@paramms/chat-widget 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +379 -375
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var r = (s, e, t) =>
|
|
4
|
-
import { p as
|
|
5
|
-
const
|
|
6
|
-
function
|
|
1
|
+
var Pe = Object.defineProperty;
|
|
2
|
+
var Be = (s, e, t) => e in s ? Pe(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var r = (s, e, t) => Be(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { p as Ke, r as Ae, h as ze } from "./uid.js";
|
|
5
|
+
const jt = (s) => s;
|
|
6
|
+
function Le(s) {
|
|
7
7
|
const e = s.length;
|
|
8
8
|
let t = 0, n = 0;
|
|
9
9
|
for (; n < e; ) {
|
|
@@ -25,7 +25,7 @@ function Ae(s) {
|
|
|
25
25
|
}
|
|
26
26
|
return t;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function Me(s, e, t) {
|
|
29
29
|
const n = s.length;
|
|
30
30
|
let i = t, o = 0;
|
|
31
31
|
for (; o < n; ) {
|
|
@@ -47,14 +47,14 @@ function ze(s, e, t) {
|
|
|
47
47
|
e[i++] = c & 63 | 128;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
const
|
|
51
|
-
function
|
|
52
|
-
|
|
50
|
+
const De = new TextEncoder(), _e = 50;
|
|
51
|
+
function $e(s, e, t) {
|
|
52
|
+
De.encodeInto(s, e.subarray(t));
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
s.length >
|
|
54
|
+
function He(s, e, t) {
|
|
55
|
+
s.length > _e ? $e(s, e, t) : Me(s, e, t);
|
|
56
56
|
}
|
|
57
|
-
const
|
|
57
|
+
const Re = 4096;
|
|
58
58
|
function xe(s, e, t) {
|
|
59
59
|
let n = e;
|
|
60
60
|
const i = n + t, o = [];
|
|
@@ -70,22 +70,22 @@ function xe(s, e, t) {
|
|
|
70
70
|
const w = s[n++] & 63, f = s[n++] & 63;
|
|
71
71
|
o.push((l & 31) << 12 | w << 6 | f);
|
|
72
72
|
} else if ((l & 248) === 240) {
|
|
73
|
-
const w = s[n++] & 63, f = s[n++] & 63,
|
|
74
|
-
let x = (l & 7) << 18 | w << 12 | f << 6 |
|
|
73
|
+
const w = s[n++] & 63, f = s[n++] & 63, b = s[n++] & 63;
|
|
74
|
+
let x = (l & 7) << 18 | w << 12 | f << 6 | b;
|
|
75
75
|
x > 65535 && (x -= 65536, o.push(x >>> 10 & 1023 | 55296), x = 56320 | x & 1023), o.push(x);
|
|
76
76
|
} else
|
|
77
77
|
o.push(l);
|
|
78
|
-
o.length >=
|
|
78
|
+
o.length >= Re && (c += String.fromCharCode(...o), o.length = 0);
|
|
79
79
|
}
|
|
80
80
|
return o.length > 0 && (c += String.fromCharCode(...o)), c;
|
|
81
81
|
}
|
|
82
|
-
const
|
|
83
|
-
function
|
|
82
|
+
const Fe = new TextDecoder(), je = 200;
|
|
83
|
+
function qe(s, e, t) {
|
|
84
84
|
const n = s.subarray(e, e + t);
|
|
85
|
-
return
|
|
85
|
+
return Fe.decode(n);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
return t >
|
|
87
|
+
function Oe(s, e, t) {
|
|
88
|
+
return t > je ? qe(s, e, t) : xe(s, e, t);
|
|
89
89
|
}
|
|
90
90
|
class W {
|
|
91
91
|
constructor(e, t) {
|
|
@@ -106,7 +106,7 @@ class z extends Error {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
const j = 4294967295;
|
|
109
|
-
function
|
|
109
|
+
function Ne(s, e, t) {
|
|
110
110
|
const n = t / 4294967296, i = t;
|
|
111
111
|
s.setUint32(e, n), s.setUint32(e + 4, i);
|
|
112
112
|
}
|
|
@@ -118,14 +118,14 @@ function ge(s, e) {
|
|
|
118
118
|
const t = s.getInt32(e), n = s.getUint32(e + 4);
|
|
119
119
|
return t * 4294967296 + n;
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function Ve(s, e) {
|
|
122
122
|
const t = s.getUint32(e), n = s.getUint32(e + 4);
|
|
123
123
|
return t * 4294967296 + n;
|
|
124
124
|
}
|
|
125
|
-
const
|
|
126
|
-
function
|
|
127
|
-
if (s >= 0 && e >= 0 && s <=
|
|
128
|
-
if (e === 0 && s <=
|
|
125
|
+
const We = -1, Xe = 4294967296 - 1, Ye = 17179869184 - 1;
|
|
126
|
+
function Je({ sec: s, nsec: e }) {
|
|
127
|
+
if (s >= 0 && e >= 0 && s <= Ye)
|
|
128
|
+
if (e === 0 && s <= Xe) {
|
|
129
129
|
const t = new Uint8Array(4);
|
|
130
130
|
return new DataView(t.buffer).setUint32(0, s), t;
|
|
131
131
|
} else {
|
|
@@ -137,21 +137,21 @@ function Xe({ sec: s, nsec: e }) {
|
|
|
137
137
|
return n.setUint32(0, e), ye(n, 4, s), t;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
function
|
|
140
|
+
function Ge(s) {
|
|
141
141
|
const e = s.getTime(), t = Math.floor(e / 1e3), n = (e - t * 1e3) * 1e6, i = Math.floor(n / 1e9);
|
|
142
142
|
return {
|
|
143
143
|
sec: t + i,
|
|
144
144
|
nsec: n - i * 1e9
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
-
function
|
|
147
|
+
function Qe(s) {
|
|
148
148
|
if (s instanceof Date) {
|
|
149
|
-
const e =
|
|
150
|
-
return
|
|
149
|
+
const e = Ge(s);
|
|
150
|
+
return Je(e);
|
|
151
151
|
} else
|
|
152
152
|
return null;
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function Ze(s) {
|
|
155
155
|
const e = new DataView(s.buffer, s.byteOffset, s.byteLength);
|
|
156
156
|
switch (s.byteLength) {
|
|
157
157
|
case 4:
|
|
@@ -168,14 +168,14 @@ function Ge(s) {
|
|
|
168
168
|
throw new z(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${s.length}`);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
function
|
|
172
|
-
const e =
|
|
171
|
+
function et(s) {
|
|
172
|
+
const e = Ze(s);
|
|
173
173
|
return new Date(e.sec * 1e3 + e.nsec / 1e6);
|
|
174
174
|
}
|
|
175
|
-
const
|
|
176
|
-
type:
|
|
177
|
-
encode:
|
|
178
|
-
decode:
|
|
175
|
+
const tt = {
|
|
176
|
+
type: We,
|
|
177
|
+
encode: Qe,
|
|
178
|
+
decode: et
|
|
179
179
|
}, J = class J {
|
|
180
180
|
constructor() {
|
|
181
181
|
// ensures ExtensionCodecType<X> matches ExtensionCodec<X>
|
|
@@ -188,7 +188,7 @@ const Qe = {
|
|
|
188
188
|
// custom extensions
|
|
189
189
|
r(this, "encoders", []);
|
|
190
190
|
r(this, "decoders", []);
|
|
191
|
-
this.register(
|
|
191
|
+
this.register(tt);
|
|
192
192
|
}
|
|
193
193
|
register({ type: e, encode: t, decode: n }) {
|
|
194
194
|
if (e >= 0)
|
|
@@ -228,13 +228,13 @@ const Qe = {
|
|
|
228
228
|
};
|
|
229
229
|
r(J, "defaultCodec", new J());
|
|
230
230
|
let X = J;
|
|
231
|
-
function
|
|
231
|
+
function nt(s) {
|
|
232
232
|
return s instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && s instanceof SharedArrayBuffer;
|
|
233
233
|
}
|
|
234
234
|
function ee(s) {
|
|
235
|
-
return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) :
|
|
235
|
+
return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) : nt(s) ? new Uint8Array(s) : Uint8Array.from(s);
|
|
236
236
|
}
|
|
237
|
-
const
|
|
237
|
+
const it = 100, st = 2048;
|
|
238
238
|
class ie {
|
|
239
239
|
constructor(e) {
|
|
240
240
|
r(this, "extensionCodec");
|
|
@@ -250,7 +250,7 @@ class ie {
|
|
|
250
250
|
r(this, "view");
|
|
251
251
|
r(this, "bytes");
|
|
252
252
|
r(this, "entered", !1);
|
|
253
|
-
this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? X.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ??
|
|
253
|
+
this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? X.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ?? it, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? st, this.sortKeys = (e == null ? void 0 : e.sortKeys) ?? !1, this.forceFloat32 = (e == null ? void 0 : e.forceFloat32) ?? !1, this.ignoreUndefined = (e == null ? void 0 : e.ignoreUndefined) ?? !1, this.forceIntegerToFloat = (e == null ? void 0 : e.forceIntegerToFloat) ?? !1, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
|
|
254
254
|
}
|
|
255
255
|
clone() {
|
|
256
256
|
return new ie({
|
|
@@ -335,8 +335,8 @@ class ie {
|
|
|
335
335
|
throw new Error(`Too long string: ${e} bytes in UTF-8`);
|
|
336
336
|
}
|
|
337
337
|
encodeString(e) {
|
|
338
|
-
const n =
|
|
339
|
-
this.ensureBufferSizeToWrite(5 + n), this.writeStringHeader(n),
|
|
338
|
+
const n = Le(e);
|
|
339
|
+
this.ensureBufferSizeToWrite(5 + n), this.writeStringHeader(n), He(e, this.bytes, this.pos), this.pos += n;
|
|
340
340
|
}
|
|
341
341
|
encodeObject(e, t) {
|
|
342
342
|
const n = this.extensionCodec.tryToEncode(e, this.context);
|
|
@@ -458,7 +458,7 @@ class ie {
|
|
|
458
458
|
this.ensureBufferSizeToWrite(8), this.view.setFloat64(this.pos, e), this.pos += 8;
|
|
459
459
|
}
|
|
460
460
|
writeU64(e) {
|
|
461
|
-
this.ensureBufferSizeToWrite(8),
|
|
461
|
+
this.ensureBufferSizeToWrite(8), Ne(this.view, this.pos, e), this.pos += 8;
|
|
462
462
|
}
|
|
463
463
|
writeI64(e) {
|
|
464
464
|
this.ensureBufferSizeToWrite(8), ye(this.view, this.pos, e), this.pos += 8;
|
|
@@ -470,15 +470,15 @@ class ie {
|
|
|
470
470
|
this.ensureBufferSizeToWrite(8), this.view.setBigInt64(this.pos, e), this.pos += 8;
|
|
471
471
|
}
|
|
472
472
|
}
|
|
473
|
-
function
|
|
473
|
+
function ot(s, e) {
|
|
474
474
|
return new ie(e).encodeSharedRef(s);
|
|
475
475
|
}
|
|
476
|
-
function
|
|
476
|
+
function Q(s) {
|
|
477
477
|
return `${s < 0 ? "-" : ""}0x${Math.abs(s).toString(16).padStart(2, "0")}`;
|
|
478
478
|
}
|
|
479
|
-
const
|
|
480
|
-
class
|
|
481
|
-
constructor(e =
|
|
479
|
+
const rt = 16, at = 16;
|
|
480
|
+
class ct {
|
|
481
|
+
constructor(e = rt, t = at) {
|
|
482
482
|
r(this, "hit", 0);
|
|
483
483
|
r(this, "miss", 0);
|
|
484
484
|
r(this, "caches");
|
|
@@ -515,12 +515,12 @@ class rt {
|
|
|
515
515
|
return this.store(c, o), o;
|
|
516
516
|
}
|
|
517
517
|
}
|
|
518
|
-
const te = "array", O = "map_key", be = "map_value",
|
|
518
|
+
const te = "array", O = "map_key", be = "map_value", dt = (s) => {
|
|
519
519
|
if (typeof s == "string" || typeof s == "number")
|
|
520
520
|
return s;
|
|
521
521
|
throw new z("The type of key must be string or number but " + typeof s);
|
|
522
522
|
};
|
|
523
|
-
class
|
|
523
|
+
class lt {
|
|
524
524
|
constructor() {
|
|
525
525
|
r(this, "stack", []);
|
|
526
526
|
r(this, "stackHeadPosition", -1);
|
|
@@ -571,14 +571,14 @@ class ct {
|
|
|
571
571
|
this.stack.length = 0, this.stackHeadPosition = -1;
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
|
-
const q = -1, se = new DataView(new ArrayBuffer(0)),
|
|
574
|
+
const q = -1, se = new DataView(new ArrayBuffer(0)), ht = new Uint8Array(se.buffer);
|
|
575
575
|
try {
|
|
576
576
|
se.getInt8(0);
|
|
577
577
|
} catch (s) {
|
|
578
578
|
if (!(s instanceof RangeError))
|
|
579
579
|
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
|
|
580
580
|
}
|
|
581
|
-
const he = new RangeError("Insufficient data"),
|
|
581
|
+
const he = new RangeError("Insufficient data"), pt = new ct();
|
|
582
582
|
class oe {
|
|
583
583
|
constructor(e) {
|
|
584
584
|
r(this, "extensionCodec");
|
|
@@ -595,11 +595,11 @@ class oe {
|
|
|
595
595
|
r(this, "totalPos", 0);
|
|
596
596
|
r(this, "pos", 0);
|
|
597
597
|
r(this, "view", se);
|
|
598
|
-
r(this, "bytes",
|
|
598
|
+
r(this, "bytes", ht);
|
|
599
599
|
r(this, "headByte", q);
|
|
600
|
-
r(this, "stack", new
|
|
600
|
+
r(this, "stack", new lt());
|
|
601
601
|
r(this, "entered", !1);
|
|
602
|
-
this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? X.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? j, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? j, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? j, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? j, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? j, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder :
|
|
602
|
+
this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? X.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? j, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? j, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? j, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? j, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? j, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : pt, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? dt;
|
|
603
603
|
}
|
|
604
604
|
clone() {
|
|
605
605
|
return new oe({
|
|
@@ -690,7 +690,7 @@ class oe {
|
|
|
690
690
|
return n;
|
|
691
691
|
}
|
|
692
692
|
const { headByte: i, pos: o, totalPos: c } = this;
|
|
693
|
-
throw new RangeError(`Insufficient data in parsing ${
|
|
693
|
+
throw new RangeError(`Insufficient data in parsing ${Q(i)} at ${c} (${o} in the current buffer)`);
|
|
694
694
|
} finally {
|
|
695
695
|
this.entered = !1;
|
|
696
696
|
}
|
|
@@ -845,7 +845,7 @@ class oe {
|
|
|
845
845
|
const i = this.lookU32();
|
|
846
846
|
t = this.decodeExtension(i, 4);
|
|
847
847
|
} else
|
|
848
|
-
throw new z(`Unrecognized type byte: ${
|
|
848
|
+
throw new z(`Unrecognized type byte: ${Q(e)}`);
|
|
849
849
|
this.complete();
|
|
850
850
|
const n = this.stack;
|
|
851
851
|
for (; n.length > 0; ) {
|
|
@@ -886,7 +886,7 @@ class oe {
|
|
|
886
886
|
default: {
|
|
887
887
|
if (e < 160)
|
|
888
888
|
return e - 144;
|
|
889
|
-
throw new z(`Unrecognized array type byte: ${
|
|
889
|
+
throw new z(`Unrecognized array type byte: ${Q(e)}`);
|
|
890
890
|
}
|
|
891
891
|
}
|
|
892
892
|
}
|
|
@@ -914,7 +914,7 @@ class oe {
|
|
|
914
914
|
throw he;
|
|
915
915
|
const n = this.pos + t;
|
|
916
916
|
let i;
|
|
917
|
-
return this.stateIsMapKey() && ((o = this.keyDecoder) != null && o.canBeCached(e)) ? i = this.keyDecoder.decode(this.bytes, n, e) : i =
|
|
917
|
+
return this.stateIsMapKey() && ((o = this.keyDecoder) != null && o.canBeCached(e)) ? i = this.keyDecoder.decode(this.bytes, n, e) : i = Oe(this.bytes, n, e), this.pos += t + e, i;
|
|
918
918
|
}
|
|
919
919
|
stateIsMapKey() {
|
|
920
920
|
return this.stack.length > 0 ? this.stack.top().type === O : !1;
|
|
@@ -974,7 +974,7 @@ class oe {
|
|
|
974
974
|
return this.pos += 4, e;
|
|
975
975
|
}
|
|
976
976
|
readU64() {
|
|
977
|
-
const e =
|
|
977
|
+
const e = Ve(this.view, this.pos);
|
|
978
978
|
return this.pos += 8, e;
|
|
979
979
|
}
|
|
980
980
|
readI64() {
|
|
@@ -998,10 +998,10 @@ class oe {
|
|
|
998
998
|
return this.pos += 8, e;
|
|
999
999
|
}
|
|
1000
1000
|
}
|
|
1001
|
-
function
|
|
1001
|
+
function ut(s, e) {
|
|
1002
1002
|
return new oe(e).decode(s);
|
|
1003
1003
|
}
|
|
1004
|
-
const
|
|
1004
|
+
const ft = /* @__PURE__ */ new Set([
|
|
1005
1005
|
"auth",
|
|
1006
1006
|
"open",
|
|
1007
1007
|
"send",
|
|
@@ -1018,22 +1018,22 @@ const pt = /* @__PURE__ */ new Set([
|
|
|
1018
1018
|
"annotate",
|
|
1019
1019
|
"annotate_clear"
|
|
1020
1020
|
]);
|
|
1021
|
-
function
|
|
1022
|
-
return
|
|
1021
|
+
function wt(s) {
|
|
1022
|
+
return ft.has(s.type);
|
|
1023
1023
|
}
|
|
1024
|
-
function
|
|
1025
|
-
return
|
|
1024
|
+
function xt(s) {
|
|
1025
|
+
return ot(s);
|
|
1026
1026
|
}
|
|
1027
|
-
function
|
|
1027
|
+
function yt(s) {
|
|
1028
1028
|
let e;
|
|
1029
1029
|
try {
|
|
1030
|
-
e =
|
|
1030
|
+
e = ut(s);
|
|
1031
1031
|
} catch {
|
|
1032
1032
|
return null;
|
|
1033
1033
|
}
|
|
1034
1034
|
return typeof e != "object" || e === null || typeof e.type != "string" ? null : e;
|
|
1035
1035
|
}
|
|
1036
|
-
class
|
|
1036
|
+
class gt {
|
|
1037
1037
|
constructor(e) {
|
|
1038
1038
|
r(this, "conversationId");
|
|
1039
1039
|
r(this, "state", "");
|
|
@@ -1197,7 +1197,7 @@ function pe(s) {
|
|
|
1197
1197
|
return 0;
|
|
1198
1198
|
}
|
|
1199
1199
|
}
|
|
1200
|
-
class
|
|
1200
|
+
class bt {
|
|
1201
1201
|
constructor(e) {
|
|
1202
1202
|
r(this, "socket", null);
|
|
1203
1203
|
r(this, "state", "idle");
|
|
@@ -1212,12 +1212,12 @@ class yt {
|
|
|
1212
1212
|
var n, i;
|
|
1213
1213
|
if (this.state === "connecting" || this.state === "open") return;
|
|
1214
1214
|
this.stopped = !1, this.state = "connecting", this.authed = !1, (i = (n = this.opts).onStatusChange) == null || i.call(n, this.attempt > 0 ? "reconnecting" : "connecting");
|
|
1215
|
-
const t = (this.opts.socketFactory ??
|
|
1215
|
+
const t = (this.opts.socketFactory ?? mt)(this.opts.url);
|
|
1216
1216
|
t.binaryType = "arraybuffer", this.socket = t, t.onopen = () => {
|
|
1217
1217
|
this.raw({ type: "auth", token: this.opts.token });
|
|
1218
1218
|
}, t.onmessage = (o) => {
|
|
1219
|
-
const c =
|
|
1220
|
-
!c ||
|
|
1219
|
+
const c = yt(new Uint8Array(o.data));
|
|
1220
|
+
!c || wt(c) || this.handle(c);
|
|
1221
1221
|
}, t.onclose = () => this.onClosed(), t.onerror = () => {
|
|
1222
1222
|
try {
|
|
1223
1223
|
t.close();
|
|
@@ -1256,7 +1256,7 @@ class yt {
|
|
|
1256
1256
|
raw(e) {
|
|
1257
1257
|
var t;
|
|
1258
1258
|
try {
|
|
1259
|
-
(t = this.socket) == null || t.send(
|
|
1259
|
+
(t = this.socket) == null || t.send(xt(e));
|
|
1260
1260
|
} catch {
|
|
1261
1261
|
this.outbox.push(e);
|
|
1262
1262
|
}
|
|
@@ -1271,11 +1271,11 @@ class yt {
|
|
|
1271
1271
|
this.attempt++, this.timer = setTimeout(() => this.connect(), n);
|
|
1272
1272
|
}
|
|
1273
1273
|
}
|
|
1274
|
-
function
|
|
1274
|
+
function mt(s) {
|
|
1275
1275
|
return new WebSocket(s);
|
|
1276
1276
|
}
|
|
1277
|
-
const ue = 200,
|
|
1278
|
-
class
|
|
1277
|
+
const ue = 200, vt = 7 * 864e5;
|
|
1278
|
+
class kt {
|
|
1279
1279
|
constructor(e) {
|
|
1280
1280
|
r(this, "key");
|
|
1281
1281
|
this.key = `ocw_outbox_${e}`;
|
|
@@ -1285,7 +1285,7 @@ class mt {
|
|
|
1285
1285
|
try {
|
|
1286
1286
|
const e = localStorage.getItem(this.key);
|
|
1287
1287
|
if (!e) return [];
|
|
1288
|
-
const t = JSON.parse(e), n = Date.now() -
|
|
1288
|
+
const t = JSON.parse(e), n = Date.now() - vt, i = t.filter((o) => o.ts >= n);
|
|
1289
1289
|
return i.length !== t.length && this.save(i), i;
|
|
1290
1290
|
} catch {
|
|
1291
1291
|
return [];
|
|
@@ -1313,7 +1313,7 @@ class mt {
|
|
|
1313
1313
|
}
|
|
1314
1314
|
}
|
|
1315
1315
|
}
|
|
1316
|
-
const
|
|
1316
|
+
const S = () => globalThis.crypto.subtle;
|
|
1317
1317
|
function Y(s) {
|
|
1318
1318
|
const e = s instanceof Uint8Array ? s : new Uint8Array(s);
|
|
1319
1319
|
let t = "";
|
|
@@ -1326,18 +1326,18 @@ function ne(s) {
|
|
|
1326
1326
|
return n;
|
|
1327
1327
|
}
|
|
1328
1328
|
async function N() {
|
|
1329
|
-
const s = await
|
|
1329
|
+
const s = await S().generateKey({ name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
|
|
1330
1330
|
return { publicKey: s.publicKey, privateKey: s.privateKey };
|
|
1331
1331
|
}
|
|
1332
|
-
async function
|
|
1333
|
-
return Y(await
|
|
1332
|
+
async function H(s) {
|
|
1333
|
+
return Y(await S().exportKey("raw", s));
|
|
1334
1334
|
}
|
|
1335
1335
|
async function F(s) {
|
|
1336
|
-
return
|
|
1336
|
+
return S().importKey("raw", ne(s), { name: "ECDH", namedCurve: "P-256" }, !1, []);
|
|
1337
1337
|
}
|
|
1338
|
-
async function
|
|
1338
|
+
async function St(s, e) {
|
|
1339
1339
|
const t = await F(e);
|
|
1340
|
-
return
|
|
1340
|
+
return S().deriveKey(
|
|
1341
1341
|
{ name: "ECDH", public: t },
|
|
1342
1342
|
s,
|
|
1343
1343
|
{ name: "AES-GCM", length: 256 },
|
|
@@ -1345,43 +1345,43 @@ async function vt(s, e) {
|
|
|
1345
1345
|
["encrypt", "decrypt"]
|
|
1346
1346
|
);
|
|
1347
1347
|
}
|
|
1348
|
-
async function
|
|
1349
|
-
const t = globalThis.crypto.getRandomValues(new Uint8Array(12)), n = new TextEncoder().encode(e), i = await
|
|
1348
|
+
async function It(s, e) {
|
|
1349
|
+
const t = globalThis.crypto.getRandomValues(new Uint8Array(12)), n = new TextEncoder().encode(e), i = await S().encrypt({ name: "AES-GCM", iv: t }, s, n);
|
|
1350
1350
|
return { ct: Y(i), iv: Y(t) };
|
|
1351
1351
|
}
|
|
1352
|
-
async function
|
|
1353
|
-
const n = await
|
|
1352
|
+
async function Ct(s, e, t) {
|
|
1353
|
+
const n = await S().decrypt({ name: "AES-GCM", iv: ne(t) }, s, ne(e));
|
|
1354
1354
|
return new TextDecoder().decode(n);
|
|
1355
1355
|
}
|
|
1356
|
-
async function
|
|
1356
|
+
async function Et(s) {
|
|
1357
1357
|
var t, n;
|
|
1358
1358
|
try {
|
|
1359
1359
|
const i = (t = globalThis.localStorage) == null ? void 0 : t.getItem(s);
|
|
1360
1360
|
if (i) {
|
|
1361
|
-
const { pub: o, priv: c } = JSON.parse(i), l = await
|
|
1361
|
+
const { pub: o, priv: c } = JSON.parse(i), l = await S().importKey("jwk", o, { name: "ECDH", namedCurve: "P-256" }, !0, []), w = await S().importKey("jwk", c, { name: "ECDH", namedCurve: "P-256" }, !0, ["deriveKey", "deriveBits"]);
|
|
1362
1362
|
return { publicKey: l, privateKey: w };
|
|
1363
1363
|
}
|
|
1364
1364
|
} catch {
|
|
1365
1365
|
}
|
|
1366
1366
|
const e = await N();
|
|
1367
1367
|
try {
|
|
1368
|
-
const i = await
|
|
1368
|
+
const i = await S().exportKey("jwk", e.publicKey), o = await S().exportKey("jwk", e.privateKey);
|
|
1369
1369
|
(n = globalThis.localStorage) == null || n.setItem(s, JSON.stringify({ pub: i, priv: o }));
|
|
1370
1370
|
} catch {
|
|
1371
1371
|
}
|
|
1372
1372
|
return e;
|
|
1373
1373
|
}
|
|
1374
|
-
async function
|
|
1375
|
-
const t = await
|
|
1374
|
+
async function Tt(s, e) {
|
|
1375
|
+
const t = await S().exportKey("raw", e), n = await S().sign({ name: "ECDSA", hash: "SHA-256" }, s, t);
|
|
1376
1376
|
return Y(n);
|
|
1377
1377
|
}
|
|
1378
|
-
async function
|
|
1379
|
-
const s = await N(), e = await
|
|
1378
|
+
async function Ut() {
|
|
1379
|
+
const s = await N(), e = await S().generateKey({ name: "ECDSA", namedCurve: "P-256" }, !0, ["sign", "verify"]);
|
|
1380
1380
|
return {
|
|
1381
1381
|
ecdhKP: s,
|
|
1382
1382
|
ecdsaKP: { publicKey: e.publicKey, privateKey: e.privateKey },
|
|
1383
|
-
publicKeyB64: await
|
|
1384
|
-
sigPublicKeyB64: await
|
|
1383
|
+
publicKeyB64: await H(s.publicKey),
|
|
1384
|
+
sigPublicKeyB64: await H(e.publicKey)
|
|
1385
1385
|
};
|
|
1386
1386
|
}
|
|
1387
1387
|
async function fe(s) {
|
|
@@ -1389,34 +1389,34 @@ async function fe(s) {
|
|
|
1389
1389
|
try {
|
|
1390
1390
|
const i = (t = globalThis.localStorage) == null ? void 0 : t.getItem(`${s}-identity`);
|
|
1391
1391
|
if (i) {
|
|
1392
|
-
const o = JSON.parse(i), c = await
|
|
1392
|
+
const o = JSON.parse(i), 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"]), w = 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"]);
|
|
1393
1393
|
return {
|
|
1394
1394
|
ecdhKP: { publicKey: c, privateKey: l },
|
|
1395
1395
|
ecdsaKP: { publicKey: w, privateKey: f },
|
|
1396
|
-
publicKeyB64: await
|
|
1397
|
-
sigPublicKeyB64: await
|
|
1396
|
+
publicKeyB64: await H(c),
|
|
1397
|
+
sigPublicKeyB64: await H(w)
|
|
1398
1398
|
};
|
|
1399
1399
|
}
|
|
1400
1400
|
} catch {
|
|
1401
1401
|
}
|
|
1402
|
-
const e = await
|
|
1402
|
+
const e = await Ut();
|
|
1403
1403
|
try {
|
|
1404
|
-
const i = await
|
|
1404
|
+
const i = 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);
|
|
1405
1405
|
(n = globalThis.localStorage) == null || n.setItem(`${s}-identity`, JSON.stringify({ ecdhPub: i, ecdhPriv: o, ecdsaPub: c, ecdsaPriv: l }));
|
|
1406
1406
|
} catch {
|
|
1407
1407
|
}
|
|
1408
1408
|
return e;
|
|
1409
1409
|
}
|
|
1410
|
-
async function
|
|
1411
|
-
const t = await N(), n = await
|
|
1410
|
+
async function Pt(s, e) {
|
|
1411
|
+
const t = await N(), n = await H(t.publicKey), i = await F(e.identityKey), o = await F(e.signedPrekey), c = e.oneTimePrekey ? await F(e.oneTimePrekey) : null, l = await $(s.privateKey, o), w = await $(t.privateKey, i), f = await $(t.privateKey, o), b = c ? await $(t.privateKey, c) : null, x = me(l, w, f, ...b ? [b] : []);
|
|
1412
1412
|
return { sharedKey: await ve(x), ephemeralPublicKey: n };
|
|
1413
1413
|
}
|
|
1414
|
-
async function
|
|
1415
|
-
const o = await F(t), c = await F(n), l = await
|
|
1414
|
+
async function Bt(s, e, t, n, i) {
|
|
1415
|
+
const o = await F(t), c = await F(n), l = await $(e.privateKey, o), w = await $(s.privateKey, c), f = await $(e.privateKey, c), b = i ? await $(i.privateKey, c) : null, x = me(l, w, f, ...b ? [b] : []);
|
|
1416
1416
|
return ve(x);
|
|
1417
1417
|
}
|
|
1418
|
-
async function
|
|
1419
|
-
return
|
|
1418
|
+
async function $(s, e) {
|
|
1419
|
+
return S().deriveBits({ name: "ECDH", public: e }, s, 256);
|
|
1420
1420
|
}
|
|
1421
1421
|
function me(...s) {
|
|
1422
1422
|
const e = s.reduce((i, o) => i + o.byteLength, 0), t = new Uint8Array(e);
|
|
@@ -1426,8 +1426,8 @@ function me(...s) {
|
|
|
1426
1426
|
return t.buffer;
|
|
1427
1427
|
}
|
|
1428
1428
|
async function ve(s) {
|
|
1429
|
-
const e = await
|
|
1430
|
-
return
|
|
1429
|
+
const e = await S().importKey("raw", s, "HKDF", !1, ["deriveKey"]);
|
|
1430
|
+
return S().deriveKey(
|
|
1431
1431
|
{ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(32), info: new TextEncoder().encode("ObjectChat X3DH v1") },
|
|
1432
1432
|
e,
|
|
1433
1433
|
{ name: "AES-GCM", length: 256 },
|
|
@@ -1435,8 +1435,8 @@ async function ve(s) {
|
|
|
1435
1435
|
["encrypt", "decrypt"]
|
|
1436
1436
|
);
|
|
1437
1437
|
}
|
|
1438
|
-
const
|
|
1439
|
-
class
|
|
1438
|
+
const Kt = 20;
|
|
1439
|
+
class At {
|
|
1440
1440
|
constructor(e) {
|
|
1441
1441
|
// Live ECDH mode state
|
|
1442
1442
|
r(this, "kp");
|
|
@@ -1457,19 +1457,19 @@ class Bt {
|
|
|
1457
1457
|
}
|
|
1458
1458
|
/** Live ECDH mode: Generate/restore our keypair and return our public key to publish. */
|
|
1459
1459
|
async begin() {
|
|
1460
|
-
return this.kp = await
|
|
1460
|
+
return this.kp = await Et(this.storageKey), H(this.kp.publicKey);
|
|
1461
1461
|
}
|
|
1462
1462
|
/** Live ECDH mode: A peer published their key — derive the shared secret. */
|
|
1463
1463
|
async onPeerKey(e) {
|
|
1464
|
-
this.kp && (this.shared = await
|
|
1464
|
+
this.kp && (this.shared = await St(this.kp.privateKey, e));
|
|
1465
1465
|
}
|
|
1466
1466
|
// ── X3DH async mode ────────────────────────────────────────────────────────
|
|
1467
1467
|
/** X3DH: Generate identity key, signed prekey, and OTP prekeys.
|
|
1468
1468
|
* Returns the upload frame payload the caller should send to the server. */
|
|
1469
1469
|
async initX3DH() {
|
|
1470
1470
|
this.identityKP = await fe(this.storageKey), this.signedPreKP = await N(), this.signedPrekeyId = `spk-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
1471
|
-
for (let i = 0; i <
|
|
1472
|
-
const e = await
|
|
1471
|
+
for (let i = 0; i < Kt; i++) this.otpKeys.push(await N());
|
|
1472
|
+
const e = await H(this.signedPreKP.publicKey), t = await Tt(this.identityKP.ecdsaKP.privateKey, this.signedPreKP.publicKey), n = await Promise.all(this.otpKeys.map((i) => H(i.publicKey)));
|
|
1473
1473
|
return {
|
|
1474
1474
|
identityKey: this.identityKP.publicKeyB64,
|
|
1475
1475
|
signedPrekey: e,
|
|
@@ -1482,7 +1482,7 @@ class Bt {
|
|
|
1482
1482
|
* return the init message fields to embed in the first encrypted message. */
|
|
1483
1483
|
async x3dhSendTo(e) {
|
|
1484
1484
|
this.identityKP || (this.identityKP = await fe(this.storageKey));
|
|
1485
|
-
const { sharedKey: t, ephemeralPublicKey: n } = await
|
|
1485
|
+
const { sharedKey: t, ephemeralPublicKey: n } = await Pt(this.identityKP.ecdhKP, e);
|
|
1486
1486
|
return this.x3dhShared = t, { ephemeralKey: n, spkId: e.signedPrekeyId, usedOTP: !!e.oneTimePrekey, senderIK: this.identityKP.publicKeyB64 };
|
|
1487
1487
|
}
|
|
1488
1488
|
/** X3DH recipient: given an init message's sender IK + EK + SPK ID, derive the shared key. */
|
|
@@ -1492,7 +1492,7 @@ class Bt {
|
|
|
1492
1492
|
return;
|
|
1493
1493
|
}
|
|
1494
1494
|
const i = this.otpKeys.shift();
|
|
1495
|
-
this.x3dhShared = await
|
|
1495
|
+
this.x3dhShared = await Bt(this.identityKP.ecdhKP, this.signedPreKP, e, t, i);
|
|
1496
1496
|
}
|
|
1497
1497
|
/** Flush pending X3DH derivation after initX3DH() completes. */
|
|
1498
1498
|
async flushPendingX3DH() {
|
|
@@ -1505,7 +1505,7 @@ class Bt {
|
|
|
1505
1505
|
async sealText(e, t) {
|
|
1506
1506
|
const n = this.x3dhShared ?? this.shared;
|
|
1507
1507
|
if (!n) throw new Error("secure channel not ready");
|
|
1508
|
-
const { ct: i, iv: o } = await
|
|
1508
|
+
const { ct: i, iv: o } = await It(n, e);
|
|
1509
1509
|
return {
|
|
1510
1510
|
kind: "text",
|
|
1511
1511
|
text: i,
|
|
@@ -1520,7 +1520,7 @@ class Bt {
|
|
|
1520
1520
|
const t = this.x3dhShared ?? this.shared;
|
|
1521
1521
|
if (!t) return { kind: "text", text: "🔒 encrypted" };
|
|
1522
1522
|
try {
|
|
1523
|
-
return { kind: "text", text: await
|
|
1523
|
+
return { kind: "text", text: await Ct(t, e.text, e.iv) };
|
|
1524
1524
|
} catch {
|
|
1525
1525
|
return { kind: "text", text: "🔒 unable to decrypt" };
|
|
1526
1526
|
}
|
|
@@ -1532,12 +1532,12 @@ class Bt {
|
|
|
1532
1532
|
for (const t of e.messages) t.content = await this.openContent(t.content);
|
|
1533
1533
|
}
|
|
1534
1534
|
}
|
|
1535
|
-
function
|
|
1535
|
+
function zt(s) {
|
|
1536
1536
|
if (s.kind !== "text" || !s.enc) return null;
|
|
1537
1537
|
const e = s;
|
|
1538
1538
|
return !e.x3dhEK || !e.x3dhSPK || !e.x3dhIK ? null : { x3dhEK: e.x3dhEK, x3dhSPK: e.x3dhSPK, x3dhIK: e.x3dhIK };
|
|
1539
1539
|
}
|
|
1540
|
-
const we = "objectchat-widget-styles",
|
|
1540
|
+
const we = "objectchat-widget-styles", Lt = ["👍", "❤️", "😂", "😮", "😢", "🙏"], Mt = `
|
|
1541
1541
|
.ocw { --ocw-accent:#f5713c; --ocw-bg:#f3efe9; --ocw-card:#fff; --ocw-line:#ececec; --ocw-ink:#1c1b1a; --ocw-mut:#9b9690;
|
|
1542
1542
|
position:relative;
|
|
1543
1543
|
display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
|
|
@@ -1696,23 +1696,23 @@ const we = "objectchat-widget-styles", At = ["👍", "❤️", "😂", "😮", "
|
|
|
1696
1696
|
.ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
|
|
1697
1697
|
.ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
|
|
1698
1698
|
`;
|
|
1699
|
-
function
|
|
1699
|
+
function Dt() {
|
|
1700
1700
|
if (typeof document > "u" || document.getElementById(we)) return;
|
|
1701
1701
|
const s = document.createElement("style");
|
|
1702
|
-
s.id = we, s.textContent =
|
|
1702
|
+
s.id = we, s.textContent = Mt, document.head.appendChild(s);
|
|
1703
1703
|
}
|
|
1704
1704
|
function a(s, e, t) {
|
|
1705
1705
|
const n = document.createElement(s);
|
|
1706
1706
|
return e && (n.className = e), t !== void 0 && (n.textContent = t), n;
|
|
1707
1707
|
}
|
|
1708
|
-
function
|
|
1708
|
+
function _t(s) {
|
|
1709
1709
|
try {
|
|
1710
1710
|
return new Date(s).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
1711
1711
|
} catch {
|
|
1712
1712
|
return "";
|
|
1713
1713
|
}
|
|
1714
1714
|
}
|
|
1715
|
-
function
|
|
1715
|
+
function Z(s) {
|
|
1716
1716
|
var e;
|
|
1717
1717
|
switch (s.kind) {
|
|
1718
1718
|
case "text":
|
|
@@ -1729,7 +1729,7 @@ function Q(s) {
|
|
|
1729
1729
|
return `📅 ${s.title} — ${new Date(s.startIso).toLocaleString()}`;
|
|
1730
1730
|
}
|
|
1731
1731
|
}
|
|
1732
|
-
class
|
|
1732
|
+
class $t {
|
|
1733
1733
|
/** Last seq the guest has seen per conversationId — used to compute unread badges. */
|
|
1734
1734
|
constructor(e, t, n, i = {}) {
|
|
1735
1735
|
r(this, "scroll");
|
|
@@ -1762,56 +1762,56 @@ class Dt {
|
|
|
1762
1762
|
r(this, "translationCache", /* @__PURE__ */ new Map());
|
|
1763
1763
|
r(this, "showingTranslation", /* @__PURE__ */ new Set());
|
|
1764
1764
|
r(this, "subjectBuilt", !1);
|
|
1765
|
-
var
|
|
1766
|
-
this.root = e, this.me = t, this.h = n, this.cfg = i,
|
|
1765
|
+
var v, m, g, I, K, P, B, T, M;
|
|
1766
|
+
this.root = e, this.me = t, this.h = n, this.cfg = i, Dt(), e.replaceChildren(), e.classList.add("ocw"), i.accent && e.style.setProperty("--ocw-accent", i.accent);
|
|
1767
1767
|
const o = a("div", "ocw-head"), c = a("div", "ocw-avatar");
|
|
1768
|
-
if ((
|
|
1769
|
-
const
|
|
1770
|
-
|
|
1768
|
+
if ((v = i.userInfo) != null && v.avatar) {
|
|
1769
|
+
const k = document.createElement("img");
|
|
1770
|
+
k.src = i.userInfo.avatar, k.alt = i.userInfo.name ?? "You", k.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover", c.append(k);
|
|
1771
1771
|
} else
|
|
1772
|
-
c.textContent = (
|
|
1772
|
+
c.textContent = (m = i.userInfo) != null && m.name ? i.userInfo.name[0].toUpperCase() : "🧑";
|
|
1773
1773
|
o.append(c);
|
|
1774
1774
|
const l = a("div", "ocw-head-main");
|
|
1775
|
-
this.headerName = a("div", "ocw-head-name", ((
|
|
1775
|
+
this.headerName = a("div", "ocw-head-name", ((g = i.subject) == null ? void 0 : g.ownerLabel) ?? ((I = i.subject) == null ? void 0 : I.title) ?? ""), l.append(this.headerName), (K = i.subject) != null && K.subtitle && l.append(a("div", "ocw-head-meta", i.subject.subtitle)), o.append(l), this.statusBadge = a("span", "ocw-badge", ((P = i.subject) == null ? void 0 : P.status) ?? ""), (B = i.subject) != null && B.status || (this.statusBadge.style.display = "none"), o.append(this.statusBadge), this.e2eBadge = a("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", o.append(this.e2eBadge), this.connStatus = a("span", "ocw-conn-status"), this.connStatus.style.display = "none", o.append(this.connStatus), this.cobrowseBtn = a("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
|
|
1776
1776
|
this.cobrowseActive = !this.cobrowseActive, this.updateCobrowseUI();
|
|
1777
1777
|
}), o.append(this.cobrowseBtn), o.append(a("button", "ocw-menu", "⋯")), this.chips = a("div", "ocw-chiprow"), this.scroll = a("div", "ocw-scroll"), this.subjectCard = a("div", "ocw-subject"), this.typing = a("div", "ocw-typing");
|
|
1778
1778
|
const w = a("div", "ocw-typing-bubble");
|
|
1779
1779
|
w.append(a("div", "ocw-typing-dot"), a("div", "ocw-typing-dot"), a("div", "ocw-typing-dot")), this.typing.append(a("div", "ocw-dot", "🧑"), w), this.quick = a("div", "ocw-quick");
|
|
1780
|
-
for (const
|
|
1781
|
-
const A = a("button", void 0,
|
|
1780
|
+
for (const k of i.quickReplies ?? []) {
|
|
1781
|
+
const A = a("button", void 0, k);
|
|
1782
1782
|
A.addEventListener("click", () => {
|
|
1783
|
-
this.h.onSend(
|
|
1783
|
+
this.h.onSend(k), this.quick.style.display = "none";
|
|
1784
1784
|
}), this.quick.append(A);
|
|
1785
1785
|
}
|
|
1786
1786
|
this.formHost = a("div", "ocw-form-host"), this.csatPanel = a("div", "ocw-csat"), this.csatPanel.style.display = "none", this.offlinePanel = a("div", "ocw-offline"), this.offlinePanel.style.display = "none", this.input = a("textarea", void 0), this.input.rows = 1, this.input.placeholder = "Message…";
|
|
1787
|
-
const f = a("button", "ocw-sendbtn", ((
|
|
1788
|
-
f.addEventListener("click", () => this.flushSend()), this.input.addEventListener("keydown", (
|
|
1789
|
-
|
|
1787
|
+
const f = a("button", "ocw-sendbtn", ((T = i.i18n) == null ? void 0 : T.send) ?? "➤");
|
|
1788
|
+
f.addEventListener("click", () => this.flushSend()), this.input.addEventListener("keydown", (k) => {
|
|
1789
|
+
k.isComposing || k.keyCode === 229 || (k.key === "Enter" && !k.shiftKey ? (k.preventDefault(), this.flushSend()) : this.signalTyping());
|
|
1790
1790
|
});
|
|
1791
|
-
const
|
|
1792
|
-
|
|
1791
|
+
const b = a("button", "ocw-attach", "📎");
|
|
1792
|
+
b.title = "Attach image or file";
|
|
1793
1793
|
const x = document.createElement("input");
|
|
1794
|
-
x.type = "file", x.accept = "image/*,.pdf,.txt,.doc,.docx", x.style.display = "none",
|
|
1795
|
-
var
|
|
1796
|
-
(
|
|
1794
|
+
x.type = "file", x.accept = "image/*,.pdf,.txt,.doc,.docx", x.style.display = "none", b.addEventListener("click", () => x.click()), x.addEventListener("change", () => {
|
|
1795
|
+
var k;
|
|
1796
|
+
(k = x.files) != null && k[0] && this.h.onAttach && this.h.onAttach(x.files[0]), x.value = "";
|
|
1797
1797
|
});
|
|
1798
1798
|
const h = a("div", "ocw-input");
|
|
1799
|
-
h.append(
|
|
1800
|
-
const
|
|
1801
|
-
((
|
|
1802
|
-
for (const
|
|
1799
|
+
h.append(b, x, this.input, f);
|
|
1800
|
+
const u = a("div", "ocw-footer");
|
|
1801
|
+
((M = i.i18n) == null ? void 0 : M.poweredBy) !== void 0 ? u.textContent = i.i18n.poweredBy : u.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = u, e.append(o, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, h, this.footer), this.cobrowseCanvas = a("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = a("div", "ocw-cobrowse-toolbar");
|
|
1802
|
+
for (const k of ["#f5713c", "#1c1b1a", "#2563eb", "#16a34a", "#dc2626"]) {
|
|
1803
1803
|
const A = a("button", "ocw-cobrowse-swatch");
|
|
1804
|
-
A.style.background =
|
|
1805
|
-
this.cobrowseColor =
|
|
1804
|
+
A.style.background = k, A.type = "button", k === this.cobrowseColor && A.classList.add("sel"), A.addEventListener("click", () => {
|
|
1805
|
+
this.cobrowseColor = k;
|
|
1806
1806
|
for (const G of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch")) G.classList.remove("sel");
|
|
1807
1807
|
A.classList.add("sel");
|
|
1808
1808
|
}), this.cobrowseToolbar.append(A);
|
|
1809
1809
|
}
|
|
1810
|
-
const
|
|
1811
|
-
|
|
1812
|
-
var
|
|
1813
|
-
return (A = (
|
|
1814
|
-
}), this.cobrowseToolbar.append(
|
|
1810
|
+
const U = a("button", "ocw-cobrowse-clear", "Clear");
|
|
1811
|
+
U.addEventListener("click", () => {
|
|
1812
|
+
var k, A;
|
|
1813
|
+
return (A = (k = this.h).onAnnotateClear) == null ? void 0 : A.call(k);
|
|
1814
|
+
}), this.cobrowseToolbar.append(U), this.cobrowseHint = a("div", "ocw-cobrowse-hint", "🖍 Draw to point things out — visible to both sides"), e.append(this.cobrowseCanvas, this.cobrowseToolbar, this.cobrowseHint), this.bindCobrowsePointerEvents();
|
|
1815
1815
|
}
|
|
1816
1816
|
/** Returns the scroll container so history.ts can attach scroll listeners. */
|
|
1817
1817
|
getScrollEl() {
|
|
@@ -1840,7 +1840,7 @@ class Dt {
|
|
|
1840
1840
|
this.h.onTyping(!0), this.typingTimer && clearTimeout(this.typingTimer), this.typingTimer = setTimeout(() => this.h.onTyping(!1), 2e3);
|
|
1841
1841
|
}
|
|
1842
1842
|
render(e) {
|
|
1843
|
-
var f,
|
|
1843
|
+
var f, b, x;
|
|
1844
1844
|
if (this.storeRef = e, this.cobrowseBtn.classList.toggle("show", !!e.subject), !e.subject && this.cobrowseActive && (this.cobrowseActive = !1, this.updateCobrowseUI()), this.cobrowseActive && e.annotationVersion !== this.lastAnnotationVersion && (this.lastAnnotationVersion = e.annotationVersion, this.resizeCobrowseCanvas(), this.redrawCobrowse()), e.accent && this.root.style.setProperty("--ocw-accent", e.accent), this.e2eBadge.style.display = e.e2e ? "inline-flex" : "none", this.buildSubjectCard(e), e.subject) {
|
|
1845
1845
|
const h = (f = this.cfg.subject) == null ? void 0 : f.ownerLabel;
|
|
1846
1846
|
h && (this.headerName.textContent = h);
|
|
@@ -1861,7 +1861,7 @@ class Dt {
|
|
|
1861
1861
|
const c = [...e.typing];
|
|
1862
1862
|
this.typing.classList.toggle("active", c.length > 0);
|
|
1863
1863
|
const l = this.typing.querySelector(".ocw-typing-bubble");
|
|
1864
|
-
l && l.setAttribute("aria-label", c.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (
|
|
1864
|
+
l && l.setAttribute("aria-label", c.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (b = this.root.querySelector(".ocw-input")) == null || b.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (x = this.root.querySelector(".ocw-input")) == null || x.style.removeProperty("display"));
|
|
1865
1865
|
const w = ["resolved", "closed", "sold", "issued", "checked_out"];
|
|
1866
1866
|
this.h.onCsat && !this.csatSubmitted && w.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
|
|
1867
1867
|
}
|
|
@@ -1992,30 +1992,30 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-t
|
|
|
1992
1992
|
t.append(a("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
|
|
1993
1993
|
const n = /* @__PURE__ */ new Map();
|
|
1994
1994
|
for (const f of e.input ?? []) {
|
|
1995
|
-
const
|
|
1996
|
-
if (
|
|
1995
|
+
const b = a("label", "ocw-form-row");
|
|
1996
|
+
if (b.append(a("span", "ocw-form-lbl", f.label)), f.type === "select" && ((l = f.options) != null && l.length)) {
|
|
1997
1997
|
const x = a("select", "ocw-form-input");
|
|
1998
1998
|
f.required || x.append(a("option", void 0, "— select —"));
|
|
1999
1999
|
for (const h of f.options) {
|
|
2000
|
-
const
|
|
2001
|
-
|
|
2000
|
+
const u = a("option");
|
|
2001
|
+
u.value = h, u.textContent = h, x.append(u);
|
|
2002
2002
|
}
|
|
2003
|
-
f.required && (x.required = !0),
|
|
2003
|
+
f.required && (x.required = !0), b.append(x), n.set(f.name, x);
|
|
2004
2004
|
} else {
|
|
2005
2005
|
const x = a("input", "ocw-form-input");
|
|
2006
|
-
x.type = f.type === "number" ? "number" : f.type === "date" ? "datetime-local" : "text", f.required && (x.required = !0),
|
|
2006
|
+
x.type = f.type === "number" ? "number" : f.type === "date" ? "datetime-local" : "text", f.required && (x.required = !0), b.append(x), n.set(f.name, x);
|
|
2007
2007
|
}
|
|
2008
|
-
t.append(
|
|
2008
|
+
t.append(b);
|
|
2009
2009
|
}
|
|
2010
2010
|
const i = a("div", "ocw-form-actions"), o = a("button", "ocw-form-cancel", "Cancel"), c = a("button", "ocw-form-submit", "Send");
|
|
2011
2011
|
o.addEventListener("click", () => this.formHost.replaceChildren()), c.addEventListener("click", () => {
|
|
2012
2012
|
const f = {};
|
|
2013
|
-
for (const [
|
|
2013
|
+
for (const [b, x] of n) {
|
|
2014
2014
|
if (x.required && !x.value) {
|
|
2015
2015
|
x.style.borderColor = "#e5484d";
|
|
2016
2016
|
return;
|
|
2017
2017
|
}
|
|
2018
|
-
f[
|
|
2018
|
+
f[b] = x.type === "number" ? Number(x.value) : x.value;
|
|
2019
2019
|
}
|
|
2020
2020
|
this.formHost.replaceChildren(), this.h.onInvoke(e.id, f);
|
|
2021
2021
|
}), i.append(o, c), t.append(i), this.formHost.append(t), (w = n.values().next().value) == null || w.focus();
|
|
@@ -2024,7 +2024,7 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-t
|
|
|
2024
2024
|
var x;
|
|
2025
2025
|
if (e.senderRole === "system") {
|
|
2026
2026
|
const h = a("div", "ocw-sys");
|
|
2027
|
-
return h.textContent = e.deletedAt ? "message deleted" :
|
|
2027
|
+
return h.textContent = e.deletedAt ? "message deleted" : Z(e.content), h;
|
|
2028
2028
|
}
|
|
2029
2029
|
const n = e.senderId === this.me, i = !!e.internal, o = a("div", `ocw-row ${i ? "ocw-note mine" : n ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
|
|
2030
2030
|
!n && !i && o.append(a("div", "ocw-dot", e.senderRole === "bot" ? "🤖" : "🧑"));
|
|
@@ -2039,115 +2039,115 @@ Message: ${o.value}`), this.offlinePanel.replaceChildren(a("div", "ocw-offline-t
|
|
|
2039
2039
|
else if (e.content.kind === "attachment") {
|
|
2040
2040
|
const h = e.content;
|
|
2041
2041
|
if ((x = h.mime) != null && x.startsWith("image/")) {
|
|
2042
|
-
const
|
|
2043
|
-
|
|
2042
|
+
const u = document.createElement("img");
|
|
2043
|
+
u.src = h.url, u.alt = h.name ?? "image", u.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", u.addEventListener("click", () => window.open(h.url, "_blank")), w.append(u);
|
|
2044
2044
|
} else {
|
|
2045
|
-
const
|
|
2046
|
-
|
|
2045
|
+
const u = document.createElement("a");
|
|
2046
|
+
u.href = h.url, u.target = "_blank", u.rel = "noopener", u.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", u.append(a("span", void 0, "📄"), a("span", void 0, h.name ?? "file")), w.append(u);
|
|
2047
2047
|
}
|
|
2048
2048
|
} else if (e.content.kind === "appointment") {
|
|
2049
|
-
const h = e.content,
|
|
2050
|
-
|
|
2051
|
-
const
|
|
2052
|
-
|
|
2053
|
-
const
|
|
2054
|
-
|
|
2049
|
+
const h = e.content, u = a("div", "ocw-appt");
|
|
2050
|
+
u.append(a("div", "ocw-appt-title", `📅 ${h.title}`)), u.append(a("div", "ocw-appt-time", new Date(h.startIso).toLocaleString() + " – " + new Date(h.endIso).toLocaleTimeString())), h.location && u.append(a("div", "ocw-appt-loc", `📍 ${h.location}`)), h.description && u.append(a("div", "ocw-appt-desc", h.description));
|
|
2051
|
+
const U = a("div", "ocw-appt-links"), v = document.createElement("a");
|
|
2052
|
+
v.href = h.googleUrl, v.target = "_blank", v.rel = "noopener", v.className = "ocw-appt-btn", v.textContent = "📅 Add to Google Calendar";
|
|
2053
|
+
const m = document.createElement("a");
|
|
2054
|
+
m.href = h.icalUrl, m.download = `${h.title}.ics`, m.className = "ocw-appt-btn ocw-appt-btn-sec", m.textContent = "🍎 Apple / iCal", U.append(v, m), u.append(U), w.append(u);
|
|
2055
2055
|
} else
|
|
2056
|
-
f = document.createTextNode(
|
|
2056
|
+
f = document.createTextNode(Z(e.content)), w.append(f), e.editedAt && w.append(a("span", "ocw-edited", "(edited)"));
|
|
2057
2057
|
if (l.append(w), !n && !i && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && f) {
|
|
2058
2058
|
const h = e.content.text;
|
|
2059
2059
|
if (h.trim()) {
|
|
2060
|
-
const
|
|
2061
|
-
|
|
2062
|
-
if (
|
|
2063
|
-
this.showingTranslation.delete(e.id), f.textContent = h,
|
|
2060
|
+
const u = a("button", "ocw-translate-btn", "🌐");
|
|
2061
|
+
u.type = "button", u.title = "Translate", u.addEventListener("click", (U) => {
|
|
2062
|
+
if (U.stopPropagation(), this.showingTranslation.has(e.id)) {
|
|
2063
|
+
this.showingTranslation.delete(e.id), f.textContent = h, u.textContent = "🌐", u.title = "Translate";
|
|
2064
2064
|
return;
|
|
2065
2065
|
}
|
|
2066
|
-
const
|
|
2067
|
-
if (
|
|
2068
|
-
this.showingTranslation.add(e.id), f.textContent =
|
|
2066
|
+
const v = this.translationCache.get(e.id);
|
|
2067
|
+
if (v !== void 0) {
|
|
2068
|
+
this.showingTranslation.add(e.id), f.textContent = v, u.textContent = "↩", u.title = "Show original";
|
|
2069
2069
|
return;
|
|
2070
2070
|
}
|
|
2071
|
-
|
|
2072
|
-
if (
|
|
2073
|
-
|
|
2074
|
-
|
|
2071
|
+
u.textContent = "⏳", this.h.onTranslate(h).then((m) => {
|
|
2072
|
+
if (m === null) {
|
|
2073
|
+
u.textContent = "⚠️", u.title = "Translation unavailable", setTimeout(() => {
|
|
2074
|
+
u.textContent = "🌐", u.title = "Translate";
|
|
2075
2075
|
}, 1500);
|
|
2076
2076
|
return;
|
|
2077
2077
|
}
|
|
2078
|
-
this.translationCache.set(e.id,
|
|
2078
|
+
this.translationCache.set(e.id, m), this.showingTranslation.add(e.id), f.textContent = m, u.textContent = "↩", u.title = "Show original";
|
|
2079
2079
|
});
|
|
2080
|
-
}), l.append(
|
|
2080
|
+
}), l.append(u);
|
|
2081
2081
|
}
|
|
2082
2082
|
}
|
|
2083
2083
|
if (n && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
|
|
2084
2084
|
const h = a("div", "ocw-msg-menu");
|
|
2085
2085
|
if (this.h.onEdit) {
|
|
2086
|
-
const
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
const
|
|
2090
|
-
|
|
2091
|
-
const
|
|
2092
|
-
|
|
2093
|
-
const
|
|
2094
|
-
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2097
|
-
const
|
|
2098
|
-
|
|
2099
|
-
const
|
|
2100
|
-
|
|
2101
|
-
const
|
|
2102
|
-
|
|
2103
|
-
}),
|
|
2104
|
-
|
|
2086
|
+
const u = a("button", void 0, "✏️");
|
|
2087
|
+
u.title = "Edit", u.addEventListener("click", (U) => {
|
|
2088
|
+
U.stopPropagation();
|
|
2089
|
+
const v = Z(e.content), m = document.createElement("textarea");
|
|
2090
|
+
m.value = v, m.rows = Math.min(4, Math.ceil(v.length / 40) + 1), m.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:#fff;color:#1c1b1a;box-sizing:border-box";
|
|
2091
|
+
const g = a("button", "ocw-form-submit", "Save");
|
|
2092
|
+
g.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
|
|
2093
|
+
const I = a("button", "ocw-form-cancel", "Cancel");
|
|
2094
|
+
I.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
|
|
2095
|
+
const K = a("div");
|
|
2096
|
+
K.style.cssText = "display:flex;gap:6px;justify-content:flex-end", K.append(I, g);
|
|
2097
|
+
const P = a("div");
|
|
2098
|
+
P.append(m, K), w.replaceChildren(P), m.focus(), m.select();
|
|
2099
|
+
const B = () => w.replaceChildren(f ?? document.createTextNode(v));
|
|
2100
|
+
I.addEventListener("click", B), g.addEventListener("click", () => {
|
|
2101
|
+
const T = m.value.trim();
|
|
2102
|
+
T && T !== v && this.h.onEdit(e.id, T), B();
|
|
2103
|
+
}), m.addEventListener("keydown", (T) => {
|
|
2104
|
+
T.key === "Enter" && !T.shiftKey && (T.preventDefault(), g.click()), T.key === "Escape" && B();
|
|
2105
2105
|
});
|
|
2106
|
-
}), h.append(
|
|
2106
|
+
}), h.append(u);
|
|
2107
2107
|
}
|
|
2108
2108
|
if (this.h.onDelete) {
|
|
2109
|
-
const
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
}), h.append(
|
|
2109
|
+
const u = a("button", "del", "🗑");
|
|
2110
|
+
u.title = "Delete", u.addEventListener("click", (U) => {
|
|
2111
|
+
U.stopPropagation(), this.h.onDelete(e.id);
|
|
2112
|
+
}), h.append(u);
|
|
2113
2113
|
}
|
|
2114
2114
|
l.append(h);
|
|
2115
2115
|
}
|
|
2116
2116
|
if (c.append(l), this.h.onReact && !e.deletedAt && e.seq > 0) {
|
|
2117
|
-
const h = a("div", "ocw-react-wrap"),
|
|
2117
|
+
const h = a("div", "ocw-react-wrap"), u = a("div", "ocw-react");
|
|
2118
2118
|
if (e.reactions && Object.keys(e.reactions).length)
|
|
2119
|
-
for (const [
|
|
2120
|
-
const
|
|
2121
|
-
|
|
2122
|
-
var
|
|
2123
|
-
return (
|
|
2124
|
-
}),
|
|
2119
|
+
for (const [m, g] of Object.entries(e.reactions)) {
|
|
2120
|
+
const I = a("button", `ocw-react-pill${g.includes(this.me) ? " mine" : ""}`, `${m} ${g.length}`);
|
|
2121
|
+
I.addEventListener("click", () => {
|
|
2122
|
+
var K, P;
|
|
2123
|
+
return (P = (K = this.h).onReact) == null ? void 0 : P.call(K, e.id, m, g.includes(this.me));
|
|
2124
|
+
}), u.append(I);
|
|
2125
2125
|
}
|
|
2126
|
-
const
|
|
2127
|
-
for (const
|
|
2128
|
-
const
|
|
2129
|
-
|
|
2130
|
-
var
|
|
2131
|
-
|
|
2132
|
-
const
|
|
2133
|
-
(
|
|
2134
|
-
}),
|
|
2126
|
+
const U = a("button", "ocw-react-btn", "+"), v = a("div", "ocw-react-picker");
|
|
2127
|
+
for (const m of Lt) {
|
|
2128
|
+
const g = a("button", void 0, m);
|
|
2129
|
+
g.addEventListener("click", (I) => {
|
|
2130
|
+
var P, B, T, M;
|
|
2131
|
+
I.stopPropagation();
|
|
2132
|
+
const K = (B = (P = e.reactions) == null ? void 0 : P[m]) == null ? void 0 : B.includes(this.me);
|
|
2133
|
+
(M = (T = this.h).onReact) == null || M.call(T, e.id, m, !!K), v.style.display = "none";
|
|
2134
|
+
}), v.append(g);
|
|
2135
2135
|
}
|
|
2136
|
-
|
|
2137
|
-
|
|
2136
|
+
v.style.display = "none", U.addEventListener("click", (m) => {
|
|
2137
|
+
m.stopPropagation(), v.style.display = v.style.display === "none" ? "flex" : "none";
|
|
2138
2138
|
}), document.addEventListener("click", () => {
|
|
2139
|
-
|
|
2140
|
-
}, { once: !0 }),
|
|
2141
|
-
} else e.reactions && Object.keys(e.reactions).length && c.append(a("div", "ocw-react", Object.entries(e.reactions).map(([h,
|
|
2142
|
-
const
|
|
2139
|
+
v.style.display = "none";
|
|
2140
|
+
}, { once: !0 }), u.append(U), h.append(u, v), c.append(h);
|
|
2141
|
+
} else e.reactions && Object.keys(e.reactions).length && c.append(a("div", "ocw-react", Object.entries(e.reactions).map(([h, u]) => `${h}${u.length}`).join(" ")));
|
|
2142
|
+
const b = a("div", "ocw-time ocw-meta", _t(e.ts));
|
|
2143
2143
|
if (n && e.status) {
|
|
2144
|
-
const h = a("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`,
|
|
2145
|
-
|
|
2144
|
+
const h = a("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Ht(e.status));
|
|
2145
|
+
b.append(h);
|
|
2146
2146
|
}
|
|
2147
|
-
return n && e.seq > 0 && t.lastReadByOthers >= e.seq &&
|
|
2147
|
+
return n && e.seq > 0 && t.lastReadByOthers >= e.seq && b.append(a("span", "ocw-seen", " · Seen")), c.append(b), o.append(c), o;
|
|
2148
2148
|
}
|
|
2149
2149
|
}
|
|
2150
|
-
function
|
|
2150
|
+
function Ht(s) {
|
|
2151
2151
|
switch (s) {
|
|
2152
2152
|
case "read":
|
|
2153
2153
|
return "✓✓";
|
|
@@ -2160,25 +2160,25 @@ function _t(s) {
|
|
|
2160
2160
|
}
|
|
2161
2161
|
}
|
|
2162
2162
|
const R = /* @__PURE__ */ new WeakMap();
|
|
2163
|
-
function
|
|
2163
|
+
function qt(s) {
|
|
2164
2164
|
var e;
|
|
2165
2165
|
(e = R.get(s)) == null || e.close(), R.delete(s);
|
|
2166
2166
|
}
|
|
2167
|
-
function
|
|
2167
|
+
function Ot(s) {
|
|
2168
2168
|
var ae, ce, de, le;
|
|
2169
2169
|
R.has(s.el) && (R.get(s.el).close(), R.delete(s.el));
|
|
2170
|
-
const e = s.token ??
|
|
2171
|
-
let t = new
|
|
2172
|
-
const n = s.subjectId ? `${e}::${s.subjectId}` : e, i = new
|
|
2170
|
+
const e = s.token ?? Ke();
|
|
2171
|
+
let t = new gt(e);
|
|
2172
|
+
const n = s.subjectId ? `${e}::${s.subjectId}` : e, i = new kt(n);
|
|
2173
2173
|
let o, c = !1, l = null, w = null;
|
|
2174
2174
|
!s.launcher && !s.el.style.height && s.el.clientHeight === 0 && (s.el.style.width = s.el.style.width || "100%", s.el.style.height = "600px");
|
|
2175
2175
|
for (const d of i.load()) t.addOptimistic(d.clientMsgId, d.content);
|
|
2176
|
-
let f = null,
|
|
2176
|
+
let f = null, b = null, x = 0, h = !s.launcher;
|
|
2177
2177
|
if (s.launcher) {
|
|
2178
|
-
const
|
|
2179
|
-
f = document.createElement("div"), f.style.cssText = `position:fixed;${
|
|
2180
|
-
const
|
|
2181
|
-
|
|
2178
|
+
const p = (s.position ?? "bottom-right").includes("right");
|
|
2179
|
+
f = document.createElement("div"), f.style.cssText = `position:fixed;${p ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${p ? "flex-end" : "flex-start"};gap:12px`;
|
|
2180
|
+
const y = document.createElement("div"), E = typeof window < "u" ? window.matchMedia("(max-width: 479px)") : null, D = (_) => {
|
|
2181
|
+
y.style.cssText = _ ? [
|
|
2182
2182
|
"position:fixed",
|
|
2183
2183
|
"inset:0",
|
|
2184
2184
|
"width:100%",
|
|
@@ -2201,124 +2201,128 @@ function jt(s) {
|
|
|
2201
2201
|
"display:none",
|
|
2202
2202
|
"flex-direction:column",
|
|
2203
2203
|
"background:#fff",
|
|
2204
|
-
"transform-origin:bottom " + (
|
|
2204
|
+
"transform-origin:bottom " + (p ? "right" : "left"),
|
|
2205
2205
|
"transition:opacity .18s,transform .18s",
|
|
2206
2206
|
"opacity:0",
|
|
2207
2207
|
"transform:scale(.95)"
|
|
2208
2208
|
].join(";");
|
|
2209
2209
|
};
|
|
2210
|
-
|
|
2211
|
-
const
|
|
2212
|
-
|
|
2210
|
+
D((E == null ? void 0 : E.matches) ?? !1), E == null || E.addEventListener("change", (_) => D(_.matches)), l = E, w = D, s.el.style.cssText = "width:100%;height:100%;overflow:hidden", y.append(s.el);
|
|
2211
|
+
const C = document.createElement("button");
|
|
2212
|
+
C.style.cssText = [
|
|
2213
2213
|
"width:56px;height:56px;border-radius:50%",
|
|
2214
2214
|
`background:${s.accent ?? "#4F63F5"}`,
|
|
2215
2215
|
"color:#fff;border:none;font-size:24px;cursor:pointer",
|
|
2216
2216
|
"box-shadow:0 4px 16px rgba(0,0,0,.25)",
|
|
2217
2217
|
"position:relative;flex:none",
|
|
2218
2218
|
"transition:transform .15s"
|
|
2219
|
-
].join(";"),
|
|
2220
|
-
|
|
2221
|
-
},
|
|
2222
|
-
|
|
2223
|
-
},
|
|
2224
|
-
const V = (
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
})) : (
|
|
2228
|
-
h || (
|
|
2219
|
+
].join(";"), C.textContent = "💬", C.onmouseenter = () => {
|
|
2220
|
+
C.style.transform = "scale(1.08)";
|
|
2221
|
+
}, C.onmouseleave = () => {
|
|
2222
|
+
C.style.transform = "scale(1)";
|
|
2223
|
+
}, b = document.createElement("span"), b.style.cssText = "position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center", C.append(b), f.append(y, C), document.body.append(f);
|
|
2224
|
+
const V = (_) => {
|
|
2225
|
+
_ ? (y.style.display = "flex", requestAnimationFrame(() => {
|
|
2226
|
+
y.style.opacity = "1", y.style.transform = "scale(1)";
|
|
2227
|
+
})) : (y.style.opacity = "0", y.style.transform = "scale(.95)", setTimeout(() => {
|
|
2228
|
+
h || (y.style.display = "none");
|
|
2229
2229
|
}, 180));
|
|
2230
2230
|
};
|
|
2231
|
-
|
|
2232
|
-
h = !h, V(h),
|
|
2233
|
-
}), document.addEventListener("keydown", (
|
|
2234
|
-
|
|
2231
|
+
C.addEventListener("click", () => {
|
|
2232
|
+
h = !h, V(h), C.textContent = h ? "✕" : "💬", C.append(b), h && (x = 0, b && (b.style.display = "none"));
|
|
2233
|
+
}), document.addEventListener("keydown", (_) => {
|
|
2234
|
+
_.key === "Escape" && h && (h = !1, V(!1), C.textContent = "💬", C.append(b));
|
|
2235
2235
|
});
|
|
2236
2236
|
}
|
|
2237
|
-
const
|
|
2238
|
-
h || (x++,
|
|
2239
|
-
},
|
|
2237
|
+
const u = () => {
|
|
2238
|
+
h || (x++, b && (b.textContent = String(x), b.style.display = "flex"));
|
|
2239
|
+
}, U = () => {
|
|
2240
2240
|
try {
|
|
2241
|
-
const d = new AudioContext(),
|
|
2242
|
-
|
|
2241
|
+
const d = new AudioContext(), p = d.createOscillator(), y = d.createGain();
|
|
2242
|
+
p.connect(y), y.connect(d.destination), p.frequency.setValueAtTime(880, d.currentTime), p.frequency.exponentialRampToValueAtTime(440, d.currentTime + 0.15), y.gain.setValueAtTime(0.3, d.currentTime), y.gain.exponentialRampToValueAtTime(1e-3, d.currentTime + 0.3), p.start(), p.stop(d.currentTime + 0.3);
|
|
2243
2243
|
} catch {
|
|
2244
2244
|
}
|
|
2245
|
+
}, v = [], m = (d) => {
|
|
2246
|
+
for (; v.length; ) {
|
|
2247
|
+
const p = v.shift();
|
|
2248
|
+
i.add({ clientMsgId: p.clientMsgId, content: p.content, ts: Date.now() }), g.send({ type: "send", conversationId: d, clientMsgId: p.clientMsgId, content: p.content });
|
|
2249
|
+
}
|
|
2245
2250
|
};
|
|
2246
|
-
let
|
|
2247
|
-
const
|
|
2248
|
-
let
|
|
2249
|
-
const
|
|
2250
|
-
let
|
|
2251
|
-
const
|
|
2252
|
-
|
|
2253
|
-
o &&
|
|
2251
|
+
let g;
|
|
2252
|
+
const I = new At(`ocw-e2e-${s.profileId}`);
|
|
2253
|
+
let K = !1;
|
|
2254
|
+
const P = [], B = [];
|
|
2255
|
+
let T = !1;
|
|
2256
|
+
const M = (d, p) => {
|
|
2257
|
+
I.sealText(p).then((y) => {
|
|
2258
|
+
o && g.send({ type: "send", conversationId: o, clientMsgId: d, content: y });
|
|
2254
2259
|
});
|
|
2255
|
-
},
|
|
2256
|
-
|
|
2257
|
-
o &&
|
|
2260
|
+
}, k = (d, p, y) => {
|
|
2261
|
+
I.sealText(p, y).then((E) => {
|
|
2262
|
+
o && g.send({ type: "send", conversationId: o, clientMsgId: d, content: E });
|
|
2258
2263
|
});
|
|
2259
|
-
},
|
|
2260
|
-
for (;
|
|
2261
|
-
const d =
|
|
2262
|
-
|
|
2264
|
+
}, A = () => {
|
|
2265
|
+
for (; P.length; ) {
|
|
2266
|
+
const d = P.shift();
|
|
2267
|
+
M(d.clientMsgId, d.text);
|
|
2263
2268
|
}
|
|
2264
|
-
for (;
|
|
2265
|
-
const d =
|
|
2266
|
-
|
|
2269
|
+
for (; B.length; ) {
|
|
2270
|
+
const d = B.shift();
|
|
2271
|
+
M(d.clientMsgId, d.text);
|
|
2267
2272
|
}
|
|
2268
|
-
},
|
|
2269
|
-
|
|
2270
|
-
},
|
|
2271
|
-
|
|
2272
|
-
const L = new
|
|
2273
|
+
}, G = (d) => {
|
|
2274
|
+
g.send({ type: "fetchPrekey", targetUserId: d });
|
|
2275
|
+
}, ke = s.i18n ?? {}, Se = ["ar", "he", "fa", "ur"], Ie = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
|
|
2276
|
+
Se.includes(Ie) && !s.el.dir && (s.el.dir = "rtl", s.el.style.fontFamily = s.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
|
|
2277
|
+
const L = new $t(s.el, e, {
|
|
2273
2278
|
onSend(d) {
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
t.addOptimistic(u, { kind: "text", text: d }), L.render(t), t.e2e ? g.ready ? K(u, d) : B ? U.push({ clientMsgId: u, text: d }) : (T.push({ clientMsgId: u, text: d }), t.assignedAgentId && v(t.assignedAgentId)) : (i.add({ clientMsgId: u, content: { kind: "text", text: d }, ts: Date.now() }), y.send({ type: "send", conversationId: o, clientMsgId: u, content: { kind: "text", text: d } }));
|
|
2279
|
+
const p = `cm_${Math.random().toString(36).slice(2)}`, y = { kind: "text", text: d };
|
|
2280
|
+
t.addOptimistic(p, y), L.render(t), t.e2e ? I.ready ? M(p, d) : T ? B.push({ clientMsgId: p, text: d }) : (P.push({ clientMsgId: p, text: d }), t.assignedAgentId && G(t.assignedAgentId)) : o ? (i.add({ clientMsgId: p, content: y, ts: Date.now() }), g.send({ type: "send", conversationId: o, clientMsgId: p, content: y })) : v.push({ clientMsgId: p, content: y });
|
|
2277
2281
|
},
|
|
2278
2282
|
async onAttach(d) {
|
|
2279
2283
|
if (!o) return;
|
|
2280
|
-
const
|
|
2281
|
-
t.addOptimistic(
|
|
2284
|
+
const E = `${s.url.replace(/^ws/, "http").replace(/\/ws$/, "")}/upload?name=${encodeURIComponent(d.name)}`, D = `cm_${Math.random().toString(36).slice(2)}`;
|
|
2285
|
+
t.addOptimistic(D, { kind: "text", text: `📎 Uploading ${d.name}…` }), L.render(t);
|
|
2282
2286
|
try {
|
|
2283
|
-
const
|
|
2287
|
+
const C = await fetch(E, {
|
|
2284
2288
|
method: "POST",
|
|
2285
2289
|
headers: { "content-type": d.type, ...s.token ? { authorization: `Bearer ${s.token}` } : {} },
|
|
2286
2290
|
body: d
|
|
2287
2291
|
});
|
|
2288
|
-
if (!
|
|
2289
|
-
const { url: V, name:
|
|
2290
|
-
|
|
2291
|
-
} catch (
|
|
2292
|
-
t.addOptimistic(
|
|
2292
|
+
if (!C.ok) throw new Error(`Upload failed: ${C.status}`);
|
|
2293
|
+
const { url: V, name: _, mime: Te, size: Ue } = await C.json();
|
|
2294
|
+
g.send({ type: "send", conversationId: o, clientMsgId: D, content: { kind: "attachment", url: V, name: _, mime: Te, size: Ue } });
|
|
2295
|
+
} catch (C) {
|
|
2296
|
+
t.addOptimistic(D, { kind: "text", text: `⚠️ Upload failed: ${C.message}` }), L.render(t);
|
|
2293
2297
|
}
|
|
2294
2298
|
},
|
|
2295
|
-
onInvoke(d,
|
|
2296
|
-
o &&
|
|
2299
|
+
onInvoke(d, p) {
|
|
2300
|
+
o && g.send({ type: "invoke", conversationId: o, actionId: d, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...p ? { inputs: p } : {} });
|
|
2297
2301
|
},
|
|
2298
2302
|
onTyping(d) {
|
|
2299
|
-
o &&
|
|
2303
|
+
o && g.send({ type: "typing", conversationId: o, isTyping: d });
|
|
2300
2304
|
},
|
|
2301
2305
|
onReadUpTo(d) {
|
|
2302
|
-
o &&
|
|
2306
|
+
o && g.send({ type: "read", conversationId: o, seq: d });
|
|
2303
2307
|
},
|
|
2304
2308
|
onLoadMore() {
|
|
2305
2309
|
if (!o || !t.e2e) return;
|
|
2306
2310
|
const d = t.messages()[0];
|
|
2307
|
-
d &&
|
|
2311
|
+
d && g.send({ type: "history", conversationId: o, beforeSeq: d.seq, limit: 20 });
|
|
2308
2312
|
},
|
|
2309
|
-
onEdit(d,
|
|
2310
|
-
o &&
|
|
2313
|
+
onEdit(d, p) {
|
|
2314
|
+
o && g.send({ type: "edit", conversationId: o, messageId: d, content: { kind: "text", text: p } });
|
|
2311
2315
|
},
|
|
2312
2316
|
onDelete(d) {
|
|
2313
|
-
o &&
|
|
2317
|
+
o && g.send({ type: "delete", conversationId: o, messageId: d });
|
|
2314
2318
|
},
|
|
2315
|
-
onReact(d,
|
|
2316
|
-
o &&
|
|
2319
|
+
onReact(d, p, y) {
|
|
2320
|
+
o && g.send({ type: "react", conversationId: o, messageId: d, emoji: p, remove: y });
|
|
2317
2321
|
},
|
|
2318
2322
|
onCsat(d) {
|
|
2319
2323
|
if (!o) return;
|
|
2320
|
-
const
|
|
2321
|
-
fetch(`${
|
|
2324
|
+
const p = ze(s.url);
|
|
2325
|
+
fetch(`${p}/conversations/${o}/csat`, {
|
|
2322
2326
|
method: "POST",
|
|
2323
2327
|
headers: { "Content-Type": "application/json", Authorization: `Bearer ${e}` },
|
|
2324
2328
|
body: JSON.stringify({ score: d })
|
|
@@ -2326,23 +2330,23 @@ function jt(s) {
|
|
|
2326
2330
|
});
|
|
2327
2331
|
},
|
|
2328
2332
|
onAnnotate(d) {
|
|
2329
|
-
o &&
|
|
2333
|
+
o && g.send({ type: "annotate", conversationId: o, stroke: d });
|
|
2330
2334
|
},
|
|
2331
2335
|
onAnnotateClear() {
|
|
2332
|
-
o &&
|
|
2336
|
+
o && g.send({ type: "annotate_clear", conversationId: o });
|
|
2333
2337
|
},
|
|
2334
2338
|
...s.translateLang ? {
|
|
2335
2339
|
async onTranslate(d) {
|
|
2336
|
-
const
|
|
2340
|
+
const p = s.url.replace(/^ws/, "http").replace(/\/+$/, "");
|
|
2337
2341
|
try {
|
|
2338
|
-
const
|
|
2342
|
+
const y = await fetch(`${p}/translate`, {
|
|
2339
2343
|
method: "POST",
|
|
2340
2344
|
headers: { "content-type": "application/json", authorization: `Bearer ${e}` },
|
|
2341
2345
|
body: JSON.stringify({ text: d, targetLang: s.translateLang })
|
|
2342
2346
|
});
|
|
2343
|
-
if (!
|
|
2344
|
-
const { translated:
|
|
2345
|
-
return
|
|
2347
|
+
if (!y.ok) return null;
|
|
2348
|
+
const { translated: E } = await y.json();
|
|
2349
|
+
return E;
|
|
2346
2350
|
} catch {
|
|
2347
2351
|
return null;
|
|
2348
2352
|
}
|
|
@@ -2353,8 +2357,8 @@ function jt(s) {
|
|
|
2353
2357
|
...s.quickReplies ? { quickReplies: s.quickReplies } : {},
|
|
2354
2358
|
...s.accent ? { accent: s.accent } : {},
|
|
2355
2359
|
...(ae = s.user) != null && ae.name || (ce = s.user) != null && ce.avatar ? { userInfo: { ...s.user.name ? { name: s.user.name } : {}, ...s.user.avatar ? { avatar: s.user.avatar } : {} } } : {},
|
|
2356
|
-
i18n:
|
|
2357
|
-
}),
|
|
2360
|
+
i18n: ke
|
|
2361
|
+
}), Ce = {
|
|
2358
2362
|
type: "open",
|
|
2359
2363
|
profileId: s.profileId,
|
|
2360
2364
|
...s.subjectId ? { subjectId: s.subjectId } : {},
|
|
@@ -2364,82 +2368,82 @@ function jt(s) {
|
|
|
2364
2368
|
// This is how listingTitle and listingMeta get saved without a separate API call.
|
|
2365
2369
|
...(de = s.subject) != null && de.title ? { subjectTitle: s.subject.title } : {},
|
|
2366
2370
|
...(le = s.subject) != null && le.subtitle ? { subjectMeta: s.subject.subtitle } : {}
|
|
2367
|
-
},
|
|
2368
|
-
const
|
|
2369
|
-
if (!
|
|
2370
|
-
const
|
|
2371
|
-
if (
|
|
2372
|
-
|
|
2373
|
-
${
|
|
2371
|
+
}, Ee = (d) => {
|
|
2372
|
+
const p = s.user;
|
|
2373
|
+
if (!p || !p.name && !p.email && !p.avatar && !p.meta) return;
|
|
2374
|
+
const y = [];
|
|
2375
|
+
if (p.name && y.push(`Name: ${p.name}`), p.email && y.push(`Email: ${p.email}`), p.avatar && y.push(`Avatar: ${p.avatar}`), p.meta) for (const [E, D] of Object.entries(p.meta)) y.push(`${E}: ${D}`);
|
|
2376
|
+
g.send({ type: "note", conversationId: d, clientMsgId: `ui_${Date.now()}`, text: `[User info]
|
|
2377
|
+
${y.join(`
|
|
2374
2378
|
`)}` });
|
|
2375
2379
|
};
|
|
2376
|
-
|
|
2380
|
+
g = new bt({
|
|
2377
2381
|
url: s.url,
|
|
2378
2382
|
token: e,
|
|
2379
|
-
open:
|
|
2383
|
+
open: Ce,
|
|
2380
2384
|
getCursor: () => t.highestSeq(),
|
|
2381
2385
|
onStatusChange: (d) => L.setConnStatus(d),
|
|
2382
2386
|
onFrame(d) {
|
|
2383
2387
|
if (d.type === "opened") {
|
|
2384
|
-
const
|
|
2388
|
+
const p = o === void 0;
|
|
2385
2389
|
if (o = d.conversation.id, !c) {
|
|
2386
2390
|
c = !0;
|
|
2387
|
-
for (const
|
|
2388
|
-
|
|
2391
|
+
for (const y of i.load())
|
|
2392
|
+
g.send({ type: "send", conversationId: o, clientMsgId: y.clientMsgId, content: y.content });
|
|
2389
2393
|
}
|
|
2390
|
-
|
|
2394
|
+
Ae(s.url, e, o, t, L), v.length && m(o), p && d.conversation.lastSeq === 0 && Ee(o);
|
|
2391
2395
|
}
|
|
2392
2396
|
if (d.type === "ack" && i.remove(d.clientMsgId), d.type === "prekeyBundle") {
|
|
2393
|
-
d.bundle && (
|
|
2394
|
-
const
|
|
2395
|
-
for (const
|
|
2397
|
+
d.bundle && (T = !0, I.x3dhSendTo(d.bundle).then((p) => {
|
|
2398
|
+
const y = [...P.splice(0), ...B.splice(0)];
|
|
2399
|
+
for (const E of y) k(E.clientMsgId, E.text, p);
|
|
2396
2400
|
L.render(t);
|
|
2397
2401
|
}));
|
|
2398
2402
|
return;
|
|
2399
2403
|
}
|
|
2400
2404
|
if (d.type === "message" && t.e2e) {
|
|
2401
|
-
const
|
|
2402
|
-
if (
|
|
2403
|
-
|
|
2404
|
-
await
|
|
2405
|
+
const p = zt(d.message.content);
|
|
2406
|
+
if (p && !I.ready) {
|
|
2407
|
+
I.x3dhReceiveFrom(p.x3dhIK, p.x3dhEK, p.x3dhSPK).then(async () => {
|
|
2408
|
+
await I.openFrame(d), t.apply(d), L.render(t);
|
|
2405
2409
|
});
|
|
2406
2410
|
return;
|
|
2407
2411
|
}
|
|
2408
2412
|
}
|
|
2409
2413
|
if (d.type === "peerkey") {
|
|
2410
|
-
|
|
2411
|
-
|
|
2414
|
+
I.onPeerKey(d.key).then(() => {
|
|
2415
|
+
A(), L.render(t);
|
|
2412
2416
|
});
|
|
2413
2417
|
return;
|
|
2414
2418
|
}
|
|
2415
2419
|
(async () => {
|
|
2416
|
-
if (t.e2e && await
|
|
2417
|
-
|
|
2418
|
-
const
|
|
2419
|
-
|
|
2420
|
-
const
|
|
2421
|
-
|
|
2420
|
+
if (t.e2e && await I.openFrame(d), t.apply(d), d.type === "message" && d.message.senderId !== e && !d.message.internal && (u(), U()), t.e2e && o && !K) {
|
|
2421
|
+
K = !0;
|
|
2422
|
+
const p = await I.initX3DH();
|
|
2423
|
+
g.send({ type: "uploadPrekeys", ...p });
|
|
2424
|
+
const y = await I.begin();
|
|
2425
|
+
g.send({ type: "pubkey", conversationId: o, key: y });
|
|
2422
2426
|
}
|
|
2423
2427
|
L.render(t);
|
|
2424
2428
|
})();
|
|
2425
2429
|
}
|
|
2426
|
-
}),
|
|
2430
|
+
}), g.connect(), L.render(t);
|
|
2427
2431
|
const re = { close: () => {
|
|
2428
|
-
|
|
2432
|
+
g.close(), f == null || f.remove(), L.destroy(), l && w && l.removeEventListener("change", (d) => w(d.matches)), R.delete(s.el);
|
|
2429
2433
|
} };
|
|
2430
2434
|
return R.set(s.el, re), re;
|
|
2431
2435
|
}
|
|
2432
2436
|
export {
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2437
|
+
gt as ChatStore,
|
|
2438
|
+
bt as ConnectionManager,
|
|
2439
|
+
At as E2ESession,
|
|
2440
|
+
kt as PersistentOutbox,
|
|
2441
|
+
$t as Renderer,
|
|
2442
|
+
jt as asConversationId,
|
|
2443
|
+
zt as extractX3DHInit,
|
|
2444
|
+
ze as httpBaseFromWsUrl,
|
|
2445
|
+
Ot as mount,
|
|
2446
|
+
Ae as restoreHistory,
|
|
2447
|
+
qt as unmount
|
|
2444
2448
|
};
|
|
2445
2449
|
//# sourceMappingURL=index.js.map
|