@onedeskpro/chatbot-core 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var e = Object.defineProperty, t = (t, n) => {
3
3
  let r = {};
4
4
  for (var i in t) e(r, i, {
@@ -6,16 +6,21 @@ var e = Object.defineProperty, t = (t, n) => {
6
6
  enumerable: !0
7
7
  });
8
8
  return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
- }, n = 3e4;
10
- function r(e) {
9
+ }, n = 3e4, r = 12e4;
10
+ function i(e) {
11
11
  return typeof e == "object" && !!e && typeof e.message == "string";
12
12
  }
13
- function i(e) {
14
- return e instanceof Error && "apiError" in e && "status" in e && typeof e.status == "number" && r(e.apiError);
13
+ function a(e) {
14
+ if (typeof e != "object" || !e) return !1;
15
+ let t = e;
16
+ return typeof t.type == "string" && typeof t.url == "string" && typeof t.fileName == "string" && typeof t.size == "number";
17
+ }
18
+ function o(e) {
19
+ return e instanceof Error && "apiError" in e && "status" in e && typeof e.status == "number" && i(e.apiError);
15
20
  }
16
- var a = class {
21
+ var s = class {
17
22
  constructor(e) {
18
- this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.apiKey = e.apiKey, this.timeoutMs = e.timeoutMs ?? 3e4;
23
+ this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.apiKey = e.apiKey, this.timeoutMs = e.timeoutMs ?? 3e4, this.uploadTimeoutMs = e.uploadTimeoutMs ?? r;
19
24
  }
20
25
  fail(e, t, n, r) {
21
26
  let i = {
@@ -30,40 +35,40 @@ var a = class {
30
35
  status: t
31
36
  });
32
37
  }
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
+ async request(e, t, n, r, a, o = this.timeoutMs) {
39
+ let s = new URL(`${this.baseUrl}${t}`);
40
+ if (r) for (let [e, t] of Object.entries(r)) s.searchParams.set(e, t);
41
+ let c = typeof FormData < "u" && n instanceof FormData, l = {
42
+ ...c ? {} : { "Content-Type": "application/json" },
38
43
  "X-API-Key": this.apiKey,
39
44
  ...a
40
- }, c = new AbortController(), l = setTimeout(() => c.abort(), this.timeoutMs), u;
45
+ }, u = new AbortController(), d = setTimeout(() => u.abort(), o), f;
41
46
  try {
42
- u = await fetch(o.toString(), {
47
+ f = await fetch(s.toString(), {
43
48
  method: e,
44
- headers: s,
45
- signal: c.signal,
46
- ...n === void 0 ? {} : { body: JSON.stringify(n) }
49
+ headers: l,
50
+ signal: u.signal,
51
+ ...n === void 0 ? {} : { body: c ? n : JSON.stringify(n) }
47
52
  });
48
53
  } 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);
54
+ u.signal.aborted && this.fail(`Request timed out after ${o}ms.`, 0, "TIMEOUT", t), this.fail(e instanceof Error ? e.message : "Network request failed.", 0, "NETWORK_ERROR", t);
50
55
  } finally {
51
- clearTimeout(l);
56
+ clearTimeout(d);
52
57
  }
53
- let d = await u.text(), f = null;
54
- if (d) try {
55
- f = JSON.parse(d);
58
+ let p = await f.text(), m = null;
59
+ if (p) try {
60
+ m = JSON.parse(p);
56
61
  } catch {
57
- f = null;
62
+ m = null;
58
63
  }
59
- if (!u.ok) {
60
- if (r(f)) throw Object.assign(Error(f.message), {
61
- apiError: f,
62
- status: u.status
64
+ if (!f.ok) {
65
+ if (i(m)) throw Object.assign(Error(m.message), {
66
+ apiError: m,
67
+ status: f.status
63
68
  });
64
- this.fail(`Request failed with status ${u.status} ${u.statusText}`.trim(), u.status, "HTTP_ERROR", t);
69
+ this.fail(`Request failed with status ${f.status} ${f.statusText}`.trim(), f.status, "HTTP_ERROR", t);
65
70
  }
66
- return f === null && this.fail("The server returned an empty or malformed response.", u.status, "BAD_RESPONSE", t), f.data;
71
+ return m === null && this.fail("The server returned an empty or malformed response.", f.status, "BAD_RESPONSE", t), m.data;
67
72
  }
68
73
  async identify(e) {
69
74
  return this.request("POST", "/sdk/identify", e);
@@ -74,6 +79,12 @@ var a = class {
74
79
  async sendMessage(e) {
75
80
  return this.request("POST", "/sdk/chat", e);
76
81
  }
82
+ async uploadAttachment(e, t) {
83
+ let n = new FormData();
84
+ n.append("file", e, e.name);
85
+ let r = await this.request("POST", "/sdk/upload", n, void 0, { "X-Visitor-Token": t }, this.uploadTimeoutMs);
86
+ return a(r) || this.fail("The server returned an unexpected upload response.", 200, "BAD_RESPONSE", "/sdk/upload"), r;
87
+ }
77
88
  async fetchConfig() {
78
89
  return this.request("GET", "/sdk/config");
79
90
  }
@@ -83,7 +94,155 @@ var a = class {
83
94
  async fetchTicketStatus(e) {
84
95
  return this.request("GET", "/sdk/ticket-status", void 0, void 0, { "X-Visitor-Token": e });
85
96
  }
86
- }, o = "https://api.onedeskpro.com", s = class {
97
+ }, c = "https://api.onedeskpro.com", l = 10485760, u = 10;
98
+ // src/attachments.ts
99
+ function d(e) {
100
+ if (e.length > 10) return "You can send up to 10 files at a time.";
101
+ let t = e.find((e) => e.size > l);
102
+ if (t) {
103
+ let e = Math.round(l / 1048576);
104
+ return `"${t.name || "This file"}" is larger than ${e} MB.`;
105
+ }
106
+ return null;
107
+ }
108
+ function f(e) {
109
+ return /^(https?:\/\/|blob:)/i.test(e);
110
+ }
111
+ function p(e) {
112
+ return typeof URL > "u" || typeof URL.createObjectURL != "function" ? "" : URL.createObjectURL(e);
113
+ }
114
+ function m(e) {
115
+ e.startsWith("blob:") && typeof URL < "u" && typeof URL.revokeObjectURL == "function" && URL.revokeObjectURL(e);
116
+ }
117
+ function ee(e) {
118
+ return {
119
+ type: e.type || "application/octet-stream",
120
+ url: p(e),
121
+ fileName: e.name || "attachment",
122
+ size: e.size
123
+ };
124
+ }
125
+ function te(e) {
126
+ return !Number.isFinite(e) || e < 0 ? "" : e < 1024 ? `${e} B` : e < 1048576 ? `${(e / 1024).toFixed(+(e < 10240))} KB` : `${(e / 1048576).toFixed(1)} MB`;
127
+ }
128
+ function ne(e) {
129
+ if (!e || typeof e != "object") return [];
130
+ let t = e, n = t.attachments;
131
+ if (!Array.isArray(n) && t.message && typeof t.message == "object" && (n = t.message.attachments), !Array.isArray(n)) return [];
132
+ let r = [];
133
+ for (let e of n) {
134
+ if (!e || typeof e != "object") continue;
135
+ let t = e;
136
+ typeof t.url == "string" && /^https?:\/\//i.test(t.url) && r.push({
137
+ type: typeof t.type == "string" && t.type ? t.type : "application/octet-stream",
138
+ url: t.url,
139
+ fileName: typeof t.fileName == "string" && t.fileName ? t.fileName : "attachment",
140
+ size: typeof t.size == "number" && t.size >= 0 ? t.size : 0,
141
+ ...typeof t.durationSeconds == "number" ? { durationSeconds: t.durationSeconds } : {}
142
+ });
143
+ }
144
+ return r;
145
+ }
146
+ function re(e, t) {
147
+ let n = e.trim();
148
+ return n ? t.length === 0 ? !1 : t.some((e) => e.fileName === n) || /^\d+ files?$/.test(n) ? !0 : [
149
+ "Image",
150
+ "Video",
151
+ "Audio",
152
+ "Attachment"
153
+ ].includes(n) : !0;
154
+ }
155
+ // src/audio.ts
156
+ var h = 16e3;
157
+ function g(e) {
158
+ return (e ?? "").split(";")[0].trim().toLowerCase() || "audio/webm";
159
+ }
160
+ function ie(e) {
161
+ return e.includes("mpeg") || e.includes("mp3") ? "mp3" : e.includes("wav") ? "wav" : e.includes("mp4") || e.includes("m4a") ? "m4a" : e.includes("ogg") ? "ogg" : "webm";
162
+ }
163
+ function _(e) {
164
+ if (!Number.isFinite(e) || e < 0) return "0:00";
165
+ let t = Math.floor(e), n = Math.floor(t / 60), r = t % 60;
166
+ return `${n}:${String(r).padStart(2, "0")}`;
167
+ }
168
+ function ae() {
169
+ if (typeof window > "u") return null;
170
+ let e = window;
171
+ return e.AudioContext ?? e.webkitAudioContext ?? null;
172
+ }
173
+ function oe() {
174
+ if (typeof window > "u") return null;
175
+ let e = window;
176
+ return e.OfflineAudioContext ?? e.webkitOfflineAudioContext ?? null;
177
+ }
178
+ async function se(e) {
179
+ let t = ae();
180
+ if (!t) return null;
181
+ let n = new t();
182
+ try {
183
+ let t = await e.arrayBuffer();
184
+ return await n.decodeAudioData(t.slice(0));
185
+ } catch {
186
+ return null;
187
+ } finally {
188
+ await n.close().catch(() => void 0);
189
+ }
190
+ }
191
+ async function ce(e) {
192
+ let t = oe();
193
+ if (t) try {
194
+ let n = new t(1, Math.max(1, Math.ceil(e.duration * h)), h), r = n.createBufferSource();
195
+ return r.buffer = e, r.connect(n.destination), r.start(0), {
196
+ samples: (await n.startRendering()).getChannelData(0),
197
+ sampleRate: h
198
+ };
199
+ } catch {}
200
+ return {
201
+ samples: e.getChannelData(0),
202
+ sampleRate: e.sampleRate
203
+ };
204
+ }
205
+ function le(e, t) {
206
+ let n = e.length * 2, r = new ArrayBuffer(44 + n), i = new DataView(r), a = (e, t) => {
207
+ for (let n = 0; n < t.length; n++) i.setUint8(e + n, t.charCodeAt(n));
208
+ };
209
+ a(0, "RIFF"), i.setUint32(4, 36 + n, !0), a(8, "WAVE"), a(12, "fmt "), i.setUint32(16, 16, !0), i.setUint16(20, 1, !0), i.setUint16(22, 1, !0), i.setUint32(24, t, !0), i.setUint32(28, t * 2, !0), i.setUint16(32, 2, !0), i.setUint16(34, 16, !0), a(36, "data"), i.setUint32(40, n, !0);
210
+ let o = 44;
211
+ for (let t = 0; t < e.length; t++) {
212
+ let n = Math.max(-1, Math.min(1, e[t] ?? 0));
213
+ i.setInt16(o, Math.round(n < 0 ? n * 32768 : n * 32767), !0), o += 2;
214
+ }
215
+ return new Blob([r], { type: "audio/wav" });
216
+ }
217
+ function ue(e, t = 48) {
218
+ if (e.length === 0) return [];
219
+ let n = Math.max(1, Math.floor(e.length / t)), r = [], i = 0;
220
+ for (let a = 0; a < t; a++) {
221
+ let t = a * n, o = Math.min(t + n, e.length), s = 0;
222
+ for (let n = t; n < o; n++) {
223
+ let t = e[n] ?? 0;
224
+ s += t * t;
225
+ }
226
+ let c = o > t ? Math.sqrt(s / (o - t)) : 0;
227
+ r.push(c), c > i && (i = c);
228
+ }
229
+ return r.map((e) => i > 0 ? Math.max(8, Math.min(100, Math.round(e / i * 100))) : 8);
230
+ }
231
+ async function de(e) {
232
+ let t = Date.now(), n = Math.max(1, Math.round(e.durationSeconds || 1)), r = g(e.mimeType ?? e.blob.type), i = await se(e.blob);
233
+ if (!i) return {
234
+ file: new File([e.blob], `voice-message-${t}.${ie(r)}`, { type: r }),
235
+ durationSeconds: n
236
+ };
237
+ let { samples: a, sampleRate: o } = await ce(i);
238
+ return {
239
+ file: new File([le(a, o)], `voice-message-${t}.wav`, { type: "audio/wav" }),
240
+ durationSeconds: Math.max(1, Math.round(i.duration || n)),
241
+ waveform: ue(a)
242
+ };
243
+ }
244
+ // src/event-emitter.ts
245
+ var fe = class {
87
246
  constructor() {
88
247
  this._listeners = {};
89
248
  }
@@ -101,82 +260,81 @@ var a = class {
101
260
  removeAllListeners() {
102
261
  for (let e of Object.keys(this._listeners)) delete this._listeners[e];
103
262
  }
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;
263
+ }, v = Object.create(null);
264
+ v.open = "0", v.close = "1", v.ping = "2", v.pong = "3", v.message = "4", v.upgrade = "5", v.noop = "6";
265
+ var y = Object.create(null);
266
+ Object.keys(v).forEach((e) => {
267
+ y[v[e]] = e;
109
268
  });
110
- var u = {
269
+ var b = {
111
270
  type: "error",
112
271
  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) => {
272
+ }, pe = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", me = typeof ArrayBuffer == "function", he = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e && e.buffer instanceof ArrayBuffer, x = ({ type: e, data: t }, n, r) => pe && t instanceof Blob ? n ? r(t) : ge(t, r) : me && (t instanceof ArrayBuffer || he(t)) ? n ? r(t) : ge(new Blob([t]), r) : r(v[e] + (t || "")), ge = (e, t) => {
114
273
  let n = new FileReader();
115
274
  return n.onload = function() {
116
275
  let e = n.result.split(",")[1];
117
276
  t("b" + (e || ""));
118
277
  }, n.readAsDataURL(e);
119
278
  };
120
- function te(e) {
279
+ function _e(e) {
121
280
  return e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
122
281
  }
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));
282
+ var ve;
283
+ function ye(e, t) {
284
+ if (pe && e.data instanceof Blob) return e.data.arrayBuffer().then(_e).then(t);
285
+ if (me && (e.data instanceof ArrayBuffer || he(e.data))) return t(_e(e.data));
286
+ x(e, !1, (e) => {
287
+ ve ||= new TextEncoder(), t(ve.encode(e));
129
288
  });
130
289
  }
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) => {
290
+ // ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js
291
+ var be = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", S = typeof Uint8Array > "u" ? [] : /* @__PURE__ */ new Uint8Array(256);
292
+ for (let e = 0; e < 64; e++) S[be.charCodeAt(e)] = e;
293
+ var xe = (e) => {
136
294
  let t = e.length * .75, n = e.length, r, i = 0, a, o, s, c;
137
295
  e[e.length - 1] === "=" && (t--, e[e.length - 2] === "=" && t--);
138
296
  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;
297
+ for (r = 0; r < n; r += 4) a = S[e.charCodeAt(r)], o = S[e.charCodeAt(r + 1)], s = S[e.charCodeAt(r + 2)], c = S[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
298
  return l;
141
- }, ae = typeof ArrayBuffer == "function", _ = (e, t) => {
299
+ }, Se = typeof ArrayBuffer == "function", C = (e, t) => {
142
300
  if (typeof e != "string") return {
143
301
  type: "message",
144
- data: v(e, t)
302
+ data: we(e, t)
145
303
  };
146
304
  let n = e.charAt(0);
147
305
  return n === "b" ? {
148
306
  type: "message",
149
- data: oe(e.substring(1), t)
150
- } : l[n] ? e.length > 1 ? {
151
- type: l[n],
307
+ data: Ce(e.substring(1), t)
308
+ } : y[n] ? e.length > 1 ? {
309
+ type: y[n],
152
310
  data: e.substring(1)
153
- } : { type: l[n] } : u;
154
- }, oe = (e, t) => ae ? v(ie(e), t) : {
311
+ } : { type: y[n] } : b;
312
+ }, Ce = (e, t) => Se ? we(xe(e), t) : {
155
313
  base64: !0,
156
314
  data: e
157
- }, v = (e, t) => {
315
+ }, we = (e, t) => {
158
316
  switch (t) {
159
317
  case "blob": return e instanceof Blob ? e : new Blob([e]);
160
318
  default: return e instanceof ArrayBuffer ? e : e.buffer;
161
319
  }
162
- }, y = "", se = (e, t) => {
320
+ }, Te = "", Ee = (e, t) => {
163
321
  let n = e.length, r = Array(n), i = 0;
164
322
  e.forEach((e, a) => {
165
- m(e, !1, (e) => {
166
- r[a] = e, ++i === n && t(r.join(y));
323
+ x(e, !1, (e) => {
324
+ r[a] = e, ++i === n && t(r.join(Te));
167
325
  });
168
326
  });
169
- }, ce = (e, t) => {
170
- let n = e.split(y), r = [];
327
+ }, De = (e, t) => {
328
+ let n = e.split(Te), r = [];
171
329
  for (let e = 0; e < n.length; e++) {
172
- let i = _(n[e], t);
330
+ let i = C(n[e], t);
173
331
  if (r.push(i), i.type === "error") break;
174
332
  }
175
333
  return r;
176
334
  };
177
- function le() {
335
+ function Oe() {
178
336
  return new TransformStream({ transform(e, t) {
179
- ne(e, (n) => {
337
+ ye(e, (n) => {
180
338
  let r = n.length, i;
181
339
  if (r < 126) i = /* @__PURE__ */ new Uint8Array(1), new DataView(i.buffer).setUint8(0, r);
182
340
  else if (r < 65536) {
@@ -192,66 +350,65 @@ function le() {
192
350
  });
193
351
  } });
194
352
  }
195
- var ue;
196
- function b(e) {
353
+ var ke;
354
+ function w(e) {
197
355
  return e.reduce((e, t) => e + t.length, 0);
198
356
  }
199
- function x(e, t) {
357
+ function T(e, t) {
200
358
  if (e[0].length === t) return e.shift();
201
359
  let n = new Uint8Array(t), r = 0;
202
360
  for (let i = 0; i < t; i++) n[i] = e[0][r++], r === e[0].length && (e.shift(), r = 0);
203
361
  return e.length && r < e[0].length && (e[0] = e[0].slice(r)), n;
204
362
  }
205
- function de(e, t) {
206
- ue ||= new TextDecoder();
363
+ function Ae(e, t) {
364
+ ke ||= new TextDecoder();
207
365
  let n = [], r = 0, i = -1, a = !1;
208
366
  return new TransformStream({ transform(o, s) {
209
367
  for (n.push(o);;) {
210
368
  if (r === 0) {
211
- if (b(n) < 1) break;
212
- let e = x(n, 1);
369
+ if (w(n) < 1) break;
370
+ let e = T(n, 1);
213
371
  a = (e[0] & 128) == 128, i = e[0] & 127, r = i < 126 ? 3 : i === 126 ? 1 : 2;
214
372
  } else if (r === 1) {
215
- if (b(n) < 2) break;
216
- let e = x(n, 2);
373
+ if (w(n) < 2) break;
374
+ let e = T(n, 2);
217
375
  i = new DataView(e.buffer, e.byteOffset, e.length).getUint16(0), r = 3;
218
376
  } 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);
377
+ if (w(n) < 8) break;
378
+ let e = T(n, 8), t = new DataView(e.buffer, e.byteOffset, e.length), a = t.getUint32(0);
221
379
  if (a > 2 ** 21 - 1) {
222
- s.enqueue(u);
380
+ s.enqueue(b);
223
381
  break;
224
382
  }
225
383
  i = a * 2 ** 32 + t.getUint32(4), r = 3;
226
384
  } else {
227
- if (b(n) < i) break;
228
- let e = x(n, i);
229
- s.enqueue(_(a ? e : ue.decode(e), t)), r = 0;
385
+ if (w(n) < i) break;
386
+ let e = T(n, i);
387
+ s.enqueue(C(a ? e : ke.decode(e), t)), r = 0;
230
388
  }
231
389
  if (i === 0 || i > e) {
232
- s.enqueue(u);
390
+ s.enqueue(b);
233
391
  break;
234
392
  }
235
393
  }
236
394
  } });
237
395
  }
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);
396
+ // ../../node_modules/.pnpm/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/esm/index.js
397
+ function E(e) {
398
+ if (e) return je(e);
242
399
  }
243
- function fe(e) {
244
- for (var t in S.prototype) e[t] = S.prototype[t];
400
+ function je(e) {
401
+ for (var t in E.prototype) e[t] = E.prototype[t];
245
402
  return e;
246
403
  }
247
- S.prototype.on = S.prototype.addEventListener = function(e, t) {
404
+ E.prototype.on = E.prototype.addEventListener = function(e, t) {
248
405
  return this._callbacks = this._callbacks || {}, (this._callbacks["$" + e] = this._callbacks["$" + e] || []).push(t), this;
249
- }, S.prototype.once = function(e, t) {
406
+ }, E.prototype.once = function(e, t) {
250
407
  function n() {
251
408
  this.off(e, n), t.apply(this, arguments);
252
409
  }
253
410
  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) {
411
+ }, E.prototype.off = E.prototype.removeListener = E.prototype.removeAllListeners = E.prototype.removeEventListener = function(e, t) {
255
412
  if (this._callbacks = this._callbacks || {}, arguments.length == 0) return this._callbacks = {}, this;
256
413
  var n = this._callbacks["$" + e];
257
414
  if (!n) return this;
@@ -261,7 +418,7 @@ S.prototype.on = S.prototype.addEventListener = function(e, t) {
261
418
  break;
262
419
  }
263
420
  return n.length === 0 && delete this._callbacks["$" + e], this;
264
- }, S.prototype.emit = function(e) {
421
+ }, E.prototype.emit = function(e) {
265
422
  this._callbacks = this._callbacks || {};
266
423
  for (var t = Array(arguments.length - 1), n = this._callbacks["$" + e], r = 1; r < arguments.length; r++) t[r - 1] = arguments[r];
267
424
  if (n) {
@@ -269,43 +426,40 @@ S.prototype.on = S.prototype.addEventListener = function(e, t) {
269
426
  for (var r = 0, i = n.length; r < i; ++r) n[r].apply(this, t);
270
427
  }
271
428
  return this;
272
- }, S.prototype.emitReserved = S.prototype.emit, S.prototype.listeners = function(e) {
429
+ }, E.prototype.emitReserved = E.prototype.emit, E.prototype.listeners = function(e) {
273
430
  return this._callbacks = this._callbacks || {}, this._callbacks["$" + e] || [];
274
- }, S.prototype.hasListeners = function(e) {
431
+ }, E.prototype.hasListeners = function(e) {
275
432
  return !!this.listeners(e).length;
276
433
  };
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) {
434
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/globals.js
435
+ var D = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), O = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Me = "arraybuffer";
436
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/util.js
437
+ function Ne(e, ...t) {
283
438
  return t.reduce((t, n) => (e.hasOwnProperty(n) && (t[n] = e[n]), t), {});
284
439
  }
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));
440
+ var Pe = O.setTimeout, Fe = O.clearTimeout;
441
+ function k(e, t) {
442
+ t.useNativeTimers ? (e.setTimeoutFn = Pe.bind(O), e.clearTimeoutFn = Fe.bind(O)) : (e.setTimeoutFn = O.setTimeout.bind(O), e.clearTimeoutFn = O.clearTimeout.bind(O));
288
443
  }
289
- var _e = 1.33;
290
- function ve(e) {
291
- return typeof e == "string" ? ye(e) : Math.ceil((e.byteLength || e.size) * _e);
444
+ var Ie = 1.33;
445
+ function Le(e) {
446
+ return typeof e == "string" ? Re(e) : Math.ceil((e.byteLength || e.size) * Ie);
292
447
  }
293
- function ye(e) {
448
+ function Re(e) {
294
449
  let t = 0, n = 0;
295
450
  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
451
  return n;
297
452
  }
298
- function be() {
453
+ function ze() {
299
454
  return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
300
455
  }
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) {
456
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/contrib/parseqs.js
457
+ function Be(e) {
304
458
  let t = "";
305
459
  for (let n in e) e.hasOwnProperty(n) && (t.length && (t += "&"), t += encodeURIComponent(n) + "=" + encodeURIComponent(e[n]));
306
460
  return t;
307
461
  }
308
- function Se(e) {
462
+ function Ve(e) {
309
463
  let t = {}, n = e.split("&");
310
464
  for (let e = 0, r = n.length; e < r; e++) {
311
465
  let r = n[e].split("=");
@@ -313,18 +467,17 @@ function Se(e) {
313
467
  }
314
468
  return t;
315
469
  }
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 {
470
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transport.js
471
+ var He = class extends Error {
319
472
  constructor(e, t, n) {
320
473
  super(e), this.description = t, this.context = n, this.type = "TransportError";
321
474
  }
322
- }, E = class extends S {
475
+ }, A = class extends E {
323
476
  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;
477
+ super(), this.writable = !1, k(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
325
478
  }
326
479
  onError(e, t, n) {
327
- return super.emitReserved("error", new Ce(e, t, n)), this;
480
+ return super.emitReserved("error", new He(e, t, n)), this;
328
481
  }
329
482
  open() {
330
483
  return this.readyState = "opening", this.doOpen(), this;
@@ -339,7 +492,7 @@ var Ce = class extends Error {
339
492
  this.readyState = "open", this.writable = !0, super.emitReserved("open");
340
493
  }
341
494
  onData(e) {
342
- let t = _(e, this.socket.binaryType);
495
+ let t = C(e, this.socket.binaryType);
343
496
  this.onPacket(t);
344
497
  }
345
498
  onPacket(e) {
@@ -360,10 +513,10 @@ var Ce = class extends Error {
360
513
  return this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
361
514
  }
362
515
  _query(e) {
363
- let t = xe(e);
516
+ let t = Be(e);
364
517
  return t.length ? "?" + t : "";
365
518
  }
366
- }, we = class extends E {
519
+ }, Ue = class extends A {
367
520
  constructor() {
368
521
  super(...arguments), this._polling = !1;
369
522
  }
@@ -391,7 +544,7 @@ var Ce = class extends Error {
391
544
  this._polling = !0, this.doPoll(), this.emitReserved("poll");
392
545
  }
393
546
  onData(e) {
394
- ce(e, this.socket.binaryType).forEach((e) => {
547
+ De(e, this.socket.binaryType).forEach((e) => {
395
548
  if (this.readyState === "opening" && e.type === "open" && this.onOpen(), e.type === "close") return this.onClose({ description: "transport closed by the server" }), !1;
396
549
  this.onPacket(e);
397
550
  }), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
@@ -403,7 +556,7 @@ var Ce = class extends Error {
403
556
  this.readyState === "open" ? e() : this.once("open", e);
404
557
  }
405
558
  write(e) {
406
- this.writable = !1, se(e, (e) => {
559
+ this.writable = !1, Ee(e, (e) => {
407
560
  this.doWrite(e, () => {
408
561
  this.writable = !0, this.emitReserved("drain");
409
562
  });
@@ -411,17 +564,16 @@ var Ce = class extends Error {
411
564
  }
412
565
  uri() {
413
566
  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);
567
+ return !1 !== this.opts.timestampRequests && (t[this.opts.timestampParam] = ze()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
415
568
  }
416
- }, Te = !1;
569
+ }, We = !1;
417
570
  try {
418
- Te = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
571
+ We = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
419
572
  } 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 {
573
+ var Ge = We;
574
+ // ../../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
575
+ function Ke() {}
576
+ var qe = class extends Ue {
425
577
  constructor(e) {
426
578
  if (super(e), typeof location < "u") {
427
579
  let t = location.protocol === "https:", n = location.port;
@@ -443,13 +595,13 @@ var Oe = class extends we {
443
595
  this.onError("xhr poll error", e, t);
444
596
  }), this.pollXhr = e;
445
597
  }
446
- }, D = class e extends S {
598
+ }, j = class e extends E {
447
599
  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();
600
+ super(), this.createRequest = e, k(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
601
  }
450
602
  _create() {
451
603
  var t;
452
- let n = me(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
604
+ let n = Ne(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
453
605
  n.xdomain = !!this._opts.xd;
454
606
  let r = this._xhr = this.createRequest(n);
455
607
  try {
@@ -485,7 +637,7 @@ var Oe = class extends we {
485
637
  }
486
638
  _cleanup(t) {
487
639
  if (this._xhr !== void 0 && this._xhr !== null) {
488
- if (this._xhr.onreadystatechange = De, t) try {
640
+ if (this._xhr.onreadystatechange = Ke, t) try {
489
641
  this._xhr.abort();
490
642
  } catch {}
491
643
  typeof document < "u" && delete e.requests[this._index], this._xhr = null;
@@ -499,46 +651,45 @@ var Oe = class extends we {
499
651
  this._cleanup();
500
652
  }
501
653
  };
502
- if (D.requestsCount = 0, D.requests = {}, typeof document < "u") {
503
- if (typeof attachEvent == "function") attachEvent("onunload", ke);
654
+ if (j.requestsCount = 0, j.requests = {}, typeof document < "u") {
655
+ if (typeof attachEvent == "function") attachEvent("onunload", Je);
504
656
  else if (typeof addEventListener == "function") {
505
- let e = "onpagehide" in w ? "pagehide" : "unload";
506
- addEventListener(e, ke, !1);
657
+ let e = "onpagehide" in O ? "pagehide" : "unload";
658
+ addEventListener(e, Je, !1);
507
659
  }
508
660
  }
509
- function ke() {
510
- for (let e in D.requests) D.requests.hasOwnProperty(e) && D.requests[e].abort();
661
+ function Je() {
662
+ for (let e in j.requests) j.requests.hasOwnProperty(e) && j.requests[e].abort();
511
663
  }
512
- var Ae = (function() {
513
- let e = Me({ xdomain: !1 });
664
+ var Ye = (function() {
665
+ let e = Ze({ xdomain: !1 });
514
666
  return e && e.responseType !== null;
515
- })(), je = class extends Oe {
667
+ })(), Xe = class extends qe {
516
668
  constructor(e) {
517
669
  super(e);
518
670
  let t = e && e.forceBase64;
519
- this.supportsBinary = Ae && !t;
671
+ this.supportsBinary = Ye && !t;
520
672
  }
521
673
  request(e = {}) {
522
- return Object.assign(e, { xd: this.xd }, this.opts), new D(Me, this.uri(), e);
674
+ return Object.assign(e, { xd: this.xd }, this.opts), new j(Ze, this.uri(), e);
523
675
  }
524
676
  };
525
- function Me(e) {
677
+ function Ze(e) {
526
678
  let t = e.xdomain;
527
679
  try {
528
- if (typeof XMLHttpRequest < "u" && (!t || Ee)) return new XMLHttpRequest();
680
+ if (typeof XMLHttpRequest < "u" && (!t || Ge)) return new XMLHttpRequest();
529
681
  } catch {}
530
682
  if (!t) try {
531
- return new w[["Active", "Object"].join("X")]("Microsoft.XMLHTTP");
683
+ return new O.ActiveXObject("Microsoft.XMLHTTP");
532
684
  } catch {}
533
685
  }
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 Ne = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative", Pe = class extends E {
686
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transports/websocket.js
687
+ var Qe = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative", $e = class extends A {
537
688
  get name() {
538
689
  return "websocket";
539
690
  }
540
691
  doOpen() {
541
- let e = this.uri(), t = this.opts.protocols, n = Ne ? {} : me(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
692
+ let e = this.uri(), t = this.opts.protocols, n = Qe ? {} : Ne(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
542
693
  this.opts.extraHeaders && (n.headers = this.opts.extraHeaders);
543
694
  try {
544
695
  this.ws = this.createSocket(e, t, n);
@@ -559,11 +710,11 @@ var Ne = typeof navigator < "u" && typeof navigator.product == "string" && navig
559
710
  this.writable = !1;
560
711
  for (let t = 0; t < e.length; t++) {
561
712
  let n = e[t], r = t === e.length - 1;
562
- m(n, this.supportsBinary, (e) => {
713
+ x(n, this.supportsBinary, (e) => {
563
714
  try {
564
715
  this.doWrite(n, e);
565
716
  } catch {}
566
- r && C(() => {
717
+ r && D(() => {
567
718
  this.writable = !0, this.emitReserved("drain");
568
719
  }, this.setTimeoutFn);
569
720
  });
@@ -574,18 +725,18 @@ var Ne = typeof navigator < "u" && typeof navigator.product == "string" && navig
574
725
  }
575
726
  uri() {
576
727
  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);
728
+ return this.opts.timestampRequests && (t[this.opts.timestampParam] = ze()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
578
729
  }
579
- }, O = w.WebSocket || w.MozWebSocket, Fe = {
580
- websocket: class extends Pe {
730
+ }, M = O.WebSocket || O.MozWebSocket, et = {
731
+ websocket: class extends $e {
581
732
  createSocket(e, t, n) {
582
- return Ne ? new O(e, t, n) : t ? new O(e, t) : new O(e);
733
+ return Qe ? new M(e, t, n) : t ? new M(e, t) : new M(e);
583
734
  }
584
735
  doWrite(e, t) {
585
736
  this.ws.send(t);
586
737
  }
587
738
  },
588
- webtransport: class extends E {
739
+ webtransport: class extends A {
589
740
  get name() {
590
741
  return "webtransport";
591
742
  }
@@ -601,7 +752,7 @@ var Ne = typeof navigator < "u" && typeof navigator.product == "string" && navig
601
752
  this.onError("webtransport error", e);
602
753
  }), this._transport.ready.then(() => {
603
754
  this._transport.createBidirectionalStream().then((e) => {
604
- let t = de(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = le();
755
+ let t = Ae(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = Oe();
605
756
  r.readable.pipeTo(e.writable), this._writer = r.writable.getWriter();
606
757
  let i = () => {
607
758
  n.read().then(({ done: e, value: t }) => {
@@ -619,7 +770,7 @@ var Ne = typeof navigator < "u" && typeof navigator.product == "string" && navig
619
770
  for (let t = 0; t < e.length; t++) {
620
771
  let n = e[t], r = t === e.length - 1;
621
772
  this._writer.write(n).then(() => {
622
- r && C(() => {
773
+ r && D(() => {
623
774
  this.writable = !0, this.emitReserved("drain");
624
775
  }, this.setTimeoutFn);
625
776
  });
@@ -630,8 +781,8 @@ var Ne = typeof navigator < "u" && typeof navigator.product == "string" && navig
630
781
  (e = this._transport) == null || e.close();
631
782
  }
632
783
  },
633
- polling: je
634
- }, Ie = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, Le = [
784
+ polling: Xe
785
+ }, tt = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, nt = [
635
786
  "source",
636
787
  "protocol",
637
788
  "authority",
@@ -647,37 +798,36 @@ var Ne = typeof navigator < "u" && typeof navigator.product == "string" && navig
647
798
  "query",
648
799
  "anchor"
649
800
  ];
650
- function k(e) {
801
+ function N(e) {
651
802
  if (e.length > 8e3) throw "URI too long";
652
803
  let t = e, n = e.indexOf("["), r = e.indexOf("]");
653
804
  n != -1 && r != -1 && (e = e.substring(0, n) + e.substring(n, r).replace(/:/g, ";") + e.substring(r, e.length));
654
- let i = Ie.exec(e || ""), a = {}, o = 14;
655
- for (; o--;) a[Le[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 = Re(a, a.path), a.queryKey = ze(a, a.query), a;
805
+ let i = tt.exec(e || ""), a = {}, o = 14;
806
+ for (; o--;) a[nt[o]] = i[o] || "";
807
+ 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 = rt(a, a.path), a.queryKey = it(a, a.query), a;
657
808
  }
658
- function Re(e, t) {
809
+ function rt(e, t) {
659
810
  let n = t.replace(/\/{2,9}/g, "/").split("/");
660
811
  return (t.slice(0, 1) == "/" || t.length === 0) && n.splice(0, 1), t.slice(-1) == "/" && n.splice(n.length - 1, 1), n;
661
812
  }
662
- function ze(e, t) {
813
+ function it(e, t) {
663
814
  let n = {};
664
815
  return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(e, t, r) {
665
816
  t && (n[t] = r);
666
817
  }), n;
667
818
  }
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 A = typeof addEventListener == "function" && typeof removeEventListener == "function", j = [];
671
- A && addEventListener("offline", () => {
672
- j.forEach((e) => e());
819
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/socket.js
820
+ var P = typeof addEventListener == "function" && typeof removeEventListener == "function", F = [];
821
+ P && addEventListener("offline", () => {
822
+ F.forEach((e) => e());
673
823
  }, !1);
674
- var M = class e extends S {
824
+ var I = class e extends E {
675
825
  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 = k(e);
826
+ if (super(), this.binaryType = Me, 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) {
827
+ let n = N(e);
678
828
  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 = k(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) => {
829
+ } else t.host && (t.hostname = N(t.host).host);
830
+ k(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
831
  let t = e.prototype.name;
682
832
  this.transports.push(t), this._transportsByName[t] = e;
683
833
  }), this.opts = Object.assign({
@@ -692,11 +842,11 @@ var M = class e extends S {
692
842
  perMessageDeflate: { threshold: 1024 },
693
843
  transportOptions: {},
694
844
  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)), A && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
845
+ }, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = Ve(this.opts.query)), P && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
696
846
  this.transport && (this.transport.removeAllListeners(), this.transport.close());
697
847
  }, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
698
848
  this._onClose("transport close", { description: "network connection lost" });
699
- }, j.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
849
+ }, F.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
700
850
  }
701
851
  createTransport(e) {
702
852
  let t = Object.assign({}, this.opts.query);
@@ -767,7 +917,7 @@ var M = class e extends S {
767
917
  let e = 1;
768
918
  for (let t = 0; t < this.writeBuffer.length; t++) {
769
919
  let n = this.writeBuffer[t].data;
770
- if (n && (e += ve(n)), t > 0 && e > this._maxPayload) return this.writeBuffer.slice(0, t);
920
+ if (n && (e += Le(n)), t > 0 && e > this._maxPayload) return this.writeBuffer.slice(0, t);
771
921
  e += 2;
772
922
  }
773
923
  return this.writeBuffer;
@@ -775,7 +925,7 @@ var M = class e extends S {
775
925
  _hasPingExpired() {
776
926
  if (!this._pingTimeoutTime) return !0;
777
927
  let e = Date.now() > this._pingTimeoutTime;
778
- return e && (this._pingTimeoutTime = 0, C(() => {
928
+ return e && (this._pingTimeoutTime = 0, D(() => {
779
929
  this._onClose("ping timeout");
780
930
  }, this.setTimeoutFn)), e;
781
931
  }
@@ -813,16 +963,16 @@ var M = class e extends S {
813
963
  }
814
964
  _onClose(e, t) {
815
965
  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(), A && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
817
- let e = j.indexOf(this._offlineEventListener);
818
- e !== -1 && j.splice(e, 1);
966
+ if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), P && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
967
+ let e = F.indexOf(this._offlineEventListener);
968
+ e !== -1 && F.splice(e, 1);
819
969
  }
820
970
  this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
821
971
  }
822
972
  }
823
973
  };
824
- M.protocol = 4;
825
- var Be = class extends M {
974
+ I.protocol = 4;
975
+ var at = class extends I {
826
976
  constructor() {
827
977
  super(...arguments), this._upgrades = [];
828
978
  }
@@ -831,7 +981,7 @@ var Be = class extends M {
831
981
  }
832
982
  _probe(e) {
833
983
  let t = this.createTransport(e), n = !1;
834
- M.priorWebsocketSuccess = !1;
984
+ I.priorWebsocketSuccess = !1;
835
985
  let r = () => {
836
986
  n || (t.send([{
837
987
  type: "ping",
@@ -840,7 +990,7 @@ var Be = class extends M {
840
990
  if (!n) {
841
991
  if (e.type === "pong" && e.data === "probe") {
842
992
  if (this.upgrading = !0, this.emitReserved("upgrading", t), !t) return;
843
- M.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
993
+ I.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
844
994
  n || this.readyState !== "closed" && (l(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
845
995
  });
846
996
  } else {
@@ -881,54 +1031,51 @@ var Be = class extends M {
881
1031
  for (let n = 0; n < e.length; n++) ~this.transports.indexOf(e[n]) && t.push(e[n]);
882
1032
  return t;
883
1033
  }
884
- }, N = class extends Be {
1034
+ }, ot = class extends at {
885
1035
  constructor(e, t = {}) {
886
1036
  let n = typeof e == "object", r = n ? { ...e } : { ...t };
887
1037
  (!r.transports || r.transports && typeof r.transports[0] == "string") && (r.transports = (r.transports || [
888
1038
  "polling",
889
1039
  "websocket",
890
1040
  "webtransport"
891
- ]).map((e) => Fe[e]).filter((e) => !!e)), super(n ? r : e, r);
1041
+ ]).map((e) => et[e]).filter((e) => !!e)), super(n ? r : e, r);
892
1042
  }
893
1043
  };
894
- N.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) {
1044
+ ot.protocol;
1045
+ // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/url.js
1046
+ function st(e, t = "", n) {
898
1047
  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 = k(e)), r.port || (/^(http|ws)$/.test(r.protocol) ? r.port = "80" : /^(http|ws)s$/.test(r.protocol) && (r.port = "443")), r.path = r.path || "/";
1048
+ 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 = N(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
1049
  let i = r.host.indexOf(":") === -1 ? r.host : "[" + r.host + "]";
901
1050
  return r.id = r.protocol + "://" + i + ":" + r.port + t, r.href = r.protocol + "://" + i + (n && n.port === r.port ? "" : ":" + r.port), r;
902
1051
  }
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;
1052
+ // ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/is-binary.js
1053
+ var ct = typeof ArrayBuffer == "function", lt = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e.buffer instanceof ArrayBuffer, ut = Object.prototype.toString, dt = typeof Blob == "function" || typeof Blob < "u" && ut.call(Blob) === "[object BlobConstructor]", ft = typeof File == "function" || typeof File < "u" && ut.call(File) === "[object FileConstructor]";
1054
+ function L(e) {
1055
+ return ct && (e instanceof ArrayBuffer || lt(e)) || dt && e instanceof Blob || ft && e instanceof File;
908
1056
  }
909
- function I(e, t) {
1057
+ function R(e, t) {
910
1058
  if (!e || typeof e != "object") return !1;
911
1059
  if (Array.isArray(e)) {
912
- for (let t = 0, n = e.length; t < n; t++) if (I(e[t])) return !0;
1060
+ for (let t = 0, n = e.length; t < n; t++) if (R(e[t])) return !0;
913
1061
  return !1;
914
1062
  }
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;
1063
+ if (L(e)) return !0;
1064
+ if (e.toJSON && typeof e.toJSON == "function" && arguments.length === 1) return R(e.toJSON(), !0);
1065
+ for (let t in e) if (Object.prototype.hasOwnProperty.call(e, t) && R(e[t])) return !0;
918
1066
  return !1;
919
1067
  }
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) {
1068
+ // ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/binary.js
1069
+ function pt(e) {
923
1070
  let t = [], n = e.data, r = e;
924
- return r.data = L(n, t), r.attachments = t.length, {
1071
+ return r.data = z(n, t), r.attachments = t.length, {
925
1072
  packet: r,
926
1073
  buffers: t
927
1074
  };
928
1075
  }
929
- function L(e, t, n) {
1076
+ function z(e, t, n) {
930
1077
  if (!e) return e;
931
- if (F(e)) {
1078
+ if (L(e)) {
932
1079
  let n = {
933
1080
  _placeholder: !0,
934
1081
  num: t.length
@@ -937,56 +1084,55 @@ function L(e, t, n) {
937
1084
  }
938
1085
  if (Array.isArray(e)) {
939
1086
  let n = Array(e.length);
940
- for (let r = 0; r < e.length; r++) n[r] = L(e[r], t);
1087
+ for (let r = 0; r < e.length; r++) n[r] = z(e[r], t);
941
1088
  return n;
942
1089
  }
943
1090
  if (typeof e == "object" && !(e instanceof Date)) {
944
- if (e.toJSON && typeof e.toJSON == "function" && !n) return L(e.toJSON(), t, !0);
1091
+ if (e.toJSON && typeof e.toJSON == "function" && !n) return z(e.toJSON(), t, !0);
945
1092
  let r = {};
946
- for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (r[n] = L(e[n], t));
1093
+ for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (r[n] = z(e[n], t));
947
1094
  return r;
948
1095
  }
949
1096
  return e;
950
1097
  }
951
- function qe(e, t) {
952
- return e.data = R(e.data, t), delete e.attachments, e;
1098
+ function mt(e, t) {
1099
+ return e.data = B(e.data, t), delete e.attachments, e;
953
1100
  }
954
- function R(e, t) {
1101
+ function B(e, t) {
955
1102
  if (!e) return e;
956
1103
  if (e && e._placeholder === !0) {
957
1104
  if (typeof e.num == "number" && e.num >= 0 && e.num < t.length) return t[e.num];
958
1105
  throw Error("illegal attachments");
959
1106
  }
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));
1107
+ if (Array.isArray(e)) for (let n = 0; n < e.length; n++) e[n] = B(e[n], t);
1108
+ else if (typeof e == "object") for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (e[n] = B(e[n], t));
962
1109
  return e;
963
1110
  }
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: () => nt,
1111
+ // ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/index.js
1112
+ var ht = /* @__PURE__ */ t({
1113
+ Decoder: () => vt,
1114
+ Encoder: () => _t,
1115
+ PacketType: () => V,
1116
+ isPacketValid: () => wt,
971
1117
  protocol: () => 5
972
- }), z = [
1118
+ }), gt = [
973
1119
  "connect",
974
1120
  "connect_error",
975
1121
  "disconnect",
976
1122
  "disconnecting",
977
1123
  "newListener",
978
1124
  "removeListener"
979
- ], B;
1125
+ ], V;
980
1126
  (function(e) {
981
1127
  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 {
1128
+ })(V ||= {});
1129
+ var _t = class {
984
1130
  constructor(e) {
985
1131
  this.replacer = e;
986
1132
  }
987
1133
  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,
1134
+ return (e.type === V.EVENT || e.type === V.ACK) && R(e) ? this.encodeAsBinary({
1135
+ type: e.type === V.EVENT ? V.BINARY_EVENT : V.BINARY_ACK,
990
1136
  nsp: e.nsp,
991
1137
  data: e.data,
992
1138
  id: e.id
@@ -994,13 +1140,13 @@ var Ye = class {
994
1140
  }
995
1141
  encodeAsString(e) {
996
1142
  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;
1143
+ return (e.type === V.BINARY_EVENT || e.type === V.BINARY_ACK) && (t += e.attachments + "-"), e.nsp && e.nsp !== "/" && (t += e.nsp + ","), e.id != null && (t += e.id), e.data != null && (t += JSON.stringify(e.data, this.replacer)), t;
998
1144
  }
999
1145
  encodeAsBinary(e) {
1000
- let t = Ke(e), n = this.encodeAsString(t.packet), r = t.buffers;
1146
+ let t = pt(e), n = this.encodeAsString(t.packet), r = t.buffers;
1001
1147
  return r.unshift(n), r;
1002
1148
  }
1003
- }, Xe = class e extends S {
1149
+ }, vt = class e extends E {
1004
1150
  constructor(e) {
1005
1151
  super(), this.opts = Object.assign({
1006
1152
  reviver: void 0,
@@ -1012,23 +1158,23 @@ var Ye = class {
1012
1158
  if (typeof e == "string") {
1013
1159
  if (this.reconstructor) throw Error("got plaintext data when reconstructing a packet");
1014
1160
  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) {
1161
+ let n = t.type === V.BINARY_EVENT;
1162
+ n || t.type === V.BINARY_ACK ? (t.type = n ? V.EVENT : V.ACK, this.reconstructor = new yt(t)) : super.emitReserved("decoded", t);
1163
+ } else if (L(e) || e.base64) {
1018
1164
  if (this.reconstructor) t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
1019
1165
  else throw Error("got binary data when not reconstructing a packet");
1020
1166
  } else throw Error("Unknown type: " + e);
1021
1167
  }
1022
1168
  decodeString(t) {
1023
1169
  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) {
1170
+ if (V[r.type] === void 0) throw Error("unknown packet type " + r.type);
1171
+ if (r.type === V.BINARY_EVENT || r.type === V.BINARY_ACK) {
1026
1172
  let e = n + 1;
1027
1173
  for (; t.charAt(++n) !== "-" && n != t.length;);
1028
1174
  let i = t.substring(e, n);
1029
1175
  if (i != Number(i) || t.charAt(n) !== "-") throw Error("Illegal attachments");
1030
1176
  let a = Number(i);
1031
- if (!$e(a) || a < 1) throw Error("Illegal attachments");
1177
+ if (!xt(a) || a < 1) throw Error("Illegal attachments");
1032
1178
  if (a > this.opts.maxAttachments) throw Error("too many attachments");
1033
1179
  r.attachments = a;
1034
1180
  }
@@ -1066,25 +1212,25 @@ var Ye = class {
1066
1212
  }
1067
1213
  static isPayloadValid(e, t) {
1068
1214
  switch (e) {
1069
- case B.CONNECT: return V(t);
1070
- case B.DISCONNECT: return t === void 0;
1071
- case B.CONNECT_ERROR: return typeof t == "string" || V(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);
1215
+ case V.CONNECT: return H(t);
1216
+ case V.DISCONNECT: return t === void 0;
1217
+ case V.CONNECT_ERROR: return typeof t == "string" || H(t);
1218
+ case V.EVENT:
1219
+ case V.BINARY_EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && gt.indexOf(t[0]) === -1);
1220
+ case V.ACK:
1221
+ case V.BINARY_ACK: return Array.isArray(t);
1076
1222
  }
1077
1223
  }
1078
1224
  destroy() {
1079
1225
  this.reconstructor &&= (this.reconstructor.finishedReconstruction(), null);
1080
1226
  }
1081
- }, Ze = class {
1227
+ }, yt = class {
1082
1228
  constructor(e) {
1083
1229
  this.packet = e, this.buffers = [], this.reconPack = e;
1084
1230
  }
1085
1231
  takeBinaryData(e) {
1086
1232
  if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
1087
- let e = qe(this.reconPack, this.buffers);
1233
+ let e = mt(this.reconPack, this.buffers);
1088
1234
  return this.finishedReconstruction(), e;
1089
1235
  }
1090
1236
  return null;
@@ -1093,48 +1239,46 @@ var Ye = class {
1093
1239
  this.reconPack = null, this.buffers = [];
1094
1240
  }
1095
1241
  };
1096
- function Qe(e) {
1242
+ function bt(e) {
1097
1243
  return typeof e == "string";
1098
1244
  }
1099
- var $e = Number.isInteger || function(e) {
1245
+ var xt = Number.isInteger || function(e) {
1100
1246
  return typeof e == "number" && isFinite(e) && Math.floor(e) === e;
1101
1247
  };
1102
- function et(e) {
1103
- return e === void 0 || $e(e);
1248
+ function St(e) {
1249
+ return e === void 0 || xt(e);
1104
1250
  }
1105
- function V(e) {
1251
+ function H(e) {
1106
1252
  return Object.prototype.toString.call(e) === "[object Object]";
1107
1253
  }
1108
- function tt(e, t) {
1254
+ function Ct(e, t) {
1109
1255
  switch (e) {
1110
- case B.CONNECT: return t === void 0 || V(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" || V(t);
1256
+ case V.CONNECT: return t === void 0 || H(t);
1257
+ case V.DISCONNECT: return t === void 0;
1258
+ case V.EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && gt.indexOf(t[0]) === -1);
1259
+ case V.ACK: return Array.isArray(t);
1260
+ case V.CONNECT_ERROR: return typeof t == "string" || H(t);
1115
1261
  default: return !1;
1116
1262
  }
1117
1263
  }
1118
- function nt(e) {
1119
- return Qe(e.nsp) && et(e.id) && tt(e.type, e.data);
1264
+ function wt(e) {
1265
+ return bt(e.nsp) && St(e.id) && Ct(e.type, e.data);
1120
1266
  }
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 H(e, t, n) {
1267
+ // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/on.js
1268
+ function U(e, t, n) {
1124
1269
  return e.on(t, n), function() {
1125
1270
  e.off(t, n);
1126
1271
  };
1127
1272
  }
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 rt = Object.freeze({
1273
+ // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/socket.js
1274
+ var Tt = Object.freeze({
1131
1275
  connect: 1,
1132
1276
  connect_error: 1,
1133
1277
  disconnect: 1,
1134
1278
  disconnecting: 1,
1135
1279
  newListener: 1,
1136
1280
  removeListener: 1
1137
- }), it = class extends S {
1281
+ }), Et = class extends E {
1138
1282
  constructor(e, t, n) {
1139
1283
  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
1284
  }
@@ -1145,10 +1289,10 @@ var rt = Object.freeze({
1145
1289
  if (this.subs) return;
1146
1290
  let e = this.io;
1147
1291
  this.subs = [
1148
- H(e, "open", this.onopen.bind(this)),
1149
- H(e, "packet", this.onpacket.bind(this)),
1150
- H(e, "error", this.onerror.bind(this)),
1151
- H(e, "close", this.onclose.bind(this))
1292
+ U(e, "open", this.onopen.bind(this)),
1293
+ U(e, "packet", this.onpacket.bind(this)),
1294
+ U(e, "error", this.onerror.bind(this)),
1295
+ U(e, "close", this.onclose.bind(this))
1152
1296
  ];
1153
1297
  }
1154
1298
  get active() {
@@ -1164,10 +1308,10 @@ var rt = Object.freeze({
1164
1308
  return e.unshift("message"), this.emit.apply(this, e), this;
1165
1309
  }
1166
1310
  emit(e, ...t) {
1167
- if (rt.hasOwnProperty(e)) throw Error("\"" + e.toString() + "\" is a reserved event name");
1311
+ if (Tt.hasOwnProperty(e)) throw Error("\"" + e.toString() + "\" is a reserved event name");
1168
1312
  if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) return this._addToQueue(t), this;
1169
1313
  let n = {
1170
- type: B.EVENT,
1314
+ type: V.EVENT,
1171
1315
  data: t
1172
1316
  };
1173
1317
  if (n.options = {}, n.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
@@ -1225,7 +1369,7 @@ var rt = Object.freeze({
1225
1369
  }
1226
1370
  _sendConnectPacket(e) {
1227
1371
  this.packet({
1228
- type: B.CONNECT,
1372
+ type: V.CONNECT,
1229
1373
  data: this._pid ? Object.assign({
1230
1374
  pid: this._pid,
1231
1375
  offset: this._lastOffset
@@ -1248,21 +1392,21 @@ var rt = Object.freeze({
1248
1392
  }
1249
1393
  onpacket(e) {
1250
1394
  if (e.nsp === this.nsp) switch (e.type) {
1251
- case B.CONNECT:
1395
+ case V.CONNECT:
1252
1396
  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
1397
  break;
1254
- case B.EVENT:
1255
- case B.BINARY_EVENT:
1398
+ case V.EVENT:
1399
+ case V.BINARY_EVENT:
1256
1400
  this.onevent(e);
1257
1401
  break;
1258
- case B.ACK:
1259
- case B.BINARY_ACK:
1402
+ case V.ACK:
1403
+ case V.BINARY_ACK:
1260
1404
  this.onack(e);
1261
1405
  break;
1262
- case B.DISCONNECT:
1406
+ case V.DISCONNECT:
1263
1407
  this.ondisconnect();
1264
1408
  break;
1265
- case B.CONNECT_ERROR:
1409
+ case V.CONNECT_ERROR:
1266
1410
  this.destroy();
1267
1411
  let t = Error(e.data.message);
1268
1412
  t.data = e.data.data, this.emitReserved("connect_error", t);
@@ -1283,7 +1427,7 @@ var rt = Object.freeze({
1283
1427
  let t = this, n = !1;
1284
1428
  return function(...r) {
1285
1429
  n || (n = !0, t.packet({
1286
- type: B.ACK,
1430
+ type: V.ACK,
1287
1431
  id: e,
1288
1432
  data: r
1289
1433
  }));
@@ -1308,7 +1452,7 @@ var rt = Object.freeze({
1308
1452
  this.subs &&= (this.subs.forEach((e) => e()), void 0), this.io._destroy(this);
1309
1453
  }
1310
1454
  disconnect() {
1311
- return this.connected && this.packet({ type: B.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
1455
+ return this.connected && this.packet({ type: V.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
1312
1456
  }
1313
1457
  close() {
1314
1458
  return this.disconnect();
@@ -1363,37 +1507,35 @@ var rt = Object.freeze({
1363
1507
  }
1364
1508
  }
1365
1509
  };
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 U(e) {
1510
+ // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/contrib/backo2.js
1511
+ function W(e) {
1369
1512
  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
1513
  }
1371
- U.prototype.duration = function() {
1514
+ W.prototype.duration = function() {
1372
1515
  var e = this.ms * this.factor ** +this.attempts++;
1373
1516
  if (this.jitter) {
1374
1517
  var t = Math.random(), n = Math.floor(t * this.jitter * e);
1375
1518
  e = Math.floor(t * 10) & 1 ? e + n : e - n;
1376
1519
  }
1377
1520
  return Math.min(e, this.max) | 0;
1378
- }, U.prototype.reset = function() {
1521
+ }, W.prototype.reset = function() {
1379
1522
  this.attempts = 0;
1380
- }, U.prototype.setMin = function(e) {
1523
+ }, W.prototype.setMin = function(e) {
1381
1524
  this.ms = e;
1382
- }, U.prototype.setMax = function(e) {
1525
+ }, W.prototype.setMax = function(e) {
1383
1526
  this.max = e;
1384
- }, U.prototype.setJitter = function(e) {
1527
+ }, W.prototype.setJitter = function(e) {
1385
1528
  this.jitter = e;
1386
1529
  };
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 W = class extends S {
1530
+ // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/manager.js
1531
+ var G = class extends E {
1390
1532
  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 U({
1533
+ super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t ||= {}, t.path = t.path || "/socket.io", this.opts = t, k(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
1534
  min: this.reconnectionDelay(),
1393
1535
  max: this.reconnectionDelayMax(),
1394
1536
  jitter: this.randomizationFactor()
1395
1537
  }), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
1396
- let n = t.parser || Je;
1538
+ let n = t.parser || ht;
1397
1539
  this.encoder = new n.Encoder(), this.decoder = new n.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
1398
1540
  }
1399
1541
  reconnection(e) {
@@ -1422,14 +1564,14 @@ var W = class extends S {
1422
1564
  }
1423
1565
  open(e) {
1424
1566
  if (~this._readyState.indexOf("open")) return this;
1425
- this.engine = new N(this.uri, this.opts);
1567
+ this.engine = new ot(this.uri, this.opts);
1426
1568
  let t = this.engine, n = this;
1427
1569
  this._readyState = "opening", this.skipReconnect = !1;
1428
- let r = H(t, "open", function() {
1570
+ let r = U(t, "open", function() {
1429
1571
  n.onopen(), e && e();
1430
1572
  }), i = (t) => {
1431
1573
  this.cleanup(), this._readyState = "closed", this.emitReserved("error", t), e ? e(t) : this.maybeReconnectOnOpen();
1432
- }, a = H(t, "error", i);
1574
+ }, a = U(t, "error", i);
1433
1575
  if (!1 !== this._timeout) {
1434
1576
  let e = this._timeout, n = this.setTimeoutFn(() => {
1435
1577
  r(), i(/* @__PURE__ */ Error("timeout")), t.close();
@@ -1446,7 +1588,7 @@ var W = class extends S {
1446
1588
  onopen() {
1447
1589
  this.cleanup(), this._readyState = "open", this.emitReserved("open");
1448
1590
  let e = this.engine;
1449
- this.subs.push(H(e, "ping", this.onping.bind(this)), H(e, "data", this.ondata.bind(this)), H(e, "error", this.onerror.bind(this)), H(e, "close", this.onclose.bind(this)), H(this.decoder, "decoded", this.ondecoded.bind(this)));
1591
+ 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
1592
  }
1451
1593
  onping() {
1452
1594
  this.emitReserved("ping");
@@ -1459,7 +1601,7 @@ var W = class extends S {
1459
1601
  }
1460
1602
  }
1461
1603
  ondecoded(e) {
1462
- C(() => {
1604
+ D(() => {
1463
1605
  this.emitReserved("packet", e);
1464
1606
  }, this.setTimeoutFn);
1465
1607
  }
@@ -1468,7 +1610,7 @@ var W = class extends S {
1468
1610
  }
1469
1611
  socket(e, t) {
1470
1612
  let n = this.nsps[e];
1471
- return n ? this._autoConnect && !n.active && n.connect() : (n = new it(this, e, t), this.nsps[e] = n), n;
1613
+ return n ? this._autoConnect && !n.active && n.connect() : (n = new Et(this, e, t), this.nsps[e] = n), n;
1472
1614
  }
1473
1615
  _destroy(e) {
1474
1616
  let t = Object.keys(this.nsps);
@@ -1513,21 +1655,20 @@ var W = class extends S {
1513
1655
  let e = this.backoff.attempts;
1514
1656
  this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
1515
1657
  }
1516
- }, G = {};
1517
- function K(e, t) {
1658
+ }, K = {};
1659
+ function q(e, t) {
1518
1660
  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 = G[i] && a in G[i].nsps, s = t.forceNew || t["force new connection"] || !1 === t.multiplex || o, c;
1520
- return s ? c = new W(r, t) : (G[i] || (G[i] = new W(r, t)), c = G[i]), n.query && !t.query && (t.query = n.queryKey), c.socket(n.path, t);
1521
- }
1522
- Object.assign(K, {
1523
- Manager: W,
1524
- Socket: it,
1525
- io: K,
1526
- connect: K
1661
+ let n = st(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;
1662
+ 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);
1663
+ }
1664
+ Object.assign(q, {
1665
+ Manager: G,
1666
+ Socket: Et,
1667
+ io: q,
1668
+ connect: q
1527
1669
  });
1528
- //#endregion
1529
- //#region src/sdk-socket.ts
1530
- function at(e) {
1670
+ // src/sdk-socket.ts
1671
+ function Dt(e) {
1531
1672
  let t = e.replace(/\/$/, "");
1532
1673
  try {
1533
1674
  return `${new URL(t).origin}/sdk`;
@@ -1535,7 +1676,7 @@ function at(e) {
1535
1676
  return `${t}/sdk`;
1536
1677
  }
1537
1678
  }
1538
- var ot = class {
1679
+ var Ot = class {
1539
1680
  constructor() {
1540
1681
  this.socket = null;
1541
1682
  }
@@ -1544,8 +1685,8 @@ var ot = class {
1544
1685
  }
1545
1686
  connect(e) {
1546
1687
  this.disconnect();
1547
- let t = at(e.baseUrl);
1548
- this.socket = K(t, {
1688
+ let t = Dt(e.baseUrl);
1689
+ this.socket = q(t, {
1549
1690
  auth: {
1550
1691
  apiKey: e.apiKey,
1551
1692
  visitorToken: e.visitorToken
@@ -1568,41 +1709,182 @@ var ot = class {
1568
1709
  disconnect() {
1569
1710
  this.socket &&= (this.socket.removeAllListeners(), this.socket.disconnect(), null);
1570
1711
  }
1571
- }, q = "onedeskpro_visitor_token";
1572
- function st(e) {
1712
+ }, J = "onedeskpro_visitor_token";
1713
+ function kt(e) {
1573
1714
  try {
1574
1715
  return typeof window < "u" ? window.localStorage.getItem(e) : null;
1575
1716
  } catch {
1576
1717
  return null;
1577
1718
  }
1578
1719
  }
1579
- function ct(e, t) {
1720
+ function At(e, t) {
1580
1721
  try {
1581
1722
  typeof window < "u" && window.localStorage.setItem(e, t);
1582
1723
  } catch {}
1583
1724
  }
1584
- function lt(e) {
1725
+ function jt(e) {
1585
1726
  try {
1586
1727
  typeof window < "u" && window.localStorage.removeItem(e);
1587
1728
  } catch {}
1588
1729
  }
1589
- var ut = class {
1730
+ var Mt = class {
1590
1731
  constructor() {
1591
- this.token = null, this.storageKey = q;
1732
+ this.token = null, this.storageKey = J;
1592
1733
  }
1593
1734
  setScope(e) {
1594
- this.storageKey = e?.trim() ? `${q}:${e.trim()}` : q, this.token = st(this.storageKey);
1735
+ this.storageKey = e?.trim() ? `${J}:${e.trim()}` : J, this.token = kt(this.storageKey);
1595
1736
  }
1596
1737
  get() {
1597
- return this.token ?? st(this.storageKey);
1738
+ return this.token ?? kt(this.storageKey);
1598
1739
  }
1599
1740
  set(e) {
1600
- this.token = e, ct(this.storageKey, e);
1741
+ this.token = e, At(this.storageKey, e);
1601
1742
  }
1602
1743
  clear() {
1603
- this.token = null, lt(this.storageKey);
1744
+ this.token = null, jt(this.storageKey);
1745
+ }
1746
+ }, Nt = 300, Pt = 250, Ft = 100, It = [
1747
+ "audio/webm;codecs=opus",
1748
+ "audio/webm",
1749
+ "audio/mp4",
1750
+ "audio/ogg;codecs=opus"
1751
+ ];
1752
+ function Lt() {
1753
+ return typeof MediaRecorder > "u" || typeof MediaRecorder.isTypeSupported != "function" ? "audio/webm" : It.find((e) => MediaRecorder.isTypeSupported(e)) ?? "audio/webm";
1754
+ }
1755
+ function Rt(e) {
1756
+ let t = e instanceof DOMException ? e.name : "";
1757
+ return t === "NotAllowedError" || t === "PermissionDeniedError" || t === "SecurityError" ? "Microphone access was denied." : t === "NotFoundError" || t === "DevicesNotFoundError" ? "No microphone was found." : "Could not start recording.";
1758
+ }
1759
+ var Y = class e {
1760
+ constructor(e, t = 300) {
1761
+ this.onChange = e, this.maxDurationSeconds = t, this.recorder = null, this.stream = null, this.chunks = [], this.mimeType = "audio/webm", this.startedAt = 0, this.tickTimer = null, this.levelTimer = null, this.maxTimer = null, this.audioContext = null, this.analyser = null, this.snapshot = {
1762
+ state: "idle",
1763
+ elapsedSeconds: 0,
1764
+ level: 0,
1765
+ result: null
1766
+ };
1767
+ }
1768
+ static isSupported() {
1769
+ return typeof navigator < "u" && typeof navigator.mediaDevices?.getUserMedia == "function" && typeof MediaRecorder < "u";
1770
+ }
1771
+ getSnapshot() {
1772
+ return { ...this.snapshot };
1773
+ }
1774
+ async start() {
1775
+ if (!e.isSupported()) throw Error("Voice messages are not supported in this browser.");
1776
+ this.release(), this.chunks = [];
1777
+ let t;
1778
+ try {
1779
+ t = await navigator.mediaDevices.getUserMedia({ audio: !0 });
1780
+ } catch (e) {
1781
+ throw Error(Rt(e));
1782
+ }
1783
+ try {
1784
+ this.mimeType = Lt();
1785
+ let e = new MediaRecorder(t, { mimeType: this.mimeType });
1786
+ e.ondataavailable = (e) => {
1787
+ e.data.size > 0 && this.chunks.push(e.data);
1788
+ }, this.stream = t, this.recorder = e, this.startedAt = Date.now(), e.start(200);
1789
+ } catch (e) {
1790
+ throw t.getTracks().forEach((e) => e.stop()), this.stream = null, this.recorder = null, Error(Rt(e));
1791
+ }
1792
+ this.startLevelMeter(t), this.tickTimer = setInterval(() => {
1793
+ this.update({ elapsedSeconds: Math.floor(this.elapsedMs() / 1e3) });
1794
+ }, Pt), this.maxTimer = setTimeout(() => void this.stop(), this.maxDurationSeconds * 1e3), this.update({
1795
+ state: "recording",
1796
+ elapsedSeconds: 0,
1797
+ level: 0,
1798
+ result: null
1799
+ });
1800
+ }
1801
+ async stop() {
1802
+ let e = this.recorder;
1803
+ if (!e || e.state === "inactive") return this.release(), null;
1804
+ let t = Math.max(1, Math.round(this.elapsedMs() / 1e3));
1805
+ this.clearTimers();
1806
+ let n = await new Promise((t) => {
1807
+ e.onstop = () => {
1808
+ let e = this.chunks;
1809
+ this.chunks = [], t(new Blob(e, { type: g(this.mimeType) }));
1810
+ };
1811
+ try {
1812
+ e.stop();
1813
+ } catch {
1814
+ t(new Blob(this.chunks, { type: g(this.mimeType) }));
1815
+ }
1816
+ });
1817
+ this.releaseMedia();
1818
+ let r = {
1819
+ blob: n,
1820
+ mimeType: g(this.mimeType),
1821
+ durationSeconds: t
1822
+ };
1823
+ return this.update({
1824
+ state: "preview",
1825
+ elapsedSeconds: t,
1826
+ level: 0,
1827
+ result: r
1828
+ }), r;
1829
+ }
1830
+ cancel() {
1831
+ this.release(), this.update({
1832
+ state: "idle",
1833
+ elapsedSeconds: 0,
1834
+ level: 0,
1835
+ result: null
1836
+ });
1837
+ }
1838
+ destroy() {
1839
+ this.release(), this.snapshot = {
1840
+ state: "idle",
1841
+ elapsedSeconds: 0,
1842
+ level: 0,
1843
+ result: null
1844
+ };
1604
1845
  }
1605
- }, J = [
1846
+ update(e) {
1847
+ this.snapshot = {
1848
+ ...this.snapshot,
1849
+ ...e
1850
+ }, this.onChange({ ...this.snapshot });
1851
+ }
1852
+ elapsedMs() {
1853
+ return this.startedAt > 0 ? Date.now() - this.startedAt : 0;
1854
+ }
1855
+ startLevelMeter(e) {
1856
+ let t = typeof window > "u" ? null : window, n = t?.AudioContext ?? t?.webkitAudioContext;
1857
+ if (n) try {
1858
+ let t = new n(), r = t.createAnalyser();
1859
+ r.fftSize = 256, t.createMediaStreamSource(e).connect(r), t.resume().catch(() => void 0), this.audioContext = t, this.analyser = r;
1860
+ let i = new Uint8Array(r.frequencyBinCount);
1861
+ this.levelTimer = setInterval(() => {
1862
+ r.getByteTimeDomainData(i);
1863
+ let e = 0;
1864
+ for (let t = 0; t < i.length; t++) {
1865
+ let n = ((i[t] ?? 128) - 128) / 128;
1866
+ e += n * n;
1867
+ }
1868
+ this.update({ level: Math.min(1, Math.sqrt(e / i.length) * 3.2) });
1869
+ }, Ft);
1870
+ } catch {}
1871
+ }
1872
+ clearTimers() {
1873
+ this.tickTimer && clearInterval(this.tickTimer), this.levelTimer && clearInterval(this.levelTimer), this.maxTimer && clearTimeout(this.maxTimer), this.tickTimer = null, this.levelTimer = null, this.maxTimer = null;
1874
+ }
1875
+ releaseMedia() {
1876
+ this.stream?.getTracks().forEach((e) => e.stop()), this.stream = null, this.recorder = null, this.analyser = null, this.audioContext &&= (this.audioContext.close().catch(() => void 0), null), this.startedAt = 0;
1877
+ }
1878
+ release() {
1879
+ if (this.clearTimers(), this.recorder && this.recorder.state !== "inactive") {
1880
+ this.recorder.onstop = null;
1881
+ try {
1882
+ this.recorder.stop();
1883
+ } catch {}
1884
+ }
1885
+ this.chunks = [], this.releaseMedia();
1886
+ }
1887
+ }, X = [
1606
1888
  {
1607
1889
  iso: "BD",
1608
1890
  name: "Bangladesh",
@@ -1969,8 +2251,8 @@ var ut = class {
1969
2251
  dial: "977",
1970
2252
  flag: "🇳🇵"
1971
2253
  }
1972
- ], dt = J.find((e) => e.iso === "BD") ?? J[0];
1973
- function ft(e, t) {
2254
+ ], zt = X.find((e) => e.iso === "BD") ?? X[0];
2255
+ function Bt(e, t) {
1974
2256
  let n = t.trim();
1975
2257
  if (n.startsWith("+")) {
1976
2258
  let e = n.replace(/\D/g, "");
@@ -1979,9 +2261,9 @@ function ft(e, t) {
1979
2261
  let r = n.replace(/\D/g, "");
1980
2262
  return !r || (r = r.replace(/^0+/, ""), !r) ? "" : `+${e}${r}`;
1981
2263
  }
1982
- //#endregion
1983
- //#region src/widget/styles.ts
1984
- function pt(e, t) {
2264
+ // src/widget/styles.ts
2265
+ var Vt = "(max-width: 640px), (max-height: 500px) and (pointer: coarse)";
2266
+ function Ht(e, t) {
1985
2267
  let n = `
1986
2268
  --ttcb-bg: #ffffff;
1987
2269
  --ttcb-bg-secondary: #f3f4f6;
@@ -2048,6 +2330,7 @@ function pt(e, t) {
2048
2330
  transition: opacity 0.2s ease, transform 0.25s ease, height 0.2s ease;
2049
2331
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
2050
2332
  }
2333
+ .ttcb-panel:focus { outline: none; }
2051
2334
  .ttcb-panel.ttcb-mode-chat {
2052
2335
  height: 560px;
2053
2336
  }
@@ -2196,7 +2479,7 @@ function pt(e, t) {
2196
2479
 
2197
2480
  .ttcb-msg { display: flex; gap: 8px; max-width: 100%; }
2198
2481
  .ttcb-msg.human { flex-direction: row-reverse; }
2199
- .ttcb-msg-body { display: flex; flex-direction: column; gap: 3px; max-width: 78%; }
2482
+ .ttcb-msg-body { display: flex; flex-direction: column; gap: 3px; max-width: 78%; min-width: 0; }
2200
2483
  .ttcb-msg.human .ttcb-msg-body { align-items: flex-end; }
2201
2484
  .ttcb-msg-label {
2202
2485
  font-size: 11px; font-weight: 600; color: var(--ttcb-text-muted);
@@ -2466,29 +2749,233 @@ function pt(e, t) {
2466
2749
  flex-shrink: 0;
2467
2750
  }
2468
2751
 
2752
+ .ttcb-form { align-items: center; }
2753
+ .ttcb-attach { position: relative; flex-shrink: 0; }
2754
+ .ttcb-attach-btn {
2755
+ width: 38px; height: 38px; border-radius: 8px;
2756
+ border: 1px solid var(--ttcb-border);
2757
+ background: var(--ttcb-input-bg); color: var(--ttcb-text-muted);
2758
+ cursor: pointer; display: flex; align-items: center; justify-content: center;
2759
+ transition: color 0.15s, border-color 0.15s;
2760
+ }
2761
+ .ttcb-attach-btn:hover { color: var(--ttcb-text); }
2762
+ .ttcb-attach-btn:focus-visible { border-color: ${e}; outline: none; }
2763
+ .ttcb-attach-btn:disabled { opacity: 0.5; cursor: not-allowed; }
2764
+ .ttcb-attach-btn svg { width: 18px; height: 18px; }
2765
+ .ttcb-attach-menu {
2766
+ display: none; position: absolute; left: 0; bottom: calc(100% + 8px);
2767
+ min-width: 170px; padding: 4px;
2768
+ background: var(--ttcb-bg);
2769
+ border: 1px solid var(--ttcb-border); border-radius: 12px;
2770
+ box-shadow: 0 8px 24px rgba(0,0,0,0.12);
2771
+ z-index: 1;
2772
+ }
2773
+ .ttcb-attach-menu.open { display: flex; flex-direction: column; }
2774
+ .ttcb-attach-item {
2775
+ display: flex; align-items: center; gap: 10px;
2776
+ padding: 9px 10px; border: none; border-radius: 8px;
2777
+ background: none; cursor: pointer;
2778
+ font-family: inherit; font-size: 13px; color: var(--ttcb-text);
2779
+ text-align: left; width: 100%;
2780
+ }
2781
+ .ttcb-attach-item:hover, .ttcb-attach-item:focus-visible {
2782
+ background: var(--ttcb-bg-secondary); outline: none;
2783
+ }
2784
+ .ttcb-attach-item svg { width: 16px; height: 16px; color: var(--ttcb-text-muted); flex-shrink: 0; }
2785
+ .ttcb-file-input { display: none; }
2786
+ .ttcb-form.hidden { display: none; }
2787
+ .ttcb-mic-btn {
2788
+ width: 38px; height: 38px; border-radius: 8px; flex-shrink: 0;
2789
+ border: 1px solid var(--ttcb-border);
2790
+ background: var(--ttcb-input-bg); color: var(--ttcb-text-muted);
2791
+ cursor: pointer; display: flex; align-items: center; justify-content: center;
2792
+ transition: color 0.15s, border-color 0.15s;
2793
+ }
2794
+ .ttcb-mic-btn:hover { color: var(--ttcb-text); }
2795
+ .ttcb-mic-btn:focus-visible { border-color: ${e}; outline: none; }
2796
+ .ttcb-mic-btn:disabled { opacity: 0.5; cursor: not-allowed; }
2797
+ .ttcb-mic-btn svg { width: 18px; height: 18px; }
2798
+
2799
+ .ttcb-voice-bar, .ttcb-voice-preview {
2800
+ display: none; align-items: center; gap: 8px;
2801
+ padding: 6px 8px;
2802
+ border: 1px solid var(--ttcb-border); border-radius: 10px;
2803
+ background: var(--ttcb-input-bg);
2804
+ }
2805
+ .ttcb-voice-bar.visible, .ttcb-voice-preview.visible { display: flex; }
2806
+ .ttcb-voice-dot {
2807
+ width: 10px; height: 10px; border-radius: 50%; background: #ef4444; flex-shrink: 0;
2808
+ animation: ttcb-pulse 1.1s ease-in-out infinite;
2809
+ }
2810
+ @keyframes ttcb-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
2811
+ .ttcb-voice-time {
2812
+ font-size: 13px; font-weight: 500; color: var(--ttcb-text);
2813
+ font-variant-numeric: tabular-nums; flex-shrink: 0;
2814
+ }
2815
+ .ttcb-voice-meter {
2816
+ flex: 1; min-width: 0; height: 6px; border-radius: 999px;
2817
+ background: var(--ttcb-bg-secondary); overflow: hidden;
2818
+ }
2819
+ .ttcb-voice-level {
2820
+ display: block; height: 100%; width: 4%; border-radius: 999px;
2821
+ background: #ef4444; transition: width 0.1s linear;
2822
+ }
2823
+ .ttcb-voice-audio { flex: 1; min-width: 0; height: 32px; }
2824
+ .ttcb-voice-btn {
2825
+ width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
2826
+ border: 1px solid var(--ttcb-border);
2827
+ background: var(--ttcb-bg); color: var(--ttcb-text-muted);
2828
+ cursor: pointer; display: flex; align-items: center; justify-content: center;
2829
+ }
2830
+ .ttcb-voice-btn:hover { color: var(--ttcb-text); }
2831
+ .ttcb-voice-btn.primary { background: ${e}; border-color: ${e}; color: #fff; }
2832
+ .ttcb-voice-btn.primary:hover { opacity: 0.9; color: #fff; }
2833
+ .ttcb-voice-btn svg { width: 15px; height: 15px; }
2834
+ .ttcb-voice-btn.primary svg { fill: #fff; }
2835
+ .ttcb-voice-btn.primary svg[fill="none"] { fill: none; }
2836
+
2837
+ .ttcb-pending-tray { display: none; gap: 8px; flex-wrap: wrap; padding-bottom: 10px; }
2838
+ .ttcb-pending-tray.visible { display: flex; }
2839
+ .ttcb-pending-item {
2840
+ display: flex; align-items: center; gap: 8px; max-width: 100%;
2841
+ padding: 5px 6px 5px 5px;
2842
+ border: 1px solid var(--ttcb-border); border-radius: 10px;
2843
+ background: var(--ttcb-bg-secondary);
2844
+ font-size: 12px; color: var(--ttcb-text);
2845
+ }
2846
+ .ttcb-pending-thumb {
2847
+ width: 36px; height: 36px; border-radius: 6px; object-fit: cover;
2848
+ flex-shrink: 0; background: var(--ttcb-bg);
2849
+ }
2850
+ .ttcb-pending-icon {
2851
+ width: 36px; height: 36px; border-radius: 6px; flex-shrink: 0;
2852
+ display: flex; align-items: center; justify-content: center;
2853
+ background: var(--ttcb-bg); color: var(--ttcb-text-muted);
2854
+ }
2855
+ .ttcb-pending-icon svg { width: 18px; height: 18px; }
2856
+ .ttcb-pending-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2857
+ .ttcb-pending-remove {
2858
+ width: 22px; height: 22px; border-radius: 50%; border: none; flex-shrink: 0;
2859
+ background: var(--ttcb-bg); color: var(--ttcb-text-muted); cursor: pointer;
2860
+ display: flex; align-items: center; justify-content: center;
2861
+ }
2862
+ .ttcb-pending-remove:hover { color: var(--ttcb-text); }
2863
+ .ttcb-pending-remove svg { width: 12px; height: 12px; fill: currentColor; }
2864
+ .ttcb-compose-error { display: none; font-size: 12px; color: #ef4444; padding-bottom: 8px; }
2865
+ .ttcb-compose-error.visible { display: block; }
2866
+
2867
+ .ttcb-attachments { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
2868
+ .ttcb-msg.human .ttcb-attachments { align-items: flex-end; }
2869
+ .ttcb-attachment-image {
2870
+ display: block; max-width: 220px; border-radius: 12px; overflow: hidden;
2871
+ border: 1px solid var(--ttcb-border); background: var(--ttcb-bg-secondary);
2872
+ }
2873
+ .ttcb-attachment-image img { display: block; max-width: 100%; max-height: 240px; object-fit: cover; }
2874
+ .ttcb-attachment-video { display: block; max-width: 220px; border-radius: 12px; background: #000; }
2875
+ .ttcb-attachment-voice { display: flex; flex-direction: column; gap: 2px; width: 220px; max-width: 100%; }
2876
+ .ttcb-attachment-audio { display: block; width: 100%; height: 36px; }
2877
+ .ttcb-attachment-duration { font-size: 11px; color: var(--ttcb-text-muted); padding-left: 2px; }
2878
+ .ttcb-attachment-file {
2879
+ display: flex; align-items: center; gap: 10px;
2880
+ padding: 8px 10px; max-width: 240px;
2881
+ border: 1px solid var(--ttcb-border); border-radius: 12px;
2882
+ background: var(--ttcb-bg); color: var(--ttcb-text);
2883
+ text-decoration: none; font-size: 13px;
2884
+ }
2885
+ a.ttcb-attachment-file:hover { border-color: ${e}; }
2886
+ .ttcb-attachment-icon {
2887
+ width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
2888
+ display: flex; align-items: center; justify-content: center;
2889
+ background: var(--ttcb-bg-secondary); color: var(--ttcb-text-muted);
2890
+ }
2891
+ .ttcb-attachment-icon svg { width: 16px; height: 16px; }
2892
+ .ttcb-attachment-meta { display: flex; flex-direction: column; min-width: 0; }
2893
+ .ttcb-attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
2894
+ .ttcb-attachment-size { font-size: 11px; color: var(--ttcb-text-muted); }
2895
+ .ttcb-msg.ttcb-pending .ttcb-attachments, .ttcb-msg.ttcb-pending .ttcb-bubble { opacity: 0.6; }
2896
+ .ttcb-msg-status { font-size: 11px; color: var(--ttcb-text-muted); padding: 0 2px; }
2897
+
2469
2898
  .ttcb-footer.hidden, .ttcb-messages.hidden { display: none; }
2470
2899
 
2471
- @media (max-width: 440px) {
2472
- .ttcb-panel { width: calc(100vw - 16px); right: 8px !important; left: 8px !important; bottom: 84px !important; }
2473
- .ttcb-fab.bottom-right { right: 16px; }
2474
- .ttcb-fab.bottom-left { left: 16px; }
2900
+ @media ${Vt} {
2901
+ .ttcb-fab.bottom-right { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
2902
+ .ttcb-fab.bottom-left { left: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
2903
+ /* The open panel covers the launcher; its own close button takes over. */
2904
+ .ttcb-fab.ttcb-open { display: none; }
2905
+
2906
+ /*
2907
+ * Full screen. Offsets instead of 100vw so a scrollbar never adds width, and
2908
+ * pinned to the visual viewport (--ttcb-vv-*, set by the widget) so the
2909
+ * on-screen keyboard shrinks the panel instead of pushing it off screen.
2910
+ */
2911
+ .ttcb-panel,
2912
+ .ttcb-panel.bottom-right,
2913
+ .ttcb-panel.bottom-left,
2914
+ .ttcb-panel.ttcb-mode-chat,
2915
+ .ttcb-panel.ttcb-mode-form,
2916
+ .ttcb-panel.ttcb-mode-compact {
2917
+ top: var(--ttcb-vv-top, 0px);
2918
+ left: var(--ttcb-vv-left, 0px);
2919
+ right: auto;
2920
+ bottom: auto;
2921
+ width: var(--ttcb-vv-width, 100%);
2922
+ height: var(--ttcb-vv-height, 100%);
2923
+ max-width: none;
2924
+ max-height: none;
2925
+ border: none;
2926
+ border-radius: 0;
2927
+ box-shadow: none;
2928
+ transition: opacity 0.2s ease, transform 0.25s ease;
2929
+ -webkit-text-size-adjust: 100%;
2930
+ text-size-adjust: 100%;
2931
+ }
2932
+ .ttcb-header {
2933
+ padding-top: max(14px, env(safe-area-inset-top, 0px));
2934
+ padding-left: max(16px, env(safe-area-inset-left, 0px));
2935
+ padding-right: max(16px, env(safe-area-inset-right, 0px));
2936
+ }
2937
+ .ttcb-close-btn { padding: 8px; }
2938
+ .ttcb-close-btn svg { width: 22px; height: 22px; }
2939
+ .ttcb-footer {
2940
+ padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
2941
+ padding-left: max(12px, env(safe-area-inset-left, 0px));
2942
+ padding-right: max(12px, env(safe-area-inset-right, 0px));
2943
+ }
2944
+ .ttcb-messages {
2945
+ overflow-x: hidden;
2946
+ overscroll-behavior: contain;
2947
+ }
2948
+ .ttcb-panel.ttcb-mode-form .ttcb-identify.visible {
2949
+ flex: 1 1 auto;
2950
+ min-height: 0;
2951
+ overflow-x: hidden;
2952
+ overscroll-behavior: contain;
2953
+ padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
2954
+ }
2955
+ .ttcb-country-list { overscroll-behavior: contain; }
2956
+ .ttcb-field-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
2957
+
2958
+ /* iOS zooms the page into any field under 16px, then leaves it zoomed and scrollable sideways. */
2959
+ .ttcb-input,
2960
+ .ttcb-identify-input,
2961
+ .ttcb-phone-national,
2962
+ .ttcb-country-search { font-size: 16px; }
2475
2963
  }
2476
2964
  `;
2477
2965
  }
2478
- //#endregion
2479
- //#region src/widget/render.ts
2480
- function Y(e) {
2966
+ // src/widget/render.ts
2967
+ function Ut(e) {
2481
2968
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
2482
2969
  }
2483
- function mt(e) {
2970
+ function Wt(e) {
2484
2971
  let t = [], n = e.replace(/```[\w]*\n?([\s\S]*?)```/g, (e, n) => {
2485
2972
  let r = t.length;
2486
- return t.push(`<pre><code>${Y(n.trim())}</code></pre>`), `\x04${r}\x05`;
2973
+ return t.push(`<pre><code>${Ut(n.trim())}</code></pre>`), `\x04${r}\x05`;
2487
2974
  });
2488
2975
  n = n.replace(/`([^`\n]+)`/g, (e, n) => {
2489
2976
  let r = t.length;
2490
- return t.push(`<code>${Y(n)}</code>`), `\x02${r}\x03`;
2491
- }), n = Y(n);
2977
+ return t.push(`<code>${Ut(n)}</code>`), `\x02${r}\x03`;
2978
+ }), n = Ut(n);
2492
2979
  let r = n.split("\n"), i = [], a = "", o = () => {
2493
2980
  a &&= (i.push(`</${a}>`), "");
2494
2981
  };
@@ -2505,88 +2992,157 @@ function mt(e) {
2505
2992
  }).join("") : "";
2506
2993
  }).filter(Boolean).join(""), n = n.replace(/\x04(\d+)\x05/g, (e, n) => t[+n] ?? "").replace(/\x02(\d+)\x03/g, (e, n) => t[+n] ?? ""), n;
2507
2994
  }
2508
- function ht() {
2995
+ function Gt() {
2509
2996
  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>";
2510
2997
  }
2511
- function gt() {
2998
+ function Kt() {
2512
2999
  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>";
2513
3000
  }
2514
- function _t() {
3001
+ function qt() {
2515
3002
  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>";
2516
3003
  }
2517
- function vt() {
3004
+ function Jt() {
2518
3005
  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>";
2519
3006
  }
2520
- function X() {
3007
+ function Z() {
2521
3008
  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>";
2522
3009
  }
2523
- function yt() {
3010
+ function Yt() {
2524
3011
  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>";
2525
3012
  }
2526
- function bt() {
3013
+ function Xt() {
2527
3014
  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>";
2528
3015
  }
2529
- function xt() {
3016
+ function Zt() {
2530
3017
  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>";
2531
3018
  }
2532
- function St() {
3019
+ function Qt() {
2533
3020
  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>";
2534
3021
  }
2535
- function Ct() {
3022
+ function $t() {
2536
3023
  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>";
2537
3024
  }
2538
- function wt() {
3025
+ function en() {
2539
3026
  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>";
2540
3027
  }
2541
- function Tt() {
3028
+ function tn() {
2542
3029
  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>";
2543
3030
  }
2544
- function Et() {
3031
+ function nn() {
2545
3032
  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>";
2546
3033
  }
2547
- function Dt() {
3034
+ function rn() {
2548
3035
  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>";
2549
3036
  }
2550
- function Ot(e, t) {
2551
- let n = document.createElement("div");
2552
- n.className = `ttcb-msg ${t}`;
2553
- let r = document.createElement("div");
2554
- r.className = "ttcb-msg-avatar", r.innerHTML = t === "human" ? yt() : t === "agent" ? bt() : X();
2555
- let i = document.createElement("div");
2556
- if (i.className = "ttcb-msg-body", t === "agent") {
3037
+ function an() {
3038
+ return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <line x1=\"12\" y1=\"5\" x2=\"12\" y2=\"19\"/>\n <line x1=\"5\" y1=\"12\" x2=\"19\" y2=\"12\"/>\n </svg>";
3039
+ }
3040
+ function on() {
3041
+ 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.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48\"/>\n </svg>";
3042
+ }
3043
+ function sn() {
3044
+ 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 <rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\" ry=\"2\"/>\n <circle cx=\"8.5\" cy=\"8.5\" r=\"1.5\"/>\n <polyline points=\"21 15 16 10 5 21\"/>\n </svg>";
3045
+ }
3046
+ function cn() {
3047
+ 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 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z\"/>\n <path d=\"M19 10v2a7 7 0 0 1-14 0v-2\"/>\n <line x1=\"12\" y1=\"19\" x2=\"12\" y2=\"23\"/>\n <line x1=\"8\" y1=\"23\" x2=\"16\" y2=\"23\"/>\n </svg>";
3048
+ }
3049
+ function ln() {
3050
+ return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"2\" fill=\"currentColor\"/>\n </svg>";
3051
+ }
3052
+ function un() {
3053
+ 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=\"3 6 5 6 21 6\"/>\n <path d=\"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6\"/>\n <path d=\"M10 11v6\"/>\n <path d=\"M14 11v6\"/>\n <path d=\"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2\"/>\n </svg>";
3054
+ }
3055
+ function dn() {
3056
+ 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=\"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z\"/>\n <polyline points=\"14 2 14 8 20 8\"/>\n </svg>";
3057
+ }
3058
+ function fn(e) {
3059
+ let t = f(e.url) ? e.url : "", n = e.type.toLowerCase();
3060
+ if (t && n.startsWith("image/")) {
3061
+ let n = document.createElement("a");
3062
+ n.className = "ttcb-attachment ttcb-attachment-image", n.href = t, n.target = "_blank", n.rel = "noopener noreferrer", n.setAttribute("aria-label", `Open ${e.fileName}`);
3063
+ let r = document.createElement("img");
3064
+ return r.src = t, r.alt = e.fileName, r.loading = "lazy", n.appendChild(r), n;
3065
+ }
3066
+ if (t && n.startsWith("video/")) {
3067
+ let n = document.createElement("video");
3068
+ return n.className = "ttcb-attachment ttcb-attachment-video", n.controls = !0, n.preload = "metadata", n.src = t, n.setAttribute("aria-label", e.fileName), n;
3069
+ }
3070
+ if (t && n.startsWith("audio/")) {
3071
+ let n = document.createElement("div");
3072
+ n.className = "ttcb-attachment ttcb-attachment-voice";
3073
+ let r = document.createElement("audio");
3074
+ if (r.className = "ttcb-attachment-audio", r.controls = !0, r.preload = "metadata", r.src = t, r.setAttribute("aria-label", e.fileName), n.appendChild(r), typeof e.durationSeconds == "number" && e.durationSeconds > 0) {
3075
+ let t = document.createElement("span");
3076
+ t.className = "ttcb-attachment-duration", t.textContent = _(e.durationSeconds), n.appendChild(t);
3077
+ }
3078
+ return n;
3079
+ }
3080
+ let r = document.createElement(t ? "a" : "div");
3081
+ r.className = "ttcb-attachment ttcb-attachment-file", r instanceof HTMLAnchorElement && (r.href = t, r.target = "_blank", r.rel = "noopener noreferrer");
3082
+ let i = document.createElement("span");
3083
+ i.className = "ttcb-attachment-icon", i.setAttribute("aria-hidden", "true"), i.innerHTML = dn();
3084
+ let a = document.createElement("span");
3085
+ a.className = "ttcb-attachment-meta";
3086
+ let o = document.createElement("span");
3087
+ o.className = "ttcb-attachment-name", o.textContent = e.fileName, a.appendChild(o);
3088
+ let s = te(e.size);
3089
+ if (s) {
2557
3090
  let e = document.createElement("span");
2558
- e.className = "ttcb-msg-label", e.textContent = "Agent", i.appendChild(e);
3091
+ e.className = "ttcb-attachment-size", e.textContent = s, a.appendChild(e);
2559
3092
  }
3093
+ return r.appendChild(i), r.appendChild(a), r;
3094
+ }
3095
+ function pn(e) {
3096
+ let { type: t, content: n } = e, r = e.attachments ?? [], i = document.createElement("div");
3097
+ i.className = `ttcb-msg ${t}`, e.pending && i.classList.add("ttcb-pending");
2560
3098
  let a = document.createElement("div");
2561
- return a.className = "ttcb-bubble", t === "human" ? a.textContent = e : a.innerHTML = mt(e), i.appendChild(a), n.appendChild(r), n.appendChild(i), n;
3099
+ a.className = "ttcb-msg-avatar", a.innerHTML = t === "human" ? Yt() : t === "agent" ? Xt() : Z();
3100
+ let o = document.createElement("div");
3101
+ if (o.className = "ttcb-msg-body", t === "agent") {
3102
+ let e = document.createElement("span");
3103
+ e.className = "ttcb-msg-label", e.textContent = "Agent", o.appendChild(e);
3104
+ }
3105
+ if (r.length > 0) {
3106
+ let e = document.createElement("div");
3107
+ e.className = "ttcb-attachments";
3108
+ for (let t of r) e.appendChild(fn(t));
3109
+ o.appendChild(e);
3110
+ }
3111
+ if (r.length === 0 || !re(n, r)) {
3112
+ let e = document.createElement("div");
3113
+ e.className = "ttcb-bubble", t === "human" ? e.textContent = n : e.innerHTML = Wt(n), o.appendChild(e);
3114
+ }
3115
+ if (e.pending) {
3116
+ let e = document.createElement("span");
3117
+ e.className = "ttcb-msg-status", e.textContent = "Uploading…", o.appendChild(e);
3118
+ }
3119
+ return i.appendChild(a), i.appendChild(o), i;
2562
3120
  }
2563
- function kt() {
3121
+ function mn() {
2564
3122
  let e = document.createElement("div");
2565
3123
  e.className = "ttcb-msg ai", e.id = "ttcb-typing";
2566
3124
  let t = document.createElement("div");
2567
- t.className = "ttcb-msg-avatar", t.innerHTML = X();
3125
+ t.className = "ttcb-msg-avatar", t.innerHTML = Z();
2568
3126
  let n = document.createElement("div");
2569
3127
  return n.className = "ttcb-typing", n.innerHTML = "<span></span><span></span><span></span>", e.appendChild(t), e.appendChild(n), e;
2570
3128
  }
2571
- //#endregion
2572
- //#region src/widget/widget.ts
2573
- var At = class {
3129
+ // src/widget/widget.ts
3130
+ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mpeg,audio/wav,audio/x-m4a,audio/aac,audio/opus,application/pdf,text/csv", gn = "image/jpeg,image/png,image/gif", _n = class {
2574
3131
  constructor(e, t) {
2575
- this.selectedCountry = dt, this.countryOpen = !1, this.isOpen = !1, this.destroyed = !1, this.position = e.position ?? "bottom-right", this.callbacks = t, this.autoOpen = e.autoOpen === !0, this.mount(e);
3132
+ this.stopViewportSync = null, this.pendingFiles = [], this.attachMenuOpen = !1, this.recorder = null, this.voicePreviewUrl = "", this.selectedCountry = zt, this.countryOpen = !1, this.isOpen = !1, this.destroyed = !1, this.position = e.position ?? "bottom-right", this.callbacks = t, this.autoOpen = e.autoOpen === !0, this.mount(e);
2576
3133
  }
2577
3134
  mount(e) {
2578
3135
  this.host = document.createElement("div"), this.host.id = "onedeskpro-chatbot-host", this.host.style.display = "none", this.shadow = this.host.attachShadow({ mode: "closed" });
2579
3136
  let t = document.createElement("style");
2580
- t.textContent = pt(e.primaryColor ?? "#2563EB", e.theme ?? "auto"), this.shadow.appendChild(t);
2581
- let n = document.createElement("button");
2582
- n.className = `ttcb-fab ${this.position}`, n.setAttribute("aria-label", "Open chat"), n.innerHTML = gt(), 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";
2583
- let r = document.createElement("form");
2584
- r.className = "ttcb-form", r.addEventListener("submit", (e) => {
3137
+ t.textContent = Ht(e.primaryColor ?? "#2563EB", e.theme ?? "auto"), this.shadow.appendChild(t), this.fab = document.createElement("button"), this.fab.className = `ttcb-fab ${this.position}`, this.fab.setAttribute("aria-label", "Open chat"), this.fab.innerHTML = Kt(), this.fab.addEventListener("click", () => this.toggle()), this.shadow.appendChild(this.fab), this.panel = document.createElement("div"), this.panel.className = `ttcb-panel ${this.position} hidden ttcb-mode-compact`, this.panel.tabIndex = -1, 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", this.pendingTray = document.createElement("div"), this.pendingTray.className = "ttcb-pending-tray", this.pendingTray.setAttribute("role", "list"), this.pendingTray.setAttribute("aria-label", "Files to send"), this.footer.appendChild(this.pendingTray), this.composeError = document.createElement("p"), this.composeError.className = "ttcb-compose-error", this.composeError.setAttribute("role", "alert"), this.footer.appendChild(this.composeError), this.footer.appendChild(this.buildVoiceBar()), this.footer.appendChild(this.buildVoicePreview());
3138
+ let n = document.createElement("form");
3139
+ n.className = "ttcb-form", n.addEventListener("submit", (e) => {
2585
3140
  e.preventDefault(), this.handleSend();
2586
- }), 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 = vt(), 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) => {
2587
- if (!this.countryOpen) return;
3141
+ }), this.composeForm = n, n.appendChild(this.buildAttachControls()), 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 = Jt(), this.sendBtn.setAttribute("aria-label", "Send message"), this.micBtn = document.createElement("button"), this.micBtn.type = "button", this.micBtn.className = "ttcb-mic-btn", this.micBtn.setAttribute("aria-label", "Record voice message"), this.micBtn.title = "Record voice message", this.micBtn.innerHTML = cn(), this.micBtn.addEventListener("click", () => void this.startVoice()), n.appendChild(this.input), n.appendChild(this.micBtn), n.appendChild(this.sendBtn), this.footer.appendChild(n), this.panel.appendChild(this.footer), this.shadow.appendChild(this.panel), this.shadow.addEventListener("click", (e) => {
2588
3142
  let t = e.target;
2589
- t && (this.dialBtn.contains(t) || this.countryPopover.contains(t)) || this.closeCountryPopover();
3143
+ this.attachMenuOpen && !(t && (this.attachBtn.contains(t) || this.attachMenu.contains(t))) && this.closeAttachMenu(), this.countryOpen && (t && (this.dialBtn.contains(t) || this.countryPopover.contains(t)) || this.closeCountryPopover());
3144
+ }), this.panel.addEventListener("keydown", (e) => {
3145
+ e.key === "Escape" && this.attachMenuOpen && (e.stopPropagation(), this.closeAttachMenu(), this.attachBtn.focus());
2590
3146
  }), this.attachToDocument(), this.showInitialLoading();
2591
3147
  }
2592
3148
  reveal() {
@@ -2598,13 +3154,13 @@ var At = class {
2598
3154
  let n = document.createElement("div");
2599
3155
  n.className = "ttcb-avatar-wrap";
2600
3156
  let r = document.createElement("div");
2601
- r.className = "ttcb-avatar", r.innerHTML = X(), n.appendChild(r);
3157
+ r.className = "ttcb-avatar", r.innerHTML = Z(), n.appendChild(r);
2602
3158
  let i = document.createElement("div");
2603
3159
  i.className = "ttcb-header-main";
2604
3160
  let a = document.createElement("div");
2605
3161
  a.className = "ttcb-header-title-row", this.headerTitle = document.createElement("span"), this.headerTitle.className = "ttcb-header-title", this.headerTitle.textContent = e.chatbotName ?? "AI Assistant";
2606
3162
  let o = document.createElement("span");
2607
- o.className = "ttcb-verified", o.setAttribute("aria-label", "Verified"), o.innerHTML = Tt(), a.appendChild(this.headerTitle), a.appendChild(o);
3163
+ o.className = "ttcb-verified", o.setAttribute("aria-label", "Verified"), o.innerHTML = tn(), a.appendChild(this.headerTitle), a.appendChild(o);
2608
3164
  let s = document.createElement("div");
2609
3165
  s.className = "ttcb-header-meta";
2610
3166
  let c = document.createElement("span");
@@ -2612,11 +3168,146 @@ var At = class {
2612
3168
  let l = document.createElement("span");
2613
3169
  l.className = "ttcb-meta-sep", l.setAttribute("aria-hidden", "true");
2614
3170
  let u = document.createElement("span");
2615
- u.className = "ttcb-meta-replies", u.innerHTML = `${Et()}<span>Replies instantly</span>`, s.appendChild(c), s.appendChild(l), s.appendChild(u), i.appendChild(a), i.appendChild(s);
3171
+ u.className = "ttcb-meta-replies", u.innerHTML = `${nn()}<span>Replies instantly</span>`, s.appendChild(c), s.appendChild(l), s.appendChild(u), i.appendChild(a), i.appendChild(s);
2616
3172
  let d = document.createElement("div");
2617
- 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 = Dt(), 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 = ht(), this.newSessionBtn.addEventListener("click", () => this.callbacks.onReset());
3173
+ 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 = rn(), 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());
2618
3174
  let f = document.createElement("button");
2619
- return f.className = "ttcb-close-btn", f.setAttribute("aria-label", "Close chat"), f.innerHTML = _t(), 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;
3175
+ return f.className = "ttcb-close-btn", f.setAttribute("aria-label", "Close chat"), f.innerHTML = qt(), 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;
3176
+ }
3177
+ buildAttachControls() {
3178
+ let e = document.createElement("div");
3179
+ e.className = "ttcb-attach", this.attachBtn = document.createElement("button"), this.attachBtn.type = "button", this.attachBtn.className = "ttcb-attach-btn", this.attachBtn.setAttribute("aria-label", "Add attachment"), this.attachBtn.setAttribute("aria-haspopup", "menu"), this.attachBtn.setAttribute("aria-expanded", "false"), this.attachBtn.title = "Add attachment", this.attachBtn.innerHTML = an(), this.attachBtn.addEventListener("click", (e) => {
3180
+ e.preventDefault(), e.stopPropagation(), this.toggleAttachMenu();
3181
+ }), this.attachMenu = document.createElement("div"), this.attachMenu.className = "ttcb-attach-menu", this.attachMenu.setAttribute("role", "menu"), this.attachFileInput = this.createFileInput(hn, "Choose files"), this.attachPhotoInput = this.createFileInput(gn, "Choose photos");
3182
+ let t = [{
3183
+ label: "Attachment",
3184
+ icon: on(),
3185
+ input: this.attachFileInput
3186
+ }, {
3187
+ label: "Photo",
3188
+ icon: sn(),
3189
+ input: this.attachPhotoInput
3190
+ }];
3191
+ for (let e of t) {
3192
+ let t = document.createElement("button");
3193
+ t.type = "button", t.className = "ttcb-attach-item", t.setAttribute("role", "menuitem"), t.innerHTML = `${e.icon}<span>${e.label}</span>`, t.addEventListener("click", () => {
3194
+ this.closeAttachMenu(), e.input.click();
3195
+ }), this.attachMenu.appendChild(t);
3196
+ }
3197
+ return e.appendChild(this.attachBtn), e.appendChild(this.attachMenu), e.appendChild(this.attachFileInput), e.appendChild(this.attachPhotoInput), e;
3198
+ }
3199
+ createFileInput(e, t) {
3200
+ let n = document.createElement("input");
3201
+ return n.type = "file", n.multiple = !0, n.accept = e, n.className = "ttcb-file-input", n.tabIndex = -1, n.setAttribute("aria-label", t), n.addEventListener("change", () => {
3202
+ this.addPendingFiles(Array.from(n.files ?? [])), n.value = "";
3203
+ }), n;
3204
+ }
3205
+ toggleAttachMenu() {
3206
+ this.attachMenuOpen ? this.closeAttachMenu() : this.openAttachMenu();
3207
+ }
3208
+ openAttachMenu() {
3209
+ if (this.attachBtn.disabled) return;
3210
+ this.attachMenuOpen = !0, this.attachMenu.classList.add("open"), this.attachBtn.setAttribute("aria-expanded", "true");
3211
+ let e = this.attachMenu.querySelector(".ttcb-attach-item");
3212
+ queueMicrotask(() => e?.focus());
3213
+ }
3214
+ closeAttachMenu() {
3215
+ this.attachMenuOpen && (this.attachMenuOpen = !1, this.attachMenu.classList.remove("open"), this.attachBtn.setAttribute("aria-expanded", "false"));
3216
+ }
3217
+ addPendingFiles(e) {
3218
+ if (e.length === 0) return;
3219
+ let t = d([...this.pendingFiles.map((e) => e.file), ...e]);
3220
+ if (t) this.showComposeError(t);
3221
+ else {
3222
+ this.showComposeError("");
3223
+ for (let t of e) {
3224
+ let e = t.type.startsWith("image/") ? p(t) : "";
3225
+ this.pendingFiles.push({
3226
+ file: t,
3227
+ previewUrl: e
3228
+ });
3229
+ }
3230
+ this.renderPendingTray(), this.input.focus();
3231
+ }
3232
+ }
3233
+ removePendingFile(e) {
3234
+ let [t] = this.pendingFiles.splice(e, 1);
3235
+ t && m(t.previewUrl), this.renderPendingTray(), this.input.focus();
3236
+ }
3237
+ clearPendingFiles() {
3238
+ for (let e of this.pendingFiles) m(e.previewUrl);
3239
+ this.pendingFiles = [], this.renderPendingTray();
3240
+ }
3241
+ renderPendingTray() {
3242
+ this.pendingTray.innerHTML = "", this.pendingTray.classList.toggle("visible", this.pendingFiles.length > 0), this.pendingFiles.forEach((e, t) => {
3243
+ let n = document.createElement("div");
3244
+ if (n.className = "ttcb-pending-item", n.setAttribute("role", "listitem"), e.previewUrl) {
3245
+ let t = document.createElement("img");
3246
+ t.className = "ttcb-pending-thumb", t.src = e.previewUrl, t.alt = "", n.appendChild(t);
3247
+ } else {
3248
+ let e = document.createElement("span");
3249
+ e.className = "ttcb-pending-icon", e.setAttribute("aria-hidden", "true"), e.innerHTML = dn(), n.appendChild(e);
3250
+ }
3251
+ let r = document.createElement("span");
3252
+ r.className = "ttcb-pending-name", r.textContent = e.file.name || "attachment", r.title = e.file.name, n.appendChild(r);
3253
+ let i = document.createElement("button");
3254
+ i.type = "button", i.className = "ttcb-pending-remove", i.setAttribute("aria-label", `Remove ${e.file.name || "attachment"}`), i.innerHTML = qt(), i.addEventListener("click", () => this.removePendingFile(t)), n.appendChild(i), this.pendingTray.appendChild(n);
3255
+ });
3256
+ }
3257
+ buildVoiceBar() {
3258
+ this.voiceBar = document.createElement("div"), this.voiceBar.className = "ttcb-voice-bar", this.voiceBar.setAttribute("role", "group"), this.voiceBar.setAttribute("aria-label", "Recording voice message");
3259
+ let e = document.createElement("span");
3260
+ e.className = "ttcb-voice-dot", e.setAttribute("aria-hidden", "true"), this.voiceTime = document.createElement("span"), this.voiceTime.className = "ttcb-voice-time", this.voiceTime.setAttribute("role", "timer"), this.voiceTime.textContent = "0:00";
3261
+ let t = document.createElement("div");
3262
+ return t.className = "ttcb-voice-meter", t.setAttribute("aria-hidden", "true"), this.voiceLevel = document.createElement("span"), this.voiceLevel.className = "ttcb-voice-level", t.appendChild(this.voiceLevel), this.voiceCancelBtn = this.createVoiceButton("Cancel recording", un(), () => this.cancelVoice()), this.voiceStopBtn = this.createVoiceButton("Stop recording", ln(), () => void this.stopVoice()), this.voiceStopBtn.classList.add("primary"), this.voiceBar.appendChild(e), this.voiceBar.appendChild(this.voiceTime), this.voiceBar.appendChild(t), this.voiceBar.appendChild(this.voiceCancelBtn), this.voiceBar.appendChild(this.voiceStopBtn), this.voiceBar;
3263
+ }
3264
+ buildVoicePreview() {
3265
+ return this.voicePreview = document.createElement("div"), this.voicePreview.className = "ttcb-voice-preview", this.voicePreview.setAttribute("role", "group"), this.voicePreview.setAttribute("aria-label", "Voice message preview"), this.voiceAudio = document.createElement("audio"), this.voiceAudio.className = "ttcb-voice-audio", this.voiceAudio.controls = !0, this.voiceAudio.preload = "metadata", this.voiceAudio.setAttribute("aria-label", "Recorded voice message"), this.voicePreviewTime = document.createElement("span"), this.voicePreviewTime.className = "ttcb-voice-time", this.voiceDiscardBtn = this.createVoiceButton("Discard voice message", un(), () => this.cancelVoice()), this.voiceSendBtn = this.createVoiceButton("Send voice message", Jt(), () => this.sendVoice()), this.voiceSendBtn.classList.add("primary"), this.voicePreview.appendChild(this.voiceAudio), this.voicePreview.appendChild(this.voicePreviewTime), this.voicePreview.appendChild(this.voiceDiscardBtn), this.voicePreview.appendChild(this.voiceSendBtn), this.voicePreview;
3266
+ }
3267
+ createVoiceButton(e, t, n) {
3268
+ let r = document.createElement("button");
3269
+ return r.type = "button", r.className = "ttcb-voice-btn", r.setAttribute("aria-label", e), r.title = e, r.innerHTML = t, r.addEventListener("click", n), r;
3270
+ }
3271
+ async startVoice() {
3272
+ if (!this.micBtn.disabled) {
3273
+ if (this.closeAttachMenu(), this.showComposeError(""), !Y.isSupported()) this.showComposeError("Voice messages are not supported in this browser.");
3274
+ else {
3275
+ this.recorder?.destroy(), this.recorder = new Y((e) => this.renderVoice(e));
3276
+ try {
3277
+ await this.recorder.start();
3278
+ } catch (e) {
3279
+ this.showComposeError(e instanceof Error ? e.message : "Could not start recording."), this.recorder.destroy(), this.recorder = null, this.renderVoice({
3280
+ state: "idle",
3281
+ elapsedSeconds: 0,
3282
+ level: 0,
3283
+ result: null
3284
+ });
3285
+ }
3286
+ }
3287
+ }
3288
+ }
3289
+ async stopVoice() {
3290
+ await this.recorder?.stop();
3291
+ }
3292
+ cancelVoice() {
3293
+ this.recorder?.cancel(), this.recorder?.destroy(), this.recorder = null, this.renderVoice({
3294
+ state: "idle",
3295
+ elapsedSeconds: 0,
3296
+ level: 0,
3297
+ result: null
3298
+ }), this.input.focus();
3299
+ }
3300
+ sendVoice() {
3301
+ let e = this.recorder?.getSnapshot().result;
3302
+ e && (this.cancelVoice(), this.callbacks.onSendVoice(e));
3303
+ }
3304
+ renderVoice(e) {
3305
+ if (this.destroyed) return;
3306
+ let { state: t } = e;
3307
+ this.composeForm.classList.toggle("hidden", t !== "idle"), this.voiceBar.classList.toggle("visible", t === "recording"), this.voicePreview.classList.toggle("visible", t === "preview"), t === "recording" ? (this.voiceTime.textContent = _(e.elapsedSeconds), this.voiceLevel.style.width = `${Math.max(4, Math.round(e.level * 100))}%`) : (m(this.voicePreviewUrl), this.voicePreviewUrl = "", this.voiceAudio.removeAttribute("src"), t === "preview" && e.result && (this.voicePreviewUrl = p(new File([e.result.blob], "voice-preview", { type: e.result.blob.type })), this.voicePreviewUrl && (this.voiceAudio.src = this.voicePreviewUrl), this.voicePreviewTime.textContent = _(e.result.durationSeconds), queueMicrotask(() => this.voiceSendBtn.focus())));
3308
+ }
3309
+ showComposeError(e) {
3310
+ this.composeError.textContent = e, this.composeError.classList.toggle("visible", !!e);
2620
3311
  }
2621
3312
  setPanelMode(e) {
2622
3313
  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());
@@ -2633,7 +3324,7 @@ var At = class {
2633
3324
  placeholder: "Your name",
2634
3325
  type: "text",
2635
3326
  autocomplete: "name",
2636
- icon: bt()
3327
+ icon: Xt()
2637
3328
  }), this.createPhoneField(t), this.emailInput = this.createIconField(t, {
2638
3329
  id: "email",
2639
3330
  label: "Email (optional)",
@@ -2642,10 +3333,10 @@ var At = class {
2642
3333
  placeholder: "Email (optional)",
2643
3334
  type: "email",
2644
3335
  autocomplete: "email",
2645
- icon: xt()
2646
- }), 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>${Ct()}`, t.appendChild(this.identifySubmit), e.appendChild(t);
3336
+ icon: Zt()
3337
+ }), 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>${$t()}`, t.appendChild(this.identifySubmit), e.appendChild(t);
2647
3338
  let n = document.createElement("div");
2648
- n.className = "ttcb-trust", n.innerHTML = `${wt()}<span>Encrypted connection • No spam, ever</span>`, e.appendChild(n);
3339
+ n.className = "ttcb-trust", n.innerHTML = `${en()}<span>Encrypted connection • No spam, ever</span>`, e.appendChild(n);
2649
3340
  }
2650
3341
  createIconField(e, t) {
2651
3342
  let n = document.createElement("div");
@@ -2675,7 +3366,7 @@ var At = class {
2675
3366
  let a = document.createElement("div");
2676
3367
  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);
2677
3368
  let o = document.createElement("span");
2678
- o.setAttribute("aria-hidden", "true"), o.innerHTML = St(), this.dialBtn.appendChild(o), this.dialBtn.addEventListener("click", (e) => {
3369
+ o.setAttribute("aria-hidden", "true"), o.innerHTML = Qt(), this.dialBtn.appendChild(o), this.dialBtn.addEventListener("click", (e) => {
2679
3370
  e.preventDefault(), e.stopPropagation(), this.toggleCountryPopover();
2680
3371
  }), 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);
2681
3372
  }
@@ -2692,7 +3383,7 @@ var At = class {
2692
3383
  this.countryOpen = !1, this.countryPopover.classList.remove("open"), this.dialBtn.setAttribute("aria-expanded", "false");
2693
3384
  }
2694
3385
  renderCountryList() {
2695
- let e = this.countrySearch.value.trim().toLowerCase(), t = J.filter((t) => !e || t.name.toLowerCase().includes(e) || t.dial.includes(e) || t.iso.toLowerCase().includes(e) || `+${t.dial}`.includes(e));
3386
+ let e = this.countrySearch.value.trim().toLowerCase(), t = X.filter((t) => !e || t.name.toLowerCase().includes(e) || t.dial.includes(e) || t.iso.toLowerCase().includes(e) || `+${t.dial}`.includes(e));
2696
3387
  this.countryList.innerHTML = "";
2697
3388
  for (let e of t) {
2698
3389
  let t = document.createElement("button");
@@ -2724,7 +3415,7 @@ var At = class {
2724
3415
  let t = document.createElement("div");
2725
3416
  t.className = "ttcb-empty", t.id = "ttcb-empty";
2726
3417
  let n = document.createElement("div");
2727
- n.className = "ttcb-empty-icon", n.innerHTML = X();
3418
+ n.className = "ttcb-empty-icon", n.innerHTML = Z();
2728
3419
  let r = document.createElement("p"), i = document.createElement("strong");
2729
3420
  i.textContent = e, r.appendChild(document.createTextNode("Welcome to ")), r.appendChild(i);
2730
3421
  let a = document.createElement("p");
@@ -2736,10 +3427,15 @@ var At = class {
2736
3427
  }
2737
3428
  handleSend() {
2738
3429
  let e = this.input.value.trim();
2739
- e && !this.sendBtn.disabled && (this.input.value = "", this.callbacks.onSend(e), this.input.focus());
3430
+ if (!this.sendBtn.disabled) {
3431
+ if (this.pendingFiles.length > 0) {
3432
+ let t = this.pendingFiles.map((e) => e.file);
3433
+ this.clearPendingFiles(), this.showComposeError(""), this.input.value = "", this.callbacks.onSendAttachments(t, e), this.input.focus();
3434
+ } else e && (this.input.value = "", this.callbacks.onSend(e), this.input.focus());
3435
+ }
2740
3436
  }
2741
3437
  handleIdentifySubmit() {
2742
- let e = this.nameInput.value.trim(), t = ft(this.selectedCountry.dial, this.phoneInput.value), n = this.emailInput.value.trim();
3438
+ let e = this.nameInput.value.trim(), t = Bt(this.selectedCountry.dial, this.phoneInput.value), n = this.emailInput.value.trim();
2743
3439
  !e || !t ? this.showIdentifyError("Name and phone are required.") : (this.showIdentifyError(""), this.callbacks.onIdentify({
2744
3440
  name: e,
2745
3441
  phone: t,
@@ -2748,38 +3444,70 @@ var At = class {
2748
3444
  }
2749
3445
  appendMessage(e) {
2750
3446
  this.removeEmptyState();
2751
- let t = "message" in e ? e.message : e, n = Ot(t.content, t.type);
2752
- this.messagesContainer.appendChild(n), this.scrollToBottom();
3447
+ let t = this.buildMessage(e);
3448
+ this.messagesContainer.appendChild(t), this.scrollToBottom();
3449
+ }
3450
+ replaceMessage(e, t) {
3451
+ let n = this.findMessageEl(e);
3452
+ n ? (n.replaceWith(this.buildMessage(t)), this.scrollToBottom()) : this.appendMessage(t);
3453
+ }
3454
+ removeMessage(e) {
3455
+ this.findMessageEl(e)?.remove();
3456
+ }
3457
+ buildMessage(e) {
3458
+ if ("message" in e) {
3459
+ let t = pn({
3460
+ ...e.message,
3461
+ pending: e.pending
3462
+ });
3463
+ return t.dataset.msgId = String(e.id), t;
3464
+ }
3465
+ return pn(e);
3466
+ }
3467
+ findMessageEl(e) {
3468
+ for (let t of this.messagesContainer.querySelectorAll(".ttcb-msg")) if (t.dataset.msgId === String(e)) return t;
3469
+ return null;
2753
3470
  }
2754
3471
  setMessages(e) {
2755
3472
  if (this.messagesContainer.innerHTML = "", e.length !== 0) {
2756
- for (let t of e) {
2757
- let e = Ot(t.message.content, t.message.type);
2758
- this.messagesContainer.appendChild(e);
2759
- }
3473
+ for (let t of e) this.messagesContainer.appendChild(this.buildMessage(t));
2760
3474
  this.scrollToBottom();
2761
3475
  }
2762
3476
  }
2763
3477
  setLoading(e) {
2764
- if (this.sendBtn.disabled = e || this.input.disabled, e) this.shadow.getElementById("ttcb-typing") || (this.messagesContainer.appendChild(kt()), this.scrollToBottom()), this.input.focus();
3478
+ if (this.sendBtn.disabled = e || this.input.disabled, this.attachBtn.disabled = e || this.input.disabled, this.micBtn.disabled = e || this.input.disabled, e) this.closeAttachMenu(), this.shadow.getElementById("ttcb-typing") || (this.messagesContainer.appendChild(mn()), this.scrollToBottom()), this.isFullScreen() || this.input.focus();
2765
3479
  else {
2766
3480
  let e = this.shadow.getElementById("ttcb-typing");
2767
- e && e.remove(), this.input.disabled || this.input.focus();
3481
+ e && e.remove(), !this.input.disabled && !this.isFullScreen() && this.input.focus();
2768
3482
  }
2769
3483
  }
2770
3484
  setIdentifyLoading(e) {
2771
3485
  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);
2772
3486
  for (let t of this.identifyContainer.querySelectorAll(".ttcb-input-wrap")) t.classList.toggle("disabled", e);
2773
- this.identifySubmit.innerHTML = e ? "<span>Starting…</span>" : `<span>Start Chatting</span>${Ct()}`, e && this.closeCountryPopover();
3487
+ this.identifySubmit.innerHTML = e ? "<span>Starting…</span>" : `<span>Start Chatting</span>${$t()}`, e && this.closeCountryPopover();
2774
3488
  }
2775
3489
  showIdentifyError(e) {
2776
3490
  this.identifyError.textContent = e;
2777
3491
  }
2778
3492
  open() {
2779
- this.isOpen = !0, this.panel.classList.remove("hidden"), this.identifyContainer.classList.contains("visible") ? this.nameInput.focus() : this.input.focus(), this.callbacks.onOpen();
3493
+ this.isOpen = !0, this.startViewportSync(), this.panel.classList.remove("hidden"), this.fab.classList.add("ttcb-open"), this.isFullScreen() ? this.panel.focus({ preventScroll: !0 }) : this.identifyContainer.classList.contains("visible") ? this.nameInput.focus() : this.input.focus(), this.callbacks.onOpen();
2780
3494
  }
2781
3495
  close() {
2782
- this.isOpen = !1, this.closeCountryPopover(), this.panel.classList.add("hidden"), this.callbacks.onClose();
3496
+ this.isOpen = !1, this.closeCountryPopover(), this.closeAttachMenu(), this.panel.classList.add("hidden"), this.fab.classList.remove("ttcb-open"), this.stopViewportSync?.(), this.stopViewportSync = null, this.fab.focus({ preventScroll: !0 }), this.callbacks.onClose();
3497
+ }
3498
+ isFullScreen() {
3499
+ return typeof window.matchMedia == "function" && window.matchMedia("(max-width: 640px), (max-height: 500px) and (pointer: coarse)").matches;
3500
+ }
3501
+ startViewportSync() {
3502
+ let e = window.visualViewport;
3503
+ if (!e || this.stopViewportSync) return;
3504
+ let t = () => {
3505
+ let t = this.messagesContainer, n = t.scrollHeight - t.scrollTop - t.clientHeight < 40;
3506
+ this.panel.style.setProperty("--ttcb-vv-top", `${e.offsetTop}px`), this.panel.style.setProperty("--ttcb-vv-left", `${e.offsetLeft}px`), this.panel.style.setProperty("--ttcb-vv-width", `${e.width}px`), this.panel.style.setProperty("--ttcb-vv-height", `${e.height}px`), n && this.scrollToBottom();
3507
+ };
3508
+ e.addEventListener("resize", t), e.addEventListener("scroll", t), t(), this.stopViewportSync = () => {
3509
+ e.removeEventListener("resize", t), e.removeEventListener("scroll", t);
3510
+ };
2783
3511
  }
2784
3512
  toggle() {
2785
3513
  this.isOpen ? this.close() : this.open();
@@ -2794,11 +3522,11 @@ var At = class {
2794
3522
  }) : this.showEmptyState(e.chatbotName ?? "AI Assistant"), this.setMode("ai");
2795
3523
  }
2796
3524
  clearMessages(e) {
2797
- this.messagesContainer.innerHTML = "", this.showEmptyState(e);
3525
+ this.messagesContainer.innerHTML = "", this.clearPendingFiles(), this.showComposeError(""), this.showEmptyState(e);
2798
3526
  }
2799
3527
  setMode(e, t) {
2800
3528
  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";
2801
- 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();
3529
+ this.requestHumanBtn.classList.toggle("hidden", !a), this.newSessionBtn.classList.toggle("hidden", !o), this.input.disabled = s, s ? (this.sendBtn.disabled = !0, this.attachBtn.disabled = !0, this.micBtn.disabled = !0, this.closeAttachMenu(), this.clearPendingFiles(), this.recorder && this.cancelVoice(), this.showComposeError("")) : this.shadow.getElementById("ttcb-typing") || (this.sendBtn.disabled = !1, this.attachBtn.disabled = !1, this.micBtn.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();
2802
3530
  }
2803
3531
  showModeBanner(e, t) {
2804
3532
  this.modeBanner.textContent = e, this.modeBanner.className = `ttcb-mode-banner visible ${t}`;
@@ -2807,13 +3535,13 @@ var At = class {
2807
3535
  this.modeBanner.textContent = "", this.modeBanner.className = "ttcb-mode-banner";
2808
3536
  }
2809
3537
  destroy() {
2810
- this.destroyed = !0, this.host.remove();
3538
+ this.destroyed = !0, this.stopViewportSync?.(), this.stopViewportSync = null, this.clearPendingFiles(), this.recorder?.destroy(), this.recorder = null, m(this.voicePreviewUrl), this.voicePreviewUrl = "", this.host.remove();
2811
3539
  }
2812
3540
  scrollToBottom() {
2813
3541
  this.messagesContainer.scrollTop = this.messagesContainer.scrollHeight;
2814
3542
  }
2815
- }, jt = {
2816
- apiBaseUrl: o,
3543
+ }, vn = {
3544
+ apiBaseUrl: c,
2817
3545
  chatbotName: "AI Assistant",
2818
3546
  primaryColor: "#2563EB",
2819
3547
  theme: "auto",
@@ -2824,23 +3552,23 @@ var At = class {
2824
3552
  sessionId: "",
2825
3553
  requestTimeoutMs: n
2826
3554
  };
2827
- function Mt(e) {
3555
+ function yn(e) {
2828
3556
  return Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0));
2829
3557
  }
2830
- var Nt = [
3558
+ var bn = [
2831
3559
  5e3,
2832
3560
  15e3,
2833
3561
  3e4,
2834
3562
  6e4
2835
3563
  ];
2836
- function Pt(e) {
2837
- return i(e) ? e.status === 0 || e.status >= 500 || e.apiError.code === "BAD_RESPONSE" : !1;
3564
+ function xn(e) {
3565
+ return o(e) ? e.status === 0 || e.status >= 500 || e.apiError.code === "BAD_RESPONSE" : !1;
2838
3566
  }
2839
- function Ft(e) {
2840
- return i(e) ? e.apiError.message : e instanceof Error ? e.message : "Failed to load chatbot config.";
3567
+ function Sn(e) {
3568
+ return o(e) ? e.apiError.message : e instanceof Error ? e.message : "Failed to load chatbot config.";
2841
3569
  }
2842
- var It = 0, Z = () => Date.now() * 1e3 + It++ % 1e3;
2843
- function Lt(e) {
3570
+ var Cn = 0, Q = () => Date.now() * 1e3 + Cn++ % 1e3;
3571
+ function wn(e) {
2844
3572
  if (!e || typeof e != "object") return null;
2845
3573
  let t = e;
2846
3574
  if (typeof t.textMessage == "string" && t.textMessage.trim()) return t.textMessage.trim();
@@ -2852,7 +3580,11 @@ function Lt(e) {
2852
3580
  }
2853
3581
  return null;
2854
3582
  }
2855
- function Rt(e) {
3583
+ function Tn(e) {
3584
+ let t = (e.attachments ?? []).map((e) => e.url).join("");
3585
+ return `${e.content}\u0000${t}`;
3586
+ }
3587
+ function En(e) {
2856
3588
  if (!e || typeof e != "object") return null;
2857
3589
  let t = e;
2858
3590
  if (typeof t.id == "string" && t.id) return t.id;
@@ -2862,9 +3594,9 @@ function Rt(e) {
2862
3594
  }
2863
3595
  return null;
2864
3596
  }
2865
- var Q = class {
3597
+ var Dn = class {
2866
3598
  constructor() {
2867
- this.emitter = new s(), this.visitorTokens = new ut(), this.widget = null, this.sdkSocket = null, this.callerSetName = !1, this.hasActiveTicket = !1, this.retryTimer = null, this.lastPushId = null, this.initToken = 0, this._state = {
3599
+ this.emitter = new fe(), this.visitorTokens = new Mt(), this.widget = null, this.sdkSocket = null, this.callerSetName = !1, this.hasActiveTicket = !1, this.retryTimer = null, this.lastPushId = null, this.initToken = 0, this._state = {
2868
3600
  isOpen: !1,
2869
3601
  isLoading: !1,
2870
3602
  isReady: !1,
@@ -2899,9 +3631,9 @@ var Q = class {
2899
3631
  if (!e.apiKey) throw Error("[onedeskpro-chatbot] `apiKey` is required to initialise the chatbot.");
2900
3632
  let t = ++this.initToken;
2901
3633
  this.clearRetry(), this.disconnectSdkSocket(), this.widget?.destroy(), this.widget = null, this.callerSetName = e.chatbotName !== void 0, this.options = {
2902
- ...jt,
2903
- ...Mt(e)
2904
- }, this.apiClient = new a({
3634
+ ...vn,
3635
+ ...yn(e)
3636
+ }, this.apiClient = new s({
2905
3637
  baseUrl: this.options.apiBaseUrl,
2906
3638
  apiKey: this.options.apiKey,
2907
3639
  timeoutMs: this.options.requestTimeoutMs
@@ -2922,13 +3654,13 @@ var Q = class {
2922
3654
  n = await this.apiClient.fetchConfig();
2923
3655
  } catch (n) {
2924
3656
  if (e !== this.initToken) return;
2925
- if (Pt(n)) {
3657
+ if (xn(n)) {
2926
3658
  this.setState({
2927
3659
  isReady: !1,
2928
3660
  blockReason: "server-unavailable",
2929
- error: Ft(n)
3661
+ error: Sn(n)
2930
3662
  });
2931
- let r = Nt[t];
3663
+ let r = bn[t];
2932
3664
  if (r !== void 0) {
2933
3665
  this.retryTimer = setTimeout(() => {
2934
3666
  this.retryTimer = null, this.checkReadiness(e, t + 1);
@@ -2949,8 +3681,10 @@ var Q = class {
2949
3681
  }), i ? (this.mountWidget(), this.visitorTokens.setScope(n.agentId), await this.resolveVisitorGate(e), e === this.initToken && (this.widget?.reveal(), this.emitter.emit("ready"))) : this.emitter.emit("ready");
2950
3682
  }
2951
3683
  mountWidget() {
2952
- typeof window < "u" && typeof document < "u" && (this.widget = new At(this.options, {
3684
+ typeof window < "u" && typeof document < "u" && (this.widget = new _n(this.options, {
2953
3685
  onSend: (e) => void this.sendMessage(e),
3686
+ onSendAttachments: (e, t) => void this.sendAttachments(e, t),
3687
+ onSendVoice: (e) => void this.sendVoice(e),
2954
3688
  onIdentify: (e) => void this.submitIdentify(e),
2955
3689
  onOpen: () => {
2956
3690
  this.setState({ isOpen: !0 }), this.emitter.emit("open");
@@ -2966,11 +3700,11 @@ var Q = class {
2966
3700
  this.retryTimer !== null && (clearTimeout(this.retryTimer), this.retryTimer = null);
2967
3701
  }
2968
3702
  handleConfigError(e) {
2969
- let t = (i(e) ? e : null)?.apiError.code === "agent_not_assigned" ? "no-agent" : null;
3703
+ let t = (o(e) ? e : null)?.apiError.code === "agent_not_assigned" ? "no-agent" : null;
2970
3704
  this.setState({
2971
3705
  isReady: !1,
2972
3706
  blockReason: t,
2973
- error: Ft(e)
3707
+ error: Sn(e)
2974
3708
  });
2975
3709
  }
2976
3710
  async resolveVisitorGate(e) {
@@ -3002,7 +3736,7 @@ var Q = class {
3002
3736
  }), this.widget?.readyToChat(this.options), this.connectSdkSocket(e), await this.restoreTicketStatus(e, n);
3003
3737
  }
3004
3738
  connectSdkSocket(e) {
3005
- this.sdkSocket ||= new ot(), this.sdkSocket.connect({
3739
+ this.sdkSocket ||= new Ot(), this.sdkSocket.connect({
3006
3740
  baseUrl: this.options.apiBaseUrl,
3007
3741
  apiKey: this.options.apiKey,
3008
3742
  visitorToken: e,
@@ -3032,20 +3766,24 @@ var Q = class {
3032
3766
  }
3033
3767
  handleMessageReceive(e) {
3034
3768
  if (this._state.mode === "ai") return;
3035
- let t = Lt(e);
3036
- if (!t) return;
3037
- let n = Rt(e), r = this._state.messages[this._state.messages.length - 1];
3038
- if (r?.message.content === t && (r.message.type === "ai" || r.message.type === "agent" && (!n || n === this.lastPushId))) return;
3039
- this.lastPushId = n;
3040
- let i = this.visitorTokens.get() ?? this._state.visitorToken ?? "", a = {
3041
- id: Z(),
3042
- sessionId: i,
3769
+ let t = wn(e) ?? "", n = ne(e);
3770
+ if (!t && n.length === 0) return;
3771
+ let r = En(e), i = this._state.messages[this._state.messages.length - 1];
3772
+ if (i && Tn(i.message) === Tn({
3773
+ content: t,
3774
+ attachments: n
3775
+ }) && (i.message.type === "ai" || i.message.type === "agent" && (!r || r === this.lastPushId))) return;
3776
+ this.lastPushId = r;
3777
+ let a = this.visitorTokens.get() ?? this._state.visitorToken ?? "", o = {
3778
+ id: Q(),
3779
+ sessionId: a,
3043
3780
  message: {
3044
3781
  type: "agent",
3045
- content: t
3782
+ content: t,
3783
+ ...n.length > 0 ? { attachments: n } : {}
3046
3784
  }
3047
3785
  };
3048
- this.setState({ messages: [...this._state.messages, a] }), this.widget?.appendMessage(a), this.emitter.emit("message", a);
3786
+ this.setState({ messages: [...this._state.messages, o] }), this.widget?.appendMessage(o), this.emitter.emit("message", o);
3049
3787
  }
3050
3788
  async submitIdentify(e) {
3051
3789
  if (!this.apiClient || this._state.isLoading || !this._state.isReady) return;
@@ -3088,9 +3826,26 @@ var Q = class {
3088
3826
  this.setState({ isLoading: !1 });
3089
3827
  }
3090
3828
  }
3091
- async sendMessage(e) {
3829
+ requireVisitorToken(e) {
3092
3830
  let t = this.visitorTokens.get() ?? this._state.visitorToken;
3093
- if (!this.apiClient || !t) throw Error("[onedeskpro-chatbot] Identify before sendMessage().");
3831
+ if (!this.apiClient || !t) throw Error(`[onedeskpro-chatbot] Identify before ${e}().`);
3832
+ return t;
3833
+ }
3834
+ pushLocalMessage(e) {
3835
+ this.setState({
3836
+ messages: [...this._state.messages, e],
3837
+ isLoading: !0,
3838
+ error: null
3839
+ }), this.widget?.appendMessage(e), this.emitter.emit("message", e);
3840
+ }
3841
+ replaceMessage(e, t) {
3842
+ this.setState({ messages: this._state.messages.map((n) => n.id === e ? t : n) }), this.widget?.replaceMessage(e, t);
3843
+ }
3844
+ removeMessage(e) {
3845
+ this.setState({ messages: this._state.messages.filter((t) => t.id !== e) }), this.widget?.removeMessage(e);
3846
+ }
3847
+ async sendMessage(e) {
3848
+ let t = this.requireVisitorToken("sendMessage");
3094
3849
  if (this._state.mode === "closed") {
3095
3850
  this.setState({ error: "Conversation is closed" });
3096
3851
  return;
@@ -3098,41 +3853,142 @@ var Q = class {
3098
3853
  let n = e.trim();
3099
3854
  if (!n || this._state.isLoading || this._state.needsIdentify) return;
3100
3855
  let r = {
3101
- id: Z(),
3856
+ id: Q(),
3102
3857
  sessionId: t,
3103
3858
  message: {
3104
3859
  type: "human",
3105
3860
  content: n
3106
3861
  }
3107
- }, i = this._state.mode, a = i === "ai";
3108
- this.setState({
3109
- messages: [...this._state.messages, r],
3110
- isLoading: !0,
3111
- error: null
3112
- }), this.widget?.appendMessage(r), a && this.widget?.setLoading(!0), this.emitter.emit("message", r);
3862
+ }, i = this._state.mode;
3863
+ this.pushLocalMessage(r), i === "ai" && this.widget?.setLoading(!0), await this.deliver({
3864
+ chatInput: n,
3865
+ visitorToken: t
3866
+ }, i);
3867
+ }
3868
+ rejectSend(e) {
3869
+ this.setState({ error: e }), this.widget?.showComposeError(e), this.emitter.emit("error", Error(e));
3870
+ }
3871
+ async sendAttachments(e, t = "") {
3872
+ let n = this.requireVisitorToken("sendAttachments");
3873
+ if (this._state.mode === "closed") {
3874
+ this.setState({ error: "Conversation is closed" });
3875
+ return;
3876
+ }
3877
+ if (e.length === 0 || this._state.isLoading || this._state.needsIdentify) return;
3878
+ let r = d(e);
3879
+ r ? this.rejectSend(r) : await this.uploadThenDeliver({
3880
+ visitorToken: n,
3881
+ files: e,
3882
+ previews: e.map(ee),
3883
+ caption: t.trim()
3884
+ });
3885
+ }
3886
+ async sendVoice(e) {
3887
+ let t = this.requireVisitorToken("sendVoice");
3888
+ if (this._state.mode === "closed") {
3889
+ this.setState({ error: "Conversation is closed" });
3890
+ return;
3891
+ }
3892
+ if (!e?.blob || e.blob.size === 0 || this._state.isLoading || this._state.needsIdentify) return;
3893
+ let n;
3113
3894
  try {
3114
- let e = await this.apiClient.sendMessage({
3115
- chatInput: n,
3116
- visitorToken: t
3117
- });
3895
+ n = await de(e);
3896
+ } catch {
3897
+ this.rejectSend("Could not process the recording.");
3898
+ return;
3899
+ }
3900
+ if (n.file.size > 10485760) {
3901
+ this.rejectSend("This voice message is too long to send.");
3902
+ return;
3903
+ }
3904
+ let r = {
3905
+ durationSeconds: n.durationSeconds,
3906
+ ...n.waveform ? { waveform: n.waveform } : {}
3907
+ }, i = {
3908
+ type: n.file.type,
3909
+ url: p(n.file),
3910
+ fileName: n.file.name,
3911
+ size: n.file.size,
3912
+ ...r
3913
+ };
3914
+ await this.uploadThenDeliver({
3915
+ visitorToken: t,
3916
+ files: [n.file],
3917
+ previews: [i],
3918
+ caption: "",
3919
+ messageType: "voice",
3920
+ decorate: (e) => ({
3921
+ ...e,
3922
+ ...r
3923
+ })
3924
+ });
3925
+ }
3926
+ async uploadThenDeliver(e) {
3927
+ let { visitorToken: t, files: n, previews: r, caption: i } = e, a = {
3928
+ id: Q(),
3929
+ sessionId: t,
3930
+ message: {
3931
+ type: "human",
3932
+ content: i,
3933
+ attachments: r
3934
+ },
3935
+ pending: !0
3936
+ }, o = this._state.mode;
3937
+ this.pushLocalMessage(a);
3938
+ let s = [];
3939
+ try {
3940
+ for (let r of n) {
3941
+ let n = await this.apiClient.uploadAttachment(r, t);
3942
+ s.push(e.decorate ? e.decorate(n) : n);
3943
+ }
3944
+ } catch (e) {
3945
+ this.removeMessage(a.id);
3946
+ for (let e of r) m(e.url);
3947
+ let t = e instanceof Error ? e : Error(String(e));
3948
+ this.setState({
3949
+ error: t.message,
3950
+ isLoading: !1
3951
+ }), this.widget?.showComposeError(t.message), this.emitter.emit("error", t);
3952
+ return;
3953
+ }
3954
+ let c = {
3955
+ ...a,
3956
+ pending: !1,
3957
+ message: {
3958
+ ...a.message,
3959
+ attachments: s
3960
+ }
3961
+ };
3962
+ this.replaceMessage(a.id, c);
3963
+ for (let e of r) m(e.url);
3964
+ o === "ai" && this.widget?.setLoading(!0), await this.deliver({
3965
+ chatInput: i,
3966
+ visitorToken: t,
3967
+ attachments: s,
3968
+ ...e.messageType ? { messageType: e.messageType } : {}
3969
+ }, o);
3970
+ }
3971
+ async deliver(e, t) {
3972
+ try {
3973
+ let n = await this.apiClient.sendMessage(e);
3118
3974
  this.hasActiveTicket = !0;
3119
- let r = e.mode ?? i, a = [...this._state.messages], o = (e.text ?? "").trim();
3120
- if (r !== i && (this.setState({ mode: r }), this.syncWidgetMode(r), this.emitter.emit("ticket-status", { mode: r })), o) {
3121
- let t = a[a.length - 1];
3122
- if (t?.message.type !== "agent" && t?.message.type !== "ai" || t.message.content !== o) {
3123
- let t = {
3124
- id: Z(),
3125
- sessionId: e.sessionId,
3975
+ let r = n.mode ?? t, i = [...this._state.messages], a = (n.text ?? "").trim();
3976
+ if (r !== t && (this.setState({ mode: r }), this.syncWidgetMode(r), this.emitter.emit("ticket-status", { mode: r })), a) {
3977
+ let e = i[i.length - 1];
3978
+ if (e?.message.type !== "agent" && e?.message.type !== "ai" || e.message.content !== a) {
3979
+ let e = {
3980
+ id: Q(),
3981
+ sessionId: n.sessionId,
3126
3982
  message: {
3127
3983
  type: "ai",
3128
- content: o
3984
+ content: a
3129
3985
  }
3130
3986
  };
3131
- a.push(t), this.widget?.appendMessage(t), this.emitter.emit("message", t);
3987
+ i.push(e), this.widget?.appendMessage(e), this.emitter.emit("message", e);
3132
3988
  }
3133
3989
  }
3134
3990
  this.setState({
3135
- messages: a,
3991
+ messages: i,
3136
3992
  isLoading: !1,
3137
3993
  mode: r
3138
3994
  }), this.syncWidgetMode(r);
@@ -3176,13 +4032,12 @@ var Q = class {
3176
4032
  needsIdentify: !0
3177
4033
  });
3178
4034
  }
3179
- }, $ = null, zt = {
4035
+ }, $ = null, On = {
3180
4036
  async init(e) {
3181
- return $ = new Q(), await $.init(e), $;
4037
+ return $ = new Dn(), await $.init(e), $;
3182
4038
  },
3183
4039
  getInstance() {
3184
4040
  return $;
3185
4041
  }
3186
4042
  };
3187
- //#endregion
3188
- export { a as ApiClient, Q as ChatbotCore, o as DEFAULT_API_BASE_URL, n as DEFAULT_REQUEST_TIMEOUT_MS, s as EventEmitter, zt as OnedeskProChatbot, ot as SdkSocket, ut as SessionManager, i as isChatbotRequestError, at as resolveSdkSocketUrl };
4043
+ export { s as ApiClient, Dn as ChatbotCore, c as DEFAULT_API_BASE_URL, n as DEFAULT_REQUEST_TIMEOUT_MS, fe as EventEmitter, On as OnedeskProChatbot, u as SDK_CHAT_MAX_ATTACHMENTS, l as SDK_UPLOAD_MAX_BYTES, Ot as SdkSocket, Mt as SessionManager, Nt as VOICE_MAX_DURATION_SECONDS, Y as VoiceRecorder, o as isChatbotRequestError, Dt as resolveSdkSocketUrl };