@capgo/camera-preview 8.0.15 → 8.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1071,33 +1071,34 @@ Get the native Capacitor plugin version
1071
1071
 
1072
1072
  Defines the configuration options for starting the camera preview.
1073
1073
 
1074
- | Prop | Type | Description | Default | Since |
1075
- | ---------------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------ |
1076
- | **`parent`** | <code>string</code> | The parent element to attach the video preview to. | | |
1077
- | **`className`** | <code>string</code> | A CSS class name to add to the preview element. | | |
1078
- | **`width`** | <code>number</code> | The width of the preview in pixels. Defaults to the screen width. | | |
1079
- | **`height`** | <code>number</code> | The height of the preview in pixels. Defaults to the screen height. | | |
1080
- | **`x`** | <code>number</code> | The horizontal origin of the preview, in pixels. | | |
1081
- | **`y`** | <code>number</code> | The vertical origin of the preview, in pixels. | | |
1082
- | **`aspectRatio`** | <code>'4:3' \| '16:9'</code> | The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'. Cannot be set if width or height is provided, otherwise the call will be rejected. Use setPreviewSize to adjust size after starting. | | 2.0.0 |
1083
- | **`gridMode`** | <code><a href="#gridmode">GridMode</a></code> | The grid overlay to display on the camera preview. | <code>"none"</code> | 2.1.0 |
1084
- | **`includeSafeAreaInsets`** | <code>boolean</code> | Adjusts the y-position to account for safe areas (e.g., notches). | <code>false</code> | |
1085
- | **`toBack`** | <code>boolean</code> | If true, places the preview behind the webview. | <code>true</code> | |
1086
- | **`paddingBottom`** | <code>number</code> | Bottom padding for the preview, in pixels. | | |
1087
- | **`rotateWhenOrientationChanged`** | <code>boolean</code> | Whether to rotate the preview when the device orientation changes. | <code>true</code> | |
1088
- | **`position`** | <code>string</code> | The camera to use. | <code>"rear"</code> | |
1089
- | **`storeToFile`** | <code>boolean</code> | If true, saves the captured image to a file and returns the file path. If false, returns a base64 encoded string. | <code>false</code> | |
1090
- | **`disableExifHeaderStripping`** | <code>boolean</code> | If true, prevents the plugin from rotating the image based on EXIF data. | <code>false</code> | |
1091
- | **`disableAudio`** | <code>boolean</code> | If true, disables the audio stream, preventing audio permission requests. | <code>true</code> | |
1092
- | **`lockAndroidOrientation`** | <code>boolean</code> | If true, locks the device orientation while the camera is active. | <code>false</code> | |
1093
- | **`enableOpacity`** | <code>boolean</code> | If true, allows the camera preview's opacity to be changed. | <code>false</code> | |
1094
- | **`disableFocusIndicator`** | <code>boolean</code> | If true, disables the visual focus indicator when tapping to focus. | <code>false</code> | |
1095
- | **`deviceId`** | <code>string</code> | The `deviceId` of the camera to use. If provided, `position` is ignored. | | |
1096
- | **`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 |
1097
- | **`positioning`** | <code><a href="#camerapositioning">CameraPositioning</a></code> | The vertical positioning of the camera preview. | <code>"center"</code> | 2.3.0 |
1098
- | **`enableVideoMode`** | <code>boolean</code> | If true, enables video capture capabilities when the camera starts. | <code>false</code> | 7.11.0 |
1099
- | **`force`** | <code>boolean</code> | If true, forces the camera to start/restart even if it's already running or busy. This will kill the current camera session and start a new one, ignoring all state checks. | <code>false</code> | |
1100
- | **`videoQuality`** | <code>'low' \| 'medium' \| 'high'</code> | Sets the quality of video for recording. Options: 'low', 'medium', 'high' | <code>"high"</code> | |
1074
+ | Prop | Type | Description | Default | Since |
1075
+ | ---------------------------------- | --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | ------ |
1076
+ | **`parent`** | <code>string</code> | The parent element to attach the video preview to. | | |
1077
+ | **`className`** | <code>string</code> | A CSS class name to add to the preview element. | | |
1078
+ | **`width`** | <code>number</code> | The width of the preview in pixels. Defaults to the screen width. | | |
1079
+ | **`height`** | <code>number</code> | The height of the preview in pixels. Defaults to the screen height. | | |
1080
+ | **`x`** | <code>number</code> | The horizontal origin of the preview, in pixels. | | |
1081
+ | **`y`** | <code>number</code> | The vertical origin of the preview, in pixels. | | |
1082
+ | **`aspectRatio`** | <code>'4:3' \| '16:9'</code> | The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'. Cannot be set if width or height is provided, otherwise the call will be rejected. Use setPreviewSize to adjust size after starting. | | 2.0.0 |
1083
+ | **`aspectMode`** | <code>'cover' \| 'contain'</code> | Controls how the camera preview fills the available space. - 'contain': Fits the entire preview within the space, may show letterboxing (default). - 'cover': Fills the entire space, may crop edges of the preview. | <code>"contain"</code> | |
1084
+ | **`gridMode`** | <code><a href="#gridmode">GridMode</a></code> | The grid overlay to display on the camera preview. | <code>"none"</code> | 2.1.0 |
1085
+ | **`includeSafeAreaInsets`** | <code>boolean</code> | Adjusts the y-position to account for safe areas (e.g., notches). | <code>false</code> | |
1086
+ | **`toBack`** | <code>boolean</code> | If true, places the preview behind the webview. | <code>true</code> | |
1087
+ | **`paddingBottom`** | <code>number</code> | Bottom padding for the preview, in pixels. | | |
1088
+ | **`rotateWhenOrientationChanged`** | <code>boolean</code> | Whether to rotate the preview when the device orientation changes. | <code>true</code> | |
1089
+ | **`position`** | <code>string</code> | The camera to use. | <code>"rear"</code> | |
1090
+ | **`storeToFile`** | <code>boolean</code> | If true, saves the captured image to a file and returns the file path. If false, returns a base64 encoded string. | <code>false</code> | |
1091
+ | **`disableExifHeaderStripping`** | <code>boolean</code> | If true, prevents the plugin from rotating the image based on EXIF data. | <code>false</code> | |
1092
+ | **`disableAudio`** | <code>boolean</code> | If true, disables the audio stream, preventing audio permission requests. | <code>true</code> | |
1093
+ | **`lockAndroidOrientation`** | <code>boolean</code> | If true, locks the device orientation while the camera is active. | <code>false</code> | |
1094
+ | **`enableOpacity`** | <code>boolean</code> | If true, allows the camera preview's opacity to be changed. | <code>false</code> | |
1095
+ | **`disableFocusIndicator`** | <code>boolean</code> | If true, disables the visual focus indicator when tapping to focus. | <code>false</code> | |
1096
+ | **`deviceId`** | <code>string</code> | The `deviceId` of the camera to use. If provided, `position` is ignored. | | |
1097
+ | **`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 |
1098
+ | **`positioning`** | <code><a href="#camerapositioning">CameraPositioning</a></code> | The vertical positioning of the camera preview. | <code>"center"</code> | 2.3.0 |
1099
+ | **`enableVideoMode`** | <code>boolean</code> | If true, enables video capture capabilities when the camera starts. | <code>false</code> | 7.11.0 |
1100
+ | **`force`** | <code>boolean</code> | If true, forces the camera to start/restart even if it's already running or busy. This will kill the current camera session and start a new one, ignoring all state checks. | <code>false</code> | |
1101
+ | **`videoQuality`** | <code>'low' \| 'medium' \| 'high'</code> | Sets the quality of video for recording. Options: 'low', 'medium', 'high' | <code>"high"</code> | |
1101
1102
 
1102
1103
 
1103
1104
  #### ExifData
@@ -897,6 +897,7 @@ public class CameraPreview extends Plugin implements CameraXView.CameraXViewList
897
897
  final boolean disableAudio = Boolean.TRUE.equals(call.getBoolean("disableAudio", true));
898
898
  this.lastDisableAudio = disableAudio;
899
899
  final String aspectRatio = call.getString("aspectRatio", "4:3");
900
+ final String aspectMode = call.getString("aspectMode", "contain");
900
901
  final String gridMode = call.getString("gridMode", "none");
901
902
  final String positioning = call.getString("positioning", "top");
902
903
  //noinspection DataFlowIssue
@@ -1202,6 +1203,7 @@ public class CameraPreview extends Plugin implements CameraXView.CameraXViewList
1202
1203
  disableAudio,
1203
1204
  1.0f,
1204
1205
  aspectRatio,
1206
+ aspectMode,
1205
1207
  gridMode,
1206
1208
  disableFocusIndicator,
1207
1209
  enableVideoMode,
@@ -1648,16 +1650,22 @@ public class CameraPreview extends Plugin implements CameraXView.CameraXViewList
1648
1650
  ")"
1649
1651
  );
1650
1652
 
1651
- // Transition window background to transparent now that camera is ready
1653
+ // Transition window and webview backgrounds to transparent now that camera is ready
1652
1654
  // This prevents flickering during camera initialization
1655
+ // Both are set together in the same UI thread operation to avoid race conditions
1653
1656
  if (isToBackMode()) {
1654
1657
  getBridge()
1655
1658
  .getActivity()
1656
1659
  .runOnUiThread(() -> {
1657
1660
  try {
1661
+ // Set window background to transparent
1658
1662
  getBridge().getActivity().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
1663
+ // Set webview background to almost-transparent for MIUI compatibility
1664
+ // Use alpha=1 instead of 0 to work around MIUI/Xiaomi rendering issues
1665
+ // where Color.TRANSPARENT (alpha=0) is not rendered correctly
1666
+ getBridge().getWebView().setBackgroundColor(Color.argb(1, 255, 255, 255));
1659
1667
  } catch (Exception e) {
1660
- Log.w(TAG, "Failed to set window background to transparent", e);
1668
+ Log.w(TAG, "Failed to set backgrounds to transparent", e);
1661
1669
  }
1662
1670
  });
1663
1671
  }
@@ -538,13 +538,9 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
538
538
  // Use TextureView-backed implementation for broader device compatibility when overlaying with WebView
539
539
  // This avoids SurfaceView z-order issues seen on some MIUI/EMUI devices.
540
540
  previewView.setImplementationMode(PreviewView.ImplementationMode.COMPATIBLE);
541
- // Match iOS behavior: FIT when no aspect ratio, FILL when aspect ratio is set
542
- String initialAspectRatio = sessionConfig != null ? sessionConfig.getAspectRatio() : null;
543
- previewView.setScaleType(
544
- (initialAspectRatio == null || initialAspectRatio.isEmpty())
545
- ? PreviewView.ScaleType.FIT_CENTER
546
- : PreviewView.ScaleType.FILL_CENTER
547
- );
541
+ // Set scale type based on aspectMode: 'contain' uses FIT, 'cover' uses FILL
542
+ String aspectMode = sessionConfig != null ? sessionConfig.getAspectMode() : "contain";
543
+ previewView.setScaleType("cover".equals(aspectMode) ? PreviewView.ScaleType.FILL_CENTER : PreviewView.ScaleType.FIT_CENTER);
548
544
  // Also make preview view touchable as backup
549
545
  previewView.setClickable(true);
550
546
  previewView.setFocusable(true);
@@ -986,11 +982,9 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
986
982
  Log.d(TAG, "Image capture resolution: " + imageCaptureResolution.getResolution());
987
983
  }
988
984
 
989
- // Update scale type based on aspect ratio whenever (re)binding
990
- String ar = sessionConfig != null ? sessionConfig.getAspectRatio() : null;
991
- previewView.setScaleType(
992
- (ar == null || ar.isEmpty()) ? PreviewView.ScaleType.FIT_CENTER : PreviewView.ScaleType.FILL_CENTER
993
- );
985
+ // Update scale type based on aspectMode
986
+ String aspectMode = sessionConfig != null ? sessionConfig.getAspectMode() : "contain";
987
+ previewView.setScaleType("cover".equals(aspectMode) ? PreviewView.ScaleType.FILL_CENTER : PreviewView.ScaleType.FIT_CENTER);
994
988
 
995
989
  // Set initial zoom if specified, prioritizing targetZoom over default zoomFactor
996
990
  float initialZoom = sessionConfig.getTargetZoom() != 1.0f ? sessionConfig.getTargetZoom() : sessionConfig.getZoomFactor();
@@ -1048,14 +1042,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
1048
1042
  // Update grid overlay bounds after camera is started
1049
1043
  updateGridOverlayBounds();
1050
1044
 
1051
- // Now transition to transparent background after camera is ready
1052
- // This prevents flickering during camera initialization
1053
- if (sessionConfig.isToBack()) {
1054
- webView.post(() -> {
1055
- webView.setBackgroundColor(android.graphics.Color.TRANSPARENT);
1056
- });
1057
- }
1058
-
1045
+ // Notify listener that camera is started
1046
+ // The listener (CameraPreview) will handle setting both window and webview to transparent
1059
1047
  listener.onCameraStarted(actualWidth, actualHeight, actualX, actualY);
1060
1048
  });
1061
1049
  }
@@ -2760,6 +2748,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2760
2748
  sessionConfig.getDisableAudio(),
2761
2749
  sessionConfig.getZoomFactor(),
2762
2750
  sessionConfig.getAspectRatio(),
2751
+ sessionConfig.getAspectMode(),
2763
2752
  sessionConfig.getGridMode(),
2764
2753
  sessionConfig.getDisableFocusIndicator(),
2765
2754
  sessionConfig.isVideoModeEnabled(),
@@ -2805,6 +2794,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2805
2794
  sessionConfig.isDisableAudio(), // disableAudio
2806
2795
  sessionConfig.getZoomFactor(), // zoomFactor
2807
2796
  sessionConfig.getAspectRatio(), // aspectRatio
2797
+ sessionConfig.getAspectMode(), // aspectMode
2808
2798
  sessionConfig.getGridMode(), // gridMode
2809
2799
  sessionConfig.getDisableFocusIndicator(), // disableFocusIndicator
2810
2800
  sessionConfig.isVideoModeEnabled(), // enableVideoMode
@@ -2924,6 +2914,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2924
2914
  sessionConfig.getDisableAudio(),
2925
2915
  sessionConfig.getZoomFactor(),
2926
2916
  aspectRatio,
2917
+ sessionConfig.getAspectMode(),
2927
2918
  currentGridMode,
2928
2919
  sessionConfig.getDisableFocusIndicator(),
2929
2920
  sessionConfig.isVideoModeEnabled(),
@@ -2999,6 +2990,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2999
2990
  sessionConfig.getDisableAudio(),
3000
2991
  sessionConfig.getZoomFactor(),
3001
2992
  aspectRatio,
2993
+ sessionConfig.getAspectMode(),
3002
2994
  currentGridMode,
3003
2995
  sessionConfig.getDisableFocusIndicator(),
3004
2996
  sessionConfig.isVideoModeEnabled(),
@@ -3061,6 +3053,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
3061
3053
  sessionConfig.getDisableAudio(),
3062
3054
  sessionConfig.getZoomFactor(),
3063
3055
  sessionConfig.getAspectRatio(),
3056
+ sessionConfig.getAspectMode(),
3064
3057
  gridMode,
3065
3058
  sessionConfig.getDisableFocusIndicator(),
3066
3059
  sessionConfig.isVideoModeEnabled(),
@@ -3400,6 +3393,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
3400
3393
  sessionConfig.getDisableAudio(),
3401
3394
  sessionConfig.getZoomFactor(),
3402
3395
  calculatedAspectRatio,
3396
+ sessionConfig.getAspectMode(),
3403
3397
  sessionConfig.getGridMode(),
3404
3398
  sessionConfig.getDisableFocusIndicator(),
3405
3399
  sessionConfig.isVideoModeEnabled(),
@@ -19,6 +19,7 @@ public class CameraSessionConfiguration {
19
19
  private final boolean disableAudio;
20
20
  private final float zoomFactor;
21
21
  private final String aspectRatio;
22
+ private final String aspectMode;
22
23
  private final String gridMode;
23
24
  private final boolean disableFocusIndicator;
24
25
  private final boolean enableVideoMode;
@@ -41,6 +42,7 @@ public class CameraSessionConfiguration {
41
42
  boolean disableAudio,
42
43
  float zoomFactor,
43
44
  String aspectRatio,
45
+ String aspectMode,
44
46
  String gridMode,
45
47
  boolean disableFocusIndicator,
46
48
  boolean enableVideoMode,
@@ -60,6 +62,7 @@ public class CameraSessionConfiguration {
60
62
  this.disableAudio = disableAudio;
61
63
  this.zoomFactor = zoomFactor;
62
64
  this.aspectRatio = aspectRatio;
65
+ this.aspectMode = aspectMode != null ? aspectMode : "contain";
63
66
  this.gridMode = gridMode != null ? gridMode : "none";
64
67
  this.disableFocusIndicator = disableFocusIndicator;
65
68
  this.enableVideoMode = enableVideoMode;
@@ -130,6 +133,10 @@ public class CameraSessionConfiguration {
130
133
  return aspectRatio;
131
134
  }
132
135
 
136
+ public String getAspectMode() {
137
+ return aspectMode;
138
+ }
139
+
133
140
  public String getGridMode() {
134
141
  return gridMode;
135
142
  }
package/dist/docs.json CHANGED
@@ -1180,6 +1180,22 @@
1180
1180
  "complexTypes": [],
1181
1181
  "type": "'4:3' | '16:9' | undefined"
1182
1182
  },
1183
+ {
1184
+ "name": "aspectMode",
1185
+ "tags": [
1186
+ {
1187
+ "text": "\"contain\"",
1188
+ "name": "default"
1189
+ },
1190
+ {
1191
+ "text": "android, ios, web",
1192
+ "name": "platform"
1193
+ }
1194
+ ],
1195
+ "docs": "Controls how the camera preview fills the available space.\n- 'contain': Fits the entire preview within the space, may show letterboxing (default).\n- 'cover': Fills the entire space, may crop edges of the preview.",
1196
+ "complexTypes": [],
1197
+ "type": "'cover' | 'contain' | undefined"
1198
+ },
1183
1199
  {
1184
1200
  "name": "gridMode",
1185
1201
  "tags": [
@@ -115,6 +115,14 @@ export interface CameraPreviewOptions {
115
115
  * @since 2.0.0
116
116
  */
117
117
  aspectRatio?: '4:3' | '16:9';
118
+ /**
119
+ * Controls how the camera preview fills the available space.
120
+ * - 'contain': Fits the entire preview within the space, may show letterboxing (default).
121
+ * - 'cover': Fills the entire space, may crop edges of the preview.
122
+ * @default "contain"
123
+ * @platform android, ios, web
124
+ */
125
+ aspectMode?: 'cover' | 'contain';
118
126
  /**
119
127
  * The grid overlay to display on the camera preview.
120
128
  * @default "none"
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAwBA,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 { PermissionState, 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 interface CameraPermissionStatus {\n camera: PermissionState;\n microphone?: PermissionState;\n}\n\nexport interface PermissionRequestOptions {\n disableAudio?: boolean;\n showSettingsAlert?: boolean;\n title?: string;\n message?: string;\n openSettingsButtonTitle?: string;\n cancelButtonTitle?: string;\n}\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 /**\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 * 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 * If true, enables video capture capabilities when the camera starts.\n * @default false\n * @platform android\n * @since 7.11.0\n */\n enableVideoMode?: boolean;\n /**\n * If true, forces the camera to start/restart even if it's already running or busy.\n * This will kill the current camera session and start a new one, ignoring all state checks.\n * @default false\n * @platform android, ios, web\n */\n force?: boolean;\n /**\n * Sets the quality of video for recording.\n * Options: 'low', 'medium', 'high'\n * @note On Android requires 'enableVideoMode' to be true\n * @note Will affect the entire preview stream for iOS\n * @platform ios, android\n * @default \"high\"\n */\n videoQuality?: 'low' | 'medium' | 'high';\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 * If true, the plugin will embed a timestamp in the top-right corner of the image.\n * @default false\n * @since 7.17.0\n */\n embedTimestamp?: boolean;\n /**\n * If true, the plugin will embed the current location in the top-right corner of the image.\n * Requires `withExifLocation` to be enabled.\n * @default false\n * @since 7.18.0\n */\n embedLocation?: boolean;\n /**\n * Sets the priority for photo quality vs. capture speed.\n * - \"speed\": Prioritizes faster capture times, may reduce image quality.\n * - \"balanced\": Aims for a balance between quality and speed.\n * - \"quality\": Prioritizes image quality, may reduce capture speed.\n * See https://developer.apple.com/documentation/avfoundation/avcapturephotosettings/photoqualityprioritization for details.\n *\n * @since 7.21.0\n * @platform ios\n * @default \"speed\"\n */\n photoQualityPrioritization?: 'speed' | 'balanced' | 'quality';\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/** Reusable exposure mode type for cross-platform support. */\nexport type ExposureMode = 'AUTO' | 'LOCK' | 'CONTINUOUS' | 'CUSTOM';\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 = 'portrait' | 'landscape-left' | 'landscape-right' | 'portrait-upside-down' | '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 * @param {object} options - Optional configuration for stopping the camera.\n * @param {boolean} options.force - If true, forces the camera to stop even if busy or capturing. Default: false.\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(options?: { force?: boolean }): 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(options: CameraPreviewPictureOptions): 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: { aspectRatio: '4:3' | '16:9'; x?: number; y?: number }): 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 * Checks the current camera (and optionally microphone) permission status without prompting the system dialog.\n *\n * @param options Set `disableAudio` to `false` to also include microphone status (defaults to `true`).\n * @returns {Promise<CameraPermissionStatus>} A promise resolving to the current authorization states.\n * @since 8.7.0\n */\n checkPermissions(options?: Pick<PermissionRequestOptions, 'disableAudio'>): Promise<CameraPermissionStatus>;\n\n /**\n * Requests camera (and optional microphone) permissions. If permissions are already granted or denied,\n * the current status is returned without prompting. When `showSettingsAlert` is true and permissions are denied,\n * a platform specific alert guiding the user to the app settings will be presented.\n *\n * @param {PermissionRequestOptions} options - Configuration for the permission request behaviour.\n * @returns {Promise<CameraPermissionStatus>} A promise resolving to the final authorization states.\n * @since 8.7.0\n */\n requestPermissions(options?: PermissionRequestOptions): Promise<CameraPermissionStatus>;\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: { flashMode: CameraPreviewFlashMode | string }): 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. Only iOS.\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: { level: number; ramp?: boolean; autoFocus?: boolean }): 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: { x?: number; y?: number; width: number; height: number }): 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 * Note: The plugin does not attach any native tap-to-focus gesture handlers. Handle taps in\n * your HTML/JS (e.g., on the overlaying UI), then pass normalized coordinates here.\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: { width: number; height: number; x: number; y: number }) => 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 /**\n * Returns the exposure modes supported by the active camera.\n * Modes can include: 'locked', 'auto', 'continuous', 'custom'.\n * @platform android, ios\n */\n getExposureModes(): Promise<{ modes: ExposureMode[] }>;\n\n /**\n * Returns the current exposure mode.\n * @platform android, ios\n */\n getExposureMode(): Promise<{ mode: ExposureMode }>;\n\n /**\n * Sets the exposure mode.\n * @platform android, ios\n */\n setExposureMode(options: { mode: ExposureMode }): Promise<void>;\n\n /**\n * Returns the exposure compensation (EV bias) supported range.\n * @platform ios, android\n */\n getExposureCompensationRange(): Promise<{\n min: number;\n max: number;\n step: number;\n }>;\n\n /**\n * Returns the current exposure compensation (EV bias).\n * @platform ios, android\n */\n getExposureCompensation(): Promise<{ value: number }>;\n\n /**\n * Sets the exposure compensation (EV bias). Value will be clamped to range.\n * @platform ios, android\n */\n setExposureCompensation(options: { value: number }): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAwBA,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 { PermissionState, 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 interface CameraPermissionStatus {\n camera: PermissionState;\n microphone?: PermissionState;\n}\n\nexport interface PermissionRequestOptions {\n disableAudio?: boolean;\n showSettingsAlert?: boolean;\n title?: string;\n message?: string;\n openSettingsButtonTitle?: string;\n cancelButtonTitle?: string;\n}\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 * Controls how the camera preview fills the available space.\n * - 'contain': Fits the entire preview within the space, may show letterboxing (default).\n * - 'cover': Fills the entire space, may crop edges of the preview.\n * @default \"contain\"\n * @platform android, ios, web\n */\n aspectMode?: 'cover' | 'contain';\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 /**\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 * 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 * If true, enables video capture capabilities when the camera starts.\n * @default false\n * @platform android\n * @since 7.11.0\n */\n enableVideoMode?: boolean;\n /**\n * If true, forces the camera to start/restart even if it's already running or busy.\n * This will kill the current camera session and start a new one, ignoring all state checks.\n * @default false\n * @platform android, ios, web\n */\n force?: boolean;\n /**\n * Sets the quality of video for recording.\n * Options: 'low', 'medium', 'high'\n * @note On Android requires 'enableVideoMode' to be true\n * @note Will affect the entire preview stream for iOS\n * @platform ios, android\n * @default \"high\"\n */\n videoQuality?: 'low' | 'medium' | 'high';\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 * If true, the plugin will embed a timestamp in the top-right corner of the image.\n * @default false\n * @since 7.17.0\n */\n embedTimestamp?: boolean;\n /**\n * If true, the plugin will embed the current location in the top-right corner of the image.\n * Requires `withExifLocation` to be enabled.\n * @default false\n * @since 7.18.0\n */\n embedLocation?: boolean;\n /**\n * Sets the priority for photo quality vs. capture speed.\n * - \"speed\": Prioritizes faster capture times, may reduce image quality.\n * - \"balanced\": Aims for a balance between quality and speed.\n * - \"quality\": Prioritizes image quality, may reduce capture speed.\n * See https://developer.apple.com/documentation/avfoundation/avcapturephotosettings/photoqualityprioritization for details.\n *\n * @since 7.21.0\n * @platform ios\n * @default \"speed\"\n */\n photoQualityPrioritization?: 'speed' | 'balanced' | 'quality';\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/** Reusable exposure mode type for cross-platform support. */\nexport type ExposureMode = 'AUTO' | 'LOCK' | 'CONTINUOUS' | 'CUSTOM';\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 = 'portrait' | 'landscape-left' | 'landscape-right' | 'portrait-upside-down' | '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 * @param {object} options - Optional configuration for stopping the camera.\n * @param {boolean} options.force - If true, forces the camera to stop even if busy or capturing. Default: false.\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(options?: { force?: boolean }): 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(options: CameraPreviewPictureOptions): 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: { aspectRatio: '4:3' | '16:9'; x?: number; y?: number }): 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 * Checks the current camera (and optionally microphone) permission status without prompting the system dialog.\n *\n * @param options Set `disableAudio` to `false` to also include microphone status (defaults to `true`).\n * @returns {Promise<CameraPermissionStatus>} A promise resolving to the current authorization states.\n * @since 8.7.0\n */\n checkPermissions(options?: Pick<PermissionRequestOptions, 'disableAudio'>): Promise<CameraPermissionStatus>;\n\n /**\n * Requests camera (and optional microphone) permissions. If permissions are already granted or denied,\n * the current status is returned without prompting. When `showSettingsAlert` is true and permissions are denied,\n * a platform specific alert guiding the user to the app settings will be presented.\n *\n * @param {PermissionRequestOptions} options - Configuration for the permission request behaviour.\n * @returns {Promise<CameraPermissionStatus>} A promise resolving to the final authorization states.\n * @since 8.7.0\n */\n requestPermissions(options?: PermissionRequestOptions): Promise<CameraPermissionStatus>;\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: { flashMode: CameraPreviewFlashMode | string }): 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. Only iOS.\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: { level: number; ramp?: boolean; autoFocus?: boolean }): 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: { x?: number; y?: number; width: number; height: number }): 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 * Note: The plugin does not attach any native tap-to-focus gesture handlers. Handle taps in\n * your HTML/JS (e.g., on the overlaying UI), then pass normalized coordinates here.\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: { width: number; height: number; x: number; y: number }) => 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 /**\n * Returns the exposure modes supported by the active camera.\n * Modes can include: 'locked', 'auto', 'continuous', 'custom'.\n * @platform android, ios\n */\n getExposureModes(): Promise<{ modes: ExposureMode[] }>;\n\n /**\n * Returns the current exposure mode.\n * @platform android, ios\n */\n getExposureMode(): Promise<{ mode: ExposureMode }>;\n\n /**\n * Sets the exposure mode.\n * @platform android, ios\n */\n setExposureMode(options: { mode: ExposureMode }): Promise<void>;\n\n /**\n * Returns the exposure compensation (EV bias) supported range.\n * @platform ios, android\n */\n getExposureCompensationRange(): Promise<{\n min: number;\n max: number;\n step: number;\n }>;\n\n /**\n * Returns the current exposure compensation (EV bias).\n * @platform ios, android\n */\n getExposureCompensation(): Promise<{ value: number }>;\n\n /**\n * Sets the exposure compensation (EV bias). Value will be clamped to range.\n * @platform ios, android\n */\n setExposureCompensation(options: { value: number }): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -10,6 +10,8 @@ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreview
10
10
  private videoElement;
11
11
  private isStarted;
12
12
  private orientationListenerBound;
13
+ private mediaRecorder;
14
+ private recordedChunks;
13
15
  constructor();
14
16
  checkPermissions(options?: {
15
17
  disableAudio?: boolean;
package/dist/esm/web.js CHANGED
@@ -13,6 +13,8 @@ export class CameraPreviewWeb extends WebPlugin {
13
13
  this.videoElement = null;
14
14
  this.isStarted = false;
15
15
  this.orientationListenerBound = false;
16
+ this.mediaRecorder = null;
17
+ this.recordedChunks = [];
16
18
  }
17
19
  async checkPermissions(options) {
18
20
  const result = {
@@ -190,6 +192,9 @@ export class CameraPreviewWeb extends WebPlugin {
190
192
  // Reset any default margins that might interfere
191
193
  this.videoElement.style.margin = '0';
192
194
  this.videoElement.style.padding = '0';
195
+ // Set object-fit based on aspectMode (default: contain)
196
+ const aspectMode = options.aspectMode || 'contain';
197
+ this.videoElement.style.objectFit = aspectMode;
193
198
  container.appendChild(this.videoElement);
194
199
  if (options.toBack) {
195
200
  this.videoElement.style.zIndex = '-1';
@@ -567,11 +572,60 @@ export class CameraPreviewWeb extends WebPlugin {
567
572
  return this.capture(_options);
568
573
  }
569
574
  async stopRecordVideo() {
570
- throw new Error('stopRecordVideo not supported under the web platform');
575
+ if (!this.mediaRecorder) {
576
+ throw new Error('video recording is not running');
577
+ }
578
+ const recorder = this.mediaRecorder;
579
+ return await new Promise((resolve, reject) => {
580
+ recorder.onstop = () => {
581
+ try {
582
+ const blob = new Blob(this.recordedChunks, {
583
+ type: recorder.mimeType || 'video/webm',
584
+ });
585
+ this.recordedChunks = [];
586
+ this.mediaRecorder = null;
587
+ const videoFilePath = URL.createObjectURL(blob);
588
+ resolve({ videoFilePath });
589
+ }
590
+ catch (error) {
591
+ reject(error);
592
+ }
593
+ };
594
+ recorder.onerror = (event) => {
595
+ this.mediaRecorder = null;
596
+ this.recordedChunks = [];
597
+ reject((event === null || event === void 0 ? void 0 : event.error) || new Error('failed to stop video recording'));
598
+ };
599
+ recorder.stop();
600
+ });
571
601
  }
572
602
  async startRecordVideo(_options) {
573
- console.log('startRecordVideo', _options);
574
- throw new Error('startRecordVideo not supported under the web platform');
603
+ const video = document.getElementById(DEFAULT_VIDEO_ID);
604
+ if (!(video === null || video === void 0 ? void 0 : video.srcObject)) {
605
+ throw new Error('camera is not running');
606
+ }
607
+ if (this.mediaRecorder && this.mediaRecorder.state === 'recording') {
608
+ throw new Error('video recording is already running');
609
+ }
610
+ if (typeof MediaRecorder === 'undefined') {
611
+ throw new Error('MediaRecorder API is not available in this browser');
612
+ }
613
+ const stream = video.srcObject;
614
+ const supportsWebmVp9 = MediaRecorder.isTypeSupported('video/webm;codecs=vp9');
615
+ const supportsWebmVp8 = MediaRecorder.isTypeSupported('video/webm;codecs=vp8');
616
+ const mimeType = supportsWebmVp9
617
+ ? 'video/webm;codecs=vp9'
618
+ : supportsWebmVp8
619
+ ? 'video/webm;codecs=vp8'
620
+ : 'video/webm';
621
+ this.recordedChunks = [];
622
+ this.mediaRecorder = new MediaRecorder(stream, { mimeType });
623
+ this.mediaRecorder.ondataavailable = (event) => {
624
+ if (event.data && event.data.size > 0) {
625
+ this.recordedChunks.push(event.data);
626
+ }
627
+ };
628
+ this.mediaRecorder.start();
575
629
  }
576
630
  async getSupportedFlashModes() {
577
631
  throw new Error('getSupportedFlashModes not supported under the web platform');