veryfi-lens-wasm 2.0.3 → 2.0.5

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.
@@ -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
- Oops, your image appears to be blurry
59
+ ${modalOptions.blurModalMessage.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
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
- Retake a picture
78
+ ${modalOptions.retakeButtonText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
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
- Submit anyway
97
+ ${modalOptions.submitButtonText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
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
- Oops, There appears to be no document on your image
64
+ ${modalOptions.noDocumentMessage.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
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
- Retake a picture
83
+ ${modalOptions.retakeButtonText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
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
- Submit anyway
102
+ ${modalOptions.submitButtonText.replace(/</g, '&lt;').replace(/>/g, '&gt;')}
94
103
  </p>
95
104
  </button>
96
105
  </div>
@@ -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
- button.style.right = '50px';
44
- button.style.botom = 'calc(20vh - 20px)';
45
- button.style.left = 'unset';
46
- button.style.top = 'unset';
47
- } else {
48
- // Apply default styles directly
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
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);
@@ -886,7 +896,7 @@ const VeryfiLens = (function () {
886
896
  if (state.torchButton) {
887
897
  state.torchButton = createTorchButton(state.videoOverlay.overlay, () => {
888
898
  toggleTorchLight();
889
- });
899
+ }, state.lensFlavor);
890
900
  }
891
901
  };
892
902
 
@@ -904,6 +914,11 @@ const VeryfiLens = (function () {
904
914
  lensFlavor: state.lensFlavor,
905
915
  }, removeOverlay);
906
916
  }
917
+ if (state.torchButton) {
918
+ state.torchButton = createTorchButton(state.cardOverlay.element, () => {
919
+ toggleTorchLight();
920
+ }, state.lensFlavor);
921
+ }
907
922
  }
908
923
 
909
924
  const renderModalsIfNeeded = () => {
@@ -922,6 +937,11 @@ const VeryfiLens = (function () {
922
937
  state.debug_mode && console.log("Submitting anyway");
923
938
  hideVideoOverlay();
924
939
  state.submitHandler && state.submitHandler(state.finalImage);
940
+ },
941
+ {
942
+ blurModalMessage: state.blurModalMessage,
943
+ retakeButtonText: state.retakeButtonText,
944
+ submitButtonText: state.submitButtonText
925
945
  }
926
946
  );
927
947
  }
@@ -939,6 +959,11 @@ const VeryfiLens = (function () {
939
959
  state.debug_mode && console.log("Submitting anyway");
940
960
  hideVideoOverlay();
941
961
  state.submitHandler && state.submitHandler(state.finalImage);
962
+ },
963
+ {
964
+ noDocumentMessage: state.documentModalMessage,
965
+ retakeButtonText: state.retakeButtonText,
966
+ submitButtonText: state.submitButtonText
942
967
  }
943
968
  );
944
969
  }
@@ -1365,148 +1390,137 @@ const VeryfiLens = (function () {
1365
1390
 
1366
1391
  const captureChecks = async () => {
1367
1392
  try {
1368
- if (state.isCapturingFront) {
1369
- state.frontImage = await cropWasm();
1370
- state.finalImage = state.frontImage;
1371
- stopLens();
1372
-
1373
- state.debug_mode && console.log("Front capture - Document detected:", state.isDocument);
1374
- const isDocumentDetected = checkIfDocumentOnCapture();
1375
- if (!isDocumentDetected) {
1376
- showVideoOverlay();
1377
- return;
1378
- }
1393
+ if (state.isCapturingFront) {
1394
+ state.frontImage = await cropWasm();
1395
+ state.finalImage = state.frontImage;
1396
+
1397
+ // Hide video and box elements temporarily
1398
+ if (state.videoRef) state.videoRef.style.display = 'none';
1399
+ if (state.boxRef) state.boxRef.style.display = 'none';
1400
+ if (state.frameRef) state.frameRef.style.display = 'none';
1401
+
1402
+ const isDocumentDetected = checkIfDocumentOnCapture();
1403
+ if (!isDocumentDetected) {
1404
+ showVideoOverlay();
1405
+ return;
1406
+ }
1379
1407
 
1380
- const isBlurry = checkIfBlurOnCapture();
1381
- if (isBlurry) {
1382
- showVideoOverlay();
1383
- return;
1384
- }
1408
+ const isBlurry = checkIfBlurOnCapture();
1409
+ if (isBlurry) {
1410
+ showVideoOverlay();
1411
+ return;
1412
+ }
1385
1413
 
1386
- // Both checks passed, show success border
1387
- if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
1388
- state.cropImgRef.showSuccessBorder();
1389
- }
1414
+ if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
1415
+ state.cropImgRef.showSuccessBorder();
1416
+ }
1390
1417
 
1391
- if (state.captureBackOfCheck) {
1392
- const checkCaptureModal = createCheckCaptureModal(
1393
- state.container,
1394
- state.finalImage,
1395
- () => {
1396
- // Reset border and clear canvas before starting back capture
1397
- if (state.cropImgRef) {
1398
- state.cropImgRef.hideBorder();
1399
- const ctx = state.cropImgRef.getContext("2d");
1400
- if (ctx) {
1401
- ctx.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
1402
- }
1403
- }
1404
- newStartLens(state.lensFlavor);
1405
- },
1406
- () => {
1407
- // Handle "No" click
1408
- hideVideoOverlay();
1409
- if (state.isDocument && !state.blurStatus) {
1410
- state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1411
- handleSubmit(state.frontImage);
1412
- }, removeOverlay);
1413
- state.enableSubmit && state.submitButton.show();
1414
- }
1415
- // Call success handler with front image only
1416
- if (state.resultSetter && typeof state.resultSetter === 'function') {
1417
- state.resultSetter({
1418
- frontImage: state.frontImage
1419
- });
1420
- }
1418
+ if (state.captureBackOfCheck) {
1419
+ const checkCaptureModal = createCheckCaptureModal(
1420
+ state.container,
1421
+ state.finalImage,
1422
+ () => {
1423
+ // "Yes" click handler
1424
+ // Show video elements again
1425
+ if (state.videoRef) state.videoRef.style.display = 'block';
1426
+ if (state.boxRef) state.boxRef.style.display = 'block';
1427
+ if (state.frameRef) state.frameRef.style.display = 'block';
1428
+
1429
+ // Reset border and clear canvas
1430
+ if (state.cropImgRef) {
1431
+ state.cropImgRef.hideBorder();
1432
+ const ctx = state.cropImgRef.getContext("2d");
1433
+ if (ctx) {
1434
+ ctx.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
1435
+ }
1436
+ }
1437
+ newStartLens(state.lensFlavor);
1438
+ },
1439
+ () => {
1440
+ // "No" click handler
1441
+ hideVideoOverlay();
1442
+ if (state.isDocument && !state.blurStatus) {
1443
+ state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1444
+ handleSubmit(state.frontImage);
1445
+ }, removeOverlay);
1446
+ state.enableSubmit && state.submitButton.show();
1447
+ }
1448
+ if (state.resultSetter && typeof state.resultSetter === 'function') {
1449
+ state.resultSetter({
1450
+ frontImage: state.frontImage
1451
+ });
1452
+ }
1453
+ }
1454
+ );
1455
+ checkCaptureModal.show();
1456
+ state.isCapturingFront = false;
1457
+ state.updateHandler && state.updateHandler({ status: 'capture_back_side' });
1421
1458
  }
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
1459
 
1442
- } else {
1443
- state.backImage = await cropWasm();
1460
+ } else {
1461
+ state.backImage = await cropWasm();
1444
1462
 
1445
- state.debug_mode && console.log("Back capture - Document detected:", state.isDocument);
1446
- // Check for document first
1447
- const isDocumentDetected = checkIfDocumentOnCapture();
1448
- state.debug_mode && console.log("Back capture - Document check result:", isDocumentDetected);
1463
+ state.debug_mode && console.log("Back capture - Document detected:", state.isDocument);
1464
+ // Check for document first
1465
+ const isDocumentDetected = checkIfDocumentOnCapture();
1466
+ state.debug_mode && console.log("Back capture - Document check result:", isDocumentDetected);
1449
1467
 
1450
- if (!isDocumentDetected) {
1451
- state.debug_mode && console.log("Back capture - No document detected, showing video overlay");
1452
- showVideoOverlay();
1453
- return;
1454
- }
1468
+ if (!isDocumentDetected) {
1469
+ state.debug_mode && console.log("Back capture - No document detected, showing video overlay");
1470
+ showVideoOverlay();
1471
+ return;
1472
+ }
1455
1473
 
1456
- // Then check for blur
1457
- const isBlurry = checkIfBlurOnCapture();
1458
- if (isBlurry) {
1459
- showVideoOverlay();
1460
- return;
1461
- }
1474
+ // Then check for blur
1475
+ const isBlurry = checkIfBlurOnCapture();
1476
+ if (isBlurry) {
1477
+ showVideoOverlay();
1478
+ return;
1479
+ }
1462
1480
 
1463
- // Both checks passed, show success border
1464
- if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
1465
- state.cropImgRef.showSuccessBorder();
1466
- }
1481
+ // Both checks passed, show success border
1482
+ if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
1483
+ state.cropImgRef.showSuccessBorder();
1484
+ }
1467
1485
 
1468
- // Only proceed with rendering if both checks pass
1469
- hideVideoOverlay();
1486
+ // Only proceed with rendering if both checks pass
1487
+ hideVideoOverlay();
1470
1488
 
1471
- if (!checkImagesComponent) {
1472
- checkImagesComponent = createCheckImages(state.container);
1473
- }
1489
+ // Create new check images component for each capture instead of checking if it exists
1490
+ checkImagesComponent = createCheckImages(state.container);
1474
1491
 
1475
-
1476
-
1492
+ try {
1493
+ const elements = await checkImagesComponent.renderCheckImages(state.frontImage, state.backImage, state.cropImgRef);
1494
+ if (state.isDocument && !state.blurStatus) {
1495
+ const zip = new JSZip();
1496
+ zip.file("front.jpg", state.frontImage, { base64: true });
1497
+ zip.file("back.jpg", state.backImage, { base64: true });
1498
+ const zipContent = await zip.generateAsync({ type: "base64" });
1499
+ state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1500
+ state.captureBackOfCheck ? handleSubmit(zipContent) : handleSubmit(state.frontImage);
1477
1501
 
1478
- try {
1479
- const elements = await checkImagesComponent.renderCheckImages(state.frontImage, state.backImage, state.cropImgRef);
1480
- if (state.isDocument && !state.blurStatus) {
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
- }
1502
+ }, removeOverlay);
1503
+ state.enableSubmit && state.submitButton.show();
1504
+ }
1491
1505
 
1492
- // Call success handler with properly structured data
1493
- if (state.resultSetter && typeof state.resultSetter === 'function') {
1494
- state.resultSetter({
1495
- frontImage: state.frontImage,
1496
- backImage: state.backImage
1497
- });
1498
- }
1499
- } catch (error) {
1500
- console.error('Error rendering check images:', error);
1501
- showVideoOverlay();
1506
+ // Call success handler with properly structured data
1507
+ if (state.resultSetter && typeof state.resultSetter === 'function') {
1508
+ state.resultSetter({
1509
+ frontImage: state.frontImage,
1510
+ backImage: state.backImage
1511
+ });
1512
+ }
1513
+ } catch (error) {
1514
+ console.error('Error rendering check images:', error);
1515
+ showVideoOverlay();
1516
+ }
1502
1517
  }
1503
- }
1504
1518
  } catch (error) {
1505
- console.error('Error in captureChecks:', error);
1506
- if (state.failureHandler && typeof state.failureHandler === 'function') {
1507
- state.failureHandler(error);
1508
- }
1509
- showVideoOverlay();
1519
+ console.error('Error in captureChecks:', error);
1520
+ if (state.failureHandler && typeof state.failureHandler === 'function') {
1521
+ state.failureHandler(error);
1522
+ }
1523
+ showVideoOverlay();
1510
1524
  }
1511
1525
  };
1512
1526
 
@@ -1933,6 +1947,14 @@ const VeryfiLens = (function () {
1933
1947
  switch (state.lensFlavor) {
1934
1948
  case 'upload':
1935
1949
  !state.fileUpload && (state.fileUpload = createFileUpload(state.container, captureUploaded, handleSubmit));
1950
+ // Add exit button for upload flavor
1951
+ if (state.exitButton) {
1952
+ createExitButton(state.container, {
1953
+ setter: state.onClose,
1954
+ redirectUrl: state.onCloseRedirectUrl,
1955
+ lensFlavor: state.lensFlavor,
1956
+ }, removeOverlay);
1957
+ }
1936
1958
  break;
1937
1959
  case 'credit_card':
1938
1960
  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
- };