veryfi-lens-wasm 1.2.3 → 1.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/veryfi-lens.js +39 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "1.2.3",
3
+ "version": "1.2.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
@@ -636,14 +636,22 @@ const VeryfiLens = (function () {
636
636
  console.log(
637
637
  `Detector Result: ${detectorResult}, Documents Detected: ${nDocs}`
638
638
  );
639
- for (let i = 0; i < nDocs; i++) {
640
- const offset = i * 4;
641
- coordinates = [
642
- [corners[offset].x, corners[offset].y],
643
- [corners[offset + 1].x, corners[offset + 1].y],
644
- [corners[offset + 2].x, corners[offset + 2].y],
645
- [corners[offset + 3].x, corners[offset + 3].y],
646
- ];
639
+ if (nDocs > 0) {
640
+ for (let i = 0; i < nDocs; i++) {
641
+ const offset = i * 4;
642
+ const coordinates = [
643
+ [corners[offset].x, corners[offset].y],
644
+ [corners[offset + 1].x, corners[offset + 1].y],
645
+ [corners[offset + 2].x, corners[offset + 2].y],
646
+ [corners[offset + 3].x, corners[offset + 3].y],
647
+ ];
648
+
649
+ // Call drawContours with the obtained coordinates
650
+ drawContours(coordinates);
651
+ }
652
+ } else {
653
+ // No documents detected, clear the canvas
654
+ drawContours([]);
647
655
  }
648
656
  }
649
657
 
@@ -706,24 +714,34 @@ const VeryfiLens = (function () {
706
714
  const drawContours = (contours) => {
707
715
  const video = videoRef;
708
716
  const BoxCanvas = boxRef;
709
-
710
717
  if (video && BoxCanvas) {
711
718
  BoxCanvas.width = video.videoWidth;
712
719
  BoxCanvas.height = video.videoHeight;
713
720
  let ctx = BoxCanvas.getContext("2d");
714
721
 
715
722
  if (ctx) {
716
- ctx.save();
717
- ctx.beginPath();
718
- ctx.moveTo(contours[0][0], contours[0][1]);
719
- ctx.lineTo(contours[1][0], contours[1][1]);
720
- ctx.lineTo(contours[2][0], contours[2][1]);
721
- ctx.lineTo(contours[3][0], contours[3][1]);
722
- ctx.fillStyle = boxColor;
723
- ctx.fill();
724
- setCoordinates(contours);
725
- setHasCoordinates(true);
726
- ctx.restore();
723
+ // Clear the canvas before drawing new contours
724
+ ctx.clearRect(0, 0, BoxCanvas.width, BoxCanvas.height);
725
+
726
+ if (contours && contours.length === 4) {
727
+ ctx.save();
728
+ ctx.beginPath();
729
+ ctx.moveTo(contours[0][0], contours[0][1]);
730
+ ctx.lineTo(contours[1][0], contours[1][1]);
731
+ ctx.lineTo(contours[2][0], contours[2][1]);
732
+ ctx.lineTo(contours[3][0], contours[3][1]);
733
+ ctx.closePath(); // Close the path to complete the contour
734
+ ctx.fillStyle = boxColor;
735
+ ctx.fill();
736
+ setCoordinates(contours);
737
+ setHasCoordinates(true);
738
+ ctx.restore();
739
+ } else {
740
+ // Handle the case where no valid contours are provided
741
+ // Clear any previous coordinates
742
+ setCoordinates([]);
743
+ setHasCoordinates(false);
744
+ }
727
745
  }
728
746
  }
729
747
  };
@@ -1575,6 +1593,7 @@ const VeryfiLens = (function () {
1575
1593
  boxRef && boxRef.remove();
1576
1594
  cropImgRef && cropImgRef.remove();
1577
1595
  setIsDocument(false);
1596
+ // wasmWrapper.releaseCallback()
1578
1597
  },
1579
1598
 
1580
1599
  getDeviceData: async () => {