@rdlabo/ionic-angular-photo-editor 21.0.1 → 21.0.3-3
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/fesm2022/rdlabo-ionic-angular-photo-editor.mjs +523 -0
- package/fesm2022/rdlabo-ionic-angular-photo-editor.mjs.map +1 -0
- package/package.json +18 -3
- package/types/rdlabo-ionic-angular-photo-editor.d.ts +132 -0
- package/eslint.config.js +0 -7
- package/ng-package.json +0 -7
- package/src/lib/dictionaries.ts +0 -31
- package/src/lib/filter-preset.ts +0 -44
- package/src/lib/ion-components.ts +0 -3
- package/src/lib/pages/core.scss +0 -63
- package/src/lib/pages/photo-editor/photo-editor.page.html +0 -95
- package/src/lib/pages/photo-editor/photo-editor.page.scss +0 -95
- package/src/lib/pages/photo-editor/photo-editor.page.spec.ts +0 -21
- package/src/lib/pages/photo-editor/photo-editor.page.ts +0 -221
- package/src/lib/pages/photo-viewer/photo-viewer.page.html +0 -31
- package/src/lib/pages/photo-viewer/photo-viewer.page.scss +0 -29
- package/src/lib/pages/photo-viewer/photo-viewer.page.spec.ts +0 -25
- package/src/lib/pages/photo-viewer/photo-viewer.page.ts +0 -134
- package/src/lib/pages/util.ts +0 -48
- package/src/lib/photoEditorErrors.ts +0 -5
- package/src/lib/services/photo-file.service.spec.ts +0 -19
- package/src/lib/services/photo-file.service.ts +0 -161
- package/src/lib/types.ts +0 -55
- package/src/public-api.ts +0 -8
- package/tsconfig.lib.json +0 -14
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -14
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { inject, Injectable, signal } from '@angular/core';
|
|
2
|
-
import { ActionSheetController, Platform } from '@ionic/angular/standalone';
|
|
3
|
-
import { Camera, CameraResultType, CameraSource, ImageOptions } from '@capacitor/camera';
|
|
4
|
-
import ImageEditor from 'tui-image-editor';
|
|
5
|
-
import { PhotoEditorErrors } from '../photoEditorErrors';
|
|
6
|
-
import { dictionaryForService } from '../dictionaries';
|
|
7
|
-
import { IDictionaryForService } from '../types';
|
|
8
|
-
|
|
9
|
-
@Injectable({
|
|
10
|
-
providedIn: 'root',
|
|
11
|
-
})
|
|
12
|
-
export class PhotoFileService {
|
|
13
|
-
private readonly $photoMaxSize = signal<number>(1000);
|
|
14
|
-
private readonly actionSheetCtrl = inject(ActionSheetController);
|
|
15
|
-
private readonly platform = inject(Platform);
|
|
16
|
-
private readonly dictionary = signal<IDictionaryForService>(dictionaryForService());
|
|
17
|
-
|
|
18
|
-
set photoMaxSize(value: number) {
|
|
19
|
-
this.$photoMaxSize.set(value);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
set labels(d: IDictionaryForService) {
|
|
23
|
-
this.dictionary.update((value) => ({ ...value, ...d }));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async loadPhoto(limit: number): Promise<string[]> {
|
|
27
|
-
/**
|
|
28
|
-
* Using Input for browser
|
|
29
|
-
*/
|
|
30
|
-
if (!this.platform.is('capacitor')) {
|
|
31
|
-
return this.getPictureFromBrowser();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const actionSheet = await this.actionSheetCtrl.create({
|
|
35
|
-
buttons: [
|
|
36
|
-
{
|
|
37
|
-
text: this.dictionary().camera,
|
|
38
|
-
handler: () => {
|
|
39
|
-
actionSheet.dismiss('camera');
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
text: this.dictionary().album,
|
|
44
|
-
handler: () => {
|
|
45
|
-
actionSheet.dismiss('album');
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
text: this.dictionary().cancel,
|
|
50
|
-
role: 'cancel',
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
});
|
|
54
|
-
await actionSheet.present();
|
|
55
|
-
const { data } = await actionSheet.onDidDismiss<'camera' | 'album'>();
|
|
56
|
-
if (!data) {
|
|
57
|
-
return Promise.reject(PhotoEditorErrors.cancel);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (data === 'camera') {
|
|
61
|
-
const defaultCamera: ImageOptions = {
|
|
62
|
-
quality: 100,
|
|
63
|
-
width: this.$photoMaxSize(),
|
|
64
|
-
allowEditing: false,
|
|
65
|
-
resultType: CameraResultType.DataUrl,
|
|
66
|
-
source: CameraSource.Camera,
|
|
67
|
-
presentationStyle: 'popover',
|
|
68
|
-
};
|
|
69
|
-
const image = await Camera.getPhoto(defaultCamera).catch(() => undefined);
|
|
70
|
-
if (!image?.dataUrl) {
|
|
71
|
-
return Promise.reject(PhotoEditorErrors.cancel);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!image.dataUrl.includes('capacitor://localhost')) {
|
|
75
|
-
return [image.dataUrl];
|
|
76
|
-
}
|
|
77
|
-
return Promise.all([image.dataUrl].map(async (image) => await this.loadPhotoFromFilePath(image)));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (data === 'album') {
|
|
81
|
-
const images = await Camera.pickImages({
|
|
82
|
-
quality: 100,
|
|
83
|
-
width: this.$photoMaxSize(),
|
|
84
|
-
limit,
|
|
85
|
-
presentationStyle: 'popover',
|
|
86
|
-
}).catch(() => undefined);
|
|
87
|
-
|
|
88
|
-
if (!images) {
|
|
89
|
-
return Promise.reject(PhotoEditorErrors.cancel);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return Promise.all(images.photos.map(async (image) => await this.loadPhotoFromFilePath(image.webPath)));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Not run on this line. This is for lint
|
|
96
|
-
return [];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private getPictureFromBrowser(): Promise<string[]> {
|
|
100
|
-
const inputFile: HTMLInputElement | null = document.querySelector('input#browserPhotoUploader');
|
|
101
|
-
|
|
102
|
-
if (!inputFile) {
|
|
103
|
-
return Promise.reject(PhotoEditorErrors.initialize);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return new Promise((resolve, reject) => {
|
|
107
|
-
const cancelMethod = () => {
|
|
108
|
-
inputFile!.removeEventListener('cancel', cancelMethod, false);
|
|
109
|
-
inputFile!.removeEventListener('change', changeMethod, false);
|
|
110
|
-
|
|
111
|
-
reject(PhotoEditorErrors.cancel);
|
|
112
|
-
};
|
|
113
|
-
const changeMethod = (e: Event) => {
|
|
114
|
-
inputFile!.removeEventListener('cancel', cancelMethod, false);
|
|
115
|
-
inputFile!.removeEventListener('change', changeMethod, false);
|
|
116
|
-
|
|
117
|
-
if (!(e.target as HTMLInputElement).files || !(e.target as HTMLInputElement).files![0]) {
|
|
118
|
-
reject(PhotoEditorErrors.cancel);
|
|
119
|
-
}
|
|
120
|
-
const file = (e.target as HTMLInputElement).files![0];
|
|
121
|
-
const reader = new FileReader();
|
|
122
|
-
|
|
123
|
-
reader.onload = (() => {
|
|
124
|
-
if (file.type.indexOf('image') < 0) {
|
|
125
|
-
reject(PhotoEditorErrors.type);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return async (event) => {
|
|
129
|
-
inputFile.value = '';
|
|
130
|
-
const result = event.target!.result as string;
|
|
131
|
-
const data = await this.loadPhotoFromFilePath(result);
|
|
132
|
-
resolve([data]);
|
|
133
|
-
};
|
|
134
|
-
})();
|
|
135
|
-
|
|
136
|
-
reader.readAsDataURL(file);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
inputFile!.addEventListener('cancel', cancelMethod, false);
|
|
140
|
-
inputFile!.addEventListener('change', changeMethod, false);
|
|
141
|
-
inputFile.click();
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private async loadPhotoFromFilePath(filePath: string): Promise<string> {
|
|
146
|
-
const defaultInstance = new ImageEditor(document.createElement('div'), {
|
|
147
|
-
cssMaxWidth: this.$photoMaxSize(),
|
|
148
|
-
cssMaxHeight: this.$photoMaxSize(),
|
|
149
|
-
});
|
|
150
|
-
const blob = await fetch(filePath).then((res) => res.blob());
|
|
151
|
-
const loaded = await defaultInstance.loadImageFromFile(new File([blob], 'data.png', { type: blob.type }));
|
|
152
|
-
|
|
153
|
-
const maxSize = Math.max(loaded.newWidth, loaded.newHeight);
|
|
154
|
-
const dataUrl = defaultInstance.toDataURL({
|
|
155
|
-
multiplier: this.$photoMaxSize() / maxSize,
|
|
156
|
-
});
|
|
157
|
-
defaultInstance.destroy();
|
|
158
|
-
|
|
159
|
-
return dataUrl;
|
|
160
|
-
}
|
|
161
|
-
}
|
package/src/lib/types.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export interface IFilter {
|
|
2
|
-
name: string;
|
|
3
|
-
type: string;
|
|
4
|
-
option: any;
|
|
5
|
-
data: string;
|
|
6
|
-
width: number;
|
|
7
|
-
height: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface ISize {
|
|
11
|
-
width: number;
|
|
12
|
-
height: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface IDictionaryForEditor {
|
|
16
|
-
save: string;
|
|
17
|
-
crop: string;
|
|
18
|
-
filter: string;
|
|
19
|
-
brightness: string;
|
|
20
|
-
original: string;
|
|
21
|
-
invert: string;
|
|
22
|
-
sepia: string;
|
|
23
|
-
vintage: string;
|
|
24
|
-
blur: string;
|
|
25
|
-
grayscale: string;
|
|
26
|
-
sharpen: string;
|
|
27
|
-
emboss: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface IFilterPreset {
|
|
31
|
-
name: string;
|
|
32
|
-
type: string;
|
|
33
|
-
option: any;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface IPhotoEditorDismiss {
|
|
37
|
-
value: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface IPhotoViewerDismiss {
|
|
41
|
-
delete: {
|
|
42
|
-
index: number;
|
|
43
|
-
value: string;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface IDictionaryForViewer {
|
|
48
|
-
delete: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface IDictionaryForService {
|
|
52
|
-
camera: string;
|
|
53
|
-
album: string;
|
|
54
|
-
cancel: string;
|
|
55
|
-
}
|
package/src/public-api.ts
DELETED
package/tsconfig.lib.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/lib",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"inlineSources": true,
|
|
9
|
-
"types": []
|
|
10
|
-
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"**/*.spec.ts"
|
|
13
|
-
]
|
|
14
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/spec",
|
|
6
|
-
"types": [
|
|
7
|
-
"jasmine"
|
|
8
|
-
]
|
|
9
|
-
},
|
|
10
|
-
"include": [
|
|
11
|
-
"**/*.spec.ts",
|
|
12
|
-
"**/*.d.ts"
|
|
13
|
-
]
|
|
14
|
-
}
|