veryfi-lens-wasm 2.0.3 → 2.0.5-beta.1
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/components/blurModal.js +10 -4
- package/components/createFileUpload.js +11 -0
- package/components/croppedImage.js +38 -0
- package/components/documentModal.js +13 -4
- package/components/exitButton.js +7 -0
- package/components/submitButton.js +16 -0
- package/components/torchButton.js +15 -7
- package/package.json +1 -1
- package/utils/parser-wrapper.js +30 -1
- package/veryfi-lens.js +175 -142
- package/components/checksCapture.js +0 -71
package/components/blurModal.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const createBlurModal = (container, croppedImage, onRetake, onSubmit) => {
|
|
1
|
+
export const createBlurModal = (container, croppedImage, onRetake, onSubmit, options = {}) => {
|
|
2
2
|
const modal = document.createElement('div');
|
|
3
3
|
modal.id = 'veryfi-blur-modal';
|
|
4
4
|
modal.style.display = 'none';
|
|
@@ -31,6 +31,12 @@ export const createBlurModal = (container, croppedImage, onRetake, onSubmit) =>
|
|
|
31
31
|
secondaryButtonColor: '#1e293b'
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
const defaultOptions = {
|
|
35
|
+
blurModalMessage: 'Oops, The image is too blurry to process'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Merge provided options with defaults
|
|
39
|
+
const modalOptions = { ...defaultOptions, ...options };
|
|
34
40
|
// Apply styles with fallback to default values
|
|
35
41
|
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
36
42
|
const cssVar = `--blur-modal-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
|
|
@@ -50,7 +56,7 @@ export const createBlurModal = (container, croppedImage, onRetake, onSubmit) =>
|
|
|
50
56
|
font-size: var(--blur-modal-text-font-size, ${defaultStyles.textFontSize});
|
|
51
57
|
font-family: var(--blur-modal-text-font-family, ${defaultStyles.textFontFamily});
|
|
52
58
|
">
|
|
53
|
-
|
|
59
|
+
${modalOptions.blurModalMessage.replace(/</g, '<').replace(/>/g, '>')}
|
|
54
60
|
</p>
|
|
55
61
|
<div style="display: flex; flex-direction: column; align-items: center; gap: 8px;">
|
|
56
62
|
<button id="veryfi-retake-blur" style="
|
|
@@ -69,7 +75,7 @@ export const createBlurModal = (container, croppedImage, onRetake, onSubmit) =>
|
|
|
69
75
|
font-family: var(--blur-modal-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
70
76
|
text-transform: var(--blur-modal-button-text-transform, ${defaultStyles.buttonTextTransform});
|
|
71
77
|
">
|
|
72
|
-
|
|
78
|
+
${modalOptions.retakeButtonText.replace(/</g, '<').replace(/>/g, '>')}
|
|
73
79
|
</p>
|
|
74
80
|
</button>
|
|
75
81
|
<button id="veryfi-submit-blur" style="
|
|
@@ -88,7 +94,7 @@ export const createBlurModal = (container, croppedImage, onRetake, onSubmit) =>
|
|
|
88
94
|
font-family: var(--blur-modal-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
89
95
|
text-transform: var(--blur-modal-button-text-transform, ${defaultStyles.buttonTextTransform});
|
|
90
96
|
">
|
|
91
|
-
|
|
97
|
+
${modalOptions.submitButtonText.replace(/</g, '<').replace(/>/g, '>')}
|
|
92
98
|
</p>
|
|
93
99
|
</button>
|
|
94
100
|
</div>
|
|
@@ -12,6 +12,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
|
|
|
12
12
|
alignItems: 'center',
|
|
13
13
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
14
14
|
imageContainerHeight: 'calc(100% - 120px)',
|
|
15
|
+
imageContainerTop: 'unset',
|
|
15
16
|
imagePreviewMaxWidth: '500px',
|
|
16
17
|
imagePreviewMaxHeight: '80vh',
|
|
17
18
|
imagePreviewObjectFit: 'contain',
|
|
@@ -44,6 +45,15 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
|
|
|
44
45
|
fileUploadComponent.style.setProperty(cssVar, `var(${cssVar}, ${value})`);
|
|
45
46
|
});
|
|
46
47
|
|
|
48
|
+
const isLandscape = window.innerWidth > window.innerHeight;
|
|
49
|
+
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
|
|
50
|
+
if (isLandscape && isMobile) {
|
|
51
|
+
fileUploadComponent.style.position = 'fixed';
|
|
52
|
+
fileUploadComponent.style.bottom = '5px';
|
|
53
|
+
fileUploadComponent.style.zIndex = '9999';
|
|
54
|
+
fileUploadComponent.style.imageContainerTop = '0%';
|
|
55
|
+
}
|
|
56
|
+
|
|
47
57
|
fileUploadComponent.innerHTML = `
|
|
48
58
|
<div id="image-container" style="
|
|
49
59
|
width: 100%;
|
|
@@ -52,6 +62,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
|
|
|
52
62
|
justify-content: center;
|
|
53
63
|
align-items: center;
|
|
54
64
|
overflow: hidden;
|
|
65
|
+
top: var(--file-upload-image-container-top, ${defaultStyles.imageContainerTop});
|
|
55
66
|
">
|
|
56
67
|
<img id="veryfi-image-preview" style="
|
|
57
68
|
max-width: var(--file-upload-image-preview-max-width, ${defaultStyles.imagePreviewMaxWidth});
|
|
@@ -15,8 +15,38 @@ export const createCroppedImage = (container) => {
|
|
|
15
15
|
cropImgCanvas.style[key] = value;
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
+
// Override the putImageData method to handle rotation automatically
|
|
19
|
+
const originalPutImageData = cropImgCanvas.getContext('2d').putImageData;
|
|
20
|
+
cropImgCanvas.getContext('2d').putImageData = function(imageData, dx, dy) {
|
|
21
|
+
// Check if we're in check capture mode
|
|
22
|
+
const isCheckCapture = container.querySelector('#check-images-container') !== null;
|
|
23
|
+
|
|
24
|
+
if (!isCheckCapture && imageData.width > imageData.height) { // Only rotate for non-check captures
|
|
25
|
+
const tempCanvas = document.createElement('canvas');
|
|
26
|
+
tempCanvas.width = imageData.width;
|
|
27
|
+
tempCanvas.height = imageData.height;
|
|
28
|
+
const tempCtx = tempCanvas.getContext('2d');
|
|
29
|
+
tempCtx.putImageData(imageData, 0, 0);
|
|
30
|
+
|
|
31
|
+
cropImgCanvas.width = imageData.height;
|
|
32
|
+
cropImgCanvas.height = imageData.width;
|
|
33
|
+
|
|
34
|
+
this.clearRect(0, 0, cropImgCanvas.width, cropImgCanvas.height);
|
|
35
|
+
this.save();
|
|
36
|
+
this.translate(cropImgCanvas.width, 0);
|
|
37
|
+
this.rotate(Math.PI/2);
|
|
38
|
+
this.drawImage(tempCanvas, 0, 0);
|
|
39
|
+
this.restore();
|
|
40
|
+
} else {
|
|
41
|
+
cropImgCanvas.width = imageData.width;
|
|
42
|
+
cropImgCanvas.height = imageData.height;
|
|
43
|
+
originalPutImageData.call(this, imageData, dx, dy);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
18
47
|
const handleResize = () => {
|
|
19
48
|
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
|
|
49
|
+
const isLandscape = window.innerWidth > window.innerHeight;
|
|
20
50
|
|
|
21
51
|
if (isMobile) {
|
|
22
52
|
cropImgCanvas.style.width = '370px';
|
|
@@ -25,6 +55,14 @@ export const createCroppedImage = (container) => {
|
|
|
25
55
|
cropImgCanvas.style.position = 'fixed';
|
|
26
56
|
cropImgCanvas.style.top = '';
|
|
27
57
|
cropImgCanvas.style.left = '';
|
|
58
|
+
if (isLandscape) {
|
|
59
|
+
cropImgCanvas.style.width = '170px';
|
|
60
|
+
cropImgCanvas.style.height = '85vh';
|
|
61
|
+
cropImgCanvas.style.maxWidth = '200px';
|
|
62
|
+
cropImgCanvas.style.position = 'fixed';
|
|
63
|
+
cropImgCanvas.style.top = '';
|
|
64
|
+
cropImgCanvas.style.left = '';
|
|
65
|
+
}
|
|
28
66
|
} else {
|
|
29
67
|
cropImgCanvas.style.width = '100%';
|
|
30
68
|
cropImgCanvas.style.height = '95%';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const createDocumentModal = (container, croppedImage, onRetake, onSubmit) => {
|
|
1
|
+
export const createDocumentModal = (container, croppedImage, onRetake, onSubmit, options = {}) => {
|
|
2
2
|
const modal = document.createElement('div');
|
|
3
3
|
modal.id = 'veryfi-document-modal';
|
|
4
4
|
modal.style.display = 'none';
|
|
@@ -32,6 +32,15 @@ export const createDocumentModal = (container, croppedImage, onRetake, onSubmit)
|
|
|
32
32
|
secondaryButtonColor: '#1e293b'
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
const defaultOptions = {
|
|
36
|
+
noDocumentMessage: 'Oops, There appears to be no document on your image',
|
|
37
|
+
retakeButtonText: 'Retake a picture',
|
|
38
|
+
submitButtonText: 'Submit Anyway'
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Merge provided options with defaults
|
|
42
|
+
const modalOptions = { ...defaultOptions, ...options };
|
|
43
|
+
|
|
35
44
|
// Apply styles with fallback to default values
|
|
36
45
|
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
37
46
|
const cssVar = `--modal-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
|
|
@@ -52,7 +61,7 @@ export const createDocumentModal = (container, croppedImage, onRetake, onSubmit)
|
|
|
52
61
|
font-size: var(--modal-text-font-size, ${defaultStyles.textFontSize});
|
|
53
62
|
font-family: var(--modal-text-font-family, ${defaultStyles.textFontFamily});
|
|
54
63
|
">
|
|
55
|
-
|
|
64
|
+
${modalOptions.noDocumentMessage.replace(/</g, '<').replace(/>/g, '>')}
|
|
56
65
|
</p>
|
|
57
66
|
<div style="display: flex; flex-direction: column; align-items: center; gap: 8px;">
|
|
58
67
|
<button id="veryfi-retake-document" style="
|
|
@@ -71,7 +80,7 @@ export const createDocumentModal = (container, croppedImage, onRetake, onSubmit)
|
|
|
71
80
|
font-family: var(--modal-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
72
81
|
text-transform: var(--modal-button-text-transform, ${defaultStyles.buttonTextTransform});
|
|
73
82
|
">
|
|
74
|
-
|
|
83
|
+
${modalOptions.retakeButtonText.replace(/</g, '<').replace(/>/g, '>')}
|
|
75
84
|
</p>
|
|
76
85
|
</button>
|
|
77
86
|
<button id="veryfi-submit-document" style="
|
|
@@ -90,7 +99,7 @@ export const createDocumentModal = (container, croppedImage, onRetake, onSubmit)
|
|
|
90
99
|
font-family: var(--modal-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
91
100
|
text-transform: var(--modal-button-text-transform, ${defaultStyles.buttonTextTransform});
|
|
92
101
|
">
|
|
93
|
-
|
|
102
|
+
${modalOptions.submitButtonText.replace(/</g, '<').replace(/>/g, '>')}
|
|
94
103
|
</p>
|
|
95
104
|
</button>
|
|
96
105
|
</div>
|
package/components/exitButton.js
CHANGED
|
@@ -60,6 +60,13 @@ export const createExitButton = (container, options, removeOverlay) => {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
if (lensFlavor === 'upload') {
|
|
64
|
+
button.style.right = '40px';
|
|
65
|
+
button.style.top = '40px';
|
|
66
|
+
button.style.left = 'unset';
|
|
67
|
+
button.style.bottom = 'unset';
|
|
68
|
+
}
|
|
69
|
+
|
|
63
70
|
button.addEventListener('mouseenter', () => {
|
|
64
71
|
button.style.backgroundColor = 'rgba(55, 65, 81, 0.8)';
|
|
65
72
|
});
|
|
@@ -18,10 +18,26 @@ export const createSubmitButton = (container, onSubmit, removeOverlay) => {
|
|
|
18
18
|
display: 'none',
|
|
19
19
|
pointerEvents: 'auto'
|
|
20
20
|
};
|
|
21
|
+
|
|
22
|
+
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
|
|
23
|
+
const isLandscape = window.innerWidth > window.innerHeight;
|
|
24
|
+
console.log('isLandscape', isLandscape);
|
|
25
|
+
|
|
21
26
|
|
|
22
27
|
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
23
28
|
button.style[key] = value;
|
|
24
29
|
});
|
|
30
|
+
|
|
31
|
+
if (isLandscape && isMobile) {
|
|
32
|
+
button.style.position = 'fixed';
|
|
33
|
+
button.style.bottom = 'calc(50% - 20px)';
|
|
34
|
+
button.style.transform = 'rotate(270deg)';
|
|
35
|
+
button.style.right = '20px';
|
|
36
|
+
button.style.left = 'unset';
|
|
37
|
+
button.style.top = 'unset';
|
|
38
|
+
button.style.zIndex = '9999';
|
|
39
|
+
}
|
|
40
|
+
|
|
25
41
|
button.addEventListener('click', () => {
|
|
26
42
|
onSubmit();
|
|
27
43
|
removeOverlay();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const createTorchButton = (container, toggleCallback) => {
|
|
1
|
+
export const createTorchButton = (container, toggleCallback, lensFlavor) => {
|
|
2
2
|
const button = document.createElement("button");
|
|
3
3
|
button.id = "veryfi-torch-button";
|
|
4
4
|
|
|
@@ -40,13 +40,21 @@ export const createTorchButton = (container, toggleCallback) => {
|
|
|
40
40
|
!isMobile && (button.style.display = 'none');
|
|
41
41
|
|
|
42
42
|
if (isMobile && isLandscape) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
if (lensFlavor === 'credit_card') {
|
|
44
|
+
// Special positioning for credit card in landscape
|
|
45
|
+
button.style.position = 'fixed';
|
|
46
|
+
button.style.bottom = '20px';
|
|
47
|
+
button.style.right = '20px';
|
|
48
|
+
button.style.left = 'unset';
|
|
49
|
+
button.style.top = 'unset';
|
|
50
|
+
button.style.zIndex = '9999'; // Ensure it's above the card outline
|
|
51
|
+
} else {
|
|
52
|
+
button.style.right = '50px';
|
|
53
|
+
button.style.botom = 'calc(20vh - 20px)';
|
|
54
|
+
button.style.left = 'unset';
|
|
55
|
+
button.style.top = 'unset';
|
|
49
56
|
}
|
|
57
|
+
}
|
|
50
58
|
|
|
51
59
|
button.addEventListener('mouseover', () => {
|
|
52
60
|
button.style.backgroundColor = 'rgba(75, 85, 99, 0.8)';
|
package/package.json
CHANGED
package/utils/parser-wrapper.js
CHANGED
|
@@ -1,2 +1,31 @@
|
|
|
1
1
|
import './ua-parser.js';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
// Create a wrapper that ensures we always have something to export
|
|
4
|
+
const UAParserWrapper = function(ua, extensions) {
|
|
5
|
+
if (typeof window !== 'undefined' && window.UAParser) {
|
|
6
|
+
return new window.UAParser(ua, extensions);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Fallback implementation that won't crash
|
|
10
|
+
return {
|
|
11
|
+
getResult: function() {
|
|
12
|
+
return {
|
|
13
|
+
ua: ua || navigator?.userAgent || '',
|
|
14
|
+
browser: { name: 'unknown', version: 'unknown' },
|
|
15
|
+
engine: { name: 'unknown', version: 'unknown' },
|
|
16
|
+
os: { name: 'unknown', version: 'unknown' },
|
|
17
|
+
device: { model: 'unknown', type: 'unknown', vendor: 'unknown' },
|
|
18
|
+
cpu: { architecture: 'unknown' }
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
getBrowser: function() { return { name: 'unknown', version: 'unknown' }; },
|
|
22
|
+
getEngine: function() { return { name: 'unknown', version: 'unknown' }; },
|
|
23
|
+
getOS: function() { return { name: 'unknown', version: 'unknown' }; },
|
|
24
|
+
getDevice: function() { return { model: 'unknown', type: 'unknown', vendor: 'unknown' }; },
|
|
25
|
+
getCPU: function() { return { architecture: 'unknown' }; },
|
|
26
|
+
getUA: function() { return ua || navigator?.userAgent || ''; },
|
|
27
|
+
setUA: function() { return this; }
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default UAParserWrapper;
|
package/veryfi-lens.js
CHANGED
|
@@ -138,6 +138,10 @@ const VeryfiLens = (function () {
|
|
|
138
138
|
submitButtonShown: false,
|
|
139
139
|
backScanningStartTime: null,
|
|
140
140
|
sdkVersion: "2.0.0",
|
|
141
|
+
documentModalMessage: 'Oops, There appears to be no document on your image',
|
|
142
|
+
blurModalMessage: 'Oops, The image is too blurry to process',
|
|
143
|
+
submitButtonText: 'Submit Anyway',
|
|
144
|
+
retakeButtonText: 'Retake a picture',
|
|
141
145
|
};
|
|
142
146
|
|
|
143
147
|
|
|
@@ -179,20 +183,23 @@ const VeryfiLens = (function () {
|
|
|
179
183
|
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
|
|
180
184
|
|
|
181
185
|
let videoConfig = {
|
|
182
|
-
...(isMobile ? {
|
|
183
|
-
width: { ideal: 3840 },
|
|
184
|
-
height: { ideal: 2160 },
|
|
185
|
-
} : lensFlavor === 'long_document' ? {
|
|
186
|
-
width: { ideal: 3840 },
|
|
187
|
-
height: { ideal: 2160 },
|
|
188
|
-
} : {
|
|
186
|
+
...(isMobile && lensFlavor === 'long_document' ? {
|
|
189
187
|
width: { ideal: 1920 },
|
|
190
|
-
height: { ideal: 1080 }
|
|
188
|
+
height: { ideal: 1080 }
|
|
189
|
+
} : isMobile ? {
|
|
190
|
+
width: { ideal: 2440 }, // Also reduced for other mobile cases
|
|
191
|
+
height: { ideal: 1080 }
|
|
192
|
+
} : state.fullScreenEnabled ? {
|
|
193
|
+
width: { ideal: 1920 },
|
|
194
|
+
height: { ideal: 1080 }
|
|
195
|
+
} : {
|
|
196
|
+
width: { ideal: 3840 },
|
|
197
|
+
height: { ideal: 2160 }
|
|
191
198
|
}),
|
|
192
199
|
facingMode: "environment",
|
|
193
|
-
advanced: [{ torch: true }]
|
|
200
|
+
advanced: [{ torch: true }]
|
|
194
201
|
};
|
|
195
|
-
console.log(videoConfig);
|
|
202
|
+
state.debug_mode && console.log("video config", videoConfig);
|
|
196
203
|
|
|
197
204
|
if (isAndroid) {
|
|
198
205
|
try {
|
|
@@ -201,6 +208,7 @@ const VeryfiLens = (function () {
|
|
|
201
208
|
const mainCameraDevice = videoDevices.find(device => device.label.includes("camera2 0"));
|
|
202
209
|
if (mainCameraDevice) {
|
|
203
210
|
videoConfig.deviceId = { exact: mainCameraDevice.deviceId };
|
|
211
|
+
console.log("mainCameraDevice", mainCameraDevice);
|
|
204
212
|
}
|
|
205
213
|
} catch (error) {
|
|
206
214
|
console.error("Error enumerating devices", error);
|
|
@@ -395,6 +403,7 @@ const VeryfiLens = (function () {
|
|
|
395
403
|
createImageBitmap(state.fullSizeImage).then((bitmap) => {
|
|
396
404
|
if (wasmWrapper && typeof wasmWrapper.processDocument === 'function') {
|
|
397
405
|
wasmWrapper.processDocument(bitmap, mode);
|
|
406
|
+
|
|
398
407
|
rCorners = state.coordinates.map((corner) => corner);
|
|
399
408
|
if (
|
|
400
409
|
rCorners.length &&
|
|
@@ -413,6 +422,7 @@ const VeryfiLens = (function () {
|
|
|
413
422
|
state.image = imgString;
|
|
414
423
|
}
|
|
415
424
|
}
|
|
425
|
+
bitmap.close();
|
|
416
426
|
});
|
|
417
427
|
} catch (error) {
|
|
418
428
|
console.log(error);
|
|
@@ -852,11 +862,22 @@ const VeryfiLens = (function () {
|
|
|
852
862
|
};
|
|
853
863
|
|
|
854
864
|
const parseUA = () => {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
865
|
+
try {
|
|
866
|
+
const userAgentString = navigator.userAgent;
|
|
867
|
+
const parser = UAParser(userAgentString); // Note: no 'new' keyword needed now
|
|
868
|
+
let parserResults = parser.getResult();
|
|
869
|
+
if (parserResults) {
|
|
870
|
+
return parserResults;
|
|
871
|
+
}
|
|
872
|
+
// ...
|
|
873
|
+
} catch (error) {
|
|
874
|
+
console.error('Error parsing user agent:', error);
|
|
875
|
+
// Return fallback object
|
|
876
|
+
return {
|
|
877
|
+
browser: { name: 'unknown', version: 'unknown' },
|
|
878
|
+
os: { name: 'unknown', version: 'unknown' },
|
|
879
|
+
device: { model: 'unknown', type: 'unknown', vendor: 'unknown' }
|
|
880
|
+
};
|
|
860
881
|
}
|
|
861
882
|
};
|
|
862
883
|
|
|
@@ -886,7 +907,7 @@ const VeryfiLens = (function () {
|
|
|
886
907
|
if (state.torchButton) {
|
|
887
908
|
state.torchButton = createTorchButton(state.videoOverlay.overlay, () => {
|
|
888
909
|
toggleTorchLight();
|
|
889
|
-
});
|
|
910
|
+
}, state.lensFlavor);
|
|
890
911
|
}
|
|
891
912
|
};
|
|
892
913
|
|
|
@@ -904,6 +925,11 @@ const VeryfiLens = (function () {
|
|
|
904
925
|
lensFlavor: state.lensFlavor,
|
|
905
926
|
}, removeOverlay);
|
|
906
927
|
}
|
|
928
|
+
if (state.torchButton) {
|
|
929
|
+
state.torchButton = createTorchButton(state.cardOverlay.element, () => {
|
|
930
|
+
toggleTorchLight();
|
|
931
|
+
}, state.lensFlavor);
|
|
932
|
+
}
|
|
907
933
|
}
|
|
908
934
|
|
|
909
935
|
const renderModalsIfNeeded = () => {
|
|
@@ -922,6 +948,11 @@ const VeryfiLens = (function () {
|
|
|
922
948
|
state.debug_mode && console.log("Submitting anyway");
|
|
923
949
|
hideVideoOverlay();
|
|
924
950
|
state.submitHandler && state.submitHandler(state.finalImage);
|
|
951
|
+
},
|
|
952
|
+
{
|
|
953
|
+
blurModalMessage: state.blurModalMessage,
|
|
954
|
+
retakeButtonText: state.retakeButtonText,
|
|
955
|
+
submitButtonText: state.submitButtonText
|
|
925
956
|
}
|
|
926
957
|
);
|
|
927
958
|
}
|
|
@@ -939,6 +970,11 @@ const VeryfiLens = (function () {
|
|
|
939
970
|
state.debug_mode && console.log("Submitting anyway");
|
|
940
971
|
hideVideoOverlay();
|
|
941
972
|
state.submitHandler && state.submitHandler(state.finalImage);
|
|
973
|
+
},
|
|
974
|
+
{
|
|
975
|
+
noDocumentMessage: state.documentModalMessage,
|
|
976
|
+
retakeButtonText: state.retakeButtonText,
|
|
977
|
+
submitButtonText: state.submitButtonText
|
|
942
978
|
}
|
|
943
979
|
);
|
|
944
980
|
}
|
|
@@ -1365,148 +1401,137 @@ const VeryfiLens = (function () {
|
|
|
1365
1401
|
|
|
1366
1402
|
const captureChecks = async () => {
|
|
1367
1403
|
try {
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1404
|
+
if (state.isCapturingFront) {
|
|
1405
|
+
state.frontImage = await cropWasm();
|
|
1406
|
+
state.finalImage = state.frontImage;
|
|
1407
|
+
|
|
1408
|
+
// Hide video and box elements temporarily
|
|
1409
|
+
if (state.videoRef) state.videoRef.style.display = 'none';
|
|
1410
|
+
if (state.boxRef) state.boxRef.style.display = 'none';
|
|
1411
|
+
if (state.frameRef) state.frameRef.style.display = 'none';
|
|
1412
|
+
|
|
1413
|
+
const isDocumentDetected = checkIfDocumentOnCapture();
|
|
1414
|
+
if (!isDocumentDetected) {
|
|
1415
|
+
showVideoOverlay();
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1379
1418
|
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1419
|
+
const isBlurry = checkIfBlurOnCapture();
|
|
1420
|
+
if (isBlurry) {
|
|
1421
|
+
showVideoOverlay();
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1385
1424
|
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
}
|
|
1425
|
+
if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
|
|
1426
|
+
state.cropImgRef.showSuccessBorder();
|
|
1427
|
+
}
|
|
1390
1428
|
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1429
|
+
if (state.captureBackOfCheck) {
|
|
1430
|
+
const checkCaptureModal = createCheckCaptureModal(
|
|
1431
|
+
state.container,
|
|
1432
|
+
state.finalImage,
|
|
1433
|
+
() => {
|
|
1434
|
+
// "Yes" click handler
|
|
1435
|
+
// Show video elements again
|
|
1436
|
+
if (state.videoRef) state.videoRef.style.display = 'block';
|
|
1437
|
+
if (state.boxRef) state.boxRef.style.display = 'block';
|
|
1438
|
+
if (state.frameRef) state.frameRef.style.display = 'block';
|
|
1439
|
+
|
|
1440
|
+
// Reset border and clear canvas
|
|
1441
|
+
if (state.cropImgRef) {
|
|
1442
|
+
state.cropImgRef.hideBorder();
|
|
1443
|
+
const ctx = state.cropImgRef.getContext("2d");
|
|
1444
|
+
if (ctx) {
|
|
1445
|
+
ctx.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
newStartLens(state.lensFlavor);
|
|
1449
|
+
},
|
|
1450
|
+
() => {
|
|
1451
|
+
// "No" click handler
|
|
1452
|
+
hideVideoOverlay();
|
|
1453
|
+
if (state.isDocument && !state.blurStatus) {
|
|
1454
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1455
|
+
handleSubmit(state.frontImage);
|
|
1456
|
+
}, removeOverlay);
|
|
1457
|
+
state.enableSubmit && state.submitButton.show();
|
|
1458
|
+
}
|
|
1459
|
+
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
1460
|
+
state.resultSetter({
|
|
1461
|
+
frontImage: state.frontImage
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
);
|
|
1466
|
+
checkCaptureModal.show();
|
|
1467
|
+
state.isCapturingFront = false;
|
|
1468
|
+
state.updateHandler && state.updateHandler({ status: 'capture_back_side' });
|
|
1421
1469
|
}
|
|
1422
|
-
);
|
|
1423
|
-
checkCaptureModal.show();
|
|
1424
|
-
state.isCapturingFront = false;
|
|
1425
|
-
state.updateHandler && state.updateHandler({ status: 'capture_back_side' });
|
|
1426
|
-
} else{
|
|
1427
|
-
hideVideoOverlay();
|
|
1428
|
-
if (state.isDocument && !state.blurStatus) {
|
|
1429
|
-
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1430
|
-
handleSubmit(state.frontImage);
|
|
1431
|
-
}, removeOverlay);
|
|
1432
|
-
state.enableSubmit && state.submitButton.show();
|
|
1433
|
-
}
|
|
1434
|
-
// Call success handler with front image only
|
|
1435
|
-
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
1436
|
-
state.resultSetter({
|
|
1437
|
-
frontImage: state.frontImage
|
|
1438
|
-
});
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
1470
|
|
|
1442
|
-
|
|
1443
|
-
|
|
1471
|
+
} else {
|
|
1472
|
+
state.backImage = await cropWasm();
|
|
1444
1473
|
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1474
|
+
state.debug_mode && console.log("Back capture - Document detected:", state.isDocument);
|
|
1475
|
+
// Check for document first
|
|
1476
|
+
const isDocumentDetected = checkIfDocumentOnCapture();
|
|
1477
|
+
state.debug_mode && console.log("Back capture - Document check result:", isDocumentDetected);
|
|
1449
1478
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1479
|
+
if (!isDocumentDetected) {
|
|
1480
|
+
state.debug_mode && console.log("Back capture - No document detected, showing video overlay");
|
|
1481
|
+
showVideoOverlay();
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1455
1484
|
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1485
|
+
// Then check for blur
|
|
1486
|
+
const isBlurry = checkIfBlurOnCapture();
|
|
1487
|
+
if (isBlurry) {
|
|
1488
|
+
showVideoOverlay();
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1462
1491
|
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1492
|
+
// Both checks passed, show success border
|
|
1493
|
+
if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
|
|
1494
|
+
state.cropImgRef.showSuccessBorder();
|
|
1495
|
+
}
|
|
1467
1496
|
|
|
1468
|
-
|
|
1469
|
-
|
|
1497
|
+
// Only proceed with rendering if both checks pass
|
|
1498
|
+
hideVideoOverlay();
|
|
1470
1499
|
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
}
|
|
1500
|
+
// Create new check images component for each capture instead of checking if it exists
|
|
1501
|
+
checkImagesComponent = createCheckImages(state.container);
|
|
1474
1502
|
|
|
1475
|
-
|
|
1476
|
-
|
|
1503
|
+
try {
|
|
1504
|
+
const elements = await checkImagesComponent.renderCheckImages(state.frontImage, state.backImage, state.cropImgRef);
|
|
1505
|
+
if (state.isDocument && !state.blurStatus) {
|
|
1506
|
+
const zip = new JSZip();
|
|
1507
|
+
zip.file("front.jpg", state.frontImage, { base64: true });
|
|
1508
|
+
zip.file("back.jpg", state.backImage, { base64: true });
|
|
1509
|
+
const zipContent = await zip.generateAsync({ type: "base64" });
|
|
1510
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1511
|
+
state.captureBackOfCheck ? handleSubmit(zipContent) : handleSubmit(state.frontImage);
|
|
1477
1512
|
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
const zip = new JSZip();
|
|
1482
|
-
zip.file("front.jpg", state.frontImage, { base64: true });
|
|
1483
|
-
zip.file("back.jpg", state.backImage, { base64: true });
|
|
1484
|
-
const zipContent = await zip.generateAsync({ type: "base64" });
|
|
1485
|
-
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1486
|
-
state.captureBackOfCheck ? handleSubmit(zipContent) : handleSubmit(state.frontImage);
|
|
1487
|
-
|
|
1488
|
-
}, removeOverlay);
|
|
1489
|
-
state.enableSubmit && state.submitButton.show();
|
|
1490
|
-
}
|
|
1513
|
+
}, removeOverlay);
|
|
1514
|
+
state.enableSubmit && state.submitButton.show();
|
|
1515
|
+
}
|
|
1491
1516
|
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1517
|
+
// Call success handler with properly structured data
|
|
1518
|
+
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
1519
|
+
state.resultSetter({
|
|
1520
|
+
frontImage: state.frontImage,
|
|
1521
|
+
backImage: state.backImage
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
} catch (error) {
|
|
1525
|
+
console.error('Error rendering check images:', error);
|
|
1526
|
+
showVideoOverlay();
|
|
1527
|
+
}
|
|
1502
1528
|
}
|
|
1503
|
-
}
|
|
1504
1529
|
} catch (error) {
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1530
|
+
console.error('Error in captureChecks:', error);
|
|
1531
|
+
if (state.failureHandler && typeof state.failureHandler === 'function') {
|
|
1532
|
+
state.failureHandler(error);
|
|
1533
|
+
}
|
|
1534
|
+
showVideoOverlay();
|
|
1510
1535
|
}
|
|
1511
1536
|
};
|
|
1512
1537
|
|
|
@@ -1933,6 +1958,14 @@ const VeryfiLens = (function () {
|
|
|
1933
1958
|
switch (state.lensFlavor) {
|
|
1934
1959
|
case 'upload':
|
|
1935
1960
|
!state.fileUpload && (state.fileUpload = createFileUpload(state.container, captureUploaded, handleSubmit));
|
|
1961
|
+
// Add exit button for upload flavor
|
|
1962
|
+
if (state.exitButton) {
|
|
1963
|
+
createExitButton(state.container, {
|
|
1964
|
+
setter: state.onClose,
|
|
1965
|
+
redirectUrl: state.onCloseRedirectUrl,
|
|
1966
|
+
lensFlavor: state.lensFlavor,
|
|
1967
|
+
}, removeOverlay);
|
|
1968
|
+
}
|
|
1936
1969
|
break;
|
|
1937
1970
|
case 'credit_card':
|
|
1938
1971
|
renderCreditCardIfNeeded();
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
export const createCheckCapture = (container, captureChecks, successHandler) => {
|
|
2
|
-
const defaultStyles = {
|
|
3
|
-
containerDisplay: 'flex',
|
|
4
|
-
containerFlexDirection: 'column',
|
|
5
|
-
containerJustifyContent: 'center',
|
|
6
|
-
containerAlignItems: 'center',
|
|
7
|
-
containerWidth: '100%',
|
|
8
|
-
containerHeight: '100%',
|
|
9
|
-
containerOverflow: 'auto',
|
|
10
|
-
imageMaxWidth: '48%',
|
|
11
|
-
imageMaxHeight: '96%',
|
|
12
|
-
imageObjectFit: 'contain',
|
|
13
|
-
imageMargin: '1%'
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const imagesContainer = document.createElement('div');
|
|
17
|
-
imagesContainer.id = 'check-images-container';
|
|
18
|
-
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
19
|
-
const cssVar = `--check-capture-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
|
|
20
|
-
imagesContainer.style.setProperty(key, `var(${cssVar}, ${value})`);
|
|
21
|
-
});
|
|
22
|
-
container.appendChild(imagesContainer);
|
|
23
|
-
|
|
24
|
-
const createImageElement = (img, alt) => {
|
|
25
|
-
const imgElement = document.createElement('img');
|
|
26
|
-
imgElement.src = img.src;
|
|
27
|
-
imgElement.alt = alt;
|
|
28
|
-
imgElement.style.maxWidth = `var(--check-capture-image-max-width, ${defaultStyles.imageMaxWidth})`;
|
|
29
|
-
imgElement.style.maxHeight = `var(--check-capture-image-max-height, ${defaultStyles.imageMaxHeight})`;
|
|
30
|
-
imgElement.style.objectFit = `var(--check-capture-image-object-fit, ${defaultStyles.imageObjectFit})`;
|
|
31
|
-
imgElement.style.margin = `var(--check-capture-image-margin, ${defaultStyles.imageMargin})`;
|
|
32
|
-
return imgElement;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const displayImages = (frontImage, backImage) => {
|
|
36
|
-
imagesContainer.innerHTML = '';
|
|
37
|
-
const frontImg = new Image();
|
|
38
|
-
frontImg.onload = () => {
|
|
39
|
-
const backImg = new Image();
|
|
40
|
-
backImg.onload = () => {
|
|
41
|
-
const containerAspectRatio = container.clientWidth / container.clientHeight;
|
|
42
|
-
const frontAspectRatio = frontImg.width / frontImg.height;
|
|
43
|
-
const backAspectRatio = backImg.width / backImg.height;
|
|
44
|
-
|
|
45
|
-
const isPortrait = frontAspectRatio < containerAspectRatio && backAspectRatio < containerAspectRatio;
|
|
46
|
-
imagesContainer.style.flexDirection = isPortrait ? 'row' : 'column';
|
|
47
|
-
|
|
48
|
-
const frontImageElement = createImageElement(frontImg, 'Front of check');
|
|
49
|
-
const backImageElement = createImageElement(backImg, 'Back of check');
|
|
50
|
-
|
|
51
|
-
imagesContainer.appendChild(frontImageElement);
|
|
52
|
-
imagesContainer.appendChild(backImageElement);
|
|
53
|
-
|
|
54
|
-
successHandler({ frontImage, backImage });
|
|
55
|
-
};
|
|
56
|
-
backImg.src = `data:image/jpeg;base64,${backImage}`;
|
|
57
|
-
};
|
|
58
|
-
frontImg.src = `data:image/jpeg;base64,${frontImage}`;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
captureCheck: async (isCapturingFront, frontImage, backImage) => {
|
|
63
|
-
if (isCapturingFront) {
|
|
64
|
-
await captureChecks();
|
|
65
|
-
} else {
|
|
66
|
-
await captureChecks();
|
|
67
|
-
displayImages(frontImage, backImage);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
};
|