@capgo/camera-preview 8.14.0 → 8.14.2

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.
@@ -40,6 +40,20 @@ async function deleteFile(path) {
40
40
  return !!success;
41
41
  }
42
42
 
43
+ /** Source and destination rects for scaling a video frame into the capture canvas. */
44
+ function getWebCaptureImageDrawRects(videoWidth, videoHeight, captureWidth, captureHeight) {
45
+ return {
46
+ sx: 0,
47
+ sy: 0,
48
+ sWidth: videoWidth,
49
+ sHeight: videoHeight,
50
+ dx: 0,
51
+ dy: 0,
52
+ dWidth: captureWidth,
53
+ dHeight: captureHeight,
54
+ };
55
+ }
56
+
43
57
  const DEFAULT_VIDEO_ID = 'capgo_video';
44
58
  class CameraPreviewWeb extends core.WebPlugin {
45
59
  constructor() {
@@ -650,8 +664,6 @@ class CameraPreviewWeb extends core.WebPlugin {
650
664
  // Calculate capture dimensions
651
665
  let captureWidth = video.videoWidth;
652
666
  let captureHeight = video.videoHeight;
653
- const sourceX = 0;
654
- const sourceY = 0;
655
667
  // If width or height is specified, resize to fit within both maximums while maintaining aspect ratio
656
668
  if (options.width || options.height) {
657
669
  const originalAspectRatio = video.videoWidth / video.videoHeight;
@@ -690,7 +702,8 @@ class CameraPreviewWeb extends core.WebPlugin {
690
702
  context === null || context === void 0 ? void 0 : context.translate(captureWidth, 0);
691
703
  context === null || context === void 0 ? void 0 : context.scale(-1, 1);
692
704
  }
693
- context === null || context === void 0 ? void 0 : context.drawImage(video, sourceX, sourceY, captureWidth, captureHeight, 0, 0, captureWidth, captureHeight);
705
+ const { sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight } = getWebCaptureImageDrawRects(video.videoWidth, video.videoHeight, captureWidth, captureHeight);
706
+ context === null || context === void 0 ? void 0 : context.drawImage(video, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
694
707
  if (options.saveToGallery) ;
695
708
  if (options.withExifLocation) ;
696
709
  if ((options.format || 'jpeg') === 'jpeg') {