@gradio/imageeditor 0.12.3 → 0.12.4
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 +7 -0
- package/Index.svelte +6 -0
- package/dist/Index.svelte +6 -0
- package/dist/shared/ImageEditor.svelte +13 -17
- package/dist/shared/InteractiveImageEditor.svelte +7 -1
- package/dist/shared/InteractiveImageEditor.svelte.d.ts +1 -0
- package/dist/shared/tools/Crop.svelte +2 -2
- package/dist/shared/tools/crop.d.ts +1 -1
- package/dist/shared/tools/crop.js +3 -3
- package/package.json +4 -4
- package/shared/ImageEditor.svelte +13 -17
- package/shared/InteractiveImageEditor.svelte +8 -2
- package/shared/tools/Crop.svelte +2 -2
- package/shared/tools/crop.ts +3 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @gradio/imageeditor
|
|
2
2
|
|
|
3
|
+
## 0.12.4
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#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!
|
|
8
|
+
- [#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!
|
|
9
|
+
|
|
3
10
|
## 0.12.3
|
|
4
11
|
|
|
5
12
|
### Fixes
|
package/Index.svelte
CHANGED
package/dist/Index.svelte
CHANGED
|
@@ -46,7 +46,7 @@ export let canvas_height = void 0;
|
|
|
46
46
|
$:
|
|
47
47
|
height = $editor_box.child_height;
|
|
48
48
|
$:
|
|
49
|
-
canvas_height = $
|
|
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 =
|
|
175
|
-
const cy =
|
|
176
|
-
const cw =
|
|
177
|
-
const ch =
|
|
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(
|
|
190
|
-
Math.round(
|
|
191
|
-
Math.round(
|
|
192
|
-
Math.round(
|
|
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="{$
|
|
289
|
-
style:height="{$
|
|
290
|
-
style:top="{$
|
|
291
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
+
"version": "0.12.4",
|
|
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/
|
|
16
|
+
"@gradio/image": "^0.20.2",
|
|
18
17
|
"@gradio/statustracker": "^0.10.2",
|
|
19
18
|
"@gradio/utils": "^0.10.0",
|
|
20
|
-
"@gradio/wasm": "^0.17.0"
|
|
19
|
+
"@gradio/wasm": "^0.17.0",
|
|
20
|
+
"@gradio/upload": "^0.14.6"
|
|
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 = $
|
|
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 =
|
|
254
|
-
const cy =
|
|
255
|
-
const cw =
|
|
256
|
-
const ch =
|
|
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(
|
|
273
|
-
Math.round(
|
|
274
|
-
Math.round(
|
|
275
|
-
Math.round(
|
|
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="{$
|
|
385
|
-
style:height="{$
|
|
386
|
-
style:top="{$
|
|
387
|
-
|
|
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
|
-
|
|
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;
|
package/shared/tools/Crop.svelte
CHANGED
|
@@ -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!.
|
|
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.
|
|
114
|
+
$pixi.background_container,
|
|
115
115
|
crop,
|
|
116
116
|
current_opacity
|
|
117
117
|
);
|
package/shared/tools/crop.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface CropCommand extends Command {
|
|
|
26
26
|
|
|
27
27
|
export function crop_canvas(
|
|
28
28
|
renderer: IRenderer,
|
|
29
|
-
|
|
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
|
-
|
|
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
|
}
|