@rdlabo/ionic-angular-photo-editor 22.0.1-0 → 22.0.1-beta.pr105.sha55308d6acf67
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/README.md +61 -56
- package/docs/editor.md +32 -21
- package/docs/photo-file.md +50 -35
- package/docs/viewer.md +33 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,73 +1,69 @@
|
|
|
1
1
|
# @rdlabo/ionic-angular-photo-editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Photo editor and viewer modal pages for Ionic Angular applications, with browser file selection and optional Capacitor camera/album support.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
### Choose by editing goal
|
|
5
|
+
## Installation
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
| Crop and edit in a modal | [Photo Editor](https://docs.rdlabo.dev/projects/ionic-angular-photo-editor/docs/editor) |
|
|
15
|
-
| Browse images in a modal | [Photo Viewer](https://docs.rdlabo.dev/projects/ionic-angular-photo-editor/docs/viewer) |
|
|
16
|
-
| Override editor colors | [Theme](https://docs.rdlabo.dev/projects/ionic-angular-photo-editor/docs/theme) |
|
|
17
|
-
| Upgrade from an earlier release | [Migration guide](https://github.com/rdlabo-dev/ionic-angular-library/blob/main/docs/migration.md#rdlaboionic-angular-photo-editor) |
|
|
7
|
+
```bash
|
|
8
|
+
npm install @rdlabo/ionic-angular-photo-editor tui-image-editor
|
|
9
|
+
```
|
|
18
10
|
|
|
19
|
-
##
|
|
11
|
+
## Select and display a photo in the browser
|
|
20
12
|
|
|
21
|
-
|
|
13
|
+
Register the TUI resize adapter (required for `loadPhoto` resizing), then pick a file and show the returned data URL:
|
|
22
14
|
|
|
23
15
|
```typescript
|
|
24
|
-
import {
|
|
16
|
+
import { Component, inject, signal } from '@angular/core';
|
|
17
|
+
import type { ApplicationConfig } from '@angular/core';
|
|
18
|
+
import { IonButton, IonImg } from '@ionic/angular';
|
|
19
|
+
import { providePhotoEditor, PhotoLoadError } from '@rdlabo/ionic-angular-photo-editor';
|
|
25
20
|
import { createTuiImageEditor } from '@rdlabo/ionic-angular-photo-editor/editor/tui';
|
|
26
21
|
import { PhotoFileService } from '@rdlabo/ionic-angular-photo-editor/file';
|
|
27
|
-
import { loadCapacitorPhotoCamera } from '@rdlabo/ionic-angular-photo-editor/file/capacitor';
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
export const appConfig = {
|
|
23
|
+
export const appConfig: ApplicationConfig = {
|
|
31
24
|
providers: [
|
|
32
25
|
providePhotoEditor({
|
|
33
26
|
maxSize: 1000,
|
|
34
27
|
createImageEditor: createTuiImageEditor,
|
|
35
|
-
loadCamera: loadCapacitorPhotoCamera,
|
|
36
28
|
}),
|
|
37
29
|
],
|
|
38
30
|
};
|
|
39
31
|
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
@Component({
|
|
33
|
+
selector: 'app-photo-pick',
|
|
34
|
+
imports: [IonButton, IonImg],
|
|
35
|
+
template: `
|
|
36
|
+
<ion-button type="button" (click)="pick()">Select photo</ion-button>
|
|
37
|
+
@if (previewUrl()) {
|
|
38
|
+
<ion-img [src]="previewUrl()" alt="Selected photo"></ion-img>
|
|
39
|
+
}
|
|
40
|
+
`,
|
|
41
|
+
})
|
|
42
|
+
export class PhotoPickPage {
|
|
43
|
+
private readonly photoFileService = inject(PhotoFileService);
|
|
44
|
+
readonly previewUrl = signal('');
|
|
45
|
+
|
|
46
|
+
async pick(): Promise<void> {
|
|
47
|
+
try {
|
|
48
|
+
const files = await this.photoFileService.loadPhoto({ limit: 1 });
|
|
49
|
+
this.previewUrl.set(files[0] ?? '');
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (error instanceof PhotoLoadError && error.code === 'cancelled') {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
42
58
|
```
|
|
43
59
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## Package entry points
|
|
47
|
-
|
|
48
|
-
| Import path | Exports |
|
|
49
|
-
| --------------------------------------------------- | -------------------------------------------------------------------- |
|
|
50
|
-
| `@rdlabo/ionic-angular-photo-editor` | Types, `providePhotoEditor`, `PHOTO_EDITOR_CONFIG`, `PhotoLoadError` |
|
|
51
|
-
| `@rdlabo/ionic-angular-photo-editor/editor` | `PhotoEditorPage` |
|
|
52
|
-
| `@rdlabo/ionic-angular-photo-editor/editor/tui` | opt-in `createTuiImageEditor` adapter |
|
|
53
|
-
| `@rdlabo/ionic-angular-photo-editor/viewer` | `PhotoViewerPage` |
|
|
54
|
-
| `@rdlabo/ionic-angular-photo-editor/file` | `PhotoFileService` |
|
|
55
|
-
| `@rdlabo/ionic-angular-photo-editor/file/capacitor` | opt-in `loadCapacitorPhotoCamera` adapter |
|
|
56
|
-
|
|
57
|
-
Import components and services only from their entry point. Import shared types and configuration from the root package.
|
|
58
|
-
|
|
59
|
-
## Installation
|
|
60
|
+
Click Select photo, choose an image — the preview appears. Native camera/album setup comes later under [PhotoFileService](https://docs.rdlabo.dev/projects/ionic-angular-photo-editor/docs/photo-file).
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
npm install @rdlabo/ionic-angular-photo-editor
|
|
63
|
-
```
|
|
62
|
+
## Add a viewer or native camera
|
|
64
63
|
|
|
65
|
-
Install
|
|
64
|
+
Install the dependencies for the features you add:
|
|
66
65
|
|
|
67
66
|
```bash
|
|
68
|
-
# editor, and resizing in PhotoFileService
|
|
69
|
-
npm install tui-image-editor
|
|
70
|
-
|
|
71
67
|
# viewer
|
|
72
68
|
npm install swiper
|
|
73
69
|
|
|
@@ -75,21 +71,30 @@ npm install swiper
|
|
|
75
71
|
npm install @capacitor/camera
|
|
76
72
|
```
|
|
77
73
|
|
|
78
|
-
|
|
79
|
-
Native iOS applications must target iOS/iPadOS 16.4 or later.
|
|
74
|
+
For native camera access, configure [Camera permissions](https://capacitorjs.com/docs/apis/camera#android-configuration) and the adapter in [PhotoFileService](./docs/photo-file.md). Native iOS apps require iOS/iPadOS 16.4 or later.
|
|
80
75
|
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
## Package entry points
|
|
77
|
+
|
|
78
|
+
| Import path | Exports |
|
|
79
|
+
| --------------------------------------------------- | -------------------------------------------------------------------- |
|
|
80
|
+
| `@rdlabo/ionic-angular-photo-editor` | Types, `providePhotoEditor`, `PHOTO_EDITOR_CONFIG`, `PhotoLoadError` |
|
|
81
|
+
| `@rdlabo/ionic-angular-photo-editor/editor` | `PhotoEditorPage` |
|
|
82
|
+
| `@rdlabo/ionic-angular-photo-editor/editor/tui` | opt-in `createTuiImageEditor` adapter |
|
|
83
|
+
| `@rdlabo/ionic-angular-photo-editor/viewer` | `PhotoViewerPage` |
|
|
84
|
+
| `@rdlabo/ionic-angular-photo-editor/file` | `PhotoFileService` |
|
|
85
|
+
| `@rdlabo/ionic-angular-photo-editor/file/capacitor` | opt-in `loadCapacitorPhotoCamera` adapter |
|
|
83
86
|
|
|
84
|
-
|
|
87
|
+
Import components and services only from their entry point. Import shared types and configuration from the root package.
|
|
85
88
|
|
|
86
|
-
|
|
89
|
+
## Choose by editing goal
|
|
87
90
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
| Goal | Guide |
|
|
92
|
+
| --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
93
|
+
| Load a photo from camera or album | [PhotoFileService](https://docs.rdlabo.dev/projects/ionic-angular-photo-editor/docs/photo-file) |
|
|
94
|
+
| Crop and edit in a modal | [Photo Editor](https://docs.rdlabo.dev/projects/ionic-angular-photo-editor/docs/editor) |
|
|
95
|
+
| Browse images in a modal | [Photo Viewer](https://docs.rdlabo.dev/projects/ionic-angular-photo-editor/docs/viewer) |
|
|
96
|
+
| Override editor colors | [Theme](https://docs.rdlabo.dev/projects/ionic-angular-photo-editor/docs/theme) |
|
|
97
|
+
| Upgrade from an earlier release | [Migration guide](https://github.com/rdlabo-dev/ionic-angular-library/blob/main/docs/migration.md#rdlaboionic-angular-photo-editor) |
|
|
93
98
|
|
|
94
99
|
<!-- rdlabo-docs-omit -->
|
|
95
100
|
|
package/docs/editor.md
CHANGED
|
@@ -1,34 +1,45 @@
|
|
|
1
|
-
Present `PhotoEditorPage`
|
|
1
|
+
Present `PhotoEditorPage` from a button or existing page method via Ionic Modal. Call this after [Installation](../README.md#installation).
|
|
2
2
|
|
|
3
3
|
```typescript
|
|
4
|
+
import { Component, inject } from '@angular/core';
|
|
5
|
+
import type { ApplicationConfig } from '@angular/core';
|
|
6
|
+
import { ModalController, IonButton } from '@ionic/angular';
|
|
4
7
|
import { PhotoEditorProps, PhotoEditorResult, providePhotoEditor } from '@rdlabo/ionic-angular-photo-editor';
|
|
5
8
|
import { PhotoEditorPage } from '@rdlabo/ionic-angular-photo-editor/editor';
|
|
6
9
|
import { createTuiImageEditor } from '@rdlabo/ionic-angular-photo-editor/editor/tui';
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
export const appConfig = {
|
|
11
|
+
export const appConfig: ApplicationConfig = {
|
|
10
12
|
providers: [providePhotoEditor({ createImageEditor: createTuiImageEditor })],
|
|
11
13
|
};
|
|
12
14
|
|
|
13
|
-
(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
@Component({
|
|
16
|
+
selector: 'app-edit-photo',
|
|
17
|
+
imports: [IonButton],
|
|
18
|
+
template: `<ion-button type="button" (click)="openEditor()">Edit photo</ion-button>`,
|
|
19
|
+
})
|
|
20
|
+
export class EditPhotoPage {
|
|
21
|
+
private readonly modalCtrl = inject(ModalController);
|
|
22
|
+
|
|
23
|
+
async openEditor(): Promise<void> {
|
|
24
|
+
const componentProps = {
|
|
25
|
+
requireSquare: false,
|
|
26
|
+
value: 'https://picsum.photos/200/300',
|
|
27
|
+
toolbarColorScheme: 'dark',
|
|
28
|
+
labels: {
|
|
29
|
+
save: '送信', // override default '保存'
|
|
30
|
+
},
|
|
31
|
+
} satisfies PhotoEditorProps;
|
|
32
|
+
const modal = await this.modalCtrl.create({
|
|
33
|
+
component: PhotoEditorPage,
|
|
34
|
+
componentProps,
|
|
35
|
+
});
|
|
36
|
+
await modal.present();
|
|
37
|
+
const { data } = await modal.onWillDismiss<PhotoEditorResult>();
|
|
38
|
+
if (data?.action === 'save') {
|
|
39
|
+
console.log(data.value);
|
|
40
|
+
}
|
|
30
41
|
}
|
|
31
|
-
}
|
|
42
|
+
}
|
|
32
43
|
```
|
|
33
44
|
|
|
34
45
|
## Modal result
|
package/docs/photo-file.md
CHANGED
|
@@ -1,41 +1,47 @@
|
|
|
1
|
-
Load photos from the camera or album. Call this after [Installation](../README.md#installation).
|
|
1
|
+
Load photos from the browser file picker or, on native platforms, from the camera or album. Call this after [Installation](../README.md#installation).
|
|
2
|
+
|
|
3
|
+
## Browser: select and display
|
|
4
|
+
|
|
5
|
+
`createImageEditor` is required because `loadPhoto` always resizes through the image-editor adapter. Omit `loadCamera` for web-only apps.
|
|
2
6
|
|
|
3
7
|
```typescript
|
|
8
|
+
import { Component, inject, signal } from '@angular/core';
|
|
9
|
+
import type { ApplicationConfig } from '@angular/core';
|
|
10
|
+
import { IonButton, IonImg } from '@ionic/angular';
|
|
4
11
|
import { providePhotoEditor, PhotoLoadError } from '@rdlabo/ionic-angular-photo-editor';
|
|
5
12
|
import { createTuiImageEditor } from '@rdlabo/ionic-angular-photo-editor/editor/tui';
|
|
6
13
|
import { PhotoFileService } from '@rdlabo/ionic-angular-photo-editor/file';
|
|
7
|
-
import { loadCapacitorPhotoCamera } from '@rdlabo/ionic-angular-photo-editor/file/capacitor';
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
export const appConfig = {
|
|
15
|
+
export const appConfig: ApplicationConfig = {
|
|
11
16
|
providers: [
|
|
12
17
|
providePhotoEditor({
|
|
13
18
|
maxSize: 1000,
|
|
14
|
-
labels: {
|
|
15
|
-
camera: 'Camera',
|
|
16
|
-
album: 'Album',
|
|
17
|
-
cancel: 'Cancel',
|
|
18
|
-
},
|
|
19
19
|
createImageEditor: createTuiImageEditor,
|
|
20
|
-
loadCamera: loadCapacitorPhotoCamera,
|
|
21
20
|
}),
|
|
22
21
|
],
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
@Component({
|
|
25
|
+
selector: 'app-photo-pick',
|
|
26
|
+
imports: [IonButton, IonImg],
|
|
27
|
+
template: `
|
|
28
|
+
<ion-button type="button" (click)="pick()">Select photo</ion-button>
|
|
29
|
+
@if (previewUrl()) {
|
|
30
|
+
<ion-img [src]="previewUrl()" alt="Selected photo"></ion-img>
|
|
31
|
+
}
|
|
32
|
+
`,
|
|
33
|
+
})
|
|
34
|
+
export class PhotoPickPage {
|
|
35
|
+
private readonly photoFileService = inject(PhotoFileService);
|
|
36
|
+
readonly previewUrl = signal('');
|
|
28
37
|
|
|
29
|
-
async
|
|
38
|
+
async pick(): Promise<void> {
|
|
30
39
|
try {
|
|
31
40
|
const files = await this.photoFileService.loadPhoto({
|
|
32
41
|
limit: 1,
|
|
33
42
|
maxSize: 1000,
|
|
34
|
-
labels: { camera: 'Camera' }, // merges over configured defaults
|
|
35
43
|
});
|
|
36
|
-
|
|
37
|
-
// upload files
|
|
38
|
-
}
|
|
44
|
+
this.previewUrl.set(files[0] ?? '');
|
|
39
45
|
} catch (error) {
|
|
40
46
|
if (error instanceof PhotoLoadError && error.code === 'cancelled') {
|
|
41
47
|
return;
|
|
@@ -46,6 +52,31 @@ export class AppComponent {
|
|
|
46
52
|
}
|
|
47
53
|
```
|
|
48
54
|
|
|
55
|
+
## Native camera and album
|
|
56
|
+
|
|
57
|
+
Install `@capacitor/camera`, configure platform permissions, and register `loadCapacitorPhotoCamera`. On native platforms, an action sheet asks the user to choose camera or album. Per-request `labels` merge over values from `providePhotoEditor({ labels })`.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { providePhotoEditor } from '@rdlabo/ionic-angular-photo-editor';
|
|
61
|
+
import { createTuiImageEditor } from '@rdlabo/ionic-angular-photo-editor/editor/tui';
|
|
62
|
+
import { loadCapacitorPhotoCamera } from '@rdlabo/ionic-angular-photo-editor/file/capacitor';
|
|
63
|
+
|
|
64
|
+
export const appConfig = {
|
|
65
|
+
providers: [
|
|
66
|
+
providePhotoEditor({
|
|
67
|
+
maxSize: 1000,
|
|
68
|
+
labels: {
|
|
69
|
+
camera: 'Camera',
|
|
70
|
+
album: 'Album',
|
|
71
|
+
cancel: 'Cancel',
|
|
72
|
+
},
|
|
73
|
+
createImageEditor: createTuiImageEditor,
|
|
74
|
+
loadCamera: loadCapacitorPhotoCamera,
|
|
75
|
+
}),
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
49
80
|
## loadPhoto(options?)
|
|
50
81
|
|
|
51
82
|
Opens the platform photo picker and returns normalized data URLs.
|
|
@@ -64,7 +95,6 @@ Do not add a static file input to `index.html`.
|
|
|
64
95
|
|
|
65
96
|
### Capacitor behavior
|
|
66
97
|
|
|
67
|
-
On native platforms, an action sheet asks the user to choose camera or album. Per-request `labels` merge over values from `providePhotoEditor({ labels })`.
|
|
68
98
|
Register `loadCapacitorPhotoCamera` from `/file/capacitor`; the base `/file` entry point stays usable by browser-only applications without `@capacitor/camera`.
|
|
69
99
|
|
|
70
100
|
### Errors
|
|
@@ -89,19 +119,4 @@ When no global or per-request `labels` are supplied:
|
|
|
89
119
|
|
|
90
120
|
## providePhotoEditor(config?)
|
|
91
121
|
|
|
92
|
-
Register application-wide defaults in `app.config.ts
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
export const appConfig = {
|
|
96
|
-
providers: [
|
|
97
|
-
providePhotoEditor({
|
|
98
|
-
maxSize: 1200,
|
|
99
|
-
labels: { camera: '…', album: '…', cancel: '…' },
|
|
100
|
-
createImageEditor: createTuiImageEditor,
|
|
101
|
-
loadCamera: loadCapacitorPhotoCamera, // omit in browser-only applications
|
|
102
|
-
}),
|
|
103
|
-
],
|
|
104
|
-
};
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
`PhotoFileService` reads these adapters plus the global `maxSize` and `labels` defaults from this configuration. Per-request values with the same names override them for a single call. A resize requires `createImageEditor`; a native picker requires `loadCamera`. Missing adapters throw `PhotoLoadError` with `code: 'unavailable'`.
|
|
122
|
+
Register application-wide defaults in `app.config.ts`. `PhotoFileService` reads these adapters plus the global `maxSize` and `labels` defaults from this configuration. Per-request values with the same names override them for a single call. A resize requires `createImageEditor`; a native picker requires `loadCamera`. Missing adapters throw `PhotoLoadError` with `code: 'unavailable'`.
|
package/docs/viewer.md
CHANGED
|
@@ -1,31 +1,42 @@
|
|
|
1
|
-
Present `PhotoViewerPage`
|
|
1
|
+
Present `PhotoViewerPage` from a button or existing page method via Ionic Modal. Call this after [Installation](../README.md#installation). Install `swiper` when using the viewer.
|
|
2
2
|
|
|
3
3
|
```typescript
|
|
4
|
+
import { Component, inject } from '@angular/core';
|
|
5
|
+
import { ModalController, IonButton } from '@ionic/angular';
|
|
4
6
|
import { PhotoViewerProps, PhotoViewerResult } from '@rdlabo/ionic-angular-photo-editor';
|
|
5
7
|
import { PhotoViewerPage } from '@rdlabo/ionic-angular-photo-editor/viewer';
|
|
6
8
|
|
|
7
|
-
(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
9
|
+
@Component({
|
|
10
|
+
selector: 'app-view-photos',
|
|
11
|
+
imports: [IonButton],
|
|
12
|
+
template: `<ion-button type="button" (click)="openViewer()">View photos</ion-button>`,
|
|
13
|
+
})
|
|
14
|
+
export class ViewPhotosPage {
|
|
15
|
+
private readonly modalCtrl = inject(ModalController);
|
|
16
|
+
|
|
17
|
+
async openViewer(): Promise<void> {
|
|
18
|
+
const componentProps = {
|
|
19
|
+
imageUrls: ['https://picsum.photos/200/300', 'https://picsum.photos/200/301'],
|
|
20
|
+
index: 0,
|
|
21
|
+
isCircle: false,
|
|
22
|
+
enableDelete: true,
|
|
23
|
+
toolbarColorScheme: 'dark',
|
|
24
|
+
imageAlt: (url, index) => `Photo ${index + 1}`,
|
|
25
|
+
labels: {
|
|
26
|
+
delete: 'Delete',
|
|
27
|
+
},
|
|
28
|
+
} satisfies PhotoViewerProps;
|
|
29
|
+
const modal = await this.modalCtrl.create({
|
|
30
|
+
component: PhotoViewerPage,
|
|
31
|
+
componentProps,
|
|
32
|
+
});
|
|
33
|
+
await modal.present();
|
|
34
|
+
const { data } = await modal.onWillDismiss<PhotoViewerResult>();
|
|
35
|
+
if (data?.action === 'delete') {
|
|
36
|
+
console.log(data.index, data.value);
|
|
37
|
+
}
|
|
27
38
|
}
|
|
28
|
-
}
|
|
39
|
+
}
|
|
29
40
|
```
|
|
30
41
|
|
|
31
42
|
## Modal result
|