@gradio/image 0.4.2 → 0.5.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 +12 -0
- package/Example.svelte +6 -1
- package/Image.stories.svelte +6 -6
- package/package.json +7 -7
- package/shared/Image.svelte +24 -13
- package/shared/ImagePreview.svelte +15 -11
- package/shared/ImageUploader.svelte +11 -15
- package/shared/Webcam.svelte +7 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# @gradio/image
|
2
2
|
|
3
|
+
## 0.5.0
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
- [#6726](https://github.com/gradio-app/gradio/pull/6726) [`21cfb0a`](https://github.com/gradio-app/gradio/commit/21cfb0acc309bb1a392f4d8a8e42f6be864c5978) - Remove the styles from the Image/Video primitive components and Fix the container styles. Thanks [@whitphx](https://github.com/whitphx)!
|
8
|
+
- [#6398](https://github.com/gradio-app/gradio/pull/6398) [`67ddd40`](https://github.com/gradio-app/gradio/commit/67ddd40b4b70d3a37cb1637c33620f8d197dbee0) - Lite v4. Thanks [@whitphx](https://github.com/whitphx)!
|
9
|
+
- [#6399](https://github.com/gradio-app/gradio/pull/6399) [`053bec9`](https://github.com/gradio-app/gradio/commit/053bec98be1127e083414024e02cf0bebb0b5142) - Improve CSS token documentation in Storybook. Thanks [@hannahblair](https://github.com/hannahblair)!
|
10
|
+
|
11
|
+
### Fixes
|
12
|
+
|
13
|
+
- [#6709](https://github.com/gradio-app/gradio/pull/6709) [`6a9151d`](https://github.com/gradio-app/gradio/commit/6a9151d5c9432c724098da7d88a539aaaf5ffe88) - Remove progress animation on streaming. Thanks [@aliabid94](https://github.com/aliabid94)!
|
14
|
+
|
3
15
|
## 0.4.2
|
4
16
|
|
5
17
|
### Fixes
|
package/Example.svelte
CHANGED
@@ -17,6 +17,11 @@
|
|
17
17
|
</div>
|
18
18
|
|
19
19
|
<style>
|
20
|
+
.container :global(img) {
|
21
|
+
width: 100%;
|
22
|
+
height: 100%;
|
23
|
+
}
|
24
|
+
|
20
25
|
.container.selected {
|
21
26
|
border-color: var(--border-color-accent);
|
22
27
|
}
|
@@ -25,13 +30,13 @@
|
|
25
30
|
margin: 0 auto;
|
26
31
|
border: 2px solid var(--border-color-primary);
|
27
32
|
border-radius: var(--radius-lg);
|
33
|
+
overflow: hidden;
|
28
34
|
width: var(--size-20);
|
29
35
|
height: var(--size-20);
|
30
36
|
object-fit: cover;
|
31
37
|
}
|
32
38
|
|
33
39
|
.container.gallery {
|
34
|
-
border: 2px solid var(--border-color-primary);
|
35
40
|
height: var(--size-20);
|
36
41
|
max-height: var(--size-20);
|
37
42
|
object-fit: cover;
|
package/Image.stories.svelte
CHANGED
@@ -34,9 +34,9 @@
|
|
34
34
|
name="Static Image with label and download button"
|
35
35
|
args={{
|
36
36
|
value: {
|
37
|
-
path: "https://
|
38
|
-
url: "https://
|
39
|
-
orig_name: "
|
37
|
+
path: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
|
38
|
+
url: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
|
39
|
+
orig_name: "cheetah.jpg"
|
40
40
|
},
|
41
41
|
show_label: true,
|
42
42
|
show_download_button: true
|
@@ -47,9 +47,9 @@
|
|
47
47
|
name="Static Image with no label or download button"
|
48
48
|
args={{
|
49
49
|
value: {
|
50
|
-
path: "https://
|
51
|
-
url: "https://
|
52
|
-
orig_name: "
|
50
|
+
path: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
|
51
|
+
url: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
|
52
|
+
orig_name: "cheetah.jpg"
|
53
53
|
},
|
54
54
|
show_label: false,
|
55
55
|
show_download_button: false
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gradio/image",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.0",
|
4
4
|
"description": "Gradio UI packages",
|
5
5
|
"type": "module",
|
6
6
|
"author": "",
|
@@ -10,13 +10,13 @@
|
|
10
10
|
"cropperjs": "^1.5.12",
|
11
11
|
"lazy-brush": "^1.0.1",
|
12
12
|
"resize-observer-polyfill": "^1.5.1",
|
13
|
-
"@gradio/atoms": "^0.
|
14
|
-
"@gradio/client": "^0.
|
15
|
-
"@gradio/icons": "^0.3.
|
16
|
-
"@gradio/
|
17
|
-
"@gradio/
|
13
|
+
"@gradio/atoms": "^0.4.0",
|
14
|
+
"@gradio/client": "^0.9.0",
|
15
|
+
"@gradio/icons": "^0.3.2",
|
16
|
+
"@gradio/upload": "^0.5.3",
|
17
|
+
"@gradio/wasm": "^0.4.0",
|
18
18
|
"@gradio/utils": "^0.2.0",
|
19
|
-
"@gradio/
|
19
|
+
"@gradio/statustracker": "^0.4.2"
|
20
20
|
},
|
21
21
|
"main_changeset": true,
|
22
22
|
"main": "./Index.svelte",
|
package/shared/Image.svelte
CHANGED
@@ -5,19 +5,30 @@
|
|
5
5
|
import { resolve_wasm_src } from "@gradio/wasm/svelte";
|
6
6
|
|
7
7
|
export let src: HTMLImgAttributes["src"] = undefined;
|
8
|
-
</script>
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
let resolved_src: typeof src;
|
10
|
+
|
11
|
+
// The `src` prop can be updated before the Promise from `resolve_wasm_src` is resolved.
|
12
|
+
// In such a case, the resolved value for the old `src` has to be discarded,
|
13
|
+
// This variable `latest_src` is used to pick up only the value resolved for the latest `src` prop.
|
14
|
+
let latest_src: typeof src;
|
15
|
+
$: {
|
16
|
+
// In normal (non-Wasm) Gradio, the `<img>` element should be rendered with the passed `src` props immediately
|
17
|
+
// without waiting for `resolve_wasm_src()` to resolve.
|
18
|
+
// If it waits, a black image is displayed until the async task finishes
|
19
|
+
// and it leads to undesirable flickering.
|
20
|
+
// So set `src` to `resolved_src` here.
|
21
|
+
resolved_src = src;
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
latest_src = src;
|
24
|
+
const resolving_src = src;
|
25
|
+
resolve_wasm_src(resolving_src).then((s) => {
|
26
|
+
if (latest_src === resolving_src) {
|
27
|
+
resolved_src = s;
|
28
|
+
}
|
29
|
+
});
|
22
30
|
}
|
23
|
-
</
|
31
|
+
</script>
|
32
|
+
|
33
|
+
<!-- svelte-ignore a11y-missing-attribute -->
|
34
|
+
<img src={resolved_src} {...$$restProps} />
|
@@ -5,8 +5,10 @@
|
|
5
5
|
import { BlockLabel, Empty, IconButton, ShareButton } from "@gradio/atoms";
|
6
6
|
import { Download } from "@gradio/icons";
|
7
7
|
import { get_coordinates_of_clicked_image } from "./utils";
|
8
|
+
import Image from "./Image.svelte";
|
9
|
+
import { DownloadLink } from "@gradio/wasm/svelte";
|
8
10
|
|
9
|
-
import { Image } from "@gradio/icons";
|
11
|
+
import { Image as ImageIcon } from "@gradio/icons";
|
10
12
|
import { type FileData, normalise_file } from "@gradio/client";
|
11
13
|
import type { I18nFormatter } from "@gradio/utils";
|
12
14
|
|
@@ -31,19 +33,19 @@
|
|
31
33
|
};
|
32
34
|
</script>
|
33
35
|
|
34
|
-
<BlockLabel
|
36
|
+
<BlockLabel
|
37
|
+
{show_label}
|
38
|
+
Icon={ImageIcon}
|
39
|
+
label={label || i18n("image.image")}
|
40
|
+
/>
|
35
41
|
{#if value === null || !value.url}
|
36
|
-
<Empty unpadded_box={true} size="large"><
|
42
|
+
<Empty unpadded_box={true} size="large"><ImageIcon /></Empty>
|
37
43
|
{:else}
|
38
44
|
<div class="icon-buttons">
|
39
45
|
{#if show_download_button}
|
40
|
-
<
|
41
|
-
href={value.url}
|
42
|
-
target={window.__is_colab__ ? "_blank" : null}
|
43
|
-
download={value.orig_name || "image"}
|
44
|
-
>
|
46
|
+
<DownloadLink href={value.url} download={value.orig_name || "image"}>
|
45
47
|
<IconButton Icon={Download} label={i18n("common.download")} />
|
46
|
-
</
|
48
|
+
</DownloadLink>
|
47
49
|
{/if}
|
48
50
|
{#if show_share_button}
|
49
51
|
<ShareButton
|
@@ -60,12 +62,14 @@
|
|
60
62
|
{/if}
|
61
63
|
</div>
|
62
64
|
<button on:click={handle_click}>
|
63
|
-
<
|
65
|
+
<div class:selectable class="image-container">
|
66
|
+
<Image src={value.url} alt="" loading="lazy" />
|
67
|
+
</div>
|
64
68
|
</button>
|
65
69
|
{/if}
|
66
70
|
|
67
71
|
<style>
|
68
|
-
img,
|
72
|
+
.image-container :global(img),
|
69
73
|
button {
|
70
74
|
width: var(--size-full);
|
71
75
|
height: var(--size-full);
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<script lang="ts">
|
2
2
|
import { createEventDispatcher, tick } from "svelte";
|
3
3
|
import { BlockLabel } from "@gradio/atoms";
|
4
|
-
import { Image } from "@gradio/icons";
|
4
|
+
import { Image as ImageIcon } from "@gradio/icons";
|
5
5
|
import type { SelectData, I18nFormatter } from "@gradio/utils";
|
6
6
|
import { get_coordinates_of_clicked_image } from "./utils";
|
7
7
|
import {
|
@@ -15,6 +15,7 @@
|
|
15
15
|
import { Upload } from "@gradio/upload";
|
16
16
|
import { type FileData, normalise_file } from "@gradio/client";
|
17
17
|
import ClearImage from "./ClearImage.svelte";
|
18
|
+
import Image from "./Image.svelte";
|
18
19
|
|
19
20
|
export let value: null | FileData;
|
20
21
|
export let label: string | undefined = undefined;
|
@@ -54,7 +55,8 @@
|
|
54
55
|
pending = false;
|
55
56
|
}
|
56
57
|
|
57
|
-
$:
|
58
|
+
$: active_streaming = streaming && active_tool === "webcam";
|
59
|
+
$: if (uploading && !active_streaming) value = null;
|
58
60
|
|
59
61
|
$: value && !value.url && (value = normalise_file(value, root, null));
|
60
62
|
|
@@ -140,10 +142,10 @@
|
|
140
142
|
}
|
141
143
|
</script>
|
142
144
|
|
143
|
-
<BlockLabel {show_label} Icon={
|
145
|
+
<BlockLabel {show_label} Icon={ImageIcon} label={label || "Image"} />
|
144
146
|
|
145
147
|
<div data-testid="image" class="image-container">
|
146
|
-
{#if value?.url}
|
148
|
+
{#if value?.url && !active_streaming}
|
147
149
|
<ClearImage
|
148
150
|
on:remove_image={() => {
|
149
151
|
value = null;
|
@@ -182,13 +184,10 @@
|
|
182
184
|
/>
|
183
185
|
{:else if value !== null && !streaming}
|
184
186
|
<!-- svelte-ignore a11y-click-events-have-key-events-->
|
185
|
-
<!-- svelte-ignore a11y-no-
|
186
|
-
<
|
187
|
-
src={value.url}
|
188
|
-
|
189
|
-
on:click={handle_click}
|
190
|
-
class:selectable
|
191
|
-
/>
|
187
|
+
<!-- svelte-ignore a11y-no-static-element-interactions-->
|
188
|
+
<div class:selectable class="image-frame" on:click={handle_click}>
|
189
|
+
<Image src={value.url} alt={value.alt_text} />
|
190
|
+
</div>
|
192
191
|
{/if}
|
193
192
|
</div>
|
194
193
|
{#if sources.length > 1 || sources.includes("clipboard")}
|
@@ -207,10 +206,7 @@
|
|
207
206
|
</div>
|
208
207
|
|
209
208
|
<style>
|
210
|
-
|
211
|
-
height: auto;
|
212
|
-
} */
|
213
|
-
img {
|
209
|
+
.image-frame :global(img) {
|
214
210
|
width: var(--size-full);
|
215
211
|
height: var(--size-full);
|
216
212
|
}
|
package/shared/Webcam.svelte
CHANGED
@@ -189,11 +189,11 @@
|
|
189
189
|
>
|
190
190
|
{#if mode === "video"}
|
191
191
|
{#if recording}
|
192
|
-
<div class="icon" title="stop recording">
|
192
|
+
<div class="icon red" title="stop recording">
|
193
193
|
<Square />
|
194
194
|
</div>
|
195
195
|
{:else}
|
196
|
-
<div class="icon" title="start recording">
|
196
|
+
<div class="icon red" title="start recording">
|
197
197
|
<Circle />
|
198
198
|
</div>
|
199
199
|
{/if}
|
@@ -297,6 +297,11 @@
|
|
297
297
|
align-items: center;
|
298
298
|
}
|
299
299
|
|
300
|
+
.red {
|
301
|
+
fill: red;
|
302
|
+
stroke: red;
|
303
|
+
}
|
304
|
+
|
300
305
|
.flip {
|
301
306
|
transform: scaleX(-1);
|
302
307
|
}
|