touch-coop 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,1680 @@
1
+ async function ne(o) {
2
+ const r = new TextEncoder(), i = r.encode(o);
3
+ console.log("Original text size (bytes):", i.length);
4
+ const n = new CompressionStream("gzip"), t = n.writable.getWriter();
5
+ t.write(r.encode(o)), t.close();
6
+ const e = n.readable.getReader(), s = [];
7
+ for (; ; ) {
8
+ const { done: h, value: f } = await e.read();
9
+ if (h) break;
10
+ s.push(f);
11
+ }
12
+ const a = new Uint8Array(await new Blob(s).arrayBuffer()), c = btoa(String.fromCharCode(...a)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), l = new TextEncoder().encode(c).length;
13
+ return console.log("SafeBase64 size (bytes):", l), c;
14
+ }
15
+ async function re(o) {
16
+ let r = (o || "").trim();
17
+ r = r.replace(/\s+/g, ""), r = r.replace(/-/g, "+").replace(/_/g, "/");
18
+ const i = r.length % 4;
19
+ i === 2 ? r += "==" : i === 3 && (r += "=");
20
+ const n = atob(r), t = Uint8Array.from(n, (a) => a.charCodeAt(0)), e = new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"));
21
+ return await new Response(e).text();
22
+ }
23
+ class Ne {
24
+ constructor() {
25
+ this._playerId = null, this._dataChannel = null, this._pc = new RTCPeerConnection(), this._pc.ondatachannel = (r) => {
26
+ this._dataChannel = r.channel, this._dataChannel.onopen = () => {
27
+ if (this._playerId && this._dataChannel) {
28
+ const i = {
29
+ playerId: this._playerId,
30
+ action: "JOIN",
31
+ timestamp: Date.now()
32
+ };
33
+ this._dataChannel.send(JSON.stringify(i));
34
+ }
35
+ };
36
+ }, window.addEventListener("beforeunload", () => {
37
+ if (this._dataChannel && this._dataChannel.readyState === "open" && this._playerId) {
38
+ const r = {
39
+ playerId: this._playerId,
40
+ action: "LEAVE",
41
+ button: "",
42
+ timestamp: Date.now()
43
+ };
44
+ try {
45
+ this._dataChannel.send(JSON.stringify(r));
46
+ } catch {
47
+ }
48
+ }
49
+ });
50
+ }
51
+ async joinMatch() {
52
+ const i = new URLSearchParams(window.location.search).get("remoteSDP");
53
+ if (!i)
54
+ throw new Error("No remoteSDP found in URL parameters.");
55
+ const n = await re(i), t = JSON.parse(n);
56
+ this._playerId = t.playerId;
57
+ const e = t.sdp;
58
+ if (await this._pc.setRemoteDescription(e), e.type === "offer") {
59
+ const s = await this._pc.createAnswer();
60
+ await this._pc.setLocalDescription(s), await new Promise((f) => {
61
+ this._pc.onicecandidate = (d) => {
62
+ d.candidate || f(void 0);
63
+ };
64
+ });
65
+ const a = {
66
+ playerId: this._playerId,
67
+ sdp: this._pc.localDescription
68
+ }, u = JSON.stringify(a), c = btoa(u), l = new BroadcastChannel("touch-coop-signaling"), h = {
69
+ type: "answer",
70
+ playerId: this._playerId,
71
+ base64Answer: c
72
+ };
73
+ l.postMessage(h), l.close();
74
+ }
75
+ }
76
+ async sendMove(r) {
77
+ if (this._dataChannel && this._dataChannel.readyState === "open") {
78
+ if (!this._playerId)
79
+ throw new Error("Player ID is not set. Cannot send data.");
80
+ const i = {
81
+ playerId: this._playerId,
82
+ action: "MOVE",
83
+ button: r,
84
+ timestamp: Date.now()
85
+ }, n = JSON.stringify(i);
86
+ this._dataChannel.send(n);
87
+ } else
88
+ console.warn("Data channel is not open. Cannot send data.");
89
+ }
90
+ }
91
+ function oe(o) {
92
+ return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
93
+ }
94
+ var O = {}, G, Bt;
95
+ function ie() {
96
+ return Bt || (Bt = 1, G = function() {
97
+ return typeof Promise == "function" && Promise.prototype && Promise.prototype.then;
98
+ }), G;
99
+ }
100
+ var Q = {}, U = {}, It;
101
+ function q() {
102
+ if (It) return U;
103
+ It = 1;
104
+ let o;
105
+ const r = [
106
+ 0,
107
+ // Not used
108
+ 26,
109
+ 44,
110
+ 70,
111
+ 100,
112
+ 134,
113
+ 172,
114
+ 196,
115
+ 242,
116
+ 292,
117
+ 346,
118
+ 404,
119
+ 466,
120
+ 532,
121
+ 581,
122
+ 655,
123
+ 733,
124
+ 815,
125
+ 901,
126
+ 991,
127
+ 1085,
128
+ 1156,
129
+ 1258,
130
+ 1364,
131
+ 1474,
132
+ 1588,
133
+ 1706,
134
+ 1828,
135
+ 1921,
136
+ 2051,
137
+ 2185,
138
+ 2323,
139
+ 2465,
140
+ 2611,
141
+ 2761,
142
+ 2876,
143
+ 3034,
144
+ 3196,
145
+ 3362,
146
+ 3532,
147
+ 3706
148
+ ];
149
+ return U.getSymbolSize = function(n) {
150
+ if (!n) throw new Error('"version" cannot be null or undefined');
151
+ if (n < 1 || n > 40) throw new Error('"version" should be in range from 1 to 40');
152
+ return n * 4 + 17;
153
+ }, U.getSymbolTotalCodewords = function(n) {
154
+ return r[n];
155
+ }, U.getBCHDigit = function(i) {
156
+ let n = 0;
157
+ for (; i !== 0; )
158
+ n++, i >>>= 1;
159
+ return n;
160
+ }, U.setToSJISFunction = function(n) {
161
+ if (typeof n != "function")
162
+ throw new Error('"toSJISFunc" is not a valid function.');
163
+ o = n;
164
+ }, U.isKanjiModeEnabled = function() {
165
+ return typeof o < "u";
166
+ }, U.toSJIS = function(n) {
167
+ return o(n);
168
+ }, U;
169
+ }
170
+ var W = {}, At;
171
+ function pt() {
172
+ return At || (At = 1, (function(o) {
173
+ o.L = { bit: 1 }, o.M = { bit: 0 }, o.Q = { bit: 3 }, o.H = { bit: 2 };
174
+ function r(i) {
175
+ if (typeof i != "string")
176
+ throw new Error("Param is not a string");
177
+ switch (i.toLowerCase()) {
178
+ case "l":
179
+ case "low":
180
+ return o.L;
181
+ case "m":
182
+ case "medium":
183
+ return o.M;
184
+ case "q":
185
+ case "quartile":
186
+ return o.Q;
187
+ case "h":
188
+ case "high":
189
+ return o.H;
190
+ default:
191
+ throw new Error("Unknown EC Level: " + i);
192
+ }
193
+ }
194
+ o.isValid = function(n) {
195
+ return n && typeof n.bit < "u" && n.bit >= 0 && n.bit < 4;
196
+ }, o.from = function(n, t) {
197
+ if (o.isValid(n))
198
+ return n;
199
+ try {
200
+ return r(n);
201
+ } catch {
202
+ return t;
203
+ }
204
+ };
205
+ })(W)), W;
206
+ }
207
+ var Z, Rt;
208
+ function se() {
209
+ if (Rt) return Z;
210
+ Rt = 1;
211
+ function o() {
212
+ this.buffer = [], this.length = 0;
213
+ }
214
+ return o.prototype = {
215
+ get: function(r) {
216
+ const i = Math.floor(r / 8);
217
+ return (this.buffer[i] >>> 7 - r % 8 & 1) === 1;
218
+ },
219
+ put: function(r, i) {
220
+ for (let n = 0; n < i; n++)
221
+ this.putBit((r >>> i - n - 1 & 1) === 1);
222
+ },
223
+ getLengthInBits: function() {
224
+ return this.length;
225
+ },
226
+ putBit: function(r) {
227
+ const i = Math.floor(this.length / 8);
228
+ this.buffer.length <= i && this.buffer.push(0), r && (this.buffer[i] |= 128 >>> this.length % 8), this.length++;
229
+ }
230
+ }, Z = o, Z;
231
+ }
232
+ var X, St;
233
+ function ae() {
234
+ if (St) return X;
235
+ St = 1;
236
+ function o(r) {
237
+ if (!r || r < 1)
238
+ throw new Error("BitMatrix size must be defined and greater than 0");
239
+ this.size = r, this.data = new Uint8Array(r * r), this.reservedBit = new Uint8Array(r * r);
240
+ }
241
+ return o.prototype.set = function(r, i, n, t) {
242
+ const e = r * this.size + i;
243
+ this.data[e] = n, t && (this.reservedBit[e] = !0);
244
+ }, o.prototype.get = function(r, i) {
245
+ return this.data[r * this.size + i];
246
+ }, o.prototype.xor = function(r, i, n) {
247
+ this.data[r * this.size + i] ^= n;
248
+ }, o.prototype.isReserved = function(r, i) {
249
+ return this.reservedBit[r * this.size + i];
250
+ }, X = o, X;
251
+ }
252
+ var $ = {}, Pt;
253
+ function ue() {
254
+ return Pt || (Pt = 1, (function(o) {
255
+ const r = q().getSymbolSize;
256
+ o.getRowColCoords = function(n) {
257
+ if (n === 1) return [];
258
+ const t = Math.floor(n / 7) + 2, e = r(n), s = e === 145 ? 26 : Math.ceil((e - 13) / (2 * t - 2)) * 2, a = [e - 7];
259
+ for (let u = 1; u < t - 1; u++)
260
+ a[u] = a[u - 1] - s;
261
+ return a.push(6), a.reverse();
262
+ }, o.getPositions = function(n) {
263
+ const t = [], e = o.getRowColCoords(n), s = e.length;
264
+ for (let a = 0; a < s; a++)
265
+ for (let u = 0; u < s; u++)
266
+ a === 0 && u === 0 || // top-left
267
+ a === 0 && u === s - 1 || // bottom-left
268
+ a === s - 1 && u === 0 || t.push([e[a], e[u]]);
269
+ return t;
270
+ };
271
+ })($)), $;
272
+ }
273
+ var tt = {}, bt;
274
+ function ce() {
275
+ if (bt) return tt;
276
+ bt = 1;
277
+ const o = q().getSymbolSize, r = 7;
278
+ return tt.getPositions = function(n) {
279
+ const t = o(n);
280
+ return [
281
+ // top-left
282
+ [0, 0],
283
+ // top-right
284
+ [t - r, 0],
285
+ // bottom-left
286
+ [0, t - r]
287
+ ];
288
+ }, tt;
289
+ }
290
+ var et = {}, Nt;
291
+ function le() {
292
+ return Nt || (Nt = 1, (function(o) {
293
+ o.Patterns = {
294
+ PATTERN000: 0,
295
+ PATTERN001: 1,
296
+ PATTERN010: 2,
297
+ PATTERN011: 3,
298
+ PATTERN100: 4,
299
+ PATTERN101: 5,
300
+ PATTERN110: 6,
301
+ PATTERN111: 7
302
+ };
303
+ const r = {
304
+ N1: 3,
305
+ N2: 3,
306
+ N3: 40,
307
+ N4: 10
308
+ };
309
+ o.isValid = function(t) {
310
+ return t != null && t !== "" && !isNaN(t) && t >= 0 && t <= 7;
311
+ }, o.from = function(t) {
312
+ return o.isValid(t) ? parseInt(t, 10) : void 0;
313
+ }, o.getPenaltyN1 = function(t) {
314
+ const e = t.size;
315
+ let s = 0, a = 0, u = 0, c = null, l = null;
316
+ for (let h = 0; h < e; h++) {
317
+ a = u = 0, c = l = null;
318
+ for (let f = 0; f < e; f++) {
319
+ let d = t.get(h, f);
320
+ d === c ? a++ : (a >= 5 && (s += r.N1 + (a - 5)), c = d, a = 1), d = t.get(f, h), d === l ? u++ : (u >= 5 && (s += r.N1 + (u - 5)), l = d, u = 1);
321
+ }
322
+ a >= 5 && (s += r.N1 + (a - 5)), u >= 5 && (s += r.N1 + (u - 5));
323
+ }
324
+ return s;
325
+ }, o.getPenaltyN2 = function(t) {
326
+ const e = t.size;
327
+ let s = 0;
328
+ for (let a = 0; a < e - 1; a++)
329
+ for (let u = 0; u < e - 1; u++) {
330
+ const c = t.get(a, u) + t.get(a, u + 1) + t.get(a + 1, u) + t.get(a + 1, u + 1);
331
+ (c === 4 || c === 0) && s++;
332
+ }
333
+ return s * r.N2;
334
+ }, o.getPenaltyN3 = function(t) {
335
+ const e = t.size;
336
+ let s = 0, a = 0, u = 0;
337
+ for (let c = 0; c < e; c++) {
338
+ a = u = 0;
339
+ for (let l = 0; l < e; l++)
340
+ a = a << 1 & 2047 | t.get(c, l), l >= 10 && (a === 1488 || a === 93) && s++, u = u << 1 & 2047 | t.get(l, c), l >= 10 && (u === 1488 || u === 93) && s++;
341
+ }
342
+ return s * r.N3;
343
+ }, o.getPenaltyN4 = function(t) {
344
+ let e = 0;
345
+ const s = t.data.length;
346
+ for (let u = 0; u < s; u++) e += t.data[u];
347
+ return Math.abs(Math.ceil(e * 100 / s / 5) - 10) * r.N4;
348
+ };
349
+ function i(n, t, e) {
350
+ switch (n) {
351
+ case o.Patterns.PATTERN000:
352
+ return (t + e) % 2 === 0;
353
+ case o.Patterns.PATTERN001:
354
+ return t % 2 === 0;
355
+ case o.Patterns.PATTERN010:
356
+ return e % 3 === 0;
357
+ case o.Patterns.PATTERN011:
358
+ return (t + e) % 3 === 0;
359
+ case o.Patterns.PATTERN100:
360
+ return (Math.floor(t / 2) + Math.floor(e / 3)) % 2 === 0;
361
+ case o.Patterns.PATTERN101:
362
+ return t * e % 2 + t * e % 3 === 0;
363
+ case o.Patterns.PATTERN110:
364
+ return (t * e % 2 + t * e % 3) % 2 === 0;
365
+ case o.Patterns.PATTERN111:
366
+ return (t * e % 3 + (t + e) % 2) % 2 === 0;
367
+ default:
368
+ throw new Error("bad maskPattern:" + n);
369
+ }
370
+ }
371
+ o.applyMask = function(t, e) {
372
+ const s = e.size;
373
+ for (let a = 0; a < s; a++)
374
+ for (let u = 0; u < s; u++)
375
+ e.isReserved(u, a) || e.xor(u, a, i(t, u, a));
376
+ }, o.getBestMask = function(t, e) {
377
+ const s = Object.keys(o.Patterns).length;
378
+ let a = 0, u = 1 / 0;
379
+ for (let c = 0; c < s; c++) {
380
+ e(c), o.applyMask(c, t);
381
+ const l = o.getPenaltyN1(t) + o.getPenaltyN2(t) + o.getPenaltyN3(t) + o.getPenaltyN4(t);
382
+ o.applyMask(c, t), l < u && (u = l, a = c);
383
+ }
384
+ return a;
385
+ };
386
+ })(et)), et;
387
+ }
388
+ var j = {}, Mt;
389
+ function Qt() {
390
+ if (Mt) return j;
391
+ Mt = 1;
392
+ const o = pt(), r = [
393
+ // L M Q H
394
+ 1,
395
+ 1,
396
+ 1,
397
+ 1,
398
+ 1,
399
+ 1,
400
+ 1,
401
+ 1,
402
+ 1,
403
+ 1,
404
+ 2,
405
+ 2,
406
+ 1,
407
+ 2,
408
+ 2,
409
+ 4,
410
+ 1,
411
+ 2,
412
+ 4,
413
+ 4,
414
+ 2,
415
+ 4,
416
+ 4,
417
+ 4,
418
+ 2,
419
+ 4,
420
+ 6,
421
+ 5,
422
+ 2,
423
+ 4,
424
+ 6,
425
+ 6,
426
+ 2,
427
+ 5,
428
+ 8,
429
+ 8,
430
+ 4,
431
+ 5,
432
+ 8,
433
+ 8,
434
+ 4,
435
+ 5,
436
+ 8,
437
+ 11,
438
+ 4,
439
+ 8,
440
+ 10,
441
+ 11,
442
+ 4,
443
+ 9,
444
+ 12,
445
+ 16,
446
+ 4,
447
+ 9,
448
+ 16,
449
+ 16,
450
+ 6,
451
+ 10,
452
+ 12,
453
+ 18,
454
+ 6,
455
+ 10,
456
+ 17,
457
+ 16,
458
+ 6,
459
+ 11,
460
+ 16,
461
+ 19,
462
+ 6,
463
+ 13,
464
+ 18,
465
+ 21,
466
+ 7,
467
+ 14,
468
+ 21,
469
+ 25,
470
+ 8,
471
+ 16,
472
+ 20,
473
+ 25,
474
+ 8,
475
+ 17,
476
+ 23,
477
+ 25,
478
+ 9,
479
+ 17,
480
+ 23,
481
+ 34,
482
+ 9,
483
+ 18,
484
+ 25,
485
+ 30,
486
+ 10,
487
+ 20,
488
+ 27,
489
+ 32,
490
+ 12,
491
+ 21,
492
+ 29,
493
+ 35,
494
+ 12,
495
+ 23,
496
+ 34,
497
+ 37,
498
+ 12,
499
+ 25,
500
+ 34,
501
+ 40,
502
+ 13,
503
+ 26,
504
+ 35,
505
+ 42,
506
+ 14,
507
+ 28,
508
+ 38,
509
+ 45,
510
+ 15,
511
+ 29,
512
+ 40,
513
+ 48,
514
+ 16,
515
+ 31,
516
+ 43,
517
+ 51,
518
+ 17,
519
+ 33,
520
+ 45,
521
+ 54,
522
+ 18,
523
+ 35,
524
+ 48,
525
+ 57,
526
+ 19,
527
+ 37,
528
+ 51,
529
+ 60,
530
+ 19,
531
+ 38,
532
+ 53,
533
+ 63,
534
+ 20,
535
+ 40,
536
+ 56,
537
+ 66,
538
+ 21,
539
+ 43,
540
+ 59,
541
+ 70,
542
+ 22,
543
+ 45,
544
+ 62,
545
+ 74,
546
+ 24,
547
+ 47,
548
+ 65,
549
+ 77,
550
+ 25,
551
+ 49,
552
+ 68,
553
+ 81
554
+ ], i = [
555
+ // L M Q H
556
+ 7,
557
+ 10,
558
+ 13,
559
+ 17,
560
+ 10,
561
+ 16,
562
+ 22,
563
+ 28,
564
+ 15,
565
+ 26,
566
+ 36,
567
+ 44,
568
+ 20,
569
+ 36,
570
+ 52,
571
+ 64,
572
+ 26,
573
+ 48,
574
+ 72,
575
+ 88,
576
+ 36,
577
+ 64,
578
+ 96,
579
+ 112,
580
+ 40,
581
+ 72,
582
+ 108,
583
+ 130,
584
+ 48,
585
+ 88,
586
+ 132,
587
+ 156,
588
+ 60,
589
+ 110,
590
+ 160,
591
+ 192,
592
+ 72,
593
+ 130,
594
+ 192,
595
+ 224,
596
+ 80,
597
+ 150,
598
+ 224,
599
+ 264,
600
+ 96,
601
+ 176,
602
+ 260,
603
+ 308,
604
+ 104,
605
+ 198,
606
+ 288,
607
+ 352,
608
+ 120,
609
+ 216,
610
+ 320,
611
+ 384,
612
+ 132,
613
+ 240,
614
+ 360,
615
+ 432,
616
+ 144,
617
+ 280,
618
+ 408,
619
+ 480,
620
+ 168,
621
+ 308,
622
+ 448,
623
+ 532,
624
+ 180,
625
+ 338,
626
+ 504,
627
+ 588,
628
+ 196,
629
+ 364,
630
+ 546,
631
+ 650,
632
+ 224,
633
+ 416,
634
+ 600,
635
+ 700,
636
+ 224,
637
+ 442,
638
+ 644,
639
+ 750,
640
+ 252,
641
+ 476,
642
+ 690,
643
+ 816,
644
+ 270,
645
+ 504,
646
+ 750,
647
+ 900,
648
+ 300,
649
+ 560,
650
+ 810,
651
+ 960,
652
+ 312,
653
+ 588,
654
+ 870,
655
+ 1050,
656
+ 336,
657
+ 644,
658
+ 952,
659
+ 1110,
660
+ 360,
661
+ 700,
662
+ 1020,
663
+ 1200,
664
+ 390,
665
+ 728,
666
+ 1050,
667
+ 1260,
668
+ 420,
669
+ 784,
670
+ 1140,
671
+ 1350,
672
+ 450,
673
+ 812,
674
+ 1200,
675
+ 1440,
676
+ 480,
677
+ 868,
678
+ 1290,
679
+ 1530,
680
+ 510,
681
+ 924,
682
+ 1350,
683
+ 1620,
684
+ 540,
685
+ 980,
686
+ 1440,
687
+ 1710,
688
+ 570,
689
+ 1036,
690
+ 1530,
691
+ 1800,
692
+ 570,
693
+ 1064,
694
+ 1590,
695
+ 1890,
696
+ 600,
697
+ 1120,
698
+ 1680,
699
+ 1980,
700
+ 630,
701
+ 1204,
702
+ 1770,
703
+ 2100,
704
+ 660,
705
+ 1260,
706
+ 1860,
707
+ 2220,
708
+ 720,
709
+ 1316,
710
+ 1950,
711
+ 2310,
712
+ 750,
713
+ 1372,
714
+ 2040,
715
+ 2430
716
+ ];
717
+ return j.getBlocksCount = function(t, e) {
718
+ switch (e) {
719
+ case o.L:
720
+ return r[(t - 1) * 4 + 0];
721
+ case o.M:
722
+ return r[(t - 1) * 4 + 1];
723
+ case o.Q:
724
+ return r[(t - 1) * 4 + 2];
725
+ case o.H:
726
+ return r[(t - 1) * 4 + 3];
727
+ default:
728
+ return;
729
+ }
730
+ }, j.getTotalCodewordsCount = function(t, e) {
731
+ switch (e) {
732
+ case o.L:
733
+ return i[(t - 1) * 4 + 0];
734
+ case o.M:
735
+ return i[(t - 1) * 4 + 1];
736
+ case o.Q:
737
+ return i[(t - 1) * 4 + 2];
738
+ case o.H:
739
+ return i[(t - 1) * 4 + 3];
740
+ default:
741
+ return;
742
+ }
743
+ }, j;
744
+ }
745
+ var nt = {}, J = {}, Tt;
746
+ function fe() {
747
+ if (Tt) return J;
748
+ Tt = 1;
749
+ const o = new Uint8Array(512), r = new Uint8Array(256);
750
+ return (function() {
751
+ let n = 1;
752
+ for (let t = 0; t < 255; t++)
753
+ o[t] = n, r[n] = t, n <<= 1, n & 256 && (n ^= 285);
754
+ for (let t = 255; t < 512; t++)
755
+ o[t] = o[t - 255];
756
+ })(), J.log = function(n) {
757
+ if (n < 1) throw new Error("log(" + n + ")");
758
+ return r[n];
759
+ }, J.exp = function(n) {
760
+ return o[n];
761
+ }, J.mul = function(n, t) {
762
+ return n === 0 || t === 0 ? 0 : o[r[n] + r[t]];
763
+ }, J;
764
+ }
765
+ var _t;
766
+ function de() {
767
+ return _t || (_t = 1, (function(o) {
768
+ const r = fe();
769
+ o.mul = function(n, t) {
770
+ const e = new Uint8Array(n.length + t.length - 1);
771
+ for (let s = 0; s < n.length; s++)
772
+ for (let a = 0; a < t.length; a++)
773
+ e[s + a] ^= r.mul(n[s], t[a]);
774
+ return e;
775
+ }, o.mod = function(n, t) {
776
+ let e = new Uint8Array(n);
777
+ for (; e.length - t.length >= 0; ) {
778
+ const s = e[0];
779
+ for (let u = 0; u < t.length; u++)
780
+ e[u] ^= r.mul(t[u], s);
781
+ let a = 0;
782
+ for (; a < e.length && e[a] === 0; ) a++;
783
+ e = e.slice(a);
784
+ }
785
+ return e;
786
+ }, o.generateECPolynomial = function(n) {
787
+ let t = new Uint8Array([1]);
788
+ for (let e = 0; e < n; e++)
789
+ t = o.mul(t, new Uint8Array([1, r.exp(e)]));
790
+ return t;
791
+ };
792
+ })(nt)), nt;
793
+ }
794
+ var rt, Dt;
795
+ function he() {
796
+ if (Dt) return rt;
797
+ Dt = 1;
798
+ const o = de();
799
+ function r(i) {
800
+ this.genPoly = void 0, this.degree = i, this.degree && this.initialize(this.degree);
801
+ }
802
+ return r.prototype.initialize = function(n) {
803
+ this.degree = n, this.genPoly = o.generateECPolynomial(this.degree);
804
+ }, r.prototype.encode = function(n) {
805
+ if (!this.genPoly)
806
+ throw new Error("Encoder not initialized");
807
+ const t = new Uint8Array(n.length + this.degree);
808
+ t.set(n);
809
+ const e = o.mod(t, this.genPoly), s = this.degree - e.length;
810
+ if (s > 0) {
811
+ const a = new Uint8Array(this.degree);
812
+ return a.set(e, s), a;
813
+ }
814
+ return e;
815
+ }, rt = r, rt;
816
+ }
817
+ var ot = {}, it = {}, st = {}, Lt;
818
+ function Wt() {
819
+ return Lt || (Lt = 1, st.isValid = function(r) {
820
+ return !isNaN(r) && r >= 1 && r <= 40;
821
+ }), st;
822
+ }
823
+ var _ = {}, vt;
824
+ function Zt() {
825
+ if (vt) return _;
826
+ vt = 1;
827
+ const o = "[0-9]+", r = "[A-Z $%*+\\-./:]+";
828
+ let i = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";
829
+ i = i.replace(/u/g, "\\u");
830
+ const n = "(?:(?![A-Z0-9 $%*+\\-./:]|" + i + `)(?:.|[\r
831
+ ]))+`;
832
+ _.KANJI = new RegExp(i, "g"), _.BYTE_KANJI = new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g"), _.BYTE = new RegExp(n, "g"), _.NUMERIC = new RegExp(o, "g"), _.ALPHANUMERIC = new RegExp(r, "g");
833
+ const t = new RegExp("^" + i + "$"), e = new RegExp("^" + o + "$"), s = new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
834
+ return _.testKanji = function(u) {
835
+ return t.test(u);
836
+ }, _.testNumeric = function(u) {
837
+ return e.test(u);
838
+ }, _.testAlphanumeric = function(u) {
839
+ return s.test(u);
840
+ }, _;
841
+ }
842
+ var Ut;
843
+ function F() {
844
+ return Ut || (Ut = 1, (function(o) {
845
+ const r = Wt(), i = Zt();
846
+ o.NUMERIC = {
847
+ id: "Numeric",
848
+ bit: 1,
849
+ ccBits: [10, 12, 14]
850
+ }, o.ALPHANUMERIC = {
851
+ id: "Alphanumeric",
852
+ bit: 2,
853
+ ccBits: [9, 11, 13]
854
+ }, o.BYTE = {
855
+ id: "Byte",
856
+ bit: 4,
857
+ ccBits: [8, 16, 16]
858
+ }, o.KANJI = {
859
+ id: "Kanji",
860
+ bit: 8,
861
+ ccBits: [8, 10, 12]
862
+ }, o.MIXED = {
863
+ bit: -1
864
+ }, o.getCharCountIndicator = function(e, s) {
865
+ if (!e.ccBits) throw new Error("Invalid mode: " + e);
866
+ if (!r.isValid(s))
867
+ throw new Error("Invalid version: " + s);
868
+ return s >= 1 && s < 10 ? e.ccBits[0] : s < 27 ? e.ccBits[1] : e.ccBits[2];
869
+ }, o.getBestModeForData = function(e) {
870
+ return i.testNumeric(e) ? o.NUMERIC : i.testAlphanumeric(e) ? o.ALPHANUMERIC : i.testKanji(e) ? o.KANJI : o.BYTE;
871
+ }, o.toString = function(e) {
872
+ if (e && e.id) return e.id;
873
+ throw new Error("Invalid mode");
874
+ }, o.isValid = function(e) {
875
+ return e && e.bit && e.ccBits;
876
+ };
877
+ function n(t) {
878
+ if (typeof t != "string")
879
+ throw new Error("Param is not a string");
880
+ switch (t.toLowerCase()) {
881
+ case "numeric":
882
+ return o.NUMERIC;
883
+ case "alphanumeric":
884
+ return o.ALPHANUMERIC;
885
+ case "kanji":
886
+ return o.KANJI;
887
+ case "byte":
888
+ return o.BYTE;
889
+ default:
890
+ throw new Error("Unknown mode: " + t);
891
+ }
892
+ }
893
+ o.from = function(e, s) {
894
+ if (o.isValid(e))
895
+ return e;
896
+ try {
897
+ return n(e);
898
+ } catch {
899
+ return s;
900
+ }
901
+ };
902
+ })(it)), it;
903
+ }
904
+ var qt;
905
+ function ge() {
906
+ return qt || (qt = 1, (function(o) {
907
+ const r = q(), i = Qt(), n = pt(), t = F(), e = Wt(), s = 7973, a = r.getBCHDigit(s);
908
+ function u(f, d, P) {
909
+ for (let b = 1; b <= 40; b++)
910
+ if (d <= o.getCapacity(b, P, f))
911
+ return b;
912
+ }
913
+ function c(f, d) {
914
+ return t.getCharCountIndicator(f, d) + 4;
915
+ }
916
+ function l(f, d) {
917
+ let P = 0;
918
+ return f.forEach(function(b) {
919
+ const M = c(b.mode, d);
920
+ P += M + b.getBitsLength();
921
+ }), P;
922
+ }
923
+ function h(f, d) {
924
+ for (let P = 1; P <= 40; P++)
925
+ if (l(f, P) <= o.getCapacity(P, d, t.MIXED))
926
+ return P;
927
+ }
928
+ o.from = function(d, P) {
929
+ return e.isValid(d) ? parseInt(d, 10) : P;
930
+ }, o.getCapacity = function(d, P, b) {
931
+ if (!e.isValid(d))
932
+ throw new Error("Invalid QR Code version");
933
+ typeof b > "u" && (b = t.BYTE);
934
+ const M = r.getSymbolTotalCodewords(d), A = i.getTotalCodewordsCount(d, P), N = (M - A) * 8;
935
+ if (b === t.MIXED) return N;
936
+ const R = N - c(b, d);
937
+ switch (b) {
938
+ case t.NUMERIC:
939
+ return Math.floor(R / 10 * 3);
940
+ case t.ALPHANUMERIC:
941
+ return Math.floor(R / 11 * 2);
942
+ case t.KANJI:
943
+ return Math.floor(R / 13);
944
+ case t.BYTE:
945
+ default:
946
+ return Math.floor(R / 8);
947
+ }
948
+ }, o.getBestVersionForData = function(d, P) {
949
+ let b;
950
+ const M = n.from(P, n.M);
951
+ if (Array.isArray(d)) {
952
+ if (d.length > 1)
953
+ return h(d, M);
954
+ if (d.length === 0)
955
+ return 1;
956
+ b = d[0];
957
+ } else
958
+ b = d;
959
+ return u(b.mode, b.getLength(), M);
960
+ }, o.getEncodedBits = function(d) {
961
+ if (!e.isValid(d) || d < 7)
962
+ throw new Error("Invalid QR Code version");
963
+ let P = d << 12;
964
+ for (; r.getBCHDigit(P) - a >= 0; )
965
+ P ^= s << r.getBCHDigit(P) - a;
966
+ return d << 12 | P;
967
+ };
968
+ })(ot)), ot;
969
+ }
970
+ var at = {}, Ft;
971
+ function we() {
972
+ if (Ft) return at;
973
+ Ft = 1;
974
+ const o = q(), r = 1335, i = 21522, n = o.getBCHDigit(r);
975
+ return at.getEncodedBits = function(e, s) {
976
+ const a = e.bit << 3 | s;
977
+ let u = a << 10;
978
+ for (; o.getBCHDigit(u) - n >= 0; )
979
+ u ^= r << o.getBCHDigit(u) - n;
980
+ return (a << 10 | u) ^ i;
981
+ }, at;
982
+ }
983
+ var ut = {}, ct, kt;
984
+ function me() {
985
+ if (kt) return ct;
986
+ kt = 1;
987
+ const o = F();
988
+ function r(i) {
989
+ this.mode = o.NUMERIC, this.data = i.toString();
990
+ }
991
+ return r.getBitsLength = function(n) {
992
+ return 10 * Math.floor(n / 3) + (n % 3 ? n % 3 * 3 + 1 : 0);
993
+ }, r.prototype.getLength = function() {
994
+ return this.data.length;
995
+ }, r.prototype.getBitsLength = function() {
996
+ return r.getBitsLength(this.data.length);
997
+ }, r.prototype.write = function(n) {
998
+ let t, e, s;
999
+ for (t = 0; t + 3 <= this.data.length; t += 3)
1000
+ e = this.data.substr(t, 3), s = parseInt(e, 10), n.put(s, 10);
1001
+ const a = this.data.length - t;
1002
+ a > 0 && (e = this.data.substr(t), s = parseInt(e, 10), n.put(s, a * 3 + 1));
1003
+ }, ct = r, ct;
1004
+ }
1005
+ var lt, Ot;
1006
+ function pe() {
1007
+ if (Ot) return lt;
1008
+ Ot = 1;
1009
+ const o = F(), r = [
1010
+ "0",
1011
+ "1",
1012
+ "2",
1013
+ "3",
1014
+ "4",
1015
+ "5",
1016
+ "6",
1017
+ "7",
1018
+ "8",
1019
+ "9",
1020
+ "A",
1021
+ "B",
1022
+ "C",
1023
+ "D",
1024
+ "E",
1025
+ "F",
1026
+ "G",
1027
+ "H",
1028
+ "I",
1029
+ "J",
1030
+ "K",
1031
+ "L",
1032
+ "M",
1033
+ "N",
1034
+ "O",
1035
+ "P",
1036
+ "Q",
1037
+ "R",
1038
+ "S",
1039
+ "T",
1040
+ "U",
1041
+ "V",
1042
+ "W",
1043
+ "X",
1044
+ "Y",
1045
+ "Z",
1046
+ " ",
1047
+ "$",
1048
+ "%",
1049
+ "*",
1050
+ "+",
1051
+ "-",
1052
+ ".",
1053
+ "/",
1054
+ ":"
1055
+ ];
1056
+ function i(n) {
1057
+ this.mode = o.ALPHANUMERIC, this.data = n;
1058
+ }
1059
+ return i.getBitsLength = function(t) {
1060
+ return 11 * Math.floor(t / 2) + 6 * (t % 2);
1061
+ }, i.prototype.getLength = function() {
1062
+ return this.data.length;
1063
+ }, i.prototype.getBitsLength = function() {
1064
+ return i.getBitsLength(this.data.length);
1065
+ }, i.prototype.write = function(t) {
1066
+ let e;
1067
+ for (e = 0; e + 2 <= this.data.length; e += 2) {
1068
+ let s = r.indexOf(this.data[e]) * 45;
1069
+ s += r.indexOf(this.data[e + 1]), t.put(s, 11);
1070
+ }
1071
+ this.data.length % 2 && t.put(r.indexOf(this.data[e]), 6);
1072
+ }, lt = i, lt;
1073
+ }
1074
+ var ft, zt;
1075
+ function ye() {
1076
+ if (zt) return ft;
1077
+ zt = 1;
1078
+ const o = F();
1079
+ function r(i) {
1080
+ this.mode = o.BYTE, typeof i == "string" ? this.data = new TextEncoder().encode(i) : this.data = new Uint8Array(i);
1081
+ }
1082
+ return r.getBitsLength = function(n) {
1083
+ return n * 8;
1084
+ }, r.prototype.getLength = function() {
1085
+ return this.data.length;
1086
+ }, r.prototype.getBitsLength = function() {
1087
+ return r.getBitsLength(this.data.length);
1088
+ }, r.prototype.write = function(i) {
1089
+ for (let n = 0, t = this.data.length; n < t; n++)
1090
+ i.put(this.data[n], 8);
1091
+ }, ft = r, ft;
1092
+ }
1093
+ var dt, Jt;
1094
+ function Ce() {
1095
+ if (Jt) return dt;
1096
+ Jt = 1;
1097
+ const o = F(), r = q();
1098
+ function i(n) {
1099
+ this.mode = o.KANJI, this.data = n;
1100
+ }
1101
+ return i.getBitsLength = function(t) {
1102
+ return t * 13;
1103
+ }, i.prototype.getLength = function() {
1104
+ return this.data.length;
1105
+ }, i.prototype.getBitsLength = function() {
1106
+ return i.getBitsLength(this.data.length);
1107
+ }, i.prototype.write = function(n) {
1108
+ let t;
1109
+ for (t = 0; t < this.data.length; t++) {
1110
+ let e = r.toSJIS(this.data[t]);
1111
+ if (e >= 33088 && e <= 40956)
1112
+ e -= 33088;
1113
+ else if (e >= 57408 && e <= 60351)
1114
+ e -= 49472;
1115
+ else
1116
+ throw new Error(
1117
+ "Invalid SJIS character: " + this.data[t] + `
1118
+ Make sure your charset is UTF-8`
1119
+ );
1120
+ e = (e >>> 8 & 255) * 192 + (e & 255), n.put(e, 13);
1121
+ }
1122
+ }, dt = i, dt;
1123
+ }
1124
+ var ht = { exports: {} }, Vt;
1125
+ function Ee() {
1126
+ return Vt || (Vt = 1, (function(o) {
1127
+ var r = {
1128
+ single_source_shortest_paths: function(i, n, t) {
1129
+ var e = {}, s = {};
1130
+ s[n] = 0;
1131
+ var a = r.PriorityQueue.make();
1132
+ a.push(n, 0);
1133
+ for (var u, c, l, h, f, d, P, b, M; !a.empty(); ) {
1134
+ u = a.pop(), c = u.value, h = u.cost, f = i[c] || {};
1135
+ for (l in f)
1136
+ f.hasOwnProperty(l) && (d = f[l], P = h + d, b = s[l], M = typeof s[l] > "u", (M || b > P) && (s[l] = P, a.push(l, P), e[l] = c));
1137
+ }
1138
+ if (typeof t < "u" && typeof s[t] > "u") {
1139
+ var A = ["Could not find a path from ", n, " to ", t, "."].join("");
1140
+ throw new Error(A);
1141
+ }
1142
+ return e;
1143
+ },
1144
+ extract_shortest_path_from_predecessor_list: function(i, n) {
1145
+ for (var t = [], e = n; e; )
1146
+ t.push(e), i[e], e = i[e];
1147
+ return t.reverse(), t;
1148
+ },
1149
+ find_path: function(i, n, t) {
1150
+ var e = r.single_source_shortest_paths(i, n, t);
1151
+ return r.extract_shortest_path_from_predecessor_list(
1152
+ e,
1153
+ t
1154
+ );
1155
+ },
1156
+ /**
1157
+ * A very naive priority queue implementation.
1158
+ */
1159
+ PriorityQueue: {
1160
+ make: function(i) {
1161
+ var n = r.PriorityQueue, t = {}, e;
1162
+ i = i || {};
1163
+ for (e in n)
1164
+ n.hasOwnProperty(e) && (t[e] = n[e]);
1165
+ return t.queue = [], t.sorter = i.sorter || n.default_sorter, t;
1166
+ },
1167
+ default_sorter: function(i, n) {
1168
+ return i.cost - n.cost;
1169
+ },
1170
+ /**
1171
+ * Add a new item to the queue and ensure the highest priority element
1172
+ * is at the front of the queue.
1173
+ */
1174
+ push: function(i, n) {
1175
+ var t = { value: i, cost: n };
1176
+ this.queue.push(t), this.queue.sort(this.sorter);
1177
+ },
1178
+ /**
1179
+ * Return the highest priority element in the queue.
1180
+ */
1181
+ pop: function() {
1182
+ return this.queue.shift();
1183
+ },
1184
+ empty: function() {
1185
+ return this.queue.length === 0;
1186
+ }
1187
+ }
1188
+ };
1189
+ o.exports = r;
1190
+ })(ht)), ht.exports;
1191
+ }
1192
+ var jt;
1193
+ function Be() {
1194
+ return jt || (jt = 1, (function(o) {
1195
+ const r = F(), i = me(), n = pe(), t = ye(), e = Ce(), s = Zt(), a = q(), u = Ee();
1196
+ function c(A) {
1197
+ return unescape(encodeURIComponent(A)).length;
1198
+ }
1199
+ function l(A, N, R) {
1200
+ const B = [];
1201
+ let T;
1202
+ for (; (T = A.exec(R)) !== null; )
1203
+ B.push({
1204
+ data: T[0],
1205
+ index: T.index,
1206
+ mode: N,
1207
+ length: T[0].length
1208
+ });
1209
+ return B;
1210
+ }
1211
+ function h(A) {
1212
+ const N = l(s.NUMERIC, r.NUMERIC, A), R = l(s.ALPHANUMERIC, r.ALPHANUMERIC, A);
1213
+ let B, T;
1214
+ return a.isKanjiModeEnabled() ? (B = l(s.BYTE, r.BYTE, A), T = l(s.KANJI, r.KANJI, A)) : (B = l(s.BYTE_KANJI, r.BYTE, A), T = []), N.concat(R, B, T).sort(function(C, y) {
1215
+ return C.index - y.index;
1216
+ }).map(function(C) {
1217
+ return {
1218
+ data: C.data,
1219
+ mode: C.mode,
1220
+ length: C.length
1221
+ };
1222
+ });
1223
+ }
1224
+ function f(A, N) {
1225
+ switch (N) {
1226
+ case r.NUMERIC:
1227
+ return i.getBitsLength(A);
1228
+ case r.ALPHANUMERIC:
1229
+ return n.getBitsLength(A);
1230
+ case r.KANJI:
1231
+ return e.getBitsLength(A);
1232
+ case r.BYTE:
1233
+ return t.getBitsLength(A);
1234
+ }
1235
+ }
1236
+ function d(A) {
1237
+ return A.reduce(function(N, R) {
1238
+ const B = N.length - 1 >= 0 ? N[N.length - 1] : null;
1239
+ return B && B.mode === R.mode ? (N[N.length - 1].data += R.data, N) : (N.push(R), N);
1240
+ }, []);
1241
+ }
1242
+ function P(A) {
1243
+ const N = [];
1244
+ for (let R = 0; R < A.length; R++) {
1245
+ const B = A[R];
1246
+ switch (B.mode) {
1247
+ case r.NUMERIC:
1248
+ N.push([
1249
+ B,
1250
+ { data: B.data, mode: r.ALPHANUMERIC, length: B.length },
1251
+ { data: B.data, mode: r.BYTE, length: B.length }
1252
+ ]);
1253
+ break;
1254
+ case r.ALPHANUMERIC:
1255
+ N.push([
1256
+ B,
1257
+ { data: B.data, mode: r.BYTE, length: B.length }
1258
+ ]);
1259
+ break;
1260
+ case r.KANJI:
1261
+ N.push([
1262
+ B,
1263
+ { data: B.data, mode: r.BYTE, length: c(B.data) }
1264
+ ]);
1265
+ break;
1266
+ case r.BYTE:
1267
+ N.push([
1268
+ { data: B.data, mode: r.BYTE, length: c(B.data) }
1269
+ ]);
1270
+ }
1271
+ }
1272
+ return N;
1273
+ }
1274
+ function b(A, N) {
1275
+ const R = {}, B = { start: {} };
1276
+ let T = ["start"];
1277
+ for (let w = 0; w < A.length; w++) {
1278
+ const C = A[w], y = [];
1279
+ for (let g = 0; g < C.length; g++) {
1280
+ const I = C[g], m = "" + w + g;
1281
+ y.push(m), R[m] = { node: I, lastCount: 0 }, B[m] = {};
1282
+ for (let E = 0; E < T.length; E++) {
1283
+ const p = T[E];
1284
+ R[p] && R[p].node.mode === I.mode ? (B[p][m] = f(R[p].lastCount + I.length, I.mode) - f(R[p].lastCount, I.mode), R[p].lastCount += I.length) : (R[p] && (R[p].lastCount = I.length), B[p][m] = f(I.length, I.mode) + 4 + r.getCharCountIndicator(I.mode, N));
1285
+ }
1286
+ }
1287
+ T = y;
1288
+ }
1289
+ for (let w = 0; w < T.length; w++)
1290
+ B[T[w]].end = 0;
1291
+ return { map: B, table: R };
1292
+ }
1293
+ function M(A, N) {
1294
+ let R;
1295
+ const B = r.getBestModeForData(A);
1296
+ if (R = r.from(N, B), R !== r.BYTE && R.bit < B.bit)
1297
+ throw new Error('"' + A + '" cannot be encoded with mode ' + r.toString(R) + `.
1298
+ Suggested mode is: ` + r.toString(B));
1299
+ switch (R === r.KANJI && !a.isKanjiModeEnabled() && (R = r.BYTE), R) {
1300
+ case r.NUMERIC:
1301
+ return new i(A);
1302
+ case r.ALPHANUMERIC:
1303
+ return new n(A);
1304
+ case r.KANJI:
1305
+ return new e(A);
1306
+ case r.BYTE:
1307
+ return new t(A);
1308
+ }
1309
+ }
1310
+ o.fromArray = function(N) {
1311
+ return N.reduce(function(R, B) {
1312
+ return typeof B == "string" ? R.push(M(B, null)) : B.data && R.push(M(B.data, B.mode)), R;
1313
+ }, []);
1314
+ }, o.fromString = function(N, R) {
1315
+ const B = h(N, a.isKanjiModeEnabled()), T = P(B), w = b(T, R), C = u.find_path(w.map, "start", "end"), y = [];
1316
+ for (let g = 1; g < C.length - 1; g++)
1317
+ y.push(w.table[C[g]].node);
1318
+ return o.fromArray(d(y));
1319
+ }, o.rawSplit = function(N) {
1320
+ return o.fromArray(
1321
+ h(N, a.isKanjiModeEnabled())
1322
+ );
1323
+ };
1324
+ })(ut)), ut;
1325
+ }
1326
+ var Kt;
1327
+ function Ie() {
1328
+ if (Kt) return Q;
1329
+ Kt = 1;
1330
+ const o = q(), r = pt(), i = se(), n = ae(), t = ue(), e = ce(), s = le(), a = Qt(), u = he(), c = ge(), l = we(), h = F(), f = Be();
1331
+ function d(w, C) {
1332
+ const y = w.size, g = e.getPositions(C);
1333
+ for (let I = 0; I < g.length; I++) {
1334
+ const m = g[I][0], E = g[I][1];
1335
+ for (let p = -1; p <= 7; p++)
1336
+ if (!(m + p <= -1 || y <= m + p))
1337
+ for (let S = -1; S <= 7; S++)
1338
+ E + S <= -1 || y <= E + S || (p >= 0 && p <= 6 && (S === 0 || S === 6) || S >= 0 && S <= 6 && (p === 0 || p === 6) || p >= 2 && p <= 4 && S >= 2 && S <= 4 ? w.set(m + p, E + S, !0, !0) : w.set(m + p, E + S, !1, !0));
1339
+ }
1340
+ }
1341
+ function P(w) {
1342
+ const C = w.size;
1343
+ for (let y = 8; y < C - 8; y++) {
1344
+ const g = y % 2 === 0;
1345
+ w.set(y, 6, g, !0), w.set(6, y, g, !0);
1346
+ }
1347
+ }
1348
+ function b(w, C) {
1349
+ const y = t.getPositions(C);
1350
+ for (let g = 0; g < y.length; g++) {
1351
+ const I = y[g][0], m = y[g][1];
1352
+ for (let E = -2; E <= 2; E++)
1353
+ for (let p = -2; p <= 2; p++)
1354
+ E === -2 || E === 2 || p === -2 || p === 2 || E === 0 && p === 0 ? w.set(I + E, m + p, !0, !0) : w.set(I + E, m + p, !1, !0);
1355
+ }
1356
+ }
1357
+ function M(w, C) {
1358
+ const y = w.size, g = c.getEncodedBits(C);
1359
+ let I, m, E;
1360
+ for (let p = 0; p < 18; p++)
1361
+ I = Math.floor(p / 3), m = p % 3 + y - 8 - 3, E = (g >> p & 1) === 1, w.set(I, m, E, !0), w.set(m, I, E, !0);
1362
+ }
1363
+ function A(w, C, y) {
1364
+ const g = w.size, I = l.getEncodedBits(C, y);
1365
+ let m, E;
1366
+ for (m = 0; m < 15; m++)
1367
+ E = (I >> m & 1) === 1, m < 6 ? w.set(m, 8, E, !0) : m < 8 ? w.set(m + 1, 8, E, !0) : w.set(g - 15 + m, 8, E, !0), m < 8 ? w.set(8, g - m - 1, E, !0) : m < 9 ? w.set(8, 15 - m - 1 + 1, E, !0) : w.set(8, 15 - m - 1, E, !0);
1368
+ w.set(g - 8, 8, 1, !0);
1369
+ }
1370
+ function N(w, C) {
1371
+ const y = w.size;
1372
+ let g = -1, I = y - 1, m = 7, E = 0;
1373
+ for (let p = y - 1; p > 0; p -= 2)
1374
+ for (p === 6 && p--; ; ) {
1375
+ for (let S = 0; S < 2; S++)
1376
+ if (!w.isReserved(I, p - S)) {
1377
+ let v = !1;
1378
+ E < C.length && (v = (C[E] >>> m & 1) === 1), w.set(I, p - S, v), m--, m === -1 && (E++, m = 7);
1379
+ }
1380
+ if (I += g, I < 0 || y <= I) {
1381
+ I -= g, g = -g;
1382
+ break;
1383
+ }
1384
+ }
1385
+ }
1386
+ function R(w, C, y) {
1387
+ const g = new i();
1388
+ y.forEach(function(S) {
1389
+ g.put(S.mode.bit, 4), g.put(S.getLength(), h.getCharCountIndicator(S.mode, w)), S.write(g);
1390
+ });
1391
+ const I = o.getSymbolTotalCodewords(w), m = a.getTotalCodewordsCount(w, C), E = (I - m) * 8;
1392
+ for (g.getLengthInBits() + 4 <= E && g.put(0, 4); g.getLengthInBits() % 8 !== 0; )
1393
+ g.putBit(0);
1394
+ const p = (E - g.getLengthInBits()) / 8;
1395
+ for (let S = 0; S < p; S++)
1396
+ g.put(S % 2 ? 17 : 236, 8);
1397
+ return B(g, w, C);
1398
+ }
1399
+ function B(w, C, y) {
1400
+ const g = o.getSymbolTotalCodewords(C), I = a.getTotalCodewordsCount(C, y), m = g - I, E = a.getBlocksCount(C, y), p = g % E, S = E - p, v = Math.floor(g / E), z = Math.floor(m / E), $t = z + 1, yt = v - z, te = new u(yt);
1401
+ let K = 0;
1402
+ const V = new Array(E), Ct = new Array(E);
1403
+ let H = 0;
1404
+ const ee = new Uint8Array(w.buffer);
1405
+ for (let k = 0; k < E; k++) {
1406
+ const x = k < S ? z : $t;
1407
+ V[k] = ee.slice(K, K + x), Ct[k] = te.encode(V[k]), K += x, H = Math.max(H, x);
1408
+ }
1409
+ const Y = new Uint8Array(g);
1410
+ let Et = 0, D, L;
1411
+ for (D = 0; D < H; D++)
1412
+ for (L = 0; L < E; L++)
1413
+ D < V[L].length && (Y[Et++] = V[L][D]);
1414
+ for (D = 0; D < yt; D++)
1415
+ for (L = 0; L < E; L++)
1416
+ Y[Et++] = Ct[L][D];
1417
+ return Y;
1418
+ }
1419
+ function T(w, C, y, g) {
1420
+ let I;
1421
+ if (Array.isArray(w))
1422
+ I = f.fromArray(w);
1423
+ else if (typeof w == "string") {
1424
+ let v = C;
1425
+ if (!v) {
1426
+ const z = f.rawSplit(w);
1427
+ v = c.getBestVersionForData(z, y);
1428
+ }
1429
+ I = f.fromString(w, v || 40);
1430
+ } else
1431
+ throw new Error("Invalid data");
1432
+ const m = c.getBestVersionForData(I, y);
1433
+ if (!m)
1434
+ throw new Error("The amount of data is too big to be stored in a QR Code");
1435
+ if (!C)
1436
+ C = m;
1437
+ else if (C < m)
1438
+ throw new Error(
1439
+ `
1440
+ The chosen QR Code version cannot contain this amount of data.
1441
+ Minimum version required to store current data is: ` + m + `.
1442
+ `
1443
+ );
1444
+ const E = R(C, y, I), p = o.getSymbolSize(C), S = new n(p);
1445
+ return d(S, C), P(S), b(S, C), A(S, y, 0), C >= 7 && M(S, C), N(S, E), isNaN(g) && (g = s.getBestMask(
1446
+ S,
1447
+ A.bind(null, S, y)
1448
+ )), s.applyMask(g, S), A(S, y, g), {
1449
+ modules: S,
1450
+ version: C,
1451
+ errorCorrectionLevel: y,
1452
+ maskPattern: g,
1453
+ segments: I
1454
+ };
1455
+ }
1456
+ return Q.create = function(C, y) {
1457
+ if (typeof C > "u" || C === "")
1458
+ throw new Error("No input text");
1459
+ let g = r.M, I, m;
1460
+ return typeof y < "u" && (g = r.from(y.errorCorrectionLevel, r.M), I = c.from(y.version), m = s.from(y.maskPattern), y.toSJISFunc && o.setToSJISFunction(y.toSJISFunc)), T(C, I, g, m);
1461
+ }, Q;
1462
+ }
1463
+ var gt = {}, wt = {}, Ht;
1464
+ function Xt() {
1465
+ return Ht || (Ht = 1, (function(o) {
1466
+ function r(i) {
1467
+ if (typeof i == "number" && (i = i.toString()), typeof i != "string")
1468
+ throw new Error("Color should be defined as hex string");
1469
+ let n = i.slice().replace("#", "").split("");
1470
+ if (n.length < 3 || n.length === 5 || n.length > 8)
1471
+ throw new Error("Invalid hex color: " + i);
1472
+ (n.length === 3 || n.length === 4) && (n = Array.prototype.concat.apply([], n.map(function(e) {
1473
+ return [e, e];
1474
+ }))), n.length === 6 && n.push("F", "F");
1475
+ const t = parseInt(n.join(""), 16);
1476
+ return {
1477
+ r: t >> 24 & 255,
1478
+ g: t >> 16 & 255,
1479
+ b: t >> 8 & 255,
1480
+ a: t & 255,
1481
+ hex: "#" + n.slice(0, 6).join("")
1482
+ };
1483
+ }
1484
+ o.getOptions = function(n) {
1485
+ n || (n = {}), n.color || (n.color = {});
1486
+ const t = typeof n.margin > "u" || n.margin === null || n.margin < 0 ? 4 : n.margin, e = n.width && n.width >= 21 ? n.width : void 0, s = n.scale || 4;
1487
+ return {
1488
+ width: e,
1489
+ scale: e ? 4 : s,
1490
+ margin: t,
1491
+ color: {
1492
+ dark: r(n.color.dark || "#000000ff"),
1493
+ light: r(n.color.light || "#ffffffff")
1494
+ },
1495
+ type: n.type,
1496
+ rendererOpts: n.rendererOpts || {}
1497
+ };
1498
+ }, o.getScale = function(n, t) {
1499
+ return t.width && t.width >= n + t.margin * 2 ? t.width / (n + t.margin * 2) : t.scale;
1500
+ }, o.getImageWidth = function(n, t) {
1501
+ const e = o.getScale(n, t);
1502
+ return Math.floor((n + t.margin * 2) * e);
1503
+ }, o.qrToImageData = function(n, t, e) {
1504
+ const s = t.modules.size, a = t.modules.data, u = o.getScale(s, e), c = Math.floor((s + e.margin * 2) * u), l = e.margin * u, h = [e.color.light, e.color.dark];
1505
+ for (let f = 0; f < c; f++)
1506
+ for (let d = 0; d < c; d++) {
1507
+ let P = (f * c + d) * 4, b = e.color.light;
1508
+ if (f >= l && d >= l && f < c - l && d < c - l) {
1509
+ const M = Math.floor((f - l) / u), A = Math.floor((d - l) / u);
1510
+ b = h[a[M * s + A] ? 1 : 0];
1511
+ }
1512
+ n[P++] = b.r, n[P++] = b.g, n[P++] = b.b, n[P] = b.a;
1513
+ }
1514
+ };
1515
+ })(wt)), wt;
1516
+ }
1517
+ var Yt;
1518
+ function Ae() {
1519
+ return Yt || (Yt = 1, (function(o) {
1520
+ const r = Xt();
1521
+ function i(t, e, s) {
1522
+ t.clearRect(0, 0, e.width, e.height), e.style || (e.style = {}), e.height = s, e.width = s, e.style.height = s + "px", e.style.width = s + "px";
1523
+ }
1524
+ function n() {
1525
+ try {
1526
+ return document.createElement("canvas");
1527
+ } catch {
1528
+ throw new Error("You need to specify a canvas element");
1529
+ }
1530
+ }
1531
+ o.render = function(e, s, a) {
1532
+ let u = a, c = s;
1533
+ typeof u > "u" && (!s || !s.getContext) && (u = s, s = void 0), s || (c = n()), u = r.getOptions(u);
1534
+ const l = r.getImageWidth(e.modules.size, u), h = c.getContext("2d"), f = h.createImageData(l, l);
1535
+ return r.qrToImageData(f.data, e, u), i(h, c, l), h.putImageData(f, 0, 0), c;
1536
+ }, o.renderToDataURL = function(e, s, a) {
1537
+ let u = a;
1538
+ typeof u > "u" && (!s || !s.getContext) && (u = s, s = void 0), u || (u = {});
1539
+ const c = o.render(e, s, u), l = u.type || "image/png", h = u.rendererOpts || {};
1540
+ return c.toDataURL(l, h.quality);
1541
+ };
1542
+ })(gt)), gt;
1543
+ }
1544
+ var mt = {}, xt;
1545
+ function Re() {
1546
+ if (xt) return mt;
1547
+ xt = 1;
1548
+ const o = Xt();
1549
+ function r(t, e) {
1550
+ const s = t.a / 255, a = e + '="' + t.hex + '"';
1551
+ return s < 1 ? a + " " + e + '-opacity="' + s.toFixed(2).slice(1) + '"' : a;
1552
+ }
1553
+ function i(t, e, s) {
1554
+ let a = t + e;
1555
+ return typeof s < "u" && (a += " " + s), a;
1556
+ }
1557
+ function n(t, e, s) {
1558
+ let a = "", u = 0, c = !1, l = 0;
1559
+ for (let h = 0; h < t.length; h++) {
1560
+ const f = Math.floor(h % e), d = Math.floor(h / e);
1561
+ !f && !c && (c = !0), t[h] ? (l++, h > 0 && f > 0 && t[h - 1] || (a += c ? i("M", f + s, 0.5 + d + s) : i("m", u, 0), u = 0, c = !1), f + 1 < e && t[h + 1] || (a += i("h", l), l = 0)) : u++;
1562
+ }
1563
+ return a;
1564
+ }
1565
+ return mt.render = function(e, s, a) {
1566
+ const u = o.getOptions(s), c = e.modules.size, l = e.modules.data, h = c + u.margin * 2, f = u.color.light.a ? "<path " + r(u.color.light, "fill") + ' d="M0 0h' + h + "v" + h + 'H0z"/>' : "", d = "<path " + r(u.color.dark, "stroke") + ' d="' + n(l, c, u.margin) + '"/>', P = 'viewBox="0 0 ' + h + " " + h + '"', M = '<svg xmlns="http://www.w3.org/2000/svg" ' + (u.width ? 'width="' + u.width + '" height="' + u.width + '" ' : "") + P + ' shape-rendering="crispEdges">' + f + d + `</svg>
1567
+ `;
1568
+ return typeof a == "function" && a(null, M), M;
1569
+ }, mt;
1570
+ }
1571
+ var Gt;
1572
+ function Se() {
1573
+ if (Gt) return O;
1574
+ Gt = 1;
1575
+ const o = ie(), r = Ie(), i = Ae(), n = Re();
1576
+ function t(e, s, a, u, c) {
1577
+ const l = [].slice.call(arguments, 1), h = l.length, f = typeof l[h - 1] == "function";
1578
+ if (!f && !o())
1579
+ throw new Error("Callback required as last argument");
1580
+ if (f) {
1581
+ if (h < 2)
1582
+ throw new Error("Too few arguments provided");
1583
+ h === 2 ? (c = a, a = s, s = u = void 0) : h === 3 && (s.getContext && typeof c > "u" ? (c = u, u = void 0) : (c = u, u = a, a = s, s = void 0));
1584
+ } else {
1585
+ if (h < 1)
1586
+ throw new Error("Too few arguments provided");
1587
+ return h === 1 ? (a = s, s = u = void 0) : h === 2 && !s.getContext && (u = a, a = s, s = void 0), new Promise(function(d, P) {
1588
+ try {
1589
+ const b = r.create(a, u);
1590
+ d(e(b, s, u));
1591
+ } catch (b) {
1592
+ P(b);
1593
+ }
1594
+ });
1595
+ }
1596
+ try {
1597
+ const d = r.create(a, u);
1598
+ c(null, e(d, s, u));
1599
+ } catch (d) {
1600
+ c(d);
1601
+ }
1602
+ }
1603
+ return O.create = r.create, O.toCanvas = t.bind(null, i.render), O.toDataURL = t.bind(null, i.renderToDataURL), O.toString = t.bind(null, function(e, s, a) {
1604
+ return n.render(e, a);
1605
+ }), O;
1606
+ }
1607
+ var Pe = Se();
1608
+ const be = /* @__PURE__ */ oe(Pe);
1609
+ class Me {
1610
+ constructor(r, i) {
1611
+ this._playerConnections = /* @__PURE__ */ new Map(), this._playerChannels = /* @__PURE__ */ new Map(), this._invitationAccepted = /* @__PURE__ */ new Map(), this._onPlayerEvent = null, this._onPlayerEvent = i, this._gamepadUiUrl = r;
1612
+ const n = new BroadcastChannel("touch-coop-signaling");
1613
+ n.onmessage = async (t) => {
1614
+ const e = t.data;
1615
+ if (e && e.type === "answer" && e.playerId && e.base64Answer)
1616
+ try {
1617
+ const s = this._playerConnections.get(e.playerId);
1618
+ if (!s)
1619
+ throw new Error(`No peer connection for player: ${e.playerId}`);
1620
+ const a = JSON.parse(atob(e.base64Answer));
1621
+ await s.setRemoteDescription(a.sdp), this._invitationAccepted.set(e.playerId, !0);
1622
+ } catch {
1623
+ }
1624
+ };
1625
+ }
1626
+ _UUIID() {
1627
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (r) => {
1628
+ const i = Math.random() * 16 | 0;
1629
+ return (r === "x" ? i : i & 3 | 8).toString(16);
1630
+ });
1631
+ }
1632
+ async requestNewPlayerToJoin() {
1633
+ return new Promise(
1634
+ (r, i) => {
1635
+ (async () => {
1636
+ const n = this._UUIID(), t = new RTCPeerConnection(), e = t.createDataChannel("player");
1637
+ this._playerConnections.set(n, t), this._playerChannels.set(n, e), this._invitationAccepted.set(n, !1), e.onmessage = (h) => {
1638
+ if (this._onPlayerEvent) {
1639
+ let f = h.data;
1640
+ f = JSON.parse(h.data), this._onPlayerEvent(f);
1641
+ }
1642
+ };
1643
+ const s = await t.createOffer();
1644
+ await t.setLocalDescription(s), await new Promise((h) => {
1645
+ t.onicecandidate = (f) => {
1646
+ f.candidate || h(void 0);
1647
+ };
1648
+ });
1649
+ const a = {
1650
+ playerId: n,
1651
+ sdp: t.localDescription
1652
+ }, u = JSON.stringify(a), c = await ne(u), l = `${this._gamepadUiUrl}?remoteSDP=${c}`;
1653
+ be.toDataURL(
1654
+ l,
1655
+ { errorCorrectionLevel: "M" },
1656
+ (h, f) => {
1657
+ if (h)
1658
+ return i(h);
1659
+ r({
1660
+ dataUrl: f,
1661
+ shareURL: l,
1662
+ playerId: n
1663
+ });
1664
+ }
1665
+ );
1666
+ })();
1667
+ }
1668
+ );
1669
+ }
1670
+ // Returns true if invitation was accepted, false if still pending, undefined if not found
1671
+ getInvitationStatus(r) {
1672
+ return this._invitationAccepted.get(r);
1673
+ }
1674
+ async acceptPlayerAnswer(r, i) {
1675
+ }
1676
+ }
1677
+ export {
1678
+ Me as Match,
1679
+ Ne as Player
1680
+ };