@capacitor/camera 8.1.0-test.250320251731 → 8.1.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.
- package/CapacitorCamera.podspec +3 -2
- package/Package.swift +4 -2
- package/README.md +419 -67
- package/android/build.gradle +4 -4
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.kt +3 -2
- package/android/src/main/java/com/capacitorjs/plugins/camera/IonCameraFlow.kt +111 -70
- package/android/src/main/java/com/capacitorjs/plugins/camera/IonCameraSettings.kt +1 -2
- package/android/src/main/java/com/capacitorjs/plugins/camera/IonEditableMode.kt +16 -0
- package/android/src/main/java/com/capacitorjs/plugins/camera/IonGallerySettings.kt +1 -2
- package/dist/docs.json +18 -50
- package/dist/esm/definitions.d.ts +22 -37
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +13 -2
- package/dist/esm/web.js +280 -39
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +279 -38
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +279 -38
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CameraPlugin/CameraPlugin.swift +193 -9
- package/package.json +10 -5
- package/android/libs/IONCameraLib-debug.aar +0 -0
- package/android/src/main/java/com/capacitorjs/plugins/camera/IonVideoSettings.kt +0 -7
|
@@ -150,23 +150,16 @@ export interface TakePhotoOptions {
|
|
|
150
150
|
*/
|
|
151
151
|
cameraDirection?: CameraDirection;
|
|
152
152
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
|
|
159
|
-
allowEdit?: boolean;
|
|
160
|
-
/**
|
|
161
|
-
* If `true`, will use an in-app editor for photo edition.
|
|
162
|
-
* If `false`, will open a separate (platform-specific) native app to handle photo edition, falling back to the in-app editor if none is available.
|
|
163
|
-
* Only applicable with `allowEdit` set to true.
|
|
164
|
-
* Note: This option is only supported on Android and iOS.
|
|
153
|
+
* Determines if and how the user can edit the photo.
|
|
154
|
+
* - 'in-app': Use an in-app editor for photo edition.
|
|
155
|
+
* - 'external': Open a separate (platform-specific) native app to handle photo edition, falling back to the in-app editor if none is available. Note: iOS does not support external editing and will use 'in-app' instead.
|
|
156
|
+
* - 'no': No editing allowed.
|
|
157
|
+
* Not available on Web.
|
|
158
|
+
* @default 'no'
|
|
165
159
|
*
|
|
166
|
-
* @default true
|
|
167
160
|
* @since 8.1.0
|
|
168
161
|
*/
|
|
169
|
-
|
|
162
|
+
editable?: 'in-app' | 'external' | 'no';
|
|
170
163
|
/**
|
|
171
164
|
* iOS only: The presentation style of the Camera.
|
|
172
165
|
* @default 'fullscreen'
|
|
@@ -187,7 +180,6 @@ export interface TakePhotoOptions {
|
|
|
187
180
|
/**
|
|
188
181
|
* Whether or not MediaResult should include its metadata.
|
|
189
182
|
* If an error occurs when obtaining the metadata, it will return empty.
|
|
190
|
-
* Note: This option is only supported on Android and iOS.
|
|
191
183
|
* @default false
|
|
192
184
|
*
|
|
193
185
|
* @since 8.1.0
|
|
@@ -257,31 +249,23 @@ export interface ChooseFromGalleryOptions {
|
|
|
257
249
|
/**
|
|
258
250
|
* Whether or not MediaResult should include its metadata.
|
|
259
251
|
* If an error occurs when obtaining the metadata, it will return empty.
|
|
260
|
-
* Note: This option is only supported on Android and iOS.
|
|
261
252
|
* @default false
|
|
262
253
|
*
|
|
263
254
|
* @since 8.1.0
|
|
264
255
|
*/
|
|
265
256
|
includeMetadata?: boolean;
|
|
266
257
|
/**
|
|
267
|
-
*
|
|
258
|
+
* Determines if and how the user can edit the photo.
|
|
259
|
+
* - 'in-app': Use an in-app editor for photo edition.
|
|
260
|
+
* - 'external': Open a separate (platform-specific) native app to handle photo edition, falling back to the in-app editor if none is available. Note: iOS does not support external editing and will use 'in-app' instead.
|
|
261
|
+
* - 'no': No editing allowed.
|
|
268
262
|
* Only applicable for `MediaTypeSelection.Photo` and `allowMultipleSelection` set to `false`.
|
|
269
|
-
*
|
|
270
|
-
* @default
|
|
271
|
-
*
|
|
272
|
-
* @since 8.1.0
|
|
273
|
-
*/
|
|
274
|
-
allowEdit?: boolean;
|
|
275
|
-
/**
|
|
276
|
-
* If `true`, will use an in-app editor for photo edition.
|
|
277
|
-
* If `false`, will open a separate (platform-specific) native app to handle photo edition, falling back to the in-app editor if none is available.
|
|
278
|
-
* Only applicable with `allowEdit` set to true.
|
|
279
|
-
* Note: This option is only supported on Android and iOS.
|
|
263
|
+
* Not available on Web.
|
|
264
|
+
* @default 'no'
|
|
280
265
|
*
|
|
281
|
-
* @default true
|
|
282
266
|
* @since 8.1.0
|
|
283
267
|
*/
|
|
284
|
-
|
|
268
|
+
editable?: 'in-app' | 'external' | 'no';
|
|
285
269
|
/**
|
|
286
270
|
* iOS only: The presentation style of media picker.
|
|
287
271
|
* @default 'fullscreen'
|
|
@@ -354,7 +338,6 @@ export interface EditURIPhotoOptions {
|
|
|
354
338
|
/**
|
|
355
339
|
* Whether or not MediaResult should include its metadata.
|
|
356
340
|
* If an error occurs when obtaining the metadata, it will return empty.
|
|
357
|
-
* Note: This option is only supported on Android and iOS.
|
|
358
341
|
* @default false
|
|
359
342
|
*
|
|
360
343
|
* @since 8.1.0
|
|
@@ -394,6 +377,7 @@ export interface MediaResult {
|
|
|
394
377
|
/**
|
|
395
378
|
* Returns the thumbnail of the media, base64 encoded.
|
|
396
379
|
* On Web, for `MediaType.Photo`, the full image is returned here, also base64 encoded.
|
|
380
|
+
* On Web, for `MediaType.Video`, a full-resolution JPEG frame captured from the video is returned, base64 encoded at 80% quality.
|
|
397
381
|
*
|
|
398
382
|
* @since 8.1.0
|
|
399
383
|
*/
|
|
@@ -424,15 +408,13 @@ export interface MediaResult {
|
|
|
424
408
|
}
|
|
425
409
|
export interface MediaMetadata {
|
|
426
410
|
/**
|
|
427
|
-
* File size of the media, in bytes
|
|
428
|
-
* Not available on Web.
|
|
411
|
+
* File size of the media, in bytes.
|
|
429
412
|
*
|
|
430
413
|
* @since 8.1.0
|
|
431
414
|
*/
|
|
432
415
|
size?: number;
|
|
433
416
|
/**
|
|
434
417
|
* Only applicable for `MediaType.Video` - the duration of the media, in seconds.
|
|
435
|
-
* Not available on Web.
|
|
436
418
|
*
|
|
437
419
|
* @since 8.1.0
|
|
438
420
|
*/
|
|
@@ -440,8 +422,10 @@ export interface MediaMetadata {
|
|
|
440
422
|
/**
|
|
441
423
|
* The format of the image, ex: jpeg, png, mp4.
|
|
442
424
|
*
|
|
425
|
+
* Android and iOS may return 'jpg' instead of 'jpeg'. The format is the same, just with a different name.
|
|
426
|
+
* Please compare against both 'jpeg' and 'jpg' when checking if the format of the returned media is JPEG.
|
|
443
427
|
* Web supports jpeg, png and gif, but the exact availability may vary depending on the browser.
|
|
444
|
-
* gif is only supported for `chooseFromGallery
|
|
428
|
+
* gif is only supported for `chooseFromGallery` on Web.
|
|
445
429
|
*
|
|
446
430
|
* @since 8.1.0
|
|
447
431
|
*/
|
|
@@ -451,17 +435,18 @@ export interface MediaMetadata {
|
|
|
451
435
|
*
|
|
452
436
|
* @since 8.1.0
|
|
453
437
|
*/
|
|
454
|
-
resolution
|
|
438
|
+
resolution?: string;
|
|
455
439
|
/**
|
|
456
440
|
* The date and time the media was created, in ISO 8601 format.
|
|
457
441
|
* If creation date is not available (e.g. Android 7 and below), the last modified date is returned.
|
|
458
|
-
*
|
|
442
|
+
* For Web, the last modified date is always returned.
|
|
459
443
|
*
|
|
460
444
|
* @since 8.1.0
|
|
461
445
|
*/
|
|
462
446
|
creationDate?: string;
|
|
463
447
|
/**
|
|
464
448
|
* Exif data, if any, retreived from the media item.
|
|
449
|
+
* Only available for `MediaType.Photo`.
|
|
465
450
|
* Not available on Web.
|
|
466
451
|
*
|
|
467
452
|
* @since 8.1.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAuzBA;;;GAGG;AACH,MAAM,CAAN,IAAY,YAaX;AAbD,WAAY,YAAY;IACtB;;OAEG;IACH,iCAAiB,CAAA;IACjB;;OAEG;IACH,iCAAiB,CAAA;IACjB;;OAEG;IACH,iCAAiB,CAAA;AACnB,CAAC,EAbW,YAAY,KAAZ,YAAY,QAavB;AAED,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,gCAAa,CAAA;IACb,kCAAe,CAAA;AACjB,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,+BAAW,CAAA;IACX,qCAAiB,CAAA;IACjB,uCAAmB,CAAA;AACrB,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B;AAED,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,2CAAS,CAAA;IACT,2CAAS,CAAA;AACX,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAED,MAAM,CAAN,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,yDAAO,CAAA;AACT,CAAC,EAJW,kBAAkB,KAAlB,kBAAkB,QAI7B;AAED,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,+CAAQ,CAAA;IACR,6CAAO,CAAA;AACT,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB","sourcesContent":["import type { PermissionState } from '@capacitor/core';\n\nexport type CameraPermissionState = PermissionState | 'limited';\n\nexport type CameraPermissionType = 'camera' | 'photos';\n\nexport interface PermissionStatus {\n camera: CameraPermissionState;\n photos: CameraPermissionState;\n}\n\nexport interface CameraPluginPermissions {\n permissions: CameraPermissionType[];\n}\n\nexport interface CameraPlugin {\n /**\n * Open the device's camera and allow the user to take a photo.\n *\n * @since 8.1.0\n */\n takePhoto(options: TakePhotoOptions): Promise<MediaResult>;\n\n /**\n * Open the device's camera and allow the user to record a video.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n recordVideo(options: RecordVideoOptions): Promise<MediaResult>;\n\n /**\n * Open a native video player.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n playVideo(options: PlayVideoOptions): Promise<void>;\n\n /**\n * Allow users to choose pictures, videos, or both, directly from their gallery.\n *\n * @since 8.1.0\n */\n chooseFromGallery(options: ChooseFromGalleryOptions): Promise<MediaResults>;\n\n /**\n * Open an in-app screen to edit a given photo using the provided base64 string.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n editPhoto(options: EditPhotoOptions): Promise<EditPhotoResult>;\n\n /**\n * Open an in-app screen to edit a photo using the provided URI.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n editURIPhoto(options: EditURIPhotoOptions): Promise<MediaResult>;\n\n /**\n * Allows the user to update their limited photo library selection.\n * Returns all the limited photos after the picker dismissal.\n * If instead the user gave full access to the photos it returns an empty array.\n *\n * @since 4.1.0\n */\n pickLimitedLibraryPhotos(): Promise<GalleryPhotos>;\n /**\n * Return an array of photos selected from the limited photo library.\n *\n * @since 4.1.0\n */\n getLimitedLibraryPhotos(): Promise<GalleryPhotos>;\n\n /**\n * Check camera and photo album permissions\n *\n * @since 1.0.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request camera and photo album permissions\n *\n * @since 1.0.0\n */\n requestPermissions(permissions?: CameraPluginPermissions): Promise<PermissionStatus>;\n\n /**\n * Prompt the user to pick a photo from an album, or take a new photo\n * with the camera.\n *\n * @since 1.0.0\n * @deprecated Use `takePhoto` for a camera photo, or `chooseFromGallery` to select from the gallery. For creating a prompt for the user to select which source, use `@capacitor/action-sheet` or any UI component of your choosing. Refer to the Camera API documentation for more information on migrating.\n */\n getPhoto(options: ImageOptions): Promise<Photo>;\n\n /**\n * Allows the user to pick multiple pictures from the photo gallery.\n *\n * @since 1.2.0\n * @deprecated Use `chooseFromGallery` instead. Refer to the Camera API documentation for more information on migrating.\n */\n pickImages(options: GalleryImageOptions): Promise<GalleryPhotos>;\n}\n\nexport interface TakePhotoOptions {\n /**\n * The quality of image to return, from 0-100.\n * Only applicable for `EncodingType.JPEG`.\n * Note: This option is only supported on Android and iOS.\n *\n * @default 100\n * @since 8.1.0\n */\n quality?: number;\n\n /**\n * The target width of photos to apply.\n * Must be a positive number, and used along `targetHeight`.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 8.1.0\n */\n targetWidth?: number;\n\n /**\n * The target width of photos to apply.\n * Must be a positive number, and used along `targetWidth`.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 8.1.0\n */\n targetHeight?: number;\n\n /**\n * Whether to automatically rotate the image \"up\" to correct for orientation\n * in portrait mode.\n * Note: This option is only supported on Android and iOS\n * @default true\n *\n * @since 8.1.0\n */\n correctOrientation?: boolean;\n\n /**\n * The encoding type for the captured photo - JPEG or PNG.\n * Note: This option is only supported on Android and iOS.\n * @default EncodingType.JPEG\n *\n * @since 8.1.0\n */\n encodingType?: EncodingType;\n\n /**\n * Whether to save the photo to the gallery.\n * Note: This option is only supported on Android and iOS.\n * @default false\n *\n * @since 8.1.0\n */\n saveToGallery?: boolean;\n\n /**\n * iOS and Web only: The camera direction.\n * @default CameraDirection.Rear\n *\n * @since 8.1.0\n */\n cameraDirection?: CameraDirection;\n\n /**\n * Whether to allow the user to crop or make small edits.\n * Note: This option is only supported on Android and iOS.\n * @default false\n *\n * @since 8.1.0\n */\n allowEdit?: boolean;\n\n /**\n * If `true`, will use an in-app editor for photo edition.\n * If `false`, will open a separate (platform-specific) native app to handle photo edition, falling back to the in-app editor if none is available.\n * Only applicable with `allowEdit` set to true.\n * Note: This option is only supported on Android and iOS.\n *\n * @default true\n * @since 8.1.0\n */\n editInApp?: boolean;\n\n /**\n * iOS only: The presentation style of the Camera.\n * @default 'fullscreen'\n *\n * @since 8.1.0\n */\n presentationStyle?: 'fullscreen' | 'popover';\n\n /**\n * Web only: Whether to use the PWA Element experience or file input. The\n * default is to use PWA Elements if installed and fall back to file input.\n * To always use file input, set this to `true`.\n *\n * Learn more about PWA Elements: https://capacitorjs.com/docs/web/pwa-elements\n *\n * @since 8.1.0\n */\n webUseInput?: boolean;\n\n /**\n * Whether or not MediaResult should include its metadata.\n * If an error occurs when obtaining the metadata, it will return empty.\n * Note: This option is only supported on Android and iOS.\n * @default false\n *\n * @since 8.1.0\n */\n includeMetadata?: boolean;\n}\n\nexport interface RecordVideoOptions {\n /**\n * Whether to save the video to the gallery.\n * @default false\n *\n * @since 8.1.0\n */\n saveToGallery?: boolean;\n\n /**\n * Whether or not MediaResult should include its metadata.\n * If an error occurs when obtaining the metadata, it will return empty.\n * @default false\n *\n * @since 8.1.0\n */\n includeMetadata?: boolean;\n\n /**\n * Whether the to store the video in persistent app storage or in temporary cache.\n * If you plan to use the returned `MediaResult#URI` across app launches, you may want to set to true.\n * Otherwise, you can set to false.\n * @default true\n *\n * @since 8.1.0\n */\n isPersistent?: boolean;\n}\n\nexport interface PlayVideoOptions {\n /**\n * The URI of the video to play.\n * You may use the `MediaResult#URI` returned from `recordVideo` or `chooseFromGallery` directly.\n *\n * @since 8.1.0\n */\n uri: string;\n}\n\nexport interface ChooseFromGalleryOptions {\n /**\n * The type of media to select. Can be pictures, videos, or both.\n * @default MediaTypeSelection.Photo\n *\n * @since 8.1.0\n */\n mediaType?: MediaTypeSelection;\n\n /**\n * Whether or not to allow selecting multiple media files from the gallery.\n * @default false\n *\n * @since 8.1.0\n */\n allowMultipleSelection?: boolean;\n\n /**\n * The maximum number of media files that the user can choose.\n * Only applicable if `allowMultipleSelection` is `true`.\n * Any non-positive number will be treated as unlimited.\n * Note: This option is only supported on Android 13+ and iOS.\n * @default 0\n *\n * @since 8.1.0\n */\n limit?: number;\n\n /**\n * Whether or not MediaResult should include its metadata.\n * If an error occurs when obtaining the metadata, it will return empty.\n * Note: This option is only supported on Android and iOS.\n * @default false\n *\n * @since 8.1.0\n */\n includeMetadata?: boolean;\n\n /**\n * Whether to allow the user to crop or make small edits.\n * Only applicable for `MediaTypeSelection.Photo` and `allowMultipleSelection` set to `false`.\n * Note: This option is only supported on Android and iOS.\n * @default false\n *\n * @since 8.1.0\n */\n allowEdit?: boolean;\n\n /**\n * If `true`, will use an in-app editor for photo edition.\n * If `false`, will open a separate (platform-specific) native app to handle photo edition, falling back to the in-app editor if none is available.\n * Only applicable with `allowEdit` set to true.\n * Note: This option is only supported on Android and iOS.\n *\n * @default true\n * @since 8.1.0\n */\n editInApp?: boolean;\n\n /**\n * iOS only: The presentation style of media picker.\n * @default 'fullscreen'\n *\n * @since 8.1.0\n */\n presentationStyle?: 'fullscreen' | 'popover';\n\n /**\n * The quality of images to return, from 0-100.\n * Only applicable for `MediaType.Photo` and JPEG format.\n * Note: This option is only supported on Android and iOS.\n *\n * @default 100\n * @since 8.1.0\n */\n quality?: number;\n\n /**\n * The target width of photos to apply.\n * Must be a positive number, and used along `targetHeight`.\n * Not applicable when videos are selected.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 1.0.0\n */\n targetWidth?: number;\n\n /**\n * The target width of photos to apply.\n * Must be a positive number, and used along `targetWidth`.\n * Not applicable when videos are selected.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 8.1.0\n */\n targetHeight?: number;\n\n /**\n * Whether to automatically rotate the image \"up\" to correct for orientation\n * in portrait mode.\n * Not applicable when videos are selected.\n * Note: This option is only supported on Android and iOS\n * @default true\n *\n * @since 8.1.0\n */\n correctOrientation?: boolean;\n\n /**\n * Web only: Whether to use the PWA Element experience or file input. The\n * default is to use PWA Elements if installed and fall back to file input.\n * To always use file input, set this to `true`.\n *\n * Learn more about PWA Elements: https://capacitorjs.com/docs/web/pwa-elements\n *\n * @since 8.1.0\n */\n webUseInput?: boolean;\n}\n\nexport interface EditURIPhotoOptions {\n /**\n * The URI that contains the photo to edit.\n *\n * @since 8.1.0\n */\n uri: string;\n\n /**\n * Whether to save the edited photo to the gallery.\n * @default false\n *\n * @since 8.1.0\n */\n\n saveToGallery?: boolean;\n\n /**\n * Whether or not MediaResult should include its metadata.\n * If an error occurs when obtaining the metadata, it will return empty.\n * Note: This option is only supported on Android and iOS.\n * @default false\n *\n * @since 8.1.0\n */\n includeMetadata?: boolean;\n}\n\nexport interface EditPhotoOptions {\n /**\n * The base64 encoded image to edit.\n *\n * @since 8.1.0\n */\n inputImage: string;\n}\n\nexport interface EditPhotoResult {\n /**\n * The edited image, base64 encoded.\n *\n * @since 8.1.0\n */\n outputImage: string;\n}\n\nexport interface MediaResult {\n /**\n * The type of media result. Either `Photo` or `Video`.\n *\n * @since 8.1.0\n */\n type: MediaType;\n\n /**\n * The URI pointing to the media file.\n * Not available on Web. Use `webPath` instead for Web.\n *\n * @since 8.1.0\n */\n uri?: string;\n\n /**\n * Returns the thumbnail of the media, base64 encoded.\n * On Web, for `MediaType.Photo`, the full image is returned here, also base64 encoded.\n *\n * @since 8.1.0\n */\n thumbnail?: string;\n\n /**\n * Whether if the media was saved to the gallery successfully or not.\n * Only applicable if `saveToGallery` was set to `true` in input options.\n * Otherwise, `false` is always returned for `save`.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n saved: boolean;\n\n /**\n * webPath returns a path that can be used to set the src attribute of a media item for efficient\n * loading and rendering.\n *\n * @since 8.1.0\n */\n webPath?: string;\n\n /**\n * Metadata associated to the media result.\n * Only included if `includeMetadata` was set to `true` in input options.\n *\n * @since 8.1.0\n */\n metadata?: MediaMetadata;\n}\n\nexport interface MediaMetadata {\n /**\n * File size of the media, in bytes\n * Not available on Web.\n *\n * @since 8.1.0\n */\n size?: number;\n\n /**\n * Only applicable for `MediaType.Video` - the duration of the media, in seconds.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n duration?: number;\n\n /**\n * The format of the image, ex: jpeg, png, mp4.\n *\n * Web supports jpeg, png and gif, but the exact availability may vary depending on the browser.\n * gif is only supported for `chooseFromGallery`, and only if `webUseInput` option is set to `true`.\n *\n * @since 8.1.0\n */\n format: string;\n\n /**\n * The resolution of the media, in `<width>x<height>` format. Example: '1920x1080'.\n *\n * @since 8.1.0\n */\n resolution: string;\n\n /**\n * The date and time the media was created, in ISO 8601 format.\n * If creation date is not available (e.g. Android 7 and below), the last modified date is returned.\n * Not available on web.\n *\n * @since 8.1.0\n */\n creationDate?: string;\n\n /**\n * Exif data, if any, retreived from the media item.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n exif?: string;\n}\n\nexport interface MediaResults {\n /**\n * The list of media results.\n *\n * @since 8.1.0\n */\n results: MediaResult[];\n}\n\n/**\n * @deprecated This interface is only meant to be used for deprecated `getPhoto` method.\n * It will be removed in a future major version of the plugin, along with `getPhoto`.\n */\nexport interface ImageOptions {\n /**\n * The quality of image to return as JPEG, from 0-100\n * Note: This option is only supported on Android and iOS.\n *\n * @since 1.0.0\n */\n quality?: number;\n /**\n * Whether to allow the user to crop or make small edits (platform specific).\n * Note: This option is only supported on Android and iOS.\n * On iOS it's only supported for CameraSource.Camera, but not for CameraSource.Photos.\n *\n * @since 1.0.0\n */\n allowEditing?: boolean;\n /**\n * How the data should be returned. Currently, only 'Base64', 'DataUrl' or 'Uri' is supported\n *\n * @since 1.0.0\n */\n resultType: CameraResultType;\n /**\n * Whether to save the photo to the gallery.\n * If the photo was picked from the gallery, it will only be saved if edited.\n * Note: This option is only supported on Android and iOS.\n * @default false\n *\n * @since 1.0.0\n */\n saveToGallery?: boolean;\n /**\n * The desired maximum width of the saved image. The aspect ratio is respected.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 1.0.0\n */\n width?: number;\n /**\n * The desired maximum height of the saved image. The aspect ratio is respected.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 1.0.0\n */\n height?: number;\n /**\n * Whether to automatically rotate the image \"up\" to correct for orientation\n * in portrait mode.\n * Note: This option is only supported on Android and iOS.\n * @default true\n *\n * @since 1.0.0\n */\n correctOrientation?: boolean;\n /**\n * The source to get the photo from. By default this prompts the user to select\n * either the photo album or take a photo.\n * @default CameraSource.Prompt\n *\n * @since 1.0.0\n */\n source?: CameraSource;\n /**\n * iOS and Web only: The camera direction.\n * @default CameraDirection.Rear\n *\n * @since 1.0.0\n */\n direction?: CameraDirection;\n\n /**\n * iOS only: The presentation style of the Camera.\n * @default 'fullscreen'\n *\n * @since 1.0.0\n */\n presentationStyle?: 'fullscreen' | 'popover';\n\n /**\n * Web only: Whether to use the PWA Element experience or file input. The\n * default is to use PWA Elements if installed and fall back to file input.\n * To always use file input, set this to `true`.\n *\n * Learn more about PWA Elements: https://capacitorjs.com/docs/web/pwa-elements\n *\n * @since 1.0.0\n */\n webUseInput?: boolean;\n\n /**\n * Text value to use when displaying the prompt.\n * @default 'Photo'\n *\n * @since 1.0.0\n *\n */\n promptLabelHeader?: string;\n\n /**\n * Text value to use when displaying the prompt.\n * iOS only: The label of the 'cancel' button.\n * @default 'Cancel'\n *\n * @since 1.0.0\n */\n promptLabelCancel?: string;\n\n /**\n * Text value to use when displaying the prompt.\n * The label of the button to select a saved image.\n * @default 'From Photos'\n *\n * @since 1.0.0\n */\n promptLabelPhoto?: string;\n\n /**\n * Text value to use when displaying the prompt.\n * The label of the button to open the camera.\n * @default 'Take Picture'\n *\n * @since 1.0.0\n */\n promptLabelPicture?: string;\n}\n\n/**\n * @deprecated This interface is only meant to be used for received the result of deprecated `getPhoto` method.\n * It will be removed in a future major version of the plugin, along with `getPhoto`.\n */\nexport interface Photo {\n /**\n * The base64 encoded string representation of the image, if using CameraResultType.Base64.\n *\n * @since 1.0.0\n */\n base64String?: string;\n /**\n * The url starting with 'data:image/jpeg;base64,' and the base64 encoded string representation of the image, if using CameraResultType.DataUrl.\n *\n * Note: On web, the file format could change depending on the browser.\n * @since 1.0.0\n */\n dataUrl?: string;\n /**\n * If using CameraResultType.Uri, the path will contain a full,\n * platform-specific file URL that can be read later using the Filesystem API.\n *\n * @since 1.0.0\n */\n path?: string;\n /**\n * webPath returns a path that can be used to set the src attribute of an image for efficient\n * loading and rendering.\n *\n * @since 1.0.0\n */\n webPath?: string;\n /**\n * Exif data, if any, retrieved from the image\n *\n * @since 1.0.0\n */\n exif?: any;\n /**\n * The format of the image, ex: jpeg, png, gif.\n *\n * iOS and Android only support jpeg.\n * Web supports jpeg, png and gif, but the exact availability may vary depending on the browser.\n * gif is only supported if `webUseInput` is set to `true` or if `source` is set to `Photos`.\n *\n * @since 1.0.0\n */\n format: string;\n /**\n * Whether if the image was saved to the gallery or not.\n *\n * On Android and iOS, saving to the gallery can fail if the user didn't\n * grant the required permissions.\n * On Web there is no gallery, so always returns false.\n *\n * @since 1.1.0\n */\n saved: boolean;\n}\n\nexport interface GalleryPhotos {\n /**\n * Array of all the picked photos.\n *\n * @since 1.2.0\n */\n photos: GalleryPhoto[];\n}\n\nexport interface GalleryPhoto {\n /**\n * Full, platform-specific file URL that can be read later using the Filesystem API.\n *\n * @since 1.2.0\n */\n path?: string;\n /**\n * webPath returns a path that can be used to set the src attribute of an image for efficient\n * loading and rendering.\n *\n * @since 1.2.0\n */\n webPath: string;\n /**\n * Exif data, if any, retrieved from the image\n *\n * @since 1.2.0\n */\n exif?: any;\n /**\n * The format of the image, ex: jpeg, png, gif.\n *\n * iOS and Android only support jpeg.\n * Web supports jpeg, png and gif.\n *\n * @since 1.2.0\n */\n format: string;\n}\n\n/**\n * @deprecated This interface is only meant to be used for deprecated `pickImages` method.\n * It will be removed in a future major version of the plugin, along with `pickImages`.\n */\nexport interface GalleryImageOptions {\n /**\n * The quality of image to return as JPEG, from 0-100\n * Note: This option is only supported on Android and iOS.\n *\n * @since 1.2.0\n */\n quality?: number;\n /**\n * The desired maximum width of the saved image. The aspect ratio is respected.\n *\n * @since 1.2.0\n */\n width?: number;\n /**\n * The desired maximum height of the saved image. The aspect ratio is respected.\n *\n * @since 1.2.0\n */\n height?: number;\n /**\n * Whether to automatically rotate the image \"up\" to correct for orientation\n * in portrait mode\n * @default true\n *\n * @since 1.2.0\n */\n correctOrientation?: boolean;\n\n /**\n * iOS only: The presentation style of the Camera.\n * @default 'fullscreen'\n *\n * @since 1.2.0\n */\n presentationStyle?: 'fullscreen' | 'popover';\n\n /**\n * Maximum number of pictures the user will be able to choose.\n * Note: This option is only supported on Android 13+ and iOS.\n *\n * @default 0 (unlimited)\n *\n * @since 1.2.0\n */\n limit?: number;\n}\n\n/**\n * @deprecated This enum is only meant to be used for deprecated `getPhoto` method.\n * It will be removed in a future major version of the plugin, along with `getPhoto`.\n */\nexport enum CameraSource {\n /**\n * Prompts the user to select either the photo album or take a photo.\n */\n Prompt = 'PROMPT',\n /**\n * Take a new photo using the camera.\n */\n Camera = 'CAMERA',\n /**\n * Pick an existing photo from the gallery or photo album.\n */\n Photos = 'PHOTOS',\n}\n\nexport enum CameraDirection {\n Rear = 'REAR',\n Front = 'FRONT',\n}\n\n/**\n * @deprecated This enum is only meant to be used for `ImageOptions` in deprecated `getPhoto` method.\n * It will be removed in a future major version of the plugin, along with `getPhoto`.\n */\nexport enum CameraResultType {\n Uri = 'uri',\n Base64 = 'base64',\n DataUrl = 'dataUrl',\n}\n\nexport enum MediaType {\n Photo = 0,\n Video = 1,\n}\n\nexport enum MediaTypeSelection {\n Photo = 0,\n Video = 1,\n All = 2,\n}\n\nexport enum EncodingType {\n JPEG = 0,\n PNG = 1,\n}\n\n/**\n * @deprecated Use `Photo`.\n * @since 1.0.0\n */\nexport type CameraPhoto = Photo;\n\n/**\n * @deprecated Use `ImageOptions`.\n * @since 1.0.0\n */\nexport type CameraOptions = ImageOptions;\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAsyBA;;;GAGG;AACH,MAAM,CAAN,IAAY,YAaX;AAbD,WAAY,YAAY;IACtB;;OAEG;IACH,iCAAiB,CAAA;IACjB;;OAEG;IACH,iCAAiB,CAAA;IACjB;;OAEG;IACH,iCAAiB,CAAA;AACnB,CAAC,EAbW,YAAY,KAAZ,YAAY,QAavB;AAED,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,gCAAa,CAAA;IACb,kCAAe,CAAA;AACjB,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,+BAAW,CAAA;IACX,qCAAiB,CAAA;IACjB,uCAAmB,CAAA;AACrB,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B;AAED,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,2CAAS,CAAA;IACT,2CAAS,CAAA;AACX,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAED,MAAM,CAAN,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,yDAAO,CAAA;AACT,CAAC,EAJW,kBAAkB,KAAlB,kBAAkB,QAI7B;AAED,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,+CAAQ,CAAA;IACR,6CAAO,CAAA;AACT,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB","sourcesContent":["import type { PermissionState } from '@capacitor/core';\n\nexport type CameraPermissionState = PermissionState | 'limited';\n\nexport type CameraPermissionType = 'camera' | 'photos';\n\nexport interface PermissionStatus {\n camera: CameraPermissionState;\n photos: CameraPermissionState;\n}\n\nexport interface CameraPluginPermissions {\n permissions: CameraPermissionType[];\n}\n\nexport interface CameraPlugin {\n /**\n * Open the device's camera and allow the user to take a photo.\n *\n * @since 8.1.0\n */\n takePhoto(options: TakePhotoOptions): Promise<MediaResult>;\n\n /**\n * Open the device's camera and allow the user to record a video.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n recordVideo(options: RecordVideoOptions): Promise<MediaResult>;\n\n /**\n * Open a native video player.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n playVideo(options: PlayVideoOptions): Promise<void>;\n\n /**\n * Allow users to choose pictures, videos, or both, directly from their gallery.\n *\n * @since 8.1.0\n */\n chooseFromGallery(options: ChooseFromGalleryOptions): Promise<MediaResults>;\n\n /**\n * Open an in-app screen to edit a given photo using the provided base64 string.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n editPhoto(options: EditPhotoOptions): Promise<EditPhotoResult>;\n\n /**\n * Open an in-app screen to edit a photo using the provided URI.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n editURIPhoto(options: EditURIPhotoOptions): Promise<MediaResult>;\n\n /**\n * Allows the user to update their limited photo library selection.\n * Returns all the limited photos after the picker dismissal.\n * If instead the user gave full access to the photos it returns an empty array.\n *\n * @since 4.1.0\n */\n pickLimitedLibraryPhotos(): Promise<GalleryPhotos>;\n /**\n * Return an array of photos selected from the limited photo library.\n *\n * @since 4.1.0\n */\n getLimitedLibraryPhotos(): Promise<GalleryPhotos>;\n\n /**\n * Check camera and photo album permissions\n *\n * @since 1.0.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request camera and photo album permissions\n *\n * @since 1.0.0\n */\n requestPermissions(permissions?: CameraPluginPermissions): Promise<PermissionStatus>;\n\n /**\n * Prompt the user to pick a photo from an album, or take a new photo\n * with the camera.\n *\n * @since 1.0.0\n * @deprecated Use `takePhoto` for a camera photo, or `chooseFromGallery` to select from the gallery. For creating a prompt for the user to select which source, use `@capacitor/action-sheet` or any UI component of your choosing. Refer to the Camera API documentation for more information on migrating.\n */\n getPhoto(options: ImageOptions): Promise<Photo>;\n\n /**\n * Allows the user to pick multiple pictures from the photo gallery.\n *\n * @since 1.2.0\n * @deprecated Use `chooseFromGallery` instead. Refer to the Camera API documentation for more information on migrating.\n */\n pickImages(options: GalleryImageOptions): Promise<GalleryPhotos>;\n}\n\nexport interface TakePhotoOptions {\n /**\n * The quality of image to return, from 0-100.\n * Only applicable for `EncodingType.JPEG`.\n * Note: This option is only supported on Android and iOS.\n *\n * @default 100\n * @since 8.1.0\n */\n quality?: number;\n\n /**\n * The target width of photos to apply.\n * Must be a positive number, and used along `targetHeight`.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 8.1.0\n */\n targetWidth?: number;\n\n /**\n * The target width of photos to apply.\n * Must be a positive number, and used along `targetWidth`.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 8.1.0\n */\n targetHeight?: number;\n\n /**\n * Whether to automatically rotate the image \"up\" to correct for orientation\n * in portrait mode.\n * Note: This option is only supported on Android and iOS\n * @default true\n *\n * @since 8.1.0\n */\n correctOrientation?: boolean;\n\n /**\n * The encoding type for the captured photo - JPEG or PNG.\n * Note: This option is only supported on Android and iOS.\n * @default EncodingType.JPEG\n *\n * @since 8.1.0\n */\n encodingType?: EncodingType;\n\n /**\n * Whether to save the photo to the gallery.\n * Note: This option is only supported on Android and iOS.\n * @default false\n *\n * @since 8.1.0\n */\n saveToGallery?: boolean;\n\n /**\n * iOS and Web only: The camera direction.\n * @default CameraDirection.Rear\n *\n * @since 8.1.0\n */\n cameraDirection?: CameraDirection;\n\n /**\n * Determines if and how the user can edit the photo.\n * - 'in-app': Use an in-app editor for photo edition.\n * - 'external': Open a separate (platform-specific) native app to handle photo edition, falling back to the in-app editor if none is available. Note: iOS does not support external editing and will use 'in-app' instead.\n * - 'no': No editing allowed.\n * Not available on Web.\n * @default 'no'\n *\n * @since 8.1.0\n */\n editable?: 'in-app' | 'external' | 'no';\n\n /**\n * iOS only: The presentation style of the Camera.\n * @default 'fullscreen'\n *\n * @since 8.1.0\n */\n presentationStyle?: 'fullscreen' | 'popover';\n\n /**\n * Web only: Whether to use the PWA Element experience or file input. The\n * default is to use PWA Elements if installed and fall back to file input.\n * To always use file input, set this to `true`.\n *\n * Learn more about PWA Elements: https://capacitorjs.com/docs/web/pwa-elements\n *\n * @since 8.1.0\n */\n webUseInput?: boolean;\n\n /**\n * Whether or not MediaResult should include its metadata.\n * If an error occurs when obtaining the metadata, it will return empty.\n * @default false\n *\n * @since 8.1.0\n */\n includeMetadata?: boolean;\n}\n\nexport interface RecordVideoOptions {\n /**\n * Whether to save the video to the gallery.\n * @default false\n *\n * @since 8.1.0\n */\n saveToGallery?: boolean;\n\n /**\n * Whether or not MediaResult should include its metadata.\n * If an error occurs when obtaining the metadata, it will return empty.\n * @default false\n *\n * @since 8.1.0\n */\n includeMetadata?: boolean;\n\n /**\n * Whether the to store the video in persistent app storage or in temporary cache.\n * If you plan to use the returned `MediaResult#URI` across app launches, you may want to set to true.\n * Otherwise, you can set to false.\n * @default true\n *\n * @since 8.1.0\n */\n isPersistent?: boolean;\n}\n\nexport interface PlayVideoOptions {\n /**\n * The URI of the video to play.\n * You may use the `MediaResult#URI` returned from `recordVideo` or `chooseFromGallery` directly.\n *\n * @since 8.1.0\n */\n uri: string;\n}\n\nexport interface ChooseFromGalleryOptions {\n /**\n * The type of media to select. Can be pictures, videos, or both.\n * @default MediaTypeSelection.Photo\n *\n * @since 8.1.0\n */\n mediaType?: MediaTypeSelection;\n\n /**\n * Whether or not to allow selecting multiple media files from the gallery.\n * @default false\n *\n * @since 8.1.0\n */\n allowMultipleSelection?: boolean;\n\n /**\n * The maximum number of media files that the user can choose.\n * Only applicable if `allowMultipleSelection` is `true`.\n * Any non-positive number will be treated as unlimited.\n * Note: This option is only supported on Android 13+ and iOS.\n * @default 0\n *\n * @since 8.1.0\n */\n limit?: number;\n\n /**\n * Whether or not MediaResult should include its metadata.\n * If an error occurs when obtaining the metadata, it will return empty.\n * @default false\n *\n * @since 8.1.0\n */\n includeMetadata?: boolean;\n\n /**\n * Determines if and how the user can edit the photo.\n * - 'in-app': Use an in-app editor for photo edition.\n * - 'external': Open a separate (platform-specific) native app to handle photo edition, falling back to the in-app editor if none is available. Note: iOS does not support external editing and will use 'in-app' instead.\n * - 'no': No editing allowed.\n * Only applicable for `MediaTypeSelection.Photo` and `allowMultipleSelection` set to `false`.\n * Not available on Web.\n * @default 'no'\n *\n * @since 8.1.0\n */\n editable?: 'in-app' | 'external' | 'no';\n\n /**\n * iOS only: The presentation style of media picker.\n * @default 'fullscreen'\n *\n * @since 8.1.0\n */\n presentationStyle?: 'fullscreen' | 'popover';\n\n /**\n * The quality of images to return, from 0-100.\n * Only applicable for `MediaType.Photo` and JPEG format.\n * Note: This option is only supported on Android and iOS.\n *\n * @default 100\n * @since 8.1.0\n */\n quality?: number;\n\n /**\n * The target width of photos to apply.\n * Must be a positive number, and used along `targetHeight`.\n * Not applicable when videos are selected.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 1.0.0\n */\n targetWidth?: number;\n\n /**\n * The target width of photos to apply.\n * Must be a positive number, and used along `targetWidth`.\n * Not applicable when videos are selected.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 8.1.0\n */\n targetHeight?: number;\n\n /**\n * Whether to automatically rotate the image \"up\" to correct for orientation\n * in portrait mode.\n * Not applicable when videos are selected.\n * Note: This option is only supported on Android and iOS\n * @default true\n *\n * @since 8.1.0\n */\n correctOrientation?: boolean;\n\n /**\n * Web only: Whether to use the PWA Element experience or file input. The\n * default is to use PWA Elements if installed and fall back to file input.\n * To always use file input, set this to `true`.\n *\n * Learn more about PWA Elements: https://capacitorjs.com/docs/web/pwa-elements\n *\n * @since 8.1.0\n */\n webUseInput?: boolean;\n}\n\nexport interface EditURIPhotoOptions {\n /**\n * The URI that contains the photo to edit.\n *\n * @since 8.1.0\n */\n uri: string;\n\n /**\n * Whether to save the edited photo to the gallery.\n * @default false\n *\n * @since 8.1.0\n */\n\n saveToGallery?: boolean;\n\n /**\n * Whether or not MediaResult should include its metadata.\n * If an error occurs when obtaining the metadata, it will return empty.\n * @default false\n *\n * @since 8.1.0\n */\n includeMetadata?: boolean;\n}\n\nexport interface EditPhotoOptions {\n /**\n * The base64 encoded image to edit.\n *\n * @since 8.1.0\n */\n inputImage: string;\n}\n\nexport interface EditPhotoResult {\n /**\n * The edited image, base64 encoded.\n *\n * @since 8.1.0\n */\n outputImage: string;\n}\n\nexport interface MediaResult {\n /**\n * The type of media result. Either `Photo` or `Video`.\n *\n * @since 8.1.0\n */\n type: MediaType;\n\n /**\n * The URI pointing to the media file.\n * Not available on Web. Use `webPath` instead for Web.\n *\n * @since 8.1.0\n */\n uri?: string;\n\n /**\n * Returns the thumbnail of the media, base64 encoded.\n * On Web, for `MediaType.Photo`, the full image is returned here, also base64 encoded.\n * On Web, for `MediaType.Video`, a full-resolution JPEG frame captured from the video is returned, base64 encoded at 80% quality.\n *\n * @since 8.1.0\n */\n thumbnail?: string;\n\n /**\n * Whether if the media was saved to the gallery successfully or not.\n * Only applicable if `saveToGallery` was set to `true` in input options.\n * Otherwise, `false` is always returned for `save`.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n saved: boolean;\n\n /**\n * webPath returns a path that can be used to set the src attribute of a media item for efficient\n * loading and rendering.\n *\n * @since 8.1.0\n */\n webPath?: string;\n\n /**\n * Metadata associated to the media result.\n * Only included if `includeMetadata` was set to `true` in input options.\n *\n * @since 8.1.0\n */\n metadata?: MediaMetadata;\n}\n\nexport interface MediaMetadata {\n /**\n * File size of the media, in bytes.\n *\n * @since 8.1.0\n */\n size?: number;\n\n /**\n * Only applicable for `MediaType.Video` - the duration of the media, in seconds.\n *\n * @since 8.1.0\n */\n duration?: number;\n\n /**\n * The format of the image, ex: jpeg, png, mp4.\n *\n * Android and iOS may return 'jpg' instead of 'jpeg'. The format is the same, just with a different name.\n * Please compare against both 'jpeg' and 'jpg' when checking if the format of the returned media is JPEG.\n * Web supports jpeg, png and gif, but the exact availability may vary depending on the browser.\n * gif is only supported for `chooseFromGallery` on Web.\n *\n * @since 8.1.0\n */\n format: string;\n\n /**\n * The resolution of the media, in `<width>x<height>` format. Example: '1920x1080'.\n *\n * @since 8.1.0\n */\n resolution?: string;\n\n /**\n * The date and time the media was created, in ISO 8601 format.\n * If creation date is not available (e.g. Android 7 and below), the last modified date is returned.\n * For Web, the last modified date is always returned.\n *\n * @since 8.1.0\n */\n creationDate?: string;\n\n /**\n * Exif data, if any, retreived from the media item.\n * Only available for `MediaType.Photo`.\n * Not available on Web.\n *\n * @since 8.1.0\n */\n exif?: string;\n}\n\nexport interface MediaResults {\n /**\n * The list of media results.\n *\n * @since 8.1.0\n */\n results: MediaResult[];\n}\n\n/**\n * @deprecated This interface is only meant to be used for deprecated `getPhoto` method.\n * It will be removed in a future major version of the plugin, along with `getPhoto`.\n */\nexport interface ImageOptions {\n /**\n * The quality of image to return as JPEG, from 0-100\n * Note: This option is only supported on Android and iOS.\n *\n * @since 1.0.0\n */\n quality?: number;\n /**\n * Whether to allow the user to crop or make small edits (platform specific).\n * Note: This option is only supported on Android and iOS.\n * On iOS it's only supported for CameraSource.Camera, but not for CameraSource.Photos.\n *\n * @since 1.0.0\n */\n allowEditing?: boolean;\n /**\n * How the data should be returned. Currently, only 'Base64', 'DataUrl' or 'Uri' is supported\n *\n * @since 1.0.0\n */\n resultType: CameraResultType;\n /**\n * Whether to save the photo to the gallery.\n * If the photo was picked from the gallery, it will only be saved if edited.\n * Note: This option is only supported on Android and iOS.\n * @default false\n *\n * @since 1.0.0\n */\n saveToGallery?: boolean;\n /**\n * The desired maximum width of the saved image. The aspect ratio is respected.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 1.0.0\n */\n width?: number;\n /**\n * The desired maximum height of the saved image. The aspect ratio is respected.\n * Note: This option is only supported on Android and iOS.\n *\n * @since 1.0.0\n */\n height?: number;\n /**\n * Whether to automatically rotate the image \"up\" to correct for orientation\n * in portrait mode.\n * Note: This option is only supported on Android and iOS.\n * @default true\n *\n * @since 1.0.0\n */\n correctOrientation?: boolean;\n /**\n * The source to get the photo from. By default this prompts the user to select\n * either the photo album or take a photo.\n * @default CameraSource.Prompt\n *\n * @since 1.0.0\n */\n source?: CameraSource;\n /**\n * iOS and Web only: The camera direction.\n * @default CameraDirection.Rear\n *\n * @since 1.0.0\n */\n direction?: CameraDirection;\n\n /**\n * iOS only: The presentation style of the Camera.\n * @default 'fullscreen'\n *\n * @since 1.0.0\n */\n presentationStyle?: 'fullscreen' | 'popover';\n\n /**\n * Web only: Whether to use the PWA Element experience or file input. The\n * default is to use PWA Elements if installed and fall back to file input.\n * To always use file input, set this to `true`.\n *\n * Learn more about PWA Elements: https://capacitorjs.com/docs/web/pwa-elements\n *\n * @since 1.0.0\n */\n webUseInput?: boolean;\n\n /**\n * Text value to use when displaying the prompt.\n * @default 'Photo'\n *\n * @since 1.0.0\n *\n */\n promptLabelHeader?: string;\n\n /**\n * Text value to use when displaying the prompt.\n * iOS only: The label of the 'cancel' button.\n * @default 'Cancel'\n *\n * @since 1.0.0\n */\n promptLabelCancel?: string;\n\n /**\n * Text value to use when displaying the prompt.\n * The label of the button to select a saved image.\n * @default 'From Photos'\n *\n * @since 1.0.0\n */\n promptLabelPhoto?: string;\n\n /**\n * Text value to use when displaying the prompt.\n * The label of the button to open the camera.\n * @default 'Take Picture'\n *\n * @since 1.0.0\n */\n promptLabelPicture?: string;\n}\n\n/**\n * @deprecated This interface is only meant to be used for received the result of deprecated `getPhoto` method.\n * It will be removed in a future major version of the plugin, along with `getPhoto`.\n */\nexport interface Photo {\n /**\n * The base64 encoded string representation of the image, if using CameraResultType.Base64.\n *\n * @since 1.0.0\n */\n base64String?: string;\n /**\n * The url starting with 'data:image/jpeg;base64,' and the base64 encoded string representation of the image, if using CameraResultType.DataUrl.\n *\n * Note: On web, the file format could change depending on the browser.\n * @since 1.0.0\n */\n dataUrl?: string;\n /**\n * If using CameraResultType.Uri, the path will contain a full,\n * platform-specific file URL that can be read later using the Filesystem API.\n *\n * @since 1.0.0\n */\n path?: string;\n /**\n * webPath returns a path that can be used to set the src attribute of an image for efficient\n * loading and rendering.\n *\n * @since 1.0.0\n */\n webPath?: string;\n /**\n * Exif data, if any, retrieved from the image\n *\n * @since 1.0.0\n */\n exif?: any;\n /**\n * The format of the image, ex: jpeg, png, gif.\n *\n * iOS and Android only support jpeg.\n * Web supports jpeg, png and gif, but the exact availability may vary depending on the browser.\n * gif is only supported if `webUseInput` is set to `true` or if `source` is set to `Photos`.\n *\n * @since 1.0.0\n */\n format: string;\n /**\n * Whether if the image was saved to the gallery or not.\n *\n * On Android and iOS, saving to the gallery can fail if the user didn't\n * grant the required permissions.\n * On Web there is no gallery, so always returns false.\n *\n * @since 1.1.0\n */\n saved: boolean;\n}\n\nexport interface GalleryPhotos {\n /**\n * Array of all the picked photos.\n *\n * @since 1.2.0\n */\n photos: GalleryPhoto[];\n}\n\nexport interface GalleryPhoto {\n /**\n * Full, platform-specific file URL that can be read later using the Filesystem API.\n *\n * @since 1.2.0\n */\n path?: string;\n /**\n * webPath returns a path that can be used to set the src attribute of an image for efficient\n * loading and rendering.\n *\n * @since 1.2.0\n */\n webPath: string;\n /**\n * Exif data, if any, retrieved from the image\n *\n * @since 1.2.0\n */\n exif?: any;\n /**\n * The format of the image, ex: jpeg, png, gif.\n *\n * iOS and Android only support jpeg.\n * Web supports jpeg, png and gif.\n *\n * @since 1.2.0\n */\n format: string;\n}\n\n/**\n * @deprecated This interface is only meant to be used for deprecated `pickImages` method.\n * It will be removed in a future major version of the plugin, along with `pickImages`.\n */\nexport interface GalleryImageOptions {\n /**\n * The quality of image to return as JPEG, from 0-100\n * Note: This option is only supported on Android and iOS.\n *\n * @since 1.2.0\n */\n quality?: number;\n /**\n * The desired maximum width of the saved image. The aspect ratio is respected.\n *\n * @since 1.2.0\n */\n width?: number;\n /**\n * The desired maximum height of the saved image. The aspect ratio is respected.\n *\n * @since 1.2.0\n */\n height?: number;\n /**\n * Whether to automatically rotate the image \"up\" to correct for orientation\n * in portrait mode\n * @default true\n *\n * @since 1.2.0\n */\n correctOrientation?: boolean;\n\n /**\n * iOS only: The presentation style of the Camera.\n * @default 'fullscreen'\n *\n * @since 1.2.0\n */\n presentationStyle?: 'fullscreen' | 'popover';\n\n /**\n * Maximum number of pictures the user will be able to choose.\n * Note: This option is only supported on Android 13+ and iOS.\n *\n * @default 0 (unlimited)\n *\n * @since 1.2.0\n */\n limit?: number;\n}\n\n/**\n * @deprecated This enum is only meant to be used for deprecated `getPhoto` method.\n * It will be removed in a future major version of the plugin, along with `getPhoto`.\n */\nexport enum CameraSource {\n /**\n * Prompts the user to select either the photo album or take a photo.\n */\n Prompt = 'PROMPT',\n /**\n * Take a new photo using the camera.\n */\n Camera = 'CAMERA',\n /**\n * Pick an existing photo from the gallery or photo album.\n */\n Photos = 'PHOTOS',\n}\n\nexport enum CameraDirection {\n Rear = 'REAR',\n Front = 'FRONT',\n}\n\n/**\n * @deprecated This enum is only meant to be used for `ImageOptions` in deprecated `getPhoto` method.\n * It will be removed in a future major version of the plugin, along with `getPhoto`.\n */\nexport enum CameraResultType {\n Uri = 'uri',\n Base64 = 'base64',\n DataUrl = 'dataUrl',\n}\n\nexport enum MediaType {\n Photo = 0,\n Video = 1,\n}\n\nexport enum MediaTypeSelection {\n Photo = 0,\n Video = 1,\n All = 2,\n}\n\nexport enum EncodingType {\n JPEG = 0,\n PNG = 1,\n}\n\n/**\n * @deprecated Use `Photo`.\n * @since 1.0.0\n */\nexport type CameraPhoto = Photo;\n\n/**\n * @deprecated Use `ImageOptions`.\n * @since 1.0.0\n */\nexport type CameraOptions = ImageOptions;\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
2
|
import type { CameraPlugin, GalleryImageOptions, GalleryPhotos, ImageOptions, PermissionStatus, Photo, RecordVideoOptions, EditPhotoOptions, PlayVideoOptions, EditURIPhotoOptions, EditPhotoResult, MediaResult, MediaResults, ChooseFromGalleryOptions, TakePhotoOptions } from './definitions';
|
|
3
3
|
export declare class CameraWeb extends WebPlugin implements CameraPlugin {
|
|
4
|
-
takePhoto(
|
|
4
|
+
takePhoto(options: TakePhotoOptions): Promise<MediaResult>;
|
|
5
5
|
recordVideo(_options: RecordVideoOptions): Promise<MediaResult>;
|
|
6
6
|
playVideo(_options: PlayVideoOptions): Promise<void>;
|
|
7
|
-
chooseFromGallery(
|
|
7
|
+
chooseFromGallery(options: ChooseFromGalleryOptions): Promise<MediaResults>;
|
|
8
8
|
editPhoto(_options: EditPhotoOptions): Promise<EditPhotoResult>;
|
|
9
9
|
editURIPhoto(_options: EditURIPhotoOptions): Promise<MediaResult>;
|
|
10
10
|
getPhoto(options: ImageOptions): Promise<Photo>;
|
|
@@ -13,6 +13,17 @@ export declare class CameraWeb extends WebPlugin implements CameraPlugin {
|
|
|
13
13
|
private fileInputExperience;
|
|
14
14
|
private multipleFileInputExperience;
|
|
15
15
|
private _getCameraPhoto;
|
|
16
|
+
private takePhotoCameraExperience;
|
|
17
|
+
private takePhotoCameraInputExperience;
|
|
18
|
+
private galleryInputExperience;
|
|
19
|
+
private _getFileFormat;
|
|
20
|
+
private _buildPhotoMediaResult;
|
|
21
|
+
private _validateFileInput;
|
|
22
|
+
private _setupPWACameraModal;
|
|
23
|
+
private _createFileInput;
|
|
24
|
+
private _getImageResolution;
|
|
25
|
+
private _getBase64FromFile;
|
|
26
|
+
private _getVideoMetadata;
|
|
16
27
|
checkPermissions(): Promise<PermissionStatus>;
|
|
17
28
|
requestPermissions(): Promise<PermissionStatus>;
|
|
18
29
|
pickLimitedLibraryPhotos(): Promise<GalleryPhotos>;
|
package/dist/esm/web.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { WebPlugin, CapacitorException } from '@capacitor/core';
|
|
2
|
-
import { CameraSource, CameraDirection } from './definitions';
|
|
2
|
+
import { CameraSource, CameraDirection, MediaType, MediaTypeSelection } from './definitions';
|
|
3
3
|
export class CameraWeb extends WebPlugin {
|
|
4
|
-
async takePhoto(
|
|
5
|
-
|
|
4
|
+
async takePhoto(options) {
|
|
5
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
6
|
+
return new Promise(async (resolve, reject) => {
|
|
7
|
+
if (options.webUseInput) {
|
|
8
|
+
this.takePhotoCameraInputExperience(options, resolve, reject);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
this.takePhotoCameraExperience(options, resolve, reject);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
6
14
|
}
|
|
7
15
|
async recordVideo(_options) {
|
|
8
16
|
throw this.unimplemented('recordVideo is not implemented on Web.');
|
|
@@ -10,8 +18,11 @@ export class CameraWeb extends WebPlugin {
|
|
|
10
18
|
async playVideo(_options) {
|
|
11
19
|
throw this.unimplemented('playVideo is not implemented on Web.');
|
|
12
20
|
}
|
|
13
|
-
async chooseFromGallery(
|
|
14
|
-
|
|
21
|
+
async chooseFromGallery(options) {
|
|
22
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
23
|
+
return new Promise(async (resolve, reject) => {
|
|
24
|
+
this.galleryInputExperience(options, resolve, reject);
|
|
25
|
+
});
|
|
15
26
|
}
|
|
16
27
|
async editPhoto(_options) {
|
|
17
28
|
throw this.unimplemented('editPhoto is not implemented on Web.');
|
|
@@ -59,36 +70,7 @@ export class CameraWeb extends WebPlugin {
|
|
|
59
70
|
});
|
|
60
71
|
}
|
|
61
72
|
async cameraExperience(options, resolve, reject) {
|
|
62
|
-
|
|
63
|
-
const cameraModal = document.createElement('pwa-camera-modal');
|
|
64
|
-
cameraModal.facingMode = options.direction === CameraDirection.Front ? 'user' : 'environment';
|
|
65
|
-
document.body.appendChild(cameraModal);
|
|
66
|
-
try {
|
|
67
|
-
await cameraModal.componentOnReady();
|
|
68
|
-
cameraModal.addEventListener('onPhoto', async (e) => {
|
|
69
|
-
const photo = e.detail;
|
|
70
|
-
if (photo === null) {
|
|
71
|
-
reject(new CapacitorException('User cancelled photos app'));
|
|
72
|
-
}
|
|
73
|
-
else if (photo instanceof Error) {
|
|
74
|
-
reject(photo);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
resolve(await this._getCameraPhoto(photo, options));
|
|
78
|
-
}
|
|
79
|
-
cameraModal.dismiss();
|
|
80
|
-
document.body.removeChild(cameraModal);
|
|
81
|
-
});
|
|
82
|
-
cameraModal.present();
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
this.fileInputExperience(options, resolve, reject);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
console.error(`Unable to load PWA Element 'pwa-camera-modal'. See the docs: https://capacitorjs.com/docs/web/pwa-elements.`);
|
|
90
|
-
this.fileInputExperience(options, resolve, reject);
|
|
91
|
-
}
|
|
73
|
+
await this._setupPWACameraModal(options.direction, (photo) => this._getCameraPhoto(photo, options), () => this.fileInputExperience(options, resolve, reject), resolve, reject);
|
|
92
74
|
}
|
|
93
75
|
fileInputExperience(options, resolve, reject) {
|
|
94
76
|
let input = document.querySelector('#_capacitor-camera-input');
|
|
@@ -201,11 +183,11 @@ export class CameraWeb extends WebPlugin {
|
|
|
201
183
|
_getCameraPhoto(photo, options) {
|
|
202
184
|
return new Promise((resolve, reject) => {
|
|
203
185
|
const reader = new FileReader();
|
|
204
|
-
const format =
|
|
186
|
+
const format = this._getFileFormat(photo);
|
|
205
187
|
if (options.resultType === 'uri') {
|
|
206
188
|
resolve({
|
|
207
189
|
webPath: URL.createObjectURL(photo),
|
|
208
|
-
format
|
|
190
|
+
format,
|
|
209
191
|
saved: false,
|
|
210
192
|
});
|
|
211
193
|
}
|
|
@@ -216,14 +198,14 @@ export class CameraWeb extends WebPlugin {
|
|
|
216
198
|
if (options.resultType === 'dataUrl') {
|
|
217
199
|
resolve({
|
|
218
200
|
dataUrl: r,
|
|
219
|
-
format
|
|
201
|
+
format,
|
|
220
202
|
saved: false,
|
|
221
203
|
});
|
|
222
204
|
}
|
|
223
205
|
else {
|
|
224
206
|
resolve({
|
|
225
207
|
base64String: r.split(',')[1],
|
|
226
|
-
format
|
|
208
|
+
format,
|
|
227
209
|
saved: false,
|
|
228
210
|
});
|
|
229
211
|
}
|
|
@@ -234,6 +216,265 @@ export class CameraWeb extends WebPlugin {
|
|
|
234
216
|
}
|
|
235
217
|
});
|
|
236
218
|
}
|
|
219
|
+
async takePhotoCameraExperience(options, resolve, reject) {
|
|
220
|
+
await this._setupPWACameraModal(options.cameraDirection, (photo) => { var _a; return this._buildPhotoMediaResult(photo, (_a = options.includeMetadata) !== null && _a !== void 0 ? _a : false); }, () => this.takePhotoCameraInputExperience(options, resolve, reject), resolve, reject);
|
|
221
|
+
}
|
|
222
|
+
takePhotoCameraInputExperience(options, resolve, reject) {
|
|
223
|
+
const input = this._createFileInput('_capacitor-camera-input-takephoto');
|
|
224
|
+
const cleanup = () => {
|
|
225
|
+
var _a;
|
|
226
|
+
(_a = input.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(input);
|
|
227
|
+
};
|
|
228
|
+
input.onchange = async (_e) => {
|
|
229
|
+
var _a;
|
|
230
|
+
if (!this._validateFileInput(input, reject, cleanup)) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const file = input.files[0];
|
|
234
|
+
resolve(await this._buildPhotoMediaResult(file, (_a = options.includeMetadata) !== null && _a !== void 0 ? _a : false));
|
|
235
|
+
cleanup();
|
|
236
|
+
};
|
|
237
|
+
input.oncancel = () => {
|
|
238
|
+
reject(new CapacitorException('User cancelled photos app'));
|
|
239
|
+
cleanup();
|
|
240
|
+
};
|
|
241
|
+
input.accept = 'image/*';
|
|
242
|
+
if (options.cameraDirection === CameraDirection.Front) {
|
|
243
|
+
input.capture = 'user';
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
// CameraDirection.Rear
|
|
247
|
+
input.capture = 'environment';
|
|
248
|
+
}
|
|
249
|
+
input.click();
|
|
250
|
+
}
|
|
251
|
+
galleryInputExperience(options, resolve, reject) {
|
|
252
|
+
var _a, _b;
|
|
253
|
+
const input = this._createFileInput('_capacitor-camera-input-gallery');
|
|
254
|
+
input.multiple = (_a = options.allowMultipleSelection) !== null && _a !== void 0 ? _a : false;
|
|
255
|
+
const cleanup = () => {
|
|
256
|
+
var _a;
|
|
257
|
+
(_a = input.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(input);
|
|
258
|
+
};
|
|
259
|
+
input.onchange = async (_e) => {
|
|
260
|
+
var _a;
|
|
261
|
+
if (!this._validateFileInput(input, reject, cleanup)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const results = [];
|
|
265
|
+
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
266
|
+
for (let i = 0; i < input.files.length; i++) {
|
|
267
|
+
const file = input.files[i];
|
|
268
|
+
if (file.type.startsWith('image/')) {
|
|
269
|
+
results.push(await this._buildPhotoMediaResult(file, (_a = options.includeMetadata) !== null && _a !== void 0 ? _a : false));
|
|
270
|
+
}
|
|
271
|
+
else if (file.type.startsWith('video/')) {
|
|
272
|
+
const format = this._getFileFormat(file);
|
|
273
|
+
let thumbnail;
|
|
274
|
+
let resolution;
|
|
275
|
+
let duration;
|
|
276
|
+
try {
|
|
277
|
+
const videoInfo = await this._getVideoMetadata(file);
|
|
278
|
+
thumbnail = videoInfo.thumbnail;
|
|
279
|
+
if (options.includeMetadata) {
|
|
280
|
+
resolution = videoInfo.resolution;
|
|
281
|
+
duration = videoInfo.duration;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch (e) {
|
|
285
|
+
console.warn('Failed to get video metadata:', e);
|
|
286
|
+
}
|
|
287
|
+
const result = {
|
|
288
|
+
type: MediaType.Video,
|
|
289
|
+
thumbnail,
|
|
290
|
+
webPath: URL.createObjectURL(file),
|
|
291
|
+
saved: false,
|
|
292
|
+
};
|
|
293
|
+
if (options.includeMetadata) {
|
|
294
|
+
result.metadata = {
|
|
295
|
+
format,
|
|
296
|
+
resolution,
|
|
297
|
+
size: file.size,
|
|
298
|
+
creationDate: new Date(file.lastModified).toISOString(),
|
|
299
|
+
duration,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
results.push(result);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
resolve({ results });
|
|
306
|
+
cleanup();
|
|
307
|
+
};
|
|
308
|
+
input.oncancel = () => {
|
|
309
|
+
reject(new CapacitorException('User cancelled photos app'));
|
|
310
|
+
cleanup();
|
|
311
|
+
};
|
|
312
|
+
// Set accept attribute based on mediaType
|
|
313
|
+
const mediaType = (_b = options.mediaType) !== null && _b !== void 0 ? _b : MediaTypeSelection.Photo;
|
|
314
|
+
if (mediaType === MediaTypeSelection.Photo) {
|
|
315
|
+
input.accept = 'image/*';
|
|
316
|
+
}
|
|
317
|
+
else if (mediaType === MediaTypeSelection.Video) {
|
|
318
|
+
input.accept = 'video/*';
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
// MediaTypeSelection.All
|
|
322
|
+
input.accept = 'image/*,video/*';
|
|
323
|
+
}
|
|
324
|
+
input.click();
|
|
325
|
+
}
|
|
326
|
+
_getFileFormat(file) {
|
|
327
|
+
if (file.type === 'image/png') {
|
|
328
|
+
return 'png';
|
|
329
|
+
}
|
|
330
|
+
else if (file.type === 'image/gif') {
|
|
331
|
+
return 'gif';
|
|
332
|
+
}
|
|
333
|
+
else if (file.type.startsWith('video/')) {
|
|
334
|
+
return file.type.split('/')[1];
|
|
335
|
+
}
|
|
336
|
+
else if (file.type.startsWith('image/')) {
|
|
337
|
+
return 'jpeg';
|
|
338
|
+
}
|
|
339
|
+
return file.type.split('/')[1] || 'jpeg';
|
|
340
|
+
}
|
|
341
|
+
async _buildPhotoMediaResult(file, includeMetadata) {
|
|
342
|
+
const format = this._getFileFormat(file);
|
|
343
|
+
const thumbnail = await this._getBase64FromFile(file);
|
|
344
|
+
const result = {
|
|
345
|
+
type: MediaType.Photo,
|
|
346
|
+
thumbnail,
|
|
347
|
+
webPath: URL.createObjectURL(file),
|
|
348
|
+
saved: false,
|
|
349
|
+
};
|
|
350
|
+
if (includeMetadata) {
|
|
351
|
+
const resolution = await this._getImageResolution(file);
|
|
352
|
+
result.metadata = {
|
|
353
|
+
format,
|
|
354
|
+
resolution,
|
|
355
|
+
size: file.size,
|
|
356
|
+
creationDate: 'lastModified' in file ? new Date(file.lastModified).toISOString() : new Date().toISOString(),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
return result;
|
|
360
|
+
}
|
|
361
|
+
_validateFileInput(input, reject, cleanup) {
|
|
362
|
+
if (!input.files || input.files.length === 0) {
|
|
363
|
+
const message = input.multiple ? 'No files selected' : 'No file selected';
|
|
364
|
+
reject(new CapacitorException(message));
|
|
365
|
+
cleanup();
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
async _setupPWACameraModal(cameraDirection, onPhotoCallback, fallbackCallback, resolve, reject) {
|
|
371
|
+
if (customElements.get('pwa-camera-modal')) {
|
|
372
|
+
const cameraModal = document.createElement('pwa-camera-modal');
|
|
373
|
+
cameraModal.facingMode = cameraDirection === CameraDirection.Front ? 'user' : 'environment';
|
|
374
|
+
document.body.appendChild(cameraModal);
|
|
375
|
+
try {
|
|
376
|
+
await cameraModal.componentOnReady();
|
|
377
|
+
cameraModal.addEventListener('onPhoto', async (e) => {
|
|
378
|
+
const photo = e.detail;
|
|
379
|
+
if (photo === null) {
|
|
380
|
+
reject(new CapacitorException('User cancelled photos app'));
|
|
381
|
+
}
|
|
382
|
+
else if (photo instanceof Error) {
|
|
383
|
+
reject(photo);
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
resolve(await onPhotoCallback(photo));
|
|
387
|
+
}
|
|
388
|
+
cameraModal.dismiss();
|
|
389
|
+
document.body.removeChild(cameraModal);
|
|
390
|
+
});
|
|
391
|
+
cameraModal.present();
|
|
392
|
+
}
|
|
393
|
+
catch (e) {
|
|
394
|
+
fallbackCallback();
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
console.error(`Unable to load PWA Element 'pwa-camera-modal'. See the docs: https://capacitorjs.com/docs/web/pwa-elements.`);
|
|
399
|
+
fallbackCallback();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
_createFileInput(id) {
|
|
403
|
+
let input = document.querySelector(`#${id}`);
|
|
404
|
+
if (!input) {
|
|
405
|
+
input = document.createElement('input');
|
|
406
|
+
input.id = id;
|
|
407
|
+
input.type = 'file';
|
|
408
|
+
input.hidden = true;
|
|
409
|
+
document.body.appendChild(input);
|
|
410
|
+
}
|
|
411
|
+
return input;
|
|
412
|
+
}
|
|
413
|
+
async _getImageResolution(image) {
|
|
414
|
+
try {
|
|
415
|
+
const bitmap = await createImageBitmap(image);
|
|
416
|
+
const resolution = `${bitmap.width}x${bitmap.height}`;
|
|
417
|
+
bitmap.close();
|
|
418
|
+
return resolution;
|
|
419
|
+
}
|
|
420
|
+
catch (e) {
|
|
421
|
+
console.warn('Failed to get image resolution:', e);
|
|
422
|
+
return undefined;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
_getBase64FromFile(file) {
|
|
426
|
+
return new Promise((resolve, reject) => {
|
|
427
|
+
const reader = new FileReader();
|
|
428
|
+
reader.onloadend = () => {
|
|
429
|
+
const dataUrl = reader.result;
|
|
430
|
+
const base64 = dataUrl.split(',')[1];
|
|
431
|
+
resolve(base64);
|
|
432
|
+
};
|
|
433
|
+
reader.onerror = (e) => {
|
|
434
|
+
reject(e);
|
|
435
|
+
};
|
|
436
|
+
reader.readAsDataURL(file);
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
_getVideoMetadata(videoFile) {
|
|
440
|
+
return new Promise((resolve) => {
|
|
441
|
+
const video = document.createElement('video');
|
|
442
|
+
video.preload = 'metadata';
|
|
443
|
+
video.muted = true;
|
|
444
|
+
video.onloadedmetadata = () => {
|
|
445
|
+
// Seek to 1 second or 10% of duration to capture thumbnail
|
|
446
|
+
const seekTime = Math.min(1, video.duration * 0.1);
|
|
447
|
+
video.currentTime = seekTime;
|
|
448
|
+
};
|
|
449
|
+
video.onseeked = () => {
|
|
450
|
+
const result = {
|
|
451
|
+
resolution: `${video.videoWidth}x${video.videoHeight}`,
|
|
452
|
+
duration: video.duration,
|
|
453
|
+
};
|
|
454
|
+
try {
|
|
455
|
+
const canvas = document.createElement('canvas');
|
|
456
|
+
canvas.width = video.videoWidth;
|
|
457
|
+
canvas.height = video.videoHeight;
|
|
458
|
+
const ctx = canvas.getContext('2d');
|
|
459
|
+
if (ctx) {
|
|
460
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
461
|
+
result.thumbnail = canvas.toDataURL('image/jpeg', 0.8).split(',')[1];
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
catch (e) {
|
|
465
|
+
console.warn('Failed to generate video thumbnail:', e);
|
|
466
|
+
}
|
|
467
|
+
URL.revokeObjectURL(video.src);
|
|
468
|
+
resolve(result);
|
|
469
|
+
};
|
|
470
|
+
video.onerror = () => {
|
|
471
|
+
// Clean up and return defaults
|
|
472
|
+
URL.revokeObjectURL(video.src);
|
|
473
|
+
resolve({});
|
|
474
|
+
};
|
|
475
|
+
video.src = URL.createObjectURL(videoFile);
|
|
476
|
+
});
|
|
477
|
+
}
|
|
237
478
|
async checkPermissions() {
|
|
238
479
|
if (typeof navigator === 'undefined' || !navigator.permissions) {
|
|
239
480
|
throw this.unavailable('Permissions API not available in this browser');
|