liveroom-client-element 0.0.2 → 0.0.4

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,3223 @@
1
+ var je = Object.defineProperty;
2
+ var xe = (s, n, t) => n in s ? je(s, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[n] = t;
3
+ var f = (s, n, t) => (xe(s, typeof n != "symbol" ? n + "" : n, t), t);
4
+ function ht() {
5
+ }
6
+ function oe(s) {
7
+ return s();
8
+ }
9
+ function Zt() {
10
+ return /* @__PURE__ */ Object.create(null);
11
+ }
12
+ function ut(s) {
13
+ s.forEach(oe);
14
+ }
15
+ function ae(s) {
16
+ return typeof s == "function";
17
+ }
18
+ function Se(s, n) {
19
+ return s != s ? n == n : s !== n || s && typeof s == "object" || typeof s == "function";
20
+ }
21
+ function Me(s) {
22
+ return Object.keys(s).length === 0;
23
+ }
24
+ function B(s, n) {
25
+ s.appendChild(n);
26
+ }
27
+ function Ne(s, n, t) {
28
+ const e = Le(s);
29
+ if (!e.getElementById(n)) {
30
+ const r = W("style");
31
+ r.id = n, r.textContent = t, Re(e, r);
32
+ }
33
+ }
34
+ function Le(s) {
35
+ if (!s)
36
+ return document;
37
+ const n = s.getRootNode ? s.getRootNode() : s.ownerDocument;
38
+ return n && /** @type {ShadowRoot} */
39
+ n.host ? (
40
+ /** @type {ShadowRoot} */
41
+ n
42
+ ) : s.ownerDocument;
43
+ }
44
+ function Re(s, n) {
45
+ return B(
46
+ /** @type {Document} */
47
+ s.head || s,
48
+ n
49
+ ), n.sheet;
50
+ }
51
+ function Ct(s, n, t) {
52
+ s.insertBefore(n, t || null);
53
+ }
54
+ function pt(s) {
55
+ s.parentNode && s.parentNode.removeChild(s);
56
+ }
57
+ function W(s) {
58
+ return document.createElement(s);
59
+ }
60
+ function Qt(s) {
61
+ return document.createElementNS("http://www.w3.org/2000/svg", s);
62
+ }
63
+ function he(s) {
64
+ return document.createTextNode(s);
65
+ }
66
+ function jt() {
67
+ return he(" ");
68
+ }
69
+ function x(s, n, t) {
70
+ t == null ? s.removeAttribute(n) : s.getAttribute(n) !== t && s.setAttribute(n, t);
71
+ }
72
+ function He(s) {
73
+ return Array.from(s.childNodes);
74
+ }
75
+ function Pe(s, n) {
76
+ n = "" + n, s.data !== n && (s.data = /** @type {string} */
77
+ n);
78
+ }
79
+ function Q(s, n, t, e) {
80
+ t == null ? s.style.removeProperty(n) : s.style.setProperty(n, t, e ? "important" : "");
81
+ }
82
+ function Ie(s) {
83
+ const n = {};
84
+ return s.childNodes.forEach(
85
+ /** @param {Element} node */
86
+ (t) => {
87
+ n[t.slot || "default"] = !0;
88
+ }
89
+ ), n;
90
+ }
91
+ let ct;
92
+ function it(s) {
93
+ ct = s;
94
+ }
95
+ function ce() {
96
+ if (!ct)
97
+ throw new Error("Function called outside component initialization");
98
+ return ct;
99
+ }
100
+ function De(s) {
101
+ ce().$$.on_mount.push(s);
102
+ }
103
+ function Ue(s) {
104
+ ce().$$.on_destroy.push(s);
105
+ }
106
+ const tt = [], Mt = [];
107
+ let et = [];
108
+ const Kt = [], Je = /* @__PURE__ */ Promise.resolve();
109
+ let Nt = !1;
110
+ function Ve() {
111
+ Nt || (Nt = !0, Je.then(bt));
112
+ }
113
+ function Lt(s) {
114
+ et.push(s);
115
+ }
116
+ const xt = /* @__PURE__ */ new Set();
117
+ let K = 0;
118
+ function bt() {
119
+ if (K !== 0)
120
+ return;
121
+ const s = ct;
122
+ do {
123
+ try {
124
+ for (; K < tt.length; ) {
125
+ const n = tt[K];
126
+ K++, it(n), qe(n.$$);
127
+ }
128
+ } catch (n) {
129
+ throw tt.length = 0, K = 0, n;
130
+ }
131
+ for (it(null), tt.length = 0, K = 0; Mt.length; )
132
+ Mt.pop()();
133
+ for (let n = 0; n < et.length; n += 1) {
134
+ const t = et[n];
135
+ xt.has(t) || (xt.add(t), t());
136
+ }
137
+ et.length = 0;
138
+ } while (tt.length);
139
+ for (; Kt.length; )
140
+ Kt.pop()();
141
+ Nt = !1, xt.clear(), it(s);
142
+ }
143
+ function qe(s) {
144
+ if (s.fragment !== null) {
145
+ s.update(), ut(s.before_update);
146
+ const n = s.dirty;
147
+ s.dirty = [-1], s.fragment && s.fragment.p(s.ctx, n), s.after_update.forEach(Lt);
148
+ }
149
+ }
150
+ function Be(s) {
151
+ const n = [], t = [];
152
+ et.forEach((e) => s.indexOf(e) === -1 ? n.push(e) : t.push(e)), t.forEach((e) => e()), et = n;
153
+ }
154
+ const Fe = /* @__PURE__ */ new Set();
155
+ function le(s, n) {
156
+ s && s.i && (Fe.delete(s), s.i(n));
157
+ }
158
+ function te(s) {
159
+ return (s == null ? void 0 : s.length) !== void 0 ? s : Array.from(s);
160
+ }
161
+ function ze(s, n) {
162
+ s.d(1), n.delete(s.key);
163
+ }
164
+ function We(s, n, t, e, r, i, o, h, p, d, b, _) {
165
+ let A = s.length, T = i.length, j = A;
166
+ const R = {};
167
+ for (; j--; )
168
+ R[s[j].key] = j;
169
+ const N = [], k = /* @__PURE__ */ new Map(), G = /* @__PURE__ */ new Map(), dt = [];
170
+ for (j = T; j--; ) {
171
+ const S = _(r, i, j), U = t(S);
172
+ let J = o.get(U);
173
+ J ? e && dt.push(() => J.p(S, n)) : (J = d(U, S), J.c()), k.set(U, N[j] = J), U in R && G.set(U, Math.abs(j - R[U]));
174
+ }
175
+ const gt = /* @__PURE__ */ new Set(), vt = /* @__PURE__ */ new Set();
176
+ function st(S) {
177
+ le(S, 1), S.m(h, b), o.set(S.key, S), b = S.first, T--;
178
+ }
179
+ for (; A && T; ) {
180
+ const S = N[T - 1], U = s[A - 1], J = S.key, X = U.key;
181
+ S === U ? (b = S.first, A--, T--) : k.has(X) ? !o.has(J) || gt.has(J) ? st(S) : vt.has(X) ? A-- : G.get(J) > G.get(X) ? (vt.add(J), st(S)) : (gt.add(X), A--) : (p(U, o), A--);
182
+ }
183
+ for (; A--; ) {
184
+ const S = s[A];
185
+ k.has(S.key) || p(S, o);
186
+ }
187
+ for (; T; )
188
+ st(N[T - 1]);
189
+ return ut(dt), N;
190
+ }
191
+ function Ge(s, n, t) {
192
+ const { fragment: e, after_update: r } = s.$$;
193
+ e && e.m(n, t), Lt(() => {
194
+ const i = s.$$.on_mount.map(oe).filter(ae);
195
+ s.$$.on_destroy ? s.$$.on_destroy.push(...i) : ut(i), s.$$.on_mount = [];
196
+ }), r.forEach(Lt);
197
+ }
198
+ function Xe(s, n) {
199
+ const t = s.$$;
200
+ t.fragment !== null && (Be(t.after_update), ut(t.on_destroy), t.fragment && t.fragment.d(n), t.on_destroy = t.fragment = null, t.ctx = []);
201
+ }
202
+ function Ye(s, n) {
203
+ s.$$.dirty[0] === -1 && (tt.push(s), Ve(), s.$$.dirty.fill(0)), s.$$.dirty[n / 31 | 0] |= 1 << n % 31;
204
+ }
205
+ function Ze(s, n, t, e, r, i, o, h = [-1]) {
206
+ const p = ct;
207
+ it(s);
208
+ const d = s.$$ = {
209
+ fragment: null,
210
+ ctx: [],
211
+ // state
212
+ props: i,
213
+ update: ht,
214
+ not_equal: r,
215
+ bound: Zt(),
216
+ // lifecycle
217
+ on_mount: [],
218
+ on_destroy: [],
219
+ on_disconnect: [],
220
+ before_update: [],
221
+ after_update: [],
222
+ context: new Map(n.context || (p ? p.$$.context : [])),
223
+ // everything else
224
+ callbacks: Zt(),
225
+ dirty: h,
226
+ skip_bound: !1,
227
+ root: n.target || p.$$.root
228
+ };
229
+ o && o(d.root);
230
+ let b = !1;
231
+ if (d.ctx = t ? t(s, n.props || {}, (_, A, ...T) => {
232
+ const j = T.length ? T[0] : A;
233
+ return d.ctx && r(d.ctx[_], d.ctx[_] = j) && (!d.skip_bound && d.bound[_] && d.bound[_](j), b && Ye(s, _)), A;
234
+ }) : [], d.update(), b = !0, ut(d.before_update), d.fragment = e ? e(d.ctx) : !1, n.target) {
235
+ if (n.hydrate) {
236
+ const _ = He(n.target);
237
+ d.fragment && d.fragment.l(_), _.forEach(pt);
238
+ } else
239
+ d.fragment && d.fragment.c();
240
+ n.intro && le(s.$$.fragment), Ge(s, n.target, n.anchor), bt();
241
+ }
242
+ it(p);
243
+ }
244
+ let ue;
245
+ typeof HTMLElement == "function" && (ue = class extends HTMLElement {
246
+ constructor(n, t, e) {
247
+ super();
248
+ /** The Svelte component constructor */
249
+ f(this, "$$ctor");
250
+ /** Slots */
251
+ f(this, "$$s");
252
+ /** The Svelte component instance */
253
+ f(this, "$$c");
254
+ /** Whether or not the custom element is connected */
255
+ f(this, "$$cn", !1);
256
+ /** Component props data */
257
+ f(this, "$$d", {});
258
+ /** `true` if currently in the process of reflecting component props back to attributes */
259
+ f(this, "$$r", !1);
260
+ /** @type {Record<string, CustomElementPropDefinition>} Props definition (name, reflected, type etc) */
261
+ f(this, "$$p_d", {});
262
+ /** @type {Record<string, Function[]>} Event listeners */
263
+ f(this, "$$l", {});
264
+ /** @type {Map<Function, Function>} Event listener unsubscribe functions */
265
+ f(this, "$$l_u", /* @__PURE__ */ new Map());
266
+ this.$$ctor = n, this.$$s = t, e && this.attachShadow({ mode: "open" });
267
+ }
268
+ addEventListener(n, t, e) {
269
+ if (this.$$l[n] = this.$$l[n] || [], this.$$l[n].push(t), this.$$c) {
270
+ const r = this.$$c.$on(n, t);
271
+ this.$$l_u.set(t, r);
272
+ }
273
+ super.addEventListener(n, t, e);
274
+ }
275
+ removeEventListener(n, t, e) {
276
+ if (super.removeEventListener(n, t, e), this.$$c) {
277
+ const r = this.$$l_u.get(t);
278
+ r && (r(), this.$$l_u.delete(t));
279
+ }
280
+ }
281
+ async connectedCallback() {
282
+ if (this.$$cn = !0, !this.$$c) {
283
+ let n = function(i) {
284
+ return () => {
285
+ let o;
286
+ return {
287
+ c: function() {
288
+ o = W("slot"), i !== "default" && x(o, "name", i);
289
+ },
290
+ /**
291
+ * @param {HTMLElement} target
292
+ * @param {HTMLElement} [anchor]
293
+ */
294
+ m: function(d, b) {
295
+ Ct(d, o, b);
296
+ },
297
+ d: function(d) {
298
+ d && pt(o);
299
+ }
300
+ };
301
+ };
302
+ };
303
+ if (await Promise.resolve(), !this.$$cn)
304
+ return;
305
+ const t = {}, e = Ie(this);
306
+ for (const i of this.$$s)
307
+ i in e && (t[i] = [n(i)]);
308
+ for (const i of this.attributes) {
309
+ const o = this.$$g_p(i.name);
310
+ o in this.$$d || (this.$$d[o] = wt(o, i.value, this.$$p_d, "toProp"));
311
+ }
312
+ this.$$c = new this.$$ctor({
313
+ target: this.shadowRoot || this,
314
+ props: {
315
+ ...this.$$d,
316
+ $$slots: t,
317
+ $$scope: {
318
+ ctx: []
319
+ }
320
+ }
321
+ });
322
+ const r = () => {
323
+ this.$$r = !0;
324
+ for (const i in this.$$p_d)
325
+ if (this.$$d[i] = this.$$c.$$.ctx[this.$$c.$$.props[i]], this.$$p_d[i].reflect) {
326
+ const o = wt(
327
+ i,
328
+ this.$$d[i],
329
+ this.$$p_d,
330
+ "toAttribute"
331
+ );
332
+ o == null ? this.removeAttribute(i) : this.setAttribute(this.$$p_d[i].attribute || i, o);
333
+ }
334
+ this.$$r = !1;
335
+ };
336
+ this.$$c.$$.after_update.push(r), r();
337
+ for (const i in this.$$l)
338
+ for (const o of this.$$l[i]) {
339
+ const h = this.$$c.$on(i, o);
340
+ this.$$l_u.set(o, h);
341
+ }
342
+ this.$$l = {};
343
+ }
344
+ }
345
+ // We don't need this when working within Svelte code, but for compatibility of people using this outside of Svelte
346
+ // and setting attributes through setAttribute etc, this is helpful
347
+ attributeChangedCallback(n, t, e) {
348
+ var r;
349
+ this.$$r || (n = this.$$g_p(n), this.$$d[n] = wt(n, e, this.$$p_d, "toProp"), (r = this.$$c) == null || r.$set({ [n]: this.$$d[n] }));
350
+ }
351
+ disconnectedCallback() {
352
+ this.$$cn = !1, Promise.resolve().then(() => {
353
+ this.$$cn || (this.$$c.$destroy(), this.$$c = void 0);
354
+ });
355
+ }
356
+ $$g_p(n) {
357
+ return Object.keys(this.$$p_d).find(
358
+ (t) => this.$$p_d[t].attribute === n || !this.$$p_d[t].attribute && t.toLowerCase() === n
359
+ ) || n;
360
+ }
361
+ });
362
+ function wt(s, n, t, e) {
363
+ var i;
364
+ const r = (i = t[s]) == null ? void 0 : i.type;
365
+ if (n = r === "Boolean" && typeof n != "boolean" ? n != null : n, !e || !t[s])
366
+ return n;
367
+ if (e === "toAttribute")
368
+ switch (r) {
369
+ case "Object":
370
+ case "Array":
371
+ return n == null ? null : JSON.stringify(n);
372
+ case "Boolean":
373
+ return n ? "" : null;
374
+ case "Number":
375
+ return n ?? null;
376
+ default:
377
+ return n;
378
+ }
379
+ else
380
+ switch (r) {
381
+ case "Object":
382
+ case "Array":
383
+ return n && JSON.parse(n);
384
+ case "Boolean":
385
+ return n;
386
+ case "Number":
387
+ return n != null ? +n : n;
388
+ default:
389
+ return n;
390
+ }
391
+ }
392
+ function Qe(s, n, t, e, r, i) {
393
+ let o = class extends ue {
394
+ constructor() {
395
+ super(s, t, r), this.$$p_d = n;
396
+ }
397
+ static get observedAttributes() {
398
+ return Object.keys(n).map(
399
+ (h) => (n[h].attribute || h).toLowerCase()
400
+ );
401
+ }
402
+ };
403
+ return Object.keys(n).forEach((h) => {
404
+ Object.defineProperty(o.prototype, h, {
405
+ get() {
406
+ return this.$$c && h in this.$$c ? this.$$c[h] : this.$$d[h];
407
+ },
408
+ set(p) {
409
+ var d;
410
+ p = wt(h, p, n), this.$$d[h] = p, (d = this.$$c) == null || d.$set({ [h]: p });
411
+ }
412
+ });
413
+ }), e.forEach((h) => {
414
+ Object.defineProperty(o.prototype, h, {
415
+ get() {
416
+ var p;
417
+ return (p = this.$$c) == null ? void 0 : p[h];
418
+ }
419
+ });
420
+ }), i && (o = i(o)), s.element = /** @type {any} */
421
+ o, o;
422
+ }
423
+ class Ke {
424
+ constructor() {
425
+ /**
426
+ * ### PRIVATE API
427
+ *
428
+ * Do not use, may change at any time
429
+ *
430
+ * @type {any}
431
+ */
432
+ f(this, "$$");
433
+ /**
434
+ * ### PRIVATE API
435
+ *
436
+ * Do not use, may change at any time
437
+ *
438
+ * @type {any}
439
+ */
440
+ f(this, "$$set");
441
+ }
442
+ /** @returns {void} */
443
+ $destroy() {
444
+ Xe(this, 1), this.$destroy = ht;
445
+ }
446
+ /**
447
+ * @template {Extract<keyof Events, string>} K
448
+ * @param {K} type
449
+ * @param {((e: Events[K]) => void) | null | undefined} callback
450
+ * @returns {() => void}
451
+ */
452
+ $on(n, t) {
453
+ if (!ae(t))
454
+ return ht;
455
+ const e = this.$$.callbacks[n] || (this.$$.callbacks[n] = []);
456
+ return e.push(t), () => {
457
+ const r = e.indexOf(t);
458
+ r !== -1 && e.splice(r, 1);
459
+ };
460
+ }
461
+ /**
462
+ * @param {Partial<Props>} props
463
+ * @returns {void}
464
+ */
465
+ $set(n) {
466
+ this.$$set && !Me(n) && (this.$$.skip_bound = !0, this.$$set(n), this.$$.skip_bound = !1);
467
+ }
468
+ }
469
+ const ts = "4";
470
+ typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(ts);
471
+ const { isArray: es } = Array, ss = Object.keys, lt = (s) => {
472
+ if (!s)
473
+ return s;
474
+ if (es(s)) {
475
+ const n = [], t = s.length;
476
+ for (let e = 0; e < t; e++)
477
+ n.push(lt(s[e]));
478
+ return n;
479
+ } else if (typeof s == "object") {
480
+ const n = ss(s), t = n.length, e = {};
481
+ for (let r = 0; r < t; r++) {
482
+ const i = n[r];
483
+ e[i] = lt(s[i]);
484
+ }
485
+ return e;
486
+ }
487
+ return s;
488
+ };
489
+ class D {
490
+ constructor(n) {
491
+ f(this, "path");
492
+ f(this, "from");
493
+ this.path = n;
494
+ }
495
+ }
496
+ const ns = /~1/g, rs = /~0/g, is = /~/g, os = /\//g;
497
+ function as(s) {
498
+ return s.indexOf("~") === -1 ? s : s.replace(ns, "/").replace(rs, "~");
499
+ }
500
+ function hs(s) {
501
+ return s.indexOf("/") === -1 && s.indexOf("~") === -1 ? s : s.replace(is, "~0").replace(os, "~1");
502
+ }
503
+ function cs(s) {
504
+ return s ? s.slice(1).split("/").map(as) : [];
505
+ }
506
+ function C(s) {
507
+ return ls(s) ? "" : "/" + s.map((n) => hs(String(n))).join("/");
508
+ }
509
+ const w = (s) => typeof s == "string" ? cs(s) : s, ls = (s) => !s.length, us = Object.prototype.hasOwnProperty;
510
+ function ps(s, n) {
511
+ return us.call(s, n);
512
+ }
513
+ const { isArray: pe } = Array, O = (s, n) => {
514
+ const t = n.length;
515
+ if (!t)
516
+ return { val: s };
517
+ let e, r;
518
+ for (let o = 0; o < t; o++)
519
+ if (e = s, r = n[o], pe(e)) {
520
+ const h = e.length;
521
+ if (r === "-")
522
+ r = h;
523
+ else if (typeof r == "string") {
524
+ const p = ~~r;
525
+ if ("" + p !== r)
526
+ throw new Error("INVALID_INDEX");
527
+ if (r = p, r < 0)
528
+ throw new Error("INVALID_INDEX");
529
+ }
530
+ s = e[r];
531
+ } else if (typeof e == "object" && e)
532
+ s = ps(e, r) ? e[r] : void 0;
533
+ else
534
+ throw new Error("NOT_FOUND");
535
+ return { val: s, obj: e, key: r };
536
+ }, ft = (s) => pe(s.obj) && typeof s.key == "number", kt = (s) => typeof s.obj == "object" && typeof s.key == "string";
537
+ class It extends D {
538
+ constructor(t, e) {
539
+ super(t);
540
+ f(this, "value");
541
+ this.value = e;
542
+ }
543
+ op() {
544
+ return "add";
545
+ }
546
+ code() {
547
+ return 0;
548
+ }
549
+ apply(t) {
550
+ const { val: e, key: r, obj: i } = O(t, this.path), o = lt(this.value);
551
+ if (!i)
552
+ t = o;
553
+ else if (typeof r == "string")
554
+ i[r] = o;
555
+ else {
556
+ const h = i.length;
557
+ if (r < h)
558
+ i.splice(r, 0, o);
559
+ else {
560
+ if (r > h)
561
+ throw new Error("INVALID_INDEX");
562
+ i.push(o);
563
+ }
564
+ }
565
+ return { doc: t, old: e };
566
+ }
567
+ toJson(t) {
568
+ return {
569
+ op: "add",
570
+ path: C(this.path),
571
+ value: this.value
572
+ };
573
+ }
574
+ toCompact(t, e) {
575
+ return [e ? "add" : 0, this.path, this.value];
576
+ }
577
+ encode(t) {
578
+ t.encodeArrayHeader(3), t.writer.u8(0), t.encodeArray(this.path), t.encodeAny(this.value);
579
+ }
580
+ }
581
+ class fe extends D {
582
+ constructor(t, e) {
583
+ super(t);
584
+ f(this, "oldValue");
585
+ this.oldValue = e;
586
+ }
587
+ op() {
588
+ return "remove";
589
+ }
590
+ code() {
591
+ return 1;
592
+ }
593
+ apply(t) {
594
+ const e = O(t, this.path);
595
+ if (e.val === void 0)
596
+ throw new Error("NOT_FOUND");
597
+ return kt(e) ? delete e.obj[e.key] : ft(e) ? e.val !== void 0 && e.obj.splice(e.key, 1) : t = null, { doc: t, old: e.val };
598
+ }
599
+ toJson(t) {
600
+ const e = {
601
+ op: "remove",
602
+ path: C(this.path)
603
+ };
604
+ return this.oldValue !== void 0 && (e.oldValue = this.oldValue), e;
605
+ }
606
+ toCompact(t, e) {
607
+ const r = e ? "remove" : 1;
608
+ return this.oldValue === void 0 ? [r, this.path] : [r, this.path, this.oldValue];
609
+ }
610
+ encode(t, e) {
611
+ const r = this.oldValue !== void 0;
612
+ t.encodeArrayHeader(r ? 3 : 2), t.writer.u8(1), t.encodeArray(this.path), r && t.encodeAny(this.oldValue);
613
+ }
614
+ }
615
+ class fs extends D {
616
+ constructor(t, e, r) {
617
+ super(t);
618
+ f(this, "value");
619
+ f(this, "oldValue");
620
+ this.value = e, this.oldValue = r;
621
+ }
622
+ op() {
623
+ return "replace";
624
+ }
625
+ code() {
626
+ return 2;
627
+ }
628
+ apply(t) {
629
+ const e = O(t, this.path);
630
+ if (e.val === void 0)
631
+ throw new Error("NOT_FOUND");
632
+ return kt(e) ? e.obj[e.key] = this.value : ft(e) ? e.obj[e.key] = this.value : t = this.value, { doc: t, old: e.val };
633
+ }
634
+ toJson(t) {
635
+ const e = {
636
+ op: "replace",
637
+ path: C(this.path),
638
+ value: this.value
639
+ };
640
+ return this.oldValue !== void 0 && (e.oldValue = this.oldValue), e;
641
+ }
642
+ toCompact(t, e) {
643
+ const r = e ? "replace" : 2;
644
+ return this.oldValue === void 0 ? [r, this.path, this.value] : [r, this.path, this.value, this.oldValue];
645
+ }
646
+ encode(t, e) {
647
+ const r = this.oldValue !== void 0;
648
+ t.encodeArrayHeader(r ? 4 : 3), t.writer.u8(2), t.encodeArray(this.path), t.encodeAny(this.value), r && t.encodeAny(this.oldValue);
649
+ }
650
+ }
651
+ class ds extends D {
652
+ constructor(t, e) {
653
+ super(t);
654
+ f(this, "from");
655
+ this.from = e;
656
+ }
657
+ op() {
658
+ return "move";
659
+ }
660
+ code() {
661
+ return 4;
662
+ }
663
+ apply(t) {
664
+ const e = new fe(w(this.from), void 0).apply(t);
665
+ return new It(this.path, e.old).apply(e.doc);
666
+ }
667
+ toJson(t) {
668
+ return {
669
+ op: "move",
670
+ path: C(this.path),
671
+ from: C(this.from)
672
+ };
673
+ }
674
+ toCompact(t, e) {
675
+ return [e ? "move" : 4, this.path, this.from];
676
+ }
677
+ encode(t, e) {
678
+ t.encodeArrayHeader(3), t.writer.u8(4), t.encodeArray(this.path), t.encodeArray(this.from);
679
+ }
680
+ }
681
+ class gs extends D {
682
+ constructor(t, e) {
683
+ super(t);
684
+ f(this, "from");
685
+ this.from = e;
686
+ }
687
+ op() {
688
+ return "copy";
689
+ }
690
+ code() {
691
+ return 3;
692
+ }
693
+ apply(t) {
694
+ const { val: e } = O(t, this.from);
695
+ if (e === void 0)
696
+ throw new Error("NOT_FOUND");
697
+ return new It(this.path, lt(e)).apply(t);
698
+ }
699
+ toJson(t) {
700
+ return {
701
+ op: "copy",
702
+ path: C(this.path),
703
+ from: C(this.from)
704
+ };
705
+ }
706
+ toCompact(t, e) {
707
+ return [e ? "copy" : 3, this.path, this.from];
708
+ }
709
+ encode(t, e) {
710
+ t.encodeArrayHeader(3), t.writer.u8(3), t.encodeArray(this.path), t.encodeArray(this.from);
711
+ }
712
+ }
713
+ class P extends D {
714
+ apply(n) {
715
+ if (!this.test(n))
716
+ throw new Error("TEST");
717
+ return { doc: n };
718
+ }
719
+ }
720
+ const Et = (s, n) => {
721
+ if (s === n)
722
+ return !0;
723
+ if (s && n && typeof s == "object" && typeof n == "object") {
724
+ if (s.constructor !== n.constructor)
725
+ return !1;
726
+ let t, e, r;
727
+ if (Array.isArray(s)) {
728
+ if (t = s.length, t !== n.length)
729
+ return !1;
730
+ for (e = t; e-- !== 0; )
731
+ if (!Et(s[e], n[e]))
732
+ return !1;
733
+ return !0;
734
+ }
735
+ if (r = Object.keys(s), t = r.length, t !== Object.keys(n).length)
736
+ return !1;
737
+ for (e = t; e-- !== 0; ) {
738
+ const i = r[e];
739
+ if (!Et(s[i], n[i]))
740
+ return !1;
741
+ }
742
+ return !0;
743
+ }
744
+ return !1;
745
+ };
746
+ class vs extends P {
747
+ constructor(t, e, r) {
748
+ super(t);
749
+ f(this, "value");
750
+ f(this, "not");
751
+ this.value = e, this.not = r;
752
+ }
753
+ op() {
754
+ return "test";
755
+ }
756
+ code() {
757
+ return 5;
758
+ }
759
+ test(t) {
760
+ const { val: e } = O(t, this.path);
761
+ if (e === void 0)
762
+ return !!this.not;
763
+ const r = Et(e, this.value);
764
+ return this.not ? !r : r;
765
+ }
766
+ toJson(t) {
767
+ const e = {
768
+ op: "test",
769
+ path: C(t ? this.path.slice(t.path.length) : this.path),
770
+ value: this.value
771
+ };
772
+ return this.not && (e.not = this.not), e;
773
+ }
774
+ toCompact(t, e) {
775
+ const r = t ? this.path.slice(t.path.length) : this.path, i = e ? "test" : 5;
776
+ return this.not ? [i, r, this.value, 1] : [i, r, this.value];
777
+ }
778
+ encode(t, e) {
779
+ t.encodeArrayHeader(this.not ? 4 : 3), t.writer.u8(5), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeAny(this.value), this.not && t.writer.u8(1);
780
+ }
781
+ }
782
+ class ys extends D {
783
+ constructor(n) {
784
+ super(n);
785
+ }
786
+ op() {
787
+ return "flip";
788
+ }
789
+ code() {
790
+ return 8;
791
+ }
792
+ apply(n) {
793
+ const t = O(n, this.path);
794
+ return t.obj ? t.obj[t.key] = !t.val : n = !t.val, { doc: n, old: t.val };
795
+ }
796
+ toJson(n) {
797
+ return {
798
+ op: "flip",
799
+ path: C(this.path)
800
+ };
801
+ }
802
+ toCompact(n, t) {
803
+ return [t ? "flip" : 8, this.path];
804
+ }
805
+ encode(n, t) {
806
+ n.encodeArrayHeader(2), n.writer.u8(8), n.encodeArray(this.path);
807
+ }
808
+ }
809
+ class ms extends D {
810
+ constructor(t, e) {
811
+ super(t);
812
+ f(this, "inc");
813
+ this.inc = e;
814
+ }
815
+ op() {
816
+ return "inc";
817
+ }
818
+ code() {
819
+ return 9;
820
+ }
821
+ apply(t) {
822
+ const e = O(t, this.path), r = this.inc + Number(e.val);
823
+ return e.obj ? e.obj[e.key] = r : t = r, { doc: t, old: e.val };
824
+ }
825
+ toJson(t) {
826
+ return {
827
+ op: "inc",
828
+ path: C(this.path),
829
+ inc: this.inc
830
+ };
831
+ }
832
+ toCompact(t, e) {
833
+ return [e ? "inc" : 9, this.path, this.inc];
834
+ }
835
+ encode(t, e) {
836
+ t.encodeArrayHeader(3), t.writer.u8(9), t.encodeArray(this.path), t.encodeNumber(this.inc);
837
+ }
838
+ }
839
+ class ws extends D {
840
+ constructor(t, e, r) {
841
+ super(t);
842
+ f(this, "pos");
843
+ f(this, "str");
844
+ this.pos = e, this.str = r;
845
+ }
846
+ op() {
847
+ return "str_ins";
848
+ }
849
+ code() {
850
+ return 6;
851
+ }
852
+ apply(t) {
853
+ const { val: e, key: r, obj: i } = O(t, this.path);
854
+ if (typeof e != "string") {
855
+ if (e !== void 0)
856
+ throw new Error("NOT_A_STRING");
857
+ if (this.pos !== 0)
858
+ throw new Error("POS");
859
+ }
860
+ const o = typeof e == "string" ? e : "", h = Math.min(this.pos, o.length), p = o.slice(0, h), d = o.slice(h), b = p + this.str + d;
861
+ return i ? i[r] = b : t = b, { doc: t, old: e };
862
+ }
863
+ toJson(t) {
864
+ return {
865
+ op: "str_ins",
866
+ path: C(this.path),
867
+ pos: this.pos,
868
+ str: this.str
869
+ };
870
+ }
871
+ toCompact(t, e) {
872
+ return [e ? "str_ins" : 6, this.path, this.pos, this.str];
873
+ }
874
+ encode(t, e) {
875
+ t.encodeArrayHeader(4), t.writer.u8(6), t.encodeArray(this.path), t.encodeNumber(this.pos), t.encodeString(this.str);
876
+ }
877
+ }
878
+ class _s extends D {
879
+ constructor(t, e, r, i) {
880
+ super(t);
881
+ f(this, "pos");
882
+ f(this, "str");
883
+ f(this, "len");
884
+ this.pos = e, this.str = r, this.len = i;
885
+ }
886
+ op() {
887
+ return "str_del";
888
+ }
889
+ code() {
890
+ return 7;
891
+ }
892
+ deleteLength() {
893
+ return typeof this.str == "string" ? this.str.length : this.len;
894
+ }
895
+ apply(t) {
896
+ const { val: e, key: r, obj: i } = O(t, this.path);
897
+ if (typeof e != "string")
898
+ throw new Error("NOT_A_STRING");
899
+ const o = e.length, h = Math.min(this.pos, e.length), p = Math.min(h, o), d = this.str !== void 0 ? this.str.length : this.len, b = Math.min(h + d, o), _ = e.slice(0, p), A = e.substr(b), T = _ + A;
900
+ return i ? i[r] = T : t = T, { doc: t, old: e };
901
+ }
902
+ toJson(t) {
903
+ return typeof this.str == "string" ? {
904
+ op: "str_del",
905
+ path: C(this.path),
906
+ pos: this.pos,
907
+ str: this.str
908
+ } : {
909
+ op: "str_del",
910
+ path: C(this.path),
911
+ pos: this.pos,
912
+ len: this.len
913
+ };
914
+ }
915
+ toCompact(t, e) {
916
+ const r = e ? "str_del" : 7;
917
+ return typeof this.str == "string" ? [r, this.path, this.pos, this.str] : [r, this.path, this.pos, 0, this.len];
918
+ }
919
+ encode(t, e) {
920
+ const r = typeof this.str == "string";
921
+ t.encodeArrayHeader(r ? 4 : 5), t.writer.u8(7), t.encodeArray(this.path), t.encodeNumber(this.pos), r ? t.encodeString(this.str) : (t.writer.u8(0), t.encodeNumber(this.len));
922
+ }
923
+ }
924
+ const { isArray: bs } = Array, Rt = (s) => !!s && typeof s == "object" && typeof s.text == "string", Ht = (s) => !!s && typeof s == "object" && bs(s.children), Es = (s, n) => {
925
+ const t = new RegExp(s, n ? "i" : void 0);
926
+ return (e) => t.test(e);
927
+ };
928
+ class $s extends D {
929
+ constructor(t, e, r) {
930
+ super(t);
931
+ f(this, "pos");
932
+ f(this, "props");
933
+ this.pos = e, this.props = r;
934
+ }
935
+ op() {
936
+ return "split";
937
+ }
938
+ code() {
939
+ return 10;
940
+ }
941
+ apply(t) {
942
+ const e = O(t, this.path);
943
+ if (e.val === void 0)
944
+ throw new Error("NOT_FOUND");
945
+ const r = this.split(e.val);
946
+ return kt(e) ? e.obj[e.key] = r : ft(e) ? (e.obj[e.key] = r[0], e.obj.splice(e.key + 1, 0, r[1])) : t = r, { doc: t, old: e.val };
947
+ }
948
+ split(t) {
949
+ if (typeof t == "string") {
950
+ const { pos: e, props: r } = this, i = t.slice(0, e), o = t.slice(e);
951
+ return r ? [
952
+ {
953
+ ...r,
954
+ text: i
955
+ },
956
+ {
957
+ ...r,
958
+ text: o
959
+ }
960
+ ] : [i, o];
961
+ } else if (Rt(t)) {
962
+ const { pos: e, props: r } = this, i = t.text.slice(0, e), o = t.text.slice(e);
963
+ return [
964
+ {
965
+ ...t,
966
+ ...r,
967
+ text: i
968
+ },
969
+ {
970
+ ...t,
971
+ ...r,
972
+ text: o
973
+ }
974
+ ];
975
+ } else if (Ht(t)) {
976
+ const { pos: e, props: r } = this, i = t.children.slice(0, e), o = t.children.slice(e);
977
+ return [
978
+ {
979
+ ...t,
980
+ ...r,
981
+ children: i
982
+ },
983
+ {
984
+ ...t,
985
+ ...r,
986
+ children: o
987
+ }
988
+ ];
989
+ } else if (typeof t == "number") {
990
+ const { pos: e } = this;
991
+ return [e, t - e];
992
+ } else
993
+ return [t, t];
994
+ }
995
+ toJson(t) {
996
+ const e = {
997
+ op: "split",
998
+ path: C(this.path),
999
+ pos: this.pos
1000
+ };
1001
+ return this.props && (e.props = this.props), e;
1002
+ }
1003
+ toCompact(t, e) {
1004
+ const r = e ? "split" : 10;
1005
+ return this.props ? [r, this.path, this.pos, this.props] : [r, this.path, this.pos];
1006
+ }
1007
+ encode(t, e) {
1008
+ t.encodeArrayHeader(this.props ? 4 : 3), t.writer.u8(10), t.encodeArray(this.path), t.encodeNumber(this.pos), this.props && t.encodeObject(this.props);
1009
+ }
1010
+ }
1011
+ class Cs extends D {
1012
+ constructor(t, e, r) {
1013
+ super(t);
1014
+ f(this, "pos");
1015
+ f(this, "props");
1016
+ this.pos = e, this.props = r;
1017
+ }
1018
+ op() {
1019
+ return "merge";
1020
+ }
1021
+ code() {
1022
+ return 11;
1023
+ }
1024
+ apply(t) {
1025
+ const e = O(t, this.path);
1026
+ if (!ft(e))
1027
+ throw new Error("INVALID_TARGET");
1028
+ if (e.key <= 0)
1029
+ throw new Error("INVALID_KEY");
1030
+ const r = e.obj[e.key - 1], i = e.obj[e.key], o = this.merge(r, i);
1031
+ return e.obj[e.key - 1] = o, e.obj.splice(e.key, 1), { doc: t, old: [r, i] };
1032
+ }
1033
+ merge(t, e) {
1034
+ return typeof t == "string" && typeof e == "string" || typeof t == "number" && typeof e == "number" ? t + e : Rt(t) && Rt(e) ? { ...t, ...e, text: t.text + e.text } : Ht(t) && Ht(e) ? { ...t, ...e, children: [...t.children, ...e.children] } : [t, e];
1035
+ }
1036
+ toJson(t) {
1037
+ const e = {
1038
+ op: "merge",
1039
+ path: C(this.path),
1040
+ pos: this.pos
1041
+ };
1042
+ return this.props && (e.props = this.props), e;
1043
+ }
1044
+ toCompact(t, e) {
1045
+ const r = e ? "merge" : 11;
1046
+ return this.props ? [r, this.path, this.pos, this.props] : [r, this.path, this.pos];
1047
+ }
1048
+ encode(t, e) {
1049
+ t.encodeArrayHeader(this.props ? 4 : 3), t.writer.u8(11), t.encodeArray(this.path), t.encodeNumber(this.pos), this.props && t.encodeAny(this.props);
1050
+ }
1051
+ }
1052
+ const { isArray: ks } = Array;
1053
+ class As extends D {
1054
+ constructor(t, e, r) {
1055
+ super(t);
1056
+ f(this, "props");
1057
+ f(this, "deleteNull");
1058
+ this.props = e, this.deleteNull = r;
1059
+ }
1060
+ op() {
1061
+ return "extend";
1062
+ }
1063
+ code() {
1064
+ return 12;
1065
+ }
1066
+ apply(t) {
1067
+ const e = O(t, this.path);
1068
+ return ft(e) ? e.val !== void 0 && (e.obj[e.key] = this.extend(e.val)) : kt(e) ? e.obj[e.key] = this.extend(e.val) : t = this.extend(t), { doc: t };
1069
+ }
1070
+ extend(t) {
1071
+ if (ks(t) || typeof t != "object" || !t)
1072
+ return t;
1073
+ for (const [e, r] of Object.entries(this.props)) {
1074
+ if (e === "__proto__")
1075
+ throw new Error("NO_PROTO");
1076
+ if (r === null && this.deleteNull) {
1077
+ delete t[e];
1078
+ continue;
1079
+ }
1080
+ t[e] = r;
1081
+ }
1082
+ return t;
1083
+ }
1084
+ toJson(t) {
1085
+ const e = {
1086
+ op: "extend",
1087
+ path: C(this.path),
1088
+ props: this.props
1089
+ };
1090
+ return this.deleteNull && (e.deleteNull = this.deleteNull), e;
1091
+ }
1092
+ toCompact(t, e) {
1093
+ const r = e ? "extend" : 12;
1094
+ return this.deleteNull ? [r, this.path, this.props, 1] : [r, this.path, this.props];
1095
+ }
1096
+ encode(t, e) {
1097
+ const { deleteNull: r } = this;
1098
+ t.encodeArrayHeader(r ? 4 : 3), t.writer.u8(12), t.encodeArray(this.path), t.encodeObject(this.props), r && t.writer.u8(1);
1099
+ }
1100
+ }
1101
+ class Ts extends P {
1102
+ constructor(n) {
1103
+ super(n);
1104
+ }
1105
+ op() {
1106
+ return "defined";
1107
+ }
1108
+ code() {
1109
+ return 31;
1110
+ }
1111
+ test(n) {
1112
+ const { val: t } = O(n, this.path);
1113
+ return t !== void 0;
1114
+ }
1115
+ toJson(n) {
1116
+ return {
1117
+ op: "defined",
1118
+ path: C(n ? this.path.slice(n.path.length) : this.path)
1119
+ };
1120
+ }
1121
+ toCompact(n, t) {
1122
+ return [t ? "defined" : 31, n ? this.path.slice(n.path.length) : this.path];
1123
+ }
1124
+ encode(n, t) {
1125
+ n.encodeArrayHeader(2), n.writer.u8(31), n.encodeArray(t ? this.path.slice(t.path.length) : this.path);
1126
+ }
1127
+ }
1128
+ class Os extends P {
1129
+ constructor(n) {
1130
+ super(n);
1131
+ }
1132
+ op() {
1133
+ return "undefined";
1134
+ }
1135
+ code() {
1136
+ return 38;
1137
+ }
1138
+ test(n) {
1139
+ try {
1140
+ const { val: t } = O(n, this.path);
1141
+ return t === void 0;
1142
+ } catch (t) {
1143
+ if (t.message === "NOT_FOUND")
1144
+ return !0;
1145
+ throw t;
1146
+ }
1147
+ }
1148
+ toJson(n) {
1149
+ return {
1150
+ op: "undefined",
1151
+ path: C(n ? this.path.slice(n.path.length) : this.path)
1152
+ };
1153
+ }
1154
+ toCompact(n, t) {
1155
+ return [t ? "undefined" : 38, n ? this.path.slice(n.path.length) : this.path];
1156
+ }
1157
+ encode(n, t) {
1158
+ n.encodeArrayHeader(2), n.writer.u8(38), n.encodeArray(t ? this.path.slice(t.path.length) : this.path);
1159
+ }
1160
+ }
1161
+ const { isArray: js } = Array;
1162
+ class xs extends P {
1163
+ constructor(t, e) {
1164
+ super(t);
1165
+ f(this, "type");
1166
+ this.type = e;
1167
+ }
1168
+ op() {
1169
+ return "test_type";
1170
+ }
1171
+ code() {
1172
+ return 39;
1173
+ }
1174
+ test(t) {
1175
+ const { val: e } = O(t, this.path);
1176
+ return e === null ? this.type.indexOf("null") > -1 : js(e) ? this.type.indexOf("array") > -1 : this.type.indexOf(typeof e) > -1 || typeof e == "number" && e === Math.round(e) && this.type.indexOf("integer") > -1;
1177
+ }
1178
+ toJson(t) {
1179
+ return {
1180
+ op: "test_type",
1181
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1182
+ type: this.type
1183
+ };
1184
+ }
1185
+ toCompact(t, e) {
1186
+ return [e ? "test_type" : 39, t ? this.path.slice(t.path.length) : this.path, this.type];
1187
+ }
1188
+ encode(t, e) {
1189
+ t.encodeArrayHeader(3), t.writer.u8(39), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeArray(this.type);
1190
+ }
1191
+ }
1192
+ class Ss extends P {
1193
+ constructor(t, e, r, i) {
1194
+ super(t);
1195
+ f(this, "pos");
1196
+ f(this, "str");
1197
+ f(this, "not");
1198
+ this.pos = e, this.str = r, this.not = i;
1199
+ }
1200
+ op() {
1201
+ return "test_string";
1202
+ }
1203
+ code() {
1204
+ return 40;
1205
+ }
1206
+ test(t) {
1207
+ const { val: e } = O(t, this.path);
1208
+ if (typeof e != "string")
1209
+ return !1;
1210
+ const r = e.length, i = Math.min(this.pos, r), o = Math.min(this.pos + this.str.length, r), h = e.substring(i, o) === this.str;
1211
+ return this.not ? !h : h;
1212
+ }
1213
+ toJson(t) {
1214
+ const e = {
1215
+ op: "test_string",
1216
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1217
+ pos: this.pos,
1218
+ str: this.str
1219
+ };
1220
+ return this.not && (e.not = this.not), e;
1221
+ }
1222
+ toCompact(t, e) {
1223
+ const r = e ? "test_string" : 40, i = t ? this.path.slice(t.path.length) : this.path;
1224
+ return this.not ? [r, i, this.pos, this.str, 1] : [r, i, this.pos, this.str];
1225
+ }
1226
+ encode(t, e) {
1227
+ t.encodeArrayHeader(this.not ? 5 : 4), t.writer.u8(40), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeNumber(this.pos), t.encodeString(this.str), this.not && t.writer.u8(1);
1228
+ }
1229
+ }
1230
+ class Ms extends P {
1231
+ constructor(t, e, r) {
1232
+ super(t);
1233
+ f(this, "len");
1234
+ f(this, "not");
1235
+ this.len = e, this.not = r;
1236
+ }
1237
+ op() {
1238
+ return "test_string_len";
1239
+ }
1240
+ code() {
1241
+ return 41;
1242
+ }
1243
+ test(t) {
1244
+ const { val: e } = O(t, this.path);
1245
+ if (typeof e != "string")
1246
+ return !1;
1247
+ const i = e.length >= this.len;
1248
+ return this.not ? !i : i;
1249
+ }
1250
+ toJson(t) {
1251
+ const e = {
1252
+ op: "test_string_len",
1253
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1254
+ len: this.len
1255
+ };
1256
+ return this.not && (e.not = this.not), e;
1257
+ }
1258
+ toCompact(t, e) {
1259
+ const r = e ? "test_string_len" : 41, i = t ? this.path.slice(t.path.length) : this.path;
1260
+ return this.not ? [r, i, this.len, 1] : [r, i, this.len];
1261
+ }
1262
+ encode(t, e) {
1263
+ t.encodeArrayHeader(this.not ? 4 : 3), t.writer.u8(41), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeNumber(this.len), this.not && t.writer.u8(1);
1264
+ }
1265
+ }
1266
+ class Ns extends P {
1267
+ constructor(t, e, r) {
1268
+ super(t);
1269
+ f(this, "value");
1270
+ f(this, "ignore_case");
1271
+ this.value = e, this.ignore_case = r;
1272
+ }
1273
+ op() {
1274
+ return "contains";
1275
+ }
1276
+ code() {
1277
+ return 30;
1278
+ }
1279
+ test(t) {
1280
+ const { val: e } = O(t, this.path);
1281
+ if (typeof e != "string")
1282
+ return !1;
1283
+ const r = this.ignore_case ? e.toLowerCase() : e, i = this.ignore_case ? this.value.toLowerCase() : this.value;
1284
+ return r.indexOf(i) > -1;
1285
+ }
1286
+ toJson(t) {
1287
+ const e = {
1288
+ op: "contains",
1289
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1290
+ value: this.value
1291
+ };
1292
+ return this.ignore_case && (e.ignore_case = this.ignore_case), e;
1293
+ }
1294
+ toCompact(t, e) {
1295
+ const r = e ? "contains" : 30;
1296
+ return this.ignore_case ? [r, t ? this.path.slice(t.path.length) : this.path, this.value, 1] : [r, t ? this.path.slice(t.path.length) : this.path, this.value];
1297
+ }
1298
+ encode(t, e) {
1299
+ const r = this.ignore_case;
1300
+ t.encodeArrayHeader(r ? 4 : 3), t.writer.u8(30), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeString(this.value), r && t.writer.u8(1);
1301
+ }
1302
+ }
1303
+ class Ls extends P {
1304
+ constructor(t, e, r) {
1305
+ super(t);
1306
+ f(this, "value");
1307
+ f(this, "ignore_case");
1308
+ this.value = e, this.ignore_case = r;
1309
+ }
1310
+ op() {
1311
+ return "ends";
1312
+ }
1313
+ code() {
1314
+ return 32;
1315
+ }
1316
+ test(t) {
1317
+ const { val: e } = O(t, this.path);
1318
+ if (typeof e != "string")
1319
+ return !1;
1320
+ const r = this.ignore_case ? e.toLowerCase() : e, i = this.ignore_case ? this.value.toLowerCase() : this.value;
1321
+ return r.endsWith(i);
1322
+ }
1323
+ toJson(t) {
1324
+ const e = {
1325
+ op: "ends",
1326
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1327
+ value: this.value
1328
+ };
1329
+ return this.ignore_case && (e.ignore_case = this.ignore_case), e;
1330
+ }
1331
+ toCompact(t, e) {
1332
+ const r = e ? "ends" : 32;
1333
+ return this.ignore_case ? [r, t ? this.path.slice(t.path.length) : this.path, this.value, 1] : [r, t ? this.path.slice(t.path.length) : this.path, this.value];
1334
+ }
1335
+ encode(t, e) {
1336
+ const r = this.ignore_case;
1337
+ t.encodeArrayHeader(r ? 4 : 3), t.writer.u8(32), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeString(this.value), r && t.writer.u8(1);
1338
+ }
1339
+ }
1340
+ class Rs extends P {
1341
+ constructor(t, e, r) {
1342
+ super(t);
1343
+ f(this, "value");
1344
+ f(this, "ignore_case");
1345
+ this.value = e, this.ignore_case = r;
1346
+ }
1347
+ op() {
1348
+ return "starts";
1349
+ }
1350
+ code() {
1351
+ return 37;
1352
+ }
1353
+ test(t) {
1354
+ const { val: e } = O(t, this.path);
1355
+ if (typeof e != "string")
1356
+ return !1;
1357
+ const r = this.ignore_case ? e.toLowerCase() : e, i = this.ignore_case ? this.value.toLowerCase() : this.value;
1358
+ return r.startsWith(i);
1359
+ }
1360
+ toJson(t) {
1361
+ const e = {
1362
+ op: "starts",
1363
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1364
+ value: this.value
1365
+ };
1366
+ return this.ignore_case && (e.ignore_case = this.ignore_case), e;
1367
+ }
1368
+ toCompact(t, e) {
1369
+ const r = e ? "starts" : 37;
1370
+ return this.ignore_case ? [r, t ? this.path.slice(t.path.length) : this.path, this.value, 1] : [r, t ? this.path.slice(t.path.length) : this.path, this.value];
1371
+ }
1372
+ encode(t, e) {
1373
+ const r = this.ignore_case;
1374
+ t.encodeArrayHeader(r ? 4 : 3), t.writer.u8(37), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeString(this.value), r && t.writer.u8(1);
1375
+ }
1376
+ }
1377
+ class Hs extends P {
1378
+ constructor(t, e) {
1379
+ super(t);
1380
+ f(this, "value");
1381
+ this.value = e;
1382
+ }
1383
+ op() {
1384
+ return "in";
1385
+ }
1386
+ code() {
1387
+ return 33;
1388
+ }
1389
+ test(t) {
1390
+ const { val: e } = O(t, this.path);
1391
+ for (const r of this.value)
1392
+ if (Et(e, r))
1393
+ return !0;
1394
+ return !1;
1395
+ }
1396
+ toJson(t) {
1397
+ return {
1398
+ op: "in",
1399
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1400
+ value: this.value
1401
+ };
1402
+ }
1403
+ toCompact(t, e) {
1404
+ return [e ? "in" : 33, t ? this.path.slice(t.path.length) : this.path, this.value];
1405
+ }
1406
+ encode(t, e) {
1407
+ t.encodeArrayHeader(3), t.writer.u8(33), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeArray(this.value);
1408
+ }
1409
+ }
1410
+ class Ps extends P {
1411
+ constructor(t, e) {
1412
+ super(t);
1413
+ f(this, "value");
1414
+ this.value = e;
1415
+ }
1416
+ op() {
1417
+ return "less";
1418
+ }
1419
+ code() {
1420
+ return 34;
1421
+ }
1422
+ test(t) {
1423
+ const { val: e } = O(t, this.path);
1424
+ return typeof e != "number" ? !1 : e < this.value;
1425
+ }
1426
+ toJson(t) {
1427
+ return {
1428
+ op: "less",
1429
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1430
+ value: this.value
1431
+ };
1432
+ }
1433
+ toCompact(t, e) {
1434
+ return [e ? "less" : 34, t ? this.path.slice(t.path.length) : this.path, this.value];
1435
+ }
1436
+ encode(t, e) {
1437
+ t.encodeArrayHeader(3), t.writer.u8(34), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeNumber(this.value);
1438
+ }
1439
+ }
1440
+ class Is extends P {
1441
+ constructor(t, e) {
1442
+ super(t);
1443
+ f(this, "value");
1444
+ this.value = e;
1445
+ }
1446
+ op() {
1447
+ return "more";
1448
+ }
1449
+ code() {
1450
+ return 36;
1451
+ }
1452
+ test(t) {
1453
+ const { val: e } = O(t, this.path);
1454
+ return typeof e != "number" ? !1 : e > this.value;
1455
+ }
1456
+ toJson(t) {
1457
+ return {
1458
+ op: "more",
1459
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1460
+ value: this.value
1461
+ };
1462
+ }
1463
+ toCompact(t, e) {
1464
+ return [e ? "more" : 36, t ? this.path.slice(t.path.length) : this.path, this.value];
1465
+ }
1466
+ encode(t, e) {
1467
+ t.encodeArrayHeader(3), t.writer.u8(36), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeNumber(this.value);
1468
+ }
1469
+ }
1470
+ class Dt extends P {
1471
+ constructor(t, e) {
1472
+ super(t);
1473
+ f(this, "ops");
1474
+ this.ops = e;
1475
+ }
1476
+ }
1477
+ class Ds extends Dt {
1478
+ constructor(t, e) {
1479
+ super(t, e);
1480
+ f(this, "ops");
1481
+ this.ops = e;
1482
+ }
1483
+ op() {
1484
+ return "and";
1485
+ }
1486
+ code() {
1487
+ return 43;
1488
+ }
1489
+ test(t) {
1490
+ for (const e of this.ops)
1491
+ if (!e.test(t))
1492
+ return !1;
1493
+ return !0;
1494
+ }
1495
+ toJson(t) {
1496
+ return {
1497
+ op: "and",
1498
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1499
+ apply: this.ops.map((r) => r.toJson(this))
1500
+ };
1501
+ }
1502
+ toCompact(t, e) {
1503
+ return [
1504
+ e ? "and" : 43,
1505
+ t ? this.path.slice(t.path.length) : this.path,
1506
+ this.ops.map((i) => i.toCompact(this, e))
1507
+ ];
1508
+ }
1509
+ encode(t, e) {
1510
+ const r = e ? this.path.slice(e.path.length) : this.path;
1511
+ t.encodeArrayHeader(3), t.writer.u8(43), t.encodeArray(r);
1512
+ const i = this.ops.length;
1513
+ t.encodeArrayHeader(i);
1514
+ for (let o = 0; o < i; o++)
1515
+ this.ops[o].encode(t, this);
1516
+ }
1517
+ }
1518
+ class Us extends Dt {
1519
+ constructor(t, e) {
1520
+ super(t, e);
1521
+ f(this, "ops");
1522
+ this.ops = e;
1523
+ }
1524
+ op() {
1525
+ return "or";
1526
+ }
1527
+ code() {
1528
+ return 45;
1529
+ }
1530
+ test(t) {
1531
+ for (const e of this.ops)
1532
+ if (e.test(t))
1533
+ return !0;
1534
+ return !1;
1535
+ }
1536
+ toJson(t) {
1537
+ return {
1538
+ op: "or",
1539
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1540
+ apply: this.ops.map((r) => r.toJson(this))
1541
+ };
1542
+ }
1543
+ toCompact(t, e) {
1544
+ return [
1545
+ e ? "or" : 45,
1546
+ t ? this.path.slice(t.path.length) : this.path,
1547
+ this.ops.map((i) => i.toCompact(this, e))
1548
+ ];
1549
+ }
1550
+ encode(t, e) {
1551
+ t.encodeArrayHeader(3), t.writer.u8(45), t.encodeArray(e ? this.path.slice(e.path.length) : this.path);
1552
+ const r = this.ops.length;
1553
+ t.encodeArrayHeader(r);
1554
+ for (let i = 0; i < r; i++)
1555
+ this.ops[i].encode(t, this);
1556
+ }
1557
+ }
1558
+ class Js extends Dt {
1559
+ constructor(t, e) {
1560
+ super(t, e);
1561
+ f(this, "ops");
1562
+ this.ops = e;
1563
+ }
1564
+ op() {
1565
+ return "not";
1566
+ }
1567
+ code() {
1568
+ return 44;
1569
+ }
1570
+ test(t) {
1571
+ for (const e of this.ops)
1572
+ if (e.test(t))
1573
+ return !1;
1574
+ return !0;
1575
+ }
1576
+ toJson(t) {
1577
+ return {
1578
+ op: "not",
1579
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1580
+ apply: this.ops.map((r) => r.toJson(this))
1581
+ };
1582
+ }
1583
+ toCompact(t, e) {
1584
+ return [
1585
+ e ? "not" : 44,
1586
+ t ? this.path.slice(t.path.length) : this.path,
1587
+ this.ops.map((i) => i.toCompact(this, e))
1588
+ ];
1589
+ }
1590
+ encode(t, e) {
1591
+ t.encodeArrayHeader(3), t.writer.u8(44), t.encodeArray(e ? this.path.slice(e.path.length) : this.path);
1592
+ const r = this.ops.length;
1593
+ t.encodeArrayHeader(r);
1594
+ for (let i = 0; i < r; i++)
1595
+ this.ops[i].encode(t, this);
1596
+ }
1597
+ }
1598
+ class Vs extends P {
1599
+ constructor(t, e, r, i) {
1600
+ super(t);
1601
+ f(this, "value");
1602
+ f(this, "ignore_case");
1603
+ f(this, "matcher");
1604
+ this.value = e, this.ignore_case = r, this.matcher = i(e, r);
1605
+ }
1606
+ op() {
1607
+ return "matches";
1608
+ }
1609
+ code() {
1610
+ return 35;
1611
+ }
1612
+ test(t) {
1613
+ const { val: e } = O(t, this.path);
1614
+ return typeof e != "string" ? !1 : this.matcher(e);
1615
+ }
1616
+ toJson(t) {
1617
+ const e = {
1618
+ op: "matches",
1619
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1620
+ value: this.value
1621
+ };
1622
+ return this.ignore_case && (e.ignore_case = this.ignore_case), e;
1623
+ }
1624
+ toCompact(t, e) {
1625
+ const r = e ? "matches" : 35;
1626
+ return this.ignore_case ? [r, t ? this.path.slice(t.path.length) : this.path, this.value, 1] : [r, t ? this.path.slice(t.path.length) : this.path, this.value];
1627
+ }
1628
+ encode(t, e) {
1629
+ const r = this.ignore_case;
1630
+ t.encodeArrayHeader(r ? 4 : 3), t.writer.u8(35), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeString(this.value), r && t.writer.u8(1);
1631
+ }
1632
+ }
1633
+ const { isArray: qs } = Array;
1634
+ class Bs extends P {
1635
+ constructor(t, e) {
1636
+ super(t);
1637
+ f(this, "value");
1638
+ this.value = e;
1639
+ }
1640
+ op() {
1641
+ return "type";
1642
+ }
1643
+ code() {
1644
+ return 42;
1645
+ }
1646
+ test(t) {
1647
+ const { val: e } = O(t, this.path);
1648
+ return e === null ? this.value === "null" : qs(e) ? this.value === "array" : typeof e === this.value || typeof e == "number" && e === Math.round(e) && this.value === "integer";
1649
+ }
1650
+ toJson(t) {
1651
+ return {
1652
+ op: "type",
1653
+ path: C(t ? this.path.slice(t.path.length) : this.path),
1654
+ value: this.value
1655
+ };
1656
+ }
1657
+ toCompact(t, e) {
1658
+ return [e ? "type" : 42, t ? this.path.slice(t.path.length) : this.path, this.value];
1659
+ }
1660
+ encode(t, e) {
1661
+ t.encodeArrayHeader(3), t.writer.u8(42), t.encodeArray(e ? this.path.slice(e.path.length) : this.path), t.encodeString(this.value);
1662
+ }
1663
+ }
1664
+ const Fs = (s, n) => {
1665
+ switch (s.op) {
1666
+ case "add":
1667
+ return new It(w(s.path), s.value);
1668
+ case "remove":
1669
+ return new fe(w(s.path), s.oldValue);
1670
+ case "replace":
1671
+ return new fs(w(s.path), s.value, s.oldValue);
1672
+ case "move":
1673
+ return new ds(w(s.path), w(s.from));
1674
+ case "copy":
1675
+ return new gs(w(s.path), w(s.from));
1676
+ case "flip":
1677
+ return new ys(w(s.path));
1678
+ case "inc":
1679
+ return new ms(w(s.path), s.inc);
1680
+ case "str_ins":
1681
+ return new ws(w(s.path), s.pos, s.str);
1682
+ case "str_del":
1683
+ return new _s(w(s.path), s.pos, s.str, s.len);
1684
+ case "split":
1685
+ return new $s(w(s.path), s.pos, s.props || null);
1686
+ case "merge":
1687
+ return new Cs(w(s.path), s.pos, s.props || null);
1688
+ case "extend":
1689
+ return new As(w(s.path), s.props, !!s.deleteNull);
1690
+ default:
1691
+ return _t(s, n);
1692
+ }
1693
+ }, _t = (s, n) => {
1694
+ switch (s.op) {
1695
+ case "test":
1696
+ return new vs(w(s.path), s.value, !!s.not);
1697
+ case "defined":
1698
+ return new Ts(w(s.path));
1699
+ case "undefined":
1700
+ return new Os(w(s.path));
1701
+ case "type":
1702
+ return new Bs(w(s.path), s.value);
1703
+ case "test_type":
1704
+ return new xs(w(s.path), s.type);
1705
+ case "test_string":
1706
+ return new Ss(w(s.path), s.pos, s.str, !!s.not);
1707
+ case "test_string_len":
1708
+ return new Ms(w(s.path), s.len, !!s.not);
1709
+ case "contains":
1710
+ return new Ns(w(s.path), s.value, !!s.ignore_case);
1711
+ case "ends":
1712
+ return new Ls(w(s.path), s.value, !!s.ignore_case);
1713
+ case "starts":
1714
+ return new Rs(w(s.path), s.value, !!s.ignore_case);
1715
+ case "matches":
1716
+ return new Vs(w(s.path), s.value, !!s.ignore_case, n.createMatcher || Es);
1717
+ case "in":
1718
+ return new Hs(w(s.path), s.value);
1719
+ case "less":
1720
+ return new Ps(w(s.path), s.value);
1721
+ case "more":
1722
+ return new Is(w(s.path), s.value);
1723
+ case "and": {
1724
+ const t = w(s.path);
1725
+ return new Ds(t, s.apply.map((e) => _t({ ...e, path: [...t, ...w(e.path)] }, n)));
1726
+ }
1727
+ case "or": {
1728
+ const t = w(s.path);
1729
+ return new Us(t, s.apply.map((e) => _t({ ...e, path: [...t, ...w(e.path)] }, n)));
1730
+ }
1731
+ case "not": {
1732
+ const t = w(s.path);
1733
+ return new Js(t, s.apply.map((e) => _t({ ...e, path: [...t, ...w(e.path)] }, n)));
1734
+ }
1735
+ default:
1736
+ throw new Error("OP_UNKNOWN");
1737
+ }
1738
+ };
1739
+ function zs(s, n, t) {
1740
+ t.mutate || (s = lt(s));
1741
+ const e = [], r = n.length;
1742
+ for (let i = 0; i < r; i++) {
1743
+ const h = Fs(n[i], t).apply(s);
1744
+ s = h.doc, e.push(h);
1745
+ }
1746
+ return { doc: s, res: e };
1747
+ }
1748
+ var ot = (s) => typeof s == "function" ? s : function() {
1749
+ return s;
1750
+ }, Ws = typeof self < "u" ? self : null, rt = typeof window < "u" ? window : null, at = Ws || rt || at, Gs = "2.0.0", V = { connecting: 0, open: 1, closing: 2, closed: 3 }, Xs = 1e4, Ys = 1e3, I = {
1751
+ closed: "closed",
1752
+ errored: "errored",
1753
+ joined: "joined",
1754
+ joining: "joining",
1755
+ leaving: "leaving"
1756
+ }, F = {
1757
+ close: "phx_close",
1758
+ error: "phx_error",
1759
+ join: "phx_join",
1760
+ reply: "phx_reply",
1761
+ leave: "phx_leave"
1762
+ }, Pt = {
1763
+ longpoll: "longpoll",
1764
+ websocket: "websocket"
1765
+ }, Zs = {
1766
+ complete: 4
1767
+ }, yt = class {
1768
+ constructor(s, n, t, e) {
1769
+ this.channel = s, this.event = n, this.payload = t || function() {
1770
+ return {};
1771
+ }, this.receivedResp = null, this.timeout = e, this.timeoutTimer = null, this.recHooks = [], this.sent = !1;
1772
+ }
1773
+ resend(s) {
1774
+ this.timeout = s, this.reset(), this.send();
1775
+ }
1776
+ send() {
1777
+ this.hasReceived("timeout") || (this.startTimeout(), this.sent = !0, this.channel.socket.push({
1778
+ topic: this.channel.topic,
1779
+ event: this.event,
1780
+ payload: this.payload(),
1781
+ ref: this.ref,
1782
+ join_ref: this.channel.joinRef()
1783
+ }));
1784
+ }
1785
+ receive(s, n) {
1786
+ return this.hasReceived(s) && n(this.receivedResp.response), this.recHooks.push({ status: s, callback: n }), this;
1787
+ }
1788
+ reset() {
1789
+ this.cancelRefEvent(), this.ref = null, this.refEvent = null, this.receivedResp = null, this.sent = !1;
1790
+ }
1791
+ matchReceive({ status: s, response: n, _ref: t }) {
1792
+ this.recHooks.filter((e) => e.status === s).forEach((e) => e.callback(n));
1793
+ }
1794
+ cancelRefEvent() {
1795
+ this.refEvent && this.channel.off(this.refEvent);
1796
+ }
1797
+ cancelTimeout() {
1798
+ clearTimeout(this.timeoutTimer), this.timeoutTimer = null;
1799
+ }
1800
+ startTimeout() {
1801
+ this.timeoutTimer && this.cancelTimeout(), this.ref = this.channel.socket.makeRef(), this.refEvent = this.channel.replyEventName(this.ref), this.channel.on(this.refEvent, (s) => {
1802
+ this.cancelRefEvent(), this.cancelTimeout(), this.receivedResp = s, this.matchReceive(s);
1803
+ }), this.timeoutTimer = setTimeout(() => {
1804
+ this.trigger("timeout", {});
1805
+ }, this.timeout);
1806
+ }
1807
+ hasReceived(s) {
1808
+ return this.receivedResp && this.receivedResp.status === s;
1809
+ }
1810
+ trigger(s, n) {
1811
+ this.channel.trigger(this.refEvent, { status: s, response: n });
1812
+ }
1813
+ }, de = class {
1814
+ constructor(s, n) {
1815
+ this.callback = s, this.timerCalc = n, this.timer = null, this.tries = 0;
1816
+ }
1817
+ reset() {
1818
+ this.tries = 0, clearTimeout(this.timer);
1819
+ }
1820
+ scheduleTimeout() {
1821
+ clearTimeout(this.timer), this.timer = setTimeout(() => {
1822
+ this.tries = this.tries + 1, this.callback();
1823
+ }, this.timerCalc(this.tries + 1));
1824
+ }
1825
+ }, Qs = class {
1826
+ constructor(s, n, t) {
1827
+ this.state = I.closed, this.topic = s, this.params = ot(n || {}), this.socket = t, this.bindings = [], this.bindingRef = 0, this.timeout = this.socket.timeout, this.joinedOnce = !1, this.joinPush = new yt(this, F.join, this.params, this.timeout), this.pushBuffer = [], this.stateChangeRefs = [], this.rejoinTimer = new de(() => {
1828
+ this.socket.isConnected() && this.rejoin();
1829
+ }, this.socket.rejoinAfterMs), this.stateChangeRefs.push(this.socket.onError(() => this.rejoinTimer.reset())), this.stateChangeRefs.push(this.socket.onOpen(() => {
1830
+ this.rejoinTimer.reset(), this.isErrored() && this.rejoin();
1831
+ })), this.joinPush.receive("ok", () => {
1832
+ this.state = I.joined, this.rejoinTimer.reset(), this.pushBuffer.forEach((e) => e.send()), this.pushBuffer = [];
1833
+ }), this.joinPush.receive("error", () => {
1834
+ this.state = I.errored, this.socket.isConnected() && this.rejoinTimer.scheduleTimeout();
1835
+ }), this.onClose(() => {
1836
+ this.rejoinTimer.reset(), this.socket.hasLogger() && this.socket.log("channel", `close ${this.topic} ${this.joinRef()}`), this.state = I.closed, this.socket.remove(this);
1837
+ }), this.onError((e) => {
1838
+ this.socket.hasLogger() && this.socket.log("channel", `error ${this.topic}`, e), this.isJoining() && this.joinPush.reset(), this.state = I.errored, this.socket.isConnected() && this.rejoinTimer.scheduleTimeout();
1839
+ }), this.joinPush.receive("timeout", () => {
1840
+ this.socket.hasLogger() && this.socket.log("channel", `timeout ${this.topic} (${this.joinRef()})`, this.joinPush.timeout), new yt(this, F.leave, ot({}), this.timeout).send(), this.state = I.errored, this.joinPush.reset(), this.socket.isConnected() && this.rejoinTimer.scheduleTimeout();
1841
+ }), this.on(F.reply, (e, r) => {
1842
+ this.trigger(this.replyEventName(r), e);
1843
+ });
1844
+ }
1845
+ join(s = this.timeout) {
1846
+ if (this.joinedOnce)
1847
+ throw new Error("tried to join multiple times. 'join' can only be called a single time per channel instance");
1848
+ return this.timeout = s, this.joinedOnce = !0, this.rejoin(), this.joinPush;
1849
+ }
1850
+ onClose(s) {
1851
+ this.on(F.close, s);
1852
+ }
1853
+ onError(s) {
1854
+ return this.on(F.error, (n) => s(n));
1855
+ }
1856
+ on(s, n) {
1857
+ let t = this.bindingRef++;
1858
+ return this.bindings.push({ event: s, ref: t, callback: n }), t;
1859
+ }
1860
+ off(s, n) {
1861
+ this.bindings = this.bindings.filter((t) => !(t.event === s && (typeof n > "u" || n === t.ref)));
1862
+ }
1863
+ canPush() {
1864
+ return this.socket.isConnected() && this.isJoined();
1865
+ }
1866
+ push(s, n, t = this.timeout) {
1867
+ if (n = n || {}, !this.joinedOnce)
1868
+ throw new Error(`tried to push '${s}' to '${this.topic}' before joining. Use channel.join() before pushing events`);
1869
+ let e = new yt(this, s, function() {
1870
+ return n;
1871
+ }, t);
1872
+ return this.canPush() ? e.send() : (e.startTimeout(), this.pushBuffer.push(e)), e;
1873
+ }
1874
+ leave(s = this.timeout) {
1875
+ this.rejoinTimer.reset(), this.joinPush.cancelTimeout(), this.state = I.leaving;
1876
+ let n = () => {
1877
+ this.socket.hasLogger() && this.socket.log("channel", `leave ${this.topic}`), this.trigger(F.close, "leave");
1878
+ }, t = new yt(this, F.leave, ot({}), s);
1879
+ return t.receive("ok", () => n()).receive("timeout", () => n()), t.send(), this.canPush() || t.trigger("ok", {}), t;
1880
+ }
1881
+ onMessage(s, n, t) {
1882
+ return n;
1883
+ }
1884
+ isMember(s, n, t, e) {
1885
+ return this.topic !== s ? !1 : e && e !== this.joinRef() ? (this.socket.hasLogger() && this.socket.log("channel", "dropping outdated message", { topic: s, event: n, payload: t, joinRef: e }), !1) : !0;
1886
+ }
1887
+ joinRef() {
1888
+ return this.joinPush.ref;
1889
+ }
1890
+ rejoin(s = this.timeout) {
1891
+ this.isLeaving() || (this.socket.leaveOpenTopic(this.topic), this.state = I.joining, this.joinPush.resend(s));
1892
+ }
1893
+ trigger(s, n, t, e) {
1894
+ let r = this.onMessage(s, n, t, e);
1895
+ if (n && !r)
1896
+ throw new Error("channel onMessage callbacks must return the payload, modified or unmodified");
1897
+ let i = this.bindings.filter((o) => o.event === s);
1898
+ for (let o = 0; o < i.length; o++)
1899
+ i[o].callback(r, t, e || this.joinRef());
1900
+ }
1901
+ replyEventName(s) {
1902
+ return `chan_reply_${s}`;
1903
+ }
1904
+ isClosed() {
1905
+ return this.state === I.closed;
1906
+ }
1907
+ isErrored() {
1908
+ return this.state === I.errored;
1909
+ }
1910
+ isJoined() {
1911
+ return this.state === I.joined;
1912
+ }
1913
+ isJoining() {
1914
+ return this.state === I.joining;
1915
+ }
1916
+ isLeaving() {
1917
+ return this.state === I.leaving;
1918
+ }
1919
+ }, $t = class {
1920
+ static request(s, n, t, e, r, i, o) {
1921
+ if (at.XDomainRequest) {
1922
+ let h = new at.XDomainRequest();
1923
+ return this.xdomainRequest(h, s, n, e, r, i, o);
1924
+ } else {
1925
+ let h = new at.XMLHttpRequest();
1926
+ return this.xhrRequest(h, s, n, t, e, r, i, o);
1927
+ }
1928
+ }
1929
+ static xdomainRequest(s, n, t, e, r, i, o) {
1930
+ return s.timeout = r, s.open(n, t), s.onload = () => {
1931
+ let h = this.parseJSON(s.responseText);
1932
+ o && o(h);
1933
+ }, i && (s.ontimeout = i), s.onprogress = () => {
1934
+ }, s.send(e), s;
1935
+ }
1936
+ static xhrRequest(s, n, t, e, r, i, o, h) {
1937
+ return s.open(n, t, !0), s.timeout = i, s.setRequestHeader("Content-Type", e), s.onerror = () => h && h(null), s.onreadystatechange = () => {
1938
+ if (s.readyState === Zs.complete && h) {
1939
+ let p = this.parseJSON(s.responseText);
1940
+ h(p);
1941
+ }
1942
+ }, o && (s.ontimeout = o), s.send(r), s;
1943
+ }
1944
+ static parseJSON(s) {
1945
+ if (!s || s === "")
1946
+ return null;
1947
+ try {
1948
+ return JSON.parse(s);
1949
+ } catch {
1950
+ return console && console.log("failed to parse JSON response", s), null;
1951
+ }
1952
+ }
1953
+ static serialize(s, n) {
1954
+ let t = [];
1955
+ for (var e in s) {
1956
+ if (!Object.prototype.hasOwnProperty.call(s, e))
1957
+ continue;
1958
+ let r = n ? `${n}[${e}]` : e, i = s[e];
1959
+ typeof i == "object" ? t.push(this.serialize(i, r)) : t.push(encodeURIComponent(r) + "=" + encodeURIComponent(i));
1960
+ }
1961
+ return t.join("&");
1962
+ }
1963
+ static appendParams(s, n) {
1964
+ if (Object.keys(n).length === 0)
1965
+ return s;
1966
+ let t = s.match(/\?/) ? "&" : "?";
1967
+ return `${s}${t}${this.serialize(n)}`;
1968
+ }
1969
+ }, St = class {
1970
+ constructor(s) {
1971
+ this.endPoint = null, this.token = null, this.skipHeartbeat = !0, this.reqs = /* @__PURE__ */ new Set(), this.onopen = function() {
1972
+ }, this.onerror = function() {
1973
+ }, this.onmessage = function() {
1974
+ }, this.onclose = function() {
1975
+ }, this.pollEndpoint = this.normalizeEndpoint(s), this.readyState = V.connecting, this.poll();
1976
+ }
1977
+ normalizeEndpoint(s) {
1978
+ return s.replace("ws://", "http://").replace("wss://", "https://").replace(new RegExp("(.*)/" + Pt.websocket), "$1/" + Pt.longpoll);
1979
+ }
1980
+ endpointURL() {
1981
+ return $t.appendParams(this.pollEndpoint, { token: this.token });
1982
+ }
1983
+ closeAndRetry(s, n, t) {
1984
+ this.close(s, n, t), this.readyState = V.connecting;
1985
+ }
1986
+ ontimeout() {
1987
+ this.onerror("timeout"), this.closeAndRetry(1005, "timeout", !1);
1988
+ }
1989
+ isActive() {
1990
+ return this.readyState === V.open || this.readyState === V.connecting;
1991
+ }
1992
+ poll() {
1993
+ this.ajax("GET", null, () => this.ontimeout(), (s) => {
1994
+ if (s) {
1995
+ var { status: n, token: t, messages: e } = s;
1996
+ this.token = t;
1997
+ } else
1998
+ n = 0;
1999
+ switch (n) {
2000
+ case 200:
2001
+ e.forEach((r) => {
2002
+ setTimeout(() => this.onmessage({ data: r }), 0);
2003
+ }), this.poll();
2004
+ break;
2005
+ case 204:
2006
+ this.poll();
2007
+ break;
2008
+ case 410:
2009
+ this.readyState = V.open, this.onopen({}), this.poll();
2010
+ break;
2011
+ case 403:
2012
+ this.onerror(403), this.close(1008, "forbidden", !1);
2013
+ break;
2014
+ case 0:
2015
+ case 500:
2016
+ this.onerror(500), this.closeAndRetry(1011, "internal server error", 500);
2017
+ break;
2018
+ default:
2019
+ throw new Error(`unhandled poll status ${n}`);
2020
+ }
2021
+ });
2022
+ }
2023
+ send(s) {
2024
+ this.ajax("POST", s, () => this.onerror("timeout"), (n) => {
2025
+ (!n || n.status !== 200) && (this.onerror(n && n.status), this.closeAndRetry(1011, "internal server error", !1));
2026
+ });
2027
+ }
2028
+ close(s, n, t) {
2029
+ for (let r of this.reqs)
2030
+ r.abort();
2031
+ this.readyState = V.closed;
2032
+ let e = Object.assign({ code: 1e3, reason: void 0, wasClean: !0 }, { code: s, reason: n, wasClean: t });
2033
+ typeof CloseEvent < "u" ? this.onclose(new CloseEvent("close", e)) : this.onclose(e);
2034
+ }
2035
+ ajax(s, n, t, e) {
2036
+ let r, i = () => {
2037
+ this.reqs.delete(r), t();
2038
+ };
2039
+ r = $t.request(s, this.endpointURL(), "application/json", n, this.timeout, i, (o) => {
2040
+ this.reqs.delete(r), this.isActive() && e(o);
2041
+ }), this.reqs.add(r);
2042
+ }
2043
+ }, mt = {
2044
+ HEADER_LENGTH: 1,
2045
+ META_LENGTH: 4,
2046
+ KINDS: { push: 0, reply: 1, broadcast: 2 },
2047
+ encode(s, n) {
2048
+ if (s.payload.constructor === ArrayBuffer)
2049
+ return n(this.binaryEncode(s));
2050
+ {
2051
+ let t = [s.join_ref, s.ref, s.topic, s.event, s.payload];
2052
+ return n(JSON.stringify(t));
2053
+ }
2054
+ },
2055
+ decode(s, n) {
2056
+ if (s.constructor === ArrayBuffer)
2057
+ return n(this.binaryDecode(s));
2058
+ {
2059
+ let [t, e, r, i, o] = JSON.parse(s);
2060
+ return n({ join_ref: t, ref: e, topic: r, event: i, payload: o });
2061
+ }
2062
+ },
2063
+ binaryEncode(s) {
2064
+ let { join_ref: n, ref: t, event: e, topic: r, payload: i } = s, o = this.META_LENGTH + n.length + t.length + r.length + e.length, h = new ArrayBuffer(this.HEADER_LENGTH + o), p = new DataView(h), d = 0;
2065
+ p.setUint8(d++, this.KINDS.push), p.setUint8(d++, n.length), p.setUint8(d++, t.length), p.setUint8(d++, r.length), p.setUint8(d++, e.length), Array.from(n, (_) => p.setUint8(d++, _.charCodeAt(0))), Array.from(t, (_) => p.setUint8(d++, _.charCodeAt(0))), Array.from(r, (_) => p.setUint8(d++, _.charCodeAt(0))), Array.from(e, (_) => p.setUint8(d++, _.charCodeAt(0)));
2066
+ var b = new Uint8Array(h.byteLength + i.byteLength);
2067
+ return b.set(new Uint8Array(h), 0), b.set(new Uint8Array(i), h.byteLength), b.buffer;
2068
+ },
2069
+ binaryDecode(s) {
2070
+ let n = new DataView(s), t = n.getUint8(0), e = new TextDecoder();
2071
+ switch (t) {
2072
+ case this.KINDS.push:
2073
+ return this.decodePush(s, n, e);
2074
+ case this.KINDS.reply:
2075
+ return this.decodeReply(s, n, e);
2076
+ case this.KINDS.broadcast:
2077
+ return this.decodeBroadcast(s, n, e);
2078
+ }
2079
+ },
2080
+ decodePush(s, n, t) {
2081
+ let e = n.getUint8(1), r = n.getUint8(2), i = n.getUint8(3), o = this.HEADER_LENGTH + this.META_LENGTH - 1, h = t.decode(s.slice(o, o + e));
2082
+ o = o + e;
2083
+ let p = t.decode(s.slice(o, o + r));
2084
+ o = o + r;
2085
+ let d = t.decode(s.slice(o, o + i));
2086
+ o = o + i;
2087
+ let b = s.slice(o, s.byteLength);
2088
+ return { join_ref: h, ref: null, topic: p, event: d, payload: b };
2089
+ },
2090
+ decodeReply(s, n, t) {
2091
+ let e = n.getUint8(1), r = n.getUint8(2), i = n.getUint8(3), o = n.getUint8(4), h = this.HEADER_LENGTH + this.META_LENGTH, p = t.decode(s.slice(h, h + e));
2092
+ h = h + e;
2093
+ let d = t.decode(s.slice(h, h + r));
2094
+ h = h + r;
2095
+ let b = t.decode(s.slice(h, h + i));
2096
+ h = h + i;
2097
+ let _ = t.decode(s.slice(h, h + o));
2098
+ h = h + o;
2099
+ let A = s.slice(h, s.byteLength), T = { status: _, response: A };
2100
+ return { join_ref: p, ref: d, topic: b, event: F.reply, payload: T };
2101
+ },
2102
+ decodeBroadcast(s, n, t) {
2103
+ let e = n.getUint8(1), r = n.getUint8(2), i = this.HEADER_LENGTH + 2, o = t.decode(s.slice(i, i + e));
2104
+ i = i + e;
2105
+ let h = t.decode(s.slice(i, i + r));
2106
+ i = i + r;
2107
+ let p = s.slice(i, s.byteLength);
2108
+ return { join_ref: null, ref: null, topic: o, event: h, payload: p };
2109
+ }
2110
+ }, Ks = class {
2111
+ constructor(s, n = {}) {
2112
+ this.stateChangeCallbacks = { open: [], close: [], error: [], message: [] }, this.channels = [], this.sendBuffer = [], this.ref = 0, this.timeout = n.timeout || Xs, this.transport = n.transport || at.WebSocket || St, this.establishedConnections = 0, this.defaultEncoder = mt.encode.bind(mt), this.defaultDecoder = mt.decode.bind(mt), this.closeWasClean = !1, this.binaryType = n.binaryType || "arraybuffer", this.connectClock = 1, this.transport !== St ? (this.encode = n.encode || this.defaultEncoder, this.decode = n.decode || this.defaultDecoder) : (this.encode = this.defaultEncoder, this.decode = this.defaultDecoder);
2113
+ let t = null;
2114
+ rt && rt.addEventListener && (rt.addEventListener("pagehide", (e) => {
2115
+ this.conn && (this.disconnect(), t = this.connectClock);
2116
+ }), rt.addEventListener("pageshow", (e) => {
2117
+ t === this.connectClock && (t = null, this.connect());
2118
+ })), this.heartbeatIntervalMs = n.heartbeatIntervalMs || 3e4, this.rejoinAfterMs = (e) => n.rejoinAfterMs ? n.rejoinAfterMs(e) : [1e3, 2e3, 5e3][e - 1] || 1e4, this.reconnectAfterMs = (e) => n.reconnectAfterMs ? n.reconnectAfterMs(e) : [10, 50, 100, 150, 200, 250, 500, 1e3, 2e3][e - 1] || 5e3, this.logger = n.logger || null, this.longpollerTimeout = n.longpollerTimeout || 2e4, this.params = ot(n.params || {}), this.endPoint = `${s}/${Pt.websocket}`, this.vsn = n.vsn || Gs, this.heartbeatTimeoutTimer = null, this.heartbeatTimer = null, this.pendingHeartbeatRef = null, this.reconnectTimer = new de(() => {
2119
+ this.teardown(() => this.connect());
2120
+ }, this.reconnectAfterMs);
2121
+ }
2122
+ getLongPollTransport() {
2123
+ return St;
2124
+ }
2125
+ replaceTransport(s) {
2126
+ this.connectClock++, this.closeWasClean = !0, this.reconnectTimer.reset(), this.sendBuffer = [], this.conn && (this.conn.close(), this.conn = null), this.transport = s;
2127
+ }
2128
+ protocol() {
2129
+ return location.protocol.match(/^https/) ? "wss" : "ws";
2130
+ }
2131
+ endPointURL() {
2132
+ let s = $t.appendParams($t.appendParams(this.endPoint, this.params()), { vsn: this.vsn });
2133
+ return s.charAt(0) !== "/" ? s : s.charAt(1) === "/" ? `${this.protocol()}:${s}` : `${this.protocol()}://${location.host}${s}`;
2134
+ }
2135
+ disconnect(s, n, t) {
2136
+ this.connectClock++, this.closeWasClean = !0, this.reconnectTimer.reset(), this.teardown(s, n, t);
2137
+ }
2138
+ connect(s) {
2139
+ s && (console && console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor"), this.params = ot(s)), !this.conn && (this.connectClock++, this.closeWasClean = !1, this.conn = new this.transport(this.endPointURL()), this.conn.binaryType = this.binaryType, this.conn.timeout = this.longpollerTimeout, this.conn.onopen = () => this.onConnOpen(), this.conn.onerror = (n) => this.onConnError(n), this.conn.onmessage = (n) => this.onConnMessage(n), this.conn.onclose = (n) => this.onConnClose(n));
2140
+ }
2141
+ log(s, n, t) {
2142
+ this.logger(s, n, t);
2143
+ }
2144
+ hasLogger() {
2145
+ return this.logger !== null;
2146
+ }
2147
+ onOpen(s) {
2148
+ let n = this.makeRef();
2149
+ return this.stateChangeCallbacks.open.push([n, s]), n;
2150
+ }
2151
+ onClose(s) {
2152
+ let n = this.makeRef();
2153
+ return this.stateChangeCallbacks.close.push([n, s]), n;
2154
+ }
2155
+ onError(s) {
2156
+ let n = this.makeRef();
2157
+ return this.stateChangeCallbacks.error.push([n, s]), n;
2158
+ }
2159
+ onMessage(s) {
2160
+ let n = this.makeRef();
2161
+ return this.stateChangeCallbacks.message.push([n, s]), n;
2162
+ }
2163
+ ping(s) {
2164
+ if (!this.isConnected())
2165
+ return !1;
2166
+ let n = this.makeRef(), t = Date.now();
2167
+ this.push({ topic: "phoenix", event: "heartbeat", payload: {}, ref: n });
2168
+ let e = this.onMessage((r) => {
2169
+ r.ref === n && (this.off([e]), s(Date.now() - t));
2170
+ });
2171
+ return !0;
2172
+ }
2173
+ clearHeartbeats() {
2174
+ clearTimeout(this.heartbeatTimer), clearTimeout(this.heartbeatTimeoutTimer);
2175
+ }
2176
+ onConnOpen() {
2177
+ this.hasLogger() && this.log("transport", `connected to ${this.endPointURL()}`), this.closeWasClean = !1, this.establishedConnections++, this.flushSendBuffer(), this.reconnectTimer.reset(), this.resetHeartbeat(), this.stateChangeCallbacks.open.forEach(([, s]) => s());
2178
+ }
2179
+ heartbeatTimeout() {
2180
+ this.pendingHeartbeatRef && (this.pendingHeartbeatRef = null, this.hasLogger() && this.log("transport", "heartbeat timeout. Attempting to re-establish connection"), this.triggerChanError(), this.closeWasClean = !1, this.teardown(() => this.reconnectTimer.scheduleTimeout(), Ys, "heartbeat timeout"));
2181
+ }
2182
+ resetHeartbeat() {
2183
+ this.conn && this.conn.skipHeartbeat || (this.pendingHeartbeatRef = null, this.clearHeartbeats(), this.heartbeatTimer = setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs));
2184
+ }
2185
+ teardown(s, n, t) {
2186
+ if (!this.conn)
2187
+ return s && s();
2188
+ this.waitForBufferDone(() => {
2189
+ this.conn && (n ? this.conn.close(n, t || "") : this.conn.close()), this.waitForSocketClosed(() => {
2190
+ this.conn && (this.conn.onopen = function() {
2191
+ }, this.conn.onerror = function() {
2192
+ }, this.conn.onmessage = function() {
2193
+ }, this.conn.onclose = function() {
2194
+ }, this.conn = null), s && s();
2195
+ });
2196
+ });
2197
+ }
2198
+ waitForBufferDone(s, n = 1) {
2199
+ if (n === 5 || !this.conn || !this.conn.bufferedAmount) {
2200
+ s();
2201
+ return;
2202
+ }
2203
+ setTimeout(() => {
2204
+ this.waitForBufferDone(s, n + 1);
2205
+ }, 150 * n);
2206
+ }
2207
+ waitForSocketClosed(s, n = 1) {
2208
+ if (n === 5 || !this.conn || this.conn.readyState === V.closed) {
2209
+ s();
2210
+ return;
2211
+ }
2212
+ setTimeout(() => {
2213
+ this.waitForSocketClosed(s, n + 1);
2214
+ }, 150 * n);
2215
+ }
2216
+ onConnClose(s) {
2217
+ let n = s && s.code;
2218
+ this.hasLogger() && this.log("transport", "close", s), this.triggerChanError(), this.clearHeartbeats(), !this.closeWasClean && n !== 1e3 && this.reconnectTimer.scheduleTimeout(), this.stateChangeCallbacks.close.forEach(([, t]) => t(s));
2219
+ }
2220
+ onConnError(s) {
2221
+ this.hasLogger() && this.log("transport", s);
2222
+ let n = this.transport, t = this.establishedConnections;
2223
+ this.stateChangeCallbacks.error.forEach(([, e]) => {
2224
+ e(s, n, t);
2225
+ }), (n === this.transport || t > 0) && this.triggerChanError();
2226
+ }
2227
+ triggerChanError() {
2228
+ this.channels.forEach((s) => {
2229
+ s.isErrored() || s.isLeaving() || s.isClosed() || s.trigger(F.error);
2230
+ });
2231
+ }
2232
+ connectionState() {
2233
+ switch (this.conn && this.conn.readyState) {
2234
+ case V.connecting:
2235
+ return "connecting";
2236
+ case V.open:
2237
+ return "open";
2238
+ case V.closing:
2239
+ return "closing";
2240
+ default:
2241
+ return "closed";
2242
+ }
2243
+ }
2244
+ isConnected() {
2245
+ return this.connectionState() === "open";
2246
+ }
2247
+ remove(s) {
2248
+ this.off(s.stateChangeRefs), this.channels = this.channels.filter((n) => n.joinRef() !== s.joinRef());
2249
+ }
2250
+ off(s) {
2251
+ for (let n in this.stateChangeCallbacks)
2252
+ this.stateChangeCallbacks[n] = this.stateChangeCallbacks[n].filter(([t]) => s.indexOf(t) === -1);
2253
+ }
2254
+ channel(s, n = {}) {
2255
+ let t = new Qs(s, n, this);
2256
+ return this.channels.push(t), t;
2257
+ }
2258
+ push(s) {
2259
+ if (this.hasLogger()) {
2260
+ let { topic: n, event: t, payload: e, ref: r, join_ref: i } = s;
2261
+ this.log("push", `${n} ${t} (${i}, ${r})`, e);
2262
+ }
2263
+ this.isConnected() ? this.encode(s, (n) => this.conn.send(n)) : this.sendBuffer.push(() => this.encode(s, (n) => this.conn.send(n)));
2264
+ }
2265
+ makeRef() {
2266
+ let s = this.ref + 1;
2267
+ return s === this.ref ? this.ref = 0 : this.ref = s, this.ref.toString();
2268
+ }
2269
+ sendHeartbeat() {
2270
+ this.pendingHeartbeatRef && !this.isConnected() || (this.pendingHeartbeatRef = this.makeRef(), this.push({ topic: "phoenix", event: "heartbeat", payload: {}, ref: this.pendingHeartbeatRef }), this.heartbeatTimeoutTimer = setTimeout(() => this.heartbeatTimeout(), this.heartbeatIntervalMs));
2271
+ }
2272
+ flushSendBuffer() {
2273
+ this.isConnected() && this.sendBuffer.length > 0 && (this.sendBuffer.forEach((s) => s()), this.sendBuffer = []);
2274
+ }
2275
+ onConnMessage(s) {
2276
+ this.decode(s.data, (n) => {
2277
+ let { topic: t, event: e, payload: r, ref: i, join_ref: o } = n;
2278
+ i && i === this.pendingHeartbeatRef && (this.clearHeartbeats(), this.pendingHeartbeatRef = null, this.heartbeatTimer = setTimeout(() => this.sendHeartbeat(), this.heartbeatIntervalMs)), this.hasLogger() && this.log("receive", `${r.status || ""} ${t} ${e} ${i && "(" + i + ")" || ""}`, r);
2279
+ for (let h = 0; h < this.channels.length; h++) {
2280
+ const p = this.channels[h];
2281
+ p.isMember(t, e, r, o) && p.trigger(e, r, i, o);
2282
+ }
2283
+ for (let h = 0; h < this.stateChangeCallbacks.message.length; h++) {
2284
+ let [, p] = this.stateChangeCallbacks.message[h];
2285
+ p(n);
2286
+ }
2287
+ });
2288
+ }
2289
+ leaveOpenTopic(s) {
2290
+ let n = this.channels.find((t) => t.topic === s && (t.isJoined() || t.isJoining()));
2291
+ n && (this.hasLogger() && this.log("transport", `leaving duplicate topic "${s}"`), n.leave());
2292
+ }
2293
+ };
2294
+ class tn {
2295
+ constructor(n) {
2296
+ this.connected = !1, this.config = n, this.socket = new Ks(this.config.url, { logger: (t, e, r) => {
2297
+ console.log(`${t}: ${e}`, r);
2298
+ } }), this.channel = this.socket.channel(this.config.topic, this.config.params), this.eventTarget = new EventTarget();
2299
+ }
2300
+ /** connect to socket and join channel. will do nothing if already connected */
2301
+ connect() {
2302
+ this.connected || (this.socket.onError((n) => this.emitError("socket error", n)), this.socket.connect(), this.channel.onError((n) => console.log("channel error", n)), this.channel.join().receive("ok", () => {
2303
+ console.log("joined");
2304
+ }).receive("error", (n) => {
2305
+ this.emitError("channel join error", n);
2306
+ }), this.channel.on("state:change", (n) => this.handleChange(n)), this.channel.on("state:patch", (n) => this.handlePatch(n)), this.connected = !0);
2307
+ }
2308
+ /** leave channel and disconnect from socket */
2309
+ disconnect() {
2310
+ this.channel && this.channel.leave(), this.socket.disconnect(), this.connected = !1;
2311
+ }
2312
+ /** for events that begin with 'livestate-', add a listener. For
2313
+ * other events, additionally call `channel.on` to receive the event
2314
+ * over the channel, which will then be dispatched.
2315
+ */
2316
+ addEventListener(n, t, e) {
2317
+ var r;
2318
+ this.eventTarget.addEventListener(n, t, e), n.startsWith("livestate-") || (r = this.channel) == null || r.on(n, (i) => {
2319
+ this.eventTarget.dispatchEvent(new CustomEvent(n, { detail: i }));
2320
+ });
2321
+ }
2322
+ removeEventListener(n, t, e) {
2323
+ return this.eventTarget.removeEventListener(n, t, e);
2324
+ }
2325
+ /** @deprecated */
2326
+ subscribe(n) {
2327
+ this.addEventListener("livestate-change", n);
2328
+ }
2329
+ /** @deprecated */
2330
+ unsubscribe(n) {
2331
+ this.removeEventListener("livestate-change", n);
2332
+ }
2333
+ emitError(n, t) {
2334
+ this.eventTarget.dispatchEvent(new CustomEvent("livestate-error", {
2335
+ detail: {
2336
+ kind: n,
2337
+ error: t
2338
+ }
2339
+ }));
2340
+ }
2341
+ handleChange({ state: n, version: t }) {
2342
+ this.state = n, this.stateVersion = t, this.eventTarget.dispatchEvent(new CustomEvent("livestate-change", {
2343
+ detail: {
2344
+ state: this.state,
2345
+ version: this.stateVersion
2346
+ }
2347
+ }));
2348
+ }
2349
+ handlePatch({ patch: n, version: t }) {
2350
+ if (this.eventTarget.dispatchEvent(new CustomEvent("livestate-patch", {
2351
+ detail: { patch: n, version: t }
2352
+ })), t === this.stateVersion + 1) {
2353
+ const { doc: e, res: r } = zs(this.state, n, { mutate: !1 });
2354
+ this.state = e, this.stateVersion = t, this.eventTarget.dispatchEvent(new CustomEvent("livestate-change", {
2355
+ detail: {
2356
+ state: this.state,
2357
+ version: this.stateVersion
2358
+ }
2359
+ }));
2360
+ } else
2361
+ this.channel.push("lvs_refresh");
2362
+ }
2363
+ pushEvent(n, t) {
2364
+ this.dispatchEvent(new CustomEvent(n, { detail: t }));
2365
+ }
2366
+ /** Pushes the event over the channel, adding the `lvs_evt:` prefix and using the CustomEvent
2367
+ * detail property as the payload
2368
+ */
2369
+ dispatchEvent(n) {
2370
+ return this.channel.push(`lvs_evt:${n.type}`, n.detail), !0;
2371
+ }
2372
+ pushCustomEvent(n) {
2373
+ this.dispatchEvent(n);
2374
+ }
2375
+ }
2376
+ Promise.resolve();
2377
+ var ee = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
2378
+ /*! *****************************************************************************
2379
+ Copyright (C) Microsoft. All rights reserved.
2380
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
2381
+ this file except in compliance with the License. You may obtain a copy of the
2382
+ License at http://www.apache.org/licenses/LICENSE-2.0
2383
+
2384
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
2385
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
2386
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
2387
+ MERCHANTABLITY OR NON-INFRINGEMENT.
2388
+
2389
+ See the Apache Version 2.0 License for specific language governing permissions
2390
+ and limitations under the License.
2391
+ ***************************************************************************** */
2392
+ var se;
2393
+ (function(s) {
2394
+ (function(n) {
2395
+ var t = typeof ee == "object" ? ee : typeof self == "object" ? self : typeof this == "object" ? this : Function("return this;")(), e = r(s);
2396
+ typeof t.Reflect > "u" ? t.Reflect = s : e = r(t.Reflect, e), n(e);
2397
+ function r(i, o) {
2398
+ return function(h, p) {
2399
+ typeof i[h] != "function" && Object.defineProperty(i, h, { configurable: !0, writable: !0, value: p }), o && o(h, p);
2400
+ };
2401
+ }
2402
+ })(function(n) {
2403
+ var t = Object.prototype.hasOwnProperty, e = typeof Symbol == "function", r = e && typeof Symbol.toPrimitive < "u" ? Symbol.toPrimitive : "@@toPrimitive", i = e && typeof Symbol.iterator < "u" ? Symbol.iterator : "@@iterator", o = typeof Object.create == "function", h = { __proto__: [] } instanceof Array, p = !o && !h, d = {
2404
+ // create an object in dictionary mode (a.k.a. "slow" mode in v8)
2405
+ create: o ? function() {
2406
+ return Ot(/* @__PURE__ */ Object.create(null));
2407
+ } : h ? function() {
2408
+ return Ot({ __proto__: null });
2409
+ } : function() {
2410
+ return Ot({});
2411
+ },
2412
+ has: p ? function(a, c) {
2413
+ return t.call(a, c);
2414
+ } : function(a, c) {
2415
+ return c in a;
2416
+ },
2417
+ get: p ? function(a, c) {
2418
+ return t.call(a, c) ? a[c] : void 0;
2419
+ } : function(a, c) {
2420
+ return a[c];
2421
+ }
2422
+ }, b = Object.getPrototypeOf(Function), _ = typeof process == "object" && process.env && process.env.REFLECT_METADATA_USE_MAP_POLYFILL === "true", A = !_ && typeof Map == "function" && typeof Map.prototype.entries == "function" ? Map : Ae(), T = !_ && typeof Set == "function" && typeof Set.prototype.entries == "function" ? Set : Te(), j = !_ && typeof WeakMap == "function" ? WeakMap : Oe(), R = new j();
2423
+ function N(a, c, l, u) {
2424
+ if (M(l)) {
2425
+ if (!Wt(a))
2426
+ throw new TypeError();
2427
+ if (!Gt(c))
2428
+ throw new TypeError();
2429
+ return X(a, c);
2430
+ } else {
2431
+ if (!Wt(a))
2432
+ throw new TypeError();
2433
+ if (!L(c))
2434
+ throw new TypeError();
2435
+ if (!L(u) && !M(u) && !Y(u))
2436
+ throw new TypeError();
2437
+ return Y(u) && (u = void 0), l = q(l), ge(a, c, l, u);
2438
+ }
2439
+ }
2440
+ n("decorate", N);
2441
+ function k(a, c) {
2442
+ function l(u, g) {
2443
+ if (!L(u))
2444
+ throw new TypeError();
2445
+ if (!M(g) && !be(g))
2446
+ throw new TypeError();
2447
+ qt(a, c, u, g);
2448
+ }
2449
+ return l;
2450
+ }
2451
+ n("metadata", k);
2452
+ function G(a, c, l, u) {
2453
+ if (!L(l))
2454
+ throw new TypeError();
2455
+ return M(u) || (u = q(u)), qt(a, c, l, u);
2456
+ }
2457
+ n("defineMetadata", G);
2458
+ function dt(a, c, l) {
2459
+ if (!L(c))
2460
+ throw new TypeError();
2461
+ return M(l) || (l = q(l)), Ut(a, c, l);
2462
+ }
2463
+ n("hasMetadata", dt);
2464
+ function gt(a, c, l) {
2465
+ if (!L(c))
2466
+ throw new TypeError();
2467
+ return M(l) || (l = q(l)), At(a, c, l);
2468
+ }
2469
+ n("hasOwnMetadata", gt);
2470
+ function vt(a, c, l) {
2471
+ if (!L(c))
2472
+ throw new TypeError();
2473
+ return M(l) || (l = q(l)), Jt(a, c, l);
2474
+ }
2475
+ n("getMetadata", vt);
2476
+ function st(a, c, l) {
2477
+ if (!L(c))
2478
+ throw new TypeError();
2479
+ return M(l) || (l = q(l)), Vt(a, c, l);
2480
+ }
2481
+ n("getOwnMetadata", st);
2482
+ function S(a, c) {
2483
+ if (!L(a))
2484
+ throw new TypeError();
2485
+ return M(c) || (c = q(c)), Bt(a, c);
2486
+ }
2487
+ n("getMetadataKeys", S);
2488
+ function U(a, c) {
2489
+ if (!L(a))
2490
+ throw new TypeError();
2491
+ return M(c) || (c = q(c)), Ft(a, c);
2492
+ }
2493
+ n("getOwnMetadataKeys", U);
2494
+ function J(a, c, l) {
2495
+ if (!L(c))
2496
+ throw new TypeError();
2497
+ M(l) || (l = q(l));
2498
+ var u = nt(
2499
+ c,
2500
+ l,
2501
+ /*Create*/
2502
+ !1
2503
+ );
2504
+ if (M(u) || !u.delete(a))
2505
+ return !1;
2506
+ if (u.size > 0)
2507
+ return !0;
2508
+ var g = R.get(c);
2509
+ return g.delete(l), g.size > 0 || R.delete(c), !0;
2510
+ }
2511
+ n("deleteMetadata", J);
2512
+ function X(a, c) {
2513
+ for (var l = a.length - 1; l >= 0; --l) {
2514
+ var u = a[l], g = u(c);
2515
+ if (!M(g) && !Y(g)) {
2516
+ if (!Gt(g))
2517
+ throw new TypeError();
2518
+ c = g;
2519
+ }
2520
+ }
2521
+ return c;
2522
+ }
2523
+ function ge(a, c, l, u) {
2524
+ for (var g = a.length - 1; g >= 0; --g) {
2525
+ var H = a[g], y = H(c, l, u);
2526
+ if (!M(y) && !Y(y)) {
2527
+ if (!L(y))
2528
+ throw new TypeError();
2529
+ u = y;
2530
+ }
2531
+ }
2532
+ return u;
2533
+ }
2534
+ function nt(a, c, l) {
2535
+ var u = R.get(a);
2536
+ if (M(u)) {
2537
+ if (!l)
2538
+ return;
2539
+ u = new A(), R.set(a, u);
2540
+ }
2541
+ var g = u.get(c);
2542
+ if (M(g)) {
2543
+ if (!l)
2544
+ return;
2545
+ g = new A(), u.set(c, g);
2546
+ }
2547
+ return g;
2548
+ }
2549
+ function Ut(a, c, l) {
2550
+ var u = At(a, c, l);
2551
+ if (u)
2552
+ return !0;
2553
+ var g = Tt(c);
2554
+ return Y(g) ? !1 : Ut(a, g, l);
2555
+ }
2556
+ function At(a, c, l) {
2557
+ var u = nt(
2558
+ c,
2559
+ l,
2560
+ /*Create*/
2561
+ !1
2562
+ );
2563
+ return M(u) ? !1 : we(u.has(a));
2564
+ }
2565
+ function Jt(a, c, l) {
2566
+ var u = At(a, c, l);
2567
+ if (u)
2568
+ return Vt(a, c, l);
2569
+ var g = Tt(c);
2570
+ if (!Y(g))
2571
+ return Jt(a, g, l);
2572
+ }
2573
+ function Vt(a, c, l) {
2574
+ var u = nt(
2575
+ c,
2576
+ l,
2577
+ /*Create*/
2578
+ !1
2579
+ );
2580
+ if (!M(u))
2581
+ return u.get(a);
2582
+ }
2583
+ function qt(a, c, l, u) {
2584
+ var g = nt(
2585
+ l,
2586
+ u,
2587
+ /*Create*/
2588
+ !0
2589
+ );
2590
+ g.set(a, c);
2591
+ }
2592
+ function Bt(a, c) {
2593
+ var l = Ft(a, c), u = Tt(a);
2594
+ if (u === null)
2595
+ return l;
2596
+ var g = Bt(u, c);
2597
+ if (g.length <= 0)
2598
+ return l;
2599
+ if (l.length <= 0)
2600
+ return g;
2601
+ for (var H = new T(), y = [], m = 0, v = l; m < v.length; m++) {
2602
+ var E = v[m], $ = H.has(E);
2603
+ $ || (H.add(E), y.push(E));
2604
+ }
2605
+ for (var z = 0, Yt = g; z < Yt.length; z++) {
2606
+ var E = Yt[z], $ = H.has(E);
2607
+ $ || (H.add(E), y.push(E));
2608
+ }
2609
+ return y;
2610
+ }
2611
+ function Ft(a, c) {
2612
+ var l = [], u = nt(
2613
+ a,
2614
+ c,
2615
+ /*Create*/
2616
+ !1
2617
+ );
2618
+ if (M(u))
2619
+ return l;
2620
+ for (var g = u.keys(), H = Ee(g), y = 0; ; ) {
2621
+ var m = Ce(H);
2622
+ if (!m)
2623
+ return l.length = y, l;
2624
+ var v = $e(m);
2625
+ try {
2626
+ l[y] = v;
2627
+ } catch (E) {
2628
+ try {
2629
+ ke(H);
2630
+ } finally {
2631
+ throw E;
2632
+ }
2633
+ }
2634
+ y++;
2635
+ }
2636
+ }
2637
+ function zt(a) {
2638
+ if (a === null)
2639
+ return 1;
2640
+ switch (typeof a) {
2641
+ case "undefined":
2642
+ return 0;
2643
+ case "boolean":
2644
+ return 2;
2645
+ case "string":
2646
+ return 3;
2647
+ case "symbol":
2648
+ return 4;
2649
+ case "number":
2650
+ return 5;
2651
+ case "object":
2652
+ return a === null ? 1 : 6;
2653
+ default:
2654
+ return 6;
2655
+ }
2656
+ }
2657
+ function M(a) {
2658
+ return a === void 0;
2659
+ }
2660
+ function Y(a) {
2661
+ return a === null;
2662
+ }
2663
+ function ve(a) {
2664
+ return typeof a == "symbol";
2665
+ }
2666
+ function L(a) {
2667
+ return typeof a == "object" ? a !== null : typeof a == "function";
2668
+ }
2669
+ function ye(a, c) {
2670
+ switch (zt(a)) {
2671
+ case 0:
2672
+ return a;
2673
+ case 1:
2674
+ return a;
2675
+ case 2:
2676
+ return a;
2677
+ case 3:
2678
+ return a;
2679
+ case 4:
2680
+ return a;
2681
+ case 5:
2682
+ return a;
2683
+ }
2684
+ var l = c === 3 ? "string" : c === 5 ? "number" : "default", u = Xt(a, r);
2685
+ if (u !== void 0) {
2686
+ var g = u.call(a, l);
2687
+ if (L(g))
2688
+ throw new TypeError();
2689
+ return g;
2690
+ }
2691
+ return me(a, l === "default" ? "number" : l);
2692
+ }
2693
+ function me(a, c) {
2694
+ if (c === "string") {
2695
+ var l = a.toString;
2696
+ if (Z(l)) {
2697
+ var u = l.call(a);
2698
+ if (!L(u))
2699
+ return u;
2700
+ }
2701
+ var g = a.valueOf;
2702
+ if (Z(g)) {
2703
+ var u = g.call(a);
2704
+ if (!L(u))
2705
+ return u;
2706
+ }
2707
+ } else {
2708
+ var g = a.valueOf;
2709
+ if (Z(g)) {
2710
+ var u = g.call(a);
2711
+ if (!L(u))
2712
+ return u;
2713
+ }
2714
+ var H = a.toString;
2715
+ if (Z(H)) {
2716
+ var u = H.call(a);
2717
+ if (!L(u))
2718
+ return u;
2719
+ }
2720
+ }
2721
+ throw new TypeError();
2722
+ }
2723
+ function we(a) {
2724
+ return !!a;
2725
+ }
2726
+ function _e(a) {
2727
+ return "" + a;
2728
+ }
2729
+ function q(a) {
2730
+ var c = ye(
2731
+ a,
2732
+ 3
2733
+ /* String */
2734
+ );
2735
+ return ve(c) ? c : _e(c);
2736
+ }
2737
+ function Wt(a) {
2738
+ return Array.isArray ? Array.isArray(a) : a instanceof Object ? a instanceof Array : Object.prototype.toString.call(a) === "[object Array]";
2739
+ }
2740
+ function Z(a) {
2741
+ return typeof a == "function";
2742
+ }
2743
+ function Gt(a) {
2744
+ return typeof a == "function";
2745
+ }
2746
+ function be(a) {
2747
+ switch (zt(a)) {
2748
+ case 3:
2749
+ return !0;
2750
+ case 4:
2751
+ return !0;
2752
+ default:
2753
+ return !1;
2754
+ }
2755
+ }
2756
+ function Xt(a, c) {
2757
+ var l = a[c];
2758
+ if (l != null) {
2759
+ if (!Z(l))
2760
+ throw new TypeError();
2761
+ return l;
2762
+ }
2763
+ }
2764
+ function Ee(a) {
2765
+ var c = Xt(a, i);
2766
+ if (!Z(c))
2767
+ throw new TypeError();
2768
+ var l = c.call(a);
2769
+ if (!L(l))
2770
+ throw new TypeError();
2771
+ return l;
2772
+ }
2773
+ function $e(a) {
2774
+ return a.value;
2775
+ }
2776
+ function Ce(a) {
2777
+ var c = a.next();
2778
+ return c.done ? !1 : c;
2779
+ }
2780
+ function ke(a) {
2781
+ var c = a.return;
2782
+ c && c.call(a);
2783
+ }
2784
+ function Tt(a) {
2785
+ var c = Object.getPrototypeOf(a);
2786
+ if (typeof a != "function" || a === b || c !== b)
2787
+ return c;
2788
+ var l = a.prototype, u = l && Object.getPrototypeOf(l);
2789
+ if (u == null || u === Object.prototype)
2790
+ return c;
2791
+ var g = u.constructor;
2792
+ return typeof g != "function" || g === a ? c : g;
2793
+ }
2794
+ function Ae() {
2795
+ var a = {}, c = [], l = (
2796
+ /** @class */
2797
+ function() {
2798
+ function y(m, v, E) {
2799
+ this._index = 0, this._keys = m, this._values = v, this._selector = E;
2800
+ }
2801
+ return y.prototype["@@iterator"] = function() {
2802
+ return this;
2803
+ }, y.prototype[i] = function() {
2804
+ return this;
2805
+ }, y.prototype.next = function() {
2806
+ var m = this._index;
2807
+ if (m >= 0 && m < this._keys.length) {
2808
+ var v = this._selector(this._keys[m], this._values[m]);
2809
+ return m + 1 >= this._keys.length ? (this._index = -1, this._keys = c, this._values = c) : this._index++, { value: v, done: !1 };
2810
+ }
2811
+ return { value: void 0, done: !0 };
2812
+ }, y.prototype.throw = function(m) {
2813
+ throw this._index >= 0 && (this._index = -1, this._keys = c, this._values = c), m;
2814
+ }, y.prototype.return = function(m) {
2815
+ return this._index >= 0 && (this._index = -1, this._keys = c, this._values = c), { value: m, done: !0 };
2816
+ }, y;
2817
+ }()
2818
+ );
2819
+ return (
2820
+ /** @class */
2821
+ function() {
2822
+ function y() {
2823
+ this._keys = [], this._values = [], this._cacheKey = a, this._cacheIndex = -2;
2824
+ }
2825
+ return Object.defineProperty(y.prototype, "size", {
2826
+ get: function() {
2827
+ return this._keys.length;
2828
+ },
2829
+ enumerable: !0,
2830
+ configurable: !0
2831
+ }), y.prototype.has = function(m) {
2832
+ return this._find(
2833
+ m,
2834
+ /*insert*/
2835
+ !1
2836
+ ) >= 0;
2837
+ }, y.prototype.get = function(m) {
2838
+ var v = this._find(
2839
+ m,
2840
+ /*insert*/
2841
+ !1
2842
+ );
2843
+ return v >= 0 ? this._values[v] : void 0;
2844
+ }, y.prototype.set = function(m, v) {
2845
+ var E = this._find(
2846
+ m,
2847
+ /*insert*/
2848
+ !0
2849
+ );
2850
+ return this._values[E] = v, this;
2851
+ }, y.prototype.delete = function(m) {
2852
+ var v = this._find(
2853
+ m,
2854
+ /*insert*/
2855
+ !1
2856
+ );
2857
+ if (v >= 0) {
2858
+ for (var E = this._keys.length, $ = v + 1; $ < E; $++)
2859
+ this._keys[$ - 1] = this._keys[$], this._values[$ - 1] = this._values[$];
2860
+ return this._keys.length--, this._values.length--, m === this._cacheKey && (this._cacheKey = a, this._cacheIndex = -2), !0;
2861
+ }
2862
+ return !1;
2863
+ }, y.prototype.clear = function() {
2864
+ this._keys.length = 0, this._values.length = 0, this._cacheKey = a, this._cacheIndex = -2;
2865
+ }, y.prototype.keys = function() {
2866
+ return new l(this._keys, this._values, u);
2867
+ }, y.prototype.values = function() {
2868
+ return new l(this._keys, this._values, g);
2869
+ }, y.prototype.entries = function() {
2870
+ return new l(this._keys, this._values, H);
2871
+ }, y.prototype["@@iterator"] = function() {
2872
+ return this.entries();
2873
+ }, y.prototype[i] = function() {
2874
+ return this.entries();
2875
+ }, y.prototype._find = function(m, v) {
2876
+ return this._cacheKey !== m && (this._cacheIndex = this._keys.indexOf(this._cacheKey = m)), this._cacheIndex < 0 && v && (this._cacheIndex = this._keys.length, this._keys.push(m), this._values.push(void 0)), this._cacheIndex;
2877
+ }, y;
2878
+ }()
2879
+ );
2880
+ function u(y, m) {
2881
+ return y;
2882
+ }
2883
+ function g(y, m) {
2884
+ return m;
2885
+ }
2886
+ function H(y, m) {
2887
+ return [y, m];
2888
+ }
2889
+ }
2890
+ function Te() {
2891
+ return (
2892
+ /** @class */
2893
+ function() {
2894
+ function a() {
2895
+ this._map = new A();
2896
+ }
2897
+ return Object.defineProperty(a.prototype, "size", {
2898
+ get: function() {
2899
+ return this._map.size;
2900
+ },
2901
+ enumerable: !0,
2902
+ configurable: !0
2903
+ }), a.prototype.has = function(c) {
2904
+ return this._map.has(c);
2905
+ }, a.prototype.add = function(c) {
2906
+ return this._map.set(c, c), this;
2907
+ }, a.prototype.delete = function(c) {
2908
+ return this._map.delete(c);
2909
+ }, a.prototype.clear = function() {
2910
+ this._map.clear();
2911
+ }, a.prototype.keys = function() {
2912
+ return this._map.keys();
2913
+ }, a.prototype.values = function() {
2914
+ return this._map.values();
2915
+ }, a.prototype.entries = function() {
2916
+ return this._map.entries();
2917
+ }, a.prototype["@@iterator"] = function() {
2918
+ return this.keys();
2919
+ }, a.prototype[i] = function() {
2920
+ return this.keys();
2921
+ }, a;
2922
+ }()
2923
+ );
2924
+ }
2925
+ function Oe() {
2926
+ var a = 16, c = d.create(), l = u();
2927
+ return (
2928
+ /** @class */
2929
+ function() {
2930
+ function v() {
2931
+ this._key = u();
2932
+ }
2933
+ return v.prototype.has = function(E) {
2934
+ var $ = g(
2935
+ E,
2936
+ /*create*/
2937
+ !1
2938
+ );
2939
+ return $ !== void 0 ? d.has($, this._key) : !1;
2940
+ }, v.prototype.get = function(E) {
2941
+ var $ = g(
2942
+ E,
2943
+ /*create*/
2944
+ !1
2945
+ );
2946
+ return $ !== void 0 ? d.get($, this._key) : void 0;
2947
+ }, v.prototype.set = function(E, $) {
2948
+ var z = g(
2949
+ E,
2950
+ /*create*/
2951
+ !0
2952
+ );
2953
+ return z[this._key] = $, this;
2954
+ }, v.prototype.delete = function(E) {
2955
+ var $ = g(
2956
+ E,
2957
+ /*create*/
2958
+ !1
2959
+ );
2960
+ return $ !== void 0 ? delete $[this._key] : !1;
2961
+ }, v.prototype.clear = function() {
2962
+ this._key = u();
2963
+ }, v;
2964
+ }()
2965
+ );
2966
+ function u() {
2967
+ var v;
2968
+ do
2969
+ v = "@@WeakMap@@" + m();
2970
+ while (d.has(c, v));
2971
+ return c[v] = !0, v;
2972
+ }
2973
+ function g(v, E) {
2974
+ if (!t.call(v, l)) {
2975
+ if (!E)
2976
+ return;
2977
+ Object.defineProperty(v, l, { value: d.create() });
2978
+ }
2979
+ return v[l];
2980
+ }
2981
+ function H(v, E) {
2982
+ for (var $ = 0; $ < E; ++$)
2983
+ v[$] = Math.random() * 255 | 0;
2984
+ return v;
2985
+ }
2986
+ function y(v) {
2987
+ return typeof Uint8Array == "function" ? typeof crypto < "u" ? crypto.getRandomValues(new Uint8Array(v)) : typeof msCrypto < "u" ? msCrypto.getRandomValues(new Uint8Array(v)) : H(new Uint8Array(v), v) : H(new Array(v), v);
2988
+ }
2989
+ function m() {
2990
+ var v = y(a);
2991
+ v[6] = v[6] & 79 | 64, v[8] = v[8] & 191 | 128;
2992
+ for (var E = "", $ = 0; $ < a; ++$) {
2993
+ var z = v[$];
2994
+ ($ === 4 || $ === 6 || $ === 8) && (E += "-"), z < 16 && (E += "0"), E += z.toString(16).toLowerCase();
2995
+ }
2996
+ return E;
2997
+ }
2998
+ }
2999
+ function Ot(a) {
3000
+ return a.__ = void 0, delete a.__, a;
3001
+ }
3002
+ });
3003
+ })(se || (se = {}));
3004
+ function en(s) {
3005
+ Ne(s, "svelte-w16tqa", "#liveroom-client-element.svelte-w16tqa.svelte-w16tqa{font-family:Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;line-height:1.5;font-weight:400;font-synthesis:none;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;-webkit-text-size-adjust:100%}#users-container.svelte-w16tqa.svelte-w16tqa{position:absolute;inset:0;overflow:hidden;pointer-events:none}.user.svelte-w16tqa.svelte-w16tqa{z-index:1000;position:absolute;top:0;left:0;user-select:none;transform:translate(var(--x), var(--y))}.user.svelte-w16tqa .cursor.svelte-w16tqa{position:absolute;top:0;left:0;color:var(--color);transform-origin:top left;transform:rotate(6deg)}.user[data-isself='true'].svelte-w16tqa .cursor.svelte-w16tqa{display:none}.user-name.svelte-w16tqa.svelte-w16tqa{padding:4px 10px;font-size:14px;line-height:20px;font-weight:600;color:black;background-color:var(--color);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-radius:9999px;box-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05)}.user.svelte-w16tqa .user-name.svelte-w16tqa{position:absolute;top:20px;left:16px}.user[data-isself='true'].svelte-w16tqa .user-name.svelte-w16tqa{display:none}.user.svelte-w16tqa .halo.svelte-w16tqa{transform:scale(0);z-index:-1;position:absolute;top:-60px;left:-60px;width:120px;height:120px;border-radius:9999px;background-color:var(--color);opacity:0.25;transition:transform 0.15s ease-out;box-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05)}.user.svelte-w16tqa .halo[data-show='true'].svelte-w16tqa{transform:scale(1)}");
3006
+ }
3007
+ function ne(s, n, t) {
3008
+ const e = s.slice();
3009
+ return e[14] = n[t], e;
3010
+ }
3011
+ function re(s) {
3012
+ let n, t = [], e = /* @__PURE__ */ new Map(), r = te(Object.values(
3013
+ /*users*/
3014
+ s[2]
3015
+ ));
3016
+ const i = (o) => (
3017
+ /*user*/
3018
+ o[14].id
3019
+ );
3020
+ for (let o = 0; o < r.length; o += 1) {
3021
+ let h = ne(s, r, o), p = i(h);
3022
+ e.set(p, t[o] = ie(p, h));
3023
+ }
3024
+ return {
3025
+ c() {
3026
+ n = W("div");
3027
+ for (let o = 0; o < t.length; o += 1)
3028
+ t[o].c();
3029
+ x(n, "id", "users-container"), x(n, "class", "svelte-w16tqa");
3030
+ },
3031
+ m(o, h) {
3032
+ Ct(o, n, h);
3033
+ for (let p = 0; p < t.length; p += 1)
3034
+ t[p] && t[p].m(n, null);
3035
+ },
3036
+ p(o, h) {
3037
+ h & /*Object, users, me, parseFloat*/
3038
+ 6 && (r = te(Object.values(
3039
+ /*users*/
3040
+ o[2]
3041
+ )), t = We(t, h, i, 1, o, r, e, n, ze, ie, null, ne));
3042
+ },
3043
+ d(o) {
3044
+ o && pt(n);
3045
+ for (let h = 0; h < t.length; h += 1)
3046
+ t[h].d();
3047
+ }
3048
+ };
3049
+ }
3050
+ function ie(s, n) {
3051
+ let t, e, r, i, o, h = (
3052
+ /*user*/
3053
+ n[14].name + ""
3054
+ ), p, d, b, _, A, T, j;
3055
+ return {
3056
+ key: s,
3057
+ first: null,
3058
+ c() {
3059
+ t = W("div"), e = Qt("svg"), r = Qt("path"), i = jt(), o = W("span"), p = he(h), d = jt(), b = W("div"), A = jt(), x(r, "d", "M2.2706 0.0593359L25.4277 8.05957H25.45926C25.65896 8.13153 25.83096 8.25952 25.95221 8.42653C26.07357 8.59354 26.13851 8.79166 26.13851 8.99459C26.13851 9.19751 26.07357 9.39564 25.95221 9.56265C25.83096 9.72966 25.65896 9.85765 25.45926 9.92962L15.3543 13.7698L11.3124 23.37C11.2344 23.5561 11.0994 23.7156 10.9248 23.828C10.7503 23.9402 10.5443 24.0002 10.3335 24C10.1172 24 9.9061 23.9365 9.7291 23.8184C9.552 23.7004 9.4176 23.5332 9.344 23.34L0.9233 1.33937C0.8555 1.16076 0.8426 0.967504 0.8861 0.782189C0.9297 0.596873 1.0278 0.427163 1.1691 0.292901C1.3105 0.158639 1.4891 0.0653762 1.6841 0.0240151C1.8792 -0.0173461 2.0826 -0.00509504 2.2706 0.0593359Z"), x(e, "width", "23"), x(e, "viewBox", "0 0 27 24"), x(e, "fill", "currentColor"), x(e, "aria-hidden", "true"), x(e, "xmlns", "http://www.w3.org/2000/svg"), x(e, "class", "cursor svelte-w16tqa"), x(o, "class", "user-name svelte-w16tqa"), x(b, "class", "halo svelte-w16tqa"), x(b, "data-show", _ = /*user*/
3060
+ n[14].is_mouse_down || /*user*/
3061
+ n[14].is_escape_key_down), x(t, "id", T = "user-" + /*user*/
3062
+ n[14].id), x(t, "class", "user svelte-w16tqa"), x(t, "data-isself", j = /*user*/
3063
+ n[14].id == /*me*/
3064
+ n[1].id), Q(
3065
+ t,
3066
+ "--color",
3067
+ /*user*/
3068
+ n[14].color
3069
+ ), Q(t, "--x", parseFloat(
3070
+ /*user*/
3071
+ n[14].x
3072
+ ) + "vw"), Q(t, "--y", parseFloat(
3073
+ /*user*/
3074
+ n[14].y
3075
+ ) + "vh"), this.first = t;
3076
+ },
3077
+ m(R, N) {
3078
+ Ct(R, t, N), B(t, e), B(e, r), B(t, i), B(t, o), B(o, p), B(t, d), B(t, b), B(t, A);
3079
+ },
3080
+ p(R, N) {
3081
+ n = R, N & /*users*/
3082
+ 4 && h !== (h = /*user*/
3083
+ n[14].name + "") && Pe(p, h), N & /*users*/
3084
+ 4 && _ !== (_ = /*user*/
3085
+ n[14].is_mouse_down || /*user*/
3086
+ n[14].is_escape_key_down) && x(b, "data-show", _), N & /*users*/
3087
+ 4 && T !== (T = "user-" + /*user*/
3088
+ n[14].id) && x(t, "id", T), N & /*users, me*/
3089
+ 6 && j !== (j = /*user*/
3090
+ n[14].id == /*me*/
3091
+ n[1].id) && x(t, "data-isself", j), N & /*users*/
3092
+ 4 && Q(
3093
+ t,
3094
+ "--color",
3095
+ /*user*/
3096
+ n[14].color
3097
+ ), N & /*users*/
3098
+ 4 && Q(t, "--x", parseFloat(
3099
+ /*user*/
3100
+ n[14].x
3101
+ ) + "vw"), N & /*users*/
3102
+ 4 && Q(t, "--y", parseFloat(
3103
+ /*user*/
3104
+ n[14].y
3105
+ ) + "vh");
3106
+ },
3107
+ d(R) {
3108
+ R && pt(t);
3109
+ }
3110
+ };
3111
+ }
3112
+ function sn(s) {
3113
+ let n, t = (
3114
+ /*me*/
3115
+ s[1] && /*users*/
3116
+ s[2] && re(s)
3117
+ );
3118
+ return {
3119
+ c() {
3120
+ n = W("div"), t && t.c(), x(n, "id", "liveroom-client-element"), x(n, "class", "svelte-w16tqa");
3121
+ },
3122
+ m(e, r) {
3123
+ Ct(e, n, r), t && t.m(n, null), s[5](n);
3124
+ },
3125
+ p(e, [r]) {
3126
+ /*me*/
3127
+ e[1] && /*users*/
3128
+ e[2] ? t ? t.p(e, r) : (t = re(e), t.c(), t.m(n, null)) : t && (t.d(1), t = null);
3129
+ },
3130
+ i: ht,
3131
+ o: ht,
3132
+ d(e) {
3133
+ e && pt(n), t && t.d(), s[5](null);
3134
+ }
3135
+ };
3136
+ }
3137
+ function nn(s, n, t) {
3138
+ let { url: e } = n, { room_id: r } = n, i, o, h, p;
3139
+ De(async () => {
3140
+ o = new tn({
3141
+ url: e,
3142
+ topic: `liveroom-livestate:${r}`,
3143
+ params: {
3144
+ room_id: r,
3145
+ current_url: window.origin,
3146
+ inner_width: window.innerWidth,
3147
+ inner_height: window.innerHeight
3148
+ }
3149
+ }), o.connect(), o.addEventListener("livestate-change", ({ detail: { state: k } }) => {
3150
+ t(3, r = k.room_id), t(1, h = k.me), t(2, p = k.users);
3151
+ }), window.addEventListener("mousemove", d), window.addEventListener("mousedown", b), window.addEventListener("mouseup", _), window.addEventListener("keydown", T), window.addEventListener("keyup", j), window.addEventListener("resize", R);
3152
+ }), Ue(() => {
3153
+ window.removeEventListener("resize", R), window.removeEventListener("keyup", j), window.removeEventListener("keydown", T), window.removeEventListener("mouseup", _), window.removeEventListener("mousedown", b), window.removeEventListener("mousemove", d), o == null || o.disconnect();
3154
+ });
3155
+ function d(k) {
3156
+ o && (h != null && h.id) && o.dispatchEvent(new CustomEvent(
3157
+ "mouse_move",
3158
+ {
3159
+ detail: {
3160
+ user_id: h.id,
3161
+ x: Number(k.pageX / window.innerWidth * 100).toFixed(2),
3162
+ // in %
3163
+ y: Number(k.pageY / window.innerHeight * 100).toFixed(2)
3164
+ }
3165
+ // in %
3166
+ }
3167
+ ));
3168
+ }
3169
+ function b() {
3170
+ o && (h != null && h.id) && o.dispatchEvent(new CustomEvent("mouse_down", { detail: { user_id: h.id } }));
3171
+ }
3172
+ function _() {
3173
+ o && (h != null && h.id) && o.dispatchEvent(new CustomEvent("mouse_up", { detail: { user_id: h.id } }));
3174
+ }
3175
+ const A = ["Escape"];
3176
+ function T(k) {
3177
+ !k.repeat && A.includes(k.key) && o && (h != null && h.id) && o.dispatchEvent(new CustomEvent("key_down", { detail: { key: k.key, user_id: h.id } }));
3178
+ }
3179
+ function j(k) {
3180
+ A.includes(k.key) && o && (h != null && h.id) && o.dispatchEvent(new CustomEvent("key_up", { detail: { key: k.key, user_id: h.id } }));
3181
+ }
3182
+ function R() {
3183
+ o && (h != null && h.id) && o.dispatchEvent(new CustomEvent(
3184
+ "window_resize",
3185
+ {
3186
+ detail: {
3187
+ inner_width: window.innerWidth,
3188
+ inner_height: window.innerHeight,
3189
+ user_id: h.id
3190
+ }
3191
+ }
3192
+ ));
3193
+ }
3194
+ function N(k) {
3195
+ Mt[k ? "unshift" : "push"](() => {
3196
+ i = k, t(0, i);
3197
+ });
3198
+ }
3199
+ return s.$$set = (k) => {
3200
+ "url" in k && t(4, e = k.url), "room_id" in k && t(3, r = k.room_id);
3201
+ }, [i, h, p, r, e, N];
3202
+ }
3203
+ class rn extends Ke {
3204
+ constructor(n) {
3205
+ super(), Ze(this, n, nn, sn, Se, { url: 4, room_id: 3 }, en);
3206
+ }
3207
+ get url() {
3208
+ return this.$$.ctx[4];
3209
+ }
3210
+ set url(n) {
3211
+ this.$$set({ url: n }), bt();
3212
+ }
3213
+ get room_id() {
3214
+ return this.$$.ctx[3];
3215
+ }
3216
+ set room_id(n) {
3217
+ this.$$set({ room_id: n }), bt();
3218
+ }
3219
+ }
3220
+ customElements.define("liveroom-client-element", Qe(rn, { url: {}, room_id: {} }, [], [], !0));
3221
+ export {
3222
+ rn as default
3223
+ };