@nextcloud/image-editor 1.0.0-beta.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.
- package/LICENSE +661 -0
- package/README.md +156 -0
- package/dist/assets/index.css +509 -0
- package/dist/index.cjs +4690 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +233 -0
- package/dist/index.mjs +4683 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +105 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { ComponentOptionsMixin } from 'vue';
|
|
2
|
+
import { ComponentProvideOptions } from 'vue';
|
|
3
|
+
import { ComputedRef } from 'vue';
|
|
4
|
+
import { DefineComponent } from 'vue';
|
|
5
|
+
import { PublicProps } from 'vue';
|
|
6
|
+
|
|
7
|
+
declare type __VLS_Props = {
|
|
8
|
+
/** Image to edit: Blob, File or URL */
|
|
9
|
+
src: Blob | string;
|
|
10
|
+
/** Accessible label of the canvas area */
|
|
11
|
+
label?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Format, quality and size bound for the save button. Defaults to
|
|
14
|
+
* PNG at natural resolution, which is lossless but large: a host
|
|
15
|
+
* saving over a photo will want its source format instead.
|
|
16
|
+
*/
|
|
17
|
+
exportOptions?: ExportOptions;
|
|
18
|
+
/**
|
|
19
|
+
* State to open with, as emitted by the change event, for resuming
|
|
20
|
+
* an edit that was not finished. Read when the source loads, so
|
|
21
|
+
* changing it later has no effect until the source changes too.
|
|
22
|
+
*/
|
|
23
|
+
initialState?: EditorState;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** All values range from -100 to 100, 0 meaning unchanged */
|
|
27
|
+
export declare interface Adjustments {
|
|
28
|
+
brightness: number;
|
|
29
|
+
contrast: number;
|
|
30
|
+
saturation: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export declare type Annotation = DrawAnnotation | ArrowAnnotation | BoxAnnotation | TextAnnotation | RedactAnnotation;
|
|
34
|
+
|
|
35
|
+
export declare interface ArrowAnnotation {
|
|
36
|
+
id: string;
|
|
37
|
+
type: 'arrow';
|
|
38
|
+
/** [fromX, fromY, toX, toY] in oriented image coordinates */
|
|
39
|
+
points: [number, number, number, number];
|
|
40
|
+
color: string;
|
|
41
|
+
strokeWidth: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare interface BoxAnnotation {
|
|
45
|
+
id: string;
|
|
46
|
+
type: 'rectangle' | 'ellipse';
|
|
47
|
+
/** The shape's local frame: rotation pivots on the rect's top-left */
|
|
48
|
+
rect: Rect;
|
|
49
|
+
/** Clockwise degrees around the rect's top-left corner */
|
|
50
|
+
rotation: number;
|
|
51
|
+
color: string;
|
|
52
|
+
strokeWidth: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A pristine edit state: nothing rotated, cropped, adjusted or annotated.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createInitialState(): EditorState;
|
|
59
|
+
|
|
60
|
+
export declare interface DrawAnnotation {
|
|
61
|
+
id: string;
|
|
62
|
+
type: 'draw';
|
|
63
|
+
/** Flat [x1, y1, x2, y2, …] polyline in oriented image coordinates */
|
|
64
|
+
points: number[];
|
|
65
|
+
color: string;
|
|
66
|
+
strokeWidth: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export declare interface EditorState {
|
|
70
|
+
rotation: Rotation;
|
|
71
|
+
/** Additional free rotation in degrees, -45 to 45 */
|
|
72
|
+
fineRotation: number;
|
|
73
|
+
/** Center zoom factor, 1 or greater */
|
|
74
|
+
zoom: number;
|
|
75
|
+
flipX: boolean;
|
|
76
|
+
flipY: boolean;
|
|
77
|
+
/** Crop rectangle in oriented image coordinates, null meaning uncropped */
|
|
78
|
+
crop: Rect | null;
|
|
79
|
+
adjustments: Adjustments;
|
|
80
|
+
preset: FilterPreset;
|
|
81
|
+
annotations: Annotation[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
|
|
86
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
87
|
+
*/
|
|
88
|
+
export declare interface ExportOptions {
|
|
89
|
+
/** Target MIME type, defaults to 'image/png' */
|
|
90
|
+
format?: 'image/png' | 'image/jpeg' | 'image/webp';
|
|
91
|
+
/** Encoder quality between 0 and 1, only for lossy formats */
|
|
92
|
+
quality?: number;
|
|
93
|
+
/** Bound the longest output edge, never upscaling */
|
|
94
|
+
maxSize?: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export declare interface ExportResult {
|
|
98
|
+
blob: Blob;
|
|
99
|
+
width: number;
|
|
100
|
+
height: number;
|
|
101
|
+
mimeType: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export declare type FilterPreset = 'none' | 'grayscale' | 'noir' | 'luna' | 'sepia' | 'fade' | 'warm' | 'cool' | 'golden' | 'coast' | 'mist' | 'berry' | 'cinema' | 'invert' | 'solarize' | 'posterize' | 'pop';
|
|
105
|
+
|
|
106
|
+
declare interface HistoryEntry<T> {
|
|
107
|
+
/** The recorded state */
|
|
108
|
+
snapshot: T;
|
|
109
|
+
/**
|
|
110
|
+
* What the user did to get here, already translated. Undefined for
|
|
111
|
+
* a step whose call site did not name it.
|
|
112
|
+
*/
|
|
113
|
+
label?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export declare const ImageEditor: DefineComponent<__VLS_Props, {
|
|
117
|
+
exportImage: (options?: ExportOptions) => Promise<ExportResult>;
|
|
118
|
+
/**
|
|
119
|
+
* Start over, optionally from a given state.
|
|
120
|
+
*
|
|
121
|
+
* @param state state to reset to, defaulting to a pristine one
|
|
122
|
+
*/
|
|
123
|
+
reset: (state?: EditorState) => void;
|
|
124
|
+
}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
125
|
+
cancel: () => any;
|
|
126
|
+
change: (state: EditorState) => any;
|
|
127
|
+
error: (error: Error) => any;
|
|
128
|
+
save: (result: ExportResult) => any;
|
|
129
|
+
}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
130
|
+
onCancel?: (() => any) | undefined;
|
|
131
|
+
onChange?: ((state: EditorState) => any) | undefined;
|
|
132
|
+
onError?: ((error: Error) => any) | undefined;
|
|
133
|
+
onSave?: ((result: ExportResult) => any) | undefined;
|
|
134
|
+
}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {
|
|
135
|
+
container: HTMLDivElement;
|
|
136
|
+
}, HTMLDivElement>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Whether a state carries no edit at all, matching a fresh one from
|
|
140
|
+
* createInitialState. Consumers can use it for a dirty check, and the
|
|
141
|
+
* editor uses it to hand an untouched image back as it came in.
|
|
142
|
+
*
|
|
143
|
+
* @param state the state to inspect
|
|
144
|
+
*/
|
|
145
|
+
export declare function isPristine(state: EditorState): boolean;
|
|
146
|
+
|
|
147
|
+
export declare interface Rect {
|
|
148
|
+
x: number;
|
|
149
|
+
y: number;
|
|
150
|
+
width: number;
|
|
151
|
+
height: number;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export declare interface RedactAnnotation {
|
|
155
|
+
id: string;
|
|
156
|
+
type: 'redact';
|
|
157
|
+
/** Region to obfuscate, in oriented image coordinates */
|
|
158
|
+
rect: Rect;
|
|
159
|
+
/** How the region is destroyed */
|
|
160
|
+
style: 'pixelate' | 'blur';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
|
|
165
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
166
|
+
*/
|
|
167
|
+
export declare type Rotation = 0 | 90 | 180 | 270;
|
|
168
|
+
|
|
169
|
+
export declare interface Size {
|
|
170
|
+
width: number;
|
|
171
|
+
height: number;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export declare interface TextAnnotation {
|
|
175
|
+
id: string;
|
|
176
|
+
type: 'text' | 'sticker';
|
|
177
|
+
x: number;
|
|
178
|
+
y: number;
|
|
179
|
+
/** Text content, or the emoji character for stickers */
|
|
180
|
+
text: string;
|
|
181
|
+
color: string;
|
|
182
|
+
fontSize: number;
|
|
183
|
+
/** Clockwise degrees around the anchor */
|
|
184
|
+
rotation: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export declare interface UseHistory<T> {
|
|
188
|
+
/** Whether an older snapshot is available */
|
|
189
|
+
canUndo: ComputedRef<boolean>;
|
|
190
|
+
/** Whether a newer snapshot is available */
|
|
191
|
+
canRedo: ComputedRef<boolean>;
|
|
192
|
+
/** The active snapshot, undefined while the history is empty */
|
|
193
|
+
current: ComputedRef<T | undefined>;
|
|
194
|
+
/** Every recorded step, oldest first */
|
|
195
|
+
entries: ComputedRef<readonly HistoryEntry<T>[]>;
|
|
196
|
+
/** Position of the active step in entries, -1 while empty */
|
|
197
|
+
index: ComputedRef<number>;
|
|
198
|
+
/**
|
|
199
|
+
* Append a snapshot after the active one, discarding any redoable
|
|
200
|
+
* entries.
|
|
201
|
+
*
|
|
202
|
+
* @param snapshot the state to record
|
|
203
|
+
* @param label what the user did, for a history list
|
|
204
|
+
*/
|
|
205
|
+
push(snapshot: T, label?: string): void;
|
|
206
|
+
/** Move back one snapshot and return it, or undefined at the oldest entry */
|
|
207
|
+
undo(): T | undefined;
|
|
208
|
+
/** Move forward one snapshot and return it, or undefined at the newest entry */
|
|
209
|
+
redo(): T | undefined;
|
|
210
|
+
/**
|
|
211
|
+
* Move to an arbitrary step and return its snapshot, or undefined
|
|
212
|
+
* where there is no such step or it is the active one already.
|
|
213
|
+
*
|
|
214
|
+
* @param target position in entries
|
|
215
|
+
*/
|
|
216
|
+
jumpTo(target: number): T | undefined;
|
|
217
|
+
/** Drop all snapshots */
|
|
218
|
+
clear(): void;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Linear undo/redo history of immutable state snapshots.
|
|
223
|
+
*
|
|
224
|
+
* Snapshots are treated as opaque immutable values. Whatever is pushed
|
|
225
|
+
* must not be mutated afterwards, or the history it sits in changes
|
|
226
|
+
* under the caller; pushing a reference to a value the caller keeps
|
|
227
|
+
* building new versions of is fine, and cheaper than copying.
|
|
228
|
+
*
|
|
229
|
+
* @param capacity maximum number of snapshots kept, oldest dropped first
|
|
230
|
+
*/
|
|
231
|
+
export declare function useHistory<T>(capacity?: number): UseHistory<T>;
|
|
232
|
+
|
|
233
|
+
export { }
|