@gradio/image 0.27.0 → 0.28.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 +14 -0
- package/Example.svelte +9 -3
- package/Index.svelte +26 -49
- package/dist/Example.svelte +9 -3
- package/dist/Example.svelte.d.ts +4 -18
- package/dist/Index.svelte +26 -49
- package/dist/shared/Image.svelte +21 -4
- package/dist/shared/Image.svelte.d.ts +4 -19
- package/dist/shared/ImagePreview.svelte +39 -23
- package/dist/shared/ImagePreview.svelte.d.ts +10 -26
- package/dist/shared/ImageUploader.svelte +97 -63
- package/dist/shared/ImageUploader.svelte.d.ts +19 -42
- package/dist/shared/Webcam.svelte +63 -47
- package/dist/shared/Webcam.svelte.d.ts +11 -27
- package/dist/shared/WebcamPermissions.svelte +2 -5
- package/dist/shared/WebcamPermissions.svelte.d.ts +5 -19
- package/package.json +7 -7
- package/shared/Image.svelte +21 -4
- package/shared/ImagePreview.svelte +39 -23
- package/shared/ImageUploader.svelte +97 -63
- package/shared/Webcam.svelte +63 -47
- package/shared/WebcamPermissions.svelte +2 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @gradio/image
|
|
2
2
|
|
|
3
|
+
## 0.28.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#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!
|
|
8
|
+
|
|
9
|
+
### Dependency updates
|
|
10
|
+
|
|
11
|
+
- @gradio/statustracker@0.15.1
|
|
12
|
+
- @gradio/icons@0.16.0
|
|
13
|
+
- @gradio/atoms@0.26.0
|
|
14
|
+
- @gradio/client@2.3.1
|
|
15
|
+
- @gradio/upload@0.18.1
|
|
16
|
+
|
|
3
17
|
## 0.27.0
|
|
4
18
|
|
|
5
19
|
### Features
|
package/Example.svelte
CHANGED
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
import Image from "./shared/Image.svelte";
|
|
3
3
|
import type { FileData } from "@gradio/client";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let {
|
|
6
|
+
value,
|
|
7
|
+
type,
|
|
8
|
+
selected = false
|
|
9
|
+
}: {
|
|
10
|
+
value: null | FileData;
|
|
11
|
+
type: "gallery" | "table";
|
|
12
|
+
selected?: boolean;
|
|
13
|
+
} = $props();
|
|
8
14
|
</script>
|
|
9
15
|
|
|
10
16
|
<div
|
package/Index.svelte
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import type { ImageProps, ImageEvents } from "./shared/types";
|
|
20
20
|
|
|
21
21
|
let stream_data = { value: null };
|
|
22
|
-
let upload_promise = $state<Promise<any
|
|
22
|
+
let upload_promise = $state<Promise<any> | null>(null);
|
|
23
23
|
class ImageGradio extends Gradio<ImageEvents, ImageProps> {
|
|
24
24
|
async get_data() {
|
|
25
25
|
if (upload_promise) {
|
|
@@ -37,50 +37,34 @@
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const props = $props();
|
|
40
|
-
const gradio = new ImageGradio(props);
|
|
40
|
+
const gradio = new ImageGradio(props, { value: null });
|
|
41
41
|
|
|
42
|
+
let value = $state(gradio.props.value ?? null);
|
|
42
43
|
let fullscreen = $state(false);
|
|
43
44
|
let dragging = $state(false);
|
|
44
45
|
let active_source = $derived.by(() =>
|
|
45
46
|
gradio.props.sources ? gradio.props.sources[0] : null
|
|
46
47
|
);
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
drag_event.preventDefault();
|
|
52
|
-
drag_event.stopPropagation();
|
|
53
|
-
if (drag_event.type === "dragenter" || drag_event.type === "dragover") {
|
|
54
|
-
dragging = true;
|
|
55
|
-
} else if (drag_event.type === "dragleave") {
|
|
56
|
-
dragging = false;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const handle_drop = (event: Event): void => {
|
|
61
|
-
if (gradio.shared.interactive) {
|
|
62
|
-
const drop_event = event as DragEvent;
|
|
63
|
-
drop_event.preventDefault();
|
|
64
|
-
drop_event.stopPropagation();
|
|
65
|
-
dragging = false;
|
|
49
|
+
$effect(() => {
|
|
50
|
+
value = gradio.props.value ?? null;
|
|
51
|
+
});
|
|
66
52
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
};
|
|
53
|
+
$effect(() => {
|
|
54
|
+
gradio.props.value = value;
|
|
55
|
+
});
|
|
72
56
|
|
|
73
|
-
let old_value =
|
|
57
|
+
let old_value = value;
|
|
74
58
|
let mounted = false;
|
|
75
59
|
|
|
76
60
|
$effect(() => {
|
|
77
61
|
if (!mounted) {
|
|
78
|
-
old_value =
|
|
62
|
+
old_value = value;
|
|
79
63
|
mounted = true;
|
|
80
64
|
return;
|
|
81
65
|
}
|
|
82
|
-
if (old_value !==
|
|
83
|
-
old_value =
|
|
66
|
+
if (old_value !== value) {
|
|
67
|
+
old_value = value;
|
|
84
68
|
gradio.dispatch("change");
|
|
85
69
|
}
|
|
86
70
|
});
|
|
@@ -112,14 +96,14 @@
|
|
|
112
96
|
gradio.dispatch("clear_status", gradio.shared.loading_status)}
|
|
113
97
|
/>
|
|
114
98
|
<StaticImage
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
99
|
+
onselect={(detail) => gradio.dispatch("select", detail)}
|
|
100
|
+
onshare={(detail) => gradio.dispatch("share", detail)}
|
|
101
|
+
onerror={(detail) => gradio.dispatch("error", detail)}
|
|
102
|
+
onfullscreen={(detail) => {
|
|
119
103
|
fullscreen = detail;
|
|
120
104
|
}}
|
|
121
105
|
{fullscreen}
|
|
122
|
-
|
|
106
|
+
{value}
|
|
123
107
|
label={gradio.shared.label}
|
|
124
108
|
show_label={gradio.shared.show_label}
|
|
125
109
|
selectable={gradio.props._selectable}
|
|
@@ -145,10 +129,6 @@
|
|
|
145
129
|
scale={gradio.shared.scale}
|
|
146
130
|
min_width={gradio.shared.min_width}
|
|
147
131
|
bind:fullscreen
|
|
148
|
-
on:dragenter={handle_drag_event}
|
|
149
|
-
on:dragleave={handle_drag_event}
|
|
150
|
-
on:dragover={handle_drag_event}
|
|
151
|
-
on:drop={handle_drop}
|
|
152
132
|
>
|
|
153
133
|
{#if gradio.shared.loading_status.type === "output" || gradio.shared.loading_status.validation_error}
|
|
154
134
|
<StatusTracker
|
|
@@ -161,9 +141,8 @@
|
|
|
161
141
|
{/if}
|
|
162
142
|
<ImageUploader
|
|
163
143
|
bind:upload_promise
|
|
164
|
-
bind:this={upload_component}
|
|
165
144
|
bind:active_source
|
|
166
|
-
bind:value
|
|
145
|
+
bind:value
|
|
167
146
|
bind:dragging
|
|
168
147
|
selectable={gradio.props._selectable}
|
|
169
148
|
root={gradio.shared.root}
|
|
@@ -174,31 +153,29 @@
|
|
|
174
153
|
: gradio.props.buttons.some(
|
|
175
154
|
(btn) => typeof btn === "string" && btn === "fullscreen"
|
|
176
155
|
)}
|
|
177
|
-
|
|
178
|
-
on:clear={() => {
|
|
156
|
+
onclear={() => {
|
|
179
157
|
fullscreen = false;
|
|
180
158
|
gradio.dispatch("clear");
|
|
181
159
|
gradio.dispatch("input");
|
|
182
160
|
}}
|
|
183
|
-
|
|
161
|
+
onstream={(detail) => {
|
|
184
162
|
stream_data = detail;
|
|
185
163
|
gradio.dispatch("stream", detail);
|
|
186
164
|
}}
|
|
187
|
-
|
|
188
|
-
|
|
165
|
+
ondrag={(detail) => (dragging = detail)}
|
|
166
|
+
onupload={() => {
|
|
189
167
|
gradio.dispatch("upload");
|
|
190
168
|
gradio.dispatch("input");
|
|
191
169
|
}}
|
|
192
|
-
|
|
193
|
-
on:share={({ detail }) => gradio.dispatch("share", detail)}
|
|
170
|
+
onselect={(detail) => gradio.dispatch("select", detail)}
|
|
194
171
|
onerror={(detail) => {
|
|
195
172
|
gradio.shared.loading_status.status = "error";
|
|
196
173
|
gradio.dispatch("error", detail);
|
|
197
174
|
}}
|
|
198
|
-
|
|
175
|
+
onclose_stream={() => {
|
|
199
176
|
gradio.dispatch("close_stream");
|
|
200
177
|
}}
|
|
201
|
-
|
|
178
|
+
onfullscreen={(detail) => {
|
|
202
179
|
fullscreen = detail;
|
|
203
180
|
}}
|
|
204
181
|
label={gradio.shared.label}
|
package/dist/Example.svelte
CHANGED
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
import Image from "./shared/Image.svelte";
|
|
3
3
|
import type { FileData } from "@gradio/client";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let {
|
|
6
|
+
value,
|
|
7
|
+
type,
|
|
8
|
+
selected = false
|
|
9
|
+
}: {
|
|
10
|
+
value: null | FileData;
|
|
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 { FileData } from "@gradio/client";
|
|
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: null | FileData;
|
|
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
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import type { ImageProps, ImageEvents } from "./shared/types";
|
|
20
20
|
|
|
21
21
|
let stream_data = { value: null };
|
|
22
|
-
let upload_promise = $state<Promise<any
|
|
22
|
+
let upload_promise = $state<Promise<any> | null>(null);
|
|
23
23
|
class ImageGradio extends Gradio<ImageEvents, ImageProps> {
|
|
24
24
|
async get_data() {
|
|
25
25
|
if (upload_promise) {
|
|
@@ -37,50 +37,34 @@
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const props = $props();
|
|
40
|
-
const gradio = new ImageGradio(props);
|
|
40
|
+
const gradio = new ImageGradio(props, { value: null });
|
|
41
41
|
|
|
42
|
+
let value = $state(gradio.props.value ?? null);
|
|
42
43
|
let fullscreen = $state(false);
|
|
43
44
|
let dragging = $state(false);
|
|
44
45
|
let active_source = $derived.by(() =>
|
|
45
46
|
gradio.props.sources ? gradio.props.sources[0] : null
|
|
46
47
|
);
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
drag_event.preventDefault();
|
|
52
|
-
drag_event.stopPropagation();
|
|
53
|
-
if (drag_event.type === "dragenter" || drag_event.type === "dragover") {
|
|
54
|
-
dragging = true;
|
|
55
|
-
} else if (drag_event.type === "dragleave") {
|
|
56
|
-
dragging = false;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const handle_drop = (event: Event): void => {
|
|
61
|
-
if (gradio.shared.interactive) {
|
|
62
|
-
const drop_event = event as DragEvent;
|
|
63
|
-
drop_event.preventDefault();
|
|
64
|
-
drop_event.stopPropagation();
|
|
65
|
-
dragging = false;
|
|
49
|
+
$effect(() => {
|
|
50
|
+
value = gradio.props.value ?? null;
|
|
51
|
+
});
|
|
66
52
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
};
|
|
53
|
+
$effect(() => {
|
|
54
|
+
gradio.props.value = value;
|
|
55
|
+
});
|
|
72
56
|
|
|
73
|
-
let old_value =
|
|
57
|
+
let old_value = value;
|
|
74
58
|
let mounted = false;
|
|
75
59
|
|
|
76
60
|
$effect(() => {
|
|
77
61
|
if (!mounted) {
|
|
78
|
-
old_value =
|
|
62
|
+
old_value = value;
|
|
79
63
|
mounted = true;
|
|
80
64
|
return;
|
|
81
65
|
}
|
|
82
|
-
if (old_value !==
|
|
83
|
-
old_value =
|
|
66
|
+
if (old_value !== value) {
|
|
67
|
+
old_value = value;
|
|
84
68
|
gradio.dispatch("change");
|
|
85
69
|
}
|
|
86
70
|
});
|
|
@@ -112,14 +96,14 @@
|
|
|
112
96
|
gradio.dispatch("clear_status", gradio.shared.loading_status)}
|
|
113
97
|
/>
|
|
114
98
|
<StaticImage
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
99
|
+
onselect={(detail) => gradio.dispatch("select", detail)}
|
|
100
|
+
onshare={(detail) => gradio.dispatch("share", detail)}
|
|
101
|
+
onerror={(detail) => gradio.dispatch("error", detail)}
|
|
102
|
+
onfullscreen={(detail) => {
|
|
119
103
|
fullscreen = detail;
|
|
120
104
|
}}
|
|
121
105
|
{fullscreen}
|
|
122
|
-
|
|
106
|
+
{value}
|
|
123
107
|
label={gradio.shared.label}
|
|
124
108
|
show_label={gradio.shared.show_label}
|
|
125
109
|
selectable={gradio.props._selectable}
|
|
@@ -145,10 +129,6 @@
|
|
|
145
129
|
scale={gradio.shared.scale}
|
|
146
130
|
min_width={gradio.shared.min_width}
|
|
147
131
|
bind:fullscreen
|
|
148
|
-
on:dragenter={handle_drag_event}
|
|
149
|
-
on:dragleave={handle_drag_event}
|
|
150
|
-
on:dragover={handle_drag_event}
|
|
151
|
-
on:drop={handle_drop}
|
|
152
132
|
>
|
|
153
133
|
{#if gradio.shared.loading_status.type === "output" || gradio.shared.loading_status.validation_error}
|
|
154
134
|
<StatusTracker
|
|
@@ -161,9 +141,8 @@
|
|
|
161
141
|
{/if}
|
|
162
142
|
<ImageUploader
|
|
163
143
|
bind:upload_promise
|
|
164
|
-
bind:this={upload_component}
|
|
165
144
|
bind:active_source
|
|
166
|
-
bind:value
|
|
145
|
+
bind:value
|
|
167
146
|
bind:dragging
|
|
168
147
|
selectable={gradio.props._selectable}
|
|
169
148
|
root={gradio.shared.root}
|
|
@@ -174,31 +153,29 @@
|
|
|
174
153
|
: gradio.props.buttons.some(
|
|
175
154
|
(btn) => typeof btn === "string" && btn === "fullscreen"
|
|
176
155
|
)}
|
|
177
|
-
|
|
178
|
-
on:clear={() => {
|
|
156
|
+
onclear={() => {
|
|
179
157
|
fullscreen = false;
|
|
180
158
|
gradio.dispatch("clear");
|
|
181
159
|
gradio.dispatch("input");
|
|
182
160
|
}}
|
|
183
|
-
|
|
161
|
+
onstream={(detail) => {
|
|
184
162
|
stream_data = detail;
|
|
185
163
|
gradio.dispatch("stream", detail);
|
|
186
164
|
}}
|
|
187
|
-
|
|
188
|
-
|
|
165
|
+
ondrag={(detail) => (dragging = detail)}
|
|
166
|
+
onupload={() => {
|
|
189
167
|
gradio.dispatch("upload");
|
|
190
168
|
gradio.dispatch("input");
|
|
191
169
|
}}
|
|
192
|
-
|
|
193
|
-
on:share={({ detail }) => gradio.dispatch("share", detail)}
|
|
170
|
+
onselect={(detail) => gradio.dispatch("select", detail)}
|
|
194
171
|
onerror={(detail) => {
|
|
195
172
|
gradio.shared.loading_status.status = "error";
|
|
196
173
|
gradio.dispatch("error", detail);
|
|
197
174
|
}}
|
|
198
|
-
|
|
175
|
+
onclose_stream={() => {
|
|
199
176
|
gradio.dispatch("close_stream");
|
|
200
177
|
}}
|
|
201
|
-
|
|
178
|
+
onfullscreen={(detail) => {
|
|
202
179
|
fullscreen = detail;
|
|
203
180
|
}}
|
|
204
181
|
label={gradio.shared.label}
|
package/dist/shared/Image.svelte
CHANGED
|
@@ -1,27 +1,44 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import type { HTMLImgAttributes } from "svelte/elements";
|
|
3
|
+
|
|
2
4
|
let {
|
|
3
5
|
src = "",
|
|
4
6
|
restProps = {},
|
|
5
7
|
data_testid,
|
|
6
8
|
class_names = [],
|
|
9
|
+
onload,
|
|
7
10
|
...imgProps
|
|
8
11
|
}: {
|
|
9
12
|
src?: string;
|
|
10
13
|
restProps?: Record<string, any>;
|
|
11
14
|
data_testid?: string;
|
|
12
15
|
class_names?: string[];
|
|
16
|
+
onload?: HTMLImgAttributes["onload"];
|
|
13
17
|
[key: string]: any;
|
|
14
18
|
} = $props();
|
|
19
|
+
|
|
20
|
+
const without_class = ({
|
|
21
|
+
class: _class,
|
|
22
|
+
...props
|
|
23
|
+
}: Record<string, any>): Record<string, any> => props;
|
|
24
|
+
|
|
25
|
+
let rest_img_props = $derived(without_class(restProps));
|
|
26
|
+
let direct_img_props = $derived(without_class(imgProps));
|
|
27
|
+
let classes = $derived(
|
|
28
|
+
[class_names.join(" "), restProps.class, imgProps.class]
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.join(" ")
|
|
31
|
+
);
|
|
15
32
|
</script>
|
|
16
33
|
|
|
17
34
|
<!-- svelte-ignore a11y-missing-attribute -->
|
|
18
35
|
<img
|
|
19
36
|
{src}
|
|
20
|
-
class={
|
|
37
|
+
class={classes}
|
|
21
38
|
data-testid={data_testid}
|
|
22
|
-
{...
|
|
23
|
-
{...
|
|
24
|
-
|
|
39
|
+
{...rest_img_props}
|
|
40
|
+
{...direct_img_props}
|
|
41
|
+
{onload}
|
|
25
42
|
/>
|
|
26
43
|
|
|
27
44
|
<style>
|
|
@@ -1,27 +1,12 @@
|
|
|
1
|
+
import type { HTMLImgAttributes } from "svelte/elements";
|
|
1
2
|
type $$ComponentProps = {
|
|
2
3
|
src?: string;
|
|
3
4
|
restProps?: Record<string, any>;
|
|
4
5
|
data_testid?: string;
|
|
5
6
|
class_names?: string[];
|
|
7
|
+
onload?: HTMLImgAttributes["onload"];
|
|
6
8
|
[key: string]: any;
|
|
7
9
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
$$bindings?: Bindings;
|
|
11
|
-
} & Exports;
|
|
12
|
-
(internal: unknown, props: Props & {
|
|
13
|
-
$$events?: Events;
|
|
14
|
-
$$slots?: Slots;
|
|
15
|
-
}): Exports & {
|
|
16
|
-
$set?: any;
|
|
17
|
-
$on?: any;
|
|
18
|
-
};
|
|
19
|
-
z_$$bindings?: Bindings;
|
|
20
|
-
}
|
|
21
|
-
declare const Image: $$__sveltets_2_IsomorphicComponent<$$ComponentProps, {
|
|
22
|
-
load: Event;
|
|
23
|
-
} & {
|
|
24
|
-
[evt: string]: CustomEvent<any>;
|
|
25
|
-
}, {}, {}, "">;
|
|
26
|
-
type Image = InstanceType<typeof Image>;
|
|
10
|
+
declare const Image: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
11
|
+
type Image = ReturnType<typeof Image>;
|
|
27
12
|
export default Image;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { createEventDispatcher, onMount } from "svelte";
|
|
3
2
|
import type { SelectData } from "@gradio/utils";
|
|
4
3
|
import { uploadToHuggingFace } from "@gradio/utils";
|
|
5
4
|
import {
|
|
@@ -19,27 +18,44 @@
|
|
|
19
18
|
import type { I18nFormatter } from "@gradio/utils";
|
|
20
19
|
import type { FileData } from "@gradio/client";
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
let {
|
|
22
|
+
value,
|
|
23
|
+
label = undefined,
|
|
24
|
+
show_label,
|
|
25
|
+
buttons = [],
|
|
26
|
+
on_custom_button_click = null,
|
|
27
|
+
selectable = false,
|
|
28
|
+
i18n,
|
|
29
|
+
display_icon_button_wrapper_top_corner = false,
|
|
30
|
+
fullscreen = $bindable(false),
|
|
31
|
+
show_button_background = true,
|
|
32
|
+
onselect,
|
|
33
|
+
onfullscreen,
|
|
34
|
+
onshare,
|
|
35
|
+
onerror,
|
|
36
|
+
onload
|
|
37
|
+
}: {
|
|
38
|
+
value: null | FileData;
|
|
39
|
+
label?: string;
|
|
40
|
+
show_label: boolean;
|
|
41
|
+
buttons?: (string | CustomButtonType)[];
|
|
42
|
+
on_custom_button_click?: ((id: number) => void) | null;
|
|
43
|
+
selectable?: boolean;
|
|
44
|
+
i18n: I18nFormatter;
|
|
45
|
+
display_icon_button_wrapper_top_corner?: boolean;
|
|
46
|
+
fullscreen?: boolean;
|
|
47
|
+
show_button_background?: boolean;
|
|
48
|
+
onselect?: (value: SelectData) => void;
|
|
49
|
+
onfullscreen?: (fullscreen: boolean) => void;
|
|
50
|
+
onshare?: (detail: unknown) => void;
|
|
51
|
+
onerror?: (error: string) => void;
|
|
52
|
+
onload?: () => void;
|
|
53
|
+
} = $props();
|
|
38
54
|
|
|
39
55
|
const handle_click = (evt: MouseEvent): void => {
|
|
40
56
|
let coordinates = get_coordinates_of_clicked_image(evt);
|
|
41
57
|
if (coordinates) {
|
|
42
|
-
|
|
58
|
+
onselect?.({ index: coordinates, value: null });
|
|
43
59
|
}
|
|
44
60
|
};
|
|
45
61
|
|
|
@@ -66,7 +82,7 @@
|
|
|
66
82
|
{fullscreen}
|
|
67
83
|
onclick={(is_fullscreen) => {
|
|
68
84
|
fullscreen = is_fullscreen;
|
|
69
|
-
|
|
85
|
+
onfullscreen?.(is_fullscreen);
|
|
70
86
|
}}
|
|
71
87
|
/>
|
|
72
88
|
{/if}
|
|
@@ -78,8 +94,8 @@
|
|
|
78
94
|
{#if buttons.some((btn) => typeof btn === "string" && btn === "share")}
|
|
79
95
|
<ShareButton
|
|
80
96
|
{i18n}
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
onshare={(detail) => onshare?.(detail)}
|
|
98
|
+
onerror={(detail) => onerror?.(detail)}
|
|
83
99
|
formatter={async (value) => {
|
|
84
100
|
if (!value) return "";
|
|
85
101
|
let url = await uploadToHuggingFace(value, "url");
|
|
@@ -89,12 +105,12 @@
|
|
|
89
105
|
/>
|
|
90
106
|
{/if}
|
|
91
107
|
</IconButtonWrapper>
|
|
92
|
-
<button
|
|
108
|
+
<button onclick={handle_click}>
|
|
93
109
|
<div class:selectable class="image-frame">
|
|
94
110
|
<Image
|
|
95
111
|
src={value.url}
|
|
96
112
|
restProps={{ loading: "lazy", alt: "" }}
|
|
97
|
-
|
|
113
|
+
{onload}
|
|
98
114
|
/>
|
|
99
115
|
</div>
|
|
100
116
|
</button>
|
|
@@ -2,22 +2,9 @@ import type { SelectData } from "@gradio/utils";
|
|
|
2
2
|
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
|
3
3
|
import type { I18nFormatter } from "@gradio/utils";
|
|
4
4
|
import type { FileData } from "@gradio/client";
|
|
5
|
-
|
|
6
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
7
|
-
$$bindings?: Bindings;
|
|
8
|
-
} & Exports;
|
|
9
|
-
(internal: unknown, props: Props & {
|
|
10
|
-
$$events?: Events;
|
|
11
|
-
$$slots?: Slots;
|
|
12
|
-
}): Exports & {
|
|
13
|
-
$set?: any;
|
|
14
|
-
$on?: any;
|
|
15
|
-
};
|
|
16
|
-
z_$$bindings?: Bindings;
|
|
17
|
-
}
|
|
18
|
-
declare const ImagePreview: $$__sveltets_2_IsomorphicComponent<{
|
|
5
|
+
type $$ComponentProps = {
|
|
19
6
|
value: null | FileData;
|
|
20
|
-
label?: string
|
|
7
|
+
label?: string;
|
|
21
8
|
show_label: boolean;
|
|
22
9
|
buttons?: (string | CustomButtonType)[];
|
|
23
10
|
on_custom_button_click?: ((id: number) => void) | null;
|
|
@@ -26,15 +13,12 @@ declare const ImagePreview: $$__sveltets_2_IsomorphicComponent<{
|
|
|
26
13
|
display_icon_button_wrapper_top_corner?: boolean;
|
|
27
14
|
fullscreen?: boolean;
|
|
28
15
|
show_button_background?: boolean;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
[evt: string]: CustomEvent<any>;
|
|
38
|
-
}, {}, {}, string>;
|
|
39
|
-
type ImagePreview = InstanceType<typeof ImagePreview>;
|
|
16
|
+
onselect?: (value: SelectData) => void;
|
|
17
|
+
onfullscreen?: (fullscreen: boolean) => void;
|
|
18
|
+
onshare?: (detail: unknown) => void;
|
|
19
|
+
onerror?: (error: string) => void;
|
|
20
|
+
onload?: () => void;
|
|
21
|
+
};
|
|
22
|
+
declare const ImagePreview: import("svelte").Component<$$ComponentProps, {}, "fullscreen">;
|
|
23
|
+
type ImagePreview = ReturnType<typeof ImagePreview>;
|
|
40
24
|
export default ImagePreview;
|