@capgo/camera-preview 8.11.12 → 8.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -37
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraPreview.java +13 -0
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraXView.java +51 -43
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CaptureBitmapDecoding.java +62 -0
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CaptureResolutionSupport.java +161 -0
- package/android/src/main/java/app/capgo/capacitor/camera/preview/model/CameraSessionConfiguration.java +31 -0
- package/android/src/test/java/app/capgo/capacitor/camera/preview/CaptureBitmapDecodingTest.java +43 -0
- package/android/src/test/java/app/capgo/capacitor/camera/preview/CaptureResolutionSupportTest.java +197 -0
- package/dist/docs.json +41 -0
- package/dist/esm/definitions.d.ts +24 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1558,43 +1558,57 @@ Get the native Capacitor plugin version
|
|
|
1558
1558
|
|
|
1559
1559
|
Defines the configuration options for starting the camera preview.
|
|
1560
1560
|
|
|
1561
|
-
| Prop | Type | Description
|
|
1562
|
-
| ------------------------------------------------ | ---------------------------------------------------------------------------------- |
|
|
1563
|
-
| **`parent`** | <code>string</code> | The parent element to attach the video preview to.
|
|
1564
|
-
| **`className`** | <code>string</code> | A CSS class name to add to the preview element.
|
|
1565
|
-
| **`width`** | <code>number</code> | The width of the preview in pixels. Defaults to the screen width.
|
|
1566
|
-
| **`height`** | <code>number</code> | The height of the preview in pixels. Defaults to the screen height.
|
|
1567
|
-
| **`x`** | <code>number</code> | The horizontal origin of the preview, in pixels.
|
|
1568
|
-
| **`y`** | <code>number</code> | The vertical origin of the preview, in pixels.
|
|
1569
|
-
| **`aspectRatio`** | <code><a href="#camerapreviewaspectratio">CameraPreviewAspectRatio</a></code> | The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'. Cannot be set if width or height is provided, otherwise the call will be rejected. Use setPreviewSize to adjust size after starting.
|
|
1570
|
-
| **`aspectMode`** | <code>'cover' \| 'contain'</code> | Controls how the camera preview fills the available space. - 'contain': Fits the entire preview within the space, may show letterboxing (default). - 'cover': Fills the entire space, may crop edges of the preview.
|
|
1571
|
-
| **`gridMode`** | <code><a href="#gridmode">GridMode</a></code> | The grid overlay to display on the camera preview.
|
|
1572
|
-
| **`includeSafeAreaInsets`** | <code>boolean</code> | Adjusts the y-position to account for safe areas (e.g., notches).
|
|
1573
|
-
| **`toBack`** | <code>boolean</code> | If true, places the preview behind the webview.
|
|
1574
|
-
| **`paddingBottom`** | <code>number</code> | Bottom padding for the preview, in pixels.
|
|
1575
|
-
| **`rotateWhenOrientationChanged`** | <code>boolean</code> | Whether to rotate the preview when the device orientation changes.
|
|
1576
|
-
| **`position`** | <code>string</code> | The camera to use.
|
|
1577
|
-
| **`storeToFile`** | <code>boolean</code> | If true, saves the captured image to a file and returns the file path. If false, returns a base64 encoded string.
|
|
1578
|
-
| **`disableExifHeaderStripping`** | <code>boolean</code> | If true, prevents the plugin from rotating the image based on EXIF data.
|
|
1579
|
-
| **`disableAudio`** | <code>boolean</code> | If true, disables the audio stream, preventing audio permission requests.
|
|
1580
|
-
| **`lockAndroidOrientation`** | <code>boolean</code> | If true, locks the device orientation while the camera is active.
|
|
1581
|
-
| **`enableOpacity`** | <code>boolean</code> | If true, allows the camera preview's opacity to be changed.
|
|
1582
|
-
| **`disableFocusIndicator`** | <code>boolean</code> | If true, disables the visual focus indicator when tapping to focus.
|
|
1583
|
-
| **`deviceId`** | <code>string</code> | The `deviceId` of the camera to use. If provided, `position` is ignored.
|
|
1584
|
-
| **`enablePhysicalDeviceSelection`** | <code>boolean</code> | On Android, attempts to bind a physical camera directly when `deviceId` refers to a physical lens. Disabled by default because OEM support is inconsistent; when false, Android keeps the current logical-camera fallback behavior.
|
|
1585
|
-
| **`initialZoomLevel`** | <code>number</code> | The initial zoom level when starting the camera preview. If the requested zoom level is not available, the native plugin will reject.
|
|
1586
|
-
| **`positioning`** | <code><a href="#camerapositioning">CameraPositioning</a></code> | The vertical positioning of the camera preview.
|
|
1587
|
-
| **`enableVideoMode`** | <code>boolean</code> | If true, enables video capture capabilities when the camera starts.
|
|
1588
|
-
| **`
|
|
1589
|
-
| **`
|
|
1590
|
-
| **`
|
|
1591
|
-
| **`
|
|
1592
|
-
| **`
|
|
1593
|
-
| **`
|
|
1594
|
-
| **`
|
|
1595
|
-
| **`
|
|
1596
|
-
| **`
|
|
1597
|
-
| **`
|
|
1561
|
+
| Prop | Type | Description | Default | Since |
|
|
1562
|
+
| ------------------------------------------------ | ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | ------ |
|
|
1563
|
+
| **`parent`** | <code>string</code> | The parent element to attach the video preview to. | | |
|
|
1564
|
+
| **`className`** | <code>string</code> | A CSS class name to add to the preview element. | | |
|
|
1565
|
+
| **`width`** | <code>number</code> | The width of the preview in pixels. Defaults to the screen width. | | |
|
|
1566
|
+
| **`height`** | <code>number</code> | The height of the preview in pixels. Defaults to the screen height. | | |
|
|
1567
|
+
| **`x`** | <code>number</code> | The horizontal origin of the preview, in pixels. | | |
|
|
1568
|
+
| **`y`** | <code>number</code> | The vertical origin of the preview, in pixels. | | |
|
|
1569
|
+
| **`aspectRatio`** | <code><a href="#camerapreviewaspectratio">CameraPreviewAspectRatio</a></code> | The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'. Cannot be set if width or height is provided, otherwise the call will be rejected. Use setPreviewSize to adjust size after starting. | | 2.0.0 |
|
|
1570
|
+
| **`aspectMode`** | <code>'cover' \| 'contain'</code> | Controls how the camera preview fills the available space. - 'contain': Fits the entire preview within the space, may show letterboxing (default). - 'cover': Fills the entire space, may crop edges of the preview. | <code>"contain"</code> | |
|
|
1571
|
+
| **`gridMode`** | <code><a href="#gridmode">GridMode</a></code> | The grid overlay to display on the camera preview. | <code>"none"</code> | 2.1.0 |
|
|
1572
|
+
| **`includeSafeAreaInsets`** | <code>boolean</code> | Adjusts the y-position to account for safe areas (e.g., notches). | <code>false</code> | |
|
|
1573
|
+
| **`toBack`** | <code>boolean</code> | If true, places the preview behind the webview. | <code>true</code> | |
|
|
1574
|
+
| **`paddingBottom`** | <code>number</code> | Bottom padding for the preview, in pixels. | | |
|
|
1575
|
+
| **`rotateWhenOrientationChanged`** | <code>boolean</code> | Whether to rotate the preview when the device orientation changes. | <code>true</code> | |
|
|
1576
|
+
| **`position`** | <code>string</code> | The camera to use. | <code>"rear"</code> | |
|
|
1577
|
+
| **`storeToFile`** | <code>boolean</code> | If true, saves the captured image to a file and returns the file path. If false, returns a base64 encoded string. | <code>false</code> | |
|
|
1578
|
+
| **`disableExifHeaderStripping`** | <code>boolean</code> | If true, prevents the plugin from rotating the image based on EXIF data. | <code>false</code> | |
|
|
1579
|
+
| **`disableAudio`** | <code>boolean</code> | If true, disables the audio stream, preventing audio permission requests. | <code>true</code> | |
|
|
1580
|
+
| **`lockAndroidOrientation`** | <code>boolean</code> | If true, locks the device orientation while the camera is active. | <code>false</code> | |
|
|
1581
|
+
| **`enableOpacity`** | <code>boolean</code> | If true, allows the camera preview's opacity to be changed. | <code>false</code> | |
|
|
1582
|
+
| **`disableFocusIndicator`** | <code>boolean</code> | If true, disables the visual focus indicator when tapping to focus. | <code>false</code> | |
|
|
1583
|
+
| **`deviceId`** | <code>string</code> | The `deviceId` of the camera to use. If provided, `position` is ignored. | | |
|
|
1584
|
+
| **`enablePhysicalDeviceSelection`** | <code>boolean</code> | On Android, attempts to bind a physical camera directly when `deviceId` refers to a physical lens. Disabled by default because OEM support is inconsistent; when false, Android keeps the current logical-camera fallback behavior. | <code>false</code> | |
|
|
1585
|
+
| **`initialZoomLevel`** | <code>number</code> | The initial zoom level when starting the camera preview. If the requested zoom level is not available, the native plugin will reject. | <code>1.0</code> | 2.2.0 |
|
|
1586
|
+
| **`positioning`** | <code><a href="#camerapositioning">CameraPositioning</a></code> | The vertical positioning of the camera preview. | <code>"center"</code> | 2.3.0 |
|
|
1587
|
+
| **`enableVideoMode`** | <code>boolean</code> | If true, enables video capture capabilities when the camera starts. | <code>false</code> | 7.11.0 |
|
|
1588
|
+
| **`captureResolution`** | <code><a href="#cameracaptureresolution">CameraCaptureResolution</a></code> | Sets the Android still-capture resolution for the `ImageCapture` use case at session bind time. Preview resolution is unchanged. The shared ViewPort crop from the preview still applies to captures. When omitted, `ImageCapture` uses the highest resolution supported by the active camera (same as versions before 8.11.10). Set this to cap capture size for faster shots on high-megapixel sensors, for example `{ width: 1920, height: 1080 }` or `{ width: 1600, height: 1200 }`. | | 8.12.0 |
|
|
1589
|
+
| **`force`** | <code>boolean</code> | If true, forces the camera to start/restart even if it's already running or busy. This will kill the current camera session and start a new one, ignoring all state checks. | <code>false</code> | |
|
|
1590
|
+
| **`videoQuality`** | <code><a href="#videoquality">VideoQuality</a></code> | Sets the quality of video for recording. Options: 'low', 'medium', 'high', '2160p', '1080p', '720p', '480p', '4:3' | <code>"high"</code> | |
|
|
1591
|
+
| **`maxDuration`** | <code>number</code> | Maximum recording duration in seconds. Recording stops automatically when reached. | | |
|
|
1592
|
+
| **`maxFileSize`** | <code>number</code> | Maximum recording file size in bytes. Recording stops automatically when reached. | | |
|
|
1593
|
+
| **`videoCodec`** | <code><a href="#videocodec">VideoCodec</a></code> | Preferred video codec for recording. | <code>"avc1"</code> | |
|
|
1594
|
+
| **`frameRate`** | <code>number</code> | Target video frame rate in frames per second. Applied when recording starts. Use `getSupportedVideoFrameRates()` to list supported values. | | 8.6.0 |
|
|
1595
|
+
| **`videoStabilizationMode`** | <code><a href="#videostabilizationmode">VideoStabilizationMode</a></code> | Preferred video stabilization mode for recording. | <code>"off"</code> | |
|
|
1596
|
+
| **`allowHapticsAndSystemSoundsDuringRecording`** | <code>boolean</code> | When `true`, allows haptic feedback and system sounds while recording video with audio. iOS suppresses haptics during audio input recording unless this is enabled. Requires `disableAudio: false`. | <code>false</code> | 8.8.0 |
|
|
1597
|
+
| **`mirrorFrontCamera`** | <code>boolean</code> | When `true` and the front camera is active, mirrors the recorded video file so it matches the selfie-style preview (text and gestures are not reversed). Does not affect the live preview. Defaults to `false` to preserve existing behavior. | <code>false</code> | 8.10.0 |
|
|
1598
|
+
| **`barcodeScanner`** | <code>boolean \| <a href="#barcodescanneroptions">BarcodeScannerOptions</a></code> | Starts barcode scanning together with the camera preview. Set to `true` or pass options to scan all supported formats. Omit this option to keep barcode scanning disabled at startup. | | 8.8.0 |
|
|
1599
|
+
|
|
1600
|
+
|
|
1601
|
+
#### CameraCaptureResolution
|
|
1602
|
+
|
|
1603
|
+
Target still-capture resolution for the Android `ImageCapture` use case.
|
|
1604
|
+
|
|
1605
|
+
Width and height define the resolution strategy target. The plugin also filters out
|
|
1606
|
+
supported capture sizes whose long edge exceeds `max(width, height)`.
|
|
1607
|
+
|
|
1608
|
+
| Prop | Type | Description |
|
|
1609
|
+
| ------------ | ------------------- | ------------------------ |
|
|
1610
|
+
| **`width`** | <code>number</code> | Target width in pixels. |
|
|
1611
|
+
| **`height`** | <code>number</code> | Target height in pixels. |
|
|
1598
1612
|
|
|
1599
1613
|
|
|
1600
1614
|
#### BarcodeScannerOptions
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
distributionBase=GRADLE_USER_HOME
|
|
2
2
|
distributionPath=wrapper/dists
|
|
3
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.
|
|
3
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.6-bin.zip
|
|
4
4
|
networkTimeout=10000
|
|
5
5
|
validateDistributionUrl=true
|
|
6
6
|
zipStoreBase=GRADLE_USER_HOME
|
|
@@ -1315,6 +1315,18 @@ public class CameraPreview extends Plugin implements CameraXView.CameraXViewList
|
|
|
1315
1315
|
final String videoQuality = call.getString("videoQuality", "high");
|
|
1316
1316
|
final JSONObject barcodeScannerOptions = getStartBarcodeScannerOptions(call);
|
|
1317
1317
|
|
|
1318
|
+
final Integer captureResolutionWidth;
|
|
1319
|
+
final Integer captureResolutionHeight;
|
|
1320
|
+
Object captureResolutionObject = call.getData().opt("captureResolution");
|
|
1321
|
+
CaptureResolutionSupport.CaptureResolutionParseResult captureResolutionParseResult =
|
|
1322
|
+
CaptureResolutionSupport.parseStartCaptureResolution(captureResolutionObject);
|
|
1323
|
+
if (captureResolutionParseResult.isError()) {
|
|
1324
|
+
call.reject(captureResolutionParseResult.errorMessage);
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
captureResolutionWidth = captureResolutionParseResult.width;
|
|
1328
|
+
captureResolutionHeight = captureResolutionParseResult.height;
|
|
1329
|
+
|
|
1318
1330
|
// Check for conflict between aspectRatio and size
|
|
1319
1331
|
if (call.getData().has("aspectRatio") && (call.getData().has("width") || call.getData().has("height"))) {
|
|
1320
1332
|
call.reject("Cannot set both aspectRatio and size (width/height). Use setPreviewSize after start.");
|
|
@@ -1629,6 +1641,7 @@ public class CameraPreview extends Plugin implements CameraXView.CameraXViewList
|
|
|
1629
1641
|
config.setTargetZoom(finalTargetZoom);
|
|
1630
1642
|
config.setCentered(isCentered);
|
|
1631
1643
|
config.setEnablePhysicalDeviceSelection(enablePhysicalDeviceSelection);
|
|
1644
|
+
config.setCaptureResolution(captureResolutionWidth, captureResolutionHeight);
|
|
1632
1645
|
config.setBarcodeScannerEnabled(barcodeScannerOptions != null);
|
|
1633
1646
|
setPendingStartBarcodeScanner(barcodeScannerOptions);
|
|
1634
1647
|
if (barcodeScannerOptions == null) {
|
|
@@ -127,7 +127,6 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
127
127
|
|
|
128
128
|
private static final String TAG = "CameraPreview CameraXView";
|
|
129
129
|
private static final String FOCUS_INDICATOR_TAG = "cpcp_focus_indicator";
|
|
130
|
-
private static final Size DEFAULT_MAX_CAPTURE_RESOLUTION = new Size(1920, 1080);
|
|
131
130
|
|
|
132
131
|
public interface CameraXViewListener {
|
|
133
132
|
void onPictureTaken(String base64, JSONObject exif);
|
|
@@ -1107,6 +1106,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1107
1106
|
.setResolutionSelector(imageCaptureResolutionSelector)
|
|
1108
1107
|
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
|
1109
1108
|
.setFlashMode(currentFlashMode)
|
|
1109
|
+
.setJpegQuality(CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY)
|
|
1110
1110
|
.setTargetRotation(rotation)
|
|
1111
1111
|
.build();
|
|
1112
1112
|
sampleImageCapture = imageCapture;
|
|
@@ -1677,14 +1677,19 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1677
1677
|
}
|
|
1678
1678
|
|
|
1679
1679
|
private ResolutionSelector buildImageCaptureResolutionSelector() {
|
|
1680
|
-
Size targetResolution = new Size(
|
|
1681
|
-
Math.max(DEFAULT_MAX_CAPTURE_RESOLUTION.getWidth(), DEFAULT_MAX_CAPTURE_RESOLUTION.getHeight()),
|
|
1682
|
-
Math.min(DEFAULT_MAX_CAPTURE_RESOLUTION.getWidth(), DEFAULT_MAX_CAPTURE_RESOLUTION.getHeight())
|
|
1683
|
-
);
|
|
1684
|
-
int maxCaptureLongEdge = Math.max(DEFAULT_MAX_CAPTURE_RESOLUTION.getWidth(), DEFAULT_MAX_CAPTURE_RESOLUTION.getHeight());
|
|
1685
1680
|
ResolutionSelector.Builder resolutionSelectorBuilder = new ResolutionSelector.Builder();
|
|
1681
|
+
if (sessionConfig == null || !sessionConfig.hasCaptureResolution()) {
|
|
1682
|
+
resolutionSelectorBuilder.setResolutionStrategy(ResolutionStrategy.HIGHEST_AVAILABLE_STRATEGY);
|
|
1683
|
+
applySessionAspectRatioStrategy(resolutionSelectorBuilder);
|
|
1684
|
+
return resolutionSelectorBuilder.build();
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
int configuredWidth = sessionConfig.getCaptureResolutionWidth();
|
|
1688
|
+
int configuredHeight = sessionConfig.getCaptureResolutionHeight();
|
|
1689
|
+
Size targetResolution = CaptureResolutionSupport.normalizedCaptureTargetResolution(configuredWidth, configuredHeight);
|
|
1690
|
+
int maxCaptureLongEdge = Math.max(configuredWidth, configuredHeight);
|
|
1686
1691
|
resolutionSelectorBuilder.setResolutionFilter((supportedSizes, rotationDegrees) ->
|
|
1687
|
-
filterCaptureResolutionCandidates(supportedSizes, maxCaptureLongEdge)
|
|
1692
|
+
CaptureResolutionSupport.filterCaptureResolutionCandidates(supportedSizes, maxCaptureLongEdge)
|
|
1688
1693
|
);
|
|
1689
1694
|
resolutionSelectorBuilder.setResolutionStrategy(
|
|
1690
1695
|
new ResolutionStrategy(targetResolution, ResolutionStrategy.FALLBACK_RULE_CLOSEST_LOWER_THEN_HIGHER)
|
|
@@ -1693,35 +1698,6 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1693
1698
|
return resolutionSelectorBuilder.build();
|
|
1694
1699
|
}
|
|
1695
1700
|
|
|
1696
|
-
private List<Size> filterCaptureResolutionCandidates(List<Size> supportedSizes, int maxCaptureLongEdge) {
|
|
1697
|
-
if (supportedSizes == null || supportedSizes.isEmpty()) {
|
|
1698
|
-
return supportedSizes;
|
|
1699
|
-
}
|
|
1700
|
-
|
|
1701
|
-
List<Size> cappedSizes = new ArrayList<>();
|
|
1702
|
-
for (Size size : supportedSizes) {
|
|
1703
|
-
int longEdge = Math.max(size.getWidth(), size.getHeight());
|
|
1704
|
-
if (longEdge <= maxCaptureLongEdge) {
|
|
1705
|
-
cappedSizes.add(size);
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
if (!cappedSizes.isEmpty()) {
|
|
1710
|
-
return cappedSizes;
|
|
1711
|
-
}
|
|
1712
|
-
|
|
1713
|
-
Size smallest = supportedSizes.get(0);
|
|
1714
|
-
int smallestLongEdge = Math.max(smallest.getWidth(), smallest.getHeight());
|
|
1715
|
-
for (Size size : supportedSizes) {
|
|
1716
|
-
int longEdge = Math.max(size.getWidth(), size.getHeight());
|
|
1717
|
-
if (longEdge < smallestLongEdge) {
|
|
1718
|
-
smallest = size;
|
|
1719
|
-
smallestLongEdge = longEdge;
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
return Collections.singletonList(smallest);
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
1701
|
private void applySessionAspectRatioStrategy(ResolutionSelector.Builder resolutionSelectorBuilder) {
|
|
1726
1702
|
if (sessionConfig == null || sessionConfig.getAspectRatio() == null) {
|
|
1727
1703
|
return;
|
|
@@ -1826,7 +1802,14 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1826
1802
|
boolean embedLocation,
|
|
1827
1803
|
boolean mirrorFrontCamera
|
|
1828
1804
|
) {
|
|
1829
|
-
return
|
|
1805
|
+
return CaptureResolutionSupport.captureRequiresSoftwareTransform(
|
|
1806
|
+
width,
|
|
1807
|
+
height,
|
|
1808
|
+
embedTimestamp,
|
|
1809
|
+
embedLocation,
|
|
1810
|
+
mirrorFrontCamera,
|
|
1811
|
+
shouldMirrorFrontCamera(mirrorFrontCamera)
|
|
1812
|
+
);
|
|
1830
1813
|
}
|
|
1831
1814
|
|
|
1832
1815
|
private void bindConfiguredUseCases(CameraBindingPlan bindingPlan, Preview preview) {
|
|
@@ -2163,6 +2146,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2163
2146
|
target.setTargetZoom(source.getTargetZoom());
|
|
2164
2147
|
target.setEnablePhysicalDeviceSelection(source.isPhysicalDeviceSelectionEnabled());
|
|
2165
2148
|
target.setBarcodeScannerEnabled(source.isBarcodeScannerEnabled());
|
|
2149
|
+
target.copyCaptureResolutionFrom(source);
|
|
2166
2150
|
}
|
|
2167
2151
|
|
|
2168
2152
|
private void requestEnumeratedDeviceCacheRefresh() {
|
|
@@ -2374,16 +2358,40 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2374
2358
|
mirrorFrontCamera
|
|
2375
2359
|
);
|
|
2376
2360
|
|
|
2361
|
+
int exifOrientation = exifInterface.getAttributeInt(
|
|
2362
|
+
ExifInterface.TAG_ORIENTATION,
|
|
2363
|
+
ExifInterface.ORIENTATION_UNDEFINED
|
|
2364
|
+
);
|
|
2377
2365
|
if (
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2366
|
+
CaptureResolutionSupport.canUseViewportCaptureFastPath(
|
|
2367
|
+
quality,
|
|
2368
|
+
CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY,
|
|
2369
|
+
requiresSoftwareTransform,
|
|
2370
|
+
isViewportCropCurrent(),
|
|
2371
|
+
exifOrientation
|
|
2372
|
+
)
|
|
2383
2373
|
) {
|
|
2384
2374
|
Log.d(TAG, "capturePhoto: Using ViewPort fast path without software decode/crop/re-encode");
|
|
2385
2375
|
} else if (width != null || height != null) {
|
|
2386
|
-
Bitmap bitmap =
|
|
2376
|
+
Bitmap bitmap = CaptureBitmapDecoding.decodeJpegSubsamplingToMaxDimensions(
|
|
2377
|
+
originalCaptureBytes,
|
|
2378
|
+
width,
|
|
2379
|
+
height
|
|
2380
|
+
);
|
|
2381
|
+
if (bitmap == null) {
|
|
2382
|
+
if (listener != null) {
|
|
2383
|
+
listener.onPictureTakenError("Failed to decode captured image");
|
|
2384
|
+
}
|
|
2385
|
+
synchronized (captureLock) {
|
|
2386
|
+
isCapturingPhoto = false;
|
|
2387
|
+
if (stopRequested) {
|
|
2388
|
+
performImmediateStop();
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
maybePerformPendingViewportRebind();
|
|
2392
|
+
endOperation("capturePhoto");
|
|
2393
|
+
return;
|
|
2394
|
+
}
|
|
2387
2395
|
bitmap = applyExifOrientation(bitmap, exifInterface);
|
|
2388
2396
|
bitmap = maybeMirrorFrontCameraBitmap(bitmap, mirrorFrontCamera);
|
|
2389
2397
|
Bitmap resizedBitmap = resizeBitmapToMaxDimensions(bitmap, width, height);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
package app.capgo.capacitor.camera.preview;
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap;
|
|
4
|
+
import android.graphics.BitmapFactory;
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
|
|
7
|
+
/** Subsampled JPEG decode for capture resize paths. */
|
|
8
|
+
final class CaptureBitmapDecoding {
|
|
9
|
+
|
|
10
|
+
private CaptureBitmapDecoding() {}
|
|
11
|
+
|
|
12
|
+
@Nullable
|
|
13
|
+
static Bitmap decodeJpegSubsamplingToMaxDimensions(byte[] jpegBytes, @Nullable Integer maxWidth, @Nullable Integer maxHeight) {
|
|
14
|
+
if (jpegBytes == null || jpegBytes.length == 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
BitmapFactory.Options boundsOptions = new BitmapFactory.Options();
|
|
18
|
+
boundsOptions.inJustDecodeBounds = true;
|
|
19
|
+
BitmapFactory.decodeByteArray(jpegBytes, 0, jpegBytes.length, boundsOptions);
|
|
20
|
+
int sourceWidth = boundsOptions.outWidth;
|
|
21
|
+
int sourceHeight = boundsOptions.outHeight;
|
|
22
|
+
if (sourceWidth <= 0 || sourceHeight <= 0) {
|
|
23
|
+
return BitmapFactory.decodeByteArray(jpegBytes, 0, jpegBytes.length);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
|
|
27
|
+
decodeOptions.inSampleSize = computeInSampleSize(sourceWidth, sourceHeight, maxWidth, maxHeight);
|
|
28
|
+
return BitmapFactory.decodeByteArray(jpegBytes, 0, jpegBytes.length, decodeOptions);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static int computeInSampleSize(int sourceWidth, int sourceHeight, @Nullable Integer maxWidth, @Nullable Integer maxHeight) {
|
|
32
|
+
if (maxWidth == null && maxHeight == null) {
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
int reqWidth;
|
|
37
|
+
int reqHeight;
|
|
38
|
+
if (maxWidth != null && maxHeight != null) {
|
|
39
|
+
reqWidth = maxWidth;
|
|
40
|
+
reqHeight = maxHeight;
|
|
41
|
+
} else if (maxWidth != null) {
|
|
42
|
+
reqWidth = maxWidth;
|
|
43
|
+
reqHeight = Math.max(1, (int) (((long) sourceHeight * maxWidth) / sourceWidth));
|
|
44
|
+
} else {
|
|
45
|
+
reqHeight = maxHeight;
|
|
46
|
+
reqWidth = Math.max(1, (int) (((long) sourceWidth * maxHeight) / sourceHeight));
|
|
47
|
+
}
|
|
48
|
+
if (reqWidth <= 0 || reqHeight <= 0) {
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
int inSampleSize = 1;
|
|
53
|
+
if (sourceHeight > reqHeight || sourceWidth > reqWidth) {
|
|
54
|
+
final int halfHeight = sourceHeight / 2;
|
|
55
|
+
final int halfWidth = sourceWidth / 2;
|
|
56
|
+
while (halfHeight / inSampleSize >= reqHeight && halfWidth / inSampleSize >= reqWidth) {
|
|
57
|
+
inSampleSize *= 2;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return Math.max(1, inSampleSize);
|
|
61
|
+
}
|
|
62
|
+
}
|
package/android/src/main/java/app/capgo/capacitor/camera/preview/CaptureResolutionSupport.java
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
package app.capgo.capacitor.camera.preview;
|
|
2
|
+
|
|
3
|
+
import android.util.Size;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import androidx.exifinterface.media.ExifInterface;
|
|
6
|
+
import java.util.ArrayList;
|
|
7
|
+
import java.util.Collections;
|
|
8
|
+
import java.util.List;
|
|
9
|
+
import org.json.JSONObject;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Package-private helpers for Android still capture resolution and fast-path decisions.
|
|
13
|
+
*/
|
|
14
|
+
final class CaptureResolutionSupport {
|
|
15
|
+
|
|
16
|
+
/** Matches {@link CameraPreview} default capture quality and ImageCapture JPEG quality. */
|
|
17
|
+
static final int DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY = 85;
|
|
18
|
+
|
|
19
|
+
private CaptureResolutionSupport() {}
|
|
20
|
+
|
|
21
|
+
static final class CaptureResolutionParseResult {
|
|
22
|
+
|
|
23
|
+
@Nullable
|
|
24
|
+
final Integer width;
|
|
25
|
+
|
|
26
|
+
@Nullable
|
|
27
|
+
final Integer height;
|
|
28
|
+
|
|
29
|
+
@Nullable
|
|
30
|
+
final String errorMessage;
|
|
31
|
+
|
|
32
|
+
private CaptureResolutionParseResult(@Nullable Integer width, @Nullable Integer height, @Nullable String errorMessage) {
|
|
33
|
+
this.width = width;
|
|
34
|
+
this.height = height;
|
|
35
|
+
this.errorMessage = errorMessage;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static CaptureResolutionParseResult success(@Nullable Integer width, @Nullable Integer height) {
|
|
39
|
+
return new CaptureResolutionParseResult(width, height, null);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static CaptureResolutionParseResult error(String message) {
|
|
43
|
+
return new CaptureResolutionParseResult(null, null, message);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
boolean isError() {
|
|
47
|
+
return errorMessage != null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static CaptureResolutionParseResult parseStartCaptureResolution(@Nullable Object captureResolutionObject) {
|
|
52
|
+
if (captureResolutionObject == null) {
|
|
53
|
+
return CaptureResolutionParseResult.success(null, null);
|
|
54
|
+
}
|
|
55
|
+
if (!(captureResolutionObject instanceof JSONObject)) {
|
|
56
|
+
return CaptureResolutionParseResult.error("captureResolution must be an object with width and height");
|
|
57
|
+
}
|
|
58
|
+
JSONObject captureResolution = (JSONObject) captureResolutionObject;
|
|
59
|
+
if (!captureResolution.has("width") || !captureResolution.has("height")) {
|
|
60
|
+
return CaptureResolutionParseResult.error("captureResolution requires both width and height");
|
|
61
|
+
}
|
|
62
|
+
Integer captureWidth = parsePositivePixelDimension(captureResolution.opt("width"));
|
|
63
|
+
Integer captureHeight = parsePositivePixelDimension(captureResolution.opt("height"));
|
|
64
|
+
if (captureWidth == null || captureHeight == null) {
|
|
65
|
+
return CaptureResolutionParseResult.error("captureResolution width and height must be positive");
|
|
66
|
+
}
|
|
67
|
+
return CaptureResolutionParseResult.success(captureWidth, captureHeight);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Nullable
|
|
71
|
+
static Integer parsePositivePixelDimension(@Nullable Object value) {
|
|
72
|
+
if (value == null || value == JSONObject.NULL) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
if (value instanceof Number) {
|
|
76
|
+
return parsePositivePixelDimensionFromDouble(((Number) value).doubleValue());
|
|
77
|
+
}
|
|
78
|
+
if (value instanceof String) {
|
|
79
|
+
String trimmed = ((String) value).trim();
|
|
80
|
+
if (trimmed.isEmpty()) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
return parsePositivePixelDimensionFromDouble(Double.parseDouble(trimmed));
|
|
85
|
+
} catch (NumberFormatException ignored) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@Nullable
|
|
93
|
+
private static Integer parsePositivePixelDimensionFromDouble(double numeric) {
|
|
94
|
+
if (Double.isNaN(numeric) || Double.isInfinite(numeric) || numeric <= 0) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
if (numeric != Math.floor(numeric) || numeric > Integer.MAX_VALUE) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return (int) numeric;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static Size normalizedCaptureTargetResolution(int configuredWidth, int configuredHeight) {
|
|
104
|
+
return new Size(Math.max(configuredWidth, configuredHeight), Math.min(configuredWidth, configuredHeight));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static List<Size> filterCaptureResolutionCandidates(@Nullable List<Size> supportedSizes, int maxCaptureLongEdge) {
|
|
108
|
+
if (supportedSizes == null || supportedSizes.isEmpty()) {
|
|
109
|
+
return supportedSizes;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
List<Size> cappedSizes = new ArrayList<>();
|
|
113
|
+
for (Size size : supportedSizes) {
|
|
114
|
+
int longEdge = Math.max(size.getWidth(), size.getHeight());
|
|
115
|
+
if (longEdge <= maxCaptureLongEdge) {
|
|
116
|
+
cappedSizes.add(size);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!cappedSizes.isEmpty()) {
|
|
121
|
+
return cappedSizes;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
Size smallest = supportedSizes.get(0);
|
|
125
|
+
int smallestLongEdge = Math.max(smallest.getWidth(), smallest.getHeight());
|
|
126
|
+
for (Size size : supportedSizes) {
|
|
127
|
+
int longEdge = Math.max(size.getWidth(), size.getHeight());
|
|
128
|
+
if (longEdge < smallestLongEdge) {
|
|
129
|
+
smallest = size;
|
|
130
|
+
smallestLongEdge = longEdge;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return Collections.singletonList(smallest);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static boolean captureRequiresSoftwareTransform(
|
|
137
|
+
@Nullable Integer width,
|
|
138
|
+
@Nullable Integer height,
|
|
139
|
+
boolean embedTimestamp,
|
|
140
|
+
boolean embedLocation,
|
|
141
|
+
boolean mirrorFrontCamera,
|
|
142
|
+
boolean shouldMirrorFrontCamera
|
|
143
|
+
) {
|
|
144
|
+
return width != null || height != null || embedTimestamp || embedLocation || (mirrorFrontCamera && shouldMirrorFrontCamera);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static boolean canUseViewportCaptureFastPath(
|
|
148
|
+
int requestedQuality,
|
|
149
|
+
int imageCaptureJpegQuality,
|
|
150
|
+
boolean requiresSoftwareTransform,
|
|
151
|
+
boolean viewportCropCurrent,
|
|
152
|
+
int exifOrientation
|
|
153
|
+
) {
|
|
154
|
+
return (
|
|
155
|
+
requestedQuality == imageCaptureJpegQuality &&
|
|
156
|
+
!requiresSoftwareTransform &&
|
|
157
|
+
viewportCropCurrent &&
|
|
158
|
+
exifOrientation == ExifInterface.ORIENTATION_NORMAL
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -31,6 +31,8 @@ public class CameraSessionConfiguration {
|
|
|
31
31
|
private boolean enablePhysicalDeviceSelection = false;
|
|
32
32
|
private boolean barcodeScannerEnabled = false;
|
|
33
33
|
private boolean mirrorFrontCamera = false;
|
|
34
|
+
private Integer captureResolutionWidth;
|
|
35
|
+
private Integer captureResolutionHeight;
|
|
34
36
|
|
|
35
37
|
public CameraSessionConfiguration(
|
|
36
38
|
String deviceId,
|
|
@@ -198,6 +200,35 @@ public class CameraSessionConfiguration {
|
|
|
198
200
|
this.barcodeScannerEnabled = barcodeScannerEnabled;
|
|
199
201
|
}
|
|
200
202
|
|
|
203
|
+
public boolean hasCaptureResolution() {
|
|
204
|
+
return (
|
|
205
|
+
captureResolutionWidth != null && captureResolutionHeight != null && captureResolutionWidth > 0 && captureResolutionHeight > 0
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public Integer getCaptureResolutionWidth() {
|
|
210
|
+
return captureResolutionWidth;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public Integer getCaptureResolutionHeight() {
|
|
214
|
+
return captureResolutionHeight;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public void setCaptureResolution(Integer width, Integer height) {
|
|
218
|
+
this.captureResolutionWidth = width;
|
|
219
|
+
this.captureResolutionHeight = height;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public void copyCaptureResolutionFrom(CameraSessionConfiguration source) {
|
|
223
|
+
if (source == null) {
|
|
224
|
+
this.captureResolutionWidth = null;
|
|
225
|
+
this.captureResolutionHeight = null;
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
this.captureResolutionWidth = source.captureResolutionWidth;
|
|
229
|
+
this.captureResolutionHeight = source.captureResolutionHeight;
|
|
230
|
+
}
|
|
231
|
+
|
|
201
232
|
// Additional getters with "get" prefix for compatibility
|
|
202
233
|
public boolean getToBack() {
|
|
203
234
|
return toBack;
|
package/android/src/test/java/app/capgo/capacitor/camera/preview/CaptureBitmapDecodingTest.java
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
package app.capgo.capacitor.camera.preview;
|
|
2
|
+
|
|
3
|
+
import static org.junit.Assert.assertEquals;
|
|
4
|
+
import static org.junit.Assert.assertNull;
|
|
5
|
+
import static org.junit.Assert.assertTrue;
|
|
6
|
+
|
|
7
|
+
import org.junit.Test;
|
|
8
|
+
import org.junit.runner.RunWith;
|
|
9
|
+
import org.robolectric.RobolectricTestRunner;
|
|
10
|
+
import org.robolectric.annotation.Config;
|
|
11
|
+
|
|
12
|
+
@RunWith(RobolectricTestRunner.class)
|
|
13
|
+
@Config(manifest = Config.NONE, sdk = 28)
|
|
14
|
+
public class CaptureBitmapDecodingTest {
|
|
15
|
+
|
|
16
|
+
@Test
|
|
17
|
+
public void computeInSampleSize_noBounds() {
|
|
18
|
+
assertEquals(1, CaptureBitmapDecoding.computeInSampleSize(4000, 3000, null, null));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Test
|
|
22
|
+
public void computeInSampleSize_scalesDownForMaxDimensions() {
|
|
23
|
+
int sampleSize = CaptureBitmapDecoding.computeInSampleSize(4000, 3000, 1920, 1080);
|
|
24
|
+
assertEquals(2, sampleSize);
|
|
25
|
+
int decodedWidth = 4000 / sampleSize;
|
|
26
|
+
int decodedHeight = 3000 / sampleSize;
|
|
27
|
+
assertEquals(2000, decodedWidth);
|
|
28
|
+
assertEquals(1500, decodedHeight);
|
|
29
|
+
assertTrue(decodedWidth >= 1920 && decodedHeight >= 1080);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Test
|
|
33
|
+
public void decodeJpegSubsamplingToMaxDimensions_returnsNullForEmptyInput() {
|
|
34
|
+
assertNull(CaptureBitmapDecoding.decodeJpegSubsamplingToMaxDimensions(new byte[0], 1920, 1080));
|
|
35
|
+
assertNull(CaptureBitmapDecoding.decodeJpegSubsamplingToMaxDimensions(null, 1920, 1080));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test
|
|
39
|
+
public void computeInSampleSize_singleDimensionBound() {
|
|
40
|
+
int sampleSize = CaptureBitmapDecoding.computeInSampleSize(4000, 3000, 800, null);
|
|
41
|
+
assertTrue(sampleSize >= 4);
|
|
42
|
+
}
|
|
43
|
+
}
|
package/android/src/test/java/app/capgo/capacitor/camera/preview/CaptureResolutionSupportTest.java
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
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.assertNull;
|
|
6
|
+
import static org.junit.Assert.assertTrue;
|
|
7
|
+
|
|
8
|
+
import android.util.Size;
|
|
9
|
+
import androidx.exifinterface.media.ExifInterface;
|
|
10
|
+
import java.util.Arrays;
|
|
11
|
+
import java.util.Collections;
|
|
12
|
+
import java.util.List;
|
|
13
|
+
import org.json.JSONObject;
|
|
14
|
+
import org.junit.Test;
|
|
15
|
+
import org.junit.runner.RunWith;
|
|
16
|
+
import org.robolectric.RobolectricTestRunner;
|
|
17
|
+
import org.robolectric.annotation.Config;
|
|
18
|
+
|
|
19
|
+
@RunWith(RobolectricTestRunner.class)
|
|
20
|
+
@Config(manifest = Config.NONE, sdk = 28)
|
|
21
|
+
public class CaptureResolutionSupportTest {
|
|
22
|
+
|
|
23
|
+
@Test
|
|
24
|
+
public void parseCaptureResolution_nullObject() {
|
|
25
|
+
CaptureResolutionSupport.CaptureResolutionParseResult result = CaptureResolutionSupport.parseStartCaptureResolution(null);
|
|
26
|
+
assertFalse(result.isError());
|
|
27
|
+
assertNull(result.width);
|
|
28
|
+
assertNull(result.height);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Test
|
|
32
|
+
public void parseCaptureResolution_missingWidthOrHeight() throws Exception {
|
|
33
|
+
CaptureResolutionSupport.CaptureResolutionParseResult missingWidth = CaptureResolutionSupport.parseStartCaptureResolution(
|
|
34
|
+
new JSONObject("{\"height\":1080}")
|
|
35
|
+
);
|
|
36
|
+
assertTrue(missingWidth.isError());
|
|
37
|
+
assertEquals("captureResolution requires both width and height", missingWidth.errorMessage);
|
|
38
|
+
|
|
39
|
+
CaptureResolutionSupport.CaptureResolutionParseResult missingHeight = CaptureResolutionSupport.parseStartCaptureResolution(
|
|
40
|
+
new JSONObject("{\"width\":1920}")
|
|
41
|
+
);
|
|
42
|
+
assertTrue(missingHeight.isError());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Test
|
|
46
|
+
public void parseCaptureResolution_invalidTypesAndValues() throws Exception {
|
|
47
|
+
assertTrue(CaptureResolutionSupport.parseStartCaptureResolution("not-an-object").isError());
|
|
48
|
+
|
|
49
|
+
CaptureResolutionSupport.CaptureResolutionParseResult zero = CaptureResolutionSupport.parseStartCaptureResolution(
|
|
50
|
+
new JSONObject("{\"width\":0,\"height\":1080}")
|
|
51
|
+
);
|
|
52
|
+
assertTrue(zero.isError());
|
|
53
|
+
|
|
54
|
+
CaptureResolutionSupport.CaptureResolutionParseResult negative = CaptureResolutionSupport.parseStartCaptureResolution(
|
|
55
|
+
new JSONObject("{\"width\":-1,\"height\":1080}")
|
|
56
|
+
);
|
|
57
|
+
assertTrue(negative.isError());
|
|
58
|
+
|
|
59
|
+
CaptureResolutionSupport.CaptureResolutionParseResult nanWidth = CaptureResolutionSupport.parseStartCaptureResolution(
|
|
60
|
+
new JSONObject("{\"width\":\"NaN\",\"height\":1080}")
|
|
61
|
+
);
|
|
62
|
+
assertTrue(nanWidth.isError());
|
|
63
|
+
|
|
64
|
+
CaptureResolutionSupport.CaptureResolutionParseResult nullWidth = CaptureResolutionSupport.parseStartCaptureResolution(
|
|
65
|
+
new JSONObject("{\"width\":null,\"height\":1080}")
|
|
66
|
+
);
|
|
67
|
+
assertTrue(nullWidth.isError());
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Test
|
|
71
|
+
public void parseCaptureResolution_stringNumbers() throws Exception {
|
|
72
|
+
CaptureResolutionSupport.CaptureResolutionParseResult result = CaptureResolutionSupport.parseStartCaptureResolution(
|
|
73
|
+
new JSONObject("{\"width\":\"1920\",\"height\":\"1080\"}")
|
|
74
|
+
);
|
|
75
|
+
assertFalse(result.isError());
|
|
76
|
+
assertEquals(Integer.valueOf(1920), result.width);
|
|
77
|
+
assertEquals(Integer.valueOf(1080), result.height);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Test
|
|
81
|
+
public void parseCaptureResolution_rejectsFractionalDimensions() throws Exception {
|
|
82
|
+
JSONObject fractional = new JSONObject();
|
|
83
|
+
fractional.put("width", 1920.7);
|
|
84
|
+
fractional.put("height", 1080);
|
|
85
|
+
CaptureResolutionSupport.CaptureResolutionParseResult result = CaptureResolutionSupport.parseStartCaptureResolution(fractional);
|
|
86
|
+
assertTrue(result.isError());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Test
|
|
90
|
+
public void parseCaptureResolution_validNumbers() throws Exception {
|
|
91
|
+
CaptureResolutionSupport.CaptureResolutionParseResult result = CaptureResolutionSupport.parseStartCaptureResolution(
|
|
92
|
+
new JSONObject("{\"width\":1600,\"height\":1200}")
|
|
93
|
+
);
|
|
94
|
+
assertFalse(result.isError());
|
|
95
|
+
assertEquals(Integer.valueOf(1600), result.width);
|
|
96
|
+
assertEquals(Integer.valueOf(1200), result.height);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Test
|
|
100
|
+
public void parsePositivePixelDimension_edgeCases() {
|
|
101
|
+
assertNull(CaptureResolutionSupport.parsePositivePixelDimension(null));
|
|
102
|
+
assertNull(CaptureResolutionSupport.parsePositivePixelDimension(Double.NaN));
|
|
103
|
+
assertNull(CaptureResolutionSupport.parsePositivePixelDimension("not-a-number"));
|
|
104
|
+
assertEquals(Integer.valueOf(42), CaptureResolutionSupport.parsePositivePixelDimension("42"));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@Test
|
|
108
|
+
public void normalizedCaptureTargetResolution_swapsToLandscapeMajor() {
|
|
109
|
+
Size normalized = CaptureResolutionSupport.normalizedCaptureTargetResolution(1080, 1920);
|
|
110
|
+
assertEquals(1920, normalized.getWidth());
|
|
111
|
+
assertEquals(1080, normalized.getHeight());
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@Test
|
|
115
|
+
public void filterCaptureResolutionCandidates_capsByLongEdge() {
|
|
116
|
+
List<Size> supported = Arrays.asList(new Size(4000, 3000), new Size(1920, 1080), new Size(1280, 720));
|
|
117
|
+
List<Size> capped = CaptureResolutionSupport.filterCaptureResolutionCandidates(supported, 1920);
|
|
118
|
+
assertEquals(2, capped.size());
|
|
119
|
+
for (Size size : capped) {
|
|
120
|
+
assertTrue(Math.max(size.getWidth(), size.getHeight()) <= 1920);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@Test
|
|
125
|
+
public void filterCaptureResolutionCandidates_fallsBackToSmallest() {
|
|
126
|
+
List<Size> supported = Arrays.asList(new Size(4000, 3000), new Size(3200, 2400));
|
|
127
|
+
List<Size> capped = CaptureResolutionSupport.filterCaptureResolutionCandidates(supported, 1000);
|
|
128
|
+
assertEquals(1, capped.size());
|
|
129
|
+
assertEquals(3200, capped.get(0).getWidth());
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@Test
|
|
133
|
+
public void filterCaptureResolutionCandidates_emptyInput() {
|
|
134
|
+
assertNull(CaptureResolutionSupport.filterCaptureResolutionCandidates(null, 1920));
|
|
135
|
+
assertTrue(CaptureResolutionSupport.filterCaptureResolutionCandidates(Collections.emptyList(), 1920).isEmpty());
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@Test
|
|
139
|
+
public void captureRequiresSoftwareTransform() {
|
|
140
|
+
assertTrue(CaptureResolutionSupport.captureRequiresSoftwareTransform(800, null, false, false, false, false));
|
|
141
|
+
assertTrue(CaptureResolutionSupport.captureRequiresSoftwareTransform(null, 600, false, false, false, false));
|
|
142
|
+
assertTrue(CaptureResolutionSupport.captureRequiresSoftwareTransform(null, null, true, false, false, false));
|
|
143
|
+
assertTrue(CaptureResolutionSupport.captureRequiresSoftwareTransform(null, null, false, true, false, false));
|
|
144
|
+
assertTrue(CaptureResolutionSupport.captureRequiresSoftwareTransform(null, null, false, false, true, true));
|
|
145
|
+
assertFalse(CaptureResolutionSupport.captureRequiresSoftwareTransform(null, null, false, false, true, false));
|
|
146
|
+
assertFalse(CaptureResolutionSupport.captureRequiresSoftwareTransform(null, null, false, false, false, false));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@Test
|
|
150
|
+
public void canUseViewportCaptureFastPath_qualityAndTransforms() {
|
|
151
|
+
assertTrue(
|
|
152
|
+
CaptureResolutionSupport.canUseViewportCaptureFastPath(
|
|
153
|
+
CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY,
|
|
154
|
+
CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY,
|
|
155
|
+
false,
|
|
156
|
+
true,
|
|
157
|
+
ExifInterface.ORIENTATION_NORMAL
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
assertFalse(
|
|
161
|
+
CaptureResolutionSupport.canUseViewportCaptureFastPath(
|
|
162
|
+
50,
|
|
163
|
+
CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY,
|
|
164
|
+
false,
|
|
165
|
+
true,
|
|
166
|
+
ExifInterface.ORIENTATION_NORMAL
|
|
167
|
+
)
|
|
168
|
+
);
|
|
169
|
+
assertFalse(
|
|
170
|
+
CaptureResolutionSupport.canUseViewportCaptureFastPath(
|
|
171
|
+
CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY,
|
|
172
|
+
CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY,
|
|
173
|
+
true,
|
|
174
|
+
true,
|
|
175
|
+
ExifInterface.ORIENTATION_NORMAL
|
|
176
|
+
)
|
|
177
|
+
);
|
|
178
|
+
assertFalse(
|
|
179
|
+
CaptureResolutionSupport.canUseViewportCaptureFastPath(
|
|
180
|
+
CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY,
|
|
181
|
+
CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY,
|
|
182
|
+
false,
|
|
183
|
+
false,
|
|
184
|
+
ExifInterface.ORIENTATION_NORMAL
|
|
185
|
+
)
|
|
186
|
+
);
|
|
187
|
+
assertFalse(
|
|
188
|
+
CaptureResolutionSupport.canUseViewportCaptureFastPath(
|
|
189
|
+
CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY,
|
|
190
|
+
CaptureResolutionSupport.DEFAULT_IMAGE_CAPTURE_JPEG_QUALITY,
|
|
191
|
+
false,
|
|
192
|
+
true,
|
|
193
|
+
ExifInterface.ORIENTATION_ROTATE_90
|
|
194
|
+
)
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
package/dist/docs.json
CHANGED
|
@@ -2082,6 +2082,24 @@
|
|
|
2082
2082
|
"complexTypes": [],
|
|
2083
2083
|
"type": "boolean | undefined"
|
|
2084
2084
|
},
|
|
2085
|
+
{
|
|
2086
|
+
"name": "captureResolution",
|
|
2087
|
+
"tags": [
|
|
2088
|
+
{
|
|
2089
|
+
"text": "android",
|
|
2090
|
+
"name": "platform"
|
|
2091
|
+
},
|
|
2092
|
+
{
|
|
2093
|
+
"text": "8.12.0",
|
|
2094
|
+
"name": "since"
|
|
2095
|
+
}
|
|
2096
|
+
],
|
|
2097
|
+
"docs": "Sets the Android still-capture resolution for the `ImageCapture` use case at session bind time.\nPreview resolution is unchanged. The shared ViewPort crop from the preview still applies to captures.\n\nWhen omitted, `ImageCapture` uses the highest resolution supported by the active camera\n(same as versions before 8.11.10). Set this to cap capture size for faster shots on high-megapixel\nsensors, for example `{ width: 1920, height: 1080 }` or `{ width: 1600, height: 1200 }`.",
|
|
2098
|
+
"complexTypes": [
|
|
2099
|
+
"CameraCaptureResolution"
|
|
2100
|
+
],
|
|
2101
|
+
"type": "CameraCaptureResolution"
|
|
2102
|
+
},
|
|
2085
2103
|
{
|
|
2086
2104
|
"name": "force",
|
|
2087
2105
|
"tags": [
|
|
@@ -2260,6 +2278,29 @@
|
|
|
2260
2278
|
}
|
|
2261
2279
|
]
|
|
2262
2280
|
},
|
|
2281
|
+
{
|
|
2282
|
+
"name": "CameraCaptureResolution",
|
|
2283
|
+
"slug": "cameracaptureresolution",
|
|
2284
|
+
"docs": "Target still-capture resolution for the Android `ImageCapture` use case.\n\nWidth and height define the resolution strategy target. The plugin also filters out\nsupported capture sizes whose long edge exceeds `max(width, height)`.",
|
|
2285
|
+
"tags": [],
|
|
2286
|
+
"methods": [],
|
|
2287
|
+
"properties": [
|
|
2288
|
+
{
|
|
2289
|
+
"name": "width",
|
|
2290
|
+
"tags": [],
|
|
2291
|
+
"docs": "Target width in pixels.",
|
|
2292
|
+
"complexTypes": [],
|
|
2293
|
+
"type": "number"
|
|
2294
|
+
},
|
|
2295
|
+
{
|
|
2296
|
+
"name": "height",
|
|
2297
|
+
"tags": [],
|
|
2298
|
+
"docs": "Target height in pixels.",
|
|
2299
|
+
"complexTypes": [],
|
|
2300
|
+
"type": "number"
|
|
2301
|
+
}
|
|
2302
|
+
]
|
|
2303
|
+
},
|
|
2263
2304
|
{
|
|
2264
2305
|
"name": "BarcodeScannerOptions",
|
|
2265
2306
|
"slug": "barcodescanneroptions",
|
|
@@ -4,6 +4,18 @@ export type FlashMode = CameraPreviewFlashMode;
|
|
|
4
4
|
export type GridMode = 'none' | '3x3' | '4x4';
|
|
5
5
|
export type CameraPositioning = 'center' | 'top' | 'bottom';
|
|
6
6
|
export type CameraPreviewAspectRatio = '4:3' | '16:9' | 'fill';
|
|
7
|
+
/**
|
|
8
|
+
* Target still-capture resolution for the Android `ImageCapture` use case.
|
|
9
|
+
*
|
|
10
|
+
* Width and height define the resolution strategy target. The plugin also filters out
|
|
11
|
+
* supported capture sizes whose long edge exceeds `max(width, height)`.
|
|
12
|
+
*/
|
|
13
|
+
export interface CameraCaptureResolution {
|
|
14
|
+
/** Target width in pixels. */
|
|
15
|
+
width: number;
|
|
16
|
+
/** Target height in pixels. */
|
|
17
|
+
height: number;
|
|
18
|
+
}
|
|
7
19
|
export type BarcodeScannerFormat = 'aztec' | 'codabar' | 'code_39' | 'code_93' | 'code_128' | 'data_matrix' | 'ean_8' | 'ean_13' | 'itf' | 'pdf417' | 'qr_code' | 'upc_a' | 'upc_e';
|
|
8
20
|
export type BarcodeFormat = BarcodeScannerFormat | 'unknown';
|
|
9
21
|
export interface BarcodeScannerOptions {
|
|
@@ -301,6 +313,18 @@ export interface CameraPreviewOptions {
|
|
|
301
313
|
* @since 7.11.0
|
|
302
314
|
*/
|
|
303
315
|
enableVideoMode?: boolean;
|
|
316
|
+
/**
|
|
317
|
+
* Sets the Android still-capture resolution for the `ImageCapture` use case at session bind time.
|
|
318
|
+
* Preview resolution is unchanged. The shared ViewPort crop from the preview still applies to captures.
|
|
319
|
+
*
|
|
320
|
+
* When omitted, `ImageCapture` uses the highest resolution supported by the active camera
|
|
321
|
+
* (same as versions before 8.11.10). Set this to cap capture size for faster shots on high-megapixel
|
|
322
|
+
* sensors, for example `{ width: 1920, height: 1080 }` or `{ width: 1600, height: 1200 }`.
|
|
323
|
+
*
|
|
324
|
+
* @platform android
|
|
325
|
+
* @since 8.12.0
|
|
326
|
+
*/
|
|
327
|
+
captureResolution?: CameraCaptureResolution;
|
|
304
328
|
/**
|
|
305
329
|
* If true, forces the camera to start/restart even if it's already running or busy.
|
|
306
330
|
* This will kill the current camera session and start a new one, ignoring all state checks.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA8EA,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\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 * 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 preview size and position.\n * @returns {Promise<{x: number, y: number, width: number, height: number}>}\n * @since 7.5.0\n * @platform android, ios\n */\n getPreviewSize(): Promise<{\n x: number;\n y: number;\n width: number;\n height: number;\n }>;\n /**\n * Sets the preview size and position.\n * @param options The new position and dimensions.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.5.0\n * @platform android, ios\n */\n setPreviewSize(options: { x?: number; y?: number; width: number; height: number }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Sets the camera focus to a specific point in the preview.\n *\n * Note: The plugin does not attach any native tap-to-focus gesture handlers. Handle taps in\n * your HTML/JS (e.g., on the overlaying UI), then pass normalized coordinates here.\n *\n * @param {Object} options - The focus options.\n * @param {number} options.x - The x coordinate in the preview view to focus on (0-1 normalized).\n * @param {number} options.y - The y coordinate in the preview view to focus on (0-1 normalized).\n * @returns {Promise<void>} A promise that resolves when the focus is set.\n * @since 7.5.0\n * @platform android, ios\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n\n /**\n * Adds a listener for screen resize events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: 'screenResize',\n listenerFunc: (data: { width: number; height: number; x: number; y: number }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for orientation change events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: 'orientationChange',\n listenerFunc: (data: { orientation: DeviceOrientation }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\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 Android still-capture resolution for the `ImageCapture` use case at session bind time.\n * Preview resolution is unchanged. The shared ViewPort crop from the preview still applies to captures.\n *\n * When omitted, `ImageCapture` uses the highest resolution supported by the active camera\n * (same as versions before 8.11.10). Set this to cap capture size for faster shots on high-megapixel\n * sensors, for example `{ width: 1920, height: 1080 }` or `{ width: 1600, height: 1200 }`.\n *\n * @platform android\n * @since 8.12.0\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 preview size and position.\n * @returns {Promise<{x: number, y: number, width: number, height: number}>}\n * @since 7.5.0\n * @platform android, ios\n */\n getPreviewSize(): Promise<{\n x: number;\n y: number;\n width: number;\n height: number;\n }>;\n /**\n * Sets the preview size and position.\n * @param options The new position and dimensions.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.5.0\n * @platform android, ios\n */\n setPreviewSize(options: { x?: number; y?: number; width: number; height: number }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Sets the camera focus to a specific point in the preview.\n *\n * Note: The plugin does not attach any native tap-to-focus gesture handlers. Handle taps in\n * your HTML/JS (e.g., on the overlaying UI), then pass normalized coordinates here.\n *\n * @param {Object} options - The focus options.\n * @param {number} options.x - The x coordinate in the preview view to focus on (0-1 normalized).\n * @param {number} options.y - The y coordinate in the preview view to focus on (0-1 normalized).\n * @returns {Promise<void>} A promise that resolves when the focus is set.\n * @since 7.5.0\n * @platform android, ios\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n\n /**\n * Adds a listener for screen resize events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: 'screenResize',\n listenerFunc: (data: { width: number; height: number; x: number; y: number }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for orientation change events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: 'orientationChange',\n listenerFunc: (data: { orientation: DeviceOrientation }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\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"]}
|
|
@@ -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.12.1"
|
|
39
39
|
public let identifier = "CameraPreviewPlugin"
|
|
40
40
|
public let jsName = "CameraPreview"
|
|
41
41
|
public let pluginMethods: [CAPPluginMethod] = [
|