@capgo/camera-preview 8.0.1 → 8.0.3

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.
@@ -34,7 +34,7 @@ extension UIWindow {
34
34
  */
35
35
  @objc(CameraPreview)
36
36
  public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelegate {
37
- private let pluginVersion: String = "8.0.1"
37
+ private let pluginVersion: String = "8.0.3"
38
38
  public let identifier = "CameraPreviewPlugin"
39
39
  public let jsName = "CameraPreview"
40
40
  public let pluginMethods: [CAPPluginMethod] = [
@@ -470,8 +470,8 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
470
470
  availableHeight = webViewHeight - paddingBottom
471
471
  } else {
472
472
  // Manual positioning - calculate remaining space
473
- availableWidth = webViewWidth - self.posX!
474
- availableHeight = webViewHeight - self.posY! - paddingBottom
473
+ availableWidth = webViewWidth - (self.posX ?? 0)
474
+ availableHeight = webViewHeight - (self.posY ?? 0) - paddingBottom
475
475
  }
476
476
 
477
477
  // Parse aspect ratio - convert to portrait orientation for camera use
@@ -722,20 +722,20 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
722
722
  }
723
723
 
724
724
  // Set x position - use exact CSS pixel value from web view, or mark for centering
725
- if let x = call.getInt("x") {
726
- self.posX = CGFloat(x)
725
+ if let xPosition = call.getInt("x") {
726
+ self.posX = CGFloat(xPosition)
727
727
  } else {
728
728
  self.posX = -1 // Use -1 to indicate auto-centering
729
729
  }
730
730
 
731
731
  // Set y position - use exact CSS pixel value from web view, or mark for centering
732
- if let y = call.getInt("y") {
733
- self.posY = CGFloat(y)
732
+ if let yPosition = call.getInt("y") {
733
+ self.posY = CGFloat(yPosition)
734
734
  } else {
735
735
  self.posY = -1 // Use -1 to indicate auto-centering
736
736
  }
737
- if call.getInt("paddingBottom") != nil {
738
- self.paddingBottom = CGFloat(call.getInt("paddingBottom")!)
737
+ if let paddingBottomValue = call.getInt("paddingBottom") {
738
+ self.paddingBottom = CGFloat(paddingBottomValue)
739
739
  }
740
740
 
741
741
  self.rotateWhenOrientationChanged = call.getBool("rotateWhenOrientationChanged") ?? true
@@ -823,7 +823,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
823
823
 
824
824
  // Add preview view to hierarchy first
825
825
  self.webView?.addSubview(self.previewView)
826
- if self.toBack! {
826
+ if self.toBack == true {
827
827
  self.webView?.sendSubviewToBack(self.previewView)
828
828
  }
829
829
 
@@ -1177,13 +1177,13 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1177
1177
  if Thread.isMainThread {
1178
1178
  return (self.previewView.frame.width, self.previewView.frame.height)
1179
1179
  }
1180
- var w: CGFloat = 0
1181
- var h: CGFloat = 0
1180
+ var width: CGFloat = 0
1181
+ var height: CGFloat = 0
1182
1182
  DispatchQueue.main.sync {
1183
- w = self.previewView.frame.width
1184
- h = self.previewView.frame.height
1183
+ width = self.previewView.frame.width
1184
+ height = self.previewView.frame.height
1185
1185
  }
1186
- return (w, h)
1186
+ return (width, height)
1187
1187
  }()
1188
1188
  print("[CameraPreview] Preview dimensions: \(previewWidth)x\(previewHeight)")
1189
1189
 
@@ -1398,7 +1398,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1398
1398
  }
1399
1399
 
1400
1400
  @objc func captureSample(_ call: CAPPluginCall) {
1401
- let quality: Int? = call.getInt("quality", 85)
1401
+ let quality: Int = call.getInt("quality") ?? 85
1402
1402
 
1403
1403
  self.cameraController.captureSample { image, error in
1404
1404
  guard let image = image else {
@@ -1410,14 +1410,17 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1410
1410
  let imageData: Data?
1411
1411
  if self.cameraPosition == "front" {
1412
1412
  let flippedImage = image.withHorizontallyFlippedOrientation()
1413
- imageData = flippedImage.jpegData(compressionQuality: CGFloat(quality!/100))
1413
+ imageData = flippedImage.jpegData(compressionQuality: CGFloat(quality)/100)
1414
1414
  } else {
1415
- imageData = image.jpegData(compressionQuality: CGFloat(quality!/100))
1415
+ imageData = image.jpegData(compressionQuality: CGFloat(quality)/100)
1416
1416
  }
1417
1417
 
1418
1418
  if self.storeToFile == false {
1419
- let imageBase64 = imageData?.base64EncodedString()
1420
- call.resolve(["value": imageBase64!])
1419
+ guard let imageBase64 = imageData?.base64EncodedString() else {
1420
+ call.reject("Failed to encode image to base64")
1421
+ return
1422
+ }
1423
+ call.resolve(["value": imageBase64])
1421
1424
  } else {
1422
1425
  do {
1423
1426
  let fileUrl = self.getTempFilePath()
@@ -1464,8 +1467,8 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1464
1467
  flashModeAsEnum = AVCaptureDevice.FlashMode.auto
1465
1468
  default: break
1466
1469
  }
1467
- if flashModeAsEnum != nil {
1468
- try self.cameraController.setFlashMode(flashMode: flashModeAsEnum!)
1470
+ if let flashModeEnum = flashModeAsEnum {
1471
+ try self.cameraController.setFlashMode(flashMode: flashModeEnum)
1469
1472
  } else if flashMode == "torch" {
1470
1473
  try self.cameraController.setTorchMode()
1471
1474
  } else {
@@ -1633,7 +1636,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1633
1636
  // First, convert from UI/display zoom to native zoom using the iOS 18 multiplier
1634
1637
  let displayMultiplier = self.cameraController.getDisplayZoomMultiplier()
1635
1638
  if displayMultiplier != 1.0 {
1636
- level = level / displayMultiplier
1639
+ level /= displayMultiplier
1637
1640
  }
1638
1641
 
1639
1642
  let ramp = call.getBool("ramp") ?? true
@@ -1905,12 +1908,12 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1905
1908
  }
1906
1909
  }
1907
1910
 
1908
- private func calculateCameraFrame(x: CGFloat? = nil, y: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil, aspectRatio: String? = nil) -> CGRect {
1911
+ private func calculateCameraFrame(xPosition: CGFloat? = nil, yPosition: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil, aspectRatio: String? = nil) -> CGRect {
1909
1912
  // Use provided values or existing ones
1910
1913
  let currentWidth = width ?? self.width ?? UIScreen.main.bounds.size.width
1911
1914
  let currentHeight = height ?? self.height ?? UIScreen.main.bounds.size.height
1912
- let currentX = x ?? self.posX ?? -1
1913
- let currentY = y ?? self.posY ?? -1
1915
+ let currentX = xPosition ?? self.posX ?? -1
1916
+ let currentY = yPosition ?? self.posY ?? -1
1914
1917
  let currentAspectRatio = aspectRatio ?? self.aspectRatio
1915
1918
 
1916
1919
  let paddingBottom = self.paddingBottom ?? 0
@@ -2014,11 +2017,11 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
2014
2017
 
2015
2018
  if currentRatio > ratio {
2016
2019
  let newWidth = frame.height * ratio
2017
- frame.origin.x = frame.origin.x + (frame.width - newWidth) / 2
2020
+ frame.origin.x += (frame.width - newWidth) / 2
2018
2021
  frame.size.width = newWidth
2019
2022
  } else {
2020
2023
  let newHeight = frame.width / ratio
2021
- frame.origin.y = frame.origin.y + (frame.height - newHeight) / 2
2024
+ frame.origin.y += (frame.height - newHeight) / 2
2022
2025
  frame.size.height = newHeight
2023
2026
  }
2024
2027
  }
@@ -2071,14 +2074,14 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
2071
2074
  }
2072
2075
 
2073
2076
  // Always set to -1 for auto-centering if not explicitly provided
2074
- if let x = call.getInt("x") {
2075
- self.posX = CGFloat(x)
2077
+ if let xValue = call.getInt("x") {
2078
+ self.posX = CGFloat(xValue)
2076
2079
  } else {
2077
2080
  self.posX = -1 // Auto-center if X not provided
2078
2081
  }
2079
2082
 
2080
- if let y = call.getInt("y") {
2081
- self.posY = CGFloat(y)
2083
+ if let yValue = call.getInt("y") {
2084
+ self.posY = CGFloat(yValue)
2082
2085
  } else {
2083
2086
  self.posY = -1 // Auto-center if Y not provided
2084
2087
  }
@@ -2107,13 +2110,13 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
2107
2110
  return
2108
2111
  }
2109
2112
 
2110
- guard let x = call.getFloat("x"), let y = call.getFloat("y") else {
2113
+ guard let xCoord = call.getFloat("x"), let yCoord = call.getFloat("y") else {
2111
2114
  call.reject("x and y parameters are required")
2112
2115
  return
2113
2116
  }
2114
2117
 
2115
2118
  // Reject if values are outside 0-1 range
2116
- if x < 0 || x > 1 || y < 0 || y > 1 {
2119
+ if xCoord < 0 || xCoord > 1 || yCoord < 0 || yCoord > 1 {
2117
2120
  call.reject("Focus coordinates must be between 0 and 1")
2118
2121
  return
2119
2122
  }
@@ -2121,8 +2124,8 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
2121
2124
  DispatchQueue.main.async {
2122
2125
  do {
2123
2126
  // Convert normalized coordinates to view coordinates
2124
- let viewX = CGFloat(x) * self.previewView.bounds.width
2125
- let viewY = CGFloat(y) * self.previewView.bounds.height
2127
+ let viewX = CGFloat(xCoord) * self.previewView.bounds.width
2128
+ let viewY = CGFloat(yCoord) * self.previewView.bounds.height
2126
2129
  let focusPoint = CGPoint(x: viewX, y: viewY)
2127
2130
 
2128
2131
  // Convert view coordinates to device coordinates
@@ -2232,13 +2235,13 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
2232
2235
  // Snap to valid range and step
2233
2236
  var range = try self.cameraController.getExposureCompensationRange()
2234
2237
  if range.step <= 0 { range.step = 0.1 }
2235
- let lo = min(range.min, range.max)
2236
- let hi = max(range.min, range.max)
2237
- // Clamp to [lo, hi]
2238
- value = max(lo, min(hi, value))
2238
+ let minValue = min(range.min, range.max)
2239
+ let maxValue = max(range.min, range.max)
2240
+ // Clamp to [minValue, maxValue]
2241
+ value = max(minValue, min(maxValue, value))
2239
2242
  // Snap to nearest step
2240
- let steps = round((value - lo) / range.step)
2241
- let snapped = lo + steps * range.step
2243
+ let steps = round((value - minValue) / range.step)
2244
+ let snapped = minValue + steps * range.step
2242
2245
 
2243
2246
  try self.cameraController.setExposureCompensation(snapped)
2244
2247
  call.resolve()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "8.0.1",
3
+ "version": "8.0.3",
4
4
  "description": "Camera preview",
5
5
  "license": "MPL-2.0",
6
6
  "repository": {