@ekyc_qoobiss/qbs-ect-cmp 1.10.2 → 1.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/cjs/{agreement-check_16.cjs.entry.js → agreement-check_17.cjs.entry.js} +2973 -6
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/qbs-ect-cmp.cjs.js +1 -1
  4. package/dist/collection/collection-manifest.json +1 -0
  5. package/dist/collection/components/common/id-back-capture/id-back-capture.js +0 -1
  6. package/dist/collection/components/flow/id-double-side/id-double-side.js +2 -0
  7. package/dist/collection/components/flow/mobile-redirect/mobile-redirect.css +10 -0
  8. package/dist/collection/components/flow/mobile-redirect/mobile-redirect.js +105 -0
  9. package/dist/collection/components/identification-component/identification-component.js +8 -3
  10. package/dist/collection/helpers/ApiCall.js +11 -1
  11. package/dist/collection/helpers/textValues.js +7 -0
  12. package/dist/collection/models/ILinkSend.js +1 -0
  13. package/dist/collection/models/IOrderStatus.js +1 -0
  14. package/dist/collection/models/OrderStatuses.js +7 -0
  15. package/dist/esm/{agreement-check_16.entry.js → agreement-check_17.entry.js} +2973 -7
  16. package/dist/esm/loader.js +1 -1
  17. package/dist/esm/qbs-ect-cmp.js +1 -1
  18. package/dist/qbs-ect-cmp/{p-658d6a9d.entry.js → p-43f6e06b.entry.js} +20 -20
  19. package/dist/qbs-ect-cmp/qbs-ect-cmp.esm.js +1 -1
  20. package/dist/types/components/flow/mobile-redirect/mobile-redirect.d.ts +20 -0
  21. package/dist/types/components.d.ts +18 -0
  22. package/dist/types/helpers/ApiCall.d.ts +5 -1
  23. package/dist/types/helpers/textValues.d.ts +7 -0
  24. package/dist/types/models/ILinkSend.d.ts +3 -0
  25. package/dist/types/models/IOrderStatus.d.ts +4 -0
  26. package/dist/types/models/OrderStatuses.d.ts +6 -0
  27. package/package.json +2 -1
@@ -4,6 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-79f82518.js');
6
6
 
7
+ var OrderStatuses;
8
+ (function (OrderStatuses) {
9
+ OrderStatuses[OrderStatuses["Capturing"] = 0] = "Capturing";
10
+ OrderStatuses[OrderStatuses["FinishedCapturing"] = 1] = "FinishedCapturing";
11
+ OrderStatuses[OrderStatuses["Waiting"] = 2] = "Waiting";
12
+ OrderStatuses[OrderStatuses["NotFound"] = 3] = "NotFound";
13
+ })(OrderStatuses || (OrderStatuses = {}));
14
+
7
15
  const appendToMap = (map, propName, value) => {
8
16
  const items = map.get(propName);
9
17
  if (!items) {
@@ -320,8 +328,15 @@ class ApiUrls {
320
328
  this.UploadCapture = this.uriEnv + 'validation/upload/capture';
321
329
  this.GetAgreement = this.uriEnv + 'validation/agreement/content';
322
330
  this.GenerateAgreement = this.uriEnv + 'validation/agreement/generate';
331
+ this.SendLink = this.uriEnv + 'validation/otp/sendlink';
332
+ this.GetStatus = this.uriEnv + 'validation/identity/status';
323
333
  }
324
- }
334
+ }
335
+ class MobileRedirectValues extends GlobalValues {
336
+ }
337
+ MobileRedirectValues.InfoTop = 'Pentru a continua scanați codul de mai jos cu un smartphone.';
338
+ MobileRedirectValues.InfoBottom = 'Sau introduceți un număr de telefon sau o adresă de e-mail pentru a primi link-ul pe smartphone.';
339
+ MobileRedirectValues.Validation = 'Numar de telefon sau adresa e-mail invalid';
325
340
 
326
341
  const { state, onChange } = createStore({
327
342
  flowStatus: FlowStatus.LANDING,
@@ -393,7 +408,7 @@ class ApiCall {
393
408
  return jsonResp.valid;
394
409
  }
395
410
  async AddIdentificationRequest(requestId, deviceInfo) {
396
- let data = { requestId: requestId, clientDeviceInfo: deviceInfo };
411
+ let data = { requestId: requestId, clientDeviceInfo: JSON.stringify(deviceInfo), isDesktop: !deviceInfo.isMobile };
397
412
  let jsonResp = await this.post(this.urls.IdentityInsert, JSON.stringify(data));
398
413
  state.hasIdBack = jsonResp.hasIdBack;
399
414
  state.agreementsValidation = jsonResp.agreementsValidation;
@@ -424,6 +439,15 @@ class ApiCall {
424
439
  let resp = await this.post(this.urls.GenerateAgreement, JSON.stringify(data));
425
440
  return resp.generation;
426
441
  }
442
+ async GetStatus(requestId) {
443
+ let resp = await this.get(this.urls.GetStatus + '?orderId=' + requestId);
444
+ return OrderStatuses[resp.status];
445
+ }
446
+ async SendLink(link, phoneNumber) {
447
+ let data = { link: link, phoneNumber: phoneNumber };
448
+ let resp = await this.post(this.urls.SendLink, JSON.stringify(data));
449
+ return resp.sent;
450
+ }
427
451
  }
428
452
 
429
453
  const agreementCheckCss = "";
@@ -5353,7 +5377,6 @@ const IdBackCapture = class {
5353
5377
  if (this.captureTaken)
5354
5378
  return;
5355
5379
  this.captureTaken = true;
5356
- this.titleMesage = IdCaptureValues.Loading;
5357
5380
  let res = await Stream.getInstance().takePhoto();
5358
5381
  this.photoIsReady(res);
5359
5382
  }
@@ -5623,6 +5646,8 @@ const IdDoubleSide = class {
5623
5646
  this.flow.recordingUploadType = 'IdBackVideo';
5624
5647
  this.flow.photoFile = null;
5625
5648
  this.flow.recordingFile = null;
5649
+ this.flow.photoDone = false;
5650
+ this.flow.recordingDone = false;
5626
5651
  this.front = false;
5627
5652
  this.showHowTo = true;
5628
5653
  return;
@@ -5912,7 +5937,7 @@ const IdentificationComponent = class {
5912
5937
  }
5913
5938
  try {
5914
5939
  if (state.token != '' && state.requestId != '') {
5915
- state.initialised = await this.apiCall.AddIdentificationRequest(state.requestId, JSON.stringify(this.device));
5940
+ state.initialised = await this.apiCall.AddIdentificationRequest(state.requestId, this.device);
5916
5941
  }
5917
5942
  }
5918
5943
  catch (e) {
@@ -5921,8 +5946,13 @@ const IdentificationComponent = class {
5921
5946
  }
5922
5947
  render() {
5923
5948
  let currentBlock = index.h("div", null);
5924
- if (state.flowStatus == FlowStatus.LANDING) {
5925
- currentBlock = index.h("landing-validation", { device: this.device });
5949
+ if (this.device.isMobile) {
5950
+ if (state.flowStatus == FlowStatus.LANDING) {
5951
+ currentBlock = index.h("landing-validation", { device: this.device });
5952
+ }
5953
+ }
5954
+ else {
5955
+ currentBlock = index.h("mobile-redirect", null);
5926
5956
  }
5927
5957
  if (state.flowStatus == FlowStatus.AGREEMENT) {
5928
5958
  currentBlock = index.h("agreement-info", null);
@@ -6013,6 +6043,2942 @@ const LandingValidation = class {
6013
6043
  };
6014
6044
  LandingValidation.style = landingValidationCss;
6015
6045
 
6046
+ // can-promise has a crash in some versions of react native that dont have
6047
+ // standard global objects
6048
+ // https://github.com/soldair/node-qrcode/issues/157
6049
+
6050
+ var canPromise = function () {
6051
+ return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then
6052
+ };
6053
+
6054
+ let toSJISFunction;
6055
+ const CODEWORDS_COUNT = [
6056
+ 0, // Not used
6057
+ 26, 44, 70, 100, 134, 172, 196, 242, 292, 346,
6058
+ 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,
6059
+ 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,
6060
+ 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
6061
+ ];
6062
+
6063
+ /**
6064
+ * Returns the QR Code size for the specified version
6065
+ *
6066
+ * @param {Number} version QR Code version
6067
+ * @return {Number} size of QR code
6068
+ */
6069
+ var getSymbolSize$1 = function getSymbolSize (version) {
6070
+ if (!version) throw new Error('"version" cannot be null or undefined')
6071
+ if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40')
6072
+ return version * 4 + 17
6073
+ };
6074
+
6075
+ /**
6076
+ * Returns the total number of codewords used to store data and EC information.
6077
+ *
6078
+ * @param {Number} version QR Code version
6079
+ * @return {Number} Data length in bits
6080
+ */
6081
+ var getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {
6082
+ return CODEWORDS_COUNT[version]
6083
+ };
6084
+
6085
+ /**
6086
+ * Encode data with Bose-Chaudhuri-Hocquenghem
6087
+ *
6088
+ * @param {Number} data Value to encode
6089
+ * @return {Number} Encoded value
6090
+ */
6091
+ var getBCHDigit = function (data) {
6092
+ let digit = 0;
6093
+
6094
+ while (data !== 0) {
6095
+ digit++;
6096
+ data >>>= 1;
6097
+ }
6098
+
6099
+ return digit
6100
+ };
6101
+
6102
+ var setToSJISFunction = function setToSJISFunction (f) {
6103
+ if (typeof f !== 'function') {
6104
+ throw new Error('"toSJISFunc" is not a valid function.')
6105
+ }
6106
+
6107
+ toSJISFunction = f;
6108
+ };
6109
+
6110
+ var isKanjiModeEnabled = function () {
6111
+ return typeof toSJISFunction !== 'undefined'
6112
+ };
6113
+
6114
+ var toSJIS = function toSJIS (kanji) {
6115
+ return toSJISFunction(kanji)
6116
+ };
6117
+
6118
+ var utils$1 = {
6119
+ getSymbolSize: getSymbolSize$1,
6120
+ getSymbolTotalCodewords: getSymbolTotalCodewords,
6121
+ getBCHDigit: getBCHDigit,
6122
+ setToSJISFunction: setToSJISFunction,
6123
+ isKanjiModeEnabled: isKanjiModeEnabled,
6124
+ toSJIS: toSJIS
6125
+ };
6126
+
6127
+ var errorCorrectionLevel = createCommonjsModule(function (module, exports) {
6128
+ exports.L = { bit: 1 };
6129
+ exports.M = { bit: 0 };
6130
+ exports.Q = { bit: 3 };
6131
+ exports.H = { bit: 2 };
6132
+
6133
+ function fromString (string) {
6134
+ if (typeof string !== 'string') {
6135
+ throw new Error('Param is not a string')
6136
+ }
6137
+
6138
+ const lcStr = string.toLowerCase();
6139
+
6140
+ switch (lcStr) {
6141
+ case 'l':
6142
+ case 'low':
6143
+ return exports.L
6144
+
6145
+ case 'm':
6146
+ case 'medium':
6147
+ return exports.M
6148
+
6149
+ case 'q':
6150
+ case 'quartile':
6151
+ return exports.Q
6152
+
6153
+ case 'h':
6154
+ case 'high':
6155
+ return exports.H
6156
+
6157
+ default:
6158
+ throw new Error('Unknown EC Level: ' + string)
6159
+ }
6160
+ }
6161
+
6162
+ exports.isValid = function isValid (level) {
6163
+ return level && typeof level.bit !== 'undefined' &&
6164
+ level.bit >= 0 && level.bit < 4
6165
+ };
6166
+
6167
+ exports.from = function from (value, defaultValue) {
6168
+ if (exports.isValid(value)) {
6169
+ return value
6170
+ }
6171
+
6172
+ try {
6173
+ return fromString(value)
6174
+ } catch (e) {
6175
+ return defaultValue
6176
+ }
6177
+ };
6178
+ });
6179
+
6180
+ function BitBuffer () {
6181
+ this.buffer = [];
6182
+ this.length = 0;
6183
+ }
6184
+
6185
+ BitBuffer.prototype = {
6186
+
6187
+ get: function (index) {
6188
+ const bufIndex = Math.floor(index / 8);
6189
+ return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
6190
+ },
6191
+
6192
+ put: function (num, length) {
6193
+ for (let i = 0; i < length; i++) {
6194
+ this.putBit(((num >>> (length - i - 1)) & 1) === 1);
6195
+ }
6196
+ },
6197
+
6198
+ getLengthInBits: function () {
6199
+ return this.length
6200
+ },
6201
+
6202
+ putBit: function (bit) {
6203
+ const bufIndex = Math.floor(this.length / 8);
6204
+ if (this.buffer.length <= bufIndex) {
6205
+ this.buffer.push(0);
6206
+ }
6207
+
6208
+ if (bit) {
6209
+ this.buffer[bufIndex] |= (0x80 >>> (this.length % 8));
6210
+ }
6211
+
6212
+ this.length++;
6213
+ }
6214
+ };
6215
+
6216
+ var bitBuffer = BitBuffer;
6217
+
6218
+ /**
6219
+ * Helper class to handle QR Code symbol modules
6220
+ *
6221
+ * @param {Number} size Symbol size
6222
+ */
6223
+ function BitMatrix (size) {
6224
+ if (!size || size < 1) {
6225
+ throw new Error('BitMatrix size must be defined and greater than 0')
6226
+ }
6227
+
6228
+ this.size = size;
6229
+ this.data = new Uint8Array(size * size);
6230
+ this.reservedBit = new Uint8Array(size * size);
6231
+ }
6232
+
6233
+ /**
6234
+ * Set bit value at specified location
6235
+ * If reserved flag is set, this bit will be ignored during masking process
6236
+ *
6237
+ * @param {Number} row
6238
+ * @param {Number} col
6239
+ * @param {Boolean} value
6240
+ * @param {Boolean} reserved
6241
+ */
6242
+ BitMatrix.prototype.set = function (row, col, value, reserved) {
6243
+ const index = row * this.size + col;
6244
+ this.data[index] = value;
6245
+ if (reserved) this.reservedBit[index] = true;
6246
+ };
6247
+
6248
+ /**
6249
+ * Returns bit value at specified location
6250
+ *
6251
+ * @param {Number} row
6252
+ * @param {Number} col
6253
+ * @return {Boolean}
6254
+ */
6255
+ BitMatrix.prototype.get = function (row, col) {
6256
+ return this.data[row * this.size + col]
6257
+ };
6258
+
6259
+ /**
6260
+ * Applies xor operator at specified location
6261
+ * (used during masking process)
6262
+ *
6263
+ * @param {Number} row
6264
+ * @param {Number} col
6265
+ * @param {Boolean} value
6266
+ */
6267
+ BitMatrix.prototype.xor = function (row, col, value) {
6268
+ this.data[row * this.size + col] ^= value;
6269
+ };
6270
+
6271
+ /**
6272
+ * Check if bit at specified location is reserved
6273
+ *
6274
+ * @param {Number} row
6275
+ * @param {Number} col
6276
+ * @return {Boolean}
6277
+ */
6278
+ BitMatrix.prototype.isReserved = function (row, col) {
6279
+ return this.reservedBit[row * this.size + col]
6280
+ };
6281
+
6282
+ var bitMatrix = BitMatrix;
6283
+
6284
+ var alignmentPattern = createCommonjsModule(function (module, exports) {
6285
+ /**
6286
+ * Alignment pattern are fixed reference pattern in defined positions
6287
+ * in a matrix symbology, which enables the decode software to re-synchronise
6288
+ * the coordinate mapping of the image modules in the event of moderate amounts
6289
+ * of distortion of the image.
6290
+ *
6291
+ * Alignment patterns are present only in QR Code symbols of version 2 or larger
6292
+ * and their number depends on the symbol version.
6293
+ */
6294
+
6295
+ const getSymbolSize = utils$1.getSymbolSize;
6296
+
6297
+ /**
6298
+ * Calculate the row/column coordinates of the center module of each alignment pattern
6299
+ * for the specified QR Code version.
6300
+ *
6301
+ * The alignment patterns are positioned symmetrically on either side of the diagonal
6302
+ * running from the top left corner of the symbol to the bottom right corner.
6303
+ *
6304
+ * Since positions are simmetrical only half of the coordinates are returned.
6305
+ * Each item of the array will represent in turn the x and y coordinate.
6306
+ * @see {@link getPositions}
6307
+ *
6308
+ * @param {Number} version QR Code version
6309
+ * @return {Array} Array of coordinate
6310
+ */
6311
+ exports.getRowColCoords = function getRowColCoords (version) {
6312
+ if (version === 1) return []
6313
+
6314
+ const posCount = Math.floor(version / 7) + 2;
6315
+ const size = getSymbolSize(version);
6316
+ const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
6317
+ const positions = [size - 7]; // Last coord is always (size - 7)
6318
+
6319
+ for (let i = 1; i < posCount - 1; i++) {
6320
+ positions[i] = positions[i - 1] - intervals;
6321
+ }
6322
+
6323
+ positions.push(6); // First coord is always 6
6324
+
6325
+ return positions.reverse()
6326
+ };
6327
+
6328
+ /**
6329
+ * Returns an array containing the positions of each alignment pattern.
6330
+ * Each array's element represent the center point of the pattern as (x, y) coordinates
6331
+ *
6332
+ * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
6333
+ * and filtering out the items that overlaps with finder pattern
6334
+ *
6335
+ * @example
6336
+ * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
6337
+ * The alignment patterns, therefore, are to be centered on (row, column)
6338
+ * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
6339
+ * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
6340
+ * and are not therefore used for alignment patterns.
6341
+ *
6342
+ * let pos = getPositions(7)
6343
+ * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
6344
+ *
6345
+ * @param {Number} version QR Code version
6346
+ * @return {Array} Array of coordinates
6347
+ */
6348
+ exports.getPositions = function getPositions (version) {
6349
+ const coords = [];
6350
+ const pos = exports.getRowColCoords(version);
6351
+ const posLength = pos.length;
6352
+
6353
+ for (let i = 0; i < posLength; i++) {
6354
+ for (let j = 0; j < posLength; j++) {
6355
+ // Skip if position is occupied by finder patterns
6356
+ if ((i === 0 && j === 0) || // top-left
6357
+ (i === 0 && j === posLength - 1) || // bottom-left
6358
+ (i === posLength - 1 && j === 0)) { // top-right
6359
+ continue
6360
+ }
6361
+
6362
+ coords.push([pos[i], pos[j]]);
6363
+ }
6364
+ }
6365
+
6366
+ return coords
6367
+ };
6368
+ });
6369
+
6370
+ const getSymbolSize = utils$1.getSymbolSize;
6371
+ const FINDER_PATTERN_SIZE = 7;
6372
+
6373
+ /**
6374
+ * Returns an array containing the positions of each finder pattern.
6375
+ * Each array's element represent the top-left point of the pattern as (x, y) coordinates
6376
+ *
6377
+ * @param {Number} version QR Code version
6378
+ * @return {Array} Array of coordinates
6379
+ */
6380
+ var getPositions = function getPositions (version) {
6381
+ const size = getSymbolSize(version);
6382
+
6383
+ return [
6384
+ // top-left
6385
+ [0, 0],
6386
+ // top-right
6387
+ [size - FINDER_PATTERN_SIZE, 0],
6388
+ // bottom-left
6389
+ [0, size - FINDER_PATTERN_SIZE]
6390
+ ]
6391
+ };
6392
+
6393
+ var finderPattern = {
6394
+ getPositions: getPositions
6395
+ };
6396
+
6397
+ var maskPattern = createCommonjsModule(function (module, exports) {
6398
+ /**
6399
+ * Data mask pattern reference
6400
+ * @type {Object}
6401
+ */
6402
+ exports.Patterns = {
6403
+ PATTERN000: 0,
6404
+ PATTERN001: 1,
6405
+ PATTERN010: 2,
6406
+ PATTERN011: 3,
6407
+ PATTERN100: 4,
6408
+ PATTERN101: 5,
6409
+ PATTERN110: 6,
6410
+ PATTERN111: 7
6411
+ };
6412
+
6413
+ /**
6414
+ * Weighted penalty scores for the undesirable features
6415
+ * @type {Object}
6416
+ */
6417
+ const PenaltyScores = {
6418
+ N1: 3,
6419
+ N2: 3,
6420
+ N3: 40,
6421
+ N4: 10
6422
+ };
6423
+
6424
+ /**
6425
+ * Check if mask pattern value is valid
6426
+ *
6427
+ * @param {Number} mask Mask pattern
6428
+ * @return {Boolean} true if valid, false otherwise
6429
+ */
6430
+ exports.isValid = function isValid (mask) {
6431
+ return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7
6432
+ };
6433
+
6434
+ /**
6435
+ * Returns mask pattern from a value.
6436
+ * If value is not valid, returns undefined
6437
+ *
6438
+ * @param {Number|String} value Mask pattern value
6439
+ * @return {Number} Valid mask pattern or undefined
6440
+ */
6441
+ exports.from = function from (value) {
6442
+ return exports.isValid(value) ? parseInt(value, 10) : undefined
6443
+ };
6444
+
6445
+ /**
6446
+ * Find adjacent modules in row/column with the same color
6447
+ * and assign a penalty value.
6448
+ *
6449
+ * Points: N1 + i
6450
+ * i is the amount by which the number of adjacent modules of the same color exceeds 5
6451
+ */
6452
+ exports.getPenaltyN1 = function getPenaltyN1 (data) {
6453
+ const size = data.size;
6454
+ let points = 0;
6455
+ let sameCountCol = 0;
6456
+ let sameCountRow = 0;
6457
+ let lastCol = null;
6458
+ let lastRow = null;
6459
+
6460
+ for (let row = 0; row < size; row++) {
6461
+ sameCountCol = sameCountRow = 0;
6462
+ lastCol = lastRow = null;
6463
+
6464
+ for (let col = 0; col < size; col++) {
6465
+ let module = data.get(row, col);
6466
+ if (module === lastCol) {
6467
+ sameCountCol++;
6468
+ } else {
6469
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
6470
+ lastCol = module;
6471
+ sameCountCol = 1;
6472
+ }
6473
+
6474
+ module = data.get(col, row);
6475
+ if (module === lastRow) {
6476
+ sameCountRow++;
6477
+ } else {
6478
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
6479
+ lastRow = module;
6480
+ sameCountRow = 1;
6481
+ }
6482
+ }
6483
+
6484
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
6485
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
6486
+ }
6487
+
6488
+ return points
6489
+ };
6490
+
6491
+ /**
6492
+ * Find 2x2 blocks with the same color and assign a penalty value
6493
+ *
6494
+ * Points: N2 * (m - 1) * (n - 1)
6495
+ */
6496
+ exports.getPenaltyN2 = function getPenaltyN2 (data) {
6497
+ const size = data.size;
6498
+ let points = 0;
6499
+
6500
+ for (let row = 0; row < size - 1; row++) {
6501
+ for (let col = 0; col < size - 1; col++) {
6502
+ const last = data.get(row, col) +
6503
+ data.get(row, col + 1) +
6504
+ data.get(row + 1, col) +
6505
+ data.get(row + 1, col + 1);
6506
+
6507
+ if (last === 4 || last === 0) points++;
6508
+ }
6509
+ }
6510
+
6511
+ return points * PenaltyScores.N2
6512
+ };
6513
+
6514
+ /**
6515
+ * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
6516
+ * preceded or followed by light area 4 modules wide
6517
+ *
6518
+ * Points: N3 * number of pattern found
6519
+ */
6520
+ exports.getPenaltyN3 = function getPenaltyN3 (data) {
6521
+ const size = data.size;
6522
+ let points = 0;
6523
+ let bitsCol = 0;
6524
+ let bitsRow = 0;
6525
+
6526
+ for (let row = 0; row < size; row++) {
6527
+ bitsCol = bitsRow = 0;
6528
+ for (let col = 0; col < size; col++) {
6529
+ bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col);
6530
+ if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++;
6531
+
6532
+ bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row);
6533
+ if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++;
6534
+ }
6535
+ }
6536
+
6537
+ return points * PenaltyScores.N3
6538
+ };
6539
+
6540
+ /**
6541
+ * Calculate proportion of dark modules in entire symbol
6542
+ *
6543
+ * Points: N4 * k
6544
+ *
6545
+ * k is the rating of the deviation of the proportion of dark modules
6546
+ * in the symbol from 50% in steps of 5%
6547
+ */
6548
+ exports.getPenaltyN4 = function getPenaltyN4 (data) {
6549
+ let darkCount = 0;
6550
+ const modulesCount = data.data.length;
6551
+
6552
+ for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
6553
+
6554
+ const k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10);
6555
+
6556
+ return k * PenaltyScores.N4
6557
+ };
6558
+
6559
+ /**
6560
+ * Return mask value at given position
6561
+ *
6562
+ * @param {Number} maskPattern Pattern reference value
6563
+ * @param {Number} i Row
6564
+ * @param {Number} j Column
6565
+ * @return {Boolean} Mask value
6566
+ */
6567
+ function getMaskAt (maskPattern, i, j) {
6568
+ switch (maskPattern) {
6569
+ case exports.Patterns.PATTERN000: return (i + j) % 2 === 0
6570
+ case exports.Patterns.PATTERN001: return i % 2 === 0
6571
+ case exports.Patterns.PATTERN010: return j % 3 === 0
6572
+ case exports.Patterns.PATTERN011: return (i + j) % 3 === 0
6573
+ case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0
6574
+ case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0
6575
+ case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0
6576
+ case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0
6577
+
6578
+ default: throw new Error('bad maskPattern:' + maskPattern)
6579
+ }
6580
+ }
6581
+
6582
+ /**
6583
+ * Apply a mask pattern to a BitMatrix
6584
+ *
6585
+ * @param {Number} pattern Pattern reference number
6586
+ * @param {BitMatrix} data BitMatrix data
6587
+ */
6588
+ exports.applyMask = function applyMask (pattern, data) {
6589
+ const size = data.size;
6590
+
6591
+ for (let col = 0; col < size; col++) {
6592
+ for (let row = 0; row < size; row++) {
6593
+ if (data.isReserved(row, col)) continue
6594
+ data.xor(row, col, getMaskAt(pattern, row, col));
6595
+ }
6596
+ }
6597
+ };
6598
+
6599
+ /**
6600
+ * Returns the best mask pattern for data
6601
+ *
6602
+ * @param {BitMatrix} data
6603
+ * @return {Number} Mask pattern reference number
6604
+ */
6605
+ exports.getBestMask = function getBestMask (data, setupFormatFunc) {
6606
+ const numPatterns = Object.keys(exports.Patterns).length;
6607
+ let bestPattern = 0;
6608
+ let lowerPenalty = Infinity;
6609
+
6610
+ for (let p = 0; p < numPatterns; p++) {
6611
+ setupFormatFunc(p);
6612
+ exports.applyMask(p, data);
6613
+
6614
+ // Calculate penalty
6615
+ const penalty =
6616
+ exports.getPenaltyN1(data) +
6617
+ exports.getPenaltyN2(data) +
6618
+ exports.getPenaltyN3(data) +
6619
+ exports.getPenaltyN4(data);
6620
+
6621
+ // Undo previously applied mask
6622
+ exports.applyMask(p, data);
6623
+
6624
+ if (penalty < lowerPenalty) {
6625
+ lowerPenalty = penalty;
6626
+ bestPattern = p;
6627
+ }
6628
+ }
6629
+
6630
+ return bestPattern
6631
+ };
6632
+ });
6633
+
6634
+ const EC_BLOCKS_TABLE = [
6635
+ // L M Q H
6636
+ 1, 1, 1, 1,
6637
+ 1, 1, 1, 1,
6638
+ 1, 1, 2, 2,
6639
+ 1, 2, 2, 4,
6640
+ 1, 2, 4, 4,
6641
+ 2, 4, 4, 4,
6642
+ 2, 4, 6, 5,
6643
+ 2, 4, 6, 6,
6644
+ 2, 5, 8, 8,
6645
+ 4, 5, 8, 8,
6646
+ 4, 5, 8, 11,
6647
+ 4, 8, 10, 11,
6648
+ 4, 9, 12, 16,
6649
+ 4, 9, 16, 16,
6650
+ 6, 10, 12, 18,
6651
+ 6, 10, 17, 16,
6652
+ 6, 11, 16, 19,
6653
+ 6, 13, 18, 21,
6654
+ 7, 14, 21, 25,
6655
+ 8, 16, 20, 25,
6656
+ 8, 17, 23, 25,
6657
+ 9, 17, 23, 34,
6658
+ 9, 18, 25, 30,
6659
+ 10, 20, 27, 32,
6660
+ 12, 21, 29, 35,
6661
+ 12, 23, 34, 37,
6662
+ 12, 25, 34, 40,
6663
+ 13, 26, 35, 42,
6664
+ 14, 28, 38, 45,
6665
+ 15, 29, 40, 48,
6666
+ 16, 31, 43, 51,
6667
+ 17, 33, 45, 54,
6668
+ 18, 35, 48, 57,
6669
+ 19, 37, 51, 60,
6670
+ 19, 38, 53, 63,
6671
+ 20, 40, 56, 66,
6672
+ 21, 43, 59, 70,
6673
+ 22, 45, 62, 74,
6674
+ 24, 47, 65, 77,
6675
+ 25, 49, 68, 81
6676
+ ];
6677
+
6678
+ const EC_CODEWORDS_TABLE = [
6679
+ // L M Q H
6680
+ 7, 10, 13, 17,
6681
+ 10, 16, 22, 28,
6682
+ 15, 26, 36, 44,
6683
+ 20, 36, 52, 64,
6684
+ 26, 48, 72, 88,
6685
+ 36, 64, 96, 112,
6686
+ 40, 72, 108, 130,
6687
+ 48, 88, 132, 156,
6688
+ 60, 110, 160, 192,
6689
+ 72, 130, 192, 224,
6690
+ 80, 150, 224, 264,
6691
+ 96, 176, 260, 308,
6692
+ 104, 198, 288, 352,
6693
+ 120, 216, 320, 384,
6694
+ 132, 240, 360, 432,
6695
+ 144, 280, 408, 480,
6696
+ 168, 308, 448, 532,
6697
+ 180, 338, 504, 588,
6698
+ 196, 364, 546, 650,
6699
+ 224, 416, 600, 700,
6700
+ 224, 442, 644, 750,
6701
+ 252, 476, 690, 816,
6702
+ 270, 504, 750, 900,
6703
+ 300, 560, 810, 960,
6704
+ 312, 588, 870, 1050,
6705
+ 336, 644, 952, 1110,
6706
+ 360, 700, 1020, 1200,
6707
+ 390, 728, 1050, 1260,
6708
+ 420, 784, 1140, 1350,
6709
+ 450, 812, 1200, 1440,
6710
+ 480, 868, 1290, 1530,
6711
+ 510, 924, 1350, 1620,
6712
+ 540, 980, 1440, 1710,
6713
+ 570, 1036, 1530, 1800,
6714
+ 570, 1064, 1590, 1890,
6715
+ 600, 1120, 1680, 1980,
6716
+ 630, 1204, 1770, 2100,
6717
+ 660, 1260, 1860, 2220,
6718
+ 720, 1316, 1950, 2310,
6719
+ 750, 1372, 2040, 2430
6720
+ ];
6721
+
6722
+ /**
6723
+ * Returns the number of error correction block that the QR Code should contain
6724
+ * for the specified version and error correction level.
6725
+ *
6726
+ * @param {Number} version QR Code version
6727
+ * @param {Number} errorCorrectionLevel Error correction level
6728
+ * @return {Number} Number of error correction blocks
6729
+ */
6730
+ var getBlocksCount = function getBlocksCount (version, errorCorrectionLevel$1) {
6731
+ switch (errorCorrectionLevel$1) {
6732
+ case errorCorrectionLevel.L:
6733
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]
6734
+ case errorCorrectionLevel.M:
6735
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]
6736
+ case errorCorrectionLevel.Q:
6737
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]
6738
+ case errorCorrectionLevel.H:
6739
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]
6740
+ default:
6741
+ return undefined
6742
+ }
6743
+ };
6744
+
6745
+ /**
6746
+ * Returns the number of error correction codewords to use for the specified
6747
+ * version and error correction level.
6748
+ *
6749
+ * @param {Number} version QR Code version
6750
+ * @param {Number} errorCorrectionLevel Error correction level
6751
+ * @return {Number} Number of error correction codewords
6752
+ */
6753
+ var getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel$1) {
6754
+ switch (errorCorrectionLevel$1) {
6755
+ case errorCorrectionLevel.L:
6756
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]
6757
+ case errorCorrectionLevel.M:
6758
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]
6759
+ case errorCorrectionLevel.Q:
6760
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]
6761
+ case errorCorrectionLevel.H:
6762
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]
6763
+ default:
6764
+ return undefined
6765
+ }
6766
+ };
6767
+
6768
+ var errorCorrectionCode = {
6769
+ getBlocksCount: getBlocksCount,
6770
+ getTotalCodewordsCount: getTotalCodewordsCount
6771
+ };
6772
+
6773
+ const EXP_TABLE = new Uint8Array(512);
6774
+ const LOG_TABLE = new Uint8Array(256)
6775
+ /**
6776
+ * Precompute the log and anti-log tables for faster computation later
6777
+ *
6778
+ * For each possible value in the galois field 2^8, we will pre-compute
6779
+ * the logarithm and anti-logarithm (exponential) of this value
6780
+ *
6781
+ * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}
6782
+ */
6783
+ ;(function initTables () {
6784
+ let x = 1;
6785
+ for (let i = 0; i < 255; i++) {
6786
+ EXP_TABLE[i] = x;
6787
+ LOG_TABLE[x] = i;
6788
+
6789
+ x <<= 1; // multiply by 2
6790
+
6791
+ // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
6792
+ // This means that when a number is 256 or larger, it should be XORed with 0x11D.
6793
+ if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)
6794
+ x ^= 0x11D;
6795
+ }
6796
+ }
6797
+
6798
+ // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
6799
+ // stay inside the bounds (because we will mainly use this table for the multiplication of
6800
+ // two GF numbers, no more).
6801
+ // @see {@link mul}
6802
+ for (let i = 255; i < 512; i++) {
6803
+ EXP_TABLE[i] = EXP_TABLE[i - 255];
6804
+ }
6805
+ }());
6806
+
6807
+ /**
6808
+ * Returns log value of n inside Galois Field
6809
+ *
6810
+ * @param {Number} n
6811
+ * @return {Number}
6812
+ */
6813
+ var log = function log (n) {
6814
+ if (n < 1) throw new Error('log(' + n + ')')
6815
+ return LOG_TABLE[n]
6816
+ };
6817
+
6818
+ /**
6819
+ * Returns anti-log value of n inside Galois Field
6820
+ *
6821
+ * @param {Number} n
6822
+ * @return {Number}
6823
+ */
6824
+ var exp = function exp (n) {
6825
+ return EXP_TABLE[n]
6826
+ };
6827
+
6828
+ /**
6829
+ * Multiplies two number inside Galois Field
6830
+ *
6831
+ * @param {Number} x
6832
+ * @param {Number} y
6833
+ * @return {Number}
6834
+ */
6835
+ var mul = function mul (x, y) {
6836
+ if (x === 0 || y === 0) return 0
6837
+
6838
+ // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
6839
+ // @see {@link initTables}
6840
+ return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]
6841
+ };
6842
+
6843
+ var galoisField = {
6844
+ log: log,
6845
+ exp: exp,
6846
+ mul: mul
6847
+ };
6848
+
6849
+ var polynomial = createCommonjsModule(function (module, exports) {
6850
+ /**
6851
+ * Multiplies two polynomials inside Galois Field
6852
+ *
6853
+ * @param {Uint8Array} p1 Polynomial
6854
+ * @param {Uint8Array} p2 Polynomial
6855
+ * @return {Uint8Array} Product of p1 and p2
6856
+ */
6857
+ exports.mul = function mul (p1, p2) {
6858
+ const coeff = new Uint8Array(p1.length + p2.length - 1);
6859
+
6860
+ for (let i = 0; i < p1.length; i++) {
6861
+ for (let j = 0; j < p2.length; j++) {
6862
+ coeff[i + j] ^= galoisField.mul(p1[i], p2[j]);
6863
+ }
6864
+ }
6865
+
6866
+ return coeff
6867
+ };
6868
+
6869
+ /**
6870
+ * Calculate the remainder of polynomials division
6871
+ *
6872
+ * @param {Uint8Array} divident Polynomial
6873
+ * @param {Uint8Array} divisor Polynomial
6874
+ * @return {Uint8Array} Remainder
6875
+ */
6876
+ exports.mod = function mod (divident, divisor) {
6877
+ let result = new Uint8Array(divident);
6878
+
6879
+ while ((result.length - divisor.length) >= 0) {
6880
+ const coeff = result[0];
6881
+
6882
+ for (let i = 0; i < divisor.length; i++) {
6883
+ result[i] ^= galoisField.mul(divisor[i], coeff);
6884
+ }
6885
+
6886
+ // remove all zeros from buffer head
6887
+ let offset = 0;
6888
+ while (offset < result.length && result[offset] === 0) offset++;
6889
+ result = result.slice(offset);
6890
+ }
6891
+
6892
+ return result
6893
+ };
6894
+
6895
+ /**
6896
+ * Generate an irreducible generator polynomial of specified degree
6897
+ * (used by Reed-Solomon encoder)
6898
+ *
6899
+ * @param {Number} degree Degree of the generator polynomial
6900
+ * @return {Uint8Array} Buffer containing polynomial coefficients
6901
+ */
6902
+ exports.generateECPolynomial = function generateECPolynomial (degree) {
6903
+ let poly = new Uint8Array([1]);
6904
+ for (let i = 0; i < degree; i++) {
6905
+ poly = exports.mul(poly, new Uint8Array([1, galoisField.exp(i)]));
6906
+ }
6907
+
6908
+ return poly
6909
+ };
6910
+ });
6911
+
6912
+ function ReedSolomonEncoder (degree) {
6913
+ this.genPoly = undefined;
6914
+ this.degree = degree;
6915
+
6916
+ if (this.degree) this.initialize(this.degree);
6917
+ }
6918
+
6919
+ /**
6920
+ * Initialize the encoder.
6921
+ * The input param should correspond to the number of error correction codewords.
6922
+ *
6923
+ * @param {Number} degree
6924
+ */
6925
+ ReedSolomonEncoder.prototype.initialize = function initialize (degree) {
6926
+ // create an irreducible generator polynomial
6927
+ this.degree = degree;
6928
+ this.genPoly = polynomial.generateECPolynomial(this.degree);
6929
+ };
6930
+
6931
+ /**
6932
+ * Encodes a chunk of data
6933
+ *
6934
+ * @param {Uint8Array} data Buffer containing input data
6935
+ * @return {Uint8Array} Buffer containing encoded data
6936
+ */
6937
+ ReedSolomonEncoder.prototype.encode = function encode (data) {
6938
+ if (!this.genPoly) {
6939
+ throw new Error('Encoder not initialized')
6940
+ }
6941
+
6942
+ // Calculate EC for this data block
6943
+ // extends data size to data+genPoly size
6944
+ const paddedData = new Uint8Array(data.length + this.degree);
6945
+ paddedData.set(data);
6946
+
6947
+ // The error correction codewords are the remainder after dividing the data codewords
6948
+ // by a generator polynomial
6949
+ const remainder = polynomial.mod(paddedData, this.genPoly);
6950
+
6951
+ // return EC data blocks (last n byte, where n is the degree of genPoly)
6952
+ // If coefficients number in remainder are less than genPoly degree,
6953
+ // pad with 0s to the left to reach the needed number of coefficients
6954
+ const start = this.degree - remainder.length;
6955
+ if (start > 0) {
6956
+ const buff = new Uint8Array(this.degree);
6957
+ buff.set(remainder, start);
6958
+
6959
+ return buff
6960
+ }
6961
+
6962
+ return remainder
6963
+ };
6964
+
6965
+ var reedSolomonEncoder = ReedSolomonEncoder;
6966
+
6967
+ /**
6968
+ * Check if QR Code version is valid
6969
+ *
6970
+ * @param {Number} version QR Code version
6971
+ * @return {Boolean} true if valid version, false otherwise
6972
+ */
6973
+ var isValid = function isValid (version) {
6974
+ return !isNaN(version) && version >= 1 && version <= 40
6975
+ };
6976
+
6977
+ var versionCheck = {
6978
+ isValid: isValid
6979
+ };
6980
+
6981
+ const numeric = '[0-9]+';
6982
+ const alphanumeric = '[A-Z $%*+\\-./:]+';
6983
+ let kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
6984
+ '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
6985
+ '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
6986
+ '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+';
6987
+ kanji = kanji.replace(/u/g, '\\u');
6988
+
6989
+ const byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+';
6990
+
6991
+ var KANJI = new RegExp(kanji, 'g');
6992
+ var BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g');
6993
+ var BYTE = new RegExp(byte, 'g');
6994
+ var NUMERIC = new RegExp(numeric, 'g');
6995
+ var ALPHANUMERIC = new RegExp(alphanumeric, 'g');
6996
+
6997
+ const TEST_KANJI = new RegExp('^' + kanji + '$');
6998
+ const TEST_NUMERIC = new RegExp('^' + numeric + '$');
6999
+ const TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$');
7000
+
7001
+ var testKanji = function testKanji (str) {
7002
+ return TEST_KANJI.test(str)
7003
+ };
7004
+
7005
+ var testNumeric = function testNumeric (str) {
7006
+ return TEST_NUMERIC.test(str)
7007
+ };
7008
+
7009
+ var testAlphanumeric = function testAlphanumeric (str) {
7010
+ return TEST_ALPHANUMERIC.test(str)
7011
+ };
7012
+
7013
+ var regex = {
7014
+ KANJI: KANJI,
7015
+ BYTE_KANJI: BYTE_KANJI,
7016
+ BYTE: BYTE,
7017
+ NUMERIC: NUMERIC,
7018
+ ALPHANUMERIC: ALPHANUMERIC,
7019
+ testKanji: testKanji,
7020
+ testNumeric: testNumeric,
7021
+ testAlphanumeric: testAlphanumeric
7022
+ };
7023
+
7024
+ var mode = createCommonjsModule(function (module, exports) {
7025
+ /**
7026
+ * Numeric mode encodes data from the decimal digit set (0 - 9)
7027
+ * (byte values 30HEX to 39HEX).
7028
+ * Normally, 3 data characters are represented by 10 bits.
7029
+ *
7030
+ * @type {Object}
7031
+ */
7032
+ exports.NUMERIC = {
7033
+ id: 'Numeric',
7034
+ bit: 1 << 0,
7035
+ ccBits: [10, 12, 14]
7036
+ };
7037
+
7038
+ /**
7039
+ * Alphanumeric mode encodes data from a set of 45 characters,
7040
+ * i.e. 10 numeric digits (0 - 9),
7041
+ * 26 alphabetic characters (A - Z),
7042
+ * and 9 symbols (SP, $, %, *, +, -, ., /, :).
7043
+ * Normally, two input characters are represented by 11 bits.
7044
+ *
7045
+ * @type {Object}
7046
+ */
7047
+ exports.ALPHANUMERIC = {
7048
+ id: 'Alphanumeric',
7049
+ bit: 1 << 1,
7050
+ ccBits: [9, 11, 13]
7051
+ };
7052
+
7053
+ /**
7054
+ * In byte mode, data is encoded at 8 bits per character.
7055
+ *
7056
+ * @type {Object}
7057
+ */
7058
+ exports.BYTE = {
7059
+ id: 'Byte',
7060
+ bit: 1 << 2,
7061
+ ccBits: [8, 16, 16]
7062
+ };
7063
+
7064
+ /**
7065
+ * The Kanji mode efficiently encodes Kanji characters in accordance with
7066
+ * the Shift JIS system based on JIS X 0208.
7067
+ * The Shift JIS values are shifted from the JIS X 0208 values.
7068
+ * JIS X 0208 gives details of the shift coded representation.
7069
+ * Each two-byte character value is compacted to a 13-bit binary codeword.
7070
+ *
7071
+ * @type {Object}
7072
+ */
7073
+ exports.KANJI = {
7074
+ id: 'Kanji',
7075
+ bit: 1 << 3,
7076
+ ccBits: [8, 10, 12]
7077
+ };
7078
+
7079
+ /**
7080
+ * Mixed mode will contain a sequences of data in a combination of any of
7081
+ * the modes described above
7082
+ *
7083
+ * @type {Object}
7084
+ */
7085
+ exports.MIXED = {
7086
+ bit: -1
7087
+ };
7088
+
7089
+ /**
7090
+ * Returns the number of bits needed to store the data length
7091
+ * according to QR Code specifications.
7092
+ *
7093
+ * @param {Mode} mode Data mode
7094
+ * @param {Number} version QR Code version
7095
+ * @return {Number} Number of bits
7096
+ */
7097
+ exports.getCharCountIndicator = function getCharCountIndicator (mode, version) {
7098
+ if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)
7099
+
7100
+ if (!versionCheck.isValid(version)) {
7101
+ throw new Error('Invalid version: ' + version)
7102
+ }
7103
+
7104
+ if (version >= 1 && version < 10) return mode.ccBits[0]
7105
+ else if (version < 27) return mode.ccBits[1]
7106
+ return mode.ccBits[2]
7107
+ };
7108
+
7109
+ /**
7110
+ * Returns the most efficient mode to store the specified data
7111
+ *
7112
+ * @param {String} dataStr Input data string
7113
+ * @return {Mode} Best mode
7114
+ */
7115
+ exports.getBestModeForData = function getBestModeForData (dataStr) {
7116
+ if (regex.testNumeric(dataStr)) return exports.NUMERIC
7117
+ else if (regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC
7118
+ else if (regex.testKanji(dataStr)) return exports.KANJI
7119
+ else return exports.BYTE
7120
+ };
7121
+
7122
+ /**
7123
+ * Return mode name as string
7124
+ *
7125
+ * @param {Mode} mode Mode object
7126
+ * @returns {String} Mode name
7127
+ */
7128
+ exports.toString = function toString (mode) {
7129
+ if (mode && mode.id) return mode.id
7130
+ throw new Error('Invalid mode')
7131
+ };
7132
+
7133
+ /**
7134
+ * Check if input param is a valid mode object
7135
+ *
7136
+ * @param {Mode} mode Mode object
7137
+ * @returns {Boolean} True if valid mode, false otherwise
7138
+ */
7139
+ exports.isValid = function isValid (mode) {
7140
+ return mode && mode.bit && mode.ccBits
7141
+ };
7142
+
7143
+ /**
7144
+ * Get mode object from its name
7145
+ *
7146
+ * @param {String} string Mode name
7147
+ * @returns {Mode} Mode object
7148
+ */
7149
+ function fromString (string) {
7150
+ if (typeof string !== 'string') {
7151
+ throw new Error('Param is not a string')
7152
+ }
7153
+
7154
+ const lcStr = string.toLowerCase();
7155
+
7156
+ switch (lcStr) {
7157
+ case 'numeric':
7158
+ return exports.NUMERIC
7159
+ case 'alphanumeric':
7160
+ return exports.ALPHANUMERIC
7161
+ case 'kanji':
7162
+ return exports.KANJI
7163
+ case 'byte':
7164
+ return exports.BYTE
7165
+ default:
7166
+ throw new Error('Unknown mode: ' + string)
7167
+ }
7168
+ }
7169
+
7170
+ /**
7171
+ * Returns mode from a value.
7172
+ * If value is not a valid mode, returns defaultValue
7173
+ *
7174
+ * @param {Mode|String} value Encoding mode
7175
+ * @param {Mode} defaultValue Fallback value
7176
+ * @return {Mode} Encoding mode
7177
+ */
7178
+ exports.from = function from (value, defaultValue) {
7179
+ if (exports.isValid(value)) {
7180
+ return value
7181
+ }
7182
+
7183
+ try {
7184
+ return fromString(value)
7185
+ } catch (e) {
7186
+ return defaultValue
7187
+ }
7188
+ };
7189
+ });
7190
+
7191
+ var version = createCommonjsModule(function (module, exports) {
7192
+ // Generator polynomial used to encode version information
7193
+ const G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
7194
+ const G18_BCH = utils$1.getBCHDigit(G18);
7195
+
7196
+ function getBestVersionForDataLength (mode, length, errorCorrectionLevel) {
7197
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
7198
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
7199
+ return currentVersion
7200
+ }
7201
+ }
7202
+
7203
+ return undefined
7204
+ }
7205
+
7206
+ function getReservedBitsCount (mode$1, version) {
7207
+ // Character count indicator + mode indicator bits
7208
+ return mode.getCharCountIndicator(mode$1, version) + 4
7209
+ }
7210
+
7211
+ function getTotalBitsFromDataArray (segments, version) {
7212
+ let totalBits = 0;
7213
+
7214
+ segments.forEach(function (data) {
7215
+ const reservedBits = getReservedBitsCount(data.mode, version);
7216
+ totalBits += reservedBits + data.getBitsLength();
7217
+ });
7218
+
7219
+ return totalBits
7220
+ }
7221
+
7222
+ function getBestVersionForMixedData (segments, errorCorrectionLevel) {
7223
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
7224
+ const length = getTotalBitsFromDataArray(segments, currentVersion);
7225
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode.MIXED)) {
7226
+ return currentVersion
7227
+ }
7228
+ }
7229
+
7230
+ return undefined
7231
+ }
7232
+
7233
+ /**
7234
+ * Returns version number from a value.
7235
+ * If value is not a valid version, returns defaultValue
7236
+ *
7237
+ * @param {Number|String} value QR Code version
7238
+ * @param {Number} defaultValue Fallback value
7239
+ * @return {Number} QR Code version number
7240
+ */
7241
+ exports.from = function from (value, defaultValue) {
7242
+ if (versionCheck.isValid(value)) {
7243
+ return parseInt(value, 10)
7244
+ }
7245
+
7246
+ return defaultValue
7247
+ };
7248
+
7249
+ /**
7250
+ * Returns how much data can be stored with the specified QR code version
7251
+ * and error correction level
7252
+ *
7253
+ * @param {Number} version QR Code version (1-40)
7254
+ * @param {Number} errorCorrectionLevel Error correction level
7255
+ * @param {Mode} mode Data mode
7256
+ * @return {Number} Quantity of storable data
7257
+ */
7258
+ exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode$1) {
7259
+ if (!versionCheck.isValid(version)) {
7260
+ throw new Error('Invalid QR Code version')
7261
+ }
7262
+
7263
+ // Use Byte mode as default
7264
+ if (typeof mode$1 === 'undefined') mode$1 = mode.BYTE;
7265
+
7266
+ // Total codewords for this QR code version (Data + Error correction)
7267
+ const totalCodewords = utils$1.getSymbolTotalCodewords(version);
7268
+
7269
+ // Total number of error correction codewords
7270
+ const ecTotalCodewords = errorCorrectionCode.getTotalCodewordsCount(version, errorCorrectionLevel);
7271
+
7272
+ // Total number of data codewords
7273
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
7274
+
7275
+ if (mode$1 === mode.MIXED) return dataTotalCodewordsBits
7276
+
7277
+ const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode$1, version);
7278
+
7279
+ // Return max number of storable codewords
7280
+ switch (mode$1) {
7281
+ case mode.NUMERIC:
7282
+ return Math.floor((usableBits / 10) * 3)
7283
+
7284
+ case mode.ALPHANUMERIC:
7285
+ return Math.floor((usableBits / 11) * 2)
7286
+
7287
+ case mode.KANJI:
7288
+ return Math.floor(usableBits / 13)
7289
+
7290
+ case mode.BYTE:
7291
+ default:
7292
+ return Math.floor(usableBits / 8)
7293
+ }
7294
+ };
7295
+
7296
+ /**
7297
+ * Returns the minimum version needed to contain the amount of data
7298
+ *
7299
+ * @param {Segment} data Segment of data
7300
+ * @param {Number} [errorCorrectionLevel=H] Error correction level
7301
+ * @param {Mode} mode Data mode
7302
+ * @return {Number} QR Code version
7303
+ */
7304
+ exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel$1) {
7305
+ let seg;
7306
+
7307
+ const ecl = errorCorrectionLevel.from(errorCorrectionLevel$1, errorCorrectionLevel.M);
7308
+
7309
+ if (Array.isArray(data)) {
7310
+ if (data.length > 1) {
7311
+ return getBestVersionForMixedData(data, ecl)
7312
+ }
7313
+
7314
+ if (data.length === 0) {
7315
+ return 1
7316
+ }
7317
+
7318
+ seg = data[0];
7319
+ } else {
7320
+ seg = data;
7321
+ }
7322
+
7323
+ return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)
7324
+ };
7325
+
7326
+ /**
7327
+ * Returns version information with relative error correction bits
7328
+ *
7329
+ * The version information is included in QR Code symbols of version 7 or larger.
7330
+ * It consists of an 18-bit sequence containing 6 data bits,
7331
+ * with 12 error correction bits calculated using the (18, 6) Golay code.
7332
+ *
7333
+ * @param {Number} version QR Code version
7334
+ * @return {Number} Encoded version info bits
7335
+ */
7336
+ exports.getEncodedBits = function getEncodedBits (version) {
7337
+ if (!versionCheck.isValid(version) || version < 7) {
7338
+ throw new Error('Invalid QR Code version')
7339
+ }
7340
+
7341
+ let d = version << 12;
7342
+
7343
+ while (utils$1.getBCHDigit(d) - G18_BCH >= 0) {
7344
+ d ^= (G18 << (utils$1.getBCHDigit(d) - G18_BCH));
7345
+ }
7346
+
7347
+ return (version << 12) | d
7348
+ };
7349
+ });
7350
+
7351
+ const G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
7352
+ const G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
7353
+ const G15_BCH = utils$1.getBCHDigit(G15);
7354
+
7355
+ /**
7356
+ * Returns format information with relative error correction bits
7357
+ *
7358
+ * The format information is a 15-bit sequence containing 5 data bits,
7359
+ * with 10 error correction bits calculated using the (15, 5) BCH code.
7360
+ *
7361
+ * @param {Number} errorCorrectionLevel Error correction level
7362
+ * @param {Number} mask Mask pattern
7363
+ * @return {Number} Encoded format information bits
7364
+ */
7365
+ var getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
7366
+ const data = ((errorCorrectionLevel.bit << 3) | mask);
7367
+ let d = data << 10;
7368
+
7369
+ while (utils$1.getBCHDigit(d) - G15_BCH >= 0) {
7370
+ d ^= (G15 << (utils$1.getBCHDigit(d) - G15_BCH));
7371
+ }
7372
+
7373
+ // xor final data with mask pattern in order to ensure that
7374
+ // no combination of Error Correction Level and data mask pattern
7375
+ // will result in an all-zero data string
7376
+ return ((data << 10) | d) ^ G15_MASK
7377
+ };
7378
+
7379
+ var formatInfo = {
7380
+ getEncodedBits: getEncodedBits
7381
+ };
7382
+
7383
+ function NumericData (data) {
7384
+ this.mode = mode.NUMERIC;
7385
+ this.data = data.toString();
7386
+ }
7387
+
7388
+ NumericData.getBitsLength = function getBitsLength (length) {
7389
+ return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
7390
+ };
7391
+
7392
+ NumericData.prototype.getLength = function getLength () {
7393
+ return this.data.length
7394
+ };
7395
+
7396
+ NumericData.prototype.getBitsLength = function getBitsLength () {
7397
+ return NumericData.getBitsLength(this.data.length)
7398
+ };
7399
+
7400
+ NumericData.prototype.write = function write (bitBuffer) {
7401
+ let i, group, value;
7402
+
7403
+ // The input data string is divided into groups of three digits,
7404
+ // and each group is converted to its 10-bit binary equivalent.
7405
+ for (i = 0; i + 3 <= this.data.length; i += 3) {
7406
+ group = this.data.substr(i, 3);
7407
+ value = parseInt(group, 10);
7408
+
7409
+ bitBuffer.put(value, 10);
7410
+ }
7411
+
7412
+ // If the number of input digits is not an exact multiple of three,
7413
+ // the final one or two digits are converted to 4 or 7 bits respectively.
7414
+ const remainingNum = this.data.length - i;
7415
+ if (remainingNum > 0) {
7416
+ group = this.data.substr(i);
7417
+ value = parseInt(group, 10);
7418
+
7419
+ bitBuffer.put(value, remainingNum * 3 + 1);
7420
+ }
7421
+ };
7422
+
7423
+ var numericData = NumericData;
7424
+
7425
+ /**
7426
+ * Array of characters available in alphanumeric mode
7427
+ *
7428
+ * As per QR Code specification, to each character
7429
+ * is assigned a value from 0 to 44 which in this case coincides
7430
+ * with the array index
7431
+ *
7432
+ * @type {Array}
7433
+ */
7434
+ const ALPHA_NUM_CHARS = [
7435
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
7436
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
7437
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
7438
+ ' ', '$', '%', '*', '+', '-', '.', '/', ':'
7439
+ ];
7440
+
7441
+ function AlphanumericData (data) {
7442
+ this.mode = mode.ALPHANUMERIC;
7443
+ this.data = data;
7444
+ }
7445
+
7446
+ AlphanumericData.getBitsLength = function getBitsLength (length) {
7447
+ return 11 * Math.floor(length / 2) + 6 * (length % 2)
7448
+ };
7449
+
7450
+ AlphanumericData.prototype.getLength = function getLength () {
7451
+ return this.data.length
7452
+ };
7453
+
7454
+ AlphanumericData.prototype.getBitsLength = function getBitsLength () {
7455
+ return AlphanumericData.getBitsLength(this.data.length)
7456
+ };
7457
+
7458
+ AlphanumericData.prototype.write = function write (bitBuffer) {
7459
+ let i;
7460
+
7461
+ // Input data characters are divided into groups of two characters
7462
+ // and encoded as 11-bit binary codes.
7463
+ for (i = 0; i + 2 <= this.data.length; i += 2) {
7464
+ // The character value of the first character is multiplied by 45
7465
+ let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
7466
+
7467
+ // The character value of the second digit is added to the product
7468
+ value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
7469
+
7470
+ // The sum is then stored as 11-bit binary number
7471
+ bitBuffer.put(value, 11);
7472
+ }
7473
+
7474
+ // If the number of input data characters is not a multiple of two,
7475
+ // the character value of the final character is encoded as a 6-bit binary number.
7476
+ if (this.data.length % 2) {
7477
+ bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
7478
+ }
7479
+ };
7480
+
7481
+ var alphanumericData = AlphanumericData;
7482
+
7483
+ var encodeUtf8 = function encodeUtf8 (input) {
7484
+ var result = [];
7485
+ var size = input.length;
7486
+
7487
+ for (var index = 0; index < size; index++) {
7488
+ var point = input.charCodeAt(index);
7489
+
7490
+ if (point >= 0xD800 && point <= 0xDBFF && size > index + 1) {
7491
+ var second = input.charCodeAt(index + 1);
7492
+
7493
+ if (second >= 0xDC00 && second <= 0xDFFF) {
7494
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
7495
+ point = (point - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
7496
+ index += 1;
7497
+ }
7498
+ }
7499
+
7500
+ // US-ASCII
7501
+ if (point < 0x80) {
7502
+ result.push(point);
7503
+ continue
7504
+ }
7505
+
7506
+ // 2-byte UTF-8
7507
+ if (point < 0x800) {
7508
+ result.push((point >> 6) | 192);
7509
+ result.push((point & 63) | 128);
7510
+ continue
7511
+ }
7512
+
7513
+ // 3-byte UTF-8
7514
+ if (point < 0xD800 || (point >= 0xE000 && point < 0x10000)) {
7515
+ result.push((point >> 12) | 224);
7516
+ result.push(((point >> 6) & 63) | 128);
7517
+ result.push((point & 63) | 128);
7518
+ continue
7519
+ }
7520
+
7521
+ // 4-byte UTF-8
7522
+ if (point >= 0x10000 && point <= 0x10FFFF) {
7523
+ result.push((point >> 18) | 240);
7524
+ result.push(((point >> 12) & 63) | 128);
7525
+ result.push(((point >> 6) & 63) | 128);
7526
+ result.push((point & 63) | 128);
7527
+ continue
7528
+ }
7529
+
7530
+ // Invalid character
7531
+ result.push(0xEF, 0xBF, 0xBD);
7532
+ }
7533
+
7534
+ return new Uint8Array(result).buffer
7535
+ };
7536
+
7537
+ function ByteData (data) {
7538
+ this.mode = mode.BYTE;
7539
+ if (typeof (data) === 'string') {
7540
+ data = encodeUtf8(data);
7541
+ }
7542
+ this.data = new Uint8Array(data);
7543
+ }
7544
+
7545
+ ByteData.getBitsLength = function getBitsLength (length) {
7546
+ return length * 8
7547
+ };
7548
+
7549
+ ByteData.prototype.getLength = function getLength () {
7550
+ return this.data.length
7551
+ };
7552
+
7553
+ ByteData.prototype.getBitsLength = function getBitsLength () {
7554
+ return ByteData.getBitsLength(this.data.length)
7555
+ };
7556
+
7557
+ ByteData.prototype.write = function (bitBuffer) {
7558
+ for (let i = 0, l = this.data.length; i < l; i++) {
7559
+ bitBuffer.put(this.data[i], 8);
7560
+ }
7561
+ };
7562
+
7563
+ var byteData = ByteData;
7564
+
7565
+ function KanjiData (data) {
7566
+ this.mode = mode.KANJI;
7567
+ this.data = data;
7568
+ }
7569
+
7570
+ KanjiData.getBitsLength = function getBitsLength (length) {
7571
+ return length * 13
7572
+ };
7573
+
7574
+ KanjiData.prototype.getLength = function getLength () {
7575
+ return this.data.length
7576
+ };
7577
+
7578
+ KanjiData.prototype.getBitsLength = function getBitsLength () {
7579
+ return KanjiData.getBitsLength(this.data.length)
7580
+ };
7581
+
7582
+ KanjiData.prototype.write = function (bitBuffer) {
7583
+ let i;
7584
+
7585
+ // In the Shift JIS system, Kanji characters are represented by a two byte combination.
7586
+ // These byte values are shifted from the JIS X 0208 values.
7587
+ // JIS X 0208 gives details of the shift coded representation.
7588
+ for (i = 0; i < this.data.length; i++) {
7589
+ let value = utils$1.toSJIS(this.data[i]);
7590
+
7591
+ // For characters with Shift JIS values from 0x8140 to 0x9FFC:
7592
+ if (value >= 0x8140 && value <= 0x9FFC) {
7593
+ // Subtract 0x8140 from Shift JIS value
7594
+ value -= 0x8140;
7595
+
7596
+ // For characters with Shift JIS values from 0xE040 to 0xEBBF
7597
+ } else if (value >= 0xE040 && value <= 0xEBBF) {
7598
+ // Subtract 0xC140 from Shift JIS value
7599
+ value -= 0xC140;
7600
+ } else {
7601
+ throw new Error(
7602
+ 'Invalid SJIS character: ' + this.data[i] + '\n' +
7603
+ 'Make sure your charset is UTF-8')
7604
+ }
7605
+
7606
+ // Multiply most significant byte of result by 0xC0
7607
+ // and add least significant byte to product
7608
+ value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff);
7609
+
7610
+ // Convert result to a 13-bit binary string
7611
+ bitBuffer.put(value, 13);
7612
+ }
7613
+ };
7614
+
7615
+ var kanjiData = KanjiData;
7616
+
7617
+ var dijkstra_1 = createCommonjsModule(function (module) {
7618
+
7619
+ /******************************************************************************
7620
+ * Created 2008-08-19.
7621
+ *
7622
+ * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
7623
+ *
7624
+ * Copyright (C) 2008
7625
+ * Wyatt Baldwin <self@wyattbaldwin.com>
7626
+ * All rights reserved
7627
+ *
7628
+ * Licensed under the MIT license.
7629
+ *
7630
+ * http://www.opensource.org/licenses/mit-license.php
7631
+ *
7632
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
7633
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7634
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7635
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
7636
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
7637
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
7638
+ * THE SOFTWARE.
7639
+ *****************************************************************************/
7640
+ var dijkstra = {
7641
+ single_source_shortest_paths: function(graph, s, d) {
7642
+ // Predecessor map for each node that has been encountered.
7643
+ // node ID => predecessor node ID
7644
+ var predecessors = {};
7645
+
7646
+ // Costs of shortest paths from s to all nodes encountered.
7647
+ // node ID => cost
7648
+ var costs = {};
7649
+ costs[s] = 0;
7650
+
7651
+ // Costs of shortest paths from s to all nodes encountered; differs from
7652
+ // `costs` in that it provides easy access to the node that currently has
7653
+ // the known shortest path from s.
7654
+ // XXX: Do we actually need both `costs` and `open`?
7655
+ var open = dijkstra.PriorityQueue.make();
7656
+ open.push(s, 0);
7657
+
7658
+ var closest,
7659
+ u, v,
7660
+ cost_of_s_to_u,
7661
+ adjacent_nodes,
7662
+ cost_of_e,
7663
+ cost_of_s_to_u_plus_cost_of_e,
7664
+ cost_of_s_to_v,
7665
+ first_visit;
7666
+ while (!open.empty()) {
7667
+ // In the nodes remaining in graph that have a known cost from s,
7668
+ // find the node, u, that currently has the shortest path from s.
7669
+ closest = open.pop();
7670
+ u = closest.value;
7671
+ cost_of_s_to_u = closest.cost;
7672
+
7673
+ // Get nodes adjacent to u...
7674
+ adjacent_nodes = graph[u] || {};
7675
+
7676
+ // ...and explore the edges that connect u to those nodes, updating
7677
+ // the cost of the shortest paths to any or all of those nodes as
7678
+ // necessary. v is the node across the current edge from u.
7679
+ for (v in adjacent_nodes) {
7680
+ if (adjacent_nodes.hasOwnProperty(v)) {
7681
+ // Get the cost of the edge running from u to v.
7682
+ cost_of_e = adjacent_nodes[v];
7683
+
7684
+ // Cost of s to u plus the cost of u to v across e--this is *a*
7685
+ // cost from s to v that may or may not be less than the current
7686
+ // known cost to v.
7687
+ cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
7688
+
7689
+ // If we haven't visited v yet OR if the current known cost from s to
7690
+ // v is greater than the new cost we just found (cost of s to u plus
7691
+ // cost of u to v across e), update v's cost in the cost list and
7692
+ // update v's predecessor in the predecessor list (it's now u).
7693
+ cost_of_s_to_v = costs[v];
7694
+ first_visit = (typeof costs[v] === 'undefined');
7695
+ if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
7696
+ costs[v] = cost_of_s_to_u_plus_cost_of_e;
7697
+ open.push(v, cost_of_s_to_u_plus_cost_of_e);
7698
+ predecessors[v] = u;
7699
+ }
7700
+ }
7701
+ }
7702
+ }
7703
+
7704
+ if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
7705
+ var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
7706
+ throw new Error(msg);
7707
+ }
7708
+
7709
+ return predecessors;
7710
+ },
7711
+
7712
+ extract_shortest_path_from_predecessor_list: function(predecessors, d) {
7713
+ var nodes = [];
7714
+ var u = d;
7715
+ while (u) {
7716
+ nodes.push(u);
7717
+ u = predecessors[u];
7718
+ }
7719
+ nodes.reverse();
7720
+ return nodes;
7721
+ },
7722
+
7723
+ find_path: function(graph, s, d) {
7724
+ var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
7725
+ return dijkstra.extract_shortest_path_from_predecessor_list(
7726
+ predecessors, d);
7727
+ },
7728
+
7729
+ /**
7730
+ * A very naive priority queue implementation.
7731
+ */
7732
+ PriorityQueue: {
7733
+ make: function (opts) {
7734
+ var T = dijkstra.PriorityQueue,
7735
+ t = {},
7736
+ key;
7737
+ opts = opts || {};
7738
+ for (key in T) {
7739
+ if (T.hasOwnProperty(key)) {
7740
+ t[key] = T[key];
7741
+ }
7742
+ }
7743
+ t.queue = [];
7744
+ t.sorter = opts.sorter || T.default_sorter;
7745
+ return t;
7746
+ },
7747
+
7748
+ default_sorter: function (a, b) {
7749
+ return a.cost - b.cost;
7750
+ },
7751
+
7752
+ /**
7753
+ * Add a new item to the queue and ensure the highest priority element
7754
+ * is at the front of the queue.
7755
+ */
7756
+ push: function (value, cost) {
7757
+ var item = {value: value, cost: cost};
7758
+ this.queue.push(item);
7759
+ this.queue.sort(this.sorter);
7760
+ },
7761
+
7762
+ /**
7763
+ * Return the highest priority element in the queue.
7764
+ */
7765
+ pop: function () {
7766
+ return this.queue.shift();
7767
+ },
7768
+
7769
+ empty: function () {
7770
+ return this.queue.length === 0;
7771
+ }
7772
+ }
7773
+ };
7774
+
7775
+
7776
+ // node.js module exports
7777
+ {
7778
+ module.exports = dijkstra;
7779
+ }
7780
+ });
7781
+
7782
+ var segments = createCommonjsModule(function (module, exports) {
7783
+ /**
7784
+ * Returns UTF8 byte length
7785
+ *
7786
+ * @param {String} str Input string
7787
+ * @return {Number} Number of byte
7788
+ */
7789
+ function getStringByteLength (str) {
7790
+ return unescape(encodeURIComponent(str)).length
7791
+ }
7792
+
7793
+ /**
7794
+ * Get a list of segments of the specified mode
7795
+ * from a string
7796
+ *
7797
+ * @param {Mode} mode Segment mode
7798
+ * @param {String} str String to process
7799
+ * @return {Array} Array of object with segments data
7800
+ */
7801
+ function getSegments (regex, mode, str) {
7802
+ const segments = [];
7803
+ let result;
7804
+
7805
+ while ((result = regex.exec(str)) !== null) {
7806
+ segments.push({
7807
+ data: result[0],
7808
+ index: result.index,
7809
+ mode: mode,
7810
+ length: result[0].length
7811
+ });
7812
+ }
7813
+
7814
+ return segments
7815
+ }
7816
+
7817
+ /**
7818
+ * Extracts a series of segments with the appropriate
7819
+ * modes from a string
7820
+ *
7821
+ * @param {String} dataStr Input string
7822
+ * @return {Array} Array of object with segments data
7823
+ */
7824
+ function getSegmentsFromString (dataStr) {
7825
+ const numSegs = getSegments(regex.NUMERIC, mode.NUMERIC, dataStr);
7826
+ const alphaNumSegs = getSegments(regex.ALPHANUMERIC, mode.ALPHANUMERIC, dataStr);
7827
+ let byteSegs;
7828
+ let kanjiSegs;
7829
+
7830
+ if (utils$1.isKanjiModeEnabled()) {
7831
+ byteSegs = getSegments(regex.BYTE, mode.BYTE, dataStr);
7832
+ kanjiSegs = getSegments(regex.KANJI, mode.KANJI, dataStr);
7833
+ } else {
7834
+ byteSegs = getSegments(regex.BYTE_KANJI, mode.BYTE, dataStr);
7835
+ kanjiSegs = [];
7836
+ }
7837
+
7838
+ const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
7839
+
7840
+ return segs
7841
+ .sort(function (s1, s2) {
7842
+ return s1.index - s2.index
7843
+ })
7844
+ .map(function (obj) {
7845
+ return {
7846
+ data: obj.data,
7847
+ mode: obj.mode,
7848
+ length: obj.length
7849
+ }
7850
+ })
7851
+ }
7852
+
7853
+ /**
7854
+ * Returns how many bits are needed to encode a string of
7855
+ * specified length with the specified mode
7856
+ *
7857
+ * @param {Number} length String length
7858
+ * @param {Mode} mode Segment mode
7859
+ * @return {Number} Bit length
7860
+ */
7861
+ function getSegmentBitsLength (length, mode$1) {
7862
+ switch (mode$1) {
7863
+ case mode.NUMERIC:
7864
+ return numericData.getBitsLength(length)
7865
+ case mode.ALPHANUMERIC:
7866
+ return alphanumericData.getBitsLength(length)
7867
+ case mode.KANJI:
7868
+ return kanjiData.getBitsLength(length)
7869
+ case mode.BYTE:
7870
+ return byteData.getBitsLength(length)
7871
+ }
7872
+ }
7873
+
7874
+ /**
7875
+ * Merges adjacent segments which have the same mode
7876
+ *
7877
+ * @param {Array} segs Array of object with segments data
7878
+ * @return {Array} Array of object with segments data
7879
+ */
7880
+ function mergeSegments (segs) {
7881
+ return segs.reduce(function (acc, curr) {
7882
+ const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
7883
+ if (prevSeg && prevSeg.mode === curr.mode) {
7884
+ acc[acc.length - 1].data += curr.data;
7885
+ return acc
7886
+ }
7887
+
7888
+ acc.push(curr);
7889
+ return acc
7890
+ }, [])
7891
+ }
7892
+
7893
+ /**
7894
+ * Generates a list of all possible nodes combination which
7895
+ * will be used to build a segments graph.
7896
+ *
7897
+ * Nodes are divided by groups. Each group will contain a list of all the modes
7898
+ * in which is possible to encode the given text.
7899
+ *
7900
+ * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
7901
+ * The group for '12345' will contain then 3 objects, one for each
7902
+ * possible encoding mode.
7903
+ *
7904
+ * Each node represents a possible segment.
7905
+ *
7906
+ * @param {Array} segs Array of object with segments data
7907
+ * @return {Array} Array of object with segments data
7908
+ */
7909
+ function buildNodes (segs) {
7910
+ const nodes = [];
7911
+ for (let i = 0; i < segs.length; i++) {
7912
+ const seg = segs[i];
7913
+
7914
+ switch (seg.mode) {
7915
+ case mode.NUMERIC:
7916
+ nodes.push([seg,
7917
+ { data: seg.data, mode: mode.ALPHANUMERIC, length: seg.length },
7918
+ { data: seg.data, mode: mode.BYTE, length: seg.length }
7919
+ ]);
7920
+ break
7921
+ case mode.ALPHANUMERIC:
7922
+ nodes.push([seg,
7923
+ { data: seg.data, mode: mode.BYTE, length: seg.length }
7924
+ ]);
7925
+ break
7926
+ case mode.KANJI:
7927
+ nodes.push([seg,
7928
+ { data: seg.data, mode: mode.BYTE, length: getStringByteLength(seg.data) }
7929
+ ]);
7930
+ break
7931
+ case mode.BYTE:
7932
+ nodes.push([
7933
+ { data: seg.data, mode: mode.BYTE, length: getStringByteLength(seg.data) }
7934
+ ]);
7935
+ }
7936
+ }
7937
+
7938
+ return nodes
7939
+ }
7940
+
7941
+ /**
7942
+ * Builds a graph from a list of nodes.
7943
+ * All segments in each node group will be connected with all the segments of
7944
+ * the next group and so on.
7945
+ *
7946
+ * At each connection will be assigned a weight depending on the
7947
+ * segment's byte length.
7948
+ *
7949
+ * @param {Array} nodes Array of object with segments data
7950
+ * @param {Number} version QR Code version
7951
+ * @return {Object} Graph of all possible segments
7952
+ */
7953
+ function buildGraph (nodes, version) {
7954
+ const table = {};
7955
+ const graph = { start: {} };
7956
+ let prevNodeIds = ['start'];
7957
+
7958
+ for (let i = 0; i < nodes.length; i++) {
7959
+ const nodeGroup = nodes[i];
7960
+ const currentNodeIds = [];
7961
+
7962
+ for (let j = 0; j < nodeGroup.length; j++) {
7963
+ const node = nodeGroup[j];
7964
+ const key = '' + i + j;
7965
+
7966
+ currentNodeIds.push(key);
7967
+ table[key] = { node: node, lastCount: 0 };
7968
+ graph[key] = {};
7969
+
7970
+ for (let n = 0; n < prevNodeIds.length; n++) {
7971
+ const prevNodeId = prevNodeIds[n];
7972
+
7973
+ if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
7974
+ graph[prevNodeId][key] =
7975
+ getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -
7976
+ getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
7977
+
7978
+ table[prevNodeId].lastCount += node.length;
7979
+ } else {
7980
+ if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
7981
+
7982
+ graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +
7983
+ 4 + mode.getCharCountIndicator(node.mode, version); // switch cost
7984
+ }
7985
+ }
7986
+ }
7987
+
7988
+ prevNodeIds = currentNodeIds;
7989
+ }
7990
+
7991
+ for (let n = 0; n < prevNodeIds.length; n++) {
7992
+ graph[prevNodeIds[n]].end = 0;
7993
+ }
7994
+
7995
+ return { map: graph, table: table }
7996
+ }
7997
+
7998
+ /**
7999
+ * Builds a segment from a specified data and mode.
8000
+ * If a mode is not specified, the more suitable will be used.
8001
+ *
8002
+ * @param {String} data Input data
8003
+ * @param {Mode | String} modesHint Data mode
8004
+ * @return {Segment} Segment
8005
+ */
8006
+ function buildSingleSegment (data, modesHint) {
8007
+ let mode$1;
8008
+ const bestMode = mode.getBestModeForData(data);
8009
+
8010
+ mode$1 = mode.from(modesHint, bestMode);
8011
+
8012
+ // Make sure data can be encoded
8013
+ if (mode$1 !== mode.BYTE && mode$1.bit < bestMode.bit) {
8014
+ throw new Error('"' + data + '"' +
8015
+ ' cannot be encoded with mode ' + mode.toString(mode$1) +
8016
+ '.\n Suggested mode is: ' + mode.toString(bestMode))
8017
+ }
8018
+
8019
+ // Use Mode.BYTE if Kanji support is disabled
8020
+ if (mode$1 === mode.KANJI && !utils$1.isKanjiModeEnabled()) {
8021
+ mode$1 = mode.BYTE;
8022
+ }
8023
+
8024
+ switch (mode$1) {
8025
+ case mode.NUMERIC:
8026
+ return new numericData(data)
8027
+
8028
+ case mode.ALPHANUMERIC:
8029
+ return new alphanumericData(data)
8030
+
8031
+ case mode.KANJI:
8032
+ return new kanjiData(data)
8033
+
8034
+ case mode.BYTE:
8035
+ return new byteData(data)
8036
+ }
8037
+ }
8038
+
8039
+ /**
8040
+ * Builds a list of segments from an array.
8041
+ * Array can contain Strings or Objects with segment's info.
8042
+ *
8043
+ * For each item which is a string, will be generated a segment with the given
8044
+ * string and the more appropriate encoding mode.
8045
+ *
8046
+ * For each item which is an object, will be generated a segment with the given
8047
+ * data and mode.
8048
+ * Objects must contain at least the property "data".
8049
+ * If property "mode" is not present, the more suitable mode will be used.
8050
+ *
8051
+ * @param {Array} array Array of objects with segments data
8052
+ * @return {Array} Array of Segments
8053
+ */
8054
+ exports.fromArray = function fromArray (array) {
8055
+ return array.reduce(function (acc, seg) {
8056
+ if (typeof seg === 'string') {
8057
+ acc.push(buildSingleSegment(seg, null));
8058
+ } else if (seg.data) {
8059
+ acc.push(buildSingleSegment(seg.data, seg.mode));
8060
+ }
8061
+
8062
+ return acc
8063
+ }, [])
8064
+ };
8065
+
8066
+ /**
8067
+ * Builds an optimized sequence of segments from a string,
8068
+ * which will produce the shortest possible bitstream.
8069
+ *
8070
+ * @param {String} data Input string
8071
+ * @param {Number} version QR Code version
8072
+ * @return {Array} Array of segments
8073
+ */
8074
+ exports.fromString = function fromString (data, version) {
8075
+ const segs = getSegmentsFromString(data, utils$1.isKanjiModeEnabled());
8076
+
8077
+ const nodes = buildNodes(segs);
8078
+ const graph = buildGraph(nodes, version);
8079
+ const path = dijkstra_1.find_path(graph.map, 'start', 'end');
8080
+
8081
+ const optimizedSegs = [];
8082
+ for (let i = 1; i < path.length - 1; i++) {
8083
+ optimizedSegs.push(graph.table[path[i]].node);
8084
+ }
8085
+
8086
+ return exports.fromArray(mergeSegments(optimizedSegs))
8087
+ };
8088
+
8089
+ /**
8090
+ * Splits a string in various segments with the modes which
8091
+ * best represent their content.
8092
+ * The produced segments are far from being optimized.
8093
+ * The output of this function is only used to estimate a QR Code version
8094
+ * which may contain the data.
8095
+ *
8096
+ * @param {string} data Input string
8097
+ * @return {Array} Array of segments
8098
+ */
8099
+ exports.rawSplit = function rawSplit (data) {
8100
+ return exports.fromArray(
8101
+ getSegmentsFromString(data, utils$1.isKanjiModeEnabled())
8102
+ )
8103
+ };
8104
+ });
8105
+
8106
+ /**
8107
+ * QRCode for JavaScript
8108
+ *
8109
+ * modified by Ryan Day for nodejs support
8110
+ * Copyright (c) 2011 Ryan Day
8111
+ *
8112
+ * Licensed under the MIT license:
8113
+ * http://www.opensource.org/licenses/mit-license.php
8114
+ *
8115
+ //---------------------------------------------------------------------
8116
+ // QRCode for JavaScript
8117
+ //
8118
+ // Copyright (c) 2009 Kazuhiko Arase
8119
+ //
8120
+ // URL: http://www.d-project.com/
8121
+ //
8122
+ // Licensed under the MIT license:
8123
+ // http://www.opensource.org/licenses/mit-license.php
8124
+ //
8125
+ // The word "QR Code" is registered trademark of
8126
+ // DENSO WAVE INCORPORATED
8127
+ // http://www.denso-wave.com/qrcode/faqpatent-e.html
8128
+ //
8129
+ //---------------------------------------------------------------------
8130
+ */
8131
+
8132
+ /**
8133
+ * Add finder patterns bits to matrix
8134
+ *
8135
+ * @param {BitMatrix} matrix Modules matrix
8136
+ * @param {Number} version QR Code version
8137
+ */
8138
+ function setupFinderPattern (matrix, version) {
8139
+ const size = matrix.size;
8140
+ const pos = finderPattern.getPositions(version);
8141
+
8142
+ for (let i = 0; i < pos.length; i++) {
8143
+ const row = pos[i][0];
8144
+ const col = pos[i][1];
8145
+
8146
+ for (let r = -1; r <= 7; r++) {
8147
+ if (row + r <= -1 || size <= row + r) continue
8148
+
8149
+ for (let c = -1; c <= 7; c++) {
8150
+ if (col + c <= -1 || size <= col + c) continue
8151
+
8152
+ if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||
8153
+ (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||
8154
+ (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {
8155
+ matrix.set(row + r, col + c, true, true);
8156
+ } else {
8157
+ matrix.set(row + r, col + c, false, true);
8158
+ }
8159
+ }
8160
+ }
8161
+ }
8162
+ }
8163
+
8164
+ /**
8165
+ * Add timing pattern bits to matrix
8166
+ *
8167
+ * Note: this function must be called before {@link setupAlignmentPattern}
8168
+ *
8169
+ * @param {BitMatrix} matrix Modules matrix
8170
+ */
8171
+ function setupTimingPattern (matrix) {
8172
+ const size = matrix.size;
8173
+
8174
+ for (let r = 8; r < size - 8; r++) {
8175
+ const value = r % 2 === 0;
8176
+ matrix.set(r, 6, value, true);
8177
+ matrix.set(6, r, value, true);
8178
+ }
8179
+ }
8180
+
8181
+ /**
8182
+ * Add alignment patterns bits to matrix
8183
+ *
8184
+ * Note: this function must be called after {@link setupTimingPattern}
8185
+ *
8186
+ * @param {BitMatrix} matrix Modules matrix
8187
+ * @param {Number} version QR Code version
8188
+ */
8189
+ function setupAlignmentPattern (matrix, version) {
8190
+ const pos = alignmentPattern.getPositions(version);
8191
+
8192
+ for (let i = 0; i < pos.length; i++) {
8193
+ const row = pos[i][0];
8194
+ const col = pos[i][1];
8195
+
8196
+ for (let r = -2; r <= 2; r++) {
8197
+ for (let c = -2; c <= 2; c++) {
8198
+ if (r === -2 || r === 2 || c === -2 || c === 2 ||
8199
+ (r === 0 && c === 0)) {
8200
+ matrix.set(row + r, col + c, true, true);
8201
+ } else {
8202
+ matrix.set(row + r, col + c, false, true);
8203
+ }
8204
+ }
8205
+ }
8206
+ }
8207
+ }
8208
+
8209
+ /**
8210
+ * Add version info bits to matrix
8211
+ *
8212
+ * @param {BitMatrix} matrix Modules matrix
8213
+ * @param {Number} version QR Code version
8214
+ */
8215
+ function setupVersionInfo (matrix, version$1) {
8216
+ const size = matrix.size;
8217
+ const bits = version.getEncodedBits(version$1);
8218
+ let row, col, mod;
8219
+
8220
+ for (let i = 0; i < 18; i++) {
8221
+ row = Math.floor(i / 3);
8222
+ col = i % 3 + size - 8 - 3;
8223
+ mod = ((bits >> i) & 1) === 1;
8224
+
8225
+ matrix.set(row, col, mod, true);
8226
+ matrix.set(col, row, mod, true);
8227
+ }
8228
+ }
8229
+
8230
+ /**
8231
+ * Add format info bits to matrix
8232
+ *
8233
+ * @param {BitMatrix} matrix Modules matrix
8234
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
8235
+ * @param {Number} maskPattern Mask pattern reference value
8236
+ */
8237
+ function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {
8238
+ const size = matrix.size;
8239
+ const bits = formatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
8240
+ let i, mod;
8241
+
8242
+ for (i = 0; i < 15; i++) {
8243
+ mod = ((bits >> i) & 1) === 1;
8244
+
8245
+ // vertical
8246
+ if (i < 6) {
8247
+ matrix.set(i, 8, mod, true);
8248
+ } else if (i < 8) {
8249
+ matrix.set(i + 1, 8, mod, true);
8250
+ } else {
8251
+ matrix.set(size - 15 + i, 8, mod, true);
8252
+ }
8253
+
8254
+ // horizontal
8255
+ if (i < 8) {
8256
+ matrix.set(8, size - i - 1, mod, true);
8257
+ } else if (i < 9) {
8258
+ matrix.set(8, 15 - i - 1 + 1, mod, true);
8259
+ } else {
8260
+ matrix.set(8, 15 - i - 1, mod, true);
8261
+ }
8262
+ }
8263
+
8264
+ // fixed module
8265
+ matrix.set(size - 8, 8, 1, true);
8266
+ }
8267
+
8268
+ /**
8269
+ * Add encoded data bits to matrix
8270
+ *
8271
+ * @param {BitMatrix} matrix Modules matrix
8272
+ * @param {Uint8Array} data Data codewords
8273
+ */
8274
+ function setupData (matrix, data) {
8275
+ const size = matrix.size;
8276
+ let inc = -1;
8277
+ let row = size - 1;
8278
+ let bitIndex = 7;
8279
+ let byteIndex = 0;
8280
+
8281
+ for (let col = size - 1; col > 0; col -= 2) {
8282
+ if (col === 6) col--;
8283
+
8284
+ while (true) {
8285
+ for (let c = 0; c < 2; c++) {
8286
+ if (!matrix.isReserved(row, col - c)) {
8287
+ let dark = false;
8288
+
8289
+ if (byteIndex < data.length) {
8290
+ dark = (((data[byteIndex] >>> bitIndex) & 1) === 1);
8291
+ }
8292
+
8293
+ matrix.set(row, col - c, dark);
8294
+ bitIndex--;
8295
+
8296
+ if (bitIndex === -1) {
8297
+ byteIndex++;
8298
+ bitIndex = 7;
8299
+ }
8300
+ }
8301
+ }
8302
+
8303
+ row += inc;
8304
+
8305
+ if (row < 0 || size <= row) {
8306
+ row -= inc;
8307
+ inc = -inc;
8308
+ break
8309
+ }
8310
+ }
8311
+ }
8312
+ }
8313
+
8314
+ /**
8315
+ * Create encoded codewords from data input
8316
+ *
8317
+ * @param {Number} version QR Code version
8318
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
8319
+ * @param {ByteData} data Data input
8320
+ * @return {Uint8Array} Buffer containing encoded codewords
8321
+ */
8322
+ function createData (version, errorCorrectionLevel, segments) {
8323
+ // Prepare data buffer
8324
+ const buffer = new bitBuffer();
8325
+
8326
+ segments.forEach(function (data) {
8327
+ // prefix data with mode indicator (4 bits)
8328
+ buffer.put(data.mode.bit, 4);
8329
+
8330
+ // Prefix data with character count indicator.
8331
+ // The character count indicator is a string of bits that represents the
8332
+ // number of characters that are being encoded.
8333
+ // The character count indicator must be placed after the mode indicator
8334
+ // and must be a certain number of bits long, depending on the QR version
8335
+ // and data mode
8336
+ // @see {@link Mode.getCharCountIndicator}.
8337
+ buffer.put(data.getLength(), mode.getCharCountIndicator(data.mode, version));
8338
+
8339
+ // add binary data sequence to buffer
8340
+ data.write(buffer);
8341
+ });
8342
+
8343
+ // Calculate required number of bits
8344
+ const totalCodewords = utils$1.getSymbolTotalCodewords(version);
8345
+ const ecTotalCodewords = errorCorrectionCode.getTotalCodewordsCount(version, errorCorrectionLevel);
8346
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
8347
+
8348
+ // Add a terminator.
8349
+ // If the bit string is shorter than the total number of required bits,
8350
+ // a terminator of up to four 0s must be added to the right side of the string.
8351
+ // If the bit string is more than four bits shorter than the required number of bits,
8352
+ // add four 0s to the end.
8353
+ if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
8354
+ buffer.put(0, 4);
8355
+ }
8356
+
8357
+ // If the bit string is fewer than four bits shorter, add only the number of 0s that
8358
+ // are needed to reach the required number of bits.
8359
+
8360
+ // After adding the terminator, if the number of bits in the string is not a multiple of 8,
8361
+ // pad the string on the right with 0s to make the string's length a multiple of 8.
8362
+ while (buffer.getLengthInBits() % 8 !== 0) {
8363
+ buffer.putBit(0);
8364
+ }
8365
+
8366
+ // Add pad bytes if the string is still shorter than the total number of required bits.
8367
+ // Extend the buffer to fill the data capacity of the symbol corresponding to
8368
+ // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
8369
+ // and 00010001 (0x11) alternately.
8370
+ const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
8371
+ for (let i = 0; i < remainingByte; i++) {
8372
+ buffer.put(i % 2 ? 0x11 : 0xEC, 8);
8373
+ }
8374
+
8375
+ return createCodewords(buffer, version, errorCorrectionLevel)
8376
+ }
8377
+
8378
+ /**
8379
+ * Encode input data with Reed-Solomon and return codewords with
8380
+ * relative error correction bits
8381
+ *
8382
+ * @param {BitBuffer} bitBuffer Data to encode
8383
+ * @param {Number} version QR Code version
8384
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
8385
+ * @return {Uint8Array} Buffer containing encoded codewords
8386
+ */
8387
+ function createCodewords (bitBuffer, version, errorCorrectionLevel) {
8388
+ // Total codewords for this QR code version (Data + Error correction)
8389
+ const totalCodewords = utils$1.getSymbolTotalCodewords(version);
8390
+
8391
+ // Total number of error correction codewords
8392
+ const ecTotalCodewords = errorCorrectionCode.getTotalCodewordsCount(version, errorCorrectionLevel);
8393
+
8394
+ // Total number of data codewords
8395
+ const dataTotalCodewords = totalCodewords - ecTotalCodewords;
8396
+
8397
+ // Total number of blocks
8398
+ const ecTotalBlocks = errorCorrectionCode.getBlocksCount(version, errorCorrectionLevel);
8399
+
8400
+ // Calculate how many blocks each group should contain
8401
+ const blocksInGroup2 = totalCodewords % ecTotalBlocks;
8402
+ const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
8403
+
8404
+ const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
8405
+
8406
+ const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
8407
+ const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
8408
+
8409
+ // Number of EC codewords is the same for both groups
8410
+ const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
8411
+
8412
+ // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
8413
+ const rs = new reedSolomonEncoder(ecCount);
8414
+
8415
+ let offset = 0;
8416
+ const dcData = new Array(ecTotalBlocks);
8417
+ const ecData = new Array(ecTotalBlocks);
8418
+ let maxDataSize = 0;
8419
+ const buffer = new Uint8Array(bitBuffer.buffer);
8420
+
8421
+ // Divide the buffer into the required number of blocks
8422
+ for (let b = 0; b < ecTotalBlocks; b++) {
8423
+ const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
8424
+
8425
+ // extract a block of data from buffer
8426
+ dcData[b] = buffer.slice(offset, offset + dataSize);
8427
+
8428
+ // Calculate EC codewords for this data block
8429
+ ecData[b] = rs.encode(dcData[b]);
8430
+
8431
+ offset += dataSize;
8432
+ maxDataSize = Math.max(maxDataSize, dataSize);
8433
+ }
8434
+
8435
+ // Create final data
8436
+ // Interleave the data and error correction codewords from each block
8437
+ const data = new Uint8Array(totalCodewords);
8438
+ let index = 0;
8439
+ let i, r;
8440
+
8441
+ // Add data codewords
8442
+ for (i = 0; i < maxDataSize; i++) {
8443
+ for (r = 0; r < ecTotalBlocks; r++) {
8444
+ if (i < dcData[r].length) {
8445
+ data[index++] = dcData[r][i];
8446
+ }
8447
+ }
8448
+ }
8449
+
8450
+ // Apped EC codewords
8451
+ for (i = 0; i < ecCount; i++) {
8452
+ for (r = 0; r < ecTotalBlocks; r++) {
8453
+ data[index++] = ecData[r][i];
8454
+ }
8455
+ }
8456
+
8457
+ return data
8458
+ }
8459
+
8460
+ /**
8461
+ * Build QR Code symbol
8462
+ *
8463
+ * @param {String} data Input string
8464
+ * @param {Number} version QR Code version
8465
+ * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
8466
+ * @param {MaskPattern} maskPattern Mask pattern
8467
+ * @return {Object} Object containing symbol data
8468
+ */
8469
+ function createSymbol (data, version$1, errorCorrectionLevel, maskPattern$1) {
8470
+ let segments$1;
8471
+
8472
+ if (Array.isArray(data)) {
8473
+ segments$1 = segments.fromArray(data);
8474
+ } else if (typeof data === 'string') {
8475
+ let estimatedVersion = version$1;
8476
+
8477
+ if (!estimatedVersion) {
8478
+ const rawSegments = segments.rawSplit(data);
8479
+
8480
+ // Estimate best version that can contain raw splitted segments
8481
+ estimatedVersion = version.getBestVersionForData(rawSegments, errorCorrectionLevel);
8482
+ }
8483
+
8484
+ // Build optimized segments
8485
+ // If estimated version is undefined, try with the highest version
8486
+ segments$1 = segments.fromString(data, estimatedVersion || 40);
8487
+ } else {
8488
+ throw new Error('Invalid data')
8489
+ }
8490
+
8491
+ // Get the min version that can contain data
8492
+ const bestVersion = version.getBestVersionForData(segments$1, errorCorrectionLevel);
8493
+
8494
+ // If no version is found, data cannot be stored
8495
+ if (!bestVersion) {
8496
+ throw new Error('The amount of data is too big to be stored in a QR Code')
8497
+ }
8498
+
8499
+ // If not specified, use min version as default
8500
+ if (!version$1) {
8501
+ version$1 = bestVersion;
8502
+
8503
+ // Check if the specified version can contain the data
8504
+ } else if (version$1 < bestVersion) {
8505
+ throw new Error('\n' +
8506
+ 'The chosen QR Code version cannot contain this amount of data.\n' +
8507
+ 'Minimum version required to store current data is: ' + bestVersion + '.\n'
8508
+ )
8509
+ }
8510
+
8511
+ const dataBits = createData(version$1, errorCorrectionLevel, segments$1);
8512
+
8513
+ // Allocate matrix buffer
8514
+ const moduleCount = utils$1.getSymbolSize(version$1);
8515
+ const modules = new bitMatrix(moduleCount);
8516
+
8517
+ // Add function modules
8518
+ setupFinderPattern(modules, version$1);
8519
+ setupTimingPattern(modules);
8520
+ setupAlignmentPattern(modules, version$1);
8521
+
8522
+ // Add temporary dummy bits for format info just to set them as reserved.
8523
+ // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
8524
+ // since the masking operation must be performed only on the encoding region.
8525
+ // These blocks will be replaced with correct values later in code.
8526
+ setupFormatInfo(modules, errorCorrectionLevel, 0);
8527
+
8528
+ if (version$1 >= 7) {
8529
+ setupVersionInfo(modules, version$1);
8530
+ }
8531
+
8532
+ // Add data codewords
8533
+ setupData(modules, dataBits);
8534
+
8535
+ if (isNaN(maskPattern$1)) {
8536
+ // Find best mask pattern
8537
+ maskPattern$1 = maskPattern.getBestMask(modules,
8538
+ setupFormatInfo.bind(null, modules, errorCorrectionLevel));
8539
+ }
8540
+
8541
+ // Apply mask pattern
8542
+ maskPattern.applyMask(maskPattern$1, modules);
8543
+
8544
+ // Replace format info bits with correct values
8545
+ setupFormatInfo(modules, errorCorrectionLevel, maskPattern$1);
8546
+
8547
+ return {
8548
+ modules: modules,
8549
+ version: version$1,
8550
+ errorCorrectionLevel: errorCorrectionLevel,
8551
+ maskPattern: maskPattern$1,
8552
+ segments: segments$1
8553
+ }
8554
+ }
8555
+
8556
+ /**
8557
+ * QR Code
8558
+ *
8559
+ * @param {String | Array} data Input data
8560
+ * @param {Object} options Optional configurations
8561
+ * @param {Number} options.version QR Code version
8562
+ * @param {String} options.errorCorrectionLevel Error correction level
8563
+ * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
8564
+ */
8565
+ var create$1 = function create (data, options) {
8566
+ if (typeof data === 'undefined' || data === '') {
8567
+ throw new Error('No input text')
8568
+ }
8569
+
8570
+ let errorCorrectionLevel$1 = errorCorrectionLevel.M;
8571
+ let version$1;
8572
+ let mask;
8573
+
8574
+ if (typeof options !== 'undefined') {
8575
+ // Use higher error correction level as default
8576
+ errorCorrectionLevel$1 = errorCorrectionLevel.from(options.errorCorrectionLevel, errorCorrectionLevel.M);
8577
+ version$1 = version.from(options.version);
8578
+ mask = maskPattern.from(options.maskPattern);
8579
+
8580
+ if (options.toSJISFunc) {
8581
+ utils$1.setToSJISFunction(options.toSJISFunc);
8582
+ }
8583
+ }
8584
+
8585
+ return createSymbol(data, version$1, errorCorrectionLevel$1, mask)
8586
+ };
8587
+
8588
+ var qrcode = {
8589
+ create: create$1
8590
+ };
8591
+
8592
+ var utils = createCommonjsModule(function (module, exports) {
8593
+ function hex2rgba (hex) {
8594
+ if (typeof hex === 'number') {
8595
+ hex = hex.toString();
8596
+ }
8597
+
8598
+ if (typeof hex !== 'string') {
8599
+ throw new Error('Color should be defined as hex string')
8600
+ }
8601
+
8602
+ let hexCode = hex.slice().replace('#', '').split('');
8603
+ if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
8604
+ throw new Error('Invalid hex color: ' + hex)
8605
+ }
8606
+
8607
+ // Convert from short to long form (fff -> ffffff)
8608
+ if (hexCode.length === 3 || hexCode.length === 4) {
8609
+ hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
8610
+ return [c, c]
8611
+ }));
8612
+ }
8613
+
8614
+ // Add default alpha value
8615
+ if (hexCode.length === 6) hexCode.push('F', 'F');
8616
+
8617
+ const hexValue = parseInt(hexCode.join(''), 16);
8618
+
8619
+ return {
8620
+ r: (hexValue >> 24) & 255,
8621
+ g: (hexValue >> 16) & 255,
8622
+ b: (hexValue >> 8) & 255,
8623
+ a: hexValue & 255,
8624
+ hex: '#' + hexCode.slice(0, 6).join('')
8625
+ }
8626
+ }
8627
+
8628
+ exports.getOptions = function getOptions (options) {
8629
+ if (!options) options = {};
8630
+ if (!options.color) options.color = {};
8631
+
8632
+ const margin = typeof options.margin === 'undefined' ||
8633
+ options.margin === null ||
8634
+ options.margin < 0
8635
+ ? 4
8636
+ : options.margin;
8637
+
8638
+ const width = options.width && options.width >= 21 ? options.width : undefined;
8639
+ const scale = options.scale || 4;
8640
+
8641
+ return {
8642
+ width: width,
8643
+ scale: width ? 4 : scale,
8644
+ margin: margin,
8645
+ color: {
8646
+ dark: hex2rgba(options.color.dark || '#000000ff'),
8647
+ light: hex2rgba(options.color.light || '#ffffffff')
8648
+ },
8649
+ type: options.type,
8650
+ rendererOpts: options.rendererOpts || {}
8651
+ }
8652
+ };
8653
+
8654
+ exports.getScale = function getScale (qrSize, opts) {
8655
+ return opts.width && opts.width >= qrSize + opts.margin * 2
8656
+ ? opts.width / (qrSize + opts.margin * 2)
8657
+ : opts.scale
8658
+ };
8659
+
8660
+ exports.getImageWidth = function getImageWidth (qrSize, opts) {
8661
+ const scale = exports.getScale(qrSize, opts);
8662
+ return Math.floor((qrSize + opts.margin * 2) * scale)
8663
+ };
8664
+
8665
+ exports.qrToImageData = function qrToImageData (imgData, qr, opts) {
8666
+ const size = qr.modules.size;
8667
+ const data = qr.modules.data;
8668
+ const scale = exports.getScale(size, opts);
8669
+ const symbolSize = Math.floor((size + opts.margin * 2) * scale);
8670
+ const scaledMargin = opts.margin * scale;
8671
+ const palette = [opts.color.light, opts.color.dark];
8672
+
8673
+ for (let i = 0; i < symbolSize; i++) {
8674
+ for (let j = 0; j < symbolSize; j++) {
8675
+ let posDst = (i * symbolSize + j) * 4;
8676
+ let pxColor = opts.color.light;
8677
+
8678
+ if (i >= scaledMargin && j >= scaledMargin &&
8679
+ i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
8680
+ const iSrc = Math.floor((i - scaledMargin) / scale);
8681
+ const jSrc = Math.floor((j - scaledMargin) / scale);
8682
+ pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
8683
+ }
8684
+
8685
+ imgData[posDst++] = pxColor.r;
8686
+ imgData[posDst++] = pxColor.g;
8687
+ imgData[posDst++] = pxColor.b;
8688
+ imgData[posDst] = pxColor.a;
8689
+ }
8690
+ }
8691
+ };
8692
+ });
8693
+
8694
+ var canvas = createCommonjsModule(function (module, exports) {
8695
+ function clearCanvas (ctx, canvas, size) {
8696
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
8697
+
8698
+ if (!canvas.style) canvas.style = {};
8699
+ canvas.height = size;
8700
+ canvas.width = size;
8701
+ canvas.style.height = size + 'px';
8702
+ canvas.style.width = size + 'px';
8703
+ }
8704
+
8705
+ function getCanvasElement () {
8706
+ try {
8707
+ return document.createElement('canvas')
8708
+ } catch (e) {
8709
+ throw new Error('You need to specify a canvas element')
8710
+ }
8711
+ }
8712
+
8713
+ exports.render = function render (qrData, canvas, options) {
8714
+ let opts = options;
8715
+ let canvasEl = canvas;
8716
+
8717
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
8718
+ opts = canvas;
8719
+ canvas = undefined;
8720
+ }
8721
+
8722
+ if (!canvas) {
8723
+ canvasEl = getCanvasElement();
8724
+ }
8725
+
8726
+ opts = utils.getOptions(opts);
8727
+ const size = utils.getImageWidth(qrData.modules.size, opts);
8728
+
8729
+ const ctx = canvasEl.getContext('2d');
8730
+ const image = ctx.createImageData(size, size);
8731
+ utils.qrToImageData(image.data, qrData, opts);
8732
+
8733
+ clearCanvas(ctx, canvasEl, size);
8734
+ ctx.putImageData(image, 0, 0);
8735
+
8736
+ return canvasEl
8737
+ };
8738
+
8739
+ exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
8740
+ let opts = options;
8741
+
8742
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
8743
+ opts = canvas;
8744
+ canvas = undefined;
8745
+ }
8746
+
8747
+ if (!opts) opts = {};
8748
+
8749
+ const canvasEl = exports.render(qrData, canvas, opts);
8750
+
8751
+ const type = opts.type || 'image/png';
8752
+ const rendererOpts = opts.rendererOpts || {};
8753
+
8754
+ return canvasEl.toDataURL(type, rendererOpts.quality)
8755
+ };
8756
+ });
8757
+
8758
+ function getColorAttrib (color, attrib) {
8759
+ const alpha = color.a / 255;
8760
+ const str = attrib + '="' + color.hex + '"';
8761
+
8762
+ return alpha < 1
8763
+ ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"'
8764
+ : str
8765
+ }
8766
+
8767
+ function svgCmd (cmd, x, y) {
8768
+ let str = cmd + x;
8769
+ if (typeof y !== 'undefined') str += ' ' + y;
8770
+
8771
+ return str
8772
+ }
8773
+
8774
+ function qrToPath (data, size, margin) {
8775
+ let path = '';
8776
+ let moveBy = 0;
8777
+ let newRow = false;
8778
+ let lineLength = 0;
8779
+
8780
+ for (let i = 0; i < data.length; i++) {
8781
+ const col = Math.floor(i % size);
8782
+ const row = Math.floor(i / size);
8783
+
8784
+ if (!col && !newRow) newRow = true;
8785
+
8786
+ if (data[i]) {
8787
+ lineLength++;
8788
+
8789
+ if (!(i > 0 && col > 0 && data[i - 1])) {
8790
+ path += newRow
8791
+ ? svgCmd('M', col + margin, 0.5 + row + margin)
8792
+ : svgCmd('m', moveBy, 0);
8793
+
8794
+ moveBy = 0;
8795
+ newRow = false;
8796
+ }
8797
+
8798
+ if (!(col + 1 < size && data[i + 1])) {
8799
+ path += svgCmd('h', lineLength);
8800
+ lineLength = 0;
8801
+ }
8802
+ } else {
8803
+ moveBy++;
8804
+ }
8805
+ }
8806
+
8807
+ return path
8808
+ }
8809
+
8810
+ var render = function render (qrData, options, cb) {
8811
+ const opts = utils.getOptions(options);
8812
+ const size = qrData.modules.size;
8813
+ const data = qrData.modules.data;
8814
+ const qrcodesize = size + opts.margin * 2;
8815
+
8816
+ const bg = !opts.color.light.a
8817
+ ? ''
8818
+ : '<path ' + getColorAttrib(opts.color.light, 'fill') +
8819
+ ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>';
8820
+
8821
+ const path =
8822
+ '<path ' + getColorAttrib(opts.color.dark, 'stroke') +
8823
+ ' d="' + qrToPath(data, size, opts.margin) + '"/>';
8824
+
8825
+ const viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"';
8826
+
8827
+ const width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" ';
8828
+
8829
+ const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n';
8830
+
8831
+ if (typeof cb === 'function') {
8832
+ cb(null, svgTag);
8833
+ }
8834
+
8835
+ return svgTag
8836
+ };
8837
+
8838
+ var svgTag = {
8839
+ render: render
8840
+ };
8841
+
8842
+ function renderCanvas (renderFunc, canvas, text, opts, cb) {
8843
+ const args = [].slice.call(arguments, 1);
8844
+ const argsNum = args.length;
8845
+ const isLastArgCb = typeof args[argsNum - 1] === 'function';
8846
+
8847
+ if (!isLastArgCb && !canPromise()) {
8848
+ throw new Error('Callback required as last argument')
8849
+ }
8850
+
8851
+ if (isLastArgCb) {
8852
+ if (argsNum < 2) {
8853
+ throw new Error('Too few arguments provided')
8854
+ }
8855
+
8856
+ if (argsNum === 2) {
8857
+ cb = text;
8858
+ text = canvas;
8859
+ canvas = opts = undefined;
8860
+ } else if (argsNum === 3) {
8861
+ if (canvas.getContext && typeof cb === 'undefined') {
8862
+ cb = opts;
8863
+ opts = undefined;
8864
+ } else {
8865
+ cb = opts;
8866
+ opts = text;
8867
+ text = canvas;
8868
+ canvas = undefined;
8869
+ }
8870
+ }
8871
+ } else {
8872
+ if (argsNum < 1) {
8873
+ throw new Error('Too few arguments provided')
8874
+ }
8875
+
8876
+ if (argsNum === 1) {
8877
+ text = canvas;
8878
+ canvas = opts = undefined;
8879
+ } else if (argsNum === 2 && !canvas.getContext) {
8880
+ opts = text;
8881
+ text = canvas;
8882
+ canvas = undefined;
8883
+ }
8884
+
8885
+ return new Promise(function (resolve, reject) {
8886
+ try {
8887
+ const data = qrcode.create(text, opts);
8888
+ resolve(renderFunc(data, canvas, opts));
8889
+ } catch (e) {
8890
+ reject(e);
8891
+ }
8892
+ })
8893
+ }
8894
+
8895
+ try {
8896
+ const data = qrcode.create(text, opts);
8897
+ cb(null, renderFunc(data, canvas, opts));
8898
+ } catch (e) {
8899
+ cb(e);
8900
+ }
8901
+ }
8902
+
8903
+ var create = qrcode.create;
8904
+ var toCanvas = renderCanvas.bind(null, canvas.render);
8905
+ var toDataURL = renderCanvas.bind(null, canvas.renderToDataURL);
8906
+
8907
+ // only svg for now.
8908
+ var toString_1 = renderCanvas.bind(null, function (data, _, opts) {
8909
+ return svgTag.render(data, opts)
8910
+ });
8911
+
8912
+ var browser = {
8913
+ create: create,
8914
+ toCanvas: toCanvas,
8915
+ toDataURL: toDataURL,
8916
+ toString: toString_1
8917
+ };
8918
+
8919
+ const mobileRedirectCss = ".qr-canvas{max-height:60vh;max-width:80vw;text-align:center}.qr-canvas>canvas{width:100%;height:100%}";
8920
+
8921
+ const MobileRedirect = class {
8922
+ constructor(hostRef) {
8923
+ index.registerInstance(this, hostRef);
8924
+ this.apiErrorEvent = index.createEvent(this, "apiError", 7);
8925
+ this.delay = ms => new Promise(res => setTimeout(res, ms));
8926
+ this.qrCanvas = undefined;
8927
+ this.infoTextTop = undefined;
8928
+ this.infoTextBottom = undefined;
8929
+ this.contact = undefined;
8930
+ this.invalidValue = undefined;
8931
+ this.waitingMobile = undefined;
8932
+ this.orderStatus = undefined;
8933
+ this.redirectLink = undefined;
8934
+ this.apiCall = new ApiCall();
8935
+ this.invalidValue = false;
8936
+ this.waitingMobile = false;
8937
+ }
8938
+ async componentDidLoad() {
8939
+ this.infoTextTop = MobileRedirectValues.InfoTop;
8940
+ this.infoTextBottom = MobileRedirectValues.InfoBottom;
8941
+ this.redirectLink = 'https://onro.id-kyc.com/fromqr?orderId=' + state.requestId + '&token=' + state.token;
8942
+ browser.toDataURL(this.qrCanvas, this.redirectLink, { type: 'image/png', errorCorrectionLevel: 'M', scale: 6 }, function (error) {
8943
+ if (error)
8944
+ console.error(error);
8945
+ });
8946
+ this.checkStatus();
8947
+ while (this.orderStatus == OrderStatuses.Capturing || this.orderStatus == OrderStatuses.Waiting) {
8948
+ await this.checkStatus();
8949
+ await this.delay(10000);
8950
+ }
8951
+ }
8952
+ async checkStatus() {
8953
+ this.orderStatus = await this.apiCall.GetStatus(state.requestId);
8954
+ if (this.orderStatus == OrderStatuses.FinishedCapturing) {
8955
+ this.waitingMobile = false;
8956
+ state.flowStatus = FlowStatus.COMPLETE;
8957
+ }
8958
+ if (this.orderStatus == OrderStatuses.NotFound) {
8959
+ this.apiErrorEvent.emit('No order was started for this process.');
8960
+ }
8961
+ if (this.orderStatus == OrderStatuses.Capturing) {
8962
+ this.waitingMobile = true;
8963
+ }
8964
+ }
8965
+ async buttonClick() {
8966
+ this.waitingMobile = true;
8967
+ await this.apiCall.SendLink(this.redirectLink, this.contact);
8968
+ }
8969
+ handleChangeContact(ev) {
8970
+ let value = ev.target ? ev.target.value : '';
8971
+ this.contact = value.replace(/\D/g, '');
8972
+ if (this.contact.length > 10)
8973
+ this.contact = this.contact.substring(0, 10);
8974
+ ev.target.value = this.contact;
8975
+ }
8976
+ render() {
8977
+ return (index.h("div", { class: "container" }, index.h("div", { class: "row" }, index.h("div", { hidden: this.waitingMobile }, index.h("div", { class: "text-center" }, index.h("p", { class: "font-size-2" }, this.infoTextTop)), index.h("div", { class: "qr-canvas align-center" }, index.h("canvas", { id: "canvas", ref: el => (this.qrCanvas = el) })), index.h("div", { class: "text-center" }, index.h("p", { class: "font-size-2" }, this.infoTextBottom)), index.h("div", { class: "input-container mb-15" }, index.h("label", { class: "font-size-18 mb-1 color-red", hidden: this.invalidValue == false }, index.h("b", null, MobileRedirectValues.Validation)), index.h("input", { type: "text", id: "codeInput", class: "main-input", value: this.contact, onInput: ev => this.handleChangeContact(ev) })), index.h("div", { class: "pos-relative" }, index.h("div", { class: "btn-buletin" }, index.h("button", { class: "main-button", onClick: () => this.buttonClick() }, "Trimite"), index.h("p", { class: "main-text font-size-18 text-right mb-0" }, MobileRedirectValues.FooterText)))), index.h("div", { hidden: this.waitingMobile == false }, index.h("div", { class: "text-center" }, index.h("p", { class: "font-size-2" }, this.infoTextTop))))));
8978
+ }
8979
+ };
8980
+ MobileRedirect.style = mobileRedirectCss;
8981
+
6016
8982
  const selfieCaptureCss = "";
6017
8983
 
6018
8984
  const SelfieCapture = class {
@@ -6337,6 +9303,7 @@ exports.id_double_side = IdDoubleSide;
6337
9303
  exports.id_single_side = IdSingleSide;
6338
9304
  exports.identification_component = IdentificationComponent;
6339
9305
  exports.landing_validation = LandingValidation;
9306
+ exports.mobile_redirect = MobileRedirect;
6340
9307
  exports.selfie_capture = SelfieCapture;
6341
9308
  exports.sms_code_validation = SmsCodeValidation;
6342
9309
  exports.user_liveness = UserLiveness;