@gradio/imageeditor 0.3.1 → 0.4.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @gradio/imageeditor
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Features
6
+
7
+ - [#7183](https://github.com/gradio-app/gradio/pull/7183) [`49d9c48`](https://github.com/gradio-app/gradio/commit/49d9c48537aa706bf72628e3640389470138bdc6) - [WIP] Refactor file normalization to be in the backend and remove it from the frontend of each component. Thanks [@abidlabs](https://github.com/abidlabs)!
8
+
9
+ ## 0.3.2
10
+
11
+ ### Fixes
12
+
13
+ - [#7219](https://github.com/gradio-app/gradio/pull/7219) [`faead14`](https://github.com/gradio-app/gradio/commit/faead1403cdba6415912a6ad512291ac63b04173) - Show label in interactive image editor. Thanks [@hannahblair](https://github.com/hannahblair)!
14
+
3
15
  ## 0.3.1
4
16
 
5
17
  ### Patch Changes
@@ -151,4 +163,4 @@ Thanks [@pngwn](https://github.com/pngwn)!
151
163
 
152
164
  - [#6502](https://github.com/gradio-app/gradio/pull/6502) [`070f71c93`](https://github.com/gradio-app/gradio/commit/070f71c933d846ce8e2fe11cdd9bc0f3f897f29f) - Ensure image editor crop and draw cursor works as expected when the scroll position changes. Thanks [@pngwn](https://github.com/pngwn)!
153
165
 
154
- # @gradio/image
166
+ # @gradio/image
@@ -1,13 +1,25 @@
1
- <script lang="ts">
2
- import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
1
+ <script context="module">
2
+ import { Template, Story } from "@storybook/addon-svelte-csf";
3
3
  import ImageEditor from "./Index.svelte";
4
4
  import { format } from "svelte-i18n";
5
5
  import { get } from "svelte/store";
6
6
  import { userEvent, within } from "@storybook/testing-library";
7
+ import { allModes } from "../storybook/modes";
8
+
9
+ export const meta = {
10
+ title: "Components/Image Editor",
11
+ component: ImageEditor,
12
+ parameters: {
13
+ chromatic: {
14
+ modes: {
15
+ desktop: allModes["desktop"],
16
+ mobile: allModes["mobile"]
17
+ }
18
+ }
19
+ }
20
+ };
7
21
  </script>
8
22
 
9
- <Meta title="Components/Image Editor" component={ImageEditor} />
10
-
11
23
  <Template let:args>
12
24
  <div
13
25
  class="image-container"
@@ -23,6 +35,8 @@
23
35
  sources: ["webcam", "upload"],
24
36
  type: "pil",
25
37
  interactive: "true",
38
+ label: "Image Editor",
39
+ show_label: true,
26
40
  brush: {
27
41
  default_size: "auto",
28
42
  colors: ["#ff0000", "#00ff00", "#0000ff"],
@@ -36,7 +50,7 @@
36
50
  />
37
51
 
38
52
  <Story
39
- name="Image Editor Interactions"
53
+ name="Image Editor Drawing Interactions"
40
54
  args={{
41
55
  value: {
42
56
  path: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
@@ -182,7 +196,56 @@
182
196
 
183
197
  userEvent.click(canvas.getByLabelText("Add Layer"));
184
198
 
185
- await userEvent.click(canvas.getByLabelText("Image button"));
199
+ await userEvent.click(canvas.getByLabelText("Clear canvas"));
200
+ }}
201
+ />
202
+
203
+ <Story
204
+ name="Image Editor Undo/Redo Interactions"
205
+ args={{
206
+ value: {
207
+ path: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
208
+ url: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
209
+ orig_name: "cheetah.jpg"
210
+ },
211
+ type: "pil",
212
+ sources: ["upload", "webcam"],
213
+ interactive: "true",
214
+ brush: {
215
+ default_size: "auto",
216
+ colors: ["#ff0000", "#00ff00", "#0000ff"],
217
+ default_color: "#ff0000",
218
+ color_mode: "defaults"
219
+ },
220
+ eraser: {
221
+ default_size: "auto"
222
+ }
223
+ }}
224
+ play={async ({ canvasElement }) => {
225
+ const canvas = within(canvasElement);
226
+
227
+ const drawButton = canvas.getAllByLabelText("Draw button")[0];
228
+
229
+ userEvent.click(drawButton);
230
+
231
+ const drawCanvas = document.getElementsByTagName("canvas")[0];
232
+ if (!drawCanvas) {
233
+ throw new Error("Could not find canvas");
234
+ }
235
+
236
+ await new Promise((r) => setTimeout(r, 1000));
237
+
238
+ await userEvent.pointer({
239
+ keys: "[MouseLeft][MouseRight]",
240
+ target: drawCanvas,
241
+ coords: { clientX: 300, clientY: 100 }
242
+ });
243
+
244
+ await userEvent.pointer({
245
+ keys: "[MouseLeft][MouseRight]",
246
+ target: drawCanvas,
247
+ coords: { clientX: 400, clientY: 200 }
248
+ });
186
249
 
187
250
  await userEvent.click(canvas.getByLabelText("Undo"));
188
251
 
package/Index.svelte CHANGED
@@ -13,7 +13,6 @@
13
13
  import { Block } from "@gradio/atoms";
14
14
  import { StatusTracker } from "@gradio/statustracker";
15
15
  import type { LoadingStatus } from "@gradio/statustracker";
16
- import { normalise_file } from "@gradio/client";
17
16
 
18
17
  export let elem_id = "";
19
18
  export let elem_classes: string[] = [];
@@ -42,7 +41,6 @@
42
41
  "clipboard",
43
42
  "webcam"
44
43
  ];
45
- export let proxy_url: string;
46
44
  export let interactive: boolean;
47
45
 
48
46
  export let brush: Brush;
@@ -120,7 +118,7 @@
120
118
  on:select={({ detail }) => gradio.dispatch("select", detail)}
121
119
  on:share={({ detail }) => gradio.dispatch("share", detail)}
122
120
  on:error={({ detail }) => gradio.dispatch("error", detail)}
123
- value={normalise_file(value?.composite || null, root, proxy_url)}
121
+ value={value?.composite || null}
124
122
  {label}
125
123
  {show_label}
126
124
  {show_download_button}
@@ -156,6 +154,8 @@
156
154
  bind:this={editor_instance}
157
155
  {root}
158
156
  {sources}
157
+ {label}
158
+ {show_label}
159
159
  on:save={(e) => handle_save()}
160
160
  on:edit={() => gradio.dispatch("edit")}
161
161
  on:clear={() => gradio.dispatch("clear")}
@@ -172,7 +172,6 @@
172
172
  on:error
173
173
  {brush}
174
174
  {eraser}
175
- {proxy_url}
176
175
  changeable={attached_events.includes("change")}
177
176
  i18n={gradio.i18n}
178
177
  {transforms}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/imageeditor",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
@@ -10,14 +10,14 @@
10
10
  "@types/tinycolor2": "^1.4.6",
11
11
  "pixi.js": "^7.3.2",
12
12
  "tinycolor2": "^1.6.0",
13
- "@gradio/atoms": "^0.5.0",
14
- "@gradio/client": "^0.10.1",
13
+ "@gradio/client": "^0.12.0",
14
+ "@gradio/image": "^0.9.0",
15
15
  "@gradio/icons": "^0.3.2",
16
- "@gradio/image": "^0.7.1",
17
- "@gradio/statustracker": "^0.4.4",
18
- "@gradio/upload": "^0.7.0",
19
- "@gradio/utils": "^0.2.1",
20
- "@gradio/wasm": "^0.5.1"
16
+ "@gradio/atoms": "^0.5.1",
17
+ "@gradio/upload": "^0.7.2",
18
+ "@gradio/utils": "^0.2.2",
19
+ "@gradio/wasm": "^0.6.0",
20
+ "@gradio/statustracker": "^0.4.5"
21
21
  },
22
22
  "main_changeset": true,
23
23
  "main": "./Index.svelte",
@@ -97,8 +97,4 @@
97
97
  gap: var(--spacing-sm);
98
98
  z-index: var(--layer-5);
99
99
  }
100
-
101
- .save :global(svg) {
102
- transform: translateY(1px);
103
- }
104
100
  </style>
@@ -14,12 +14,7 @@
14
14
 
15
15
  <script lang="ts">
16
16
  import { type I18nFormatter } from "@gradio/utils";
17
- import {
18
- prepare_files,
19
- upload,
20
- normalise_file,
21
- type FileData
22
- } from "@gradio/client";
17
+ import { prepare_files, upload, type FileData } from "@gradio/client";
23
18
 
24
19
  import ImageEditor from "./ImageEditor.svelte";
25
20
  import Layers from "./layers/Layers.svelte";
@@ -29,12 +24,15 @@
29
24
  export let brush: IBrush | null;
30
25
  export let eraser: Eraser | null;
31
26
  import { Tools, Crop, Brush, Sources } from "./tools";
27
+ import { BlockLabel } from "@gradio/atoms";
28
+ import { Image as ImageIcon } from "@gradio/icons";
32
29
 
33
30
  export let sources: ("clipboard" | "webcam" | "upload")[];
34
31
  export let crop_size: [number, number] | `${string}:${string}` | null = null;
35
32
  export let i18n: I18nFormatter;
36
33
  export let root: string;
37
- export let proxy_url: string;
34
+ export let label: string | undefined = undefined;
35
+ export let show_label: boolean;
38
36
  export let changeable = false;
39
37
  export let value: EditorData | null = {
40
38
  background: null,
@@ -111,6 +109,11 @@
111
109
  : editor.set_tool("draw"));
112
110
  </script>
113
111
 
112
+ <BlockLabel
113
+ {show_label}
114
+ Icon={ImageIcon}
115
+ label={label || i18n("image.image")}
116
+ />
114
117
  <ImageEditor
115
118
  bind:this={editor}
116
119
  {changeable}
@@ -127,11 +130,7 @@
127
130
  {root}
128
131
  {sources}
129
132
  bind:bg
130
- background_file={normalise_file(
131
- value?.background || null,
132
- root,
133
- proxy_url
134
- )}
133
+ background_file={value?.background || null}
135
134
  ></Sources>
136
135
  {/if}
137
136
  {#if transforms.includes("crop")}
@@ -152,9 +151,7 @@
152
151
  {/if}
153
152
  </Tools>
154
153
 
155
- <Layers
156
- layer_files={normalise_file(value?.layers || null, root, proxy_url)}
157
- />
154
+ <Layers layer_files={value?.layers || null} />
158
155
 
159
156
  {#if !bg && !history}
160
157
  <div class="empty wrap">
@@ -12,7 +12,7 @@
12
12
  import { type I18nFormatter } from "@gradio/utils";
13
13
 
14
14
  import { add_bg_color, add_bg_image } from "./sources";
15
- import type { FileData, normalise_file } from "@gradio/client";
15
+ import type { FileData } from "@gradio/client";
16
16
 
17
17
  export let background_file: FileData | null;
18
18
  export let root: string;