@paramms/chat-widget 1.0.10 → 1.0.12

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,22 +1,22 @@
1
- var Ee = Object.defineProperty;
2
- var Te = (s, e, t) => e in s ? Ee(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var r = (s, e, t) => Te(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { p as Ue, r as Pe, h as Be } from "./uid.js";
5
- const Ht = (s) => s;
6
- function Ke(s) {
1
+ var Te = Object.defineProperty;
2
+ var Ue = (s, e, t) => e in s ? Te(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var r = (s, e, t) => Ue(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { p as Pe, r as Be, h as Ke } from "./uid.js";
5
+ const Rt = (s) => s;
6
+ function Ae(s) {
7
7
  const e = s.length;
8
- let t = 0, i = 0;
9
- for (; i < e; ) {
10
- let n = s.charCodeAt(i++);
11
- if (n & 4294967168)
12
- if (!(n & 4294965248))
8
+ let t = 0, n = 0;
9
+ for (; n < e; ) {
10
+ let i = s.charCodeAt(n++);
11
+ if (i & 4294967168)
12
+ if (!(i & 4294965248))
13
13
  t += 2;
14
14
  else {
15
- if (n >= 55296 && n <= 56319 && i < e) {
16
- const o = s.charCodeAt(i);
17
- (o & 64512) === 56320 && (++i, n = ((n & 1023) << 10) + (o & 1023) + 65536);
15
+ if (i >= 55296 && i <= 56319 && n < e) {
16
+ const o = s.charCodeAt(n);
17
+ (o & 64512) === 56320 && (++n, i = ((i & 1023) << 10) + (o & 1023) + 65536);
18
18
  }
19
- n & 4294901760 ? t += 4 : t += 3;
19
+ i & 4294901760 ? t += 4 : t += 3;
20
20
  }
21
21
  else {
22
22
  t++;
@@ -25,69 +25,69 @@ function Ke(s) {
25
25
  }
26
26
  return t;
27
27
  }
28
- function Ae(s, e, t) {
29
- const i = s.length;
30
- let n = t, o = 0;
31
- for (; o < i; ) {
28
+ function ze(s, e, t) {
29
+ const n = s.length;
30
+ let i = t, o = 0;
31
+ for (; o < n; ) {
32
32
  let c = s.charCodeAt(o++);
33
33
  if (c & 4294967168)
34
34
  if (!(c & 4294965248))
35
- e[n++] = c >> 6 & 31 | 192;
35
+ e[i++] = c >> 6 & 31 | 192;
36
36
  else {
37
- if (c >= 55296 && c <= 56319 && o < i) {
37
+ if (c >= 55296 && c <= 56319 && o < n) {
38
38
  const l = s.charCodeAt(o);
39
39
  (l & 64512) === 56320 && (++o, c = ((c & 1023) << 10) + (l & 1023) + 65536);
40
40
  }
41
- c & 4294901760 ? (e[n++] = c >> 18 & 7 | 240, e[n++] = c >> 12 & 63 | 128, e[n++] = c >> 6 & 63 | 128) : (e[n++] = c >> 12 & 15 | 224, e[n++] = c >> 6 & 63 | 128);
41
+ c & 4294901760 ? (e[i++] = c >> 18 & 7 | 240, e[i++] = c >> 12 & 63 | 128, e[i++] = c >> 6 & 63 | 128) : (e[i++] = c >> 12 & 15 | 224, e[i++] = c >> 6 & 63 | 128);
42
42
  }
43
43
  else {
44
- e[n++] = c;
44
+ e[i++] = c;
45
45
  continue;
46
46
  }
47
- e[n++] = c & 63 | 128;
47
+ e[i++] = c & 63 | 128;
48
48
  }
49
49
  }
50
- const ze = new TextEncoder(), Le = 50;
51
- function Me(s, e, t) {
52
- ze.encodeInto(s, e.subarray(t));
53
- }
50
+ const Le = new TextEncoder(), Me = 50;
54
51
  function De(s, e, t) {
55
- s.length > Le ? Me(s, e, t) : Ae(s, e, t);
52
+ Le.encodeInto(s, e.subarray(t));
53
+ }
54
+ function _e(s, e, t) {
55
+ s.length > Me ? De(s, e, t) : ze(s, e, t);
56
56
  }
57
57
  const $e = 4096;
58
- function fe(s, e, t) {
59
- let i = e;
60
- const n = i + t, o = [];
58
+ function xe(s, e, t) {
59
+ let n = e;
60
+ const i = n + t, o = [];
61
61
  let c = "";
62
- for (; i < n; ) {
63
- const l = s[i++];
62
+ for (; n < i; ) {
63
+ const l = s[n++];
64
64
  if (!(l & 128))
65
65
  o.push(l);
66
66
  else if ((l & 224) === 192) {
67
- const x = s[i++] & 63;
68
- o.push((l & 31) << 6 | x);
67
+ const w = s[n++] & 63;
68
+ o.push((l & 31) << 6 | w);
69
69
  } else if ((l & 240) === 224) {
70
- const x = s[i++] & 63, y = s[i++] & 63;
71
- o.push((l & 31) << 12 | x << 6 | y);
70
+ const w = s[n++] & 63, f = s[n++] & 63;
71
+ o.push((l & 31) << 12 | w << 6 | f);
72
72
  } else if ((l & 248) === 240) {
73
- const x = s[i++] & 63, y = s[i++] & 63, b = s[i++] & 63;
74
- let f = (l & 7) << 18 | x << 12 | y << 6 | b;
75
- f > 65535 && (f -= 65536, o.push(f >>> 10 & 1023 | 55296), f = 56320 | f & 1023), o.push(f);
73
+ const w = s[n++] & 63, f = s[n++] & 63, m = s[n++] & 63;
74
+ let x = (l & 7) << 18 | w << 12 | f << 6 | m;
75
+ x > 65535 && (x -= 65536, o.push(x >>> 10 & 1023 | 55296), x = 56320 | x & 1023), o.push(x);
76
76
  } else
77
77
  o.push(l);
78
78
  o.length >= $e && (c += String.fromCharCode(...o), o.length = 0);
79
79
  }
80
80
  return o.length > 0 && (c += String.fromCharCode(...o)), c;
81
81
  }
82
- const _e = new TextDecoder(), He = 200;
83
- function Re(s, e, t) {
84
- const i = s.subarray(e, e + t);
85
- return _e.decode(i);
86
- }
82
+ const He = new TextDecoder(), Re = 200;
87
83
  function Fe(s, e, t) {
88
- return t > He ? Re(s, e, t) : fe(s, e, t);
84
+ const n = s.subarray(e, e + t);
85
+ return He.decode(n);
89
86
  }
90
- class V {
87
+ function je(s, e, t) {
88
+ return t > Re ? Fe(s, e, t) : xe(s, e, t);
89
+ }
90
+ class W {
91
91
  constructor(e, t) {
92
92
  r(this, "type");
93
93
  r(this, "data");
@@ -105,78 +105,78 @@ class z extends Error {
105
105
  });
106
106
  }
107
107
  }
108
- const F = 4294967295;
109
- function je(s, e, t) {
110
- const i = t / 4294967296, n = t;
111
- s.setUint32(e, i), s.setUint32(e + 4, n);
108
+ const j = 4294967295;
109
+ function qe(s, e, t) {
110
+ const n = t / 4294967296, i = t;
111
+ s.setUint32(e, n), s.setUint32(e + 4, i);
112
112
  }
113
- function we(s, e, t) {
114
- const i = Math.floor(t / 4294967296), n = t;
115
- s.setUint32(e, i), s.setUint32(e + 4, n);
113
+ function ye(s, e, t) {
114
+ const n = Math.floor(t / 4294967296), i = t;
115
+ s.setUint32(e, n), s.setUint32(e + 4, i);
116
116
  }
117
- function xe(s, e) {
118
- const t = s.getInt32(e), i = s.getUint32(e + 4);
119
- return t * 4294967296 + i;
117
+ function ge(s, e) {
118
+ const t = s.getInt32(e), n = s.getUint32(e + 4);
119
+ return t * 4294967296 + n;
120
120
  }
121
- function qe(s, e) {
122
- const t = s.getUint32(e), i = s.getUint32(e + 4);
123
- return t * 4294967296 + i;
121
+ function Oe(s, e) {
122
+ const t = s.getUint32(e), n = s.getUint32(e + 4);
123
+ return t * 4294967296 + n;
124
124
  }
125
- const Oe = -1, Ne = 4294967296 - 1, Ve = 17179869184 - 1;
126
- function We({ sec: s, nsec: e }) {
127
- if (s >= 0 && e >= 0 && s <= Ve)
128
- if (e === 0 && s <= Ne) {
125
+ const Ne = -1, Ve = 4294967296 - 1, We = 17179869184 - 1;
126
+ function Xe({ sec: s, nsec: e }) {
127
+ if (s >= 0 && e >= 0 && s <= We)
128
+ if (e === 0 && s <= Ve) {
129
129
  const t = new Uint8Array(4);
130
130
  return new DataView(t.buffer).setUint32(0, s), t;
131
131
  } else {
132
- const t = s / 4294967296, i = s & 4294967295, n = new Uint8Array(8), o = new DataView(n.buffer);
133
- return o.setUint32(0, e << 2 | t & 3), o.setUint32(4, i), n;
132
+ const t = s / 4294967296, n = s & 4294967295, i = new Uint8Array(8), o = new DataView(i.buffer);
133
+ return o.setUint32(0, e << 2 | t & 3), o.setUint32(4, n), i;
134
134
  }
135
135
  else {
136
- const t = new Uint8Array(12), i = new DataView(t.buffer);
137
- return i.setUint32(0, e), we(i, 4, s), t;
136
+ const t = new Uint8Array(12), n = new DataView(t.buffer);
137
+ return n.setUint32(0, e), ye(n, 4, s), t;
138
138
  }
139
139
  }
140
- function Xe(s) {
141
- const e = s.getTime(), t = Math.floor(e / 1e3), i = (e - t * 1e3) * 1e6, n = Math.floor(i / 1e9);
140
+ function Ye(s) {
141
+ const e = s.getTime(), t = Math.floor(e / 1e3), n = (e - t * 1e3) * 1e6, i = Math.floor(n / 1e9);
142
142
  return {
143
- sec: t + n,
144
- nsec: i - n * 1e9
143
+ sec: t + i,
144
+ nsec: n - i * 1e9
145
145
  };
146
146
  }
147
- function Ye(s) {
147
+ function Je(s) {
148
148
  if (s instanceof Date) {
149
- const e = Xe(s);
150
- return We(e);
149
+ const e = Ye(s);
150
+ return Xe(e);
151
151
  } else
152
152
  return null;
153
153
  }
154
- function Je(s) {
154
+ function Ge(s) {
155
155
  const e = new DataView(s.buffer, s.byteOffset, s.byteLength);
156
156
  switch (s.byteLength) {
157
157
  case 4:
158
158
  return { sec: e.getUint32(0), nsec: 0 };
159
159
  case 8: {
160
- const t = e.getUint32(0), i = e.getUint32(4), n = (t & 3) * 4294967296 + i, o = t >>> 2;
161
- return { sec: n, nsec: o };
160
+ const t = e.getUint32(0), n = e.getUint32(4), i = (t & 3) * 4294967296 + n, o = t >>> 2;
161
+ return { sec: i, nsec: o };
162
162
  }
163
163
  case 12: {
164
- const t = xe(e, 4), i = e.getUint32(0);
165
- return { sec: t, nsec: i };
164
+ const t = ge(e, 4), n = e.getUint32(0);
165
+ return { sec: t, nsec: n };
166
166
  }
167
167
  default:
168
168
  throw new z(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${s.length}`);
169
169
  }
170
170
  }
171
- function Ge(s) {
172
- const e = Je(s);
171
+ function Ze(s) {
172
+ const e = Ge(s);
173
173
  return new Date(e.sec * 1e3 + e.nsec / 1e6);
174
174
  }
175
- const Ze = {
176
- type: Oe,
177
- encode: Ye,
178
- decode: Ge
179
- }, Y = class Y {
175
+ const Qe = {
176
+ type: Ne,
177
+ encode: Je,
178
+ decode: Ze
179
+ }, J = class J {
180
180
  constructor() {
181
181
  // ensures ExtensionCodecType<X> matches ExtensionCodec<X>
182
182
  // this will make type errors a lot more clear
@@ -188,53 +188,53 @@ const Ze = {
188
188
  // custom extensions
189
189
  r(this, "encoders", []);
190
190
  r(this, "decoders", []);
191
- this.register(Ze);
191
+ this.register(Qe);
192
192
  }
193
- register({ type: e, encode: t, decode: i }) {
193
+ register({ type: e, encode: t, decode: n }) {
194
194
  if (e >= 0)
195
- this.encoders[e] = t, this.decoders[e] = i;
195
+ this.encoders[e] = t, this.decoders[e] = n;
196
196
  else {
197
- const n = -1 - e;
198
- this.builtInEncoders[n] = t, this.builtInDecoders[n] = i;
197
+ const i = -1 - e;
198
+ this.builtInEncoders[i] = t, this.builtInDecoders[i] = n;
199
199
  }
200
200
  }
201
201
  tryToEncode(e, t) {
202
- for (let i = 0; i < this.builtInEncoders.length; i++) {
203
- const n = this.builtInEncoders[i];
204
- if (n != null) {
205
- const o = n(e, t);
202
+ for (let n = 0; n < this.builtInEncoders.length; n++) {
203
+ const i = this.builtInEncoders[n];
204
+ if (i != null) {
205
+ const o = i(e, t);
206
206
  if (o != null) {
207
- const c = -1 - i;
208
- return new V(c, o);
207
+ const c = -1 - n;
208
+ return new W(c, o);
209
209
  }
210
210
  }
211
211
  }
212
- for (let i = 0; i < this.encoders.length; i++) {
213
- const n = this.encoders[i];
214
- if (n != null) {
215
- const o = n(e, t);
212
+ for (let n = 0; n < this.encoders.length; n++) {
213
+ const i = this.encoders[n];
214
+ if (i != null) {
215
+ const o = i(e, t);
216
216
  if (o != null) {
217
- const c = i;
218
- return new V(c, o);
217
+ const c = n;
218
+ return new W(c, o);
219
219
  }
220
220
  }
221
221
  }
222
- return e instanceof V ? e : null;
222
+ return e instanceof W ? e : null;
223
223
  }
224
- decode(e, t, i) {
225
- const n = t < 0 ? this.builtInDecoders[-1 - t] : this.decoders[t];
226
- return n ? n(e, t, i) : new V(t, e);
224
+ decode(e, t, n) {
225
+ const i = t < 0 ? this.builtInDecoders[-1 - t] : this.decoders[t];
226
+ return i ? i(e, t, n) : new W(t, e);
227
227
  }
228
228
  };
229
- r(Y, "defaultCodec", new Y());
230
- let W = Y;
231
- function Qe(s) {
229
+ r(J, "defaultCodec", new J());
230
+ let X = J;
231
+ function et(s) {
232
232
  return s instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && s instanceof SharedArrayBuffer;
233
233
  }
234
- function Q(s) {
235
- return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) : Qe(s) ? new Uint8Array(s) : Uint8Array.from(s);
234
+ function ee(s) {
235
+ return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) : et(s) ? new Uint8Array(s) : Uint8Array.from(s);
236
236
  }
237
- const et = 100, tt = 2048;
237
+ const tt = 100, nt = 2048;
238
238
  class ie {
239
239
  constructor(e) {
240
240
  r(this, "extensionCodec");
@@ -250,7 +250,7 @@ class ie {
250
250
  r(this, "view");
251
251
  r(this, "bytes");
252
252
  r(this, "entered", !1);
253
- this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? W.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) ?? et, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? tt, 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);
253
+ this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? X.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) ?? tt, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? nt, 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);
254
254
  }
255
255
  clone() {
256
256
  return new ie({
@@ -304,8 +304,8 @@ class ie {
304
304
  this.view.byteLength < t && this.resizeBuffer(t * 2);
305
305
  }
306
306
  resizeBuffer(e) {
307
- const t = new ArrayBuffer(e), i = new Uint8Array(t), n = new DataView(t);
308
- i.set(this.bytes), this.view = n, this.bytes = i;
307
+ const t = new ArrayBuffer(e), n = new Uint8Array(t), i = new DataView(t);
308
+ n.set(this.bytes), this.view = i, this.bytes = n;
309
309
  }
310
310
  encodeNil() {
311
311
  this.writeU8(192);
@@ -335,13 +335,13 @@ class ie {
335
335
  throw new Error(`Too long string: ${e} bytes in UTF-8`);
336
336
  }
337
337
  encodeString(e) {
338
- const i = Ke(e);
339
- this.ensureBufferSizeToWrite(5 + i), this.writeStringHeader(i), De(e, this.bytes, this.pos), this.pos += i;
338
+ const n = Ae(e);
339
+ this.ensureBufferSizeToWrite(5 + n), this.writeStringHeader(n), _e(e, this.bytes, this.pos), this.pos += n;
340
340
  }
341
341
  encodeObject(e, t) {
342
- const i = this.extensionCodec.tryToEncode(e, this.context);
343
- if (i != null)
344
- this.encodeExtension(i);
342
+ const n = this.extensionCodec.tryToEncode(e, this.context);
343
+ if (n != null)
344
+ this.encodeExtension(n);
345
345
  else if (Array.isArray(e))
346
346
  this.encodeArray(e, t);
347
347
  else if (ArrayBuffer.isView(e))
@@ -361,51 +361,51 @@ class ie {
361
361
  this.writeU8(198), this.writeU32(t);
362
362
  else
363
363
  throw new Error(`Too large binary: ${t}`);
364
- const i = Q(e);
365
- this.writeU8a(i);
364
+ const n = ee(e);
365
+ this.writeU8a(n);
366
366
  }
367
367
  encodeArray(e, t) {
368
- const i = e.length;
369
- if (i < 16)
370
- this.writeU8(144 + i);
371
- else if (i < 65536)
372
- this.writeU8(220), this.writeU16(i);
373
- else if (i < 4294967296)
374
- this.writeU8(221), this.writeU32(i);
368
+ const n = e.length;
369
+ if (n < 16)
370
+ this.writeU8(144 + n);
371
+ else if (n < 65536)
372
+ this.writeU8(220), this.writeU16(n);
373
+ else if (n < 4294967296)
374
+ this.writeU8(221), this.writeU32(n);
375
375
  else
376
- throw new Error(`Too large array: ${i}`);
377
- for (const n of e)
378
- this.doEncode(n, t + 1);
376
+ throw new Error(`Too large array: ${n}`);
377
+ for (const i of e)
378
+ this.doEncode(i, t + 1);
379
379
  }
380
380
  countWithoutUndefined(e, t) {
381
- let i = 0;
382
- for (const n of t)
383
- e[n] !== void 0 && i++;
384
- return i;
381
+ let n = 0;
382
+ for (const i of t)
383
+ e[i] !== void 0 && n++;
384
+ return n;
385
385
  }
386
386
  encodeMap(e, t) {
387
- const i = Object.keys(e);
388
- this.sortKeys && i.sort();
389
- const n = this.ignoreUndefined ? this.countWithoutUndefined(e, i) : i.length;
390
- if (n < 16)
391
- this.writeU8(128 + n);
392
- else if (n < 65536)
393
- this.writeU8(222), this.writeU16(n);
394
- else if (n < 4294967296)
395
- this.writeU8(223), this.writeU32(n);
387
+ const n = Object.keys(e);
388
+ this.sortKeys && n.sort();
389
+ const i = this.ignoreUndefined ? this.countWithoutUndefined(e, n) : n.length;
390
+ if (i < 16)
391
+ this.writeU8(128 + i);
392
+ else if (i < 65536)
393
+ this.writeU8(222), this.writeU16(i);
394
+ else if (i < 4294967296)
395
+ this.writeU8(223), this.writeU32(i);
396
396
  else
397
- throw new Error(`Too large map object: ${n}`);
398
- for (const o of i) {
397
+ throw new Error(`Too large map object: ${i}`);
398
+ for (const o of n) {
399
399
  const c = e[o];
400
400
  this.ignoreUndefined && c === void 0 || (this.encodeString(o), this.doEncode(c, t + 1));
401
401
  }
402
402
  }
403
403
  encodeExtension(e) {
404
404
  if (typeof e.data == "function") {
405
- const i = e.data(this.pos + 6), n = i.length;
406
- if (n >= 4294967296)
407
- throw new Error(`Too large extension object: ${n}`);
408
- this.writeU8(201), this.writeU32(n), this.writeI8(e.type), this.writeU8a(i);
405
+ const n = e.data(this.pos + 6), i = n.length;
406
+ if (i >= 4294967296)
407
+ throw new Error(`Too large extension object: ${i}`);
408
+ this.writeU8(201), this.writeU32(i), this.writeI8(e.type), this.writeU8a(n);
409
409
  return;
410
410
  }
411
411
  const t = e.data.length;
@@ -458,10 +458,10 @@ class ie {
458
458
  this.ensureBufferSizeToWrite(8), this.view.setFloat64(this.pos, e), this.pos += 8;
459
459
  }
460
460
  writeU64(e) {
461
- this.ensureBufferSizeToWrite(8), je(this.view, this.pos, e), this.pos += 8;
461
+ this.ensureBufferSizeToWrite(8), qe(this.view, this.pos, e), this.pos += 8;
462
462
  }
463
463
  writeI64(e) {
464
- this.ensureBufferSizeToWrite(8), we(this.view, this.pos, e), this.pos += 8;
464
+ this.ensureBufferSizeToWrite(8), ye(this.view, this.pos, e), this.pos += 8;
465
465
  }
466
466
  writeBigUint64(e) {
467
467
  this.ensureBufferSizeToWrite(8), this.view.setBigUint64(this.pos, e), this.pos += 8;
@@ -473,29 +473,29 @@ class ie {
473
473
  function it(s, e) {
474
474
  return new ie(e).encodeSharedRef(s);
475
475
  }
476
- function G(s) {
476
+ function Z(s) {
477
477
  return `${s < 0 ? "-" : ""}0x${Math.abs(s).toString(16).padStart(2, "0")}`;
478
478
  }
479
- const nt = 16, st = 16;
480
- class ot {
481
- constructor(e = nt, t = st) {
479
+ const st = 16, ot = 16;
480
+ class rt {
481
+ constructor(e = st, t = ot) {
482
482
  r(this, "hit", 0);
483
483
  r(this, "miss", 0);
484
484
  r(this, "caches");
485
485
  r(this, "maxKeyLength");
486
486
  r(this, "maxLengthPerKey");
487
487
  this.maxKeyLength = e, this.maxLengthPerKey = t, this.caches = [];
488
- for (let i = 0; i < this.maxKeyLength; i++)
488
+ for (let n = 0; n < this.maxKeyLength; n++)
489
489
  this.caches.push([]);
490
490
  }
491
491
  canBeCached(e) {
492
492
  return e > 0 && e <= this.maxKeyLength;
493
493
  }
494
- find(e, t, i) {
495
- const n = this.caches[i - 1];
496
- e: for (const o of n) {
494
+ find(e, t, n) {
495
+ const i = this.caches[n - 1];
496
+ e: for (const o of i) {
497
497
  const c = o.bytes;
498
- for (let l = 0; l < i; l++)
498
+ for (let l = 0; l < n; l++)
499
499
  if (c[l] !== e[t + l])
500
500
  continue e;
501
501
  return o.str;
@@ -503,24 +503,24 @@ class ot {
503
503
  return null;
504
504
  }
505
505
  store(e, t) {
506
- const i = this.caches[e.length - 1], n = { bytes: e, str: t };
507
- i.length >= this.maxLengthPerKey ? i[Math.random() * i.length | 0] = n : i.push(n);
506
+ const n = this.caches[e.length - 1], i = { bytes: e, str: t };
507
+ n.length >= this.maxLengthPerKey ? n[Math.random() * n.length | 0] = i : n.push(i);
508
508
  }
509
- decode(e, t, i) {
510
- const n = this.find(e, t, i);
511
- if (n != null)
512
- return this.hit++, n;
509
+ decode(e, t, n) {
510
+ const i = this.find(e, t, n);
511
+ if (i != null)
512
+ return this.hit++, i;
513
513
  this.miss++;
514
- const o = fe(e, t, i), c = Uint8Array.prototype.slice.call(e, t, t + i);
514
+ const o = xe(e, t, n), c = Uint8Array.prototype.slice.call(e, t, t + n);
515
515
  return this.store(c, o), o;
516
516
  }
517
517
  }
518
- const ee = "array", q = "map_key", ye = "map_value", rt = (s) => {
518
+ const te = "array", O = "map_key", be = "map_value", at = (s) => {
519
519
  if (typeof s == "string" || typeof s == "number")
520
520
  return s;
521
521
  throw new z("The type of key must be string or number but " + typeof s);
522
522
  };
523
- class at {
523
+ class ct {
524
524
  constructor() {
525
525
  r(this, "stack", []);
526
526
  r(this, "stackHeadPosition", -1);
@@ -533,11 +533,11 @@ class at {
533
533
  }
534
534
  pushArrayState(e) {
535
535
  const t = this.getUninitializedStateFromPool();
536
- t.type = ee, t.position = 0, t.size = e, t.array = new Array(e);
536
+ t.type = te, t.position = 0, t.size = e, t.array = new Array(e);
537
537
  }
538
538
  pushMapState(e) {
539
539
  const t = this.getUninitializedStateFromPool();
540
- t.type = q, t.readCount = 0, t.size = e, t.map = {};
540
+ t.type = O, t.readCount = 0, t.size = e, t.map = {};
541
541
  }
542
542
  getUninitializedStateFromPool() {
543
543
  if (this.stackHeadPosition++, this.stackHeadPosition === this.stack.length) {
@@ -557,13 +557,13 @@ class at {
557
557
  release(e) {
558
558
  if (this.stack[this.stackHeadPosition] !== e)
559
559
  throw new Error("Invalid stack state. Released state is not on top of the stack.");
560
- if (e.type === ee) {
561
- const i = e;
562
- i.size = 0, i.array = void 0, i.position = 0, i.type = void 0;
560
+ if (e.type === te) {
561
+ const n = e;
562
+ n.size = 0, n.array = void 0, n.position = 0, n.type = void 0;
563
563
  }
564
- if (e.type === q || e.type === ye) {
565
- const i = e;
566
- i.size = 0, i.map = void 0, i.readCount = 0, i.type = void 0;
564
+ if (e.type === O || e.type === be) {
565
+ const n = e;
566
+ n.size = 0, n.map = void 0, n.readCount = 0, n.type = void 0;
567
567
  }
568
568
  this.stackHeadPosition--;
569
569
  }
@@ -571,15 +571,15 @@ class at {
571
571
  this.stack.length = 0, this.stackHeadPosition = -1;
572
572
  }
573
573
  }
574
- const j = -1, ne = new DataView(new ArrayBuffer(0)), ct = new Uint8Array(ne.buffer);
574
+ const q = -1, se = new DataView(new ArrayBuffer(0)), dt = new Uint8Array(se.buffer);
575
575
  try {
576
- ne.getInt8(0);
576
+ se.getInt8(0);
577
577
  } catch (s) {
578
578
  if (!(s instanceof RangeError))
579
579
  throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
580
580
  }
581
- const de = new RangeError("Insufficient data"), dt = new ot();
582
- class se {
581
+ const he = new RangeError("Insufficient data"), lt = new rt();
582
+ class oe {
583
583
  constructor(e) {
584
584
  r(this, "extensionCodec");
585
585
  r(this, "context");
@@ -594,15 +594,15 @@ class se {
594
594
  r(this, "mapKeyConverter");
595
595
  r(this, "totalPos", 0);
596
596
  r(this, "pos", 0);
597
- r(this, "view", ne);
598
- r(this, "bytes", ct);
599
- r(this, "headByte", j);
600
- r(this, "stack", new at());
597
+ r(this, "view", se);
598
+ r(this, "bytes", dt);
599
+ r(this, "headByte", q);
600
+ r(this, "stack", new ct());
601
601
  r(this, "entered", !1);
602
- this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? W.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) ?? F, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? F, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? F, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? F, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? F, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : dt, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? rt;
602
+ this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? X.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 : lt, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? at;
603
603
  }
604
604
  clone() {
605
- return new se({
605
+ return new oe({
606
606
  extensionCodec: this.extensionCodec,
607
607
  context: this.context,
608
608
  useBigInt64: this.useBigInt64,
@@ -616,26 +616,26 @@ class se {
616
616
  });
617
617
  }
618
618
  reinitializeState() {
619
- this.totalPos = 0, this.headByte = j, this.stack.reset();
619
+ this.totalPos = 0, this.headByte = q, this.stack.reset();
620
620
  }
621
621
  setBuffer(e) {
622
- const t = Q(e);
622
+ const t = ee(e);
623
623
  this.bytes = t, this.view = new DataView(t.buffer, t.byteOffset, t.byteLength), this.pos = 0;
624
624
  }
625
625
  appendBuffer(e) {
626
- if (this.headByte === j && !this.hasRemaining(1))
626
+ if (this.headByte === q && !this.hasRemaining(1))
627
627
  this.setBuffer(e);
628
628
  else {
629
- const t = this.bytes.subarray(this.pos), i = Q(e), n = new Uint8Array(t.length + i.length);
630
- n.set(t), n.set(i, t.length), this.setBuffer(n);
629
+ const t = this.bytes.subarray(this.pos), n = ee(e), i = new Uint8Array(t.length + n.length);
630
+ i.set(t), i.set(n, t.length), this.setBuffer(i);
631
631
  }
632
632
  }
633
633
  hasRemaining(e) {
634
634
  return this.view.byteLength - this.pos >= e;
635
635
  }
636
636
  createExtraByteError(e) {
637
- const { view: t, pos: i } = this;
638
- return new RangeError(`Extra ${t.byteLength - i} of ${t.byteLength} byte(s) found at buffer[${e}]`);
637
+ const { view: t, pos: n } = this;
638
+ return new RangeError(`Extra ${t.byteLength - n} of ${t.byteLength} byte(s) found at buffer[${e}]`);
639
639
  }
640
640
  /**
641
641
  * @throws {@link DecodeError}
@@ -671,26 +671,26 @@ class se {
671
671
  return this.clone().decodeAsync(e);
672
672
  try {
673
673
  this.entered = !0;
674
- let t = !1, i;
674
+ let t = !1, n;
675
675
  for await (const l of e) {
676
676
  if (t)
677
677
  throw this.entered = !1, this.createExtraByteError(this.totalPos);
678
678
  this.appendBuffer(l);
679
679
  try {
680
- i = this.doDecodeSync(), t = !0;
681
- } catch (x) {
682
- if (!(x instanceof RangeError))
683
- throw x;
680
+ n = this.doDecodeSync(), t = !0;
681
+ } catch (w) {
682
+ if (!(w instanceof RangeError))
683
+ throw w;
684
684
  }
685
685
  this.totalPos += this.pos;
686
686
  }
687
687
  if (t) {
688
688
  if (this.hasRemaining(1))
689
689
  throw this.createExtraByteError(this.totalPos);
690
- return i;
690
+ return n;
691
691
  }
692
- const { headByte: n, pos: o, totalPos: c } = this;
693
- throw new RangeError(`Insufficient data in parsing ${G(n)} at ${c} (${o} in the current buffer)`);
692
+ const { headByte: i, pos: o, totalPos: c } = this;
693
+ throw new RangeError(`Insufficient data in parsing ${Z(i)} at ${c} (${o} in the current buffer)`);
694
694
  } finally {
695
695
  this.entered = !1;
696
696
  }
@@ -708,13 +708,13 @@ class se {
708
708
  }
709
709
  try {
710
710
  this.entered = !0;
711
- let i = t, n = -1;
711
+ let n = t, i = -1;
712
712
  for await (const o of e) {
713
- if (t && n === 0)
713
+ if (t && i === 0)
714
714
  throw this.createExtraByteError(this.totalPos);
715
- this.appendBuffer(o), i && (n = this.readArraySize(), i = !1, this.complete());
715
+ this.appendBuffer(o), n && (i = this.readArraySize(), n = !1, this.complete());
716
716
  try {
717
- for (; yield this.doDecodeSync(), --n !== 0; )
717
+ for (; yield this.doDecodeSync(), --i !== 0; )
718
718
  ;
719
719
  } catch (c) {
720
720
  if (!(c instanceof RangeError))
@@ -736,22 +736,22 @@ class se {
736
736
  if (e < 128)
737
737
  t = e;
738
738
  else if (e < 144) {
739
- const n = e - 128;
740
- if (n !== 0) {
741
- this.pushMapState(n), this.complete();
739
+ const i = e - 128;
740
+ if (i !== 0) {
741
+ this.pushMapState(i), this.complete();
742
742
  continue e;
743
743
  } else
744
744
  t = {};
745
745
  } else if (e < 160) {
746
- const n = e - 144;
747
- if (n !== 0) {
748
- this.pushArrayState(n), this.complete();
746
+ const i = e - 144;
747
+ if (i !== 0) {
748
+ this.pushArrayState(i), this.complete();
749
749
  continue e;
750
750
  } else
751
751
  t = [];
752
752
  } else {
753
- const n = e - 160;
754
- t = this.decodeString(n, 0);
753
+ const i = e - 160;
754
+ t = this.decodeString(i, 0);
755
755
  }
756
756
  else if (e === 192)
757
757
  t = null;
@@ -780,51 +780,51 @@ class se {
780
780
  else if (e === 211)
781
781
  this.useBigInt64 ? t = this.readI64AsBigInt() : t = this.readI64();
782
782
  else if (e === 217) {
783
- const n = this.lookU8();
784
- t = this.decodeString(n, 1);
783
+ const i = this.lookU8();
784
+ t = this.decodeString(i, 1);
785
785
  } else if (e === 218) {
786
- const n = this.lookU16();
787
- t = this.decodeString(n, 2);
786
+ const i = this.lookU16();
787
+ t = this.decodeString(i, 2);
788
788
  } else if (e === 219) {
789
- const n = this.lookU32();
790
- t = this.decodeString(n, 4);
789
+ const i = this.lookU32();
790
+ t = this.decodeString(i, 4);
791
791
  } else if (e === 220) {
792
- const n = this.readU16();
793
- if (n !== 0) {
794
- this.pushArrayState(n), this.complete();
792
+ const i = this.readU16();
793
+ if (i !== 0) {
794
+ this.pushArrayState(i), this.complete();
795
795
  continue e;
796
796
  } else
797
797
  t = [];
798
798
  } else if (e === 221) {
799
- const n = this.readU32();
800
- if (n !== 0) {
801
- this.pushArrayState(n), this.complete();
799
+ const i = this.readU32();
800
+ if (i !== 0) {
801
+ this.pushArrayState(i), this.complete();
802
802
  continue e;
803
803
  } else
804
804
  t = [];
805
805
  } else if (e === 222) {
806
- const n = this.readU16();
807
- if (n !== 0) {
808
- this.pushMapState(n), this.complete();
806
+ const i = this.readU16();
807
+ if (i !== 0) {
808
+ this.pushMapState(i), this.complete();
809
809
  continue e;
810
810
  } else
811
811
  t = {};
812
812
  } else if (e === 223) {
813
- const n = this.readU32();
814
- if (n !== 0) {
815
- this.pushMapState(n), this.complete();
813
+ const i = this.readU32();
814
+ if (i !== 0) {
815
+ this.pushMapState(i), this.complete();
816
816
  continue e;
817
817
  } else
818
818
  t = {};
819
819
  } else if (e === 196) {
820
- const n = this.lookU8();
821
- t = this.decodeBinary(n, 1);
820
+ const i = this.lookU8();
821
+ t = this.decodeBinary(i, 1);
822
822
  } else if (e === 197) {
823
- const n = this.lookU16();
824
- t = this.decodeBinary(n, 2);
823
+ const i = this.lookU16();
824
+ t = this.decodeBinary(i, 2);
825
825
  } else if (e === 198) {
826
- const n = this.lookU32();
827
- t = this.decodeBinary(n, 4);
826
+ const i = this.lookU32();
827
+ t = this.decodeBinary(i, 4);
828
828
  } else if (e === 212)
829
829
  t = this.decodeExtension(1, 0);
830
830
  else if (e === 213)
@@ -836,34 +836,34 @@ class se {
836
836
  else if (e === 216)
837
837
  t = this.decodeExtension(16, 0);
838
838
  else if (e === 199) {
839
- const n = this.lookU8();
840
- t = this.decodeExtension(n, 1);
839
+ const i = this.lookU8();
840
+ t = this.decodeExtension(i, 1);
841
841
  } else if (e === 200) {
842
- const n = this.lookU16();
843
- t = this.decodeExtension(n, 2);
842
+ const i = this.lookU16();
843
+ t = this.decodeExtension(i, 2);
844
844
  } else if (e === 201) {
845
- const n = this.lookU32();
846
- t = this.decodeExtension(n, 4);
845
+ const i = this.lookU32();
846
+ t = this.decodeExtension(i, 4);
847
847
  } else
848
- throw new z(`Unrecognized type byte: ${G(e)}`);
848
+ throw new z(`Unrecognized type byte: ${Z(e)}`);
849
849
  this.complete();
850
- const i = this.stack;
851
- for (; i.length > 0; ) {
852
- const n = i.top();
853
- if (n.type === ee)
854
- if (n.array[n.position] = t, n.position++, n.position === n.size)
855
- t = n.array, i.release(n);
850
+ const n = this.stack;
851
+ for (; n.length > 0; ) {
852
+ const i = n.top();
853
+ if (i.type === te)
854
+ if (i.array[i.position] = t, i.position++, i.position === i.size)
855
+ t = i.array, n.release(i);
856
856
  else
857
857
  continue e;
858
- else if (n.type === q) {
858
+ else if (i.type === O) {
859
859
  if (t === "__proto__")
860
860
  throw new z("The key __proto__ is not allowed");
861
- n.key = this.mapKeyConverter(t), n.type = ye;
861
+ i.key = this.mapKeyConverter(t), i.type = be;
862
862
  continue e;
863
- } else if (n.map[n.key] = t, n.readCount++, n.readCount === n.size)
864
- t = n.map, i.release(n);
863
+ } else if (i.map[i.key] = t, i.readCount++, i.readCount === i.size)
864
+ t = i.map, n.release(i);
865
865
  else {
866
- n.key = null, n.type = q;
866
+ i.key = null, i.type = O;
867
867
  continue e;
868
868
  }
869
869
  }
@@ -871,10 +871,10 @@ class se {
871
871
  }
872
872
  }
873
873
  readHeadByte() {
874
- return this.headByte === j && (this.headByte = this.readU8()), this.headByte;
874
+ return this.headByte === q && (this.headByte = this.readU8()), this.headByte;
875
875
  }
876
876
  complete() {
877
- this.headByte = j;
877
+ this.headByte = q;
878
878
  }
879
879
  readArraySize() {
880
880
  const e = this.readHeadByte();
@@ -886,7 +886,7 @@ class se {
886
886
  default: {
887
887
  if (e < 160)
888
888
  return e - 144;
889
- throw new z(`Unrecognized array type byte: ${G(e)}`);
889
+ throw new z(`Unrecognized array type byte: ${Z(e)}`);
890
890
  }
891
891
  }
892
892
  }
@@ -911,13 +911,13 @@ class se {
911
911
  if (e > this.maxStrLength)
912
912
  throw new z(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);
913
913
  if (this.bytes.byteLength < this.pos + t + e)
914
- throw de;
915
- const i = this.pos + t;
916
- let n;
917
- return this.stateIsMapKey() && ((o = this.keyDecoder) != null && o.canBeCached(e)) ? n = this.keyDecoder.decode(this.bytes, i, e) : n = Fe(this.bytes, i, e), this.pos += t + e, n;
914
+ throw he;
915
+ const n = this.pos + t;
916
+ let i;
917
+ return this.stateIsMapKey() && ((o = this.keyDecoder) != null && o.canBeCached(e)) ? i = this.keyDecoder.decode(this.bytes, n, e) : i = je(this.bytes, n, e), this.pos += t + e, i;
918
918
  }
919
919
  stateIsMapKey() {
920
- return this.stack.length > 0 ? this.stack.top().type === q : !1;
920
+ return this.stack.length > 0 ? this.stack.top().type === O : !1;
921
921
  }
922
922
  /**
923
923
  * @throws {@link RangeError}
@@ -926,19 +926,19 @@ class se {
926
926
  if (e > this.maxBinLength)
927
927
  throw new z(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);
928
928
  if (!this.hasRemaining(e + t))
929
- throw de;
930
- const i = this.pos + t, n = this.bytes.subarray(i, i + e);
931
- return this.pos += t + e, n;
929
+ throw he;
930
+ const n = this.pos + t, i = this.bytes.subarray(n, n + e);
931
+ return this.pos += t + e, i;
932
932
  }
933
933
  decodeExtension(e, t) {
934
934
  if (e > this.maxExtLength)
935
935
  throw new z(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);
936
- const i = this.view.getInt8(this.pos + t), n = this.decodeBinary(
936
+ const n = this.view.getInt8(this.pos + t), i = this.decodeBinary(
937
937
  e,
938
938
  t + 1
939
939
  /* extType */
940
940
  );
941
- return this.extensionCodec.decode(n, i, this.context);
941
+ return this.extensionCodec.decode(i, n, this.context);
942
942
  }
943
943
  lookU8() {
944
944
  return this.view.getUint8(this.pos);
@@ -974,11 +974,11 @@ class se {
974
974
  return this.pos += 4, e;
975
975
  }
976
976
  readU64() {
977
- const e = qe(this.view, this.pos);
977
+ const e = Oe(this.view, this.pos);
978
978
  return this.pos += 8, e;
979
979
  }
980
980
  readI64() {
981
- const e = xe(this.view, this.pos);
981
+ const e = ge(this.view, this.pos);
982
982
  return this.pos += 8, e;
983
983
  }
984
984
  readU64AsBigInt() {
@@ -998,10 +998,10 @@ class se {
998
998
  return this.pos += 8, e;
999
999
  }
1000
1000
  }
1001
- function lt(s, e) {
1002
- return new se(e).decode(s);
1001
+ function ht(s, e) {
1002
+ return new oe(e).decode(s);
1003
1003
  }
1004
- const ht = /* @__PURE__ */ new Set([
1004
+ const pt = /* @__PURE__ */ new Set([
1005
1005
  "auth",
1006
1006
  "open",
1007
1007
  "send",
@@ -1018,22 +1018,22 @@ const ht = /* @__PURE__ */ new Set([
1018
1018
  "annotate",
1019
1019
  "annotate_clear"
1020
1020
  ]);
1021
- function pt(s) {
1022
- return ht.has(s.type);
1023
- }
1024
1021
  function ut(s) {
1025
- return it(s);
1022
+ return pt.has(s.type);
1026
1023
  }
1027
1024
  function ft(s) {
1025
+ return it(s);
1026
+ }
1027
+ function wt(s) {
1028
1028
  let e;
1029
1029
  try {
1030
- e = lt(s);
1030
+ e = ht(s);
1031
1031
  } catch {
1032
1032
  return null;
1033
1033
  }
1034
1034
  return typeof e != "object" || e === null || typeof e.type != "string" ? null : e;
1035
1035
  }
1036
- class wt {
1036
+ class xt {
1037
1037
  constructor(e) {
1038
1038
  r(this, "conversationId");
1039
1039
  r(this, "state", "");
@@ -1066,8 +1066,8 @@ class wt {
1066
1066
  }
1067
1067
  messages() {
1068
1068
  return this._sorted || (this._sorted = [...this.byId.values()].sort((e, t) => {
1069
- const i = e.status === "pending", n = t.status === "pending";
1070
- return i !== n ? i ? 1 : -1 : i && n ? e.ts - t.ts : e.seq - t.seq;
1069
+ const n = e.status === "pending", i = t.status === "pending";
1070
+ return n !== i ? n ? 1 : -1 : n && i ? e.ts - t.ts : e.seq - t.seq;
1071
1071
  })), this._sorted;
1072
1072
  }
1073
1073
  visibleActions() {
@@ -1077,7 +1077,7 @@ class wt {
1077
1077
  return this._maxSeq;
1078
1078
  }
1079
1079
  addOptimistic(e, t) {
1080
- const i = {
1080
+ const n = {
1081
1081
  id: e,
1082
1082
  conversationId: this.conversationId,
1083
1083
  seq: 0,
@@ -1088,7 +1088,7 @@ class wt {
1088
1088
  clientMsgId: e,
1089
1089
  status: "pending"
1090
1090
  };
1091
- return this.byId.set(e, i), this.keyByClient.set(e, e), this._sorted = null, i;
1091
+ return this.byId.set(e, n), this.keyByClient.set(e, e), this._sorted = null, n;
1092
1092
  }
1093
1093
  apply(e) {
1094
1094
  var t;
@@ -1103,10 +1103,10 @@ class wt {
1103
1103
  this.upsert({ ...e.message });
1104
1104
  return;
1105
1105
  case "ack": {
1106
- const i = this.keyByClient.get(e.clientMsgId), n = i ? this.byId.get(i) : void 0;
1107
- if (n && i) {
1108
- this.byId.delete(i);
1109
- const o = { ...n, id: e.messageId, seq: e.seq, ts: e.ts, status: "sent" };
1106
+ const n = this.keyByClient.get(e.clientMsgId), i = n ? this.byId.get(n) : void 0;
1107
+ if (i && n) {
1108
+ this.byId.delete(n);
1109
+ const o = { ...i, id: e.messageId, seq: e.seq, ts: e.ts, status: "sent" };
1110
1110
  this.byId.set(e.messageId, o), this.keyByClient.set(e.clientMsgId, e.messageId), e.seq > this._maxSeq && (this._maxSeq = e.seq);
1111
1111
  }
1112
1112
  this._sorted = null;
@@ -1119,30 +1119,30 @@ class wt {
1119
1119
  e.by !== this.me && (this.lastReadByOthers = Math.max(this.lastReadByOthers, e.seq), this.markOwnStatus(e.seq, "read"));
1120
1120
  return;
1121
1121
  case "sync":
1122
- for (const i of e.messages) this.upsert({ ...i });
1122
+ for (const n of e.messages) this.upsert({ ...n });
1123
1123
  return;
1124
1124
  case "history":
1125
- for (const i of e.messages) this.upsert({ ...i });
1125
+ for (const n of e.messages) this.upsert({ ...n });
1126
1126
  this.hasMoreHistory = e.hasMore;
1127
1127
  return;
1128
1128
  case "typing":
1129
1129
  e.userId !== this.me && (e.isTyping ? this.typing.add(e.userId) : this.typing.delete(e.userId));
1130
1130
  return;
1131
1131
  case "reaction": {
1132
- const i = this.byId.get(e.messageId);
1133
- if (!i) return;
1134
- const n = { ...i.reactions ?? {} }, o = (n[e.emoji] ?? []).filter((c) => c !== e.by);
1135
- e.removed || o.push(e.by), o.length ? n[e.emoji] = o : delete n[e.emoji], this.byId.set(e.messageId, { ...i, reactions: n }), this._sorted = null;
1132
+ const n = this.byId.get(e.messageId);
1133
+ if (!n) return;
1134
+ const i = { ...n.reactions ?? {} }, o = (i[e.emoji] ?? []).filter((c) => c !== e.by);
1135
+ 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;
1136
1136
  return;
1137
1137
  }
1138
1138
  case "edited": {
1139
- const i = this.byId.get(e.messageId);
1140
- i && (this.byId.set(e.messageId, { ...i, content: e.content, editedAt: e.editedAt }), this._sorted = null);
1139
+ const n = this.byId.get(e.messageId);
1140
+ n && (this.byId.set(e.messageId, { ...n, content: e.content, editedAt: e.editedAt }), this._sorted = null);
1141
1141
  return;
1142
1142
  }
1143
1143
  case "deleted": {
1144
- const i = this.byId.get(e.messageId);
1145
- i && (this.byId.set(e.messageId, { ...i, deletedAt: e.ts }), this._sorted = null);
1144
+ const n = this.byId.get(e.messageId);
1145
+ n && (this.byId.set(e.messageId, { ...n, deletedAt: e.ts }), this._sorted = null);
1146
1146
  return;
1147
1147
  }
1148
1148
  case "state":
@@ -1178,14 +1178,14 @@ class wt {
1178
1178
  this.byId.set(e.id, t ? { ...t, ...e } : e), e.seq > this._maxSeq && (this._maxSeq = e.seq), this._sorted = null;
1179
1179
  }
1180
1180
  markOwnStatus(e, t) {
1181
- const i = le(t);
1182
- let n = !1;
1181
+ const n = pe(t);
1182
+ let i = !1;
1183
1183
  for (const [o, c] of this.byId)
1184
- c.senderId !== this.me || c.seq <= 0 || c.seq > e || le(c.status) >= i || (this.byId.set(o, { ...c, status: t }), n = !0);
1185
- n && (this._sorted = null);
1184
+ c.senderId !== this.me || c.seq <= 0 || c.seq > e || pe(c.status) >= n || (this.byId.set(o, { ...c, status: t }), i = !0);
1185
+ i && (this._sorted = null);
1186
1186
  }
1187
1187
  }
1188
- function le(s) {
1188
+ function pe(s) {
1189
1189
  switch (s) {
1190
1190
  case "read":
1191
1191
  return 3;
@@ -1197,7 +1197,7 @@ function le(s) {
1197
1197
  return 0;
1198
1198
  }
1199
1199
  }
1200
- class xt {
1200
+ class yt {
1201
1201
  constructor(e) {
1202
1202
  r(this, "socket", null);
1203
1203
  r(this, "state", "idle");
@@ -1209,15 +1209,15 @@ class xt {
1209
1209
  this.opts = e;
1210
1210
  }
1211
1211
  connect() {
1212
- var i, n;
1212
+ var n, i;
1213
1213
  if (this.state === "connecting" || this.state === "open") return;
1214
- this.stopped = !1, this.state = "connecting", this.authed = !1, (n = (i = this.opts).onStatusChange) == null || n.call(i, this.attempt > 0 ? "reconnecting" : "connecting");
1215
- const t = (this.opts.socketFactory ?? yt)(this.opts.url);
1214
+ this.stopped = !1, this.state = "connecting", this.authed = !1, (i = (n = this.opts).onStatusChange) == null || i.call(n, this.attempt > 0 ? "reconnecting" : "connecting");
1215
+ const t = (this.opts.socketFactory ?? gt)(this.opts.url);
1216
1216
  t.binaryType = "arraybuffer", this.socket = t, t.onopen = () => {
1217
1217
  this.raw({ type: "auth", token: this.opts.token });
1218
1218
  }, t.onmessage = (o) => {
1219
- const c = ft(new Uint8Array(o.data));
1220
- !c || pt(c) || this.handle(c);
1219
+ const c = wt(new Uint8Array(o.data));
1220
+ !c || ut(c) || this.handle(c);
1221
1221
  }, t.onclose = () => this.onClosed(), t.onerror = () => {
1222
1222
  try {
1223
1223
  t.close();
@@ -1245,8 +1245,8 @@ class xt {
1245
1245
  }
1246
1246
  }
1247
1247
  handle(e) {
1248
- var t, i;
1249
- e.type === "authed" && (this.attempt = 0, this.state = "open", this.authed = !0, (i = (t = this.opts).onStatusChange) == null || i.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() }), this.opts.onFrame(e);
1248
+ var t, n;
1249
+ e.type === "authed" && (this.attempt = 0, this.state = "open", this.authed = !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() }), this.opts.onFrame(e);
1250
1250
  }
1251
1251
  flush() {
1252
1252
  const e = this.outbox;
@@ -1256,7 +1256,7 @@ class xt {
1256
1256
  raw(e) {
1257
1257
  var t;
1258
1258
  try {
1259
- (t = this.socket) == null || t.send(ut(e));
1259
+ (t = this.socket) == null || t.send(ft(e));
1260
1260
  } catch {
1261
1261
  this.outbox.push(e);
1262
1262
  }
@@ -1267,15 +1267,15 @@ class xt {
1267
1267
  return;
1268
1268
  }
1269
1269
  this.state = "idle";
1270
- const e = this.opts.backoffBaseMs ?? 500, t = this.opts.backoffMaxMs ?? 15e3, i = Math.min(t, e * 2 ** this.attempt) * (0.5 + Math.random() * 0.5);
1271
- this.attempt++, this.timer = setTimeout(() => this.connect(), i);
1270
+ 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);
1271
+ this.attempt++, this.timer = setTimeout(() => this.connect(), n);
1272
1272
  }
1273
1273
  }
1274
- function yt(s) {
1274
+ function gt(s) {
1275
1275
  return new WebSocket(s);
1276
1276
  }
1277
- const he = 200, gt = 7 * 864e5;
1278
- class bt {
1277
+ const ue = 200, bt = 7 * 864e5;
1278
+ class mt {
1279
1279
  constructor(e) {
1280
1280
  r(this, "key");
1281
1281
  this.key = `ocw_outbox_${e}`;
@@ -1285,8 +1285,8 @@ class bt {
1285
1285
  try {
1286
1286
  const e = localStorage.getItem(this.key);
1287
1287
  if (!e) return [];
1288
- const t = JSON.parse(e), i = Date.now() - gt, n = t.filter((o) => o.ts >= i);
1289
- return n.length !== t.length && this.save(n), n;
1288
+ const t = JSON.parse(e), n = Date.now() - bt, i = t.filter((o) => o.ts >= n);
1289
+ return i.length !== t.length && this.save(i), i;
1290
1290
  } catch {
1291
1291
  return [];
1292
1292
  }
@@ -1294,14 +1294,14 @@ class bt {
1294
1294
  add(e) {
1295
1295
  try {
1296
1296
  const t = this.load();
1297
- t.push(e), this.save(t.length > he ? t.slice(t.length - he) : t);
1297
+ t.push(e), this.save(t.length > ue ? t.slice(t.length - ue) : t);
1298
1298
  } catch {
1299
1299
  }
1300
1300
  }
1301
1301
  /** Remove an item once it's been acknowledged by the server. */
1302
1302
  remove(e) {
1303
1303
  try {
1304
- const t = this.load().filter((i) => i.clientMsgId !== e);
1304
+ const t = this.load().filter((n) => n.clientMsgId !== e);
1305
1305
  this.save(t);
1306
1306
  } catch {
1307
1307
  }
@@ -1313,31 +1313,31 @@ class bt {
1313
1313
  }
1314
1314
  }
1315
1315
  }
1316
- const S = () => globalThis.crypto.subtle;
1317
- function X(s) {
1316
+ const k = () => globalThis.crypto.subtle;
1317
+ function Y(s) {
1318
1318
  const e = s instanceof Uint8Array ? s : new Uint8Array(s);
1319
1319
  let t = "";
1320
- for (const i of e) t += String.fromCharCode(i);
1320
+ for (const n of e) t += String.fromCharCode(n);
1321
1321
  return btoa(t);
1322
1322
  }
1323
- function te(s) {
1324
- const e = atob(s), t = new ArrayBuffer(e.length), i = new Uint8Array(t);
1325
- for (let n = 0; n < e.length; n++) i[n] = e.charCodeAt(n);
1326
- return i;
1323
+ function ne(s) {
1324
+ const e = atob(s), t = new ArrayBuffer(e.length), n = new Uint8Array(t);
1325
+ for (let i = 0; i < e.length; i++) n[i] = e.charCodeAt(i);
1326
+ return n;
1327
1327
  }
1328
- async function O() {
1329
- const s = await S().generateKey({ name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
1328
+ async function N() {
1329
+ const s = await k().generateKey({ name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
1330
1330
  return { publicKey: s.publicKey, privateKey: s.privateKey };
1331
1331
  }
1332
- async function _(s) {
1333
- return X(await S().exportKey("raw", s));
1332
+ async function $(s) {
1333
+ return Y(await k().exportKey("raw", s));
1334
1334
  }
1335
- async function R(s) {
1336
- return S().importKey("raw", te(s), { name: "ECDH", namedCurve: "P-256" }, !1, []);
1335
+ async function F(s) {
1336
+ return k().importKey("raw", ne(s), { name: "ECDH", namedCurve: "P-256" }, !1, []);
1337
1337
  }
1338
- async function mt(s, e) {
1339
- const t = await R(e);
1340
- return S().deriveKey(
1338
+ async function vt(s, e) {
1339
+ const t = await F(e);
1340
+ return k().deriveKey(
1341
1341
  { name: "ECDH", public: t },
1342
1342
  s,
1343
1343
  { name: "AES-GCM", length: 256 },
@@ -1345,89 +1345,89 @@ async function mt(s, e) {
1345
1345
  ["encrypt", "decrypt"]
1346
1346
  );
1347
1347
  }
1348
- async function vt(s, e) {
1349
- const t = globalThis.crypto.getRandomValues(new Uint8Array(12)), i = new TextEncoder().encode(e), n = await S().encrypt({ name: "AES-GCM", iv: t }, s, i);
1350
- return { ct: X(n), iv: X(t) };
1348
+ async function kt(s, e) {
1349
+ const t = globalThis.crypto.getRandomValues(new Uint8Array(12)), n = new TextEncoder().encode(e), i = await k().encrypt({ name: "AES-GCM", iv: t }, s, n);
1350
+ return { ct: Y(i), iv: Y(t) };
1351
1351
  }
1352
- async function kt(s, e, t) {
1353
- const i = await S().decrypt({ name: "AES-GCM", iv: te(t) }, s, te(e));
1354
- return new TextDecoder().decode(i);
1352
+ async function St(s, e, t) {
1353
+ const n = await k().decrypt({ name: "AES-GCM", iv: ne(t) }, s, ne(e));
1354
+ return new TextDecoder().decode(n);
1355
1355
  }
1356
- async function St(s) {
1357
- var t, i;
1356
+ async function It(s) {
1357
+ var t, n;
1358
1358
  try {
1359
- const n = (t = globalThis.localStorage) == null ? void 0 : t.getItem(s);
1360
- if (n) {
1361
- const { pub: o, priv: c } = JSON.parse(n), l = await S().importKey("jwk", o, { name: "ECDH", namedCurve: "P-256" }, !0, []), x = await S().importKey("jwk", c, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
1362
- return { publicKey: l, privateKey: x };
1359
+ const i = (t = globalThis.localStorage) == null ? void 0 : t.getItem(s);
1360
+ if (i) {
1361
+ const { pub: o, priv: c } = JSON.parse(i), l = await k().importKey("jwk", o, { name: "ECDH", namedCurve: "P-256" }, !0, []), w = await k().importKey("jwk", c, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
1362
+ return { publicKey: l, privateKey: w };
1363
1363
  }
1364
1364
  } catch {
1365
1365
  }
1366
- const e = await O();
1366
+ const e = await N();
1367
1367
  try {
1368
- const n = await S().exportKey("jwk", e.publicKey), o = await S().exportKey("jwk", e.privateKey);
1369
- (i = globalThis.localStorage) == null || i.setItem(s, JSON.stringify({ pub: n, priv: o }));
1368
+ const i = await k().exportKey("jwk", e.publicKey), o = await k().exportKey("jwk", e.privateKey);
1369
+ (n = globalThis.localStorage) == null || n.setItem(s, JSON.stringify({ pub: i, priv: o }));
1370
1370
  } catch {
1371
1371
  }
1372
1372
  return e;
1373
1373
  }
1374
- async function It(s, e) {
1375
- const t = await S().exportKey("raw", e), i = await S().sign({ name: "ECDSA", hash: "SHA-256" }, s, t);
1376
- return X(i);
1374
+ async function Ct(s, e) {
1375
+ const t = await k().exportKey("raw", e), n = await k().sign({ name: "ECDSA", hash: "SHA-256" }, s, t);
1376
+ return Y(n);
1377
1377
  }
1378
- async function Ct() {
1379
- const s = await O(), e = await S().generateKey({ name: "ECDSA", namedCurve: "P-256" }, !0, ["sign", "verify"]);
1378
+ async function Et() {
1379
+ const s = await N(), e = await k().generateKey({ name: "ECDSA", namedCurve: "P-256" }, !0, ["sign", "verify"]);
1380
1380
  return {
1381
1381
  ecdhKP: s,
1382
1382
  ecdsaKP: { publicKey: e.publicKey, privateKey: e.privateKey },
1383
- publicKeyB64: await _(s.publicKey),
1384
- sigPublicKeyB64: await _(e.publicKey)
1383
+ publicKeyB64: await $(s.publicKey),
1384
+ sigPublicKeyB64: await $(e.publicKey)
1385
1385
  };
1386
1386
  }
1387
- async function pe(s) {
1388
- var t, i;
1387
+ async function fe(s) {
1388
+ var t, n;
1389
1389
  try {
1390
- const n = (t = globalThis.localStorage) == null ? void 0 : t.getItem(`${s}-identity`);
1391
- if (n) {
1392
- const o = JSON.parse(n), c = await S().importKey("jwk", o.ecdhPub, { name: "ECDH", namedCurve: "P-256" }, !0, []), l = await S().importKey("jwk", o.ecdhPriv, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]), x = await S().importKey("jwk", o.ecdsaPub, { name: "ECDSA", namedCurve: "P-256" }, !0, ["verify"]), y = await S().importKey("jwk", o.ecdsaPriv, { name: "ECDSA", namedCurve: "P-256" }, !0, ["sign"]);
1390
+ const i = (t = globalThis.localStorage) == null ? void 0 : t.getItem(`${s}-identity`);
1391
+ if (i) {
1392
+ const o = JSON.parse(i), c = await k().importKey("jwk", o.ecdhPub, { name: "ECDH", namedCurve: "P-256" }, !0, []), l = await k().importKey("jwk", o.ecdhPriv, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]), w = await k().importKey("jwk", o.ecdsaPub, { name: "ECDSA", namedCurve: "P-256" }, !0, ["verify"]), f = await k().importKey("jwk", o.ecdsaPriv, { name: "ECDSA", namedCurve: "P-256" }, !0, ["sign"]);
1393
1393
  return {
1394
1394
  ecdhKP: { publicKey: c, privateKey: l },
1395
- ecdsaKP: { publicKey: x, privateKey: y },
1396
- publicKeyB64: await _(c),
1397
- sigPublicKeyB64: await _(x)
1395
+ ecdsaKP: { publicKey: w, privateKey: f },
1396
+ publicKeyB64: await $(c),
1397
+ sigPublicKeyB64: await $(w)
1398
1398
  };
1399
1399
  }
1400
1400
  } catch {
1401
1401
  }
1402
- const e = await Ct();
1402
+ const e = await Et();
1403
1403
  try {
1404
- const n = await S().exportKey("jwk", e.ecdhKP.publicKey), o = await S().exportKey("jwk", e.ecdhKP.privateKey), c = await S().exportKey("jwk", e.ecdsaKP.publicKey), l = await S().exportKey("jwk", e.ecdsaKP.privateKey);
1405
- (i = globalThis.localStorage) == null || i.setItem(`${s}-identity`, JSON.stringify({ ecdhPub: n, ecdhPriv: o, ecdsaPub: c, ecdsaPriv: l }));
1404
+ const i = await k().exportKey("jwk", e.ecdhKP.publicKey), o = await k().exportKey("jwk", e.ecdhKP.privateKey), c = await k().exportKey("jwk", e.ecdsaKP.publicKey), l = await k().exportKey("jwk", e.ecdsaKP.privateKey);
1405
+ (n = globalThis.localStorage) == null || n.setItem(`${s}-identity`, JSON.stringify({ ecdhPub: i, ecdhPriv: o, ecdsaPub: c, ecdsaPriv: l }));
1406
1406
  } catch {
1407
1407
  }
1408
1408
  return e;
1409
1409
  }
1410
- async function Et(s, e) {
1411
- const t = await O(), i = await _(t.publicKey), n = await R(e.identityKey), o = await R(e.signedPrekey), c = e.oneTimePrekey ? await R(e.oneTimePrekey) : null, l = await $(s.privateKey, o), x = await $(t.privateKey, n), y = await $(t.privateKey, o), b = c ? await $(t.privateKey, c) : null, f = ge(l, x, y, ...b ? [b] : []);
1412
- return { sharedKey: await be(f), ephemeralPublicKey: i };
1410
+ async function Tt(s, e) {
1411
+ const t = await N(), n = await $(t.publicKey), i = await F(e.identityKey), o = await F(e.signedPrekey), c = e.oneTimePrekey ? await F(e.oneTimePrekey) : null, l = await _(s.privateKey, o), w = await _(t.privateKey, i), f = await _(t.privateKey, o), m = c ? await _(t.privateKey, c) : null, x = me(l, w, f, ...m ? [m] : []);
1412
+ return { sharedKey: await ve(x), ephemeralPublicKey: n };
1413
1413
  }
1414
- async function Tt(s, e, t, i, n) {
1415
- const o = await R(t), c = await R(i), l = await $(e.privateKey, o), x = await $(s.privateKey, c), y = await $(e.privateKey, c), b = n ? await $(n.privateKey, c) : null, f = ge(l, x, y, ...b ? [b] : []);
1416
- return be(f);
1414
+ async function Ut(s, e, t, n, i) {
1415
+ const o = await F(t), c = await F(n), l = await _(e.privateKey, o), w = await _(s.privateKey, c), f = await _(e.privateKey, c), m = i ? await _(i.privateKey, c) : null, x = me(l, w, f, ...m ? [m] : []);
1416
+ return ve(x);
1417
1417
  }
1418
- async function $(s, e) {
1419
- return S().deriveBits({ name: "ECDH", public: e }, s, 256);
1418
+ async function _(s, e) {
1419
+ return k().deriveBits({ name: "ECDH", public: e }, s, 256);
1420
1420
  }
1421
- function ge(...s) {
1422
- const e = s.reduce((n, o) => n + o.byteLength, 0), t = new Uint8Array(e);
1423
- let i = 0;
1424
- for (const n of s)
1425
- t.set(new Uint8Array(n), i), i += n.byteLength;
1421
+ function me(...s) {
1422
+ const e = s.reduce((i, o) => i + o.byteLength, 0), t = new Uint8Array(e);
1423
+ let n = 0;
1424
+ for (const i of s)
1425
+ t.set(new Uint8Array(i), n), n += i.byteLength;
1426
1426
  return t.buffer;
1427
1427
  }
1428
- async function be(s) {
1429
- const e = await S().importKey("raw", s, "HKDF", !1, ["deriveKey"]);
1430
- return S().deriveKey(
1428
+ async function ve(s) {
1429
+ const e = await k().importKey("raw", s, "HKDF", !1, ["deriveKey"]);
1430
+ return k().deriveKey(
1431
1431
  { name: "HKDF", hash: "SHA-256", salt: new Uint8Array(32), info: new TextEncoder().encode("ObjectChat X3DH v1") },
1432
1432
  e,
1433
1433
  { name: "AES-GCM", length: 256 },
@@ -1435,8 +1435,8 @@ async function be(s) {
1435
1435
  ["encrypt", "decrypt"]
1436
1436
  );
1437
1437
  }
1438
- const Ut = 20;
1439
- class Pt {
1438
+ const Pt = 20;
1439
+ class Bt {
1440
1440
  constructor(e) {
1441
1441
  // Live ECDH mode state
1442
1442
  r(this, "kp");
@@ -1457,58 +1457,58 @@ class Pt {
1457
1457
  }
1458
1458
  /** Live ECDH mode: Generate/restore our keypair and return our public key to publish. */
1459
1459
  async begin() {
1460
- return this.kp = await St(this.storageKey), _(this.kp.publicKey);
1460
+ return this.kp = await It(this.storageKey), $(this.kp.publicKey);
1461
1461
  }
1462
1462
  /** Live ECDH mode: A peer published their key — derive the shared secret. */
1463
1463
  async onPeerKey(e) {
1464
- this.kp && (this.shared = await mt(this.kp.privateKey, e));
1464
+ this.kp && (this.shared = await vt(this.kp.privateKey, e));
1465
1465
  }
1466
1466
  // ── X3DH async mode ────────────────────────────────────────────────────────
1467
1467
  /** X3DH: Generate identity key, signed prekey, and OTP prekeys.
1468
1468
  * Returns the upload frame payload the caller should send to the server. */
1469
1469
  async initX3DH() {
1470
- this.identityKP = await pe(this.storageKey), this.signedPreKP = await O(), this.signedPrekeyId = `spk-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1471
- for (let n = 0; n < Ut; n++) this.otpKeys.push(await O());
1472
- const e = await _(this.signedPreKP.publicKey), t = await It(this.identityKP.ecdsaKP.privateKey, this.signedPreKP.publicKey), i = await Promise.all(this.otpKeys.map((n) => _(n.publicKey)));
1470
+ this.identityKP = await fe(this.storageKey), this.signedPreKP = await N(), this.signedPrekeyId = `spk-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1471
+ for (let i = 0; i < Pt; i++) this.otpKeys.push(await N());
1472
+ const e = await $(this.signedPreKP.publicKey), t = await Ct(this.identityKP.ecdsaKP.privateKey, this.signedPreKP.publicKey), n = await Promise.all(this.otpKeys.map((i) => $(i.publicKey)));
1473
1473
  return {
1474
1474
  identityKey: this.identityKP.publicKeyB64,
1475
1475
  signedPrekey: e,
1476
1476
  signedPrekeyId: this.signedPrekeyId,
1477
1477
  signature: t,
1478
- oneTimePrekeys: i
1478
+ oneTimePrekeys: n
1479
1479
  };
1480
1480
  }
1481
1481
  /** X3DH sender: given a recipient's prekey bundle, derive the shared key and
1482
1482
  * return the init message fields to embed in the first encrypted message. */
1483
1483
  async x3dhSendTo(e) {
1484
- this.identityKP || (this.identityKP = await pe(this.storageKey));
1485
- const { sharedKey: t, ephemeralPublicKey: i } = await Et(this.identityKP.ecdhKP, e);
1486
- return this.x3dhShared = t, { ephemeralKey: i, spkId: e.signedPrekeyId, usedOTP: !!e.oneTimePrekey, senderIK: this.identityKP.publicKeyB64 };
1484
+ this.identityKP || (this.identityKP = await fe(this.storageKey));
1485
+ const { sharedKey: t, ephemeralPublicKey: n } = await Tt(this.identityKP.ecdhKP, e);
1486
+ return this.x3dhShared = t, { ephemeralKey: n, spkId: e.signedPrekeyId, usedOTP: !!e.oneTimePrekey, senderIK: this.identityKP.publicKeyB64 };
1487
1487
  }
1488
1488
  /** X3DH recipient: given an init message's sender IK + EK + SPK ID, derive the shared key. */
1489
- async x3dhReceiveFrom(e, t, i) {
1489
+ async x3dhReceiveFrom(e, t, n) {
1490
1490
  if (!this.identityKP || !this.signedPreKP) {
1491
- this.pendingX3DH = { senderIK: e, ephemeralKey: t, spkId: i };
1491
+ this.pendingX3DH = { senderIK: e, ephemeralKey: t, spkId: n };
1492
1492
  return;
1493
1493
  }
1494
- const n = this.otpKeys.shift();
1495
- this.x3dhShared = await Tt(this.identityKP.ecdhKP, this.signedPreKP, e, t, n);
1494
+ const i = this.otpKeys.shift();
1495
+ this.x3dhShared = await Ut(this.identityKP.ecdhKP, this.signedPreKP, e, t, i);
1496
1496
  }
1497
1497
  /** Flush pending X3DH derivation after initX3DH() completes. */
1498
1498
  async flushPendingX3DH() {
1499
1499
  if (!this.pendingX3DH) return;
1500
- const { senderIK: e, ephemeralKey: t, spkId: i } = this.pendingX3DH;
1501
- this.pendingX3DH = void 0, await this.x3dhReceiveFrom(e, t, i);
1500
+ const { senderIK: e, ephemeralKey: t, spkId: n } = this.pendingX3DH;
1501
+ this.pendingX3DH = void 0, await this.x3dhReceiveFrom(e, t, n);
1502
1502
  }
1503
1503
  /** Encrypt outgoing text into a wire content object. For X3DH init messages,
1504
1504
  * the caller should pass x3dhInit fields to embed in the content. */
1505
1505
  async sealText(e, t) {
1506
- const i = this.x3dhShared ?? this.shared;
1507
- if (!i) throw new Error("secure channel not ready");
1508
- const { ct: n, iv: o } = await vt(i, e);
1506
+ const n = this.x3dhShared ?? this.shared;
1507
+ if (!n) throw new Error("secure channel not ready");
1508
+ const { ct: i, iv: o } = await kt(n, e);
1509
1509
  return {
1510
1510
  kind: "text",
1511
- text: n,
1511
+ text: i,
1512
1512
  enc: !0,
1513
1513
  iv: o,
1514
1514
  ...t ? { x3dhEK: t.ephemeralKey, x3dhSPK: t.spkId, x3dhIK: t.senderIK } : {}
@@ -1520,7 +1520,7 @@ class Pt {
1520
1520
  const t = this.x3dhShared ?? this.shared;
1521
1521
  if (!t) return { kind: "text", text: "🔒 encrypted" };
1522
1522
  try {
1523
- return { kind: "text", text: await kt(t, e.text, e.iv) };
1523
+ return { kind: "text", text: await St(t, e.text, e.iv) };
1524
1524
  } catch {
1525
1525
  return { kind: "text", text: "🔒 unable to decrypt" };
1526
1526
  }
@@ -1532,12 +1532,12 @@ class Pt {
1532
1532
  for (const t of e.messages) t.content = await this.openContent(t.content);
1533
1533
  }
1534
1534
  }
1535
- function Bt(s) {
1535
+ function Kt(s) {
1536
1536
  if (s.kind !== "text" || !s.enc) return null;
1537
1537
  const e = s;
1538
1538
  return !e.x3dhEK || !e.x3dhSPK || !e.x3dhIK ? null : { x3dhEK: e.x3dhEK, x3dhSPK: e.x3dhSPK, x3dhIK: e.x3dhIK };
1539
1539
  }
1540
- const ue = "objectchat-widget-styles", Kt = ["👍", "❤️", "😂", "😮", "😢", "🙏"], At = `
1540
+ const we = "objectchat-widget-styles", At = ["👍", "❤️", "😂", "😮", "😢", "🙏"], zt = `
1541
1541
  .ocw { --ocw-accent:#f5713c; --ocw-bg:#f3efe9; --ocw-card:#fff; --ocw-line:#ececec; --ocw-ink:#1c1b1a; --ocw-mut:#9b9690;
1542
1542
  position:relative;
1543
1543
  display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
@@ -1696,23 +1696,23 @@ const ue = "objectchat-widget-styles", Kt = ["👍", "❤️", "😂", "😮", "
1696
1696
  .ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
1697
1697
  .ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
1698
1698
  `;
1699
- function zt() {
1700
- if (typeof document > "u" || document.getElementById(ue)) return;
1699
+ function Lt() {
1700
+ if (typeof document > "u" || document.getElementById(we)) return;
1701
1701
  const s = document.createElement("style");
1702
- s.id = ue, s.textContent = At, document.head.appendChild(s);
1702
+ s.id = we, s.textContent = zt, document.head.appendChild(s);
1703
1703
  }
1704
1704
  function a(s, e, t) {
1705
- const i = document.createElement(s);
1706
- return e && (i.className = e), t !== void 0 && (i.textContent = t), i;
1705
+ const n = document.createElement(s);
1706
+ return e && (n.className = e), t !== void 0 && (n.textContent = t), n;
1707
1707
  }
1708
- function Lt(s) {
1708
+ function Mt(s) {
1709
1709
  try {
1710
1710
  return new Date(s).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
1711
1711
  } catch {
1712
1712
  return "";
1713
1713
  }
1714
1714
  }
1715
- function Z(s) {
1715
+ function Q(s) {
1716
1716
  var e;
1717
1717
  switch (s.kind) {
1718
1718
  case "text":
@@ -1729,9 +1729,9 @@ function Z(s) {
1729
1729
  return `📅 ${s.title} — ${new Date(s.startIso).toLocaleString()}`;
1730
1730
  }
1731
1731
  }
1732
- class Mt {
1732
+ class Dt {
1733
1733
  /** Last seq the guest has seen per conversationId — used to compute unread badges. */
1734
- constructor(e, t, i, n = {}) {
1734
+ constructor(e, t, n, i = {}) {
1735
1735
  r(this, "scroll");
1736
1736
  r(this, "chips");
1737
1737
  r(this, "typing");
@@ -1762,56 +1762,56 @@ class Mt {
1762
1762
  r(this, "translationCache", /* @__PURE__ */ new Map());
1763
1763
  r(this, "showingTranslation", /* @__PURE__ */ new Set());
1764
1764
  r(this, "subjectBuilt", !1);
1765
- var m, w, v, B, U, P, A, C, H;
1766
- this.root = e, this.me = t, this.h = i, this.cfg = n, zt(), e.classList.add("ocw"), n.accent && e.style.setProperty("--ocw-accent", n.accent);
1765
+ var y, g, C, T, U, B, K, P, H;
1766
+ this.root = e, this.me = t, this.h = n, this.cfg = i, Lt(), e.classList.add("ocw"), i.accent && e.style.setProperty("--ocw-accent", i.accent);
1767
1767
  const o = a("div", "ocw-head"), c = a("div", "ocw-avatar");
1768
- if ((m = n.userInfo) != null && m.avatar) {
1769
- const k = document.createElement("img");
1770
- k.src = n.userInfo.avatar, k.alt = n.userInfo.name ?? "You", k.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover", c.append(k);
1768
+ if ((y = i.userInfo) != null && y.avatar) {
1769
+ const v = document.createElement("img");
1770
+ v.src = i.userInfo.avatar, v.alt = i.userInfo.name ?? "You", v.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover", c.append(v);
1771
1771
  } else
1772
- c.textContent = (w = n.userInfo) != null && w.name ? n.userInfo.name[0].toUpperCase() : "🧑";
1772
+ c.textContent = (g = i.userInfo) != null && g.name ? i.userInfo.name[0].toUpperCase() : "🧑";
1773
1773
  o.append(c);
1774
1774
  const l = a("div", "ocw-head-main");
1775
- this.headerName = a("div", "ocw-head-name", ((v = n.subject) == null ? void 0 : v.ownerLabel) ?? ((B = n.subject) == null ? void 0 : B.title) ?? ""), l.append(this.headerName), (U = n.subject) != null && U.subtitle && l.append(a("div", "ocw-head-meta", n.subject.subtitle)), o.append(l), this.statusBadge = a("span", "ocw-badge", ((P = n.subject) == null ? void 0 : P.status) ?? ""), (A = n.subject) != null && A.status || (this.statusBadge.style.display = "none"), o.append(this.statusBadge), this.e2eBadge = a("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", o.append(this.e2eBadge), this.connStatus = a("span", "ocw-conn-status"), this.connStatus.style.display = "none", o.append(this.connStatus), this.cobrowseBtn = a("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
1775
+ this.headerName = a("div", "ocw-head-name", ((C = i.subject) == null ? void 0 : C.ownerLabel) ?? ((T = i.subject) == null ? void 0 : T.title) ?? ""), l.append(this.headerName), (U = i.subject) != null && U.subtitle && l.append(a("div", "ocw-head-meta", i.subject.subtitle)), o.append(l), this.statusBadge = a("span", "ocw-badge", ((B = i.subject) == null ? void 0 : B.status) ?? ""), (K = i.subject) != null && K.status || (this.statusBadge.style.display = "none"), o.append(this.statusBadge), this.e2eBadge = a("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", o.append(this.e2eBadge), this.connStatus = a("span", "ocw-conn-status"), this.connStatus.style.display = "none", o.append(this.connStatus), this.cobrowseBtn = a("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
1776
1776
  this.cobrowseActive = !this.cobrowseActive, this.updateCobrowseUI();
1777
1777
  }), o.append(this.cobrowseBtn), o.append(a("button", "ocw-menu", "⋯")), this.chips = a("div", "ocw-chiprow"), this.scroll = a("div", "ocw-scroll"), this.subjectCard = a("div", "ocw-subject"), this.typing = a("div", "ocw-typing");
1778
- const x = a("div", "ocw-typing-bubble");
1779
- x.append(a("div", "ocw-typing-dot"), a("div", "ocw-typing-dot"), a("div", "ocw-typing-dot")), this.typing.append(a("div", "ocw-dot", "🧑"), x), this.quick = a("div", "ocw-quick");
1780
- for (const k of n.quickReplies ?? []) {
1781
- const K = a("button", void 0, k);
1782
- K.addEventListener("click", () => {
1783
- this.h.onSend(k), this.quick.style.display = "none";
1784
- }), this.quick.append(K);
1778
+ const w = a("div", "ocw-typing-bubble");
1779
+ w.append(a("div", "ocw-typing-dot"), a("div", "ocw-typing-dot"), a("div", "ocw-typing-dot")), this.typing.append(a("div", "ocw-dot", "🧑"), w), this.quick = a("div", "ocw-quick");
1780
+ for (const v of i.quickReplies ?? []) {
1781
+ const A = a("button", void 0, v);
1782
+ A.addEventListener("click", () => {
1783
+ this.h.onSend(v), this.quick.style.display = "none";
1784
+ }), this.quick.append(A);
1785
1785
  }
1786
1786
  this.formHost = a("div", "ocw-form-host"), this.csatPanel = a("div", "ocw-csat"), this.csatPanel.style.display = "none", this.offlinePanel = a("div", "ocw-offline"), this.offlinePanel.style.display = "none", this.input = a("textarea", void 0), this.input.rows = 1, this.input.placeholder = "Message…";
1787
- const y = a("button", "ocw-sendbtn", ((C = n.i18n) == null ? void 0 : C.send) ?? "➤");
1788
- y.addEventListener("click", () => this.flushSend()), this.input.addEventListener("keydown", (k) => {
1789
- k.isComposing || k.keyCode === 229 || (k.key === "Enter" && !k.shiftKey ? (k.preventDefault(), this.flushSend()) : this.signalTyping());
1787
+ const f = a("button", "ocw-sendbtn", ((P = i.i18n) == null ? void 0 : P.send) ?? "➤");
1788
+ f.addEventListener("click", () => this.flushSend()), this.input.addEventListener("keydown", (v) => {
1789
+ v.isComposing || v.keyCode === 229 || (v.key === "Enter" && !v.shiftKey ? (v.preventDefault(), this.flushSend()) : this.signalTyping());
1790
1790
  });
1791
- const b = a("button", "ocw-attach", "📎");
1792
- b.title = "Attach image or file";
1793
- const f = document.createElement("input");
1794
- f.type = "file", f.accept = "image/*,.pdf,.txt,.doc,.docx", f.style.display = "none", b.addEventListener("click", () => f.click()), f.addEventListener("change", () => {
1795
- var k;
1796
- (k = f.files) != null && k[0] && this.h.onAttach && this.h.onAttach(f.files[0]), f.value = "";
1791
+ const m = a("button", "ocw-attach", "📎");
1792
+ m.title = "Attach image or file";
1793
+ const x = document.createElement("input");
1794
+ x.type = "file", x.accept = "image/*,.pdf,.txt,.doc,.docx", x.style.display = "none", m.addEventListener("click", () => x.click()), x.addEventListener("change", () => {
1795
+ var v;
1796
+ (v = x.files) != null && v[0] && this.h.onAttach && this.h.onAttach(x.files[0]), x.value = "";
1797
1797
  });
1798
- const p = a("div", "ocw-input");
1799
- p.append(b, f, this.input, y);
1800
- const h = a("div", "ocw-footer");
1801
- ((H = n.i18n) == null ? void 0 : H.poweredBy) !== void 0 ? h.textContent = n.i18n.poweredBy : h.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = h, e.append(o, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, p, this.footer), this.cobrowseCanvas = a("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = a("div", "ocw-cobrowse-toolbar");
1802
- for (const k of ["#f5713c", "#1c1b1a", "#2563eb", "#16a34a", "#dc2626"]) {
1803
- const K = a("button", "ocw-cobrowse-swatch");
1804
- K.style.background = k, K.type = "button", k === this.cobrowseColor && K.classList.add("sel"), K.addEventListener("click", () => {
1805
- this.cobrowseColor = k;
1806
- for (const J of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch")) J.classList.remove("sel");
1807
- K.classList.add("sel");
1808
- }), this.cobrowseToolbar.append(K);
1798
+ const h = a("div", "ocw-input");
1799
+ h.append(m, x, this.input, f);
1800
+ const p = a("div", "ocw-footer");
1801
+ ((H = i.i18n) == null ? void 0 : H.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, h, this.footer), this.cobrowseCanvas = a("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = a("div", "ocw-cobrowse-toolbar");
1802
+ for (const v of ["#f5713c", "#1c1b1a", "#2563eb", "#16a34a", "#dc2626"]) {
1803
+ const A = a("button", "ocw-cobrowse-swatch");
1804
+ A.style.background = v, A.type = "button", v === this.cobrowseColor && A.classList.add("sel"), A.addEventListener("click", () => {
1805
+ this.cobrowseColor = v;
1806
+ for (const G of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch")) G.classList.remove("sel");
1807
+ A.classList.add("sel");
1808
+ }), this.cobrowseToolbar.append(A);
1809
1809
  }
1810
- const T = a("button", "ocw-cobrowse-clear", "Clear");
1811
- T.addEventListener("click", () => {
1812
- var k, K;
1813
- return (K = (k = this.h).onAnnotateClear) == null ? void 0 : K.call(k);
1814
- }), this.cobrowseToolbar.append(T), this.cobrowseHint = a("div", "ocw-cobrowse-hint", "🖍 Draw to point things out — visible to both sides"), e.append(this.cobrowseCanvas, this.cobrowseToolbar, this.cobrowseHint), this.bindCobrowsePointerEvents();
1810
+ const E = a("button", "ocw-cobrowse-clear", "Clear");
1811
+ E.addEventListener("click", () => {
1812
+ var v, A;
1813
+ return (A = (v = this.h).onAnnotateClear) == null ? void 0 : A.call(v);
1814
+ }), this.cobrowseToolbar.append(E), this.cobrowseHint = a("div", "ocw-cobrowse-hint", "🖍 Draw to point things out — visible to both sides"), e.append(this.cobrowseCanvas, this.cobrowseToolbar, this.cobrowseHint), this.bindCobrowsePointerEvents();
1815
1815
  }
1816
1816
  /** Returns the scroll container so history.ts can attach scroll listeners. */
1817
1817
  getScrollEl() {
@@ -1840,30 +1840,30 @@ class Mt {
1840
1840
  this.h.onTyping(!0), this.typingTimer && clearTimeout(this.typingTimer), this.typingTimer = setTimeout(() => this.h.onTyping(!1), 2e3);
1841
1841
  }
1842
1842
  render(e) {
1843
- var y, b, f;
1843
+ var f, m, x;
1844
1844
  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) {
1845
- const p = (y = this.cfg.subject) == null ? void 0 : y.ownerLabel;
1846
- p && (this.headerName.textContent = p);
1845
+ const h = (f = this.cfg.subject) == null ? void 0 : f.ownerLabel;
1846
+ h && (this.headerName.textContent = h);
1847
1847
  }
1848
1848
  this.chips.replaceChildren();
1849
1849
  const t = e.visibleActions();
1850
1850
  this.chips.style.display = t.length ? "flex" : "none";
1851
- for (const p of t) this.chips.append(this.chipEl(p));
1852
- const i = this.scroll.scrollHeight, n = this.scroll.scrollTop;
1851
+ for (const h of t) this.chips.append(this.chipEl(h));
1852
+ const n = this.scroll.scrollHeight, i = this.scroll.scrollTop;
1853
1853
  if (this.scroll.replaceChildren(), this.subjectCard.childNodes.length && this.scroll.append(this.subjectCard), e.hasMoreHistory) {
1854
- const p = a("div", "ocw-load-more");
1855
- p.textContent = "↑ Loading earlier messages…", p.style.pointerEvents = "none", this.scroll.append(p);
1854
+ const h = a("div", "ocw-load-more");
1855
+ h.textContent = "↑ Loading earlier messages…", h.style.pointerEvents = "none", this.scroll.append(h);
1856
1856
  }
1857
1857
  let o = 0;
1858
- for (const p of e.messages())
1859
- this.scroll.append(this.messageEl(p, e)), p.senderId !== this.me && p.seq > o && (o = p.seq);
1860
- n > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - i + n : this.scroll.scrollTop = this.scroll.scrollHeight, o > 0 && this.h.onReadUpTo(o);
1858
+ for (const h of e.messages())
1859
+ this.scroll.append(this.messageEl(h, e)), h.senderId !== this.me && h.seq > o && (o = h.seq);
1860
+ i > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - n + i : this.scroll.scrollTop = this.scroll.scrollHeight, o > 0 && this.h.onReadUpTo(o);
1861
1861
  const c = [...e.typing];
1862
1862
  this.typing.classList.toggle("active", c.length > 0);
1863
1863
  const l = this.typing.querySelector(".ocw-typing-bubble");
1864
- l && l.setAttribute("aria-label", c.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", (b = this.root.querySelector(".ocw-input")) == null || b.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (f = this.root.querySelector(".ocw-input")) == null || f.style.removeProperty("display"));
1865
- const x = ["resolved", "closed", "sold", "issued", "checked_out"];
1866
- this.h.onCsat && !this.csatSubmitted && x.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
1864
+ l && l.setAttribute("aria-label", c.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", (m = this.root.querySelector(".ocw-input")) == null || m.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (x = this.root.querySelector(".ocw-input")) == null || x.style.removeProperty("display"));
1865
+ const w = ["resolved", "closed", "sold", "issued", "checked_out"];
1866
+ 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");
1867
1867
  }
1868
1868
  setConnStatus(e) {
1869
1869
  if (e === "open") {
@@ -1875,29 +1875,29 @@ class Mt {
1875
1875
  buildOfflinePanel(e) {
1876
1876
  var l;
1877
1877
  this.offlinePanel.replaceChildren(), this.offlinePanel.append(a("div", "ocw-offline-icon", "🌙")), this.offlinePanel.append(a("div", "ocw-offline-title", ((l = this.cfg.i18n) == null ? void 0 : l.offline) ?? "We're offline right now")), this.offlinePanel.append(a("div", "ocw-offline-msg", e || "Leave your details and we'll get back to you soon."));
1878
- const t = a("div", "ocw-offline-form"), i = a("input", "ocw-offline-input");
1879
- i.placeholder = "Your name", i.type = "text";
1880
- const n = a("input", "ocw-offline-input");
1881
- n.placeholder = "Your email", n.type = "email";
1878
+ const t = a("div", "ocw-offline-form"), n = a("input", "ocw-offline-input");
1879
+ n.placeholder = "Your name", n.type = "text";
1880
+ const i = a("input", "ocw-offline-input");
1881
+ i.placeholder = "Your email", i.type = "email";
1882
1882
  const o = a("textarea", "ocw-offline-input");
1883
1883
  o.placeholder = "Your message", o.rows = 3;
1884
1884
  const c = a("button", "ocw-offline-submit", "Send message");
1885
1885
  c.addEventListener("click", () => {
1886
- !n.value.trim() || !o.value.trim() || (this.h.onSend(`[Offline form]
1887
- Name: ${i.value || "Anonymous"}
1888
- Email: ${n.value}
1886
+ !i.value.trim() || !o.value.trim() || (this.h.onSend(`[Offline form]
1887
+ Name: ${n.value || "Anonymous"}
1888
+ Email: ${i.value}
1889
1889
  Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-thanks", "✓ Message sent! We'll reply to your email.")));
1890
- }), t.append(i, n, o, c), this.offlinePanel.append(t);
1890
+ }), t.append(n, i, o, c), this.offlinePanel.append(t);
1891
1891
  }
1892
1892
  buildCsatPanel() {
1893
1893
  this.csatPanel.replaceChildren(), this.csatPanel.append(a("div", "ocw-csat-title", "How did we do?"));
1894
1894
  const e = a("div", "ocw-csat-stars"), t = [];
1895
- for (let i = 1; i <= 5; i++) {
1896
- const n = a("button", "ocw-csat-star", "★");
1897
- n.dataset.score = String(i), n.addEventListener("mouseenter", () => t.forEach((o, c) => o.classList.toggle("lit", c < i))), n.addEventListener("mouseleave", () => t.forEach((o) => o.classList.remove("lit"))), n.addEventListener("click", () => {
1895
+ for (let n = 1; n <= 5; n++) {
1896
+ const i = a("button", "ocw-csat-star", "★");
1897
+ i.dataset.score = String(n), i.addEventListener("mouseenter", () => t.forEach((o, c) => o.classList.toggle("lit", c < n))), i.addEventListener("mouseleave", () => t.forEach((o) => o.classList.remove("lit"))), i.addEventListener("click", () => {
1898
1898
  var o, c;
1899
- this.csatSubmitted = !0, this.csatPanel.replaceChildren(a("div", "ocw-csat-done", `Thanks for your ${i}★ rating!`)), (c = (o = this.h).onCsat) == null || c.call(o, i);
1900
- }), t.push(n), e.append(n);
1899
+ this.csatSubmitted = !0, this.csatPanel.replaceChildren(a("div", "ocw-csat-done", `Thanks for your ${n}★ rating!`)), (c = (o = this.h).onCsat) == null || c.call(o, n);
1900
+ }), t.push(i), e.append(i);
1901
1901
  }
1902
1902
  this.csatPanel.append(e);
1903
1903
  }
@@ -1915,9 +1915,9 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-t
1915
1915
  drawStroke(e) {
1916
1916
  const t = this.cobrowseCanvas.getContext("2d");
1917
1917
  if (!t || e.points.length < 2) return;
1918
- const i = this.cobrowseCanvas.width, n = this.cobrowseCanvas.height;
1919
- t.strokeStyle = e.color, t.lineWidth = Math.max(1, e.width * Math.min(i, n)), t.lineJoin = "round", t.lineCap = "round", t.beginPath(), t.moveTo(e.points[0].x * i, e.points[0].y * n);
1920
- for (const o of e.points.slice(1)) t.lineTo(o.x * i, o.y * n);
1918
+ const n = this.cobrowseCanvas.width, i = this.cobrowseCanvas.height;
1919
+ 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);
1920
+ for (const o of e.points.slice(1)) t.lineTo(o.x * n, o.y * i);
1921
1921
  t.stroke();
1922
1922
  }
1923
1923
  redrawCobrowse() {
@@ -1925,24 +1925,24 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-t
1925
1925
  const e = this.cobrowseCanvas.getContext("2d");
1926
1926
  if (e) {
1927
1927
  e.clearRect(0, 0, this.cobrowseCanvas.width, this.cobrowseCanvas.height);
1928
- for (const i of ((t = this.storeRef) == null ? void 0 : t.annotations) ?? []) this.drawStroke(i);
1928
+ for (const n of ((t = this.storeRef) == null ? void 0 : t.annotations) ?? []) this.drawStroke(n);
1929
1929
  }
1930
1930
  }
1931
1931
  bindCobrowsePointerEvents() {
1932
1932
  let e = !1, t = [];
1933
- const i = (c) => {
1934
- const l = this.cobrowseCanvas.getBoundingClientRect(), x = l.width > 0 ? (c.clientX - l.left) / l.width : 0, y = l.height > 0 ? (c.clientY - l.top) / l.height : 0;
1935
- return { x: Math.min(1, Math.max(0, x)), y: Math.min(1, Math.max(0, y)) };
1936
- }, n = 6e-3;
1933
+ const n = (c) => {
1934
+ const l = this.cobrowseCanvas.getBoundingClientRect(), w = l.width > 0 ? (c.clientX - l.left) / l.width : 0, f = l.height > 0 ? (c.clientY - l.top) / l.height : 0;
1935
+ return { x: Math.min(1, Math.max(0, w)), y: Math.min(1, Math.max(0, f)) };
1936
+ }, i = 6e-3;
1937
1937
  this.cobrowseCanvas.addEventListener("pointerdown", (c) => {
1938
- this.cobrowseActive && (e = !0, t = [i(c)], this.cobrowseCanvas.setPointerCapture(c.pointerId));
1938
+ this.cobrowseActive && (e = !0, t = [n(c)], this.cobrowseCanvas.setPointerCapture(c.pointerId));
1939
1939
  }), this.cobrowseCanvas.addEventListener("pointermove", (c) => {
1940
- e && (t.push(i(c)), this.redrawCobrowse(), this.drawStroke({ points: t, color: this.cobrowseColor, width: n }));
1940
+ e && (t.push(n(c)), this.redrawCobrowse(), this.drawStroke({ points: t, color: this.cobrowseColor, width: i }));
1941
1941
  });
1942
1942
  const o = (c) => {
1943
- var l, x;
1943
+ var l, w;
1944
1944
  if (e) {
1945
- e = !1, t.length > 1 && ((x = (l = this.h).onAnnotate) == null || x.call(l, { id: `an_${Date.now()}_${Math.random().toString(36).slice(2)}`, points: t, color: this.cobrowseColor, width: n })), t = [];
1945
+ e = !1, t.length > 1 && ((w = (l = this.h).onAnnotate) == null || w.call(l, { id: `an_${Date.now()}_${Math.random().toString(36).slice(2)}`, points: t, color: this.cobrowseColor, width: i })), t = [];
1946
1946
  try {
1947
1947
  this.cobrowseCanvas.releasePointerCapture(c.pointerId);
1948
1948
  } catch {
@@ -1953,201 +1953,201 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-t
1953
1953
  }
1954
1954
  buildSubjectCard(e) {
1955
1955
  if (this.subjectBuilt) return;
1956
- const t = e.subject, i = this.cfg.subject, n = (t == null ? void 0 : t.title) ?? (i == null ? void 0 : i.title);
1957
- if (!n) return;
1958
- this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(a("div", "ocw-subject-title", n)), i != null && i.subtitle && this.subjectCard.append(a("div", "ocw-subject-sub", i.subtitle));
1956
+ const t = e.subject, n = this.cfg.subject, i = (t == null ? void 0 : t.title) ?? (n == null ? void 0 : n.title);
1957
+ if (!i) return;
1958
+ this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(a("div", "ocw-subject-title", i)), n != null && n.subtitle && this.subjectCard.append(a("div", "ocw-subject-sub", n.subtitle));
1959
1959
  const o = a("div", "ocw-tags");
1960
- if (t) for (const [l, x] of Object.entries(t.fields)) o.append(a("span", "ocw-tag", `${l}: ${x}`));
1961
- else for (const l of (i == null ? void 0 : i.tags) ?? []) o.append(a("span", "ocw-tag", l));
1960
+ if (t) for (const [l, w] of Object.entries(t.fields)) o.append(a("span", "ocw-tag", `${l}: ${w}`));
1961
+ else for (const l of (n == null ? void 0 : n.tags) ?? []) o.append(a("span", "ocw-tag", l));
1962
1962
  o.childNodes.length && this.subjectCard.append(o);
1963
- const c = (t == null ? void 0 : t.state) ?? (i == null ? void 0 : i.status);
1963
+ const c = (t == null ? void 0 : t.state) ?? (n == null ? void 0 : n.status);
1964
1964
  c && (this.statusBadge.textContent = c, this.statusBadge.style.display = "inline-flex");
1965
1965
  }
1966
1966
  chipEl(e) {
1967
1967
  const t = a("button", "ocw-chip", e.icon ? `${e.icon} ${e.label}` : e.label);
1968
1968
  return t.dataset.actionId = e.id, t.addEventListener("click", async () => {
1969
- var i;
1970
- e.confirm && !await this.confirm(e.label) || ((i = e.input) != null && i.length ? this.openForm(e) : this.h.onInvoke(e.id));
1969
+ var n;
1970
+ e.confirm && !await this.confirm(e.label) || ((n = e.input) != null && n.length ? this.openForm(e) : this.h.onInvoke(e.id));
1971
1971
  }), t;
1972
1972
  }
1973
1973
  /** In-widget confirmation modal (replaces window.confirm). */
1974
1974
  confirm(e) {
1975
1975
  return new Promise((t) => {
1976
- const i = a("div", "ocw-modal"), n = a("div", "ocw-modal-card");
1977
- n.append(a("div", "ocw-modal-title", e)), n.append(a("div", "ocw-modal-body", `Confirm “${e}”?`));
1978
- const o = a("div", "ocw-modal-actions"), c = a("button", "ocw-modal-cancel", "Cancel"), l = a("button", "ocw-modal-ok", "Confirm"), x = (y) => {
1979
- i.remove(), t(y);
1976
+ const n = a("div", "ocw-modal"), i = a("div", "ocw-modal-card");
1977
+ i.append(a("div", "ocw-modal-title", e)), i.append(a("div", "ocw-modal-body", `Confirm “${e}”?`));
1978
+ const o = a("div", "ocw-modal-actions"), c = a("button", "ocw-modal-cancel", "Cancel"), l = a("button", "ocw-modal-ok", "Confirm"), w = (f) => {
1979
+ n.remove(), t(f);
1980
1980
  };
1981
- c.addEventListener("click", () => x(!1)), l.addEventListener("click", () => x(!0)), i.addEventListener("click", (y) => {
1982
- y.target === i && x(!1);
1983
- }), o.append(c, l), n.append(o), i.append(n), this.root.append(i), l.focus();
1981
+ c.addEventListener("click", () => w(!1)), l.addEventListener("click", () => w(!0)), n.addEventListener("click", (f) => {
1982
+ f.target === n && w(!1);
1983
+ }), o.append(c, l), i.append(o), n.append(i), this.root.append(n), l.focus();
1984
1984
  });
1985
1985
  }
1986
1986
  /** Inline form for a form-effect action: typed inputs (date picker, number,
1987
1987
  * text) rendered above the composer — no browser prompts. */
1988
1988
  openForm(e) {
1989
- var l, x;
1989
+ var l, w;
1990
1990
  this.formHost.replaceChildren();
1991
1991
  const t = a("div", "ocw-form");
1992
1992
  t.append(a("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
1993
- const i = /* @__PURE__ */ new Map();
1994
- for (const y of e.input ?? []) {
1995
- const b = a("label", "ocw-form-row");
1996
- if (b.append(a("span", "ocw-form-lbl", y.label)), y.type === "select" && ((l = y.options) != null && l.length)) {
1997
- const f = a("select", "ocw-form-input");
1998
- y.required || f.append(a("option", void 0, "— select —"));
1999
- for (const p of y.options) {
2000
- const h = a("option");
2001
- h.value = p, h.textContent = p, f.append(h);
1993
+ const n = /* @__PURE__ */ new Map();
1994
+ for (const f of e.input ?? []) {
1995
+ const m = a("label", "ocw-form-row");
1996
+ if (m.append(a("span", "ocw-form-lbl", f.label)), f.type === "select" && ((l = f.options) != null && l.length)) {
1997
+ const x = a("select", "ocw-form-input");
1998
+ f.required || x.append(a("option", void 0, "— select —"));
1999
+ for (const h of f.options) {
2000
+ const p = a("option");
2001
+ p.value = h, p.textContent = h, x.append(p);
2002
2002
  }
2003
- y.required && (f.required = !0), b.append(f), i.set(y.name, f);
2003
+ f.required && (x.required = !0), m.append(x), n.set(f.name, x);
2004
2004
  } else {
2005
- const f = a("input", "ocw-form-input");
2006
- f.type = y.type === "number" ? "number" : y.type === "date" ? "datetime-local" : "text", y.required && (f.required = !0), b.append(f), i.set(y.name, f);
2005
+ const x = a("input", "ocw-form-input");
2006
+ x.type = f.type === "number" ? "number" : f.type === "date" ? "datetime-local" : "text", f.required && (x.required = !0), m.append(x), n.set(f.name, x);
2007
2007
  }
2008
- t.append(b);
2008
+ t.append(m);
2009
2009
  }
2010
- const n = a("div", "ocw-form-actions"), o = a("button", "ocw-form-cancel", "Cancel"), c = a("button", "ocw-form-submit", "Send");
2010
+ const i = a("div", "ocw-form-actions"), o = a("button", "ocw-form-cancel", "Cancel"), c = a("button", "ocw-form-submit", "Send");
2011
2011
  o.addEventListener("click", () => this.formHost.replaceChildren()), c.addEventListener("click", () => {
2012
- const y = {};
2013
- for (const [b, f] of i) {
2014
- if (f.required && !f.value) {
2015
- f.style.borderColor = "#e5484d";
2012
+ const f = {};
2013
+ for (const [m, x] of n) {
2014
+ if (x.required && !x.value) {
2015
+ x.style.borderColor = "#e5484d";
2016
2016
  return;
2017
2017
  }
2018
- y[b] = f.type === "number" ? Number(f.value) : f.value;
2018
+ f[m] = x.type === "number" ? Number(x.value) : x.value;
2019
2019
  }
2020
- this.formHost.replaceChildren(), this.h.onInvoke(e.id, y);
2021
- }), n.append(o, c), t.append(n), this.formHost.append(t), (x = i.values().next().value) == null || x.focus();
2020
+ this.formHost.replaceChildren(), this.h.onInvoke(e.id, f);
2021
+ }), i.append(o, c), t.append(i), this.formHost.append(t), (w = n.values().next().value) == null || w.focus();
2022
2022
  }
2023
2023
  messageEl(e, t) {
2024
- var f;
2024
+ var x;
2025
2025
  if (e.senderRole === "system") {
2026
- const p = a("div", "ocw-sys");
2027
- return p.textContent = e.deletedAt ? "message deleted" : Z(e.content), p;
2026
+ const h = a("div", "ocw-sys");
2027
+ return h.textContent = e.deletedAt ? "message deleted" : Q(e.content), h;
2028
2028
  }
2029
- const i = e.senderId === this.me, n = !!e.internal, o = a("div", `ocw-row ${n ? "ocw-note mine" : i ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
2030
- !i && !n && o.append(a("div", "ocw-dot", e.senderRole === "bot" ? "🤖" : "🧑"));
2029
+ const n = e.senderId === this.me, i = !!e.internal, o = a("div", `ocw-row ${i ? "ocw-note mine" : n ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
2030
+ !n && !i && o.append(a("div", "ocw-dot", e.senderRole === "bot" ? "🤖" : "🧑"));
2031
2031
  const c = a("div"), l = a("div", "ocw-bubble-wrap");
2032
2032
  if (e.replyToId) {
2033
- const p = a("div", "ocw-reply-to", "↩ replying to a message");
2034
- p.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", c.append(p);
2033
+ const h = a("div", "ocw-reply-to", "↩ replying to a message");
2034
+ h.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", c.append(h);
2035
2035
  }
2036
- const x = a("div", "ocw-bubble");
2037
- let y = null;
2038
- if (e.deletedAt) x.append(a("span", "ocw-deleted", "message deleted"));
2036
+ const w = a("div", "ocw-bubble");
2037
+ let f = null;
2038
+ if (e.deletedAt) w.append(a("span", "ocw-deleted", "message deleted"));
2039
2039
  else if (e.content.kind === "attachment") {
2040
- const p = e.content;
2041
- if ((f = p.mime) != null && f.startsWith("image/")) {
2042
- const h = document.createElement("img");
2043
- h.src = p.url, h.alt = p.name ?? "image", h.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", h.addEventListener("click", () => window.open(p.url, "_blank")), x.append(h);
2040
+ const h = e.content;
2041
+ if ((x = h.mime) != null && x.startsWith("image/")) {
2042
+ const p = document.createElement("img");
2043
+ p.src = h.url, p.alt = h.name ?? "image", p.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", p.addEventListener("click", () => window.open(h.url, "_blank")), w.append(p);
2044
2044
  } else {
2045
- const h = document.createElement("a");
2046
- h.href = p.url, h.target = "_blank", h.rel = "noopener", h.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", h.append(a("span", void 0, "📄"), a("span", void 0, p.name ?? "file")), x.append(h);
2045
+ const p = document.createElement("a");
2046
+ p.href = h.url, p.target = "_blank", p.rel = "noopener", p.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", p.append(a("span", void 0, "📄"), a("span", void 0, h.name ?? "file")), w.append(p);
2047
2047
  }
2048
2048
  } else if (e.content.kind === "appointment") {
2049
- const p = e.content, h = a("div", "ocw-appt");
2050
- h.append(a("div", "ocw-appt-title", `📅 ${p.title}`)), h.append(a("div", "ocw-appt-time", new Date(p.startIso).toLocaleString() + " – " + new Date(p.endIso).toLocaleTimeString())), p.location && h.append(a("div", "ocw-appt-loc", `📍 ${p.location}`)), p.description && h.append(a("div", "ocw-appt-desc", p.description));
2051
- const T = a("div", "ocw-appt-links"), m = document.createElement("a");
2052
- m.href = p.googleUrl, m.target = "_blank", m.rel = "noopener", m.className = "ocw-appt-btn", m.textContent = "📅 Add to Google Calendar";
2053
- const w = document.createElement("a");
2054
- w.href = p.icalUrl, w.download = `${p.title}.ics`, w.className = "ocw-appt-btn ocw-appt-btn-sec", w.textContent = "🍎 Apple / iCal", T.append(m, w), h.append(T), x.append(h);
2049
+ const h = e.content, p = a("div", "ocw-appt");
2050
+ p.append(a("div", "ocw-appt-title", `📅 ${h.title}`)), p.append(a("div", "ocw-appt-time", new Date(h.startIso).toLocaleString() + " – " + new Date(h.endIso).toLocaleTimeString())), h.location && p.append(a("div", "ocw-appt-loc", `📍 ${h.location}`)), h.description && p.append(a("div", "ocw-appt-desc", h.description));
2051
+ const E = a("div", "ocw-appt-links"), y = document.createElement("a");
2052
+ y.href = h.googleUrl, y.target = "_blank", y.rel = "noopener", y.className = "ocw-appt-btn", y.textContent = "📅 Add to Google Calendar";
2053
+ const g = document.createElement("a");
2054
+ g.href = h.icalUrl, g.download = `${h.title}.ics`, g.className = "ocw-appt-btn ocw-appt-btn-sec", g.textContent = "🍎 Apple / iCal", E.append(y, g), p.append(E), w.append(p);
2055
2055
  } else
2056
- y = document.createTextNode(Z(e.content)), x.append(y), e.editedAt && x.append(a("span", "ocw-edited", "(edited)"));
2057
- if (l.append(x), !i && !n && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && y) {
2058
- const p = e.content.text;
2059
- if (p.trim()) {
2060
- const h = a("button", "ocw-translate-btn", "🌐");
2061
- h.type = "button", h.title = "Translate", h.addEventListener("click", (T) => {
2062
- if (T.stopPropagation(), this.showingTranslation.has(e.id)) {
2063
- this.showingTranslation.delete(e.id), y.textContent = p, h.textContent = "🌐", h.title = "Translate";
2056
+ f = document.createTextNode(Q(e.content)), w.append(f), e.editedAt && w.append(a("span", "ocw-edited", "(edited)"));
2057
+ if (l.append(w), !n && !i && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && f) {
2058
+ const h = e.content.text;
2059
+ if (h.trim()) {
2060
+ const p = a("button", "ocw-translate-btn", "🌐");
2061
+ p.type = "button", p.title = "Translate", p.addEventListener("click", (E) => {
2062
+ if (E.stopPropagation(), this.showingTranslation.has(e.id)) {
2063
+ this.showingTranslation.delete(e.id), f.textContent = h, p.textContent = "🌐", p.title = "Translate";
2064
2064
  return;
2065
2065
  }
2066
- const m = this.translationCache.get(e.id);
2067
- if (m !== void 0) {
2068
- this.showingTranslation.add(e.id), y.textContent = m, h.textContent = "↩", h.title = "Show original";
2066
+ const y = this.translationCache.get(e.id);
2067
+ if (y !== void 0) {
2068
+ this.showingTranslation.add(e.id), f.textContent = y, p.textContent = "↩", p.title = "Show original";
2069
2069
  return;
2070
2070
  }
2071
- h.textContent = "⏳", this.h.onTranslate(p).then((w) => {
2072
- if (w === null) {
2073
- h.textContent = "⚠️", h.title = "Translation unavailable", setTimeout(() => {
2074
- h.textContent = "🌐", h.title = "Translate";
2071
+ p.textContent = "⏳", this.h.onTranslate(h).then((g) => {
2072
+ if (g === null) {
2073
+ p.textContent = "⚠️", p.title = "Translation unavailable", setTimeout(() => {
2074
+ p.textContent = "🌐", p.title = "Translate";
2075
2075
  }, 1500);
2076
2076
  return;
2077
2077
  }
2078
- this.translationCache.set(e.id, w), this.showingTranslation.add(e.id), y.textContent = w, h.textContent = "↩", h.title = "Show original";
2078
+ this.translationCache.set(e.id, g), this.showingTranslation.add(e.id), f.textContent = g, p.textContent = "↩", p.title = "Show original";
2079
2079
  });
2080
- }), l.append(h);
2080
+ }), l.append(p);
2081
2081
  }
2082
2082
  }
2083
- if (i && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
2084
- const p = a("div", "ocw-msg-menu");
2083
+ if (n && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
2084
+ const h = a("div", "ocw-msg-menu");
2085
2085
  if (this.h.onEdit) {
2086
- const h = a("button", void 0, "✏️");
2087
- h.title = "Edit", h.addEventListener("click", (T) => {
2088
- T.stopPropagation();
2089
- const m = Z(e.content), w = document.createElement("textarea");
2090
- w.value = m, w.rows = Math.min(4, Math.ceil(m.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";
2091
- const v = a("button", "ocw-form-submit", "Save");
2092
- v.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
2093
- const B = a("button", "ocw-form-cancel", "Cancel");
2094
- B.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
2086
+ const p = a("button", void 0, "✏️");
2087
+ p.title = "Edit", p.addEventListener("click", (E) => {
2088
+ E.stopPropagation();
2089
+ const y = Q(e.content), g = document.createElement("textarea");
2090
+ g.value = y, g.rows = Math.min(4, Math.ceil(y.length / 40) + 1), g.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";
2091
+ const C = a("button", "ocw-form-submit", "Save");
2092
+ C.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
2093
+ const T = a("button", "ocw-form-cancel", "Cancel");
2094
+ T.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
2095
2095
  const U = a("div");
2096
- U.style.cssText = "display:flex;gap:6px;justify-content:flex-end", U.append(B, v);
2097
- const P = a("div");
2098
- P.append(w, U), x.replaceChildren(P), w.focus(), w.select();
2099
- const A = () => x.replaceChildren(y ?? document.createTextNode(m));
2100
- B.addEventListener("click", A), v.addEventListener("click", () => {
2101
- const C = w.value.trim();
2102
- C && C !== m && this.h.onEdit(e.id, C), A();
2103
- }), w.addEventListener("keydown", (C) => {
2104
- C.key === "Enter" && !C.shiftKey && (C.preventDefault(), v.click()), C.key === "Escape" && A();
2096
+ U.style.cssText = "display:flex;gap:6px;justify-content:flex-end", U.append(T, C);
2097
+ const B = a("div");
2098
+ B.append(g, U), w.replaceChildren(B), g.focus(), g.select();
2099
+ const K = () => w.replaceChildren(f ?? document.createTextNode(y));
2100
+ T.addEventListener("click", K), C.addEventListener("click", () => {
2101
+ const P = g.value.trim();
2102
+ P && P !== y && this.h.onEdit(e.id, P), K();
2103
+ }), g.addEventListener("keydown", (P) => {
2104
+ P.key === "Enter" && !P.shiftKey && (P.preventDefault(), C.click()), P.key === "Escape" && K();
2105
2105
  });
2106
- }), p.append(h);
2106
+ }), h.append(p);
2107
2107
  }
2108
2108
  if (this.h.onDelete) {
2109
- const h = a("button", "del", "🗑");
2110
- h.title = "Delete", h.addEventListener("click", (T) => {
2111
- T.stopPropagation(), this.h.onDelete(e.id);
2112
- }), p.append(h);
2109
+ const p = a("button", "del", "🗑");
2110
+ p.title = "Delete", p.addEventListener("click", (E) => {
2111
+ E.stopPropagation(), this.h.onDelete(e.id);
2112
+ }), h.append(p);
2113
2113
  }
2114
- l.append(p);
2114
+ l.append(h);
2115
2115
  }
2116
2116
  if (c.append(l), this.h.onReact && !e.deletedAt && e.seq > 0) {
2117
- const p = a("div", "ocw-react-wrap"), h = a("div", "ocw-react");
2117
+ const h = a("div", "ocw-react-wrap"), p = a("div", "ocw-react");
2118
2118
  if (e.reactions && Object.keys(e.reactions).length)
2119
- for (const [w, v] of Object.entries(e.reactions)) {
2120
- const B = a("button", `ocw-react-pill${v.includes(this.me) ? " mine" : ""}`, `${w} ${v.length}`);
2121
- B.addEventListener("click", () => {
2122
- var U, P;
2123
- return (P = (U = this.h).onReact) == null ? void 0 : P.call(U, e.id, w, v.includes(this.me));
2124
- }), h.append(B);
2119
+ for (const [g, C] of Object.entries(e.reactions)) {
2120
+ const T = a("button", `ocw-react-pill${C.includes(this.me) ? " mine" : ""}`, `${g} ${C.length}`);
2121
+ T.addEventListener("click", () => {
2122
+ var U, B;
2123
+ return (B = (U = this.h).onReact) == null ? void 0 : B.call(U, e.id, g, C.includes(this.me));
2124
+ }), p.append(T);
2125
2125
  }
2126
- const T = a("button", "ocw-react-btn", "+"), m = a("div", "ocw-react-picker");
2127
- for (const w of Kt) {
2128
- const v = a("button", void 0, w);
2129
- v.addEventListener("click", (B) => {
2130
- var P, A, C, H;
2131
- B.stopPropagation();
2132
- const U = (A = (P = e.reactions) == null ? void 0 : P[w]) == null ? void 0 : A.includes(this.me);
2133
- (H = (C = this.h).onReact) == null || H.call(C, e.id, w, !!U), m.style.display = "none";
2134
- }), m.append(v);
2126
+ const E = a("button", "ocw-react-btn", "+"), y = a("div", "ocw-react-picker");
2127
+ for (const g of At) {
2128
+ const C = a("button", void 0, g);
2129
+ C.addEventListener("click", (T) => {
2130
+ var B, K, P, H;
2131
+ T.stopPropagation();
2132
+ const U = (K = (B = e.reactions) == null ? void 0 : B[g]) == null ? void 0 : K.includes(this.me);
2133
+ (H = (P = this.h).onReact) == null || H.call(P, e.id, g, !!U), y.style.display = "none";
2134
+ }), y.append(C);
2135
2135
  }
2136
- m.style.display = "none", T.addEventListener("click", (w) => {
2137
- w.stopPropagation(), m.style.display = m.style.display === "none" ? "flex" : "none";
2136
+ y.style.display = "none", E.addEventListener("click", (g) => {
2137
+ g.stopPropagation(), y.style.display = y.style.display === "none" ? "flex" : "none";
2138
2138
  }), document.addEventListener("click", () => {
2139
- m.style.display = "none";
2140
- }, { once: !0 }), h.append(T), p.append(h, m), c.append(p);
2141
- } else e.reactions && Object.keys(e.reactions).length && c.append(a("div", "ocw-react", Object.entries(e.reactions).map(([p, h]) => `${p}${h.length}`).join(" ")));
2142
- const b = a("div", "ocw-time ocw-meta", Lt(e.ts));
2143
- if (i && e.status) {
2144
- const p = a("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Dt(e.status));
2145
- b.append(p);
2139
+ y.style.display = "none";
2140
+ }, { once: !0 }), p.append(E), h.append(p, y), c.append(h);
2141
+ } else e.reactions && Object.keys(e.reactions).length && c.append(a("div", "ocw-react", Object.entries(e.reactions).map(([h, p]) => `${h}${p.length}`).join(" ")));
2142
+ const m = a("div", "ocw-time ocw-meta", Mt(e.ts));
2143
+ if (n && e.status) {
2144
+ const h = a("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, _t(e.status));
2145
+ m.append(h);
2146
2146
  }
2147
- return i && e.seq > 0 && t.lastReadByOthers >= e.seq && b.append(a("span", "ocw-seen", " · Seen")), c.append(b), o.append(c), o;
2147
+ return n && e.seq > 0 && t.lastReadByOthers >= e.seq && m.append(a("span", "ocw-seen", " · Seen")), c.append(m), o.append(c), o;
2148
2148
  }
2149
2149
  }
2150
- function Dt(s) {
2150
+ function _t(s) {
2151
2151
  switch (s) {
2152
2152
  case "read":
2153
2153
  return "✓✓";
@@ -2159,20 +2159,26 @@ function Dt(s) {
2159
2159
  return "🕓";
2160
2160
  }
2161
2161
  }
2162
- function Rt(s) {
2163
- var oe, re, ae, ce;
2164
- const e = s.token ?? Ue();
2165
- let t = new wt(e);
2166
- const i = s.subjectId ? `${e}::${s.subjectId}` : e, n = new bt(i);
2167
- let o, c = !1, l = null, x = null, y = null;
2162
+ const R = /* @__PURE__ */ new WeakMap();
2163
+ function Ft(s) {
2164
+ var e;
2165
+ (e = R.get(s)) == null || e.close(), R.delete(s);
2166
+ }
2167
+ function jt(s) {
2168
+ var ae, ce, de, le;
2169
+ R.has(s.el) && (R.get(s.el).close(), R.delete(s.el));
2170
+ const e = s.token ?? Pe();
2171
+ let t = new xt(e);
2172
+ const n = s.subjectId ? `${e}::${s.subjectId}` : e, i = new mt(n);
2173
+ let o, c = !1, l = null, w = null;
2168
2174
  !s.launcher && !s.el.style.height && s.el.clientHeight === 0 && (s.el.style.width = s.el.style.width || "100%", s.el.style.height = "600px");
2169
- for (const d of n.load()) t.addOptimistic(d.clientMsgId, d.content);
2170
- let b = null, f = null, p = 0, h = !s.launcher;
2175
+ for (const d of i.load()) t.addOptimistic(d.clientMsgId, d.content);
2176
+ let f = null, m = null, x = 0, h = !s.launcher;
2171
2177
  if (s.launcher) {
2172
2178
  const u = (s.position ?? "bottom-right").includes("right");
2173
- b = document.createElement("div"), b.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`;
2174
- const g = document.createElement("div"), E = typeof window < "u" ? window.matchMedia("(max-width: 479px)") : null, M = (D) => {
2175
- g.style.cssText = D ? [
2179
+ f = document.createElement("div"), f.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`;
2180
+ const b = document.createElement("div"), I = typeof window < "u" ? window.matchMedia("(max-width: 479px)") : null, M = (D) => {
2181
+ b.style.cssText = D ? [
2176
2182
  "position:fixed",
2177
2183
  "inset:0",
2178
2184
  "width:100%",
@@ -2201,117 +2207,117 @@ function Rt(s) {
2201
2207
  "transform:scale(.95)"
2202
2208
  ].join(";");
2203
2209
  };
2204
- M((E == null ? void 0 : E.matches) ?? !1), E == null || E.addEventListener("change", (D) => M(D.matches)), x = E, y = M, s.el.style.cssText = "width:100%;height:100%;overflow:hidden", g.append(s.el);
2205
- const I = document.createElement("button");
2206
- I.style.cssText = [
2210
+ M((I == null ? void 0 : I.matches) ?? !1), I == null || I.addEventListener("change", (D) => M(D.matches)), l = I, w = M, s.el.style.cssText = "width:100%;height:100%;overflow:hidden", b.append(s.el);
2211
+ const S = document.createElement("button");
2212
+ S.style.cssText = [
2207
2213
  "width:56px;height:56px;border-radius:50%",
2208
2214
  `background:${s.accent ?? "#4F63F5"}`,
2209
2215
  "color:#fff;border:none;font-size:24px;cursor:pointer",
2210
2216
  "box-shadow:0 4px 16px rgba(0,0,0,.25)",
2211
2217
  "position:relative;flex:none",
2212
2218
  "transition:transform .15s"
2213
- ].join(";"), I.textContent = "💬", I.onmouseenter = () => {
2214
- I.style.transform = "scale(1.08)";
2215
- }, I.onmouseleave = () => {
2216
- I.style.transform = "scale(1)";
2217
- }, f = document.createElement("span"), f.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", I.append(f), b.append(g, I), document.body.append(b);
2218
- const N = (D) => {
2219
- D ? (g.style.display = "flex", requestAnimationFrame(() => {
2220
- g.style.opacity = "1", g.style.transform = "scale(1)";
2221
- })) : (g.style.opacity = "0", g.style.transform = "scale(.95)", setTimeout(() => {
2222
- h || (g.style.display = "none");
2219
+ ].join(";"), S.textContent = "💬", S.onmouseenter = () => {
2220
+ S.style.transform = "scale(1.08)";
2221
+ }, S.onmouseleave = () => {
2222
+ S.style.transform = "scale(1)";
2223
+ }, m = document.createElement("span"), m.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", S.append(m), f.append(b, S), document.body.append(f);
2224
+ const V = (D) => {
2225
+ D ? (b.style.display = "flex", requestAnimationFrame(() => {
2226
+ b.style.opacity = "1", b.style.transform = "scale(1)";
2227
+ })) : (b.style.opacity = "0", b.style.transform = "scale(.95)", setTimeout(() => {
2228
+ h || (b.style.display = "none");
2223
2229
  }, 180));
2224
2230
  };
2225
- I.addEventListener("click", () => {
2226
- h = !h, N(h), I.textContent = h ? "✕" : "💬", I.append(f), h && (p = 0, f && (f.style.display = "none"));
2231
+ S.addEventListener("click", () => {
2232
+ h = !h, V(h), S.textContent = h ? "✕" : "💬", S.append(m), h && (x = 0, m && (m.style.display = "none"));
2227
2233
  }), document.addEventListener("keydown", (D) => {
2228
- D.key === "Escape" && h && (h = !1, N(!1), I.textContent = "💬", I.append(f));
2234
+ D.key === "Escape" && h && (h = !1, V(!1), S.textContent = "💬", S.append(m));
2229
2235
  });
2230
2236
  }
2231
- const T = () => {
2232
- h || (p++, f && (f.textContent = String(p), f.style.display = "flex"));
2233
- }, m = () => {
2237
+ const p = () => {
2238
+ h || (x++, m && (m.textContent = String(x), m.style.display = "flex"));
2239
+ }, E = () => {
2234
2240
  try {
2235
- const d = new AudioContext(), u = d.createOscillator(), g = d.createGain();
2236
- u.connect(g), g.connect(d.destination), u.frequency.setValueAtTime(880, d.currentTime), u.frequency.exponentialRampToValueAtTime(440, d.currentTime + 0.15), g.gain.setValueAtTime(0.3, d.currentTime), g.gain.exponentialRampToValueAtTime(1e-3, d.currentTime + 0.3), u.start(), u.stop(d.currentTime + 0.3);
2241
+ const d = new AudioContext(), u = d.createOscillator(), b = d.createGain();
2242
+ u.connect(b), b.connect(d.destination), u.frequency.setValueAtTime(880, d.currentTime), u.frequency.exponentialRampToValueAtTime(440, d.currentTime + 0.15), b.gain.setValueAtTime(0.3, d.currentTime), b.gain.exponentialRampToValueAtTime(1e-3, d.currentTime + 0.3), u.start(), u.stop(d.currentTime + 0.3);
2237
2243
  } catch {
2238
2244
  }
2239
2245
  };
2240
- let w;
2241
- const v = new Pt(`ocw-e2e-${s.profileId}`);
2246
+ let y;
2247
+ const g = new Bt(`ocw-e2e-${s.profileId}`);
2248
+ let C = !1;
2249
+ const T = [], U = [];
2242
2250
  let B = !1;
2243
- const U = [], P = [];
2244
- let A = !1;
2245
- const C = (d, u) => {
2246
- v.sealText(u).then((g) => {
2247
- o && w.send({ type: "send", conversationId: o, clientMsgId: d, content: g });
2251
+ const K = (d, u) => {
2252
+ g.sealText(u).then((b) => {
2253
+ o && y.send({ type: "send", conversationId: o, clientMsgId: d, content: b });
2248
2254
  });
2249
- }, H = (d, u, g) => {
2250
- v.sealText(u, g).then((E) => {
2251
- o && w.send({ type: "send", conversationId: o, clientMsgId: d, content: E });
2255
+ }, P = (d, u, b) => {
2256
+ g.sealText(u, b).then((I) => {
2257
+ o && y.send({ type: "send", conversationId: o, clientMsgId: d, content: I });
2252
2258
  });
2253
- }, k = () => {
2259
+ }, H = () => {
2260
+ for (; T.length; ) {
2261
+ const d = T.shift();
2262
+ K(d.clientMsgId, d.text);
2263
+ }
2254
2264
  for (; U.length; ) {
2255
2265
  const d = U.shift();
2256
- C(d.clientMsgId, d.text);
2257
- }
2258
- for (; P.length; ) {
2259
- const d = P.shift();
2260
- C(d.clientMsgId, d.text);
2266
+ K(d.clientMsgId, d.text);
2261
2267
  }
2262
- }, K = (d) => {
2263
- w.send({ type: "fetchPrekey", targetUserId: d });
2264
- }, J = s.i18n ?? {}, me = ["ar", "he", "fa", "ur"], ve = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
2265
- me.includes(ve) && !s.el.dir && (s.el.dir = "rtl", s.el.style.fontFamily = s.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
2266
- const L = new Mt(s.el, e, {
2268
+ }, v = (d) => {
2269
+ y.send({ type: "fetchPrekey", targetUserId: d });
2270
+ }, A = s.i18n ?? {}, G = ["ar", "he", "fa", "ur"], ke = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
2271
+ G.includes(ke) && !s.el.dir && (s.el.dir = "rtl", s.el.style.fontFamily = s.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
2272
+ const L = new Dt(s.el, e, {
2267
2273
  onSend(d) {
2268
2274
  if (!o) return;
2269
2275
  const u = `cm_${Math.random().toString(36).slice(2)}`;
2270
- t.addOptimistic(u, { kind: "text", text: d }), L.render(t), t.e2e ? v.ready ? C(u, d) : A ? P.push({ clientMsgId: u, text: d }) : (U.push({ clientMsgId: u, text: d }), t.assignedAgentId && K(t.assignedAgentId)) : (n.add({ clientMsgId: u, content: { kind: "text", text: d }, ts: Date.now() }), w.send({ type: "send", conversationId: o, clientMsgId: u, content: { kind: "text", text: d } }));
2276
+ t.addOptimistic(u, { kind: "text", text: d }), L.render(t), t.e2e ? g.ready ? K(u, d) : B ? U.push({ clientMsgId: u, text: d }) : (T.push({ clientMsgId: u, text: d }), t.assignedAgentId && v(t.assignedAgentId)) : (i.add({ clientMsgId: u, content: { kind: "text", text: d }, ts: Date.now() }), y.send({ type: "send", conversationId: o, clientMsgId: u, content: { kind: "text", text: d } }));
2271
2277
  },
2272
2278
  async onAttach(d) {
2273
2279
  if (!o) return;
2274
- const E = `${s.url.replace(/^ws/, "http").replace(/\/ws$/, "")}/upload?name=${encodeURIComponent(d.name)}`, M = `cm_${Math.random().toString(36).slice(2)}`;
2280
+ const I = `${s.url.replace(/^ws/, "http").replace(/\/ws$/, "")}/upload?name=${encodeURIComponent(d.name)}`, M = `cm_${Math.random().toString(36).slice(2)}`;
2275
2281
  t.addOptimistic(M, { kind: "text", text: `📎 Uploading ${d.name}…` }), L.render(t);
2276
2282
  try {
2277
- const I = await fetch(E, {
2283
+ const S = await fetch(I, {
2278
2284
  method: "POST",
2279
2285
  headers: { "content-type": d.type, ...s.token ? { authorization: `Bearer ${s.token}` } : {} },
2280
2286
  body: d
2281
2287
  });
2282
- if (!I.ok) throw new Error(`Upload failed: ${I.status}`);
2283
- const { url: N, name: D, mime: Ie, size: Ce } = await I.json();
2284
- w.send({ type: "send", conversationId: o, clientMsgId: M, content: { kind: "attachment", url: N, name: D, mime: Ie, size: Ce } });
2285
- } catch (I) {
2286
- t.addOptimistic(M, { kind: "text", text: `⚠️ Upload failed: ${I.message}` }), L.render(t);
2288
+ if (!S.ok) throw new Error(`Upload failed: ${S.status}`);
2289
+ const { url: V, name: D, mime: Ce, size: Ee } = await S.json();
2290
+ y.send({ type: "send", conversationId: o, clientMsgId: M, content: { kind: "attachment", url: V, name: D, mime: Ce, size: Ee } });
2291
+ } catch (S) {
2292
+ t.addOptimistic(M, { kind: "text", text: `⚠️ Upload failed: ${S.message}` }), L.render(t);
2287
2293
  }
2288
2294
  },
2289
2295
  onInvoke(d, u) {
2290
- o && w.send({ type: "invoke", conversationId: o, actionId: d, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...u ? { inputs: u } : {} });
2296
+ o && y.send({ type: "invoke", conversationId: o, actionId: d, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...u ? { inputs: u } : {} });
2291
2297
  },
2292
2298
  onTyping(d) {
2293
- o && w.send({ type: "typing", conversationId: o, isTyping: d });
2299
+ o && y.send({ type: "typing", conversationId: o, isTyping: d });
2294
2300
  },
2295
2301
  onReadUpTo(d) {
2296
- o && w.send({ type: "read", conversationId: o, seq: d });
2302
+ o && y.send({ type: "read", conversationId: o, seq: d });
2297
2303
  },
2298
2304
  onLoadMore() {
2299
2305
  if (!o || !t.e2e) return;
2300
2306
  const d = t.messages()[0];
2301
- d && w.send({ type: "history", conversationId: o, beforeSeq: d.seq, limit: 20 });
2307
+ d && y.send({ type: "history", conversationId: o, beforeSeq: d.seq, limit: 20 });
2302
2308
  },
2303
2309
  onEdit(d, u) {
2304
- o && w.send({ type: "edit", conversationId: o, messageId: d, content: { kind: "text", text: u } });
2310
+ o && y.send({ type: "edit", conversationId: o, messageId: d, content: { kind: "text", text: u } });
2305
2311
  },
2306
2312
  onDelete(d) {
2307
- o && w.send({ type: "delete", conversationId: o, messageId: d });
2313
+ o && y.send({ type: "delete", conversationId: o, messageId: d });
2308
2314
  },
2309
- onReact(d, u, g) {
2310
- o && w.send({ type: "react", conversationId: o, messageId: d, emoji: u, remove: g });
2315
+ onReact(d, u, b) {
2316
+ o && y.send({ type: "react", conversationId: o, messageId: d, emoji: u, remove: b });
2311
2317
  },
2312
2318
  onCsat(d) {
2313
2319
  if (!o) return;
2314
- const u = Be(s.url);
2320
+ const u = Ke(s.url);
2315
2321
  fetch(`${u}/conversations/${o}/csat`, {
2316
2322
  method: "POST",
2317
2323
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${e}` },
@@ -2320,23 +2326,23 @@ function Rt(s) {
2320
2326
  });
2321
2327
  },
2322
2328
  onAnnotate(d) {
2323
- o && w.send({ type: "annotate", conversationId: o, stroke: d });
2329
+ o && y.send({ type: "annotate", conversationId: o, stroke: d });
2324
2330
  },
2325
2331
  onAnnotateClear() {
2326
- o && w.send({ type: "annotate_clear", conversationId: o });
2332
+ o && y.send({ type: "annotate_clear", conversationId: o });
2327
2333
  },
2328
2334
  ...s.translateLang ? {
2329
2335
  async onTranslate(d) {
2330
2336
  const u = s.url.replace(/^ws/, "http").replace(/\/+$/, "");
2331
2337
  try {
2332
- const g = await fetch(`${u}/translate`, {
2338
+ const b = await fetch(`${u}/translate`, {
2333
2339
  method: "POST",
2334
2340
  headers: { "content-type": "application/json", authorization: `Bearer ${e}` },
2335
2341
  body: JSON.stringify({ text: d, targetLang: s.translateLang })
2336
2342
  });
2337
- if (!g.ok) return null;
2338
- const { translated: E } = await g.json();
2339
- return E;
2343
+ if (!b.ok) return null;
2344
+ const { translated: I } = await b.json();
2345
+ return I;
2340
2346
  } catch {
2341
2347
  return null;
2342
2348
  }
@@ -2346,9 +2352,9 @@ function Rt(s) {
2346
2352
  ...s.subject ? { subject: s.subject } : {},
2347
2353
  ...s.quickReplies ? { quickReplies: s.quickReplies } : {},
2348
2354
  ...s.accent ? { accent: s.accent } : {},
2349
- ...(oe = s.user) != null && oe.name || (re = s.user) != null && re.avatar ? { userInfo: { ...s.user.name ? { name: s.user.name } : {}, ...s.user.avatar ? { avatar: s.user.avatar } : {} } } : {},
2350
- i18n: J
2351
- }), ke = {
2355
+ ...(ae = s.user) != null && ae.name || (ce = s.user) != null && ce.avatar ? { userInfo: { ...s.user.name ? { name: s.user.name } : {}, ...s.user.avatar ? { avatar: s.user.avatar } : {} } } : {},
2356
+ i18n: A
2357
+ }), Se = {
2352
2358
  type: "open",
2353
2359
  profileId: s.profileId,
2354
2360
  ...s.subjectId ? { subjectId: s.subjectId } : {},
@@ -2356,21 +2362,21 @@ function Rt(s) {
2356
2362
  ...typeof document < "u" && document.title ? { pageTitle: document.title } : {},
2357
2363
  // Pass subject display info so the server can persist it to the Subject record.
2358
2364
  // This is how listingTitle and listingMeta get saved without a separate API call.
2359
- ...(ae = s.subject) != null && ae.title ? { subjectTitle: s.subject.title } : {},
2360
- ...(ce = s.subject) != null && ce.subtitle ? { subjectMeta: s.subject.subtitle } : {}
2361
- }, Se = (d) => {
2365
+ ...(de = s.subject) != null && de.title ? { subjectTitle: s.subject.title } : {},
2366
+ ...(le = s.subject) != null && le.subtitle ? { subjectMeta: s.subject.subtitle } : {}
2367
+ }, Ie = (d) => {
2362
2368
  const u = s.user;
2363
2369
  if (!u || !u.name && !u.email && !u.avatar && !u.meta) return;
2364
- const g = [];
2365
- if (u.name && g.push(`Name: ${u.name}`), u.email && g.push(`Email: ${u.email}`), u.avatar && g.push(`Avatar: ${u.avatar}`), u.meta) for (const [E, M] of Object.entries(u.meta)) g.push(`${E}: ${M}`);
2366
- w.send({ type: "note", conversationId: d, clientMsgId: `ui_${Date.now()}`, text: `[User info]
2367
- ${g.join(`
2370
+ const b = [];
2371
+ if (u.name && b.push(`Name: ${u.name}`), u.email && b.push(`Email: ${u.email}`), u.avatar && b.push(`Avatar: ${u.avatar}`), u.meta) for (const [I, M] of Object.entries(u.meta)) b.push(`${I}: ${M}`);
2372
+ y.send({ type: "note", conversationId: d, clientMsgId: `ui_${Date.now()}`, text: `[User info]
2373
+ ${b.join(`
2368
2374
  `)}` });
2369
2375
  };
2370
- return w = new xt({
2376
+ y = new yt({
2371
2377
  url: s.url,
2372
2378
  token: e,
2373
- open: ke,
2379
+ open: Se,
2374
2380
  getCursor: () => t.highestSeq(),
2375
2381
  onStatusChange: (d) => L.setConnStatus(d),
2376
2382
  onFrame(d) {
@@ -2378,59 +2384,62 @@ ${g.join(`
2378
2384
  const u = o === void 0;
2379
2385
  if (o = d.conversation.id, !c) {
2380
2386
  c = !0;
2381
- for (const g of n.load())
2382
- w.send({ type: "send", conversationId: o, clientMsgId: g.clientMsgId, content: g.content });
2387
+ for (const b of i.load())
2388
+ y.send({ type: "send", conversationId: o, clientMsgId: b.clientMsgId, content: b.content });
2383
2389
  }
2384
- u && (Pe(s.url, e, o, t, L), d.conversation.lastSeq === 0 && Se(o));
2390
+ u && (Be(s.url, e, o, t, L), d.conversation.lastSeq === 0 && Ie(o));
2385
2391
  }
2386
- if (d.type === "ack" && n.remove(d.clientMsgId), d.type === "prekeyBundle") {
2387
- d.bundle && (A = !0, v.x3dhSendTo(d.bundle).then((u) => {
2388
- const g = [...U.splice(0), ...P.splice(0)];
2389
- for (const E of g) H(E.clientMsgId, E.text, u);
2392
+ if (d.type === "ack" && i.remove(d.clientMsgId), d.type === "prekeyBundle") {
2393
+ d.bundle && (B = !0, g.x3dhSendTo(d.bundle).then((u) => {
2394
+ const b = [...T.splice(0), ...U.splice(0)];
2395
+ for (const I of b) P(I.clientMsgId, I.text, u);
2390
2396
  L.render(t);
2391
2397
  }));
2392
2398
  return;
2393
2399
  }
2394
2400
  if (d.type === "message" && t.e2e) {
2395
- const u = Bt(d.message.content);
2396
- if (u && !v.ready) {
2397
- v.x3dhReceiveFrom(u.x3dhIK, u.x3dhEK, u.x3dhSPK).then(async () => {
2398
- await v.openFrame(d), t.apply(d), L.render(t);
2401
+ const u = Kt(d.message.content);
2402
+ if (u && !g.ready) {
2403
+ g.x3dhReceiveFrom(u.x3dhIK, u.x3dhEK, u.x3dhSPK).then(async () => {
2404
+ await g.openFrame(d), t.apply(d), L.render(t);
2399
2405
  });
2400
2406
  return;
2401
2407
  }
2402
2408
  }
2403
2409
  if (d.type === "peerkey") {
2404
- v.onPeerKey(d.key).then(() => {
2405
- k(), L.render(t);
2410
+ g.onPeerKey(d.key).then(() => {
2411
+ H(), L.render(t);
2406
2412
  });
2407
2413
  return;
2408
2414
  }
2409
2415
  (async () => {
2410
- if (t.e2e && await v.openFrame(d), t.apply(d), d.type === "message" && d.message.senderId !== e && !d.message.internal && (T(), m()), t.e2e && o && !B) {
2411
- B = !0;
2412
- const u = await v.initX3DH();
2413
- w.send({ type: "uploadPrekeys", ...u });
2414
- const g = await v.begin();
2415
- w.send({ type: "pubkey", conversationId: o, key: g });
2416
+ if (t.e2e && await g.openFrame(d), t.apply(d), d.type === "message" && d.message.senderId !== e && !d.message.internal && (p(), E()), t.e2e && o && !C) {
2417
+ C = !0;
2418
+ const u = await g.initX3DH();
2419
+ y.send({ type: "uploadPrekeys", ...u });
2420
+ const b = await g.begin();
2421
+ y.send({ type: "pubkey", conversationId: o, key: b });
2416
2422
  }
2417
2423
  L.render(t);
2418
2424
  })();
2419
2425
  }
2420
- }), w.connect(), L.render(t), l = { close: () => {
2421
- w.close(), b == null || b.remove(), L.destroy(), x && y && x.removeEventListener("change", (d) => y(d.matches));
2422
- } }, l;
2426
+ }), y.connect(), L.render(t);
2427
+ const re = { close: () => {
2428
+ y.close(), f == null || f.remove(), L.destroy(), l && w && l.removeEventListener("change", (d) => w(d.matches)), R.delete(s.el);
2429
+ } };
2430
+ return R.set(s.el, re), re;
2423
2431
  }
2424
2432
  export {
2425
- wt as ChatStore,
2426
- xt as ConnectionManager,
2427
- Pt as E2ESession,
2428
- bt as PersistentOutbox,
2429
- Mt as Renderer,
2430
- Ht as asConversationId,
2431
- Bt as extractX3DHInit,
2432
- Be as httpBaseFromWsUrl,
2433
- Rt as mount,
2434
- Pe as restoreHistory
2433
+ xt as ChatStore,
2434
+ yt as ConnectionManager,
2435
+ Bt as E2ESession,
2436
+ mt as PersistentOutbox,
2437
+ Dt as Renderer,
2438
+ Rt as asConversationId,
2439
+ Kt as extractX3DHInit,
2440
+ Ke as httpBaseFromWsUrl,
2441
+ jt as mount,
2442
+ Be as restoreHistory,
2443
+ Ft as unmount
2435
2444
  };
2436
2445
  //# sourceMappingURL=index.js.map