veryfi-lens-wasm 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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%';
@@ -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.4",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
package/veryfi-lens.js CHANGED
@@ -179,20 +179,23 @@ const VeryfiLens = (function () {
179
179
  const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
180
180
 
181
181
  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
- } : {
182
+ ...(isMobile && lensFlavor === 'long_document' ? {
183
+ width: { ideal: 1920 },
184
+ height: { ideal: 1080 }
185
+ } : isMobile ? {
186
+ width: { ideal: 2440 }, // Also reduced for other mobile cases
187
+ height: { ideal: 1080 }
188
+ } : state.fullScreenEnabled ? {
189
189
  width: { ideal: 1920 },
190
- height: { ideal: 1080 },
190
+ height: { ideal: 1080 }
191
+ } : {
192
+ width: { ideal: 3840 },
193
+ height: { ideal: 2160 }
191
194
  }),
192
195
  facingMode: "environment",
193
- advanced: [{ torch: true }],
196
+ advanced: [{ torch: true }]
194
197
  };
195
- console.log(videoConfig);
198
+ state.debug_mode && console.log("video config", videoConfig);
196
199
 
197
200
  if (isAndroid) {
198
201
  try {
@@ -201,6 +204,7 @@ const VeryfiLens = (function () {
201
204
  const mainCameraDevice = videoDevices.find(device => device.label.includes("camera2 0"));
202
205
  if (mainCameraDevice) {
203
206
  videoConfig.deviceId = { exact: mainCameraDevice.deviceId };
207
+ console.log("mainCameraDevice", mainCameraDevice);
204
208
  }
205
209
  } catch (error) {
206
210
  console.error("Error enumerating devices", error);
@@ -395,6 +399,7 @@ const VeryfiLens = (function () {
395
399
  createImageBitmap(state.fullSizeImage).then((bitmap) => {
396
400
  if (wasmWrapper && typeof wasmWrapper.processDocument === 'function') {
397
401
  wasmWrapper.processDocument(bitmap, mode);
402
+
398
403
  rCorners = state.coordinates.map((corner) => corner);
399
404
  if (
400
405
  rCorners.length &&
@@ -413,6 +418,7 @@ const VeryfiLens = (function () {
413
418
  state.image = imgString;
414
419
  }
415
420
  }
421
+ bitmap.close();
416
422
  });
417
423
  } catch (error) {
418
424
  console.log(error);
@@ -886,7 +892,7 @@ const VeryfiLens = (function () {
886
892
  if (state.torchButton) {
887
893
  state.torchButton = createTorchButton(state.videoOverlay.overlay, () => {
888
894
  toggleTorchLight();
889
- });
895
+ }, state.lensFlavor);
890
896
  }
891
897
  };
892
898
 
@@ -904,6 +910,11 @@ const VeryfiLens = (function () {
904
910
  lensFlavor: state.lensFlavor,
905
911
  }, removeOverlay);
906
912
  }
913
+ if (state.torchButton) {
914
+ state.torchButton = createTorchButton(state.cardOverlay.element, () => {
915
+ toggleTorchLight();
916
+ }, state.lensFlavor);
917
+ }
907
918
  }
908
919
 
909
920
  const renderModalsIfNeeded = () => {
@@ -1365,148 +1376,137 @@ const VeryfiLens = (function () {
1365
1376
 
1366
1377
  const captureChecks = async () => {
1367
1378
  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
- }
1379
+ if (state.isCapturingFront) {
1380
+ state.frontImage = await cropWasm();
1381
+ state.finalImage = state.frontImage;
1382
+
1383
+ // Hide video and box elements temporarily
1384
+ if (state.videoRef) state.videoRef.style.display = 'none';
1385
+ if (state.boxRef) state.boxRef.style.display = 'none';
1386
+ if (state.frameRef) state.frameRef.style.display = 'none';
1387
+
1388
+ const isDocumentDetected = checkIfDocumentOnCapture();
1389
+ if (!isDocumentDetected) {
1390
+ showVideoOverlay();
1391
+ return;
1392
+ }
1379
1393
 
1380
- const isBlurry = checkIfBlurOnCapture();
1381
- if (isBlurry) {
1382
- showVideoOverlay();
1383
- return;
1384
- }
1394
+ const isBlurry = checkIfBlurOnCapture();
1395
+ if (isBlurry) {
1396
+ showVideoOverlay();
1397
+ return;
1398
+ }
1385
1399
 
1386
- // Both checks passed, show success border
1387
- if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
1388
- state.cropImgRef.showSuccessBorder();
1389
- }
1400
+ if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
1401
+ state.cropImgRef.showSuccessBorder();
1402
+ }
1390
1403
 
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
- }
1404
+ if (state.captureBackOfCheck) {
1405
+ const checkCaptureModal = createCheckCaptureModal(
1406
+ state.container,
1407
+ state.finalImage,
1408
+ () => {
1409
+ // "Yes" click handler
1410
+ // Show video elements again
1411
+ if (state.videoRef) state.videoRef.style.display = 'block';
1412
+ if (state.boxRef) state.boxRef.style.display = 'block';
1413
+ if (state.frameRef) state.frameRef.style.display = 'block';
1414
+
1415
+ // Reset border and clear canvas
1416
+ if (state.cropImgRef) {
1417
+ state.cropImgRef.hideBorder();
1418
+ const ctx = state.cropImgRef.getContext("2d");
1419
+ if (ctx) {
1420
+ ctx.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
1421
+ }
1422
+ }
1423
+ newStartLens(state.lensFlavor);
1424
+ },
1425
+ () => {
1426
+ // "No" click handler
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
+ if (state.resultSetter && typeof state.resultSetter === 'function') {
1435
+ state.resultSetter({
1436
+ frontImage: state.frontImage
1437
+ });
1438
+ }
1439
+ }
1440
+ );
1441
+ checkCaptureModal.show();
1442
+ state.isCapturingFront = false;
1443
+ state.updateHandler && state.updateHandler({ status: 'capture_back_side' });
1421
1444
  }
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
1445
 
1442
- } else {
1443
- state.backImage = await cropWasm();
1446
+ } else {
1447
+ state.backImage = await cropWasm();
1444
1448
 
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);
1449
+ state.debug_mode && console.log("Back capture - Document detected:", state.isDocument);
1450
+ // Check for document first
1451
+ const isDocumentDetected = checkIfDocumentOnCapture();
1452
+ state.debug_mode && console.log("Back capture - Document check result:", isDocumentDetected);
1449
1453
 
1450
- if (!isDocumentDetected) {
1451
- state.debug_mode && console.log("Back capture - No document detected, showing video overlay");
1452
- showVideoOverlay();
1453
- return;
1454
- }
1454
+ if (!isDocumentDetected) {
1455
+ state.debug_mode && console.log("Back capture - No document detected, showing video overlay");
1456
+ showVideoOverlay();
1457
+ return;
1458
+ }
1455
1459
 
1456
- // Then check for blur
1457
- const isBlurry = checkIfBlurOnCapture();
1458
- if (isBlurry) {
1459
- showVideoOverlay();
1460
- return;
1461
- }
1460
+ // Then check for blur
1461
+ const isBlurry = checkIfBlurOnCapture();
1462
+ if (isBlurry) {
1463
+ showVideoOverlay();
1464
+ return;
1465
+ }
1462
1466
 
1463
- // Both checks passed, show success border
1464
- if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
1465
- state.cropImgRef.showSuccessBorder();
1466
- }
1467
+ // Both checks passed, show success border
1468
+ if (state.cropImgRef && typeof state.cropImgRef.showSuccessBorder === 'function') {
1469
+ state.cropImgRef.showSuccessBorder();
1470
+ }
1467
1471
 
1468
- // Only proceed with rendering if both checks pass
1469
- hideVideoOverlay();
1472
+ // Only proceed with rendering if both checks pass
1473
+ hideVideoOverlay();
1470
1474
 
1471
- if (!checkImagesComponent) {
1472
- checkImagesComponent = createCheckImages(state.container);
1473
- }
1475
+ // Create new check images component for each capture instead of checking if it exists
1476
+ checkImagesComponent = createCheckImages(state.container);
1474
1477
 
1475
-
1476
-
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);
1477
1487
 
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
- }
1488
+ }, removeOverlay);
1489
+ state.enableSubmit && state.submitButton.show();
1490
+ }
1491
1491
 
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();
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();
1502
+ }
1502
1503
  }
1503
- }
1504
1504
  } catch (error) {
1505
- console.error('Error in captureChecks:', error);
1506
- if (state.failureHandler && typeof state.failureHandler === 'function') {
1507
- state.failureHandler(error);
1508
- }
1509
- showVideoOverlay();
1505
+ console.error('Error in captureChecks:', error);
1506
+ if (state.failureHandler && typeof state.failureHandler === 'function') {
1507
+ state.failureHandler(error);
1508
+ }
1509
+ showVideoOverlay();
1510
1510
  }
1511
1511
  };
1512
1512
 
@@ -1933,6 +1933,14 @@ const VeryfiLens = (function () {
1933
1933
  switch (state.lensFlavor) {
1934
1934
  case 'upload':
1935
1935
  !state.fileUpload && (state.fileUpload = createFileUpload(state.container, captureUploaded, handleSubmit));
1936
+ // Add exit button for upload flavor
1937
+ if (state.exitButton) {
1938
+ createExitButton(state.container, {
1939
+ setter: state.onClose,
1940
+ redirectUrl: state.onCloseRedirectUrl,
1941
+ lensFlavor: state.lensFlavor,
1942
+ }, removeOverlay);
1943
+ }
1936
1944
  break;
1937
1945
  case 'credit_card':
1938
1946
  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
- };