import { Suspense, useEffect, useRef, useState } from "react"; import DragableBox from "./DragableBox"; import { PhAngle } from "./PhAngle"; type Coordinates = { x: number; y: number; } export default function CropSelector() { const [firstDragable, setFirstDragable] = useState({ x: 0, y: 0 }); const [secondDragable, setSecondDragable] = useState({ x: 100, y: 100 }); const [selectorPosition, setSelectorPosition] = useState({ x: 0, y: 0 }); const containerRef = useRef(null); // Update selector position and dimensions based on handle positions useEffect(() => { setSelectorPosition({ x: Math.min(firstDragable.x, secondDragable.x), y: Math.min(firstDragable.y, secondDragable.y) }); }, [firstDragable, secondDragable]); // Calculate selector dimensions const selectorWidth = Math.abs(secondDragable.x - firstDragable.x); const selectorHeight = Math.abs(secondDragable.y - firstDragable.y); // Handle selector drag const handleSelectorDrag = (newPosition: Coordinates) => { const deltaX = newPosition.x - selectorPosition.x; const deltaY = newPosition.y - selectorPosition.y; setFirstDragable({ x: Math.min(firstDragable.x, secondDragable.x) + deltaX, y: Math.min(firstDragable.y, secondDragable.y) + deltaY }); setSecondDragable({ x: Math.max(firstDragable.x, secondDragable.x) + deltaX, y: Math.max(firstDragable.y, secondDragable.y) + deltaY }); }; return (
); }