@paramms/chat-widget 1.0.5 → 1.0.7

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