@capgo/camera-preview 8.12.5 → 8.13.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 +13 -12
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraPreview.java +13 -2
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraXView.java +17 -4
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CaptureOrientationResolver.java +28 -0
- package/android/src/test/java/app/capgo/capacitor/camera/preview/CaptureOrientationResolverTest.java +31 -0
- package/dist/docs.json +16 -0
- package/dist/esm/definitions.d.ts +8 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/CameraController.swift +94 -33
- package/ios/Sources/CapgoCameraPreviewPlugin/CaptureImageExifEncoder.swift +88 -0
- package/ios/Sources/CapgoCameraPreviewPlugin/CaptureLifecycleCoordination.swift +37 -0
- package/ios/Sources/CapgoCameraPreviewPlugin/CaptureOrientationResolver.swift +23 -0
- package/ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift +18 -82
- package/ios/Tests/CameraPreviewPluginTests/CaptureImageExifEncoderTests.swift +141 -0
- package/ios/Tests/CameraPreviewPluginTests/CaptureLifecycleCoordinationTests.swift +73 -0
- package/ios/Tests/CameraPreviewPluginTests/CaptureOrientationResolverTests.swift +30 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1633,18 +1633,19 @@ Represents EXIF data extracted from an image.
|
|
|
1633
1633
|
|
|
1634
1634
|
Defines the options for capturing a picture.
|
|
1635
1635
|
|
|
1636
|
-
| Prop | Type | Description | Default
|
|
1637
|
-
| -------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1638
|
-
| **`height`** | <code>number</code> | The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. |
|
|
1639
|
-
| **`width`** | <code>number</code> | The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. |
|
|
1640
|
-
| **`quality`** | <code>number</code> | The quality of the captured image, from 0 to 100. Does not apply to `png` format. | <code>85</code>
|
|
1641
|
-
| **`format`** | <code><a href="#pictureformat">PictureFormat</a></code> | The format of the captured image. | <code>"jpeg"</code>
|
|
1642
|
-
| **`saveToGallery`** | <code>boolean</code> | If true, the captured image will be saved to the user's gallery. | <code>false</code>
|
|
1643
|
-
| **`withExifLocation`** | <code>boolean</code> | If true, the plugin will attempt to add GPS location data to the image's EXIF metadata. This may prompt the user for location permissions. | <code>false</code>
|
|
1644
|
-
| **`embedTimestamp`** | <code>boolean</code> | If true, the plugin will embed a timestamp in the top-right corner of the image. | <code>false</code>
|
|
1645
|
-
| **`embedLocation`** | <code>boolean</code> | If true, the plugin will embed the current location in the top-right corner of the image. Requires `withExifLocation` to be enabled. | <code>false</code>
|
|
1646
|
-
| **`photoQualityPrioritization`** | <code>'speed' \| 'balanced' \| 'quality'</code> | Sets the priority for photo quality vs. capture speed. - "speed": Prioritizes faster capture times, may reduce image quality. - "balanced": Aims for a balance between quality and speed. - "quality": Prioritizes image quality, may reduce capture speed. See https://developer.apple.com/documentation/avfoundation/avcapturephotosettings/photoqualityprioritization for details. | <code>"speed"</code>
|
|
1647
|
-
| **`mirrorFrontCamera`** | <code>boolean</code> | If true and the front camera is active, horizontally mirror the captured photo so it matches a selfie-style preview. Rear camera captures are never mirrored. Defaults to false to preserve the previous non-mirrored behavior. | <code>false</code>
|
|
1636
|
+
| Prop | Type | Description | Default | Since |
|
|
1637
|
+
| -------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------ |
|
|
1638
|
+
| **`height`** | <code>number</code> | The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. | | |
|
|
1639
|
+
| **`width`** | <code>number</code> | The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. | | |
|
|
1640
|
+
| **`quality`** | <code>number</code> | The quality of the captured image, from 0 to 100. Does not apply to `png` format. | <code>85</code> | |
|
|
1641
|
+
| **`format`** | <code><a href="#pictureformat">PictureFormat</a></code> | The format of the captured image. | <code>"jpeg"</code> | |
|
|
1642
|
+
| **`saveToGallery`** | <code>boolean</code> | If true, the captured image will be saved to the user's gallery. | <code>false</code> | 7.5.0 |
|
|
1643
|
+
| **`withExifLocation`** | <code>boolean</code> | If true, the plugin will attempt to add GPS location data to the image's EXIF metadata. This may prompt the user for location permissions. | <code>false</code> | 7.6.0 |
|
|
1644
|
+
| **`embedTimestamp`** | <code>boolean</code> | If true, the plugin will embed a timestamp in the top-right corner of the image. | <code>false</code> | 7.17.0 |
|
|
1645
|
+
| **`embedLocation`** | <code>boolean</code> | If true, the plugin will embed the current location in the top-right corner of the image. Requires `withExifLocation` to be enabled. | <code>false</code> | 7.18.0 |
|
|
1646
|
+
| **`photoQualityPrioritization`** | <code>'speed' \| 'balanced' \| 'quality'</code> | Sets the priority for photo quality vs. capture speed. - "speed": Prioritizes faster capture times, may reduce image quality. - "balanced": Aims for a balance between quality and speed. - "quality": Prioritizes image quality, may reduce capture speed. See https://developer.apple.com/documentation/avfoundation/avcapturephotosettings/photoqualityprioritization for details. | <code>"speed"</code> | 7.21.0 |
|
|
1647
|
+
| **`mirrorFrontCamera`** | <code>boolean</code> | If true and the front camera is active, horizontally mirror the captured photo so it matches a selfie-style preview. Rear camera captures are never mirrored. Defaults to false to preserve the previous non-mirrored behavior. | <code>false</code> | 8.10.0 |
|
|
1648
|
+
| **`orientation`** | <code>'preview' \| 'device'</code> | Which orientation to apply to the captured photo. - `"device"`: uses physical device tilt from the accelerometer (default). Preserves landscape captures when the app UI is rotation-locked. - `"preview"`: matches the on-screen preview. Use for WYSIWYG capture, including retakes without stopping the camera. | <code>"device"</code> | 8.13.0 |
|
|
1648
1649
|
|
|
1649
1650
|
|
|
1650
1651
|
#### CameraSampleOptions
|
|
@@ -521,8 +521,19 @@ public class CameraPreview extends Plugin implements CameraXView.CameraXViewList
|
|
|
521
521
|
final boolean embedTimestamp = Boolean.TRUE.equals(call.getBoolean("embedTimestamp"));
|
|
522
522
|
final boolean embedLocation = Boolean.TRUE.equals(call.getBoolean("embedLocation"));
|
|
523
523
|
final boolean mirrorFrontCamera = Boolean.TRUE.equals(call.getBoolean("mirrorFrontCamera"));
|
|
524
|
-
|
|
525
|
-
|
|
524
|
+
final String orientation = call.getString("orientation", CaptureOrientationResolver.ORIENTATION_DEVICE);
|
|
525
|
+
|
|
526
|
+
cameraXView.capturePhoto(
|
|
527
|
+
quality,
|
|
528
|
+
saveToGallery,
|
|
529
|
+
width,
|
|
530
|
+
height,
|
|
531
|
+
location,
|
|
532
|
+
embedTimestamp,
|
|
533
|
+
embedLocation,
|
|
534
|
+
mirrorFrontCamera,
|
|
535
|
+
orientation
|
|
536
|
+
);
|
|
526
537
|
}
|
|
527
538
|
|
|
528
539
|
@PluginMethod
|
|
@@ -2251,7 +2251,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2251
2251
|
Location location,
|
|
2252
2252
|
final boolean embedTimestamp,
|
|
2253
2253
|
final boolean embedLocation,
|
|
2254
|
-
final boolean mirrorFrontCamera
|
|
2254
|
+
final boolean mirrorFrontCamera,
|
|
2255
|
+
String orientationMode
|
|
2255
2256
|
) {
|
|
2256
2257
|
if (imageCapture == null) {
|
|
2257
2258
|
if (listener != null) {
|
|
@@ -2266,11 +2267,23 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2266
2267
|
return;
|
|
2267
2268
|
}
|
|
2268
2269
|
|
|
2269
|
-
|
|
2270
|
-
int
|
|
2270
|
+
int displayRotation = getDisplayRotationFallback();
|
|
2271
|
+
int deviceRotation = getRotationFromAccelerometer();
|
|
2272
|
+
int rotation = CaptureOrientationResolver.resolveRotation(orientationMode, displayRotation, deviceRotation);
|
|
2271
2273
|
lastCaptureRotation = rotation;
|
|
2272
2274
|
imageCapture.setTargetRotation(rotation);
|
|
2273
|
-
Log.d(
|
|
2275
|
+
Log.d(
|
|
2276
|
+
TAG,
|
|
2277
|
+
"capturePhoto: Set target rotation to " +
|
|
2278
|
+
rotation +
|
|
2279
|
+
" (mode=" +
|
|
2280
|
+
orientationMode +
|
|
2281
|
+
", display=" +
|
|
2282
|
+
displayRotation +
|
|
2283
|
+
", device=" +
|
|
2284
|
+
deviceRotation +
|
|
2285
|
+
")"
|
|
2286
|
+
);
|
|
2274
2287
|
|
|
2275
2288
|
Log.d(
|
|
2276
2289
|
TAG,
|
package/android/src/main/java/app/capgo/capacitor/camera/preview/CaptureOrientationResolver.java
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package app.capgo.capacitor.camera.preview;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Chooses whether still capture uses on-screen preview rotation or physical device rotation.
|
|
5
|
+
*/
|
|
6
|
+
public final class CaptureOrientationResolver {
|
|
7
|
+
|
|
8
|
+
public static final String ORIENTATION_PREVIEW = "preview";
|
|
9
|
+
public static final String ORIENTATION_DEVICE = "device";
|
|
10
|
+
|
|
11
|
+
private CaptureOrientationResolver() {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param orientationMode {@link #ORIENTATION_PREVIEW}, {@link #ORIENTATION_DEVICE}, or null/empty for device.
|
|
15
|
+
* @param displayRotation rotation matching the preview (typically {@link android.view.Display#getRotation()}).
|
|
16
|
+
* @param deviceRotation rotation from the accelerometer / physical resolver.
|
|
17
|
+
*/
|
|
18
|
+
public static int resolveRotation(String orientationMode, int displayRotation, int deviceRotation) {
|
|
19
|
+
if (ORIENTATION_PREVIEW.equals(orientationMode)) {
|
|
20
|
+
return displayRotation;
|
|
21
|
+
}
|
|
22
|
+
return deviceRotation;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static boolean usesDeviceOrientation(String orientationMode) {
|
|
26
|
+
return !ORIENTATION_PREVIEW.equals(orientationMode);
|
|
27
|
+
}
|
|
28
|
+
}
|
package/android/src/test/java/app/capgo/capacitor/camera/preview/CaptureOrientationResolverTest.java
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package app.capgo.capacitor.camera.preview;
|
|
2
|
+
|
|
3
|
+
import static org.junit.Assert.assertEquals;
|
|
4
|
+
import static org.junit.Assert.assertFalse;
|
|
5
|
+
import static org.junit.Assert.assertTrue;
|
|
6
|
+
|
|
7
|
+
import android.view.Surface;
|
|
8
|
+
import org.junit.Test;
|
|
9
|
+
import org.junit.runner.RunWith;
|
|
10
|
+
import org.robolectric.RobolectricTestRunner;
|
|
11
|
+
import org.robolectric.annotation.Config;
|
|
12
|
+
|
|
13
|
+
@RunWith(RobolectricTestRunner.class)
|
|
14
|
+
@Config(manifest = Config.NONE, sdk = 28)
|
|
15
|
+
public class CaptureOrientationResolverTest {
|
|
16
|
+
|
|
17
|
+
@Test
|
|
18
|
+
public void defaultsToDeviceRotation() {
|
|
19
|
+
assertEquals(Surface.ROTATION_90, CaptureOrientationResolver.resolveRotation(null, Surface.ROTATION_0, Surface.ROTATION_90));
|
|
20
|
+
assertEquals(Surface.ROTATION_90, CaptureOrientationResolver.resolveRotation("", Surface.ROTATION_0, Surface.ROTATION_90));
|
|
21
|
+
assertEquals(Surface.ROTATION_90, CaptureOrientationResolver.resolveRotation("device", Surface.ROTATION_0, Surface.ROTATION_90));
|
|
22
|
+
assertTrue(CaptureOrientationResolver.usesDeviceOrientation(null));
|
|
23
|
+
assertTrue(CaptureOrientationResolver.usesDeviceOrientation("device"));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Test
|
|
27
|
+
public void previewModeUsesDisplayRotation() {
|
|
28
|
+
assertEquals(Surface.ROTATION_270, CaptureOrientationResolver.resolveRotation("preview", Surface.ROTATION_270, Surface.ROTATION_0));
|
|
29
|
+
assertFalse(CaptureOrientationResolver.usesDeviceOrientation("preview"));
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/docs.json
CHANGED
|
@@ -2489,6 +2489,22 @@
|
|
|
2489
2489
|
"docs": "If true and the front camera is active, horizontally mirror the captured photo\nso it matches a selfie-style preview. Rear camera captures are never mirrored.\nDefaults to false to preserve the previous non-mirrored behavior.",
|
|
2490
2490
|
"complexTypes": [],
|
|
2491
2491
|
"type": "boolean | undefined"
|
|
2492
|
+
},
|
|
2493
|
+
{
|
|
2494
|
+
"name": "orientation",
|
|
2495
|
+
"tags": [
|
|
2496
|
+
{
|
|
2497
|
+
"text": "\"device\"",
|
|
2498
|
+
"name": "default"
|
|
2499
|
+
},
|
|
2500
|
+
{
|
|
2501
|
+
"text": "8.13.0",
|
|
2502
|
+
"name": "since"
|
|
2503
|
+
}
|
|
2504
|
+
],
|
|
2505
|
+
"docs": "Which orientation to apply to the captured photo.\n- `\"device\"`: uses physical device tilt from the accelerometer (default). Preserves landscape captures when the app UI is rotation-locked.\n- `\"preview\"`: matches the on-screen preview. Use for WYSIWYG capture, including retakes without stopping the camera.",
|
|
2506
|
+
"complexTypes": [],
|
|
2507
|
+
"type": "'preview' | 'device' | undefined"
|
|
2492
2508
|
}
|
|
2493
2509
|
]
|
|
2494
2510
|
},
|
|
@@ -475,6 +475,14 @@ export interface CameraPreviewPictureOptions {
|
|
|
475
475
|
* @since 8.10.0
|
|
476
476
|
*/
|
|
477
477
|
mirrorFrontCamera?: boolean;
|
|
478
|
+
/**
|
|
479
|
+
* Which orientation to apply to the captured photo.
|
|
480
|
+
* - `"device"`: uses physical device tilt from the accelerometer (default). Preserves landscape captures when the app UI is rotation-locked.
|
|
481
|
+
* - `"preview"`: matches the on-screen preview. Use for WYSIWYG capture, including retakes without stopping the camera.
|
|
482
|
+
* @default "device"
|
|
483
|
+
* @since 8.13.0
|
|
484
|
+
*/
|
|
485
|
+
orientation?: 'preview' | 'device';
|
|
478
486
|
}
|
|
479
487
|
/** Represents EXIF data extracted from an image. */
|
|
480
488
|
export interface ExifData {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA2FA,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 type CameraPreviewAspectRatio = '4:3' | '16:9' | 'fill';\n\n/**\n * Target still-capture resolution for the Android `ImageCapture` use case.\n *\n * Width and height define the resolution strategy target. The plugin also filters out\n * supported capture sizes whose long edge exceeds `max(width, height)`.\n */\nexport interface CameraCaptureResolution {\n /** Target width in pixels. */\n width: number;\n /** Target height in pixels. */\n height: number;\n}\n\nexport type BarcodeScannerFormat =\n | 'aztec'\n | 'codabar'\n | 'code_39'\n | 'code_93'\n | 'code_128'\n | 'data_matrix'\n | 'ean_8'\n | 'ean_13'\n | 'itf'\n | 'pdf417'\n | 'qr_code'\n | 'upc_a'\n | 'upc_e';\n\nexport type BarcodeFormat = BarcodeScannerFormat | 'unknown';\n\nexport interface BarcodeScannerOptions {\n /**\n * Restricts detection to the given formats. Leaving this empty scans all supported formats.\n * Restricting formats can improve scanning speed.\n */\n formats?: BarcodeScannerFormat[];\n /**\n * Minimum delay between native scan attempts in milliseconds.\n * Lower values scan more often but use more CPU.\n * @default 500\n */\n detectionInterval?: number;\n}\n\nexport interface BarcodeScanResult {\n /** Decoded barcode value. */\n value: string;\n /** Barcode format. */\n format: BarcodeFormat;\n /** Human-readable value when the platform exposes one. */\n displayValue?: string;\n /** Base64-encoded raw bytes when the platform exposes them. */\n rawBytes?: string;\n}\n\nexport interface BarcodeScannedEvent {\n /** Barcodes decoded from the current frame. */\n barcodes: BarcodeScanResult[];\n}\n\nexport interface BarcodeScanErrorEvent {\n /** Native scanner error message. */\n message: string;\n}\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\nexport type VideoQuality = 'low' | 'medium' | 'high' | '2160p' | '1080p' | '720p' | '480p' | '4:3';\n\n/**\n * Video codec identifiers used when recording.\n * - `avc1`: H.264\n * - `hvc1`: HEVC / H.265\n */\nexport type VideoCodec = 'avc1' | 'hvc1' | 'jpeg' | 'apcn' | 'ap4h';\n\n/**\n * Video stabilization modes used when recording.\n *\n * On Android only `off` and `standard` are supported.\n * On iOS all listed modes may be available when the device supports video stabilization.\n */\nexport type VideoStabilizationMode =\n | 'off'\n | 'standard'\n | 'cinematic'\n | 'cinematicExtended'\n | 'previewOptimized'\n | 'cinematicExtendedEnhanced'\n | 'auto'\n | 'lowLatency';\n\nexport type RecordingFinishedReason = 'manual' | 'maxDuration' | 'maxFileSize';\n\nexport interface RecordingFinishedEvent {\n /**\n * The path to the recorded video file.\n */\n videoFilePath: string;\n /**\n * Why the recording stopped.\n */\n reason: RecordingFinishedReason;\n}\n\n/**\n * Emitted when the native capture session is interrupted (for example during a phone call).\n *\n * @since 8.11.7\n * @platform ios\n */\nexport interface CameraInterruptedEvent {\n /**\n * Why the session was interrupted.\n */\n reason: 'runtimeError' | 'interrupted';\n /**\n * When true, the plugin removed the microphone input and continued with video only.\n */\n audioDropped: boolean;\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?: CameraPreviewAspectRatio;\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 android, 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 * On Android, attempts to bind a physical camera directly when `deviceId` refers to a physical lens.\n * Disabled by default because OEM support is inconsistent; when false, Android keeps the current logical-camera fallback behavior.\n * @default false\n * @platform android\n */\n enablePhysicalDeviceSelection?: boolean;\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, ios\n * @since 7.11.0\n */\n enableVideoMode?: boolean;\n /**\n * Sets the still-capture sensor resolution cap at session start. Preview resolution is unchanged.\n * The shared ViewPort crop from the preview still applies to captures.\n *\n * On Android this binds the `ImageCapture` use case to the requested size. On iOS 16+ this sets\n * `AVCapturePhotoSettings.maxPhotoDimensions` (and disables high-resolution photo capture when capped)\n * so the sensor delivers fewer pixels instead of downscaling a full-sensor frame in software.\n * On iOS 15, `start()` rejects this option.\n *\n * When omitted, capture uses the highest resolution supported by the active camera\n * (same as versions before 8.11.10 on Android, and the format default on iOS). Set this to cap\n * capture size for faster shots on high-megapixel sensors, for example `{ width: 1920, height: 1080 }`\n * or `{ width: 1600, height: 1200 }`.\n *\n * @platform android, ios\n * @since 8.12.0\n * @since 8.13.0 (iOS)\n */\n captureResolution?: CameraCaptureResolution;\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', '2160p', '1080p', '720p', '480p', '4:3'\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?: VideoQuality;\n /**\n * Maximum recording duration in seconds. Recording stops automatically when reached.\n * @platform ios, android\n */\n maxDuration?: number;\n /**\n * Maximum recording file size in bytes. Recording stops automatically when reached.\n * @platform ios, android\n */\n maxFileSize?: number;\n /**\n * Preferred video codec for recording.\n * @platform ios, android\n * @default \"avc1\"\n */\n videoCodec?: VideoCodec;\n /**\n * Target video frame rate in frames per second.\n * Applied when recording starts. Use `getSupportedVideoFrameRates()` to list supported values.\n * @platform ios, android\n * @since 8.6.0\n */\n frameRate?: number;\n /**\n * Preferred video stabilization mode for recording.\n * @platform ios, android\n * @default \"off\"\n */\n videoStabilizationMode?: VideoStabilizationMode;\n /**\n * When `true`, allows haptic feedback and system sounds while recording video with audio.\n * iOS suppresses haptics during audio input recording unless this is enabled.\n * Requires `disableAudio: false`.\n * @platform ios\n * @default false\n * @since 8.8.0\n */\n allowHapticsAndSystemSoundsDuringRecording?: boolean;\n /**\n * When `true` and the front camera is active, mirrors the recorded video file\n * so it matches the selfie-style preview (text and gestures are not reversed).\n * Does not affect the live preview. Defaults to `false` to preserve existing behavior.\n * @platform ios, android\n * @default false\n * @since 8.10.0\n */\n mirrorFrontCamera?: boolean;\n /**\n * Starts barcode scanning together with the camera preview.\n * Set to `true` or pass options to scan all supported formats.\n * Omit this option to keep barcode scanning disabled at startup.\n * @platform android, ios, web\n * @since 8.8.0\n */\n barcodeScanner?: boolean | BarcodeScannerOptions;\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 * If true and the front camera is active, horizontally mirror the captured photo\n * so it matches a selfie-style preview. Rear camera captures are never mirrored.\n * Defaults to false to preserve the previous non-mirrored behavior.\n * @default false\n * @since 8.10.0\n */\n mirrorFrontCamera?: 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 * If true and the front camera is active, horizontally mirror the captured sample\n * so it matches a selfie-style preview. Rear camera samples are never mirrored.\n * Defaults to false to preserve the previous non-mirrored behavior.\n * @default false\n * @since 8.10.0\n */\n mirrorFrontCamera?: boolean;\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 * Reusable white-balance mode type for cross-platform support.\n * `CUSTOM` is reserved for a future manual white-balance gains API and is not\n * returned by `getWhiteBalanceModes()` until implemented.\n */\nexport type WhiteBalanceMode = '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 * Starts barcode scanning on the active camera preview.\n *\n * The scanner reuses the current camera session and emits `barcodeScanned` events.\n * Call `stopBarcodeScanner()` when scanning is no longer needed.\n *\n * Android uses the lightweight Google Play Services ML Kit model. If the model is not installed yet,\n * first scans may return no result until Google Play Services finishes downloading it.\n *\n * @since 8.8.0\n * @platform android, ios, web\n */\n startBarcodeScanner(options?: BarcodeScannerOptions): Promise<void>;\n\n /**\n * Stops barcode scanning while keeping the camera preview running.\n *\n * @since 8.8.0\n * @platform android, ios, web\n */\n stopBarcodeScanner(): Promise<void>;\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: CameraPreviewAspectRatio; x?: number; y?: number }} options - The desired aspect ratio and optional position.\n * - aspectRatio: The desired aspect ratio ('4:3', '16:9', or 'fill')\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: CameraPreviewAspectRatio; 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: CameraPreviewAspectRatio }>} A promise that resolves with the current aspect ratio.\n * @since 7.5.0\n * @platform android, ios\n */\n getAspectRatio(): Promise<{ aspectRatio: CameraPreviewAspectRatio }>;\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<RecordingFinishedEvent>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<RecordingFinishedEvent>;\n\n /**\n * Starts recording a video.\n *\n * Supports `frameRate`, `videoCodec`, `videoStabilizationMode`, `maxDuration`, `maxFileSize`, `disableAudio`, `allowHapticsAndSystemSoundsDuringRecording`, and `mirrorFrontCamera` on each call.\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 * Sets the video recording quality for the active camera session.\n *\n * @param {{ quality: VideoQuality }} options - The desired video quality.\n * @returns {Promise<void>} A promise that resolves when the quality is set.\n * @since 8.5.0\n * @platform android, ios\n */\n setVideoQuality(options: { quality: VideoQuality }): Promise<void>;\n\n /**\n * Gets the current video recording quality.\n *\n * @returns {Promise<{ quality: VideoQuality }>} A promise that resolves with the current quality.\n * @since 8.5.0\n * @platform android, ios\n */\n getVideoQuality(): Promise<{ quality: VideoQuality }>;\n\n /**\n * Returns the video qualities supported by the active camera.\n *\n * @returns {Promise<{ qualities: VideoQuality[] }>} A promise that resolves with supported qualities.\n * @since 8.5.0\n * @platform android, ios\n */\n getSupportedVideoQualities(): Promise<{ qualities: VideoQuality[] }>;\n\n /**\n * Sets the video codec used when recording.\n *\n * @param {{ codec: VideoCodec }} options - The desired codec.\n * @returns {Promise<void>} A promise that resolves when the codec is set.\n * @since 8.5.0\n * @platform android, ios\n */\n setVideoCodec(options: { codec: VideoCodec }): Promise<void>;\n\n /**\n * Gets the current video codec used for recording.\n *\n * @returns {Promise<{ codec: VideoCodec }>} A promise that resolves with the current codec.\n * @since 8.5.0\n * @platform android, ios\n */\n getVideoCodec(): Promise<{ codec: VideoCodec }>;\n\n /**\n * Returns the video codecs supported by the active camera.\n *\n * @returns {Promise<{ codecs: VideoCodec[] }>} A promise that resolves with supported codecs.\n * @since 8.5.0\n * @platform android, ios\n */\n getSupportedVideoCodecs(): Promise<{ codecs: VideoCodec[] }>;\n\n /**\n * Checks whether video stabilization is supported by the active camera.\n *\n * @returns {Promise<{ supported: boolean }>} A promise that resolves with the support state.\n * @since 8.5.2\n * @platform android, ios\n */\n isVideoStabilizationSupported(): Promise<{ supported: boolean }>;\n\n /**\n * Returns the video stabilization modes supported by the active camera.\n *\n * @returns {Promise<{ modes: VideoStabilizationMode[] }>} A promise that resolves with supported modes.\n * @since 8.5.2\n * @platform android, ios\n */\n getSupportedVideoStabilizationModes(): Promise<{ modes: VideoStabilizationMode[] }>;\n\n /**\n * Gets the current video stabilization mode.\n *\n * @returns {Promise<{ mode: VideoStabilizationMode }>} A promise that resolves with the current mode.\n * @since 8.5.2\n * @platform android, ios\n */\n getVideoStabilizationMode(): Promise<{ mode: VideoStabilizationMode }>;\n\n /**\n * Sets the video stabilization mode for recording.\n * Cannot be changed while a recording is in progress.\n * You can also pass `videoStabilizationMode` in `startRecordVideo()` options.\n *\n * @param {{ mode: VideoStabilizationMode }} options - The desired stabilization mode.\n * @returns {Promise<void>} A promise that resolves when the mode is set.\n * @since 8.5.2\n * @platform android, ios\n */\n setVideoStabilizationMode(options: { mode: VideoStabilizationMode }): 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 camera device that is currently bound.\n * On Android, if a physical-lens request falls back to a logical camera, this returns the bound logical camera ID.\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 visible camera preview bounds in web-view coordinates.\n *\n * With `aspectMode: 'contain'`, this is the letterboxed camera image rect inside the\n * preview container (not the full container when bars are shown). With `aspectMode: 'cover'`,\n * this matches the preview container bounds on both platforms.\n *\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 visible camera preview bounds (same contract as {@link CameraPreviewPlugin.getPreviewSize}).\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 /**\n * Adds a listener for barcode scan results.\n *\n * @since 8.8.0\n * @platform android, ios, web\n */\n addListener(\n eventName: 'barcodeScanned',\n listenerFunc: (data: BarcodeScannedEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for non-fatal barcode scanner errors.\n *\n * @since 8.8.0\n * @platform android, web\n */\n addListener(\n eventName: 'barcodeScanError',\n listenerFunc: (data: BarcodeScanErrorEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener fired when a video recording finishes natively, including automatic stops.\n *\n * @since 8.4.7\n * @platform android, ios\n */\n addListener(\n eventName: 'recordingFinished',\n listenerFunc: (data: RecordingFinishedEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for capture session interruptions (for example an active phone call).\n *\n * @since 8.11.7\n * @platform ios\n */\n addListener(\n eventName: 'cameraInterrupted',\n listenerFunc: (data: CameraInterruptedEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener fired when a capture session interruption ends.\n * Native recovery may still be restarting the session; wait for preview frames before assuming the stream is live.\n *\n * @since 8.11.7\n * @platform ios\n */\n addListener(eventName: 'cameraInterruptionEnded', listenerFunc: () => void): Promise<PluginListenerHandle>;\n\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 * Returns the white-balance modes supported by the active camera.\n * Modes can include: 'AUTO', 'LOCK', 'CONTINUOUS'. `CUSTOM` is not listed\n * until manual gains support is implemented.\n * @platform android, ios\n */\n getWhiteBalanceModes(): Promise<{ modes: WhiteBalanceMode[] }>;\n\n /**\n * Returns the current white-balance mode.\n * @platform android, ios\n */\n getWhiteBalanceMode(): Promise<{ mode: WhiteBalanceMode }>;\n\n /**\n * Sets the white-balance mode. `CONTINUOUS` keeps auto white balance running\n * (recommended; avoids a warm/yellow cast), `LOCK` freezes the current gains,\n * `AUTO` performs a one-time adjustment. `CUSTOM` is reserved and rejected\n * until manual gains support is implemented.\n * @platform android, ios\n */\n setWhiteBalanceMode(options: { mode: WhiteBalanceMode }): Promise<void>;\n\n /**\n * Lists the video frame rates supported by the active camera for the current format.\n * Supported values depend on the selected camera, lens, and video quality.\n *\n * @platform android, ios\n * @since 8.6.0\n */\n getSupportedVideoFrameRates(): Promise<{\n frameRates: number[];\n }>;\n\n /**\n * Returns the configured video frame rate for the active camera.\n * On Android the actual recording frame rate can still vary in low light or under thermal pressure.\n *\n * @platform android, ios\n * @since 8.6.0\n */\n getVideoFrameRate(): Promise<{\n frameRate: number;\n }>;\n\n /**\n * Sets the target video frame rate for the active camera session.\n * Prefer passing `frameRate` to `startRecordVideo()` when starting a recording.\n * Rejects unsupported values with a clear error.\n *\n * @platform android, ios\n * @since 8.6.0\n */\n setVideoFrameRate(options: { frameRate: 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":"AA2FA,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 type CameraPreviewAspectRatio = '4:3' | '16:9' | 'fill';\n\n/**\n * Target still-capture resolution for the Android `ImageCapture` use case.\n *\n * Width and height define the resolution strategy target. The plugin also filters out\n * supported capture sizes whose long edge exceeds `max(width, height)`.\n */\nexport interface CameraCaptureResolution {\n /** Target width in pixels. */\n width: number;\n /** Target height in pixels. */\n height: number;\n}\n\nexport type BarcodeScannerFormat =\n | 'aztec'\n | 'codabar'\n | 'code_39'\n | 'code_93'\n | 'code_128'\n | 'data_matrix'\n | 'ean_8'\n | 'ean_13'\n | 'itf'\n | 'pdf417'\n | 'qr_code'\n | 'upc_a'\n | 'upc_e';\n\nexport type BarcodeFormat = BarcodeScannerFormat | 'unknown';\n\nexport interface BarcodeScannerOptions {\n /**\n * Restricts detection to the given formats. Leaving this empty scans all supported formats.\n * Restricting formats can improve scanning speed.\n */\n formats?: BarcodeScannerFormat[];\n /**\n * Minimum delay between native scan attempts in milliseconds.\n * Lower values scan more often but use more CPU.\n * @default 500\n */\n detectionInterval?: number;\n}\n\nexport interface BarcodeScanResult {\n /** Decoded barcode value. */\n value: string;\n /** Barcode format. */\n format: BarcodeFormat;\n /** Human-readable value when the platform exposes one. */\n displayValue?: string;\n /** Base64-encoded raw bytes when the platform exposes them. */\n rawBytes?: string;\n}\n\nexport interface BarcodeScannedEvent {\n /** Barcodes decoded from the current frame. */\n barcodes: BarcodeScanResult[];\n}\n\nexport interface BarcodeScanErrorEvent {\n /** Native scanner error message. */\n message: string;\n}\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\nexport type VideoQuality = 'low' | 'medium' | 'high' | '2160p' | '1080p' | '720p' | '480p' | '4:3';\n\n/**\n * Video codec identifiers used when recording.\n * - `avc1`: H.264\n * - `hvc1`: HEVC / H.265\n */\nexport type VideoCodec = 'avc1' | 'hvc1' | 'jpeg' | 'apcn' | 'ap4h';\n\n/**\n * Video stabilization modes used when recording.\n *\n * On Android only `off` and `standard` are supported.\n * On iOS all listed modes may be available when the device supports video stabilization.\n */\nexport type VideoStabilizationMode =\n | 'off'\n | 'standard'\n | 'cinematic'\n | 'cinematicExtended'\n | 'previewOptimized'\n | 'cinematicExtendedEnhanced'\n | 'auto'\n | 'lowLatency';\n\nexport type RecordingFinishedReason = 'manual' | 'maxDuration' | 'maxFileSize';\n\nexport interface RecordingFinishedEvent {\n /**\n * The path to the recorded video file.\n */\n videoFilePath: string;\n /**\n * Why the recording stopped.\n */\n reason: RecordingFinishedReason;\n}\n\n/**\n * Emitted when the native capture session is interrupted (for example during a phone call).\n *\n * @since 8.11.7\n * @platform ios\n */\nexport interface CameraInterruptedEvent {\n /**\n * Why the session was interrupted.\n */\n reason: 'runtimeError' | 'interrupted';\n /**\n * When true, the plugin removed the microphone input and continued with video only.\n */\n audioDropped: boolean;\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?: CameraPreviewAspectRatio;\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 android, 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 * On Android, attempts to bind a physical camera directly when `deviceId` refers to a physical lens.\n * Disabled by default because OEM support is inconsistent; when false, Android keeps the current logical-camera fallback behavior.\n * @default false\n * @platform android\n */\n enablePhysicalDeviceSelection?: boolean;\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, ios\n * @since 7.11.0\n */\n enableVideoMode?: boolean;\n /**\n * Sets the still-capture sensor resolution cap at session start. Preview resolution is unchanged.\n * The shared ViewPort crop from the preview still applies to captures.\n *\n * On Android this binds the `ImageCapture` use case to the requested size. On iOS 16+ this sets\n * `AVCapturePhotoSettings.maxPhotoDimensions` (and disables high-resolution photo capture when capped)\n * so the sensor delivers fewer pixels instead of downscaling a full-sensor frame in software.\n * On iOS 15, `start()` rejects this option.\n *\n * When omitted, capture uses the highest resolution supported by the active camera\n * (same as versions before 8.11.10 on Android, and the format default on iOS). Set this to cap\n * capture size for faster shots on high-megapixel sensors, for example `{ width: 1920, height: 1080 }`\n * or `{ width: 1600, height: 1200 }`.\n *\n * @platform android, ios\n * @since 8.12.0\n * @since 8.13.0 (iOS)\n */\n captureResolution?: CameraCaptureResolution;\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', '2160p', '1080p', '720p', '480p', '4:3'\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?: VideoQuality;\n /**\n * Maximum recording duration in seconds. Recording stops automatically when reached.\n * @platform ios, android\n */\n maxDuration?: number;\n /**\n * Maximum recording file size in bytes. Recording stops automatically when reached.\n * @platform ios, android\n */\n maxFileSize?: number;\n /**\n * Preferred video codec for recording.\n * @platform ios, android\n * @default \"avc1\"\n */\n videoCodec?: VideoCodec;\n /**\n * Target video frame rate in frames per second.\n * Applied when recording starts. Use `getSupportedVideoFrameRates()` to list supported values.\n * @platform ios, android\n * @since 8.6.0\n */\n frameRate?: number;\n /**\n * Preferred video stabilization mode for recording.\n * @platform ios, android\n * @default \"off\"\n */\n videoStabilizationMode?: VideoStabilizationMode;\n /**\n * When `true`, allows haptic feedback and system sounds while recording video with audio.\n * iOS suppresses haptics during audio input recording unless this is enabled.\n * Requires `disableAudio: false`.\n * @platform ios\n * @default false\n * @since 8.8.0\n */\n allowHapticsAndSystemSoundsDuringRecording?: boolean;\n /**\n * When `true` and the front camera is active, mirrors the recorded video file\n * so it matches the selfie-style preview (text and gestures are not reversed).\n * Does not affect the live preview. Defaults to `false` to preserve existing behavior.\n * @platform ios, android\n * @default false\n * @since 8.10.0\n */\n mirrorFrontCamera?: boolean;\n /**\n * Starts barcode scanning together with the camera preview.\n * Set to `true` or pass options to scan all supported formats.\n * Omit this option to keep barcode scanning disabled at startup.\n * @platform android, ios, web\n * @since 8.8.0\n */\n barcodeScanner?: boolean | BarcodeScannerOptions;\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 * If true and the front camera is active, horizontally mirror the captured photo\n * so it matches a selfie-style preview. Rear camera captures are never mirrored.\n * Defaults to false to preserve the previous non-mirrored behavior.\n * @default false\n * @since 8.10.0\n */\n mirrorFrontCamera?: boolean;\n /**\n * Which orientation to apply to the captured photo.\n * - `\"device\"`: uses physical device tilt from the accelerometer (default). Preserves landscape captures when the app UI is rotation-locked.\n * - `\"preview\"`: matches the on-screen preview. Use for WYSIWYG capture, including retakes without stopping the camera.\n * @default \"device\"\n * @since 8.13.0\n */\n orientation?: 'preview' | 'device';\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 * If true and the front camera is active, horizontally mirror the captured sample\n * so it matches a selfie-style preview. Rear camera samples are never mirrored.\n * Defaults to false to preserve the previous non-mirrored behavior.\n * @default false\n * @since 8.10.0\n */\n mirrorFrontCamera?: boolean;\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 * Reusable white-balance mode type for cross-platform support.\n * `CUSTOM` is reserved for a future manual white-balance gains API and is not\n * returned by `getWhiteBalanceModes()` until implemented.\n */\nexport type WhiteBalanceMode = '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 * Starts barcode scanning on the active camera preview.\n *\n * The scanner reuses the current camera session and emits `barcodeScanned` events.\n * Call `stopBarcodeScanner()` when scanning is no longer needed.\n *\n * Android uses the lightweight Google Play Services ML Kit model. If the model is not installed yet,\n * first scans may return no result until Google Play Services finishes downloading it.\n *\n * @since 8.8.0\n * @platform android, ios, web\n */\n startBarcodeScanner(options?: BarcodeScannerOptions): Promise<void>;\n\n /**\n * Stops barcode scanning while keeping the camera preview running.\n *\n * @since 8.8.0\n * @platform android, ios, web\n */\n stopBarcodeScanner(): Promise<void>;\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: CameraPreviewAspectRatio; x?: number; y?: number }} options - The desired aspect ratio and optional position.\n * - aspectRatio: The desired aspect ratio ('4:3', '16:9', or 'fill')\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: CameraPreviewAspectRatio; 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: CameraPreviewAspectRatio }>} A promise that resolves with the current aspect ratio.\n * @since 7.5.0\n * @platform android, ios\n */\n getAspectRatio(): Promise<{ aspectRatio: CameraPreviewAspectRatio }>;\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<RecordingFinishedEvent>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<RecordingFinishedEvent>;\n\n /**\n * Starts recording a video.\n *\n * Supports `frameRate`, `videoCodec`, `videoStabilizationMode`, `maxDuration`, `maxFileSize`, `disableAudio`, `allowHapticsAndSystemSoundsDuringRecording`, and `mirrorFrontCamera` on each call.\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 * Sets the video recording quality for the active camera session.\n *\n * @param {{ quality: VideoQuality }} options - The desired video quality.\n * @returns {Promise<void>} A promise that resolves when the quality is set.\n * @since 8.5.0\n * @platform android, ios\n */\n setVideoQuality(options: { quality: VideoQuality }): Promise<void>;\n\n /**\n * Gets the current video recording quality.\n *\n * @returns {Promise<{ quality: VideoQuality }>} A promise that resolves with the current quality.\n * @since 8.5.0\n * @platform android, ios\n */\n getVideoQuality(): Promise<{ quality: VideoQuality }>;\n\n /**\n * Returns the video qualities supported by the active camera.\n *\n * @returns {Promise<{ qualities: VideoQuality[] }>} A promise that resolves with supported qualities.\n * @since 8.5.0\n * @platform android, ios\n */\n getSupportedVideoQualities(): Promise<{ qualities: VideoQuality[] }>;\n\n /**\n * Sets the video codec used when recording.\n *\n * @param {{ codec: VideoCodec }} options - The desired codec.\n * @returns {Promise<void>} A promise that resolves when the codec is set.\n * @since 8.5.0\n * @platform android, ios\n */\n setVideoCodec(options: { codec: VideoCodec }): Promise<void>;\n\n /**\n * Gets the current video codec used for recording.\n *\n * @returns {Promise<{ codec: VideoCodec }>} A promise that resolves with the current codec.\n * @since 8.5.0\n * @platform android, ios\n */\n getVideoCodec(): Promise<{ codec: VideoCodec }>;\n\n /**\n * Returns the video codecs supported by the active camera.\n *\n * @returns {Promise<{ codecs: VideoCodec[] }>} A promise that resolves with supported codecs.\n * @since 8.5.0\n * @platform android, ios\n */\n getSupportedVideoCodecs(): Promise<{ codecs: VideoCodec[] }>;\n\n /**\n * Checks whether video stabilization is supported by the active camera.\n *\n * @returns {Promise<{ supported: boolean }>} A promise that resolves with the support state.\n * @since 8.5.2\n * @platform android, ios\n */\n isVideoStabilizationSupported(): Promise<{ supported: boolean }>;\n\n /**\n * Returns the video stabilization modes supported by the active camera.\n *\n * @returns {Promise<{ modes: VideoStabilizationMode[] }>} A promise that resolves with supported modes.\n * @since 8.5.2\n * @platform android, ios\n */\n getSupportedVideoStabilizationModes(): Promise<{ modes: VideoStabilizationMode[] }>;\n\n /**\n * Gets the current video stabilization mode.\n *\n * @returns {Promise<{ mode: VideoStabilizationMode }>} A promise that resolves with the current mode.\n * @since 8.5.2\n * @platform android, ios\n */\n getVideoStabilizationMode(): Promise<{ mode: VideoStabilizationMode }>;\n\n /**\n * Sets the video stabilization mode for recording.\n * Cannot be changed while a recording is in progress.\n * You can also pass `videoStabilizationMode` in `startRecordVideo()` options.\n *\n * @param {{ mode: VideoStabilizationMode }} options - The desired stabilization mode.\n * @returns {Promise<void>} A promise that resolves when the mode is set.\n * @since 8.5.2\n * @platform android, ios\n */\n setVideoStabilizationMode(options: { mode: VideoStabilizationMode }): 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 camera device that is currently bound.\n * On Android, if a physical-lens request falls back to a logical camera, this returns the bound logical camera ID.\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 visible camera preview bounds in web-view coordinates.\n *\n * With `aspectMode: 'contain'`, this is the letterboxed camera image rect inside the\n * preview container (not the full container when bars are shown). With `aspectMode: 'cover'`,\n * this matches the preview container bounds on both platforms.\n *\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 visible camera preview bounds (same contract as {@link CameraPreviewPlugin.getPreviewSize}).\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 /**\n * Adds a listener for barcode scan results.\n *\n * @since 8.8.0\n * @platform android, ios, web\n */\n addListener(\n eventName: 'barcodeScanned',\n listenerFunc: (data: BarcodeScannedEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for non-fatal barcode scanner errors.\n *\n * @since 8.8.0\n * @platform android, web\n */\n addListener(\n eventName: 'barcodeScanError',\n listenerFunc: (data: BarcodeScanErrorEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener fired when a video recording finishes natively, including automatic stops.\n *\n * @since 8.4.7\n * @platform android, ios\n */\n addListener(\n eventName: 'recordingFinished',\n listenerFunc: (data: RecordingFinishedEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for capture session interruptions (for example an active phone call).\n *\n * @since 8.11.7\n * @platform ios\n */\n addListener(\n eventName: 'cameraInterrupted',\n listenerFunc: (data: CameraInterruptedEvent) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener fired when a capture session interruption ends.\n * Native recovery may still be restarting the session; wait for preview frames before assuming the stream is live.\n *\n * @since 8.11.7\n * @platform ios\n */\n addListener(eventName: 'cameraInterruptionEnded', listenerFunc: () => void): Promise<PluginListenerHandle>;\n\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 * Returns the white-balance modes supported by the active camera.\n * Modes can include: 'AUTO', 'LOCK', 'CONTINUOUS'. `CUSTOM` is not listed\n * until manual gains support is implemented.\n * @platform android, ios\n */\n getWhiteBalanceModes(): Promise<{ modes: WhiteBalanceMode[] }>;\n\n /**\n * Returns the current white-balance mode.\n * @platform android, ios\n */\n getWhiteBalanceMode(): Promise<{ mode: WhiteBalanceMode }>;\n\n /**\n * Sets the white-balance mode. `CONTINUOUS` keeps auto white balance running\n * (recommended; avoids a warm/yellow cast), `LOCK` freezes the current gains,\n * `AUTO` performs a one-time adjustment. `CUSTOM` is reserved and rejected\n * until manual gains support is implemented.\n * @platform android, ios\n */\n setWhiteBalanceMode(options: { mode: WhiteBalanceMode }): Promise<void>;\n\n /**\n * Lists the video frame rates supported by the active camera for the current format.\n * Supported values depend on the selected camera, lens, and video quality.\n *\n * @platform android, ios\n * @since 8.6.0\n */\n getSupportedVideoFrameRates(): Promise<{\n frameRates: number[];\n }>;\n\n /**\n * Returns the configured video frame rate for the active camera.\n * On Android the actual recording frame rate can still vary in low light or under thermal pressure.\n *\n * @platform android, ios\n * @since 8.6.0\n */\n getVideoFrameRate(): Promise<{\n frameRate: number;\n }>;\n\n /**\n * Sets the target video frame rate for the active camera session.\n * Prefer passing `frameRate` to `startRecordVideo()` when starting a recording.\n * Rejects unsupported values with a clear error.\n *\n * @platform android, ios\n * @since 8.6.0\n */\n setVideoFrameRate(options: { frameRate: 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"]}
|
|
@@ -55,6 +55,22 @@ class CameraController: NSObject, CXCallObserverDelegate {
|
|
|
55
55
|
return orientation
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
private func getPreviewLayerVideoOrientation() -> AVCaptureVideoOrientation? {
|
|
59
|
+
if Thread.isMainThread {
|
|
60
|
+
if let connection = self.previewLayer?.connection, connection.isVideoOrientationSupported {
|
|
61
|
+
return connection.videoOrientation
|
|
62
|
+
}
|
|
63
|
+
return nil
|
|
64
|
+
}
|
|
65
|
+
var orientation: AVCaptureVideoOrientation?
|
|
66
|
+
DispatchQueue.main.sync {
|
|
67
|
+
if let connection = self.previewLayer?.connection, connection.isVideoOrientationSupported {
|
|
68
|
+
orientation = connection.videoOrientation
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return orientation
|
|
72
|
+
}
|
|
73
|
+
|
|
58
74
|
// For capture only - uses accelerometer to detect physical orientation to properly position videos/images
|
|
59
75
|
private var lastReliableCaptureOrientation: AVCaptureVideoOrientation?
|
|
60
76
|
|
|
@@ -482,9 +498,30 @@ class CameraController: NSObject, CXCallObserverDelegate {
|
|
|
482
498
|
// Track output preparation status
|
|
483
499
|
private var outputsPrepared: Bool = false
|
|
484
500
|
|
|
485
|
-
// Capture/stop coordination
|
|
486
|
-
var
|
|
487
|
-
|
|
501
|
+
// Capture/stop coordination (main-thread only; see CaptureLifecycleCoordination)
|
|
502
|
+
var captureLifecycle = CaptureLifecycleState()
|
|
503
|
+
|
|
504
|
+
var isCapturingPhoto: Bool {
|
|
505
|
+
get { self.captureLifecycle.isCapturingPhoto }
|
|
506
|
+
set { self.captureLifecycle.isCapturingPhoto = newValue }
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
var stopRequestedAfterCapture: Bool {
|
|
510
|
+
get { self.captureLifecycle.stopRequestedAfterCapture }
|
|
511
|
+
set { self.captureLifecycle.stopRequestedAfterCapture = newValue }
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
func finishPhotoCaptureLifecycle() {
|
|
515
|
+
let work = { [weak self] in
|
|
516
|
+
guard let self = self else { return }
|
|
517
|
+
CaptureLifecycleCoordination.finishCapture(state: &self.captureLifecycle, cleanup: { self.cleanup() })
|
|
518
|
+
}
|
|
519
|
+
if Thread.isMainThread {
|
|
520
|
+
work()
|
|
521
|
+
} else {
|
|
522
|
+
DispatchQueue.main.async(execute: work)
|
|
523
|
+
}
|
|
524
|
+
}
|
|
488
525
|
|
|
489
526
|
var isUsingMultiLensVirtualCamera: Bool {
|
|
490
527
|
guard let device = (currentCameraPosition == .rear) ? rearCamera : frontCamera else { return false }
|
|
@@ -1505,21 +1542,29 @@ extension CameraController {
|
|
|
1505
1542
|
self.updateVideoOrientation()
|
|
1506
1543
|
}
|
|
1507
1544
|
|
|
1508
|
-
func captureImage(width: Int?, height: Int?, quality: Float, gpsLocation: CLLocation?, embedTimestamp: Bool, embedLocation: Bool, photoQualityPrioritization: String, completion: @escaping (UIImage?, Data?, [AnyHashable: Any]?, Error?) -> Void) {
|
|
1545
|
+
func captureImage(width: Int?, height: Int?, quality: Float, gpsLocation: CLLocation?, embedTimestamp: Bool, embedLocation: Bool, photoQualityPrioritization: String, captureOrientationMode: String?, completion: @escaping (UIImage?, Data?, [AnyHashable: Any]?, Error?) -> Void) {
|
|
1509
1546
|
guard let photoOutput = self.photoOutput else {
|
|
1510
1547
|
completion(nil, nil, nil, NSError(domain: "Camera", code: 0, userInfo: [NSLocalizedDescriptionKey: "Photo output is not available"]))
|
|
1511
1548
|
return
|
|
1512
1549
|
}
|
|
1513
1550
|
|
|
1514
|
-
|
|
1551
|
+
var orientationUsedForCapture = self.getPhysicalOrientation()
|
|
1515
1552
|
if let connection = photoOutput.connection(with: .video) {
|
|
1516
|
-
let
|
|
1517
|
-
|
|
1553
|
+
let previewOrientation = self.getPreviewLayerVideoOrientation() ?? self.getVideoOrientation()
|
|
1554
|
+
let captureOrientation = CaptureOrientationResolver.resolveOrientation(
|
|
1555
|
+
mode: captureOrientationMode,
|
|
1556
|
+
previewOrientation: previewOrientation,
|
|
1557
|
+
deviceOrientation: self.getPhysicalOrientation()
|
|
1558
|
+
)
|
|
1559
|
+
orientationUsedForCapture = captureOrientation
|
|
1560
|
+
if CaptureOrientationResolver.usesDeviceOrientation(mode: captureOrientationMode) {
|
|
1561
|
+
self.lastCaptureOrientation = captureOrientation
|
|
1562
|
+
}
|
|
1518
1563
|
self.setVideoOrientation(captureOrientation, on: connection)
|
|
1519
1564
|
}
|
|
1520
1565
|
// For fill + cover the preview shows a centered crop of the frame. Snapshot its
|
|
1521
1566
|
// shape now so the photo can be cropped to the same visible area.
|
|
1522
|
-
let visibleFillRatio = self.visibleFillCaptureAspectRatio()
|
|
1567
|
+
let visibleFillRatio = self.visibleFillCaptureAspectRatio(captureOrientation: orientationUsedForCapture)
|
|
1523
1568
|
let settings = AVCapturePhotoSettings()
|
|
1524
1569
|
// Configure photo capture settings optimized for speed
|
|
1525
1570
|
let shouldUseHighRes = CaptureResolutionSupport.shouldEnableHighResolutionPhoto(
|
|
@@ -1563,27 +1608,25 @@ extension CameraController {
|
|
|
1563
1608
|
}
|
|
1564
1609
|
}
|
|
1565
1610
|
|
|
1566
|
-
|
|
1611
|
+
if Thread.isMainThread {
|
|
1612
|
+
self.isCapturingPhoto = true
|
|
1613
|
+
} else {
|
|
1614
|
+
DispatchQueue.main.sync {
|
|
1615
|
+
self.isCapturingPhoto = true
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1567
1618
|
|
|
1568
1619
|
self.photoCaptureCompletionBlock = { [weak self] (image, photoData, metadata, error) in
|
|
1569
1620
|
guard let self = self else { return }
|
|
1570
1621
|
if let error = error {
|
|
1571
1622
|
completion(nil, nil, nil, error)
|
|
1572
|
-
|
|
1573
|
-
self.isCapturingPhoto = false
|
|
1574
|
-
if self.stopRequestedAfterCapture {
|
|
1575
|
-
DispatchQueue.main.async { self.cleanup(); self.stopRequestedAfterCapture = false }
|
|
1576
|
-
}
|
|
1623
|
+
self.finishPhotoCaptureLifecycle()
|
|
1577
1624
|
return
|
|
1578
1625
|
}
|
|
1579
1626
|
|
|
1580
1627
|
guard let image = image else {
|
|
1581
1628
|
completion(nil, nil, nil, NSError(domain: "Camera", code: 0, userInfo: [NSLocalizedDescriptionKey: "Failed to capture image"]))
|
|
1582
|
-
|
|
1583
|
-
self.isCapturingPhoto = false
|
|
1584
|
-
if self.stopRequestedAfterCapture {
|
|
1585
|
-
DispatchQueue.main.async { self.cleanup(); self.stopRequestedAfterCapture = false }
|
|
1586
|
-
}
|
|
1629
|
+
self.finishPhotoCaptureLifecycle()
|
|
1587
1630
|
return
|
|
1588
1631
|
}
|
|
1589
1632
|
|
|
@@ -1598,7 +1641,12 @@ extension CameraController {
|
|
|
1598
1641
|
// When max dimensions are specified, we used high-res capture
|
|
1599
1642
|
// First crop to aspect ratio if needed, then resize to max dimensions
|
|
1600
1643
|
if let aspectRatio = self.requestedAspectRatio {
|
|
1601
|
-
finalImage = self.cropCapturedImage(
|
|
1644
|
+
finalImage = self.cropCapturedImage(
|
|
1645
|
+
image,
|
|
1646
|
+
aspectRatio: aspectRatio,
|
|
1647
|
+
visibleFillRatio: visibleFillRatio,
|
|
1648
|
+
captureOrientation: orientationUsedForCapture
|
|
1649
|
+
)
|
|
1602
1650
|
print("[CameraPreview] Cropped high-res image to aspect ratio \(aspectRatio)")
|
|
1603
1651
|
}
|
|
1604
1652
|
// Then resize to fit within maximum dimensions while maintaining aspect ratio
|
|
@@ -1607,7 +1655,12 @@ extension CameraController {
|
|
|
1607
1655
|
} else if let aspectRatio = self.requestedAspectRatio {
|
|
1608
1656
|
// No max dimensions specified, but aspect ratio is specified
|
|
1609
1657
|
// Always apply aspect ratio cropping to ensure correct orientation
|
|
1610
|
-
finalImage = self.cropCapturedImage(
|
|
1658
|
+
finalImage = self.cropCapturedImage(
|
|
1659
|
+
image,
|
|
1660
|
+
aspectRatio: aspectRatio,
|
|
1661
|
+
visibleFillRatio: visibleFillRatio,
|
|
1662
|
+
captureOrientation: orientationUsedForCapture
|
|
1663
|
+
)
|
|
1611
1664
|
print("[CameraPreview] Applied aspect ratio cropping for \(aspectRatio): \(finalImage.size.width)x\(finalImage.size.height)")
|
|
1612
1665
|
}
|
|
1613
1666
|
|
|
@@ -1629,12 +1682,7 @@ extension CameraController {
|
|
|
1629
1682
|
}
|
|
1630
1683
|
|
|
1631
1684
|
completion(finalImage, photoData, metadata, nil)
|
|
1632
|
-
|
|
1633
|
-
// End capture lifecycle
|
|
1634
|
-
self.isCapturingPhoto = false
|
|
1635
|
-
if self.stopRequestedAfterCapture {
|
|
1636
|
-
DispatchQueue.main.async { self.cleanup(); self.stopRequestedAfterCapture = false }
|
|
1637
|
-
}
|
|
1685
|
+
self.finishPhotoCaptureLifecycle()
|
|
1638
1686
|
}
|
|
1639
1687
|
|
|
1640
1688
|
photoOutput.capturePhoto(with: settings, delegate: self)
|
|
@@ -1926,7 +1974,7 @@ extension CameraController {
|
|
|
1926
1974
|
|
|
1927
1975
|
/// Ratio of the visible preview area for `fill` + `cover`, in capture orientation.
|
|
1928
1976
|
/// Returns `nil` for numeric ratios and for `contain`, where the full frame is visible.
|
|
1929
|
-
func visibleFillCaptureAspectRatio() -> CGFloat? {
|
|
1977
|
+
func visibleFillCaptureAspectRatio(captureOrientation: AVCaptureVideoOrientation? = nil) -> CGFloat? {
|
|
1930
1978
|
guard let aspectRatio = self.requestedAspectRatio,
|
|
1931
1979
|
AspectRatioLayout.isFillMode(aspectRatio),
|
|
1932
1980
|
self.requestedAspectMode == "cover",
|
|
@@ -1934,7 +1982,7 @@ extension CameraController {
|
|
|
1934
1982
|
return nil
|
|
1935
1983
|
}
|
|
1936
1984
|
|
|
1937
|
-
let orientation = self.lastCaptureOrientation ?? self.getPhysicalOrientation()
|
|
1985
|
+
let orientation = captureOrientation ?? self.lastCaptureOrientation ?? self.getPhysicalOrientation()
|
|
1938
1986
|
let captureIsPortrait = orientation == .portrait || orientation == .portraitUpsideDown
|
|
1939
1987
|
let screenBounds = UIScreen.main.bounds
|
|
1940
1988
|
return AspectRatioLayout.visibleFillCaptureAspectRatio(
|
|
@@ -1945,7 +1993,12 @@ extension CameraController {
|
|
|
1945
1993
|
}
|
|
1946
1994
|
|
|
1947
1995
|
/// Crops a captured photo so it matches what the preview shows.
|
|
1948
|
-
func cropCapturedImage(
|
|
1996
|
+
func cropCapturedImage(
|
|
1997
|
+
_ image: UIImage,
|
|
1998
|
+
aspectRatio: String,
|
|
1999
|
+
visibleFillRatio: CGFloat?,
|
|
2000
|
+
captureOrientation: AVCaptureVideoOrientation? = nil
|
|
2001
|
+
) -> UIImage {
|
|
1949
2002
|
if AspectRatioLayout.isFillMode(aspectRatio) {
|
|
1950
2003
|
guard let ratio = visibleFillRatio else {
|
|
1951
2004
|
// fill + contain shows the whole frame, so keep the full photo.
|
|
@@ -1953,7 +2006,11 @@ extension CameraController {
|
|
|
1953
2006
|
}
|
|
1954
2007
|
return cropImage(image, toAspectRatio: ratio) ?? image
|
|
1955
2008
|
}
|
|
1956
|
-
return cropImageToAspectRatio(
|
|
2009
|
+
return cropImageToAspectRatio(
|
|
2010
|
+
image: image,
|
|
2011
|
+
aspectRatio: aspectRatio,
|
|
2012
|
+
captureOrientation: captureOrientation
|
|
2013
|
+
) ?? image
|
|
1957
2014
|
}
|
|
1958
2015
|
|
|
1959
2016
|
/// Center-crops `image` (after normalizing its orientation) to a width / height ratio.
|
|
@@ -1973,7 +2030,11 @@ extension CameraController {
|
|
|
1973
2030
|
return UIImage(cgImage: croppedCGImage, scale: normalizedImage.scale, orientation: .up)
|
|
1974
2031
|
}
|
|
1975
2032
|
|
|
1976
|
-
func cropImageToAspectRatio(
|
|
2033
|
+
func cropImageToAspectRatio(
|
|
2034
|
+
image: UIImage,
|
|
2035
|
+
aspectRatio: String,
|
|
2036
|
+
captureOrientation: AVCaptureVideoOrientation? = nil
|
|
2037
|
+
) -> UIImage? {
|
|
1977
2038
|
let components = aspectRatio.split(separator: ":").compactMap {Float(String($0))}
|
|
1978
2039
|
guard components.count == 2 else {
|
|
1979
2040
|
print("[CameraPreview] cropImageToAspectRatio - Failed to parse aspect ratio: \(aspectRatio)")
|
|
@@ -1981,7 +2042,7 @@ extension CameraController {
|
|
|
1981
2042
|
}
|
|
1982
2043
|
|
|
1983
2044
|
// Use physical orientation for capture works with portrait lock
|
|
1984
|
-
let orientation = self.lastCaptureOrientation ?? self.getPhysicalOrientation()
|
|
2045
|
+
let orientation = captureOrientation ?? self.lastCaptureOrientation ?? self.getPhysicalOrientation()
|
|
1985
2046
|
let isPortrait = (orientation == .portrait || orientation == .portraitUpsideDown)
|
|
1986
2047
|
|
|
1987
2048
|
let ratioWidth: CGFloat
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ImageIO
|
|
3
|
+
import MobileCoreServices
|
|
4
|
+
import UIKit
|
|
5
|
+
|
|
6
|
+
enum CaptureImageExifEncoder {
|
|
7
|
+
typealias JpegEncoder = (UIImage, Int) -> Data?
|
|
8
|
+
|
|
9
|
+
static func createImageData(
|
|
10
|
+
from image: UIImage,
|
|
11
|
+
quality: Int,
|
|
12
|
+
location: CLLocation?,
|
|
13
|
+
heading: CLHeading?,
|
|
14
|
+
originalPhotoData: Data?,
|
|
15
|
+
jpegEncoder: JpegEncoder = defaultJpegEncoder
|
|
16
|
+
) -> Data? {
|
|
17
|
+
guard let cgImage = image.cgImage else {
|
|
18
|
+
return jpegEncoder(image, quality)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let sourceDataForMetadata: CFData
|
|
22
|
+
if let originalPhotoData {
|
|
23
|
+
sourceDataForMetadata = originalPhotoData as CFData
|
|
24
|
+
} else if let encoded = jpegEncoder(image, quality) {
|
|
25
|
+
sourceDataForMetadata = encoded as CFData
|
|
26
|
+
} else {
|
|
27
|
+
return nil
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
guard let imageSource = CGImageSourceCreateWithData(sourceDataForMetadata, nil),
|
|
31
|
+
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [String: Any] else {
|
|
32
|
+
return jpegEncoder(image, quality)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var finalProperties = imageProperties
|
|
36
|
+
|
|
37
|
+
// Ensure orientation reflects the pixel data (we pass an orientation-fixed UIImage)
|
|
38
|
+
finalProperties[kCGImagePropertyOrientation as String] = 1
|
|
39
|
+
|
|
40
|
+
if let location {
|
|
41
|
+
let formatter = DateFormatter()
|
|
42
|
+
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
|
|
43
|
+
formatter.timeZone = TimeZone(abbreviation: "UTC")
|
|
44
|
+
|
|
45
|
+
var gpsDict: [String: Any] = [
|
|
46
|
+
kCGImagePropertyGPSLatitude as String: abs(location.coordinate.latitude),
|
|
47
|
+
kCGImagePropertyGPSLatitudeRef as String: location.coordinate.latitude >= 0 ? "N" : "S",
|
|
48
|
+
kCGImagePropertyGPSLongitude as String: abs(location.coordinate.longitude),
|
|
49
|
+
kCGImagePropertyGPSLongitudeRef as String: location.coordinate.longitude >= 0 ? "E" : "W",
|
|
50
|
+
kCGImagePropertyGPSTimeStamp as String: formatter.string(from: location.timestamp),
|
|
51
|
+
kCGImagePropertyGPSAltitude as String: location.altitude,
|
|
52
|
+
kCGImagePropertyGPSAltitudeRef as String: location.altitude >= 0 ? 0 : 1
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
if let heading {
|
|
56
|
+
let directionDegrees: Double
|
|
57
|
+
let directionRef: String
|
|
58
|
+
if heading.trueHeading >= 0 {
|
|
59
|
+
directionDegrees = heading.trueHeading
|
|
60
|
+
directionRef = "T"
|
|
61
|
+
} else {
|
|
62
|
+
directionDegrees = heading.magneticHeading
|
|
63
|
+
directionRef = "M"
|
|
64
|
+
}
|
|
65
|
+
gpsDict[kCGImagePropertyGPSImgDirection as String] = directionDegrees
|
|
66
|
+
gpsDict[kCGImagePropertyGPSImgDirectionRef as String] = directionRef
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
finalProperties[kCGImagePropertyGPSDictionary as String] = gpsDict
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
var tiffDict = finalProperties[kCGImagePropertyTIFFDictionary as String] as? [String: Any] ?? [:]
|
|
73
|
+
tiffDict[kCGImagePropertyTIFFMake as String] = "Apple"
|
|
74
|
+
tiffDict[kCGImagePropertyTIFFModel as String] = UIDevice.current.model
|
|
75
|
+
tiffDict[kCGImagePropertyTIFFOrientation as String] = 1
|
|
76
|
+
finalProperties[kCGImagePropertyTIFFDictionary as String] = tiffDict
|
|
77
|
+
|
|
78
|
+
if let encoded = ImageIOJpegEncoding.encode(cgImage: cgImage, properties: finalProperties, qualityPercent: quality) {
|
|
79
|
+
return encoded
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return jpegEncoder(image, quality)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private static func defaultJpegEncoder(image: UIImage, quality: Int) -> Data? {
|
|
86
|
+
image.jpegData(compressionQuality: CGFloat(Double(quality) / 100.0))
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Flags coordinating `stop()` with an in-flight still capture. Mutate only on the main thread.
|
|
4
|
+
struct CaptureLifecycleState {
|
|
5
|
+
var isCapturingPhoto: Bool = false
|
|
6
|
+
var stopRequestedAfterCapture: Bool = false
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
enum CaptureLifecycleCoordination {
|
|
10
|
+
/// Handles `stop()` when a capture may be in flight. Call on the main thread only.
|
|
11
|
+
static func handleStop(
|
|
12
|
+
state: inout CaptureLifecycleState,
|
|
13
|
+
force: Bool,
|
|
14
|
+
cleanup: () -> Void
|
|
15
|
+
) {
|
|
16
|
+
if state.isCapturingPhoto && !force {
|
|
17
|
+
state.stopRequestedAfterCapture = true
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
if force {
|
|
21
|
+
state.stopRequestedAfterCapture = false
|
|
22
|
+
}
|
|
23
|
+
cleanup()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/// Ends the capture lifecycle after processing completes. Call on the main thread only.
|
|
27
|
+
static func finishCapture(
|
|
28
|
+
state: inout CaptureLifecycleState,
|
|
29
|
+
cleanup: () -> Void
|
|
30
|
+
) {
|
|
31
|
+
state.isCapturingPhoto = false
|
|
32
|
+
if state.stopRequestedAfterCapture {
|
|
33
|
+
cleanup()
|
|
34
|
+
state.stopRequestedAfterCapture = false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import AVFoundation
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
/// Selects whether still capture follows on-screen preview orientation or physical device tilt.
|
|
5
|
+
enum CaptureOrientationResolver {
|
|
6
|
+
static let orientationPreview = "preview"
|
|
7
|
+
static let orientationDevice = "device"
|
|
8
|
+
|
|
9
|
+
static func usesDeviceOrientation(mode: String?) -> Bool {
|
|
10
|
+
mode != orientationPreview
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static func resolveOrientation(
|
|
14
|
+
mode: String?,
|
|
15
|
+
previewOrientation: AVCaptureVideoOrientation,
|
|
16
|
+
deviceOrientation: AVCaptureVideoOrientation
|
|
17
|
+
) -> AVCaptureVideoOrientation {
|
|
18
|
+
if mode == orientationPreview {
|
|
19
|
+
return previewOrientation
|
|
20
|
+
}
|
|
21
|
+
return deviceOrientation
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -35,7 +35,7 @@ extension UIWindow {
|
|
|
35
35
|
*/
|
|
36
36
|
@objc(CameraPreview)
|
|
37
37
|
public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelegate {
|
|
38
|
-
private let pluginVersion: String = "8.
|
|
38
|
+
private let pluginVersion: String = "8.13.0"
|
|
39
39
|
public let identifier = "CameraPreviewPlugin"
|
|
40
40
|
public let jsName = "CameraPreview"
|
|
41
41
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -676,7 +676,10 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
676
676
|
if let pendingStartCall = self.pendingStartCall, !self.hasResolvedStartCall {
|
|
677
677
|
self.failPendingStart(pendingStartCall, message: "Camera start cancelled")
|
|
678
678
|
}
|
|
679
|
-
|
|
679
|
+
let captureLifecycleBusy = DispatchQueue.main.sync {
|
|
680
|
+
self.cameraController.isCapturingPhoto || self.cameraController.stopRequestedAfterCapture
|
|
681
|
+
}
|
|
682
|
+
if self.isInitializing || self.isInitialized || captureLifecycleBusy {
|
|
680
683
|
self.startGeneration += 1
|
|
681
684
|
self.cancelFirstFrameTimeout()
|
|
682
685
|
// Force stop everything synchronously
|
|
@@ -717,7 +720,10 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
717
720
|
return
|
|
718
721
|
}
|
|
719
722
|
// Guard against starting while a deferred stop is pending due to in-flight capture
|
|
720
|
-
|
|
723
|
+
let captureLifecycleBusy = DispatchQueue.main.sync {
|
|
724
|
+
self.cameraController.isCapturingPhoto || self.cameraController.stopRequestedAfterCapture
|
|
725
|
+
}
|
|
726
|
+
if captureLifecycleBusy {
|
|
721
727
|
call.reject("camera is stopping or busy, please retry shortly")
|
|
722
728
|
return
|
|
723
729
|
}
|
|
@@ -1171,16 +1177,11 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
1171
1177
|
self.isGeneratingDeviceOrientationNotifications = false
|
|
1172
1178
|
}
|
|
1173
1179
|
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
if force {
|
|
1180
|
-
self.cameraController.stopRequestedAfterCapture = false
|
|
1181
|
-
}
|
|
1182
|
-
self.cameraController.cleanup()
|
|
1183
|
-
}
|
|
1180
|
+
CaptureLifecycleCoordination.handleStop(
|
|
1181
|
+
state: &self.cameraController.captureLifecycle,
|
|
1182
|
+
force: force,
|
|
1183
|
+
cleanup: { self.cameraController.cleanup() }
|
|
1184
|
+
)
|
|
1184
1185
|
|
|
1185
1186
|
call.resolve()
|
|
1186
1187
|
}
|
|
@@ -1367,10 +1368,11 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
1367
1368
|
let height = call.getInt("height")
|
|
1368
1369
|
let photoQualityPrioritization = call.getString("photoQualityPrioritization", "speed")
|
|
1369
1370
|
let mirrorFrontCamera = call.getBool("mirrorFrontCamera", false) ?? false
|
|
1371
|
+
let captureOrientation = call.getString("orientation", CaptureOrientationResolver.orientationDevice)
|
|
1370
1372
|
|
|
1371
1373
|
print("[CameraPreview] Raw parameter values - width: \(String(describing: width)), height: \(String(describing: height))")
|
|
1372
1374
|
|
|
1373
|
-
print("[CameraPreview] Capture params - quality: \(quality), saveToGallery: \(saveToGallery), withExifLocation: \(withExifLocation ?? false), embedTimestamp: \(embedTimestamp), embedLocation: \(effectiveEmbedLocation) (requested=\(embedLocationRequested)), width: \(width ?? -1), height: \(height ?? -1), mirrorFrontCamera: \(mirrorFrontCamera)")
|
|
1375
|
+
print("[CameraPreview] Capture params - quality: \(quality), saveToGallery: \(saveToGallery), withExifLocation: \(withExifLocation ?? false), embedTimestamp: \(embedTimestamp), embedLocation: \(effectiveEmbedLocation) (requested=\(embedLocationRequested)), width: \(width ?? -1), height: \(height ?? -1), mirrorFrontCamera: \(mirrorFrontCamera), orientation: \(captureOrientation ?? CaptureOrientationResolver.orientationDevice)")
|
|
1374
1376
|
print("[CameraPreview] Current location: \(self.currentLocation?.description ?? "nil")")
|
|
1375
1377
|
// Safely read frame from main thread for logging
|
|
1376
1378
|
let (previewWidth, previewHeight): (CGFloat, CGFloat) = {
|
|
@@ -1392,7 +1394,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
1392
1394
|
let locationForExif = (withExifLocation ?? false) ? self.currentLocation : nil
|
|
1393
1395
|
let headingForExif = (withExifLocation ?? false) ? self.currentHeading : nil
|
|
1394
1396
|
let storeToFile = self.storeToFile
|
|
1395
|
-
self.cameraController.captureImage(width: width, height: height, quality: quality, gpsLocation: gpsForThisCapture, embedTimestamp: embedTimestamp, embedLocation: effectiveEmbedLocation, photoQualityPrioritization: photoQualityPrioritization) { (image, originalPhotoData, _, error) in
|
|
1397
|
+
self.cameraController.captureImage(width: width, height: height, quality: quality, gpsLocation: gpsForThisCapture, embedTimestamp: embedTimestamp, embedLocation: effectiveEmbedLocation, photoQualityPrioritization: photoQualityPrioritization, captureOrientationMode: captureOrientation) { (image, originalPhotoData, _, error) in
|
|
1396
1398
|
print("[CameraPreview] captureImage callback received")
|
|
1397
1399
|
CapturePhotoProcessingQueue.async {
|
|
1398
1400
|
print("[CameraPreview] Processing capture on background queue (isMain=\(Thread.isMainThread))")
|
|
@@ -1423,7 +1425,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
1423
1425
|
imageToEncode = capturedImage
|
|
1424
1426
|
}
|
|
1425
1427
|
|
|
1426
|
-
guard let imageDataWithExif =
|
|
1428
|
+
guard let imageDataWithExif = CaptureImageExifEncoder.createImageData(
|
|
1427
1429
|
from: imageToEncode,
|
|
1428
1430
|
quality: Int(quality),
|
|
1429
1431
|
location: locationForExif,
|
|
@@ -1562,72 +1564,6 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
1562
1564
|
}
|
|
1563
1565
|
}
|
|
1564
1566
|
|
|
1565
|
-
private func createImageDataWithExif(from image: UIImage, quality: Int, location: CLLocation?, heading: CLHeading?, originalPhotoData: Data?) -> Data? {
|
|
1566
|
-
guard let jpegDataAtQuality = image.jpegData(compressionQuality: CGFloat(Double(quality) / 100.0)) else {
|
|
1567
|
-
return nil
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
// Prefer metadata from the original AVCapturePhoto file data to preserve lens/EXIF
|
|
1571
|
-
let sourceDataForMetadata = (originalPhotoData ?? jpegDataAtQuality) as CFData
|
|
1572
|
-
guard let imageSource = CGImageSourceCreateWithData(sourceDataForMetadata, nil),
|
|
1573
|
-
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [String: Any],
|
|
1574
|
-
let cgImage = image.cgImage else {
|
|
1575
|
-
return jpegDataAtQuality
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
var finalProperties = imageProperties
|
|
1579
|
-
|
|
1580
|
-
// Ensure orientation reflects the pixel data (we pass an orientation-fixed UIImage)
|
|
1581
|
-
finalProperties[kCGImagePropertyOrientation as String] = 1
|
|
1582
|
-
|
|
1583
|
-
// Add GPS location if available
|
|
1584
|
-
if let location = location {
|
|
1585
|
-
let formatter = DateFormatter()
|
|
1586
|
-
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
|
|
1587
|
-
formatter.timeZone = TimeZone(abbreviation: "UTC")
|
|
1588
|
-
|
|
1589
|
-
var gpsDict: [String: Any] = [
|
|
1590
|
-
kCGImagePropertyGPSLatitude as String: abs(location.coordinate.latitude),
|
|
1591
|
-
kCGImagePropertyGPSLatitudeRef as String: location.coordinate.latitude >= 0 ? "N" : "S",
|
|
1592
|
-
kCGImagePropertyGPSLongitude as String: abs(location.coordinate.longitude),
|
|
1593
|
-
kCGImagePropertyGPSLongitudeRef as String: location.coordinate.longitude >= 0 ? "E" : "W",
|
|
1594
|
-
kCGImagePropertyGPSTimeStamp as String: formatter.string(from: location.timestamp),
|
|
1595
|
-
kCGImagePropertyGPSAltitude as String: location.altitude,
|
|
1596
|
-
kCGImagePropertyGPSAltitudeRef as String: location.altitude >= 0 ? 0 : 1
|
|
1597
|
-
]
|
|
1598
|
-
|
|
1599
|
-
// Add image direction (compass heading) when available
|
|
1600
|
-
if let heading = heading {
|
|
1601
|
-
let directionDegrees: Double
|
|
1602
|
-
let directionRef: String
|
|
1603
|
-
if heading.trueHeading >= 0 {
|
|
1604
|
-
directionDegrees = heading.trueHeading
|
|
1605
|
-
directionRef = "T"
|
|
1606
|
-
} else {
|
|
1607
|
-
directionDegrees = heading.magneticHeading
|
|
1608
|
-
directionRef = "M"
|
|
1609
|
-
}
|
|
1610
|
-
gpsDict[kCGImagePropertyGPSImgDirection as String] = directionDegrees
|
|
1611
|
-
gpsDict[kCGImagePropertyGPSImgDirectionRef as String] = directionRef
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
finalProperties[kCGImagePropertyGPSDictionary as String] = gpsDict
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
// Create or update TIFF dictionary for device info and set orientation to Up
|
|
1618
|
-
var tiffDict = finalProperties[kCGImagePropertyTIFFDictionary as String] as? [String: Any] ?? [:]
|
|
1619
|
-
tiffDict[kCGImagePropertyTIFFMake as String] = "Apple"
|
|
1620
|
-
tiffDict[kCGImagePropertyTIFFModel as String] = UIDevice.current.model
|
|
1621
|
-
tiffDict[kCGImagePropertyTIFFOrientation as String] = 1
|
|
1622
|
-
finalProperties[kCGImagePropertyTIFFDictionary as String] = tiffDict
|
|
1623
|
-
|
|
1624
|
-
if let encoded = ImageIOJpegEncoding.encode(cgImage: cgImage, properties: finalProperties, qualityPercent: quality) {
|
|
1625
|
-
return encoded
|
|
1626
|
-
}
|
|
1627
|
-
|
|
1628
|
-
return jpegDataAtQuality
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
1567
|
@objc func captureSample(_ call: CAPPluginCall) {
|
|
1632
1568
|
let quality: Int = call.getInt("quality") ?? 85
|
|
1633
1569
|
let mirrorFrontCamera = call.getBool("mirrorFrontCamera", false) ?? false
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ImageIO
|
|
3
|
+
import UIKit
|
|
4
|
+
import XCTest
|
|
5
|
+
@testable import CapgoCameraPreview
|
|
6
|
+
|
|
7
|
+
final class CaptureImageExifEncoderTests: XCTestCase {
|
|
8
|
+
func testSkipsJpegEncodeWhenOriginalPhotoDataProvided() {
|
|
9
|
+
let image = makeTestImage()
|
|
10
|
+
guard let originalPhotoData = image.jpegData(compressionQuality: 0.9) else {
|
|
11
|
+
XCTFail("Failed to build fixture JPEG")
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var encodeCallCount = 0
|
|
16
|
+
let result = CaptureImageExifEncoder.createImageData(
|
|
17
|
+
from: image,
|
|
18
|
+
quality: 85,
|
|
19
|
+
location: nil,
|
|
20
|
+
heading: nil,
|
|
21
|
+
originalPhotoData: originalPhotoData,
|
|
22
|
+
jpegEncoder: { _, _ in
|
|
23
|
+
encodeCallCount += 1
|
|
24
|
+
return nil
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
XCTAssertNotNil(result)
|
|
29
|
+
XCTAssertEqual(encodeCallCount, 0)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
func testProducesJpegWithTiffMetadata() {
|
|
33
|
+
let image = makeTestImage()
|
|
34
|
+
guard let originalPhotoData = image.jpegData(compressionQuality: 0.9) else {
|
|
35
|
+
XCTFail("Failed to build fixture JPEG")
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let result = CaptureImageExifEncoder.createImageData(
|
|
40
|
+
from: image,
|
|
41
|
+
quality: 85,
|
|
42
|
+
location: nil,
|
|
43
|
+
heading: nil,
|
|
44
|
+
originalPhotoData: originalPhotoData
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
guard let result,
|
|
48
|
+
let source = CGImageSourceCreateWithData(result as CFData, nil),
|
|
49
|
+
let properties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [String: Any],
|
|
50
|
+
let tiff = properties[kCGImagePropertyTIFFDictionary as String] as? [String: Any] else {
|
|
51
|
+
XCTFail("Expected JPEG output with TIFF metadata")
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
XCTAssertEqual(tiff[kCGImagePropertyTIFFMake as String] as? String, "Apple")
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
func testHonorsRequestedQualityWhenOriginalPhotoDataProvided() {
|
|
59
|
+
let size = CGSize(width: 400, height: 300)
|
|
60
|
+
let renderer = UIGraphicsImageRenderer(size: size)
|
|
61
|
+
let image = renderer.image { context in
|
|
62
|
+
UIColor.red.setFill()
|
|
63
|
+
context.fill(CGRect(origin: .zero, size: size))
|
|
64
|
+
UIColor.blue.setFill()
|
|
65
|
+
context.fill(CGRect(x: 50, y: 50, width: 300, height: 200))
|
|
66
|
+
}
|
|
67
|
+
guard let originalPhotoData = image.jpegData(compressionQuality: 1.0) else {
|
|
68
|
+
XCTFail("Failed to build fixture JPEG")
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
guard let lowQuality = CaptureImageExifEncoder.createImageData(
|
|
73
|
+
from: image,
|
|
74
|
+
quality: 20,
|
|
75
|
+
location: nil,
|
|
76
|
+
heading: nil,
|
|
77
|
+
originalPhotoData: originalPhotoData
|
|
78
|
+
),
|
|
79
|
+
let highQuality = CaptureImageExifEncoder.createImageData(
|
|
80
|
+
from: image,
|
|
81
|
+
quality: 95,
|
|
82
|
+
location: nil,
|
|
83
|
+
heading: nil,
|
|
84
|
+
originalPhotoData: originalPhotoData
|
|
85
|
+
) else {
|
|
86
|
+
XCTFail("Expected JPEG output at both quality levels")
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
XCTAssertLessThan(lowQuality.count, highQuality.count)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
func testFallsBackToJpegEncoderWhenMetadataReadFails() {
|
|
94
|
+
let image = makeTestImage()
|
|
95
|
+
let invalidOriginalData = Data([0x00, 0x01, 0x02, 0x03])
|
|
96
|
+
|
|
97
|
+
var encodeCallCount = 0
|
|
98
|
+
let result = CaptureImageExifEncoder.createImageData(
|
|
99
|
+
from: image,
|
|
100
|
+
quality: 85,
|
|
101
|
+
location: nil,
|
|
102
|
+
heading: nil,
|
|
103
|
+
originalPhotoData: invalidOriginalData,
|
|
104
|
+
jpegEncoder: { _, _ in
|
|
105
|
+
encodeCallCount += 1
|
|
106
|
+
return image.jpegData(compressionQuality: 0.85)
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
XCTAssertNotNil(result)
|
|
111
|
+
XCTAssertEqual(encodeCallCount, 1)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
func testEncodesWhenOriginalPhotoDataMissing() {
|
|
115
|
+
let image = makeTestImage()
|
|
116
|
+
|
|
117
|
+
var encodeCallCount = 0
|
|
118
|
+
let result = CaptureImageExifEncoder.createImageData(
|
|
119
|
+
from: image,
|
|
120
|
+
quality: 85,
|
|
121
|
+
location: nil,
|
|
122
|
+
heading: nil,
|
|
123
|
+
originalPhotoData: nil,
|
|
124
|
+
jpegEncoder: { _, _ in
|
|
125
|
+
encodeCallCount += 1
|
|
126
|
+
return image.jpegData(compressionQuality: 0.85)
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
XCTAssertNotNil(result)
|
|
131
|
+
XCTAssertGreaterThanOrEqual(encodeCallCount, 1)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private func makeTestImage() -> UIImage {
|
|
135
|
+
let renderer = UIGraphicsImageRenderer(size: CGSize(width: 32, height: 32))
|
|
136
|
+
return renderer.image { context in
|
|
137
|
+
UIColor.red.setFill()
|
|
138
|
+
context.fill(CGRect(x: 0, y: 0, width: 32, height: 32))
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import CapgoCameraPreview
|
|
3
|
+
|
|
4
|
+
final class CaptureLifecycleCoordinationTests: XCTestCase {
|
|
5
|
+
func testDeferredStopRunsCleanupWhenCaptureFinishes() {
|
|
6
|
+
var state = CaptureLifecycleState()
|
|
7
|
+
state.isCapturingPhoto = true
|
|
8
|
+
var cleanupCount = 0
|
|
9
|
+
|
|
10
|
+
CaptureLifecycleCoordination.handleStop(state: &state, force: false, cleanup: { cleanupCount += 1 })
|
|
11
|
+
|
|
12
|
+
XCTAssertTrue(state.stopRequestedAfterCapture)
|
|
13
|
+
XCTAssertTrue(state.isCapturingPhoto)
|
|
14
|
+
XCTAssertEqual(cleanupCount, 0)
|
|
15
|
+
|
|
16
|
+
CaptureLifecycleCoordination.finishCapture(state: &state, cleanup: { cleanupCount += 1 })
|
|
17
|
+
|
|
18
|
+
XCTAssertFalse(state.isCapturingPhoto)
|
|
19
|
+
XCTAssertFalse(state.stopRequestedAfterCapture)
|
|
20
|
+
XCTAssertEqual(cleanupCount, 1)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func testForceStopDuringCaptureCleansUpImmediately() {
|
|
24
|
+
var state = CaptureLifecycleState()
|
|
25
|
+
state.isCapturingPhoto = true
|
|
26
|
+
var cleanupCount = 0
|
|
27
|
+
|
|
28
|
+
CaptureLifecycleCoordination.handleStop(state: &state, force: true, cleanup: { cleanupCount += 1 })
|
|
29
|
+
|
|
30
|
+
XCTAssertFalse(state.stopRequestedAfterCapture)
|
|
31
|
+
XCTAssertEqual(cleanupCount, 1)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func testFinishCaptureWithoutDeferredStopDoesNotCleanup() {
|
|
35
|
+
var state = CaptureLifecycleState()
|
|
36
|
+
state.isCapturingPhoto = true
|
|
37
|
+
var cleanupCount = 0
|
|
38
|
+
|
|
39
|
+
CaptureLifecycleCoordination.finishCapture(state: &state, cleanup: { cleanupCount += 1 })
|
|
40
|
+
|
|
41
|
+
XCTAssertFalse(state.isCapturingPhoto)
|
|
42
|
+
XCTAssertFalse(state.stopRequestedAfterCapture)
|
|
43
|
+
XCTAssertEqual(cleanupCount, 0)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
func testStopAfterCaptureAlreadyFinishedCleansUpImmediately() {
|
|
47
|
+
var state = CaptureLifecycleState()
|
|
48
|
+
state.isCapturingPhoto = false
|
|
49
|
+
var cleanupCount = 0
|
|
50
|
+
|
|
51
|
+
CaptureLifecycleCoordination.handleStop(state: &state, force: false, cleanup: { cleanupCount += 1 })
|
|
52
|
+
|
|
53
|
+
XCTAssertFalse(state.stopRequestedAfterCapture)
|
|
54
|
+
XCTAssertEqual(cleanupCount, 1)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
func testCoordinatorDeferredStopThenFinishCleansUpOnce() {
|
|
58
|
+
var state = CaptureLifecycleState()
|
|
59
|
+
state.isCapturingPhoto = true
|
|
60
|
+
var cleanupCount = 0
|
|
61
|
+
let finishExpectation = expectation(description: "finish on main")
|
|
62
|
+
|
|
63
|
+
DispatchQueue.main.async {
|
|
64
|
+
CaptureLifecycleCoordination.handleStop(state: &state, force: false, cleanup: { cleanupCount += 1 })
|
|
65
|
+
CaptureLifecycleCoordination.finishCapture(state: &state, cleanup: { cleanupCount += 1 })
|
|
66
|
+
finishExpectation.fulfill()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
waitForExpectations(timeout: 5)
|
|
70
|
+
XCTAssertEqual(cleanupCount, 1)
|
|
71
|
+
XCTAssertFalse(state.stopRequestedAfterCapture)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import AVFoundation
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import CapgoCameraPreview
|
|
4
|
+
|
|
5
|
+
final class CaptureOrientationResolverTests: XCTestCase {
|
|
6
|
+
func testDefaultsToDeviceOrientation() {
|
|
7
|
+
XCTAssertEqual(
|
|
8
|
+
CaptureOrientationResolver.resolveOrientation(
|
|
9
|
+
mode: nil,
|
|
10
|
+
previewOrientation: .portrait,
|
|
11
|
+
deviceOrientation: .landscapeRight
|
|
12
|
+
),
|
|
13
|
+
.landscapeRight
|
|
14
|
+
)
|
|
15
|
+
XCTAssertTrue(CaptureOrientationResolver.usesDeviceOrientation(mode: nil))
|
|
16
|
+
XCTAssertTrue(CaptureOrientationResolver.usesDeviceOrientation(mode: "device"))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func testPreviewModeUsesPreviewOrientation() {
|
|
20
|
+
XCTAssertEqual(
|
|
21
|
+
CaptureOrientationResolver.resolveOrientation(
|
|
22
|
+
mode: "preview",
|
|
23
|
+
previewOrientation: .landscapeLeft,
|
|
24
|
+
deviceOrientation: .portrait
|
|
25
|
+
),
|
|
26
|
+
.landscapeLeft
|
|
27
|
+
)
|
|
28
|
+
XCTAssertFalse(CaptureOrientationResolver.usesDeviceOrientation(mode: "preview"))
|
|
29
|
+
}
|
|
30
|
+
}
|