@paramms/chat-widget 1.0.9 → 1.0.10

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,10 +1,9 @@
1
- var Ie = Object.defineProperty;
2
- var Ce = (s, e, t) => e in s ? Ie(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var r = (s, e, t) => Ce(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { p as Ee, r as Ue } from "./uid.js";
5
- import { h as Rt } from "./uid.js";
6
- const Dt = (s) => s;
7
- function Te(s) {
1
+ var Ee = Object.defineProperty;
2
+ var Te = (s, e, t) => e in s ? Ee(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var r = (s, e, t) => Te(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { p as Ue, r as Pe, h as Be } from "./uid.js";
5
+ const Ht = (s) => s;
6
+ function Ke(s) {
8
7
  const e = s.length;
9
8
  let t = 0, i = 0;
10
9
  for (; i < e; ) {
@@ -26,7 +25,7 @@ function Te(s) {
26
25
  }
27
26
  return t;
28
27
  }
29
- function Pe(s, e, t) {
28
+ function Ae(s, e, t) {
30
29
  const i = s.length;
31
30
  let n = t, o = 0;
32
31
  for (; o < i; ) {
@@ -48,15 +47,15 @@ function Pe(s, e, t) {
48
47
  e[n++] = c & 63 | 128;
49
48
  }
50
49
  }
51
- const Be = new TextEncoder(), Ke = 50;
52
- function Ae(s, e, t) {
53
- Be.encodeInto(s, e.subarray(t));
50
+ const ze = new TextEncoder(), Le = 50;
51
+ function Me(s, e, t) {
52
+ ze.encodeInto(s, e.subarray(t));
54
53
  }
55
- function ze(s, e, t) {
56
- s.length > Ke ? Ae(s, e, t) : Pe(s, e, t);
54
+ function De(s, e, t) {
55
+ s.length > Le ? Me(s, e, t) : Ae(s, e, t);
57
56
  }
58
- const Le = 4096;
59
- function ue(s, e, t) {
57
+ const $e = 4096;
58
+ function fe(s, e, t) {
60
59
  let i = e;
61
60
  const n = i + t, o = [];
62
61
  let c = "";
@@ -68,65 +67,65 @@ function ue(s, e, t) {
68
67
  const x = s[i++] & 63;
69
68
  o.push((l & 31) << 6 | x);
70
69
  } else if ((l & 240) === 224) {
71
- const x = s[i++] & 63, f = s[i++] & 63;
72
- o.push((l & 31) << 12 | x << 6 | f);
70
+ const x = s[i++] & 63, y = s[i++] & 63;
71
+ o.push((l & 31) << 12 | x << 6 | y);
73
72
  } else if ((l & 248) === 240) {
74
- const x = s[i++] & 63, f = s[i++] & 63, m = s[i++] & 63;
75
- let w = (l & 7) << 18 | x << 12 | f << 6 | m;
76
- w > 65535 && (w -= 65536, o.push(w >>> 10 & 1023 | 55296), w = 56320 | w & 1023), o.push(w);
73
+ const x = s[i++] & 63, y = s[i++] & 63, b = s[i++] & 63;
74
+ let f = (l & 7) << 18 | x << 12 | y << 6 | b;
75
+ f > 65535 && (f -= 65536, o.push(f >>> 10 & 1023 | 55296), f = 56320 | f & 1023), o.push(f);
77
76
  } else
78
77
  o.push(l);
79
- o.length >= Le && (c += String.fromCharCode(...o), o.length = 0);
78
+ o.length >= $e && (c += String.fromCharCode(...o), o.length = 0);
80
79
  }
81
80
  return o.length > 0 && (c += String.fromCharCode(...o)), c;
82
81
  }
83
- const Me = new TextDecoder(), De = 200;
84
- function $e(s, e, t) {
82
+ const _e = new TextDecoder(), He = 200;
83
+ function Re(s, e, t) {
85
84
  const i = s.subarray(e, e + t);
86
- return Me.decode(i);
85
+ return _e.decode(i);
87
86
  }
88
- function _e(s, e, t) {
89
- return t > De ? $e(s, e, t) : ue(s, e, t);
87
+ function Fe(s, e, t) {
88
+ return t > He ? Re(s, e, t) : fe(s, e, t);
90
89
  }
91
- class N {
90
+ class V {
92
91
  constructor(e, t) {
93
92
  r(this, "type");
94
93
  r(this, "data");
95
94
  this.type = e, this.data = t;
96
95
  }
97
96
  }
98
- class U extends Error {
97
+ class z extends Error {
99
98
  constructor(e) {
100
99
  super(e);
101
- const t = Object.create(U.prototype);
100
+ const t = Object.create(z.prototype);
102
101
  Object.setPrototypeOf(this, t), Object.defineProperty(this, "name", {
103
102
  configurable: !0,
104
103
  enumerable: !1,
105
- value: U.name
104
+ value: z.name
106
105
  });
107
106
  }
108
107
  }
109
108
  const F = 4294967295;
110
- function He(s, e, t) {
109
+ function je(s, e, t) {
111
110
  const i = t / 4294967296, n = t;
112
111
  s.setUint32(e, i), s.setUint32(e + 4, n);
113
112
  }
114
- function fe(s, e, t) {
113
+ function we(s, e, t) {
115
114
  const i = Math.floor(t / 4294967296), n = t;
116
115
  s.setUint32(e, i), s.setUint32(e + 4, n);
117
116
  }
118
- function we(s, e) {
117
+ function xe(s, e) {
119
118
  const t = s.getInt32(e), i = s.getUint32(e + 4);
120
119
  return t * 4294967296 + i;
121
120
  }
122
- function Re(s, e) {
121
+ function qe(s, e) {
123
122
  const t = s.getUint32(e), i = s.getUint32(e + 4);
124
123
  return t * 4294967296 + i;
125
124
  }
126
- const Fe = -1, qe = 4294967296 - 1, je = 17179869184 - 1;
127
- function Oe({ sec: s, nsec: e }) {
128
- if (s >= 0 && e >= 0 && s <= je)
129
- if (e === 0 && s <= qe) {
125
+ const Oe = -1, Ne = 4294967296 - 1, Ve = 17179869184 - 1;
126
+ function We({ sec: s, nsec: e }) {
127
+ if (s >= 0 && e >= 0 && s <= Ve)
128
+ if (e === 0 && s <= Ne) {
130
129
  const t = new Uint8Array(4);
131
130
  return new DataView(t.buffer).setUint32(0, s), t;
132
131
  } else {
@@ -135,24 +134,24 @@ function Oe({ sec: s, nsec: e }) {
135
134
  }
136
135
  else {
137
136
  const t = new Uint8Array(12), i = new DataView(t.buffer);
138
- return i.setUint32(0, e), fe(i, 4, s), t;
137
+ return i.setUint32(0, e), we(i, 4, s), t;
139
138
  }
140
139
  }
141
- function Ne(s) {
140
+ function Xe(s) {
142
141
  const e = s.getTime(), t = Math.floor(e / 1e3), i = (e - t * 1e3) * 1e6, n = Math.floor(i / 1e9);
143
142
  return {
144
143
  sec: t + n,
145
144
  nsec: i - n * 1e9
146
145
  };
147
146
  }
148
- function Ve(s) {
147
+ function Ye(s) {
149
148
  if (s instanceof Date) {
150
- const e = Ne(s);
151
- return Oe(e);
149
+ const e = Xe(s);
150
+ return We(e);
152
151
  } else
153
152
  return null;
154
153
  }
155
- function We(s) {
154
+ function Je(s) {
156
155
  const e = new DataView(s.buffer, s.byteOffset, s.byteLength);
157
156
  switch (s.byteLength) {
158
157
  case 4:
@@ -162,22 +161,22 @@ function We(s) {
162
161
  return { sec: n, nsec: o };
163
162
  }
164
163
  case 12: {
165
- const t = we(e, 4), i = e.getUint32(0);
164
+ const t = xe(e, 4), i = e.getUint32(0);
166
165
  return { sec: t, nsec: i };
167
166
  }
168
167
  default:
169
- throw new U(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${s.length}`);
168
+ throw new z(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${s.length}`);
170
169
  }
171
170
  }
172
- function Xe(s) {
173
- const e = We(s);
171
+ function Ge(s) {
172
+ const e = Je(s);
174
173
  return new Date(e.sec * 1e3 + e.nsec / 1e6);
175
174
  }
176
- const Ye = {
177
- type: Fe,
178
- encode: Ve,
179
- decode: Xe
180
- }, X = class X {
175
+ const Ze = {
176
+ type: Oe,
177
+ encode: Ye,
178
+ decode: Ge
179
+ }, Y = class Y {
181
180
  constructor() {
182
181
  // ensures ExtensionCodecType<X> matches ExtensionCodec<X>
183
182
  // this will make type errors a lot more clear
@@ -189,7 +188,7 @@ const Ye = {
189
188
  // custom extensions
190
189
  r(this, "encoders", []);
191
190
  r(this, "decoders", []);
192
- this.register(Ye);
191
+ this.register(Ze);
193
192
  }
194
193
  register({ type: e, encode: t, decode: i }) {
195
194
  if (e >= 0)
@@ -206,7 +205,7 @@ const Ye = {
206
205
  const o = n(e, t);
207
206
  if (o != null) {
208
207
  const c = -1 - i;
209
- return new N(c, o);
208
+ return new V(c, o);
210
209
  }
211
210
  }
212
211
  }
@@ -216,27 +215,27 @@ const Ye = {
216
215
  const o = n(e, t);
217
216
  if (o != null) {
218
217
  const c = i;
219
- return new N(c, o);
218
+ return new V(c, o);
220
219
  }
221
220
  }
222
221
  }
223
- return e instanceof N ? e : null;
222
+ return e instanceof V ? e : null;
224
223
  }
225
224
  decode(e, t, i) {
226
225
  const n = t < 0 ? this.builtInDecoders[-1 - t] : this.decoders[t];
227
- return n ? n(e, t, i) : new N(t, e);
226
+ return n ? n(e, t, i) : new V(t, e);
228
227
  }
229
228
  };
230
- r(X, "defaultCodec", new X());
231
- let V = X;
232
- function Je(s) {
229
+ r(Y, "defaultCodec", new Y());
230
+ let W = Y;
231
+ function Qe(s) {
233
232
  return s instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && s instanceof SharedArrayBuffer;
234
233
  }
235
- function Z(s) {
236
- return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) : Je(s) ? new Uint8Array(s) : Uint8Array.from(s);
234
+ function Q(s) {
235
+ return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) : Qe(s) ? new Uint8Array(s) : Uint8Array.from(s);
237
236
  }
238
- const Ge = 100, Ze = 2048;
239
- class te {
237
+ const et = 100, tt = 2048;
238
+ class ie {
240
239
  constructor(e) {
241
240
  r(this, "extensionCodec");
242
241
  r(this, "context");
@@ -251,10 +250,10 @@ class te {
251
250
  r(this, "view");
252
251
  r(this, "bytes");
253
252
  r(this, "entered", !1);
254
- this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? V.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ?? Ge, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? Ze, this.sortKeys = (e == null ? void 0 : e.sortKeys) ?? !1, this.forceFloat32 = (e == null ? void 0 : e.forceFloat32) ?? !1, this.ignoreUndefined = (e == null ? void 0 : e.ignoreUndefined) ?? !1, this.forceIntegerToFloat = (e == null ? void 0 : e.forceIntegerToFloat) ?? !1, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
253
+ this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? W.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ?? et, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? tt, this.sortKeys = (e == null ? void 0 : e.sortKeys) ?? !1, this.forceFloat32 = (e == null ? void 0 : e.forceFloat32) ?? !1, this.ignoreUndefined = (e == null ? void 0 : e.ignoreUndefined) ?? !1, this.forceIntegerToFloat = (e == null ? void 0 : e.forceIntegerToFloat) ?? !1, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
255
254
  }
256
255
  clone() {
257
- return new te({
256
+ return new ie({
258
257
  extensionCodec: this.extensionCodec,
259
258
  context: this.context,
260
259
  useBigInt64: this.useBigInt64,
@@ -336,8 +335,8 @@ class te {
336
335
  throw new Error(`Too long string: ${e} bytes in UTF-8`);
337
336
  }
338
337
  encodeString(e) {
339
- const i = Te(e);
340
- this.ensureBufferSizeToWrite(5 + i), this.writeStringHeader(i), ze(e, this.bytes, this.pos), this.pos += i;
338
+ const i = Ke(e);
339
+ this.ensureBufferSizeToWrite(5 + i), this.writeStringHeader(i), De(e, this.bytes, this.pos), this.pos += i;
341
340
  }
342
341
  encodeObject(e, t) {
343
342
  const i = this.extensionCodec.tryToEncode(e, this.context);
@@ -362,7 +361,7 @@ class te {
362
361
  this.writeU8(198), this.writeU32(t);
363
362
  else
364
363
  throw new Error(`Too large binary: ${t}`);
365
- const i = Z(e);
364
+ const i = Q(e);
366
365
  this.writeU8a(i);
367
366
  }
368
367
  encodeArray(e, t) {
@@ -459,10 +458,10 @@ class te {
459
458
  this.ensureBufferSizeToWrite(8), this.view.setFloat64(this.pos, e), this.pos += 8;
460
459
  }
461
460
  writeU64(e) {
462
- this.ensureBufferSizeToWrite(8), He(this.view, this.pos, e), this.pos += 8;
461
+ this.ensureBufferSizeToWrite(8), je(this.view, this.pos, e), this.pos += 8;
463
462
  }
464
463
  writeI64(e) {
465
- this.ensureBufferSizeToWrite(8), fe(this.view, this.pos, e), this.pos += 8;
464
+ this.ensureBufferSizeToWrite(8), we(this.view, this.pos, e), this.pos += 8;
466
465
  }
467
466
  writeBigUint64(e) {
468
467
  this.ensureBufferSizeToWrite(8), this.view.setBigUint64(this.pos, e), this.pos += 8;
@@ -471,15 +470,15 @@ class te {
471
470
  this.ensureBufferSizeToWrite(8), this.view.setBigInt64(this.pos, e), this.pos += 8;
472
471
  }
473
472
  }
474
- function Qe(s, e) {
475
- return new te(e).encodeSharedRef(s);
473
+ function it(s, e) {
474
+ return new ie(e).encodeSharedRef(s);
476
475
  }
477
- function J(s) {
476
+ function G(s) {
478
477
  return `${s < 0 ? "-" : ""}0x${Math.abs(s).toString(16).padStart(2, "0")}`;
479
478
  }
480
- const et = 16, tt = 16;
481
- class it {
482
- constructor(e = et, t = tt) {
479
+ const nt = 16, st = 16;
480
+ class ot {
481
+ constructor(e = nt, t = st) {
483
482
  r(this, "hit", 0);
484
483
  r(this, "miss", 0);
485
484
  r(this, "caches");
@@ -512,16 +511,16 @@ class it {
512
511
  if (n != null)
513
512
  return this.hit++, n;
514
513
  this.miss++;
515
- const o = ue(e, t, i), c = Uint8Array.prototype.slice.call(e, t, t + i);
514
+ const o = fe(e, t, i), c = Uint8Array.prototype.slice.call(e, t, t + i);
516
515
  return this.store(c, o), o;
517
516
  }
518
517
  }
519
- const Q = "array", j = "map_key", xe = "map_value", nt = (s) => {
518
+ const ee = "array", q = "map_key", ye = "map_value", rt = (s) => {
520
519
  if (typeof s == "string" || typeof s == "number")
521
520
  return s;
522
- throw new U("The type of key must be string or number but " + typeof s);
521
+ throw new z("The type of key must be string or number but " + typeof s);
523
522
  };
524
- class st {
523
+ class at {
525
524
  constructor() {
526
525
  r(this, "stack", []);
527
526
  r(this, "stackHeadPosition", -1);
@@ -534,11 +533,11 @@ class st {
534
533
  }
535
534
  pushArrayState(e) {
536
535
  const t = this.getUninitializedStateFromPool();
537
- t.type = Q, t.position = 0, t.size = e, t.array = new Array(e);
536
+ t.type = ee, t.position = 0, t.size = e, t.array = new Array(e);
538
537
  }
539
538
  pushMapState(e) {
540
539
  const t = this.getUninitializedStateFromPool();
541
- t.type = j, t.readCount = 0, t.size = e, t.map = {};
540
+ t.type = q, t.readCount = 0, t.size = e, t.map = {};
542
541
  }
543
542
  getUninitializedStateFromPool() {
544
543
  if (this.stackHeadPosition++, this.stackHeadPosition === this.stack.length) {
@@ -558,11 +557,11 @@ class st {
558
557
  release(e) {
559
558
  if (this.stack[this.stackHeadPosition] !== e)
560
559
  throw new Error("Invalid stack state. Released state is not on top of the stack.");
561
- if (e.type === Q) {
560
+ if (e.type === ee) {
562
561
  const i = e;
563
562
  i.size = 0, i.array = void 0, i.position = 0, i.type = void 0;
564
563
  }
565
- if (e.type === j || e.type === xe) {
564
+ if (e.type === q || e.type === ye) {
566
565
  const i = e;
567
566
  i.size = 0, i.map = void 0, i.readCount = 0, i.type = void 0;
568
567
  }
@@ -572,15 +571,15 @@ class st {
572
571
  this.stack.length = 0, this.stackHeadPosition = -1;
573
572
  }
574
573
  }
575
- const q = -1, ie = new DataView(new ArrayBuffer(0)), ot = new Uint8Array(ie.buffer);
574
+ const j = -1, ne = new DataView(new ArrayBuffer(0)), ct = new Uint8Array(ne.buffer);
576
575
  try {
577
- ie.getInt8(0);
576
+ ne.getInt8(0);
578
577
  } catch (s) {
579
578
  if (!(s instanceof RangeError))
580
579
  throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
581
580
  }
582
- const ce = new RangeError("Insufficient data"), rt = new it();
583
- class ne {
581
+ const de = new RangeError("Insufficient data"), dt = new ot();
582
+ class se {
584
583
  constructor(e) {
585
584
  r(this, "extensionCodec");
586
585
  r(this, "context");
@@ -595,15 +594,15 @@ class ne {
595
594
  r(this, "mapKeyConverter");
596
595
  r(this, "totalPos", 0);
597
596
  r(this, "pos", 0);
598
- r(this, "view", ie);
599
- r(this, "bytes", ot);
600
- r(this, "headByte", q);
601
- r(this, "stack", new st());
597
+ r(this, "view", ne);
598
+ r(this, "bytes", ct);
599
+ r(this, "headByte", j);
600
+ r(this, "stack", new at());
602
601
  r(this, "entered", !1);
603
- this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? V.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? F, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? F, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? F, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? F, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? F, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : rt, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? nt;
602
+ this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? W.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? F, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? F, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? F, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? F, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? F, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : dt, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? rt;
604
603
  }
605
604
  clone() {
606
- return new ne({
605
+ return new se({
607
606
  extensionCodec: this.extensionCodec,
608
607
  context: this.context,
609
608
  useBigInt64: this.useBigInt64,
@@ -617,17 +616,17 @@ class ne {
617
616
  });
618
617
  }
619
618
  reinitializeState() {
620
- this.totalPos = 0, this.headByte = q, this.stack.reset();
619
+ this.totalPos = 0, this.headByte = j, this.stack.reset();
621
620
  }
622
621
  setBuffer(e) {
623
- const t = Z(e);
622
+ const t = Q(e);
624
623
  this.bytes = t, this.view = new DataView(t.buffer, t.byteOffset, t.byteLength), this.pos = 0;
625
624
  }
626
625
  appendBuffer(e) {
627
- if (this.headByte === q && !this.hasRemaining(1))
626
+ if (this.headByte === j && !this.hasRemaining(1))
628
627
  this.setBuffer(e);
629
628
  else {
630
- const t = this.bytes.subarray(this.pos), i = Z(e), n = new Uint8Array(t.length + i.length);
629
+ const t = this.bytes.subarray(this.pos), i = Q(e), n = new Uint8Array(t.length + i.length);
631
630
  n.set(t), n.set(i, t.length), this.setBuffer(n);
632
631
  }
633
632
  }
@@ -691,7 +690,7 @@ class ne {
691
690
  return i;
692
691
  }
693
692
  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
+ throw new RangeError(`Insufficient data in parsing ${G(n)} at ${c} (${o} in the current buffer)`);
695
694
  } finally {
696
695
  this.entered = !1;
697
696
  }
@@ -846,25 +845,25 @@ class ne {
846
845
  const n = this.lookU32();
847
846
  t = this.decodeExtension(n, 4);
848
847
  } else
849
- throw new U(`Unrecognized type byte: ${J(e)}`);
848
+ throw new z(`Unrecognized type byte: ${G(e)}`);
850
849
  this.complete();
851
850
  const i = this.stack;
852
851
  for (; i.length > 0; ) {
853
852
  const n = i.top();
854
- if (n.type === Q)
853
+ if (n.type === ee)
855
854
  if (n.array[n.position] = t, n.position++, n.position === n.size)
856
855
  t = n.array, i.release(n);
857
856
  else
858
857
  continue e;
859
- else if (n.type === j) {
858
+ else if (n.type === q) {
860
859
  if (t === "__proto__")
861
- throw new U("The key __proto__ is not allowed");
862
- n.key = this.mapKeyConverter(t), n.type = xe;
860
+ throw new z("The key __proto__ is not allowed");
861
+ n.key = this.mapKeyConverter(t), n.type = ye;
863
862
  continue e;
864
863
  } else if (n.map[n.key] = t, n.readCount++, n.readCount === n.size)
865
864
  t = n.map, i.release(n);
866
865
  else {
867
- n.key = null, n.type = j;
866
+ n.key = null, n.type = q;
868
867
  continue e;
869
868
  }
870
869
  }
@@ -872,10 +871,10 @@ class ne {
872
871
  }
873
872
  }
874
873
  readHeadByte() {
875
- return this.headByte === q && (this.headByte = this.readU8()), this.headByte;
874
+ return this.headByte === j && (this.headByte = this.readU8()), this.headByte;
876
875
  }
877
876
  complete() {
878
- this.headByte = q;
877
+ this.headByte = j;
879
878
  }
880
879
  readArraySize() {
881
880
  const e = this.readHeadByte();
@@ -887,18 +886,18 @@ class ne {
887
886
  default: {
888
887
  if (e < 160)
889
888
  return e - 144;
890
- throw new U(`Unrecognized array type byte: ${J(e)}`);
889
+ throw new z(`Unrecognized array type byte: ${G(e)}`);
891
890
  }
892
891
  }
893
892
  }
894
893
  pushMapState(e) {
895
894
  if (e > this.maxMapLength)
896
- throw new U(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);
895
+ throw new z(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);
897
896
  this.stack.pushMapState(e);
898
897
  }
899
898
  pushArrayState(e) {
900
899
  if (e > this.maxArrayLength)
901
- throw new U(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);
900
+ throw new z(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);
902
901
  this.stack.pushArrayState(e);
903
902
  }
904
903
  decodeString(e, t) {
@@ -910,30 +909,30 @@ class ne {
910
909
  decodeUtf8String(e, t) {
911
910
  var o;
912
911
  if (e > this.maxStrLength)
913
- throw new U(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);
912
+ throw new z(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);
914
913
  if (this.bytes.byteLength < this.pos + t + e)
915
- throw ce;
914
+ throw de;
916
915
  const i = this.pos + t;
917
916
  let n;
918
- return this.stateIsMapKey() && ((o = this.keyDecoder) != null && o.canBeCached(e)) ? n = this.keyDecoder.decode(this.bytes, i, e) : n = _e(this.bytes, i, e), this.pos += t + e, n;
917
+ return this.stateIsMapKey() && ((o = this.keyDecoder) != null && o.canBeCached(e)) ? n = this.keyDecoder.decode(this.bytes, i, e) : n = Fe(this.bytes, i, e), this.pos += t + e, n;
919
918
  }
920
919
  stateIsMapKey() {
921
- return this.stack.length > 0 ? this.stack.top().type === j : !1;
920
+ return this.stack.length > 0 ? this.stack.top().type === q : !1;
922
921
  }
923
922
  /**
924
923
  * @throws {@link RangeError}
925
924
  */
926
925
  decodeBinary(e, t) {
927
926
  if (e > this.maxBinLength)
928
- throw new U(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);
927
+ throw new z(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);
929
928
  if (!this.hasRemaining(e + t))
930
- throw ce;
929
+ throw de;
931
930
  const i = this.pos + t, n = this.bytes.subarray(i, i + e);
932
931
  return this.pos += t + e, n;
933
932
  }
934
933
  decodeExtension(e, t) {
935
934
  if (e > this.maxExtLength)
936
- throw new U(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);
935
+ throw new z(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);
937
936
  const i = this.view.getInt8(this.pos + t), n = this.decodeBinary(
938
937
  e,
939
938
  t + 1
@@ -975,11 +974,11 @@ class ne {
975
974
  return this.pos += 4, e;
976
975
  }
977
976
  readU64() {
978
- const e = Re(this.view, this.pos);
977
+ const e = qe(this.view, this.pos);
979
978
  return this.pos += 8, e;
980
979
  }
981
980
  readI64() {
982
- const e = we(this.view, this.pos);
981
+ const e = xe(this.view, this.pos);
983
982
  return this.pos += 8, e;
984
983
  }
985
984
  readU64AsBigInt() {
@@ -999,10 +998,10 @@ class ne {
999
998
  return this.pos += 8, e;
1000
999
  }
1001
1000
  }
1002
- function at(s, e) {
1003
- return new ne(e).decode(s);
1001
+ function lt(s, e) {
1002
+ return new se(e).decode(s);
1004
1003
  }
1005
- const ct = /* @__PURE__ */ new Set([
1004
+ const ht = /* @__PURE__ */ new Set([
1006
1005
  "auth",
1007
1006
  "open",
1008
1007
  "send",
@@ -1019,22 +1018,22 @@ const ct = /* @__PURE__ */ new Set([
1019
1018
  "annotate",
1020
1019
  "annotate_clear"
1021
1020
  ]);
1022
- function dt(s) {
1023
- return ct.has(s.type);
1021
+ function pt(s) {
1022
+ return ht.has(s.type);
1024
1023
  }
1025
- function lt(s) {
1026
- return Qe(s);
1024
+ function ut(s) {
1025
+ return it(s);
1027
1026
  }
1028
- function ht(s) {
1027
+ function ft(s) {
1029
1028
  let e;
1030
1029
  try {
1031
- e = at(s);
1030
+ e = lt(s);
1032
1031
  } catch {
1033
1032
  return null;
1034
1033
  }
1035
1034
  return typeof e != "object" || e === null || typeof e.type != "string" ? null : e;
1036
1035
  }
1037
- class pt {
1036
+ class wt {
1038
1037
  constructor(e) {
1039
1038
  r(this, "conversationId");
1040
1039
  r(this, "state", "");
@@ -1179,11 +1178,14 @@ class pt {
1179
1178
  this.byId.set(e.id, t ? { ...t, ...e } : e), e.seq > this._maxSeq && (this._maxSeq = e.seq), this._sorted = null;
1180
1179
  }
1181
1180
  markOwnStatus(e, t) {
1182
- for (const [i, n] of this.byId)
1183
- n.senderId === this.me && n.seq > 0 && n.seq <= e && de(t) > de(n.status) && (this.byId.set(i, { ...n, status: t }), this._sorted = null);
1181
+ const i = le(t);
1182
+ let n = !1;
1183
+ for (const [o, c] of this.byId)
1184
+ c.senderId !== this.me || c.seq <= 0 || c.seq > e || le(c.status) >= i || (this.byId.set(o, { ...c, status: t }), n = !0);
1185
+ n && (this._sorted = null);
1184
1186
  }
1185
1187
  }
1186
- function de(s) {
1188
+ function le(s) {
1187
1189
  switch (s) {
1188
1190
  case "read":
1189
1191
  return 3;
@@ -1195,7 +1197,7 @@ function de(s) {
1195
1197
  return 0;
1196
1198
  }
1197
1199
  }
1198
- class ut {
1200
+ class xt {
1199
1201
  constructor(e) {
1200
1202
  r(this, "socket", null);
1201
1203
  r(this, "state", "idle");
@@ -1210,12 +1212,12 @@ class ut {
1210
1212
  var i, n;
1211
1213
  if (this.state === "connecting" || this.state === "open") return;
1212
1214
  this.stopped = !1, this.state = "connecting", this.authed = !1, (n = (i = this.opts).onStatusChange) == null || n.call(i, this.attempt > 0 ? "reconnecting" : "connecting");
1213
- const t = (this.opts.socketFactory ?? ft)(this.opts.url);
1215
+ const t = (this.opts.socketFactory ?? yt)(this.opts.url);
1214
1216
  t.binaryType = "arraybuffer", this.socket = t, t.onopen = () => {
1215
1217
  this.raw({ type: "auth", token: this.opts.token });
1216
1218
  }, t.onmessage = (o) => {
1217
- const c = ht(new Uint8Array(o.data));
1218
- !c || dt(c) || this.handle(c);
1219
+ const c = ft(new Uint8Array(o.data));
1220
+ !c || pt(c) || this.handle(c);
1219
1221
  }, t.onclose = () => this.onClosed(), t.onerror = () => {
1220
1222
  try {
1221
1223
  t.close();
@@ -1254,7 +1256,7 @@ class ut {
1254
1256
  raw(e) {
1255
1257
  var t;
1256
1258
  try {
1257
- (t = this.socket) == null || t.send(lt(e));
1259
+ (t = this.socket) == null || t.send(ut(e));
1258
1260
  } catch {
1259
1261
  this.outbox.push(e);
1260
1262
  }
@@ -1269,11 +1271,11 @@ class ut {
1269
1271
  this.attempt++, this.timer = setTimeout(() => this.connect(), i);
1270
1272
  }
1271
1273
  }
1272
- function ft(s) {
1274
+ function yt(s) {
1273
1275
  return new WebSocket(s);
1274
1276
  }
1275
- const le = 200, wt = 7 * 864e5;
1276
- class xt {
1277
+ const he = 200, gt = 7 * 864e5;
1278
+ class bt {
1277
1279
  constructor(e) {
1278
1280
  r(this, "key");
1279
1281
  this.key = `ocw_outbox_${e}`;
@@ -1283,7 +1285,7 @@ class xt {
1283
1285
  try {
1284
1286
  const e = localStorage.getItem(this.key);
1285
1287
  if (!e) return [];
1286
- const t = JSON.parse(e), i = Date.now() - wt, n = t.filter((o) => o.ts >= i);
1288
+ const t = JSON.parse(e), i = Date.now() - gt, n = t.filter((o) => o.ts >= i);
1287
1289
  return n.length !== t.length && this.save(n), n;
1288
1290
  } catch {
1289
1291
  return [];
@@ -1292,7 +1294,7 @@ class xt {
1292
1294
  add(e) {
1293
1295
  try {
1294
1296
  const t = this.load();
1295
- t.push(e), this.save(t.length > le ? t.slice(t.length - le) : t);
1297
+ t.push(e), this.save(t.length > he ? t.slice(t.length - he) : t);
1296
1298
  } catch {
1297
1299
  }
1298
1300
  }
@@ -1312,13 +1314,13 @@ class xt {
1312
1314
  }
1313
1315
  }
1314
1316
  const S = () => globalThis.crypto.subtle;
1315
- function W(s) {
1317
+ function X(s) {
1316
1318
  const e = s instanceof Uint8Array ? s : new Uint8Array(s);
1317
1319
  let t = "";
1318
1320
  for (const i of e) t += String.fromCharCode(i);
1319
1321
  return btoa(t);
1320
1322
  }
1321
- function ee(s) {
1323
+ function te(s) {
1322
1324
  const e = atob(s), t = new ArrayBuffer(e.length), i = new Uint8Array(t);
1323
1325
  for (let n = 0; n < e.length; n++) i[n] = e.charCodeAt(n);
1324
1326
  return i;
@@ -1327,14 +1329,14 @@ async function O() {
1327
1329
  const s = await S().generateKey({ name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
1328
1330
  return { publicKey: s.publicKey, privateKey: s.privateKey };
1329
1331
  }
1330
- async function M(s) {
1331
- return W(await S().exportKey("raw", s));
1332
+ async function _(s) {
1333
+ return X(await S().exportKey("raw", s));
1332
1334
  }
1333
- async function H(s) {
1334
- return S().importKey("raw", ee(s), { name: "ECDH", namedCurve: "P-256" }, !1, []);
1335
+ async function R(s) {
1336
+ return S().importKey("raw", te(s), { name: "ECDH", namedCurve: "P-256" }, !1, []);
1335
1337
  }
1336
- async function yt(s, e) {
1337
- const t = await H(e);
1338
+ async function mt(s, e) {
1339
+ const t = await R(e);
1338
1340
  return S().deriveKey(
1339
1341
  { name: "ECDH", public: t },
1340
1342
  s,
@@ -1343,15 +1345,15 @@ async function yt(s, e) {
1343
1345
  ["encrypt", "decrypt"]
1344
1346
  );
1345
1347
  }
1346
- async function gt(s, e) {
1348
+ async function vt(s, e) {
1347
1349
  const t = globalThis.crypto.getRandomValues(new Uint8Array(12)), i = new TextEncoder().encode(e), n = await S().encrypt({ name: "AES-GCM", iv: t }, s, i);
1348
- return { ct: W(n), iv: W(t) };
1350
+ return { ct: X(n), iv: X(t) };
1349
1351
  }
1350
- async function bt(s, e, t) {
1351
- const i = await S().decrypt({ name: "AES-GCM", iv: ee(t) }, s, ee(e));
1352
+ async function kt(s, e, t) {
1353
+ const i = await S().decrypt({ name: "AES-GCM", iv: te(t) }, s, te(e));
1352
1354
  return new TextDecoder().decode(i);
1353
1355
  }
1354
- async function mt(s) {
1356
+ async function St(s) {
1355
1357
  var t, i;
1356
1358
  try {
1357
1359
  const n = (t = globalThis.localStorage) == null ? void 0 : t.getItem(s);
@@ -1369,35 +1371,35 @@ async function mt(s) {
1369
1371
  }
1370
1372
  return e;
1371
1373
  }
1372
- async function vt(s, e) {
1374
+ async function It(s, e) {
1373
1375
  const t = await S().exportKey("raw", e), i = await S().sign({ name: "ECDSA", hash: "SHA-256" }, s, t);
1374
- return W(i);
1376
+ return X(i);
1375
1377
  }
1376
- async function kt() {
1378
+ async function Ct() {
1377
1379
  const s = await O(), e = await S().generateKey({ name: "ECDSA", namedCurve: "P-256" }, !0, ["sign", "verify"]);
1378
1380
  return {
1379
1381
  ecdhKP: s,
1380
1382
  ecdsaKP: { publicKey: e.publicKey, privateKey: e.privateKey },
1381
- publicKeyB64: await M(s.publicKey),
1382
- sigPublicKeyB64: await M(e.publicKey)
1383
+ publicKeyB64: await _(s.publicKey),
1384
+ sigPublicKeyB64: await _(e.publicKey)
1383
1385
  };
1384
1386
  }
1385
- async function he(s) {
1387
+ async function pe(s) {
1386
1388
  var t, i;
1387
1389
  try {
1388
1390
  const n = (t = globalThis.localStorage) == null ? void 0 : t.getItem(`${s}-identity`);
1389
1391
  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"]);
1392
+ const o = JSON.parse(n), c = await S().importKey("jwk", o.ecdhPub, { name: "ECDH", namedCurve: "P-256" }, !0, []), l = await S().importKey("jwk", o.ecdhPriv, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]), x = await S().importKey("jwk", o.ecdsaPub, { name: "ECDSA", namedCurve: "P-256" }, !0, ["verify"]), y = await S().importKey("jwk", o.ecdsaPriv, { name: "ECDSA", namedCurve: "P-256" }, !0, ["sign"]);
1391
1393
  return {
1392
1394
  ecdhKP: { publicKey: c, privateKey: l },
1393
- ecdsaKP: { publicKey: x, privateKey: f },
1394
- publicKeyB64: await M(c),
1395
- sigPublicKeyB64: await M(x)
1395
+ ecdsaKP: { publicKey: x, privateKey: y },
1396
+ publicKeyB64: await _(c),
1397
+ sigPublicKeyB64: await _(x)
1396
1398
  };
1397
1399
  }
1398
1400
  } catch {
1399
1401
  }
1400
- const e = await kt();
1402
+ const e = await Ct();
1401
1403
  try {
1402
1404
  const n = await S().exportKey("jwk", e.ecdhKP.publicKey), o = await S().exportKey("jwk", e.ecdhKP.privateKey), c = await S().exportKey("jwk", e.ecdsaKP.publicKey), l = await S().exportKey("jwk", e.ecdsaKP.privateKey);
1403
1405
  (i = globalThis.localStorage) == null || i.setItem(`${s}-identity`, JSON.stringify({ ecdhPub: n, ecdhPriv: o, ecdsaPub: c, ecdsaPriv: l }));
@@ -1405,25 +1407,25 @@ async function he(s) {
1405
1407
  }
1406
1408
  return e;
1407
1409
  }
1408
- async function St(s, e) {
1409
- const t = await O(), i = await M(t.publicKey), n = await H(e.identityKey), o = await H(e.signedPrekey), c = e.oneTimePrekey ? await H(e.oneTimePrekey) : null, l = await L(s.privateKey, o), x = await L(t.privateKey, n), f = await L(t.privateKey, o), m = c ? await L(t.privateKey, c) : null, w = ye(l, x, f, ...m ? [m] : []);
1410
- return { sharedKey: await ge(w), ephemeralPublicKey: i };
1410
+ async function Et(s, e) {
1411
+ const t = await O(), i = await _(t.publicKey), n = await R(e.identityKey), o = await R(e.signedPrekey), c = e.oneTimePrekey ? await R(e.oneTimePrekey) : null, l = await $(s.privateKey, o), x = await $(t.privateKey, n), y = await $(t.privateKey, o), b = c ? await $(t.privateKey, c) : null, f = ge(l, x, y, ...b ? [b] : []);
1412
+ return { sharedKey: await be(f), ephemeralPublicKey: i };
1411
1413
  }
1412
- async function It(s, e, t, i, n) {
1413
- const o = await H(t), c = await H(i), l = await L(e.privateKey, o), x = await L(s.privateKey, c), f = await L(e.privateKey, c), m = n ? await L(n.privateKey, c) : null, w = ye(l, x, f, ...m ? [m] : []);
1414
- return ge(w);
1414
+ async function Tt(s, e, t, i, n) {
1415
+ const o = await R(t), c = await R(i), l = await $(e.privateKey, o), x = await $(s.privateKey, c), y = await $(e.privateKey, c), b = n ? await $(n.privateKey, c) : null, f = ge(l, x, y, ...b ? [b] : []);
1416
+ return be(f);
1415
1417
  }
1416
- async function L(s, e) {
1418
+ async function $(s, e) {
1417
1419
  return S().deriveBits({ name: "ECDH", public: e }, s, 256);
1418
1420
  }
1419
- function ye(...s) {
1421
+ function ge(...s) {
1420
1422
  const e = s.reduce((n, o) => n + o.byteLength, 0), t = new Uint8Array(e);
1421
1423
  let i = 0;
1422
1424
  for (const n of s)
1423
1425
  t.set(new Uint8Array(n), i), i += n.byteLength;
1424
1426
  return t.buffer;
1425
1427
  }
1426
- async function ge(s) {
1428
+ async function be(s) {
1427
1429
  const e = await S().importKey("raw", s, "HKDF", !1, ["deriveKey"]);
1428
1430
  return S().deriveKey(
1429
1431
  { name: "HKDF", hash: "SHA-256", salt: new Uint8Array(32), info: new TextEncoder().encode("ObjectChat X3DH v1") },
@@ -1433,8 +1435,8 @@ async function ge(s) {
1433
1435
  ["encrypt", "decrypt"]
1434
1436
  );
1435
1437
  }
1436
- const Ct = 20;
1437
- class Et {
1438
+ const Ut = 20;
1439
+ class Pt {
1438
1440
  constructor(e) {
1439
1441
  // Live ECDH mode state
1440
1442
  r(this, "kp");
@@ -1455,19 +1457,19 @@ class Et {
1455
1457
  }
1456
1458
  /** Live ECDH mode: Generate/restore our keypair and return our public key to publish. */
1457
1459
  async begin() {
1458
- return this.kp = await mt(this.storageKey), M(this.kp.publicKey);
1460
+ return this.kp = await St(this.storageKey), _(this.kp.publicKey);
1459
1461
  }
1460
1462
  /** Live ECDH mode: A peer published their key — derive the shared secret. */
1461
1463
  async onPeerKey(e) {
1462
- this.kp && (this.shared = await yt(this.kp.privateKey, e));
1464
+ this.kp && (this.shared = await mt(this.kp.privateKey, e));
1463
1465
  }
1464
1466
  // ── X3DH async mode ────────────────────────────────────────────────────────
1465
1467
  /** X3DH: Generate identity key, signed prekey, and OTP prekeys.
1466
1468
  * Returns the upload frame payload the caller should send to the server. */
1467
1469
  async initX3DH() {
1468
- this.identityKP = await he(this.storageKey), this.signedPreKP = await O(), this.signedPrekeyId = `spk-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1469
- for (let n = 0; n < Ct; n++) this.otpKeys.push(await O());
1470
- const e = await M(this.signedPreKP.publicKey), t = await vt(this.identityKP.ecdsaKP.privateKey, this.signedPreKP.publicKey), i = await Promise.all(this.otpKeys.map((n) => M(n.publicKey)));
1470
+ this.identityKP = await pe(this.storageKey), this.signedPreKP = await O(), this.signedPrekeyId = `spk-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1471
+ for (let n = 0; n < Ut; n++) this.otpKeys.push(await O());
1472
+ const e = await _(this.signedPreKP.publicKey), t = await It(this.identityKP.ecdsaKP.privateKey, this.signedPreKP.publicKey), i = await Promise.all(this.otpKeys.map((n) => _(n.publicKey)));
1471
1473
  return {
1472
1474
  identityKey: this.identityKP.publicKeyB64,
1473
1475
  signedPrekey: e,
@@ -1479,8 +1481,8 @@ class Et {
1479
1481
  /** X3DH sender: given a recipient's prekey bundle, derive the shared key and
1480
1482
  * return the init message fields to embed in the first encrypted message. */
1481
1483
  async x3dhSendTo(e) {
1482
- this.identityKP || (this.identityKP = await he(this.storageKey));
1483
- const { sharedKey: t, ephemeralPublicKey: i } = await St(this.identityKP.ecdhKP, e);
1484
+ this.identityKP || (this.identityKP = await pe(this.storageKey));
1485
+ const { sharedKey: t, ephemeralPublicKey: i } = await Et(this.identityKP.ecdhKP, e);
1484
1486
  return this.x3dhShared = t, { ephemeralKey: i, spkId: e.signedPrekeyId, usedOTP: !!e.oneTimePrekey, senderIK: this.identityKP.publicKeyB64 };
1485
1487
  }
1486
1488
  /** X3DH recipient: given an init message's sender IK + EK + SPK ID, derive the shared key. */
@@ -1490,7 +1492,7 @@ class Et {
1490
1492
  return;
1491
1493
  }
1492
1494
  const n = this.otpKeys.shift();
1493
- this.x3dhShared = await It(this.identityKP.ecdhKP, this.signedPreKP, e, t, n);
1495
+ this.x3dhShared = await Tt(this.identityKP.ecdhKP, this.signedPreKP, e, t, n);
1494
1496
  }
1495
1497
  /** Flush pending X3DH derivation after initX3DH() completes. */
1496
1498
  async flushPendingX3DH() {
@@ -1503,7 +1505,7 @@ class Et {
1503
1505
  async sealText(e, t) {
1504
1506
  const i = this.x3dhShared ?? this.shared;
1505
1507
  if (!i) throw new Error("secure channel not ready");
1506
- const { ct: n, iv: o } = await gt(i, e);
1508
+ const { ct: n, iv: o } = await vt(i, e);
1507
1509
  return {
1508
1510
  kind: "text",
1509
1511
  text: n,
@@ -1518,7 +1520,7 @@ class Et {
1518
1520
  const t = this.x3dhShared ?? this.shared;
1519
1521
  if (!t) return { kind: "text", text: "🔒 encrypted" };
1520
1522
  try {
1521
- return { kind: "text", text: await bt(t, e.text, e.iv) };
1523
+ return { kind: "text", text: await kt(t, e.text, e.iv) };
1522
1524
  } catch {
1523
1525
  return { kind: "text", text: "🔒 unable to decrypt" };
1524
1526
  }
@@ -1530,12 +1532,12 @@ class Et {
1530
1532
  for (const t of e.messages) t.content = await this.openContent(t.content);
1531
1533
  }
1532
1534
  }
1533
- function Ut(s) {
1535
+ function Bt(s) {
1534
1536
  if (s.kind !== "text" || !s.enc) return null;
1535
1537
  const e = s;
1536
1538
  return !e.x3dhEK || !e.x3dhSPK || !e.x3dhIK ? null : { x3dhEK: e.x3dhEK, x3dhSPK: e.x3dhSPK, x3dhIK: e.x3dhIK };
1537
1539
  }
1538
- const pe = "objectchat-widget-styles", Tt = ["👍", "❤️", "😂", "😮", "😢", "🙏"], Pt = `
1540
+ const ue = "objectchat-widget-styles", Kt = ["👍", "❤️", "😂", "😮", "😢", "🙏"], At = `
1539
1541
  .ocw { --ocw-accent:#f5713c; --ocw-bg:#f3efe9; --ocw-card:#fff; --ocw-line:#ececec; --ocw-ink:#1c1b1a; --ocw-mut:#9b9690;
1540
1542
  position:relative;
1541
1543
  display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
@@ -1694,23 +1696,23 @@ const pe = "objectchat-widget-styles", Tt = ["👍", "❤️", "😂", "😮", "
1694
1696
  .ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
1695
1697
  .ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
1696
1698
  `;
1697
- function Bt() {
1698
- if (typeof document > "u" || document.getElementById(pe)) return;
1699
+ function zt() {
1700
+ if (typeof document > "u" || document.getElementById(ue)) return;
1699
1701
  const s = document.createElement("style");
1700
- s.id = pe, s.textContent = Pt, document.head.appendChild(s);
1702
+ s.id = ue, s.textContent = At, document.head.appendChild(s);
1701
1703
  }
1702
1704
  function a(s, e, t) {
1703
1705
  const i = document.createElement(s);
1704
1706
  return e && (i.className = e), t !== void 0 && (i.textContent = t), i;
1705
1707
  }
1706
- function Kt(s) {
1708
+ function Lt(s) {
1707
1709
  try {
1708
1710
  return new Date(s).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
1709
1711
  } catch {
1710
1712
  return "";
1711
1713
  }
1712
1714
  }
1713
- function G(s) {
1715
+ function Z(s) {
1714
1716
  var e;
1715
1717
  switch (s.kind) {
1716
1718
  case "text":
@@ -1727,7 +1729,7 @@ function G(s) {
1727
1729
  return `📅 ${s.title} — ${new Date(s.startIso).toLocaleString()}`;
1728
1730
  }
1729
1731
  }
1730
- class At {
1732
+ class Mt {
1731
1733
  /** Last seq the guest has seen per conversationId — used to compute unread badges. */
1732
1734
  constructor(e, t, i, n = {}) {
1733
1735
  r(this, "scroll");
@@ -1760,56 +1762,56 @@ class At {
1760
1762
  r(this, "translationCache", /* @__PURE__ */ new Map());
1761
1763
  r(this, "showingTranslation", /* @__PURE__ */ new Set());
1762
1764
  r(this, "subjectBuilt", !1);
1763
- var b, v, C, T, A, P, D, $, _;
1764
- this.root = e, this.me = t, this.h = i, this.cfg = n, Bt(), e.classList.add("ocw"), n.accent && e.style.setProperty("--ocw-accent", n.accent);
1765
+ var m, w, v, B, U, P, A, C, H;
1766
+ this.root = e, this.me = t, this.h = i, this.cfg = n, zt(), e.classList.add("ocw"), n.accent && e.style.setProperty("--ocw-accent", n.accent);
1765
1767
  const o = a("div", "ocw-head"), c = a("div", "ocw-avatar");
1766
- if ((b = n.userInfo) != null && b.avatar) {
1768
+ if ((m = n.userInfo) != null && m.avatar) {
1767
1769
  const k = document.createElement("img");
1768
1770
  k.src = n.userInfo.avatar, k.alt = n.userInfo.name ?? "You", k.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover", c.append(k);
1769
1771
  } else
1770
- c.textContent = (v = n.userInfo) != null && v.name ? n.userInfo.name[0].toUpperCase() : "🧑";
1772
+ c.textContent = (w = n.userInfo) != null && w.name ? n.userInfo.name[0].toUpperCase() : "🧑";
1771
1773
  o.append(c);
1772
1774
  const l = a("div", "ocw-head-main");
1773
- this.headerName = a("div", "ocw-head-name", ((C = n.subject) == null ? void 0 : C.ownerLabel) ?? ((T = n.subject) == null ? void 0 : T.title) ?? ""), l.append(this.headerName), (A = n.subject) != null && A.subtitle && l.append(a("div", "ocw-head-meta", n.subject.subtitle)), o.append(l), this.statusBadge = a("span", "ocw-badge", ((P = n.subject) == null ? void 0 : P.status) ?? ""), (D = n.subject) != null && D.status || (this.statusBadge.style.display = "none"), o.append(this.statusBadge), this.e2eBadge = a("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", o.append(this.e2eBadge), this.connStatus = a("span", "ocw-conn-status"), this.connStatus.style.display = "none", o.append(this.connStatus), this.cobrowseBtn = a("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
1775
+ this.headerName = a("div", "ocw-head-name", ((v = n.subject) == null ? void 0 : v.ownerLabel) ?? ((B = n.subject) == null ? void 0 : B.title) ?? ""), l.append(this.headerName), (U = n.subject) != null && U.subtitle && l.append(a("div", "ocw-head-meta", n.subject.subtitle)), o.append(l), this.statusBadge = a("span", "ocw-badge", ((P = n.subject) == null ? void 0 : P.status) ?? ""), (A = n.subject) != null && A.status || (this.statusBadge.style.display = "none"), o.append(this.statusBadge), this.e2eBadge = a("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", o.append(this.e2eBadge), this.connStatus = a("span", "ocw-conn-status"), this.connStatus.style.display = "none", o.append(this.connStatus), this.cobrowseBtn = a("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
1774
1776
  this.cobrowseActive = !this.cobrowseActive, this.updateCobrowseUI();
1775
1777
  }), o.append(this.cobrowseBtn), o.append(a("button", "ocw-menu", "⋯")), this.chips = a("div", "ocw-chiprow"), this.scroll = a("div", "ocw-scroll"), this.subjectCard = a("div", "ocw-subject"), this.typing = a("div", "ocw-typing");
1776
1778
  const x = a("div", "ocw-typing-bubble");
1777
1779
  x.append(a("div", "ocw-typing-dot"), a("div", "ocw-typing-dot"), a("div", "ocw-typing-dot")), this.typing.append(a("div", "ocw-dot", "🧑"), x), this.quick = a("div", "ocw-quick");
1778
1780
  for (const k of n.quickReplies ?? []) {
1779
- const E = a("button", void 0, k);
1780
- E.addEventListener("click", () => {
1781
+ const K = a("button", void 0, k);
1782
+ K.addEventListener("click", () => {
1781
1783
  this.h.onSend(k), this.quick.style.display = "none";
1782
- }), this.quick.append(E);
1784
+ }), this.quick.append(K);
1783
1785
  }
1784
1786
  this.formHost = a("div", "ocw-form-host"), this.csatPanel = a("div", "ocw-csat"), this.csatPanel.style.display = "none", this.offlinePanel = a("div", "ocw-offline"), this.offlinePanel.style.display = "none", this.input = a("textarea", void 0), this.input.rows = 1, this.input.placeholder = "Message…";
1785
- const f = a("button", "ocw-sendbtn", (($ = n.i18n) == null ? void 0 : $.send) ?? "➤");
1786
- f.addEventListener("click", () => this.flushSend()), this.input.addEventListener("keydown", (k) => {
1787
+ const y = a("button", "ocw-sendbtn", ((C = n.i18n) == null ? void 0 : C.send) ?? "➤");
1788
+ y.addEventListener("click", () => this.flushSend()), this.input.addEventListener("keydown", (k) => {
1787
1789
  k.isComposing || k.keyCode === 229 || (k.key === "Enter" && !k.shiftKey ? (k.preventDefault(), this.flushSend()) : this.signalTyping());
1788
1790
  });
1789
- const m = a("button", "ocw-attach", "📎");
1790
- m.title = "Attach image or file";
1791
- const w = document.createElement("input");
1792
- w.type = "file", w.accept = "image/*,.pdf,.txt,.doc,.docx", w.style.display = "none", m.addEventListener("click", () => w.click()), w.addEventListener("change", () => {
1791
+ const b = a("button", "ocw-attach", "📎");
1792
+ b.title = "Attach image or file";
1793
+ const f = document.createElement("input");
1794
+ f.type = "file", f.accept = "image/*,.pdf,.txt,.doc,.docx", f.style.display = "none", b.addEventListener("click", () => f.click()), f.addEventListener("change", () => {
1793
1795
  var k;
1794
- (k = w.files) != null && k[0] && this.h.onAttach && this.h.onAttach(w.files[0]), w.value = "";
1796
+ (k = f.files) != null && k[0] && this.h.onAttach && this.h.onAttach(f.files[0]), f.value = "";
1795
1797
  });
1796
- const h = a("div", "ocw-input");
1797
- h.append(m, w, this.input, f);
1798
- const p = a("div", "ocw-footer");
1799
- p.innerHTML = ((_ = n.i18n) == null ? void 0 : _.poweredBy) !== void 0 ? n.i18n.poweredBy : 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = p, e.append(o, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, h, this.footer), this.cobrowseCanvas = a("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = a("div", "ocw-cobrowse-toolbar");
1798
+ const p = a("div", "ocw-input");
1799
+ p.append(b, f, this.input, y);
1800
+ const h = a("div", "ocw-footer");
1801
+ ((H = n.i18n) == null ? void 0 : H.poweredBy) !== void 0 ? h.textContent = n.i18n.poweredBy : h.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = h, e.append(o, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, p, this.footer), this.cobrowseCanvas = a("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = a("div", "ocw-cobrowse-toolbar");
1800
1802
  for (const k of ["#f5713c", "#1c1b1a", "#2563eb", "#16a34a", "#dc2626"]) {
1801
- const E = a("button", "ocw-cobrowse-swatch");
1802
- E.style.background = k, E.type = "button", k === this.cobrowseColor && E.classList.add("sel"), E.addEventListener("click", () => {
1803
+ const K = a("button", "ocw-cobrowse-swatch");
1804
+ K.style.background = k, K.type = "button", k === this.cobrowseColor && K.classList.add("sel"), K.addEventListener("click", () => {
1803
1805
  this.cobrowseColor = k;
1804
- for (const Y of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch")) Y.classList.remove("sel");
1805
- E.classList.add("sel");
1806
- }), this.cobrowseToolbar.append(E);
1806
+ for (const J of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch")) J.classList.remove("sel");
1807
+ K.classList.add("sel");
1808
+ }), this.cobrowseToolbar.append(K);
1807
1809
  }
1808
- const g = a("button", "ocw-cobrowse-clear", "Clear");
1809
- g.addEventListener("click", () => {
1810
- var k, E;
1811
- return (E = (k = this.h).onAnnotateClear) == null ? void 0 : E.call(k);
1812
- }), this.cobrowseToolbar.append(g), this.cobrowseHint = a("div", "ocw-cobrowse-hint", "🖍 Draw to point things out — visible to both sides"), e.append(this.cobrowseCanvas, this.cobrowseToolbar, this.cobrowseHint), this.bindCobrowsePointerEvents();
1810
+ const T = a("button", "ocw-cobrowse-clear", "Clear");
1811
+ T.addEventListener("click", () => {
1812
+ var k, K;
1813
+ return (K = (k = this.h).onAnnotateClear) == null ? void 0 : K.call(k);
1814
+ }), this.cobrowseToolbar.append(T), this.cobrowseHint = a("div", "ocw-cobrowse-hint", "🖍 Draw to point things out — visible to both sides"), e.append(this.cobrowseCanvas, this.cobrowseToolbar, this.cobrowseHint), this.bindCobrowsePointerEvents();
1813
1815
  }
1814
1816
  /** Returns the scroll container so history.ts can attach scroll listeners. */
1815
1817
  getScrollEl() {
@@ -1820,10 +1822,10 @@ class At {
1820
1822
  var t;
1821
1823
  (t = this.scrollCleanup) == null || t.call(this), this.scrollCleanup = e;
1822
1824
  }
1823
- /** Call when the widget is unmounted. Disconnects scroll listeners. */
1825
+ /** Call when the widget is unmounted. Disconnects scroll listeners and clears timers. */
1824
1826
  destroy() {
1825
1827
  var e;
1826
- (e = this.scrollCleanup) == null || e.call(this), this.scrollCleanup = null;
1828
+ (e = this.scrollCleanup) == null || e.call(this), this.scrollCleanup = null, this.typingTimer && (clearTimeout(this.typingTimer), this.typingTimer = null);
1827
1829
  }
1828
1830
  /** Render list rows, optionally filtered by search query. */
1829
1831
  /** Build a single WhatsApp-style conversation row. */
@@ -1838,28 +1840,28 @@ class At {
1838
1840
  this.h.onTyping(!0), this.typingTimer && clearTimeout(this.typingTimer), this.typingTimer = setTimeout(() => this.h.onTyping(!1), 2e3);
1839
1841
  }
1840
1842
  render(e) {
1841
- var f, m, w;
1843
+ var y, b, f;
1842
1844
  if (this.storeRef = e, this.cobrowseBtn.classList.toggle("show", !!e.subject), !e.subject && this.cobrowseActive && (this.cobrowseActive = !1, this.updateCobrowseUI()), this.cobrowseActive && e.annotationVersion !== this.lastAnnotationVersion && (this.lastAnnotationVersion = e.annotationVersion, this.resizeCobrowseCanvas(), this.redrawCobrowse()), e.accent && this.root.style.setProperty("--ocw-accent", e.accent), this.e2eBadge.style.display = e.e2e ? "inline-flex" : "none", this.buildSubjectCard(e), e.subject) {
1843
- const h = (f = this.cfg.subject) == null ? void 0 : f.ownerLabel;
1844
- h && (this.headerName.textContent = h);
1845
+ const p = (y = this.cfg.subject) == null ? void 0 : y.ownerLabel;
1846
+ p && (this.headerName.textContent = p);
1845
1847
  }
1846
1848
  this.chips.replaceChildren();
1847
1849
  const t = e.visibleActions();
1848
1850
  this.chips.style.display = t.length ? "flex" : "none";
1849
- for (const h of t) this.chips.append(this.chipEl(h));
1851
+ for (const p of t) this.chips.append(this.chipEl(p));
1850
1852
  const i = this.scroll.scrollHeight, n = this.scroll.scrollTop;
1851
1853
  if (this.scroll.replaceChildren(), this.subjectCard.childNodes.length && this.scroll.append(this.subjectCard), e.hasMoreHistory) {
1852
- const h = a("div", "ocw-load-more");
1853
- h.textContent = "↑ Loading earlier messages…", h.style.pointerEvents = "none", this.scroll.append(h);
1854
+ const p = a("div", "ocw-load-more");
1855
+ p.textContent = "↑ Loading earlier messages…", p.style.pointerEvents = "none", this.scroll.append(p);
1854
1856
  }
1855
1857
  let o = 0;
1856
- for (const h of e.messages())
1857
- this.scroll.append(this.messageEl(h, e)), h.senderId !== this.me && h.seq > o && (o = h.seq);
1858
+ for (const p of e.messages())
1859
+ this.scroll.append(this.messageEl(p, e)), p.senderId !== this.me && p.seq > o && (o = p.seq);
1858
1860
  n > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - i + n : this.scroll.scrollTop = this.scroll.scrollHeight, o > 0 && this.h.onReadUpTo(o);
1859
1861
  const c = [...e.typing];
1860
1862
  this.typing.classList.toggle("active", c.length > 0);
1861
1863
  const l = this.typing.querySelector(".ocw-typing-bubble");
1862
- l && l.setAttribute("aria-label", c.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (m = this.root.querySelector(".ocw-input")) == null || m.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (w = this.root.querySelector(".ocw-input")) == null || w.style.removeProperty("display"));
1864
+ l && l.setAttribute("aria-label", c.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (b = this.root.querySelector(".ocw-input")) == null || b.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (f = this.root.querySelector(".ocw-input")) == null || f.style.removeProperty("display"));
1863
1865
  const x = ["resolved", "closed", "sold", "issued", "checked_out"];
1864
1866
  this.h.onCsat && !this.csatSubmitted && x.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
1865
1867
  }
@@ -1929,8 +1931,8 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-t
1929
1931
  bindCobrowsePointerEvents() {
1930
1932
  let e = !1, t = [];
1931
1933
  const i = (c) => {
1932
- const l = this.cobrowseCanvas.getBoundingClientRect(), x = l.width > 0 ? (c.clientX - l.left) / l.width : 0, f = l.height > 0 ? (c.clientY - l.top) / l.height : 0;
1933
- return { x: Math.min(1, Math.max(0, x)), y: Math.min(1, Math.max(0, f)) };
1934
+ const l = this.cobrowseCanvas.getBoundingClientRect(), x = l.width > 0 ? (c.clientX - l.left) / l.width : 0, y = l.height > 0 ? (c.clientY - l.top) / l.height : 0;
1935
+ return { x: Math.min(1, Math.max(0, x)), y: Math.min(1, Math.max(0, y)) };
1934
1936
  }, n = 6e-3;
1935
1937
  this.cobrowseCanvas.addEventListener("pointerdown", (c) => {
1936
1938
  this.cobrowseActive && (e = !0, t = [i(c)], this.cobrowseCanvas.setPointerCapture(c.pointerId));
@@ -1973,11 +1975,11 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-t
1973
1975
  return new Promise((t) => {
1974
1976
  const i = a("div", "ocw-modal"), n = a("div", "ocw-modal-card");
1975
1977
  n.append(a("div", "ocw-modal-title", e)), n.append(a("div", "ocw-modal-body", `Confirm “${e}”?`));
1976
- const o = a("div", "ocw-modal-actions"), c = a("button", "ocw-modal-cancel", "Cancel"), l = a("button", "ocw-modal-ok", "Confirm"), x = (f) => {
1977
- i.remove(), t(f);
1978
+ const o = a("div", "ocw-modal-actions"), c = a("button", "ocw-modal-cancel", "Cancel"), l = a("button", "ocw-modal-ok", "Confirm"), x = (y) => {
1979
+ i.remove(), t(y);
1978
1980
  };
1979
- c.addEventListener("click", () => x(!1)), l.addEventListener("click", () => x(!0)), i.addEventListener("click", (f) => {
1980
- f.target === i && x(!1);
1981
+ c.addEventListener("click", () => x(!1)), l.addEventListener("click", () => x(!0)), i.addEventListener("click", (y) => {
1982
+ y.target === i && x(!1);
1981
1983
  }), o.append(c, l), n.append(o), i.append(n), this.root.append(i), l.focus();
1982
1984
  });
1983
1985
  }
@@ -1989,148 +1991,163 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-t
1989
1991
  const t = a("div", "ocw-form");
1990
1992
  t.append(a("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
1991
1993
  const i = /* @__PURE__ */ new Map();
1992
- for (const f of e.input ?? []) {
1993
- const m = a("label", "ocw-form-row");
1994
- if (m.append(a("span", "ocw-form-lbl", f.label)), f.type === "select" && ((l = f.options) != null && l.length)) {
1995
- const w = a("select", "ocw-form-input");
1996
- f.required || w.append(a("option", void 0, "— select —"));
1997
- for (const h of f.options) {
1998
- const p = a("option");
1999
- p.value = h, p.textContent = h, w.append(p);
1994
+ for (const y of e.input ?? []) {
1995
+ const b = a("label", "ocw-form-row");
1996
+ if (b.append(a("span", "ocw-form-lbl", y.label)), y.type === "select" && ((l = y.options) != null && l.length)) {
1997
+ const f = a("select", "ocw-form-input");
1998
+ y.required || f.append(a("option", void 0, "— select —"));
1999
+ for (const p of y.options) {
2000
+ const h = a("option");
2001
+ h.value = p, h.textContent = p, f.append(h);
2000
2002
  }
2001
- f.required && (w.required = !0), m.append(w), i.set(f.name, w);
2003
+ y.required && (f.required = !0), b.append(f), i.set(y.name, f);
2002
2004
  } else {
2003
- const w = a("input", "ocw-form-input");
2004
- w.type = f.type === "number" ? "number" : f.type === "date" ? "datetime-local" : "text", f.required && (w.required = !0), m.append(w), i.set(f.name, w);
2005
+ const f = a("input", "ocw-form-input");
2006
+ f.type = y.type === "number" ? "number" : y.type === "date" ? "datetime-local" : "text", y.required && (f.required = !0), b.append(f), i.set(y.name, f);
2005
2007
  }
2006
- t.append(m);
2008
+ t.append(b);
2007
2009
  }
2008
2010
  const n = a("div", "ocw-form-actions"), o = a("button", "ocw-form-cancel", "Cancel"), c = a("button", "ocw-form-submit", "Send");
2009
2011
  o.addEventListener("click", () => this.formHost.replaceChildren()), c.addEventListener("click", () => {
2010
- const f = {};
2011
- for (const [m, w] of i) {
2012
- if (w.required && !w.value) {
2013
- w.style.borderColor = "#e5484d";
2012
+ const y = {};
2013
+ for (const [b, f] of i) {
2014
+ if (f.required && !f.value) {
2015
+ f.style.borderColor = "#e5484d";
2014
2016
  return;
2015
2017
  }
2016
- f[m] = w.type === "number" ? Number(w.value) : w.value;
2018
+ y[b] = f.type === "number" ? Number(f.value) : f.value;
2017
2019
  }
2018
- this.formHost.replaceChildren(), this.h.onInvoke(e.id, f);
2020
+ this.formHost.replaceChildren(), this.h.onInvoke(e.id, y);
2019
2021
  }), n.append(o, c), t.append(n), this.formHost.append(t), (x = i.values().next().value) == null || x.focus();
2020
2022
  }
2021
2023
  messageEl(e, t) {
2022
- var w;
2024
+ var f;
2023
2025
  if (e.senderRole === "system") {
2024
- const h = a("div", "ocw-sys");
2025
- return h.textContent = e.deletedAt ? "message deleted" : G(e.content), h;
2026
+ const p = a("div", "ocw-sys");
2027
+ return p.textContent = e.deletedAt ? "message deleted" : Z(e.content), p;
2026
2028
  }
2027
2029
  const i = e.senderId === this.me, n = !!e.internal, o = a("div", `ocw-row ${n ? "ocw-note mine" : i ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
2028
2030
  !i && !n && o.append(a("div", "ocw-dot", e.senderRole === "bot" ? "🤖" : "🧑"));
2029
2031
  const c = a("div"), l = a("div", "ocw-bubble-wrap");
2030
2032
  if (e.replyToId) {
2031
- const h = a("div", "ocw-reply-to", "↩ replying to a message");
2032
- h.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", c.append(h);
2033
+ const p = a("div", "ocw-reply-to", "↩ replying to a message");
2034
+ p.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", c.append(p);
2033
2035
  }
2034
2036
  const x = a("div", "ocw-bubble");
2035
- let f = null;
2037
+ let y = null;
2036
2038
  if (e.deletedAt) x.append(a("span", "ocw-deleted", "message deleted"));
2037
2039
  else if (e.content.kind === "attachment") {
2038
- const h = e.content;
2039
- if ((w = h.mime) != null && w.startsWith("image/")) {
2040
- const p = document.createElement("img");
2041
- p.src = h.url, p.alt = h.name ?? "image", p.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", p.addEventListener("click", () => window.open(h.url, "_blank")), x.append(p);
2040
+ const p = e.content;
2041
+ if ((f = p.mime) != null && f.startsWith("image/")) {
2042
+ const h = document.createElement("img");
2043
+ h.src = p.url, h.alt = p.name ?? "image", h.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", h.addEventListener("click", () => window.open(p.url, "_blank")), x.append(h);
2042
2044
  } else {
2043
- const p = document.createElement("a");
2044
- p.href = h.url, p.target = "_blank", p.rel = "noopener", p.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", p.append(a("span", void 0, "📄"), a("span", void 0, h.name ?? "file")), x.append(p);
2045
+ const h = document.createElement("a");
2046
+ h.href = p.url, h.target = "_blank", h.rel = "noopener", h.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", h.append(a("span", void 0, "📄"), a("span", void 0, p.name ?? "file")), x.append(h);
2045
2047
  }
2046
2048
  } else if (e.content.kind === "appointment") {
2047
- const h = e.content, p = a("div", "ocw-appt");
2048
- p.append(a("div", "ocw-appt-title", `📅 ${h.title}`)), p.append(a("div", "ocw-appt-time", new Date(h.startIso).toLocaleString() + " – " + new Date(h.endIso).toLocaleTimeString())), h.location && p.append(a("div", "ocw-appt-loc", `📍 ${h.location}`)), h.description && p.append(a("div", "ocw-appt-desc", h.description));
2049
- const g = a("div", "ocw-appt-links"), b = document.createElement("a");
2050
- b.href = h.googleUrl, b.target = "_blank", b.rel = "noopener", b.className = "ocw-appt-btn", b.textContent = "📅 Add to Google Calendar";
2051
- const v = document.createElement("a");
2052
- v.href = h.icalUrl, v.download = `${h.title}.ics`, v.className = "ocw-appt-btn ocw-appt-btn-sec", v.textContent = "🍎 Apple / iCal", g.append(b, v), p.append(g), x.append(p);
2049
+ const p = e.content, h = a("div", "ocw-appt");
2050
+ h.append(a("div", "ocw-appt-title", `📅 ${p.title}`)), h.append(a("div", "ocw-appt-time", new Date(p.startIso).toLocaleString() + " – " + new Date(p.endIso).toLocaleTimeString())), p.location && h.append(a("div", "ocw-appt-loc", `📍 ${p.location}`)), p.description && h.append(a("div", "ocw-appt-desc", p.description));
2051
+ const T = a("div", "ocw-appt-links"), m = document.createElement("a");
2052
+ m.href = p.googleUrl, m.target = "_blank", m.rel = "noopener", m.className = "ocw-appt-btn", m.textContent = "📅 Add to Google Calendar";
2053
+ const w = document.createElement("a");
2054
+ w.href = p.icalUrl, w.download = `${p.title}.ics`, w.className = "ocw-appt-btn ocw-appt-btn-sec", w.textContent = "🍎 Apple / iCal", T.append(m, w), h.append(T), x.append(h);
2053
2055
  } else
2054
- f = document.createTextNode(G(e.content)), x.append(f), e.editedAt && x.append(a("span", "ocw-edited", "(edited)"));
2055
- if (l.append(x), !i && !n && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && f) {
2056
- const h = e.content.text;
2057
- if (h.trim()) {
2058
- const p = a("button", "ocw-translate-btn", "🌐");
2059
- p.type = "button", p.title = "Translate", p.addEventListener("click", (g) => {
2060
- if (g.stopPropagation(), this.showingTranslation.has(e.id)) {
2061
- this.showingTranslation.delete(e.id), f.textContent = h, p.textContent = "🌐", p.title = "Translate";
2056
+ y = document.createTextNode(Z(e.content)), x.append(y), e.editedAt && x.append(a("span", "ocw-edited", "(edited)"));
2057
+ if (l.append(x), !i && !n && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && y) {
2058
+ const p = e.content.text;
2059
+ if (p.trim()) {
2060
+ const h = a("button", "ocw-translate-btn", "🌐");
2061
+ h.type = "button", h.title = "Translate", h.addEventListener("click", (T) => {
2062
+ if (T.stopPropagation(), this.showingTranslation.has(e.id)) {
2063
+ this.showingTranslation.delete(e.id), y.textContent = p, h.textContent = "🌐", h.title = "Translate";
2062
2064
  return;
2063
2065
  }
2064
- const b = this.translationCache.get(e.id);
2065
- if (b !== void 0) {
2066
- this.showingTranslation.add(e.id), f.textContent = b, p.textContent = "↩", p.title = "Show original";
2066
+ const m = this.translationCache.get(e.id);
2067
+ if (m !== void 0) {
2068
+ this.showingTranslation.add(e.id), y.textContent = m, h.textContent = "↩", h.title = "Show original";
2067
2069
  return;
2068
2070
  }
2069
- p.textContent = "⏳", this.h.onTranslate(h).then((v) => {
2070
- if (v === null) {
2071
- p.textContent = "⚠️", p.title = "Translation unavailable", setTimeout(() => {
2072
- p.textContent = "🌐", p.title = "Translate";
2071
+ h.textContent = "⏳", this.h.onTranslate(p).then((w) => {
2072
+ if (w === null) {
2073
+ h.textContent = "⚠️", h.title = "Translation unavailable", setTimeout(() => {
2074
+ h.textContent = "🌐", h.title = "Translate";
2073
2075
  }, 1500);
2074
2076
  return;
2075
2077
  }
2076
- this.translationCache.set(e.id, v), this.showingTranslation.add(e.id), f.textContent = v, p.textContent = "↩", p.title = "Show original";
2078
+ this.translationCache.set(e.id, w), this.showingTranslation.add(e.id), y.textContent = w, h.textContent = "↩", h.title = "Show original";
2077
2079
  });
2078
- }), l.append(p);
2080
+ }), l.append(h);
2079
2081
  }
2080
2082
  }
2081
2083
  if (i && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
2082
- const h = a("div", "ocw-msg-menu");
2084
+ const p = a("div", "ocw-msg-menu");
2083
2085
  if (this.h.onEdit) {
2084
- const p = a("button", void 0, "✏️");
2085
- p.title = "Edit", p.addEventListener("click", (g) => {
2086
- g.stopPropagation();
2087
- const b = G(e.content), v = prompt("Edit message:", b);
2088
- v !== null && v.trim() && v !== b && this.h.onEdit(e.id, v.trim());
2089
- }), h.append(p);
2086
+ const h = a("button", void 0, "✏️");
2087
+ h.title = "Edit", h.addEventListener("click", (T) => {
2088
+ T.stopPropagation();
2089
+ const m = Z(e.content), w = document.createElement("textarea");
2090
+ w.value = m, w.rows = Math.min(4, Math.ceil(m.length / 40) + 1), w.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:#fff;color:#1c1b1a;box-sizing:border-box";
2091
+ const v = a("button", "ocw-form-submit", "Save");
2092
+ v.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
2093
+ const B = a("button", "ocw-form-cancel", "Cancel");
2094
+ B.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
2095
+ const U = a("div");
2096
+ U.style.cssText = "display:flex;gap:6px;justify-content:flex-end", U.append(B, v);
2097
+ const P = a("div");
2098
+ P.append(w, U), x.replaceChildren(P), w.focus(), w.select();
2099
+ const A = () => x.replaceChildren(y ?? document.createTextNode(m));
2100
+ B.addEventListener("click", A), v.addEventListener("click", () => {
2101
+ const C = w.value.trim();
2102
+ C && C !== m && this.h.onEdit(e.id, C), A();
2103
+ }), w.addEventListener("keydown", (C) => {
2104
+ C.key === "Enter" && !C.shiftKey && (C.preventDefault(), v.click()), C.key === "Escape" && A();
2105
+ });
2106
+ }), p.append(h);
2090
2107
  }
2091
2108
  if (this.h.onDelete) {
2092
- const p = a("button", "del", "🗑");
2093
- p.title = "Delete", p.addEventListener("click", (g) => {
2094
- g.stopPropagation(), this.h.onDelete(e.id);
2095
- }), h.append(p);
2109
+ const h = a("button", "del", "🗑");
2110
+ h.title = "Delete", h.addEventListener("click", (T) => {
2111
+ T.stopPropagation(), this.h.onDelete(e.id);
2112
+ }), p.append(h);
2096
2113
  }
2097
- l.append(h);
2114
+ l.append(p);
2098
2115
  }
2099
2116
  if (c.append(l), this.h.onReact && !e.deletedAt && e.seq > 0) {
2100
- const h = a("div", "ocw-react-wrap"), p = a("div", "ocw-react");
2117
+ const p = a("div", "ocw-react-wrap"), h = a("div", "ocw-react");
2101
2118
  if (e.reactions && Object.keys(e.reactions).length)
2102
- for (const [v, C] of Object.entries(e.reactions)) {
2103
- const T = a("button", `ocw-react-pill${C.includes(this.me) ? " mine" : ""}`, `${v} ${C.length}`);
2104
- T.addEventListener("click", () => {
2105
- var A, P;
2106
- return (P = (A = this.h).onReact) == null ? void 0 : P.call(A, e.id, v, C.includes(this.me));
2107
- }), p.append(T);
2119
+ for (const [w, v] of Object.entries(e.reactions)) {
2120
+ const B = a("button", `ocw-react-pill${v.includes(this.me) ? " mine" : ""}`, `${w} ${v.length}`);
2121
+ B.addEventListener("click", () => {
2122
+ var U, P;
2123
+ return (P = (U = this.h).onReact) == null ? void 0 : P.call(U, e.id, w, v.includes(this.me));
2124
+ }), h.append(B);
2108
2125
  }
2109
- const g = a("button", "ocw-react-btn", "+"), b = a("div", "ocw-react-picker");
2110
- for (const v of Tt) {
2111
- const C = a("button", void 0, v);
2112
- C.addEventListener("click", (T) => {
2113
- var P, D, $, _;
2114
- T.stopPropagation();
2115
- const A = (D = (P = e.reactions) == null ? void 0 : P[v]) == null ? void 0 : D.includes(this.me);
2116
- (_ = ($ = this.h).onReact) == null || _.call($, e.id, v, !!A), b.style.display = "none";
2117
- }), b.append(C);
2126
+ const T = a("button", "ocw-react-btn", "+"), m = a("div", "ocw-react-picker");
2127
+ for (const w of Kt) {
2128
+ const v = a("button", void 0, w);
2129
+ v.addEventListener("click", (B) => {
2130
+ var P, A, C, H;
2131
+ B.stopPropagation();
2132
+ const U = (A = (P = e.reactions) == null ? void 0 : P[w]) == null ? void 0 : A.includes(this.me);
2133
+ (H = (C = this.h).onReact) == null || H.call(C, e.id, w, !!U), m.style.display = "none";
2134
+ }), m.append(v);
2118
2135
  }
2119
- b.style.display = "none", g.addEventListener("click", (v) => {
2120
- v.stopPropagation(), b.style.display = b.style.display === "none" ? "flex" : "none";
2136
+ m.style.display = "none", T.addEventListener("click", (w) => {
2137
+ w.stopPropagation(), m.style.display = m.style.display === "none" ? "flex" : "none";
2121
2138
  }), document.addEventListener("click", () => {
2122
- b.style.display = "none";
2123
- }, { once: !0 }), p.append(g), h.append(p, b), c.append(h);
2124
- } else e.reactions && Object.keys(e.reactions).length && c.append(a("div", "ocw-react", Object.entries(e.reactions).map(([h, p]) => `${h}${p.length}`).join(" ")));
2125
- const m = a("div", "ocw-time ocw-meta", Kt(e.ts));
2139
+ m.style.display = "none";
2140
+ }, { once: !0 }), h.append(T), p.append(h, m), c.append(p);
2141
+ } else e.reactions && Object.keys(e.reactions).length && c.append(a("div", "ocw-react", Object.entries(e.reactions).map(([p, h]) => `${p}${h.length}`).join(" ")));
2142
+ const b = a("div", "ocw-time ocw-meta", Lt(e.ts));
2126
2143
  if (i && e.status) {
2127
- const h = a("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, zt(e.status));
2128
- m.append(h);
2144
+ const p = a("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Dt(e.status));
2145
+ b.append(p);
2129
2146
  }
2130
- return i && e.seq > 0 && t.lastReadByOthers >= e.seq && m.append(a("span", "ocw-seen", " · Seen")), c.append(m), o.append(c), o;
2147
+ return i && e.seq > 0 && t.lastReadByOthers >= e.seq && b.append(a("span", "ocw-seen", " · Seen")), c.append(b), o.append(c), o;
2131
2148
  }
2132
2149
  }
2133
- function zt(s) {
2150
+ function Dt(s) {
2134
2151
  switch (s) {
2135
2152
  case "read":
2136
2153
  return "✓✓";
@@ -2142,47 +2159,49 @@ function zt(s) {
2142
2159
  return "🕓";
2143
2160
  }
2144
2161
  }
2145
- function $t(s) {
2146
- var se, oe, re, ae;
2147
- const e = s.token ?? Ee();
2148
- let t = new pt(e);
2149
- const i = s.subjectId ? `${e}::${s.subjectId}` : e, n = new xt(i);
2150
- let o, c = !1, l = null;
2162
+ function Rt(s) {
2163
+ var oe, re, ae, ce;
2164
+ const e = s.token ?? Ue();
2165
+ let t = new wt(e);
2166
+ const i = s.subjectId ? `${e}::${s.subjectId}` : e, n = new bt(i);
2167
+ let o, c = !1, l = null, x = null, y = null;
2151
2168
  !s.launcher && !s.el.style.height && s.el.clientHeight === 0 && (s.el.style.width = s.el.style.width || "100%", s.el.style.height = "600px");
2152
2169
  for (const d of n.load()) t.addOptimistic(d.clientMsgId, d.content);
2153
- let x = null, f = null, m = 0, w = !s.launcher;
2170
+ let b = null, f = null, p = 0, h = !s.launcher;
2154
2171
  if (s.launcher) {
2155
2172
  const u = (s.position ?? "bottom-right").includes("right");
2156
- x = document.createElement("div"), x.style.cssText = `position:fixed;${u ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${u ? "flex-end" : "flex-start"};gap:12px`;
2157
- const y = document.createElement("div"), B = typeof window < "u" && window.innerWidth < 480;
2158
- y.style.cssText = B ? [
2159
- "position:fixed",
2160
- "inset:0",
2161
- "width:100%",
2162
- "height:100%",
2163
- "border-radius:0",
2164
- "overflow:hidden",
2165
- "box-shadow:none",
2166
- "display:none",
2167
- "flex-direction:column",
2168
- "background:#fff",
2169
- "transition:opacity .18s",
2170
- "opacity:0",
2171
- "z-index:9998"
2172
- ].join(";") : [
2173
- "width:380px",
2174
- "height:600px",
2175
- "border-radius:16px",
2176
- "overflow:hidden",
2177
- "box-shadow:0 8px 40px rgba(0,0,0,.18)",
2178
- "display:none",
2179
- "flex-direction:column",
2180
- "background:#fff",
2181
- "transform-origin:bottom " + (u ? "right" : "left"),
2182
- "transition:opacity .18s,transform .18s",
2183
- "opacity:0",
2184
- "transform:scale(.95)"
2185
- ].join(";"), s.el.style.cssText = "width:100%;height:100%;overflow:hidden", y.append(s.el);
2173
+ b = document.createElement("div"), b.style.cssText = `position:fixed;${u ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${u ? "flex-end" : "flex-start"};gap:12px`;
2174
+ const g = document.createElement("div"), E = typeof window < "u" ? window.matchMedia("(max-width: 479px)") : null, M = (D) => {
2175
+ g.style.cssText = D ? [
2176
+ "position:fixed",
2177
+ "inset:0",
2178
+ "width:100%",
2179
+ "height:100%",
2180
+ "border-radius:0",
2181
+ "overflow:hidden",
2182
+ "box-shadow:none",
2183
+ "display:none",
2184
+ "flex-direction:column",
2185
+ "background:#fff",
2186
+ "transition:opacity .18s",
2187
+ "opacity:0",
2188
+ "z-index:9998"
2189
+ ].join(";") : [
2190
+ "width:380px",
2191
+ "height:600px",
2192
+ "border-radius:16px",
2193
+ "overflow:hidden",
2194
+ "box-shadow:0 8px 40px rgba(0,0,0,.18)",
2195
+ "display:none",
2196
+ "flex-direction:column",
2197
+ "background:#fff",
2198
+ "transform-origin:bottom " + (u ? "right" : "left"),
2199
+ "transition:opacity .18s,transform .18s",
2200
+ "opacity:0",
2201
+ "transform:scale(.95)"
2202
+ ].join(";");
2203
+ };
2204
+ M((E == null ? void 0 : E.matches) ?? !1), E == null || E.addEventListener("change", (D) => M(D.matches)), x = E, y = M, s.el.style.cssText = "width:100%;height:100%;overflow:hidden", g.append(s.el);
2186
2205
  const I = document.createElement("button");
2187
2206
  I.style.cssText = [
2188
2207
  "width:56px;height:56px;border-radius:50%",
@@ -2195,104 +2214,104 @@ function $t(s) {
2195
2214
  I.style.transform = "scale(1.08)";
2196
2215
  }, I.onmouseleave = () => {
2197
2216
  I.style.transform = "scale(1)";
2198
- }, f = document.createElement("span"), f.style.cssText = "position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center", I.append(f), x.append(y, I), document.body.append(x);
2199
- const z = (R) => {
2200
- R ? (y.style.display = "flex", requestAnimationFrame(() => {
2201
- y.style.opacity = "1", y.style.transform = "scale(1)";
2202
- })) : (y.style.opacity = "0", y.style.transform = "scale(.95)", setTimeout(() => {
2203
- w || (y.style.display = "none");
2217
+ }, f = document.createElement("span"), f.style.cssText = "position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center", I.append(f), b.append(g, I), document.body.append(b);
2218
+ const N = (D) => {
2219
+ D ? (g.style.display = "flex", requestAnimationFrame(() => {
2220
+ g.style.opacity = "1", g.style.transform = "scale(1)";
2221
+ })) : (g.style.opacity = "0", g.style.transform = "scale(.95)", setTimeout(() => {
2222
+ h || (g.style.display = "none");
2204
2223
  }, 180));
2205
2224
  };
2206
2225
  I.addEventListener("click", () => {
2207
- w = !w, z(w), I.textContent = w ? "✕" : "💬", I.append(f), w && (m = 0, f && (f.style.display = "none"));
2208
- }), document.addEventListener("keydown", (R) => {
2209
- R.key === "Escape" && w && (w = !1, z(!1), I.textContent = "💬", I.append(f));
2226
+ h = !h, N(h), I.textContent = h ? "✕" : "💬", I.append(f), h && (p = 0, f && (f.style.display = "none"));
2227
+ }), document.addEventListener("keydown", (D) => {
2228
+ D.key === "Escape" && h && (h = !1, N(!1), I.textContent = "💬", I.append(f));
2210
2229
  });
2211
2230
  }
2212
- const h = () => {
2213
- w || (m++, f && (f.textContent = String(m), f.style.display = "flex"));
2214
- }, p = () => {
2231
+ const T = () => {
2232
+ h || (p++, f && (f.textContent = String(p), f.style.display = "flex"));
2233
+ }, m = () => {
2215
2234
  try {
2216
- const d = new AudioContext(), u = d.createOscillator(), y = d.createGain();
2217
- u.connect(y), y.connect(d.destination), u.frequency.setValueAtTime(880, d.currentTime), u.frequency.exponentialRampToValueAtTime(440, d.currentTime + 0.15), y.gain.setValueAtTime(0.3, d.currentTime), y.gain.exponentialRampToValueAtTime(1e-3, d.currentTime + 0.3), u.start(), u.stop(d.currentTime + 0.3);
2235
+ const d = new AudioContext(), u = d.createOscillator(), g = d.createGain();
2236
+ u.connect(g), g.connect(d.destination), u.frequency.setValueAtTime(880, d.currentTime), u.frequency.exponentialRampToValueAtTime(440, d.currentTime + 0.15), g.gain.setValueAtTime(0.3, d.currentTime), g.gain.exponentialRampToValueAtTime(1e-3, d.currentTime + 0.3), u.start(), u.stop(d.currentTime + 0.3);
2218
2237
  } catch {
2219
2238
  }
2220
2239
  };
2221
- let g;
2222
- const b = new Et(`ocw-e2e-${s.profileId}`);
2223
- let v = !1;
2224
- const C = [], T = [];
2240
+ let w;
2241
+ const v = new Pt(`ocw-e2e-${s.profileId}`);
2242
+ let B = !1;
2243
+ const U = [], P = [];
2225
2244
  let A = !1;
2226
- const P = (d, u) => {
2227
- b.sealText(u).then((y) => {
2228
- o && g.send({ type: "send", conversationId: o, clientMsgId: d, content: y });
2245
+ const C = (d, u) => {
2246
+ v.sealText(u).then((g) => {
2247
+ o && w.send({ type: "send", conversationId: o, clientMsgId: d, content: g });
2229
2248
  });
2230
- }, D = (d, u, y) => {
2231
- b.sealText(u, y).then((B) => {
2232
- o && g.send({ type: "send", conversationId: o, clientMsgId: d, content: B });
2249
+ }, H = (d, u, g) => {
2250
+ v.sealText(u, g).then((E) => {
2251
+ o && w.send({ type: "send", conversationId: o, clientMsgId: d, content: E });
2233
2252
  });
2234
- }, $ = () => {
2235
- for (; C.length; ) {
2236
- const d = C.shift();
2237
- P(d.clientMsgId, d.text);
2253
+ }, k = () => {
2254
+ for (; U.length; ) {
2255
+ const d = U.shift();
2256
+ C(d.clientMsgId, d.text);
2238
2257
  }
2239
- for (; T.length; ) {
2240
- const d = T.shift();
2241
- P(d.clientMsgId, d.text);
2258
+ for (; P.length; ) {
2259
+ const d = P.shift();
2260
+ C(d.clientMsgId, d.text);
2242
2261
  }
2243
- }, _ = (d) => {
2244
- g.send({ type: "fetchPrekey", targetUserId: d });
2245
- }, k = s.i18n ?? {}, E = ["ar", "he", "fa", "ur"], Y = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
2246
- E.includes(Y) && !s.el.dir && (s.el.dir = "rtl", s.el.style.fontFamily = s.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
2247
- const K = new At(s.el, e, {
2262
+ }, K = (d) => {
2263
+ w.send({ type: "fetchPrekey", targetUserId: d });
2264
+ }, J = s.i18n ?? {}, me = ["ar", "he", "fa", "ur"], ve = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
2265
+ me.includes(ve) && !s.el.dir && (s.el.dir = "rtl", s.el.style.fontFamily = s.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
2266
+ const L = new Mt(s.el, e, {
2248
2267
  onSend(d) {
2249
2268
  if (!o) return;
2250
2269
  const u = `cm_${Math.random().toString(36).slice(2)}`;
2251
- t.addOptimistic(u, { kind: "text", text: d }), K.render(t), t.e2e ? b.ready ? P(u, d) : A ? T.push({ clientMsgId: u, text: d }) : (C.push({ clientMsgId: u, text: d }), t.assignedAgentId && _(t.assignedAgentId)) : (n.add({ clientMsgId: u, content: { kind: "text", text: d }, ts: Date.now() }), g.send({ type: "send", conversationId: o, clientMsgId: u, content: { kind: "text", text: d } }));
2270
+ t.addOptimistic(u, { kind: "text", text: d }), L.render(t), t.e2e ? v.ready ? C(u, d) : A ? P.push({ clientMsgId: u, text: d }) : (U.push({ clientMsgId: u, text: d }), t.assignedAgentId && K(t.assignedAgentId)) : (n.add({ clientMsgId: u, content: { kind: "text", text: d }, ts: Date.now() }), w.send({ type: "send", conversationId: o, clientMsgId: u, content: { kind: "text", text: d } }));
2252
2271
  },
2253
2272
  async onAttach(d) {
2254
2273
  if (!o) return;
2255
- const B = `${s.url.replace(/^ws/, "http").replace(/\/ws$/, "")}/upload?name=${encodeURIComponent(d.name)}`, I = `cm_${Math.random().toString(36).slice(2)}`;
2256
- t.addOptimistic(I, { kind: "text", text: `📎 Uploading ${d.name}…` }), K.render(t);
2274
+ const E = `${s.url.replace(/^ws/, "http").replace(/\/ws$/, "")}/upload?name=${encodeURIComponent(d.name)}`, M = `cm_${Math.random().toString(36).slice(2)}`;
2275
+ t.addOptimistic(M, { kind: "text", text: `📎 Uploading ${d.name}…` }), L.render(t);
2257
2276
  try {
2258
- const z = await fetch(B, {
2277
+ const I = await fetch(E, {
2259
2278
  method: "POST",
2260
2279
  headers: { "content-type": d.type, ...s.token ? { authorization: `Bearer ${s.token}` } : {} },
2261
2280
  body: d
2262
2281
  });
2263
- if (!z.ok) throw new Error(`Upload failed: ${z.status}`);
2264
- const { url: R, name: ve, mime: ke, size: Se } = await z.json();
2265
- g.send({ type: "send", conversationId: o, clientMsgId: I, content: { kind: "attachment", url: R, name: ve, mime: ke, size: Se } });
2266
- } catch (z) {
2267
- t.addOptimistic(I, { kind: "text", text: `⚠️ Upload failed: ${z.message}` }), K.render(t);
2282
+ if (!I.ok) throw new Error(`Upload failed: ${I.status}`);
2283
+ const { url: N, name: D, mime: Ie, size: Ce } = await I.json();
2284
+ w.send({ type: "send", conversationId: o, clientMsgId: M, content: { kind: "attachment", url: N, name: D, mime: Ie, size: Ce } });
2285
+ } catch (I) {
2286
+ t.addOptimistic(M, { kind: "text", text: `⚠️ Upload failed: ${I.message}` }), L.render(t);
2268
2287
  }
2269
2288
  },
2270
2289
  onInvoke(d, u) {
2271
- o && g.send({ type: "invoke", conversationId: o, actionId: d, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...u ? { inputs: u } : {} });
2290
+ o && w.send({ type: "invoke", conversationId: o, actionId: d, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...u ? { inputs: u } : {} });
2272
2291
  },
2273
2292
  onTyping(d) {
2274
- o && g.send({ type: "typing", conversationId: o, isTyping: d });
2293
+ o && w.send({ type: "typing", conversationId: o, isTyping: d });
2275
2294
  },
2276
2295
  onReadUpTo(d) {
2277
- o && g.send({ type: "read", conversationId: o, seq: d });
2296
+ o && w.send({ type: "read", conversationId: o, seq: d });
2278
2297
  },
2279
2298
  onLoadMore() {
2280
2299
  if (!o || !t.e2e) return;
2281
2300
  const d = t.messages()[0];
2282
- d && g.send({ type: "history", conversationId: o, beforeSeq: d.seq, limit: 20 });
2301
+ d && w.send({ type: "history", conversationId: o, beforeSeq: d.seq, limit: 20 });
2283
2302
  },
2284
2303
  onEdit(d, u) {
2285
- o && g.send({ type: "edit", conversationId: o, messageId: d, content: { kind: "text", text: u } });
2304
+ o && w.send({ type: "edit", conversationId: o, messageId: d, content: { kind: "text", text: u } });
2286
2305
  },
2287
2306
  onDelete(d) {
2288
- o && g.send({ type: "delete", conversationId: o, messageId: d });
2307
+ o && w.send({ type: "delete", conversationId: o, messageId: d });
2289
2308
  },
2290
- onReact(d, u, y) {
2291
- o && g.send({ type: "react", conversationId: o, messageId: d, emoji: u, remove: y });
2309
+ onReact(d, u, g) {
2310
+ o && w.send({ type: "react", conversationId: o, messageId: d, emoji: u, remove: g });
2292
2311
  },
2293
2312
  onCsat(d) {
2294
2313
  if (!o) return;
2295
- const u = s.url.replace(/^ws/, "http").replace(/\/+$/, "").replace(/:\d+$/, (y) => y);
2314
+ const u = Be(s.url);
2296
2315
  fetch(`${u}/conversations/${o}/csat`, {
2297
2316
  method: "POST",
2298
2317
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${e}` },
@@ -2301,23 +2320,23 @@ function $t(s) {
2301
2320
  });
2302
2321
  },
2303
2322
  onAnnotate(d) {
2304
- o && g.send({ type: "annotate", conversationId: o, stroke: d });
2323
+ o && w.send({ type: "annotate", conversationId: o, stroke: d });
2305
2324
  },
2306
2325
  onAnnotateClear() {
2307
- o && g.send({ type: "annotate_clear", conversationId: o });
2326
+ o && w.send({ type: "annotate_clear", conversationId: o });
2308
2327
  },
2309
2328
  ...s.translateLang ? {
2310
2329
  async onTranslate(d) {
2311
2330
  const u = s.url.replace(/^ws/, "http").replace(/\/+$/, "");
2312
2331
  try {
2313
- const y = await fetch(`${u}/translate`, {
2332
+ const g = await fetch(`${u}/translate`, {
2314
2333
  method: "POST",
2315
2334
  headers: { "content-type": "application/json", authorization: `Bearer ${e}` },
2316
2335
  body: JSON.stringify({ text: d, targetLang: s.translateLang })
2317
2336
  });
2318
- if (!y.ok) return null;
2319
- const { translated: B } = await y.json();
2320
- return B;
2337
+ if (!g.ok) return null;
2338
+ const { translated: E } = await g.json();
2339
+ return E;
2321
2340
  } catch {
2322
2341
  return null;
2323
2342
  }
@@ -2327,9 +2346,9 @@ function $t(s) {
2327
2346
  ...s.subject ? { subject: s.subject } : {},
2328
2347
  ...s.quickReplies ? { quickReplies: s.quickReplies } : {},
2329
2348
  ...s.accent ? { accent: s.accent } : {},
2330
- ...(se = s.user) != null && se.name || (oe = s.user) != null && oe.avatar ? { userInfo: { ...s.user.name ? { name: s.user.name } : {}, ...s.user.avatar ? { avatar: s.user.avatar } : {} } } : {},
2331
- i18n: k
2332
- }), be = {
2349
+ ...(oe = s.user) != null && oe.name || (re = s.user) != null && re.avatar ? { userInfo: { ...s.user.name ? { name: s.user.name } : {}, ...s.user.avatar ? { avatar: s.user.avatar } : {} } } : {},
2350
+ i18n: J
2351
+ }), ke = {
2333
2352
  type: "open",
2334
2353
  profileId: s.profileId,
2335
2354
  ...s.subjectId ? { subjectId: s.subjectId } : {},
@@ -2337,81 +2356,81 @@ function $t(s) {
2337
2356
  ...typeof document < "u" && document.title ? { pageTitle: document.title } : {},
2338
2357
  // Pass subject display info so the server can persist it to the Subject record.
2339
2358
  // This is how listingTitle and listingMeta get saved without a separate API call.
2340
- ...(re = s.subject) != null && re.title ? { subjectTitle: s.subject.title } : {},
2341
- ...(ae = s.subject) != null && ae.subtitle ? { subjectMeta: s.subject.subtitle } : {}
2342
- }, me = (d) => {
2359
+ ...(ae = s.subject) != null && ae.title ? { subjectTitle: s.subject.title } : {},
2360
+ ...(ce = s.subject) != null && ce.subtitle ? { subjectMeta: s.subject.subtitle } : {}
2361
+ }, Se = (d) => {
2343
2362
  const u = s.user;
2344
2363
  if (!u || !u.name && !u.email && !u.avatar && !u.meta) return;
2345
- const y = [];
2346
- if (u.name && y.push(`Name: ${u.name}`), u.email && y.push(`Email: ${u.email}`), u.avatar && y.push(`Avatar: ${u.avatar}`), u.meta) for (const [B, I] of Object.entries(u.meta)) y.push(`${B}: ${I}`);
2347
- g.send({ type: "note", conversationId: d, clientMsgId: `ui_${Date.now()}`, text: `[User info]
2348
- ${y.join(`
2364
+ const g = [];
2365
+ if (u.name && g.push(`Name: ${u.name}`), u.email && g.push(`Email: ${u.email}`), u.avatar && g.push(`Avatar: ${u.avatar}`), u.meta) for (const [E, M] of Object.entries(u.meta)) g.push(`${E}: ${M}`);
2366
+ w.send({ type: "note", conversationId: d, clientMsgId: `ui_${Date.now()}`, text: `[User info]
2367
+ ${g.join(`
2349
2368
  `)}` });
2350
2369
  };
2351
- return g = new ut({
2370
+ return w = new xt({
2352
2371
  url: s.url,
2353
2372
  token: e,
2354
- open: be,
2373
+ open: ke,
2355
2374
  getCursor: () => t.highestSeq(),
2356
- onStatusChange: (d) => K.setConnStatus(d),
2375
+ onStatusChange: (d) => L.setConnStatus(d),
2357
2376
  onFrame(d) {
2358
2377
  if (d.type === "opened") {
2359
2378
  const u = o === void 0;
2360
2379
  if (o = d.conversation.id, !c) {
2361
2380
  c = !0;
2362
- for (const y of n.load())
2363
- g.send({ type: "send", conversationId: o, clientMsgId: y.clientMsgId, content: y.content });
2381
+ for (const g of n.load())
2382
+ w.send({ type: "send", conversationId: o, clientMsgId: g.clientMsgId, content: g.content });
2364
2383
  }
2365
- u && (Ue(s.url, e, o, t, K), d.conversation.lastSeq === 0 && me(o));
2384
+ u && (Pe(s.url, e, o, t, L), d.conversation.lastSeq === 0 && Se(o));
2366
2385
  }
2367
2386
  if (d.type === "ack" && n.remove(d.clientMsgId), d.type === "prekeyBundle") {
2368
- d.bundle && (A = !0, b.x3dhSendTo(d.bundle).then((u) => {
2369
- const y = [...C.splice(0), ...T.splice(0)];
2370
- for (const B of y) D(B.clientMsgId, B.text, u);
2371
- K.render(t);
2387
+ d.bundle && (A = !0, v.x3dhSendTo(d.bundle).then((u) => {
2388
+ const g = [...U.splice(0), ...P.splice(0)];
2389
+ for (const E of g) H(E.clientMsgId, E.text, u);
2390
+ L.render(t);
2372
2391
  }));
2373
2392
  return;
2374
2393
  }
2375
2394
  if (d.type === "message" && t.e2e) {
2376
- const u = Ut(d.message.content);
2377
- if (u && !b.ready) {
2378
- b.x3dhReceiveFrom(u.x3dhIK, u.x3dhEK, u.x3dhSPK).then(async () => {
2379
- await b.openFrame(d), t.apply(d), K.render(t);
2395
+ const u = Bt(d.message.content);
2396
+ if (u && !v.ready) {
2397
+ v.x3dhReceiveFrom(u.x3dhIK, u.x3dhEK, u.x3dhSPK).then(async () => {
2398
+ await v.openFrame(d), t.apply(d), L.render(t);
2380
2399
  });
2381
2400
  return;
2382
2401
  }
2383
2402
  }
2384
2403
  if (d.type === "peerkey") {
2385
- b.onPeerKey(d.key).then(() => {
2386
- $(), K.render(t);
2404
+ v.onPeerKey(d.key).then(() => {
2405
+ k(), L.render(t);
2387
2406
  });
2388
2407
  return;
2389
2408
  }
2390
2409
  (async () => {
2391
- if (t.e2e && await b.openFrame(d), t.apply(d), d.type === "message" && d.message.senderId !== e && !d.message.internal && (h(), p()), t.e2e && o && !v) {
2392
- v = !0;
2393
- const u = await b.initX3DH();
2394
- g.send({ type: "uploadPrekeys", ...u });
2395
- const y = await b.begin();
2396
- g.send({ type: "pubkey", conversationId: o, key: y });
2410
+ if (t.e2e && await v.openFrame(d), t.apply(d), d.type === "message" && d.message.senderId !== e && !d.message.internal && (T(), m()), t.e2e && o && !B) {
2411
+ B = !0;
2412
+ const u = await v.initX3DH();
2413
+ w.send({ type: "uploadPrekeys", ...u });
2414
+ const g = await v.begin();
2415
+ w.send({ type: "pubkey", conversationId: o, key: g });
2397
2416
  }
2398
- K.render(t);
2417
+ L.render(t);
2399
2418
  })();
2400
2419
  }
2401
- }), g.connect(), K.render(t), l = { close: () => {
2402
- g.close(), x == null || x.remove(), K.destroy();
2420
+ }), w.connect(), L.render(t), l = { close: () => {
2421
+ w.close(), b == null || b.remove(), L.destroy(), x && y && x.removeEventListener("change", (d) => y(d.matches));
2403
2422
  } }, l;
2404
2423
  }
2405
2424
  export {
2406
- pt as ChatStore,
2407
- ut as ConnectionManager,
2408
- Et as E2ESession,
2409
- xt as PersistentOutbox,
2410
- At as Renderer,
2411
- Dt as asConversationId,
2412
- Ut as extractX3DHInit,
2413
- Rt as httpBaseFromWsUrl,
2414
- $t as mount,
2415
- Ue as restoreHistory
2425
+ wt as ChatStore,
2426
+ xt as ConnectionManager,
2427
+ Pt as E2ESession,
2428
+ bt as PersistentOutbox,
2429
+ Mt as Renderer,
2430
+ Ht as asConversationId,
2431
+ Bt as extractX3DHInit,
2432
+ Be as httpBaseFromWsUrl,
2433
+ Rt as mount,
2434
+ Pe as restoreHistory
2416
2435
  };
2417
2436
  //# sourceMappingURL=index.js.map