@gradio/imageeditor 0.12.3 → 0.12.5

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,20 @@
1
1
  # @gradio/imageeditor
2
2
 
3
+ ## 0.12.5
4
+
5
+ ### Dependency updates
6
+
7
+ - @gradio/upload@0.14.7
8
+ - @gradio/image@0.20.3
9
+ - @gradio/wasm@0.17.1
10
+
11
+ ## 0.12.4
12
+
13
+ ### Features
14
+
15
+ - [#10370](https://github.com/gradio-app/gradio/pull/10370) [`71c8b8a`](https://github.com/gradio-app/gradio/commit/71c8b8abbfae0e47eb46561b0104bd452e5dffe8) - Clear Image Editor Value with None. Thanks @freddyaboulton!
16
+ - [#10416](https://github.com/gradio-app/gradio/pull/10416) [`3c2e12b`](https://github.com/gradio-app/gradio/commit/3c2e12b5ba52441f45565ae8e14cea46ea5b5b2c) - Fix ImageEditor Cropping - Cropping now crops the background image instead of the image + canvas. Thanks @freddyaboulton!
17
+
3
18
  ## 0.12.3
4
19
 
5
20
  ### Fixes
package/Index.svelte CHANGED
@@ -225,6 +225,12 @@
225
225
  loading_status.status = "error";
226
226
  gradio.dispatch("error", detail);
227
227
  }}
228
+ on:receive_null={() =>
229
+ (value = {
230
+ background: null,
231
+ layers: [],
232
+ composite: null
233
+ })}
228
234
  on:error
229
235
  {brush}
230
236
  {eraser}
package/dist/Index.svelte CHANGED
@@ -177,6 +177,12 @@ $:
177
177
  loading_status.status = "error";
178
178
  gradio.dispatch("error", detail);
179
179
  }}
180
+ on:receive_null={() =>
181
+ (value = {
182
+ background: null,
183
+ layers: [],
184
+ composite: null
185
+ })}
180
186
  on:error
181
187
  {brush}
182
188
  {eraser}
@@ -46,7 +46,7 @@ export let canvas_height = void 0;
46
46
  $:
47
47
  height = $editor_box.child_height;
48
48
  $:
49
- canvas_height = $crop[3] * $editor_box.child_height + 1;
49
+ canvas_height = $editor_box.child_height + 1;
50
50
  const crop = writable([0, 0, 1, 1]);
51
51
  const position_spring = spring(
52
52
  { x: 0, y: 0 },
@@ -171,10 +171,10 @@ function reposition_canvas() {
171
171
  if (!$editor_box)
172
172
  return;
173
173
  const [l, t, w, h] = $crop;
174
- const cx = l * $editor_box.child_width;
175
- const cy = t * $editor_box.child_height;
176
- const cw = w * $editor_box.child_width;
177
- const ch = h * $editor_box.child_height;
174
+ const cx = 0;
175
+ const cy = 0;
176
+ const cw = $editor_box.child_width;
177
+ const ch = $editor_box.child_height;
178
178
  const x = 0.5 * $editor_box.child_width - cx - cw / 2;
179
179
  const y = 0.5 * $editor_box.child_height - cy - ch / 2;
180
180
  position_spring.set({ x, y });
@@ -186,10 +186,10 @@ export async function get_blobs() {
186
186
  return $pixi?.get_blobs(
187
187
  $pixi.get_layers(),
188
188
  new Rectangle(
189
- Math.round(l * $dimensions[0]),
190
- Math.round(t * $dimensions[1]),
191
- Math.round(w * $dimensions[0]),
192
- Math.round(h * $dimensions[1])
189
+ Math.round(0),
190
+ Math.round(0),
191
+ Math.round(1 * $dimensions[0]),
192
+ Math.round(1 * $dimensions[1])
193
193
  ),
194
194
  $dimensions
195
195
  );
@@ -285,14 +285,10 @@ export function set_tool(tool) {
285
285
  <div
286
286
  class="canvas"
287
287
  class:no-border={!bg && $active_tool === "bg" && !history}
288
- style:width="{$crop[2] * $editor_box.child_width + 1}px"
289
- style:height="{$crop[3] * $editor_box.child_height + 1}px"
290
- style:top="{$crop[1] * $editor_box.child_height +
291
- ($editor_box.child_top - $editor_box.parent_top) -
292
- 0.5}px"
293
- style:left="{$crop[0] * $editor_box.child_width +
294
- ($editor_box.child_left - $editor_box.parent_left) -
295
- 0.5}px"
288
+ style:width="{$editor_box.child_width + 1}px"
289
+ style:height="{$editor_box.child_height + 1}px"
290
+ style:top="{$editor_box.child_top - $editor_box.parent_top - 0.5}px"
291
+ style:left="{$editor_box.child_left - $editor_box.parent_left - 0.5}px"
296
292
  ></div>
297
293
  </div>
298
294
  </div>
@@ -52,7 +52,12 @@ $:
52
52
  if (bg)
53
53
  dispatch("upload");
54
54
  export async function get_data() {
55
- const blobs = await editor.get_blobs();
55
+ let blobs;
56
+ try {
57
+ blobs = await editor.get_blobs();
58
+ } catch (e) {
59
+ return { background: null, layers: [], composite: null };
60
+ }
56
61
  const bg2 = blobs.background ? upload(
57
62
  await prepare_files([new File([blobs.background], "background.png")]),
58
63
  root
@@ -80,6 +85,7 @@ function handle_value(value2) {
80
85
  return;
81
86
  if (value2 == null) {
82
87
  editor.handle_remove();
88
+ dispatch("receive_null");
83
89
  }
84
90
  }
85
91
  $:
@@ -49,6 +49,7 @@ declare const __propDef: {
49
49
  clear?: CustomEvent<undefined> | undefined;
50
50
  upload?: CustomEvent<undefined> | undefined;
51
51
  change?: CustomEvent<undefined> | undefined;
52
+ receive_null?: CustomEvent<undefined> | undefined;
52
53
  } & {
53
54
  [evt: string]: CustomEvent<any>;
54
55
  };
@@ -52,7 +52,7 @@ async function initial_crop() {
52
52
  h_p = new_height / $editor_box.child_height;
53
53
  l_p = x_offset / $editor_box.child_width;
54
54
  t_p = y_offset / $editor_box.child_height;
55
- c = crop_canvas($pixi.renderer, $pixi.mask_container, crop, 0.2);
55
+ c = crop_canvas($pixi.renderer, $pixi.background_container, crop, 0.2);
56
56
  c.start(...$dimensions, current_crop, false);
57
57
  c.continue(
58
58
  [
@@ -83,7 +83,7 @@ function handle_crop(type, {
83
83
  }
84
84
  cropper = crop_canvas(
85
85
  $pixi?.renderer,
86
- $pixi.mask_container,
86
+ $pixi.background_container,
87
87
  crop,
88
88
  current_opacity
89
89
  );
@@ -6,7 +6,7 @@ export interface CropCommand extends Command {
6
6
  stop: () => number;
7
7
  continue: (crop_size: [number, number, number, number], preview?: boolean) => void;
8
8
  }
9
- export declare function crop_canvas(renderer: IRenderer, mask_container: Container, crop: Writable<[number, number, number, number]>, current_opacity?: number): CropCommand;
9
+ export declare function crop_canvas(renderer: IRenderer, background_container: Container, crop: Writable<[number, number, number, number]>, current_opacity?: number): CropCommand;
10
10
  export declare function resize_and_reposition(original_width: number, original_height: number, anchor: "t" | "r" | "l" | "b" | "tl" | "tr" | "bl" | "br" | "c", aspect_ratio: number, max_width: number, max_height: number): {
11
11
  new_width: number;
12
12
  new_height: number;
@@ -1,7 +1,7 @@
1
1
  import { Graphics, Sprite, RenderTexture } from "pixi.js";
2
2
  import {} from "../utils/commands";
3
3
  import { spring } from "svelte/motion";
4
- export function crop_canvas(renderer, mask_container, crop, current_opacity = 0) {
4
+ export function crop_canvas(renderer, background_container, crop, current_opacity = 0) {
5
5
  let text;
6
6
  let sprite;
7
7
  const mask_graphics = new Graphics();
@@ -45,7 +45,7 @@ export function crop_canvas(renderer, mask_container, crop, current_opacity = 0)
45
45
  });
46
46
  crop_mask(_width, _height, _previous_crop, _preview);
47
47
  sprite = new Sprite(text);
48
- mask_container.mask = sprite;
48
+ background_container.mask = sprite;
49
49
  width = _width;
50
50
  height = _height;
51
51
  if (set_previous)
@@ -87,7 +87,7 @@ export function crop_canvas(renderer, mask_container, crop, current_opacity = 0)
87
87
  }
88
88
  else {
89
89
  if (!stopped) {
90
- alpha_spring.set(0);
90
+ alpha_spring.set(0, { hard: true });
91
91
  }
92
92
  crop.set([
93
93
  final_crop[0] / width,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/imageeditor",
3
- "version": "0.12.3",
3
+ "version": "0.12.5",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
@@ -12,12 +12,12 @@
12
12
  "tinycolor2": "^1.6.0",
13
13
  "@gradio/atoms": "^0.13.1",
14
14
  "@gradio/client": "^1.10.0",
15
- "@gradio/image": "^0.20.2",
16
15
  "@gradio/icons": "^0.10.0",
17
- "@gradio/upload": "^0.14.6",
16
+ "@gradio/image": "^0.20.3",
18
17
  "@gradio/statustracker": "^0.10.2",
18
+ "@gradio/upload": "^0.14.7",
19
19
  "@gradio/utils": "^0.10.0",
20
- "@gradio/wasm": "^0.17.0"
20
+ "@gradio/wasm": "^0.17.1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@gradio/preview": "^0.13.0"
@@ -103,7 +103,7 @@
103
103
  export let canvas_height = undefined;
104
104
 
105
105
  $: height = $editor_box.child_height;
106
- $: canvas_height = $crop[3] * $editor_box.child_height + 1;
106
+ $: canvas_height = $editor_box.child_height + 1;
107
107
 
108
108
  const crop = writable<[number, number, number, number]>([0, 0, 1, 1]);
109
109
  const position_spring = spring(
@@ -250,10 +250,10 @@
250
250
  if (!$editor_box) return;
251
251
  const [l, t, w, h] = $crop;
252
252
 
253
- const cx = l * $editor_box.child_width;
254
- const cy = t * $editor_box.child_height;
255
- const cw = w * $editor_box.child_width;
256
- const ch = h * $editor_box.child_height;
253
+ const cx = 0;
254
+ const cy = 0;
255
+ const cw = $editor_box.child_width;
256
+ const ch = $editor_box.child_height;
257
257
 
258
258
  const x = 0.5 * $editor_box.child_width - cx - cw / 2;
259
259
  const y = 0.5 * $editor_box.child_height - cy - ch / 2;
@@ -269,10 +269,10 @@
269
269
  return $pixi?.get_blobs(
270
270
  $pixi.get_layers(),
271
271
  new Rectangle(
272
- Math.round(l * $dimensions[0]),
273
- Math.round(t * $dimensions[1]),
274
- Math.round(w * $dimensions[0]),
275
- Math.round(h * $dimensions[1])
272
+ Math.round(0),
273
+ Math.round(0),
274
+ Math.round(1 * $dimensions[0]),
275
+ Math.round(1 * $dimensions[1])
276
276
  ),
277
277
  $dimensions
278
278
  );
@@ -381,14 +381,10 @@
381
381
  <div
382
382
  class="canvas"
383
383
  class:no-border={!bg && $active_tool === "bg" && !history}
384
- style:width="{$crop[2] * $editor_box.child_width + 1}px"
385
- style:height="{$crop[3] * $editor_box.child_height + 1}px"
386
- style:top="{$crop[1] * $editor_box.child_height +
387
- ($editor_box.child_top - $editor_box.parent_top) -
388
- 0.5}px"
389
- style:left="{$crop[0] * $editor_box.child_width +
390
- ($editor_box.child_left - $editor_box.parent_left) -
391
- 0.5}px"
384
+ style:width="{$editor_box.child_width + 1}px"
385
+ style:height="{$editor_box.child_height + 1}px"
386
+ style:top="{$editor_box.child_top - $editor_box.parent_top - 0.5}px"
387
+ style:left="{$editor_box.child_left - $editor_box.parent_left - 0.5}px"
392
388
  ></div>
393
389
  </div>
394
390
  </div>
@@ -65,6 +65,7 @@
65
65
  clear?: never;
66
66
  upload?: never;
67
67
  change?: never;
68
+ receive_null?: never;
68
69
  }>();
69
70
 
70
71
  let editor: ImageEditor;
@@ -80,7 +81,12 @@
80
81
  $: if (bg) dispatch("upload");
81
82
 
82
83
  export async function get_data(): Promise<ImageBlobs> {
83
- const blobs = await editor.get_blobs();
84
+ let blobs;
85
+ try {
86
+ blobs = await editor.get_blobs();
87
+ } catch (e) {
88
+ return { background: null, layers: [], composite: null };
89
+ }
84
90
 
85
91
  const bg = blobs.background
86
92
  ? upload(
@@ -121,11 +127,11 @@
121
127
  if (!editor) return;
122
128
  if (value == null) {
123
129
  editor.handle_remove();
130
+ dispatch("receive_null");
124
131
  }
125
132
  }
126
133
 
127
134
  $: handle_value(value);
128
-
129
135
  $: crop_constraint = crop_size;
130
136
  let bg = false;
131
137
  let history = false;
@@ -67,7 +67,7 @@
67
67
  l_p = x_offset / $editor_box.child_width;
68
68
  t_p = y_offset / $editor_box.child_height;
69
69
 
70
- c = crop_canvas($pixi!.renderer, $pixi!.mask_container, crop, 0.2);
70
+ c = crop_canvas($pixi!.renderer, $pixi!.background_container, crop, 0.2);
71
71
  c.start(...$dimensions, current_crop, false);
72
72
 
73
73
  c.continue(
@@ -111,7 +111,7 @@
111
111
 
112
112
  cropper = crop_canvas(
113
113
  $pixi?.renderer,
114
- $pixi.mask_container,
114
+ $pixi.background_container,
115
115
  crop,
116
116
  current_opacity
117
117
  );
@@ -26,7 +26,7 @@ export interface CropCommand extends Command {
26
26
 
27
27
  export function crop_canvas(
28
28
  renderer: IRenderer,
29
- mask_container: Container,
29
+ background_container: Container,
30
30
  crop: Writable<[number, number, number, number]>,
31
31
  current_opacity = 0
32
32
  ): CropCommand {
@@ -89,7 +89,7 @@ export function crop_canvas(
89
89
 
90
90
  crop_mask(_width, _height, _previous_crop, _preview);
91
91
  sprite = new Sprite(text);
92
- mask_container.mask = sprite;
92
+ background_container.mask = sprite;
93
93
  width = _width;
94
94
  height = _height;
95
95
  if (set_previous)
@@ -131,16 +131,14 @@ export function crop_canvas(
131
131
  clean = true;
132
132
  } else {
133
133
  if (!stopped) {
134
- alpha_spring.set(0);
134
+ alpha_spring.set(0, { hard: true });
135
135
  }
136
-
137
136
  crop.set([
138
137
  final_crop[0] / width,
139
138
  final_crop[1] / height,
140
139
  final_crop[2] / width,
141
140
  final_crop[3] / height
142
141
  ]);
143
-
144
142
  clean = true;
145
143
  }
146
144
  }