@capgo/camera-preview 7.3.9 → 7.4.0-beta.2

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.
Files changed (56) hide show
  1. package/CapgoCameraPreview.podspec +16 -13
  2. package/README.md +306 -70
  3. package/android/.gradle/8.14.2/checksums/checksums.lock +0 -0
  4. package/android/.gradle/8.14.2/checksums/sha1-checksums.bin +0 -0
  5. package/android/.gradle/8.14.2/executionHistory/executionHistory.bin +0 -0
  6. package/android/.gradle/8.14.2/executionHistory/executionHistory.lock +0 -0
  7. package/android/.gradle/8.14.2/fileChanges/last-build.bin +0 -0
  8. package/android/.gradle/8.14.2/fileHashes/fileHashes.bin +0 -0
  9. package/android/.gradle/8.14.2/fileHashes/fileHashes.lock +0 -0
  10. package/android/.gradle/8.14.2/fileHashes/resourceHashesCache.bin +0 -0
  11. package/android/.gradle/8.14.2/gc.properties +0 -0
  12. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  13. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  14. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  15. package/android/.gradle/file-system.probe +0 -0
  16. package/android/.gradle/vcs-1/gc.properties +0 -0
  17. package/android/build.gradle +9 -0
  18. package/android/src/main/AndroidManifest.xml +5 -0
  19. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +260 -551
  20. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraXView.java +968 -0
  21. package/android/src/main/java/com/ahm/capacitor/camera/preview/model/CameraDevice.java +54 -0
  22. package/android/src/main/java/com/ahm/capacitor/camera/preview/model/CameraLens.java +70 -0
  23. package/android/src/main/java/com/ahm/capacitor/camera/preview/model/CameraSessionConfiguration.java +65 -0
  24. package/android/src/main/java/com/ahm/capacitor/camera/preview/model/LensInfo.java +34 -0
  25. package/android/src/main/java/com/ahm/capacitor/camera/preview/model/ZoomFactors.java +34 -0
  26. package/dist/docs.json +729 -153
  27. package/dist/esm/definitions.d.ts +337 -80
  28. package/dist/esm/definitions.js +10 -1
  29. package/dist/esm/definitions.js.map +1 -1
  30. package/dist/esm/web.d.ts +27 -1
  31. package/dist/esm/web.js +248 -4
  32. package/dist/esm/web.js.map +1 -1
  33. package/dist/plugin.cjs.js +256 -4
  34. package/dist/plugin.cjs.js.map +1 -1
  35. package/dist/plugin.js +256 -4
  36. package/dist/plugin.js.map +1 -1
  37. package/ios/{Plugin → Sources/CapgoCameraPreview}/CameraController.swift +359 -34
  38. package/ios/{Plugin → Sources/CapgoCameraPreview}/Plugin.swift +348 -42
  39. package/ios/Tests/CameraPreviewPluginTests/CameraPreviewPluginTests.swift +15 -0
  40. package/package.json +1 -1
  41. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +0 -1279
  42. package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomSurfaceView.java +0 -29
  43. package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +0 -39
  44. package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +0 -461
  45. package/android/src/main/java/com/ahm/capacitor/camera/preview/TapGestureDetector.java +0 -24
  46. package/ios/Plugin/Info.plist +0 -24
  47. package/ios/Plugin/Plugin.h +0 -10
  48. package/ios/Plugin/Plugin.m +0 -18
  49. package/ios/Plugin.xcodeproj/project.pbxproj +0 -593
  50. package/ios/Plugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  51. package/ios/Plugin.xcworkspace/contents.xcworkspacedata +0 -10
  52. package/ios/Plugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  53. package/ios/PluginTests/Info.plist +0 -22
  54. package/ios/PluginTests/PluginTests.swift +0 -83
  55. package/ios/Podfile +0 -13
  56. package/ios/Podfile.lock +0 -23
@@ -1,175 +1,432 @@
1
1
  export type CameraPosition = "rear" | "front";
2
+ export type FlashMode = CameraPreviewFlashMode;
3
+ export declare enum DeviceType {
4
+ ULTRA_WIDE = "ultraWide",
5
+ WIDE_ANGLE = "wideAngle",
6
+ TELEPHOTO = "telephoto",
7
+ TRUE_DEPTH = "trueDepth",
8
+ DUAL = "dual",
9
+ DUAL_WIDE = "dualWide",
10
+ TRIPLE = "triple"
11
+ }
12
+ /**
13
+ * Represents a single camera lens on a device. A {@link CameraDevice} can have multiple lenses.
14
+ */
15
+ export interface CameraLens {
16
+ /** A human-readable name for the lens, e.g., "Ultra-Wide". */
17
+ label: string;
18
+ /** The type of the camera lens. */
19
+ deviceType: DeviceType;
20
+ /** The focal length of the lens in millimeters. */
21
+ focalLength: number;
22
+ /** The base zoom factor for this lens (e.g., 0.5 for ultra-wide, 1.0 for wide). */
23
+ baseZoomRatio: number;
24
+ /** The minimum zoom factor supported by this specific lens. */
25
+ minZoom: number;
26
+ /** The maximum zoom factor supported by this specific lens. */
27
+ maxZoom: number;
28
+ }
29
+ /**
30
+ * Represents a physical camera on the device (e.g., the front-facing camera).
31
+ */
32
+ export interface CameraDevice {
33
+ /** A unique identifier for the camera device. */
34
+ deviceId: string;
35
+ /** A human-readable name for the camera device. */
36
+ label: string;
37
+ /** The physical position of the camera on the device. */
38
+ position: CameraPosition;
39
+ /** A list of all available lenses for this camera device. */
40
+ lenses: CameraLens[];
41
+ /** The overall minimum zoom factor available across all lenses on this device. */
42
+ minZoom: number;
43
+ /** The overall maximum zoom factor available across all lenses on this device. */
44
+ maxZoom: number;
45
+ /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */
46
+ isLogical: boolean;
47
+ }
48
+ /**
49
+ * Represents the detailed information of the currently active lens.
50
+ */
51
+ export interface LensInfo {
52
+ /** The focal length of the active lens in millimeters. */
53
+ focalLength: number;
54
+ /** The device type of the active lens. */
55
+ deviceType: DeviceType;
56
+ /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */
57
+ baseZoomRatio: number;
58
+ /** The current digital zoom factor applied on top of the base zoom. */
59
+ digitalZoom: number;
60
+ }
61
+ /**
62
+ * Defines the configuration options for starting the camera preview.
63
+ */
2
64
  export interface CameraPreviewOptions {
3
- /** Parent element to attach the video preview element to (applicable to the web platform only) */
65
+ /**
66
+ * The parent element to attach the video preview to.
67
+ * @platform web
68
+ */
4
69
  parent?: string;
5
- /** Class name to add to the video preview element (applicable to the web platform only) */
70
+ /**
71
+ * A CSS class name to add to the preview element.
72
+ * @platform web
73
+ */
6
74
  className?: string;
7
- /** The preview width in pixels, default window.screen.width */
75
+ /**
76
+ * The width of the preview in pixels. Defaults to the screen width.
77
+ * @platform android, ios, web
78
+ */
8
79
  width?: number;
9
- /** The preview height in pixels, default window.screen.height */
80
+ /**
81
+ * The height of the preview in pixels. Defaults to the screen height.
82
+ * @platform android, ios, web
83
+ */
10
84
  height?: number;
11
- /** The x origin, default 0 (applicable to the android and ios platforms only) */
85
+ /**
86
+ * The horizontal origin of the preview, in pixels.
87
+ * @platform android, ios
88
+ */
12
89
  x?: number;
13
- /** The y origin, default 0 (applicable to the android and ios platforms only) */
90
+ /**
91
+ * The vertical origin of the preview, in pixels.
92
+ * @platform android, ios
93
+ */
14
94
  y?: number;
15
- /** Whether to include safe area insets in y-position calculation, default false (applicable to the ios platform only) */
95
+ /**
96
+ * Adjusts the y-position to account for safe areas (e.g., notches).
97
+ * @platform ios
98
+ * @default false
99
+ */
16
100
  includeSafeAreaInsets?: boolean;
17
- /** Brings your html in front of your preview, default false (applicable to the android only) */
101
+ /**
102
+ * If true, places the preview behind the webview.
103
+ * @platform android
104
+ * @default true
105
+ */
18
106
  toBack?: boolean;
19
- /** The preview bottom padding in pixes. Useful to keep the appropriate preview sizes when orientation changes (applicable to the android and ios platforms only) */
107
+ /**
108
+ * Bottom padding for the preview, in pixels.
109
+ * @platform android, ios
110
+ */
20
111
  paddingBottom?: number;
21
- /** Rotate preview when orientation changes (applicable to the ios platforms only; default value is true) */
112
+ /**
113
+ * Whether to rotate the preview when the device orientation changes.
114
+ * @platform ios
115
+ * @default true
116
+ */
22
117
  rotateWhenOrientationChanged?: boolean;
23
- /** Choose the camera to use 'front' or 'rear', default 'front' */
118
+ /**
119
+ * The camera to use.
120
+ * @default "rear"
121
+ */
24
122
  position?: CameraPosition | string;
25
- /** Defaults to false - Capture images to a file and return the file path instead of returning base64 encoded data */
123
+ /**
124
+ * If true, saves the captured image to a file and returns the file path.
125
+ * If false, returns a base64 encoded string.
126
+ * @default false
127
+ */
26
128
  storeToFile?: boolean;
27
- /** Defaults to false - Android Only - Disable automatic rotation of the image, and let the browser deal with it (keep reading on how to achieve it) */
129
+ /**
130
+ * If true, prevents the plugin from rotating the image based on EXIF data.
131
+ * @platform android
132
+ * @default false
133
+ */
28
134
  disableExifHeaderStripping?: boolean;
29
- /** Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device **/
135
+ /**
136
+ * If true, enables high-resolution image capture.
137
+ * @platform ios
138
+ * @default false
139
+ */
30
140
  enableHighResolution?: boolean;
31
- /** Defaults to false - Disables audio stream to prevent permission requests and output switching */
141
+ /**
142
+ * If true, disables the audio stream, preventing audio permission requests.
143
+ * @default false
144
+ */
32
145
  disableAudio?: boolean;
33
- /** Android Only - Locks device orientation when camera is showing. */
146
+ /**
147
+ * If true, locks the device orientation while the camera is active.
148
+ * @platform android
149
+ * @default false
150
+ */
34
151
  lockAndroidOrientation?: boolean;
35
- /** Defaults to false - Android and Web only. Set if camera preview can change opacity. */
152
+ /**
153
+ * If true, allows the camera preview's opacity to be changed.
154
+ * @platform android, web
155
+ * @default false
156
+ */
36
157
  enableOpacity?: boolean;
37
- /** Defaults to false - Android only. Set if camera preview will support pinch to zoom. */
158
+ /**
159
+ * If true, enables pinch-to-zoom functionality on the preview.
160
+ * @platform android
161
+ * @default false
162
+ */
38
163
  enableZoom?: boolean;
39
- /** default to false - IOS only. Set the CameraPreview to use the video mode preset */
40
- cameraMode?: boolean;
164
+ /**
165
+ * If true, uses the video-optimized preset for the camera session.
166
+ * @platform ios
167
+ * @default false
168
+ */
169
+ enableVideoMode?: boolean;
170
+ /**
171
+ * The `deviceId` of the camera to use. If provided, `position` is ignored.
172
+ * @platform ios
173
+ */
174
+ deviceId?: string;
41
175
  }
176
+ /**
177
+ * Defines the options for capturing a picture.
178
+ */
42
179
  export interface CameraPreviewPictureOptions {
43
- /** The picture height, optional, default 0 (Device default) */
180
+ /** The desired height of the picture in pixels. If not provided, the device default is used. */
44
181
  height?: number;
45
- /** The picture width, optional, default 0 (Device default) */
182
+ /** The desired width of the picture in pixels. If not provided, the device default is used. */
46
183
  width?: number;
47
- /** The picture quality, 0 - 100, default 85 */
184
+ /**
185
+ * The quality of the captured image, from 0 to 100.
186
+ * Does not apply to `png` format.
187
+ * @default 85
188
+ */
48
189
  quality?: number;
49
- /** The picture format, jpeg or png, default jpeg on `Web`.
50
- *
51
- * quality has no effect on png */
190
+ /**
191
+ * The format of the captured image.
192
+ * @default "jpeg"
193
+ */
52
194
  format?: PictureFormat;
195
+ /**
196
+ * If true, the captured image will be saved to the user's gallery.
197
+ * @default false
198
+ * @since 7.5.0
199
+ */
200
+ saveToGallery?: boolean;
201
+ }
202
+ /** Represents EXIF data extracted from an image. */
203
+ export interface ExifData {
204
+ [key: string]: any;
53
205
  }
54
206
  export type PictureFormat = "jpeg" | "png";
207
+ /** Defines a standard picture size with width and height. */
208
+ export interface PictureSize {
209
+ /** The width of the picture in pixels. */
210
+ width: number;
211
+ /** The height of the picture in pixels. */
212
+ height: number;
213
+ }
214
+ /** Represents the supported picture sizes for a camera facing a certain direction. */
215
+ export interface SupportedPictureSizes {
216
+ /** The camera direction ("front" or "rear"). */
217
+ facing: string;
218
+ /** A list of supported picture sizes for this camera. */
219
+ supportedPictureSizes: PictureSize[];
220
+ }
221
+ /**
222
+ * Defines the options for capturing a sample frame from the camera preview.
223
+ */
55
224
  export interface CameraSampleOptions {
56
- /** The picture quality, 0 - 100, default 85 */
225
+ /**
226
+ * The quality of the captured sample, from 0 to 100.
227
+ * @default 85
228
+ */
57
229
  quality?: number;
58
230
  }
59
- export type CameraPreviewFlashMode = "off" | "on" | "auto" | "red-eye" | "torch";
231
+ /**
232
+ * The available flash modes for the camera.
233
+ * 'torch' is a continuous light mode.
234
+ */
235
+ export type CameraPreviewFlashMode = "off" | "on" | "auto" | "torch";
236
+ /**
237
+ * Defines the options for setting the camera preview's opacity.
238
+ */
60
239
  export interface CameraOpacityOptions {
61
- /** The percent opacity to set for camera view, default 1 */
240
+ /**
241
+ * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).
242
+ * @default 1.0
243
+ */
62
244
  opacity?: number;
63
245
  }
246
+ /**
247
+ * The main interface for the CameraPreview plugin.
248
+ */
64
249
  export interface CameraPreviewPlugin {
65
250
  /**
66
- * Start the camera preview instance.
67
- * @param {CameraPreviewOptions} options the options to start the camera preview with
68
- * @returns {Promise<void>} an Promise that resolves when the instance is started
69
- * @throws An error if the something went wrong
251
+ * Starts the camera preview.
252
+ *
253
+ * @param {CameraPreviewOptions} options - The configuration for the camera preview.
254
+ * @returns {Promise<void>} A promise that resolves when the camera preview is started.
70
255
  * @since 0.0.1
71
256
  */
72
257
  start(options: CameraPreviewOptions): Promise<void>;
73
258
  /**
74
- * Stop the camera preview instance.
75
- * @returns {Promise<void>} an Promise that resolves when the instance is stopped
76
- * @throws An error if the something went wrong
259
+ * Stops the camera preview.
260
+ *
261
+ * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.
77
262
  * @since 0.0.1
78
263
  */
79
264
  stop(): Promise<void>;
80
265
  /**
81
- * Switch camera.
82
- * @param {CameraPreviewOptions} options the options to switch the camera with
83
- * @returns {Promise<void>} an Promise that resolves when the camera is switched
84
- * @throws An error if the something went wrong
266
+ * Captures a picture from the camera.
267
+ *
268
+ * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.
269
+ * @returns {Promise<{ value: string }>} A promise that resolves with the captured image data.
270
+ * The `value` is a base64 encoded string unless `storeToFile` is true, in which case it's a file path.
85
271
  * @since 0.0.1
86
272
  */
87
273
  capture(options: CameraPreviewPictureOptions): Promise<{
88
274
  value: string;
275
+ exif: ExifData;
89
276
  }>;
90
277
  /**
91
- * Capture a sample image.
92
- * @param {CameraSampleOptions} options the options to capture the sample image with
93
- * @returns {Promise<string>} an Promise that resolves with the sample image as a base64 encoded string
94
- * @throws An error if the something went wrong
278
+ * Captures a single frame from the camera preview stream.
279
+ *
280
+ * @param {CameraSampleOptions} options - The options for capturing the sample.
281
+ * @returns {Promise<{ value: string }>} A promise that resolves with the sample image as a base64 encoded string.
95
282
  * @since 0.0.1
96
283
  */
97
284
  captureSample(options: CameraSampleOptions): Promise<{
98
285
  value: string;
99
286
  }>;
100
287
  /**
101
- * Get supported flash modes.
102
- * @returns {Promise<CameraPreviewFlashMode[]>} an Promise that resolves with the supported flash modes
103
- * @throws An error if the something went wrong
288
+ * Gets the flash modes supported by the active camera.
289
+ *
290
+ * @returns {Promise<{ result: CameraPreviewFlashMode[] }>} A promise that resolves with an array of supported flash modes.
104
291
  * @since 0.0.1
105
292
  */
106
293
  getSupportedFlashModes(): Promise<{
107
294
  result: CameraPreviewFlashMode[];
108
295
  }>;
109
296
  /**
110
- * Get horizontal field of view.
111
- * @returns {Promise<any>} an Promise that resolves with the horizontal field of view
112
- * @throws An error if the something went wrong
297
+ * Gets the horizontal field of view (FoV) for the active camera.
298
+ * Note: This can be an estimate on some devices.
299
+ *
300
+ * @returns {Promise<{ result: number }>} A promise that resolves with the horizontal field of view in degrees.
113
301
  * @since 0.0.1
114
302
  */
115
303
  getHorizontalFov(): Promise<{
116
- result: any;
304
+ result: number;
117
305
  }>;
118
306
  /**
119
- * Gets the supported picture sizes for a given device.
120
- * @returns {Promise<any>} an Promise that resolves with the supported picture sizes for a given device
121
- * @throws An error if the something goes wrong
307
+ * Gets the supported picture sizes for all cameras.
308
+ *
309
+ * @returns {Promise<{ supportedPictureSizes: SupportedPictureSizes[] }>} A promise that resolves with the list of supported sizes.
310
+ * @since 7.4.0
122
311
  */
123
312
  getSupportedPictureSizes(): Promise<{
124
- supportedPictureSizes: {
125
- facing: string;
126
- supportedPictureSizes: {
127
- width: number;
128
- height: number;
129
- }[];
130
- }[];
313
+ supportedPictureSizes: SupportedPictureSizes[];
131
314
  }>;
132
315
  /**
133
- * Set flash mode.
134
- * @param options the options to set the flash mode with
135
- * @returns {Promise<void>} an Promise that resolves when the flash mode is set
136
- * @throws An error if the something went wrong
316
+ * Sets the flash mode for the active camera.
317
+ *
318
+ * @param {{ flashMode: CameraPreviewFlashMode | string }} options - The desired flash mode.
319
+ * @returns {Promise<void>} A promise that resolves when the flash mode is set.
137
320
  * @since 0.0.1
138
321
  */
139
322
  setFlashMode(options: {
140
323
  flashMode: CameraPreviewFlashMode | string;
141
324
  }): Promise<void>;
142
325
  /**
143
- * Flip camera.
144
- * @returns {Promise<void>} an Promise that resolves when the camera is flipped
145
- * @throws An error if the something went wrong
326
+ * Toggles between the front and rear cameras.
327
+ *
328
+ * @returns {Promise<void>} A promise that resolves when the camera is flipped.
146
329
  * @since 0.0.1
147
330
  */
148
331
  flip(): Promise<void>;
149
332
  /**
150
- * Set opacity.
151
- * @param {CameraOpacityOptions} options the options to set the camera opacity with
152
- * @returns {Promise<void>} an Promise that resolves when the camera color effect is set
153
- * @throws An error if the something went wrong
333
+ * Sets the opacity of the camera preview.
334
+ *
335
+ * @param {CameraOpacityOptions} options - The opacity options.
336
+ * @returns {Promise<void>} A promise that resolves when the opacity is set.
154
337
  * @since 0.0.1
155
338
  */
156
339
  setOpacity(options: CameraOpacityOptions): Promise<void>;
157
340
  /**
158
- * Stop recording video.
159
- * @param {CameraPreviewOptions} options the options to stop recording video with
160
- * @returns {Promise<{videoFilePath: string}>} an Promise that resolves when the camera zoom is set
161
- * @throws An error if the something went wrong
341
+ * Stops an ongoing video recording.
342
+ *
343
+ * @returns {Promise<{ videoFilePath: string }>} A promise that resolves with the path to the recorded video file.
162
344
  * @since 0.0.1
163
345
  */
164
346
  stopRecordVideo(): Promise<{
165
347
  videoFilePath: string;
166
348
  }>;
167
349
  /**
168
- * Start recording video.
169
- * @param {CameraPreviewOptions} options the options to start recording video with
170
- * @returns {Promise<void>} an Promise that resolves when the video recording is started
171
- * @throws An error if the something went wrong
350
+ * Starts recording a video.
351
+ *
352
+ * @param {CameraPreviewOptions} options - The options for video recording.
353
+ * @returns {Promise<void>} A promise that resolves when video recording starts.
172
354
  * @since 0.0.1
173
355
  */
174
356
  startRecordVideo(options: CameraPreviewOptions): Promise<void>;
357
+ /**
358
+ * Checks if the camera preview is currently running.
359
+ *
360
+ * @returns {Promise<{ isRunning: boolean }>} A promise that resolves with the running state.
361
+ * @since 7.4.0
362
+ */
363
+ isRunning(): Promise<{
364
+ isRunning: boolean;
365
+ }>;
366
+ /**
367
+ * Gets all available camera devices.
368
+ *
369
+ * @returns {Promise<{ devices: CameraDevice[] }>} A promise that resolves with the list of available camera devices.
370
+ * @since 7.4.0
371
+ */
372
+ getAvailableDevices(): Promise<{
373
+ devices: CameraDevice[];
374
+ }>;
375
+ /**
376
+ * Gets the current zoom state, including min/max and current lens info.
377
+ *
378
+ * @returns {Promise<{ min: number; max: number; current: number; lens: LensInfo }>} A promise that resolves with the zoom state.
379
+ * @since 7.4.0
380
+ */
381
+ getZoom(): Promise<{
382
+ min: number;
383
+ max: number;
384
+ current: number;
385
+ lens: LensInfo;
386
+ }>;
387
+ /**
388
+ * Sets the camera's zoom level.
389
+ *
390
+ * @param {{ level: number; ramp?: boolean }} options - The desired zoom level. `ramp` is currently unused.
391
+ * @returns {Promise<void>} A promise that resolves when the zoom level is set.
392
+ * @since 7.4.0
393
+ */
394
+ setZoom(options: {
395
+ level: number;
396
+ ramp?: boolean;
397
+ }): Promise<void>;
398
+ /**
399
+ * Gets the current flash mode.
400
+ *
401
+ * @returns {Promise<{ flashMode: FlashMode }>} A promise that resolves with the current flash mode.
402
+ * @since 7.4.0
403
+ */
404
+ getFlashMode(): Promise<{
405
+ flashMode: FlashMode;
406
+ }>;
407
+ /**
408
+ * Removes all registered listeners.
409
+ *
410
+ * @since 7.4.0
411
+ */
412
+ removeAllListeners(): Promise<void>;
413
+ /**
414
+ * Switches the active camera to the one with the specified `deviceId`.
415
+ *
416
+ * @param {{ deviceId: string }} options - The ID of the device to switch to.
417
+ * @returns {Promise<void>} A promise that resolves when the camera is switched.
418
+ * @since 7.4.0
419
+ */
420
+ setDeviceId(options: {
421
+ deviceId: string;
422
+ }): Promise<void>;
423
+ /**
424
+ * Gets the ID of the currently active camera device.
425
+ *
426
+ * @returns {Promise<{ deviceId: string }>} A promise that resolves with the current device ID.
427
+ * @since 7.4.0
428
+ */
429
+ getDeviceId(): Promise<{
430
+ deviceId: string;
431
+ }>;
175
432
  }
@@ -1,2 +1,11 @@
1
- export {};
1
+ export var DeviceType;
2
+ (function (DeviceType) {
3
+ DeviceType["ULTRA_WIDE"] = "ultraWide";
4
+ DeviceType["WIDE_ANGLE"] = "wideAngle";
5
+ DeviceType["TELEPHOTO"] = "telephoto";
6
+ DeviceType["TRUE_DEPTH"] = "trueDepth";
7
+ DeviceType["DUAL"] = "dual";
8
+ DeviceType["DUAL_WIDE"] = "dualWide";
9
+ DeviceType["TRIPLE"] = "triple";
10
+ })(DeviceType || (DeviceType = {}));
2
11
  //# sourceMappingURL=definitions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export type CameraPosition = \"rear\" | \"front\";\nexport interface CameraPreviewOptions {\n /** Parent element to attach the video preview element to (applicable to the web platform only) */\n parent?: string;\n /** Class name to add to the video preview element (applicable to the web platform only) */\n className?: string;\n /** The preview width in pixels, default window.screen.width */\n width?: number;\n /** The preview height in pixels, default window.screen.height */\n height?: number;\n /** The x origin, default 0 (applicable to the android and ios platforms only) */\n x?: number;\n /** The y origin, default 0 (applicable to the android and ios platforms only) */\n y?: number;\n /** Whether to include safe area insets in y-position calculation, default false (applicable to the ios platform only) */\n includeSafeAreaInsets?: boolean;\n /** Brings your html in front of your preview, default false (applicable to the android only) */\n toBack?: boolean;\n /** The preview bottom padding in pixes. Useful to keep the appropriate preview sizes when orientation changes (applicable to the android and ios platforms only) */\n paddingBottom?: number;\n /** Rotate preview when orientation changes (applicable to the ios platforms only; default value is true) */\n rotateWhenOrientationChanged?: boolean;\n /** Choose the camera to use 'front' or 'rear', default 'front' */\n position?: CameraPosition | string;\n /** Defaults to false - Capture images to a file and return the file path instead of returning base64 encoded data */\n storeToFile?: boolean;\n /** Defaults to false - Android Only - Disable automatic rotation of the image, and let the browser deal with it (keep reading on how to achieve it) */\n disableExifHeaderStripping?: boolean;\n /** Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device **/\n enableHighResolution?: boolean;\n /** Defaults to false - Disables audio stream to prevent permission requests and output switching */\n disableAudio?: boolean;\n /** Android Only - Locks device orientation when camera is showing. */\n lockAndroidOrientation?: boolean;\n /** Defaults to false - Android and Web only. Set if camera preview can change opacity. */\n enableOpacity?: boolean;\n /** Defaults to false - Android only. Set if camera preview will support pinch to zoom. */\n enableZoom?: boolean;\n /** default to false - IOS only. Set the CameraPreview to use the video mode preset */\n cameraMode?: boolean;\n}\n\nexport interface CameraPreviewPictureOptions {\n /** The picture height, optional, default 0 (Device default) */\n height?: number;\n /** The picture width, optional, default 0 (Device default) */\n width?: number;\n /** The picture quality, 0 - 100, default 85 */\n quality?: number;\n /** The picture format, jpeg or png, default jpeg on `Web`.\n *\n * quality has no effect on png */\n format?: PictureFormat;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\nexport interface CameraSampleOptions {\n /** The picture quality, 0 - 100, default 85 */\n quality?: number;\n}\n\nexport type CameraPreviewFlashMode =\n | \"off\"\n | \"on\"\n | \"auto\"\n | \"red-eye\"\n | \"torch\";\n\nexport interface CameraOpacityOptions {\n /** The percent opacity to set for camera view, default 1 */\n opacity?: number;\n}\n\nexport interface CameraPreviewPlugin {\n /**\n * Start the camera preview instance.\n * @param {CameraPreviewOptions} options the options to start the camera preview with\n * @returns {Promise<void>} an Promise that resolves when the instance is started\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<void>;\n /**\n * Stop the camera preview instance.\n * @returns {Promise<void>} an Promise that resolves when the instance is stopped\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n stop(): Promise<void>;\n /**\n * Switch camera.\n * @param {CameraPreviewOptions} options the options to switch the camera with\n * @returns {Promise<void>} an Promise that resolves when the camera is switched\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n capture(options: CameraPreviewPictureOptions): Promise<{ value: string }>;\n /**\n * Capture a sample image.\n * @param {CameraSampleOptions} options the options to capture the sample image with\n * @returns {Promise<string>} an Promise that resolves with the sample image as a base64 encoded string\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n /**\n * Get supported flash modes.\n * @returns {Promise<CameraPreviewFlashMode[]>} an Promise that resolves with the supported flash modes\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n /**\n * Get horizontal field of view.\n * @returns {Promise<any>} an Promise that resolves with the horizontal field of view\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: any;\n }>;\n /**\n * Gets the supported picture sizes for a given device.\n * @returns {Promise<any>} an Promise that resolves with the supported picture sizes for a given device\n * @throws An error if the something goes wrong\n */\n getSupportedPictureSizes(): Promise<{\n supportedPictureSizes: {\n facing: string;\n supportedPictureSizes: { width: number; height: number }[];\n }[];\n }>;\n /**\n * Set flash mode.\n * @param options the options to set the flash mode with\n * @returns {Promise<void>} an Promise that resolves when the flash mode is set\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n /**\n * Flip camera.\n * @returns {Promise<void>} an Promise that resolves when the camera is flipped\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n flip(): Promise<void>;\n /**\n * Set opacity.\n * @param {CameraOpacityOptions} options the options to set the camera opacity with\n * @returns {Promise<void>} an Promise that resolves when the camera color effect is set\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n /**\n * Stop recording video.\n * @param {CameraPreviewOptions} options the options to stop recording video with\n * @returns {Promise<{videoFilePath: string}>} an Promise that resolves when the camera zoom is set\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{ videoFilePath: string }>;\n /**\n * Start recording video.\n * @param {CameraPreviewOptions} options the options to start recording video with\n * @returns {Promise<void>} an Promise that resolves when the video recording is started\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAIA,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,sCAAwB,CAAA;IACxB,sCAAwB,CAAA;IACxB,qCAAuB,CAAA;IACvB,sCAAwB,CAAA;IACxB,2BAAa,CAAA;IACb,oCAAsB,CAAA;IACtB,+BAAiB,CAAA;AACnB,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB","sourcesContent":["export type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport enum DeviceType {\n ULTRA_WIDE = \"ultraWide\",\n WIDE_ANGLE = \"wideAngle\",\n TELEPHOTO = \"telephoto\",\n TRUE_DEPTH = \"trueDepth\",\n DUAL = \"dual\",\n DUAL_WIDE = \"dualWide\",\n TRIPLE = \"triple\",\n}\n\n/**\n * Represents a single camera lens on a device. A {@link CameraDevice} can have multiple lenses.\n */\nexport interface CameraLens {\n /** A human-readable name for the lens, e.g., \"Ultra-Wide\". */\n label: string;\n /** The type of the camera lens. */\n deviceType: DeviceType;\n /** The focal length of the lens in millimeters. */\n focalLength: number;\n /** The base zoom factor for this lens (e.g., 0.5 for ultra-wide, 1.0 for wide). */\n baseZoomRatio: number;\n /** The minimum zoom factor supported by this specific lens. */\n minZoom: number;\n /** The maximum zoom factor supported by this specific lens. */\n maxZoom: number;\n}\n\n/**\n * Represents a physical camera on the device (e.g., the front-facing camera).\n */\nexport interface CameraDevice {\n /** A unique identifier for the camera device. */\n deviceId: string;\n /** A human-readable name for the camera device. */\n label: string;\n /** The physical position of the camera on the device. */\n position: CameraPosition;\n /** A list of all available lenses for this camera device. */\n lenses: CameraLens[];\n /** The overall minimum zoom factor available across all lenses on this device. */\n minZoom: number;\n /** The overall maximum zoom factor available across all lenses on this device. */\n maxZoom: number;\n /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */\n isLogical: boolean;\n}\n\n/**\n * Represents the detailed information of the currently active lens.\n */\nexport interface LensInfo {\n /** The focal length of the active lens in millimeters. */\n focalLength: number;\n /** The device type of the active lens. */\n deviceType: DeviceType;\n /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */\n baseZoomRatio: number;\n /** The current digital zoom factor applied on top of the base zoom. */\n digitalZoom: number;\n}\n\n/**\n * Defines the configuration options for starting the camera preview.\n */\nexport interface CameraPreviewOptions {\n /** \n * The parent element to attach the video preview to.\n * @platform web\n */\n parent?: string;\n /** \n * A CSS class name to add to the preview element.\n * @platform web\n */\n className?: string;\n /** \n * The width of the preview in pixels. Defaults to the screen width.\n * @platform android, ios, web\n */\n width?: number;\n /** \n * The height of the preview in pixels. Defaults to the screen height.\n * @platform android, ios, web\n */\n height?: number;\n /** \n * The horizontal origin of the preview, in pixels.\n * @platform android, ios\n */\n x?: number;\n /** \n * The vertical origin of the preview, in pixels.\n * @platform android, ios\n */\n y?: number;\n /** \n * Adjusts the y-position to account for safe areas (e.g., notches).\n * @platform ios\n * @default false\n */\n includeSafeAreaInsets?: boolean;\n /** \n * If true, places the preview behind the webview.\n * @platform android\n * @default true\n */\n toBack?: boolean;\n /** \n * Bottom padding for the preview, in pixels.\n * @platform android, ios\n */\n paddingBottom?: number;\n /** \n * Whether to rotate the preview when the device orientation changes.\n * @platform ios\n * @default true\n */\n rotateWhenOrientationChanged?: boolean;\n /** \n * The camera to use.\n * @default \"rear\"\n */\n position?: CameraPosition | string;\n /** \n * If true, saves the captured image to a file and returns the file path.\n * If false, returns a base64 encoded string.\n * @default false\n */\n storeToFile?: boolean;\n /** \n * If true, prevents the plugin from rotating the image based on EXIF data.\n * @platform android\n * @default false\n */\n disableExifHeaderStripping?: boolean;\n /** \n * If true, enables high-resolution image capture.\n * @platform ios\n * @default false\n */\n enableHighResolution?: boolean;\n /** \n * If true, disables the audio stream, preventing audio permission requests.\n * @default false\n */\n disableAudio?: boolean;\n /** \n * If true, locks the device orientation while the camera is active.\n * @platform android\n * @default false\n */\n lockAndroidOrientation?: boolean;\n /** \n * If true, allows the camera preview's opacity to be changed.\n * @platform android, web\n * @default false\n */\n enableOpacity?: boolean;\n /** \n * If true, enables pinch-to-zoom functionality on the preview.\n * @platform android\n * @default false\n */\n enableZoom?: boolean;\n /** \n * If true, uses the video-optimized preset for the camera session.\n * @platform ios\n * @default false\n */\n enableVideoMode?: boolean;\n /** \n * The `deviceId` of the camera to use. If provided, `position` is ignored.\n * @platform ios\n */\n deviceId?: string;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /** The desired height of the picture in pixels. If not provided, the device default is used. */\n height?: number;\n /** The desired width of the picture in pixels. If not provided, the device default is used. */\n width?: number;\n /** \n * The quality of the captured image, from 0 to 100.\n * Does not apply to `png` format.\n * @default 85\n */\n quality?: number;\n /** \n * The format of the captured image.\n * @default \"jpeg\"\n */\n format?: PictureFormat;\n /**\n * If true, the captured image will be saved to the user's gallery.\n * @default false\n * @since 7.5.0\n */\n saveToGallery?: boolean;\n}\n\n/** Represents EXIF data extracted from an image. */\nexport interface ExifData {\n [key: string]: any;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\n/** Defines a standard picture size with width and height. */\nexport interface PictureSize {\n /** The width of the picture in pixels. */\n width: number;\n /** The height of the picture in pixels. */\n height: number;\n}\n\n/** Represents the supported picture sizes for a camera facing a certain direction. */\nexport interface SupportedPictureSizes {\n /** The camera direction (\"front\" or \"rear\"). */\n facing: string;\n /** A list of supported picture sizes for this camera. */\n supportedPictureSizes: PictureSize[];\n}\n\n/**\n * Defines the options for capturing a sample frame from the camera preview.\n */\nexport interface CameraSampleOptions {\n /** \n * The quality of the captured sample, from 0 to 100.\n * @default 85\n */\n quality?: number;\n}\n\n/**\n * The available flash modes for the camera.\n * 'torch' is a continuous light mode.\n */\nexport type CameraPreviewFlashMode =\n | \"off\"\n | \"on\"\n | \"auto\"\n | \"torch\";\n\n/**\n * Defines the options for setting the camera preview's opacity.\n */\nexport interface CameraOpacityOptions {\n /** \n * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).\n * @default 1.0\n */\n opacity?: number;\n}\n\n/**\n * The main interface for the CameraPreview plugin.\n */\nexport interface CameraPreviewPlugin {\n /**\n * Starts the camera preview.\n *\n * @param {CameraPreviewOptions} options - The configuration for the camera preview.\n * @returns {Promise<void>} A promise that resolves when the camera preview is started.\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<void>;\n\n /**\n * Stops the camera preview.\n *\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(): Promise<void>;\n\n /**\n * Captures a picture from the camera.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string }>} A promise that resolves with the captured image data.\n * The `value` is a base64 encoded string unless `storeToFile` is true, in which case it's a file path.\n * @since 0.0.1\n */\n capture(\n options: CameraPreviewPictureOptions\n ): Promise<{ value: string; exif: ExifData }>;\n\n /**\n * Captures a single frame from the camera preview stream.\n *\n * @param {CameraSampleOptions} options - The options for capturing the sample.\n * @returns {Promise<{ value: string }>} A promise that resolves with the sample image as a base64 encoded string.\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n\n /**\n * Gets the flash modes supported by the active camera.\n *\n * @returns {Promise<{ result: CameraPreviewFlashMode[] }>} A promise that resolves with an array of supported flash modes.\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n\n /**\n * Gets the horizontal field of view (FoV) for the active camera.\n * Note: This can be an estimate on some devices.\n *\n * @returns {Promise<{ result: number }>} A promise that resolves with the horizontal field of view in degrees.\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: number;\n }>;\n\n /**\n * Gets the supported picture sizes for all cameras.\n *\n * @returns {Promise<{ supportedPictureSizes: SupportedPictureSizes[] }>} A promise that resolves with the list of supported sizes.\n * @since 7.4.0\n */\n getSupportedPictureSizes(): Promise<{\n supportedPictureSizes: SupportedPictureSizes[];\n }>;\n\n /**\n * Sets the flash mode for the active camera.\n *\n * @param {{ flashMode: CameraPreviewFlashMode | string }} options - The desired flash mode.\n * @returns {Promise<void>} A promise that resolves when the flash mode is set.\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n\n /**\n * Toggles between the front and rear cameras.\n *\n * @returns {Promise<void>} A promise that resolves when the camera is flipped.\n * @since 0.0.1\n */\n flip(): Promise<void>;\n\n /**\n * Sets the opacity of the camera preview.\n *\n * @param {CameraOpacityOptions} options - The opacity options.\n * @returns {Promise<void>} A promise that resolves when the opacity is set.\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n\n /**\n * Stops an ongoing video recording.\n *\n * @returns {Promise<{ videoFilePath: string }>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{ videoFilePath: string }>;\n\n /**\n * Starts recording a video.\n *\n * @param {CameraPreviewOptions} options - The options for video recording.\n * @returns {Promise<void>} A promise that resolves when video recording starts.\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n\n /**\n * Checks if the camera preview is currently running.\n *\n * @returns {Promise<{ isRunning: boolean }>} A promise that resolves with the running state.\n * @since 7.4.0\n */\n isRunning(): Promise<{ isRunning: boolean }>;\n\n /**\n * Gets all available camera devices.\n *\n * @returns {Promise<{ devices: CameraDevice[] }>} A promise that resolves with the list of available camera devices.\n * @since 7.4.0\n */\n getAvailableDevices(): Promise<{ devices: CameraDevice[] }>;\n\n /**\n * Gets the current zoom state, including min/max and current lens info.\n *\n * @returns {Promise<{ min: number; max: number; current: number; lens: LensInfo }>} A promise that resolves with the zoom state.\n * @since 7.4.0\n */\n getZoom(): Promise<{ \n min: number; \n max: number; \n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Sets the camera's zoom level.\n *\n * @param {{ level: number; ramp?: boolean }} options - The desired zoom level. `ramp` is currently unused.\n * @returns {Promise<void>} A promise that resolves when the zoom level is set.\n * @since 7.4.0\n */\n setZoom(options: { level: number; ramp?: boolean }): Promise<void>;\n\n /**\n * Gets the current flash mode.\n *\n * @returns {Promise<{ flashMode: FlashMode }>} A promise that resolves with the current flash mode.\n * @since 7.4.0\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.4.0\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Switches the active camera to the one with the specified `deviceId`.\n *\n * @param {{ deviceId: string }} options - The ID of the device to switch to.\n * @returns {Promise<void>} A promise that resolves when the camera is switched.\n * @since 7.4.0\n */\n setDeviceId(options: { deviceId: string }): Promise<void>;\n\n /**\n * Gets the ID of the currently active camera device.\n *\n * @returns {Promise<{ deviceId: string }>} A promise that resolves with the current device ID.\n * @since 7.4.0\n */\n getDeviceId(): Promise<{ deviceId: string }>;\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { WebPlugin } from "@capacitor/core";
2
- import type { CameraOpacityOptions, CameraPreviewFlashMode, CameraPreviewOptions, CameraPreviewPictureOptions, CameraPreviewPlugin, CameraSampleOptions } from "./definitions";
2
+ import type { CameraDevice, CameraOpacityOptions, CameraPreviewFlashMode, CameraPreviewOptions, CameraPreviewPictureOptions, CameraPreviewPlugin, CameraSampleOptions, FlashMode, LensInfo } from "./definitions";
3
3
  export declare class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
4
4
  /**
5
5
  * track which camera is used based on start options
6
6
  * used in capture
7
7
  */
8
8
  private isBackCamera;
9
+ private currentDeviceId;
9
10
  constructor();
10
11
  getSupportedPictureSizes(): Promise<any>;
11
12
  start(options: CameraPreviewOptions): Promise<void>;
@@ -26,4 +27,29 @@ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreview
26
27
  }): Promise<void>;
27
28
  flip(): Promise<void>;
28
29
  setOpacity(_options: CameraOpacityOptions): Promise<any>;
30
+ isRunning(): Promise<{
31
+ isRunning: boolean;
32
+ }>;
33
+ getAvailableDevices(): Promise<{
34
+ devices: CameraDevice[];
35
+ }>;
36
+ getZoom(): Promise<{
37
+ min: number;
38
+ max: number;
39
+ current: number;
40
+ lens: LensInfo;
41
+ }>;
42
+ setZoom(options: {
43
+ level: number;
44
+ ramp?: boolean;
45
+ }): Promise<void>;
46
+ getFlashMode(): Promise<{
47
+ flashMode: FlashMode;
48
+ }>;
49
+ getDeviceId(): Promise<{
50
+ deviceId: string;
51
+ }>;
52
+ setDeviceId(options: {
53
+ deviceId: string;
54
+ }): Promise<void>;
29
55
  }