@paramms/chat-widget 1.0.28 → 1.0.30

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,1572 +1,58 @@
1
- var De = Object.defineProperty;
2
- var _e = (s, e, t) => e in s ? De(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var a = (s, e, t) => _e(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { p as $e, r as He, a as Re } from "./uid.js";
5
- import { h as nn } from "./uid.js";
6
- const Gt = (s) => s;
7
- function Fe(s) {
8
- const e = s.length;
9
- let t = 0, n = 0;
10
- for (; n < e; ) {
11
- let i = s.charCodeAt(n++);
12
- if (i & 4294967168)
13
- if (!(i & 4294965248))
14
- t += 2;
15
- else {
16
- if (i >= 55296 && i <= 56319 && n < e) {
17
- const o = s.charCodeAt(n);
18
- (o & 64512) === 56320 && (++n, i = ((i & 1023) << 10) + (o & 1023) + 65536);
19
- }
20
- i & 4294901760 ? t += 4 : t += 3;
21
- }
22
- else {
23
- t++;
24
- continue;
25
- }
26
- }
27
- return t;
28
- }
29
- function je(s, e, t) {
30
- const n = s.length;
31
- let i = t, o = 0;
32
- for (; o < n; ) {
33
- let r = s.charCodeAt(o++);
34
- if (r & 4294967168)
35
- if (!(r & 4294965248))
36
- e[i++] = r >> 6 & 31 | 192;
37
- else {
38
- if (r >= 55296 && r <= 56319 && o < n) {
39
- const h = s.charCodeAt(o);
40
- (h & 64512) === 56320 && (++o, r = ((r & 1023) << 10) + (h & 1023) + 65536);
41
- }
42
- r & 4294901760 ? (e[i++] = r >> 18 & 7 | 240, e[i++] = r >> 12 & 63 | 128, e[i++] = r >> 6 & 63 | 128) : (e[i++] = r >> 12 & 15 | 224, e[i++] = r >> 6 & 63 | 128);
43
- }
44
- else {
45
- e[i++] = r;
46
- continue;
47
- }
48
- e[i++] = r & 63 | 128;
49
- }
50
- }
51
- const qe = new TextEncoder(), Oe = 50;
52
- function Ne(s, e, t) {
53
- qe.encodeInto(s, e.subarray(t));
54
- }
55
- function Ve(s, e, t) {
56
- s.length > Oe ? Ne(s, e, t) : je(s, e, t);
57
- }
58
- const We = 4096;
59
- function Se(s, e, t) {
60
- let n = e;
61
- const i = n + t, o = [];
62
- let r = "";
63
- for (; n < i; ) {
64
- const h = s[n++];
65
- if (!(h & 128))
66
- o.push(h);
67
- else if ((h & 224) === 192) {
68
- const w = s[n++] & 63;
69
- o.push((h & 31) << 6 | w);
70
- } else if ((h & 240) === 224) {
71
- const w = s[n++] & 63, d = s[n++] & 63;
72
- o.push((h & 31) << 12 | w << 6 | d);
73
- } else if ((h & 248) === 240) {
74
- const w = s[n++] & 63, d = s[n++] & 63, v = s[n++] & 63;
75
- let x = (h & 7) << 18 | w << 12 | d << 6 | v;
76
- x > 65535 && (x -= 65536, o.push(x >>> 10 & 1023 | 55296), x = 56320 | x & 1023), o.push(x);
77
- } else
78
- o.push(h);
79
- o.length >= We && (r += String.fromCharCode(...o), o.length = 0);
80
- }
81
- return o.length > 0 && (r += String.fromCharCode(...o)), r;
82
- }
83
- const Xe = new TextDecoder(), Ye = 200;
84
- function Je(s, e, t) {
85
- const n = s.subarray(e, e + t);
86
- return Xe.decode(n);
87
- }
88
- function Ge(s, e, t) {
89
- return t > Ye ? Je(s, e, t) : Se(s, e, t);
90
- }
91
- class G {
92
- constructor(e, t) {
93
- a(this, "type");
94
- a(this, "data");
95
- this.type = e, this.data = t;
96
- }
97
- }
98
- class z extends Error {
99
- constructor(e) {
100
- super(e);
101
- const t = Object.create(z.prototype);
102
- Object.setPrototypeOf(this, t), Object.defineProperty(this, "name", {
103
- configurable: !0,
104
- enumerable: !1,
105
- value: z.name
106
- });
107
- }
108
- }
109
- const j = 4294967295;
110
- function Ze(s, e, t) {
111
- const n = t / 4294967296, i = t;
112
- s.setUint32(e, n), s.setUint32(e + 4, i);
113
- }
114
- function Ie(s, e, t) {
115
- const n = Math.floor(t / 4294967296), i = t;
116
- s.setUint32(e, n), s.setUint32(e + 4, i);
117
- }
118
- function Ce(s, e) {
119
- const t = s.getInt32(e), n = s.getUint32(e + 4);
120
- return t * 4294967296 + n;
121
- }
122
- function Qe(s, e) {
123
- const t = s.getUint32(e), n = s.getUint32(e + 4);
124
- return t * 4294967296 + n;
125
- }
126
- const et = -1, tt = 4294967296 - 1, nt = 17179869184 - 1;
127
- function it({ sec: s, nsec: e }) {
128
- if (s >= 0 && e >= 0 && s <= nt)
129
- if (e === 0 && s <= tt) {
130
- const t = new Uint8Array(4);
131
- return new DataView(t.buffer).setUint32(0, s), t;
132
- } else {
133
- const t = s / 4294967296, n = s & 4294967295, i = new Uint8Array(8), o = new DataView(i.buffer);
134
- return o.setUint32(0, e << 2 | t & 3), o.setUint32(4, n), i;
135
- }
136
- else {
137
- const t = new Uint8Array(12), n = new DataView(t.buffer);
138
- return n.setUint32(0, e), Ie(n, 4, s), t;
139
- }
140
- }
141
- function st(s) {
142
- const e = s.getTime(), t = Math.floor(e / 1e3), n = (e - t * 1e3) * 1e6, i = Math.floor(n / 1e9);
143
- return {
144
- sec: t + i,
145
- nsec: n - i * 1e9
146
- };
147
- }
148
- function ot(s) {
149
- if (s instanceof Date) {
150
- const e = st(s);
151
- return it(e);
152
- } else
153
- return null;
154
- }
155
- function rt(s) {
156
- const e = new DataView(s.buffer, s.byteOffset, s.byteLength);
157
- switch (s.byteLength) {
158
- case 4:
159
- return { sec: e.getUint32(0), nsec: 0 };
160
- case 8: {
161
- const t = e.getUint32(0), n = e.getUint32(4), i = (t & 3) * 4294967296 + n, o = t >>> 2;
162
- return { sec: i, nsec: o };
163
- }
164
- case 12: {
165
- const t = Ce(e, 4), n = e.getUint32(0);
166
- return { sec: t, nsec: n };
167
- }
168
- default:
169
- throw new z(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${s.length}`);
170
- }
171
- }
172
- function at(s) {
173
- const e = rt(s);
174
- return new Date(e.sec * 1e3 + e.nsec / 1e6);
175
- }
176
- const ct = {
177
- type: et,
178
- encode: ot,
179
- decode: at
180
- }, te = class te {
181
- constructor() {
182
- // ensures ExtensionCodecType<X> matches ExtensionCodec<X>
183
- // this will make type errors a lot more clear
184
- // eslint-disable-next-line @typescript-eslint/naming-convention
185
- a(this, "__brand");
186
- // built-in extensions
187
- a(this, "builtInEncoders", []);
188
- a(this, "builtInDecoders", []);
189
- // custom extensions
190
- a(this, "encoders", []);
191
- a(this, "decoders", []);
192
- this.register(ct);
193
- }
194
- register({ type: e, encode: t, decode: n }) {
195
- if (e >= 0)
196
- this.encoders[e] = t, this.decoders[e] = n;
197
- else {
198
- const i = -1 - e;
199
- this.builtInEncoders[i] = t, this.builtInDecoders[i] = n;
200
- }
201
- }
202
- tryToEncode(e, t) {
203
- for (let n = 0; n < this.builtInEncoders.length; n++) {
204
- const i = this.builtInEncoders[n];
205
- if (i != null) {
206
- const o = i(e, t);
207
- if (o != null) {
208
- const r = -1 - n;
209
- return new G(r, o);
210
- }
211
- }
212
- }
213
- for (let n = 0; n < this.encoders.length; n++) {
214
- const i = this.encoders[n];
215
- if (i != null) {
216
- const o = i(e, t);
217
- if (o != null) {
218
- const r = n;
219
- return new G(r, o);
220
- }
221
- }
222
- }
223
- return e instanceof G ? e : null;
224
- }
225
- decode(e, t, n) {
226
- const i = t < 0 ? this.builtInDecoders[-1 - t] : this.decoders[t];
227
- return i ? i(e, t, n) : new G(t, e);
228
- }
229
- };
230
- a(te, "defaultCodec", new te());
231
- let Q = te;
232
- function dt(s) {
233
- return s instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && s instanceof SharedArrayBuffer;
234
- }
235
- function oe(s) {
236
- return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) : dt(s) ? new Uint8Array(s) : Uint8Array.from(s);
237
- }
238
- const lt = 100, ht = 2048;
239
- class ce {
240
- constructor(e) {
241
- a(this, "extensionCodec");
242
- a(this, "context");
243
- a(this, "useBigInt64");
244
- a(this, "maxDepth");
245
- a(this, "initialBufferSize");
246
- a(this, "sortKeys");
247
- a(this, "forceFloat32");
248
- a(this, "ignoreUndefined");
249
- a(this, "forceIntegerToFloat");
250
- a(this, "pos");
251
- a(this, "view");
252
- a(this, "bytes");
253
- a(this, "entered", !1);
254
- this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? Q.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ?? lt, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? ht, this.sortKeys = (e == null ? void 0 : e.sortKeys) ?? !1, this.forceFloat32 = (e == null ? void 0 : e.forceFloat32) ?? !1, this.ignoreUndefined = (e == null ? void 0 : e.ignoreUndefined) ?? !1, this.forceIntegerToFloat = (e == null ? void 0 : e.forceIntegerToFloat) ?? !1, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
255
- }
256
- clone() {
257
- return new ce({
258
- extensionCodec: this.extensionCodec,
259
- context: this.context,
260
- useBigInt64: this.useBigInt64,
261
- maxDepth: this.maxDepth,
262
- initialBufferSize: this.initialBufferSize,
263
- sortKeys: this.sortKeys,
264
- forceFloat32: this.forceFloat32,
265
- ignoreUndefined: this.ignoreUndefined,
266
- forceIntegerToFloat: this.forceIntegerToFloat
267
- });
268
- }
269
- reinitializeState() {
270
- this.pos = 0;
271
- }
272
- /**
273
- * This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}.
274
- *
275
- * @returns Encodes the object and returns a shared reference the encoder's internal buffer.
276
- */
277
- encodeSharedRef(e) {
278
- if (this.entered)
279
- return this.clone().encodeSharedRef(e);
280
- try {
281
- return this.entered = !0, this.reinitializeState(), this.doEncode(e, 1), this.bytes.subarray(0, this.pos);
282
- } finally {
283
- this.entered = !1;
284
- }
285
- }
286
- /**
287
- * @returns Encodes the object and returns a copy of the encoder's internal buffer.
288
- */
289
- encode(e) {
290
- if (this.entered)
291
- return this.clone().encode(e);
292
- try {
293
- return this.entered = !0, this.reinitializeState(), this.doEncode(e, 1), this.bytes.slice(0, this.pos);
294
- } finally {
295
- this.entered = !1;
296
- }
297
- }
298
- doEncode(e, t) {
299
- if (t > this.maxDepth)
300
- throw new Error(`Too deep objects in depth ${t}`);
301
- e == null ? this.encodeNil() : typeof e == "boolean" ? this.encodeBoolean(e) : typeof e == "number" ? this.forceIntegerToFloat ? this.encodeNumberAsFloat(e) : this.encodeNumber(e) : typeof e == "string" ? this.encodeString(e) : this.useBigInt64 && typeof e == "bigint" ? this.encodeBigInt64(e) : this.encodeObject(e, t);
302
- }
303
- ensureBufferSizeToWrite(e) {
304
- const t = this.pos + e;
305
- this.view.byteLength < t && this.resizeBuffer(t * 2);
306
- }
307
- resizeBuffer(e) {
308
- const t = new ArrayBuffer(e), n = new Uint8Array(t), i = new DataView(t);
309
- n.set(this.bytes), this.view = i, this.bytes = n;
310
- }
311
- encodeNil() {
312
- this.writeU8(192);
313
- }
314
- encodeBoolean(e) {
315
- e === !1 ? this.writeU8(194) : this.writeU8(195);
316
- }
317
- encodeNumber(e) {
318
- !this.forceIntegerToFloat && Number.isSafeInteger(e) ? e >= 0 ? e < 128 ? this.writeU8(e) : e < 256 ? (this.writeU8(204), this.writeU8(e)) : e < 65536 ? (this.writeU8(205), this.writeU16(e)) : e < 4294967296 ? (this.writeU8(206), this.writeU32(e)) : this.useBigInt64 ? this.encodeNumberAsFloat(e) : (this.writeU8(207), this.writeU64(e)) : e >= -32 ? this.writeU8(224 | e + 32) : e >= -128 ? (this.writeU8(208), this.writeI8(e)) : e >= -32768 ? (this.writeU8(209), this.writeI16(e)) : e >= -2147483648 ? (this.writeU8(210), this.writeI32(e)) : this.useBigInt64 ? this.encodeNumberAsFloat(e) : (this.writeU8(211), this.writeI64(e)) : this.encodeNumberAsFloat(e);
319
- }
320
- encodeNumberAsFloat(e) {
321
- this.forceFloat32 ? (this.writeU8(202), this.writeF32(e)) : (this.writeU8(203), this.writeF64(e));
322
- }
323
- encodeBigInt64(e) {
324
- e >= BigInt(0) ? (this.writeU8(207), this.writeBigUint64(e)) : (this.writeU8(211), this.writeBigInt64(e));
325
- }
326
- writeStringHeader(e) {
327
- if (e < 32)
328
- this.writeU8(160 + e);
329
- else if (e < 256)
330
- this.writeU8(217), this.writeU8(e);
331
- else if (e < 65536)
332
- this.writeU8(218), this.writeU16(e);
333
- else if (e < 4294967296)
334
- this.writeU8(219), this.writeU32(e);
335
- else
336
- throw new Error(`Too long string: ${e} bytes in UTF-8`);
337
- }
338
- encodeString(e) {
339
- const n = Fe(e);
340
- this.ensureBufferSizeToWrite(5 + n), this.writeStringHeader(n), Ve(e, this.bytes, this.pos), this.pos += n;
341
- }
342
- encodeObject(e, t) {
343
- const n = this.extensionCodec.tryToEncode(e, this.context);
344
- if (n != null)
345
- this.encodeExtension(n);
346
- else if (Array.isArray(e))
347
- this.encodeArray(e, t);
348
- else if (ArrayBuffer.isView(e))
349
- this.encodeBinary(e);
350
- else if (typeof e == "object")
351
- this.encodeMap(e, t);
352
- else
353
- throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`);
354
- }
355
- encodeBinary(e) {
356
- const t = e.byteLength;
357
- if (t < 256)
358
- this.writeU8(196), this.writeU8(t);
359
- else if (t < 65536)
360
- this.writeU8(197), this.writeU16(t);
361
- else if (t < 4294967296)
362
- this.writeU8(198), this.writeU32(t);
363
- else
364
- throw new Error(`Too large binary: ${t}`);
365
- const n = oe(e);
366
- this.writeU8a(n);
367
- }
368
- encodeArray(e, t) {
369
- const n = e.length;
370
- if (n < 16)
371
- this.writeU8(144 + n);
372
- else if (n < 65536)
373
- this.writeU8(220), this.writeU16(n);
374
- else if (n < 4294967296)
375
- this.writeU8(221), this.writeU32(n);
376
- else
377
- throw new Error(`Too large array: ${n}`);
378
- for (const i of e)
379
- this.doEncode(i, t + 1);
380
- }
381
- countWithoutUndefined(e, t) {
382
- let n = 0;
383
- for (const i of t)
384
- e[i] !== void 0 && n++;
385
- return n;
386
- }
387
- encodeMap(e, t) {
388
- const n = Object.keys(e);
389
- this.sortKeys && n.sort();
390
- const i = this.ignoreUndefined ? this.countWithoutUndefined(e, n) : n.length;
391
- if (i < 16)
392
- this.writeU8(128 + i);
393
- else if (i < 65536)
394
- this.writeU8(222), this.writeU16(i);
395
- else if (i < 4294967296)
396
- this.writeU8(223), this.writeU32(i);
397
- else
398
- throw new Error(`Too large map object: ${i}`);
399
- for (const o of n) {
400
- const r = e[o];
401
- this.ignoreUndefined && r === void 0 || (this.encodeString(o), this.doEncode(r, t + 1));
402
- }
403
- }
404
- encodeExtension(e) {
405
- if (typeof e.data == "function") {
406
- const n = e.data(this.pos + 6), i = n.length;
407
- if (i >= 4294967296)
408
- throw new Error(`Too large extension object: ${i}`);
409
- this.writeU8(201), this.writeU32(i), this.writeI8(e.type), this.writeU8a(n);
410
- return;
411
- }
412
- const t = e.data.length;
413
- if (t === 1)
414
- this.writeU8(212);
415
- else if (t === 2)
416
- this.writeU8(213);
417
- else if (t === 4)
418
- this.writeU8(214);
419
- else if (t === 8)
420
- this.writeU8(215);
421
- else if (t === 16)
422
- this.writeU8(216);
423
- else if (t < 256)
424
- this.writeU8(199), this.writeU8(t);
425
- else if (t < 65536)
426
- this.writeU8(200), this.writeU16(t);
427
- else if (t < 4294967296)
428
- this.writeU8(201), this.writeU32(t);
429
- else
430
- throw new Error(`Too large extension object: ${t}`);
431
- this.writeI8(e.type), this.writeU8a(e.data);
432
- }
433
- writeU8(e) {
434
- this.ensureBufferSizeToWrite(1), this.view.setUint8(this.pos, e), this.pos++;
435
- }
436
- writeU8a(e) {
437
- const t = e.length;
438
- this.ensureBufferSizeToWrite(t), this.bytes.set(e, this.pos), this.pos += t;
439
- }
440
- writeI8(e) {
441
- this.ensureBufferSizeToWrite(1), this.view.setInt8(this.pos, e), this.pos++;
442
- }
443
- writeU16(e) {
444
- this.ensureBufferSizeToWrite(2), this.view.setUint16(this.pos, e), this.pos += 2;
445
- }
446
- writeI16(e) {
447
- this.ensureBufferSizeToWrite(2), this.view.setInt16(this.pos, e), this.pos += 2;
448
- }
449
- writeU32(e) {
450
- this.ensureBufferSizeToWrite(4), this.view.setUint32(this.pos, e), this.pos += 4;
451
- }
452
- writeI32(e) {
453
- this.ensureBufferSizeToWrite(4), this.view.setInt32(this.pos, e), this.pos += 4;
454
- }
455
- writeF32(e) {
456
- this.ensureBufferSizeToWrite(4), this.view.setFloat32(this.pos, e), this.pos += 4;
457
- }
458
- writeF64(e) {
459
- this.ensureBufferSizeToWrite(8), this.view.setFloat64(this.pos, e), this.pos += 8;
460
- }
461
- writeU64(e) {
462
- this.ensureBufferSizeToWrite(8), Ze(this.view, this.pos, e), this.pos += 8;
463
- }
464
- writeI64(e) {
465
- this.ensureBufferSizeToWrite(8), Ie(this.view, this.pos, e), this.pos += 8;
466
- }
467
- writeBigUint64(e) {
468
- this.ensureBufferSizeToWrite(8), this.view.setBigUint64(this.pos, e), this.pos += 8;
469
- }
470
- writeBigInt64(e) {
471
- this.ensureBufferSizeToWrite(8), this.view.setBigInt64(this.pos, e), this.pos += 8;
472
- }
473
- }
474
- function pt(s, e) {
475
- return new ce(e).encodeSharedRef(s);
476
- }
477
- function ie(s) {
478
- return `${s < 0 ? "-" : ""}0x${Math.abs(s).toString(16).padStart(2, "0")}`;
479
- }
480
- const ut = 16, ft = 16;
481
- class wt {
482
- constructor(e = ut, t = ft) {
483
- a(this, "hit", 0);
484
- a(this, "miss", 0);
485
- a(this, "caches");
486
- a(this, "maxKeyLength");
487
- a(this, "maxLengthPerKey");
488
- this.maxKeyLength = e, this.maxLengthPerKey = t, this.caches = [];
489
- for (let n = 0; n < this.maxKeyLength; n++)
490
- this.caches.push([]);
491
- }
492
- canBeCached(e) {
493
- return e > 0 && e <= this.maxKeyLength;
494
- }
495
- find(e, t, n) {
496
- const i = this.caches[n - 1];
497
- e: for (const o of i) {
498
- const r = o.bytes;
499
- for (let h = 0; h < n; h++)
500
- if (r[h] !== e[t + h])
501
- continue e;
502
- return o.str;
503
- }
504
- return null;
505
- }
506
- store(e, t) {
507
- const n = this.caches[e.length - 1], i = { bytes: e, str: t };
508
- n.length >= this.maxLengthPerKey ? n[Math.random() * n.length | 0] = i : n.push(i);
509
- }
510
- decode(e, t, n) {
511
- const i = this.find(e, t, n);
512
- if (i != null)
513
- return this.hit++, i;
514
- this.miss++;
515
- const o = Se(e, t, n), r = Uint8Array.prototype.slice.call(e, t, t + n);
516
- return this.store(r, o), o;
517
- }
518
- }
519
- const re = "array", O = "map_key", Ee = "map_value", xt = (s) => {
520
- if (typeof s == "string" || typeof s == "number")
521
- return s;
522
- throw new z("The type of key must be string or number but " + typeof s);
523
- };
524
- class yt {
1
+ var ce = Object.defineProperty;
2
+ var de = (t, e, n) => e in t ? ce(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var m = (t, e, n) => de(t, typeof e != "symbol" ? e + "" : e, n);
4
+ import { p as le, r as pe, a as ue } from "./uid.js";
5
+ import { h as $e } from "./uid.js";
6
+ import { P as fe, C as he, E as we, b as be, m as xe } from "./e2e.js";
7
+ import { e as Me } from "./e2e.js";
8
+ const Q = "http://www.w3.org/2000/svg", ge = 8e3;
9
+ class me {
525
10
  constructor() {
526
- a(this, "stack", []);
527
- a(this, "stackHeadPosition", -1);
528
- }
529
- get length() {
530
- return this.stackHeadPosition + 1;
531
- }
532
- top() {
533
- return this.stack[this.stackHeadPosition];
534
- }
535
- pushArrayState(e) {
536
- const t = this.getUninitializedStateFromPool();
537
- t.type = re, t.position = 0, t.size = e, t.array = new Array(e);
538
- }
539
- pushMapState(e) {
540
- const t = this.getUninitializedStateFromPool();
541
- t.type = O, t.readCount = 0, t.size = e, t.map = {};
542
- }
543
- getUninitializedStateFromPool() {
544
- if (this.stackHeadPosition++, this.stackHeadPosition === this.stack.length) {
545
- const e = {
546
- type: void 0,
547
- size: 0,
548
- array: void 0,
549
- position: 0,
550
- readCount: 0,
551
- map: void 0,
552
- key: null
553
- };
554
- this.stack.push(e);
555
- }
556
- return this.stack[this.stackHeadPosition];
557
- }
558
- release(e) {
559
- if (this.stack[this.stackHeadPosition] !== e)
560
- throw new Error("Invalid stack state. Released state is not on top of the stack.");
561
- if (e.type === re) {
562
- const n = e;
563
- n.size = 0, n.array = void 0, n.position = 0, n.type = void 0;
564
- }
565
- if (e.type === O || e.type === Ee) {
566
- const n = e;
567
- n.size = 0, n.map = void 0, n.readCount = 0, n.type = void 0;
568
- }
569
- this.stackHeadPosition--;
570
- }
571
- reset() {
572
- this.stack.length = 0, this.stackHeadPosition = -1;
573
- }
574
- }
575
- const q = -1, de = new DataView(new ArrayBuffer(0)), gt = new Uint8Array(de.buffer);
576
- try {
577
- de.getInt8(0);
578
- } catch (s) {
579
- if (!(s instanceof RangeError))
580
- throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
581
- }
582
- const ye = new RangeError("Insufficient data"), bt = new wt();
583
- class le {
584
- constructor(e) {
585
- a(this, "extensionCodec");
586
- a(this, "context");
587
- a(this, "useBigInt64");
588
- a(this, "rawStrings");
589
- a(this, "maxStrLength");
590
- a(this, "maxBinLength");
591
- a(this, "maxArrayLength");
592
- a(this, "maxMapLength");
593
- a(this, "maxExtLength");
594
- a(this, "keyDecoder");
595
- a(this, "mapKeyConverter");
596
- a(this, "totalPos", 0);
597
- a(this, "pos", 0);
598
- a(this, "view", de);
599
- a(this, "bytes", gt);
600
- a(this, "headByte", q);
601
- a(this, "stack", new yt());
602
- a(this, "entered", !1);
603
- this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? Q.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? j, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? j, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? j, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? j, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? j, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : bt, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? xt;
604
- }
605
- clone() {
606
- return new le({
607
- extensionCodec: this.extensionCodec,
608
- context: this.context,
609
- useBigInt64: this.useBigInt64,
610
- rawStrings: this.rawStrings,
611
- maxStrLength: this.maxStrLength,
612
- maxBinLength: this.maxBinLength,
613
- maxArrayLength: this.maxArrayLength,
614
- maxMapLength: this.maxMapLength,
615
- maxExtLength: this.maxExtLength,
616
- keyDecoder: this.keyDecoder
617
- });
618
- }
619
- reinitializeState() {
620
- this.totalPos = 0, this.headByte = q, this.stack.reset();
621
- }
622
- setBuffer(e) {
623
- const t = oe(e);
624
- this.bytes = t, this.view = new DataView(t.buffer, t.byteOffset, t.byteLength), this.pos = 0;
625
- }
626
- appendBuffer(e) {
627
- if (this.headByte === q && !this.hasRemaining(1))
628
- this.setBuffer(e);
629
- else {
630
- const t = this.bytes.subarray(this.pos), n = oe(e), i = new Uint8Array(t.length + n.length);
631
- i.set(t), i.set(n, t.length), this.setBuffer(i);
632
- }
633
- }
634
- hasRemaining(e) {
635
- return this.view.byteLength - this.pos >= e;
636
- }
637
- createExtraByteError(e) {
638
- const { view: t, pos: n } = this;
639
- return new RangeError(`Extra ${t.byteLength - n} of ${t.byteLength} byte(s) found at buffer[${e}]`);
640
- }
641
- /**
642
- * @throws {@link DecodeError}
643
- * @throws {@link RangeError}
644
- */
645
- decode(e) {
646
- if (this.entered)
647
- return this.clone().decode(e);
648
- try {
649
- this.entered = !0, this.reinitializeState(), this.setBuffer(e);
650
- const t = this.doDecodeSync();
651
- if (this.hasRemaining(1))
652
- throw this.createExtraByteError(this.pos);
653
- return t;
654
- } finally {
655
- this.entered = !1;
656
- }
657
- }
658
- *decodeMulti(e) {
659
- if (this.entered) {
660
- yield* this.clone().decodeMulti(e);
661
- return;
662
- }
663
- try {
664
- for (this.entered = !0, this.reinitializeState(), this.setBuffer(e); this.hasRemaining(1); )
665
- yield this.doDecodeSync();
666
- } finally {
667
- this.entered = !1;
668
- }
669
- }
670
- async decodeAsync(e) {
671
- if (this.entered)
672
- return this.clone().decodeAsync(e);
673
- try {
674
- this.entered = !0;
675
- let t = !1, n;
676
- for await (const h of e) {
677
- if (t)
678
- throw this.entered = !1, this.createExtraByteError(this.totalPos);
679
- this.appendBuffer(h);
680
- try {
681
- n = this.doDecodeSync(), t = !0;
682
- } catch (w) {
683
- if (!(w instanceof RangeError))
684
- throw w;
685
- }
686
- this.totalPos += this.pos;
687
- }
688
- if (t) {
689
- if (this.hasRemaining(1))
690
- throw this.createExtraByteError(this.totalPos);
691
- return n;
692
- }
693
- const { headByte: i, pos: o, totalPos: r } = this;
694
- throw new RangeError(`Insufficient data in parsing ${ie(i)} at ${r} (${o} in the current buffer)`);
695
- } finally {
696
- this.entered = !1;
697
- }
698
- }
699
- decodeArrayStream(e) {
700
- return this.decodeMultiAsync(e, !0);
701
- }
702
- decodeStream(e) {
703
- return this.decodeMultiAsync(e, !1);
704
- }
705
- async *decodeMultiAsync(e, t) {
706
- if (this.entered) {
707
- yield* this.clone().decodeMultiAsync(e, t);
708
- return;
709
- }
710
- try {
711
- this.entered = !0;
712
- let n = t, i = -1;
713
- for await (const o of e) {
714
- if (t && i === 0)
715
- throw this.createExtraByteError(this.totalPos);
716
- this.appendBuffer(o), n && (i = this.readArraySize(), n = !1, this.complete());
717
- try {
718
- for (; yield this.doDecodeSync(), --i !== 0; )
719
- ;
720
- } catch (r) {
721
- if (!(r instanceof RangeError))
722
- throw r;
723
- }
724
- this.totalPos += this.pos;
725
- }
726
- } finally {
727
- this.entered = !1;
728
- }
729
- }
730
- doDecodeSync() {
731
- e: for (; ; ) {
732
- const e = this.readHeadByte();
733
- let t;
734
- if (e >= 224)
735
- t = e - 256;
736
- else if (e < 192)
737
- if (e < 128)
738
- t = e;
739
- else if (e < 144) {
740
- const i = e - 128;
741
- if (i !== 0) {
742
- this.pushMapState(i), this.complete();
743
- continue e;
744
- } else
745
- t = {};
746
- } else if (e < 160) {
747
- const i = e - 144;
748
- if (i !== 0) {
749
- this.pushArrayState(i), this.complete();
750
- continue e;
751
- } else
752
- t = [];
753
- } else {
754
- const i = e - 160;
755
- t = this.decodeString(i, 0);
756
- }
757
- else if (e === 192)
758
- t = null;
759
- else if (e === 194)
760
- t = !1;
761
- else if (e === 195)
762
- t = !0;
763
- else if (e === 202)
764
- t = this.readF32();
765
- else if (e === 203)
766
- t = this.readF64();
767
- else if (e === 204)
768
- t = this.readU8();
769
- else if (e === 205)
770
- t = this.readU16();
771
- else if (e === 206)
772
- t = this.readU32();
773
- else if (e === 207)
774
- this.useBigInt64 ? t = this.readU64AsBigInt() : t = this.readU64();
775
- else if (e === 208)
776
- t = this.readI8();
777
- else if (e === 209)
778
- t = this.readI16();
779
- else if (e === 210)
780
- t = this.readI32();
781
- else if (e === 211)
782
- this.useBigInt64 ? t = this.readI64AsBigInt() : t = this.readI64();
783
- else if (e === 217) {
784
- const i = this.lookU8();
785
- t = this.decodeString(i, 1);
786
- } else if (e === 218) {
787
- const i = this.lookU16();
788
- t = this.decodeString(i, 2);
789
- } else if (e === 219) {
790
- const i = this.lookU32();
791
- t = this.decodeString(i, 4);
792
- } else if (e === 220) {
793
- const i = this.readU16();
794
- if (i !== 0) {
795
- this.pushArrayState(i), this.complete();
796
- continue e;
797
- } else
798
- t = [];
799
- } else if (e === 221) {
800
- const i = this.readU32();
801
- if (i !== 0) {
802
- this.pushArrayState(i), this.complete();
803
- continue e;
804
- } else
805
- t = [];
806
- } else if (e === 222) {
807
- const i = this.readU16();
808
- if (i !== 0) {
809
- this.pushMapState(i), this.complete();
810
- continue e;
811
- } else
812
- t = {};
813
- } else if (e === 223) {
814
- const i = this.readU32();
815
- if (i !== 0) {
816
- this.pushMapState(i), this.complete();
817
- continue e;
818
- } else
819
- t = {};
820
- } else if (e === 196) {
821
- const i = this.lookU8();
822
- t = this.decodeBinary(i, 1);
823
- } else if (e === 197) {
824
- const i = this.lookU16();
825
- t = this.decodeBinary(i, 2);
826
- } else if (e === 198) {
827
- const i = this.lookU32();
828
- t = this.decodeBinary(i, 4);
829
- } else if (e === 212)
830
- t = this.decodeExtension(1, 0);
831
- else if (e === 213)
832
- t = this.decodeExtension(2, 0);
833
- else if (e === 214)
834
- t = this.decodeExtension(4, 0);
835
- else if (e === 215)
836
- t = this.decodeExtension(8, 0);
837
- else if (e === 216)
838
- t = this.decodeExtension(16, 0);
839
- else if (e === 199) {
840
- const i = this.lookU8();
841
- t = this.decodeExtension(i, 1);
842
- } else if (e === 200) {
843
- const i = this.lookU16();
844
- t = this.decodeExtension(i, 2);
845
- } else if (e === 201) {
846
- const i = this.lookU32();
847
- t = this.decodeExtension(i, 4);
848
- } else
849
- throw new z(`Unrecognized type byte: ${ie(e)}`);
850
- this.complete();
851
- const n = this.stack;
852
- for (; n.length > 0; ) {
853
- const i = n.top();
854
- if (i.type === re)
855
- if (i.array[i.position] = t, i.position++, i.position === i.size)
856
- t = i.array, n.release(i);
857
- else
858
- continue e;
859
- else if (i.type === O) {
860
- if (t === "__proto__")
861
- throw new z("The key __proto__ is not allowed");
862
- i.key = this.mapKeyConverter(t), i.type = Ee;
863
- continue e;
864
- } else if (i.map[i.key] = t, i.readCount++, i.readCount === i.size)
865
- t = i.map, n.release(i);
866
- else {
867
- i.key = null, i.type = O;
868
- continue e;
869
- }
870
- }
871
- return t;
872
- }
873
- }
874
- readHeadByte() {
875
- return this.headByte === q && (this.headByte = this.readU8()), this.headByte;
876
- }
877
- complete() {
878
- this.headByte = q;
879
- }
880
- readArraySize() {
881
- const e = this.readHeadByte();
882
- switch (e) {
883
- case 220:
884
- return this.readU16();
885
- case 221:
886
- return this.readU32();
887
- default: {
888
- if (e < 160)
889
- return e - 144;
890
- throw new z(`Unrecognized array type byte: ${ie(e)}`);
891
- }
892
- }
893
- }
894
- pushMapState(e) {
895
- if (e > this.maxMapLength)
896
- throw new z(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);
897
- this.stack.pushMapState(e);
898
- }
899
- pushArrayState(e) {
900
- if (e > this.maxArrayLength)
901
- throw new z(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);
902
- this.stack.pushArrayState(e);
903
- }
904
- decodeString(e, t) {
905
- return !this.rawStrings || this.stateIsMapKey() ? this.decodeUtf8String(e, t) : this.decodeBinary(e, t);
906
- }
907
- /**
908
- * @throws {@link RangeError}
909
- */
910
- decodeUtf8String(e, t) {
911
- var o;
912
- if (e > this.maxStrLength)
913
- throw new z(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);
914
- if (this.bytes.byteLength < this.pos + t + e)
915
- throw ye;
916
- const n = this.pos + t;
917
- let i;
918
- return this.stateIsMapKey() && ((o = this.keyDecoder) != null && o.canBeCached(e)) ? i = this.keyDecoder.decode(this.bytes, n, e) : i = Ge(this.bytes, n, e), this.pos += t + e, i;
919
- }
920
- stateIsMapKey() {
921
- return this.stack.length > 0 ? this.stack.top().type === O : !1;
922
- }
923
- /**
924
- * @throws {@link RangeError}
925
- */
926
- decodeBinary(e, t) {
927
- if (e > this.maxBinLength)
928
- throw new z(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);
929
- if (!this.hasRemaining(e + t))
930
- throw ye;
931
- const n = this.pos + t, i = this.bytes.subarray(n, n + e);
932
- return this.pos += t + e, i;
933
- }
934
- decodeExtension(e, t) {
935
- if (e > this.maxExtLength)
936
- throw new z(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);
937
- const n = this.view.getInt8(this.pos + t), i = this.decodeBinary(
938
- e,
939
- t + 1
940
- /* extType */
941
- );
942
- return this.extensionCodec.decode(i, n, this.context);
943
- }
944
- lookU8() {
945
- return this.view.getUint8(this.pos);
946
- }
947
- lookU16() {
948
- return this.view.getUint16(this.pos);
949
- }
950
- lookU32() {
951
- return this.view.getUint32(this.pos);
952
- }
953
- readU8() {
954
- const e = this.view.getUint8(this.pos);
955
- return this.pos++, e;
956
- }
957
- readI8() {
958
- const e = this.view.getInt8(this.pos);
959
- return this.pos++, e;
960
- }
961
- readU16() {
962
- const e = this.view.getUint16(this.pos);
963
- return this.pos += 2, e;
964
- }
965
- readI16() {
966
- const e = this.view.getInt16(this.pos);
967
- return this.pos += 2, e;
968
- }
969
- readU32() {
970
- const e = this.view.getUint32(this.pos);
971
- return this.pos += 4, e;
972
- }
973
- readI32() {
974
- const e = this.view.getInt32(this.pos);
975
- return this.pos += 4, e;
976
- }
977
- readU64() {
978
- const e = Qe(this.view, this.pos);
979
- return this.pos += 8, e;
980
- }
981
- readI64() {
982
- const e = Ce(this.view, this.pos);
983
- return this.pos += 8, e;
984
- }
985
- readU64AsBigInt() {
986
- const e = this.view.getBigUint64(this.pos);
987
- return this.pos += 8, e;
988
- }
989
- readI64AsBigInt() {
990
- const e = this.view.getBigInt64(this.pos);
991
- return this.pos += 8, e;
992
- }
993
- readF32() {
994
- const e = this.view.getFloat32(this.pos);
995
- return this.pos += 4, e;
996
- }
997
- readF64() {
998
- const e = this.view.getFloat64(this.pos);
999
- return this.pos += 8, e;
1000
- }
1001
- }
1002
- function mt(s, e) {
1003
- return new le(e).decode(s);
1004
- }
1005
- const vt = /* @__PURE__ */ new Set([
1006
- "auth",
1007
- "open",
1008
- "send",
1009
- "sync",
1010
- "history",
1011
- "read",
1012
- "typing",
1013
- "react",
1014
- "edit",
1015
- "delete",
1016
- "invoke",
1017
- "pubkey",
1018
- "ping",
1019
- "annotate",
1020
- "annotate_clear",
1021
- "uploadPrekeys",
1022
- "fetchPrekey",
1023
- "assign",
1024
- "tag",
1025
- "note",
1026
- "agent_status",
1027
- "subscribe_inbox",
1028
- "unsubscribe_inbox"
1029
- ]);
1030
- function kt(s) {
1031
- return vt.has(s.type);
1032
- }
1033
- function St(s) {
1034
- return pt(s);
1035
- }
1036
- function It(s) {
1037
- let e;
1038
- try {
1039
- e = mt(s);
1040
- } catch {
1041
- return null;
1042
- }
1043
- return typeof e != "object" || e === null || typeof e.type != "string" ? null : e;
1044
- }
1045
- class Ct {
1046
- constructor(e) {
1047
- a(this, "conversationId");
1048
- a(this, "state", "");
1049
- a(this, "version", 0);
1050
- a(this, "hasMoreHistory", !1);
1051
- a(this, "lastReadByOthers", 0);
1052
- a(this, "assignedAgentId");
1053
- a(this, "accent");
1054
- a(this, "subject");
1055
- a(this, "name");
1056
- a(this, "e2e", !1);
1057
- a(this, "offline", !1);
1058
- a(this, "offlineMessage", "");
1059
- a(this, "whiteLabel", !1);
1060
- a(this, "typing", /* @__PURE__ */ new Set());
1061
- a(this, "online", /* @__PURE__ */ new Set());
1062
- /** Co-browsing: shared whiteboard strokes for this conversation. */
1063
- a(this, "annotations", []);
1064
- /** Bumped on any annotation change so the renderer can cheaply detect updates. */
1065
- a(this, "annotationVersion", 0);
1066
- /** Live sentiment of the guest's latest message (agent-side only). */
1067
- a(this, "sentiment");
1068
- a(this, "sentimentScore");
1069
- a(this, "actions", []);
1070
- a(this, "byId", /* @__PURE__ */ new Map());
1071
- a(this, "keyByClient", /* @__PURE__ */ new Map());
1072
- a(this, "_maxSeq", 0);
1073
- a(this, "_sorted", null);
1074
- this.me = e;
1075
- }
1076
- messages() {
1077
- return this._sorted || (this._sorted = [...this.byId.values()].sort((e, t) => {
1078
- const n = e.status === "pending", i = t.status === "pending";
1079
- return n !== i ? n ? 1 : -1 : n && i ? e.ts - t.ts : e.seq - t.seq;
1080
- })), this._sorted;
1081
- }
1082
- visibleActions() {
1083
- return this.actions.filter((e) => !e.availableInStates || e.availableInStates.includes(this.state));
1084
- }
1085
- highestSeq() {
1086
- return this._maxSeq;
1087
- }
1088
- addOptimistic(e, t) {
1089
- const n = {
1090
- id: e,
1091
- conversationId: this.conversationId,
1092
- seq: 0,
1093
- senderId: this.me,
1094
- senderRole: "guest",
1095
- content: t,
1096
- ts: Date.now(),
1097
- clientMsgId: e,
1098
- status: "pending"
1099
- };
1100
- return this.byId.set(e, n), this.keyByClient.set(e, e), this._sorted = null, n;
11
+ m(this, "svg", null);
12
+ m(this, "timers", /* @__PURE__ */ new Set());
1101
13
  }
14
+ /** Feed every server frame; the overlay reacts to annotation frames only. */
1102
15
  apply(e) {
1103
- var t;
1104
- switch (e.type) {
1105
- case "opened":
1106
- this.conversationId = e.conversation.id, this.state = e.conversation.state, e.subject && (this.subject = e.subject), e.annotations && (this.annotations = e.annotations, this.annotationVersion++);
1107
- return;
1108
- case "manifest":
1109
- this.actions = e.actions, this.version = e.version, e.name && (this.name = e.name), (t = e.theme) != null && t.accent && (this.accent = e.theme.accent), e.e2e && (this.e2e = !0), e.offline && (this.offline = !0), e.offlineMessage && (this.offlineMessage = e.offlineMessage), e.whiteLabel && (this.whiteLabel = !0);
1110
- return;
1111
- case "message":
1112
- this.upsert({ ...e.message });
1113
- return;
1114
- case "ack": {
1115
- const n = this.keyByClient.get(e.clientMsgId), i = n ? this.byId.get(n) : void 0;
1116
- if (i && n) {
1117
- this.byId.delete(n);
1118
- const o = { ...i, id: e.messageId, seq: e.seq, ts: e.ts, status: "sent" };
1119
- this.byId.set(e.messageId, o), this.keyByClient.set(e.clientMsgId, e.messageId), e.seq > this._maxSeq && (this._maxSeq = e.seq);
1120
- }
1121
- this._sorted = null;
1122
- return;
1123
- }
1124
- case "delivered":
1125
- this.markOwnStatus(e.seq, "delivered");
1126
- return;
1127
- case "read":
1128
- e.by !== this.me && (this.lastReadByOthers = Math.max(this.lastReadByOthers, e.seq), this.markOwnStatus(e.seq, "read"));
1129
- return;
1130
- case "sync":
1131
- for (const n of e.messages) this.upsert({ ...n });
1132
- return;
1133
- case "history":
1134
- for (const n of e.messages) this.upsert({ ...n });
1135
- this.hasMoreHistory = e.hasMore;
1136
- return;
1137
- case "typing":
1138
- e.userId !== this.me && (e.isTyping ? this.typing.add(e.userId) : this.typing.delete(e.userId));
1139
- return;
1140
- case "reaction": {
1141
- const n = this.byId.get(e.messageId);
1142
- if (!n) return;
1143
- const i = { ...n.reactions ?? {} }, o = (i[e.emoji] ?? []).filter((r) => r !== e.by);
1144
- e.removed || o.push(e.by), o.length ? i[e.emoji] = o : delete i[e.emoji], this.byId.set(e.messageId, { ...n, reactions: i }), this._sorted = null;
1145
- return;
1146
- }
1147
- case "edited": {
1148
- const n = this.byId.get(e.messageId);
1149
- n && (this.byId.set(e.messageId, { ...n, content: e.content, editedAt: e.editedAt }), this._sorted = null);
1150
- return;
1151
- }
1152
- case "deleted": {
1153
- const n = this.byId.get(e.messageId);
1154
- n && (this.byId.set(e.messageId, { ...n, deletedAt: e.ts }), this._sorted = null);
1155
- return;
1156
- }
1157
- case "state":
1158
- this.state = e.state;
1159
- return;
1160
- case "assigned":
1161
- this.assignedAgentId = e.agentId ?? void 0;
1162
- return;
1163
- case "presence":
1164
- e.status === "online" ? this.online.add(e.userId) : this.online.delete(e.userId);
1165
- return;
1166
- case "subjectState":
1167
- case "invoked":
1168
- case "authed":
1169
- case "error":
1170
- case "pong":
1171
- return;
1172
- case "annotation":
1173
- this.annotations = [...this.annotations, e.stroke], this.annotationVersion++;
1174
- return;
1175
- case "annotation_clear":
1176
- this.annotations = [], this.annotationVersion++;
1177
- return;
1178
- case "sentiment":
1179
- this.sentiment = e.label, this.sentimentScore = e.score;
1180
- return;
1181
- default:
1182
- return;
1183
- }
1184
- }
1185
- upsert(e) {
1186
- const t = this.byId.get(e.id);
1187
- this.byId.set(e.id, t ? { ...t, ...e } : e), e.seq > this._maxSeq && (this._maxSeq = e.seq), this._sorted = null;
1188
- }
1189
- markOwnStatus(e, t) {
1190
- const n = ge(t);
1191
- let i = !1;
1192
- for (const [o, r] of this.byId)
1193
- r.senderId !== this.me || r.seq <= 0 || r.seq > e || ge(r.status) >= n || (this.byId.set(o, { ...r, status: t }), i = !0);
1194
- i && (this._sorted = null);
1195
- }
1196
- }
1197
- function ge(s) {
1198
- switch (s) {
1199
- case "read":
1200
- return 3;
1201
- case "delivered":
1202
- return 2;
1203
- case "sent":
1204
- return 1;
1205
- default:
1206
- return 0;
1207
- }
1208
- }
1209
- class Et {
1210
- constructor(e) {
1211
- a(this, "socket", null);
1212
- a(this, "state", "idle");
1213
- a(this, "authed", !1);
1214
- a(this, "everAuthed", !1);
1215
- a(this, "attempt", 0);
1216
- a(this, "outbox", []);
1217
- a(this, "stopped", !1);
1218
- a(this, "timer", null);
1219
- this.opts = e;
1220
- }
1221
- connect() {
1222
- var n, i;
1223
- if (this.state === "connecting" || this.state === "open") return;
1224
- this.stopped = !1, this.state = "connecting", this.authed = !1, (i = (n = this.opts).onStatusChange) == null || i.call(n, this.attempt > 0 ? "reconnecting" : "connecting");
1225
- const t = (this.opts.socketFactory ?? Pt)(this.opts.url);
1226
- t.binaryType = "arraybuffer", this.socket = t, t.onopen = () => {
1227
- this.raw({ type: "auth", token: this.opts.token });
1228
- }, t.onmessage = (o) => {
1229
- const r = It(new Uint8Array(o.data));
1230
- !r || kt(r) || this.handle(r);
1231
- }, t.onclose = () => this.onClosed(), t.onerror = () => {
1232
- try {
1233
- t.close();
1234
- } catch {
1235
- }
1236
- };
1237
- }
1238
- /** Queue a frame; sent immediately if open, else flushed on (re)connect.
1239
- * The outbox is bounded so a prolonged outage can't grow memory without limit
1240
- * — oldest queued frames are dropped past the cap. */
1241
- send(e) {
1242
- if (this.state === "open" && this.authed) {
1243
- this.raw(e);
1244
- return;
1245
- }
1246
- const t = this.opts.maxOutbox ?? 1e3;
1247
- this.outbox.length >= t && (this.outbox = this.outbox.slice(this.outbox.length - (t >> 1))), this.outbox.push(e);
1248
- }
1249
- close() {
16
+ var n;
17
+ if (e.type === "annotation") this.draw(e.stroke);
18
+ else if (e.type === "annotation_clear") this.clear();
19
+ else if (e.type === "opened" && ((n = e.annotations) != null && n.length))
20
+ for (const s of e.annotations) this.draw(s);
21
+ }
22
+ ensureSvg() {
23
+ var n;
24
+ if ((n = this.svg) != null && n.isConnected) return this.svg;
25
+ const e = document.createElementNS(Q, "svg");
26
+ return e.setAttribute("data-relay-annotations", ""), e.setAttribute("aria-hidden", "true"), e.setAttribute(
27
+ "style",
28
+ "position:fixed;inset:0;width:100vw;height:100vh;pointer-events:none;z-index:2147483000;"
29
+ ), document.body.append(e), this.svg = e, e;
30
+ }
31
+ draw(e) {
32
+ var f;
33
+ if (typeof document > "u" || !((f = e.points) != null && f.length)) return;
34
+ const n = this.ensureSvg(), s = window.innerWidth, p = window.innerHeight, d = document.createElementNS(Q, "polyline");
35
+ d.setAttribute("points", e.points.map((h) => `${(h.x * s).toFixed(1)},${(h.y * p).toFixed(1)}`).join(" ")), d.setAttribute("fill", "none"), d.setAttribute("stroke", e.color || "#ff3b30"), d.setAttribute("stroke-width", String(e.width || 3)), d.setAttribute("stroke-linecap", "round"), d.setAttribute("stroke-linejoin", "round"), d.setAttribute("data-stroke-id", e.id), n.append(d);
36
+ const a = setTimeout(() => {
37
+ d.style.transition = "opacity 600ms", d.style.opacity = "0";
38
+ const h = setTimeout(() => {
39
+ d.remove(), this.timers.delete(h);
40
+ }, 650);
41
+ this.timers.add(h), this.timers.delete(a);
42
+ }, ge);
43
+ this.timers.add(a);
44
+ }
45
+ clear() {
1250
46
  var e;
1251
- this.stopped = !0, this.timer && clearTimeout(this.timer), this.state = "closed";
1252
- try {
1253
- (e = this.socket) == null || e.close();
1254
- } catch {
1255
- }
47
+ (e = this.svg) == null || e.replaceChildren();
1256
48
  }
1257
- handle(e) {
1258
- var t, n, i, o, r;
1259
- if (e.type === "authed" && (this.attempt = 0, this.state = "open", this.authed = !0, this.everAuthed = !0, (n = (t = this.opts).onStatusChange) == null || n.call(t, "open"), this.raw(this.opts.open), this.flush()), e.type === "opened" && this.raw({ type: "sync", conversationId: e.conversation.id, sinceSeq: this.opts.getCursor() }), e.type === "error" && Tt.has(e.code)) {
1260
- this.stopped = !0;
1261
- try {
1262
- (i = this.socket) == null || i.close();
1263
- } catch {
1264
- }
1265
- this.state = "closed", (r = (o = this.opts).onStatusChange) == null || r.call(o, "error", Ut(e.code)), this.opts.onFrame(e);
1266
- return;
1267
- }
1268
- this.opts.onFrame(e);
1269
- }
1270
- flush() {
1271
- const e = this.outbox;
1272
- this.outbox = [];
1273
- for (const t of e) this.raw(t);
1274
- }
1275
- raw(e) {
1276
- var t;
1277
- try {
1278
- (t = this.socket) == null || t.send(St(e));
1279
- } catch {
1280
- this.outbox.push(e);
1281
- }
1282
- }
1283
- onClosed() {
1284
- var i, o;
1285
- if (this.authed = !1, this.socket = null, this.stopped) {
1286
- this.state = "closed";
1287
- return;
1288
- }
1289
- this.state = "idle";
1290
- const e = this.opts.backoffBaseMs ?? 500, t = this.opts.backoffMaxMs ?? 15e3, n = Math.min(t, e * 2 ** this.attempt) * (0.5 + Math.random() * 0.5);
1291
- this.attempt++, this.attempt >= 3 && !this.everAuthed && ((o = (i = this.opts).onStatusChange) == null || o.call(i, "reconnecting", "Can't reach chat — retrying…")), this.timer = setTimeout(() => this.connect(), n);
1292
- }
1293
- }
1294
- const Tt = /* @__PURE__ */ new Set(["UNAUTHORIZED"]);
1295
- function Ut(s) {
1296
- switch (s) {
1297
- case "UNAUTHORIZED":
1298
- return "Chat unavailable — sign-in/token was rejected";
1299
- default:
1300
- return "Chat unavailable";
1301
- }
1302
- }
1303
- function Pt(s) {
1304
- return new WebSocket(s);
1305
- }
1306
- const be = 200, Bt = 7 * 864e5;
1307
- class At {
1308
- constructor(e) {
1309
- a(this, "key");
1310
- this.key = `ocw_outbox_${e}`;
1311
- }
1312
- /** All pending items, oldest first, with stale (>7d) entries dropped. */
1313
- load() {
1314
- try {
1315
- const e = localStorage.getItem(this.key);
1316
- if (!e) return [];
1317
- const t = JSON.parse(e), n = Date.now() - Bt, i = t.filter((o) => o.ts >= n);
1318
- return i.length !== t.length && this.save(i), i;
1319
- } catch {
1320
- return [];
1321
- }
1322
- }
1323
- add(e) {
1324
- try {
1325
- const t = this.load();
1326
- t.push(e), this.save(t.length > be ? t.slice(t.length - be) : t);
1327
- } catch {
1328
- }
1329
- }
1330
- /** Remove an item once it's been acknowledged by the server. */
1331
- remove(e) {
1332
- try {
1333
- const t = this.load().filter((n) => n.clientMsgId !== e);
1334
- this.save(t);
1335
- } catch {
1336
- }
1337
- }
1338
- save(e) {
1339
- try {
1340
- localStorage.setItem(this.key, JSON.stringify(e));
1341
- } catch {
1342
- }
1343
- }
1344
- }
1345
- const C = () => globalThis.crypto.subtle;
1346
- function ee(s) {
1347
- const e = s instanceof Uint8Array ? s : new Uint8Array(s);
1348
- let t = "";
1349
- for (const n of e) t += String.fromCharCode(n);
1350
- return btoa(t);
1351
- }
1352
- function ae(s) {
1353
- const e = atob(s), t = new ArrayBuffer(e.length), n = new Uint8Array(t);
1354
- for (let i = 0; i < e.length; i++) n[i] = e.charCodeAt(i);
1355
- return n;
1356
- }
1357
- async function N() {
1358
- const s = await C().generateKey({ name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
1359
- return { publicKey: s.publicKey, privateKey: s.privateKey };
1360
- }
1361
- async function _(s) {
1362
- return ee(await C().exportKey("raw", s));
1363
- }
1364
- async function R(s) {
1365
- return C().importKey("raw", ae(s), { name: "ECDH", namedCurve: "P-256" }, !1, []);
1366
- }
1367
- async function Kt(s, e) {
1368
- const t = await R(e);
1369
- return C().deriveKey(
1370
- { name: "ECDH", public: t },
1371
- s,
1372
- { name: "AES-GCM", length: 256 },
1373
- !1,
1374
- ["encrypt", "decrypt"]
1375
- );
1376
- }
1377
- async function zt(s, e) {
1378
- const t = globalThis.crypto.getRandomValues(new Uint8Array(12)), n = new TextEncoder().encode(e), i = await C().encrypt({ name: "AES-GCM", iv: t }, s, n);
1379
- return { ct: ee(i), iv: ee(t) };
1380
- }
1381
- async function Lt(s, e, t) {
1382
- const n = await C().decrypt({ name: "AES-GCM", iv: ae(t) }, s, ae(e));
1383
- return new TextDecoder().decode(n);
1384
- }
1385
- async function Mt(s) {
1386
- var t, n;
1387
- try {
1388
- const i = (t = globalThis.localStorage) == null ? void 0 : t.getItem(s);
1389
- if (i) {
1390
- const { pub: o, priv: r } = JSON.parse(i), h = await C().importKey("jwk", o, { name: "ECDH", namedCurve: "P-256" }, !0, []), w = await C().importKey("jwk", r, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
1391
- return { publicKey: h, privateKey: w };
1392
- }
1393
- } catch {
1394
- }
1395
- const e = await N();
1396
- try {
1397
- const i = await C().exportKey("jwk", e.publicKey), o = await C().exportKey("jwk", e.privateKey);
1398
- (n = globalThis.localStorage) == null || n.setItem(s, JSON.stringify({ pub: i, priv: o }));
1399
- } catch {
1400
- }
1401
- return e;
1402
- }
1403
- async function Dt(s, e) {
1404
- const t = await C().exportKey("raw", e), n = await C().sign({ name: "ECDSA", hash: "SHA-256" }, s, t);
1405
- return ee(n);
1406
- }
1407
- async function _t() {
1408
- const s = await N(), e = await C().generateKey({ name: "ECDSA", namedCurve: "P-256" }, !0, ["sign", "verify"]);
1409
- return {
1410
- ecdhKP: s,
1411
- ecdsaKP: { publicKey: e.publicKey, privateKey: e.privateKey },
1412
- publicKeyB64: await _(s.publicKey),
1413
- sigPublicKeyB64: await _(e.publicKey)
1414
- };
1415
- }
1416
- async function me(s) {
1417
- var t, n;
1418
- try {
1419
- const i = (t = globalThis.localStorage) == null ? void 0 : t.getItem(`${s}-identity`);
1420
- if (i) {
1421
- const o = JSON.parse(i), r = await C().importKey("jwk", o.ecdhPub, { name: "ECDH", namedCurve: "P-256" }, !0, []), h = await C().importKey("jwk", o.ecdhPriv, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]), w = await C().importKey("jwk", o.ecdsaPub, { name: "ECDSA", namedCurve: "P-256" }, !0, ["verify"]), d = await C().importKey("jwk", o.ecdsaPriv, { name: "ECDSA", namedCurve: "P-256" }, !0, ["sign"]);
1422
- return {
1423
- ecdhKP: { publicKey: r, privateKey: h },
1424
- ecdsaKP: { publicKey: w, privateKey: d },
1425
- publicKeyB64: await _(r),
1426
- sigPublicKeyB64: await _(w)
1427
- };
1428
- }
1429
- } catch {
1430
- }
1431
- const e = await _t();
1432
- try {
1433
- const i = await C().exportKey("jwk", e.ecdhKP.publicKey), o = await C().exportKey("jwk", e.ecdhKP.privateKey), r = await C().exportKey("jwk", e.ecdsaKP.publicKey), h = await C().exportKey("jwk", e.ecdsaKP.privateKey);
1434
- (n = globalThis.localStorage) == null || n.setItem(`${s}-identity`, JSON.stringify({ ecdhPub: i, ecdhPriv: o, ecdsaPub: r, ecdsaPriv: h }));
1435
- } catch {
1436
- }
1437
- return e;
1438
- }
1439
- async function $t(s, e) {
1440
- const t = await N(), n = await _(t.publicKey), i = await R(e.identityKey), o = await R(e.signedPrekey), r = e.oneTimePrekey ? await R(e.oneTimePrekey) : null, h = await D(s.privateKey, o), w = await D(t.privateKey, i), d = await D(t.privateKey, o), v = r ? await D(t.privateKey, r) : null, x = Te(h, w, d, ...v ? [v] : []);
1441
- return { sharedKey: await Ue(x), ephemeralPublicKey: n };
1442
- }
1443
- async function Ht(s, e, t, n, i) {
1444
- const o = await R(t), r = await R(n), h = await D(e.privateKey, o), w = await D(s.privateKey, r), d = await D(e.privateKey, r), v = i ? await D(i.privateKey, r) : null, x = Te(h, w, d, ...v ? [v] : []);
1445
- return Ue(x);
1446
- }
1447
- async function D(s, e) {
1448
- return C().deriveBits({ name: "ECDH", public: e }, s, 256);
1449
- }
1450
- function Te(...s) {
1451
- const e = s.reduce((i, o) => i + o.byteLength, 0), t = new Uint8Array(e);
1452
- let n = 0;
1453
- for (const i of s)
1454
- t.set(new Uint8Array(i), n), n += i.byteLength;
1455
- return t.buffer;
1456
- }
1457
- async function Ue(s) {
1458
- const e = await C().importKey("raw", s, "HKDF", !1, ["deriveKey"]);
1459
- return C().deriveKey(
1460
- { name: "HKDF", hash: "SHA-256", salt: new Uint8Array(32), info: new TextEncoder().encode("ObjectChat X3DH v1") },
1461
- e,
1462
- { name: "AES-GCM", length: 256 },
1463
- !1,
1464
- ["encrypt", "decrypt"]
1465
- );
1466
- }
1467
- const Rt = 20;
1468
- class Ft {
1469
- constructor(e) {
1470
- // Live ECDH mode state
1471
- a(this, "kp");
1472
- a(this, "shared");
1473
- // X3DH async mode state
1474
- a(this, "identityKP");
1475
- a(this, "signedPreKP");
1476
- a(this, "signedPrekeyId");
1477
- a(this, "otpKeys", []);
1478
- // one-time prekeys awaiting matching
1479
- a(this, "x3dhShared");
1480
- // Queued init messages arriving before we could derive (shouldn't happen, but safe)
1481
- a(this, "pendingX3DH");
1482
- this.storageKey = e;
1483
- }
1484
- get ready() {
1485
- return !!(this.shared ?? this.x3dhShared);
1486
- }
1487
- /** Live ECDH mode: Generate/restore our keypair and return our public key to publish. */
1488
- async begin() {
1489
- return this.kp = await Mt(this.storageKey), _(this.kp.publicKey);
1490
- }
1491
- /** Live ECDH mode: A peer published their key — derive the shared secret. */
1492
- async onPeerKey(e) {
1493
- this.kp && (this.shared = await Kt(this.kp.privateKey, e));
1494
- }
1495
- // ── X3DH async mode ────────────────────────────────────────────────────────
1496
- /** X3DH: Generate identity key, signed prekey, and OTP prekeys.
1497
- * Returns the upload frame payload the caller should send to the server. */
1498
- async initX3DH() {
1499
- this.identityKP = await me(this.storageKey), this.signedPreKP = await N(), this.signedPrekeyId = `spk-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1500
- for (let i = 0; i < Rt; i++) this.otpKeys.push(await N());
1501
- const e = await _(this.signedPreKP.publicKey), t = await Dt(this.identityKP.ecdsaKP.privateKey, this.signedPreKP.publicKey), n = await Promise.all(this.otpKeys.map((i) => _(i.publicKey)));
1502
- return {
1503
- identityKey: this.identityKP.publicKeyB64,
1504
- signedPrekey: e,
1505
- signedPrekeyId: this.signedPrekeyId,
1506
- signature: t,
1507
- oneTimePrekeys: n
1508
- };
1509
- }
1510
- /** X3DH sender: given a recipient's prekey bundle, derive the shared key and
1511
- * return the init message fields to embed in the first encrypted message. */
1512
- async x3dhSendTo(e) {
1513
- this.identityKP || (this.identityKP = await me(this.storageKey));
1514
- const { sharedKey: t, ephemeralPublicKey: n } = await $t(this.identityKP.ecdhKP, e);
1515
- return this.x3dhShared = t, { ephemeralKey: n, spkId: e.signedPrekeyId, usedOTP: !!e.oneTimePrekey, senderIK: this.identityKP.publicKeyB64 };
1516
- }
1517
- /** X3DH recipient: given an init message's sender IK + EK + SPK ID, derive the shared key. */
1518
- async x3dhReceiveFrom(e, t, n) {
1519
- if (!this.identityKP || !this.signedPreKP) {
1520
- this.pendingX3DH = { senderIK: e, ephemeralKey: t, spkId: n };
1521
- return;
1522
- }
1523
- const i = this.otpKeys.shift();
1524
- this.x3dhShared = await Ht(this.identityKP.ecdhKP, this.signedPreKP, e, t, i);
1525
- }
1526
- /** Flush pending X3DH derivation after initX3DH() completes. */
1527
- async flushPendingX3DH() {
1528
- if (!this.pendingX3DH) return;
1529
- const { senderIK: e, ephemeralKey: t, spkId: n } = this.pendingX3DH;
1530
- this.pendingX3DH = void 0, await this.x3dhReceiveFrom(e, t, n);
1531
- }
1532
- /** Encrypt outgoing text into a wire content object. For X3DH init messages,
1533
- * the caller should pass x3dhInit fields to embed in the content. */
1534
- async sealText(e, t) {
1535
- const n = this.x3dhShared ?? this.shared;
1536
- if (!n) throw new Error("secure channel not ready");
1537
- const { ct: i, iv: o } = await zt(n, e);
1538
- return {
1539
- kind: "text",
1540
- text: i,
1541
- enc: !0,
1542
- iv: o,
1543
- ...t ? { x3dhEK: t.ephemeralKey, x3dhSPK: t.spkId, x3dhIK: t.senderIK } : {}
1544
- };
1545
- }
1546
- /** Decrypt one content object if it is encrypted (otherwise pass through). */
1547
- async openContent(e) {
1548
- if (e.kind !== "text" || !e.enc || !e.iv) return e;
1549
- const t = this.x3dhShared ?? this.shared;
1550
- if (!t) return { kind: "text", text: "🔒 encrypted" };
1551
- try {
1552
- return { kind: "text", text: await Lt(t, e.text, e.iv) };
1553
- } catch {
1554
- return { kind: "text", text: "🔒 unable to decrypt" };
1555
- }
1556
- }
1557
- /** Decrypt any encrypted message content carried by an incoming frame, in place. */
1558
- async openFrame(e) {
1559
- if (e.type === "message") e.message.content = await this.openContent(e.message.content);
1560
- else if (e.type === "sync")
1561
- for (const t of e.messages) t.content = await this.openContent(t.content);
49
+ destroy() {
50
+ var e;
51
+ for (const n of this.timers) clearTimeout(n);
52
+ this.timers.clear(), (e = this.svg) == null || e.remove(), this.svg = null;
1562
53
  }
1563
54
  }
1564
- function jt(s) {
1565
- if (s.kind !== "text" || !s.enc) return null;
1566
- const e = s;
1567
- return !e.x3dhEK || !e.x3dhSPK || !e.x3dhIK ? null : { x3dhEK: e.x3dhEK, x3dhSPK: e.x3dhSPK, x3dhIK: e.x3dhIK };
1568
- }
1569
- const ve = "objectchat-widget-styles", qt = ["👍", "❤️", "😂", "😮", "😢", "🙏"], Ot = `
55
+ const Z = "objectchat-widget-styles", ve = ["👍", "❤️", "😂", "😮", "😢", "🙏"], ye = `
1570
56
  .ocw { --ocw-accent:#4F63F5; --ocw-bg:#f3efe9; --ocw-card:#fff; --ocw-line:#ececec; --ocw-ink:#1c1b1a; --ocw-mut:#9b9690;
1571
57
  position:relative;
1572
58
  display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
@@ -1726,122 +212,122 @@ const ve = "objectchat-widget-styles", qt = ["👍", "❤️", "😂", "😮", "
1726
212
  .ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
1727
213
  .ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
1728
214
  `;
1729
- function Nt() {
1730
- if (typeof document > "u" || document.getElementById(ve)) return;
1731
- const s = document.createElement("style");
1732
- s.id = ve, s.textContent = Ot, document.head.appendChild(s);
215
+ function ke() {
216
+ if (typeof document > "u" || document.getElementById(Z)) return;
217
+ const t = document.createElement("style");
218
+ t.id = Z, t.textContent = ye, document.head.appendChild(t);
1733
219
  }
1734
- function c(s, e, t) {
1735
- const n = document.createElement(s);
1736
- return e && (n.className = e), t !== void 0 && (n.textContent = t), n;
220
+ function o(t, e, n) {
221
+ const s = document.createElement(t);
222
+ return e && (s.className = e), n !== void 0 && (s.textContent = n), s;
1737
223
  }
1738
- function Vt(s) {
224
+ function Ce(t) {
1739
225
  try {
1740
- return new Date(s).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
226
+ return new Date(t).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
1741
227
  } catch {
1742
228
  return "";
1743
229
  }
1744
230
  }
1745
- function se(s) {
231
+ function _(t) {
1746
232
  var e;
1747
- switch (s.kind) {
233
+ switch (t.kind) {
1748
234
  case "text":
1749
- return s.text;
235
+ return t.text;
1750
236
  case "system":
1751
- return typeof ((e = s.data) == null ? void 0 : e.message) == "string" ? String(s.data.message) : s.event;
237
+ return typeof ((e = t.data) == null ? void 0 : e.message) == "string" ? String(t.data.message) : t.event;
1752
238
  case "card":
1753
- return [s.title, s.body].filter(Boolean).join(" — ");
239
+ return [t.title, t.body].filter(Boolean).join(" — ");
1754
240
  case "attachment":
1755
- return s.name ?? s.url;
241
+ return t.name ?? t.url;
1756
242
  case "form":
1757
- return s.prompt;
243
+ return t.prompt;
1758
244
  case "appointment":
1759
- return `📅 ${s.title} — ${new Date(s.startIso).toLocaleString()}`;
245
+ return `📅 ${t.title} — ${new Date(t.startIso).toLocaleString()}`;
1760
246
  }
1761
247
  }
1762
- class Wt {
248
+ class Te {
1763
249
  /** Last seq the guest has seen per conversationId — used to compute unread badges. */
1764
- constructor(e, t, n, i = {}) {
1765
- a(this, "scroll");
1766
- a(this, "chips");
1767
- a(this, "typing");
1768
- a(this, "quick");
1769
- a(this, "formHost");
1770
- a(this, "csatPanel");
1771
- a(this, "offlinePanel");
1772
- a(this, "footer");
1773
- a(this, "input");
1774
- a(this, "subjectCard");
1775
- a(this, "e2eBadge");
1776
- a(this, "statusBadge");
1777
- a(this, "headerName");
1778
- a(this, "connStatus");
1779
- a(this, "typingTimer", null);
1780
- a(this, "csatSubmitted", !1);
250
+ constructor(e, n, s, p = {}) {
251
+ m(this, "scroll");
252
+ m(this, "chips");
253
+ m(this, "typing");
254
+ m(this, "quick");
255
+ m(this, "formHost");
256
+ m(this, "csatPanel");
257
+ m(this, "offlinePanel");
258
+ m(this, "footer");
259
+ m(this, "input");
260
+ m(this, "subjectCard");
261
+ m(this, "e2eBadge");
262
+ m(this, "statusBadge");
263
+ m(this, "headerName");
264
+ m(this, "connStatus");
265
+ m(this, "typingTimer", null);
266
+ m(this, "csatSubmitted", !1);
1781
267
  // ── Co-browsing (shared whiteboard) ─────────────────────────────────────
1782
- a(this, "cobrowseBtn");
1783
- a(this, "cobrowseCanvas");
1784
- a(this, "cobrowseToolbar");
1785
- a(this, "cobrowseHint");
1786
- a(this, "cobrowseActive", !1);
1787
- a(this, "cobrowseColor", "#f5713c");
1788
- a(this, "lastAnnotationVersion", -1);
1789
- a(this, "storeRef", null);
1790
- a(this, "scrollCleanup", null);
268
+ m(this, "cobrowseBtn");
269
+ m(this, "cobrowseCanvas");
270
+ m(this, "cobrowseToolbar");
271
+ m(this, "cobrowseHint");
272
+ m(this, "cobrowseActive", !1);
273
+ m(this, "cobrowseColor", "#f5713c");
274
+ m(this, "lastAnnotationVersion", -1);
275
+ m(this, "storeRef", null);
276
+ m(this, "scrollCleanup", null);
1791
277
  // ── Live translation ──────────────────────────────────────────────────-
1792
- a(this, "translationCache", /* @__PURE__ */ new Map());
1793
- a(this, "showingTranslation", /* @__PURE__ */ new Set());
1794
- a(this, "subjectBuilt", !1);
1795
- var m, y, U, A, P, K, b, S, M;
1796
- this.root = e, this.me = t, this.h = n, this.cfg = i, Nt(), e.replaceChildren(), e.classList.add("ocw"), i.accent && e.style.setProperty("--ocw-accent", i.accent);
1797
- const o = c("div", "ocw-head"), r = c("div", "ocw-avatar");
1798
- if ((m = i.userInfo) != null && m.avatar) {
1799
- const k = document.createElement("img");
1800
- k.src = i.userInfo.avatar, k.alt = i.userInfo.name ?? "You", k.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover", r.append(k);
278
+ m(this, "translationCache", /* @__PURE__ */ new Map());
279
+ m(this, "showingTranslation", /* @__PURE__ */ new Set());
280
+ m(this, "subjectBuilt", !1);
281
+ var v, w, z, L, I, A, g, k, $;
282
+ this.root = e, this.me = n, this.h = s, this.cfg = p, ke(), e.replaceChildren(), e.classList.add("ocw"), p.accent && e.style.setProperty("--ocw-accent", p.accent);
283
+ const d = o("div", "ocw-head"), a = o("div", "ocw-avatar");
284
+ if ((v = p.userInfo) != null && v.avatar) {
285
+ const y = document.createElement("img");
286
+ y.src = p.userInfo.avatar, y.alt = p.userInfo.name ?? "You", y.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover", a.append(y);
1801
287
  } else
1802
- r.textContent = (y = i.userInfo) != null && y.name ? i.userInfo.name[0].toUpperCase() : "🧑";
1803
- o.append(r);
1804
- const h = c("div", "ocw-head-main");
1805
- this.headerName = c("div", "ocw-head-name", ((U = i.subject) == null ? void 0 : U.ownerLabel) ?? ((A = i.subject) == null ? void 0 : A.title) ?? ""), h.append(this.headerName), (P = i.subject) != null && P.subtitle && h.append(c("div", "ocw-head-meta", i.subject.subtitle)), o.append(h), this.statusBadge = c("span", "ocw-badge", ((K = i.subject) == null ? void 0 : K.status) ?? ""), (b = i.subject) != null && b.status || (this.statusBadge.style.display = "none"), o.append(this.statusBadge), this.e2eBadge = c("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", o.append(this.e2eBadge), this.connStatus = c("span", "ocw-conn-status"), this.connStatus.style.display = "none", o.append(this.connStatus), this.cobrowseBtn = c("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
288
+ a.textContent = (w = p.userInfo) != null && w.name ? p.userInfo.name[0].toUpperCase() : "🧑";
289
+ d.append(a);
290
+ const f = o("div", "ocw-head-main");
291
+ this.headerName = o("div", "ocw-head-name", ((z = p.subject) == null ? void 0 : z.ownerLabel) ?? ((L = p.subject) == null ? void 0 : L.title) ?? ""), f.append(this.headerName), (I = p.subject) != null && I.subtitle && f.append(o("div", "ocw-head-meta", p.subject.subtitle)), d.append(f), this.statusBadge = o("span", "ocw-badge", ((A = p.subject) == null ? void 0 : A.status) ?? ""), (g = p.subject) != null && g.status || (this.statusBadge.style.display = "none"), d.append(this.statusBadge), this.e2eBadge = o("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", d.append(this.e2eBadge), this.connStatus = o("span", "ocw-conn-status"), this.connStatus.style.display = "none", d.append(this.connStatus), this.cobrowseBtn = o("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
1806
292
  this.cobrowseActive = !this.cobrowseActive, this.updateCobrowseUI();
1807
- }), o.append(this.cobrowseBtn), o.append(c("button", "ocw-menu", "⋯")), this.chips = c("div", "ocw-chiprow"), this.scroll = c("div", "ocw-scroll"), this.subjectCard = c("div", "ocw-subject"), this.typing = c("div", "ocw-typing");
1808
- const w = c("div", "ocw-typing-bubble");
1809
- w.append(c("div", "ocw-typing-dot"), c("div", "ocw-typing-dot"), c("div", "ocw-typing-dot")), this.typing.append(c("div", "ocw-dot", "🧑"), w), this.quick = c("div", "ocw-quick");
1810
- for (const k of i.quickReplies ?? []) {
1811
- const T = c("button", void 0, k);
1812
- T.addEventListener("click", () => {
1813
- this.h.onSend(k), this.quick.style.display = "none";
1814
- }), this.quick.append(T);
1815
- }
1816
- this.formHost = c("div", "ocw-form-host"), this.csatPanel = c("div", "ocw-csat"), this.csatPanel.style.display = "none", this.offlinePanel = c("div", "ocw-offline"), this.offlinePanel.style.display = "none", this.input = c("textarea", void 0), this.input.rows = 1, this.input.placeholder = "Message…";
1817
- const d = c("button", "ocw-sendbtn", ((S = i.i18n) == null ? void 0 : S.send) ?? "➤");
1818
- d.addEventListener("click", () => this.flushSend()), this.input.addEventListener("keydown", (k) => {
1819
- k.isComposing || k.keyCode === 229 || (k.key === "Enter" && !k.shiftKey ? (k.preventDefault(), this.flushSend()) : this.signalTyping());
293
+ }), d.append(this.cobrowseBtn), d.append(o("button", "ocw-menu", "⋯")), this.chips = o("div", "ocw-chiprow"), this.scroll = o("div", "ocw-scroll"), this.subjectCard = o("div", "ocw-subject"), this.typing = o("div", "ocw-typing");
294
+ const h = o("div", "ocw-typing-bubble");
295
+ h.append(o("div", "ocw-typing-dot"), o("div", "ocw-typing-dot"), o("div", "ocw-typing-dot")), this.typing.append(o("div", "ocw-dot", "🧑"), h), this.quick = o("div", "ocw-quick");
296
+ for (const y of p.quickReplies ?? []) {
297
+ const E = o("button", void 0, y);
298
+ E.addEventListener("click", () => {
299
+ this.h.onSend(y), this.quick.style.display = "none";
300
+ }), this.quick.append(E);
301
+ }
302
+ this.formHost = o("div", "ocw-form-host"), this.csatPanel = o("div", "ocw-csat"), this.csatPanel.style.display = "none", this.offlinePanel = o("div", "ocw-offline"), this.offlinePanel.style.display = "none", this.input = o("textarea", void 0), this.input.rows = 1, this.input.placeholder = "Message…";
303
+ const r = o("button", "ocw-sendbtn", ((k = p.i18n) == null ? void 0 : k.send) ?? "➤");
304
+ r.addEventListener("click", () => this.flushSend()), this.input.addEventListener("keydown", (y) => {
305
+ y.isComposing || y.keyCode === 229 || (y.key === "Enter" && !y.shiftKey ? (y.preventDefault(), this.flushSend()) : this.signalTyping());
1820
306
  });
1821
- const v = c("button", "ocw-attach", "📎");
1822
- v.title = "Attach image or file";
1823
- const x = document.createElement("input");
1824
- x.type = "file", x.accept = "image/*,.pdf,.txt,.doc,.docx", x.style.display = "none", v.addEventListener("click", () => x.click()), x.addEventListener("change", () => {
1825
- var k;
1826
- (k = x.files) != null && k[0] && this.h.onAttach && this.h.onAttach(x.files[0]), x.value = "";
307
+ const T = o("button", "ocw-attach", "📎");
308
+ T.title = "Attach image or file";
309
+ const b = document.createElement("input");
310
+ b.type = "file", b.accept = "image/*,.pdf,.txt,.doc,.docx", b.style.display = "none", T.addEventListener("click", () => b.click()), b.addEventListener("change", () => {
311
+ var y;
312
+ (y = b.files) != null && y[0] && this.h.onAttach && this.h.onAttach(b.files[0]), b.value = "";
1827
313
  });
1828
- const u = c("div", "ocw-input");
1829
- u.append(v, x, this.input, d);
1830
- const p = c("div", "ocw-footer");
1831
- ((M = i.i18n) == null ? void 0 : M.poweredBy) !== void 0 ? p.textContent = i.i18n.poweredBy : p.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = p, e.append(o, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, u, this.footer), this.cobrowseCanvas = c("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = c("div", "ocw-cobrowse-toolbar");
1832
- for (const k of ["#f5713c", "#1c1b1a", "#2563eb", "#16a34a", "#dc2626"]) {
1833
- const T = c("button", "ocw-cobrowse-swatch");
1834
- T.style.background = k, T.type = "button", k === this.cobrowseColor && T.classList.add("sel"), T.addEventListener("click", () => {
1835
- this.cobrowseColor = k;
1836
- for (const V of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch")) V.classList.remove("sel");
1837
- T.classList.add("sel");
1838
- }), this.cobrowseToolbar.append(T);
1839
- }
1840
- const I = c("button", "ocw-cobrowse-clear", "Clear");
1841
- I.addEventListener("click", () => {
1842
- var k, T;
1843
- return (T = (k = this.h).onAnnotateClear) == null ? void 0 : T.call(k);
1844
- }), this.cobrowseToolbar.append(I), this.cobrowseHint = c("div", "ocw-cobrowse-hint", "🖍 Draw to point things out — visible to both sides"), e.append(this.cobrowseCanvas, this.cobrowseToolbar, this.cobrowseHint), this.bindCobrowsePointerEvents();
314
+ const l = o("div", "ocw-input");
315
+ l.append(T, b, this.input, r);
316
+ const c = o("div", "ocw-footer");
317
+ (($ = p.i18n) == null ? void 0 : $.poweredBy) !== void 0 ? c.textContent = p.i18n.poweredBy : c.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = c, e.append(d, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, l, this.footer), this.cobrowseCanvas = o("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = o("div", "ocw-cobrowse-toolbar");
318
+ for (const y of ["#f5713c", "#1c1b1a", "#2563eb", "#16a34a", "#dc2626"]) {
319
+ const E = o("button", "ocw-cobrowse-swatch");
320
+ E.style.background = y, E.type = "button", y === this.cobrowseColor && E.classList.add("sel"), E.addEventListener("click", () => {
321
+ this.cobrowseColor = y;
322
+ for (const R of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch")) R.classList.remove("sel");
323
+ E.classList.add("sel");
324
+ }), this.cobrowseToolbar.append(E);
325
+ }
326
+ const C = o("button", "ocw-cobrowse-clear", "Clear");
327
+ C.addEventListener("click", () => {
328
+ var y, E;
329
+ return (E = (y = this.h).onAnnotateClear) == null ? void 0 : E.call(y);
330
+ }), this.cobrowseToolbar.append(C), this.cobrowseHint = o("div", "ocw-cobrowse-hint", "🖍 Draw to point things out — visible to both sides"), e.append(this.cobrowseCanvas, this.cobrowseToolbar, this.cobrowseHint), this.bindCobrowsePointerEvents();
1845
331
  }
1846
332
  /** Returns the scroll container so history.ts can attach scroll listeners. */
1847
333
  getScrollEl() {
@@ -1849,8 +335,8 @@ class Wt {
1849
335
  }
1850
336
  /** Registers a cleanup fn removed on destroy() to prevent listener leaks. */
1851
337
  setScrollCleanup(e) {
1852
- var t;
1853
- (t = this.scrollCleanup) == null || t.call(this), this.scrollCleanup = e;
338
+ var n;
339
+ (n = this.scrollCleanup) == null || n.call(this), this.scrollCleanup = e;
1854
340
  }
1855
341
  /** Call when the widget is unmounted. Disconnects scroll listeners and clears timers. */
1856
342
  destroy() {
@@ -1871,66 +357,66 @@ class Wt {
1871
357
  this.h.onTyping(!0, e), this.typingTimer && clearTimeout(this.typingTimer), this.typingTimer = setTimeout(() => this.h.onTyping(!1), 2e3);
1872
358
  }
1873
359
  render(e) {
1874
- var d, v, x;
360
+ var r, T, b;
1875
361
  if (this.storeRef = e, this.cobrowseBtn.classList.toggle("show", !!e.subject), !e.subject && this.cobrowseActive && (this.cobrowseActive = !1, this.updateCobrowseUI()), this.cobrowseActive && e.annotationVersion !== this.lastAnnotationVersion && (this.lastAnnotationVersion = e.annotationVersion, this.resizeCobrowseCanvas(), this.redrawCobrowse()), e.accent && this.root.style.setProperty("--ocw-accent", e.accent), this.e2eBadge.style.display = e.e2e ? "inline-flex" : "none", this.buildSubjectCard(e), e.subject) {
1876
- const u = (d = this.cfg.subject) == null ? void 0 : d.ownerLabel;
1877
- u && (this.headerName.textContent = u);
362
+ const l = (r = this.cfg.subject) == null ? void 0 : r.ownerLabel;
363
+ l && (this.headerName.textContent = l);
1878
364
  }
1879
365
  this.quick.style.display = e.messages().length === 0 ? "flex" : "none", this.chips.replaceChildren();
1880
- const t = e.visibleActions();
1881
- this.chips.style.display = t.length ? "flex" : "none";
1882
- for (const u of t) this.chips.append(this.chipEl(u));
1883
- const n = this.scroll.scrollHeight, i = this.scroll.scrollTop;
366
+ const n = e.visibleActions();
367
+ this.chips.style.display = n.length ? "flex" : "none";
368
+ for (const l of n) this.chips.append(this.chipEl(l));
369
+ const s = this.scroll.scrollHeight, p = this.scroll.scrollTop;
1884
370
  if (this.scroll.replaceChildren(), this.subjectCard.childNodes.length && this.scroll.append(this.subjectCard), e.hasMoreHistory) {
1885
- const u = c("div", "ocw-load-more");
1886
- u.textContent = "↑ Loading earlier messages…", u.style.pointerEvents = "none", this.scroll.append(u);
1887
- }
1888
- let o = 0;
1889
- for (const u of e.messages())
1890
- this.scroll.append(this.messageEl(u, e)), u.senderId !== this.me && u.seq > o && (o = u.seq);
1891
- i > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - n + i : this.scroll.scrollTop = this.scroll.scrollHeight, o > 0 && this.h.onReadUpTo(o);
1892
- const r = [...e.typing];
1893
- this.typing.classList.toggle("active", r.length > 0);
1894
- const h = this.typing.querySelector(".ocw-typing-bubble");
1895
- h && h.setAttribute("aria-label", r.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (v = this.root.querySelector(".ocw-input")) == null || v.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (x = this.root.querySelector(".ocw-input")) == null || x.style.removeProperty("display"));
1896
- const w = ["resolved", "closed", "sold", "issued", "checked_out"];
1897
- this.h.onCsat && !this.csatSubmitted && w.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
1898
- }
1899
- setConnStatus(e, t) {
371
+ const l = o("div", "ocw-load-more");
372
+ l.textContent = "↑ Loading earlier messages…", l.style.pointerEvents = "none", this.scroll.append(l);
373
+ }
374
+ let d = 0;
375
+ for (const l of e.messages())
376
+ this.scroll.append(this.messageEl(l, e)), l.senderId !== this.me && l.seq > d && (d = l.seq);
377
+ p > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - s + p : this.scroll.scrollTop = this.scroll.scrollHeight, d > 0 && this.h.onReadUpTo(d);
378
+ const a = [...e.typing];
379
+ this.typing.classList.toggle("active", a.length > 0);
380
+ const f = this.typing.querySelector(".ocw-typing-bubble");
381
+ f && f.setAttribute("aria-label", a.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (T = this.root.querySelector(".ocw-input")) == null || T.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (b = this.root.querySelector(".ocw-input")) == null || b.style.removeProperty("display"));
382
+ const h = ["resolved", "closed", "sold", "issued", "checked_out"];
383
+ this.h.onCsat && !this.csatSubmitted && h.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
384
+ }
385
+ setConnStatus(e, n) {
1900
386
  if (e === "open") {
1901
387
  this.connStatus.style.display = "none";
1902
388
  return;
1903
389
  }
1904
390
  this.connStatus.style.display = "";
1905
- const n = e === "error";
1906
- this.connStatus.className = `ocw-conn-status${n ? " err" : e === "reconnecting" ? " warn" : ""}`, this.connStatus.textContent = n ? `⚠ ${t ?? "Chat unavailable"}` : e === "reconnecting" ? t ?? "↻ reconnecting…" : "● connecting…";
391
+ const s = e === "error";
392
+ this.connStatus.className = `ocw-conn-status${s ? " err" : e === "reconnecting" ? " warn" : ""}`, this.connStatus.textContent = s ? `⚠ ${n ?? "Chat unavailable"}` : e === "reconnecting" ? n ?? "↻ reconnecting…" : "● connecting…";
1907
393
  }
1908
394
  buildOfflinePanel(e) {
1909
- var h;
1910
- this.offlinePanel.replaceChildren(), this.offlinePanel.append(c("div", "ocw-offline-icon", "🌙")), this.offlinePanel.append(c("div", "ocw-offline-title", ((h = this.cfg.i18n) == null ? void 0 : h.offline) ?? "We're offline right now")), this.offlinePanel.append(c("div", "ocw-offline-msg", e || "Leave your details and we'll get back to you soon."));
1911
- const t = c("div", "ocw-offline-form"), n = c("input", "ocw-offline-input");
1912
- n.placeholder = "Your name", n.type = "text";
1913
- const i = c("input", "ocw-offline-input");
1914
- i.placeholder = "Your email", i.type = "email";
1915
- const o = c("textarea", "ocw-offline-input");
1916
- o.placeholder = "Your message", o.rows = 3;
1917
- const r = c("button", "ocw-offline-submit", "Send message");
1918
- r.addEventListener("click", () => {
1919
- !i.value.trim() || !o.value.trim() || (this.h.onSend(`[Offline form]
1920
- Name: ${n.value || "Anonymous"}
1921
- Email: ${i.value}
1922
- Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-thanks", "✓ Message sent! We'll reply to your email.")));
1923
- }), t.append(n, i, o, r), this.offlinePanel.append(t);
395
+ var f;
396
+ this.offlinePanel.replaceChildren(), this.offlinePanel.append(o("div", "ocw-offline-icon", "🌙")), this.offlinePanel.append(o("div", "ocw-offline-title", ((f = this.cfg.i18n) == null ? void 0 : f.offline) ?? "We're offline right now")), this.offlinePanel.append(o("div", "ocw-offline-msg", e || "Leave your details and we'll get back to you soon."));
397
+ const n = o("div", "ocw-offline-form"), s = o("input", "ocw-offline-input");
398
+ s.placeholder = "Your name", s.type = "text";
399
+ const p = o("input", "ocw-offline-input");
400
+ p.placeholder = "Your email", p.type = "email";
401
+ const d = o("textarea", "ocw-offline-input");
402
+ d.placeholder = "Your message", d.rows = 3;
403
+ const a = o("button", "ocw-offline-submit", "Send message");
404
+ a.addEventListener("click", () => {
405
+ !p.value.trim() || !d.value.trim() || (this.h.onSend(`[Offline form]
406
+ Name: ${s.value || "Anonymous"}
407
+ Email: ${p.value}
408
+ Message: ${d.value}`), this.offlinePanel.replaceChildren(o("div", "ocw-offline-thanks", "✓ Message sent! We'll reply to your email.")));
409
+ }), n.append(s, p, d, a), this.offlinePanel.append(n);
1924
410
  }
1925
411
  buildCsatPanel() {
1926
- this.csatPanel.replaceChildren(), this.csatPanel.append(c("div", "ocw-csat-title", "How did we do?"));
1927
- const e = c("div", "ocw-csat-stars"), t = [];
1928
- for (let n = 1; n <= 5; n++) {
1929
- const i = c("button", "ocw-csat-star", "★");
1930
- i.dataset.score = String(n), i.addEventListener("mouseenter", () => t.forEach((o, r) => o.classList.toggle("lit", r < n))), i.addEventListener("mouseleave", () => t.forEach((o) => o.classList.remove("lit"))), i.addEventListener("click", () => {
1931
- var o, r;
1932
- this.csatSubmitted = !0, this.csatPanel.replaceChildren(c("div", "ocw-csat-done", `Thanks for your ${n}★ rating!`)), (r = (o = this.h).onCsat) == null || r.call(o, n);
1933
- }), t.push(i), e.append(i);
412
+ this.csatPanel.replaceChildren(), this.csatPanel.append(o("div", "ocw-csat-title", "How did we do?"));
413
+ const e = o("div", "ocw-csat-stars"), n = [];
414
+ for (let s = 1; s <= 5; s++) {
415
+ const p = o("button", "ocw-csat-star", "★");
416
+ p.dataset.score = String(s), p.addEventListener("mouseenter", () => n.forEach((d, a) => d.classList.toggle("lit", a < s))), p.addEventListener("mouseleave", () => n.forEach((d) => d.classList.remove("lit"))), p.addEventListener("click", () => {
417
+ var d, a;
418
+ this.csatSubmitted = !0, this.csatPanel.replaceChildren(o("div", "ocw-csat-done", `Thanks for your ${s}★ rating!`)), (a = (d = this.h).onCsat) == null || a.call(d, s);
419
+ }), n.push(p), e.append(p);
1934
420
  }
1935
421
  this.csatPanel.append(e);
1936
422
  }
@@ -1946,242 +432,242 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(c("div", "ocw-offline-t
1946
432
  /** Draw a stroke whose points are normalized to 0..1, scaled to the current
1947
433
  * canvas size — so strokes line up across different viewport sizes. */
1948
434
  drawStroke(e) {
1949
- const t = this.cobrowseCanvas.getContext("2d");
1950
- if (!t || e.points.length < 2) return;
1951
- const n = this.cobrowseCanvas.width, i = this.cobrowseCanvas.height;
1952
- t.strokeStyle = e.color, t.lineWidth = Math.max(1, e.width * Math.min(n, i)), t.lineJoin = "round", t.lineCap = "round", t.beginPath(), t.moveTo(e.points[0].x * n, e.points[0].y * i);
1953
- for (const o of e.points.slice(1)) t.lineTo(o.x * n, o.y * i);
1954
- t.stroke();
435
+ const n = this.cobrowseCanvas.getContext("2d");
436
+ if (!n || e.points.length < 2) return;
437
+ const s = this.cobrowseCanvas.width, p = this.cobrowseCanvas.height;
438
+ n.strokeStyle = e.color, n.lineWidth = Math.max(1, e.width * Math.min(s, p)), n.lineJoin = "round", n.lineCap = "round", n.beginPath(), n.moveTo(e.points[0].x * s, e.points[0].y * p);
439
+ for (const d of e.points.slice(1)) n.lineTo(d.x * s, d.y * p);
440
+ n.stroke();
1955
441
  }
1956
442
  redrawCobrowse() {
1957
- var t;
443
+ var n;
1958
444
  const e = this.cobrowseCanvas.getContext("2d");
1959
445
  if (e) {
1960
446
  e.clearRect(0, 0, this.cobrowseCanvas.width, this.cobrowseCanvas.height);
1961
- for (const n of ((t = this.storeRef) == null ? void 0 : t.annotations) ?? []) this.drawStroke(n);
447
+ for (const s of ((n = this.storeRef) == null ? void 0 : n.annotations) ?? []) this.drawStroke(s);
1962
448
  }
1963
449
  }
1964
450
  bindCobrowsePointerEvents() {
1965
- let e = !1, t = [];
1966
- const n = (r) => {
1967
- const h = this.cobrowseCanvas.getBoundingClientRect(), w = h.width > 0 ? (r.clientX - h.left) / h.width : 0, d = h.height > 0 ? (r.clientY - h.top) / h.height : 0;
1968
- return { x: Math.min(1, Math.max(0, w)), y: Math.min(1, Math.max(0, d)) };
1969
- }, i = 6e-3;
1970
- this.cobrowseCanvas.addEventListener("pointerdown", (r) => {
1971
- this.cobrowseActive && (e = !0, t = [n(r)], this.cobrowseCanvas.setPointerCapture(r.pointerId));
1972
- }), this.cobrowseCanvas.addEventListener("pointermove", (r) => {
1973
- e && (t.push(n(r)), this.redrawCobrowse(), this.drawStroke({ points: t, color: this.cobrowseColor, width: i }));
451
+ let e = !1, n = [];
452
+ const s = (a) => {
453
+ const f = this.cobrowseCanvas.getBoundingClientRect(), h = f.width > 0 ? (a.clientX - f.left) / f.width : 0, r = f.height > 0 ? (a.clientY - f.top) / f.height : 0;
454
+ return { x: Math.min(1, Math.max(0, h)), y: Math.min(1, Math.max(0, r)) };
455
+ }, p = 6e-3;
456
+ this.cobrowseCanvas.addEventListener("pointerdown", (a) => {
457
+ this.cobrowseActive && (e = !0, n = [s(a)], this.cobrowseCanvas.setPointerCapture(a.pointerId));
458
+ }), this.cobrowseCanvas.addEventListener("pointermove", (a) => {
459
+ e && (n.push(s(a)), this.redrawCobrowse(), this.drawStroke({ points: n, color: this.cobrowseColor, width: p }));
1974
460
  });
1975
- const o = (r) => {
1976
- var h, w;
461
+ const d = (a) => {
462
+ var f, h;
1977
463
  if (e) {
1978
- e = !1, t.length > 1 && ((w = (h = this.h).onAnnotate) == null || w.call(h, { id: `an_${Date.now()}_${Math.random().toString(36).slice(2)}`, points: t, color: this.cobrowseColor, width: i })), t = [];
464
+ e = !1, n.length > 1 && ((h = (f = this.h).onAnnotate) == null || h.call(f, { id: `an_${Date.now()}_${Math.random().toString(36).slice(2)}`, points: n, color: this.cobrowseColor, width: p })), n = [];
1979
465
  try {
1980
- this.cobrowseCanvas.releasePointerCapture(r.pointerId);
466
+ this.cobrowseCanvas.releasePointerCapture(a.pointerId);
1981
467
  } catch {
1982
468
  }
1983
469
  }
1984
470
  };
1985
- this.cobrowseCanvas.addEventListener("pointerup", o), this.cobrowseCanvas.addEventListener("pointercancel", o);
471
+ this.cobrowseCanvas.addEventListener("pointerup", d), this.cobrowseCanvas.addEventListener("pointercancel", d);
1986
472
  }
1987
473
  buildSubjectCard(e) {
1988
474
  if (this.subjectBuilt) return;
1989
- const t = e.subject, n = this.cfg.subject, i = (t == null ? void 0 : t.title) ?? (n == null ? void 0 : n.title);
1990
- if (!i) return;
1991
- this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(c("div", "ocw-subject-title", i)), n != null && n.subtitle && this.subjectCard.append(c("div", "ocw-subject-sub", n.subtitle));
1992
- const o = c("div", "ocw-tags");
1993
- if (t) for (const [h, w] of Object.entries(t.fields)) o.append(c("span", "ocw-tag", `${h}: ${w}`));
1994
- else for (const h of (n == null ? void 0 : n.tags) ?? []) o.append(c("span", "ocw-tag", h));
1995
- o.childNodes.length && this.subjectCard.append(o);
1996
- const r = (t == null ? void 0 : t.state) ?? (n == null ? void 0 : n.status);
1997
- r && (this.statusBadge.textContent = r, this.statusBadge.style.display = "inline-flex");
475
+ const n = e.subject, s = this.cfg.subject, p = (n == null ? void 0 : n.title) ?? (s == null ? void 0 : s.title);
476
+ if (!p) return;
477
+ this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(o("div", "ocw-subject-title", p)), s != null && s.subtitle && this.subjectCard.append(o("div", "ocw-subject-sub", s.subtitle));
478
+ const d = o("div", "ocw-tags");
479
+ if (n) for (const [f, h] of Object.entries(n.fields)) d.append(o("span", "ocw-tag", `${f}: ${h}`));
480
+ else for (const f of (s == null ? void 0 : s.tags) ?? []) d.append(o("span", "ocw-tag", f));
481
+ d.childNodes.length && this.subjectCard.append(d);
482
+ const a = (n == null ? void 0 : n.state) ?? (s == null ? void 0 : s.status);
483
+ a && (this.statusBadge.textContent = a, this.statusBadge.style.display = "inline-flex");
1998
484
  }
1999
485
  chipEl(e) {
2000
- const t = c("button", "ocw-chip", e.icon ? `${e.icon} ${e.label}` : e.label);
2001
- return t.dataset.actionId = e.id, t.addEventListener("click", async () => {
2002
- var n;
2003
- e.confirm && !await this.confirm(e.label) || ((n = e.input) != null && n.length ? this.openForm(e) : this.h.onInvoke(e.id));
2004
- }), t;
486
+ const n = o("button", "ocw-chip", e.icon ? `${e.icon} ${e.label}` : e.label);
487
+ return n.dataset.actionId = e.id, n.addEventListener("click", async () => {
488
+ var s;
489
+ e.confirm && !await this.confirm(e.label) || ((s = e.input) != null && s.length ? this.openForm(e) : this.h.onInvoke(e.id));
490
+ }), n;
2005
491
  }
2006
492
  /** In-widget confirmation modal (replaces window.confirm). */
2007
493
  confirm(e) {
2008
- return new Promise((t) => {
2009
- const n = c("div", "ocw-modal"), i = c("div", "ocw-modal-card");
2010
- i.append(c("div", "ocw-modal-title", e)), i.append(c("div", "ocw-modal-body", `Confirm “${e}”?`));
2011
- const o = c("div", "ocw-modal-actions"), r = c("button", "ocw-modal-cancel", "Cancel"), h = c("button", "ocw-modal-ok", "Confirm"), w = (d) => {
2012
- n.remove(), t(d);
494
+ return new Promise((n) => {
495
+ const s = o("div", "ocw-modal"), p = o("div", "ocw-modal-card");
496
+ p.append(o("div", "ocw-modal-title", e)), p.append(o("div", "ocw-modal-body", `Confirm “${e}”?`));
497
+ const d = o("div", "ocw-modal-actions"), a = o("button", "ocw-modal-cancel", "Cancel"), f = o("button", "ocw-modal-ok", "Confirm"), h = (r) => {
498
+ s.remove(), n(r);
2013
499
  };
2014
- r.addEventListener("click", () => w(!1)), h.addEventListener("click", () => w(!0)), n.addEventListener("click", (d) => {
2015
- d.target === n && w(!1);
2016
- }), o.append(r, h), i.append(o), n.append(i), this.root.append(n), h.focus();
500
+ a.addEventListener("click", () => h(!1)), f.addEventListener("click", () => h(!0)), s.addEventListener("click", (r) => {
501
+ r.target === s && h(!1);
502
+ }), d.append(a, f), p.append(d), s.append(p), this.root.append(s), f.focus();
2017
503
  });
2018
504
  }
2019
505
  /** Inline form for a form-effect action: typed inputs (date picker, number,
2020
506
  * text) rendered above the composer — no browser prompts. */
2021
507
  openForm(e) {
2022
- var h, w;
508
+ var f, h;
2023
509
  this.formHost.replaceChildren();
2024
- const t = c("div", "ocw-form");
2025
- t.append(c("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
2026
- const n = /* @__PURE__ */ new Map();
2027
- for (const d of e.input ?? []) {
2028
- const v = c("label", "ocw-form-row");
2029
- if (v.append(c("span", "ocw-form-lbl", d.label)), d.type === "select" && ((h = d.options) != null && h.length)) {
2030
- const x = c("select", "ocw-form-input");
2031
- d.required || x.append(c("option", void 0, "— select —"));
2032
- for (const u of d.options) {
2033
- const p = c("option");
2034
- p.value = u, p.textContent = u, x.append(p);
510
+ const n = o("div", "ocw-form");
511
+ n.append(o("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
512
+ const s = /* @__PURE__ */ new Map();
513
+ for (const r of e.input ?? []) {
514
+ const T = o("label", "ocw-form-row");
515
+ if (T.append(o("span", "ocw-form-lbl", r.label)), r.type === "select" && ((f = r.options) != null && f.length)) {
516
+ const b = o("select", "ocw-form-input");
517
+ r.required || b.append(o("option", void 0, "— select —"));
518
+ for (const l of r.options) {
519
+ const c = o("option");
520
+ c.value = l, c.textContent = l, b.append(c);
2035
521
  }
2036
- d.required && (x.required = !0), v.append(x), n.set(d.name, x);
522
+ r.required && (b.required = !0), T.append(b), s.set(r.name, b);
2037
523
  } else {
2038
- const x = c("input", "ocw-form-input");
2039
- x.type = d.type === "number" ? "number" : d.type === "date" ? "datetime-local" : "text", d.required && (x.required = !0), v.append(x), n.set(d.name, x);
524
+ const b = o("input", "ocw-form-input");
525
+ b.type = r.type === "number" ? "number" : r.type === "date" ? "datetime-local" : "text", r.required && (b.required = !0), T.append(b), s.set(r.name, b);
2040
526
  }
2041
- t.append(v);
2042
- }
2043
- const i = c("div", "ocw-form-actions"), o = c("button", "ocw-form-cancel", "Cancel"), r = c("button", "ocw-form-submit", "Send");
2044
- o.addEventListener("click", () => this.formHost.replaceChildren()), r.addEventListener("click", () => {
2045
- const d = {};
2046
- for (const [v, x] of n) {
2047
- if (x.required && !x.value) {
2048
- x.style.borderColor = "#e5484d";
527
+ n.append(T);
528
+ }
529
+ const p = o("div", "ocw-form-actions"), d = o("button", "ocw-form-cancel", "Cancel"), a = o("button", "ocw-form-submit", "Send");
530
+ d.addEventListener("click", () => this.formHost.replaceChildren()), a.addEventListener("click", () => {
531
+ const r = {};
532
+ for (const [T, b] of s) {
533
+ if (b.required && !b.value) {
534
+ b.style.borderColor = "#e5484d";
2049
535
  return;
2050
536
  }
2051
- d[v] = x.type === "number" ? Number(x.value) : x.value;
537
+ r[T] = b.type === "number" ? Number(b.value) : b.value;
2052
538
  }
2053
- this.formHost.replaceChildren(), this.h.onInvoke(e.id, d);
2054
- }), i.append(o, r), t.append(i), this.formHost.append(t), (w = n.values().next().value) == null || w.focus();
539
+ this.formHost.replaceChildren(), this.h.onInvoke(e.id, r);
540
+ }), p.append(d, a), n.append(p), this.formHost.append(n), (h = s.values().next().value) == null || h.focus();
2055
541
  }
2056
- messageEl(e, t) {
2057
- var x;
542
+ messageEl(e, n) {
543
+ var b;
2058
544
  if (e.senderRole === "system") {
2059
- const u = c("div", "ocw-sys");
2060
- return u.textContent = e.deletedAt ? "message deleted" : se(e.content), u;
545
+ const l = o("div", "ocw-sys");
546
+ return l.textContent = e.deletedAt ? "message deleted" : _(e.content), l;
2061
547
  }
2062
- const n = e.senderId === this.me, i = !!e.internal, o = c("div", `ocw-row ${i ? "ocw-note mine" : n ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
2063
- !n && !i && o.append(c("div", "ocw-dot", e.senderRole === "bot" ? "🤖" : "🧑"));
2064
- const r = c("div"), h = c("div", "ocw-bubble-wrap");
548
+ const s = e.senderId === this.me, p = !!e.internal, d = o("div", `ocw-row ${p ? "ocw-note mine" : s ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
549
+ !s && !p && d.append(o("div", "ocw-dot", e.senderRole === "bot" ? "🤖" : "🧑"));
550
+ const a = o("div"), f = o("div", "ocw-bubble-wrap");
2065
551
  if (e.replyToId) {
2066
- const u = c("div", "ocw-reply-to", "↩ replying to a message");
2067
- u.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", r.append(u);
552
+ const l = o("div", "ocw-reply-to", "↩ replying to a message");
553
+ l.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", a.append(l);
2068
554
  }
2069
- const w = c("div", "ocw-bubble");
2070
- let d = null;
2071
- if (e.deletedAt) w.append(c("span", "ocw-deleted", "message deleted"));
555
+ const h = o("div", "ocw-bubble");
556
+ let r = null;
557
+ if (e.deletedAt) h.append(o("span", "ocw-deleted", "message deleted"));
2072
558
  else if (e.content.kind === "attachment") {
2073
- const u = e.content;
2074
- if ((x = u.mime) != null && x.startsWith("image/")) {
2075
- const p = document.createElement("img");
2076
- p.src = u.url, p.alt = u.name ?? "image", p.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", p.addEventListener("click", () => window.open(u.url, "_blank")), w.append(p);
559
+ const l = e.content;
560
+ if ((b = l.mime) != null && b.startsWith("image/")) {
561
+ const c = document.createElement("img");
562
+ c.src = l.url, c.alt = l.name ?? "image", c.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", c.addEventListener("click", () => window.open(l.url, "_blank")), h.append(c);
2077
563
  } else {
2078
- const p = document.createElement("a");
2079
- p.href = u.url, p.target = "_blank", p.rel = "noopener", p.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", p.append(c("span", void 0, "📄"), c("span", void 0, u.name ?? "file")), w.append(p);
564
+ const c = document.createElement("a");
565
+ c.href = l.url, c.target = "_blank", c.rel = "noopener", c.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", c.append(o("span", void 0, "📄"), o("span", void 0, l.name ?? "file")), h.append(c);
2080
566
  }
2081
567
  } else if (e.content.kind === "appointment") {
2082
- const u = e.content, p = c("div", "ocw-appt");
2083
- p.append(c("div", "ocw-appt-title", `📅 ${u.title}`)), p.append(c("div", "ocw-appt-time", new Date(u.startIso).toLocaleString() + " – " + new Date(u.endIso).toLocaleTimeString())), u.location && p.append(c("div", "ocw-appt-loc", `📍 ${u.location}`)), u.description && p.append(c("div", "ocw-appt-desc", u.description));
2084
- const I = c("div", "ocw-appt-links"), m = document.createElement("a");
2085
- m.href = u.googleUrl, m.target = "_blank", m.rel = "noopener", m.className = "ocw-appt-btn", m.textContent = "📅 Add to Google Calendar";
2086
- const y = document.createElement("a");
2087
- y.href = u.icalUrl, y.download = `${u.title}.ics`, y.className = "ocw-appt-btn ocw-appt-btn-sec", y.textContent = "🍎 Apple / iCal", I.append(m, y), p.append(I), w.append(p);
568
+ const l = e.content, c = o("div", "ocw-appt");
569
+ c.append(o("div", "ocw-appt-title", `📅 ${l.title}`)), c.append(o("div", "ocw-appt-time", new Date(l.startIso).toLocaleString() + " – " + new Date(l.endIso).toLocaleTimeString())), l.location && c.append(o("div", "ocw-appt-loc", `📍 ${l.location}`)), l.description && c.append(o("div", "ocw-appt-desc", l.description));
570
+ const C = o("div", "ocw-appt-links"), v = document.createElement("a");
571
+ v.href = l.googleUrl, v.target = "_blank", v.rel = "noopener", v.className = "ocw-appt-btn", v.textContent = "📅 Add to Google Calendar";
572
+ const w = document.createElement("a");
573
+ w.href = l.icalUrl, w.download = `${l.title}.ics`, w.className = "ocw-appt-btn ocw-appt-btn-sec", w.textContent = "🍎 Apple / iCal", C.append(v, w), c.append(C), h.append(c);
2088
574
  } else
2089
- d = document.createTextNode(se(e.content)), w.append(d), e.editedAt && w.append(c("span", "ocw-edited", "(edited)"));
2090
- if (h.append(w), !n && !i && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && d) {
2091
- const u = e.content.text;
2092
- if (u.trim()) {
2093
- const p = c("button", "ocw-translate-btn", "🌐");
2094
- p.type = "button", p.title = "Translate", p.addEventListener("click", (I) => {
2095
- if (I.stopPropagation(), this.showingTranslation.has(e.id)) {
2096
- this.showingTranslation.delete(e.id), d.textContent = u, p.textContent = "🌐", p.title = "Translate";
575
+ r = document.createTextNode(_(e.content)), h.append(r), e.editedAt && h.append(o("span", "ocw-edited", "(edited)"));
576
+ if (f.append(h), !s && !p && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && r) {
577
+ const l = e.content.text;
578
+ if (l.trim()) {
579
+ const c = o("button", "ocw-translate-btn", "🌐");
580
+ c.type = "button", c.title = "Translate", c.addEventListener("click", (C) => {
581
+ if (C.stopPropagation(), this.showingTranslation.has(e.id)) {
582
+ this.showingTranslation.delete(e.id), r.textContent = l, c.textContent = "🌐", c.title = "Translate";
2097
583
  return;
2098
584
  }
2099
- const m = this.translationCache.get(e.id);
2100
- if (m !== void 0) {
2101
- this.showingTranslation.add(e.id), d.textContent = m, p.textContent = "↩", p.title = "Show original";
585
+ const v = this.translationCache.get(e.id);
586
+ if (v !== void 0) {
587
+ this.showingTranslation.add(e.id), r.textContent = v, c.textContent = "↩", c.title = "Show original";
2102
588
  return;
2103
589
  }
2104
- p.textContent = "⏳", this.h.onTranslate(u).then((y) => {
2105
- if (y === null) {
2106
- p.textContent = "⚠️", p.title = "Translation unavailable", setTimeout(() => {
2107
- p.textContent = "🌐", p.title = "Translate";
590
+ c.textContent = "⏳", this.h.onTranslate(l).then((w) => {
591
+ if (w === null) {
592
+ c.textContent = "⚠️", c.title = "Translation unavailable", setTimeout(() => {
593
+ c.textContent = "🌐", c.title = "Translate";
2108
594
  }, 1500);
2109
595
  return;
2110
596
  }
2111
- this.translationCache.set(e.id, y), this.showingTranslation.add(e.id), d.textContent = y, p.textContent = "↩", p.title = "Show original";
597
+ this.translationCache.set(e.id, w), this.showingTranslation.add(e.id), r.textContent = w, c.textContent = "↩", c.title = "Show original";
2112
598
  });
2113
- }), h.append(p);
599
+ }), f.append(c);
2114
600
  }
2115
601
  }
2116
- if (n && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
2117
- const u = c("div", "ocw-msg-menu");
602
+ if (s && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
603
+ const l = o("div", "ocw-msg-menu");
2118
604
  if (this.h.onEdit) {
2119
- const p = c("button", void 0, "✏️");
2120
- p.title = "Edit", p.addEventListener("click", (I) => {
2121
- I.stopPropagation();
2122
- const m = se(e.content), y = document.createElement("textarea");
2123
- y.value = m, y.rows = Math.min(4, Math.ceil(m.length / 40) + 1), y.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:#fff;color:#1c1b1a;box-sizing:border-box";
2124
- const U = c("button", "ocw-form-submit", "Save");
2125
- U.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
2126
- const A = c("button", "ocw-form-cancel", "Cancel");
2127
- A.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
2128
- const P = c("div");
2129
- P.style.cssText = "display:flex;gap:6px;justify-content:flex-end", P.append(A, U);
2130
- const K = c("div");
2131
- K.append(y, P), w.replaceChildren(K), y.focus(), y.select();
2132
- const b = () => w.replaceChildren(d ?? document.createTextNode(m));
2133
- A.addEventListener("click", b), U.addEventListener("click", () => {
2134
- const S = y.value.trim();
2135
- S && S !== m && this.h.onEdit(e.id, S), b();
2136
- }), y.addEventListener("keydown", (S) => {
2137
- S.key === "Enter" && !S.shiftKey && (S.preventDefault(), U.click()), S.key === "Escape" && b();
605
+ const c = o("button", void 0, "✏️");
606
+ c.title = "Edit", c.addEventListener("click", (C) => {
607
+ C.stopPropagation();
608
+ const v = _(e.content), w = document.createElement("textarea");
609
+ w.value = v, w.rows = Math.min(4, Math.ceil(v.length / 40) + 1), w.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:#fff;color:#1c1b1a;box-sizing:border-box";
610
+ const z = o("button", "ocw-form-submit", "Save");
611
+ z.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
612
+ const L = o("button", "ocw-form-cancel", "Cancel");
613
+ L.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
614
+ const I = o("div");
615
+ I.style.cssText = "display:flex;gap:6px;justify-content:flex-end", I.append(L, z);
616
+ const A = o("div");
617
+ A.append(w, I), h.replaceChildren(A), w.focus(), w.select();
618
+ const g = () => h.replaceChildren(r ?? document.createTextNode(v));
619
+ L.addEventListener("click", g), z.addEventListener("click", () => {
620
+ const k = w.value.trim();
621
+ k && k !== v && this.h.onEdit(e.id, k), g();
622
+ }), w.addEventListener("keydown", (k) => {
623
+ k.key === "Enter" && !k.shiftKey && (k.preventDefault(), z.click()), k.key === "Escape" && g();
2138
624
  });
2139
- }), u.append(p);
625
+ }), l.append(c);
2140
626
  }
2141
627
  if (this.h.onDelete) {
2142
- const p = c("button", "del", "🗑");
2143
- p.title = "Delete", p.addEventListener("click", (I) => {
2144
- I.stopPropagation(), this.h.onDelete(e.id);
2145
- }), u.append(p);
628
+ const c = o("button", "del", "🗑");
629
+ c.title = "Delete", c.addEventListener("click", (C) => {
630
+ C.stopPropagation(), this.h.onDelete(e.id);
631
+ }), l.append(c);
2146
632
  }
2147
- h.append(u);
633
+ f.append(l);
2148
634
  }
2149
- if (r.append(h), this.h.onReact && !e.deletedAt && e.seq > 0) {
2150
- const u = c("div", "ocw-react-wrap"), p = c("div", "ocw-react");
635
+ if (a.append(f), this.h.onReact && !e.deletedAt && e.seq > 0) {
636
+ const l = o("div", "ocw-react-wrap"), c = o("div", "ocw-react");
2151
637
  if (e.reactions && Object.keys(e.reactions).length)
2152
- for (const [y, U] of Object.entries(e.reactions)) {
2153
- const A = c("button", `ocw-react-pill${U.includes(this.me) ? " mine" : ""}`, `${y} ${U.length}`);
2154
- A.addEventListener("click", () => {
2155
- var P, K;
2156
- return (K = (P = this.h).onReact) == null ? void 0 : K.call(P, e.id, y, U.includes(this.me));
2157
- }), p.append(A);
638
+ for (const [w, z] of Object.entries(e.reactions)) {
639
+ const L = o("button", `ocw-react-pill${z.includes(this.me) ? " mine" : ""}`, `${w} ${z.length}`);
640
+ L.addEventListener("click", () => {
641
+ var I, A;
642
+ return (A = (I = this.h).onReact) == null ? void 0 : A.call(I, e.id, w, z.includes(this.me));
643
+ }), c.append(L);
2158
644
  }
2159
- const I = c("button", "ocw-react-btn", "+"), m = c("div", "ocw-react-picker");
2160
- for (const y of qt) {
2161
- const U = c("button", void 0, y);
2162
- U.addEventListener("click", (A) => {
2163
- var K, b, S, M;
2164
- A.stopPropagation();
2165
- const P = (b = (K = e.reactions) == null ? void 0 : K[y]) == null ? void 0 : b.includes(this.me);
2166
- (M = (S = this.h).onReact) == null || M.call(S, e.id, y, !!P), m.style.display = "none";
2167
- }), m.append(U);
645
+ const C = o("button", "ocw-react-btn", "+"), v = o("div", "ocw-react-picker");
646
+ for (const w of ve) {
647
+ const z = o("button", void 0, w);
648
+ z.addEventListener("click", (L) => {
649
+ var A, g, k, $;
650
+ L.stopPropagation();
651
+ const I = (g = (A = e.reactions) == null ? void 0 : A[w]) == null ? void 0 : g.includes(this.me);
652
+ ($ = (k = this.h).onReact) == null || $.call(k, e.id, w, !!I), v.style.display = "none";
653
+ }), v.append(z);
2168
654
  }
2169
- m.style.display = "none", I.addEventListener("click", (y) => {
2170
- y.stopPropagation(), m.style.display = m.style.display === "none" ? "flex" : "none";
655
+ v.style.display = "none", C.addEventListener("click", (w) => {
656
+ w.stopPropagation(), v.style.display = v.style.display === "none" ? "flex" : "none";
2171
657
  }), document.addEventListener("click", () => {
2172
- m.style.display = "none";
2173
- }, { once: !0 }), p.append(I), u.append(p, m), r.append(u);
2174
- } else e.reactions && Object.keys(e.reactions).length && r.append(c("div", "ocw-react", Object.entries(e.reactions).map(([u, p]) => `${u}${p.length}`).join(" ")));
2175
- const v = c("div", "ocw-time ocw-meta", Vt(e.ts));
2176
- if (n && e.status) {
2177
- const u = c("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Xt(e.status));
2178
- v.append(u);
658
+ v.style.display = "none";
659
+ }, { once: !0 }), c.append(C), l.append(c, v), a.append(l);
660
+ } else e.reactions && Object.keys(e.reactions).length && a.append(o("div", "ocw-react", Object.entries(e.reactions).map(([l, c]) => `${l}${c.length}`).join(" ")));
661
+ const T = o("div", "ocw-time ocw-meta", Ce(e.ts));
662
+ if (s && e.status) {
663
+ const l = o("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Se(e.status));
664
+ T.append(l);
2179
665
  }
2180
- return n && e.seq > 0 && t.lastReadByOthers >= e.seq && v.append(c("span", "ocw-seen", " · Seen")), r.append(v), o.append(r), o;
666
+ return s && e.seq > 0 && n.lastReadByOthers >= e.seq && T.append(o("span", "ocw-seen", " · Seen")), a.append(T), d.append(a), d;
2181
667
  }
2182
668
  }
2183
- function Xt(s) {
2184
- switch (s) {
669
+ function Se(t) {
670
+ switch (t) {
2185
671
  case "read":
2186
672
  return "✓✓";
2187
673
  case "delivered":
@@ -2192,29 +678,29 @@ function Xt(s) {
2192
678
  return "🕓";
2193
679
  }
2194
680
  }
2195
- const H = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new Map();
2196
- function ke(s) {
2197
- return `relay-launcher::${s.profileId}::${s.subjectId ?? ""}`;
681
+ const M = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new Map();
682
+ function ee(t) {
683
+ return `relay-launcher::${t.profileId}::${t.subjectId ?? ""}`;
2198
684
  }
2199
- function Zt(s) {
685
+ function je(t) {
2200
686
  var e;
2201
- (e = H.get(s)) == null || e.close(), H.delete(s);
2202
- }
2203
- function Qt(s) {
2204
- var pe, ue, fe, we, xe;
2205
- H.has(s.el) && (H.get(s.el).close(), H.delete(s.el)), s.launcher && ((pe = Z.get(ke(s))) == null || pe.close());
2206
- const e = $e(), t = s.token ?? s.userId ?? e, n = t !== e ? e : void 0, { wsUrl: i, httpBase: o } = He(s.url, s.apiUrl);
2207
- let r = new Ct(t);
2208
- const h = s.subjectId ? `${t}::${s.subjectId}` : t, w = new At(h);
2209
- let d, v = !1, x = null, u = null;
2210
- !s.launcher && !s.el.style.height && s.el.clientHeight === 0 && (s.el.style.width = s.el.style.width || "100%", s.el.style.height = "600px");
2211
- for (const l of w.load()) r.addOptimistic(l.clientMsgId, l.content);
2212
- let p = null, I = null, m = 0, y = !s.launcher;
2213
- if (s.launcher) {
2214
- const f = (s.position ?? "bottom-right").includes("right");
2215
- p = document.createElement("div"), p.style.cssText = `position:fixed;${f ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${f ? "flex-end" : "flex-start"};gap:12px`;
2216
- const g = document.createElement("div"), E = typeof window < "u" ? window.matchMedia("(max-width: 479px)") : null, X = ($) => {
2217
- g.style.cssText = $ ? [
687
+ (e = M.get(t)) == null || e.close(), M.delete(t);
688
+ }
689
+ function Le(t) {
690
+ var V, Y, X, J, G;
691
+ M.has(t.el) && (M.get(t.el).close(), M.delete(t.el)), t.launcher && ((V = F.get(ee(t))) == null || V.close());
692
+ const e = le(), n = t.token ?? t.userId ?? e, s = n !== e ? e : void 0, { wsUrl: p, httpBase: d } = pe(t.url, t.apiUrl);
693
+ let a = new he(n);
694
+ const f = t.subjectId ? `${n}::${t.subjectId}` : n, h = new fe(f);
695
+ let r, T = !1, b = null, l = null;
696
+ !t.launcher && !t.el.style.height && t.el.clientHeight === 0 && (t.el.style.width = t.el.style.width || "100%", t.el.style.height = "600px");
697
+ for (const i of h.load()) a.addOptimistic(i.clientMsgId, i.content);
698
+ let c = null, C = null, v = 0, w = !t.launcher;
699
+ if (t.launcher) {
700
+ const u = (t.position ?? "bottom-right").includes("right");
701
+ c = document.createElement("div"), c.style.cssText = `position:fixed;${u ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${u ? "flex-end" : "flex-start"};gap:12px`;
702
+ const x = document.createElement("div"), S = typeof window < "u" ? window.matchMedia("(max-width: 479px)") : null, O = (B) => {
703
+ x.style.cssText = B ? [
2218
704
  "position:fixed",
2219
705
  "inset:0",
2220
706
  "width:100%",
@@ -2237,247 +723,248 @@ function Qt(s) {
2237
723
  "display:none",
2238
724
  "flex-direction:column",
2239
725
  "background:#fff",
2240
- "transform-origin:bottom " + (f ? "right" : "left"),
726
+ "transform-origin:bottom " + (u ? "right" : "left"),
2241
727
  "transition:opacity .18s,transform .18s",
2242
728
  "opacity:0",
2243
729
  "transform:scale(.95)"
2244
730
  ].join(";");
2245
731
  };
2246
- X((E == null ? void 0 : E.matches) ?? !1);
2247
- const Y = ($) => X($.matches);
2248
- E == null || E.addEventListener("change", Y), x = E, u = Y, s.el.style.cssText = "width:100%;height:100%;overflow:hidden", g.append(s.el);
2249
- const B = document.createElement("button");
2250
- B.style.cssText = [
732
+ O((S == null ? void 0 : S.matches) ?? !1);
733
+ const N = (B) => O(B.matches);
734
+ S == null || S.addEventListener("change", N), b = S, l = N, t.el.style.cssText = "width:100%;height:100%;overflow:hidden", x.append(t.el);
735
+ const j = document.createElement("button");
736
+ j.style.cssText = [
2251
737
  "width:56px;height:56px;border-radius:50%",
2252
- `background:${s.accent ?? "#4F63F5"}`,
738
+ `background:${t.accent ?? "#4F63F5"}`,
2253
739
  "color:#fff;border:none;font-size:24px;cursor:pointer",
2254
740
  "box-shadow:0 4px 16px rgba(0,0,0,.25)",
2255
741
  "position:relative;flex:none",
2256
742
  "transition:transform .15s"
2257
- ].join(";"), B.textContent = "💬", B.onmouseenter = () => {
2258
- B.style.transform = "scale(1.08)";
2259
- }, B.onmouseleave = () => {
2260
- B.style.transform = "scale(1)";
2261
- }, I = document.createElement("span"), I.style.cssText = "position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center", B.append(I), p.append(g, B), document.body.append(p);
2262
- const J = ($) => {
2263
- $ ? (g.style.display = "flex", requestAnimationFrame(() => {
2264
- g.style.opacity = "1", g.style.transform = "scale(1)";
2265
- })) : (g.style.opacity = "0", g.style.transform = "scale(.95)", setTimeout(() => {
2266
- y || (g.style.display = "none");
743
+ ].join(";"), j.textContent = "💬", j.onmouseenter = () => {
744
+ j.style.transform = "scale(1.08)";
745
+ }, j.onmouseleave = () => {
746
+ j.style.transform = "scale(1)";
747
+ }, C = document.createElement("span"), C.style.cssText = "position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center", j.append(C), c.append(x, j), document.body.append(c);
748
+ const D = (B) => {
749
+ B ? (x.style.display = "flex", requestAnimationFrame(() => {
750
+ x.style.opacity = "1", x.style.transform = "scale(1)";
751
+ })) : (x.style.opacity = "0", x.style.transform = "scale(.95)", setTimeout(() => {
752
+ w || (x.style.display = "none");
2267
753
  }, 180));
2268
754
  };
2269
- B.addEventListener("click", () => {
2270
- y = !y, J(y), B.textContent = y ? "✕" : "💬", B.append(I), y && (m = 0, I && (I.style.display = "none"));
2271
- }), document.addEventListener("keydown", ($) => {
2272
- $.key === "Escape" && y && (y = !1, J(!1), B.textContent = "💬", B.append(I));
755
+ j.addEventListener("click", () => {
756
+ w = !w, D(w), j.textContent = w ? "✕" : "💬", j.append(C), w && (v = 0, C && (C.style.display = "none"));
757
+ }), document.addEventListener("keydown", (B) => {
758
+ B.key === "Escape" && w && (w = !1, D(!1), j.textContent = "💬", j.append(C));
2273
759
  });
2274
760
  }
2275
- const U = () => {
2276
- y || (m++, I && (I.textContent = String(m), I.style.display = "flex"));
2277
- }, A = () => {
761
+ const z = () => {
762
+ w || (v++, C && (C.textContent = String(v), C.style.display = "flex"));
763
+ }, L = () => {
2278
764
  try {
2279
- const l = new AudioContext(), f = l.createOscillator(), g = l.createGain();
2280
- f.connect(g), g.connect(l.destination), f.frequency.setValueAtTime(880, l.currentTime), f.frequency.exponentialRampToValueAtTime(440, l.currentTime + 0.15), g.gain.setValueAtTime(0.3, l.currentTime), g.gain.exponentialRampToValueAtTime(1e-3, l.currentTime + 0.3), f.start(), f.stop(l.currentTime + 0.3);
765
+ const i = new AudioContext(), u = i.createOscillator(), x = i.createGain();
766
+ u.connect(x), x.connect(i.destination), u.frequency.setValueAtTime(880, i.currentTime), u.frequency.exponentialRampToValueAtTime(440, i.currentTime + 0.15), x.gain.setValueAtTime(0.3, i.currentTime), x.gain.exponentialRampToValueAtTime(1e-3, i.currentTime + 0.3), u.start(), u.stop(i.currentTime + 0.3);
2281
767
  } catch {
2282
768
  }
2283
- }, P = [], K = (l) => {
2284
- for (; P.length; ) {
2285
- const f = P.shift();
2286
- w.add({ clientMsgId: f.clientMsgId, content: f.content, ts: Date.now() }), b.send({ type: "send", conversationId: l, clientMsgId: f.clientMsgId, content: f.content });
769
+ }, I = [], A = (i) => {
770
+ for (; I.length; ) {
771
+ const u = I.shift();
772
+ h.add({ clientMsgId: u.clientMsgId, content: u.content, ts: Date.now() }), g.send({ type: "send", conversationId: i, clientMsgId: u.clientMsgId, content: u.content });
2287
773
  }
2288
774
  };
2289
- let b;
2290
- const S = new Ft(`ocw-e2e-${s.profileId}`);
2291
- let M = !1;
2292
- const k = [], T = [];
2293
- let V = !1;
2294
- const ne = (l, f) => {
2295
- S.sealText(f).then((g) => {
2296
- d && b.send({ type: "send", conversationId: d, clientMsgId: l, content: g });
775
+ let g;
776
+ const k = new we(`ocw-e2e-${t.profileId}`);
777
+ let $ = !1;
778
+ const y = [], E = [];
779
+ let R = !1;
780
+ const U = (i, u) => {
781
+ k.sealText(u).then((x) => {
782
+ r && g.send({ type: "send", conversationId: r, clientMsgId: i, content: x });
2297
783
  });
2298
- }, Pe = (l, f, g) => {
2299
- S.sealText(f, g).then((E) => {
2300
- d && b.send({ type: "send", conversationId: d, clientMsgId: l, content: E });
784
+ }, te = (i, u, x) => {
785
+ k.sealText(u, x).then((S) => {
786
+ r && g.send({ type: "send", conversationId: r, clientMsgId: i, content: S });
2301
787
  });
2302
- }, Be = () => {
2303
- for (; k.length; ) {
2304
- const l = k.shift();
2305
- ne(l.clientMsgId, l.text);
2306
- }
2307
- for (; T.length; ) {
2308
- const l = T.shift();
2309
- ne(l.clientMsgId, l.text);
2310
- }
2311
- }, Ae = (l) => {
2312
- b.send({ type: "fetchPrekey", targetUserId: l });
2313
- }, Ke = s.i18n ?? {}, ze = ["ar", "he", "fa", "ur"], Le = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
2314
- ze.includes(Le) && !s.el.dir && (s.el.dir = "rtl", s.el.style.fontFamily = s.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
2315
- const L = new Wt(s.el, t, {
2316
- onSend(l) {
2317
- const f = `cm_${Math.random().toString(36).slice(2)}`, g = { kind: "text", text: l };
2318
- r.addOptimistic(f, g), L.render(r), r.e2e ? S.ready ? ne(f, l) : V ? T.push({ clientMsgId: f, text: l }) : (k.push({ clientMsgId: f, text: l }), r.assignedAgentId && Ae(r.assignedAgentId)) : d ? (w.add({ clientMsgId: f, content: g, ts: Date.now() }), b.send({ type: "send", conversationId: d, clientMsgId: f, content: g })) : P.push({ clientMsgId: f, content: g });
788
+ }, oe = () => {
789
+ for (; y.length; ) {
790
+ const i = y.shift();
791
+ U(i.clientMsgId, i.text);
792
+ }
793
+ for (; E.length; ) {
794
+ const i = E.shift();
795
+ U(i.clientMsgId, i.text);
796
+ }
797
+ }, ne = (i) => {
798
+ g.send({ type: "fetchPrekey", targetUserId: i });
799
+ }, ie = t.i18n ?? {}, se = ["ar", "he", "fa", "ur"], re = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
800
+ se.includes(re) && !t.el.dir && (t.el.dir = "rtl", t.el.style.fontFamily = t.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
801
+ const W = new me(), P = new Te(t.el, n, {
802
+ onSend(i) {
803
+ const u = `cm_${Math.random().toString(36).slice(2)}`, x = { kind: "text", text: i };
804
+ a.addOptimistic(u, x), P.render(a), a.e2e ? k.ready ? U(u, i) : R ? E.push({ clientMsgId: u, text: i }) : (y.push({ clientMsgId: u, text: i }), a.assignedAgentId && ne(a.assignedAgentId)) : r ? (h.add({ clientMsgId: u, content: x, ts: Date.now() }), g.send({ type: "send", conversationId: r, clientMsgId: u, content: x })) : I.push({ clientMsgId: u, content: x });
2319
805
  },
2320
- async onAttach(l) {
2321
- if (!d) return;
2322
- const f = `${o}/upload?name=${encodeURIComponent(l.name)}`, g = `cm_${Math.random().toString(36).slice(2)}`;
2323
- r.addOptimistic(g, { kind: "text", text: `📎 Uploading ${l.name}…` }), L.render(r);
806
+ async onAttach(i) {
807
+ if (!r) return;
808
+ const u = `${d}/upload?name=${encodeURIComponent(i.name)}`, x = `cm_${Math.random().toString(36).slice(2)}`;
809
+ a.addOptimistic(x, { kind: "text", text: `📎 Uploading ${i.name}…` }), P.render(a);
2324
810
  try {
2325
- const E = await fetch(f, {
811
+ const S = await fetch(u, {
2326
812
  method: "POST",
2327
- headers: { "content-type": l.type, ...s.token ? { authorization: `Bearer ${s.token}` } : {} },
2328
- body: l
813
+ headers: { "content-type": i.type, ...t.token ? { authorization: `Bearer ${t.token}` } : {} },
814
+ body: i
2329
815
  });
2330
- if (!E.ok) throw new Error(`Upload failed: ${E.status}`);
2331
- const { url: X, name: Y, mime: B, size: J } = await E.json();
2332
- b.send({ type: "send", conversationId: d, clientMsgId: g, content: { kind: "attachment", url: X, name: Y, mime: B, size: J } });
2333
- } catch (E) {
2334
- r.addOptimistic(g, { kind: "text", text: `⚠️ Upload failed: ${E.message}` }), L.render(r);
816
+ if (!S.ok) throw new Error(`Upload failed: ${S.status}`);
817
+ const { url: O, name: N, mime: j, size: D } = await S.json();
818
+ g.send({ type: "send", conversationId: r, clientMsgId: x, content: { kind: "attachment", url: O, name: N, mime: j, size: D } });
819
+ } catch (S) {
820
+ a.addOptimistic(x, { kind: "text", text: `⚠️ Upload failed: ${S.message}` }), P.render(a);
2335
821
  }
2336
822
  },
2337
- onInvoke(l, f) {
2338
- d && b.send({ type: "invoke", conversationId: d, actionId: l, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...f ? { inputs: f } : {} });
823
+ onInvoke(i, u) {
824
+ r && g.send({ type: "invoke", conversationId: r, actionId: i, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...u ? { inputs: u } : {} });
2339
825
  },
2340
- onTyping(l, f) {
2341
- d && b.send({ type: "typing", conversationId: d, isTyping: l, ...f ? { preview: f } : {} });
826
+ onTyping(i, u) {
827
+ r && g.send({ type: "typing", conversationId: r, isTyping: i, ...u ? { preview: u } : {} });
2342
828
  },
2343
- onReadUpTo(l) {
2344
- d && b.send({ type: "read", conversationId: d, seq: l });
829
+ onReadUpTo(i) {
830
+ r && g.send({ type: "read", conversationId: r, seq: i });
2345
831
  },
2346
832
  onLoadMore() {
2347
- if (!d || !r.e2e) return;
2348
- const l = r.messages()[0];
2349
- l && b.send({ type: "history", conversationId: d, beforeSeq: l.seq, limit: 20 });
833
+ if (!r || !a.e2e) return;
834
+ const i = a.messages()[0];
835
+ i && g.send({ type: "history", conversationId: r, beforeSeq: i.seq, limit: 20 });
2350
836
  },
2351
- onEdit(l, f) {
2352
- d && b.send({ type: "edit", conversationId: d, messageId: l, content: { kind: "text", text: f } });
837
+ onEdit(i, u) {
838
+ r && g.send({ type: "edit", conversationId: r, messageId: i, content: { kind: "text", text: u } });
2353
839
  },
2354
- onDelete(l) {
2355
- d && b.send({ type: "delete", conversationId: d, messageId: l });
840
+ onDelete(i) {
841
+ r && g.send({ type: "delete", conversationId: r, messageId: i });
2356
842
  },
2357
- onReact(l, f, g) {
2358
- d && b.send({ type: "react", conversationId: d, messageId: l, emoji: f, remove: g });
843
+ onReact(i, u, x) {
844
+ r && g.send({ type: "react", conversationId: r, messageId: i, emoji: u, remove: x });
2359
845
  },
2360
- onCsat(l) {
2361
- d && fetch(`${o}/conversations/${d}/csat`, {
846
+ onCsat(i) {
847
+ r && fetch(`${d}/conversations/${r}/csat`, {
2362
848
  method: "POST",
2363
- headers: { "Content-Type": "application/json", Authorization: `Bearer ${t}` },
2364
- body: JSON.stringify({ score: l })
849
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${n}` },
850
+ body: JSON.stringify({ score: i })
2365
851
  }).catch(() => {
2366
852
  });
2367
853
  },
2368
- onAnnotate(l) {
2369
- d && b.send({ type: "annotate", conversationId: d, stroke: l });
854
+ onAnnotate(i) {
855
+ r && g.send({ type: "annotate", conversationId: r, stroke: i });
2370
856
  },
2371
857
  onAnnotateClear() {
2372
- d && b.send({ type: "annotate_clear", conversationId: d });
858
+ r && g.send({ type: "annotate_clear", conversationId: r });
2373
859
  },
2374
- ...s.translateLang ? {
2375
- async onTranslate(l) {
860
+ ...t.translateLang ? {
861
+ async onTranslate(i) {
2376
862
  try {
2377
- const f = await fetch(`${o}/translate`, {
863
+ const u = await fetch(`${d}/translate`, {
2378
864
  method: "POST",
2379
- headers: { "content-type": "application/json", authorization: `Bearer ${t}` },
2380
- body: JSON.stringify({ text: l, targetLang: s.translateLang })
865
+ headers: { "content-type": "application/json", authorization: `Bearer ${n}` },
866
+ body: JSON.stringify({ text: i, targetLang: t.translateLang })
2381
867
  });
2382
- if (!f.ok) return null;
2383
- const { translated: g } = await f.json();
2384
- return g;
868
+ if (!u.ok) return null;
869
+ const { translated: x } = await u.json();
870
+ return x;
2385
871
  } catch {
2386
872
  return null;
2387
873
  }
2388
874
  }
2389
875
  } : {}
2390
876
  }, {
2391
- ...s.subject ? { subject: s.subject } : {},
2392
- ...s.quickReplies ? { quickReplies: s.quickReplies } : {},
2393
- ...s.accent ? { accent: s.accent } : {},
2394
- ...(ue = s.user) != null && ue.name || (fe = s.user) != null && fe.avatar ? { userInfo: { ...s.user.name ? { name: s.user.name } : {}, ...s.user.avatar ? { avatar: s.user.avatar } : {} } } : {},
2395
- i18n: Ke
2396
- }), he = s.user && (s.user.name || s.user.email || s.user.avatar || s.user.meta) ? {
2397
- ...s.user.name ? { name: s.user.name } : {},
2398
- ...s.user.email ? { email: s.user.email } : {},
2399
- ...s.user.avatar ? { avatar: s.user.avatar } : {},
2400
- ...s.user.meta ? { meta: s.user.meta } : {}
2401
- } : void 0, Me = {
877
+ ...t.subject ? { subject: t.subject } : {},
878
+ ...t.quickReplies ? { quickReplies: t.quickReplies } : {},
879
+ ...t.accent ? { accent: t.accent } : {},
880
+ ...(Y = t.user) != null && Y.name || (X = t.user) != null && X.avatar ? { userInfo: { ...t.user.name ? { name: t.user.name } : {}, ...t.user.avatar ? { avatar: t.user.avatar } : {} } } : {},
881
+ i18n: ie
882
+ }), K = t.user && (t.user.name || t.user.email || t.user.avatar || t.user.meta) ? {
883
+ ...t.user.name ? { name: t.user.name } : {},
884
+ ...t.user.email ? { email: t.user.email } : {},
885
+ ...t.user.avatar ? { avatar: t.user.avatar } : {},
886
+ ...t.user.meta ? { meta: t.user.meta } : {}
887
+ } : void 0, ae = {
2402
888
  type: "open",
2403
- profileId: s.profileId,
2404
- ...s.subjectId ? { subjectId: s.subjectId } : {},
2405
- ...n ? { linkFrom: n } : {},
2406
- ...he ? { userInfo: he } : {},
889
+ profileId: t.profileId,
890
+ ...t.subjectId ? { subjectId: t.subjectId } : {},
891
+ ...s ? { linkFrom: s } : {},
892
+ ...K ? { userInfo: K } : {},
2407
893
  ...typeof location < "u" ? { pageUrl: location.href } : {},
2408
894
  ...typeof document < "u" && document.title ? { pageTitle: document.title } : {},
2409
895
  // Pass subject display info so the server can persist it to the Subject record.
2410
896
  // This is how listingTitle and listingMeta get saved without a separate API call.
2411
- ...(we = s.subject) != null && we.title ? { subjectTitle: s.subject.title } : {},
2412
- ...(xe = s.subject) != null && xe.subtitle ? { subjectMeta: s.subject.subtitle } : {}
897
+ ...(J = t.subject) != null && J.title ? { subjectTitle: t.subject.title } : {},
898
+ ...(G = t.subject) != null && G.subtitle ? { subjectMeta: t.subject.subtitle } : {}
2413
899
  };
2414
- b = new Et({
2415
- url: i,
2416
- token: t,
2417
- open: Me,
2418
- getCursor: () => r.highestSeq(),
2419
- onStatusChange: (l, f) => L.setConnStatus(l, f),
2420
- onFrame(l) {
2421
- if (l.type === "opened") {
2422
- if (d = l.conversation.id, !v) {
2423
- v = !0;
2424
- for (const f of w.load())
2425
- b.send({ type: "send", conversationId: d, clientMsgId: f.clientMsgId, content: f.content });
900
+ g = new be({
901
+ ...t.refreshToken ? { refreshToken: t.refreshToken } : {},
902
+ url: p,
903
+ token: n,
904
+ open: ae,
905
+ getCursor: () => a.highestSeq(),
906
+ onStatusChange: (i, u) => P.setConnStatus(i, u),
907
+ onFrame(i) {
908
+ if (W.apply(i), i.type === "opened") {
909
+ if (r = i.conversation.id, !T) {
910
+ T = !0;
911
+ for (const u of h.load())
912
+ g.send({ type: "send", conversationId: r, clientMsgId: u.clientMsgId, content: u.content });
2426
913
  }
2427
- Re(i, t, d, r, L, o), P.length && K(d);
914
+ ue(p, n, r, a, P, d), I.length && A(r);
2428
915
  }
2429
- if (l.type === "ack" && w.remove(l.clientMsgId), l.type === "prekeyBundle") {
2430
- l.bundle && (V = !0, S.x3dhSendTo(l.bundle).then((f) => {
2431
- const g = [...k.splice(0), ...T.splice(0)];
2432
- for (const E of g) Pe(E.clientMsgId, E.text, f);
2433
- L.render(r);
916
+ if (i.type === "ack" && h.remove(i.clientMsgId), i.type === "prekeyBundle") {
917
+ i.bundle && (R = !0, k.x3dhSendTo(i.bundle).then((u) => {
918
+ const x = [...y.splice(0), ...E.splice(0)];
919
+ for (const S of x) te(S.clientMsgId, S.text, u);
920
+ P.render(a);
2434
921
  }));
2435
922
  return;
2436
923
  }
2437
- if (l.type === "message" && r.e2e) {
2438
- const f = jt(l.message.content);
2439
- if (f && !S.ready) {
2440
- S.x3dhReceiveFrom(f.x3dhIK, f.x3dhEK, f.x3dhSPK).then(async () => {
2441
- await S.openFrame(l), r.apply(l), L.render(r);
924
+ if (i.type === "message" && a.e2e) {
925
+ const u = xe(i.message.content);
926
+ if (u && !k.ready) {
927
+ k.x3dhReceiveFrom(u.x3dhIK, u.x3dhEK, u.x3dhSPK).then(async () => {
928
+ await k.openFrame(i), a.apply(i), P.render(a);
2442
929
  });
2443
930
  return;
2444
931
  }
2445
932
  }
2446
- if (l.type === "peerkey") {
2447
- S.onPeerKey(l.key).then(() => {
2448
- Be(), L.render(r);
933
+ if (i.type === "peerkey") {
934
+ k.onPeerKey(i.key).then(() => {
935
+ oe(), P.render(a);
2449
936
  });
2450
937
  return;
2451
938
  }
2452
939
  (async () => {
2453
- if (r.e2e && await S.openFrame(l), r.apply(l), l.type === "message" && l.message.senderId !== t && !l.message.internal && (U(), A()), r.e2e && d && !M) {
2454
- M = !0;
2455
- const f = await S.initX3DH();
2456
- b.send({ type: "uploadPrekeys", ...f });
2457
- const g = await S.begin();
2458
- b.send({ type: "pubkey", conversationId: d, key: g });
940
+ if (a.e2e && await k.openFrame(i), a.apply(i), i.type === "message" && i.message.senderId !== n && !i.message.internal && (z(), L()), a.e2e && r && !$) {
941
+ $ = !0;
942
+ const u = await k.initX3DH();
943
+ g.send({ type: "uploadPrekeys", ...u });
944
+ const x = await k.begin();
945
+ g.send({ type: "pubkey", conversationId: r, key: x });
2459
946
  }
2460
- L.render(r);
947
+ P.render(a);
2461
948
  })();
2462
949
  }
2463
- }), b.connect(), L.render(r);
2464
- const F = s.launcher ? ke(s) : null, W = { close: () => {
2465
- b.close(), p == null || p.remove(), L.destroy(), x && u && x.removeEventListener("change", u), H.delete(s.el), F && Z.get(F) === W && Z.delete(F);
950
+ }), g.connect(), P.render(a);
951
+ const q = t.launcher ? ee(t) : null, H = { close: () => {
952
+ g.close(), c == null || c.remove(), P.destroy(), W.destroy(), b && l && b.removeEventListener("change", l), M.delete(t.el), q && F.get(q) === H && F.delete(q);
2466
953
  } };
2467
- return H.set(s.el, W), F && Z.set(F, W), W;
954
+ return M.set(t.el, H), q && F.set(q, H), H;
2468
955
  }
2469
956
  export {
2470
- Ct as ChatStore,
2471
- Et as ConnectionManager,
2472
- Ft as E2ESession,
2473
- At as PersistentOutbox,
2474
- Wt as Renderer,
2475
- Gt as asConversationId,
2476
- jt as extractX3DHInit,
2477
- nn as httpBaseFromWsUrl,
2478
- Qt as mount,
2479
- He as resolveRelayUrls,
2480
- Re as restoreHistory,
2481
- Zt as unmount
957
+ he as ChatStore,
958
+ be as ConnectionManager,
959
+ we as E2ESession,
960
+ fe as PersistentOutbox,
961
+ Te as Renderer,
962
+ Me as asConversationId,
963
+ xe as extractX3DHInit,
964
+ $e as httpBaseFromWsUrl,
965
+ Le as mount,
966
+ pe as resolveRelayUrls,
967
+ ue as restoreHistory,
968
+ je as unmount
2482
969
  };
2483
970
  //# sourceMappingURL=index.js.map