@gradio/imageeditor 0.18.12 → 0.20.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.
- package/CHANGELOG.md +42 -0
- package/Example.svelte +9 -3
- package/ImageEditor.stories.svelte +0 -74
- package/Index.svelte +34 -35
- package/InteractiveImageEditor.svelte +99 -57
- package/dist/Example.svelte +9 -3
- package/dist/Example.svelte.d.ts +4 -18
- package/dist/Index.svelte +34 -35
- package/dist/Index.svelte.d.ts +2 -19
- package/dist/InteractiveImageEditor.svelte +99 -57
- package/dist/InteractiveImageEditor.svelte.d.ts +20 -37
- 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 +39 -18
- package/dist/shared/IconButton.svelte.d.ts +7 -21
- package/dist/shared/ImageEditor.svelte +246 -167
- 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 +10 -25
- 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/dist/types.d.ts +1 -1
- package/package.json +8 -8
- package/shared/Anchor.svelte +13 -11
- package/shared/Controls.svelte +63 -39
- package/shared/IconButton.svelte +39 -18
- package/shared/ImageEditor.svelte +246 -167
- 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/types.ts +1 -1
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,13 +118,13 @@
|
|
|
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}
|
|
119
|
-
buttons={gradio.props.buttons}
|
|
127
|
+
buttons={gradio.props.buttons ?? []}
|
|
120
128
|
selectable={gradio.props._selectable}
|
|
121
129
|
i18n={gradio.i18n}
|
|
122
130
|
/>
|
|
@@ -146,68 +154,59 @@
|
|
|
146
154
|
/>
|
|
147
155
|
|
|
148
156
|
<InteractiveImageEditor
|
|
149
|
-
border_region={gradio.props.border_region}
|
|
157
|
+
border_region={gradio.props.border_region ?? 0}
|
|
150
158
|
bind:is_dragging
|
|
151
|
-
canvas_size={gradio.props.canvas_size}
|
|
159
|
+
canvas_size={gradio.props.canvas_size ?? [800, 800]}
|
|
152
160
|
bind:image_id
|
|
153
161
|
layers={normalised_layers}
|
|
154
162
|
composite={normalised_composite}
|
|
155
163
|
background={normalised_background}
|
|
156
164
|
bind:this={editor_instance}
|
|
157
165
|
root={gradio.shared.root}
|
|
158
|
-
sources={gradio.props.sources}
|
|
166
|
+
sources={gradio.props.sources ?? ["upload", "webcam", "clipboard"]}
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
gradio.shared.attached_events.includes("input")}
|
|
193
|
+
brush={gradio.props.brush ?? false}
|
|
194
|
+
eraser={gradio.props.eraser ?? false}
|
|
195
|
+
changeable={gradio.shared.attached_events?.includes("apply") ?? false}
|
|
196
|
+
realtime={gradio.shared.attached_events?.includes("change") ||
|
|
197
|
+
gradio.shared.attached_events?.includes("input")}
|
|
199
198
|
i18n={gradio.i18n}
|
|
200
|
-
transforms={gradio.props.transforms}
|
|
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
|
-
: gradio.props.buttons.includes("download")}
|
|
209
|
-
theme_mode={
|
|
210
|
-
|
|
207
|
+
: (gradio.props.buttons ?? []).includes("download")}
|
|
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;
|
|
@@ -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,44 +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
|
-
|
|
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();
|
|
69
106
|
|
|
70
107
|
let editor: ImageEditor;
|
|
71
|
-
let has_drawn = false;
|
|
108
|
+
let has_drawn = $state(false);
|
|
72
109
|
|
|
73
110
|
function is_not_null(o: Blob | null): o is Blob {
|
|
74
111
|
return !!o;
|
|
@@ -78,7 +115,9 @@
|
|
|
78
115
|
return !!o;
|
|
79
116
|
}
|
|
80
117
|
|
|
81
|
-
|
|
118
|
+
$effect(() => {
|
|
119
|
+
if (background_image) onupload?.();
|
|
120
|
+
});
|
|
82
121
|
|
|
83
122
|
export async function get_data(): Promise<ImageBlobs> {
|
|
84
123
|
let blobs;
|
|
@@ -127,16 +166,16 @@
|
|
|
127
166
|
if (!editor) return;
|
|
128
167
|
if (value == null) {
|
|
129
168
|
editor.handle_remove();
|
|
130
|
-
|
|
169
|
+
onreceive_null?.();
|
|
131
170
|
}
|
|
132
171
|
}
|
|
133
172
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
let can_undo: boolean;
|
|
173
|
+
$effect(() => {
|
|
174
|
+
handle_value({ layers, composite, background });
|
|
175
|
+
});
|
|
138
176
|
|
|
139
|
-
|
|
177
|
+
let background_image = $state(false);
|
|
178
|
+
let can_undo = $state(false);
|
|
140
179
|
|
|
141
180
|
type BinaryImages = [string, string, File, number | null][];
|
|
142
181
|
|
|
@@ -144,9 +183,9 @@
|
|
|
144
183
|
return new Promise((resolve) => setTimeout(() => resolve(), 30));
|
|
145
184
|
}
|
|
146
185
|
|
|
147
|
-
let uploading = false;
|
|
148
|
-
let pending = false;
|
|
149
|
-
async function handle_change(
|
|
186
|
+
let uploading = $state(false);
|
|
187
|
+
let pending = $state(false);
|
|
188
|
+
async function handle_change(): Promise<void> {
|
|
150
189
|
if (!realtime) return;
|
|
151
190
|
if (uploading) {
|
|
152
191
|
pending = true;
|
|
@@ -189,19 +228,23 @@
|
|
|
189
228
|
})
|
|
190
229
|
);
|
|
191
230
|
image_id = id;
|
|
192
|
-
|
|
231
|
+
onchange?.();
|
|
193
232
|
await nextframe();
|
|
194
233
|
uploading = false;
|
|
195
234
|
if (pending) {
|
|
196
235
|
pending = false;
|
|
197
236
|
uploading = false;
|
|
198
|
-
handle_change(
|
|
237
|
+
handle_change();
|
|
199
238
|
}
|
|
200
239
|
}
|
|
201
240
|
|
|
202
|
-
|
|
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]);
|
|
203
246
|
|
|
204
|
-
let current_tool
|
|
247
|
+
let current_tool = $state<ToolbarTool>("image");
|
|
205
248
|
</script>
|
|
206
249
|
|
|
207
250
|
<BlockLabel
|
|
@@ -214,15 +257,14 @@
|
|
|
214
257
|
{composite}
|
|
215
258
|
{layers}
|
|
216
259
|
{background}
|
|
217
|
-
on:history
|
|
218
260
|
{canvas_size}
|
|
219
261
|
bind:this={editor}
|
|
220
262
|
{changeable}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
263
|
+
{onsave}
|
|
264
|
+
{oninput}
|
|
265
|
+
onchange={handle_change}
|
|
266
|
+
onclear={() => onclear?.()}
|
|
267
|
+
{ondownload_error}
|
|
226
268
|
{sources}
|
|
227
269
|
bind:background_image
|
|
228
270
|
bind:current_tool
|
|
@@ -13,60 +13,43 @@ import { type FileData, type Client } from "@gradio/client";
|
|
|
13
13
|
import { type CommandNode } from "./shared/core/commands";
|
|
14
14
|
import { type Brush as IBrush, type Eraser } from "./shared/brush/types";
|
|
15
15
|
import { type LayerOptions, type Transform, type Source, type WebcamOptions } from "./shared/types";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} & Exports;
|
|
20
|
-
(internal: unknown, props: Props & {
|
|
21
|
-
$$events?: Events;
|
|
22
|
-
$$slots?: Slots;
|
|
23
|
-
}): Exports & {
|
|
24
|
-
$set?: any;
|
|
25
|
-
$on?: any;
|
|
26
|
-
};
|
|
27
|
-
z_$$bindings?: Bindings;
|
|
28
|
-
}
|
|
29
|
-
declare const InteractiveImageEditor: $$__sveltets_2_IsomorphicComponent<{
|
|
30
|
-
brush: IBrush;
|
|
31
|
-
eraser: Eraser;
|
|
16
|
+
type $$ComponentProps = {
|
|
17
|
+
brush: IBrush | false;
|
|
18
|
+
eraser: Eraser | false;
|
|
32
19
|
sources: Source[];
|
|
33
20
|
i18n: I18nFormatter;
|
|
34
21
|
root: string;
|
|
35
|
-
label?: string
|
|
22
|
+
label?: string;
|
|
36
23
|
show_label: boolean;
|
|
37
24
|
changeable?: boolean;
|
|
38
25
|
theme_mode: "dark" | "light";
|
|
39
26
|
layers: FileData[];
|
|
40
27
|
composite: FileData | null;
|
|
41
28
|
background: FileData | null;
|
|
42
|
-
layer_options
|
|
29
|
+
layer_options?: LayerOptions;
|
|
43
30
|
transforms: Transform[];
|
|
44
31
|
accept_blobs: (a: any) => void;
|
|
45
32
|
canvas_size: [number, number];
|
|
46
33
|
fixed_canvas?: boolean;
|
|
47
|
-
realtime
|
|
34
|
+
realtime?: boolean;
|
|
48
35
|
upload: Client["upload"];
|
|
49
|
-
is_dragging
|
|
50
|
-
placeholder?: string
|
|
36
|
+
is_dragging?: boolean;
|
|
37
|
+
placeholder?: string;
|
|
51
38
|
border_region: number;
|
|
52
39
|
full_history?: CommandNode | null;
|
|
53
|
-
webcam_options
|
|
40
|
+
webcam_options?: WebcamOptions;
|
|
54
41
|
show_download_button?: boolean;
|
|
55
|
-
get_data?: () => Promise<ImageBlobs>;
|
|
56
42
|
image_id?: null | string;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
} & {
|
|
67
|
-
[evt: string]: CustomEvent<any>;
|
|
68
|
-
}, {}, {
|
|
43
|
+
onclear?: () => void;
|
|
44
|
+
onupload?: () => void;
|
|
45
|
+
onchange?: () => void;
|
|
46
|
+
oninput?: () => void;
|
|
47
|
+
onsave?: () => void;
|
|
48
|
+
onreceive_null?: () => void;
|
|
49
|
+
ondownload_error?: (error: string) => void;
|
|
50
|
+
};
|
|
51
|
+
declare const InteractiveImageEditor: import("svelte").Component<$$ComponentProps, {
|
|
69
52
|
get_data: () => Promise<ImageBlobs>;
|
|
70
|
-
},
|
|
71
|
-
type InteractiveImageEditor =
|
|
53
|
+
}, "is_dragging" | "full_history" | "image_id">;
|
|
54
|
+
type InteractiveImageEditor = ReturnType<typeof InteractiveImageEditor>;
|
|
72
55
|
export default InteractiveImageEditor;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { spring } from "svelte/motion";
|
|
3
3
|
import { Image } from "@gradio/icons";
|
|
4
|
-
import { onMount
|
|
4
|
+
import { onMount } from "svelte";
|
|
5
5
|
|
|
6
6
|
const positions = [
|
|
7
7
|
"top-left",
|
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
"bottom",
|
|
15
15
|
"bottom-right"
|
|
16
16
|
] as const;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
let {
|
|
18
|
+
onposition
|
|
19
|
+
}: {
|
|
20
|
+
onposition?: (position: (typeof positions)[number]) => void;
|
|
21
|
+
} = $props();
|
|
20
22
|
|
|
21
23
|
const spring_opt = {
|
|
22
24
|
stiffness: 0.1,
|
|
@@ -35,8 +37,8 @@
|
|
|
35
37
|
};
|
|
36
38
|
const arrow_spring = spring<Arrow[]>([], spring_opt);
|
|
37
39
|
|
|
38
|
-
let last_i = 0;
|
|
39
|
-
let expanded = true;
|
|
40
|
+
let last_i = $state(0);
|
|
41
|
+
let expanded = $state(true);
|
|
40
42
|
const box_size = (120 - 5 * 2) / 3;
|
|
41
43
|
|
|
42
44
|
async function handle_box_hover(i: number): Promise<void> {
|
|
@@ -49,7 +51,7 @@
|
|
|
49
51
|
dimensions.set(init);
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
let last_pos = 0;
|
|
54
|
+
let last_pos = $state(0);
|
|
53
55
|
async function handle_box_click(i: number, stagger = false): Promise<void> {
|
|
54
56
|
if (expanded && stagger) return;
|
|
55
57
|
|
|
@@ -77,7 +79,7 @@
|
|
|
77
79
|
dimensions.set([120 + 10, 120 + 10]);
|
|
78
80
|
arrow_spring.set(eventual_arrows);
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
onposition?.(positions[i]);
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
function get_valid_offsets(anchorPoint: {
|
|
@@ -215,14 +217,14 @@
|
|
|
215
217
|
class="box-wrap"
|
|
216
218
|
role="grid"
|
|
217
219
|
tabindex="0"
|
|
218
|
-
|
|
220
|
+
onmouseleave={() => handle_box_click(last_pos, true)}
|
|
219
221
|
>
|
|
220
222
|
{#each { length: 9 } as _, i}
|
|
221
223
|
<button
|
|
222
224
|
class="box"
|
|
223
225
|
class:active-box={last_pos === i}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
+
onmouseenter={() => handle_box_hover(i)}
|
|
227
|
+
onclick={() => handle_box_click(i)}
|
|
226
228
|
>
|
|
227
229
|
<span class:active={last_pos === i} class="icon-wrap">
|
|
228
230
|
<Image />
|
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
(internal: unknown, props: {
|
|
6
|
-
$$events?: Events;
|
|
7
|
-
$$slots?: Slots;
|
|
8
|
-
}): Exports & {
|
|
9
|
-
$set?: any;
|
|
10
|
-
$on?: any;
|
|
11
|
-
};
|
|
12
|
-
z_$$bindings?: Bindings;
|
|
13
|
-
}
|
|
14
|
-
declare const Anchor: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
-
position: CustomEvent<"center" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "top" | "bottom">;
|
|
16
|
-
} & {
|
|
17
|
-
[evt: string]: CustomEvent<any>;
|
|
18
|
-
}, {}, {}, string>;
|
|
19
|
-
type Anchor = InstanceType<typeof Anchor>;
|
|
1
|
+
declare const Anchor: import("svelte").Component<{
|
|
2
|
+
onposition?: (position: "center" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "top" | "bottom") => void;
|
|
3
|
+
}, {}, "">;
|
|
4
|
+
type Anchor = ReturnType<typeof Anchor>;
|
|
20
5
|
export default Anchor;
|