@rdlabo/ionic-angular-photo-editor 22.0.0-0 → 22.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 (25) hide show
  1. package/README.md +57 -23
  2. package/css/ios26-header-button-color-scheme.css +114 -0
  3. package/docs/editor.md +65 -18
  4. package/docs/photo-file.md +90 -18
  5. package/docs/theme.md +21 -3
  6. package/docs/viewer.md +58 -23
  7. package/fesm2022/rdlabo-ionic-angular-photo-editor-editor-tui.mjs +12 -0
  8. package/fesm2022/rdlabo-ionic-angular-photo-editor-editor-tui.mjs.map +1 -0
  9. package/fesm2022/rdlabo-ionic-angular-photo-editor-editor.mjs +301 -0
  10. package/fesm2022/rdlabo-ionic-angular-photo-editor-editor.mjs.map +1 -0
  11. package/fesm2022/rdlabo-ionic-angular-photo-editor-file-capacitor.mjs +30 -0
  12. package/fesm2022/rdlabo-ionic-angular-photo-editor-file-capacitor.mjs.map +1 -0
  13. package/fesm2022/rdlabo-ionic-angular-photo-editor-file.mjs +193 -0
  14. package/fesm2022/rdlabo-ionic-angular-photo-editor-file.mjs.map +1 -0
  15. package/fesm2022/rdlabo-ionic-angular-photo-editor-viewer.mjs +126 -0
  16. package/fesm2022/rdlabo-ionic-angular-photo-editor-viewer.mjs.map +1 -0
  17. package/fesm2022/rdlabo-ionic-angular-photo-editor.mjs +32 -520
  18. package/fesm2022/rdlabo-ionic-angular-photo-editor.mjs.map +1 -1
  19. package/package.json +43 -4
  20. package/types/rdlabo-ionic-angular-photo-editor-editor-tui.d.ts +6 -0
  21. package/types/rdlabo-ionic-angular-photo-editor-editor.d.ts +52 -0
  22. package/types/rdlabo-ionic-angular-photo-editor-file-capacitor.d.ts +6 -0
  23. package/types/rdlabo-ionic-angular-photo-editor-file.d.ts +13 -0
  24. package/types/rdlabo-ionic-angular-photo-editor-viewer.d.ts +32 -0
  25. package/types/rdlabo-ionic-angular-photo-editor.d.ts +144 -95
@@ -1,84 +1,5 @@
1
- import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
2
- import * as i0 from '@angular/core';
3
- import { inject, signal, input, effect, viewChild, ElementRef, computed, ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, Injectable } from '@angular/core';
4
- import { CommonModule } from '@angular/common';
5
- import { FormsModule } from '@angular/forms';
6
- import * as i1 from '@ionic/angular';
7
- import { IonHeader, IonToolbar, IonButtons, IonButton, IonIcon, IonContent, IonFooter, IonText, IonRange, ModalController, IonicSlides, ActionSheetController, Platform } from '@ionic/angular';
8
- import ImageEditor from 'tui-image-editor';
9
- import { toObservable } from '@angular/core/rxjs-interop';
10
- import { addIcons } from 'ionicons';
11
- import { removeOutline, closeOutline, checkmarkOutline, refreshOutline, squareOutline, tabletLandscapeOutline, expandOutline, sunnyOutline, colorFilterOutline, cropOutline, send } from 'ionicons/icons';
12
- import { Navigation, Zoom } from 'swiper/modules';
13
- import { Subscription, fromEvent, zipWith, withLatestFrom, throttleTime } from 'rxjs';
14
- import { register } from 'swiper/element/bundle';
15
- import { CameraSource, CameraResultType, Camera } from '@capacitor/camera';
1
+ import { InjectionToken, makeEnvironmentProviders } from '@angular/core';
16
2
 
17
- const filterPreset = (dictionary) => [
18
- {
19
- name: dictionary.original,
20
- type: 'Default',
21
- option: null,
22
- },
23
- // {
24
- // name: dictionary.invert,
25
- // type: 'Invert',
26
- // option: null,
27
- // },
28
- {
29
- name: dictionary.sepia,
30
- type: 'Sepia',
31
- option: null,
32
- },
33
- {
34
- name: dictionary.vintage,
35
- type: 'vintage',
36
- option: null,
37
- },
38
- {
39
- name: 'ぼかし',
40
- type: 'Blur',
41
- option: { blur: 0.1 },
42
- },
43
- {
44
- name: dictionary.grayscale,
45
- type: 'Grayscale',
46
- option: null,
47
- },
48
- // {
49
- // name: dictionary.sharpen,
50
- // type: 'Sharpen',
51
- // option: null,
52
- // },
53
- // {
54
- // name: dictionary.emboss,
55
- // type: 'Emboss',
56
- // option: null,
57
- // },
58
- ];
59
-
60
- const ionComponents = [IonHeader, IonToolbar, IonButtons, IonButton, IonIcon, IonContent, IonFooter, IonText, IonRange];
61
-
62
- const dictionaryForEditor = () => ({
63
- // UI labels
64
- save: '保存',
65
- crop: '切り抜き・回転',
66
- filter: 'フィルター',
67
- brightness: '明るさ',
68
- // Filter labels
69
- original: 'オリジナル',
70
- invert: '反転',
71
- sepia: 'セピア',
72
- vintage: 'ヴィンテージ',
73
- blur: 'ぼかし',
74
- grayscale: 'グレースケール',
75
- sharpen: '輪郭',
76
- emboss: 'エンボス',
77
- });
78
- const dictionaryForViewer = () => ({
79
- // UI labels
80
- delete: '削除',
81
- });
82
3
  const dictionaryForService = () => ({
83
4
  // UI labels
84
5
  camera: 'カメラ撮影',
@@ -86,450 +7,41 @@ const dictionaryForService = () => ({
86
7
  cancel: 'キャンセル',
87
8
  });
88
9
 
89
- const initializeViewerIcons = () => {
90
- addIcons({
91
- closeOutline,
92
- removeOutline,
93
- });
94
- };
95
- const initializeEditorIcons = () => {
96
- addIcons({
97
- closeOutline,
98
- send,
99
- cropOutline,
100
- colorFilterOutline,
101
- sunnyOutline,
102
- expandOutline,
103
- tabletLandscapeOutline,
104
- squareOutline,
105
- refreshOutline,
106
- checkmarkOutline,
107
- });
108
- };
109
- const waitToFindDom = (nativeElement, selector) => {
110
- return new Promise((resolve) => {
111
- const interval = setInterval(() => {
112
- const find = nativeElement.querySelector(selector);
113
- if (find) {
114
- clearInterval(interval);
115
- resolve();
116
- }
117
- });
118
- });
119
- };
120
-
121
- class PhotoEditorPage {
122
- constructor() {
123
- this.modalCtrl = inject(ModalController);
124
- this.dictionary = signal(dictionaryForEditor(), /* @ts-ignore */
125
- ...(ngDevMode ? [{ debugName: "dictionary" }] : /* istanbul ignore next */ []));
126
- this.requireSquare = input(false, { ...(ngDevMode ? { debugName: "requireSquare" } : /* istanbul ignore next */ {}), transform: coerceBooleanProperty });
127
- this.labels = input(undefined, /* @ts-ignore */
128
- ...(ngDevMode ? [{ debugName: "labels" }] : /* istanbul ignore next */ []));
129
- this.setLabels = effect(() => {
130
- if (this.labels()) {
131
- this.dictionary.update((value) => ({ ...value, ...this.labels() }));
132
- }
133
- }, /* @ts-ignore */
134
- ...(ngDevMode ? [{ debugName: "setLabels" }] : /* istanbul ignore next */ []));
135
- this.value = input.required(/* @ts-ignore */
136
- ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
137
- this.editorRef = viewChild.required('imageEditor', /* @ts-ignore */
138
- ...(ngDevMode ? [{ debugName: "editorRef" }] : /* istanbul ignore next */ []));
139
- this.ionContent = viewChild.required(IonContent, { ...(ngDevMode ? { debugName: "ionContent" } : /* istanbul ignore next */ {}), read: ElementRef });
140
- this.filters = signal([], /* @ts-ignore */
141
- ...(ngDevMode ? [{ debugName: "filters" }] : /* istanbul ignore next */ []));
142
- this.footerMenu = signal('menu', /* @ts-ignore */
143
- ...(ngDevMode ? [{ debugName: "footerMenu" }] : /* istanbul ignore next */ []));
144
- this.currentCrop = signal('cover', /* @ts-ignore */
145
- ...(ngDevMode ? [{ debugName: "currentCrop" }] : /* istanbul ignore next */ []));
146
- this.currentRotate = signal(0, /* @ts-ignore */
147
- ...(ngDevMode ? [{ debugName: "currentRotate" }] : /* istanbul ignore next */ []));
148
- this.photoCrop = signal({
149
- width: 0,
150
- height: 0,
151
- }, /* @ts-ignore */
152
- ...(ngDevMode ? [{ debugName: "photoCrop" }] : /* istanbul ignore next */ []));
153
- this.isCropped = signal(false, /* @ts-ignore */
154
- ...(ngDevMode ? [{ debugName: "isCropped" }] : /* istanbul ignore next */ []));
155
- this.adoptFilter = signal(undefined, /* @ts-ignore */
156
- ...(ngDevMode ? [{ debugName: "adoptFilter" }] : /* istanbul ignore next */ []));
157
- this.filterPreset = computed(() => filterPreset(this.dictionary()), /* @ts-ignore */
158
- ...(ngDevMode ? [{ debugName: "filterPreset" }] : /* istanbul ignore next */ []));
159
- this.footerMenu$ = toObservable(this.footerMenu);
160
- this.initSubscription$ = [];
161
- this.filterImageSize = 240;
162
- this.canvasContainerObserver = new MutationObserver((mutationsList) => {
163
- if (mutationsList.find((mutation) => mutation.type === 'attributes' && mutation.attributeName === 'style')) {
164
- // Cover the image editor with the parent element
165
- const editorRef = this.editorRef();
166
- editorRef.nativeElement.style.minWidth = mutationsList[0].target.parentElement.style.maxWidth;
167
- editorRef.nativeElement.style.minHeight = mutationsList[0].target.parentElement.style.maxHeight;
168
- this.photoCrop.set({
169
- width: mutationsList[0].target.parentElement.querySelector('canvas').width,
170
- height: mutationsList[0].target.parentElement.querySelector('canvas').height,
171
- });
172
- }
173
- });
174
- initializeEditorIcons();
175
- }
176
- ngOnInit() {
177
- this.initSubscription$.push(this.footerMenu$.subscribe((value) => {
178
- if (value === 'filter') {
179
- this.initializeFilterMenu().then();
180
- }
181
- if (value === 'crop') {
182
- this.editorInstance.startDrawingMode('CROPPER');
183
- this.changeCrop(this.requireSquare() ? '1' : 'cover');
184
- }
185
- }));
186
- }
187
- ngOnDestroy() {
188
- this.initSubscription$.forEach((subscription) => subscription.unsubscribe());
189
- }
190
- async ionViewDidEnter() {
191
- this.editorInstance = new ImageEditor(this.editorRef().nativeElement, {
192
- cssMaxWidth: this.ionContent().nativeElement.clientWidth - 32,
193
- cssMaxHeight: this.ionContent().nativeElement.clientHeight - 32,
194
- });
195
- waitToFindDom(this.editorRef().nativeElement, '.tui-image-editor-canvas-container').then(() => {
196
- this.canvasContainerObserver.observe(this.editorRef().nativeElement.querySelector('.tui-image-editor-canvas-container'), {
197
- attributes: true,
198
- childList: false,
199
- subtree: true,
200
- });
201
- });
202
- const blob = await fetch(this.value()).then((res) => res.blob());
203
- await this.editorInstance.loadImageFromFile(new File([blob], 'data.png', { type: blob.type }));
204
- this.footerMenu.set(this.requireSquare() ? 'crop' : 'menu');
205
- }
206
- ionViewDidLeave() {
207
- this.editorInstance.destroy();
208
- this.canvasContainerObserver.disconnect();
209
- }
210
- changeCrop(crop) {
211
- const rect = crop === 'cover' ? this.photoCrop().width / this.photoCrop().height : crop === '16/9' ? 16 / 9 : 1;
212
- this.editorInstance.setCropzoneRect(crop !== 'auto' ? rect : undefined);
213
- this.currentCrop.set(crop);
214
- }
215
- async rotate() {
216
- this.editorInstance.stopDrawingMode();
217
- await this.editorInstance.rotate(90);
218
- this.currentRotate.update((value) => value + 90);
219
- this.editorInstance.startDrawingMode('CROPPER');
220
- requestAnimationFrame(() => this.changeCrop(this.currentCrop()));
221
- }
222
- async closeCrop(type) {
223
- if (this.footerMenu() === 'crop') {
224
- if (type === 'cancel') {
225
- await this.editorInstance.rotate(this.currentRotate() * -1);
226
- }
227
- else {
228
- await this.editorInstance.crop(this.editorInstance.getCropzoneRect());
229
- this.isCropped.set(true);
230
- }
231
- this.currentRotate.set(0);
232
- this.currentCrop.set('cover');
233
- this.editorInstance.stopDrawingMode();
234
- }
235
- else if (this.footerMenu() === 'brightness') {
236
- if (type === 'cancel' && this.editorInstance.hasFilter('brightness')) {
237
- await this.editorInstance.removeFilter('brightness');
238
- }
239
- }
240
- this.footerMenu.set('menu');
241
- }
242
- async changeRange(event) {
243
- if (this.editorInstance.hasFilter('brightness')) {
244
- await this.editorInstance.removeFilter('brightness');
245
- }
246
- await this.editorInstance.applyFilter('brightness', {
247
- brightness: Number(event.detail.value) / 255,
248
- });
249
- }
250
- imageSave() {
251
- const value = this.editorInstance.toDataURL();
252
- this.modalCtrl.dismiss({ value });
10
+ /** Typed error produced by expected photo selection failures. */
11
+ class PhotoLoadError extends Error {
12
+ constructor(code, options) {
13
+ super(code, options);
14
+ this.code = code;
15
+ this.name = 'PhotoLoadError';
253
16
  }
254
- async initializeFilterMenu() {
255
- const filters = [];
256
- const defaultInstance = new ImageEditor(document.createElement('div'), {
257
- cssMaxWidth: this.filterImageSize,
258
- cssMaxHeight: (this.photoCrop().height * this.filterImageSize) / this.photoCrop().width,
259
- });
260
- const blob = await fetch(this.editorInstance.toDataURL({
261
- multiplier: this.filterImageSize / this.photoCrop().width,
262
- })).then((res) => res.blob());
263
- await defaultInstance.loadImageFromFile(new File([blob], 'defaultInstance.png', { type: blob.type }));
264
- for (const filter of this.filterPreset()) {
265
- if (filter.type !== 'Default') {
266
- await defaultInstance.applyFilter(filter.type, filter.option);
267
- }
268
- filters.push({
269
- name: filter.name,
270
- type: filter.type,
271
- option: filter.option,
272
- data: defaultInstance.toDataURL(),
273
- width: this.filterImageSize,
274
- height: (this.photoCrop().height * this.filterImageSize) / this.photoCrop().width,
275
- });
276
- if (filter.type !== 'Default') {
277
- await defaultInstance.removeFilter(filter.type);
278
- }
279
- }
280
- this.filters.set(filters);
281
- defaultInstance.destroy();
282
- }
283
- async filterImage(filter) {
284
- if (this.adoptFilter()) {
285
- await this.editorInstance.removeFilter(this.adoptFilter().type);
286
- }
287
- if (filter.type === 'Default') {
288
- this.adoptFilter.set(undefined);
289
- return;
290
- }
291
- await this.editorInstance.applyFilter(filter.type, filter.option);
292
- this.adoptFilter.set(filter);
293
- }
294
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: PhotoEditorPage, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
295
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.3", type: PhotoEditorPage, isStandalone: true, selector: "app-editor-image", inputs: { requireSquare: { classPropertyName: "requireSquare", publicName: "requireSquare", isSignal: true, isRequired: false, transformFunction: null }, labels: { classPropertyName: "labels", publicName: "labels", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null } }, viewQueries: [{ propertyName: "editorRef", first: true, predicate: ["imageEditor"], descendants: true, isSignal: true }, { propertyName: "ionContent", first: true, predicate: IonContent, descendants: true, read: ElementRef, isSignal: true }], ngImport: i0, template: "<ion-header>\n <ion-toolbar>\n <ion-buttons slot=\"start\"\n ><ion-button (click)=\"modalCtrl.dismiss()\"><ion-icon name=\"close-outline\" slot=\"icon-only\"></ion-icon></ion-button\n ></ion-buttons>\n <ion-buttons slot=\"end\">\n <ion-button color=\"photo-editor-primary\" fill=\"solid\" type=\"submit\" [disabled]=\"!['menu', 'filter'].includes(footerMenu())\" (click)=\"imageSave()\">\n {{ dictionary().save }}\n </ion-button>\n </ion-buttons>\n </ion-toolbar>\n</ion-header>\n\n<ion-content class=\"ion-padding\" [scrollY]=\"false\">\n <div #imageEditor></div>\n</ion-content>\n<ion-footer>\n <ion-toolbar>\n @if (this.footerMenu() === 'menu') {\n <aside class=\"ion-justify-content-center\">\n <button (click)=\"footerMenu.set('crop')\">\n <ion-text>{{ dictionary().crop }}</ion-text>\n <ion-icon name=\"crop-outline\" size=\"large\"></ion-icon>\n </button>\n <button (click)=\"footerMenu.set('filter')\">\n <ion-text>{{ dictionary().filter }}</ion-text>\n <ion-icon name=\"color-filter-outline\" size=\"large\"></ion-icon>\n </button>\n <button (click)=\"footerMenu.set('brightness')\">\n <ion-text>{{ dictionary().brightness }}</ion-text>\n <ion-icon name=\"sunny-outline\" size=\"large\"></ion-icon>\n </button>\n </aside>\n }\n\n @if (this.footerMenu() === 'filter') {\n <aside>\n @for (item of filters(); track item) {\n <button (click)=\"filterImage(item)\">\n <ion-text>{{ item.name }}</ion-text>\n <span class=\"image-filter-box\" [style.background-image]=\"'url(' + item.data + ')'\"></span>\n </button>\n }\n </aside>\n }\n\n @if (this.footerMenu() === 'crop' && !requireSquare()) {\n <ion-buttons class=\"ion-justify-content-center submenu-icon-buttons\">\n <ion-button (click)=\"changeCrop('cover')\" [color]=\"currentCrop() === 'cover' ? 'success' : undefined\">\n <ion-icon name=\"expand-outline\" slot=\"icon-only\"></ion-icon>\n </ion-button>\n <ion-button (click)=\"changeCrop('16/9')\" [color]=\"currentCrop() === '16/9' ? 'success' : undefined\">\n <ion-icon name=\"tablet-landscape-outline\" slot=\"icon-only\" style=\"transform: scale(1, 0.8)\"></ion-icon>\n </ion-button>\n <ion-button (click)=\"changeCrop('1')\" [color]=\"currentCrop() === '1' ? 'success' : undefined\">\n <ion-icon name=\"square-outline\" slot=\"icon-only\"></ion-icon>\n </ion-button>\n <ion-button (click)=\"changeCrop('auto')\" [color]=\"currentCrop() === 'auto' ? 'success' : undefined\">\n <ion-icon name=\"crop-outline\" slot=\"icon-only\"></ion-icon>\n </ion-button>\n <ion-button (click)=\"rotate()\"><ion-icon name=\"refresh-outline\" slot=\"icon-only\"></ion-icon></ion-button>\n </ion-buttons>\n }\n\n @if (['brightness'].includes(this.footerMenu())) {\n <div class=\"ion-padding ion-margin\">\n <ion-range [pin]=\"true\" [min]=\"-100\" [max]=\"100\" (ionChange)=\"changeRange($any($event))\"></ion-range>\n </div>\n }\n </ion-toolbar>\n @if (this.footerMenu() !== 'menu') {\n <ion-toolbar mode=\"md\">\n @if (this.footerMenu() === 'filter') {\n <ion-buttons class=\"ion-justify-content-center\" style=\"margin: 0 8px\">\n <ion-button fill=\"outline\" shape=\"round\" (click)=\"this.footerMenu.set('menu')\">\u623B\u308B</ion-button>\n </ion-buttons>\n } @else {\n <ion-buttons slot=\"start\" style=\"min-width: 60px\">\n @if (!requireSquare() || isCropped()) {\n <ion-button (click)=\"closeCrop('cancel')\"><ion-icon name=\"close-outline\" slot=\"icon-only\"></ion-icon></ion-button>\n }</ion-buttons\n ><ion-text class=\"footer-title\">\n @if (footerMenu() === 'crop') {\n {{ dictionary().crop }}\n } @else if (footerMenu() === 'brightness') {\n {{ dictionary().brightness }}\n }</ion-text\n ><ion-buttons slot=\"end\"\n ><ion-button (click)=\"closeCrop('apply')\"\n ><ion-icon name=\"checkmark-outline\" color=\"photo-editor-success\" slot=\"icon-only\"></ion-icon></ion-button\n ></ion-buttons>\n }\n </ion-toolbar>\n }\n</ion-footer>\n", styles: [":host{--editor-background: var(--ion-photo-editor-background, --ion-color-step-100, #2a2a2a);--editor-background-tint: var(--ion-photo-editor-background-tint, --ion-color-step-200, #414141);--editor-color: var(--ion-photo-editor-color, --ion-color-step-950, #f0f0f0);--editor-color-tint: var(--ion-photo-editor-color-tint, --ion-color-step-850, #dbdbdb);--ion-color-photo-editor-primary: var(--ion-photo-editor-primary, --ion-color-primary, #4d8dff);--ion-color-photo-editor-danger: var(--ion-photo-editor-danger, #f24c58);--ion-color-photo-editor-success: var(--ion-photo-editor-success, #2dd55b)}.ion-color-photo-editor-primary{--ion-color-base: var(--ion-color-photo-editor-primary)}.ion-color-photo-editor-danger{--ion-color-base: var(--ion-color-photo-editor-danger)}.ion-color-photo-editor-success{--ion-color-base: var(--ion-color-photo-editor-success)}ion-content,ion-toolbar,ion-header,ion-footer{background:var(--editor-background)!important;--background: var(--editor-background) !important}\n", "ion-content{--background: var(--editor-background)}ion-content>div{width:100%;height:100%;max-width:100%;max-height:100%;display:grid;align-items:center;justify-items:center}aside{display:flex;overflow-x:scroll;margin-top:16px;min-height:120px}aside ion-icon{color:var(--editor-color);border:1px solid var(--editor-background-tint);border-radius:50%;padding:16px}aside button{width:120px;display:block;flex:1;background:transparent;margin:0 8px 16px}aside button ion-text{display:block;color:var(--editor-color);margin-bottom:8px;font-size:.8rem}aside button span.image-filter-box{width:96px;height:64px;border-radius:8px;overflow:hidden;display:block;background-position:center,center;background-size:cover}ion-header ion-button,ion-footer ion-button{--color: var(--editor-color) !important}ion-footer ion-toolbar ion-text.footer-title{color:var(--editor-color)!important;display:block;text-align:center}ion-footer ion-toolbar ion-range{--bar-background: var(--editor-color);--bar-background-active: var(--editor-color);--bar-height: 2px;--bar-border-radius: 8px;--knob-background: var(--editor-color);--knob-size: 20px;--pin-background: none;--pin-color: var(--editor-color)}ion-footer ion-toolbar ion-buttons[slot=start] ion-button,ion-footer ion-toolbar ion-buttons[slot=end] ion-button{--background: var(--editor-background-tint) !important;--border-radius: 50%;margin:0 8px;min-width:32px;min-height:32px}ion-footer ion-toolbar ion-buttons.submenu-icon-buttons ion-button{margin:16px}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: FormsModule }, { kind: "component", type: i1.IonHeader, selector: "ion-header", inputs: ["collapse", "mode", "translucent"] }, { kind: "component", type: i1.IonToolbar, selector: "ion-toolbar", inputs: ["color", "mode"] }, { kind: "component", type: i1.IonButtons, selector: "ion-buttons", inputs: ["collapse"] }, { kind: "component", type: i1.IonButton, selector: "ion-button", inputs: ["buttonType", "color", "disabled", "download", "expand", "fill", "form", "href", "mode", "rel", "routerAnimation", "routerDirection", "shape", "size", "strong", "target", "type"], outputs: ["ionFocus", "ionBlur"] }, { kind: "component", type: i1.IonIcon, selector: "ion-icon", inputs: ["color", "flipRtl", "icon", "ios", "lazy", "md", "mode", "name", "sanitize", "size", "src"] }, { kind: "component", type: i1.IonContent, selector: "ion-content", inputs: ["color", "fixedSlotPlacement", "forceOverscroll", "fullscreen", "scrollEvents", "scrollX", "scrollY"], outputs: ["ionScrollStart", "ionScroll", "ionScrollEnd"] }, { kind: "component", type: i1.IonFooter, selector: "ion-footer", inputs: ["collapse", "mode", "translucent"] }, { kind: "component", type: i1.IonText, selector: "ion-text", inputs: ["color", "mode"] }, { kind: "component", type: i1.IonRange, selector: "ion-range", inputs: ["activeBarStart", "color", "debounce", "disabled", "dualKnobs", "label", "labelPlacement", "max", "min", "mode", "name", "pin", "pinFormatter", "snaps", "step", "ticks", "value"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
296
17
  }
297
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: PhotoEditorPage, decorators: [{
298
- type: Component,
299
- args: [{ selector: 'app-editor-image', imports: [CommonModule, FormsModule, ...ionComponents], changeDetection: ChangeDetectionStrategy.OnPush, template: "<ion-header>\n <ion-toolbar>\n <ion-buttons slot=\"start\"\n ><ion-button (click)=\"modalCtrl.dismiss()\"><ion-icon name=\"close-outline\" slot=\"icon-only\"></ion-icon></ion-button\n ></ion-buttons>\n <ion-buttons slot=\"end\">\n <ion-button color=\"photo-editor-primary\" fill=\"solid\" type=\"submit\" [disabled]=\"!['menu', 'filter'].includes(footerMenu())\" (click)=\"imageSave()\">\n {{ dictionary().save }}\n </ion-button>\n </ion-buttons>\n </ion-toolbar>\n</ion-header>\n\n<ion-content class=\"ion-padding\" [scrollY]=\"false\">\n <div #imageEditor></div>\n</ion-content>\n<ion-footer>\n <ion-toolbar>\n @if (this.footerMenu() === 'menu') {\n <aside class=\"ion-justify-content-center\">\n <button (click)=\"footerMenu.set('crop')\">\n <ion-text>{{ dictionary().crop }}</ion-text>\n <ion-icon name=\"crop-outline\" size=\"large\"></ion-icon>\n </button>\n <button (click)=\"footerMenu.set('filter')\">\n <ion-text>{{ dictionary().filter }}</ion-text>\n <ion-icon name=\"color-filter-outline\" size=\"large\"></ion-icon>\n </button>\n <button (click)=\"footerMenu.set('brightness')\">\n <ion-text>{{ dictionary().brightness }}</ion-text>\n <ion-icon name=\"sunny-outline\" size=\"large\"></ion-icon>\n </button>\n </aside>\n }\n\n @if (this.footerMenu() === 'filter') {\n <aside>\n @for (item of filters(); track item) {\n <button (click)=\"filterImage(item)\">\n <ion-text>{{ item.name }}</ion-text>\n <span class=\"image-filter-box\" [style.background-image]=\"'url(' + item.data + ')'\"></span>\n </button>\n }\n </aside>\n }\n\n @if (this.footerMenu() === 'crop' && !requireSquare()) {\n <ion-buttons class=\"ion-justify-content-center submenu-icon-buttons\">\n <ion-button (click)=\"changeCrop('cover')\" [color]=\"currentCrop() === 'cover' ? 'success' : undefined\">\n <ion-icon name=\"expand-outline\" slot=\"icon-only\"></ion-icon>\n </ion-button>\n <ion-button (click)=\"changeCrop('16/9')\" [color]=\"currentCrop() === '16/9' ? 'success' : undefined\">\n <ion-icon name=\"tablet-landscape-outline\" slot=\"icon-only\" style=\"transform: scale(1, 0.8)\"></ion-icon>\n </ion-button>\n <ion-button (click)=\"changeCrop('1')\" [color]=\"currentCrop() === '1' ? 'success' : undefined\">\n <ion-icon name=\"square-outline\" slot=\"icon-only\"></ion-icon>\n </ion-button>\n <ion-button (click)=\"changeCrop('auto')\" [color]=\"currentCrop() === 'auto' ? 'success' : undefined\">\n <ion-icon name=\"crop-outline\" slot=\"icon-only\"></ion-icon>\n </ion-button>\n <ion-button (click)=\"rotate()\"><ion-icon name=\"refresh-outline\" slot=\"icon-only\"></ion-icon></ion-button>\n </ion-buttons>\n }\n\n @if (['brightness'].includes(this.footerMenu())) {\n <div class=\"ion-padding ion-margin\">\n <ion-range [pin]=\"true\" [min]=\"-100\" [max]=\"100\" (ionChange)=\"changeRange($any($event))\"></ion-range>\n </div>\n }\n </ion-toolbar>\n @if (this.footerMenu() !== 'menu') {\n <ion-toolbar mode=\"md\">\n @if (this.footerMenu() === 'filter') {\n <ion-buttons class=\"ion-justify-content-center\" style=\"margin: 0 8px\">\n <ion-button fill=\"outline\" shape=\"round\" (click)=\"this.footerMenu.set('menu')\">\u623B\u308B</ion-button>\n </ion-buttons>\n } @else {\n <ion-buttons slot=\"start\" style=\"min-width: 60px\">\n @if (!requireSquare() || isCropped()) {\n <ion-button (click)=\"closeCrop('cancel')\"><ion-icon name=\"close-outline\" slot=\"icon-only\"></ion-icon></ion-button>\n }</ion-buttons\n ><ion-text class=\"footer-title\">\n @if (footerMenu() === 'crop') {\n {{ dictionary().crop }}\n } @else if (footerMenu() === 'brightness') {\n {{ dictionary().brightness }}\n }</ion-text\n ><ion-buttons slot=\"end\"\n ><ion-button (click)=\"closeCrop('apply')\"\n ><ion-icon name=\"checkmark-outline\" color=\"photo-editor-success\" slot=\"icon-only\"></ion-icon></ion-button\n ></ion-buttons>\n }\n </ion-toolbar>\n }\n</ion-footer>\n", styles: [":host{--editor-background: var(--ion-photo-editor-background, --ion-color-step-100, #2a2a2a);--editor-background-tint: var(--ion-photo-editor-background-tint, --ion-color-step-200, #414141);--editor-color: var(--ion-photo-editor-color, --ion-color-step-950, #f0f0f0);--editor-color-tint: var(--ion-photo-editor-color-tint, --ion-color-step-850, #dbdbdb);--ion-color-photo-editor-primary: var(--ion-photo-editor-primary, --ion-color-primary, #4d8dff);--ion-color-photo-editor-danger: var(--ion-photo-editor-danger, #f24c58);--ion-color-photo-editor-success: var(--ion-photo-editor-success, #2dd55b)}.ion-color-photo-editor-primary{--ion-color-base: var(--ion-color-photo-editor-primary)}.ion-color-photo-editor-danger{--ion-color-base: var(--ion-color-photo-editor-danger)}.ion-color-photo-editor-success{--ion-color-base: var(--ion-color-photo-editor-success)}ion-content,ion-toolbar,ion-header,ion-footer{background:var(--editor-background)!important;--background: var(--editor-background) !important}\n", "ion-content{--background: var(--editor-background)}ion-content>div{width:100%;height:100%;max-width:100%;max-height:100%;display:grid;align-items:center;justify-items:center}aside{display:flex;overflow-x:scroll;margin-top:16px;min-height:120px}aside ion-icon{color:var(--editor-color);border:1px solid var(--editor-background-tint);border-radius:50%;padding:16px}aside button{width:120px;display:block;flex:1;background:transparent;margin:0 8px 16px}aside button ion-text{display:block;color:var(--editor-color);margin-bottom:8px;font-size:.8rem}aside button span.image-filter-box{width:96px;height:64px;border-radius:8px;overflow:hidden;display:block;background-position:center,center;background-size:cover}ion-header ion-button,ion-footer ion-button{--color: var(--editor-color) !important}ion-footer ion-toolbar ion-text.footer-title{color:var(--editor-color)!important;display:block;text-align:center}ion-footer ion-toolbar ion-range{--bar-background: var(--editor-color);--bar-background-active: var(--editor-color);--bar-height: 2px;--bar-border-radius: 8px;--knob-background: var(--editor-color);--knob-size: 20px;--pin-background: none;--pin-color: var(--editor-color)}ion-footer ion-toolbar ion-buttons[slot=start] ion-button,ion-footer ion-toolbar ion-buttons[slot=end] ion-button{--background: var(--editor-background-tint) !important;--border-radius: 50%;margin:0 8px;min-width:32px;min-height:32px}ion-footer ion-toolbar ion-buttons.submenu-icon-buttons ion-button{margin:16px}\n"] }]
300
- }], ctorParameters: () => [], propDecorators: { requireSquare: [{ type: i0.Input, args: [{ isSignal: true, alias: "requireSquare", required: false }] }], labels: [{ type: i0.Input, args: [{ isSignal: true, alias: "labels", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], editorRef: [{ type: i0.ViewChild, args: ['imageEditor', { isSignal: true }] }], ionContent: [{ type: i0.ViewChild, args: [i0.forwardRef(() => IonContent), { ...{ read: ElementRef }, isSignal: true }] }] } });
301
18
 
302
- class PhotoViewerPage {
303
- constructor() {
304
- this.imageUrls = input.required(/* @ts-ignore */
305
- ...(ngDevMode ? [{ debugName: "imageUrls" }] : /* istanbul ignore next */ []));
306
- this.index = input(0, { ...(ngDevMode ? { debugName: "index" } : /* istanbul ignore next */ {}), transform: coerceNumberProperty });
307
- this.isCircle = input(false, { ...(ngDevMode ? { debugName: "isCircle" } : /* istanbul ignore next */ {}), transform: coerceBooleanProperty });
308
- this.enableDelete = input(false, { ...(ngDevMode ? { debugName: "enableDelete" } : /* istanbul ignore next */ {}), transform: coerceBooleanProperty });
309
- this.enableFooterSafeArea = input(false, { ...(ngDevMode ? { debugName: "enableFooterSafeArea" } : /* istanbul ignore next */ {}), transform: coerceBooleanProperty });
310
- this.labels = input(/* @ts-ignore */
311
- ...(ngDevMode ? [undefined, { debugName: "labels" }] : /* istanbul ignore next */ []));
312
- this.setLabels = effect(() => {
313
- if (this.labels()) {
314
- this.dictionary.update((value) => ({ ...value, ...this.labels() }));
315
- }
316
- }, /* @ts-ignore */
317
- ...(ngDevMode ? [{ debugName: "setLabels" }] : /* istanbul ignore next */ []));
318
- this.swiper = viewChild.required('swiper', /* @ts-ignore */
319
- ...(ngDevMode ? [{ debugName: "swiper" }] : /* istanbul ignore next */ []));
320
- this.dictionary = signal(dictionaryForViewer(), /* @ts-ignore */
321
- ...(ngDevMode ? [{ debugName: "dictionary" }] : /* istanbul ignore next */ []));
322
- this.watchSwipe$ = new Subscription();
323
- this.modalCtrl = inject(ModalController);
324
- this.el = inject(ElementRef);
325
- register();
326
- initializeViewerIcons();
327
- }
328
- async ngOnInit() {
329
- waitToFindDom(this.el.nativeElement, 'swiper-container').then(() => {
330
- const index = this.index();
331
- const swiper = this.swiper();
332
- Object.assign(swiper.nativeElement, {
333
- modules: [Navigation, Zoom, IonicSlides],
334
- initialSlide: index,
335
- slidesPerView: 1,
336
- pagination: {
337
- enabled: true,
338
- clickable: true,
339
- },
340
- zoom: true,
341
- });
342
- swiper.nativeElement.initialize();
343
- swiper.nativeElement.swiper.zoom.enable();
344
- swiper.nativeElement.swiper.activeIndex = index;
345
- swiper.nativeElement.swiper.update();
346
- });
347
- this.watchSwipe$.add(fromEvent(this.el.nativeElement, 'touchstart')
348
- .pipe(zipWith(fromEvent(this.el.nativeElement, 'touchend').pipe(withLatestFrom(fromEvent(this.el.nativeElement, 'touchmove')))), throttleTime(1))
349
- .subscribe(([touchstart, [_, touchmove]]) => {
350
- const touchstartClientX = touchstart.touches ? touchstart.touches[0].clientX : touchstart.detail[1].clientX;
351
- const touchmoveClientX = touchmove.touches ? touchmove.touches[0].clientX : touchmove.detail[1].clientX;
352
- const touchstartClientY = touchstart.touches ? touchstart.touches[0].clientY : touchstart.detail[1].clientY;
353
- const touchmoveClientY = touchmove.touches ? touchmove.touches[0].clientY : touchmove.detail[1].clientY;
354
- const xDiff = touchstartClientX - touchmoveClientX;
355
- const yDiff = touchstartClientY - touchmoveClientY;
356
- const slides = this.swiper().nativeElement.querySelectorAll('swiper-slide');
357
- const isZoomed = Array.from(slides).find((slide) => {
358
- return ['swiper-slide-zoomed', 'swiper-slide-active'].every((c) => slide.classList.contains(c));
359
- });
360
- const threshold = touchmove.touches ? -50 : -5;
361
- if (!isZoomed && Math.abs(xDiff) < Math.abs(threshold) && yDiff < threshold && touchstart.timeStamp <= touchmove.timeStamp) {
362
- this.watchSwipe$.unsubscribe();
363
- this.modalCtrl.dismiss();
364
- }
365
- }));
366
- }
367
- ngOnDestroy() {
368
- this.watchSwipe$.unsubscribe();
369
- }
370
- remove() {
371
- this.modalCtrl.dismiss({
372
- delete: {
373
- index: this.swiper().nativeElement.swiper.activeIndex,
374
- value: this.imageUrls()[this.swiper().nativeElement.swiper.activeIndex],
19
+ const missingImageEditor = () => Promise.reject(new PhotoLoadError('unavailable', { cause: new Error('Configure createImageEditor with the editor adapter.') }));
20
+ const missingCamera = () => Promise.reject(new PhotoLoadError('unavailable', { cause: new Error('Configure loadCamera with the Capacitor adapter.') }));
21
+ /** Resolved photo editor configuration used by library services and components. */
22
+ const PHOTO_EDITOR_CONFIG = new InjectionToken('PHOTO_EDITOR_CONFIG', {
23
+ providedIn: 'root',
24
+ factory: () => ({
25
+ maxSize: 1000,
26
+ labels: dictionaryForService(),
27
+ createImageEditor: missingImageEditor,
28
+ loadCamera: missingCamera,
29
+ }),
30
+ });
31
+ /** Provides application-wide photo editor defaults and an optional editor adapter. */
32
+ function providePhotoEditor(config = {}) {
33
+ return makeEnvironmentProviders([
34
+ {
35
+ provide: PHOTO_EDITOR_CONFIG,
36
+ useValue: {
37
+ maxSize: config.maxSize ?? 1000,
38
+ labels: { ...dictionaryForService(), ...config.labels },
39
+ createImageEditor: config.createImageEditor ?? missingImageEditor,
40
+ loadCamera: config.loadCamera ?? missingCamera,
375
41
  },
376
- });
377
- }
378
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: PhotoViewerPage, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
379
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.3", type: PhotoViewerPage, isStandalone: true, selector: "app-photo-image", inputs: { imageUrls: { classPropertyName: "imageUrls", publicName: "imageUrls", isSignal: true, isRequired: true, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null }, isCircle: { classPropertyName: "isCircle", publicName: "isCircle", isSignal: true, isRequired: false, transformFunction: null }, enableDelete: { classPropertyName: "enableDelete", publicName: "enableDelete", isSignal: true, isRequired: false, transformFunction: null }, enableFooterSafeArea: { classPropertyName: "enableFooterSafeArea", publicName: "enableFooterSafeArea", isSignal: true, isRequired: false, transformFunction: null }, labels: { classPropertyName: "labels", publicName: "labels", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "swiper", first: true, predicate: ["swiper"], descendants: true, isSignal: true }], ngImport: i0, template: "<ion-header [translucent]=\"true\">\n <ion-toolbar>\n <ion-buttons slot=\"start\">\n <ion-button (click)=\"modalCtrl.dismiss()\" class=\"viewer-close-button\">\n <ion-icon name=\"close-outline\" slot=\"icon-only\"></ion-icon>\n </ion-button>\n </ion-buttons>\n @if (enableDelete()) {\n <ion-buttons slot=\"end\">\n <ion-button color=\"photo-editor-danger\" fill=\"solid\" type=\"submit\" (click)=\"remove()\">{{ dictionary().delete }}</ion-button>\n </ion-buttons>\n }\n </ion-toolbar>\n</ion-header>\n\n<ion-content [fullscreen]=\"true\">\n <swiper-container #swiper>\n @for (url of imageUrls(); track url) {\n <swiper-slide>\n <div class=\"swiper-zoom-container\"><img [src]=\"url\" alt=\"\" [class.circle]=\"isCircle()\" /></div>\n </swiper-slide>\n }\n </swiper-container>\n</ion-content>\n\n@if (enableFooterSafeArea()) {\n <!-- use for safe area-->\n <ion-footer>\n <ion-toolbar style=\"--border-width: 0; --min-height: 0\"></ion-toolbar>\n </ion-footer>\n}\n", styles: [":host{--editor-background: var(--ion-photo-editor-background, --ion-color-step-100, #2a2a2a);--editor-background-tint: var(--ion-photo-editor-background-tint, --ion-color-step-200, #414141);--editor-color: var(--ion-photo-editor-color, --ion-color-step-950, #f0f0f0);--editor-color-tint: var(--ion-photo-editor-color-tint, --ion-color-step-850, #dbdbdb);--ion-color-photo-editor-primary: var(--ion-photo-editor-primary, --ion-color-primary, #4d8dff);--ion-color-photo-editor-danger: var(--ion-photo-editor-danger, #f24c58);--ion-color-photo-editor-success: var(--ion-photo-editor-success, #2dd55b)}.ion-color-photo-editor-primary{--ion-color-base: var(--ion-color-photo-editor-primary)}.ion-color-photo-editor-danger{--ion-color-base: var(--ion-color-photo-editor-danger)}.ion-color-photo-editor-success{--ion-color-base: var(--ion-color-photo-editor-success)}ion-content,ion-toolbar,ion-header,ion-footer{background:var(--editor-background)!important;--background: var(--editor-background) !important}\n", "ion-button.viewer-close-button{--color: var(--editor-color) !important}img.circle{border-radius:50%;display:block;padding:16px}swiper-container{height:100%;max-height:100%}swiper-slide{height:100%;max-height:100%;display:flex;justify-content:center;align-items:center}swiper-slide img{display:block;object-fit:contain;max-width:100%;max-height:100%}\n"], dependencies: [{ kind: "component", type: i1.IonHeader, selector: "ion-header", inputs: ["collapse", "mode", "translucent"] }, { kind: "component", type: i1.IonToolbar, selector: "ion-toolbar", inputs: ["color", "mode"] }, { kind: "component", type: i1.IonButtons, selector: "ion-buttons", inputs: ["collapse"] }, { kind: "component", type: i1.IonButton, selector: "ion-button", inputs: ["buttonType", "color", "disabled", "download", "expand", "fill", "form", "href", "mode", "rel", "routerAnimation", "routerDirection", "shape", "size", "strong", "target", "type"], outputs: ["ionFocus", "ionBlur"] }, { kind: "component", type: i1.IonIcon, selector: "ion-icon", inputs: ["color", "flipRtl", "icon", "ios", "lazy", "md", "mode", "name", "sanitize", "size", "src"] }, { kind: "component", type: i1.IonContent, selector: "ion-content", inputs: ["color", "fixedSlotPlacement", "forceOverscroll", "fullscreen", "scrollEvents", "scrollX", "scrollY"], outputs: ["ionScrollStart", "ionScroll", "ionScrollEnd"] }, { kind: "component", type: i1.IonFooter, selector: "ion-footer", inputs: ["collapse", "mode", "translucent"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
380
- }
381
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: PhotoViewerPage, decorators: [{
382
- type: Component,
383
- args: [{ selector: 'app-photo-image', imports: [...ionComponents], schemas: [CUSTOM_ELEMENTS_SCHEMA], changeDetection: ChangeDetectionStrategy.OnPush, template: "<ion-header [translucent]=\"true\">\n <ion-toolbar>\n <ion-buttons slot=\"start\">\n <ion-button (click)=\"modalCtrl.dismiss()\" class=\"viewer-close-button\">\n <ion-icon name=\"close-outline\" slot=\"icon-only\"></ion-icon>\n </ion-button>\n </ion-buttons>\n @if (enableDelete()) {\n <ion-buttons slot=\"end\">\n <ion-button color=\"photo-editor-danger\" fill=\"solid\" type=\"submit\" (click)=\"remove()\">{{ dictionary().delete }}</ion-button>\n </ion-buttons>\n }\n </ion-toolbar>\n</ion-header>\n\n<ion-content [fullscreen]=\"true\">\n <swiper-container #swiper>\n @for (url of imageUrls(); track url) {\n <swiper-slide>\n <div class=\"swiper-zoom-container\"><img [src]=\"url\" alt=\"\" [class.circle]=\"isCircle()\" /></div>\n </swiper-slide>\n }\n </swiper-container>\n</ion-content>\n\n@if (enableFooterSafeArea()) {\n <!-- use for safe area-->\n <ion-footer>\n <ion-toolbar style=\"--border-width: 0; --min-height: 0\"></ion-toolbar>\n </ion-footer>\n}\n", styles: [":host{--editor-background: var(--ion-photo-editor-background, --ion-color-step-100, #2a2a2a);--editor-background-tint: var(--ion-photo-editor-background-tint, --ion-color-step-200, #414141);--editor-color: var(--ion-photo-editor-color, --ion-color-step-950, #f0f0f0);--editor-color-tint: var(--ion-photo-editor-color-tint, --ion-color-step-850, #dbdbdb);--ion-color-photo-editor-primary: var(--ion-photo-editor-primary, --ion-color-primary, #4d8dff);--ion-color-photo-editor-danger: var(--ion-photo-editor-danger, #f24c58);--ion-color-photo-editor-success: var(--ion-photo-editor-success, #2dd55b)}.ion-color-photo-editor-primary{--ion-color-base: var(--ion-color-photo-editor-primary)}.ion-color-photo-editor-danger{--ion-color-base: var(--ion-color-photo-editor-danger)}.ion-color-photo-editor-success{--ion-color-base: var(--ion-color-photo-editor-success)}ion-content,ion-toolbar,ion-header,ion-footer{background:var(--editor-background)!important;--background: var(--editor-background) !important}\n", "ion-button.viewer-close-button{--color: var(--editor-color) !important}img.circle{border-radius:50%;display:block;padding:16px}swiper-container{height:100%;max-height:100%}swiper-slide{height:100%;max-height:100%;display:flex;justify-content:center;align-items:center}swiper-slide img{display:block;object-fit:contain;max-width:100%;max-height:100%}\n"] }]
384
- }], ctorParameters: () => [], propDecorators: { imageUrls: [{ type: i0.Input, args: [{ isSignal: true, alias: "imageUrls", required: true }] }], index: [{ type: i0.Input, args: [{ isSignal: true, alias: "index", required: false }] }], isCircle: [{ type: i0.Input, args: [{ isSignal: true, alias: "isCircle", required: false }] }], enableDelete: [{ type: i0.Input, args: [{ isSignal: true, alias: "enableDelete", required: false }] }], enableFooterSafeArea: [{ type: i0.Input, args: [{ isSignal: true, alias: "enableFooterSafeArea", required: false }] }], labels: [{ type: i0.Input, args: [{ isSignal: true, alias: "labels", required: false }] }], swiper: [{ type: i0.ViewChild, args: ['swiper', { isSignal: true }] }] } });
385
-
386
- var PhotoEditorErrors;
387
- (function (PhotoEditorErrors) {
388
- PhotoEditorErrors["initialize"] = "input dom is not found";
389
- PhotoEditorErrors["cancel"] = "user canceled";
390
- PhotoEditorErrors["type"] = "upload file is not image.";
391
- })(PhotoEditorErrors || (PhotoEditorErrors = {}));
392
-
393
- class PhotoFileService {
394
- constructor() {
395
- this.$photoMaxSize = signal(1000, /* @ts-ignore */
396
- ...(ngDevMode ? [{ debugName: "$photoMaxSize" }] : /* istanbul ignore next */ []));
397
- this.actionSheetCtrl = inject(ActionSheetController);
398
- this.platform = inject(Platform);
399
- this.dictionary = signal(dictionaryForService(), /* @ts-ignore */
400
- ...(ngDevMode ? [{ debugName: "dictionary" }] : /* istanbul ignore next */ []));
401
- }
402
- set photoMaxSize(value) {
403
- this.$photoMaxSize.set(value);
404
- }
405
- set labels(d) {
406
- this.dictionary.update((value) => ({ ...value, ...d }));
407
- }
408
- async loadPhoto(limit) {
409
- /**
410
- * Using Input for browser
411
- */
412
- if (!this.platform.is('capacitor')) {
413
- return this.getPictureFromBrowser();
414
- }
415
- const actionSheet = await this.actionSheetCtrl.create({
416
- buttons: [
417
- {
418
- text: this.dictionary().camera,
419
- handler: () => {
420
- actionSheet.dismiss('camera');
421
- },
422
- },
423
- {
424
- text: this.dictionary().album,
425
- handler: () => {
426
- actionSheet.dismiss('album');
427
- },
428
- },
429
- {
430
- text: this.dictionary().cancel,
431
- role: 'cancel',
432
- },
433
- ],
434
- });
435
- await actionSheet.present();
436
- const { data } = await actionSheet.onDidDismiss();
437
- if (!data) {
438
- return Promise.reject(PhotoEditorErrors.cancel);
439
- }
440
- if (data === 'camera') {
441
- const defaultCamera = {
442
- quality: 100,
443
- width: this.$photoMaxSize(),
444
- allowEditing: false,
445
- resultType: CameraResultType.DataUrl,
446
- source: CameraSource.Camera,
447
- presentationStyle: 'popover',
448
- };
449
- const image = await Camera.getPhoto(defaultCamera).catch(() => undefined);
450
- if (!image?.dataUrl) {
451
- return Promise.reject(PhotoEditorErrors.cancel);
452
- }
453
- if (!image.dataUrl.includes('capacitor://localhost')) {
454
- return [image.dataUrl];
455
- }
456
- return Promise.all([image.dataUrl].map(async (image) => await this.loadPhotoFromFilePath(image)));
457
- }
458
- if (data === 'album') {
459
- const images = await Camera.pickImages({
460
- quality: 100,
461
- width: this.$photoMaxSize(),
462
- limit,
463
- presentationStyle: 'popover',
464
- }).catch(() => undefined);
465
- if (!images) {
466
- return Promise.reject(PhotoEditorErrors.cancel);
467
- }
468
- return Promise.all(images.photos.map(async (image) => await this.loadPhotoFromFilePath(image.webPath)));
469
- }
470
- // Not run on this line. This is for lint
471
- return [];
472
- }
473
- getPictureFromBrowser() {
474
- const inputFile = document.querySelector('input#browserPhotoUploader');
475
- if (!inputFile) {
476
- return Promise.reject(PhotoEditorErrors.initialize);
477
- }
478
- return new Promise((resolve, reject) => {
479
- const cancelMethod = () => {
480
- inputFile.removeEventListener('cancel', cancelMethod, false);
481
- inputFile.removeEventListener('change', changeMethod, false);
482
- reject(PhotoEditorErrors.cancel);
483
- };
484
- const changeMethod = (e) => {
485
- inputFile.removeEventListener('cancel', cancelMethod, false);
486
- inputFile.removeEventListener('change', changeMethod, false);
487
- if (!e.target.files || !e.target.files[0]) {
488
- reject(PhotoEditorErrors.cancel);
489
- }
490
- const file = e.target.files[0];
491
- const reader = new FileReader();
492
- reader.onload = (() => {
493
- if (file.type.indexOf('image') < 0) {
494
- reject(PhotoEditorErrors.type);
495
- }
496
- return async (event) => {
497
- inputFile.value = '';
498
- const result = event.target.result;
499
- const data = await this.loadPhotoFromFilePath(result);
500
- resolve([data]);
501
- };
502
- })();
503
- reader.readAsDataURL(file);
504
- };
505
- inputFile.addEventListener('cancel', cancelMethod, false);
506
- inputFile.addEventListener('change', changeMethod, false);
507
- inputFile.click();
508
- });
509
- }
510
- async loadPhotoFromFilePath(filePath) {
511
- const defaultInstance = new ImageEditor(document.createElement('div'), {
512
- cssMaxWidth: this.$photoMaxSize(),
513
- cssMaxHeight: this.$photoMaxSize(),
514
- });
515
- const blob = await fetch(filePath).then((res) => res.blob());
516
- const loaded = await defaultInstance.loadImageFromFile(new File([blob], 'data.png', { type: blob.type }));
517
- const maxSize = Math.max(loaded.newWidth, loaded.newHeight);
518
- const dataUrl = defaultInstance.toDataURL({
519
- multiplier: this.$photoMaxSize() / maxSize,
520
- });
521
- defaultInstance.destroy();
522
- return dataUrl;
523
- }
524
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: PhotoFileService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
525
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: PhotoFileService, providedIn: 'root' }); }
42
+ },
43
+ ]);
526
44
  }
527
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: PhotoFileService, decorators: [{
528
- type: Injectable,
529
- args: [{
530
- providedIn: 'root',
531
- }]
532
- }] });
533
45
 
534
46
  /*
535
47
  * Public API Surface of photo-editor
@@ -539,5 +51,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImpor
539
51
  * Generated bundle index. Do not edit.
540
52
  */
541
53
 
542
- export { PhotoEditorPage, PhotoFileService, PhotoViewerPage };
54
+ export { PHOTO_EDITOR_CONFIG, PhotoLoadError, providePhotoEditor };
543
55
  //# sourceMappingURL=rdlabo-ionic-angular-photo-editor.mjs.map