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