definitions.d.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. import type { PermissionState } from '@capacitor/core';
  2. export declare type CameraPermissionState = PermissionState | 'limited';
  3. export declare type CameraPermissionType = 'camera' | 'photos';
  4. export interface PermissionStatus {
  5. camera: CameraPermissionState;
  6. photos: CameraPermissionState;
  7. }
  8. export interface CameraPluginPermissions {
  9. permissions: CameraPermissionType[];
  10. }
  11. export interface CameraPlugin {
  12. /**
  13. * Prompt the user to pick a photo from an album, or take a new photo
  14. * with the camera.
  15. *
  16. * @since 1.0.0
  17. */
  18. getPhoto(options: ImageOptions): Promise<Photo>;
  19. /**
  20. * Allows the user to pick multiple pictures from the photo gallery.
  21. * On iOS 13 and older it only allows to pick one picture.
  22. *
  23. * @since 1.2.0
  24. */
  25. pickImages(options: GalleryImageOptions): Promise<GalleryPhotos>;
  26. /**
  27. * iOS 14+ Only: Allows the user to update their limited photo library selection.
  28. * On iOS 15+ returns all the limited photos after the picker dismissal.
  29. * On iOS 14 or if the user gave full access to the photos it returns an empty array.
  30. *
  31. * @since 4.1.0
  32. */
  33. pickLimitedLibraryPhotos(): Promise<GalleryPhotos>;
  34. /**
  35. * iOS 14+ Only: Return an array of photos selected from the limited photo library.
  36. *
  37. * @since 4.1.0
  38. */
  39. getLimitedLibraryPhotos(): Promise<GalleryPhotos>;
  40. /**
  41. * Check camera and photo album permissions
  42. *
  43. * @since 1.0.0
  44. */
  45. checkPermissions(): Promise<PermissionStatus>;
  46. /**
  47. * Request camera and photo album permissions
  48. *
  49. * @since 1.0.0
  50. */
  51. requestPermissions(permissions?: CameraPluginPermissions): Promise<PermissionStatus>;
  52. }
  53. export interface ImageOptions {
  54. /**
  55. * The quality of image to return as JPEG, from 0-100
  56. * Note: This option is only supported on Android and iOS
  57. *
  58. * @since 1.0.0
  59. */
  60. quality?: number;
  61. /**
  62. * Whether to allow the user to crop or make small edits (platform specific).
  63. * On iOS 14+ it's only supported for CameraSource.Camera, but not for CameraSource.Photos.
  64. *
  65. * @since 1.0.0
  66. */
  67. allowEditing?: boolean;
  68. /**
  69. * How the data should be returned. Currently, only 'Base64', 'DataUrl' or 'Uri' is supported
  70. *
  71. * @since 1.0.0
  72. */
  73. resultType: CameraResultType;
  74. /**
  75. * Whether to save the photo to the gallery.
  76. * If the photo was picked from the gallery, it will only be saved if edited.
  77. * @default: false
  78. *
  79. * @since 1.0.0
  80. */
  81. saveToGallery?: boolean;
  82. /**
  83. * The desired maximum width of the saved image. The aspect ratio is respected.
  84. *
  85. * @since 1.0.0
  86. */
  87. width?: number;
  88. /**
  89. * The desired maximum height of the saved image. The aspect ratio is respected.
  90. *
  91. * @since 1.0.0
  92. */
  93. height?: number;
  94. /**
  95. * Whether to automatically rotate the image "up" to correct for orientation
  96. * in portrait mode
  97. * @default: true
  98. *
  99. * @since 1.0.0
  100. */
  101. correctOrientation?: boolean;
  102. /**
  103. * The source to get the photo from. By default this prompts the user to select
  104. * either the photo album or take a photo.
  105. * @default: CameraSource.Prompt
  106. *
  107. * @since 1.0.0
  108. */
  109. source?: CameraSource;
  110. /**
  111. * iOS and Web only: The camera direction.
  112. * @default: CameraDirection.Rear
  113. *
  114. * @since 1.0.0
  115. */
  116. direction?: CameraDirection;
  117. /**
  118. * iOS only: The presentation style of the Camera.
  119. * @default: 'fullscreen'
  120. *
  121. * @since 1.0.0
  122. */
  123. presentationStyle?: 'fullscreen' | 'popover';
  124. /**
  125. * Web only: Whether to use the PWA Element experience or file input. The
  126. * default is to use PWA Elements if installed and fall back to file input.
  127. * To always use file input, set this to `true`.
  128. *
  129. * Learn more about PWA Elements: https://capacitorjs.com/docs/web/pwa-elements
  130. *
  131. * @since 1.0.0
  132. */
  133. webUseInput?: boolean;
  134. /**
  135. * Text value to use when displaying the prompt.
  136. * @default: 'Photo'
  137. *
  138. * @since 1.0.0
  139. *
  140. */
  141. promptLabelHeader?: string;
  142. /**
  143. * Text value to use when displaying the prompt.
  144. * iOS only: The label of the 'cancel' button.
  145. * @default: 'Cancel'
  146. *
  147. * @since 1.0.0
  148. */
  149. promptLabelCancel?: string;
  150. /**
  151. * Text value to use when displaying the prompt.
  152. * The label of the button to select a saved image.
  153. * @default: 'From Photos'
  154. *
  155. * @since 1.0.0
  156. */
  157. promptLabelPhoto?: string;
  158. /**
  159. * Text value to use when displaying the prompt.
  160. * The label of the button to open the camera.
  161. * @default: 'Take Picture'
  162. *
  163. * @since 1.0.0
  164. */
  165. promptLabelPicture?: string;
  166. }
  167. export interface Photo {
  168. /**
  169. * The base64 encoded string representation of the image, if using CameraResultType.Base64.
  170. *
  171. * @since 1.0.0
  172. */
  173. base64String?: string;
  174. /**
  175. * The url starting with 'data:image/jpeg;base64,' and the base64 encoded string representation of the image, if using CameraResultType.DataUrl.
  176. *
  177. * Note: On web, the file format could change depending on the browser.
  178. * @since 1.0.0
  179. */
  180. dataUrl?: string;
  181. /**
  182. * If using CameraResultType.Uri, the path will contain a full,
  183. * platform-specific file URL that can be read later using the Filesystem API.
  184. *
  185. * @since 1.0.0
  186. */
  187. path?: string;
  188. /**
  189. * webPath returns a path that can be used to set the src attribute of an image for efficient
  190. * loading and rendering.
  191. *
  192. * @since 1.0.0
  193. */
  194. webPath?: string;
  195. /**
  196. * Exif data, if any, retrieved from the image
  197. *
  198. * @since 1.0.0
  199. */
  200. exif?: any;
  201. /**
  202. * The format of the image, ex: jpeg, png, gif.
  203. *
  204. * iOS and Android only support jpeg.
  205. * Web supports jpeg, png and gif, but the exact availability may vary depending on the browser.
  206. * gif is only supported if `webUseInput` is set to `true` or if `source` is set to `Photos`.
  207. *
  208. * @since 1.0.0
  209. */
  210. format: string;
  211. /**
  212. * Whether if the image was saved to the gallery or not.
  213. *
  214. * On Android and iOS, saving to the gallery can fail if the user didn't
  215. * grant the required permissions.
  216. * On Web there is no gallery, so always returns false.
  217. *
  218. * @since 1.1.0
  219. */
  220. saved: boolean;
  221. }
  222. export interface GalleryPhotos {
  223. /**
  224. * Array of all the picked photos.
  225. *
  226. * @since 1.2.0
  227. */
  228. photos: GalleryPhoto[];
  229. }
  230. export interface GalleryPhoto {
  231. /**
  232. * Full, platform-specific file URL that can be read later using the Filesystem API.
  233. *
  234. * @since 1.2.0
  235. */
  236. path?: string;
  237. /**
  238. * webPath returns a path that can be used to set the src attribute of an image for efficient
  239. * loading and rendering.
  240. *
  241. * @since 1.2.0
  242. */
  243. webPath: string;
  244. /**
  245. * Exif data, if any, retrieved from the image
  246. *
  247. * @since 1.2.0
  248. */
  249. exif?: any;
  250. /**
  251. * The format of the image, ex: jpeg, png, gif.
  252. *
  253. * iOS and Android only support jpeg.
  254. * Web supports jpeg, png and gif.
  255. *
  256. * @since 1.2.0
  257. */
  258. format: string;
  259. }
  260. export interface GalleryImageOptions {
  261. /**
  262. * The quality of image to return as JPEG, from 0-100
  263. * Note: This option is only supported on Android and iOS.
  264. *
  265. * @since 1.2.0
  266. */
  267. quality?: number;
  268. /**
  269. * The desired maximum width of the saved image. The aspect ratio is respected.
  270. *
  271. * @since 1.2.0
  272. */
  273. width?: number;
  274. /**
  275. * The desired maximum height of the saved image. The aspect ratio is respected.
  276. *
  277. * @since 1.2.0
  278. */
  279. height?: number;
  280. /**
  281. * Whether to automatically rotate the image "up" to correct for orientation
  282. * in portrait mode
  283. * @default: true
  284. *
  285. * @since 1.2.0
  286. */
  287. correctOrientation?: boolean;
  288. /**
  289. * iOS only: The presentation style of the Camera.
  290. * @default: 'fullscreen'
  291. *
  292. * @since 1.2.0
  293. */
  294. presentationStyle?: 'fullscreen' | 'popover';
  295. /**
  296. * Maximum number of pictures the user will be able to choose.
  297. * Note: This option is only supported on Android 13+ and iOS.
  298. *
  299. * @default 0 (unlimited)
  300. *
  301. * @since 1.2.0
  302. */
  303. limit?: number;
  304. }
  305. export declare enum CameraSource {
  306. /**
  307. * Prompts the user to select either the photo album or take a photo.
  308. */
  309. Prompt = "PROMPT",
  310. /**
  311. * Take a new photo using the camera.
  312. */
  313. Camera = "CAMERA",
  314. /**
  315. * Pick an existing photo from the gallery or photo album.
  316. */
  317. Photos = "PHOTOS"
  318. }
  319. export declare enum CameraDirection {
  320. Rear = "REAR",
  321. Front = "FRONT"
  322. }
  323. export declare enum CameraResultType {
  324. Uri = "uri",
  325. Base64 = "base64",
  326. DataUrl = "dataUrl"
  327. }
  328. /**
  329. * @deprecated Use `Photo`.
  330. * @since 1.0.0
  331. */
  332. export declare type CameraPhoto = Photo;
  333. /**
  334. * @deprecated Use `ImageOptions`.
  335. * @since 1.0.0
  336. */
  337. export declare type CameraOptions = ImageOptions;