@gradio/imageeditor 0.14.4 → 0.15.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/InteractiveImageEditor.svelte +4 -7
  3. package/dist/InteractiveImageEditor.svelte +4 -3
  4. package/dist/InteractiveImageEditor.svelte.d.ts +1 -1
  5. package/dist/shared/Controls.svelte +32 -1
  6. package/dist/shared/Controls.svelte.d.ts +2 -0
  7. package/dist/shared/ImageEditor.svelte +23 -1
  8. package/dist/shared/ImageEditor.svelte.d.ts +2 -1
  9. package/dist/shared/brush/brush-cursor.js +0 -42
  10. package/dist/shared/brush/brush-textures.d.ts +19 -2
  11. package/dist/shared/brush/brush-textures.js +120 -82
  12. package/dist/shared/brush/brush.js +0 -52
  13. package/dist/shared/{utils → core}/commands.d.ts +19 -58
  14. package/dist/shared/core/commands.js +70 -0
  15. package/dist/shared/core/editor.d.ts +4 -91
  16. package/dist/shared/core/editor.js +18 -708
  17. package/dist/shared/core/layers.d.ts +143 -0
  18. package/dist/shared/core/layers.js +774 -0
  19. package/dist/shared/image/image.d.ts +14 -4
  20. package/dist/shared/image/image.js +91 -18
  21. package/dist/shared/resize/resize.d.ts +31 -0
  22. package/dist/shared/resize/resize.js +127 -290
  23. package/dist/shared/zoom/zoom.js +0 -51
  24. package/package.json +7 -7
  25. package/shared/Controls.svelte +33 -1
  26. package/shared/ImageEditor.svelte +25 -9
  27. package/shared/Toolbar.svelte +1 -4
  28. package/shared/brush/ColorSwatch.svelte +0 -3
  29. package/shared/brush/brush-cursor.ts +0 -42
  30. package/shared/brush/brush-textures.ts +166 -83
  31. package/shared/brush/brush.ts +0 -53
  32. package/shared/core/commands.ts +118 -0
  33. package/shared/core/editor.ts +33 -957
  34. package/shared/core/layers.ts +1068 -0
  35. package/shared/image/image.ts +139 -21
  36. package/shared/resize/resize.ts +160 -299
  37. package/shared/zoom/zoom.ts +0 -51
  38. package/dist/shared/utils/commands.js +0 -73
  39. package/shared/utils/commands.ts +0 -174
@@ -0,0 +1,143 @@
1
+ import { Application, Container, RenderTexture } from "pixi.js";
2
+ import type { Writable } from "svelte/store";
3
+ import { type ImageBlobs, type LayerOptions } from "../types";
4
+ import { type Command } from "./commands";
5
+ import { type ImageEditorContext } from "./editor";
6
+ export declare class LayerManager {
7
+ private layers;
8
+ private active_layer;
9
+ private active_layer_id;
10
+ private draw_textures;
11
+ layer_store: Writable<{
12
+ active_layer: string;
13
+ layers: {
14
+ name: string;
15
+ id: string;
16
+ user_created: boolean;
17
+ visible: boolean;
18
+ }[];
19
+ }>;
20
+ private background_layer;
21
+ private image_container;
22
+ private app;
23
+ private fixed_canvas;
24
+ private dark;
25
+ private border_region;
26
+ private layer_options;
27
+ constructor(image_container: Container, app: Application, fixed_canvas: boolean, dark: boolean, border_region: number, layer_options: LayerOptions);
28
+ toggle_layer_visibility(id: string): void;
29
+ create_background_layer(width: number, height: number): Container;
30
+ set_layer_options(layer_options: LayerOptions, width: number, height: number): void;
31
+ /**
32
+ * Creates a background layer from an image URL
33
+ * @param url The URL of the image to use as background
34
+ * @param width The width of the layer (if fixed_canvas is true)
35
+ * @param height The height of the layer (if fixed_canvas is true)
36
+ * @param borderRegion Minimum border region to add around the image for outpainting (in pixels)
37
+ * @returns A Promise that resolves to the background Container when the image is loaded
38
+ */
39
+ create_background_layer_from_url(url: string, width?: number, height?: number): Promise<Container>;
40
+ create_layer({ width, height, layer_name, user_created, layer_id, make_active }: {
41
+ width: number;
42
+ height: number;
43
+ layer_name?: string;
44
+ user_created: boolean;
45
+ layer_id?: string;
46
+ make_active?: boolean;
47
+ }): Container;
48
+ /**
49
+ * Creates a new layer with an image loaded from a URL
50
+ * @param url The URL of the image to load
51
+ * @param borderRegion Minimum border region to add around the image for outpainting (in pixels)
52
+ * @returns A Promise that resolves to the layer ID
53
+ */
54
+ add_layer_from_url(url: string): Promise<string>;
55
+ get_active_layer(): typeof this.active_layer;
56
+ set_active_layer(id: string): void;
57
+ get_layers(): typeof this.layers;
58
+ get_layer_textures(id: string): {
59
+ draw: RenderTexture;
60
+ } | null;
61
+ delete_layer(id: string): void;
62
+ private update_layer_order;
63
+ move_layer(id: string, direction: "up" | "down"): void;
64
+ /**
65
+ * Resizes all layers to a new width and height
66
+ * @param newWidth The new width of the layers
67
+ * @param newHeight The new height of the layers
68
+ * @param scale If true, scales the layer content to fit the new dimensions. If false, keeps the content size unchanged.
69
+ * @param anchor The anchor point to position the content relative to the new size
70
+ */
71
+ 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;
72
+ /**
73
+ * Helper method to resize the background layer.
74
+ */
75
+ private _resize_background_layer;
76
+ /**
77
+ * Helper method to resize a single regular layer.
78
+ */
79
+ private _resize_single_layer;
80
+ get_blobs(width: number, height: number): Promise<ImageBlobs>;
81
+ reset_layers(width: number, height: number, persist?: boolean): void;
82
+ init_layers(width: number, height: number): void;
83
+ }
84
+ /**
85
+ * Command to add a new layer
86
+ */
87
+ export declare class AddLayerCommand implements Command {
88
+ private context;
89
+ private layer_id;
90
+ private layer_name;
91
+ private width;
92
+ private height;
93
+ private user_created;
94
+ private make_active;
95
+ private previous_active_layer;
96
+ name: string;
97
+ constructor(context: ImageEditorContext, options: {
98
+ width: number;
99
+ height: number;
100
+ layer_name?: string;
101
+ user_created: boolean;
102
+ layer_id?: string;
103
+ make_active?: boolean;
104
+ });
105
+ execute(): Promise<void>;
106
+ undo(): Promise<void>;
107
+ }
108
+ /**
109
+ * Command to remove a layer
110
+ */
111
+ export declare class RemoveLayerCommand implements Command {
112
+ private context;
113
+ private layer_data;
114
+ private previous_active_layer;
115
+ private texture_copy;
116
+ name: string;
117
+ constructor(context: ImageEditorContext, layer_id: string);
118
+ /**
119
+ * Create a direct copy of the layer's texture
120
+ */
121
+ private captureTextureData;
122
+ execute(): Promise<void>;
123
+ undo(): Promise<void>;
124
+ /**
125
+ * Clean up resources when the command is no longer needed
126
+ * This would need to be called by a garbage collection mechanism
127
+ */
128
+ destroy(): void;
129
+ }
130
+ /**
131
+ * Command to reorder layers
132
+ */
133
+ export declare class ReorderLayerCommand implements Command {
134
+ private context;
135
+ private original_order;
136
+ private new_order;
137
+ private layer_id;
138
+ private direction;
139
+ name: string;
140
+ constructor(context: ImageEditorContext, layer_id: string, direction: "up" | "down");
141
+ execute(): Promise<void>;
142
+ undo(): Promise<void>;
143
+ }