@aws-amplify/ui-react 1.2.26 → 1.2.54-legacy-ui.10

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 (77) hide show
  1. package/CHANGELOG.md +224 -0
  2. package/dist/0.js.map +1 -1
  3. package/dist/1.js +656 -2000
  4. package/dist/1.js.map +1 -1
  5. package/dist/10.js +23 -681
  6. package/dist/10.js.map +1 -1
  7. package/dist/11.js +1157 -20
  8. package/dist/11.js.map +1 -1
  9. package/dist/12.js +61 -1087
  10. package/dist/12.js.map +1 -1
  11. package/dist/13.js +1146 -64
  12. package/dist/13.js.map +1 -1
  13. package/dist/14.js +34 -1163
  14. package/dist/14.js.map +1 -1
  15. package/dist/15.js +17 -37
  16. package/dist/15.js.map +1 -1
  17. package/dist/16.js +109 -13
  18. package/dist/16.js.map +1 -1
  19. package/dist/17.js +32 -67
  20. package/dist/17.js.map +1 -1
  21. package/dist/18.js +236 -46
  22. package/dist/18.js.map +1 -1
  23. package/dist/19.js +35 -224
  24. package/dist/19.js.map +1 -1
  25. package/dist/2.js +2190 -159
  26. package/dist/2.js.map +1 -1
  27. package/dist/20.js +28 -48
  28. package/dist/20.js.map +1 -1
  29. package/dist/21.js +46 -25
  30. package/dist/21.js.map +1 -1
  31. package/dist/22.js +22 -25
  32. package/dist/22.js.map +1 -1
  33. package/dist/23.js +254 -25
  34. package/dist/23.js.map +1 -1
  35. package/dist/24.js +62 -230
  36. package/dist/24.js.map +1 -1
  37. package/dist/25.js +28 -62
  38. package/dist/25.js.map +1 -1
  39. package/dist/26.js +349 -30
  40. package/dist/26.js.map +1 -1
  41. package/dist/27.js +24 -352
  42. package/dist/27.js.map +1 -1
  43. package/dist/28.js +25 -22
  44. package/dist/28.js.map +1 -1
  45. package/dist/29.js +483 -26
  46. package/dist/29.js.map +1 -1
  47. package/dist/3.js +2710 -1818
  48. package/dist/3.js.map +1 -1
  49. package/dist/30.js +1 -502
  50. package/dist/30.js.map +1 -1
  51. package/dist/31.js +1 -1
  52. package/dist/31.js.map +1 -1
  53. package/dist/32.js +12 -1
  54. package/dist/32.js.map +1 -1
  55. package/dist/4.js +361 -3669
  56. package/dist/4.js.map +1 -1
  57. package/dist/5.js +48 -242
  58. package/dist/5.js.map +1 -1
  59. package/dist/6.js +118 -74
  60. package/dist/6.js.map +1 -1
  61. package/dist/7.js +55 -99
  62. package/dist/7.js.map +1 -1
  63. package/dist/8.js +98 -46
  64. package/dist/8.js.map +1 -1
  65. package/dist/9.js +474 -412
  66. package/dist/9.js.map +1 -1
  67. package/dist/@aws-amplify/ui-react.js +50 -44
  68. package/dist/@aws-amplify/ui-react.js.map +1 -1
  69. package/dist/aws-amplify-react.min.js +2 -2
  70. package/dist/aws-amplify-react.min.js.map +1 -1
  71. package/dist/polyfills-core-js.js +5 -11
  72. package/dist/polyfills-core-js.js.map +1 -1
  73. package/dist/polyfills-css-shim.js.map +1 -1
  74. package/dist/polyfills-dom.js.map +1 -1
  75. package/package.json +3 -3
  76. package/dist/33.js +0 -13
  77. package/dist/33.js.map +0 -1
package/dist/4.js CHANGED
@@ -1,29 +1,26 @@
1
1
  (this["webpackJsonpaws_amplify_react"] = this["webpackJsonpaws_amplify_react"] || []).push([[4],{
2
2
 
3
- /***/ "../amplify-ui-components/dist/esm-es5/amplify-radio-button_3.entry.js":
4
- /*!*****************************************************************************!*\
5
- !*** ../amplify-ui-components/dist/esm-es5/amplify-radio-button_3.entry.js ***!
6
- \*****************************************************************************/
7
- /*! exports provided: amplify_radio_button, amplify_toast, amplify_totp_setup */
3
+ /***/ "../amplify-ui-components/dist/esm-es5/amplify-s3-album.entry.js":
4
+ /*!***********************************************************************!*\
5
+ !*** ../amplify-ui-components/dist/esm-es5/amplify-s3-album.entry.js ***!
6
+ \***********************************************************************/
7
+ /*! exports provided: amplify_s3_album */
8
8
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
9
9
 
10
10
  "use strict";
11
11
  __webpack_require__.r(__webpack_exports__);
12
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_radio_button", function() { return AmplifyRadioButton; });
13
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_toast", function() { return AmplifyToast; });
14
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_totp_setup", function() { return AmplifyTOTPSetup; });
12
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_s3_album", function() { return AmplifyS3Album; });
15
13
  /* harmony import */ var _index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index-83f2275b.js */ "../amplify-ui-components/dist/esm-es5/index-83f2275b.js");
16
14
  /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
17
15
  /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__);
18
- /* harmony import */ var _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./auth-types-78df304e.js */ "../amplify-ui-components/dist/esm-es5/auth-types-78df304e.js");
16
+ /* harmony import */ var _storage_types_f257c0f2_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./storage-types-f257c0f2.js */ "../amplify-ui-components/dist/esm-es5/storage-types-f257c0f2.js");
19
17
  /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @aws-amplify/auth */ "@aws-amplify/auth");
20
18
  /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__);
21
19
  /* harmony import */ var _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./Translations-108d469f.js */ "../amplify-ui-components/dist/esm-es5/Translations-108d469f.js");
22
20
  /* harmony import */ var _constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./constants-c8ecaa24.js */ "../amplify-ui-components/dist/esm-es5/constants-c8ecaa24.js");
23
- /* harmony import */ var _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./helpers-14fcb50c.js */ "../amplify-ui-components/dist/esm-es5/helpers-14fcb50c.js");
24
- /* harmony import */ var _auth_helpers_557b83fc_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./auth-helpers-557b83fc.js */ "../amplify-ui-components/dist/esm-es5/auth-helpers-557b83fc.js");
25
- /* harmony import */ var buffer__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! buffer */ "../../node_modules/buffer/index.js");
26
- /* harmony import */ var buffer__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(buffer__WEBPACK_IMPORTED_MODULE_8__);
21
+ /* harmony import */ var _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @aws-amplify/storage */ "@aws-amplify/storage");
22
+ /* harmony import */ var _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_storage__WEBPACK_IMPORTED_MODULE_6__);
23
+ /* harmony import */ var _storage_helpers_1afafead_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./storage-helpers-1afafead.js */ "../amplify-ui-components/dist/esm-es5/storage-helpers-1afafead.js");
27
24
  var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
28
25
  function adopt(value) {
29
26
  return value instanceof P ? value : new P(function (resolve) {
@@ -167,3628 +164,325 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
167
164
  }
168
165
  };
169
166
 
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
- var amplifyRadioButtonCss = ":host{--font-family:var(--amplify-font-family)}.radio-button{display:block;width:100%;padding:16px;font-size:var(--amplify-text-sm);font-family:var(--font-family)}.radio-button input{margin-right:12px}";
180
-
181
- var AmplifyRadioButton =
182
- /** @class */
183
- function () {
184
- function AmplifyRadioButton(hostRef) {
185
- Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
186
- /** (Optional) The placeholder for the input element. Using hints is recommended, but placeholders can also be useful to convey information to users. */
187
-
188
- this.placeholder = '';
189
- /** If `true`, the radio button is selected. */
190
-
191
- this.checked = false;
192
- /** If `true`, the checkbox is disabled */
193
-
194
- this.disabled = false;
195
- }
196
-
197
- AmplifyRadioButton.prototype.render = function () {
198
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", {
199
- "class": "radio-button"
200
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("input", Object.assign({
201
- type: "radio",
202
- name: this.name,
203
- value: this.value,
204
- onInput: this.handleInputChange,
205
- placeholder: this.placeholder,
206
- id: this.fieldId,
207
- checked: this.checked,
208
- disabled: this.disabled
209
- }, this.inputProps)), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-label", {
210
- htmlFor: this.fieldId
211
- }, this.label));
212
- };
213
-
214
- return AmplifyRadioButton;
215
- }();
216
-
217
- AmplifyRadioButton.style = amplifyRadioButtonCss;
218
- var amplifyToastCss = ":host{--background-color:var(--amplify-secondary-tint);--color:var(--amplify-white);--font-size:var(--amplify-text-sm);--font-family:var(--amplify-font-family);--close-icon-color:var(--amplify-white);--close-icon-hover:var(--amplify-red)}.toast-icon{padding-right:5px}.toast{display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;position:absolute;top:0;left:0;width:100%;z-index:99;-webkit-box-shadow:0 0 5px 0 rgba(0, 0, 0, 0.3);box-shadow:0 0 5px 0 rgba(0, 0, 0, 0.3);padding:16px;background-color:var(--background-color);font-size:var(--font-size);color:var(--color);-webkit-box-sizing:border-box;box-sizing:border-box;border-radius:5px;font-family:var(--font-family)}.toast>span{margin-right:10px}.toast-close{margin-left:auto;-ms-flex-item-align:center;align-self:center;position:relative;width:18px;height:18px;overflow:hidden;cursor:pointer;background:transparent;border:none}.toast-close::before,.toast-close::after{content:\"\";position:absolute;height:2px;width:100%;top:50%;left:0;margin-top:-1px;background:var(--close-icon-color)}.toast-close:hover::before,.toast-close:hover::after{background:var(--close-icon-hover)}.toast-close::before{-webkit-transform:rotate(45deg);-moz-transform:rotate(45deg);-ms-transform:rotate(45deg);-o-transform:rotate(45deg);transform:rotate(45deg)}.toast-close::after{-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-ms-transform:rotate(-45deg);-o-transform:rotate(-45deg);transform:rotate(-45deg)}";
219
-
220
- var AmplifyToast =
221
- /** @class */
222
- function () {
223
- function AmplifyToast(hostRef) {
224
- Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
225
- /** Message to be displayed inside the toast*/
226
-
227
- this.message = '';
228
- }
229
- /*
230
- TODO #170365145: Work on a helper function that will populate and
231
- update class colors for success / warning / failure messages
232
- */
233
-
234
-
235
- AmplifyToast.prototype.render = function () {
236
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
237
- "class": "toast"
238
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-icon", {
239
- "class": "toast-icon",
240
- name: "warning"
241
- }), this.message ? Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", null, this.message) : null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", null), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("button", {
242
- "class": "toast-close",
243
- onClick: this.handleClose
244
- }));
245
- };
246
-
247
- return AmplifyToast;
248
- }();
249
-
250
- AmplifyToast.style = amplifyToastCss; // can-promise has a crash in some versions of react native that dont have
251
- // standard global objects
252
- // https://github.com/soldair/node-qrcode/issues/157
253
-
254
- var canPromise = function canPromise() {
255
- return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then;
256
- };
257
-
258
- var toString = {}.toString;
259
-
260
- var isarray = Array.isArray || function (arr) {
261
- return toString.call(arr) == '[object Array]';
262
- };
263
-
264
- function typedArraySupport() {
265
- // Can typed array instances be augmented?
266
- try {
267
- var arr = new Uint8Array(1);
268
- arr.__proto__ = {
269
- __proto__: Uint8Array.prototype,
270
- foo: function foo() {
271
- return 42;
272
- }
273
- };
274
- return arr.foo() === 42;
275
- } catch (e) {
276
- return false;
277
- }
278
- }
279
-
280
- Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
281
- var K_MAX_LENGTH = Buffer.TYPED_ARRAY_SUPPORT ? 0x7fffffff : 0x3fffffff;
282
-
283
- function Buffer(arg, offset, length) {
284
- if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
285
- return new Buffer(arg, offset, length);
286
- }
287
-
288
- if (typeof arg === 'number') {
289
- return allocUnsafe(this, arg);
290
- }
291
-
292
- return from(this, arg, offset, length);
293
- }
294
-
295
- if (Buffer.TYPED_ARRAY_SUPPORT) {
296
- Buffer.prototype.__proto__ = Uint8Array.prototype;
297
- Buffer.__proto__ = Uint8Array; // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
298
-
299
- if (typeof Symbol !== 'undefined' && Symbol.species && Buffer[Symbol.species] === Buffer) {
300
- Object.defineProperty(Buffer, Symbol.species, {
301
- value: null,
302
- configurable: true,
303
- enumerable: false,
304
- writable: false
305
- });
306
- }
307
- }
308
-
309
- function checked(length) {
310
- // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
311
- // length is NaN (which is otherwise coerced to zero.)
312
- if (length >= K_MAX_LENGTH) {
313
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes');
314
- }
315
-
316
- return length | 0;
317
- }
318
-
319
- function isnan(val) {
320
- return val !== val; // eslint-disable-line no-self-compare
321
- }
322
-
323
- function createBuffer(that, length) {
324
- var buf;
325
-
326
- if (Buffer.TYPED_ARRAY_SUPPORT) {
327
- buf = new Uint8Array(length);
328
- buf.__proto__ = Buffer.prototype;
329
- } else {
330
- // Fallback: Return an object instance of the Buffer class
331
- buf = that;
332
-
333
- if (buf === null) {
334
- buf = new Buffer(length);
335
- }
336
-
337
- buf.length = length;
338
- }
339
-
340
- return buf;
341
- }
342
-
343
- function allocUnsafe(that, size) {
344
- var buf = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
345
-
346
- if (!Buffer.TYPED_ARRAY_SUPPORT) {
347
- for (var i = 0; i < size; ++i) {
348
- buf[i] = 0;
349
- }
350
- }
351
-
352
- return buf;
353
- }
354
-
355
- function fromString(that, string) {
356
- var length = byteLength(string) | 0;
357
- var buf = createBuffer(that, length);
358
- var actual = buf.write(string);
359
-
360
- if (actual !== length) {
361
- // Writing a hex string, for example, that contains invalid characters will
362
- // cause everything after the first invalid character to be ignored. (e.g.
363
- // 'abxxcd' will be treated as 'ab')
364
- buf = buf.slice(0, actual);
365
- }
366
-
367
- return buf;
368
- }
369
-
370
- function fromArrayLike(that, array) {
371
- var length = array.length < 0 ? 0 : checked(array.length) | 0;
372
- var buf = createBuffer(that, length);
373
-
374
- for (var i = 0; i < length; i += 1) {
375
- buf[i] = array[i] & 255;
376
- }
377
-
378
- return buf;
379
- }
380
-
381
- function fromArrayBuffer(that, array, byteOffset, length) {
382
- if (byteOffset < 0 || array.byteLength < byteOffset) {
383
- throw new RangeError('\'offset\' is out of bounds');
384
- }
385
-
386
- if (array.byteLength < byteOffset + (length || 0)) {
387
- throw new RangeError('\'length\' is out of bounds');
388
- }
389
-
390
- var buf;
391
-
392
- if (byteOffset === undefined && length === undefined) {
393
- buf = new Uint8Array(array);
394
- } else if (length === undefined) {
395
- buf = new Uint8Array(array, byteOffset);
396
- } else {
397
- buf = new Uint8Array(array, byteOffset, length);
398
- }
399
-
400
- if (Buffer.TYPED_ARRAY_SUPPORT) {
401
- // Return an augmented `Uint8Array` instance, for best performance
402
- buf.__proto__ = Buffer.prototype;
403
- } else {
404
- // Fallback: Return an object instance of the Buffer class
405
- buf = fromArrayLike(that, buf);
406
- }
407
-
408
- return buf;
409
- }
410
-
411
- function fromObject(that, obj) {
412
- if (Buffer.isBuffer(obj)) {
413
- var len = checked(obj.length) | 0;
414
- var buf = createBuffer(that, len);
415
-
416
- if (buf.length === 0) {
417
- return buf;
418
- }
419
-
420
- obj.copy(buf, 0, 0, len);
421
- return buf;
422
- }
423
-
424
- if (obj) {
425
- if (typeof ArrayBuffer !== 'undefined' && obj.buffer instanceof ArrayBuffer || 'length' in obj) {
426
- if (typeof obj.length !== 'number' || isnan(obj.length)) {
427
- return createBuffer(that, 0);
428
- }
429
-
430
- return fromArrayLike(that, obj);
431
- }
432
-
433
- if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
434
- return fromArrayLike(that, obj.data);
435
- }
436
- }
437
-
438
- throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.');
439
- }
440
-
441
- function utf8ToBytes(string, units) {
442
- units = units || Infinity;
443
- var codePoint;
444
- var length = string.length;
445
- var leadSurrogate = null;
446
- var bytes = [];
447
-
448
- for (var i = 0; i < length; ++i) {
449
- codePoint = string.charCodeAt(i); // is surrogate component
450
-
451
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
452
- // last char was a lead
453
- if (!leadSurrogate) {
454
- // no lead yet
455
- if (codePoint > 0xDBFF) {
456
- // unexpected trail
457
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
458
- continue;
459
- } else if (i + 1 === length) {
460
- // unpaired lead
461
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
462
- continue;
463
- } // valid lead
464
-
465
-
466
- leadSurrogate = codePoint;
467
- continue;
468
- } // 2 leads in a row
469
-
470
-
471
- if (codePoint < 0xDC00) {
472
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
473
- leadSurrogate = codePoint;
474
- continue;
475
- } // valid surrogate pair
476
-
477
-
478
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
479
- } else if (leadSurrogate) {
480
- // valid bmp char, but last char was a lead
481
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
482
- }
483
-
484
- leadSurrogate = null; // encode utf8
485
-
486
- if (codePoint < 0x80) {
487
- if ((units -= 1) < 0) break;
488
- bytes.push(codePoint);
489
- } else if (codePoint < 0x800) {
490
- if ((units -= 2) < 0) break;
491
- bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80);
492
- } else if (codePoint < 0x10000) {
493
- if ((units -= 3) < 0) break;
494
- bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
495
- } else if (codePoint < 0x110000) {
496
- if ((units -= 4) < 0) break;
497
- bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
498
- } else {
499
- throw new Error('Invalid code point');
500
- }
501
- }
502
-
503
- return bytes;
504
- }
505
-
506
- function byteLength(string) {
507
- if (Buffer.isBuffer(string)) {
508
- return string.length;
509
- }
510
-
511
- if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
512
- return string.byteLength;
513
- }
514
-
515
- if (typeof string !== 'string') {
516
- string = '' + string;
517
- }
518
-
519
- var len = string.length;
520
- if (len === 0) return 0;
521
- return utf8ToBytes(string).length;
522
- }
523
-
524
- function blitBuffer(src, dst, offset, length) {
525
- for (var i = 0; i < length; ++i) {
526
- if (i + offset >= dst.length || i >= src.length) break;
527
- dst[i + offset] = src[i];
528
- }
529
-
530
- return i;
531
- }
532
-
533
- function utf8Write(buf, string, offset, length) {
534
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
535
- }
536
-
537
- function from(that, value, offset, length) {
538
- if (typeof value === 'number') {
539
- throw new TypeError('"value" argument must not be a number');
540
- }
541
-
542
- if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
543
- return fromArrayBuffer(that, value, offset, length);
544
- }
545
-
546
- if (typeof value === 'string') {
547
- return fromString(that, value);
548
- }
549
-
550
- return fromObject(that, value);
551
- }
552
-
553
- Buffer.prototype.write = function write(string, offset, length) {
554
- // Buffer#write(string)
555
- if (offset === undefined) {
556
- length = this.length;
557
- offset = 0; // Buffer#write(string, encoding)
558
- } else if (length === undefined && typeof offset === 'string') {
559
- length = this.length;
560
- offset = 0; // Buffer#write(string, offset[, length])
561
- } else if (isFinite(offset)) {
562
- offset = offset | 0;
563
-
564
- if (isFinite(length)) {
565
- length = length | 0;
566
- } else {
567
- length = undefined;
568
- }
569
- }
570
-
571
- var remaining = this.length - offset;
572
- if (length === undefined || length > remaining) length = remaining;
573
-
574
- if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
575
- throw new RangeError('Attempt to write outside buffer bounds');
576
- }
577
-
578
- return utf8Write(this, string, offset, length);
579
- };
580
-
581
- Buffer.prototype.slice = function slice(start, end) {
582
- var len = this.length;
583
- start = ~~start;
584
- end = end === undefined ? len : ~~end;
585
-
586
- if (start < 0) {
587
- start += len;
588
- if (start < 0) start = 0;
589
- } else if (start > len) {
590
- start = len;
591
- }
592
-
593
- if (end < 0) {
594
- end += len;
595
- if (end < 0) end = 0;
596
- } else if (end > len) {
597
- end = len;
598
- }
599
-
600
- if (end < start) end = start;
601
- var newBuf;
602
-
603
- if (Buffer.TYPED_ARRAY_SUPPORT) {
604
- newBuf = this.subarray(start, end); // Return an augmented `Uint8Array` instance
605
-
606
- newBuf.__proto__ = Buffer.prototype;
607
- } else {
608
- var sliceLen = end - start;
609
- newBuf = new Buffer(sliceLen, undefined);
610
-
611
- for (var i = 0; i < sliceLen; ++i) {
612
- newBuf[i] = this[i + start];
613
- }
614
- }
615
-
616
- return newBuf;
617
- };
618
-
619
- Buffer.prototype.copy = function copy(target, targetStart, start, end) {
620
- if (!start) start = 0;
621
- if (!end && end !== 0) end = this.length;
622
- if (targetStart >= target.length) targetStart = target.length;
623
- if (!targetStart) targetStart = 0;
624
- if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done
625
-
626
- if (end === start) return 0;
627
- if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions
628
-
629
- if (targetStart < 0) {
630
- throw new RangeError('targetStart out of bounds');
631
- }
632
-
633
- if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds');
634
- if (end < 0) throw new RangeError('sourceEnd out of bounds'); // Are we oob?
635
-
636
- if (end > this.length) end = this.length;
637
-
638
- if (target.length - targetStart < end - start) {
639
- end = target.length - targetStart + start;
640
- }
641
-
642
- var len = end - start;
643
- var i;
644
-
645
- if (this === target && start < targetStart && targetStart < end) {
646
- // descending copy from end
647
- for (i = len - 1; i >= 0; --i) {
648
- target[i + targetStart] = this[i + start];
649
- }
650
- } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
651
- // ascending copy from start
652
- for (i = 0; i < len; ++i) {
653
- target[i + targetStart] = this[i + start];
654
- }
655
- } else {
656
- Uint8Array.prototype.set.call(target, this.subarray(start, start + len), targetStart);
657
- }
658
-
659
- return len;
660
- };
661
-
662
- Buffer.prototype.fill = function fill(val, start, end) {
663
- // Handle string cases:
664
- if (typeof val === 'string') {
665
- if (typeof start === 'string') {
666
- start = 0;
667
- end = this.length;
668
- } else if (typeof end === 'string') {
669
- end = this.length;
670
- }
671
-
672
- if (val.length === 1) {
673
- var code = val.charCodeAt(0);
674
-
675
- if (code < 256) {
676
- val = code;
677
- }
678
- }
679
- } else if (typeof val === 'number') {
680
- val = val & 255;
681
- } // Invalid ranges are not set to a default, so can range check early.
682
-
683
-
684
- if (start < 0 || this.length < start || this.length < end) {
685
- throw new RangeError('Out of range index');
686
- }
687
-
688
- if (end <= start) {
689
- return this;
690
- }
691
-
692
- start = start >>> 0;
693
- end = end === undefined ? this.length : end >>> 0;
694
- if (!val) val = 0;
695
- var i;
696
-
697
- if (typeof val === 'number') {
698
- for (i = start; i < end; ++i) {
699
- this[i] = val;
700
- }
701
- } else {
702
- var bytes = Buffer.isBuffer(val) ? val : new Buffer(val);
703
- var len = bytes.length;
704
-
705
- for (i = 0; i < end - start; ++i) {
706
- this[i + start] = bytes[i % len];
707
- }
708
- }
709
-
710
- return this;
711
- };
712
-
713
- Buffer.concat = function concat(list, length) {
714
- if (!isarray(list)) {
715
- throw new TypeError('"list" argument must be an Array of Buffers');
716
- }
717
-
718
- if (list.length === 0) {
719
- return createBuffer(null, 0);
720
- }
721
-
722
- var i;
723
-
724
- if (length === undefined) {
725
- length = 0;
726
-
727
- for (i = 0; i < list.length; ++i) {
728
- length += list[i].length;
729
- }
730
- }
731
-
732
- var buffer = allocUnsafe(null, length);
733
- var pos = 0;
734
-
735
- for (i = 0; i < list.length; ++i) {
736
- var buf = list[i];
737
-
738
- if (!Buffer.isBuffer(buf)) {
739
- throw new TypeError('"list" argument must be an Array of Buffers');
740
- }
741
-
742
- buf.copy(buffer, pos);
743
- pos += buf.length;
744
- }
745
-
746
- return buffer;
747
- };
748
-
749
- Buffer.byteLength = byteLength;
750
- Buffer.prototype._isBuffer = true;
751
-
752
- Buffer.isBuffer = function isBuffer(b) {
753
- return !!(b != null && b._isBuffer);
754
- };
755
-
756
- var alloc = function alloc(size) {
757
- var buffer = new Buffer(size);
758
- buffer.fill(0);
759
- return buffer;
760
- };
761
-
762
- var from_1 = function from_1(data) {
763
- return new Buffer(data);
764
- };
765
-
766
- var typedarrayBuffer = {
767
- alloc: alloc,
768
- from: from_1
769
- };
770
- var toSJISFunction;
771
- var CODEWORDS_COUNT = [0, 26, 44, 70, 100, 134, 172, 196, 242, 292, 346, 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085, 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185, 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706];
772
- /**
773
- * Returns the QR Code size for the specified version
774
- *
775
- * @param {Number} version QR Code version
776
- * @return {Number} size of QR code
777
- */
778
-
779
- var getSymbolSize = function getSymbolSize(version) {
780
- if (!version) throw new Error('"version" cannot be null or undefined');
781
- if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40');
782
- return version * 4 + 17;
783
- };
784
- /**
785
- * Returns the total number of codewords used to store data and EC information.
786
- *
787
- * @param {Number} version QR Code version
788
- * @return {Number} Data length in bits
789
- */
790
-
791
-
792
- var getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
793
- return CODEWORDS_COUNT[version];
794
- };
795
- /**
796
- * Encode data with Bose-Chaudhuri-Hocquenghem
797
- *
798
- * @param {Number} data Value to encode
799
- * @return {Number} Encoded value
800
- */
801
-
802
-
803
- var getBCHDigit = function getBCHDigit(data) {
804
- var digit = 0;
805
-
806
- while (data !== 0) {
807
- digit++;
808
- data >>>= 1;
809
- }
810
-
811
- return digit;
812
- };
813
-
814
- var setToSJISFunction = function setToSJISFunction(f) {
815
- if (typeof f !== 'function') {
816
- throw new Error('"toSJISFunc" is not a valid function.');
817
- }
818
-
819
- toSJISFunction = f;
820
- };
821
-
822
- var isKanjiModeEnabled = function isKanjiModeEnabled() {
823
- return typeof toSJISFunction !== 'undefined';
824
- };
825
-
826
- var toSJIS = function toSJIS(kanji) {
827
- return toSJISFunction(kanji);
828
- };
829
-
830
- var utils = {
831
- getSymbolSize: getSymbolSize,
832
- getSymbolTotalCodewords: getSymbolTotalCodewords,
833
- getBCHDigit: getBCHDigit,
834
- setToSJISFunction: setToSJISFunction,
835
- isKanjiModeEnabled: isKanjiModeEnabled,
836
- toSJIS: toSJIS
837
- };
838
-
839
- function createCommonjsModule(fn, basedir, module) {
840
- return module = {
841
- path: basedir,
842
- exports: {},
843
- require: function require(path, base) {
844
- return commonjsRequire();
845
- }
846
- }, fn(module, module.exports), module.exports;
847
- }
848
-
849
- function commonjsRequire() {
850
- throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
851
- }
852
-
853
- var errorCorrectionLevel = createCommonjsModule(function (module, exports) {
854
- exports.L = {
855
- bit: 1
856
- };
857
- exports.M = {
858
- bit: 0
859
- };
860
- exports.Q = {
861
- bit: 3
862
- };
863
- exports.H = {
864
- bit: 2
865
- };
866
-
867
- function fromString(string) {
868
- if (typeof string !== 'string') {
869
- throw new Error('Param is not a string');
870
- }
871
-
872
- var lcStr = string.toLowerCase();
873
-
874
- switch (lcStr) {
875
- case 'l':
876
- case 'low':
877
- return exports.L;
878
-
879
- case 'm':
880
- case 'medium':
881
- return exports.M;
882
-
883
- case 'q':
884
- case 'quartile':
885
- return exports.Q;
886
-
887
- case 'h':
888
- case 'high':
889
- return exports.H;
890
-
891
- default:
892
- throw new Error('Unknown EC Level: ' + string);
893
- }
894
- }
895
-
896
- exports.isValid = function isValid(level) {
897
- return level && typeof level.bit !== 'undefined' && level.bit >= 0 && level.bit < 4;
898
- };
899
-
900
- exports.from = function from(value, defaultValue) {
901
- if (exports.isValid(value)) {
902
- return value;
903
- }
904
-
905
- try {
906
- return fromString(value);
907
- } catch (e) {
908
- return defaultValue;
909
- }
910
- };
911
- });
912
-
913
- function BitBuffer() {
914
- this.buffer = [];
915
- this.length = 0;
916
- }
917
-
918
- BitBuffer.prototype = {
919
- get: function get(index) {
920
- var bufIndex = Math.floor(index / 8);
921
- return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
922
- },
923
- put: function put(num, length) {
924
- for (var i = 0; i < length; i++) {
925
- this.putBit((num >>> length - i - 1 & 1) === 1);
926
- }
927
- },
928
- getLengthInBits: function getLengthInBits() {
929
- return this.length;
930
- },
931
- putBit: function putBit(bit) {
932
- var bufIndex = Math.floor(this.length / 8);
933
-
934
- if (this.buffer.length <= bufIndex) {
935
- this.buffer.push(0);
936
- }
937
-
938
- if (bit) {
939
- this.buffer[bufIndex] |= 0x80 >>> this.length % 8;
940
- }
941
-
942
- this.length++;
943
- }
944
- };
945
- var bitBuffer = BitBuffer;
946
- /**
947
- * Helper class to handle QR Code symbol modules
948
- *
949
- * @param {Number} size Symbol size
950
- */
951
-
952
- function BitMatrix(size) {
953
- if (!size || size < 1) {
954
- throw new Error('BitMatrix size must be defined and greater than 0');
955
- }
956
-
957
- this.size = size;
958
- this.data = typedarrayBuffer.alloc(size * size);
959
- this.reservedBit = typedarrayBuffer.alloc(size * size);
960
- }
961
- /**
962
- * Set bit value at specified location
963
- * If reserved flag is set, this bit will be ignored during masking process
964
- *
965
- * @param {Number} row
966
- * @param {Number} col
967
- * @param {Boolean} value
968
- * @param {Boolean} reserved
969
- */
970
-
971
-
972
- BitMatrix.prototype.set = function (row, col, value, reserved) {
973
- var index = row * this.size + col;
974
- this.data[index] = value;
975
- if (reserved) this.reservedBit[index] = true;
976
- };
977
- /**
978
- * Returns bit value at specified location
979
- *
980
- * @param {Number} row
981
- * @param {Number} col
982
- * @return {Boolean}
983
- */
984
-
985
-
986
- BitMatrix.prototype.get = function (row, col) {
987
- return this.data[row * this.size + col];
988
- };
989
- /**
990
- * Applies xor operator at specified location
991
- * (used during masking process)
992
- *
993
- * @param {Number} row
994
- * @param {Number} col
995
- * @param {Boolean} value
996
- */
997
-
998
-
999
- BitMatrix.prototype.xor = function (row, col, value) {
1000
- this.data[row * this.size + col] ^= value;
1001
- };
1002
- /**
1003
- * Check if bit at specified location is reserved
1004
- *
1005
- * @param {Number} row
1006
- * @param {Number} col
1007
- * @return {Boolean}
1008
- */
1009
-
1010
-
1011
- BitMatrix.prototype.isReserved = function (row, col) {
1012
- return this.reservedBit[row * this.size + col];
1013
- };
1014
-
1015
- var bitMatrix = BitMatrix;
1016
- var alignmentPattern = createCommonjsModule(function (module, exports) {
1017
- /**
1018
- * Alignment pattern are fixed reference pattern in defined positions
1019
- * in a matrix symbology, which enables the decode software to re-synchronise
1020
- * the coordinate mapping of the image modules in the event of moderate amounts
1021
- * of distortion of the image.
1022
- *
1023
- * Alignment patterns are present only in QR Code symbols of version 2 or larger
1024
- * and their number depends on the symbol version.
1025
- */
1026
- var getSymbolSize = utils.getSymbolSize;
1027
- /**
1028
- * Calculate the row/column coordinates of the center module of each alignment pattern
1029
- * for the specified QR Code version.
1030
- *
1031
- * The alignment patterns are positioned symmetrically on either side of the diagonal
1032
- * running from the top left corner of the symbol to the bottom right corner.
1033
- *
1034
- * Since positions are simmetrical only half of the coordinates are returned.
1035
- * Each item of the array will represent in turn the x and y coordinate.
1036
- * @see {@link getPositions}
1037
- *
1038
- * @param {Number} version QR Code version
1039
- * @return {Array} Array of coordinate
1040
- */
1041
-
1042
- exports.getRowColCoords = function getRowColCoords(version) {
1043
- if (version === 1) return [];
1044
- var posCount = Math.floor(version / 7) + 2;
1045
- var size = getSymbolSize(version);
1046
- var intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
1047
- var positions = [size - 7]; // Last coord is always (size - 7)
1048
-
1049
- for (var i = 1; i < posCount - 1; i++) {
1050
- positions[i] = positions[i - 1] - intervals;
1051
- }
1052
-
1053
- positions.push(6); // First coord is always 6
1054
-
1055
- return positions.reverse();
1056
- };
1057
- /**
1058
- * Returns an array containing the positions of each alignment pattern.
1059
- * Each array's element represent the center point of the pattern as (x, y) coordinates
1060
- *
1061
- * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
1062
- * and filtering out the items that overlaps with finder pattern
1063
- *
1064
- * @example
1065
- * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
1066
- * The alignment patterns, therefore, are to be centered on (row, column)
1067
- * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
1068
- * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
1069
- * and are not therefore used for alignment patterns.
1070
- *
1071
- * var pos = getPositions(7)
1072
- * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
1073
- *
1074
- * @param {Number} version QR Code version
1075
- * @return {Array} Array of coordinates
1076
- */
1077
-
1078
-
1079
- exports.getPositions = function getPositions(version) {
1080
- var coords = [];
1081
- var pos = exports.getRowColCoords(version);
1082
- var posLength = pos.length;
1083
-
1084
- for (var i = 0; i < posLength; i++) {
1085
- for (var j = 0; j < posLength; j++) {
1086
- // Skip if position is occupied by finder patterns
1087
- if (i === 0 && j === 0 || // top-left
1088
- i === 0 && j === posLength - 1 || // bottom-left
1089
- i === posLength - 1 && j === 0) {
1090
- // top-right
1091
- continue;
1092
- }
1093
-
1094
- coords.push([pos[i], pos[j]]);
1095
- }
1096
- }
1097
-
1098
- return coords;
1099
- };
1100
- });
1101
- var getSymbolSize$1 = utils.getSymbolSize;
1102
- var FINDER_PATTERN_SIZE = 7;
1103
- /**
1104
- * Returns an array containing the positions of each finder pattern.
1105
- * Each array's element represent the top-left point of the pattern as (x, y) coordinates
1106
- *
1107
- * @param {Number} version QR Code version
1108
- * @return {Array} Array of coordinates
1109
- */
1110
-
1111
- var getPositions = function getPositions(version) {
1112
- var size = getSymbolSize$1(version);
1113
- return [// top-left
1114
- [0, 0], // top-right
1115
- [size - FINDER_PATTERN_SIZE, 0], // bottom-left
1116
- [0, size - FINDER_PATTERN_SIZE]];
1117
- };
1118
-
1119
- var finderPattern = {
1120
- getPositions: getPositions
1121
- };
1122
- var maskPattern = createCommonjsModule(function (module, exports) {
1123
- /**
1124
- * Data mask pattern reference
1125
- * @type {Object}
1126
- */
1127
- exports.Patterns = {
1128
- PATTERN000: 0,
1129
- PATTERN001: 1,
1130
- PATTERN010: 2,
1131
- PATTERN011: 3,
1132
- PATTERN100: 4,
1133
- PATTERN101: 5,
1134
- PATTERN110: 6,
1135
- PATTERN111: 7
1136
- };
1137
- /**
1138
- * Weighted penalty scores for the undesirable features
1139
- * @type {Object}
1140
- */
1141
-
1142
- var PenaltyScores = {
1143
- N1: 3,
1144
- N2: 3,
1145
- N3: 40,
1146
- N4: 10
1147
- };
1148
- /**
1149
- * Check if mask pattern value is valid
1150
- *
1151
- * @param {Number} mask Mask pattern
1152
- * @return {Boolean} true if valid, false otherwise
1153
- */
1154
-
1155
- exports.isValid = function isValid(mask) {
1156
- return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7;
1157
- };
1158
- /**
1159
- * Returns mask pattern from a value.
1160
- * If value is not valid, returns undefined
1161
- *
1162
- * @param {Number|String} value Mask pattern value
1163
- * @return {Number} Valid mask pattern or undefined
1164
- */
1165
-
1166
-
1167
- exports.from = function from(value) {
1168
- return exports.isValid(value) ? parseInt(value, 10) : undefined;
1169
- };
1170
- /**
1171
- * Find adjacent modules in row/column with the same color
1172
- * and assign a penalty value.
1173
- *
1174
- * Points: N1 + i
1175
- * i is the amount by which the number of adjacent modules of the same color exceeds 5
1176
- */
1177
-
1178
-
1179
- exports.getPenaltyN1 = function getPenaltyN1(data) {
1180
- var size = data.size;
1181
- var points = 0;
1182
- var sameCountCol = 0;
1183
- var sameCountRow = 0;
1184
- var lastCol = null;
1185
- var lastRow = null;
1186
-
1187
- for (var row = 0; row < size; row++) {
1188
- sameCountCol = sameCountRow = 0;
1189
- lastCol = lastRow = null;
1190
-
1191
- for (var col = 0; col < size; col++) {
1192
- var module = data.get(row, col);
1193
-
1194
- if (module === lastCol) {
1195
- sameCountCol++;
1196
- } else {
1197
- if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
1198
- lastCol = module;
1199
- sameCountCol = 1;
1200
- }
1201
-
1202
- module = data.get(col, row);
1203
-
1204
- if (module === lastRow) {
1205
- sameCountRow++;
1206
- } else {
1207
- if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
1208
- lastRow = module;
1209
- sameCountRow = 1;
1210
- }
1211
- }
1212
-
1213
- if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
1214
- if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
1215
- }
1216
-
1217
- return points;
1218
- };
1219
- /**
1220
- * Find 2x2 blocks with the same color and assign a penalty value
1221
- *
1222
- * Points: N2 * (m - 1) * (n - 1)
1223
- */
1224
-
1225
-
1226
- exports.getPenaltyN2 = function getPenaltyN2(data) {
1227
- var size = data.size;
1228
- var points = 0;
1229
-
1230
- for (var row = 0; row < size - 1; row++) {
1231
- for (var col = 0; col < size - 1; col++) {
1232
- var last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
1233
- if (last === 4 || last === 0) points++;
1234
- }
1235
- }
1236
-
1237
- return points * PenaltyScores.N2;
1238
- };
1239
- /**
1240
- * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
1241
- * preceded or followed by light area 4 modules wide
1242
- *
1243
- * Points: N3 * number of pattern found
1244
- */
1245
-
1246
-
1247
- exports.getPenaltyN3 = function getPenaltyN3(data) {
1248
- var size = data.size;
1249
- var points = 0;
1250
- var bitsCol = 0;
1251
- var bitsRow = 0;
1252
-
1253
- for (var row = 0; row < size; row++) {
1254
- bitsCol = bitsRow = 0;
1255
-
1256
- for (var col = 0; col < size; col++) {
1257
- bitsCol = bitsCol << 1 & 0x7FF | data.get(row, col);
1258
- if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++;
1259
- bitsRow = bitsRow << 1 & 0x7FF | data.get(col, row);
1260
- if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++;
1261
- }
1262
- }
1263
-
1264
- return points * PenaltyScores.N3;
1265
- };
1266
- /**
1267
- * Calculate proportion of dark modules in entire symbol
1268
- *
1269
- * Points: N4 * k
1270
- *
1271
- * k is the rating of the deviation of the proportion of dark modules
1272
- * in the symbol from 50% in steps of 5%
1273
- */
1274
-
1275
-
1276
- exports.getPenaltyN4 = function getPenaltyN4(data) {
1277
- var darkCount = 0;
1278
- var modulesCount = data.data.length;
1279
-
1280
- for (var i = 0; i < modulesCount; i++) {
1281
- darkCount += data.data[i];
1282
- }
1283
-
1284
- var k = Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10);
1285
- return k * PenaltyScores.N4;
1286
- };
1287
- /**
1288
- * Return mask value at given position
1289
- *
1290
- * @param {Number} maskPattern Pattern reference value
1291
- * @param {Number} i Row
1292
- * @param {Number} j Column
1293
- * @return {Boolean} Mask value
1294
- */
1295
-
1296
-
1297
- function getMaskAt(maskPattern, i, j) {
1298
- switch (maskPattern) {
1299
- case exports.Patterns.PATTERN000:
1300
- return (i + j) % 2 === 0;
1301
-
1302
- case exports.Patterns.PATTERN001:
1303
- return i % 2 === 0;
1304
-
1305
- case exports.Patterns.PATTERN010:
1306
- return j % 3 === 0;
1307
-
1308
- case exports.Patterns.PATTERN011:
1309
- return (i + j) % 3 === 0;
1310
-
1311
- case exports.Patterns.PATTERN100:
1312
- return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
1313
-
1314
- case exports.Patterns.PATTERN101:
1315
- return i * j % 2 + i * j % 3 === 0;
1316
-
1317
- case exports.Patterns.PATTERN110:
1318
- return (i * j % 2 + i * j % 3) % 2 === 0;
1319
-
1320
- case exports.Patterns.PATTERN111:
1321
- return (i * j % 3 + (i + j) % 2) % 2 === 0;
1322
-
1323
- default:
1324
- throw new Error('bad maskPattern:' + maskPattern);
1325
- }
1326
- }
1327
- /**
1328
- * Apply a mask pattern to a BitMatrix
1329
- *
1330
- * @param {Number} pattern Pattern reference number
1331
- * @param {BitMatrix} data BitMatrix data
1332
- */
1333
-
1334
-
1335
- exports.applyMask = function applyMask(pattern, data) {
1336
- var size = data.size;
1337
-
1338
- for (var col = 0; col < size; col++) {
1339
- for (var row = 0; row < size; row++) {
1340
- if (data.isReserved(row, col)) continue;
1341
- data.xor(row, col, getMaskAt(pattern, row, col));
1342
- }
1343
- }
1344
- };
1345
- /**
1346
- * Returns the best mask pattern for data
1347
- *
1348
- * @param {BitMatrix} data
1349
- * @return {Number} Mask pattern reference number
1350
- */
1351
-
1352
-
1353
- exports.getBestMask = function getBestMask(data, setupFormatFunc) {
1354
- var numPatterns = Object.keys(exports.Patterns).length;
1355
- var bestPattern = 0;
1356
- var lowerPenalty = Infinity;
1357
-
1358
- for (var p = 0; p < numPatterns; p++) {
1359
- setupFormatFunc(p);
1360
- exports.applyMask(p, data); // Calculate penalty
1361
-
1362
- var penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data); // Undo previously applied mask
1363
-
1364
- exports.applyMask(p, data);
1365
-
1366
- if (penalty < lowerPenalty) {
1367
- lowerPenalty = penalty;
1368
- bestPattern = p;
1369
- }
1370
- }
1371
-
1372
- return bestPattern;
1373
- };
1374
- });
1375
- var EC_BLOCKS_TABLE = [// L M Q H
1376
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 4, 1, 2, 4, 4, 2, 4, 4, 4, 2, 4, 6, 5, 2, 4, 6, 6, 2, 5, 8, 8, 4, 5, 8, 8, 4, 5, 8, 11, 4, 8, 10, 11, 4, 9, 12, 16, 4, 9, 16, 16, 6, 10, 12, 18, 6, 10, 17, 16, 6, 11, 16, 19, 6, 13, 18, 21, 7, 14, 21, 25, 8, 16, 20, 25, 8, 17, 23, 25, 9, 17, 23, 34, 9, 18, 25, 30, 10, 20, 27, 32, 12, 21, 29, 35, 12, 23, 34, 37, 12, 25, 34, 40, 13, 26, 35, 42, 14, 28, 38, 45, 15, 29, 40, 48, 16, 31, 43, 51, 17, 33, 45, 54, 18, 35, 48, 57, 19, 37, 51, 60, 19, 38, 53, 63, 20, 40, 56, 66, 21, 43, 59, 70, 22, 45, 62, 74, 24, 47, 65, 77, 25, 49, 68, 81];
1377
- var EC_CODEWORDS_TABLE = [// L M Q H
1378
- 7, 10, 13, 17, 10, 16, 22, 28, 15, 26, 36, 44, 20, 36, 52, 64, 26, 48, 72, 88, 36, 64, 96, 112, 40, 72, 108, 130, 48, 88, 132, 156, 60, 110, 160, 192, 72, 130, 192, 224, 80, 150, 224, 264, 96, 176, 260, 308, 104, 198, 288, 352, 120, 216, 320, 384, 132, 240, 360, 432, 144, 280, 408, 480, 168, 308, 448, 532, 180, 338, 504, 588, 196, 364, 546, 650, 224, 416, 600, 700, 224, 442, 644, 750, 252, 476, 690, 816, 270, 504, 750, 900, 300, 560, 810, 960, 312, 588, 870, 1050, 336, 644, 952, 1110, 360, 700, 1020, 1200, 390, 728, 1050, 1260, 420, 784, 1140, 1350, 450, 812, 1200, 1440, 480, 868, 1290, 1530, 510, 924, 1350, 1620, 540, 980, 1440, 1710, 570, 1036, 1530, 1800, 570, 1064, 1590, 1890, 600, 1120, 1680, 1980, 630, 1204, 1770, 2100, 660, 1260, 1860, 2220, 720, 1316, 1950, 2310, 750, 1372, 2040, 2430];
1379
- /**
1380
- * Returns the number of error correction block that the QR Code should contain
1381
- * for the specified version and error correction level.
1382
- *
1383
- * @param {Number} version QR Code version
1384
- * @param {Number} errorCorrectionLevel Error correction level
1385
- * @return {Number} Number of error correction blocks
1386
- */
1387
-
1388
- var getBlocksCount = function getBlocksCount(version, errorCorrectionLevel$1) {
1389
- switch (errorCorrectionLevel$1) {
1390
- case errorCorrectionLevel.L:
1391
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 0];
1392
-
1393
- case errorCorrectionLevel.M:
1394
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 1];
1395
-
1396
- case errorCorrectionLevel.Q:
1397
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 2];
1398
-
1399
- case errorCorrectionLevel.H:
1400
- return EC_BLOCKS_TABLE[(version - 1) * 4 + 3];
1401
-
1402
- default:
1403
- return undefined;
1404
- }
1405
- };
1406
- /**
1407
- * Returns the number of error correction codewords to use for the specified
1408
- * version and error correction level.
1409
- *
1410
- * @param {Number} version QR Code version
1411
- * @param {Number} errorCorrectionLevel Error correction level
1412
- * @return {Number} Number of error correction codewords
1413
- */
1414
-
1415
-
1416
- var getTotalCodewordsCount = function getTotalCodewordsCount(version, errorCorrectionLevel$1) {
1417
- switch (errorCorrectionLevel$1) {
1418
- case errorCorrectionLevel.L:
1419
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0];
1420
-
1421
- case errorCorrectionLevel.M:
1422
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1];
1423
-
1424
- case errorCorrectionLevel.Q:
1425
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2];
1426
-
1427
- case errorCorrectionLevel.H:
1428
- return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3];
1429
-
1430
- default:
1431
- return undefined;
1432
- }
1433
- };
1434
-
1435
- var errorCorrectionCode = {
1436
- getBlocksCount: getBlocksCount,
1437
- getTotalCodewordsCount: getTotalCodewordsCount
1438
- };
1439
- var EXP_TABLE = typedarrayBuffer.alloc(512);
1440
- var LOG_TABLE = typedarrayBuffer.alloc(256);
1441
-
1442
- (function initTables() {
1443
- var x = 1;
1444
-
1445
- for (var i = 0; i < 255; i++) {
1446
- EXP_TABLE[i] = x;
1447
- LOG_TABLE[x] = i;
1448
- x <<= 1; // multiply by 2
1449
- // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
1450
- // This means that when a number is 256 or larger, it should be XORed with 0x11D.
1451
-
1452
- if (x & 0x100) {
1453
- // similar to x >= 256, but a lot faster (because 0x100 == 256)
1454
- x ^= 0x11D;
1455
- }
1456
- } // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
1457
- // stay inside the bounds (because we will mainly use this table for the multiplication of
1458
- // two GF numbers, no more).
1459
- // @see {@link mul}
1460
-
1461
-
1462
- for (i = 255; i < 512; i++) {
1463
- EXP_TABLE[i] = EXP_TABLE[i - 255];
1464
- }
1465
- })();
1466
- /**
1467
- * Returns log value of n inside Galois Field
1468
- *
1469
- * @param {Number} n
1470
- * @return {Number}
1471
- */
1472
-
1473
-
1474
- var log = function log(n) {
1475
- if (n < 1) throw new Error('log(' + n + ')');
1476
- return LOG_TABLE[n];
1477
- };
1478
- /**
1479
- * Returns anti-log value of n inside Galois Field
1480
- *
1481
- * @param {Number} n
1482
- * @return {Number}
1483
- */
1484
-
1485
-
1486
- var exp = function exp(n) {
1487
- return EXP_TABLE[n];
1488
- };
1489
- /**
1490
- * Multiplies two number inside Galois Field
1491
- *
1492
- * @param {Number} x
1493
- * @param {Number} y
1494
- * @return {Number}
1495
- */
1496
-
1497
-
1498
- var mul = function mul(x, y) {
1499
- if (x === 0 || y === 0) return 0; // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
1500
- // @see {@link initTables}
1501
-
1502
- return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]];
1503
- };
1504
-
1505
- var galoisField = {
1506
- log: log,
1507
- exp: exp,
1508
- mul: mul
1509
- };
1510
- var polynomial = createCommonjsModule(function (module, exports) {
1511
- /**
1512
- * Multiplies two polynomials inside Galois Field
1513
- *
1514
- * @param {Buffer} p1 Polynomial
1515
- * @param {Buffer} p2 Polynomial
1516
- * @return {Buffer} Product of p1 and p2
1517
- */
1518
- exports.mul = function mul(p1, p2) {
1519
- var coeff = typedarrayBuffer.alloc(p1.length + p2.length - 1);
1520
-
1521
- for (var i = 0; i < p1.length; i++) {
1522
- for (var j = 0; j < p2.length; j++) {
1523
- coeff[i + j] ^= galoisField.mul(p1[i], p2[j]);
1524
- }
1525
- }
1526
-
1527
- return coeff;
1528
- };
1529
- /**
1530
- * Calculate the remainder of polynomials division
1531
- *
1532
- * @param {Buffer} divident Polynomial
1533
- * @param {Buffer} divisor Polynomial
1534
- * @return {Buffer} Remainder
1535
- */
1536
-
1537
-
1538
- exports.mod = function mod(divident, divisor) {
1539
- var result = typedarrayBuffer.from(divident);
1540
-
1541
- while (result.length - divisor.length >= 0) {
1542
- var coeff = result[0];
1543
-
1544
- for (var i = 0; i < divisor.length; i++) {
1545
- result[i] ^= galoisField.mul(divisor[i], coeff);
1546
- } // remove all zeros from buffer head
1547
-
1548
-
1549
- var offset = 0;
1550
-
1551
- while (offset < result.length && result[offset] === 0) {
1552
- offset++;
1553
- }
1554
-
1555
- result = result.slice(offset);
1556
- }
1557
-
1558
- return result;
1559
- };
1560
- /**
1561
- * Generate an irreducible generator polynomial of specified degree
1562
- * (used by Reed-Solomon encoder)
1563
- *
1564
- * @param {Number} degree Degree of the generator polynomial
1565
- * @return {Buffer} Buffer containing polynomial coefficients
1566
- */
1567
-
1568
-
1569
- exports.generateECPolynomial = function generateECPolynomial(degree) {
1570
- var poly = typedarrayBuffer.from([1]);
1571
-
1572
- for (var i = 0; i < degree; i++) {
1573
- poly = exports.mul(poly, [1, galoisField.exp(i)]);
1574
- }
1575
-
1576
- return poly;
1577
- };
1578
- });
1579
- var Buffer$1 = buffer__WEBPACK_IMPORTED_MODULE_8___default.a.Buffer;
1580
-
1581
- function ReedSolomonEncoder(degree) {
1582
- this.genPoly = undefined;
1583
- this.degree = degree;
1584
- if (this.degree) this.initialize(this.degree);
1585
- }
1586
- /**
1587
- * Initialize the encoder.
1588
- * The input param should correspond to the number of error correction codewords.
1589
- *
1590
- * @param {Number} degree
1591
- */
1592
-
1593
-
1594
- ReedSolomonEncoder.prototype.initialize = function initialize(degree) {
1595
- // create an irreducible generator polynomial
1596
- this.degree = degree;
1597
- this.genPoly = polynomial.generateECPolynomial(this.degree);
1598
- };
1599
- /**
1600
- * Encodes a chunk of data
1601
- *
1602
- * @param {Buffer} data Buffer containing input data
1603
- * @return {Buffer} Buffer containing encoded data
1604
- */
1605
-
1606
-
1607
- ReedSolomonEncoder.prototype.encode = function encode(data) {
1608
- if (!this.genPoly) {
1609
- throw new Error('Encoder not initialized');
1610
- } // Calculate EC for this data block
1611
- // extends data size to data+genPoly size
1612
-
1613
-
1614
- var pad = typedarrayBuffer.alloc(this.degree);
1615
- var paddedData = Buffer$1.concat([data, pad], data.length + this.degree); // The error correction codewords are the remainder after dividing the data codewords
1616
- // by a generator polynomial
1617
-
1618
- var remainder = polynomial.mod(paddedData, this.genPoly); // return EC data blocks (last n byte, where n is the degree of genPoly)
1619
- // If coefficients number in remainder are less than genPoly degree,
1620
- // pad with 0s to the left to reach the needed number of coefficients
1621
-
1622
- var start = this.degree - remainder.length;
1623
-
1624
- if (start > 0) {
1625
- var buff = typedarrayBuffer.alloc(this.degree);
1626
- remainder.copy(buff, start);
1627
- return buff;
1628
- }
1629
-
1630
- return remainder;
1631
- };
1632
-
1633
- var reedSolomonEncoder = ReedSolomonEncoder;
1634
- /**
1635
- * Check if QR Code version is valid
1636
- *
1637
- * @param {Number} version QR Code version
1638
- * @return {Boolean} true if valid version, false otherwise
1639
- */
1640
-
1641
- var isValid = function isValid(version) {
1642
- return !isNaN(version) && version >= 1 && version <= 40;
1643
- };
1644
-
1645
- var versionCheck = {
1646
- isValid: isValid
1647
- };
1648
- var numeric = '[0-9]+';
1649
- var alphanumeric = '[A-Z $%*+\\-./:]+';
1650
- var kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' + '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' + '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' + '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+';
1651
- kanji = kanji.replace(/u/g, "\\u");
1652
-
1653
- var _byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+';
1654
-
1655
- var KANJI = new RegExp(kanji, 'g');
1656
- var BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g');
1657
- var BYTE = new RegExp(_byte, 'g');
1658
- var NUMERIC = new RegExp(numeric, 'g');
1659
- var ALPHANUMERIC = new RegExp(alphanumeric, 'g');
1660
- var TEST_KANJI = new RegExp('^' + kanji + '$');
1661
- var TEST_NUMERIC = new RegExp('^' + numeric + '$');
1662
- var TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$');
1663
-
1664
- var testKanji = function testKanji(str) {
1665
- return TEST_KANJI.test(str);
1666
- };
1667
-
1668
- var testNumeric = function testNumeric(str) {
1669
- return TEST_NUMERIC.test(str);
1670
- };
1671
-
1672
- var testAlphanumeric = function testAlphanumeric(str) {
1673
- return TEST_ALPHANUMERIC.test(str);
1674
- };
1675
-
1676
- var regex = {
1677
- KANJI: KANJI,
1678
- BYTE_KANJI: BYTE_KANJI,
1679
- BYTE: BYTE,
1680
- NUMERIC: NUMERIC,
1681
- ALPHANUMERIC: ALPHANUMERIC,
1682
- testKanji: testKanji,
1683
- testNumeric: testNumeric,
1684
- testAlphanumeric: testAlphanumeric
1685
- };
1686
- var mode = createCommonjsModule(function (module, exports) {
1687
- /**
1688
- * Numeric mode encodes data from the decimal digit set (0 - 9)
1689
- * (byte values 30HEX to 39HEX).
1690
- * Normally, 3 data characters are represented by 10 bits.
1691
- *
1692
- * @type {Object}
1693
- */
1694
- exports.NUMERIC = {
1695
- id: 'Numeric',
1696
- bit: 1 << 0,
1697
- ccBits: [10, 12, 14]
1698
- };
1699
- /**
1700
- * Alphanumeric mode encodes data from a set of 45 characters,
1701
- * i.e. 10 numeric digits (0 - 9),
1702
- * 26 alphabetic characters (A - Z),
1703
- * and 9 symbols (SP, $, %, *, +, -, ., /, :).
1704
- * Normally, two input characters are represented by 11 bits.
1705
- *
1706
- * @type {Object}
1707
- */
1708
-
1709
- exports.ALPHANUMERIC = {
1710
- id: 'Alphanumeric',
1711
- bit: 1 << 1,
1712
- ccBits: [9, 11, 13]
1713
- };
1714
- /**
1715
- * In byte mode, data is encoded at 8 bits per character.
1716
- *
1717
- * @type {Object}
1718
- */
1719
-
1720
- exports.BYTE = {
1721
- id: 'Byte',
1722
- bit: 1 << 2,
1723
- ccBits: [8, 16, 16]
1724
- };
1725
- /**
1726
- * The Kanji mode efficiently encodes Kanji characters in accordance with
1727
- * the Shift JIS system based on JIS X 0208.
1728
- * The Shift JIS values are shifted from the JIS X 0208 values.
1729
- * JIS X 0208 gives details of the shift coded representation.
1730
- * Each two-byte character value is compacted to a 13-bit binary codeword.
1731
- *
1732
- * @type {Object}
1733
- */
1734
-
1735
- exports.KANJI = {
1736
- id: 'Kanji',
1737
- bit: 1 << 3,
1738
- ccBits: [8, 10, 12]
1739
- };
1740
- /**
1741
- * Mixed mode will contain a sequences of data in a combination of any of
1742
- * the modes described above
1743
- *
1744
- * @type {Object}
1745
- */
1746
-
1747
- exports.MIXED = {
1748
- bit: -1
1749
- };
1750
- /**
1751
- * Returns the number of bits needed to store the data length
1752
- * according to QR Code specifications.
1753
- *
1754
- * @param {Mode} mode Data mode
1755
- * @param {Number} version QR Code version
1756
- * @return {Number} Number of bits
1757
- */
1758
-
1759
- exports.getCharCountIndicator = function getCharCountIndicator(mode, version) {
1760
- if (!mode.ccBits) throw new Error('Invalid mode: ' + mode);
1761
-
1762
- if (!versionCheck.isValid(version)) {
1763
- throw new Error('Invalid version: ' + version);
1764
- }
1765
-
1766
- if (version >= 1 && version < 10) return mode.ccBits[0];else if (version < 27) return mode.ccBits[1];
1767
- return mode.ccBits[2];
1768
- };
1769
- /**
1770
- * Returns the most efficient mode to store the specified data
1771
- *
1772
- * @param {String} dataStr Input data string
1773
- * @return {Mode} Best mode
1774
- */
1775
-
1776
-
1777
- exports.getBestModeForData = function getBestModeForData(dataStr) {
1778
- if (regex.testNumeric(dataStr)) return exports.NUMERIC;else if (regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC;else if (regex.testKanji(dataStr)) return exports.KANJI;else return exports.BYTE;
1779
- };
1780
- /**
1781
- * Return mode name as string
1782
- *
1783
- * @param {Mode} mode Mode object
1784
- * @returns {String} Mode name
1785
- */
1786
-
1787
-
1788
- exports.toString = function toString(mode) {
1789
- if (mode && mode.id) return mode.id;
1790
- throw new Error('Invalid mode');
1791
- };
1792
- /**
1793
- * Check if input param is a valid mode object
1794
- *
1795
- * @param {Mode} mode Mode object
1796
- * @returns {Boolean} True if valid mode, false otherwise
1797
- */
1798
-
1799
-
1800
- exports.isValid = function isValid(mode) {
1801
- return mode && mode.bit && mode.ccBits;
1802
- };
1803
- /**
1804
- * Get mode object from its name
1805
- *
1806
- * @param {String} string Mode name
1807
- * @returns {Mode} Mode object
1808
- */
1809
-
1810
-
1811
- function fromString(string) {
1812
- if (typeof string !== 'string') {
1813
- throw new Error('Param is not a string');
1814
- }
1815
-
1816
- var lcStr = string.toLowerCase();
1817
-
1818
- switch (lcStr) {
1819
- case 'numeric':
1820
- return exports.NUMERIC;
1821
-
1822
- case 'alphanumeric':
1823
- return exports.ALPHANUMERIC;
1824
-
1825
- case 'kanji':
1826
- return exports.KANJI;
1827
-
1828
- case 'byte':
1829
- return exports.BYTE;
1830
-
1831
- default:
1832
- throw new Error('Unknown mode: ' + string);
1833
- }
1834
- }
1835
- /**
1836
- * Returns mode from a value.
1837
- * If value is not a valid mode, returns defaultValue
1838
- *
1839
- * @param {Mode|String} value Encoding mode
1840
- * @param {Mode} defaultValue Fallback value
1841
- * @return {Mode} Encoding mode
1842
- */
1843
-
1844
-
1845
- exports.from = function from(value, defaultValue) {
1846
- if (exports.isValid(value)) {
1847
- return value;
1848
- }
1849
-
1850
- try {
1851
- return fromString(value);
1852
- } catch (e) {
1853
- return defaultValue;
1854
- }
1855
- };
1856
- });
1857
- var version = createCommonjsModule(function (module, exports) {
1858
- // Generator polynomial used to encode version information
1859
- var G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
1860
- var G18_BCH = utils.getBCHDigit(G18);
1861
-
1862
- function getBestVersionForDataLength(mode, length, errorCorrectionLevel) {
1863
- for (var currentVersion = 1; currentVersion <= 40; currentVersion++) {
1864
- if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
1865
- return currentVersion;
1866
- }
1867
- }
1868
-
1869
- return undefined;
1870
- }
1871
-
1872
- function getReservedBitsCount(mode$1, version) {
1873
- // Character count indicator + mode indicator bits
1874
- return mode.getCharCountIndicator(mode$1, version) + 4;
1875
- }
1876
-
1877
- function getTotalBitsFromDataArray(segments, version) {
1878
- var totalBits = 0;
1879
- segments.forEach(function (data) {
1880
- var reservedBits = getReservedBitsCount(data.mode, version);
1881
- totalBits += reservedBits + data.getBitsLength();
1882
- });
1883
- return totalBits;
1884
- }
1885
-
1886
- function getBestVersionForMixedData(segments, errorCorrectionLevel) {
1887
- for (var currentVersion = 1; currentVersion <= 40; currentVersion++) {
1888
- var length = getTotalBitsFromDataArray(segments, currentVersion);
1889
-
1890
- if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode.MIXED)) {
1891
- return currentVersion;
1892
- }
1893
- }
1894
-
1895
- return undefined;
1896
- }
1897
- /**
1898
- * Returns version number from a value.
1899
- * If value is not a valid version, returns defaultValue
1900
- *
1901
- * @param {Number|String} value QR Code version
1902
- * @param {Number} defaultValue Fallback value
1903
- * @return {Number} QR Code version number
1904
- */
1905
-
1906
-
1907
- exports.from = function from(value, defaultValue) {
1908
- if (versionCheck.isValid(value)) {
1909
- return parseInt(value, 10);
1910
- }
1911
-
1912
- return defaultValue;
1913
- };
1914
- /**
1915
- * Returns how much data can be stored with the specified QR code version
1916
- * and error correction level
1917
- *
1918
- * @param {Number} version QR Code version (1-40)
1919
- * @param {Number} errorCorrectionLevel Error correction level
1920
- * @param {Mode} mode Data mode
1921
- * @return {Number} Quantity of storable data
1922
- */
1923
-
1924
-
1925
- exports.getCapacity = function getCapacity(version, errorCorrectionLevel, mode$1) {
1926
- if (!versionCheck.isValid(version)) {
1927
- throw new Error('Invalid QR Code version');
1928
- } // Use Byte mode as default
1929
-
1930
-
1931
- if (typeof mode$1 === 'undefined') mode$1 = mode.BYTE; // Total codewords for this QR code version (Data + Error correction)
1932
-
1933
- var totalCodewords = utils.getSymbolTotalCodewords(version); // Total number of error correction codewords
1934
-
1935
- var ecTotalCodewords = errorCorrectionCode.getTotalCodewordsCount(version, errorCorrectionLevel); // Total number of data codewords
1936
-
1937
- var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
1938
- if (mode$1 === mode.MIXED) return dataTotalCodewordsBits;
1939
- var usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode$1, version); // Return max number of storable codewords
1940
-
1941
- switch (mode$1) {
1942
- case mode.NUMERIC:
1943
- return Math.floor(usableBits / 10 * 3);
1944
-
1945
- case mode.ALPHANUMERIC:
1946
- return Math.floor(usableBits / 11 * 2);
1947
-
1948
- case mode.KANJI:
1949
- return Math.floor(usableBits / 13);
1950
-
1951
- case mode.BYTE:
1952
- default:
1953
- return Math.floor(usableBits / 8);
1954
- }
1955
- };
1956
- /**
1957
- * Returns the minimum version needed to contain the amount of data
1958
- *
1959
- * @param {Segment} data Segment of data
1960
- * @param {Number} [errorCorrectionLevel=H] Error correction level
1961
- * @param {Mode} mode Data mode
1962
- * @return {Number} QR Code version
1963
- */
1964
-
1965
-
1966
- exports.getBestVersionForData = function getBestVersionForData(data, errorCorrectionLevel$1) {
1967
- var seg;
1968
- var ecl = errorCorrectionLevel.from(errorCorrectionLevel$1, errorCorrectionLevel.M);
1969
-
1970
- if (isarray(data)) {
1971
- if (data.length > 1) {
1972
- return getBestVersionForMixedData(data, ecl);
1973
- }
1974
-
1975
- if (data.length === 0) {
1976
- return 1;
1977
- }
1978
-
1979
- seg = data[0];
1980
- } else {
1981
- seg = data;
1982
- }
1983
-
1984
- return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl);
1985
- };
1986
- /**
1987
- * Returns version information with relative error correction bits
1988
- *
1989
- * The version information is included in QR Code symbols of version 7 or larger.
1990
- * It consists of an 18-bit sequence containing 6 data bits,
1991
- * with 12 error correction bits calculated using the (18, 6) Golay code.
1992
- *
1993
- * @param {Number} version QR Code version
1994
- * @return {Number} Encoded version info bits
1995
- */
1996
-
1997
-
1998
- exports.getEncodedBits = function getEncodedBits(version) {
1999
- if (!versionCheck.isValid(version) || version < 7) {
2000
- throw new Error('Invalid QR Code version');
2001
- }
2002
-
2003
- var d = version << 12;
2004
-
2005
- while (utils.getBCHDigit(d) - G18_BCH >= 0) {
2006
- d ^= G18 << utils.getBCHDigit(d) - G18_BCH;
2007
- }
2008
-
2009
- return version << 12 | d;
2010
- };
2011
- });
2012
- var G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
2013
- var G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
2014
- var G15_BCH = utils.getBCHDigit(G15);
2015
- /**
2016
- * Returns format information with relative error correction bits
2017
- *
2018
- * The format information is a 15-bit sequence containing 5 data bits,
2019
- * with 10 error correction bits calculated using the (15, 5) BCH code.
2020
- *
2021
- * @param {Number} errorCorrectionLevel Error correction level
2022
- * @param {Number} mask Mask pattern
2023
- * @return {Number} Encoded format information bits
2024
- */
2025
-
2026
- var getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {
2027
- var data = errorCorrectionLevel.bit << 3 | mask;
2028
- var d = data << 10;
2029
-
2030
- while (utils.getBCHDigit(d) - G15_BCH >= 0) {
2031
- d ^= G15 << utils.getBCHDigit(d) - G15_BCH;
2032
- } // xor final data with mask pattern in order to ensure that
2033
- // no combination of Error Correction Level and data mask pattern
2034
- // will result in an all-zero data string
2035
-
2036
-
2037
- return (data << 10 | d) ^ G15_MASK;
2038
- };
2039
-
2040
- var formatInfo = {
2041
- getEncodedBits: getEncodedBits
2042
- };
2043
-
2044
- function NumericData(data) {
2045
- this.mode = mode.NUMERIC;
2046
- this.data = data.toString();
2047
- }
2048
-
2049
- NumericData.getBitsLength = function getBitsLength(length) {
2050
- return 10 * Math.floor(length / 3) + (length % 3 ? length % 3 * 3 + 1 : 0);
2051
- };
2052
-
2053
- NumericData.prototype.getLength = function getLength() {
2054
- return this.data.length;
2055
- };
2056
-
2057
- NumericData.prototype.getBitsLength = function getBitsLength() {
2058
- return NumericData.getBitsLength(this.data.length);
2059
- };
2060
-
2061
- NumericData.prototype.write = function write(bitBuffer) {
2062
- var i, group, value; // The input data string is divided into groups of three digits,
2063
- // and each group is converted to its 10-bit binary equivalent.
2064
-
2065
- for (i = 0; i + 3 <= this.data.length; i += 3) {
2066
- group = this.data.substr(i, 3);
2067
- value = parseInt(group, 10);
2068
- bitBuffer.put(value, 10);
2069
- } // If the number of input digits is not an exact multiple of three,
2070
- // the final one or two digits are converted to 4 or 7 bits respectively.
2071
-
2072
-
2073
- var remainingNum = this.data.length - i;
2074
-
2075
- if (remainingNum > 0) {
2076
- group = this.data.substr(i);
2077
- value = parseInt(group, 10);
2078
- bitBuffer.put(value, remainingNum * 3 + 1);
2079
- }
2080
- };
2081
-
2082
- var numericData = NumericData;
2083
- /**
2084
- * Array of characters available in alphanumeric mode
2085
- *
2086
- * As per QR Code specification, to each character
2087
- * is assigned a value from 0 to 44 which in this case coincides
2088
- * with the array index
2089
- *
2090
- * @type {Array}
2091
- */
2092
-
2093
- var ALPHA_NUM_CHARS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':'];
2094
-
2095
- function AlphanumericData(data) {
2096
- this.mode = mode.ALPHANUMERIC;
2097
- this.data = data;
2098
- }
2099
-
2100
- AlphanumericData.getBitsLength = function getBitsLength(length) {
2101
- return 11 * Math.floor(length / 2) + 6 * (length % 2);
2102
- };
2103
-
2104
- AlphanumericData.prototype.getLength = function getLength() {
2105
- return this.data.length;
2106
- };
2107
-
2108
- AlphanumericData.prototype.getBitsLength = function getBitsLength() {
2109
- return AlphanumericData.getBitsLength(this.data.length);
2110
- };
2111
-
2112
- AlphanumericData.prototype.write = function write(bitBuffer) {
2113
- var i; // Input data characters are divided into groups of two characters
2114
- // and encoded as 11-bit binary codes.
2115
-
2116
- for (i = 0; i + 2 <= this.data.length; i += 2) {
2117
- // The character value of the first character is multiplied by 45
2118
- var value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45; // The character value of the second digit is added to the product
2119
-
2120
- value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]); // The sum is then stored as 11-bit binary number
2121
-
2122
- bitBuffer.put(value, 11);
2123
- } // If the number of input data characters is not a multiple of two,
2124
- // the character value of the final character is encoded as a 6-bit binary number.
2125
-
2126
-
2127
- if (this.data.length % 2) {
2128
- bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
2129
- }
2130
- };
2131
-
2132
- var alphanumericData = AlphanumericData;
2133
-
2134
- function ByteData(data) {
2135
- this.mode = mode.BYTE;
2136
- this.data = typedarrayBuffer.from(data);
2137
- }
2138
-
2139
- ByteData.getBitsLength = function getBitsLength(length) {
2140
- return length * 8;
2141
- };
2142
-
2143
- ByteData.prototype.getLength = function getLength() {
2144
- return this.data.length;
2145
- };
2146
-
2147
- ByteData.prototype.getBitsLength = function getBitsLength() {
2148
- return ByteData.getBitsLength(this.data.length);
2149
- };
2150
-
2151
- ByteData.prototype.write = function (bitBuffer) {
2152
- for (var i = 0, l = this.data.length; i < l; i++) {
2153
- bitBuffer.put(this.data[i], 8);
2154
- }
2155
- };
2156
-
2157
- var byteData = ByteData;
2158
-
2159
- function KanjiData(data) {
2160
- this.mode = mode.KANJI;
2161
- this.data = data;
2162
- }
2163
-
2164
- KanjiData.getBitsLength = function getBitsLength(length) {
2165
- return length * 13;
2166
- };
2167
-
2168
- KanjiData.prototype.getLength = function getLength() {
2169
- return this.data.length;
2170
- };
2171
-
2172
- KanjiData.prototype.getBitsLength = function getBitsLength() {
2173
- return KanjiData.getBitsLength(this.data.length);
2174
- };
2175
-
2176
- KanjiData.prototype.write = function (bitBuffer) {
2177
- var i; // In the Shift JIS system, Kanji characters are represented by a two byte combination.
2178
- // These byte values are shifted from the JIS X 0208 values.
2179
- // JIS X 0208 gives details of the shift coded representation.
2180
-
2181
- for (i = 0; i < this.data.length; i++) {
2182
- var value = utils.toSJIS(this.data[i]); // For characters with Shift JIS values from 0x8140 to 0x9FFC:
2183
-
2184
- if (value >= 0x8140 && value <= 0x9FFC) {
2185
- // Subtract 0x8140 from Shift JIS value
2186
- value -= 0x8140; // For characters with Shift JIS values from 0xE040 to 0xEBBF
2187
- } else if (value >= 0xE040 && value <= 0xEBBF) {
2188
- // Subtract 0xC140 from Shift JIS value
2189
- value -= 0xC140;
2190
- } else {
2191
- throw new Error('Invalid SJIS character: ' + this.data[i] + '\n' + 'Make sure your charset is UTF-8');
2192
- } // Multiply most significant byte of result by 0xC0
2193
- // and add least significant byte to product
2194
-
2195
-
2196
- value = (value >>> 8 & 0xff) * 0xC0 + (value & 0xff); // Convert result to a 13-bit binary string
2197
-
2198
- bitBuffer.put(value, 13);
2199
- }
2200
- };
2201
-
2202
- var kanjiData = KanjiData;
2203
- var dijkstra_1 = createCommonjsModule(function (module) {
2204
- /******************************************************************************
2205
- * Created 2008-08-19.
2206
- *
2207
- * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
2208
- *
2209
- * Copyright (C) 2008
2210
- * Wyatt Baldwin <self@wyattbaldwin.com>
2211
- * All rights reserved
2212
- *
2213
- * Licensed under the MIT license.
2214
- *
2215
- * http://www.opensource.org/licenses/mit-license.php
2216
- *
2217
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2218
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2219
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2220
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2221
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2222
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2223
- * THE SOFTWARE.
2224
- *****************************************************************************/
2225
- var dijkstra = {
2226
- single_source_shortest_paths: function single_source_shortest_paths(graph, s, d) {
2227
- // Predecessor map for each node that has been encountered.
2228
- // node ID => predecessor node ID
2229
- var predecessors = {}; // Costs of shortest paths from s to all nodes encountered.
2230
- // node ID => cost
2231
-
2232
- var costs = {};
2233
- costs[s] = 0; // Costs of shortest paths from s to all nodes encountered; differs from
2234
- // `costs` in that it provides easy access to the node that currently has
2235
- // the known shortest path from s.
2236
- // XXX: Do we actually need both `costs` and `open`?
2237
-
2238
- var open = dijkstra.PriorityQueue.make();
2239
- open.push(s, 0);
2240
- var closest, u, v, cost_of_s_to_u, adjacent_nodes, cost_of_e, cost_of_s_to_u_plus_cost_of_e, cost_of_s_to_v, first_visit;
2241
-
2242
- while (!open.empty()) {
2243
- // In the nodes remaining in graph that have a known cost from s,
2244
- // find the node, u, that currently has the shortest path from s.
2245
- closest = open.pop();
2246
- u = closest.value;
2247
- cost_of_s_to_u = closest.cost; // Get nodes adjacent to u...
2248
-
2249
- adjacent_nodes = graph[u] || {}; // ...and explore the edges that connect u to those nodes, updating
2250
- // the cost of the shortest paths to any or all of those nodes as
2251
- // necessary. v is the node across the current edge from u.
2252
-
2253
- for (v in adjacent_nodes) {
2254
- if (adjacent_nodes.hasOwnProperty(v)) {
2255
- // Get the cost of the edge running from u to v.
2256
- cost_of_e = adjacent_nodes[v]; // Cost of s to u plus the cost of u to v across e--this is *a*
2257
- // cost from s to v that may or may not be less than the current
2258
- // known cost to v.
2259
-
2260
- cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e; // If we haven't visited v yet OR if the current known cost from s to
2261
- // v is greater than the new cost we just found (cost of s to u plus
2262
- // cost of u to v across e), update v's cost in the cost list and
2263
- // update v's predecessor in the predecessor list (it's now u).
2264
-
2265
- cost_of_s_to_v = costs[v];
2266
- first_visit = typeof costs[v] === 'undefined';
2267
-
2268
- if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
2269
- costs[v] = cost_of_s_to_u_plus_cost_of_e;
2270
- open.push(v, cost_of_s_to_u_plus_cost_of_e);
2271
- predecessors[v] = u;
2272
- }
2273
- }
2274
- }
2275
- }
2276
-
2277
- if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
2278
- var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
2279
- throw new Error(msg);
2280
- }
2281
-
2282
- return predecessors;
2283
- },
2284
- extract_shortest_path_from_predecessor_list: function extract_shortest_path_from_predecessor_list(predecessors, d) {
2285
- var nodes = [];
2286
- var u = d;
2287
-
2288
- while (u) {
2289
- nodes.push(u);
2290
- u = predecessors[u];
2291
- }
2292
-
2293
- nodes.reverse();
2294
- return nodes;
2295
- },
2296
- find_path: function find_path(graph, s, d) {
2297
- var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
2298
- return dijkstra.extract_shortest_path_from_predecessor_list(predecessors, d);
2299
- },
2300
-
2301
- /**
2302
- * A very naive priority queue implementation.
2303
- */
2304
- PriorityQueue: {
2305
- make: function make(opts) {
2306
- var T = dijkstra.PriorityQueue,
2307
- t = {},
2308
- key;
2309
- opts = opts || {};
2310
-
2311
- for (key in T) {
2312
- if (T.hasOwnProperty(key)) {
2313
- t[key] = T[key];
2314
- }
2315
- }
2316
-
2317
- t.queue = [];
2318
- t.sorter = opts.sorter || T.default_sorter;
2319
- return t;
2320
- },
2321
- default_sorter: function default_sorter(a, b) {
2322
- return a.cost - b.cost;
2323
- },
2324
-
2325
- /**
2326
- * Add a new item to the queue and ensure the highest priority element
2327
- * is at the front of the queue.
2328
- */
2329
- push: function push(value, cost) {
2330
- var item = {
2331
- value: value,
2332
- cost: cost
2333
- };
2334
- this.queue.push(item);
2335
- this.queue.sort(this.sorter);
2336
- },
2337
-
2338
- /**
2339
- * Return the highest priority element in the queue.
2340
- */
2341
- pop: function pop() {
2342
- return this.queue.shift();
2343
- },
2344
- empty: function empty() {
2345
- return this.queue.length === 0;
2346
- }
2347
- }
2348
- }; // node.js module exports
2349
-
2350
- {
2351
- module.exports = dijkstra;
2352
- }
2353
- });
2354
- var segments = createCommonjsModule(function (module, exports) {
2355
- /**
2356
- * Returns UTF8 byte length
2357
- *
2358
- * @param {String} str Input string
2359
- * @return {Number} Number of byte
2360
- */
2361
- function getStringByteLength(str) {
2362
- return unescape(encodeURIComponent(str)).length;
2363
- }
2364
- /**
2365
- * Get a list of segments of the specified mode
2366
- * from a string
2367
- *
2368
- * @param {Mode} mode Segment mode
2369
- * @param {String} str String to process
2370
- * @return {Array} Array of object with segments data
2371
- */
2372
-
2373
-
2374
- function getSegments(regex, mode, str) {
2375
- var segments = [];
2376
- var result;
2377
-
2378
- while ((result = regex.exec(str)) !== null) {
2379
- segments.push({
2380
- data: result[0],
2381
- index: result.index,
2382
- mode: mode,
2383
- length: result[0].length
2384
- });
2385
- }
2386
-
2387
- return segments;
2388
- }
2389
- /**
2390
- * Extracts a series of segments with the appropriate
2391
- * modes from a string
2392
- *
2393
- * @param {String} dataStr Input string
2394
- * @return {Array} Array of object with segments data
2395
- */
2396
-
2397
-
2398
- function getSegmentsFromString(dataStr) {
2399
- var numSegs = getSegments(regex.NUMERIC, mode.NUMERIC, dataStr);
2400
- var alphaNumSegs = getSegments(regex.ALPHANUMERIC, mode.ALPHANUMERIC, dataStr);
2401
- var byteSegs;
2402
- var kanjiSegs;
2403
-
2404
- if (utils.isKanjiModeEnabled()) {
2405
- byteSegs = getSegments(regex.BYTE, mode.BYTE, dataStr);
2406
- kanjiSegs = getSegments(regex.KANJI, mode.KANJI, dataStr);
2407
- } else {
2408
- byteSegs = getSegments(regex.BYTE_KANJI, mode.BYTE, dataStr);
2409
- kanjiSegs = [];
2410
- }
2411
-
2412
- var segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
2413
- return segs.sort(function (s1, s2) {
2414
- return s1.index - s2.index;
2415
- }).map(function (obj) {
2416
- return {
2417
- data: obj.data,
2418
- mode: obj.mode,
2419
- length: obj.length
2420
- };
2421
- });
2422
- }
2423
- /**
2424
- * Returns how many bits are needed to encode a string of
2425
- * specified length with the specified mode
2426
- *
2427
- * @param {Number} length String length
2428
- * @param {Mode} mode Segment mode
2429
- * @return {Number} Bit length
2430
- */
2431
-
2432
-
2433
- function getSegmentBitsLength(length, mode$1) {
2434
- switch (mode$1) {
2435
- case mode.NUMERIC:
2436
- return numericData.getBitsLength(length);
2437
-
2438
- case mode.ALPHANUMERIC:
2439
- return alphanumericData.getBitsLength(length);
2440
-
2441
- case mode.KANJI:
2442
- return kanjiData.getBitsLength(length);
2443
-
2444
- case mode.BYTE:
2445
- return byteData.getBitsLength(length);
2446
- }
2447
- }
2448
- /**
2449
- * Merges adjacent segments which have the same mode
2450
- *
2451
- * @param {Array} segs Array of object with segments data
2452
- * @return {Array} Array of object with segments data
2453
- */
2454
-
2455
-
2456
- function mergeSegments(segs) {
2457
- return segs.reduce(function (acc, curr) {
2458
- var prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
2459
-
2460
- if (prevSeg && prevSeg.mode === curr.mode) {
2461
- acc[acc.length - 1].data += curr.data;
2462
- return acc;
2463
- }
2464
-
2465
- acc.push(curr);
2466
- return acc;
2467
- }, []);
2468
- }
2469
- /**
2470
- * Generates a list of all possible nodes combination which
2471
- * will be used to build a segments graph.
2472
- *
2473
- * Nodes are divided by groups. Each group will contain a list of all the modes
2474
- * in which is possible to encode the given text.
2475
- *
2476
- * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
2477
- * The group for '12345' will contain then 3 objects, one for each
2478
- * possible encoding mode.
2479
- *
2480
- * Each node represents a possible segment.
2481
- *
2482
- * @param {Array} segs Array of object with segments data
2483
- * @return {Array} Array of object with segments data
2484
- */
2485
-
2486
-
2487
- function buildNodes(segs) {
2488
- var nodes = [];
2489
-
2490
- for (var i = 0; i < segs.length; i++) {
2491
- var seg = segs[i];
2492
-
2493
- switch (seg.mode) {
2494
- case mode.NUMERIC:
2495
- nodes.push([seg, {
2496
- data: seg.data,
2497
- mode: mode.ALPHANUMERIC,
2498
- length: seg.length
2499
- }, {
2500
- data: seg.data,
2501
- mode: mode.BYTE,
2502
- length: seg.length
2503
- }]);
2504
- break;
2505
-
2506
- case mode.ALPHANUMERIC:
2507
- nodes.push([seg, {
2508
- data: seg.data,
2509
- mode: mode.BYTE,
2510
- length: seg.length
2511
- }]);
2512
- break;
2513
-
2514
- case mode.KANJI:
2515
- nodes.push([seg, {
2516
- data: seg.data,
2517
- mode: mode.BYTE,
2518
- length: getStringByteLength(seg.data)
2519
- }]);
2520
- break;
2521
-
2522
- case mode.BYTE:
2523
- nodes.push([{
2524
- data: seg.data,
2525
- mode: mode.BYTE,
2526
- length: getStringByteLength(seg.data)
2527
- }]);
2528
- }
2529
- }
2530
-
2531
- return nodes;
2532
- }
2533
- /**
2534
- * Builds a graph from a list of nodes.
2535
- * All segments in each node group will be connected with all the segments of
2536
- * the next group and so on.
2537
- *
2538
- * At each connection will be assigned a weight depending on the
2539
- * segment's byte length.
2540
- *
2541
- * @param {Array} nodes Array of object with segments data
2542
- * @param {Number} version QR Code version
2543
- * @return {Object} Graph of all possible segments
2544
- */
2545
-
2546
-
2547
- function buildGraph(nodes, version) {
2548
- var table = {};
2549
- var graph = {
2550
- 'start': {}
2551
- };
2552
- var prevNodeIds = ['start'];
2553
-
2554
- for (var i = 0; i < nodes.length; i++) {
2555
- var nodeGroup = nodes[i];
2556
- var currentNodeIds = [];
2557
-
2558
- for (var j = 0; j < nodeGroup.length; j++) {
2559
- var node = nodeGroup[j];
2560
- var key = '' + i + j;
2561
- currentNodeIds.push(key);
2562
- table[key] = {
2563
- node: node,
2564
- lastCount: 0
2565
- };
2566
- graph[key] = {};
2567
-
2568
- for (var n = 0; n < prevNodeIds.length; n++) {
2569
- var prevNodeId = prevNodeIds[n];
2570
-
2571
- if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
2572
- graph[prevNodeId][key] = getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
2573
- table[prevNodeId].lastCount += node.length;
2574
- } else {
2575
- if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
2576
- graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + 4 + mode.getCharCountIndicator(node.mode, version); // switch cost
2577
- }
2578
- }
2579
- }
2580
-
2581
- prevNodeIds = currentNodeIds;
2582
- }
2583
-
2584
- for (n = 0; n < prevNodeIds.length; n++) {
2585
- graph[prevNodeIds[n]]['end'] = 0;
2586
- }
2587
-
2588
- return {
2589
- map: graph,
2590
- table: table
2591
- };
2592
- }
2593
- /**
2594
- * Builds a segment from a specified data and mode.
2595
- * If a mode is not specified, the more suitable will be used.
2596
- *
2597
- * @param {String} data Input data
2598
- * @param {Mode | String} modesHint Data mode
2599
- * @return {Segment} Segment
2600
- */
2601
-
2602
-
2603
- function buildSingleSegment(data, modesHint) {
2604
- var mode$1;
2605
- var bestMode = mode.getBestModeForData(data);
2606
- mode$1 = mode.from(modesHint, bestMode); // Make sure data can be encoded
2607
-
2608
- if (mode$1 !== mode.BYTE && mode$1.bit < bestMode.bit) {
2609
- throw new Error('"' + data + '"' + ' cannot be encoded with mode ' + mode.toString(mode$1) + '.\n Suggested mode is: ' + mode.toString(bestMode));
2610
- } // Use Mode.BYTE if Kanji support is disabled
2611
-
2612
-
2613
- if (mode$1 === mode.KANJI && !utils.isKanjiModeEnabled()) {
2614
- mode$1 = mode.BYTE;
2615
- }
2616
-
2617
- switch (mode$1) {
2618
- case mode.NUMERIC:
2619
- return new numericData(data);
2620
-
2621
- case mode.ALPHANUMERIC:
2622
- return new alphanumericData(data);
2623
-
2624
- case mode.KANJI:
2625
- return new kanjiData(data);
2626
-
2627
- case mode.BYTE:
2628
- return new byteData(data);
2629
- }
2630
- }
2631
- /**
2632
- * Builds a list of segments from an array.
2633
- * Array can contain Strings or Objects with segment's info.
2634
- *
2635
- * For each item which is a string, will be generated a segment with the given
2636
- * string and the more appropriate encoding mode.
2637
- *
2638
- * For each item which is an object, will be generated a segment with the given
2639
- * data and mode.
2640
- * Objects must contain at least the property "data".
2641
- * If property "mode" is not present, the more suitable mode will be used.
2642
- *
2643
- * @param {Array} array Array of objects with segments data
2644
- * @return {Array} Array of Segments
2645
- */
2646
-
2647
-
2648
- exports.fromArray = function fromArray(array) {
2649
- return array.reduce(function (acc, seg) {
2650
- if (typeof seg === 'string') {
2651
- acc.push(buildSingleSegment(seg, null));
2652
- } else if (seg.data) {
2653
- acc.push(buildSingleSegment(seg.data, seg.mode));
2654
- }
2655
-
2656
- return acc;
2657
- }, []);
2658
- };
2659
- /**
2660
- * Builds an optimized sequence of segments from a string,
2661
- * which will produce the shortest possible bitstream.
2662
- *
2663
- * @param {String} data Input string
2664
- * @param {Number} version QR Code version
2665
- * @return {Array} Array of segments
2666
- */
2667
-
2668
-
2669
- exports.fromString = function fromString(data, version) {
2670
- var segs = getSegmentsFromString(data, utils.isKanjiModeEnabled());
2671
- var nodes = buildNodes(segs);
2672
- var graph = buildGraph(nodes, version);
2673
- var path = dijkstra_1.find_path(graph.map, 'start', 'end');
2674
- var optimizedSegs = [];
2675
-
2676
- for (var i = 1; i < path.length - 1; i++) {
2677
- optimizedSegs.push(graph.table[path[i]].node);
2678
- }
2679
-
2680
- return exports.fromArray(mergeSegments(optimizedSegs));
2681
- };
2682
- /**
2683
- * Splits a string in various segments with the modes which
2684
- * best represent their content.
2685
- * The produced segments are far from being optimized.
2686
- * The output of this function is only used to estimate a QR Code version
2687
- * which may contain the data.
2688
- *
2689
- * @param {string} data Input string
2690
- * @return {Array} Array of segments
2691
- */
2692
-
2693
-
2694
- exports.rawSplit = function rawSplit(data) {
2695
- return exports.fromArray(getSegmentsFromString(data, utils.isKanjiModeEnabled()));
2696
- };
2697
- });
2698
- /**
2699
- * QRCode for JavaScript
2700
- *
2701
- * modified by Ryan Day for nodejs support
2702
- * Copyright (c) 2011 Ryan Day
2703
- *
2704
- * Licensed under the MIT license:
2705
- * http://www.opensource.org/licenses/mit-license.php
2706
- *
2707
- //---------------------------------------------------------------------
2708
- // QRCode for JavaScript
2709
- //
2710
- // Copyright (c) 2009 Kazuhiko Arase
2711
- //
2712
- // URL: http://www.d-project.com/
2713
- //
2714
- // Licensed under the MIT license:
2715
- // http://www.opensource.org/licenses/mit-license.php
2716
- //
2717
- // The word "QR Code" is registered trademark of
2718
- // DENSO WAVE INCORPORATED
2719
- // http://www.denso-wave.com/qrcode/faqpatent-e.html
2720
- //
2721
- //---------------------------------------------------------------------
2722
- */
2723
-
2724
- /**
2725
- * Add finder patterns bits to matrix
2726
- *
2727
- * @param {BitMatrix} matrix Modules matrix
2728
- * @param {Number} version QR Code version
2729
- */
2730
-
2731
- function setupFinderPattern(matrix, version) {
2732
- var size = matrix.size;
2733
- var pos = finderPattern.getPositions(version);
2734
-
2735
- for (var i = 0; i < pos.length; i++) {
2736
- var row = pos[i][0];
2737
- var col = pos[i][1];
2738
-
2739
- for (var r = -1; r <= 7; r++) {
2740
- if (row + r <= -1 || size <= row + r) continue;
2741
-
2742
- for (var c = -1; c <= 7; c++) {
2743
- if (col + c <= -1 || size <= col + c) continue;
2744
-
2745
- if (r >= 0 && r <= 6 && (c === 0 || c === 6) || c >= 0 && c <= 6 && (r === 0 || r === 6) || r >= 2 && r <= 4 && c >= 2 && c <= 4) {
2746
- matrix.set(row + r, col + c, true, true);
2747
- } else {
2748
- matrix.set(row + r, col + c, false, true);
2749
- }
2750
- }
2751
- }
2752
- }
2753
- }
2754
- /**
2755
- * Add timing pattern bits to matrix
2756
- *
2757
- * Note: this function must be called before {@link setupAlignmentPattern}
2758
- *
2759
- * @param {BitMatrix} matrix Modules matrix
2760
- */
2761
-
2762
-
2763
- function setupTimingPattern(matrix) {
2764
- var size = matrix.size;
2765
-
2766
- for (var r = 8; r < size - 8; r++) {
2767
- var value = r % 2 === 0;
2768
- matrix.set(r, 6, value, true);
2769
- matrix.set(6, r, value, true);
2770
- }
2771
- }
2772
- /**
2773
- * Add alignment patterns bits to matrix
2774
- *
2775
- * Note: this function must be called after {@link setupTimingPattern}
2776
- *
2777
- * @param {BitMatrix} matrix Modules matrix
2778
- * @param {Number} version QR Code version
2779
- */
2780
-
2781
-
2782
- function setupAlignmentPattern(matrix, version) {
2783
- var pos = alignmentPattern.getPositions(version);
2784
-
2785
- for (var i = 0; i < pos.length; i++) {
2786
- var row = pos[i][0];
2787
- var col = pos[i][1];
2788
-
2789
- for (var r = -2; r <= 2; r++) {
2790
- for (var c = -2; c <= 2; c++) {
2791
- if (r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0) {
2792
- matrix.set(row + r, col + c, true, true);
2793
- } else {
2794
- matrix.set(row + r, col + c, false, true);
2795
- }
2796
- }
2797
- }
2798
- }
2799
- }
2800
- /**
2801
- * Add version info bits to matrix
2802
- *
2803
- * @param {BitMatrix} matrix Modules matrix
2804
- * @param {Number} version QR Code version
2805
- */
2806
-
2807
-
2808
- function setupVersionInfo(matrix, version$1) {
2809
- var size = matrix.size;
2810
- var bits = version.getEncodedBits(version$1);
2811
- var row, col, mod;
2812
-
2813
- for (var i = 0; i < 18; i++) {
2814
- row = Math.floor(i / 3);
2815
- col = i % 3 + size - 8 - 3;
2816
- mod = (bits >> i & 1) === 1;
2817
- matrix.set(row, col, mod, true);
2818
- matrix.set(col, row, mod, true);
2819
- }
2820
- }
2821
- /**
2822
- * Add format info bits to matrix
2823
- *
2824
- * @param {BitMatrix} matrix Modules matrix
2825
- * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2826
- * @param {Number} maskPattern Mask pattern reference value
2827
- */
2828
-
2829
-
2830
- function setupFormatInfo(matrix, errorCorrectionLevel, maskPattern) {
2831
- var size = matrix.size;
2832
- var bits = formatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
2833
- var i, mod;
2834
-
2835
- for (i = 0; i < 15; i++) {
2836
- mod = (bits >> i & 1) === 1; // vertical
2837
-
2838
- if (i < 6) {
2839
- matrix.set(i, 8, mod, true);
2840
- } else if (i < 8) {
2841
- matrix.set(i + 1, 8, mod, true);
2842
- } else {
2843
- matrix.set(size - 15 + i, 8, mod, true);
2844
- } // horizontal
2845
-
2846
-
2847
- if (i < 8) {
2848
- matrix.set(8, size - i - 1, mod, true);
2849
- } else if (i < 9) {
2850
- matrix.set(8, 15 - i - 1 + 1, mod, true);
2851
- } else {
2852
- matrix.set(8, 15 - i - 1, mod, true);
2853
- }
2854
- } // fixed module
2855
-
2856
-
2857
- matrix.set(size - 8, 8, 1, true);
2858
- }
2859
- /**
2860
- * Add encoded data bits to matrix
2861
- *
2862
- * @param {BitMatrix} matrix Modules matrix
2863
- * @param {Buffer} data Data codewords
2864
- */
2865
-
2866
-
2867
- function setupData(matrix, data) {
2868
- var size = matrix.size;
2869
- var inc = -1;
2870
- var row = size - 1;
2871
- var bitIndex = 7;
2872
- var byteIndex = 0;
2873
-
2874
- for (var col = size - 1; col > 0; col -= 2) {
2875
- if (col === 6) col--;
2876
-
2877
- while (true) {
2878
- for (var c = 0; c < 2; c++) {
2879
- if (!matrix.isReserved(row, col - c)) {
2880
- var dark = false;
2881
-
2882
- if (byteIndex < data.length) {
2883
- dark = (data[byteIndex] >>> bitIndex & 1) === 1;
2884
- }
2885
-
2886
- matrix.set(row, col - c, dark);
2887
- bitIndex--;
2888
-
2889
- if (bitIndex === -1) {
2890
- byteIndex++;
2891
- bitIndex = 7;
2892
- }
2893
- }
2894
- }
2895
-
2896
- row += inc;
2897
-
2898
- if (row < 0 || size <= row) {
2899
- row -= inc;
2900
- inc = -inc;
2901
- break;
2902
- }
2903
- }
2904
- }
2905
- }
2906
- /**
2907
- * Create encoded codewords from data input
2908
- *
2909
- * @param {Number} version QR Code version
2910
- * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2911
- * @param {ByteData} data Data input
2912
- * @return {Buffer} Buffer containing encoded codewords
2913
- */
2914
-
2915
-
2916
- function createData(version, errorCorrectionLevel, segments) {
2917
- // Prepare data buffer
2918
- var buffer = new bitBuffer();
2919
- segments.forEach(function (data) {
2920
- // prefix data with mode indicator (4 bits)
2921
- buffer.put(data.mode.bit, 4); // Prefix data with character count indicator.
2922
- // The character count indicator is a string of bits that represents the
2923
- // number of characters that are being encoded.
2924
- // The character count indicator must be placed after the mode indicator
2925
- // and must be a certain number of bits long, depending on the QR version
2926
- // and data mode
2927
- // @see {@link Mode.getCharCountIndicator}.
2928
-
2929
- buffer.put(data.getLength(), mode.getCharCountIndicator(data.mode, version)); // add binary data sequence to buffer
2930
-
2931
- data.write(buffer);
2932
- }); // Calculate required number of bits
2933
-
2934
- var totalCodewords = utils.getSymbolTotalCodewords(version);
2935
- var ecTotalCodewords = errorCorrectionCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2936
- var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8; // Add a terminator.
2937
- // If the bit string is shorter than the total number of required bits,
2938
- // a terminator of up to four 0s must be added to the right side of the string.
2939
- // If the bit string is more than four bits shorter than the required number of bits,
2940
- // add four 0s to the end.
2941
-
2942
- if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
2943
- buffer.put(0, 4);
2944
- } // If the bit string is fewer than four bits shorter, add only the number of 0s that
2945
- // are needed to reach the required number of bits.
2946
- // After adding the terminator, if the number of bits in the string is not a multiple of 8,
2947
- // pad the string on the right with 0s to make the string's length a multiple of 8.
2948
-
2949
-
2950
- while (buffer.getLengthInBits() % 8 !== 0) {
2951
- buffer.putBit(0);
2952
- } // Add pad bytes if the string is still shorter than the total number of required bits.
2953
- // Extend the buffer to fill the data capacity of the symbol corresponding to
2954
- // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
2955
- // and 00010001 (0x11) alternately.
2956
-
2957
-
2958
- var remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
2959
-
2960
- for (var i = 0; i < remainingByte; i++) {
2961
- buffer.put(i % 2 ? 0x11 : 0xEC, 8);
2962
- }
2963
-
2964
- return createCodewords(buffer, version, errorCorrectionLevel);
2965
- }
2966
- /**
2967
- * Encode input data with Reed-Solomon and return codewords with
2968
- * relative error correction bits
2969
- *
2970
- * @param {BitBuffer} bitBuffer Data to encode
2971
- * @param {Number} version QR Code version
2972
- * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2973
- * @return {Buffer} Buffer containing encoded codewords
2974
- */
2975
-
2976
-
2977
- function createCodewords(bitBuffer, version, errorCorrectionLevel) {
2978
- // Total codewords for this QR code version (Data + Error correction)
2979
- var totalCodewords = utils.getSymbolTotalCodewords(version); // Total number of error correction codewords
2980
-
2981
- var ecTotalCodewords = errorCorrectionCode.getTotalCodewordsCount(version, errorCorrectionLevel); // Total number of data codewords
2982
-
2983
- var dataTotalCodewords = totalCodewords - ecTotalCodewords; // Total number of blocks
2984
-
2985
- var ecTotalBlocks = errorCorrectionCode.getBlocksCount(version, errorCorrectionLevel); // Calculate how many blocks each group should contain
2986
-
2987
- var blocksInGroup2 = totalCodewords % ecTotalBlocks;
2988
- var blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
2989
- var totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
2990
- var dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
2991
- var dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1; // Number of EC codewords is the same for both groups
2992
-
2993
- var ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1; // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
2994
-
2995
- var rs = new reedSolomonEncoder(ecCount);
2996
- var offset = 0;
2997
- var dcData = new Array(ecTotalBlocks);
2998
- var ecData = new Array(ecTotalBlocks);
2999
- var maxDataSize = 0;
3000
- var buffer = typedarrayBuffer.from(bitBuffer.buffer); // Divide the buffer into the required number of blocks
3001
-
3002
- for (var b = 0; b < ecTotalBlocks; b++) {
3003
- var dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2; // extract a block of data from buffer
3004
-
3005
- dcData[b] = buffer.slice(offset, offset + dataSize); // Calculate EC codewords for this data block
3006
-
3007
- ecData[b] = rs.encode(dcData[b]);
3008
- offset += dataSize;
3009
- maxDataSize = Math.max(maxDataSize, dataSize);
3010
- } // Create final data
3011
- // Interleave the data and error correction codewords from each block
3012
-
3013
-
3014
- var data = typedarrayBuffer.alloc(totalCodewords);
3015
- var index = 0;
3016
- var i, r; // Add data codewords
3017
-
3018
- for (i = 0; i < maxDataSize; i++) {
3019
- for (r = 0; r < ecTotalBlocks; r++) {
3020
- if (i < dcData[r].length) {
3021
- data[index++] = dcData[r][i];
3022
- }
3023
- }
3024
- } // Apped EC codewords
3025
-
3026
-
3027
- for (i = 0; i < ecCount; i++) {
3028
- for (r = 0; r < ecTotalBlocks; r++) {
3029
- data[index++] = ecData[r][i];
3030
- }
3031
- }
3032
-
3033
- return data;
3034
- }
3035
- /**
3036
- * Build QR Code symbol
3037
- *
3038
- * @param {String} data Input string
3039
- * @param {Number} version QR Code version
3040
- * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
3041
- * @param {MaskPattern} maskPattern Mask pattern
3042
- * @return {Object} Object containing symbol data
3043
- */
3044
-
3045
-
3046
- function createSymbol(data, version$1, errorCorrectionLevel, maskPattern$1) {
3047
- var segments$1;
3048
-
3049
- if (isarray(data)) {
3050
- segments$1 = segments.fromArray(data);
3051
- } else if (typeof data === 'string') {
3052
- var estimatedVersion = version$1;
3053
-
3054
- if (!estimatedVersion) {
3055
- var rawSegments = segments.rawSplit(data); // Estimate best version that can contain raw splitted segments
3056
-
3057
- estimatedVersion = version.getBestVersionForData(rawSegments, errorCorrectionLevel);
3058
- } // Build optimized segments
3059
- // If estimated version is undefined, try with the highest version
3060
-
3061
-
3062
- segments$1 = segments.fromString(data, estimatedVersion || 40);
3063
- } else {
3064
- throw new Error('Invalid data');
3065
- } // Get the min version that can contain data
3066
-
3067
-
3068
- var bestVersion = version.getBestVersionForData(segments$1, errorCorrectionLevel); // If no version is found, data cannot be stored
3069
-
3070
- if (!bestVersion) {
3071
- throw new Error('The amount of data is too big to be stored in a QR Code');
3072
- } // If not specified, use min version as default
3073
-
3074
-
3075
- if (!version$1) {
3076
- version$1 = bestVersion; // Check if the specified version can contain the data
3077
- } else if (version$1 < bestVersion) {
3078
- throw new Error('\n' + 'The chosen QR Code version cannot contain this amount of data.\n' + 'Minimum version required to store current data is: ' + bestVersion + '.\n');
3079
- }
3080
-
3081
- var dataBits = createData(version$1, errorCorrectionLevel, segments$1); // Allocate matrix buffer
3082
-
3083
- var moduleCount = utils.getSymbolSize(version$1);
3084
- var modules = new bitMatrix(moduleCount); // Add function modules
3085
-
3086
- setupFinderPattern(modules, version$1);
3087
- setupTimingPattern(modules);
3088
- setupAlignmentPattern(modules, version$1); // Add temporary dummy bits for format info just to set them as reserved.
3089
- // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
3090
- // since the masking operation must be performed only on the encoding region.
3091
- // These blocks will be replaced with correct values later in code.
3092
-
3093
- setupFormatInfo(modules, errorCorrectionLevel, 0);
3094
-
3095
- if (version$1 >= 7) {
3096
- setupVersionInfo(modules, version$1);
3097
- } // Add data codewords
3098
-
3099
-
3100
- setupData(modules, dataBits);
3101
-
3102
- if (isNaN(maskPattern$1)) {
3103
- // Find best mask pattern
3104
- maskPattern$1 = maskPattern.getBestMask(modules, setupFormatInfo.bind(null, modules, errorCorrectionLevel));
3105
- } // Apply mask pattern
3106
-
3107
-
3108
- maskPattern.applyMask(maskPattern$1, modules); // Replace format info bits with correct values
3109
-
3110
- setupFormatInfo(modules, errorCorrectionLevel, maskPattern$1);
3111
- return {
3112
- modules: modules,
3113
- version: version$1,
3114
- errorCorrectionLevel: errorCorrectionLevel,
3115
- maskPattern: maskPattern$1,
3116
- segments: segments$1
3117
- };
3118
- }
3119
- /**
3120
- * QR Code
3121
- *
3122
- * @param {String | Array} data Input data
3123
- * @param {Object} options Optional configurations
3124
- * @param {Number} options.version QR Code version
3125
- * @param {String} options.errorCorrectionLevel Error correction level
3126
- * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
3127
- */
3128
-
3129
-
3130
- var create = function create(data, options) {
3131
- if (typeof data === 'undefined' || data === '') {
3132
- throw new Error('No input text');
167
+ var __spreadArrays = undefined && undefined.__spreadArrays || function () {
168
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) {
169
+ s += arguments[i].length;
3133
170
  }
3134
171
 
3135
- var errorCorrectionLevel$1 = errorCorrectionLevel.M;
3136
- var version$1;
3137
- var mask;
3138
-
3139
- if (typeof options !== 'undefined') {
3140
- // Use higher error correction level as default
3141
- errorCorrectionLevel$1 = errorCorrectionLevel.from(options.errorCorrectionLevel, errorCorrectionLevel.M);
3142
- version$1 = version.from(options.version);
3143
- mask = maskPattern.from(options.maskPattern);
3144
-
3145
- if (options.toSJISFunc) {
3146
- utils.setToSJISFunction(options.toSJISFunc);
172
+ for (var r = Array(s), k = 0, i = 0; i < il; i++) {
173
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) {
174
+ r[k] = a[j];
3147
175
  }
3148
176
  }
3149
177
 
3150
- return createSymbol(data, version$1, errorCorrectionLevel$1, mask);
3151
- };
3152
-
3153
- var qrcode = {
3154
- create: create
178
+ return r;
3155
179
  };
3156
- var utils$1 = createCommonjsModule(function (module, exports) {
3157
- function hex2rgba(hex) {
3158
- if (typeof hex === 'number') {
3159
- hex = hex.toString();
3160
- }
3161
-
3162
- if (typeof hex !== 'string') {
3163
- throw new Error('Color should be defined as hex string');
3164
- }
3165
180
 
3166
- var hexCode = hex.slice().replace('#', '').split('');
3167
181
 
3168
- if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
3169
- throw new Error('Invalid hex color: ' + hex);
3170
- } // Convert from short to long form (fff -> ffffff)
3171
182
 
3172
183
 
3173
- if (hexCode.length === 3 || hexCode.length === 4) {
3174
- hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
3175
- return [c, c];
3176
- }));
3177
- } // Add default alpha value
3178
-
3179
184
 
3180
- if (hexCode.length === 6) hexCode.push('F', 'F');
3181
- var hexValue = parseInt(hexCode.join(''), 16);
3182
- return {
3183
- r: hexValue >> 24 & 255,
3184
- g: hexValue >> 16 & 255,
3185
- b: hexValue >> 8 & 255,
3186
- a: hexValue & 255,
3187
- hex: '#' + hexCode.slice(0, 6).join('')
3188
- };
3189
- }
3190
185
 
3191
- exports.getOptions = function getOptions(options) {
3192
- if (!options) options = {};
3193
- if (!options.color) options.color = {};
3194
- var margin = typeof options.margin === 'undefined' || options.margin === null || options.margin < 0 ? 4 : options.margin;
3195
- var width = options.width && options.width >= 21 ? options.width : undefined;
3196
- var scale = options.scale || 4;
3197
- return {
3198
- width: width,
3199
- scale: width ? 4 : scale,
3200
- margin: margin,
3201
- color: {
3202
- dark: hex2rgba(options.color.dark || '#000000ff'),
3203
- light: hex2rgba(options.color.light || '#ffffffff')
3204
- },
3205
- type: options.type,
3206
- rendererOpts: options.rendererOpts || {}
3207
- };
3208
- };
3209
186
 
3210
- exports.getScale = function getScale(qrSize, opts) {
3211
- return opts.width && opts.width >= qrSize + opts.margin * 2 ? opts.width / (qrSize + opts.margin * 2) : opts.scale;
3212
- };
3213
187
 
3214
- exports.getImageWidth = function getImageWidth(qrSize, opts) {
3215
- var scale = exports.getScale(qrSize, opts);
3216
- return Math.floor((qrSize + opts.margin * 2) * scale);
3217
- };
188
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
189
+ // require the crypto API and do not support built-in fallback to lower quality random number
190
+ // generators (like Math.random()).
3218
191
 
3219
- exports.qrToImageData = function qrToImageData(imgData, qr, opts) {
3220
- var size = qr.modules.size;
3221
- var data = qr.modules.data;
3222
- var scale = exports.getScale(size, opts);
3223
- var symbolSize = Math.floor((size + opts.margin * 2) * scale);
3224
- var scaledMargin = opts.margin * scale;
3225
- var palette = [opts.color.light, opts.color.dark];
3226
-
3227
- for (var i = 0; i < symbolSize; i++) {
3228
- for (var j = 0; j < symbolSize; j++) {
3229
- var posDst = (i * symbolSize + j) * 4;
3230
- var pxColor = opts.color.light;
3231
-
3232
- if (i >= scaledMargin && j >= scaledMargin && i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
3233
- var iSrc = Math.floor((i - scaledMargin) / scale);
3234
- var jSrc = Math.floor((j - scaledMargin) / scale);
3235
- pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
3236
- }
192
+ var getRandomValues;
193
+ var rnds8 = new Uint8Array(16);
3237
194
 
3238
- imgData[posDst++] = pxColor.r;
3239
- imgData[posDst++] = pxColor.g;
3240
- imgData[posDst++] = pxColor.b;
3241
- imgData[posDst] = pxColor.a;
3242
- }
3243
- }
3244
- };
3245
- });
3246
- var canvas = createCommonjsModule(function (module, exports) {
3247
- function clearCanvas(ctx, canvas, size) {
3248
- ctx.clearRect(0, 0, canvas.width, canvas.height);
3249
- if (!canvas.style) canvas.style = {};
3250
- canvas.height = size;
3251
- canvas.width = size;
3252
- canvas.style.height = size + 'px';
3253
- canvas.style.width = size + 'px';
3254
- }
195
+ function rng() {
196
+ // lazy load so that environments that need to polyfill have a chance to do so
197
+ if (!getRandomValues) {
198
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
199
+ // find the complete implementation of crypto (msCrypto) on IE11.
200
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
3255
201
 
3256
- function getCanvasElement() {
3257
- try {
3258
- return document.createElement('canvas');
3259
- } catch (e) {
3260
- throw new Error('You need to specify a canvas element');
202
+ if (!getRandomValues) {
203
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
3261
204
  }
3262
205
  }
3263
206
 
3264
- exports.render = function render(qrData, canvas, options) {
3265
- var opts = options;
3266
- var canvasEl = canvas;
3267
-
3268
- if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
3269
- opts = canvas;
3270
- canvas = undefined;
3271
- }
3272
-
3273
- if (!canvas) {
3274
- canvasEl = getCanvasElement();
3275
- }
3276
-
3277
- opts = utils$1.getOptions(opts);
3278
- var size = utils$1.getImageWidth(qrData.modules.size, opts);
3279
- var ctx = canvasEl.getContext('2d');
3280
- var image = ctx.createImageData(size, size);
3281
- utils$1.qrToImageData(image.data, qrData, opts);
3282
- clearCanvas(ctx, canvasEl, size);
3283
- ctx.putImageData(image, 0, 0);
3284
- return canvasEl;
3285
- };
3286
-
3287
- exports.renderToDataURL = function renderToDataURL(qrData, canvas, options) {
3288
- var opts = options;
3289
-
3290
- if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
3291
- opts = canvas;
3292
- canvas = undefined;
3293
- }
207
+ return getRandomValues(rnds8);
208
+ }
3294
209
 
3295
- if (!opts) opts = {};
3296
- var canvasEl = exports.render(qrData, canvas, opts);
3297
- var type = opts.type || 'image/png';
3298
- var rendererOpts = opts.rendererOpts || {};
3299
- return canvasEl.toDataURL(type, rendererOpts.quality);
3300
- };
3301
- });
210
+ var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
3302
211
 
3303
- function getColorAttrib(color, attrib) {
3304
- var alpha = color.a / 255;
3305
- var str = attrib + '="' + color.hex + '"';
3306
- return alpha < 1 ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' : str;
212
+ function validate(uuid) {
213
+ return typeof uuid === 'string' && REGEX.test(uuid);
3307
214
  }
215
+ /**
216
+ * Convert array of 16 byte values to UUID string format of the form:
217
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
218
+ */
3308
219
 
3309
- function svgCmd(cmd, x, y) {
3310
- var str = cmd + x;
3311
- if (typeof y !== 'undefined') str += ' ' + y;
3312
- return str;
3313
- }
3314
220
 
3315
- function qrToPath(data, size, margin) {
3316
- var path = '';
3317
- var moveBy = 0;
3318
- var newRow = false;
3319
- var lineLength = 0;
221
+ var byteToHex = [];
3320
222
 
3321
- for (var i = 0; i < data.length; i++) {
3322
- var col = Math.floor(i % size);
3323
- var row = Math.floor(i / size);
3324
- if (!col && !newRow) newRow = true;
223
+ for (var i = 0; i < 256; ++i) {
224
+ byteToHex.push((i + 0x100).toString(16).substr(1));
225
+ }
3325
226
 
3326
- if (data[i]) {
3327
- lineLength++;
227
+ function stringify(arr) {
228
+ var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; // Note: Be careful editing this code! It's been tuned for performance
229
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
3328
230
 
3329
- if (!(i > 0 && col > 0 && data[i - 1])) {
3330
- path += newRow ? svgCmd('M', col + margin, 0.5 + row + margin) : svgCmd('m', moveBy, 0);
3331
- moveBy = 0;
3332
- newRow = false;
3333
- }
231
+ var uuid = (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(); // Consistency check for valid UUID. If this throws, it's likely due to one
232
+ // of the following:
233
+ // - One or more input array values don't map to a hex octet (leading to
234
+ // "undefined" in the uuid)
235
+ // - Invalid input values for the RFC `version` or `variant` fields
3334
236
 
3335
- if (!(col + 1 < size && data[i + 1])) {
3336
- path += svgCmd('h', lineLength);
3337
- lineLength = 0;
3338
- }
3339
- } else {
3340
- moveBy++;
3341
- }
237
+ if (!validate(uuid)) {
238
+ throw TypeError('Stringified UUID is invalid');
3342
239
  }
3343
240
 
3344
- return path;
241
+ return uuid;
3345
242
  }
3346
243
 
3347
- var render = function render(qrData, options, cb) {
3348
- var opts = utils$1.getOptions(options);
3349
- var size = qrData.modules.size;
3350
- var data = qrData.modules.data;
3351
- var qrcodesize = size + opts.margin * 2;
3352
- var bg = !opts.color.light.a ? '' : '<path ' + getColorAttrib(opts.color.light, 'fill') + ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>';
3353
- var path = '<path ' + getColorAttrib(opts.color.dark, 'stroke') + ' d="' + qrToPath(data, size, opts.margin) + '"/>';
3354
- var viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"';
3355
- var width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" ';
3356
- var svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n';
3357
-
3358
- if (typeof cb === 'function') {
3359
- cb(null, svgTag);
3360
- }
3361
-
3362
- return svgTag;
3363
- };
3364
-
3365
- var svgTag = {
3366
- render: render
3367
- };
3368
-
3369
- function renderCanvas(renderFunc, canvas, text, opts, cb) {
3370
- var args = [].slice.call(arguments, 1);
3371
- var argsNum = args.length;
3372
- var isLastArgCb = typeof args[argsNum - 1] === 'function';
3373
-
3374
- if (!isLastArgCb && !canPromise()) {
3375
- throw new Error('Callback required as last argument');
3376
- }
244
+ function v4(options, buf, offset) {
245
+ options = options || {};
246
+ var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
3377
247
 
3378
- if (isLastArgCb) {
3379
- if (argsNum < 2) {
3380
- throw new Error('Too few arguments provided');
3381
- }
248
+ rnds[6] = rnds[6] & 0x0f | 0x40;
249
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
3382
250
 
3383
- if (argsNum === 2) {
3384
- cb = text;
3385
- text = canvas;
3386
- canvas = opts = undefined;
3387
- } else if (argsNum === 3) {
3388
- if (canvas.getContext && typeof cb === 'undefined') {
3389
- cb = opts;
3390
- opts = undefined;
3391
- } else {
3392
- cb = opts;
3393
- opts = text;
3394
- text = canvas;
3395
- canvas = undefined;
3396
- }
3397
- }
3398
- } else {
3399
- if (argsNum < 1) {
3400
- throw new Error('Too few arguments provided');
3401
- }
251
+ if (buf) {
252
+ offset = offset || 0;
3402
253
 
3403
- if (argsNum === 1) {
3404
- text = canvas;
3405
- canvas = opts = undefined;
3406
- } else if (argsNum === 2 && !canvas.getContext) {
3407
- opts = text;
3408
- text = canvas;
3409
- canvas = undefined;
254
+ for (var i = 0; i < 16; ++i) {
255
+ buf[offset + i] = rnds[i];
3410
256
  }
3411
257
 
3412
- return new Promise(function (resolve, reject) {
3413
- try {
3414
- var data = qrcode.create(text, opts);
3415
- resolve(renderFunc(data, canvas, opts));
3416
- } catch (e) {
3417
- reject(e);
3418
- }
3419
- });
258
+ return buf;
3420
259
  }
3421
260
 
3422
- try {
3423
- var data = qrcode.create(text, opts);
3424
- cb(null, renderFunc(data, canvas, opts));
3425
- } catch (e) {
3426
- cb(e);
3427
- }
261
+ return stringify(rnds);
3428
262
  }
3429
263
 
3430
- var create$1 = qrcode.create;
3431
- var toCanvas = renderCanvas.bind(null, canvas.render);
3432
- var toDataURL = renderCanvas.bind(null, canvas.renderToDataURL); // only svg for now.
3433
-
3434
- var toString_1 = renderCanvas.bind(null, function (data, _, opts) {
3435
- return svgTag.render(data, opts);
3436
- });
3437
- var browser = {
3438
- create: create$1,
3439
- toCanvas: toCanvas,
3440
- toDataURL: toDataURL,
3441
- toString: toString_1
3442
- };
3443
- var amplifyTotpSetupCss = ".totp-setup{text-align:center;margin-bottom:30px}.totp-setup img{height:128px;width:128px}";
3444
- var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Logger"]('TOTP');
264
+ var amplifyS3AlbumCss = ":host{--overlay-bg-color:rgba(0, 0, 0, 0.15)}.album-container{-webkit-box-sizing:border-box;box-sizing:border-box;max-width:100%;margin:0 auto;padding:0 2rem}.grid-row{display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;margin:-1rem -1rem;padding-bottom:3rem}.grid-item{position:relative;-ms-flex:1 0 22rem;flex:1 0 22rem;-ms-flex-positive:1;flex-grow:1;margin:1rem;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center}amplify-s3-image{--width:22rem;--height:20rem;border-radius:5px;-o-object-fit:cover;object-fit:cover}.img-overlay{display:none;width:100%;height:21rem;position:absolute;top:0;left:0;background-color:var(--overlay-bg-color)}.grid-item:hover .img-overlay{display:block}";
265
+ var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Logger"]('S3Album');
3445
266
 
3446
- var AmplifyTOTPSetup =
267
+ var AmplifyS3Album =
3447
268
  /** @class */
3448
269
  function () {
3449
270
  function class_1(hostRef) {
271
+ var _this = this;
272
+
3450
273
  Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
3451
- this.inputProps = {
3452
- autoFocus: true
274
+ /** The content type header used when uploading to S3 */
275
+
276
+ this.contentType = 'binary/octet-stream';
277
+ /** The access level of the files */
278
+
279
+ this.level = _storage_types_f257c0f2_js__WEBPACK_IMPORTED_MODULE_2__["A"].Public;
280
+ /** Boolean to enable or disable picker */
281
+
282
+ this.picker = true;
283
+ /** Picker button text */
284
+
285
+ this.pickerText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].PICKER_TEXT;
286
+ this.albumItems = [];
287
+ this.imgArr = {};
288
+
289
+ this.list = function () {
290
+ return __awaiter(_this, void 0, void 0, function () {
291
+ var _a, _b, path, level, track, identityId, data, error_1;
292
+
293
+ return __generator(this, function (_c) {
294
+ switch (_c.label) {
295
+ case 0:
296
+ _a = this, _b = _a.path, path = _b === void 0 ? '' : _b, level = _a.level, track = _a.track, identityId = _a.identityId;
297
+ logger.debug('Album path: ' + path);
298
+
299
+ if (!_aws_amplify_storage__WEBPACK_IMPORTED_MODULE_6__["Storage"] || typeof _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_6__["Storage"].list !== 'function') {
300
+ throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["d"]);
301
+ }
302
+
303
+ _c.label = 1;
304
+
305
+ case 1:
306
+ _c.trys.push([1, 3,, 4]);
307
+
308
+ return [4
309
+ /*yield*/
310
+ , _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_6__["Storage"].list(path, {
311
+ level: level,
312
+ track: track,
313
+ identityId: identityId
314
+ })];
315
+
316
+ case 2:
317
+ data = _c.sent();
318
+ this.marshal(data);
319
+ return [3
320
+ /*break*/
321
+ , 4];
322
+
323
+ case 3:
324
+ error_1 = _c.sent();
325
+ logger.warn(error_1);
326
+ return [3
327
+ /*break*/
328
+ , 4];
329
+
330
+ case 4:
331
+ return [2
332
+ /*return*/
333
+ ];
334
+ }
335
+ });
336
+ });
3453
337
  };
3454
- /** Auth state change handler for this component */
3455
-
3456
- this.handleAuthStateChange = _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["d"];
3457
- /** Used for header text in totp setup component */
3458
-
3459
- this.headerText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_HEADER_TEXT;
3460
- /** Used for customizing the issuer string in the qr code image */
3461
-
3462
- this.issuer = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_ISSUER;
3463
- /** This is run after totp setup is complete. Useful if using this as standalone. */
3464
-
3465
- this.handleComplete = this.onTOTPEvent;
3466
- /** Set this to true if this component is running outside the default `amplify-authenticator` usage */
3467
-
3468
- this.standalone = false;
3469
- this.code = null;
3470
- this.setupMessage = null;
3471
- this.qrCodeInput = null;
3472
- this.loading = false;
3473
- }
3474
338
 
3475
- class_1.prototype.componentWillLoad = function () {
3476
- return __awaiter(this, void 0, void 0, function () {
3477
- var _this = this;
3478
-
3479
- return __generator(this, function (_a) {
3480
- switch (_a.label) {
3481
- case 0:
3482
- /**
3483
- * If this component is being used internally by the authenticator, we want to re-run
3484
- * setup only when the current auth state is `AuthState.TOTPSetup`.
3485
- *
3486
- * Ideally, we would only run the setup once when the component is mounted. This is not possible
3487
- * due to a bug with slots -- a slotted component will run its `componentWillLoad` lifecycle before
3488
- * it is even rendered. So instead we watch for authstate changes and run setup conditionally.
3489
- */
3490
- if (!this.standalone) {
3491
- this.removeHubListener = Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["o"])(function (authState) {
3492
- if (authState === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].TOTPSetup) _this.setup();
3493
- });
3494
- }
339
+ this.marshal = function (list) {
340
+ list.forEach(function (item) {
341
+ var name = item.key.toLowerCase();
342
+ var ext = name.split('.')[1];
3495
343
 
3496
- return [4
3497
- /*yield*/
3498
- , this.setup()];
3499
-
3500
- case 1:
3501
- _a.sent();
3502
-
3503
- return [2
3504
- /*return*/
3505
- ];
344
+ if (_storage_helpers_1afafead_js__WEBPACK_IMPORTED_MODULE_7__["i"].has(ext)) {
345
+ if (!item.contentType || item.contentType && item.contentType === 'binary/octet-stream') {
346
+ item.contentType = _this.getContentType(item);
347
+ }
3506
348
  }
3507
349
  });
3508
- });
3509
- };
3510
- /**
3511
- * If this component is being used externally, we can use `@Watch` as normal.
3512
- */
3513
-
3514
-
3515
- class_1.prototype.handleUserChange = function () {
3516
- this.standalone && this.setup();
3517
- };
3518
-
3519
- class_1.prototype.disconnectedCallback = function () {
3520
- this.removeHubListener && this.removeHubListener(); // stop listening to `onAuthUIStateChange`
3521
- };
3522
-
3523
- class_1.prototype.buildOtpAuthPath = function (user, issuer, secretKey) {
3524
- return "otpauth://totp/" + issuer + ":" + user.username + "?secret=" + secretKey + "&issuer=" + issuer;
3525
- };
3526
-
3527
- class_1.prototype.onTOTPEvent = function (user) {
3528
- return __awaiter(this, void 0, void 0, function () {
3529
- return __generator(this, function (_a) {
3530
- switch (_a.label) {
3531
- case 0:
3532
- logger.debug('on totp event');
3533
- return [4
3534
- /*yield*/
3535
- , Object(_auth_helpers_557b83fc_js__WEBPACK_IMPORTED_MODULE_7__["c"])(user, this.handleAuthStateChange)];
3536
-
3537
- case 1:
3538
- _a.sent();
3539
-
3540
- return [2
3541
- /*return*/
3542
- ];
3543
- }
350
+ var filtered = list.filter(function (item) {
351
+ return item.contentType && item.contentType.startsWith('image/');
3544
352
  });
3545
- });
3546
- };
3547
-
3548
- class_1.prototype.handleTotpInputChange = function (event) {
3549
- this.setupMessage = null;
3550
- this.qrCodeInput = event.target.value;
3551
- };
3552
-
3553
- class_1.prototype.generateQRCode = function (codeFromTotp) {
3554
- return __awaiter(this, void 0, void 0, function () {
3555
- var _a, error_1;
353
+ var items = _this.filter ? _this.filter(filtered) : filtered;
354
+ items = _this.sort ? _this.sort(items) : items;
355
+ _this.albumItems = items;
356
+ logger.debug('album items', _this.albumItems);
3556
357
 
3557
- return __generator(this, function (_b) {
3558
- switch (_b.label) {
3559
- case 0:
3560
- _b.trys.push([0, 2,, 3]);
3561
-
3562
- _a = this;
3563
- return [4
3564
- /*yield*/
3565
- , browser.toDataURL(codeFromTotp)];
358
+ _this.constructImgArray(_this.albumItems);
359
+ };
3566
360
 
3567
- case 1:
3568
- _a.qrCodeImageSource = _b.sent();
3569
- return [3
3570
- /*break*/
3571
- , 3];
3572
-
3573
- case 2:
3574
- error_1 = _b.sent();
3575
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_1);
3576
- return [3
3577
- /*break*/
3578
- , 3];
3579
-
3580
- case 3:
3581
- return [2
3582
- /*return*/
3583
- ];
3584
- }
361
+ this.constructImgArray = function (list) {
362
+ list.map(function (item) {
363
+ _this.imgArr["" + item['key']] = item['key'];
3585
364
  });
3586
- });
3587
- };
365
+ };
3588
366
 
3589
- class_1.prototype.setup = function () {
3590
- return __awaiter(this, void 0, void 0, function () {
3591
- var encodedIssuer, secretKey, error_2;
3592
- return __generator(this, function (_a) {
3593
- switch (_a.label) {
3594
- case 0:
3595
- // ensure setup is only run once after totp setup is available
3596
- if (this.code || this.loading) {
3597
- logger.debug('setup was attempted while another is in progress, skipping setup.');
3598
- return [2
3599
- /*return*/
3600
- ];
3601
- }
367
+ this.handlePick = function (event) {
368
+ return __awaiter(_this, void 0, void 0, function () {
369
+ var file, _a, _b, path, level, track, fileToKey, key, error_2, filtered;
370
+
371
+ return __generator(this, function (_c) {
372
+ switch (_c.label) {
373
+ case 0:
374
+ file = event.target.files[0];
375
+ _a = this, _b = _a.path, path = _b === void 0 ? '' : _b, level = _a.level, track = _a.track, fileToKey = _a.fileToKey;
376
+ key = path + Object(_storage_helpers_1afafead_js__WEBPACK_IMPORTED_MODULE_7__["c"])(file, fileToKey);
377
+ _c.label = 1;
378
+
379
+ case 1:
380
+ _c.trys.push([1, 3,, 4]);
381
+
382
+ return [4
383
+ /*yield*/
384
+ , Object(_storage_helpers_1afafead_js__WEBPACK_IMPORTED_MODULE_7__["p"])(key, file, level, track, file['type'], logger)];
385
+
386
+ case 2:
387
+ _c.sent();
388
+
389
+ return [3
390
+ /*break*/
391
+ , 4];
392
+
393
+ case 3:
394
+ error_2 = _c.sent();
395
+ logger.error(error_2);
396
+ throw new Error(error_2);
397
+
398
+ case 4:
399
+ if (Object.keys(this.imgArr).includes(key)) {
400
+ this.albumItems = __spreadArrays(this.albumItems);
401
+ this.imgArr[key] = key + "-" + v4();
402
+ } else {
403
+ filtered = __spreadArrays(this.albumItems, this.filter ? this.filter([{
404
+ key: key
405
+ }]) : [{
406
+ key: key
407
+ }]);
408
+ this.albumItems = this.sort ? this.sort(filtered) : filtered;
409
+ }
3602
410
 
3603
- if (!this.user || !this.user.associateSoftwareToken) {
3604
- logger.debug('setup was attempted with invalid `user`, skipping setup.', this.user);
3605
411
  return [2
3606
412
  /*return*/
3607
413
  ];
3608
- }
3609
-
3610
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].setupTOTP !== 'function') {
3611
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
3612
- }
3613
-
3614
- this.setupMessage = null;
3615
- encodedIssuer = encodeURI(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.issuer));
3616
- this.loading = true;
3617
- _a.label = 1;
3618
-
3619
- case 1:
3620
- _a.trys.push([1, 3, 4, 5]);
3621
-
3622
- return [4
3623
- /*yield*/
3624
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].setupTOTP(this.user)];
3625
-
3626
- case 2:
3627
- secretKey = _a.sent();
3628
- logger.debug('secret key', secretKey);
3629
- this.code = this.buildOtpAuthPath(this.user, encodedIssuer, secretKey);
3630
- this.generateQRCode(this.code);
3631
- return [3
3632
- /*break*/
3633
- , 5];
3634
-
3635
- case 3:
3636
- error_2 = _a.sent();
3637
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_2);
3638
- logger.debug(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_SETUP_FAILURE), error_2);
3639
- return [3
3640
- /*break*/
3641
- , 5];
3642
-
3643
- case 4:
3644
- this.loading = false;
3645
- return [7
3646
- /*endfinally*/
3647
- ];
3648
-
3649
- case 5:
3650
- return [2
3651
- /*return*/
3652
- ];
3653
- }
414
+ }
415
+ });
3654
416
  });
3655
- });
3656
- };
3657
-
3658
- class_1.prototype.verifyTotpToken = function (event) {
3659
- return __awaiter(this, void 0, void 0, function () {
3660
- var user, error_3;
3661
- return __generator(this, function (_a) {
3662
- switch (_a.label) {
3663
- case 0:
3664
- if (event) {
3665
- event.preventDefault();
3666
- }
3667
-
3668
- if (!this.qrCodeInput) {
3669
- logger.debug('No TOTP Code provided');
3670
- return [2
3671
- /*return*/
3672
- ];
3673
- }
3674
-
3675
- user = this.user;
3676
-
3677
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].verifyTotpToken !== 'function' || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].setPreferredMFA !== 'function') {
3678
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
3679
- }
3680
-
3681
- _a.label = 1;
3682
-
3683
- case 1:
3684
- _a.trys.push([1, 5,, 6]);
3685
-
3686
- return [4
3687
- /*yield*/
3688
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].verifyTotpToken(user, this.qrCodeInput)];
3689
-
3690
- case 2:
3691
- _a.sent();
3692
-
3693
- return [4
3694
- /*yield*/
3695
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].setPreferredMFA(user, _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["M"].TOTP)];
3696
-
3697
- case 3:
3698
- _a.sent();
3699
-
3700
- this.setupMessage = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_SUCCESS_MESSAGE);
3701
- logger.debug(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_SUCCESS_MESSAGE));
3702
- return [4
3703
- /*yield*/
3704
- , this.handleComplete(user)];
3705
-
3706
- case 4:
3707
- _a.sent();
417
+ };
418
+ }
3708
419
 
3709
- return [3
3710
- /*break*/
3711
- , 6];
420
+ class_1.prototype.getContentType = function (item) {
421
+ return Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["filenameToContentType"])(item.key, 'image/*');
422
+ };
3712
423
 
3713
- case 5:
3714
- error_3 = _a.sent();
3715
- this.setupMessage = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_SETUP_FAILURE);
3716
- logger.error(error_3);
3717
- return [3
3718
- /*break*/
3719
- , 6];
3720
-
3721
- case 6:
3722
- return [2
3723
- /*return*/
3724
- ];
3725
- }
3726
- });
3727
- });
424
+ class_1.prototype.componentWillLoad = function () {
425
+ console.warn('Version `1.x` of Amplify UI has been deprecated and will be removed in a future major version of `aws-amplify`. Please visit https://ui.docs.amplify.aws/ for the current version of Amplify UI.');
426
+ this.list();
3728
427
  };
3729
428
 
3730
429
  class_1.prototype.render = function () {
3731
430
  var _this = this;
3732
431
 
3733
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["H"], null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-form-section", {
3734
- headerText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.headerText),
3735
- submitButtonText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_SUBMIT_BUTTON_TEXT),
3736
- handleSubmit: function handleSubmit(event) {
3737
- return _this.verifyTotpToken(event);
3738
- },
3739
- loading: this.loading
432
+ return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
433
+ "class": "album-container"
3740
434
  }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
3741
- "class": "totp-setup"
3742
- }, this.qrCodeImageSource && Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("img", {
3743
- src: this.qrCodeImageSource,
3744
- alt: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].QR_CODE_ALT)
3745
- }), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-form-field", {
3746
- label: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_LABEL),
3747
- inputProps: this.inputProps,
3748
- fieldId: "totpCode",
3749
- name: "totpCode",
3750
- handleInputChange: function handleInputChange(event) {
3751
- return _this.handleTotpInputChange(event);
3752
- }
3753
- }))));
435
+ "class": "grid-row"
436
+ }, this.albumItems.map(function (item) {
437
+ return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
438
+ "class": "grid-item",
439
+ key: "key-" + item.key
440
+ }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-s3-image", {
441
+ key: _this.imgArr[item.key],
442
+ imgKey: item.key,
443
+ level: _this.level,
444
+ path: _this.path,
445
+ identityId: _this.identityId,
446
+ track: _this.track,
447
+ handleOnError: _this.handleOnError,
448
+ handleOnLoad: _this.handleOnLoad
449
+ }), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", {
450
+ "class": "img-overlay"
451
+ }));
452
+ }))), this.picker && Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-picker", {
453
+ pickerText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.pickerText),
454
+ inputHandler: function inputHandler(e) {
455
+ return _this.handlePick(e);
456
+ },
457
+ acceptValue: "image/*"
458
+ }));
3754
459
  };
3755
460
 
3756
- Object.defineProperty(class_1, "watchers", {
3757
- get: function get() {
3758
- return {
3759
- "user": ["handleUserChange"]
3760
- };
3761
- },
3762
- enumerable: false,
3763
- configurable: true
3764
- });
3765
461
  return class_1;
3766
462
  }();
3767
463
 
3768
- AmplifyTOTPSetup.style = amplifyTotpSetupCss;
464
+ AmplifyS3Album.style = amplifyS3AlbumCss;
3769
465
 
3770
466
 
3771
467
  /***/ }),
3772
468
 
3773
- /***/ "../amplify-ui-components/dist/esm-es5/auth-helpers-557b83fc.js":
3774
- /*!**********************************************************************!*\
3775
- !*** ../amplify-ui-components/dist/esm-es5/auth-helpers-557b83fc.js ***!
3776
- \**********************************************************************/
3777
- /*! exports provided: c, h */
469
+ /***/ "../amplify-ui-components/dist/esm-es5/storage-helpers-1afafead.js":
470
+ /*!*************************************************************************!*\
471
+ !*** ../amplify-ui-components/dist/esm-es5/storage-helpers-1afafead.js ***!
472
+ \*************************************************************************/
473
+ /*! exports provided: a, c, g, i, p */
3778
474
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3779
475
 
3780
476
  "use strict";
3781
477
  __webpack_require__.r(__webpack_exports__);
3782
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return checkContact; });
3783
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "h", function() { return handleSignIn; });
3784
- /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
3785
- /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__);
3786
- /* harmony import */ var _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./auth-types-78df304e.js */ "../amplify-ui-components/dist/esm-es5/auth-types-78df304e.js");
3787
- /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @aws-amplify/auth */ "@aws-amplify/auth");
3788
- /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_2__);
3789
- /* harmony import */ var _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Translations-108d469f.js */ "../amplify-ui-components/dist/esm-es5/Translations-108d469f.js");
3790
- /* harmony import */ var _constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./constants-c8ecaa24.js */ "../amplify-ui-components/dist/esm-es5/constants-c8ecaa24.js");
3791
- /* harmony import */ var _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./helpers-14fcb50c.js */ "../amplify-ui-components/dist/esm-es5/helpers-14fcb50c.js");
478
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getTextSource; });
479
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return calcKey; });
480
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "g", function() { return getStorageObject; });
481
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "i", function() { return imageFileType; });
482
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "p", function() { return putStorageObject; });
483
+ /* harmony import */ var _constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants-c8ecaa24.js */ "../amplify-ui-components/dist/esm-es5/constants-c8ecaa24.js");
484
+ /* harmony import */ var _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @aws-amplify/storage */ "@aws-amplify/storage");
485
+ /* harmony import */ var _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__);
3792
486
  var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
3793
487
  function adopt(value) {
3794
488
  return value instanceof P ? value : new P(function (resolve) {
@@ -3934,29 +628,43 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
3934
628
 
3935
629
 
3936
630
 
631
+ var imageFileType = new Set(['apng', 'bmp', 'gif', 'ico', 'cur', 'jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp', 'png', 'svg', 'tif', 'tiff', 'webp']);
3937
632
 
633
+ var calcKey = function calcKey(file, fileToKey) {
634
+ var name = file.name,
635
+ size = file.size,
636
+ type = file.type;
637
+ var key = encodeURI(name);
3938
638
 
639
+ if (fileToKey) {
640
+ if (typeof fileToKey === 'string') {
641
+ key = fileToKey;
642
+ } else if (typeof fileToKey === 'function') {
643
+ key = fileToKey({
644
+ name: name,
645
+ size: size,
646
+ type: type
647
+ });
648
+ } else {
649
+ key = encodeURI(JSON.stringify(fileToKey));
650
+ }
3939
651
 
652
+ if (!key) {
653
+ key = 'empty_key';
654
+ }
655
+ }
3940
656
 
3941
- var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Logger"]('auth-helpers');
657
+ return key.replace(/\s/g, '_');
658
+ };
3942
659
 
3943
- function checkContact(user, handleAuthStateChange) {
3944
- return __awaiter(this, void 0, void 0, function () {
3945
- var data, newUser, error_1;
660
+ var getStorageObject = function getStorageObject(key, level, track, identityId, logger) {
661
+ return __awaiter(void 0, void 0, void 0, function () {
662
+ var src, error_1;
3946
663
  return __generator(this, function (_a) {
3947
664
  switch (_a.label) {
3948
665
  case 0:
3949
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_2__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_2__["Auth"].verifiedContact !== 'function') {
3950
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_4__["N"]);
3951
- } // If `user` is a federated user, we shouldn't call `verifiedContact`
3952
- // since `user` isn't `CognitoUser`
3953
-
3954
-
3955
- if (!isCognitoUser(user)) {
3956
- handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["A"].SignedIn, user);
3957
- return [2
3958
- /*return*/
3959
- ];
666
+ if (!_aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__["Storage"] || typeof _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__["Storage"].get !== 'function') {
667
+ throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_0__["d"]);
3960
668
  }
3961
669
 
3962
670
  _a.label = 1;
@@ -3966,28 +674,22 @@ function checkContact(user, handleAuthStateChange) {
3966
674
 
3967
675
  return [4
3968
676
  /*yield*/
3969
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_2__["Auth"].verifiedContact(user)];
677
+ , _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__["Storage"].get(key, {
678
+ level: level,
679
+ track: track,
680
+ identityId: identityId
681
+ })];
3970
682
 
3971
683
  case 2:
3972
- data = _a.sent();
3973
-
3974
- if (!Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["isEmpty"])(data.verified) || Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["isEmpty"])(data.unverified)) {
3975
- handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["A"].SignedIn, user);
3976
- } else {
3977
- newUser = Object.assign(user, data);
3978
- handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["A"].VerifyContact, newUser);
3979
- }
3980
-
3981
- return [3
3982
- /*break*/
3983
- , 4];
684
+ src = _a.sent();
685
+ logger.debug('Storage image get', src);
686
+ return [2
687
+ /*return*/
688
+ , src];
3984
689
 
3985
690
  case 3:
3986
691
  error_1 = _a.sent();
3987
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_5__["a"])(error_1);
3988
- return [3
3989
- /*break*/
3990
- , 4];
692
+ throw new Error(error_1);
3991
693
 
3992
694
  case 4:
3993
695
  return [2
@@ -3996,116 +698,110 @@ function checkContact(user, handleAuthStateChange) {
3996
698
  }
3997
699
  });
3998
700
  });
3999
- }
701
+ };
702
+
703
+ var readFileAsync = function readFileAsync(blob) {
704
+ return new Promise(function (resolve, reject) {
705
+ var reader = new FileReader();
706
+
707
+ reader.onload = function () {
708
+ resolve(reader.result);
709
+ };
710
+
711
+ reader.onerror = function () {
712
+ reject('Failed to read file!');
713
+ reader.abort();
714
+ };
715
+
716
+ reader.readAsText(blob);
717
+ });
718
+ };
4000
719
 
4001
- var handleSignIn = function handleSignIn(username, password, handleAuthStateChange, usernameAlias) {
720
+ var getTextSource = function getTextSource(key, level, track, identityId, logger) {
4002
721
  return __awaiter(void 0, void 0, void 0, function () {
4003
- var user, error_2;
722
+ var textSrc, text, error_2;
4004
723
  return __generator(this, function (_a) {
4005
724
  switch (_a.label) {
4006
725
  case 0:
4007
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_2__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_2__["Auth"].signIn !== 'function') {
4008
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_4__["N"]);
726
+ if (!_aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__["Storage"] || typeof _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__["Storage"].get !== 'function') {
727
+ throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_0__["d"]);
4009
728
  }
4010
729
 
4011
730
  _a.label = 1;
4012
731
 
4013
732
  case 1:
4014
- _a.trys.push([1, 9,, 10]);
733
+ _a.trys.push([1, 4,, 5]);
4015
734
 
4016
735
  return [4
4017
736
  /*yield*/
4018
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_2__["Auth"].signIn(username, password)];
737
+ , _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__["Storage"].get(key, {
738
+ download: true,
739
+ level: level,
740
+ track: track,
741
+ identityId: identityId
742
+ })];
4019
743
 
4020
744
  case 2:
4021
- user = _a.sent();
4022
- logger.debug(user);
4023
- if (!(user.challengeName === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["C"].SMSMFA || user.challengeName === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["C"].SoftwareTokenMFA)) return [3
4024
- /*break*/
4025
- , 3];
4026
- logger.debug('confirm user with ' + user.challengeName);
4027
- handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["A"].ConfirmSignIn, user);
4028
- return [3
4029
- /*break*/
4030
- , 8];
745
+ textSrc = _a.sent();
746
+ logger.debug(textSrc);
747
+ return [4
748
+ /*yield*/
749
+ , readFileAsync(textSrc['Body'])];
4031
750
 
4032
751
  case 3:
4033
- if (!(user.challengeName === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["C"].NewPasswordRequired)) return [3
4034
- /*break*/
4035
- , 4];
4036
- logger.debug('require new password', user.challengeParam);
4037
- handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["A"].ResetPassword, user);
4038
- return [3
4039
- /*break*/
4040
- , 8];
752
+ text = _a.sent();
753
+ return [2
754
+ /*return*/
755
+ , text];
4041
756
 
4042
757
  case 4:
4043
- if (!(user.challengeName === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["C"].MFASetup)) return [3
4044
- /*break*/
4045
- , 5];
4046
- logger.debug('TOTP setup', user.challengeParam);
4047
- handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["A"].TOTPSetup, user);
4048
- return [3
4049
- /*break*/
4050
- , 8];
758
+ error_2 = _a.sent();
759
+ throw new Error(error_2);
4051
760
 
4052
761
  case 5:
4053
- if (!(user.challengeName === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["C"].CustomChallenge && user.challengeParam && user.challengeParam.trigger === 'true')) return [3
4054
- /*break*/
4055
- , 6];
4056
- logger.debug('custom challenge', user.challengeParam);
4057
- handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["A"].CustomConfirmSignIn, user);
4058
- return [3
4059
- /*break*/
4060
- , 8];
4061
-
4062
- case 6:
4063
- return [4
4064
- /*yield*/
4065
- , checkContact(user, handleAuthStateChange)];
4066
-
4067
- case 7:
4068
- _a.sent();
4069
-
4070
- _a.label = 8;
762
+ return [2
763
+ /*return*/
764
+ ];
765
+ }
766
+ });
767
+ });
768
+ };
4071
769
 
4072
- case 8:
4073
- return [3
4074
- /*break*/
4075
- , 10];
770
+ var putStorageObject = function putStorageObject(key, body, level, track, contentType, logger) {
771
+ return __awaiter(void 0, void 0, void 0, function () {
772
+ var data, error_3;
773
+ return __generator(this, function (_a) {
774
+ switch (_a.label) {
775
+ case 0:
776
+ if (!_aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__["Storage"] || typeof _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__["Storage"].put !== 'function') {
777
+ throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_0__["d"]);
778
+ }
4076
779
 
4077
- case 9:
4078
- error_2 = _a.sent();
780
+ _a.label = 1;
4079
781
 
4080
- if (error_2.code === 'UserNotConfirmedException') {
4081
- logger.debug('the user is not confirmed');
4082
- handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["A"].ConfirmSignUp, {
4083
- username: username
4084
- });
4085
- } else if (error_2.code === 'PasswordResetRequiredException') {
4086
- logger.debug('the user requires a new password');
4087
- handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["A"].ForgotPassword, {
4088
- username: username
4089
- });
4090
- } else if (error_2.code === 'InvalidParameterException' && password === '') {
4091
- logger.debug('Password cannot be empty');
4092
- error_2.message = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_3__["T"].EMPTY_PASSWORD;
4093
- } else if (error_2.message === _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_3__["T"].EMPTY_USERNAME) {
4094
- if (usernameAlias === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["U"].email) {
4095
- error_2.message = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_3__["T"].EMPTY_EMAIL;
4096
- }
782
+ case 1:
783
+ _a.trys.push([1, 3,, 4]);
4097
784
 
4098
- if (usernameAlias === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_1__["U"].phone_number) {
4099
- error_2.message = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_3__["T"].EMPTY_PHONE;
4100
- }
4101
- }
785
+ return [4
786
+ /*yield*/
787
+ , _aws_amplify_storage__WEBPACK_IMPORTED_MODULE_1__["Storage"].put(key, body, {
788
+ contentType: contentType,
789
+ level: level,
790
+ track: track
791
+ })];
4102
792
 
4103
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_5__["a"])(error_2);
793
+ case 2:
794
+ data = _a.sent();
795
+ logger.debug('Upload data', data);
4104
796
  return [3
4105
797
  /*break*/
4106
- , 10];
798
+ , 4];
799
+
800
+ case 3:
801
+ error_3 = _a.sent();
802
+ throw new Error(error_3);
4107
803
 
4108
- case 10:
804
+ case 4:
4109
805
  return [2
4110
806
  /*return*/
4111
807
  ];
@@ -4114,10 +810,6 @@ var handleSignIn = function handleSignIn(username, password, handleAuthStateChan
4114
810
  });
4115
811
  };
4116
812
 
4117
- var isCognitoUser = function isCognitoUser(user) {
4118
- return user instanceof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_2__["CognitoUser"];
4119
- };
4120
-
4121
813
 
4122
814
 
4123
815
  /***/ })