@gradio/imageeditor 0.12.13 → 0.13.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 +23 -0
- package/Example.svelte +1 -1
- package/IMAGE_EDITOR_OVERVIEW.md +224 -0
- package/ImageEditor.stories.svelte +4 -4
- package/Index.svelte +35 -46
- package/{shared/InteractiveImageEditor.svelte → InteractiveImageEditor.svelte} +56 -103
- package/dist/Example.svelte.d.ts +1 -1
- package/dist/Index.svelte +29 -33
- package/dist/Index.svelte.d.ts +17 -16
- package/dist/{shared/InteractiveImageEditor.svelte → InteractiveImageEditor.svelte} +47 -88
- package/dist/{shared/InteractiveImageEditor.svelte.d.ts → InteractiveImageEditor.svelte.d.ts} +13 -15
- package/dist/shared/Anchor.svelte +311 -0
- package/dist/shared/Anchor.svelte.d.ts +18 -0
- package/dist/shared/Controls.svelte +162 -23
- package/dist/shared/Controls.svelte.d.ts +7 -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 +546 -289
- package/dist/shared/ImageEditor.svelte.d.ts +51 -56
- package/dist/shared/Layers.svelte +233 -0
- package/dist/shared/Layers.svelte.d.ts +35 -0
- package/dist/shared/Resize.svelte +218 -0
- package/dist/shared/Resize.svelte.d.ts +29 -0
- package/dist/shared/SecondaryToolbar.svelte +54 -0
- package/dist/shared/SecondaryToolbar.svelte.d.ts +35 -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 +71 -0
- package/dist/shared/brush/brush-textures.js +404 -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 +396 -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 +252 -0
- package/dist/shared/core/editor.js +1221 -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 +185 -0
- package/dist/shared/resize/resize.d.ts +270 -0
- package/dist/shared/resize/resize.js +1413 -0
- package/dist/shared/types.d.ts +12 -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 +11 -10
- package/shared/Anchor.svelte +384 -0
- package/shared/Controls.svelte +194 -27
- package/shared/{tools/IconButton.svelte → IconButton.svelte} +21 -4
- package/shared/ImageEditor.svelte +682 -349
- package/shared/Layers.svelte +249 -0
- package/shared/Resize.svelte +239 -0
- package/shared/SecondaryToolbar.svelte +61 -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 +508 -0
- package/shared/brush/brush-utils.ts +76 -0
- package/shared/brush/brush.ts +506 -0
- package/shared/brush/types.ts +41 -0
- package/shared/core/EDITOR.md +182 -0
- package/shared/core/editor.ts +1730 -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 +300 -0
- package/shared/resize/resize.ts +1894 -0
- package/shared/types.ts +14 -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
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
|
-
import { type ColorInput } from "tinycolor2";
|
|
3
|
-
export interface Eraser {
|
|
4
|
-
/**
|
|
5
|
-
* The default size of the eraser.
|
|
6
|
-
*/
|
|
7
|
-
default_size: number | "auto";
|
|
8
|
-
}
|
|
9
|
-
export interface Brush extends Eraser {
|
|
10
|
-
/**
|
|
11
|
-
* The default color of the brush.
|
|
12
|
-
*/
|
|
13
|
-
default_color: ColorInput;
|
|
14
|
-
/**
|
|
15
|
-
* The colors to show in the color swatch
|
|
16
|
-
*/
|
|
17
|
-
colors: ColorInput[];
|
|
18
|
-
/**
|
|
19
|
-
* Whether to show _only_ the color swatches specified in `colors`, or to show the color swatches specified in `colors` along with the colorpicker.
|
|
20
|
-
*/
|
|
21
|
-
color_mode: "fixed" | "defaults";
|
|
22
|
-
}
|
|
23
|
-
declare const __propDef: any;
|
|
24
|
-
export type BrushProps = typeof __propDef.props;
|
|
25
|
-
export type BrushEvents = typeof __propDef.events;
|
|
26
|
-
export type BrushSlots = typeof __propDef.slots;
|
|
27
|
-
export default class Brush extends SvelteComponent<BrushProps, BrushEvents, BrushSlots> {
|
|
28
|
-
}
|
|
29
|
-
export {};
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
<script>import { getContext, onDestroy, onMount, tick } from "svelte";
|
|
2
|
-
import { TOOL_KEY } from "./Tools.svelte";
|
|
3
|
-
import { EDITOR_KEY } from "../ImageEditor.svelte";
|
|
4
|
-
import { crop_canvas, resize_and_reposition } from "./crop";
|
|
5
|
-
import Cropper from "./Cropper.svelte";
|
|
6
|
-
const { active_tool, register_tool } = getContext(TOOL_KEY);
|
|
7
|
-
const {
|
|
8
|
-
dimensions,
|
|
9
|
-
editor_box,
|
|
10
|
-
pixi,
|
|
11
|
-
crop,
|
|
12
|
-
command_manager,
|
|
13
|
-
current_history
|
|
14
|
-
} = getContext(EDITOR_KEY);
|
|
15
|
-
let cropper;
|
|
16
|
-
export let crop_constraint;
|
|
17
|
-
let _crop_constraint = null;
|
|
18
|
-
$: {
|
|
19
|
-
if (typeof crop_constraint === "string") {
|
|
20
|
-
const [w, h] = crop_constraint.split(":");
|
|
21
|
-
_crop_constraint = parseInt(w) / parseInt(h);
|
|
22
|
-
} else if (Array.isArray(crop_constraint)) {
|
|
23
|
-
_crop_constraint = crop_constraint[0] / crop_constraint[1];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
let w_p = 1;
|
|
27
|
-
let h_p = 1;
|
|
28
|
-
let l_p = 0;
|
|
29
|
-
let t_p = 0;
|
|
30
|
-
let current_opacity = 0;
|
|
31
|
-
let manually_cropped = false;
|
|
32
|
-
$: {
|
|
33
|
-
if (!manually_cropped && _crop_constraint && $pixi && $active_tool) {
|
|
34
|
-
requestAnimationFrame(() => {
|
|
35
|
-
initial_crop();
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
let c = null;
|
|
40
|
-
async function initial_crop() {
|
|
41
|
-
if (c || $current_history.previous)
|
|
42
|
-
return;
|
|
43
|
-
const { new_height, new_width, x_offset, y_offset } = resize_and_reposition(
|
|
44
|
-
$editor_box.child_width,
|
|
45
|
-
$editor_box.child_height,
|
|
46
|
-
"c",
|
|
47
|
-
_crop_constraint,
|
|
48
|
-
$editor_box.child_width,
|
|
49
|
-
$editor_box.child_height
|
|
50
|
-
);
|
|
51
|
-
w_p = new_width / $editor_box.child_width;
|
|
52
|
-
h_p = new_height / $editor_box.child_height;
|
|
53
|
-
l_p = x_offset / $editor_box.child_width;
|
|
54
|
-
t_p = y_offset / $editor_box.child_height;
|
|
55
|
-
c = crop_canvas($pixi.renderer, $pixi.background_container, crop, 0.2);
|
|
56
|
-
c.start(...$dimensions, current_crop, false);
|
|
57
|
-
c.continue(
|
|
58
|
-
[
|
|
59
|
-
l_p * $dimensions[0],
|
|
60
|
-
t_p * $dimensions[1],
|
|
61
|
-
w_p * $dimensions[0],
|
|
62
|
-
h_p * $dimensions[1]
|
|
63
|
-
],
|
|
64
|
-
false
|
|
65
|
-
);
|
|
66
|
-
c.stop();
|
|
67
|
-
c.execute();
|
|
68
|
-
c = null;
|
|
69
|
-
current_opacity = 0;
|
|
70
|
-
}
|
|
71
|
-
function handle_crop(type, {
|
|
72
|
-
x,
|
|
73
|
-
y,
|
|
74
|
-
width,
|
|
75
|
-
height
|
|
76
|
-
}) {
|
|
77
|
-
if (!$pixi)
|
|
78
|
-
return;
|
|
79
|
-
if (type === "start") {
|
|
80
|
-
if (cropper) {
|
|
81
|
-
current_opacity = cropper.stop();
|
|
82
|
-
cropper = null;
|
|
83
|
-
}
|
|
84
|
-
cropper = crop_canvas(
|
|
85
|
-
$pixi?.renderer,
|
|
86
|
-
$pixi.background_container,
|
|
87
|
-
crop,
|
|
88
|
-
current_opacity
|
|
89
|
-
);
|
|
90
|
-
cropper.start(...$dimensions, current_crop);
|
|
91
|
-
} else if (type === "continue") {
|
|
92
|
-
if (!cropper)
|
|
93
|
-
return;
|
|
94
|
-
cropper.continue([
|
|
95
|
-
x * $dimensions[0],
|
|
96
|
-
y * $dimensions[1],
|
|
97
|
-
width * $dimensions[0],
|
|
98
|
-
height * $dimensions[1]
|
|
99
|
-
]);
|
|
100
|
-
} else if (type === "stop") {
|
|
101
|
-
if (!cropper)
|
|
102
|
-
return;
|
|
103
|
-
command_manager.execute(cropper);
|
|
104
|
-
}
|
|
105
|
-
manually_cropped = true;
|
|
106
|
-
}
|
|
107
|
-
let measured = false;
|
|
108
|
-
function get_measurements() {
|
|
109
|
-
if (measured)
|
|
110
|
-
return;
|
|
111
|
-
if (!$editor_box.child_height)
|
|
112
|
-
return;
|
|
113
|
-
const _height = $editor_box.child_height;
|
|
114
|
-
const _width = $editor_box.child_width;
|
|
115
|
-
const _top = $editor_box.child_top - $editor_box.parent_top;
|
|
116
|
-
const _left = $editor_box.child_left - $editor_box.parent_left;
|
|
117
|
-
w_p = _width / $editor_box.child_width;
|
|
118
|
-
h_p = _height / $editor_box.child_height;
|
|
119
|
-
l_p = (_left - $editor_box.child_left + $editor_box.parent_left) / $editor_box.child_width;
|
|
120
|
-
t_p = (_top - $editor_box.child_top + $editor_box.parent_top) / $editor_box.child_height;
|
|
121
|
-
measured = true;
|
|
122
|
-
}
|
|
123
|
-
let current_crop;
|
|
124
|
-
$:
|
|
125
|
-
current_crop = [
|
|
126
|
-
l_p * $dimensions[0],
|
|
127
|
-
t_p * $dimensions[1],
|
|
128
|
-
w_p * $dimensions[0],
|
|
129
|
-
h_p * $dimensions[1]
|
|
130
|
-
];
|
|
131
|
-
$: {
|
|
132
|
-
l_p = $crop[0];
|
|
133
|
-
t_p = $crop[1];
|
|
134
|
-
w_p = $crop[2];
|
|
135
|
-
h_p = $crop[3];
|
|
136
|
-
}
|
|
137
|
-
$:
|
|
138
|
-
$editor_box && get_measurements();
|
|
139
|
-
const unregister = register_tool("crop");
|
|
140
|
-
onDestroy(unregister);
|
|
141
|
-
</script>
|
|
142
|
-
|
|
143
|
-
{#if $active_tool === "crop" && measured}
|
|
144
|
-
<Cropper
|
|
145
|
-
crop_constraint={_crop_constraint}
|
|
146
|
-
{w_p}
|
|
147
|
-
{h_p}
|
|
148
|
-
{l_p}
|
|
149
|
-
{t_p}
|
|
150
|
-
{editor_box}
|
|
151
|
-
on:crop_start={({ detail }) => handle_crop("start", detail)}
|
|
152
|
-
on:crop_continue={({ detail }) => handle_crop("continue", detail)}
|
|
153
|
-
on:crop_end={({ detail }) => handle_crop("stop", detail)}
|
|
154
|
-
/>
|
|
155
|
-
{/if}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: {
|
|
4
|
-
crop_constraint: [number, number] | `${string}:${string}` | null;
|
|
5
|
-
};
|
|
6
|
-
events: {
|
|
7
|
-
[evt: string]: CustomEvent<any>;
|
|
8
|
-
};
|
|
9
|
-
slots: {};
|
|
10
|
-
};
|
|
11
|
-
export type CropProps = typeof __propDef.props;
|
|
12
|
-
export type CropEvents = typeof __propDef.events;
|
|
13
|
-
export type CropSlots = typeof __propDef.slots;
|
|
14
|
-
export default class Crop extends SvelteComponent<CropProps, CropEvents, CropSlots> {
|
|
15
|
-
}
|
|
16
|
-
export {};
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
<script>import { createEventDispatcher } from "svelte";
|
|
2
|
-
import Handle from "./Handle.svelte";
|
|
3
|
-
import {} from "../ImageEditor.svelte";
|
|
4
|
-
import { clamp } from "../utils/pixi";
|
|
5
|
-
import { resize_and_reposition } from "./crop";
|
|
6
|
-
export let editor_box;
|
|
7
|
-
export let crop_constraint;
|
|
8
|
-
const dispatch = createEventDispatcher();
|
|
9
|
-
let _height = $editor_box.child_height;
|
|
10
|
-
let _width = $editor_box.child_width;
|
|
11
|
-
let _top = $editor_box.child_top - $editor_box.parent_top;
|
|
12
|
-
let _left = $editor_box.child_left - $editor_box.parent_left;
|
|
13
|
-
let _right = $editor_box.child_right - $editor_box.parent_left;
|
|
14
|
-
let _bottom = 0;
|
|
15
|
-
let dragging = false;
|
|
16
|
-
export let w_p;
|
|
17
|
-
export let h_p;
|
|
18
|
-
export let l_p;
|
|
19
|
-
export let t_p;
|
|
20
|
-
const positions = ["tl", "br", "tr", "bl", "t", "b", "l", "r"];
|
|
21
|
-
let finished;
|
|
22
|
-
let timer;
|
|
23
|
-
let triggered = false;
|
|
24
|
-
$: {
|
|
25
|
-
if (dragging || position_drag) {
|
|
26
|
-
clearTimeout(timer);
|
|
27
|
-
finished = false;
|
|
28
|
-
} else {
|
|
29
|
-
set_finished_with_timeout_and_delay();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function set_finished_with_timeout_and_delay() {
|
|
33
|
-
if (timer) {
|
|
34
|
-
clearTimeout(timer);
|
|
35
|
-
}
|
|
36
|
-
timer = setTimeout(() => {
|
|
37
|
-
if (triggered) {
|
|
38
|
-
dispatch("crop_end", {
|
|
39
|
-
x: l_p,
|
|
40
|
-
y: t_p,
|
|
41
|
-
width: w_p,
|
|
42
|
-
height: h_p
|
|
43
|
-
});
|
|
44
|
-
triggered = false;
|
|
45
|
-
}
|
|
46
|
-
finished = true;
|
|
47
|
-
position_drag = false;
|
|
48
|
-
}, 1e3);
|
|
49
|
-
}
|
|
50
|
-
function handle_change({
|
|
51
|
-
top,
|
|
52
|
-
bottom,
|
|
53
|
-
left,
|
|
54
|
-
right
|
|
55
|
-
}, position) {
|
|
56
|
-
_top = clamp(
|
|
57
|
-
top ? top - $editor_box.parent_top : _top,
|
|
58
|
-
$editor_box.child_top - $editor_box.parent_top,
|
|
59
|
-
$editor_box.child_bottom - $editor_box.parent_top
|
|
60
|
-
);
|
|
61
|
-
_left = clamp(
|
|
62
|
-
left ? left - $editor_box.parent_left : _left,
|
|
63
|
-
$editor_box.child_left - $editor_box.parent_left,
|
|
64
|
-
$editor_box.child_right - $editor_box.parent_left
|
|
65
|
-
);
|
|
66
|
-
_right = clamp(
|
|
67
|
-
right ? right - $editor_box.parent_left : _right,
|
|
68
|
-
$editor_box.child_left - $editor_box.parent_left,
|
|
69
|
-
$editor_box.child_right - $editor_box.parent_left
|
|
70
|
-
);
|
|
71
|
-
_bottom = clamp(
|
|
72
|
-
bottom ? bottom - $editor_box.parent_top : _bottom,
|
|
73
|
-
$editor_box.child_top - $editor_box.parent_top,
|
|
74
|
-
$editor_box.child_bottom - $editor_box.parent_top
|
|
75
|
-
);
|
|
76
|
-
_width = clamp(
|
|
77
|
-
right ? right - _left - $editor_box.parent_left : _width,
|
|
78
|
-
0,
|
|
79
|
-
_right - _left
|
|
80
|
-
);
|
|
81
|
-
_width = clamp(
|
|
82
|
-
left ? _right - left + $editor_box.parent_left : _width,
|
|
83
|
-
0,
|
|
84
|
-
_right - _left
|
|
85
|
-
);
|
|
86
|
-
_height = clamp(
|
|
87
|
-
bottom ? bottom - _top - $editor_box.parent_top : _height,
|
|
88
|
-
0,
|
|
89
|
-
_bottom - _top
|
|
90
|
-
);
|
|
91
|
-
_height = clamp(
|
|
92
|
-
top ? _bottom - top + $editor_box.parent_top : _height,
|
|
93
|
-
0,
|
|
94
|
-
_bottom - _top
|
|
95
|
-
);
|
|
96
|
-
const anchors_for_position = {
|
|
97
|
-
tl: "br",
|
|
98
|
-
tr: "bl",
|
|
99
|
-
bl: "tr",
|
|
100
|
-
br: "tl",
|
|
101
|
-
t: "b",
|
|
102
|
-
b: "t",
|
|
103
|
-
l: "r",
|
|
104
|
-
r: "l",
|
|
105
|
-
c: "c"
|
|
106
|
-
};
|
|
107
|
-
if (crop_constraint) {
|
|
108
|
-
const max_w = ["t", "b"].includes(position) ? $editor_box.child_width : _right - _left;
|
|
109
|
-
const max_h = ["l", "r"].includes(position) ? $editor_box.child_height : _bottom - _top;
|
|
110
|
-
let result = resize_and_reposition(
|
|
111
|
-
_width,
|
|
112
|
-
_height,
|
|
113
|
-
anchors_for_position[position],
|
|
114
|
-
crop_constraint,
|
|
115
|
-
max_w,
|
|
116
|
-
max_h
|
|
117
|
-
);
|
|
118
|
-
_width = result.new_width;
|
|
119
|
-
_height = result.new_height;
|
|
120
|
-
_left = _left + result.x_offset;
|
|
121
|
-
_top = _top + result.y_offset;
|
|
122
|
-
_right = _left + _width;
|
|
123
|
-
_bottom = _top + _height;
|
|
124
|
-
}
|
|
125
|
-
w_p = _width / $editor_box.child_width;
|
|
126
|
-
h_p = _height / $editor_box.child_height;
|
|
127
|
-
l_p = (_left - $editor_box.child_left + $editor_box.parent_left) / $editor_box.child_width;
|
|
128
|
-
t_p = (_top - $editor_box.child_top + $editor_box.parent_top) / $editor_box.child_height;
|
|
129
|
-
dispatch(triggered ? "crop_continue" : "crop_start", {
|
|
130
|
-
x: l_p,
|
|
131
|
-
y: t_p,
|
|
132
|
-
width: w_p,
|
|
133
|
-
height: h_p
|
|
134
|
-
});
|
|
135
|
-
triggered = true;
|
|
136
|
-
}
|
|
137
|
-
function resize() {
|
|
138
|
-
_width = w_p * $editor_box.child_width;
|
|
139
|
-
_height = h_p * $editor_box.child_height;
|
|
140
|
-
_left = l_p * $editor_box.child_width + ($editor_box.child_left - $editor_box.parent_left);
|
|
141
|
-
_top = t_p * $editor_box.child_height + ($editor_box.child_top - $editor_box.parent_top);
|
|
142
|
-
_right = _left + _width;
|
|
143
|
-
_bottom = _top + _height;
|
|
144
|
-
}
|
|
145
|
-
$:
|
|
146
|
-
$editor_box && resize();
|
|
147
|
-
let start_x = 0;
|
|
148
|
-
let start_y = 0;
|
|
149
|
-
let position_drag = false;
|
|
150
|
-
function handle_drag_start(e) {
|
|
151
|
-
position_drag = true;
|
|
152
|
-
start_x = e.clientX;
|
|
153
|
-
start_y = e.clientY;
|
|
154
|
-
if (!finished)
|
|
155
|
-
return;
|
|
156
|
-
finished = false;
|
|
157
|
-
dispatch("crop_start", {
|
|
158
|
-
x: l_p,
|
|
159
|
-
y: t_p,
|
|
160
|
-
width: w_p,
|
|
161
|
-
height: h_p
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
function handle_drag_end(e) {
|
|
165
|
-
if (!position_drag)
|
|
166
|
-
return;
|
|
167
|
-
position_drag = false;
|
|
168
|
-
}
|
|
169
|
-
function handle_dragging(e) {
|
|
170
|
-
if (!position_drag)
|
|
171
|
-
return;
|
|
172
|
-
const x_delta = e.clientX - start_x;
|
|
173
|
-
const y_delta = e.clientY - start_y;
|
|
174
|
-
_left = clamp(
|
|
175
|
-
_left + x_delta,
|
|
176
|
-
$editor_box.child_left - $editor_box.parent_left,
|
|
177
|
-
$editor_box.child_right - $editor_box.parent_left - _width
|
|
178
|
-
);
|
|
179
|
-
_top = clamp(
|
|
180
|
-
_top + y_delta,
|
|
181
|
-
$editor_box.child_top - $editor_box.parent_top,
|
|
182
|
-
$editor_box.child_bottom - $editor_box.parent_top - _height
|
|
183
|
-
);
|
|
184
|
-
_right = _left + _width;
|
|
185
|
-
_bottom = _top + _height;
|
|
186
|
-
l_p = (_left - $editor_box.child_left + $editor_box.parent_left) / $editor_box.child_width;
|
|
187
|
-
t_p = (_top - $editor_box.child_top + $editor_box.parent_top) / $editor_box.child_height;
|
|
188
|
-
start_x = e.clientX;
|
|
189
|
-
start_y = e.clientY;
|
|
190
|
-
dispatch("crop_continue", {
|
|
191
|
-
x: l_p,
|
|
192
|
-
y: t_p,
|
|
193
|
-
width: w_p,
|
|
194
|
-
height: h_p
|
|
195
|
-
});
|
|
196
|
-
triggered = true;
|
|
197
|
-
}
|
|
198
|
-
</script>
|
|
199
|
-
|
|
200
|
-
<svelte:window on:mousemove={handle_dragging} on:mouseup={handle_drag_end} />
|
|
201
|
-
|
|
202
|
-
<div class="wrap">
|
|
203
|
-
<div
|
|
204
|
-
class="box"
|
|
205
|
-
style:width="{_width}px"
|
|
206
|
-
style:height="{_height}px"
|
|
207
|
-
style:top="{_top}px"
|
|
208
|
-
style:left="{_left}px"
|
|
209
|
-
>
|
|
210
|
-
{#each positions as position}
|
|
211
|
-
<Handle
|
|
212
|
-
on:change={({ detail }) => handle_change(detail, position)}
|
|
213
|
-
bind:dragging
|
|
214
|
-
location={position}
|
|
215
|
-
/>
|
|
216
|
-
{/each}
|
|
217
|
-
|
|
218
|
-
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
219
|
-
<div class="grid" class:finished on:mousedown={handle_drag_start}>
|
|
220
|
-
{#each { length: 25 } as _}
|
|
221
|
-
<div></div>
|
|
222
|
-
{/each}
|
|
223
|
-
</div>
|
|
224
|
-
</div>
|
|
225
|
-
</div>
|
|
226
|
-
|
|
227
|
-
<style>
|
|
228
|
-
.grid {
|
|
229
|
-
height: 100%;
|
|
230
|
-
width: 100%;
|
|
231
|
-
display: grid;
|
|
232
|
-
grid-template-rows: 1fr 1px 1fr 1px 1fr;
|
|
233
|
-
grid-template-columns: 1fr 1px 1fr 1px 1fr;
|
|
234
|
-
overflow: hidden;
|
|
235
|
-
transition: 0.2s;
|
|
236
|
-
opacity: 1;
|
|
237
|
-
/* pointer-events: none; */
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
.grid.finished {
|
|
241
|
-
opacity: 0;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
.grid > div {
|
|
245
|
-
width: 100%;
|
|
246
|
-
height: 100%;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
.grid > div:nth-of-type(even) {
|
|
250
|
-
background: black;
|
|
251
|
-
opacity: 0.5;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
.wrap {
|
|
255
|
-
position: absolute;
|
|
256
|
-
top: 0;
|
|
257
|
-
left: 0;
|
|
258
|
-
width: 100%;
|
|
259
|
-
height: 100%;
|
|
260
|
-
|
|
261
|
-
/* transform: translateY(-20px); */
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
.box {
|
|
265
|
-
position: absolute;
|
|
266
|
-
width: 100%;
|
|
267
|
-
height: 100%;
|
|
268
|
-
border: 1px solid black;
|
|
269
|
-
z-index: var(--layer-top);
|
|
270
|
-
}
|
|
271
|
-
</style>
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
|
-
import { type EditorContext } from "../ImageEditor.svelte";
|
|
3
|
-
declare const __propDef: {
|
|
4
|
-
props: {
|
|
5
|
-
editor_box: EditorContext["editor_box"];
|
|
6
|
-
crop_constraint: number | null;
|
|
7
|
-
w_p: number;
|
|
8
|
-
h_p: number;
|
|
9
|
-
l_p: number;
|
|
10
|
-
t_p: number;
|
|
11
|
-
};
|
|
12
|
-
events: {
|
|
13
|
-
crop_start: CustomEvent<{
|
|
14
|
-
x: number;
|
|
15
|
-
y: number;
|
|
16
|
-
width: number;
|
|
17
|
-
height: number;
|
|
18
|
-
}>;
|
|
19
|
-
crop_continue: CustomEvent<{
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
22
|
-
width: number;
|
|
23
|
-
height: number;
|
|
24
|
-
}>;
|
|
25
|
-
crop_end: CustomEvent<{
|
|
26
|
-
x: number;
|
|
27
|
-
y: number;
|
|
28
|
-
width: number;
|
|
29
|
-
height: number;
|
|
30
|
-
}>;
|
|
31
|
-
} & {
|
|
32
|
-
[evt: string]: CustomEvent<any>;
|
|
33
|
-
};
|
|
34
|
-
slots: {};
|
|
35
|
-
};
|
|
36
|
-
export type CropperProps = typeof __propDef.props;
|
|
37
|
-
export type CropperEvents = typeof __propDef.events;
|
|
38
|
-
export type CropperSlots = typeof __propDef.slots;
|
|
39
|
-
export default class Cropper extends SvelteComponent<CropperProps, CropperEvents, CropperSlots> {
|
|
40
|
-
}
|
|
41
|
-
export {};
|