@pixerate/editor-svelte 0.13.0 → 0.15.0

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.
@@ -0,0 +1,151 @@
1
+ import {
2
+ ImageEditorController,
3
+ type ImageEditorOptions,
4
+ type ImageEditorState,
5
+ type ImageEditorTool,
6
+ type CropBox,
7
+ type AspectRatio,
8
+ type ImageAdjustments,
9
+ type DepthMaskOptions,
10
+ type Annotation,
11
+ type CreateAnnotationPayload,
12
+ type ExportOptions,
13
+ type SerializedImageEditorState,
14
+ type ImagePoint,
15
+ } from '@pixerate/editor';
16
+
17
+ export function createReactiveImageEditor(options: ImageEditorOptions = {}) {
18
+ const controller = new ImageEditorController(options);
19
+ let state = $state<ImageEditorState>(controller.getState());
20
+ let historyTicks = $state<number>(0);
21
+
22
+ controller.subscribe((updated) => {
23
+ state = { ...updated };
24
+ historyTicks++;
25
+ });
26
+
27
+ return {
28
+ get controller() {
29
+ return controller;
30
+ },
31
+ get state() {
32
+ return state;
33
+ },
34
+ get canUndo() {
35
+ // depend on historyTicks for reactivity
36
+ void historyTicks;
37
+ return controller.canUndo;
38
+ },
39
+ get canRedo() {
40
+ void historyTicks;
41
+ return controller.canRedo;
42
+ },
43
+ setTool(tool: ImageEditorTool) {
44
+ controller.setTool(tool);
45
+ },
46
+ setCrop(crop: CropBox | null, addToHistory = true) {
47
+ controller.setCrop(crop, addToHistory);
48
+ },
49
+ applyCropPreset(ratio: AspectRatio) {
50
+ controller.applyCropPreset(ratio);
51
+ },
52
+ resetCrop() {
53
+ controller.resetCrop();
54
+ },
55
+ rotate(degrees: number) {
56
+ controller.rotate(degrees);
57
+ },
58
+ setRotation(degrees: number) {
59
+ controller.setRotation(degrees);
60
+ },
61
+ flipHorizontal() {
62
+ controller.flipHorizontal();
63
+ },
64
+ flipVertical() {
65
+ controller.flipVertical();
66
+ },
67
+ setAdjustments(partial: Partial<ImageAdjustments>, commitToHistory = true) {
68
+ controller.setAdjustments(partial, commitToHistory);
69
+ },
70
+ resetAdjustments() {
71
+ controller.resetAdjustments();
72
+ },
73
+ setDepthMask(partial: Partial<DepthMaskOptions>) {
74
+ controller.setDepthMask(partial);
75
+ },
76
+ resetDepthMask() {
77
+ controller.resetDepthMask();
78
+ },
79
+ addAnnotation(ann: CreateAnnotationPayload) {
80
+ return controller.addAnnotation(ann);
81
+ },
82
+ updateAnnotation(id: string, partial: Partial<Annotation>, commitToHistory = true) {
83
+ controller.updateAnnotation(id, partial, commitToHistory);
84
+ },
85
+ removeAnnotation(id: string) {
86
+ controller.removeAnnotation(id);
87
+ },
88
+ clearAnnotations() {
89
+ controller.clearAnnotations();
90
+ },
91
+ selectAnnotation(id: string | null) {
92
+ controller.selectAnnotation(id);
93
+ },
94
+ undo() {
95
+ return controller.undo();
96
+ },
97
+ redo() {
98
+ return controller.redo();
99
+ },
100
+ reset() {
101
+ controller.reset();
102
+ },
103
+ zoomIn(factor?: number) {
104
+ controller.zoomIn(factor);
105
+ },
106
+ zoomOut(factor?: number) {
107
+ controller.zoomOut(factor);
108
+ },
109
+ resetZoom() {
110
+ controller.resetZoom();
111
+ },
112
+ setZoom(zoom: number) {
113
+ controller.setZoom(zoom);
114
+ },
115
+ setPan(pan: ImagePoint) {
116
+ controller.setPan(pan);
117
+ },
118
+ setComparing(comparing: boolean) {
119
+ controller.setComparing(comparing);
120
+ },
121
+ loadImage(src: string | HTMLImageElement) {
122
+ return controller.loadImage(src);
123
+ },
124
+ toDataURL(opts?: ExportOptions) {
125
+ return controller.toDataURL(opts);
126
+ },
127
+ toBlob(opts?: ExportOptions) {
128
+ return controller.toBlob(opts);
129
+ },
130
+ toJSON() {
131
+ return controller.toJSON();
132
+ },
133
+ loadJSON(data: SerializedImageEditorState) {
134
+ controller.loadJSON(data);
135
+ },
136
+ renderMask(opts?: { useAnnotations?: boolean; useCrop?: boolean }) {
137
+ return controller.renderMask(opts);
138
+ },
139
+ toMaskDataURL(opts?: { useAnnotations?: boolean; useCrop?: boolean }) {
140
+ return controller.toMaskDataURL(opts);
141
+ },
142
+ applyInpaintedImage(newDataUrl: string) {
143
+ return controller.applyInpaintedImage(newDataUrl);
144
+ },
145
+ applyBackgroundRemovedImage(newDataUrl: string) {
146
+ return controller.applyBackgroundRemovedImage(newDataUrl);
147
+ },
148
+ };
149
+ }
150
+
151
+ export type ReactiveImageEditor = ReturnType<typeof createReactiveImageEditor>;
@@ -0,0 +1,16 @@
1
+ import type { Component } from 'svelte';
2
+ import type { ExportOptions, ImageEditorOptions } from '@pixerate/editor';
3
+ import type { ReactiveImageEditor } from './imageEditorState.svelte';
4
+
5
+ export interface ImageEditorProps {
6
+ editor?: ReactiveImageEditor;
7
+ src?: string;
8
+ class?: string;
9
+ style?: string;
10
+ onSave?: (dataUrl: string) => void;
11
+ exportOptions?: ExportOptions;
12
+ }
13
+
14
+ export declare const ImageEditor: Component<ImageEditorProps>;
15
+ export declare function createReactiveImageEditor(options?: ImageEditorOptions): ReactiveImageEditor;
16
+ export type { ReactiveImageEditor } from './imageEditorState.svelte';
@@ -0,0 +1,2 @@
1
+ export { default as ImageEditor } from './ImageEditor.svelte';
2
+ export * from './imageEditorState.svelte';
package/src/index.d.ts CHANGED
@@ -245,3 +245,5 @@ export type {
245
245
  HistoryState,
246
246
  HistoryManagerOptions,
247
247
  } from "@pixerate/editor";
248
+
249
+ export * from "./image-editor";
package/src/index.ts CHANGED
@@ -86,3 +86,4 @@ export type {
86
86
  } from "@pixerate/editor";
87
87
 
88
88
  export * from "./spreadsheet";
89
+ export * from "./image-editor";