@brainfish-ai/web-tracker 0.0.4-alpha.15 → 0.0.4-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,1944 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const e = require("./index-D2jDlqQC.js");
4
- exports.Tracker = e.Tracker, exports.VERSION = e.VERSION;
1
+ var Je = Object.defineProperty, Qe = Object.defineProperties;
2
+ var Ge = Object.getOwnPropertyDescriptors;
3
+ var pe = Object.getOwnPropertySymbols, Ze = Object.getPrototypeOf, et = Object.prototype.hasOwnProperty, tt = Object.prototype.propertyIsEnumerable, st = Reflect.get;
4
+ var fe = Math.pow, z = (s, e, t) => e in s ? Je(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, v = (s, e) => {
5
+ for (var t in e || (e = {}))
6
+ et.call(e, t) && z(s, t, e[t]);
7
+ if (pe)
8
+ for (var t of pe(e))
9
+ tt.call(e, t) && z(s, t, e[t]);
10
+ return s;
11
+ }, O = (s, e) => Qe(s, Ge(e));
12
+ var b = (s, e, t) => z(s, typeof e != "symbol" ? e + "" : e, t);
13
+ var ge = (s, e, t) => st(Ze(s), t, e);
14
+ var p = (s, e, t) => new Promise((n, r) => {
15
+ var i = (c) => {
16
+ try {
17
+ a(t.next(c));
18
+ } catch (h) {
19
+ r(h);
20
+ }
21
+ }, o = (c) => {
22
+ try {
23
+ a(t.throw(c));
24
+ } catch (h) {
25
+ r(h);
26
+ }
27
+ }, a = (c) => c.done ? n(c.value) : Promise.resolve(c.value).then(i, o);
28
+ a((t = t.apply(s, e)).next());
29
+ });
30
+ const R = /* @__PURE__ */ Object.create(null);
31
+ R.open = "0", R.close = "1", R.ping = "2", R.pong = "3", R.message = "4", R.upgrade = "5", R.noop = "6";
32
+ const U = /* @__PURE__ */ Object.create(null);
33
+ Object.keys(R).forEach((s) => {
34
+ U[R[s]] = s;
35
+ });
36
+ const G = { type: "error", data: "parser error" }, Oe = typeof Blob == "function" || typeof Blob != "undefined" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", Ne = typeof ArrayBuffer == "function", Le = (s) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(s) : s && s.buffer instanceof ArrayBuffer, ie = ({ type: s, data: e }, t, n) => Oe && e instanceof Blob ? t ? n(e) : ye(e, n) : Ne && (e instanceof ArrayBuffer || Le(e)) ? t ? n(e) : ye(new Blob([e]), n) : n(R[s] + (e || "")), ye = (s, e) => {
37
+ const t = new FileReader();
38
+ return t.onload = function() {
39
+ const n = t.result.split(",")[1];
40
+ e("b" + (n || ""));
41
+ }, t.readAsDataURL(s);
42
+ };
43
+ function me(s) {
44
+ return s instanceof Uint8Array ? s : s instanceof ArrayBuffer ? new Uint8Array(s) : new Uint8Array(s.buffer, s.byteOffset, s.byteLength);
45
+ }
46
+ let K;
47
+ const nt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", P = typeof Uint8Array == "undefined" ? [] : new Uint8Array(256);
48
+ for (let s = 0; s < 64; s++) P[nt.charCodeAt(s)] = s;
49
+ const rt = typeof ArrayBuffer == "function", oe = (s, e) => {
50
+ if (typeof s != "string") return { type: "message", data: Pe(s, e) };
51
+ const t = s.charAt(0);
52
+ return t === "b" ? { type: "message", data: it(s.substring(1), e) } : U[t] ? s.length > 1 ? { type: U[t], data: s.substring(1) } : { type: U[t] } : G;
53
+ }, it = (s, e) => {
54
+ if (rt) {
55
+ const t = ((n) => {
56
+ let r, i, o, a, c, h = 0.75 * n.length, u = n.length, l = 0;
57
+ n[n.length - 1] === "=" && (h--, n[n.length - 2] === "=" && h--);
58
+ const d = new ArrayBuffer(h), m = new Uint8Array(d);
59
+ for (r = 0; r < u; r += 4) i = P[n.charCodeAt(r)], o = P[n.charCodeAt(r + 1)], a = P[n.charCodeAt(r + 2)], c = P[n.charCodeAt(r + 3)], m[l++] = i << 2 | o >> 4, m[l++] = (15 & o) << 4 | a >> 2, m[l++] = (3 & a) << 6 | 63 & c;
60
+ return d;
61
+ })(s);
62
+ return Pe(t, e);
63
+ }
64
+ return { base64: !0, data: s };
65
+ }, Pe = (s, e) => e === "blob" ? s instanceof Blob ? s : new Blob([s]) : s instanceof ArrayBuffer ? s : s.buffer, be = "";
66
+ function ot() {
67
+ return new TransformStream({ transform(s, e) {
68
+ (function(t, n) {
69
+ Oe && t.data instanceof Blob ? t.data.arrayBuffer().then(me).then(n) : Ne && (t.data instanceof ArrayBuffer || Le(t.data)) ? n(me(t.data)) : ie(t, !1, (r) => {
70
+ K || (K = new TextEncoder()), n(K.encode(r));
71
+ });
72
+ })(s, (t) => {
73
+ const n = t.length;
74
+ let r;
75
+ if (n < 126) r = new Uint8Array(1), new DataView(r.buffer).setUint8(0, n);
76
+ else if (n < 65536) {
77
+ r = new Uint8Array(3);
78
+ const i = new DataView(r.buffer);
79
+ i.setUint8(0, 126), i.setUint16(1, n);
80
+ } else {
81
+ r = new Uint8Array(9);
82
+ const i = new DataView(r.buffer);
83
+ i.setUint8(0, 127), i.setBigUint64(1, BigInt(n));
84
+ }
85
+ s.data && typeof s.data != "string" && (r[0] |= 128), e.enqueue(r), e.enqueue(t);
86
+ });
87
+ } });
88
+ }
89
+ let Y;
90
+ function B(s) {
91
+ return s.reduce((e, t) => e + t.length, 0);
92
+ }
93
+ function I(s, e) {
94
+ if (s[0].length === e) return s.shift();
95
+ const t = new Uint8Array(e);
96
+ let n = 0;
97
+ for (let r = 0; r < e; r++) t[r] = s[0][n++], n === s[0].length && (s.shift(), n = 0);
98
+ return s.length && n < s[0].length && (s[0] = s[0].slice(n)), t;
99
+ }
100
+ function y(s) {
101
+ if (s) return function(e) {
102
+ for (var t in y.prototype) e[t] = y.prototype[t];
103
+ return e;
104
+ }(s);
105
+ }
106
+ y.prototype.on = y.prototype.addEventListener = function(s, e) {
107
+ return this._callbacks = this._callbacks || {}, (this._callbacks["$" + s] = this._callbacks["$" + s] || []).push(e), this;
108
+ }, y.prototype.once = function(s, e) {
109
+ function t() {
110
+ this.off(s, t), e.apply(this, arguments);
111
+ }
112
+ return t.fn = e, this.on(s, t), this;
113
+ }, y.prototype.off = y.prototype.removeListener = y.prototype.removeAllListeners = y.prototype.removeEventListener = function(s, e) {
114
+ if (this._callbacks = this._callbacks || {}, arguments.length == 0) return this._callbacks = {}, this;
115
+ var t, n = this._callbacks["$" + s];
116
+ if (!n) return this;
117
+ if (arguments.length == 1) return delete this._callbacks["$" + s], this;
118
+ for (var r = 0; r < n.length; r++) if ((t = n[r]) === e || t.fn === e) {
119
+ n.splice(r, 1);
120
+ break;
121
+ }
122
+ return n.length === 0 && delete this._callbacks["$" + s], this;
123
+ }, y.prototype.emit = function(s) {
124
+ this._callbacks = this._callbacks || {};
125
+ for (var e = new Array(arguments.length - 1), t = this._callbacks["$" + s], n = 1; n < arguments.length; n++) e[n - 1] = arguments[n];
126
+ if (t) {
127
+ n = 0;
128
+ for (var r = (t = t.slice(0)).length; n < r; ++n) t[n].apply(this, e);
129
+ }
130
+ return this;
131
+ }, y.prototype.emitReserved = y.prototype.emit, y.prototype.listeners = function(s) {
132
+ return this._callbacks = this._callbacks || {}, this._callbacks["$" + s] || [];
133
+ }, y.prototype.hasListeners = function(s) {
134
+ return !!this.listeners(s).length;
135
+ };
136
+ const W = typeof Promise == "function" && typeof Promise.resolve == "function" ? (s) => Promise.resolve().then(s) : (s, e) => e(s, 0), k = typeof self != "undefined" ? self : typeof window != "undefined" ? window : Function("return this")();
137
+ function Be(s, ...e) {
138
+ return e.reduce((t, n) => (s.hasOwnProperty(n) && (t[n] = s[n]), t), {});
139
+ }
140
+ const at = k.setTimeout, ct = k.clearTimeout;
141
+ function H(s, e) {
142
+ e.useNativeTimers ? (s.setTimeoutFn = at.bind(k), s.clearTimeoutFn = ct.bind(k)) : (s.setTimeoutFn = k.setTimeout.bind(k), s.clearTimeoutFn = k.clearTimeout.bind(k));
143
+ }
144
+ function Ie() {
145
+ return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
146
+ }
147
+ class ht extends Error {
148
+ constructor(e, t, n) {
149
+ super(e), this.description = t, this.context = n, this.type = "TransportError";
150
+ }
151
+ }
152
+ class ae extends y {
153
+ constructor(e) {
154
+ super(), this.writable = !1, H(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
155
+ }
156
+ onError(e, t, n) {
157
+ return super.emitReserved("error", new ht(e, t, n)), this;
158
+ }
159
+ open() {
160
+ return this.readyState = "opening", this.doOpen(), this;
161
+ }
162
+ close() {
163
+ return this.readyState !== "opening" && this.readyState !== "open" || (this.doClose(), this.onClose()), this;
164
+ }
165
+ send(e) {
166
+ this.readyState === "open" && this.write(e);
167
+ }
168
+ onOpen() {
169
+ this.readyState = "open", this.writable = !0, super.emitReserved("open");
170
+ }
171
+ onData(e) {
172
+ const t = oe(e, this.socket.binaryType);
173
+ this.onPacket(t);
174
+ }
175
+ onPacket(e) {
176
+ super.emitReserved("packet", e);
177
+ }
178
+ onClose(e) {
179
+ this.readyState = "closed", super.emitReserved("close", e);
180
+ }
181
+ pause(e) {
182
+ }
183
+ createUri(e, t = {}) {
184
+ return e + "://" + this._hostname() + this._port() + this.opts.path + this._query(t);
185
+ }
186
+ _hostname() {
187
+ const e = this.opts.hostname;
188
+ return e.indexOf(":") === -1 ? e : "[" + e + "]";
189
+ }
190
+ _port() {
191
+ return this.opts.port && (this.opts.secure && +(this.opts.port !== 443) || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
192
+ }
193
+ _query(e) {
194
+ const t = function(n) {
195
+ let r = "";
196
+ for (let i in n) n.hasOwnProperty(i) && (r.length && (r += "&"), r += encodeURIComponent(i) + "=" + encodeURIComponent(n[i]));
197
+ return r;
198
+ }(e);
199
+ return t.length ? "?" + t : "";
200
+ }
201
+ }
202
+ class ut extends ae {
203
+ constructor() {
204
+ super(...arguments), this._polling = !1;
205
+ }
206
+ get name() {
207
+ return "polling";
208
+ }
209
+ doOpen() {
210
+ this._poll();
211
+ }
212
+ pause(e) {
213
+ this.readyState = "pausing";
214
+ const t = () => {
215
+ this.readyState = "paused", e();
216
+ };
217
+ if (this._polling || !this.writable) {
218
+ let n = 0;
219
+ this._polling && (n++, this.once("pollComplete", function() {
220
+ --n || t();
221
+ })), this.writable || (n++, this.once("drain", function() {
222
+ --n || t();
223
+ }));
224
+ } else t();
225
+ }
226
+ _poll() {
227
+ this._polling = !0, this.doPoll(), this.emitReserved("poll");
228
+ }
229
+ onData(e) {
230
+ ((t, n) => {
231
+ const r = t.split(be), i = [];
232
+ for (let o = 0; o < r.length; o++) {
233
+ const a = oe(r[o], n);
234
+ if (i.push(a), a.type === "error") break;
235
+ }
236
+ return i;
237
+ })(e, this.socket.binaryType).forEach((t) => {
238
+ if (this.readyState === "opening" && t.type === "open" && this.onOpen(), t.type === "close") return this.onClose({ description: "transport closed by the server" }), !1;
239
+ this.onPacket(t);
240
+ }), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
241
+ }
242
+ doClose() {
243
+ const e = () => {
244
+ this.write([{ type: "close" }]);
245
+ };
246
+ this.readyState === "open" ? e() : this.once("open", e);
247
+ }
248
+ write(e) {
249
+ this.writable = !1, ((t, n) => {
250
+ const r = t.length, i = new Array(r);
251
+ let o = 0;
252
+ t.forEach((a, c) => {
253
+ ie(a, !1, (h) => {
254
+ i[c] = h, ++o === r && n(i.join(be));
255
+ });
256
+ });
257
+ })(e, (t) => {
258
+ this.doWrite(t, () => {
259
+ this.writable = !0, this.emitReserved("drain");
260
+ });
261
+ });
262
+ }
263
+ uri() {
264
+ const e = this.opts.secure ? "https" : "http", t = this.query || {};
265
+ return this.opts.timestampRequests !== !1 && (t[this.opts.timestampParam] = Ie()), this.supportsBinary || t.sid || (t.b64 = 1), this.createUri(e, t);
266
+ }
267
+ }
268
+ let qe = !1;
269
+ try {
270
+ qe = typeof XMLHttpRequest != "undefined" && "withCredentials" in new XMLHttpRequest();
271
+ } catch (s) {
272
+ }
273
+ const lt = qe;
274
+ function dt() {
275
+ }
276
+ class pt extends ut {
277
+ constructor(e) {
278
+ if (super(e), typeof location != "undefined") {
279
+ const t = location.protocol === "https:";
280
+ let n = location.port;
281
+ n || (n = t ? "443" : "80"), this.xd = typeof location != "undefined" && e.hostname !== location.hostname || n !== e.port;
282
+ }
283
+ }
284
+ doWrite(e, t) {
285
+ const n = this.request({ method: "POST", data: e });
286
+ n.on("success", t), n.on("error", (r, i) => {
287
+ this.onError("xhr post error", r, i);
288
+ });
289
+ }
290
+ doPoll() {
291
+ const e = this.request();
292
+ e.on("data", this.onData.bind(this)), e.on("error", (t, n) => {
293
+ this.onError("xhr poll error", t, n);
294
+ }), this.pollXhr = e;
295
+ }
296
+ }
297
+ class A extends y {
298
+ constructor(e, t, n) {
299
+ super(), this.createRequest = e, H(this, n), this._opts = n, this._method = n.method || "GET", this._uri = t, this._data = n.data !== void 0 ? n.data : null, this._create();
300
+ }
301
+ _create() {
302
+ var e;
303
+ const t = Be(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
304
+ t.xdomain = !!this._opts.xd;
305
+ const n = this._xhr = this.createRequest(t);
306
+ try {
307
+ n.open(this._method, this._uri, !0);
308
+ try {
309
+ if (this._opts.extraHeaders) {
310
+ n.setDisableHeaderCheck && n.setDisableHeaderCheck(!0);
311
+ for (let r in this._opts.extraHeaders) this._opts.extraHeaders.hasOwnProperty(r) && n.setRequestHeader(r, this._opts.extraHeaders[r]);
312
+ }
313
+ } catch (r) {
314
+ }
315
+ if (this._method === "POST") try {
316
+ n.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
317
+ } catch (r) {
318
+ }
319
+ try {
320
+ n.setRequestHeader("Accept", "*/*");
321
+ } catch (r) {
322
+ }
323
+ (e = this._opts.cookieJar) === null || e === void 0 || e.addCookies(n), "withCredentials" in n && (n.withCredentials = this._opts.withCredentials), this._opts.requestTimeout && (n.timeout = this._opts.requestTimeout), n.onreadystatechange = () => {
324
+ var r;
325
+ n.readyState === 3 && ((r = this._opts.cookieJar) === null || r === void 0 || r.parseCookies(n.getResponseHeader("set-cookie"))), n.readyState === 4 && (n.status === 200 || n.status === 1223 ? this._onLoad() : this.setTimeoutFn(() => {
326
+ this._onError(typeof n.status == "number" ? n.status : 0);
327
+ }, 0));
328
+ }, n.send(this._data);
329
+ } catch (r) {
330
+ return void this.setTimeoutFn(() => {
331
+ this._onError(r);
332
+ }, 0);
333
+ }
334
+ typeof document != "undefined" && (this._index = A.requestsCount++, A.requests[this._index] = this);
335
+ }
336
+ _onError(e) {
337
+ this.emitReserved("error", e, this._xhr), this._cleanup(!0);
338
+ }
339
+ _cleanup(e) {
340
+ if (this._xhr !== void 0 && this._xhr !== null) {
341
+ if (this._xhr.onreadystatechange = dt, e) try {
342
+ this._xhr.abort();
343
+ } catch (t) {
344
+ }
345
+ typeof document != "undefined" && delete A.requests[this._index], this._xhr = null;
346
+ }
347
+ }
348
+ _onLoad() {
349
+ const e = this._xhr.responseText;
350
+ e !== null && (this.emitReserved("data", e), this.emitReserved("success"), this._cleanup());
351
+ }
352
+ abort() {
353
+ this._cleanup();
354
+ }
355
+ }
356
+ A.requestsCount = 0, A.requests = {}, typeof document != "undefined" && (typeof attachEvent == "function" ? attachEvent("onunload", we) : typeof addEventListener == "function" && addEventListener("onpagehide" in k ? "pagehide" : "unload", we, !1));
357
+ function we() {
358
+ for (let s in A.requests) A.requests.hasOwnProperty(s) && A.requests[s].abort();
359
+ }
360
+ const ft = function() {
361
+ const s = je({ xdomain: !1 });
362
+ return s && s.responseType !== null;
363
+ }();
364
+ function je(s) {
365
+ const e = s.xdomain;
366
+ try {
367
+ if (typeof XMLHttpRequest != "undefined" && (!e || lt)) return new XMLHttpRequest();
368
+ } catch (t) {
369
+ }
370
+ if (!e) try {
371
+ return new k[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
372
+ } catch (t) {
373
+ }
374
+ }
375
+ const Ue = typeof navigator != "undefined" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
376
+ class gt extends ae {
377
+ get name() {
378
+ return "websocket";
379
+ }
380
+ doOpen() {
381
+ const e = this.uri(), t = this.opts.protocols, n = Ue ? {} : Be(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
382
+ this.opts.extraHeaders && (n.headers = this.opts.extraHeaders);
383
+ try {
384
+ this.ws = this.createSocket(e, t, n);
385
+ } catch (r) {
386
+ return this.emitReserved("error", r);
387
+ }
388
+ this.ws.binaryType = this.socket.binaryType, this.addEventListeners();
389
+ }
390
+ addEventListeners() {
391
+ this.ws.onopen = () => {
392
+ this.opts.autoUnref && this.ws._socket.unref(), this.onOpen();
393
+ }, this.ws.onclose = (e) => this.onClose({ description: "websocket connection closed", context: e }), this.ws.onmessage = (e) => this.onData(e.data), this.ws.onerror = (e) => this.onError("websocket error", e);
394
+ }
395
+ write(e) {
396
+ this.writable = !1;
397
+ for (let t = 0; t < e.length; t++) {
398
+ const n = e[t], r = t === e.length - 1;
399
+ ie(n, this.supportsBinary, (i) => {
400
+ try {
401
+ this.doWrite(n, i);
402
+ } catch (o) {
403
+ }
404
+ r && W(() => {
405
+ this.writable = !0, this.emitReserved("drain");
406
+ }, this.setTimeoutFn);
407
+ });
408
+ }
409
+ }
410
+ doClose() {
411
+ this.ws !== void 0 && (this.ws.close(), this.ws = null);
412
+ }
413
+ uri() {
414
+ const e = this.opts.secure ? "wss" : "ws", t = this.query || {};
415
+ return this.opts.timestampRequests && (t[this.opts.timestampParam] = Ie()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
416
+ }
417
+ }
418
+ const X = k.WebSocket || k.MozWebSocket, yt = { websocket: class extends gt {
419
+ createSocket(s, e, t) {
420
+ return Ue ? new X(s, e, t) : e ? new X(s, e) : new X(s);
421
+ }
422
+ doWrite(s, e) {
423
+ this.ws.send(e);
424
+ }
425
+ }, webtransport: class extends ae {
426
+ get name() {
427
+ return "webtransport";
428
+ }
429
+ doOpen() {
430
+ try {
431
+ this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
432
+ } catch (s) {
433
+ return this.emitReserved("error", s);
434
+ }
435
+ this._transport.closed.then(() => {
436
+ this.onClose();
437
+ }).catch((s) => {
438
+ this.onError("webtransport error", s);
439
+ }), this._transport.ready.then(() => {
440
+ this._transport.createBidirectionalStream().then((s) => {
441
+ const e = function(o, a) {
442
+ Y || (Y = new TextDecoder());
443
+ const c = [];
444
+ let h = 0, u = -1, l = !1;
445
+ return new TransformStream({ transform(d, m) {
446
+ for (c.push(d); ; ) {
447
+ if (h === 0) {
448
+ if (B(c) < 1) break;
449
+ const g = I(c, 1);
450
+ l = !(128 & ~g[0]), u = 127 & g[0], h = u < 126 ? 3 : u === 126 ? 1 : 2;
451
+ } else if (h === 1) {
452
+ if (B(c) < 2) break;
453
+ const g = I(c, 2);
454
+ u = new DataView(g.buffer, g.byteOffset, g.length).getUint16(0), h = 3;
455
+ } else if (h === 2) {
456
+ if (B(c) < 8) break;
457
+ const g = I(c, 8), C = new DataView(g.buffer, g.byteOffset, g.length), de = C.getUint32(0);
458
+ if (de > Math.pow(2, 21) - 1) {
459
+ m.enqueue(G);
460
+ break;
461
+ }
462
+ u = de * Math.pow(2, 32) + C.getUint32(4), h = 3;
463
+ } else {
464
+ if (B(c) < u) break;
465
+ const g = I(c, u);
466
+ m.enqueue(oe(l ? g : Y.decode(g), a)), h = 0;
467
+ }
468
+ if (u === 0 || u > o) {
469
+ m.enqueue(G);
470
+ break;
471
+ }
472
+ }
473
+ } });
474
+ }(Number.MAX_SAFE_INTEGER, this.socket.binaryType), t = s.readable.pipeThrough(e).getReader(), n = ot();
475
+ n.readable.pipeTo(s.writable), this._writer = n.writable.getWriter();
476
+ const r = () => {
477
+ t.read().then(({ done: o, value: a }) => {
478
+ o || (this.onPacket(a), r());
479
+ }).catch((o) => {
480
+ });
481
+ };
482
+ r();
483
+ const i = { type: "open" };
484
+ this.query.sid && (i.data = `{"sid":"${this.query.sid}"}`), this._writer.write(i).then(() => this.onOpen());
485
+ });
486
+ });
487
+ }
488
+ write(s) {
489
+ this.writable = !1;
490
+ for (let e = 0; e < s.length; e++) {
491
+ const t = s[e], n = e === s.length - 1;
492
+ this._writer.write(t).then(() => {
493
+ n && W(() => {
494
+ this.writable = !0, this.emitReserved("drain");
495
+ }, this.setTimeoutFn);
496
+ });
497
+ }
498
+ }
499
+ doClose() {
500
+ var s;
501
+ (s = this._transport) === null || s === void 0 || s.close();
502
+ }
503
+ }, polling: class extends pt {
504
+ constructor(s) {
505
+ super(s);
506
+ const e = s && s.forceBase64;
507
+ this.supportsBinary = ft && !e;
508
+ }
509
+ request(s = {}) {
510
+ return Object.assign(s, { xd: this.xd }, this.opts), new A(je, this.uri(), s);
511
+ }
512
+ } }, mt = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, bt = ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"];
513
+ function Z(s) {
514
+ if (s.length > 8e3) throw "URI too long";
515
+ const e = s, t = s.indexOf("["), n = s.indexOf("]");
516
+ t != -1 && n != -1 && (s = s.substring(0, t) + s.substring(t, n).replace(/:/g, ";") + s.substring(n, s.length));
517
+ let r = mt.exec(s || ""), i = {}, o = 14;
518
+ for (; o--; ) i[bt[o]] = r[o] || "";
519
+ return t != -1 && n != -1 && (i.source = e, i.host = i.host.substring(1, i.host.length - 1).replace(/;/g, ":"), i.authority = i.authority.replace("[", "").replace("]", "").replace(/;/g, ":"), i.ipv6uri = !0), i.pathNames = function(a, c) {
520
+ const h = /\/{2,9}/g, u = c.replace(h, "/").split("/");
521
+ return c.slice(0, 1) != "/" && c.length !== 0 || u.splice(0, 1), c.slice(-1) == "/" && u.splice(u.length - 1, 1), u;
522
+ }(0, i.path), i.queryKey = function(a, c) {
523
+ const h = {};
524
+ return c.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(u, l, d) {
525
+ l && (h[l] = d);
526
+ }), h;
527
+ }(0, i.query), i;
528
+ }
529
+ const ee = typeof addEventListener == "function" && typeof removeEventListener == "function", D = [];
530
+ ee && addEventListener("offline", () => {
531
+ D.forEach((s) => s());
532
+ }, !1);
533
+ class T extends y {
534
+ constructor(e, t) {
535
+ if (super(), this.binaryType = "arraybuffer", this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = 1 / 0, e && typeof e == "object" && (t = e, e = null), e) {
536
+ const n = Z(e);
537
+ t.hostname = n.host, t.secure = n.protocol === "https" || n.protocol === "wss", t.port = n.port, n.query && (t.query = n.query);
538
+ } else t.host && (t.hostname = Z(t.host).host);
539
+ H(this, t), this.secure = t.secure != null ? t.secure : typeof location != "undefined" && location.protocol === "https:", t.hostname && !t.port && (t.port = this.secure ? "443" : "80"), this.hostname = t.hostname || (typeof location != "undefined" ? location.hostname : "localhost"), this.port = t.port || (typeof location != "undefined" && location.port ? location.port : this.secure ? "443" : "80"), this.transports = [], this._transportsByName = {}, t.transports.forEach((n) => {
540
+ const r = n.prototype.name;
541
+ this.transports.push(r), this._transportsByName[r] = n;
542
+ }), this.opts = Object.assign({ path: "/engine.io", agent: !1, withCredentials: !1, upgrade: !0, timestampParam: "t", rememberUpgrade: !1, addTrailingSlash: !0, rejectUnauthorized: !0, perMessageDeflate: { threshold: 1024 }, transportOptions: {}, closeOnBeforeunload: !1 }, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = function(n) {
543
+ let r = {}, i = n.split("&");
544
+ for (let o = 0, a = i.length; o < a; o++) {
545
+ let c = i[o].split("=");
546
+ r[decodeURIComponent(c[0])] = decodeURIComponent(c[1]);
547
+ }
548
+ return r;
549
+ }(this.opts.query)), ee && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
550
+ this.transport && (this.transport.removeAllListeners(), this.transport.close());
551
+ }, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
552
+ this._onClose("transport close", { description: "network connection lost" });
553
+ }, D.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
554
+ }
555
+ createTransport(e) {
556
+ const t = Object.assign({}, this.opts.query);
557
+ t.EIO = 4, t.transport = e, this.id && (t.sid = this.id);
558
+ const n = Object.assign({}, this.opts, { query: t, socket: this, hostname: this.hostname, secure: this.secure, port: this.port }, this.opts.transportOptions[e]);
559
+ return new this._transportsByName[e](n);
560
+ }
561
+ _open() {
562
+ if (this.transports.length === 0) return void this.setTimeoutFn(() => {
563
+ this.emitReserved("error", "No transports available");
564
+ }, 0);
565
+ const e = this.opts.rememberUpgrade && T.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
566
+ this.readyState = "opening";
567
+ const t = this.createTransport(e);
568
+ t.open(), this.setTransport(t);
569
+ }
570
+ setTransport(e) {
571
+ this.transport && this.transport.removeAllListeners(), this.transport = e, e.on("drain", this._onDrain.bind(this)).on("packet", this._onPacket.bind(this)).on("error", this._onError.bind(this)).on("close", (t) => this._onClose("transport close", t));
572
+ }
573
+ onOpen() {
574
+ this.readyState = "open", T.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush();
575
+ }
576
+ _onPacket(e) {
577
+ if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") switch (this.emitReserved("packet", e), this.emitReserved("heartbeat"), e.type) {
578
+ case "open":
579
+ this.onHandshake(JSON.parse(e.data));
580
+ break;
581
+ case "ping":
582
+ this._sendPacket("pong"), this.emitReserved("ping"), this.emitReserved("pong"), this._resetPingTimeout();
583
+ break;
584
+ case "error":
585
+ const t = new Error("server error");
586
+ t.code = e.data, this._onError(t);
587
+ break;
588
+ case "message":
589
+ this.emitReserved("data", e.data), this.emitReserved("message", e.data);
590
+ }
591
+ }
592
+ onHandshake(e) {
593
+ this.emitReserved("handshake", e), this.id = e.sid, this.transport.query.sid = e.sid, this._pingInterval = e.pingInterval, this._pingTimeout = e.pingTimeout, this._maxPayload = e.maxPayload, this.onOpen(), this.readyState !== "closed" && this._resetPingTimeout();
594
+ }
595
+ _resetPingTimeout() {
596
+ this.clearTimeoutFn(this._pingTimeoutTimer);
597
+ const e = this._pingInterval + this._pingTimeout;
598
+ this._pingTimeoutTime = Date.now() + e, this._pingTimeoutTimer = this.setTimeoutFn(() => {
599
+ this._onClose("ping timeout");
600
+ }, e), this.opts.autoUnref && this._pingTimeoutTimer.unref();
601
+ }
602
+ _onDrain() {
603
+ this.writeBuffer.splice(0, this._prevBufferLen), this._prevBufferLen = 0, this.writeBuffer.length === 0 ? this.emitReserved("drain") : this.flush();
604
+ }
605
+ flush() {
606
+ if (this.readyState !== "closed" && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
607
+ const e = this._getWritablePackets();
608
+ this.transport.send(e), this._prevBufferLen = e.length, this.emitReserved("flush");
609
+ }
610
+ }
611
+ _getWritablePackets() {
612
+ if (!(this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1)) return this.writeBuffer;
613
+ let e = 1;
614
+ for (let n = 0; n < this.writeBuffer.length; n++) {
615
+ const r = this.writeBuffer[n].data;
616
+ if (r && (e += typeof (t = r) == "string" ? function(i) {
617
+ let o = 0, a = 0;
618
+ for (let c = 0, h = i.length; c < h; c++) o = i.charCodeAt(c), o < 128 ? a += 1 : o < 2048 ? a += 2 : o < 55296 || o >= 57344 ? a += 3 : (c++, a += 4);
619
+ return a;
620
+ }(t) : Math.ceil(1.33 * (t.byteLength || t.size))), n > 0 && e > this._maxPayload) return this.writeBuffer.slice(0, n);
621
+ e += 2;
622
+ }
623
+ var t;
624
+ return this.writeBuffer;
625
+ }
626
+ _hasPingExpired() {
627
+ if (!this._pingTimeoutTime) return !0;
628
+ const e = Date.now() > this._pingTimeoutTime;
629
+ return e && (this._pingTimeoutTime = 0, W(() => {
630
+ this._onClose("ping timeout");
631
+ }, this.setTimeoutFn)), e;
632
+ }
633
+ write(e, t, n) {
634
+ return this._sendPacket("message", e, t, n), this;
635
+ }
636
+ send(e, t, n) {
637
+ return this._sendPacket("message", e, t, n), this;
638
+ }
639
+ _sendPacket(e, t, n, r) {
640
+ if (typeof t == "function" && (r = t, t = void 0), typeof n == "function" && (r = n, n = null), this.readyState === "closing" || this.readyState === "closed") return;
641
+ (n = n || {}).compress = n.compress !== !1;
642
+ const i = { type: e, data: t, options: n };
643
+ this.emitReserved("packetCreate", i), this.writeBuffer.push(i), r && this.once("flush", r), this.flush();
644
+ }
645
+ close() {
646
+ const e = () => {
647
+ this._onClose("forced close"), this.transport.close();
648
+ }, t = () => {
649
+ this.off("upgrade", t), this.off("upgradeError", t), e();
650
+ }, n = () => {
651
+ this.once("upgrade", t), this.once("upgradeError", t);
652
+ };
653
+ return this.readyState !== "opening" && this.readyState !== "open" || (this.readyState = "closing", this.writeBuffer.length ? this.once("drain", () => {
654
+ this.upgrading ? n() : e();
655
+ }) : this.upgrading ? n() : e()), this;
656
+ }
657
+ _onError(e) {
658
+ if (T.priorWebsocketSuccess = !1, this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening") return this.transports.shift(), this._open();
659
+ this.emitReserved("error", e), this._onClose("transport error", e);
660
+ }
661
+ _onClose(e, t) {
662
+ if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
663
+ if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), ee && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
664
+ const n = D.indexOf(this._offlineEventListener);
665
+ n !== -1 && D.splice(n, 1);
666
+ }
667
+ this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
668
+ }
669
+ }
670
+ }
671
+ T.protocol = 4;
672
+ class wt extends T {
673
+ constructor() {
674
+ super(...arguments), this._upgrades = [];
675
+ }
676
+ onOpen() {
677
+ if (super.onOpen(), this.readyState === "open" && this.opts.upgrade) for (let e = 0; e < this._upgrades.length; e++) this._probe(this._upgrades[e]);
678
+ }
679
+ _probe(e) {
680
+ let t = this.createTransport(e), n = !1;
681
+ T.priorWebsocketSuccess = !1;
682
+ const r = () => {
683
+ n || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (l) => {
684
+ if (!n) if (l.type === "pong" && l.data === "probe") {
685
+ if (this.upgrading = !0, this.emitReserved("upgrading", t), !t) return;
686
+ T.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
687
+ n || this.readyState !== "closed" && (u(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
688
+ });
689
+ } else {
690
+ const d = new Error("probe error");
691
+ d.transport = t.name, this.emitReserved("upgradeError", d);
692
+ }
693
+ }));
694
+ };
695
+ function i() {
696
+ n || (n = !0, u(), t.close(), t = null);
697
+ }
698
+ const o = (l) => {
699
+ const d = new Error("probe error: " + l);
700
+ d.transport = t.name, i(), this.emitReserved("upgradeError", d);
701
+ };
702
+ function a() {
703
+ o("transport closed");
704
+ }
705
+ function c() {
706
+ o("socket closed");
707
+ }
708
+ function h(l) {
709
+ t && l.name !== t.name && i();
710
+ }
711
+ const u = () => {
712
+ t.removeListener("open", r), t.removeListener("error", o), t.removeListener("close", a), this.off("close", c), this.off("upgrading", h);
713
+ };
714
+ t.once("open", r), t.once("error", o), t.once("close", a), this.once("close", c), this.once("upgrading", h), this._upgrades.indexOf("webtransport") !== -1 && e !== "webtransport" ? this.setTimeoutFn(() => {
715
+ n || t.open();
716
+ }, 200) : t.open();
717
+ }
718
+ onHandshake(e) {
719
+ this._upgrades = this._filterUpgrades(e.upgrades), super.onHandshake(e);
720
+ }
721
+ _filterUpgrades(e) {
722
+ const t = [];
723
+ for (let n = 0; n < e.length; n++) ~this.transports.indexOf(e[n]) && t.push(e[n]);
724
+ return t;
725
+ }
726
+ }
727
+ let _t = class extends wt {
728
+ constructor(s, e = {}) {
729
+ const t = typeof s == "object" ? s : e;
730
+ (!t.transports || t.transports && typeof t.transports[0] == "string") && (t.transports = (t.transports || ["polling", "websocket", "webtransport"]).map((n) => yt[n]).filter((n) => !!n)), super(s, t);
731
+ }
732
+ };
733
+ const vt = typeof ArrayBuffer == "function", De = Object.prototype.toString, kt = typeof Blob == "function" || typeof Blob != "undefined" && De.call(Blob) === "[object BlobConstructor]", Et = typeof File == "function" || typeof File != "undefined" && De.call(File) === "[object FileConstructor]";
734
+ function ce(s) {
735
+ return vt && (s instanceof ArrayBuffer || ((e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e.buffer instanceof ArrayBuffer)(s)) || kt && s instanceof Blob || Et && s instanceof File;
736
+ }
737
+ function $(s, e) {
738
+ if (!s || typeof s != "object") return !1;
739
+ if (Array.isArray(s)) {
740
+ for (let t = 0, n = s.length; t < n; t++) if ($(s[t])) return !0;
741
+ return !1;
742
+ }
743
+ if (ce(s)) return !0;
744
+ if (s.toJSON && typeof s.toJSON == "function" && arguments.length === 1) return $(s.toJSON(), !0);
745
+ for (const t in s) if (Object.prototype.hasOwnProperty.call(s, t) && $(s[t])) return !0;
746
+ return !1;
747
+ }
748
+ function Rt(s) {
749
+ const e = [], t = s.data, n = s;
750
+ return n.data = te(t, e), n.attachments = e.length, { packet: n, buffers: e };
751
+ }
752
+ function te(s, e) {
753
+ if (!s) return s;
754
+ if (ce(s)) {
755
+ const t = { _placeholder: !0, num: e.length };
756
+ return e.push(s), t;
757
+ }
758
+ if (Array.isArray(s)) {
759
+ const t = new Array(s.length);
760
+ for (let n = 0; n < s.length; n++) t[n] = te(s[n], e);
761
+ return t;
762
+ }
763
+ if (typeof s == "object" && !(s instanceof Date)) {
764
+ const t = {};
765
+ for (const n in s) Object.prototype.hasOwnProperty.call(s, n) && (t[n] = te(s[n], e));
766
+ return t;
767
+ }
768
+ return s;
769
+ }
770
+ function At(s, e) {
771
+ return s.data = se(s.data, e), delete s.attachments, s;
772
+ }
773
+ function se(s, e) {
774
+ if (!s) return s;
775
+ if (s && s._placeholder === !0) {
776
+ if (typeof s.num == "number" && s.num >= 0 && s.num < e.length) return e[s.num];
777
+ throw new Error("illegal attachments");
778
+ }
779
+ if (Array.isArray(s)) for (let t = 0; t < s.length; t++) s[t] = se(s[t], e);
780
+ else if (typeof s == "object") for (const t in s) Object.prototype.hasOwnProperty.call(s, t) && (s[t] = se(s[t], e));
781
+ return s;
782
+ }
783
+ const St = ["connect", "connect_error", "disconnect", "disconnecting", "newListener", "removeListener"];
784
+ var f;
785
+ (function(s) {
786
+ s[s.CONNECT = 0] = "CONNECT", s[s.DISCONNECT = 1] = "DISCONNECT", s[s.EVENT = 2] = "EVENT", s[s.ACK = 3] = "ACK", s[s.CONNECT_ERROR = 4] = "CONNECT_ERROR", s[s.BINARY_EVENT = 5] = "BINARY_EVENT", s[s.BINARY_ACK = 6] = "BINARY_ACK";
787
+ })(f || (f = {}));
788
+ function _e(s) {
789
+ return Object.prototype.toString.call(s) === "[object Object]";
790
+ }
791
+ class he extends y {
792
+ constructor(e) {
793
+ super(), this.reviver = e;
794
+ }
795
+ add(e) {
796
+ let t;
797
+ if (typeof e == "string") {
798
+ if (this.reconstructor) throw new Error("got plaintext data when reconstructing a packet");
799
+ t = this.decodeString(e);
800
+ const n = t.type === f.BINARY_EVENT;
801
+ n || t.type === f.BINARY_ACK ? (t.type = n ? f.EVENT : f.ACK, this.reconstructor = new Tt(t), t.attachments === 0 && super.emitReserved("decoded", t)) : super.emitReserved("decoded", t);
802
+ } else {
803
+ if (!ce(e) && !e.base64) throw new Error("Unknown type: " + e);
804
+ if (!this.reconstructor) throw new Error("got binary data when not reconstructing a packet");
805
+ t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
806
+ }
807
+ }
808
+ decodeString(e) {
809
+ let t = 0;
810
+ const n = { type: Number(e.charAt(0)) };
811
+ if (f[n.type] === void 0) throw new Error("unknown packet type " + n.type);
812
+ if (n.type === f.BINARY_EVENT || n.type === f.BINARY_ACK) {
813
+ const i = t + 1;
814
+ for (; e.charAt(++t) !== "-" && t != e.length; ) ;
815
+ const o = e.substring(i, t);
816
+ if (o != Number(o) || e.charAt(t) !== "-") throw new Error("Illegal attachments");
817
+ n.attachments = Number(o);
818
+ }
819
+ if (e.charAt(t + 1) === "/") {
820
+ const i = t + 1;
821
+ for (; ++t && !(e.charAt(t) === "," || t === e.length); )
822
+ ;
823
+ n.nsp = e.substring(i, t);
824
+ } else n.nsp = "/";
825
+ const r = e.charAt(t + 1);
826
+ if (r !== "" && Number(r) == r) {
827
+ const i = t + 1;
828
+ for (; ++t; ) {
829
+ const o = e.charAt(t);
830
+ if (o == null || Number(o) != o) {
831
+ --t;
832
+ break;
833
+ }
834
+ if (t === e.length) break;
835
+ }
836
+ n.id = Number(e.substring(i, t + 1));
837
+ }
838
+ if (e.charAt(++t)) {
839
+ const i = this.tryParse(e.substr(t));
840
+ if (!he.isPayloadValid(n.type, i)) throw new Error("invalid payload");
841
+ n.data = i;
842
+ }
843
+ return n;
844
+ }
845
+ tryParse(e) {
846
+ try {
847
+ return JSON.parse(e, this.reviver);
848
+ } catch (t) {
849
+ return !1;
850
+ }
851
+ }
852
+ static isPayloadValid(e, t) {
853
+ switch (e) {
854
+ case f.CONNECT:
855
+ return _e(t);
856
+ case f.DISCONNECT:
857
+ return t === void 0;
858
+ case f.CONNECT_ERROR:
859
+ return typeof t == "string" || _e(t);
860
+ case f.EVENT:
861
+ case f.BINARY_EVENT:
862
+ return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && St.indexOf(t[0]) === -1);
863
+ case f.ACK:
864
+ case f.BINARY_ACK:
865
+ return Array.isArray(t);
866
+ }
867
+ }
868
+ destroy() {
869
+ this.reconstructor && (this.reconstructor.finishedReconstruction(), this.reconstructor = null);
870
+ }
871
+ }
872
+ class Tt {
873
+ constructor(e) {
874
+ this.packet = e, this.buffers = [], this.reconPack = e;
875
+ }
876
+ takeBinaryData(e) {
877
+ if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
878
+ const t = At(this.reconPack, this.buffers);
879
+ return this.finishedReconstruction(), t;
880
+ }
881
+ return null;
882
+ }
883
+ finishedReconstruction() {
884
+ this.reconPack = null, this.buffers = [];
885
+ }
886
+ }
887
+ const xt = Object.freeze(Object.defineProperty({ __proto__: null, Decoder: he, Encoder: class {
888
+ constructor(s) {
889
+ this.replacer = s;
890
+ }
891
+ encode(s) {
892
+ return s.type !== f.EVENT && s.type !== f.ACK || !$(s) ? [this.encodeAsString(s)] : this.encodeAsBinary({ type: s.type === f.EVENT ? f.BINARY_EVENT : f.BINARY_ACK, nsp: s.nsp, data: s.data, id: s.id });
893
+ }
894
+ encodeAsString(s) {
895
+ let e = "" + s.type;
896
+ return s.type !== f.BINARY_EVENT && s.type !== f.BINARY_ACK || (e += s.attachments + "-"), s.nsp && s.nsp !== "/" && (e += s.nsp + ","), s.id != null && (e += s.id), s.data != null && (e += JSON.stringify(s.data, this.replacer)), e;
897
+ }
898
+ encodeAsBinary(s) {
899
+ const e = Rt(s), t = this.encodeAsString(e.packet), n = e.buffers;
900
+ return n.unshift(t), n;
901
+ }
902
+ }, get PacketType() {
903
+ return f;
904
+ }, protocol: 5 }, Symbol.toStringTag, { value: "Module" }));
905
+ function E(s, e, t) {
906
+ return s.on(e, t), function() {
907
+ s.off(e, t);
908
+ };
909
+ }
910
+ const Ct = Object.freeze({ connect: 1, connect_error: 1, disconnect: 1, disconnecting: 1, newListener: 1, removeListener: 1 });
911
+ class $e extends y {
912
+ constructor(e, t, n) {
913
+ super(), this.connected = !1, this.recovered = !1, this.receiveBuffer = [], this.sendBuffer = [], this._queue = [], this._queueSeq = 0, this.ids = 0, this.acks = {}, this.flags = {}, this.io = e, this.nsp = t, n && n.auth && (this.auth = n.auth), this._opts = Object.assign({}, n), this.io._autoConnect && this.open();
914
+ }
915
+ get disconnected() {
916
+ return !this.connected;
917
+ }
918
+ subEvents() {
919
+ if (this.subs) return;
920
+ const e = this.io;
921
+ this.subs = [E(e, "open", this.onopen.bind(this)), E(e, "packet", this.onpacket.bind(this)), E(e, "error", this.onerror.bind(this)), E(e, "close", this.onclose.bind(this))];
922
+ }
923
+ get active() {
924
+ return !!this.subs;
925
+ }
926
+ connect() {
927
+ return this.connected || (this.subEvents(), this.io._reconnecting || this.io.open(), this.io._readyState === "open" && this.onopen()), this;
928
+ }
929
+ open() {
930
+ return this.connect();
931
+ }
932
+ send(...e) {
933
+ return e.unshift("message"), this.emit.apply(this, e), this;
934
+ }
935
+ emit(e, ...t) {
936
+ var n, r, i;
937
+ if (Ct.hasOwnProperty(e)) throw new Error('"' + e.toString() + '" is a reserved event name');
938
+ if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) return this._addToQueue(t), this;
939
+ const o = { type: f.EVENT, data: t, options: {} };
940
+ if (o.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
941
+ const h = this.ids++, u = t.pop();
942
+ this._registerAckCallback(h, u), o.id = h;
943
+ }
944
+ const a = (r = (n = this.io.engine) === null || n === void 0 ? void 0 : n.transport) === null || r === void 0 ? void 0 : r.writable, c = this.connected && !(!((i = this.io.engine) === null || i === void 0) && i._hasPingExpired());
945
+ return this.flags.volatile && !a || (c ? (this.notifyOutgoingListeners(o), this.packet(o)) : this.sendBuffer.push(o)), this.flags = {}, this;
946
+ }
947
+ _registerAckCallback(e, t) {
948
+ var n;
949
+ const r = (n = this.flags.timeout) !== null && n !== void 0 ? n : this._opts.ackTimeout;
950
+ if (r === void 0) return void (this.acks[e] = t);
951
+ const i = this.io.setTimeoutFn(() => {
952
+ delete this.acks[e];
953
+ for (let a = 0; a < this.sendBuffer.length; a++) this.sendBuffer[a].id === e && this.sendBuffer.splice(a, 1);
954
+ t.call(this, new Error("operation has timed out"));
955
+ }, r), o = (...a) => {
956
+ this.io.clearTimeoutFn(i), t.apply(this, a);
957
+ };
958
+ o.withError = !0, this.acks[e] = o;
959
+ }
960
+ emitWithAck(e, ...t) {
961
+ return new Promise((n, r) => {
962
+ const i = (o, a) => o ? r(o) : n(a);
963
+ i.withError = !0, t.push(i), this.emit(e, ...t);
964
+ });
965
+ }
966
+ _addToQueue(e) {
967
+ let t;
968
+ typeof e[e.length - 1] == "function" && (t = e.pop());
969
+ const n = { id: this._queueSeq++, tryCount: 0, pending: !1, args: e, flags: Object.assign({ fromQueue: !0 }, this.flags) };
970
+ e.push((r, ...i) => {
971
+ if (n === this._queue[0])
972
+ return r !== null ? n.tryCount > this._opts.retries && (this._queue.shift(), t && t(r)) : (this._queue.shift(), t && t(null, ...i)), n.pending = !1, this._drainQueue();
973
+ }), this._queue.push(n), this._drainQueue();
974
+ }
975
+ _drainQueue(e = !1) {
976
+ if (!this.connected || this._queue.length === 0) return;
977
+ const t = this._queue[0];
978
+ t.pending && !e || (t.pending = !0, t.tryCount++, this.flags = t.flags, this.emit.apply(this, t.args));
979
+ }
980
+ packet(e) {
981
+ e.nsp = this.nsp, this.io._packet(e);
982
+ }
983
+ onopen() {
984
+ typeof this.auth == "function" ? this.auth((e) => {
985
+ this._sendConnectPacket(e);
986
+ }) : this._sendConnectPacket(this.auth);
987
+ }
988
+ _sendConnectPacket(e) {
989
+ this.packet({ type: f.CONNECT, data: this._pid ? Object.assign({ pid: this._pid, offset: this._lastOffset }, e) : e });
990
+ }
991
+ onerror(e) {
992
+ this.connected || this.emitReserved("connect_error", e);
993
+ }
994
+ onclose(e, t) {
995
+ this.connected = !1, delete this.id, this.emitReserved("disconnect", e, t), this._clearAcks();
996
+ }
997
+ _clearAcks() {
998
+ Object.keys(this.acks).forEach((e) => {
999
+ if (!this.sendBuffer.some((t) => String(t.id) === e)) {
1000
+ const t = this.acks[e];
1001
+ delete this.acks[e], t.withError && t.call(this, new Error("socket has been disconnected"));
1002
+ }
1003
+ });
1004
+ }
1005
+ onpacket(e) {
1006
+ if (e.nsp === this.nsp) switch (e.type) {
1007
+ case f.CONNECT:
1008
+ e.data && e.data.sid ? this.onconnect(e.data.sid, e.data.pid) : this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
1009
+ break;
1010
+ case f.EVENT:
1011
+ case f.BINARY_EVENT:
1012
+ this.onevent(e);
1013
+ break;
1014
+ case f.ACK:
1015
+ case f.BINARY_ACK:
1016
+ this.onack(e);
1017
+ break;
1018
+ case f.DISCONNECT:
1019
+ this.ondisconnect();
1020
+ break;
1021
+ case f.CONNECT_ERROR:
1022
+ this.destroy();
1023
+ const t = new Error(e.data.message);
1024
+ t.data = e.data.data, this.emitReserved("connect_error", t);
1025
+ }
1026
+ }
1027
+ onevent(e) {
1028
+ const t = e.data || [];
1029
+ e.id != null && t.push(this.ack(e.id)), this.connected ? this.emitEvent(t) : this.receiveBuffer.push(Object.freeze(t));
1030
+ }
1031
+ emitEvent(e) {
1032
+ if (this._anyListeners && this._anyListeners.length) {
1033
+ const t = this._anyListeners.slice();
1034
+ for (const n of t) n.apply(this, e);
1035
+ }
1036
+ super.emit.apply(this, e), this._pid && e.length && typeof e[e.length - 1] == "string" && (this._lastOffset = e[e.length - 1]);
1037
+ }
1038
+ ack(e) {
1039
+ const t = this;
1040
+ let n = !1;
1041
+ return function(...r) {
1042
+ n || (n = !0, t.packet({ type: f.ACK, id: e, data: r }));
1043
+ };
1044
+ }
1045
+ onack(e) {
1046
+ const t = this.acks[e.id];
1047
+ typeof t == "function" && (delete this.acks[e.id], t.withError && e.data.unshift(null), t.apply(this, e.data));
1048
+ }
1049
+ onconnect(e, t) {
1050
+ this.id = e, this.recovered = t && this._pid === t, this._pid = t, this.connected = !0, this.emitBuffered(), this.emitReserved("connect"), this._drainQueue(!0);
1051
+ }
1052
+ emitBuffered() {
1053
+ this.receiveBuffer.forEach((e) => this.emitEvent(e)), this.receiveBuffer = [], this.sendBuffer.forEach((e) => {
1054
+ this.notifyOutgoingListeners(e), this.packet(e);
1055
+ }), this.sendBuffer = [];
1056
+ }
1057
+ ondisconnect() {
1058
+ this.destroy(), this.onclose("io server disconnect");
1059
+ }
1060
+ destroy() {
1061
+ this.subs && (this.subs.forEach((e) => e()), this.subs = void 0), this.io._destroy(this);
1062
+ }
1063
+ disconnect() {
1064
+ return this.connected && this.packet({ type: f.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
1065
+ }
1066
+ close() {
1067
+ return this.disconnect();
1068
+ }
1069
+ compress(e) {
1070
+ return this.flags.compress = e, this;
1071
+ }
1072
+ get volatile() {
1073
+ return this.flags.volatile = !0, this;
1074
+ }
1075
+ timeout(e) {
1076
+ return this.flags.timeout = e, this;
1077
+ }
1078
+ onAny(e) {
1079
+ return this._anyListeners = this._anyListeners || [], this._anyListeners.push(e), this;
1080
+ }
1081
+ prependAny(e) {
1082
+ return this._anyListeners = this._anyListeners || [], this._anyListeners.unshift(e), this;
1083
+ }
1084
+ offAny(e) {
1085
+ if (!this._anyListeners) return this;
1086
+ if (e) {
1087
+ const t = this._anyListeners;
1088
+ for (let n = 0; n < t.length; n++) if (e === t[n]) return t.splice(n, 1), this;
1089
+ } else this._anyListeners = [];
1090
+ return this;
1091
+ }
1092
+ listenersAny() {
1093
+ return this._anyListeners || [];
1094
+ }
1095
+ onAnyOutgoing(e) {
1096
+ return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.push(e), this;
1097
+ }
1098
+ prependAnyOutgoing(e) {
1099
+ return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.unshift(e), this;
1100
+ }
1101
+ offAnyOutgoing(e) {
1102
+ if (!this._anyOutgoingListeners) return this;
1103
+ if (e) {
1104
+ const t = this._anyOutgoingListeners;
1105
+ for (let n = 0; n < t.length; n++) if (e === t[n]) return t.splice(n, 1), this;
1106
+ } else this._anyOutgoingListeners = [];
1107
+ return this;
1108
+ }
1109
+ listenersAnyOutgoing() {
1110
+ return this._anyOutgoingListeners || [];
1111
+ }
1112
+ notifyOutgoingListeners(e) {
1113
+ if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
1114
+ const t = this._anyOutgoingListeners.slice();
1115
+ for (const n of t) n.apply(this, e.data);
1116
+ }
1117
+ }
1118
+ }
1119
+ function x(s) {
1120
+ s = s || {}, this.ms = s.min || 100, this.max = s.max || 1e4, this.factor = s.factor || 2, this.jitter = s.jitter > 0 && s.jitter <= 1 ? s.jitter : 0, this.attempts = 0;
1121
+ }
1122
+ x.prototype.duration = function() {
1123
+ var s = this.ms * Math.pow(this.factor, this.attempts++);
1124
+ if (this.jitter) {
1125
+ var e = Math.random(), t = Math.floor(e * this.jitter * s);
1126
+ s = 1 & Math.floor(10 * e) ? s + t : s - t;
1127
+ }
1128
+ return 0 | Math.min(s, this.max);
1129
+ }, x.prototype.reset = function() {
1130
+ this.attempts = 0;
1131
+ }, x.prototype.setMin = function(s) {
1132
+ this.ms = s;
1133
+ }, x.prototype.setMax = function(s) {
1134
+ this.max = s;
1135
+ }, x.prototype.setJitter = function(s) {
1136
+ this.jitter = s;
1137
+ };
1138
+ class ne extends y {
1139
+ constructor(e, t) {
1140
+ var n;
1141
+ super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), (t = t || {}).path = t.path || "/socket.io", this.opts = t, H(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || 1 / 0), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor((n = t.randomizationFactor) !== null && n !== void 0 ? n : 0.5), this.backoff = new x({ min: this.reconnectionDelay(), max: this.reconnectionDelayMax(), jitter: this.randomizationFactor() }), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
1142
+ const r = t.parser || xt;
1143
+ this.encoder = new r.Encoder(), this.decoder = new r.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
1144
+ }
1145
+ reconnection(e) {
1146
+ return arguments.length ? (this._reconnection = !!e, e || (this.skipReconnect = !0), this) : this._reconnection;
1147
+ }
1148
+ reconnectionAttempts(e) {
1149
+ return e === void 0 ? this._reconnectionAttempts : (this._reconnectionAttempts = e, this);
1150
+ }
1151
+ reconnectionDelay(e) {
1152
+ var t;
1153
+ return e === void 0 ? this._reconnectionDelay : (this._reconnectionDelay = e, (t = this.backoff) === null || t === void 0 || t.setMin(e), this);
1154
+ }
1155
+ randomizationFactor(e) {
1156
+ var t;
1157
+ return e === void 0 ? this._randomizationFactor : (this._randomizationFactor = e, (t = this.backoff) === null || t === void 0 || t.setJitter(e), this);
1158
+ }
1159
+ reconnectionDelayMax(e) {
1160
+ var t;
1161
+ return e === void 0 ? this._reconnectionDelayMax : (this._reconnectionDelayMax = e, (t = this.backoff) === null || t === void 0 || t.setMax(e), this);
1162
+ }
1163
+ timeout(e) {
1164
+ return arguments.length ? (this._timeout = e, this) : this._timeout;
1165
+ }
1166
+ maybeReconnectOnOpen() {
1167
+ !this._reconnecting && this._reconnection && this.backoff.attempts === 0 && this.reconnect();
1168
+ }
1169
+ open(e) {
1170
+ if (~this._readyState.indexOf("open")) return this;
1171
+ this.engine = new _t(this.uri, this.opts);
1172
+ const t = this.engine, n = this;
1173
+ this._readyState = "opening", this.skipReconnect = !1;
1174
+ const r = E(t, "open", function() {
1175
+ n.onopen(), e && e();
1176
+ }), i = (a) => {
1177
+ this.cleanup(), this._readyState = "closed", this.emitReserved("error", a), e ? e(a) : this.maybeReconnectOnOpen();
1178
+ }, o = E(t, "error", i);
1179
+ if (this._timeout !== !1) {
1180
+ const a = this._timeout, c = this.setTimeoutFn(() => {
1181
+ r(), i(new Error("timeout")), t.close();
1182
+ }, a);
1183
+ this.opts.autoUnref && c.unref(), this.subs.push(() => {
1184
+ this.clearTimeoutFn(c);
1185
+ });
1186
+ }
1187
+ return this.subs.push(r), this.subs.push(o), this;
1188
+ }
1189
+ connect(e) {
1190
+ return this.open(e);
1191
+ }
1192
+ onopen() {
1193
+ this.cleanup(), this._readyState = "open", this.emitReserved("open");
1194
+ const e = this.engine;
1195
+ this.subs.push(E(e, "ping", this.onping.bind(this)), E(e, "data", this.ondata.bind(this)), E(e, "error", this.onerror.bind(this)), E(e, "close", this.onclose.bind(this)), E(this.decoder, "decoded", this.ondecoded.bind(this)));
1196
+ }
1197
+ onping() {
1198
+ this.emitReserved("ping");
1199
+ }
1200
+ ondata(e) {
1201
+ try {
1202
+ this.decoder.add(e);
1203
+ } catch (t) {
1204
+ this.onclose("parse error", t);
1205
+ }
1206
+ }
1207
+ ondecoded(e) {
1208
+ W(() => {
1209
+ this.emitReserved("packet", e);
1210
+ }, this.setTimeoutFn);
1211
+ }
1212
+ onerror(e) {
1213
+ this.emitReserved("error", e);
1214
+ }
1215
+ socket(e, t) {
1216
+ let n = this.nsps[e];
1217
+ return n ? this._autoConnect && !n.active && n.connect() : (n = new $e(this, e, t), this.nsps[e] = n), n;
1218
+ }
1219
+ _destroy(e) {
1220
+ const t = Object.keys(this.nsps);
1221
+ for (const n of t)
1222
+ if (this.nsps[n].active) return;
1223
+ this._close();
1224
+ }
1225
+ _packet(e) {
1226
+ const t = this.encoder.encode(e);
1227
+ for (let n = 0; n < t.length; n++) this.engine.write(t[n], e.options);
1228
+ }
1229
+ cleanup() {
1230
+ this.subs.forEach((e) => e()), this.subs.length = 0, this.decoder.destroy();
1231
+ }
1232
+ _close() {
1233
+ this.skipReconnect = !0, this._reconnecting = !1, this.onclose("forced close");
1234
+ }
1235
+ disconnect() {
1236
+ return this._close();
1237
+ }
1238
+ onclose(e, t) {
1239
+ var n;
1240
+ this.cleanup(), (n = this.engine) === null || n === void 0 || n.close(), this.backoff.reset(), this._readyState = "closed", this.emitReserved("close", e, t), this._reconnection && !this.skipReconnect && this.reconnect();
1241
+ }
1242
+ reconnect() {
1243
+ if (this._reconnecting || this.skipReconnect) return this;
1244
+ const e = this;
1245
+ if (this.backoff.attempts >= this._reconnectionAttempts) this.backoff.reset(), this.emitReserved("reconnect_failed"), this._reconnecting = !1;
1246
+ else {
1247
+ const t = this.backoff.duration();
1248
+ this._reconnecting = !0;
1249
+ const n = this.setTimeoutFn(() => {
1250
+ e.skipReconnect || (this.emitReserved("reconnect_attempt", e.backoff.attempts), e.skipReconnect || e.open((r) => {
1251
+ r ? (e._reconnecting = !1, e.reconnect(), this.emitReserved("reconnect_error", r)) : e.onreconnect();
1252
+ }));
1253
+ }, t);
1254
+ this.opts.autoUnref && n.unref(), this.subs.push(() => {
1255
+ this.clearTimeoutFn(n);
1256
+ });
1257
+ }
1258
+ }
1259
+ onreconnect() {
1260
+ const e = this.backoff.attempts;
1261
+ this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
1262
+ }
1263
+ }
1264
+ const N = {};
1265
+ function F(s, e) {
1266
+ typeof s == "object" && (e = s, s = void 0);
1267
+ const t = function(c, h = "", u) {
1268
+ let l = c;
1269
+ u = u || typeof location != "undefined" && location, c == null && (c = u.protocol + "//" + u.host), typeof c == "string" && (c.charAt(0) === "/" && (c = c.charAt(1) === "/" ? u.protocol + c : u.host + c), /^(https?|wss?):\/\//.test(c) || (c = u !== void 0 ? u.protocol + "//" + c : "https://" + c), l = Z(c)), l.port || (/^(http|ws)$/.test(l.protocol) ? l.port = "80" : /^(http|ws)s$/.test(l.protocol) && (l.port = "443")), l.path = l.path || "/";
1270
+ const d = l.host.indexOf(":") !== -1 ? "[" + l.host + "]" : l.host;
1271
+ return l.id = l.protocol + "://" + d + ":" + l.port + h, l.href = l.protocol + "://" + d + (u && u.port === l.port ? "" : ":" + l.port), l;
1272
+ }(s, (e = e || {}).path || "/socket.io"), n = t.source, r = t.id, i = t.path, o = N[r] && i in N[r].nsps;
1273
+ let a;
1274
+ return e.forceNew || e["force new connection"] || e.multiplex === !1 || o ? a = new ne(n, e) : (N[r] || (N[r] = new ne(n, e)), a = N[r]), t.query && !e.query && (e.query = t.queryKey), a.socket(t.path, e);
1275
+ }
1276
+ Object.assign(F, { Manager: ne, Socket: $e, io: F, connect: F });
1277
+ class Ot {
1278
+ constructor(e) {
1279
+ b(this, "socket");
1280
+ b(this, "encode");
1281
+ var t;
1282
+ this.socket = F(e.baseUrl, { transports: ["websocket"], path: "/analytics/ws", auth: { token: e.authToken }, query: e.query }), this.encode = (t = e.encoder) != null ? t : (n) => function(r) {
1283
+ const i = new TextEncoder().encode(r);
1284
+ if (typeof window != "undefined" && typeof window.btoa == "function") {
1285
+ const o = Array.from(i, (a) => String.fromCharCode(a)).join("");
1286
+ return btoa(o);
1287
+ }
1288
+ if (typeof Buffer != "undefined") return Buffer.from(i).toString("base64");
1289
+ throw new Error("[utils.base64Encode]: Unsupported environment");
1290
+ }(JSON.stringify(n));
1291
+ }
1292
+ send(e, t) {
1293
+ this.socket.emit(e, this.encode(t));
1294
+ }
1295
+ }
1296
+ class Nt {
1297
+ constructor(e) {
1298
+ b(this, "options");
1299
+ b(this, "client");
1300
+ b(this, "userId");
1301
+ b(this, "global");
1302
+ b(this, "queue", []);
1303
+ this.options = e;
1304
+ const t = { sdk_name: e.sdk || "node", sdk_version: e.sdkVersion || "" };
1305
+ this.client = new Ot({ baseUrl: e.apiUrl || "https://analytic.brainfi.sh", authToken: e.accessKey, query: t });
1306
+ }
1307
+ init() {
1308
+ }
1309
+ ready() {
1310
+ this.options.waitForUser = !1, this.flush();
1311
+ }
1312
+ send(e) {
1313
+ return p(this, null, function* () {
1314
+ return this.options.disabled || this.options.filter && !this.options.filter(e) ? Promise.resolve() : this.options.waitForUser && !this.userId ? (this.queue.push(e), Promise.resolve()) : this.client.send("t", e);
1315
+ });
1316
+ }
1317
+ setGlobalProperties(e) {
1318
+ this.global = v(v({}, this.global), e);
1319
+ }
1320
+ track(e, t) {
1321
+ return p(this, null, function* () {
1322
+ var n, r;
1323
+ return this.send({ type: "event.track", payload: { name: e, userId: (n = t == null ? void 0 : t.userId) != null ? n : this.userId, properties: v(v({}, (r = this.global) != null ? r : {}), t != null ? t : {}) } });
1324
+ });
1325
+ }
1326
+ identify(e) {
1327
+ return p(this, null, function* () {
1328
+ if (e.userId && (this.userId = e.userId, this.flush()), Object.keys(e).length > 1) return this.send({ type: "user.identify", payload: O(v({}, e), { properties: v(v({}, this.global), e.properties) }) });
1329
+ });
1330
+ }
1331
+ record(e) {
1332
+ return p(this, null, function* () {
1333
+ return this.send({ type: "event.record", payload: { events: e, userId: this.userId } });
1334
+ });
1335
+ }
1336
+ alias(e) {
1337
+ return p(this, null, function* () {
1338
+ return this.send({ type: "user.alias", payload: e });
1339
+ });
1340
+ }
1341
+ increment(e) {
1342
+ return p(this, null, function* () {
1343
+ return this.send({ type: "user.increment", payload: e });
1344
+ });
1345
+ }
1346
+ decrement(e) {
1347
+ return p(this, null, function* () {
1348
+ return this.send({ type: "user.decrement", payload: e });
1349
+ });
1350
+ }
1351
+ clear() {
1352
+ this.userId = void 0;
1353
+ }
1354
+ flush() {
1355
+ this.queue.forEach((e) => {
1356
+ var t;
1357
+ this.send(O(v({}, e), { payload: O(v({}, e.payload), { userId: (t = e.payload.userId) != null ? t : this.userId }) }));
1358
+ }), this.queue = [];
1359
+ }
1360
+ }
1361
+ const Lt = /* @__PURE__ */ (() => {
1362
+ let s = 0;
1363
+ return () => (s += 1, `u${`0000${(Math.random() * fe(36, 4) | 0).toString(36)}`.slice(-4)}${s}`);
1364
+ })();
1365
+ function S(s) {
1366
+ const e = [];
1367
+ for (let t = 0, n = s.length; t < n; t++) e.push(s[t]);
1368
+ return e;
1369
+ }
1370
+ function q(s, e) {
1371
+ const t = (s.ownerDocument.defaultView || window).getComputedStyle(s).getPropertyValue(e);
1372
+ return t ? parseFloat(t.replace("px", "")) : 0;
1373
+ }
1374
+ function Fe(s, e = {}) {
1375
+ return { width: e.width || function(t) {
1376
+ const n = q(t, "border-left-width"), r = q(t, "border-right-width");
1377
+ return t.clientWidth + n + r;
1378
+ }(s), height: e.height || function(t) {
1379
+ const n = q(t, "border-top-width"), r = q(t, "border-bottom-width");
1380
+ return t.clientHeight + n + r;
1381
+ }(s) };
1382
+ }
1383
+ const _ = 16384;
1384
+ function M(s) {
1385
+ return new Promise((e, t) => {
1386
+ const n = new Image();
1387
+ n.decode = () => e(n), n.onload = () => e(n), n.onerror = t, n.crossOrigin = "anonymous", n.decoding = "async", n.src = s;
1388
+ });
1389
+ }
1390
+ function Pt(s, e, t) {
1391
+ return p(this, null, function* () {
1392
+ const n = "http://www.w3.org/2000/svg", r = document.createElementNS(n, "svg"), i = document.createElementNS(n, "foreignObject");
1393
+ return r.setAttribute("width", `${e}`), r.setAttribute("height", `${t}`), r.setAttribute("viewBox", `0 0 ${e} ${t}`), i.setAttribute("width", "100%"), i.setAttribute("height", "100%"), i.setAttribute("x", "0"), i.setAttribute("y", "0"), i.setAttribute("externalResourcesRequired", "true"), r.appendChild(i), i.appendChild(s), function(o) {
1394
+ return p(this, null, function* () {
1395
+ return Promise.resolve().then(() => new XMLSerializer().serializeToString(o)).then(encodeURIComponent).then((a) => `data:image/svg+xml;charset=utf-8,${a}`);
1396
+ });
1397
+ }(r);
1398
+ });
1399
+ }
1400
+ const w = (s, e) => {
1401
+ if (s instanceof e) return !0;
1402
+ const t = Object.getPrototypeOf(s);
1403
+ return t !== null && (t.constructor.name === e.name || w(t, e));
1404
+ };
1405
+ function Bt(s, e, t) {
1406
+ const n = `.${s}:${e}`, r = t.cssText ? function(i) {
1407
+ const o = i.getPropertyValue("content");
1408
+ return `${i.cssText} content: '${o.replace(/'|"/g, "")}';`;
1409
+ }(t) : function(i) {
1410
+ return S(i).map((o) => `${o}: ${i.getPropertyValue(o)}${i.getPropertyPriority(o) ? " !important" : ""};`).join(" ");
1411
+ }(t);
1412
+ return document.createTextNode(`${n}{${r}}`);
1413
+ }
1414
+ function ve(s, e, t) {
1415
+ const n = window.getComputedStyle(s, t), r = n.getPropertyValue("content");
1416
+ if (r === "" || r === "none") return;
1417
+ const i = Lt();
1418
+ try {
1419
+ e.className = `${e.className} ${i}`;
1420
+ } catch (a) {
1421
+ return;
1422
+ }
1423
+ const o = document.createElement("style");
1424
+ o.appendChild(Bt(i, t, n)), e.appendChild(o);
1425
+ }
1426
+ const ke = "application/font-woff", Ee = "image/jpeg", It = { woff: ke, woff2: ke, ttf: "application/font-truetype", eot: "application/vnd.ms-fontobject", png: "image/png", jpg: Ee, jpeg: Ee, gif: "image/gif", tiff: "image/tiff", svg: "image/svg+xml", webp: "image/webp" };
1427
+ function ue(s) {
1428
+ const e = function(t) {
1429
+ const n = /\.([^./]*?)$/g.exec(t);
1430
+ return n ? n[1] : "";
1431
+ }(s).toLowerCase();
1432
+ return It[e] || "";
1433
+ }
1434
+ function re(s) {
1435
+ return s.search(/^(data:)/) !== -1;
1436
+ }
1437
+ function Me(s, e, t) {
1438
+ return p(this, null, function* () {
1439
+ const n = yield fetch(s, e);
1440
+ if (n.status === 404) throw new Error(`Resource "${n.url}" not found`);
1441
+ const r = yield n.blob();
1442
+ return new Promise((i, o) => {
1443
+ const a = new FileReader();
1444
+ a.onerror = o, a.onloadend = () => {
1445
+ try {
1446
+ i(t({ res: n, result: a.result }));
1447
+ } catch (c) {
1448
+ o(c);
1449
+ }
1450
+ }, a.readAsDataURL(r);
1451
+ });
1452
+ });
1453
+ }
1454
+ const J = {};
1455
+ function le(s, e, t) {
1456
+ return p(this, null, function* () {
1457
+ const n = function(i, o, a) {
1458
+ let c = i.replace(/\?.*/, "");
1459
+ return a && (c = i), /ttf|otf|eot|woff2?/i.test(c) && (c = c.replace(/.*\//, "")), o ? `[${o}]${c}` : c;
1460
+ }(s, e, t.includeQueryParams);
1461
+ if (J[n] != null) return J[n];
1462
+ let r;
1463
+ t.cacheBust && (s += (/\?/.test(s) ? "&" : "?") + (/* @__PURE__ */ new Date()).getTime());
1464
+ try {
1465
+ const i = yield Me(s, t.fetchRequestInit, ({ res: o, result: a }) => (e || (e = o.headers.get("Content-Type") || ""), function(c) {
1466
+ return c.split(/,/)[1];
1467
+ }(a)));
1468
+ r = function(o, a) {
1469
+ return `data:${a};base64,${o}`;
1470
+ }(i, e);
1471
+ } catch (i) {
1472
+ r = t.imagePlaceholder || "";
1473
+ let o = `Failed to fetch resource: ${s}`;
1474
+ i && (o = typeof i == "string" ? i : i.message), o && console.warn(o);
1475
+ }
1476
+ return J[n] = r, r;
1477
+ });
1478
+ }
1479
+ function qt(s, e) {
1480
+ return p(this, null, function* () {
1481
+ return w(s, HTMLCanvasElement) ? function(t) {
1482
+ return p(this, null, function* () {
1483
+ const n = t.toDataURL();
1484
+ return n === "data:," ? t.cloneNode(!1) : M(n);
1485
+ });
1486
+ }(s) : w(s, HTMLVideoElement) ? function(t, n) {
1487
+ return p(this, null, function* () {
1488
+ if (t.currentSrc) {
1489
+ const o = document.createElement("canvas"), a = o.getContext("2d");
1490
+ return o.width = t.clientWidth, o.height = t.clientHeight, a == null || a.drawImage(t, 0, 0, o.width, o.height), M(o.toDataURL());
1491
+ }
1492
+ const r = t.poster, i = ue(r);
1493
+ return M(yield le(r, i, n));
1494
+ });
1495
+ }(s, e) : w(s, HTMLIFrameElement) ? function(t) {
1496
+ return p(this, null, function* () {
1497
+ var n;
1498
+ try {
1499
+ if (!((n = t == null ? void 0 : t.contentDocument) === null || n === void 0) && n.body) return yield V(t.contentDocument.body, {}, !0);
1500
+ } catch (r) {
1501
+ }
1502
+ return t.cloneNode(!1);
1503
+ });
1504
+ }(s) : s.cloneNode(!1);
1505
+ });
1506
+ }
1507
+ const jt = (s) => s.tagName != null && s.tagName.toUpperCase() === "SLOT";
1508
+ function Ut(s, e) {
1509
+ return w(e, Element) && (function(t, n) {
1510
+ const r = n.style;
1511
+ if (!r) return;
1512
+ const i = window.getComputedStyle(t);
1513
+ i.cssText ? (r.cssText = i.cssText, r.transformOrigin = i.transformOrigin) : S(i).forEach((o) => {
1514
+ let a = i.getPropertyValue(o);
1515
+ o === "font-size" && a.endsWith("px") && (a = `${Math.floor(parseFloat(a.substring(0, a.length - 2))) - 0.1}px`), w(t, HTMLIFrameElement) && o === "display" && a === "inline" && (a = "block"), o === "d" && n.getAttribute("d") && (a = `path(${n.getAttribute("d")})`), r.setProperty(o, a, i.getPropertyPriority(o));
1516
+ });
1517
+ }(s, e), function(t, n) {
1518
+ ve(t, n, ":before"), ve(t, n, ":after");
1519
+ }(s, e), function(t, n) {
1520
+ w(t, HTMLTextAreaElement) && (n.innerHTML = t.value), w(t, HTMLInputElement) && n.setAttribute("value", t.value);
1521
+ }(s, e), function(t, n) {
1522
+ if (w(t, HTMLSelectElement)) {
1523
+ const r = n, i = Array.from(r.children).find((o) => t.value === o.getAttribute("value"));
1524
+ i && i.setAttribute("selected", "");
1525
+ }
1526
+ }(s, e)), e;
1527
+ }
1528
+ function V(s, e, t) {
1529
+ return p(this, null, function* () {
1530
+ return t || !e.filter || e.filter(s) ? Promise.resolve(s).then((n) => qt(n, e)).then((n) => function(r, i, o) {
1531
+ return p(this, null, function* () {
1532
+ var a, c;
1533
+ let h = [];
1534
+ return h = jt(r) && r.assignedNodes ? S(r.assignedNodes()) : w(r, HTMLIFrameElement) && (!((a = r.contentDocument) === null || a === void 0) && a.body) ? S(r.contentDocument.body.childNodes) : S(((c = r.shadowRoot) !== null && c !== void 0 ? c : r).childNodes), h.length === 0 || w(r, HTMLVideoElement) || (yield h.reduce((u, l) => u.then(() => V(l, o)).then((d) => {
1535
+ d && i.appendChild(d);
1536
+ }), Promise.resolve())), i;
1537
+ });
1538
+ }(s, n, e)).then((n) => Ut(s, n)).then((n) => function(r, i) {
1539
+ return p(this, null, function* () {
1540
+ const o = r.querySelectorAll ? r.querySelectorAll("use") : [];
1541
+ if (o.length === 0) return r;
1542
+ const a = {};
1543
+ for (let h = 0; h < o.length; h++) {
1544
+ const u = o[h].getAttribute("xlink:href");
1545
+ if (u) {
1546
+ const l = r.querySelector(u), d = document.querySelector(u);
1547
+ l || !d || a[u] || (a[u] = yield V(d, i, !0));
1548
+ }
1549
+ }
1550
+ const c = Object.values(a);
1551
+ if (c.length) {
1552
+ const h = "http://www.w3.org/1999/xhtml", u = document.createElementNS(h, "svg");
1553
+ u.setAttribute("xmlns", h), u.style.position = "absolute", u.style.width = "0", u.style.height = "0", u.style.overflow = "hidden", u.style.display = "none";
1554
+ const l = document.createElementNS(h, "defs");
1555
+ u.appendChild(l);
1556
+ for (let d = 0; d < c.length; d++) l.appendChild(c[d]);
1557
+ r.appendChild(u);
1558
+ }
1559
+ return r;
1560
+ });
1561
+ }(n, e)) : null;
1562
+ });
1563
+ }
1564
+ const Ve = /url\((['"]?)([^'"]+?)\1\)/g, Dt = /url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g, $t = /src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;
1565
+ function Ft(s, e, t, n, r) {
1566
+ return p(this, null, function* () {
1567
+ try {
1568
+ const i = t ? function(c, h) {
1569
+ if (c.match(/^[a-z]+:\/\//i)) return c;
1570
+ if (c.match(/^\/\//)) return window.location.protocol + c;
1571
+ if (c.match(/^[a-z]+:/i)) return c;
1572
+ const u = document.implementation.createHTMLDocument(), l = u.createElement("base"), d = u.createElement("a");
1573
+ return u.head.appendChild(l), u.body.appendChild(d), h && (l.href = h), d.href = c, d.href;
1574
+ }(e, t) : e, o = ue(e);
1575
+ let a;
1576
+ return r || (a = yield le(i, o, n)), s.replace(function(c) {
1577
+ const h = c.replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1");
1578
+ return new RegExp(`(url\\(['"]?)(${h})(['"]?\\))`, "g");
1579
+ }(e), `$1${a}$3`);
1580
+ } catch (i) {
1581
+ }
1582
+ return s;
1583
+ });
1584
+ }
1585
+ function We(s) {
1586
+ return s.search(Ve) !== -1;
1587
+ }
1588
+ function He(s, e, t) {
1589
+ return p(this, null, function* () {
1590
+ if (!We(s)) return s;
1591
+ const n = function(i, { preferredFontFormat: o }) {
1592
+ return o ? i.replace($t, (a) => {
1593
+ for (; ; ) {
1594
+ const [c, , h] = Dt.exec(a) || [];
1595
+ if (!h) return "";
1596
+ if (h === o) return `src: ${c};`;
1597
+ }
1598
+ }) : i;
1599
+ }(s, t);
1600
+ return function(i) {
1601
+ const o = [];
1602
+ return i.replace(Ve, (a, c, h) => (o.push(h), a)), o.filter((a) => !re(a));
1603
+ }(n).reduce((i, o) => i.then((a) => Ft(a, o, e, t)), Promise.resolve(n));
1604
+ });
1605
+ }
1606
+ function j(s, e, t) {
1607
+ return p(this, null, function* () {
1608
+ var n;
1609
+ const r = (n = e.style) === null || n === void 0 ? void 0 : n.getPropertyValue(s);
1610
+ if (r) {
1611
+ const i = yield He(r, null, t);
1612
+ return e.style.setProperty(s, i, e.style.getPropertyPriority(s)), !0;
1613
+ }
1614
+ return !1;
1615
+ });
1616
+ }
1617
+ function ze(s, e) {
1618
+ return p(this, null, function* () {
1619
+ w(s, Element) && (yield function(t, n) {
1620
+ return p(this, null, function* () {
1621
+ (yield j("background", t, n)) || (yield j("background-image", t, n)), (yield j("mask", t, n)) || (yield j("mask-image", t, n));
1622
+ });
1623
+ }(s, e), yield function(t, n) {
1624
+ return p(this, null, function* () {
1625
+ const r = w(t, HTMLImageElement);
1626
+ if ((!r || re(t.src)) && (!w(t, SVGImageElement) || re(t.href.baseVal))) return;
1627
+ const i = r ? t.src : t.href.baseVal, o = yield le(i, ue(i), n);
1628
+ yield new Promise((a, c) => {
1629
+ t.onload = a, t.onerror = c;
1630
+ const h = t;
1631
+ h.decode && (h.decode = a), h.loading === "lazy" && (h.loading = "eager"), r ? (t.srcset = "", t.src = o) : t.href.baseVal = o;
1632
+ });
1633
+ });
1634
+ }(s, e), yield function(t, n) {
1635
+ return p(this, null, function* () {
1636
+ const r = S(t.childNodes).map((i) => ze(i, n));
1637
+ yield Promise.all(r).then(() => t);
1638
+ });
1639
+ }(s, e));
1640
+ });
1641
+ }
1642
+ const Re = {};
1643
+ function Ae(s) {
1644
+ return p(this, null, function* () {
1645
+ let e = Re[s];
1646
+ if (e != null) return e;
1647
+ const t = yield fetch(s);
1648
+ return e = { url: s, cssText: yield t.text() }, Re[s] = e, e;
1649
+ });
1650
+ }
1651
+ function Se(s, e) {
1652
+ return p(this, null, function* () {
1653
+ let t = s.cssText;
1654
+ const n = /url\(["']?([^"')]+)["']?\)/g, r = (t.match(/url\([^)]+\)/g) || []).map((i) => p(this, null, function* () {
1655
+ let o = i.replace(n, "$1");
1656
+ return o.startsWith("https://") || (o = new URL(o, s.url).href), Me(o, e.fetchRequestInit, ({ result: a }) => (t = t.replace(i, `url(${a})`), [i, a]));
1657
+ }));
1658
+ return Promise.all(r).then(() => t);
1659
+ });
1660
+ }
1661
+ function Te(s) {
1662
+ if (s == null) return [];
1663
+ const e = [];
1664
+ let t = s.replace(/(\/\*[\s\S]*?\*\/)/gi, "");
1665
+ const n = new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})", "gi");
1666
+ for (; ; ) {
1667
+ const o = n.exec(t);
1668
+ if (o === null) break;
1669
+ e.push(o[0]);
1670
+ }
1671
+ t = t.replace(n, "");
1672
+ const r = /@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi, i = new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})", "gi");
1673
+ for (; ; ) {
1674
+ let o = r.exec(t);
1675
+ if (o === null) {
1676
+ if (o = i.exec(t), o === null) break;
1677
+ r.lastIndex = i.lastIndex;
1678
+ } else i.lastIndex = r.lastIndex;
1679
+ e.push(o[0]);
1680
+ }
1681
+ return e;
1682
+ }
1683
+ function Mt(s, e) {
1684
+ return p(this, null, function* () {
1685
+ if (s.ownerDocument == null) throw new Error("Provided element is not within a Document");
1686
+ const t = S(s.ownerDocument.styleSheets), n = yield function(r, i) {
1687
+ return p(this, null, function* () {
1688
+ const o = [], a = [];
1689
+ return r.forEach((c) => {
1690
+ if ("cssRules" in c) try {
1691
+ S(c.cssRules || []).forEach((h, u) => {
1692
+ if (h.type === CSSRule.IMPORT_RULE) {
1693
+ let l = u + 1;
1694
+ const d = Ae(h.href).then((m) => Se(m, i)).then((m) => Te(m).forEach((g) => {
1695
+ try {
1696
+ c.insertRule(g, g.startsWith("@import") ? l += 1 : c.cssRules.length);
1697
+ } catch (C) {
1698
+ console.error("Error inserting rule from remote css", { rule: g, error: C });
1699
+ }
1700
+ })).catch((m) => {
1701
+ console.error("Error loading remote css", m.toString());
1702
+ });
1703
+ a.push(d);
1704
+ }
1705
+ });
1706
+ } catch (h) {
1707
+ const u = r.find((l) => l.href == null) || document.styleSheets[0];
1708
+ c.href != null && a.push(Ae(c.href).then((l) => Se(l, i)).then((l) => Te(l).forEach((d) => {
1709
+ u.insertRule(d, c.cssRules.length);
1710
+ })).catch((l) => {
1711
+ console.error("Error loading remote stylesheet", l);
1712
+ })), console.error("Error inlining remote css file", h);
1713
+ }
1714
+ }), Promise.all(a).then(() => (r.forEach((c) => {
1715
+ if ("cssRules" in c) try {
1716
+ S(c.cssRules || []).forEach((h) => {
1717
+ o.push(h);
1718
+ });
1719
+ } catch (h) {
1720
+ console.error(`Error while reading CSS rules from ${c.href}`, h);
1721
+ }
1722
+ }), o));
1723
+ });
1724
+ }(t, e);
1725
+ return function(r) {
1726
+ return r.filter((i) => i.type === CSSRule.FONT_FACE_RULE).filter((i) => We(i.style.getPropertyValue("src")));
1727
+ }(n);
1728
+ });
1729
+ }
1730
+ function Vt(s, e) {
1731
+ return p(this, null, function* () {
1732
+ const t = e.fontEmbedCSS != null ? e.fontEmbedCSS : e.skipFonts ? null : yield function(n, r) {
1733
+ return p(this, null, function* () {
1734
+ const i = yield Mt(n, r);
1735
+ return (yield Promise.all(i.map((o) => {
1736
+ const a = o.parentStyleSheet ? o.parentStyleSheet.href : null;
1737
+ return He(o.cssText, a, r);
1738
+ }))).join(`
1739
+ `);
1740
+ });
1741
+ }(s, e);
1742
+ if (t) {
1743
+ const n = document.createElement("style"), r = document.createTextNode(t);
1744
+ n.appendChild(r), s.firstChild ? s.insertBefore(n, s.firstChild) : s.appendChild(n);
1745
+ }
1746
+ });
1747
+ }
1748
+ function Wt(t) {
1749
+ return p(this, arguments, function* (s, e = {}) {
1750
+ const { width: n, height: r } = Fe(s, e), i = yield V(s, e, !0);
1751
+ return yield Vt(i, e), yield ze(i, e), function(o, a) {
1752
+ const { style: c } = o;
1753
+ a.backgroundColor && (c.backgroundColor = a.backgroundColor), a.width && (c.width = `${a.width}px`), a.height && (c.height = `${a.height}px`);
1754
+ const h = a.style;
1755
+ h != null && Object.keys(h).forEach((u) => {
1756
+ c[u] = h[u];
1757
+ });
1758
+ }(i, e), yield Pt(i, n, r);
1759
+ });
1760
+ }
1761
+ function Ht(t) {
1762
+ return p(this, arguments, function* (s, e = {}) {
1763
+ const { width: n, height: r } = Fe(s, e), i = yield Wt(s, e), o = yield M(i), a = document.createElement("canvas"), c = a.getContext("2d"), h = e.pixelRatio || function() {
1764
+ let d, m;
1765
+ try {
1766
+ m = process;
1767
+ } catch (C) {
1768
+ }
1769
+ const g = m && m.env ? m.env.devicePixelRatio : null;
1770
+ return g && (d = parseInt(g, 10), Number.isNaN(d) && (d = 1)), d || window.devicePixelRatio || 1;
1771
+ }(), u = e.canvasWidth || n, l = e.canvasHeight || r;
1772
+ return a.width = u * h, a.height = l * h, e.skipAutoScale || function(d) {
1773
+ (d.width > _ || d.height > _) && (d.width > _ && d.height > _ ? d.width > d.height ? (d.height *= _ / d.width, d.width = _) : (d.width *= _ / d.height, d.height = _) : d.width > _ ? (d.height *= _ / d.width, d.width = _) : (d.width *= _ / d.height, d.height = _));
1774
+ }(a), a.style.width = `${u}`, a.style.height = `${l}`, e.backgroundColor && (c.fillStyle = e.backgroundColor, c.fillRect(0, 0, a.width, a.height)), c.drawImage(o, 0, 0, a.width, a.height), a;
1775
+ });
1776
+ }
1777
+ function zt(s) {
1778
+ return p(this, null, function* () {
1779
+ const e = document.documentElement.scrollHeight, t = document.documentElement.scrollWidth, n = Array.from(document.styleSheets).map((o) => {
1780
+ try {
1781
+ return Array.from(o.cssRules).map((a) => a.cssText).join("");
1782
+ } catch (a) {
1783
+ return console.log("Error accessing stylesheet rules:", a), "";
1784
+ }
1785
+ }).join(`
1786
+ `), r = document.createElement("style");
1787
+ r.textContent = n, s.appendChild(r);
1788
+ const i = yield function(c) {
1789
+ return p(this, arguments, function* (o, a = {}) {
1790
+ return (yield Ht(o, a)).toDataURL();
1791
+ });
1792
+ }(s, { quality: 0.7, width: t, height: e, style: { transform: "scale(1)" }, skipFonts: !0, cacheBust: !0, backgroundColor: "white", fetchRequestInit: { mode: "cors" } });
1793
+ return s.removeChild(r), i;
1794
+ });
1795
+ }
1796
+ const L = new RegExp("(((" + /(^|\.\s+)(dear|hi|hello|greetings|hey|hey there)/gi.source + ")|(" + /(thx|thanks|thank you|regards|best|[a-z]+ly|[a-z]+ regards|all the best|happy [a-z]+ing|take care|have a [a-z]+ (weekend|night|day))/gi.source + "\\s*[,.!]*))[\\s-]*)", "gi"), Q = new RegExp("( ?(([A-Z][a-z]+)|([A-Z]\\.)))+([,.]|[,.]?$)", "gm"), Kt = new RegExp("\\b(\\s*)(\\s*(" + (void 0)("|") + "))+\\b", "gim");
1797
+ class Yt {
1798
+ constructor(e = "PERSON_NAME") {
1799
+ this.replaceWith = e;
1800
+ }
1801
+ redact(e) {
1802
+ L.lastIndex = 0, Q.lastIndex = 0;
1803
+ let t = L.exec(e);
1804
+ for (; t !== null; ) {
1805
+ Q.lastIndex = L.lastIndex;
1806
+ let n = Q.exec(e);
1807
+ if (n !== null && n.index === L.lastIndex) {
1808
+ let r = n[5] === null ? "" : n[5];
1809
+ e = e.slice(0, n.index) + this.replaceWith + r + e.slice(n.index + n[0].length);
1810
+ }
1811
+ t = L.exec(e);
1812
+ }
1813
+ return e = e.replace(Kt, "$1" + this.replaceWith);
1814
+ }
1815
+ }
1816
+ const Xt = new RegExp("(\\d+\\s*(\\w+ ){1,2}" + /(street|st|road|rd|avenue|ave|drive|dr|loop|court|ct|circle|cir|lane|ln|boulevard|blvd|way)\.?\b/gi.source + "(\\s+" + /(apt|bldg|dept|fl|hngr|lot|pier|rm|ste|slip|trlr|unit|#)\.? *[a-z0-9-]+\b/gi.source + ")?)|(" + /P\.? ?O\.? *Box +\d+/gi.source + ")", "gi"), xe = Object.freeze(Object.defineProperty({ __proto__: null, credentials: /(login( cred(ential)?s| info(rmation)?)?|cred(ential)?s) ?:\s*\S+\s+\/?\s*\S+/gi, creditCardNumber: /\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}|\d{4}[ -]?\d{6}[ -]?\d{4}\d?/g, digits: /\b\d{4,}\b/g, emailAddress: /([a-z0-9_\-.+]+)@\w+(\.\w+)*/gi, ipAddress: /(\d{1,3}(\.\d{1,3}){3}|[0-9A-F]{4}(:[0-9A-F]{4}){5}(::|(:0000)+))/gi, password: /(pass(word|phrase)?|secret): \S+/gi, phoneNumber: /(\(?\+?[0-9]{1,2}\)?[-. ]?)?(\(?[0-9]{3}\)?|[0-9]{3})[-. ]?([0-9]{3}[-. ]?[0-9]{4}|\b[A-Z0-9]{7}\b)/g, streetAddress: Xt, url: /([^\s:/?#]+):\/\/([^/?#\s]*)([^?#\s]*)(\?([^#\s]*))?(#([^\s]*))?/g, usSocialSecurityNumber: /\b\d{3}[ -.]\d{2}[ -.]\d{4}\b/g, username: /(user( ?name)?|login): \S+/gi, zipcode: /\b\d{5}\b(-\d{4})?\b/g }, Symbol.toStringTag, { value: "Module" }));
1817
+ function Ke(s) {
1818
+ return s.replace(/[A-Z]/g, (e, t) => t !== 0 ? `_${e.toLowerCase()}` : e.toLowerCase());
1819
+ }
1820
+ class Ye {
1821
+ constructor({ replaceWith: e = Ke("default").toUpperCase(), regexpPattern: t }) {
1822
+ b(this, "regexpMatcher");
1823
+ b(this, "replaceWith");
1824
+ this.replaceWith = e, this.regexpMatcher = t;
1825
+ }
1826
+ redact(e) {
1827
+ return e.replace(this.regexpMatcher, this.replaceWith);
1828
+ }
1829
+ }
1830
+ function Ce(s) {
1831
+ return s.regexpPattern !== void 0 ? new Ye({ regexpPattern: s.regexpPattern, replaceWith: s.replaceWith }) : s;
1832
+ }
1833
+ class Jt {
1834
+ constructor(e) {
1835
+ b(this, "childRedactors", []);
1836
+ b(this, "redact", (e) => {
1837
+ for (const t of this.childRedactors) e = t.redact(e);
1838
+ return e;
1839
+ });
1840
+ this.childRedactors = function(t = {}) {
1841
+ const n = [];
1842
+ t.customRedactors && t.customRedactors.before && t.customRedactors.before.map(Ce).forEach((r) => n.push(r));
1843
+ for (const r of Object.keys(xe)) t.builtInRedactors && t.builtInRedactors[r] && t.builtInRedactors[r].enabled === !1 || n.push(new Ye({ regexpPattern: xe[r], replaceWith: t.globalReplaceWith || Ke(r).toUpperCase() }));
1844
+ return t.builtInRedactors && t.builtInRedactors.names && t.builtInRedactors.names.enabled === !1 || n.push(new Yt(t.globalReplaceWith)), t.customRedactors && t.customRedactors.after && t.customRedactors.after.map(Ce).forEach((r) => n.push(r)), n;
1845
+ }(e);
1846
+ }
1847
+ }
1848
+ const Qt = { before: [{ regexpPattern: /\b[A-Z]\d{7}\b/g, replaceWith: "PASSPORT_NUMBER" }, { regexpPattern: new RegExp("(?<=password: )(.*)", "gi"), replaceWith: "[REDACTED]" }] };
1849
+ function Gt(s) {
1850
+ const e = document.createTreeWalker(s, NodeFilter.SHOW_TEXT, null);
1851
+ let t;
1852
+ for (; t = e.nextNode(); ) {
1853
+ const r = t.nodeValue, i = (n = r, new Jt({ builtInRedactors: { names: { replaceWith: "ANONYMOUS_PERSON" } }, customRedactors: Qt }).redact(n));
1854
+ r !== i && (t.nodeValue = i);
1855
+ }
1856
+ var n;
1857
+ (function(r) {
1858
+ Array.from(r.querySelectorAll('input[type="password"]')).forEach((o) => {
1859
+ o.value = "[REDACTED]";
1860
+ });
1861
+ })(s);
1862
+ }
1863
+ const Zt = "0.0.4-alpha.16";
1864
+ class Xe extends Nt {
1865
+ constructor(t) {
1866
+ super(v({ sdk: "web", sdkVersion: Zt }, t));
1867
+ b(this, "lastPath", "");
1868
+ b(this, "debounceTimer", null);
1869
+ this.options = t, this.isServer() || (this.setGlobalProperties({ __referrer: document.referrer }), this.options.trackOutgoingLinks && this.trackOutgoingLinks(), this.options.trackScreenViews && this.trackScreenViews(), this.options.trackAttributes && this.trackAttributes());
1870
+ }
1871
+ debounce(t, n) {
1872
+ this.debounceTimer && clearTimeout(this.debounceTimer), this.debounceTimer = setTimeout(t, n);
1873
+ }
1874
+ isServer() {
1875
+ return typeof document == "undefined";
1876
+ }
1877
+ trackOutgoingLinks() {
1878
+ this.isServer() || document.addEventListener("click", (t) => {
1879
+ const n = t.target, r = n.closest("a");
1880
+ if (r && n) {
1881
+ const i = r.getAttribute("href");
1882
+ i != null && i.startsWith("http") && super.track("link_out", { href: i, text: r.innerText || r.getAttribute("title") || n.getAttribute("alt") || n.getAttribute("title") });
1883
+ }
1884
+ });
1885
+ }
1886
+ trackScreenViews() {
1887
+ if (this.isServer()) return;
1888
+ this.screenView();
1889
+ const t = history.pushState;
1890
+ history.pushState = function(...i) {
1891
+ const o = t.apply(this, i);
1892
+ return window.dispatchEvent(new Event("pushstate")), window.dispatchEvent(new Event("locationchange")), o;
1893
+ };
1894
+ const n = history.replaceState;
1895
+ history.replaceState = function(...i) {
1896
+ const o = n.apply(this, i);
1897
+ return window.dispatchEvent(new Event("replacestate")), window.dispatchEvent(new Event("locationchange")), o;
1898
+ }, window.addEventListener("popstate", function() {
1899
+ window.dispatchEvent(new Event("locationchange"));
1900
+ });
1901
+ const r = () => this.debounce(() => this.screenView(), 50);
1902
+ this.options.trackHashChanges ? window.addEventListener("hashchange", r) : window.addEventListener("locationchange", r);
1903
+ }
1904
+ trackAttributes() {
1905
+ this.isServer() || document.addEventListener("click", (t) => {
1906
+ const n = t.target, r = n.closest("button"), i = n.closest("a"), o = r != null && r.getAttribute("data-track") ? r : i != null && i.getAttribute("data-track") ? i : null;
1907
+ if (o) {
1908
+ const c = {};
1909
+ for (const u of o.attributes) u.name.startsWith("data-") && u.name !== "data-track" && (c[a = u.name.replace(/^data-/, ""), a.replace(/([-_][a-z])/gi, (l) => l.toUpperCase().replace("-", "").replace("_", ""))] = u.value);
1910
+ const h = o.getAttribute("data-track");
1911
+ h && super.track(h, c);
1912
+ }
1913
+ var a;
1914
+ });
1915
+ }
1916
+ screenView(t, n) {
1917
+ return p(this, null, function* () {
1918
+ if (this.isServer()) return;
1919
+ let r, i;
1920
+ if (typeof t == "string" ? (r = t, i = n) : (r = window.location.href, i = t), this.lastPath === r) return;
1921
+ const o = yield function() {
1922
+ return p(this, null, function* () {
1923
+ try {
1924
+ yield new Promise((h) => {
1925
+ document.readyState === "complete" ? h(null) : window.addEventListener("load", h);
1926
+ });
1927
+ const a = document.body.cloneNode(!0);
1928
+ Gt(a);
1929
+ const c = yield zt(a);
1930
+ return window.location.hostname === "localhost" && console.log(c), c;
1931
+ } catch (a) {
1932
+ console.error("An error occurred:", a);
1933
+ }
1934
+ });
1935
+ }();
1936
+ this.lastPath = r, ge(Xe.prototype, this, "track").call(this, "screen_view", O(v({}, i != null ? i : {}), { screenshot: o, __path: r, __title: document.title }));
1937
+ });
1938
+ }
1939
+ }
1940
+ export {
1941
+ Xe as Tracker,
1942
+ Zt as VERSION
1943
+ };
5
1944
  //# sourceMappingURL=index.js.map