@pixerate/editor-react 0.7.0 → 0.9.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.
@@ -0,0 +1,1428 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/image-editor/index.ts
21
+ var image_editor_exports = {};
22
+ __export(image_editor_exports, {
23
+ ImageEditor: () => ImageEditor,
24
+ useImageEditor: () => useImageEditor
25
+ });
26
+ module.exports = __toCommonJS(image_editor_exports);
27
+
28
+ // src/image-editor/useImageEditor.ts
29
+ var import_react = require("react");
30
+ var import_editor = require("@pixerate/editor");
31
+ function useImageEditor(options = {}) {
32
+ const controllerRef = (0, import_react.useRef)(null);
33
+ if (!controllerRef.current) {
34
+ controllerRef.current = new import_editor.ImageEditorController(options);
35
+ }
36
+ const controller = controllerRef.current;
37
+ const [state, setState] = (0, import_react.useState)(() => controller.getState());
38
+ const [historyTicks, setHistoryTicks] = (0, import_react.useState)(0);
39
+ (0, import_react.useEffect)(() => {
40
+ const unsub = controller.subscribe((next) => {
41
+ setState(next);
42
+ setHistoryTicks((t) => t + 1);
43
+ });
44
+ return unsub;
45
+ }, [controller]);
46
+ (0, import_react.useEffect)(() => {
47
+ if (options.image && options.image !== state.sourceUrl) {
48
+ controller.loadImage(options.image);
49
+ }
50
+ }, [options.image, controller, state.sourceUrl]);
51
+ const setTool = (0, import_react.useCallback)((tool) => controller.setTool(tool), [controller]);
52
+ const setCrop = (0, import_react.useCallback)(
53
+ (crop, addToHistory = true) => controller.setCrop(crop, addToHistory),
54
+ [controller]
55
+ );
56
+ const applyCropPreset = (0, import_react.useCallback)((ratio) => controller.applyCropPreset(ratio), [controller]);
57
+ const resetCrop = (0, import_react.useCallback)(() => controller.resetCrop(), [controller]);
58
+ const rotate = (0, import_react.useCallback)((deg) => controller.rotate(deg), [controller]);
59
+ const setRotation = (0, import_react.useCallback)((deg) => controller.setRotation(deg), [controller]);
60
+ const flipHorizontal = (0, import_react.useCallback)(() => controller.flipHorizontal(), [controller]);
61
+ const flipVertical = (0, import_react.useCallback)(() => controller.flipVertical(), [controller]);
62
+ const setAdjustments = (0, import_react.useCallback)(
63
+ (partial, commitToHistory = true) => controller.setAdjustments(partial, commitToHistory),
64
+ [controller]
65
+ );
66
+ const resetAdjustments = (0, import_react.useCallback)(() => controller.resetAdjustments(), [controller]);
67
+ const setDepthMask = (0, import_react.useCallback)((partial) => controller.setDepthMask(partial), [controller]);
68
+ const resetDepthMask = (0, import_react.useCallback)(() => controller.resetDepthMask(), [controller]);
69
+ const addAnnotation = (0, import_react.useCallback)((ann) => controller.addAnnotation(ann), [controller]);
70
+ const updateAnnotation = (0, import_react.useCallback)(
71
+ (id, partial, commitToHistory = true) => controller.updateAnnotation(id, partial, commitToHistory),
72
+ [controller]
73
+ );
74
+ const removeAnnotation = (0, import_react.useCallback)((id) => controller.removeAnnotation(id), [controller]);
75
+ const clearAnnotations = (0, import_react.useCallback)(() => controller.clearAnnotations(), [controller]);
76
+ const selectAnnotation = (0, import_react.useCallback)((id) => controller.selectAnnotation(id), [controller]);
77
+ const undo = (0, import_react.useCallback)(() => controller.undo(), [controller]);
78
+ const redo = (0, import_react.useCallback)(() => controller.redo(), [controller]);
79
+ const reset = (0, import_react.useCallback)(() => controller.reset(), [controller]);
80
+ const zoomIn = (0, import_react.useCallback)((factor) => controller.zoomIn(factor), [controller]);
81
+ const zoomOut = (0, import_react.useCallback)((factor) => controller.zoomOut(factor), [controller]);
82
+ const resetZoom = (0, import_react.useCallback)(() => controller.resetZoom(), [controller]);
83
+ const setZoom = (0, import_react.useCallback)((zoom) => controller.setZoom(zoom), [controller]);
84
+ const setPan = (0, import_react.useCallback)((pan) => controller.setPan(pan), [controller]);
85
+ const setComparing = (0, import_react.useCallback)((comp) => controller.setComparing(comp), [controller]);
86
+ const loadImage = (0, import_react.useCallback)((src) => controller.loadImage(src), [controller]);
87
+ const toDataURL = (0, import_react.useCallback)((opts) => controller.toDataURL(opts), [controller]);
88
+ const toBlob = (0, import_react.useCallback)((opts) => controller.toBlob(opts), [controller]);
89
+ const toJSON = (0, import_react.useCallback)(() => controller.toJSON(), [controller]);
90
+ const loadJSON = (0, import_react.useCallback)((data) => controller.loadJSON(data), [controller]);
91
+ const renderMask = (0, import_react.useCallback)(
92
+ (opts) => controller.renderMask(opts),
93
+ [controller]
94
+ );
95
+ const toMaskDataURL = (0, import_react.useCallback)(
96
+ (opts) => controller.toMaskDataURL(opts),
97
+ [controller]
98
+ );
99
+ const applyInpaintedImage = (0, import_react.useCallback)(
100
+ (newDataUrl) => controller.applyInpaintedImage(newDataUrl),
101
+ [controller]
102
+ );
103
+ const applyBackgroundRemovedImage = (0, import_react.useCallback)(
104
+ (newDataUrl) => controller.applyBackgroundRemovedImage(newDataUrl),
105
+ [controller]
106
+ );
107
+ return (0, import_react.useMemo)(
108
+ () => ({
109
+ controller,
110
+ state,
111
+ canUndo: controller.canUndo,
112
+ canRedo: controller.canRedo,
113
+ setTool,
114
+ setCrop,
115
+ applyCropPreset,
116
+ resetCrop,
117
+ rotate,
118
+ setRotation,
119
+ flipHorizontal,
120
+ flipVertical,
121
+ setAdjustments,
122
+ resetAdjustments,
123
+ setDepthMask,
124
+ resetDepthMask,
125
+ addAnnotation,
126
+ updateAnnotation,
127
+ removeAnnotation,
128
+ clearAnnotations,
129
+ selectAnnotation,
130
+ undo,
131
+ redo,
132
+ reset,
133
+ zoomIn,
134
+ zoomOut,
135
+ resetZoom,
136
+ setZoom,
137
+ setPan,
138
+ setComparing,
139
+ loadImage,
140
+ toDataURL,
141
+ toBlob,
142
+ toJSON,
143
+ loadJSON,
144
+ renderMask,
145
+ toMaskDataURL,
146
+ applyInpaintedImage,
147
+ applyBackgroundRemovedImage
148
+ }),
149
+ // eslint-disable-next-line react-hooks/exhaustive-deps
150
+ [controller, state, historyTicks]
151
+ );
152
+ }
153
+
154
+ // src/image-editor/ImageEditor.tsx
155
+ var import_react2 = require("react");
156
+ var import_editor2 = require("@pixerate/editor");
157
+ var import_jsx_runtime = require("react/jsx-runtime");
158
+ var ImageEditor = ({
159
+ editor: externalEditor,
160
+ src,
161
+ className = "",
162
+ style,
163
+ onSave,
164
+ exportOptions,
165
+ onInpaint,
166
+ onRemoveBackground,
167
+ aiHooks
168
+ }) => {
169
+ const internalEditor = useImageEditor({ image: src });
170
+ const editor = externalEditor || internalEditor;
171
+ const { state, controller } = editor;
172
+ const canvasRef = (0, import_react2.useRef)(null);
173
+ const containerRef = (0, import_react2.useRef)(null);
174
+ const [activeTab, setActiveTab] = (0, import_react2.useState)("crop");
175
+ const [activeCropRatio, setActiveCropRatio] = (0, import_react2.useState)(null);
176
+ const [inpaintPrompt, setInpaintPrompt] = (0, import_react2.useState)("");
177
+ const [inpaintMaskMode, setInpaintMaskMode] = (0, import_react2.useState)("annotations");
178
+ const [isRemovingBg, setIsRemovingBg] = (0, import_react2.useState)(false);
179
+ const [isInpainting, setIsInpainting] = (0, import_react2.useState)(false);
180
+ const [aiError, setAiError] = (0, import_react2.useState)(null);
181
+ const [aiSuccess, setAiSuccess] = (0, import_react2.useState)(null);
182
+ const effectiveOnInpaint = onInpaint || aiHooks?.onInpaint;
183
+ const effectiveOnRemoveBg = onRemoveBackground || aiHooks?.onRemoveBackground;
184
+ const handleRemoveBackground = async () => {
185
+ if (!effectiveOnRemoveBg) {
186
+ setAiError("No background removal hook is configured.");
187
+ return;
188
+ }
189
+ setAiError(null);
190
+ setAiSuccess(null);
191
+ setIsRemovingBg(true);
192
+ try {
193
+ const imageDataUrl = await editor.toDataURL(exportOptions);
194
+ const result = await effectiveOnRemoveBg({ imageDataUrl });
195
+ if (typeof result === "string") {
196
+ await editor.applyBackgroundRemovedImage(result);
197
+ setAiSuccess("Background removed successfully!");
198
+ } else {
199
+ setAiSuccess("Background removal complete.");
200
+ }
201
+ } catch (err) {
202
+ setAiError(err?.message || "Failed to remove background.");
203
+ } finally {
204
+ setIsRemovingBg(false);
205
+ }
206
+ };
207
+ const handleInpaint = async () => {
208
+ if (!effectiveOnInpaint) {
209
+ setAiError("No inpainting hook is configured.");
210
+ return;
211
+ }
212
+ if (!inpaintPrompt.trim()) {
213
+ setAiError("Please enter an inpainting prompt.");
214
+ return;
215
+ }
216
+ setAiError(null);
217
+ setAiSuccess(null);
218
+ setIsInpainting(true);
219
+ try {
220
+ const imageDataUrl = await editor.toDataURL(exportOptions);
221
+ const maskDataUrl = await editor.toMaskDataURL({
222
+ useAnnotations: inpaintMaskMode === "annotations",
223
+ useCrop: inpaintMaskMode === "crop"
224
+ });
225
+ const result = await effectiveOnInpaint({
226
+ prompt: inpaintPrompt.trim(),
227
+ imageDataUrl,
228
+ maskDataUrl,
229
+ cropBox: inpaintMaskMode === "crop" ? editor.state.crop : null
230
+ });
231
+ if (typeof result === "string") {
232
+ await editor.applyInpaintedImage(result);
233
+ setAiSuccess("Inpainting applied successfully!");
234
+ } else {
235
+ setAiSuccess("Inpainting complete.");
236
+ }
237
+ } catch (err) {
238
+ setAiError(err?.message || "Failed to apply inpainting.");
239
+ } finally {
240
+ setIsInpainting(false);
241
+ }
242
+ };
243
+ const [activeColor, setActiveColor] = (0, import_react2.useState)("#ef4444");
244
+ const [strokeWidth, setStrokeWidth] = (0, import_react2.useState)(3);
245
+ const [fontSize, setFontSize] = (0, import_react2.useState)(24);
246
+ const [textInput, setTextInput] = (0, import_react2.useState)("");
247
+ const draftAnnotationRef = (0, import_react2.useRef)(null);
248
+ const draftCropRef = (0, import_react2.useRef)(null);
249
+ const cropDragInfoRef = (0, import_react2.useRef)(null);
250
+ const annotationDragInfoRef = (0, import_react2.useRef)(null);
251
+ const isDrawingRef = (0, import_react2.useRef)(false);
252
+ const currentPathRef = (0, import_react2.useRef)([]);
253
+ const dragStartPointRef = (0, import_react2.useRef)(null);
254
+ const renderCanvas = (0, import_react2.useCallback)(
255
+ async (draftAnnotation, draftCrop) => {
256
+ const canvas = canvasRef.current;
257
+ const container = containerRef.current;
258
+ if (!canvas || !container) return;
259
+ const vpWidth = container.clientWidth || 800;
260
+ const vpHeight = container.clientHeight || 500;
261
+ await controller.render(canvas, {
262
+ viewportWidth: vpWidth,
263
+ viewportHeight: vpHeight,
264
+ showCropOverlay: activeTab === "crop",
265
+ showSelectionOverlay: true,
266
+ interactive: true,
267
+ draftAnnotation: draftAnnotation !== void 0 ? draftAnnotation : draftAnnotationRef.current,
268
+ draftCrop: draftCrop !== void 0 ? draftCrop : draftCropRef.current
269
+ });
270
+ },
271
+ [controller, activeTab]
272
+ );
273
+ (0, import_react2.useEffect)(() => {
274
+ const raf = typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : (cb) => setTimeout(cb, 0);
275
+ const caf = typeof cancelAnimationFrame !== "undefined" ? cancelAnimationFrame : (id) => clearTimeout(id);
276
+ const animId = raf(() => {
277
+ renderCanvas();
278
+ });
279
+ return () => caf(animId);
280
+ }, [renderCanvas, state]);
281
+ (0, import_react2.useEffect)(() => {
282
+ if (activeTab === "crop" && editor.state.activeTool !== "crop") {
283
+ editor.setTool("crop");
284
+ }
285
+ }, [activeTab, editor]);
286
+ (0, import_react2.useEffect)(() => {
287
+ const container = containerRef.current;
288
+ if (!container) return;
289
+ if (typeof ResizeObserver !== "undefined") {
290
+ const observer = new ResizeObserver(() => {
291
+ renderCanvas();
292
+ });
293
+ observer.observe(container);
294
+ return () => observer.disconnect();
295
+ } else {
296
+ const handleResize = () => renderCanvas();
297
+ window.addEventListener("resize", handleResize);
298
+ return () => window.removeEventListener("resize", handleResize);
299
+ }
300
+ }, [renderCanvas]);
301
+ const getCanvasEventPoint = (e) => {
302
+ const canvas = canvasRef.current;
303
+ if (!canvas) return { x: 0, y: 0 };
304
+ const rect = canvas.getBoundingClientRect();
305
+ const scaleX = rect.width > 0 ? canvas.width / rect.width : 1;
306
+ const scaleY = rect.height > 0 ? canvas.height / rect.height : 1;
307
+ return {
308
+ x: (e.clientX - rect.left) * scaleX,
309
+ y: (e.clientY - rect.top) * scaleY
310
+ };
311
+ };
312
+ const handleMouseDown = (e) => {
313
+ const canvas = canvasRef.current;
314
+ if (!canvas) return;
315
+ const canvasPt = getCanvasEventPoint(e);
316
+ if (activeTab === "crop") {
317
+ const activeCrop = draftCropRef.current || state.crop || {
318
+ x: 0,
319
+ y: 0,
320
+ width: state.imageDimensions.width,
321
+ height: state.imageDimensions.height
322
+ };
323
+ const handle = (0, import_editor2.hitTestCrop)(canvasPt, state, canvas.width, canvas.height, 14, activeCrop);
324
+ const startImgPt = (0, import_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, true);
325
+ if (handle) {
326
+ cropDragInfoRef.current = {
327
+ handle,
328
+ startCanvasPt: canvasPt,
329
+ startImgPt,
330
+ startCrop: activeCrop
331
+ };
332
+ } else {
333
+ cropDragInfoRef.current = {
334
+ handle: "new",
335
+ startCanvasPt: canvasPt,
336
+ startImgPt,
337
+ startCrop: { x: startImgPt.x, y: startImgPt.y, width: 0, height: 0 }
338
+ };
339
+ }
340
+ return;
341
+ }
342
+ if (activeTab === "annotate") {
343
+ const imgPt = (0, import_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
344
+ dragStartPointRef.current = imgPt;
345
+ if (state.activeTool === "select") {
346
+ for (let i = state.annotations.length - 1; i >= 0; i--) {
347
+ const ann = state.annotations[i];
348
+ if ((0, import_editor2.hitTestAnnotation)(imgPt, ann)) {
349
+ editor.selectAnnotation(ann.id);
350
+ annotationDragInfoRef.current = {
351
+ annId: ann.id,
352
+ startImgPt: imgPt,
353
+ initialAnn: { ...ann }
354
+ };
355
+ return;
356
+ }
357
+ }
358
+ editor.selectAnnotation(null);
359
+ return;
360
+ }
361
+ if (state.activeTool === "pen") {
362
+ isDrawingRef.current = true;
363
+ currentPathRef.current = [imgPt];
364
+ const draft = {
365
+ id: "draft",
366
+ type: "pen",
367
+ x: 0,
368
+ y: 0,
369
+ points: [imgPt],
370
+ strokeColor: activeColor,
371
+ strokeWidth
372
+ };
373
+ draftAnnotationRef.current = draft;
374
+ renderCanvas(draft);
375
+ }
376
+ }
377
+ };
378
+ const handleMouseMove = (e) => {
379
+ const canvas = canvasRef.current;
380
+ if (!canvas) return;
381
+ const canvasPt = getCanvasEventPoint(e);
382
+ if (activeTab === "crop") {
383
+ const drag = cropDragInfoRef.current;
384
+ if (drag) {
385
+ const currentImgPt = (0, import_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, true);
386
+ let newCrop;
387
+ if (drag.handle === "new") {
388
+ const minX = Math.max(0, Math.min(drag.startImgPt.x, currentImgPt.x));
389
+ const minY = Math.max(0, Math.min(drag.startImgPt.y, currentImgPt.y));
390
+ const maxX = Math.min(state.imageDimensions.width, Math.max(drag.startImgPt.x, currentImgPt.x));
391
+ const maxY = Math.min(state.imageDimensions.height, Math.max(drag.startImgPt.y, currentImgPt.y));
392
+ newCrop = {
393
+ x: Math.round(minX),
394
+ y: Math.round(minY),
395
+ width: Math.round(Math.max(20, maxX - minX)),
396
+ height: Math.round(Math.max(20, maxY - minY))
397
+ };
398
+ } else {
399
+ newCrop = (0, import_editor2.calculateCropDrag)(
400
+ drag.startCrop,
401
+ drag.handle,
402
+ drag.startImgPt,
403
+ currentImgPt,
404
+ state.imageDimensions.width,
405
+ state.imageDimensions.height,
406
+ activeCropRatio
407
+ );
408
+ }
409
+ draftCropRef.current = newCrop;
410
+ renderCanvas(null, newCrop);
411
+ } else {
412
+ const activeCrop = draftCropRef.current || state.crop || {
413
+ x: 0,
414
+ y: 0,
415
+ width: state.imageDimensions.width,
416
+ height: state.imageDimensions.height
417
+ };
418
+ const handle = (0, import_editor2.hitTestCrop)(canvasPt, state, canvas.width, canvas.height, 14, activeCrop);
419
+ canvas.style.cursor = (0, import_editor2.getCropCursor)(handle);
420
+ }
421
+ return;
422
+ }
423
+ if (activeTab === "annotate") {
424
+ if (annotationDragInfoRef.current) {
425
+ const drag = annotationDragInfoRef.current;
426
+ const currentImgPt2 = (0, import_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
427
+ const dx = currentImgPt2.x - drag.startImgPt.x;
428
+ const dy = currentImgPt2.y - drag.startImgPt.y;
429
+ editor.updateAnnotation(drag.annId, {
430
+ x: Math.round(drag.initialAnn.x + dx),
431
+ y: Math.round(drag.initialAnn.y + dy)
432
+ });
433
+ return;
434
+ }
435
+ const startPt = dragStartPointRef.current;
436
+ if (!startPt) {
437
+ if (state.activeTool === "select") {
438
+ const imgPt = (0, import_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
439
+ let hovered = false;
440
+ for (let i = state.annotations.length - 1; i >= 0; i--) {
441
+ if ((0, import_editor2.hitTestAnnotation)(imgPt, state.annotations[i])) {
442
+ hovered = true;
443
+ break;
444
+ }
445
+ }
446
+ canvas.style.cursor = hovered ? "move" : "default";
447
+ } else {
448
+ canvas.style.cursor = "crosshair";
449
+ }
450
+ return;
451
+ }
452
+ const currentImgPt = (0, import_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
453
+ if (state.activeTool === "pen" && isDrawingRef.current) {
454
+ currentPathRef.current.push(currentImgPt);
455
+ const draft = {
456
+ id: "draft",
457
+ type: "pen",
458
+ x: 0,
459
+ y: 0,
460
+ points: [...currentPathRef.current],
461
+ strokeColor: activeColor,
462
+ strokeWidth
463
+ };
464
+ draftAnnotationRef.current = draft;
465
+ renderCanvas(draft);
466
+ } else if (state.activeTool === "rect") {
467
+ const w = currentImgPt.x - startPt.x;
468
+ const h = currentImgPt.y - startPt.y;
469
+ const draft = {
470
+ id: "draft",
471
+ type: "rect",
472
+ x: Math.min(startPt.x, currentImgPt.x),
473
+ y: Math.min(startPt.y, currentImgPt.y),
474
+ width: Math.abs(w),
475
+ height: Math.abs(h),
476
+ strokeColor: activeColor,
477
+ strokeWidth
478
+ };
479
+ draftAnnotationRef.current = draft;
480
+ renderCanvas(draft);
481
+ } else if (state.activeTool === "circle") {
482
+ const rx = Math.abs(currentImgPt.x - startPt.x) / 2;
483
+ const ry = Math.abs(currentImgPt.y - startPt.y) / 2;
484
+ const draft = {
485
+ id: "draft",
486
+ type: "circle",
487
+ x: Math.min(startPt.x, currentImgPt.x) + rx,
488
+ y: Math.min(startPt.y, currentImgPt.y) + ry,
489
+ radiusX: rx,
490
+ radiusY: ry,
491
+ strokeColor: activeColor,
492
+ strokeWidth
493
+ };
494
+ draftAnnotationRef.current = draft;
495
+ renderCanvas(draft);
496
+ } else if (state.activeTool === "arrow") {
497
+ const draft = {
498
+ id: "draft",
499
+ type: "arrow",
500
+ x: startPt.x,
501
+ y: startPt.y,
502
+ endX: currentImgPt.x,
503
+ endY: currentImgPt.y,
504
+ strokeColor: activeColor,
505
+ strokeWidth
506
+ };
507
+ draftAnnotationRef.current = draft;
508
+ renderCanvas(draft);
509
+ } else if (state.activeTool === "line") {
510
+ const draft = {
511
+ id: "draft",
512
+ type: "line",
513
+ x: startPt.x,
514
+ y: startPt.y,
515
+ endX: currentImgPt.x,
516
+ endY: currentImgPt.y,
517
+ strokeColor: activeColor,
518
+ strokeWidth
519
+ };
520
+ draftAnnotationRef.current = draft;
521
+ renderCanvas(draft);
522
+ }
523
+ }
524
+ };
525
+ const handleMouseUp = (e) => {
526
+ const canvas = canvasRef.current;
527
+ if (!canvas) return;
528
+ const canvasPt = getCanvasEventPoint(e);
529
+ if (activeTab === "crop") {
530
+ if (cropDragInfoRef.current) {
531
+ if (draftCropRef.current && draftCropRef.current.width >= 20 && draftCropRef.current.height >= 20) {
532
+ editor.setCrop(draftCropRef.current, true);
533
+ }
534
+ cropDragInfoRef.current = null;
535
+ draftCropRef.current = null;
536
+ renderCanvas();
537
+ }
538
+ return;
539
+ }
540
+ if (activeTab === "annotate") {
541
+ if (annotationDragInfoRef.current) {
542
+ annotationDragInfoRef.current = null;
543
+ return;
544
+ }
545
+ const startPt = dragStartPointRef.current;
546
+ if (startPt) {
547
+ const currentImgPt = (0, import_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
548
+ if (state.activeTool === "pen" && isDrawingRef.current) {
549
+ if (currentPathRef.current.length > 1) {
550
+ editor.addAnnotation({
551
+ type: "pen",
552
+ x: 0,
553
+ y: 0,
554
+ points: [...currentPathRef.current],
555
+ strokeColor: activeColor,
556
+ strokeWidth
557
+ });
558
+ }
559
+ isDrawingRef.current = false;
560
+ currentPathRef.current = [];
561
+ } else if (state.activeTool === "rect") {
562
+ const w = Math.abs(currentImgPt.x - startPt.x);
563
+ const h = Math.abs(currentImgPt.y - startPt.y);
564
+ if (w > 4 && h > 4) {
565
+ editor.addAnnotation({
566
+ type: "rect",
567
+ x: Math.min(startPt.x, currentImgPt.x),
568
+ y: Math.min(startPt.y, currentImgPt.y),
569
+ width: w,
570
+ height: h,
571
+ strokeColor: activeColor,
572
+ strokeWidth
573
+ });
574
+ }
575
+ } else if (state.activeTool === "circle") {
576
+ const rx = Math.abs(currentImgPt.x - startPt.x) / 2;
577
+ const ry = Math.abs(currentImgPt.y - startPt.y) / 2;
578
+ if (rx > 4 && ry > 4) {
579
+ editor.addAnnotation({
580
+ type: "circle",
581
+ x: Math.min(startPt.x, currentImgPt.x) + rx,
582
+ y: Math.min(startPt.y, currentImgPt.y) + ry,
583
+ radiusX: rx,
584
+ radiusY: ry,
585
+ strokeColor: activeColor,
586
+ strokeWidth
587
+ });
588
+ }
589
+ } else if (state.activeTool === "arrow") {
590
+ if (Math.hypot(currentImgPt.x - startPt.x, currentImgPt.y - startPt.y) > 4) {
591
+ editor.addAnnotation({
592
+ type: "arrow",
593
+ x: startPt.x,
594
+ y: startPt.y,
595
+ endX: currentImgPt.x,
596
+ endY: currentImgPt.y,
597
+ strokeColor: activeColor,
598
+ strokeWidth
599
+ });
600
+ }
601
+ } else if (state.activeTool === "line") {
602
+ if (Math.hypot(currentImgPt.x - startPt.x, currentImgPt.y - startPt.y) > 4) {
603
+ editor.addAnnotation({
604
+ type: "line",
605
+ x: startPt.x,
606
+ y: startPt.y,
607
+ endX: currentImgPt.x,
608
+ endY: currentImgPt.y,
609
+ strokeColor: activeColor,
610
+ strokeWidth
611
+ });
612
+ }
613
+ }
614
+ draftAnnotationRef.current = null;
615
+ dragStartPointRef.current = null;
616
+ renderCanvas();
617
+ }
618
+ }
619
+ };
620
+ const handleAddText = () => {
621
+ if (!textInput.trim()) return;
622
+ editor.addAnnotation({
623
+ type: "text",
624
+ x: 50,
625
+ y: 50,
626
+ text: textInput.trim(),
627
+ fontSize,
628
+ color: activeColor
629
+ });
630
+ setTextInput("");
631
+ };
632
+ const handleExport = async () => {
633
+ const dataUrl = await editor.toDataURL(exportOptions);
634
+ if (onSave) {
635
+ onSave(dataUrl);
636
+ } else {
637
+ const link = document.createElement("a");
638
+ link.download = `edited-image-${Date.now()}.png`;
639
+ link.href = dataUrl;
640
+ link.click();
641
+ }
642
+ };
643
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
644
+ "div",
645
+ {
646
+ className: `flex flex-col bg-slate-900 border border-slate-800 rounded-xl overflow-hidden shadow-2xl text-slate-100 ${className}`,
647
+ style,
648
+ children: [
649
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-wrap items-center justify-between px-4 py-3 bg-slate-950/80 border-b border-slate-800 gap-3", children: [
650
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-1 bg-slate-900 p-1 rounded-lg border border-slate-800 text-xs", children: [
651
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
652
+ "button",
653
+ {
654
+ type: "button",
655
+ onClick: () => {
656
+ setActiveTab("crop");
657
+ editor.setTool("crop");
658
+ },
659
+ className: `px-3 py-1.5 rounded-md font-medium transition-colors ${activeTab === "crop" ? "bg-indigo-600 text-white shadow" : "text-slate-400 hover:text-slate-200"}`,
660
+ children: "Transform & Crop"
661
+ }
662
+ ),
663
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
664
+ "button",
665
+ {
666
+ type: "button",
667
+ onClick: () => {
668
+ setActiveTab("adjust");
669
+ editor.setTool("select");
670
+ },
671
+ className: `px-3 py-1.5 rounded-md font-medium transition-colors ${activeTab === "adjust" ? "bg-indigo-600 text-white shadow" : "text-slate-400 hover:text-slate-200"}`,
672
+ children: "Adjustments"
673
+ }
674
+ ),
675
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
676
+ "button",
677
+ {
678
+ type: "button",
679
+ onClick: () => {
680
+ setActiveTab("annotate");
681
+ editor.setTool("pen");
682
+ },
683
+ className: `px-3 py-1.5 rounded-md font-medium transition-colors ${activeTab === "annotate" ? "bg-indigo-600 text-white shadow" : "text-slate-400 hover:text-slate-200"}`,
684
+ children: "Annotations"
685
+ }
686
+ ),
687
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
688
+ "button",
689
+ {
690
+ type: "button",
691
+ onClick: () => {
692
+ setActiveTab("depth");
693
+ editor.setTool("select");
694
+ },
695
+ className: `px-3 py-1.5 rounded-md font-medium transition-colors ${activeTab === "depth" ? "bg-indigo-600 text-white shadow" : "text-slate-400 hover:text-slate-200"}`,
696
+ children: "Depth Mask"
697
+ }
698
+ ),
699
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
700
+ "button",
701
+ {
702
+ type: "button",
703
+ onClick: () => {
704
+ setActiveTab("ai");
705
+ editor.setTool("select");
706
+ },
707
+ className: `px-3 py-1.5 rounded-md font-medium transition-colors flex items-center gap-1.5 ${activeTab === "ai" ? "bg-indigo-600 text-white shadow" : "text-slate-400 hover:text-slate-200"}`,
708
+ children: [
709
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-3.5 h-3.5", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83" }) }),
710
+ "AI Tools"
711
+ ]
712
+ }
713
+ )
714
+ ] }),
715
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2 text-xs", children: [
716
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
717
+ "button",
718
+ {
719
+ type: "button",
720
+ disabled: !editor.canUndo,
721
+ onClick: () => editor.undo(),
722
+ className: "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",
723
+ title: "Undo",
724
+ children: "\u21A9"
725
+ }
726
+ ),
727
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
728
+ "button",
729
+ {
730
+ type: "button",
731
+ disabled: !editor.canRedo,
732
+ onClick: () => editor.redo(),
733
+ className: "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",
734
+ title: "Redo",
735
+ children: "\u21AA"
736
+ }
737
+ ),
738
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
739
+ "button",
740
+ {
741
+ type: "button",
742
+ onClick: () => editor.reset(),
743
+ className: "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",
744
+ children: "Reset"
745
+ }
746
+ ),
747
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "h-4 w-px bg-slate-800 mx-1" }),
748
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
749
+ "button",
750
+ {
751
+ type: "button",
752
+ onClick: () => editor.zoomOut(),
753
+ className: "p-1.5 rounded-lg border border-slate-800 bg-slate-900 text-slate-300 hover:bg-slate-800",
754
+ title: "Zoom Out",
755
+ children: "-"
756
+ }
757
+ ),
758
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "font-mono text-slate-400 w-10 text-center", children: [
759
+ Math.round(state.zoom * 100),
760
+ "%"
761
+ ] }),
762
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
763
+ "button",
764
+ {
765
+ type: "button",
766
+ onClick: () => editor.zoomIn(),
767
+ className: "p-1.5 rounded-lg border border-slate-800 bg-slate-900 text-slate-300 hover:bg-slate-800",
768
+ title: "Zoom In",
769
+ children: "+"
770
+ }
771
+ ),
772
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "h-4 w-px bg-slate-800 mx-1" }),
773
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
774
+ "button",
775
+ {
776
+ type: "button",
777
+ onMouseDown: () => editor.setComparing(true),
778
+ onMouseUp: () => editor.setComparing(false),
779
+ onMouseLeave: () => editor.setComparing(false),
780
+ className: "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",
781
+ children: "Hold Compare"
782
+ }
783
+ ),
784
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
785
+ "button",
786
+ {
787
+ type: "button",
788
+ onClick: handleExport,
789
+ className: "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",
790
+ children: "Export Image"
791
+ }
792
+ )
793
+ ] })
794
+ ] }),
795
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col md:flex-row flex-1 min-h-[520px] md:h-[560px]", children: [
796
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
797
+ "div",
798
+ {
799
+ ref: containerRef,
800
+ className: "relative flex-1 h-[360px] md:h-full min-h-[320px] bg-slate-950 overflow-hidden select-none",
801
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
802
+ "canvas",
803
+ {
804
+ ref: canvasRef,
805
+ onMouseDown: handleMouseDown,
806
+ onMouseMove: handleMouseMove,
807
+ onMouseUp: handleMouseUp,
808
+ onMouseLeave: handleMouseUp,
809
+ className: "absolute inset-0 w-full h-full block"
810
+ }
811
+ )
812
+ }
813
+ ),
814
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "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]", children: [
815
+ activeTab === "crop" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-4 text-xs", children: [
816
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold text-slate-200 uppercase tracking-wider text-[11px]", children: "Aspect Ratio Presets" }),
817
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "grid grid-cols-3 gap-2", children: [
818
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
819
+ "button",
820
+ {
821
+ type: "button",
822
+ onClick: () => {
823
+ setActiveCropRatio(null);
824
+ editor.applyCropPreset(null);
825
+ },
826
+ className: `px-2.5 py-2 rounded-lg border font-medium ${activeCropRatio === null && state.crop ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 hover:bg-slate-700 text-slate-200 border-slate-700"}`,
827
+ children: "Freeform"
828
+ }
829
+ ),
830
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
831
+ "button",
832
+ {
833
+ type: "button",
834
+ onClick: () => {
835
+ setActiveCropRatio(1);
836
+ editor.applyCropPreset(1);
837
+ },
838
+ className: `px-2.5 py-2 rounded-lg border font-medium ${activeCropRatio === 1 ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 hover:bg-slate-700 text-slate-200 border-slate-700"}`,
839
+ children: "1:1 Square"
840
+ }
841
+ ),
842
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
843
+ "button",
844
+ {
845
+ type: "button",
846
+ onClick: () => {
847
+ setActiveCropRatio(4 / 3);
848
+ editor.applyCropPreset(4 / 3);
849
+ },
850
+ className: `px-2.5 py-2 rounded-lg border font-medium ${activeCropRatio === 4 / 3 ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 hover:bg-slate-700 text-slate-200 border-slate-700"}`,
851
+ children: "4:3 Standard"
852
+ }
853
+ ),
854
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
855
+ "button",
856
+ {
857
+ type: "button",
858
+ onClick: () => {
859
+ setActiveCropRatio(16 / 9);
860
+ editor.applyCropPreset(16 / 9);
861
+ },
862
+ className: `px-2.5 py-2 rounded-lg border font-medium ${activeCropRatio === 16 / 9 ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 hover:bg-slate-700 text-slate-200 border-slate-700"}`,
863
+ children: "16:9 Wide"
864
+ }
865
+ ),
866
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
867
+ "button",
868
+ {
869
+ type: "button",
870
+ onClick: () => {
871
+ setActiveCropRatio(3 / 2);
872
+ editor.applyCropPreset(3 / 2);
873
+ },
874
+ className: `px-2.5 py-2 rounded-lg border font-medium ${activeCropRatio === 3 / 2 ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 hover:bg-slate-700 text-slate-200 border-slate-700"}`,
875
+ children: "3:2 Photo"
876
+ }
877
+ ),
878
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
879
+ "button",
880
+ {
881
+ type: "button",
882
+ onClick: () => {
883
+ setActiveCropRatio(null);
884
+ editor.resetCrop();
885
+ },
886
+ className: "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",
887
+ children: "Clear Crop"
888
+ }
889
+ )
890
+ ] }),
891
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "h-px bg-slate-800 my-1" }),
892
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold text-slate-200 uppercase tracking-wider text-[11px]", children: "Orientation & Flips" }),
893
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "grid grid-cols-2 gap-2", children: [
894
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
895
+ "button",
896
+ {
897
+ type: "button",
898
+ onClick: () => editor.rotate(-90),
899
+ className: "px-3 py-2 rounded-lg bg-slate-800 hover:bg-slate-700 text-slate-200 border border-slate-700",
900
+ children: "Rotate -90\xB0"
901
+ }
902
+ ),
903
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
904
+ "button",
905
+ {
906
+ type: "button",
907
+ onClick: () => editor.rotate(90),
908
+ className: "px-3 py-2 rounded-lg bg-slate-800 hover:bg-slate-700 text-slate-200 border border-slate-700",
909
+ children: "Rotate +90\xB0"
910
+ }
911
+ ),
912
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
913
+ "button",
914
+ {
915
+ type: "button",
916
+ onClick: () => editor.flipHorizontal(),
917
+ className: `px-3 py-2 rounded-lg border transition-colors ${state.transform.flipH ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 border-slate-700 text-slate-200 hover:bg-slate-700"}`,
918
+ children: "Flip Horizontal"
919
+ }
920
+ ),
921
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
922
+ "button",
923
+ {
924
+ type: "button",
925
+ onClick: () => editor.flipVertical(),
926
+ className: `px-3 py-2 rounded-lg border transition-colors ${state.transform.flipV ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 border-slate-700 text-slate-200 hover:bg-slate-700"}`,
927
+ children: "Flip Vertical"
928
+ }
929
+ )
930
+ ] })
931
+ ] }),
932
+ activeTab === "adjust" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-3 text-xs", children: [
933
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between", children: [
934
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold text-slate-200 uppercase tracking-wider text-[11px]", children: "Color Adjustments" }),
935
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
936
+ "button",
937
+ {
938
+ type: "button",
939
+ onClick: () => editor.resetAdjustments(),
940
+ className: "text-[10px] text-rose-400 hover:underline",
941
+ children: "Reset Sliders"
942
+ }
943
+ )
944
+ ] }),
945
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
946
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-1", children: [
947
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Brightness" }),
948
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono", children: state.adjustments.brightness })
949
+ ] }),
950
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
951
+ "input",
952
+ {
953
+ type: "range",
954
+ min: "-100",
955
+ max: "100",
956
+ value: state.adjustments.brightness,
957
+ onChange: (e) => editor.setAdjustments({ brightness: Number(e.target.value) }),
958
+ className: "w-full accent-indigo-500"
959
+ }
960
+ )
961
+ ] }),
962
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
963
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-1", children: [
964
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Contrast" }),
965
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono", children: state.adjustments.contrast })
966
+ ] }),
967
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
968
+ "input",
969
+ {
970
+ type: "range",
971
+ min: "-100",
972
+ max: "100",
973
+ value: state.adjustments.contrast,
974
+ onChange: (e) => editor.setAdjustments({ contrast: Number(e.target.value) }),
975
+ className: "w-full accent-indigo-500"
976
+ }
977
+ )
978
+ ] }),
979
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
980
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-1", children: [
981
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Saturation" }),
982
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono", children: state.adjustments.saturation })
983
+ ] }),
984
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
985
+ "input",
986
+ {
987
+ type: "range",
988
+ min: "-100",
989
+ max: "100",
990
+ value: state.adjustments.saturation,
991
+ onChange: (e) => editor.setAdjustments({ saturation: Number(e.target.value) }),
992
+ className: "w-full accent-indigo-500"
993
+ }
994
+ )
995
+ ] }),
996
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
997
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-1", children: [
998
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Exposure" }),
999
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono", children: state.adjustments.exposure })
1000
+ ] }),
1001
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1002
+ "input",
1003
+ {
1004
+ type: "range",
1005
+ min: "-100",
1006
+ max: "100",
1007
+ value: state.adjustments.exposure,
1008
+ onChange: (e) => editor.setAdjustments({ exposure: Number(e.target.value) }),
1009
+ className: "w-full accent-indigo-500"
1010
+ }
1011
+ )
1012
+ ] }),
1013
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
1014
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-1", children: [
1015
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Warmth / Temperature" }),
1016
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono", children: state.adjustments.temperature })
1017
+ ] }),
1018
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1019
+ "input",
1020
+ {
1021
+ type: "range",
1022
+ min: "-100",
1023
+ max: "100",
1024
+ value: state.adjustments.temperature,
1025
+ onChange: (e) => editor.setAdjustments({ temperature: Number(e.target.value) }),
1026
+ className: "w-full accent-indigo-500"
1027
+ }
1028
+ )
1029
+ ] }),
1030
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
1031
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-1", children: [
1032
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Blur" }),
1033
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "font-mono", children: [
1034
+ state.adjustments.blur,
1035
+ "px"
1036
+ ] })
1037
+ ] }),
1038
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1039
+ "input",
1040
+ {
1041
+ type: "range",
1042
+ min: "0",
1043
+ max: "30",
1044
+ value: state.adjustments.blur,
1045
+ onChange: (e) => editor.setAdjustments({ blur: Number(e.target.value) }),
1046
+ className: "w-full accent-indigo-500"
1047
+ }
1048
+ )
1049
+ ] }),
1050
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
1051
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-1", children: [
1052
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Opacity" }),
1053
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "font-mono", children: [
1054
+ Math.round(state.adjustments.opacity * 100),
1055
+ "%"
1056
+ ] })
1057
+ ] }),
1058
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1059
+ "input",
1060
+ {
1061
+ type: "range",
1062
+ min: "0",
1063
+ max: "1",
1064
+ step: "0.05",
1065
+ value: state.adjustments.opacity,
1066
+ onChange: (e) => editor.setAdjustments({ opacity: Number(e.target.value) }),
1067
+ className: "w-full accent-indigo-500"
1068
+ }
1069
+ )
1070
+ ] })
1071
+ ] }),
1072
+ activeTab === "annotate" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-3 text-xs", children: [
1073
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold text-slate-200 uppercase tracking-wider text-[11px]", children: "Draw & Annotate" }),
1074
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "grid grid-cols-3 gap-1.5", children: ["pen", "rect", "circle", "arrow", "line"].map((t) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1075
+ "button",
1076
+ {
1077
+ type: "button",
1078
+ onClick: () => editor.setTool(t),
1079
+ className: `py-1.5 px-2 rounded-lg font-medium capitalize border transition-colors ${state.activeTool === t ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 border-slate-700 text-slate-300 hover:bg-slate-700"}`,
1080
+ children: t
1081
+ },
1082
+ t
1083
+ )) }),
1084
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2 mt-2", children: [
1085
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { className: "text-slate-400", children: "Color:" }),
1086
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1087
+ "input",
1088
+ {
1089
+ type: "color",
1090
+ value: activeColor,
1091
+ onChange: (e) => setActiveColor(e.target.value),
1092
+ className: "w-8 h-8 rounded border border-slate-700 cursor-pointer bg-transparent"
1093
+ }
1094
+ ),
1095
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex-1 ml-2", children: [
1096
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-0.5", children: [
1097
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Width:" }),
1098
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "font-mono", children: [
1099
+ strokeWidth,
1100
+ "px"
1101
+ ] })
1102
+ ] }),
1103
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1104
+ "input",
1105
+ {
1106
+ type: "range",
1107
+ min: "1",
1108
+ max: "20",
1109
+ value: strokeWidth,
1110
+ onChange: (e) => setStrokeWidth(Number(e.target.value)),
1111
+ className: "w-full accent-indigo-500"
1112
+ }
1113
+ )
1114
+ ] })
1115
+ ] }),
1116
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "h-px bg-slate-800 my-1" }),
1117
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold text-slate-200 uppercase tracking-wider text-[11px]", children: "Add Text" }),
1118
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
1119
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1120
+ "input",
1121
+ {
1122
+ type: "text",
1123
+ placeholder: "Type watermark or label...",
1124
+ value: textInput,
1125
+ onChange: (e) => setTextInput(e.target.value),
1126
+ onKeyDown: (e) => e.key === "Enter" && handleAddText(),
1127
+ className: "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"
1128
+ }
1129
+ ),
1130
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1131
+ "button",
1132
+ {
1133
+ type: "button",
1134
+ onClick: handleAddText,
1135
+ className: "px-3 py-1.5 rounded-lg bg-indigo-600 hover:bg-indigo-500 text-white font-medium shadow",
1136
+ children: "Add"
1137
+ }
1138
+ )
1139
+ ] }),
1140
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between text-slate-400", children: [
1141
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Font Size:" }),
1142
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "font-mono", children: [
1143
+ fontSize,
1144
+ "px"
1145
+ ] })
1146
+ ] }),
1147
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1148
+ "input",
1149
+ {
1150
+ type: "range",
1151
+ min: "12",
1152
+ max: "72",
1153
+ value: fontSize,
1154
+ onChange: (e) => setFontSize(Number(e.target.value)),
1155
+ className: "w-full accent-indigo-500"
1156
+ }
1157
+ ),
1158
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "h-px bg-slate-800 my-1" }),
1159
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between", children: [
1160
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "text-slate-400", children: [
1161
+ "Layers (",
1162
+ state.annotations.length,
1163
+ ")"
1164
+ ] }),
1165
+ state.selectedAnnotationId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1166
+ "button",
1167
+ {
1168
+ type: "button",
1169
+ onClick: () => editor.removeAnnotation(state.selectedAnnotationId),
1170
+ className: "text-rose-400 hover:underline text-[11px]",
1171
+ children: "Delete Selected"
1172
+ }
1173
+ ),
1174
+ state.annotations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1175
+ "button",
1176
+ {
1177
+ type: "button",
1178
+ onClick: () => editor.clearAnnotations(),
1179
+ className: "text-slate-400 hover:text-slate-200 text-[11px]",
1180
+ children: "Clear All"
1181
+ }
1182
+ )
1183
+ ] })
1184
+ ] }),
1185
+ activeTab === "depth" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-3 text-xs", children: [
1186
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between", children: [
1187
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-semibold text-slate-200 uppercase tracking-wider text-[11px]", children: "Depth Masking" }),
1188
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1189
+ "button",
1190
+ {
1191
+ type: "button",
1192
+ onClick: () => editor.resetDepthMask(),
1193
+ className: "text-[10px] text-rose-400 hover:underline",
1194
+ children: "Reset Mask"
1195
+ }
1196
+ )
1197
+ ] }),
1198
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "flex items-center gap-2 cursor-pointer text-slate-300", children: [
1199
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1200
+ "input",
1201
+ {
1202
+ type: "checkbox",
1203
+ checked: state.depthMask.enabled,
1204
+ onChange: (e) => editor.setDepthMask({ enabled: e.target.checked }),
1205
+ className: "rounded accent-indigo-500"
1206
+ }
1207
+ ),
1208
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Enable Depth / Alpha Mask" })
1209
+ ] }),
1210
+ state.depthMask.enabled && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1211
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
1212
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { className: "text-slate-400 block mb-1", children: "Mask Image URL:" }),
1213
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1214
+ "input",
1215
+ {
1216
+ type: "text",
1217
+ placeholder: "https://.../depthmap.png",
1218
+ value: state.depthMask.maskSource || "",
1219
+ onChange: (e) => editor.setDepthMask({ maskSource: e.target.value || null }),
1220
+ className: "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"
1221
+ }
1222
+ )
1223
+ ] }),
1224
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
1225
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1226
+ "button",
1227
+ {
1228
+ type: "button",
1229
+ onClick: () => editor.setDepthMask({ mode: "threshold" }),
1230
+ className: `flex-1 py-1.5 rounded-lg border text-xs font-medium ${state.depthMask.mode === "threshold" ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 border-slate-700 text-slate-300"}`,
1231
+ children: "Threshold Mode"
1232
+ }
1233
+ ),
1234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1235
+ "button",
1236
+ {
1237
+ type: "button",
1238
+ onClick: () => editor.setDepthMask({ mode: "brightness" }),
1239
+ className: `flex-1 py-1.5 rounded-lg border text-xs font-medium ${state.depthMask.mode === "brightness" ? "bg-indigo-600 border-indigo-500 text-white" : "bg-slate-800 border-slate-700 text-slate-300"}`,
1240
+ children: "Brightness Mode"
1241
+ }
1242
+ )
1243
+ ] }),
1244
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
1245
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-1", children: [
1246
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Depth Start (Lower):" }),
1247
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono", children: state.depthMask.depthRange[0] })
1248
+ ] }),
1249
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1250
+ "input",
1251
+ {
1252
+ type: "range",
1253
+ min: "0",
1254
+ max: "255",
1255
+ value: state.depthMask.depthRange[0],
1256
+ onChange: (e) => editor.setDepthMask({
1257
+ depthRange: [Number(e.target.value), state.depthMask.depthRange[1]]
1258
+ }),
1259
+ className: "w-full accent-indigo-500"
1260
+ }
1261
+ )
1262
+ ] }),
1263
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
1264
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-1", children: [
1265
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Depth Stop (Upper):" }),
1266
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono", children: state.depthMask.depthRange[1] })
1267
+ ] }),
1268
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1269
+ "input",
1270
+ {
1271
+ type: "range",
1272
+ min: "0",
1273
+ max: "255",
1274
+ value: state.depthMask.depthRange[1],
1275
+ onChange: (e) => editor.setDepthMask({
1276
+ depthRange: [state.depthMask.depthRange[0], Number(e.target.value)]
1277
+ }),
1278
+ className: "w-full accent-indigo-500"
1279
+ }
1280
+ )
1281
+ ] }),
1282
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
1283
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex justify-between text-slate-400 mb-1", children: [
1284
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Softness:" }),
1285
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono", children: state.depthMask.softness })
1286
+ ] }),
1287
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1288
+ "input",
1289
+ {
1290
+ type: "range",
1291
+ min: "1",
1292
+ max: "50",
1293
+ value: state.depthMask.softness,
1294
+ onChange: (e) => editor.setDepthMask({ softness: Number(e.target.value) }),
1295
+ className: "w-full accent-indigo-500"
1296
+ }
1297
+ )
1298
+ ] }),
1299
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "flex items-center gap-2 cursor-pointer text-slate-300 mt-1", children: [
1300
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1301
+ "input",
1302
+ {
1303
+ type: "checkbox",
1304
+ checked: state.depthMask.invert,
1305
+ onChange: (e) => editor.setDepthMask({ invert: e.target.checked }),
1306
+ className: "rounded accent-indigo-500"
1307
+ }
1308
+ ),
1309
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Invert Mask" })
1310
+ ] })
1311
+ ] })
1312
+ ] }),
1313
+ activeTab === "ai" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-4 text-xs", children: [
1314
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "p-3 rounded-lg bg-slate-950/60 border border-slate-800 flex flex-col gap-2.5", children: [
1315
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between", children: [
1316
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "font-semibold text-slate-200 uppercase tracking-wider text-[11px] flex items-center gap-1.5", children: [
1317
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-3.5 h-3.5 text-indigo-400", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 3v12M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6z" }) }),
1318
+ "Background Removal"
1319
+ ] }),
1320
+ isRemovingBg && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-indigo-900/60 text-indigo-300 animate-pulse", children: "Removing..." })
1321
+ ] }),
1322
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-slate-400 text-[11px] leading-relaxed", children: "Isolate foreground subject with AI alpha transparency segmentation." }),
1323
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1324
+ "button",
1325
+ {
1326
+ type: "button",
1327
+ onClick: handleRemoveBackground,
1328
+ disabled: isRemovingBg || isInpainting,
1329
+ className: "mt-1 px-3 py-2 rounded-lg bg-indigo-600 hover:bg-indigo-500 disabled:opacity-50 text-white font-medium shadow transition-colors flex items-center justify-center gap-2",
1330
+ children: isRemovingBg ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1331
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin" }),
1332
+ "Removing Background..."
1333
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1334
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-3.5 h-3.5", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83" }) }),
1335
+ "Remove Background"
1336
+ ] })
1337
+ }
1338
+ )
1339
+ ] }),
1340
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "p-3 rounded-lg bg-slate-950/60 border border-slate-800 flex flex-col gap-2.5", children: [
1341
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between", children: [
1342
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "font-semibold text-slate-200 uppercase tracking-wider text-[11px] flex items-center gap-1.5", children: [
1343
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { className: "w-3.5 h-3.5 text-purple-400", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
1344
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m21.64 3.64-1.28-1.28a1.2 1.2 0 0 0-1.7 0l-9.72 9.72-1.94 4.86 4.86-1.94 9.72-9.72a1.2 1.2 0 0 0 .06-1.64z" }),
1345
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m14 7 3 3" })
1346
+ ] }),
1347
+ "Generative Inpainting"
1348
+ ] }),
1349
+ isInpainting && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-900/60 text-purple-300 animate-pulse", children: "Inpainting..." })
1350
+ ] }),
1351
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-slate-400 text-[11px] leading-relaxed", children: "Replace, modify, or fill selected regions using prompt-guided generative inpainting." }),
1352
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-1", children: [
1353
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: "ai-inpaint-prompt-react", className: "text-slate-300 text-[11px] font-medium", children: "Prompt" }),
1354
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1355
+ "textarea",
1356
+ {
1357
+ id: "ai-inpaint-prompt-react",
1358
+ value: inpaintPrompt,
1359
+ onChange: (e) => setInpaintPrompt(e.target.value),
1360
+ placeholder: "e.g. replace sunglasses with steampunk goggles, remove person in background...",
1361
+ rows: 3,
1362
+ className: "w-full bg-slate-900 border border-slate-700 rounded-lg p-2 text-xs text-slate-100 placeholder-slate-500 focus:outline-none focus:border-indigo-500 resize-none"
1363
+ }
1364
+ )
1365
+ ] }),
1366
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-1", children: [
1367
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-slate-300 text-[11px] font-medium", children: "Target Mask Region" }),
1368
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "grid grid-cols-2 gap-1.5", children: [
1369
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1370
+ "button",
1371
+ {
1372
+ type: "button",
1373
+ onClick: () => setInpaintMaskMode("annotations"),
1374
+ className: `px-2 py-1.5 rounded border text-[11px] font-medium text-left transition-colors ${inpaintMaskMode === "annotations" ? "bg-purple-600/30 border-purple-500 text-purple-200" : "bg-slate-900 border-slate-700 text-slate-400 hover:text-slate-200"}`,
1375
+ children: [
1376
+ "Drawn Shapes (",
1377
+ state.annotations.length,
1378
+ ")"
1379
+ ]
1380
+ }
1381
+ ),
1382
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1383
+ "button",
1384
+ {
1385
+ type: "button",
1386
+ onClick: () => setInpaintMaskMode("crop"),
1387
+ className: `px-2 py-1.5 rounded border text-[11px] font-medium text-left transition-colors ${inpaintMaskMode === "crop" ? "bg-purple-600/30 border-purple-500 text-purple-200" : "bg-slate-900 border-slate-700 text-slate-400 hover:text-slate-200"}`,
1388
+ children: [
1389
+ "Crop Box (",
1390
+ state.crop ? "Selected" : "Full",
1391
+ ")"
1392
+ ]
1393
+ }
1394
+ )
1395
+ ] })
1396
+ ] }),
1397
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1398
+ "button",
1399
+ {
1400
+ type: "button",
1401
+ onClick: handleInpaint,
1402
+ disabled: isInpainting || isRemovingBg || !inpaintPrompt.trim(),
1403
+ className: "mt-1 px-3 py-2 rounded-lg bg-purple-600 hover:bg-purple-500 disabled:opacity-50 text-white font-medium shadow transition-colors flex items-center justify-center gap-2",
1404
+ children: isInpainting ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1405
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin" }),
1406
+ "Generating Inpaint..."
1407
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1408
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-3.5 h-3.5", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83" }) }),
1409
+ "Apply Inpainting"
1410
+ ] })
1411
+ }
1412
+ )
1413
+ ] }),
1414
+ aiError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "p-2.5 rounded-lg bg-rose-950/60 border border-rose-800 text-rose-300 text-[11px]", children: aiError }),
1415
+ aiSuccess && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "p-2.5 rounded-lg bg-emerald-950/60 border border-emerald-800 text-emerald-300 text-[11px]", children: aiSuccess })
1416
+ ] })
1417
+ ] })
1418
+ ] })
1419
+ ]
1420
+ }
1421
+ );
1422
+ };
1423
+ // Annotate the CommonJS export names for ESM import in node:
1424
+ 0 && (module.exports = {
1425
+ ImageEditor,
1426
+ useImageEditor
1427
+ });
1428
+ //# sourceMappingURL=index.cjs.map