@paramms/chat-widget 1.0.23 → 1.0.25

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