@capgo/camera-preview 7.4.0-beta.16 → 7.4.0-beta.18

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/README.md CHANGED
@@ -725,15 +725,15 @@ Represents EXIF data extracted from an image.
725
725
 
726
726
  Defines the options for capturing a picture.
727
727
 
728
- | Prop | Type | Description | Default | Since |
729
- | ---------------------- | ------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ----- |
730
- | **`height`** | <code>number</code> | The desired height of the picture in pixels. If not provided, the device default is used. | | |
731
- | **`width`** | <code>number</code> | The desired width of the picture in pixels. If not provided, the device default is used. | | |
732
- | **`aspectRatio`** | <code>string</code> | The desired aspect ratio of the captured image (e.g., '4:3', '16:9'). If specified without width/height, captures the largest possible image with this ratio. Cannot be used together with width or height - the capture will be rejected with an error. | | 7.7.0 |
733
- | **`quality`** | <code>number</code> | The quality of the captured image, from 0 to 100. Does not apply to `png` format. | <code>85</code> | |
734
- | **`format`** | <code><a href="#pictureformat">PictureFormat</a></code> | The format of the captured image. | <code>"jpeg"</code> | |
735
- | **`saveToGallery`** | <code>boolean</code> | If true, the captured image will be saved to the user's gallery. | <code>false</code> | 7.5.0 |
736
- | **`withExifLocation`** | <code>boolean</code> | If true, the plugin will attempt to add GPS location data to the image's EXIF metadata. This may prompt the user for location permissions. | <code>false</code> | 7.6.0 |
728
+ | Prop | Type | Description | Default | Since |
729
+ | ---------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------- | ----- |
730
+ | **`height`** | <code>number</code> | | | |
731
+ | **`width`** | <code>number</code> | | | |
732
+ | **`aspectRatio`** | <code>string</code> | | | 7.7.0 |
733
+ | **`quality`** | <code>number</code> | The quality of the captured image, from 0 to 100. Does not apply to `png` format. | <code>85</code> | |
734
+ | **`format`** | <code><a href="#pictureformat">PictureFormat</a></code> | The format of the captured image. | <code>"jpeg"</code> | |
735
+ | **`saveToGallery`** | <code>boolean</code> | If true, the captured image will be saved to the user's gallery. | <code>false</code> | 7.5.0 |
736
+ | **`withExifLocation`** | <code>boolean</code> | If true, the plugin will attempt to add GPS location data to the image's EXIF metadata. This may prompt the user for location permissions. | <code>false</code> | 7.6.0 |
737
737
 
738
738
 
739
739
  #### CameraSampleOptions
@@ -360,6 +360,14 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
360
360
  Log.d(TAG, "setupPreviewView: Setting grid mode to: " + currentGridMode);
361
361
  gridOverlayView.setGridMode(currentGridMode);
362
362
  });
363
+
364
+ // Add a layout listener to update grid bounds when preview view changes size
365
+ previewView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
366
+ if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
367
+ Log.d(TAG, "PreviewView layout changed, updating grid bounds");
368
+ updateGridOverlayBounds();
369
+ }
370
+ });
363
371
 
364
372
  ViewGroup parent = (ViewGroup) webView.getParent();
365
373
  if (parent != null) {
@@ -738,6 +746,9 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
738
746
  actualHeight
739
747
  );
740
748
 
749
+ // Update grid overlay bounds after camera is started
750
+ updateGridOverlayBounds();
751
+
741
752
  listener.onCameraStarted(
742
753
  actualWidth,
743
754
  actualHeight,
@@ -827,7 +838,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
827
838
  String aspectRatio,
828
839
  Location location
829
840
  ) {
830
- Log.d(TAG, "capturePhoto: Starting photo capture with quality: " + quality + ", aspectRatio: " + aspectRatio);
841
+ Log.d(TAG, "capturePhoto: Starting photo capture with quality: " + quality + ", width: " + width + ", height: " + height + ", aspectRatio: " + aspectRatio);
831
842
 
832
843
  // Check for conflicting parameters
833
844
  if (aspectRatio != null && (width != null || height != null)) {
@@ -883,15 +894,26 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
883
894
 
884
895
  JSONObject exifData = getExifData(exifInterface);
885
896
 
897
+ // Use the stored aspectRatio if none is provided and no width/height is specified
898
+ String captureAspectRatio = aspectRatio;
899
+ if (width == null && height == null && aspectRatio == null && sessionConfig != null) {
900
+ captureAspectRatio = sessionConfig.getAspectRatio();
901
+ // Default to "4:3" if no aspect ratio was set at all
902
+ if (captureAspectRatio == null) {
903
+ captureAspectRatio = "4:3";
904
+ }
905
+ Log.d(TAG, "capturePhoto: Using stored aspectRatio: " + captureAspectRatio);
906
+ }
907
+
886
908
  // Handle aspect ratio if no width/height specified
887
- if (width == null && height == null && aspectRatio != null && !aspectRatio.isEmpty()) {
909
+ if (width == null && height == null && captureAspectRatio != null && !captureAspectRatio.isEmpty()) {
888
910
  // Get the original image dimensions
889
911
  Bitmap originalBitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
890
912
  int originalWidth = originalBitmap.getWidth();
891
913
  int originalHeight = originalBitmap.getHeight();
892
914
 
893
915
  // Parse aspect ratio
894
- String[] ratios = aspectRatio.split(":");
916
+ String[] ratios = captureAspectRatio.split(":");
895
917
  if (ratios.length == 2) {
896
918
  try {
897
919
  float widthRatio = Float.parseFloat(ratios[0]);
@@ -936,7 +958,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
936
958
  originalBitmap.recycle();
937
959
  croppedBitmap.recycle();
938
960
  } catch (NumberFormatException e) {
939
- Log.e(TAG, "Invalid aspect ratio format: " + aspectRatio, e);
961
+ Log.e(TAG, "Invalid aspect ratio format: " + captureAspectRatio, e);
940
962
  }
941
963
  }
942
964
  } else if (width != null && height != null) {
@@ -2621,19 +2643,30 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2621
2643
 
2622
2644
  // Wait for camera rebinding to complete, then call callback
2623
2645
  if (callback != null) {
2624
- previewContainer.post(() -> previewContainer.post(callback));
2646
+ previewContainer.post(() -> {
2647
+ updateGridOverlayBounds();
2648
+ previewContainer.post(callback);
2649
+ });
2650
+ } else {
2651
+ previewContainer.post(() -> updateGridOverlayBounds());
2625
2652
  }
2626
2653
  } else {
2627
2654
  // No camera rebinding needed, wait for layout to complete then call callback
2628
- if (callback != null) {
2629
- previewContainer.post(callback);
2630
- }
2655
+ previewContainer.post(() -> {
2656
+ updateGridOverlayBounds();
2657
+ if (callback != null) {
2658
+ callback.run();
2659
+ }
2660
+ });
2631
2661
  }
2632
2662
  } else {
2633
2663
  // No sessionConfig, just wait for layout then call callback
2634
- if (callback != null) {
2635
- previewContainer.post(callback);
2636
- }
2664
+ previewContainer.post(() -> {
2665
+ updateGridOverlayBounds();
2666
+ if (callback != null) {
2667
+ callback.run();
2668
+ }
2669
+ });
2637
2670
  }
2638
2671
  } else {
2639
2672
  Log.w(
@@ -2772,6 +2805,9 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2772
2805
  finalY +
2773
2806
  ")"
2774
2807
  );
2808
+
2809
+ // Update grid overlay bounds after aspect ratio change
2810
+ previewContainer.post(() -> updateGridOverlayBounds());
2775
2811
  }
2776
2812
  } catch (NumberFormatException e) {
2777
2813
  Log.e(TAG, "Invalid aspect ratio format: " + aspectRatio, e);
@@ -2842,6 +2878,22 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2842
2878
  return new int[] { x, y, width, height };
2843
2879
  }
2844
2880
 
2881
+ private void updateGridOverlayBounds() {
2882
+ if (gridOverlayView != null && previewView != null) {
2883
+ // Get the actual camera bounds
2884
+ Rect cameraBounds = getActualCameraBounds();
2885
+
2886
+ // Update the grid overlay with the camera bounds
2887
+ gridOverlayView.setCameraBounds(cameraBounds);
2888
+
2889
+ Log.d(
2890
+ TAG,
2891
+ "updateGridOverlayBounds: Updated grid bounds to " +
2892
+ cameraBounds.toString()
2893
+ );
2894
+ }
2895
+ }
2896
+
2845
2897
  private void triggerAutoFocus() {
2846
2898
  if (camera == null) {
2847
2899
  return;
@@ -3,6 +3,7 @@ package com.ahm.capacitor.camera.preview;
3
3
  import android.content.Context;
4
4
  import android.graphics.Canvas;
5
5
  import android.graphics.Paint;
6
+ import android.graphics.Rect;
6
7
  import android.util.AttributeSet;
7
8
  import android.view.View;
8
9
 
@@ -10,6 +11,7 @@ public class GridOverlayView extends View {
10
11
 
11
12
  private Paint gridPaint;
12
13
  private String gridMode = "none";
14
+ private Rect cameraBounds = null;
13
15
 
14
16
  public GridOverlayView(Context context) {
15
17
  super(context);
@@ -38,6 +40,11 @@ public class GridOverlayView extends View {
38
40
  gridPaint.setAntiAlias(true);
39
41
  }
40
42
 
43
+ public void setCameraBounds(Rect bounds) {
44
+ this.cameraBounds = bounds;
45
+ invalidate();
46
+ }
47
+
41
48
  public void setGridMode(String mode) {
42
49
  String previousMode = this.gridMode;
43
50
  this.gridMode = mode != null ? mode : "none";
@@ -62,34 +69,44 @@ public class GridOverlayView extends View {
62
69
  return;
63
70
  }
64
71
 
72
+ // Use camera bounds if available, otherwise use full view bounds
73
+ int left = 0;
74
+ int top = 0;
65
75
  int width = getWidth();
66
76
  int height = getHeight();
67
77
 
78
+ if (cameraBounds != null) {
79
+ left = cameraBounds.left;
80
+ top = cameraBounds.top;
81
+ width = cameraBounds.width();
82
+ height = cameraBounds.height();
83
+ }
84
+
68
85
  if (width <= 0 || height <= 0) {
69
86
  return;
70
87
  }
71
88
 
72
89
  if ("3x3".equals(gridMode)) {
73
- drawGrid(canvas, width, height, 3);
90
+ drawGrid(canvas, left, top, width, height, 3);
74
91
  } else if ("4x4".equals(gridMode)) {
75
- drawGrid(canvas, width, height, 4);
92
+ drawGrid(canvas, left, top, width, height, 4);
76
93
  }
77
94
  }
78
95
 
79
- private void drawGrid(Canvas canvas, int width, int height, int divisions) {
96
+ private void drawGrid(Canvas canvas, int left, int top, int width, int height, int divisions) {
80
97
  float stepX = (float) width / divisions;
81
98
  float stepY = (float) height / divisions;
82
99
 
83
100
  // Draw vertical lines
84
101
  for (int i = 1; i < divisions; i++) {
85
- float x = i * stepX;
86
- canvas.drawLine(x, 0, x, height, gridPaint);
102
+ float x = left + (i * stepX);
103
+ canvas.drawLine(x, top, x, top + height, gridPaint);
87
104
  }
88
105
 
89
106
  // Draw horizontal lines
90
107
  for (int i = 1; i < divisions; i++) {
91
- float y = i * stepY;
92
- canvas.drawLine(0, y, width, y, gridPaint);
108
+ float y = top + (i * stepY);
109
+ canvas.drawLine(left, y, left + width, y, gridPaint);
93
110
  }
94
111
  }
95
112
  }
package/dist/docs.json CHANGED
@@ -994,27 +994,41 @@
994
994
  "properties": [
995
995
  {
996
996
  "name": "height",
997
- "tags": [],
998
- "docs": "The desired height of the picture in pixels. If not provided, the device default is used.",
997
+ "tags": [
998
+ {
999
+ "text": ",\nThe desired height of the picture in pixels. \nIf not specified and no aspectRatio is provided, the captured image will match the preview's visible area.",
1000
+ "name": "deprecated"
1001
+ }
1002
+ ],
1003
+ "docs": "",
999
1004
  "complexTypes": [],
1000
1005
  "type": "number | undefined"
1001
1006
  },
1002
1007
  {
1003
1008
  "name": "width",
1004
- "tags": [],
1005
- "docs": "The desired width of the picture in pixels. If not provided, the device default is used.",
1009
+ "tags": [
1010
+ {
1011
+ "text": ",\nThe desired width of the picture in pixels. \nIf not specified and no aspectRatio is provided, the captured image will match the preview's visible area.",
1012
+ "name": "deprecated"
1013
+ }
1014
+ ],
1015
+ "docs": "",
1006
1016
  "complexTypes": [],
1007
1017
  "type": "number | undefined"
1008
1018
  },
1009
1019
  {
1010
1020
  "name": "aspectRatio",
1011
1021
  "tags": [
1022
+ {
1023
+ "text": ",\nThe desired aspect ratio of the captured image (e.g., '4:3', '16:9').\nIf not specified and no width/height is provided, the aspect ratio from the camera start will be used.\nIf no aspect ratio was set at start, defaults to '4:3'.\nCannot be used together with width or height - the capture will be rejected with an error.",
1024
+ "name": "deprecated"
1025
+ },
1012
1026
  {
1013
1027
  "text": "7.7.0",
1014
1028
  "name": "since"
1015
1029
  }
1016
1030
  ],
1017
- "docs": "The desired aspect ratio of the captured image (e.g., '4:3', '16:9').\nIf specified without width/height, captures the largest possible image with this ratio.\nCannot be used together with width or height - the capture will be rejected with an error.",
1031
+ "docs": "",
1018
1032
  "complexTypes": [],
1019
1033
  "type": "string | undefined"
1020
1034
  },
@@ -194,13 +194,20 @@ export interface CameraPreviewOptions {
194
194
  * Defines the options for capturing a picture.
195
195
  */
196
196
  export interface CameraPreviewPictureOptions {
197
- /** The desired height of the picture in pixels. If not provided, the device default is used. */
197
+ /** @deprecated,
198
+ * The desired height of the picture in pixels.
199
+ * If not specified and no aspectRatio is provided, the captured image will match the preview's visible area.
200
+ */
198
201
  height?: number;
199
- /** The desired width of the picture in pixels. If not provided, the device default is used. */
202
+ /** @deprecated,
203
+ * The desired width of the picture in pixels.
204
+ * If not specified and no aspectRatio is provided, the captured image will match the preview's visible area.
205
+ */
200
206
  width?: number;
201
- /**
207
+ /** @deprecated,
202
208
  * The desired aspect ratio of the captured image (e.g., '4:3', '16:9').
203
- * If specified without width/height, captures the largest possible image with this ratio.
209
+ * If not specified and no width/height is provided, the aspect ratio from the camera start will be used.
210
+ * If no aspect ratio was set at start, defaults to '4:3'.
204
211
  * Cannot be used together with width or height - the capture will be rejected with an error.
205
212
  * @since 7.7.0
206
213
  */
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,sCAAwB,CAAA;IACxB,sCAAwB,CAAA;IACxB,qCAAuB,CAAA;IACvB,sCAAwB,CAAA;IACxB,2BAAa,CAAA;IACb,oCAAsB,CAAA;IACtB,+BAAiB,CAAA;AACnB,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB","sourcesContent":["export type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport enum DeviceType {\n ULTRA_WIDE = \"ultraWide\",\n WIDE_ANGLE = \"wideAngle\",\n TELEPHOTO = \"telephoto\",\n TRUE_DEPTH = \"trueDepth\",\n DUAL = \"dual\",\n DUAL_WIDE = \"dualWide\",\n TRIPLE = \"triple\",\n}\n\n/**\n * Represents a single camera lens on a device. A {@link CameraDevice} can have multiple lenses.\n */\nexport interface CameraLens {\n /** A human-readable name for the lens, e.g., \"Ultra-Wide\". */\n label: string;\n /** The type of the camera lens. */\n deviceType: DeviceType;\n /** The focal length of the lens in millimeters. */\n focalLength: number;\n /** The base zoom factor for this lens (e.g., 0.5 for ultra-wide, 1.0 for wide). */\n baseZoomRatio: number;\n /** The minimum zoom factor supported by this specific lens. */\n minZoom: number;\n /** The maximum zoom factor supported by this specific lens. */\n maxZoom: number;\n}\n\n/**\n * Represents a physical camera on the device (e.g., the front-facing camera).\n */\nexport interface CameraDevice {\n /** A unique identifier for the camera device. */\n deviceId: string;\n /** A human-readable name for the camera device. */\n label: string;\n /** The physical position of the camera on the device. */\n position: CameraPosition;\n /** A list of all available lenses for this camera device. */\n lenses: CameraLens[];\n /** The overall minimum zoom factor available across all lenses on this device. */\n minZoom: number;\n /** The overall maximum zoom factor available across all lenses on this device. */\n maxZoom: number;\n /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */\n isLogical: boolean;\n}\n\n/**\n * Represents the detailed information of the currently active lens.\n */\nexport interface LensInfo {\n /** The focal length of the active lens in millimeters. */\n focalLength: number;\n /** The device type of the active lens. */\n deviceType: DeviceType;\n /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */\n baseZoomRatio: number;\n /** The current digital zoom factor applied on top of the base zoom. */\n digitalZoom: number;\n}\n\n/**\n * Defines the configuration options for starting the camera preview.\n */\nexport interface CameraPreviewOptions {\n /**\n * The parent element to attach the video preview to.\n * @platform web\n */\n parent?: string;\n /**\n * A CSS class name to add to the preview element.\n * @platform web\n */\n className?: string;\n /**\n * The width of the preview in pixels. Defaults to the screen width.\n * @platform android, ios, web\n */\n width?: number;\n /**\n * The height of the preview in pixels. Defaults to the screen height.\n * @platform android, ios, web\n */\n height?: number;\n /**\n * The horizontal origin of the preview, in pixels.\n * @platform android, ios\n */\n x?: number;\n /**\n * The vertical origin of the preview, in pixels.\n * @platform android, ios\n */\n y?: number;\n /**\n * The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'.\n * Cannot be set if width or height is provided, otherwise the call will be rejected.\n * Use setPreviewSize to adjust size after starting.\n *\n * @since 2.0.0\n */\n aspectRatio?: \"4:3\" | \"16:9\";\n /**\n * The grid overlay to display on the camera preview.\n * @default \"none\"\n * @since 2.1.0\n */\n gridMode?: GridMode;\n /**\n * Adjusts the y-position to account for safe areas (e.g., notches).\n * @platform ios\n * @default false\n */\n includeSafeAreaInsets?: boolean;\n /**\n * If true, places the preview behind the webview.\n * @platform android\n * @default true\n */\n toBack?: boolean;\n /**\n * Bottom padding for the preview, in pixels.\n * @platform android, ios\n */\n paddingBottom?: number;\n /**\n * Whether to rotate the preview when the device orientation changes.\n * @platform ios\n * @default true\n */\n rotateWhenOrientationChanged?: boolean;\n /**\n * The camera to use.\n * @default \"rear\"\n */\n position?: CameraPosition | string;\n /**\n * If true, saves the captured image to a file and returns the file path.\n * If false, returns a base64 encoded string.\n * @default false\n */\n storeToFile?: boolean;\n /**\n * If true, prevents the plugin from rotating the image based on EXIF data.\n * @platform android\n * @default false\n */\n disableExifHeaderStripping?: boolean;\n /**\n * If true, disables the audio stream, preventing audio permission requests.\n * @default true\n */\n disableAudio?: boolean;\n /**\n * If true, locks the device orientation while the camera is active.\n * @platform android\n * @default false\n */\n lockAndroidOrientation?: boolean;\n /**\n * If true, allows the camera preview's opacity to be changed.\n * @platform android, web\n * @default false\n */\n enableOpacity?: boolean;\n /**\n * If true, enables pinch-to-zoom functionality on the preview.\n * @platform android\n * @default false\n */\n enableZoom?: boolean;\n /**\n * If true, uses the video-optimized preset for the camera session.\n * @platform ios\n * @default false\n */\n enableVideoMode?: boolean;\n /**\n * The `deviceId` of the camera to use. If provided, `position` is ignored.\n * @platform ios\n */\n deviceId?: string;\n /**\n * The initial zoom level when starting the camera preview.\n * If the requested zoom level is not available, the native plugin will reject.\n * @default 1.0\n * @platform android, ios\n * @since 2.2.0\n */\n initialZoomLevel?: number;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /** The desired height of the picture in pixels. If not provided, the device default is used. */\n height?: number;\n /** The desired width of the picture in pixels. If not provided, the device default is used. */\n width?: number;\n /**\n * The desired aspect ratio of the captured image (e.g., '4:3', '16:9').\n * If specified without width/height, captures the largest possible image with this ratio.\n * Cannot be used together with width or height - the capture will be rejected with an error.\n * @since 7.7.0\n */\n aspectRatio?: string;\n /**\n * The quality of the captured image, from 0 to 100.\n * Does not apply to `png` format.\n * @default 85\n */\n quality?: number;\n /**\n * The format of the captured image.\n * @default \"jpeg\"\n */\n format?: PictureFormat;\n /**\n * If true, the captured image will be saved to the user's gallery.\n * @default false\n * @since 7.5.0\n */\n saveToGallery?: boolean;\n /**\n * If true, the plugin will attempt to add GPS location data to the image's EXIF metadata.\n * This may prompt the user for location permissions.\n * @default false\n * @since 7.6.0\n */\n withExifLocation?: boolean;\n}\n\n/** Represents EXIF data extracted from an image. */\nexport interface ExifData {\n [key: string]: any;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\n/** Defines a standard picture size with width and height. */\nexport interface PictureSize {\n /** The width of the picture in pixels. */\n width: number;\n /** The height of the picture in pixels. */\n height: number;\n}\n\n/** Represents the supported picture sizes for a camera facing a certain direction. */\nexport interface SupportedPictureSizes {\n /** The camera direction (\"front\" or \"rear\"). */\n facing: string;\n /** A list of supported picture sizes for this camera. */\n supportedPictureSizes: PictureSize[];\n}\n\n/**\n * Defines the options for capturing a sample frame from the camera preview.\n */\nexport interface CameraSampleOptions {\n /**\n * The quality of the captured sample, from 0 to 100.\n * @default 85\n */\n quality?: number;\n}\n\n/**\n * The available flash modes for the camera.\n * 'torch' is a continuous light mode.\n */\nexport type CameraPreviewFlashMode = \"off\" | \"on\" | \"auto\" | \"torch\";\n\n/**\n * Defines the options for setting the camera preview's opacity.\n */\nexport interface CameraOpacityOptions {\n /**\n * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).\n * @default 1.0\n */\n opacity?: number;\n}\n\n/**\n * The main interface for the CameraPreview plugin.\n */\nexport interface CameraPreviewPlugin {\n /**\n * Starts the camera preview.\n *\n * @param {CameraPreviewOptions} options - The configuration for the camera preview.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the preview dimensions.\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<{\n /** The width of the preview in pixels. */\n width: number;\n /** The height of the preview in pixels. */\n height: number;\n /** The horizontal origin of the preview, in pixels. */\n x: number;\n /** The vertical origin of the preview, in pixels. */\n y: number;\n }>;\n\n /**\n * Stops the camera preview.\n *\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(): Promise<void>;\n\n /**\n * Captures a picture from the camera.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string }>} A promise that resolves with the captured image data.\n * The `value` is a base64 encoded string unless `storeToFile` is true, in which case it's a file path.\n * @since 0.0.1\n */\n capture(\n options: CameraPreviewPictureOptions,\n ): Promise<{ value: string; exif: ExifData }>;\n\n /**\n * Captures a single frame from the camera preview stream.\n *\n * @param {CameraSampleOptions} options - The options for capturing the sample.\n * @returns {Promise<{ value: string }>} A promise that resolves with the sample image as a base64 encoded string.\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n\n /**\n * Gets the flash modes supported by the active camera.\n *\n * @returns {Promise<{ result: CameraPreviewFlashMode[] }>} A promise that resolves with an array of supported flash modes.\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n\n /**\n * Set the aspect ratio of the camera preview.\n *\n * @param {{ aspectRatio: '4:3' | '16:9'; x?: number; y?: number }} options - The desired aspect ratio and optional position.\n * - aspectRatio: The desired aspect ratio ('4:3' or '16:9')\n * - x: Optional x coordinate for positioning. If not provided, view will be auto-centered horizontally.\n * - y: Optional y coordinate for positioning. If not provided, view will be auto-centered vertically.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.4.0\n */\n setAspectRatio(options: {\n aspectRatio: \"4:3\" | \"16:9\";\n x?: number;\n y?: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Gets the current aspect ratio of the camera preview.\n *\n * @returns {Promise<{ aspectRatio: '4:3' | '16:9' }>} A promise that resolves with the current aspect ratio.\n * @since 7.4.0\n */\n getAspectRatio(): Promise<{ aspectRatio: \"4:3\" | \"16:9\" }>;\n\n /**\n * Sets the grid mode of the camera preview overlay.\n *\n * @param {{ gridMode: GridMode }} options - The desired grid mode ('none', '3x3', or '4x4').\n * @returns {Promise<void>} A promise that resolves when the grid mode is set.\n * @since 8.0.0\n */\n setGridMode(options: { gridMode: GridMode }): Promise<void>;\n\n /**\n * Gets the current grid mode of the camera preview overlay.\n *\n * @returns {Promise<{ gridMode: GridMode }>} A promise that resolves with the current grid mode.\n * @since 8.0.0\n */\n getGridMode(): Promise<{ gridMode: GridMode }>;\n\n /**\n * Gets the horizontal field of view (FoV) for the active camera.\n * Note: This can be an estimate on some devices.\n *\n * @returns {Promise<{ result: number }>} A promise that resolves with the horizontal field of view in degrees.\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: number;\n }>;\n\n /**\n * Gets the supported picture sizes for all cameras.\n *\n * @returns {Promise<{ supportedPictureSizes: SupportedPictureSizes[] }>} A promise that resolves with the list of supported sizes.\n * @since 7.4.0\n */\n getSupportedPictureSizes(): Promise<{\n supportedPictureSizes: SupportedPictureSizes[];\n }>;\n\n /**\n * Sets the flash mode for the active camera.\n *\n * @param {{ flashMode: CameraPreviewFlashMode | string }} options - The desired flash mode.\n * @returns {Promise<void>} A promise that resolves when the flash mode is set.\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n\n /**\n * Toggles between the front and rear cameras.\n *\n * @returns {Promise<void>} A promise that resolves when the camera is flipped.\n * @since 0.0.1\n */\n flip(): Promise<void>;\n\n /**\n * Sets the opacity of the camera preview.\n *\n * @param {CameraOpacityOptions} options - The opacity options.\n * @returns {Promise<void>} A promise that resolves when the opacity is set.\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n\n /**\n * Stops an ongoing video recording.\n *\n * @returns {Promise<{ videoFilePath: string }>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{ videoFilePath: string }>;\n\n /**\n * Starts recording a video.\n *\n * @param {CameraPreviewOptions} options - The options for video recording.\n * @returns {Promise<void>} A promise that resolves when video recording starts.\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n\n /**\n * Checks if the camera preview is currently running.\n *\n * @returns {Promise<{ isRunning: boolean }>} A promise that resolves with the running state.\n * @since 7.4.0\n */\n isRunning(): Promise<{ isRunning: boolean }>;\n\n /**\n * Gets all available camera devices.\n *\n * @returns {Promise<{ devices: CameraDevice[] }>} A promise that resolves with the list of available camera devices.\n * @since 7.4.0\n */\n getAvailableDevices(): Promise<{ devices: CameraDevice[] }>;\n\n /**\n * Gets the current zoom state, including min/max and current lens info.\n *\n * @returns {Promise<{ min: number; max: number; current: number; lens: LensInfo }>} A promise that resolves with the zoom state.\n * @since 7.4.0\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Sets the zoom level of the camera.\n *\n * @param {{ level: number; ramp?: boolean; autoFocus?: boolean }} options - The desired zoom level. `ramp` is currently unused. `autoFocus` defaults to true.\n * @returns {Promise<void>} A promise that resolves when the zoom level is set.\n * @since 7.4.0\n */\n setZoom(options: {\n level: number;\n ramp?: boolean;\n autoFocus?: boolean;\n }): Promise<void>;\n\n /**\n * Gets the current flash mode.\n *\n * @returns {Promise<{ flashMode: FlashMode }>} A promise that resolves with the current flash mode.\n * @since 7.4.0\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.4.0\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Switches the active camera to the one with the specified `deviceId`.\n *\n * @param {{ deviceId: string }} options - The ID of the device to switch to.\n * @returns {Promise<void>} A promise that resolves when the camera is switched.\n * @since 7.4.0\n */\n setDeviceId(options: { deviceId: string }): Promise<void>;\n\n /**\n * Gets the ID of the currently active camera device.\n *\n * @returns {Promise<{ deviceId: string }>} A promise that resolves with the current device ID.\n * @since 7.4.0\n */\n getDeviceId(): Promise<{ deviceId: string }>;\n\n /**\n * Gets the current preview size and position.\n * @returns {Promise<{x: number, y: number, width: number, height: number}>}\n */\n getPreviewSize(): Promise<{\n x: number;\n y: number;\n width: number;\n height: number;\n }>;\n /**\n * Sets the preview size and position.\n * @param options The new position and dimensions.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n */\n setPreviewSize(options: {\n x?: number;\n y?: number;\n width: number;\n height: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Sets the camera focus to a specific point in the preview.\n *\n * @param {Object} options - The focus options.\n * @param {number} options.x - The x coordinate in the preview view to focus on (0-1 normalized).\n * @param {number} options.y - The y coordinate in the preview view to focus on (0-1 normalized).\n * @returns {Promise<void>} A promise that resolves when the focus is set.\n * @since 8.1.0\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,sCAAwB,CAAA;IACxB,sCAAwB,CAAA;IACxB,qCAAuB,CAAA;IACvB,sCAAwB,CAAA;IACxB,2BAAa,CAAA;IACb,oCAAsB,CAAA;IACtB,+BAAiB,CAAA;AACnB,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB","sourcesContent":["export type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport enum DeviceType {\n ULTRA_WIDE = \"ultraWide\",\n WIDE_ANGLE = \"wideAngle\",\n TELEPHOTO = \"telephoto\",\n TRUE_DEPTH = \"trueDepth\",\n DUAL = \"dual\",\n DUAL_WIDE = \"dualWide\",\n TRIPLE = \"triple\",\n}\n\n/**\n * Represents a single camera lens on a device. A {@link CameraDevice} can have multiple lenses.\n */\nexport interface CameraLens {\n /** A human-readable name for the lens, e.g., \"Ultra-Wide\". */\n label: string;\n /** The type of the camera lens. */\n deviceType: DeviceType;\n /** The focal length of the lens in millimeters. */\n focalLength: number;\n /** The base zoom factor for this lens (e.g., 0.5 for ultra-wide, 1.0 for wide). */\n baseZoomRatio: number;\n /** The minimum zoom factor supported by this specific lens. */\n minZoom: number;\n /** The maximum zoom factor supported by this specific lens. */\n maxZoom: number;\n}\n\n/**\n * Represents a physical camera on the device (e.g., the front-facing camera).\n */\nexport interface CameraDevice {\n /** A unique identifier for the camera device. */\n deviceId: string;\n /** A human-readable name for the camera device. */\n label: string;\n /** The physical position of the camera on the device. */\n position: CameraPosition;\n /** A list of all available lenses for this camera device. */\n lenses: CameraLens[];\n /** The overall minimum zoom factor available across all lenses on this device. */\n minZoom: number;\n /** The overall maximum zoom factor available across all lenses on this device. */\n maxZoom: number;\n /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */\n isLogical: boolean;\n}\n\n/**\n * Represents the detailed information of the currently active lens.\n */\nexport interface LensInfo {\n /** The focal length of the active lens in millimeters. */\n focalLength: number;\n /** The device type of the active lens. */\n deviceType: DeviceType;\n /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */\n baseZoomRatio: number;\n /** The current digital zoom factor applied on top of the base zoom. */\n digitalZoom: number;\n}\n\n/**\n * Defines the configuration options for starting the camera preview.\n */\nexport interface CameraPreviewOptions {\n /**\n * The parent element to attach the video preview to.\n * @platform web\n */\n parent?: string;\n /**\n * A CSS class name to add to the preview element.\n * @platform web\n */\n className?: string;\n /**\n * The width of the preview in pixels. Defaults to the screen width.\n * @platform android, ios, web\n */\n width?: number;\n /**\n * The height of the preview in pixels. Defaults to the screen height.\n * @platform android, ios, web\n */\n height?: number;\n /**\n * The horizontal origin of the preview, in pixels.\n * @platform android, ios\n */\n x?: number;\n /**\n * The vertical origin of the preview, in pixels.\n * @platform android, ios\n */\n y?: number;\n /**\n * The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'.\n * Cannot be set if width or height is provided, otherwise the call will be rejected.\n * Use setPreviewSize to adjust size after starting.\n *\n * @since 2.0.0\n */\n aspectRatio?: \"4:3\" | \"16:9\";\n /**\n * The grid overlay to display on the camera preview.\n * @default \"none\"\n * @since 2.1.0\n */\n gridMode?: GridMode;\n /**\n * Adjusts the y-position to account for safe areas (e.g., notches).\n * @platform ios\n * @default false\n */\n includeSafeAreaInsets?: boolean;\n /**\n * If true, places the preview behind the webview.\n * @platform android\n * @default true\n */\n toBack?: boolean;\n /**\n * Bottom padding for the preview, in pixels.\n * @platform android, ios\n */\n paddingBottom?: number;\n /**\n * Whether to rotate the preview when the device orientation changes.\n * @platform ios\n * @default true\n */\n rotateWhenOrientationChanged?: boolean;\n /**\n * The camera to use.\n * @default \"rear\"\n */\n position?: CameraPosition | string;\n /**\n * If true, saves the captured image to a file and returns the file path.\n * If false, returns a base64 encoded string.\n * @default false\n */\n storeToFile?: boolean;\n /**\n * If true, prevents the plugin from rotating the image based on EXIF data.\n * @platform android\n * @default false\n */\n disableExifHeaderStripping?: boolean;\n /**\n * If true, disables the audio stream, preventing audio permission requests.\n * @default true\n */\n disableAudio?: boolean;\n /**\n * If true, locks the device orientation while the camera is active.\n * @platform android\n * @default false\n */\n lockAndroidOrientation?: boolean;\n /**\n * If true, allows the camera preview's opacity to be changed.\n * @platform android, web\n * @default false\n */\n enableOpacity?: boolean;\n /**\n * If true, enables pinch-to-zoom functionality on the preview.\n * @platform android\n * @default false\n */\n enableZoom?: boolean;\n /**\n * If true, uses the video-optimized preset for the camera session.\n * @platform ios\n * @default false\n */\n enableVideoMode?: boolean;\n /**\n * The `deviceId` of the camera to use. If provided, `position` is ignored.\n * @platform ios\n */\n deviceId?: string;\n /**\n * The initial zoom level when starting the camera preview.\n * If the requested zoom level is not available, the native plugin will reject.\n * @default 1.0\n * @platform android, ios\n * @since 2.2.0\n */\n initialZoomLevel?: number;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /** @deprecated,\n * The desired height of the picture in pixels. \n * If not specified and no aspectRatio is provided, the captured image will match the preview's visible area.\n */\n height?: number;\n /** @deprecated,\n * The desired width of the picture in pixels. \n * If not specified and no aspectRatio is provided, the captured image will match the preview's visible area.\n */\n width?: number;\n /** @deprecated,\n * The desired aspect ratio of the captured image (e.g., '4:3', '16:9').\n * If not specified and no width/height is provided, the aspect ratio from the camera start will be used.\n * If no aspect ratio was set at start, defaults to '4:3'.\n * Cannot be used together with width or height - the capture will be rejected with an error.\n * @since 7.7.0\n */\n aspectRatio?: string;\n /**\n * The quality of the captured image, from 0 to 100.\n * Does not apply to `png` format.\n * @default 85\n */\n quality?: number;\n /**\n * The format of the captured image.\n * @default \"jpeg\"\n */\n format?: PictureFormat;\n /**\n * If true, the captured image will be saved to the user's gallery.\n * @default false\n * @since 7.5.0\n */\n saveToGallery?: boolean;\n /**\n * If true, the plugin will attempt to add GPS location data to the image's EXIF metadata.\n * This may prompt the user for location permissions.\n * @default false\n * @since 7.6.0\n */\n withExifLocation?: boolean;\n}\n\n/** Represents EXIF data extracted from an image. */\nexport interface ExifData {\n [key: string]: any;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\n/** Defines a standard picture size with width and height. */\nexport interface PictureSize {\n /** The width of the picture in pixels. */\n width: number;\n /** The height of the picture in pixels. */\n height: number;\n}\n\n/** Represents the supported picture sizes for a camera facing a certain direction. */\nexport interface SupportedPictureSizes {\n /** The camera direction (\"front\" or \"rear\"). */\n facing: string;\n /** A list of supported picture sizes for this camera. */\n supportedPictureSizes: PictureSize[];\n}\n\n/**\n * Defines the options for capturing a sample frame from the camera preview.\n */\nexport interface CameraSampleOptions {\n /**\n * The quality of the captured sample, from 0 to 100.\n * @default 85\n */\n quality?: number;\n}\n\n/**\n * The available flash modes for the camera.\n * 'torch' is a continuous light mode.\n */\nexport type CameraPreviewFlashMode = \"off\" | \"on\" | \"auto\" | \"torch\";\n\n/**\n * Defines the options for setting the camera preview's opacity.\n */\nexport interface CameraOpacityOptions {\n /**\n * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).\n * @default 1.0\n */\n opacity?: number;\n}\n\n/**\n * The main interface for the CameraPreview plugin.\n */\nexport interface CameraPreviewPlugin {\n /**\n * Starts the camera preview.\n *\n * @param {CameraPreviewOptions} options - The configuration for the camera preview.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the preview dimensions.\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<{\n /** The width of the preview in pixels. */\n width: number;\n /** The height of the preview in pixels. */\n height: number;\n /** The horizontal origin of the preview, in pixels. */\n x: number;\n /** The vertical origin of the preview, in pixels. */\n y: number;\n }>;\n\n /**\n * Stops the camera preview.\n *\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(): Promise<void>;\n\n /**\n * Captures a picture from the camera.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string }>} A promise that resolves with the captured image data.\n * The `value` is a base64 encoded string unless `storeToFile` is true, in which case it's a file path.\n * @since 0.0.1\n */\n capture(\n options: CameraPreviewPictureOptions,\n ): Promise<{ value: string; exif: ExifData }>;\n\n /**\n * Captures a single frame from the camera preview stream.\n *\n * @param {CameraSampleOptions} options - The options for capturing the sample.\n * @returns {Promise<{ value: string }>} A promise that resolves with the sample image as a base64 encoded string.\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n\n /**\n * Gets the flash modes supported by the active camera.\n *\n * @returns {Promise<{ result: CameraPreviewFlashMode[] }>} A promise that resolves with an array of supported flash modes.\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n\n /**\n * Set the aspect ratio of the camera preview.\n *\n * @param {{ aspectRatio: '4:3' | '16:9'; x?: number; y?: number }} options - The desired aspect ratio and optional position.\n * - aspectRatio: The desired aspect ratio ('4:3' or '16:9')\n * - x: Optional x coordinate for positioning. If not provided, view will be auto-centered horizontally.\n * - y: Optional y coordinate for positioning. If not provided, view will be auto-centered vertically.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.4.0\n */\n setAspectRatio(options: {\n aspectRatio: \"4:3\" | \"16:9\";\n x?: number;\n y?: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Gets the current aspect ratio of the camera preview.\n *\n * @returns {Promise<{ aspectRatio: '4:3' | '16:9' }>} A promise that resolves with the current aspect ratio.\n * @since 7.4.0\n */\n getAspectRatio(): Promise<{ aspectRatio: \"4:3\" | \"16:9\" }>;\n\n /**\n * Sets the grid mode of the camera preview overlay.\n *\n * @param {{ gridMode: GridMode }} options - The desired grid mode ('none', '3x3', or '4x4').\n * @returns {Promise<void>} A promise that resolves when the grid mode is set.\n * @since 8.0.0\n */\n setGridMode(options: { gridMode: GridMode }): Promise<void>;\n\n /**\n * Gets the current grid mode of the camera preview overlay.\n *\n * @returns {Promise<{ gridMode: GridMode }>} A promise that resolves with the current grid mode.\n * @since 8.0.0\n */\n getGridMode(): Promise<{ gridMode: GridMode }>;\n\n /**\n * Gets the horizontal field of view (FoV) for the active camera.\n * Note: This can be an estimate on some devices.\n *\n * @returns {Promise<{ result: number }>} A promise that resolves with the horizontal field of view in degrees.\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: number;\n }>;\n\n /**\n * Gets the supported picture sizes for all cameras.\n *\n * @returns {Promise<{ supportedPictureSizes: SupportedPictureSizes[] }>} A promise that resolves with the list of supported sizes.\n * @since 7.4.0\n */\n getSupportedPictureSizes(): Promise<{\n supportedPictureSizes: SupportedPictureSizes[];\n }>;\n\n /**\n * Sets the flash mode for the active camera.\n *\n * @param {{ flashMode: CameraPreviewFlashMode | string }} options - The desired flash mode.\n * @returns {Promise<void>} A promise that resolves when the flash mode is set.\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n\n /**\n * Toggles between the front and rear cameras.\n *\n * @returns {Promise<void>} A promise that resolves when the camera is flipped.\n * @since 0.0.1\n */\n flip(): Promise<void>;\n\n /**\n * Sets the opacity of the camera preview.\n *\n * @param {CameraOpacityOptions} options - The opacity options.\n * @returns {Promise<void>} A promise that resolves when the opacity is set.\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n\n /**\n * Stops an ongoing video recording.\n *\n * @returns {Promise<{ videoFilePath: string }>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{ videoFilePath: string }>;\n\n /**\n * Starts recording a video.\n *\n * @param {CameraPreviewOptions} options - The options for video recording.\n * @returns {Promise<void>} A promise that resolves when video recording starts.\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n\n /**\n * Checks if the camera preview is currently running.\n *\n * @returns {Promise<{ isRunning: boolean }>} A promise that resolves with the running state.\n * @since 7.4.0\n */\n isRunning(): Promise<{ isRunning: boolean }>;\n\n /**\n * Gets all available camera devices.\n *\n * @returns {Promise<{ devices: CameraDevice[] }>} A promise that resolves with the list of available camera devices.\n * @since 7.4.0\n */\n getAvailableDevices(): Promise<{ devices: CameraDevice[] }>;\n\n /**\n * Gets the current zoom state, including min/max and current lens info.\n *\n * @returns {Promise<{ min: number; max: number; current: number; lens: LensInfo }>} A promise that resolves with the zoom state.\n * @since 7.4.0\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Sets the zoom level of the camera.\n *\n * @param {{ level: number; ramp?: boolean; autoFocus?: boolean }} options - The desired zoom level. `ramp` is currently unused. `autoFocus` defaults to true.\n * @returns {Promise<void>} A promise that resolves when the zoom level is set.\n * @since 7.4.0\n */\n setZoom(options: {\n level: number;\n ramp?: boolean;\n autoFocus?: boolean;\n }): Promise<void>;\n\n /**\n * Gets the current flash mode.\n *\n * @returns {Promise<{ flashMode: FlashMode }>} A promise that resolves with the current flash mode.\n * @since 7.4.0\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.4.0\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Switches the active camera to the one with the specified `deviceId`.\n *\n * @param {{ deviceId: string }} options - The ID of the device to switch to.\n * @returns {Promise<void>} A promise that resolves when the camera is switched.\n * @since 7.4.0\n */\n setDeviceId(options: { deviceId: string }): Promise<void>;\n\n /**\n * Gets the ID of the currently active camera device.\n *\n * @returns {Promise<{ deviceId: string }>} A promise that resolves with the current device ID.\n * @since 7.4.0\n */\n getDeviceId(): Promise<{ deviceId: string }>;\n\n /**\n * Gets the current preview size and position.\n * @returns {Promise<{x: number, y: number, width: number, height: number}>}\n */\n getPreviewSize(): Promise<{\n x: number;\n y: number;\n width: number;\n height: number;\n }>;\n /**\n * Sets the preview size and position.\n * @param options The new position and dimensions.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n */\n setPreviewSize(options: {\n x?: number;\n y?: number;\n width: number;\n height: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Sets the camera focus to a specific point in the preview.\n *\n * @param {Object} options - The focus options.\n * @param {number} options.x - The x coordinate in the preview view to focus on (0-1 normalized).\n * @param {number} options.y - The y coordinate in the preview view to focus on (0-1 normalized).\n * @returns {Promise<void>} A promise that resolves when the focus is set.\n * @since 8.1.0\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n}\n"]}
@@ -665,7 +665,7 @@ extension CameraController {
665
665
  self.updateVideoOrientation()
666
666
  }
667
667
 
668
- func captureImage(width: Int?, height: Int?, aspectRatio: String?, quality: Float, gpsLocation: CLLocation?, completion: @escaping (UIImage?, Error?) -> Void) {
668
+ func captureImage(width: Int?, height: Int?, aspectRatio: String?, quality: Float, gpsLocation: CLLocation?, completion: @escaping (UIImage?, Error?) -> Void) {
669
669
  guard let photoOutput = self.photoOutput else {
670
670
  completion(nil, NSError(domain: "Camera", code: 0, userInfo: [NSLocalizedDescriptionKey: "Photo output is not available"]))
671
671
  return
@@ -710,8 +710,10 @@ extension CameraController {
710
710
 
711
711
  var finalImage = image
712
712
 
713
- // Handle aspect ratio if no width/height specified
714
- if width == nil && height == nil, let aspectRatio = aspectRatio {
713
+ // When no dimensions are specified, crop to match what's visible in preview
714
+ if width == nil && height == nil {
715
+ // If aspectRatio is specified, use it to crop
716
+ if let aspectRatio = aspectRatio {
715
717
  let components = aspectRatio.split(separator: ":").compactMap { Double($0) }
716
718
  if components.count == 2 {
717
719
  // For capture in portrait orientation, swap the aspect ratio (16:9 becomes 9:16)
@@ -735,6 +737,15 @@ extension CameraController {
735
737
  finalImage = croppedImage
736
738
  }
737
739
  }
740
+ } else {
741
+ // No aspectRatio specified but we need to crop to match preview
742
+ // Since preview uses resizeAspectFill, we need to crop the captured image
743
+ // to match what's visible in the preview
744
+ if let previewLayer = self.previewLayer,
745
+ let croppedImage = self.cropImageToMatchPreview(image: image, previewLayer: previewLayer) {
746
+ finalImage = croppedImage
747
+ }
748
+ }
738
749
  } else if let width = width, let height = height {
739
750
  finalImage = self.resizeImage(image: image, to: CGSize(width: width, height: height))!
740
751
  }
@@ -798,6 +809,40 @@ extension CameraController {
798
809
 
799
810
  return UIImage(cgImage: croppedCGImage, scale: image.scale, orientation: image.imageOrientation)
800
811
  }
812
+
813
+ func cropImageToMatchPreview(image: UIImage, previewLayer: AVCaptureVideoPreviewLayer) -> UIImage? {
814
+ // Get the dimensions of the preview layer
815
+ let previewBounds = previewLayer.bounds
816
+ let previewAspectRatio = previewBounds.width / previewBounds.height
817
+
818
+ // Get the dimensions of the captured image
819
+ let imageSize = image.size
820
+ let imageAspectRatio = imageSize.width / imageSize.height
821
+
822
+ // Since we're using resizeAspectFill, we need to calculate what portion of the image
823
+ // is visible in the preview
824
+ var cropRect: CGRect
825
+
826
+ if imageAspectRatio > previewAspectRatio {
827
+ // Image is wider than preview - crop horizontally
828
+ let visibleWidth = imageSize.height * previewAspectRatio
829
+ let xOffset = (imageSize.width - visibleWidth) / 2
830
+ cropRect = CGRect(x: xOffset, y: 0, width: visibleWidth, height: imageSize.height)
831
+ } else {
832
+ // Image is taller than preview - crop vertically
833
+ let visibleHeight = imageSize.width / previewAspectRatio
834
+ let yOffset = (imageSize.height - visibleHeight) / 2
835
+ cropRect = CGRect(x: 0, y: yOffset, width: imageSize.width, height: visibleHeight)
836
+ }
837
+
838
+ // Create the cropped image
839
+ guard let cgImage = image.cgImage,
840
+ let croppedCGImage = cgImage.cropping(to: cropRect) else {
841
+ return nil
842
+ }
843
+
844
+ return UIImage(cgImage: croppedCGImage, scale: image.scale, orientation: image.imageOrientation)
845
+ }
801
846
 
802
847
  func captureSample(completion: @escaping (UIImage?, Error?) -> Void) {
803
848
  guard let captureSession = captureSession,
@@ -672,10 +672,18 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
672
672
  return
673
673
  }
674
674
 
675
- print("[CameraPreview] Capture params - quality: \(quality), saveToGallery: \(saveToGallery), withExifLocation: \(withExifLocation), width: \(width ?? -1), height: \(height ?? -1), aspectRatio: \(aspectRatio ?? "nil")")
675
+ // Use the stored aspectRatio if none is provided and no width/height is specified
676
+ // If no aspectRatio was set at all, use "4:3" as default (matching getAspectRatio behavior)
677
+ let captureAspectRatio: String? = if width == nil && height == nil && aspectRatio == nil {
678
+ self.aspectRatio ?? "4:3"
679
+ } else {
680
+ aspectRatio
681
+ }
682
+
683
+ print("[CameraPreview] Capture params - quality: \(quality), saveToGallery: \(saveToGallery), withExifLocation: \(withExifLocation), width: \(width ?? -1), height: \(height ?? -1), aspectRatio: \(aspectRatio ?? "nil"), using aspectRatio: \(captureAspectRatio ?? "nil")")
676
684
  print("[CameraPreview] Current location: \(self.currentLocation?.description ?? "nil")")
677
685
 
678
- self.cameraController.captureImage(width: width, height: height, aspectRatio: aspectRatio, quality: quality, gpsLocation: self.currentLocation) { (image, error) in
686
+ self.cameraController.captureImage(width: width, height: height, aspectRatio: captureAspectRatio, quality: quality, gpsLocation: self.currentLocation) { (image, error) in
679
687
  print("[CameraPreview] captureImage callback received")
680
688
  DispatchQueue.main.async {
681
689
  print("[CameraPreview] Processing capture on main thread")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "7.4.0-beta.16",
3
+ "version": "7.4.0-beta.18",
4
4
  "description": "Camera preview",
5
5
  "license": "MIT",
6
6
  "repository": {