@talkjs/core 0.0.5 → 1.0.0

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.
@@ -0,0 +1,3202 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a2, b2) => {
9
+ for (var prop in b2 || (b2 = {}))
10
+ if (__hasOwnProp.call(b2, prop))
11
+ __defNormalProp(a2, prop, b2[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b2)) {
14
+ if (__propIsEnum.call(b2, prop))
15
+ __defNormalProp(a2, prop, b2[prop]);
16
+ }
17
+ return a2;
18
+ };
19
+ var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e2) {
38
+ reject(e2);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e2) {
45
+ reject(e2);
46
+ }
47
+ };
48
+ var step = (x2) => x2.done ? resolve(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
52
+ var _a;
53
+ function e(e2, s2) {
54
+ if (s2.ok) return s2.value.data;
55
+ if ("SESSION_DESTROYED" === s2.value) throw new Error(`${e2} failed because the session was destroyed`);
56
+ if ("server" === s2.where) throw new Error(t(e2, s2.value));
57
+ throw "unreachable";
58
+ }
59
+ function t(e2, t2) {
60
+ let s2;
61
+ return s2 = Array.isArray(t2.reasons) ? t2.reasons.join() : JSON.stringify(t2.reasons), `${e2} failed, got status ${t2.status} ${t2.errorCode}, reasons: ${s2}`;
62
+ }
63
+ function s(e2, t2) {
64
+ if (e2.length !== t2.length) return false;
65
+ for (let s2 = 0; s2 < e2.length; s2++) if ("*" !== t2[s2] && e2[s2] !== t2[s2]) return false;
66
+ return true;
67
+ }
68
+ function n(e2) {
69
+ return e2 <= 0 ? Promise.resolve() : new Promise((t2) => setTimeout(t2, e2));
70
+ }
71
+ function r(e2, t2) {
72
+ return e2 * (1 - t2 + 2 * Math.random() * t2);
73
+ }
74
+ const i = () => true;
75
+ function a(_0, _1, _2) {
76
+ return __async(this, arguments, function* (e2, t2, { initialDelay: s2, maxDelay: o2, log: u2, shouldRetry: c2 = i }) {
77
+ return t2().catch((i2) => __async(this, null, function* () {
78
+ if (0 === e2) throw i2;
79
+ if (!(yield c2(i2))) throw i2;
80
+ const l2 = 1e3 * s2 * 1.2, h2 = r(o2 ? Math.min(1e3 * o2, l2) : l2, 0.05);
81
+ return n(h2).then(() => a(e2 - 1, t2, { initialDelay: h2 / 1e3, maxDelay: o2, log: u2, shouldRetry: c2 }));
82
+ }));
83
+ });
84
+ }
85
+ function o() {
86
+ const e2 = {}, t2 = new Promise(function(t3, s2) {
87
+ e2.resolve = t3, e2.reject = s2;
88
+ });
89
+ return e2.promise = t2, e2;
90
+ }
91
+ class u {
92
+ constructor(e2, t2, s2) {
93
+ this.layer = e2, this.states = t2, this.transitions = s2, this._state = t2[0];
94
+ }
95
+ get state() {
96
+ return this._state;
97
+ }
98
+ transition(e2) {
99
+ const t2 = this.transitions[e2];
100
+ if (!t2) return;
101
+ if (!this.canTransition(e2)) return;
102
+ const s2 = this.state;
103
+ this._state = t2.to, t2.afterTransition({ from: s2, to: this.state });
104
+ }
105
+ canTransition(e2) {
106
+ const t2 = this.transitions[e2];
107
+ return !!t2 && ("ANY" === t2.from || t2.from.includes(this.state));
108
+ }
109
+ }
110
+ function c(e2) {
111
+ return { ok: true, value: e2 };
112
+ }
113
+ function l(e2) {
114
+ return { ok: false, where: "client", value: e2 };
115
+ }
116
+ function h(e2) {
117
+ return { ok: false, where: "server", value: e2 };
118
+ }
119
+ function d() {
120
+ const e2 = {}, t2 = new Promise((t3) => {
121
+ e2.ok = (e3) => __async(this, null, function* () {
122
+ return t3(c(e3));
123
+ }), e2.clientErr = (e3) => t3(l(e3)), e2.serverErr = (e3) => t3(h(e3)), e2.resolve = (e3) => t3(e3);
124
+ });
125
+ return e2.promise = t2, e2;
126
+ }
127
+ let p = null;
128
+ function f({ WebSocket: e2 }) {
129
+ p = e2;
130
+ }
131
+ class m {
132
+ constructor(e2, t2) {
133
+ this.realtimeUrl = e2, this.handlers = t2, this.socket = null, this.throttler = new g(), this.stateMachine = new u("ReconnectingSocket", ["STOPPED", "WAITING_FOR_THROTTLER", "CONNECTING", "READY", "TERMINATED"], { queueAutoReconnect: { from: ["READY", "CONNECTING"], to: "WAITING_FOR_THROTTLER", afterTransition: ({ from: e3 }) => {
134
+ "READY" === e3 && this.handlers.onClose(), this.throttler.request(() => {
135
+ this.stateMachine.transition("connect");
136
+ });
137
+ } }, stop: { from: ["WAITING_FOR_THROTTLER", "CONNECTING", "READY"], to: "STOPPED", afterTransition: ({ from: e3 }) => {
138
+ var _a2;
139
+ "READY" === e3 && this.handlers.onClose(), (_a2 = this == null ? void 0 : this.socket) == null ? void 0 : _a2.close(1e3), this.socket = null, this.throttler.resetDelay();
140
+ } }, connect: { from: ["STOPPED", "WAITING_FOR_THROTTLER"], to: "CONNECTING", afterTransition: () => this.createWebSocket() }, ready: { from: ["CONNECTING"], to: "READY", afterTransition: () => {
141
+ this.throttler.resetDelay(), this.handlers.onOpen();
142
+ } }, destroy: { from: "ANY", to: "TERMINATED", afterTransition: () => {
143
+ var _a2;
144
+ (_a2 = this.socket) == null ? void 0 : _a2.close(1e3);
145
+ } } });
146
+ }
147
+ stopWs() {
148
+ "TERMINATED" !== this.stateMachine.state && this.stateMachine.transition("stop");
149
+ }
150
+ startWs() {
151
+ this.stateMachine.canTransition("connect") && this.stateMachine.transition("connect");
152
+ }
153
+ createWebSocket() {
154
+ var _a2;
155
+ (_a2 = this == null ? void 0 : this.socket) == null ? void 0 : _a2.close(1e3);
156
+ const e2 = new (function() {
157
+ if (p) return p;
158
+ if (globalThis.WebSocket) return globalThis.WebSocket;
159
+ throw new Error("Missing WebSocket implementation");
160
+ }())(this.realtimeUrl);
161
+ this.socket = e2;
162
+ const t2 = () => this.stateMachine.transition("ready");
163
+ e2.addEventListener("open", t2), e2.addEventListener("message", this.handlers.onMessage);
164
+ const s2 = () => {
165
+ e2.removeEventListener("open", t2), e2.removeEventListener("close", s2), e2.removeEventListener("message", this.handlers.onMessage), "TERMINATED" !== this.stateMachine.state && "STOPPED" !== this.stateMachine.state && this.stateMachine.transition("queueAutoReconnect");
166
+ };
167
+ e2.addEventListener("close", s2);
168
+ }
169
+ send(e2) {
170
+ return "READY" === this.stateMachine.state ? (this.socket.send(e2), c(void 0)) : l("SOCKET_NOT_READY");
171
+ }
172
+ terminate() {
173
+ if (this.socket) if ("terminate" in this.socket) this.socket.terminate();
174
+ else if ("dispatchEvent" in this.socket) {
175
+ this.socket.close(1e3);
176
+ const e2 = new Event("close"), t2 = Object.assign(e2, { code: 1e3, reason: "", wasClean: true });
177
+ this.socket.dispatchEvent(t2);
178
+ } else this.socket.close(1e3);
179
+ }
180
+ destroy() {
181
+ this.stateMachine.transition("destroy");
182
+ }
183
+ }
184
+ let g = class {
185
+ constructor() {
186
+ this.initialDelayMs = 200 + 200 * Math.random(), this.exponentialFactor = 1.2, this.maxDelayMs = 1e4, this.currentDelayMs = this.initialDelayMs;
187
+ }
188
+ request(e2) {
189
+ const t2 = r(this.currentDelayMs, 0.05);
190
+ n(this.currentDelayMs).then(() => e2()), this.currentDelayMs = Math.min(t2 * this.exponentialFactor, this.maxDelayMs);
191
+ }
192
+ resetDelay() {
193
+ this.currentDelayMs = this.initialDelayMs;
194
+ }
195
+ };
196
+ class v {
197
+ constructor(e2, t2) {
198
+ this.handlers = t2, this.socket = new m(e2, { onOpen: () => this.handlers.onOpen(), onClose: () => this.handlers.onClose(), onMessage: (e3) => this.onWebSocketMessage(e3) });
199
+ }
200
+ call(e2, t2, s2, n2) {
201
+ const r2 = `/${s2.map((e3) => encodeURIComponent(e3)).join("/")}`, i2 = JSON.stringify([e2, t2, r2, n2]);
202
+ return this.socket.send(i2);
203
+ }
204
+ stopWs() {
205
+ this.socket.stopWs();
206
+ }
207
+ startWs() {
208
+ this.socket.startWs();
209
+ }
210
+ destroy() {
211
+ this.socket.destroy();
212
+ }
213
+ terminate() {
214
+ this.socket.terminate();
215
+ }
216
+ onWebSocketMessage(e2) {
217
+ if ("Auth token expired" !== e2.data) try {
218
+ const t2 = JSON.parse(e2.data);
219
+ if ("PUBLISH" === t2[1]) {
220
+ const e3 = t2[0], s2 = JSON.stringify([e3, "ACK"]);
221
+ this.socket.send(s2);
222
+ const n2 = t2.slice(2), r2 = [];
223
+ n2.forEach((e4) => {
224
+ "session.expired" === e4.type ? this.handlers.onAuthExpired() : "upstream.restarting" === e4.type ? this.handlers.onUpstreamRestarting() : r2.push(e4);
225
+ }), r2.length > 0 && this.handlers.onPublish(e3, r2);
226
+ } else {
227
+ const e3 = t2[0], s2 = t2[1], n2 = t2[2];
228
+ this.handlers.onResponse(e3, s2, n2);
229
+ }
230
+ } catch (e3) {
231
+ }
232
+ else this.handlers.onAuthExpired();
233
+ }
234
+ }
235
+ class b {
236
+ constructor(e2) {
237
+ this.delayMs = e2, this.timeout = void 0;
238
+ }
239
+ schedule(e2) {
240
+ this.stop(), this.timeout = setTimeout(() => {
241
+ void 0 !== this.timeout && (this.stop(), e2());
242
+ }, this.delayMs);
243
+ }
244
+ stop() {
245
+ void 0 !== this.timeout && (clearTimeout(this.timeout), this.timeout = void 0);
246
+ }
247
+ }
248
+ class w {
249
+ constructor() {
250
+ this.i = -1;
251
+ }
252
+ next() {
253
+ return this.i++, this.i;
254
+ }
255
+ reset() {
256
+ this.i = -1;
257
+ }
258
+ }
259
+ class y {
260
+ constructor(e2, t2) {
261
+ this.handlers = t2, this.seqCounter = new w(), this.responseHandlers = {}, this.heartbeats = new A(this), this.socket = new v(e2, { onUpstreamRestarting: () => {
262
+ this.heartbeats.serverActive(), this.handlers.onUpstreamRestarting();
263
+ }, onOpen: () => {
264
+ this.heartbeats.clientActive(), this.heartbeats.serverActive(), this.handlers.onReady();
265
+ }, onClose: () => {
266
+ this.heartbeats.stop(), Object.values(this.responseHandlers).forEach((e3) => {
267
+ e3.clientErr("WEBSOCKET_DISCONNECTED");
268
+ }), this.responseHandlers = {}, this.seqCounter.reset(), this.handlers.onNotReady();
269
+ }, onResponse: (e3, t3, s2) => {
270
+ this.heartbeats.serverActive(), this.onResponse(e3, t3, s2);
271
+ }, onPublish: (e3, t3) => {
272
+ this.heartbeats.serverActive(), this.handlers.onPublish(e3, t3), this.heartbeats.clientActive();
273
+ }, onAuthExpired: () => {
274
+ this.heartbeats.serverActive(), this.handlers.onAuthExpired();
275
+ } });
276
+ }
277
+ call(e2, t2, s2) {
278
+ const n2 = this.seqCounter.next(), r2 = d();
279
+ this.responseHandlers[n2] = r2;
280
+ const i2 = this.socket.call(n2, e2, t2, s2);
281
+ return i2.ok || r2.resolve(i2), this.heartbeats.clientActive(), r2.promise;
282
+ }
283
+ onResponse(e2, t2, s2) {
284
+ return __async(this, null, function* () {
285
+ const n2 = this.responseHandlers[e2];
286
+ n2 && (200 === t2 ? n2.ok({ status: t2, data: s2 }) : n2.serverErr({ status: t2, errorCode: s2.errorCode, reasons: s2.reasons }), delete this.responseHandlers[e2]);
287
+ });
288
+ }
289
+ stopWs() {
290
+ this.socket.stopWs();
291
+ }
292
+ startWs() {
293
+ this.socket.startWs();
294
+ }
295
+ destroy() {
296
+ this.heartbeats.stop(), Object.values(this.responseHandlers).forEach((e2) => {
297
+ e2.clientErr("WEBSOCKET_DISCONNECTED");
298
+ }), this.responseHandlers = {}, this.socket.destroy();
299
+ }
300
+ terminate() {
301
+ this.socket.terminate();
302
+ }
303
+ }
304
+ class A {
305
+ constructor(e2) {
306
+ this.connection = e2, this.clientInactivityTimer = new b(25e3), this.serverInactivityTimer = new b(1e4), this.serverTimeoutTimer = new b(5e3);
307
+ }
308
+ clientActive() {
309
+ this.clientInactivityTimer.schedule(() => {
310
+ this.sendHeartbeat();
311
+ });
312
+ }
313
+ serverActive() {
314
+ this.serverTimeoutTimer.stop(), this.serverInactivityTimer.schedule(() => {
315
+ this.sendHeartbeat(), this.serverTimeoutTimer.schedule(() => {
316
+ this.connection.terminate();
317
+ });
318
+ });
319
+ }
320
+ stop() {
321
+ this.clientInactivityTimer.stop(), this.serverInactivityTimer.stop(), this.serverTimeoutTimer.stop();
322
+ }
323
+ sendHeartbeat() {
324
+ this.connection.call("GET", ["ping"], {}).catch(() => {
325
+ });
326
+ }
327
+ }
328
+ class C {
329
+ constructor(e2, t2, s2) {
330
+ this.authProvider = t2, this.handlers = s2, this.stateMachine = new u("AuthenticatedConnection", ["WAITING_FOR_WS", "LOGGING_IN", "RENEWING_SESSION", "READY", "TERMINATED"], { logIn: { from: ["WAITING_FOR_WS"], to: "LOGGING_IN", afterTransition: () => __async(this, null, function* () {
331
+ yield this.renewSession();
332
+ }) }, logInFailed: { from: ["LOGGING_IN"], to: "LOGGING_IN", afterTransition: () => __async(this, null, function* () {
333
+ this.authProvider.refreshToken(), yield this.renewSession();
334
+ }) }, scheduledReauth: { from: ["READY"], to: "RENEWING_SESSION", afterTransition: () => __async(this, null, function* () {
335
+ yield this.renewSession();
336
+ }) }, scheduledReauthFailed: { from: ["RENEWING_SESSION"], to: "RENEWING_SESSION", afterTransition: () => __async(this, null, function* () {
337
+ this.authProvider.refreshToken(), yield this.renewSession();
338
+ }) }, authenticated: { from: ["LOGGING_IN", "RENEWING_SESSION"], to: "READY", afterTransition: ({ from: e3 }) => {
339
+ "LOGGING_IN" === e3 && this.handlers.onReady();
340
+ } }, authExpired: { from: ["READY", "RENEWING_SESSION"], to: "LOGGING_IN", afterTransition: () => __async(this, null, function* () {
341
+ this.handlers.onNotReady(), this.authProvider.refreshToken(), yield this.renewSession();
342
+ }) }, wsDisconnected: { from: ["READY", "LOGGING_IN", "RENEWING_SESSION"], to: "WAITING_FOR_WS", afterTransition: ({ from: e3 }) => {
343
+ "READY" !== e3 && "RENEWING_SESSION" !== e3 || this.handlers.onNotReady(), this.authProvider.clearScheduledRefresh();
344
+ } }, destroy: { from: "ANY", to: "TERMINATED", afterTransition: () => {
345
+ this.authProvider.clearScheduledRefresh(), this.connection.destroy();
346
+ } } }), this.connection = new y(e2, { onUpstreamRestarting: () => this.handlers.onUpstreamRestarting(), onReady: () => this.stateMachine.transition("logIn"), onNotReady: () => {
347
+ this.stateMachine.transition("wsDisconnected");
348
+ }, onAuthExpired: () => {
349
+ this.stateMachine.transition("authExpired");
350
+ }, onPublish: (e3, t3) => {
351
+ this.handlers.onPublish(e3, t3);
352
+ } }), t2.onTokenChanged(() => {
353
+ "READY" === this.stateMachine.state && this.stateMachine.transition("scheduledReauth");
354
+ });
355
+ }
356
+ call(e2, t2, s2) {
357
+ const n2 = this.connection.call(e2, t2, s2);
358
+ return n2.then((e3) => {
359
+ e3.ok || "server" !== e3.where || 401 !== e3.value.status || "READY" !== this.stateMachine.state && "RENEWING_SESSION" !== this.stateMachine.state || this.stateMachine.transition("authExpired");
360
+ }), n2;
361
+ }
362
+ stopWs() {
363
+ this.connection.stopWs();
364
+ }
365
+ startWs() {
366
+ this.connection.startWs();
367
+ }
368
+ destroy() {
369
+ this.stateMachine.transition("destroy");
370
+ }
371
+ renewSession() {
372
+ return __async(this, null, function* () {
373
+ const e2 = yield this.authProvider.getToken(), s2 = yield this.connection.call("POST", ["session", "renew"], { token: e2 });
374
+ if (!s2.ok && "client" === s2.where) return;
375
+ const n2 = s2.value;
376
+ if (n2.status, 200 === n2.status) {
377
+ const t2 = n2.data.expiresInSeconds;
378
+ return void (null !== t2 && t2 < 120 ? (console.warn(`[TalkJS] Authenticated with a token that expires in ${t2}s. Treating it as already expired and refreshing. Newly generated tokens should last at least 10 minutes.`), "LOGGING_IN" === this.stateMachine.state ? this.stateMachine.transition("logInFailed") : "RENEWING_SESSION" === this.stateMachine.state && this.stateMachine.transition("scheduledReauthFailed")) : (this.authProvider.scheduleRefresh(t2), this.authProvider.emitTokenAccepted(e2), this.stateMachine.canTransition("authenticated") && this.stateMachine.transition("authenticated")));
379
+ }
380
+ if (401 === n2.status) return void ("LOGGING_IN" === this.stateMachine.state ? this.stateMachine.transition("logInFailed") : "RENEWING_SESSION" === this.stateMachine.state && this.stateMachine.transition("scheduledReauthFailed"));
381
+ if (400 === n2.status) return void this.authProvider.emitTokenRefreshFailed(t("Authentication", n2));
382
+ if (402 === n2.status) return void this.authProvider.emitTokenRefreshFailed(t("Authentication", n2));
383
+ const r2 = 5e3 * Math.random() + 5e3;
384
+ setTimeout(() => {
385
+ this.call("POST", ["session", "renew"], { token: e2 }).catch(() => {
386
+ });
387
+ }, r2);
388
+ });
389
+ }
390
+ }
391
+ class E {
392
+ constructor(e2, t2, s2) {
393
+ this.handlers = s2, this.stateMachine = new u("StopStartConnection", ["STOPPED", "WAITING_FOR_WS", "READY", "TERMINATED"], { unexpectedDisconnect: { from: ["READY"], to: "WAITING_FOR_WS", afterTransition: () => {
394
+ this.inactivityTimer.stop(), this.handlers.onNotReady();
395
+ } }, stop: { from: ["WAITING_FOR_WS", "READY"], to: "STOPPED", afterTransition: () => {
396
+ this.connection.stopWs(), this.inactivityTimer.stop(), this.handlers.onNotReady();
397
+ } }, start: { from: ["STOPPED"], to: "WAITING_FOR_WS", afterTransition: () => {
398
+ this.connection.startWs();
399
+ } }, ready: { from: ["WAITING_FOR_WS"], to: "READY", afterTransition: () => {
400
+ this.pendingCalls = 0, this.activeSubscriptions = 0, this.inactivityTimer.schedule(() => {
401
+ this.stateMachine.transition("stop");
402
+ }), this.handlers.onReady();
403
+ } }, destroy: { from: "ANY", to: "TERMINATED", afterTransition: () => {
404
+ this.inactivityTimer.stop(), this.connection.destroy();
405
+ } } }), this.pendingCalls = 0, this.activeSubscriptions = 0, this.inactivityTimer = new b(3e3), this.connection = new C(e2, t2, { onUpstreamRestarting: () => {
406
+ this.handlers.onUpstreamRestarting();
407
+ }, onReady: () => {
408
+ this.stateMachine.transition("ready");
409
+ }, onNotReady: () => {
410
+ "READY" === this.stateMachine.state && this.stateMachine.transition("unexpectedDisconnect");
411
+ }, onPublish: (e3, t3) => {
412
+ this.handlers.onPublish(e3, t3);
413
+ } });
414
+ }
415
+ get inactive() {
416
+ return 0 === this.pendingCalls && 0 === this.activeSubscriptions;
417
+ }
418
+ ensureStarted() {
419
+ this.stateMachine.canTransition("start") && this.stateMachine.transition("start");
420
+ }
421
+ call(e2, t2, s2) {
422
+ return __async(this, null, function* () {
423
+ this.inactivityTimer.stop(), this.pendingCalls++;
424
+ const n2 = yield this.connection.call(e2, t2, s2);
425
+ return this.pendingCalls--, "SUBSCRIBE" === e2 && n2.ok ? this.activeSubscriptions++ : "UNSUBSCRIBE" === e2 && n2.ok && this.activeSubscriptions--, this.inactive && this.inactivityTimer.schedule(() => {
426
+ this.stateMachine.transition("stop");
427
+ }), n2;
428
+ });
429
+ }
430
+ destroy() {
431
+ this.stateMachine.transition("destroy");
432
+ }
433
+ isConnected() {
434
+ return "READY" === this.stateMachine.state;
435
+ }
436
+ }
437
+ class k {
438
+ constructor(e2, t2, s2) {
439
+ this.handlers = s2, this.stateMachine = new u("QueuedConnection", ["NOT_READY", "PROCESSING_QUEUE", "READY", "TERMINATED"], { processQueue: { from: ["NOT_READY"], to: "PROCESSING_QUEUE", afterTransition: () => {
440
+ this.sendQueuedCalls();
441
+ } }, ready: { from: ["PROCESSING_QUEUE"], to: "READY", afterTransition: () => {
442
+ this.handlers.onReady();
443
+ } }, notReady: { from: ["PROCESSING_QUEUE", "READY"], to: "NOT_READY", afterTransition: () => {
444
+ Object.values(this.subscribeQueue).forEach((e3) => e3.deferred.ok({ status: 200, data: {} })), this.subscribeQueue = {}, this.handlers.onSubscriptionsLost();
445
+ } }, destroy: { from: "ANY", to: "TERMINATED", afterTransition: () => {
446
+ var _a2;
447
+ for (; this.callQueue.length; ) {
448
+ const e3 = (_a2 = this.callQueue.shift()) == null ? void 0 : _a2.deferred;
449
+ e3 == null ? void 0 : e3.clientErr("SESSION_DESTROYED");
450
+ }
451
+ this.connection.destroy();
452
+ } } }), this.subscribeQueue = {}, this.callQueue = [], this.connection = new E(e2, t2, { onUpstreamRestarting: () => {
453
+ this.handlers.onUpstreamRestarting();
454
+ }, onReady: () => {
455
+ this.stateMachine.transition("processQueue");
456
+ }, onNotReady: () => {
457
+ this.stateMachine.transition("notReady");
458
+ }, onPublish: (e3, t3) => {
459
+ this.handlers.onPublish(e3, t3);
460
+ } });
461
+ }
462
+ call(e2, t2, s2) {
463
+ return "READY" === this.stateMachine.state ? this.connection.call(e2, t2, s2) : ("NOT_READY" === this.stateMachine.state && this.connection.ensureStarted(), "SUBSCRIBE" === e2 || "UNSUBSCRIBE" === e2 ? this._subscribe(e2, t2, s2) : this._call(e2, t2, s2));
464
+ }
465
+ _subscribe(e2, t2, s2) {
466
+ const n2 = t2.join("/"), r2 = this.subscribeQueue[n2];
467
+ if (r2 && r2.method === e2) return r2.deferred.promise;
468
+ r2 && r2.method !== e2 && (r2.deferred.ok({ status: 200, data: {} }), delete this.subscribeQueue[n2]);
469
+ const i2 = { deferred: d(), method: e2, path: t2, data: s2 };
470
+ return this.subscribeQueue[n2] = i2, i2.deferred.promise;
471
+ }
472
+ _call(e2, t2, s2) {
473
+ const n2 = { deferred: d(), method: e2, path: t2, data: s2 };
474
+ return this.callQueue.push(n2), n2.deferred.promise;
475
+ }
476
+ dequeue() {
477
+ for (const e2 in this.subscribeQueue) {
478
+ const t2 = this.subscribeQueue[e2];
479
+ return delete this.subscribeQueue[e2], t2;
480
+ }
481
+ return this.callQueue.shift();
482
+ }
483
+ destroy() {
484
+ this.stateMachine.transition("destroy");
485
+ }
486
+ sendQueuedCalls() {
487
+ return __async(this, null, function* () {
488
+ for (; "PROCESSING_QUEUE" === this.stateMachine.state; ) {
489
+ const e2 = this.dequeue();
490
+ if (!e2) return void this.stateMachine.transition("ready");
491
+ this.connection.call(e2.method, e2.path, e2.data).then((t2) => {
492
+ e2.deferred.resolve(t2);
493
+ }), yield new Promise((e3) => setTimeout(e3, 100));
494
+ }
495
+ });
496
+ }
497
+ isConnected() {
498
+ return "READY" === this.stateMachine.state || "PROCESSING_QUEUE" === this.stateMachine.state;
499
+ }
500
+ }
501
+ const x = "undefined" != typeof window ? (_a = window.queueMicrotask) != null ? _a : setTimeout : setTimeout;
502
+ class S {
503
+ constructor(e2, t2) {
504
+ this.clearPendingBatch = e2, this.sendCalls = t2, this.sent = false, x(() => this.send());
505
+ }
506
+ send() {
507
+ this.sent || (this.sent = true, this.clearPendingBatch(), this.sendCalls());
508
+ }
509
+ destroy() {
510
+ this.sent = true;
511
+ }
512
+ }
513
+ class T extends S {
514
+ constructor(e2, t2) {
515
+ super(t2, () => {
516
+ this.sendSubscribe(), this.sendGet();
517
+ }), this.connection = e2, this.getCalls = [], this.subscribeCalls = [];
518
+ }
519
+ canPush(e2, t2) {
520
+ return T.isCorrectBatchTypeFor(e2, t2);
521
+ }
522
+ static isCorrectBatchTypeFor(e2, t2) {
523
+ return s(t2, ["users", "*"]) && ("GET" === e2 || "SUBSCRIBE" === e2);
524
+ }
525
+ push(e2, t2, s2) {
526
+ const n2 = t2[1], r2 = d();
527
+ return "GET" === e2 ? this.getCalls.push({ userId: n2, deferred: r2 }) : this.subscribeCalls.push({ userId: n2, deferred: r2 }), 1e3 !== this.getCalls.length && 1e3 !== this.subscribeCalls.length || this.send(), r2.promise;
528
+ }
529
+ sendGet() {
530
+ return __async(this, null, function* () {
531
+ if (0 === this.getCalls.length) return;
532
+ const e2 = [...new Set(this.getCalls.map((e3) => e3.userId))], t2 = yield this.connection.call("GET", ["users"], { ids: e2, includePrivateFields: false });
533
+ if (t2.ok) for (const e3 of this.getCalls) {
534
+ const s2 = t2.value.data[e3.userId];
535
+ s2 ? e3.deferred.ok({ status: 200, data: s2 }) : e3.deferred.serverErr({ status: 404, errorCode: "NOT_FOUND", reasons: ["No user with that ID exists"] });
536
+ }
537
+ else this.getCalls.forEach((e3) => e3.deferred.resolve(t2));
538
+ });
539
+ }
540
+ sendSubscribe() {
541
+ if (0 === this.subscribeCalls.length) return;
542
+ const e2 = [...new Set(this.subscribeCalls.map((e3) => e3.userId))];
543
+ this.connection.call("SUBSCRIBE", ["users"], { ids: e2 }).then((e3) => this.subscribeCalls.forEach((t2) => t2.deferred.resolve(e3)));
544
+ }
545
+ }
546
+ class D extends S {
547
+ constructor(e2, t2, s2) {
548
+ super(s2, () => this.sendMutate()), this.conversationId = e2, this.connection = t2, this.calls = [];
549
+ }
550
+ canPush(e2, t2) {
551
+ return !!D.isCorrectBatchTypeFor(e2, t2) && t2[1] === this.conversationId;
552
+ }
553
+ static isCorrectBatchTypeFor(e2, t2) {
554
+ return s(t2, ["conversations", "*", "participants", "*"]) && ("PUT" === e2 || "POST" === e2 || "PATCH" === e2);
555
+ }
556
+ push(e2, t2, s2) {
557
+ const n2 = t2[3], r2 = d();
558
+ return this.calls.push({ action: { id: n2, method: e2, params: s2 }, deferred: r2 }), 100 === this.calls.length && this.send(), r2.promise;
559
+ }
560
+ sendMutate() {
561
+ return __async(this, null, function* () {
562
+ const e2 = this.calls.map((e3) => e3.action), t2 = yield this.connection.call("POST", ["conversations", this.conversationId, "participants"], { actions: e2 });
563
+ if (!t2.ok) return void this.calls.forEach((e3) => e3.deferred.resolve(t2));
564
+ const s2 = t2.value.data.responses;
565
+ for (let e3 = 0; e3 < s2.length; e3++) {
566
+ const t3 = this.calls[e3].deferred, n2 = s2[e3];
567
+ 200 === n2.status ? t3.ok(__spreadProps(__spreadValues({}, n2), { data: {} })) : t3.serverErr(n2);
568
+ }
569
+ });
570
+ }
571
+ }
572
+ class I {
573
+ constructor(e2, t2, s2) {
574
+ this.pendingBatch = null, this.connection = new k(e2, t2, s2);
575
+ }
576
+ call(e2, t2, s2) {
577
+ return __async(this, null, function* () {
578
+ var _a2;
579
+ if ((_a2 = this.pendingBatch) == null ? void 0 : _a2.canPush(e2, t2)) return this.pendingBatch.push(e2, t2, s2);
580
+ this.pendingBatch && this.pendingBatch.send();
581
+ const n2 = this.createEmptyBatchFor(e2, t2);
582
+ return n2 ? (this.pendingBatch = n2, n2.push(e2, t2, s2)) : this.connection.call(e2, t2, s2);
583
+ });
584
+ }
585
+ destroy() {
586
+ var _a2;
587
+ this.connection.destroy(), (_a2 = this.pendingBatch) == null ? void 0 : _a2.destroy();
588
+ }
589
+ isConnected() {
590
+ return this.connection.isConnected();
591
+ }
592
+ createEmptyBatchFor(e2, t2) {
593
+ if (T.isCorrectBatchTypeFor(e2, t2)) return new T(this.connection, () => this.pendingBatch = null);
594
+ if (D.isCorrectBatchTypeFor(e2, t2)) {
595
+ const e3 = t2[1];
596
+ return new D(e3, this.connection, () => this.pendingBatch = null);
597
+ }
598
+ return null;
599
+ }
600
+ }
601
+ const F = { 200: "RESOLVE", 400: "RESOLVE", 401: "RETRY", 402: "RESOLVE", 403: "RESOLVE", 404: "RESOLVE", 405: "RESOLVE", 409: "RESOLVE", 429: "DELAY", 500: "DELAY" };
602
+ class B {
603
+ constructor(e2, t2, s2) {
604
+ this.throttler = new M(), this.alive = true, this.connection = new I(e2, t2, s2);
605
+ }
606
+ call(e2, t2, s2) {
607
+ return __async(this, null, function* () {
608
+ let n2 = 0;
609
+ for (; this.alive; ) {
610
+ const r2 = yield this.connection.call(e2, t2, s2);
611
+ if ((r2.ok || "client" !== r2.where || "SOCKET_NOT_READY" !== r2.value) && (r2.ok || "server" !== r2.where || 500 !== r2.value.status) || n2++, 10 === n2) return r2;
612
+ if (r2.ok || "client" !== r2.where) {
613
+ const e3 = r2.value, t3 = e3.status, s3 = F[t3];
614
+ if ("RESOLVE" === s3) return this.throttler.resetDelay(), r2;
615
+ if ("RETRY" === s3) continue;
616
+ if ("DELAY" === s3) {
617
+ yield this.throttler.wait();
618
+ continue;
619
+ }
620
+ return console.warn("[TalkJS] Unexpected status code", t3), e3;
621
+ }
622
+ if ("SESSION_DESTROYED" === r2.value) return l("SESSION_DESTROYED");
623
+ "WEBSOCKET_DISCONNECTED" !== r2.value && ("SOCKET_NOT_READY" !== r2.value ? r2.value : yield this.throttler.wait());
624
+ }
625
+ return l("SESSION_DESTROYED");
626
+ });
627
+ }
628
+ destroy() {
629
+ this.alive = false, this.connection.destroy();
630
+ }
631
+ isConnected() {
632
+ return this.connection.isConnected();
633
+ }
634
+ }
635
+ class M {
636
+ constructor() {
637
+ this.initialDelayMs = 200, this.exponentialFactor = 1.2, this.maxDelayMs = 3e4, this.currentDelayMs = this.initialDelayMs, this.lastCall = 0;
638
+ }
639
+ getCurrentDelay() {
640
+ return this.currentDelayMs;
641
+ }
642
+ wait() {
643
+ const e2 = (/* @__PURE__ */ new Date()).getTime(), t2 = r(this.currentDelayMs, 0.05), s2 = this.lastCall + t2, i2 = Math.max(0, s2 - e2);
644
+ return this.lastCall = e2 + i2, this.currentDelayMs = Math.min(t2 * this.exponentialFactor, this.maxDelayMs), n(i2);
645
+ }
646
+ resetDelay() {
647
+ this.currentDelayMs = this.initialDelayMs;
648
+ }
649
+ }
650
+ function R(e2) {
651
+ return e2.map((e3) => encodeURIComponent(e3)).join();
652
+ }
653
+ class N {
654
+ constructor() {
655
+ this.paths = {};
656
+ }
657
+ add(e2) {
658
+ this.paths[R(e2)] = e2;
659
+ }
660
+ delete(e2) {
661
+ delete this.paths[R(e2)];
662
+ }
663
+ has(e2) {
664
+ return Object.hasOwnProperty.call(this.paths, R(e2));
665
+ }
666
+ clear() {
667
+ this.paths = {};
668
+ }
669
+ forEach(e2) {
670
+ Object.values(this.paths).forEach((t2) => e2(t2));
671
+ }
672
+ }
673
+ class _ {
674
+ constructor(e2, t2, s2) {
675
+ this.handlers = s2, this.targetSubscriptions = new N(), this.connection = new B(e2, t2, { onUpstreamRestarting: () => this.handlers.onUpstreamRestarting(), onSubscriptionsLost: () => {
676
+ this.targetSubscriptions.forEach((e3) => {
677
+ this.resubscribe(e3);
678
+ }), this.handlers.onResubscribeSent();
679
+ }, onReady: () => this.handlers.onReady(), onPublish: (e3, t3) => {
680
+ this.handlers.onPublish(e3, t3);
681
+ } });
682
+ }
683
+ call(e2, t2, s2) {
684
+ return this.connection.call(e2, t2, s2);
685
+ }
686
+ subscribe(e2) {
687
+ return __async(this, null, function* () {
688
+ return this.targetSubscriptions.add(e2), this.connection.call("SUBSCRIBE", e2, {});
689
+ });
690
+ }
691
+ unsubscribe(e2) {
692
+ return __async(this, null, function* () {
693
+ return this.targetSubscriptions.delete(e2), this.connection.call("UNSUBSCRIBE", e2, {});
694
+ });
695
+ }
696
+ resubscribe(e2) {
697
+ return __async(this, null, function* () {
698
+ const t2 = yield this.connection.call("SUBSCRIBE", e2, {});
699
+ t2.ok || this.handlers.onResubscribeError(e2, t2);
700
+ });
701
+ }
702
+ destroy() {
703
+ this.targetSubscriptions.clear(), this.connection.destroy();
704
+ }
705
+ isConnected() {
706
+ return this.connection.isConnected();
707
+ }
708
+ }
709
+ function P(e2, t2) {
710
+ return void 0 === t2 ? e2 : t2;
711
+ }
712
+ function O(e2, t2) {
713
+ if (void 0 === t2) return e2;
714
+ if (null === t2) return {};
715
+ const s2 = __spreadValues({}, e2);
716
+ for (const e3 in t2) {
717
+ const n2 = t2[e3];
718
+ null === n2 ? delete s2[e3] : s2[e3] = n2;
719
+ }
720
+ return s2;
721
+ }
722
+ function U(e2, t2) {
723
+ if (e2 === t2) return true;
724
+ if (!e2 || !t2) return false;
725
+ if ("object" != typeof e2 || "object" != typeof t2) return false;
726
+ if (e2.constructor !== t2.constructor) return false;
727
+ if (Array.isArray(e2) && Array.isArray(t2)) {
728
+ if (e2.length !== t2.length) return false;
729
+ for (let s2 = 0; s2 < e2.length; s2++) if (!U(e2[s2], t2[s2])) return false;
730
+ } else {
731
+ const s2 = Object.keys(e2);
732
+ if (s2.length !== Object.keys(t2).length) return false;
733
+ for (const n2 of s2) {
734
+ if (!Object.hasOwnProperty.call(t2, n2)) return false;
735
+ if (!U(e2[n2], t2[n2])) return false;
736
+ }
737
+ }
738
+ return true;
739
+ }
740
+ class j {
741
+ constructor() {
742
+ this.prev = Promise.resolve();
743
+ }
744
+ runExclusive(e2) {
745
+ return __async(this, null, function* () {
746
+ const t2 = this.prev.then(() => e2());
747
+ return this.prev = t2, t2;
748
+ });
749
+ }
750
+ }
751
+ class $ {
752
+ constructor(e2, t2) {
753
+ this.onTeardown = t2, this.error = null, this.lastLoadedState = void 0, this.lastGoodState = Promise.resolve(void 0), this.initialised = false, this.getDeepMutex = new j(), this.lastDeep = void 0;
754
+ const s2 = { seq: 0, resultPromise: new Promise((e3) => setTimeout(e3)).then(() => __async(this, null, function* () {
755
+ const e3 = yield this.fetchInitial(0);
756
+ return this.initialised = true, e3;
757
+ })) };
758
+ this.lastState = s2, this.states = [s2], this.lastLoadedState = void 0;
759
+ }
760
+ set lastState(e2) {
761
+ const t2 = this.lastGoodState;
762
+ this.lastGoodState = e2.resultPromise.then((e3) => e3.ok ? e3.value : t2), e2.resultPromise.then((e3) => {
763
+ e3.ok || this.setError(e3);
764
+ }), this._lastState = e2;
765
+ }
766
+ get lastState() {
767
+ return this._lastState;
768
+ }
769
+ refetchInitial(e2) {
770
+ return __async(this, null, function* () {
771
+ const t2 = this.lastGoodState, s2 = this.fetchInitial(e2), [n2, r2] = yield Promise.all([t2, s2]);
772
+ if (void 0 === n2) return r2;
773
+ if (!r2.ok) return r2;
774
+ return this.equal(n2, r2.value) ? c(n2) : r2;
775
+ });
776
+ }
777
+ refetch(e2) {
778
+ if (this.error) return;
779
+ const t2 = { seq: e2, resultPromise: this.refetchInitial(e2) };
780
+ this.lastState = t2, this.states.push(t2);
781
+ }
782
+ mutate(e2, t2) {
783
+ if (this.error) return void console.warn("[TalkJS] Attempting to mutate a terminated store");
784
+ if (!this.initialised && e2 > this._lastState.seq) return;
785
+ if (e2 < this.lastState.seq) throw "Seq is in the past";
786
+ const s2 = { seq: e2, resultPromise: this.lastState.resultPromise.then((e3) => e3.ok ? t2(e3) : e3) };
787
+ this.lastState = s2, this.states.push(s2);
788
+ }
789
+ getDeep(e2) {
790
+ return __async(this, null, function* () {
791
+ return this.getDeepMutex.runExclusive(() => __async(this, null, function* () {
792
+ if (this.error) return this.error;
793
+ if (this.lastLoadedState && e2 < this.lastLoadedState.seq) throw `Trying to load state ${e2} when we have previously loaded ${this.lastLoadedState.seq}`;
794
+ for (; this.states.length && this.states[0].seq <= e2; ) this.lastLoadedState = this.states.shift();
795
+ if (void 0 === this.lastLoadedState) throw `[TalkJS] Tried to load state ${e2} which is before the store was created`;
796
+ const t2 = yield this.lastLoadedState.resultPromise;
797
+ if (!t2.ok) return t2;
798
+ const s2 = yield this.loadNested(e2, t2.value);
799
+ return s2.ok && this.lastDeep && s2.value.lastChanged === this.lastDeep.value.lastChanged ? this.lastDeep : (s2.ok ? this.lastDeep = s2 : this.setError(s2), s2);
800
+ }));
801
+ });
802
+ }
803
+ setError(e2) {
804
+ var _a2;
805
+ this.error || (this.error = e2, (_a2 = this.onTeardown) == null ? void 0 : _a2.call(this, e2), this.lastGoodState.then((e3) => {
806
+ void 0 !== e3 && this.teardownNested(e3);
807
+ }));
808
+ }
809
+ }
810
+ class W extends $ {
811
+ constructor(e2, t2, s2) {
812
+ super(e2, s2), this.emitMutex = t2, this.unsubscribeTimer = new q(), this.referencedByOtherStores = 0, this.listeners = [], this.lastEmitSeq = void 0, this.lastEmitResult = void 0, t2.runExclusive(() => __async(this, null, function* () {
813
+ yield this.emit(e2);
814
+ }));
815
+ }
816
+ registerInternalSubscription() {
817
+ this.referencedByOtherStores++;
818
+ let e2 = true;
819
+ return () => {
820
+ e2 && (e2 = false, this.referencedByOtherStores--, this.startUnsubscribeTimerIfOrphan());
821
+ };
822
+ }
823
+ get onlyUsedInternally() {
824
+ return 0 === this.listeners.length;
825
+ }
826
+ listen(e2) {
827
+ return this.unsubscribeTimer.stop(), this.listeners.push(e2), void 0 !== this.lastEmitResult && e2(this.lastEmitResult), () => {
828
+ this.listeners = this.listeners.filter((t2) => t2 !== e2), this.startUnsubscribeTimerIfOrphan();
829
+ };
830
+ }
831
+ startUnsubscribeTimerIfOrphan() {
832
+ 0 === this.referencedByOtherStores && 0 === this.listeners.length && this.unsubscribeTimer.restart(() => {
833
+ this.setError(l("UNSUBSCRIBED"));
834
+ }, this.unsubscribeDebounceMs);
835
+ }
836
+ emit(e2) {
837
+ return __async(this, null, function* () {
838
+ var _a2;
839
+ if (this.lastEmitSeq && this.lastEmitSeq >= e2) return;
840
+ if (false === ((_a2 = this.lastEmitResult) == null ? void 0 : _a2.ok)) return;
841
+ const t2 = this.lastEmitSeq;
842
+ this.lastEmitSeq = e2;
843
+ const s2 = yield this.getDeep(e2);
844
+ this.lastEmitResult, this.lastEmitResult = s2, s2.ok ? (void 0 === t2 || t2 < s2.value.lastChanged) && this.listeners.forEach((e3) => e3(s2)) : this.listeners.forEach((e3) => e3(s2));
845
+ });
846
+ }
847
+ }
848
+ class q {
849
+ constructor() {
850
+ this.timerId = void 0;
851
+ }
852
+ restart(e2, t2) {
853
+ void 0 !== this.timerId && clearTimeout(this.timerId), this.timerId = setTimeout(() => e2(), t2);
854
+ }
855
+ stop() {
856
+ clearTimeout(this.timerId);
857
+ }
858
+ }
859
+ class H extends W {
860
+ constructor(e2, t2, s2, n2, r2) {
861
+ super(e2, n2, r2), this.userId = t2, this.realtimeClient = s2, this.unsubscribeDebounceMs = 1e4;
862
+ }
863
+ fetchInitial(e2) {
864
+ return __async(this, null, function* () {
865
+ const t2 = yield this.realtimeClient.call("GET", ["users", this.userId], { includePrivateFields: false }, { bypassCache: true });
866
+ return t2.ok ? c({ snapshot: this.realtimeClient.createUserSnapshot(t2.value.data), lastChanged: e2 }) : "server" === t2.where && 404 === t2.value.status ? c({ snapshot: null, lastChanged: e2 }) : t2;
867
+ });
868
+ }
869
+ equal(e2, t2) {
870
+ return U(e2.snapshot, t2.snapshot);
871
+ }
872
+ loadNested(e2, t2) {
873
+ return __async(this, null, function* () {
874
+ return c(t2);
875
+ });
876
+ }
877
+ userCreated(e2, t2) {
878
+ this.mutate(e2, () => c({ snapshot: this.realtimeClient.createUserSnapshot(t2.state), lastChanged: e2 }));
879
+ }
880
+ userEdited(e2, t2) {
881
+ this.mutate(e2, (s2) => {
882
+ const n2 = s2.value.snapshot;
883
+ if (null === n2) return console.warn("[TalkJS] Received a 'used edited' event for a user that we thought didn't exist."), s2;
884
+ return c({ snapshot: { id: n2.id, name: P(n2.name, t2.diff.name), custom: O(n2.custom, t2.diff.custom), locale: P(n2.locale, t2.diff.locale), photoUrl: P(n2.photoUrl, t2.diff.photoUrl), role: P(n2.role, t2.diff.role), welcomeMessage: P(n2.welcomeMessage, t2.diff.welcomeMessage) }, lastChanged: e2 });
885
+ });
886
+ }
887
+ getFromCache() {
888
+ return __async(this, null, function* () {
889
+ const e2 = yield this.lastState.resultPromise;
890
+ return e2.ok ? null === e2.value.snapshot ? h({ status: 404, errorCode: "USER_NOT_FOUND", reasons: ["That user does not exist yet"] }) : c({ status: 200, data: { id: e2.value.snapshot.id, name: e2.value.snapshot.name, custom: e2.value.snapshot.custom, locale: e2.value.snapshot.locale, photoUrl: e2.value.snapshot.photoUrl, role: e2.value.snapshot.role, welcomeMessage: e2.value.snapshot.welcomeMessage } }) : l("NOT_IN_CACHE");
891
+ });
892
+ }
893
+ teardownNested(e2) {
894
+ }
895
+ }
896
+ const G = /\uFE0F/g, L = String.fromCharCode(8205);
897
+ function z(e2) {
898
+ if (":arslan:" === e2.text) return ":arslan:";
899
+ const t2 = function({ text: e3, kind: t3 }) {
900
+ var _a2;
901
+ return "unicode" === t3 ? function(e4) {
902
+ const t4 = [];
903
+ let s3 = 0, n2 = 0, r2 = 0;
904
+ for (; r2 < e4.length; ) s3 = e4.charCodeAt(r2++), n2 ? (t4.push((65536 + (n2 - 55296 << 10) + (s3 - 56320)).toString(16)), n2 = 0) : 55296 <= s3 && s3 <= 56319 ? n2 = s3 : t4.push(s3.toString(16));
905
+ return t4.join("-");
906
+ }((s2 = e3).indexOf(L) < 0 ? s2.replace(G, "") : s2) : (_a2 = Y[e3]) != null ? _a2 : function(e4) {
907
+ if (/;-?\)/.test(e4)) return "1f609";
908
+ if (e4 = e4.replace(/;/g, ":"), /:-o/i.test(e4)) return "1f631";
909
+ return e4 = e4.replace(/-/g, "").toLowerCase(), J[e4];
910
+ }(e3);
911
+ var s2;
912
+ }(e2);
913
+ return t2 ? String.fromCodePoint(parseInt(t2, 16)) : e2.text;
914
+ }
915
+ const J = { ":)": "1f642", ":o": "1f62e", ":]": "1f60f", ":d": "1f600", xd: "1f61d", ":p": "1f61c", ":@": "1f621", ":[": "1f621", ":(": "1f626", ":'(": "1f62d", ":’(": "1f62d", ":*": "1f618", ":/": "1f614", ":s": "1f616", ":|": "1f633", ":$": "263a", ":x": "1f637", "<3": "2764", "</3": "1f494" }, Y = { ":thumbsup:": "1f44d", ":thumbsdown:": "1f44e", ":poop:": "1f4a9" };
916
+ var Q, V = {};
917
+ function Z(e2, t2) {
918
+ const s2 = t2.lastIndex;
919
+ let n2;
920
+ const r2 = [];
921
+ for (; null !== (n2 = t2.exec(e2)); ) r2.push(n2);
922
+ return t2.lastIndex = s2, r2;
923
+ }
924
+ function K(e2) {
925
+ const t2 = e2.replace(/%2F/g, "/").replace(/^.*?\/([^/]+?)(?:\?.*)?$/, "$1");
926
+ return decodeURIComponent(t2);
927
+ }
928
+ function X(e2, t2) {
929
+ if (!e2() && !t2) {
930
+ t2 = e2.toString().replace(/^function\s*\(\)\s*\{\s*return\s*(.*);\s*\}\s*$/, "`$1`") + " was not true";
931
+ }
932
+ }
933
+ !function() {
934
+ if (Q) return V;
935
+ function e2(e3) {
936
+ return String.fromCharCode(parseInt(e3.slice(1), 16));
937
+ }
938
+ function t2(e3) {
939
+ return `%${`00${e3.charCodeAt(0).toString(16)}`.slice(-2)}`;
940
+ }
941
+ Q = 1, Object.defineProperty(V, "__esModule", { value: true }), V.encode = function(t3) {
942
+ return btoa(encodeURIComponent(t3).replace(/%[0-9A-F]{2}/g, e2));
943
+ }, V.decode = function(e3) {
944
+ return decodeURIComponent(Array.from(atob(e3), t2).join(""));
945
+ };
946
+ }(), ((e2) => {
947
+ function t2(e3) {
948
+ }
949
+ function s2(e3, t3) {
950
+ (function(e4, t4) {
951
+ switch (t4) {
952
+ case "undefined":
953
+ return void 0 === e4;
954
+ case String:
955
+ return "string" == typeof e4 || e4 instanceof String;
956
+ case Boolean:
957
+ return "boolean" == typeof e4 || e4 instanceof Boolean;
958
+ case Number:
959
+ return "number" == typeof e4 || e4 instanceof Number;
960
+ default:
961
+ return e4 instanceof t4;
962
+ }
963
+ })(e3, t3) || (t3.name, String(e3));
964
+ }
965
+ e2.defined = t2, e2.has = function(e3, t3) {
966
+ e3[t3];
967
+ }, e2.is = s2, e2.equals = function(e3, t3) {
968
+ }, e2.oneOf = function(e3, t3) {
969
+ t3.includes(e3) || JSON.stringify(t3);
970
+ }, e2.isArray = function(e3, t3) {
971
+ s2(e3, Array), e3 && e3.length > 0 && s2(e3[0], t3);
972
+ }, e2.optional = function(e3, t3) {
973
+ void 0 !== e3 && s2(e3, t3);
974
+ }, e2.falsy = function(e3) {
975
+ }, e2.never = function(e3) {
976
+ };
977
+ })(X || (X = {}));
978
+ const ee = X, te = /^\/.*[^\\]\/[im]*$/;
979
+ function se(e2) {
980
+ if (!te.test(e2)) return false;
981
+ return !ne(e2).test("");
982
+ }
983
+ function ne(e2) {
984
+ const t2 = e2.match(/^\/(.*[^\\])\/(.*)$/);
985
+ if (!t2) throw new Error(`Expected ${e2} to be a (non-empty) regex`);
986
+ let s2 = t2[2] || "";
987
+ return s2 = s2.replace(/[^im]/g, "") + "g", new RegExp(t2[1], s2);
988
+ }
989
+ class re {
990
+ constructor({ mode: e2, allowedHostnames: t2, allowedPhoneNrs: s2, allowedMatches: n2, forbiddenMatches: r2, suppressLinks: i2, suppressEmailAddresses: a2, suppressPhoneNumbers: o2, replacement: u2 }) {
991
+ ee.oneOf(e2, ["all", "otherOnly", "off"]), this.mode = e2, this.suppressLinks = false !== i2, this.suppressEmailAddresses = false !== a2, this.suppressPhoneNumbers = false !== o2, this.allowedHostnames = t2 || [], this.allowedPhoneNrs = (s2 || []).filter((e3) => e3).map((e3) => e3.replace(/[^0-9]/g, "")), this.allowedMatches = (n2 || []).filter(se).map((e3) => ne(e3)), this.forbiddenMatches = (r2 || []).filter(se).map((e3) => ne(e3)), ee(() => this.allowedMatches.every((e3) => e3.flags.includes("g")), "All regexes in `suppressContactInfo.allowedMatches` must be global. Check `allowedMatches`!"), ee(() => this.forbiddenMatches.every((e3) => e3.flags.includes("g")), "All regexes in `suppressContactInfo.forbiddenMatches` must be global. Check `forbiddenMatches`!"), u2 = u2 == null ? void 0 : u2.trim(), this.replacement = u2 && u2.length > 0 ? u2 : void 0;
992
+ }
993
+ shouldSuppress({ isContentBySender: e2 }) {
994
+ return "all" === this.mode || "otherOnly" === this.mode && !e2;
995
+ }
996
+ }
997
+ function ie(e2, t2) {
998
+ const s2 = e2.map((e3) => function(e4, t3) {
999
+ if ("text" === e4.type) return function(e5, t4) {
1000
+ const s3 = function(e6) {
1001
+ var _a2, _b, _c, _d, _e2, _f, _g, _h, _i, _j, _k, _l;
1002
+ let t5 = "";
1003
+ return e6.t && (t5 = `(${e6.t("CONTACT_INFORMATION_HIDDEN")})`), { formattedLinks: (_a2 = e6.formattedLinks) != null ? _a2 : "plaintext", markup: (_b = e6.markup) != null ? _b : false, useFallbackMentions: (_c = e6.useFallbackMentions) != null ? _c : false, sameTabLinkRules: (_d = e6.sameTabLinkRules) != null ? _d : [], emojis: (_e2 = e6.emojis) != null ? _e2 : false, highlight: (_f = e6.highlight) != null ? _f : [], contactInfo: (_g = e6.contactInfo) != null ? _g : false, suppression: (_h = e6.suppression) != null ? _h : new re({ mode: "off" }), contactInfoHiddenText: (_k = (_j = e6.contactInfoHiddenText) != null ? _j : (_i = e6.suppression) == null ? void 0 : _i.replacement) != null ? _k : t5, customEmojiUrls: (_l = e6.customEmojiUrls) != null ? _l : {} };
1004
+ }(t4);
1005
+ return ae(e5, s3);
1006
+ }(e4.children, t3);
1007
+ if ("file" === e4.type && "video" === e4.subtype) return `🎥 ${K(e4.url)}`;
1008
+ if ("file" === e4.type && "image" === e4.subtype) return `📷 ${K(e4.url)}`;
1009
+ if ("file" === e4.type && "audio" === e4.subtype) return `🎧 ${K(e4.url)}`;
1010
+ if ("file" === e4.type && "voice" === e4.subtype) {
1011
+ const t4 = e4.duration;
1012
+ if (void 0 === t4) return "🎙️";
1013
+ return `🎙️ (${Math.floor(t4 / 60)}:${Math.floor(t4 % 60).toString().padStart(2, "0")})`;
1014
+ }
1015
+ if ("file" === e4.type) return e4.subtype, `📎 ${K(e4.url)}`;
1016
+ if ("location" === e4.type) return "📍";
1017
+ return "";
1018
+ }(e3, t2));
1019
+ return s2.join("\n\n");
1020
+ }
1021
+ function ae(e2, t2) {
1022
+ return e2.flatMap((e3) => {
1023
+ if ("string" == typeof e3) return e3;
1024
+ switch (e3.type) {
1025
+ case "blockquote":
1026
+ case "bold":
1027
+ case "italic":
1028
+ case "strikethrough":
1029
+ case "link":
1030
+ case "actionlink":
1031
+ case "actionLink":
1032
+ case "actionbutton":
1033
+ case "actionButton":
1034
+ return ae(e3.children, t2);
1035
+ case "bulletlist":
1036
+ case "bulletList":
1037
+ return "\n" + ae(e3.children, t2);
1038
+ case "bulletpoint":
1039
+ case "bulletPoint":
1040
+ return "- " + ae(e3.children, t2) + "\n";
1041
+ case "autolink":
1042
+ case "autoLink":
1043
+ case "codeblock":
1044
+ case "codeBlock":
1045
+ case "codespan":
1046
+ case "codeSpan":
1047
+ case "customemoji":
1048
+ case "customEmoji":
1049
+ return e3.text;
1050
+ case "suppressed":
1051
+ return t2.contactInfoHiddenText;
1052
+ case "mention":
1053
+ return `@${e3.text}`;
1054
+ case "emoji":
1055
+ return "images" === t2.emojis ? "" : "unicode" === t2.emojis ? z(e3) : e3.text;
1056
+ }
1057
+ }).join("");
1058
+ }
1059
+ class oe extends $ {
1060
+ constructor(e2, t2, s2, n2) {
1061
+ super(e2), this.conversationId = t2, this.message = s2, this.realtimeClient = n2;
1062
+ }
1063
+ get messageId() {
1064
+ return "string" == typeof this.message ? this.message : this.message.id;
1065
+ }
1066
+ fetchInitial(e2) {
1067
+ return __async(this, null, function* () {
1068
+ let t2;
1069
+ if ("object" == typeof this.message) t2 = this.message;
1070
+ else {
1071
+ const e3 = yield this.realtimeClient.call("GET", ["me", "conversations", this.conversationId, "messages", this.message], {}, { bypassCache: true });
1072
+ if (!e3.ok) return e3;
1073
+ t2 = e3.value.data;
1074
+ }
1075
+ return c({ lastChanged: e2, sender: null === t2.senderId ? null : this.realtimeClient.internalSubscribe(["users", t2.senderId]), data: { id: t2.id, type: t2.type, custom: t2.custom, createdAt: t2.createdAt, editedAt: t2.editedAt, referencedMessageId: t2.referencedMessageId, origin: t2.origin, plaintext: ie(t2.content, {}), content: t2.content } });
1076
+ });
1077
+ }
1078
+ refetch(e2) {
1079
+ throw "Do not call refetch on message data stores, it can return outdated data. Destroy and remake them instead";
1080
+ }
1081
+ equal(e2, t2) {
1082
+ return U(e2.data, t2.data);
1083
+ }
1084
+ teardownNested(e2) {
1085
+ var _a2;
1086
+ (_a2 = e2.sender) == null ? void 0 : _a2.unsubscribe();
1087
+ }
1088
+ loadNested(e2, t2) {
1089
+ return __async(this, null, function* () {
1090
+ var _a2, _b, _c, _d;
1091
+ const s2 = yield (_b = (_a2 = t2.sender) == null ? void 0 : _a2.store) == null ? void 0 : _b.getDeep(e2);
1092
+ if (false === (s2 == null ? void 0 : s2.ok)) return s2;
1093
+ if (null === t2.data) return c({ lastChanged: t2.lastChanged, snapshot: null });
1094
+ const n2 = s2 == null ? void 0 : s2.value;
1095
+ return c({ lastChanged: Math.max(t2.lastChanged, (_c = n2 == null ? void 0 : n2.lastChanged) != null ? _c : 0), snapshot: { sender: (_d = n2 == null ? void 0 : n2.snapshot) != null ? _d : null, id: t2.data.id, type: t2.data.type, custom: t2.data.custom, createdAt: t2.data.createdAt, editedAt: t2.data.editedAt, origin: t2.data.origin, plaintext: ie(t2.data.content, {}), content: t2.data.content, referencedMessageId: t2.data.referencedMessageId } });
1096
+ });
1097
+ }
1098
+ messageEdited(e2, t2) {
1099
+ this.mutate(e2, (s2) => {
1100
+ if (null === s2.value.data) return s2;
1101
+ return c({ lastChanged: e2, sender: s2.value.sender, data: { id: s2.value.data.id, type: s2.value.data.type, createdAt: s2.value.data.createdAt, origin: s2.value.data.origin, referencedMessageId: s2.value.data.referencedMessageId, editedAt: P(s2.value.data.editedAt, t2.diff.editedAt), custom: O(s2.value.data.custom, t2.diff.custom), content: P(s2.value.data.content, t2.diff.content) } });
1102
+ });
1103
+ }
1104
+ messageDeleted(e2, t2) {
1105
+ this.mutate(e2, (s2) => null === s2.value.data ? s2 : this.messageId === t2.messageId ? c({ lastChanged: e2, sender: null, data: null }) : s2.value.data.referencedMessageId === t2.messageId ? c({ lastChanged: e2, sender: s2.value.sender, data: { id: s2.value.data.id, type: s2.value.data.type, createdAt: s2.value.data.createdAt, origin: s2.value.data.origin, referencedMessageId: null, editedAt: s2.value.data.editedAt, custom: s2.value.data.custom, content: s2.value.data.content } }) : s2);
1106
+ }
1107
+ getFromCache() {
1108
+ return __async(this, null, function* () {
1109
+ var _b;
1110
+ const e2 = yield this.lastState.resultPromise;
1111
+ if (!e2.ok) return l("NOT_IN_CACHE");
1112
+ if (null === e2.value.data) {
1113
+ return h({ status: 404, errorCode: "MESSAGE_NOT_FOUND", reasons: ["No message with that ID exists"] });
1114
+ }
1115
+ const _a2 = e2.value, { sender: t2 } = _a2, s2 = __objRest(_a2, ["sender"]);
1116
+ return c({ status: 200, data: __spreadProps(__spreadValues({}, s2.data), { senderId: (_b = t2 == null ? void 0 : t2.store.userId) != null ? _b : null }) });
1117
+ });
1118
+ }
1119
+ }
1120
+ class ue extends $ {
1121
+ constructor(e2, t2, s2, n2) {
1122
+ super(e2), this.createdAt = t2, this.dataStore = s2, this.referencedDataStore = n2;
1123
+ }
1124
+ get messageId() {
1125
+ return this.dataStore.messageId;
1126
+ }
1127
+ fetchInitial(e2) {
1128
+ return __async(this, null, function* () {
1129
+ return c({ lastChanged: e2, dataStore: this.dataStore, referencedDataStore: this.referencedDataStore });
1130
+ });
1131
+ }
1132
+ refetch(e2) {
1133
+ throw "Do not call refetch on message stores, it can return outdated data. Destroy and remake them instead";
1134
+ }
1135
+ equal(e2, t2) {
1136
+ return true;
1137
+ }
1138
+ teardownNested(e2) {
1139
+ }
1140
+ loadNested(e2, t2) {
1141
+ return __async(this, null, function* () {
1142
+ var _a2, _b, _c, _d;
1143
+ const s2 = yield t2.dataStore.getDeep(e2);
1144
+ if (!s2.ok) return s2;
1145
+ const n2 = s2.value;
1146
+ if (null === n2.snapshot) return c({ lastChanged: s2.value.lastChanged, snapshot: null });
1147
+ const r2 = yield (_a2 = t2.referencedDataStore) == null ? void 0 : _a2.getDeep(e2);
1148
+ if (r2 && !r2.ok) return r2;
1149
+ const i2 = (_b = r2 == null ? void 0 : r2.value) != null ? _b : null, a2 = (_c = i2 == null ? void 0 : i2.snapshot) != null ? _c : null;
1150
+ return c({ lastChanged: Math.max(n2.lastChanged, (_d = i2 == null ? void 0 : i2.lastChanged) != null ? _d : 0), snapshot: { id: n2.snapshot.id, type: n2.snapshot.type, sender: n2.snapshot.sender, custom: n2.snapshot.custom, createdAt: n2.snapshot.createdAt, editedAt: n2.snapshot.editedAt, referencedMessage: a2, origin: n2.snapshot.origin, plaintext: n2.snapshot.plaintext, content: n2.snapshot.content } });
1151
+ });
1152
+ }
1153
+ }
1154
+ class ce extends W {
1155
+ constructor(e2, t2, s2, n2, r2) {
1156
+ super(e2, t2, r2), this.conversationId = s2, this.realtimeClient = n2, this.unsubscribeDebounceMs = 1e3, this.pendingLoadMore = void 0;
1157
+ }
1158
+ listen(e2) {
1159
+ return this.onlyUsedInternally && this.lastState.resultPromise.then((e3) => {
1160
+ if (e3.ok && null !== e3.value.inWindow) {
1161
+ const t2 = 30 - e3.value.inWindow.length;
1162
+ t2 > 0 && this._loadMoreMessages(t2);
1163
+ }
1164
+ }), super.listen(e2);
1165
+ }
1166
+ fetchInitial(e2) {
1167
+ return __async(this, null, function* () {
1168
+ const t2 = this.onlyUsedInternally ? 1 : 30, s2 = yield le({ realtimeClient: this.realtimeClient, conversationId: this.conversationId, count: t2 });
1169
+ return s2.ok ? null === s2.value.messages ? c({ lastChanged: e2, stores: null, inWindow: null, windowEnd: null }) : he({ seq: e2, messages: s2.value.messages, cursor: s2.value.nextCursor, conversationId: this.conversationId, realtimeClient: this.realtimeClient }) : s2;
1170
+ });
1171
+ }
1172
+ teardownNested(e2) {
1173
+ de(e2);
1174
+ }
1175
+ equal(e2, t2) {
1176
+ return null === e2.stores && null === t2.stores || null !== e2.stores && null !== t2.stores && (!!U(Object.keys(e2.stores), Object.keys(t2.stores)) && (!!U(e2.inWindow.map((e3) => e3.messageId), t2.inWindow.map((e3) => e3.messageId)) && U(e2.windowEnd, t2.windowEnd)));
1177
+ }
1178
+ loadNested(e2, t2) {
1179
+ return __async(this, null, function* () {
1180
+ if (null === t2.stores) return c({ snapshot: null, loadedAll: true, lastChanged: t2.lastChanged });
1181
+ const s2 = yield Promise.all(t2.inWindow.map((t3) => t3.getDeep(e2))), n2 = s2.find((e3) => !e3.ok);
1182
+ if (n2) return n2;
1183
+ const r2 = s2, i2 = r2.filter((e3) => null !== e3.value.snapshot).map((e3) => e3.value.snapshot), a2 = Math.max(t2.lastChanged, ...r2.map((e3) => e3.value.lastChanged));
1184
+ return c({ snapshot: i2, loadedAll: null === t2.windowEnd, lastChanged: a2 });
1185
+ });
1186
+ }
1187
+ loadMore(e2) {
1188
+ return __async(this, null, function* () {
1189
+ if (this.pendingLoadMore) return this.pendingLoadMore;
1190
+ const t2 = o();
1191
+ this.pendingLoadMore = t2.promise, yield this._loadMoreMessages(e2), t2.resolve(), this.pendingLoadMore = void 0;
1192
+ });
1193
+ }
1194
+ _loadMoreMessages(e2 = 30) {
1195
+ return __async(this, null, function* () {
1196
+ const t2 = yield this.lastState.resultPromise;
1197
+ if (!t2.ok) return;
1198
+ if (null === t2.value.windowEnd) return;
1199
+ const s2 = t2.value.windowEnd.cursor, n2 = yield le({ count: e2, cursor: s2, conversationId: this.conversationId, realtimeClient: this.realtimeClient }), r2 = this.lastState.seq + 1e-6;
1200
+ this.mutate(r2, (e3) => null === e3.value.windowEnd || s2 !== e3.value.windowEnd.cursor ? e3 : n2.ok ? null === n2.value.messages ? (console.warn("[TalkJS] When loading more messages, the conversation no longer existed. We should have been told about this."), e3) : he({ seq: r2, prevState: e3.value, messages: n2.value.messages, cursor: n2.value.nextCursor, conversationId: this.conversationId, realtimeClient: this.realtimeClient }) : n2), yield this.emitMutex.runExclusive(() => this.emit(r2));
1201
+ });
1202
+ }
1203
+ messageCreated(e2, t2) {
1204
+ this.mutate(e2, (s2) => {
1205
+ if (null === s2.value.stores) return console.warn("[TalkJS] Received a 'message.created' event for a nonexistent conversation."), s2;
1206
+ if (s2.value.windowEnd && t2.state.createdAt < s2.value.windowEnd.oldestMessageTs) return s2;
1207
+ if (Object.hasOwnProperty.call(s2.value.stores, t2.state.id)) return s2;
1208
+ const n2 = __spreadValues({}, s2.value.stores), r2 = new oe(e2, this.conversationId, t2.state, this.realtimeClient);
1209
+ n2[t2.state.id] = r2;
1210
+ const i2 = t2.state.referencedMessageId;
1211
+ let a2;
1212
+ null === i2 ? a2 = null : i2 in n2 ? a2 = n2[i2] : (a2 = new oe(e2, this.conversationId, i2, this.realtimeClient), n2[i2] = a2);
1213
+ const o2 = new ue(e2, t2.state.createdAt, r2, a2), u2 = [...s2.value.inWindow, o2];
1214
+ u2.sort((e3, t3) => t3.createdAt - e3.createdAt);
1215
+ return c({ lastChanged: e2, stores: n2, inWindow: u2, windowEnd: s2.value.windowEnd });
1216
+ });
1217
+ }
1218
+ messageEdited(e2, t2) {
1219
+ this.mutate(e2, (s2) => {
1220
+ var _a2;
1221
+ return null === s2.value.stores ? (console.warn("[TalkJS] Received a 'message.edited' event for a nonexistent conversation."), s2) : ((_a2 = s2.value.stores[t2.messageId]) == null ? void 0 : _a2.messageEdited(e2, t2), s2);
1222
+ });
1223
+ }
1224
+ messageDeleted(e2, t2) {
1225
+ this.mutate(e2, (s2) => {
1226
+ if (null === s2.value.stores) return console.warn("[TalkJS] Received a 'message.deleted' event for a conversation that we thought didn't exist."), s2;
1227
+ if (Object.values(s2.value.stores).forEach((s3) => s3.messageDeleted(e2, t2)), void 0 === s2.value.stores[t2.messageId]) return s2;
1228
+ const n2 = __spreadValues({}, s2.value.stores);
1229
+ delete n2[t2.messageId];
1230
+ const r2 = s2.value.inWindow.filter((e3) => e3.messageId !== t2.messageId);
1231
+ if (t2.newLastMessage && 0 === r2.length) {
1232
+ const s3 = new oe(e2, this.conversationId, t2.newLastMessage, this.realtimeClient);
1233
+ n2[s3.messageId] = s3;
1234
+ const i2 = t2.newLastMessage.referencedMessageId;
1235
+ let a2;
1236
+ null === i2 ? a2 = null : i2 in n2 ? a2 = n2[i2] : (a2 = new oe(e2, this.conversationId, i2, this.realtimeClient), n2[i2] = a2);
1237
+ const o2 = new ue(e2, t2.newLastMessage.createdAt, s3, a2);
1238
+ r2.push(o2);
1239
+ }
1240
+ return c({ lastChanged: e2, stores: n2, inWindow: r2, windowEnd: s2.value.windowEnd });
1241
+ });
1242
+ }
1243
+ conversationCleared(e2, t2) {
1244
+ this.mutate(e2, (t3) => (de(t3.value), c({ lastChanged: e2, stores: {}, inWindow: [], windowEnd: null })));
1245
+ }
1246
+ sideCreated(e2, t2) {
1247
+ const s2 = this.fetchInitial(e2);
1248
+ this.mutate(e2, (e3) => null !== e3.value.stores ? (s2.then((e4) => {
1249
+ e4.ok && de(e4.value);
1250
+ }), e3) : s2);
1251
+ }
1252
+ sideDeleted(e2, t2) {
1253
+ this.mutate(e2, (t3) => (de(t3.value), c({ lastChanged: e2, stores: null, inWindow: null, windowEnd: null })));
1254
+ }
1255
+ getMessageFromCache(e2) {
1256
+ return __async(this, null, function* () {
1257
+ const t2 = yield this.lastState.resultPromise;
1258
+ if (!t2.ok) return l("NOT_IN_CACHE");
1259
+ if (null === t2.value.stores) return l("NOT_IN_CACHE");
1260
+ const s2 = t2.value.stores[e2];
1261
+ return void 0 === s2 ? l("NOT_IN_CACHE") : s2.getFromCache();
1262
+ });
1263
+ }
1264
+ }
1265
+ function le(_0) {
1266
+ return __async(this, arguments, function* ({ cursor: e2, realtimeClient: t2, conversationId: s2, count: n2 }) {
1267
+ const r2 = { limit: n2, cursor: e2 }, i2 = yield t2.call("GET", ["me", "conversations", s2, "messages"], r2, { bypassCache: true });
1268
+ if (i2.ok) {
1269
+ const { data: e3, cursor: t3 } = i2.value.data;
1270
+ return c({ messages: e3, nextCursor: t3 });
1271
+ }
1272
+ return (i2.ok || "server" !== i2.where || 404 !== i2.value.status) && (i2.ok || "server" !== i2.where || 403 !== i2.value.status || "NOT_A_PARTICIPANT" !== i2.value.errorCode) ? i2 : c({ messages: null, nextCursor: null });
1273
+ });
1274
+ }
1275
+ function he({ seq: e2, prevState: t2, messages: s2, cursor: n2, conversationId: r2, realtimeClient: i2 }) {
1276
+ const a2 = t2 ? __spreadValues({}, t2.stores) : {};
1277
+ for (const t3 of s2) if (void 0 === a2[t3.id]) {
1278
+ const s3 = new oe(e2, r2, t3, i2);
1279
+ a2[s3.messageId] = s3;
1280
+ }
1281
+ for (const t3 of s2) {
1282
+ const s3 = t3.referencedMessageId;
1283
+ if (s3 && void 0 === a2[s3]) {
1284
+ const t4 = new oe(e2, r2, s3, i2);
1285
+ a2[t4.messageId] = t4;
1286
+ }
1287
+ }
1288
+ const o2 = t2 ? [...t2.inWindow] : [];
1289
+ for (const t3 of s2) o2.push(new ue(e2, t3.createdAt, a2[t3.id], t3.referencedMessageId ? a2[t3.referencedMessageId] : null));
1290
+ if (o2.sort((e3, t3) => t3.createdAt - e3.createdAt), null === n2) return c({ lastChanged: e2, stores: a2, inWindow: o2, windowEnd: null });
1291
+ return c({ lastChanged: e2, stores: a2, inWindow: o2, windowEnd: { cursor: n2, oldestMessageTs: s2[s2.length - 1].createdAt } });
1292
+ }
1293
+ function de(e2) {
1294
+ if (e2.stores) {
1295
+ const t2 = l("TERMINATED");
1296
+ Object.values(e2.stores).forEach((e3) => e3.setError(t2)), e2.inWindow.forEach((e3) => e3.setError(t2));
1297
+ }
1298
+ }
1299
+ class pe extends W {
1300
+ constructor(e2, t2, s2, n2, r2) {
1301
+ super(e2, t2, r2), this.conversationId = s2, this.realtimeClient = n2, this.unsubscribeDebounceMs = 5e3;
1302
+ }
1303
+ fetchInitial(e2) {
1304
+ return __async(this, null, function* () {
1305
+ const t2 = this.realtimeClient.internalSubscribe(["me", "conversations", this.conversationId, "messages"]), s2 = yield this.realtimeClient.call("GET", ["me", "conversations", this.conversationId], {}, { bypassCache: true });
1306
+ let n2;
1307
+ if (s2.ok) n2 = s2.value.data;
1308
+ else if ("server" === s2.where && 404 === s2.value.status) n2 = null;
1309
+ else {
1310
+ if ("server" !== s2.where || 403 !== s2.value.status || "NOT_A_PARTICIPANT" !== s2.value.errorCode) return t2.unsubscribe(), s2;
1311
+ n2 = null;
1312
+ }
1313
+ return c({ lastChanged: e2, snapshot: n2, messageWindowStore: t2 });
1314
+ });
1315
+ }
1316
+ teardownNested(e2) {
1317
+ var _a2;
1318
+ (_a2 = e2.messageWindowStore) == null ? void 0 : _a2.unsubscribe();
1319
+ }
1320
+ equal(e2, t2) {
1321
+ return U(e2.snapshot, t2.snapshot);
1322
+ }
1323
+ loadNested(e2, t2) {
1324
+ return __async(this, null, function* () {
1325
+ var _a2;
1326
+ if (!t2.snapshot) return c({ lastChanged: t2.lastChanged, snapshot: null, loadedAll: true });
1327
+ const s2 = yield t2.messageWindowStore.store.getDeep(e2);
1328
+ if (!s2.ok) return s2;
1329
+ const n2 = s2.value.snapshot, r2 = (_a2 = n2 == null ? void 0 : n2[0]) != null ? _a2 : null;
1330
+ return c({ lastChanged: Math.max(t2.lastChanged, s2.value.lastChanged), snapshot: __spreadProps(__spreadValues({}, t2.snapshot), { lastMessage: r2 }) });
1331
+ });
1332
+ }
1333
+ participantEdited(e2, t2) {
1334
+ this.mutate(e2, (s2) => null === s2.value.snapshot ? (console.warn("[TalkJS] Received a 'participant.edited' event for a conversation that we thought didn't exist."), s2) : c({ lastChanged: e2, snapshot: fe(s2.value.snapshot, t2.diff), messageWindowStore: s2.value.messageWindowStore }));
1335
+ }
1336
+ conversationEdited(e2, t2) {
1337
+ this.mutate(e2, (s2) => null === s2.value.snapshot ? (console.warn("[TalkJS] Received a 'conversation.edited' event for a conversation that we thought didn't exist."), s2) : c({ lastChanged: e2, snapshot: fe(s2.value.snapshot, t2.diff), messageWindowStore: s2.value.messageWindowStore }));
1338
+ }
1339
+ sideEdited(e2, t2) {
1340
+ this.mutate(e2, (s2) => null === s2.value.snapshot ? (console.warn("[TalkJS] Received a 'side.edited' event for a conversation that we thought didn't exist."), s2) : c({ lastChanged: e2, snapshot: fe(s2.value.snapshot, t2.diff), messageWindowStore: s2.value.messageWindowStore }));
1341
+ }
1342
+ sideCreated(e2, t2) {
1343
+ this.mutate(e2, (s2) => s2.value.snapshot ? s2 : c({ lastChanged: e2, snapshot: t2.state, messageWindowStore: s2.value.messageWindowStore }));
1344
+ }
1345
+ sideDeleted(e2, t2) {
1346
+ this.mutate(e2, (t3) => null === t3.value.snapshot ? t3 : c({ lastChanged: e2, snapshot: null, messageWindowStore: t3.value.messageWindowStore }));
1347
+ }
1348
+ getFromCache() {
1349
+ return __async(this, null, function* () {
1350
+ const e2 = yield this.lastState.resultPromise;
1351
+ return e2.ok && e2.value.snapshot ? c({ status: 200, data: e2.value.snapshot }) : l("NOT_IN_CACHE");
1352
+ });
1353
+ }
1354
+ }
1355
+ function fe(e2, t2) {
1356
+ const s2 = t2;
1357
+ return { id: e2.id, createdAt: e2.createdAt, subject: P(e2.subject, s2.subject), photoUrl: P(e2.photoUrl, s2.photoUrl), welcomeMessages: P(e2.welcomeMessages, s2.welcomeMessages), custom: O(e2.custom, s2.custom), lastMessageAt: P(e2.lastMessageAt, s2.lastMessageAt), unreadMessageCount: P(e2.unreadMessageCount, s2.unreadMessageCount), isUnread: P(e2.isUnread, s2.isUnread), access: P(e2.access, s2.access), notify: P(e2.notify, s2.notify), readUntil: P(e2.readUntil, s2.readUntil), joinedAt: e2.joinedAt };
1358
+ }
1359
+ class me {
1360
+ constructor(e2, t2, s2) {
1361
+ this.realtimeClient = s2, this.userStores = {}, this.messageWindowStores = {}, this.conversationStores = {}, this.emitMutex = new j(), this.seqOffset = 0, this.seqInThisConnection = 0, this.refetchOnNextNetworkLoss = true, this.connection = new _(e2, t2, { onUpstreamRestarting: () => {
1362
+ this.refetchOnNextNetworkLoss = false;
1363
+ }, onReady: () => {
1364
+ this.refetchOnNextNetworkLoss = true;
1365
+ }, onResubscribeSent: () => {
1366
+ if (this.seqOffset += this.seq, this.seqInThisConnection = 0, this.refetchOnNextNetworkLoss) {
1367
+ this.seqOffset++;
1368
+ const e3 = this.seq;
1369
+ this.refetchAll(e3), this.emitAll(e3);
1370
+ }
1371
+ }, onResubscribeError: (e3, t3) => {
1372
+ var _a2;
1373
+ (_a2 = this.getStoreIfExists(e3)) == null ? void 0 : _a2.setError(t3);
1374
+ }, onPublish: (e3, t3) => {
1375
+ this.seqInThisConnection = e3;
1376
+ const s3 = this.seq;
1377
+ for (const e4 of t3) this.handlePublish(s3, e4);
1378
+ this.emitAll(s3);
1379
+ } });
1380
+ }
1381
+ get seq() {
1382
+ return this.seqOffset + this.seqInThisConnection;
1383
+ }
1384
+ refetchAll(e2) {
1385
+ for (const t2 of Object.values(this.userStores)) t2.refetch(e2);
1386
+ for (const t2 of Object.values(this.messageWindowStores)) t2.refetch(e2);
1387
+ for (const t2 of Object.values(this.conversationStores)) t2.refetch(e2);
1388
+ }
1389
+ emitAll(e2) {
1390
+ return this.emitMutex.runExclusive(() => __async(this, null, function* () {
1391
+ yield Promise.all([...Object.values(this.userStores).map((t2) => t2.emit(e2)), ...Object.values(this.messageWindowStores).map((t2) => t2.emit(e2)), ...Object.values(this.conversationStores).map((t2) => t2.emit(e2))]);
1392
+ }));
1393
+ }
1394
+ handlePublish(e2, t2) {
1395
+ switch (t2.type) {
1396
+ case "user.created":
1397
+ return this.handleUserCreated(e2, t2);
1398
+ case "user.edited":
1399
+ return this.handleUserEdited(e2, t2);
1400
+ case "side.created":
1401
+ return this.handleSideCreated(e2, t2);
1402
+ case "side.edited":
1403
+ return this.handleSideEdited(e2, t2);
1404
+ case "side.deleted":
1405
+ return this.handleSideDeleted(e2, t2);
1406
+ case "participant.edited":
1407
+ return this.handleParticipantEdited(e2, t2);
1408
+ case "conversation.edited":
1409
+ return this.handleConversationEdited(e2, t2);
1410
+ case "message.created":
1411
+ return this.handleMessageCreated(e2, t2);
1412
+ case "message.edited":
1413
+ return this.handleMessageEdited(e2, t2);
1414
+ case "message.deleted":
1415
+ return this.handleMessageDeleted(e2, t2);
1416
+ case "messages.cleared":
1417
+ case "conversation.cleared":
1418
+ return this.handleConversationCleared(e2, t2);
1419
+ }
1420
+ }
1421
+ handleUserCreated(e2, t2) {
1422
+ const s2 = this.userStores[t2.userId];
1423
+ s2 && s2.userCreated(e2, t2);
1424
+ }
1425
+ handleUserEdited(e2, t2) {
1426
+ const s2 = this.userStores[t2.userId];
1427
+ s2 && s2.userEdited(e2, t2);
1428
+ }
1429
+ handleSideCreated(e2, t2) {
1430
+ const s2 = this.messageWindowStores[t2.conversationId];
1431
+ s2 && s2.sideCreated(e2, t2);
1432
+ const n2 = this.conversationStores[t2.conversationId];
1433
+ n2 && n2.sideCreated(e2, t2);
1434
+ }
1435
+ handleSideEdited(e2, t2) {
1436
+ const s2 = this.conversationStores[t2.conversationId];
1437
+ s2 && s2.sideEdited(e2, t2);
1438
+ }
1439
+ handleParticipantEdited(e2, t2) {
1440
+ const s2 = this.conversationStores[t2.conversationId];
1441
+ s2 && s2.participantEdited(e2, t2);
1442
+ }
1443
+ handleConversationEdited(e2, t2) {
1444
+ const s2 = this.conversationStores[t2.conversationId];
1445
+ s2 && s2.conversationEdited(e2, t2);
1446
+ }
1447
+ handleSideDeleted(e2, t2) {
1448
+ const s2 = this.messageWindowStores[t2.conversationId];
1449
+ s2 && s2.sideDeleted(e2, t2);
1450
+ const n2 = this.conversationStores[t2.conversationId];
1451
+ n2 && n2.sideDeleted(e2, t2);
1452
+ }
1453
+ handleMessageCreated(e2, t2) {
1454
+ const s2 = this.messageWindowStores[t2.conversationId];
1455
+ s2 && s2.messageCreated(e2, t2);
1456
+ }
1457
+ handleMessageEdited(e2, t2) {
1458
+ const s2 = this.messageWindowStores[t2.conversationId];
1459
+ s2 && s2.messageEdited(e2, t2);
1460
+ }
1461
+ handleMessageDeleted(e2, t2) {
1462
+ const s2 = this.messageWindowStores[t2.conversationId];
1463
+ s2 && s2.messageDeleted(e2, t2);
1464
+ }
1465
+ handleConversationCleared(e2, t2) {
1466
+ const s2 = this.messageWindowStores[t2.conversationId];
1467
+ s2 && s2.conversationCleared(e2, t2);
1468
+ }
1469
+ call(e2, t2, n2, r2) {
1470
+ return __async(this, null, function* () {
1471
+ if (!r2.bypassCache) {
1472
+ if ("GET" === e2 && s(t2, ["users", "*"])) {
1473
+ const e3 = t2[1], s2 = this.userStores[e3];
1474
+ if (s2) {
1475
+ const e4 = yield s2.getFromCache();
1476
+ if ("NOT_IN_CACHE" !== e4.value) return e4;
1477
+ }
1478
+ }
1479
+ if ("GET" === e2 && s(t2, ["me", "conversations", "*", "messages", "*"])) {
1480
+ const e3 = t2[2], s2 = this.messageWindowStores[e3];
1481
+ if (s2) {
1482
+ const e4 = t2[3], n3 = yield s2.getMessageFromCache(e4);
1483
+ if ("NOT_IN_CACHE" !== n3.value) return n3;
1484
+ }
1485
+ }
1486
+ }
1487
+ return this.connection.call(e2, t2, n2);
1488
+ });
1489
+ }
1490
+ subscribe(e2, s2) {
1491
+ const n2 = this.getOrCreateStore(e2), r2 = o(), i2 = o();
1492
+ r2.promise.catch(() => {
1493
+ }), i2.promise.catch(() => {
1494
+ });
1495
+ const a2 = { state: { type: "pending", latestSnapshot: void 0 }, connected: r2.promise, terminated: i2.promise, loadMore: (e3) => __async(this, null, function* () {
1496
+ "loadMore" in n2 && (yield n2.loadMore(e3));
1497
+ }), unsubscribe: () => {
1498
+ } }, u2 = n2.listen((n3) => {
1499
+ if (n3.ok) {
1500
+ const e3 = !("loadedAll" in n3.value) || n3.value.loadedAll, t2 = { type: "active", latestSnapshot: n3.value.snapshot, loadedAll: e3 };
1501
+ a2.state = t2, s2 == null ? void 0 : s2(n3.value.snapshot, e3), r2.resolve(t2);
1502
+ } else if ("pending" === a2.state.type || "active" === a2.state.type) {
1503
+ if ("server" === n3.where) {
1504
+ const s3 = { type: "error", error: new Error(t(`Subscribe to ${e2.join("/")}`, n3.value)) };
1505
+ return a2.state = s3, i2.resolve(s3), void r2.reject("Subscription encountered an error during initial connection");
1506
+ }
1507
+ if ("SESSION_DESTROYED" === n3.value) {
1508
+ const e3 = { type: "error", error: new Error("Session was destroyed causing all subscriptions to be terminated") };
1509
+ return a2.state = e3, i2.resolve(e3), void r2.reject("Subscription encountered an error during initial connection");
1510
+ }
1511
+ if ("UNSUBSCRIBED" === n3.value) return;
1512
+ if ("TERMINATED" === n3.value) return;
1513
+ n3.value;
1514
+ }
1515
+ });
1516
+ return a2.unsubscribe = () => {
1517
+ if ("pending" === a2.state.type || "active" === a2.state.type) {
1518
+ u2();
1519
+ const e3 = { type: "unsubscribed" };
1520
+ a2.state = e3, i2.resolve(e3), r2.reject("Subscription was unsubscribed before connecting");
1521
+ }
1522
+ }, a2;
1523
+ }
1524
+ getOrCreateStore(e2) {
1525
+ if (s(e2, ["users", "*"])) {
1526
+ const t2 = e2[1];
1527
+ if (Object.hasOwnProperty.call(this.userStores, t2)) return this.userStores[t2];
1528
+ {
1529
+ this.connection.subscribe(["users", t2]).then((e4) => {
1530
+ e4.ok || s2.setError(e4);
1531
+ });
1532
+ const e3 = this.seq, s2 = new H(e3, t2, this.realtimeClient, this.emitMutex, () => {
1533
+ delete this.userStores[t2], this.connection.unsubscribe(["users", t2]);
1534
+ });
1535
+ return this.userStores[t2] = s2, s2;
1536
+ }
1537
+ }
1538
+ if (s(e2, ["me", "conversations", "*"])) {
1539
+ const t2 = e2[2];
1540
+ if (Object.hasOwnProperty.call(this.conversationStores, t2)) return this.conversationStores[t2];
1541
+ {
1542
+ this.connection.subscribe(["me", "conversations", t2]).then((t3) => {
1543
+ t3.ok || e3.setError(t3);
1544
+ });
1545
+ const e3 = new pe(this.seq, this.emitMutex, t2, this.realtimeClient, () => {
1546
+ delete this.conversationStores[t2], this.connection.unsubscribe(["me", "conversations", t2]);
1547
+ });
1548
+ return this.conversationStores[t2] = e3, e3;
1549
+ }
1550
+ }
1551
+ if (s(e2, ["me", "conversations", "*", "messages"])) {
1552
+ const t2 = e2[2];
1553
+ if (Object.hasOwnProperty.call(this.messageWindowStores, t2)) return this.messageWindowStores[t2];
1554
+ {
1555
+ this.connection.subscribe(["me", "conversations", t2, "messages"]).then((t3) => {
1556
+ t3.ok || e3.setError(t3);
1557
+ });
1558
+ const e3 = new ce(this.seq, this.emitMutex, t2, this.realtimeClient, () => {
1559
+ delete this.messageWindowStores[t2], this.connection.unsubscribe(["me", "conversations", t2, "messages"]);
1560
+ });
1561
+ return this.messageWindowStores[t2] = e3, e3;
1562
+ }
1563
+ }
1564
+ throw new Error("Unrecognised subscribe path: " + e2);
1565
+ }
1566
+ getStoreIfExists(e2) {
1567
+ var _a2, _b;
1568
+ if (s(e2, ["users", "*"])) {
1569
+ const t2 = e2[1];
1570
+ return (_a2 = this.userStores[t2]) != null ? _a2 : null;
1571
+ }
1572
+ if (s(e2, ["me", "conversations", "*", "messages"])) {
1573
+ const t2 = e2[2];
1574
+ return (_b = this.messageWindowStores[t2]) != null ? _b : null;
1575
+ }
1576
+ throw new Error("Unrecognised subscribe path: " + e2);
1577
+ }
1578
+ destroy() {
1579
+ this.userStores = {}, this.messageWindowStores = {}, this.connection.destroy();
1580
+ }
1581
+ isConnected() {
1582
+ return this.connection.isConnected();
1583
+ }
1584
+ }
1585
+ class ge {
1586
+ constructor(e2, t2, s2) {
1587
+ this.userId = t2, this.alive = true, this.connection = new me(e2, s2, this), s2.onTokenRefreshFailed(() => {
1588
+ this.destroy();
1589
+ });
1590
+ }
1591
+ call(_0, _1, _2) {
1592
+ return __async(this, arguments, function* (e2, t2, s2, n2 = {}) {
1593
+ return this.alive ? this.connection.call(e2, t2, s2, n2) : l("SESSION_DESTROYED");
1594
+ });
1595
+ }
1596
+ subscribe(e2, t2) {
1597
+ return this.connection.subscribe(e2, t2);
1598
+ }
1599
+ internalSubscribe(e2) {
1600
+ const t2 = this.connection.getOrCreateStore(e2);
1601
+ return { store: t2, unsubscribe: t2.registerInternalSubscription() };
1602
+ }
1603
+ destroy() {
1604
+ this.alive = false, this.connection.destroy();
1605
+ }
1606
+ isConnected() {
1607
+ return this.connection.isConnected();
1608
+ }
1609
+ listMessages(e2, t2) {
1610
+ return __async(this, null, function* () {
1611
+ const s2 = yield this.call("GET", ["me", "conversations", e2, "messages"], t2);
1612
+ if (!s2.ok) return ve(s2, "Listing messages in " + e2);
1613
+ const n2 = s2.value.data.data, r2 = yield Promise.all(n2.map((t3) => this.createMessageSnapshot(t3, e2))), i2 = r2.find((e3) => !e3.ok);
1614
+ if (void 0 !== i2 && !i2.ok) return i2;
1615
+ return c(r2.map(({ value: e3 }) => e3));
1616
+ });
1617
+ }
1618
+ createConversationSnapshotPreloaded(e2, t2) {
1619
+ return { id: e2.id, subject: e2.subject, photoUrl: e2.photoUrl, welcomeMessages: e2.welcomeMessages, custom: e2.custom, createdAt: e2.createdAt, joinedAt: e2.joinedAt, lastMessageAt: e2.lastMessageAt, unreadMessageCount: e2.unreadMessageCount, isUnread: e2.isUnread, access: e2.access, notify: e2.notify, lastMessage: t2, readUntil: e2.readUntil };
1620
+ }
1621
+ createUserSnapshot(e2) {
1622
+ return { id: e2.id, name: e2.name, custom: e2.custom, locale: e2.locale, photoUrl: e2.photoUrl, role: e2.role, welcomeMessage: e2.welcomeMessage };
1623
+ }
1624
+ createParticipantSnapshotPreloaded(e2, t2) {
1625
+ return "None" === e2.access ? null : { user: t2, access: e2.access, notify: e2.notify, joinedAt: e2.joinedAt };
1626
+ }
1627
+ createMessageSnapshot(e2, t2) {
1628
+ return __async(this, null, function* () {
1629
+ const s2 = null === e2.senderId ? Promise.resolve(c(null)) : this.getUser(e2.senderId), n2 = null === e2.referencedMessageId ? Promise.resolve(c(null)) : this.getReferencedMessage(t2, e2.referencedMessageId), r2 = yield s2;
1630
+ if (!r2.ok) return r2;
1631
+ const i2 = yield n2;
1632
+ if (!i2.ok) return i2;
1633
+ return c(this.createMessageSnapshotPreloaded(e2, r2.value, i2.value));
1634
+ });
1635
+ }
1636
+ getReferencedMessage(e2, t2) {
1637
+ return __async(this, null, function* () {
1638
+ const s2 = yield this.call("GET", ["me", "conversations", e2, "messages", t2], {});
1639
+ if (!s2.ok && "server" === s2.where && 404 === s2.value.status) return c(null);
1640
+ if (!s2.ok && "server" === s2.where && 403 === s2.value.status && "NOT_A_PARTICIPANT" === s2.value.errorCode) return c(null);
1641
+ if (!s2.ok) return ve(s2, `Fetching referenced message ${t2} in conversation ${e2}`);
1642
+ const n2 = s2.value.data, r2 = yield this.getUser(n2.senderId);
1643
+ if (!r2.ok) return r2;
1644
+ const i2 = r2.value;
1645
+ return c(this.createReferencedMessageSnapshotPreloaded(n2, i2));
1646
+ });
1647
+ }
1648
+ getUser(e2) {
1649
+ return __async(this, null, function* () {
1650
+ const t2 = yield this.call("GET", ["users", e2], { includePrivateFields: false });
1651
+ if (!t2.ok && "server" === t2.where && 404 === t2.value.status) return c(null);
1652
+ if (!t2.ok) return ve(t2, "Get user " + e2);
1653
+ return c(this.createUserSnapshot(t2.value.data));
1654
+ });
1655
+ }
1656
+ createMessageSnapshotPreloaded(e2, t2, s2) {
1657
+ return { id: e2.id, type: e2.type, sender: t2, referencedMessage: s2, custom: e2.custom, createdAt: e2.createdAt, editedAt: e2.editedAt, origin: e2.origin, content: e2.content, plaintext: ie(e2.content, {}) };
1658
+ }
1659
+ createReferencedMessageSnapshotPreloaded(e2, t2) {
1660
+ return { id: e2.id, type: e2.type, sender: t2, referencedMessageId: e2.referencedMessageId, custom: e2.custom, createdAt: e2.createdAt, editedAt: e2.editedAt, origin: e2.origin, content: e2.content, plaintext: ie(e2.content, {}) };
1661
+ }
1662
+ }
1663
+ function ve(e2, t2) {
1664
+ return "server" === e2.where ? h(__spreadProps(__spreadValues({}, e2.value), { operation: t2 })) : e2;
1665
+ }
1666
+ function be(e2, s2) {
1667
+ var _a2;
1668
+ if (s2.ok) return s2.value;
1669
+ throw "SESSION_DESTROYED" === s2.value ? new Error(`${e2} failed because the session was destroyed`) : new Error(t((_a2 = s2.value.operation) != null ? _a2 : e2, s2.value));
1670
+ }
1671
+ class we {
1672
+ constructor(e2, t2) {
1673
+ this.id = e2, this._realtimeClient = t2;
1674
+ }
1675
+ get brandedId() {
1676
+ return this.id;
1677
+ }
1678
+ get() {
1679
+ return __async(this, null, function* () {
1680
+ const e2 = yield this._realtimeClient.getUser(this.brandedId);
1681
+ return be("Get user " + this.id, e2);
1682
+ });
1683
+ }
1684
+ set(t2) {
1685
+ return __async(this, null, function* () {
1686
+ null === t2.role && (t2.role = "default");
1687
+ const s2 = "string" == typeof t2.email ? [t2.email] : t2.email, n2 = "string" == typeof t2.phone ? [t2.phone] : t2.phone, r2 = yield this._realtimeClient.call("PUT", ["users", this.brandedId], __spreadProps(__spreadValues({}, t2), { email: s2, phone: n2 }));
1688
+ e("Set user " + this.id, r2);
1689
+ });
1690
+ }
1691
+ createIfNotExists(t2) {
1692
+ return __async(this, null, function* () {
1693
+ void 0 === t2.role && (t2.role = "default");
1694
+ const s2 = "string" == typeof t2.email ? [t2.email] : t2.email, n2 = "string" == typeof t2.phone ? [t2.phone] : t2.phone, r2 = yield this._realtimeClient.call("POST", ["users", this.brandedId], __spreadProps(__spreadValues({}, t2), { email: s2, phone: n2 }));
1695
+ (r2.ok || "server" !== r2.where || 409 != r2.value.status) && e(`Create user ${this.id} if not exists`, r2);
1696
+ });
1697
+ }
1698
+ subscribe(e2) {
1699
+ return this._realtimeClient.subscribe(["users", this.brandedId], e2);
1700
+ }
1701
+ }
1702
+ class ye {
1703
+ constructor(e2, t2, s2) {
1704
+ this.userId = e2, this.conversationId = t2, this._realtimeClient = s2;
1705
+ }
1706
+ get brandedUserId() {
1707
+ return this.userId;
1708
+ }
1709
+ get brandedConversationId() {
1710
+ return this.conversationId;
1711
+ }
1712
+ get() {
1713
+ return __async(this, null, function* () {
1714
+ const t2 = yield this._realtimeClient.call("GET", ["me", "conversations", this.brandedConversationId, "participants", this.brandedUserId], {}), s2 = yield this._realtimeClient.call("GET", ["users", this.brandedUserId], { includePrivateFields: false }), [n2, r2] = yield Promise.all([t2, s2]);
1715
+ if (!n2.ok && "server" === n2.where && 404 === n2.value.status) return null;
1716
+ if (!r2.ok && "server" === r2.where && 404 === r2.value.status) return null;
1717
+ const i2 = e(`Get participant ${this.userId} in conversation ${this.conversationId}`, n2), a2 = e(`Get user ${this.userId}`, r2), o2 = this._realtimeClient.createUserSnapshot(a2);
1718
+ return this._realtimeClient.createParticipantSnapshotPreloaded(i2, o2);
1719
+ });
1720
+ }
1721
+ set() {
1722
+ return __async(this, arguments, function* (t2 = {}) {
1723
+ const s2 = yield this._realtimeClient.call("PUT", ["conversations", this.brandedConversationId, "participants", this.brandedUserId], t2);
1724
+ e(`Set participant ${this.userId} in conversation ${this.conversationId}`, s2);
1725
+ });
1726
+ }
1727
+ edit() {
1728
+ return __async(this, arguments, function* (t2 = {}) {
1729
+ const s2 = yield this._realtimeClient.call("PATCH", ["conversations", this.brandedConversationId, "participants", this.brandedUserId], t2);
1730
+ e(`Edit participant ${this.userId} in conversation ${this.conversationId}`, s2);
1731
+ });
1732
+ }
1733
+ createIfNotExists() {
1734
+ return __async(this, arguments, function* (t2 = {}) {
1735
+ const s2 = yield this._realtimeClient.call("POST", ["conversations", this.brandedConversationId, "participants", this.brandedUserId], t2);
1736
+ (s2.ok || "server" !== s2.where || 409 !== s2.value.status) && e(`Add participant ${this.userId} to conversation ${this.conversationId}`, s2);
1737
+ });
1738
+ }
1739
+ delete() {
1740
+ return __async(this, null, function* () {
1741
+ const t2 = yield this._realtimeClient.call("DELETE", ["conversations", this.brandedConversationId, "participants", this.brandedUserId], {});
1742
+ (t2.ok || "server" !== t2.where || 404 !== t2.value.status) && e(`Remove participant ${this.userId} from conversation ${this.conversationId}`, t2);
1743
+ });
1744
+ }
1745
+ }
1746
+ function Ae(e2) {
1747
+ const t2 = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
1748
+ let s2 = 0;
1749
+ const n2 = [], r2 = e2 === s2;
1750
+ s2 = e2;
1751
+ const i2 = new Array(8);
1752
+ for (let s3 = 7; s3 >= 0; s3--) i2[s3] = t2.charAt(e2 % 64), e2 = Math.floor(e2 / 64);
1753
+ if (0 !== e2) throw new Error("We should have converted the entire timestamp.");
1754
+ let a2 = i2.join("");
1755
+ if (r2) {
1756
+ let e3;
1757
+ for (e3 = 11; e3 >= 0 && 63 === n2[e3]; e3--) n2[e3] = 0;
1758
+ n2[e3]++;
1759
+ } else for (let e3 = 0; e3 < 12; e3++) n2[e3] = Math.floor(64 * Math.random());
1760
+ for (let e3 = 0; e3 < 12; e3++) a2 += t2.charAt(n2[e3]);
1761
+ if (20 != a2.length) throw new Error("Length should be 20.");
1762
+ return a2;
1763
+ }
1764
+ const Ce = (e2, t2, s2 = void 0) => function(e3, t3) {
1765
+ return e3.reduce((e4, s3, n2) => e4.concat(t3(s3, n2)), []);
1766
+ }(e2, (e3) => {
1767
+ if ("string" == typeof e3) return t2(e3, s2);
1768
+ switch (e3.type) {
1769
+ case "bold":
1770
+ case "italic":
1771
+ case "strikethrough":
1772
+ case "blockquote":
1773
+ case "bulletlist":
1774
+ case "bulletList":
1775
+ case "bulletpoint":
1776
+ case "bulletPoint":
1777
+ return [{ type: e3.type, children: Ce(e3.children, t2, e3.type) }];
1778
+ case "link":
1779
+ return [{ type: e3.type, url: e3.url, children: Ce(e3.children, t2, e3.type) }];
1780
+ case "actionlink":
1781
+ case "actionLink":
1782
+ case "actionbutton":
1783
+ case "actionButton":
1784
+ return [{ type: e3.type, action: e3.action, params: e3.params, children: Ce(e3.children, t2, e3.type) }];
1785
+ case "mention":
1786
+ case "autolink":
1787
+ case "autoLink":
1788
+ case "codeblock":
1789
+ case "codeBlock":
1790
+ case "codespan":
1791
+ case "codeSpan":
1792
+ case "suppressed":
1793
+ case "emoji":
1794
+ case "customemoji":
1795
+ case "customEmoji":
1796
+ return [e3];
1797
+ }
1798
+ });
1799
+ function Ee(e2, t2) {
1800
+ return (s2) => {
1801
+ const n2 = s2;
1802
+ let r2 = 0;
1803
+ const i2 = [];
1804
+ for (const a2 of Z(s2, e2)) {
1805
+ a2.index - r2 > 0 && i2.push(n2.substring(r2, a2.index));
1806
+ const e3 = t2(a2);
1807
+ Array.isArray(e3) ? i2.push(...e3) : i2.push(e3), r2 = a2.index + a2[0].length;
1808
+ }
1809
+ return r2 < s2.length && i2.push(s2.substring(r2)), i2;
1810
+ };
1811
+ }
1812
+ const ke = "’'()[]{}<>:,‒–—―…!.«»-‐?‘’“”;/⁄␠·&@*\\•^¤¢$€£¥₩₪†‡°¡¿¬#№%‰‱¶′§~¨_|¦⁂☞∴‽※".replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
1813
+ var xe = ((e2) => (e2[e2.italic = 1] = "italic", e2[e2.strikethrough = 2] = "strikethrough", e2[e2.bold = 4] = "bold", e2))(xe || {});
1814
+ const Se = [0, 1, 2, 3, 4, 5, 6].map((e2) => {
1815
+ const t2 = [];
1816
+ return 1 & e2 || t2.push(/_([^\s_].*?[^\s_])_|_([^\s_])_/), 2 & e2 || t2.push(/~([^\s~].*?[^\s~])~|~([^\s~])~/), 4 & e2 || t2.push(/\*([^\s*].*?[^\s*])\*|\*([^\s*])\*/), new RegExp(t2.map((e3) => e3.source).join("|"), "g");
1817
+ }), Te = { _: 1, "*": 4, "~": 2 };
1818
+ function De(e2) {
1819
+ return Ie(e2, 0);
1820
+ }
1821
+ function Ie(e2, t2 = 0) {
1822
+ const s2 = Se[t2], n2 = s2 ? function(e3) {
1823
+ const t3 = Fe.getOrCompute(e3, () => new RegExp(`(?:^|[\\s${ke}])(?:${e3.source})(?=[\\s${ke}]|$)`, "g")), s3 = Ee(t3, (e4) => {
1824
+ const t4 = e4[0][1], s4 = e4[1] || e4[2] || e4[3] || e4[4] || e4[5] || e4[6];
1825
+ return [" ", { type: xe[Te[t4]], children: [s4] }];
1826
+ });
1827
+ return (e4) => {
1828
+ const [t4, ...n3] = s3(" " + e4);
1829
+ return t4.length > 1 && n3.unshift(t4.substring(1)), n3;
1830
+ };
1831
+ }(s2) : () => [e2];
1832
+ return Ce(n2(e2), (e3, s3) => "bold" === s3 || "italic" === s3 || "strikethrough" === s3 ? Ie(e3, t2 | xe[s3]) : [e3]);
1833
+ }
1834
+ const Fe = function() {
1835
+ const e2 = function() {
1836
+ try {
1837
+ return /* @__PURE__ */ new WeakMap();
1838
+ } catch (e3) {
1839
+ const t2 = { has: () => false, get: () => {
1840
+ }, set: () => t2 };
1841
+ return t2;
1842
+ }
1843
+ }();
1844
+ return { getOrCompute(t2, s2) {
1845
+ if (e2.has(t2)) return e2.get(t2);
1846
+ const n2 = s2();
1847
+ return e2.set(t2, n2), n2;
1848
+ } };
1849
+ }();
1850
+ function Be(e2, t2) {
1851
+ if (Array.prototype.indexOf) return e2.indexOf(t2);
1852
+ for (var s2 = 0, n2 = e2.length; s2 < n2; s2++) if (e2[s2] === t2) return s2;
1853
+ return -1;
1854
+ }
1855
+ function Me(e2, t2) {
1856
+ for (var s2 = e2.length - 1; s2 >= 0; s2--) true === t2(e2[s2]) && e2.splice(s2, 1);
1857
+ }
1858
+ function Re(e2) {
1859
+ throw new Error("Unhandled case for value: '" + e2 + "'");
1860
+ }
1861
+ var Ne = function() {
1862
+ function e2(e3) {
1863
+ void 0 === e3 && (e3 = {}), this.tagName = "", this.attrs = {}, this.innerHTML = "", this.whitespaceRegex = /\s+/, this.tagName = e3.tagName || "", this.attrs = e3.attrs || {}, this.innerHTML = e3.innerHtml || e3.innerHTML || "";
1864
+ }
1865
+ return e2.prototype.setTagName = function(e3) {
1866
+ return this.tagName = e3, this;
1867
+ }, e2.prototype.getTagName = function() {
1868
+ return this.tagName || "";
1869
+ }, e2.prototype.setAttr = function(e3, t2) {
1870
+ return this.getAttrs()[e3] = t2, this;
1871
+ }, e2.prototype.getAttr = function(e3) {
1872
+ return this.getAttrs()[e3];
1873
+ }, e2.prototype.setAttrs = function(e3) {
1874
+ return Object.assign(this.getAttrs(), e3), this;
1875
+ }, e2.prototype.getAttrs = function() {
1876
+ return this.attrs || (this.attrs = {});
1877
+ }, e2.prototype.setClass = function(e3) {
1878
+ return this.setAttr("class", e3);
1879
+ }, e2.prototype.addClass = function(e3) {
1880
+ for (var t2, s2 = this.getClass(), n2 = this.whitespaceRegex, r2 = s2 ? s2.split(n2) : [], i2 = e3.split(n2); t2 = i2.shift(); ) -1 === Be(r2, t2) && r2.push(t2);
1881
+ return this.getAttrs().class = r2.join(" "), this;
1882
+ }, e2.prototype.removeClass = function(e3) {
1883
+ for (var t2, s2 = this.getClass(), n2 = this.whitespaceRegex, r2 = s2 ? s2.split(n2) : [], i2 = e3.split(n2); r2.length && (t2 = i2.shift()); ) {
1884
+ var a2 = Be(r2, t2);
1885
+ -1 !== a2 && r2.splice(a2, 1);
1886
+ }
1887
+ return this.getAttrs().class = r2.join(" "), this;
1888
+ }, e2.prototype.getClass = function() {
1889
+ return this.getAttrs().class || "";
1890
+ }, e2.prototype.hasClass = function(e3) {
1891
+ return -1 !== (" " + this.getClass() + " ").indexOf(" " + e3 + " ");
1892
+ }, e2.prototype.setInnerHTML = function(e3) {
1893
+ return this.innerHTML = e3, this;
1894
+ }, e2.prototype.setInnerHtml = function(e3) {
1895
+ return this.setInnerHTML(e3);
1896
+ }, e2.prototype.getInnerHTML = function() {
1897
+ return this.innerHTML || "";
1898
+ }, e2.prototype.getInnerHtml = function() {
1899
+ return this.getInnerHTML();
1900
+ }, e2.prototype.toAnchorString = function() {
1901
+ var e3 = this.getTagName(), t2 = this.buildAttrsStr();
1902
+ return ["<", e3, t2 = t2 ? " " + t2 : "", ">", this.getInnerHtml(), "</", e3, ">"].join("");
1903
+ }, e2.prototype.buildAttrsStr = function() {
1904
+ if (!this.attrs) return "";
1905
+ var e3 = this.getAttrs(), t2 = [];
1906
+ for (var s2 in e3) e3.hasOwnProperty(s2) && t2.push(s2 + '="' + e3[s2] + '"');
1907
+ return t2.join(" ");
1908
+ }, e2;
1909
+ }();
1910
+ var _e = function() {
1911
+ function e2(e3) {
1912
+ void 0 === e3 && (e3 = {}), this.newWindow = false, this.truncate = {}, this.className = "", this.newWindow = e3.newWindow || false, this.truncate = e3.truncate || {}, this.className = e3.className || "";
1913
+ }
1914
+ return e2.prototype.build = function(e3) {
1915
+ return new Ne({ tagName: "a", attrs: this.createAttrs(e3), innerHtml: this.processAnchorText(e3.getAnchorText()) });
1916
+ }, e2.prototype.createAttrs = function(e3) {
1917
+ var t2 = { href: e3.getAnchorHref() }, s2 = this.createCssClass(e3);
1918
+ return s2 && (t2.class = s2), this.newWindow && (t2.target = "_blank", t2.rel = "noopener noreferrer"), this.truncate && this.truncate.length && this.truncate.length < e3.getAnchorText().length && (t2.title = e3.getAnchorHref()), t2;
1919
+ }, e2.prototype.createCssClass = function(e3) {
1920
+ var t2 = this.className;
1921
+ if (t2) {
1922
+ for (var s2 = [t2], n2 = e3.getCssClassSuffixes(), r2 = 0, i2 = n2.length; r2 < i2; r2++) s2.push(t2 + "-" + n2[r2]);
1923
+ return s2.join(" ");
1924
+ }
1925
+ return "";
1926
+ }, e2.prototype.processAnchorText = function(e3) {
1927
+ return e3 = this.doTruncate(e3);
1928
+ }, e2.prototype.doTruncate = function(e3) {
1929
+ var t2 = this.truncate;
1930
+ if (!t2 || !t2.length) return e3;
1931
+ var s2 = t2.length, n2 = t2.location;
1932
+ return "smart" === n2 ? function(e4, t3, s3) {
1933
+ var n3, r2;
1934
+ null == s3 ? (s3 = "&hellip;", r2 = 3, n3 = 8) : (r2 = s3.length, n3 = s3.length);
1935
+ var i2 = function(e5) {
1936
+ var t4 = "";
1937
+ return e5.scheme && e5.host && (t4 += e5.scheme + "://"), e5.host && (t4 += e5.host), e5.path && (t4 += "/" + e5.path), e5.query && (t4 += "?" + e5.query), e5.fragment && (t4 += "#" + e5.fragment), t4;
1938
+ }, a2 = function(e5, t4) {
1939
+ var n4 = t4 / 2, r3 = Math.ceil(n4), i3 = -1 * Math.floor(n4), a3 = "";
1940
+ return i3 < 0 && (a3 = e5.substr(i3)), e5.substr(0, r3) + s3 + a3;
1941
+ };
1942
+ if (e4.length <= t3) return e4;
1943
+ var o2 = t3 - r2, u2 = function(e5) {
1944
+ var t4 = {}, s4 = e5, n4 = s4.match(/^([a-z]+):\/\//i);
1945
+ return n4 && (t4.scheme = n4[1], s4 = s4.substr(n4[0].length)), (n4 = s4.match(/^(.*?)(?=(\?|#|\/|$))/i)) && (t4.host = n4[1], s4 = s4.substr(n4[0].length)), (n4 = s4.match(/^\/(.*?)(?=(\?|#|$))/i)) && (t4.path = n4[1], s4 = s4.substr(n4[0].length)), (n4 = s4.match(/^\?(.*?)(?=(#|$))/i)) && (t4.query = n4[1], s4 = s4.substr(n4[0].length)), (n4 = s4.match(/^#(.*?)$/i)) && (t4.fragment = n4[1]), t4;
1946
+ }(e4);
1947
+ if (u2.query) {
1948
+ var c2 = u2.query.match(/^(.*?)(?=(\?|\#))(.*?)$/i);
1949
+ c2 && (u2.query = u2.query.substr(0, c2[1].length), e4 = i2(u2));
1950
+ }
1951
+ if (e4.length <= t3) return e4;
1952
+ if (u2.host && (u2.host = u2.host.replace(/^www\./, ""), e4 = i2(u2)), e4.length <= t3) return e4;
1953
+ var l2 = "";
1954
+ if (u2.host && (l2 += u2.host), l2.length >= o2) return u2.host.length == t3 ? (u2.host.substr(0, t3 - r2) + s3).substr(0, o2 + n3) : a2(l2, o2).substr(0, o2 + n3);
1955
+ var h2 = "";
1956
+ if (u2.path && (h2 += "/" + u2.path), u2.query && (h2 += "?" + u2.query), h2) {
1957
+ if ((l2 + h2).length >= o2) return (l2 + h2).length == t3 ? (l2 + h2).substr(0, t3) : (l2 + a2(h2, o2 - l2.length)).substr(0, o2 + n3);
1958
+ l2 += h2;
1959
+ }
1960
+ if (u2.fragment) {
1961
+ var d2 = "#" + u2.fragment;
1962
+ if ((l2 + d2).length >= o2) return (l2 + d2).length == t3 ? (l2 + d2).substr(0, t3) : (l2 + a2(d2, o2 - l2.length)).substr(0, o2 + n3);
1963
+ l2 += d2;
1964
+ }
1965
+ if (u2.scheme && u2.host) {
1966
+ var p2 = u2.scheme + "://";
1967
+ if ((l2 + p2).length < o2) return (p2 + l2).substr(0, t3);
1968
+ }
1969
+ if (l2.length <= t3) return l2;
1970
+ var f2 = "";
1971
+ return o2 > 0 && (f2 = l2.substr(-1 * Math.floor(o2 / 2))), (l2.substr(0, Math.ceil(o2 / 2)) + s3 + f2).substr(0, o2 + n3);
1972
+ }(e3, s2) : "middle" === n2 ? function(e4, t3, s3) {
1973
+ if (e4.length <= t3) return e4;
1974
+ var n3, r2;
1975
+ null == s3 ? (s3 = "&hellip;", n3 = 8, r2 = 3) : (n3 = s3.length, r2 = s3.length);
1976
+ var i2 = t3 - r2, a2 = "";
1977
+ return i2 > 0 && (a2 = e4.substr(-1 * Math.floor(i2 / 2))), (e4.substr(0, Math.ceil(i2 / 2)) + s3 + a2).substr(0, i2 + n3);
1978
+ }(e3, s2) : function(e4, t3, s3) {
1979
+ return function(e5, t4, s4) {
1980
+ var n3;
1981
+ return e5.length > t4 && (null == s4 ? (s4 = "&hellip;", n3 = 3) : n3 = s4.length, e5 = e5.substring(0, t4 - n3) + s4), e5;
1982
+ }(e4, t3, s3);
1983
+ }(e3, s2);
1984
+ }, e2;
1985
+ }(), Pe = function() {
1986
+ function e2(e3) {
1987
+ this.__jsduckDummyDocProp = null, this.matchedText = "", this.offset = 0, this.tagBuilder = e3.tagBuilder, this.matchedText = e3.matchedText, this.offset = e3.offset;
1988
+ }
1989
+ return e2.prototype.getMatchedText = function() {
1990
+ return this.matchedText;
1991
+ }, e2.prototype.setOffset = function(e3) {
1992
+ this.offset = e3;
1993
+ }, e2.prototype.getOffset = function() {
1994
+ return this.offset;
1995
+ }, e2.prototype.getCssClassSuffixes = function() {
1996
+ return [this.getType()];
1997
+ }, e2.prototype.buildTag = function() {
1998
+ return this.tagBuilder.build(this);
1999
+ }, e2;
2000
+ }(), Oe = function(e2, t2) {
2001
+ return Oe = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e3, t3) {
2002
+ e3.__proto__ = t3;
2003
+ } || function(e3, t3) {
2004
+ for (var s2 in t3) t3.hasOwnProperty(s2) && (e3[s2] = t3[s2]);
2005
+ }, Oe(e2, t2);
2006
+ };
2007
+ function Ue(e2, t2) {
2008
+ function s2() {
2009
+ this.constructor = e2;
2010
+ }
2011
+ Oe(e2, t2), e2.prototype = null === t2 ? Object.create(t2) : (s2.prototype = t2.prototype, new s2());
2012
+ }
2013
+ var je, $e = function() {
2014
+ return $e = Object.assign || function(e2) {
2015
+ for (var t2, s2 = 1, n2 = arguments.length; s2 < n2; s2++) for (var r2 in t2 = arguments[s2]) Object.prototype.hasOwnProperty.call(t2, r2) && (e2[r2] = t2[r2]);
2016
+ return e2;
2017
+ }, $e.apply(this, arguments);
2018
+ }, We = function(e2) {
2019
+ function t2(t3) {
2020
+ var s2 = e2.call(this, t3) || this;
2021
+ return s2.email = "", s2.email = t3.email, s2;
2022
+ }
2023
+ return Ue(t2, e2), t2.prototype.getType = function() {
2024
+ return "email";
2025
+ }, t2.prototype.getEmail = function() {
2026
+ return this.email;
2027
+ }, t2.prototype.getAnchorHref = function() {
2028
+ return "mailto:" + this.email;
2029
+ }, t2.prototype.getAnchorText = function() {
2030
+ return this.email;
2031
+ }, t2;
2032
+ }(Pe), qe = function(e2) {
2033
+ function t2(t3) {
2034
+ var s2 = e2.call(this, t3) || this;
2035
+ return s2.serviceName = "", s2.hashtag = "", s2.serviceName = t3.serviceName, s2.hashtag = t3.hashtag, s2;
2036
+ }
2037
+ return Ue(t2, e2), t2.prototype.getType = function() {
2038
+ return "hashtag";
2039
+ }, t2.prototype.getServiceName = function() {
2040
+ return this.serviceName;
2041
+ }, t2.prototype.getHashtag = function() {
2042
+ return this.hashtag;
2043
+ }, t2.prototype.getAnchorHref = function() {
2044
+ var e3 = this.serviceName, t3 = this.hashtag;
2045
+ switch (e3) {
2046
+ case "twitter":
2047
+ return "https://twitter.com/hashtag/" + t3;
2048
+ case "facebook":
2049
+ return "https://www.facebook.com/hashtag/" + t3;
2050
+ case "instagram":
2051
+ return "https://instagram.com/explore/tags/" + t3;
2052
+ default:
2053
+ throw new Error("Unknown service name to point hashtag to: " + e3);
2054
+ }
2055
+ }, t2.prototype.getAnchorText = function() {
2056
+ return "#" + this.hashtag;
2057
+ }, t2;
2058
+ }(Pe), He = function(e2) {
2059
+ function t2(t3) {
2060
+ var s2 = e2.call(this, t3) || this;
2061
+ return s2.serviceName = "twitter", s2.mention = "", s2.mention = t3.mention, s2.serviceName = t3.serviceName, s2;
2062
+ }
2063
+ return Ue(t2, e2), t2.prototype.getType = function() {
2064
+ return "mention";
2065
+ }, t2.prototype.getMention = function() {
2066
+ return this.mention;
2067
+ }, t2.prototype.getServiceName = function() {
2068
+ return this.serviceName;
2069
+ }, t2.prototype.getAnchorHref = function() {
2070
+ switch (this.serviceName) {
2071
+ case "twitter":
2072
+ return "https://twitter.com/" + this.mention;
2073
+ case "instagram":
2074
+ return "https://instagram.com/" + this.mention;
2075
+ case "soundcloud":
2076
+ return "https://soundcloud.com/" + this.mention;
2077
+ default:
2078
+ throw new Error("Unknown service name to point mention to: " + this.serviceName);
2079
+ }
2080
+ }, t2.prototype.getAnchorText = function() {
2081
+ return "@" + this.mention;
2082
+ }, t2.prototype.getCssClassSuffixes = function() {
2083
+ var t3 = e2.prototype.getCssClassSuffixes.call(this), s2 = this.getServiceName();
2084
+ return s2 && t3.push(s2), t3;
2085
+ }, t2;
2086
+ }(Pe), Ge = function(e2) {
2087
+ function t2(t3) {
2088
+ var s2 = e2.call(this, t3) || this;
2089
+ return s2.number = "", s2.plusSign = false, s2.number = t3.number, s2.plusSign = t3.plusSign, s2;
2090
+ }
2091
+ return Ue(t2, e2), t2.prototype.getType = function() {
2092
+ return "phone";
2093
+ }, t2.prototype.getPhoneNumber = function() {
2094
+ return this.number;
2095
+ }, t2.prototype.getNumber = function() {
2096
+ return this.getPhoneNumber();
2097
+ }, t2.prototype.getAnchorHref = function() {
2098
+ return "tel:" + (this.plusSign ? "+" : "") + this.number;
2099
+ }, t2.prototype.getAnchorText = function() {
2100
+ return this.matchedText;
2101
+ }, t2;
2102
+ }(Pe), Le = function(e2) {
2103
+ function t2(t3) {
2104
+ var s2 = e2.call(this, t3) || this;
2105
+ return s2.url = "", s2.urlMatchType = "scheme", s2.protocolUrlMatch = false, s2.protocolRelativeMatch = false, s2.stripPrefix = { scheme: true, www: true }, s2.stripTrailingSlash = true, s2.decodePercentEncoding = true, s2.schemePrefixRegex = /^(https?:\/\/)?/i, s2.wwwPrefixRegex = /^(https?:\/\/)?(www\.)?/i, s2.protocolRelativeRegex = /^\/\//, s2.protocolPrepended = false, s2.urlMatchType = t3.urlMatchType, s2.url = t3.url, s2.protocolUrlMatch = t3.protocolUrlMatch, s2.protocolRelativeMatch = t3.protocolRelativeMatch, s2.stripPrefix = t3.stripPrefix, s2.stripTrailingSlash = t3.stripTrailingSlash, s2.decodePercentEncoding = t3.decodePercentEncoding, s2;
2106
+ }
2107
+ return Ue(t2, e2), t2.prototype.getType = function() {
2108
+ return "url";
2109
+ }, t2.prototype.getUrlMatchType = function() {
2110
+ return this.urlMatchType;
2111
+ }, t2.prototype.getUrl = function() {
2112
+ var e3 = this.url;
2113
+ return this.protocolRelativeMatch || this.protocolUrlMatch || this.protocolPrepended || (e3 = this.url = "http://" + e3, this.protocolPrepended = true), e3;
2114
+ }, t2.prototype.getAnchorHref = function() {
2115
+ return this.getUrl().replace(/&amp;/g, "&");
2116
+ }, t2.prototype.getAnchorText = function() {
2117
+ var e3 = this.getMatchedText();
2118
+ return this.protocolRelativeMatch && (e3 = this.stripProtocolRelativePrefix(e3)), this.stripPrefix.scheme && (e3 = this.stripSchemePrefix(e3)), this.stripPrefix.www && (e3 = this.stripWwwPrefix(e3)), this.stripTrailingSlash && (e3 = this.removeTrailingSlash(e3)), this.decodePercentEncoding && (e3 = this.removePercentEncoding(e3)), e3;
2119
+ }, t2.prototype.stripSchemePrefix = function(e3) {
2120
+ return e3.replace(this.schemePrefixRegex, "");
2121
+ }, t2.prototype.stripWwwPrefix = function(e3) {
2122
+ return e3.replace(this.wwwPrefixRegex, "$1");
2123
+ }, t2.prototype.stripProtocolRelativePrefix = function(e3) {
2124
+ return e3.replace(this.protocolRelativeRegex, "");
2125
+ }, t2.prototype.removeTrailingSlash = function(e3) {
2126
+ return "/" === e3.charAt(e3.length - 1) && (e3 = e3.slice(0, -1)), e3;
2127
+ }, t2.prototype.removePercentEncoding = function(e3) {
2128
+ var t3 = e3.replace(/%22/gi, "&quot;").replace(/%26/gi, "&amp;").replace(/%27/gi, "&#39;").replace(/%3C/gi, "&lt;").replace(/%3E/gi, "&gt;");
2129
+ try {
2130
+ return decodeURIComponent(t3);
2131
+ } catch (e4) {
2132
+ return t3;
2133
+ }
2134
+ }, t2;
2135
+ }(Pe), ze = function(e2) {
2136
+ this.__jsduckDummyDocProp = null, this.tagBuilder = e2.tagBuilder;
2137
+ }, Je = /[A-Za-z]/, Ye = /[\d]/, Qe = /[\D]/, Ve = /\s/, Ze = /['"]/, Ke = /[\x00-\x1F\x7F]/, Xe = /A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC/.source, et = Xe + /\u2700-\u27bf\udde6-\uddff\ud800-\udbff\udc00-\udfff\ufe0e\ufe0f\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0\ud83c\udffb-\udfff\u200d\u3299\u3297\u303d\u3030\u24c2\ud83c\udd70-\udd71\udd7e-\udd7f\udd8e\udd91-\udd9a\udde6-\uddff\ude01-\ude02\ude1a\ude2f\ude32-\ude3a\ude50-\ude51\u203c\u2049\u25aa-\u25ab\u25b6\u25c0\u25fb-\u25fe\u00a9\u00ae\u2122\u2139\udc04\u2600-\u26FF\u2b05\u2b06\u2b07\u2b1b\u2b1c\u2b50\u2b55\u231a\u231b\u2328\u23cf\u23e9-\u23f3\u23f8-\u23fa\udccf\u2935\u2934\u2190-\u21ff/.source + /\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D4-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C03\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D01-\u0D03\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF8\u1CF9\u1DC0-\u1DF5\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F/.source, tt = /0-9\u0660-\u0669\u06F0-\u06F9\u07C0-\u07C9\u0966-\u096F\u09E6-\u09EF\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0BE6-\u0BEF\u0C66-\u0C6F\u0CE6-\u0CEF\u0D66-\u0D6F\u0DE6-\u0DEF\u0E50-\u0E59\u0ED0-\u0ED9\u0F20-\u0F29\u1040-\u1049\u1090-\u1099\u17E0-\u17E9\u1810-\u1819\u1946-\u194F\u19D0-\u19D9\u1A80-\u1A89\u1A90-\u1A99\u1B50-\u1B59\u1BB0-\u1BB9\u1C40-\u1C49\u1C50-\u1C59\uA620-\uA629\uA8D0-\uA8D9\uA900-\uA909\uA9D0-\uA9D9\uA9F0-\uA9F9\uAA50-\uAA59\uABF0-\uABF9\uFF10-\uFF19/.source, st = et + tt, nt = et + tt, rt = "(?:[" + tt + "]{1,3}\\.){3}[" + tt + "]{1,3}", it = "[" + nt + "](?:[" + nt + "\\-]{0,61}[" + nt + "])?", at = function(e2) {
2138
+ return "(?=(" + it + "))\\" + e2;
2139
+ }, ot = function(e2) {
2140
+ return "(?:" + at(e2) + "(?:\\." + at(e2 + 1) + "){0,126}|" + rt + ")";
2141
+ }, ut = new RegExp("[" + nt + "]"), ct = /(?:xn--vermgensberatung-pwb|xn--vermgensberater-ctb|xn--clchc0ea0b2g2a9gcd|xn--w4r85el8fhu5dnra|northwesternmutual|travelersinsurance|vermögensberatung|xn--3oq18vl8pn36a|xn--5su34j936bgsg|xn--bck1b9a5dre4c|xn--mgbai9azgqp6j|xn--mgberp4a5d4ar|xn--xkc2dl3a5ee0h|vermögensberater|xn--fzys8d69uvgm|xn--mgba7c0bbn0a|xn--xkc2al3hye2a|americanexpress|kerryproperties|sandvikcoromant|xn--i1b6b1a6a2e|xn--kcrx77d1x4a|xn--lgbbat1ad8j|xn--mgba3a4f16a|xn--mgbaakc7dvf|xn--mgbc0a9azcg|xn--nqv7fs00ema|afamilycompany|americanfamily|bananarepublic|cancerresearch|cookingchannel|kerrylogistics|weatherchannel|xn--54b7fta0cc|xn--6qq986b3xl|xn--80aqecdr1a|xn--b4w605ferd|xn--fiq228c5hs|xn--h2breg3eve|xn--jlq61u9w7b|xn--mgba3a3ejt|xn--mgbaam7a8h|xn--mgbayh7gpa|xn--mgbb9fbpob|xn--mgbbh1a71e|xn--mgbca7dzdo|xn--mgbi4ecexp|xn--mgbx4cd0ab|xn--rvc1e0am3e|international|lifeinsurance|spreadbetting|travelchannel|wolterskluwer|xn--eckvdtc9d|xn--fpcrj9c3d|xn--fzc2c9e2c|xn--h2brj9c8c|xn--tiq49xqyj|xn--yfro4i67o|xn--ygbi2ammx|construction|lplfinancial|scholarships|versicherung|xn--3e0b707e|xn--45br5cyl|xn--80adxhks|xn--80asehdb|xn--8y0a063a|xn--gckr3f0f|xn--mgb9awbf|xn--mgbab2bd|xn--mgbgu82a|xn--mgbpl2fh|xn--mgbt3dhd|xn--mk1bu44c|xn--ngbc5azd|xn--ngbe9e0a|xn--ogbpf8fl|xn--qcka1pmc|accountants|barclaycard|blackfriday|blockbuster|bridgestone|calvinklein|contractors|creditunion|engineering|enterprises|foodnetwork|investments|kerryhotels|lamborghini|motorcycles|olayangroup|photography|playstation|productions|progressive|redumbrella|rightathome|williamhill|xn--11b4c3d|xn--1ck2e1b|xn--1qqw23a|xn--2scrj9c|xn--3bst00m|xn--3ds443g|xn--3hcrj9c|xn--42c2d9a|xn--45brj9c|xn--55qw42g|xn--6frz82g|xn--80ao21a|xn--9krt00a|xn--cck2b3b|xn--czr694b|xn--d1acj3b|xn--efvy88h|xn--estv75g|xn--fct429k|xn--fjq720a|xn--flw351e|xn--g2xx48c|xn--gecrj9c|xn--gk3at1e|xn--h2brj9c|xn--hxt814e|xn--imr513n|xn--j6w193g|xn--jvr189m|xn--kprw13d|xn--kpry57d|xn--kpu716f|xn--mgbbh1a|xn--mgbtx2b|xn--mix891f|xn--nyqy26a|xn--otu796d|xn--pbt977c|xn--pgbs0dh|xn--q9jyb4c|xn--rhqv96g|xn--rovu88b|xn--s9brj9c|xn--ses554g|xn--t60b56a|xn--vuq861b|xn--w4rs40l|xn--xhq521b|xn--zfr164b|சிங்கப்பூர்|accountant|apartments|associates|basketball|bnpparibas|boehringer|capitalone|consulting|creditcard|cuisinella|eurovision|extraspace|foundation|healthcare|immobilien|industries|management|mitsubishi|nationwide|newholland|nextdirect|onyourside|properties|protection|prudential|realestate|republican|restaurant|schaeffler|swiftcover|tatamotors|technology|telefonica|university|vistaprint|vlaanderen|volkswagen|xn--30rr7y|xn--3pxu8k|xn--45q11c|xn--4gbrim|xn--55qx5d|xn--5tzm5g|xn--80aswg|xn--90a3ac|xn--9dbq2a|xn--9et52u|xn--c2br7g|xn--cg4bki|xn--czrs0t|xn--czru2d|xn--fiq64b|xn--fiqs8s|xn--fiqz9s|xn--io0a7i|xn--kput3i|xn--mxtq1m|xn--o3cw4h|xn--pssy2u|xn--unup4y|xn--wgbh1c|xn--wgbl6a|xn--y9a3aq|accenture|alfaromeo|allfinanz|amsterdam|analytics|aquarelle|barcelona|bloomberg|christmas|community|directory|education|equipment|fairwinds|financial|firestone|fresenius|frontdoor|fujixerox|furniture|goldpoint|hisamitsu|homedepot|homegoods|homesense|honeywell|institute|insurance|kuokgroup|ladbrokes|lancaster|landrover|lifestyle|marketing|marshalls|melbourne|microsoft|panasonic|passagens|pramerica|richardli|scjohnson|shangrila|solutions|statebank|statefarm|stockholm|travelers|vacations|xn--90ais|xn--c1avg|xn--d1alf|xn--e1a4c|xn--fhbei|xn--j1aef|xn--j1amh|xn--l1acc|xn--ngbrx|xn--nqv7f|xn--p1acf|xn--tckwe|xn--vhquv|yodobashi|abudhabi|airforce|allstate|attorney|barclays|barefoot|bargains|baseball|boutique|bradesco|broadway|brussels|budapest|builders|business|capetown|catering|catholic|chrysler|cipriani|cityeats|cleaning|clinique|clothing|commbank|computer|delivery|deloitte|democrat|diamonds|discount|discover|download|engineer|ericsson|esurance|etisalat|everbank|exchange|feedback|fidelity|firmdale|football|frontier|goodyear|grainger|graphics|guardian|hdfcbank|helsinki|holdings|hospital|infiniti|ipiranga|istanbul|jpmorgan|lighting|lundbeck|marriott|maserati|mckinsey|memorial|merckmsd|mortgage|movistar|observer|partners|pharmacy|pictures|plumbing|property|redstone|reliance|saarland|samsclub|security|services|shopping|showtime|softbank|software|stcgroup|supplies|symantec|training|uconnect|vanguard|ventures|verisign|woodside|xn--90ae|xn--node|xn--p1ai|xn--qxam|yokohama|السعودية|abogado|academy|agakhan|alibaba|android|athleta|auction|audible|auspost|avianca|banamex|bauhaus|bentley|bestbuy|booking|brother|bugatti|capital|caravan|careers|cartier|channel|charity|chintai|citadel|clubmed|college|cologne|comcast|company|compare|contact|cooking|corsica|country|coupons|courses|cricket|cruises|dentist|digital|domains|exposed|express|farmers|fashion|ferrari|ferrero|finance|fishing|fitness|flights|florist|flowers|forsale|frogans|fujitsu|gallery|genting|godaddy|grocery|guitars|hamburg|hangout|hitachi|holiday|hosting|hoteles|hotmail|hyundai|iselect|ismaili|jewelry|juniper|kitchen|komatsu|lacaixa|lancome|lanxess|lasalle|latrobe|leclerc|liaison|limited|lincoln|markets|metlife|monster|netbank|netflix|network|neustar|okinawa|oldnavy|organic|origins|philips|pioneer|politie|realtor|recipes|rentals|reviews|rexroth|samsung|sandvik|schmidt|schwarz|science|shiksha|shriram|singles|staples|starhub|storage|support|surgery|systems|temasek|theater|theatre|tickets|tiffany|toshiba|trading|walmart|wanggou|watches|weather|website|wedding|whoswho|windows|winners|xfinity|yamaxun|youtube|zuerich|католик|اتصالات|الجزائر|العليان|پاکستان|كاثوليك|موبايلي|இந்தியா|abarth|abbott|abbvie|active|africa|agency|airbus|airtel|alipay|alsace|alstom|anquan|aramco|author|bayern|beauty|berlin|bharti|blanco|bostik|boston|broker|camera|career|caseih|casino|center|chanel|chrome|church|circle|claims|clinic|coffee|comsec|condos|coupon|credit|cruise|dating|datsun|dealer|degree|dental|design|direct|doctor|dunlop|dupont|durban|emerck|energy|estate|events|expert|family|flickr|futbol|gallup|garden|george|giving|global|google|gratis|health|hermes|hiphop|hockey|hotels|hughes|imamat|insure|intuit|jaguar|joburg|juegos|kaufen|kinder|kindle|kosher|lancia|latino|lawyer|lefrak|living|locker|london|luxury|madrid|maison|makeup|market|mattel|mobile|mobily|monash|mormon|moscow|museum|mutual|nagoya|natura|nissan|nissay|norton|nowruz|office|olayan|online|oracle|orange|otsuka|pfizer|photos|physio|piaget|pictet|quebec|racing|realty|reisen|repair|report|review|rocher|rogers|ryukyu|safety|sakura|sanofi|school|schule|search|secure|select|shouji|soccer|social|stream|studio|supply|suzuki|swatch|sydney|taipei|taobao|target|tattoo|tennis|tienda|tjmaxx|tkmaxx|toyota|travel|unicom|viajes|viking|villas|virgin|vision|voting|voyage|vuelos|walter|warman|webcam|xihuan|yachts|yandex|zappos|москва|онлайн|ابوظبي|ارامكو|الاردن|المغرب|امارات|فلسطين|مليسيا|भारतम्|இலங்கை|ファッション|actor|adult|aetna|amfam|amica|apple|archi|audio|autos|azure|baidu|beats|bible|bingo|black|boats|bosch|build|canon|cards|chase|cheap|cisco|citic|click|cloud|coach|codes|crown|cymru|dabur|dance|deals|delta|dodge|drive|dubai|earth|edeka|email|epost|epson|faith|fedex|final|forex|forum|gallo|games|gifts|gives|glade|glass|globo|gmail|green|gripe|group|gucci|guide|homes|honda|horse|house|hyatt|ikano|intel|irish|iveco|jetzt|koeln|kyoto|lamer|lease|legal|lexus|lilly|linde|lipsy|lixil|loans|locus|lotte|lotto|lupin|macys|mango|media|miami|money|mopar|movie|nadex|nexus|nikon|ninja|nokia|nowtv|omega|osaka|paris|parts|party|phone|photo|pizza|place|poker|praxi|press|prime|promo|quest|radio|rehab|reise|ricoh|rocks|rodeo|rugby|salon|sener|seven|sharp|shell|shoes|skype|sling|smart|smile|solar|space|sport|stada|store|study|style|sucks|swiss|tatar|tires|tirol|tmall|today|tokyo|tools|toray|total|tours|trade|trust|tunes|tushu|ubank|vegas|video|vodka|volvo|wales|watch|weber|weibo|works|world|xerox|yahoo|zippo|ایران|بازار|بھارت|سودان|سورية|همراه|भारोत|संगठन|বাংলা|భారత్|ഭാരതം|嘉里大酒店|aarp|able|adac|aero|aigo|akdn|ally|amex|arab|army|arpa|arte|asda|asia|audi|auto|baby|band|bank|bbva|beer|best|bike|bing|blog|blue|bofa|bond|book|buzz|cafe|call|camp|care|cars|casa|case|cash|cbre|cern|chat|citi|city|club|cool|coop|cyou|data|date|dclk|deal|dell|desi|diet|dish|docs|doha|duck|duns|dvag|erni|fage|fail|fans|farm|fast|fiat|fido|film|fire|fish|flir|food|ford|free|fund|game|gbiz|gent|ggee|gift|gmbh|gold|golf|goog|guge|guru|hair|haus|hdfc|help|here|hgtv|host|hsbc|icbc|ieee|imdb|immo|info|itau|java|jeep|jobs|jprs|kddi|kiwi|kpmg|kred|land|lego|lgbt|lidl|life|like|limo|link|live|loan|loft|love|ltda|luxe|maif|meet|meme|menu|mini|mint|mobi|moda|moto|name|navy|news|next|nico|nike|ollo|open|page|pars|pccw|pics|ping|pink|play|plus|pohl|porn|post|prod|prof|qpon|raid|read|reit|rent|rest|rich|rmit|room|rsvp|ruhr|safe|sale|sarl|save|saxo|scor|scot|seat|seek|sexy|shaw|shia|shop|show|silk|sina|site|skin|sncf|sohu|song|sony|spot|star|surf|talk|taxi|team|tech|teva|tiaa|tips|town|toys|tube|vana|visa|viva|vivo|vote|voto|wang|weir|wien|wiki|wine|work|xbox|yoga|zara|zero|zone|дети|сайт|بارت|بيتك|ڀارت|تونس|شبكة|عراق|عمان|موقع|भारत|ভারত|ভাৰত|ਭਾਰਤ|ભારત|ଭାରତ|ಭಾರತ|ලංකා|グーグル|クラウド|ポイント|大众汽车|组织机构|電訊盈科|香格里拉|aaa|abb|abc|aco|ads|aeg|afl|aig|anz|aol|app|art|aws|axa|bar|bbc|bbt|bcg|bcn|bet|bid|bio|biz|bms|bmw|bnl|bom|boo|bot|box|buy|bzh|cab|cal|cam|car|cat|cba|cbn|cbs|ceb|ceo|cfa|cfd|com|crs|csc|dad|day|dds|dev|dhl|diy|dnp|dog|dot|dtv|dvr|eat|eco|edu|esq|eus|fan|fit|fly|foo|fox|frl|ftr|fun|fyi|gal|gap|gdn|gea|gle|gmo|gmx|goo|gop|got|gov|hbo|hiv|hkt|hot|how|ibm|ice|icu|ifm|inc|ing|ink|int|ist|itv|jcb|jcp|jio|jll|jmp|jnj|jot|joy|kfh|kia|kim|kpn|krd|lat|law|lds|llc|lol|lpl|ltd|man|map|mba|med|men|mil|mit|mlb|mls|mma|moe|moi|mom|mov|msd|mtn|mtr|nab|nba|nec|net|new|nfl|ngo|nhk|now|nra|nrw|ntt|nyc|obi|off|one|ong|onl|ooo|org|ott|ovh|pay|pet|phd|pid|pin|pnc|pro|pru|pub|pwc|qvc|red|ren|ril|rio|rip|run|rwe|sap|sas|sbi|sbs|sca|scb|ses|sew|sex|sfr|ski|sky|soy|srl|srt|stc|tab|tax|tci|tdk|tel|thd|tjx|top|trv|tui|tvs|ubs|uno|uol|ups|vet|vig|vin|vip|wed|win|wme|wow|wtc|wtf|xin|xxx|xyz|you|yun|zip|бел|ком|қаз|мкд|мон|орг|рус|срб|укр|հայ|קום|عرب|قطر|كوم|مصر|कॉम|नेट|คอม|ไทย|ストア|セール|みんな|中文网|天主教|我爱你|新加坡|淡马锡|诺基亚|飞利浦|ac|ad|ae|af|ag|ai|al|am|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw|ελ|бг|ею|рф|გე|닷넷|닷컴|삼성|한국|コム|世界|中信|中国|中國|企业|佛山|信息|健康|八卦|公司|公益|台湾|台灣|商城|商店|商标|嘉里|在线|大拿|娱乐|家電|工行|广东|微博|慈善|手机|手表|招聘|政务|政府|新闻|时尚|書籍|机构|游戏|澳門|点看|珠宝|移动|网址|网店|网站|网络|联通|谷歌|购物|通販|集团|食品|餐厅|香港)/, lt = new RegExp("[" + nt + "!#$%&'*+/=?^_`{|}~-]"), ht = new RegExp("^" + ct.source + "$"), dt = function(e2) {
2142
+ function t2() {
2143
+ var t3 = null !== e2 && e2.apply(this, arguments) || this;
2144
+ return t3.localPartCharRegex = lt, t3.strictTldRegex = ht, t3;
2145
+ }
2146
+ return Ue(t2, e2), t2.prototype.parseMatches = function(e3) {
2147
+ for (var t3 = this.tagBuilder, s2 = this.localPartCharRegex, n2 = this.strictTldRegex, r2 = [], i2 = e3.length, a2 = new pt(), o2 = { m: "a", a: "i", i: "l", l: "t", t: "o", o: ":" }, u2 = 0, c2 = 0, l2 = a2; u2 < i2; ) {
2148
+ var h2 = e3.charAt(u2);
2149
+ switch (c2) {
2150
+ case 0:
2151
+ d2(h2);
2152
+ break;
2153
+ case 1:
2154
+ p2(e3.charAt(u2 - 1), h2);
2155
+ break;
2156
+ case 2:
2157
+ f2(h2);
2158
+ break;
2159
+ case 3:
2160
+ m2(h2);
2161
+ break;
2162
+ case 4:
2163
+ g2(h2);
2164
+ break;
2165
+ case 5:
2166
+ v2(h2);
2167
+ break;
2168
+ case 6:
2169
+ b2(h2);
2170
+ break;
2171
+ case 7:
2172
+ w2(h2);
2173
+ break;
2174
+ default:
2175
+ Re(c2);
2176
+ }
2177
+ u2++;
2178
+ }
2179
+ return C2(), r2;
2180
+ function d2(e4) {
2181
+ "m" === e4 ? y2(1) : s2.test(e4) && y2();
2182
+ }
2183
+ function p2(e4, t4) {
2184
+ ":" === e4 ? s2.test(t4) ? (c2 = 2, l2 = new pt($e($e({}, l2), { hasMailtoPrefix: true }))) : A2() : o2[e4] === t4 || (s2.test(t4) ? c2 = 2 : "." === t4 ? c2 = 3 : "@" === t4 ? c2 = 4 : A2());
2185
+ }
2186
+ function f2(e4) {
2187
+ "." === e4 ? c2 = 3 : "@" === e4 ? c2 = 4 : s2.test(e4) || A2();
2188
+ }
2189
+ function m2(e4) {
2190
+ "." === e4 || "@" === e4 ? A2() : s2.test(e4) ? c2 = 2 : A2();
2191
+ }
2192
+ function g2(e4) {
2193
+ ut.test(e4) ? c2 = 5 : A2();
2194
+ }
2195
+ function v2(e4) {
2196
+ "." === e4 ? c2 = 7 : "-" === e4 ? c2 = 6 : ut.test(e4) || C2();
2197
+ }
2198
+ function b2(e4) {
2199
+ "-" === e4 || "." === e4 ? C2() : ut.test(e4) ? c2 = 5 : C2();
2200
+ }
2201
+ function w2(e4) {
2202
+ "." === e4 || "-" === e4 ? C2() : ut.test(e4) ? (c2 = 5, l2 = new pt($e($e({}, l2), { hasDomainDot: true }))) : C2();
2203
+ }
2204
+ function y2(e4) {
2205
+ void 0 === e4 && (e4 = 2), c2 = e4, l2 = new pt({ idx: u2 });
2206
+ }
2207
+ function A2() {
2208
+ c2 = 0, l2 = a2;
2209
+ }
2210
+ function C2() {
2211
+ if (l2.hasDomainDot) {
2212
+ var s3 = e3.slice(l2.idx, u2);
2213
+ /[-.]$/.test(s3) && (s3 = s3.slice(0, -1));
2214
+ var i3 = l2.hasMailtoPrefix ? s3.slice(7) : s3;
2215
+ (function(e4) {
2216
+ var t4 = e4.split(".").pop() || "", s4 = t4.toLowerCase();
2217
+ return n2.test(s4);
2218
+ })(i3) && r2.push(new We({ tagBuilder: t3, matchedText: s3, offset: l2.idx, email: i3 }));
2219
+ }
2220
+ A2();
2221
+ }
2222
+ }, t2;
2223
+ }(ze), pt = function(e2) {
2224
+ void 0 === e2 && (e2 = {}), this.idx = void 0 !== e2.idx ? e2.idx : -1, this.hasMailtoPrefix = !!e2.hasMailtoPrefix, this.hasDomainDot = !!e2.hasDomainDot;
2225
+ }, ft = function() {
2226
+ function e2() {
2227
+ }
2228
+ return e2.isValid = function(e3, t2) {
2229
+ return !(t2 && !this.isValidUriScheme(t2) || this.urlMatchDoesNotHaveProtocolOrDot(e3, t2) || this.urlMatchDoesNotHaveAtLeastOneWordChar(e3, t2) && !this.isValidIpAddress(e3) || this.containsMultipleDots(e3));
2230
+ }, e2.isValidIpAddress = function(e3) {
2231
+ var t2 = new RegExp(this.hasFullProtocolRegex.source + this.ipRegex.source);
2232
+ return null !== e3.match(t2);
2233
+ }, e2.containsMultipleDots = function(e3) {
2234
+ var t2 = e3;
2235
+ return this.hasFullProtocolRegex.test(e3) && (t2 = e3.split("://")[1]), t2.split("/")[0].indexOf("..") > -1;
2236
+ }, e2.isValidUriScheme = function(e3) {
2237
+ var t2 = e3.match(this.uriSchemeRegex), s2 = t2 && t2[0].toLowerCase();
2238
+ return "javascript:" !== s2 && "vbscript:" !== s2;
2239
+ }, e2.urlMatchDoesNotHaveProtocolOrDot = function(e3, t2) {
2240
+ return !(!e3 || t2 && this.hasFullProtocolRegex.test(t2) || -1 !== e3.indexOf("."));
2241
+ }, e2.urlMatchDoesNotHaveAtLeastOneWordChar = function(e3, t2) {
2242
+ return !(!e3 || !t2) && (!this.hasFullProtocolRegex.test(t2) && !this.hasWordCharAfterProtocolRegex.test(e3));
2243
+ }, e2.hasFullProtocolRegex = /^[A-Za-z][-.+A-Za-z0-9]*:\/\//, e2.uriSchemeRegex = /^[A-Za-z][-.+A-Za-z0-9]*:/, e2.hasWordCharAfterProtocolRegex = new RegExp(":[^\\s]*?[" + Xe + "]"), e2.ipRegex = /[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?(:[0-9]*)?\/?$/, e2;
2244
+ }(), mt = (je = new RegExp("[/?#](?:[" + nt + "\\-+&@#/%=~_()|'$*\\[\\]{}?!:,.;^✓]*[" + nt + "\\-+&@#/%=~_()|'$*\\[\\]{}✓])?"), new RegExp(["(?:", "(", /(?:[A-Za-z][-.+A-Za-z0-9]{0,63}:(?![A-Za-z][-.+A-Za-z0-9]{0,63}:\/\/)(?!\d+\/?)(?:\/\/)?)/.source, ot(2), ")", "|", "(", "(//)?", /(?:www\.)/.source, ot(6), ")", "|", "(", "(//)?", ot(10) + "\\.", ct.source, "(?![-" + st + "])", ")", ")", "(?::[0-9]+)?", "(?:" + je.source + ")?"].join(""), "gi")), gt = new RegExp("[" + nt + "]"), vt = function(e2) {
2245
+ function t2(t3) {
2246
+ var s2 = e2.call(this, t3) || this;
2247
+ return s2.stripPrefix = { scheme: true, www: true }, s2.stripTrailingSlash = true, s2.decodePercentEncoding = true, s2.matcherRegex = mt, s2.wordCharRegExp = gt, s2.stripPrefix = t3.stripPrefix, s2.stripTrailingSlash = t3.stripTrailingSlash, s2.decodePercentEncoding = t3.decodePercentEncoding, s2;
2248
+ }
2249
+ return Ue(t2, e2), t2.prototype.parseMatches = function(e3) {
2250
+ for (var t3, s2 = this.matcherRegex, n2 = this.stripPrefix, r2 = this.stripTrailingSlash, i2 = this.decodePercentEncoding, a2 = this.tagBuilder, o2 = [], u2 = function() {
2251
+ var s3 = t3[0], u3 = t3[1], l2 = t3[4], h2 = t3[5], d2 = t3[9], p2 = t3.index, f2 = h2 || d2, m2 = e3.charAt(p2 - 1);
2252
+ if (!ft.isValid(s3, u3)) return "continue";
2253
+ if (p2 > 0 && "@" === m2) return "continue";
2254
+ if (p2 > 0 && f2 && c2.wordCharRegExp.test(m2)) return "continue";
2255
+ if (/\?$/.test(s3) && (s3 = s3.substr(0, s3.length - 1)), c2.matchHasUnbalancedClosingParen(s3)) s3 = s3.substr(0, s3.length - 1);
2256
+ else {
2257
+ var g2 = c2.matchHasInvalidCharAfterTld(s3, u3);
2258
+ g2 > -1 && (s3 = s3.substr(0, g2));
2259
+ }
2260
+ var v2 = ["http://", "https://"].find(function(e4) {
2261
+ return !!u3 && -1 !== u3.indexOf(e4);
2262
+ });
2263
+ if (v2) {
2264
+ var b2 = s3.indexOf(v2);
2265
+ s3 = s3.substr(b2), u3 = u3.substr(b2), p2 += b2;
2266
+ }
2267
+ var w2 = u3 ? "scheme" : l2 ? "www" : "tld", y2 = !!u3;
2268
+ o2.push(new Le({ tagBuilder: a2, matchedText: s3, offset: p2, urlMatchType: w2, url: s3, protocolUrlMatch: y2, protocolRelativeMatch: !!f2, stripPrefix: n2, stripTrailingSlash: r2, decodePercentEncoding: i2 }));
2269
+ }, c2 = this; null !== (t3 = s2.exec(e3)); ) u2();
2270
+ return o2;
2271
+ }, t2.prototype.matchHasUnbalancedClosingParen = function(e3) {
2272
+ var t3, s2 = e3.charAt(e3.length - 1);
2273
+ if (")" === s2) t3 = "(";
2274
+ else if ("]" === s2) t3 = "[";
2275
+ else {
2276
+ if ("}" !== s2) return false;
2277
+ t3 = "{";
2278
+ }
2279
+ for (var n2 = 0, r2 = 0, i2 = e3.length - 1; r2 < i2; r2++) {
2280
+ var a2 = e3.charAt(r2);
2281
+ a2 === t3 ? n2++ : a2 === s2 && (n2 = Math.max(n2 - 1, 0));
2282
+ }
2283
+ return 0 === n2;
2284
+ }, t2.prototype.matchHasInvalidCharAfterTld = function(e3, t3) {
2285
+ if (!e3) return -1;
2286
+ var s2 = 0;
2287
+ t3 && (s2 = e3.indexOf(":"), e3 = e3.slice(s2));
2288
+ var n2 = new RegExp("^((.?//)?[-." + nt + "]*[-" + nt + "]\\.[-" + nt + "]+)").exec(e3);
2289
+ return null === n2 ? -1 : (s2 += n2[1].length, e3 = e3.slice(n2[1].length), /^[^-.A-Za-z0-9:\/?#]/.test(e3) ? s2 : -1);
2290
+ }, t2;
2291
+ }(ze), bt = new RegExp("#[_" + nt + "]{1,139}(?![_" + nt + "])", "g"), wt = new RegExp("[^" + nt + "]"), yt = function(e2) {
2292
+ function t2(t3) {
2293
+ var s2 = e2.call(this, t3) || this;
2294
+ return s2.serviceName = "twitter", s2.matcherRegex = bt, s2.nonWordCharRegex = wt, s2.serviceName = t3.serviceName, s2;
2295
+ }
2296
+ return Ue(t2, e2), t2.prototype.parseMatches = function(e3) {
2297
+ for (var t3, s2 = this.matcherRegex, n2 = this.nonWordCharRegex, r2 = this.serviceName, i2 = this.tagBuilder, a2 = []; null !== (t3 = s2.exec(e3)); ) {
2298
+ var o2 = t3.index, u2 = e3.charAt(o2 - 1);
2299
+ if (0 === o2 || n2.test(u2)) {
2300
+ var c2 = t3[0], l2 = t3[0].slice(1);
2301
+ a2.push(new qe({ tagBuilder: i2, matchedText: c2, offset: o2, serviceName: r2, hashtag: l2 }));
2302
+ }
2303
+ }
2304
+ return a2;
2305
+ }, t2;
2306
+ }(ze), At = new RegExp(/(?:(?:(?:(\+)?\d{1,3}[-\040.]?)?\(?\d{3}\)?[-\040.]?\d{3}[-\040.]?\d{4})|(?:(\+)(?:9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)[-\040.]?(?:\d[-\040.]?){6,12}\d+))([,;]+[0-9]+#?)*/.source + "|" + /(0([1-9]{1}-?[1-9]\d{3}|[1-9]{2}-?\d{3}|[1-9]{2}\d{1}-?\d{2}|[1-9]{2}\d{2}-?\d{1})-?\d{4}|0[789]0-?\d{4}-?\d{4}|050-?\d{4}-?\d{4})/.source, "g"), Ct = function(e2) {
2307
+ function t2() {
2308
+ var t3 = null !== e2 && e2.apply(this, arguments) || this;
2309
+ return t3.matcherRegex = At, t3;
2310
+ }
2311
+ return Ue(t2, e2), t2.prototype.parseMatches = function(e3) {
2312
+ for (var t3, s2 = this.matcherRegex, n2 = this.tagBuilder, r2 = []; null !== (t3 = s2.exec(e3)); ) {
2313
+ var i2 = t3[0], a2 = i2.replace(/[^0-9,;#]/g, ""), o2 = !(!t3[1] && !t3[2]), u2 = 0 == t3.index ? "" : e3.substr(t3.index - 1, 1), c2 = e3.substr(t3.index + i2.length, 1), l2 = !u2.match(/\d/) && !c2.match(/\d/);
2314
+ this.testMatch(t3[3]) && this.testMatch(i2) && l2 && r2.push(new Ge({ tagBuilder: n2, matchedText: i2, offset: t3.index, number: a2, plusSign: o2 }));
2315
+ }
2316
+ return r2;
2317
+ }, t2.prototype.testMatch = function(e3) {
2318
+ return Qe.test(e3);
2319
+ }, t2;
2320
+ }(ze), Et = new RegExp("@[_" + nt + "]{1,50}(?![_" + nt + "])", "g"), kt = new RegExp("@[_." + nt + "]{1,30}(?![_" + nt + "])", "g"), xt = new RegExp("@[-_." + nt + "]{1,50}(?![-_" + nt + "])", "g"), St = new RegExp("[^" + nt + "]"), Tt = function(e2) {
2321
+ function t2(t3) {
2322
+ var s2 = e2.call(this, t3) || this;
2323
+ return s2.serviceName = "twitter", s2.matcherRegexes = { twitter: Et, instagram: kt, soundcloud: xt }, s2.nonWordCharRegex = St, s2.serviceName = t3.serviceName, s2;
2324
+ }
2325
+ return Ue(t2, e2), t2.prototype.parseMatches = function(e3) {
2326
+ var t3, s2 = this.serviceName, n2 = this.matcherRegexes[this.serviceName], r2 = this.nonWordCharRegex, i2 = this.tagBuilder, a2 = [];
2327
+ if (!n2) return a2;
2328
+ for (; null !== (t3 = n2.exec(e3)); ) {
2329
+ var o2 = t3.index, u2 = e3.charAt(o2 - 1);
2330
+ if (0 === o2 || r2.test(u2)) {
2331
+ var c2 = t3[0].replace(/\.+$/g, ""), l2 = c2.slice(1);
2332
+ a2.push(new He({ tagBuilder: i2, matchedText: c2, offset: o2, serviceName: s2, mention: l2 }));
2333
+ }
2334
+ }
2335
+ return a2;
2336
+ }, t2;
2337
+ }(ze);
2338
+ function Dt(e2, t2) {
2339
+ for (var s2, n2 = t2.onOpenTag, r2 = t2.onCloseTag, i2 = t2.onText, a2 = t2.onComment, o2 = t2.onDoctype, u2 = new It(), c2 = 0, l2 = e2.length, h2 = 0, d2 = 0, p2 = u2; c2 < l2; ) {
2340
+ var f2 = e2.charAt(c2);
2341
+ switch (h2) {
2342
+ case 0:
2343
+ m2(f2);
2344
+ break;
2345
+ case 1:
2346
+ g2(f2);
2347
+ break;
2348
+ case 2:
2349
+ b2(f2);
2350
+ break;
2351
+ case 3:
2352
+ v2(f2);
2353
+ break;
2354
+ case 4:
2355
+ w2(f2);
2356
+ break;
2357
+ case 5:
2358
+ y2(f2);
2359
+ break;
2360
+ case 6:
2361
+ A2(f2);
2362
+ break;
2363
+ case 7:
2364
+ C2(f2);
2365
+ break;
2366
+ case 8:
2367
+ E2(f2);
2368
+ break;
2369
+ case 9:
2370
+ k2(f2);
2371
+ break;
2372
+ case 10:
2373
+ x2(f2);
2374
+ break;
2375
+ case 11:
2376
+ S2(f2);
2377
+ break;
2378
+ case 12:
2379
+ T2(f2);
2380
+ break;
2381
+ case 13:
2382
+ D2();
2383
+ break;
2384
+ case 14:
2385
+ I2(f2);
2386
+ break;
2387
+ case 15:
2388
+ F2(f2);
2389
+ break;
2390
+ case 16:
2391
+ B2(f2);
2392
+ break;
2393
+ case 17:
2394
+ M2(f2);
2395
+ break;
2396
+ case 18:
2397
+ R2(f2);
2398
+ break;
2399
+ case 19:
2400
+ N2(f2);
2401
+ break;
2402
+ case 20:
2403
+ _2(f2);
2404
+ break;
2405
+ default:
2406
+ Re(h2);
2407
+ }
2408
+ c2++;
2409
+ }
2410
+ function m2(e3) {
2411
+ "<" === e3 && O2();
2412
+ }
2413
+ function g2(e3) {
2414
+ "!" === e3 ? h2 = 13 : "/" === e3 ? (h2 = 2, p2 = new It($e($e({}, p2), { isClosing: true }))) : "<" === e3 ? O2() : Je.test(e3) ? (h2 = 3, p2 = new It($e($e({}, p2), { isOpening: true }))) : (h2 = 0, p2 = u2);
2415
+ }
2416
+ function v2(e3) {
2417
+ Ve.test(e3) ? (p2 = new It($e($e({}, p2), { name: j2() })), h2 = 4) : "<" === e3 ? O2() : "/" === e3 ? (p2 = new It($e($e({}, p2), { name: j2() })), h2 = 12) : ">" === e3 ? (p2 = new It($e($e({}, p2), { name: j2() })), U2()) : Je.test(e3) || Ye.test(e3) || ":" === e3 || P2();
2418
+ }
2419
+ function b2(e3) {
2420
+ ">" === e3 ? P2() : Je.test(e3) ? h2 = 3 : P2();
2421
+ }
2422
+ function w2(e3) {
2423
+ Ve.test(e3) || ("/" === e3 ? h2 = 12 : ">" === e3 ? U2() : "<" === e3 ? O2() : "=" === e3 || Ze.test(e3) || Ke.test(e3) ? P2() : h2 = 5);
2424
+ }
2425
+ function y2(e3) {
2426
+ Ve.test(e3) ? h2 = 6 : "/" === e3 ? h2 = 12 : "=" === e3 ? h2 = 7 : ">" === e3 ? U2() : "<" === e3 ? O2() : Ze.test(e3) && P2();
2427
+ }
2428
+ function A2(e3) {
2429
+ Ve.test(e3) || ("/" === e3 ? h2 = 12 : "=" === e3 ? h2 = 7 : ">" === e3 ? U2() : "<" === e3 ? O2() : Ze.test(e3) ? P2() : h2 = 5);
2430
+ }
2431
+ function C2(e3) {
2432
+ Ve.test(e3) || ('"' === e3 ? h2 = 8 : "'" === e3 ? h2 = 9 : /[>=`]/.test(e3) ? P2() : "<" === e3 ? O2() : h2 = 10);
2433
+ }
2434
+ function E2(e3) {
2435
+ '"' === e3 && (h2 = 11);
2436
+ }
2437
+ function k2(e3) {
2438
+ "'" === e3 && (h2 = 11);
2439
+ }
2440
+ function x2(e3) {
2441
+ Ve.test(e3) ? h2 = 4 : ">" === e3 ? U2() : "<" === e3 && O2();
2442
+ }
2443
+ function S2(e3) {
2444
+ Ve.test(e3) ? h2 = 4 : "/" === e3 ? h2 = 12 : ">" === e3 ? U2() : "<" === e3 ? O2() : (h2 = 4, c2--);
2445
+ }
2446
+ function T2(e3) {
2447
+ ">" === e3 ? (p2 = new It($e($e({}, p2), { isClosing: true })), U2()) : h2 = 4;
2448
+ }
2449
+ function D2(t3) {
2450
+ "--" === e2.substr(c2, 2) ? (c2 += 2, p2 = new It($e($e({}, p2), { type: "comment" })), h2 = 14) : "DOCTYPE" === e2.substr(c2, 7).toUpperCase() ? (c2 += 7, p2 = new It($e($e({}, p2), { type: "doctype" })), h2 = 20) : P2();
2451
+ }
2452
+ function I2(e3) {
2453
+ "-" === e3 ? h2 = 15 : ">" === e3 ? P2() : h2 = 16;
2454
+ }
2455
+ function F2(e3) {
2456
+ "-" === e3 ? h2 = 18 : ">" === e3 ? P2() : h2 = 16;
2457
+ }
2458
+ function B2(e3) {
2459
+ "-" === e3 && (h2 = 17);
2460
+ }
2461
+ function M2(e3) {
2462
+ h2 = "-" === e3 ? 18 : 16;
2463
+ }
2464
+ function R2(e3) {
2465
+ ">" === e3 ? U2() : "!" === e3 ? h2 = 19 : "-" === e3 || (h2 = 16);
2466
+ }
2467
+ function N2(e3) {
2468
+ "-" === e3 ? h2 = 17 : ">" === e3 ? U2() : h2 = 16;
2469
+ }
2470
+ function _2(e3) {
2471
+ ">" === e3 ? U2() : "<" === e3 && O2();
2472
+ }
2473
+ function P2() {
2474
+ h2 = 0, p2 = u2;
2475
+ }
2476
+ function O2() {
2477
+ h2 = 1, p2 = new It({ idx: c2 });
2478
+ }
2479
+ function U2() {
2480
+ var t3 = e2.slice(d2, p2.idx);
2481
+ t3 && i2(t3, d2), "comment" === p2.type ? a2(p2.idx) : "doctype" === p2.type ? o2(p2.idx) : (p2.isOpening && n2(p2.name, p2.idx), p2.isClosing && r2(p2.name, p2.idx)), P2(), d2 = c2 + 1;
2482
+ }
2483
+ function j2() {
2484
+ var t3 = p2.idx + (p2.isClosing ? 2 : 1);
2485
+ return e2.slice(t3, c2).toLowerCase();
2486
+ }
2487
+ d2 < c2 && (s2 = e2.slice(d2, c2), i2(s2, d2), d2 = c2 + 1);
2488
+ }
2489
+ var It = function(e2) {
2490
+ void 0 === e2 && (e2 = {}), this.idx = void 0 !== e2.idx ? e2.idx : -1, this.type = e2.type || "tag", this.name = e2.name || "", this.isOpening = !!e2.isOpening, this.isClosing = !!e2.isClosing;
2491
+ }, Ft = function() {
2492
+ function e2(t2) {
2493
+ void 0 === t2 && (t2 = {}), this.version = e2.version, this.urls = {}, this.email = true, this.phone = true, this.hashtag = false, this.mention = false, this.newWindow = true, this.stripPrefix = { scheme: true, www: true }, this.stripTrailingSlash = true, this.decodePercentEncoding = true, this.truncate = { length: 0, location: "end" }, this.className = "", this.replaceFn = null, this.context = void 0, this.sanitizeHtml = false, this.matchers = null, this.tagBuilder = null, this.urls = this.normalizeUrlsCfg(t2.urls), this.email = "boolean" == typeof t2.email ? t2.email : this.email, this.phone = "boolean" == typeof t2.phone ? t2.phone : this.phone, this.hashtag = t2.hashtag || this.hashtag, this.mention = t2.mention || this.mention, this.newWindow = "boolean" == typeof t2.newWindow ? t2.newWindow : this.newWindow, this.stripPrefix = this.normalizeStripPrefixCfg(t2.stripPrefix), this.stripTrailingSlash = "boolean" == typeof t2.stripTrailingSlash ? t2.stripTrailingSlash : this.stripTrailingSlash, this.decodePercentEncoding = "boolean" == typeof t2.decodePercentEncoding ? t2.decodePercentEncoding : this.decodePercentEncoding, this.sanitizeHtml = t2.sanitizeHtml || false;
2494
+ var s2 = this.mention;
2495
+ if (false !== s2 && "twitter" !== s2 && "instagram" !== s2 && "soundcloud" !== s2) throw new Error("invalid `mention` cfg - see docs");
2496
+ var n2 = this.hashtag;
2497
+ if (false !== n2 && "twitter" !== n2 && "facebook" !== n2 && "instagram" !== n2) throw new Error("invalid `hashtag` cfg - see docs");
2498
+ this.truncate = this.normalizeTruncateCfg(t2.truncate), this.className = t2.className || this.className, this.replaceFn = t2.replaceFn || this.replaceFn, this.context = t2.context || this;
2499
+ }
2500
+ return e2.link = function(t2, s2) {
2501
+ return new e2(s2).link(t2);
2502
+ }, e2.parse = function(t2, s2) {
2503
+ return new e2(s2).parse(t2);
2504
+ }, e2.prototype.normalizeUrlsCfg = function(e3) {
2505
+ return null == e3 && (e3 = true), "boolean" == typeof e3 ? { schemeMatches: e3, wwwMatches: e3, tldMatches: e3 } : { schemeMatches: "boolean" != typeof e3.schemeMatches || e3.schemeMatches, wwwMatches: "boolean" != typeof e3.wwwMatches || e3.wwwMatches, tldMatches: "boolean" != typeof e3.tldMatches || e3.tldMatches };
2506
+ }, e2.prototype.normalizeStripPrefixCfg = function(e3) {
2507
+ return null == e3 && (e3 = true), "boolean" == typeof e3 ? { scheme: e3, www: e3 } : { scheme: "boolean" != typeof e3.scheme || e3.scheme, www: "boolean" != typeof e3.www || e3.www };
2508
+ }, e2.prototype.normalizeTruncateCfg = function(e3) {
2509
+ return "number" == typeof e3 ? { length: e3, location: "end" } : function(e4, t2) {
2510
+ for (var s2 in t2) t2.hasOwnProperty(s2) && void 0 === e4[s2] && (e4[s2] = t2[s2]);
2511
+ return e4;
2512
+ }(e3 || {}, { length: Number.POSITIVE_INFINITY, location: "end" });
2513
+ }, e2.prototype.parse = function(e3) {
2514
+ var t2 = this, s2 = ["a", "style", "script"], n2 = 0, r2 = [];
2515
+ return Dt(e3, { onOpenTag: function(e4) {
2516
+ s2.indexOf(e4) >= 0 && n2++;
2517
+ }, onText: function(e4, s3) {
2518
+ if (0 === n2) {
2519
+ var i2 = function(e5, t3) {
2520
+ if (!t3.global) throw new Error("`splitRegex` must have the 'g' flag set");
2521
+ for (var s4, n3 = [], r3 = 0; s4 = t3.exec(e5); ) n3.push(e5.substring(r3, s4.index)), n3.push(s4[0]), r3 = s4.index + s4[0].length;
2522
+ return n3.push(e5.substring(r3)), n3;
2523
+ }(e4, /(&nbsp;|&#160;|&lt;|&#60;|&gt;|&#62;|&quot;|&#34;|&#39;)/gi), a2 = s3;
2524
+ i2.forEach(function(e5, s4) {
2525
+ if (s4 % 2 == 0) {
2526
+ var n3 = t2.parseText(e5, a2);
2527
+ r2.push.apply(r2, n3);
2528
+ }
2529
+ a2 += e5.length;
2530
+ });
2531
+ }
2532
+ }, onCloseTag: function(e4) {
2533
+ s2.indexOf(e4) >= 0 && (n2 = Math.max(n2 - 1, 0));
2534
+ }, onComment: function(e4) {
2535
+ }, onDoctype: function(e4) {
2536
+ } }), r2 = this.compactMatches(r2), r2 = this.removeUnwantedMatches(r2);
2537
+ }, e2.prototype.compactMatches = function(e3) {
2538
+ e3.sort(function(e4, t3) {
2539
+ return e4.getOffset() - t3.getOffset();
2540
+ });
2541
+ for (var t2 = 0; t2 < e3.length - 1; t2++) {
2542
+ var s2 = e3[t2], n2 = s2.getOffset(), r2 = s2.getMatchedText().length, i2 = n2 + r2;
2543
+ if (t2 + 1 < e3.length) {
2544
+ if (e3[t2 + 1].getOffset() === n2) {
2545
+ var a2 = e3[t2 + 1].getMatchedText().length > r2 ? t2 : t2 + 1;
2546
+ e3.splice(a2, 1);
2547
+ continue;
2548
+ }
2549
+ e3[t2 + 1].getOffset() < i2 && e3.splice(t2 + 1, 1);
2550
+ }
2551
+ }
2552
+ return e3;
2553
+ }, e2.prototype.removeUnwantedMatches = function(e3) {
2554
+ return this.hashtag || Me(e3, function(e4) {
2555
+ return "hashtag" === e4.getType();
2556
+ }), this.email || Me(e3, function(e4) {
2557
+ return "email" === e4.getType();
2558
+ }), this.phone || Me(e3, function(e4) {
2559
+ return "phone" === e4.getType();
2560
+ }), this.mention || Me(e3, function(e4) {
2561
+ return "mention" === e4.getType();
2562
+ }), this.urls.schemeMatches || Me(e3, function(e4) {
2563
+ return "url" === e4.getType() && "scheme" === e4.getUrlMatchType();
2564
+ }), this.urls.wwwMatches || Me(e3, function(e4) {
2565
+ return "url" === e4.getType() && "www" === e4.getUrlMatchType();
2566
+ }), this.urls.tldMatches || Me(e3, function(e4) {
2567
+ return "url" === e4.getType() && "tld" === e4.getUrlMatchType();
2568
+ }), e3;
2569
+ }, e2.prototype.parseText = function(e3, t2) {
2570
+ void 0 === t2 && (t2 = 0), t2 = t2 || 0;
2571
+ for (var s2 = this.getMatchers(), n2 = [], r2 = 0, i2 = s2.length; r2 < i2; r2++) {
2572
+ for (var a2 = s2[r2].parseMatches(e3), o2 = 0, u2 = a2.length; o2 < u2; o2++) a2[o2].setOffset(t2 + a2[o2].getOffset());
2573
+ n2.push.apply(n2, a2);
2574
+ }
2575
+ return n2;
2576
+ }, e2.prototype.link = function(e3) {
2577
+ if (!e3) return "";
2578
+ this.sanitizeHtml && (e3 = e3.replace(/</g, "&lt;").replace(/>/g, "&gt;"));
2579
+ for (var t2 = this.parse(e3), s2 = [], n2 = 0, r2 = 0, i2 = t2.length; r2 < i2; r2++) {
2580
+ var a2 = t2[r2];
2581
+ s2.push(e3.substring(n2, a2.getOffset())), s2.push(this.createMatchReturnVal(a2)), n2 = a2.getOffset() + a2.getMatchedText().length;
2582
+ }
2583
+ return s2.push(e3.substring(n2)), s2.join("");
2584
+ }, e2.prototype.createMatchReturnVal = function(e3) {
2585
+ var t2;
2586
+ return this.replaceFn && (t2 = this.replaceFn.call(this.context, e3)), "string" == typeof t2 ? t2 : false === t2 ? e3.getMatchedText() : t2 instanceof Ne ? t2.toAnchorString() : e3.buildTag().toAnchorString();
2587
+ }, e2.prototype.getMatchers = function() {
2588
+ if (this.matchers) return this.matchers;
2589
+ var e3 = this.getTagBuilder(), t2 = [new yt({ tagBuilder: e3, serviceName: this.hashtag }), new dt({ tagBuilder: e3 }), new Ct({ tagBuilder: e3 }), new Tt({ tagBuilder: e3, serviceName: this.mention }), new vt({ tagBuilder: e3, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash, decodePercentEncoding: this.decodePercentEncoding })];
2590
+ return this.matchers = t2;
2591
+ }, e2.prototype.getTagBuilder = function() {
2592
+ var e3 = this.tagBuilder;
2593
+ return e3 || (e3 = this.tagBuilder = new _e({ newWindow: this.newWindow, truncate: this.truncate, className: this.className })), e3;
2594
+ }, e2.version = "3.14.3", e2.AnchorTagBuilder = _e, e2.HtmlTag = Ne, e2.matcher = { Email: dt, Hashtag: yt, Matcher: ze, Mention: Tt, Phone: Ct, Url: vt }, e2.match = { Email: We, Hashtag: qe, Match: Pe, Mention: He, Phone: Ge, Url: Le }, e2;
2595
+ }();
2596
+ function Bt(e2, t2 = e2) {
2597
+ return { type: "autolink", url: e2, text: t2 };
2598
+ }
2599
+ Object.assign(function(e2, t2) {
2600
+ return { type: "emoji", kind: e2, text: t2 };
2601
+ }, { emoticon: (e2) => ({ type: "emoji", kind: "emoticon", text: e2 }), unicode: (e2) => ({ type: "emoji", kind: "unicode", text: e2 }) });
2602
+ const Mt = Ee(/<!!mention:([^>\s]*?)\|(.*?)>/gm, ([e2, t2, s2]) => /* @__PURE__ */ function(e3, t3) {
2603
+ return { type: "mention", id: e3, text: t3 };
2604
+ }(decodeURIComponent(t2), s2)), Rt = Ee(/<!!customemoji:(.*?)>/gm, ([e2, t2]) => /* @__PURE__ */ function(e3) {
2605
+ return { type: "customemoji", text: e3 };
2606
+ }(t2)), Nt = Ee(/<((?:https?|mailto):.*?)\|(.*?)>/gi, ([e2, t2, s2]) => /* @__PURE__ */ function(e3, t3 = []) {
2607
+ return { type: "link", url: e3, children: t3 };
2608
+ }(t2, [s2])), _t = Ee(/<actionlink:([^|]+)[|]([^>]*)>/gi, ([e2, t2, s2]) => {
2609
+ const { action: n2, params: r2 } = Ot(t2);
2610
+ return /* @__PURE__ */ function(e3, t3, s3 = []) {
2611
+ return { type: "actionlink", action: e3, params: t3, children: s3 };
2612
+ }(n2, r2, [s2]);
2613
+ }), Pt = Ee(/<actionbutton:([^|]+)[|]([^>]*)>/gi, ([e2, t2, s2]) => {
2614
+ const { action: n2, params: r2 } = Ot(t2);
2615
+ return /* @__PURE__ */ function(e3, t3, s3 = []) {
2616
+ return { type: "actionbutton", action: e3, params: t3, children: s3 };
2617
+ }(n2, r2, [s2]);
2618
+ });
2619
+ function Ot(e2) {
2620
+ const t2 = e2.indexOf("?");
2621
+ if (-1 === t2) return { action: e2, params: {} };
2622
+ return { action: e2.slice(0, t2), params: Object.fromEntries(new URLSearchParams(e2.slice(t2))) };
2623
+ }
2624
+ const Ut = Ee(/(?:^|\n)(?:\s*[-*+]\s+[^\n]+(?:\n|$))+/g, ([e2]) => /* @__PURE__ */ function(e3 = []) {
2625
+ return { type: "bulletlist", children: e3 };
2626
+ }([e2.startsWith("\n") ? e2.slice(1) : e2])), jt = Ee(/^\s*[-*+]\s+([^\n]+)(?:\n|$)/gm, ([e2, t2]) => ({ type: "bulletpoint", children: [t2] })), $t = (e2) => {
2627
+ const t2 = /(?:^|[^-:/\w])([(+]?[0-9](?:[-_+ ().]?[0-9]){5,11}[0-9])(?:[^-:/\w]|$)/g;
2628
+ let s2 = 0;
2629
+ const n2 = [];
2630
+ for (const r2 of Z(e2, t2)) {
2631
+ const t3 = r2[0], i2 = r2[1], a2 = t3.startsWith(i2) ? r2.index : r2.index + 1;
2632
+ a2 - s2 > 0 && n2.push(e2.substring(s2, a2));
2633
+ const o2 = Bt("tel:" + i2.replace(/[^0-9+]/g, ""), i2);
2634
+ n2.push(o2), s2 = a2 + i2.length;
2635
+ }
2636
+ return s2 < e2.length && n2.push(e2.substring(s2)), n2;
2637
+ }, Wt = (e2) => Nt(e2).flatMap((e3) => "string" == typeof e3 ? qt(e3) : ["<", ...qt(e3.url), ...qt("|" + e3.children[0] + ">")]), qt = (e2) => {
2638
+ const t2 = Ft.parse(e2, { urls: true, email: true, phone: false, hashtag: false, mention: false }), s2 = [];
2639
+ let n2 = 0;
2640
+ for (const r2 of t2) {
2641
+ const t3 = r2.getOffset(), i2 = r2.getMatchedText(), a2 = i2.length;
2642
+ let o2 = i2;
2643
+ r2 instanceof We ? o2 = "mailto:" + r2.getEmail() : r2 instanceof Le && (o2 = r2.getUrl()), t3 > n2 && s2.push(e2.substring(n2, t3)), s2.push(Bt(o2, i2)), n2 = t3 + a2;
2644
+ }
2645
+ return n2 < e2.length && s2.push(e2.substring(n2)), s2;
2646
+ }, Ht = ["Codeblock", "Codespan", "FormattedLink", "Wikitext", "Autolink", "Actions", "Mention", "Mention", "BulletPoint", "CustomEmoji"];
2647
+ function Gt(e2 = { except: [] }) {
2648
+ var _a2;
2649
+ const t2 = { multilineSteps: [], singlelineSteps: [] }, s2 = (_a2 = e2.except) != null ? _a2 : Ht.filter((t3) => !e2.only.includes(t3));
2650
+ return s2.includes("BulletPoint") || t2.multilineSteps.push(Ut, jt), s2.includes("Mention") || t2.singlelineSteps.push(Mt), s2.includes("CustomEmoji") || t2.singlelineSteps.push(Rt), s2.includes("Codespan") || t2.multilineSteps.push(Ee(/```([^]+?)```/g, ([e3, t3]) => ({ type: "codespan", text: t3 }))), s2.includes("FormattedLink") || t2.singlelineSteps.push(Nt), s2.includes("Actions") || (t2.singlelineSteps.push(_t), t2.singlelineSteps.push(Pt)), s2.includes("Wikitext") || t2.singlelineSteps.push(De), s2.includes("Autolink") || t2.singlelineSteps.push(Wt, $t), t2;
2651
+ }
2652
+ const Lt = function(e2) {
2653
+ const t2 = RegExp(`[^${e2}]+${e2}?|${e2}`, "g");
2654
+ return (e3) => Array.from(e3.match(t2) || []);
2655
+ }("\n");
2656
+ function zt(e2, t2 = { except: [] }) {
2657
+ let s2 = function(e3, t3) {
2658
+ let s3 = [e3];
2659
+ return s3 = Jt(s3, t3.multilineSteps), s3 = Jt(s3, [Lt]), s3 = Jt(s3, t3.singlelineSteps), s3 = Yt(s3), s3;
2660
+ }(e2, Gt(t2));
2661
+ return s2 = Qt(s2, false), s2;
2662
+ }
2663
+ function Jt(e2, t2) {
2664
+ return t2.reduce((e3, t3) => Ce(e3, t3), e2);
2665
+ }
2666
+ function Yt(e2) {
2667
+ const t2 = [];
2668
+ let s2 = -1;
2669
+ for (const n2 of e2) "string" == typeof n2 ? "string" == typeof t2[s2] ? t2[s2] += n2 : t2[++s2] = n2 : t2[++s2] = "children" in n2 ? __spreadProps(__spreadValues({}, n2), { children: Yt(n2.children) }) : n2;
2670
+ return t2;
2671
+ }
2672
+ function Qt(e2, t2) {
2673
+ const s2 = [];
2674
+ let n2 = [];
2675
+ for (let r2 = 0; r2 < e2.length; r2++) {
2676
+ const i2 = e2[r2];
2677
+ "string" == typeof i2 ? n2.push(i2) : "children" in i2 ? (n2.length > 0 && (s2.push(n2.join("")), n2 = []), i2.children = Qt(i2.children, t2 || "link" === i2.type || "actionbutton" === i2.type || "actionlink" === i2.type), s2.push(i2)) : "autolink" === i2.type && t2 ? n2.push(i2.text) : (n2.length > 0 && (s2.push(n2.join("")), n2 = []), s2.push(i2));
2678
+ }
2679
+ return n2.length > 0 && (s2.push(n2.join("")), n2 = []), s2;
2680
+ }
2681
+ class Vt {
2682
+ constructor(e2, t2, s2) {
2683
+ this.id = e2, this.conversationId = t2, this._realtimeClient = s2;
2684
+ }
2685
+ get brandedId() {
2686
+ return this.id;
2687
+ }
2688
+ get brandedConversationId() {
2689
+ return this.conversationId;
2690
+ }
2691
+ get() {
2692
+ return __async(this, null, function* () {
2693
+ const t2 = yield this._realtimeClient.call("GET", ["me", "conversations", this.brandedConversationId, "messages", this.brandedId], {});
2694
+ if (!t2.ok && "server" === t2.where && 404 === t2.value.status) return null;
2695
+ if (!t2.ok && "server" === t2.where && 403 === t2.value.status && "NOT_A_PARTICIPANT" === t2.value.errorCode) return null;
2696
+ const s2 = e("Get message " + this.id, t2), n2 = yield this._realtimeClient.createMessageSnapshot(s2, this.brandedConversationId);
2697
+ return be("Get message " + this.id, n2);
2698
+ });
2699
+ }
2700
+ edit(t2) {
2701
+ return __async(this, null, function* () {
2702
+ const s2 = { content: Zt(t2), custom: "string" == typeof t2 ? void 0 : t2.custom }, n2 = yield this._realtimeClient.call("PATCH", ["conversations", this.brandedConversationId, "messages", this.brandedId], s2);
2703
+ e(`Edit message ${this.id} in conversation ${this.conversationId}`, n2);
2704
+ });
2705
+ }
2706
+ delete() {
2707
+ return __async(this, null, function* () {
2708
+ const t2 = yield this._realtimeClient.call("DELETE", ["conversations", this.brandedConversationId, "messages", this.brandedId], {});
2709
+ (t2.ok || "server" !== t2.where || 404 !== t2.value.status) && e(`Delete message ${this.id} in conversation ${this.conversationId}`, t2);
2710
+ });
2711
+ }
2712
+ }
2713
+ function Zt(e2) {
2714
+ if ("string" == typeof e2) {
2715
+ return [{ type: "text", children: zt(e2) }];
2716
+ }
2717
+ if ("text" in e2 && e2.text) {
2718
+ return [{ type: "text", children: zt(e2.text) }];
2719
+ }
2720
+ if ("content" in e2 && e2.content) return e2.content;
2721
+ }
2722
+ class Kt {
2723
+ constructor(e2, t2) {
2724
+ this.id = e2, this._realtimeClient = t2;
2725
+ }
2726
+ get brandedId() {
2727
+ return this.id;
2728
+ }
2729
+ get brandedUserId() {
2730
+ return this._realtimeClient.userId;
2731
+ }
2732
+ participant(e2) {
2733
+ return new ye("string" == typeof e2 ? e2 : e2.id, this.id, this._realtimeClient);
2734
+ }
2735
+ message(e2) {
2736
+ return new Vt(e2, this.brandedId, this._realtimeClient);
2737
+ }
2738
+ get() {
2739
+ return __async(this, null, function* () {
2740
+ const t2 = this._realtimeClient.listMessages(this.brandedId, { limit: 1 }), s2 = yield this._realtimeClient.call("GET", ["me", "conversations", this.brandedId], {});
2741
+ if (!s2.ok && "server" === s2.where && 404 === s2.value.status) return null;
2742
+ const n2 = e("Get conversation " + this.id, s2), r2 = be("Get last message in conversation " + this.id, yield t2), i2 = 0 === r2.length ? null : r2[0];
2743
+ return this._realtimeClient.createConversationSnapshotPreloaded(n2, i2);
2744
+ });
2745
+ }
2746
+ set(t2) {
2747
+ return __async(this, null, function* () {
2748
+ const s2 = this._realtimeClient.call("PUT", ["conversations", this.brandedId], t2), n2 = this._realtimeClient.call("PUT", ["conversations", this.brandedId, "participants", this.brandedUserId], t2), r2 = yield s2;
2749
+ !r2.ok && "server" === r2.where && 403 === r2.value.status && "UNAUTHORIZED_TO_EDIT" === r2.value.errorCode && function(e2) {
2750
+ if (void 0 !== e2.subject) return false;
2751
+ if (void 0 !== e2.photoUrl) return false;
2752
+ if (void 0 !== e2.welcomeMessages) return false;
2753
+ if (null === e2.custom) return false;
2754
+ if (void 0 !== e2.custom && Object.values(e2.custom).some((e3) => void 0 !== e3)) return false;
2755
+ return true;
2756
+ }(t2) || e("Set conversation " + this.id, r2);
2757
+ const i2 = yield n2;
2758
+ !i2.ok && "server" === i2.where && 403 === i2.value.status && "UNAUTHORIZED_TO_EDIT_PARTICIPANT" === i2.value.errorCode && function(e2) {
2759
+ return void 0 === e2.access && void 0 === e2.notify;
2760
+ }(t2) || e("Set your participation in conversation " + this.id, i2);
2761
+ });
2762
+ }
2763
+ createIfNotExists() {
2764
+ return __async(this, arguments, function* (t2 = {}) {
2765
+ const s2 = this._realtimeClient.call("POST", ["conversations", this.brandedId], t2), n2 = this._realtimeClient.call("POST", ["conversations", this.brandedId, "participants", this.brandedUserId], t2), r2 = yield s2;
2766
+ (r2.ok || "server" !== r2.where || 409 !== r2.value.status) && e("Create conversation " + this.id, yield s2);
2767
+ const i2 = yield n2;
2768
+ (i2.ok || "server" !== i2.where || 409 !== i2.value.status) && e("Join conversation " + this.id, yield n2);
2769
+ });
2770
+ }
2771
+ markAsRead() {
2772
+ return __async(this, null, function* () {
2773
+ const t2 = yield this._realtimeClient.call("POST", ["me", "conversations", this.brandedId, "read"], {});
2774
+ e(`Mark ${this.id} as read`, t2);
2775
+ });
2776
+ }
2777
+ markAsUnread() {
2778
+ return __async(this, null, function* () {
2779
+ const t2 = yield this._realtimeClient.call("POST", ["me", "conversations", this.brandedId, "unread"], {});
2780
+ e(`Mark ${this.id} as unread`, t2);
2781
+ });
2782
+ }
2783
+ send(t2) {
2784
+ return __async(this, null, function* () {
2785
+ const s2 = { content: Xt(t2), referencedMessageId: es(t2), custom: "string" == typeof t2 ? void 0 : t2.custom, idempotencyKey: Ae((/* @__PURE__ */ new Date()).getTime()) }, n2 = yield this._realtimeClient.call("POST", ["conversations", this.brandedId, "messages"], s2), r2 = e("Send message to conversation " + this.id, n2);
2786
+ return new Vt("string" == typeof r2 ? r2 : r2.id, this.brandedId, this._realtimeClient);
2787
+ });
2788
+ }
2789
+ subscribeMessages(e2) {
2790
+ return this._realtimeClient.subscribe(["me", "conversations", this.brandedId, "messages"], e2);
2791
+ }
2792
+ subscribe(e2) {
2793
+ return this._realtimeClient.subscribe(["me", "conversations", this.brandedId], e2);
2794
+ }
2795
+ }
2796
+ function Xt(e2) {
2797
+ if ("string" == typeof e2) {
2798
+ return [{ type: "text", children: zt(e2) }];
2799
+ }
2800
+ if ("text" in e2) {
2801
+ return [{ type: "text", children: zt(e2.text) }];
2802
+ }
2803
+ return e2.content;
2804
+ }
2805
+ function es(e2) {
2806
+ if ("string" == typeof e2) return;
2807
+ const t2 = e2.referencedMessage;
2808
+ return void 0 !== t2 ? "string" == typeof t2 ? t2 : t2.id : void 0;
2809
+ }
2810
+ class ts {
2811
+ constructor(e2, t2, s2) {
2812
+ this.realtimeWsApiUrl = e2, this.internalHttpApiUrl = t2, this.restApiHttpUrl = s2;
2813
+ }
2814
+ getBokensUrl(e2, t2, s2) {
2815
+ return this.internalHttpApiUrl + `/${e2}/bokens/${encodeURIComponent(t2)}?signature=${encodeURIComponent(s2 != null ? s2 : "")}`;
2816
+ }
2817
+ getRealtimeWsUrl(e2, t2, s2, n2) {
2818
+ const r2 = encodeURIComponent(t2);
2819
+ return this.realtimeWsApiUrl + `/${e2}/realtime/${r2}?talkjs-client-build=${n2 != null ? n2 : "standalone"}&talkjs-core=${s2}`;
2820
+ }
2821
+ }
2822
+ function ss({ method: e2, url: t2, data: s2, options: n2, attempts: r2, shouldRetry: i2, authProvider: o2 }) {
2823
+ var _a2;
2824
+ (!r2 || r2 <= 0) && (r2 = 1);
2825
+ const u2 = { "x-talkjs-client-build": "jssdk-dev", "x-talkjs-client-date": "2025-04-29T08:55:37.472Z" };
2826
+ s2 instanceof FormData || (u2["Content-Type"] = (_a2 = n2 == null ? void 0 : n2.contentType) != null ? _a2 : "application/json");
2827
+ return a(r2, () => __async(this, null, function* () {
2828
+ if (o2) {
2829
+ const e3 = yield o2.getToken();
2830
+ u2.Authorization = `Bearer ${e3}`;
2831
+ }
2832
+ return fetch(t2, { method: e2, headers: u2, body: s2 }).then((e3) => {
2833
+ if (e3.ok) return e3;
2834
+ throw e3;
2835
+ });
2836
+ }), { initialDelay: 0.2, log: void 0, shouldRetry: (s3) => __async(this, null, function* () {
2837
+ return o2 && 401 === s3.status ? (ls.log(`401 error from ${e2} ${t2}, ${yield o2.getToken()}`), o2.refreshToken(), true) : i2 ? i2(s3) : !("status" in s3 && s3.status >= 400 && s3.status < 500);
2838
+ }) }).catch((s3) => {
2839
+ if (!t2.toString().startsWith("https://capture.trackjs.com")) {
2840
+ const n3 = `Network Error for ${e2} ${t2}`;
2841
+ if ("undefined" != typeof window) if (s3 instanceof Response) {
2842
+ s3.clone().text().then((e3) => ls.log(`${n3} ${s3.status} ${e3}`));
2843
+ } else ls.log(`${n3} ${s3}`);
2844
+ console.error("[TalkJS]", n3);
2845
+ }
2846
+ throw s3;
2847
+ });
2848
+ }
2849
+ const { cdnHost: ns, appHost: rs, restHost: is, realtimeHost: as, appProtocol: os, appWsProtocol: us } = function() {
2850
+ if ("undefined" == typeof window) return { cdnHost: "test-hostname", appHost: "test-hostname", appProtocol: "http:", appWsProtocol: "ws:" };
2851
+ const e2 = function() {
2852
+ if (document.currentScript) return document.currentScript.src;
2853
+ try {
2854
+ throw new Error();
2855
+ } catch (e3) {
2856
+ const t3 = e3.stack.match(/https?:\/\/.*\.(js|jsx|ts|tsx)/);
2857
+ return t3 ? t3[0] : "";
2858
+ }
2859
+ }(), t2 = document.createElement("a");
2860
+ t2.href = e2;
2861
+ const s2 = t2.host, n2 = function(e3) {
2862
+ if (e3.match(/^cdn[.-]/)) return e3.replace(/^cdn/, "app");
2863
+ if ("talkjs.com" === e3) return "app.talkjs.com";
2864
+ return e3;
2865
+ }(s2), r2 = function(e3) {
2866
+ if (e3.match(/^app[.-]/)) return e3.replace(/^app/, "api");
2867
+ return e3 + "/public_api";
2868
+ }(n2), i2 = function(e3) {
2869
+ if (e3.match(/^app[.-]/)) return e3.replace(/^app/, "realtime");
2870
+ return e3 + "/public_api";
2871
+ }(n2), a2 = t2.protocol;
2872
+ return { cdnHost: s2, appHost: n2, restHost: r2, realtimeHost: i2, appProtocol: a2, appWsProtocol: "https:" === a2 ? "wss:" : "ws:" };
2873
+ }();
2874
+ const cs = rs.startsWith("app.talkjs.com");
2875
+ const ls = "undefined" == typeof window ? { log: (e2) => Promise.resolve(), setData: (e2) => {
2876
+ } } : new class {
2877
+ constructor(e2) {
2878
+ this._timeCreated = Date.now(), this._enabled = cs, this._trackJSData = { customer: { application: "", correlationId: "", sessionId: "", token: "", userId: "", version: "dev-2025-04-29T08:55:37.472Z" }, entry: "direct", environment: { age: Date.now() - this._timeCreated, dependencies: {}, originalUrl: window.location.href, referrer: document.referrer, userAgent: window.navigator.userAgent }, metadata: [], nav: [], network: [], url: window.location.href, stack: "", timestamp: (/* @__PURE__ */ new Date()).toISOString(), version: "dev-2025-04-29T08:55:37.472Z", throttled: 0 }, this._url = `https://capture.trackjs.com/capture?token=${e2}`, this._trackJSData.customer.token = e2;
2879
+ }
2880
+ setData({ appId: e2, meId: t2, sessionId: s2 }) {
2881
+ this._trackJSData.customer.userId = e2, this._trackJSData.customer.sessionId = `${e2}/${t2}`, this._trackJSData.customer.correlationId = s2;
2882
+ }
2883
+ log(e2) {
2884
+ return __async(this, null, function* () {
2885
+ try {
2886
+ if (!this._enabled) return Promise.resolve();
2887
+ const t2 = __spreadProps(__spreadValues({}, this._trackJSData), { message: e2 });
2888
+ yield ss({ method: "POST", url: this._url, data: JSON.stringify(t2), options: { contentType: "text/plain" } });
2889
+ } catch (e3) {
2890
+ console.error("[TalkJS] Failed when sending an error report. Error: ", e3);
2891
+ }
2892
+ });
2893
+ }
2894
+ }("970cd0be0fb74630b75c8451051299dc");
2895
+ class hs {
2896
+ constructor(e2, t2 = {}) {
2897
+ this._onSubscription = t2, this._handlers = {};
2898
+ for (const t3 in e2) Object.hasOwnProperty.call(e2, t3) && (this._handlers[t3] = []);
2899
+ }
2900
+ emit(e2, t2) {
2901
+ for (const s2 of this._handlers[e2]) try {
2902
+ s2(t2);
2903
+ } catch (t3) {
2904
+ console.error(`[TalkJS] '${String(e2)}' handler threw an error:`, t3);
2905
+ }
2906
+ }
2907
+ emitAsync(e2, t2) {
2908
+ return __async(this, null, function* () {
2909
+ try {
2910
+ const s2 = this._handlers[e2].map((e3) => e3(t2));
2911
+ yield Promise.all(s2);
2912
+ } catch (t3) {
2913
+ console.error(`[TalkJS] '${String(e2)}' handler threw an error:`, t3);
2914
+ }
2915
+ });
2916
+ }
2917
+ supports(e2) {
2918
+ return e2 in this._handlers;
2919
+ }
2920
+ on(e2, t2) {
2921
+ var _a2, _b;
2922
+ if (!this.supports(e2)) throw new Error(`Unknown event type '${String(e2)}'`);
2923
+ (_b = (_a2 = this._onSubscription)[e2]) == null ? void 0 : _b.call(_a2), this._handlers[e2].push(t2);
2924
+ }
2925
+ off(e2, t2) {
2926
+ if (!Object.hasOwnProperty.call(this._handlers, e2)) throw new Error(`Unknown event type '${String(e2)}'`);
2927
+ const s2 = this._handlers[e2].indexOf(t2);
2928
+ -1 !== s2 && this._handlers[e2].splice(s2, 1);
2929
+ }
2930
+ removeAllListeners() {
2931
+ for (const e2 in this._handlers) this._handlers[e2] = [];
2932
+ }
2933
+ handles(e2) {
2934
+ return this._handlers[e2].length > 0;
2935
+ }
2936
+ subscribe(e2, t2) {
2937
+ return this.on(e2, t2), { unsubscribe: () => this.off(e2, t2) };
2938
+ }
2939
+ }
2940
+ class ds {
2941
+ constructor(e2, t2, s2, n2, r2, i2) {
2942
+ if (this.appId = t2, this.userId = s2, this.tokenFetcher = r2, this.usingBokens = false, this.requestInProgress = false, this.eventEmitter = new hs({ tokenChanged(e3) {
2943
+ }, tokenRefreshFailed(e3) {
2944
+ }, tokenAccepted(e3) {
2945
+ } }), this.sessionExpiryWarningTimeoutId = void 0, i2 && (n2 || r2)) throw new Error("[TalkJS] If providing a signature for authentication, you must not provide a token or tokenFetcher.");
2946
+ n2 ? this.fetchToken(() => n2) : (r2 || (this.usingBokens = true, this.tokenFetcher = () => this.sendBokenRequest(e2, i2)), this.refreshToken());
2947
+ }
2948
+ get canRefreshToken() {
2949
+ return this.usingBokens || !!this.tokenFetcher;
2950
+ }
2951
+ getToken() {
2952
+ return this.token;
2953
+ }
2954
+ refreshToken() {
2955
+ if (!this.requestInProgress) {
2956
+ if (!this.tokenFetcher) throw this.emitTokenRefreshFailed("no `tokenFetcher` provided"), new Error("[TalkJS] Cannot refresh token, no `tokenFetcher` provided.");
2957
+ this.fetchToken(this.tokenFetcher);
2958
+ }
2959
+ }
2960
+ onTokenChanged(e2) {
2961
+ return this.eventEmitter.on("tokenChanged", e2), () => {
2962
+ this.eventEmitter.off("tokenChanged", e2);
2963
+ };
2964
+ }
2965
+ emitTokenChanged(e2) {
2966
+ this.eventEmitter.emit("tokenChanged", e2);
2967
+ }
2968
+ onTokenRefreshFailed(e2) {
2969
+ return this.eventEmitter.on("tokenRefreshFailed", e2), () => {
2970
+ this.eventEmitter.off("tokenRefreshFailed", e2);
2971
+ };
2972
+ }
2973
+ emitTokenRefreshFailed(e2) {
2974
+ this.eventEmitter.emit("tokenRefreshFailed", e2), console.error(`[TalkJS] Could not authenticate, cannot recover automatically: ${e2}`);
2975
+ }
2976
+ onTokenAccepted(e2) {
2977
+ return this.eventEmitter.on("tokenAccepted", e2), () => {
2978
+ this.eventEmitter.off("tokenAccepted", e2);
2979
+ };
2980
+ }
2981
+ emitTokenAccepted(e2) {
2982
+ this.eventEmitter.emit("tokenAccepted", e2);
2983
+ }
2984
+ clearScheduledRefresh() {
2985
+ this.sessionExpiryWarningTimeoutId && clearTimeout(this.sessionExpiryWarningTimeoutId);
2986
+ }
2987
+ scheduleRefresh(e2) {
2988
+ if (this.clearScheduledRefresh(), null === e2) return;
2989
+ const t2 = void 0 !== this.tokenFetcher;
2990
+ e2 < 120 && !t2 ? console.warn(`[TalkJS] TalkJS will stop working in ${e2} seconds due to auth token expiry. Token expires in ${e2} seconds, and cannot be refreshed because no \`tokenFetcher\` was provided when creating the session. Non-refreshable tokens are recommended to expire at least 24 hours in the future.`) : e2 < 120 && t2 ? console.warn(`[TalkJS] TalkJS auth token will expire and need to be refreshed in ${e2} seconds. Refreshable JWTs are recommended to expire at least 30 minutes in the future, to improve performance and reduce unnecessary refreshes.`) : e2 < 3300 && !t2 && console.warn(`[TalkJS debug] TalkJS will stop working in ${Math.round(e2 / 60)} minutes due to auth token expiry. Non-refreshable tokens are recommended to expire at least 24 hours in the future. Alternatively, provide a \`tokenFetcher\` when creating the session, so that tokens can be refreshed when they expire.`);
2991
+ if (void 0 !== this.tokenFetcher) {
2992
+ const t3 = e2 > 600 ? e2 - 300 : e2 / 2, s2 = Math.min(1728e6, 1e3 * t3);
2993
+ this.sessionExpiryWarningTimeoutId = setTimeout(() => {
2994
+ this.refreshToken();
2995
+ }, s2);
2996
+ } else e2 < 2e6 && (this.sessionExpiryWarningTimeoutId = setTimeout(() => {
2997
+ this.emitTokenRefreshFailed("Token has expired and no `tokenFetcher` was provided when creating the session, so it cannot be refreshed.");
2998
+ }, 1e3 * e2));
2999
+ }
3000
+ fetchToken(e2) {
3001
+ return __async(this, null, function* () {
3002
+ if (this.requestInProgress) return;
3003
+ this.requestInProgress = true;
3004
+ const t2 = () => __async(this, null, function* () {
3005
+ const t3 = yield e2();
3006
+ return this.checkJwt(t3), t3;
3007
+ });
3008
+ try {
3009
+ const e3 = void 0 !== this.token;
3010
+ this.token = t2(), yield this.token.then((t3) => {
3011
+ e3 && this.emitTokenChanged(t3);
3012
+ }).catch((e4) => {
3013
+ this.emitTokenRefreshFailed(e4);
3014
+ });
3015
+ } catch (e3) {
3016
+ this.emitTokenRefreshFailed(e3);
3017
+ } finally {
3018
+ this.requestInProgress = false;
3019
+ }
3020
+ });
3021
+ }
3022
+ checkJwt(e2) {
3023
+ const t2 = [];
3024
+ let s2, n2, r2;
3025
+ if ("string" == typeof e2 ? s2 = e2 : t2.push(`Token type is ${typeof e2} instead of a string.`), s2) try {
3026
+ const e3 = function(e4) {
3027
+ const t3 = e4.split(".");
3028
+ if (3 !== t3.length) throw "Token does not contain exactly two `.`. Check that you generated your JWT correctly. It should be `<header>.<payload>.<signature>`.";
3029
+ return { header: ps(t3[0]), payload: ps(t3[1]) };
3030
+ }(s2);
3031
+ n2 = e3.header, r2 = e3.payload;
3032
+ } catch (e3) {
3033
+ t2.push(e3);
3034
+ }
3035
+ if (n2) {
3036
+ const e3 = this.checkJwtHeader(n2);
3037
+ t2.push(...e3);
3038
+ }
3039
+ if (r2) {
3040
+ const e3 = this.checkJwtPayload(r2);
3041
+ t2.push(...e3);
3042
+ }
3043
+ if (t2.length) if (this.usingBokens) ls.log(`JWT Errors detected by AuthProvider when using bokens: ${t2.join("\n")}`);
3044
+ else {
3045
+ console.warn("[TalkJS] Authentication token appears to be generated incorrectly. Will still attempt to authenticate, but TalkJS may not work as expected. See below for a description of any problems and how to fix them.");
3046
+ const s3 = t2.length > 1;
3047
+ t2.forEach((e3, t3) => {
3048
+ const n3 = s3 ? `Reason ${t3 + 1}:` : "Reason:";
3049
+ console.warn(`[TalkJS] ${n3} ${e3}`);
3050
+ }), console.warn(`[TalkJS]: Authentication token: "${e2}"`);
3051
+ }
3052
+ }
3053
+ checkJwtHeader(e2) {
3054
+ const t2 = [], s2 = e2.alg;
3055
+ return void 0 === s2 ? t2.push('Token header must contain `"alg": "HS256"`, but no `alg` was specified.') : "string" != typeof s2 ? t2.push(`Token header must contain \`"alg": "HS256"\`, but \`alg\` was ${typeof s2} instead of a string. Make sure you wrap the value in "".`) : "HS256" !== s2 && t2.push(`Token header must contain \`"alg": "HS256"\`, but \`alg\` was set to "${s2}" instead. HS256 is the only supported algorithm.`), t2;
3056
+ }
3057
+ checkJwtPayload(e2) {
3058
+ const t2 = [], s2 = e2.iss;
3059
+ void 0 === s2 ? t2.push(`Token payload must contain an \`iss\` claim set to your app ID (${this.appId}), but \`iss\` was missing.`) : "string" != typeof s2 ? t2.push(`Token payload must contain an \`iss\` claim set to your app ID (${this.appId}), but \`iss\` was ${typeof s2} instead of a string. Make sure you wrap the value in "".`) : s2 !== this.appId && t2.push(`Token payload must contain an \`iss\` claim set to your app ID (${this.appId}), but \`iss\` was set to "${s2}" instead.`);
3060
+ const n2 = e2.sub;
3061
+ void 0 === n2 ? t2.push(`Token payload must contain a \`sub\` claim set to your user ID (${this.userId}), but \`sub\` was missing.`) : "string" != typeof n2 ? t2.push(`Token payload must contain a \`sub\` claim set to your user ID (${this.userId}), but \`sub\` was ${typeof n2} instead of a string. Make sure you wrap the value in "".`) : n2 !== this.userId && t2.push(`Token payload must contain a \`sub\` claim set to your userId ID (${this.userId}), but \`sub\` was set to "${n2}" instead.`);
3062
+ const r2 = e2.tokenType;
3063
+ void 0 === r2 ? t2.push('Token payload must contain a `"tokenType": "user"` claim, but no `tokenType` was specified.') : "string" != typeof r2 ? t2.push(`Token payload must contain a \`"tokenType": "user"\` claim, but \`tokenType\` was ${typeof r2} instead of a string. Make sure you wrap the value in "".`) : "user" !== r2 && t2.push(`Token payload must contain a \`"tokenType": "user"\` claim, but \`tokenType\` was set to "${r2}" instead.`);
3064
+ const i2 = e2.exp;
3065
+ void 0 === i2 || ("number" != typeof i2 ? t2.push(`Token payload contains an \`exp\` claim, but \`exp\` was ${typeof r2} instead of a number. If set, \`exp\` should be the expiry date as a number of seconds since 1970-01-01. Don't wrap the value in "".`) : i2 < 1e9 ? t2.push(`Token payload contains an \`exp\` claim, but \`exp\` is very small (${i2}, representing ${new Date(1e3 * i2).toLocaleDateString()}). If set, \`exp\` should be the expiry date as a number of seconds since 1970-01-01.`) : i2 > 1e11 ? t2.push(`Token payload contains an \`exp\` claim, but \`exp\` is very small (${i2}, representing ${new Date(1e3 * i2).toLocaleDateString()}). If set, \`exp\` should be the expiry date as a number of seconds since 1970-01-01. Double-check that you are using seconds and not milliseconds or nanoseconds.`) : i2 < (/* @__PURE__ */ new Date()).getTime() / 1e3 && t2.push(`Token payload contains an \`exp\` claim, but \`exp\` (${i2}, representing ${new Date(1e3 * i2).toLocaleDateString()}) appears to be in the past, meaning the token will be rejected. This error can also happen if your device's clock is set incorrectly, in which case the token will still work.`));
3066
+ const a2 = e2.nbf;
3067
+ return void 0 === a2 || ("number" != typeof a2 ? t2.push(`Token payload contains a \`nbf\` (not-before) claim, but \`nbf\` was ${typeof r2} instead of a number. If set, \`nbf\` should be the date when the JWT becomes valid, as a number of seconds since 1970-01-01.`) : a2 > 1e11 && t2.push(`Token payload contains a \`nbf\` (not-before) claim, but \`nbf\` is very large (${a2}, representing ${new Date(1e3 * a2).toLocaleDateString()}). If set, \`nbf\` should be the date when the JWT becomes valid, as a number of seconds since 1970-01-01. Double-check that you are using seconds and not milliseconds or nanoseconds.`)), t2;
3068
+ }
3069
+ sendBokenRequest(e2, t2) {
3070
+ return __async(this, null, function* () {
3071
+ let s2 = 0;
3072
+ const n2 = e2.getBokensUrl(this.appId, this.userId, t2), r2 = yield ss({ method: "GET", url: n2, attempts: 1e4, shouldRetry: (e3) => {
3073
+ if (e3 instanceof Error) return true;
3074
+ if (401 === e3.status) throw "Check that you provided a valid signature.";
3075
+ if (404 === e3.status) throw "Check that you specified the correct App ID.";
3076
+ if (429 === e3.status || 502 === e3.status) return true;
3077
+ if (e3.status >= 400 && e3.status < 500) throw `Unexpected HTTP ${e3.status} response when fetching auth token. Check that you configured the session correctly.`;
3078
+ if (s2++, s2 >= 5) throw `Unexpected HTTP ${e3.status} response when fetching auth token, retrying did not help.`;
3079
+ return true;
3080
+ } });
3081
+ return (yield r2.json()).boken;
3082
+ });
3083
+ }
3084
+ }
3085
+ function ps(e2) {
3086
+ try {
3087
+ const t2 = e2.replace(/-/g, "+").replace(/_/g, "/"), s2 = decodeURIComponent(atob(t2).split("").map((e3) => "%" + ("00" + e3.charCodeAt(0).toString(16)).slice(-2)).join(""));
3088
+ return JSON.parse(s2);
3089
+ } catch (t2) {
3090
+ throw `Could not base64-decode and JSON-parse token section: ${e2}. Check that you base-64 encoded the section correctly.`;
3091
+ }
3092
+ }
3093
+ const fs = new ts("wss://realtime.talkjs.com/v1", "https://app.talkjs.com/api/v0", "https://api.talkjs.com/v1");
3094
+ class ms {
3095
+ constructor(e2) {
3096
+ this.target = e2;
3097
+ }
3098
+ deref() {
3099
+ return this.target;
3100
+ }
3101
+ }
3102
+ const gs = new class {
3103
+ constructor() {
3104
+ this.registry = {};
3105
+ }
3106
+ getOrCreate(e2) {
3107
+ var _a2;
3108
+ const t2 = this.key(e2), s2 = (_a2 = this.registry[t2]) == null ? void 0 : _a2.deref();
3109
+ if (s2) return s2;
3110
+ const n2 = new bs(e2), r2 = globalThis.WeakRef ? new WeakRef(n2) : new ms(n2);
3111
+ return this.registry[t2] = r2, n2;
3112
+ }
3113
+ deregister(e2, t2) {
3114
+ const s2 = this.key({ appId: e2, userId: t2 });
3115
+ delete this.registry[s2];
3116
+ }
3117
+ key({ appId: e2, userId: t2 }) {
3118
+ return `${e2}:${t2}`;
3119
+ }
3120
+ }();
3121
+ function vs(e2) {
3122
+ return e2.forceCreateNew ? new bs(e2) : gs.getOrCreate(e2);
3123
+ }
3124
+ class bs {
3125
+ constructor(e2) {
3126
+ !function(e3) {
3127
+ function t3(e4, t4) {
3128
+ if (!e4) throw new Error("[TalkJS] TalkSession: " + t4);
3129
+ }
3130
+ t3(e3 && "object" == typeof e3, "Expected an object argument in TalkSession#constructor."), t3(e3.appId && "string" == typeof e3.appId, "The `appId` property of TalkSession#constructor is required and it must be a non-empty string."), t3("string" == typeof e3.userId, "The `userId` property of TalkSession#constructor is required and it must be a string."), void 0 !== e3.token && t3(e3.token && "string" == typeof e3.token, "The `token` property of TalkSession#constructor must be a non-empty string.");
3131
+ void 0 !== e3.tokenFetcher && t3("function" == typeof e3.tokenFetcher, "The `tokenFetcher` property of TalkSession#constructor must be a function.");
3132
+ }(e2);
3133
+ const { appId: t2, userId: s2, token: n2, tokenFetcher: r2, signature: i2 } = e2;
3134
+ this._appId = t2, this._apiUrls = e2.apiUrls ? new ts(e2.apiUrls.realtimeWsApiUrl, e2.apiUrls.internalHttpApiUrl, e2.apiUrls.restApiHttpUrl) : fs, this._authProvider = new ds(this._apiUrls, t2, s2, n2, r2, i2), this._realtimeClient = new ge(this._apiUrls.getRealtimeWsUrl(t2, s2, "1.0.0", e2.clientBuild), s2, this._authProvider), this.currentUser = new we(this._realtimeClient.userId, this._realtimeClient), this._terminationReason = o(), this._terminationReason.promise.then((e3) => {
3135
+ console.error(`[TalkSession] ${e3}`);
3136
+ }), function(e3, t3, s3) {
3137
+ return __async(this, null, function* () {
3138
+ return ss({ method: "GET", url: `${t3}/${e3}/app`, authProvider: s3 }).then((e4) => 200 === e4.status || 404 !== e4.status && (console.warn(`[TalkJS] Received unexpected ${e4.status} status code when validating app ID. Assuming that the app ID is valid.`), true)).catch((e4) => {
3139
+ if ("string" != typeof e4 && "status" in e4) {
3140
+ const t4 = e4;
3141
+ return 200 === t4.status || 404 !== t4.status && (console.warn(`[TalkJS] Received unexpected ${t4.status} status code when validating app ID. Assuming that the app ID is valid.`), true);
3142
+ }
3143
+ return console.warn("[TalkJS] Encountered network issues when validating app ID. Assuming that the app ID is valid."), true;
3144
+ });
3145
+ });
3146
+ }(this._appId, this._apiUrls.internalHttpApiUrl, this._authProvider).then((e3) => {
3147
+ e3 || this.terminate(new Error(`The app ID ${this._appId} does not exist. Make sure you are using the correct app ID as found on the TalkJS dashboard. App IDs are case-sensitive.`));
3148
+ }), this._authProvider.onTokenRefreshFailed((e3) => {
3149
+ this.terminate(new Error(`Could not authenticate, cannot recover automatically: ${e3}`));
3150
+ });
3151
+ }
3152
+ onError(e2) {
3153
+ const t2 = o();
3154
+ return Promise.race([t2.promise, this._terminationReason.promise]).then((t3) => {
3155
+ "UNSUBSCRIBED" !== t3 && e2(t3);
3156
+ }), { unsubscribe: () => t2.resolve("UNSUBSCRIBED") };
3157
+ }
3158
+ user(e2) {
3159
+ return new we(e2, this._realtimeClient);
3160
+ }
3161
+ conversation(e2) {
3162
+ return new Kt(e2, this._realtimeClient);
3163
+ }
3164
+ terminate(e2) {
3165
+ gs.deregister(this._appId, this.currentUser.id), this._terminationReason.resolve(e2), this._realtimeClient.destroy();
3166
+ }
3167
+ _isConnected() {
3168
+ return this._realtimeClient.isConnected();
3169
+ }
3170
+ uploadFile(e2, t2) {
3171
+ return ws(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, t2);
3172
+ }
3173
+ uploadImage(e2, t2) {
3174
+ return ws(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "image" }, t2));
3175
+ }
3176
+ uploadVideo(e2, t2) {
3177
+ return ws(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "video" }, t2));
3178
+ }
3179
+ uploadAudio(e2, t2) {
3180
+ return ws(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "audio" }, t2));
3181
+ }
3182
+ uploadVoice(e2, t2) {
3183
+ return ws(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "voice" }, t2));
3184
+ }
3185
+ }
3186
+ function ws(_0, _1, _2, _3) {
3187
+ return __async(this, arguments, function* (e2, t2, s2, { subtype: n2, filename: r2, width: i2, height: a2, duration: o2 }) {
3188
+ const u2 = new FormData();
3189
+ return u2.set("file", s2, r2), void 0 !== n2 && u2.set("subtype", n2), void 0 !== i2 && u2.set("width", i2.toString()), void 0 !== a2 && u2.set("height", a2.toString()), void 0 !== o2 && u2.set("duration", o2.toString()), ss({ method: "POST", url: e2, data: u2, authProvider: t2 }).then((e3) => e3.json()).then((e3) => e3.attachmentToken).catch((e3) => __async(this, null, function* () {
3190
+ if (e3 instanceof Response) {
3191
+ const t3 = yield e3.json(), s3 = `Unexpected response when uploading file, status code ${e3.status} ${t3.errorCode}, ${t3.reasons}`;
3192
+ throw new Error(s3);
3193
+ }
3194
+ throw e3;
3195
+ }));
3196
+ });
3197
+ }
3198
+ export {
3199
+ vs as getTalkSession,
3200
+ f as registerPolyfills
3201
+ };
3202
+ //# sourceMappingURL=talkSession.js.map