@capgo/camera-preview 7.4.0-alpha.27 → 7.4.0-alpha.32
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 +15 -9
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +45 -67
- package/dist/docs.json +5 -12
- package/dist/esm/definitions.d.ts +19 -9
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift +151 -50
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -795,8 +795,14 @@ On web, this is not supported and will throw.
|
|
|
795
795
|
getSafeAreaInsets() => Promise<SafeAreaInsets>
|
|
796
796
|
```
|
|
797
797
|
|
|
798
|
-
Gets the safe area insets for
|
|
799
|
-
Returns the
|
|
798
|
+
Gets the safe area insets for devices.
|
|
799
|
+
Returns the orientation-aware notch/camera cutout inset and the current orientation.
|
|
800
|
+
In portrait mode: returns top inset (notch at top).
|
|
801
|
+
In landscape mode: returns left inset (notch moved to side).
|
|
802
|
+
This specifically targets the cutout area (notch, punch hole, etc.) that all modern phones have.
|
|
803
|
+
|
|
804
|
+
Android: Values returned in dp (logical pixels).
|
|
805
|
+
iOS: Values returned in physical pixels, excluding status bar (only pure notch/cutout size).
|
|
800
806
|
|
|
801
807
|
**Returns:** <code>Promise<<a href="#safeareainsets">SafeAreaInsets</a>></code>
|
|
802
808
|
|
|
@@ -960,14 +966,14 @@ Represents the detailed information of the currently active lens.
|
|
|
960
966
|
|
|
961
967
|
#### SafeAreaInsets
|
|
962
968
|
|
|
963
|
-
Represents safe area insets
|
|
964
|
-
Values are expressed in logical pixels (dp) to match JS layout units.
|
|
969
|
+
Represents safe area insets for devices.
|
|
970
|
+
Android: Values are expressed in logical pixels (dp) to match JS layout units.
|
|
971
|
+
iOS: Values are expressed in physical pixels and exclude status bar.
|
|
965
972
|
|
|
966
|
-
| Prop | Type | Description
|
|
967
|
-
| ----------------- | ------------------- |
|
|
968
|
-
| **`orientation`** | <code>number</code> | Current device orientation
|
|
969
|
-
| **`top`** | <code>number</code> |
|
|
970
|
-
| **`bottom`** | <code>number</code> | Bottom inset (e.g., navigation bar) in dp. |
|
|
973
|
+
| Prop | Type | Description |
|
|
974
|
+
| ----------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
975
|
+
| **`orientation`** | <code>number</code> | Current device orientation (1 = portrait, 2 = landscape, 0 = unknown). |
|
|
976
|
+
| **`top`** | <code>number</code> | Orientation-aware notch/camera cutout inset (excluding status bar). In portrait mode: returns top inset (notch at top). In landscape mode: returns left inset (notch at side). Android: Value in dp, iOS: Value in pixels (status bar excluded). |
|
|
971
977
|
|
|
972
978
|
|
|
973
979
|
### Type Aliases
|
|
@@ -1680,85 +1680,63 @@ public class CameraPreview
|
|
|
1680
1680
|
.getConfiguration()
|
|
1681
1681
|
.orientation;
|
|
1682
1682
|
|
|
1683
|
-
int
|
|
1684
|
-
|
|
1683
|
+
int notchInsetPx = 0;
|
|
1684
|
+
|
|
1685
1685
|
try {
|
|
1686
|
-
View
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
int webViewTop = location[1];
|
|
1696
|
-
int webViewBottom = webViewTop + webView.getHeight();
|
|
1697
|
-
int webViewBottomGap = Math.max(0, screenHeight - webViewBottom);
|
|
1698
|
-
|
|
1699
|
-
// System insets (status/navigation/cutout)
|
|
1700
|
-
int systemTop = 0;
|
|
1701
|
-
int systemBottom = 0;
|
|
1702
|
-
View decorView = getBridge().getActivity().getWindow().getDecorView();
|
|
1703
|
-
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(decorView);
|
|
1704
|
-
if (insets != null) {
|
|
1705
|
-
Insets sysBars = insets.getInsets(
|
|
1706
|
-
WindowInsetsCompat.Type.systemBars()
|
|
1707
|
-
);
|
|
1708
|
-
Insets cutout = insets.getInsets(
|
|
1709
|
-
WindowInsetsCompat.Type.displayCutout()
|
|
1710
|
-
);
|
|
1711
|
-
systemTop = Math.max(sysBars.top, cutout.top);
|
|
1712
|
-
systemBottom = Math.max(sysBars.bottom, cutout.bottom);
|
|
1713
|
-
} else {
|
|
1714
|
-
systemTop = getStatusBarHeightPx();
|
|
1715
|
-
systemBottom = getNavigationBarHeightPx();
|
|
1716
|
-
}
|
|
1686
|
+
View decorView = getBridge().getActivity().getWindow().getDecorView();
|
|
1687
|
+
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(decorView);
|
|
1688
|
+
|
|
1689
|
+
if (insets != null) {
|
|
1690
|
+
// Get display cutout insets (notch, punch hole, etc.)
|
|
1691
|
+
// this.Capacitor.Plugins.CameraPreview.getSafeAreaInsets()
|
|
1692
|
+
Insets cutout = insets.getInsets(
|
|
1693
|
+
WindowInsetsCompat.Type.displayCutout()
|
|
1694
|
+
);
|
|
1717
1695
|
|
|
1718
|
-
//
|
|
1719
|
-
|
|
1696
|
+
// Get system bars insets (status bar, navigation bars)
|
|
1697
|
+
Insets sysBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
|
1720
1698
|
|
|
1721
|
-
//
|
|
1722
|
-
//
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1699
|
+
// In portrait mode, notch is at the top
|
|
1700
|
+
// In landscape mode, notch is typically at the left side (or right, but left is more common)
|
|
1701
|
+
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
1702
|
+
// Portrait: return top inset (notch/status bar)
|
|
1703
|
+
notchInsetPx = Math.max(cutout.top, sysBars.top);
|
|
1704
|
+
|
|
1705
|
+
// If no cutout detected but we have system bars, use status bar height as fallback
|
|
1706
|
+
if (cutout.top == 0 && sysBars.top > 0) {
|
|
1707
|
+
notchInsetPx = sysBars.top;
|
|
1708
|
+
}
|
|
1709
|
+
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
1710
|
+
// Landscape: return left inset (notch moved to side)
|
|
1711
|
+
notchInsetPx = Math.max(cutout.left, sysBars.left);
|
|
1712
|
+
|
|
1713
|
+
// If no cutout detected but we have system bars, use left system bar as fallback
|
|
1714
|
+
if (cutout.left == 0 && sysBars.left > 0) {
|
|
1715
|
+
notchInsetPx = sysBars.left;
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
// Additional fallback: some devices might have the notch on the right in landscape
|
|
1719
|
+
// If left is 0, check right side as well
|
|
1720
|
+
if (notchInsetPx == 0) {
|
|
1721
|
+
notchInsetPx = Math.max(cutout.right, sysBars.right);
|
|
1722
|
+
}
|
|
1732
1723
|
} else {
|
|
1733
|
-
|
|
1724
|
+
// Unknown orientation, default to top
|
|
1725
|
+
notchInsetPx = Math.max(cutout.top, sysBars.top);
|
|
1734
1726
|
}
|
|
1735
1727
|
} else {
|
|
1736
|
-
// Fallback if
|
|
1737
|
-
|
|
1738
|
-
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(decorView);
|
|
1739
|
-
if (insets != null) {
|
|
1740
|
-
Insets sysBars = insets.getInsets(
|
|
1741
|
-
WindowInsetsCompat.Type.systemBars()
|
|
1742
|
-
);
|
|
1743
|
-
Insets cutout = insets.getInsets(
|
|
1744
|
-
WindowInsetsCompat.Type.displayCutout()
|
|
1745
|
-
);
|
|
1746
|
-
topPx = Math.max(sysBars.top, cutout.top);
|
|
1747
|
-
bottomPx = Math.max(sysBars.bottom, cutout.bottom);
|
|
1748
|
-
} else {
|
|
1749
|
-
topPx = getStatusBarHeightPx();
|
|
1750
|
-
bottomPx = getNavigationBarHeightPx();
|
|
1751
|
-
}
|
|
1728
|
+
// Fallback to status bar height if WindowInsets are not available
|
|
1729
|
+
notchInsetPx = getStatusBarHeightPx();
|
|
1752
1730
|
}
|
|
1753
1731
|
} catch (Exception e) {
|
|
1754
|
-
|
|
1755
|
-
|
|
1732
|
+
// Final fallback
|
|
1733
|
+
notchInsetPx = getStatusBarHeightPx();
|
|
1756
1734
|
}
|
|
1757
1735
|
|
|
1736
|
+
// Convert pixels to dp for consistency with JS layout units
|
|
1758
1737
|
float density = getContext().getResources().getDisplayMetrics().density;
|
|
1759
1738
|
ret.put("orientation", orientation);
|
|
1760
|
-
ret.put("top",
|
|
1761
|
-
ret.put("bottom", bottomPx / density);
|
|
1739
|
+
ret.put("top", notchInsetPx / density);
|
|
1762
1740
|
call.resolve(ret);
|
|
1763
1741
|
}
|
|
1764
1742
|
|
package/dist/docs.json
CHANGED
|
@@ -853,10 +853,10 @@
|
|
|
853
853
|
"tags": [
|
|
854
854
|
{
|
|
855
855
|
"name": "platform",
|
|
856
|
-
"text": "android"
|
|
856
|
+
"text": "android, ios"
|
|
857
857
|
}
|
|
858
858
|
],
|
|
859
|
-
"docs": "Gets the safe area insets for
|
|
859
|
+
"docs": "Gets the safe area insets for devices.\nReturns the orientation-aware notch/camera cutout inset and the current orientation.\nIn portrait mode: returns top inset (notch at top).\nIn landscape mode: returns left inset (notch moved to side).\nThis specifically targets the cutout area (notch, punch hole, etc.) that all modern phones have.\n\nAndroid: Values returned in dp (logical pixels).\niOS: Values returned in physical pixels, excluding status bar (only pure notch/cutout size).",
|
|
860
860
|
"complexTypes": [
|
|
861
861
|
"SafeAreaInsets"
|
|
862
862
|
],
|
|
@@ -1608,28 +1608,21 @@
|
|
|
1608
1608
|
{
|
|
1609
1609
|
"name": "SafeAreaInsets",
|
|
1610
1610
|
"slug": "safeareainsets",
|
|
1611
|
-
"docs": "Represents safe area insets
|
|
1611
|
+
"docs": "Represents safe area insets for devices.\nAndroid: Values are expressed in logical pixels (dp) to match JS layout units.\niOS: Values are expressed in physical pixels and exclude status bar.",
|
|
1612
1612
|
"tags": [],
|
|
1613
1613
|
"methods": [],
|
|
1614
1614
|
"properties": [
|
|
1615
1615
|
{
|
|
1616
1616
|
"name": "orientation",
|
|
1617
1617
|
"tags": [],
|
|
1618
|
-
"docs": "Current device orientation
|
|
1618
|
+
"docs": "Current device orientation (1 = portrait, 2 = landscape, 0 = unknown).",
|
|
1619
1619
|
"complexTypes": [],
|
|
1620
1620
|
"type": "number"
|
|
1621
1621
|
},
|
|
1622
1622
|
{
|
|
1623
1623
|
"name": "top",
|
|
1624
1624
|
"tags": [],
|
|
1625
|
-
"docs": "
|
|
1626
|
-
"complexTypes": [],
|
|
1627
|
-
"type": "number"
|
|
1628
|
-
},
|
|
1629
|
-
{
|
|
1630
|
-
"name": "bottom",
|
|
1631
|
-
"tags": [],
|
|
1632
|
-
"docs": "Bottom inset (e.g., navigation bar) in dp.",
|
|
1625
|
+
"docs": "Orientation-aware notch/camera cutout inset (excluding status bar).\nIn portrait mode: returns top inset (notch at top).\nIn landscape mode: returns left inset (notch at side).\nAndroid: Value in dp, iOS: Value in pixels (status bar excluded).",
|
|
1633
1626
|
"complexTypes": [],
|
|
1634
1627
|
"type": "number"
|
|
1635
1628
|
}
|
|
@@ -291,16 +291,20 @@ export interface CameraOpacityOptions {
|
|
|
291
291
|
opacity?: number;
|
|
292
292
|
}
|
|
293
293
|
/**
|
|
294
|
-
* Represents safe area insets
|
|
295
|
-
* Values are expressed in logical pixels (dp) to match JS layout units.
|
|
294
|
+
* Represents safe area insets for devices.
|
|
295
|
+
* Android: Values are expressed in logical pixels (dp) to match JS layout units.
|
|
296
|
+
* iOS: Values are expressed in physical pixels and exclude status bar.
|
|
296
297
|
*/
|
|
297
298
|
export interface SafeAreaInsets {
|
|
298
|
-
/** Current device orientation
|
|
299
|
+
/** Current device orientation (1 = portrait, 2 = landscape, 0 = unknown). */
|
|
299
300
|
orientation: number;
|
|
300
|
-
/**
|
|
301
|
+
/**
|
|
302
|
+
* Orientation-aware notch/camera cutout inset (excluding status bar).
|
|
303
|
+
* In portrait mode: returns top inset (notch at top).
|
|
304
|
+
* In landscape mode: returns left inset (notch at side).
|
|
305
|
+
* Android: Value in dp, iOS: Value in pixels (status bar excluded).
|
|
306
|
+
*/
|
|
301
307
|
top: number;
|
|
302
|
-
/** Bottom inset (e.g., navigation bar) in dp. */
|
|
303
|
-
bottom: number;
|
|
304
308
|
}
|
|
305
309
|
/**
|
|
306
310
|
* Canonical device orientation values across platforms.
|
|
@@ -652,10 +656,16 @@ export interface CameraPreviewPlugin {
|
|
|
652
656
|
success: boolean;
|
|
653
657
|
}>;
|
|
654
658
|
/**
|
|
655
|
-
* Gets the safe area insets for
|
|
656
|
-
* Returns the
|
|
659
|
+
* Gets the safe area insets for devices.
|
|
660
|
+
* Returns the orientation-aware notch/camera cutout inset and the current orientation.
|
|
661
|
+
* In portrait mode: returns top inset (notch at top).
|
|
662
|
+
* In landscape mode: returns left inset (notch moved to side).
|
|
663
|
+
* This specifically targets the cutout area (notch, punch hole, etc.) that all modern phones have.
|
|
657
664
|
*
|
|
658
|
-
*
|
|
665
|
+
* Android: Values returned in dp (logical pixels).
|
|
666
|
+
* iOS: Values returned in physical pixels, excluding status bar (only pure notch/cutout size).
|
|
667
|
+
*
|
|
668
|
+
* @platform android, ios
|
|
659
669
|
*/
|
|
660
670
|
getSafeAreaInsets(): Promise<SafeAreaInsets>;
|
|
661
671
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAUA,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,sCAAwB,CAAA;IACxB,sCAAwB,CAAA;IACxB,qCAAuB,CAAA;IACvB,sCAAwB,CAAA;IACxB,2BAAa,CAAA;IACb,oCAAsB,CAAA;IACtB,+BAAiB,CAAA;AACnB,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport type CameraPositioning = \"center\" | \"top\" | \"bottom\";\n\nexport enum DeviceType {\n ULTRA_WIDE = \"ultraWide\",\n WIDE_ANGLE = \"wideAngle\",\n TELEPHOTO = \"telephoto\",\n TRUE_DEPTH = \"trueDepth\",\n DUAL = \"dual\",\n DUAL_WIDE = \"dualWide\",\n TRIPLE = \"triple\",\n}\n\n/**\n * Represents a single camera lens on a device. A {@link CameraDevice} can have multiple lenses.\n */\nexport interface CameraLens {\n /** A human-readable name for the lens, e.g., \"Ultra-Wide\". */\n label: string;\n /** The type of the camera lens. */\n deviceType: DeviceType;\n /** The focal length of the lens in millimeters. */\n focalLength: number;\n /** The base zoom factor for this lens (e.g., 0.5 for ultra-wide, 1.0 for wide). */\n baseZoomRatio: number;\n /** The minimum zoom factor supported by this specific lens. */\n minZoom: number;\n /** The maximum zoom factor supported by this specific lens. */\n maxZoom: number;\n}\n\n/**\n * Represents a physical camera on the device (e.g., the front-facing camera).\n */\nexport interface CameraDevice {\n /** A unique identifier for the camera device. */\n deviceId: string;\n /** A human-readable name for the camera device. */\n label: string;\n /** The physical position of the camera on the device. */\n position: CameraPosition;\n /** A list of all available lenses for this camera device. */\n lenses: CameraLens[];\n /** The overall minimum zoom factor available across all lenses on this device. */\n minZoom: number;\n /** The overall maximum zoom factor available across all lenses on this device. */\n maxZoom: number;\n /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */\n isLogical: boolean;\n}\n\n/**\n * Represents the detailed information of the currently active lens.\n */\nexport interface LensInfo {\n /** The focal length of the active lens in millimeters. */\n focalLength: number;\n /** The device type of the active lens. */\n deviceType: DeviceType;\n /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */\n baseZoomRatio: number;\n /** The current digital zoom factor applied on top of the base zoom. */\n digitalZoom: number;\n}\n\n/**\n * Defines the configuration options for starting the camera preview.\n */\nexport interface CameraPreviewOptions {\n /**\n * The parent element to attach the video preview to.\n * @platform web\n */\n parent?: string;\n /**\n * A CSS class name to add to the preview element.\n * @platform web\n */\n className?: string;\n /**\n * The width of the preview in pixels. Defaults to the screen width.\n * @platform android, ios, web\n */\n width?: number;\n /**\n * The height of the preview in pixels. Defaults to the screen height.\n * @platform android, ios, web\n */\n height?: number;\n /**\n * The horizontal origin of the preview, in pixels.\n * @platform android, ios\n */\n x?: number;\n /**\n * The vertical origin of the preview, in pixels.\n * @platform android, ios\n */\n y?: number;\n /**\n * The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'.\n * Cannot be set if width or height is provided, otherwise the call will be rejected.\n * Use setPreviewSize to adjust size after starting.\n *\n * @since 2.0.0\n */\n aspectRatio?: \"4:3\" | \"16:9\";\n /**\n * The grid overlay to display on the camera preview.\n * @default \"none\"\n * @since 2.1.0\n */\n gridMode?: GridMode;\n /**\n * Adjusts the y-position to account for safe areas (e.g., notches).\n * @platform ios\n * @default false\n */\n includeSafeAreaInsets?: boolean;\n /**\n * If true, places the preview behind the webview.\n * @platform android\n * @default true\n */\n toBack?: boolean;\n /**\n * Bottom padding for the preview, in pixels.\n * @platform android, ios\n */\n paddingBottom?: number;\n /**\n * Whether to rotate the preview when the device orientation changes.\n * @platform ios\n * @default true\n */\n rotateWhenOrientationChanged?: boolean;\n /**\n * The camera to use.\n * @default \"rear\"\n */\n position?: CameraPosition | string;\n /**\n * If true, saves the captured image to a file and returns the file path.\n * If false, returns a base64 encoded string.\n * @default false\n */\n storeToFile?: boolean;\n /**\n * If true, prevents the plugin from rotating the image based on EXIF data.\n * @platform android\n * @default false\n */\n disableExifHeaderStripping?: boolean;\n /**\n * If true, disables the audio stream, preventing audio permission requests.\n * @default true\n */\n disableAudio?: boolean;\n /**\n * If true, locks the device orientation while the camera is active.\n * @platform android\n * @default false\n */\n lockAndroidOrientation?: boolean;\n /**\n * If true, allows the camera preview's opacity to be changed.\n * @platform android, web\n * @default false\n */\n enableOpacity?: boolean;\n /**\n * If true, enables pinch-to-zoom functionality on the preview.\n * @platform android\n * @default false\n */\n enableZoom?: boolean;\n /**\n * If true, uses the video-optimized preset for the camera session.\n * @platform ios\n * @default false\n */\n enableVideoMode?: boolean;\n /**\n * The `deviceId` of the camera to use. If provided, `position` is ignored.\n * @platform ios\n */\n deviceId?: string;\n /**\n * The initial zoom level when starting the camera preview.\n * If the requested zoom level is not available, the native plugin will reject.\n * @default 1.0\n * @platform android, ios\n * @since 2.2.0\n */\n initialZoomLevel?: number;\n /**\n * The vertical positioning of the camera preview.\n * @default \"center\"\n * @platform android, ios, web\n * @since 2.3.0\n */\n positioning?: CameraPositioning;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /** @deprecated,\n * The desired height of the picture in pixels.\n * If not specified and no aspectRatio is provided, the captured image will match the preview's visible area.\n */\n height?: number;\n /** @deprecated,\n * The desired width of the picture in pixels.\n * If not specified and no aspectRatio is provided, the captured image will match the preview's visible area.\n */\n width?: number;\n /** @deprecated,\n * The desired aspect ratio of the captured image (e.g., '4:3', '16:9').\n * If not specified and no width/height is provided, the aspect ratio from the camera start will be used.\n * If no aspect ratio was set at start, defaults to '4:3'.\n * Cannot be used together with width or height - the capture will be rejected with an error.\n * @since 7.7.0\n */\n aspectRatio?: string;\n /**\n * The quality of the captured image, from 0 to 100.\n * Does not apply to `png` format.\n * @default 85\n */\n quality?: number;\n /**\n * The format of the captured image.\n * @default \"jpeg\"\n */\n format?: PictureFormat;\n /**\n * If true, the captured image will be saved to the user's gallery.\n * @default false\n * @since 7.5.0\n */\n saveToGallery?: boolean;\n /**\n * If true, the plugin will attempt to add GPS location data to the image's EXIF metadata.\n * This may prompt the user for location permissions.\n * @default false\n * @since 7.6.0\n */\n withExifLocation?: boolean;\n}\n\n/** Represents EXIF data extracted from an image. */\nexport interface ExifData {\n [key: string]: any;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\n/** Defines a standard picture size with width and height. */\nexport interface PictureSize {\n /** The width of the picture in pixels. */\n width: number;\n /** The height of the picture in pixels. */\n height: number;\n}\n\n/** Represents the supported picture sizes for a camera facing a certain direction. */\nexport interface SupportedPictureSizes {\n /** The camera direction (\"front\" or \"rear\"). */\n facing: string;\n /** A list of supported picture sizes for this camera. */\n supportedPictureSizes: PictureSize[];\n}\n\n/**\n * Defines the options for capturing a sample frame from the camera preview.\n */\nexport interface CameraSampleOptions {\n /**\n * The quality of the captured sample, from 0 to 100.\n * @default 85\n */\n quality?: number;\n}\n\n/**\n * The available flash modes for the camera.\n * 'torch' is a continuous light mode.\n */\nexport type CameraPreviewFlashMode = \"off\" | \"on\" | \"auto\" | \"torch\";\n\n/**\n * Defines the options for setting the camera preview's opacity.\n */\nexport interface CameraOpacityOptions {\n /**\n * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).\n * @default 1.0\n */\n opacity?: number;\n}\n\n/**\n * Represents safe area insets on Android.\n * Values are expressed in logical pixels (dp) to match JS layout units.\n */\nexport interface SafeAreaInsets {\n /** Current device orientation as reported by Android configuration. */\n orientation: number;\n /** Top inset (e.g., status bar or cutout) in dp. */\n top: number;\n /** Bottom inset (e.g., navigation bar) in dp. */\n bottom: number;\n}\n\n/**\n * Canonical device orientation values across platforms.\n */\nexport type DeviceOrientation =\n | \"portrait\"\n | \"landscape\"\n | \"landscape-left\"\n | \"landscape-right\"\n | \"portrait-upside-down\"\n | \"unknown\";\n\n/**\n * The main interface for the CameraPreview plugin.\n */\nexport interface CameraPreviewPlugin {\n /**\n * Starts the camera preview.\n *\n * @param {CameraPreviewOptions} options - The configuration for the camera preview.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the preview dimensions.\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<{\n /** The width of the preview in pixels. */\n width: number;\n /** The height of the preview in pixels. */\n height: number;\n /** The horizontal origin of the preview, in pixels. */\n x: number;\n /** The vertical origin of the preview, in pixels. */\n y: number;\n }>;\n\n /**\n * Stops the camera preview.\n *\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(): Promise<void>;\n\n /**\n * Captures a picture from the camera.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string }>} A promise that resolves with the captured image data.\n * The `value` is a base64 encoded string unless `storeToFile` is true, in which case it's a file path.\n * @since 0.0.1\n */\n capture(\n options: CameraPreviewPictureOptions,\n ): Promise<{ value: string; exif: ExifData }>;\n\n /**\n * Captures a single frame from the camera preview stream.\n *\n * @param {CameraSampleOptions} options - The options for capturing the sample.\n * @returns {Promise<{ value: string }>} A promise that resolves with the sample image as a base64 encoded string.\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n\n /**\n * Gets the flash modes supported by the active camera.\n *\n * @returns {Promise<{ result: CameraPreviewFlashMode[] }>} A promise that resolves with an array of supported flash modes.\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n\n /**\n * Set the aspect ratio of the camera preview.\n *\n * @param {{ aspectRatio: '4:3' | '16:9'; x?: number; y?: number }} options - The desired aspect ratio and optional position.\n * - aspectRatio: The desired aspect ratio ('4:3' or '16:9')\n * - x: Optional x coordinate for positioning. If not provided, view will be auto-centered horizontally.\n * - y: Optional y coordinate for positioning. If not provided, view will be auto-centered vertically.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.5.0\n * @platform android, ios\n */\n setAspectRatio(options: {\n aspectRatio: \"4:3\" | \"16:9\";\n x?: number;\n y?: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Gets the current aspect ratio of the camera preview.\n *\n * @returns {Promise<{ aspectRatio: '4:3' | '16:9' }>} A promise that resolves with the current aspect ratio.\n * @since 7.5.0\n * @platform android, ios\n */\n getAspectRatio(): Promise<{ aspectRatio: \"4:3\" | \"16:9\" }>;\n\n /**\n * Sets the grid mode of the camera preview overlay.\n *\n * @param {{ gridMode: GridMode }} options - The desired grid mode ('none', '3x3', or '4x4').\n * @returns {Promise<void>} A promise that resolves when the grid mode is set.\n * @since 8.0.0\n */\n setGridMode(options: { gridMode: GridMode }): Promise<void>;\n\n /**\n * Gets the current grid mode of the camera preview overlay.\n *\n * @returns {Promise<{ gridMode: GridMode }>} A promise that resolves with the current grid mode.\n * @since 8.0.0\n */\n getGridMode(): Promise<{ gridMode: GridMode }>;\n\n /**\n * Gets the horizontal field of view (FoV) for the active camera.\n * Note: This can be an estimate on some devices.\n *\n * @returns {Promise<{ result: number }>} A promise that resolves with the horizontal field of view in degrees.\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: number;\n }>;\n\n /**\n * Gets the supported picture sizes for all cameras.\n *\n * @returns {Promise<{ supportedPictureSizes: SupportedPictureSizes[] }>} A promise that resolves with the list of supported sizes.\n * @since 7.4.0\n */\n getSupportedPictureSizes(): Promise<{\n supportedPictureSizes: SupportedPictureSizes[];\n }>;\n\n /**\n * Sets the flash mode for the active camera.\n *\n * @param {{ flashMode: CameraPreviewFlashMode | string }} options - The desired flash mode.\n * @returns {Promise<void>} A promise that resolves when the flash mode is set.\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n\n /**\n * Toggles between the front and rear cameras.\n *\n * @returns {Promise<void>} A promise that resolves when the camera is flipped.\n * @since 0.0.1\n */\n flip(): Promise<void>;\n\n /**\n * Sets the opacity of the camera preview.\n *\n * @param {CameraOpacityOptions} options - The opacity options.\n * @returns {Promise<void>} A promise that resolves when the opacity is set.\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n\n /**\n * Stops an ongoing video recording.\n *\n * @returns {Promise<{ videoFilePath: string }>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{ videoFilePath: string }>;\n\n /**\n * Starts recording a video.\n *\n * @param {CameraPreviewOptions} options - The options for video recording.\n * @returns {Promise<void>} A promise that resolves when video recording starts.\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n\n /**\n * Checks if the camera preview is currently running.\n *\n * @returns {Promise<{ isRunning: boolean }>} A promise that resolves with the running state.\n * @since 7.5.0\n * @platform android, ios\n */\n isRunning(): Promise<{ isRunning: boolean }>;\n\n /**\n * Gets all available camera devices.\n *\n * @returns {Promise<{ devices: CameraDevice[] }>} A promise that resolves with the list of available camera devices.\n * @since 7.5.0\n * @platform android, ios\n */\n getAvailableDevices(): Promise<{ devices: CameraDevice[] }>;\n\n /**\n * Gets the current zoom state, including min/max and current lens info.\n *\n * @returns {Promise<{ min: number; max: number; current: number; lens: LensInfo }>} A promise that resolves with the zoom state.\n * @since 7.5.0\n * @platform android, ios\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Returns zoom button values for quick switching.\n * - iOS/Android: includes 0.5 if ultra-wide available; 1 and 2 if wide available; 3 if telephoto available\n * - Web: unsupported\n * @since 7.5.0\n * @platform android, ios\n */\n getZoomButtonValues(): Promise<{ values: number[] }>;\n\n /**\n * Sets the zoom level of the camera.\n *\n * @param {{ level: number; ramp?: boolean; autoFocus?: boolean }} options - The desired zoom level. `ramp` is currently unused. `autoFocus` defaults to true.\n * @returns {Promise<void>} A promise that resolves when the zoom level is set.\n * @since 7.5.0\n * @platform android, ios\n */\n setZoom(options: {\n level: number;\n ramp?: boolean;\n autoFocus?: boolean;\n }): Promise<void>;\n\n /**\n * Gets the current flash mode.\n *\n * @returns {Promise<{ flashMode: FlashMode }>} A promise that resolves with the current flash mode.\n * @since 7.5.0\n * @platform android, ios\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.5.0\n * @platform android, ios\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Switches the active camera to the one with the specified `deviceId`.\n *\n * @param {{ deviceId: string }} options - The ID of the device to switch to.\n * @returns {Promise<void>} A promise that resolves when the camera is switched.\n * @since 7.5.0\n * @platform android, ios\n */\n setDeviceId(options: { deviceId: string }): Promise<void>;\n\n /**\n * Gets the ID of the currently active camera device.\n *\n * @returns {Promise<{ deviceId: string }>} A promise that resolves with the current device ID.\n * @since 7.5.0\n * @platform android, ios\n */\n getDeviceId(): Promise<{ deviceId: string }>;\n\n /**\n * Gets the current preview size and position.\n * @returns {Promise<{x: number, y: number, width: number, height: number}>}\n * @since 7.5.0\n * @platform android, ios\n */\n getPreviewSize(): Promise<{\n x: number;\n y: number;\n width: number;\n height: number;\n }>;\n /**\n * Sets the preview size and position.\n * @param options The new position and dimensions.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.5.0\n * @platform android, ios\n */\n setPreviewSize(options: {\n x?: number;\n y?: number;\n width: number;\n height: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Sets the camera focus to a specific point in the preview.\n *\n * @param {Object} options - The focus options.\n * @param {number} options.x - The x coordinate in the preview view to focus on (0-1 normalized).\n * @param {number} options.y - The y coordinate in the preview view to focus on (0-1 normalized).\n * @returns {Promise<void>} A promise that resolves when the focus is set.\n * @since 7.5.0\n * @platform android, ios\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n\n /**\n * Adds a listener for screen resize events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"screenResize\",\n listenerFunc: (data: {\n width: number;\n height: number;\n x: number;\n y: number;\n }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for orientation change events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"orientationChange\",\n listenerFunc: (data: { orientation: DeviceOrientation }) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Deletes a file at the given absolute path on the device.\n * Use this to quickly clean up temporary images created with `storeToFile`.\n * On web, this is not supported and will throw.\n * @since 7.5.0\n * @platform android, ios\n */\n deleteFile(options: { path: string }): Promise<{ success: boolean }>;\n\n /**\n * Gets the safe area insets for Android devices.\n * Returns the top and bottom insets in dp and the current orientation.\n *\n * @platform android\n */\n getSafeAreaInsets(): Promise<SafeAreaInsets>;\n\n /**\n * Gets the current device orientation in a cross-platform format.\n * @since 7.5.0\n * @platform android, ios\n */\n getOrientation(): Promise<{ orientation: DeviceOrientation }>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAUA,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,sCAAwB,CAAA;IACxB,sCAAwB,CAAA;IACxB,qCAAuB,CAAA;IACvB,sCAAwB,CAAA;IACxB,2BAAa,CAAA;IACb,oCAAsB,CAAA;IACtB,+BAAiB,CAAA;AACnB,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport type CameraPositioning = \"center\" | \"top\" | \"bottom\";\n\nexport enum DeviceType {\n ULTRA_WIDE = \"ultraWide\",\n WIDE_ANGLE = \"wideAngle\",\n TELEPHOTO = \"telephoto\",\n TRUE_DEPTH = \"trueDepth\",\n DUAL = \"dual\",\n DUAL_WIDE = \"dualWide\",\n TRIPLE = \"triple\",\n}\n\n/**\n * Represents a single camera lens on a device. A {@link CameraDevice} can have multiple lenses.\n */\nexport interface CameraLens {\n /** A human-readable name for the lens, e.g., \"Ultra-Wide\". */\n label: string;\n /** The type of the camera lens. */\n deviceType: DeviceType;\n /** The focal length of the lens in millimeters. */\n focalLength: number;\n /** The base zoom factor for this lens (e.g., 0.5 for ultra-wide, 1.0 for wide). */\n baseZoomRatio: number;\n /** The minimum zoom factor supported by this specific lens. */\n minZoom: number;\n /** The maximum zoom factor supported by this specific lens. */\n maxZoom: number;\n}\n\n/**\n * Represents a physical camera on the device (e.g., the front-facing camera).\n */\nexport interface CameraDevice {\n /** A unique identifier for the camera device. */\n deviceId: string;\n /** A human-readable name for the camera device. */\n label: string;\n /** The physical position of the camera on the device. */\n position: CameraPosition;\n /** A list of all available lenses for this camera device. */\n lenses: CameraLens[];\n /** The overall minimum zoom factor available across all lenses on this device. */\n minZoom: number;\n /** The overall maximum zoom factor available across all lenses on this device. */\n maxZoom: number;\n /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */\n isLogical: boolean;\n}\n\n/**\n * Represents the detailed information of the currently active lens.\n */\nexport interface LensInfo {\n /** The focal length of the active lens in millimeters. */\n focalLength: number;\n /** The device type of the active lens. */\n deviceType: DeviceType;\n /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */\n baseZoomRatio: number;\n /** The current digital zoom factor applied on top of the base zoom. */\n digitalZoom: number;\n}\n\n/**\n * Defines the configuration options for starting the camera preview.\n */\nexport interface CameraPreviewOptions {\n /**\n * The parent element to attach the video preview to.\n * @platform web\n */\n parent?: string;\n /**\n * A CSS class name to add to the preview element.\n * @platform web\n */\n className?: string;\n /**\n * The width of the preview in pixels. Defaults to the screen width.\n * @platform android, ios, web\n */\n width?: number;\n /**\n * The height of the preview in pixels. Defaults to the screen height.\n * @platform android, ios, web\n */\n height?: number;\n /**\n * The horizontal origin of the preview, in pixels.\n * @platform android, ios\n */\n x?: number;\n /**\n * The vertical origin of the preview, in pixels.\n * @platform android, ios\n */\n y?: number;\n /**\n * The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'.\n * Cannot be set if width or height is provided, otherwise the call will be rejected.\n * Use setPreviewSize to adjust size after starting.\n *\n * @since 2.0.0\n */\n aspectRatio?: \"4:3\" | \"16:9\";\n /**\n * The grid overlay to display on the camera preview.\n * @default \"none\"\n * @since 2.1.0\n */\n gridMode?: GridMode;\n /**\n * Adjusts the y-position to account for safe areas (e.g., notches).\n * @platform ios\n * @default false\n */\n includeSafeAreaInsets?: boolean;\n /**\n * If true, places the preview behind the webview.\n * @platform android\n * @default true\n */\n toBack?: boolean;\n /**\n * Bottom padding for the preview, in pixels.\n * @platform android, ios\n */\n paddingBottom?: number;\n /**\n * Whether to rotate the preview when the device orientation changes.\n * @platform ios\n * @default true\n */\n rotateWhenOrientationChanged?: boolean;\n /**\n * The camera to use.\n * @default \"rear\"\n */\n position?: CameraPosition | string;\n /**\n * If true, saves the captured image to a file and returns the file path.\n * If false, returns a base64 encoded string.\n * @default false\n */\n storeToFile?: boolean;\n /**\n * If true, prevents the plugin from rotating the image based on EXIF data.\n * @platform android\n * @default false\n */\n disableExifHeaderStripping?: boolean;\n /**\n * If true, disables the audio stream, preventing audio permission requests.\n * @default true\n */\n disableAudio?: boolean;\n /**\n * If true, locks the device orientation while the camera is active.\n * @platform android\n * @default false\n */\n lockAndroidOrientation?: boolean;\n /**\n * If true, allows the camera preview's opacity to be changed.\n * @platform android, web\n * @default false\n */\n enableOpacity?: boolean;\n /**\n * If true, enables pinch-to-zoom functionality on the preview.\n * @platform android\n * @default false\n */\n enableZoom?: boolean;\n /**\n * If true, uses the video-optimized preset for the camera session.\n * @platform ios\n * @default false\n */\n enableVideoMode?: boolean;\n /**\n * The `deviceId` of the camera to use. If provided, `position` is ignored.\n * @platform ios\n */\n deviceId?: string;\n /**\n * The initial zoom level when starting the camera preview.\n * If the requested zoom level is not available, the native plugin will reject.\n * @default 1.0\n * @platform android, ios\n * @since 2.2.0\n */\n initialZoomLevel?: number;\n /**\n * The vertical positioning of the camera preview.\n * @default \"center\"\n * @platform android, ios, web\n * @since 2.3.0\n */\n positioning?: CameraPositioning;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /** @deprecated,\n * The desired height of the picture in pixels.\n * If not specified and no aspectRatio is provided, the captured image will match the preview's visible area.\n */\n height?: number;\n /** @deprecated,\n * The desired width of the picture in pixels.\n * If not specified and no aspectRatio is provided, the captured image will match the preview's visible area.\n */\n width?: number;\n /** @deprecated,\n * The desired aspect ratio of the captured image (e.g., '4:3', '16:9').\n * If not specified and no width/height is provided, the aspect ratio from the camera start will be used.\n * If no aspect ratio was set at start, defaults to '4:3'.\n * Cannot be used together with width or height - the capture will be rejected with an error.\n * @since 7.7.0\n */\n aspectRatio?: string;\n /**\n * The quality of the captured image, from 0 to 100.\n * Does not apply to `png` format.\n * @default 85\n */\n quality?: number;\n /**\n * The format of the captured image.\n * @default \"jpeg\"\n */\n format?: PictureFormat;\n /**\n * If true, the captured image will be saved to the user's gallery.\n * @default false\n * @since 7.5.0\n */\n saveToGallery?: boolean;\n /**\n * If true, the plugin will attempt to add GPS location data to the image's EXIF metadata.\n * This may prompt the user for location permissions.\n * @default false\n * @since 7.6.0\n */\n withExifLocation?: boolean;\n}\n\n/** Represents EXIF data extracted from an image. */\nexport interface ExifData {\n [key: string]: any;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\n/** Defines a standard picture size with width and height. */\nexport interface PictureSize {\n /** The width of the picture in pixels. */\n width: number;\n /** The height of the picture in pixels. */\n height: number;\n}\n\n/** Represents the supported picture sizes for a camera facing a certain direction. */\nexport interface SupportedPictureSizes {\n /** The camera direction (\"front\" or \"rear\"). */\n facing: string;\n /** A list of supported picture sizes for this camera. */\n supportedPictureSizes: PictureSize[];\n}\n\n/**\n * Defines the options for capturing a sample frame from the camera preview.\n */\nexport interface CameraSampleOptions {\n /**\n * The quality of the captured sample, from 0 to 100.\n * @default 85\n */\n quality?: number;\n}\n\n/**\n * The available flash modes for the camera.\n * 'torch' is a continuous light mode.\n */\nexport type CameraPreviewFlashMode = \"off\" | \"on\" | \"auto\" | \"torch\";\n\n/**\n * Defines the options for setting the camera preview's opacity.\n */\nexport interface CameraOpacityOptions {\n /**\n * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).\n * @default 1.0\n */\n opacity?: number;\n}\n\n/**\n * Represents safe area insets for devices.\n * Android: Values are expressed in logical pixels (dp) to match JS layout units.\n * iOS: Values are expressed in physical pixels and exclude status bar.\n */\nexport interface SafeAreaInsets {\n /** Current device orientation (1 = portrait, 2 = landscape, 0 = unknown). */\n orientation: number;\n /**\n * Orientation-aware notch/camera cutout inset (excluding status bar).\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch at side).\n * Android: Value in dp, iOS: Value in pixels (status bar excluded).\n */\n top: number;\n}\n\n/**\n * Canonical device orientation values across platforms.\n */\nexport type DeviceOrientation =\n | \"portrait\"\n | \"landscape\"\n | \"landscape-left\"\n | \"landscape-right\"\n | \"portrait-upside-down\"\n | \"unknown\";\n\n/**\n * The main interface for the CameraPreview plugin.\n */\nexport interface CameraPreviewPlugin {\n /**\n * Starts the camera preview.\n *\n * @param {CameraPreviewOptions} options - The configuration for the camera preview.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the preview dimensions.\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<{\n /** The width of the preview in pixels. */\n width: number;\n /** The height of the preview in pixels. */\n height: number;\n /** The horizontal origin of the preview, in pixels. */\n x: number;\n /** The vertical origin of the preview, in pixels. */\n y: number;\n }>;\n\n /**\n * Stops the camera preview.\n *\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(): Promise<void>;\n\n /**\n * Captures a picture from the camera.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string }>} A promise that resolves with the captured image data.\n * The `value` is a base64 encoded string unless `storeToFile` is true, in which case it's a file path.\n * @since 0.0.1\n */\n capture(\n options: CameraPreviewPictureOptions,\n ): Promise<{ value: string; exif: ExifData }>;\n\n /**\n * Captures a single frame from the camera preview stream.\n *\n * @param {CameraSampleOptions} options - The options for capturing the sample.\n * @returns {Promise<{ value: string }>} A promise that resolves with the sample image as a base64 encoded string.\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n\n /**\n * Gets the flash modes supported by the active camera.\n *\n * @returns {Promise<{ result: CameraPreviewFlashMode[] }>} A promise that resolves with an array of supported flash modes.\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n\n /**\n * Set the aspect ratio of the camera preview.\n *\n * @param {{ aspectRatio: '4:3' | '16:9'; x?: number; y?: number }} options - The desired aspect ratio and optional position.\n * - aspectRatio: The desired aspect ratio ('4:3' or '16:9')\n * - x: Optional x coordinate for positioning. If not provided, view will be auto-centered horizontally.\n * - y: Optional y coordinate for positioning. If not provided, view will be auto-centered vertically.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.5.0\n * @platform android, ios\n */\n setAspectRatio(options: {\n aspectRatio: \"4:3\" | \"16:9\";\n x?: number;\n y?: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Gets the current aspect ratio of the camera preview.\n *\n * @returns {Promise<{ aspectRatio: '4:3' | '16:9' }>} A promise that resolves with the current aspect ratio.\n * @since 7.5.0\n * @platform android, ios\n */\n getAspectRatio(): Promise<{ aspectRatio: \"4:3\" | \"16:9\" }>;\n\n /**\n * Sets the grid mode of the camera preview overlay.\n *\n * @param {{ gridMode: GridMode }} options - The desired grid mode ('none', '3x3', or '4x4').\n * @returns {Promise<void>} A promise that resolves when the grid mode is set.\n * @since 8.0.0\n */\n setGridMode(options: { gridMode: GridMode }): Promise<void>;\n\n /**\n * Gets the current grid mode of the camera preview overlay.\n *\n * @returns {Promise<{ gridMode: GridMode }>} A promise that resolves with the current grid mode.\n * @since 8.0.0\n */\n getGridMode(): Promise<{ gridMode: GridMode }>;\n\n /**\n * Gets the horizontal field of view (FoV) for the active camera.\n * Note: This can be an estimate on some devices.\n *\n * @returns {Promise<{ result: number }>} A promise that resolves with the horizontal field of view in degrees.\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: number;\n }>;\n\n /**\n * Gets the supported picture sizes for all cameras.\n *\n * @returns {Promise<{ supportedPictureSizes: SupportedPictureSizes[] }>} A promise that resolves with the list of supported sizes.\n * @since 7.4.0\n */\n getSupportedPictureSizes(): Promise<{\n supportedPictureSizes: SupportedPictureSizes[];\n }>;\n\n /**\n * Sets the flash mode for the active camera.\n *\n * @param {{ flashMode: CameraPreviewFlashMode | string }} options - The desired flash mode.\n * @returns {Promise<void>} A promise that resolves when the flash mode is set.\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n\n /**\n * Toggles between the front and rear cameras.\n *\n * @returns {Promise<void>} A promise that resolves when the camera is flipped.\n * @since 0.0.1\n */\n flip(): Promise<void>;\n\n /**\n * Sets the opacity of the camera preview.\n *\n * @param {CameraOpacityOptions} options - The opacity options.\n * @returns {Promise<void>} A promise that resolves when the opacity is set.\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n\n /**\n * Stops an ongoing video recording.\n *\n * @returns {Promise<{ videoFilePath: string }>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{ videoFilePath: string }>;\n\n /**\n * Starts recording a video.\n *\n * @param {CameraPreviewOptions} options - The options for video recording.\n * @returns {Promise<void>} A promise that resolves when video recording starts.\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n\n /**\n * Checks if the camera preview is currently running.\n *\n * @returns {Promise<{ isRunning: boolean }>} A promise that resolves with the running state.\n * @since 7.5.0\n * @platform android, ios\n */\n isRunning(): Promise<{ isRunning: boolean }>;\n\n /**\n * Gets all available camera devices.\n *\n * @returns {Promise<{ devices: CameraDevice[] }>} A promise that resolves with the list of available camera devices.\n * @since 7.5.0\n * @platform android, ios\n */\n getAvailableDevices(): Promise<{ devices: CameraDevice[] }>;\n\n /**\n * Gets the current zoom state, including min/max and current lens info.\n *\n * @returns {Promise<{ min: number; max: number; current: number; lens: LensInfo }>} A promise that resolves with the zoom state.\n * @since 7.5.0\n * @platform android, ios\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Returns zoom button values for quick switching.\n * - iOS/Android: includes 0.5 if ultra-wide available; 1 and 2 if wide available; 3 if telephoto available\n * - Web: unsupported\n * @since 7.5.0\n * @platform android, ios\n */\n getZoomButtonValues(): Promise<{ values: number[] }>;\n\n /**\n * Sets the zoom level of the camera.\n *\n * @param {{ level: number; ramp?: boolean; autoFocus?: boolean }} options - The desired zoom level. `ramp` is currently unused. `autoFocus` defaults to true.\n * @returns {Promise<void>} A promise that resolves when the zoom level is set.\n * @since 7.5.0\n * @platform android, ios\n */\n setZoom(options: {\n level: number;\n ramp?: boolean;\n autoFocus?: boolean;\n }): Promise<void>;\n\n /**\n * Gets the current flash mode.\n *\n * @returns {Promise<{ flashMode: FlashMode }>} A promise that resolves with the current flash mode.\n * @since 7.5.0\n * @platform android, ios\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.5.0\n * @platform android, ios\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Switches the active camera to the one with the specified `deviceId`.\n *\n * @param {{ deviceId: string }} options - The ID of the device to switch to.\n * @returns {Promise<void>} A promise that resolves when the camera is switched.\n * @since 7.5.0\n * @platform android, ios\n */\n setDeviceId(options: { deviceId: string }): Promise<void>;\n\n /**\n * Gets the ID of the currently active camera device.\n *\n * @returns {Promise<{ deviceId: string }>} A promise that resolves with the current device ID.\n * @since 7.5.0\n * @platform android, ios\n */\n getDeviceId(): Promise<{ deviceId: string }>;\n\n /**\n * Gets the current preview size and position.\n * @returns {Promise<{x: number, y: number, width: number, height: number}>}\n * @since 7.5.0\n * @platform android, ios\n */\n getPreviewSize(): Promise<{\n x: number;\n y: number;\n width: number;\n height: number;\n }>;\n /**\n * Sets the preview size and position.\n * @param options The new position and dimensions.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.5.0\n * @platform android, ios\n */\n setPreviewSize(options: {\n x?: number;\n y?: number;\n width: number;\n height: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Sets the camera focus to a specific point in the preview.\n *\n * @param {Object} options - The focus options.\n * @param {number} options.x - The x coordinate in the preview view to focus on (0-1 normalized).\n * @param {number} options.y - The y coordinate in the preview view to focus on (0-1 normalized).\n * @returns {Promise<void>} A promise that resolves when the focus is set.\n * @since 7.5.0\n * @platform android, ios\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n\n /**\n * Adds a listener for screen resize events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"screenResize\",\n listenerFunc: (data: {\n width: number;\n height: number;\n x: number;\n y: number;\n }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for orientation change events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"orientationChange\",\n listenerFunc: (data: { orientation: DeviceOrientation }) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Deletes a file at the given absolute path on the device.\n * Use this to quickly clean up temporary images created with `storeToFile`.\n * On web, this is not supported and will throw.\n * @since 7.5.0\n * @platform android, ios\n */\n deleteFile(options: { path: string }): Promise<{ success: boolean }>;\n\n /**\n * Gets the safe area insets for devices.\n * Returns the orientation-aware notch/camera cutout inset and the current orientation.\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch moved to side).\n * This specifically targets the cutout area (notch, punch hole, etc.) that all modern phones have.\n *\n * Android: Values returned in dp (logical pixels).\n * iOS: Values returned in physical pixels, excluding status bar (only pure notch/cutout size).\n *\n * @platform android, ios\n */\n getSafeAreaInsets(): Promise<SafeAreaInsets>;\n\n /**\n * Gets the current device orientation in a cross-platform format.\n * @since 7.5.0\n * @platform android, ios\n */\n getOrientation(): Promise<{ orientation: DeviceOrientation }>;\n}\n"]}
|
|
@@ -68,7 +68,9 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
68
68
|
CAPPluginMethod(name: "setPreviewSize", returnType: CAPPluginReturnPromise),
|
|
69
69
|
CAPPluginMethod(name: "setFocus", returnType: CAPPluginReturnPromise),
|
|
70
70
|
CAPPluginMethod(name: "deleteFile", returnType: CAPPluginReturnPromise),
|
|
71
|
-
CAPPluginMethod(name: "getOrientation", returnType: CAPPluginReturnPromise)
|
|
71
|
+
CAPPluginMethod(name: "getOrientation", returnType: CAPPluginReturnPromise),
|
|
72
|
+
CAPPluginMethod(name: "getSafeAreaInsets", returnType: CAPPluginReturnPromise)
|
|
73
|
+
|
|
72
74
|
]
|
|
73
75
|
// Camera state tracking
|
|
74
76
|
private var isInitializing: Bool = false
|
|
@@ -96,6 +98,44 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
96
98
|
private var permissionCallID: String?
|
|
97
99
|
private var waitingForLocation: Bool = false
|
|
98
100
|
|
|
101
|
+
// MARK: - Helper Methods for Aspect Ratio
|
|
102
|
+
|
|
103
|
+
/// Validates that aspectRatio and size (width/height) are not both set
|
|
104
|
+
private func validateAspectRatioParameters(aspectRatio: String?, width: Int?, height: Int?) -> String? {
|
|
105
|
+
if aspectRatio != nil && (width != nil || height != nil) {
|
|
106
|
+
return "Cannot set both aspectRatio and size (width/height). Use setPreviewSize after start."
|
|
107
|
+
}
|
|
108
|
+
return nil
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// Parses aspect ratio string and returns the appropriate ratio for the current orientation
|
|
112
|
+
private func parseAspectRatio(_ ratio: String, isPortrait: Bool) -> CGFloat {
|
|
113
|
+
let parts = ratio.split(separator: ":").compactMap { Double($0) }
|
|
114
|
+
guard parts.count == 2 else { return 1.0 }
|
|
115
|
+
|
|
116
|
+
// For camera (portrait), we want portrait orientation: 4:3 becomes 3:4, 16:9 becomes 9:16
|
|
117
|
+
return isPortrait ?
|
|
118
|
+
CGFloat(parts[1] / parts[0]) :
|
|
119
|
+
CGFloat(parts[0] / parts[1])
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/// Calculates dimensions based on aspect ratio and available space
|
|
123
|
+
private func calculateDimensionsForAspectRatio(_ aspectRatio: String, availableWidth: CGFloat, availableHeight: CGFloat, isPortrait: Bool) -> (width: CGFloat, height: CGFloat) {
|
|
124
|
+
let ratio = parseAspectRatio(aspectRatio, isPortrait: isPortrait)
|
|
125
|
+
|
|
126
|
+
// Calculate maximum size that fits the aspect ratio in available space
|
|
127
|
+
let maxWidthByHeight = availableHeight * ratio
|
|
128
|
+
let maxHeightByWidth = availableWidth / ratio
|
|
129
|
+
|
|
130
|
+
if maxWidthByHeight <= availableWidth {
|
|
131
|
+
// Height is the limiting factor
|
|
132
|
+
return (width: maxWidthByHeight, height: availableHeight)
|
|
133
|
+
} else {
|
|
134
|
+
// Width is the limiting factor
|
|
135
|
+
return (width: availableWidth, height: maxHeightByWidth)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
99
139
|
// MARK: - Transparency Methods
|
|
100
140
|
|
|
101
141
|
private func makeWebViewTransparent() {
|
|
@@ -302,23 +342,11 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
302
342
|
}
|
|
303
343
|
|
|
304
344
|
// Parse aspect ratio - convert to portrait orientation for camera use
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
// Calculate maximum size that fits the aspect ratio in available space
|
|
311
|
-
let maxWidthByHeight = availableHeight * CGFloat(ratio)
|
|
312
|
-
let maxHeightByWidth = availableWidth / CGFloat(ratio)
|
|
313
|
-
|
|
314
|
-
if maxWidthByHeight <= availableWidth {
|
|
315
|
-
// Height is the limiting factor
|
|
316
|
-
self.width = maxWidthByHeight
|
|
317
|
-
self.height = availableHeight
|
|
318
|
-
} else {
|
|
319
|
-
// Width is the limiting factor
|
|
320
|
-
self.width = availableWidth
|
|
321
|
-
self.height = maxHeightByWidth
|
|
345
|
+
// Use the centralized calculation method
|
|
346
|
+
if let aspectRatio = self.aspectRatio {
|
|
347
|
+
let dimensions = calculateDimensionsForAspectRatio(aspectRatio, availableWidth: availableWidth, availableHeight: availableHeight, isPortrait: isPortrait)
|
|
348
|
+
self.width = dimensions.width
|
|
349
|
+
self.height = dimensions.height
|
|
322
350
|
}
|
|
323
351
|
|
|
324
352
|
self.updateCameraFrame()
|
|
@@ -474,6 +502,26 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
474
502
|
let startTime = CFAbsoluteTimeGetCurrent()
|
|
475
503
|
print("[CameraPreview] 🚀 START CALLED at \(Date())")
|
|
476
504
|
|
|
505
|
+
// Log all received settings
|
|
506
|
+
print("[CameraPreview] 📋 Settings received:")
|
|
507
|
+
print(" - position: \(call.getString("position") ?? "rear")")
|
|
508
|
+
print(" - deviceId: \(call.getString("deviceId") ?? "nil")")
|
|
509
|
+
print(" - cameraMode: \(call.getBool("cameraMode") ?? false)")
|
|
510
|
+
print(" - width: \(call.getInt("width") ?? 0)")
|
|
511
|
+
print(" - height: \(call.getInt("height") ?? 0)")
|
|
512
|
+
print(" - x: \(call.getInt("x") ?? -1)")
|
|
513
|
+
print(" - y: \(call.getInt("y") ?? -1)")
|
|
514
|
+
print(" - paddingBottom: \(call.getInt("paddingBottom") ?? 0)")
|
|
515
|
+
print(" - rotateWhenOrientationChanged: \(call.getBool("rotateWhenOrientationChanged") ?? true)")
|
|
516
|
+
print(" - toBack: \(call.getBool("toBack") ?? true)")
|
|
517
|
+
print(" - storeToFile: \(call.getBool("storeToFile") ?? false)")
|
|
518
|
+
print(" - enableZoom: \(call.getBool("enableZoom") ?? false)")
|
|
519
|
+
print(" - disableAudio: \(call.getBool("disableAudio") ?? true)")
|
|
520
|
+
print(" - aspectRatio: \(call.getString("aspectRatio") ?? "4:3")")
|
|
521
|
+
print(" - gridMode: \(call.getString("gridMode") ?? "none")")
|
|
522
|
+
print(" - positioning: \(call.getString("positioning") ?? "top")")
|
|
523
|
+
print(" - initialZoomLevel: \(call.getFloat("initialZoomLevel") ?? 1.0)")
|
|
524
|
+
|
|
477
525
|
if self.isInitializing {
|
|
478
526
|
call.reject("camera initialization in progress")
|
|
479
527
|
return
|
|
@@ -531,8 +579,9 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
531
579
|
|
|
532
580
|
let initialZoomLevel = call.getFloat("initialZoomLevel")
|
|
533
581
|
|
|
534
|
-
|
|
535
|
-
|
|
582
|
+
// Validate aspect ratio parameters using centralized method
|
|
583
|
+
if let validationError = validateAspectRatioParameters(aspectRatio: self.aspectRatio, width: call.getInt("width"), height: call.getInt("height")) {
|
|
584
|
+
call.reject(validationError)
|
|
536
585
|
return
|
|
537
586
|
}
|
|
538
587
|
|
|
@@ -788,10 +837,10 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
788
837
|
|
|
789
838
|
print("[CameraPreview] Raw parameter values - width: \(String(describing: width)), height: \(String(describing: height)), aspectRatio: \(String(describing: aspectRatio))")
|
|
790
839
|
|
|
791
|
-
// Check for conflicting parameters
|
|
792
|
-
if
|
|
793
|
-
print("[CameraPreview] Error:
|
|
794
|
-
call.reject(
|
|
840
|
+
// Check for conflicting parameters using centralized validation
|
|
841
|
+
if let validationError = validateAspectRatioParameters(aspectRatio: aspectRatio, width: width, height: height) {
|
|
842
|
+
print("[CameraPreview] Error: \(validationError)")
|
|
843
|
+
call.reject(validationError)
|
|
795
844
|
return
|
|
796
845
|
}
|
|
797
846
|
|
|
@@ -851,7 +900,6 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
851
900
|
self.saveImageDataToGallery(imageData: imageDataWithExif) { success, error in
|
|
852
901
|
print("[CameraPreview] Save to gallery completed, success: \(success), error: \(error?.localizedDescription ?? "none")")
|
|
853
902
|
let exifData = self.getExifData(from: imageDataWithExif)
|
|
854
|
-
let base64Image = imageDataWithExif.base64EncodedString()
|
|
855
903
|
|
|
856
904
|
var result = JSObject()
|
|
857
905
|
result["exif"] = exifData
|
|
@@ -936,6 +984,62 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
936
984
|
return exifData
|
|
937
985
|
}
|
|
938
986
|
|
|
987
|
+
@objc func getSafeAreaInsets(_ call: CAPPluginCall) {
|
|
988
|
+
DispatchQueue.main.async {
|
|
989
|
+
var notchInset: CGFloat = 0
|
|
990
|
+
var orientation: Int = 0
|
|
991
|
+
|
|
992
|
+
// Get the current interface orientation
|
|
993
|
+
let interfaceOrientation: UIInterfaceOrientation? = {
|
|
994
|
+
return (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.interfaceOrientation
|
|
995
|
+
}()
|
|
996
|
+
|
|
997
|
+
// Convert to orientation number (matching Android values for consistency)
|
|
998
|
+
switch interfaceOrientation {
|
|
999
|
+
case .portrait, .portraitUpsideDown:
|
|
1000
|
+
orientation = 1 // Portrait
|
|
1001
|
+
case .landscapeLeft, .landscapeRight:
|
|
1002
|
+
orientation = 2 // Landscape
|
|
1003
|
+
default:
|
|
1004
|
+
orientation = 0 // Unknown
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// Get safe area insets
|
|
1008
|
+
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
1009
|
+
let window = windowScene.windows.first {
|
|
1010
|
+
let safeAreaInsets = window.safeAreaInsets
|
|
1011
|
+
|
|
1012
|
+
switch interfaceOrientation {
|
|
1013
|
+
case .portrait:
|
|
1014
|
+
// Portrait: notch is at the top
|
|
1015
|
+
notchInset = safeAreaInsets.top
|
|
1016
|
+
case .portraitUpsideDown:
|
|
1017
|
+
// Portrait upside down: notch is at the bottom (but we still call it "top" for consistency)
|
|
1018
|
+
notchInset = safeAreaInsets.bottom
|
|
1019
|
+
case .landscapeLeft:
|
|
1020
|
+
// Landscape left: notch is typically on the left
|
|
1021
|
+
notchInset = safeAreaInsets.left
|
|
1022
|
+
case .landscapeRight:
|
|
1023
|
+
// Landscape right: notch is typically on the right (but we use left for consistency with Android)
|
|
1024
|
+
notchInset = safeAreaInsets.right
|
|
1025
|
+
default:
|
|
1026
|
+
// Unknown orientation, default to top
|
|
1027
|
+
notchInset = safeAreaInsets.top
|
|
1028
|
+
}
|
|
1029
|
+
} else {
|
|
1030
|
+
// Fallback: use status bar height as approximation
|
|
1031
|
+
notchInset = UIApplication.shared.statusBarFrame.height
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
let result: [String: Any] = [
|
|
1035
|
+
"orientation": orientation,
|
|
1036
|
+
"top": Double(notchInset)
|
|
1037
|
+
]
|
|
1038
|
+
|
|
1039
|
+
call.resolve(result)
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
939
1043
|
private func createImageDataWithExif(from image: UIImage, quality: Int, location: CLLocation?, originalPhotoData: Data?) -> Data? {
|
|
940
1044
|
guard let jpegDataAtQuality = image.jpegData(compressionQuality: CGFloat(Double(quality) / 100.0)) else {
|
|
941
1045
|
return nil
|
|
@@ -1533,16 +1637,16 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
1533
1637
|
|
|
1534
1638
|
print("[CameraPreview] width: \(UIScreen.main.bounds.size.width) height: \(UIScreen.main.bounds.size.height)")
|
|
1535
1639
|
|
|
1536
|
-
// Calculate
|
|
1537
|
-
let
|
|
1538
|
-
if
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1640
|
+
// Calculate dimensions using centralized method
|
|
1641
|
+
let dimensions = calculateDimensionsForAspectRatio(ratio, availableWidth: finalWidth, availableHeight: webViewHeight - paddingBottom, isPortrait: isPortrait)
|
|
1642
|
+
if isPortrait {
|
|
1643
|
+
finalHeight = dimensions.height
|
|
1644
|
+
finalWidth = dimensions.width
|
|
1645
|
+
} else {
|
|
1646
|
+
// In landscape, recalculate based on available space
|
|
1647
|
+
let landscapeDimensions = calculateDimensionsForAspectRatio(ratio, availableWidth: webViewWidth, availableHeight: webViewHeight - paddingBottom, isPortrait: isPortrait)
|
|
1648
|
+
finalWidth = landscapeDimensions.width
|
|
1649
|
+
finalHeight = landscapeDimensions.height
|
|
1546
1650
|
}
|
|
1547
1651
|
}
|
|
1548
1652
|
|
|
@@ -1602,21 +1706,18 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
1602
1706
|
|
|
1603
1707
|
// Apply aspect ratio adjustments only if not auto-centering
|
|
1604
1708
|
if posX != -1 && posY != -1, let aspectRatio = self.aspectRatio {
|
|
1605
|
-
let
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
frame.origin.y = frame.origin.y + (frame.height - CGFloat(newHeight)) / 2
|
|
1618
|
-
frame.size.height = CGFloat(newHeight)
|
|
1619
|
-
}
|
|
1709
|
+
let isPortrait = self.isPortrait()
|
|
1710
|
+
let ratio = parseAspectRatio(aspectRatio, isPortrait: isPortrait)
|
|
1711
|
+
let currentRatio = frame.width / frame.height
|
|
1712
|
+
|
|
1713
|
+
if currentRatio > ratio {
|
|
1714
|
+
let newWidth = frame.height * ratio
|
|
1715
|
+
frame.origin.x = frame.origin.x + (frame.width - newWidth) / 2
|
|
1716
|
+
frame.size.width = newWidth
|
|
1717
|
+
} else {
|
|
1718
|
+
let newHeight = frame.width / ratio
|
|
1719
|
+
frame.origin.y = frame.origin.y + (frame.height - newHeight) / 2
|
|
1720
|
+
frame.size.height = newHeight
|
|
1620
1721
|
}
|
|
1621
1722
|
}
|
|
1622
1723
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/camera-preview",
|
|
3
|
-
"version": "7.4.0-alpha.
|
|
3
|
+
"version": "7.4.0-alpha.32",
|
|
4
4
|
"description": "Camera preview",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,15 @@
|
|
|
16
16
|
"plugin",
|
|
17
17
|
"camera",
|
|
18
18
|
"preview",
|
|
19
|
-
"native"
|
|
19
|
+
"native",
|
|
20
|
+
"zoom",
|
|
21
|
+
"focus",
|
|
22
|
+
"flash",
|
|
23
|
+
"lense",
|
|
24
|
+
"video",
|
|
25
|
+
"photo",
|
|
26
|
+
"image",
|
|
27
|
+
"capture"
|
|
20
28
|
],
|
|
21
29
|
"main": "dist/esm/index.js",
|
|
22
30
|
"types": "dist/esm/index.d.ts",
|