UNPKG

7.64 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var plugin_1 = require('./plugin');
9/**
10 * @name PhotoLibrary
11 * @description
12 * The PhotoLibrary plugin allows access to photos from device by url. So you can use plain img tag to display photos and their thumbnails, and different 3rd party libraries as well.
13 * Saving photos and videos to the library is also supported.
14 * cdvphotolibrary urls should be trusted by Angular. See plugin homepage to learn how.
15 *
16 * @usage
17 * ```
18 * import { PhotoLibrary } from 'ionic-native';
19 *
20 * PhotoLibrary.requestAuthorization().then(() => {
21 * PhotoLibrary.getLibrary().subscribe({
22 * next: library => {
23 * library.forEach(function(libraryItem) {
24 * console.log(libraryItem.id); // ID of the photo
25 * console.log(libraryItem.photoURL); // Cross-platform access to photo
26 * console.log(libraryItem.thumbnailURL);// Cross-platform access to thumbnail
27 * console.log(libraryItem.fileName);
28 * console.log(libraryItem.width);
29 * console.log(libraryItem.height);
30 * console.log(libraryItem.creationDate);
31 * console.log(libraryItem.latitude);
32 * console.log(libraryItem.longitude);
33 * console.log(libraryItem.albumIds); // array of ids of appropriate AlbumItem, only of includeAlbumsData was used
34 * });
35 * },
36 * error: err => {},
37 * complete: () => { console.log("could not get photos"); }
38 * });
39 * })
40 * .catch(err => console.log("permissions weren't granted"));
41 *
42 * ```
43 */
44var PhotoLibrary = (function () {
45 function PhotoLibrary() {
46 }
47 /**
48 * Retrieves library items. Library item contains photo metadata like width and height, as well as photoURL and thumbnailURL.
49 * @param options {GetLibraryOptions} Optional, like thumbnail size and chunks settings.
50 * @return {Observable<LibraryItem[]>} Returns library items. If appropriate option was set, will be returned by chunks.
51 */
52 PhotoLibrary.getLibrary = function (options) { return; };
53 /**
54 * Asks user permission to access photo library.
55 * @param options {RequestAuthorizationOptions} Optional, like whether only read access needed or read/write.
56 * @return { Promise<void>} Returns a promise that resolves when permissions are granted, and fails when not.
57 */
58 PhotoLibrary.requestAuthorization = function (options) { return; };
59 /**
60 * Returns list of photo albums on device.
61 * @return {Promise<AlbumItem[]>} Resolves to list of albums.
62 */
63 PhotoLibrary.getAlbums = function () { return; };
64 /**
65 * Provides means to request URL of thumbnail, with specified size or quality.
66 * @param photo {string | LibraryItem} Id of photo, or LibraryItem.
67 * @param options {GetThumbnailOptions} Options, like thumbnail size or quality.
68 * @return {Promise<string>} Resolves to URL of cdvphotolibrary schema.
69 */
70 PhotoLibrary.getThumbnailURL = function (photo, options) { return; };
71 /**
72 * Provides means to request photo URL by id.
73 * @param photo {string | LibraryItem} Id or LibraryItem.
74 * @param options {GetPhotoOptions} Optional options.
75 * @return {Promise<string>} Resolves to URL of cdvphotolibrary schema.
76 */
77 PhotoLibrary.getPhotoURL = function (photo, options) { return; };
78 /**
79 * Returns thumbnail as Blob.
80 * @param photo {string | LibraryItem} Id or LibraryItem.
81 * @param options {GetThumbnailOptions} Options, like thumbnail size or quality.
82 * @return {Promise<Blob>} Resolves requested thumbnail as blob.
83 */
84 PhotoLibrary.getThumbnail = function (photo, options) { return; };
85 /**
86 * Returns photo as Blob.
87 * @param photo {string | LibraryItem} Id or LibraryItem.
88 * @param options {GetPhotoOptions} Optional options.
89 * @return {Promise<Blob>} Resolves requested photo as blob.
90 */
91 PhotoLibrary.getPhoto = function (photo, options) { return; };
92 /**
93 * Saves image to specified album. Album will be created if not exists.
94 * LibraryItem that represents saved image is returned.
95 * @param url {string} URL of a file, or DataURL.
96 * @param album {AlbumItem | string} Name of an album or AlbumItem object.
97 * @param options {GetThumbnailOptions} Options, like thumbnail size for resulting LibraryItem.
98 * @return {Promise<LibraryItem>} Resolves to LibraryItem that represents saved image.
99 */
100 PhotoLibrary.saveImage = function (url, album, options) { return; };
101 /**
102 * Saves video to specified album. Album will be created if not exists.
103 * @param url {string} URL of a file, or DataURL.
104 * @param album {AlbumItem | string} Name of an album or AlbumItem object.
105 * @return {Promise<void>} Resolves when save operation completes.
106 */
107 PhotoLibrary.saveVideo = function (url, album) { return; };
108 __decorate([
109 plugin_1.CordovaFiniteObservable({
110 callbackOrder: 'reverse',
111 resultFinalPredicate: function (result) { return result.isLastChunk; },
112 resultTransform: function (result) { return result.library; },
113 })
114 ], PhotoLibrary, "getLibrary", null);
115 __decorate([
116 plugin_1.Cordova({
117 callbackOrder: 'reverse',
118 })
119 ], PhotoLibrary, "requestAuthorization", null);
120 __decorate([
121 plugin_1.Cordova({
122 callbackOrder: 'reverse',
123 })
124 ], PhotoLibrary, "getAlbums", null);
125 __decorate([
126 plugin_1.Cordova({
127 successIndex: 1,
128 errorIndex: 2
129 })
130 ], PhotoLibrary, "getThumbnailURL", null);
131 __decorate([
132 plugin_1.Cordova({
133 successIndex: 1,
134 errorIndex: 2
135 })
136 ], PhotoLibrary, "getPhotoURL", null);
137 __decorate([
138 plugin_1.Cordova({
139 successIndex: 1,
140 errorIndex: 2
141 })
142 ], PhotoLibrary, "getThumbnail", null);
143 __decorate([
144 plugin_1.Cordova({
145 successIndex: 1,
146 errorIndex: 2
147 })
148 ], PhotoLibrary, "getPhoto", null);
149 __decorate([
150 plugin_1.Cordova({
151 successIndex: 2,
152 errorIndex: 3
153 })
154 ], PhotoLibrary, "saveImage", null);
155 __decorate([
156 plugin_1.Cordova({
157 successIndex: 2,
158 errorIndex: 3
159 })
160 ], PhotoLibrary, "saveVideo", null);
161 PhotoLibrary = __decorate([
162 plugin_1.Plugin({
163 pluginName: 'PhotoLibrary',
164 plugin: 'cordova-plugin-photo-library',
165 pluginRef: 'cordova.plugins.photoLibrary',
166 repo: 'https://github.com/terikon/cordova-plugin-photo-library',
167 install: 'ionic plugin add cordova-plugin-photo-library --variable PHOTO_LIBRARY_USAGE_DESCRIPTION="To choose photos"'
168 })
169 ], PhotoLibrary);
170 return PhotoLibrary;
171}());
172exports.PhotoLibrary = PhotoLibrary;
173//# sourceMappingURL=photo-library.js.map
\No newline at end of file