feat(erase-object): auto-center compare slider at erased region

Track the painted mask centroid and initialise the before/after slider
at that position so the result is immediately visible without manual
dragging.
This commit is contained in:
Siddharth Kumar Sah
2026-04-15 23:11:27 +08:00
parent dd1e2e5ba5
commit a8cca62336
6 changed files with 52 additions and 3 deletions
@@ -9,6 +9,8 @@ interface BeforeAfterSliderProps {
beforeSize?: number;
/** Processed file size in bytes. */
afterSize?: number;
/** Initial divider position as a percentage (0100). Defaults to 50. */
initialPosition?: number;
}
function formatSize(bytes: number): string {
@@ -29,9 +31,10 @@ export function BeforeAfterSlider({
afterSrc,
beforeSize,
afterSize,
initialPosition = 50,
}: BeforeAfterSliderProps) {
const containerRef = useRef<HTMLDivElement>(null);
const [position, setPosition] = useState(50); // percentage 0-100
const [position, setPosition] = useState(initialPosition); // percentage 0-100
const [isDragging, setIsDragging] = useState(false);
const updatePosition = useCallback((clientX: number) => {