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