@paramms/chat-widget 1.0.9 → 1.0.11

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