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