@gradio/imageeditor 0.14.5 → 0.15.1
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 +23 -0
- package/InteractiveImageEditor.svelte +4 -7
- package/dist/InteractiveImageEditor.svelte +4 -3
- package/dist/InteractiveImageEditor.svelte.d.ts +1 -1
- package/dist/shared/Controls.svelte +32 -1
- package/dist/shared/Controls.svelte.d.ts +2 -0
- package/dist/shared/ImageEditor.svelte +23 -1
- package/dist/shared/ImageEditor.svelte.d.ts +2 -1
- package/dist/shared/brush/brush-cursor.js +0 -42
- package/dist/shared/brush/brush-textures.d.ts +19 -2
- package/dist/shared/brush/brush-textures.js +120 -82
- package/dist/shared/brush/brush.js +0 -52
- package/dist/shared/{utils → core}/commands.d.ts +19 -58
- package/dist/shared/core/commands.js +70 -0
- package/dist/shared/core/editor.d.ts +4 -91
- package/dist/shared/core/editor.js +18 -708
- package/dist/shared/core/layers.d.ts +143 -0
- package/dist/shared/core/layers.js +774 -0
- package/dist/shared/image/image.d.ts +14 -4
- package/dist/shared/image/image.js +91 -18
- package/dist/shared/resize/resize.d.ts +31 -0
- package/dist/shared/resize/resize.js +127 -290
- package/dist/shared/zoom/zoom.js +0 -51
- package/package.json +7 -7
- package/shared/Controls.svelte +33 -1
- package/shared/ImageEditor.svelte +25 -9
- package/shared/Toolbar.svelte +1 -4
- package/shared/brush/ColorSwatch.svelte +0 -3
- package/shared/brush/brush-cursor.ts +0 -42
- package/shared/brush/brush-textures.ts +166 -83
- package/shared/brush/brush.ts +0 -53
- package/shared/core/commands.ts +118 -0
- package/shared/core/editor.ts +33 -957
- package/shared/core/layers.ts +1068 -0
- package/shared/image/image.ts +139 -21
- package/shared/resize/resize.ts +160 -299
- package/shared/zoom/zoom.ts +0 -51
- package/dist/shared/utils/commands.js +0 -73
- package/shared/utils/commands.ts +0 -174
|
@@ -3,6 +3,10 @@ import { type Writable } from "svelte/store";
|
|
|
3
3
|
* Base command interface that is added to the command_managers history
|
|
4
4
|
*/
|
|
5
5
|
export interface Command {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the command
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
6
10
|
/**
|
|
7
11
|
* Optionally called when the command is first executed for multi-step commands
|
|
8
12
|
* @param args arguments to pass to the command
|
|
@@ -30,71 +34,28 @@ export interface Command {
|
|
|
30
34
|
undo(): any | Promise<any>;
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Undo the last command
|
|
38
|
-
*/
|
|
39
|
-
undo(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Redo the last undone command
|
|
42
|
-
*/
|
|
43
|
-
redo(): void;
|
|
44
|
-
/**
|
|
45
|
-
* Execute a command and add it to the history
|
|
46
|
-
* @param command command to execute
|
|
47
|
-
*/
|
|
48
|
-
execute(command: Command): void;
|
|
49
|
-
/**
|
|
50
|
-
* Whether or not there are commands that can be undone
|
|
51
|
-
* Observable store that you can subscribe to for updates
|
|
52
|
-
*/
|
|
53
|
-
readonly can_undo: Writable<boolean>;
|
|
54
|
-
/**
|
|
55
|
-
* Whether or not there are commands that can be redone
|
|
56
|
-
* Observable store that you can subscribe to for updates
|
|
57
|
-
*/
|
|
58
|
-
readonly can_redo: Writable<boolean>;
|
|
59
|
-
/**
|
|
60
|
-
* Resets the history
|
|
61
|
-
*/
|
|
62
|
-
reset(): void;
|
|
63
|
-
/**
|
|
64
|
-
* The current history node
|
|
65
|
-
* Observable store that you can subscribe to for updates
|
|
66
|
-
*/
|
|
67
|
-
readonly current_history: Writable<CommandNode>;
|
|
68
|
-
/**
|
|
69
|
-
* Hydrates the command manager with a full history
|
|
70
|
-
* @param full_history the full history to hydrate with
|
|
71
|
-
*/
|
|
72
|
-
hydrate(full_history: CommandNode): void;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Command node interface that is used to create the undo/redo history
|
|
37
|
+
* Creates a command node
|
|
38
|
+
* @param command command to add to the node
|
|
39
|
+
* @returns a command node
|
|
76
40
|
*/
|
|
77
|
-
export
|
|
78
|
-
/**
|
|
79
|
-
* Command that the node holds
|
|
80
|
-
*/
|
|
41
|
+
export declare class CommandNode {
|
|
81
42
|
command: Command | null;
|
|
82
|
-
/**
|
|
83
|
-
* Next command in the history
|
|
84
|
-
*/
|
|
85
43
|
next: CommandNode | null;
|
|
86
|
-
/**
|
|
87
|
-
* Previous command in the history
|
|
88
|
-
*/
|
|
89
44
|
previous: CommandNode | null;
|
|
90
|
-
|
|
91
|
-
* Push a command onto the history
|
|
92
|
-
* @param command command to push onto the history
|
|
93
|
-
*/
|
|
45
|
+
constructor(command?: Command);
|
|
94
46
|
push(command: Command): void;
|
|
95
47
|
}
|
|
96
48
|
/**
|
|
97
49
|
* Creates a command manager
|
|
98
50
|
* @returns a command manager
|
|
99
51
|
*/
|
|
100
|
-
export declare
|
|
52
|
+
export declare class CommandManager {
|
|
53
|
+
history: CommandNode;
|
|
54
|
+
current_history: Writable<CommandNode>;
|
|
55
|
+
undo(): void;
|
|
56
|
+
redo(): void;
|
|
57
|
+
execute(command: Command): void;
|
|
58
|
+
replay(full_history: CommandNode): void;
|
|
59
|
+
contains(command_name: string): boolean;
|
|
60
|
+
reset(): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { writable } from "svelte/store";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a command node
|
|
4
|
+
* @param command command to add to the node
|
|
5
|
+
* @returns a command node
|
|
6
|
+
*/
|
|
7
|
+
export class CommandNode {
|
|
8
|
+
command;
|
|
9
|
+
next;
|
|
10
|
+
previous;
|
|
11
|
+
constructor(command) {
|
|
12
|
+
this.command = command || null;
|
|
13
|
+
this.next = null;
|
|
14
|
+
this.previous = null;
|
|
15
|
+
}
|
|
16
|
+
push(command) {
|
|
17
|
+
const node = new CommandNode(command);
|
|
18
|
+
node.previous = this;
|
|
19
|
+
this.next = node;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a command manager
|
|
24
|
+
* @returns a command manager
|
|
25
|
+
*/
|
|
26
|
+
export class CommandManager {
|
|
27
|
+
history = new CommandNode();
|
|
28
|
+
current_history = writable(this.history);
|
|
29
|
+
undo() {
|
|
30
|
+
if (this.history.previous) {
|
|
31
|
+
this.history.command?.undo();
|
|
32
|
+
this.history = this.history.previous;
|
|
33
|
+
this.current_history.set(this.history);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
redo() {
|
|
37
|
+
if (this.history.next) {
|
|
38
|
+
this.history = this.history.next;
|
|
39
|
+
this.history.command?.execute();
|
|
40
|
+
}
|
|
41
|
+
this.current_history.set(this.history);
|
|
42
|
+
}
|
|
43
|
+
execute(command) {
|
|
44
|
+
command.execute();
|
|
45
|
+
this.history.push(command);
|
|
46
|
+
this.history = this.history.next;
|
|
47
|
+
this.current_history.set(this.history);
|
|
48
|
+
}
|
|
49
|
+
replay(full_history) {
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
while (full_history.next) {
|
|
52
|
+
this.execute(full_history.next.command);
|
|
53
|
+
full_history = full_history.next;
|
|
54
|
+
}
|
|
55
|
+
}, 1000);
|
|
56
|
+
}
|
|
57
|
+
contains(command_name) {
|
|
58
|
+
let current = this.history;
|
|
59
|
+
while (current) {
|
|
60
|
+
if (current.command?.name === command_name)
|
|
61
|
+
return true;
|
|
62
|
+
current = current.next;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
reset() {
|
|
67
|
+
this.history = new CommandNode();
|
|
68
|
+
this.current_history.set(this.history);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { Application, Container, Sprite
|
|
1
|
+
import { Application, Container, Sprite } from "pixi.js";
|
|
2
2
|
import type { Subtool, Tool as ToolbarTool } from "../Toolbar.svelte";
|
|
3
3
|
import type { Readable, Writable } from "svelte/store";
|
|
4
4
|
import { type Spring } from "svelte/motion";
|
|
5
5
|
import { type ImageBlobs, type LayerOptions } from "../types";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
undo: () => Promise<void>;
|
|
9
|
-
}
|
|
6
|
+
import { CommandManager, type Command } from "./commands";
|
|
7
|
+
import { LayerManager } from "./layers";
|
|
10
8
|
export interface Tool {
|
|
11
9
|
name: string;
|
|
12
10
|
setup(context: ImageEditorContext, tool: ToolbarTool, subtool: Subtool): Promise<void>;
|
|
@@ -15,91 +13,6 @@ export interface Tool {
|
|
|
15
13
|
on?: (event: string, callback: () => void) => void;
|
|
16
14
|
off?: (event: string, callback: () => void) => void;
|
|
17
15
|
}
|
|
18
|
-
export declare class CommandManager {
|
|
19
|
-
private undo_stack;
|
|
20
|
-
private redo_stack;
|
|
21
|
-
execute(command: Command): Promise<void>;
|
|
22
|
-
undo(): Promise<void>;
|
|
23
|
-
redo(): Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
export declare class LayerManager {
|
|
26
|
-
private layers;
|
|
27
|
-
private active_layer;
|
|
28
|
-
private active_layer_id;
|
|
29
|
-
private draw_textures;
|
|
30
|
-
layer_store: Writable<{
|
|
31
|
-
active_layer: string;
|
|
32
|
-
layers: {
|
|
33
|
-
name: string;
|
|
34
|
-
id: string;
|
|
35
|
-
user_created: boolean;
|
|
36
|
-
visible: boolean;
|
|
37
|
-
}[];
|
|
38
|
-
}>;
|
|
39
|
-
private background_layer;
|
|
40
|
-
private image_container;
|
|
41
|
-
private app;
|
|
42
|
-
private fixed_canvas;
|
|
43
|
-
private dark;
|
|
44
|
-
private border_region;
|
|
45
|
-
private layer_options;
|
|
46
|
-
constructor(image_container: Container, app: Application, fixed_canvas: boolean, dark: boolean, border_region: number, layer_options: LayerOptions);
|
|
47
|
-
toggle_layer_visibility(id: string): void;
|
|
48
|
-
create_background_layer(width: number, height: number): Container;
|
|
49
|
-
set_layer_options(layer_options: LayerOptions, width: number, height: number): void;
|
|
50
|
-
/**
|
|
51
|
-
* Creates a background layer from an image URL
|
|
52
|
-
* @param url The URL of the image to use as background
|
|
53
|
-
* @param width The width of the layer (if fixed_canvas is true)
|
|
54
|
-
* @param height The height of the layer (if fixed_canvas is true)
|
|
55
|
-
* @param borderRegion Minimum border region to add around the image for outpainting (in pixels)
|
|
56
|
-
* @returns A Promise that resolves to the background Container when the image is loaded
|
|
57
|
-
*/
|
|
58
|
-
create_background_layer_from_url(url: string, width?: number, height?: number): Promise<Container>;
|
|
59
|
-
create_layer({ width, height, layer_name, user_created, layer_id, make_active }: {
|
|
60
|
-
width: number;
|
|
61
|
-
height: number;
|
|
62
|
-
layer_name?: string;
|
|
63
|
-
user_created: boolean;
|
|
64
|
-
layer_id?: string;
|
|
65
|
-
make_active?: boolean;
|
|
66
|
-
}): Container;
|
|
67
|
-
/**
|
|
68
|
-
* Creates a new layer with an image loaded from a URL
|
|
69
|
-
* @param url The URL of the image to load
|
|
70
|
-
* @param borderRegion Minimum border region to add around the image for outpainting (in pixels)
|
|
71
|
-
* @returns A Promise that resolves to the layer ID
|
|
72
|
-
*/
|
|
73
|
-
add_layer_from_url(url: string): Promise<string>;
|
|
74
|
-
get_active_layer(): typeof this.active_layer;
|
|
75
|
-
set_active_layer(id: string): void;
|
|
76
|
-
get_layers(): typeof this.layers;
|
|
77
|
-
get_layer_textures(id: string): {
|
|
78
|
-
draw: RenderTexture;
|
|
79
|
-
} | null;
|
|
80
|
-
delete_layer(id: string): void;
|
|
81
|
-
private update_layer_order;
|
|
82
|
-
move_layer(id: string, direction: "up" | "down"): void;
|
|
83
|
-
/**
|
|
84
|
-
* Resizes all layers to a new width and height
|
|
85
|
-
* @param newWidth The new width of the layers
|
|
86
|
-
* @param newHeight The new height of the layers
|
|
87
|
-
* @param scale If true, scales the layer content to fit the new dimensions. If false, keeps the content size unchanged.
|
|
88
|
-
* @param anchor The anchor point to position the content relative to the new size
|
|
89
|
-
*/
|
|
90
|
-
resize_all_layers(newWidth: number, newHeight: number, scale: boolean, anchor: "top-left" | "top" | "top-right" | "left" | "center" | "right" | "bottom-left" | "bottom" | "bottom-right", oldCanvasWidth: number, oldCanvasHeight: number): void;
|
|
91
|
-
/**
|
|
92
|
-
* Helper method to resize the background layer.
|
|
93
|
-
*/
|
|
94
|
-
private _resize_background_layer;
|
|
95
|
-
/**
|
|
96
|
-
* Helper method to resize a single regular layer.
|
|
97
|
-
*/
|
|
98
|
-
private _resize_single_layer;
|
|
99
|
-
get_blobs(width: number, height: number): Promise<ImageBlobs>;
|
|
100
|
-
reset_layers(width: number, height: number, persist?: boolean): void;
|
|
101
|
-
init_layers(width: number, height: number): void;
|
|
102
|
-
}
|
|
103
16
|
declare const core_tools: readonly ["image", "zoom"];
|
|
104
17
|
interface ImageEditorOptions {
|
|
105
18
|
target_element: HTMLElement;
|
|
@@ -152,7 +65,7 @@ export declare class ImageEditor {
|
|
|
152
65
|
private app;
|
|
153
66
|
private ui_container;
|
|
154
67
|
private image_container;
|
|
155
|
-
|
|
68
|
+
command_manager: CommandManager;
|
|
156
69
|
private layer_manager;
|
|
157
70
|
private tools;
|
|
158
71
|
private current_tool;
|