capacitor-community-multilens-camerapreview 0.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.
Files changed (37) hide show
  1. package/CapacitorCommunityMultilensCamerapreview.podspec +17 -0
  2. package/README.md +210 -0
  3. package/android/build.gradle +55 -0
  4. package/android/src/main/AndroidManifest.xml +5 -0
  5. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +1005 -0
  6. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +547 -0
  7. package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomSurfaceView.java +23 -0
  8. package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +29 -0
  9. package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +386 -0
  10. package/android/src/main/java/com/ahm/capacitor/camera/preview/TapGestureDetector.java +24 -0
  11. package/android/src/main/res/layout/bridge_layout_main.xml +15 -0
  12. package/android/src/main/res/layout/camera_activity.xml +68 -0
  13. package/android/src/main/res/values/camera_ids.xml +4 -0
  14. package/android/src/main/res/values/camera_theme.xml +9 -0
  15. package/android/src/main/res/values/colors.xml +3 -0
  16. package/android/src/main/res/values/strings.xml +3 -0
  17. package/android/src/main/res/values/styles.xml +3 -0
  18. package/dist/docs.json +390 -0
  19. package/dist/esm/definitions.d.ts +79 -0
  20. package/dist/esm/definitions.js +2 -0
  21. package/dist/esm/definitions.js.map +1 -0
  22. package/dist/esm/index.d.ts +4 -0
  23. package/dist/esm/index.js +7 -0
  24. package/dist/esm/index.js.map +1 -0
  25. package/dist/esm/web.d.ts +27 -0
  26. package/dist/esm/web.js +153 -0
  27. package/dist/esm/web.js.map +1 -0
  28. package/dist/plugin.cjs.js +164 -0
  29. package/dist/plugin.cjs.js.map +1 -0
  30. package/dist/plugin.js +167 -0
  31. package/dist/plugin.js.map +1 -0
  32. package/ios/Plugin/CameraController.swift +667 -0
  33. package/ios/Plugin/Info.plist +24 -0
  34. package/ios/Plugin/Plugin.h +10 -0
  35. package/ios/Plugin/Plugin.m +17 -0
  36. package/ios/Plugin/Plugin.swift +300 -0
  37. package/package.json +78 -0
package/dist/docs.json ADDED
@@ -0,0 +1,390 @@
1
+ {
2
+ "api": {
3
+ "name": "CameraPreviewPlugin",
4
+ "slug": "camerapreviewplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "start",
10
+ "signature": "(options: CameraPreviewOptions) => Promise<{}>",
11
+ "parameters": [
12
+ {
13
+ "name": "options",
14
+ "docs": "",
15
+ "type": "CameraPreviewOptions"
16
+ }
17
+ ],
18
+ "returns": "Promise<{}>",
19
+ "tags": [],
20
+ "docs": "",
21
+ "complexTypes": [
22
+ "CameraPreviewOptions"
23
+ ],
24
+ "slug": "start"
25
+ },
26
+ {
27
+ "name": "stop",
28
+ "signature": "() => Promise<{}>",
29
+ "parameters": [],
30
+ "returns": "Promise<{}>",
31
+ "tags": [],
32
+ "docs": "",
33
+ "complexTypes": [],
34
+ "slug": "stop"
35
+ },
36
+ {
37
+ "name": "capture",
38
+ "signature": "(options: CameraPreviewPictureOptions) => Promise<{ value: string; }>",
39
+ "parameters": [
40
+ {
41
+ "name": "options",
42
+ "docs": "",
43
+ "type": "CameraPreviewPictureOptions"
44
+ }
45
+ ],
46
+ "returns": "Promise<{ value: string; }>",
47
+ "tags": [],
48
+ "docs": "",
49
+ "complexTypes": [
50
+ "CameraPreviewPictureOptions"
51
+ ],
52
+ "slug": "capture"
53
+ },
54
+ {
55
+ "name": "captureSample",
56
+ "signature": "(options: CameraSampleOptions) => Promise<{ value: string; }>",
57
+ "parameters": [
58
+ {
59
+ "name": "options",
60
+ "docs": "",
61
+ "type": "CameraSampleOptions"
62
+ }
63
+ ],
64
+ "returns": "Promise<{ value: string; }>",
65
+ "tags": [],
66
+ "docs": "",
67
+ "complexTypes": [
68
+ "CameraSampleOptions"
69
+ ],
70
+ "slug": "capturesample"
71
+ },
72
+ {
73
+ "name": "getSupportedFlashModes",
74
+ "signature": "() => Promise<{ result: CameraPreviewFlashMode[]; }>",
75
+ "parameters": [],
76
+ "returns": "Promise<{ result: CameraPreviewFlashMode[]; }>",
77
+ "tags": [],
78
+ "docs": "",
79
+ "complexTypes": [
80
+ "CameraPreviewFlashMode"
81
+ ],
82
+ "slug": "getsupportedflashmodes"
83
+ },
84
+ {
85
+ "name": "setFlashMode",
86
+ "signature": "(options: { flashMode: CameraPreviewFlashMode | string; }) => Promise<void>",
87
+ "parameters": [
88
+ {
89
+ "name": "options",
90
+ "docs": "",
91
+ "type": "{ flashMode: string; }"
92
+ }
93
+ ],
94
+ "returns": "Promise<void>",
95
+ "tags": [],
96
+ "docs": "",
97
+ "complexTypes": [
98
+ "CameraPreviewFlashMode"
99
+ ],
100
+ "slug": "setflashmode"
101
+ },
102
+ {
103
+ "name": "flip",
104
+ "signature": "() => Promise<void>",
105
+ "parameters": [],
106
+ "returns": "Promise<void>",
107
+ "tags": [],
108
+ "docs": "",
109
+ "complexTypes": [],
110
+ "slug": "flip"
111
+ },
112
+ {
113
+ "name": "setOpacity",
114
+ "signature": "(options: CameraOpacityOptions) => Promise<{}>",
115
+ "parameters": [
116
+ {
117
+ "name": "options",
118
+ "docs": "",
119
+ "type": "CameraOpacityOptions"
120
+ }
121
+ ],
122
+ "returns": "Promise<{}>",
123
+ "tags": [],
124
+ "docs": "",
125
+ "complexTypes": [
126
+ "CameraOpacityOptions"
127
+ ],
128
+ "slug": "setopacity"
129
+ },
130
+ {
131
+ "name": "getSupportedZoomLevels",
132
+ "signature": "() => Promise<{ result: any[]; }>",
133
+ "parameters": [],
134
+ "returns": "Promise<{ result: any[]; }>",
135
+ "tags": [],
136
+ "docs": "",
137
+ "complexTypes": [],
138
+ "slug": "getsupportedzoomlevels"
139
+ }
140
+ ],
141
+ "properties": []
142
+ },
143
+ "interfaces": [
144
+ {
145
+ "name": "CameraPreviewOptions",
146
+ "slug": "camerapreviewoptions",
147
+ "docs": "",
148
+ "tags": [],
149
+ "methods": [],
150
+ "properties": [
151
+ {
152
+ "name": "parent",
153
+ "tags": [],
154
+ "docs": "Parent element to attach the video preview element to (applicable to the web platform only)",
155
+ "complexTypes": [],
156
+ "type": "string | undefined"
157
+ },
158
+ {
159
+ "name": "className",
160
+ "tags": [],
161
+ "docs": "Class name to add to the video preview element (applicable to the web platform only)",
162
+ "complexTypes": [],
163
+ "type": "string | undefined"
164
+ },
165
+ {
166
+ "name": "width",
167
+ "tags": [],
168
+ "docs": "The preview width in pixels, default window.screen.width",
169
+ "complexTypes": [],
170
+ "type": "number | undefined"
171
+ },
172
+ {
173
+ "name": "height",
174
+ "tags": [],
175
+ "docs": "The preview height in pixels, default window.screen.height",
176
+ "complexTypes": [],
177
+ "type": "number | undefined"
178
+ },
179
+ {
180
+ "name": "x",
181
+ "tags": [],
182
+ "docs": "The x origin, default 0 (applicable to the android and ios platforms only)",
183
+ "complexTypes": [],
184
+ "type": "number | undefined"
185
+ },
186
+ {
187
+ "name": "y",
188
+ "tags": [],
189
+ "docs": "The y origin, default 0 (applicable to the android and ios platforms only)",
190
+ "complexTypes": [],
191
+ "type": "number | undefined"
192
+ },
193
+ {
194
+ "name": "toBack",
195
+ "tags": [],
196
+ "docs": "Brings your html in front of your preview, default false (applicable to the android only)",
197
+ "complexTypes": [],
198
+ "type": "boolean | undefined"
199
+ },
200
+ {
201
+ "name": "paddingBottom",
202
+ "tags": [],
203
+ "docs": "The preview bottom padding in pixes. Useful to keep the appropriate preview sizes when orientation changes (applicable to the android and ios platforms only)",
204
+ "complexTypes": [],
205
+ "type": "number | undefined"
206
+ },
207
+ {
208
+ "name": "rotateWhenOrientationChanged",
209
+ "tags": [],
210
+ "docs": "Rotate preview when orientation changes (applicable to the ios platforms only; default value is true)",
211
+ "complexTypes": [],
212
+ "type": "boolean | undefined"
213
+ },
214
+ {
215
+ "name": "position",
216
+ "tags": [],
217
+ "docs": "Choose the camera to use 'front' or 'rear', default 'front'",
218
+ "complexTypes": [
219
+ "CameraPosition"
220
+ ],
221
+ "type": "string | undefined"
222
+ },
223
+ {
224
+ "name": "storeToFile",
225
+ "tags": [],
226
+ "docs": "Defaults to false - Capture images to a file and return the file path instead of returning base64 encoded data",
227
+ "complexTypes": [],
228
+ "type": "boolean | undefined"
229
+ },
230
+ {
231
+ "name": "disableExifHeaderStripping",
232
+ "tags": [],
233
+ "docs": "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)",
234
+ "complexTypes": [],
235
+ "type": "boolean | undefined"
236
+ },
237
+ {
238
+ "name": "enableHighResolution",
239
+ "tags": [],
240
+ "docs": "Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device *",
241
+ "complexTypes": [],
242
+ "type": "boolean | undefined"
243
+ },
244
+ {
245
+ "name": "disableAudio",
246
+ "tags": [],
247
+ "docs": "Defaults to false - Web only - Disables audio stream to prevent permission requests and output switching",
248
+ "complexTypes": [],
249
+ "type": "boolean | undefined"
250
+ },
251
+ {
252
+ "name": "lockAndroidOrientation",
253
+ "tags": [],
254
+ "docs": "Android Only - Locks device orientation when camera is showing.",
255
+ "complexTypes": [],
256
+ "type": "boolean | undefined"
257
+ },
258
+ {
259
+ "name": "enableOpacity",
260
+ "tags": [],
261
+ "docs": "Defaults to false - Android and Web only. Set if camera preview can change opacity.",
262
+ "complexTypes": [],
263
+ "type": "boolean | undefined"
264
+ },
265
+ {
266
+ "name": "enableZoom",
267
+ "tags": [],
268
+ "docs": "Defaults to false - Android only. Set if camera preview will support pinch to zoom.",
269
+ "complexTypes": [],
270
+ "type": "boolean | undefined"
271
+ },
272
+ {
273
+ "name": "zoomFactor",
274
+ "tags": [],
275
+ "docs": "override defualt lens choice ios String 'ultra','wide','tele' android int example 100, 200 etc",
276
+ "complexTypes": [],
277
+ "type": "any"
278
+ }
279
+ ]
280
+ },
281
+ {
282
+ "name": "CameraPreviewPictureOptions",
283
+ "slug": "camerapreviewpictureoptions",
284
+ "docs": "",
285
+ "tags": [],
286
+ "methods": [],
287
+ "properties": [
288
+ {
289
+ "name": "height",
290
+ "tags": [],
291
+ "docs": "The picture height, optional, default 0 (Device default)",
292
+ "complexTypes": [],
293
+ "type": "number | undefined"
294
+ },
295
+ {
296
+ "name": "width",
297
+ "tags": [],
298
+ "docs": "The picture width, optional, default 0 (Device default)",
299
+ "complexTypes": [],
300
+ "type": "number | undefined"
301
+ },
302
+ {
303
+ "name": "quality",
304
+ "tags": [],
305
+ "docs": "The picture quality, 0 - 100, default 85 on `iOS/Android`.\n\nIf left undefined, the `web` implementation will export a PNG, otherwise a JPEG will be generated",
306
+ "complexTypes": [],
307
+ "type": "number | undefined"
308
+ }
309
+ ]
310
+ },
311
+ {
312
+ "name": "CameraSampleOptions",
313
+ "slug": "camerasampleoptions",
314
+ "docs": "",
315
+ "tags": [],
316
+ "methods": [],
317
+ "properties": [
318
+ {
319
+ "name": "quality",
320
+ "tags": [],
321
+ "docs": "The picture quality, 0 - 100, default 85",
322
+ "complexTypes": [],
323
+ "type": "number | undefined"
324
+ }
325
+ ]
326
+ },
327
+ {
328
+ "name": "CameraOpacityOptions",
329
+ "slug": "cameraopacityoptions",
330
+ "docs": "",
331
+ "tags": [],
332
+ "methods": [],
333
+ "properties": [
334
+ {
335
+ "name": "opacity",
336
+ "tags": [],
337
+ "docs": "The percent opacity to set for camera view, default 1",
338
+ "complexTypes": [],
339
+ "type": "number | undefined"
340
+ }
341
+ ]
342
+ }
343
+ ],
344
+ "enums": [],
345
+ "typeAliases": [
346
+ {
347
+ "name": "CameraPosition",
348
+ "slug": "cameraposition",
349
+ "docs": "",
350
+ "types": [
351
+ {
352
+ "text": "'rear'",
353
+ "complexTypes": []
354
+ },
355
+ {
356
+ "text": "'front'",
357
+ "complexTypes": []
358
+ }
359
+ ]
360
+ },
361
+ {
362
+ "name": "CameraPreviewFlashMode",
363
+ "slug": "camerapreviewflashmode",
364
+ "docs": "",
365
+ "types": [
366
+ {
367
+ "text": "'off'",
368
+ "complexTypes": []
369
+ },
370
+ {
371
+ "text": "'on'",
372
+ "complexTypes": []
373
+ },
374
+ {
375
+ "text": "'auto'",
376
+ "complexTypes": []
377
+ },
378
+ {
379
+ "text": "'red-eye'",
380
+ "complexTypes": []
381
+ },
382
+ {
383
+ "text": "'torch'",
384
+ "complexTypes": []
385
+ }
386
+ ]
387
+ }
388
+ ],
389
+ "pluginConfigs": []
390
+ }
@@ -0,0 +1,79 @@
1
+ export declare type CameraPosition = 'rear' | 'front';
2
+ export interface CameraPreviewOptions {
3
+ /** Parent element to attach the video preview element to (applicable to the web platform only) */
4
+ parent?: string;
5
+ /** Class name to add to the video preview element (applicable to the web platform only) */
6
+ className?: string;
7
+ /** The preview width in pixels, default window.screen.width */
8
+ width?: number;
9
+ /** The preview height in pixels, default window.screen.height */
10
+ height?: number;
11
+ /** The x origin, default 0 (applicable to the android and ios platforms only) */
12
+ x?: number;
13
+ /** The y origin, default 0 (applicable to the android and ios platforms only) */
14
+ y?: number;
15
+ /** Brings your html in front of your preview, default false (applicable to the android only) */
16
+ toBack?: boolean;
17
+ /** The preview bottom padding in pixes. Useful to keep the appropriate preview sizes when orientation changes (applicable to the android and ios platforms only) */
18
+ paddingBottom?: number;
19
+ /** Rotate preview when orientation changes (applicable to the ios platforms only; default value is true) */
20
+ rotateWhenOrientationChanged?: boolean;
21
+ /** Choose the camera to use 'front' or 'rear', default 'front' */
22
+ position?: CameraPosition | string;
23
+ /** Defaults to false - Capture images to a file and return the file path instead of returning base64 encoded data */
24
+ storeToFile?: boolean;
25
+ /** 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) */
26
+ disableExifHeaderStripping?: boolean;
27
+ /** Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device **/
28
+ enableHighResolution?: boolean;
29
+ /** Defaults to false - Web only - Disables audio stream to prevent permission requests and output switching */
30
+ disableAudio?: boolean;
31
+ /** Android Only - Locks device orientation when camera is showing. */
32
+ lockAndroidOrientation?: boolean;
33
+ /** Defaults to false - Android and Web only. Set if camera preview can change opacity. */
34
+ enableOpacity?: boolean;
35
+ /** Defaults to false - Android only. Set if camera preview will support pinch to zoom. */
36
+ enableZoom?: boolean;
37
+ /** override defualt lens choice ios String 'ultra','wide','tele' android int example 100, 200 etc */
38
+ zoomFactor?: any;
39
+ }
40
+ export interface CameraPreviewPictureOptions {
41
+ /** The picture height, optional, default 0 (Device default) */
42
+ height?: number;
43
+ /** The picture width, optional, default 0 (Device default) */
44
+ width?: number;
45
+ /** The picture quality, 0 - 100, default 85 on `iOS/Android`.
46
+ *
47
+ * If left undefined, the `web` implementation will export a PNG, otherwise a JPEG will be generated */
48
+ quality?: number;
49
+ }
50
+ export interface CameraSampleOptions {
51
+ /** The picture quality, 0 - 100, default 85 */
52
+ quality?: number;
53
+ }
54
+ export declare type CameraPreviewFlashMode = 'off' | 'on' | 'auto' | 'red-eye' | 'torch';
55
+ export interface CameraOpacityOptions {
56
+ /** The percent opacity to set for camera view, default 1 */
57
+ opacity?: number;
58
+ }
59
+ export interface CameraPreviewPlugin {
60
+ start(options: CameraPreviewOptions): Promise<{}>;
61
+ stop(): Promise<{}>;
62
+ capture(options: CameraPreviewPictureOptions): Promise<{
63
+ value: string;
64
+ }>;
65
+ captureSample(options: CameraSampleOptions): Promise<{
66
+ value: string;
67
+ }>;
68
+ getSupportedFlashModes(): Promise<{
69
+ result: CameraPreviewFlashMode[];
70
+ }>;
71
+ setFlashMode(options: {
72
+ flashMode: CameraPreviewFlashMode | string;
73
+ }): Promise<void>;
74
+ flip(): Promise<void>;
75
+ setOpacity(options: CameraOpacityOptions): Promise<{}>;
76
+ getSupportedZoomLevels(): Promise<{
77
+ result: any[];
78
+ }>;
79
+ }
@@ -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":["/* eslint-disable @typescript-eslint/ban-types */\nexport 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 /** 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 - Web only - 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 /** override defualt lens choice ios String 'ultra','wide','tele' android int example 100, 200 etc */\n zoomFactor?: any;\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 on `iOS/Android`.\n *\n * If left undefined, the `web` implementation will export a PNG, otherwise a JPEG will be generated */\n quality?: number;\n}\n\nexport interface CameraSampleOptions {\n /** The picture quality, 0 - 100, default 85 */\n quality?: number;\n}\n\nexport type CameraPreviewFlashMode = 'off' | 'on' | 'auto' | 'red-eye' | '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 start(options: CameraPreviewOptions): Promise<{}>;\n stop(): Promise<{}>;\n capture(options: CameraPreviewPictureOptions): Promise<{ value: string }>;\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n setFlashMode(options: { flashMode: CameraPreviewFlashMode | string }): Promise<void>;\n flip(): Promise<void>;\n setOpacity(options: CameraOpacityOptions): Promise<{}>;\n getSupportedZoomLevels(): Promise<{\n result: any[];\n }>;\n}"]}
@@ -0,0 +1,4 @@
1
+ import type { CameraPreviewPlugin } from './definitions';
2
+ declare const CameraPreview: CameraPreviewPlugin;
3
+ export * from './definitions';
4
+ export { CameraPreview };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const CameraPreview = registerPlugin('CameraPreview', {
3
+ web: () => import('./web').then((m) => new m.CameraPreviewWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { CameraPreview };
7
+ //# 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,MAAM,aAAa,GAAG,cAAc,CAAsB,eAAe,EAAE;IACzE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;CACjE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { CameraPreviewPlugin } from './definitions';\n\nconst CameraPreview = registerPlugin<CameraPreviewPlugin>('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\n\nexport * from './definitions';\nexport { CameraPreview };"]}
@@ -0,0 +1,27 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { CameraPreviewOptions, CameraPreviewPictureOptions, CameraPreviewPlugin, CameraPreviewFlashMode, CameraSampleOptions, CameraOpacityOptions } from './definitions';
3
+ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
4
+ /**
5
+ * track which camera is used based on start options
6
+ * used in capture
7
+ */
8
+ private isBackCamera;
9
+ constructor();
10
+ start(options: CameraPreviewOptions): Promise<{}>;
11
+ stop(): Promise<any>;
12
+ capture(options: CameraPreviewPictureOptions): Promise<any>;
13
+ captureSample(_options: CameraSampleOptions): Promise<any>;
14
+ getSupportedFlashModes(): Promise<{
15
+ result: CameraPreviewFlashMode[];
16
+ }>;
17
+ getSupportedZoomLevels(): Promise<{
18
+ result: any[];
19
+ }>;
20
+ setFlashMode(_options: {
21
+ flashMode: CameraPreviewFlashMode | string;
22
+ }): Promise<void>;
23
+ flip(): Promise<void>;
24
+ setOpacity(_options: CameraOpacityOptions): Promise<any>;
25
+ }
26
+ declare const CameraPreview: CameraPreviewWeb;
27
+ export { CameraPreview };
@@ -0,0 +1,153 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ /* eslint-disable @typescript-eslint/prefer-for-of */
3
+ /* eslint-disable @typescript-eslint/ban-types */
4
+ /* eslint-disable no-async-promise-executor */
5
+ /* eslint-disable @typescript-eslint/consistent-type-assertions */
6
+ /* eslint-disable @typescript-eslint/no-inferrable-types */
7
+ import { WebPlugin, registerWebPlugin } from '@capacitor/core';
8
+ export class CameraPreviewWeb extends WebPlugin {
9
+ constructor() {
10
+ super({
11
+ name: 'CameraPreview',
12
+ platforms: ['web'],
13
+ });
14
+ /**
15
+ * track which camera is used based on start options
16
+ * used in capture
17
+ */
18
+ this.isBackCamera = false;
19
+ }
20
+ async start(options) {
21
+ return new Promise(async (resolve, reject) => {
22
+ var _a;
23
+ await navigator.mediaDevices
24
+ .getUserMedia({
25
+ audio: !options.disableAudio,
26
+ video: true
27
+ })
28
+ .then((stream) => {
29
+ // Stop any existing stream so we can request media with different constraints based on user input
30
+ stream.getTracks().forEach((track) => track.stop());
31
+ })
32
+ .catch((error) => {
33
+ reject(error);
34
+ });
35
+ const video = document.getElementById('video');
36
+ const parent = document.getElementById(options.parent);
37
+ if (!video) {
38
+ const videoElement = document.createElement('video');
39
+ videoElement.id = 'video';
40
+ videoElement.setAttribute('class', options.className || '');
41
+ // Don't flip video feed if camera is rear facing
42
+ if (options.position !== 'rear') {
43
+ videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');
44
+ }
45
+ const userAgent = navigator.userAgent.toLowerCase();
46
+ const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');
47
+ // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful
48
+ // Without these attributes videoElement.play() will throw a NotAllowedError
49
+ // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari
50
+ if (isSafari) {
51
+ videoElement.setAttribute('autoplay', 'true');
52
+ videoElement.setAttribute('muted', 'true');
53
+ videoElement.setAttribute('playsinline', 'true');
54
+ }
55
+ if (parent) {
56
+ parent.appendChild(videoElement);
57
+ }
58
+ if ((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
59
+ const constraints = {
60
+ video: {
61
+ width: { ideal: options.width },
62
+ height: { ideal: options.height }
63
+ }
64
+ };
65
+ if (options.position === 'rear') {
66
+ constraints.video.facingMode = 'environment';
67
+ this.isBackCamera = true;
68
+ }
69
+ else {
70
+ this.isBackCamera = false;
71
+ }
72
+ navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
73
+ //video.src = window.URL.createObjectURL(stream);
74
+ videoElement.srcObject = stream;
75
+ videoElement.play();
76
+ resolve({});
77
+ }, (err) => {
78
+ reject(err);
79
+ });
80
+ }
81
+ }
82
+ else {
83
+ reject({ message: 'camera already started' });
84
+ }
85
+ });
86
+ }
87
+ async stop() {
88
+ const video = document.getElementById('video');
89
+ if (video) {
90
+ video.pause();
91
+ const st = video.srcObject;
92
+ const tracks = st.getTracks();
93
+ for (let i = 0; i < tracks.length; i++) {
94
+ const track = tracks[i];
95
+ track.stop();
96
+ }
97
+ video.remove();
98
+ }
99
+ }
100
+ async capture(options) {
101
+ return new Promise((resolve, _) => {
102
+ const video = document.getElementById('video');
103
+ const canvas = document.createElement('canvas');
104
+ // video.width = video.offsetWidth;
105
+ const context = canvas.getContext('2d');
106
+ canvas.width = video.videoWidth;
107
+ canvas.height = video.videoHeight;
108
+ // flip horizontally back camera isn't used
109
+ if (context) {
110
+ if (!this.isBackCamera) {
111
+ context.translate(video.videoWidth, 0);
112
+ context.scale(-1, 1);
113
+ }
114
+ context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
115
+ }
116
+ let base64EncodedImage;
117
+ if (options.quality != undefined) {
118
+ base64EncodedImage = canvas.toDataURL('image/jpeg', options.quality / 100.0).replace('data:image/jpeg;base64,', '');
119
+ }
120
+ else {
121
+ base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');
122
+ }
123
+ resolve({
124
+ value: base64EncodedImage,
125
+ });
126
+ });
127
+ }
128
+ async captureSample(_options) {
129
+ return this.capture(_options);
130
+ }
131
+ async getSupportedFlashModes() {
132
+ throw new Error('getSupportedFlashModes not supported under the web platform');
133
+ }
134
+ getSupportedZoomLevels() {
135
+ throw new Error('getSupportedFlashModes not supported under the web platform.');
136
+ }
137
+ async setFlashMode(_options) {
138
+ throw new Error('setFlashMode not supported under the web platform');
139
+ }
140
+ async flip() {
141
+ throw new Error('flip not supported under the web platform');
142
+ }
143
+ async setOpacity(_options) {
144
+ const video = document.getElementById('video');
145
+ if (!!video && !!_options['opacity']) {
146
+ video.style.setProperty('opacity', _options['opacity'].toString());
147
+ }
148
+ }
149
+ }
150
+ const CameraPreview = new CameraPreviewWeb();
151
+ export { CameraPreview };
152
+ registerWebPlugin(CameraPreview);
153
+ //# sourceMappingURL=web.js.map