@capgo/camera-preview 7.6.1 → 7.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +143 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +194 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraXView.java +255 -1
- package/dist/docs.json +131 -0
- package/dist/esm/definitions.d.ts +47 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +21 -1
- package/dist/esm/web.js +19 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +19 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +19 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/CameraController.swift +185 -8
- package/ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift +115 -5
- package/package.json +1 -1
|
@@ -69,7 +69,14 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
69
69
|
CAPPluginMethod(name: "setFocus", returnType: CAPPluginReturnPromise),
|
|
70
70
|
CAPPluginMethod(name: "deleteFile", returnType: CAPPluginReturnPromise),
|
|
71
71
|
CAPPluginMethod(name: "getOrientation", returnType: CAPPluginReturnPromise),
|
|
72
|
-
CAPPluginMethod(name: "getSafeAreaInsets", returnType: CAPPluginReturnPromise)
|
|
72
|
+
CAPPluginMethod(name: "getSafeAreaInsets", returnType: CAPPluginReturnPromise),
|
|
73
|
+
// Exposure control methods
|
|
74
|
+
CAPPluginMethod(name: "getExposureModes", returnType: CAPPluginReturnPromise),
|
|
75
|
+
CAPPluginMethod(name: "getExposureMode", returnType: CAPPluginReturnPromise),
|
|
76
|
+
CAPPluginMethod(name: "setExposureMode", returnType: CAPPluginReturnPromise),
|
|
77
|
+
CAPPluginMethod(name: "getExposureCompensationRange", returnType: CAPPluginReturnPromise),
|
|
78
|
+
CAPPluginMethod(name: "getExposureCompensation", returnType: CAPPluginReturnPromise),
|
|
79
|
+
CAPPluginMethod(name: "setExposureCompensation", returnType: CAPPluginReturnPromise)
|
|
73
80
|
|
|
74
81
|
]
|
|
75
82
|
// Camera state tracking
|
|
@@ -101,8 +108,6 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
101
108
|
|
|
102
109
|
// MARK: - Helper Methods for Aspect Ratio
|
|
103
110
|
|
|
104
|
-
|
|
105
|
-
|
|
106
111
|
/// Parses aspect ratio string and returns the appropriate ratio for the current orientation
|
|
107
112
|
private func parseAspectRatio(_ ratio: String, isPortrait: Bool) -> CGFloat {
|
|
108
113
|
let parts = ratio.split(separator: ":").compactMap { Double($0) }
|
|
@@ -586,8 +591,6 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
586
591
|
return
|
|
587
592
|
}
|
|
588
593
|
|
|
589
|
-
|
|
590
|
-
|
|
591
594
|
AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in
|
|
592
595
|
|
|
593
596
|
guard granted else {
|
|
@@ -1800,6 +1803,113 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
1800
1803
|
}
|
|
1801
1804
|
}
|
|
1802
1805
|
|
|
1806
|
+
// MARK: - Exposure Bridge
|
|
1807
|
+
|
|
1808
|
+
@objc func getExposureModes(_ call: CAPPluginCall) {
|
|
1809
|
+
guard isInitialized else {
|
|
1810
|
+
call.reject("Camera not initialized")
|
|
1811
|
+
return
|
|
1812
|
+
}
|
|
1813
|
+
do {
|
|
1814
|
+
let modes = try self.cameraController.getExposureModes()
|
|
1815
|
+
call.resolve(["modes": modes])
|
|
1816
|
+
} catch {
|
|
1817
|
+
call.reject("Failed to get exposure modes: \(error.localizedDescription)")
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
@objc func getExposureMode(_ call: CAPPluginCall) {
|
|
1822
|
+
guard isInitialized else {
|
|
1823
|
+
call.reject("Camera not initialized")
|
|
1824
|
+
return
|
|
1825
|
+
}
|
|
1826
|
+
do {
|
|
1827
|
+
let mode = try self.cameraController.getExposureMode()
|
|
1828
|
+
call.resolve(["mode": mode])
|
|
1829
|
+
} catch {
|
|
1830
|
+
call.reject("Failed to get exposure mode: \(error.localizedDescription)")
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
@objc func setExposureMode(_ call: CAPPluginCall) {
|
|
1835
|
+
guard isInitialized else {
|
|
1836
|
+
call.reject("Camera not initialized")
|
|
1837
|
+
return
|
|
1838
|
+
}
|
|
1839
|
+
guard let mode = call.getString("mode") else {
|
|
1840
|
+
call.reject("mode parameter is required")
|
|
1841
|
+
return
|
|
1842
|
+
}
|
|
1843
|
+
// Validate against allowed exposure modes before delegating
|
|
1844
|
+
let normalized = mode.uppercased()
|
|
1845
|
+
let allowedModes: Set<String> = ["AUTO", "LOCK", "CONTINUOUS", "CUSTOM"]
|
|
1846
|
+
guard allowedModes.contains(normalized) else {
|
|
1847
|
+
let allowedList = Array(allowedModes).sorted().joined(separator: ", ")
|
|
1848
|
+
call.reject("Invalid exposure mode: \(mode). Allowed values: \(allowedList)")
|
|
1849
|
+
return
|
|
1850
|
+
}
|
|
1851
|
+
do {
|
|
1852
|
+
try self.cameraController.setExposureMode(mode: normalized)
|
|
1853
|
+
call.resolve()
|
|
1854
|
+
} catch {
|
|
1855
|
+
call.reject("Failed to set exposure mode: \(error.localizedDescription)")
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
@objc func getExposureCompensationRange(_ call: CAPPluginCall) {
|
|
1860
|
+
guard isInitialized else {
|
|
1861
|
+
call.reject("Camera not initialized")
|
|
1862
|
+
return
|
|
1863
|
+
}
|
|
1864
|
+
do {
|
|
1865
|
+
let range = try self.cameraController.getExposureCompensationRange()
|
|
1866
|
+
call.resolve(["min": range.min, "max": range.max, "step": range.step])
|
|
1867
|
+
} catch {
|
|
1868
|
+
call.reject("Failed to get exposure compensation range: \(error.localizedDescription)")
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
@objc func getExposureCompensation(_ call: CAPPluginCall) {
|
|
1873
|
+
guard isInitialized else {
|
|
1874
|
+
call.reject("Camera not initialized")
|
|
1875
|
+
return
|
|
1876
|
+
}
|
|
1877
|
+
do {
|
|
1878
|
+
let value = try self.cameraController.getExposureCompensation()
|
|
1879
|
+
call.resolve(["value": value])
|
|
1880
|
+
} catch {
|
|
1881
|
+
call.reject("Failed to get exposure compensation: \(error.localizedDescription)")
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
@objc func setExposureCompensation(_ call: CAPPluginCall) {
|
|
1886
|
+
guard isInitialized else {
|
|
1887
|
+
call.reject("Camera not initialized")
|
|
1888
|
+
return
|
|
1889
|
+
}
|
|
1890
|
+
guard var value = call.getFloat("value") else {
|
|
1891
|
+
call.reject("value parameter is required")
|
|
1892
|
+
return
|
|
1893
|
+
}
|
|
1894
|
+
do {
|
|
1895
|
+
// Snap to valid range and step
|
|
1896
|
+
var range = try self.cameraController.getExposureCompensationRange()
|
|
1897
|
+
if range.step <= 0 { range.step = 0.1 }
|
|
1898
|
+
let lo = min(range.min, range.max)
|
|
1899
|
+
let hi = max(range.min, range.max)
|
|
1900
|
+
// Clamp to [lo, hi]
|
|
1901
|
+
value = max(lo, min(hi, value))
|
|
1902
|
+
// Snap to nearest step
|
|
1903
|
+
let steps = round((value - lo) / range.step)
|
|
1904
|
+
let snapped = lo + steps * range.step
|
|
1905
|
+
|
|
1906
|
+
try self.cameraController.setExposureCompensation(snapped)
|
|
1907
|
+
call.resolve()
|
|
1908
|
+
} catch {
|
|
1909
|
+
call.reject("Failed to set exposure compensation: \(error.localizedDescription)")
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1803
1913
|
@objc private func handleOrientationChange() {
|
|
1804
1914
|
DispatchQueue.main.async {
|
|
1805
1915
|
let result = self.rawSetAspectRatio()
|