capacitor-camera-view 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CapacitorCameraView.podspec +17 -0
  2. package/LICENSE +201 -0
  3. package/Package.swift +28 -0
  4. package/README.md +654 -0
  5. package/android/build.gradle +79 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraView.kt +555 -0
  8. package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraViewPlugin.kt +227 -0
  9. package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/BarcodeDetectionResult.kt +11 -0
  10. package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/CameraDevice.kt +14 -0
  11. package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/CameraSessionConfiguration.kt +10 -0
  12. package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/WebBoundingRect.kt +16 -0
  13. package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/ZoomFactors.kt +14 -0
  14. package/android/src/main/java/com/michaelwolz/capacitorcameraview/utils.kt +86 -0
  15. package/android/src/main/res/.gitkeep +0 -0
  16. package/dist/docs.json +968 -0
  17. package/dist/esm/definitions.d.ts +378 -0
  18. package/dist/esm/definitions.js +2 -0
  19. package/dist/esm/definitions.js.map +1 -0
  20. package/dist/esm/index.d.ts +7 -0
  21. package/dist/esm/index.js +10 -0
  22. package/dist/esm/index.js.map +1 -0
  23. package/dist/esm/utils.d.ts +45 -0
  24. package/dist/esm/utils.js +108 -0
  25. package/dist/esm/utils.js.map +1 -0
  26. package/dist/esm/web.d.ts +108 -0
  27. package/dist/esm/web.js +406 -0
  28. package/dist/esm/web.js.map +1 -0
  29. package/dist/plugin.cjs.js +530 -0
  30. package/dist/plugin.cjs.js.map +1 -0
  31. package/dist/plugin.js +533 -0
  32. package/dist/plugin.js.map +1 -0
  33. package/ios/Sources/CameraViewPlugin/CameraError.swift +39 -0
  34. package/ios/Sources/CameraViewPlugin/CameraSessionConfiguration.swift +32 -0
  35. package/ios/Sources/CameraViewPlugin/CameraViewManager+BarcodeScan.swift +91 -0
  36. package/ios/Sources/CameraViewPlugin/CameraViewManager+PhotoCapture.swift +52 -0
  37. package/ios/Sources/CameraViewPlugin/CameraViewManager+VideoDataOutput.swift +78 -0
  38. package/ios/Sources/CameraViewPlugin/CameraViewManager.swift +633 -0
  39. package/ios/Sources/CameraViewPlugin/CameraViewPlugin.swift +295 -0
  40. package/ios/Sources/CameraViewPlugin/Utils.swift +56 -0
  41. package/ios/Tests/CameraViewPluginTests/CameraViewPluginTests.swift +15 -0
  42. package/package.json +94 -0
@@ -0,0 +1,378 @@
1
+ import type { PermissionState, PluginListenerHandle } from '@capacitor/core';
2
+ /**
3
+ * Main plugin interface for Capacitor Camera View functionality.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+ export interface CameraViewPlugin {
8
+ /**
9
+ * Start the camera view with optional configuration.
10
+ *
11
+ * @param options - Configuration options for the camera session
12
+ * @returns A promise that resolves when the camera has started
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ start(options?: CameraSessionConfiguration): Promise<void>;
17
+ /**
18
+ * Stop the camera view and release resources.
19
+ *
20
+ * @returns A promise that resolves when the camera has stopped
21
+ *
22
+ * @since 1.0.0
23
+ */
24
+ stop(): Promise<void>;
25
+ /**
26
+ * Check if the camera view is currently running.
27
+ *
28
+ * @returns A promise that resolves with an object containing the running state of the camera
29
+ *
30
+ * @since 1.0.0
31
+ */
32
+ isRunning(): Promise<IsRunningResponse>;
33
+ /**
34
+ * Capture a photo using the current camera configuration.
35
+ *
36
+ * @param options - Capture configuration options
37
+ * @param options.quality - The JPEG quality of the captured photo on a scale of 0-100
38
+ * @returns A promise that resolves with an object containing a base64 encoded string of the captured photo
39
+ *
40
+ * @since 1.0.0
41
+ */
42
+ capture(options: {
43
+ quality: number;
44
+ }): Promise<CaptureResponse>;
45
+ /**
46
+ * Captures a frame from the current camera preview without using the full camera capture pipeline.
47
+ *
48
+ * Unlike `capture()` which may trigger hardware-level photo capture on native platforms,
49
+ * this method quickly samples the current video stream. This is suitable computer vision or
50
+ * simple snapshots where high fidelity is not required.
51
+ *
52
+ * On web this method does exactly the same as `capture()` as it only captures a frame from the video stream
53
+ * because unfortunately [ImageCapture API](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture) is
54
+ * not yet well supported on the web.
55
+ *
56
+ * @param options - Capture configuration options
57
+ * @param options.quality - The JPEG quality of the captured sample on a scale of 0-100
58
+ * @returns A promise that resolves with an object containing a base64 encoded string of the captured sample
59
+ *
60
+ * @since 1.0.0
61
+ */
62
+ captureSample(options: {
63
+ quality: number;
64
+ }): Promise<CaptureResponse>;
65
+ /**
66
+ * Switch between front and back camera.
67
+ *
68
+ * @returns A promise that resolves when the camera has been flipped
69
+ *
70
+ * @since 1.0.0
71
+ */
72
+ flipCamera(): Promise<void>;
73
+ /**
74
+ * Get available camera devices for capturing photos.
75
+ *
76
+ * @returns A promise that resolves with an object containing an array of available capture devices
77
+ *
78
+ * @since 1.0.0
79
+ */
80
+ getAvailableDevices(): Promise<GetAvailableDevicesResponse>;
81
+ /**
82
+ * Get current zoom level information and available range.
83
+ *
84
+ * @remarks
85
+ * Make sure the camera is properly initialized before calling this method. Otherwise, this might
86
+ * lead to returning default values on android.
87
+ *
88
+ * @returns A promise that resolves with an object containing min, max and current zoom levels
89
+ *
90
+ * @since 1.0.0
91
+ */
92
+ getZoom(): Promise<GetZoomResponse>;
93
+ /**
94
+ * Set the camera zoom level.
95
+ *
96
+ * @param options - Zoom configuration options
97
+ * @param options.level - The zoom level to set
98
+ * @param options.ramp - Whether to animate the zoom level change, defaults to false (iOS only)
99
+ * @returns A promise that resolves when the zoom level has been set
100
+ *
101
+ * @remarks
102
+ * On web platforms, zoom functionality may be limited by browser support.
103
+ * When native zoom is not available, a CSS-based zoom simulation is applied.
104
+ *
105
+ * @since 1.0.0
106
+ */
107
+ setZoom(options: {
108
+ level: number;
109
+ ramp?: boolean;
110
+ }): Promise<void>;
111
+ /**
112
+ * Get current flash mode setting.
113
+ *
114
+ * @returns A promise that resolves with an object containing the current flash mode
115
+ *
116
+ * @since 1.0.0
117
+ */
118
+ getFlashMode(): Promise<GetFlashModeResponse>;
119
+ /**
120
+ * Get supported flash modes for the current camera.
121
+ *
122
+ * @returns A promise that resolves with an object containing an array of supported flash modes
123
+ *
124
+ * @since 1.0.0
125
+ */
126
+ getSupportedFlashModes(): Promise<GetSupportedFlashModesResponse>;
127
+ /**
128
+ * Set the camera flash mode.
129
+ *
130
+ * @param options - Flash mode configuration options
131
+ * @param options.mode - The flash mode to set
132
+ * @returns A promise that resolves when the flash mode has been set
133
+ *
134
+ * @since 1.0.0
135
+ */
136
+ setFlashMode(options: {
137
+ mode: FlashMode;
138
+ }): Promise<void>;
139
+ /**
140
+ * Check camera permission status without requesting permissions.
141
+ *
142
+ * @returns A promise that resolves with an object containing the camera permission status
143
+ *
144
+ * @since 1.0.0
145
+ */
146
+ checkPermissions(): Promise<PermissionStatus>;
147
+ /**
148
+ * Request camera permission from the user.
149
+ *
150
+ * @returns A promise that resolves with an object containing the camera permission status
151
+ *
152
+ * @since 1.0.0
153
+ */
154
+ requestPermissions(): Promise<PermissionStatus>;
155
+ /**
156
+ * Listen for barcode detection events.
157
+ * This event is emitted when a barcode is detected in the camera preview.
158
+ *
159
+ * @param eventName - The name of the event to listen for ('barcodeDetected')
160
+ * @param listenerFunc - The callback function to execute when a barcode is detected
161
+ * @returns A promise that resolves with an event subscription
162
+ *
163
+ * @since 1.0.0
164
+ */
165
+ addListener(eventName: 'barcodeDetected', listenerFunc: (data: BarcodeDetectionData) => void): Promise<PluginListenerHandle>;
166
+ /**
167
+ * Remove all listeners for this plugin.
168
+ *
169
+ * @param eventName - Optional event name to remove listeners for
170
+ * @returns A promise that resolves when the listeners are removed
171
+ *
172
+ * @since 1.0.0
173
+ */
174
+ removeAllListeners(eventName?: string): Promise<void>;
175
+ }
176
+ /**
177
+ * Position options for the camera.
178
+ * - 'front': Front-facing camera
179
+ * - 'back': Rear-facing camera
180
+ *
181
+ * @since 1.0.0
182
+ */
183
+ export declare type CameraPosition = 'front' | 'back';
184
+ /**
185
+ * Flash mode options for the camera.
186
+ * - 'off': Flash disabled
187
+ * - 'on': Flash always on
188
+ * - 'auto': Flash automatically enabled in low-light conditions
189
+ *
190
+ * @since 1.0.0
191
+ */
192
+ export declare type FlashMode = 'off' | 'on' | 'auto';
193
+ /**
194
+ * Represents a physical camera device on the device.
195
+ *
196
+ * @since 1.0.0
197
+ */
198
+ export interface CameraDevice {
199
+ /** The unique identifier of the camera device */
200
+ id: string;
201
+ /** The human-readable name of the camera device */
202
+ name: string;
203
+ /** The position of the camera device (front or back) */
204
+ position: CameraPosition;
205
+ /** The type of the camera device (e.g., wide, ultra-wide, telephoto) - iOS only */
206
+ deviceType?: CameraDeviceType;
207
+ }
208
+ /**
209
+ * Available camera device types for iOS.
210
+ * Maps to AVCaptureDevice DeviceTypes in iOS.
211
+ *
212
+ * @see https://developer.apple.com/documentation/avfoundation/avcapturedevice/devicetype-swift.struct
213
+ *
214
+ * @since 1.0.0
215
+ */
216
+ export declare type CameraDeviceType =
217
+ /** builtInWideAngleCamera - standard camera */
218
+ 'wideAngle'
219
+ /** builtInUltraWideCamera - 0.5x zoom level */
220
+ | 'ultraWide'
221
+ /** builtInTelephotoCamera - 2x/3x zoom level */
222
+ | 'telephoto'
223
+ /** builtInDualCamera - wide + telephoto combination */
224
+ | 'dual'
225
+ /** builtInDualWideCamera - wide + ultraWide combination */
226
+ | 'dualWide'
227
+ /** builtInTripleCamera - wide + ultraWide + telephoto */
228
+ | 'triple'
229
+ /** builtInTrueDepthCamera - front-facing camera with depth sensing */
230
+ | 'trueDepth';
231
+ /**
232
+ * Configuration options for starting a camera session.
233
+ *
234
+ * @since 1.0.0
235
+ */
236
+ export interface CameraSessionConfiguration {
237
+ /**
238
+ * Enables the barcode detection functionality
239
+ * @default false
240
+ */
241
+ enableBarcodeDetection?: boolean;
242
+ /**
243
+ * Position of the camera to use
244
+ * @default 'back'
245
+ */
246
+ position?: CameraPosition;
247
+ /**
248
+ * Specific device ID of the camera to use
249
+ * If provided, takes precedence over position
250
+ */
251
+ deviceId?: string;
252
+ /**
253
+ * Whether to use the triple camera if available (iPhone Pro models only)
254
+ * @default false
255
+ */
256
+ useTripleCameraIfAvailable?: boolean;
257
+ /**
258
+ * Ordered list of preferred camera device types to use (iOS only).
259
+ * The system will attempt to use the first available camera type in the list.
260
+ * If position is also provided, the system will use the first available camera type
261
+ * that matches the position and is in the list.
262
+ *
263
+ * This will fallback to the default camera type if none of the preferred types are available.
264
+ *
265
+ * @example [CameraDeviceType.WideAngle, CameraDeviceType.UltraWide, CameraDeviceType.Telephoto]
266
+ * @default undefined - system will decide based on position/deviceId
267
+ */
268
+ preferredCameraDeviceTypes?: CameraDeviceType[];
269
+ /**
270
+ * The initial zoom factor to use
271
+ * @default 1.0
272
+ */
273
+ zoomFactor?: number;
274
+ /**
275
+ * Optional HTML ID of the container element where the camera view should be rendered.
276
+ * If not provided, the camera view will be appended to the document body. Web only.
277
+ * @example 'cameraContainer'
278
+ */
279
+ containerElementId?: string;
280
+ }
281
+ /**
282
+ * Response for checking if the camera view is running.
283
+ *
284
+ * @since 1.0.0
285
+ */
286
+ export interface IsRunningResponse {
287
+ /** Indicates if the camera view is currently active and running */
288
+ isRunning: boolean;
289
+ }
290
+ /**
291
+ * Response for capturing a photo.
292
+ *
293
+ * @since 1.0.0
294
+ */
295
+ export interface CaptureResponse {
296
+ /** The base64 encoded string of the captured photo */
297
+ photo: string;
298
+ }
299
+ /**
300
+ * Response for getting available camera devices.
301
+ *
302
+ * @since 1.0.0
303
+ */
304
+ export interface GetAvailableDevicesResponse {
305
+ /** An array of available camera devices */
306
+ devices: CameraDevice[];
307
+ }
308
+ /**
309
+ * Response for getting zoom level information.
310
+ *
311
+ * @since 1.0.0
312
+ */
313
+ export interface GetZoomResponse {
314
+ /** The minimum zoom level supported */
315
+ min: number;
316
+ /** The maximum zoom level supported */
317
+ max: number;
318
+ /** The current zoom level */
319
+ current: number;
320
+ }
321
+ /**
322
+ * Response for getting the current flash mode.
323
+ *
324
+ * @since 1.0.0
325
+ */
326
+ export interface GetFlashModeResponse {
327
+ /** The current flash mode setting */
328
+ flashMode: FlashMode;
329
+ }
330
+ /**
331
+ * Response for getting supported flash modes.
332
+ *
333
+ * @since 1.0.0
334
+ */
335
+ export interface GetSupportedFlashModesResponse {
336
+ /** An array of flash modes supported by the current camera */
337
+ flashModes: FlashMode[];
338
+ }
339
+ /**
340
+ * Data for a detected barcode.
341
+ *
342
+ * @since 1.0.0
343
+ */
344
+ export interface BarcodeDetectionData {
345
+ /** The decoded string value of the barcode */
346
+ value: string;
347
+ /** The display value of the barcode (may differ from the raw value) */
348
+ displayValue?: string;
349
+ /** The type/format of the barcode (e.g., 'qr', 'code128', etc.) */
350
+ type: string;
351
+ /** The bounding rectangle of the barcode in the camera frame. */
352
+ boundingRect: BoundingRect;
353
+ }
354
+ /**
355
+ * Rectangle defining the boundary of the barcode in the camera frame.
356
+ * Coordinates are normalized between 0 and 1 relative to the camera frame.
357
+ *
358
+ * @since 1.0.0
359
+ */
360
+ export interface BoundingRect {
361
+ /** X-coordinate of the top-left corner */
362
+ x: number;
363
+ /** Y-coordinate of the top-left corner */
364
+ y: number;
365
+ /** Width of the bounding rectangle (should match the actual width of the barcode) */
366
+ width: number;
367
+ /** Height of the bounding rectangle (should match the actual height of the barcode) */
368
+ height: number;
369
+ }
370
+ /**
371
+ * Response for the camera permission status.
372
+ *
373
+ * @since 1.0.0
374
+ */
375
+ export interface PermissionStatus {
376
+ /** The state of the camera permission */
377
+ camera: PermissionState;
378
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionState, PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Main plugin interface for Capacitor Camera View functionality.\n *\n * @since 1.0.0\n */\nexport interface CameraViewPlugin {\n /**\n * Start the camera view with optional configuration.\n *\n * @param options - Configuration options for the camera session\n * @returns A promise that resolves when the camera has started\n *\n * @since 1.0.0\n */\n start(options?: CameraSessionConfiguration): Promise<void>;\n\n /**\n * Stop the camera view and release resources.\n *\n * @returns A promise that resolves when the camera has stopped\n *\n * @since 1.0.0\n */\n stop(): Promise<void>;\n\n /**\n * Check if the camera view is currently running.\n *\n * @returns A promise that resolves with an object containing the running state of the camera\n *\n * @since 1.0.0\n */\n isRunning(): Promise<IsRunningResponse>;\n\n /**\n * Capture a photo using the current camera configuration.\n *\n * @param options - Capture configuration options\n * @param options.quality - The JPEG quality of the captured photo on a scale of 0-100\n * @returns A promise that resolves with an object containing a base64 encoded string of the captured photo\n *\n * @since 1.0.0\n */\n capture(options: { quality: number }): Promise<CaptureResponse>;\n\n /**\n * Captures a frame from the current camera preview without using the full camera capture pipeline.\n *\n * Unlike `capture()` which may trigger hardware-level photo capture on native platforms,\n * this method quickly samples the current video stream. This is suitable computer vision or\n * simple snapshots where high fidelity is not required.\n *\n * On web this method does exactly the same as `capture()` as it only captures a frame from the video stream\n * because unfortunately [ImageCapture API](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture) is\n * not yet well supported on the web.\n *\n * @param options - Capture configuration options\n * @param options.quality - The JPEG quality of the captured sample on a scale of 0-100\n * @returns A promise that resolves with an object containing a base64 encoded string of the captured sample\n *\n * @since 1.0.0\n */\n captureSample(options: { quality: number }): Promise<CaptureResponse>;\n\n /**\n * Switch between front and back camera.\n *\n * @returns A promise that resolves when the camera has been flipped\n *\n * @since 1.0.0\n */\n flipCamera(): Promise<void>;\n\n /**\n * Get available camera devices for capturing photos.\n *\n * @returns A promise that resolves with an object containing an array of available capture devices\n *\n * @since 1.0.0\n */\n getAvailableDevices(): Promise<GetAvailableDevicesResponse>;\n\n /**\n * Get current zoom level information and available range.\n *\n * @remarks\n * Make sure the camera is properly initialized before calling this method. Otherwise, this might\n * lead to returning default values on android.\n *\n * @returns A promise that resolves with an object containing min, max and current zoom levels\n *\n * @since 1.0.0\n */\n getZoom(): Promise<GetZoomResponse>;\n\n /**\n * Set the camera zoom level.\n *\n * @param options - Zoom configuration options\n * @param options.level - The zoom level to set\n * @param options.ramp - Whether to animate the zoom level change, defaults to false (iOS only)\n * @returns A promise that resolves when the zoom level has been set\n *\n * @remarks\n * On web platforms, zoom functionality may be limited by browser support.\n * When native zoom is not available, a CSS-based zoom simulation is applied.\n *\n * @since 1.0.0\n */\n setZoom(options: { level: number; ramp?: boolean }): Promise<void>;\n\n /**\n * Get current flash mode setting.\n *\n * @returns A promise that resolves with an object containing the current flash mode\n *\n * @since 1.0.0\n */\n getFlashMode(): Promise<GetFlashModeResponse>;\n\n /**\n * Get supported flash modes for the current camera.\n *\n * @returns A promise that resolves with an object containing an array of supported flash modes\n *\n * @since 1.0.0\n */\n getSupportedFlashModes(): Promise<GetSupportedFlashModesResponse>;\n\n /**\n * Set the camera flash mode.\n *\n * @param options - Flash mode configuration options\n * @param options.mode - The flash mode to set\n * @returns A promise that resolves when the flash mode has been set\n *\n * @since 1.0.0\n */\n setFlashMode(options: { mode: FlashMode }): Promise<void>;\n\n /**\n * Check camera permission status without requesting permissions.\n *\n * @returns A promise that resolves with an object containing the camera permission status\n *\n * @since 1.0.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request camera permission from the user.\n *\n * @returns A promise that resolves with an object containing the camera permission status\n *\n * @since 1.0.0\n */\n requestPermissions(): Promise<PermissionStatus>;\n\n /**\n * Listen for barcode detection events.\n * This event is emitted when a barcode is detected in the camera preview.\n *\n * @param eventName - The name of the event to listen for ('barcodeDetected')\n * @param listenerFunc - The callback function to execute when a barcode is detected\n * @returns A promise that resolves with an event subscription\n *\n * @since 1.0.0\n */\n addListener(\n eventName: 'barcodeDetected',\n listenerFunc: (data: BarcodeDetectionData) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Remove all listeners for this plugin.\n *\n * @param eventName - Optional event name to remove listeners for\n * @returns A promise that resolves when the listeners are removed\n *\n * @since 1.0.0\n */\n removeAllListeners(eventName?: string): Promise<void>;\n}\n\n// ------------------------------------------------------------------------------\n// Camera Configuration Types\n// ------------------------------------------------------------------------------\n\n/**\n * Position options for the camera.\n * - 'front': Front-facing camera\n * - 'back': Rear-facing camera\n *\n * @since 1.0.0\n */\nexport type CameraPosition = 'front' | 'back';\n\n/**\n * Flash mode options for the camera.\n * - 'off': Flash disabled\n * - 'on': Flash always on\n * - 'auto': Flash automatically enabled in low-light conditions\n *\n * @since 1.0.0\n */\nexport type FlashMode = 'off' | 'on' | 'auto';\n\n/**\n * Represents a physical camera device on the device.\n *\n * @since 1.0.0\n */\nexport interface CameraDevice {\n /** The unique identifier of the camera device */\n id: string;\n\n /** The human-readable name of the camera device */\n name: string;\n\n /** The position of the camera device (front or back) */\n position: CameraPosition;\n\n /** The type of the camera device (e.g., wide, ultra-wide, telephoto) - iOS only */\n deviceType?: CameraDeviceType;\n}\n\n/**\n * Available camera device types for iOS.\n * Maps to AVCaptureDevice DeviceTypes in iOS.\n *\n * @see https://developer.apple.com/documentation/avfoundation/avcapturedevice/devicetype-swift.struct\n *\n * @since 1.0.0\n */\nexport type CameraDeviceType =\n /** builtInWideAngleCamera - standard camera */\n | 'wideAngle'\n /** builtInUltraWideCamera - 0.5x zoom level */\n | 'ultraWide'\n /** builtInTelephotoCamera - 2x/3x zoom level */\n | 'telephoto'\n /** builtInDualCamera - wide + telephoto combination */\n | 'dual'\n /** builtInDualWideCamera - wide + ultraWide combination */\n | 'dualWide'\n /** builtInTripleCamera - wide + ultraWide + telephoto */\n | 'triple'\n /** builtInTrueDepthCamera - front-facing camera with depth sensing */\n | 'trueDepth';\n\n/**\n * Configuration options for starting a camera session.\n *\n * @since 1.0.0\n */\nexport interface CameraSessionConfiguration {\n /**\n * Enables the barcode detection functionality\n * @default false\n */\n enableBarcodeDetection?: boolean;\n\n /**\n * Position of the camera to use\n * @default 'back'\n */\n position?: CameraPosition;\n\n /**\n * Specific device ID of the camera to use\n * If provided, takes precedence over position\n */\n deviceId?: string;\n\n /**\n * Whether to use the triple camera if available (iPhone Pro models only)\n * @default false\n */\n useTripleCameraIfAvailable?: boolean;\n\n /**\n * Ordered list of preferred camera device types to use (iOS only).\n * The system will attempt to use the first available camera type in the list.\n * If position is also provided, the system will use the first available camera type\n * that matches the position and is in the list.\n *\n * This will fallback to the default camera type if none of the preferred types are available.\n *\n * @example [CameraDeviceType.WideAngle, CameraDeviceType.UltraWide, CameraDeviceType.Telephoto]\n * @default undefined - system will decide based on position/deviceId\n */\n preferredCameraDeviceTypes?: CameraDeviceType[];\n\n /**\n * The initial zoom factor to use\n * @default 1.0\n */\n zoomFactor?: number;\n\n /**\n * Optional HTML ID of the container element where the camera view should be rendered.\n * If not provided, the camera view will be appended to the document body. Web only.\n * @example 'cameraContainer'\n */\n containerElementId?: string;\n}\n\n// ------------------------------------------------------------------------------\n// Response Interfaces\n// ------------------------------------------------------------------------------\n\n/**\n * Response for checking if the camera view is running.\n *\n * @since 1.0.0\n */\nexport interface IsRunningResponse {\n /** Indicates if the camera view is currently active and running */\n isRunning: boolean;\n}\n\n/**\n * Response for capturing a photo.\n *\n * @since 1.0.0\n */\nexport interface CaptureResponse {\n /** The base64 encoded string of the captured photo */\n photo: string;\n}\n\n/**\n * Response for getting available camera devices.\n *\n * @since 1.0.0\n */\nexport interface GetAvailableDevicesResponse {\n /** An array of available camera devices */\n devices: CameraDevice[];\n}\n\n/**\n * Response for getting zoom level information.\n *\n * @since 1.0.0\n */\nexport interface GetZoomResponse {\n /** The minimum zoom level supported */\n min: number;\n\n /** The maximum zoom level supported */\n max: number;\n\n /** The current zoom level */\n current: number;\n}\n\n/**\n * Response for getting the current flash mode.\n *\n * @since 1.0.0\n */\nexport interface GetFlashModeResponse {\n /** The current flash mode setting */\n flashMode: FlashMode;\n}\n\n/**\n * Response for getting supported flash modes.\n *\n * @since 1.0.0\n */\nexport interface GetSupportedFlashModesResponse {\n /** An array of flash modes supported by the current camera */\n flashModes: FlashMode[];\n}\n\n/**\n * Data for a detected barcode.\n *\n * @since 1.0.0\n */\nexport interface BarcodeDetectionData {\n /** The decoded string value of the barcode */\n value: string;\n\n /** The display value of the barcode (may differ from the raw value) */\n displayValue?: string;\n\n /** The type/format of the barcode (e.g., 'qr', 'code128', etc.) */\n type: string;\n\n /** The bounding rectangle of the barcode in the camera frame. */\n boundingRect: BoundingRect;\n}\n\n/**\n * Rectangle defining the boundary of the barcode in the camera frame.\n * Coordinates are normalized between 0 and 1 relative to the camera frame.\n *\n * @since 1.0.0\n */\nexport interface BoundingRect {\n /** X-coordinate of the top-left corner */\n x: number;\n /** Y-coordinate of the top-left corner */\n y: number;\n /** Width of the bounding rectangle (should match the actual width of the barcode) */\n width: number;\n /** Height of the bounding rectangle (should match the actual height of the barcode) */\n height: number;\n}\n\n/**\n * Response for the camera permission status.\n *\n * @since 1.0.0\n */\nexport interface PermissionStatus {\n /** The state of the camera permission */\n camera: PermissionState;\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import type { CameraViewPlugin } from './definitions';
2
+ /**
3
+ * The main Capacitor Camera View plugin instance.
4
+ */
5
+ declare const CameraView: CameraViewPlugin;
6
+ export * from './definitions';
7
+ export { CameraView };
@@ -0,0 +1,10 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ /**
3
+ * The main Capacitor Camera View plugin instance.
4
+ */
5
+ const CameraView = registerPlugin('CameraView', {
6
+ web: () => import('./web').then((m) => new m.CameraViewWeb()),
7
+ });
8
+ export * from './definitions';
9
+ export { CameraView };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD;;GAEG;AACH,MAAM,UAAU,GAAG,cAAc,CAAmB,YAAY,EAAE;IAChE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { CameraViewPlugin } from './definitions';\n\n/**\n * The main Capacitor Camera View plugin instance.\n */\nconst CameraView = registerPlugin<CameraViewPlugin>('CameraView', {\n web: () => import('./web').then((m) => new m.CameraViewWeb()),\n});\n\nexport * from './definitions';\nexport { CameraView };\n"]}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Converts canvas to base64 string
3
+ */
4
+ export declare function canvasToBase64(canvas: HTMLCanvasElement, quality: number): string;
5
+ /**
6
+ * Calculates the visible area of the video based on object-fit: cover
7
+ */
8
+ export declare function calculateVisibleArea(video: HTMLVideoElement): {
9
+ sourceX: number;
10
+ sourceY: number;
11
+ sourceWidth: number;
12
+ sourceHeight: number;
13
+ displayWidth: number;
14
+ displayHeight: number;
15
+ };
16
+ /**
17
+ * Draws the visible area of the video to the canvas
18
+ */
19
+ export declare function drawVisibleAreaToCanvas(canvas: HTMLCanvasElement, videoElement: HTMLVideoElement, area: {
20
+ sourceX: number;
21
+ sourceY: number;
22
+ sourceWidth: number;
23
+ sourceHeight: number;
24
+ displayWidth: number;
25
+ displayHeight: number;
26
+ }): void;
27
+ /**
28
+ * Transforms barcode coordinates from the video source space to display space
29
+ * accounting for object-fit: cover scaling and cropping.
30
+ *
31
+ * @param barcodeBoundingBox The original barcode bounding box from the detector
32
+ * @param videoElement The video element with the camera stream
33
+ * @returns The transformed bounding box coordinates in display space
34
+ */
35
+ export declare function transformBarcodeBoundingBox(barcodeBoundingBox: {
36
+ x: number;
37
+ y: number;
38
+ width: number;
39
+ height: number;
40
+ }, videoElement: HTMLVideoElement): {
41
+ x: number;
42
+ y: number;
43
+ width: number;
44
+ height: number;
45
+ };
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Converts canvas to base64 string
3
+ */
4
+ export function canvasToBase64(canvas, quality) {
5
+ const dataUrl = canvas.toDataURL('image/jpeg', quality);
6
+ return dataUrl.split(',')[1];
7
+ }
8
+ /**
9
+ * Calculates the visible area of the video based on object-fit: cover
10
+ */
11
+ export function calculateVisibleArea(video) {
12
+ // Get the displayed dimensions of the video element
13
+ const videoRect = video.getBoundingClientRect();
14
+ const displayWidth = videoRect.width;
15
+ const displayHeight = videoRect.height;
16
+ // Get the intrinsic dimensions of the video
17
+ const videoWidth = video.videoWidth;
18
+ const videoHeight = video.videoHeight;
19
+ // Calculate which portion of the video is visible (for object-fit: cover)
20
+ const videoAspect = videoWidth / videoHeight;
21
+ const displayAspect = displayWidth / displayHeight;
22
+ let sourceX = 0;
23
+ let sourceY = 0;
24
+ let sourceWidth = videoWidth;
25
+ let sourceHeight = videoHeight;
26
+ // If video aspect ratio is greater than display aspect ratio,
27
+ // the video is cropped on the sides
28
+ if (videoAspect > displayAspect) {
29
+ sourceWidth = videoHeight * displayAspect;
30
+ sourceX = (videoWidth - sourceWidth) / 2;
31
+ }
32
+ // Otherwise the video is cropped on the top and bottom
33
+ else {
34
+ sourceHeight = videoWidth / displayAspect;
35
+ sourceY = (videoHeight - sourceHeight) / 2;
36
+ }
37
+ return {
38
+ sourceX,
39
+ sourceY,
40
+ sourceWidth,
41
+ sourceHeight,
42
+ displayWidth,
43
+ displayHeight,
44
+ };
45
+ }
46
+ /**
47
+ * Draws the visible area of the video to the canvas
48
+ */
49
+ export function drawVisibleAreaToCanvas(canvas, videoElement, area) {
50
+ const { sourceX, sourceY, sourceWidth, sourceHeight, displayWidth, displayHeight } = area;
51
+ // Set canvas size to match the displayed dimensions
52
+ canvas.width = displayWidth;
53
+ canvas.height = displayHeight;
54
+ const ctx = canvas.getContext('2d', { alpha: false });
55
+ if (!ctx) {
56
+ throw new Error('Could not get canvas context');
57
+ }
58
+ // Draw only the visible portion of the video to match what the user sees
59
+ ctx.drawImage(videoElement, sourceX, sourceY, sourceWidth, sourceHeight, 0, 0, displayWidth, displayHeight);
60
+ }
61
+ /**
62
+ * Transforms barcode coordinates from the video source space to display space
63
+ * accounting for object-fit: cover scaling and cropping.
64
+ *
65
+ * @param barcodeBoundingBox The original barcode bounding box from the detector
66
+ * @param videoElement The video element with the camera stream
67
+ * @returns The transformed bounding box coordinates in display space
68
+ */
69
+ export function transformBarcodeBoundingBox(barcodeBoundingBox, videoElement) {
70
+ // Get the video element's displayed dimensions
71
+ const videoRect = videoElement.getBoundingClientRect();
72
+ const displayWidth = videoRect.width;
73
+ const displayHeight = videoRect.height;
74
+ // Get original video dimensions
75
+ const videoWidth = videoElement.videoWidth;
76
+ const videoHeight = videoElement.videoHeight;
77
+ // Calculate scaling and positioning for object-fit: cover
78
+ const videoAspect = videoWidth / videoHeight;
79
+ const displayAspect = displayWidth / displayHeight;
80
+ let scaledX, scaledY, scaledWidth, scaledHeight;
81
+ if (videoAspect > displayAspect) {
82
+ // Video is wider than display area - height matches, width is centered and cropped
83
+ const scale = displayHeight / videoHeight;
84
+ const scaledVideoWidth = videoWidth * scale;
85
+ const cropX = (scaledVideoWidth - displayWidth) / 2;
86
+ scaledWidth = barcodeBoundingBox.width * scale;
87
+ scaledHeight = barcodeBoundingBox.height * scale;
88
+ scaledX = barcodeBoundingBox.x * scale - cropX;
89
+ scaledY = barcodeBoundingBox.y * scale;
90
+ }
91
+ else {
92
+ // Video is taller than display area - width matches, height is centered and cropped
93
+ const scale = displayWidth / videoWidth;
94
+ const scaledVideoHeight = videoHeight * scale;
95
+ const cropY = (scaledVideoHeight - displayHeight) / 2;
96
+ scaledWidth = barcodeBoundingBox.width * scale;
97
+ scaledHeight = barcodeBoundingBox.height * scale;
98
+ scaledX = barcodeBoundingBox.x * scale;
99
+ scaledY = barcodeBoundingBox.y * scale - cropY;
100
+ }
101
+ return {
102
+ x: scaledX,
103
+ y: scaledY,
104
+ width: scaledWidth,
105
+ height: scaledHeight,
106
+ };
107
+ }
108
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAyB,EAAE,OAAe;IACvE,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACxD,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAuB;IAQ1D,oDAAoD;IACpD,MAAM,SAAS,GAAG,KAAK,CAAC,qBAAqB,EAAE,CAAC;IAChD,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC;IACrC,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC;IAEvC,4CAA4C;IAC5C,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;IACpC,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;IAEtC,0EAA0E;IAC1E,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;IAC7C,MAAM,aAAa,GAAG,YAAY,GAAG,aAAa,CAAC;IAEnD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,WAAW,GAAG,UAAU,CAAC;IAC7B,IAAI,YAAY,GAAG,WAAW,CAAC;IAE/B,8DAA8D;IAC9D,oCAAoC;IACpC,IAAI,WAAW,GAAG,aAAa,EAAE;QAC/B,WAAW,GAAG,WAAW,GAAG,aAAa,CAAC;QAC1C,OAAO,GAAG,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;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Content":["/**\n * Converts canvas to base64 string\n */\nexport function canvasToBase64(canvas: HTMLCanvasElement, quality: number): string {\n const dataUrl = canvas.toDataURL('image/jpeg', quality);\n return dataUrl.split(',')[1];\n}\n\n/**\n * Calculates the visible area of the video based on object-fit: cover\n */\nexport function calculateVisibleArea(video: HTMLVideoElement): {\n sourceX: number;\n sourceY: number;\n sourceWidth: number;\n sourceHeight: number;\n displayWidth: number;\n displayHeight: number;\n} {\n // Get the displayed dimensions of the video element\n const videoRect = video.getBoundingClientRect();\n const displayWidth = videoRect.width;\n const displayHeight = videoRect.height;\n\n // Get the intrinsic dimensions of the video\n const videoWidth = video.videoWidth;\n const videoHeight = video.videoHeight;\n\n // Calculate which portion of the video is visible (for object-fit: cover)\n const videoAspect = videoWidth / videoHeight;\n const displayAspect = displayWidth / displayHeight;\n\n let sourceX = 0;\n let sourceY = 0;\n let sourceWidth = videoWidth;\n let sourceHeight = videoHeight;\n\n // If video aspect ratio is greater than display aspect ratio,\n // the video is cropped on the sides\n if (videoAspect > displayAspect) {\n sourceWidth = videoHeight * displayAspect;\n sourceX = (videoWidth - sourceWidth) / 2;\n }\n // Otherwise the video is cropped on the top and bottom\n else {\n sourceHeight = videoWidth / displayAspect;\n sourceY = (videoHeight - sourceHeight) / 2;\n }\n\n return {\n sourceX,\n sourceY,\n sourceWidth,\n sourceHeight,\n displayWidth,\n displayHeight,\n };\n}\n\n/**\n * Draws the visible area of the video to the canvas\n */\nexport function drawVisibleAreaToCanvas(\n canvas: HTMLCanvasElement,\n videoElement: HTMLVideoElement,\n area: {\n sourceX: number;\n sourceY: number;\n sourceWidth: number;\n sourceHeight: number;\n displayWidth: number;\n displayHeight: number;\n },\n): void {\n const { sourceX, sourceY, sourceWidth, sourceHeight, displayWidth, displayHeight } = area;\n\n // Set canvas size to match the displayed dimensions\n canvas.width = displayWidth;\n canvas.height = displayHeight;\n\n const ctx = canvas.getContext('2d', { alpha: false });\n if (!ctx) {\n throw new Error('Could not get canvas context');\n }\n\n // Draw only the visible portion of the video to match what the user sees\n ctx.drawImage(videoElement, sourceX, sourceY, sourceWidth, sourceHeight, 0, 0, displayWidth, displayHeight);\n}\n\n/**\n * Transforms barcode coordinates from the video source space to display space\n * accounting for object-fit: cover scaling and cropping.\n *\n * @param barcodeBoundingBox The original barcode bounding box from the detector\n * @param videoElement The video element with the camera stream\n * @returns The transformed bounding box coordinates in display space\n */\nexport function transformBarcodeBoundingBox(\n barcodeBoundingBox: {\n x: number;\n y: number;\n width: number;\n height: number;\n },\n videoElement: HTMLVideoElement,\n): {\n x: number;\n y: number;\n width: number;\n height: number;\n} {\n // Get the video element's displayed dimensions\n const videoRect = videoElement.getBoundingClientRect();\n const displayWidth = videoRect.width;\n const displayHeight = videoRect.height;\n\n // Get original video dimensions\n const videoWidth = videoElement.videoWidth;\n const videoHeight = videoElement.videoHeight;\n\n // Calculate scaling and positioning for object-fit: cover\n const videoAspect = videoWidth / videoHeight;\n const displayAspect = displayWidth / displayHeight;\n\n let scaledX, scaledY, scaledWidth, scaledHeight;\n\n if (videoAspect > displayAspect) {\n // Video is wider than display area - height matches, width is centered and cropped\n const scale = displayHeight / videoHeight;\n const scaledVideoWidth = videoWidth * scale;\n const cropX = (scaledVideoWidth - displayWidth) / 2;\n\n scaledWidth = barcodeBoundingBox.width * scale;\n scaledHeight = barcodeBoundingBox.height * scale;\n scaledX = barcodeBoundingBox.x * scale - cropX;\n scaledY = barcodeBoundingBox.y * scale;\n } else {\n // Video is taller than display area - width matches, height is centered and cropped\n const scale = displayWidth / videoWidth;\n const scaledVideoHeight = videoHeight * scale;\n const cropY = (scaledVideoHeight - displayHeight) / 2;\n\n scaledWidth = barcodeBoundingBox.width * scale;\n scaledHeight = barcodeBoundingBox.height * scale;\n scaledX = barcodeBoundingBox.x * scale;\n scaledY = barcodeBoundingBox.y * scale - cropY;\n }\n\n return {\n x: scaledX,\n y: scaledY,\n width: scaledWidth,\n height: scaledHeight,\n };\n}\n"]}