@gradio/imageeditor 0.19.0 → 0.20.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/CHANGELOG.md +32 -0
- package/Example.svelte +9 -3
- package/Index.svelte +23 -24
- package/InteractiveImageEditor.svelte +99 -61
- package/dist/Example.svelte +9 -3
- package/dist/Example.svelte.d.ts +4 -18
- package/dist/Index.svelte +23 -24
- package/dist/Index.svelte.d.ts +2 -19
- package/dist/InteractiveImageEditor.svelte +99 -61
- package/dist/InteractiveImageEditor.svelte.d.ts +15 -32
- package/dist/shared/Anchor.svelte +13 -11
- package/dist/shared/Anchor.svelte.d.ts +4 -19
- package/dist/shared/Controls.svelte +63 -39
- package/dist/shared/Controls.svelte.d.ts +13 -28
- package/dist/shared/IconButton.svelte +38 -17
- package/dist/shared/IconButton.svelte.d.ts +5 -19
- package/dist/shared/ImageEditor.svelte +235 -160
- package/dist/shared/ImageEditor.svelte.d.ts +55 -2
- package/dist/shared/Layers.svelte +43 -29
- package/dist/shared/Layers.svelte.d.ts +10 -25
- package/dist/shared/Resize.svelte +22 -16
- package/dist/shared/Resize.svelte.d.ts +6 -22
- package/dist/shared/SecondaryToolbar.svelte +34 -18
- package/dist/shared/SecondaryToolbar.svelte.d.ts +10 -25
- package/dist/shared/Toolbar.svelte +60 -76
- package/dist/shared/Toolbar.svelte.d.ts +9 -24
- package/dist/shared/brush/BrushOptions.svelte +49 -29
- package/dist/shared/brush/BrushOptions.svelte.d.ts +6 -21
- package/dist/shared/brush/BrushSize.svelte +12 -9
- package/dist/shared/brush/BrushSize.svelte.d.ts +5 -20
- package/dist/shared/brush/ColorField.svelte +21 -16
- package/dist/shared/brush/ColorField.svelte.d.ts +6 -22
- package/dist/shared/brush/ColorPicker.svelte +22 -16
- package/dist/shared/brush/ColorPicker.svelte.d.ts +4 -18
- package/dist/shared/brush/ColorSwatch.svelte +41 -21
- package/dist/shared/brush/ColorSwatch.svelte.d.ts +10 -24
- package/dist/shared/brush/brush.js +7 -8
- package/dist/shared/core/editor.d.ts +5 -0
- package/dist/shared/core/editor.js +43 -2
- package/dist/shared/resize/resize.d.ts +2 -0
- package/dist/shared/resize/resize.js +27 -18
- package/package.json +9 -9
- package/shared/Anchor.svelte +13 -11
- package/shared/Controls.svelte +63 -39
- package/shared/IconButton.svelte +38 -17
- package/shared/ImageEditor.svelte +235 -160
- package/shared/Layers.svelte +43 -29
- package/shared/Resize.svelte +22 -16
- package/shared/SecondaryToolbar.svelte +34 -18
- package/shared/Toolbar.svelte +60 -76
- package/shared/brush/BrushOptions.svelte +49 -29
- package/shared/brush/BrushSize.svelte +12 -9
- package/shared/brush/ColorField.svelte +21 -16
- package/shared/brush/ColorPicker.svelte +22 -16
- package/shared/brush/ColorSwatch.svelte +41 -21
- package/shared/brush/brush.ts +8 -10
- package/shared/core/editor.ts +49 -2
- package/shared/resize/resize.ts +28 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @gradio/imageeditor
|
|
2
2
|
|
|
3
|
+
## 0.20.1
|
|
4
|
+
|
|
5
|
+
### Dependency updates
|
|
6
|
+
|
|
7
|
+
- @gradio/client@2.4.0
|
|
8
|
+
- @gradio/utils@0.14.0
|
|
9
|
+
- @gradio/atoms@0.26.1
|
|
10
|
+
- @gradio/statustracker@0.15.2
|
|
11
|
+
- @gradio/upload@0.18.2
|
|
12
|
+
- @gradio/image@0.28.1
|
|
13
|
+
|
|
14
|
+
## 0.20.0
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
- [#13543](https://github.com/gradio-app/gradio/pull/13543) [`0533483`](https://github.com/gradio-app/gradio/commit/0533483bccdee38f334a598f18297e8c02966343) - Migrate Image components to Svelte 5. Thanks @dawoodkhan82!
|
|
19
|
+
|
|
20
|
+
### Fixes
|
|
21
|
+
|
|
22
|
+
- [#13571](https://github.com/gradio-app/gradio/pull/13571) [`c576675`](https://github.com/gradio-app/gradio/commit/c576675c1d0d9a917706bb830f7a738d9f96672f) - Fix `gr.ImageEditor` high CPU usage when idle by sleeping the render loop when nothing is changing. Thanks @abidlabs!
|
|
23
|
+
- [`dcc654d`](https://github.com/gradio-app/gradio/commit/dcc654d8467c9202a78c50b31e7d123e9804ebf4) - Fix ImageEditor transform tools and hidden cleanup. Thanks @dawoodkhan82!
|
|
24
|
+
- [#13597](https://github.com/gradio-app/gradio/pull/13597) [`7a595cb`](https://github.com/gradio-app/gradio/commit/7a595cb72d8a82151ee2231e86d20c91d0bb9062) - Fix ImageEditor brush texture resets. Thanks @dawoodkhan82!
|
|
25
|
+
|
|
26
|
+
### Dependency updates
|
|
27
|
+
|
|
28
|
+
- @gradio/statustracker@0.15.1
|
|
29
|
+
- @gradio/icons@0.16.0
|
|
30
|
+
- @gradio/atoms@0.26.0
|
|
31
|
+
- @gradio/image@0.28.0
|
|
32
|
+
- @gradio/client@2.3.1
|
|
33
|
+
- @gradio/upload@0.18.1
|
|
34
|
+
|
|
3
35
|
## 0.19.0
|
|
4
36
|
|
|
5
37
|
### Features
|
package/Example.svelte
CHANGED
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
import { BaseImage as Image } from "@gradio/image";
|
|
3
3
|
import type { EditorData } from "./InteractiveImageEditor.svelte";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let {
|
|
6
|
+
value,
|
|
7
|
+
type,
|
|
8
|
+
selected = false
|
|
9
|
+
}: {
|
|
10
|
+
value: EditorData;
|
|
11
|
+
type: "gallery" | "table";
|
|
12
|
+
selected?: boolean;
|
|
13
|
+
} = $props();
|
|
8
14
|
</script>
|
|
9
15
|
|
|
10
16
|
<div
|
package/Index.svelte
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { Block } from "@gradio/atoms";
|
|
11
11
|
import { StatusTracker } from "@gradio/statustracker";
|
|
12
12
|
|
|
13
|
-
import { Gradio } from "@gradio/utils";
|
|
13
|
+
import { Gradio, type ShareData } from "@gradio/utils";
|
|
14
14
|
import type { ImageEditorEvents, ImageEditorProps } from "./types";
|
|
15
15
|
|
|
16
16
|
let props = $props();
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
return blobs;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
let is_dragging
|
|
50
|
+
let is_dragging = $state(false);
|
|
51
51
|
|
|
52
52
|
const is_browser = typeof window !== "undefined";
|
|
53
53
|
|
|
@@ -84,6 +84,14 @@
|
|
|
84
84
|
let normalised_layers = $derived(
|
|
85
85
|
gradio.props.value?.layers?.map((layer) => new FileData(layer)) || []
|
|
86
86
|
);
|
|
87
|
+
let resolved_theme_mode: "dark" | "light" = $derived(
|
|
88
|
+
gradio.shared.theme_mode === "dark" ||
|
|
89
|
+
(gradio.shared.theme_mode === "system" &&
|
|
90
|
+
typeof window !== "undefined" &&
|
|
91
|
+
window.matchMedia?.("(prefers-color-scheme: dark)").matches)
|
|
92
|
+
? "dark"
|
|
93
|
+
: "light"
|
|
94
|
+
);
|
|
87
95
|
</script>
|
|
88
96
|
|
|
89
97
|
{#if !gradio.shared.interactive}
|
|
@@ -110,9 +118,9 @@
|
|
|
110
118
|
gradio.dispatch("clear_status", gradio.shared.loading_status)}
|
|
111
119
|
/>
|
|
112
120
|
<StaticImage
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
121
|
+
onselect={(detail) => gradio.dispatch("select", detail)}
|
|
122
|
+
onshare={(detail) => gradio.dispatch("share", detail as ShareData)}
|
|
123
|
+
onerror={(detail) => gradio.dispatch("error", detail)}
|
|
116
124
|
value={gradio.props.value?.composite || null}
|
|
117
125
|
label={gradio.shared.label}
|
|
118
126
|
show_label={gradio.shared.show_label}
|
|
@@ -159,38 +167,29 @@
|
|
|
159
167
|
label={gradio.shared.label}
|
|
160
168
|
show_label={gradio.shared.show_label}
|
|
161
169
|
fixed_canvas={gradio.props.fixed_canvas}
|
|
162
|
-
|
|
170
|
+
oninput={() => {
|
|
163
171
|
if (!has_run_input) {
|
|
164
172
|
has_run_input = true;
|
|
165
173
|
} else {
|
|
166
174
|
gradio.dispatch("input");
|
|
167
175
|
}
|
|
168
176
|
}}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
on:upload={() => gradio.dispatch("upload")}
|
|
174
|
-
on:share={({ detail }) => gradio.dispatch("share", detail)}
|
|
175
|
-
on:error={({ detail }) => {
|
|
176
|
-
gradio.shared.loading_status = gradio.shared.loading_status || {};
|
|
177
|
-
gradio.shared.loading_status.status = "error";
|
|
178
|
-
gradio.dispatch("error", detail);
|
|
179
|
-
}}
|
|
180
|
-
on:receive_null={() =>
|
|
177
|
+
onsave={() => handle_save()}
|
|
178
|
+
onclear={() => gradio.dispatch("clear")}
|
|
179
|
+
onupload={() => gradio.dispatch("upload")}
|
|
180
|
+
onreceive_null={() =>
|
|
181
181
|
(gradio.props.value = {
|
|
182
182
|
background: null,
|
|
183
183
|
layers: [],
|
|
184
184
|
composite: null
|
|
185
185
|
})}
|
|
186
|
-
|
|
186
|
+
onchange={() => {
|
|
187
187
|
if (!has_run_change) {
|
|
188
188
|
has_run_change = true;
|
|
189
189
|
} else {
|
|
190
190
|
gradio.dispatch("change");
|
|
191
191
|
}
|
|
192
192
|
}}
|
|
193
|
-
on:error
|
|
194
193
|
brush={gradio.props.brush ?? false}
|
|
195
194
|
eraser={gradio.props.eraser ?? false}
|
|
196
195
|
changeable={gradio.shared.attached_events?.includes("apply") ?? false}
|
|
@@ -199,15 +198,15 @@
|
|
|
199
198
|
i18n={gradio.i18n}
|
|
200
199
|
transforms={gradio.props.transforms ?? []}
|
|
201
200
|
accept_blobs={gradio.shared.server.accept_blobs}
|
|
202
|
-
layer_options={gradio.props.layers}
|
|
201
|
+
layer_options={gradio.props.layers!}
|
|
203
202
|
upload={(...args) => gradio.shared.client.upload(...args)}
|
|
204
203
|
placeholder={gradio.props.placeholder}
|
|
205
|
-
webcam_options={gradio.props.webcam_options}
|
|
204
|
+
webcam_options={gradio.props.webcam_options!}
|
|
206
205
|
show_download_button={gradio.props.buttons === null
|
|
207
206
|
? true
|
|
208
207
|
: (gradio.props.buttons ?? []).includes("download")}
|
|
209
|
-
theme_mode={
|
|
210
|
-
|
|
208
|
+
theme_mode={resolved_theme_mode}
|
|
209
|
+
ondownload_error={(detail) => gradio.dispatch("error", detail)}
|
|
211
210
|
></InteractiveImageEditor>
|
|
212
211
|
</Block>
|
|
213
212
|
{/if}
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
</script>
|
|
14
14
|
|
|
15
15
|
<script lang="ts">
|
|
16
|
-
import { createEventDispatcher } from "svelte";
|
|
17
16
|
import { type I18nFormatter } from "@gradio/utils";
|
|
18
17
|
import { prepare_files, type FileData, type Client } from "@gradio/client";
|
|
19
18
|
import { type CommandNode } from "./shared/core/commands";
|
|
@@ -31,48 +30,82 @@
|
|
|
31
30
|
type WebcamOptions
|
|
32
31
|
} from "./shared/types";
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
33
|
+
let {
|
|
34
|
+
brush,
|
|
35
|
+
eraser,
|
|
36
|
+
sources,
|
|
37
|
+
i18n,
|
|
38
|
+
root,
|
|
39
|
+
label = undefined,
|
|
40
|
+
show_label,
|
|
41
|
+
changeable = false,
|
|
42
|
+
theme_mode,
|
|
43
|
+
layers,
|
|
44
|
+
composite,
|
|
45
|
+
background,
|
|
46
|
+
layer_options = {
|
|
47
|
+
allow_additional_layers: true,
|
|
48
|
+
layers: [],
|
|
49
|
+
disabled: false
|
|
50
|
+
},
|
|
51
|
+
transforms,
|
|
52
|
+
accept_blobs,
|
|
53
|
+
canvas_size,
|
|
54
|
+
fixed_canvas = false,
|
|
55
|
+
realtime = false,
|
|
56
|
+
upload,
|
|
57
|
+
is_dragging = $bindable(),
|
|
58
|
+
placeholder = undefined,
|
|
59
|
+
border_region,
|
|
60
|
+
full_history = $bindable(null),
|
|
61
|
+
webcam_options = { mirror: true, constraints: {} },
|
|
62
|
+
show_download_button = false,
|
|
63
|
+
image_id = $bindable(null),
|
|
64
|
+
onclear,
|
|
65
|
+
onupload,
|
|
66
|
+
onchange,
|
|
67
|
+
oninput,
|
|
68
|
+
onsave,
|
|
69
|
+
onreceive_null,
|
|
70
|
+
ondownload_error
|
|
71
|
+
}: {
|
|
72
|
+
brush: IBrush | false;
|
|
73
|
+
eraser: Eraser | false;
|
|
74
|
+
sources: Source[];
|
|
75
|
+
i18n: I18nFormatter;
|
|
76
|
+
root: string;
|
|
77
|
+
label?: string;
|
|
78
|
+
show_label: boolean;
|
|
79
|
+
changeable?: boolean;
|
|
80
|
+
theme_mode: "dark" | "light";
|
|
81
|
+
layers: FileData[];
|
|
82
|
+
composite: FileData | null;
|
|
83
|
+
background: FileData | null;
|
|
84
|
+
layer_options?: LayerOptions;
|
|
85
|
+
transforms: Transform[];
|
|
86
|
+
accept_blobs: (a: any) => void;
|
|
87
|
+
canvas_size: [number, number];
|
|
88
|
+
fixed_canvas?: boolean;
|
|
89
|
+
realtime?: boolean;
|
|
90
|
+
upload: Client["upload"];
|
|
91
|
+
is_dragging?: boolean;
|
|
92
|
+
placeholder?: string;
|
|
93
|
+
border_region: number;
|
|
94
|
+
full_history?: CommandNode | null;
|
|
95
|
+
webcam_options?: WebcamOptions;
|
|
96
|
+
show_download_button?: boolean;
|
|
97
|
+
image_id?: null | string;
|
|
98
|
+
onclear?: () => void;
|
|
99
|
+
onupload?: () => void;
|
|
100
|
+
onchange?: () => void;
|
|
101
|
+
oninput?: () => void;
|
|
102
|
+
onsave?: () => void;
|
|
103
|
+
onreceive_null?: () => void;
|
|
104
|
+
ondownload_error?: (error: string) => void;
|
|
105
|
+
} = $props();
|
|
73
106
|
|
|
74
107
|
let editor: ImageEditor;
|
|
75
|
-
let has_drawn = false;
|
|
108
|
+
let has_drawn = $state(false);
|
|
76
109
|
|
|
77
110
|
function is_not_null(o: Blob | null): o is Blob {
|
|
78
111
|
return !!o;
|
|
@@ -82,7 +115,9 @@
|
|
|
82
115
|
return !!o;
|
|
83
116
|
}
|
|
84
117
|
|
|
85
|
-
|
|
118
|
+
$effect(() => {
|
|
119
|
+
if (background_image) onupload?.();
|
|
120
|
+
});
|
|
86
121
|
|
|
87
122
|
export async function get_data(): Promise<ImageBlobs> {
|
|
88
123
|
let blobs;
|
|
@@ -131,16 +166,16 @@
|
|
|
131
166
|
if (!editor) return;
|
|
132
167
|
if (value == null) {
|
|
133
168
|
editor.handle_remove();
|
|
134
|
-
|
|
169
|
+
onreceive_null?.();
|
|
135
170
|
}
|
|
136
171
|
}
|
|
137
172
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
let can_undo: boolean;
|
|
173
|
+
$effect(() => {
|
|
174
|
+
handle_value({ layers, composite, background });
|
|
175
|
+
});
|
|
142
176
|
|
|
143
|
-
|
|
177
|
+
let background_image = $state(false);
|
|
178
|
+
let can_undo = $state(false);
|
|
144
179
|
|
|
145
180
|
type BinaryImages = [string, string, File, number | null][];
|
|
146
181
|
|
|
@@ -148,9 +183,9 @@
|
|
|
148
183
|
return new Promise((resolve) => setTimeout(() => resolve(), 30));
|
|
149
184
|
}
|
|
150
185
|
|
|
151
|
-
let uploading = false;
|
|
152
|
-
let pending = false;
|
|
153
|
-
async function handle_change(
|
|
186
|
+
let uploading = $state(false);
|
|
187
|
+
let pending = $state(false);
|
|
188
|
+
async function handle_change(): Promise<void> {
|
|
154
189
|
if (!realtime) return;
|
|
155
190
|
if (uploading) {
|
|
156
191
|
pending = true;
|
|
@@ -193,19 +228,23 @@
|
|
|
193
228
|
})
|
|
194
229
|
);
|
|
195
230
|
image_id = id;
|
|
196
|
-
|
|
231
|
+
onchange?.();
|
|
197
232
|
await nextframe();
|
|
198
233
|
uploading = false;
|
|
199
234
|
if (pending) {
|
|
200
235
|
pending = false;
|
|
201
236
|
uploading = false;
|
|
202
|
-
handle_change(
|
|
237
|
+
handle_change();
|
|
203
238
|
}
|
|
204
239
|
}
|
|
205
240
|
|
|
206
|
-
|
|
241
|
+
let placeholder_parts = $derived(
|
|
242
|
+
placeholder ? inject(placeholder) : [false, false]
|
|
243
|
+
);
|
|
244
|
+
let heading = $derived(placeholder_parts[0]);
|
|
245
|
+
let paragraph = $derived(placeholder_parts[1]);
|
|
207
246
|
|
|
208
|
-
let current_tool
|
|
247
|
+
let current_tool = $state<ToolbarTool>("image");
|
|
209
248
|
</script>
|
|
210
249
|
|
|
211
250
|
<BlockLabel
|
|
@@ -218,15 +257,14 @@
|
|
|
218
257
|
{composite}
|
|
219
258
|
{layers}
|
|
220
259
|
{background}
|
|
221
|
-
on:history
|
|
222
260
|
{canvas_size}
|
|
223
261
|
bind:this={editor}
|
|
224
262
|
{changeable}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
263
|
+
{onsave}
|
|
264
|
+
{oninput}
|
|
265
|
+
onchange={handle_change}
|
|
266
|
+
onclear={() => onclear?.()}
|
|
267
|
+
{ondownload_error}
|
|
230
268
|
{sources}
|
|
231
269
|
bind:background_image
|
|
232
270
|
bind:current_tool
|
package/dist/Example.svelte
CHANGED
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
import { BaseImage as Image } from "@gradio/image";
|
|
3
3
|
import type { EditorData } from "./InteractiveImageEditor.svelte";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let {
|
|
6
|
+
value,
|
|
7
|
+
type,
|
|
8
|
+
selected = false
|
|
9
|
+
}: {
|
|
10
|
+
value: EditorData;
|
|
11
|
+
type: "gallery" | "table";
|
|
12
|
+
selected?: boolean;
|
|
13
|
+
} = $props();
|
|
8
14
|
</script>
|
|
9
15
|
|
|
10
16
|
<div
|
package/dist/Example.svelte.d.ts
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import type { EditorData } from "./InteractiveImageEditor.svelte";
|
|
2
|
-
|
|
3
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports & {
|
|
10
|
-
$set?: any;
|
|
11
|
-
$on?: any;
|
|
12
|
-
};
|
|
13
|
-
z_$$bindings?: Bindings;
|
|
14
|
-
}
|
|
15
|
-
declare const Example: $$__sveltets_2_IsomorphicComponent<{
|
|
2
|
+
type $$ComponentProps = {
|
|
16
3
|
value: EditorData;
|
|
17
4
|
type: "gallery" | "table";
|
|
18
5
|
selected?: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
type Example = InstanceType<typeof Example>;
|
|
6
|
+
};
|
|
7
|
+
declare const Example: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type Example = ReturnType<typeof Example>;
|
|
23
9
|
export default Example;
|
package/dist/Index.svelte
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { Block } from "@gradio/atoms";
|
|
11
11
|
import { StatusTracker } from "@gradio/statustracker";
|
|
12
12
|
|
|
13
|
-
import { Gradio } from "@gradio/utils";
|
|
13
|
+
import { Gradio, type ShareData } from "@gradio/utils";
|
|
14
14
|
import type { ImageEditorEvents, ImageEditorProps } from "./types";
|
|
15
15
|
|
|
16
16
|
let props = $props();
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
return blobs;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
let is_dragging
|
|
50
|
+
let is_dragging = $state(false);
|
|
51
51
|
|
|
52
52
|
const is_browser = typeof window !== "undefined";
|
|
53
53
|
|
|
@@ -84,6 +84,14 @@
|
|
|
84
84
|
let normalised_layers = $derived(
|
|
85
85
|
gradio.props.value?.layers?.map((layer) => new FileData(layer)) || []
|
|
86
86
|
);
|
|
87
|
+
let resolved_theme_mode: "dark" | "light" = $derived(
|
|
88
|
+
gradio.shared.theme_mode === "dark" ||
|
|
89
|
+
(gradio.shared.theme_mode === "system" &&
|
|
90
|
+
typeof window !== "undefined" &&
|
|
91
|
+
window.matchMedia?.("(prefers-color-scheme: dark)").matches)
|
|
92
|
+
? "dark"
|
|
93
|
+
: "light"
|
|
94
|
+
);
|
|
87
95
|
</script>
|
|
88
96
|
|
|
89
97
|
{#if !gradio.shared.interactive}
|
|
@@ -110,9 +118,9 @@
|
|
|
110
118
|
gradio.dispatch("clear_status", gradio.shared.loading_status)}
|
|
111
119
|
/>
|
|
112
120
|
<StaticImage
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
121
|
+
onselect={(detail) => gradio.dispatch("select", detail)}
|
|
122
|
+
onshare={(detail) => gradio.dispatch("share", detail as ShareData)}
|
|
123
|
+
onerror={(detail) => gradio.dispatch("error", detail)}
|
|
116
124
|
value={gradio.props.value?.composite || null}
|
|
117
125
|
label={gradio.shared.label}
|
|
118
126
|
show_label={gradio.shared.show_label}
|
|
@@ -159,38 +167,29 @@
|
|
|
159
167
|
label={gradio.shared.label}
|
|
160
168
|
show_label={gradio.shared.show_label}
|
|
161
169
|
fixed_canvas={gradio.props.fixed_canvas}
|
|
162
|
-
|
|
170
|
+
oninput={() => {
|
|
163
171
|
if (!has_run_input) {
|
|
164
172
|
has_run_input = true;
|
|
165
173
|
} else {
|
|
166
174
|
gradio.dispatch("input");
|
|
167
175
|
}
|
|
168
176
|
}}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
on:upload={() => gradio.dispatch("upload")}
|
|
174
|
-
on:share={({ detail }) => gradio.dispatch("share", detail)}
|
|
175
|
-
on:error={({ detail }) => {
|
|
176
|
-
gradio.shared.loading_status = gradio.shared.loading_status || {};
|
|
177
|
-
gradio.shared.loading_status.status = "error";
|
|
178
|
-
gradio.dispatch("error", detail);
|
|
179
|
-
}}
|
|
180
|
-
on:receive_null={() =>
|
|
177
|
+
onsave={() => handle_save()}
|
|
178
|
+
onclear={() => gradio.dispatch("clear")}
|
|
179
|
+
onupload={() => gradio.dispatch("upload")}
|
|
180
|
+
onreceive_null={() =>
|
|
181
181
|
(gradio.props.value = {
|
|
182
182
|
background: null,
|
|
183
183
|
layers: [],
|
|
184
184
|
composite: null
|
|
185
185
|
})}
|
|
186
|
-
|
|
186
|
+
onchange={() => {
|
|
187
187
|
if (!has_run_change) {
|
|
188
188
|
has_run_change = true;
|
|
189
189
|
} else {
|
|
190
190
|
gradio.dispatch("change");
|
|
191
191
|
}
|
|
192
192
|
}}
|
|
193
|
-
on:error
|
|
194
193
|
brush={gradio.props.brush ?? false}
|
|
195
194
|
eraser={gradio.props.eraser ?? false}
|
|
196
195
|
changeable={gradio.shared.attached_events?.includes("apply") ?? false}
|
|
@@ -199,15 +198,15 @@
|
|
|
199
198
|
i18n={gradio.i18n}
|
|
200
199
|
transforms={gradio.props.transforms ?? []}
|
|
201
200
|
accept_blobs={gradio.shared.server.accept_blobs}
|
|
202
|
-
layer_options={gradio.props.layers}
|
|
201
|
+
layer_options={gradio.props.layers!}
|
|
203
202
|
upload={(...args) => gradio.shared.client.upload(...args)}
|
|
204
203
|
placeholder={gradio.props.placeholder}
|
|
205
|
-
webcam_options={gradio.props.webcam_options}
|
|
204
|
+
webcam_options={gradio.props.webcam_options!}
|
|
206
205
|
show_download_button={gradio.props.buttons === null
|
|
207
206
|
? true
|
|
208
207
|
: (gradio.props.buttons ?? []).includes("download")}
|
|
209
|
-
theme_mode={
|
|
210
|
-
|
|
208
|
+
theme_mode={resolved_theme_mode}
|
|
209
|
+
ondownload_error={(detail) => gradio.dispatch("error", detail)}
|
|
211
210
|
></InteractiveImageEditor>
|
|
212
211
|
</Block>
|
|
213
212
|
{/if}
|
package/dist/Index.svelte.d.ts
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
$$bindings?: Bindings;
|
|
4
|
-
} & Exports;
|
|
5
|
-
(internal: unknown, props: Props & {
|
|
6
|
-
$$events?: Events;
|
|
7
|
-
$$slots?: Slots;
|
|
8
|
-
}): Exports & {
|
|
9
|
-
$set?: any;
|
|
10
|
-
$on?: any;
|
|
11
|
-
};
|
|
12
|
-
z_$$bindings?: Bindings;
|
|
13
|
-
}
|
|
14
|
-
declare const Index: $$__sveltets_2_IsomorphicComponent<$$ComponentProps, {
|
|
15
|
-
error: CustomEvent<any>;
|
|
16
|
-
} & {
|
|
17
|
-
[evt: string]: CustomEvent<any>;
|
|
18
|
-
}, {}, {}, "">;
|
|
19
|
-
type Index = InstanceType<typeof Index>;
|
|
1
|
+
declare const Index: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
2
|
+
type Index = ReturnType<typeof Index>;
|
|
20
3
|
export default Index;
|