@capgo/camera-preview 7.4.3 → 7.6.0

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
@@ -856,6 +856,7 @@ Defines the configuration options for starting the camera preview.
856
856
  | **`lockAndroidOrientation`** | <code>boolean</code> | If true, locks the device orientation while the camera is active. | <code>false</code> | |
857
857
  | **`enableOpacity`** | <code>boolean</code> | If true, allows the camera preview's opacity to be changed. | <code>false</code> | |
858
858
  | **`enableZoom`** | <code>boolean</code> | If true, enables pinch-to-zoom functionality on the preview. | <code>false</code> | |
859
+ | **`disableFocusIndicator`** | <code>boolean</code> | If true, disables the visual focus indicator when tapping to focus. | <code>false</code> | |
859
860
  | **`enableVideoMode`** | <code>boolean</code> | If true, uses the video-optimized preset for the camera session. | <code>false</code> | |
860
861
  | **`deviceId`** | <code>string</code> | The `deviceId` of the camera to use. If provided, `position` is ignored. | | |
861
862
  | **`initialZoomLevel`** | <code>number</code> | The initial zoom level when starting the camera preview. If the requested zoom level is not available, the native plugin will reject. | <code>1.0</code> | 2.2.0 |
@@ -596,6 +596,10 @@ public class CameraPreview
596
596
  final String gridMode = call.getString("gridMode", "none");
597
597
  final String positioning = call.getString("positioning", "top");
598
598
  final float initialZoomLevel = call.getFloat("initialZoomLevel", 1.0f);
599
+ final boolean disableFocusIndicator = call.getBoolean(
600
+ "disableFocusIndicator",
601
+ false
602
+ );
599
603
 
600
604
  // Check for conflict between aspectRatio and size
601
605
  if (
@@ -1008,7 +1012,8 @@ public class CameraPreview
1008
1012
  disableAudio,
1009
1013
  1.0f,
1010
1014
  aspectRatio,
1011
- gridMode
1015
+ gridMode,
1016
+ disableFocusIndicator
1012
1017
  );
1013
1018
  config.setTargetZoom(finalTargetZoom);
1014
1019
  config.setCentered(isCentered);
@@ -101,6 +101,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
101
101
  private FrameLayout previewContainer;
102
102
  private View focusIndicatorView;
103
103
  private long focusIndicatorAnimationId = 0; // Incrementing token to invalidate previous animations
104
+ private boolean disableFocusIndicator = false; // Default to false for backward compatibility
104
105
  private CameraSelector currentCameraSelector;
105
106
  private String currentDeviceId;
106
107
  private int currentFlashMode = ImageCapture.FLASH_MODE_OFF;
@@ -1079,8 +1080,12 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
1079
1080
  bytes = writeExifToImageBytes(bytes, exifInterface);
1080
1081
  }
1081
1082
 
1083
+ // Save to gallery asynchronously if requested
1082
1084
  if (saveToGallery) {
1083
- saveImageToGallery(bytes);
1085
+ final byte[] finalBytes = bytes;
1086
+ new Thread(() -> {
1087
+ saveImageToGallery(finalBytes);
1088
+ }).start();
1084
1089
  }
1085
1090
 
1086
1091
  String resultValue;
@@ -1874,6 +1879,9 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
1874
1879
  }
1875
1880
 
1876
1881
  private void showFocusIndicator(float x, float y) {
1882
+ if (disableFocusIndicator || sessionConfig.getDisableFocusIndicator()) {
1883
+ return;
1884
+ }
1877
1885
  if (previewContainer == null) {
1878
1886
  Log.w(TAG, "showFocusIndicator: previewContainer is null");
1879
1887
  return;
@@ -2258,7 +2266,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2258
2266
  sessionConfig.isDisableAudio(), // disableAudio
2259
2267
  sessionConfig.getZoomFactor(), // zoomFactor
2260
2268
  sessionConfig.getAspectRatio(), // aspectRatio
2261
- sessionConfig.getGridMode() // gridMode
2269
+ sessionConfig.getGridMode(), // gridMode
2270
+ sessionConfig.getDisableFocusIndicator() // disableFocusIndicator
2262
2271
  );
2263
2272
 
2264
2273
  // Clear current device ID to force position-based selection
@@ -2416,7 +2425,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2416
2425
  sessionConfig.getDisableAudio(),
2417
2426
  sessionConfig.getZoomFactor(),
2418
2427
  aspectRatio,
2419
- currentGridMode
2428
+ currentGridMode,
2429
+ sessionConfig.getDisableFocusIndicator()
2420
2430
  );
2421
2431
  sessionConfig.setCentered(true);
2422
2432
 
@@ -2518,7 +2528,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2518
2528
  sessionConfig.getDisableAudio(),
2519
2529
  sessionConfig.getZoomFactor(),
2520
2530
  aspectRatio,
2521
- currentGridMode
2531
+ currentGridMode,
2532
+ sessionConfig.getDisableFocusIndicator()
2522
2533
  );
2523
2534
  sessionConfig.setCentered(true);
2524
2535
 
@@ -2592,7 +2603,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2592
2603
  sessionConfig.getDisableAudio(),
2593
2604
  sessionConfig.getZoomFactor(),
2594
2605
  sessionConfig.getAspectRatio(),
2595
- gridMode
2606
+ gridMode,
2607
+ sessionConfig.getDisableFocusIndicator()
2596
2608
  );
2597
2609
 
2598
2610
  // Update the grid overlay immediately
@@ -2974,7 +2986,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2974
2986
  sessionConfig.getDisableAudio(),
2975
2987
  sessionConfig.getZoomFactor(),
2976
2988
  calculatedAspectRatio,
2977
- sessionConfig.getGridMode()
2989
+ sessionConfig.getGridMode(),
2990
+ sessionConfig.getDisableFocusIndicator()
2978
2991
  );
2979
2992
 
2980
2993
  // If aspect ratio changed due to size update, rebind camera
@@ -21,6 +21,7 @@ public class CameraSessionConfiguration {
21
21
  private final float zoomFactor;
22
22
  private final String aspectRatio;
23
23
  private final String gridMode;
24
+ private final boolean disableFocusIndicator;
24
25
  private float targetZoom = 1.0f;
25
26
  private boolean isCentered = false;
26
27
 
@@ -40,7 +41,8 @@ public class CameraSessionConfiguration {
40
41
  boolean disableAudio,
41
42
  float zoomFactor,
42
43
  String aspectRatio,
43
- String gridMode
44
+ String gridMode,
45
+ boolean disableFocusIndicator
44
46
  ) {
45
47
  this.deviceId = deviceId;
46
48
  this.position = position;
@@ -58,6 +60,7 @@ public class CameraSessionConfiguration {
58
60
  this.zoomFactor = zoomFactor;
59
61
  this.aspectRatio = aspectRatio;
60
62
  this.gridMode = gridMode != null ? gridMode : "none";
63
+ this.disableFocusIndicator = disableFocusIndicator;
61
64
  }
62
65
 
63
66
  public void setTargetZoom(float zoom) {
@@ -164,4 +167,8 @@ public class CameraSessionConfiguration {
164
167
  public void setCentered(boolean centered) {
165
168
  isCentered = centered;
166
169
  }
170
+
171
+ public boolean getDisableFocusIndicator() {
172
+ return disableFocusIndicator;
173
+ }
167
174
  }
package/dist/docs.json CHANGED
@@ -1158,6 +1158,22 @@
1158
1158
  "complexTypes": [],
1159
1159
  "type": "boolean | undefined"
1160
1160
  },
1161
+ {
1162
+ "name": "disableFocusIndicator",
1163
+ "tags": [
1164
+ {
1165
+ "text": "android, ios",
1166
+ "name": "platform"
1167
+ },
1168
+ {
1169
+ "text": "false",
1170
+ "name": "default"
1171
+ }
1172
+ ],
1173
+ "docs": "If true, disables the visual focus indicator when tapping to focus.",
1174
+ "complexTypes": [],
1175
+ "type": "boolean | undefined"
1176
+ },
1161
1177
  {
1162
1178
  "name": "enableVideoMode",
1163
1179
  "tags": [
@@ -172,6 +172,12 @@ export interface CameraPreviewOptions {
172
172
  * @default false
173
173
  */
174
174
  enableZoom?: boolean;
175
+ /**
176
+ * If true, disables the visual focus indicator when tapping to focus.
177
+ * @platform android, ios
178
+ * @default false
179
+ */
180
+ disableFocusIndicator?: boolean;
175
181
  /**
176
182
  * If true, uses the video-optimized preset for the camera session.
177
183
  * @platform ios
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAUA,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":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport type CameraPositioning = \"center\" | \"top\" | \"bottom\";\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 * The vertical positioning of the camera preview.\n * @default \"center\"\n * @platform android, ios, web\n * @since 2.3.0\n */\n positioning?: CameraPositioning;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /**\n * The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\n height?: number;\n /**\n * The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\n width?: number;\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 * Represents safe area insets for devices.\n * Android: Values are expressed in logical pixels (dp) to match JS layout units.\n * iOS: Values are expressed in physical pixels and exclude status bar.\n */\nexport interface SafeAreaInsets {\n /** Current device orientation (1 = portrait, 2 = landscape, 0 = unknown). */\n orientation: number;\n /**\n * Orientation-aware notch/camera cutout inset (excluding status bar).\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch at side).\n * Android: Value in dp, iOS: Value in pixels (status bar excluded).\n */\n top: number;\n}\n\n/**\n * Canonical device orientation values across platforms.\n */\nexport type DeviceOrientation =\n | \"portrait\"\n | \"landscape\"\n | \"landscape-left\"\n | \"landscape-right\"\n | \"portrait-upside-down\"\n | \"unknown\";\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 * If `storeToFile` was set to `true` when starting the preview, the returned\n * `value` will be an absolute file path on the device instead of a base64 string. Use getBase64FromFilePath to get the base64 string from the file path.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string; exif: ExifData }>} Resolves with:\n * - `value`: base64 string, or file path if `storeToFile` is true\n * - `exif`: extracted EXIF metadata when available\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Returns zoom button values for quick switching.\n * - iOS/Android: includes 0.5 if ultra-wide available; 1 and 2 if wide available; 3 if telephoto available\n * - Web: unsupported\n * @since 7.5.0\n * @platform android, ios\n */\n getZoomButtonValues(): Promise<{ values: number[] }>;\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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 * @since 7.5.0\n * @platform android, ios\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 * @since 7.5.0\n * @platform android, ios\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 7.5.0\n * @platform android, ios\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n\n /**\n * Adds a listener for screen resize events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"screenResize\",\n listenerFunc: (data: {\n width: number;\n height: number;\n x: number;\n y: number;\n }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for orientation change events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"orientationChange\",\n listenerFunc: (data: { orientation: DeviceOrientation }) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Deletes a file at the given absolute path on the device.\n * Use this to quickly clean up temporary images created with `storeToFile`.\n * On web, this is not supported and will throw.\n * @since 7.5.0\n * @platform android, ios\n */\n deleteFile(options: { path: string }): Promise<{ success: boolean }>;\n\n /**\n * Gets the safe area insets for devices.\n * Returns the orientation-aware notch/camera cutout inset and the current orientation.\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch moved to side).\n * This specifically targets the cutout area (notch, punch hole, etc.) that all modern phones have.\n *\n * Android: Values returned in dp (logical pixels).\n * iOS: Values returned in physical pixels, excluding status bar (only pure notch/cutout size).\n *\n * @platform android, ios\n */\n getSafeAreaInsets(): Promise<SafeAreaInsets>;\n\n /**\n * Gets the current device orientation in a cross-platform format.\n * @since 7.5.0\n * @platform android, ios\n */\n getOrientation(): Promise<{ orientation: DeviceOrientation }>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAUA,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":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport type CameraPositioning = \"center\" | \"top\" | \"bottom\";\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 /**\n * If true, disables the visual focus indicator when tapping to focus.\n * @platform android, ios\n * @default false\n */\n disableFocusIndicator?: 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 * The vertical positioning of the camera preview.\n * @default \"center\"\n * @platform android, ios, web\n * @since 2.3.0\n */\n positioning?: CameraPositioning;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /**\n * The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\n height?: number;\n /**\n * The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\n width?: number;\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 * Represents safe area insets for devices.\n * Android: Values are expressed in logical pixels (dp) to match JS layout units.\n * iOS: Values are expressed in physical pixels and exclude status bar.\n */\nexport interface SafeAreaInsets {\n /** Current device orientation (1 = portrait, 2 = landscape, 0 = unknown). */\n orientation: number;\n /**\n * Orientation-aware notch/camera cutout inset (excluding status bar).\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch at side).\n * Android: Value in dp, iOS: Value in pixels (status bar excluded).\n */\n top: number;\n}\n\n/**\n * Canonical device orientation values across platforms.\n */\nexport type DeviceOrientation =\n | \"portrait\"\n | \"landscape\"\n | \"landscape-left\"\n | \"landscape-right\"\n | \"portrait-upside-down\"\n | \"unknown\";\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 * If `storeToFile` was set to `true` when starting the preview, the returned\n * `value` will be an absolute file path on the device instead of a base64 string. Use getBase64FromFilePath to get the base64 string from the file path.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string; exif: ExifData }>} Resolves with:\n * - `value`: base64 string, or file path if `storeToFile` is true\n * - `exif`: extracted EXIF metadata when available\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Returns zoom button values for quick switching.\n * - iOS/Android: includes 0.5 if ultra-wide available; 1 and 2 if wide available; 3 if telephoto available\n * - Web: unsupported\n * @since 7.5.0\n * @platform android, ios\n */\n getZoomButtonValues(): Promise<{ values: number[] }>;\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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.5.0\n * @platform android, ios\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 * @since 7.5.0\n * @platform android, ios\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 * @since 7.5.0\n * @platform android, ios\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 7.5.0\n * @platform android, ios\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n\n /**\n * Adds a listener for screen resize events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"screenResize\",\n listenerFunc: (data: {\n width: number;\n height: number;\n x: number;\n y: number;\n }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for orientation change events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"orientationChange\",\n listenerFunc: (data: { orientation: DeviceOrientation }) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Deletes a file at the given absolute path on the device.\n * Use this to quickly clean up temporary images created with `storeToFile`.\n * On web, this is not supported and will throw.\n * @since 7.5.0\n * @platform android, ios\n */\n deleteFile(options: { path: string }): Promise<{ success: boolean }>;\n\n /**\n * Gets the safe area insets for devices.\n * Returns the orientation-aware notch/camera cutout inset and the current orientation.\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch moved to side).\n * This specifically targets the cutout area (notch, punch hole, etc.) that all modern phones have.\n *\n * Android: Values returned in dp (logical pixels).\n * iOS: Values returned in physical pixels, excluding status bar (only pure notch/cutout size).\n *\n * @platform android, ios\n */\n getSafeAreaInsets(): Promise<SafeAreaInsets>;\n\n /**\n * Gets the current device orientation in a cross-platform format.\n * @since 7.5.0\n * @platform android, ios\n */\n getOrientation(): Promise<{ orientation: DeviceOrientation }>;\n}\n"]}
@@ -4,6 +4,7 @@ import CoreLocation
4
4
 
5
5
  class CameraController: NSObject {
6
6
  var captureSession: AVCaptureSession?
7
+ var disableFocusIndicator: Bool = false
7
8
 
8
9
  var currentCameraPosition: CameraPosition?
9
10
 
@@ -70,6 +71,37 @@ class CameraController: NSObject {
70
71
 
71
72
  // Track whether an aspect ratio was explicitly requested
72
73
  var requestedAspectRatio: String?
74
+
75
+ private func calculateAspectRatioFrame(for aspectRatio: String, in bounds: CGRect) -> CGRect {
76
+ guard let ratio = parseAspectRatio(aspectRatio) else {
77
+ return bounds
78
+ }
79
+
80
+ let targetAspectRatio = ratio.width / ratio.height
81
+ let viewAspectRatio = bounds.width / bounds.height
82
+
83
+ var frame: CGRect
84
+
85
+ if viewAspectRatio > targetAspectRatio {
86
+ // View is wider than target - fit by height
87
+ let targetWidth = bounds.height * targetAspectRatio
88
+ let xOffset = (bounds.width - targetWidth) / 2
89
+ frame = CGRect(x: xOffset, y: 0, width: targetWidth, height: bounds.height)
90
+ } else {
91
+ // View is taller than target - fit by width
92
+ let targetHeight = bounds.width / targetAspectRatio
93
+ let yOffset = (bounds.height - targetHeight) / 2
94
+ frame = CGRect(x: 0, y: yOffset, width: bounds.width, height: targetHeight)
95
+ }
96
+
97
+ return frame
98
+ }
99
+
100
+ private func parseAspectRatio(_ aspectRatio: String) -> (width: CGFloat, height: CGFloat)? {
101
+ let components = aspectRatio.split(separator: ":").compactMap { Float(String($0)) }
102
+ guard components.count == 2 else { return nil }
103
+ return (width: CGFloat(components[0]), height: CGFloat(components[1]))
104
+ }
73
105
  }
74
106
 
75
107
  extension CameraController {
@@ -188,7 +220,7 @@ extension CameraController {
188
220
  self.outputsPrepared = true
189
221
  }
190
222
 
191
- func prepare(cameraPosition: String, deviceId: String? = nil, disableAudio: Bool, cameraMode: Bool, aspectRatio: String? = nil, initialZoomLevel: Float?, completionHandler: @escaping (Error?) -> Void) {
223
+ func prepare(cameraPosition: String, deviceId: String? = nil, disableAudio: Bool, cameraMode: Bool, aspectRatio: String? = nil, initialZoomLevel: Float?, disableFocusIndicator: Bool = false, completionHandler: @escaping (Error?) -> Void) {
192
224
  print("[CameraPreview] 🎬 Starting prepare - position: \(cameraPosition), deviceId: \(deviceId ?? "nil"), disableAudio: \(disableAudio), cameraMode: \(cameraMode), aspectRatio: \(aspectRatio ?? "nil"), zoom: \(initialZoomLevel)")
193
225
 
194
226
  DispatchQueue.global(qos: .userInitiated).async { [weak self] in
@@ -219,6 +251,9 @@ extension CameraController {
219
251
  self.requestedAspectRatio = aspectRatio
220
252
  self.configureSessionPreset(for: aspectRatio)
221
253
 
254
+ // Set disableFocusIndicator
255
+ self.disableFocusIndicator = disableFocusIndicator
256
+
222
257
  // Configure device inputs
223
258
  try self.configureDeviceInputs(cameraPosition: cameraPosition, deviceId: deviceId, disableAudio: disableAudio)
224
259
 
@@ -416,9 +451,17 @@ extension CameraController {
416
451
  }
417
452
 
418
453
  // Fast configuration without CATransaction overhead
419
- // Use resizeAspect to avoid crop when no aspect ratio is requested; otherwise fill
420
- previewLayer.videoGravity = (requestedAspectRatio == nil) ? .resizeAspect : .resizeAspectFill
421
- previewLayer.frame = view.bounds
454
+ // Configure video gravity and frame based on aspect ratio
455
+ if let aspectRatio = requestedAspectRatio {
456
+ // Calculate the frame based on requested aspect ratio
457
+ let frame = calculateAspectRatioFrame(for: aspectRatio, in: view.bounds)
458
+ previewLayer.frame = frame
459
+ previewLayer.videoGravity = .resizeAspectFill
460
+ } else {
461
+ // No specific aspect ratio requested - fill the entire view
462
+ previewLayer.frame = view.bounds
463
+ previewLayer.videoGravity = .resizeAspect
464
+ }
422
465
 
423
466
  // Insert layer immediately (only if new)
424
467
  if previewLayer.superlayer != view.layer {
@@ -433,7 +476,16 @@ extension CameraController {
433
476
  // Disable animation for grid overlay creation and positioning
434
477
  CATransaction.begin()
435
478
  CATransaction.setDisableActions(true)
436
- gridOverlayView = GridOverlayView(frame: view.bounds)
479
+
480
+ // Use preview layer frame if aspect ratio is specified, otherwise use full view bounds
481
+ let gridFrame: CGRect
482
+ if requestedAspectRatio != nil, let previewLayer = previewLayer {
483
+ gridFrame = previewLayer.frame
484
+ } else {
485
+ gridFrame = view.bounds
486
+ }
487
+
488
+ gridOverlayView = GridOverlayView(frame: gridFrame)
437
489
  gridOverlayView?.gridMode = gridMode
438
490
  view.addSubview(gridOverlayView!)
439
491
  CATransaction.commit()
@@ -637,9 +689,12 @@ extension CameraController {
637
689
  }
638
690
 
639
691
  let settings = AVCapturePhotoSettings()
640
- // Request highest quality photo capture
692
+ // Configure photo capture settings
641
693
  if #available(iOS 13.0, *) {
642
- settings.isHighResolutionPhotoEnabled = true
694
+ // Enable high resolution capture if max dimensions are specified or no aspect ratio constraint
695
+ // When aspect ratio is specified WITHOUT max dimensions, use session preset dimensions
696
+ let shouldUseHighRes = (width != nil || height != nil) || (self.requestedAspectRatio == nil)
697
+ settings.isHighResolutionPhotoEnabled = shouldUseHighRes
643
698
  }
644
699
  if #available(iOS 15.0, *) {
645
700
  settings.photoQualityPrioritization = .balanced
@@ -684,16 +739,28 @@ extension CameraController {
684
739
 
685
740
  // Determine what to do based on parameters
686
741
  if width != nil || height != nil {
687
- // Resize to fit within maximum dimensions while maintaining aspect ratio
688
- finalImage = self.resizeImageToMaxDimensions(image: image, maxWidth: width, maxHeight: height)!
742
+ // When max dimensions are specified, we used high-res capture
743
+ // First crop to aspect ratio if needed, then resize to max dimensions
744
+ if let aspectRatio = self.requestedAspectRatio {
745
+ finalImage = self.cropImageToAspectRatio(image: image, aspectRatio: aspectRatio) ?? image
746
+ print("[CameraPreview] Cropped high-res image to aspect ratio \(aspectRatio)")
747
+ }
748
+ // Then resize to fit within maximum dimensions while maintaining aspect ratio
749
+ finalImage = self.resizeImageToMaxDimensions(image: finalImage, maxWidth: width, maxHeight: height)!
689
750
  print("[CameraPreview] Resized to max dimensions: \(finalImage.size.width)x\(finalImage.size.height)")
690
- } else {
691
- // No parameters specified - crop to match what's visible in the preview
692
- // This ensures we capture exactly what the user sees
693
- if let previewLayer = self.previewLayer,
694
- let previewCroppedImage = self.cropImageToMatchPreview(image: image, previewLayer: previewLayer) {
695
- finalImage = previewCroppedImage
696
- print("[CameraPreview] Cropped to match preview: \(finalImage.size.width)x\(finalImage.size.height)")
751
+ } else if let aspectRatio = self.requestedAspectRatio {
752
+ // No max dimensions specified, but aspect ratio is specified
753
+ // If we used session preset (low-res), image should already be correct aspect ratio
754
+ // If we used high-res (shouldn't happen without max dimensions), crop it
755
+ let imageAspectRatio = image.size.width / image.size.height
756
+ if let targetRatio = self.parseAspectRatio(aspectRatio) {
757
+ let targetAspectRatio = targetRatio.width / targetRatio.height
758
+
759
+ // Allow small tolerance for aspect ratio comparison
760
+ if abs(imageAspectRatio - targetAspectRatio) > 0.01 {
761
+ finalImage = self.cropImageToAspectRatio(image: image, aspectRatio: aspectRatio) ?? image
762
+ print("[CameraPreview] Cropped to match aspect ratio \(aspectRatio): \(finalImage.size.width)x\(finalImage.size.height)")
763
+ }
697
764
  }
698
765
  }
699
766
 
@@ -746,9 +813,9 @@ extension CameraController {
746
813
  func resizeImageToMaxDimensions(image: UIImage, maxWidth: Int?, maxHeight: Int?) -> UIImage? {
747
814
  let originalSize = image.size
748
815
  let originalAspectRatio = originalSize.width / originalSize.height
749
-
816
+
750
817
  var targetSize = originalSize
751
-
818
+
752
819
  if let maxWidth = maxWidth, let maxHeight = maxHeight {
753
820
  // Both dimensions specified - fit within both maximums
754
821
  let maxAspectRatio = CGFloat(maxWidth) / CGFloat(maxHeight)
@@ -770,11 +837,40 @@ extension CameraController {
770
837
  targetSize.width = CGFloat(maxHeight) * originalAspectRatio
771
838
  targetSize.height = CGFloat(maxHeight)
772
839
  }
773
-
840
+
774
841
  return resizeImage(image: image, to: targetSize)
775
842
  }
776
843
 
844
+ func cropImageToAspectRatio(image: UIImage, aspectRatio: String) -> UIImage? {
845
+ guard let ratio = parseAspectRatio(aspectRatio) else {
846
+ return image
847
+ }
848
+
849
+ let imageSize = image.size
850
+ let imageAspectRatio = imageSize.width / imageSize.height
851
+ let targetAspectRatio = ratio.width / ratio.height
852
+
853
+ var cropRect: CGRect
777
854
 
855
+ if imageAspectRatio > targetAspectRatio {
856
+ // Image is wider than target - crop horizontally (center crop)
857
+ let targetWidth = imageSize.height * targetAspectRatio
858
+ let xOffset = (imageSize.width - targetWidth) / 2
859
+ cropRect = CGRect(x: xOffset, y: 0, width: targetWidth, height: imageSize.height)
860
+ } else {
861
+ // Image is taller than target - crop vertically (center crop)
862
+ let targetHeight = imageSize.width / targetAspectRatio
863
+ let yOffset = (imageSize.height - targetHeight) / 2
864
+ cropRect = CGRect(x: 0, y: yOffset, width: imageSize.width, height: targetHeight)
865
+ }
866
+
867
+ guard let cgImage = image.cgImage,
868
+ let croppedCGImage = cgImage.cropping(to: cropRect) else {
869
+ return nil
870
+ }
871
+
872
+ return UIImage(cgImage: croppedCGImage, scale: image.scale, orientation: image.imageOrientation)
873
+ }
778
874
 
779
875
  func cropImageToMatchPreview(image: UIImage, previewLayer: AVCaptureVideoPreviewLayer) -> UIImage? {
780
876
  // When using resizeAspectFill, the preview layer shows a cropped portion of the video
@@ -1113,7 +1209,7 @@ extension CameraController {
1113
1209
  return
1114
1210
  }
1115
1211
 
1116
- // Show focus indicator if requested and view is provided - only after validation
1212
+ // Show focus indicator if enabled, requested and view is provided - only after validation
1117
1213
  if showIndicator, let view = view, let previewLayer = self.previewLayer {
1118
1214
  // Convert the device point to layer point for indicator display
1119
1215
  let layerPoint = previewLayer.layerPointConverted(fromCaptureDevicePoint: point)
@@ -1416,8 +1512,8 @@ extension CameraController: UIGestureRecognizerDelegate {
1416
1512
  let point = tap.location(in: tap.view)
1417
1513
  let devicePoint = self.previewLayer?.captureDevicePointConverted(fromLayerPoint: point)
1418
1514
 
1419
- // Show focus indicator at the tap point
1420
- if let view = tap.view {
1515
+ // Show focus indicator at the tap point if not disabled
1516
+ if !self.disableFocusIndicator, let view = tap.view {
1421
1517
  showFocusIndicator(at: point, in: view)
1422
1518
  }
1423
1519
 
@@ -90,6 +90,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
90
90
  var storeToFile: Bool?
91
91
  var enableZoom: Bool?
92
92
  var disableAudio: Bool = false
93
+ var disableFocusIndicator: Bool = false
93
94
  var locationManager: CLLocationManager?
94
95
  var currentLocation: CLLocation?
95
96
  private var aspectRatio: String?
@@ -515,6 +516,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
515
516
  print(" - gridMode: \(call.getString("gridMode") ?? "none")")
516
517
  print(" - positioning: \(call.getString("positioning") ?? "top")")
517
518
  print(" - initialZoomLevel: \(call.getFloat("initialZoomLevel") ?? 1.0)")
519
+ print(" - disableFocusIndicator: \(call.getBool("disableFocusIndicator") ?? false)")
518
520
 
519
521
  if self.isInitializing {
520
522
  call.reject("camera initialization in progress")
@@ -570,6 +572,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
570
572
  self.aspectRatio = call.getString("aspectRatio") ?? "4:3"
571
573
  self.gridMode = call.getString("gridMode") ?? "none"
572
574
  self.positioning = call.getString("positioning") ?? "top"
575
+ self.disableFocusIndicator = call.getBool("disableFocusIndicator") ?? false
573
576
 
574
577
  let initialZoomLevel = call.getFloat("initialZoomLevel")
575
578
 
@@ -577,7 +580,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
577
580
  let hasAspectRatio = call.getString("aspectRatio") != nil
578
581
  let hasWidth = call.getInt("width") != nil
579
582
  let hasHeight = call.getInt("height") != nil
580
-
583
+
581
584
  if hasAspectRatio && (hasWidth || hasHeight) {
582
585
  call.reject("Cannot set both aspectRatio and size (width/height). Use setPreviewSize after start.")
583
586
  return
@@ -595,7 +598,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
595
598
  if self.cameraController.captureSession?.isRunning ?? false {
596
599
  call.reject("camera already started")
597
600
  } else {
598
- self.cameraController.prepare(cameraPosition: self.cameraPosition, deviceId: deviceId, disableAudio: self.disableAudio, cameraMode: cameraMode, aspectRatio: self.aspectRatio, initialZoomLevel: initialZoomLevel) {error in
601
+ self.cameraController.prepare(cameraPosition: self.cameraPosition, deviceId: deviceId, disableAudio: self.disableAudio, cameraMode: cameraMode, aspectRatio: self.aspectRatio, initialZoomLevel: initialZoomLevel, disableFocusIndicator: self.disableFocusIndicator) {error in
599
602
  if let error = error {
600
603
  print(error)
601
604
  call.reject(error.localizedDescription)
@@ -878,62 +881,38 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
878
881
 
879
882
  print("[CameraPreview] Image data created, size: \(imageDataWithExif.count) bytes")
880
883
 
881
- if saveToGallery {
882
- print("[CameraPreview] Saving to gallery...")
883
- self.saveImageDataToGallery(imageData: imageDataWithExif) { success, error in
884
- print("[CameraPreview] Save to gallery completed, success: \(success), error: \(error?.localizedDescription ?? "none")")
885
- let exifData = self.getExifData(from: imageDataWithExif)
886
-
887
- var result = JSObject()
888
- result["exif"] = exifData
889
- result["gallerySaved"] = success
890
- if !success, let error = error {
891
- result["galleryError"] = error.localizedDescription
892
- }
884
+ // Prepare the result first
885
+ let exifData = self.getExifData(from: imageDataWithExif)
893
886
 
894
- if self.storeToFile == false {
895
- let base64Image = imageDataWithExif.base64EncodedString()
896
- result["value"] = base64Image
897
- } else {
898
- do {
899
- let fileUrl = self.getTempFilePath()
900
- try imageDataWithExif.write(to: fileUrl)
901
- result["value"] = fileUrl.absoluteString
902
- } catch {
903
- call.reject("Error writing image to file")
904
- }
905
- }
887
+ var result = JSObject()
888
+ result["exif"] = exifData
906
889
 
907
- print("[CameraPreview] Resolving capture call with gallery save")
908
- call.resolve(result)
909
- }
890
+ if self.storeToFile == false {
891
+ let base64Image = imageDataWithExif.base64EncodedString()
892
+ result["value"] = base64Image
910
893
  } else {
911
- print("[CameraPreview] Not saving to gallery, returning image data")
912
- let exifData = self.getExifData(from: imageDataWithExif)
913
-
914
- if self.storeToFile == false {
915
- let base64Image = imageDataWithExif.base64EncodedString()
916
- var result = JSObject()
917
- result["value"] = base64Image
918
- result["exif"] = exifData
894
+ do {
895
+ let fileUrl = self.getTempFilePath()
896
+ try imageDataWithExif.write(to: fileUrl)
897
+ result["value"] = fileUrl.absoluteString
898
+ } catch {
899
+ call.reject("Error writing image to file")
900
+ return
901
+ }
902
+ }
919
903
 
920
- print("[CameraPreview] base64 - Resolving capture call")
921
- call.resolve(result)
922
- } else {
923
- do {
924
- let fileUrl = self.getTempFilePath()
925
- try imageDataWithExif.write(to: fileUrl)
926
- var result = JSObject()
927
- result["value"] = fileUrl.absoluteString
928
- result["exif"] = exifData
929
- print("[CameraPreview] filePath - Resolving capture call")
930
- call.resolve(result)
931
- } catch {
932
- call.reject("Error writing image to file")
904
+ // Save to gallery asynchronously if requested
905
+ if saveToGallery {
906
+ print("[CameraPreview] Saving to gallery asynchronously...")
907
+ DispatchQueue.global(qos: .utility).async {
908
+ self.saveImageDataToGallery(imageData: imageDataWithExif) { success, error in
909
+ print("[CameraPreview] Save to gallery completed, success: \(success), error: \(error?.localizedDescription ?? "none")")
933
910
  }
934
911
  }
935
-
936
912
  }
913
+
914
+ print("[CameraPreview] Resolving capture call immediately")
915
+ call.resolve(result)
937
916
  }
938
917
  }
939
918
  }
@@ -1813,7 +1792,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1813
1792
  }
1814
1793
  let devicePoint = previewLayer.captureDevicePointConverted(fromLayerPoint: focusPoint)
1815
1794
 
1816
- try self.cameraController.setFocus(at: devicePoint, showIndicator: true, in: self.previewView)
1795
+ try self.cameraController.setFocus(at: devicePoint, showIndicator: !self.disableFocusIndicator, in: self.previewView)
1817
1796
  call.resolve()
1818
1797
  } catch {
1819
1798
  call.reject("Failed to set focus: \(error.localizedDescription)")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "7.4.3",
3
+ "version": "7.6.0",
4
4
  "description": "Camera preview",
5
5
  "license": "MIT",
6
6
  "repository": {