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