@yogiswara/honcho-editor-ui 1.3.8 → 1.3.10
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/hooks/__tests__/useGallerySwipe.test.d.ts +0 -0
- package/dist/hooks/__tests__/useGallerySwipe.test.js +619 -0
- package/dist/hooks/editor/useHonchoEditor.d.ts +27 -83
- package/dist/hooks/editor/useHonchoEditor.js +415 -288
- package/dist/hooks/useAdjustmentHistory.d.ts +91 -0
- package/dist/hooks/useAdjustmentHistory.demo.d.ts +8 -0
- package/dist/hooks/useAdjustmentHistory.demo.js +106 -0
- package/dist/hooks/useAdjustmentHistory.example.d.ts +33 -0
- package/dist/hooks/useAdjustmentHistory.example.js +150 -0
- package/dist/hooks/useAdjustmentHistory.js +277 -0
- package/dist/hooks/useGallerySwipe.d.ts +36 -0
- package/dist/hooks/useGallerySwipe.example.d.ts +24 -0
- package/dist/hooks/useGallerySwipe.example.js +184 -0
- package/dist/hooks/useGallerySwipe.js +321 -0
- package/dist/setupTests.d.ts +1 -0
- package/dist/setupTests.js +1 -0
- package/dist/utils/adjustment.d.ts +5 -0
- package/dist/utils/adjustment.js +32 -0
- package/package.json +11 -2
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
3
3
|
import { HonchoEditor } from '../../lib/editor/honcho-editor';
|
|
4
|
+
import { mapAdjustmentStateToAdjustmentEditor, mapColorAdjustmentToAdjustmentState } from '../../utils/adjustment';
|
|
5
|
+
import { useAdjustmentHistory } from '../useAdjustmentHistory';
|
|
6
|
+
import { useGallerySwipe } from '../useGallerySwipe';
|
|
4
7
|
const initialAdjustments = {
|
|
5
8
|
tempScore: 0, tintScore: 0, vibranceScore: 0, exposureScore: 0, highlightsScore: 0, shadowsScore: 0,
|
|
6
9
|
whitesScore: 0, blacksScore: 0, saturationScore: 0, contrastScore: 0, clarityScore: 0, sharpnessScore: 0,
|
|
@@ -8,6 +11,11 @@ const initialAdjustments = {
|
|
|
8
11
|
const clamp = (value) => Math.max(-100, Math.min(100, value));
|
|
9
12
|
export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
10
13
|
const [currentImageId, setCurrentImageId] = useState(initImageId);
|
|
14
|
+
const [currentImageData, setCurrentImageData] = useState(null);
|
|
15
|
+
const [currentAdjustmentsState, setCurrentAdjustmentsState] = useState(initialAdjustments);
|
|
16
|
+
const { onSwipeNext, onSwipePrev, isNextAvailable, isPrevAvailable, isLoading: isGalleryLoading, error: galleryError, } = useGallerySwipe(firebaseUid, initImageId, controller);
|
|
17
|
+
// The useAdjustmentHistory hook now manages all undo/redo and adjustment state logic.
|
|
18
|
+
const { currentState: currentAdjustmentState, actions: historyActions, historyInfo, config: historyConfig, } = useAdjustmentHistory(initialAdjustments);
|
|
11
19
|
const [currentPage, setCurrentPage] = useState(1);
|
|
12
20
|
const [hasNextPage, setHasNextPage] = useState(true);
|
|
13
21
|
const [isFetchingNextPage, setIsFetchingNextPage] = useState(false);
|
|
@@ -33,18 +41,18 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
33
41
|
const [copyDialogExpanded, setCopyDialogExpanded] = useState({ color: true, light: true, details: true });
|
|
34
42
|
const [adjustmentsMap, setAdjustmentsMap] = useState(new Map());
|
|
35
43
|
// Individual Adjustment State
|
|
36
|
-
const [tempScore, setTempScore] = useState(0);
|
|
37
|
-
const [tintScore, setTintScore] = useState(0);
|
|
38
|
-
const [vibranceScore, setVibranceScore] = useState(0);
|
|
39
|
-
const [saturationScore, setSaturationScore] = useState(0);
|
|
40
|
-
const [exposureScore, setExposureScore] = useState(0);
|
|
41
|
-
const [highlightsScore, setHighlightsScore] = useState(0);
|
|
42
|
-
const [shadowsScore, setShadowsScore] = useState(0);
|
|
43
|
-
const [whitesScore, setWhitesScore] = useState(0);
|
|
44
|
-
const [blacksScore, setBlacksScore] = useState(0);
|
|
45
|
-
const [contrastScore, setContrastScore] = useState(0);
|
|
46
|
-
const [clarityScore, setClarityScore] = useState(0);
|
|
47
|
-
const [sharpnessScore, setSharpnessScore] = useState(0);
|
|
44
|
+
// const [tempScore, setTempScore] = useState(0);
|
|
45
|
+
// const [tintScore, setTintScore] = useState(0);
|
|
46
|
+
// const [vibranceScore, setVibranceScore] = useState(0);
|
|
47
|
+
// const [saturationScore, setSaturationScore] = useState(0);
|
|
48
|
+
// const [exposureScore, setExposureScore] = useState(0);
|
|
49
|
+
// const [highlightsScore, setHighlightsScore] = useState(0);
|
|
50
|
+
// const [shadowsScore, setShadowsScore] = useState(0);
|
|
51
|
+
// const [whitesScore, setWhitesScore] = useState(0);
|
|
52
|
+
// const [blacksScore, setBlacksScore] = useState(0);
|
|
53
|
+
// const [contrastScore, setContrastScore] = useState(0);
|
|
54
|
+
// const [clarityScore, setClarityScore] = useState(0);
|
|
55
|
+
// const [sharpnessScore, setSharpnessScore] = useState(0);
|
|
48
56
|
// MARK: - UI & App State (Moved from page.tsx)
|
|
49
57
|
// General UI State
|
|
50
58
|
const [isOnline, setIsOnline] = useState(true);
|
|
@@ -162,9 +170,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
162
170
|
}
|
|
163
171
|
}, [ /* handleOpenCopyDialog dependency */]);
|
|
164
172
|
useEffect(() => {
|
|
165
|
-
if (editorRef.current?.getInitialized() === false) {
|
|
166
|
-
editorRef.current?.initialize();
|
|
167
|
-
}
|
|
168
173
|
}, [editorRef]);
|
|
169
174
|
// Effect for measuring mobile panel content
|
|
170
175
|
useEffect(() => {
|
|
@@ -221,22 +226,24 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
221
226
|
};
|
|
222
227
|
}, []);
|
|
223
228
|
// MARK: - Core Editor Logic
|
|
224
|
-
const
|
|
225
|
-
|
|
229
|
+
const { tempScore, tintScore, vibranceScore, saturationScore, exposureScore, highlightsScore, shadowsScore, whitesScore, blacksScore, contrastScore, clarityScore, sharpnessScore } = currentAdjustmentsState;
|
|
230
|
+
const updateCanvasEditor = useCallback(() => {
|
|
231
|
+
if ((editorRef.current?.getInitialized() === true) && canvasRef.current) {
|
|
226
232
|
editorRef.current.processImage();
|
|
227
233
|
editorRef.current.renderToCanvas(canvasRef.current);
|
|
228
234
|
}
|
|
229
|
-
}, []);
|
|
235
|
+
}, [canvasRef.current, editorRef.current]);
|
|
230
236
|
const loadImage = useCallback(async (file) => {
|
|
231
237
|
if (!editorRef.current) {
|
|
232
238
|
setEditorStatus("Editor not ready.");
|
|
233
239
|
return;
|
|
234
240
|
}
|
|
235
241
|
setEditorStatus("Loading image...");
|
|
242
|
+
// TODO move
|
|
236
243
|
try {
|
|
237
244
|
await editorRef.current.loadImageFromFile(file);
|
|
238
245
|
setIsImageLoaded(true);
|
|
239
|
-
|
|
246
|
+
updateCanvasEditor();
|
|
240
247
|
}
|
|
241
248
|
catch (e) {
|
|
242
249
|
console.error("Error loading image:", e);
|
|
@@ -293,6 +300,62 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
293
300
|
setEditorStatus("Error: Could not fetch the image.");
|
|
294
301
|
}
|
|
295
302
|
}, [controller, loadImageFromUrl]);
|
|
303
|
+
const updateAdjustments = useCallback((newValues) => {
|
|
304
|
+
// In batch mode (like dragging a slider), this only updates the UI.
|
|
305
|
+
// When not in batch mode (or when the slider drag ends), it creates a history entry.
|
|
306
|
+
const newState = { ...currentAdjustmentsState, ...newValues };
|
|
307
|
+
historyActions.pushState(newState);
|
|
308
|
+
}, [currentAdjustmentsState, historyActions]);
|
|
309
|
+
const getImageFromId = useCallback(async (firebaseUid, imageId) => {
|
|
310
|
+
if (!controller)
|
|
311
|
+
return;
|
|
312
|
+
setEditorStatus("Fetching image...");
|
|
313
|
+
try {
|
|
314
|
+
const gallery = await controller.onGetImage(firebaseUid, imageId);
|
|
315
|
+
const imagePath = gallery?.raw_edited?.path
|
|
316
|
+
? gallery.raw_edited.path
|
|
317
|
+
: gallery?.download?.path;
|
|
318
|
+
console.log("[DEBUG] Extracted imagePath to load:", imagePath);
|
|
319
|
+
if (imagePath) {
|
|
320
|
+
return gallery; // ✅ RETURN the gallery object on success
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
throw new Error("Controller did not return a valid image object with path.");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
console.error("Failed to fetch or load image via controller:", error);
|
|
328
|
+
setEditorStatus("Error: Could not fetch the image.");
|
|
329
|
+
}
|
|
330
|
+
}, [controller]);
|
|
331
|
+
const extractPathFromGallery = useCallback((data) => {
|
|
332
|
+
const imagePath = data?.raw_edited?.path
|
|
333
|
+
? data.raw_edited.path
|
|
334
|
+
: data?.download?.path;
|
|
335
|
+
console.log("[DEBUG] Extracted imagePath to load:", imagePath);
|
|
336
|
+
return imagePath;
|
|
337
|
+
}, []);
|
|
338
|
+
const loadImageEditorFromUrl = useCallback(async (url) => {
|
|
339
|
+
try {
|
|
340
|
+
if (!editorRef.current)
|
|
341
|
+
return;
|
|
342
|
+
setEditorStatus("Downloading image...");
|
|
343
|
+
console.log(`[DEBUG] Attempting to fetch image from URL: ${url}`);
|
|
344
|
+
const response = await fetch(url);
|
|
345
|
+
if (!response.ok)
|
|
346
|
+
throw new Error(`Failed to fetch image from URL: ${url}`);
|
|
347
|
+
const blob = await response.blob();
|
|
348
|
+
const filename = url.substring(url.lastIndexOf('/') + 1) || 'image.jpg';
|
|
349
|
+
const file = new File([blob], filename, { type: blob.type });
|
|
350
|
+
await editorRef.current.loadImageFromFile(file);
|
|
351
|
+
setIsImageLoaded(true);
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
console.error(error);
|
|
355
|
+
setEditorStatus("Error: Could not load image from URL.");
|
|
356
|
+
setIsImageLoaded(false);
|
|
357
|
+
}
|
|
358
|
+
}, [editorRef.current]);
|
|
296
359
|
const handlePrev = useCallback(async (firebaseUid) => {
|
|
297
360
|
console.log("[DEBUG] handlePrev function was called.");
|
|
298
361
|
// Find the current image index
|
|
@@ -358,9 +421,9 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
358
421
|
]);
|
|
359
422
|
useEffect(() => {
|
|
360
423
|
const initialize = async () => {
|
|
361
|
-
if (
|
|
362
|
-
console.log(`[INIT] Starting sequence for image: ${
|
|
363
|
-
const initialGallery = await loadImageFromId(firebaseUid,
|
|
424
|
+
if (currentImageId && firebaseUid && controller && isEditorReady) {
|
|
425
|
+
console.log(`[INIT] Starting sequence for image: ${currentImageId}`);
|
|
426
|
+
const initialGallery = await loadImageFromId(firebaseUid, currentImageId);
|
|
364
427
|
// ✅ ADD THIS BLOCK TO CHECK THE DATA
|
|
365
428
|
console.group("[DEBUG] Checking Initial Gallery Data");
|
|
366
429
|
if (initialGallery) {
|
|
@@ -394,7 +457,7 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
394
457
|
}
|
|
395
458
|
};
|
|
396
459
|
initialize();
|
|
397
|
-
}, [
|
|
460
|
+
}, [currentImageId, firebaseUid, controller, isEditorReady, loadImageFromId]);
|
|
398
461
|
// useEffect(() => {
|
|
399
462
|
// // Ensure we have everything needed before trying to load.
|
|
400
463
|
// if (currentImageId && firebaseUid && controller && isEditorReady) {
|
|
@@ -407,7 +470,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
407
470
|
const files = event.target?.files;
|
|
408
471
|
if (!files || files.length === 0)
|
|
409
472
|
return;
|
|
410
|
-
applyAdjustmentState(initialAdjustments);
|
|
411
473
|
setHistory([initialAdjustments]);
|
|
412
474
|
setHistoryIndex(0);
|
|
413
475
|
if (files.length === 1) {
|
|
@@ -435,47 +497,47 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
435
497
|
setSelectedImageIds(new Set(newImageList.map(img => img.id)));
|
|
436
498
|
}
|
|
437
499
|
};
|
|
438
|
-
const applyAdjustmentState = useCallback((state) => {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}, [isBulkEditing, applyUiStateToSelectedImages]);
|
|
457
|
-
const handleRevert = useCallback(() => {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}, [applyAdjustmentState, isBulkEditing]);
|
|
465
|
-
const handleUndo = useCallback(() => {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}, [history, historyIndex, applyAdjustmentState]);
|
|
472
|
-
const handleRedo = useCallback(() => {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}, [history, historyIndex, applyAdjustmentState]);
|
|
500
|
+
// const applyAdjustmentState = useCallback((state: AdjustmentState) => {
|
|
501
|
+
// // Always update the UI controls
|
|
502
|
+
// setTempScore(state.tempScore);
|
|
503
|
+
// setTintScore(state.tintScore);
|
|
504
|
+
// setVibranceScore(state.vibranceScore);
|
|
505
|
+
// setExposureScore(state.exposureScore);
|
|
506
|
+
// setHighlightsScore(state.highlightsScore);
|
|
507
|
+
// setShadowsScore(state.shadowsScore);
|
|
508
|
+
// setWhitesScore(state.whitesScore);
|
|
509
|
+
// setBlacksScore(state.blacksScore);
|
|
510
|
+
// setSaturationScore(state.saturationScore);
|
|
511
|
+
// setContrastScore(state.contrastScore);
|
|
512
|
+
// setClarityScore(state.clarityScore);
|
|
513
|
+
// setSharpnessScore(state.sharpnessScore);
|
|
514
|
+
// // If in bulk mode, apply this state to all selected images
|
|
515
|
+
// if (isBulkEditing) {
|
|
516
|
+
// applyUiStateToSelectedImages(state);
|
|
517
|
+
// }
|
|
518
|
+
// }, [isBulkEditing, applyUiStateToSelectedImages]);
|
|
519
|
+
// const handleRevert = useCallback(() => {
|
|
520
|
+
// // This will reset the UI controls and, if in bulk mode, the selected images
|
|
521
|
+
// applyAdjustmentState(initialAdjustments);
|
|
522
|
+
// // For single image mode, also reset the underlying canvas engine
|
|
523
|
+
// if (!isBulkEditing && editorRef.current) {
|
|
524
|
+
// editorRef.current.resetAdjustments();
|
|
525
|
+
// }
|
|
526
|
+
// }, [applyAdjustmentState, isBulkEditing]);
|
|
527
|
+
// const handleUndo = useCallback(() => {
|
|
528
|
+
// if (historyIndex > 0) {
|
|
529
|
+
// const prevIndex = historyIndex - 1;
|
|
530
|
+
// applyAdjustmentState(history[prevIndex]);
|
|
531
|
+
// setHistoryIndex(prevIndex);
|
|
532
|
+
// }
|
|
533
|
+
// }, [history, historyIndex, applyAdjustmentState]);
|
|
534
|
+
// const handleRedo = useCallback(() => {
|
|
535
|
+
// if (historyIndex < history.length - 1) {
|
|
536
|
+
// const nextIndex = historyIndex + 1;
|
|
537
|
+
// applyAdjustmentState(history[nextIndex]);
|
|
538
|
+
// setHistoryIndex(nextIndex);
|
|
539
|
+
// }
|
|
540
|
+
// }, [history, historyIndex, applyAdjustmentState]);
|
|
479
541
|
const handleToggleImageSelection = useCallback((imageId) => {
|
|
480
542
|
const newSelectedIds = new Set(selectedImageIds);
|
|
481
543
|
const isCurrentlySelected = newSelectedIds.has(imageId);
|
|
@@ -529,67 +591,67 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
529
591
|
});
|
|
530
592
|
}
|
|
531
593
|
};
|
|
532
|
-
const setTempScoreAbs = createAbsoluteSetter('tempScore', setTempScore);
|
|
533
|
-
const setTintScoreAbs = createAbsoluteSetter('tintScore', setTintScore);
|
|
534
|
-
const setVibranceScoreAbs = createAbsoluteSetter('vibranceScore', setVibranceScore);
|
|
535
|
-
const setSaturationScoreAbs = createAbsoluteSetter('saturationScore', setSaturationScore);
|
|
536
|
-
const setExposureScoreAbs = createAbsoluteSetter('exposureScore', setExposureScore);
|
|
537
|
-
const setHighlightsScoreAbs = createAbsoluteSetter('highlightsScore', setHighlightsScore);
|
|
538
|
-
const setShadowsScoreAbs = createAbsoluteSetter('shadowsScore', setShadowsScore);
|
|
539
|
-
const setWhitesScoreAbs = createAbsoluteSetter('whitesScore', setWhitesScore);
|
|
540
|
-
const setBlacksScoreAbs = createAbsoluteSetter('blacksScore', setBlacksScore);
|
|
541
|
-
const setContrastScoreAbs = createAbsoluteSetter('contrastScore', setContrastScore);
|
|
542
|
-
const setClarityScoreAbs = createAbsoluteSetter('clarityScore', setClarityScore);
|
|
543
|
-
const setSharpnessScoreAbs = createAbsoluteSetter('sharpnessScore', setSharpnessScore);
|
|
544
|
-
// MARK: - Bulk Editor Handlers
|
|
545
|
-
const handleBulkTempDecreaseMax = createRelativeAdjuster('tempScore', setTempScore, -20);
|
|
546
|
-
const handleBulkTempDecrease = createRelativeAdjuster('tempScore', setTempScore, -5);
|
|
547
|
-
const handleBulkTempIncrease = createRelativeAdjuster('tempScore', setTempScore, 5);
|
|
548
|
-
const handleBulkTempIncreaseMax = createRelativeAdjuster('tempScore', setTempScore, 20);
|
|
549
|
-
const handleBulkTintDecreaseMax = createRelativeAdjuster('tintScore', setTintScore, -20);
|
|
550
|
-
const handleBulkTintDecrease = createRelativeAdjuster('tintScore', setTintScore, -5);
|
|
551
|
-
const handleBulkTintIncrease = createRelativeAdjuster('tintScore', setTintScore, 5);
|
|
552
|
-
const handleBulkTintIncreaseMax = createRelativeAdjuster('tintScore', setTintScore, 20);
|
|
553
|
-
const handleBulkVibranceDecreaseMax = createRelativeAdjuster('vibranceScore', setVibranceScore, -20);
|
|
554
|
-
const handleBulkVibranceDecrease = createRelativeAdjuster('vibranceScore', setVibranceScore, -5);
|
|
555
|
-
const handleBulkVibranceIncrease = createRelativeAdjuster('vibranceScore', setVibranceScore, 5);
|
|
556
|
-
const handleBulkVibranceIncreaseMax = createRelativeAdjuster('vibranceScore', setVibranceScore, 20);
|
|
557
|
-
const handleBulkSaturationDecreaseMax = createRelativeAdjuster('saturationScore', setSaturationScore, -20);
|
|
558
|
-
const handleBulkSaturationDecrease = createRelativeAdjuster('saturationScore', setSaturationScore, -5);
|
|
559
|
-
const handleBulkSaturationIncrease = createRelativeAdjuster('saturationScore', setSaturationScore, 5);
|
|
560
|
-
const handleBulkSaturationIncreaseMax = createRelativeAdjuster('saturationScore', setSaturationScore, 20);
|
|
561
|
-
const handleBulkExposureDecreaseMax = createRelativeAdjuster('exposureScore', setExposureScore, -20);
|
|
562
|
-
const handleBulkExposureDecrease = createRelativeAdjuster('exposureScore', setExposureScore, -5);
|
|
563
|
-
const handleBulkExposureIncrease = createRelativeAdjuster('exposureScore', setExposureScore, 5);
|
|
564
|
-
const handleBulkExposureIncreaseMax = createRelativeAdjuster('exposureScore', setExposureScore, 20);
|
|
565
|
-
const handleBulkContrastDecreaseMax = createRelativeAdjuster('contrastScore', setContrastScore, -20);
|
|
566
|
-
const handleBulkContrastDecrease = createRelativeAdjuster('contrastScore', setContrastScore, -5);
|
|
567
|
-
const handleBulkContrastIncrease = createRelativeAdjuster('contrastScore', setContrastScore, 5);
|
|
568
|
-
const handleBulkContrastIncreaseMax = createRelativeAdjuster('contrastScore', setContrastScore, 20);
|
|
569
|
-
const handleBulkHighlightsDecreaseMax = createRelativeAdjuster('highlightsScore', setHighlightsScore, -20);
|
|
570
|
-
const handleBulkHighlightsDecrease = createRelativeAdjuster('highlightsScore', setHighlightsScore, -5);
|
|
571
|
-
const handleBulkHighlightsIncrease = createRelativeAdjuster('highlightsScore', setHighlightsScore, 5);
|
|
572
|
-
const handleBulkHighlightsIncreaseMax = createRelativeAdjuster('highlightsScore', setHighlightsScore, 20);
|
|
573
|
-
const handleBulkShadowsDecreaseMax = createRelativeAdjuster('shadowsScore', setShadowsScore, -20);
|
|
574
|
-
const handleBulkShadowsDecrease = createRelativeAdjuster('shadowsScore', setShadowsScore, -5);
|
|
575
|
-
const handleBulkShadowsIncrease = createRelativeAdjuster('shadowsScore', setShadowsScore, 5);
|
|
576
|
-
const handleBulkShadowsIncreaseMax = createRelativeAdjuster('shadowsScore', setShadowsScore, 20);
|
|
577
|
-
const handleBulkWhitesDecreaseMax = createRelativeAdjuster('whitesScore', setWhitesScore, -20);
|
|
578
|
-
const handleBulkWhitesDecrease = createRelativeAdjuster('whitesScore', setWhitesScore, -5);
|
|
579
|
-
const handleBulkWhitesIncrease = createRelativeAdjuster('whitesScore', setWhitesScore, 5);
|
|
580
|
-
const handleBulkWhitesIncreaseMax = createRelativeAdjuster('whitesScore', setWhitesScore, 20);
|
|
581
|
-
const handleBulkBlacksDecreaseMax = createRelativeAdjuster('blacksScore', setBlacksScore, -20);
|
|
582
|
-
const handleBulkBlacksDecrease = createRelativeAdjuster('blacksScore', setBlacksScore, -5);
|
|
583
|
-
const handleBulkBlacksIncrease = createRelativeAdjuster('blacksScore', setBlacksScore, 5);
|
|
584
|
-
const handleBulkBlacksIncreaseMax = createRelativeAdjuster('blacksScore', setBlacksScore, 20);
|
|
585
|
-
const handleBulkClarityDecreaseMax = createRelativeAdjuster('clarityScore', setClarityScore, -20);
|
|
586
|
-
const handleBulkClarityDecrease = createRelativeAdjuster('clarityScore', setClarityScore, -5);
|
|
587
|
-
const handleBulkClarityIncrease = createRelativeAdjuster('clarityScore', setClarityScore, 5);
|
|
588
|
-
const handleBulkClarityIncreaseMax = createRelativeAdjuster('clarityScore', setClarityScore, 20);
|
|
589
|
-
const handleBulkSharpnessDecreaseMax = createRelativeAdjuster('sharpnessScore', setSharpnessScore, -20);
|
|
590
|
-
const handleBulkSharpnessDecrease = createRelativeAdjuster('sharpnessScore', setSharpnessScore, -5);
|
|
591
|
-
const handleBulkSharpnessIncrease = createRelativeAdjuster('sharpnessScore', setSharpnessScore, 5);
|
|
592
|
-
const handleBulkSharpnessIncreaseMax = createRelativeAdjuster('sharpnessScore', setSharpnessScore, 20);
|
|
594
|
+
// const setTempScoreAbs = createAbsoluteSetter('tempScore', setTempScore);
|
|
595
|
+
// const setTintScoreAbs = createAbsoluteSetter('tintScore', setTintScore);
|
|
596
|
+
// const setVibranceScoreAbs = createAbsoluteSetter('vibranceScore', setVibranceScore);
|
|
597
|
+
// const setSaturationScoreAbs = createAbsoluteSetter('saturationScore', setSaturationScore);
|
|
598
|
+
// const setExposureScoreAbs = createAbsoluteSetter('exposureScore', setExposureScore);
|
|
599
|
+
// const setHighlightsScoreAbs = createAbsoluteSetter('highlightsScore', setHighlightsScore);
|
|
600
|
+
// const setShadowsScoreAbs = createAbsoluteSetter('shadowsScore', setShadowsScore);
|
|
601
|
+
// const setWhitesScoreAbs = createAbsoluteSetter('whitesScore', setWhitesScore);
|
|
602
|
+
// const setBlacksScoreAbs = createAbsoluteSetter('blacksScore', setBlacksScore);
|
|
603
|
+
// const setContrastScoreAbs = createAbsoluteSetter('contrastScore', setContrastScore);
|
|
604
|
+
// const setClarityScoreAbs = createAbsoluteSetter('clarityScore', setClarityScore);
|
|
605
|
+
// const setSharpnessScoreAbs = createAbsoluteSetter('sharpnessScore', setSharpnessScore);
|
|
606
|
+
// // MARK: - Bulk Editor Handlers
|
|
607
|
+
// const handleBulkTempDecreaseMax = createRelativeAdjuster('tempScore', setTempScore, -20);
|
|
608
|
+
// const handleBulkTempDecrease = createRelativeAdjuster('tempScore', setTempScore, -5);
|
|
609
|
+
// const handleBulkTempIncrease = createRelativeAdjuster('tempScore', setTempScore, 5);
|
|
610
|
+
// const handleBulkTempIncreaseMax = createRelativeAdjuster('tempScore', setTempScore, 20);
|
|
611
|
+
// const handleBulkTintDecreaseMax = createRelativeAdjuster('tintScore', setTintScore, -20);
|
|
612
|
+
// const handleBulkTintDecrease = createRelativeAdjuster('tintScore', setTintScore, -5);
|
|
613
|
+
// const handleBulkTintIncrease = createRelativeAdjuster('tintScore', setTintScore, 5);
|
|
614
|
+
// const handleBulkTintIncreaseMax = createRelativeAdjuster('tintScore', setTintScore, 20);
|
|
615
|
+
// const handleBulkVibranceDecreaseMax = createRelativeAdjuster('vibranceScore', setVibranceScore, -20);
|
|
616
|
+
// const handleBulkVibranceDecrease = createRelativeAdjuster('vibranceScore', setVibranceScore, -5);
|
|
617
|
+
// const handleBulkVibranceIncrease = createRelativeAdjuster('vibranceScore', setVibranceScore, 5);
|
|
618
|
+
// const handleBulkVibranceIncreaseMax = createRelativeAdjuster('vibranceScore', setVibranceScore, 20);
|
|
619
|
+
// const handleBulkSaturationDecreaseMax = createRelativeAdjuster('saturationScore', setSaturationScore, -20);
|
|
620
|
+
// const handleBulkSaturationDecrease = createRelativeAdjuster('saturationScore', setSaturationScore, -5);
|
|
621
|
+
// const handleBulkSaturationIncrease = createRelativeAdjuster('saturationScore', setSaturationScore, 5);
|
|
622
|
+
// const handleBulkSaturationIncreaseMax = createRelativeAdjuster('saturationScore', setSaturationScore, 20);
|
|
623
|
+
// const handleBulkExposureDecreaseMax = createRelativeAdjuster('exposureScore', setExposureScore, -20);
|
|
624
|
+
// const handleBulkExposureDecrease = createRelativeAdjuster('exposureScore', setExposureScore, -5);
|
|
625
|
+
// const handleBulkExposureIncrease = createRelativeAdjuster('exposureScore', setExposureScore, 5);
|
|
626
|
+
// const handleBulkExposureIncreaseMax = createRelativeAdjuster('exposureScore', setExposureScore, 20);
|
|
627
|
+
// const handleBulkContrastDecreaseMax = createRelativeAdjuster('contrastScore', setContrastScore, -20);
|
|
628
|
+
// const handleBulkContrastDecrease = createRelativeAdjuster('contrastScore', setContrastScore, -5);
|
|
629
|
+
// const handleBulkContrastIncrease = createRelativeAdjuster('contrastScore', setContrastScore, 5);
|
|
630
|
+
// const handleBulkContrastIncreaseMax = createRelativeAdjuster('contrastScore', setContrastScore, 20);
|
|
631
|
+
// const handleBulkHighlightsDecreaseMax = createRelativeAdjuster('highlightsScore', setHighlightsScore, -20);
|
|
632
|
+
// const handleBulkHighlightsDecrease = createRelativeAdjuster('highlightsScore', setHighlightsScore, -5);
|
|
633
|
+
// const handleBulkHighlightsIncrease = createRelativeAdjuster('highlightsScore', setHighlightsScore, 5);
|
|
634
|
+
// const handleBulkHighlightsIncreaseMax = createRelativeAdjuster('highlightsScore', setHighlightsScore, 20);
|
|
635
|
+
// const handleBulkShadowsDecreaseMax = createRelativeAdjuster('shadowsScore', setShadowsScore, -20);
|
|
636
|
+
// const handleBulkShadowsDecrease = createRelativeAdjuster('shadowsScore', setShadowsScore, -5);
|
|
637
|
+
// const handleBulkShadowsIncrease = createRelativeAdjuster('shadowsScore', setShadowsScore, 5);
|
|
638
|
+
// const handleBulkShadowsIncreaseMax = createRelativeAdjuster('shadowsScore', setShadowsScore, 20);
|
|
639
|
+
// const handleBulkWhitesDecreaseMax = createRelativeAdjuster('whitesScore', setWhitesScore, -20);
|
|
640
|
+
// const handleBulkWhitesDecrease = createRelativeAdjuster('whitesScore', setWhitesScore, -5);
|
|
641
|
+
// const handleBulkWhitesIncrease = createRelativeAdjuster('whitesScore', setWhitesScore, 5);
|
|
642
|
+
// const handleBulkWhitesIncreaseMax = createRelativeAdjuster('whitesScore', setWhitesScore, 20);
|
|
643
|
+
// const handleBulkBlacksDecreaseMax = createRelativeAdjuster('blacksScore', setBlacksScore, -20);
|
|
644
|
+
// const handleBulkBlacksDecrease = createRelativeAdjuster('blacksScore', setBlacksScore, -5);
|
|
645
|
+
// const handleBulkBlacksIncrease = createRelativeAdjuster('blacksScore', setBlacksScore, 5);
|
|
646
|
+
// const handleBulkBlacksIncreaseMax = createRelativeAdjuster('blacksScore', setBlacksScore, 20);
|
|
647
|
+
// const handleBulkClarityDecreaseMax = createRelativeAdjuster('clarityScore', setClarityScore, -20);
|
|
648
|
+
// const handleBulkClarityDecrease = createRelativeAdjuster('clarityScore', setClarityScore, -5);
|
|
649
|
+
// const handleBulkClarityIncrease = createRelativeAdjuster('clarityScore', setClarityScore, 5);
|
|
650
|
+
// const handleBulkClarityIncreaseMax = createRelativeAdjuster('clarityScore', setClarityScore, 20);
|
|
651
|
+
// const handleBulkSharpnessDecreaseMax = createRelativeAdjuster('sharpnessScore', setSharpnessScore, -20);
|
|
652
|
+
// const handleBulkSharpnessDecrease = createRelativeAdjuster('sharpnessScore', setSharpnessScore, -5);
|
|
653
|
+
// const handleBulkSharpnessIncrease = createRelativeAdjuster('sharpnessScore', setSharpnessScore, 5);
|
|
654
|
+
// const handleBulkSharpnessIncreaseMax = createRelativeAdjuster('sharpnessScore', setSharpnessScore, 20);
|
|
593
655
|
const handleScriptReady = useCallback(async () => {
|
|
594
656
|
console.log("[Editor] Script tag is ready."); // Log entry
|
|
595
657
|
if (typeof window.Module === 'function' && !editorRef.current) {
|
|
@@ -711,11 +773,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
711
773
|
highlightsScore, shadowsScore, whitesScore, blacksScore, clarityScore, sharpnessScore
|
|
712
774
|
]);
|
|
713
775
|
const handleConfirmCopy = () => { handleCopyEdit(); handleCloseCopyDialog(); setShowCopyAlert(true); };
|
|
714
|
-
const handlePasteEdit = useCallback(() => {
|
|
715
|
-
if (copiedAdjustments) {
|
|
716
|
-
applyAdjustmentState(copiedAdjustments);
|
|
717
|
-
}
|
|
718
|
-
}, [copiedAdjustments, applyAdjustmentState]);
|
|
719
776
|
// Panel Handlers
|
|
720
777
|
const handleColorAccordionChange = (panel) => (_, isExpanded) => {
|
|
721
778
|
setColorAdjustmentExpandedPanels(prev => isExpanded ? [...new Set([...prev, panel])] : prev.filter(p => p !== panel));
|
|
@@ -725,17 +782,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
725
782
|
};
|
|
726
783
|
// MARK: - Preset Handlers
|
|
727
784
|
// Also it calls for the backend endpoint
|
|
728
|
-
const fetchPresets = useCallback(async () => {
|
|
729
|
-
if (!controller)
|
|
730
|
-
return;
|
|
731
|
-
try {
|
|
732
|
-
const fetchedPresets = await controller.getPresets(firebaseUid);
|
|
733
|
-
setPresets(fetchedPresets);
|
|
734
|
-
}
|
|
735
|
-
catch (error) {
|
|
736
|
-
console.error("Failed to fetch presets:", error);
|
|
737
|
-
}
|
|
738
|
-
}, [controller]);
|
|
739
785
|
const handleSelectMobilePreset = (presetId) => setSelectedMobilePreset(presetId);
|
|
740
786
|
const handleSelectDesktopPreset = (presetId) => setSelectedDesktopPreset(presetId);
|
|
741
787
|
const handlePresetMenuClick = (event, presetId) => {
|
|
@@ -830,8 +876,8 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
830
876
|
// 1. Set the flag to true to pause history recording
|
|
831
877
|
setIsViewingOriginal(true);
|
|
832
878
|
// 2. Apply the initial state to the view
|
|
833
|
-
applyAdjustmentState(initialAdjustments);
|
|
834
|
-
}, [isImageLoaded
|
|
879
|
+
// applyAdjustmentState(initialAdjustments);
|
|
880
|
+
}, [isImageLoaded]);
|
|
835
881
|
const handleShowEdited = useCallback(() => {
|
|
836
882
|
if (!editorRef.current || !isImageLoaded)
|
|
837
883
|
return;
|
|
@@ -839,12 +885,12 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
839
885
|
const latestState = history[historyIndex];
|
|
840
886
|
if (latestState) {
|
|
841
887
|
// 3. Re-apply the latest state from history
|
|
842
|
-
applyAdjustmentState(latestState);
|
|
888
|
+
// applyAdjustmentState(latestState);
|
|
843
889
|
}
|
|
844
890
|
// 4. Set the flag back to false AFTER the state has been restored.
|
|
845
891
|
// A small timeout ensures this runs after the re-render.
|
|
846
892
|
setTimeout(() => setIsViewingOriginal(false), 0);
|
|
847
|
-
}, [isImageLoaded, history, historyIndex
|
|
893
|
+
}, [isImageLoaded, history, historyIndex]);
|
|
848
894
|
// MARK: - Zoom Handlers
|
|
849
895
|
const handleZoomAction = useCallback((action) => {
|
|
850
896
|
let newZoom = zoomLevel;
|
|
@@ -885,76 +931,19 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
885
931
|
}
|
|
886
932
|
setZoomLevel(Math.max(0.1, Math.min(newZoom, 8)));
|
|
887
933
|
}, [zoomLevel, isImageLoaded]);
|
|
888
|
-
useEffect(() => {
|
|
889
|
-
if (canvasRef.current) {
|
|
890
|
-
canvasRef.current.style.transition = 'transform 0.1s ease-out';
|
|
891
|
-
canvasRef.current.style.transform = `scale(${zoomLevel})`;
|
|
892
|
-
}
|
|
893
|
-
}, [zoomLevel]);
|
|
894
|
-
// MARK: - Effects
|
|
895
|
-
// Preset Image List
|
|
896
|
-
useEffect(() => {
|
|
897
|
-
fetchPresets();
|
|
898
|
-
}, [controller, fetchPresets]);
|
|
899
|
-
// Image Load
|
|
900
|
-
useEffect(() => {
|
|
901
|
-
if (isImageLoaded && editorRef.current && canvasRef.current) {
|
|
902
|
-
const { width, height } = editorRef.current.getImageSize();
|
|
903
|
-
canvasRef.current.width = width;
|
|
904
|
-
canvasRef.current.height = height;
|
|
905
|
-
updateCanvas();
|
|
906
|
-
setEditorStatus("Image loaded successfully!");
|
|
907
|
-
}
|
|
908
|
-
}, [isImageLoaded, updateCanvas]);
|
|
909
934
|
// Adjustment USE EFFECTS
|
|
910
|
-
useEffect(() => { if (isImageLoaded) {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
} }, [
|
|
914
|
-
useEffect(() => { if (isImageLoaded) {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
} }, [
|
|
918
|
-
useEffect(() => { if (isImageLoaded) {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
} }, [
|
|
922
|
-
useEffect(() => { if (isImageLoaded) {
|
|
923
|
-
editorRef.current?.setHighlights(highlightsScore);
|
|
924
|
-
updateCanvas();
|
|
925
|
-
} }, [highlightsScore, isImageLoaded, updateCanvas]);
|
|
926
|
-
useEffect(() => { if (isImageLoaded) {
|
|
927
|
-
editorRef.current?.setShadows(shadowsScore);
|
|
928
|
-
updateCanvas();
|
|
929
|
-
} }, [shadowsScore, isImageLoaded, updateCanvas]);
|
|
930
|
-
useEffect(() => { if (isImageLoaded) {
|
|
931
|
-
editorRef.current?.setSaturation(saturationScore);
|
|
932
|
-
updateCanvas();
|
|
933
|
-
} }, [saturationScore, isImageLoaded, updateCanvas]);
|
|
934
|
-
useEffect(() => { if (isImageLoaded) {
|
|
935
|
-
editorRef.current?.setTemperature(tempScore);
|
|
936
|
-
updateCanvas();
|
|
937
|
-
} }, [tempScore, isImageLoaded, updateCanvas]);
|
|
938
|
-
useEffect(() => { if (isImageLoaded) {
|
|
939
|
-
editorRef.current?.setTint(tintScore);
|
|
940
|
-
updateCanvas();
|
|
941
|
-
} }, [tintScore, isImageLoaded, updateCanvas]);
|
|
942
|
-
useEffect(() => { if (isImageLoaded) {
|
|
943
|
-
editorRef.current?.setBlacks(blacksScore);
|
|
944
|
-
updateCanvas();
|
|
945
|
-
} }, [blacksScore, isImageLoaded, updateCanvas]);
|
|
946
|
-
useEffect(() => { if (isImageLoaded) {
|
|
947
|
-
editorRef.current?.setWhites(whitesScore);
|
|
948
|
-
updateCanvas();
|
|
949
|
-
} }, [whitesScore, isImageLoaded, updateCanvas]);
|
|
950
|
-
useEffect(() => { if (isImageLoaded) {
|
|
951
|
-
editorRef.current?.setClarity(clarityScore);
|
|
952
|
-
updateCanvas();
|
|
953
|
-
} }, [clarityScore, isImageLoaded, updateCanvas]);
|
|
954
|
-
useEffect(() => { if (isImageLoaded) {
|
|
955
|
-
editorRef.current?.setSharpness(sharpnessScore);
|
|
956
|
-
updateCanvas();
|
|
957
|
-
} }, [sharpnessScore, isImageLoaded, updateCanvas]);
|
|
935
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setExposure(exposureScore); updateCanvas(); } }, [exposureScore, isImageLoaded, updateCanvas]);
|
|
936
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setVibrance(vibranceScore); updateCanvas(); } }, [vibranceScore, isImageLoaded, updateCanvas]);
|
|
937
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setContrast(contrastScore); updateCanvas(); } }, [contrastScore, isImageLoaded, updateCanvas]);
|
|
938
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setHighlights(highlightsScore); updateCanvas(); } }, [highlightsScore, isImageLoaded, updateCanvas]);
|
|
939
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setShadows(shadowsScore); updateCanvas(); } }, [shadowsScore, isImageLoaded, updateCanvas]);
|
|
940
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setSaturation(saturationScore); updateCanvas(); } }, [saturationScore, isImageLoaded, updateCanvas]);
|
|
941
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setTemperature(tempScore); updateCanvas(); } }, [tempScore, isImageLoaded, updateCanvas]);
|
|
942
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setTint(tintScore); updateCanvas(); } }, [tintScore, isImageLoaded, updateCanvas]);
|
|
943
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setBlacks(blacksScore); updateCanvas(); } }, [blacksScore, isImageLoaded, updateCanvas]);
|
|
944
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setWhites(whitesScore); updateCanvas(); } }, [whitesScore, isImageLoaded, updateCanvas]);
|
|
945
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setClarity(clarityScore); updateCanvas(); } }, [clarityScore, isImageLoaded, updateCanvas]);
|
|
946
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setSharpness(sharpnessScore); updateCanvas(); } }, [sharpnessScore, isImageLoaded, updateCanvas]);
|
|
958
947
|
useEffect(() => {
|
|
959
948
|
// 5. Add a check to ignore state changes while viewing the original
|
|
960
949
|
if (!isImageLoaded || isViewingOriginal)
|
|
@@ -997,15 +986,158 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
997
986
|
}
|
|
998
987
|
};
|
|
999
988
|
}, []);
|
|
989
|
+
// MARK: DEBUG (NEW LOGIC)
|
|
990
|
+
// const { width, height } = editorRef.current.getImageSize();
|
|
991
|
+
// canvasRef.current.width = width;
|
|
992
|
+
// canvasRef.current.height = height;
|
|
993
|
+
useEffect(() => {
|
|
994
|
+
if (canvasRef.current) {
|
|
995
|
+
canvasRef.current.style.transition = 'transform 0.1s ease-out';
|
|
996
|
+
canvasRef.current.style.transform = `scale(${zoomLevel})`;
|
|
997
|
+
}
|
|
998
|
+
}, [zoomLevel]);
|
|
999
|
+
const setTempScore = (value) => {
|
|
1000
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.tempScore) : value;
|
|
1001
|
+
updateAdjustments({ tempScore: newValue });
|
|
1002
|
+
};
|
|
1003
|
+
const setTintScore = (value) => {
|
|
1004
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.tintScore) : value;
|
|
1005
|
+
updateAdjustments({ tintScore: newValue });
|
|
1006
|
+
};
|
|
1007
|
+
// ...and so on for all 12 adjustments. Here are the rest:
|
|
1008
|
+
const setVibranceScore = (value) => {
|
|
1009
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.vibranceScore) : value;
|
|
1010
|
+
updateAdjustments({ vibranceScore: newValue });
|
|
1011
|
+
};
|
|
1012
|
+
const setSaturationScore = (value) => {
|
|
1013
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.saturationScore) : value;
|
|
1014
|
+
updateAdjustments({ saturationScore: newValue });
|
|
1015
|
+
};
|
|
1016
|
+
const setExposureScore = (value) => {
|
|
1017
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.exposureScore) : value;
|
|
1018
|
+
updateAdjustments({ exposureScore: newValue });
|
|
1019
|
+
};
|
|
1020
|
+
const setHighlightsScore = (value) => {
|
|
1021
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.highlightsScore) : value;
|
|
1022
|
+
updateAdjustments({ highlightsScore: newValue });
|
|
1023
|
+
};
|
|
1024
|
+
const setShadowsScore = (value) => {
|
|
1025
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.shadowsScore) : value;
|
|
1026
|
+
updateAdjustments({ shadowsScore: newValue });
|
|
1027
|
+
};
|
|
1028
|
+
const setWhitesScore = (value) => {
|
|
1029
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.whitesScore) : value;
|
|
1030
|
+
updateAdjustments({ whitesScore: newValue });
|
|
1031
|
+
};
|
|
1032
|
+
const setBlacksScore = (value) => {
|
|
1033
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.blacksScore) : value;
|
|
1034
|
+
updateAdjustments({ blacksScore: newValue });
|
|
1035
|
+
};
|
|
1036
|
+
const setContrastScore = (value) => {
|
|
1037
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.contrastScore) : value;
|
|
1038
|
+
updateAdjustments({ contrastScore: newValue });
|
|
1039
|
+
};
|
|
1040
|
+
const setClarityScore = (value) => {
|
|
1041
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.clarityScore) : value;
|
|
1042
|
+
updateAdjustments({ clarityScore: newValue });
|
|
1043
|
+
};
|
|
1044
|
+
const setSharpnessScore = (value) => {
|
|
1045
|
+
const newValue = typeof value === 'function' ? value(currentAdjustmentsState.sharpnessScore) : value;
|
|
1046
|
+
updateAdjustments({ sharpnessScore: newValue });
|
|
1047
|
+
};
|
|
1048
|
+
// Undo, Redo, Revert
|
|
1049
|
+
const handleRevert = useCallback(() => {
|
|
1050
|
+
setCurrentAdjustmentsState(initialAdjustments);
|
|
1051
|
+
}, [updateCanvasEditor]);
|
|
1052
|
+
const handleUndo = useCallback(() => {
|
|
1053
|
+
if (historyIndex > 0) {
|
|
1054
|
+
const prevIndex = historyIndex - 1;
|
|
1055
|
+
setCurrentAdjustmentsState(history[prevIndex]);
|
|
1056
|
+
setHistoryIndex(prevIndex);
|
|
1057
|
+
}
|
|
1058
|
+
}, [history, historyIndex, updateCanvasEditor]);
|
|
1059
|
+
const handleRedo = useCallback(() => {
|
|
1060
|
+
if (historyIndex < history.length - 1) {
|
|
1061
|
+
const nextIndex = historyIndex + 1;
|
|
1062
|
+
setCurrentAdjustmentsState(history[nextIndex]);
|
|
1063
|
+
setHistoryIndex(nextIndex);
|
|
1064
|
+
}
|
|
1065
|
+
}, [history, historyIndex, updateCanvasEditor]);
|
|
1066
|
+
// Undo, Redo, Revert [END]
|
|
1067
|
+
// Swipe
|
|
1068
|
+
const swipeNext = useCallback(() => {
|
|
1069
|
+
// find next imageId
|
|
1070
|
+
// setCurrentImageId()
|
|
1071
|
+
}, []);
|
|
1072
|
+
const swipePrev = useCallback(() => {
|
|
1073
|
+
// find next imageId
|
|
1074
|
+
// setCurrentImageId()
|
|
1075
|
+
}, []);
|
|
1076
|
+
// Swipe [END]
|
|
1077
|
+
useEffect(() => {
|
|
1078
|
+
// will trigger when currentImageId change
|
|
1079
|
+
if (!currentImageId)
|
|
1080
|
+
return;
|
|
1081
|
+
const init = async () => {
|
|
1082
|
+
if (editorRef.current?.getInitialized() === false) {
|
|
1083
|
+
await editorRef.current?.initialize();
|
|
1084
|
+
}
|
|
1085
|
+
const imageData = await getImageFromId(firebaseUid, currentImageId);
|
|
1086
|
+
if (!imageData) {
|
|
1087
|
+
// TODO please check to make sure not crash
|
|
1088
|
+
throw new Error("can't load image data");
|
|
1089
|
+
}
|
|
1090
|
+
setCurrentImageData(imageData);
|
|
1091
|
+
const adjustmentData = imageData.editor_config?.color_adjustment;
|
|
1092
|
+
// set event
|
|
1093
|
+
setEventId(imageData.event_id);
|
|
1094
|
+
// TODO get slideshow image list
|
|
1095
|
+
// set to imageList
|
|
1096
|
+
const pathGallery = extractPathFromGallery(imageData);
|
|
1097
|
+
// load image to editor
|
|
1098
|
+
await loadImageEditorFromUrl(pathGallery);
|
|
1099
|
+
console.log("Image loaded to editor");
|
|
1100
|
+
// adjustment setup
|
|
1101
|
+
if (adjustmentData) {
|
|
1102
|
+
const adjustmentState = mapColorAdjustmentToAdjustmentState(adjustmentData);
|
|
1103
|
+
// set adjustment to editor to make adjustmentState change
|
|
1104
|
+
setCurrentAdjustmentsState(adjustmentState);
|
|
1105
|
+
}
|
|
1106
|
+
else {
|
|
1107
|
+
console.log("no adjustment found, use default");
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
init();
|
|
1111
|
+
}, [currentImageId, editorRef.current]);
|
|
1112
|
+
useEffect(() => {
|
|
1113
|
+
// Render photo if adjustmentState change;
|
|
1114
|
+
if (!editorRef.current)
|
|
1115
|
+
return;
|
|
1116
|
+
editorRef.current.setAdjustments(mapAdjustmentStateToAdjustmentEditor(currentAdjustmentsState));
|
|
1117
|
+
updateCanvasEditor();
|
|
1118
|
+
}, [editorRef.current, currentAdjustmentsState]);
|
|
1119
|
+
//
|
|
1000
1120
|
return {
|
|
1001
1121
|
// Refs
|
|
1002
1122
|
canvasRef,
|
|
1003
1123
|
canvasContainerRef,
|
|
1004
1124
|
fileInputRef,
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1125
|
+
// Status & State
|
|
1126
|
+
editorStatus,
|
|
1127
|
+
isEditorReady,
|
|
1128
|
+
isImageLoaded: isImageLoaded && !isGalleryLoading, // Combine loading states
|
|
1129
|
+
galleryError,
|
|
1130
|
+
// Gallery Swipe functions and state
|
|
1131
|
+
handlePrev: onSwipePrev,
|
|
1132
|
+
handleNext: onSwipeNext,
|
|
1133
|
+
isPrevAvailable,
|
|
1134
|
+
isNextAvailable,
|
|
1135
|
+
// History functions and state
|
|
1136
|
+
handleUndo: historyActions.undo,
|
|
1137
|
+
handleRedo: historyActions.redo,
|
|
1138
|
+
handleRevert: () => historyActions.reset(initialAdjustments),
|
|
1139
|
+
canUndo: historyInfo.canUndo,
|
|
1140
|
+
canRedo: historyInfo.canRedo,
|
|
1009
1141
|
// Refs for mobile panel
|
|
1010
1142
|
panelRef,
|
|
1011
1143
|
contentRef,
|
|
@@ -1015,9 +1147,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1015
1147
|
handleDragStart,
|
|
1016
1148
|
handleContentHeightChange,
|
|
1017
1149
|
// Status & State
|
|
1018
|
-
editorStatus,
|
|
1019
|
-
isEditorReady,
|
|
1020
|
-
isImageLoaded,
|
|
1021
1150
|
isPasteAvailable: copiedAdjustments !== null,
|
|
1022
1151
|
isOnline,
|
|
1023
1152
|
isConnectionSlow,
|
|
@@ -1063,9 +1192,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1063
1192
|
handleAlertClose,
|
|
1064
1193
|
loadImageFromId,
|
|
1065
1194
|
loadImageFromUrl,
|
|
1066
|
-
handleRevert,
|
|
1067
|
-
handleUndo,
|
|
1068
|
-
handleRedo,
|
|
1069
1195
|
handleOpenCopyDialog,
|
|
1070
1196
|
handleCloseCopyDialog,
|
|
1071
1197
|
copyColorChecks,
|
|
@@ -1080,7 +1206,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1080
1206
|
handleToggleCopyDialogExpand,
|
|
1081
1207
|
handleConfirmCopy,
|
|
1082
1208
|
handleCopyEdit,
|
|
1083
|
-
handlePasteEdit,
|
|
1084
1209
|
// adjustClarityBulk,
|
|
1085
1210
|
// adjustSharpnessBulk,
|
|
1086
1211
|
// Setters & Handlers
|
|
@@ -1121,18 +1246,20 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1121
1246
|
toggleBulkEditing,
|
|
1122
1247
|
handleSelectBulkPreset,
|
|
1123
1248
|
// Adjustment State & Setters
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1249
|
+
currentAdjustmentsState,
|
|
1250
|
+
setTempScore,
|
|
1251
|
+
setTintScore,
|
|
1252
|
+
setVibranceScore,
|
|
1253
|
+
setSaturationScore,
|
|
1254
|
+
setExposureScore,
|
|
1255
|
+
setHighlightsScore,
|
|
1256
|
+
setShadowsScore,
|
|
1257
|
+
setWhitesScore,
|
|
1258
|
+
setBlacksScore,
|
|
1259
|
+
setContrastScore,
|
|
1260
|
+
setClarityScore,
|
|
1261
|
+
setSharpnessScore,
|
|
1262
|
+
setCurrentAdjustmentsState,
|
|
1136
1263
|
// Bulk Adjustment Handlers
|
|
1137
1264
|
// Note: These handlers are for image list
|
|
1138
1265
|
imageList,
|
|
@@ -1141,55 +1268,55 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1141
1268
|
handleToggleImageSelection,
|
|
1142
1269
|
// Note: These handlers are for bulk adjustments
|
|
1143
1270
|
// Adjustment Colors
|
|
1144
|
-
handleBulkTempDecreaseMax,
|
|
1145
|
-
handleBulkTempDecrease,
|
|
1146
|
-
handleBulkTempIncrease,
|
|
1147
|
-
handleBulkTempIncreaseMax,
|
|
1148
|
-
handleBulkTintDecreaseMax,
|
|
1149
|
-
handleBulkTintDecrease,
|
|
1150
|
-
handleBulkTintIncrease,
|
|
1151
|
-
handleBulkTintIncreaseMax,
|
|
1152
|
-
handleBulkVibranceDecreaseMax,
|
|
1153
|
-
handleBulkVibranceDecrease,
|
|
1154
|
-
handleBulkVibranceIncrease,
|
|
1155
|
-
handleBulkVibranceIncreaseMax,
|
|
1156
|
-
handleBulkSaturationDecreaseMax,
|
|
1157
|
-
handleBulkSaturationDecrease,
|
|
1158
|
-
handleBulkSaturationIncrease,
|
|
1159
|
-
handleBulkSaturationIncreaseMax,
|
|
1160
|
-
// Adjustment Light
|
|
1161
|
-
handleBulkExposureDecreaseMax,
|
|
1162
|
-
handleBulkExposureDecrease,
|
|
1163
|
-
handleBulkExposureIncrease,
|
|
1164
|
-
handleBulkExposureIncreaseMax,
|
|
1165
|
-
handleBulkContrastDecreaseMax,
|
|
1166
|
-
handleBulkContrastDecrease,
|
|
1167
|
-
handleBulkContrastIncrease,
|
|
1168
|
-
handleBulkContrastIncreaseMax,
|
|
1169
|
-
handleBulkHighlightsDecreaseMax,
|
|
1170
|
-
handleBulkHighlightsDecrease,
|
|
1171
|
-
handleBulkHighlightsIncrease,
|
|
1172
|
-
handleBulkHighlightsIncreaseMax,
|
|
1173
|
-
handleBulkShadowsDecreaseMax,
|
|
1174
|
-
handleBulkShadowsDecrease,
|
|
1175
|
-
handleBulkShadowsIncrease,
|
|
1176
|
-
handleBulkShadowsIncreaseMax,
|
|
1177
|
-
handleBulkWhitesDecreaseMax,
|
|
1178
|
-
handleBulkWhitesDecrease,
|
|
1179
|
-
handleBulkWhitesIncrease,
|
|
1180
|
-
handleBulkWhitesIncreaseMax,
|
|
1181
|
-
handleBulkBlacksDecreaseMax,
|
|
1182
|
-
handleBulkBlacksDecrease,
|
|
1183
|
-
handleBulkBlacksIncrease,
|
|
1184
|
-
handleBulkBlacksIncreaseMax,
|
|
1185
|
-
// Adjustment Details
|
|
1186
|
-
handleBulkClarityDecreaseMax,
|
|
1187
|
-
handleBulkClarityDecrease,
|
|
1188
|
-
handleBulkClarityIncrease,
|
|
1189
|
-
handleBulkClarityIncreaseMax,
|
|
1190
|
-
handleBulkSharpnessDecreaseMax,
|
|
1191
|
-
handleBulkSharpnessDecrease,
|
|
1192
|
-
handleBulkSharpnessIncrease,
|
|
1193
|
-
handleBulkSharpnessIncreaseMax,
|
|
1271
|
+
// handleBulkTempDecreaseMax,
|
|
1272
|
+
// handleBulkTempDecrease,
|
|
1273
|
+
// handleBulkTempIncrease,
|
|
1274
|
+
// handleBulkTempIncreaseMax,
|
|
1275
|
+
// handleBulkTintDecreaseMax,
|
|
1276
|
+
// handleBulkTintDecrease,
|
|
1277
|
+
// handleBulkTintIncrease,
|
|
1278
|
+
// handleBulkTintIncreaseMax,
|
|
1279
|
+
// handleBulkVibranceDecreaseMax,
|
|
1280
|
+
// handleBulkVibranceDecrease,
|
|
1281
|
+
// handleBulkVibranceIncrease,
|
|
1282
|
+
// handleBulkVibranceIncreaseMax,
|
|
1283
|
+
// handleBulkSaturationDecreaseMax,
|
|
1284
|
+
// handleBulkSaturationDecrease,
|
|
1285
|
+
// handleBulkSaturationIncrease,
|
|
1286
|
+
// handleBulkSaturationIncreaseMax,
|
|
1287
|
+
// // Adjustment Light
|
|
1288
|
+
// handleBulkExposureDecreaseMax,
|
|
1289
|
+
// handleBulkExposureDecrease,
|
|
1290
|
+
// handleBulkExposureIncrease,
|
|
1291
|
+
// handleBulkExposureIncreaseMax,
|
|
1292
|
+
// handleBulkContrastDecreaseMax,
|
|
1293
|
+
// handleBulkContrastDecrease,
|
|
1294
|
+
// handleBulkContrastIncrease,
|
|
1295
|
+
// handleBulkContrastIncreaseMax,
|
|
1296
|
+
// handleBulkHighlightsDecreaseMax,
|
|
1297
|
+
// handleBulkHighlightsDecrease,
|
|
1298
|
+
// handleBulkHighlightsIncrease,
|
|
1299
|
+
// handleBulkHighlightsIncreaseMax,
|
|
1300
|
+
// handleBulkShadowsDecreaseMax,
|
|
1301
|
+
// handleBulkShadowsDecrease,
|
|
1302
|
+
// handleBulkShadowsIncrease,
|
|
1303
|
+
// handleBulkShadowsIncreaseMax,
|
|
1304
|
+
// handleBulkWhitesDecreaseMax,
|
|
1305
|
+
// handleBulkWhitesDecrease,
|
|
1306
|
+
// handleBulkWhitesIncrease,
|
|
1307
|
+
// handleBulkWhitesIncreaseMax,
|
|
1308
|
+
// handleBulkBlacksDecreaseMax,
|
|
1309
|
+
// handleBulkBlacksDecrease,
|
|
1310
|
+
// handleBulkBlacksIncrease,
|
|
1311
|
+
// handleBulkBlacksIncreaseMax,
|
|
1312
|
+
// // Adjustment Details
|
|
1313
|
+
// handleBulkClarityDecreaseMax,
|
|
1314
|
+
// handleBulkClarityDecrease,
|
|
1315
|
+
// handleBulkClarityIncrease,
|
|
1316
|
+
// handleBulkClarityIncreaseMax,
|
|
1317
|
+
// handleBulkSharpnessDecreaseMax,
|
|
1318
|
+
// handleBulkSharpnessDecrease,
|
|
1319
|
+
// handleBulkSharpnessIncrease,
|
|
1320
|
+
// handleBulkSharpnessIncreaseMax,
|
|
1194
1321
|
};
|
|
1195
1322
|
}
|