@gradio/imageeditor 0.12.14 → 0.14.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 +36 -0
- package/Example.svelte +1 -1
- package/IMAGE_EDITOR_OVERVIEW.md +224 -0
- package/ImageEditor.stories.svelte +13 -5
- package/Index.svelte +46 -45
- package/{shared/InteractiveImageEditor.svelte → InteractiveImageEditor.svelte} +65 -103
- package/README.md +2 -0
- package/dist/Example.svelte.d.ts +1 -1
- package/dist/Index.svelte +35 -33
- package/dist/Index.svelte.d.ts +25 -16
- package/dist/{shared/InteractiveImageEditor.svelte → InteractiveImageEditor.svelte} +54 -88
- package/dist/{shared/InteractiveImageEditor.svelte.d.ts → InteractiveImageEditor.svelte.d.ts} +17 -15
- package/dist/shared/Anchor.svelte +311 -0
- package/dist/shared/Anchor.svelte.d.ts +18 -0
- package/dist/shared/Controls.svelte +169 -18
- package/dist/shared/Controls.svelte.d.ts +9 -2
- package/dist/shared/{tools/IconButton.svelte → IconButton.svelte} +19 -3
- package/dist/shared/{tools/IconButton.svelte.d.ts → IconButton.svelte.d.ts} +4 -1
- package/dist/shared/ImageEditor.svelte +572 -289
- package/dist/shared/ImageEditor.svelte.d.ts +54 -56
- package/dist/shared/Layers.svelte +260 -0
- package/dist/shared/Layers.svelte.d.ts +37 -0
- package/dist/shared/Resize.svelte +218 -0
- package/dist/shared/Resize.svelte.d.ts +29 -0
- package/dist/shared/SecondaryToolbar.svelte +55 -0
- package/dist/shared/SecondaryToolbar.svelte.d.ts +37 -0
- package/dist/shared/Toolbar.svelte +337 -0
- package/dist/shared/Toolbar.svelte.d.ts +42 -0
- package/dist/shared/{tools → brush}/BrushOptions.svelte +68 -64
- package/dist/shared/{tools → brush}/BrushOptions.svelte.d.ts +9 -9
- package/dist/shared/{tools → brush}/BrushSize.svelte +2 -27
- package/dist/shared/{tools → brush}/ColorField.svelte +2 -1
- package/dist/shared/{tools → brush}/ColorField.svelte.d.ts +1 -0
- package/dist/shared/{tools → brush}/ColorPicker.svelte +81 -9
- package/dist/shared/{tools → brush}/ColorPicker.svelte.d.ts +1 -0
- package/dist/shared/{tools → brush}/ColorSwatch.svelte +78 -38
- package/dist/shared/{tools → brush}/ColorSwatch.svelte.d.ts +6 -2
- package/dist/shared/brush/brush-cursor.d.ts +101 -0
- package/dist/shared/brush/brush-cursor.js +327 -0
- package/dist/shared/brush/brush-textures.d.ts +65 -0
- package/dist/shared/brush/brush-textures.js +385 -0
- package/dist/shared/brush/brush-utils.d.ts +32 -0
- package/dist/shared/brush/brush-utils.js +59 -0
- package/dist/shared/brush/brush.d.ts +152 -0
- package/dist/shared/brush/brush.js +397 -0
- package/dist/shared/brush/types.d.ts +37 -0
- package/dist/shared/brush/types.js +1 -0
- package/dist/shared/core/editor.d.ts +261 -0
- package/dist/shared/core/editor.js +1264 -0
- package/dist/shared/crop/crop.d.ts +201 -0
- package/dist/shared/crop/crop.js +727 -0
- package/dist/shared/image/image.d.ts +89 -0
- package/dist/shared/image/image.js +183 -0
- package/dist/shared/resize/resize.d.ts +270 -0
- package/dist/shared/resize/resize.js +1413 -0
- package/dist/shared/types.d.ts +16 -0
- package/dist/shared/utils/pixi.d.ts +16 -57
- package/dist/shared/utils/pixi.js +15 -113
- package/dist/shared/zoom/zoom.d.ts +136 -0
- package/dist/shared/zoom/zoom.js +548 -0
- package/package.json +8 -7
- package/shared/Anchor.svelte +384 -0
- package/shared/Controls.svelte +178 -37
- package/shared/{tools/IconButton.svelte → IconButton.svelte} +21 -4
- package/shared/ImageEditor.svelte +712 -350
- package/shared/Layers.svelte +282 -0
- package/shared/Resize.svelte +239 -0
- package/shared/SecondaryToolbar.svelte +67 -0
- package/shared/Toolbar.svelte +386 -0
- package/shared/brush/BRUSH_TOOL.md +134 -0
- package/shared/brush/BrushOptions.svelte +200 -0
- package/shared/{tools → brush}/BrushSize.svelte +2 -30
- package/shared/{tools → brush}/ColorField.svelte +3 -1
- package/shared/{tools → brush}/ColorPicker.svelte +86 -9
- package/shared/{tools → brush}/ColorSwatch.svelte +95 -42
- package/shared/brush/brush-cursor.ts +408 -0
- package/shared/brush/brush-textures.ts +485 -0
- package/shared/brush/brush-utils.ts +76 -0
- package/shared/brush/brush.ts +510 -0
- package/shared/brush/types.ts +41 -0
- package/shared/core/EDITOR.md +182 -0
- package/shared/core/editor.ts +1788 -0
- package/shared/crop/CROP.md +139 -0
- package/shared/crop/crop.ts +1027 -0
- package/shared/image/IMAGE.md +135 -0
- package/shared/image/image.ts +298 -0
- package/shared/resize/resize.ts +1894 -0
- package/shared/types.ts +19 -0
- package/shared/utils/pixi.ts +19 -246
- package/shared/zoom/zoom.ts +729 -0
- package/dist/shared/layers/Layers.svelte +0 -231
- package/dist/shared/layers/Layers.svelte.d.ts +0 -18
- package/dist/shared/layers/utils.d.ts +0 -73
- package/dist/shared/layers/utils.js +0 -156
- package/dist/shared/tools/Brush.svelte +0 -215
- package/dist/shared/tools/Brush.svelte.d.ts +0 -29
- package/dist/shared/tools/Crop.svelte +0 -155
- package/dist/shared/tools/Crop.svelte.d.ts +0 -16
- package/dist/shared/tools/Cropper.svelte +0 -271
- package/dist/shared/tools/Cropper.svelte.d.ts +0 -41
- package/dist/shared/tools/Handle.svelte +0 -260
- package/dist/shared/tools/Handle.svelte.d.ts +0 -29
- package/dist/shared/tools/Sources.svelte +0 -257
- package/dist/shared/tools/Sources.svelte.d.ts +0 -34
- package/dist/shared/tools/Tools.svelte +0 -102
- package/dist/shared/tools/Tools.svelte.d.ts +0 -48
- package/dist/shared/tools/brush.d.ts +0 -62
- package/dist/shared/tools/brush.js +0 -133
- package/dist/shared/tools/crop.d.ts +0 -15
- package/dist/shared/tools/crop.js +0 -154
- package/dist/shared/tools/index.d.ts +0 -5
- package/dist/shared/tools/index.js +0 -5
- package/dist/shared/tools/sources.d.ts +0 -46
- package/dist/shared/tools/sources.js +0 -121
- package/dist/shared/tools/types.d.ts +0 -1
- package/shared/layers/Layers.svelte +0 -250
- package/shared/layers/utils.ts +0 -294
- package/shared/tools/Brush.svelte +0 -280
- package/shared/tools/BrushOptions.svelte +0 -180
- package/shared/tools/Crop.svelte +0 -189
- package/shared/tools/Cropper.svelte +0 -346
- package/shared/tools/Handle.svelte +0 -289
- package/shared/tools/Sources.svelte +0 -283
- package/shared/tools/Tools.svelte +0 -162
- package/shared/tools/brush.ts +0 -247
- package/shared/tools/crop.ts +0 -213
- package/shared/tools/index.ts +0 -5
- package/shared/tools/sources.ts +0 -195
- package/shared/tools/types.ts +0 -1
- /package/dist/shared/{tools → brush}/BrushSize.svelte.d.ts +0 -0
- /package/dist/shared/{tools/types.js → types.js} +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Container, type ColorSource, Sprite, type Renderer, Texture } from "pixi.js";
|
|
2
|
+
import { type ImageEditorContext, type Tool } from "../core/editor";
|
|
3
|
+
import { type Tool as ToolbarTool, type Subtool } from "../Toolbar.svelte";
|
|
4
|
+
import { type Command } from "../utils/commands";
|
|
5
|
+
/**
|
|
6
|
+
* Handles adding images to the editor
|
|
7
|
+
* Only a single image can be added at a time
|
|
8
|
+
* Adding an image removes the current image is one exists
|
|
9
|
+
*/
|
|
10
|
+
export declare class ImageTool implements Tool {
|
|
11
|
+
name: string;
|
|
12
|
+
context: ImageEditorContext;
|
|
13
|
+
current_tool: ToolbarTool;
|
|
14
|
+
current_subtool: Subtool;
|
|
15
|
+
setup(context: ImageEditorContext, tool: ToolbarTool, subtool: Subtool): Promise<void>;
|
|
16
|
+
cleanup(): void;
|
|
17
|
+
add_image({ image, fixed_canvas, border_region }: {
|
|
18
|
+
image: Blob | File | Texture;
|
|
19
|
+
fixed_canvas: boolean;
|
|
20
|
+
border_region?: number;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
set_tool(tool: ToolbarTool, subtool: Subtool): void;
|
|
23
|
+
}
|
|
24
|
+
interface BgImageCommand extends Command {
|
|
25
|
+
/**
|
|
26
|
+
* Initial setup for the bg command
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
start: () => Promise<[number, number]>;
|
|
30
|
+
}
|
|
31
|
+
export declare class AddImageCommand implements BgImageCommand {
|
|
32
|
+
sprite: Sprite;
|
|
33
|
+
fixed_canvas: boolean;
|
|
34
|
+
context: ImageEditorContext;
|
|
35
|
+
background: Blob | File | Texture;
|
|
36
|
+
current_canvas_size: {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
};
|
|
40
|
+
current_scale: number;
|
|
41
|
+
current_position: {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
};
|
|
45
|
+
border_region: number;
|
|
46
|
+
scaled_width: number;
|
|
47
|
+
scaled_height: number;
|
|
48
|
+
constructor(context: ImageEditorContext, background: Blob | File | Texture, fixed_canvas: boolean, border_region?: number);
|
|
49
|
+
start(): Promise<[number, number]>;
|
|
50
|
+
private handle_image;
|
|
51
|
+
execute(): Promise<void>;
|
|
52
|
+
undo(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Command that sets a background
|
|
56
|
+
*/
|
|
57
|
+
interface BgColorCommand extends Command {
|
|
58
|
+
/**
|
|
59
|
+
* Initial setup for the bg command
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
start: () => [number, number];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Adds a background color to the canvas.
|
|
66
|
+
* @param container The container to add the image to.
|
|
67
|
+
* @param renderer The renderer to use for the image.
|
|
68
|
+
* @param color The background color to add.
|
|
69
|
+
* @param width The width of the background.
|
|
70
|
+
* @param height The height of the background.
|
|
71
|
+
* @param resize The function to resize the canvas.
|
|
72
|
+
* @returns A command that can be used to undo the action.
|
|
73
|
+
*/
|
|
74
|
+
export declare function add_bg_color(container: Container, renderer: Renderer, color: ColorSource, width: number, height: number, resize: (width: number, height: number) => void): BgColorCommand;
|
|
75
|
+
/**
|
|
76
|
+
* Calculates new dimensions and position for an image to fit within a canvas while maintaining aspect ratio
|
|
77
|
+
* @param image_width Original width of the image
|
|
78
|
+
* @param image_height Original height of the image
|
|
79
|
+
* @param canvas_width Width of the canvas
|
|
80
|
+
* @param canvas_height Height of the canvas
|
|
81
|
+
* @returns Object containing new dimensions and position
|
|
82
|
+
*/
|
|
83
|
+
export declare function fit_image_to_canvas(image_width: number, image_height: number, canvas_width: number, canvas_height: number): {
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
x: number;
|
|
87
|
+
y: number;
|
|
88
|
+
};
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { Container, Graphics, Color, RenderTexture, Sprite, Texture } from "pixi.js";
|
|
2
|
+
import {} from "../core/editor";
|
|
3
|
+
import {} from "../Toolbar.svelte";
|
|
4
|
+
import {} from "../utils/commands";
|
|
5
|
+
import { make_graphics } from "../utils/pixi";
|
|
6
|
+
import { get } from "svelte/store";
|
|
7
|
+
/**
|
|
8
|
+
* Handles adding images to the editor
|
|
9
|
+
* Only a single image can be added at a time
|
|
10
|
+
* Adding an image removes the current image is one exists
|
|
11
|
+
*/
|
|
12
|
+
export class ImageTool {
|
|
13
|
+
name = "image";
|
|
14
|
+
context;
|
|
15
|
+
current_tool;
|
|
16
|
+
current_subtool;
|
|
17
|
+
async setup(context, tool, subtool) {
|
|
18
|
+
this.context = context;
|
|
19
|
+
this.current_tool = tool;
|
|
20
|
+
this.current_subtool = subtool;
|
|
21
|
+
}
|
|
22
|
+
cleanup() { }
|
|
23
|
+
async add_image({ image, fixed_canvas, border_region = 0 }) {
|
|
24
|
+
const image_command = new AddImageCommand(this.context, image, fixed_canvas, border_region);
|
|
25
|
+
await this.context.execute_command(image_command);
|
|
26
|
+
}
|
|
27
|
+
set_tool(tool, subtool) {
|
|
28
|
+
this.current_tool = tool;
|
|
29
|
+
this.current_subtool = subtool;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class AddImageCommand {
|
|
33
|
+
sprite;
|
|
34
|
+
fixed_canvas;
|
|
35
|
+
context;
|
|
36
|
+
background;
|
|
37
|
+
current_canvas_size;
|
|
38
|
+
current_scale;
|
|
39
|
+
current_position;
|
|
40
|
+
border_region;
|
|
41
|
+
scaled_width;
|
|
42
|
+
scaled_height;
|
|
43
|
+
constructor(context, background, fixed_canvas, border_region = 0) {
|
|
44
|
+
this.context = context;
|
|
45
|
+
this.background = background;
|
|
46
|
+
this.fixed_canvas = fixed_canvas;
|
|
47
|
+
this.border_region = border_region;
|
|
48
|
+
this.current_canvas_size = get(this.context.dimensions);
|
|
49
|
+
this.current_scale = get(this.context.scale);
|
|
50
|
+
this.current_position = get(this.context.position);
|
|
51
|
+
this.sprite = new Sprite();
|
|
52
|
+
}
|
|
53
|
+
async start() {
|
|
54
|
+
// Create the sprite from the blob
|
|
55
|
+
let image_texture;
|
|
56
|
+
if (this.background instanceof Texture) {
|
|
57
|
+
image_texture = this.background;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const img = await createImageBitmap(this.background);
|
|
61
|
+
image_texture = Texture.from(img);
|
|
62
|
+
}
|
|
63
|
+
this.sprite = new Sprite(image_texture);
|
|
64
|
+
return this.handle_image();
|
|
65
|
+
}
|
|
66
|
+
handle_image() {
|
|
67
|
+
// Handle fixed canvas differently when border region is present
|
|
68
|
+
if (this.fixed_canvas) {
|
|
69
|
+
// Calculate the effective canvas size accounting for border region
|
|
70
|
+
const effectiveCanvasWidth = Math.max(this.current_canvas_size.width - this.border_region * 2, 10);
|
|
71
|
+
const effectiveCanvasHeight = Math.max(this.current_canvas_size.height - this.border_region * 2, 10);
|
|
72
|
+
// Fit the image to the canvas while maintaining aspect ratio
|
|
73
|
+
const { width, height, x, y } = fit_image_to_canvas(this.sprite.width, this.sprite.height, effectiveCanvasWidth, effectiveCanvasHeight);
|
|
74
|
+
this.sprite.width = width;
|
|
75
|
+
this.sprite.height = height;
|
|
76
|
+
// Center the image in the canvas
|
|
77
|
+
this.sprite.x = x + this.border_region;
|
|
78
|
+
this.sprite.y = y + this.border_region;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// For non-fixed canvas, use natural dimensions plus border
|
|
82
|
+
const width = this.sprite.width;
|
|
83
|
+
const height = this.sprite.height;
|
|
84
|
+
// Position at the border's offset from origin
|
|
85
|
+
this.sprite.x = this.border_region;
|
|
86
|
+
this.sprite.y = this.border_region;
|
|
87
|
+
return [width + this.border_region * 2, height + this.border_region * 2];
|
|
88
|
+
}
|
|
89
|
+
return [this.current_canvas_size.width, this.current_canvas_size.height];
|
|
90
|
+
}
|
|
91
|
+
async execute() {
|
|
92
|
+
// First ensure we have run start() to create the sprite and get dimensions
|
|
93
|
+
const [width, height] = await this.start();
|
|
94
|
+
// Update image properties with the original dimensions and center in viewport
|
|
95
|
+
await this.context.set_image_properties({
|
|
96
|
+
scale: 1, // Start at 1:1 scale
|
|
97
|
+
position: {
|
|
98
|
+
x: this.context.app.screen.width / 2,
|
|
99
|
+
y: this.context.app.screen.height / 2
|
|
100
|
+
},
|
|
101
|
+
width: this.fixed_canvas ? this.current_canvas_size.width : width,
|
|
102
|
+
height: this.fixed_canvas ? this.current_canvas_size.height : height
|
|
103
|
+
});
|
|
104
|
+
// Create new background layer and add the sprite
|
|
105
|
+
const background_layer = this.context.layer_manager.create_background_layer(this.fixed_canvas ? this.current_canvas_size.width : width, this.fixed_canvas ? this.current_canvas_size.height : height);
|
|
106
|
+
this.sprite.zIndex = 0;
|
|
107
|
+
background_layer.addChild(this.sprite);
|
|
108
|
+
// Resize and preserve content of existing layers
|
|
109
|
+
this.context.layer_manager.reset_layers(this.fixed_canvas ? this.current_canvas_size.width : width, this.fixed_canvas ? this.current_canvas_size.height : height, true);
|
|
110
|
+
this.context.set_background_image(this.sprite);
|
|
111
|
+
this.context.reset();
|
|
112
|
+
}
|
|
113
|
+
async undo() {
|
|
114
|
+
if (this.sprite) {
|
|
115
|
+
this.sprite.destroy();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Adds a background color to the canvas.
|
|
121
|
+
* @param container The container to add the image to.
|
|
122
|
+
* @param renderer The renderer to use for the image.
|
|
123
|
+
* @param color The background color to add.
|
|
124
|
+
* @param width The width of the background.
|
|
125
|
+
* @param height The height of the background.
|
|
126
|
+
* @param resize The function to resize the canvas.
|
|
127
|
+
* @returns A command that can be used to undo the action.
|
|
128
|
+
*/
|
|
129
|
+
export function add_bg_color(container, renderer, color, width, height, resize) {
|
|
130
|
+
let sprite;
|
|
131
|
+
return {
|
|
132
|
+
start() {
|
|
133
|
+
container.removeChildren();
|
|
134
|
+
const graphics = make_graphics(1);
|
|
135
|
+
const texture = RenderTexture.create({
|
|
136
|
+
width,
|
|
137
|
+
height
|
|
138
|
+
});
|
|
139
|
+
renderer.render(graphics, { renderTexture: texture });
|
|
140
|
+
sprite = new Sprite(texture);
|
|
141
|
+
return [sprite.width, sprite.height];
|
|
142
|
+
},
|
|
143
|
+
async execute() {
|
|
144
|
+
resize(sprite.width, sprite.height);
|
|
145
|
+
sprite.zIndex = 1;
|
|
146
|
+
container.addChild(sprite);
|
|
147
|
+
},
|
|
148
|
+
undo() {
|
|
149
|
+
container.removeChildren();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Calculates new dimensions and position for an image to fit within a canvas while maintaining aspect ratio
|
|
155
|
+
* @param image_width Original width of the image
|
|
156
|
+
* @param image_height Original height of the image
|
|
157
|
+
* @param canvas_width Width of the canvas
|
|
158
|
+
* @param canvas_height Height of the canvas
|
|
159
|
+
* @returns Object containing new dimensions and position
|
|
160
|
+
*/
|
|
161
|
+
export function fit_image_to_canvas(image_width, image_height, canvas_width, canvas_height) {
|
|
162
|
+
const image_aspect_ratio = image_width / image_height;
|
|
163
|
+
const canvas_aspect_ratio = canvas_width / canvas_height;
|
|
164
|
+
let new_width;
|
|
165
|
+
let new_height;
|
|
166
|
+
if (image_aspect_ratio > canvas_aspect_ratio) {
|
|
167
|
+
new_width = canvas_width;
|
|
168
|
+
new_height = canvas_width / image_aspect_ratio;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
new_height = canvas_height;
|
|
172
|
+
new_width = canvas_height * image_aspect_ratio;
|
|
173
|
+
}
|
|
174
|
+
// center image
|
|
175
|
+
const x = Math.round((canvas_width - new_width) / 2);
|
|
176
|
+
const y = Math.round((canvas_height - new_height) / 2);
|
|
177
|
+
return {
|
|
178
|
+
width: Math.round(new_width),
|
|
179
|
+
height: Math.round(new_height),
|
|
180
|
+
x,
|
|
181
|
+
y
|
|
182
|
+
};
|
|
183
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { type ImageEditorContext, type Tool } from "../core/editor";
|
|
2
|
+
import { type Tool as ToolbarTool, type Subtool } from "../Toolbar.svelte";
|
|
3
|
+
/**
|
|
4
|
+
* @class ResizeTool
|
|
5
|
+
* @implements {Tool}
|
|
6
|
+
* @description Implements the resize tool functionality for the image editor
|
|
7
|
+
*/
|
|
8
|
+
export declare class ResizeTool implements Tool {
|
|
9
|
+
name: "resize";
|
|
10
|
+
private image_editor_context;
|
|
11
|
+
current_tool: ToolbarTool;
|
|
12
|
+
current_subtool: Subtool;
|
|
13
|
+
private current_cursor;
|
|
14
|
+
private readonly CORNER_SIZE;
|
|
15
|
+
private readonly LINE_THICKNESS;
|
|
16
|
+
private readonly HANDLE_COLOR;
|
|
17
|
+
private readonly HIT_AREA_SIZE;
|
|
18
|
+
private borderRegion;
|
|
19
|
+
private is_dragging;
|
|
20
|
+
private selected_handle;
|
|
21
|
+
private active_corner_index;
|
|
22
|
+
private active_edge_index;
|
|
23
|
+
private last_pointer_position;
|
|
24
|
+
private resize_ui_container;
|
|
25
|
+
private dimensions;
|
|
26
|
+
private position;
|
|
27
|
+
private scale;
|
|
28
|
+
private is_moving;
|
|
29
|
+
private dom_mousedown_handler;
|
|
30
|
+
private dom_mousemove_handler;
|
|
31
|
+
private dom_mouseup_handler;
|
|
32
|
+
private event_callbacks;
|
|
33
|
+
private last_scale;
|
|
34
|
+
/**
|
|
35
|
+
* @method setup
|
|
36
|
+
* @async
|
|
37
|
+
* @description Sets up the resize tool with the given context and tool/subtool
|
|
38
|
+
* @param {ImageEditorContext} context - The image editor context
|
|
39
|
+
* @param {ToolbarTool} tool - The current tool
|
|
40
|
+
* @param {Subtool} subtool - The current subtool
|
|
41
|
+
* @returns {Promise<void>}
|
|
42
|
+
*/
|
|
43
|
+
setup(context: ImageEditorContext, tool: ToolbarTool, subtool: Subtool): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* @method cleanup
|
|
46
|
+
* @description Cleans up the resize tool resources and removes event listeners
|
|
47
|
+
* @returns {void}
|
|
48
|
+
*/
|
|
49
|
+
cleanup(): void;
|
|
50
|
+
/**
|
|
51
|
+
* @method set_tool
|
|
52
|
+
* @description Sets the current tool and subtool, updating UI visibility
|
|
53
|
+
* @param {ToolbarTool} tool - The tool to set
|
|
54
|
+
* @param {Subtool} subtool - The subtool to set
|
|
55
|
+
* @returns {void}
|
|
56
|
+
*/
|
|
57
|
+
set_tool(tool: ToolbarTool, subtool: Subtool): void;
|
|
58
|
+
/**
|
|
59
|
+
* @method init_resize_ui
|
|
60
|
+
* @private
|
|
61
|
+
* @async
|
|
62
|
+
* @description Initializes the resize UI elements and sets up the update loop
|
|
63
|
+
* @returns {Promise<void>}
|
|
64
|
+
*/
|
|
65
|
+
private init_resize_ui;
|
|
66
|
+
/**
|
|
67
|
+
* @method make_resize_ui
|
|
68
|
+
* @private
|
|
69
|
+
* @description Creates the resize UI with the specified dimensions
|
|
70
|
+
* @param {number} width - Width of the resize area
|
|
71
|
+
* @param {number} height - Height of the resize area
|
|
72
|
+
* @returns {Container} The created resize UI container
|
|
73
|
+
*/
|
|
74
|
+
private make_resize_ui;
|
|
75
|
+
/**
|
|
76
|
+
* @method create_handle
|
|
77
|
+
* @private
|
|
78
|
+
* @description Creates a handle for the resize UI
|
|
79
|
+
* @param {boolean} [is_edge=false] - Whether the handle is an edge handle
|
|
80
|
+
* @returns {Container} The created handle container
|
|
81
|
+
*/
|
|
82
|
+
private create_handle;
|
|
83
|
+
/**
|
|
84
|
+
* @method create_edge_handles
|
|
85
|
+
* @private
|
|
86
|
+
* @description Creates edge handles for the resize UI
|
|
87
|
+
* @param {Container} container - The container to add handles to
|
|
88
|
+
* @param {number} width - Width of the resize area
|
|
89
|
+
* @param {number} height - Height of the resize area
|
|
90
|
+
* @returns {void}
|
|
91
|
+
*/
|
|
92
|
+
private create_edge_handles;
|
|
93
|
+
/**
|
|
94
|
+
* @method create_corner_handles
|
|
95
|
+
* @private
|
|
96
|
+
* @description Creates corner handles for the resize UI
|
|
97
|
+
* @param {Container} container - The container to add handles to
|
|
98
|
+
* @param {number} width - Width of the resize area
|
|
99
|
+
* @param {number} height - Height of the resize area
|
|
100
|
+
* @returns {void}
|
|
101
|
+
*/
|
|
102
|
+
private create_corner_handles;
|
|
103
|
+
/**
|
|
104
|
+
* @method handle_pointer_down
|
|
105
|
+
* @private
|
|
106
|
+
* @description Handles pointer down events on handles
|
|
107
|
+
* @param {FederatedPointerEvent} event - The pointer event
|
|
108
|
+
* @param {Container} handle - The handle that was clicked
|
|
109
|
+
* @param {number} corner_index - Index of the corner (-1 if not a corner)
|
|
110
|
+
* @param {number} edge_index - Index of the edge (-1 if not an edge)
|
|
111
|
+
* @returns {void}
|
|
112
|
+
*/
|
|
113
|
+
private handle_pointer_down;
|
|
114
|
+
/**
|
|
115
|
+
* Maintains aspect ratio during resizing
|
|
116
|
+
* @param new_width - The new width
|
|
117
|
+
* @param new_height - The new height
|
|
118
|
+
* @param original_aspect_ratio - The original aspect ratio
|
|
119
|
+
* @param delta - The delta to apply
|
|
120
|
+
* @returns The adjusted dimensions
|
|
121
|
+
*/
|
|
122
|
+
private maintain_aspect_ratio;
|
|
123
|
+
/**
|
|
124
|
+
* Limits dimensions based on constraints
|
|
125
|
+
* @param width - The width to limit
|
|
126
|
+
* @param height - The height to limit
|
|
127
|
+
* @param maintain_aspect_ratio - Whether to maintain aspect ratio
|
|
128
|
+
* @returns The limited dimensions
|
|
129
|
+
*/
|
|
130
|
+
private limit_dimensions;
|
|
131
|
+
/**
|
|
132
|
+
* Calculates position deltas based on dimension changes
|
|
133
|
+
* @param old_width - The original width
|
|
134
|
+
* @param old_height - The original height
|
|
135
|
+
* @param new_width - The new width
|
|
136
|
+
* @param new_height - The new height
|
|
137
|
+
* @returns Object containing x and y position deltas
|
|
138
|
+
*/
|
|
139
|
+
private calculate_position_deltas;
|
|
140
|
+
/**
|
|
141
|
+
* Applies boundary constraints to keep the image within the container
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
private apply_boundary_constraints;
|
|
145
|
+
/**
|
|
146
|
+
* Updates the resize bounds based on the delta
|
|
147
|
+
* @param delta - The delta to apply
|
|
148
|
+
* @param maintain_aspect_ratio - Whether to maintain the aspect ratio
|
|
149
|
+
*/
|
|
150
|
+
private update_resize_bounds;
|
|
151
|
+
/**
|
|
152
|
+
* updates the resize ui position and dimensions
|
|
153
|
+
*/
|
|
154
|
+
private update_resize_ui;
|
|
155
|
+
/**
|
|
156
|
+
* updates the positions of all handles
|
|
157
|
+
* @param width - width of the resize area
|
|
158
|
+
* @param height - height of the resize area
|
|
159
|
+
*/
|
|
160
|
+
private update_handle_positions;
|
|
161
|
+
/**
|
|
162
|
+
* sets up event listeners for the resize tool
|
|
163
|
+
*/
|
|
164
|
+
private setup_event_listeners;
|
|
165
|
+
/**
|
|
166
|
+
* Sets up direct DOM event listeners for dragging the background image
|
|
167
|
+
*/
|
|
168
|
+
private setup_dom_event_listeners;
|
|
169
|
+
/**
|
|
170
|
+
* Cleans up DOM event listeners
|
|
171
|
+
*/
|
|
172
|
+
private cleanup_dom_event_listeners;
|
|
173
|
+
/**
|
|
174
|
+
* removes event listeners for the resize tool
|
|
175
|
+
*/
|
|
176
|
+
private cleanup_event_listeners;
|
|
177
|
+
/**
|
|
178
|
+
* Handles pointer move events
|
|
179
|
+
*/
|
|
180
|
+
private handle_pointer_move;
|
|
181
|
+
/**
|
|
182
|
+
* handles pointer up events
|
|
183
|
+
*/
|
|
184
|
+
private handle_pointer_up;
|
|
185
|
+
/**
|
|
186
|
+
* Handles dragging of the background image
|
|
187
|
+
* @param current_position - The current pointer position
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
private handle_image_dragging;
|
|
191
|
+
/**
|
|
192
|
+
* Handles corner resizing
|
|
193
|
+
* @param current_position - The current mouse position
|
|
194
|
+
* @param original_width - The original width
|
|
195
|
+
* @param original_height - The original height
|
|
196
|
+
* @param original_x - The original x position
|
|
197
|
+
* @param original_y - The original y position
|
|
198
|
+
* @param original_aspect_ratio - The original aspect ratio
|
|
199
|
+
* @param maintain_aspect_ratio - Whether to maintain aspect ratio
|
|
200
|
+
* @returns The new dimensions and position
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
private handle_direct_corner_resize;
|
|
204
|
+
/**
|
|
205
|
+
* Handles edge resizing
|
|
206
|
+
* @param current_position - The current mouse position
|
|
207
|
+
* @param original_width - The original width
|
|
208
|
+
* @param original_height - The original height
|
|
209
|
+
* @param original_x - The original x position
|
|
210
|
+
* @param original_y - The original y position
|
|
211
|
+
* @returns The new dimensions and position
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
private handle_direct_edge_resize;
|
|
215
|
+
/**
|
|
216
|
+
* Limits dimensions to container size
|
|
217
|
+
* @param dimensions - The dimensions to limit
|
|
218
|
+
* @param original_x - The original x position
|
|
219
|
+
* @param original_y - The original y position
|
|
220
|
+
* @param original_width - The original width
|
|
221
|
+
* @param original_height - The original height
|
|
222
|
+
* @param maintain_aspect_ratio - Whether to maintain aspect ratio
|
|
223
|
+
* @returns The limited dimensions and position
|
|
224
|
+
* @private
|
|
225
|
+
*/
|
|
226
|
+
private limit_dimensions_to_container;
|
|
227
|
+
/**
|
|
228
|
+
* Apply size limits to ensure dimensions don't exceed container
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
231
|
+
private apply_size_limits;
|
|
232
|
+
/**
|
|
233
|
+
* Adjust position based on which handles are being dragged
|
|
234
|
+
* @private
|
|
235
|
+
*/
|
|
236
|
+
private adjust_position_for_resizing;
|
|
237
|
+
/**
|
|
238
|
+
* Apply border region constraints to prevent image from intruding on border
|
|
239
|
+
* @private
|
|
240
|
+
*/
|
|
241
|
+
private apply_border_constraints;
|
|
242
|
+
/**
|
|
243
|
+
* Apply top and left border constraints
|
|
244
|
+
* @private
|
|
245
|
+
*/
|
|
246
|
+
private apply_top_left_constraints;
|
|
247
|
+
/**
|
|
248
|
+
* Apply bottom and right border constraints
|
|
249
|
+
* @private
|
|
250
|
+
*/
|
|
251
|
+
private apply_bottom_right_constraints;
|
|
252
|
+
/**
|
|
253
|
+
* Shows the resize UI
|
|
254
|
+
* @private
|
|
255
|
+
*/
|
|
256
|
+
private show_resize_ui;
|
|
257
|
+
/**
|
|
258
|
+
* Hides the resize UI
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
private hide_resize_ui;
|
|
262
|
+
on<T extends string>(event: T, callback: () => void): void;
|
|
263
|
+
off<T extends string>(event: T, callback: () => void): void;
|
|
264
|
+
private notify;
|
|
265
|
+
/**
|
|
266
|
+
* Sets the border region explicitly
|
|
267
|
+
* @param borderRegion The border region size in pixels
|
|
268
|
+
*/
|
|
269
|
+
set_border_region(borderRegion: number): void;
|
|
270
|
+
}
|