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