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