Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df741d8268 | ||
|
|
3f8e36f6e3 |
No files matched your search
@@ -108,6 +108,11 @@ interface ViewerProps {
|
||||
/** Eyedropper on: a click reports where (0..1 in the shown frame). */
|
||||
picking?: boolean;
|
||||
onPick?: (u: number, v: number) => void;
|
||||
/** Remove / heal tool: a click reports where (0..1 in the shown frame). */
|
||||
spotting?: boolean;
|
||||
onSpot?: (u: number, v: number) => void;
|
||||
/** Spot pins to draw over the loupe (normalized in the shown / cropped frame). */
|
||||
spotMarks?: { u: number; v: number; size: number }[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,7 +229,7 @@ export function Viewer(props: ViewerProps) {
|
||||
|
||||
// 1:1: click and drag moves the photo (the hand tool), like Lightroom.
|
||||
const pan = useRef<{ x: number; y: number; left: number; top: number; id: number } | null>(null);
|
||||
const panning = !!props.actualPixels && !props.picking && !cropping;
|
||||
const panning = !!props.actualPixels && !props.picking && !props.spotting && !cropping;
|
||||
const panHandlers = panning
|
||||
? {
|
||||
onPointerDown: (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
@@ -265,14 +270,34 @@ export function Viewer(props: ViewerProps) {
|
||||
// While cropping the photo turns under an upright crop, as in Lightroom: the engine renders it unturned
|
||||
// (the whole frame), and the straighten angle is shown here so a drag follows the pointer at once.
|
||||
style={cropping && props.crop.angle ? { transform: `rotate(${props.crop.angle}deg)` } : undefined}
|
||||
className={`block h-full w-full shadow-[0_2px_12px_rgba(0,0,0,0.7)] ${props.picking ? "cursor-crosshair" : ""}`}
|
||||
className={`block h-full w-full shadow-[0_2px_12px_rgba(0,0,0,0.7)] ${props.picking || props.spotting ? "cursor-crosshair" : ""}`}
|
||||
aria-label="Foto em revelação"
|
||||
onClick={(e) => {
|
||||
if (!props.picking) return;
|
||||
if (!props.picking && !props.spotting) return;
|
||||
const r = e.currentTarget.getBoundingClientRect();
|
||||
callbacks.current.onPick?.((e.clientX - r.left) / r.width, (e.clientY - r.top) / r.height);
|
||||
const u = (e.clientX - r.left) / r.width;
|
||||
const v = (e.clientY - r.top) / r.height;
|
||||
if (props.picking) callbacks.current.onPick?.(u, v);
|
||||
else callbacks.current.onSpot?.(u, v);
|
||||
}}
|
||||
/>
|
||||
{props.spotMarks && props.spotMarks.length > 0 && (
|
||||
<div className="pointer-events-none absolute inset-0" aria-hidden="true">
|
||||
{props.spotMarks.map((m, i) => (
|
||||
<span
|
||||
key={i}
|
||||
className="absolute rounded-full border border-white/90 bg-black/30"
|
||||
style={{
|
||||
left: `${m.u * 100}%`,
|
||||
top: `${m.v * 100}%`,
|
||||
width: `${Math.max(8, m.size * 100)}%`,
|
||||
height: `${Math.max(8, m.size * 100)}%`,
|
||||
transform: "translate(-50%, -50%)",
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{cropping && frame && (
|
||||
<CropFrame
|
||||
crop={props.crop}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { addSpot, removeSpotAt, spotsOf, spotsPartial } from "./spots.js";
|
||||
|
||||
describe("spots", () => {
|
||||
it("adds a fill spot and round-trips through merge partial", () => {
|
||||
const settings = "{}";
|
||||
const next = addSpot(settings, { mode: "fill", x: 0.4, y: 0.6, size: 0.03, feather: 40, opacity: 100 });
|
||||
expect(next).toHaveLength(1);
|
||||
expect(next[0]?.mode).toBe("fill");
|
||||
expect(next[0]?.points[0]).toEqual({ x: 0.4, y: 0.6 });
|
||||
const merged = JSON.stringify({ ...JSON.parse(settings), ...spotsPartial(next) });
|
||||
expect(spotsOf(merged)).toEqual(next);
|
||||
});
|
||||
|
||||
it("removes by index", () => {
|
||||
let spots = addSpot("{}", { mode: "remove", x: 0.1, y: 0.1, size: 0.02, feather: 50, opacity: 100 });
|
||||
spots = addSpot(JSON.stringify({ spots }), { mode: "heal", x: 0.2, y: 0.2, size: 0.02, feather: 50, opacity: 100 });
|
||||
expect(removeSpotAt(JSON.stringify({ spots }), 0)).toHaveLength(1);
|
||||
expect(removeSpotAt(JSON.stringify({ spots }), 0)[0]?.mode).toBe("heal");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
/** Spot / heal / clone / content-aware fill — LightCraft `DevelopSettings.spots` (snake_case JSON). */
|
||||
|
||||
export type SpotMode = "remove" | "heal" | "clone" | "fill";
|
||||
|
||||
export interface SpotPoint {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
export interface Spot {
|
||||
mode: SpotMode;
|
||||
points: SpotPoint[];
|
||||
/** Radius as a fraction of the long edge (LightCraft default ~0.02). */
|
||||
size: number;
|
||||
feather: number;
|
||||
opacity: number;
|
||||
source_offset?: SpotPoint | null;
|
||||
}
|
||||
|
||||
export const SPOT_MODES: { id: SpotMode; labelKey: "spotRemove" | "spotHeal" | "spotClone" | "spotFill" }[] = [
|
||||
{ id: "remove", labelKey: "spotRemove" },
|
||||
{ id: "heal", labelKey: "spotHeal" },
|
||||
{ id: "clone", labelKey: "spotClone" },
|
||||
{ id: "fill", labelKey: "spotFill" },
|
||||
];
|
||||
|
||||
export const DEFAULT_SPOT_SIZE = 0.025;
|
||||
export const DEFAULT_SPOT_FEATHER = 50;
|
||||
export const DEFAULT_SPOT_OPACITY = 100;
|
||||
|
||||
export function spotsOf(settings: string): Spot[] {
|
||||
try {
|
||||
const s = JSON.parse(settings) as { spots?: Spot[] };
|
||||
return Array.isArray(s.spots) ? s.spots : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/** Partial for `develop.merge`: replace the spots list. */
|
||||
export function spotsPartial(spots: Spot[]): Record<string, unknown> {
|
||||
return { spots };
|
||||
}
|
||||
|
||||
export function addSpot(
|
||||
settings: string,
|
||||
spot: {
|
||||
mode: SpotMode;
|
||||
x: number;
|
||||
y: number;
|
||||
size: number;
|
||||
feather: number;
|
||||
opacity: number;
|
||||
sourceOffset?: SpotPoint | null;
|
||||
},
|
||||
): Spot[] {
|
||||
const next: Spot = {
|
||||
mode: spot.mode,
|
||||
points: [{ x: clamp01(spot.x), y: clamp01(spot.y) }],
|
||||
size: clamp(spot.size, 0.002, 0.25),
|
||||
feather: clamp(spot.feather, 0, 100),
|
||||
opacity: clamp(spot.opacity, 0, 100),
|
||||
source_offset: spot.sourceOffset ?? null,
|
||||
};
|
||||
return [...spotsOf(settings), next];
|
||||
}
|
||||
|
||||
export function removeSpotAt(settings: string, index: number): Spot[] {
|
||||
return spotsOf(settings).filter((_, i) => i !== index);
|
||||
}
|
||||
|
||||
function clamp01(v: number): number {
|
||||
return Math.min(1, Math.max(0, v));
|
||||
}
|
||||
|
||||
function clamp(v: number, lo: number, hi: number): number {
|
||||
return Math.min(hi, Math.max(lo, v));
|
||||
}
|
||||
+13
-1
@@ -1243,6 +1243,18 @@ export const t = {
|
||||
saved: "Guardado",
|
||||
crop: "Recortar",
|
||||
cropDone: "Concluir",
|
||||
spot: "Apagar",
|
||||
spotDone: "Concluir",
|
||||
spotHelp: "Clica na zona a limpar (softbox, cabo, pó). Q liga a ferramenta.",
|
||||
spotNow: "Clica na foto onde queres apagar. Esc cancela.",
|
||||
spotRemove: "Remover",
|
||||
spotHeal: "Corrigir",
|
||||
spotClone: "Clonar",
|
||||
spotFill: "Preencher",
|
||||
spotSize: "Tamanho",
|
||||
spotFeather: "Suavizar",
|
||||
spotOpacity: "Opacidade",
|
||||
spotDelete: "Tirar",
|
||||
aspect: "Proporção",
|
||||
aspectFree: "Livre",
|
||||
aspectOriginal: "Original",
|
||||
@@ -1276,7 +1288,7 @@ export const t = {
|
||||
syncApply: "Aplicar",
|
||||
synced: (n: number) => `Ajustes sincronizados em ${n} ${n === 1 ? "foto" : "fotos"}`,
|
||||
noAccess: "Só podes revelar fotos que enviaste.",
|
||||
shortcuts: "← → foto · Ctrl/Cmd+A todas · P escolher · X rejeitar · U limpar · 0–5 estrelas · 6–9 cor · G grelha · I informação · Shift+A automático · \\ antes/depois · R recortar · W conta-gotas · Z 1:1 (arrastar move) · E lupa · Ctrl+Alt+1 biblioteca · Ctrl+Z anular",
|
||||
shortcuts: "← → foto · Ctrl/Cmd+A todas · P escolher · X rejeitar · U limpar · 0–5 estrelas · 6–9 cor · G grelha · I informação · Shift+A automático · \\ antes/depois · R recortar · Q apagar · W conta-gotas · Z 1:1 (arrastar move) · E lupa · Ctrl+Alt+1 biblioteca · Ctrl+Z anular",
|
||||
groups: { wb: "Equilíbrio de brancos", tone: "Tom", presence: "Presença", profile: "Perfil" },
|
||||
labels: {
|
||||
"profile.amount": "Intensidade",
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { localPhotos } from "../offline/local.js";
|
||||
import { showLocalJpeg } from "./localIngest.js";
|
||||
|
||||
describe("showLocalJpeg", () => {
|
||||
it("puts a desktop preview into the library before upload", async () => {
|
||||
for (const p of localPhotos.list()) localPhotos.remove(p.id);
|
||||
const bytes = new Uint8Array([0xff, 0xd8, 0xff, 0xd9]);
|
||||
const file = new File([bytes], "IMG_1.JPG", { type: "image/jpeg" });
|
||||
// createImageBitmap may be missing in jsdom — stub size via origin.
|
||||
const sha = await showLocalJpeg({
|
||||
file,
|
||||
eventId: "ev1",
|
||||
origin: { sha256: "abc123", size: 4, width: 100, height: 80 },
|
||||
});
|
||||
expect(sha).toBe("abc123");
|
||||
expect(localPhotos.bySha("abc123")?.eventId).toBe("ev1");
|
||||
expect(localPhotos.bySha("abc123")?.originalName).toBe("IMG_1.JPG");
|
||||
for (const p of localPhotos.list()) localPhotos.remove(p.id);
|
||||
});
|
||||
|
||||
it("skips a second put for the same sha", async () => {
|
||||
for (const p of localPhotos.list()) localPhotos.remove(p.id);
|
||||
const file = new File([new Uint8Array([1, 2, 3])], "A.JPG", { type: "image/jpeg" });
|
||||
const origin = { sha256: "same", size: 3, width: 10, height: 10 };
|
||||
await showLocalJpeg({ file, origin });
|
||||
const spy = vi.spyOn(localPhotos, "put");
|
||||
await showLocalJpeg({ file, origin });
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
spy.mockRestore();
|
||||
for (const p of localPhotos.list()) localPhotos.remove(p.id);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
import type { PhotoSummary } from "@photoreport/contracts";
|
||||
import { exifDateTime, lisbonInstant, localPhoto, localPhotos } from "../offline/local.js";
|
||||
import { localId, offlineQueue } from "../offline/queue.js";
|
||||
import type { DesktopOrigin } from "./uploads.js";
|
||||
|
||||
/** SHA-256 hex of the bytes (same fingerprint the desktop shell uses for the original). */
|
||||
export async function sha256Hex(bytes: ArrayBuffer): Promise<string> {
|
||||
const hash = await crypto.subtle.digest("SHA-256", bytes);
|
||||
return [...new Uint8Array(hash)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
||||
}
|
||||
|
||||
async function imageSize(blob: Blob): Promise<{ width: number; height: number }> {
|
||||
if (typeof createImageBitmap === "function") {
|
||||
const bmp = await createImageBitmap(blob);
|
||||
const size = { width: bmp.width, height: bmp.height };
|
||||
bmp.close();
|
||||
return size;
|
||||
}
|
||||
return await new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
const url = URL.createObjectURL(blob);
|
||||
img.onload = () => {
|
||||
resolve({ width: img.naturalWidth, height: img.naturalHeight });
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
img.onerror = () => {
|
||||
URL.revokeObjectURL(url);
|
||||
reject(new Error("decode"));
|
||||
};
|
||||
img.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts a JPEG into the library at once from bytes already on this computer. Upload can finish later;
|
||||
* `photo.added` (same sha) replaces this row. Returns the sha when the preview is on screen.
|
||||
*/
|
||||
export async function showLocalJpeg(args: {
|
||||
file: File;
|
||||
eventId?: string | undefined;
|
||||
origin?: DesktopOrigin | undefined;
|
||||
orgId?: string | undefined;
|
||||
}): Promise<string | null> {
|
||||
const { file, eventId, origin, orgId } = args;
|
||||
try {
|
||||
let sha256: string;
|
||||
let width: number;
|
||||
let height: number;
|
||||
let previewBytes: ArrayBuffer | null = null;
|
||||
if (origin && origin !== "original") {
|
||||
sha256 = origin.sha256;
|
||||
width = origin.width;
|
||||
height = origin.height;
|
||||
} else {
|
||||
previewBytes = await file.arrayBuffer();
|
||||
sha256 = await sha256Hex(previewBytes);
|
||||
const size = await imageSize(new Blob([previewBytes], { type: "image/jpeg" }));
|
||||
width = size.width;
|
||||
height = size.height;
|
||||
}
|
||||
if (localPhotos.bySha(sha256)) return sha256;
|
||||
let url = "";
|
||||
try {
|
||||
url = URL.createObjectURL(file);
|
||||
} catch {
|
||||
/* tests / no blob URLs */
|
||||
}
|
||||
const capturedAt = previewBytes ? lisbonInstant(exifDateTime(previewBytes)) : null;
|
||||
localPhotos.put(
|
||||
localPhoto({
|
||||
sha256,
|
||||
name: file.name,
|
||||
width,
|
||||
height,
|
||||
capturedAt,
|
||||
eventId: eventId ?? null,
|
||||
url,
|
||||
}),
|
||||
);
|
||||
if (orgId) {
|
||||
for (const op of offlineQueue(orgId).pending) {
|
||||
if (op.kind === "patch" && op.ids.includes(localId(sha256))) {
|
||||
localPhotos.patch(localId(sha256), op.patch as Partial<PhotoSummary>);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sha256;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** After the server has the photo: map offline edits and drop the local stand-in. */
|
||||
export function settleLocalUpload(orgId: string, sha256: string | null | undefined, photo: PhotoSummary | undefined): void {
|
||||
if (!sha256) return;
|
||||
if (photo) offlineQueue(orgId).uploaded(sha256, photo.id);
|
||||
localPhotos.remove(localId(sha256));
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { PhotoSummary } from "@photoreport/contracts";
|
||||
import { ApiError, type ApiClient } from "@photoreport/sdk";
|
||||
import { isNetworkError } from "../offline/queue.js";
|
||||
import { isNetworkError, offlineQueue } from "../offline/queue.js";
|
||||
import { useCallback, useRef, useState } from "react";
|
||||
import { settleLocalUpload, showLocalJpeg } from "./localIngest.js";
|
||||
|
||||
export type UploadStatus = "queued" | "uploading" | "done" | "duplicate" | "failed";
|
||||
|
||||
@@ -146,12 +147,21 @@ export async function sendResumable(
|
||||
}
|
||||
|
||||
/**
|
||||
* Parallel upload queue (4 at a time). New photos show up in the grid through the live channel, so the queue
|
||||
* only tracks progress. Non-JPEG files are refused before sending.
|
||||
* Parallel upload queue (4 at a time). Each JPEG is shown in the library from a local preview at once;
|
||||
* the live channel replaces it when the server has the photo. Non-JPEG files are refused before sending.
|
||||
*/
|
||||
export function useUploadQueue(api: ApiClient, orgId: string) {
|
||||
const [items, setItems] = useState<UploadItem[]>([]);
|
||||
const queue = useRef<{ item: UploadItem; file: File; eventId: string | undefined; original?: DesktopOrigin; onSettled?: (status: UploadStatus, photo?: PhotoSummary) => void }[]>([]);
|
||||
const queue = useRef<
|
||||
{
|
||||
item: UploadItem;
|
||||
file: File;
|
||||
eventId: string | undefined;
|
||||
original?: DesktopOrigin;
|
||||
sha256?: string | null;
|
||||
onSettled?: (status: UploadStatus, photo?: PhotoSummary) => void;
|
||||
}[]
|
||||
>([]);
|
||||
const running = useRef(0);
|
||||
/** No network: the queue waits (nothing fails) and carries on when the connection is back. */
|
||||
const paused = useRef(false);
|
||||
@@ -166,7 +176,7 @@ export function useUploadQueue(api: ApiClient, orgId: string) {
|
||||
const next = queue.current.shift()!;
|
||||
running.current++;
|
||||
void (async () => {
|
||||
const { item, file, eventId, original, onSettled } = next;
|
||||
const { item, file, eventId, original, sha256, onSettled } = next;
|
||||
let final: UploadStatus = "failed";
|
||||
let filed: PhotoSummary | undefined;
|
||||
let waiting = false;
|
||||
@@ -179,11 +189,11 @@ export function useUploadQueue(api: ApiClient, orgId: string) {
|
||||
file,
|
||||
eventId,
|
||||
(p) => {
|
||||
const now = Date.now();
|
||||
if (now - lastTick > 150 || p === 1) {
|
||||
lastTick = now;
|
||||
update(item.id, { progress: p });
|
||||
}
|
||||
const now = Date.now();
|
||||
if (now - lastTick > 150 || p === 1) {
|
||||
lastTick = now;
|
||||
update(item.id, { progress: p });
|
||||
}
|
||||
},
|
||||
original,
|
||||
);
|
||||
@@ -215,7 +225,13 @@ export function useUploadQueue(api: ApiClient, orgId: string) {
|
||||
}
|
||||
} else update(item.id, { status: "failed", error: (err as Error).message });
|
||||
} finally {
|
||||
if (!waiting) onSettled?.(final, filed);
|
||||
if (!waiting) {
|
||||
if (final === "done" || final === "duplicate") {
|
||||
settleLocalUpload(orgId, sha256, filed);
|
||||
void offlineQueue(orgId).flush(api);
|
||||
}
|
||||
onSettled?.(final, filed);
|
||||
}
|
||||
running.current--;
|
||||
pump();
|
||||
}
|
||||
@@ -236,14 +252,24 @@ export function useUploadQueue(api: ApiClient, orgId: string) {
|
||||
continue;
|
||||
}
|
||||
added.push(item);
|
||||
queue.current.push({ item, file, eventId, ...(original && { original }), ...(onSettled && { onSettled: (status: UploadStatus, photo?: PhotoSummary) => onSettled(file, status, photo) }) });
|
||||
// Preview in the grid before the bytes leave this computer (USB, drop, FTP share this path).
|
||||
void (async () => {
|
||||
const sha256 = await showLocalJpeg({ file, eventId, origin: original, orgId });
|
||||
queue.current.push({
|
||||
item,
|
||||
file,
|
||||
eventId,
|
||||
...(original && { original }),
|
||||
sha256,
|
||||
...(onSettled && { onSettled: (status: UploadStatus, photo?: PhotoSummary) => onSettled(file, status, photo) }),
|
||||
});
|
||||
pump();
|
||||
})();
|
||||
}
|
||||
setItems((list) => [...list.filter((i) => i.status !== "done" && i.status !== "duplicate"), ...added]);
|
||||
pump();
|
||||
},
|
||||
[pump],
|
||||
[orgId, pump],
|
||||
);
|
||||
|
||||
const clear = useCallback(() => setItems((list) => list.filter((i) => i.status === "queued" || i.status === "uploading")), []);
|
||||
|
||||
return { items, add, clear };
|
||||
|
||||
@@ -12,6 +12,17 @@ import { type Crop, cropOf, DevelopSession, localOutbox } from "../develop/sessi
|
||||
import { SyncSettingsButton } from "../develop/SyncSettings.js";
|
||||
import { commandsFrom, queueSync } from "../develop/copySettings.js";
|
||||
import { clampUnit, constrainRotated, fitAspect, GUIDES, type Guide, rotateAspect } from "../develop/crop.js";
|
||||
import {
|
||||
addSpot,
|
||||
DEFAULT_SPOT_FEATHER,
|
||||
DEFAULT_SPOT_OPACITY,
|
||||
DEFAULT_SPOT_SIZE,
|
||||
removeSpotAt,
|
||||
SPOT_MODES,
|
||||
spotsOf,
|
||||
spotsPartial,
|
||||
type SpotMode,
|
||||
} from "../develop/spots.js";
|
||||
import { engineAuto, Viewer } from "../develop/Viewer.js";
|
||||
import { IptcInfo } from "../library/IptcInfo.js";
|
||||
import { activePhoto, savedFilter, saveFilter, setActivePhoto } from "../library/active.js";
|
||||
@@ -342,12 +353,21 @@ export function DevelopPage() {
|
||||
e.preventDefault();
|
||||
flagCurrent(patchForKey(e.key)!);
|
||||
}
|
||||
else if (e.key.toLowerCase() === "r" && canEdit) setCropping((c) => !c);
|
||||
else if (e.key.toLowerCase() === "w" && canEdit) setPicking((p) => !p);
|
||||
else if (e.key.toLowerCase() === "z") setOneToOne((z) => !z);
|
||||
else if (e.key.toLowerCase() === "r" && canEdit) {
|
||||
setSpotting(false);
|
||||
setCropping((c) => !c);
|
||||
} else if (e.key.toLowerCase() === "q" && canEdit) {
|
||||
setCropping(false);
|
||||
setPicking(false);
|
||||
setSpotting((s) => !s);
|
||||
} else if (e.key.toLowerCase() === "w" && canEdit) {
|
||||
setSpotting(false);
|
||||
setPicking((p) => !p);
|
||||
} else if (e.key.toLowerCase() === "z") setOneToOne((z) => !z);
|
||||
else if (e.key === "Escape") {
|
||||
setCropping(false);
|
||||
setPicking(false);
|
||||
setSpotting(false);
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
@@ -356,6 +376,7 @@ export function DevelopPage() {
|
||||
|
||||
const settings = session?.loaded ? session.settings : null;
|
||||
const crop = useMemo(() => (settings ? cropOf(settings) : { rect: { x0: 0, y0: 0, x1: 1, y1: 1 }, angle: 0, aspect: null }), [settings]);
|
||||
const spots = useMemo(() => (settings ? spotsOf(settings) : []), [settings]);
|
||||
const shown = settings && before && typeof engine === "object" ? engine.defaultSettings() : settings;
|
||||
|
||||
const setValue = useCallback(
|
||||
@@ -366,9 +387,57 @@ export function DevelopPage() {
|
||||
[session],
|
||||
);
|
||||
const [picking, setPicking] = useState(false);
|
||||
const [spotting, setSpotting] = useState(false);
|
||||
const [spotMode, setSpotMode] = useState<SpotMode>("remove");
|
||||
const [spotSize, setSpotSize] = useState(DEFAULT_SPOT_SIZE);
|
||||
const [spotFeather, setSpotFeather] = useState(DEFAULT_SPOT_FEATHER);
|
||||
const [spotOpacity, setSpotOpacity] = useState(DEFAULT_SPOT_OPACITY);
|
||||
|
||||
const placeSpot = useCallback(
|
||||
(u: number, v: number) => {
|
||||
if (!session?.loaded || !canEdit) return;
|
||||
const r = crop.rect;
|
||||
const x = r.x0 + u * (r.x1 - r.x0);
|
||||
const y = r.y0 + v * (r.y1 - r.y0);
|
||||
const next = addSpot(session.settings, {
|
||||
mode: spotMode,
|
||||
x,
|
||||
y,
|
||||
size: spotSize,
|
||||
feather: spotFeather,
|
||||
opacity: spotOpacity,
|
||||
});
|
||||
session.edit({ command: "develop.merge", params: { partial: spotsPartial(next) } });
|
||||
session.endGesture();
|
||||
},
|
||||
[session, canEdit, crop.rect, spotMode, spotSize, spotFeather, spotOpacity],
|
||||
);
|
||||
|
||||
const deleteSpot = useCallback(
|
||||
(index: number) => {
|
||||
if (!session?.loaded || !canEdit) return;
|
||||
session.edit({ command: "develop.merge", params: { partial: spotsPartial(removeSpotAt(session.settings, index)) } });
|
||||
session.endGesture();
|
||||
},
|
||||
[session, canEdit],
|
||||
);
|
||||
|
||||
const spotMarks = useMemo(() => {
|
||||
if (!spotting || !spots.length) return [];
|
||||
const r = crop.rect;
|
||||
const rw = r.x1 - r.x0 || 1;
|
||||
const rh = r.y1 - r.y0 || 1;
|
||||
return spots
|
||||
.map((s) => {
|
||||
const p = s.points[0];
|
||||
if (!p) return null;
|
||||
return { u: (p.x - r.x0) / rw, v: (p.y - r.y0) / rh, size: s.size / Math.max(rw, rh) };
|
||||
})
|
||||
.filter((m): m is { u: number; v: number; size: number } => !!m && m.u >= -0.05 && m.u <= 1.05 && m.v >= -0.05 && m.v <= 1.05);
|
||||
}, [spotting, spots, crop.rect]);
|
||||
|
||||
/** 1:1 view, and where its full-resolution original stands. */
|
||||
const [oneToOne, setOneToOne] = useState(false);
|
||||
const [fullState, setFullState] = useState<"idle" | "waiting" | "ready" | "missing">("idle");
|
||||
const [oneToOne, setOneToOne] = useState(false); const [fullState, setFullState] = useState<"idle" | "waiting" | "ready" | "missing">("idle");
|
||||
useEffect(() => {
|
||||
setOneToOne(false);
|
||||
setFullState("idle");
|
||||
@@ -625,13 +694,16 @@ export function DevelopPage() {
|
||||
{...(oneToOne || current.originalName.toLowerCase().endsWith(".dng") || current.name.toLowerCase().endsWith(".dng")
|
||||
? { localSource: fullSource }
|
||||
: isDesktop() && { localSource: () => localOriginalToView(current.sha256) })}
|
||||
picking={picking && !cropping && !before}
|
||||
picking={picking && !cropping && !spotting && !before}
|
||||
onPick={(u, v) => {
|
||||
setPicking(false);
|
||||
// The view shows the cropped frame: map back to the whole frame (straighten angle ignored).
|
||||
const r = crop.rect;
|
||||
void autoValues("pick", { x: r.x0 + u * (r.x1 - r.x0), y: r.y0 + v * (r.y1 - r.y0) });
|
||||
}}
|
||||
spotting={spotting && !cropping && !before}
|
||||
onSpot={placeSpot}
|
||||
spotMarks={spotMarks}
|
||||
onCrop={(rect, final) => {
|
||||
setDragging(!final);
|
||||
session?.edit({ command: "crop.set", params: { rect: clampUnit(rect), angle: crop.angle, aspect: crop.aspect } }, "crop");
|
||||
@@ -651,13 +723,103 @@ export function DevelopPage() {
|
||||
{oneToOne && fullState === "waiting" && <p className="border-b border-line bg-accent/20 px-3 py-2 text-[12px] text-ink">{t.dev.fullWaiting}</p>}
|
||||
{oneToOne && fullState === "missing" && <p className="border-b border-line px-3 py-2 text-[12px] text-[#f0a35a]">{t.dev.fullMissing}</p>}
|
||||
{picking && <p className="border-b border-line bg-accent/20 px-3 py-2 text-[12px] text-ink">{t.dev.pickWbNow}</p>}
|
||||
{spotting && <p className="border-b border-line bg-accent/20 px-3 py-2 text-[12px] text-ink">{t.dev.spotNow}</p>}
|
||||
{!canEdit && current && <p className="border-b border-line px-3 py-2 text-[12px] text-faint">{t.dev.noAccess}</p>}
|
||||
<Section title={t.dev.spot}>
|
||||
<div className="mb-2 flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
disabled={!canEdit}
|
||||
onClick={() => {
|
||||
setCropping(false);
|
||||
setPicking(false);
|
||||
setSpotting((s) => !s);
|
||||
}}
|
||||
aria-pressed={spotting}
|
||||
className={`h-7 border border-black px-3 text-[12px] disabled:opacity-40 ${spotting ? "bg-accent text-white" : "bg-cell"}`}
|
||||
>
|
||||
{spotting ? t.dev.spotDone : t.dev.spot}
|
||||
</button>
|
||||
<span className="text-[11px] text-faint">{t.dev.spotHelp}</span>
|
||||
</div>
|
||||
<div className="mb-2 flex flex-wrap gap-1">
|
||||
{SPOT_MODES.map((m) => (
|
||||
<button
|
||||
key={m.id}
|
||||
disabled={!canEdit}
|
||||
onClick={() => setSpotMode(m.id)}
|
||||
aria-pressed={spotMode === m.id}
|
||||
className={`h-6 border border-black px-2 text-[11px] disabled:opacity-40 ${spotMode === m.id ? "bg-cell-on text-ink" : "bg-cell text-muted"}`}
|
||||
>
|
||||
{t.dev[m.labelKey]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<label className="mb-2 block text-[11px] text-faint">
|
||||
{t.dev.spotSize}
|
||||
<input
|
||||
type="range"
|
||||
min={0.005}
|
||||
max={0.12}
|
||||
step={0.001}
|
||||
value={spotSize}
|
||||
disabled={!canEdit}
|
||||
onChange={(e) => setSpotSize(Number(e.target.value))}
|
||||
className="mt-1 w-full"
|
||||
/>
|
||||
</label>
|
||||
<label className="mb-2 block text-[11px] text-faint">
|
||||
{t.dev.spotFeather}
|
||||
<input
|
||||
type="range"
|
||||
min={0}
|
||||
max={100}
|
||||
step={1}
|
||||
value={spotFeather}
|
||||
disabled={!canEdit}
|
||||
onChange={(e) => setSpotFeather(Number(e.target.value))}
|
||||
className="mt-1 w-full"
|
||||
/>
|
||||
</label>
|
||||
<label className="mb-2 block text-[11px] text-faint">
|
||||
{t.dev.spotOpacity}
|
||||
<input
|
||||
type="range"
|
||||
min={0}
|
||||
max={100}
|
||||
step={1}
|
||||
value={spotOpacity}
|
||||
disabled={!canEdit}
|
||||
onChange={(e) => setSpotOpacity(Number(e.target.value))}
|
||||
className="mt-1 w-full"
|
||||
/>
|
||||
</label>
|
||||
{spots.length > 0 && (
|
||||
<ul className="mt-1 max-h-28 space-y-1 overflow-y-auto text-[11px]">
|
||||
{spots.map((s, i) => {
|
||||
const label = SPOT_MODES.find((m) => m.id === s.mode);
|
||||
return (
|
||||
<li key={i} className="flex items-center justify-between gap-2 border border-line bg-cell px-2 py-1">
|
||||
<span className="truncate text-muted">
|
||||
{label ? t.dev[label.labelKey] : s.mode} · {i + 1}
|
||||
</span>
|
||||
<button type="button" disabled={!canEdit} className="text-ink underline disabled:opacity-40" onClick={() => deleteSpot(i)}>
|
||||
{t.dev.spotDelete}
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</Section>
|
||||
{modules.includes("crop") && (
|
||||
<Section title={t.modules.crop}>
|
||||
<div className="mb-2 flex items-center gap-2">
|
||||
<button
|
||||
disabled={!canEdit}
|
||||
onClick={() => setCropping(!cropping)}
|
||||
onClick={() => {
|
||||
setSpotting(false);
|
||||
setCropping(!cropping);
|
||||
}}
|
||||
aria-pressed={cropping}
|
||||
className={`h-7 border border-black px-3 text-[12px] disabled:opacity-40 ${cropping ? "bg-accent text-white" : "bg-cell"}`}
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user