@pixerate/editor-svelte 0.13.0 → 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/dist/chunk-REI5FZ7F.js +966 -0
- package/dist/chunk-REI5FZ7F.js.map +1 -0
- package/dist/image-editor/index.d.ts +16 -0
- package/dist/image-editor/index.js +9 -0
- package/dist/image-editor/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -2
- package/src/image-editor/ImageEditor.svelte +1119 -0
- package/src/image-editor/imageEditorState.svelte.ts +139 -0
- package/src/image-editor/index.d.ts +16 -0
- package/src/image-editor/index.ts +2 -0
- package/src/index.d.ts +2 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,966 @@
|
|
|
1
|
+
// src/image-editor/ImageEditor.svelte
|
|
2
|
+
import "svelte/internal/disclose-version";
|
|
3
|
+
import * as $2 from "svelte/internal/client";
|
|
4
|
+
import {
|
|
5
|
+
canvasToImagePoint,
|
|
6
|
+
hitTestCrop,
|
|
7
|
+
getCropCursor,
|
|
8
|
+
calculateCropDrag,
|
|
9
|
+
hitTestAnnotation
|
|
10
|
+
} from "@pixerate/editor";
|
|
11
|
+
|
|
12
|
+
// src/image-editor/imageEditorState.svelte.ts
|
|
13
|
+
import * as $ from "svelte/internal/client";
|
|
14
|
+
import { ImageEditorController } from "@pixerate/editor";
|
|
15
|
+
function createReactiveImageEditor(options = {}) {
|
|
16
|
+
const controller = new ImageEditorController(options);
|
|
17
|
+
let state3 = $.state($.proxy(controller.getState()));
|
|
18
|
+
let historyTicks = $.state(0);
|
|
19
|
+
controller.subscribe((updated) => {
|
|
20
|
+
$.set(state3, { ...updated }, true);
|
|
21
|
+
$.update(historyTicks);
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
get controller() {
|
|
25
|
+
return controller;
|
|
26
|
+
},
|
|
27
|
+
get state() {
|
|
28
|
+
return $.get(state3);
|
|
29
|
+
},
|
|
30
|
+
get canUndo() {
|
|
31
|
+
void $.get(historyTicks);
|
|
32
|
+
return controller.canUndo;
|
|
33
|
+
},
|
|
34
|
+
get canRedo() {
|
|
35
|
+
void $.get(historyTicks);
|
|
36
|
+
return controller.canRedo;
|
|
37
|
+
},
|
|
38
|
+
setTool(tool) {
|
|
39
|
+
controller.setTool(tool);
|
|
40
|
+
},
|
|
41
|
+
setCrop(crop, addToHistory = true) {
|
|
42
|
+
controller.setCrop(crop, addToHistory);
|
|
43
|
+
},
|
|
44
|
+
applyCropPreset(ratio) {
|
|
45
|
+
controller.applyCropPreset(ratio);
|
|
46
|
+
},
|
|
47
|
+
resetCrop() {
|
|
48
|
+
controller.resetCrop();
|
|
49
|
+
},
|
|
50
|
+
rotate(degrees) {
|
|
51
|
+
controller.rotate(degrees);
|
|
52
|
+
},
|
|
53
|
+
setRotation(degrees) {
|
|
54
|
+
controller.setRotation(degrees);
|
|
55
|
+
},
|
|
56
|
+
flipHorizontal() {
|
|
57
|
+
controller.flipHorizontal();
|
|
58
|
+
},
|
|
59
|
+
flipVertical() {
|
|
60
|
+
controller.flipVertical();
|
|
61
|
+
},
|
|
62
|
+
setAdjustments(partial, commitToHistory = true) {
|
|
63
|
+
controller.setAdjustments(partial, commitToHistory);
|
|
64
|
+
},
|
|
65
|
+
resetAdjustments() {
|
|
66
|
+
controller.resetAdjustments();
|
|
67
|
+
},
|
|
68
|
+
setDepthMask(partial) {
|
|
69
|
+
controller.setDepthMask(partial);
|
|
70
|
+
},
|
|
71
|
+
resetDepthMask() {
|
|
72
|
+
controller.resetDepthMask();
|
|
73
|
+
},
|
|
74
|
+
addAnnotation(ann) {
|
|
75
|
+
return controller.addAnnotation(ann);
|
|
76
|
+
},
|
|
77
|
+
updateAnnotation(id, partial, commitToHistory = true) {
|
|
78
|
+
controller.updateAnnotation(id, partial, commitToHistory);
|
|
79
|
+
},
|
|
80
|
+
removeAnnotation(id) {
|
|
81
|
+
controller.removeAnnotation(id);
|
|
82
|
+
},
|
|
83
|
+
clearAnnotations() {
|
|
84
|
+
controller.clearAnnotations();
|
|
85
|
+
},
|
|
86
|
+
selectAnnotation(id) {
|
|
87
|
+
controller.selectAnnotation(id);
|
|
88
|
+
},
|
|
89
|
+
undo() {
|
|
90
|
+
return controller.undo();
|
|
91
|
+
},
|
|
92
|
+
redo() {
|
|
93
|
+
return controller.redo();
|
|
94
|
+
},
|
|
95
|
+
reset() {
|
|
96
|
+
controller.reset();
|
|
97
|
+
},
|
|
98
|
+
zoomIn(factor) {
|
|
99
|
+
controller.zoomIn(factor);
|
|
100
|
+
},
|
|
101
|
+
zoomOut(factor) {
|
|
102
|
+
controller.zoomOut(factor);
|
|
103
|
+
},
|
|
104
|
+
resetZoom() {
|
|
105
|
+
controller.resetZoom();
|
|
106
|
+
},
|
|
107
|
+
setZoom(zoom) {
|
|
108
|
+
controller.setZoom(zoom);
|
|
109
|
+
},
|
|
110
|
+
setPan(pan) {
|
|
111
|
+
controller.setPan(pan);
|
|
112
|
+
},
|
|
113
|
+
setComparing(comparing) {
|
|
114
|
+
controller.setComparing(comparing);
|
|
115
|
+
},
|
|
116
|
+
loadImage(src) {
|
|
117
|
+
return controller.loadImage(src);
|
|
118
|
+
},
|
|
119
|
+
toDataURL(opts) {
|
|
120
|
+
return controller.toDataURL(opts);
|
|
121
|
+
},
|
|
122
|
+
toBlob(opts) {
|
|
123
|
+
return controller.toBlob(opts);
|
|
124
|
+
},
|
|
125
|
+
toJSON() {
|
|
126
|
+
return controller.toJSON();
|
|
127
|
+
},
|
|
128
|
+
loadJSON(data) {
|
|
129
|
+
controller.loadJSON(data);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/image-editor/ImageEditor.svelte
|
|
135
|
+
var root = $2.from_html(`<div class="flex flex-col gap-4 text-xs"><span class="font-semibold text-slate-200 uppercase tracking-wider text-[11px]">Aspect Ratio Presets</span> <div class="grid grid-cols-3 gap-2"><button type="button">Freeform</button> <button type="button">1:1 Square</button> <button type="button">4:3 Standard</button> <button type="button">16:9 Wide</button> <button type="button">3:2 Photo</button> <button type="button" class="px-2.5 py-2 rounded-lg bg-rose-950/40 hover:bg-rose-900/60 text-rose-300 border border-rose-800/40 font-medium">Clear Crop</button></div> <div class="h-px bg-slate-800 my-1"></div> <span class="font-semibold text-slate-200 uppercase tracking-wider text-[11px]">Orientation & Flips</span> <div class="grid grid-cols-2 gap-2"><button type="button" class="px-3 py-2 rounded-lg bg-slate-800 hover:bg-slate-700 text-slate-200 border border-slate-700">Rotate -90\xB0</button> <button type="button" class="px-3 py-2 rounded-lg bg-slate-800 hover:bg-slate-700 text-slate-200 border border-slate-700">Rotate +90\xB0</button> <button type="button">Flip Horizontal</button> <button type="button">Flip Vertical</button></div></div>`);
|
|
136
|
+
var root_1 = $2.from_html(`<div class="flex flex-col gap-3 text-xs"><div class="flex items-center justify-between"><span class="font-semibold text-slate-200 uppercase tracking-wider text-[11px]">Color Adjustments</span> <button type="button" class="text-[10px] text-rose-400 hover:underline">Reset Sliders</button></div> <div><div class="flex justify-between text-slate-400 mb-1"><span>Brightness</span> <span class="font-mono"> </span></div> <input type="range" min="-100" max="100" class="w-full accent-indigo-500"/></div> <div><div class="flex justify-between text-slate-400 mb-1"><span>Contrast</span> <span class="font-mono"> </span></div> <input type="range" min="-100" max="100" class="w-full accent-indigo-500"/></div> <div><div class="flex justify-between text-slate-400 mb-1"><span>Saturation</span> <span class="font-mono"> </span></div> <input type="range" min="-100" max="100" class="w-full accent-indigo-500"/></div> <div><div class="flex justify-between text-slate-400 mb-1"><span>Exposure</span> <span class="font-mono"> </span></div> <input type="range" min="-100" max="100" class="w-full accent-indigo-500"/></div> <div><div class="flex justify-between text-slate-400 mb-1"><span>Warmth / Temperature</span> <span class="font-mono"> </span></div> <input type="range" min="-100" max="100" class="w-full accent-indigo-500"/></div> <div><div class="flex justify-between text-slate-400 mb-1"><span>Blur</span> <span class="font-mono"> </span></div> <input type="range" min="0" max="30" class="w-full accent-indigo-500"/></div> <div><div class="flex justify-between text-slate-400 mb-1"><span>Opacity</span> <span class="font-mono"> </span></div> <input type="range" min="0" max="1" step="0.05" class="w-full accent-indigo-500"/></div></div>`);
|
|
137
|
+
var root_2 = $2.from_html(`<button type="button"> </button>`);
|
|
138
|
+
var root_3 = $2.from_html(`<button type="button" class="text-rose-400 hover:underline text-[11px]">Delete Selected</button>`);
|
|
139
|
+
var root_4 = $2.from_html(`<button type="button" class="text-slate-400 hover:text-slate-200 text-[11px]">Clear All</button>`);
|
|
140
|
+
var root_5 = $2.from_html(`<div class="flex flex-col gap-3 text-xs"><span class="font-semibold text-slate-200 uppercase tracking-wider text-[11px]">Draw & Annotate</span> <div class="grid grid-cols-3 gap-1.5"></div> <div class="flex items-center gap-2 mt-2"><span class="text-slate-400">Color:</span> <input type="color" class="w-8 h-8 rounded border border-slate-700 cursor-pointer bg-transparent"/> <div class="flex-1 ml-2"><div class="flex justify-between text-slate-400 mb-0.5"><span>Width:</span> <span class="font-mono"> </span></div> <input type="range" min="1" max="20" class="w-full accent-indigo-500"/></div></div> <div class="h-px bg-slate-800 my-1"></div> <span class="font-semibold text-slate-200 uppercase tracking-wider text-[11px]">Add Text</span> <div class="flex gap-2"><input type="text" placeholder="Type watermark or label..." class="flex-1 bg-slate-950 border border-slate-700 rounded-lg px-2.5 py-1.5 text-xs text-slate-100 placeholder-slate-500 focus:outline-none focus:border-indigo-500"/> <button type="button" class="px-3 py-1.5 rounded-lg bg-indigo-600 hover:bg-indigo-500 text-white font-medium shadow">Add</button></div> <div class="flex items-center justify-between text-slate-400"><span>Font Size:</span> <span class="font-mono"> </span></div> <input type="range" min="12" max="72" class="w-full accent-indigo-500"/> <div class="h-px bg-slate-800 my-1"></div> <div class="flex items-center justify-between"><span class="text-slate-400"> </span> <!> <!></div></div>`);
|
|
141
|
+
var root_6 = $2.from_html(`<div><span class="text-slate-400 block mb-1">Mask Image URL:</span> <input type="text" placeholder="https://.../depthmap.png" class="w-full bg-slate-950 border border-slate-700 rounded-lg px-2.5 py-1.5 text-xs text-slate-100 placeholder-slate-500"/></div> <div class="flex gap-2"><button type="button">Threshold Mode</button> <button type="button">Brightness Mode</button></div> <div><div class="flex justify-between text-slate-400 mb-1"><span>Depth Start (Lower):</span> <span class="font-mono"> </span></div> <input type="range" min="0" max="255" class="w-full accent-indigo-500"/></div> <div><div class="flex justify-between text-slate-400 mb-1"><span>Depth Stop (Upper):</span> <span class="font-mono"> </span></div> <input type="range" min="0" max="255" class="w-full accent-indigo-500"/></div> <div><div class="flex justify-between text-slate-400 mb-1"><span>Softness:</span> <span class="font-mono"> </span></div> <input type="range" min="1" max="50" class="w-full accent-indigo-500"/></div> <label class="flex items-center gap-2 cursor-pointer text-slate-300 mt-1"><input type="checkbox" class="rounded accent-indigo-500"/> <span>Invert Mask</span></label>`, 1);
|
|
142
|
+
var root_7 = $2.from_html(`<div class="flex flex-col gap-3 text-xs"><div class="flex items-center justify-between"><span class="font-semibold text-slate-200 uppercase tracking-wider text-[11px]">Depth Masking</span> <button type="button" class="text-[10px] text-rose-400 hover:underline">Reset Mask</button></div> <label class="flex items-center gap-2 cursor-pointer text-slate-300"><input type="checkbox" class="rounded accent-indigo-500"/> <span>Enable Depth / Alpha Mask</span></label> <!></div>`);
|
|
143
|
+
var root_8 = $2.from_html(`<div><div class="flex flex-wrap items-center justify-between px-4 py-3 bg-slate-950/80 border-b border-slate-800 gap-3"><div class="flex items-center gap-1 bg-slate-900 p-1 rounded-lg border border-slate-800 text-xs"><button type="button">Transform & Crop</button> <button type="button">Adjustments</button> <button type="button">Annotations</button> <button type="button">Depth Mask</button></div> <div class="flex items-center gap-2 text-xs"><button type="button" class="p-1.5 rounded-lg border border-slate-800 bg-slate-900 text-slate-300 disabled:opacity-40 disabled:cursor-not-allowed hover:bg-slate-800" title="Undo">\u21A9</button> <button type="button" class="p-1.5 rounded-lg border border-slate-800 bg-slate-900 text-slate-300 disabled:opacity-40 disabled:cursor-not-allowed hover:bg-slate-800" title="Redo">\u21AA</button> <button type="button" class="px-2 py-1.5 rounded-lg border border-slate-800 bg-slate-900 text-slate-400 hover:text-slate-200 hover:bg-slate-800">Reset</button> <div class="h-4 w-px bg-slate-800 mx-1"></div> <button type="button" class="p-1.5 rounded-lg border border-slate-800 bg-slate-900 text-slate-300 hover:bg-slate-800" title="Zoom Out">-</button> <span class="font-mono text-slate-400 w-10 text-center"> </span> <button type="button" class="p-1.5 rounded-lg border border-slate-800 bg-slate-900 text-slate-300 hover:bg-slate-800" title="Zoom In">+</button> <div class="h-4 w-px bg-slate-800 mx-1"></div> <button type="button" class="px-2.5 py-1.5 rounded-lg border border-slate-800 bg-slate-900 text-amber-400 hover:bg-slate-800 select-none active:bg-amber-950/40">Hold Compare</button> <button type="button" class="px-4 py-1.5 rounded-lg bg-emerald-600 hover:bg-emerald-500 text-white font-medium shadow-md shadow-emerald-900/30 transition-colors">Export Image</button></div></div> <div class="flex flex-col md:flex-row flex-1 min-h-[520px] md:h-[560px]"><div class="relative flex-1 h-[360px] md:h-full min-h-[320px] bg-slate-950 overflow-hidden select-none"><canvas class="absolute inset-0 w-full h-full block"></canvas></div> <div class="w-full md:w-80 bg-slate-900/90 border-t md:border-t-0 md:border-l border-slate-800 p-4 overflow-y-auto h-auto md:h-full md:max-h-[560px]"><!> <!> <!> <!></div></div></div>`);
|
|
144
|
+
function ImageEditor($$anchor, $$props) {
|
|
145
|
+
$2.push($$props, true);
|
|
146
|
+
let src = $2.prop($$props, "src", 3, ""), className = $2.prop($$props, "class", 3, ""), style = $2.prop($$props, "style", 3, "");
|
|
147
|
+
const internalEditor = createReactiveImageEditor();
|
|
148
|
+
const editor = $2.derived(() => $$props.editor || internalEditor);
|
|
149
|
+
let canvasEl = $2.state(null);
|
|
150
|
+
let containerEl = $2.state(null);
|
|
151
|
+
let activeTab = $2.state("crop");
|
|
152
|
+
let activeCropRatio = $2.state(null);
|
|
153
|
+
let activeColor = $2.state("#ef4444");
|
|
154
|
+
let strokeWidth = $2.state(3);
|
|
155
|
+
let fontSize = $2.state(24);
|
|
156
|
+
let textInput = $2.state("");
|
|
157
|
+
let draftAnnotation = $2.state(null);
|
|
158
|
+
let draftCrop = $2.state(null);
|
|
159
|
+
let cropDragInfo = null;
|
|
160
|
+
let annotationDragInfo = null;
|
|
161
|
+
let isDrawing = false;
|
|
162
|
+
let currentPath = [];
|
|
163
|
+
let dragStartPoint = null;
|
|
164
|
+
$2.user_effect(() => {
|
|
165
|
+
if (src() && src() !== $2.get(editor).state.sourceUrl) {
|
|
166
|
+
$2.get(editor).loadImage(src());
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
async function renderCanvas(overrideAnnotation, overrideCrop) {
|
|
170
|
+
if (!$2.get(canvasEl) || !$2.get(containerEl)) return;
|
|
171
|
+
const vpWidth = $2.get(containerEl).clientWidth || 800;
|
|
172
|
+
const vpHeight = $2.get(containerEl).clientHeight || 500;
|
|
173
|
+
await $2.get(editor).controller.render($2.get(canvasEl), {
|
|
174
|
+
viewportWidth: vpWidth,
|
|
175
|
+
viewportHeight: vpHeight,
|
|
176
|
+
showCropOverlay: $2.get(activeTab) === "crop",
|
|
177
|
+
showSelectionOverlay: true,
|
|
178
|
+
interactive: true,
|
|
179
|
+
draftAnnotation: overrideAnnotation !== void 0 ? overrideAnnotation : $2.get(draftAnnotation),
|
|
180
|
+
draftCrop: overrideCrop !== void 0 ? overrideCrop : $2.get(draftCrop)
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
$2.user_effect(() => {
|
|
184
|
+
void $2.get(editor).state;
|
|
185
|
+
void $2.get(activeTab);
|
|
186
|
+
const raf = typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : (cb) => setTimeout(cb, 0);
|
|
187
|
+
const caf = typeof cancelAnimationFrame !== "undefined" ? cancelAnimationFrame : (id) => clearTimeout(id);
|
|
188
|
+
const animId = raf(() => {
|
|
189
|
+
renderCanvas();
|
|
190
|
+
});
|
|
191
|
+
return () => caf(animId);
|
|
192
|
+
});
|
|
193
|
+
$2.user_effect(() => {
|
|
194
|
+
if ($2.get(activeTab) === "crop" && $2.get(editor).state.activeTool !== "crop") {
|
|
195
|
+
$2.get(editor).setTool("crop");
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
$2.user_effect(() => {
|
|
199
|
+
if (!$2.get(containerEl)) return;
|
|
200
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
201
|
+
const observer = new ResizeObserver(() => {
|
|
202
|
+
renderCanvas();
|
|
203
|
+
});
|
|
204
|
+
observer.observe($2.get(containerEl));
|
|
205
|
+
return () => observer.disconnect();
|
|
206
|
+
} else {
|
|
207
|
+
const handleResize = () => renderCanvas();
|
|
208
|
+
window.addEventListener("resize", handleResize);
|
|
209
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
function getCanvasEventPoint(e) {
|
|
213
|
+
if (!$2.get(canvasEl)) return { x: 0, y: 0 };
|
|
214
|
+
const rect = $2.get(canvasEl).getBoundingClientRect();
|
|
215
|
+
const scaleX = rect.width > 0 ? $2.get(canvasEl).width / rect.width : 1;
|
|
216
|
+
const scaleY = rect.height > 0 ? $2.get(canvasEl).height / rect.height : 1;
|
|
217
|
+
return {
|
|
218
|
+
x: (e.clientX - rect.left) * scaleX,
|
|
219
|
+
y: (e.clientY - rect.top) * scaleY
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function handleMouseDown(e) {
|
|
223
|
+
if (!$2.get(canvasEl)) return;
|
|
224
|
+
const canvasPt = getCanvasEventPoint(e);
|
|
225
|
+
if ($2.get(activeTab) === "crop") {
|
|
226
|
+
const activeCrop = $2.get(draftCrop) || $2.get(editor).state.crop || {
|
|
227
|
+
x: 0,
|
|
228
|
+
y: 0,
|
|
229
|
+
width: $2.get(editor).state.imageDimensions.width,
|
|
230
|
+
height: $2.get(editor).state.imageDimensions.height
|
|
231
|
+
};
|
|
232
|
+
const handle = hitTestCrop(canvasPt, $2.get(editor).state, $2.get(canvasEl).width, $2.get(canvasEl).height, 14, activeCrop);
|
|
233
|
+
const startImgPt = canvasToImagePoint(canvasPt, $2.get(editor).state, $2.get(canvasEl).width, $2.get(canvasEl).height, true);
|
|
234
|
+
if (handle) {
|
|
235
|
+
cropDragInfo = {
|
|
236
|
+
handle,
|
|
237
|
+
startCanvasPt: canvasPt,
|
|
238
|
+
startImgPt,
|
|
239
|
+
startCrop: activeCrop
|
|
240
|
+
};
|
|
241
|
+
} else {
|
|
242
|
+
cropDragInfo = {
|
|
243
|
+
handle: "new",
|
|
244
|
+
startCanvasPt: canvasPt,
|
|
245
|
+
startImgPt,
|
|
246
|
+
startCrop: { x: startImgPt.x, y: startImgPt.y, width: 0, height: 0 }
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if ($2.get(activeTab) === "annotate") {
|
|
252
|
+
const imgPt = canvasToImagePoint(canvasPt, $2.get(editor).state, $2.get(canvasEl).width, $2.get(canvasEl).height, false);
|
|
253
|
+
dragStartPoint = imgPt;
|
|
254
|
+
if ($2.get(editor).state.activeTool === "select") {
|
|
255
|
+
for (let i = $2.get(editor).state.annotations.length - 1; i >= 0; i--) {
|
|
256
|
+
const ann = $2.get(editor).state.annotations[i];
|
|
257
|
+
if (hitTestAnnotation(imgPt, ann)) {
|
|
258
|
+
$2.get(editor).selectAnnotation(ann.id);
|
|
259
|
+
annotationDragInfo = { annId: ann.id, startImgPt: imgPt, initialAnn: { ...ann } };
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
$2.get(editor).selectAnnotation(null);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if ($2.get(editor).state.activeTool === "pen") {
|
|
267
|
+
isDrawing = true;
|
|
268
|
+
currentPath = [imgPt];
|
|
269
|
+
const draft = {
|
|
270
|
+
id: "draft",
|
|
271
|
+
type: "pen",
|
|
272
|
+
x: 0,
|
|
273
|
+
y: 0,
|
|
274
|
+
points: [imgPt],
|
|
275
|
+
strokeColor: $2.get(activeColor),
|
|
276
|
+
strokeWidth: $2.get(strokeWidth)
|
|
277
|
+
};
|
|
278
|
+
$2.set(draftAnnotation, draft, true);
|
|
279
|
+
renderCanvas(draft);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function handleMouseMove(e) {
|
|
284
|
+
if (!$2.get(canvasEl)) return;
|
|
285
|
+
const canvasPt = getCanvasEventPoint(e);
|
|
286
|
+
if ($2.get(activeTab) === "crop") {
|
|
287
|
+
if (cropDragInfo) {
|
|
288
|
+
const currentImgPt = canvasToImagePoint(canvasPt, $2.get(editor).state, $2.get(canvasEl).width, $2.get(canvasEl).height, true);
|
|
289
|
+
let newCrop;
|
|
290
|
+
if (cropDragInfo.handle === "new") {
|
|
291
|
+
const minX = Math.max(0, Math.min(cropDragInfo.startImgPt.x, currentImgPt.x));
|
|
292
|
+
const minY = Math.max(0, Math.min(cropDragInfo.startImgPt.y, currentImgPt.y));
|
|
293
|
+
const maxX = Math.min($2.get(editor).state.imageDimensions.width, Math.max(cropDragInfo.startImgPt.x, currentImgPt.x));
|
|
294
|
+
const maxY = Math.min($2.get(editor).state.imageDimensions.height, Math.max(cropDragInfo.startImgPt.y, currentImgPt.y));
|
|
295
|
+
newCrop = {
|
|
296
|
+
x: Math.round(minX),
|
|
297
|
+
y: Math.round(minY),
|
|
298
|
+
width: Math.round(Math.max(20, maxX - minX)),
|
|
299
|
+
height: Math.round(Math.max(20, maxY - minY))
|
|
300
|
+
};
|
|
301
|
+
} else {
|
|
302
|
+
newCrop = calculateCropDrag(cropDragInfo.startCrop, cropDragInfo.handle, cropDragInfo.startImgPt, currentImgPt, $2.get(editor).state.imageDimensions.width, $2.get(editor).state.imageDimensions.height, $2.get(activeCropRatio));
|
|
303
|
+
}
|
|
304
|
+
$2.set(draftCrop, newCrop, true);
|
|
305
|
+
renderCanvas(null, newCrop);
|
|
306
|
+
} else {
|
|
307
|
+
const activeCrop = $2.get(draftCrop) || $2.get(editor).state.crop || {
|
|
308
|
+
x: 0,
|
|
309
|
+
y: 0,
|
|
310
|
+
width: $2.get(editor).state.imageDimensions.width,
|
|
311
|
+
height: $2.get(editor).state.imageDimensions.height
|
|
312
|
+
};
|
|
313
|
+
const handle = hitTestCrop(canvasPt, $2.get(editor).state, $2.get(canvasEl).width, $2.get(canvasEl).height, 14, activeCrop);
|
|
314
|
+
$2.get(canvasEl).style.cursor = getCropCursor(handle);
|
|
315
|
+
}
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if ($2.get(activeTab) === "annotate") {
|
|
319
|
+
if (annotationDragInfo) {
|
|
320
|
+
const currentImgPt2 = canvasToImagePoint(canvasPt, $2.get(editor).state, $2.get(canvasEl).width, $2.get(canvasEl).height, false);
|
|
321
|
+
const dx = currentImgPt2.x - annotationDragInfo.startImgPt.x;
|
|
322
|
+
const dy = currentImgPt2.y - annotationDragInfo.startImgPt.y;
|
|
323
|
+
$2.get(editor).updateAnnotation(annotationDragInfo.annId, {
|
|
324
|
+
x: Math.round(annotationDragInfo.initialAnn.x + dx),
|
|
325
|
+
y: Math.round(annotationDragInfo.initialAnn.y + dy)
|
|
326
|
+
});
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (!dragStartPoint) {
|
|
330
|
+
if ($2.get(editor).state.activeTool === "select") {
|
|
331
|
+
const imgPt = canvasToImagePoint(canvasPt, $2.get(editor).state, $2.get(canvasEl).width, $2.get(canvasEl).height, false);
|
|
332
|
+
let hovered = false;
|
|
333
|
+
for (let i = $2.get(editor).state.annotations.length - 1; i >= 0; i--) {
|
|
334
|
+
if (hitTestAnnotation(imgPt, $2.get(editor).state.annotations[i])) {
|
|
335
|
+
hovered = true;
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
$2.get(canvasEl).style.cursor = hovered ? "move" : "default";
|
|
340
|
+
} else {
|
|
341
|
+
$2.get(canvasEl).style.cursor = "crosshair";
|
|
342
|
+
}
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const currentImgPt = canvasToImagePoint(canvasPt, $2.get(editor).state, $2.get(canvasEl).width, $2.get(canvasEl).height, false);
|
|
346
|
+
if ($2.get(editor).state.activeTool === "pen" && isDrawing) {
|
|
347
|
+
currentPath.push(currentImgPt);
|
|
348
|
+
const draft = {
|
|
349
|
+
id: "draft",
|
|
350
|
+
type: "pen",
|
|
351
|
+
x: 0,
|
|
352
|
+
y: 0,
|
|
353
|
+
points: [...currentPath],
|
|
354
|
+
strokeColor: $2.get(activeColor),
|
|
355
|
+
strokeWidth: $2.get(strokeWidth)
|
|
356
|
+
};
|
|
357
|
+
$2.set(draftAnnotation, draft, true);
|
|
358
|
+
renderCanvas(draft);
|
|
359
|
+
} else if ($2.get(editor).state.activeTool === "rect") {
|
|
360
|
+
const w = currentImgPt.x - dragStartPoint.x;
|
|
361
|
+
const h = currentImgPt.y - dragStartPoint.y;
|
|
362
|
+
const draft = {
|
|
363
|
+
id: "draft",
|
|
364
|
+
type: "rect",
|
|
365
|
+
x: Math.min(dragStartPoint.x, currentImgPt.x),
|
|
366
|
+
y: Math.min(dragStartPoint.y, currentImgPt.y),
|
|
367
|
+
width: Math.abs(w),
|
|
368
|
+
height: Math.abs(h),
|
|
369
|
+
strokeColor: $2.get(activeColor),
|
|
370
|
+
strokeWidth: $2.get(strokeWidth)
|
|
371
|
+
};
|
|
372
|
+
$2.set(draftAnnotation, draft, true);
|
|
373
|
+
renderCanvas(draft);
|
|
374
|
+
} else if ($2.get(editor).state.activeTool === "circle") {
|
|
375
|
+
const rx = Math.abs(currentImgPt.x - dragStartPoint.x) / 2;
|
|
376
|
+
const ry = Math.abs(currentImgPt.y - dragStartPoint.y) / 2;
|
|
377
|
+
const draft = {
|
|
378
|
+
id: "draft",
|
|
379
|
+
type: "circle",
|
|
380
|
+
x: Math.min(dragStartPoint.x, currentImgPt.x) + rx,
|
|
381
|
+
y: Math.min(dragStartPoint.y, currentImgPt.y) + ry,
|
|
382
|
+
radiusX: rx,
|
|
383
|
+
radiusY: ry,
|
|
384
|
+
strokeColor: $2.get(activeColor),
|
|
385
|
+
strokeWidth: $2.get(strokeWidth)
|
|
386
|
+
};
|
|
387
|
+
$2.set(draftAnnotation, draft, true);
|
|
388
|
+
renderCanvas(draft);
|
|
389
|
+
} else if ($2.get(editor).state.activeTool === "arrow") {
|
|
390
|
+
const draft = {
|
|
391
|
+
id: "draft",
|
|
392
|
+
type: "arrow",
|
|
393
|
+
x: dragStartPoint.x,
|
|
394
|
+
y: dragStartPoint.y,
|
|
395
|
+
endX: currentImgPt.x,
|
|
396
|
+
endY: currentImgPt.y,
|
|
397
|
+
strokeColor: $2.get(activeColor),
|
|
398
|
+
strokeWidth: $2.get(strokeWidth)
|
|
399
|
+
};
|
|
400
|
+
$2.set(draftAnnotation, draft, true);
|
|
401
|
+
renderCanvas(draft);
|
|
402
|
+
} else if ($2.get(editor).state.activeTool === "line") {
|
|
403
|
+
const draft = {
|
|
404
|
+
id: "draft",
|
|
405
|
+
type: "line",
|
|
406
|
+
x: dragStartPoint.x,
|
|
407
|
+
y: dragStartPoint.y,
|
|
408
|
+
endX: currentImgPt.x,
|
|
409
|
+
endY: currentImgPt.y,
|
|
410
|
+
strokeColor: $2.get(activeColor),
|
|
411
|
+
strokeWidth: $2.get(strokeWidth)
|
|
412
|
+
};
|
|
413
|
+
$2.set(draftAnnotation, draft, true);
|
|
414
|
+
renderCanvas(draft);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function handleMouseUp(e) {
|
|
419
|
+
if (!$2.get(canvasEl)) return;
|
|
420
|
+
const canvasPt = getCanvasEventPoint(e);
|
|
421
|
+
if ($2.get(activeTab) === "crop") {
|
|
422
|
+
if (cropDragInfo) {
|
|
423
|
+
if ($2.get(draftCrop) && $2.get(draftCrop).width >= 20 && $2.get(draftCrop).height >= 20) {
|
|
424
|
+
$2.get(editor).setCrop($2.get(draftCrop), true);
|
|
425
|
+
}
|
|
426
|
+
cropDragInfo = null;
|
|
427
|
+
$2.set(draftCrop, null);
|
|
428
|
+
renderCanvas();
|
|
429
|
+
}
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if ($2.get(activeTab) === "annotate") {
|
|
433
|
+
if (annotationDragInfo) {
|
|
434
|
+
annotationDragInfo = null;
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (dragStartPoint) {
|
|
438
|
+
const currentImgPt = canvasToImagePoint(canvasPt, $2.get(editor).state, $2.get(canvasEl).width, $2.get(canvasEl).height, false);
|
|
439
|
+
if ($2.get(editor).state.activeTool === "pen" && isDrawing) {
|
|
440
|
+
if (currentPath.length > 1) {
|
|
441
|
+
$2.get(editor).addAnnotation({
|
|
442
|
+
type: "pen",
|
|
443
|
+
x: 0,
|
|
444
|
+
y: 0,
|
|
445
|
+
points: [...currentPath],
|
|
446
|
+
strokeColor: $2.get(activeColor),
|
|
447
|
+
strokeWidth: $2.get(strokeWidth)
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
isDrawing = false;
|
|
451
|
+
currentPath = [];
|
|
452
|
+
} else if ($2.get(editor).state.activeTool === "rect") {
|
|
453
|
+
const w = Math.abs(currentImgPt.x - dragStartPoint.x);
|
|
454
|
+
const h = Math.abs(currentImgPt.y - dragStartPoint.y);
|
|
455
|
+
if (w > 4 && h > 4) {
|
|
456
|
+
$2.get(editor).addAnnotation({
|
|
457
|
+
type: "rect",
|
|
458
|
+
x: Math.min(dragStartPoint.x, currentImgPt.x),
|
|
459
|
+
y: Math.min(dragStartPoint.y, currentImgPt.y),
|
|
460
|
+
width: w,
|
|
461
|
+
height: h,
|
|
462
|
+
strokeColor: $2.get(activeColor),
|
|
463
|
+
strokeWidth: $2.get(strokeWidth)
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
} else if ($2.get(editor).state.activeTool === "circle") {
|
|
467
|
+
const rx = Math.abs(currentImgPt.x - dragStartPoint.x) / 2;
|
|
468
|
+
const ry = Math.abs(currentImgPt.y - dragStartPoint.y) / 2;
|
|
469
|
+
if (rx > 4 && ry > 4) {
|
|
470
|
+
$2.get(editor).addAnnotation({
|
|
471
|
+
type: "circle",
|
|
472
|
+
x: Math.min(dragStartPoint.x, currentImgPt.x) + rx,
|
|
473
|
+
y: Math.min(dragStartPoint.y, currentImgPt.y) + ry,
|
|
474
|
+
radiusX: rx,
|
|
475
|
+
radiusY: ry,
|
|
476
|
+
strokeColor: $2.get(activeColor),
|
|
477
|
+
strokeWidth: $2.get(strokeWidth)
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
} else if ($2.get(editor).state.activeTool === "arrow") {
|
|
481
|
+
if (Math.hypot(currentImgPt.x - dragStartPoint.x, currentImgPt.y - dragStartPoint.y) > 4) {
|
|
482
|
+
$2.get(editor).addAnnotation({
|
|
483
|
+
type: "arrow",
|
|
484
|
+
x: dragStartPoint.x,
|
|
485
|
+
y: dragStartPoint.y,
|
|
486
|
+
endX: currentImgPt.x,
|
|
487
|
+
endY: currentImgPt.y,
|
|
488
|
+
strokeColor: $2.get(activeColor),
|
|
489
|
+
strokeWidth: $2.get(strokeWidth)
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
} else if ($2.get(editor).state.activeTool === "line") {
|
|
493
|
+
if (Math.hypot(currentImgPt.x - dragStartPoint.x, currentImgPt.y - dragStartPoint.y) > 4) {
|
|
494
|
+
$2.get(editor).addAnnotation({
|
|
495
|
+
type: "line",
|
|
496
|
+
x: dragStartPoint.x,
|
|
497
|
+
y: dragStartPoint.y,
|
|
498
|
+
endX: currentImgPt.x,
|
|
499
|
+
endY: currentImgPt.y,
|
|
500
|
+
strokeColor: $2.get(activeColor),
|
|
501
|
+
strokeWidth: $2.get(strokeWidth)
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
$2.set(draftAnnotation, null);
|
|
506
|
+
dragStartPoint = null;
|
|
507
|
+
renderCanvas();
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function handleAddText() {
|
|
512
|
+
if (!$2.get(textInput).trim()) return;
|
|
513
|
+
$2.get(editor).addAnnotation({
|
|
514
|
+
type: "text",
|
|
515
|
+
x: 50,
|
|
516
|
+
y: 50,
|
|
517
|
+
text: $2.get(textInput).trim(),
|
|
518
|
+
fontSize: $2.get(fontSize),
|
|
519
|
+
color: $2.get(activeColor)
|
|
520
|
+
});
|
|
521
|
+
$2.set(textInput, "");
|
|
522
|
+
}
|
|
523
|
+
async function handleExport() {
|
|
524
|
+
const dataUrl = await $2.get(editor).toDataURL($$props.exportOptions);
|
|
525
|
+
if ($$props.onSave) {
|
|
526
|
+
$$props.onSave(dataUrl);
|
|
527
|
+
} else {
|
|
528
|
+
const link = document.createElement("a");
|
|
529
|
+
link.download = `edited-image-${Date.now()}.png`;
|
|
530
|
+
link.href = dataUrl;
|
|
531
|
+
link.click();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
var div = root_8();
|
|
535
|
+
var div_1 = $2.child(div);
|
|
536
|
+
var div_2 = $2.child(div_1);
|
|
537
|
+
var button = $2.child(div_2);
|
|
538
|
+
var button_1 = $2.sibling(button, 2);
|
|
539
|
+
var button_2 = $2.sibling(button_1, 2);
|
|
540
|
+
var button_3 = $2.sibling(button_2, 2);
|
|
541
|
+
$2.reset(div_2);
|
|
542
|
+
var div_3 = $2.sibling(div_2, 2);
|
|
543
|
+
var button_4 = $2.child(div_3);
|
|
544
|
+
var button_5 = $2.sibling(button_4, 2);
|
|
545
|
+
var button_6 = $2.sibling(button_5, 2);
|
|
546
|
+
var button_7 = $2.sibling(button_6, 4);
|
|
547
|
+
var span = $2.sibling(button_7, 2);
|
|
548
|
+
var text = $2.only_child(span);
|
|
549
|
+
var button_8 = $2.sibling(span, 2);
|
|
550
|
+
var button_9 = $2.sibling(button_8, 4);
|
|
551
|
+
var button_10 = $2.sibling(button_9, 2);
|
|
552
|
+
$2.reset(div_3);
|
|
553
|
+
$2.reset(div_1);
|
|
554
|
+
var div_4 = $2.sibling(div_1, 2);
|
|
555
|
+
var div_5 = $2.child(div_4);
|
|
556
|
+
var canvas = $2.child(div_5);
|
|
557
|
+
$2.bind_this(canvas, ($$value) => $2.set(canvasEl, $$value), () => $2.get(canvasEl));
|
|
558
|
+
$2.reset(div_5);
|
|
559
|
+
$2.bind_this(div_5, ($$value) => $2.set(containerEl, $$value), () => $2.get(containerEl));
|
|
560
|
+
var div_6 = $2.sibling(div_5, 2);
|
|
561
|
+
var node = $2.child(div_6);
|
|
562
|
+
{
|
|
563
|
+
var consequent = ($$anchor2) => {
|
|
564
|
+
var div_7 = root();
|
|
565
|
+
var div_8 = $2.sibling($2.child(div_7), 2);
|
|
566
|
+
var button_11 = $2.child(div_8);
|
|
567
|
+
var button_12 = $2.sibling(button_11, 2);
|
|
568
|
+
var button_13 = $2.sibling(button_12, 2);
|
|
569
|
+
var button_14 = $2.sibling(button_13, 2);
|
|
570
|
+
var button_15 = $2.sibling(button_14, 2);
|
|
571
|
+
var button_16 = $2.sibling(button_15, 2);
|
|
572
|
+
$2.reset(div_8);
|
|
573
|
+
var div_9 = $2.sibling(div_8, 6);
|
|
574
|
+
var button_17 = $2.child(div_9);
|
|
575
|
+
var button_18 = $2.sibling(button_17, 2);
|
|
576
|
+
var button_19 = $2.sibling(button_18, 2);
|
|
577
|
+
var button_20 = $2.sibling(button_19, 2);
|
|
578
|
+
$2.reset(div_9);
|
|
579
|
+
$2.reset(div_7);
|
|
580
|
+
$2.template_effect(() => {
|
|
581
|
+
$2.set_class(button_11, 1, `px-2.5 py-2 rounded-lg border font-medium ${$2.get(activeCropRatio) === null && $2.get(editor).state.crop ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 hover:bg-slate-700 text-slate-200 border-slate-700"}`);
|
|
582
|
+
$2.set_class(button_12, 1, `px-2.5 py-2 rounded-lg border font-medium ${$2.get(activeCropRatio) === 1 ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 hover:bg-slate-700 text-slate-200 border-slate-700"}`);
|
|
583
|
+
$2.set_class(button_13, 1, `px-2.5 py-2 rounded-lg border font-medium ${$2.get(activeCropRatio) === 4 / 3 ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 hover:bg-slate-700 text-slate-200 border-slate-700"}`);
|
|
584
|
+
$2.set_class(button_14, 1, `px-2.5 py-2 rounded-lg border font-medium ${$2.get(activeCropRatio) === 16 / 9 ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 hover:bg-slate-700 text-slate-200 border-slate-700"}`);
|
|
585
|
+
$2.set_class(button_15, 1, `px-2.5 py-2 rounded-lg border font-medium ${$2.get(activeCropRatio) === 3 / 2 ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 hover:bg-slate-700 text-slate-200 border-slate-700"}`);
|
|
586
|
+
$2.set_class(button_19, 1, `px-3 py-2 rounded-lg border transition-colors ${$2.get(editor).state.transform.flipH ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 border-slate-700 text-slate-200 hover:bg-slate-700"}`);
|
|
587
|
+
$2.set_class(button_20, 1, `px-3 py-2 rounded-lg border transition-colors ${$2.get(editor).state.transform.flipV ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 border-slate-700 text-slate-200 hover:bg-slate-700"}`);
|
|
588
|
+
});
|
|
589
|
+
$2.delegated("click", button_11, () => {
|
|
590
|
+
$2.set(activeCropRatio, null);
|
|
591
|
+
$2.get(editor).applyCropPreset(null);
|
|
592
|
+
});
|
|
593
|
+
$2.delegated("click", button_12, () => {
|
|
594
|
+
$2.set(activeCropRatio, 1);
|
|
595
|
+
$2.get(editor).applyCropPreset(1);
|
|
596
|
+
});
|
|
597
|
+
$2.delegated("click", button_13, () => {
|
|
598
|
+
$2.set(activeCropRatio, 4 / 3);
|
|
599
|
+
$2.get(editor).applyCropPreset(4 / 3);
|
|
600
|
+
});
|
|
601
|
+
$2.delegated("click", button_14, () => {
|
|
602
|
+
$2.set(activeCropRatio, 16 / 9);
|
|
603
|
+
$2.get(editor).applyCropPreset(16 / 9);
|
|
604
|
+
});
|
|
605
|
+
$2.delegated("click", button_15, () => {
|
|
606
|
+
$2.set(activeCropRatio, 3 / 2);
|
|
607
|
+
$2.get(editor).applyCropPreset(3 / 2);
|
|
608
|
+
});
|
|
609
|
+
$2.delegated("click", button_16, () => {
|
|
610
|
+
$2.set(activeCropRatio, null);
|
|
611
|
+
$2.get(editor).resetCrop();
|
|
612
|
+
});
|
|
613
|
+
$2.delegated("click", button_17, () => $2.get(editor).rotate(-90));
|
|
614
|
+
$2.delegated("click", button_18, () => $2.get(editor).rotate(90));
|
|
615
|
+
$2.delegated("click", button_19, () => $2.get(editor).flipHorizontal());
|
|
616
|
+
$2.delegated("click", button_20, () => $2.get(editor).flipVertical());
|
|
617
|
+
$2.append($$anchor2, div_7);
|
|
618
|
+
};
|
|
619
|
+
$2.if(node, ($$render) => {
|
|
620
|
+
if ($2.get(activeTab) === "crop") $$render(consequent);
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
var node_1 = $2.sibling(node, 2);
|
|
624
|
+
{
|
|
625
|
+
var consequent_1 = ($$anchor2) => {
|
|
626
|
+
var div_10 = root_1();
|
|
627
|
+
var div_11 = $2.child(div_10);
|
|
628
|
+
var button_21 = $2.sibling($2.child(div_11), 2);
|
|
629
|
+
$2.reset(div_11);
|
|
630
|
+
var div_12 = $2.sibling(div_11, 2);
|
|
631
|
+
var div_13 = $2.child(div_12);
|
|
632
|
+
var span_1 = $2.sibling($2.child(div_13), 2);
|
|
633
|
+
var text_1 = $2.only_child(span_1, true);
|
|
634
|
+
$2.reset(div_13);
|
|
635
|
+
var input = $2.sibling(div_13, 2);
|
|
636
|
+
$2.remove_input_defaults(input);
|
|
637
|
+
$2.reset(div_12);
|
|
638
|
+
var div_14 = $2.sibling(div_12, 2);
|
|
639
|
+
var div_15 = $2.child(div_14);
|
|
640
|
+
var span_2 = $2.sibling($2.child(div_15), 2);
|
|
641
|
+
var text_2 = $2.only_child(span_2, true);
|
|
642
|
+
$2.reset(div_15);
|
|
643
|
+
var input_1 = $2.sibling(div_15, 2);
|
|
644
|
+
$2.remove_input_defaults(input_1);
|
|
645
|
+
$2.reset(div_14);
|
|
646
|
+
var div_16 = $2.sibling(div_14, 2);
|
|
647
|
+
var div_17 = $2.child(div_16);
|
|
648
|
+
var span_3 = $2.sibling($2.child(div_17), 2);
|
|
649
|
+
var text_3 = $2.only_child(span_3, true);
|
|
650
|
+
$2.reset(div_17);
|
|
651
|
+
var input_2 = $2.sibling(div_17, 2);
|
|
652
|
+
$2.remove_input_defaults(input_2);
|
|
653
|
+
$2.reset(div_16);
|
|
654
|
+
var div_18 = $2.sibling(div_16, 2);
|
|
655
|
+
var div_19 = $2.child(div_18);
|
|
656
|
+
var span_4 = $2.sibling($2.child(div_19), 2);
|
|
657
|
+
var text_4 = $2.only_child(span_4, true);
|
|
658
|
+
$2.reset(div_19);
|
|
659
|
+
var input_3 = $2.sibling(div_19, 2);
|
|
660
|
+
$2.remove_input_defaults(input_3);
|
|
661
|
+
$2.reset(div_18);
|
|
662
|
+
var div_20 = $2.sibling(div_18, 2);
|
|
663
|
+
var div_21 = $2.child(div_20);
|
|
664
|
+
var span_5 = $2.sibling($2.child(div_21), 2);
|
|
665
|
+
var text_5 = $2.only_child(span_5, true);
|
|
666
|
+
$2.reset(div_21);
|
|
667
|
+
var input_4 = $2.sibling(div_21, 2);
|
|
668
|
+
$2.remove_input_defaults(input_4);
|
|
669
|
+
$2.reset(div_20);
|
|
670
|
+
var div_22 = $2.sibling(div_20, 2);
|
|
671
|
+
var div_23 = $2.child(div_22);
|
|
672
|
+
var span_6 = $2.sibling($2.child(div_23), 2);
|
|
673
|
+
var text_6 = $2.only_child(span_6);
|
|
674
|
+
$2.reset(div_23);
|
|
675
|
+
var input_5 = $2.sibling(div_23, 2);
|
|
676
|
+
$2.remove_input_defaults(input_5);
|
|
677
|
+
$2.reset(div_22);
|
|
678
|
+
var div_24 = $2.sibling(div_22, 2);
|
|
679
|
+
var div_25 = $2.child(div_24);
|
|
680
|
+
var span_7 = $2.sibling($2.child(div_25), 2);
|
|
681
|
+
var text_7 = $2.only_child(span_7);
|
|
682
|
+
$2.reset(div_25);
|
|
683
|
+
var input_6 = $2.sibling(div_25, 2);
|
|
684
|
+
$2.remove_input_defaults(input_6);
|
|
685
|
+
$2.reset(div_24);
|
|
686
|
+
$2.reset(div_10);
|
|
687
|
+
$2.template_effect(
|
|
688
|
+
($0) => {
|
|
689
|
+
$2.set_text(text_1, $2.get(editor).state.adjustments.brightness);
|
|
690
|
+
$2.set_value(input, $2.get(editor).state.adjustments.brightness);
|
|
691
|
+
$2.set_text(text_2, $2.get(editor).state.adjustments.contrast);
|
|
692
|
+
$2.set_value(input_1, $2.get(editor).state.adjustments.contrast);
|
|
693
|
+
$2.set_text(text_3, $2.get(editor).state.adjustments.saturation);
|
|
694
|
+
$2.set_value(input_2, $2.get(editor).state.adjustments.saturation);
|
|
695
|
+
$2.set_text(text_4, $2.get(editor).state.adjustments.exposure);
|
|
696
|
+
$2.set_value(input_3, $2.get(editor).state.adjustments.exposure);
|
|
697
|
+
$2.set_text(text_5, $2.get(editor).state.adjustments.temperature);
|
|
698
|
+
$2.set_value(input_4, $2.get(editor).state.adjustments.temperature);
|
|
699
|
+
$2.set_text(text_6, `${$2.get(editor).state.adjustments.blur ?? ""}px`);
|
|
700
|
+
$2.set_value(input_5, $2.get(editor).state.adjustments.blur);
|
|
701
|
+
$2.set_text(text_7, `${$0 ?? ""}%`);
|
|
702
|
+
$2.set_value(input_6, $2.get(editor).state.adjustments.opacity);
|
|
703
|
+
},
|
|
704
|
+
[
|
|
705
|
+
() => Math.round($2.get(editor).state.adjustments.opacity * 100)
|
|
706
|
+
]
|
|
707
|
+
);
|
|
708
|
+
$2.delegated("click", button_21, () => $2.get(editor).resetAdjustments());
|
|
709
|
+
$2.delegated("input", input, (e) => $2.get(editor).setAdjustments({ brightness: Number(e.target.value) }));
|
|
710
|
+
$2.delegated("input", input_1, (e) => $2.get(editor).setAdjustments({ contrast: Number(e.target.value) }));
|
|
711
|
+
$2.delegated("input", input_2, (e) => $2.get(editor).setAdjustments({ saturation: Number(e.target.value) }));
|
|
712
|
+
$2.delegated("input", input_3, (e) => $2.get(editor).setAdjustments({ exposure: Number(e.target.value) }));
|
|
713
|
+
$2.delegated("input", input_4, (e) => $2.get(editor).setAdjustments({ temperature: Number(e.target.value) }));
|
|
714
|
+
$2.delegated("input", input_5, (e) => $2.get(editor).setAdjustments({ blur: Number(e.target.value) }));
|
|
715
|
+
$2.delegated("input", input_6, (e) => $2.get(editor).setAdjustments({ opacity: Number(e.target.value) }));
|
|
716
|
+
$2.append($$anchor2, div_10);
|
|
717
|
+
};
|
|
718
|
+
$2.if(node_1, ($$render) => {
|
|
719
|
+
if ($2.get(activeTab) === "adjust") $$render(consequent_1);
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
var node_2 = $2.sibling(node_1, 2);
|
|
723
|
+
{
|
|
724
|
+
var consequent_4 = ($$anchor2) => {
|
|
725
|
+
var div_26 = root_5();
|
|
726
|
+
var div_27 = $2.sibling($2.child(div_26), 2);
|
|
727
|
+
$2.each(div_27, 20, () => ["pen", "rect", "circle", "arrow", "line"], $2.index, ($$anchor3, t) => {
|
|
728
|
+
var button_22 = root_2();
|
|
729
|
+
var text_8 = $2.only_child(button_22, true);
|
|
730
|
+
$2.template_effect(() => {
|
|
731
|
+
$2.set_class(button_22, 1, `py-1.5 px-2 rounded-lg font-medium capitalize border transition-colors ${$2.get(editor).state.activeTool === t ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 border-slate-700 text-slate-300 hover:bg-slate-700"}`);
|
|
732
|
+
$2.set_text(text_8, t);
|
|
733
|
+
});
|
|
734
|
+
$2.delegated("click", button_22, () => $2.get(editor).setTool(t));
|
|
735
|
+
$2.append($$anchor3, button_22);
|
|
736
|
+
});
|
|
737
|
+
$2.reset(div_27);
|
|
738
|
+
var div_28 = $2.sibling(div_27, 2);
|
|
739
|
+
var input_7 = $2.sibling($2.child(div_28), 2);
|
|
740
|
+
$2.remove_input_defaults(input_7);
|
|
741
|
+
var div_29 = $2.sibling(input_7, 2);
|
|
742
|
+
var div_30 = $2.child(div_29);
|
|
743
|
+
var span_8 = $2.sibling($2.child(div_30), 2);
|
|
744
|
+
var text_9 = $2.only_child(span_8);
|
|
745
|
+
$2.reset(div_30);
|
|
746
|
+
var input_8 = $2.sibling(div_30, 2);
|
|
747
|
+
$2.remove_input_defaults(input_8);
|
|
748
|
+
$2.reset(div_29);
|
|
749
|
+
$2.reset(div_28);
|
|
750
|
+
var div_31 = $2.sibling(div_28, 6);
|
|
751
|
+
var input_9 = $2.child(div_31);
|
|
752
|
+
$2.remove_input_defaults(input_9);
|
|
753
|
+
var button_23 = $2.sibling(input_9, 2);
|
|
754
|
+
$2.reset(div_31);
|
|
755
|
+
var div_32 = $2.sibling(div_31, 2);
|
|
756
|
+
var span_9 = $2.sibling($2.child(div_32), 2);
|
|
757
|
+
var text_10 = $2.only_child(span_9);
|
|
758
|
+
$2.reset(div_32);
|
|
759
|
+
var input_10 = $2.sibling(div_32, 2);
|
|
760
|
+
$2.remove_input_defaults(input_10);
|
|
761
|
+
var div_33 = $2.sibling(input_10, 4);
|
|
762
|
+
var span_10 = $2.child(div_33);
|
|
763
|
+
var text_11 = $2.only_child(span_10);
|
|
764
|
+
var node_3 = $2.sibling(span_10, 2);
|
|
765
|
+
{
|
|
766
|
+
var consequent_2 = ($$anchor3) => {
|
|
767
|
+
var button_24 = root_3();
|
|
768
|
+
$2.delegated("click", button_24, () => $2.get(editor).removeAnnotation($2.get(editor).state.selectedAnnotationId));
|
|
769
|
+
$2.append($$anchor3, button_24);
|
|
770
|
+
};
|
|
771
|
+
$2.if(node_3, ($$render) => {
|
|
772
|
+
if ($2.get(editor).state.selectedAnnotationId) $$render(consequent_2);
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
var node_4 = $2.sibling(node_3, 2);
|
|
776
|
+
{
|
|
777
|
+
var consequent_3 = ($$anchor3) => {
|
|
778
|
+
var button_25 = root_4();
|
|
779
|
+
$2.delegated("click", button_25, () => $2.get(editor).clearAnnotations());
|
|
780
|
+
$2.append($$anchor3, button_25);
|
|
781
|
+
};
|
|
782
|
+
$2.if(node_4, ($$render) => {
|
|
783
|
+
if ($2.get(editor).state.annotations.length > 0) $$render(consequent_3);
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
$2.reset(div_33);
|
|
787
|
+
$2.reset(div_26);
|
|
788
|
+
$2.template_effect(() => {
|
|
789
|
+
$2.set_text(text_9, `${$2.get(strokeWidth) ?? ""}px`);
|
|
790
|
+
$2.set_text(text_10, `${$2.get(fontSize) ?? ""}px`);
|
|
791
|
+
$2.set_text(text_11, `Layers (${$2.get(editor).state.annotations.length ?? ""})`);
|
|
792
|
+
});
|
|
793
|
+
$2.bind_value(input_7, () => $2.get(activeColor), ($$value) => $2.set(activeColor, $$value));
|
|
794
|
+
$2.bind_value(input_8, () => $2.get(strokeWidth), ($$value) => $2.set(strokeWidth, $$value));
|
|
795
|
+
$2.delegated("keydown", input_9, (e) => e.key === "Enter" && handleAddText());
|
|
796
|
+
$2.bind_value(input_9, () => $2.get(textInput), ($$value) => $2.set(textInput, $$value));
|
|
797
|
+
$2.delegated("click", button_23, handleAddText);
|
|
798
|
+
$2.bind_value(input_10, () => $2.get(fontSize), ($$value) => $2.set(fontSize, $$value));
|
|
799
|
+
$2.append($$anchor2, div_26);
|
|
800
|
+
};
|
|
801
|
+
$2.if(node_2, ($$render) => {
|
|
802
|
+
if ($2.get(activeTab) === "annotate") $$render(consequent_4);
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
var node_5 = $2.sibling(node_2, 2);
|
|
806
|
+
{
|
|
807
|
+
var consequent_6 = ($$anchor2) => {
|
|
808
|
+
var div_34 = root_7();
|
|
809
|
+
var div_35 = $2.child(div_34);
|
|
810
|
+
var button_26 = $2.sibling($2.child(div_35), 2);
|
|
811
|
+
$2.reset(div_35);
|
|
812
|
+
var label = $2.sibling(div_35, 2);
|
|
813
|
+
var input_11 = $2.child(label);
|
|
814
|
+
$2.remove_input_defaults(input_11);
|
|
815
|
+
$2.next(2);
|
|
816
|
+
$2.reset(label);
|
|
817
|
+
var node_6 = $2.sibling(label, 2);
|
|
818
|
+
{
|
|
819
|
+
var consequent_5 = ($$anchor3) => {
|
|
820
|
+
var fragment = root_6();
|
|
821
|
+
var div_36 = $2.first_child(fragment);
|
|
822
|
+
var input_12 = $2.sibling($2.child(div_36), 2);
|
|
823
|
+
$2.remove_input_defaults(input_12);
|
|
824
|
+
$2.reset(div_36);
|
|
825
|
+
var div_37 = $2.sibling(div_36, 2);
|
|
826
|
+
var button_27 = $2.child(div_37);
|
|
827
|
+
var button_28 = $2.sibling(button_27, 2);
|
|
828
|
+
$2.reset(div_37);
|
|
829
|
+
var div_38 = $2.sibling(div_37, 2);
|
|
830
|
+
var div_39 = $2.child(div_38);
|
|
831
|
+
var span_11 = $2.sibling($2.child(div_39), 2);
|
|
832
|
+
var text_12 = $2.only_child(span_11, true);
|
|
833
|
+
$2.reset(div_39);
|
|
834
|
+
var input_13 = $2.sibling(div_39, 2);
|
|
835
|
+
$2.remove_input_defaults(input_13);
|
|
836
|
+
$2.reset(div_38);
|
|
837
|
+
var div_40 = $2.sibling(div_38, 2);
|
|
838
|
+
var div_41 = $2.child(div_40);
|
|
839
|
+
var span_12 = $2.sibling($2.child(div_41), 2);
|
|
840
|
+
var text_13 = $2.only_child(span_12, true);
|
|
841
|
+
$2.reset(div_41);
|
|
842
|
+
var input_14 = $2.sibling(div_41, 2);
|
|
843
|
+
$2.remove_input_defaults(input_14);
|
|
844
|
+
$2.reset(div_40);
|
|
845
|
+
var div_42 = $2.sibling(div_40, 2);
|
|
846
|
+
var div_43 = $2.child(div_42);
|
|
847
|
+
var span_13 = $2.sibling($2.child(div_43), 2);
|
|
848
|
+
var text_14 = $2.only_child(span_13, true);
|
|
849
|
+
$2.reset(div_43);
|
|
850
|
+
var input_15 = $2.sibling(div_43, 2);
|
|
851
|
+
$2.remove_input_defaults(input_15);
|
|
852
|
+
$2.reset(div_42);
|
|
853
|
+
var label_1 = $2.sibling(div_42, 2);
|
|
854
|
+
var input_16 = $2.child(label_1);
|
|
855
|
+
$2.remove_input_defaults(input_16);
|
|
856
|
+
$2.next(2);
|
|
857
|
+
$2.reset(label_1);
|
|
858
|
+
$2.template_effect(() => {
|
|
859
|
+
$2.set_value(input_12, $2.get(editor).state.depthMask.maskSource || "");
|
|
860
|
+
$2.set_class(button_27, 1, `flex-1 py-1.5 rounded-lg border text-xs font-medium ${$2.get(editor).state.depthMask.mode === "threshold" ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 border-slate-700 text-slate-300"}`);
|
|
861
|
+
$2.set_class(button_28, 1, `flex-1 py-1.5 rounded-lg border text-xs font-medium ${$2.get(editor).state.depthMask.mode === "brightness" ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 border-slate-700 text-slate-300"}`);
|
|
862
|
+
$2.set_text(text_12, $2.get(editor).state.depthMask.depthRange[0]);
|
|
863
|
+
$2.set_value(input_13, $2.get(editor).state.depthMask.depthRange[0]);
|
|
864
|
+
$2.set_text(text_13, $2.get(editor).state.depthMask.depthRange[1]);
|
|
865
|
+
$2.set_value(input_14, $2.get(editor).state.depthMask.depthRange[1]);
|
|
866
|
+
$2.set_text(text_14, $2.get(editor).state.depthMask.softness);
|
|
867
|
+
$2.set_value(input_15, $2.get(editor).state.depthMask.softness);
|
|
868
|
+
$2.set_checked(input_16, $2.get(editor).state.depthMask.invert);
|
|
869
|
+
});
|
|
870
|
+
$2.delegated("input", input_12, (e) => $2.get(editor).setDepthMask({ maskSource: e.target.value || null }));
|
|
871
|
+
$2.delegated("click", button_27, () => $2.get(editor).setDepthMask({ mode: "threshold" }));
|
|
872
|
+
$2.delegated("click", button_28, () => $2.get(editor).setDepthMask({ mode: "brightness" }));
|
|
873
|
+
$2.delegated("input", input_13, (e) => $2.get(editor).setDepthMask({
|
|
874
|
+
depthRange: [
|
|
875
|
+
Number(e.target.value),
|
|
876
|
+
$2.get(editor).state.depthMask.depthRange[1]
|
|
877
|
+
]
|
|
878
|
+
}));
|
|
879
|
+
$2.delegated("input", input_14, (e) => $2.get(editor).setDepthMask({
|
|
880
|
+
depthRange: [
|
|
881
|
+
$2.get(editor).state.depthMask.depthRange[0],
|
|
882
|
+
Number(e.target.value)
|
|
883
|
+
]
|
|
884
|
+
}));
|
|
885
|
+
$2.delegated("input", input_15, (e) => $2.get(editor).setDepthMask({ softness: Number(e.target.value) }));
|
|
886
|
+
$2.delegated("change", input_16, (e) => $2.get(editor).setDepthMask({ invert: e.target.checked }));
|
|
887
|
+
$2.append($$anchor3, fragment);
|
|
888
|
+
};
|
|
889
|
+
$2.if(node_6, ($$render) => {
|
|
890
|
+
if ($2.get(editor).state.depthMask.enabled) $$render(consequent_5);
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
$2.reset(div_34);
|
|
894
|
+
$2.template_effect(() => $2.set_checked(input_11, $2.get(editor).state.depthMask.enabled));
|
|
895
|
+
$2.delegated("click", button_26, () => $2.get(editor).resetDepthMask());
|
|
896
|
+
$2.delegated("change", input_11, (e) => $2.get(editor).setDepthMask({ enabled: e.target.checked }));
|
|
897
|
+
$2.append($$anchor2, div_34);
|
|
898
|
+
};
|
|
899
|
+
$2.if(node_5, ($$render) => {
|
|
900
|
+
if ($2.get(activeTab) === "depth") $$render(consequent_6);
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
$2.reset(div_6);
|
|
904
|
+
$2.reset(div_4);
|
|
905
|
+
$2.reset(div);
|
|
906
|
+
$2.template_effect(
|
|
907
|
+
($0) => {
|
|
908
|
+
$2.set_class(div, 1, `flex flex-col bg-slate-900 border border-slate-800 rounded-xl overflow-hidden shadow-2xl text-slate-100 ${className() ?? ""}`);
|
|
909
|
+
$2.set_style(div, style());
|
|
910
|
+
$2.set_class(button, 1, `px-3 py-1.5 rounded-md font-medium transition-colors ${$2.get(activeTab) === "crop" ? "bg-indigo-600 text-white shadow" : "text-slate-400 hover:text-slate-200"}`);
|
|
911
|
+
$2.set_class(button_1, 1, `px-3 py-1.5 rounded-md font-medium transition-colors ${$2.get(activeTab) === "adjust" ? "bg-indigo-600 text-white shadow" : "text-slate-400 hover:text-slate-200"}`);
|
|
912
|
+
$2.set_class(button_2, 1, `px-3 py-1.5 rounded-md font-medium transition-colors ${$2.get(activeTab) === "annotate" ? "bg-indigo-600 text-white shadow" : "text-slate-400 hover:text-slate-200"}`);
|
|
913
|
+
$2.set_class(button_3, 1, `px-3 py-1.5 rounded-md font-medium transition-colors ${$2.get(activeTab) === "depth" ? "bg-indigo-600 text-white shadow" : "text-slate-400 hover:text-slate-200"}`);
|
|
914
|
+
button_4.disabled = !$2.get(editor).canUndo;
|
|
915
|
+
button_5.disabled = !$2.get(editor).canRedo;
|
|
916
|
+
$2.set_text(text, `${$0 ?? ""}%`);
|
|
917
|
+
},
|
|
918
|
+
[() => Math.round($2.get(editor).state.zoom * 100)]
|
|
919
|
+
);
|
|
920
|
+
$2.delegated("click", button, () => {
|
|
921
|
+
$2.set(activeTab, "crop");
|
|
922
|
+
$2.get(editor).setTool("crop");
|
|
923
|
+
});
|
|
924
|
+
$2.delegated("click", button_1, () => {
|
|
925
|
+
$2.set(activeTab, "adjust");
|
|
926
|
+
$2.get(editor).setTool("select");
|
|
927
|
+
});
|
|
928
|
+
$2.delegated("click", button_2, () => {
|
|
929
|
+
$2.set(activeTab, "annotate");
|
|
930
|
+
$2.get(editor).setTool("pen");
|
|
931
|
+
});
|
|
932
|
+
$2.delegated("click", button_3, () => {
|
|
933
|
+
$2.set(activeTab, "depth");
|
|
934
|
+
$2.get(editor).setTool("select");
|
|
935
|
+
});
|
|
936
|
+
$2.delegated("click", button_4, () => $2.get(editor).undo());
|
|
937
|
+
$2.delegated("click", button_5, () => $2.get(editor).redo());
|
|
938
|
+
$2.delegated("click", button_6, () => $2.get(editor).reset());
|
|
939
|
+
$2.delegated("click", button_7, () => $2.get(editor).zoomOut());
|
|
940
|
+
$2.delegated("click", button_8, () => $2.get(editor).zoomIn());
|
|
941
|
+
$2.delegated("mousedown", button_9, () => $2.get(editor).setComparing(true));
|
|
942
|
+
$2.delegated("mouseup", button_9, () => $2.get(editor).setComparing(false));
|
|
943
|
+
$2.event("mouseleave", button_9, () => $2.get(editor).setComparing(false));
|
|
944
|
+
$2.delegated("click", button_10, handleExport);
|
|
945
|
+
$2.delegated("mousedown", canvas, handleMouseDown);
|
|
946
|
+
$2.delegated("mousemove", canvas, handleMouseMove);
|
|
947
|
+
$2.delegated("mouseup", canvas, handleMouseUp);
|
|
948
|
+
$2.event("mouseleave", canvas, handleMouseUp);
|
|
949
|
+
$2.append($$anchor, div);
|
|
950
|
+
$2.pop();
|
|
951
|
+
}
|
|
952
|
+
$2.delegate([
|
|
953
|
+
"click",
|
|
954
|
+
"mousedown",
|
|
955
|
+
"mouseup",
|
|
956
|
+
"mousemove",
|
|
957
|
+
"input",
|
|
958
|
+
"keydown",
|
|
959
|
+
"change"
|
|
960
|
+
]);
|
|
961
|
+
|
|
962
|
+
export {
|
|
963
|
+
createReactiveImageEditor,
|
|
964
|
+
ImageEditor
|
|
965
|
+
};
|
|
966
|
+
//# sourceMappingURL=chunk-REI5FZ7F.js.map
|