@paramms/chat-widget 1.0.16 → 1.0.18

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