@vunex/support-chat 1.0.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,3106 @@
1
+ import { hasInjectionContext as St, inject as Ct, getCurrentInstance as Nt, ref as b, reactive as Ot, markRaw as J, effectScope as Tt, isRef as se, isReactive as Pe, toRef as ge, toRaw as xt, nextTick as be, getCurrentScope as Rt, onScopeDispose as At, watch as tt, toRefs as Fe, computed as De, defineComponent as Ie, openBlock as C, createElementBlock as O, normalizeClass as Ee, createElementVNode as u, toDisplayString as V, createCommentVNode as U, onMounted as st, onUnmounted as nt, normalizeStyle as Bt, withModifiers as He, Fragment as We, renderList as ze, createBlock as rt, unref as N, createVNode as ke, Transition as Se, withCtx as Ce, createStaticVNode as Lt, withDirectives as Pt, withKeys as Dt, vModelText as It } from "vue";
2
+ function re(s, e, t) {
3
+ return Array.isArray(s) ? (s.length = Math.max(s.length, e), s.splice(e, 1, t), t) : (s[e] = t, t);
4
+ }
5
+ function ye(s, e) {
6
+ if (Array.isArray(s)) {
7
+ s.splice(e, 1);
8
+ return;
9
+ }
10
+ delete s[e];
11
+ }
12
+ /*!
13
+ * pinia v2.3.1
14
+ * (c) 2025 Eduardo San Martin Morote
15
+ * @license MIT
16
+ */
17
+ let Q;
18
+ const he = (s) => Q = s, Vt = process.env.NODE_ENV !== "production" ? Symbol("pinia") : (
19
+ /* istanbul ignore next */
20
+ Symbol()
21
+ );
22
+ function $(s) {
23
+ return s && typeof s == "object" && Object.prototype.toString.call(s) === "[object Object]" && typeof s.toJSON != "function";
24
+ }
25
+ var te;
26
+ (function(s) {
27
+ s.direct = "direct", s.patchObject = "patch object", s.patchFunction = "patch function";
28
+ })(te || (te = {}));
29
+ const Z = typeof window < "u";
30
+ function it(s, e) {
31
+ for (const t in e) {
32
+ const n = e[t];
33
+ if (!(t in s))
34
+ continue;
35
+ const r = s[t];
36
+ $(r) && $(n) && !se(n) && !Pe(n) ? s[t] = it(r, n) : s[t] = n;
37
+ }
38
+ return s;
39
+ }
40
+ const ot = () => {
41
+ };
42
+ function je(s, e, t, n = ot) {
43
+ s.push(e);
44
+ const r = () => {
45
+ const i = s.indexOf(e);
46
+ i > -1 && (s.splice(i, 1), n());
47
+ };
48
+ return !t && Rt() && At(r), r;
49
+ }
50
+ function H(s, ...e) {
51
+ s.slice().forEach((t) => {
52
+ t(...e);
53
+ });
54
+ }
55
+ const Ut = (s) => s(), Ke = Symbol(), me = Symbol();
56
+ function Ne(s, e) {
57
+ s instanceof Map && e instanceof Map ? e.forEach((t, n) => s.set(n, t)) : s instanceof Set && e instanceof Set && e.forEach(s.add, s);
58
+ for (const t in e) {
59
+ if (!e.hasOwnProperty(t))
60
+ continue;
61
+ const n = e[t], r = s[t];
62
+ $(r) && $(n) && s.hasOwnProperty(t) && !se(n) && !Pe(n) ? s[t] = Ne(r, n) : s[t] = n;
63
+ }
64
+ return s;
65
+ }
66
+ const Mt = process.env.NODE_ENV !== "production" ? Symbol("pinia:skipHydration") : (
67
+ /* istanbul ignore next */
68
+ Symbol()
69
+ );
70
+ function qt(s) {
71
+ return !$(s) || !s.hasOwnProperty(Mt);
72
+ }
73
+ const { assign: B } = Object;
74
+ function Ye(s) {
75
+ return !!(se(s) && s.effect);
76
+ }
77
+ function Xe(s, e, t, n) {
78
+ const { state: r, actions: i, getters: c } = e, l = t.state.value[s];
79
+ let h;
80
+ function f() {
81
+ !l && (process.env.NODE_ENV === "production" || !n) && (t.state.value[s] = r ? r() : {});
82
+ const p = process.env.NODE_ENV !== "production" && n ? (
83
+ // use ref() to unwrap refs inside state TODO: check if this is still necessary
84
+ Fe(b(r ? r() : {}).value)
85
+ ) : Fe(t.state.value[s]);
86
+ return B(p, i, Object.keys(c || {}).reduce((g, w) => (process.env.NODE_ENV !== "production" && w in p && console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${w}" in store "${s}".`), g[w] = J(De(() => {
87
+ he(t);
88
+ const T = t._s.get(s);
89
+ return c[w].call(T, T);
90
+ })), g), {}));
91
+ }
92
+ return h = Oe(s, f, e, t, n, !0), h;
93
+ }
94
+ function Oe(s, e, t = {}, n, r, i) {
95
+ let c;
96
+ const l = B({ actions: {} }, t);
97
+ if (process.env.NODE_ENV !== "production" && !n._e.active)
98
+ throw new Error("Pinia destroyed");
99
+ const h = { deep: !0 };
100
+ process.env.NODE_ENV !== "production" && (h.onTrigger = (o) => {
101
+ f ? T = o : f == !1 && !d._hotUpdating && (Array.isArray(T) ? T.push(o) : console.error("🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug."));
102
+ });
103
+ let f, p, g = [], w = [], T;
104
+ const x = n.state.value[s];
105
+ !i && !x && (process.env.NODE_ENV === "production" || !r) && (n.state.value[s] = {});
106
+ const F = b({});
107
+ let z;
108
+ function j(o) {
109
+ let a;
110
+ f = p = !1, process.env.NODE_ENV !== "production" && (T = []), typeof o == "function" ? (o(n.state.value[s]), a = {
111
+ type: te.patchFunction,
112
+ storeId: s,
113
+ events: T
114
+ }) : (Ne(n.state.value[s], o), a = {
115
+ type: te.patchObject,
116
+ payload: o,
117
+ storeId: s,
118
+ events: T
119
+ });
120
+ const m = z = Symbol();
121
+ be().then(() => {
122
+ z === m && (f = !0);
123
+ }), p = !0, H(g, a, n.state.value[s]);
124
+ }
125
+ const q = i ? function() {
126
+ const { state: a } = t, m = a ? a() : {};
127
+ this.$patch((R) => {
128
+ B(R, m);
129
+ });
130
+ } : (
131
+ /* istanbul ignore next */
132
+ process.env.NODE_ENV !== "production" ? () => {
133
+ throw new Error(`🍍: Store "${s}" is built using the setup syntax and does not implement $reset().`);
134
+ } : ot
135
+ );
136
+ function ne() {
137
+ c.stop(), g = [], w = [], n._s.delete(s);
138
+ }
139
+ const k = (o, a = "") => {
140
+ if (Ke in o)
141
+ return o[me] = a, o;
142
+ const m = function() {
143
+ he(n);
144
+ const R = Array.from(arguments), Y = [], pe = [];
145
+ function Et(A) {
146
+ Y.push(A);
147
+ }
148
+ function kt(A) {
149
+ pe.push(A);
150
+ }
151
+ H(w, {
152
+ args: R,
153
+ name: m[me],
154
+ store: d,
155
+ after: Et,
156
+ onError: kt
157
+ });
158
+ let X;
159
+ try {
160
+ X = o.apply(this && this.$id === s ? this : d, R);
161
+ } catch (A) {
162
+ throw H(pe, A), A;
163
+ }
164
+ return X instanceof Promise ? X.then((A) => (H(Y, A), A)).catch((A) => (H(pe, A), Promise.reject(A))) : (H(Y, X), X);
165
+ };
166
+ return m[Ke] = !0, m[me] = a, m;
167
+ }, _ = /* @__PURE__ */ J({
168
+ actions: {},
169
+ getters: {},
170
+ state: [],
171
+ hotState: F
172
+ }), S = {
173
+ _p: n,
174
+ // _s: scope,
175
+ $id: s,
176
+ $onAction: je.bind(null, w),
177
+ $patch: j,
178
+ $reset: q,
179
+ $subscribe(o, a = {}) {
180
+ const m = je(g, o, a.detached, () => R()), R = c.run(() => tt(() => n.state.value[s], (Y) => {
181
+ (a.flush === "sync" ? p : f) && o({
182
+ storeId: s,
183
+ type: te.direct,
184
+ events: T
185
+ }, Y);
186
+ }, B({}, h, a)));
187
+ return m;
188
+ },
189
+ $dispose: ne
190
+ }, d = Ot(process.env.NODE_ENV !== "production" || process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test" && Z ? B(
191
+ {
192
+ _hmrPayload: _,
193
+ _customProperties: J(/* @__PURE__ */ new Set())
194
+ // devtools custom properties
195
+ },
196
+ S
197
+ // must be added later
198
+ // setupStore
199
+ ) : S);
200
+ n._s.set(s, d);
201
+ const y = (n._a && n._a.runWithContext || Ut)(() => n._e.run(() => (c = Tt()).run(() => e({ action: k }))));
202
+ for (const o in y) {
203
+ const a = y[o];
204
+ if (se(a) && !Ye(a) || Pe(a))
205
+ process.env.NODE_ENV !== "production" && r ? re(F.value, o, ge(y, o)) : i || (x && qt(a) && (se(a) ? a.value = x[o] : Ne(a, x[o])), n.state.value[s][o] = a), process.env.NODE_ENV !== "production" && _.state.push(o);
206
+ else if (typeof a == "function") {
207
+ const m = process.env.NODE_ENV !== "production" && r ? a : k(a, o);
208
+ y[o] = m, process.env.NODE_ENV !== "production" && (_.actions[o] = a), l.actions[o] = a;
209
+ } else process.env.NODE_ENV !== "production" && Ye(a) && (_.getters[o] = i ? (
210
+ // @ts-expect-error
211
+ t.getters[o]
212
+ ) : a, Z && (y._getters || // @ts-expect-error: same
213
+ (y._getters = J([]))).push(o));
214
+ }
215
+ if (B(d, y), B(xt(d), y), Object.defineProperty(d, "$state", {
216
+ get: () => process.env.NODE_ENV !== "production" && r ? F.value : n.state.value[s],
217
+ set: (o) => {
218
+ if (process.env.NODE_ENV !== "production" && r)
219
+ throw new Error("cannot set hotState");
220
+ j((a) => {
221
+ B(a, o);
222
+ });
223
+ }
224
+ }), process.env.NODE_ENV !== "production" && (d._hotUpdate = J((o) => {
225
+ d._hotUpdating = !0, o._hmrPayload.state.forEach((a) => {
226
+ if (a in d.$state) {
227
+ const m = o.$state[a], R = d.$state[a];
228
+ typeof m == "object" && $(m) && $(R) ? it(m, R) : o.$state[a] = R;
229
+ }
230
+ re(d, a, ge(o.$state, a));
231
+ }), Object.keys(d.$state).forEach((a) => {
232
+ a in o.$state || ye(d, a);
233
+ }), f = !1, p = !1, n.state.value[s] = ge(o._hmrPayload, "hotState"), p = !0, be().then(() => {
234
+ f = !0;
235
+ });
236
+ for (const a in o._hmrPayload.actions) {
237
+ const m = o[a];
238
+ re(d, a, k(m, a));
239
+ }
240
+ for (const a in o._hmrPayload.getters) {
241
+ const m = o._hmrPayload.getters[a], R = i ? (
242
+ // special handling of options api
243
+ De(() => (he(n), m.call(d, d)))
244
+ ) : m;
245
+ re(d, a, R);
246
+ }
247
+ Object.keys(d._hmrPayload.getters).forEach((a) => {
248
+ a in o._hmrPayload.getters || ye(d, a);
249
+ }), Object.keys(d._hmrPayload.actions).forEach((a) => {
250
+ a in o._hmrPayload.actions || ye(d, a);
251
+ }), d._hmrPayload = o._hmrPayload, d._getters = o._getters, d._hotUpdating = !1;
252
+ })), process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test" && Z) {
253
+ const o = {
254
+ writable: !0,
255
+ configurable: !0,
256
+ // avoid warning on devtools trying to display this property
257
+ enumerable: !1
258
+ };
259
+ ["_p", "_hmrPayload", "_getters", "_customProperties"].forEach((a) => {
260
+ Object.defineProperty(d, a, B({ value: d[a] }, o));
261
+ });
262
+ }
263
+ return n._p.forEach((o) => {
264
+ if (process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test" && Z) {
265
+ const a = c.run(() => o({
266
+ store: d,
267
+ app: n._a,
268
+ pinia: n,
269
+ options: l
270
+ }));
271
+ Object.keys(a || {}).forEach((m) => d._customProperties.add(m)), B(d, a);
272
+ } else
273
+ B(d, c.run(() => o({
274
+ store: d,
275
+ app: n._a,
276
+ pinia: n,
277
+ options: l
278
+ })));
279
+ }), process.env.NODE_ENV !== "production" && d.$state && typeof d.$state == "object" && typeof d.$state.constructor == "function" && !d.$state.constructor.toString().includes("[native code]") && console.warn(`[🍍]: The "state" must be a plain object. It cannot be
280
+ state: () => new MyClass()
281
+ Found in store "${d.$id}".`), x && i && t.hydrate && t.hydrate(d.$state, x), f = !0, p = !0, d;
282
+ }
283
+ /*! #__NO_SIDE_EFFECTS__ */
284
+ // @__NO_SIDE_EFFECTS__
285
+ function $t(s, e, t) {
286
+ let n, r;
287
+ const i = typeof e == "function";
288
+ n = s, r = i ? t : e;
289
+ function c(l, h) {
290
+ const f = St();
291
+ if (l = // in test mode, ignore the argument provided as we can always retrieve a
292
+ // pinia instance with getActivePinia()
293
+ (process.env.NODE_ENV === "test" && Q && Q._testing ? null : l) || (f ? Ct(Vt, null) : null), l && he(l), process.env.NODE_ENV !== "production" && !Q)
294
+ throw new Error(`[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"?
295
+ See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help.
296
+ This will fail in production.`);
297
+ l = Q, l._s.has(n) || (i ? Oe(n, e, r, l) : Xe(n, r, l), process.env.NODE_ENV !== "production" && (c._pinia = l));
298
+ const p = l._s.get(n);
299
+ if (process.env.NODE_ENV !== "production" && h) {
300
+ const g = "__hot:" + n, w = i ? Oe(g, e, r, l, !0) : Xe(g, B({}, r), l, !0);
301
+ h._hotUpdate(w), delete l.state.value[g], l._s.delete(g);
302
+ }
303
+ if (process.env.NODE_ENV !== "production" && Z) {
304
+ const g = Nt();
305
+ if (g && g.proxy && // avoid adding stores that are just built for hot module replacement
306
+ !h) {
307
+ const w = g.proxy, T = "_pStores" in w ? w._pStores : w._pStores = {};
308
+ T[n] = p;
309
+ }
310
+ }
311
+ return p;
312
+ }
313
+ return c.$id = n, c;
314
+ }
315
+ const I = /* @__PURE__ */ Object.create(null);
316
+ I.open = "0";
317
+ I.close = "1";
318
+ I.ping = "2";
319
+ I.pong = "3";
320
+ I.message = "4";
321
+ I.upgrade = "5";
322
+ I.noop = "6";
323
+ const ae = /* @__PURE__ */ Object.create(null);
324
+ Object.keys(I).forEach((s) => {
325
+ ae[I[s]] = s;
326
+ });
327
+ const Te = { type: "error", data: "parser error" }, at = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", ct = typeof ArrayBuffer == "function", lt = (s) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(s) : s && s.buffer instanceof ArrayBuffer, Ve = ({ type: s, data: e }, t, n) => at && e instanceof Blob ? t ? n(e) : Ge(e, n) : ct && (e instanceof ArrayBuffer || lt(e)) ? t ? n(e) : Ge(new Blob([e]), n) : n(I[s] + (e || "")), Ge = (s, e) => {
328
+ const t = new FileReader();
329
+ return t.onload = function() {
330
+ const n = t.result.split(",")[1];
331
+ e("b" + (n || ""));
332
+ }, t.readAsDataURL(s);
333
+ };
334
+ function Je(s) {
335
+ return s instanceof Uint8Array ? s : s instanceof ArrayBuffer ? new Uint8Array(s) : new Uint8Array(s.buffer, s.byteOffset, s.byteLength);
336
+ }
337
+ let ve;
338
+ function Ft(s, e) {
339
+ if (at && s.data instanceof Blob)
340
+ return s.data.arrayBuffer().then(Je).then(e);
341
+ if (ct && (s.data instanceof ArrayBuffer || lt(s.data)))
342
+ return e(Je(s.data));
343
+ Ve(s, !1, (t) => {
344
+ ve || (ve = new TextEncoder()), e(ve.encode(t));
345
+ });
346
+ }
347
+ const Qe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", ee = typeof Uint8Array > "u" ? [] : new Uint8Array(256);
348
+ for (let s = 0; s < Qe.length; s++)
349
+ ee[Qe.charCodeAt(s)] = s;
350
+ const Ht = (s) => {
351
+ let e = s.length * 0.75, t = s.length, n, r = 0, i, c, l, h;
352
+ s[s.length - 1] === "=" && (e--, s[s.length - 2] === "=" && e--);
353
+ const f = new ArrayBuffer(e), p = new Uint8Array(f);
354
+ for (n = 0; n < t; n += 4)
355
+ i = ee[s.charCodeAt(n)], c = ee[s.charCodeAt(n + 1)], l = ee[s.charCodeAt(n + 2)], h = ee[s.charCodeAt(n + 3)], p[r++] = i << 2 | c >> 4, p[r++] = (c & 15) << 4 | l >> 2, p[r++] = (l & 3) << 6 | h & 63;
356
+ return f;
357
+ }, Wt = typeof ArrayBuffer == "function", Ue = (s, e) => {
358
+ if (typeof s != "string")
359
+ return {
360
+ type: "message",
361
+ data: ut(s, e)
362
+ };
363
+ const t = s.charAt(0);
364
+ return t === "b" ? {
365
+ type: "message",
366
+ data: zt(s.substring(1), e)
367
+ } : ae[t] ? s.length > 1 ? {
368
+ type: ae[t],
369
+ data: s.substring(1)
370
+ } : {
371
+ type: ae[t]
372
+ } : Te;
373
+ }, zt = (s, e) => {
374
+ if (Wt) {
375
+ const t = Ht(s);
376
+ return ut(t, e);
377
+ } else
378
+ return { base64: !0, data: s };
379
+ }, ut = (s, e) => {
380
+ switch (e) {
381
+ case "blob":
382
+ return s instanceof Blob ? s : new Blob([s]);
383
+ case "arraybuffer":
384
+ default:
385
+ return s instanceof ArrayBuffer ? s : s.buffer;
386
+ }
387
+ }, ht = "", jt = (s, e) => {
388
+ const t = s.length, n = new Array(t);
389
+ let r = 0;
390
+ s.forEach((i, c) => {
391
+ Ve(i, !1, (l) => {
392
+ n[c] = l, ++r === t && e(n.join(ht));
393
+ });
394
+ });
395
+ }, Kt = (s, e) => {
396
+ const t = s.split(ht), n = [];
397
+ for (let r = 0; r < t.length; r++) {
398
+ const i = Ue(t[r], e);
399
+ if (n.push(i), i.type === "error")
400
+ break;
401
+ }
402
+ return n;
403
+ };
404
+ function Yt() {
405
+ return new TransformStream({
406
+ transform(s, e) {
407
+ Ft(s, (t) => {
408
+ const n = t.length;
409
+ let r;
410
+ if (n < 126)
411
+ r = new Uint8Array(1), new DataView(r.buffer).setUint8(0, n);
412
+ else if (n < 65536) {
413
+ r = new Uint8Array(3);
414
+ const i = new DataView(r.buffer);
415
+ i.setUint8(0, 126), i.setUint16(1, n);
416
+ } else {
417
+ r = new Uint8Array(9);
418
+ const i = new DataView(r.buffer);
419
+ i.setUint8(0, 127), i.setBigUint64(1, BigInt(n));
420
+ }
421
+ s.data && typeof s.data != "string" && (r[0] |= 128), e.enqueue(r), e.enqueue(t);
422
+ });
423
+ }
424
+ });
425
+ }
426
+ let _e;
427
+ function ie(s) {
428
+ return s.reduce((e, t) => e + t.length, 0);
429
+ }
430
+ function oe(s, e) {
431
+ if (s[0].length === e)
432
+ return s.shift();
433
+ const t = new Uint8Array(e);
434
+ let n = 0;
435
+ for (let r = 0; r < e; r++)
436
+ t[r] = s[0][n++], n === s[0].length && (s.shift(), n = 0);
437
+ return s.length && n < s[0].length && (s[0] = s[0].slice(n)), t;
438
+ }
439
+ function Xt(s, e) {
440
+ _e || (_e = new TextDecoder());
441
+ const t = [];
442
+ let n = 0, r = -1, i = !1;
443
+ return new TransformStream({
444
+ transform(c, l) {
445
+ for (t.push(c); ; ) {
446
+ if (n === 0) {
447
+ if (ie(t) < 1)
448
+ break;
449
+ const h = oe(t, 1);
450
+ i = (h[0] & 128) === 128, r = h[0] & 127, r < 126 ? n = 3 : r === 126 ? n = 1 : n = 2;
451
+ } else if (n === 1) {
452
+ if (ie(t) < 2)
453
+ break;
454
+ const h = oe(t, 2);
455
+ r = new DataView(h.buffer, h.byteOffset, h.length).getUint16(0), n = 3;
456
+ } else if (n === 2) {
457
+ if (ie(t) < 8)
458
+ break;
459
+ const h = oe(t, 8), f = new DataView(h.buffer, h.byteOffset, h.length), p = f.getUint32(0);
460
+ if (p > Math.pow(2, 21) - 1) {
461
+ l.enqueue(Te);
462
+ break;
463
+ }
464
+ r = p * Math.pow(2, 32) + f.getUint32(4), n = 3;
465
+ } else {
466
+ if (ie(t) < r)
467
+ break;
468
+ const h = oe(t, r);
469
+ l.enqueue(Ue(i ? h : _e.decode(h), e)), n = 0;
470
+ }
471
+ if (r === 0 || r > s) {
472
+ l.enqueue(Te);
473
+ break;
474
+ }
475
+ }
476
+ }
477
+ });
478
+ }
479
+ const ft = 4;
480
+ function E(s) {
481
+ if (s) return Gt(s);
482
+ }
483
+ function Gt(s) {
484
+ for (var e in E.prototype)
485
+ s[e] = E.prototype[e];
486
+ return s;
487
+ }
488
+ E.prototype.on = E.prototype.addEventListener = function(s, e) {
489
+ return this._callbacks = this._callbacks || {}, (this._callbacks["$" + s] = this._callbacks["$" + s] || []).push(e), this;
490
+ };
491
+ E.prototype.once = function(s, e) {
492
+ function t() {
493
+ this.off(s, t), e.apply(this, arguments);
494
+ }
495
+ return t.fn = e, this.on(s, t), this;
496
+ };
497
+ E.prototype.off = E.prototype.removeListener = E.prototype.removeAllListeners = E.prototype.removeEventListener = function(s, e) {
498
+ if (this._callbacks = this._callbacks || {}, arguments.length == 0)
499
+ return this._callbacks = {}, this;
500
+ var t = this._callbacks["$" + s];
501
+ if (!t) return this;
502
+ if (arguments.length == 1)
503
+ return delete this._callbacks["$" + s], this;
504
+ for (var n, r = 0; r < t.length; r++)
505
+ if (n = t[r], n === e || n.fn === e) {
506
+ t.splice(r, 1);
507
+ break;
508
+ }
509
+ return t.length === 0 && delete this._callbacks["$" + s], this;
510
+ };
511
+ E.prototype.emit = function(s) {
512
+ this._callbacks = this._callbacks || {};
513
+ for (var e = new Array(arguments.length - 1), t = this._callbacks["$" + s], n = 1; n < arguments.length; n++)
514
+ e[n - 1] = arguments[n];
515
+ if (t) {
516
+ t = t.slice(0);
517
+ for (var n = 0, r = t.length; n < r; ++n)
518
+ t[n].apply(this, e);
519
+ }
520
+ return this;
521
+ };
522
+ E.prototype.emitReserved = E.prototype.emit;
523
+ E.prototype.listeners = function(s) {
524
+ return this._callbacks = this._callbacks || {}, this._callbacks["$" + s] || [];
525
+ };
526
+ E.prototype.hasListeners = function(s) {
527
+ return !!this.listeners(s).length;
528
+ };
529
+ const fe = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), L = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Jt = "arraybuffer";
530
+ function dt(s, ...e) {
531
+ return e.reduce((t, n) => (s.hasOwnProperty(n) && (t[n] = s[n]), t), {});
532
+ }
533
+ const Qt = L.setTimeout, Zt = L.clearTimeout;
534
+ function de(s, e) {
535
+ e.useNativeTimers ? (s.setTimeoutFn = Qt.bind(L), s.clearTimeoutFn = Zt.bind(L)) : (s.setTimeoutFn = L.setTimeout.bind(L), s.clearTimeoutFn = L.clearTimeout.bind(L));
536
+ }
537
+ const es = 1.33;
538
+ function ts(s) {
539
+ return typeof s == "string" ? ss(s) : Math.ceil((s.byteLength || s.size) * es);
540
+ }
541
+ function ss(s) {
542
+ let e = 0, t = 0;
543
+ for (let n = 0, r = s.length; n < r; n++)
544
+ e = s.charCodeAt(n), e < 128 ? t += 1 : e < 2048 ? t += 2 : e < 55296 || e >= 57344 ? t += 3 : (n++, t += 4);
545
+ return t;
546
+ }
547
+ function pt() {
548
+ return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
549
+ }
550
+ function ns(s) {
551
+ let e = "";
552
+ for (let t in s)
553
+ s.hasOwnProperty(t) && (e.length && (e += "&"), e += encodeURIComponent(t) + "=" + encodeURIComponent(s[t]));
554
+ return e;
555
+ }
556
+ function rs(s) {
557
+ let e = {}, t = s.split("&");
558
+ for (let n = 0, r = t.length; n < r; n++) {
559
+ let i = t[n].split("=");
560
+ e[decodeURIComponent(i[0])] = decodeURIComponent(i[1]);
561
+ }
562
+ return e;
563
+ }
564
+ class is extends Error {
565
+ constructor(e, t, n) {
566
+ super(e), this.description = t, this.context = n, this.type = "TransportError";
567
+ }
568
+ }
569
+ class Me extends E {
570
+ /**
571
+ * Transport abstract constructor.
572
+ *
573
+ * @param {Object} opts - options
574
+ * @protected
575
+ */
576
+ constructor(e) {
577
+ super(), this.writable = !1, de(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
578
+ }
579
+ /**
580
+ * Emits an error.
581
+ *
582
+ * @param {String} reason
583
+ * @param description
584
+ * @param context - the error context
585
+ * @return {Transport} for chaining
586
+ * @protected
587
+ */
588
+ onError(e, t, n) {
589
+ return super.emitReserved("error", new is(e, t, n)), this;
590
+ }
591
+ /**
592
+ * Opens the transport.
593
+ */
594
+ open() {
595
+ return this.readyState = "opening", this.doOpen(), this;
596
+ }
597
+ /**
598
+ * Closes the transport.
599
+ */
600
+ close() {
601
+ return (this.readyState === "opening" || this.readyState === "open") && (this.doClose(), this.onClose()), this;
602
+ }
603
+ /**
604
+ * Sends multiple packets.
605
+ *
606
+ * @param {Array} packets
607
+ */
608
+ send(e) {
609
+ this.readyState === "open" && this.write(e);
610
+ }
611
+ /**
612
+ * Called upon open
613
+ *
614
+ * @protected
615
+ */
616
+ onOpen() {
617
+ this.readyState = "open", this.writable = !0, super.emitReserved("open");
618
+ }
619
+ /**
620
+ * Called with data.
621
+ *
622
+ * @param {String} data
623
+ * @protected
624
+ */
625
+ onData(e) {
626
+ const t = Ue(e, this.socket.binaryType);
627
+ this.onPacket(t);
628
+ }
629
+ /**
630
+ * Called with a decoded packet.
631
+ *
632
+ * @protected
633
+ */
634
+ onPacket(e) {
635
+ super.emitReserved("packet", e);
636
+ }
637
+ /**
638
+ * Called upon close.
639
+ *
640
+ * @protected
641
+ */
642
+ onClose(e) {
643
+ this.readyState = "closed", super.emitReserved("close", e);
644
+ }
645
+ /**
646
+ * Pauses the transport, in order not to lose packets during an upgrade.
647
+ *
648
+ * @param onPause
649
+ */
650
+ pause(e) {
651
+ }
652
+ createUri(e, t = {}) {
653
+ return e + "://" + this._hostname() + this._port() + this.opts.path + this._query(t);
654
+ }
655
+ _hostname() {
656
+ const e = this.opts.hostname;
657
+ return e.indexOf(":") === -1 ? e : "[" + e + "]";
658
+ }
659
+ _port() {
660
+ return this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
661
+ }
662
+ _query(e) {
663
+ const t = ns(e);
664
+ return t.length ? "?" + t : "";
665
+ }
666
+ }
667
+ class os extends Me {
668
+ constructor() {
669
+ super(...arguments), this._polling = !1;
670
+ }
671
+ get name() {
672
+ return "polling";
673
+ }
674
+ /**
675
+ * Opens the socket (triggers polling). We write a PING message to determine
676
+ * when the transport is open.
677
+ *
678
+ * @protected
679
+ */
680
+ doOpen() {
681
+ this._poll();
682
+ }
683
+ /**
684
+ * Pauses polling.
685
+ *
686
+ * @param {Function} onPause - callback upon buffers are flushed and transport is paused
687
+ * @package
688
+ */
689
+ pause(e) {
690
+ this.readyState = "pausing";
691
+ const t = () => {
692
+ this.readyState = "paused", e();
693
+ };
694
+ if (this._polling || !this.writable) {
695
+ let n = 0;
696
+ this._polling && (n++, this.once("pollComplete", function() {
697
+ --n || t();
698
+ })), this.writable || (n++, this.once("drain", function() {
699
+ --n || t();
700
+ }));
701
+ } else
702
+ t();
703
+ }
704
+ /**
705
+ * Starts polling cycle.
706
+ *
707
+ * @private
708
+ */
709
+ _poll() {
710
+ this._polling = !0, this.doPoll(), this.emitReserved("poll");
711
+ }
712
+ /**
713
+ * Overloads onData to detect payloads.
714
+ *
715
+ * @protected
716
+ */
717
+ onData(e) {
718
+ const t = (n) => {
719
+ if (this.readyState === "opening" && n.type === "open" && this.onOpen(), n.type === "close")
720
+ return this.onClose({ description: "transport closed by the server" }), !1;
721
+ this.onPacket(n);
722
+ };
723
+ Kt(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
724
+ }
725
+ /**
726
+ * For polling, send a close packet.
727
+ *
728
+ * @protected
729
+ */
730
+ doClose() {
731
+ const e = () => {
732
+ this.write([{ type: "close" }]);
733
+ };
734
+ this.readyState === "open" ? e() : this.once("open", e);
735
+ }
736
+ /**
737
+ * Writes a packets payload.
738
+ *
739
+ * @param {Array} packets - data packets
740
+ * @protected
741
+ */
742
+ write(e) {
743
+ this.writable = !1, jt(e, (t) => {
744
+ this.doWrite(t, () => {
745
+ this.writable = !0, this.emitReserved("drain");
746
+ });
747
+ });
748
+ }
749
+ /**
750
+ * Generates uri for connection.
751
+ *
752
+ * @private
753
+ */
754
+ uri() {
755
+ const e = this.opts.secure ? "https" : "http", t = this.query || {};
756
+ return this.opts.timestampRequests !== !1 && (t[this.opts.timestampParam] = pt()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
757
+ }
758
+ }
759
+ let gt = !1;
760
+ try {
761
+ gt = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
762
+ } catch {
763
+ }
764
+ const as = gt;
765
+ function cs() {
766
+ }
767
+ class ls extends os {
768
+ /**
769
+ * XHR Polling constructor.
770
+ *
771
+ * @param {Object} opts
772
+ * @package
773
+ */
774
+ constructor(e) {
775
+ if (super(e), typeof location < "u") {
776
+ const t = location.protocol === "https:";
777
+ let n = location.port;
778
+ n || (n = t ? "443" : "80"), this.xd = typeof location < "u" && e.hostname !== location.hostname || n !== e.port;
779
+ }
780
+ }
781
+ /**
782
+ * Sends data.
783
+ *
784
+ * @param {String} data to send.
785
+ * @param {Function} called upon flush.
786
+ * @private
787
+ */
788
+ doWrite(e, t) {
789
+ const n = this.request({
790
+ method: "POST",
791
+ data: e
792
+ });
793
+ n.on("success", t), n.on("error", (r, i) => {
794
+ this.onError("xhr post error", r, i);
795
+ });
796
+ }
797
+ /**
798
+ * Starts a poll cycle.
799
+ *
800
+ * @private
801
+ */
802
+ doPoll() {
803
+ const e = this.request();
804
+ e.on("data", this.onData.bind(this)), e.on("error", (t, n) => {
805
+ this.onError("xhr poll error", t, n);
806
+ }), this.pollXhr = e;
807
+ }
808
+ }
809
+ class D extends E {
810
+ /**
811
+ * Request constructor
812
+ *
813
+ * @param {Object} options
814
+ * @package
815
+ */
816
+ constructor(e, t, n) {
817
+ super(), this.createRequest = e, de(this, n), this._opts = n, this._method = n.method || "GET", this._uri = t, this._data = n.data !== void 0 ? n.data : null, this._create();
818
+ }
819
+ /**
820
+ * Creates the XHR object and sends the request.
821
+ *
822
+ * @private
823
+ */
824
+ _create() {
825
+ var e;
826
+ const t = dt(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
827
+ t.xdomain = !!this._opts.xd;
828
+ const n = this._xhr = this.createRequest(t);
829
+ try {
830
+ n.open(this._method, this._uri, !0);
831
+ try {
832
+ if (this._opts.extraHeaders) {
833
+ n.setDisableHeaderCheck && n.setDisableHeaderCheck(!0);
834
+ for (let r in this._opts.extraHeaders)
835
+ this._opts.extraHeaders.hasOwnProperty(r) && n.setRequestHeader(r, this._opts.extraHeaders[r]);
836
+ }
837
+ } catch {
838
+ }
839
+ if (this._method === "POST")
840
+ try {
841
+ n.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
842
+ } catch {
843
+ }
844
+ try {
845
+ n.setRequestHeader("Accept", "*/*");
846
+ } catch {
847
+ }
848
+ (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 = () => {
849
+ var r;
850
+ n.readyState === 3 && ((r = this._opts.cookieJar) === null || r === void 0 || r.parseCookies(
851
+ // @ts-ignore
852
+ n.getResponseHeader("set-cookie")
853
+ )), n.readyState === 4 && (n.status === 200 || n.status === 1223 ? this._onLoad() : this.setTimeoutFn(() => {
854
+ this._onError(typeof n.status == "number" ? n.status : 0);
855
+ }, 0));
856
+ }, n.send(this._data);
857
+ } catch (r) {
858
+ this.setTimeoutFn(() => {
859
+ this._onError(r);
860
+ }, 0);
861
+ return;
862
+ }
863
+ typeof document < "u" && (this._index = D.requestsCount++, D.requests[this._index] = this);
864
+ }
865
+ /**
866
+ * Called upon error.
867
+ *
868
+ * @private
869
+ */
870
+ _onError(e) {
871
+ this.emitReserved("error", e, this._xhr), this._cleanup(!0);
872
+ }
873
+ /**
874
+ * Cleans up house.
875
+ *
876
+ * @private
877
+ */
878
+ _cleanup(e) {
879
+ if (!(typeof this._xhr > "u" || this._xhr === null)) {
880
+ if (this._xhr.onreadystatechange = cs, e)
881
+ try {
882
+ this._xhr.abort();
883
+ } catch {
884
+ }
885
+ typeof document < "u" && delete D.requests[this._index], this._xhr = null;
886
+ }
887
+ }
888
+ /**
889
+ * Called upon load.
890
+ *
891
+ * @private
892
+ */
893
+ _onLoad() {
894
+ const e = this._xhr.responseText;
895
+ e !== null && (this.emitReserved("data", e), this.emitReserved("success"), this._cleanup());
896
+ }
897
+ /**
898
+ * Aborts the request.
899
+ *
900
+ * @package
901
+ */
902
+ abort() {
903
+ this._cleanup();
904
+ }
905
+ }
906
+ D.requestsCount = 0;
907
+ D.requests = {};
908
+ if (typeof document < "u") {
909
+ if (typeof attachEvent == "function")
910
+ attachEvent("onunload", Ze);
911
+ else if (typeof addEventListener == "function") {
912
+ const s = "onpagehide" in L ? "pagehide" : "unload";
913
+ addEventListener(s, Ze, !1);
914
+ }
915
+ }
916
+ function Ze() {
917
+ for (let s in D.requests)
918
+ D.requests.hasOwnProperty(s) && D.requests[s].abort();
919
+ }
920
+ const us = (function() {
921
+ const s = yt({
922
+ xdomain: !1
923
+ });
924
+ return s && s.responseType !== null;
925
+ })();
926
+ class hs extends ls {
927
+ constructor(e) {
928
+ super(e);
929
+ const t = e && e.forceBase64;
930
+ this.supportsBinary = us && !t;
931
+ }
932
+ request(e = {}) {
933
+ return Object.assign(e, { xd: this.xd }, this.opts), new D(yt, this.uri(), e);
934
+ }
935
+ }
936
+ function yt(s) {
937
+ const e = s.xdomain;
938
+ try {
939
+ if (typeof XMLHttpRequest < "u" && (!e || as))
940
+ return new XMLHttpRequest();
941
+ } catch {
942
+ }
943
+ if (!e)
944
+ try {
945
+ return new L[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
946
+ } catch {
947
+ }
948
+ }
949
+ const mt = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
950
+ class fs extends Me {
951
+ get name() {
952
+ return "websocket";
953
+ }
954
+ doOpen() {
955
+ const e = this.uri(), t = this.opts.protocols, n = mt ? {} : dt(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
956
+ this.opts.extraHeaders && (n.headers = this.opts.extraHeaders);
957
+ try {
958
+ this.ws = this.createSocket(e, t, n);
959
+ } catch (r) {
960
+ return this.emitReserved("error", r);
961
+ }
962
+ this.ws.binaryType = this.socket.binaryType, this.addEventListeners();
963
+ }
964
+ /**
965
+ * Adds event listeners to the socket
966
+ *
967
+ * @private
968
+ */
969
+ addEventListeners() {
970
+ this.ws.onopen = () => {
971
+ this.opts.autoUnref && this.ws._socket.unref(), this.onOpen();
972
+ }, this.ws.onclose = (e) => this.onClose({
973
+ description: "websocket connection closed",
974
+ context: e
975
+ }), this.ws.onmessage = (e) => this.onData(e.data), this.ws.onerror = (e) => this.onError("websocket error", e);
976
+ }
977
+ write(e) {
978
+ this.writable = !1;
979
+ for (let t = 0; t < e.length; t++) {
980
+ const n = e[t], r = t === e.length - 1;
981
+ Ve(n, this.supportsBinary, (i) => {
982
+ try {
983
+ this.doWrite(n, i);
984
+ } catch {
985
+ }
986
+ r && fe(() => {
987
+ this.writable = !0, this.emitReserved("drain");
988
+ }, this.setTimeoutFn);
989
+ });
990
+ }
991
+ }
992
+ doClose() {
993
+ typeof this.ws < "u" && (this.ws.onerror = () => {
994
+ }, this.ws.close(), this.ws = null);
995
+ }
996
+ /**
997
+ * Generates uri for connection.
998
+ *
999
+ * @private
1000
+ */
1001
+ uri() {
1002
+ const e = this.opts.secure ? "wss" : "ws", t = this.query || {};
1003
+ return this.opts.timestampRequests && (t[this.opts.timestampParam] = pt()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
1004
+ }
1005
+ }
1006
+ const we = L.WebSocket || L.MozWebSocket;
1007
+ class ds extends fs {
1008
+ createSocket(e, t, n) {
1009
+ return mt ? new we(e, t, n) : t ? new we(e, t) : new we(e);
1010
+ }
1011
+ doWrite(e, t) {
1012
+ this.ws.send(t);
1013
+ }
1014
+ }
1015
+ class ps extends Me {
1016
+ get name() {
1017
+ return "webtransport";
1018
+ }
1019
+ doOpen() {
1020
+ try {
1021
+ this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
1022
+ } catch (e) {
1023
+ return this.emitReserved("error", e);
1024
+ }
1025
+ this._transport.closed.then(() => {
1026
+ this.onClose();
1027
+ }).catch((e) => {
1028
+ this.onError("webtransport error", e);
1029
+ }), this._transport.ready.then(() => {
1030
+ this._transport.createBidirectionalStream().then((e) => {
1031
+ const t = Xt(Number.MAX_SAFE_INTEGER, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = Yt();
1032
+ r.readable.pipeTo(e.writable), this._writer = r.writable.getWriter();
1033
+ const i = () => {
1034
+ n.read().then(({ done: l, value: h }) => {
1035
+ l || (this.onPacket(h), i());
1036
+ }).catch((l) => {
1037
+ });
1038
+ };
1039
+ i();
1040
+ const c = { type: "open" };
1041
+ this.query.sid && (c.data = `{"sid":"${this.query.sid}"}`), this._writer.write(c).then(() => this.onOpen());
1042
+ });
1043
+ });
1044
+ }
1045
+ write(e) {
1046
+ this.writable = !1;
1047
+ for (let t = 0; t < e.length; t++) {
1048
+ const n = e[t], r = t === e.length - 1;
1049
+ this._writer.write(n).then(() => {
1050
+ r && fe(() => {
1051
+ this.writable = !0, this.emitReserved("drain");
1052
+ }, this.setTimeoutFn);
1053
+ });
1054
+ }
1055
+ }
1056
+ doClose() {
1057
+ var e;
1058
+ (e = this._transport) === null || e === void 0 || e.close();
1059
+ }
1060
+ }
1061
+ const gs = {
1062
+ websocket: ds,
1063
+ webtransport: ps,
1064
+ polling: hs
1065
+ }, ys = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, ms = [
1066
+ "source",
1067
+ "protocol",
1068
+ "authority",
1069
+ "userInfo",
1070
+ "user",
1071
+ "password",
1072
+ "host",
1073
+ "port",
1074
+ "relative",
1075
+ "path",
1076
+ "directory",
1077
+ "file",
1078
+ "query",
1079
+ "anchor"
1080
+ ];
1081
+ function xe(s) {
1082
+ if (s.length > 8e3)
1083
+ throw "URI too long";
1084
+ const e = s, t = s.indexOf("["), n = s.indexOf("]");
1085
+ t != -1 && n != -1 && (s = s.substring(0, t) + s.substring(t, n).replace(/:/g, ";") + s.substring(n, s.length));
1086
+ let r = ys.exec(s || ""), i = {}, c = 14;
1087
+ for (; c--; )
1088
+ i[ms[c]] = r[c] || "";
1089
+ 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 = vs(i, i.path), i.queryKey = _s(i, i.query), i;
1090
+ }
1091
+ function vs(s, e) {
1092
+ const t = /\/{2,9}/g, n = e.replace(t, "/").split("/");
1093
+ return (e.slice(0, 1) == "/" || e.length === 0) && n.splice(0, 1), e.slice(-1) == "/" && n.splice(n.length - 1, 1), n;
1094
+ }
1095
+ function _s(s, e) {
1096
+ const t = {};
1097
+ return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(n, r, i) {
1098
+ r && (t[r] = i);
1099
+ }), t;
1100
+ }
1101
+ const Re = typeof addEventListener == "function" && typeof removeEventListener == "function", ce = [];
1102
+ Re && addEventListener("offline", () => {
1103
+ ce.forEach((s) => s());
1104
+ }, !1);
1105
+ class M extends E {
1106
+ /**
1107
+ * Socket constructor.
1108
+ *
1109
+ * @param {String|Object} uri - uri or options
1110
+ * @param {Object} opts - options
1111
+ */
1112
+ constructor(e, t) {
1113
+ if (super(), this.binaryType = Jt, 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) {
1114
+ const n = xe(e);
1115
+ t.hostname = n.host, t.secure = n.protocol === "https" || n.protocol === "wss", t.port = n.port, n.query && (t.query = n.query);
1116
+ } else t.host && (t.hostname = xe(t.host).host);
1117
+ de(this, t), this.secure = t.secure != null ? t.secure : typeof location < "u" && location.protocol === "https:", t.hostname && !t.port && (t.port = this.secure ? "443" : "80"), this.hostname = t.hostname || (typeof location < "u" ? location.hostname : "localhost"), this.port = t.port || (typeof location < "u" && location.port ? location.port : this.secure ? "443" : "80"), this.transports = [], this._transportsByName = {}, t.transports.forEach((n) => {
1118
+ const r = n.prototype.name;
1119
+ this.transports.push(r), this._transportsByName[r] = n;
1120
+ }), this.opts = Object.assign({
1121
+ path: "/engine.io",
1122
+ agent: !1,
1123
+ withCredentials: !1,
1124
+ upgrade: !0,
1125
+ timestampParam: "t",
1126
+ rememberUpgrade: !1,
1127
+ addTrailingSlash: !0,
1128
+ rejectUnauthorized: !0,
1129
+ perMessageDeflate: {
1130
+ threshold: 1024
1131
+ },
1132
+ transportOptions: {},
1133
+ closeOnBeforeunload: !1
1134
+ }, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = rs(this.opts.query)), Re && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
1135
+ this.transport && (this.transport.removeAllListeners(), this.transport.close());
1136
+ }, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
1137
+ this._onClose("transport close", {
1138
+ description: "network connection lost"
1139
+ });
1140
+ }, ce.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
1141
+ }
1142
+ /**
1143
+ * Creates transport of the given type.
1144
+ *
1145
+ * @param {String} name - transport name
1146
+ * @return {Transport}
1147
+ * @private
1148
+ */
1149
+ createTransport(e) {
1150
+ const t = Object.assign({}, this.opts.query);
1151
+ t.EIO = ft, t.transport = e, this.id && (t.sid = this.id);
1152
+ const n = Object.assign({}, this.opts, {
1153
+ query: t,
1154
+ socket: this,
1155
+ hostname: this.hostname,
1156
+ secure: this.secure,
1157
+ port: this.port
1158
+ }, this.opts.transportOptions[e]);
1159
+ return new this._transportsByName[e](n);
1160
+ }
1161
+ /**
1162
+ * Initializes transport to use and starts probe.
1163
+ *
1164
+ * @private
1165
+ */
1166
+ _open() {
1167
+ if (this.transports.length === 0) {
1168
+ this.setTimeoutFn(() => {
1169
+ this.emitReserved("error", "No transports available");
1170
+ }, 0);
1171
+ return;
1172
+ }
1173
+ const e = this.opts.rememberUpgrade && M.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
1174
+ this.readyState = "opening";
1175
+ const t = this.createTransport(e);
1176
+ t.open(), this.setTransport(t);
1177
+ }
1178
+ /**
1179
+ * Sets the current transport. Disables the existing one (if any).
1180
+ *
1181
+ * @private
1182
+ */
1183
+ setTransport(e) {
1184
+ 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));
1185
+ }
1186
+ /**
1187
+ * Called when connection is deemed open.
1188
+ *
1189
+ * @private
1190
+ */
1191
+ onOpen() {
1192
+ this.readyState = "open", M.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush();
1193
+ }
1194
+ /**
1195
+ * Handles a packet.
1196
+ *
1197
+ * @private
1198
+ */
1199
+ _onPacket(e) {
1200
+ if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing")
1201
+ switch (this.emitReserved("packet", e), this.emitReserved("heartbeat"), e.type) {
1202
+ case "open":
1203
+ this.onHandshake(JSON.parse(e.data));
1204
+ break;
1205
+ case "ping":
1206
+ this._sendPacket("pong"), this.emitReserved("ping"), this.emitReserved("pong"), this._resetPingTimeout();
1207
+ break;
1208
+ case "error":
1209
+ const t = new Error("server error");
1210
+ t.code = e.data, this._onError(t);
1211
+ break;
1212
+ case "message":
1213
+ this.emitReserved("data", e.data), this.emitReserved("message", e.data);
1214
+ break;
1215
+ }
1216
+ }
1217
+ /**
1218
+ * Called upon handshake completion.
1219
+ *
1220
+ * @param {Object} data - handshake obj
1221
+ * @private
1222
+ */
1223
+ onHandshake(e) {
1224
+ 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();
1225
+ }
1226
+ /**
1227
+ * Sets and resets ping timeout timer based on server pings.
1228
+ *
1229
+ * @private
1230
+ */
1231
+ _resetPingTimeout() {
1232
+ this.clearTimeoutFn(this._pingTimeoutTimer);
1233
+ const e = this._pingInterval + this._pingTimeout;
1234
+ this._pingTimeoutTime = Date.now() + e, this._pingTimeoutTimer = this.setTimeoutFn(() => {
1235
+ this._onClose("ping timeout");
1236
+ }, e), this.opts.autoUnref && this._pingTimeoutTimer.unref();
1237
+ }
1238
+ /**
1239
+ * Called on `drain` event
1240
+ *
1241
+ * @private
1242
+ */
1243
+ _onDrain() {
1244
+ this.writeBuffer.splice(0, this._prevBufferLen), this._prevBufferLen = 0, this.writeBuffer.length === 0 ? this.emitReserved("drain") : this.flush();
1245
+ }
1246
+ /**
1247
+ * Flush write buffers.
1248
+ *
1249
+ * @private
1250
+ */
1251
+ flush() {
1252
+ if (this.readyState !== "closed" && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
1253
+ const e = this._getWritablePackets();
1254
+ this.transport.send(e), this._prevBufferLen = e.length, this.emitReserved("flush");
1255
+ }
1256
+ }
1257
+ /**
1258
+ * Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
1259
+ * long-polling)
1260
+ *
1261
+ * @private
1262
+ */
1263
+ _getWritablePackets() {
1264
+ if (!(this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1))
1265
+ return this.writeBuffer;
1266
+ let t = 1;
1267
+ for (let n = 0; n < this.writeBuffer.length; n++) {
1268
+ const r = this.writeBuffer[n].data;
1269
+ if (r && (t += ts(r)), n > 0 && t > this._maxPayload)
1270
+ return this.writeBuffer.slice(0, n);
1271
+ t += 2;
1272
+ }
1273
+ return this.writeBuffer;
1274
+ }
1275
+ /**
1276
+ * Checks whether the heartbeat timer has expired but the socket has not yet been notified.
1277
+ *
1278
+ * Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
1279
+ * `write()` method then the message would not be buffered by the Socket.IO client.
1280
+ *
1281
+ * @return {boolean}
1282
+ * @private
1283
+ */
1284
+ /* private */
1285
+ _hasPingExpired() {
1286
+ if (!this._pingTimeoutTime)
1287
+ return !0;
1288
+ const e = Date.now() > this._pingTimeoutTime;
1289
+ return e && (this._pingTimeoutTime = 0, fe(() => {
1290
+ this._onClose("ping timeout");
1291
+ }, this.setTimeoutFn)), e;
1292
+ }
1293
+ /**
1294
+ * Sends a message.
1295
+ *
1296
+ * @param {String} msg - message.
1297
+ * @param {Object} options.
1298
+ * @param {Function} fn - callback function.
1299
+ * @return {Socket} for chaining.
1300
+ */
1301
+ write(e, t, n) {
1302
+ return this._sendPacket("message", e, t, n), this;
1303
+ }
1304
+ /**
1305
+ * Sends a message. Alias of {@link Socket#write}.
1306
+ *
1307
+ * @param {String} msg - message.
1308
+ * @param {Object} options.
1309
+ * @param {Function} fn - callback function.
1310
+ * @return {Socket} for chaining.
1311
+ */
1312
+ send(e, t, n) {
1313
+ return this._sendPacket("message", e, t, n), this;
1314
+ }
1315
+ /**
1316
+ * Sends a packet.
1317
+ *
1318
+ * @param {String} type: packet type.
1319
+ * @param {String} data.
1320
+ * @param {Object} options.
1321
+ * @param {Function} fn - callback function.
1322
+ * @private
1323
+ */
1324
+ _sendPacket(e, t, n, r) {
1325
+ if (typeof t == "function" && (r = t, t = void 0), typeof n == "function" && (r = n, n = null), this.readyState === "closing" || this.readyState === "closed")
1326
+ return;
1327
+ n = n || {}, n.compress = n.compress !== !1;
1328
+ const i = {
1329
+ type: e,
1330
+ data: t,
1331
+ options: n
1332
+ };
1333
+ this.emitReserved("packetCreate", i), this.writeBuffer.push(i), r && this.once("flush", r), this.flush();
1334
+ }
1335
+ /**
1336
+ * Closes the connection.
1337
+ */
1338
+ close() {
1339
+ const e = () => {
1340
+ this._onClose("forced close"), this.transport.close();
1341
+ }, t = () => {
1342
+ this.off("upgrade", t), this.off("upgradeError", t), e();
1343
+ }, n = () => {
1344
+ this.once("upgrade", t), this.once("upgradeError", t);
1345
+ };
1346
+ return (this.readyState === "opening" || this.readyState === "open") && (this.readyState = "closing", this.writeBuffer.length ? this.once("drain", () => {
1347
+ this.upgrading ? n() : e();
1348
+ }) : this.upgrading ? n() : e()), this;
1349
+ }
1350
+ /**
1351
+ * Called upon transport error
1352
+ *
1353
+ * @private
1354
+ */
1355
+ _onError(e) {
1356
+ if (M.priorWebsocketSuccess = !1, this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening")
1357
+ return this.transports.shift(), this._open();
1358
+ this.emitReserved("error", e), this._onClose("transport error", e);
1359
+ }
1360
+ /**
1361
+ * Called upon transport close.
1362
+ *
1363
+ * @private
1364
+ */
1365
+ _onClose(e, t) {
1366
+ if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
1367
+ if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), Re && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
1368
+ const n = ce.indexOf(this._offlineEventListener);
1369
+ n !== -1 && ce.splice(n, 1);
1370
+ }
1371
+ this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
1372
+ }
1373
+ }
1374
+ }
1375
+ M.protocol = ft;
1376
+ class ws extends M {
1377
+ constructor() {
1378
+ super(...arguments), this._upgrades = [];
1379
+ }
1380
+ onOpen() {
1381
+ if (super.onOpen(), this.readyState === "open" && this.opts.upgrade)
1382
+ for (let e = 0; e < this._upgrades.length; e++)
1383
+ this._probe(this._upgrades[e]);
1384
+ }
1385
+ /**
1386
+ * Probes a transport.
1387
+ *
1388
+ * @param {String} name - transport name
1389
+ * @private
1390
+ */
1391
+ _probe(e) {
1392
+ let t = this.createTransport(e), n = !1;
1393
+ M.priorWebsocketSuccess = !1;
1394
+ const r = () => {
1395
+ n || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (g) => {
1396
+ if (!n)
1397
+ if (g.type === "pong" && g.data === "probe") {
1398
+ if (this.upgrading = !0, this.emitReserved("upgrading", t), !t)
1399
+ return;
1400
+ M.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
1401
+ n || this.readyState !== "closed" && (p(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
1402
+ });
1403
+ } else {
1404
+ const w = new Error("probe error");
1405
+ w.transport = t.name, this.emitReserved("upgradeError", w);
1406
+ }
1407
+ }));
1408
+ };
1409
+ function i() {
1410
+ n || (n = !0, p(), t.close(), t = null);
1411
+ }
1412
+ const c = (g) => {
1413
+ const w = new Error("probe error: " + g);
1414
+ w.transport = t.name, i(), this.emitReserved("upgradeError", w);
1415
+ };
1416
+ function l() {
1417
+ c("transport closed");
1418
+ }
1419
+ function h() {
1420
+ c("socket closed");
1421
+ }
1422
+ function f(g) {
1423
+ t && g.name !== t.name && i();
1424
+ }
1425
+ const p = () => {
1426
+ t.removeListener("open", r), t.removeListener("error", c), t.removeListener("close", l), this.off("close", h), this.off("upgrading", f);
1427
+ };
1428
+ t.once("open", r), t.once("error", c), t.once("close", l), this.once("close", h), this.once("upgrading", f), this._upgrades.indexOf("webtransport") !== -1 && e !== "webtransport" ? this.setTimeoutFn(() => {
1429
+ n || t.open();
1430
+ }, 200) : t.open();
1431
+ }
1432
+ onHandshake(e) {
1433
+ this._upgrades = this._filterUpgrades(e.upgrades), super.onHandshake(e);
1434
+ }
1435
+ /**
1436
+ * Filters upgrades, returning only those matching client transports.
1437
+ *
1438
+ * @param {Array} upgrades - server upgrades
1439
+ * @private
1440
+ */
1441
+ _filterUpgrades(e) {
1442
+ const t = [];
1443
+ for (let n = 0; n < e.length; n++)
1444
+ ~this.transports.indexOf(e[n]) && t.push(e[n]);
1445
+ return t;
1446
+ }
1447
+ }
1448
+ let bs = class extends ws {
1449
+ constructor(e, t = {}) {
1450
+ const n = typeof e == "object" ? e : t;
1451
+ (!n.transports || n.transports && typeof n.transports[0] == "string") && (n.transports = (n.transports || ["polling", "websocket", "webtransport"]).map((r) => gs[r]).filter((r) => !!r)), super(e, n);
1452
+ }
1453
+ };
1454
+ function Es(s, e = "", t) {
1455
+ let n = s;
1456
+ t = t || typeof location < "u" && location, s == null && (s = t.protocol + "//" + t.host), typeof s == "string" && (s.charAt(0) === "/" && (s.charAt(1) === "/" ? s = t.protocol + s : s = t.host + s), /^(https?|wss?):\/\//.test(s) || (typeof t < "u" ? s = t.protocol + "//" + s : s = "https://" + s), n = xe(s)), n.port || (/^(http|ws)$/.test(n.protocol) ? n.port = "80" : /^(http|ws)s$/.test(n.protocol) && (n.port = "443")), n.path = n.path || "/";
1457
+ const i = n.host.indexOf(":") !== -1 ? "[" + n.host + "]" : n.host;
1458
+ return n.id = n.protocol + "://" + i + ":" + n.port + e, n.href = n.protocol + "://" + i + (t && t.port === n.port ? "" : ":" + n.port), n;
1459
+ }
1460
+ const ks = typeof ArrayBuffer == "function", Ss = (s) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(s) : s.buffer instanceof ArrayBuffer, vt = Object.prototype.toString, Cs = typeof Blob == "function" || typeof Blob < "u" && vt.call(Blob) === "[object BlobConstructor]", Ns = typeof File == "function" || typeof File < "u" && vt.call(File) === "[object FileConstructor]";
1461
+ function qe(s) {
1462
+ return ks && (s instanceof ArrayBuffer || Ss(s)) || Cs && s instanceof Blob || Ns && s instanceof File;
1463
+ }
1464
+ function le(s, e) {
1465
+ if (!s || typeof s != "object")
1466
+ return !1;
1467
+ if (Array.isArray(s)) {
1468
+ for (let t = 0, n = s.length; t < n; t++)
1469
+ if (le(s[t]))
1470
+ return !0;
1471
+ return !1;
1472
+ }
1473
+ if (qe(s))
1474
+ return !0;
1475
+ if (s.toJSON && typeof s.toJSON == "function" && arguments.length === 1)
1476
+ return le(s.toJSON(), !0);
1477
+ for (const t in s)
1478
+ if (Object.prototype.hasOwnProperty.call(s, t) && le(s[t]))
1479
+ return !0;
1480
+ return !1;
1481
+ }
1482
+ function Os(s) {
1483
+ const e = [], t = s.data, n = s;
1484
+ return n.data = Ae(t, e), n.attachments = e.length, { packet: n, buffers: e };
1485
+ }
1486
+ function Ae(s, e) {
1487
+ if (!s)
1488
+ return s;
1489
+ if (qe(s)) {
1490
+ const t = { _placeholder: !0, num: e.length };
1491
+ return e.push(s), t;
1492
+ } else if (Array.isArray(s)) {
1493
+ const t = new Array(s.length);
1494
+ for (let n = 0; n < s.length; n++)
1495
+ t[n] = Ae(s[n], e);
1496
+ return t;
1497
+ } else if (typeof s == "object" && !(s instanceof Date)) {
1498
+ const t = {};
1499
+ for (const n in s)
1500
+ Object.prototype.hasOwnProperty.call(s, n) && (t[n] = Ae(s[n], e));
1501
+ return t;
1502
+ }
1503
+ return s;
1504
+ }
1505
+ function Ts(s, e) {
1506
+ return s.data = Be(s.data, e), delete s.attachments, s;
1507
+ }
1508
+ function Be(s, e) {
1509
+ if (!s)
1510
+ return s;
1511
+ if (s && s._placeholder === !0) {
1512
+ if (typeof s.num == "number" && s.num >= 0 && s.num < e.length)
1513
+ return e[s.num];
1514
+ throw new Error("illegal attachments");
1515
+ } else if (Array.isArray(s))
1516
+ for (let t = 0; t < s.length; t++)
1517
+ s[t] = Be(s[t], e);
1518
+ else if (typeof s == "object")
1519
+ for (const t in s)
1520
+ Object.prototype.hasOwnProperty.call(s, t) && (s[t] = Be(s[t], e));
1521
+ return s;
1522
+ }
1523
+ const xs = [
1524
+ "connect",
1525
+ // used on the client side
1526
+ "connect_error",
1527
+ // used on the client side
1528
+ "disconnect",
1529
+ // used on both sides
1530
+ "disconnecting",
1531
+ // used on the server side
1532
+ "newListener",
1533
+ // used by the Node.js EventEmitter
1534
+ "removeListener"
1535
+ // used by the Node.js EventEmitter
1536
+ ];
1537
+ var v;
1538
+ (function(s) {
1539
+ 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";
1540
+ })(v || (v = {}));
1541
+ class Rs {
1542
+ /**
1543
+ * Encoder constructor
1544
+ *
1545
+ * @param {function} replacer - custom replacer to pass down to JSON.parse
1546
+ */
1547
+ constructor(e) {
1548
+ this.replacer = e;
1549
+ }
1550
+ /**
1551
+ * Encode a packet as a single string if non-binary, or as a
1552
+ * buffer sequence, depending on packet type.
1553
+ *
1554
+ * @param {Object} obj - packet object
1555
+ */
1556
+ encode(e) {
1557
+ return (e.type === v.EVENT || e.type === v.ACK) && le(e) ? this.encodeAsBinary({
1558
+ type: e.type === v.EVENT ? v.BINARY_EVENT : v.BINARY_ACK,
1559
+ nsp: e.nsp,
1560
+ data: e.data,
1561
+ id: e.id
1562
+ }) : [this.encodeAsString(e)];
1563
+ }
1564
+ /**
1565
+ * Encode packet as string.
1566
+ */
1567
+ encodeAsString(e) {
1568
+ let t = "" + e.type;
1569
+ return (e.type === v.BINARY_EVENT || e.type === v.BINARY_ACK) && (t += e.attachments + "-"), e.nsp && e.nsp !== "/" && (t += e.nsp + ","), e.id != null && (t += e.id), e.data != null && (t += JSON.stringify(e.data, this.replacer)), t;
1570
+ }
1571
+ /**
1572
+ * Encode packet as 'buffer sequence' by removing blobs, and
1573
+ * deconstructing packet into object with placeholders and
1574
+ * a list of buffers.
1575
+ */
1576
+ encodeAsBinary(e) {
1577
+ const t = Os(e), n = this.encodeAsString(t.packet), r = t.buffers;
1578
+ return r.unshift(n), r;
1579
+ }
1580
+ }
1581
+ class $e extends E {
1582
+ /**
1583
+ * Decoder constructor
1584
+ *
1585
+ * @param {function} reviver - custom reviver to pass down to JSON.stringify
1586
+ */
1587
+ constructor(e) {
1588
+ super(), this.reviver = e;
1589
+ }
1590
+ /**
1591
+ * Decodes an encoded packet string into packet JSON.
1592
+ *
1593
+ * @param {String} obj - encoded packet
1594
+ */
1595
+ add(e) {
1596
+ let t;
1597
+ if (typeof e == "string") {
1598
+ if (this.reconstructor)
1599
+ throw new Error("got plaintext data when reconstructing a packet");
1600
+ t = this.decodeString(e);
1601
+ const n = t.type === v.BINARY_EVENT;
1602
+ n || t.type === v.BINARY_ACK ? (t.type = n ? v.EVENT : v.ACK, this.reconstructor = new As(t), t.attachments === 0 && super.emitReserved("decoded", t)) : super.emitReserved("decoded", t);
1603
+ } else if (qe(e) || e.base64)
1604
+ if (this.reconstructor)
1605
+ t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
1606
+ else
1607
+ throw new Error("got binary data when not reconstructing a packet");
1608
+ else
1609
+ throw new Error("Unknown type: " + e);
1610
+ }
1611
+ /**
1612
+ * Decode a packet String (JSON data)
1613
+ *
1614
+ * @param {String} str
1615
+ * @return {Object} packet
1616
+ */
1617
+ decodeString(e) {
1618
+ let t = 0;
1619
+ const n = {
1620
+ type: Number(e.charAt(0))
1621
+ };
1622
+ if (v[n.type] === void 0)
1623
+ throw new Error("unknown packet type " + n.type);
1624
+ if (n.type === v.BINARY_EVENT || n.type === v.BINARY_ACK) {
1625
+ const i = t + 1;
1626
+ for (; e.charAt(++t) !== "-" && t != e.length; )
1627
+ ;
1628
+ const c = e.substring(i, t);
1629
+ if (c != Number(c) || e.charAt(t) !== "-")
1630
+ throw new Error("Illegal attachments");
1631
+ n.attachments = Number(c);
1632
+ }
1633
+ if (e.charAt(t + 1) === "/") {
1634
+ const i = t + 1;
1635
+ for (; ++t && !(e.charAt(t) === "," || t === e.length); )
1636
+ ;
1637
+ n.nsp = e.substring(i, t);
1638
+ } else
1639
+ n.nsp = "/";
1640
+ const r = e.charAt(t + 1);
1641
+ if (r !== "" && Number(r) == r) {
1642
+ const i = t + 1;
1643
+ for (; ++t; ) {
1644
+ const c = e.charAt(t);
1645
+ if (c == null || Number(c) != c) {
1646
+ --t;
1647
+ break;
1648
+ }
1649
+ if (t === e.length)
1650
+ break;
1651
+ }
1652
+ n.id = Number(e.substring(i, t + 1));
1653
+ }
1654
+ if (e.charAt(++t)) {
1655
+ const i = this.tryParse(e.substr(t));
1656
+ if ($e.isPayloadValid(n.type, i))
1657
+ n.data = i;
1658
+ else
1659
+ throw new Error("invalid payload");
1660
+ }
1661
+ return n;
1662
+ }
1663
+ tryParse(e) {
1664
+ try {
1665
+ return JSON.parse(e, this.reviver);
1666
+ } catch {
1667
+ return !1;
1668
+ }
1669
+ }
1670
+ static isPayloadValid(e, t) {
1671
+ switch (e) {
1672
+ case v.CONNECT:
1673
+ return et(t);
1674
+ case v.DISCONNECT:
1675
+ return t === void 0;
1676
+ case v.CONNECT_ERROR:
1677
+ return typeof t == "string" || et(t);
1678
+ case v.EVENT:
1679
+ case v.BINARY_EVENT:
1680
+ return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && xs.indexOf(t[0]) === -1);
1681
+ case v.ACK:
1682
+ case v.BINARY_ACK:
1683
+ return Array.isArray(t);
1684
+ }
1685
+ }
1686
+ /**
1687
+ * Deallocates a parser's resources
1688
+ */
1689
+ destroy() {
1690
+ this.reconstructor && (this.reconstructor.finishedReconstruction(), this.reconstructor = null);
1691
+ }
1692
+ }
1693
+ class As {
1694
+ constructor(e) {
1695
+ this.packet = e, this.buffers = [], this.reconPack = e;
1696
+ }
1697
+ /**
1698
+ * Method to be called when binary data received from connection
1699
+ * after a BINARY_EVENT packet.
1700
+ *
1701
+ * @param {Buffer | ArrayBuffer} binData - the raw binary data received
1702
+ * @return {null | Object} returns null if more binary data is expected or
1703
+ * a reconstructed packet object if all buffers have been received.
1704
+ */
1705
+ takeBinaryData(e) {
1706
+ if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
1707
+ const t = Ts(this.reconPack, this.buffers);
1708
+ return this.finishedReconstruction(), t;
1709
+ }
1710
+ return null;
1711
+ }
1712
+ /**
1713
+ * Cleans up binary packet reconstruction variables.
1714
+ */
1715
+ finishedReconstruction() {
1716
+ this.reconPack = null, this.buffers = [];
1717
+ }
1718
+ }
1719
+ function et(s) {
1720
+ return Object.prototype.toString.call(s) === "[object Object]";
1721
+ }
1722
+ const Bs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1723
+ __proto__: null,
1724
+ Decoder: $e,
1725
+ Encoder: Rs,
1726
+ get PacketType() {
1727
+ return v;
1728
+ }
1729
+ }, Symbol.toStringTag, { value: "Module" }));
1730
+ function P(s, e, t) {
1731
+ return s.on(e, t), function() {
1732
+ s.off(e, t);
1733
+ };
1734
+ }
1735
+ const Ls = Object.freeze({
1736
+ connect: 1,
1737
+ connect_error: 1,
1738
+ disconnect: 1,
1739
+ disconnecting: 1,
1740
+ // EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
1741
+ newListener: 1,
1742
+ removeListener: 1
1743
+ });
1744
+ class _t extends E {
1745
+ /**
1746
+ * `Socket` constructor.
1747
+ */
1748
+ constructor(e, t, n) {
1749
+ 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();
1750
+ }
1751
+ /**
1752
+ * Whether the socket is currently disconnected
1753
+ *
1754
+ * @example
1755
+ * const socket = io();
1756
+ *
1757
+ * socket.on("connect", () => {
1758
+ * console.log(socket.disconnected); // false
1759
+ * });
1760
+ *
1761
+ * socket.on("disconnect", () => {
1762
+ * console.log(socket.disconnected); // true
1763
+ * });
1764
+ */
1765
+ get disconnected() {
1766
+ return !this.connected;
1767
+ }
1768
+ /**
1769
+ * Subscribe to open, close and packet events
1770
+ *
1771
+ * @private
1772
+ */
1773
+ subEvents() {
1774
+ if (this.subs)
1775
+ return;
1776
+ const e = this.io;
1777
+ this.subs = [
1778
+ P(e, "open", this.onopen.bind(this)),
1779
+ P(e, "packet", this.onpacket.bind(this)),
1780
+ P(e, "error", this.onerror.bind(this)),
1781
+ P(e, "close", this.onclose.bind(this))
1782
+ ];
1783
+ }
1784
+ /**
1785
+ * Whether the Socket will try to reconnect when its Manager connects or reconnects.
1786
+ *
1787
+ * @example
1788
+ * const socket = io();
1789
+ *
1790
+ * console.log(socket.active); // true
1791
+ *
1792
+ * socket.on("disconnect", (reason) => {
1793
+ * if (reason === "io server disconnect") {
1794
+ * // the disconnection was initiated by the server, you need to manually reconnect
1795
+ * console.log(socket.active); // false
1796
+ * }
1797
+ * // else the socket will automatically try to reconnect
1798
+ * console.log(socket.active); // true
1799
+ * });
1800
+ */
1801
+ get active() {
1802
+ return !!this.subs;
1803
+ }
1804
+ /**
1805
+ * "Opens" the socket.
1806
+ *
1807
+ * @example
1808
+ * const socket = io({
1809
+ * autoConnect: false
1810
+ * });
1811
+ *
1812
+ * socket.connect();
1813
+ */
1814
+ connect() {
1815
+ return this.connected ? this : (this.subEvents(), this.io._reconnecting || this.io.open(), this.io._readyState === "open" && this.onopen(), this);
1816
+ }
1817
+ /**
1818
+ * Alias for {@link connect()}.
1819
+ */
1820
+ open() {
1821
+ return this.connect();
1822
+ }
1823
+ /**
1824
+ * Sends a `message` event.
1825
+ *
1826
+ * This method mimics the WebSocket.send() method.
1827
+ *
1828
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
1829
+ *
1830
+ * @example
1831
+ * socket.send("hello");
1832
+ *
1833
+ * // this is equivalent to
1834
+ * socket.emit("message", "hello");
1835
+ *
1836
+ * @return self
1837
+ */
1838
+ send(...e) {
1839
+ return e.unshift("message"), this.emit.apply(this, e), this;
1840
+ }
1841
+ /**
1842
+ * Override `emit`.
1843
+ * If the event is in `events`, it's emitted normally.
1844
+ *
1845
+ * @example
1846
+ * socket.emit("hello", "world");
1847
+ *
1848
+ * // all serializable datastructures are supported (no need to call JSON.stringify)
1849
+ * socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
1850
+ *
1851
+ * // with an acknowledgement from the server
1852
+ * socket.emit("hello", "world", (val) => {
1853
+ * // ...
1854
+ * });
1855
+ *
1856
+ * @return self
1857
+ */
1858
+ emit(e, ...t) {
1859
+ var n, r, i;
1860
+ if (Ls.hasOwnProperty(e))
1861
+ throw new Error('"' + e.toString() + '" is a reserved event name');
1862
+ if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile)
1863
+ return this._addToQueue(t), this;
1864
+ const c = {
1865
+ type: v.EVENT,
1866
+ data: t
1867
+ };
1868
+ if (c.options = {}, c.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
1869
+ const p = this.ids++, g = t.pop();
1870
+ this._registerAckCallback(p, g), c.id = p;
1871
+ }
1872
+ const l = (r = (n = this.io.engine) === null || n === void 0 ? void 0 : n.transport) === null || r === void 0 ? void 0 : r.writable, h = this.connected && !(!((i = this.io.engine) === null || i === void 0) && i._hasPingExpired());
1873
+ return this.flags.volatile && !l || (h ? (this.notifyOutgoingListeners(c), this.packet(c)) : this.sendBuffer.push(c)), this.flags = {}, this;
1874
+ }
1875
+ /**
1876
+ * @private
1877
+ */
1878
+ _registerAckCallback(e, t) {
1879
+ var n;
1880
+ const r = (n = this.flags.timeout) !== null && n !== void 0 ? n : this._opts.ackTimeout;
1881
+ if (r === void 0) {
1882
+ this.acks[e] = t;
1883
+ return;
1884
+ }
1885
+ const i = this.io.setTimeoutFn(() => {
1886
+ delete this.acks[e];
1887
+ for (let l = 0; l < this.sendBuffer.length; l++)
1888
+ this.sendBuffer[l].id === e && this.sendBuffer.splice(l, 1);
1889
+ t.call(this, new Error("operation has timed out"));
1890
+ }, r), c = (...l) => {
1891
+ this.io.clearTimeoutFn(i), t.apply(this, l);
1892
+ };
1893
+ c.withError = !0, this.acks[e] = c;
1894
+ }
1895
+ /**
1896
+ * Emits an event and waits for an acknowledgement
1897
+ *
1898
+ * @example
1899
+ * // without timeout
1900
+ * const response = await socket.emitWithAck("hello", "world");
1901
+ *
1902
+ * // with a specific timeout
1903
+ * try {
1904
+ * const response = await socket.timeout(1000).emitWithAck("hello", "world");
1905
+ * } catch (err) {
1906
+ * // the server did not acknowledge the event in the given delay
1907
+ * }
1908
+ *
1909
+ * @return a Promise that will be fulfilled when the server acknowledges the event
1910
+ */
1911
+ emitWithAck(e, ...t) {
1912
+ return new Promise((n, r) => {
1913
+ const i = (c, l) => c ? r(c) : n(l);
1914
+ i.withError = !0, t.push(i), this.emit(e, ...t);
1915
+ });
1916
+ }
1917
+ /**
1918
+ * Add the packet to the queue.
1919
+ * @param args
1920
+ * @private
1921
+ */
1922
+ _addToQueue(e) {
1923
+ let t;
1924
+ typeof e[e.length - 1] == "function" && (t = e.pop());
1925
+ const n = {
1926
+ id: this._queueSeq++,
1927
+ tryCount: 0,
1928
+ pending: !1,
1929
+ args: e,
1930
+ flags: Object.assign({ fromQueue: !0 }, this.flags)
1931
+ };
1932
+ e.push((r, ...i) => (this._queue[0], 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())), this._queue.push(n), this._drainQueue();
1933
+ }
1934
+ /**
1935
+ * Send the first packet of the queue, and wait for an acknowledgement from the server.
1936
+ * @param force - whether to resend a packet that has not been acknowledged yet
1937
+ *
1938
+ * @private
1939
+ */
1940
+ _drainQueue(e = !1) {
1941
+ if (!this.connected || this._queue.length === 0)
1942
+ return;
1943
+ const t = this._queue[0];
1944
+ t.pending && !e || (t.pending = !0, t.tryCount++, this.flags = t.flags, this.emit.apply(this, t.args));
1945
+ }
1946
+ /**
1947
+ * Sends a packet.
1948
+ *
1949
+ * @param packet
1950
+ * @private
1951
+ */
1952
+ packet(e) {
1953
+ e.nsp = this.nsp, this.io._packet(e);
1954
+ }
1955
+ /**
1956
+ * Called upon engine `open`.
1957
+ *
1958
+ * @private
1959
+ */
1960
+ onopen() {
1961
+ typeof this.auth == "function" ? this.auth((e) => {
1962
+ this._sendConnectPacket(e);
1963
+ }) : this._sendConnectPacket(this.auth);
1964
+ }
1965
+ /**
1966
+ * Sends a CONNECT packet to initiate the Socket.IO session.
1967
+ *
1968
+ * @param data
1969
+ * @private
1970
+ */
1971
+ _sendConnectPacket(e) {
1972
+ this.packet({
1973
+ type: v.CONNECT,
1974
+ data: this._pid ? Object.assign({ pid: this._pid, offset: this._lastOffset }, e) : e
1975
+ });
1976
+ }
1977
+ /**
1978
+ * Called upon engine or manager `error`.
1979
+ *
1980
+ * @param err
1981
+ * @private
1982
+ */
1983
+ onerror(e) {
1984
+ this.connected || this.emitReserved("connect_error", e);
1985
+ }
1986
+ /**
1987
+ * Called upon engine `close`.
1988
+ *
1989
+ * @param reason
1990
+ * @param description
1991
+ * @private
1992
+ */
1993
+ onclose(e, t) {
1994
+ this.connected = !1, delete this.id, this.emitReserved("disconnect", e, t), this._clearAcks();
1995
+ }
1996
+ /**
1997
+ * Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
1998
+ * the server.
1999
+ *
2000
+ * @private
2001
+ */
2002
+ _clearAcks() {
2003
+ Object.keys(this.acks).forEach((e) => {
2004
+ if (!this.sendBuffer.some((n) => String(n.id) === e)) {
2005
+ const n = this.acks[e];
2006
+ delete this.acks[e], n.withError && n.call(this, new Error("socket has been disconnected"));
2007
+ }
2008
+ });
2009
+ }
2010
+ /**
2011
+ * Called with socket packet.
2012
+ *
2013
+ * @param packet
2014
+ * @private
2015
+ */
2016
+ onpacket(e) {
2017
+ if (e.nsp === this.nsp)
2018
+ switch (e.type) {
2019
+ case v.CONNECT:
2020
+ 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/)"));
2021
+ break;
2022
+ case v.EVENT:
2023
+ case v.BINARY_EVENT:
2024
+ this.onevent(e);
2025
+ break;
2026
+ case v.ACK:
2027
+ case v.BINARY_ACK:
2028
+ this.onack(e);
2029
+ break;
2030
+ case v.DISCONNECT:
2031
+ this.ondisconnect();
2032
+ break;
2033
+ case v.CONNECT_ERROR:
2034
+ this.destroy();
2035
+ const n = new Error(e.data.message);
2036
+ n.data = e.data.data, this.emitReserved("connect_error", n);
2037
+ break;
2038
+ }
2039
+ }
2040
+ /**
2041
+ * Called upon a server event.
2042
+ *
2043
+ * @param packet
2044
+ * @private
2045
+ */
2046
+ onevent(e) {
2047
+ const t = e.data || [];
2048
+ e.id != null && t.push(this.ack(e.id)), this.connected ? this.emitEvent(t) : this.receiveBuffer.push(Object.freeze(t));
2049
+ }
2050
+ emitEvent(e) {
2051
+ if (this._anyListeners && this._anyListeners.length) {
2052
+ const t = this._anyListeners.slice();
2053
+ for (const n of t)
2054
+ n.apply(this, e);
2055
+ }
2056
+ super.emit.apply(this, e), this._pid && e.length && typeof e[e.length - 1] == "string" && (this._lastOffset = e[e.length - 1]);
2057
+ }
2058
+ /**
2059
+ * Produces an ack callback to emit with an event.
2060
+ *
2061
+ * @private
2062
+ */
2063
+ ack(e) {
2064
+ const t = this;
2065
+ let n = !1;
2066
+ return function(...r) {
2067
+ n || (n = !0, t.packet({
2068
+ type: v.ACK,
2069
+ id: e,
2070
+ data: r
2071
+ }));
2072
+ };
2073
+ }
2074
+ /**
2075
+ * Called upon a server acknowledgement.
2076
+ *
2077
+ * @param packet
2078
+ * @private
2079
+ */
2080
+ onack(e) {
2081
+ const t = this.acks[e.id];
2082
+ typeof t == "function" && (delete this.acks[e.id], t.withError && e.data.unshift(null), t.apply(this, e.data));
2083
+ }
2084
+ /**
2085
+ * Called upon server connect.
2086
+ *
2087
+ * @private
2088
+ */
2089
+ onconnect(e, t) {
2090
+ this.id = e, this.recovered = t && this._pid === t, this._pid = t, this.connected = !0, this.emitBuffered(), this._drainQueue(!0), this.emitReserved("connect");
2091
+ }
2092
+ /**
2093
+ * Emit buffered events (received and emitted).
2094
+ *
2095
+ * @private
2096
+ */
2097
+ emitBuffered() {
2098
+ this.receiveBuffer.forEach((e) => this.emitEvent(e)), this.receiveBuffer = [], this.sendBuffer.forEach((e) => {
2099
+ this.notifyOutgoingListeners(e), this.packet(e);
2100
+ }), this.sendBuffer = [];
2101
+ }
2102
+ /**
2103
+ * Called upon server disconnect.
2104
+ *
2105
+ * @private
2106
+ */
2107
+ ondisconnect() {
2108
+ this.destroy(), this.onclose("io server disconnect");
2109
+ }
2110
+ /**
2111
+ * Called upon forced client/server side disconnections,
2112
+ * this method ensures the manager stops tracking us and
2113
+ * that reconnections don't get triggered for this.
2114
+ *
2115
+ * @private
2116
+ */
2117
+ destroy() {
2118
+ this.subs && (this.subs.forEach((e) => e()), this.subs = void 0), this.io._destroy(this);
2119
+ }
2120
+ /**
2121
+ * Disconnects the socket manually. In that case, the socket will not try to reconnect.
2122
+ *
2123
+ * If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
2124
+ *
2125
+ * @example
2126
+ * const socket = io();
2127
+ *
2128
+ * socket.on("disconnect", (reason) => {
2129
+ * // console.log(reason); prints "io client disconnect"
2130
+ * });
2131
+ *
2132
+ * socket.disconnect();
2133
+ *
2134
+ * @return self
2135
+ */
2136
+ disconnect() {
2137
+ return this.connected && this.packet({ type: v.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
2138
+ }
2139
+ /**
2140
+ * Alias for {@link disconnect()}.
2141
+ *
2142
+ * @return self
2143
+ */
2144
+ close() {
2145
+ return this.disconnect();
2146
+ }
2147
+ /**
2148
+ * Sets the compress flag.
2149
+ *
2150
+ * @example
2151
+ * socket.compress(false).emit("hello");
2152
+ *
2153
+ * @param compress - if `true`, compresses the sending data
2154
+ * @return self
2155
+ */
2156
+ compress(e) {
2157
+ return this.flags.compress = e, this;
2158
+ }
2159
+ /**
2160
+ * Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
2161
+ * ready to send messages.
2162
+ *
2163
+ * @example
2164
+ * socket.volatile.emit("hello"); // the server may or may not receive it
2165
+ *
2166
+ * @returns self
2167
+ */
2168
+ get volatile() {
2169
+ return this.flags.volatile = !0, this;
2170
+ }
2171
+ /**
2172
+ * Sets a modifier for a subsequent event emission that the callback will be called with an error when the
2173
+ * given number of milliseconds have elapsed without an acknowledgement from the server:
2174
+ *
2175
+ * @example
2176
+ * socket.timeout(5000).emit("my-event", (err) => {
2177
+ * if (err) {
2178
+ * // the server did not acknowledge the event in the given delay
2179
+ * }
2180
+ * });
2181
+ *
2182
+ * @returns self
2183
+ */
2184
+ timeout(e) {
2185
+ return this.flags.timeout = e, this;
2186
+ }
2187
+ /**
2188
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2189
+ * callback.
2190
+ *
2191
+ * @example
2192
+ * socket.onAny((event, ...args) => {
2193
+ * console.log(`got ${event}`);
2194
+ * });
2195
+ *
2196
+ * @param listener
2197
+ */
2198
+ onAny(e) {
2199
+ return this._anyListeners = this._anyListeners || [], this._anyListeners.push(e), this;
2200
+ }
2201
+ /**
2202
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2203
+ * callback. The listener is added to the beginning of the listeners array.
2204
+ *
2205
+ * @example
2206
+ * socket.prependAny((event, ...args) => {
2207
+ * console.log(`got event ${event}`);
2208
+ * });
2209
+ *
2210
+ * @param listener
2211
+ */
2212
+ prependAny(e) {
2213
+ return this._anyListeners = this._anyListeners || [], this._anyListeners.unshift(e), this;
2214
+ }
2215
+ /**
2216
+ * Removes the listener that will be fired when any event is emitted.
2217
+ *
2218
+ * @example
2219
+ * const catchAllListener = (event, ...args) => {
2220
+ * console.log(`got event ${event}`);
2221
+ * }
2222
+ *
2223
+ * socket.onAny(catchAllListener);
2224
+ *
2225
+ * // remove a specific listener
2226
+ * socket.offAny(catchAllListener);
2227
+ *
2228
+ * // or remove all listeners
2229
+ * socket.offAny();
2230
+ *
2231
+ * @param listener
2232
+ */
2233
+ offAny(e) {
2234
+ if (!this._anyListeners)
2235
+ return this;
2236
+ if (e) {
2237
+ const t = this._anyListeners;
2238
+ for (let n = 0; n < t.length; n++)
2239
+ if (e === t[n])
2240
+ return t.splice(n, 1), this;
2241
+ } else
2242
+ this._anyListeners = [];
2243
+ return this;
2244
+ }
2245
+ /**
2246
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
2247
+ * e.g. to remove listeners.
2248
+ */
2249
+ listenersAny() {
2250
+ return this._anyListeners || [];
2251
+ }
2252
+ /**
2253
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2254
+ * callback.
2255
+ *
2256
+ * Note: acknowledgements sent to the server are not included.
2257
+ *
2258
+ * @example
2259
+ * socket.onAnyOutgoing((event, ...args) => {
2260
+ * console.log(`sent event ${event}`);
2261
+ * });
2262
+ *
2263
+ * @param listener
2264
+ */
2265
+ onAnyOutgoing(e) {
2266
+ return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.push(e), this;
2267
+ }
2268
+ /**
2269
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2270
+ * callback. The listener is added to the beginning of the listeners array.
2271
+ *
2272
+ * Note: acknowledgements sent to the server are not included.
2273
+ *
2274
+ * @example
2275
+ * socket.prependAnyOutgoing((event, ...args) => {
2276
+ * console.log(`sent event ${event}`);
2277
+ * });
2278
+ *
2279
+ * @param listener
2280
+ */
2281
+ prependAnyOutgoing(e) {
2282
+ return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.unshift(e), this;
2283
+ }
2284
+ /**
2285
+ * Removes the listener that will be fired when any event is emitted.
2286
+ *
2287
+ * @example
2288
+ * const catchAllListener = (event, ...args) => {
2289
+ * console.log(`sent event ${event}`);
2290
+ * }
2291
+ *
2292
+ * socket.onAnyOutgoing(catchAllListener);
2293
+ *
2294
+ * // remove a specific listener
2295
+ * socket.offAnyOutgoing(catchAllListener);
2296
+ *
2297
+ * // or remove all listeners
2298
+ * socket.offAnyOutgoing();
2299
+ *
2300
+ * @param [listener] - the catch-all listener (optional)
2301
+ */
2302
+ offAnyOutgoing(e) {
2303
+ if (!this._anyOutgoingListeners)
2304
+ return this;
2305
+ if (e) {
2306
+ const t = this._anyOutgoingListeners;
2307
+ for (let n = 0; n < t.length; n++)
2308
+ if (e === t[n])
2309
+ return t.splice(n, 1), this;
2310
+ } else
2311
+ this._anyOutgoingListeners = [];
2312
+ return this;
2313
+ }
2314
+ /**
2315
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
2316
+ * e.g. to remove listeners.
2317
+ */
2318
+ listenersAnyOutgoing() {
2319
+ return this._anyOutgoingListeners || [];
2320
+ }
2321
+ /**
2322
+ * Notify the listeners for each packet sent
2323
+ *
2324
+ * @param packet
2325
+ *
2326
+ * @private
2327
+ */
2328
+ notifyOutgoingListeners(e) {
2329
+ if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
2330
+ const t = this._anyOutgoingListeners.slice();
2331
+ for (const n of t)
2332
+ n.apply(this, e.data);
2333
+ }
2334
+ }
2335
+ }
2336
+ function W(s) {
2337
+ 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;
2338
+ }
2339
+ W.prototype.duration = function() {
2340
+ var s = this.ms * Math.pow(this.factor, this.attempts++);
2341
+ if (this.jitter) {
2342
+ var e = Math.random(), t = Math.floor(e * this.jitter * s);
2343
+ s = (Math.floor(e * 10) & 1) == 0 ? s - t : s + t;
2344
+ }
2345
+ return Math.min(s, this.max) | 0;
2346
+ };
2347
+ W.prototype.reset = function() {
2348
+ this.attempts = 0;
2349
+ };
2350
+ W.prototype.setMin = function(s) {
2351
+ this.ms = s;
2352
+ };
2353
+ W.prototype.setMax = function(s) {
2354
+ this.max = s;
2355
+ };
2356
+ W.prototype.setJitter = function(s) {
2357
+ this.jitter = s;
2358
+ };
2359
+ class Le extends E {
2360
+ constructor(e, t) {
2361
+ var n;
2362
+ super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t = t || {}, t.path = t.path || "/socket.io", this.opts = t, de(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 W({
2363
+ min: this.reconnectionDelay(),
2364
+ max: this.reconnectionDelayMax(),
2365
+ jitter: this.randomizationFactor()
2366
+ }), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
2367
+ const r = t.parser || Bs;
2368
+ this.encoder = new r.Encoder(), this.decoder = new r.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
2369
+ }
2370
+ reconnection(e) {
2371
+ return arguments.length ? (this._reconnection = !!e, e || (this.skipReconnect = !0), this) : this._reconnection;
2372
+ }
2373
+ reconnectionAttempts(e) {
2374
+ return e === void 0 ? this._reconnectionAttempts : (this._reconnectionAttempts = e, this);
2375
+ }
2376
+ reconnectionDelay(e) {
2377
+ var t;
2378
+ return e === void 0 ? this._reconnectionDelay : (this._reconnectionDelay = e, (t = this.backoff) === null || t === void 0 || t.setMin(e), this);
2379
+ }
2380
+ randomizationFactor(e) {
2381
+ var t;
2382
+ return e === void 0 ? this._randomizationFactor : (this._randomizationFactor = e, (t = this.backoff) === null || t === void 0 || t.setJitter(e), this);
2383
+ }
2384
+ reconnectionDelayMax(e) {
2385
+ var t;
2386
+ return e === void 0 ? this._reconnectionDelayMax : (this._reconnectionDelayMax = e, (t = this.backoff) === null || t === void 0 || t.setMax(e), this);
2387
+ }
2388
+ timeout(e) {
2389
+ return arguments.length ? (this._timeout = e, this) : this._timeout;
2390
+ }
2391
+ /**
2392
+ * Starts trying to reconnect if reconnection is enabled and we have not
2393
+ * started reconnecting yet
2394
+ *
2395
+ * @private
2396
+ */
2397
+ maybeReconnectOnOpen() {
2398
+ !this._reconnecting && this._reconnection && this.backoff.attempts === 0 && this.reconnect();
2399
+ }
2400
+ /**
2401
+ * Sets the current transport `socket`.
2402
+ *
2403
+ * @param {Function} fn - optional, callback
2404
+ * @return self
2405
+ * @public
2406
+ */
2407
+ open(e) {
2408
+ if (~this._readyState.indexOf("open"))
2409
+ return this;
2410
+ this.engine = new bs(this.uri, this.opts);
2411
+ const t = this.engine, n = this;
2412
+ this._readyState = "opening", this.skipReconnect = !1;
2413
+ const r = P(t, "open", function() {
2414
+ n.onopen(), e && e();
2415
+ }), i = (l) => {
2416
+ this.cleanup(), this._readyState = "closed", this.emitReserved("error", l), e ? e(l) : this.maybeReconnectOnOpen();
2417
+ }, c = P(t, "error", i);
2418
+ if (this._timeout !== !1) {
2419
+ const l = this._timeout, h = this.setTimeoutFn(() => {
2420
+ r(), i(new Error("timeout")), t.close();
2421
+ }, l);
2422
+ this.opts.autoUnref && h.unref(), this.subs.push(() => {
2423
+ this.clearTimeoutFn(h);
2424
+ });
2425
+ }
2426
+ return this.subs.push(r), this.subs.push(c), this;
2427
+ }
2428
+ /**
2429
+ * Alias for open()
2430
+ *
2431
+ * @return self
2432
+ * @public
2433
+ */
2434
+ connect(e) {
2435
+ return this.open(e);
2436
+ }
2437
+ /**
2438
+ * Called upon transport open.
2439
+ *
2440
+ * @private
2441
+ */
2442
+ onopen() {
2443
+ this.cleanup(), this._readyState = "open", this.emitReserved("open");
2444
+ const e = this.engine;
2445
+ this.subs.push(
2446
+ P(e, "ping", this.onping.bind(this)),
2447
+ P(e, "data", this.ondata.bind(this)),
2448
+ P(e, "error", this.onerror.bind(this)),
2449
+ P(e, "close", this.onclose.bind(this)),
2450
+ // @ts-ignore
2451
+ P(this.decoder, "decoded", this.ondecoded.bind(this))
2452
+ );
2453
+ }
2454
+ /**
2455
+ * Called upon a ping.
2456
+ *
2457
+ * @private
2458
+ */
2459
+ onping() {
2460
+ this.emitReserved("ping");
2461
+ }
2462
+ /**
2463
+ * Called with data.
2464
+ *
2465
+ * @private
2466
+ */
2467
+ ondata(e) {
2468
+ try {
2469
+ this.decoder.add(e);
2470
+ } catch (t) {
2471
+ this.onclose("parse error", t);
2472
+ }
2473
+ }
2474
+ /**
2475
+ * Called when parser fully decodes a packet.
2476
+ *
2477
+ * @private
2478
+ */
2479
+ ondecoded(e) {
2480
+ fe(() => {
2481
+ this.emitReserved("packet", e);
2482
+ }, this.setTimeoutFn);
2483
+ }
2484
+ /**
2485
+ * Called upon socket error.
2486
+ *
2487
+ * @private
2488
+ */
2489
+ onerror(e) {
2490
+ this.emitReserved("error", e);
2491
+ }
2492
+ /**
2493
+ * Creates a new socket for the given `nsp`.
2494
+ *
2495
+ * @return {Socket}
2496
+ * @public
2497
+ */
2498
+ socket(e, t) {
2499
+ let n = this.nsps[e];
2500
+ return n ? this._autoConnect && !n.active && n.connect() : (n = new _t(this, e, t), this.nsps[e] = n), n;
2501
+ }
2502
+ /**
2503
+ * Called upon a socket close.
2504
+ *
2505
+ * @param socket
2506
+ * @private
2507
+ */
2508
+ _destroy(e) {
2509
+ const t = Object.keys(this.nsps);
2510
+ for (const n of t)
2511
+ if (this.nsps[n].active)
2512
+ return;
2513
+ this._close();
2514
+ }
2515
+ /**
2516
+ * Writes a packet.
2517
+ *
2518
+ * @param packet
2519
+ * @private
2520
+ */
2521
+ _packet(e) {
2522
+ const t = this.encoder.encode(e);
2523
+ for (let n = 0; n < t.length; n++)
2524
+ this.engine.write(t[n], e.options);
2525
+ }
2526
+ /**
2527
+ * Clean up transport subscriptions and packet buffer.
2528
+ *
2529
+ * @private
2530
+ */
2531
+ cleanup() {
2532
+ this.subs.forEach((e) => e()), this.subs.length = 0, this.decoder.destroy();
2533
+ }
2534
+ /**
2535
+ * Close the current socket.
2536
+ *
2537
+ * @private
2538
+ */
2539
+ _close() {
2540
+ this.skipReconnect = !0, this._reconnecting = !1, this.onclose("forced close");
2541
+ }
2542
+ /**
2543
+ * Alias for close()
2544
+ *
2545
+ * @private
2546
+ */
2547
+ disconnect() {
2548
+ return this._close();
2549
+ }
2550
+ /**
2551
+ * Called when:
2552
+ *
2553
+ * - the low-level engine is closed
2554
+ * - the parser encountered a badly formatted packet
2555
+ * - all sockets are disconnected
2556
+ *
2557
+ * @private
2558
+ */
2559
+ onclose(e, t) {
2560
+ var n;
2561
+ 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();
2562
+ }
2563
+ /**
2564
+ * Attempt a reconnection.
2565
+ *
2566
+ * @private
2567
+ */
2568
+ reconnect() {
2569
+ if (this._reconnecting || this.skipReconnect)
2570
+ return this;
2571
+ const e = this;
2572
+ if (this.backoff.attempts >= this._reconnectionAttempts)
2573
+ this.backoff.reset(), this.emitReserved("reconnect_failed"), this._reconnecting = !1;
2574
+ else {
2575
+ const t = this.backoff.duration();
2576
+ this._reconnecting = !0;
2577
+ const n = this.setTimeoutFn(() => {
2578
+ e.skipReconnect || (this.emitReserved("reconnect_attempt", e.backoff.attempts), !e.skipReconnect && e.open((r) => {
2579
+ r ? (e._reconnecting = !1, e.reconnect(), this.emitReserved("reconnect_error", r)) : e.onreconnect();
2580
+ }));
2581
+ }, t);
2582
+ this.opts.autoUnref && n.unref(), this.subs.push(() => {
2583
+ this.clearTimeoutFn(n);
2584
+ });
2585
+ }
2586
+ }
2587
+ /**
2588
+ * Called upon successful reconnect.
2589
+ *
2590
+ * @private
2591
+ */
2592
+ onreconnect() {
2593
+ const e = this.backoff.attempts;
2594
+ this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
2595
+ }
2596
+ }
2597
+ const G = {};
2598
+ function ue(s, e) {
2599
+ typeof s == "object" && (e = s, s = void 0), e = e || {};
2600
+ const t = Es(s, e.path || "/socket.io"), n = t.source, r = t.id, i = t.path, c = G[r] && i in G[r].nsps, l = e.forceNew || e["force new connection"] || e.multiplex === !1 || c;
2601
+ let h;
2602
+ return l ? h = new Le(n, e) : (G[r] || (G[r] = new Le(n, e)), h = G[r]), t.query && !e.query && (e.query = t.queryKey), h.socket(t.path, e);
2603
+ }
2604
+ Object.assign(ue, {
2605
+ Manager: Le,
2606
+ Socket: _t,
2607
+ io: ue,
2608
+ connect: ue
2609
+ });
2610
+ const wt = /* @__PURE__ */ $t("gigSupportChat", () => {
2611
+ const s = b(null), e = b([]), t = b(!1), n = b(!1), r = b(0), i = b(""), c = b([]), l = b(!1), h = b(null), f = b(null), p = (k) => {
2612
+ f.value = k;
2613
+ }, g = () => {
2614
+ var k;
2615
+ (k = s.value) != null && k.connected || !f.value || (s.value = ue(f.value.apiUrl, {
2616
+ path: f.value.path || "/ws",
2617
+ transports: ["websocket", "polling"],
2618
+ auth: {
2619
+ apiKey: f.value.apiKey,
2620
+ uuid: f.value.uuid,
2621
+ metaUser: f.value.metaUser
2622
+ }
2623
+ }), s.value.on("connect", () => {
2624
+ console.log("[GigSupportChat] Connected"), t.value = !0;
2625
+ }), s.value.on("connected", (_) => {
2626
+ console.log("[GigSupportChat] Registered as:", _.userId), i.value = _.userId, x();
2627
+ }), s.value.on("disconnect", () => {
2628
+ console.log("[GigSupportChat] Disconnected"), t.value = !1;
2629
+ }), s.value.on("new_message", (_) => {
2630
+ _.status === "SUCCESS" && (e.value.find((S) => S.id === _.message.id) || (e.value.push(_.message), n.value || r.value++));
2631
+ }), s.value.on("message_sent", (_) => {
2632
+ _.status === "SUCCESS" && (e.value.find((S) => S.id === _.message.id) || e.value.push(_.message));
2633
+ }), s.value.on("history", (_) => {
2634
+ _.status === "SUCCESS" && (e.value = _.messages);
2635
+ }), s.value.on("error", (_) => {
2636
+ console.error("[GigSupportChat] Socket error:", _);
2637
+ }));
2638
+ }, w = () => {
2639
+ s.value && (s.value.disconnect(), s.value = null), t.value = !1, e.value = [], r.value = 0, i.value = "";
2640
+ }, T = (k) => {
2641
+ var _, S;
2642
+ !s.value || !t.value || (s.value.emit("send_message", {
2643
+ userId: i.value,
2644
+ text: k,
2645
+ replyToMessageId: (_ = h.value) == null ? void 0 : _.id,
2646
+ metaUser: (S = f.value) == null ? void 0 : S.metaUser
2647
+ }), h.value = null);
2648
+ }, x = () => {
2649
+ !s.value || !i.value || s.value.emit("get_history", {
2650
+ userId: i.value,
2651
+ limit: 50,
2652
+ offset: 0
2653
+ });
2654
+ };
2655
+ return {
2656
+ messages: e,
2657
+ isConnected: t,
2658
+ isWidgetOpen: n,
2659
+ unreadCount: r,
2660
+ currentUserId: i,
2661
+ stickers: c,
2662
+ isLoadingStickers: l,
2663
+ replyingToMessage: h,
2664
+ init: p,
2665
+ connect: g,
2666
+ disconnect: w,
2667
+ sendMessage: T,
2668
+ sendSticker: (k) => {
2669
+ var _, S;
2670
+ !s.value || !t.value || (s.value.emit("send_message", {
2671
+ userId: i.value,
2672
+ stickerId: k,
2673
+ messageType: "sticker",
2674
+ replyToMessageId: (_ = h.value) == null ? void 0 : _.id,
2675
+ metaUser: (S = f.value) == null ? void 0 : S.metaUser
2676
+ }), h.value = null);
2677
+ },
2678
+ fetchStickers: async () => {
2679
+ var k;
2680
+ if ((k = f.value) != null && k.apiUrl) {
2681
+ l.value = !0;
2682
+ try {
2683
+ const S = await (await fetch(`${f.value.apiUrl}/api/v1.0/stickers?activeOnly=true`, {
2684
+ headers: {
2685
+ "x-api-key": f.value.apiKey || ""
2686
+ }
2687
+ })).json();
2688
+ S.status === "SUCCESS" && (c.value = S.content);
2689
+ } catch (_) {
2690
+ console.error("[GigSupportChat] Error fetching stickers:", _);
2691
+ } finally {
2692
+ l.value = !1;
2693
+ }
2694
+ }
2695
+ },
2696
+ toggleWidget: () => {
2697
+ n.value = !n.value, n.value && (r.value = 0);
2698
+ },
2699
+ loadHistory: x,
2700
+ startReply: (k) => {
2701
+ h.value = k;
2702
+ },
2703
+ cancelReply: () => {
2704
+ h.value = null;
2705
+ }
2706
+ };
2707
+ }), Ps = ["data-message-id"], Ds = {
2708
+ key: 0,
2709
+ class: "gig-message-author"
2710
+ }, Is = { class: "gig-author-name" }, Vs = { class: "gig-reply-author" }, Us = { class: "gig-reply-text" }, Ms = ["src", "alt"], qs = ["innerHTML"], $s = { class: "gig-message-meta" }, Fs = { class: "gig-message-time" }, Hs = /* @__PURE__ */ Ie({
2711
+ __name: "ChatMessage",
2712
+ props: {
2713
+ message: {},
2714
+ currentUserId: {}
2715
+ },
2716
+ emits: ["reply", "scroll-to"],
2717
+ setup(s) {
2718
+ const e = s, t = De(() => e.message.userId === e.currentUserId), n = (c) => new Date(c).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }), r = (c) => {
2719
+ if (!c || c === "GIGMARKET Support") return c;
2720
+ const l = c.trim().split(/\s+/);
2721
+ return l.length >= 2 && l[1] ? `${l[0]} ${l[1][0]}.` : c;
2722
+ }, i = (c) => {
2723
+ if (!c) return "";
2724
+ const h = ((p) => p.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"))(c), f = /(https?:\/\/[^\s<]+[^\s<.,;:!?'")\]}>])/gi;
2725
+ return h.replace(f, (p) => `<a href="${p.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#039;/g, "'")}" target="_blank" rel="noopener noreferrer">${p}</a>`);
2726
+ };
2727
+ return (c, l) => (C(), O("div", {
2728
+ class: Ee(["gig-message-wrapper", t.value ? "sent" : "received"]),
2729
+ "data-message-id": s.message.id
2730
+ }, [
2731
+ t.value ? U("", !0) : (C(), O("div", Ds, [
2732
+ l[2] || (l[2] = u("div", { class: "gig-author-avatar" }, "GP", -1)),
2733
+ u("span", Is, V(r(s.message.userName || "Support")), 1)
2734
+ ])),
2735
+ u("div", {
2736
+ class: Ee(["gig-message-bubble", s.message.messageType === "sticker" ? "is-sticker" : ""])
2737
+ }, [
2738
+ s.message.replyToMessage ? (C(), O("div", {
2739
+ key: 0,
2740
+ class: "gig-reply-preview",
2741
+ onClick: l[0] || (l[0] = (h) => c.$emit("scroll-to", s.message.replyToMessageId))
2742
+ }, [
2743
+ u("div", Vs, V(s.message.replyToMessage.userId === s.currentUserId ? "Вы" : r(s.message.replyToMessage.userName || "Support")), 1),
2744
+ u("div", Us, V(s.message.replyToMessage.messageType === "sticker" ? "[Стикер]" : s.message.replyToMessage.text), 1)
2745
+ ])) : U("", !0),
2746
+ s.message.messageType === "sticker" && s.message.sticker ? (C(), O("img", {
2747
+ key: 1,
2748
+ src: `data:${s.message.sticker.mimeType || "image/png"};base64,${s.message.sticker.base64}`,
2749
+ class: "gig-sticker-img",
2750
+ alt: s.message.sticker.name
2751
+ }, null, 8, Ms)) : (C(), O("div", {
2752
+ key: 2,
2753
+ class: "gig-message-text",
2754
+ innerHTML: i(s.message.text || "")
2755
+ }, null, 8, qs)),
2756
+ u("div", $s, [
2757
+ u("span", Fs, V(n(s.message.createdAt)), 1)
2758
+ ]),
2759
+ u("button", {
2760
+ class: "gig-message-reply-btn",
2761
+ onClick: l[1] || (l[1] = (h) => c.$emit("reply", s.message))
2762
+ }, [...l[3] || (l[3] = [
2763
+ u("svg", {
2764
+ viewBox: "0 0 24 24",
2765
+ width: "14",
2766
+ height: "14",
2767
+ fill: "none",
2768
+ stroke: "currentColor",
2769
+ "stroke-width": "2"
2770
+ }, [
2771
+ u("polyline", { points: "9 17 4 12 9 7" }),
2772
+ u("path", { d: "M20 18v-2a4 4 0 0 0-4-4H4" })
2773
+ ], -1)
2774
+ ])])
2775
+ ], 2)
2776
+ ], 10, Ps));
2777
+ }
2778
+ }), bt = (s, e) => {
2779
+ const t = s.__vccOpts || s;
2780
+ for (const [n, r] of e)
2781
+ t[n] = r;
2782
+ return t;
2783
+ }, Ws = /* @__PURE__ */ bt(Hs, [["__scopeId", "data-v-0f2196d9"]]), zs = { class: "gig-header-info" }, js = { class: "gig-status-area" }, Ks = { class: "gig-status-text" }, Ys = {
2784
+ key: 0,
2785
+ class: "gig-empty-state"
2786
+ }, Xs = {
2787
+ key: 0,
2788
+ class: "gig-sticker-picker"
2789
+ }, Gs = { class: "gig-picker-header" }, Js = { class: "gig-sticker-grid" }, Qs = {
2790
+ key: 0,
2791
+ class: "gig-loading"
2792
+ }, Zs = ["onClick"], en = ["src", "alt"], tn = {
2793
+ key: 0,
2794
+ class: "gig-reply-bar"
2795
+ }, sn = { class: "gig-reply-content" }, nn = { class: "gig-reply-title" }, rn = { class: "gig-reply-preview" }, on = { class: "gig-chat-input-area" }, an = { class: "gig-input-wrapper" }, cn = ["onKeydown"], ln = ["disabled"], un = /* @__PURE__ */ Ie({
2796
+ __name: "ChatWindow",
2797
+ props: {
2798
+ messages: {},
2799
+ isConnected: { type: Boolean },
2800
+ currentUserId: {}
2801
+ },
2802
+ emits: ["close"],
2803
+ setup(s, { emit: e }) {
2804
+ const t = s, n = wt(), r = b(""), i = b(null), c = b({ x: 30, y: 110 }), l = b({ width: 440, height: 600 }), h = b(!1), f = b(null), p = b({ x: 0, y: 0, w: 0, h: 0 }), g = b(!1), w = () => {
2805
+ g.value = !g.value, g.value && n.stickers.length === 0 && n.fetchStickers();
2806
+ }, T = (y) => {
2807
+ n.sendSticker(y), g.value = !1, q();
2808
+ }, x = () => {
2809
+ r.value.trim() && (n.sendMessage(r.value), r.value = "", q());
2810
+ }, F = (y) => y.userId === t.currentUserId ? "вам" : j(y.userName || "Support"), z = (y) => y.messageType === "sticker" ? "[Стикер]" : y.text || "", j = (y) => y.trim().split(/\s+/)[0], q = async () => {
2811
+ await be(), i.value && (i.value.scrollTop = i.value.scrollHeight);
2812
+ }, ne = (y) => {
2813
+ var a;
2814
+ const o = (a = i.value) == null ? void 0 : a.querySelector(`[data-message-id="${y}"]`);
2815
+ o && (o.scrollIntoView({ behavior: "smooth", block: "center" }), o.classList.add("gig-highlight"), setTimeout(() => o.classList.remove("gig-highlight"), 2e3));
2816
+ }, k = (y) => {
2817
+ y.target.closest("button") || (h.value = !0, p.value = { x: y.clientX + c.value.x, y: y.clientY + c.value.y, w: 0, h: 0 }, window.addEventListener("mousemove", _), window.addEventListener("mouseup", K));
2818
+ }, _ = (y) => {
2819
+ h.value && (c.value = { x: p.value.x - y.clientX, y: p.value.y - y.clientY });
2820
+ }, S = (y, o) => {
2821
+ y.preventDefault(), f.value = o, p.value = { x: y.clientX, y: y.clientY, w: l.value.width, h: l.value.height }, window.addEventListener("mousemove", d), window.addEventListener("mouseup", K);
2822
+ }, d = (y) => {
2823
+ if (!f.value) return;
2824
+ const o = p.value.x - y.clientX, a = p.value.y - y.clientY;
2825
+ if (f.value === "left" || f.value === "corner") {
2826
+ const m = p.value.w + o;
2827
+ m > 320 && m < 800 && (l.value.width = m);
2828
+ }
2829
+ if (f.value === "top" || f.value === "corner") {
2830
+ const m = p.value.h + a;
2831
+ m > 400 && m < 900 && (l.value.height = m);
2832
+ }
2833
+ }, K = () => {
2834
+ h.value = !1, f.value = null, window.removeEventListener("mousemove", _), window.removeEventListener("mousemove", d), window.removeEventListener("mouseup", K);
2835
+ };
2836
+ return tt(() => t.messages.length, q), st(q), nt(K), (y, o) => (C(), O("div", {
2837
+ class: "gig-chat-window",
2838
+ style: Bt({
2839
+ width: l.value.width + "px",
2840
+ height: l.value.height + "px",
2841
+ bottom: c.value.y + "px",
2842
+ right: c.value.x + "px",
2843
+ cursor: h.value ? "grabbing" : "auto"
2844
+ })
2845
+ }, [
2846
+ u("div", {
2847
+ class: "gig-resize-h gig-resize-left",
2848
+ onMousedown: o[0] || (o[0] = (a) => S(a, "left"))
2849
+ }, null, 32),
2850
+ u("div", {
2851
+ class: "gig-resize-h gig-resize-top",
2852
+ onMousedown: o[1] || (o[1] = (a) => S(a, "top"))
2853
+ }, null, 32),
2854
+ u("div", {
2855
+ class: "gig-resize-corner",
2856
+ onMousedown: o[2] || (o[2] = (a) => S(a, "corner"))
2857
+ }, null, 32),
2858
+ u("div", {
2859
+ class: "gig-chat-header",
2860
+ onMousedown: k
2861
+ }, [
2862
+ o[13] || (o[13] = u("div", { class: "gig-header-brand-overlay" }, null, -1)),
2863
+ u("div", zs, [
2864
+ o[11] || (o[11] = u("div", { class: "gig-header-avatar" }, [
2865
+ u("svg", {
2866
+ viewBox: "0 0 24 24",
2867
+ width: "20",
2868
+ height: "20",
2869
+ fill: "none",
2870
+ stroke: "currentColor",
2871
+ "stroke-width": "2"
2872
+ }, [
2873
+ u("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" })
2874
+ ])
2875
+ ], -1)),
2876
+ u("div", null, [
2877
+ o[10] || (o[10] = u("h3", null, "Поддержка", -1)),
2878
+ u("div", js, [
2879
+ o[9] || (o[9] = u("span", { class: "gig-status-pulse" }, null, -1)),
2880
+ u("span", Ks, V(s.isConnected ? "В сети" : "Подключение..."), 1)
2881
+ ])
2882
+ ])
2883
+ ]),
2884
+ u("button", {
2885
+ onClick: o[3] || (o[3] = He((a) => y.$emit("close"), ["stop"])),
2886
+ class: "gig-close-btn"
2887
+ }, [...o[12] || (o[12] = [
2888
+ u("svg", {
2889
+ viewBox: "0 0 24 24",
2890
+ width: "20",
2891
+ height: "20",
2892
+ fill: "none",
2893
+ stroke: "currentColor",
2894
+ "stroke-width": "2"
2895
+ }, [
2896
+ u("line", {
2897
+ x1: "18",
2898
+ y1: "6",
2899
+ x2: "6",
2900
+ y2: "18"
2901
+ }),
2902
+ u("line", {
2903
+ x1: "6",
2904
+ y1: "6",
2905
+ x2: "18",
2906
+ y2: "18"
2907
+ })
2908
+ ], -1)
2909
+ ])])
2910
+ ], 32),
2911
+ u("div", {
2912
+ class: "gig-messages-container",
2913
+ ref_key: "messagesContainer",
2914
+ ref: i
2915
+ }, [
2916
+ s.messages.length === 0 ? (C(), O("div", Ys, [...o[14] || (o[14] = [
2917
+ u("div", { class: "gig-empty-icon" }, [
2918
+ u("svg", {
2919
+ viewBox: "0 0 24 24",
2920
+ width: "40",
2921
+ height: "40",
2922
+ fill: "none",
2923
+ stroke: "currentColor",
2924
+ "stroke-width": "1.5"
2925
+ }, [
2926
+ u("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" })
2927
+ ])
2928
+ ], -1),
2929
+ u("p", null, "Чем мы можем вам помочь?", -1)
2930
+ ])])) : U("", !0),
2931
+ (C(!0), O(We, null, ze(s.messages, (a) => (C(), rt(Ws, {
2932
+ key: a.id,
2933
+ message: a,
2934
+ "current-user-id": s.currentUserId,
2935
+ onReply: o[4] || (o[4] = (m) => N(n).startReply(m)),
2936
+ onScrollTo: ne
2937
+ }, null, 8, ["message", "current-user-id"]))), 128))
2938
+ ], 512),
2939
+ ke(Se, { name: "gig-slide-up" }, {
2940
+ default: Ce(() => [
2941
+ g.value ? (C(), O("div", Xs, [
2942
+ u("div", Gs, [
2943
+ o[15] || (o[15] = u("span", null, "Выберите стикер", -1)),
2944
+ u("button", {
2945
+ onClick: o[5] || (o[5] = (a) => g.value = !1),
2946
+ class: "gig-picker-close"
2947
+ }, "×")
2948
+ ]),
2949
+ u("div", Js, [
2950
+ N(n).isLoadingStickers ? (C(), O("div", Qs, "...")) : U("", !0),
2951
+ (C(!0), O(We, null, ze(N(n).stickers, (a) => (C(), O("div", {
2952
+ key: a.id,
2953
+ class: "gig-sticker-item",
2954
+ onClick: (m) => T(a.id)
2955
+ }, [
2956
+ u("img", {
2957
+ src: `data:${a.mimeType || "image/png"};base64,${a.base64}`,
2958
+ alt: a.name
2959
+ }, null, 8, en)
2960
+ ], 8, Zs))), 128))
2961
+ ])
2962
+ ])) : U("", !0)
2963
+ ]),
2964
+ _: 1
2965
+ }),
2966
+ ke(Se, { name: "gig-fade" }, {
2967
+ default: Ce(() => [
2968
+ N(n).replyingToMessage ? (C(), O("div", tn, [
2969
+ o[16] || (o[16] = u("div", { class: "gig-reply-line" }, null, -1)),
2970
+ u("div", sn, [
2971
+ u("div", nn, "Ответ " + V(F(N(n).replyingToMessage)), 1),
2972
+ u("div", rn, V(z(N(n).replyingToMessage)), 1)
2973
+ ]),
2974
+ u("button", {
2975
+ onClick: o[6] || (o[6] = (a) => N(n).cancelReply()),
2976
+ class: "gig-reply-close"
2977
+ }, "×")
2978
+ ])) : U("", !0)
2979
+ ]),
2980
+ _: 1
2981
+ }),
2982
+ u("div", on, [
2983
+ u("div", an, [
2984
+ u("button", {
2985
+ class: Ee(["gig-sticker-toggle", { active: g.value }]),
2986
+ onClick: w
2987
+ }, [...o[17] || (o[17] = [
2988
+ Lt('<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" data-v-4a6ac4c2><circle cx="12" cy="12" r="10" data-v-4a6ac4c2></circle><path d="M8 14s1.5 2 4 2 4-2 4-2" data-v-4a6ac4c2></path><line x1="9" y1="9" x2="9.01" y2="9" data-v-4a6ac4c2></line><line x1="15" y1="9" x2="15.01" y2="9" data-v-4a6ac4c2></line></svg>', 1)
2989
+ ])], 2),
2990
+ Pt(u("textarea", {
2991
+ "onUpdate:modelValue": o[7] || (o[7] = (a) => r.value = a),
2992
+ onKeydown: Dt(He(x, ["exact", "prevent"]), ["enter"]),
2993
+ placeholder: "Введите сообщение...",
2994
+ class: "gig-chat-input",
2995
+ rows: "1",
2996
+ onFocus: o[8] || (o[8] = (a) => g.value = !1)
2997
+ }, null, 40, cn), [
2998
+ [It, r.value]
2999
+ ]),
3000
+ u("button", {
3001
+ onClick: x,
3002
+ class: "gig-send-btn",
3003
+ disabled: !r.value.trim()
3004
+ }, [...o[18] || (o[18] = [
3005
+ u("svg", {
3006
+ viewBox: "0 0 24 24",
3007
+ width: "20",
3008
+ height: "20",
3009
+ fill: "none",
3010
+ stroke: "currentColor",
3011
+ "stroke-width": "2"
3012
+ }, [
3013
+ u("line", {
3014
+ x1: "22",
3015
+ y1: "2",
3016
+ x2: "11",
3017
+ y2: "13"
3018
+ }),
3019
+ u("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
3020
+ ], -1)
3021
+ ])], 8, ln)
3022
+ ]),
3023
+ o[19] || (o[19] = u("div", { class: "gig-powered-by" }, [
3024
+ u("span", null, "Powered by GIGMARKET")
3025
+ ], -1))
3026
+ ])
3027
+ ], 4));
3028
+ }
3029
+ }), hn = /* @__PURE__ */ bt(un, [["__scopeId", "data-v-4a6ac4c2"]]), fn = { class: "gig-chat-wrapper" }, dn = {
3030
+ key: 0,
3031
+ class: "gig-chat-badge"
3032
+ }, pn = {
3033
+ key: 1,
3034
+ viewBox: "0 0 24 24",
3035
+ width: "32",
3036
+ height: "32",
3037
+ fill: "none",
3038
+ stroke: "white",
3039
+ "stroke-width": "2"
3040
+ }, gn = {
3041
+ key: 2,
3042
+ viewBox: "0 0 24 24",
3043
+ width: "32",
3044
+ height: "32",
3045
+ fill: "none",
3046
+ stroke: "white",
3047
+ "stroke-width": "2"
3048
+ }, yn = /* @__PURE__ */ Ie({
3049
+ __name: "GigSupportChat",
3050
+ props: {
3051
+ config: {}
3052
+ },
3053
+ setup(s) {
3054
+ const e = s, t = wt();
3055
+ return st(() => {
3056
+ t.init(e.config), t.connect();
3057
+ }), nt(() => {
3058
+ t.disconnect();
3059
+ }), (n, r) => (C(), O("div", fn, [
3060
+ ke(Se, { name: "gig-fade" }, {
3061
+ default: Ce(() => [
3062
+ N(t).isWidgetOpen ? (C(), rt(hn, {
3063
+ key: 0,
3064
+ messages: N(t).messages,
3065
+ "is-connected": N(t).isConnected,
3066
+ "current-user-id": N(t).currentUserId,
3067
+ onSend: r[0] || (r[0] = (i) => N(t).sendMessage(i)),
3068
+ onClose: r[1] || (r[1] = (i) => N(t).toggleWidget())
3069
+ }, null, 8, ["messages", "is-connected", "current-user-id"])) : U("", !0)
3070
+ ]),
3071
+ _: 1
3072
+ }),
3073
+ u("button", {
3074
+ class: "gig-chat-trigger",
3075
+ onClick: r[2] || (r[2] = (i) => N(t).toggleWidget())
3076
+ }, [
3077
+ N(t).unreadCount > 0 ? (C(), O("div", dn, V(N(t).unreadCount), 1)) : U("", !0),
3078
+ N(t).isWidgetOpen ? (C(), O("svg", gn, [...r[4] || (r[4] = [
3079
+ u("line", {
3080
+ x1: "18",
3081
+ y1: "6",
3082
+ x2: "6",
3083
+ y2: "18"
3084
+ }, null, -1),
3085
+ u("line", {
3086
+ x1: "6",
3087
+ y1: "6",
3088
+ x2: "18",
3089
+ y2: "18"
3090
+ }, null, -1)
3091
+ ])])) : (C(), O("svg", pn, [...r[3] || (r[3] = [
3092
+ u("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }, null, -1)
3093
+ ])]))
3094
+ ])
3095
+ ]));
3096
+ }
3097
+ }), _n = {
3098
+ install: (s) => {
3099
+ s.component("GigSupportChat", yn);
3100
+ }
3101
+ };
3102
+ export {
3103
+ yn as GigSupportChat,
3104
+ _n as default,
3105
+ wt as useSupportChat
3106
+ };