@oila/0account 3.4.3 → 3.4.5

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.
Files changed (94) hide show
  1. package/LICENSE +1 -1
  2. package/dist/cjs/index-1e526aba.js +1645 -0
  3. package/dist/cjs/index-1e526aba.js.map +1 -0
  4. package/dist/cjs/index.cjs.js +4 -0
  5. package/dist/cjs/index.cjs.js.map +1 -0
  6. package/dist/cjs/loader.cjs.js +15 -0
  7. package/dist/cjs/loader.cjs.js.map +1 -0
  8. package/dist/cjs/qr-code_2.cjs.entry.js +2472 -0
  9. package/dist/cjs/qr-code_2.cjs.entry.js.map +1 -0
  10. package/dist/cjs/zero-account.cjs.js +25 -0
  11. package/dist/cjs/zero-account.cjs.js.map +1 -0
  12. package/dist/collection/collection-manifest.json +13 -0
  13. package/dist/collection/components/zero-account/enums.js +18 -0
  14. package/dist/collection/components/zero-account/enums.js.map +1 -0
  15. package/dist/collection/components/zero-account/logo.js +6 -0
  16. package/dist/collection/components/zero-account/logo.js.map +1 -0
  17. package/dist/collection/components/zero-account/qrcode.js +111 -0
  18. package/dist/collection/components/zero-account/qrcode.js.map +1 -0
  19. package/dist/collection/components/zero-account/websocket.js +174 -0
  20. package/dist/collection/components/zero-account/websocket.js.map +1 -0
  21. package/dist/collection/components/zero-account/zero-account.css +287 -0
  22. package/dist/collection/components/zero-account/zero-account.e2e.js +26 -0
  23. package/dist/collection/components/zero-account/zero-account.e2e.js.map +1 -0
  24. package/dist/collection/components/zero-account/zero-account.js +457 -0
  25. package/dist/collection/components/zero-account/zero-account.js.map +1 -0
  26. package/dist/collection/components/zero-account/zero-account.spec.js +35 -0
  27. package/dist/collection/components/zero-account/zero-account.spec.js.map +1 -0
  28. package/dist/collection/index.js +2 -0
  29. package/dist/collection/index.js.map +1 -0
  30. package/dist/collection/utils/qrcode/qrcode.js +1007 -0
  31. package/dist/collection/utils/request.js +38 -0
  32. package/dist/collection/utils/request.js.map +1 -0
  33. package/dist/collection/utils/url.js +43 -0
  34. package/dist/collection/utils/utils.js +16 -0
  35. package/dist/collection/utils/utils.js.map +1 -0
  36. package/dist/collection/utils/utils.spec.js +10 -0
  37. package/dist/collection/utils/utils.spec.js.map +1 -0
  38. package/dist/components/index.d.ts +27 -0
  39. package/dist/components/index.js +3 -0
  40. package/dist/components/index.js.map +1 -0
  41. package/dist/components/qr-code.d.ts +11 -0
  42. package/dist/components/qr-code.js +8 -0
  43. package/dist/components/qr-code.js.map +1 -0
  44. package/dist/components/qrcode.js +1073 -0
  45. package/dist/components/qrcode.js.map +1 -0
  46. package/dist/components/zero-account.d.ts +11 -0
  47. package/dist/components/zero-account.js +1460 -0
  48. package/dist/components/zero-account.js.map +1 -0
  49. package/dist/esm/index-09024c20.js +1616 -0
  50. package/dist/esm/index-09024c20.js.map +1 -0
  51. package/dist/esm/index.js +3 -0
  52. package/dist/esm/index.js.map +1 -0
  53. package/dist/esm/loader.js +11 -0
  54. package/dist/esm/loader.js.map +1 -0
  55. package/dist/esm/polyfills/core-js.js +11 -0
  56. package/dist/esm/polyfills/dom.js +79 -0
  57. package/dist/esm/polyfills/es5-html-element.js +1 -0
  58. package/dist/esm/polyfills/index.js +34 -0
  59. package/dist/esm/polyfills/system.js +6 -0
  60. package/dist/esm/qr-code_2.entry.js +2467 -0
  61. package/dist/esm/qr-code_2.entry.js.map +1 -0
  62. package/dist/esm/zero-account.js +20 -0
  63. package/dist/esm/zero-account.js.map +1 -0
  64. package/dist/index.cjs.js +1 -0
  65. package/dist/index.js +1 -0
  66. package/dist/types/components/zero-account/enums.d.ts +14 -0
  67. package/dist/types/components/zero-account/logo.d.ts +5 -0
  68. package/dist/types/components/zero-account/qrcode.d.ts +8 -0
  69. package/dist/types/components/zero-account/websocket.d.ts +31 -0
  70. package/dist/types/components/zero-account/zero-account.d.ts +45 -0
  71. package/dist/types/components.d.ts +88 -0
  72. package/dist/types/index.d.ts +1 -0
  73. package/dist/types/stencil-public-runtime.d.ts +1640 -0
  74. package/dist/types/utils/request.d.ts +10 -0
  75. package/dist/types/utils/utils.d.ts +7 -0
  76. package/dist/zero-account/index.esm.js +2 -0
  77. package/dist/zero-account/index.esm.js.map +1 -0
  78. package/dist/zero-account/p-21f4994d.js +3 -0
  79. package/dist/zero-account/p-21f4994d.js.map +1 -0
  80. package/dist/zero-account/p-9a90a04d.entry.js +2 -0
  81. package/dist/zero-account/p-9a90a04d.entry.js.map +1 -0
  82. package/dist/zero-account/zero-account.esm.js +2 -0
  83. package/dist/zero-account/zero-account.esm.js.map +1 -0
  84. package/loader/cdn.js +3 -0
  85. package/loader/index.cjs.js +3 -0
  86. package/loader/index.d.ts +21 -0
  87. package/loader/index.es2017.js +3 -0
  88. package/loader/index.js +4 -0
  89. package/loader/package.json +11 -0
  90. package/package.json +33 -40
  91. package/readme.md +75 -0
  92. package/0account.d.ts +0 -24
  93. package/README.md +0 -3
  94. package/dist/0account.js +0 -1
@@ -0,0 +1,2472 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-1e526aba.js');
6
+
7
+ /*
8
+ * QR Code generator library (JavaScript)
9
+ *
10
+ * Copyright (c) Project Nayuki. (MIT License)
11
+ * https://www.nayuki.io/page/qr-code-generator-library
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
14
+ * this software and associated documentation files (the "Software"), to deal in
15
+ * the Software without restriction, including without limitation the rights to
16
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
17
+ * the Software, and to permit persons to whom the Software is furnished to do so,
18
+ * subject to the following conditions:
19
+ * - The above copyright notice and this permission notice shall be included in
20
+ * all copies or substantial portions of the Software.
21
+ * - The Software is provided "as is", without warranty of any kind, express or
22
+ * implied, including but not limited to the warranties of merchantability,
23
+ * fitness for a particular purpose and noninfringement. In no event shall the
24
+ * authors or copyright holders be liable for any claim, damages or other
25
+ * liability, whether in an action of contract, tort or otherwise, arising from,
26
+ * out of or in connection with the Software or the use or other dealings in the
27
+ * Software.
28
+ */
29
+
30
+
31
+ /*
32
+ * Module "qrcodegen", public members:
33
+ * - Class QrCode:
34
+ * - Function encodeText(str text, QrCode.Ecc ecl) -> QrCode
35
+ * - Function encodeBinary(list<byte> data, QrCode.Ecc ecl) -> QrCode
36
+ * - Function encodeSegments(list<QrSegment> segs, QrCode.Ecc ecl,
37
+ * int minVersion=1, int maxVersion=40, mask=-1, boostEcl=true) -> QrCode
38
+ * - Constants int MIN_VERSION, MAX_VERSION
39
+ * - Constructor QrCode(int version, QrCode.Ecc ecl, list<byte> dataCodewords, int mask)
40
+ * - Fields int version, size, mask
41
+ * - Field QrCode.Ecc errorCorrectionLevel
42
+ * - Method getModule(int x, int y) -> bool
43
+ * - Method drawCanvas(int scale, int border, HTMLCanvasElement canvas) -> void
44
+ * - Method toSvgString(int border) -> str
45
+ * - Enum Ecc:
46
+ * - Constants LOW, MEDIUM, QUARTILE, HIGH
47
+ * - Field int ordinal
48
+ * - Class QrSegment:
49
+ * - Function makeBytes(list<byte> data) -> QrSegment
50
+ * - Function makeNumeric(str data) -> QrSegment
51
+ * - Function makeAlphanumeric(str data) -> QrSegment
52
+ * - Function makeSegments(str text) -> list<QrSegment>
53
+ * - Function makeEci(int assignVal) -> QrSegment
54
+ * - Constructor QrSegment(QrSegment.Mode mode, int numChars, list<int> bitData)
55
+ * - Field QrSegment.Mode mode
56
+ * - Field int numChars
57
+ * - Method getData() -> list<int>
58
+ * - Constants RegExp NUMERIC_REGEX, ALPHANUMERIC_REGEX
59
+ * - Enum Mode:
60
+ * - Constants NUMERIC, ALPHANUMERIC, BYTE, KANJI, ECI
61
+ */
62
+ var qrcodegen = new function() {
63
+
64
+ /*---- QR Code symbol class ----*/
65
+
66
+ /*
67
+ * A class that represents a QR Code symbol, which is a type of two-dimension barcode.
68
+ * Invented by Denso Wave and described in the ISO/IEC 18004 standard.
69
+ * Instances of this class represent an immutable square grid of black and white cells.
70
+ * The class provides static factory functions to create a QR Code from text or binary data.
71
+ * The class covers the QR Code Model 2 specification, supporting all versions (sizes)
72
+ * from 1 to 40, all 4 error correction levels, and 4 character encoding modes.
73
+ *
74
+ * Ways to create a QR Code object:
75
+ * - High level: Take the payload data and call QrCode.encodeText() or QrCode.encodeBinary().
76
+ * - Mid level: Custom-make the list of segments and call QrCode.encodeSegments().
77
+ * - Low level: Custom-make the array of data codeword bytes (including
78
+ * segment headers and final padding, excluding error correction codewords),
79
+ * supply the appropriate version number, and call the QrCode() constructor.
80
+ * (Note that all ways require supplying the desired error correction level.)
81
+ *
82
+ * This constructor creates a new QR Code with the given version number,
83
+ * error correction level, data codeword bytes, and mask number.
84
+ * This is a low-level API that most users should not use directly.
85
+ * A mid-level API is the encodeSegments() function.
86
+ */
87
+ this.QrCode = function(version, errCorLvl, dataCodewords, mask) {
88
+
89
+ /*---- Constructor (low level) ----*/
90
+
91
+ // Check scalar arguments
92
+ if (version < MIN_VERSION || version > MAX_VERSION)
93
+ throw "Version value out of range";
94
+ if (mask < -1 || mask > 7)
95
+ throw "Mask value out of range";
96
+ if (!(errCorLvl instanceof Ecc))
97
+ throw "QrCode.Ecc expected";
98
+ var size = version * 4 + 17;
99
+
100
+ // Initialize both grids to be size*size arrays of Boolean false
101
+ var row = [];
102
+ for (var i = 0; i < size; i++)
103
+ row.push(false);
104
+ var modules = []; // Initially all white
105
+ var isFunction = [];
106
+ for (var i = 0; i < size; i++) {
107
+ modules .push(row.slice());
108
+ isFunction.push(row.slice());
109
+ }
110
+
111
+ // Compute ECC, draw modules
112
+ drawFunctionPatterns();
113
+ var allCodewords = addEccAndInterleave(dataCodewords);
114
+ drawCodewords(allCodewords);
115
+
116
+ // Do masking
117
+ if (mask == -1) { // Automatically choose best mask
118
+ var minPenalty = Infinity;
119
+ for (var i = 0; i < 8; i++) {
120
+ drawFormatBits(i);
121
+ applyMask(i);
122
+ var penalty = getPenaltyScore();
123
+ if (penalty < minPenalty) {
124
+ mask = i;
125
+ minPenalty = penalty;
126
+ }
127
+ applyMask(i); // Undoes the mask due to XOR
128
+ }
129
+ }
130
+ if (mask < 0 || mask > 7)
131
+ throw "Assertion error";
132
+ drawFormatBits(mask); // Overwrite old format bits
133
+ applyMask(mask); // Apply the final choice of mask
134
+
135
+ isFunction = null;
136
+
137
+
138
+ /*---- Read-only instance properties ----*/
139
+
140
+ // The version number of this QR Code, which is between 1 and 40 (inclusive).
141
+ // This determines the size of this barcode.
142
+ Object.defineProperty(this, "version", {value:version});
143
+
144
+ // The width and height of this QR Code, measured in modules, between
145
+ // 21 and 177 (inclusive). This is equal to version * 4 + 17.
146
+ Object.defineProperty(this, "size", {value:size});
147
+
148
+ // The error correction level used in this QR Code.
149
+ Object.defineProperty(this, "errorCorrectionLevel", {value:errCorLvl});
150
+
151
+ // The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
152
+ // Even if a QR Code is created with automatic masking requested (mask = -1),
153
+ // the resulting object still has a mask value between 0 and 7.
154
+ Object.defineProperty(this, "mask", {value:mask});
155
+
156
+
157
+ /*---- Accessor methods ----*/
158
+
159
+ // Returns the color of the module (pixel) at the given coordinates, which is false
160
+ // for white or true for black. The top left corner has the coordinates (x=0, y=0).
161
+ // If the given coordinates are out of bounds, then false (white) is returned.
162
+ this.getModule = function(x, y) {
163
+ return 0 <= x && x < size && 0 <= y && y < size && modules[y][x];
164
+ };
165
+
166
+
167
+ /*---- Public instance methods ----*/
168
+
169
+ this.circlePath = function(cx, cy, r){
170
+ return 'M '+cx+' '+cy+' m -'+r+', 0 a '+r+','+r+' 0 1,0 '+(r*2)+',0 a '+r+','+r+' 0 1,0 -'+(r*2)+',0';
171
+ };
172
+
173
+ this.svgObject = function(round) {
174
+ var parts = [];
175
+ for (var y = 0; y < size; y++) {
176
+ for (var x = 0; x < size; x++) {
177
+ if (this.getModule(x, y)){
178
+ if (round) {
179
+ parts.push(this.circlePath(x+0.5,y+0.5, 0.5));
180
+ } else {
181
+ parts.push("M" + x + "," + y + "h1v1h-1z");
182
+ }
183
+ }
184
+ }
185
+ }
186
+ return {
187
+ path: parts.join(" "),
188
+ size: size
189
+ }
190
+ };
191
+
192
+
193
+ /*---- Private helper methods for constructor: Drawing function modules ----*/
194
+
195
+ // Reads this object's version field, and draws and marks all function modules.
196
+ function drawFunctionPatterns() {
197
+ // Draw horizontal and vertical timing patterns
198
+ for (var i = 0; i < size; i++) {
199
+ setFunctionModule(6, i, i % 2 == 0);
200
+ setFunctionModule(i, 6, i % 2 == 0);
201
+ }
202
+
203
+ // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
204
+ drawFinderPattern(3, 3);
205
+ drawFinderPattern(size - 4, 3);
206
+ drawFinderPattern(3, size - 4);
207
+
208
+ // Draw numerous alignment patterns
209
+ var alignPatPos = getAlignmentPatternPositions();
210
+ var numAlign = alignPatPos.length;
211
+ for (var i = 0; i < numAlign; i++) {
212
+ for (var j = 0; j < numAlign; j++) {
213
+ // Don't draw on the three finder corners
214
+ if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
215
+ drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
216
+ }
217
+ }
218
+
219
+ // Draw configuration data
220
+ drawFormatBits(0); // Dummy mask value; overwritten later in the constructor
221
+ drawVersion();
222
+ }
223
+
224
+
225
+ // Draws two copies of the format bits (with its own error correction code)
226
+ // based on the given mask and this object's error correction level field.
227
+ function drawFormatBits(mask) {
228
+ // Calculate error correction code and pack bits
229
+ var data = errCorLvl.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3
230
+ var rem = data;
231
+ for (var i = 0; i < 10; i++)
232
+ rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
233
+ var bits = (data << 10 | rem) ^ 0x5412; // uint15
234
+ if (bits >>> 15 != 0)
235
+ throw "Assertion error";
236
+
237
+ // Draw first copy
238
+ for (var i = 0; i <= 5; i++)
239
+ setFunctionModule(8, i, getBit(bits, i));
240
+ setFunctionModule(8, 7, getBit(bits, 6));
241
+ setFunctionModule(8, 8, getBit(bits, 7));
242
+ setFunctionModule(7, 8, getBit(bits, 8));
243
+ for (var i = 9; i < 15; i++)
244
+ setFunctionModule(14 - i, 8, getBit(bits, i));
245
+
246
+ // Draw second copy
247
+ for (var i = 0; i < 8; i++)
248
+ setFunctionModule(size - 1 - i, 8, getBit(bits, i));
249
+ for (var i = 8; i < 15; i++)
250
+ setFunctionModule(8, size - 15 + i, getBit(bits, i));
251
+ setFunctionModule(8, size - 8, true); // Always black
252
+ }
253
+
254
+
255
+ // Draws two copies of the version bits (with its own error correction code),
256
+ // based on this object's version field, iff 7 <= version <= 40.
257
+ function drawVersion() {
258
+ if (version < 7)
259
+ return;
260
+
261
+ // Calculate error correction code and pack bits
262
+ var rem = version; // version is uint6, in the range [7, 40]
263
+ for (var i = 0; i < 12; i++)
264
+ rem = (rem << 1) ^ ((rem >>> 11) * 0x1F25);
265
+ var bits = version << 12 | rem; // uint18
266
+ if (bits >>> 18 != 0)
267
+ throw "Assertion error";
268
+
269
+ // Draw two copies
270
+ for (var i = 0; i < 18; i++) {
271
+ var bit = getBit(bits, i);
272
+ var a = size - 11 + i % 3;
273
+ var b = Math.floor(i / 3);
274
+ setFunctionModule(a, b, bit);
275
+ setFunctionModule(b, a, bit);
276
+ }
277
+ }
278
+
279
+
280
+ // Draws a 9*9 finder pattern including the border separator,
281
+ // with the center module at (x, y). Modules can be out of bounds.
282
+ function drawFinderPattern(x, y) {
283
+ for (var dy = -4; dy <= 4; dy++) {
284
+ for (var dx = -4; dx <= 4; dx++) {
285
+ var dist = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm
286
+ var xx = x + dx, yy = y + dy;
287
+ if (0 <= xx && xx < size && 0 <= yy && yy < size)
288
+ setFunctionModule(xx, yy, dist != 2 && dist != 4);
289
+ }
290
+ }
291
+ }
292
+
293
+
294
+ // Draws a 5*5 alignment pattern, with the center module
295
+ // at (x, y). All modules must be in bounds.
296
+ function drawAlignmentPattern(x, y) {
297
+ for (var dy = -2; dy <= 2; dy++) {
298
+ for (var dx = -2; dx <= 2; dx++)
299
+ setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
300
+ }
301
+ }
302
+
303
+
304
+ // Sets the color of a module and marks it as a function module.
305
+ // Only used by the constructor. Coordinates must be in bounds.
306
+ function setFunctionModule(x, y, isBlack) {
307
+ modules[y][x] = isBlack;
308
+ isFunction[y][x] = true;
309
+ }
310
+
311
+
312
+ /*---- Private helper methods for constructor: Codewords and masking ----*/
313
+
314
+ // Returns a new byte string representing the given data with the appropriate error correction
315
+ // codewords appended to it, based on this object's version and error correction level.
316
+ function addEccAndInterleave(data) {
317
+ if (data.length != QrCode.getNumDataCodewords(version, errCorLvl))
318
+ throw "Invalid argument";
319
+
320
+ // Calculate parameter numbers
321
+ var numBlocks = QrCode.NUM_ERROR_CORRECTION_BLOCKS[errCorLvl.ordinal][version];
322
+ var blockEccLen = QrCode.ECC_CODEWORDS_PER_BLOCK [errCorLvl.ordinal][version];
323
+ var rawCodewords = Math.floor(QrCode.getNumRawDataModules(version) / 8);
324
+ var numShortBlocks = numBlocks - rawCodewords % numBlocks;
325
+ var shortBlockLen = Math.floor(rawCodewords / numBlocks);
326
+
327
+ // Split data into blocks and append ECC to each block
328
+ var blocks = [];
329
+ var rs = new ReedSolomonGenerator(blockEccLen);
330
+ for (var i = 0, k = 0; i < numBlocks; i++) {
331
+ var dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
332
+ k += dat.length;
333
+ var ecc = rs.getRemainder(dat);
334
+ if (i < numShortBlocks)
335
+ dat.push(0);
336
+ blocks.push(dat.concat(ecc));
337
+ }
338
+
339
+ // Interleave (not concatenate) the bytes from every block into a single sequence
340
+ var result = [];
341
+ for (var i = 0; i < blocks[0].length; i++) {
342
+ for (var j = 0; j < blocks.length; j++) {
343
+ // Skip the padding byte in short blocks
344
+ if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
345
+ result.push(blocks[j][i]);
346
+ }
347
+ }
348
+ if (result.length != rawCodewords)
349
+ throw "Assertion error";
350
+ return result;
351
+ }
352
+
353
+
354
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
355
+ // data area of this QR Code. Function modules need to be marked off before this is called.
356
+ function drawCodewords(data) {
357
+ if (data.length != Math.floor(QrCode.getNumRawDataModules(version) / 8))
358
+ throw "Invalid argument";
359
+ var i = 0; // Bit index into the data
360
+ // Do the funny zigzag scan
361
+ for (var right = size - 1; right >= 1; right -= 2) { // Index of right column in each column pair
362
+ if (right == 6)
363
+ right = 5;
364
+ for (var vert = 0; vert < size; vert++) { // Vertical counter
365
+ for (var j = 0; j < 2; j++) {
366
+ var x = right - j; // Actual x coordinate
367
+ var upward = ((right + 1) & 2) == 0;
368
+ var y = upward ? size - 1 - vert : vert; // Actual y coordinate
369
+ if (!isFunction[y][x] && i < data.length * 8) {
370
+ modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
371
+ i++;
372
+ }
373
+ // If this QR Code has any remainder bits (0 to 7), they were assigned as
374
+ // 0/false/white by the constructor and are left unchanged by this method
375
+ }
376
+ }
377
+ }
378
+ if (i != data.length * 8)
379
+ throw "Assertion error";
380
+ }
381
+
382
+
383
+ // XORs the codeword modules in this QR Code with the given mask pattern.
384
+ // The function modules must be marked and the codeword bits must be drawn
385
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
386
+ // the same mask value a second time will undo the mask. A final well-formed
387
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
388
+ function applyMask(mask) {
389
+ if (mask < 0 || mask > 7)
390
+ throw "Mask value out of range";
391
+ for (var y = 0; y < size; y++) {
392
+ for (var x = 0; x < size; x++) {
393
+ var invert;
394
+ switch (mask) {
395
+ case 0: invert = (x + y) % 2 == 0; break;
396
+ case 1: invert = y % 2 == 0; break;
397
+ case 2: invert = x % 3 == 0; break;
398
+ case 3: invert = (x + y) % 3 == 0; break;
399
+ case 4: invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0; break;
400
+ case 5: invert = x * y % 2 + x * y % 3 == 0; break;
401
+ case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break;
402
+ case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break;
403
+ default: throw "Assertion error";
404
+ }
405
+ if (!isFunction[y][x] && invert)
406
+ modules[y][x] = !modules[y][x];
407
+ }
408
+ }
409
+ }
410
+
411
+
412
+ // Calculates and returns the penalty score based on state of this QR Code's current modules.
413
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
414
+ function getPenaltyScore() {
415
+ var result = 0;
416
+
417
+ // Adjacent modules in row having same color
418
+ for (var y = 0; y < size; y++) {
419
+ for (var x = 0, runX, colorX; x < size; x++) {
420
+ if (x == 0 || modules[y][x] != colorX) {
421
+ colorX = modules[y][x];
422
+ runX = 1;
423
+ } else {
424
+ runX++;
425
+ if (runX == 5)
426
+ result += QrCode.PENALTY_N1;
427
+ else if (runX > 5)
428
+ result++;
429
+ }
430
+ }
431
+ }
432
+ // Adjacent modules in column having same color
433
+ for (var x = 0; x < size; x++) {
434
+ for (var y = 0, runY, colorY; y < size; y++) {
435
+ if (y == 0 || modules[y][x] != colorY) {
436
+ colorY = modules[y][x];
437
+ runY = 1;
438
+ } else {
439
+ runY++;
440
+ if (runY == 5)
441
+ result += QrCode.PENALTY_N1;
442
+ else if (runY > 5)
443
+ result++;
444
+ }
445
+ }
446
+ }
447
+
448
+ // 2*2 blocks of modules having same color
449
+ for (var y = 0; y < size - 1; y++) {
450
+ for (var x = 0; x < size - 1; x++) {
451
+ var color = modules[y][x];
452
+ if ( color == modules[y][x + 1] &&
453
+ color == modules[y + 1][x] &&
454
+ color == modules[y + 1][x + 1])
455
+ result += QrCode.PENALTY_N2;
456
+ }
457
+ }
458
+
459
+ // Finder-like pattern in rows
460
+ for (var y = 0; y < size; y++) {
461
+ for (var x = 0, bits = 0; x < size; x++) {
462
+ bits = ((bits << 1) & 0x7FF) | (modules[y][x] ? 1 : 0);
463
+ if (x >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
464
+ result += QrCode.PENALTY_N3;
465
+ }
466
+ }
467
+ // Finder-like pattern in columns
468
+ for (var x = 0; x < size; x++) {
469
+ for (var y = 0, bits = 0; y < size; y++) {
470
+ bits = ((bits << 1) & 0x7FF) | (modules[y][x] ? 1 : 0);
471
+ if (y >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
472
+ result += QrCode.PENALTY_N3;
473
+ }
474
+ }
475
+
476
+ // Balance of black and white modules
477
+ var black = 0;
478
+ modules.forEach(function(row) {
479
+ row.forEach(function(color) {
480
+ if (color)
481
+ black++;
482
+ });
483
+ });
484
+ var total = size * size; // Note that size is odd, so black/total != 1/2
485
+ // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)%
486
+ var k = Math.ceil(Math.abs(black * 20 - total * 10) / total) - 1;
487
+ result += k * QrCode.PENALTY_N4;
488
+ return result;
489
+ }
490
+
491
+
492
+ // Returns an ascending list of positions of alignment patterns for this version number.
493
+ // Each position is in the range [0,177), and are used on both the x and y axes.
494
+ // This could be implemented as lookup table of 40 variable-length lists of integers.
495
+ function getAlignmentPatternPositions() {
496
+ if (version == 1)
497
+ return [];
498
+ else {
499
+ var numAlign = Math.floor(version / 7) + 2;
500
+ var step = (version == 32) ? 26 :
501
+ Math.ceil((size - 13) / (numAlign*2 - 2)) * 2;
502
+ var result = [6];
503
+ for (var pos = size - 7; result.length < numAlign; pos -= step)
504
+ result.splice(1, 0, pos);
505
+ return result;
506
+ }
507
+ }
508
+
509
+
510
+ // Returns true iff the i'th bit of x is set to 1.
511
+ function getBit(x, i) {
512
+ return ((x >>> i) & 1) != 0;
513
+ }
514
+ };
515
+
516
+
517
+ /*---- Static factory functions (high level) for QrCode ----*/
518
+
519
+ /*
520
+ * Returns a QR Code representing the given Unicode text string at the given error correction level.
521
+ * As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
522
+ * Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
523
+ * QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
524
+ * ecl argument if it can be done without increasing the version.
525
+ */
526
+ this.QrCode.encodeText = function(text, ecl) {
527
+ var segs = qrcodegen.QrSegment.makeSegments(text);
528
+ return this.encodeSegments(segs, ecl);
529
+ };
530
+
531
+
532
+ /*
533
+ * Returns a QR Code representing the given binary data at the given error correction level.
534
+ * This function always encodes using the binary segment mode, not any text mode. The maximum number of
535
+ * bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
536
+ * The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
537
+ */
538
+ this.QrCode.encodeBinary = function(data, ecl) {
539
+ var seg = qrcodegen.QrSegment.makeBytes(data);
540
+ return this.encodeSegments([seg], ecl);
541
+ };
542
+
543
+
544
+ /*---- Static factory functions (mid level) for QrCode ----*/
545
+
546
+ /*
547
+ * Returns a QR Code representing the given segments with the given encoding parameters.
548
+ * The smallest possible QR Code version within the given range is automatically
549
+ * chosen for the output. Iff boostEcl is true, then the ECC level of the result
550
+ * may be higher than the ecl argument if it can be done without increasing the
551
+ * version. The mask number is either between 0 to 7 (inclusive) to force that
552
+ * mask, or -1 to automatically choose an appropriate mask (which may be slow).
553
+ * This function allows the user to create a custom sequence of segments that switches
554
+ * between modes (such as alphanumeric and byte) to encode text in less space.
555
+ * This is a mid-level API; the high-level API is encodeText() and encodeBinary().
556
+ */
557
+ this.QrCode.encodeSegments = function(segs, ecl, minVersion, maxVersion, mask, boostEcl) {
558
+ if (minVersion == undefined) minVersion = MIN_VERSION;
559
+ if (maxVersion == undefined) maxVersion = MAX_VERSION;
560
+ if (mask == undefined) mask = -1;
561
+ if (boostEcl == undefined) boostEcl = true;
562
+ if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7)
563
+ throw "Invalid value";
564
+
565
+ // Find the minimal version number to use
566
+ var version, dataUsedBits;
567
+ for (version = minVersion; ; version++) {
568
+ var dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8; // Number of data bits available
569
+ dataUsedBits = qrcodegen.QrSegment.getTotalBits(segs, version);
570
+ if (dataUsedBits <= dataCapacityBits)
571
+ break; // This version number is found to be suitable
572
+ if (version >= maxVersion) // All versions in the range could not fit the given data
573
+ throw "Data too long";
574
+ }
575
+
576
+ // Increase the error correction level while the data still fits in the current version number
577
+ [this.Ecc.MEDIUM, this.Ecc.QUARTILE, this.Ecc.HIGH].forEach(function(newEcl) { // From low to high
578
+ if (boostEcl && dataUsedBits <= QrCode.getNumDataCodewords(version, newEcl) * 8)
579
+ ecl = newEcl;
580
+ });
581
+
582
+ // Concatenate all segments to create the data bit string
583
+ var bb = new BitBuffer();
584
+ segs.forEach(function(seg) {
585
+ bb.appendBits(seg.mode.modeBits, 4);
586
+ bb.appendBits(seg.numChars, seg.mode.numCharCountBits(version));
587
+ seg.getData().forEach(function(bit) {
588
+ bb.push(bit);
589
+ });
590
+ });
591
+ if (bb.length != dataUsedBits)
592
+ throw "Assertion error";
593
+
594
+ // Add terminator and pad up to a byte if applicable
595
+ var dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8;
596
+ if (bb.length > dataCapacityBits)
597
+ throw "Assertion error";
598
+ bb.appendBits(0, Math.min(4, dataCapacityBits - bb.length));
599
+ bb.appendBits(0, (8 - bb.length % 8) % 8);
600
+ if (bb.length % 8 != 0)
601
+ throw "Assertion error";
602
+
603
+ // Pad with alternating bytes until data capacity is reached
604
+ for (var padByte = 0xEC; bb.length < dataCapacityBits; padByte ^= 0xEC ^ 0x11)
605
+ bb.appendBits(padByte, 8);
606
+
607
+ // Pack bits into bytes in big endian
608
+ var dataCodewords = [];
609
+ while (dataCodewords.length * 8 < bb.length)
610
+ dataCodewords.push(0);
611
+ bb.forEach(function(bit, i) {
612
+ dataCodewords[i >>> 3] |= bit << (7 - (i & 7));
613
+ });
614
+
615
+ // Create the QR Code object
616
+ return new this(version, ecl, dataCodewords, mask);
617
+ };
618
+
619
+
620
+ /*---- Private static helper functions for QrCode ----*/
621
+
622
+ var QrCode = {}; // Private object to assign properties to. Not the same object as 'this.QrCode'.
623
+
624
+
625
+ // Returns the number of data bits that can be stored in a QR Code of the given version number, after
626
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
627
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
628
+ QrCode.getNumRawDataModules = function(ver) {
629
+ if (ver < MIN_VERSION || ver > MAX_VERSION)
630
+ throw "Version number out of range";
631
+ var result = (16 * ver + 128) * ver + 64;
632
+ if (ver >= 2) {
633
+ var numAlign = Math.floor(ver / 7) + 2;
634
+ result -= (25 * numAlign - 10) * numAlign - 55;
635
+ if (ver >= 7)
636
+ result -= 36;
637
+ }
638
+ return result;
639
+ };
640
+
641
+
642
+ // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
643
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
644
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
645
+ QrCode.getNumDataCodewords = function(ver, ecl) {
646
+ return Math.floor(QrCode.getNumRawDataModules(ver) / 8) -
647
+ QrCode.ECC_CODEWORDS_PER_BLOCK [ecl.ordinal][ver] *
648
+ QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
649
+ };
650
+
651
+
652
+ /*---- Constants and tables for QrCode ----*/
653
+
654
+ var MIN_VERSION = 1; // The minimum version number supported in the QR Code Model 2 standard
655
+ var MAX_VERSION = 40; // The maximum version number supported in the QR Code Model 2 standard
656
+ Object.defineProperty(this.QrCode, "MIN_VERSION", {value:MIN_VERSION});
657
+ Object.defineProperty(this.QrCode, "MAX_VERSION", {value:MAX_VERSION});
658
+
659
+ // For use in getPenaltyScore(), when evaluating which mask is best.
660
+ QrCode.PENALTY_N1 = 3;
661
+ QrCode.PENALTY_N2 = 3;
662
+ QrCode.PENALTY_N3 = 40;
663
+ QrCode.PENALTY_N4 = 10;
664
+
665
+ QrCode.ECC_CODEWORDS_PER_BLOCK = [
666
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
667
+ // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
668
+ [null, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Low
669
+ [null, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28], // Medium
670
+ [null, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Quartile
671
+ [null, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // High
672
+ ];
673
+
674
+ QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
675
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
676
+ // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
677
+ [null, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25], // Low
678
+ [null, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49], // Medium
679
+ [null, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68], // Quartile
680
+ [null, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81], // High
681
+ ];
682
+
683
+
684
+ /*---- Public helper enumeration ----*/
685
+
686
+ /*
687
+ * The error correction level in a QR Code symbol. Immutable.
688
+ */
689
+ this.QrCode.Ecc = {
690
+ LOW : new Ecc(0, 1), // The QR Code can tolerate about 7% erroneous codewords
691
+ MEDIUM : new Ecc(1, 0), // The QR Code can tolerate about 15% erroneous codewords
692
+ QUARTILE: new Ecc(2, 3), // The QR Code can tolerate about 25% erroneous codewords
693
+ HIGH : new Ecc(3, 2), // The QR Code can tolerate about 30% erroneous codewords
694
+ };
695
+
696
+
697
+ // Private constructor.
698
+ function Ecc(ord, fb) {
699
+ // (Public) In the range 0 to 3 (unsigned 2-bit integer)
700
+ Object.defineProperty(this, "ordinal", {value:ord});
701
+
702
+ // (Package-private) In the range 0 to 3 (unsigned 2-bit integer)
703
+ Object.defineProperty(this, "formatBits", {value:fb});
704
+ }
705
+
706
+
707
+
708
+ /*---- Data segment class ----*/
709
+
710
+ /*
711
+ * A segment of character/binary/control data in a QR Code symbol.
712
+ * Instances of this class are immutable.
713
+ * The mid-level way to create a segment is to take the payload data
714
+ * and call a static factory function such as QrSegment.makeNumeric().
715
+ * The low-level way to create a segment is to custom-make the bit buffer
716
+ * and call the QrSegment() constructor with appropriate values.
717
+ * This segment class imposes no length restrictions, but QR Codes have restrictions.
718
+ * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
719
+ * Any segment longer than this is meaningless for the purpose of generating QR Codes.
720
+ * This constructor creates a QR Code segment with the given attributes and data.
721
+ * The character count (numChars) must agree with the mode and the bit buffer length,
722
+ * but the constraint isn't checked. The given bit buffer is cloned and stored.
723
+ */
724
+ this.QrSegment = function(mode, numChars, bitData) {
725
+ /*---- Constructor (low level) ----*/
726
+ if (numChars < 0 || !(mode instanceof Mode))
727
+ throw "Invalid argument";
728
+
729
+ // The data bits of this segment. Accessed through getData().
730
+ bitData = bitData.slice(); // Make defensive copy
731
+
732
+ // The mode indicator of this segment.
733
+ Object.defineProperty(this, "mode", {value:mode});
734
+
735
+ // The length of this segment's unencoded data. Measured in characters for
736
+ // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
737
+ // Always zero or positive. Not the same as the data's bit length.
738
+ Object.defineProperty(this, "numChars", {value:numChars});
739
+
740
+ // Returns a new copy of the data bits of this segment.
741
+ this.getData = function() {
742
+ return bitData.slice(); // Make defensive copy
743
+ };
744
+ };
745
+
746
+
747
+ /*---- Static factory functions (mid level) for QrSegment ----*/
748
+
749
+ /*
750
+ * Returns a segment representing the given binary data encoded in
751
+ * byte mode. All input byte arrays are acceptable. Any text string
752
+ * can be converted to UTF-8 bytes and encoded as a byte mode segment.
753
+ */
754
+ this.QrSegment.makeBytes = function(data) {
755
+ var bb = new BitBuffer();
756
+ data.forEach(function(b) {
757
+ bb.appendBits(b, 8);
758
+ });
759
+ return new this(this.Mode.BYTE, data.length, bb);
760
+ };
761
+
762
+
763
+ /*
764
+ * Returns a segment representing the given string of decimal digits encoded in numeric mode.
765
+ */
766
+ this.QrSegment.makeNumeric = function(digits) {
767
+ if (!this.NUMERIC_REGEX.test(digits))
768
+ throw "String contains non-numeric characters";
769
+ var bb = new BitBuffer();
770
+ for (var i = 0; i < digits.length; ) { // Consume up to 3 digits per iteration
771
+ var n = Math.min(digits.length - i, 3);
772
+ bb.appendBits(parseInt(digits.substr(i, n), 10), n * 3 + 1);
773
+ i += n;
774
+ }
775
+ return new this(this.Mode.NUMERIC, digits.length, bb);
776
+ };
777
+
778
+
779
+ /*
780
+ * Returns a segment representing the given text string encoded in alphanumeric mode.
781
+ * The characters allowed are: 0 to 9, A to Z (uppercase only), space,
782
+ * dollar, percent, asterisk, plus, hyphen, period, slash, colon.
783
+ */
784
+ this.QrSegment.makeAlphanumeric = function(text) {
785
+ if (!this.ALPHANUMERIC_REGEX.test(text))
786
+ throw "String contains unencodable characters in alphanumeric mode";
787
+ var bb = new BitBuffer();
788
+ var i;
789
+ for (i = 0; i + 2 <= text.length; i += 2) { // Process groups of 2
790
+ var temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
791
+ temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
792
+ bb.appendBits(temp, 11);
793
+ }
794
+ if (i < text.length) // 1 character remaining
795
+ bb.appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6);
796
+ return new this(this.Mode.ALPHANUMERIC, text.length, bb);
797
+ };
798
+
799
+
800
+ /*
801
+ * Returns a new mutable list of zero or more segments to represent the given Unicode text string.
802
+ * The result may use various segment modes and switch modes to optimize the length of the bit stream.
803
+ */
804
+ this.QrSegment.makeSegments = function(text) {
805
+ // Select the most efficient segment encoding automatically
806
+ if (text == "")
807
+ return [];
808
+ else if (this.NUMERIC_REGEX.test(text))
809
+ return [this.makeNumeric(text)];
810
+ else if (this.ALPHANUMERIC_REGEX.test(text))
811
+ return [this.makeAlphanumeric(text)];
812
+ else
813
+ return [this.makeBytes(toUtf8ByteArray(text))];
814
+ };
815
+
816
+
817
+ /*
818
+ * Returns a segment representing an Extended Channel Interpretation
819
+ * (ECI) designator with the given assignment value.
820
+ */
821
+ this.QrSegment.makeEci = function(assignVal) {
822
+ var bb = new BitBuffer();
823
+ if (assignVal < 0)
824
+ throw "ECI assignment value out of range";
825
+ else if (assignVal < (1 << 7))
826
+ bb.appendBits(assignVal, 8);
827
+ else if (assignVal < (1 << 14)) {
828
+ bb.appendBits(2, 2);
829
+ bb.appendBits(assignVal, 14);
830
+ } else if (assignVal < 1000000) {
831
+ bb.appendBits(6, 3);
832
+ bb.appendBits(assignVal, 21);
833
+ } else
834
+ throw "ECI assignment value out of range";
835
+ return new this(this.Mode.ECI, 0, bb);
836
+ };
837
+
838
+
839
+ // (Package-private) Calculates and returns the number of bits needed to encode the given segments at the
840
+ // given version. The result is infinity if a segment has too many characters to fit its length field.
841
+ this.QrSegment.getTotalBits = function(segs, version) {
842
+ var result = 0;
843
+ for (var i = 0; i < segs.length; i++) {
844
+ var seg = segs[i];
845
+ var ccbits = seg.mode.numCharCountBits(version);
846
+ if (seg.numChars >= (1 << ccbits))
847
+ return Infinity; // The segment's length doesn't fit the field's bit width
848
+ result += 4 + ccbits + seg.getData().length;
849
+ }
850
+ return result;
851
+ };
852
+
853
+
854
+ /*---- Constants for QrSegment ----*/
855
+
856
+ var QrSegment = {}; // Private object to assign properties to. Not the same object as 'this.QrSegment'.
857
+
858
+ // (Public) Describes precisely all strings that are encodable in numeric mode.
859
+ // To test whether a string s is encodable: var ok = NUMERIC_REGEX.test(s);
860
+ // A string is encodable iff each character is in the range 0 to 9.
861
+ this.QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
862
+
863
+ // (Public) Describes precisely all strings that are encodable in alphanumeric mode.
864
+ // To test whether a string s is encodable: var ok = ALPHANUMERIC_REGEX.test(s);
865
+ // A string is encodable iff each character is in the following set: 0 to 9, A to Z
866
+ // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
867
+ this.QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
868
+
869
+ // (Private) The set of all legal characters in alphanumeric mode,
870
+ // where each character value maps to the index in the string.
871
+ QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
872
+
873
+
874
+ /*---- Public helper enumeration ----*/
875
+
876
+ /*
877
+ * Describes how a segment's data bits are interpreted. Immutable.
878
+ */
879
+ this.QrSegment.Mode = { // Constants
880
+ NUMERIC : new Mode(0x1, [10, 12, 14]),
881
+ ALPHANUMERIC: new Mode(0x2, [ 9, 11, 13]),
882
+ BYTE : new Mode(0x4, [ 8, 16, 16]),
883
+ KANJI : new Mode(0x8, [ 8, 10, 12]),
884
+ ECI : new Mode(0x7, [ 0, 0, 0]),
885
+ };
886
+
887
+
888
+ // Private constructor.
889
+ function Mode(mode, ccbits) {
890
+ // (Package-private) The mode indicator bits, which is a uint4 value (range 0 to 15).
891
+ Object.defineProperty(this, "modeBits", {value:mode});
892
+
893
+ // (Package-private) Returns the bit width of the character count field for a segment in
894
+ // this mode in a QR Code at the given version number. The result is in the range [0, 16].
895
+ this.numCharCountBits = function(ver) {
896
+ return ccbits[Math.floor((ver + 7) / 17)];
897
+ };
898
+ }
899
+
900
+
901
+
902
+ /*---- Private helper functions and classes ----*/
903
+
904
+ // Returns a new array of bytes representing the given string encoded in UTF-8.
905
+ function toUtf8ByteArray(str) {
906
+ str = encodeURI(str);
907
+ var result = [];
908
+ for (var i = 0; i < str.length; i++) {
909
+ if (str.charAt(i) != "%")
910
+ result.push(str.charCodeAt(i));
911
+ else {
912
+ result.push(parseInt(str.substr(i + 1, 2), 16));
913
+ i += 2;
914
+ }
915
+ }
916
+ return result;
917
+ }
918
+
919
+
920
+
921
+ /*
922
+ * A private helper class that computes the Reed-Solomon error correction codewords for a sequence of
923
+ * data codewords at a given degree. Objects are immutable, and the state only depends on the degree.
924
+ * This class exists because each data block in a QR Code shares the same the divisor polynomial.
925
+ * This constructor creates a Reed-Solomon ECC generator for the given degree. This could be implemented
926
+ * as a lookup table over all possible parameter values, instead of as an algorithm.
927
+ */
928
+ function ReedSolomonGenerator(degree) {
929
+ if (degree < 1 || degree > 255)
930
+ throw "Degree out of range";
931
+
932
+ // Coefficients of the divisor polynomial, stored from highest to lowest power, excluding the leading term which
933
+ // is always 1. For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array {255, 8, 93}.
934
+ var coefficients = [];
935
+
936
+ // Start with the monomial x^0
937
+ for (var i = 0; i < degree - 1; i++)
938
+ coefficients.push(0);
939
+ coefficients.push(1);
940
+
941
+ // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
942
+ // drop the highest term, and store the rest of the coefficients in order of descending powers.
943
+ // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
944
+ var root = 1;
945
+ for (var i = 0; i < degree; i++) {
946
+ // Multiply the current product by (x - r^i)
947
+ for (var j = 0; j < coefficients.length; j++) {
948
+ coefficients[j] = ReedSolomonGenerator.multiply(coefficients[j], root);
949
+ if (j + 1 < coefficients.length)
950
+ coefficients[j] ^= coefficients[j + 1];
951
+ }
952
+ root = ReedSolomonGenerator.multiply(root, 0x02);
953
+ }
954
+
955
+ // Computes and returns the Reed-Solomon error correction codewords for the given
956
+ // sequence of data codewords. The returned object is always a new byte array.
957
+ // This method does not alter this object's state (because it is immutable).
958
+ this.getRemainder = function(data) {
959
+ // Compute the remainder by performing polynomial division
960
+ var result = coefficients.map(function() { return 0; });
961
+ data.forEach(function(b) {
962
+ var factor = b ^ result.shift();
963
+ result.push(0);
964
+ for (var i = 0; i < result.length; i++)
965
+ result[i] ^= ReedSolomonGenerator.multiply(coefficients[i], factor);
966
+ });
967
+ return result;
968
+ };
969
+ }
970
+
971
+ // This static function returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and
972
+ // result are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
973
+ ReedSolomonGenerator.multiply = function(x, y) {
974
+ if (x >>> 8 != 0 || y >>> 8 != 0)
975
+ throw "Byte out of range";
976
+ // Russian peasant multiplication
977
+ var z = 0;
978
+ for (var i = 7; i >= 0; i--) {
979
+ z = (z << 1) ^ ((z >>> 7) * 0x11D);
980
+ z ^= ((y >>> i) & 1) * x;
981
+ }
982
+ if (z >>> 8 != 0)
983
+ throw "Assertion error";
984
+ return z;
985
+ };
986
+
987
+
988
+
989
+ /*
990
+ * A private helper class that represents an appendable sequence of bits (0s and 1s).
991
+ * Mainly used by QrSegment. This constructor creates an empty bit buffer (length 0).
992
+ */
993
+ function BitBuffer() {
994
+ Array.call(this);
995
+
996
+ // Appends the given number of low-order bits of the given value
997
+ // to this buffer. Requires 0 <= len <= 31 and 0 <= val < 2^len.
998
+ this.appendBits = function(val, len) {
999
+ if (len < 0 || len > 31 || val >>> len != 0)
1000
+ throw "Value out of range";
1001
+ for (var i = len - 1; i >= 0; i--) // Append bit by bit
1002
+ this.push((val >>> i) & 1);
1003
+ };
1004
+ }
1005
+
1006
+ BitBuffer.prototype = Object.create(Array.prototype);
1007
+ BitBuffer.prototype.constructor = BitBuffer;
1008
+
1009
+ };
1010
+
1011
+ var ErrorCorrectionLevel;
1012
+ (function (ErrorCorrectionLevel) {
1013
+ ErrorCorrectionLevel["L"] = "L";
1014
+ ErrorCorrectionLevel["M"] = "M";
1015
+ ErrorCorrectionLevel["Q"] = "Q";
1016
+ ErrorCorrectionLevel["H"] = "H";
1017
+ })(ErrorCorrectionLevel || (ErrorCorrectionLevel = {}));
1018
+ var Environment;
1019
+ (function (Environment) {
1020
+ Environment["production"] = "production";
1021
+ Environment["staging"] = "staging";
1022
+ })(Environment || (Environment = {}));
1023
+ var ThemePreset;
1024
+ (function (ThemePreset) {
1025
+ ThemePreset["light"] = "light";
1026
+ ThemePreset["dark"] = "dark";
1027
+ })(ThemePreset || (ThemePreset = {}));
1028
+
1029
+ const QRC = qrcodegen.QrCode;
1030
+ const QRCode = class {
1031
+ constructor(hostRef) {
1032
+ index.registerInstance(this, hostRef);
1033
+ this.url = undefined;
1034
+ this.level = ErrorCorrectionLevel.M;
1035
+ this.class = '';
1036
+ this.color = 'black';
1037
+ }
1038
+ render() {
1039
+ const getEcc = (ecc) => {
1040
+ ecc = ecc.toUpperCase();
1041
+ if (ecc === 'L')
1042
+ return QRC.Ecc.LOW;
1043
+ if (ecc === 'M')
1044
+ return QRC.Ecc.MEDIUM;
1045
+ if (ecc === 'Q')
1046
+ return QRC.Ecc.QUARTILE;
1047
+ return QRC.Ecc.HIGH;
1048
+ };
1049
+ const ecc = getEcc(this.level);
1050
+ const qr = QRC.encodeText(this.url, ecc);
1051
+ const qrcode = qr.svgObject();
1052
+ return (index.h("svg", { class: this.class, viewBox: `0 0 ${qrcode.size} ${qrcode.size}` }, index.h("path", { d: qrcode.path, fill: this.color })));
1053
+ }
1054
+ };
1055
+
1056
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
1057
+
1058
+ function createCommonjsModule(fn, basedir, module) {
1059
+ return module = {
1060
+ path: basedir,
1061
+ exports: {},
1062
+ require: function (path, base) {
1063
+ return commonjsRequire();
1064
+ }
1065
+ }, fn(module, module.exports), module.exports;
1066
+ }
1067
+
1068
+ function commonjsRequire () {
1069
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
1070
+ }
1071
+
1072
+ var uaParser = createCommonjsModule(function (module, exports) {
1073
+ /////////////////////////////////////////////////////////////////////////////////
1074
+ /* UAParser.js v1.0.35
1075
+ Copyright © 2012-2021 Faisal Salman <f@faisalman.com>
1076
+ MIT License *//*
1077
+ Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data.
1078
+ Supports browser & node.js environment.
1079
+ Demo : https://faisalman.github.io/ua-parser-js
1080
+ Source : https://github.com/faisalman/ua-parser-js */
1081
+ /////////////////////////////////////////////////////////////////////////////////
1082
+
1083
+ (function (window, undefined$1) {
1084
+
1085
+ //////////////
1086
+ // Constants
1087
+ /////////////
1088
+
1089
+
1090
+ var LIBVERSION = '1.0.35',
1091
+ EMPTY = '',
1092
+ UNKNOWN = '?',
1093
+ FUNC_TYPE = 'function',
1094
+ UNDEF_TYPE = 'undefined',
1095
+ OBJ_TYPE = 'object',
1096
+ STR_TYPE = 'string',
1097
+ MAJOR = 'major',
1098
+ MODEL = 'model',
1099
+ NAME = 'name',
1100
+ TYPE = 'type',
1101
+ VENDOR = 'vendor',
1102
+ VERSION = 'version',
1103
+ ARCHITECTURE= 'architecture',
1104
+ CONSOLE = 'console',
1105
+ MOBILE = 'mobile',
1106
+ TABLET = 'tablet',
1107
+ SMARTTV = 'smarttv',
1108
+ WEARABLE = 'wearable',
1109
+ EMBEDDED = 'embedded',
1110
+ UA_MAX_LENGTH = 350;
1111
+
1112
+ var AMAZON = 'Amazon',
1113
+ APPLE = 'Apple',
1114
+ ASUS = 'ASUS',
1115
+ BLACKBERRY = 'BlackBerry',
1116
+ BROWSER = 'Browser',
1117
+ CHROME = 'Chrome',
1118
+ EDGE = 'Edge',
1119
+ FIREFOX = 'Firefox',
1120
+ GOOGLE = 'Google',
1121
+ HUAWEI = 'Huawei',
1122
+ LG = 'LG',
1123
+ MICROSOFT = 'Microsoft',
1124
+ MOTOROLA = 'Motorola',
1125
+ OPERA = 'Opera',
1126
+ SAMSUNG = 'Samsung',
1127
+ SHARP = 'Sharp',
1128
+ SONY = 'Sony',
1129
+ XIAOMI = 'Xiaomi',
1130
+ ZEBRA = 'Zebra',
1131
+ FACEBOOK = 'Facebook',
1132
+ CHROMIUM_OS = 'Chromium OS',
1133
+ MAC_OS = 'Mac OS';
1134
+
1135
+ ///////////
1136
+ // Helper
1137
+ //////////
1138
+
1139
+ var extend = function (regexes, extensions) {
1140
+ var mergedRegexes = {};
1141
+ for (var i in regexes) {
1142
+ if (extensions[i] && extensions[i].length % 2 === 0) {
1143
+ mergedRegexes[i] = extensions[i].concat(regexes[i]);
1144
+ } else {
1145
+ mergedRegexes[i] = regexes[i];
1146
+ }
1147
+ }
1148
+ return mergedRegexes;
1149
+ },
1150
+ enumerize = function (arr) {
1151
+ var enums = {};
1152
+ for (var i=0; i<arr.length; i++) {
1153
+ enums[arr[i].toUpperCase()] = arr[i];
1154
+ }
1155
+ return enums;
1156
+ },
1157
+ has = function (str1, str2) {
1158
+ return typeof str1 === STR_TYPE ? lowerize(str2).indexOf(lowerize(str1)) !== -1 : false;
1159
+ },
1160
+ lowerize = function (str) {
1161
+ return str.toLowerCase();
1162
+ },
1163
+ majorize = function (version) {
1164
+ return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g, EMPTY).split('.')[0] : undefined$1;
1165
+ },
1166
+ trim = function (str, len) {
1167
+ if (typeof(str) === STR_TYPE) {
1168
+ str = str.replace(/^\s\s*/, EMPTY);
1169
+ return typeof(len) === UNDEF_TYPE ? str : str.substring(0, UA_MAX_LENGTH);
1170
+ }
1171
+ };
1172
+
1173
+ ///////////////
1174
+ // Map helper
1175
+ //////////////
1176
+
1177
+ var rgxMapper = function (ua, arrays) {
1178
+
1179
+ var i = 0, j, k, p, q, matches, match;
1180
+
1181
+ // loop through all regexes maps
1182
+ while (i < arrays.length && !matches) {
1183
+
1184
+ var regex = arrays[i], // even sequence (0,2,4,..)
1185
+ props = arrays[i + 1]; // odd sequence (1,3,5,..)
1186
+ j = k = 0;
1187
+
1188
+ // try matching uastring with regexes
1189
+ while (j < regex.length && !matches) {
1190
+
1191
+ if (!regex[j]) { break; }
1192
+ matches = regex[j++].exec(ua);
1193
+
1194
+ if (!!matches) {
1195
+ for (p = 0; p < props.length; p++) {
1196
+ match = matches[++k];
1197
+ q = props[p];
1198
+ // check if given property is actually array
1199
+ if (typeof q === OBJ_TYPE && q.length > 0) {
1200
+ if (q.length === 2) {
1201
+ if (typeof q[1] == FUNC_TYPE) {
1202
+ // assign modified match
1203
+ this[q[0]] = q[1].call(this, match);
1204
+ } else {
1205
+ // assign given value, ignore regex match
1206
+ this[q[0]] = q[1];
1207
+ }
1208
+ } else if (q.length === 3) {
1209
+ // check whether function or regex
1210
+ if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
1211
+ // call function (usually string mapper)
1212
+ this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined$1;
1213
+ } else {
1214
+ // sanitize match using given regex
1215
+ this[q[0]] = match ? match.replace(q[1], q[2]) : undefined$1;
1216
+ }
1217
+ } else if (q.length === 4) {
1218
+ this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined$1;
1219
+ }
1220
+ } else {
1221
+ this[q] = match ? match : undefined$1;
1222
+ }
1223
+ }
1224
+ }
1225
+ }
1226
+ i += 2;
1227
+ }
1228
+ },
1229
+
1230
+ strMapper = function (str, map) {
1231
+
1232
+ for (var i in map) {
1233
+ // check if current value is array
1234
+ if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
1235
+ for (var j = 0; j < map[i].length; j++) {
1236
+ if (has(map[i][j], str)) {
1237
+ return (i === UNKNOWN) ? undefined$1 : i;
1238
+ }
1239
+ }
1240
+ } else if (has(map[i], str)) {
1241
+ return (i === UNKNOWN) ? undefined$1 : i;
1242
+ }
1243
+ }
1244
+ return str;
1245
+ };
1246
+
1247
+ ///////////////
1248
+ // String map
1249
+ //////////////
1250
+
1251
+ // Safari < 3.0
1252
+ var oldSafariMap = {
1253
+ '1.0' : '/8',
1254
+ '1.2' : '/1',
1255
+ '1.3' : '/3',
1256
+ '2.0' : '/412',
1257
+ '2.0.2' : '/416',
1258
+ '2.0.3' : '/417',
1259
+ '2.0.4' : '/419',
1260
+ '?' : '/'
1261
+ },
1262
+ windowsVersionMap = {
1263
+ 'ME' : '4.90',
1264
+ 'NT 3.11' : 'NT3.51',
1265
+ 'NT 4.0' : 'NT4.0',
1266
+ '2000' : 'NT 5.0',
1267
+ 'XP' : ['NT 5.1', 'NT 5.2'],
1268
+ 'Vista' : 'NT 6.0',
1269
+ '7' : 'NT 6.1',
1270
+ '8' : 'NT 6.2',
1271
+ '8.1' : 'NT 6.3',
1272
+ '10' : ['NT 6.4', 'NT 10.0'],
1273
+ 'RT' : 'ARM'
1274
+ };
1275
+
1276
+ //////////////
1277
+ // Regex map
1278
+ /////////////
1279
+
1280
+ var regexes = {
1281
+
1282
+ browser : [[
1283
+
1284
+ /\b(?:crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
1285
+ ], [VERSION, [NAME, 'Chrome']], [
1286
+ /edg(?:e|ios|a)?\/([\w\.]+)/i // Microsoft Edge
1287
+ ], [VERSION, [NAME, 'Edge']], [
1288
+
1289
+ // Presto based
1290
+ /(opera mini)\/([-\w\.]+)/i, // Opera Mini
1291
+ /(opera [mobiletab]{3,6})\b.+version\/([-\w\.]+)/i, // Opera Mobi/Tablet
1292
+ /(opera)(?:.+version\/|[\/ ]+)([\w\.]+)/i // Opera
1293
+ ], [NAME, VERSION], [
1294
+ /opios[\/ ]+([\w\.]+)/i // Opera mini on iphone >= 8.0
1295
+ ], [VERSION, [NAME, OPERA+' Mini']], [
1296
+ /\bopr\/([\w\.]+)/i // Opera Webkit
1297
+ ], [VERSION, [NAME, OPERA]], [
1298
+
1299
+ // Mixed
1300
+ /(kindle)\/([\w\.]+)/i, // Kindle
1301
+ /(lunascape|maxthon|netfront|jasmine|blazer)[\/ ]?([\w\.]*)/i, // Lunascape/Maxthon/Netfront/Jasmine/Blazer
1302
+ // Trident based
1303
+ /(avant |iemobile|slim)(?:browser)?[\/ ]?([\w\.]*)/i, // Avant/IEMobile/SlimBrowser
1304
+ /(ba?idubrowser)[\/ ]?([\w\.]+)/i, // Baidu Browser
1305
+ /(?:ms|\()(ie) ([\w\.]+)/i, // Internet Explorer
1306
+
1307
+ // Webkit/KHTML based // Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
1308
+ /(flock|rockmelt|midori|epiphany|silk|skyfire|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon|rekonq|puffin|brave|whale(?!.+naver)|qqbrowserlite|qq|duckduckgo)\/([-\w\.]+)/i,
1309
+ // Rekonq/Puffin/Brave/Whale/QQBrowserLite/QQ, aka ShouQ
1310
+ /(heytap|ovi)browser\/([\d\.]+)/i, // Heytap/Ovi
1311
+ /(weibo)__([\d\.]+)/i // Weibo
1312
+ ], [NAME, VERSION], [
1313
+ /(?:\buc? ?browser|(?:juc.+)ucweb)[\/ ]?([\w\.]+)/i // UCBrowser
1314
+ ], [VERSION, [NAME, 'UC'+BROWSER]], [
1315
+ /microm.+\bqbcore\/([\w\.]+)/i, // WeChat Desktop for Windows Built-in Browser
1316
+ /\bqbcore\/([\w\.]+).+microm/i
1317
+ ], [VERSION, [NAME, 'WeChat(Win) Desktop']], [
1318
+ /micromessenger\/([\w\.]+)/i // WeChat
1319
+ ], [VERSION, [NAME, 'WeChat']], [
1320
+ /konqueror\/([\w\.]+)/i // Konqueror
1321
+ ], [VERSION, [NAME, 'Konqueror']], [
1322
+ /trident.+rv[: ]([\w\.]{1,9})\b.+like gecko/i // IE11
1323
+ ], [VERSION, [NAME, 'IE']], [
1324
+ /ya(?:search)?browser\/([\w\.]+)/i // Yandex
1325
+ ], [VERSION, [NAME, 'Yandex']], [
1326
+ /(avast|avg)\/([\w\.]+)/i // Avast/AVG Secure Browser
1327
+ ], [[NAME, /(.+)/, '$1 Secure '+BROWSER], VERSION], [
1328
+ /\bfocus\/([\w\.]+)/i // Firefox Focus
1329
+ ], [VERSION, [NAME, FIREFOX+' Focus']], [
1330
+ /\bopt\/([\w\.]+)/i // Opera Touch
1331
+ ], [VERSION, [NAME, OPERA+' Touch']], [
1332
+ /coc_coc\w+\/([\w\.]+)/i // Coc Coc Browser
1333
+ ], [VERSION, [NAME, 'Coc Coc']], [
1334
+ /dolfin\/([\w\.]+)/i // Dolphin
1335
+ ], [VERSION, [NAME, 'Dolphin']], [
1336
+ /coast\/([\w\.]+)/i // Opera Coast
1337
+ ], [VERSION, [NAME, OPERA+' Coast']], [
1338
+ /miuibrowser\/([\w\.]+)/i // MIUI Browser
1339
+ ], [VERSION, [NAME, 'MIUI '+BROWSER]], [
1340
+ /fxios\/([-\w\.]+)/i // Firefox for iOS
1341
+ ], [VERSION, [NAME, FIREFOX]], [
1342
+ /\bqihu|(qi?ho?o?|360)browser/i // 360
1343
+ ], [[NAME, '360 '+BROWSER]], [
1344
+ /(oculus|samsung|sailfish|huawei)browser\/([\w\.]+)/i
1345
+ ], [[NAME, /(.+)/, '$1 '+BROWSER], VERSION], [ // Oculus/Samsung/Sailfish/Huawei Browser
1346
+ /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
1347
+ ], [[NAME, /_/g, ' '], VERSION], [
1348
+ /(electron)\/([\w\.]+) safari/i, // Electron-based App
1349
+ /(tesla)(?: qtcarbrowser|\/(20\d\d\.[-\w\.]+))/i, // Tesla
1350
+ /m?(qqbrowser|baiduboxapp|2345Explorer)[\/ ]?([\w\.]+)/i // QQBrowser/Baidu App/2345 Browser
1351
+ ], [NAME, VERSION], [
1352
+ /(metasr)[\/ ]?([\w\.]+)/i, // SouGouBrowser
1353
+ /(lbbrowser)/i, // LieBao Browser
1354
+ /\[(linkedin)app\]/i // LinkedIn App for iOS & Android
1355
+ ], [NAME], [
1356
+
1357
+ // WebView
1358
+ /((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i // Facebook App for iOS & Android
1359
+ ], [[NAME, FACEBOOK], VERSION], [
1360
+ /(kakao(?:talk|story))[\/ ]([\w\.]+)/i, // Kakao App
1361
+ /(naver)\(.*?(\d+\.[\w\.]+).*\)/i, // Naver InApp
1362
+ /safari (line)\/([\w\.]+)/i, // Line App for iOS
1363
+ /\b(line)\/([\w\.]+)\/iab/i, // Line App for Android
1364
+ /(chromium|instagram)[\/ ]([-\w\.]+)/i // Chromium/Instagram
1365
+ ], [NAME, VERSION], [
1366
+ /\bgsa\/([\w\.]+) .*safari\//i // Google Search Appliance on iOS
1367
+ ], [VERSION, [NAME, 'GSA']], [
1368
+ /musical_ly(?:.+app_?version\/|_)([\w\.]+)/i // TikTok
1369
+ ], [VERSION, [NAME, 'TikTok']], [
1370
+
1371
+ /headlesschrome(?:\/([\w\.]+)| )/i // Chrome Headless
1372
+ ], [VERSION, [NAME, CHROME+' Headless']], [
1373
+
1374
+ / wv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
1375
+ ], [[NAME, CHROME+' WebView'], VERSION], [
1376
+
1377
+ /droid.+ version\/([\w\.]+)\b.+(?:mobile safari|safari)/i // Android Browser
1378
+ ], [VERSION, [NAME, 'Android '+BROWSER]], [
1379
+
1380
+ /(chrome|omniweb|arora|[tizenoka]{5} ?browser)\/v?([\w\.]+)/i // Chrome/OmniWeb/Arora/Tizen/Nokia
1381
+ ], [NAME, VERSION], [
1382
+
1383
+ /version\/([\w\.\,]+) .*mobile\/\w+ (safari)/i // Mobile Safari
1384
+ ], [VERSION, [NAME, 'Mobile Safari']], [
1385
+ /version\/([\w(\.|\,)]+) .*(mobile ?safari|safari)/i // Safari & Safari Mobile
1386
+ ], [VERSION, NAME], [
1387
+ /webkit.+?(mobile ?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
1388
+ ], [NAME, [VERSION, strMapper, oldSafariMap]], [
1389
+
1390
+ /(webkit|khtml)\/([\w\.]+)/i
1391
+ ], [NAME, VERSION], [
1392
+
1393
+ // Gecko based
1394
+ /(navigator|netscape\d?)\/([-\w\.]+)/i // Netscape
1395
+ ], [[NAME, 'Netscape'], VERSION], [
1396
+ /mobile vr; rv:([\w\.]+)\).+firefox/i // Firefox Reality
1397
+ ], [VERSION, [NAME, FIREFOX+' Reality']], [
1398
+ /ekiohf.+(flow)\/([\w\.]+)/i, // Flow
1399
+ /(swiftfox)/i, // Swiftfox
1400
+ /(icedragon|iceweasel|camino|chimera|fennec|maemo browser|minimo|conkeror|klar)[\/ ]?([\w\.\+]+)/i,
1401
+ // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror/Klar
1402
+ /(seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([-\w\.]+)$/i,
1403
+ // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
1404
+ /(firefox)\/([\w\.]+)/i, // Other Firefox-based
1405
+ /(mozilla)\/([\w\.]+) .+rv\:.+gecko\/\d+/i, // Mozilla
1406
+
1407
+ // Other
1408
+ /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir|obigo|mosaic|(?:go|ice|up)[\. ]?browser)[-\/ ]?v?([\w\.]+)/i,
1409
+ // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir/Obigo/Mosaic/Go/ICE/UP.Browser
1410
+ /(links) \(([\w\.]+)/i, // Links
1411
+ /panasonic;(viera)/i // Panasonic Viera
1412
+ ], [NAME, VERSION], [
1413
+
1414
+ /(cobalt)\/([\w\.]+)/i // Cobalt
1415
+ ], [NAME, [VERSION, /master.|lts./, ""]]
1416
+ ],
1417
+
1418
+ cpu : [[
1419
+
1420
+ /(?:(amd|x(?:(?:86|64)[-_])?|wow|win)64)[;\)]/i // AMD64 (x64)
1421
+ ], [[ARCHITECTURE, 'amd64']], [
1422
+
1423
+ /(ia32(?=;))/i // IA32 (quicktime)
1424
+ ], [[ARCHITECTURE, lowerize]], [
1425
+
1426
+ /((?:i[346]|x)86)[;\)]/i // IA32 (x86)
1427
+ ], [[ARCHITECTURE, 'ia32']], [
1428
+
1429
+ /\b(aarch64|arm(v?8e?l?|_?64))\b/i // ARM64
1430
+ ], [[ARCHITECTURE, 'arm64']], [
1431
+
1432
+ /\b(arm(?:v[67])?ht?n?[fl]p?)\b/i // ARMHF
1433
+ ], [[ARCHITECTURE, 'armhf']], [
1434
+
1435
+ // PocketPC mistakenly identified as PowerPC
1436
+ /windows (ce|mobile); ppc;/i
1437
+ ], [[ARCHITECTURE, 'arm']], [
1438
+
1439
+ /((?:ppc|powerpc)(?:64)?)(?: mac|;|\))/i // PowerPC
1440
+ ], [[ARCHITECTURE, /ower/, EMPTY, lowerize]], [
1441
+
1442
+ /(sun4\w)[;\)]/i // SPARC
1443
+ ], [[ARCHITECTURE, 'sparc']], [
1444
+
1445
+ /((?:avr32|ia64(?=;))|68k(?=\))|\barm(?=v(?:[1-7]|[5-7]1)l?|;|eabi)|(?=atmel )avr|(?:irix|mips|sparc)(?:64)?\b|pa-risc)/i
1446
+ // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
1447
+ ], [[ARCHITECTURE, lowerize]]
1448
+ ],
1449
+
1450
+ device : [[
1451
+
1452
+ //////////////////////////
1453
+ // MOBILES & TABLETS
1454
+ /////////////////////////
1455
+
1456
+ // Samsung
1457
+ /\b(sch-i[89]0\d|shw-m380s|sm-[ptx]\w{2,4}|gt-[pn]\d{2,4}|sgh-t8[56]9|nexus 10)/i
1458
+ ], [MODEL, [VENDOR, SAMSUNG], [TYPE, TABLET]], [
1459
+ /\b((?:s[cgp]h|gt|sm)-\w+|sc[g-]?[\d]+a?|galaxy nexus)/i,
1460
+ /samsung[- ]([-\w]+)/i,
1461
+ /sec-(sgh\w+)/i
1462
+ ], [MODEL, [VENDOR, SAMSUNG], [TYPE, MOBILE]], [
1463
+
1464
+ // Apple
1465
+ /(?:\/|\()(ip(?:hone|od)[\w, ]*)(?:\/|;)/i // iPod/iPhone
1466
+ ], [MODEL, [VENDOR, APPLE], [TYPE, MOBILE]], [
1467
+ /\((ipad);[-\w\),; ]+apple/i, // iPad
1468
+ /applecoremedia\/[\w\.]+ \((ipad)/i,
1469
+ /\b(ipad)\d\d?,\d\d?[;\]].+ios/i
1470
+ ], [MODEL, [VENDOR, APPLE], [TYPE, TABLET]], [
1471
+ /(macintosh);/i
1472
+ ], [MODEL, [VENDOR, APPLE]], [
1473
+
1474
+ // Sharp
1475
+ /\b(sh-?[altvz]?\d\d[a-ekm]?)/i
1476
+ ], [MODEL, [VENDOR, SHARP], [TYPE, MOBILE]], [
1477
+
1478
+ // Huawei
1479
+ /\b((?:ag[rs][23]?|bah2?|sht?|btv)-a?[lw]\d{2})\b(?!.+d\/s)/i
1480
+ ], [MODEL, [VENDOR, HUAWEI], [TYPE, TABLET]], [
1481
+ /(?:huawei|honor)([-\w ]+)[;\)]/i,
1482
+ /\b(nexus 6p|\w{2,4}e?-[atu]?[ln][\dx][012359c][adn]?)\b(?!.+d\/s)/i
1483
+ ], [MODEL, [VENDOR, HUAWEI], [TYPE, MOBILE]], [
1484
+
1485
+ // Xiaomi
1486
+ /\b(poco[\w ]+)(?: bui|\))/i, // Xiaomi POCO
1487
+ /\b; (\w+) build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
1488
+ /\b(hm[-_ ]?note?[_ ]?(?:\d\w)?) bui/i, // Xiaomi Hongmi
1489
+ /\b(redmi[\-_ ]?(?:note|k)?[\w_ ]+)(?: bui|\))/i, // Xiaomi Redmi
1490
+ /\b(mi[-_ ]?(?:a\d|one|one[_ ]plus|note lte|max|cc)?[_ ]?(?:\d?\w?)[_ ]?(?:plus|se|lite)?)(?: bui|\))/i // Xiaomi Mi
1491
+ ], [[MODEL, /_/g, ' '], [VENDOR, XIAOMI], [TYPE, MOBILE]], [
1492
+ /\b(mi[-_ ]?(?:pad)(?:[\w_ ]+))(?: bui|\))/i // Mi Pad tablets
1493
+ ],[[MODEL, /_/g, ' '], [VENDOR, XIAOMI], [TYPE, TABLET]], [
1494
+
1495
+ // OPPO
1496
+ /; (\w+) bui.+ oppo/i,
1497
+ /\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007|a101op)\b/i
1498
+ ], [MODEL, [VENDOR, 'OPPO'], [TYPE, MOBILE]], [
1499
+
1500
+ // Vivo
1501
+ /vivo (\w+)(?: bui|\))/i,
1502
+ /\b(v[12]\d{3}\w?[at])(?: bui|;)/i
1503
+ ], [MODEL, [VENDOR, 'Vivo'], [TYPE, MOBILE]], [
1504
+
1505
+ // Realme
1506
+ /\b(rmx[12]\d{3})(?: bui|;|\))/i
1507
+ ], [MODEL, [VENDOR, 'Realme'], [TYPE, MOBILE]], [
1508
+
1509
+ // Motorola
1510
+ /\b(milestone|droid(?:[2-4x]| (?:bionic|x2|pro|razr))?:?( 4g)?)\b[\w ]+build\//i,
1511
+ /\bmot(?:orola)?[- ](\w*)/i,
1512
+ /((?:moto[\w\(\) ]+|xt\d{3,4}|nexus 6)(?= bui|\)))/i
1513
+ ], [MODEL, [VENDOR, MOTOROLA], [TYPE, MOBILE]], [
1514
+ /\b(mz60\d|xoom[2 ]{0,2}) build\//i
1515
+ ], [MODEL, [VENDOR, MOTOROLA], [TYPE, TABLET]], [
1516
+
1517
+ // LG
1518
+ /((?=lg)?[vl]k\-?\d{3}) bui| 3\.[-\w; ]{10}lg?-([06cv9]{3,4})/i
1519
+ ], [MODEL, [VENDOR, LG], [TYPE, TABLET]], [
1520
+ /(lm(?:-?f100[nv]?|-[\w\.]+)(?= bui|\))|nexus [45])/i,
1521
+ /\blg[-e;\/ ]+((?!browser|netcast|android tv)\w+)/i,
1522
+ /\blg-?([\d\w]+) bui/i
1523
+ ], [MODEL, [VENDOR, LG], [TYPE, MOBILE]], [
1524
+
1525
+ // Lenovo
1526
+ /(ideatab[-\w ]+)/i,
1527
+ /lenovo ?(s[56]000[-\w]+|tab(?:[\w ]+)|yt[-\d\w]{6}|tb[-\d\w]{6})/i
1528
+ ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
1529
+
1530
+ // Nokia
1531
+ /(?:maemo|nokia).*(n900|lumia \d+)/i,
1532
+ /nokia[-_ ]?([-\w\.]*)/i
1533
+ ], [[MODEL, /_/g, ' '], [VENDOR, 'Nokia'], [TYPE, MOBILE]], [
1534
+
1535
+ // Google
1536
+ /(pixel c)\b/i // Google Pixel C
1537
+ ], [MODEL, [VENDOR, GOOGLE], [TYPE, TABLET]], [
1538
+ /droid.+; (pixel[\daxl ]{0,6})(?: bui|\))/i // Google Pixel
1539
+ ], [MODEL, [VENDOR, GOOGLE], [TYPE, MOBILE]], [
1540
+
1541
+ // Sony
1542
+ /droid.+ (a?\d[0-2]{2}so|[c-g]\d{4}|so[-gl]\w+|xq-a\w[4-7][12])(?= bui|\).+chrome\/(?![1-6]{0,1}\d\.))/i
1543
+ ], [MODEL, [VENDOR, SONY], [TYPE, MOBILE]], [
1544
+ /sony tablet [ps]/i,
1545
+ /\b(?:sony)?sgp\w+(?: bui|\))/i
1546
+ ], [[MODEL, 'Xperia Tablet'], [VENDOR, SONY], [TYPE, TABLET]], [
1547
+
1548
+ // OnePlus
1549
+ / (kb2005|in20[12]5|be20[12][59])\b/i,
1550
+ /(?:one)?(?:plus)? (a\d0\d\d)(?: b|\))/i
1551
+ ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
1552
+
1553
+ // Amazon
1554
+ /(alexa)webm/i,
1555
+ /(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i, // Kindle Fire without Silk / Echo Show
1556
+ /(kf[a-z]+)( bui|\)).+silk\//i // Kindle Fire HD
1557
+ ], [MODEL, [VENDOR, AMAZON], [TYPE, TABLET]], [
1558
+ /((?:sd|kf)[0349hijorstuw]+)( bui|\)).+silk\//i // Fire Phone
1559
+ ], [[MODEL, /(.+)/g, 'Fire Phone $1'], [VENDOR, AMAZON], [TYPE, MOBILE]], [
1560
+
1561
+ // BlackBerry
1562
+ /(playbook);[-\w\),; ]+(rim)/i // BlackBerry PlayBook
1563
+ ], [MODEL, VENDOR, [TYPE, TABLET]], [
1564
+ /\b((?:bb[a-f]|st[hv])100-\d)/i,
1565
+ /\(bb10; (\w+)/i // BlackBerry 10
1566
+ ], [MODEL, [VENDOR, BLACKBERRY], [TYPE, MOBILE]], [
1567
+
1568
+ // Asus
1569
+ /(?:\b|asus_)(transfo[prime ]{4,10} \w+|eeepc|slider \w+|nexus 7|padfone|p00[cj])/i
1570
+ ], [MODEL, [VENDOR, ASUS], [TYPE, TABLET]], [
1571
+ / (z[bes]6[027][012][km][ls]|zenfone \d\w?)\b/i
1572
+ ], [MODEL, [VENDOR, ASUS], [TYPE, MOBILE]], [
1573
+
1574
+ // HTC
1575
+ /(nexus 9)/i // HTC Nexus 9
1576
+ ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
1577
+ /(htc)[-;_ ]{1,2}([\w ]+(?=\)| bui)|\w+)/i, // HTC
1578
+
1579
+ // ZTE
1580
+ /(zte)[- ]([\w ]+?)(?: bui|\/|\))/i,
1581
+ /(alcatel|geeksphone|nexian|panasonic(?!(?:;|\.))|sony(?!-bra))[-_ ]?([-\w]*)/i // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
1582
+ ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
1583
+
1584
+ // Acer
1585
+ /droid.+; ([ab][1-7]-?[0178a]\d\d?)/i
1586
+ ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
1587
+
1588
+ // Meizu
1589
+ /droid.+; (m[1-5] note) bui/i,
1590
+ /\bmz-([-\w]{2,})/i
1591
+ ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [
1592
+
1593
+ // MIXED
1594
+ /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[-_ ]?([-\w]*)/i,
1595
+ // BlackBerry/BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
1596
+ /(hp) ([\w ]+\w)/i, // HP iPAQ
1597
+ /(asus)-?(\w+)/i, // Asus
1598
+ /(microsoft); (lumia[\w ]+)/i, // Microsoft Lumia
1599
+ /(lenovo)[-_ ]?([-\w]+)/i, // Lenovo
1600
+ /(jolla)/i, // Jolla
1601
+ /(oppo) ?([\w ]+) bui/i // OPPO
1602
+ ], [VENDOR, MODEL, [TYPE, MOBILE]], [
1603
+
1604
+ /(kobo)\s(ereader|touch)/i, // Kobo
1605
+ /(archos) (gamepad2?)/i, // Archos
1606
+ /(hp).+(touchpad(?!.+tablet)|tablet)/i, // HP TouchPad
1607
+ /(kindle)\/([\w\.]+)/i, // Kindle
1608
+ /(nook)[\w ]+build\/(\w+)/i, // Nook
1609
+ /(dell) (strea[kpr\d ]*[\dko])/i, // Dell Streak
1610
+ /(le[- ]+pan)[- ]+(\w{1,9}) bui/i, // Le Pan Tablets
1611
+ /(trinity)[- ]*(t\d{3}) bui/i, // Trinity Tablets
1612
+ /(gigaset)[- ]+(q\w{1,9}) bui/i, // Gigaset Tablets
1613
+ /(vodafone) ([\w ]+)(?:\)| bui)/i // Vodafone
1614
+ ], [VENDOR, MODEL, [TYPE, TABLET]], [
1615
+
1616
+ /(surface duo)/i // Surface Duo
1617
+ ], [MODEL, [VENDOR, MICROSOFT], [TYPE, TABLET]], [
1618
+ /droid [\d\.]+; (fp\du?)(?: b|\))/i // Fairphone
1619
+ ], [MODEL, [VENDOR, 'Fairphone'], [TYPE, MOBILE]], [
1620
+ /(u304aa)/i // AT&T
1621
+ ], [MODEL, [VENDOR, 'AT&T'], [TYPE, MOBILE]], [
1622
+ /\bsie-(\w*)/i // Siemens
1623
+ ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
1624
+ /\b(rct\w+) b/i // RCA Tablets
1625
+ ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
1626
+ /\b(venue[\d ]{2,7}) b/i // Dell Venue Tablets
1627
+ ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
1628
+ /\b(q(?:mv|ta)\w+) b/i // Verizon Tablet
1629
+ ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
1630
+ /\b(?:barnes[& ]+noble |bn[rt])([\w\+ ]*) b/i // Barnes & Noble Tablet
1631
+ ], [MODEL, [VENDOR, 'Barnes & Noble'], [TYPE, TABLET]], [
1632
+ /\b(tm\d{3}\w+) b/i
1633
+ ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
1634
+ /\b(k88) b/i // ZTE K Series Tablet
1635
+ ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
1636
+ /\b(nx\d{3}j) b/i // ZTE Nubia
1637
+ ], [MODEL, [VENDOR, 'ZTE'], [TYPE, MOBILE]], [
1638
+ /\b(gen\d{3}) b.+49h/i // Swiss GEN Mobile
1639
+ ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
1640
+ /\b(zur\d{3}) b/i // Swiss ZUR Tablet
1641
+ ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
1642
+ /\b((zeki)?tb.*\b) b/i // Zeki Tablets
1643
+ ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
1644
+ /\b([yr]\d{2}) b/i,
1645
+ /\b(dragon[- ]+touch |dt)(\w{5}) b/i // Dragon Touch Tablet
1646
+ ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
1647
+ /\b(ns-?\w{0,9}) b/i // Insignia Tablets
1648
+ ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
1649
+ /\b((nxa|next)-?\w{0,9}) b/i // NextBook Tablets
1650
+ ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
1651
+ /\b(xtreme\_)?(v(1[045]|2[015]|[3469]0|7[05])) b/i // Voice Xtreme Phones
1652
+ ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [
1653
+ /\b(lvtel\-)?(v1[12]) b/i // LvTel Phones
1654
+ ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
1655
+ /\b(ph-1) /i // Essential PH-1
1656
+ ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [
1657
+ /\b(v(100md|700na|7011|917g).*\b) b/i // Envizen Tablets
1658
+ ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
1659
+ /\b(trio[-\w\. ]+) b/i // MachSpeed Tablets
1660
+ ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
1661
+ /\btu_(1491) b/i // Rotor Tablets
1662
+ ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
1663
+ /(shield[\w ]+) b/i // Nvidia Shield Tablets
1664
+ ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, TABLET]], [
1665
+ /(sprint) (\w+)/i // Sprint Phones
1666
+ ], [VENDOR, MODEL, [TYPE, MOBILE]], [
1667
+ /(kin\.[onetw]{3})/i // Microsoft Kin
1668
+ ], [[MODEL, /\./g, ' '], [VENDOR, MICROSOFT], [TYPE, MOBILE]], [
1669
+ /droid.+; (cc6666?|et5[16]|mc[239][23]x?|vc8[03]x?)\)/i // Zebra
1670
+ ], [MODEL, [VENDOR, ZEBRA], [TYPE, TABLET]], [
1671
+ /droid.+; (ec30|ps20|tc[2-8]\d[kx])\)/i
1672
+ ], [MODEL, [VENDOR, ZEBRA], [TYPE, MOBILE]], [
1673
+
1674
+ ///////////////////
1675
+ // SMARTTVS
1676
+ ///////////////////
1677
+
1678
+ /smart-tv.+(samsung)/i // Samsung
1679
+ ], [VENDOR, [TYPE, SMARTTV]], [
1680
+ /hbbtv.+maple;(\d+)/i
1681
+ ], [[MODEL, /^/, 'SmartTV'], [VENDOR, SAMSUNG], [TYPE, SMARTTV]], [
1682
+ /(nux; netcast.+smarttv|lg (netcast\.tv-201\d|android tv))/i // LG SmartTV
1683
+ ], [[VENDOR, LG], [TYPE, SMARTTV]], [
1684
+ /(apple) ?tv/i // Apple TV
1685
+ ], [VENDOR, [MODEL, APPLE+' TV'], [TYPE, SMARTTV]], [
1686
+ /crkey/i // Google Chromecast
1687
+ ], [[MODEL, CHROME+'cast'], [VENDOR, GOOGLE], [TYPE, SMARTTV]], [
1688
+ /droid.+aft(\w)( bui|\))/i // Fire TV
1689
+ ], [MODEL, [VENDOR, AMAZON], [TYPE, SMARTTV]], [
1690
+ /\(dtv[\);].+(aquos)/i,
1691
+ /(aquos-tv[\w ]+)\)/i // Sharp
1692
+ ], [MODEL, [VENDOR, SHARP], [TYPE, SMARTTV]],[
1693
+ /(bravia[\w ]+)( bui|\))/i // Sony
1694
+ ], [MODEL, [VENDOR, SONY], [TYPE, SMARTTV]], [
1695
+ /(mitv-\w{5}) bui/i // Xiaomi
1696
+ ], [MODEL, [VENDOR, XIAOMI], [TYPE, SMARTTV]], [
1697
+ /Hbbtv.*(technisat) (.*);/i // TechniSAT
1698
+ ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
1699
+ /\b(roku)[\dx]*[\)\/]((?:dvp-)?[\d\.]*)/i, // Roku
1700
+ /hbbtv\/\d+\.\d+\.\d+ +\([\w\+ ]*; *([\w\d][^;]*);([^;]*)/i // HbbTV devices
1701
+ ], [[VENDOR, trim], [MODEL, trim], [TYPE, SMARTTV]], [
1702
+ /\b(android tv|smart[- ]?tv|opera tv|tv; rv:)\b/i // SmartTV from Unidentified Vendors
1703
+ ], [[TYPE, SMARTTV]], [
1704
+
1705
+ ///////////////////
1706
+ // CONSOLES
1707
+ ///////////////////
1708
+
1709
+ /(ouya)/i, // Ouya
1710
+ /(nintendo) ([wids3utch]+)/i // Nintendo
1711
+ ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
1712
+ /droid.+; (shield) bui/i // Nvidia
1713
+ ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
1714
+ /(playstation [345portablevi]+)/i // Playstation
1715
+ ], [MODEL, [VENDOR, SONY], [TYPE, CONSOLE]], [
1716
+ /\b(xbox(?: one)?(?!; xbox))[\); ]/i // Microsoft Xbox
1717
+ ], [MODEL, [VENDOR, MICROSOFT], [TYPE, CONSOLE]], [
1718
+
1719
+ ///////////////////
1720
+ // WEARABLES
1721
+ ///////////////////
1722
+
1723
+ /((pebble))app/i // Pebble
1724
+ ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
1725
+ /(watch)(?: ?os[,\/]|\d,\d\/)[\d\.]+/i // Apple Watch
1726
+ ], [MODEL, [VENDOR, APPLE], [TYPE, WEARABLE]], [
1727
+ /droid.+; (glass) \d/i // Google Glass
1728
+ ], [MODEL, [VENDOR, GOOGLE], [TYPE, WEARABLE]], [
1729
+ /droid.+; (wt63?0{2,3})\)/i
1730
+ ], [MODEL, [VENDOR, ZEBRA], [TYPE, WEARABLE]], [
1731
+ /(quest( 2| pro)?)/i // Oculus Quest
1732
+ ], [MODEL, [VENDOR, FACEBOOK], [TYPE, WEARABLE]], [
1733
+
1734
+ ///////////////////
1735
+ // EMBEDDED
1736
+ ///////////////////
1737
+
1738
+ /(tesla)(?: qtcarbrowser|\/[-\w\.]+)/i // Tesla
1739
+ ], [VENDOR, [TYPE, EMBEDDED]], [
1740
+ /(aeobc)\b/i // Echo Dot
1741
+ ], [MODEL, [VENDOR, AMAZON], [TYPE, EMBEDDED]], [
1742
+
1743
+ ////////////////////
1744
+ // MIXED (GENERIC)
1745
+ ///////////////////
1746
+
1747
+ /droid .+?; ([^;]+?)(?: bui|\) applew).+? mobile safari/i // Android Phones from Unidentified Vendors
1748
+ ], [MODEL, [TYPE, MOBILE]], [
1749
+ /droid .+?; ([^;]+?)(?: bui|\) applew).+?(?! mobile) safari/i // Android Tablets from Unidentified Vendors
1750
+ ], [MODEL, [TYPE, TABLET]], [
1751
+ /\b((tablet|tab)[;\/]|focus\/\d(?!.+mobile))/i // Unidentifiable Tablet
1752
+ ], [[TYPE, TABLET]], [
1753
+ /(phone|mobile(?:[;\/]| [ \w\/\.]*safari)|pda(?=.+windows ce))/i // Unidentifiable Mobile
1754
+ ], [[TYPE, MOBILE]], [
1755
+ /(android[-\w\. ]{0,9});.+buil/i // Generic Android Device
1756
+ ], [MODEL, [VENDOR, 'Generic']]
1757
+ ],
1758
+
1759
+ engine : [[
1760
+
1761
+ /windows.+ edge\/([\w\.]+)/i // EdgeHTML
1762
+ ], [VERSION, [NAME, EDGE+'HTML']], [
1763
+
1764
+ /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i // Blink
1765
+ ], [VERSION, [NAME, 'Blink']], [
1766
+
1767
+ /(presto)\/([\w\.]+)/i, // Presto
1768
+ /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i, // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
1769
+ /ekioh(flow)\/([\w\.]+)/i, // Flow
1770
+ /(khtml|tasman|links)[\/ ]\(?([\w\.]+)/i, // KHTML/Tasman/Links
1771
+ /(icab)[\/ ]([23]\.[\d\.]+)/i, // iCab
1772
+ /\b(libweb)/i
1773
+ ], [NAME, VERSION], [
1774
+
1775
+ /rv\:([\w\.]{1,9})\b.+(gecko)/i // Gecko
1776
+ ], [VERSION, NAME]
1777
+ ],
1778
+
1779
+ os : [[
1780
+
1781
+ // Windows
1782
+ /microsoft (windows) (vista|xp)/i // Windows (iTunes)
1783
+ ], [NAME, VERSION], [
1784
+ /(windows) nt 6\.2; (arm)/i, // Windows RT
1785
+ /(windows (?:phone(?: os)?|mobile))[\/ ]?([\d\.\w ]*)/i, // Windows Phone
1786
+ /(windows)[\/ ]?([ntce\d\. ]+\w)(?!.+xbox)/i
1787
+ ], [NAME, [VERSION, strMapper, windowsVersionMap]], [
1788
+ /(win(?=3|9|n)|win 9x )([nt\d\.]+)/i
1789
+ ], [[NAME, 'Windows'], [VERSION, strMapper, windowsVersionMap]], [
1790
+
1791
+ // iOS/macOS
1792
+ /ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/i, // iOS
1793
+ /ios;fbsv\/([\d\.]+)/i,
1794
+ /cfnetwork\/.+darwin/i
1795
+ ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
1796
+ /(mac os x) ?([\w\. ]*)/i,
1797
+ /(macintosh|mac_powerpc\b)(?!.+haiku)/i // Mac OS
1798
+ ], [[NAME, MAC_OS], [VERSION, /_/g, '.']], [
1799
+
1800
+ // Mobile OSes
1801
+ /droid ([\w\.]+)\b.+(android[- ]x86|harmonyos)/i // Android-x86/HarmonyOS
1802
+ ], [VERSION, NAME], [ // Android/WebOS/QNX/Bada/RIM/Maemo/MeeGo/Sailfish OS
1803
+ /(android|webos|qnx|bada|rim tablet os|maemo|meego|sailfish)[-\/ ]?([\w\.]*)/i,
1804
+ /(blackberry)\w*\/([\w\.]*)/i, // Blackberry
1805
+ /(tizen|kaios)[\/ ]([\w\.]+)/i, // Tizen/KaiOS
1806
+ /\((series40);/i // Series 40
1807
+ ], [NAME, VERSION], [
1808
+ /\(bb(10);/i // BlackBerry 10
1809
+ ], [VERSION, [NAME, BLACKBERRY]], [
1810
+ /(?:symbian ?os|symbos|s60(?=;)|series60)[-\/ ]?([\w\.]*)/i // Symbian
1811
+ ], [VERSION, [NAME, 'Symbian']], [
1812
+ /mozilla\/[\d\.]+ \((?:mobile|tablet|tv|mobile; [\w ]+); rv:.+ gecko\/([\w\.]+)/i // Firefox OS
1813
+ ], [VERSION, [NAME, FIREFOX+' OS']], [
1814
+ /web0s;.+rt(tv)/i,
1815
+ /\b(?:hp)?wos(?:browser)?\/([\w\.]+)/i // WebOS
1816
+ ], [VERSION, [NAME, 'webOS']], [
1817
+ /watch(?: ?os[,\/]|\d,\d\/)([\d\.]+)/i // watchOS
1818
+ ], [VERSION, [NAME, 'watchOS']], [
1819
+
1820
+ // Google Chromecast
1821
+ /crkey\/([\d\.]+)/i // Google Chromecast
1822
+ ], [VERSION, [NAME, CHROME+'cast']], [
1823
+ /(cros) [\w]+(?:\)| ([\w\.]+)\b)/i // Chromium OS
1824
+ ], [[NAME, CHROMIUM_OS], VERSION],[
1825
+
1826
+ // Smart TVs
1827
+ /panasonic;(viera)/i, // Panasonic Viera
1828
+ /(netrange)mmh/i, // Netrange
1829
+ /(nettv)\/(\d+\.[\w\.]+)/i, // NetTV
1830
+
1831
+ // Console
1832
+ /(nintendo|playstation) ([wids345portablevuch]+)/i, // Nintendo/Playstation
1833
+ /(xbox); +xbox ([^\);]+)/i, // Microsoft Xbox (360, One, X, S, Series X, Series S)
1834
+
1835
+ // Other
1836
+ /\b(joli|palm)\b ?(?:os)?\/?([\w\.]*)/i, // Joli/Palm
1837
+ /(mint)[\/\(\) ]?(\w*)/i, // Mint
1838
+ /(mageia|vectorlinux)[; ]/i, // Mageia/VectorLinux
1839
+ /([kxln]?ubuntu|debian|suse|opensuse|gentoo|arch(?= linux)|slackware|fedora|mandriva|centos|pclinuxos|red ?hat|zenwalk|linpus|raspbian|plan 9|minix|risc os|contiki|deepin|manjaro|elementary os|sabayon|linspire)(?: gnu\/linux)?(?: enterprise)?(?:[- ]linux)?(?:-gnu)?[-\/ ]?(?!chrom|package)([-\w\.]*)/i,
1840
+ // Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware/Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus/Raspbian/Plan9/Minix/RISCOS/Contiki/Deepin/Manjaro/elementary/Sabayon/Linspire
1841
+ /(hurd|linux) ?([\w\.]*)/i, // Hurd/Linux
1842
+ /(gnu) ?([\w\.]*)/i, // GNU
1843
+ /\b([-frentopcghs]{0,5}bsd|dragonfly)[\/ ]?(?!amd|[ix346]{1,2}86)([\w\.]*)/i, // FreeBSD/NetBSD/OpenBSD/PC-BSD/GhostBSD/DragonFly
1844
+ /(haiku) (\w+)/i // Haiku
1845
+ ], [NAME, VERSION], [
1846
+ /(sunos) ?([\w\.\d]*)/i // Solaris
1847
+ ], [[NAME, 'Solaris'], VERSION], [
1848
+ /((?:open)?solaris)[-\/ ]?([\w\.]*)/i, // Solaris
1849
+ /(aix) ((\d)(?=\.|\)| )[\w\.])*/i, // AIX
1850
+ /\b(beos|os\/2|amigaos|morphos|openvms|fuchsia|hp-ux|serenityos)/i, // BeOS/OS2/AmigaOS/MorphOS/OpenVMS/Fuchsia/HP-UX/SerenityOS
1851
+ /(unix) ?([\w\.]*)/i // UNIX
1852
+ ], [NAME, VERSION]
1853
+ ]
1854
+ };
1855
+
1856
+ /////////////////
1857
+ // Constructor
1858
+ ////////////////
1859
+
1860
+ var UAParser = function (ua, extensions) {
1861
+
1862
+ if (typeof ua === OBJ_TYPE) {
1863
+ extensions = ua;
1864
+ ua = undefined$1;
1865
+ }
1866
+
1867
+ if (!(this instanceof UAParser)) {
1868
+ return new UAParser(ua, extensions).getResult();
1869
+ }
1870
+
1871
+ var _navigator = (typeof window !== UNDEF_TYPE && window.navigator) ? window.navigator : undefined$1;
1872
+ var _ua = ua || ((_navigator && _navigator.userAgent) ? _navigator.userAgent : EMPTY);
1873
+ var _uach = (_navigator && _navigator.userAgentData) ? _navigator.userAgentData : undefined$1;
1874
+ var _rgxmap = extensions ? extend(regexes, extensions) : regexes;
1875
+ var _isSelfNav = _navigator && _navigator.userAgent == _ua;
1876
+
1877
+ this.getBrowser = function () {
1878
+ var _browser = {};
1879
+ _browser[NAME] = undefined$1;
1880
+ _browser[VERSION] = undefined$1;
1881
+ rgxMapper.call(_browser, _ua, _rgxmap.browser);
1882
+ _browser[MAJOR] = majorize(_browser[VERSION]);
1883
+ // Brave-specific detection
1884
+ if (_isSelfNav && _navigator && _navigator.brave && typeof _navigator.brave.isBrave == FUNC_TYPE) {
1885
+ _browser[NAME] = 'Brave';
1886
+ }
1887
+ return _browser;
1888
+ };
1889
+ this.getCPU = function () {
1890
+ var _cpu = {};
1891
+ _cpu[ARCHITECTURE] = undefined$1;
1892
+ rgxMapper.call(_cpu, _ua, _rgxmap.cpu);
1893
+ return _cpu;
1894
+ };
1895
+ this.getDevice = function () {
1896
+ var _device = {};
1897
+ _device[VENDOR] = undefined$1;
1898
+ _device[MODEL] = undefined$1;
1899
+ _device[TYPE] = undefined$1;
1900
+ rgxMapper.call(_device, _ua, _rgxmap.device);
1901
+ if (_isSelfNav && !_device[TYPE] && _uach && _uach.mobile) {
1902
+ _device[TYPE] = MOBILE;
1903
+ }
1904
+ // iPadOS-specific detection: identified as Mac, but has some iOS-only properties
1905
+ if (_isSelfNav && _device[MODEL] == 'Macintosh' && _navigator && typeof _navigator.standalone !== UNDEF_TYPE && _navigator.maxTouchPoints && _navigator.maxTouchPoints > 2) {
1906
+ _device[MODEL] = 'iPad';
1907
+ _device[TYPE] = TABLET;
1908
+ }
1909
+ return _device;
1910
+ };
1911
+ this.getEngine = function () {
1912
+ var _engine = {};
1913
+ _engine[NAME] = undefined$1;
1914
+ _engine[VERSION] = undefined$1;
1915
+ rgxMapper.call(_engine, _ua, _rgxmap.engine);
1916
+ return _engine;
1917
+ };
1918
+ this.getOS = function () {
1919
+ var _os = {};
1920
+ _os[NAME] = undefined$1;
1921
+ _os[VERSION] = undefined$1;
1922
+ rgxMapper.call(_os, _ua, _rgxmap.os);
1923
+ if (_isSelfNav && !_os[NAME] && _uach && _uach.platform != 'Unknown') {
1924
+ _os[NAME] = _uach.platform
1925
+ .replace(/chrome os/i, CHROMIUM_OS)
1926
+ .replace(/macos/i, MAC_OS); // backward compatibility
1927
+ }
1928
+ return _os;
1929
+ };
1930
+ this.getResult = function () {
1931
+ return {
1932
+ ua : this.getUA(),
1933
+ browser : this.getBrowser(),
1934
+ engine : this.getEngine(),
1935
+ os : this.getOS(),
1936
+ device : this.getDevice(),
1937
+ cpu : this.getCPU()
1938
+ };
1939
+ };
1940
+ this.getUA = function () {
1941
+ return _ua;
1942
+ };
1943
+ this.setUA = function (ua) {
1944
+ _ua = (typeof ua === STR_TYPE && ua.length > UA_MAX_LENGTH) ? trim(ua, UA_MAX_LENGTH) : ua;
1945
+ return this;
1946
+ };
1947
+ this.setUA(_ua);
1948
+ return this;
1949
+ };
1950
+
1951
+ UAParser.VERSION = LIBVERSION;
1952
+ UAParser.BROWSER = enumerize([NAME, VERSION, MAJOR]);
1953
+ UAParser.CPU = enumerize([ARCHITECTURE]);
1954
+ UAParser.DEVICE = enumerize([MODEL, VENDOR, TYPE, CONSOLE, MOBILE, SMARTTV, TABLET, WEARABLE, EMBEDDED]);
1955
+ UAParser.ENGINE = UAParser.OS = enumerize([NAME, VERSION]);
1956
+
1957
+ ///////////
1958
+ // Export
1959
+ //////////
1960
+
1961
+ // check js environment
1962
+ {
1963
+ // nodejs env
1964
+ if (module.exports) {
1965
+ exports = module.exports = UAParser;
1966
+ }
1967
+ exports.UAParser = UAParser;
1968
+ }
1969
+
1970
+ // jQuery/Zepto specific (optional)
1971
+ // Note:
1972
+ // In AMD env the global scope should be kept clean, but jQuery is an exception.
1973
+ // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
1974
+ // and we should catch that.
1975
+ var $ = typeof window !== UNDEF_TYPE && (window.jQuery || window.Zepto);
1976
+ if ($ && !$.ua) {
1977
+ var parser = new UAParser();
1978
+ $.ua = parser.getResult();
1979
+ $.ua.get = function () {
1980
+ return parser.getUA();
1981
+ };
1982
+ $.ua.set = function (ua) {
1983
+ parser.setUA(ua);
1984
+ var result = parser.getResult();
1985
+ for (var prop in result) {
1986
+ $.ua[prop] = result[prop];
1987
+ }
1988
+ };
1989
+ }
1990
+
1991
+ })(typeof window === 'object' ? window : commonjsGlobal);
1992
+ });
1993
+
1994
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
1995
+ // require the crypto API and do not support built-in fallback to lower quality random number
1996
+ // generators (like Math.random()).
1997
+ let getRandomValues;
1998
+ const rnds8 = new Uint8Array(16);
1999
+ function rng() {
2000
+ // lazy load so that environments that need to polyfill have a chance to do so
2001
+ if (!getRandomValues) {
2002
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
2003
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
2004
+
2005
+ if (!getRandomValues) {
2006
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
2007
+ }
2008
+ }
2009
+
2010
+ return getRandomValues(rnds8);
2011
+ }
2012
+
2013
+ /**
2014
+ * Convert array of 16 byte values to UUID string format of the form:
2015
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
2016
+ */
2017
+
2018
+ const byteToHex = [];
2019
+
2020
+ for (let i = 0; i < 256; ++i) {
2021
+ byteToHex.push((i + 0x100).toString(16).slice(1));
2022
+ }
2023
+
2024
+ function unsafeStringify(arr, offset = 0) {
2025
+ // Note: Be careful editing this code! It's been tuned for performance
2026
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
2027
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
2028
+ }
2029
+
2030
+ const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
2031
+ const native = {
2032
+ randomUUID
2033
+ };
2034
+
2035
+ function v4(options, buf, offset) {
2036
+ if (native.randomUUID && !buf && !options) {
2037
+ return native.randomUUID();
2038
+ }
2039
+
2040
+ options = options || {};
2041
+ const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2042
+
2043
+ rnds[6] = rnds[6] & 0x0f | 0x40;
2044
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
2045
+
2046
+ if (buf) {
2047
+ offset = offset || 0;
2048
+
2049
+ for (let i = 0; i < 16; ++i) {
2050
+ buf[offset + i] = rnds[i];
2051
+ }
2052
+
2053
+ return buf;
2054
+ }
2055
+
2056
+ return unsafeStringify(rnds);
2057
+ }
2058
+
2059
+ class Logger {
2060
+ constructor(environment) {
2061
+ this.log = (...args) => {
2062
+ if (this.environment !== 'production' && index.Build.isDev) {
2063
+ console.clear();
2064
+ console.log(...args);
2065
+ }
2066
+ };
2067
+ this.environment = environment;
2068
+ }
2069
+ }
2070
+
2071
+ function appendToParams(url, getParamsToUpdate) {
2072
+ if (typeof getParamsToUpdate !== "object") return false;
2073
+
2074
+ // remove consecutive duplicate '&' chars from the url
2075
+ url = url.replace(/(&)\1+/g, '&');
2076
+ //Note: substr(1) removes first character (getting rid of possible "?")
2077
+ // (does nothing with empty string)
2078
+ let getParams = url.substr(1).split('&');
2079
+
2080
+ //avoid extra "&" at the beginning if current document.location.search was empty or 1 char
2081
+ if ((getParams.length < 1) || ((getParams.length === 1) && (getParams[0] === "")))
2082
+ getParams = [];
2083
+
2084
+ let searchBuffer;
2085
+ let found;
2086
+
2087
+ for (let k in getParamsToUpdate) {
2088
+ if (!getParamsToUpdate.hasOwnProperty(k)) continue;
2089
+
2090
+ let key = encodeURIComponent(k);
2091
+ let value = encodeURIComponent(getParamsToUpdate[k]);
2092
+
2093
+ searchBuffer = [];
2094
+ found = false;
2095
+
2096
+ let paramsLength = getParams.length - 1;
2097
+ //from the end to start...
2098
+ for (let i = paramsLength; i >= 0; --i) {
2099
+ searchBuffer = getParams[i].split('=');
2100
+
2101
+ if (searchBuffer[0] === key) {
2102
+ //found key!
2103
+ getParams[i] = key + '=' + value;
2104
+ found = true;
2105
+ break;
2106
+ }
2107
+ }
2108
+
2109
+ if (!found) getParams.push(key + '=' + value);
2110
+ }
2111
+
2112
+ return getParams.join('&');
2113
+ }
2114
+
2115
+ const Logo = ({ className = '', color = '#7263FA' }) => {
2116
+ return (index.h("svg", { class: className, xmlns: 'http://www.w3.org/2000/svg', fill: 'none', viewBox: '0 0 256 256' },
2117
+ index.h("g", { fill: color, "clip-path": 'url(#a)' },
2118
+ index.h("path", { d: 'M128 185h57v57h-57zM128 14h57v57h-57zM71 185h57v57H71zM71 14h57v57H71zM14 71h57v57H14zM185 71h57v57h-57zM71 14v57H14l57-57ZM14 128h57v57H14zM185 128h57v57h-57zM14 185h57v57l-57-57ZM185 14l57 57h-57V14Z' })),
2119
+ index.h("defs", null,
2120
+ index.h("clipPath", { id: 'a' },
2121
+ index.h("path", { fill: '#fff', d: 'M14 14h228v228H14z' })))));
2122
+ };
2123
+
2124
+ const send = (url, opts, request, errorCount) => {
2125
+ let limit = errorCount
2126
+ ? Math.pow(2, errorCount - 1) * opts.startLimit
2127
+ : 0;
2128
+ limit = limit < opts.maxLimit ? limit : opts.maxLimit;
2129
+ const pause = Math.random() * limit;
2130
+ setTimeout(function () {
2131
+ request.open('POST', url, true);
2132
+ for (const k in opts.headers) {
2133
+ if (Object.prototype.hasOwnProperty.call(opts.headers, k)) {
2134
+ request.setRequestHeader(k, opts.headers[k]);
2135
+ }
2136
+ }
2137
+ request.send();
2138
+ }, pause);
2139
+ };
2140
+ const xhr = (url, opts = { startLimit: 100, maxLimit: 3 * 1000, enableWithCredentials: false }, callback) => {
2141
+ let errorCount = 0;
2142
+ const request = new XMLHttpRequest();
2143
+ if (opts.enableWithCredentials)
2144
+ request.withCredentials = true;
2145
+ const retry = () => send(url, opts, request, ++errorCount);
2146
+ request.addEventListener('error', retry);
2147
+ request.addEventListener('timeout', retry);
2148
+ request.addEventListener('load', () => {
2149
+ if (request.status >= 200 && request.status < 300) {
2150
+ return callback(request.responseText);
2151
+ }
2152
+ retry();
2153
+ });
2154
+ send(url, opts, request, errorCount);
2155
+ return request;
2156
+ };
2157
+ const http = {
2158
+ send: xhr,
2159
+ };
2160
+
2161
+ const API_URL = 'wss://ws.0account.com/ws';
2162
+ const API_URL_STAGING = 'wss://staging.ws.0account.com/ws';
2163
+ const PREFIX = '0account';
2164
+ const SESSION_ID = 'session-id';
2165
+ const SESSION_TOKEN = 'session-token';
2166
+ const fromWidgetUUIDUpdated = 'from-widget-uuid-updated';
2167
+ // const fromWidgetAuthenticationStarted = 'from-widget-authentication-started';
2168
+ const fromWidgetEnsureSession = 'from-widget-ensure-session';
2169
+ const toWidgetLogout = 'to-widget-logout';
2170
+ const toWidgetApproved = 'to-widget-approved';
2171
+ const toAnyError = 'to-any-error';
2172
+ // CustomEvents
2173
+ const zeroLogout = '0account-logout';
2174
+ const zeroAuthenticated = '0account-authenticated';
2175
+ // const zeroAuthenticationFailed = '0account-authentication-failed';
2176
+ function debounce(func, timeout = 300) {
2177
+ let timer;
2178
+ return (...args) => {
2179
+ clearTimeout(timer);
2180
+ timer = setTimeout(() => {
2181
+ func.apply(this, args);
2182
+ }, timeout);
2183
+ };
2184
+ }
2185
+ class WS {
2186
+ constructor(appId, opts) {
2187
+ this.wsURL = API_URL;
2188
+ this.callbackURL = API_URL;
2189
+ if (!opts.env)
2190
+ opts.env = Environment.production;
2191
+ this.appId = appId;
2192
+ this.uaParser = opts.uaParser;
2193
+ this.callbackURL = opts.callbackURL;
2194
+ this.updateInterval = opts.updateInterval;
2195
+ this.log = opts.log;
2196
+ if (opts.env !== Environment.production)
2197
+ this.wsURL = API_URL_STAGING;
2198
+ this.init();
2199
+ }
2200
+ deviceInfo() {
2201
+ return {
2202
+ appId: this.appId,
2203
+ browser: this.uaParser.getBrowser().name,
2204
+ os: this.uaParser.getOS().name,
2205
+ // TODO: handle these on backend:
2206
+ // device: `${this.uaParser.getDevice().vendor} ${this.uaParser.getDevice().model}`,
2207
+ // all: this.uaParser.getResult()
2208
+ };
2209
+ }
2210
+ reinit() {
2211
+ const retry = debounce(this.init.bind(this), 1000);
2212
+ retry();
2213
+ }
2214
+ init() {
2215
+ const onopen = (_) => {
2216
+ this.send(fromWidgetEnsureSession, this.deviceInfo());
2217
+ };
2218
+ const onmessage = (event) => {
2219
+ try {
2220
+ const data = JSON.parse(event.data);
2221
+ this.handleMessage(data);
2222
+ }
2223
+ catch (e) {
2224
+ this.log(e);
2225
+ }
2226
+ };
2227
+ const onerror = (_) => {
2228
+ if (this.socket && (this.socket.readyState !== WebSocket.CLOSED
2229
+ && this.socket.readyState !== WebSocket.CLOSING)) {
2230
+ this.socket.close();
2231
+ }
2232
+ };
2233
+ const onclose = (_) => {
2234
+ if (this.socket) {
2235
+ this.socket.removeEventListener('open', onopen);
2236
+ this.socket.removeEventListener('message', onmessage);
2237
+ this.socket.removeEventListener('error', onerror);
2238
+ this.socket.removeEventListener('close', onclose);
2239
+ delete this.socket;
2240
+ }
2241
+ this.reinit();
2242
+ };
2243
+ if (this.socket) {
2244
+ this.socket.removeEventListener('open', onopen);
2245
+ this.socket.removeEventListener('message', onmessage);
2246
+ this.socket.removeEventListener('error', onerror);
2247
+ this.socket.removeEventListener('close', onclose);
2248
+ }
2249
+ this.socket = new WebSocket(this.wsURL);
2250
+ this.socket.addEventListener('open', onopen);
2251
+ this.socket.addEventListener('message', onmessage);
2252
+ this.socket.addEventListener('error', onerror);
2253
+ this.socket.addEventListener('close', onclose);
2254
+ }
2255
+ updateUUID(uuid) {
2256
+ this.uuid = uuid;
2257
+ this.send(fromWidgetUUIDUpdated, this.deviceInfo());
2258
+ }
2259
+ send(action, data) {
2260
+ if (!this.socket || !this.socket.readyState || this.socket.readyState !== WebSocket.OPEN) {
2261
+ const retry = debounce(this.send.bind(this), 1000);
2262
+ return retry();
2263
+ }
2264
+ const msg = {
2265
+ action: action,
2266
+ timeout: `${this.updateInterval}ms`,
2267
+ uuid: this.uuid,
2268
+ appId: `${this.appId}`,
2269
+ message: {},
2270
+ };
2271
+ if (action === fromWidgetEnsureSession) {
2272
+ const sessionId = localStorage.getItem(`${PREFIX}_${SESSION_ID}`);
2273
+ const sessionToken = localStorage.getItem(`${PREFIX}_${SESSION_TOKEN}`);
2274
+ if (!sessionId || !sessionToken)
2275
+ return;
2276
+ msg.sessionId = sessionId;
2277
+ msg.sessionToken = sessionToken;
2278
+ }
2279
+ if (data)
2280
+ msg.message = data;
2281
+ this.socket.send(JSON.stringify(msg));
2282
+ }
2283
+ onZeroAuth() {
2284
+ if (this.request)
2285
+ this.request.abort();
2286
+ this.request = http.send(this.callbackURL, {
2287
+ enableWithCredentials: true,
2288
+ headers: {
2289
+ 'x-0account-uuid': this.uuid,
2290
+ 'x-0account-auth': 'true',
2291
+ },
2292
+ }, (responseText) => {
2293
+ try {
2294
+ const data = JSON.parse(responseText);
2295
+ this.dispatchEventAndWsSend(zeroAuthenticated, data);
2296
+ }
2297
+ catch (err) {
2298
+ this.log(err);
2299
+ }
2300
+ });
2301
+ }
2302
+ handleMessage(msg) {
2303
+ switch (msg.action) {
2304
+ case toWidgetApproved:
2305
+ this.onZeroAuth();
2306
+ localStorage.setItem(`${PREFIX}_${SESSION_ID}`, msg.sessionId);
2307
+ localStorage.setItem(`${PREFIX}_${SESSION_TOKEN}`, msg.message);
2308
+ break;
2309
+ case toWidgetLogout:
2310
+ localStorage.removeItem(`${PREFIX}_${SESSION_ID}`);
2311
+ localStorage.removeItem(`${PREFIX}_${SESSION_TOKEN}`);
2312
+ this.dispatchEvent(zeroLogout);
2313
+ break;
2314
+ case toAnyError:
2315
+ this.log('ws error', msg);
2316
+ break;
2317
+ default:
2318
+ this.log('incorrect action', msg.action, msg);
2319
+ }
2320
+ }
2321
+ dispatchEventAndWsSend(name, data) {
2322
+ this.dispatchEvent(name, data);
2323
+ this.send('from-widget-' + name, data);
2324
+ }
2325
+ dispatchEvent(name, data) {
2326
+ let event = new CustomEvent(name);
2327
+ if (data)
2328
+ event = new CustomEvent(name, { detail: data });
2329
+ document.dispatchEvent(event);
2330
+ }
2331
+ }
2332
+
2333
+ const zeroAccountCss = ":host{--primary-color:#7263FA;--primary-background-color:#FFF;--button-animation-duration:200ms;--text-color:#000;--button-border-color:#B2D4FF;--button-border-radius:9999px;--button-background-color:var(--primary-background-color);--modal-logo-border-color:var(--primary-color);--modal-animation-duration:350ms;--easing:cubic-bezier(0.16, 1, 0.3, 1);font-family:sans-serif}.dark{--button-background-color:rgb(30, 41, 59);--primary-background-color:rgb(30, 41, 59);--button-border-color:#FFFFF9;--text-color:#FFFFF9;--modal-logo-border-color:#CCC}.button{font-size:16px;color:var(--text-color);cursor:pointer;padding:8px 12px 8px 10px;display:flex;flex-direction:row;align-items:center;gap:6px;border:1px solid var(--button-border-color);background-color:var(--button-background-color);border-radius:var(--button-border-radius)}.button:hover{transition:box-shadow var(--button-animation-duration);box-shadow:0 0 3px rgba(0, 0, 0, 0.3);background:linear-gradient(\n to top,\n rgba(200, 200, 200, 0.1),\n rgba(200, 200, 200, 0.1)\n ) var(--button-background-color)}.button:active{transition:box-shadow var(--button-animation-duration);box-shadow:0 0 0 rgba(0, 0, 0, 0)}.button__logo{width:1.3rem}.modal{display:flex;z-index:9999;justify-content:center;align-items:center;position:fixed;top:0;left:0;width:100%;height:100%;opacity:1;background-color:rgba(0, 0, 0, 0.3);transition:opacity var(--modal-animation-duration) var(--easing)}.modal--hidden{opacity:0;pointer-events:none}.modal__content{max-width:240px;border-radius:4px;position:relative;display:flex;flex-direction:column;align-items:center;padding:16px;background-color:var(--primary-background-color);transform:scale(1);transition:transform var(--modal-animation-duration) var(--easing)}.modal--hidden .modal__content{transform:scale(0.5)}.modal__qrcode__container{position:relative}.modal__qrcode{border-radius:4px;width:100%;height:auto}.modal__logo{padding:8px;border:2px var(--modal-logo-border-color) solid;border-radius:var(--button-border-radius);background-color:var(--primary-background-color);position:absolute;width:16%;top:50%;left:50%;transform:translate3d(-50%, -50%, 0)}.modal-animated .circle__overlay{width:100%;height:100%}.modal-animated .modal__qrcode{filter:blur(2px)}.modal-animated .modal__logo{border:none;animation:spin 2.5s var(--easing) infinite}@keyframes spin{0%{transform:translate3d(-50%, -50%, 0) rotate(0deg)}50%{transform:translate3d(-50%, -50%, 0) rotate(180deg)}100%{transform:translate3d(-50%, -50%, 0) rotate(360deg)}}.modal__buttons{width:100%;flex-direction:column;align-items:center;margin-top:14px;display:flex;text-align:center}.modal:not(.modal--hidden) .modal__button{transform:scale(1) translate3d(0, 0, 0)}.modal:not(.modal--hidden) .modal__link{transform:scale(1) translate3d(0, 0, 0)}.modal__button{transform:scale(0) translate3d(0, 150px, 0);transition:calc(var(--modal-animation-duration) + 50ms) var(--easing);transition-property:scale, transform, background-color;cursor:pointer;padding:12px;font-size:14px;background-color:var(--primary-color);color:white;border:none;border-radius:6px;width:100%}.modal__button:hover{background:linear-gradient(\n to top,\n rgba(0, 0, 0, 0.1),\n rgba(0, 0, 0, 0.1)\n ) var(--primary-color)}.modal__link{transform:scale(0) translate3d(0, 150px, 0);transition:calc(var(--modal-animation-duration) + 150ms) var(--easing);transition-property:scale, transform;font-size:0.8rem;padding:10px 20px 0;color:var(--primary-color);width:100%;text-decoration:underline rgba(0, 0, 0, 0)}.modal__link:hover{text-decoration-color:var(--primary-color)}.modal__close-button{position:absolute;top:-26px;right:-26px;width:24px;height:24px;background-color:rgba(0, 0, 0, 0.1);border-radius:10px;cursor:pointer;transition:background-color var(--modal-animation-duration) var(--easing)}.modal__close-button:hover{background-color:rgba(0, 0, 0, 0.3)}.modal__close-button:before,.modal__close-button:after{content:\"\";position:absolute;top:50%;left:50%;width:50%;height:1px;background-color:rgba(255, 255, 255, 0.8);transform:translate(-50%, -50%) rotate(45deg)}.modal__close-button:after{transform:translate(-50%, -50%) rotate(-45deg)}.circle__overlay{overflow:hidden;top:50%;left:50%;transform:translate(-50%, -50%);position:absolute;background-color:var(--primary-background-color);border-radius:var(--button-border-radius);width:10%;height:10%;border:2px var(--modal-logo-border-color) solid;transition:calc(var(--modal-animation-duration) + 200ms) var(--easing);transition-property:width, height, opacity}.circle{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);width:100px;height:100px;border-radius:50%;background-color:#E0E0E0;animation:circle__ripple 2s linear infinite}.circle--medium{width:150px;height:150px;animation-duration:2.5s}.circle--large{width:200px;height:200px;animation-duration:3s}@keyframes circle__ripple{0%{transform:translate(-50%, -50%) scale(0);opacity:1}100%{transform:translate(-50%, -50%) scale(1.5);opacity:0}}";
2334
+
2335
+ const maxInterval = 59 * 60 * 1000;
2336
+ const minInterval = 10 * 1000;
2337
+ const DEFAULT_CALLBACK_URL = window.location.origin + '/zero/auth';
2338
+ const ANIMATION_DURATION = 3000;
2339
+ const ZeroAccount = class {
2340
+ constructor(hostRef) {
2341
+ index.registerInstance(this, hostRef);
2342
+ this.refreshQR = (ignoreAnimate = false) => {
2343
+ const update = () => {
2344
+ this.restartTimer();
2345
+ this.updateURL();
2346
+ };
2347
+ if (ignoreAnimate)
2348
+ return update();
2349
+ this.isAnimating = true;
2350
+ this.animationTimer = window.setTimeout(() => {
2351
+ update();
2352
+ this.isAnimating = false;
2353
+ }, ANIMATION_DURATION);
2354
+ };
2355
+ this.hideOnEsc = (e) => {
2356
+ if ((e.key === 'Escape' || e.key === 'Esc')) {
2357
+ this.modalOpen = false;
2358
+ }
2359
+ };
2360
+ this.log = (...args) => this.logger.log(...args);
2361
+ this.appId = undefined;
2362
+ this.updateInterval = 3 * 60 * 1000;
2363
+ this.callbackURL = DEFAULT_CALLBACK_URL;
2364
+ this.modal = true;
2365
+ this.selector = null;
2366
+ this.level = ErrorCorrectionLevel.M;
2367
+ this.primaryColor = '#3C444F';
2368
+ this.secondaryColor = undefined;
2369
+ this.instructionsText = undefined;
2370
+ this.hideInstructions = false;
2371
+ this.environment = Environment.production;
2372
+ this.enableWithCredentials = false;
2373
+ this.themePreset = ThemePreset.light;
2374
+ this.autoStartApp = true;
2375
+ this.modalOpen = false;
2376
+ this.isAnimating = false;
2377
+ this.url = '';
2378
+ }
2379
+ getUpdateInterval() {
2380
+ // make sure the provided value is within bounds
2381
+ return Math.min(Math.max(this.updateInterval, minInterval), maxInterval);
2382
+ }
2383
+ toggleModal() {
2384
+ this.modalOpen = !this.modalOpen;
2385
+ if (this.modalOpen)
2386
+ this.refreshQR(true);
2387
+ if ((this.modalOpen && this.autoStartApp) || this.isMobile())
2388
+ this.openApp();
2389
+ }
2390
+ _closeModal() {
2391
+ this.modalOpen = false;
2392
+ this.stopTimer();
2393
+ }
2394
+ closeModal(e) {
2395
+ if (e.target !== this.modalEl && e.target !== this.closeButtonEl) {
2396
+ return e.stopPropagation();
2397
+ }
2398
+ this._closeModal();
2399
+ }
2400
+ openApp() {
2401
+ if (this.modalOpen) {
2402
+ window.location.href = this.url;
2403
+ }
2404
+ }
2405
+ render() {
2406
+ const logoColor = this.themePreset === ThemePreset.light ? '#7263FA' : '#FFFFF9';
2407
+ const qrColor = this.themePreset === ThemePreset.light ? '#000' : '#FFFFF9';
2408
+ return (index.h(index.Host, null, index.h("slot", null), this.host.childNodes.length === 0 &&
2409
+ index.h("button", { class: `button ${this.themePreset}`, onClick: () => this.toggleModal() }, index.h(Logo, { className: 'button__logo', color: logoColor }), "use 0account"), index.h("div", { ref: el => this.modalEl = el, onClick: (e) => this.closeModal(e), class: `modal ${this.themePreset} ${this.isAnimating ? 'modal-animated' : ''} ${this.modalOpen ? '' : 'modal--hidden'}` }, index.h("div", { class: 'modal__content' }, index.h("div", { ref: el => this.closeButtonEl = el, class: 'modal__close-button' }), index.h("div", { class: 'modal__qrcode__container' }, index.h("qr-code", { url: this.url, class: `modal__qrcode`, level: this.level, color: qrColor }), index.h("div", { class: 'circle__overlay' }, index.h("div", { class: 'circle' }), index.h("div", { class: 'circle circle--medium' }), index.h("div", { class: 'circle circle--large' })), index.h(Logo, { className: 'modal__logo', color: logoColor })), index.h("div", { class: 'modal__buttons' }, index.h("button", { onClick: () => this.openApp(), class: 'modal__button' }, "Open the desktop app"), index.h("a", { href: '#', class: 'modal__link' }, "Download the app"))))));
2410
+ }
2411
+ // called only once
2412
+ componentWillLoad() {
2413
+ this.logger = new Logger(this.environment);
2414
+ this.uaParser = new uaParser.UAParser();
2415
+ this.ws = new WS(this.appId, {
2416
+ updateInterval: this.getUpdateInterval(),
2417
+ callbackURL: this.callbackURL,
2418
+ uaParser: this.uaParser,
2419
+ env: this.environment,
2420
+ log: this.log,
2421
+ });
2422
+ // make sure we initQR
2423
+ this.refreshQR(true);
2424
+ document.addEventListener('keydown', this.hideOnEsc);
2425
+ }
2426
+ updateURL() {
2427
+ const expires = new Date().getTime() + this.getUpdateInterval();
2428
+ const uuid = v4();
2429
+ this.ws.updateUUID(uuid);
2430
+ const params = appendToParams('', {
2431
+ appId: this.appId,
2432
+ uuid: uuid,
2433
+ expires: expires,
2434
+ });
2435
+ if (this.isMobile()) {
2436
+ this.url = 'https://launch.0account.com/auth?' + params;
2437
+ }
2438
+ else {
2439
+ this.url = 'zero-account://auth?' + params;
2440
+ }
2441
+ }
2442
+ isMobile() {
2443
+ const device = this.uaParser.getDevice();
2444
+ return device.type === 'tablet' || device.type === 'mobile';
2445
+ }
2446
+ connectedCallback() {
2447
+ this.startTimer();
2448
+ }
2449
+ disconnectedCallback() {
2450
+ this.stopTimer();
2451
+ document.removeEventListener('keydown', this.hideOnEsc);
2452
+ }
2453
+ restartTimer() {
2454
+ this.stopTimer();
2455
+ this.startTimer();
2456
+ }
2457
+ startTimer() {
2458
+ this.timer = window.setInterval(this.refreshQR, this.getUpdateInterval());
2459
+ }
2460
+ stopTimer() {
2461
+ window.clearInterval(this.timer);
2462
+ window.clearTimeout(this.animationTimer);
2463
+ this.isAnimating = false;
2464
+ }
2465
+ get host() { return index.getElement(this); }
2466
+ };
2467
+ ZeroAccount.style = zeroAccountCss;
2468
+
2469
+ exports.qr_code = QRCode;
2470
+ exports.zero_account = ZeroAccount;
2471
+
2472
+ //# sourceMappingURL=qr-code_2.cjs.entry.js.map