@auth-link/web 0.0.0-stage → 0.0.2

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/vue.js ADDED
@@ -0,0 +1,2550 @@
1
+ // src/vue.ts
2
+ import { defineComponent, normalizeClass, onBeforeUnmount, onMounted, shallowRef, watch } from "vue";
3
+
4
+ // node_modules/qrcode-generator/dist/qrcode.mjs
5
+ var qrcode = function(typeNumber, errorCorrectionLevel) {
6
+ const PAD0 = 236;
7
+ const PAD1 = 17;
8
+ let _typeNumber = typeNumber;
9
+ const _errorCorrectionLevel = QRErrorCorrectionLevel[errorCorrectionLevel];
10
+ let _modules = null;
11
+ let _moduleCount = 0;
12
+ let _dataCache = null;
13
+ const _dataList = [];
14
+ const _this = {};
15
+ const makeImpl = function(test, maskPattern) {
16
+ _moduleCount = _typeNumber * 4 + 17;
17
+ _modules = (function(moduleCount) {
18
+ const modules = new Array(moduleCount);
19
+ for (let row = 0; row < moduleCount; row += 1) {
20
+ modules[row] = new Array(moduleCount);
21
+ for (let col = 0; col < moduleCount; col += 1) {
22
+ modules[row][col] = null;
23
+ }
24
+ }
25
+ return modules;
26
+ })(_moduleCount);
27
+ setupPositionProbePattern(0, 0);
28
+ setupPositionProbePattern(_moduleCount - 7, 0);
29
+ setupPositionProbePattern(0, _moduleCount - 7);
30
+ setupPositionAdjustPattern();
31
+ setupTimingPattern();
32
+ setupTypeInfo(test, maskPattern);
33
+ if (_typeNumber >= 7) {
34
+ setupTypeNumber(test);
35
+ }
36
+ if (_dataCache == null) {
37
+ _dataCache = createData(_typeNumber, _errorCorrectionLevel, _dataList);
38
+ }
39
+ mapData(_dataCache, maskPattern);
40
+ };
41
+ const setupPositionProbePattern = function(row, col) {
42
+ for (let r = -1; r <= 7; r += 1) {
43
+ if (row + r <= -1 || _moduleCount <= row + r) continue;
44
+ for (let c = -1; c <= 7; c += 1) {
45
+ if (col + c <= -1 || _moduleCount <= col + c) continue;
46
+ if (0 <= r && r <= 6 && (c == 0 || c == 6) || 0 <= c && c <= 6 && (r == 0 || r == 6) || 2 <= r && r <= 4 && 2 <= c && c <= 4) {
47
+ _modules[row + r][col + c] = true;
48
+ } else {
49
+ _modules[row + r][col + c] = false;
50
+ }
51
+ }
52
+ }
53
+ };
54
+ const getBestMaskPattern = function() {
55
+ let minLostPoint = 0;
56
+ let pattern = 0;
57
+ for (let i = 0; i < 8; i += 1) {
58
+ makeImpl(true, i);
59
+ const lostPoint = QRUtil.getLostPoint(_this);
60
+ if (i == 0 || minLostPoint > lostPoint) {
61
+ minLostPoint = lostPoint;
62
+ pattern = i;
63
+ }
64
+ }
65
+ return pattern;
66
+ };
67
+ const setupTimingPattern = function() {
68
+ for (let r = 8; r < _moduleCount - 8; r += 1) {
69
+ if (_modules[r][6] != null) {
70
+ continue;
71
+ }
72
+ _modules[r][6] = r % 2 == 0;
73
+ }
74
+ for (let c = 8; c < _moduleCount - 8; c += 1) {
75
+ if (_modules[6][c] != null) {
76
+ continue;
77
+ }
78
+ _modules[6][c] = c % 2 == 0;
79
+ }
80
+ };
81
+ const setupPositionAdjustPattern = function() {
82
+ const pos = QRUtil.getPatternPosition(_typeNumber);
83
+ for (let i = 0; i < pos.length; i += 1) {
84
+ for (let j = 0; j < pos.length; j += 1) {
85
+ const row = pos[i];
86
+ const col = pos[j];
87
+ if (_modules[row][col] != null) {
88
+ continue;
89
+ }
90
+ for (let r = -2; r <= 2; r += 1) {
91
+ for (let c = -2; c <= 2; c += 1) {
92
+ if (r == -2 || r == 2 || c == -2 || c == 2 || r == 0 && c == 0) {
93
+ _modules[row + r][col + c] = true;
94
+ } else {
95
+ _modules[row + r][col + c] = false;
96
+ }
97
+ }
98
+ }
99
+ }
100
+ }
101
+ };
102
+ const setupTypeNumber = function(test) {
103
+ const bits = QRUtil.getBCHTypeNumber(_typeNumber);
104
+ for (let i = 0; i < 18; i += 1) {
105
+ const mod = !test && (bits >> i & 1) == 1;
106
+ _modules[Math.floor(i / 3)][i % 3 + _moduleCount - 8 - 3] = mod;
107
+ }
108
+ for (let i = 0; i < 18; i += 1) {
109
+ const mod = !test && (bits >> i & 1) == 1;
110
+ _modules[i % 3 + _moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
111
+ }
112
+ };
113
+ const setupTypeInfo = function(test, maskPattern) {
114
+ const data = _errorCorrectionLevel << 3 | maskPattern;
115
+ const bits = QRUtil.getBCHTypeInfo(data);
116
+ for (let i = 0; i < 15; i += 1) {
117
+ const mod = !test && (bits >> i & 1) == 1;
118
+ if (i < 6) {
119
+ _modules[i][8] = mod;
120
+ } else if (i < 8) {
121
+ _modules[i + 1][8] = mod;
122
+ } else {
123
+ _modules[_moduleCount - 15 + i][8] = mod;
124
+ }
125
+ }
126
+ for (let i = 0; i < 15; i += 1) {
127
+ const mod = !test && (bits >> i & 1) == 1;
128
+ if (i < 8) {
129
+ _modules[8][_moduleCount - i - 1] = mod;
130
+ } else if (i < 9) {
131
+ _modules[8][15 - i - 1 + 1] = mod;
132
+ } else {
133
+ _modules[8][15 - i - 1] = mod;
134
+ }
135
+ }
136
+ _modules[_moduleCount - 8][8] = !test;
137
+ };
138
+ const mapData = function(data, maskPattern) {
139
+ let inc = -1;
140
+ let row = _moduleCount - 1;
141
+ let bitIndex = 7;
142
+ let byteIndex = 0;
143
+ const maskFunc = QRUtil.getMaskFunction(maskPattern);
144
+ for (let col = _moduleCount - 1; col > 0; col -= 2) {
145
+ if (col == 6) col -= 1;
146
+ while (true) {
147
+ for (let c = 0; c < 2; c += 1) {
148
+ if (_modules[row][col - c] == null) {
149
+ let dark = false;
150
+ if (byteIndex < data.length) {
151
+ dark = (data[byteIndex] >>> bitIndex & 1) == 1;
152
+ }
153
+ const mask = maskFunc(row, col - c);
154
+ if (mask) {
155
+ dark = !dark;
156
+ }
157
+ _modules[row][col - c] = dark;
158
+ bitIndex -= 1;
159
+ if (bitIndex == -1) {
160
+ byteIndex += 1;
161
+ bitIndex = 7;
162
+ }
163
+ }
164
+ }
165
+ row += inc;
166
+ if (row < 0 || _moduleCount <= row) {
167
+ row -= inc;
168
+ inc = -inc;
169
+ break;
170
+ }
171
+ }
172
+ }
173
+ };
174
+ const createBytes = function(buffer, rsBlocks) {
175
+ let offset = 0;
176
+ let maxDcCount = 0;
177
+ let maxEcCount = 0;
178
+ const dcdata = new Array(rsBlocks.length);
179
+ const ecdata = new Array(rsBlocks.length);
180
+ for (let r = 0; r < rsBlocks.length; r += 1) {
181
+ const dcCount = rsBlocks[r].dataCount;
182
+ const ecCount = rsBlocks[r].totalCount - dcCount;
183
+ maxDcCount = Math.max(maxDcCount, dcCount);
184
+ maxEcCount = Math.max(maxEcCount, ecCount);
185
+ dcdata[r] = new Array(dcCount);
186
+ for (let i = 0; i < dcdata[r].length; i += 1) {
187
+ dcdata[r][i] = 255 & buffer.getBuffer()[i + offset];
188
+ }
189
+ offset += dcCount;
190
+ const rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
191
+ const rawPoly = qrPolynomial(dcdata[r], rsPoly.getLength() - 1);
192
+ const modPoly = rawPoly.mod(rsPoly);
193
+ ecdata[r] = new Array(rsPoly.getLength() - 1);
194
+ for (let i = 0; i < ecdata[r].length; i += 1) {
195
+ const modIndex = i + modPoly.getLength() - ecdata[r].length;
196
+ ecdata[r][i] = modIndex >= 0 ? modPoly.getAt(modIndex) : 0;
197
+ }
198
+ }
199
+ let totalCodeCount = 0;
200
+ for (let i = 0; i < rsBlocks.length; i += 1) {
201
+ totalCodeCount += rsBlocks[i].totalCount;
202
+ }
203
+ const data = new Array(totalCodeCount);
204
+ let index = 0;
205
+ for (let i = 0; i < maxDcCount; i += 1) {
206
+ for (let r = 0; r < rsBlocks.length; r += 1) {
207
+ if (i < dcdata[r].length) {
208
+ data[index] = dcdata[r][i];
209
+ index += 1;
210
+ }
211
+ }
212
+ }
213
+ for (let i = 0; i < maxEcCount; i += 1) {
214
+ for (let r = 0; r < rsBlocks.length; r += 1) {
215
+ if (i < ecdata[r].length) {
216
+ data[index] = ecdata[r][i];
217
+ index += 1;
218
+ }
219
+ }
220
+ }
221
+ return data;
222
+ };
223
+ const createData = function(typeNumber2, errorCorrectionLevel2, dataList) {
224
+ const rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, errorCorrectionLevel2);
225
+ const buffer = qrBitBuffer();
226
+ for (let i = 0; i < dataList.length; i += 1) {
227
+ const data = dataList[i];
228
+ buffer.put(data.getMode(), 4);
229
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
230
+ data.write(buffer);
231
+ }
232
+ let totalDataCount = 0;
233
+ for (let i = 0; i < rsBlocks.length; i += 1) {
234
+ totalDataCount += rsBlocks[i].dataCount;
235
+ }
236
+ if (buffer.getLengthInBits() > totalDataCount * 8) {
237
+ throw "code length overflow. (" + buffer.getLengthInBits() + ">" + totalDataCount * 8 + ")";
238
+ }
239
+ if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
240
+ buffer.put(0, 4);
241
+ }
242
+ while (buffer.getLengthInBits() % 8 != 0) {
243
+ buffer.putBit(false);
244
+ }
245
+ while (true) {
246
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
247
+ break;
248
+ }
249
+ buffer.put(PAD0, 8);
250
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
251
+ break;
252
+ }
253
+ buffer.put(PAD1, 8);
254
+ }
255
+ return createBytes(buffer, rsBlocks);
256
+ };
257
+ _this.addData = function(data, mode) {
258
+ mode = mode || "Byte";
259
+ let newData = null;
260
+ switch (mode) {
261
+ case "Numeric":
262
+ newData = qrNumber(data);
263
+ break;
264
+ case "Alphanumeric":
265
+ newData = qrAlphaNum(data);
266
+ break;
267
+ case "Byte":
268
+ newData = qr8BitByte(data);
269
+ break;
270
+ case "Kanji":
271
+ newData = qrKanji(data);
272
+ break;
273
+ default:
274
+ throw "mode:" + mode;
275
+ }
276
+ _dataList.push(newData);
277
+ _dataCache = null;
278
+ };
279
+ _this.isDark = function(row, col) {
280
+ if (row < 0 || _moduleCount <= row || col < 0 || _moduleCount <= col) {
281
+ throw row + "," + col;
282
+ }
283
+ return _modules[row][col];
284
+ };
285
+ _this.getModuleCount = function() {
286
+ return _moduleCount;
287
+ };
288
+ _this.make = function() {
289
+ if (_typeNumber < 1) {
290
+ let typeNumber2 = 1;
291
+ for (; typeNumber2 < 40; typeNumber2++) {
292
+ const rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, _errorCorrectionLevel);
293
+ const buffer = qrBitBuffer();
294
+ for (let i = 0; i < _dataList.length; i++) {
295
+ const data = _dataList[i];
296
+ buffer.put(data.getMode(), 4);
297
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
298
+ data.write(buffer);
299
+ }
300
+ let totalDataCount = 0;
301
+ for (let i = 0; i < rsBlocks.length; i++) {
302
+ totalDataCount += rsBlocks[i].dataCount;
303
+ }
304
+ if (buffer.getLengthInBits() <= totalDataCount * 8) {
305
+ break;
306
+ }
307
+ }
308
+ _typeNumber = typeNumber2;
309
+ }
310
+ makeImpl(false, getBestMaskPattern());
311
+ };
312
+ _this.createTableTag = function(cellSize, margin) {
313
+ cellSize = cellSize || 2;
314
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
315
+ let qrHtml = "";
316
+ qrHtml += '<table style="';
317
+ qrHtml += " border-width: 0px; border-style: none;";
318
+ qrHtml += " border-collapse: collapse;";
319
+ qrHtml += " padding: 0px; margin: " + margin + "px;";
320
+ qrHtml += '">';
321
+ qrHtml += "<tbody>";
322
+ for (let r = 0; r < _this.getModuleCount(); r += 1) {
323
+ qrHtml += "<tr>";
324
+ for (let c = 0; c < _this.getModuleCount(); c += 1) {
325
+ qrHtml += '<td style="';
326
+ qrHtml += " border-width: 0px; border-style: none;";
327
+ qrHtml += " border-collapse: collapse;";
328
+ qrHtml += " padding: 0px; margin: 0px;";
329
+ qrHtml += " width: " + cellSize + "px;";
330
+ qrHtml += " height: " + cellSize + "px;";
331
+ qrHtml += " background-color: ";
332
+ qrHtml += _this.isDark(r, c) ? "#000000" : "#ffffff";
333
+ qrHtml += ";";
334
+ qrHtml += '"/>';
335
+ }
336
+ qrHtml += "</tr>";
337
+ }
338
+ qrHtml += "</tbody>";
339
+ qrHtml += "</table>";
340
+ return qrHtml;
341
+ };
342
+ _this.createSvgTag = function(cellSize, margin, alt, title) {
343
+ let opts = {};
344
+ if (typeof arguments[0] == "object") {
345
+ opts = arguments[0];
346
+ cellSize = opts.cellSize;
347
+ margin = opts.margin;
348
+ alt = opts.alt;
349
+ title = opts.title;
350
+ }
351
+ cellSize = cellSize || 2;
352
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
353
+ alt = typeof alt === "string" ? { text: alt } : alt || {};
354
+ alt.text = alt.text || null;
355
+ alt.id = alt.text ? alt.id || "qrcode-description" : null;
356
+ title = typeof title === "string" ? { text: title } : title || {};
357
+ title.text = title.text || null;
358
+ title.id = title.text ? title.id || "qrcode-title" : null;
359
+ const size = _this.getModuleCount() * cellSize + margin * 2;
360
+ let c, mc, r, mr, qrSvg = "", rect;
361
+ rect = "l" + cellSize + ",0 0," + cellSize + " -" + cellSize + ",0 0,-" + cellSize + "z ";
362
+ qrSvg += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg"';
363
+ qrSvg += !opts.scalable ? ' width="' + size + 'px" height="' + size + 'px"' : "";
364
+ qrSvg += ' viewBox="0 0 ' + size + " " + size + '" ';
365
+ qrSvg += ' preserveAspectRatio="xMinYMin meet"';
366
+ qrSvg += title.text || alt.text ? ' role="img" aria-labelledby="' + escapeXml([title.id, alt.id].join(" ").trim()) + '"' : "";
367
+ qrSvg += ">";
368
+ qrSvg += title.text ? '<title id="' + escapeXml(title.id) + '">' + escapeXml(title.text) + "</title>" : "";
369
+ qrSvg += alt.text ? '<description id="' + escapeXml(alt.id) + '">' + escapeXml(alt.text) + "</description>" : "";
370
+ qrSvg += '<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>';
371
+ qrSvg += '<path d="';
372
+ for (r = 0; r < _this.getModuleCount(); r += 1) {
373
+ mr = r * cellSize + margin;
374
+ for (c = 0; c < _this.getModuleCount(); c += 1) {
375
+ if (_this.isDark(r, c)) {
376
+ mc = c * cellSize + margin;
377
+ qrSvg += "M" + mc + "," + mr + rect;
378
+ }
379
+ }
380
+ }
381
+ qrSvg += '" stroke="transparent" fill="black"/>';
382
+ qrSvg += "</svg>";
383
+ return qrSvg;
384
+ };
385
+ _this.createDataURL = function(cellSize, margin) {
386
+ cellSize = cellSize || 2;
387
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
388
+ const size = _this.getModuleCount() * cellSize + margin * 2;
389
+ const min = margin;
390
+ const max = size - margin;
391
+ return createDataURL(size, size, function(x, y) {
392
+ if (min <= x && x < max && min <= y && y < max) {
393
+ const c = Math.floor((x - min) / cellSize);
394
+ const r = Math.floor((y - min) / cellSize);
395
+ return _this.isDark(r, c) ? 0 : 1;
396
+ } else {
397
+ return 1;
398
+ }
399
+ });
400
+ };
401
+ _this.createImgTag = function(cellSize, margin, alt) {
402
+ cellSize = cellSize || 2;
403
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
404
+ const size = _this.getModuleCount() * cellSize + margin * 2;
405
+ let img = "";
406
+ img += "<img";
407
+ img += ' src="';
408
+ img += _this.createDataURL(cellSize, margin);
409
+ img += '"';
410
+ img += ' width="';
411
+ img += size;
412
+ img += '"';
413
+ img += ' height="';
414
+ img += size;
415
+ img += '"';
416
+ if (alt) {
417
+ img += ' alt="';
418
+ img += escapeXml(alt);
419
+ img += '"';
420
+ }
421
+ img += "/>";
422
+ return img;
423
+ };
424
+ const escapeXml = function(s) {
425
+ let escaped = "";
426
+ for (let i = 0; i < s.length; i += 1) {
427
+ const c = s.charAt(i);
428
+ switch (c) {
429
+ case "<":
430
+ escaped += "&lt;";
431
+ break;
432
+ case ">":
433
+ escaped += "&gt;";
434
+ break;
435
+ case "&":
436
+ escaped += "&amp;";
437
+ break;
438
+ case '"':
439
+ escaped += "&quot;";
440
+ break;
441
+ default:
442
+ escaped += c;
443
+ break;
444
+ }
445
+ }
446
+ return escaped;
447
+ };
448
+ const _createHalfASCII = function(margin) {
449
+ const cellSize = 1;
450
+ margin = typeof margin == "undefined" ? cellSize * 2 : margin;
451
+ const size = _this.getModuleCount() * cellSize + margin * 2;
452
+ const min = margin;
453
+ const max = size - margin;
454
+ let y, x, r1, r2, p;
455
+ const blocks = {
456
+ "\u2588\u2588": "\u2588",
457
+ "\u2588 ": "\u2580",
458
+ " \u2588": "\u2584",
459
+ " ": " "
460
+ };
461
+ const blocksLastLineNoMargin = {
462
+ "\u2588\u2588": "\u2580",
463
+ "\u2588 ": "\u2580",
464
+ " \u2588": " ",
465
+ " ": " "
466
+ };
467
+ let ascii = "";
468
+ for (y = 0; y < size; y += 2) {
469
+ r1 = Math.floor((y - min) / cellSize);
470
+ r2 = Math.floor((y + 1 - min) / cellSize);
471
+ for (x = 0; x < size; x += 1) {
472
+ p = "\u2588";
473
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r1, Math.floor((x - min) / cellSize))) {
474
+ p = " ";
475
+ }
476
+ if (min <= x && x < max && min <= y + 1 && y + 1 < max && _this.isDark(r2, Math.floor((x - min) / cellSize))) {
477
+ p += " ";
478
+ } else {
479
+ p += "\u2588";
480
+ }
481
+ ascii += margin < 1 && y + 1 >= max ? blocksLastLineNoMargin[p] : blocks[p];
482
+ }
483
+ ascii += "\n";
484
+ }
485
+ if (size % 2 && margin > 0) {
486
+ return ascii.substring(0, ascii.length - size - 1) + Array(size + 1).join("\u2580");
487
+ }
488
+ return ascii.substring(0, ascii.length - 1);
489
+ };
490
+ _this.createASCII = function(cellSize, margin) {
491
+ cellSize = cellSize || 1;
492
+ if (cellSize < 2) {
493
+ return _createHalfASCII(margin);
494
+ }
495
+ cellSize -= 1;
496
+ margin = typeof margin == "undefined" ? cellSize * 2 : margin;
497
+ const size = _this.getModuleCount() * cellSize + margin * 2;
498
+ const min = margin;
499
+ const max = size - margin;
500
+ let y, x, r, p;
501
+ const white = Array(cellSize + 1).join("\u2588\u2588");
502
+ const black = Array(cellSize + 1).join(" ");
503
+ let ascii = "";
504
+ let line = "";
505
+ for (y = 0; y < size; y += 1) {
506
+ r = Math.floor((y - min) / cellSize);
507
+ line = "";
508
+ for (x = 0; x < size; x += 1) {
509
+ p = 1;
510
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r, Math.floor((x - min) / cellSize))) {
511
+ p = 0;
512
+ }
513
+ line += p ? white : black;
514
+ }
515
+ for (r = 0; r < cellSize; r += 1) {
516
+ ascii += line + "\n";
517
+ }
518
+ }
519
+ return ascii.substring(0, ascii.length - 1);
520
+ };
521
+ _this.renderTo2dContext = function(context, cellSize) {
522
+ cellSize = cellSize || 2;
523
+ const length = _this.getModuleCount();
524
+ for (let row = 0; row < length; row++) {
525
+ for (let col = 0; col < length; col++) {
526
+ context.fillStyle = _this.isDark(row, col) ? "black" : "white";
527
+ context.fillRect(col * cellSize, row * cellSize, cellSize, cellSize);
528
+ }
529
+ }
530
+ };
531
+ return _this;
532
+ };
533
+ qrcode.stringToBytes = function(s) {
534
+ const bytes = [];
535
+ for (let i = 0; i < s.length; i += 1) {
536
+ const c = s.charCodeAt(i);
537
+ bytes.push(c & 255);
538
+ }
539
+ return bytes;
540
+ };
541
+ qrcode.createStringToBytes = function(unicodeData, numChars) {
542
+ const unicodeMap = (function() {
543
+ const bin = base64DecodeInputStream(unicodeData);
544
+ const read = function() {
545
+ const b = bin.read();
546
+ if (b == -1) throw "eof";
547
+ return b;
548
+ };
549
+ let count = 0;
550
+ const unicodeMap2 = {};
551
+ while (true) {
552
+ const b0 = bin.read();
553
+ if (b0 == -1) break;
554
+ const b1 = read();
555
+ const b2 = read();
556
+ const b3 = read();
557
+ const k = String.fromCharCode(b0 << 8 | b1);
558
+ const v = b2 << 8 | b3;
559
+ unicodeMap2[k] = v;
560
+ count += 1;
561
+ }
562
+ if (count != numChars) {
563
+ throw count + " != " + numChars;
564
+ }
565
+ return unicodeMap2;
566
+ })();
567
+ const unknownChar = "?".charCodeAt(0);
568
+ return function(s) {
569
+ const bytes = [];
570
+ for (let i = 0; i < s.length; i += 1) {
571
+ const c = s.charCodeAt(i);
572
+ if (c < 128) {
573
+ bytes.push(c);
574
+ } else {
575
+ const b = unicodeMap[s.charAt(i)];
576
+ if (typeof b == "number") {
577
+ if ((b & 255) == b) {
578
+ bytes.push(b);
579
+ } else {
580
+ bytes.push(b >>> 8);
581
+ bytes.push(b & 255);
582
+ }
583
+ } else {
584
+ bytes.push(unknownChar);
585
+ }
586
+ }
587
+ }
588
+ return bytes;
589
+ };
590
+ };
591
+ var QRMode = {
592
+ MODE_NUMBER: 1 << 0,
593
+ MODE_ALPHA_NUM: 1 << 1,
594
+ MODE_8BIT_BYTE: 1 << 2,
595
+ MODE_KANJI: 1 << 3
596
+ };
597
+ var QRErrorCorrectionLevel = {
598
+ L: 1,
599
+ M: 0,
600
+ Q: 3,
601
+ H: 2
602
+ };
603
+ var QRMaskPattern = {
604
+ PATTERN000: 0,
605
+ PATTERN001: 1,
606
+ PATTERN010: 2,
607
+ PATTERN011: 3,
608
+ PATTERN100: 4,
609
+ PATTERN101: 5,
610
+ PATTERN110: 6,
611
+ PATTERN111: 7
612
+ };
613
+ var QRUtil = (function() {
614
+ const PATTERN_POSITION_TABLE = [
615
+ [],
616
+ [6, 18],
617
+ [6, 22],
618
+ [6, 26],
619
+ [6, 30],
620
+ [6, 34],
621
+ [6, 22, 38],
622
+ [6, 24, 42],
623
+ [6, 26, 46],
624
+ [6, 28, 50],
625
+ [6, 30, 54],
626
+ [6, 32, 58],
627
+ [6, 34, 62],
628
+ [6, 26, 46, 66],
629
+ [6, 26, 48, 70],
630
+ [6, 26, 50, 74],
631
+ [6, 30, 54, 78],
632
+ [6, 30, 56, 82],
633
+ [6, 30, 58, 86],
634
+ [6, 34, 62, 90],
635
+ [6, 28, 50, 72, 94],
636
+ [6, 26, 50, 74, 98],
637
+ [6, 30, 54, 78, 102],
638
+ [6, 28, 54, 80, 106],
639
+ [6, 32, 58, 84, 110],
640
+ [6, 30, 58, 86, 114],
641
+ [6, 34, 62, 90, 118],
642
+ [6, 26, 50, 74, 98, 122],
643
+ [6, 30, 54, 78, 102, 126],
644
+ [6, 26, 52, 78, 104, 130],
645
+ [6, 30, 56, 82, 108, 134],
646
+ [6, 34, 60, 86, 112, 138],
647
+ [6, 30, 58, 86, 114, 142],
648
+ [6, 34, 62, 90, 118, 146],
649
+ [6, 30, 54, 78, 102, 126, 150],
650
+ [6, 24, 50, 76, 102, 128, 154],
651
+ [6, 28, 54, 80, 106, 132, 158],
652
+ [6, 32, 58, 84, 110, 136, 162],
653
+ [6, 26, 54, 82, 110, 138, 166],
654
+ [6, 30, 58, 86, 114, 142, 170]
655
+ ];
656
+ const G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
657
+ const G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
658
+ const G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
659
+ const _this = {};
660
+ const getBCHDigit = function(data) {
661
+ let digit = 0;
662
+ while (data != 0) {
663
+ digit += 1;
664
+ data >>>= 1;
665
+ }
666
+ return digit;
667
+ };
668
+ _this.getBCHTypeInfo = function(data) {
669
+ let d = data << 10;
670
+ while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
671
+ d ^= G15 << getBCHDigit(d) - getBCHDigit(G15);
672
+ }
673
+ return (data << 10 | d) ^ G15_MASK;
674
+ };
675
+ _this.getBCHTypeNumber = function(data) {
676
+ let d = data << 12;
677
+ while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
678
+ d ^= G18 << getBCHDigit(d) - getBCHDigit(G18);
679
+ }
680
+ return data << 12 | d;
681
+ };
682
+ _this.getPatternPosition = function(typeNumber) {
683
+ return PATTERN_POSITION_TABLE[typeNumber - 1];
684
+ };
685
+ _this.getMaskFunction = function(maskPattern) {
686
+ switch (maskPattern) {
687
+ case QRMaskPattern.PATTERN000:
688
+ return function(i, j) {
689
+ return (i + j) % 2 == 0;
690
+ };
691
+ case QRMaskPattern.PATTERN001:
692
+ return function(i, j) {
693
+ return i % 2 == 0;
694
+ };
695
+ case QRMaskPattern.PATTERN010:
696
+ return function(i, j) {
697
+ return j % 3 == 0;
698
+ };
699
+ case QRMaskPattern.PATTERN011:
700
+ return function(i, j) {
701
+ return (i + j) % 3 == 0;
702
+ };
703
+ case QRMaskPattern.PATTERN100:
704
+ return function(i, j) {
705
+ return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
706
+ };
707
+ case QRMaskPattern.PATTERN101:
708
+ return function(i, j) {
709
+ return i * j % 2 + i * j % 3 == 0;
710
+ };
711
+ case QRMaskPattern.PATTERN110:
712
+ return function(i, j) {
713
+ return (i * j % 2 + i * j % 3) % 2 == 0;
714
+ };
715
+ case QRMaskPattern.PATTERN111:
716
+ return function(i, j) {
717
+ return (i * j % 3 + (i + j) % 2) % 2 == 0;
718
+ };
719
+ default:
720
+ throw "bad maskPattern:" + maskPattern;
721
+ }
722
+ };
723
+ _this.getErrorCorrectPolynomial = function(errorCorrectLength) {
724
+ let a = qrPolynomial([1], 0);
725
+ for (let i = 0; i < errorCorrectLength; i += 1) {
726
+ a = a.multiply(qrPolynomial([1, QRMath.gexp(i)], 0));
727
+ }
728
+ return a;
729
+ };
730
+ _this.getLengthInBits = function(mode, type) {
731
+ if (1 <= type && type < 10) {
732
+ switch (mode) {
733
+ case QRMode.MODE_NUMBER:
734
+ return 10;
735
+ case QRMode.MODE_ALPHA_NUM:
736
+ return 9;
737
+ case QRMode.MODE_8BIT_BYTE:
738
+ return 8;
739
+ case QRMode.MODE_KANJI:
740
+ return 8;
741
+ default:
742
+ throw "mode:" + mode;
743
+ }
744
+ } else if (type < 27) {
745
+ switch (mode) {
746
+ case QRMode.MODE_NUMBER:
747
+ return 12;
748
+ case QRMode.MODE_ALPHA_NUM:
749
+ return 11;
750
+ case QRMode.MODE_8BIT_BYTE:
751
+ return 16;
752
+ case QRMode.MODE_KANJI:
753
+ return 10;
754
+ default:
755
+ throw "mode:" + mode;
756
+ }
757
+ } else if (type < 41) {
758
+ switch (mode) {
759
+ case QRMode.MODE_NUMBER:
760
+ return 14;
761
+ case QRMode.MODE_ALPHA_NUM:
762
+ return 13;
763
+ case QRMode.MODE_8BIT_BYTE:
764
+ return 16;
765
+ case QRMode.MODE_KANJI:
766
+ return 12;
767
+ default:
768
+ throw "mode:" + mode;
769
+ }
770
+ } else {
771
+ throw "type:" + type;
772
+ }
773
+ };
774
+ _this.getLostPoint = function(qrcode2) {
775
+ const moduleCount = qrcode2.getModuleCount();
776
+ let lostPoint = 0;
777
+ for (let row = 0; row < moduleCount; row += 1) {
778
+ for (let col = 0; col < moduleCount; col += 1) {
779
+ let sameCount = 0;
780
+ const dark = qrcode2.isDark(row, col);
781
+ for (let r = -1; r <= 1; r += 1) {
782
+ if (row + r < 0 || moduleCount <= row + r) {
783
+ continue;
784
+ }
785
+ for (let c = -1; c <= 1; c += 1) {
786
+ if (col + c < 0 || moduleCount <= col + c) {
787
+ continue;
788
+ }
789
+ if (r == 0 && c == 0) {
790
+ continue;
791
+ }
792
+ if (dark == qrcode2.isDark(row + r, col + c)) {
793
+ sameCount += 1;
794
+ }
795
+ }
796
+ }
797
+ if (sameCount > 5) {
798
+ lostPoint += 3 + sameCount - 5;
799
+ }
800
+ }
801
+ }
802
+ ;
803
+ for (let row = 0; row < moduleCount - 1; row += 1) {
804
+ for (let col = 0; col < moduleCount - 1; col += 1) {
805
+ let count = 0;
806
+ if (qrcode2.isDark(row, col)) count += 1;
807
+ if (qrcode2.isDark(row + 1, col)) count += 1;
808
+ if (qrcode2.isDark(row, col + 1)) count += 1;
809
+ if (qrcode2.isDark(row + 1, col + 1)) count += 1;
810
+ if (count == 0 || count == 4) {
811
+ lostPoint += 3;
812
+ }
813
+ }
814
+ }
815
+ for (let row = 0; row < moduleCount; row += 1) {
816
+ for (let col = 0; col < moduleCount - 6; col += 1) {
817
+ if (qrcode2.isDark(row, col) && !qrcode2.isDark(row, col + 1) && qrcode2.isDark(row, col + 2) && qrcode2.isDark(row, col + 3) && qrcode2.isDark(row, col + 4) && !qrcode2.isDark(row, col + 5) && qrcode2.isDark(row, col + 6)) {
818
+ lostPoint += 40;
819
+ }
820
+ }
821
+ }
822
+ for (let col = 0; col < moduleCount; col += 1) {
823
+ for (let row = 0; row < moduleCount - 6; row += 1) {
824
+ if (qrcode2.isDark(row, col) && !qrcode2.isDark(row + 1, col) && qrcode2.isDark(row + 2, col) && qrcode2.isDark(row + 3, col) && qrcode2.isDark(row + 4, col) && !qrcode2.isDark(row + 5, col) && qrcode2.isDark(row + 6, col)) {
825
+ lostPoint += 40;
826
+ }
827
+ }
828
+ }
829
+ let darkCount = 0;
830
+ for (let col = 0; col < moduleCount; col += 1) {
831
+ for (let row = 0; row < moduleCount; row += 1) {
832
+ if (qrcode2.isDark(row, col)) {
833
+ darkCount += 1;
834
+ }
835
+ }
836
+ }
837
+ const ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
838
+ lostPoint += ratio * 10;
839
+ return lostPoint;
840
+ };
841
+ return _this;
842
+ })();
843
+ var QRMath = (function() {
844
+ const EXP_TABLE = new Array(256);
845
+ const LOG_TABLE = new Array(256);
846
+ for (let i = 0; i < 8; i += 1) {
847
+ EXP_TABLE[i] = 1 << i;
848
+ }
849
+ for (let i = 8; i < 256; i += 1) {
850
+ EXP_TABLE[i] = EXP_TABLE[i - 4] ^ EXP_TABLE[i - 5] ^ EXP_TABLE[i - 6] ^ EXP_TABLE[i - 8];
851
+ }
852
+ for (let i = 0; i < 255; i += 1) {
853
+ LOG_TABLE[EXP_TABLE[i]] = i;
854
+ }
855
+ const _this = {};
856
+ _this.glog = function(n) {
857
+ if (n < 1) {
858
+ throw "glog(" + n + ")";
859
+ }
860
+ return LOG_TABLE[n];
861
+ };
862
+ _this.gexp = function(n) {
863
+ while (n < 0) {
864
+ n += 255;
865
+ }
866
+ while (n >= 256) {
867
+ n -= 255;
868
+ }
869
+ return EXP_TABLE[n];
870
+ };
871
+ return _this;
872
+ })();
873
+ var qrPolynomial = function(num, shift) {
874
+ if (typeof num.length == "undefined") {
875
+ throw num.length + "/" + shift;
876
+ }
877
+ const _num = (function() {
878
+ let offset = 0;
879
+ while (offset < num.length && num[offset] == 0) {
880
+ offset += 1;
881
+ }
882
+ const _num2 = new Array(num.length - offset + shift);
883
+ for (let i = 0; i < num.length - offset; i += 1) {
884
+ _num2[i] = num[i + offset];
885
+ }
886
+ return _num2;
887
+ })();
888
+ const _this = {};
889
+ _this.getAt = function(index) {
890
+ return _num[index];
891
+ };
892
+ _this.getLength = function() {
893
+ return _num.length;
894
+ };
895
+ _this.multiply = function(e) {
896
+ const num2 = new Array(_this.getLength() + e.getLength() - 1);
897
+ for (let i = 0; i < _this.getLength(); i += 1) {
898
+ for (let j = 0; j < e.getLength(); j += 1) {
899
+ num2[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i)) + QRMath.glog(e.getAt(j)));
900
+ }
901
+ }
902
+ return qrPolynomial(num2, 0);
903
+ };
904
+ _this.mod = function(e) {
905
+ if (_this.getLength() - e.getLength() < 0) {
906
+ return _this;
907
+ }
908
+ const ratio = QRMath.glog(_this.getAt(0)) - QRMath.glog(e.getAt(0));
909
+ const num2 = new Array(_this.getLength());
910
+ for (let i = 0; i < _this.getLength(); i += 1) {
911
+ num2[i] = _this.getAt(i);
912
+ }
913
+ for (let i = 0; i < e.getLength(); i += 1) {
914
+ num2[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i)) + ratio);
915
+ }
916
+ return qrPolynomial(num2, 0).mod(e);
917
+ };
918
+ return _this;
919
+ };
920
+ var QRRSBlock = (function() {
921
+ const RS_BLOCK_TABLE = [
922
+ // L
923
+ // M
924
+ // Q
925
+ // H
926
+ // 1
927
+ [1, 26, 19],
928
+ [1, 26, 16],
929
+ [1, 26, 13],
930
+ [1, 26, 9],
931
+ // 2
932
+ [1, 44, 34],
933
+ [1, 44, 28],
934
+ [1, 44, 22],
935
+ [1, 44, 16],
936
+ // 3
937
+ [1, 70, 55],
938
+ [1, 70, 44],
939
+ [2, 35, 17],
940
+ [2, 35, 13],
941
+ // 4
942
+ [1, 100, 80],
943
+ [2, 50, 32],
944
+ [2, 50, 24],
945
+ [4, 25, 9],
946
+ // 5
947
+ [1, 134, 108],
948
+ [2, 67, 43],
949
+ [2, 33, 15, 2, 34, 16],
950
+ [2, 33, 11, 2, 34, 12],
951
+ // 6
952
+ [2, 86, 68],
953
+ [4, 43, 27],
954
+ [4, 43, 19],
955
+ [4, 43, 15],
956
+ // 7
957
+ [2, 98, 78],
958
+ [4, 49, 31],
959
+ [2, 32, 14, 4, 33, 15],
960
+ [4, 39, 13, 1, 40, 14],
961
+ // 8
962
+ [2, 121, 97],
963
+ [2, 60, 38, 2, 61, 39],
964
+ [4, 40, 18, 2, 41, 19],
965
+ [4, 40, 14, 2, 41, 15],
966
+ // 9
967
+ [2, 146, 116],
968
+ [3, 58, 36, 2, 59, 37],
969
+ [4, 36, 16, 4, 37, 17],
970
+ [4, 36, 12, 4, 37, 13],
971
+ // 10
972
+ [2, 86, 68, 2, 87, 69],
973
+ [4, 69, 43, 1, 70, 44],
974
+ [6, 43, 19, 2, 44, 20],
975
+ [6, 43, 15, 2, 44, 16],
976
+ // 11
977
+ [4, 101, 81],
978
+ [1, 80, 50, 4, 81, 51],
979
+ [4, 50, 22, 4, 51, 23],
980
+ [3, 36, 12, 8, 37, 13],
981
+ // 12
982
+ [2, 116, 92, 2, 117, 93],
983
+ [6, 58, 36, 2, 59, 37],
984
+ [4, 46, 20, 6, 47, 21],
985
+ [7, 42, 14, 4, 43, 15],
986
+ // 13
987
+ [4, 133, 107],
988
+ [8, 59, 37, 1, 60, 38],
989
+ [8, 44, 20, 4, 45, 21],
990
+ [12, 33, 11, 4, 34, 12],
991
+ // 14
992
+ [3, 145, 115, 1, 146, 116],
993
+ [4, 64, 40, 5, 65, 41],
994
+ [11, 36, 16, 5, 37, 17],
995
+ [11, 36, 12, 5, 37, 13],
996
+ // 15
997
+ [5, 109, 87, 1, 110, 88],
998
+ [5, 65, 41, 5, 66, 42],
999
+ [5, 54, 24, 7, 55, 25],
1000
+ [11, 36, 12, 7, 37, 13],
1001
+ // 16
1002
+ [5, 122, 98, 1, 123, 99],
1003
+ [7, 73, 45, 3, 74, 46],
1004
+ [15, 43, 19, 2, 44, 20],
1005
+ [3, 45, 15, 13, 46, 16],
1006
+ // 17
1007
+ [1, 135, 107, 5, 136, 108],
1008
+ [10, 74, 46, 1, 75, 47],
1009
+ [1, 50, 22, 15, 51, 23],
1010
+ [2, 42, 14, 17, 43, 15],
1011
+ // 18
1012
+ [5, 150, 120, 1, 151, 121],
1013
+ [9, 69, 43, 4, 70, 44],
1014
+ [17, 50, 22, 1, 51, 23],
1015
+ [2, 42, 14, 19, 43, 15],
1016
+ // 19
1017
+ [3, 141, 113, 4, 142, 114],
1018
+ [3, 70, 44, 11, 71, 45],
1019
+ [17, 47, 21, 4, 48, 22],
1020
+ [9, 39, 13, 16, 40, 14],
1021
+ // 20
1022
+ [3, 135, 107, 5, 136, 108],
1023
+ [3, 67, 41, 13, 68, 42],
1024
+ [15, 54, 24, 5, 55, 25],
1025
+ [15, 43, 15, 10, 44, 16],
1026
+ // 21
1027
+ [4, 144, 116, 4, 145, 117],
1028
+ [17, 68, 42],
1029
+ [17, 50, 22, 6, 51, 23],
1030
+ [19, 46, 16, 6, 47, 17],
1031
+ // 22
1032
+ [2, 139, 111, 7, 140, 112],
1033
+ [17, 74, 46],
1034
+ [7, 54, 24, 16, 55, 25],
1035
+ [34, 37, 13],
1036
+ // 23
1037
+ [4, 151, 121, 5, 152, 122],
1038
+ [4, 75, 47, 14, 76, 48],
1039
+ [11, 54, 24, 14, 55, 25],
1040
+ [16, 45, 15, 14, 46, 16],
1041
+ // 24
1042
+ [6, 147, 117, 4, 148, 118],
1043
+ [6, 73, 45, 14, 74, 46],
1044
+ [11, 54, 24, 16, 55, 25],
1045
+ [30, 46, 16, 2, 47, 17],
1046
+ // 25
1047
+ [8, 132, 106, 4, 133, 107],
1048
+ [8, 75, 47, 13, 76, 48],
1049
+ [7, 54, 24, 22, 55, 25],
1050
+ [22, 45, 15, 13, 46, 16],
1051
+ // 26
1052
+ [10, 142, 114, 2, 143, 115],
1053
+ [19, 74, 46, 4, 75, 47],
1054
+ [28, 50, 22, 6, 51, 23],
1055
+ [33, 46, 16, 4, 47, 17],
1056
+ // 27
1057
+ [8, 152, 122, 4, 153, 123],
1058
+ [22, 73, 45, 3, 74, 46],
1059
+ [8, 53, 23, 26, 54, 24],
1060
+ [12, 45, 15, 28, 46, 16],
1061
+ // 28
1062
+ [3, 147, 117, 10, 148, 118],
1063
+ [3, 73, 45, 23, 74, 46],
1064
+ [4, 54, 24, 31, 55, 25],
1065
+ [11, 45, 15, 31, 46, 16],
1066
+ // 29
1067
+ [7, 146, 116, 7, 147, 117],
1068
+ [21, 73, 45, 7, 74, 46],
1069
+ [1, 53, 23, 37, 54, 24],
1070
+ [19, 45, 15, 26, 46, 16],
1071
+ // 30
1072
+ [5, 145, 115, 10, 146, 116],
1073
+ [19, 75, 47, 10, 76, 48],
1074
+ [15, 54, 24, 25, 55, 25],
1075
+ [23, 45, 15, 25, 46, 16],
1076
+ // 31
1077
+ [13, 145, 115, 3, 146, 116],
1078
+ [2, 74, 46, 29, 75, 47],
1079
+ [42, 54, 24, 1, 55, 25],
1080
+ [23, 45, 15, 28, 46, 16],
1081
+ // 32
1082
+ [17, 145, 115],
1083
+ [10, 74, 46, 23, 75, 47],
1084
+ [10, 54, 24, 35, 55, 25],
1085
+ [19, 45, 15, 35, 46, 16],
1086
+ // 33
1087
+ [17, 145, 115, 1, 146, 116],
1088
+ [14, 74, 46, 21, 75, 47],
1089
+ [29, 54, 24, 19, 55, 25],
1090
+ [11, 45, 15, 46, 46, 16],
1091
+ // 34
1092
+ [13, 145, 115, 6, 146, 116],
1093
+ [14, 74, 46, 23, 75, 47],
1094
+ [44, 54, 24, 7, 55, 25],
1095
+ [59, 46, 16, 1, 47, 17],
1096
+ // 35
1097
+ [12, 151, 121, 7, 152, 122],
1098
+ [12, 75, 47, 26, 76, 48],
1099
+ [39, 54, 24, 14, 55, 25],
1100
+ [22, 45, 15, 41, 46, 16],
1101
+ // 36
1102
+ [6, 151, 121, 14, 152, 122],
1103
+ [6, 75, 47, 34, 76, 48],
1104
+ [46, 54, 24, 10, 55, 25],
1105
+ [2, 45, 15, 64, 46, 16],
1106
+ // 37
1107
+ [17, 152, 122, 4, 153, 123],
1108
+ [29, 74, 46, 14, 75, 47],
1109
+ [49, 54, 24, 10, 55, 25],
1110
+ [24, 45, 15, 46, 46, 16],
1111
+ // 38
1112
+ [4, 152, 122, 18, 153, 123],
1113
+ [13, 74, 46, 32, 75, 47],
1114
+ [48, 54, 24, 14, 55, 25],
1115
+ [42, 45, 15, 32, 46, 16],
1116
+ // 39
1117
+ [20, 147, 117, 4, 148, 118],
1118
+ [40, 75, 47, 7, 76, 48],
1119
+ [43, 54, 24, 22, 55, 25],
1120
+ [10, 45, 15, 67, 46, 16],
1121
+ // 40
1122
+ [19, 148, 118, 6, 149, 119],
1123
+ [18, 75, 47, 31, 76, 48],
1124
+ [34, 54, 24, 34, 55, 25],
1125
+ [20, 45, 15, 61, 46, 16]
1126
+ ];
1127
+ const qrRSBlock = function(totalCount, dataCount) {
1128
+ const _this2 = {};
1129
+ _this2.totalCount = totalCount;
1130
+ _this2.dataCount = dataCount;
1131
+ return _this2;
1132
+ };
1133
+ const _this = {};
1134
+ const getRsBlockTable = function(typeNumber, errorCorrectionLevel) {
1135
+ switch (errorCorrectionLevel) {
1136
+ case QRErrorCorrectionLevel.L:
1137
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
1138
+ case QRErrorCorrectionLevel.M:
1139
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
1140
+ case QRErrorCorrectionLevel.Q:
1141
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
1142
+ case QRErrorCorrectionLevel.H:
1143
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
1144
+ default:
1145
+ return void 0;
1146
+ }
1147
+ };
1148
+ _this.getRSBlocks = function(typeNumber, errorCorrectionLevel) {
1149
+ const rsBlock = getRsBlockTable(typeNumber, errorCorrectionLevel);
1150
+ if (typeof rsBlock == "undefined") {
1151
+ throw "bad rs block @ typeNumber:" + typeNumber + "/errorCorrectionLevel:" + errorCorrectionLevel;
1152
+ }
1153
+ const length = rsBlock.length / 3;
1154
+ const list = [];
1155
+ for (let i = 0; i < length; i += 1) {
1156
+ const count = rsBlock[i * 3 + 0];
1157
+ const totalCount = rsBlock[i * 3 + 1];
1158
+ const dataCount = rsBlock[i * 3 + 2];
1159
+ for (let j = 0; j < count; j += 1) {
1160
+ list.push(qrRSBlock(totalCount, dataCount));
1161
+ }
1162
+ }
1163
+ return list;
1164
+ };
1165
+ return _this;
1166
+ })();
1167
+ var qrBitBuffer = function() {
1168
+ const _buffer = [];
1169
+ let _length = 0;
1170
+ const _this = {};
1171
+ _this.getBuffer = function() {
1172
+ return _buffer;
1173
+ };
1174
+ _this.getAt = function(index) {
1175
+ const bufIndex = Math.floor(index / 8);
1176
+ return (_buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
1177
+ };
1178
+ _this.put = function(num, length) {
1179
+ for (let i = 0; i < length; i += 1) {
1180
+ _this.putBit((num >>> length - i - 1 & 1) == 1);
1181
+ }
1182
+ };
1183
+ _this.getLengthInBits = function() {
1184
+ return _length;
1185
+ };
1186
+ _this.putBit = function(bit) {
1187
+ const bufIndex = Math.floor(_length / 8);
1188
+ if (_buffer.length <= bufIndex) {
1189
+ _buffer.push(0);
1190
+ }
1191
+ if (bit) {
1192
+ _buffer[bufIndex] |= 128 >>> _length % 8;
1193
+ }
1194
+ _length += 1;
1195
+ };
1196
+ return _this;
1197
+ };
1198
+ var qrNumber = function(data) {
1199
+ const _mode = QRMode.MODE_NUMBER;
1200
+ const _data = data;
1201
+ const _this = {};
1202
+ _this.getMode = function() {
1203
+ return _mode;
1204
+ };
1205
+ _this.getLength = function(buffer) {
1206
+ return _data.length;
1207
+ };
1208
+ _this.write = function(buffer) {
1209
+ const data2 = _data;
1210
+ let i = 0;
1211
+ while (i + 2 < data2.length) {
1212
+ buffer.put(strToNum(data2.substring(i, i + 3)), 10);
1213
+ i += 3;
1214
+ }
1215
+ if (i < data2.length) {
1216
+ if (data2.length - i == 1) {
1217
+ buffer.put(strToNum(data2.substring(i, i + 1)), 4);
1218
+ } else if (data2.length - i == 2) {
1219
+ buffer.put(strToNum(data2.substring(i, i + 2)), 7);
1220
+ }
1221
+ }
1222
+ };
1223
+ const strToNum = function(s) {
1224
+ let num = 0;
1225
+ for (let i = 0; i < s.length; i += 1) {
1226
+ num = num * 10 + chatToNum(s.charAt(i));
1227
+ }
1228
+ return num;
1229
+ };
1230
+ const chatToNum = function(c) {
1231
+ if ("0" <= c && c <= "9") {
1232
+ return c.charCodeAt(0) - "0".charCodeAt(0);
1233
+ }
1234
+ throw "illegal char :" + c;
1235
+ };
1236
+ return _this;
1237
+ };
1238
+ var qrAlphaNum = function(data) {
1239
+ const _mode = QRMode.MODE_ALPHA_NUM;
1240
+ const _data = data;
1241
+ const _this = {};
1242
+ _this.getMode = function() {
1243
+ return _mode;
1244
+ };
1245
+ _this.getLength = function(buffer) {
1246
+ return _data.length;
1247
+ };
1248
+ _this.write = function(buffer) {
1249
+ const s = _data;
1250
+ let i = 0;
1251
+ while (i + 1 < s.length) {
1252
+ buffer.put(
1253
+ getCode(s.charAt(i)) * 45 + getCode(s.charAt(i + 1)),
1254
+ 11
1255
+ );
1256
+ i += 2;
1257
+ }
1258
+ if (i < s.length) {
1259
+ buffer.put(getCode(s.charAt(i)), 6);
1260
+ }
1261
+ };
1262
+ const getCode = function(c) {
1263
+ if ("0" <= c && c <= "9") {
1264
+ return c.charCodeAt(0) - "0".charCodeAt(0);
1265
+ } else if ("A" <= c && c <= "Z") {
1266
+ return c.charCodeAt(0) - "A".charCodeAt(0) + 10;
1267
+ } else {
1268
+ switch (c) {
1269
+ case " ":
1270
+ return 36;
1271
+ case "$":
1272
+ return 37;
1273
+ case "%":
1274
+ return 38;
1275
+ case "*":
1276
+ return 39;
1277
+ case "+":
1278
+ return 40;
1279
+ case "-":
1280
+ return 41;
1281
+ case ".":
1282
+ return 42;
1283
+ case "/":
1284
+ return 43;
1285
+ case ":":
1286
+ return 44;
1287
+ default:
1288
+ throw "illegal char :" + c;
1289
+ }
1290
+ }
1291
+ };
1292
+ return _this;
1293
+ };
1294
+ var qr8BitByte = function(data) {
1295
+ const _mode = QRMode.MODE_8BIT_BYTE;
1296
+ const _data = data;
1297
+ const _bytes = qrcode.stringToBytes(data);
1298
+ const _this = {};
1299
+ _this.getMode = function() {
1300
+ return _mode;
1301
+ };
1302
+ _this.getLength = function(buffer) {
1303
+ return _bytes.length;
1304
+ };
1305
+ _this.write = function(buffer) {
1306
+ for (let i = 0; i < _bytes.length; i += 1) {
1307
+ buffer.put(_bytes[i], 8);
1308
+ }
1309
+ };
1310
+ return _this;
1311
+ };
1312
+ var qrKanji = function(data) {
1313
+ const _mode = QRMode.MODE_KANJI;
1314
+ const _data = data;
1315
+ const stringToBytes2 = qrcode.stringToBytes;
1316
+ !(function(c, code) {
1317
+ const test = stringToBytes2(c);
1318
+ if (test.length != 2 || (test[0] << 8 | test[1]) != code) {
1319
+ throw "sjis not supported.";
1320
+ }
1321
+ })("\u53CB", 38726);
1322
+ const _bytes = stringToBytes2(data);
1323
+ const _this = {};
1324
+ _this.getMode = function() {
1325
+ return _mode;
1326
+ };
1327
+ _this.getLength = function(buffer) {
1328
+ return ~~(_bytes.length / 2);
1329
+ };
1330
+ _this.write = function(buffer) {
1331
+ const data2 = _bytes;
1332
+ let i = 0;
1333
+ while (i + 1 < data2.length) {
1334
+ let c = (255 & data2[i]) << 8 | 255 & data2[i + 1];
1335
+ if (33088 <= c && c <= 40956) {
1336
+ c -= 33088;
1337
+ } else if (57408 <= c && c <= 60351) {
1338
+ c -= 49472;
1339
+ } else {
1340
+ throw "illegal char at " + (i + 1) + "/" + c;
1341
+ }
1342
+ c = (c >>> 8 & 255) * 192 + (c & 255);
1343
+ buffer.put(c, 13);
1344
+ i += 2;
1345
+ }
1346
+ if (i < data2.length) {
1347
+ throw "illegal char at " + (i + 1);
1348
+ }
1349
+ };
1350
+ return _this;
1351
+ };
1352
+ var byteArrayOutputStream = function() {
1353
+ const _bytes = [];
1354
+ const _this = {};
1355
+ _this.writeByte = function(b) {
1356
+ _bytes.push(b & 255);
1357
+ };
1358
+ _this.writeShort = function(i) {
1359
+ _this.writeByte(i);
1360
+ _this.writeByte(i >>> 8);
1361
+ };
1362
+ _this.writeBytes = function(b, off, len) {
1363
+ off = off || 0;
1364
+ len = len || b.length;
1365
+ for (let i = 0; i < len; i += 1) {
1366
+ _this.writeByte(b[i + off]);
1367
+ }
1368
+ };
1369
+ _this.writeString = function(s) {
1370
+ for (let i = 0; i < s.length; i += 1) {
1371
+ _this.writeByte(s.charCodeAt(i));
1372
+ }
1373
+ };
1374
+ _this.toByteArray = function() {
1375
+ return _bytes;
1376
+ };
1377
+ _this.toString = function() {
1378
+ let s = "";
1379
+ s += "[";
1380
+ for (let i = 0; i < _bytes.length; i += 1) {
1381
+ if (i > 0) {
1382
+ s += ",";
1383
+ }
1384
+ s += _bytes[i];
1385
+ }
1386
+ s += "]";
1387
+ return s;
1388
+ };
1389
+ return _this;
1390
+ };
1391
+ var base64EncodeOutputStream = function() {
1392
+ let _buffer = 0;
1393
+ let _buflen = 0;
1394
+ let _length = 0;
1395
+ let _base64 = "";
1396
+ const _this = {};
1397
+ const writeEncoded = function(b) {
1398
+ _base64 += String.fromCharCode(encode(b & 63));
1399
+ };
1400
+ const encode = function(n) {
1401
+ if (n < 0) {
1402
+ throw "n:" + n;
1403
+ } else if (n < 26) {
1404
+ return 65 + n;
1405
+ } else if (n < 52) {
1406
+ return 97 + (n - 26);
1407
+ } else if (n < 62) {
1408
+ return 48 + (n - 52);
1409
+ } else if (n == 62) {
1410
+ return 43;
1411
+ } else if (n == 63) {
1412
+ return 47;
1413
+ } else {
1414
+ throw "n:" + n;
1415
+ }
1416
+ };
1417
+ _this.writeByte = function(n) {
1418
+ _buffer = _buffer << 8 | n & 255;
1419
+ _buflen += 8;
1420
+ _length += 1;
1421
+ while (_buflen >= 6) {
1422
+ writeEncoded(_buffer >>> _buflen - 6);
1423
+ _buflen -= 6;
1424
+ }
1425
+ };
1426
+ _this.flush = function() {
1427
+ if (_buflen > 0) {
1428
+ writeEncoded(_buffer << 6 - _buflen);
1429
+ _buffer = 0;
1430
+ _buflen = 0;
1431
+ }
1432
+ if (_length % 3 != 0) {
1433
+ const padlen = 3 - _length % 3;
1434
+ for (let i = 0; i < padlen; i += 1) {
1435
+ _base64 += "=";
1436
+ }
1437
+ }
1438
+ };
1439
+ _this.toString = function() {
1440
+ return _base64;
1441
+ };
1442
+ return _this;
1443
+ };
1444
+ var base64DecodeInputStream = function(str) {
1445
+ const _str = str;
1446
+ let _pos = 0;
1447
+ let _buffer = 0;
1448
+ let _buflen = 0;
1449
+ const _this = {};
1450
+ _this.read = function() {
1451
+ while (_buflen < 8) {
1452
+ if (_pos >= _str.length) {
1453
+ if (_buflen == 0) {
1454
+ return -1;
1455
+ }
1456
+ throw "unexpected end of file./" + _buflen;
1457
+ }
1458
+ const c = _str.charAt(_pos);
1459
+ _pos += 1;
1460
+ if (c == "=") {
1461
+ _buflen = 0;
1462
+ return -1;
1463
+ } else if (c.match(/^\s$/)) {
1464
+ continue;
1465
+ }
1466
+ _buffer = _buffer << 6 | decode(c.charCodeAt(0));
1467
+ _buflen += 6;
1468
+ }
1469
+ const n = _buffer >>> _buflen - 8 & 255;
1470
+ _buflen -= 8;
1471
+ return n;
1472
+ };
1473
+ const decode = function(c) {
1474
+ if (65 <= c && c <= 90) {
1475
+ return c - 65;
1476
+ } else if (97 <= c && c <= 122) {
1477
+ return c - 97 + 26;
1478
+ } else if (48 <= c && c <= 57) {
1479
+ return c - 48 + 52;
1480
+ } else if (c == 43) {
1481
+ return 62;
1482
+ } else if (c == 47) {
1483
+ return 63;
1484
+ } else {
1485
+ throw "c:" + c;
1486
+ }
1487
+ };
1488
+ return _this;
1489
+ };
1490
+ var gifImage = function(width, height) {
1491
+ const _width = width;
1492
+ const _height = height;
1493
+ const _data = new Array(width * height);
1494
+ const _this = {};
1495
+ _this.setPixel = function(x, y, pixel) {
1496
+ _data[y * _width + x] = pixel;
1497
+ };
1498
+ _this.write = function(out) {
1499
+ out.writeString("GIF87a");
1500
+ out.writeShort(_width);
1501
+ out.writeShort(_height);
1502
+ out.writeByte(128);
1503
+ out.writeByte(0);
1504
+ out.writeByte(0);
1505
+ out.writeByte(0);
1506
+ out.writeByte(0);
1507
+ out.writeByte(0);
1508
+ out.writeByte(255);
1509
+ out.writeByte(255);
1510
+ out.writeByte(255);
1511
+ out.writeString(",");
1512
+ out.writeShort(0);
1513
+ out.writeShort(0);
1514
+ out.writeShort(_width);
1515
+ out.writeShort(_height);
1516
+ out.writeByte(0);
1517
+ const lzwMinCodeSize = 2;
1518
+ const raster = getLZWRaster(lzwMinCodeSize);
1519
+ out.writeByte(lzwMinCodeSize);
1520
+ let offset = 0;
1521
+ while (raster.length - offset > 255) {
1522
+ out.writeByte(255);
1523
+ out.writeBytes(raster, offset, 255);
1524
+ offset += 255;
1525
+ }
1526
+ out.writeByte(raster.length - offset);
1527
+ out.writeBytes(raster, offset, raster.length - offset);
1528
+ out.writeByte(0);
1529
+ out.writeString(";");
1530
+ };
1531
+ const bitOutputStream = function(out) {
1532
+ const _out = out;
1533
+ let _bitLength = 0;
1534
+ let _bitBuffer = 0;
1535
+ const _this2 = {};
1536
+ _this2.write = function(data, length) {
1537
+ if (data >>> length != 0) {
1538
+ throw "length over";
1539
+ }
1540
+ while (_bitLength + length >= 8) {
1541
+ _out.writeByte(255 & (data << _bitLength | _bitBuffer));
1542
+ length -= 8 - _bitLength;
1543
+ data >>>= 8 - _bitLength;
1544
+ _bitBuffer = 0;
1545
+ _bitLength = 0;
1546
+ }
1547
+ _bitBuffer = data << _bitLength | _bitBuffer;
1548
+ _bitLength = _bitLength + length;
1549
+ };
1550
+ _this2.flush = function() {
1551
+ if (_bitLength > 0) {
1552
+ _out.writeByte(_bitBuffer);
1553
+ }
1554
+ };
1555
+ return _this2;
1556
+ };
1557
+ const getLZWRaster = function(lzwMinCodeSize) {
1558
+ const clearCode = 1 << lzwMinCodeSize;
1559
+ const endCode = (1 << lzwMinCodeSize) + 1;
1560
+ let bitLength = lzwMinCodeSize + 1;
1561
+ const table = lzwTable();
1562
+ for (let i = 0; i < clearCode; i += 1) {
1563
+ table.add(String.fromCharCode(i));
1564
+ }
1565
+ table.add(String.fromCharCode(clearCode));
1566
+ table.add(String.fromCharCode(endCode));
1567
+ const byteOut = byteArrayOutputStream();
1568
+ const bitOut = bitOutputStream(byteOut);
1569
+ bitOut.write(clearCode, bitLength);
1570
+ let dataIndex = 0;
1571
+ let s = String.fromCharCode(_data[dataIndex]);
1572
+ dataIndex += 1;
1573
+ while (dataIndex < _data.length) {
1574
+ const c = String.fromCharCode(_data[dataIndex]);
1575
+ dataIndex += 1;
1576
+ if (table.contains(s + c)) {
1577
+ s = s + c;
1578
+ } else {
1579
+ bitOut.write(table.indexOf(s), bitLength);
1580
+ if (table.size() < 4095) {
1581
+ if (table.size() == 1 << bitLength) {
1582
+ bitLength += 1;
1583
+ }
1584
+ table.add(s + c);
1585
+ }
1586
+ s = c;
1587
+ }
1588
+ }
1589
+ bitOut.write(table.indexOf(s), bitLength);
1590
+ bitOut.write(endCode, bitLength);
1591
+ bitOut.flush();
1592
+ return byteOut.toByteArray();
1593
+ };
1594
+ const lzwTable = function() {
1595
+ const _map = {};
1596
+ let _size = 0;
1597
+ const _this2 = {};
1598
+ _this2.add = function(key) {
1599
+ if (_this2.contains(key)) {
1600
+ throw "dup key:" + key;
1601
+ }
1602
+ _map[key] = _size;
1603
+ _size += 1;
1604
+ };
1605
+ _this2.size = function() {
1606
+ return _size;
1607
+ };
1608
+ _this2.indexOf = function(key) {
1609
+ return _map[key];
1610
+ };
1611
+ _this2.contains = function(key) {
1612
+ return typeof _map[key] != "undefined";
1613
+ };
1614
+ return _this2;
1615
+ };
1616
+ return _this;
1617
+ };
1618
+ var createDataURL = function(width, height, getPixel) {
1619
+ const gif = gifImage(width, height);
1620
+ for (let y = 0; y < height; y += 1) {
1621
+ for (let x = 0; x < width; x += 1) {
1622
+ gif.setPixel(x, y, getPixel(x, y));
1623
+ }
1624
+ }
1625
+ const b = byteArrayOutputStream();
1626
+ gif.write(b);
1627
+ const base64 = base64EncodeOutputStream();
1628
+ const bytes = b.toByteArray();
1629
+ for (let i = 0; i < bytes.length; i += 1) {
1630
+ base64.writeByte(bytes[i]);
1631
+ }
1632
+ base64.flush();
1633
+ return "data:image/gif;base64," + base64;
1634
+ };
1635
+ var qrcode_default = qrcode;
1636
+ var stringToBytes = qrcode.stringToBytes;
1637
+
1638
+ // src/core.ts
1639
+ var token = /^[A-Za-z0-9_-]{43}$/;
1640
+ var AuthLinkError = class extends Error {
1641
+ constructor(code) {
1642
+ super(code);
1643
+ this.code = code;
1644
+ this.name = "AuthLinkError";
1645
+ }
1646
+ code;
1647
+ };
1648
+ function fail(code) {
1649
+ throw new AuthLinkError(code);
1650
+ }
1651
+ function object(value) {
1652
+ if (!value || typeof value !== "object" || Array.isArray(value)) fail("INVALID_RESPONSE");
1653
+ return value;
1654
+ }
1655
+ function validateDisplayCode(value) {
1656
+ const m = object(value);
1657
+ const span = Date.parse(String(m.validUntil)) - Date.parse(String(m.serverTime));
1658
+ if (typeof m.value !== "string" || !/^\d{6}$/.test(m.value) || m.periodSeconds !== 30 || !Number.isFinite(span) || span <= 0 || span > 3e4 || "seed" in m || "secret" in m || "key" in m) fail("INVALID_DISPLAY_CODE");
1659
+ return { value: m.value, serverTime: String(m.serverTime), validUntil: String(m.validUntil), periodSeconds: 30 };
1660
+ }
1661
+ function validateTicket(value, expectedMode, trustedOrigin) {
1662
+ const m = object(value);
1663
+ if ("pairing" in m || "seed" in m || "apiKey" in m) fail("SERVER_SECRET_FORBIDDEN");
1664
+ if (typeof m.requestId !== "string" || !token.test(m.requestId) || !["bind", "confirm"].includes(String(m.purpose)) || expectedMode && m.purpose !== expectedMode || typeof m.qr !== "string" || m.qr.length > 4096 || typeof m.pairingCode !== "string" || !/^\d{6}$/.test(m.pairingCode)) fail("INVALID_TICKET");
1665
+ let qr;
1666
+ try {
1667
+ qr = object(JSON.parse(m.qr));
1668
+ } catch {
1669
+ return fail("INVALID_QR");
1670
+ }
1671
+ let origin;
1672
+ try {
1673
+ origin = new URL(String(qr.origin));
1674
+ } catch {
1675
+ return fail("INVALID_QR");
1676
+ }
1677
+ if (qr.v !== 1 || qr.requestId !== m.requestId || typeof qr.token !== "string" || !token.test(qr.token) || origin.protocol !== "https:" || origin.origin !== qr.origin || origin.origin.length > 512 || origin.username || origin.password || trustedOrigin && origin.origin !== trustedOrigin) fail("UNTRUSTED_QR");
1678
+ const displayCode = m.displayCode === void 0 ? void 0 : validateDisplayCode(m.displayCode);
1679
+ if (m.purpose === "confirm" && !displayCode) fail("DYNAMIC_CODE_REQUIRED");
1680
+ const expiry = Date.parse(String(m.expiresAt));
1681
+ const now = displayCode ? Date.parse(displayCode.serverTime) : Date.now();
1682
+ if (!Number.isFinite(expiry) || expiry > now + 18e4) fail("INVALID_EXPIRY");
1683
+ return {
1684
+ requestId: m.requestId,
1685
+ purpose: m.purpose,
1686
+ qr: m.qr,
1687
+ pairingCode: m.pairingCode,
1688
+ expiresAt: String(m.expiresAt),
1689
+ ...displayCode ? { displayCode } : {}
1690
+ };
1691
+ }
1692
+ function qrImage(ticket) {
1693
+ const value = validateTicket(ticket);
1694
+ const payload = JSON.parse(value.qr);
1695
+ const qr = qrcode_default(0, "M");
1696
+ qr.addData(JSON.stringify({ v: 1, origin: payload.origin, requestId: payload.requestId, token: payload.token }), "Byte");
1697
+ qr.make();
1698
+ return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(qr.createSvgTag({ cellSize: 4, margin: 16, scalable: true }))}`;
1699
+ }
1700
+ function initialSnapshot() {
1701
+ return { status: "idle", code: null, secondsRemaining: 0, codeSecondsRemaining: 0, error: null };
1702
+ }
1703
+ function abortable(promise, signal) {
1704
+ signal.throwIfAborted();
1705
+ let cancel;
1706
+ const abort = new Promise((_, reject) => {
1707
+ cancel = () => reject(signal.reason);
1708
+ signal.addEventListener("abort", cancel, { once: true });
1709
+ });
1710
+ return Promise.race([promise, abort]).finally(() => signal.removeEventListener("abort", cancel));
1711
+ }
1712
+ async function observeRequest(input, options) {
1713
+ const { client, signal, onUpdate } = options;
1714
+ const interval = options.intervalMs ?? 1500;
1715
+ let ticket;
1716
+ try {
1717
+ if (interval < 250 || interval > 1e4 || !Number.isFinite(interval)) fail("INVALID_INTERVAL");
1718
+ ticket = validateTicket(input, options.expectedMode);
1719
+ } catch (error) {
1720
+ if (!signal.aborted) {
1721
+ const e = error instanceof Error ? error : new AuthLinkError("INVALID_TICKET");
1722
+ onUpdate({ ...initialSnapshot(), status: "error", error: e });
1723
+ options.onError?.(e);
1724
+ }
1725
+ return;
1726
+ }
1727
+ let frame = ticket.displayCode;
1728
+ let serverAnchor = frame ? Date.parse(frame.serverTime) : Date.now();
1729
+ let monotonicAnchor = performance.now();
1730
+ const serverNow = () => serverAnchor + performance.now() - monotonicAnchor;
1731
+ const expiry = Date.parse(ticket.expiresAt);
1732
+ let ended = false;
1733
+ const controller = new AbortController();
1734
+ const cancel = () => controller.abort(signal.reason);
1735
+ signal.addEventListener("abort", cancel, { once: true });
1736
+ if (signal.aborted) cancel();
1737
+ let last = initialSnapshot();
1738
+ const update = (value) => {
1739
+ if (signal.aborted) return;
1740
+ if (JSON.stringify(value) !== JSON.stringify(last)) {
1741
+ last = value;
1742
+ onUpdate(value);
1743
+ }
1744
+ };
1745
+ const tick = () => {
1746
+ if (ended || signal.aborted) return;
1747
+ const now = serverNow();
1748
+ if (now >= expiry) {
1749
+ controller.abort(new AuthLinkError("REQUEST_EXPIRED"));
1750
+ return;
1751
+ }
1752
+ const codeRemaining = Math.max(0, ((frame ? Date.parse(frame.validUntil) : expiry) - now) / 1e3);
1753
+ options.onCodeTiming?.(codeRemaining * 1e3);
1754
+ update({
1755
+ status: "pending",
1756
+ code: codeRemaining > 0 ? frame?.value ?? ticket.pairingCode : null,
1757
+ secondsRemaining: Math.max(0, Math.ceil((expiry - now) / 1e3)),
1758
+ codeSecondsRemaining: Math.ceil(codeRemaining),
1759
+ error: null
1760
+ });
1761
+ };
1762
+ const timer = setInterval(tick, 200);
1763
+ const finish = (status, result, error) => {
1764
+ if (ended || signal.aborted) return;
1765
+ ended = true;
1766
+ update({ ...last, status, code: null, error: error ?? null });
1767
+ try {
1768
+ let effect = void 0;
1769
+ if (status === "confirmed") effect = options.onConfirmed?.(result);
1770
+ else if (status === "rejected") effect = options.onRejected?.({ status: "rejected", code: "REJECTED", requestId: ticket.requestId, purpose: ticket.purpose });
1771
+ else if (status === "expired") effect = options.onExpired?.();
1772
+ else options.onError?.(error);
1773
+ void Promise.resolve(effect).catch(() => {
1774
+ if (!signal.aborted) options.onError?.(new AuthLinkError("CALLBACK_FAILED"));
1775
+ });
1776
+ } catch {
1777
+ if (status !== "error") options.onError?.(new AuthLinkError("CALLBACK_FAILED"));
1778
+ }
1779
+ };
1780
+ try {
1781
+ tick();
1782
+ for (; ; ) {
1783
+ controller.signal.throwIfAborted();
1784
+ const value = object(await abortable(client.result(ticket, controller.signal), controller.signal));
1785
+ controller.signal.throwIfAborted();
1786
+ if (value.requestId !== ticket.requestId) fail("REQUEST_MISMATCH");
1787
+ if (value.status === "confirmed") {
1788
+ if (!token.test(String(value.verificationId)) || !["device-presence.v1"].includes(String(value.authenticationPolicy)) || value.expiresAt !== ticket.expiresAt || value.purpose !== ticket.purpose || serverNow() >= expiry || "action" in value || "transactionHash" in value) fail("INVALID_CONFIRMATION");
1789
+ finish("confirmed", value);
1790
+ return;
1791
+ }
1792
+ if (value.status === "rejected" || value.status === "expired") {
1793
+ finish(value.status);
1794
+ return;
1795
+ }
1796
+ if (!["new", "pending", "approved", "consumed"].includes(String(value.status))) fail("INVALID_RESPONSE");
1797
+ if (value.displayCode !== void 0) {
1798
+ const nextFrame = validateDisplayCode(value.displayCode);
1799
+ const nextExpiry = Date.parse(nextFrame.validUntil);
1800
+ const currentExpiry = frame ? Date.parse(frame.validUntil) : 0;
1801
+ if (!frame || nextExpiry > currentExpiry) {
1802
+ serverAnchor = Math.max(serverNow(), Date.parse(nextFrame.serverTime));
1803
+ monotonicAnchor = performance.now();
1804
+ }
1805
+ if (!frame || nextExpiry >= currentExpiry) frame = nextFrame;
1806
+ }
1807
+ tick();
1808
+ let pause;
1809
+ try {
1810
+ await abortable(new Promise((resolve) => {
1811
+ pause = setTimeout(resolve, interval);
1812
+ }), controller.signal);
1813
+ } finally {
1814
+ clearTimeout(pause);
1815
+ }
1816
+ }
1817
+ } catch (error) {
1818
+ if (!signal.aborted && !ended) {
1819
+ if (error instanceof AuthLinkError && error.code === "REQUEST_EXPIRED") finish("expired");
1820
+ else finish("error", void 0, error instanceof AuthLinkError ? error : new AuthLinkError("NETWORK_ERROR"));
1821
+ }
1822
+ } finally {
1823
+ ended = true;
1824
+ clearInterval(timer);
1825
+ controller.abort();
1826
+ signal.removeEventListener("abort", cancel);
1827
+ }
1828
+ }
1829
+
1830
+ // src/locales/en.json
1831
+ var en_default = {
1832
+ bind: "Bind your phone",
1833
+ confirm: "Confirm verification",
1834
+ scan: "Scan with AuthLink",
1835
+ code: "Matching code",
1836
+ help: "Check that the numbers match in the app, then confirm on your phone.",
1837
+ waiting: "Waiting for your phone",
1838
+ loading: "Connecting",
1839
+ confirmed: "Confirmed",
1840
+ rejected: "Rejected",
1841
+ expired: "Request expired",
1842
+ error: "Verification is unavailable",
1843
+ retry: "Retry",
1844
+ refresh: "New request",
1845
+ updating: "Updating code",
1846
+ close: "Close",
1847
+ cancel: "Cancel",
1848
+ autoUpdate: "Code updates automatically every 30 seconds",
1849
+ expiring: "Request expiring soon"
1850
+ };
1851
+
1852
+ // src/locales/zh-CN.json
1853
+ var zh_CN_default = {
1854
+ bind: "\u7ED1\u5B9A\u624B\u673A",
1855
+ confirm: "\u786E\u8BA4\u8EAB\u4EFD\u9A8C\u8BC1",
1856
+ scan: "\u4F7F\u7528 AuthLink \u626B\u63CF\u4E8C\u7EF4\u7801",
1857
+ code: "\u52A8\u6001\u6838\u5BF9\u7801",
1858
+ help: "\u6838\u5BF9 App \u4E2D\u7684\u6570\u5B57\u4E00\u81F4\u540E\uFF0C\u5728\u624B\u673A\u4E0A\u786E\u8BA4\u3002",
1859
+ waiting: "\u7B49\u5F85\u624B\u673A\u786E\u8BA4",
1860
+ loading: "\u6B63\u5728\u8FDE\u63A5",
1861
+ confirmed: "\u5DF2\u786E\u8BA4",
1862
+ rejected: "\u5DF2\u62D2\u7EDD",
1863
+ expired: "\u8BF7\u6C42\u5DF2\u8FC7\u671F",
1864
+ error: "\u6682\u65F6\u65E0\u6CD5\u5B8C\u6210\u9A8C\u8BC1",
1865
+ retry: "\u91CD\u8BD5",
1866
+ refresh: "\u91CD\u65B0\u53D1\u8D77",
1867
+ updating: "\u6B63\u5728\u66F4\u65B0\u6570\u5B57",
1868
+ close: "\u5173\u95ED",
1869
+ cancel: "\u53D6\u6D88",
1870
+ autoUpdate: "\u6838\u5BF9\u7801\u6BCF 30 \u79D2\u81EA\u52A8\u66F4\u65B0",
1871
+ expiring: "\u8BF7\u6C42\u5373\u5C06\u8FC7\u671F"
1872
+ };
1873
+
1874
+ // src/locales/zh-TW.json
1875
+ var zh_TW_default = {
1876
+ bind: "\u7D81\u5B9A\u624B\u6A5F",
1877
+ confirm: "\u78BA\u8A8D\u8EAB\u5206\u9A57\u8B49",
1878
+ scan: "\u4F7F\u7528 AuthLink \u6383\u63CF QR \u78BC",
1879
+ code: "\u52D5\u614B\u6838\u5C0D\u78BC",
1880
+ help: "\u6838\u5C0D App \u4E2D\u7684\u6578\u5B57\u4E00\u81F4\u5F8C\uFF0C\u5728\u624B\u6A5F\u4E0A\u78BA\u8A8D\u3002",
1881
+ waiting: "\u7B49\u5F85\u624B\u6A5F\u78BA\u8A8D",
1882
+ loading: "\u6B63\u5728\u9023\u7DDA",
1883
+ confirmed: "\u5DF2\u78BA\u8A8D",
1884
+ rejected: "\u5DF2\u62D2\u7D55",
1885
+ expired: "\u8ACB\u6C42\u5DF2\u904E\u671F",
1886
+ error: "\u66AB\u6642\u7121\u6CD5\u5B8C\u6210\u9A57\u8B49",
1887
+ retry: "\u91CD\u8A66",
1888
+ refresh: "\u91CD\u65B0\u767C\u8D77",
1889
+ updating: "\u6B63\u5728\u66F4\u65B0\u6578\u5B57",
1890
+ close: "\u95DC\u9589",
1891
+ cancel: "\u53D6\u6D88",
1892
+ autoUpdate: "\u6838\u5C0D\u78BC\u6BCF 30 \u79D2\u81EA\u52D5\u66F4\u65B0",
1893
+ expiring: "\u8ACB\u6C42\u5373\u5C07\u5230\u671F"
1894
+ };
1895
+
1896
+ // src/locales/ja.json
1897
+ var ja_default = {
1898
+ bind: "\u30B9\u30DE\u30FC\u30C8\u30D5\u30A9\u30F3\u3092\u767B\u9332",
1899
+ confirm: "\u672C\u4EBA\u78BA\u8A8D",
1900
+ scan: "AuthLink \u3067 QR \u30B3\u30FC\u30C9\u3092\u30B9\u30AD\u30E3\u30F3",
1901
+ code: "\u7167\u5408\u30B3\u30FC\u30C9",
1902
+ help: "\u30A2\u30D7\u30EA\u306E\u6570\u5B57\u304C\u4E00\u81F4\u3059\u308B\u3053\u3068\u3092\u78BA\u8A8D\u3057\u3001\u30B9\u30DE\u30FC\u30C8\u30D5\u30A9\u30F3\u3067\u627F\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002",
1903
+ waiting: "\u30B9\u30DE\u30FC\u30C8\u30D5\u30A9\u30F3\u306E\u78BA\u8A8D\u3092\u5F85\u3063\u3066\u3044\u307E\u3059",
1904
+ loading: "\u63A5\u7D9A\u4E2D",
1905
+ confirmed: "\u78BA\u8A8D\u6E08\u307F",
1906
+ rejected: "\u62D2\u5426\u3055\u308C\u307E\u3057\u305F",
1907
+ expired: "\u6709\u52B9\u671F\u9650\u304C\u5207\u308C\u307E\u3057\u305F",
1908
+ error: "\u672C\u4EBA\u78BA\u8A8D\u3092\u5B8C\u4E86\u3067\u304D\u307E\u305B\u3093",
1909
+ retry: "\u518D\u8A66\u884C",
1910
+ refresh: "\u65B0\u3057\u3044\u30EA\u30AF\u30A8\u30B9\u30C8",
1911
+ updating: "\u30B3\u30FC\u30C9\u3092\u66F4\u65B0\u4E2D",
1912
+ close: "\u9589\u3058\u308B",
1913
+ cancel: "\u30AD\u30E3\u30F3\u30BB\u30EB",
1914
+ autoUpdate: "\u7167\u5408\u30B3\u30FC\u30C9\u306F30\u79D2\u3054\u3068\u306B\u81EA\u52D5\u66F4\u65B0",
1915
+ expiring: "\u30EA\u30AF\u30A8\u30B9\u30C8\u306E\u6709\u52B9\u671F\u9650\u304C\u307E\u3082\u306A\u304F\u5207\u308C\u307E\u3059"
1916
+ };
1917
+
1918
+ // src/locales/bn.json
1919
+ var bn_default = {
1920
+ bind: "\u0986\u09AA\u09A8\u09BE\u09B0 \u09AB\u09CB\u09A8 \u09AF\u09C1\u0995\u09CD\u09A4 \u0995\u09B0\u09C1\u09A8",
1921
+ confirm: "\u09AF\u09BE\u099A\u09BE\u0987\u0995\u09B0\u09A3 \u09A8\u09BF\u09B6\u09CD\u099A\u09BF\u09A4 \u0995\u09B0\u09C1\u09A8",
1922
+ scan: "AuthLink \u09A6\u09BF\u09AF\u09BC\u09C7 \u09B8\u09CD\u0995\u09CD\u09AF\u09BE\u09A8 \u0995\u09B0\u09C1\u09A8",
1923
+ code: "\u09AE\u09BF\u09B2\u09BF\u09AF\u09BC\u09C7 \u09A6\u09C7\u0996\u09BE\u09B0 \u0995\u09CB\u09A1",
1924
+ help: "\u0985\u09CD\u09AF\u09BE\u09AA\u09C7\u09B0 \u09B8\u0982\u0996\u09CD\u09AF\u09BE\u0997\u09C1\u09B2\u09CB \u09AE\u09BF\u09B2\u09C7 \u0997\u09C7\u09B2\u09C7 \u09AB\u09CB\u09A8\u09C7 \u09A8\u09BF\u09B6\u09CD\u099A\u09BF\u09A4 \u0995\u09B0\u09C1\u09A8\u0964",
1925
+ waiting: "\u09AB\u09CB\u09A8\u09C7 \u09A8\u09BF\u09B6\u09CD\u099A\u09BF\u09A4\u0995\u09B0\u09A3\u09C7\u09B0 \u0985\u09AA\u09C7\u0995\u09CD\u09B7\u09BE\u09AF\u09BC",
1926
+ loading: "\u09B8\u0982\u09AF\u09CB\u0997 \u0995\u09B0\u09BE \u09B9\u099A\u09CD\u099B\u09C7",
1927
+ confirmed: "\u09A8\u09BF\u09B6\u09CD\u099A\u09BF\u09A4 \u09B9\u09AF\u09BC\u09C7\u099B\u09C7",
1928
+ rejected: "\u09AA\u09CD\u09B0\u09A4\u09CD\u09AF\u09BE\u0996\u09CD\u09AF\u09BE\u09A4",
1929
+ expired: "\u0985\u09A8\u09C1\u09B0\u09CB\u09A7\u09C7\u09B0 \u09AE\u09C7\u09AF\u09BC\u09BE\u09A6 \u09B6\u09C7\u09B7",
1930
+ error: "\u09AF\u09BE\u099A\u09BE\u0987\u0995\u09B0\u09A3 \u098F\u0996\u09A8 \u09B8\u09AE\u09CD\u09AD\u09AC \u09A8\u09AF\u09BC",
1931
+ retry: "\u0986\u09AC\u09BE\u09B0 \u099A\u09C7\u09B7\u09CD\u099F\u09BE \u0995\u09B0\u09C1\u09A8",
1932
+ refresh: "\u09A8\u09A4\u09C1\u09A8 \u0985\u09A8\u09C1\u09B0\u09CB\u09A7",
1933
+ updating: "\u0995\u09CB\u09A1 \u0986\u09AA\u09A1\u09C7\u099F \u09B9\u099A\u09CD\u099B\u09C7",
1934
+ close: "\u09AC\u09A8\u09CD\u09A7 \u0995\u09B0\u09C1\u09A8",
1935
+ cancel: "\u09AC\u09BE\u09A4\u09BF\u09B2",
1936
+ autoUpdate: "\u0995\u09CB\u09A1 \u09AA\u09CD\u09B0\u09A4\u09BF \u09E9\u09E6 \u09B8\u09C7\u0995\u09C7\u09A8\u09CD\u09A1\u09C7 \u09B8\u09CD\u09AC\u09AF\u09BC\u0982\u0995\u09CD\u09B0\u09BF\u09AF\u09BC\u09AD\u09BE\u09AC\u09C7 \u09AC\u09A6\u09B2\u09BE\u09AF\u09BC",
1937
+ expiring: "\u0985\u09A8\u09C1\u09B0\u09CB\u09A7\u09C7\u09B0 \u09AE\u09C7\u09AF\u09BC\u09BE\u09A6 \u09B6\u09C0\u0998\u09CD\u09B0\u0987 \u09B6\u09C7\u09B7 \u09B9\u09AC\u09C7"
1938
+ };
1939
+
1940
+ // src/locales/es.json
1941
+ var es_default = {
1942
+ bind: "Vincula tu tel\xE9fono",
1943
+ confirm: "Confirma la verificaci\xF3n",
1944
+ scan: "Escanea con AuthLink",
1945
+ code: "C\xF3digo de comparaci\xF3n",
1946
+ help: "Comprueba que los n\xFAmeros coincidan en la aplicaci\xF3n y confirma en tu tel\xE9fono.",
1947
+ waiting: "Esperando la confirmaci\xF3n del tel\xE9fono",
1948
+ loading: "Conectando",
1949
+ confirmed: "Confirmado",
1950
+ rejected: "Rechazado",
1951
+ expired: "La solicitud ha caducado",
1952
+ error: "La verificaci\xF3n no est\xE1 disponible",
1953
+ retry: "Reintentar",
1954
+ refresh: "Nueva solicitud",
1955
+ updating: "Actualizando el c\xF3digo",
1956
+ close: "Cerrar",
1957
+ cancel: "Cancelar",
1958
+ autoUpdate: "El c\xF3digo se actualiza autom\xE1ticamente cada 30 segundos",
1959
+ expiring: "La solicitud est\xE1 por caducar"
1960
+ };
1961
+
1962
+ // src/locales/fil.json
1963
+ var fil_default = {
1964
+ bind: "Iugnay ang iyong telepono",
1965
+ confirm: "Kumpirmahin ang pagpapatunay",
1966
+ scan: "Mag-scan gamit ang AuthLink",
1967
+ code: "Code na paghahambingin",
1968
+ help: "Tiyaking magkapareho ang mga numero sa app, pagkatapos ay kumpirmahin sa iyong telepono.",
1969
+ waiting: "Hinihintay ang kumpirmasyon sa telepono",
1970
+ loading: "Kumokonekta",
1971
+ confirmed: "Nakumpirma",
1972
+ rejected: "Tinanggihan",
1973
+ expired: "Nag-expire ang kahilingan",
1974
+ error: "Hindi available ang pagpapatunay",
1975
+ retry: "Subukan muli",
1976
+ refresh: "Bagong kahilingan",
1977
+ updating: "Ina-update ang code",
1978
+ close: "Isara",
1979
+ cancel: "Kanselahin",
1980
+ autoUpdate: "Awtomatikong nagbabago ang code kada 30 segundo",
1981
+ expiring: "Malapit nang mag-expire ang kahilingan"
1982
+ };
1983
+
1984
+ // src/locales/hi.json
1985
+ var hi_default = {
1986
+ bind: "\u0905\u092A\u0928\u093E \u092B\u093C\u094B\u0928 \u091C\u094B\u0921\u093C\u0947\u0902",
1987
+ confirm: "\u0938\u0924\u094D\u092F\u093E\u092A\u0928 \u0915\u0940 \u092A\u0941\u0937\u094D\u091F\u093F \u0915\u0930\u0947\u0902",
1988
+ scan: "AuthLink \u0938\u0947 \u0938\u094D\u0915\u0948\u0928 \u0915\u0930\u0947\u0902",
1989
+ code: "\u092E\u093F\u0932\u093E\u0928 \u0915\u094B\u0921",
1990
+ help: "\u0910\u092A \u092E\u0947\u0902 \u0938\u0902\u0916\u094D\u092F\u093E\u0913\u0902 \u0915\u093E \u092E\u093F\u0932\u093E\u0928 \u0915\u0930\u0947\u0902, \u092B\u093F\u0930 \u0905\u092A\u0928\u0947 \u092B\u093C\u094B\u0928 \u092A\u0930 \u092A\u0941\u0937\u094D\u091F\u093F \u0915\u0930\u0947\u0902\u0964",
1991
+ waiting: "\u092B\u093C\u094B\u0928 \u092A\u0930 \u092A\u0941\u0937\u094D\u091F\u093F \u0915\u0940 \u092A\u094D\u0930\u0924\u0940\u0915\u094D\u0937\u093E \u0939\u0948",
1992
+ loading: "\u0915\u0928\u0947\u0915\u094D\u091F \u0939\u094B \u0930\u0939\u093E \u0939\u0948",
1993
+ confirmed: "\u092A\u0941\u0937\u094D\u091F\u093F \u0939\u094B \u0917\u0908",
1994
+ rejected: "\u0905\u0938\u094D\u0935\u0940\u0915\u0943\u0924",
1995
+ expired: "\u0905\u0928\u0941\u0930\u094B\u0927 \u0915\u0940 \u0938\u092E\u092F \u0938\u0940\u092E\u093E \u0938\u092E\u093E\u092A\u094D\u0924",
1996
+ error: "\u0938\u0924\u094D\u092F\u093E\u092A\u0928 \u0909\u092A\u0932\u092C\u094D\u0927 \u0928\u0939\u0940\u0902 \u0939\u0948",
1997
+ retry: "\u092B\u093F\u0930 \u0915\u094B\u0936\u093F\u0936 \u0915\u0930\u0947\u0902",
1998
+ refresh: "\u0928\u092F\u093E \u0905\u0928\u0941\u0930\u094B\u0927",
1999
+ updating: "\u0915\u094B\u0921 \u0905\u092A\u0921\u0947\u091F \u0939\u094B \u0930\u0939\u093E \u0939\u0948",
2000
+ close: "\u092C\u0902\u0926 \u0915\u0930\u0947\u0902",
2001
+ cancel: "\u0930\u0926\u094D\u0926 \u0915\u0930\u0947\u0902",
2002
+ autoUpdate: "\u0915\u094B\u0921 \u0939\u0930 30 \u0938\u0947\u0915\u0902\u0921 \u092E\u0947\u0902 \u0905\u092A\u0928\u0947 \u0906\u092A \u092C\u0926\u0932\u0924\u093E \u0939\u0948",
2003
+ expiring: "\u0905\u0928\u0941\u0930\u094B\u0927 \u0915\u0940 \u0938\u092E\u092F-\u0938\u0940\u092E\u093E \u0938\u092E\u093E\u092A\u094D\u0924 \u0939\u094B\u0928\u0947 \u0935\u093E\u0932\u0940 \u0939\u0948"
2004
+ };
2005
+
2006
+ // src/locales/id.json
2007
+ var id_default = {
2008
+ bind: "Tautkan ponsel Anda",
2009
+ confirm: "Konfirmasi verifikasi",
2010
+ scan: "Pindai dengan AuthLink",
2011
+ code: "Kode pencocokan",
2012
+ help: "Pastikan angka di aplikasi cocok, lalu konfirmasi di ponsel Anda.",
2013
+ waiting: "Menunggu konfirmasi dari ponsel",
2014
+ loading: "Menghubungkan",
2015
+ confirmed: "Dikonfirmasi",
2016
+ rejected: "Ditolak",
2017
+ expired: "Permintaan kedaluwarsa",
2018
+ error: "Verifikasi tidak tersedia",
2019
+ retry: "Coba lagi",
2020
+ refresh: "Permintaan baru",
2021
+ updating: "Memperbarui kode",
2022
+ close: "Tutup",
2023
+ cancel: "Batal",
2024
+ autoUpdate: "Kode diperbarui otomatis setiap 30 detik",
2025
+ expiring: "Permintaan akan segera kedaluwarsa"
2026
+ };
2027
+
2028
+ // src/locales/ms.json
2029
+ var ms_default = {
2030
+ bind: "Pautkan telefon anda",
2031
+ confirm: "Sahkan pengesahan",
2032
+ scan: "Imbas dengan AuthLink",
2033
+ code: "Kod padanan",
2034
+ help: "Pastikan nombor dalam aplikasi sepadan, kemudian sahkan pada telefon anda.",
2035
+ waiting: "Menunggu pengesahan daripada telefon",
2036
+ loading: "Sedang menyambung",
2037
+ confirmed: "Disahkan",
2038
+ rejected: "Ditolak",
2039
+ expired: "Permintaan telah tamat tempoh",
2040
+ error: "Pengesahan tidak tersedia",
2041
+ retry: "Cuba lagi",
2042
+ refresh: "Permintaan baharu",
2043
+ updating: "Sedang mengemas kini kod",
2044
+ close: "Tutup",
2045
+ cancel: "Batal",
2046
+ autoUpdate: "Kod dikemas kini secara automatik setiap 30 saat",
2047
+ expiring: "Permintaan akan tamat tempoh tidak lama lagi"
2048
+ };
2049
+
2050
+ // src/locales/pt.json
2051
+ var pt_default = {
2052
+ bind: "Vincule seu celular",
2053
+ confirm: "Confirme a verifica\xE7\xE3o",
2054
+ scan: "Escaneie com o AuthLink",
2055
+ code: "C\xF3digo de compara\xE7\xE3o",
2056
+ help: "Confira se os n\xFAmeros no aplicativo coincidem e confirme no celular.",
2057
+ waiting: "Aguardando confirma\xE7\xE3o no celular",
2058
+ loading: "Conectando",
2059
+ confirmed: "Confirmado",
2060
+ rejected: "Recusado",
2061
+ expired: "A solicita\xE7\xE3o expirou",
2062
+ error: "A verifica\xE7\xE3o est\xE1 indispon\xEDvel",
2063
+ retry: "Tentar novamente",
2064
+ refresh: "Nova solicita\xE7\xE3o",
2065
+ updating: "Atualizando o c\xF3digo",
2066
+ close: "Fechar",
2067
+ cancel: "Cancelar",
2068
+ autoUpdate: "O c\xF3digo \xE9 atualizado automaticamente a cada 30 segundos",
2069
+ expiring: "A solicita\xE7\xE3o est\xE1 prestes a expirar"
2070
+ };
2071
+
2072
+ // src/locales/th.json
2073
+ var th_default = {
2074
+ bind: "\u0E1C\u0E39\u0E01\u0E42\u0E17\u0E23\u0E28\u0E31\u0E1E\u0E17\u0E4C\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13",
2075
+ confirm: "\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E01\u0E32\u0E23\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A",
2076
+ scan: "\u0E2A\u0E41\u0E01\u0E19\u0E14\u0E49\u0E27\u0E22 AuthLink",
2077
+ code: "\u0E23\u0E2B\u0E31\u0E2A\u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E40\u0E1B\u0E23\u0E35\u0E22\u0E1A\u0E40\u0E17\u0E35\u0E22\u0E1A",
2078
+ help: "\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E27\u0E48\u0E32\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02\u0E43\u0E19\u0E41\u0E2D\u0E1B\u0E15\u0E23\u0E07\u0E01\u0E31\u0E19 \u0E41\u0E25\u0E49\u0E27\u0E08\u0E36\u0E07\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E1A\u0E19\u0E42\u0E17\u0E23\u0E28\u0E31\u0E1E\u0E17\u0E4C\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13",
2079
+ waiting: "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E23\u0E2D\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E08\u0E32\u0E01\u0E42\u0E17\u0E23\u0E28\u0E31\u0E1E\u0E17\u0E4C",
2080
+ loading: "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D",
2081
+ confirmed: "\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E41\u0E25\u0E49\u0E27",
2082
+ rejected: "\u0E1B\u0E0F\u0E34\u0E40\u0E2A\u0E18\u0E41\u0E25\u0E49\u0E27",
2083
+ expired: "\u0E04\u0E33\u0E02\u0E2D\u0E2B\u0E21\u0E14\u0E2D\u0E32\u0E22\u0E38",
2084
+ error: "\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E44\u0E14\u0E49\u0E43\u0E19\u0E02\u0E13\u0E30\u0E19\u0E35\u0E49",
2085
+ retry: "\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
2086
+ refresh: "\u0E04\u0E33\u0E02\u0E2D\u0E43\u0E2B\u0E21\u0E48",
2087
+ updating: "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2D\u0E31\u0E1B\u0E40\u0E14\u0E15\u0E23\u0E2B\u0E31\u0E2A",
2088
+ close: "\u0E1B\u0E34\u0E14",
2089
+ cancel: "\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01",
2090
+ autoUpdate: "\u0E23\u0E2B\u0E31\u0E2A\u0E08\u0E30\u0E2D\u0E31\u0E1B\u0E40\u0E14\u0E15\u0E2D\u0E31\u0E15\u0E42\u0E19\u0E21\u0E31\u0E15\u0E34\u0E17\u0E38\u0E01 30 \u0E27\u0E34\u0E19\u0E32\u0E17\u0E35",
2091
+ expiring: "\u0E04\u0E33\u0E02\u0E2D\u0E43\u0E01\u0E25\u0E49\u0E2B\u0E21\u0E14\u0E2D\u0E32\u0E22\u0E38"
2092
+ };
2093
+
2094
+ // src/locales/vi.json
2095
+ var vi_default = {
2096
+ bind: "Li\xEAn k\u1EBFt \u0111i\u1EC7n tho\u1EA1i",
2097
+ confirm: "X\xE1c nh\u1EADn x\xE1c th\u1EF1c",
2098
+ scan: "Qu\xE9t b\u1EB1ng AuthLink",
2099
+ code: "M\xE3 \u0111\u1ED1i chi\u1EBFu",
2100
+ help: "Ki\u1EC3m tra c\xE1c ch\u1EEF s\u1ED1 trong \u1EE9ng d\u1EE5ng c\xF3 kh\u1EDBp kh\xF4ng, r\u1ED3i x\xE1c nh\u1EADn tr\xEAn \u0111i\u1EC7n tho\u1EA1i.",
2101
+ waiting: "\u0110ang ch\u1EDD x\xE1c nh\u1EADn t\u1EEB \u0111i\u1EC7n tho\u1EA1i",
2102
+ loading: "\u0110ang k\u1EBFt n\u1ED1i",
2103
+ confirmed: "\u0110\xE3 x\xE1c nh\u1EADn",
2104
+ rejected: "\u0110\xE3 t\u1EEB ch\u1ED1i",
2105
+ expired: "Y\xEAu c\u1EA7u \u0111\xE3 h\u1EBFt h\u1EA1n",
2106
+ error: "Hi\u1EC7n kh\xF4ng th\u1EC3 x\xE1c th\u1EF1c",
2107
+ retry: "Th\u1EED l\u1EA1i",
2108
+ refresh: "Y\xEAu c\u1EA7u m\u1EDBi",
2109
+ updating: "\u0110ang c\u1EADp nh\u1EADt m\xE3",
2110
+ close: "\u0110\xF3ng",
2111
+ cancel: "H\u1EE7y",
2112
+ autoUpdate: "M\xE3 t\u1EF1 \u0111\u1ED9ng c\u1EADp nh\u1EADt m\u1ED7i 30 gi\xE2y",
2113
+ expiring: "Y\xEAu c\u1EA7u s\u1EAFp h\u1EBFt h\u1EA1n"
2114
+ };
2115
+
2116
+ // src/i18n.ts
2117
+ var messages = {
2118
+ "en": en_default,
2119
+ "zh-CN": zh_CN_default,
2120
+ "zh-TW": zh_TW_default,
2121
+ "ja": ja_default,
2122
+ "bn": bn_default,
2123
+ "es": es_default,
2124
+ "fil": fil_default,
2125
+ "hi": hi_default,
2126
+ "id": id_default,
2127
+ "ms": ms_default,
2128
+ "pt": pt_default,
2129
+ "th": th_default,
2130
+ "vi": vi_default
2131
+ };
2132
+ var defaultLocale = "zh-CN";
2133
+ function resolveLocale(locale) {
2134
+ return locale && Object.hasOwn(messages, locale) ? locale : defaultLocale;
2135
+ }
2136
+ function getMessages(locale) {
2137
+ return messages[resolveLocale(locale)];
2138
+ }
2139
+
2140
+ // src/view.ts
2141
+ var node = (tag, props, ...children) => ({ tag, props, children });
2142
+ function resolveVariant(variant) {
2143
+ return variant === "B" || variant === "C" ? variant : "A";
2144
+ }
2145
+ function widgetView(options) {
2146
+ const { snapshot: s, mode, retry, refresh } = options;
2147
+ const locale = resolveLocale(options.locale), variant = resolveVariant(options.variant);
2148
+ const l = getMessages(locale);
2149
+ const pending = s.status === "pending", hasQr = pending && (mode === "bind" || Boolean(options.showQr)) && Boolean(options.qr);
2150
+ const status = { idle: l.loading, pending: l.waiting, confirmed: l.confirmed, rejected: l.rejected, expired: l.expired, error: l.error }[s.status];
2151
+ const expiring = pending && s.secondsRemaining <= 30;
2152
+ const expiryTime = `00:${String(Math.max(0, Math.ceil(s.secondsRemaining))).padStart(2, "0")}`;
2153
+ const statusNode = () => node(
2154
+ "p",
2155
+ {
2156
+ class: "authlink-status",
2157
+ role: s.status === "error" ? "alert" : "status",
2158
+ "data-expiring": String(expiring)
2159
+ },
2160
+ node("span", { class: "authlink-status-dot", "aria-hidden": "true" }),
2161
+ expiring ? l.expiring : status,
2162
+ ...expiring ? [node("span", { class: "authlink-expiry", "aria-hidden": "true" }, ` \xB7 ${expiryTime}`)] : []
2163
+ );
2164
+ const cancel = () => options.close ? [node("button", {
2165
+ type: "button",
2166
+ class: "authlink-cancel",
2167
+ "data-authlink-focus": "cancel",
2168
+ onClick: options.close
2169
+ }, l.cancel)] : [];
2170
+ const children = [node("h3", { class: "authlink-title" }, l[mode])];
2171
+ if (hasQr) children.push(node("p", { class: "authlink-subtitle" }, l.scan));
2172
+ if (pending) {
2173
+ const qr = hasQr ? [node(
2174
+ "figure",
2175
+ { class: "authlink-qr-wrap" },
2176
+ node("img", { class: "authlink-qr", src: options.qr, alt: l.scan, width: 240, height: 240 }),
2177
+ node("figcaption", { class: "authlink-qr-caption" }, l.scan)
2178
+ )] : [];
2179
+ const seconds = Math.max(0, Math.min(30, s.codeSecondsRemaining));
2180
+ const code = node(
2181
+ "output",
2182
+ {
2183
+ class: "authlink-code",
2184
+ "aria-label": s.code ? `${l.code}: ${s.code.split("").join(" ")}` : l.updating,
2185
+ "aria-live": "polite",
2186
+ "data-testid": "authlink-code"
2187
+ },
2188
+ node("span", { class: "authlink-code-group" }, s.code?.slice(0, 3) ?? "---"),
2189
+ node("span", { class: "authlink-code-group" }, s.code?.slice(3) ?? "---")
2190
+ );
2191
+ const panel = node(
2192
+ "div",
2193
+ { class: "authlink-code-panel" },
2194
+ node("div", { class: "authlink-code-values" }, node("div", { class: "authlink-code-label" }, l.code), code),
2195
+ node(
2196
+ "div",
2197
+ {
2198
+ class: "authlink-progress",
2199
+ role: "progressbar",
2200
+ "aria-valuemin": 0,
2201
+ "aria-valuemax": 30,
2202
+ "aria-valuenow": seconds,
2203
+ "aria-label": l.autoUpdate
2204
+ },
2205
+ node("span", { class: "authlink-progress-fill", "aria-hidden": "true", style: `transform:scaleX(${seconds / 30})` })
2206
+ ),
2207
+ node("p", { class: "authlink-code-caption" }, s.code ? l.autoUpdate : l.updating)
2208
+ );
2209
+ const detail = [panel, node("p", { class: "authlink-help" }, l.help)];
2210
+ children.push(node("div", { class: "authlink-body" }, ...qr, node("div", { class: "authlink-details" }, ...detail)));
2211
+ if (variant === "A") children.push(node("div", { class: "authlink-footer" }, statusNode()));
2212
+ if (variant === "B") children.push(node("div", { class: "authlink-footer" }, statusNode(), ...cancel()));
2213
+ if (variant === "C") children.push(node("div", { class: "authlink-footer" }, statusNode(), ...cancel()));
2214
+ } else {
2215
+ children.push(statusNode());
2216
+ if (s.status === "error") children.push(node("button", {
2217
+ type: "button",
2218
+ class: "authlink-button",
2219
+ "data-authlink-focus": "retry",
2220
+ onClick: retry
2221
+ }, l.retry));
2222
+ if (refresh && ["expired", "rejected"].includes(s.status)) children.push(node("button", {
2223
+ type: "button",
2224
+ class: "authlink-button",
2225
+ "data-authlink-focus": "refresh",
2226
+ onClick: refresh
2227
+ }, l.refresh));
2228
+ }
2229
+ return node("section", {
2230
+ lang: locale,
2231
+ class: `authlink-widget ${options.className ?? ""}`.trim(),
2232
+ "data-status": s.status,
2233
+ "data-variant": variant,
2234
+ "data-has-qr": String(hasQr),
2235
+ "aria-label": l[mode]
2236
+ }, ...children);
2237
+ }
2238
+
2239
+ // src/modal.ts
2240
+ function element(value, svg = false) {
2241
+ if (typeof value === "string") return document.createTextNode(value);
2242
+ svg ||= value.tag === "svg";
2243
+ const result = svg ? document.createElementNS("http://www.w3.org/2000/svg", value.tag) : document.createElement(value.tag);
2244
+ for (const [key, v] of Object.entries(value.props)) {
2245
+ if (key === "onClick" && typeof v === "function") result.addEventListener("click", v);
2246
+ else if (v !== void 0 && v !== null) result.setAttribute(key, String(v));
2247
+ }
2248
+ result.append(...value.children.map((child) => element(child, svg)));
2249
+ return result;
2250
+ }
2251
+ function openAuthLink(options) {
2252
+ if (typeof document === "undefined" || !document.body) throw new AuthLinkError("BROWSER_REQUIRED");
2253
+ const mode = options.mode ?? options.ticket.purpose;
2254
+ const ticket = validateTicket(options.ticket, mode);
2255
+ const dialog = document.createElement("dialog");
2256
+ if (typeof dialog.showModal !== "function") throw new AuthLinkError("DIALOG_UNSUPPORTED");
2257
+ const previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
2258
+ dialog.className = `authlink-dialog ${options.className ?? ""}`.trim();
2259
+ dialog.setAttribute("aria-modal", "true");
2260
+ const header = document.createElement("div");
2261
+ header.className = "authlink-header";
2262
+ const brand = document.createElement("span");
2263
+ brand.className = "authlink-brand";
2264
+ brand.textContent = "AuthLink";
2265
+ brand.tabIndex = -1;
2266
+ const closeButton = document.createElement("button");
2267
+ closeButton.type = "button";
2268
+ closeButton.className = "authlink-close";
2269
+ const closeIcon = document.createElement("span");
2270
+ closeIcon.className = "authlink-close-icon";
2271
+ closeIcon.setAttribute("aria-hidden", "true");
2272
+ closeButton.append(closeIcon);
2273
+ const content = document.createElement("div");
2274
+ content.className = "authlink-modal-content";
2275
+ header.append(brand, closeButton);
2276
+ dialog.append(header, content);
2277
+ let locale = options.locale, variant = resolveVariant(options.variant), snapshot = initialSnapshot(), closed = false;
2278
+ let abort;
2279
+ const image = qrImage(ticket);
2280
+ let progressFill, progressFrame, progressDeadline = 0;
2281
+ const motion = window.matchMedia?.("(prefers-reduced-motion: reduce)");
2282
+ const stopProgress = () => {
2283
+ if (progressFrame !== void 0) window.cancelAnimationFrame(progressFrame);
2284
+ progressFrame = void 0;
2285
+ };
2286
+ const drawProgress = () => {
2287
+ stopProgress();
2288
+ if (closed || !progressFill?.isConnected) return;
2289
+ const remaining = Math.max(0, progressDeadline - performance.now());
2290
+ progressFill.style.transform = `scaleX(${Math.min(1, remaining / 3e4)})`;
2291
+ if (remaining > 0 && !motion?.matches && typeof window.requestAnimationFrame === "function") {
2292
+ progressFrame = window.requestAnimationFrame(drawProgress);
2293
+ }
2294
+ };
2295
+ const syncProgress = (remainingMs) => {
2296
+ progressDeadline = performance.now() + remainingMs;
2297
+ drawProgress();
2298
+ };
2299
+ motion?.addEventListener?.("change", drawProgress);
2300
+ const render = () => {
2301
+ if (closed) return;
2302
+ const language = resolveLocale(locale), messages2 = getMessages(language);
2303
+ dialog.lang = language;
2304
+ dialog.setAttribute("aria-label", messages2[mode]);
2305
+ dialog.dataset.variant = variant;
2306
+ dialog.dataset.mode = mode;
2307
+ dialog.dataset.hasQr = String(snapshot.status === "pending" && (mode === "bind" || Boolean(options.showQr)));
2308
+ closeButton.setAttribute("aria-label", messages2.close);
2309
+ const focused = document.activeElement;
2310
+ const focusKey = focused instanceof HTMLElement && content.contains(focused) ? focused.dataset.authlinkFocus : void 0;
2311
+ const next = element(widgetView({
2312
+ mode,
2313
+ locale,
2314
+ variant,
2315
+ snapshot,
2316
+ qr: image,
2317
+ showQr: options.showQr,
2318
+ retry,
2319
+ refresh: options.onRefresh,
2320
+ close: () => dispose(true)
2321
+ }));
2322
+ const oldCode = content.querySelector(".authlink-code");
2323
+ const nextCode = next.querySelector(".authlink-code");
2324
+ const codeChanged = Boolean(oldCode && nextCode && snapshot.code && oldCode.textContent !== nextCode.textContent);
2325
+ if (oldCode && nextCode && oldCode.textContent === nextCode.textContent) {
2326
+ oldCode.setAttribute("aria-label", nextCode.getAttribute("aria-label"));
2327
+ nextCode.replaceWith(oldCode);
2328
+ }
2329
+ const oldProgress = content.querySelector(".authlink-progress");
2330
+ const nextProgress = next.querySelector(".authlink-progress");
2331
+ if (oldProgress && nextProgress) {
2332
+ oldProgress.setAttribute("aria-valuenow", nextProgress.getAttribute("aria-valuenow"));
2333
+ oldProgress.setAttribute("aria-label", nextProgress.getAttribute("aria-label"));
2334
+ nextProgress.replaceWith(oldProgress);
2335
+ }
2336
+ content.replaceChildren(next);
2337
+ progressFill = content.querySelector(".authlink-progress-fill") ?? void 0;
2338
+ drawProgress();
2339
+ if (codeChanged && !window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {
2340
+ nextCode?.animate?.([{ opacity: 0.5 }, { opacity: 1 }], { duration: 180, easing: "ease-out" });
2341
+ }
2342
+ if (focusKey) (Array.from(content.querySelectorAll("[data-authlink-focus]")).find((item) => item.dataset.authlinkFocus === focusKey) ?? brand).focus({ preventScroll: true });
2343
+ };
2344
+ const dispose = (notify) => {
2345
+ if (closed) return;
2346
+ closed = true;
2347
+ abort?.abort();
2348
+ stopProgress();
2349
+ progressFill = void 0;
2350
+ motion?.removeEventListener?.("change", drawProgress);
2351
+ if (dialog.open) dialog.close();
2352
+ dialog.remove();
2353
+ if (!document.querySelector("dialog.authlink-dialog[open]")) {
2354
+ if (document.body.style.overflow === "hidden") document.body.style.overflow = document.body.dataset.authlinkOverflow ?? "";
2355
+ delete document.body.dataset.authlinkOverflow;
2356
+ }
2357
+ if (previousFocus?.isConnected) previousFocus.focus();
2358
+ if (notify) options.onClose?.();
2359
+ };
2360
+ const delivered = /* @__PURE__ */ new Set();
2361
+ const once = (status, callback) => {
2362
+ if (delivered.has(status)) return;
2363
+ delivered.add(status);
2364
+ return callback();
2365
+ };
2366
+ const retry = () => {
2367
+ if (closed) return;
2368
+ abort?.abort();
2369
+ abort = new AbortController();
2370
+ snapshot = initialSnapshot();
2371
+ render();
2372
+ void observeRequest(ticket, {
2373
+ client: options.client,
2374
+ intervalMs: options.intervalMs,
2375
+ expectedMode: mode,
2376
+ signal: abort.signal,
2377
+ onCodeTiming: syncProgress,
2378
+ onUpdate: (value) => {
2379
+ snapshot = value;
2380
+ if (value.status !== "rejected") render();
2381
+ },
2382
+ onConfirmed: (value) => once("confirmed", () => {
2383
+ dispose(false);
2384
+ try {
2385
+ return Promise.resolve(options.onConfirmed?.(value)).catch(() => options.onError?.(new AuthLinkError("CALLBACK_FAILED")));
2386
+ } catch {
2387
+ options.onError?.(new AuthLinkError("CALLBACK_FAILED"));
2388
+ }
2389
+ }),
2390
+ onRejected: (value) => once("rejected", () => {
2391
+ dispose(false);
2392
+ try {
2393
+ return Promise.resolve(options.onRejected?.(value)).catch(() => options.onError?.(new AuthLinkError("CALLBACK_FAILED")));
2394
+ } catch {
2395
+ options.onError?.(new AuthLinkError("CALLBACK_FAILED"));
2396
+ }
2397
+ }),
2398
+ onExpired: () => once("expired", () => options.onExpired?.()),
2399
+ onError: options.onError
2400
+ });
2401
+ };
2402
+ closeButton.addEventListener("click", () => dispose(true));
2403
+ dialog.addEventListener("cancel", (event) => {
2404
+ event.preventDefault();
2405
+ dispose(true);
2406
+ });
2407
+ dialog.addEventListener("close", () => dispose(true));
2408
+ render();
2409
+ document.body.append(dialog);
2410
+ try {
2411
+ dialog.showModal();
2412
+ } catch (error) {
2413
+ dialog.remove();
2414
+ throw error;
2415
+ }
2416
+ brand.focus({ preventScroll: true });
2417
+ if (document.body.dataset.authlinkOverflow === void 0) document.body.dataset.authlinkOverflow = document.body.style.overflow;
2418
+ document.body.style.overflow = "hidden";
2419
+ retry();
2420
+ return {
2421
+ close: () => dispose(true),
2422
+ destroy: () => dispose(false),
2423
+ setLocale: (value) => {
2424
+ locale = value;
2425
+ render();
2426
+ },
2427
+ setVariant: (value) => {
2428
+ variant = resolveVariant(value);
2429
+ render();
2430
+ },
2431
+ retry
2432
+ };
2433
+ }
2434
+
2435
+ // src/vue.ts
2436
+ function useAuthLink(getOptions) {
2437
+ const snapshot = shallowRef(initialSnapshot());
2438
+ const delivered = /* @__PURE__ */ new Set();
2439
+ let mounted = false, abort;
2440
+ const retry = () => {
2441
+ if (!mounted) return;
2442
+ abort?.abort();
2443
+ abort = new AbortController();
2444
+ const options = getOptions();
2445
+ snapshot.value = initialSnapshot();
2446
+ const once = (status, callback) => {
2447
+ const key = `${options.ticket.requestId}:${status}`;
2448
+ if (delivered.has(key)) return;
2449
+ delivered.add(key);
2450
+ return callback();
2451
+ };
2452
+ void observeRequest(options.ticket, {
2453
+ client: options.client,
2454
+ intervalMs: options.intervalMs,
2455
+ expectedMode: options.mode,
2456
+ signal: abort.signal,
2457
+ onUpdate: (value) => {
2458
+ snapshot.value = value;
2459
+ },
2460
+ onConfirmed: (value) => once("confirmed", () => getOptions().onConfirmed?.(value)),
2461
+ onRejected: (result) => once("rejected", () => getOptions().onRejected?.(result)),
2462
+ onExpired: () => once("expired", () => getOptions().onExpired?.()),
2463
+ onError: (error) => getOptions().onError?.(error)
2464
+ });
2465
+ };
2466
+ onMounted(() => {
2467
+ mounted = true;
2468
+ retry();
2469
+ });
2470
+ watch([
2471
+ () => getOptions().ticket,
2472
+ () => getOptions().client,
2473
+ () => getOptions().intervalMs,
2474
+ () => getOptions().mode
2475
+ ], retry);
2476
+ onBeforeUnmount(() => {
2477
+ mounted = false;
2478
+ abort?.abort();
2479
+ });
2480
+ return { snapshot, retry };
2481
+ }
2482
+ function widget(mode) {
2483
+ return defineComponent({
2484
+ name: mode === "bind" ? "AuthLinkBind" : "AuthLinkConfirm",
2485
+ inheritAttrs: false,
2486
+ props: {
2487
+ ticket: { type: Object, required: true },
2488
+ client: { type: Object, required: true },
2489
+ locale: { type: String, default: defaultLocale },
2490
+ variant: { type: String, default: "A" },
2491
+ intervalMs: Number,
2492
+ showQr: Boolean,
2493
+ className: String,
2494
+ onRefresh: Function
2495
+ },
2496
+ emits: ["confirmed", "rejected", "expired", "error", "close"],
2497
+ setup(props, { emit, attrs }) {
2498
+ let modal, mounted = false;
2499
+ const delivered = /* @__PURE__ */ new Set();
2500
+ const once = (status, callback) => {
2501
+ const key = `${props.ticket.requestId}:${status}`;
2502
+ if (delivered.has(key)) return;
2503
+ delivered.add(key);
2504
+ callback();
2505
+ };
2506
+ const open = () => {
2507
+ if (!mounted) return;
2508
+ modal?.destroy();
2509
+ modal = openAuthLink({
2510
+ ...props,
2511
+ mode,
2512
+ className: normalizeClass([props.className, attrs.class]),
2513
+ onRefresh: props.onRefresh ? () => props.onRefresh?.() : void 0,
2514
+ onConfirmed: (value) => once("confirmed", () => emit("confirmed", value)),
2515
+ onRejected: (result) => once("rejected", () => emit("rejected", result)),
2516
+ onExpired: () => once("expired", () => emit("expired")),
2517
+ onError: (error) => emit("error", error),
2518
+ onClose: () => emit("close")
2519
+ });
2520
+ };
2521
+ onMounted(() => {
2522
+ mounted = true;
2523
+ open();
2524
+ });
2525
+ watch([
2526
+ () => props.ticket,
2527
+ () => props.client,
2528
+ () => props.intervalMs,
2529
+ () => props.showQr,
2530
+ () => props.className,
2531
+ () => Boolean(props.onRefresh)
2532
+ ], open);
2533
+ watch(() => props.locale, (value) => modal?.setLocale(value));
2534
+ watch(() => props.variant, (value) => modal?.setVariant(value));
2535
+ onBeforeUnmount(() => {
2536
+ mounted = false;
2537
+ modal?.destroy();
2538
+ });
2539
+ return () => null;
2540
+ }
2541
+ });
2542
+ }
2543
+ var AuthLinkBind = widget("bind");
2544
+ var AuthLinkConfirm = widget("confirm");
2545
+ export {
2546
+ AuthLinkBind,
2547
+ AuthLinkConfirm,
2548
+ useAuthLink
2549
+ };
2550
+ //# sourceMappingURL=vue.js.map