@ekyc_qoobiss/qbs-ect-cmp 1.12.2 → 1.12.3

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