@onedeskpro/chatbot-core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -12
- package/dist/index.cjs +327 -36
- package/dist/index.d.cts +103 -10
- package/dist/index.d.ts +103 -10
- package/dist/index.iife.js +327 -36
- package/dist/index.js +2973 -558
- package/package.json +13 -7
package/dist/index.js
CHANGED
|
@@ -1,177 +1,2021 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var e = Object.defineProperty, t = (t, n) => {
|
|
3
|
+
let r = {};
|
|
4
|
+
for (var i in t) e(r, i, {
|
|
5
|
+
get: t[i],
|
|
6
|
+
enumerable: !0
|
|
7
|
+
});
|
|
8
|
+
return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
|
|
9
|
+
}, n = 3e4;
|
|
10
|
+
function r(e) {
|
|
11
|
+
return typeof e == "object" && !!e && typeof e.message == "string";
|
|
12
|
+
}
|
|
13
|
+
function i(e) {
|
|
14
|
+
return e instanceof Error && "apiError" in e && "status" in e && typeof e.status == "number" && r(e.apiError);
|
|
15
|
+
}
|
|
16
|
+
var a = class {
|
|
17
|
+
constructor(e) {
|
|
18
|
+
this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.apiKey = e.apiKey, this.timeoutMs = e.timeoutMs ?? 3e4;
|
|
19
|
+
}
|
|
20
|
+
fail(e, t, n, r) {
|
|
21
|
+
let i = {
|
|
22
|
+
statusCode: t,
|
|
23
|
+
message: e,
|
|
24
|
+
code: n,
|
|
25
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
26
|
+
path: r
|
|
27
|
+
};
|
|
28
|
+
throw Object.assign(Error(e), {
|
|
29
|
+
apiError: i,
|
|
30
|
+
status: t
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async request(e, t, n, i, a) {
|
|
34
|
+
let o = new URL(`${this.baseUrl}${t}`);
|
|
35
|
+
if (i) for (let [e, t] of Object.entries(i)) o.searchParams.set(e, t);
|
|
36
|
+
let s = {
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
"X-API-Key": this.apiKey,
|
|
39
|
+
...a
|
|
40
|
+
}, c = new AbortController(), l = setTimeout(() => c.abort(), this.timeoutMs), u;
|
|
41
|
+
try {
|
|
42
|
+
u = await fetch(o.toString(), {
|
|
43
|
+
method: e,
|
|
44
|
+
headers: s,
|
|
45
|
+
signal: c.signal,
|
|
46
|
+
...n === void 0 ? {} : { body: JSON.stringify(n) }
|
|
47
|
+
});
|
|
48
|
+
} catch (e) {
|
|
49
|
+
c.signal.aborted && this.fail(`Request timed out after ${this.timeoutMs}ms.`, 0, "TIMEOUT", t), this.fail(e instanceof Error ? e.message : "Network request failed.", 0, "NETWORK_ERROR", t);
|
|
50
|
+
} finally {
|
|
51
|
+
clearTimeout(l);
|
|
52
|
+
}
|
|
53
|
+
let d = await u.text(), f = null;
|
|
54
|
+
if (d) try {
|
|
55
|
+
f = JSON.parse(d);
|
|
56
|
+
} catch {
|
|
57
|
+
f = null;
|
|
58
|
+
}
|
|
59
|
+
if (!u.ok) {
|
|
60
|
+
if (r(f)) throw Object.assign(Error(f.message), {
|
|
61
|
+
apiError: f,
|
|
62
|
+
status: u.status
|
|
63
|
+
});
|
|
64
|
+
this.fail(`Request failed with status ${u.status} ${u.statusText}`.trim(), u.status, "HTTP_ERROR", t);
|
|
65
|
+
}
|
|
66
|
+
return f === null && this.fail("The server returned an empty or malformed response.", u.status, "BAD_RESPONSE", t), f.data;
|
|
67
|
+
}
|
|
68
|
+
async identify(e) {
|
|
69
|
+
return this.request("POST", "/sdk/identify", e);
|
|
70
|
+
}
|
|
71
|
+
async verifyVisitor(e) {
|
|
72
|
+
return this.request("GET", "/sdk/visitor", void 0, void 0, { "X-Visitor-Token": e });
|
|
73
|
+
}
|
|
74
|
+
async sendMessage(e) {
|
|
75
|
+
return this.request("POST", "/sdk/chat", e);
|
|
76
|
+
}
|
|
77
|
+
async fetchConfig() {
|
|
78
|
+
return this.request("GET", "/sdk/config");
|
|
79
|
+
}
|
|
80
|
+
async requestHuman(e) {
|
|
81
|
+
return this.request("POST", "/sdk/human-request", { visitorToken: e });
|
|
82
|
+
}
|
|
83
|
+
async fetchTicketStatus(e) {
|
|
84
|
+
return this.request("GET", "/sdk/ticket-status", void 0, void 0, { "X-Visitor-Token": e });
|
|
85
|
+
}
|
|
86
|
+
}, o = "https://api.onedeskpro.com", s = class {
|
|
87
|
+
constructor() {
|
|
88
|
+
this._listeners = {};
|
|
89
|
+
}
|
|
90
|
+
on(e, t) {
|
|
91
|
+
return this._listeners[e] || (this._listeners[e] = []), this._listeners[e].push(t), () => this.off(e, t);
|
|
92
|
+
}
|
|
93
|
+
off(e, t) {
|
|
94
|
+
let n = this._listeners[e];
|
|
95
|
+
n && (this._listeners[e] = n.filter((e) => e !== t));
|
|
96
|
+
}
|
|
97
|
+
emit(e, ...t) {
|
|
98
|
+
let n = this._listeners[e];
|
|
99
|
+
if (n) for (let e of n) e(...t);
|
|
100
|
+
}
|
|
101
|
+
removeAllListeners() {
|
|
102
|
+
for (let e of Object.keys(this._listeners)) delete this._listeners[e];
|
|
103
|
+
}
|
|
104
|
+
}, c = Object.create(null);
|
|
105
|
+
c.open = "0", c.close = "1", c.ping = "2", c.pong = "3", c.message = "4", c.upgrade = "5", c.noop = "6";
|
|
106
|
+
var l = Object.create(null);
|
|
107
|
+
Object.keys(c).forEach((e) => {
|
|
108
|
+
l[c[e]] = e;
|
|
109
|
+
});
|
|
110
|
+
var u = {
|
|
111
|
+
type: "error",
|
|
112
|
+
data: "parser error"
|
|
113
|
+
}, d = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", f = typeof ArrayBuffer == "function", p = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e && e.buffer instanceof ArrayBuffer, m = ({ type: e, data: t }, n, r) => d && t instanceof Blob ? n ? r(t) : ee(t, r) : f && (t instanceof ArrayBuffer || p(t)) ? n ? r(t) : ee(new Blob([t]), r) : r(c[e] + (t || "")), ee = (e, t) => {
|
|
114
|
+
let n = new FileReader();
|
|
115
|
+
return n.onload = function() {
|
|
116
|
+
let e = n.result.split(",")[1];
|
|
117
|
+
t("b" + (e || ""));
|
|
118
|
+
}, n.readAsDataURL(e);
|
|
119
|
+
};
|
|
120
|
+
function te(e) {
|
|
121
|
+
return e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
122
|
+
}
|
|
123
|
+
var h;
|
|
124
|
+
function ne(e, t) {
|
|
125
|
+
if (d && e.data instanceof Blob) return e.data.arrayBuffer().then(te).then(t);
|
|
126
|
+
if (f && (e.data instanceof ArrayBuffer || p(e.data))) return t(te(e.data));
|
|
127
|
+
m(e, !1, (e) => {
|
|
128
|
+
h ||= new TextEncoder(), t(h.encode(e));
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js
|
|
133
|
+
var re = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", g = typeof Uint8Array > "u" ? [] : /* @__PURE__ */ new Uint8Array(256);
|
|
134
|
+
for (let e = 0; e < 64; e++) g[re.charCodeAt(e)] = e;
|
|
135
|
+
var ie = (e) => {
|
|
136
|
+
let t = e.length * .75, n = e.length, r, i = 0, a, o, s, c;
|
|
137
|
+
e[e.length - 1] === "=" && (t--, e[e.length - 2] === "=" && t--);
|
|
138
|
+
let l = new ArrayBuffer(t), u = new Uint8Array(l);
|
|
139
|
+
for (r = 0; r < n; r += 4) a = g[e.charCodeAt(r)], o = g[e.charCodeAt(r + 1)], s = g[e.charCodeAt(r + 2)], c = g[e.charCodeAt(r + 3)], u[i++] = a << 2 | o >> 4, u[i++] = (o & 15) << 4 | s >> 2, u[i++] = (s & 3) << 6 | c & 63;
|
|
140
|
+
return l;
|
|
141
|
+
}, ae = typeof ArrayBuffer == "function", _ = (e, t) => {
|
|
142
|
+
if (typeof e != "string") return {
|
|
143
|
+
type: "message",
|
|
144
|
+
data: v(e, t)
|
|
145
|
+
};
|
|
146
|
+
let n = e.charAt(0);
|
|
147
|
+
return n === "b" ? {
|
|
148
|
+
type: "message",
|
|
149
|
+
data: oe(e.substring(1), t)
|
|
150
|
+
} : l[n] ? e.length > 1 ? {
|
|
151
|
+
type: l[n],
|
|
152
|
+
data: e.substring(1)
|
|
153
|
+
} : { type: l[n] } : u;
|
|
154
|
+
}, oe = (e, t) => ae ? v(ie(e), t) : {
|
|
155
|
+
base64: !0,
|
|
156
|
+
data: e
|
|
157
|
+
}, v = (e, t) => {
|
|
158
|
+
switch (t) {
|
|
159
|
+
case "blob": return e instanceof Blob ? e : new Blob([e]);
|
|
160
|
+
default: return e instanceof ArrayBuffer ? e : e.buffer;
|
|
161
|
+
}
|
|
162
|
+
}, y = "", se = (e, t) => {
|
|
163
|
+
let n = e.length, r = Array(n), i = 0;
|
|
164
|
+
e.forEach((e, a) => {
|
|
165
|
+
m(e, !1, (e) => {
|
|
166
|
+
r[a] = e, ++i === n && t(r.join(y));
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}, ce = (e, t) => {
|
|
170
|
+
let n = e.split(y), r = [];
|
|
171
|
+
for (let e = 0; e < n.length; e++) {
|
|
172
|
+
let i = _(n[e], t);
|
|
173
|
+
if (r.push(i), i.type === "error") break;
|
|
174
|
+
}
|
|
175
|
+
return r;
|
|
176
|
+
};
|
|
177
|
+
function le() {
|
|
178
|
+
return new TransformStream({ transform(e, t) {
|
|
179
|
+
ne(e, (n) => {
|
|
180
|
+
let r = n.length, i;
|
|
181
|
+
if (r < 126) i = /* @__PURE__ */ new Uint8Array(1), new DataView(i.buffer).setUint8(0, r);
|
|
182
|
+
else if (r < 65536) {
|
|
183
|
+
i = /* @__PURE__ */ new Uint8Array(3);
|
|
184
|
+
let e = new DataView(i.buffer);
|
|
185
|
+
e.setUint8(0, 126), e.setUint16(1, r);
|
|
186
|
+
} else {
|
|
187
|
+
i = /* @__PURE__ */ new Uint8Array(9);
|
|
188
|
+
let e = new DataView(i.buffer);
|
|
189
|
+
e.setUint8(0, 127), e.setBigUint64(1, BigInt(r));
|
|
190
|
+
}
|
|
191
|
+
e.data && typeof e.data != "string" && (i[0] |= 128), t.enqueue(i), t.enqueue(n);
|
|
192
|
+
});
|
|
193
|
+
} });
|
|
194
|
+
}
|
|
195
|
+
var ue;
|
|
196
|
+
function b(e) {
|
|
197
|
+
return e.reduce((e, t) => e + t.length, 0);
|
|
198
|
+
}
|
|
199
|
+
function x(e, t) {
|
|
200
|
+
if (e[0].length === t) return e.shift();
|
|
201
|
+
let n = new Uint8Array(t), r = 0;
|
|
202
|
+
for (let i = 0; i < t; i++) n[i] = e[0][r++], r === e[0].length && (e.shift(), r = 0);
|
|
203
|
+
return e.length && r < e[0].length && (e[0] = e[0].slice(r)), n;
|
|
204
|
+
}
|
|
205
|
+
function de(e, t) {
|
|
206
|
+
ue ||= new TextDecoder();
|
|
207
|
+
let n = [], r = 0, i = -1, a = !1;
|
|
208
|
+
return new TransformStream({ transform(o, s) {
|
|
209
|
+
for (n.push(o);;) {
|
|
210
|
+
if (r === 0) {
|
|
211
|
+
if (b(n) < 1) break;
|
|
212
|
+
let e = x(n, 1);
|
|
213
|
+
a = (e[0] & 128) == 128, i = e[0] & 127, r = i < 126 ? 3 : i === 126 ? 1 : 2;
|
|
214
|
+
} else if (r === 1) {
|
|
215
|
+
if (b(n) < 2) break;
|
|
216
|
+
let e = x(n, 2);
|
|
217
|
+
i = new DataView(e.buffer, e.byteOffset, e.length).getUint16(0), r = 3;
|
|
218
|
+
} else if (r === 2) {
|
|
219
|
+
if (b(n) < 8) break;
|
|
220
|
+
let e = x(n, 8), t = new DataView(e.buffer, e.byteOffset, e.length), a = t.getUint32(0);
|
|
221
|
+
if (a > 2 ** 21 - 1) {
|
|
222
|
+
s.enqueue(u);
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
i = a * 2 ** 32 + t.getUint32(4), r = 3;
|
|
226
|
+
} else {
|
|
227
|
+
if (b(n) < i) break;
|
|
228
|
+
let e = x(n, i);
|
|
229
|
+
s.enqueue(_(a ? e : ue.decode(e), t)), r = 0;
|
|
230
|
+
}
|
|
231
|
+
if (i === 0 || i > e) {
|
|
232
|
+
s.enqueue(u);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
} });
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region ../../node_modules/.pnpm/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/esm/index.js
|
|
240
|
+
function S(e) {
|
|
241
|
+
if (e) return fe(e);
|
|
242
|
+
}
|
|
243
|
+
function fe(e) {
|
|
244
|
+
for (var t in S.prototype) e[t] = S.prototype[t];
|
|
245
|
+
return e;
|
|
246
|
+
}
|
|
247
|
+
S.prototype.on = S.prototype.addEventListener = function(e, t) {
|
|
248
|
+
return this._callbacks = this._callbacks || {}, (this._callbacks["$" + e] = this._callbacks["$" + e] || []).push(t), this;
|
|
249
|
+
}, S.prototype.once = function(e, t) {
|
|
250
|
+
function n() {
|
|
251
|
+
this.off(e, n), t.apply(this, arguments);
|
|
252
|
+
}
|
|
253
|
+
return n.fn = t, this.on(e, n), this;
|
|
254
|
+
}, S.prototype.off = S.prototype.removeListener = S.prototype.removeAllListeners = S.prototype.removeEventListener = function(e, t) {
|
|
255
|
+
if (this._callbacks = this._callbacks || {}, arguments.length == 0) return this._callbacks = {}, this;
|
|
256
|
+
var n = this._callbacks["$" + e];
|
|
257
|
+
if (!n) return this;
|
|
258
|
+
if (arguments.length == 1) return delete this._callbacks["$" + e], this;
|
|
259
|
+
for (var r, i = 0; i < n.length; i++) if (r = n[i], r === t || r.fn === t) {
|
|
260
|
+
n.splice(i, 1);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
return n.length === 0 && delete this._callbacks["$" + e], this;
|
|
264
|
+
}, S.prototype.emit = function(e) {
|
|
265
|
+
this._callbacks = this._callbacks || {};
|
|
266
|
+
for (var t = Array(arguments.length - 1), n = this._callbacks["$" + e], r = 1; r < arguments.length; r++) t[r - 1] = arguments[r];
|
|
267
|
+
if (n) {
|
|
268
|
+
n = n.slice(0);
|
|
269
|
+
for (var r = 0, i = n.length; r < i; ++r) n[r].apply(this, t);
|
|
270
|
+
}
|
|
271
|
+
return this;
|
|
272
|
+
}, S.prototype.emitReserved = S.prototype.emit, S.prototype.listeners = function(e) {
|
|
273
|
+
return this._callbacks = this._callbacks || {}, this._callbacks["$" + e] || [];
|
|
274
|
+
}, S.prototype.hasListeners = function(e) {
|
|
275
|
+
return !!this.listeners(e).length;
|
|
276
|
+
};
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/globals.js
|
|
279
|
+
var C = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), w = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), pe = "arraybuffer";
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/util.js
|
|
282
|
+
function me(e, ...t) {
|
|
283
|
+
return t.reduce((t, n) => (e.hasOwnProperty(n) && (t[n] = e[n]), t), {});
|
|
284
|
+
}
|
|
285
|
+
var he = w.setTimeout, ge = w.clearTimeout;
|
|
286
|
+
function T(e, t) {
|
|
287
|
+
t.useNativeTimers ? (e.setTimeoutFn = he.bind(w), e.clearTimeoutFn = ge.bind(w)) : (e.setTimeoutFn = w.setTimeout.bind(w), e.clearTimeoutFn = w.clearTimeout.bind(w));
|
|
288
|
+
}
|
|
289
|
+
var _e = 1.33;
|
|
290
|
+
function ve(e) {
|
|
291
|
+
return typeof e == "string" ? ye(e) : Math.ceil((e.byteLength || e.size) * _e);
|
|
292
|
+
}
|
|
293
|
+
function ye(e) {
|
|
294
|
+
let t = 0, n = 0;
|
|
295
|
+
for (let r = 0, i = e.length; r < i; r++) t = e.charCodeAt(r), t < 128 ? n += 1 : t < 2048 ? n += 2 : t < 55296 || t >= 57344 ? n += 3 : (r++, n += 4);
|
|
296
|
+
return n;
|
|
297
|
+
}
|
|
298
|
+
function be() {
|
|
299
|
+
return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
|
|
300
|
+
}
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/contrib/parseqs.js
|
|
303
|
+
function xe(e) {
|
|
304
|
+
let t = "";
|
|
305
|
+
for (let n in e) e.hasOwnProperty(n) && (t.length && (t += "&"), t += encodeURIComponent(n) + "=" + encodeURIComponent(e[n]));
|
|
306
|
+
return t;
|
|
307
|
+
}
|
|
308
|
+
function Se(e) {
|
|
309
|
+
let t = {}, n = e.split("&");
|
|
310
|
+
for (let e = 0, r = n.length; e < r; e++) {
|
|
311
|
+
let r = n[e].split("=");
|
|
312
|
+
t[decodeURIComponent(r[0])] = decodeURIComponent(r[1]);
|
|
313
|
+
}
|
|
314
|
+
return t;
|
|
315
|
+
}
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transport.js
|
|
318
|
+
var Ce = class extends Error {
|
|
319
|
+
constructor(e, t, n) {
|
|
320
|
+
super(e), this.description = t, this.context = n, this.type = "TransportError";
|
|
321
|
+
}
|
|
322
|
+
}, E = class extends S {
|
|
323
|
+
constructor(e) {
|
|
324
|
+
super(), this.writable = !1, T(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
|
|
325
|
+
}
|
|
326
|
+
onError(e, t, n) {
|
|
327
|
+
return super.emitReserved("error", new Ce(e, t, n)), this;
|
|
328
|
+
}
|
|
329
|
+
open() {
|
|
330
|
+
return this.readyState = "opening", this.doOpen(), this;
|
|
331
|
+
}
|
|
332
|
+
close() {
|
|
333
|
+
return (this.readyState === "opening" || this.readyState === "open") && (this.doClose(), this.onClose()), this;
|
|
334
|
+
}
|
|
335
|
+
send(e) {
|
|
336
|
+
this.readyState === "open" && this.write(e);
|
|
337
|
+
}
|
|
338
|
+
onOpen() {
|
|
339
|
+
this.readyState = "open", this.writable = !0, super.emitReserved("open");
|
|
340
|
+
}
|
|
341
|
+
onData(e) {
|
|
342
|
+
let t = _(e, this.socket.binaryType);
|
|
343
|
+
this.onPacket(t);
|
|
344
|
+
}
|
|
345
|
+
onPacket(e) {
|
|
346
|
+
super.emitReserved("packet", e);
|
|
347
|
+
}
|
|
348
|
+
onClose(e) {
|
|
349
|
+
this.readyState = "closed", super.emitReserved("close", e);
|
|
350
|
+
}
|
|
351
|
+
pause(e) {}
|
|
352
|
+
createUri(e, t = {}) {
|
|
353
|
+
return e + "://" + this._hostname() + this._port() + this.opts.path + this._query(t);
|
|
354
|
+
}
|
|
355
|
+
_hostname() {
|
|
356
|
+
let e = this.opts.hostname;
|
|
357
|
+
return e.indexOf(":") === -1 ? e : "[" + e + "]";
|
|
358
|
+
}
|
|
359
|
+
_port() {
|
|
360
|
+
return this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
|
|
361
|
+
}
|
|
362
|
+
_query(e) {
|
|
363
|
+
let t = xe(e);
|
|
364
|
+
return t.length ? "?" + t : "";
|
|
365
|
+
}
|
|
366
|
+
}, we = class extends E {
|
|
367
|
+
constructor() {
|
|
368
|
+
super(...arguments), this._polling = !1;
|
|
369
|
+
}
|
|
370
|
+
get name() {
|
|
371
|
+
return "polling";
|
|
372
|
+
}
|
|
373
|
+
doOpen() {
|
|
374
|
+
this._poll();
|
|
375
|
+
}
|
|
376
|
+
pause(e) {
|
|
377
|
+
this.readyState = "pausing";
|
|
378
|
+
let t = () => {
|
|
379
|
+
this.readyState = "paused", e();
|
|
380
|
+
};
|
|
381
|
+
if (this._polling || !this.writable) {
|
|
382
|
+
let e = 0;
|
|
383
|
+
this._polling && (e++, this.once("pollComplete", function() {
|
|
384
|
+
--e || t();
|
|
385
|
+
})), this.writable || (e++, this.once("drain", function() {
|
|
386
|
+
--e || t();
|
|
387
|
+
}));
|
|
388
|
+
} else t();
|
|
389
|
+
}
|
|
390
|
+
_poll() {
|
|
391
|
+
this._polling = !0, this.doPoll(), this.emitReserved("poll");
|
|
392
|
+
}
|
|
393
|
+
onData(e) {
|
|
394
|
+
ce(e, this.socket.binaryType).forEach((e) => {
|
|
395
|
+
if (this.readyState === "opening" && e.type === "open" && this.onOpen(), e.type === "close") return this.onClose({ description: "transport closed by the server" }), !1;
|
|
396
|
+
this.onPacket(e);
|
|
397
|
+
}), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
|
|
398
|
+
}
|
|
399
|
+
doClose() {
|
|
400
|
+
let e = () => {
|
|
401
|
+
this.write([{ type: "close" }]);
|
|
402
|
+
};
|
|
403
|
+
this.readyState === "open" ? e() : this.once("open", e);
|
|
404
|
+
}
|
|
405
|
+
write(e) {
|
|
406
|
+
this.writable = !1, se(e, (e) => {
|
|
407
|
+
this.doWrite(e, () => {
|
|
408
|
+
this.writable = !0, this.emitReserved("drain");
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
uri() {
|
|
413
|
+
let e = this.opts.secure ? "https" : "http", t = this.query || {};
|
|
414
|
+
return !1 !== this.opts.timestampRequests && (t[this.opts.timestampParam] = be()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
|
|
415
|
+
}
|
|
416
|
+
}, Te = !1;
|
|
417
|
+
try {
|
|
418
|
+
Te = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
|
|
419
|
+
} catch {}
|
|
420
|
+
var Ee = Te;
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transports/polling-xhr.js
|
|
423
|
+
function De() {}
|
|
424
|
+
var Oe = class extends we {
|
|
425
|
+
constructor(e) {
|
|
426
|
+
if (super(e), typeof location < "u") {
|
|
427
|
+
let t = location.protocol === "https:", n = location.port;
|
|
428
|
+
n ||= t ? "443" : "80", this.xd = typeof location < "u" && e.hostname !== location.hostname || n !== e.port;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
doWrite(e, t) {
|
|
432
|
+
let n = this.request({
|
|
433
|
+
method: "POST",
|
|
434
|
+
data: e
|
|
435
|
+
});
|
|
436
|
+
n.on("success", t), n.on("error", (e, t) => {
|
|
437
|
+
this.onError("xhr post error", e, t);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
doPoll() {
|
|
441
|
+
let e = this.request();
|
|
442
|
+
e.on("data", this.onData.bind(this)), e.on("error", (e, t) => {
|
|
443
|
+
this.onError("xhr poll error", e, t);
|
|
444
|
+
}), this.pollXhr = e;
|
|
445
|
+
}
|
|
446
|
+
}, D = class e extends S {
|
|
447
|
+
constructor(e, t, n) {
|
|
448
|
+
super(), this.createRequest = e, T(this, n), this._opts = n, this._method = n.method || "GET", this._uri = t, this._data = n.data === void 0 ? null : n.data, this._create();
|
|
449
|
+
}
|
|
450
|
+
_create() {
|
|
451
|
+
var t;
|
|
452
|
+
let n = me(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
453
|
+
n.xdomain = !!this._opts.xd;
|
|
454
|
+
let r = this._xhr = this.createRequest(n);
|
|
455
|
+
try {
|
|
456
|
+
r.open(this._method, this._uri, !0);
|
|
457
|
+
try {
|
|
458
|
+
if (this._opts.extraHeaders) {
|
|
459
|
+
r.setDisableHeaderCheck && r.setDisableHeaderCheck(!0);
|
|
460
|
+
for (let e in this._opts.extraHeaders) this._opts.extraHeaders.hasOwnProperty(e) && r.setRequestHeader(e, this._opts.extraHeaders[e]);
|
|
461
|
+
}
|
|
462
|
+
} catch {}
|
|
463
|
+
if (this._method === "POST") try {
|
|
464
|
+
r.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
|
|
465
|
+
} catch {}
|
|
466
|
+
try {
|
|
467
|
+
r.setRequestHeader("Accept", "*/*");
|
|
468
|
+
} catch {}
|
|
469
|
+
(t = this._opts.cookieJar) == null || t.addCookies(r), "withCredentials" in r && (r.withCredentials = this._opts.withCredentials), this._opts.requestTimeout && (r.timeout = this._opts.requestTimeout), r.onreadystatechange = () => {
|
|
470
|
+
var e;
|
|
471
|
+
r.readyState === 3 && ((e = this._opts.cookieJar) == null || e.parseCookies(r.getResponseHeader("set-cookie"))), r.readyState === 4 && (r.status === 200 || r.status === 1223 ? this._onLoad() : this.setTimeoutFn(() => {
|
|
472
|
+
this._onError(typeof r.status == "number" ? r.status : 0);
|
|
473
|
+
}, 0));
|
|
474
|
+
}, r.send(this._data);
|
|
475
|
+
} catch (e) {
|
|
476
|
+
this.setTimeoutFn(() => {
|
|
477
|
+
this._onError(e);
|
|
478
|
+
}, 0);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
typeof document < "u" && (this._index = e.requestsCount++, e.requests[this._index] = this);
|
|
482
|
+
}
|
|
483
|
+
_onError(e) {
|
|
484
|
+
this.emitReserved("error", e, this._xhr), this._cleanup(!0);
|
|
485
|
+
}
|
|
486
|
+
_cleanup(t) {
|
|
487
|
+
if (this._xhr !== void 0 && this._xhr !== null) {
|
|
488
|
+
if (this._xhr.onreadystatechange = De, t) try {
|
|
489
|
+
this._xhr.abort();
|
|
490
|
+
} catch {}
|
|
491
|
+
typeof document < "u" && delete e.requests[this._index], this._xhr = null;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
_onLoad() {
|
|
495
|
+
let e = this._xhr.responseText;
|
|
496
|
+
e !== null && (this.emitReserved("data", e), this.emitReserved("success"), this._cleanup());
|
|
497
|
+
}
|
|
498
|
+
abort() {
|
|
499
|
+
this._cleanup();
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
if (D.requestsCount = 0, D.requests = {}, typeof document < "u") {
|
|
503
|
+
if (typeof attachEvent == "function") attachEvent("onunload", O);
|
|
504
|
+
else if (typeof addEventListener == "function") {
|
|
505
|
+
let e = "onpagehide" in w ? "pagehide" : "unload";
|
|
506
|
+
addEventListener(e, O, !1);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
function O() {
|
|
510
|
+
for (let e in D.requests) D.requests.hasOwnProperty(e) && D.requests[e].abort();
|
|
511
|
+
}
|
|
512
|
+
var ke = (function() {
|
|
513
|
+
let e = je({ xdomain: !1 });
|
|
514
|
+
return e && e.responseType !== null;
|
|
515
|
+
})(), Ae = class extends Oe {
|
|
516
|
+
constructor(e) {
|
|
517
|
+
super(e);
|
|
518
|
+
let t = e && e.forceBase64;
|
|
519
|
+
this.supportsBinary = ke && !t;
|
|
520
|
+
}
|
|
521
|
+
request(e = {}) {
|
|
522
|
+
return Object.assign(e, { xd: this.xd }, this.opts), new D(je, this.uri(), e);
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
function je(e) {
|
|
526
|
+
let t = e.xdomain;
|
|
527
|
+
try {
|
|
528
|
+
if (typeof XMLHttpRequest < "u" && (!t || Ee)) return new XMLHttpRequest();
|
|
529
|
+
} catch {}
|
|
530
|
+
if (!t) try {
|
|
531
|
+
return new w[["Active", "Object"].join("X")]("Microsoft.XMLHTTP");
|
|
532
|
+
} catch {}
|
|
533
|
+
}
|
|
534
|
+
//#endregion
|
|
535
|
+
//#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transports/websocket.js
|
|
536
|
+
var Me = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative", Ne = class extends E {
|
|
537
|
+
get name() {
|
|
538
|
+
return "websocket";
|
|
539
|
+
}
|
|
540
|
+
doOpen() {
|
|
541
|
+
let e = this.uri(), t = this.opts.protocols, n = Me ? {} : me(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
|
|
542
|
+
this.opts.extraHeaders && (n.headers = this.opts.extraHeaders);
|
|
543
|
+
try {
|
|
544
|
+
this.ws = this.createSocket(e, t, n);
|
|
545
|
+
} catch (e) {
|
|
546
|
+
return this.emitReserved("error", e);
|
|
547
|
+
}
|
|
548
|
+
this.ws.binaryType = this.socket.binaryType, this.addEventListeners();
|
|
549
|
+
}
|
|
550
|
+
addEventListeners() {
|
|
551
|
+
this.ws.onopen = () => {
|
|
552
|
+
this.opts.autoUnref && this.ws._socket.unref(), this.onOpen();
|
|
553
|
+
}, this.ws.onclose = (e) => this.onClose({
|
|
554
|
+
description: "websocket connection closed",
|
|
555
|
+
context: e
|
|
556
|
+
}), this.ws.onmessage = (e) => this.onData(e.data), this.ws.onerror = (e) => this.onError("websocket error", e);
|
|
557
|
+
}
|
|
558
|
+
write(e) {
|
|
559
|
+
this.writable = !1;
|
|
560
|
+
for (let t = 0; t < e.length; t++) {
|
|
561
|
+
let n = e[t], r = t === e.length - 1;
|
|
562
|
+
m(n, this.supportsBinary, (e) => {
|
|
563
|
+
try {
|
|
564
|
+
this.doWrite(n, e);
|
|
565
|
+
} catch {}
|
|
566
|
+
r && C(() => {
|
|
567
|
+
this.writable = !0, this.emitReserved("drain");
|
|
568
|
+
}, this.setTimeoutFn);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
doClose() {
|
|
573
|
+
this.ws !== void 0 && (this.ws.onerror = () => {}, this.ws.close(), this.ws = null);
|
|
574
|
+
}
|
|
575
|
+
uri() {
|
|
576
|
+
let e = this.opts.secure ? "wss" : "ws", t = this.query || {};
|
|
577
|
+
return this.opts.timestampRequests && (t[this.opts.timestampParam] = be()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
|
|
578
|
+
}
|
|
579
|
+
}, k = w.WebSocket || w.MozWebSocket, Pe = {
|
|
580
|
+
websocket: class extends Ne {
|
|
581
|
+
createSocket(e, t, n) {
|
|
582
|
+
return Me ? new k(e, t, n) : t ? new k(e, t) : new k(e);
|
|
583
|
+
}
|
|
584
|
+
doWrite(e, t) {
|
|
585
|
+
this.ws.send(t);
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
webtransport: class extends E {
|
|
589
|
+
get name() {
|
|
590
|
+
return "webtransport";
|
|
591
|
+
}
|
|
592
|
+
doOpen() {
|
|
593
|
+
try {
|
|
594
|
+
this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
|
|
595
|
+
} catch (e) {
|
|
596
|
+
return this.emitReserved("error", e);
|
|
597
|
+
}
|
|
598
|
+
this._transport.closed.then(() => {
|
|
599
|
+
this.onClose();
|
|
600
|
+
}).catch((e) => {
|
|
601
|
+
this.onError("webtransport error", e);
|
|
602
|
+
}), this._transport.ready.then(() => {
|
|
603
|
+
this._transport.createBidirectionalStream().then((e) => {
|
|
604
|
+
let t = de(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = le();
|
|
605
|
+
r.readable.pipeTo(e.writable), this._writer = r.writable.getWriter();
|
|
606
|
+
let i = () => {
|
|
607
|
+
n.read().then(({ done: e, value: t }) => {
|
|
608
|
+
e || (this.onPacket(t), i());
|
|
609
|
+
}).catch((e) => {});
|
|
610
|
+
};
|
|
611
|
+
i();
|
|
612
|
+
let a = { type: "open" };
|
|
613
|
+
this.query.sid && (a.data = `{"sid":"${this.query.sid}"}`), this._writer.write(a).then(() => this.onOpen());
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
write(e) {
|
|
618
|
+
this.writable = !1;
|
|
619
|
+
for (let t = 0; t < e.length; t++) {
|
|
620
|
+
let n = e[t], r = t === e.length - 1;
|
|
621
|
+
this._writer.write(n).then(() => {
|
|
622
|
+
r && C(() => {
|
|
623
|
+
this.writable = !0, this.emitReserved("drain");
|
|
624
|
+
}, this.setTimeoutFn);
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
doClose() {
|
|
629
|
+
var e;
|
|
630
|
+
(e = this._transport) == null || e.close();
|
|
631
|
+
}
|
|
632
|
+
},
|
|
633
|
+
polling: Ae
|
|
634
|
+
}, Fe = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, Ie = [
|
|
635
|
+
"source",
|
|
636
|
+
"protocol",
|
|
637
|
+
"authority",
|
|
638
|
+
"userInfo",
|
|
639
|
+
"user",
|
|
640
|
+
"password",
|
|
641
|
+
"host",
|
|
642
|
+
"port",
|
|
643
|
+
"relative",
|
|
644
|
+
"path",
|
|
645
|
+
"directory",
|
|
646
|
+
"file",
|
|
647
|
+
"query",
|
|
648
|
+
"anchor"
|
|
649
|
+
];
|
|
650
|
+
function A(e) {
|
|
651
|
+
if (e.length > 8e3) throw "URI too long";
|
|
652
|
+
let t = e, n = e.indexOf("["), r = e.indexOf("]");
|
|
653
|
+
n != -1 && r != -1 && (e = e.substring(0, n) + e.substring(n, r).replace(/:/g, ";") + e.substring(r, e.length));
|
|
654
|
+
let i = Fe.exec(e || ""), a = {}, o = 14;
|
|
655
|
+
for (; o--;) a[Ie[o]] = i[o] || "";
|
|
656
|
+
return n != -1 && r != -1 && (a.source = t, a.host = a.host.substring(1, a.host.length - 1).replace(/;/g, ":"), a.authority = a.authority.replace("[", "").replace("]", "").replace(/;/g, ":"), a.ipv6uri = !0), a.pathNames = Le(a, a.path), a.queryKey = Re(a, a.query), a;
|
|
657
|
+
}
|
|
658
|
+
function Le(e, t) {
|
|
659
|
+
let n = t.replace(/\/{2,9}/g, "/").split("/");
|
|
660
|
+
return (t.slice(0, 1) == "/" || t.length === 0) && n.splice(0, 1), t.slice(-1) == "/" && n.splice(n.length - 1, 1), n;
|
|
661
|
+
}
|
|
662
|
+
function Re(e, t) {
|
|
663
|
+
let n = {};
|
|
664
|
+
return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(e, t, r) {
|
|
665
|
+
t && (n[t] = r);
|
|
666
|
+
}), n;
|
|
667
|
+
}
|
|
668
|
+
//#endregion
|
|
669
|
+
//#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/socket.js
|
|
670
|
+
var j = typeof addEventListener == "function" && typeof removeEventListener == "function", M = [];
|
|
671
|
+
j && addEventListener("offline", () => {
|
|
672
|
+
M.forEach((e) => e());
|
|
673
|
+
}, !1);
|
|
674
|
+
var N = class e extends S {
|
|
675
|
+
constructor(e, t) {
|
|
676
|
+
if (super(), this.binaryType = pe, this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = Infinity, e && typeof e == "object" && (t = e, e = null), e) {
|
|
677
|
+
let n = A(e);
|
|
678
|
+
t.hostname = n.host, t.secure = n.protocol === "https" || n.protocol === "wss", t.port = n.port, n.query && (t.query = n.query);
|
|
679
|
+
} else t.host && (t.hostname = A(t.host).host);
|
|
680
|
+
T(this, t), this.secure = t.secure == null ? typeof location < "u" && location.protocol === "https:" : t.secure, 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((e) => {
|
|
681
|
+
let t = e.prototype.name;
|
|
682
|
+
this.transports.push(t), this._transportsByName[t] = e;
|
|
683
|
+
}), this.opts = Object.assign({
|
|
684
|
+
path: "/engine.io",
|
|
685
|
+
agent: !1,
|
|
686
|
+
withCredentials: !1,
|
|
687
|
+
upgrade: !0,
|
|
688
|
+
timestampParam: "t",
|
|
689
|
+
rememberUpgrade: !1,
|
|
690
|
+
addTrailingSlash: !0,
|
|
691
|
+
rejectUnauthorized: !0,
|
|
692
|
+
perMessageDeflate: { threshold: 1024 },
|
|
693
|
+
transportOptions: {},
|
|
694
|
+
closeOnBeforeunload: !1
|
|
695
|
+
}, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = Se(this.opts.query)), j && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
|
|
696
|
+
this.transport && (this.transport.removeAllListeners(), this.transport.close());
|
|
697
|
+
}, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
|
|
698
|
+
this._onClose("transport close", { description: "network connection lost" });
|
|
699
|
+
}, M.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
|
|
700
|
+
}
|
|
701
|
+
createTransport(e) {
|
|
702
|
+
let t = Object.assign({}, this.opts.query);
|
|
703
|
+
t.EIO = 4, t.transport = e, this.id && (t.sid = this.id);
|
|
704
|
+
let n = Object.assign({}, this.opts, {
|
|
705
|
+
query: t,
|
|
706
|
+
socket: this,
|
|
707
|
+
hostname: this.hostname,
|
|
708
|
+
secure: this.secure,
|
|
709
|
+
port: this.port
|
|
710
|
+
}, this.opts.transportOptions[e]);
|
|
711
|
+
return new this._transportsByName[e](n);
|
|
712
|
+
}
|
|
713
|
+
_open() {
|
|
714
|
+
if (this.transports.length === 0) {
|
|
715
|
+
this.setTimeoutFn(() => {
|
|
716
|
+
this.emitReserved("error", "No transports available");
|
|
717
|
+
}, 0);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
let t = this.opts.rememberUpgrade && e.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
|
|
721
|
+
this.readyState = "opening";
|
|
722
|
+
let n = this.createTransport(t);
|
|
723
|
+
n.open(), this.setTransport(n);
|
|
724
|
+
}
|
|
725
|
+
setTransport(e) {
|
|
726
|
+
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", (e) => this._onClose("transport close", e));
|
|
727
|
+
}
|
|
728
|
+
onOpen() {
|
|
729
|
+
this.readyState = "open", e.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush();
|
|
730
|
+
}
|
|
731
|
+
_onPacket(e) {
|
|
732
|
+
if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") switch (this.emitReserved("packet", e), this.emitReserved("heartbeat"), e.type) {
|
|
733
|
+
case "open":
|
|
734
|
+
this.onHandshake(JSON.parse(e.data));
|
|
735
|
+
break;
|
|
736
|
+
case "ping":
|
|
737
|
+
this._sendPacket("pong"), this.emitReserved("ping"), this.emitReserved("pong"), this._resetPingTimeout();
|
|
738
|
+
break;
|
|
739
|
+
case "error":
|
|
740
|
+
let t = /* @__PURE__ */ Error("server error");
|
|
741
|
+
t.code = e.data, this._onError(t);
|
|
742
|
+
break;
|
|
743
|
+
case "message": this.emitReserved("data", e.data), this.emitReserved("message", e.data);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
onHandshake(e) {
|
|
747
|
+
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();
|
|
748
|
+
}
|
|
749
|
+
_resetPingTimeout() {
|
|
750
|
+
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
751
|
+
let e = this._pingInterval + this._pingTimeout;
|
|
752
|
+
this._pingTimeoutTime = Date.now() + e, this._pingTimeoutTimer = this.setTimeoutFn(() => {
|
|
753
|
+
this._onClose("ping timeout");
|
|
754
|
+
}, e), this.opts.autoUnref && this._pingTimeoutTimer.unref();
|
|
755
|
+
}
|
|
756
|
+
_onDrain() {
|
|
757
|
+
this.writeBuffer.splice(0, this._prevBufferLen), this._prevBufferLen = 0, this.writeBuffer.length === 0 ? this.emitReserved("drain") : this.flush();
|
|
758
|
+
}
|
|
759
|
+
flush() {
|
|
760
|
+
if (this.readyState !== "closed" && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
|
|
761
|
+
let e = this._getWritablePackets();
|
|
762
|
+
this.transport.send(e), this._prevBufferLen = e.length, this.emitReserved("flush");
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
_getWritablePackets() {
|
|
766
|
+
if (!(this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1)) return this.writeBuffer;
|
|
767
|
+
let e = 1;
|
|
768
|
+
for (let t = 0; t < this.writeBuffer.length; t++) {
|
|
769
|
+
let n = this.writeBuffer[t].data;
|
|
770
|
+
if (n && (e += ve(n)), t > 0 && e > this._maxPayload) return this.writeBuffer.slice(0, t);
|
|
771
|
+
e += 2;
|
|
772
|
+
}
|
|
773
|
+
return this.writeBuffer;
|
|
774
|
+
}
|
|
775
|
+
_hasPingExpired() {
|
|
776
|
+
if (!this._pingTimeoutTime) return !0;
|
|
777
|
+
let e = Date.now() > this._pingTimeoutTime;
|
|
778
|
+
return e && (this._pingTimeoutTime = 0, C(() => {
|
|
779
|
+
this._onClose("ping timeout");
|
|
780
|
+
}, this.setTimeoutFn)), e;
|
|
781
|
+
}
|
|
782
|
+
write(e, t, n) {
|
|
783
|
+
return this._sendPacket("message", e, t, n), this;
|
|
784
|
+
}
|
|
785
|
+
send(e, t, n) {
|
|
786
|
+
return this._sendPacket("message", e, t, n), this;
|
|
787
|
+
}
|
|
788
|
+
_sendPacket(e, t, n, r) {
|
|
789
|
+
if (typeof t == "function" && (r = t, t = void 0), typeof n == "function" && (r = n, n = null), this.readyState === "closing" || this.readyState === "closed") return;
|
|
790
|
+
n ||= {}, n.compress = !1 !== n.compress;
|
|
791
|
+
let i = {
|
|
792
|
+
type: e,
|
|
793
|
+
data: t,
|
|
794
|
+
options: n
|
|
795
|
+
};
|
|
796
|
+
this.emitReserved("packetCreate", i), this.writeBuffer.push(i), r && this.once("flush", r), this.flush();
|
|
797
|
+
}
|
|
798
|
+
close() {
|
|
799
|
+
let e = () => {
|
|
800
|
+
this._onClose("forced close"), this.transport.close();
|
|
801
|
+
}, t = () => {
|
|
802
|
+
this.off("upgrade", t), this.off("upgradeError", t), e();
|
|
803
|
+
}, n = () => {
|
|
804
|
+
this.once("upgrade", t), this.once("upgradeError", t);
|
|
805
|
+
};
|
|
806
|
+
return (this.readyState === "opening" || this.readyState === "open") && (this.readyState = "closing", this.writeBuffer.length ? this.once("drain", () => {
|
|
807
|
+
this.upgrading ? n() : e();
|
|
808
|
+
}) : this.upgrading ? n() : e()), this;
|
|
809
|
+
}
|
|
810
|
+
_onError(t) {
|
|
811
|
+
if (e.priorWebsocketSuccess = !1, this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening") return this.transports.shift(), this._open();
|
|
812
|
+
this.emitReserved("error", t), this._onClose("transport error", t);
|
|
813
|
+
}
|
|
814
|
+
_onClose(e, t) {
|
|
815
|
+
if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
|
|
816
|
+
if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), j && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
|
|
817
|
+
let e = M.indexOf(this._offlineEventListener);
|
|
818
|
+
e !== -1 && M.splice(e, 1);
|
|
819
|
+
}
|
|
820
|
+
this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
N.protocol = 4;
|
|
825
|
+
var ze = class extends N {
|
|
826
|
+
constructor() {
|
|
827
|
+
super(...arguments), this._upgrades = [];
|
|
828
|
+
}
|
|
829
|
+
onOpen() {
|
|
830
|
+
if (super.onOpen(), this.readyState === "open" && this.opts.upgrade) for (let e = 0; e < this._upgrades.length; e++) this._probe(this._upgrades[e]);
|
|
831
|
+
}
|
|
832
|
+
_probe(e) {
|
|
833
|
+
let t = this.createTransport(e), n = !1;
|
|
834
|
+
N.priorWebsocketSuccess = !1;
|
|
835
|
+
let r = () => {
|
|
836
|
+
n || (t.send([{
|
|
837
|
+
type: "ping",
|
|
838
|
+
data: "probe"
|
|
839
|
+
}]), t.once("packet", (e) => {
|
|
840
|
+
if (!n) {
|
|
841
|
+
if (e.type === "pong" && e.data === "probe") {
|
|
842
|
+
if (this.upgrading = !0, this.emitReserved("upgrading", t), !t) return;
|
|
843
|
+
N.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
|
|
844
|
+
n || this.readyState !== "closed" && (l(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
|
|
845
|
+
});
|
|
846
|
+
} else {
|
|
847
|
+
let e = /* @__PURE__ */ Error("probe error");
|
|
848
|
+
e.transport = t.name, this.emitReserved("upgradeError", e);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}));
|
|
852
|
+
};
|
|
853
|
+
function i() {
|
|
854
|
+
n || (n = !0, l(), t.close(), t = null);
|
|
855
|
+
}
|
|
856
|
+
let a = (e) => {
|
|
857
|
+
let n = /* @__PURE__ */ Error("probe error: " + e);
|
|
858
|
+
n.transport = t.name, i(), this.emitReserved("upgradeError", n);
|
|
859
|
+
};
|
|
860
|
+
function o() {
|
|
861
|
+
a("transport closed");
|
|
862
|
+
}
|
|
863
|
+
function s() {
|
|
864
|
+
a("socket closed");
|
|
865
|
+
}
|
|
866
|
+
function c(e) {
|
|
867
|
+
t && e.name !== t.name && i();
|
|
868
|
+
}
|
|
869
|
+
let l = () => {
|
|
870
|
+
t.removeListener("open", r), t.removeListener("error", a), t.removeListener("close", o), this.off("close", s), this.off("upgrading", c);
|
|
871
|
+
};
|
|
872
|
+
t.once("open", r), t.once("error", a), t.once("close", o), this.once("close", s), this.once("upgrading", c), this._upgrades.indexOf("webtransport") !== -1 && e !== "webtransport" ? this.setTimeoutFn(() => {
|
|
873
|
+
n || t.open();
|
|
874
|
+
}, 200) : t.open();
|
|
875
|
+
}
|
|
876
|
+
onHandshake(e) {
|
|
877
|
+
this._upgrades = this._filterUpgrades(e.upgrades), super.onHandshake(e);
|
|
878
|
+
}
|
|
879
|
+
_filterUpgrades(e) {
|
|
880
|
+
let t = [];
|
|
881
|
+
for (let n = 0; n < e.length; n++) ~this.transports.indexOf(e[n]) && t.push(e[n]);
|
|
882
|
+
return t;
|
|
883
|
+
}
|
|
884
|
+
}, Be = class extends ze {
|
|
885
|
+
constructor(e, t = {}) {
|
|
886
|
+
let n = typeof e == "object", r = n ? { ...e } : { ...t };
|
|
887
|
+
(!r.transports || r.transports && typeof r.transports[0] == "string") && (r.transports = (r.transports || [
|
|
888
|
+
"polling",
|
|
889
|
+
"websocket",
|
|
890
|
+
"webtransport"
|
|
891
|
+
]).map((e) => Pe[e]).filter((e) => !!e)), super(n ? r : e, r);
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
Be.protocol;
|
|
895
|
+
//#endregion
|
|
896
|
+
//#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/url.js
|
|
897
|
+
function Ve(e, t = "", n) {
|
|
898
|
+
let r = e;
|
|
899
|
+
n ||= typeof location < "u" && location, e ??= n.protocol + "//" + n.host, typeof e == "string" && (e.charAt(0) === "/" && (e = e.charAt(1) === "/" ? n.protocol + e : n.host + e), /^(https?|wss?):\/\//.test(e) || (e = n === void 0 ? "https://" + e : n.protocol + "//" + e), r = A(e)), r.port || (/^(http|ws)$/.test(r.protocol) ? r.port = "80" : /^(http|ws)s$/.test(r.protocol) && (r.port = "443")), r.path = r.path || "/";
|
|
900
|
+
let i = r.host.indexOf(":") === -1 ? r.host : "[" + r.host + "]";
|
|
901
|
+
return r.id = r.protocol + "://" + i + ":" + r.port + t, r.href = r.protocol + "://" + i + (n && n.port === r.port ? "" : ":" + r.port), r;
|
|
902
|
+
}
|
|
903
|
+
//#endregion
|
|
904
|
+
//#region ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/is-binary.js
|
|
905
|
+
var He = typeof ArrayBuffer == "function", Ue = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e.buffer instanceof ArrayBuffer, P = Object.prototype.toString, We = typeof Blob == "function" || typeof Blob < "u" && P.call(Blob) === "[object BlobConstructor]", Ge = typeof File == "function" || typeof File < "u" && P.call(File) === "[object FileConstructor]";
|
|
906
|
+
function F(e) {
|
|
907
|
+
return He && (e instanceof ArrayBuffer || Ue(e)) || We && e instanceof Blob || Ge && e instanceof File;
|
|
908
|
+
}
|
|
909
|
+
function I(e, t) {
|
|
910
|
+
if (!e || typeof e != "object") return !1;
|
|
911
|
+
if (Array.isArray(e)) {
|
|
912
|
+
for (let t = 0, n = e.length; t < n; t++) if (I(e[t])) return !0;
|
|
913
|
+
return !1;
|
|
914
|
+
}
|
|
915
|
+
if (F(e)) return !0;
|
|
916
|
+
if (e.toJSON && typeof e.toJSON == "function" && arguments.length === 1) return I(e.toJSON(), !0);
|
|
917
|
+
for (let t in e) if (Object.prototype.hasOwnProperty.call(e, t) && I(e[t])) return !0;
|
|
918
|
+
return !1;
|
|
919
|
+
}
|
|
920
|
+
//#endregion
|
|
921
|
+
//#region ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/binary.js
|
|
922
|
+
function Ke(e) {
|
|
923
|
+
let t = [], n = e.data, r = e;
|
|
924
|
+
return r.data = L(n, t), r.attachments = t.length, {
|
|
925
|
+
packet: r,
|
|
926
|
+
buffers: t
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
function L(e, t, n) {
|
|
930
|
+
if (!e) return e;
|
|
931
|
+
if (F(e)) {
|
|
932
|
+
let n = {
|
|
933
|
+
_placeholder: !0,
|
|
934
|
+
num: t.length
|
|
935
|
+
};
|
|
936
|
+
return t.push(e), n;
|
|
937
|
+
}
|
|
938
|
+
if (Array.isArray(e)) {
|
|
939
|
+
let n = Array(e.length);
|
|
940
|
+
for (let r = 0; r < e.length; r++) n[r] = L(e[r], t);
|
|
941
|
+
return n;
|
|
942
|
+
}
|
|
943
|
+
if (typeof e == "object" && !(e instanceof Date)) {
|
|
944
|
+
if (e.toJSON && typeof e.toJSON == "function" && !n) return L(e.toJSON(), t, !0);
|
|
945
|
+
let r = {};
|
|
946
|
+
for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (r[n] = L(e[n], t));
|
|
947
|
+
return r;
|
|
948
|
+
}
|
|
949
|
+
return e;
|
|
950
|
+
}
|
|
951
|
+
function qe(e, t) {
|
|
952
|
+
return e.data = R(e.data, t), delete e.attachments, e;
|
|
953
|
+
}
|
|
954
|
+
function R(e, t) {
|
|
955
|
+
if (!e) return e;
|
|
956
|
+
if (e && e._placeholder === !0) {
|
|
957
|
+
if (typeof e.num == "number" && e.num >= 0 && e.num < t.length) return t[e.num];
|
|
958
|
+
throw Error("illegal attachments");
|
|
959
|
+
}
|
|
960
|
+
if (Array.isArray(e)) for (let n = 0; n < e.length; n++) e[n] = R(e[n], t);
|
|
961
|
+
else if (typeof e == "object") for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (e[n] = R(e[n], t));
|
|
962
|
+
return e;
|
|
963
|
+
}
|
|
964
|
+
//#endregion
|
|
965
|
+
//#region ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/index.js
|
|
966
|
+
var Je = /* @__PURE__ */ t({
|
|
967
|
+
Decoder: () => Xe,
|
|
968
|
+
Encoder: () => Ye,
|
|
969
|
+
PacketType: () => B,
|
|
970
|
+
isPacketValid: () => tt,
|
|
971
|
+
protocol: () => 5
|
|
972
|
+
}), z = [
|
|
973
|
+
"connect",
|
|
974
|
+
"connect_error",
|
|
975
|
+
"disconnect",
|
|
976
|
+
"disconnecting",
|
|
977
|
+
"newListener",
|
|
978
|
+
"removeListener"
|
|
979
|
+
], B;
|
|
980
|
+
(function(e) {
|
|
981
|
+
e[e.CONNECT = 0] = "CONNECT", e[e.DISCONNECT = 1] = "DISCONNECT", e[e.EVENT = 2] = "EVENT", e[e.ACK = 3] = "ACK", e[e.CONNECT_ERROR = 4] = "CONNECT_ERROR", e[e.BINARY_EVENT = 5] = "BINARY_EVENT", e[e.BINARY_ACK = 6] = "BINARY_ACK";
|
|
982
|
+
})(B ||= {});
|
|
983
|
+
var Ye = class {
|
|
984
|
+
constructor(e) {
|
|
985
|
+
this.replacer = e;
|
|
986
|
+
}
|
|
987
|
+
encode(e) {
|
|
988
|
+
return (e.type === B.EVENT || e.type === B.ACK) && I(e) ? this.encodeAsBinary({
|
|
989
|
+
type: e.type === B.EVENT ? B.BINARY_EVENT : B.BINARY_ACK,
|
|
990
|
+
nsp: e.nsp,
|
|
991
|
+
data: e.data,
|
|
992
|
+
id: e.id
|
|
993
|
+
}) : [this.encodeAsString(e)];
|
|
994
|
+
}
|
|
995
|
+
encodeAsString(e) {
|
|
996
|
+
let t = "" + e.type;
|
|
997
|
+
return (e.type === B.BINARY_EVENT || e.type === B.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;
|
|
998
|
+
}
|
|
999
|
+
encodeAsBinary(e) {
|
|
1000
|
+
let t = Ke(e), n = this.encodeAsString(t.packet), r = t.buffers;
|
|
1001
|
+
return r.unshift(n), r;
|
|
1002
|
+
}
|
|
1003
|
+
}, Xe = class e extends S {
|
|
1004
|
+
constructor(e) {
|
|
1005
|
+
super(), this.opts = Object.assign({
|
|
1006
|
+
reviver: void 0,
|
|
1007
|
+
maxAttachments: 10
|
|
1008
|
+
}, typeof e == "function" ? { reviver: e } : e);
|
|
1009
|
+
}
|
|
1010
|
+
add(e) {
|
|
1011
|
+
let t;
|
|
1012
|
+
if (typeof e == "string") {
|
|
1013
|
+
if (this.reconstructor) throw Error("got plaintext data when reconstructing a packet");
|
|
1014
|
+
t = this.decodeString(e);
|
|
1015
|
+
let n = t.type === B.BINARY_EVENT;
|
|
1016
|
+
n || t.type === B.BINARY_ACK ? (t.type = n ? B.EVENT : B.ACK, this.reconstructor = new Ze(t)) : super.emitReserved("decoded", t);
|
|
1017
|
+
} else if (F(e) || e.base64) {
|
|
1018
|
+
if (this.reconstructor) t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
|
|
1019
|
+
else throw Error("got binary data when not reconstructing a packet");
|
|
1020
|
+
} else throw Error("Unknown type: " + e);
|
|
1021
|
+
}
|
|
1022
|
+
decodeString(t) {
|
|
1023
|
+
let n = 0, r = { type: Number(t.charAt(0)) };
|
|
1024
|
+
if (B[r.type] === void 0) throw Error("unknown packet type " + r.type);
|
|
1025
|
+
if (r.type === B.BINARY_EVENT || r.type === B.BINARY_ACK) {
|
|
1026
|
+
let e = n + 1;
|
|
1027
|
+
for (; t.charAt(++n) !== "-" && n != t.length;);
|
|
1028
|
+
let i = t.substring(e, n);
|
|
1029
|
+
if (i != Number(i) || t.charAt(n) !== "-") throw Error("Illegal attachments");
|
|
1030
|
+
let a = Number(i);
|
|
1031
|
+
if (!V(a) || a < 1) throw Error("Illegal attachments");
|
|
1032
|
+
if (a > this.opts.maxAttachments) throw Error("too many attachments");
|
|
1033
|
+
r.attachments = a;
|
|
1034
|
+
}
|
|
1035
|
+
if (t.charAt(n + 1) === "/") {
|
|
1036
|
+
let e = n + 1;
|
|
1037
|
+
for (; ++n && t.charAt(n) !== "," && n !== t.length;);
|
|
1038
|
+
r.nsp = t.substring(e, n);
|
|
1039
|
+
} else r.nsp = "/";
|
|
1040
|
+
let i = t.charAt(n + 1);
|
|
1041
|
+
if (i !== "" && Number(i) == i) {
|
|
1042
|
+
let e = n + 1;
|
|
1043
|
+
for (; ++n;) {
|
|
1044
|
+
let e = t.charAt(n);
|
|
1045
|
+
if (e == null || Number(e) != e) {
|
|
1046
|
+
--n;
|
|
1047
|
+
break;
|
|
1048
|
+
}
|
|
1049
|
+
if (n === t.length) break;
|
|
1050
|
+
}
|
|
1051
|
+
r.id = Number(t.substring(e, n + 1));
|
|
1052
|
+
}
|
|
1053
|
+
if (t.charAt(++n)) {
|
|
1054
|
+
let i = this.tryParse(t.substr(n));
|
|
1055
|
+
if (e.isPayloadValid(r.type, i)) r.data = i;
|
|
1056
|
+
else throw Error("invalid payload");
|
|
1057
|
+
}
|
|
1058
|
+
return r;
|
|
1059
|
+
}
|
|
1060
|
+
tryParse(e) {
|
|
1061
|
+
try {
|
|
1062
|
+
return JSON.parse(e, this.opts.reviver);
|
|
1063
|
+
} catch {
|
|
1064
|
+
return !1;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
static isPayloadValid(e, t) {
|
|
1068
|
+
switch (e) {
|
|
1069
|
+
case B.CONNECT: return H(t);
|
|
1070
|
+
case B.DISCONNECT: return t === void 0;
|
|
1071
|
+
case B.CONNECT_ERROR: return typeof t == "string" || H(t);
|
|
1072
|
+
case B.EVENT:
|
|
1073
|
+
case B.BINARY_EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && z.indexOf(t[0]) === -1);
|
|
1074
|
+
case B.ACK:
|
|
1075
|
+
case B.BINARY_ACK: return Array.isArray(t);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
destroy() {
|
|
1079
|
+
this.reconstructor &&= (this.reconstructor.finishedReconstruction(), null);
|
|
1080
|
+
}
|
|
1081
|
+
}, Ze = class {
|
|
1082
|
+
constructor(e) {
|
|
1083
|
+
this.packet = e, this.buffers = [], this.reconPack = e;
|
|
1084
|
+
}
|
|
1085
|
+
takeBinaryData(e) {
|
|
1086
|
+
if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
|
|
1087
|
+
let e = qe(this.reconPack, this.buffers);
|
|
1088
|
+
return this.finishedReconstruction(), e;
|
|
1089
|
+
}
|
|
1090
|
+
return null;
|
|
1091
|
+
}
|
|
1092
|
+
finishedReconstruction() {
|
|
1093
|
+
this.reconPack = null, this.buffers = [];
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
function Qe(e) {
|
|
1097
|
+
return typeof e == "string";
|
|
1098
|
+
}
|
|
1099
|
+
var V = Number.isInteger || function(e) {
|
|
1100
|
+
return typeof e == "number" && isFinite(e) && Math.floor(e) === e;
|
|
1101
|
+
};
|
|
1102
|
+
function $e(e) {
|
|
1103
|
+
return e === void 0 || V(e);
|
|
1104
|
+
}
|
|
1105
|
+
function H(e) {
|
|
1106
|
+
return Object.prototype.toString.call(e) === "[object Object]";
|
|
1107
|
+
}
|
|
1108
|
+
function et(e, t) {
|
|
1109
|
+
switch (e) {
|
|
1110
|
+
case B.CONNECT: return t === void 0 || H(t);
|
|
1111
|
+
case B.DISCONNECT: return t === void 0;
|
|
1112
|
+
case B.EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && z.indexOf(t[0]) === -1);
|
|
1113
|
+
case B.ACK: return Array.isArray(t);
|
|
1114
|
+
case B.CONNECT_ERROR: return typeof t == "string" || H(t);
|
|
1115
|
+
default: return !1;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
function tt(e) {
|
|
1119
|
+
return Qe(e.nsp) && $e(e.id) && et(e.type, e.data);
|
|
1120
|
+
}
|
|
1121
|
+
//#endregion
|
|
1122
|
+
//#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/on.js
|
|
1123
|
+
function U(e, t, n) {
|
|
1124
|
+
return e.on(t, n), function() {
|
|
1125
|
+
e.off(t, n);
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
//#endregion
|
|
1129
|
+
//#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/socket.js
|
|
1130
|
+
var nt = Object.freeze({
|
|
1131
|
+
connect: 1,
|
|
1132
|
+
connect_error: 1,
|
|
1133
|
+
disconnect: 1,
|
|
1134
|
+
disconnecting: 1,
|
|
1135
|
+
newListener: 1,
|
|
1136
|
+
removeListener: 1
|
|
1137
|
+
}), rt = class extends S {
|
|
1138
|
+
constructor(e, t, n) {
|
|
1139
|
+
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();
|
|
1140
|
+
}
|
|
1141
|
+
get disconnected() {
|
|
1142
|
+
return !this.connected;
|
|
1143
|
+
}
|
|
1144
|
+
subEvents() {
|
|
1145
|
+
if (this.subs) return;
|
|
1146
|
+
let e = this.io;
|
|
1147
|
+
this.subs = [
|
|
1148
|
+
U(e, "open", this.onopen.bind(this)),
|
|
1149
|
+
U(e, "packet", this.onpacket.bind(this)),
|
|
1150
|
+
U(e, "error", this.onerror.bind(this)),
|
|
1151
|
+
U(e, "close", this.onclose.bind(this))
|
|
1152
|
+
];
|
|
1153
|
+
}
|
|
1154
|
+
get active() {
|
|
1155
|
+
return !!this.subs;
|
|
1156
|
+
}
|
|
1157
|
+
connect() {
|
|
1158
|
+
return this.connected || (this.subEvents(), this.io._reconnecting || this.io.open(), this.io._readyState === "open" && this.onopen()), this;
|
|
1159
|
+
}
|
|
1160
|
+
open() {
|
|
1161
|
+
return this.connect();
|
|
1162
|
+
}
|
|
1163
|
+
send(...e) {
|
|
1164
|
+
return e.unshift("message"), this.emit.apply(this, e), this;
|
|
1165
|
+
}
|
|
1166
|
+
emit(e, ...t) {
|
|
1167
|
+
if (nt.hasOwnProperty(e)) throw Error("\"" + e.toString() + "\" is a reserved event name");
|
|
1168
|
+
if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) return this._addToQueue(t), this;
|
|
1169
|
+
let n = {
|
|
1170
|
+
type: B.EVENT,
|
|
1171
|
+
data: t
|
|
1172
|
+
};
|
|
1173
|
+
if (n.options = {}, n.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
|
|
1174
|
+
let e = this.ids++, r = t.pop();
|
|
1175
|
+
this._registerAckCallback(e, r), n.id = e;
|
|
1176
|
+
}
|
|
1177
|
+
let r = this.io.engine?.transport?.writable, i = this.connected && !this.io.engine?._hasPingExpired();
|
|
1178
|
+
return this.flags.volatile && !r || (i ? (this.notifyOutgoingListeners(n), this.packet(n)) : this.sendBuffer.push(n)), this.flags = {}, this;
|
|
1179
|
+
}
|
|
1180
|
+
_registerAckCallback(e, t) {
|
|
1181
|
+
let n = this.flags.timeout ?? this._opts.ackTimeout;
|
|
1182
|
+
if (n === void 0) {
|
|
1183
|
+
this.acks[e] = t;
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
let r = this.io.setTimeoutFn(() => {
|
|
1187
|
+
delete this.acks[e];
|
|
1188
|
+
for (let t = 0; t < this.sendBuffer.length; t++) this.sendBuffer[t].id === e && this.sendBuffer.splice(t, 1);
|
|
1189
|
+
t.call(this, /* @__PURE__ */ Error("operation has timed out"));
|
|
1190
|
+
}, n), i = (...e) => {
|
|
1191
|
+
this.io.clearTimeoutFn(r), t.apply(this, e);
|
|
1192
|
+
};
|
|
1193
|
+
i.withError = !0, this.acks[e] = i;
|
|
1194
|
+
}
|
|
1195
|
+
emitWithAck(e, ...t) {
|
|
1196
|
+
return new Promise((n, r) => {
|
|
1197
|
+
let i = (e, t) => e ? r(e) : n(t);
|
|
1198
|
+
i.withError = !0, t.push(i), this.emit(e, ...t);
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
_addToQueue(e) {
|
|
1202
|
+
let t;
|
|
1203
|
+
typeof e[e.length - 1] == "function" && (t = e.pop());
|
|
1204
|
+
let n = {
|
|
1205
|
+
id: this._queueSeq++,
|
|
1206
|
+
tryCount: 0,
|
|
1207
|
+
pending: !1,
|
|
1208
|
+
args: e,
|
|
1209
|
+
flags: Object.assign({ fromQueue: !0 }, this.flags)
|
|
1210
|
+
};
|
|
1211
|
+
e.push((e, ...r) => (this._queue[0], e === null ? (this._queue.shift(), t && t(null, ...r)) : n.tryCount > this._opts.retries && (this._queue.shift(), t && t(e)), n.pending = !1, this._drainQueue())), this._queue.push(n), this._drainQueue();
|
|
1212
|
+
}
|
|
1213
|
+
_drainQueue(e = !1) {
|
|
1214
|
+
if (!this.connected || this._queue.length === 0) return;
|
|
1215
|
+
let t = this._queue[0];
|
|
1216
|
+
(!t.pending || e) && (t.pending = !0, t.tryCount++, this.flags = t.flags, this.emit.apply(this, t.args));
|
|
1217
|
+
}
|
|
1218
|
+
packet(e) {
|
|
1219
|
+
e.nsp = this.nsp, this.io._packet(e);
|
|
1220
|
+
}
|
|
1221
|
+
onopen() {
|
|
1222
|
+
typeof this.auth == "function" ? this.auth((e) => {
|
|
1223
|
+
this._sendConnectPacket(e);
|
|
1224
|
+
}) : this._sendConnectPacket(this.auth);
|
|
1225
|
+
}
|
|
1226
|
+
_sendConnectPacket(e) {
|
|
1227
|
+
this.packet({
|
|
1228
|
+
type: B.CONNECT,
|
|
1229
|
+
data: this._pid ? Object.assign({
|
|
1230
|
+
pid: this._pid,
|
|
1231
|
+
offset: this._lastOffset
|
|
1232
|
+
}, e) : e
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
onerror(e) {
|
|
1236
|
+
this.connected || this.emitReserved("connect_error", e);
|
|
1237
|
+
}
|
|
1238
|
+
onclose(e, t) {
|
|
1239
|
+
this.connected = !1, delete this.id, this.emitReserved("disconnect", e, t), this._clearAcks();
|
|
1240
|
+
}
|
|
1241
|
+
_clearAcks() {
|
|
1242
|
+
Object.keys(this.acks).forEach((e) => {
|
|
1243
|
+
if (!this.sendBuffer.some((t) => String(t.id) === e)) {
|
|
1244
|
+
let t = this.acks[e];
|
|
1245
|
+
delete this.acks[e], t.withError && t.call(this, /* @__PURE__ */ Error("socket has been disconnected"));
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
onpacket(e) {
|
|
1250
|
+
if (e.nsp === this.nsp) switch (e.type) {
|
|
1251
|
+
case B.CONNECT:
|
|
1252
|
+
e.data && e.data.sid ? this.onconnect(e.data.sid, e.data.pid) : this.emitReserved("connect_error", /* @__PURE__ */ 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/)"));
|
|
1253
|
+
break;
|
|
1254
|
+
case B.EVENT:
|
|
1255
|
+
case B.BINARY_EVENT:
|
|
1256
|
+
this.onevent(e);
|
|
1257
|
+
break;
|
|
1258
|
+
case B.ACK:
|
|
1259
|
+
case B.BINARY_ACK:
|
|
1260
|
+
this.onack(e);
|
|
1261
|
+
break;
|
|
1262
|
+
case B.DISCONNECT:
|
|
1263
|
+
this.ondisconnect();
|
|
1264
|
+
break;
|
|
1265
|
+
case B.CONNECT_ERROR:
|
|
1266
|
+
this.destroy();
|
|
1267
|
+
let t = Error(e.data.message);
|
|
1268
|
+
t.data = e.data.data, this.emitReserved("connect_error", t);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
onevent(e) {
|
|
1272
|
+
let t = e.data || [];
|
|
1273
|
+
e.id != null && t.push(this.ack(e.id)), this.connected ? this.emitEvent(t) : this.receiveBuffer.push(Object.freeze(t));
|
|
1274
|
+
}
|
|
1275
|
+
emitEvent(e) {
|
|
1276
|
+
if (this._anyListeners && this._anyListeners.length) {
|
|
1277
|
+
let t = this._anyListeners.slice();
|
|
1278
|
+
for (let n of t) n.apply(this, e);
|
|
1279
|
+
}
|
|
1280
|
+
super.emit.apply(this, e), this._pid && e.length && typeof e[e.length - 1] == "string" && (this._lastOffset = e[e.length - 1]);
|
|
1281
|
+
}
|
|
1282
|
+
ack(e) {
|
|
1283
|
+
let t = this, n = !1;
|
|
1284
|
+
return function(...r) {
|
|
1285
|
+
n || (n = !0, t.packet({
|
|
1286
|
+
type: B.ACK,
|
|
1287
|
+
id: e,
|
|
1288
|
+
data: r
|
|
1289
|
+
}));
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
onack(e) {
|
|
1293
|
+
let t = this.acks[e.id];
|
|
1294
|
+
typeof t == "function" && (delete this.acks[e.id], t.withError && e.data.unshift(null), t.apply(this, e.data));
|
|
1295
|
+
}
|
|
1296
|
+
onconnect(e, t) {
|
|
1297
|
+
this.id = e, this.recovered = t && this._pid === t, this._pid = t, this.connected = !0, this.emitBuffered(), this._drainQueue(!0), this.emitReserved("connect");
|
|
1298
|
+
}
|
|
1299
|
+
emitBuffered() {
|
|
1300
|
+
this.receiveBuffer.forEach((e) => this.emitEvent(e)), this.receiveBuffer = [], this.sendBuffer.forEach((e) => {
|
|
1301
|
+
this.notifyOutgoingListeners(e), this.packet(e);
|
|
1302
|
+
}), this.sendBuffer = [];
|
|
1303
|
+
}
|
|
1304
|
+
ondisconnect() {
|
|
1305
|
+
this.destroy(), this.onclose("io server disconnect");
|
|
1306
|
+
}
|
|
1307
|
+
destroy() {
|
|
1308
|
+
this.subs &&= (this.subs.forEach((e) => e()), void 0), this.io._destroy(this);
|
|
1309
|
+
}
|
|
1310
|
+
disconnect() {
|
|
1311
|
+
return this.connected && this.packet({ type: B.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
|
|
1312
|
+
}
|
|
1313
|
+
close() {
|
|
1314
|
+
return this.disconnect();
|
|
1315
|
+
}
|
|
1316
|
+
compress(e) {
|
|
1317
|
+
return this.flags.compress = e, this;
|
|
1318
|
+
}
|
|
1319
|
+
get volatile() {
|
|
1320
|
+
return this.flags.volatile = !0, this;
|
|
1321
|
+
}
|
|
1322
|
+
timeout(e) {
|
|
1323
|
+
return this.flags.timeout = e, this;
|
|
1324
|
+
}
|
|
1325
|
+
onAny(e) {
|
|
1326
|
+
return this._anyListeners = this._anyListeners || [], this._anyListeners.push(e), this;
|
|
1327
|
+
}
|
|
1328
|
+
prependAny(e) {
|
|
1329
|
+
return this._anyListeners = this._anyListeners || [], this._anyListeners.unshift(e), this;
|
|
1330
|
+
}
|
|
1331
|
+
offAny(e) {
|
|
1332
|
+
if (!this._anyListeners) return this;
|
|
1333
|
+
if (e) {
|
|
1334
|
+
let t = this._anyListeners;
|
|
1335
|
+
for (let n = 0; n < t.length; n++) if (e === t[n]) return t.splice(n, 1), this;
|
|
1336
|
+
} else this._anyListeners = [];
|
|
1337
|
+
return this;
|
|
1338
|
+
}
|
|
1339
|
+
listenersAny() {
|
|
1340
|
+
return this._anyListeners || [];
|
|
1341
|
+
}
|
|
1342
|
+
onAnyOutgoing(e) {
|
|
1343
|
+
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.push(e), this;
|
|
1344
|
+
}
|
|
1345
|
+
prependAnyOutgoing(e) {
|
|
1346
|
+
return this._anyOutgoingListeners = this._anyOutgoingListeners || [], this._anyOutgoingListeners.unshift(e), this;
|
|
1347
|
+
}
|
|
1348
|
+
offAnyOutgoing(e) {
|
|
1349
|
+
if (!this._anyOutgoingListeners) return this;
|
|
1350
|
+
if (e) {
|
|
1351
|
+
let t = this._anyOutgoingListeners;
|
|
1352
|
+
for (let n = 0; n < t.length; n++) if (e === t[n]) return t.splice(n, 1), this;
|
|
1353
|
+
} else this._anyOutgoingListeners = [];
|
|
1354
|
+
return this;
|
|
1355
|
+
}
|
|
1356
|
+
listenersAnyOutgoing() {
|
|
1357
|
+
return this._anyOutgoingListeners || [];
|
|
1358
|
+
}
|
|
1359
|
+
notifyOutgoingListeners(e) {
|
|
1360
|
+
if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
|
|
1361
|
+
let t = this._anyOutgoingListeners.slice();
|
|
1362
|
+
for (let n of t) n.apply(this, e.data);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
};
|
|
1366
|
+
//#endregion
|
|
1367
|
+
//#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/contrib/backo2.js
|
|
1368
|
+
function W(e) {
|
|
1369
|
+
e ||= {}, this.ms = e.min || 100, this.max = e.max || 1e4, this.factor = e.factor || 2, this.jitter = e.jitter > 0 && e.jitter <= 1 ? e.jitter : 0, this.attempts = 0;
|
|
1370
|
+
}
|
|
1371
|
+
W.prototype.duration = function() {
|
|
1372
|
+
var e = this.ms * this.factor ** +this.attempts++;
|
|
1373
|
+
if (this.jitter) {
|
|
1374
|
+
var t = Math.random(), n = Math.floor(t * this.jitter * e);
|
|
1375
|
+
e = Math.floor(t * 10) & 1 ? e + n : e - n;
|
|
1376
|
+
}
|
|
1377
|
+
return Math.min(e, this.max) | 0;
|
|
1378
|
+
}, W.prototype.reset = function() {
|
|
1379
|
+
this.attempts = 0;
|
|
1380
|
+
}, W.prototype.setMin = function(e) {
|
|
1381
|
+
this.ms = e;
|
|
1382
|
+
}, W.prototype.setMax = function(e) {
|
|
1383
|
+
this.max = e;
|
|
1384
|
+
}, W.prototype.setJitter = function(e) {
|
|
1385
|
+
this.jitter = e;
|
|
1386
|
+
};
|
|
1387
|
+
//#endregion
|
|
1388
|
+
//#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/manager.js
|
|
1389
|
+
var G = class extends S {
|
|
1390
|
+
constructor(e, t) {
|
|
1391
|
+
super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t ||= {}, t.path = t.path || "/socket.io", this.opts = t, T(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || Infinity), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor(t.randomizationFactor ?? .5), this.backoff = new W({
|
|
1392
|
+
min: this.reconnectionDelay(),
|
|
1393
|
+
max: this.reconnectionDelayMax(),
|
|
1394
|
+
jitter: this.randomizationFactor()
|
|
1395
|
+
}), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
|
|
1396
|
+
let n = t.parser || Je;
|
|
1397
|
+
this.encoder = new n.Encoder(), this.decoder = new n.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
|
|
1398
|
+
}
|
|
1399
|
+
reconnection(e) {
|
|
1400
|
+
return arguments.length ? (this._reconnection = !!e, e || (this.skipReconnect = !0), this) : this._reconnection;
|
|
1401
|
+
}
|
|
1402
|
+
reconnectionAttempts(e) {
|
|
1403
|
+
return e === void 0 ? this._reconnectionAttempts : (this._reconnectionAttempts = e, this);
|
|
1404
|
+
}
|
|
1405
|
+
reconnectionDelay(e) {
|
|
1406
|
+
var t;
|
|
1407
|
+
return e === void 0 ? this._reconnectionDelay : (this._reconnectionDelay = e, (t = this.backoff) == null || t.setMin(e), this);
|
|
1408
|
+
}
|
|
1409
|
+
randomizationFactor(e) {
|
|
1410
|
+
var t;
|
|
1411
|
+
return e === void 0 ? this._randomizationFactor : (this._randomizationFactor = e, (t = this.backoff) == null || t.setJitter(e), this);
|
|
1412
|
+
}
|
|
1413
|
+
reconnectionDelayMax(e) {
|
|
1414
|
+
var t;
|
|
1415
|
+
return e === void 0 ? this._reconnectionDelayMax : (this._reconnectionDelayMax = e, (t = this.backoff) == null || t.setMax(e), this);
|
|
1416
|
+
}
|
|
1417
|
+
timeout(e) {
|
|
1418
|
+
return arguments.length ? (this._timeout = e, this) : this._timeout;
|
|
1419
|
+
}
|
|
1420
|
+
maybeReconnectOnOpen() {
|
|
1421
|
+
!this._reconnecting && this._reconnection && this.backoff.attempts === 0 && this.reconnect();
|
|
1422
|
+
}
|
|
1423
|
+
open(e) {
|
|
1424
|
+
if (~this._readyState.indexOf("open")) return this;
|
|
1425
|
+
this.engine = new Be(this.uri, this.opts);
|
|
1426
|
+
let t = this.engine, n = this;
|
|
1427
|
+
this._readyState = "opening", this.skipReconnect = !1;
|
|
1428
|
+
let r = U(t, "open", function() {
|
|
1429
|
+
n.onopen(), e && e();
|
|
1430
|
+
}), i = (t) => {
|
|
1431
|
+
this.cleanup(), this._readyState = "closed", this.emitReserved("error", t), e ? e(t) : this.maybeReconnectOnOpen();
|
|
1432
|
+
}, a = U(t, "error", i);
|
|
1433
|
+
if (!1 !== this._timeout) {
|
|
1434
|
+
let e = this._timeout, n = this.setTimeoutFn(() => {
|
|
1435
|
+
r(), i(/* @__PURE__ */ Error("timeout")), t.close();
|
|
1436
|
+
}, e);
|
|
1437
|
+
this.opts.autoUnref && n.unref(), this.subs.push(() => {
|
|
1438
|
+
this.clearTimeoutFn(n);
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
return this.subs.push(r), this.subs.push(a), this;
|
|
1442
|
+
}
|
|
1443
|
+
connect(e) {
|
|
1444
|
+
return this.open(e);
|
|
1445
|
+
}
|
|
1446
|
+
onopen() {
|
|
1447
|
+
this.cleanup(), this._readyState = "open", this.emitReserved("open");
|
|
1448
|
+
let e = this.engine;
|
|
1449
|
+
this.subs.push(U(e, "ping", this.onping.bind(this)), U(e, "data", this.ondata.bind(this)), U(e, "error", this.onerror.bind(this)), U(e, "close", this.onclose.bind(this)), U(this.decoder, "decoded", this.ondecoded.bind(this)));
|
|
1450
|
+
}
|
|
1451
|
+
onping() {
|
|
1452
|
+
this.emitReserved("ping");
|
|
1453
|
+
}
|
|
1454
|
+
ondata(e) {
|
|
1455
|
+
try {
|
|
1456
|
+
this.decoder.add(e);
|
|
1457
|
+
} catch (e) {
|
|
1458
|
+
this.onclose("parse error", e);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
ondecoded(e) {
|
|
1462
|
+
C(() => {
|
|
1463
|
+
this.emitReserved("packet", e);
|
|
1464
|
+
}, this.setTimeoutFn);
|
|
1465
|
+
}
|
|
1466
|
+
onerror(e) {
|
|
1467
|
+
this.emitReserved("error", e);
|
|
1468
|
+
}
|
|
1469
|
+
socket(e, t) {
|
|
1470
|
+
let n = this.nsps[e];
|
|
1471
|
+
return n ? this._autoConnect && !n.active && n.connect() : (n = new rt(this, e, t), this.nsps[e] = n), n;
|
|
1472
|
+
}
|
|
1473
|
+
_destroy(e) {
|
|
1474
|
+
let t = Object.keys(this.nsps);
|
|
1475
|
+
for (let e of t) if (this.nsps[e].active) return;
|
|
1476
|
+
this._close();
|
|
1477
|
+
}
|
|
1478
|
+
_packet(e) {
|
|
1479
|
+
let t = this.encoder.encode(e);
|
|
1480
|
+
for (let n = 0; n < t.length; n++) this.engine.write(t[n], e.options);
|
|
1481
|
+
}
|
|
1482
|
+
cleanup() {
|
|
1483
|
+
this.subs.forEach((e) => e()), this.subs.length = 0, this.decoder.destroy();
|
|
1484
|
+
}
|
|
1485
|
+
_close() {
|
|
1486
|
+
this.skipReconnect = !0, this._reconnecting = !1, this.onclose("forced close");
|
|
1487
|
+
}
|
|
1488
|
+
disconnect() {
|
|
1489
|
+
return this._close();
|
|
1490
|
+
}
|
|
1491
|
+
onclose(e, t) {
|
|
1492
|
+
var n;
|
|
1493
|
+
this.cleanup(), (n = this.engine) == null || n.close(), this.backoff.reset(), this._readyState = "closed", this.emitReserved("close", e, t), this._reconnection && !this.skipReconnect && this.reconnect();
|
|
1494
|
+
}
|
|
1495
|
+
reconnect() {
|
|
1496
|
+
if (this._reconnecting || this.skipReconnect) return this;
|
|
1497
|
+
let e = this;
|
|
1498
|
+
if (this.backoff.attempts >= this._reconnectionAttempts) this.backoff.reset(), this.emitReserved("reconnect_failed"), this._reconnecting = !1;
|
|
1499
|
+
else {
|
|
1500
|
+
let t = this.backoff.duration();
|
|
1501
|
+
this._reconnecting = !0;
|
|
1502
|
+
let n = this.setTimeoutFn(() => {
|
|
1503
|
+
e.skipReconnect || (this.emitReserved("reconnect_attempt", e.backoff.attempts), !e.skipReconnect && e.open((t) => {
|
|
1504
|
+
t ? (e._reconnecting = !1, e.reconnect(), this.emitReserved("reconnect_error", t)) : e.onreconnect();
|
|
1505
|
+
}));
|
|
1506
|
+
}, t);
|
|
1507
|
+
this.opts.autoUnref && n.unref(), this.subs.push(() => {
|
|
1508
|
+
this.clearTimeoutFn(n);
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
onreconnect() {
|
|
1513
|
+
let e = this.backoff.attempts;
|
|
1514
|
+
this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
|
|
1515
|
+
}
|
|
1516
|
+
}, K = {};
|
|
1517
|
+
function q(e, t) {
|
|
1518
|
+
typeof e == "object" && (t = e, e = void 0), t ||= {};
|
|
1519
|
+
let n = Ve(e, t.path || "/socket.io"), r = n.source, i = n.id, a = n.path, o = K[i] && a in K[i].nsps, s = t.forceNew || t["force new connection"] || !1 === t.multiplex || o, c;
|
|
1520
|
+
return s ? c = new G(r, t) : (K[i] || (K[i] = new G(r, t)), c = K[i]), n.query && !t.query && (t.query = n.queryKey), c.socket(n.path, t);
|
|
1521
|
+
}
|
|
1522
|
+
Object.assign(q, {
|
|
1523
|
+
Manager: G,
|
|
1524
|
+
Socket: rt,
|
|
1525
|
+
io: q,
|
|
1526
|
+
connect: q
|
|
1527
|
+
});
|
|
1528
|
+
//#endregion
|
|
1529
|
+
//#region src/sdk-socket.ts
|
|
1530
|
+
function it(e) {
|
|
1531
|
+
let t = e.replace(/\/$/, "");
|
|
1532
|
+
try {
|
|
1533
|
+
return `${new URL(t).origin}/sdk`;
|
|
1534
|
+
} catch {
|
|
1535
|
+
return `${t}/sdk`;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
var at = class {
|
|
1539
|
+
constructor() {
|
|
1540
|
+
this.socket = null;
|
|
1541
|
+
}
|
|
1542
|
+
get connected() {
|
|
1543
|
+
return this.socket?.connected ?? !1;
|
|
1544
|
+
}
|
|
1545
|
+
connect(e) {
|
|
1546
|
+
this.disconnect();
|
|
1547
|
+
let t = it(e.baseUrl);
|
|
1548
|
+
this.socket = q(t, {
|
|
1549
|
+
auth: {
|
|
1550
|
+
apiKey: e.apiKey,
|
|
1551
|
+
visitorToken: e.visitorToken
|
|
1552
|
+
},
|
|
1553
|
+
transports: ["websocket", "polling"],
|
|
1554
|
+
autoConnect: !0,
|
|
1555
|
+
reconnection: !0
|
|
1556
|
+
});
|
|
1557
|
+
let n = !1;
|
|
1558
|
+
this.socket.on("connect", () => {
|
|
1559
|
+
n ? e.onReconnect?.() : n = !0;
|
|
1560
|
+
}), this.socket.on("ticket:status", (t) => {
|
|
1561
|
+
e.onTicketStatus?.(t);
|
|
1562
|
+
}), this.socket.on("message:receive", (t) => {
|
|
1563
|
+
e.onMessageReceive?.(t);
|
|
1564
|
+
}), this.socket.on("connect_error", (t) => {
|
|
1565
|
+
e.onConnectError?.(t);
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
disconnect() {
|
|
1569
|
+
this.socket &&= (this.socket.removeAllListeners(), this.socket.disconnect(), null);
|
|
1570
|
+
}
|
|
1571
|
+
}, J = "onedeskpro_visitor_token";
|
|
1572
|
+
function ot(e) {
|
|
1573
|
+
try {
|
|
1574
|
+
return typeof window < "u" ? window.localStorage.getItem(e) : null;
|
|
1575
|
+
} catch {
|
|
1576
|
+
return null;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
function st(e, t) {
|
|
1580
|
+
try {
|
|
1581
|
+
typeof window < "u" && window.localStorage.setItem(e, t);
|
|
1582
|
+
} catch {}
|
|
1583
|
+
}
|
|
1584
|
+
function ct(e) {
|
|
1585
|
+
try {
|
|
1586
|
+
typeof window < "u" && window.localStorage.removeItem(e);
|
|
1587
|
+
} catch {}
|
|
1588
|
+
}
|
|
1589
|
+
var lt = class {
|
|
1590
|
+
constructor() {
|
|
1591
|
+
this.token = null, this.storageKey = J;
|
|
1592
|
+
}
|
|
1593
|
+
setScope(e) {
|
|
1594
|
+
this.storageKey = e?.trim() ? `${J}:${e.trim()}` : J, this.token = ot(this.storageKey);
|
|
1595
|
+
}
|
|
1596
|
+
get() {
|
|
1597
|
+
return this.token ?? ot(this.storageKey);
|
|
1598
|
+
}
|
|
1599
|
+
set(e) {
|
|
1600
|
+
this.token = e, st(this.storageKey, e);
|
|
1601
|
+
}
|
|
1602
|
+
clear() {
|
|
1603
|
+
this.token = null, ct(this.storageKey);
|
|
1604
|
+
}
|
|
1605
|
+
}, Y = [
|
|
1606
|
+
{
|
|
1607
|
+
iso: "BD",
|
|
1608
|
+
name: "Bangladesh",
|
|
1609
|
+
dial: "880",
|
|
1610
|
+
flag: "🇧🇩"
|
|
1611
|
+
},
|
|
1612
|
+
{
|
|
1613
|
+
iso: "US",
|
|
1614
|
+
name: "United States",
|
|
1615
|
+
dial: "1",
|
|
1616
|
+
flag: "🇺🇸"
|
|
1617
|
+
},
|
|
1618
|
+
{
|
|
1619
|
+
iso: "GB",
|
|
1620
|
+
name: "United Kingdom",
|
|
1621
|
+
dial: "44",
|
|
1622
|
+
flag: "🇬🇧"
|
|
1623
|
+
},
|
|
1624
|
+
{
|
|
1625
|
+
iso: "IN",
|
|
1626
|
+
name: "India",
|
|
1627
|
+
dial: "91",
|
|
1628
|
+
flag: "🇮🇳"
|
|
1629
|
+
},
|
|
1630
|
+
{
|
|
1631
|
+
iso: "PK",
|
|
1632
|
+
name: "Pakistan",
|
|
1633
|
+
dial: "92",
|
|
1634
|
+
flag: "🇵🇰"
|
|
1635
|
+
},
|
|
1636
|
+
{
|
|
1637
|
+
iso: "AE",
|
|
1638
|
+
name: "United Arab Emirates",
|
|
1639
|
+
dial: "971",
|
|
1640
|
+
flag: "🇦🇪"
|
|
1641
|
+
},
|
|
1642
|
+
{
|
|
1643
|
+
iso: "SA",
|
|
1644
|
+
name: "Saudi Arabia",
|
|
1645
|
+
dial: "966",
|
|
1646
|
+
flag: "🇸🇦"
|
|
1647
|
+
},
|
|
1648
|
+
{
|
|
1649
|
+
iso: "CA",
|
|
1650
|
+
name: "Canada",
|
|
1651
|
+
dial: "1",
|
|
1652
|
+
flag: "🇨🇦"
|
|
1653
|
+
},
|
|
1654
|
+
{
|
|
1655
|
+
iso: "AU",
|
|
1656
|
+
name: "Australia",
|
|
1657
|
+
dial: "61",
|
|
1658
|
+
flag: "🇦🇺"
|
|
1659
|
+
},
|
|
1660
|
+
{
|
|
1661
|
+
iso: "DE",
|
|
1662
|
+
name: "Germany",
|
|
1663
|
+
dial: "49",
|
|
1664
|
+
flag: "🇩🇪"
|
|
1665
|
+
},
|
|
1666
|
+
{
|
|
1667
|
+
iso: "FR",
|
|
1668
|
+
name: "France",
|
|
1669
|
+
dial: "33",
|
|
1670
|
+
flag: "🇫🇷"
|
|
1671
|
+
},
|
|
1672
|
+
{
|
|
1673
|
+
iso: "IT",
|
|
1674
|
+
name: "Italy",
|
|
1675
|
+
dial: "39",
|
|
1676
|
+
flag: "🇮🇹"
|
|
1677
|
+
},
|
|
1678
|
+
{
|
|
1679
|
+
iso: "ES",
|
|
1680
|
+
name: "Spain",
|
|
1681
|
+
dial: "34",
|
|
1682
|
+
flag: "🇪🇸"
|
|
1683
|
+
},
|
|
1684
|
+
{
|
|
1685
|
+
iso: "NL",
|
|
1686
|
+
name: "Netherlands",
|
|
1687
|
+
dial: "31",
|
|
1688
|
+
flag: "🇳🇱"
|
|
1689
|
+
},
|
|
1690
|
+
{
|
|
1691
|
+
iso: "SE",
|
|
1692
|
+
name: "Sweden",
|
|
1693
|
+
dial: "46",
|
|
1694
|
+
flag: "🇸🇪"
|
|
1695
|
+
},
|
|
1696
|
+
{
|
|
1697
|
+
iso: "NO",
|
|
1698
|
+
name: "Norway",
|
|
1699
|
+
dial: "47",
|
|
1700
|
+
flag: "🇳🇴"
|
|
1701
|
+
},
|
|
1702
|
+
{
|
|
1703
|
+
iso: "DK",
|
|
1704
|
+
name: "Denmark",
|
|
1705
|
+
dial: "45",
|
|
1706
|
+
flag: "🇩🇰"
|
|
1707
|
+
},
|
|
1708
|
+
{
|
|
1709
|
+
iso: "FI",
|
|
1710
|
+
name: "Finland",
|
|
1711
|
+
dial: "358",
|
|
1712
|
+
flag: "🇫🇮"
|
|
1713
|
+
},
|
|
1714
|
+
{
|
|
1715
|
+
iso: "IE",
|
|
1716
|
+
name: "Ireland",
|
|
1717
|
+
dial: "353",
|
|
1718
|
+
flag: "🇮🇪"
|
|
1719
|
+
},
|
|
1720
|
+
{
|
|
1721
|
+
iso: "CH",
|
|
1722
|
+
name: "Switzerland",
|
|
1723
|
+
dial: "41",
|
|
1724
|
+
flag: "🇨🇭"
|
|
1725
|
+
},
|
|
1726
|
+
{
|
|
1727
|
+
iso: "AT",
|
|
1728
|
+
name: "Austria",
|
|
1729
|
+
dial: "43",
|
|
1730
|
+
flag: "🇦🇹"
|
|
1731
|
+
},
|
|
1732
|
+
{
|
|
1733
|
+
iso: "BE",
|
|
1734
|
+
name: "Belgium",
|
|
1735
|
+
dial: "32",
|
|
1736
|
+
flag: "🇧🇪"
|
|
1737
|
+
},
|
|
1738
|
+
{
|
|
1739
|
+
iso: "PT",
|
|
1740
|
+
name: "Portugal",
|
|
1741
|
+
dial: "351",
|
|
1742
|
+
flag: "🇵🇹"
|
|
1743
|
+
},
|
|
1744
|
+
{
|
|
1745
|
+
iso: "PL",
|
|
1746
|
+
name: "Poland",
|
|
1747
|
+
dial: "48",
|
|
1748
|
+
flag: "🇵🇱"
|
|
1749
|
+
},
|
|
1750
|
+
{
|
|
1751
|
+
iso: "CZ",
|
|
1752
|
+
name: "Czechia",
|
|
1753
|
+
dial: "420",
|
|
1754
|
+
flag: "🇨🇿"
|
|
1755
|
+
},
|
|
1756
|
+
{
|
|
1757
|
+
iso: "RO",
|
|
1758
|
+
name: "Romania",
|
|
1759
|
+
dial: "40",
|
|
1760
|
+
flag: "🇷🇴"
|
|
1761
|
+
},
|
|
1762
|
+
{
|
|
1763
|
+
iso: "HU",
|
|
1764
|
+
name: "Hungary",
|
|
1765
|
+
dial: "36",
|
|
1766
|
+
flag: "🇭🇺"
|
|
1767
|
+
},
|
|
1768
|
+
{
|
|
1769
|
+
iso: "GR",
|
|
1770
|
+
name: "Greece",
|
|
1771
|
+
dial: "30",
|
|
1772
|
+
flag: "🇬🇷"
|
|
1773
|
+
},
|
|
1774
|
+
{
|
|
1775
|
+
iso: "TR",
|
|
1776
|
+
name: "Turkey",
|
|
1777
|
+
dial: "90",
|
|
1778
|
+
flag: "🇹🇷"
|
|
1779
|
+
},
|
|
1780
|
+
{
|
|
1781
|
+
iso: "RU",
|
|
1782
|
+
name: "Russia",
|
|
1783
|
+
dial: "7",
|
|
1784
|
+
flag: "🇷🇺"
|
|
1785
|
+
},
|
|
1786
|
+
{
|
|
1787
|
+
iso: "UA",
|
|
1788
|
+
name: "Ukraine",
|
|
1789
|
+
dial: "380",
|
|
1790
|
+
flag: "🇺🇦"
|
|
1791
|
+
},
|
|
1792
|
+
{
|
|
1793
|
+
iso: "CN",
|
|
1794
|
+
name: "China",
|
|
1795
|
+
dial: "86",
|
|
1796
|
+
flag: "🇨🇳"
|
|
1797
|
+
},
|
|
1798
|
+
{
|
|
1799
|
+
iso: "JP",
|
|
1800
|
+
name: "Japan",
|
|
1801
|
+
dial: "81",
|
|
1802
|
+
flag: "🇯🇵"
|
|
1803
|
+
},
|
|
1804
|
+
{
|
|
1805
|
+
iso: "KR",
|
|
1806
|
+
name: "South Korea",
|
|
1807
|
+
dial: "82",
|
|
1808
|
+
flag: "🇰🇷"
|
|
1809
|
+
},
|
|
1810
|
+
{
|
|
1811
|
+
iso: "SG",
|
|
1812
|
+
name: "Singapore",
|
|
1813
|
+
dial: "65",
|
|
1814
|
+
flag: "🇸🇬"
|
|
1815
|
+
},
|
|
1816
|
+
{
|
|
1817
|
+
iso: "MY",
|
|
1818
|
+
name: "Malaysia",
|
|
1819
|
+
dial: "60",
|
|
1820
|
+
flag: "🇲🇾"
|
|
1821
|
+
},
|
|
1822
|
+
{
|
|
1823
|
+
iso: "ID",
|
|
1824
|
+
name: "Indonesia",
|
|
1825
|
+
dial: "62",
|
|
1826
|
+
flag: "🇮🇩"
|
|
1827
|
+
},
|
|
1828
|
+
{
|
|
1829
|
+
iso: "TH",
|
|
1830
|
+
name: "Thailand",
|
|
1831
|
+
dial: "66",
|
|
1832
|
+
flag: "🇹🇭"
|
|
1833
|
+
},
|
|
1834
|
+
{
|
|
1835
|
+
iso: "VN",
|
|
1836
|
+
name: "Vietnam",
|
|
1837
|
+
dial: "84",
|
|
1838
|
+
flag: "🇻🇳"
|
|
1839
|
+
},
|
|
1840
|
+
{
|
|
1841
|
+
iso: "PH",
|
|
1842
|
+
name: "Philippines",
|
|
1843
|
+
dial: "63",
|
|
1844
|
+
flag: "🇵🇭"
|
|
1845
|
+
},
|
|
1846
|
+
{
|
|
1847
|
+
iso: "HK",
|
|
1848
|
+
name: "Hong Kong",
|
|
1849
|
+
dial: "852",
|
|
1850
|
+
flag: "🇭🇰"
|
|
1851
|
+
},
|
|
1852
|
+
{
|
|
1853
|
+
iso: "TW",
|
|
1854
|
+
name: "Taiwan",
|
|
1855
|
+
dial: "886",
|
|
1856
|
+
flag: "🇹🇼"
|
|
1857
|
+
},
|
|
1858
|
+
{
|
|
1859
|
+
iso: "NZ",
|
|
1860
|
+
name: "New Zealand",
|
|
1861
|
+
dial: "64",
|
|
1862
|
+
flag: "🇳🇿"
|
|
1863
|
+
},
|
|
1864
|
+
{
|
|
1865
|
+
iso: "ZA",
|
|
1866
|
+
name: "South Africa",
|
|
1867
|
+
dial: "27",
|
|
1868
|
+
flag: "🇿🇦"
|
|
1869
|
+
},
|
|
1870
|
+
{
|
|
1871
|
+
iso: "NG",
|
|
1872
|
+
name: "Nigeria",
|
|
1873
|
+
dial: "234",
|
|
1874
|
+
flag: "🇳🇬"
|
|
1875
|
+
},
|
|
1876
|
+
{
|
|
1877
|
+
iso: "KE",
|
|
1878
|
+
name: "Kenya",
|
|
1879
|
+
dial: "254",
|
|
1880
|
+
flag: "🇰🇪"
|
|
1881
|
+
},
|
|
1882
|
+
{
|
|
1883
|
+
iso: "EG",
|
|
1884
|
+
name: "Egypt",
|
|
1885
|
+
dial: "20",
|
|
1886
|
+
flag: "🇪🇬"
|
|
1887
|
+
},
|
|
1888
|
+
{
|
|
1889
|
+
iso: "MA",
|
|
1890
|
+
name: "Morocco",
|
|
1891
|
+
dial: "212",
|
|
1892
|
+
flag: "🇲🇦"
|
|
1893
|
+
},
|
|
1894
|
+
{
|
|
1895
|
+
iso: "BR",
|
|
1896
|
+
name: "Brazil",
|
|
1897
|
+
dial: "55",
|
|
1898
|
+
flag: "🇧🇷"
|
|
1899
|
+
},
|
|
1900
|
+
{
|
|
1901
|
+
iso: "MX",
|
|
1902
|
+
name: "Mexico",
|
|
1903
|
+
dial: "52",
|
|
1904
|
+
flag: "🇲🇽"
|
|
1905
|
+
},
|
|
1906
|
+
{
|
|
1907
|
+
iso: "AR",
|
|
1908
|
+
name: "Argentina",
|
|
1909
|
+
dial: "54",
|
|
1910
|
+
flag: "🇦🇷"
|
|
1911
|
+
},
|
|
1912
|
+
{
|
|
1913
|
+
iso: "CL",
|
|
1914
|
+
name: "Chile",
|
|
1915
|
+
dial: "56",
|
|
1916
|
+
flag: "🇨🇱"
|
|
1917
|
+
},
|
|
1918
|
+
{
|
|
1919
|
+
iso: "CO",
|
|
1920
|
+
name: "Colombia",
|
|
1921
|
+
dial: "57",
|
|
1922
|
+
flag: "🇨🇴"
|
|
1923
|
+
},
|
|
1924
|
+
{
|
|
1925
|
+
iso: "PE",
|
|
1926
|
+
name: "Peru",
|
|
1927
|
+
dial: "51",
|
|
1928
|
+
flag: "🇵🇪"
|
|
1929
|
+
},
|
|
1930
|
+
{
|
|
1931
|
+
iso: "IL",
|
|
1932
|
+
name: "Israel",
|
|
1933
|
+
dial: "972",
|
|
1934
|
+
flag: "🇮🇱"
|
|
1935
|
+
},
|
|
1936
|
+
{
|
|
1937
|
+
iso: "QA",
|
|
1938
|
+
name: "Qatar",
|
|
1939
|
+
dial: "974",
|
|
1940
|
+
flag: "🇶🇦"
|
|
1941
|
+
},
|
|
1942
|
+
{
|
|
1943
|
+
iso: "KW",
|
|
1944
|
+
name: "Kuwait",
|
|
1945
|
+
dial: "965",
|
|
1946
|
+
flag: "🇰🇼"
|
|
1947
|
+
},
|
|
1948
|
+
{
|
|
1949
|
+
iso: "BH",
|
|
1950
|
+
name: "Bahrain",
|
|
1951
|
+
dial: "973",
|
|
1952
|
+
flag: "🇧🇭"
|
|
1953
|
+
},
|
|
1954
|
+
{
|
|
1955
|
+
iso: "OM",
|
|
1956
|
+
name: "Oman",
|
|
1957
|
+
dial: "968",
|
|
1958
|
+
flag: "🇴🇲"
|
|
1959
|
+
},
|
|
1960
|
+
{
|
|
1961
|
+
iso: "LK",
|
|
1962
|
+
name: "Sri Lanka",
|
|
1963
|
+
dial: "94",
|
|
1964
|
+
flag: "🇱🇰"
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
iso: "NP",
|
|
1968
|
+
name: "Nepal",
|
|
1969
|
+
dial: "977",
|
|
1970
|
+
flag: "🇳🇵"
|
|
1971
|
+
}
|
|
1972
|
+
], ut = Y.find((e) => e.iso === "BD") ?? Y[0];
|
|
1973
|
+
function dt(e, t) {
|
|
1974
|
+
let n = t.trim();
|
|
1975
|
+
if (n.startsWith("+")) {
|
|
1976
|
+
let e = n.replace(/\D/g, "");
|
|
1977
|
+
return e ? `+${e}` : "";
|
|
1978
|
+
}
|
|
1979
|
+
let r = n.replace(/\D/g, "");
|
|
1980
|
+
return !r || (r = r.replace(/^0+/, ""), !r) ? "" : `+${e}${r}`;
|
|
1981
|
+
}
|
|
1982
|
+
//#endregion
|
|
1983
|
+
//#region src/widget/styles.ts
|
|
1984
|
+
function ft(e, t) {
|
|
1985
|
+
let n = `
|
|
145
1986
|
--ttcb-bg: #ffffff;
|
|
146
1987
|
--ttcb-bg-secondary: #f3f4f6;
|
|
147
1988
|
--ttcb-text: #111827;
|
|
148
1989
|
--ttcb-text-muted: #6b7280;
|
|
149
1990
|
--ttcb-border: #e5e7eb;
|
|
150
|
-
--ttcb-user-bubble: ${
|
|
1991
|
+
--ttcb-user-bubble: ${e};
|
|
151
1992
|
--ttcb-user-text: #ffffff;
|
|
152
1993
|
--ttcb-ai-bubble: #f3f4f6;
|
|
153
1994
|
--ttcb-ai-text: #111827;
|
|
154
1995
|
--ttcb-input-bg: #ffffff;
|
|
155
1996
|
--ttcb-shadow: 0 20px 60px rgba(0,0,0,0.15);
|
|
156
|
-
|
|
1997
|
+
--ttcb-online: #22c55e;
|
|
1998
|
+
--ttcb-hint: #9ca3af;
|
|
1999
|
+
`, r = `
|
|
157
2000
|
--ttcb-bg: #1f2937;
|
|
158
2001
|
--ttcb-bg-secondary: #111827;
|
|
159
2002
|
--ttcb-text: #f9fafb;
|
|
160
2003
|
--ttcb-text-muted: #9ca3af;
|
|
161
2004
|
--ttcb-border: #374151;
|
|
162
|
-
--ttcb-user-bubble: ${
|
|
2005
|
+
--ttcb-user-bubble: ${e};
|
|
163
2006
|
--ttcb-user-text: #ffffff;
|
|
164
2007
|
--ttcb-ai-bubble: #374151;
|
|
165
2008
|
--ttcb-ai-text: #f9fafb;
|
|
166
2009
|
--ttcb-input-bg: #111827;
|
|
167
2010
|
--ttcb-shadow: 0 20px 60px rgba(0,0,0,0.4);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
2011
|
+
--ttcb-online: #22c55e;
|
|
2012
|
+
--ttcb-hint: #9ca3af;
|
|
2013
|
+
`, i;
|
|
2014
|
+
return i = t === "dark" ? `:host { ${r} }` : t === "light" ? `:host { ${n} }` : `
|
|
2015
|
+
:host { ${n} }
|
|
2016
|
+
@media (prefers-color-scheme: dark) { :host { ${r} } }
|
|
173
2017
|
`, `
|
|
174
|
-
${
|
|
2018
|
+
${i}
|
|
175
2019
|
|
|
176
2020
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
177
2021
|
|
|
@@ -179,7 +2023,7 @@ function I(i, t) {
|
|
|
179
2023
|
position: fixed;
|
|
180
2024
|
width: 56px; height: 56px;
|
|
181
2025
|
border-radius: 50%;
|
|
182
|
-
background: ${
|
|
2026
|
+
background: ${e};
|
|
183
2027
|
border: none; cursor: pointer;
|
|
184
2028
|
display: flex; align-items: center; justify-content: center;
|
|
185
2029
|
box-shadow: 0 4px 20px rgba(0,0,0,0.2);
|
|
@@ -193,7 +2037,7 @@ function I(i, t) {
|
|
|
193
2037
|
|
|
194
2038
|
.ttcb-panel {
|
|
195
2039
|
position: fixed;
|
|
196
|
-
width: 380px;
|
|
2040
|
+
width: 380px;
|
|
197
2041
|
background: var(--ttcb-bg);
|
|
198
2042
|
border: 1px solid var(--ttcb-border);
|
|
199
2043
|
border-radius: 16px;
|
|
@@ -201,9 +2045,17 @@ function I(i, t) {
|
|
|
201
2045
|
box-shadow: var(--ttcb-shadow);
|
|
202
2046
|
overflow: hidden;
|
|
203
2047
|
z-index: 9998;
|
|
204
|
-
transition: opacity 0.2s ease, transform 0.25s ease;
|
|
2048
|
+
transition: opacity 0.2s ease, transform 0.25s ease, height 0.2s ease;
|
|
205
2049
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
206
2050
|
}
|
|
2051
|
+
.ttcb-panel.ttcb-mode-chat {
|
|
2052
|
+
height: 560px;
|
|
2053
|
+
}
|
|
2054
|
+
.ttcb-panel.ttcb-mode-form,
|
|
2055
|
+
.ttcb-panel.ttcb-mode-compact {
|
|
2056
|
+
height: auto;
|
|
2057
|
+
max-height: min(560px, calc(100vh - 100px));
|
|
2058
|
+
}
|
|
207
2059
|
.ttcb-panel.bottom-right { bottom: 92px; right: 24px; }
|
|
208
2060
|
.ttcb-panel.bottom-left { bottom: 92px; left: 24px; }
|
|
209
2061
|
.ttcb-panel.hidden {
|
|
@@ -218,28 +2070,98 @@ function I(i, t) {
|
|
|
218
2070
|
background: var(--ttcb-bg);
|
|
219
2071
|
flex-shrink: 0;
|
|
220
2072
|
}
|
|
2073
|
+
.ttcb-avatar-wrap {
|
|
2074
|
+
flex-shrink: 0;
|
|
2075
|
+
}
|
|
221
2076
|
.ttcb-avatar {
|
|
222
|
-
width:
|
|
223
|
-
background: ${
|
|
2077
|
+
width: 40px; height: 40px; border-radius: 10px;
|
|
2078
|
+
background: ${e};
|
|
224
2079
|
display: flex; align-items: center; justify-content: center;
|
|
225
|
-
flex-shrink: 0;
|
|
226
2080
|
}
|
|
227
|
-
.ttcb-avatar svg { width:
|
|
228
|
-
.ttcb-header-
|
|
229
|
-
|
|
2081
|
+
.ttcb-avatar svg { width: 22px; height: 22px; fill: #fff; }
|
|
2082
|
+
.ttcb-header-main {
|
|
2083
|
+
flex: 1; min-width: 0;
|
|
2084
|
+
display: flex; flex-direction: column; gap: 4px;
|
|
2085
|
+
}
|
|
2086
|
+
.ttcb-header-title-row {
|
|
2087
|
+
display: flex; align-items: center; gap: 6px;
|
|
2088
|
+
}
|
|
2089
|
+
.ttcb-header-title {
|
|
2090
|
+
font-weight: 700; font-size: 15px; color: var(--ttcb-text);
|
|
2091
|
+
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
|
2092
|
+
}
|
|
2093
|
+
.ttcb-verified {
|
|
2094
|
+
width: 16px; height: 16px; color: ${e};
|
|
2095
|
+
flex-shrink: 0; display: flex;
|
|
2096
|
+
}
|
|
2097
|
+
.ttcb-verified svg { width: 16px; height: 16px; }
|
|
2098
|
+
.ttcb-header-meta {
|
|
2099
|
+
display: flex; align-items: center; gap: 8px;
|
|
2100
|
+
font-size: 12px; color: var(--ttcb-text-muted);
|
|
2101
|
+
}
|
|
2102
|
+
.ttcb-meta-online {
|
|
2103
|
+
display: inline-flex; align-items: center; gap: 5px;
|
|
2104
|
+
color: var(--ttcb-online); font-weight: 500;
|
|
2105
|
+
}
|
|
2106
|
+
.ttcb-meta-online::before {
|
|
2107
|
+
content: '';
|
|
2108
|
+
width: 7px; height: 7px; border-radius: 50%;
|
|
2109
|
+
background: var(--ttcb-online);
|
|
2110
|
+
}
|
|
2111
|
+
.ttcb-meta-sep {
|
|
2112
|
+
width: 1px; height: 12px; background: var(--ttcb-border);
|
|
2113
|
+
}
|
|
2114
|
+
.ttcb-meta-replies {
|
|
2115
|
+
display: inline-flex; align-items: center; gap: 4px;
|
|
2116
|
+
color: var(--ttcb-text-muted);
|
|
2117
|
+
}
|
|
2118
|
+
.ttcb-meta-replies svg { width: 18px; height: 14px; }
|
|
2119
|
+
.ttcb-header-actions {
|
|
2120
|
+
display: flex; align-items: center; gap: 3px;
|
|
2121
|
+
flex-shrink: 0; align-self: center;
|
|
2122
|
+
}
|
|
2123
|
+
.ttcb-close-btn, .ttcb-new-session-btn, .ttcb-request-human-btn {
|
|
230
2124
|
background: none; border: none; cursor: pointer;
|
|
231
|
-
color: var(--ttcb-text-muted); padding:
|
|
2125
|
+
color: var(--ttcb-text-muted); padding: 6px; border-radius: 6px;
|
|
232
2126
|
display: flex; align-items: center; justify-content: center;
|
|
233
2127
|
}
|
|
234
|
-
.ttcb-close-btn:hover, .ttcb-new-session-btn:hover
|
|
235
|
-
|
|
236
|
-
|
|
2128
|
+
.ttcb-close-btn:hover, .ttcb-new-session-btn:hover, .ttcb-request-human-btn:hover {
|
|
2129
|
+
background: var(--ttcb-bg-secondary);
|
|
2130
|
+
}
|
|
2131
|
+
.ttcb-close-btn svg { width: 19px; height: 19px; fill: currentColor; }
|
|
2132
|
+
.ttcb-new-session-btn svg,
|
|
2133
|
+
.ttcb-request-human-btn svg {
|
|
2134
|
+
width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2;
|
|
2135
|
+
}
|
|
2136
|
+
.ttcb-new-session-btn.hidden, .ttcb-request-human-btn.hidden { display: none; }
|
|
2137
|
+
|
|
2138
|
+
.ttcb-mode-banner {
|
|
2139
|
+
display: none;
|
|
2140
|
+
padding: 10px 16px;
|
|
2141
|
+
font-size: 12px;
|
|
2142
|
+
line-height: 1.4;
|
|
2143
|
+
color: var(--ttcb-text-muted);
|
|
2144
|
+
background: var(--ttcb-bg-secondary);
|
|
2145
|
+
border-top: 1px solid var(--ttcb-border);
|
|
2146
|
+
flex-shrink: 0;
|
|
2147
|
+
}
|
|
2148
|
+
.ttcb-mode-banner.visible { display: block; }
|
|
2149
|
+
.ttcb-mode-banner.waiting { color: var(--ttcb-text); }
|
|
2150
|
+
.ttcb-mode-banner.closed {
|
|
2151
|
+
color: var(--ttcb-text);
|
|
2152
|
+
background: color-mix(in srgb, #ef4444 10%, var(--ttcb-bg-secondary));
|
|
2153
|
+
}
|
|
2154
|
+
.ttcb-mode-banner.human { color: var(--ttcb-text); }
|
|
237
2155
|
|
|
238
2156
|
.ttcb-messages {
|
|
239
2157
|
flex: 1; overflow-y: auto; padding: 16px;
|
|
240
2158
|
display: flex; flex-direction: column; gap: 12px;
|
|
241
2159
|
scroll-behavior: smooth;
|
|
242
2160
|
font-size: 14px;
|
|
2161
|
+
min-height: 120px;
|
|
2162
|
+
}
|
|
2163
|
+
.ttcb-panel.ttcb-mode-compact .ttcb-messages {
|
|
2164
|
+
min-height: 160px;
|
|
243
2165
|
}
|
|
244
2166
|
|
|
245
2167
|
.ttcb-empty {
|
|
@@ -289,15 +2211,24 @@ function I(i, t) {
|
|
|
289
2211
|
|
|
290
2212
|
.ttcb-msg { display: flex; gap: 8px; max-width: 100%; }
|
|
291
2213
|
.ttcb-msg.human { flex-direction: row-reverse; }
|
|
2214
|
+
.ttcb-msg-body { display: flex; flex-direction: column; gap: 3px; max-width: 78%; }
|
|
2215
|
+
.ttcb-msg.human .ttcb-msg-body { align-items: flex-end; }
|
|
2216
|
+
.ttcb-msg-label {
|
|
2217
|
+
font-size: 11px; font-weight: 600; color: var(--ttcb-text-muted);
|
|
2218
|
+
padding-left: 2px;
|
|
2219
|
+
}
|
|
292
2220
|
.ttcb-msg-avatar {
|
|
293
2221
|
width: 28px; height: 28px; border-radius: 50%;
|
|
294
2222
|
background: var(--ttcb-bg-secondary);
|
|
295
2223
|
display: flex; align-items: center; justify-content: center;
|
|
296
2224
|
flex-shrink: 0; margin-top: 2px;
|
|
297
2225
|
}
|
|
2226
|
+
/* Offset past the "Agent" label so the avatar lines up with the bubble */
|
|
2227
|
+
.ttcb-msg.agent .ttcb-msg-avatar { margin-top: 22px; }
|
|
298
2228
|
.ttcb-msg-avatar svg { width: 13px; height: 13px; fill: var(--ttcb-text-muted); }
|
|
2229
|
+
.ttcb-msg.agent .ttcb-msg-avatar svg { fill: none; stroke: var(--ttcb-text-muted); stroke-width: 2; }
|
|
299
2230
|
.ttcb-bubble {
|
|
300
|
-
max-width:
|
|
2231
|
+
max-width: 100%; padding: 9px 13px;
|
|
301
2232
|
border-radius: 16px 16px 16px 4px;
|
|
302
2233
|
line-height: 1.5;
|
|
303
2234
|
color: var(--ttcb-ai-text);
|
|
@@ -310,8 +2241,13 @@ function I(i, t) {
|
|
|
310
2241
|
color: var(--ttcb-user-text);
|
|
311
2242
|
border-radius: 16px 16px 4px 16px;
|
|
312
2243
|
}
|
|
2244
|
+
.ttcb-msg.agent .ttcb-bubble {
|
|
2245
|
+
background: var(--ttcb-bg);
|
|
2246
|
+
color: var(--ttcb-text);
|
|
2247
|
+
border: 1px solid var(--ttcb-border);
|
|
2248
|
+
border-radius: 16px 16px 16px 4px;
|
|
2249
|
+
}
|
|
313
2250
|
|
|
314
|
-
/* Markdown styles inside AI bubble */
|
|
315
2251
|
.ttcb-bubble p { margin: 0 0 6px 0; }
|
|
316
2252
|
.ttcb-bubble p:last-child { margin-bottom: 0; }
|
|
317
2253
|
.ttcb-bubble strong { font-weight: 600; }
|
|
@@ -368,12 +2304,12 @@ function I(i, t) {
|
|
|
368
2304
|
transition: border-color 0.15s;
|
|
369
2305
|
font-family: inherit;
|
|
370
2306
|
}
|
|
371
|
-
.ttcb-input:focus { border-color: ${
|
|
2307
|
+
.ttcb-input:focus { border-color: ${e}; }
|
|
372
2308
|
.ttcb-input::placeholder { color: var(--ttcb-text-muted); }
|
|
373
2309
|
.ttcb-input:disabled { opacity: 0.6; cursor: not-allowed; }
|
|
374
2310
|
.ttcb-send-btn {
|
|
375
2311
|
padding: 0 14px; height: 38px;
|
|
376
|
-
background: ${
|
|
2312
|
+
background: ${e}; color: #fff;
|
|
377
2313
|
border: none; border-radius: 8px; cursor: pointer;
|
|
378
2314
|
display: flex; align-items: center; justify-content: center;
|
|
379
2315
|
transition: opacity 0.15s; flex-shrink: 0;
|
|
@@ -382,6 +2318,171 @@ function I(i, t) {
|
|
|
382
2318
|
.ttcb-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
383
2319
|
.ttcb-send-btn svg { width: 16px; height: 16px; fill: #fff; }
|
|
384
2320
|
|
|
2321
|
+
.ttcb-identify {
|
|
2322
|
+
display: none;
|
|
2323
|
+
flex-direction: column;
|
|
2324
|
+
gap: 14px;
|
|
2325
|
+
padding: 16px 16px 14px;
|
|
2326
|
+
overflow-y: auto;
|
|
2327
|
+
}
|
|
2328
|
+
.ttcb-panel.ttcb-mode-form .ttcb-identify.visible {
|
|
2329
|
+
display: flex;
|
|
2330
|
+
flex: 0 0 auto;
|
|
2331
|
+
}
|
|
2332
|
+
.ttcb-identify-form {
|
|
2333
|
+
display: flex; flex-direction: column; gap: 14px;
|
|
2334
|
+
}
|
|
2335
|
+
.ttcb-field { display: flex; flex-direction: column; gap: 6px; }
|
|
2336
|
+
.ttcb-field-label-row {
|
|
2337
|
+
display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
|
|
2338
|
+
}
|
|
2339
|
+
.ttcb-label {
|
|
2340
|
+
font-size: 13px; font-weight: 600; color: var(--ttcb-text);
|
|
2341
|
+
}
|
|
2342
|
+
.ttcb-label .ttcb-req { color: #ef4444; font-weight: 600; }
|
|
2343
|
+
.ttcb-field-hint {
|
|
2344
|
+
font-size: 11px; color: var(--ttcb-hint); font-weight: 400;
|
|
2345
|
+
white-space: nowrap;
|
|
2346
|
+
}
|
|
2347
|
+
.ttcb-input-wrap {
|
|
2348
|
+
display: flex; align-items: center; gap: 8px;
|
|
2349
|
+
border: 1px solid var(--ttcb-border);
|
|
2350
|
+
border-radius: 10px;
|
|
2351
|
+
padding: 0 12px;
|
|
2352
|
+
background: var(--ttcb-input-bg);
|
|
2353
|
+
transition: border-color 0.15s;
|
|
2354
|
+
}
|
|
2355
|
+
.ttcb-input-wrap:focus-within { border-color: ${e}; }
|
|
2356
|
+
.ttcb-input-wrap.disabled { opacity: 0.6; }
|
|
2357
|
+
.ttcb-input-icon {
|
|
2358
|
+
width: 18px; height: 18px; color: var(--ttcb-text-muted);
|
|
2359
|
+
flex-shrink: 0; display: flex;
|
|
2360
|
+
}
|
|
2361
|
+
.ttcb-input-icon svg { width: 18px; height: 18px; }
|
|
2362
|
+
.ttcb-identify-input {
|
|
2363
|
+
flex: 1; min-width: 0;
|
|
2364
|
+
border: none; outline: none;
|
|
2365
|
+
padding: 11px 0;
|
|
2366
|
+
font-size: 14px;
|
|
2367
|
+
background: transparent;
|
|
2368
|
+
color: var(--ttcb-text);
|
|
2369
|
+
font-family: inherit;
|
|
2370
|
+
}
|
|
2371
|
+
.ttcb-identify-input::placeholder { color: var(--ttcb-text-muted); }
|
|
2372
|
+
.ttcb-identify-input:disabled { cursor: not-allowed; }
|
|
2373
|
+
|
|
2374
|
+
.ttcb-phone-row {
|
|
2375
|
+
display: flex; align-items: stretch;
|
|
2376
|
+
border: 1px solid var(--ttcb-border);
|
|
2377
|
+
border-radius: 10px;
|
|
2378
|
+
background: var(--ttcb-input-bg);
|
|
2379
|
+
overflow: hidden;
|
|
2380
|
+
transition: border-color 0.15s;
|
|
2381
|
+
}
|
|
2382
|
+
.ttcb-phone-row:focus-within { border-color: ${e}; }
|
|
2383
|
+
.ttcb-phone-row.disabled { opacity: 0.6; }
|
|
2384
|
+
.ttcb-dial-btn {
|
|
2385
|
+
display: flex; align-items: center; gap: 4px;
|
|
2386
|
+
padding: 0 10px;
|
|
2387
|
+
border: none; border-right: 1px solid var(--ttcb-border);
|
|
2388
|
+
background: var(--ttcb-bg-secondary);
|
|
2389
|
+
cursor: pointer;
|
|
2390
|
+
font-family: inherit;
|
|
2391
|
+
font-size: 13px;
|
|
2392
|
+
font-weight: 500;
|
|
2393
|
+
color: var(--ttcb-text);
|
|
2394
|
+
flex-shrink: 0;
|
|
2395
|
+
}
|
|
2396
|
+
.ttcb-dial-btn:disabled { cursor: not-allowed; }
|
|
2397
|
+
.ttcb-dial-flag { font-size: 16px; line-height: 1; }
|
|
2398
|
+
.ttcb-dial-code { letter-spacing: 0.01em; }
|
|
2399
|
+
.ttcb-dial-btn svg {
|
|
2400
|
+
width: 14px; height: 14px; color: var(--ttcb-text-muted);
|
|
2401
|
+
}
|
|
2402
|
+
.ttcb-phone-national {
|
|
2403
|
+
flex: 1; min-width: 0;
|
|
2404
|
+
border: none; outline: none;
|
|
2405
|
+
padding: 11px 12px;
|
|
2406
|
+
font-size: 14px;
|
|
2407
|
+
background: transparent;
|
|
2408
|
+
color: var(--ttcb-text);
|
|
2409
|
+
font-family: inherit;
|
|
2410
|
+
}
|
|
2411
|
+
.ttcb-phone-national::placeholder { color: var(--ttcb-text-muted); }
|
|
2412
|
+
|
|
2413
|
+
.ttcb-country-popover {
|
|
2414
|
+
display: none;
|
|
2415
|
+
flex-direction: column;
|
|
2416
|
+
border: 1px solid var(--ttcb-border);
|
|
2417
|
+
border-radius: 10px;
|
|
2418
|
+
background: var(--ttcb-bg);
|
|
2419
|
+
box-shadow: 0 8px 24px rgba(0,0,0,0.12);
|
|
2420
|
+
max-height: 220px;
|
|
2421
|
+
overflow: hidden;
|
|
2422
|
+
margin-top: -8px;
|
|
2423
|
+
}
|
|
2424
|
+
.ttcb-country-popover.open { display: flex; }
|
|
2425
|
+
.ttcb-country-search {
|
|
2426
|
+
border: none; border-bottom: 1px solid var(--ttcb-border);
|
|
2427
|
+
padding: 10px 12px;
|
|
2428
|
+
font-size: 13px; outline: none;
|
|
2429
|
+
background: var(--ttcb-input-bg);
|
|
2430
|
+
color: var(--ttcb-text);
|
|
2431
|
+
font-family: inherit;
|
|
2432
|
+
}
|
|
2433
|
+
.ttcb-country-list {
|
|
2434
|
+
overflow-y: auto;
|
|
2435
|
+
max-height: 176px;
|
|
2436
|
+
}
|
|
2437
|
+
.ttcb-country-item {
|
|
2438
|
+
display: flex; align-items: center; gap: 8px;
|
|
2439
|
+
width: 100%;
|
|
2440
|
+
padding: 8px 12px;
|
|
2441
|
+
border: none; background: none;
|
|
2442
|
+
cursor: pointer;
|
|
2443
|
+
font-family: inherit;
|
|
2444
|
+
font-size: 13px;
|
|
2445
|
+
color: var(--ttcb-text);
|
|
2446
|
+
text-align: left;
|
|
2447
|
+
}
|
|
2448
|
+
.ttcb-country-item:hover,
|
|
2449
|
+
.ttcb-country-item[aria-selected="true"] {
|
|
2450
|
+
background: var(--ttcb-bg-secondary);
|
|
2451
|
+
}
|
|
2452
|
+
.ttcb-country-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2453
|
+
.ttcb-country-item-dial { color: var(--ttcb-text-muted); flex-shrink: 0; }
|
|
2454
|
+
|
|
2455
|
+
.ttcb-identify-error {
|
|
2456
|
+
font-size: 12px; color: #ef4444; min-height: 16px;
|
|
2457
|
+
margin-top: -4px;
|
|
2458
|
+
}
|
|
2459
|
+
.ttcb-identify-submit {
|
|
2460
|
+
width: 100%; height: 46px;
|
|
2461
|
+
background: ${e}; color: #fff;
|
|
2462
|
+
border: none; border-radius: 999px; cursor: pointer;
|
|
2463
|
+
font-size: 15px; font-weight: 600; font-family: inherit;
|
|
2464
|
+
display: flex; align-items: center; justify-content: center; gap: 8px;
|
|
2465
|
+
}
|
|
2466
|
+
.ttcb-identify-submit svg {
|
|
2467
|
+
width: 18px; height: 18px; stroke: #fff; fill: none;
|
|
2468
|
+
}
|
|
2469
|
+
.ttcb-identify-submit:hover { opacity: 0.92; }
|
|
2470
|
+
.ttcb-identify-submit:disabled { opacity: 0.55; cursor: not-allowed; }
|
|
2471
|
+
|
|
2472
|
+
.ttcb-trust {
|
|
2473
|
+
display: flex; align-items: center; justify-content: center; gap: 6px;
|
|
2474
|
+
font-size: 11px; color: var(--ttcb-text-muted);
|
|
2475
|
+
padding-bottom: 2px;
|
|
2476
|
+
}
|
|
2477
|
+
.ttcb-trust svg {
|
|
2478
|
+
width: 14px; height: 14px;
|
|
2479
|
+
stroke: var(--ttcb-online);
|
|
2480
|
+
fill: none;
|
|
2481
|
+
flex-shrink: 0;
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
.ttcb-footer.hidden, .ttcb-messages.hidden { display: none; }
|
|
2485
|
+
|
|
385
2486
|
@media (max-width: 440px) {
|
|
386
2487
|
.ttcb-panel { width: calc(100vw - 16px); right: 8px !important; left: 8px !important; bottom: 84px !important; }
|
|
387
2488
|
.ttcb-fab.bottom-right { right: 16px; }
|
|
@@ -389,394 +2490,708 @@ function I(i, t) {
|
|
|
389
2490
|
}
|
|
390
2491
|
`;
|
|
391
2492
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const t = [];
|
|
397
|
-
let e = i.replace(/```[\w]*\n?([\s\S]*?)```/g, (r, o) => {
|
|
398
|
-
const c = t.length;
|
|
399
|
-
return t.push(`<pre><code>${u(o.trim())}</code></pre>`), `${c}`;
|
|
400
|
-
});
|
|
401
|
-
e = e.replace(/`([^`\n]+)`/g, (r, o) => {
|
|
402
|
-
const c = t.length;
|
|
403
|
-
return t.push(`<code>${u(o)}</code>`), `${c}`;
|
|
404
|
-
}), e = u(e);
|
|
405
|
-
const n = e.split(`
|
|
406
|
-
`), s = [];
|
|
407
|
-
let a = "";
|
|
408
|
-
const l = () => {
|
|
409
|
-
a && (s.push(`</${a}>`), a = "");
|
|
410
|
-
};
|
|
411
|
-
for (const r of n) {
|
|
412
|
-
let o;
|
|
413
|
-
(o = r.match(/^### (.+)/)) ? (l(), s.push(`<h3>${o[1]}</h3>`)) : (o = r.match(/^## (.+)/)) ? (l(), s.push(`<h2>${o[1]}</h2>`)) : (o = r.match(/^# (.+)/)) ? (l(), s.push(`<h1>${o[1]}</h1>`)) : (o = r.match(/^[*-] (.+)/)) ? (a !== "ul" && (l(), s.push("<ul>"), a = "ul"), s.push(`<li>${o[1]}</li>`)) : (o = r.match(/^\d+\. (.+)/)) ? (a !== "ol" && (l(), s.push("<ol>"), a = "ol"), s.push(`<li>${o[1]}</li>`)) : (l(), s.push(r));
|
|
414
|
-
}
|
|
415
|
-
return l(), e = s.join(`
|
|
416
|
-
`), e = e.replace(/\*\*(.+?)\*\*/gs, "<strong>$1</strong>").replace(/__(.+?)__/gs, "<strong>$1</strong>").replace(/\*(.+?)\*/gs, "<em>$1</em>").replace(/_(.+?)_/gs, "<em>$1</em>").replace(
|
|
417
|
-
/\[([^\]]+)\]\((https?:\/\/[^)]+)\)/g,
|
|
418
|
-
'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'
|
|
419
|
-
), e = e.split(/\n{2,}/).map((r) => {
|
|
420
|
-
const o = r.trim();
|
|
421
|
-
return o ? /^<(h[1-3]|ul|ol|pre|li)/.test(o) ? o : o.split(/(\x04\d+\x05)/g).map((c) => {
|
|
422
|
-
if (/^\x04\d+\x05$/.test(c)) return c;
|
|
423
|
-
const d = c.trim();
|
|
424
|
-
return d ? `<p>${d.replace(/\n/g, "<br>")}</p>` : "";
|
|
425
|
-
}).join("") : "";
|
|
426
|
-
}).filter(Boolean).join(""), e = e.replace(/\x04(\d+)\x05/g, (r, o) => t[+o] ?? "").replace(/\x02(\d+)\x03/g, (r, o) => t[+o] ?? ""), e;
|
|
427
|
-
}
|
|
428
|
-
function N() {
|
|
429
|
-
return `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
430
|
-
<path d="M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.3-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.23-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.23.09.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z"/>
|
|
431
|
-
</svg>`;
|
|
432
|
-
}
|
|
433
|
-
function f() {
|
|
434
|
-
return `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
435
|
-
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"/>
|
|
436
|
-
</svg>`;
|
|
437
|
-
}
|
|
438
|
-
function _() {
|
|
439
|
-
return `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg">
|
|
440
|
-
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
|
|
441
|
-
<line x1="12" y1="8" x2="12" y2="14"/>
|
|
442
|
-
<line x1="9" y1="11" x2="15" y2="11"/>
|
|
443
|
-
</svg>`;
|
|
444
|
-
}
|
|
445
|
-
function $() {
|
|
446
|
-
return `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
447
|
-
<path d="M20 2H4C2.9 2 2 2.9 2 4v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z"/>
|
|
448
|
-
</svg>`;
|
|
449
|
-
}
|
|
450
|
-
function B() {
|
|
451
|
-
return `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
452
|
-
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
|
|
453
|
-
</svg>`;
|
|
454
|
-
}
|
|
455
|
-
function A() {
|
|
456
|
-
return `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
457
|
-
<path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/>
|
|
458
|
-
</svg>`;
|
|
459
|
-
}
|
|
460
|
-
function m() {
|
|
461
|
-
return `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
462
|
-
<path d="M20 9V7c0-1.1-.9-2-2-2h-3c0-1.66-1.34-3-3-3S9 3.34 9 5H6c-1.1 0-2 .9-2 2v2c-1.66 0-3 1.34-3 3s1.34 3 3 3v4c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-4c1.66 0 3-1.34 3-3s-1.34-3-3-3zm-2 10H6V7h12v12zm-9-6c-.83 0-1.5-.67-1.5-1.5S8.17 10 9 10s1.5.67 1.5 1.5S9.83 13 9 13zm6 0c-.83 0-1.5-.67-1.5-1.5S14.17 10 15 10s1.5.67 1.5 1.5S15.83 13 15 13z"/>
|
|
463
|
-
</svg>`;
|
|
2493
|
+
//#endregion
|
|
2494
|
+
//#region src/widget/render.ts
|
|
2495
|
+
function X(e) {
|
|
2496
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
464
2497
|
}
|
|
465
|
-
function
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
2498
|
+
function pt(e) {
|
|
2499
|
+
let t = [], n = e.replace(/```[\w]*\n?([\s\S]*?)```/g, (e, n) => {
|
|
2500
|
+
let r = t.length;
|
|
2501
|
+
return t.push(`<pre><code>${X(n.trim())}</code></pre>`), `\x04${r}\x05`;
|
|
2502
|
+
});
|
|
2503
|
+
n = n.replace(/`([^`\n]+)`/g, (e, n) => {
|
|
2504
|
+
let r = t.length;
|
|
2505
|
+
return t.push(`<code>${X(n)}</code>`), `\x02${r}\x03`;
|
|
2506
|
+
}), n = X(n);
|
|
2507
|
+
let r = n.split("\n"), i = [], a = "", o = () => {
|
|
2508
|
+
a &&= (i.push(`</${a}>`), "");
|
|
2509
|
+
};
|
|
2510
|
+
for (let e of r) {
|
|
2511
|
+
let t;
|
|
2512
|
+
(t = e.match(/^### (.+)/)) ? (o(), i.push(`<h3>${t[1]}</h3>`)) : (t = e.match(/^## (.+)/)) ? (o(), i.push(`<h2>${t[1]}</h2>`)) : (t = e.match(/^# (.+)/)) ? (o(), i.push(`<h1>${t[1]}</h1>`)) : (t = e.match(/^[*-] (.+)/)) ? (a !== "ul" && (o(), i.push("<ul>"), a = "ul"), i.push(`<li>${t[1]}</li>`)) : (t = e.match(/^\d+\. (.+)/)) ? (a !== "ol" && (o(), i.push("<ol>"), a = "ol"), i.push(`<li>${t[1]}</li>`)) : (o(), i.push(e));
|
|
2513
|
+
}
|
|
2514
|
+
return o(), n = i.join("\n"), n = n.replace(/\*\*(.+?)\*\*/gs, "<strong>$1</strong>").replace(/__(.+?)__/gs, "<strong>$1</strong>").replace(/\*(.+?)\*/gs, "<em>$1</em>").replace(/_(.+?)_/gs, "<em>$1</em>").replace(/\[([^\]]+)\]\((https?:\/\/[^)]+)\)/g, "<a href=\"$2\" target=\"_blank\" rel=\"noopener noreferrer\">$1</a>"), n = n.split(/\n{2,}/).map((e) => {
|
|
2515
|
+
let t = e.trim();
|
|
2516
|
+
return t ? /^<(h[1-3]|ul|ol|pre|li)/.test(t) ? t : t.split(/(\x04\d+\x05)/g).map((e) => {
|
|
2517
|
+
if (/^\x04\d+\x05$/.test(e)) return e;
|
|
2518
|
+
let t = e.trim();
|
|
2519
|
+
return t ? `<p>${t.replace(/\n/g, "<br>")}</p>` : "";
|
|
2520
|
+
}).join("") : "";
|
|
2521
|
+
}).filter(Boolean).join(""), n = n.replace(/\x04(\d+)\x05/g, (e, n) => t[+n] ?? "").replace(/\x02(\d+)\x03/g, (e, n) => t[+n] ?? ""), n;
|
|
2522
|
+
}
|
|
2523
|
+
function mt() {
|
|
2524
|
+
return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.3-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.23-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.23.09.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z\"/>\n </svg>";
|
|
2525
|
+
}
|
|
2526
|
+
function ht() {
|
|
2527
|
+
return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z\"/>\n </svg>";
|
|
2528
|
+
}
|
|
2529
|
+
function gt() {
|
|
2530
|
+
return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z\"/>\n <line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"14\"/>\n <line x1=\"9\" y1=\"11\" x2=\"15\" y2=\"11\"/>\n </svg>";
|
|
2531
|
+
}
|
|
2532
|
+
function _t() {
|
|
2533
|
+
return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 2H4C2.9 2 2 2.9 2 4v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z\"/>\n </svg>";
|
|
2534
|
+
}
|
|
2535
|
+
function vt() {
|
|
2536
|
+
return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z\"/>\n </svg>";
|
|
2537
|
+
}
|
|
2538
|
+
function yt() {
|
|
2539
|
+
return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z\"/>\n </svg>";
|
|
2540
|
+
}
|
|
2541
|
+
function Z() {
|
|
2542
|
+
return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 9V7c0-1.1-.9-2-2-2h-3c0-1.66-1.34-3-3-3S9 3.34 9 5H6c-1.1 0-2 .9-2 2v2c-1.66 0-3 1.34-3 3s1.34 3 3 3v4c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-4c1.66 0 3-1.34 3-3s-1.34-3-3-3zm-2 10H6V7h12v12zm-9-6c-.83 0-1.5-.67-1.5-1.5S8.17 10 9 10s1.5.67 1.5 1.5S9.83 13 9 13zm6 0c-.83 0-1.5-.67-1.5-1.5S14.17 10 15 10s1.5.67 1.5 1.5S15.83 13 15 13z\"/>\n </svg>";
|
|
2543
|
+
}
|
|
2544
|
+
function bt() {
|
|
2545
|
+
return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z\"/>\n </svg>";
|
|
2546
|
+
}
|
|
2547
|
+
function xt() {
|
|
2548
|
+
return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2\"/>\n <circle cx=\"12\" cy=\"7\" r=\"4\"/>\n </svg>";
|
|
2549
|
+
}
|
|
2550
|
+
function St() {
|
|
2551
|
+
return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z\"/>\n <polyline points=\"22,6 12,13 2,6\"/>\n </svg>";
|
|
2552
|
+
}
|
|
2553
|
+
function Ct() {
|
|
2554
|
+
return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <polyline points=\"6 9 12 15 18 9\"/>\n </svg>";
|
|
2555
|
+
}
|
|
2556
|
+
function wt() {
|
|
2557
|
+
return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <line x1=\"5\" y1=\"12\" x2=\"19\" y2=\"12\"/>\n <polyline points=\"12 5 19 12 12 19\"/>\n </svg>";
|
|
2558
|
+
}
|
|
2559
|
+
function Tt() {
|
|
2560
|
+
return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z\"/>\n <polyline points=\"9 12 11 14 15 10\"/>\n </svg>";
|
|
2561
|
+
}
|
|
2562
|
+
function Et() {
|
|
2563
|
+
return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" fill=\"currentColor\"/>\n <path d=\"M9 12l2 2 4-4\" fill=\"none\" stroke=\"#fff\" stroke-width=\"2.2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>";
|
|
2564
|
+
}
|
|
2565
|
+
function Dt() {
|
|
2566
|
+
return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path fill=\"#F59E0B\" d=\"M8 2.5l1.1 2.2 2.4.3-1.7 1.7.4 2.4L8 8l-2.2 1.1.4-2.4L4.5 5l2.4-.3L8 2.5z\"/>\n <path fill=\"#F59E0B\" d=\"M16 3.5l.8 1.6 1.8.2-1.3 1.3.3 1.8L16 7.5l-1.6.9.3-1.8-1.3-1.3 1.8-.2L16 3.5z\"/>\n <path fill=\"#FBBF24\" d=\"M12 11.5l1 2 2.2.3-1.6 1.6.4 2.2-2-1.1-2 1.1.4-2.2-1.6-1.6 2.2-.3 1-2z\"/>\n </svg>";
|
|
2567
|
+
}
|
|
2568
|
+
function Ot() {
|
|
2569
|
+
return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2\"/>\n <circle cx=\"9\" cy=\"7\" r=\"4\"/>\n <path d=\"M23 21v-2a4 4 0 0 0-3-3.87\"/>\n <path d=\"M16 3.13a4 4 0 0 1 0 7.75\"/>\n </svg>";
|
|
2570
|
+
}
|
|
2571
|
+
function kt(e, t) {
|
|
2572
|
+
let n = document.createElement("div");
|
|
2573
|
+
n.className = `ttcb-msg ${t}`;
|
|
2574
|
+
let r = document.createElement("div");
|
|
2575
|
+
r.className = "ttcb-msg-avatar", r.innerHTML = t === "human" ? bt() : t === "agent" ? xt() : Z();
|
|
2576
|
+
let i = document.createElement("div");
|
|
2577
|
+
if (i.className = "ttcb-msg-body", t === "agent") {
|
|
2578
|
+
let e = document.createElement("span");
|
|
2579
|
+
e.className = "ttcb-msg-label", e.textContent = "Agent", i.appendChild(e);
|
|
2580
|
+
}
|
|
2581
|
+
let a = document.createElement("div");
|
|
2582
|
+
return a.className = "ttcb-bubble", t === "human" ? a.textContent = e : a.innerHTML = pt(e), i.appendChild(a), n.appendChild(r), n.appendChild(i), n;
|
|
2583
|
+
}
|
|
2584
|
+
function At() {
|
|
2585
|
+
let e = document.createElement("div");
|
|
2586
|
+
e.className = "ttcb-msg ai", e.id = "ttcb-typing";
|
|
2587
|
+
let t = document.createElement("div");
|
|
2588
|
+
t.className = "ttcb-msg-avatar", t.innerHTML = Z();
|
|
2589
|
+
let n = document.createElement("div");
|
|
2590
|
+
return n.className = "ttcb-typing", n.innerHTML = "<span></span><span></span><span></span>", e.appendChild(t), e.appendChild(n), e;
|
|
2591
|
+
}
|
|
2592
|
+
//#endregion
|
|
2593
|
+
//#region src/widget/widget.ts
|
|
2594
|
+
var jt = class {
|
|
2595
|
+
constructor(e, t) {
|
|
2596
|
+
this.selectedCountry = ut, this.countryOpen = !1, this.isOpen = !1, this.destroyed = !1, this.position = e.position ?? "bottom-right", this.callbacks = t, this.mount(e);
|
|
2597
|
+
}
|
|
2598
|
+
mount(e) {
|
|
2599
|
+
this.host = document.createElement("div"), this.host.id = "onedeskpro-chatbot-host", this.shadow = this.host.attachShadow({ mode: "closed" });
|
|
2600
|
+
let t = document.createElement("style");
|
|
2601
|
+
t.textContent = ft(e.primaryColor ?? "#2563EB", e.theme ?? "auto"), this.shadow.appendChild(t);
|
|
2602
|
+
let n = document.createElement("button");
|
|
2603
|
+
n.className = `ttcb-fab ${this.position}`, n.setAttribute("aria-label", "Open chat"), n.innerHTML = _t(), n.addEventListener("click", () => this.toggle()), this.shadow.appendChild(n), this.panel = document.createElement("div"), this.panel.className = `ttcb-panel ${this.position} hidden ttcb-mode-compact`, this.panel.setAttribute("role", "dialog"), this.panel.setAttribute("aria-modal", "true"), this.panel.setAttribute("aria-label", e.chatbotName ?? "AI Assistant"), this.panel.appendChild(this.buildHeader(e)), this.identifyContainer = document.createElement("div"), this.identifyContainer.className = "ttcb-identify", this.buildIdentifyForm(this.identifyContainer), this.panel.appendChild(this.identifyContainer), this.messagesContainer = document.createElement("div"), this.messagesContainer.className = "ttcb-messages", this.messagesContainer.setAttribute("aria-live", "polite"), this.messagesContainer.setAttribute("aria-label", "Chat messages"), this.panel.appendChild(this.messagesContainer), this.modeBanner = document.createElement("div"), this.modeBanner.className = "ttcb-mode-banner", this.modeBanner.setAttribute("role", "status"), this.panel.appendChild(this.modeBanner), this.footer = document.createElement("div"), this.footer.className = "ttcb-footer";
|
|
2604
|
+
let r = document.createElement("form");
|
|
2605
|
+
r.className = "ttcb-form", r.addEventListener("submit", (e) => {
|
|
2606
|
+
e.preventDefault(), this.handleSend();
|
|
2607
|
+
}), this.input = document.createElement("input"), this.input.type = "text", this.input.className = "ttcb-input", this.input.placeholder = e.placeholder ?? "Type your message…", this.input.setAttribute("aria-label", "Message input"), this.input.setAttribute("autocomplete", "off"), this.sendBtn = document.createElement("button"), this.sendBtn.type = "submit", this.sendBtn.className = "ttcb-send-btn", this.sendBtn.innerHTML = yt(), this.sendBtn.setAttribute("aria-label", "Send message"), r.appendChild(this.input), r.appendChild(this.sendBtn), this.footer.appendChild(r), this.panel.appendChild(this.footer), this.shadow.appendChild(this.panel), this.shadow.addEventListener("click", (e) => {
|
|
2608
|
+
if (!this.countryOpen) return;
|
|
2609
|
+
let t = e.target;
|
|
2610
|
+
t && (this.dialBtn.contains(t) || this.countryPopover.contains(t)) || this.closeCountryPopover();
|
|
2611
|
+
}), this.attachToDocument(), this.showInitialLoading(), e.autoOpen && this.open();
|
|
2612
|
+
}
|
|
2613
|
+
buildHeader(e) {
|
|
2614
|
+
let t = document.createElement("div");
|
|
2615
|
+
t.className = "ttcb-header";
|
|
2616
|
+
let n = document.createElement("div");
|
|
2617
|
+
n.className = "ttcb-avatar-wrap";
|
|
2618
|
+
let r = document.createElement("div");
|
|
2619
|
+
r.className = "ttcb-avatar", r.innerHTML = Z(), n.appendChild(r);
|
|
2620
|
+
let i = document.createElement("div");
|
|
2621
|
+
i.className = "ttcb-header-main";
|
|
2622
|
+
let a = document.createElement("div");
|
|
2623
|
+
a.className = "ttcb-header-title-row", this.headerTitle = document.createElement("span"), this.headerTitle.className = "ttcb-header-title", this.headerTitle.textContent = e.chatbotName ?? "AI Assistant";
|
|
2624
|
+
let o = document.createElement("span");
|
|
2625
|
+
o.className = "ttcb-verified", o.setAttribute("aria-label", "Verified"), o.innerHTML = Et(), a.appendChild(this.headerTitle), a.appendChild(o);
|
|
2626
|
+
let s = document.createElement("div");
|
|
2627
|
+
s.className = "ttcb-header-meta";
|
|
2628
|
+
let c = document.createElement("span");
|
|
2629
|
+
c.className = "ttcb-meta-online", c.textContent = "Online";
|
|
2630
|
+
let l = document.createElement("span");
|
|
2631
|
+
l.className = "ttcb-meta-sep", l.setAttribute("aria-hidden", "true");
|
|
2632
|
+
let u = document.createElement("span");
|
|
2633
|
+
u.className = "ttcb-meta-replies", u.innerHTML = `${Dt()}<span>Replies instantly</span>`, s.appendChild(c), s.appendChild(l), s.appendChild(u), i.appendChild(a), i.appendChild(s);
|
|
2634
|
+
let d = document.createElement("div");
|
|
2635
|
+
d.className = "ttcb-header-actions", this.requestHumanBtn = document.createElement("button"), this.requestHumanBtn.type = "button", this.requestHumanBtn.className = "ttcb-request-human-btn hidden", this.requestHumanBtn.id = "ttcb-request-human-btn", this.requestHumanBtn.setAttribute("aria-label", "Request human agent"), this.requestHumanBtn.title = "Request human agent", this.requestHumanBtn.innerHTML = Ot(), this.requestHumanBtn.addEventListener("click", () => this.callbacks.onRequestHuman()), this.newSessionBtn = document.createElement("button"), this.newSessionBtn.className = "ttcb-new-session-btn hidden", this.newSessionBtn.setAttribute("aria-label", "New conversation"), this.newSessionBtn.title = "New conversation", this.newSessionBtn.innerHTML = gt(), this.newSessionBtn.addEventListener("click", () => this.callbacks.onReset());
|
|
2636
|
+
let f = document.createElement("button");
|
|
2637
|
+
return f.className = "ttcb-close-btn", f.setAttribute("aria-label", "Close chat"), f.innerHTML = vt(), f.addEventListener("click", () => this.close()), d.appendChild(this.requestHumanBtn), d.appendChild(this.newSessionBtn), d.appendChild(f), t.appendChild(n), t.appendChild(i), t.appendChild(d), t;
|
|
2638
|
+
}
|
|
2639
|
+
setPanelMode(e) {
|
|
2640
|
+
this.panel.classList.remove("ttcb-mode-form", "ttcb-mode-chat", "ttcb-mode-compact"), this.panel.classList.add(`ttcb-mode-${e}`), e !== "chat" && (this.requestHumanBtn.classList.add("hidden"), this.newSessionBtn.classList.add("hidden"), this.hideModeBanner());
|
|
2641
|
+
}
|
|
2642
|
+
buildIdentifyForm(e) {
|
|
2643
|
+
let t = document.createElement("form");
|
|
2644
|
+
t.className = "ttcb-identify-form", t.addEventListener("submit", (e) => {
|
|
2645
|
+
e.preventDefault(), this.handleIdentifySubmit();
|
|
2646
|
+
}), this.nameInput = this.createIconField(t, {
|
|
2647
|
+
id: "name",
|
|
2648
|
+
label: "Name",
|
|
2649
|
+
required: !0,
|
|
2650
|
+
hint: "Required",
|
|
2651
|
+
placeholder: "Your name",
|
|
2652
|
+
type: "text",
|
|
2653
|
+
autocomplete: "name",
|
|
2654
|
+
icon: xt()
|
|
2655
|
+
}), this.createPhoneField(t), this.emailInput = this.createIconField(t, {
|
|
2656
|
+
id: "email",
|
|
2657
|
+
label: "Email (optional)",
|
|
2658
|
+
required: !1,
|
|
2659
|
+
hint: "For chat transcript",
|
|
2660
|
+
placeholder: "Email (optional)",
|
|
2661
|
+
type: "email",
|
|
2662
|
+
autocomplete: "email",
|
|
2663
|
+
icon: St()
|
|
2664
|
+
}), this.identifyError = document.createElement("p"), this.identifyError.className = "ttcb-identify-error", t.appendChild(this.identifyError), this.identifySubmit = document.createElement("button"), this.identifySubmit.type = "submit", this.identifySubmit.className = "ttcb-identify-submit", this.identifySubmit.innerHTML = `<span>Start Chatting</span>${wt()}`, t.appendChild(this.identifySubmit), e.appendChild(t);
|
|
2665
|
+
let n = document.createElement("div");
|
|
2666
|
+
n.className = "ttcb-trust", n.innerHTML = `${Tt()}<span>Encrypted connection • No spam, ever</span>`, e.appendChild(n);
|
|
2667
|
+
}
|
|
2668
|
+
createIconField(e, t) {
|
|
2669
|
+
let n = document.createElement("div");
|
|
2670
|
+
n.className = "ttcb-field";
|
|
2671
|
+
let r = document.createElement("div");
|
|
2672
|
+
r.className = "ttcb-field-label-row";
|
|
2673
|
+
let i = document.createElement("label");
|
|
2674
|
+
i.className = "ttcb-label", i.htmlFor = `ttcb-${t.id}`, t.required ? i.innerHTML = `${t.label.replace(" (optional)", "")} <span class="ttcb-req">*</span>` : i.textContent = t.label;
|
|
2675
|
+
let a = document.createElement("span");
|
|
2676
|
+
a.className = "ttcb-field-hint", a.textContent = t.hint, r.appendChild(i), r.appendChild(a);
|
|
2677
|
+
let o = document.createElement("div");
|
|
2678
|
+
o.className = "ttcb-input-wrap";
|
|
2679
|
+
let s = document.createElement("span");
|
|
2680
|
+
s.className = "ttcb-input-icon", s.setAttribute("aria-hidden", "true"), s.innerHTML = t.icon;
|
|
2681
|
+
let c = document.createElement("input");
|
|
2682
|
+
return c.id = `ttcb-${t.id}`, c.name = t.id, c.type = t.type, c.className = "ttcb-identify-input", c.placeholder = t.placeholder, c.required = t.required, c.autocomplete = t.autocomplete, o.appendChild(s), o.appendChild(c), n.appendChild(r), n.appendChild(o), e.appendChild(n), c;
|
|
2683
|
+
}
|
|
2684
|
+
createPhoneField(e) {
|
|
2685
|
+
let t = document.createElement("div");
|
|
2686
|
+
t.className = "ttcb-field";
|
|
2687
|
+
let n = document.createElement("div");
|
|
2688
|
+
n.className = "ttcb-field-label-row";
|
|
2689
|
+
let r = document.createElement("label");
|
|
2690
|
+
r.className = "ttcb-label", r.htmlFor = "ttcb-tel", r.innerHTML = "Phone <span class=\"ttcb-req\">*</span>";
|
|
2691
|
+
let i = document.createElement("span");
|
|
2692
|
+
i.className = "ttcb-field-hint", i.textContent = "SMS / WhatsApp sync", n.appendChild(r), n.appendChild(i);
|
|
2693
|
+
let a = document.createElement("div");
|
|
2694
|
+
a.className = "ttcb-phone-row", a.id = "ttcb-phone-row", this.dialBtn = document.createElement("button"), this.dialBtn.type = "button", this.dialBtn.className = "ttcb-dial-btn", this.dialBtn.setAttribute("aria-label", "Select country code"), this.dialBtn.setAttribute("aria-haspopup", "listbox"), this.dialBtn.setAttribute("aria-expanded", "false"), this.dialFlag = document.createElement("span"), this.dialFlag.className = "ttcb-dial-flag", this.dialCode = document.createElement("span"), this.dialCode.className = "ttcb-dial-code", this.syncDialButton(), this.dialBtn.appendChild(this.dialFlag), this.dialBtn.appendChild(this.dialCode);
|
|
2695
|
+
let o = document.createElement("span");
|
|
2696
|
+
o.setAttribute("aria-hidden", "true"), o.innerHTML = Ct(), this.dialBtn.appendChild(o), this.dialBtn.addEventListener("click", (e) => {
|
|
2697
|
+
e.preventDefault(), e.stopPropagation(), this.toggleCountryPopover();
|
|
2698
|
+
}), this.phoneInput = document.createElement("input"), this.phoneInput.id = "ttcb-tel", this.phoneInput.name = "tel", this.phoneInput.type = "tel", this.phoneInput.className = "ttcb-phone-national", this.phoneInput.placeholder = "1712-345678", this.phoneInput.required = !0, this.phoneInput.autocomplete = "tel-national", this.phoneInput.setAttribute("inputmode", "tel"), a.appendChild(this.dialBtn), a.appendChild(this.phoneInput), this.countryPopover = document.createElement("div"), this.countryPopover.className = "ttcb-country-popover", this.countryPopover.setAttribute("role", "listbox"), this.countrySearch = document.createElement("input"), this.countrySearch.type = "search", this.countrySearch.className = "ttcb-country-search", this.countrySearch.placeholder = "Search country…", this.countrySearch.setAttribute("aria-label", "Search countries"), this.countrySearch.addEventListener("input", () => this.renderCountryList()), this.countryList = document.createElement("div"), this.countryList.className = "ttcb-country-list", this.countryPopover.appendChild(this.countrySearch), this.countryPopover.appendChild(this.countryList), this.renderCountryList(), t.appendChild(n), t.appendChild(a), t.appendChild(this.countryPopover), e.appendChild(t);
|
|
2699
|
+
}
|
|
2700
|
+
syncDialButton() {
|
|
2701
|
+
this.dialFlag.textContent = this.selectedCountry.flag, this.dialCode.textContent = `+${this.selectedCountry.dial}`;
|
|
2702
|
+
}
|
|
2703
|
+
toggleCountryPopover() {
|
|
2704
|
+
this.countryOpen ? this.closeCountryPopover() : this.openCountryPopover();
|
|
2705
|
+
}
|
|
2706
|
+
openCountryPopover() {
|
|
2707
|
+
this.countryOpen = !0, this.countryPopover.classList.add("open"), this.dialBtn.setAttribute("aria-expanded", "true"), this.countrySearch.value = "", this.renderCountryList(), queueMicrotask(() => this.countrySearch.focus());
|
|
2708
|
+
}
|
|
2709
|
+
closeCountryPopover() {
|
|
2710
|
+
this.countryOpen = !1, this.countryPopover.classList.remove("open"), this.dialBtn.setAttribute("aria-expanded", "false");
|
|
2711
|
+
}
|
|
2712
|
+
renderCountryList() {
|
|
2713
|
+
let e = this.countrySearch.value.trim().toLowerCase(), t = Y.filter((t) => !e || t.name.toLowerCase().includes(e) || t.dial.includes(e) || t.iso.toLowerCase().includes(e) || `+${t.dial}`.includes(e));
|
|
2714
|
+
this.countryList.innerHTML = "";
|
|
2715
|
+
for (let e of t) {
|
|
2716
|
+
let t = document.createElement("button");
|
|
2717
|
+
t.type = "button", t.className = "ttcb-country-item", t.setAttribute("role", "option"), t.setAttribute("aria-selected", e.iso === this.selectedCountry.iso ? "true" : "false"), t.innerHTML = `
|
|
2718
|
+
<span class="ttcb-dial-flag">${e.flag}</span>
|
|
2719
|
+
<span class="ttcb-country-item-name">${e.name}</span>
|
|
2720
|
+
<span class="ttcb-country-item-dial">+${e.dial}</span>
|
|
2721
|
+
`, t.addEventListener("click", () => {
|
|
2722
|
+
this.selectedCountry = e, this.syncDialButton(), this.closeCountryPopover(), this.phoneInput.focus();
|
|
2723
|
+
}), this.countryList.appendChild(t);
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
attachToDocument() {
|
|
2727
|
+
let e = () => {
|
|
2728
|
+
this.destroyed || (document.body ?? document.documentElement).appendChild(this.host);
|
|
2729
|
+
};
|
|
2730
|
+
document.body ? e() : document.addEventListener("DOMContentLoaded", e, { once: !0 });
|
|
2731
|
+
}
|
|
2732
|
+
showInitialLoading() {
|
|
2733
|
+
this.setPanelMode("compact"), this.identifyContainer.classList.remove("visible"), this.messagesContainer.classList.remove("hidden"), this.footer.classList.add("hidden"), this.messagesContainer.innerHTML = "", this.input.disabled = !0, this.sendBtn.disabled = !0;
|
|
2734
|
+
let e = document.createElement("div");
|
|
2735
|
+
e.className = "ttcb-initial-loading", e.id = "ttcb-initial-loading";
|
|
2736
|
+
let t = document.createElement("div");
|
|
2737
|
+
t.className = "ttcb-spinner";
|
|
2738
|
+
let n = document.createElement("p");
|
|
2739
|
+
n.textContent = "Loading…", e.appendChild(t), e.appendChild(n), this.messagesContainer.appendChild(e);
|
|
2740
|
+
}
|
|
2741
|
+
showEmptyState(e) {
|
|
2742
|
+
let t = document.createElement("div");
|
|
2743
|
+
t.className = "ttcb-empty", t.id = "ttcb-empty";
|
|
2744
|
+
let n = document.createElement("div");
|
|
2745
|
+
n.className = "ttcb-empty-icon", n.innerHTML = Z();
|
|
2746
|
+
let r = document.createElement("p"), i = document.createElement("strong");
|
|
2747
|
+
i.textContent = e, r.appendChild(document.createTextNode("Welcome to ")), r.appendChild(i);
|
|
2748
|
+
let a = document.createElement("p");
|
|
2749
|
+
a.textContent = "Ask me anything — I'm here to help!", a.style.marginTop = "6px", a.style.fontSize = "12px", t.appendChild(n), t.appendChild(r), t.appendChild(a), this.messagesContainer.appendChild(t);
|
|
2750
|
+
}
|
|
2751
|
+
removeEmptyState() {
|
|
2752
|
+
let e = this.shadow.getElementById("ttcb-empty");
|
|
2753
|
+
e && e.remove();
|
|
2754
|
+
}
|
|
2755
|
+
handleSend() {
|
|
2756
|
+
let e = this.input.value.trim();
|
|
2757
|
+
e && !this.sendBtn.disabled && (this.input.value = "", this.callbacks.onSend(e), this.input.focus());
|
|
2758
|
+
}
|
|
2759
|
+
handleIdentifySubmit() {
|
|
2760
|
+
let e = this.nameInput.value.trim(), t = dt(this.selectedCountry.dial, this.phoneInput.value), n = this.emailInput.value.trim();
|
|
2761
|
+
!e || !t ? this.showIdentifyError("Name and phone are required.") : (this.showIdentifyError(""), this.callbacks.onIdentify({
|
|
2762
|
+
name: e,
|
|
2763
|
+
phone: t,
|
|
2764
|
+
...n ? { email: n } : {}
|
|
2765
|
+
}));
|
|
2766
|
+
}
|
|
2767
|
+
appendMessage(e) {
|
|
2768
|
+
this.removeEmptyState();
|
|
2769
|
+
let t = "message" in e ? e.message : e, n = kt(t.content, t.type);
|
|
2770
|
+
this.messagesContainer.appendChild(n), this.scrollToBottom();
|
|
2771
|
+
}
|
|
2772
|
+
setMessages(e) {
|
|
2773
|
+
if (this.messagesContainer.innerHTML = "", e.length !== 0) {
|
|
2774
|
+
for (let t of e) {
|
|
2775
|
+
let e = kt(t.message.content, t.message.type);
|
|
2776
|
+
this.messagesContainer.appendChild(e);
|
|
2777
|
+
}
|
|
2778
|
+
this.scrollToBottom();
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
setLoading(e) {
|
|
2782
|
+
if (this.sendBtn.disabled = e || this.input.disabled, e) this.shadow.getElementById("ttcb-typing") || (this.messagesContainer.appendChild(At()), this.scrollToBottom()), this.input.focus();
|
|
2783
|
+
else {
|
|
2784
|
+
let e = this.shadow.getElementById("ttcb-typing");
|
|
2785
|
+
e && e.remove(), this.input.disabled || this.input.focus();
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
setIdentifyLoading(e) {
|
|
2789
|
+
this.identifySubmit.disabled = e, this.nameInput.disabled = e, this.phoneInput.disabled = e, this.emailInput.disabled = e, this.dialBtn.disabled = e, this.shadow.getElementById("ttcb-phone-row")?.classList.toggle("disabled", e);
|
|
2790
|
+
for (let t of this.identifyContainer.querySelectorAll(".ttcb-input-wrap")) t.classList.toggle("disabled", e);
|
|
2791
|
+
this.identifySubmit.innerHTML = e ? "<span>Starting…</span>" : `<span>Start Chatting</span>${wt()}`, e && this.closeCountryPopover();
|
|
2792
|
+
}
|
|
2793
|
+
showIdentifyError(e) {
|
|
2794
|
+
this.identifyError.textContent = e;
|
|
2795
|
+
}
|
|
2796
|
+
open() {
|
|
2797
|
+
this.isOpen = !0, this.panel.classList.remove("hidden"), this.identifyContainer.classList.contains("visible") ? this.nameInput.focus() : this.input.focus(), this.callbacks.onOpen();
|
|
2798
|
+
}
|
|
2799
|
+
close() {
|
|
2800
|
+
this.isOpen = !1, this.closeCountryPopover(), this.panel.classList.add("hidden"), this.callbacks.onClose();
|
|
2801
|
+
}
|
|
2802
|
+
toggle() {
|
|
2803
|
+
this.isOpen ? this.close() : this.open();
|
|
2804
|
+
}
|
|
2805
|
+
showIdentifyForm(e) {
|
|
2806
|
+
this.setPanelMode("form"), e.chatbotName && (this.headerTitle.textContent = e.chatbotName), this.messagesContainer.classList.add("hidden"), this.footer.classList.add("hidden"), this.identifyContainer.classList.add("visible"), this.showIdentifyError(""), this.setIdentifyLoading(!1);
|
|
2807
|
+
}
|
|
2808
|
+
readyToChat(e) {
|
|
2809
|
+
this.setPanelMode("chat"), this.closeCountryPopover(), this.identifyContainer.classList.remove("visible"), this.messagesContainer.classList.remove("hidden"), this.footer.classList.remove("hidden"), this.messagesContainer.innerHTML = "", e.chatbotName && (this.headerTitle.textContent = e.chatbotName), e.welcomeMessage ? this.appendMessage({
|
|
2810
|
+
type: "ai",
|
|
2811
|
+
content: e.welcomeMessage
|
|
2812
|
+
}) : this.showEmptyState(e.chatbotName ?? "AI Assistant"), this.setMode("ai");
|
|
2813
|
+
}
|
|
2814
|
+
showBlocked(e, t) {
|
|
2815
|
+
this.setPanelMode("compact"), this.closeCountryPopover(), this.identifyContainer.classList.remove("visible"), this.messagesContainer.classList.remove("hidden"), this.footer.classList.add("hidden"), this.messagesContainer.innerHTML = "";
|
|
2816
|
+
let n = document.createElement("div");
|
|
2817
|
+
n.className = "ttcb-blocked";
|
|
2818
|
+
let r = document.createElement("div");
|
|
2819
|
+
r.className = "ttcb-blocked-icon";
|
|
2820
|
+
let i = document.createElement("p");
|
|
2821
|
+
i.className = "ttcb-blocked-title";
|
|
2822
|
+
let a = document.createElement("p");
|
|
2823
|
+
a.className = "ttcb-blocked-desc", e === "no-prompt" ? (r.innerHTML = ht(), i.textContent = "Business Context Required", a.textContent = t ?? "Add a system prompt for this agent in the admin panel.") : e === "no-agent" ? (r.innerHTML = mt(), i.textContent = "Channel Not Connected", a.textContent = t ?? "Connect this Website channel under AI Agents → Connected Channels.") : e === "no-directories" || e === "no-collections" ? (r.innerHTML = ht(), i.textContent = "Knowledge Base Required", a.textContent = t ?? "Assign at least one knowledge-base collection to this agent in the admin panel.") : (r.innerHTML = mt(), i.textContent = "Chatbot Settings Required", a.textContent = t ?? "The chatbot has not been configured yet. Please set it up in the admin panel."), n.appendChild(r), n.appendChild(i), n.appendChild(a), this.messagesContainer.appendChild(n);
|
|
2824
|
+
}
|
|
2825
|
+
clearMessages(e) {
|
|
2826
|
+
this.messagesContainer.innerHTML = "", this.showEmptyState(e);
|
|
2827
|
+
}
|
|
2828
|
+
setMode(e, t) {
|
|
2829
|
+
let n = this.panel.classList.contains("ttcb-mode-chat"), r = t?.agentName, i = t?.canRequestHuman === !0, a = n && i, o = n && e === "closed", s = e === "closed";
|
|
2830
|
+
this.requestHumanBtn.classList.toggle("hidden", !a), this.newSessionBtn.classList.toggle("hidden", !o), this.input.disabled = s, s ? this.sendBtn.disabled = !0 : this.shadow.getElementById("ttcb-typing") || (this.sendBtn.disabled = !1), n ? e === "waiting" ? this.showModeBanner("Waiting for a human agent…", "waiting") : e === "closed" ? this.showModeBanner("This conversation is closed", "closed") : e === "human" && r?.trim() ? this.showModeBanner(`Connected with ${r.trim()}`, "human") : this.hideModeBanner() : this.hideModeBanner();
|
|
2831
|
+
}
|
|
2832
|
+
showModeBanner(e, t) {
|
|
2833
|
+
this.modeBanner.textContent = e, this.modeBanner.className = `ttcb-mode-banner visible ${t}`;
|
|
2834
|
+
}
|
|
2835
|
+
hideModeBanner() {
|
|
2836
|
+
this.modeBanner.textContent = "", this.modeBanner.className = "ttcb-mode-banner";
|
|
2837
|
+
}
|
|
2838
|
+
destroy() {
|
|
2839
|
+
this.destroyed = !0, this.host.remove();
|
|
2840
|
+
}
|
|
2841
|
+
scrollToBottom() {
|
|
2842
|
+
this.messagesContainer.scrollTop = this.messagesContainer.scrollHeight;
|
|
2843
|
+
}
|
|
2844
|
+
}, Mt = {
|
|
2845
|
+
apiBaseUrl: o,
|
|
2846
|
+
chatbotName: "AI Assistant",
|
|
2847
|
+
primaryColor: "#2563EB",
|
|
2848
|
+
theme: "auto",
|
|
2849
|
+
position: "bottom-right",
|
|
2850
|
+
welcomeMessage: "",
|
|
2851
|
+
placeholder: "Type your message…",
|
|
2852
|
+
autoOpen: !1,
|
|
2853
|
+
sessionId: "",
|
|
2854
|
+
requestTimeoutMs: n
|
|
773
2855
|
};
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
2856
|
+
function Nt(e) {
|
|
2857
|
+
return Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0));
|
|
2858
|
+
}
|
|
2859
|
+
var Pt = 0, Q = () => Date.now() * 1e3 + Pt++ % 1e3;
|
|
2860
|
+
function Ft(e) {
|
|
2861
|
+
if (!e || typeof e != "object") return null;
|
|
2862
|
+
let t = e;
|
|
2863
|
+
if (typeof t.textMessage == "string" && t.textMessage.trim()) return t.textMessage.trim();
|
|
2864
|
+
if (typeof t.content == "string" && t.content.trim()) return t.content.trim();
|
|
2865
|
+
if (t.message && typeof t.message == "object") {
|
|
2866
|
+
let e = t.message;
|
|
2867
|
+
if (typeof e.content == "string" && e.content.trim()) return e.content.trim();
|
|
2868
|
+
if (typeof e.textMessage == "string" && e.textMessage.trim()) return e.textMessage.trim();
|
|
2869
|
+
}
|
|
2870
|
+
return null;
|
|
2871
|
+
}
|
|
2872
|
+
function It(e) {
|
|
2873
|
+
if (!e || typeof e != "object") return null;
|
|
2874
|
+
let t = e;
|
|
2875
|
+
if (typeof t.id == "string" && t.id) return t.id;
|
|
2876
|
+
if (t.message && typeof t.message == "object") {
|
|
2877
|
+
let e = t.message;
|
|
2878
|
+
if (typeof e.id == "string" && e.id) return e.id;
|
|
2879
|
+
}
|
|
2880
|
+
return null;
|
|
2881
|
+
}
|
|
2882
|
+
var Lt = class {
|
|
2883
|
+
constructor() {
|
|
2884
|
+
this.emitter = new s(), this.visitorTokens = new lt(), this.widget = null, this.sdkSocket = null, this.callerSetName = !1, this.hasActiveTicket = !1, this.lastPushId = null, this.initToken = 0, this._state = {
|
|
2885
|
+
isOpen: !1,
|
|
2886
|
+
isLoading: !1,
|
|
2887
|
+
isReady: !1,
|
|
2888
|
+
needsIdentify: !0,
|
|
2889
|
+
blockReason: null,
|
|
2890
|
+
messages: [],
|
|
2891
|
+
visitorToken: null,
|
|
2892
|
+
visitorName: null,
|
|
2893
|
+
error: null,
|
|
2894
|
+
mode: "ai"
|
|
2895
|
+
};
|
|
2896
|
+
}
|
|
2897
|
+
setState(e) {
|
|
2898
|
+
this._state = {
|
|
2899
|
+
...this._state,
|
|
2900
|
+
...e
|
|
2901
|
+
}, this.emitter.emit("state-change", this._state);
|
|
2902
|
+
}
|
|
2903
|
+
applyMode(e, t) {
|
|
2904
|
+
t ? this.syncHasActiveTicket(t) : e !== "ai" && (this.hasActiveTicket = !0), this.setState({ mode: e }), this.syncWidgetMode(e, t?.agentName), t && this.emitter.emit("ticket-status", t);
|
|
2905
|
+
}
|
|
2906
|
+
syncHasActiveTicket(e) {
|
|
2907
|
+
this.hasActiveTicket = !!(e.conversationId || e.mode !== "ai");
|
|
2908
|
+
}
|
|
2909
|
+
syncWidgetMode(e, t) {
|
|
2910
|
+
this.widget?.setMode(e, {
|
|
2911
|
+
agentName: t,
|
|
2912
|
+
canRequestHuman: e === "ai" && this.hasActiveTicket
|
|
2913
|
+
});
|
|
2914
|
+
}
|
|
2915
|
+
async init(e) {
|
|
2916
|
+
if (!e.apiKey) throw Error("[onedeskpro-chatbot] `apiKey` is required to initialise the chatbot.");
|
|
2917
|
+
let t = ++this.initToken;
|
|
2918
|
+
this.disconnectSdkSocket(), this.widget?.destroy(), this.widget = null, this.callerSetName = e.chatbotName !== void 0, this.options = {
|
|
2919
|
+
...Mt,
|
|
2920
|
+
...Nt(e)
|
|
2921
|
+
}, this.apiClient = new a({
|
|
2922
|
+
baseUrl: this.options.apiBaseUrl,
|
|
2923
|
+
apiKey: this.options.apiKey,
|
|
2924
|
+
timeoutMs: this.options.requestTimeoutMs
|
|
2925
|
+
}), this.hasActiveTicket = !1, this.setState({
|
|
2926
|
+
visitorToken: null,
|
|
2927
|
+
visitorName: null,
|
|
2928
|
+
needsIdentify: !0,
|
|
2929
|
+
messages: [],
|
|
2930
|
+
error: null,
|
|
2931
|
+
mode: "ai"
|
|
2932
|
+
}), typeof window < "u" && typeof document < "u" && (this.widget = new jt(this.options, {
|
|
2933
|
+
onSend: (e) => void this.sendMessage(e),
|
|
2934
|
+
onIdentify: (e) => void this.submitIdentify(e),
|
|
2935
|
+
onOpen: () => {
|
|
2936
|
+
this.setState({ isOpen: !0 }), this.emitter.emit("open");
|
|
2937
|
+
},
|
|
2938
|
+
onClose: () => {
|
|
2939
|
+
this.setState({ isOpen: !1 }), this.emitter.emit("close");
|
|
2940
|
+
},
|
|
2941
|
+
onReset: () => this.resetSession(),
|
|
2942
|
+
onRequestHuman: () => void this.requestHuman()
|
|
2943
|
+
}));
|
|
2944
|
+
let n = null, r = null;
|
|
2945
|
+
try {
|
|
2946
|
+
n = await this.apiClient.fetchConfig();
|
|
2947
|
+
} catch (e) {
|
|
2948
|
+
r = e;
|
|
2949
|
+
}
|
|
2950
|
+
if (t !== this.initToken) return;
|
|
2951
|
+
if (r) {
|
|
2952
|
+
this.handleConfigError(r), this.emitter.emit("ready");
|
|
2953
|
+
return;
|
|
2954
|
+
}
|
|
2955
|
+
if (!n) {
|
|
2956
|
+
this.emitter.emit("ready");
|
|
2957
|
+
return;
|
|
2958
|
+
}
|
|
2959
|
+
!this.callerSetName && n.agentName.trim() && (this.options.chatbotName = n.agentName);
|
|
2960
|
+
let i = n.blockReason ?? null;
|
|
2961
|
+
if (this.setState({
|
|
2962
|
+
blockReason: i,
|
|
2963
|
+
isReady: i === null,
|
|
2964
|
+
error: null
|
|
2965
|
+
}), i) this.widget?.showBlocked(i);
|
|
2966
|
+
else if (this.visitorTokens.setScope(n.agentId), await this.resolveVisitorGate(t), t !== this.initToken) return;
|
|
2967
|
+
this.emitter.emit("ready");
|
|
2968
|
+
}
|
|
2969
|
+
handleConfigError(e) {
|
|
2970
|
+
let t = i(e) ? e : null, n = t?.apiError.message ?? (e instanceof Error ? e.message : "Failed to load chatbot config."), r = t?.apiError.code, a = t?.status;
|
|
2971
|
+
r === "agent_not_assigned" ? (this.setState({
|
|
2972
|
+
isReady: !1,
|
|
2973
|
+
blockReason: "no-agent",
|
|
2974
|
+
error: n
|
|
2975
|
+
}), this.widget?.showBlocked("no-agent")) : a === 403 ? (this.setState({
|
|
2976
|
+
isReady: !1,
|
|
2977
|
+
blockReason: null,
|
|
2978
|
+
error: n
|
|
2979
|
+
}), this.widget?.showBlocked(null, n)) : this.setState({
|
|
2980
|
+
isReady: !1,
|
|
2981
|
+
blockReason: null,
|
|
2982
|
+
error: n
|
|
2983
|
+
});
|
|
2984
|
+
}
|
|
2985
|
+
async resolveVisitorGate(e) {
|
|
2986
|
+
let t = this.visitorTokens.get();
|
|
2987
|
+
if (t) {
|
|
2988
|
+
try {
|
|
2989
|
+
let n = await this.apiClient.verifyVisitor(t);
|
|
2990
|
+
if (e !== this.initToken) return;
|
|
2991
|
+
if (n.valid) {
|
|
2992
|
+
await this.enterChat(t, n.name, e);
|
|
2993
|
+
return;
|
|
2994
|
+
}
|
|
2995
|
+
} catch {}
|
|
2996
|
+
this.visitorTokens.clear();
|
|
2997
|
+
}
|
|
2998
|
+
this.setState({
|
|
2999
|
+
needsIdentify: !0,
|
|
3000
|
+
visitorToken: null,
|
|
3001
|
+
visitorName: null
|
|
3002
|
+
}), this.widget?.showIdentifyForm(this.options);
|
|
3003
|
+
}
|
|
3004
|
+
async enterChat(e, t, n = this.initToken) {
|
|
3005
|
+
this.visitorTokens.set(e), this.setState({
|
|
3006
|
+
visitorToken: e,
|
|
3007
|
+
visitorName: t,
|
|
3008
|
+
needsIdentify: !1,
|
|
3009
|
+
messages: [],
|
|
3010
|
+
error: null
|
|
3011
|
+
}), this.widget?.readyToChat(this.options), this.connectSdkSocket(e), await this.restoreTicketStatus(e, n);
|
|
3012
|
+
}
|
|
3013
|
+
connectSdkSocket(e) {
|
|
3014
|
+
this.sdkSocket ||= new at(), this.sdkSocket.connect({
|
|
3015
|
+
baseUrl: this.options.apiBaseUrl,
|
|
3016
|
+
apiKey: this.options.apiKey,
|
|
3017
|
+
visitorToken: e,
|
|
3018
|
+
onTicketStatus: (e) => this.handleTicketStatus(e),
|
|
3019
|
+
onMessageReceive: (e) => this.handleMessageReceive(e),
|
|
3020
|
+
onReconnect: () => {
|
|
3021
|
+
let e = this.visitorTokens.get() ?? this._state.visitorToken;
|
|
3022
|
+
e && this.restoreTicketStatus(e, this.initToken);
|
|
3023
|
+
},
|
|
3024
|
+
onConnectError: (e) => {
|
|
3025
|
+
this.emitter.emit("error", e);
|
|
3026
|
+
}
|
|
3027
|
+
});
|
|
3028
|
+
}
|
|
3029
|
+
disconnectSdkSocket() {
|
|
3030
|
+
this.sdkSocket?.disconnect(), this.sdkSocket = null;
|
|
3031
|
+
}
|
|
3032
|
+
async restoreTicketStatus(e, t) {
|
|
3033
|
+
try {
|
|
3034
|
+
let n = await this.apiClient.fetchTicketStatus(e);
|
|
3035
|
+
if (t !== this.initToken) return;
|
|
3036
|
+
this.applyMode(n.mode, n);
|
|
3037
|
+
} catch {}
|
|
3038
|
+
}
|
|
3039
|
+
handleTicketStatus(e) {
|
|
3040
|
+
e?.mode && this.applyMode(e.mode, e);
|
|
3041
|
+
}
|
|
3042
|
+
handleMessageReceive(e) {
|
|
3043
|
+
if (this._state.mode === "ai") return;
|
|
3044
|
+
let t = Ft(e);
|
|
3045
|
+
if (!t) return;
|
|
3046
|
+
let n = It(e), r = this._state.messages[this._state.messages.length - 1];
|
|
3047
|
+
if (r?.message.content === t && (r.message.type === "ai" || r.message.type === "agent" && (!n || n === this.lastPushId))) return;
|
|
3048
|
+
this.lastPushId = n;
|
|
3049
|
+
let i = this.visitorTokens.get() ?? this._state.visitorToken ?? "", a = {
|
|
3050
|
+
id: Q(),
|
|
3051
|
+
sessionId: i,
|
|
3052
|
+
message: {
|
|
3053
|
+
type: "agent",
|
|
3054
|
+
content: t
|
|
3055
|
+
}
|
|
3056
|
+
};
|
|
3057
|
+
this.setState({ messages: [...this._state.messages, a] }), this.widget?.appendMessage(a), this.emitter.emit("message", a);
|
|
3058
|
+
}
|
|
3059
|
+
async submitIdentify(e) {
|
|
3060
|
+
if (!this.apiClient || this._state.isLoading || !this._state.isReady) return;
|
|
3061
|
+
let t = e.name.trim(), n = e.phone.trim();
|
|
3062
|
+
if (t && n) {
|
|
3063
|
+
this.setState({
|
|
3064
|
+
isLoading: !0,
|
|
3065
|
+
error: null
|
|
3066
|
+
}), this.widget?.setIdentifyLoading(!0);
|
|
3067
|
+
try {
|
|
3068
|
+
let r = await this.apiClient.identify({
|
|
3069
|
+
name: t,
|
|
3070
|
+
phone: n,
|
|
3071
|
+
...e.email?.trim() ? { email: e.email.trim() } : {}
|
|
3072
|
+
});
|
|
3073
|
+
await this.enterChat(r.visitorToken, t);
|
|
3074
|
+
} catch (e) {
|
|
3075
|
+
let t = e instanceof Error ? e : Error(String(e));
|
|
3076
|
+
this.setState({ error: t.message }), this.widget?.showIdentifyError(t.message), this.emitter.emit("error", t);
|
|
3077
|
+
} finally {
|
|
3078
|
+
this.setState({ isLoading: !1 }), this.widget?.setIdentifyLoading(!1);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
async requestHuman() {
|
|
3083
|
+
if (!this.apiClient || this._state.mode !== "ai" || !this.hasActiveTicket || this._state.isLoading) return;
|
|
3084
|
+
let e = this.visitorTokens.get() ?? this._state.visitorToken;
|
|
3085
|
+
if (!e) throw Error("[onedeskpro-chatbot] Identify before requestHuman().");
|
|
3086
|
+
this.setState({
|
|
3087
|
+
isLoading: !0,
|
|
3088
|
+
error: null
|
|
3089
|
+
});
|
|
3090
|
+
try {
|
|
3091
|
+
let t = await this.apiClient.requestHuman(e);
|
|
3092
|
+
this.applyMode(t.mode, t), this.emitter.emit("human-requested");
|
|
3093
|
+
} catch (e) {
|
|
3094
|
+
let t = e instanceof Error ? e : Error(String(e));
|
|
3095
|
+
this.setState({ error: t.message }), this.emitter.emit("error", t);
|
|
3096
|
+
} finally {
|
|
3097
|
+
this.setState({ isLoading: !1 });
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
async sendMessage(e) {
|
|
3101
|
+
let t = this.visitorTokens.get() ?? this._state.visitorToken;
|
|
3102
|
+
if (!this.apiClient || !t) throw Error("[onedeskpro-chatbot] Identify before sendMessage().");
|
|
3103
|
+
if (this._state.mode === "closed") {
|
|
3104
|
+
this.setState({ error: "Conversation is closed" });
|
|
3105
|
+
return;
|
|
3106
|
+
}
|
|
3107
|
+
let n = e.trim();
|
|
3108
|
+
if (!n || this._state.isLoading || this._state.needsIdentify) return;
|
|
3109
|
+
let r = {
|
|
3110
|
+
id: Q(),
|
|
3111
|
+
sessionId: t,
|
|
3112
|
+
message: {
|
|
3113
|
+
type: "human",
|
|
3114
|
+
content: n
|
|
3115
|
+
}
|
|
3116
|
+
}, i = this._state.mode, a = i === "ai";
|
|
3117
|
+
this.setState({
|
|
3118
|
+
messages: [...this._state.messages, r],
|
|
3119
|
+
isLoading: !0,
|
|
3120
|
+
error: null
|
|
3121
|
+
}), this.widget?.appendMessage(r), a && this.widget?.setLoading(!0), this.emitter.emit("message", r);
|
|
3122
|
+
try {
|
|
3123
|
+
let e = await this.apiClient.sendMessage({
|
|
3124
|
+
chatInput: n,
|
|
3125
|
+
visitorToken: t
|
|
3126
|
+
});
|
|
3127
|
+
this.hasActiveTicket = !0;
|
|
3128
|
+
let r = e.mode ?? i, a = [...this._state.messages], o = (e.text ?? "").trim();
|
|
3129
|
+
if (r !== i && (this.setState({ mode: r }), this.syncWidgetMode(r), this.emitter.emit("ticket-status", { mode: r })), o) {
|
|
3130
|
+
let t = a[a.length - 1];
|
|
3131
|
+
if (t?.message.type !== "agent" && t?.message.type !== "ai" || t.message.content !== o) {
|
|
3132
|
+
let t = {
|
|
3133
|
+
id: Q(),
|
|
3134
|
+
sessionId: e.sessionId,
|
|
3135
|
+
message: {
|
|
3136
|
+
type: "ai",
|
|
3137
|
+
content: o
|
|
3138
|
+
}
|
|
3139
|
+
};
|
|
3140
|
+
a.push(t), this.widget?.appendMessage(t), this.emitter.emit("message", t);
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
this.setState({
|
|
3144
|
+
messages: a,
|
|
3145
|
+
isLoading: !1,
|
|
3146
|
+
mode: r
|
|
3147
|
+
}), this.syncWidgetMode(r);
|
|
3148
|
+
} catch (e) {
|
|
3149
|
+
let t = e instanceof Error ? e : Error(String(e));
|
|
3150
|
+
this.setState({
|
|
3151
|
+
error: t.message,
|
|
3152
|
+
isLoading: !1
|
|
3153
|
+
}), this.emitter.emit("error", t);
|
|
3154
|
+
} finally {
|
|
3155
|
+
this.widget?.setLoading(!1);
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
on(e, t) {
|
|
3159
|
+
return this.emitter.on(e, t);
|
|
3160
|
+
}
|
|
3161
|
+
resetSession() {
|
|
3162
|
+
this._state.isReady && !this._state.needsIdentify && this._state.mode === "closed" && (this.hasActiveTicket = !1, this.setState({
|
|
3163
|
+
messages: [],
|
|
3164
|
+
error: null,
|
|
3165
|
+
mode: "ai"
|
|
3166
|
+
}), this.widget?.clearMessages(this.options.chatbotName), this.syncWidgetMode("ai"), this.emitter.emit("session-reset"));
|
|
3167
|
+
}
|
|
3168
|
+
open() {
|
|
3169
|
+
this.widget?.open();
|
|
3170
|
+
}
|
|
3171
|
+
close() {
|
|
3172
|
+
this.widget?.close();
|
|
3173
|
+
}
|
|
3174
|
+
toggle() {
|
|
3175
|
+
this.widget?.toggle();
|
|
3176
|
+
}
|
|
3177
|
+
getState() {
|
|
3178
|
+
return { ...this._state };
|
|
3179
|
+
}
|
|
3180
|
+
destroy() {
|
|
3181
|
+
this.initToken++, this.disconnectSdkSocket(), this.widget?.destroy(), this.widget = null, this.setState({
|
|
3182
|
+
isOpen: !1,
|
|
3183
|
+
isLoading: !1,
|
|
3184
|
+
isReady: !1,
|
|
3185
|
+
needsIdentify: !0
|
|
3186
|
+
});
|
|
3187
|
+
}
|
|
3188
|
+
}, $ = null, Rt = {
|
|
3189
|
+
async init(e) {
|
|
3190
|
+
return $ = new Lt(), await $.init(e), $;
|
|
3191
|
+
},
|
|
3192
|
+
getInstance() {
|
|
3193
|
+
return $;
|
|
3194
|
+
}
|
|
782
3195
|
};
|
|
3196
|
+
//#endregion
|
|
3197
|
+
export { a as ApiClient, Lt as ChatbotCore, o as DEFAULT_API_BASE_URL, n as DEFAULT_REQUEST_TIMEOUT_MS, s as EventEmitter, Rt as OnedeskProChatbot, at as SdkSocket, lt as SessionManager, i as isChatbotRequestError, it as resolveSdkSocketUrl };
|