@capacitor-community/camera-preview 6.0.1 → 7.0.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.
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => 'https://github.com/capacitor-community/camera-preview.git', :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '13.0'
14
+ s.ios.deployment_target = '14.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.swift_version = '5.1'
17
17
  end
package/README.md CHANGED
@@ -2,13 +2,15 @@
2
2
  <h3 align="center">Capacitor Camera Preview</h3>
3
3
  <p align="center"><strong><code>@capacitor-community/camera-preview</code></strong></p>
4
4
  <br>
5
- <p align="center"><strong>CAPACITOR 5</strong></p><br>
5
+ <p align="center"><strong>CAPACITOR 7</strong></p><br>
6
6
 
7
7
  <p align="center">
8
8
  Capacitor plugin that allows camera interaction from Javascript and HTML<br>(based on cordova-plugin-camera-preview).
9
9
  </p>
10
10
  <br>
11
- Version 6 of this plugin requires Capacitor 6.
11
+ Version 7 of this plugin requires Capacitor 7.
12
+
13
+ If you are using Capacitor 6, use [version 6.1](https://github.com/capacitor-community/camera-preview/releases/tag/v6.0.1)
12
14
 
13
15
  If you are using Capacitor 5, use [version 5](https://github.com/capacitor-community/camera-preview/releases/tag/v5.0.0)
14
16
 
@@ -46,18 +48,23 @@ or
46
48
 
47
49
  npm install @capacitor-community/camera-preview
48
50
  ```
51
+
49
52
  Then run
53
+
50
54
  ```
51
55
  npx cap sync
52
56
  ```
53
57
 
54
58
  ## Extra Android installation steps
59
+
55
60
  **Important** `camera-preview` 3+ requires Gradle 7. If you are using Gradle 4, please use [version 2](https://github.com/capacitor-community/camera-preview/tree/v2.1.0) of this plugin.
56
61
 
57
62
  Open `android/app/src/main/AndroidManifest.xml` and above the closing `</manifest>` tag add this line to request the CAMERA permission:
63
+
58
64
  ```xml
59
65
  <uses-permission android:name="android.permission.CAMERA" />
60
66
  ```
67
+
61
68
  For more help consult the [Capacitor docs](https://capacitorjs.com/docs/android/configuration#configuring-androidmanifestxml).
62
69
 
63
70
  ### Variables
@@ -67,6 +74,7 @@ This plugin will use the following project variables (defined in your app's `var
67
74
  - `androidxExifInterfaceVersion`: version of `androidx.exifinterface:exifinterface` (default: `1.3.6`)
68
75
 
69
76
  ## Extra iOS installation steps
77
+
70
78
  You will need to add two permissions to `Info.plist`. Follow the [Capacitor docs](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist) and add permissions with the raw keys `NSCameraUsageDescription` and `NSMicrophoneUsageDescription`. `NSMicrophoneUsageDescription` is only required, if audio will be used. Otherwise set the `disableAudio` option to `true`, which also disables the microphone permission request.
71
79
 
72
80
  ## Extra Web installation steps
@@ -77,31 +85,31 @@ then in html add `<div id="cameraPreview"></div>`
77
85
 
78
86
  and `CameraPreview.start({ parent: "cameraPreview"});` will work.
79
87
 
80
-
81
88
  # Methods
82
89
 
83
90
  ### start(options)
84
91
 
85
92
  Starts the camera preview instance.
93
+
86
94
  <br>
87
95
 
88
- | Option | values | descriptions |
89
- |----------|---------------|------------------------------------------------------------------------|
90
- | position | front \| rear | Show front or rear camera when start the preview. Defaults to front |
91
- | width | number | (optional) The preview width in pixels, default window.screen.width (applicable to the android and ios platforms only) |
92
- | height | number | (optional) The preview height in pixels, default window.screen.height (applicable to the android and ios platforms only) |
93
- | x | number | (optional) The x origin, default 0 (applicable to the android and ios platforms only) |
94
- | y | number | (optional) The y origin, default 0 (applicable to the android and ios platforms only) |
95
- | toBack | boolean | (optional) Brings your html in front of your preview, default false (applicable to the android and ios platforms only) |
96
- | paddingBottom | number | (optional) The preview bottom padding in pixes. Useful to keep the appropriate preview sizes when orientation changes (applicable to the android and ios platforms only) |
97
- | rotateWhenOrientationChanged | boolean | (optional) Rotate preview when orientation changes (applicable to the ios platforms only; default value is true) |
98
- | storeToFile | boolean | (optional) Capture images to a file and return back the file path instead of returning base64 encoded data, default false. |
99
- | disableExifHeaderStripping | boolean | (optional) Disable automatic rotation of the image, and let the browser deal with it, default true (applicable to the android and ios platforms only) |
100
- | enableHighResolution | boolean | (optional) Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device |
101
- | disableAudio | boolean | (optional) Disables audio stream to prevent permission requests, default false. (applicable to web and iOS only) |
102
- | lockAndroidOrientation | boolean | (optional) Locks device orientation when camera is showing, default false. (applicable to Android only) |
103
- | enableOpacity | boolean | (optional) Make the camera preview see-through. Ideal for augmented reality uses. Default false (applicable to Android and web only)
104
- | enableZoom | boolean | (optional) Set if you can pinch to zoom. Default false (applicable to the android and ios platforms only)
96
+ | Option | values | descriptions |
97
+ | ---------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
98
+ | position | front \| rear | Show front or rear camera when start the preview. Defaults to front |
99
+ | width | number | (optional) The preview width in pixels, default window.screen.width (applicable to the android and ios platforms only) |
100
+ | height | number | (optional) The preview height in pixels, default window.screen.height (applicable to the android and ios platforms only) |
101
+ | x | number | (optional) The x origin, default 0 (applicable to the android and ios platforms only) |
102
+ | y | number | (optional) The y origin, default 0 (applicable to the android and ios platforms only) |
103
+ | toBack | boolean | (optional) Brings your html in front of your preview, default false (applicable to the android and ios platforms only) |
104
+ | paddingBottom | number | (optional) The preview bottom padding in pixes. Useful to keep the appropriate preview sizes when orientation changes (applicable to the android and ios platforms only) |
105
+ | rotateWhenOrientationChanged | boolean | (optional) Rotate preview when orientation changes (applicable to the ios platforms only; default value is true) |
106
+ | storeToFile | boolean | (optional) Capture images to a file and return back the file path instead of returning base64 encoded data, default false. |
107
+ | disableExifHeaderStripping | boolean | (optional) Disable automatic rotation of the image, and let the browser deal with it, default true (applicable to the android and ios platforms only) |
108
+ | enableHighResolution | boolean | (optional) Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device |
109
+ | disableAudio | boolean | (optional) Disables audio stream to prevent permission requests, default false. (applicable to web and iOS only) |
110
+ | lockAndroidOrientation | boolean | (optional) Locks device orientation when camera is showing, default false. (applicable to Android only) |
111
+ | enableOpacity | boolean | (optional) Make the camera preview see-through. Ideal for augmented reality uses. Default false (applicable to Android and web only) |
112
+ | enableZoom | boolean | (optional) Set if you can pinch to zoom. Default false (applicable to the android and ios platforms only) |
105
113
 
106
114
  <!-- <strong>Options:</strong>
107
115
  All options stated are optional and will default to values here
@@ -146,7 +154,8 @@ Take into account that this will make transparent all ion-content on application
146
154
  ```
147
155
 
148
156
  If the camera preview is not displaying after applying the above styles, apply transparent background color to the root div element of the parent component
149
- Ex: VueJS >> App.vue component
157
+ Ex: VueJS >> App.vue component
158
+
150
159
  ```html
151
160
  <template>
152
161
  <ion-app id="app">
@@ -161,20 +170,19 @@ Ex: VueJS >> App.vue component
161
170
  <style>
162
171
  ```
163
172
 
164
-
165
173
  ### stop()
166
174
 
167
- <info>Stops the camera preview instance.</info><br/>
175
+ <info>Stops the camera preview instance.</info>
176
+ <br />
168
177
 
169
178
  ```javascript
170
179
  CameraPreview.stop();
171
180
  ```
172
181
 
173
182
  ### flip()
183
+
174
184
  <info>Switch between rear and front camera only for android and ios, web is not supported</info>
175
- ```javascript
176
- CameraPreview.flip()
177
- ```
185
+ ```javascript CameraPreview.flip() ```
178
186
 
179
187
  <!-- ### switchCamera([successCallback, errorCallback])
180
188
 
@@ -202,11 +210,11 @@ CameraPreview.hide();
202
210
 
203
211
  ### capture(options)
204
212
 
205
- | Option | values | descriptions |
206
- |----------|---------------|----------------------------------------------------------------------|
207
- | quality | number | (optional) The picture quality, 0 - 100, default 85 |
208
- | width | number | (optional) The picture width, default 0 (Device default) |
209
- | height | number | (optional) The picture height, default 0 (Device default) |
213
+ | Option | values | descriptions |
214
+ | ------- | ------ | --------------------------------------------------------- |
215
+ | quality | number | (optional) The picture quality, 0 - 100, default 85 |
216
+ | width | number | (optional) The picture width, default 0 (Device default) |
217
+ | height | number | (optional) The picture height, default 0 (Device default) |
210
218
 
211
219
  <!-- <info>Take the picture. If width and height are not specified or are 0 it will use the defaults. If width and height are specified, it will choose a supported photo size that is closest to width and height specified and has closest aspect ratio to the preview. The argument `quality` defaults to `85` and specifies the quality/compression value: `0=max compression`, `100=max quality`.</info><br/> -->
212
220
 
@@ -226,11 +234,16 @@ const base64PictureData = result.value;
226
234
 
227
235
  ### captureSample(options)
228
236
 
229
- | Option | values | descriptions |
230
- |----------|---------------|----------------------------------------------------------------------|
231
- | quality | number | (optional) The picture quality, 0 - 100, default 85 |
237
+ | Option | values | descriptions |
238
+ | ------- | ------ | --------------------------------------------------- |
239
+ | quality | number | (optional) The picture quality, 0 - 100, default 85 |
232
240
 
233
- <info>Captures a sample image from the video stream. Only for Android and iOS, web implementation falls back to `capture` method. This can be used to perform real-time analysis on the current frame in the video. The argument `quality` defaults to `85` and specifies the quality/compression value: `0=max compression`, `100=max quality`.</info><br/>
241
+ <info>
242
+ Captures a sample image from the video stream. Only for Android and iOS, web implementation falls back to `capture`
243
+ method. This can be used to perform real-time analysis on the current frame in the video. The argument `quality`
244
+ defaults to `85` and specifies the quality/compression value: `0=max compression`, `100=max quality`.
245
+ </info>
246
+ <br />
234
247
 
235
248
  ```javascript
236
249
  import { CameraSampleOptions } from '@capacitor-community/camera-preview';
@@ -248,7 +261,11 @@ const base64PictureData = result.value;
248
261
 
249
262
  ### getSupportedFlashModes()
250
263
 
251
- <info>Get the flash modes supported by the camera device currently started. Returns an array containing supported flash modes. See <code>[FLASH_MODE](#camera_Settings.FlashMode)</code> for possible values that can be returned</info><br/>
264
+ <info>
265
+ Get the flash modes supported by the camera device currently started. Returns an array containing supported flash
266
+ modes. See <code>[FLASH_MODE](#camera_Settings.FlashMode)</code> for possible values that can be returned
267
+ </info>
268
+ <br />
252
269
 
253
270
  ```javascript
254
271
  import { CameraPreviewFlashMode } from '@capacitor-community/camera-preview';
@@ -256,9 +273,14 @@ import { CameraPreviewFlashMode } from '@capacitor-community/camera-preview';
256
273
  const flashModes = await CameraPreview.getSupportedFlashModes();
257
274
  const supportedFlashModes: CameraPreviewFlashMode[] = flashModes.result;
258
275
  ```
276
+
259
277
  ### setFlashMode(options)
260
278
 
261
- <info>Set the flash mode. See <code>[FLASH_MODE](#camera_Settings.FlashMode)</code> for details about the possible values for flashMode.</info><br/>
279
+ <info>
280
+ Set the flash mode. See <code>[FLASH_MODE](#camera_Settings.FlashMode)</code> for details about the possible values
281
+ for flashMode.
282
+ </info>
283
+ <br />
262
284
 
263
285
  ```javascript
264
286
  const CameraPreviewFlashMode: CameraPreviewFlashMode = 'torch';
@@ -266,9 +288,10 @@ const CameraPreviewFlashMode: CameraPreviewFlashMode = 'torch';
266
288
  CameraPreview.setFlashMode(cameraPreviewFlashMode);
267
289
  ```
268
290
 
269
- ### startRecordVideo(options) ---- ANDROID and iOS only
291
+ ### startRecordVideo(options) ---- ANDROID and iOS only
270
292
 
271
- <info>Start capturing video</info><br/>
293
+ <info>Start capturing video</info>
294
+ <br />
272
295
 
273
296
  ```javascript
274
297
  const cameraPreviewOptions: CameraPreviewOptions = {
@@ -280,26 +303,29 @@ const cameraPreviewOptions: CameraPreviewOptions = {
280
303
  CameraPreview.startRecordVideo(cameraPreviewOptions);
281
304
  ```
282
305
 
283
- ### stopRecordVideo() ---- ANDROID and iOS only
306
+ ### stopRecordVideo() ---- ANDROID and iOS only
284
307
 
285
- <info>Finish capturing a video. The captured video will be returned as a file path and the video format is .mp4</info><br/>
308
+ <info>Finish capturing a video. The captured video will be returned as a file path and the video format is .mp4</info>
309
+ <br />
286
310
 
287
311
  ```javascript
288
312
  const resultRecordVideo = await CameraPreview.stopRecordVideo();
289
313
  ```
290
314
 
291
- ### setOpacity(options: CameraOpacityOptions): Promise<{}>; ---- ANDROID only
315
+ ### setOpacity(options: CameraOpacityOptions): Promise<{}>; ---- ANDROID only
292
316
 
293
- <info>Set the opacity for the camera preview</info><br/>
317
+ <info>Set the opacity for the camera preview</info>
318
+ <br />
294
319
 
295
320
  ```javascript
296
- const myCamera = CameraPreview.start({enableOpacity: true});
297
- myCamera.setOpacity({opacity: 0.4});
321
+ const myCamera = CameraPreview.start({ enableOpacity: true });
322
+ myCamera.setOpacity({ opacity: 0.4 });
298
323
  ```
299
324
 
300
- ### isCameraStarted() ---- ANDROID and iOS only
325
+ ### isCameraStarted() ---- ANDROID and iOS only
301
326
 
302
- <info>Check or detect if the camera has been started</info><br/>
327
+ <info>Check or detect if the camera has been started</info>
328
+ <br />
303
329
 
304
330
  ```javascript
305
331
  const { value } = await CameraPreview.isCameraStarted();
@@ -311,15 +337,16 @@ const { value } = await CameraPreview.isCameraStarted();
311
337
 
312
338
  ### FLASH_MODE
313
339
 
314
- <info>Flash mode settings:</info><br/>
340
+ <info>Flash mode settings:</info>
341
+ <br />
315
342
 
316
- | Name | Type | Default | Note |
317
- | ------- | ------- | ------- | ------------- |
318
- | OFF | string | off | |
319
- | ON | string | on | |
320
- | AUTO | string | auto | |
321
- | RED_EYE | string | red-eye | Android Only |
322
- | TORCH | string | torch | |
343
+ | Name | Type | Default | Note |
344
+ | ------- | ------ | ------- | ------------ |
345
+ | OFF | string | off | |
346
+ | ON | string | on | |
347
+ | AUTO | string | auto | |
348
+ | RED_EYE | string | red-eye | Android Only |
349
+ | TORCH | string | torch | |
323
350
 
324
351
  <!--
325
352
 
@@ -449,8 +476,6 @@ Maintained by [Weston Ganger](https://westonganger.com) - [@westonganger](https:
449
476
  Created by Marcel Barbosa Pinto [@mbppower](https://github.com/mbppower)
450
477
  Â -->
451
478
 
452
- # Demo
453
-
454
- A working example can be found at [Demo](https://github.com/capacitor-community/camera-preview/tree/master/demo)
479
+ # Demo/Example App
455
480
 
456
- To run the demo on your local network and access media devices, a secure context is needed. Add an `.env` file at the root of the demo folder with `HTTPS=true` to start react with HTTPS.
481
+ A working example can be found at [Example App](https://github.com/capacitor-community/camera-preview/tree/master/example-app)
@@ -1,9 +1,9 @@
1
1
  ext {
2
2
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
4
- androidxExifInterfaceVersion = project.hasProperty('androidxExifInterfaceVersion') ? rootProject.ext.androidxExifInterfaceVersion : '1.3.6'
5
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
6
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
+ androidxExifInterfaceVersion = project.hasProperty('androidxExifInterfaceVersion') ? rootProject.ext.androidxExifInterfaceVersion : '1.3.7'
5
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
6
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
7
7
  }
8
8
 
9
9
  buildscript {
@@ -12,7 +12,7 @@ buildscript {
12
12
  google()
13
13
  }
14
14
  dependencies {
15
- classpath 'com.android.tools.build:gradle:8.2.1'
15
+ classpath 'com.android.tools.build:gradle:8.7.2'
16
16
  }
17
17
  }
18
18
 
@@ -20,10 +20,10 @@ apply plugin: 'com.android.library'
20
20
 
21
21
  android {
22
22
  namespace "com.ahm.capacitor.camera.preview.capacitorcamerapreview"
23
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
23
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
24
24
  defaultConfig {
25
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
26
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
25
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
26
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
27
27
  versionCode 1
28
28
  versionName "1.0"
29
29
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -1,6 +1,6 @@
1
1
  distributionBase=GRADLE_USER_HOME
2
2
  distributionPath=wrapper/dists
3
- distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
3
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
4
4
  networkTimeout=10000
5
5
  validateDistributionUrl=true
6
6
  zipStoreBase=GRADLE_USER_HOME
package/android/gradlew CHANGED
@@ -15,6 +15,8 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
  #
18
+ # SPDX-License-Identifier: Apache-2.0
19
+ #
18
20
 
19
21
  ##############################################################################
20
22
  #
@@ -55,7 +57,7 @@
55
57
  # Darwin, MinGW, and NonStop.
56
58
  #
57
59
  # (3) This script is generated from the Groovy template
58
- # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
60
+ # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59
61
  # within the Gradle project.
60
62
  #
61
63
  # You can find Gradle at https://github.com/gradle/gradle/.
@@ -83,7 +85,9 @@ done
83
85
  # This is normally unused
84
86
  # shellcheck disable=SC2034
85
87
  APP_BASE_NAME=${0##*/}
86
- APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
88
+ # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89
+ APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90
+ ' "$PWD" ) || exit
87
91
 
88
92
  # Use the maximum available, or set MAX_FD != -1 to use that value.
89
93
  MAX_FD=maximum
@@ -144,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144
148
  case $MAX_FD in #(
145
149
  max*)
146
150
  # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147
- # shellcheck disable=SC3045
151
+ # shellcheck disable=SC2039,SC3045
148
152
  MAX_FD=$( ulimit -H -n ) ||
149
153
  warn "Could not query maximum file descriptor limit"
150
154
  esac
@@ -152,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
152
156
  '' | soft) :;; #(
153
157
  *)
154
158
  # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155
- # shellcheck disable=SC3045
159
+ # shellcheck disable=SC2039,SC3045
156
160
  ulimit -n "$MAX_FD" ||
157
161
  warn "Could not set maximum file descriptor limit to $MAX_FD"
158
162
  esac
@@ -201,11 +205,11 @@ fi
201
205
  # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
202
206
  DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
203
207
 
204
- # Collect all arguments for the java command;
205
- # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
206
- # shell script including quotes and variable substitutions, so put them in
207
- # double quotes to make sure that they get re-expanded; and
208
- # * put everything else in single quotes, so that it's not re-expanded.
208
+ # Collect all arguments for the java command:
209
+ # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
210
+ # and any embedded shellness will be escaped.
211
+ # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
212
+ # treated as '${Hostname}' itself on the command line.
209
213
 
210
214
  set -- \
211
215
  "-Dorg.gradle.appname=$APP_BASE_NAME" \
@@ -13,6 +13,8 @@
13
13
  @rem See the License for the specific language governing permissions and
14
14
  @rem limitations under the License.
15
15
  @rem
16
+ @rem SPDX-License-Identifier: Apache-2.0
17
+ @rem
16
18
 
17
19
  @if "%DEBUG%"=="" @echo off
18
20
  @rem ##########################################################################
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
43
45
  %JAVA_EXE% -version >NUL 2>&1
44
46
  if %ERRORLEVEL% equ 0 goto execute
45
47
 
46
- echo.
47
- echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48
- echo.
49
- echo Please set the JAVA_HOME variable in your environment to match the
50
- echo location of your Java installation.
48
+ echo. 1>&2
49
+ echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50
+ echo. 1>&2
51
+ echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52
+ echo location of your Java installation. 1>&2
51
53
 
52
54
  goto fail
53
55
 
@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57
59
 
58
60
  if exist "%JAVA_EXE%" goto execute
59
61
 
60
- echo.
61
- echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62
- echo.
63
- echo Please set the JAVA_HOME variable in your environment to match the
64
- echo location of your Java installation.
62
+ echo. 1>&2
63
+ echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64
+ echo. 1>&2
65
+ echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66
+ echo location of your Java installation. 1>&2
65
67
 
66
68
  goto fail
67
69
 
@@ -136,8 +136,9 @@ public class CameraActivity extends Fragment {
136
136
  //set box position and size
137
137
  FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width, height);
138
138
  layoutParams.setMargins(x, y, 0, 0);
139
- frameContainerLayout =
140
- (FrameLayout) view.findViewById(getResources().getIdentifier("frame_container", "id", appResourcesPackage));
139
+ frameContainerLayout = (FrameLayout) view.findViewById(
140
+ getResources().getIdentifier("frame_container", "id", appResourcesPackage)
141
+ );
141
142
  frameContainerLayout.setLayoutParams(layoutParams);
142
143
 
143
144
  //video view
@@ -173,7 +174,8 @@ public class CameraActivity extends Fragment {
173
174
 
174
175
  @Override
175
176
  public boolean onTouch(View v, MotionEvent event) {
176
- FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) frameContainerLayout.getLayoutParams();
177
+ FrameLayout.LayoutParams layoutParams =
178
+ (FrameLayout.LayoutParams) frameContainerLayout.getLayoutParams();
177
179
 
178
180
  boolean isSingleTapTouch = gestureDetector.onTouchEvent(event);
179
181
  int action = event.getAction();
@@ -427,6 +429,44 @@ public class CameraActivity extends Fragment {
427
429
  return mCamera;
428
430
  }
429
431
 
432
+ /**
433
+ * Method to get the front camera id if the current camera is back and visa versa
434
+ *
435
+ * @return front or back camera id depending on the currently active camera
436
+ */
437
+ private int getNextCameraId() {
438
+ int nextCameraId = 0;
439
+
440
+ // Find the total number of cameras available
441
+ // NOTE: The getNumberOfCameras() method in Android's android.hardware.camera API returns the total
442
+ // number of cameras available on the device. The number might not be limited to just the front
443
+ // and back cameras because modern smartphones often come with more than two cameras.
444
+ // For example, devices might have:
445
+ // - a main (back) camera.
446
+ // - a wide-angle camera.
447
+ // - a telephoto camera.
448
+ // - a depth-sensing camera.
449
+ // - an ultrawide camera.
450
+ // - a macro camera.
451
+ // etc.
452
+ numberOfCameras = Camera.getNumberOfCameras();
453
+
454
+ int nextFacing = cameraCurrentlyLocked == Camera.CameraInfo.CAMERA_FACING_BACK
455
+ ? Camera.CameraInfo.CAMERA_FACING_FRONT
456
+ : Camera.CameraInfo.CAMERA_FACING_BACK;
457
+
458
+ // Find the next ID of the camera to switch to (front if the current is back and visa versa)
459
+ Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
460
+ for (int i = 0; i < numberOfCameras; i++) {
461
+ Camera.getCameraInfo(i, cameraInfo);
462
+ if (cameraInfo.facing == nextFacing) {
463
+ nextCameraId = i;
464
+ break;
465
+ }
466
+ }
467
+ return nextCameraId;
468
+ }
469
+
430
470
  public void switchCamera() {
431
471
  // check for availability of multiple cameras
432
472
  if (numberOfCameras == 1) {
@@ -444,7 +484,7 @@ public class CameraActivity extends Fragment {
444
484
 
445
485
  Log.d(TAG, "cameraCurrentlyLocked := " + Integer.toString(cameraCurrentlyLocked));
446
486
  try {
447
- cameraCurrentlyLocked = (cameraCurrentlyLocked + 1) % numberOfCameras;
487
+ cameraCurrentlyLocked = getNextCameraId();
448
488
  Log.d(TAG, "cameraCurrentlyLocked new: " + cameraCurrentlyLocked);
449
489
  } catch (Exception exception) {
450
490
  Log.d(TAG, exception.getMessage());
@@ -981,10 +1021,10 @@ public class CameraActivity extends Fragment {
981
1021
  y = height - 100;
982
1022
  }
983
1023
  return new Rect(
984
- Math.round((x - 100) * 2000 / width - 1000),
985
- Math.round((y - 100) * 2000 / height - 1000),
986
- Math.round((x + 100) * 2000 / width - 1000),
987
- Math.round((y + 100) * 2000 / height - 1000)
1024
+ Math.round(((x - 100) * 2000) / width - 1000),
1025
+ Math.round(((y - 100) * 2000) / height - 1000),
1026
+ Math.round(((x + 100) * 2000) / width - 1000),
1027
+ Math.round(((y + 100) * 2000) / height - 1000)
988
1028
  );
989
1029
  }
990
1030
 
@@ -70,7 +70,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
70
70
  @PluginMethod
71
71
  public void setOpacity(PluginCall call) {
72
72
  if (this.hasCamera(call) == false) {
73
- call.error("Camera is not running");
73
+ call.reject("Camera is not running");
74
74
  return;
75
75
  }
76
76
 
@@ -223,14 +223,14 @@ class Preview extends RelativeLayout implements SurfaceHolder.Callback, TextureV
223
223
  // Center the child SurfaceView within the parent.
224
224
  if (width * previewHeight < height * previewWidth) {
225
225
  Log.d(TAG, "center horizontally");
226
- int scaledChildWidth = (int) ((previewWidth * height / previewHeight) * scale);
226
+ int scaledChildWidth = (int) (((previewWidth * height) / previewHeight) * scale);
227
227
  nW = (width + scaledChildWidth) / 2;
228
228
  nH = (int) (height * scale);
229
229
  top = 0;
230
230
  left = (width - scaledChildWidth) / 2;
231
231
  } else {
232
232
  Log.d(TAG, "center vertically");
233
- int scaledChildHeight = (int) ((previewHeight * width / previewWidth) * scale);
233
+ int scaledChildHeight = (int) (((previewHeight * width) / previewWidth) * scale);
234
234
  nW = (int) (width * scale);
235
235
  nH = (height + scaledChildHeight) / 2;
236
236
  top = (height - scaledChildHeight) / 2;
package/dist/esm/web.d.ts CHANGED
@@ -6,7 +6,6 @@ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreview
6
6
  * used in capture
7
7
  */
8
8
  private isBackCamera;
9
- constructor();
10
9
  start(options: CameraPreviewOptions): Promise<void>;
11
10
  startRecordVideo(): Promise<void>;
12
11
  stopRecordVideo(): Promise<void>;
package/dist/esm/web.js CHANGED
@@ -1,11 +1,5 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  export class CameraPreviewWeb extends WebPlugin {
3
- constructor() {
4
- super({
5
- name: 'CameraPreview',
6
- platforms: ['web'],
7
- });
8
- }
9
3
  async start(options) {
10
4
  // eslint-disable-next-line no-async-promise-executor
11
5
  return new Promise(async (resolve, reject) => {
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAO7C;QACE,KAAK,CAAC;YACJ,IAAI,EAAE,eAAe;YACrB,SAAS,EAAE,CAAC,KAAK,CAAC;SACnB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAA6B;QACvC,qDAAqD;QACrD,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;;YAC3C,MAAM,SAAS,CAAC,YAAY;iBACzB,YAAY,CAAC;gBACZ,KAAK,EAAE,CAAC,OAAO,CAAC,YAAY;gBAC5B,KAAK,EAAE,IAAI;aACZ,CAAC;iBACD,IAAI,CAAC,CAAC,MAAmB,EAAE,EAAE;gBAC5B,kGAAkG;gBAClG,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,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AE,CAAC,CAAC;aAC1F;YAED,OAAO,CAAC;gBACN,KAAK,EAAE,kBAAkB;aAC1B,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,QAA6B;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,sBAAsB;QAG1B,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IAED,6DAA6D;IAC7D,KAAK,CAAC,YAAY,CAAC,QAAwD;QACzE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,QAA8B;QAC7C,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAqB,CAAC;QACnE,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YACpC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;SACpE;IACH,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CameraPreviewOptions,\n CameraPreviewPictureOptions,\n CameraPreviewPlugin,\n CameraPreviewFlashMode,\n CameraSampleOptions,\n CameraOpacityOptions,\n} from './definitions';\n\nexport class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {\n /**\n * track which camera is used based on start options\n * used in capture\n */\n private isBackCamera: boolean;\n\n constructor() {\n super({\n name: 'CameraPreview',\n platforms: ['web'],\n });\n }\n\n async start(options: CameraPreviewOptions): Promise<void> {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true,\n })\n .then((stream: MediaStream) => {\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n })\n .catch((error) => {\n reject(error);\n });\n\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n\n if (!video) {\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n\n parent.appendChild(videoElement);\n\n if (navigator.mediaDevices?.getUserMedia) {\n const constraints: MediaStreamConstraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n\n if (options.position === 'rear') {\n (constraints.video as MediaTrackConstraints).facingMode = 'environment';\n this.isBackCamera = true;\n } else {\n this.isBackCamera = false;\n }\n\n navigator.mediaDevices.getUserMedia(constraints).then(\n function (stream) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n resolve();\n },\n (err) => {\n reject(err);\n }\n );\n }\n } else {\n reject({ message: 'camera already started' });\n }\n });\n }\n\n async startRecordVideo(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async stopRecordVideo(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async stop(): Promise<any> {\n const video = document.getElementById('video') as HTMLVideoElement;\n if (video) {\n video.pause();\n\n const st: any = video.srcObject;\n const tracks = st.getTracks();\n\n for (const track of tracks) {\n track.stop();\n }\n video.remove();\n }\n }\n\n async capture(options: CameraPreviewPictureOptions): Promise<any> {\n return new Promise((resolve) => {\n const video = document.getElementById('video') as HTMLVideoElement;\n const canvas = document.createElement('canvas');\n\n // video.width = video.offsetWidth;\n\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n\n let base64EncodedImage;\n\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n } else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n\n async captureSample(_options: CameraSampleOptions): Promise<any> {\n return this.capture(_options);\n }\n\n async getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }> {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async setFlashMode(_options: { flashMode: CameraPreviewFlashMode | string }): Promise<void> {\n throw new Error('setFlashMode not supported under the web platform');\n }\n\n async flip(): Promise<void> {\n throw new Error('flip not supported under the web platform');\n }\n\n async setOpacity(_options: CameraOpacityOptions): Promise<any> {\n const video = document.getElementById('video') as HTMLVideoElement;\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n\n async isCameraStarted(): Promise<{ value: boolean }> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA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AAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;SACpE;IACH,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CameraPreviewOptions,\n CameraPreviewPictureOptions,\n CameraPreviewPlugin,\n CameraPreviewFlashMode,\n CameraSampleOptions,\n CameraOpacityOptions,\n} from './definitions';\n\nexport class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {\n /**\n * track which camera is used based on start options\n * used in capture\n */\n private isBackCamera: boolean;\n\n async start(options: CameraPreviewOptions): Promise<void> {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true,\n })\n .then((stream: MediaStream) => {\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n })\n .catch((error) => {\n reject(error);\n });\n\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n\n if (!video) {\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n\n parent.appendChild(videoElement);\n\n if (navigator.mediaDevices?.getUserMedia) {\n const constraints: MediaStreamConstraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n\n if (options.position === 'rear') {\n (constraints.video as MediaTrackConstraints).facingMode = 'environment';\n this.isBackCamera = true;\n } else {\n this.isBackCamera = false;\n }\n\n navigator.mediaDevices.getUserMedia(constraints).then(\n function (stream) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n resolve();\n },\n (err) => {\n reject(err);\n },\n );\n }\n } else {\n reject({ message: 'camera already started' });\n }\n });\n }\n\n async startRecordVideo(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async stopRecordVideo(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async stop(): Promise<any> {\n const video = document.getElementById('video') as HTMLVideoElement;\n if (video) {\n video.pause();\n\n const st: any = video.srcObject;\n const tracks = st.getTracks();\n\n for (const track of tracks) {\n track.stop();\n }\n video.remove();\n }\n }\n\n async capture(options: CameraPreviewPictureOptions): Promise<any> {\n return new Promise((resolve) => {\n const video = document.getElementById('video') as HTMLVideoElement;\n const canvas = document.createElement('canvas');\n\n // video.width = video.offsetWidth;\n\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n\n let base64EncodedImage;\n\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n } else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n\n async captureSample(_options: CameraSampleOptions): Promise<any> {\n return this.capture(_options);\n }\n\n async getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }> {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async setFlashMode(_options: { flashMode: CameraPreviewFlashMode | string }): Promise<void> {\n throw new Error('setFlashMode not supported under the web platform');\n }\n\n async flip(): Promise<void> {\n throw new Error('flip not supported under the web platform');\n }\n\n async setOpacity(_options: CameraOpacityOptions): Promise<any> {\n const video = document.getElementById('video') as HTMLVideoElement;\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n\n async isCameraStarted(): Promise<{ value: boolean }> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"]}
@@ -7,12 +7,6 @@ const CameraPreview = core.registerPlugin('CameraPreview', {
7
7
  });
8
8
 
9
9
  class CameraPreviewWeb extends core.WebPlugin {
10
- constructor() {
11
- super({
12
- name: 'CameraPreview',
13
- platforms: ['web'],
14
- });
15
- }
16
10
  async start(options) {
17
11
  // eslint-disable-next-line no-async-promise-executor
18
12
  return new Promise(async (resolve, reject) => {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super({\n name: 'CameraPreview',\n platforms: ['web'],\n });\n }\n async start(options) {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n var _a;\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true,\n })\n .then((stream) => {\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n })\n .catch((error) => {\n reject(error);\n });\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (!video) {\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if ((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n resolve();\n }, (err) => {\n reject(err);\n });\n }\n }\n else {\n reject({ message: 'camera already started' });\n }\n });\n }\n async startRecordVideo() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stopRecordVideo() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (const track of tracks) {\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async isCameraStarted() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;AACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACpE,CAAC;;ACFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;AAChD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC;AACd,YAAY,IAAI,EAAE,eAAe;AACjC,YAAY,SAAS,EAAE,CAAC,KAAK,CAAC;AAC9B,SAAS,CAAC;AACV;AACA,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB;AACA,QAAQ,OAAO,IAAI,OAAO,CAAC,OAAO,OAAO,EAAE,MAAM,KAAK;AACtD,YAAY,IAAI,EAAE;AAClB,YAAY,MAAM,SAAS,CAAC;AAC5B,iBAAiB,YAAY,CAAC;AAC9B,gBAAgB,KAAK,EAAE,CAAC,OAAO,CAAC,YAA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,aAAa,CAAC,yBAAyB,CAAC;AAC3D;AACA;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n async start(options) {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n var _a;\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true,\n })\n .then((stream) => {\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n })\n .catch((error) => {\n reject(error);\n });\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (!video) {\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if ((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n resolve();\n }, (err) => {\n reject(err);\n });\n }\n }\n else {\n reject({ message: 'camera already started' });\n }\n });\n }\n async startRecordVideo() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stopRecordVideo() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (const track of tracks) {\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async isCameraStarted() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,M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QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC;AACpE;AACA,IAAI,MAAM,UAAU,CAAC,QAAQ,EAAE;AAC/B,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;AACtD,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AAC9C,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC9E;AACA;AACA,IAAI,MAAM,eAAe,GAAG;AAC5B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D;AACA;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -6,12 +6,6 @@ var capacitorCameraPreview = (function (exports, core) {
6
6
  });
7
7
 
8
8
  class CameraPreviewWeb extends core.WebPlugin {
9
- constructor() {
10
- super({
11
- name: 'CameraPreview',
12
- platforms: ['web'],
13
- });
14
- }
15
9
  async start(options) {
16
10
  // eslint-disable-next-line no-async-promise-executor
17
11
  return new Promise(async (resolve, reject) => {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super({\n name: 'CameraPreview',\n platforms: ['web'],\n });\n }\n async start(options) {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n var _a;\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true,\n })\n .then((stream) => {\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n })\n .catch((error) => {\n reject(error);\n });\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (!video) {\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if ((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n resolve();\n }, (err) => {\n reject(err);\n });\n }\n }\n else {\n reject({ message: 'camera already started' });\n }\n });\n }\n async startRecordVideo() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stopRecordVideo() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (const track of tracks) {\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async isCameraStarted() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpE,CAAC;;ICFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC;IACd,YAAY,IAAI,EAAE,eAAe;IACjC,YAAY,SAAS,EAAE,CAAC,KAAK,CAAC;IAC9B,SAAS,CAAC;IACV;IACA,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB;IACA,QAAQ,OAAO,IAAI,OAAO,CAAC,OAAO,OAAO,EAAE,MAAM,KAAK;IACtD,YAAY,IAAI,EAAE;I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S,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9E;IACA;IACA,IAAI,MAAM,eAAe,GAAG;IAC5B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D;IACA;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n async start(options) {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n var _a;\n await navigator.mediaDevices\n .getUserMedia({\n audio: !options.disableAudio,\n video: true,\n })\n .then((stream) => {\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n })\n .catch((error) => {\n reject(error);\n });\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (!video) {\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if ((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {\n //video.src = window.URL.createObjectURL(stream);\n videoElement.srcObject = stream;\n videoElement.play();\n resolve();\n }, (err) => {\n reject(err);\n });\n }\n }\n else {\n reject({ message: 'camera already started' });\n }\n });\n }\n async startRecordVideo() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stopRecordVideo() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (const track of tracks) {\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async isCameraStarted() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpE,CAAC;;ICFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB;IACA,QAAQ,OAAO,IAAI,OAAO,CAAC,OAAO,OAAO,EAAE,MAAM,KAAK;IACtD,YAAY,IAAI,EAAE;IAClB,YAAY,MAAM,SAAS,CAAC;IAC5B,iBAAiB,YAAY,CAAC;IAC9B,gBAAgB,KAAK,EAAE,CAAC,OAAO,CAAC,YAAY;IAC5C,gBAAgB,KAAK,EAAE,IAAI;IAC3B,aAAa;IACb,iBAAiB,IAAI,CAAC,CAAC,MAAM,KAAK;IAClC;IACA,gBAAgB,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;IACnE,aAAa;IACb,iBAAiB,KAAK,CAAC,CAAC,KAAK,KAAK;IAClC,gBAAgB,MAAM,CAAC,KAAK,CAAC;IAC7B,aAAa,CAAC;IACd,YAAY,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;IAC1D,YAAY,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;IAClE,YAAY,IAAI,CAAC,KAAK,EAAE;IACxB,gBAAgB,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;IACpE,gBAAgB,YAAY,CAAC,EAAE,GAAG,OAAO;IACzC,gBAAgB,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAA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QAAQ,EAAE;IACjC,QAAQ,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC;IAC5E;IACA,IAAI,MAAM,IAAI,GAAG;IACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC;IACpE;IACA,IAAI,MAAM,UAAU,CAAC,QAAQ,EAAE;IAC/B,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;IACtD,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;IAC9C,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9E;IACA;IACA,IAAI,MAAM,eAAe,GAAG;IAC5B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D;IACA;;;;;;;;;;;;;;;"}
@@ -595,17 +595,14 @@ extension UIImage {
595
595
  transform = transform.translatedBy(x: size.width, y: size.height)
596
596
  transform = transform.rotated(by: CGFloat.pi)
597
597
  print("down")
598
- break
599
598
  case .left, .leftMirrored:
600
599
  transform = transform.translatedBy(x: size.width, y: 0)
601
600
  transform = transform.rotated(by: CGFloat.pi / 2.0)
602
601
  print("left")
603
- break
604
602
  case .right, .rightMirrored:
605
603
  transform = transform.translatedBy(x: 0, y: size.height)
606
604
  transform = transform.rotated(by: CGFloat.pi / -2.0)
607
605
  print("right")
608
- break
609
606
  case .up, .upMirrored:
610
607
  break
611
608
  }
@@ -615,7 +612,6 @@ extension UIImage {
615
612
  case .upMirrored, .downMirrored:
616
613
  transform.translatedBy(x: size.width, y: 0)
617
614
  transform.scaledBy(x: -1, y: 1)
618
- break
619
615
  case .leftMirrored, .rightMirrored:
620
616
  transform.translatedBy(x: size.height, y: 0)
621
617
  transform.scaledBy(x: -1, y: 1)
@@ -630,7 +626,6 @@ extension UIImage {
630
626
  ctx.draw(self.cgImage!, in: CGRect(x: 0, y: 0, width: size.height, height: size.width))
631
627
  default:
632
628
  ctx.draw(self.cgImage!, in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
633
- break
634
629
  }
635
630
  guard let newCGImage = ctx.makeImage() else { return nil }
636
631
  return UIImage.init(cgImage: newCGImage, scale: 1, orientation: .up)
@@ -11,8 +11,10 @@ public class CameraPreview: CAPPlugin {
11
11
  var previewView: UIView!
12
12
  var cameraPosition = String()
13
13
  let cameraController = CameraController()
14
+ // swiftlint:disable identifier_name
14
15
  var x: CGFloat?
15
16
  var y: CGFloat?
17
+ // swiftlint:enable identifier_name
16
18
  var width: CGFloat?
17
19
  var height: CGFloat?
18
20
  var paddingBottom: CGFloat?
@@ -287,7 +289,7 @@ public class CameraPreview: CAPPlugin {
287
289
 
288
290
  }
289
291
  }
290
-
292
+
291
293
  @objc func isCameraStarted(_ call: CAPPluginCall) {
292
294
  DispatchQueue.main.async {
293
295
  if self.cameraController.captureSession?.isRunning ?? false {
@@ -414,7 +414,7 @@
414
414
  GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
415
415
  GCC_WARN_UNUSED_FUNCTION = YES;
416
416
  GCC_WARN_UNUSED_VARIABLE = YES;
417
- IPHONEOS_DEPLOYMENT_TARGET = 13.0;
417
+ IPHONEOS_DEPLOYMENT_TARGET = 14.0;
418
418
  MTL_ENABLE_DEBUG_INFO = YES;
419
419
  ONLY_ACTIVE_ARCH = YES;
420
420
  SDKROOT = iphoneos;
@@ -469,7 +469,7 @@
469
469
  GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
470
470
  GCC_WARN_UNUSED_FUNCTION = YES;
471
471
  GCC_WARN_UNUSED_VARIABLE = YES;
472
- IPHONEOS_DEPLOYMENT_TARGET = 13.0;
472
+ IPHONEOS_DEPLOYMENT_TARGET = 14.0;
473
473
  MTL_ENABLE_DEBUG_INFO = NO;
474
474
  SDKROOT = iphoneos;
475
475
  SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
@@ -493,7 +493,7 @@
493
493
  DYLIB_INSTALL_NAME_BASE = "@rpath";
494
494
  INFOPLIST_FILE = Plugin/Info.plist;
495
495
  INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
496
- IPHONEOS_DEPLOYMENT_TARGET = 13.0;
496
+ IPHONEOS_DEPLOYMENT_TARGET = 14.0;
497
497
  LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)";
498
498
  ONLY_ACTIVE_ARCH = YES;
499
499
  PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin;
@@ -519,7 +519,7 @@
519
519
  DYLIB_INSTALL_NAME_BASE = "@rpath";
520
520
  INFOPLIST_FILE = Plugin/Info.plist;
521
521
  INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
522
- IPHONEOS_DEPLOYMENT_TARGET = 13.0;
522
+ IPHONEOS_DEPLOYMENT_TARGET = 14.0;
523
523
  LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)";
524
524
  ONLY_ACTIVE_ARCH = NO;
525
525
  PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin;
@@ -3,14 +3,4 @@ import Capacitor
3
3
  @testable import Plugin
4
4
 
5
5
  class PluginTests: XCTestCase {
6
-
7
- override func setUp() {
8
- super.setUp()
9
- // Put setup code here. This method is called before the invocation of each test method in the class.
10
- }
11
-
12
- override func tearDown() {
13
- // Put teardown code here. This method is called after the invocation of each test method in the class.
14
- super.tearDown()
15
- }
16
6
  }
package/ios/Podfile CHANGED
@@ -1,4 +1,4 @@
1
- platform :ios, '13.0'
1
+ platform :ios, '14.0'
2
2
 
3
3
  def capacitor_pods
4
4
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/camera-preview",
3
- "version": "6.0.1",
3
+ "version": "7.0.1",
4
4
  "description": "Camera preview",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -17,7 +17,7 @@
17
17
  "lint": "concurrently -g \"npm:eslint\" \"npm:prettier -- --check --plugin=prettier-plugin-java\" \"npm run swiftlint -- lint ios\"",
18
18
  "fmt": "concurrently -g \"npm:eslint -- --fix\" \"npm:prettier -- --write\" \"npm:swiftlint -- lint --fix --format ios\"",
19
19
  "eslint": "eslint . --ext ts",
20
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
20
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
21
21
  "swiftlint": "node-swiftlint",
22
22
  "prepublishOnly": "npm run build",
23
23
  "prepare": "husky install && npm run build"
@@ -25,25 +25,25 @@
25
25
  "author": "Ariel Hernandez Musa",
26
26
  "license": "MIT",
27
27
  "devDependencies": {
28
- "@capacitor/android": "^6.2.0",
29
- "@capacitor/core": "^6.2.0",
30
- "@capacitor/ios": "^6.2.0",
28
+ "@capacitor/android": "^7.2.0",
29
+ "@capacitor/core": "^7.2.0",
30
+ "@capacitor/ios": "^7.2.0",
31
31
  "@ionic/eslint-config": "^0.4.0",
32
32
  "@ionic/prettier-config": "^4.0.0",
33
33
  "@ionic/swiftlint-config": "^2.0.0",
34
- "concurrently": "^9.1.0",
35
- "eslint": "^8.57.1",
34
+ "concurrently": "^9.1.2",
35
+ "eslint": "^8.57.0",
36
36
  "husky": "^9.1.7",
37
- "prettier": "^3.4.2",
38
- "prettier-plugin-java": "^2.6.5",
39
- "pretty-quick": "^4.0.0",
37
+ "prettier": "^3.5.3",
38
+ "prettier-plugin-java": "^2.6.6",
39
+ "pretty-quick": "^4.1.1",
40
40
  "rimraf": "^6.0.1",
41
- "rollup": "^4.28.1",
41
+ "rollup": "^4.39.0",
42
42
  "swiftlint": "^2.0.0",
43
43
  "typescript": "^4.3.2"
44
44
  },
45
45
  "peerDependencies": {
46
- "@capacitor/core": "^6.0.0"
46
+ "@capacitor/core": ">=7.0.0"
47
47
  },
48
48
  "husky": {
49
49
  "hooks": {
@@ -1,15 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
- xmlns:app="http://schemas.android.com/apk/res-auto"
4
- xmlns:tools="http://schemas.android.com/tools"
5
- android:layout_width="match_parent"
6
- android:layout_height="match_parent"
7
- tools:context="com.getcapacitor.BridgeActivity"
8
- >
9
-
10
- <WebView
11
- android:id="@+id/webview"
12
- android:layout_width="fill_parent"
13
- android:layout_height="fill_parent" />
14
-
15
- </androidx.coordinatorlayout.widget.CoordinatorLayout>
@@ -1,3 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <resources>
3
- </resources>
@@ -1,3 +0,0 @@
1
- <resources>
2
- <string name="my_string">Just a simple string</string>
3
- </resources>
@@ -1,3 +0,0 @@
1
- <resources>
2
-
3
- </resources>