Spaces:
Running
Running
Commit ·
4fe0fa4
1
Parent(s): 78167bc
fix: make image resizing smooth, allow side distortion, aspect ratio locking on corners, and stylize handles
Browse files41 unmodified lines4243444546474849505137 unmodified lines8990919293949516 unmodified lines11211311411511611711841 unmodified lines}}, [data.url]);// Re-calculate handles when local size changesuseEffect(() => {updateNodeInternals(id);}, [id, localSize, updateNodeInternals]);const handleImageLoad = (e) => {const { naturalWidth, naturalHeight } = e.target;37 unmodified linesisVisible={selected}minWidth={50}minHeight={50}keepAspectRatio={true}onResize={(e, params) => {setLocalSize({ width: params.width, height: params.height });}}16 unmodified linessrc={imageUrl}alt="Canvas Asset"onLoad={handleImageLoad}className="w-full h-full object-cover pointer-events-none select-none rounded-lg"/>) : (<div className="w-full h-full min-h-[100px] bg-secondary/5 flex flex-col items-center justify-center gap-2 p-4 text-center border-2 border-dashed border-primary/10">41 unmodified lines4243444546474849505152535455565758596061626337 unmodified lines10110210310410510610710810911016 unmodified lines12712812913013113213341 unmodified lines}}, [data.url]);// Re-calculate handles when data dimensions update (instead of on every pixel movement to eliminate lag)useEffect(() => {updateNodeInternals(id);}, [id, data.width, data.height, updateNodeInternals]);const [keepRatio, setKeepRatio] = useState(false);const handleResizeStart = (e) => {const classList = e.target.classList;// Check if dragging via corners to keep aspect ratio, otherwise allow distortion on sidesconst isCorner = classList.contains('top-left') ||classList.contains('top-right') ||classList.contains('bottom-left') ||classList.contains('bottom-right');setKeepRatio(isCorner);};const handleImageLoad = (e) => {const { naturalWidth, naturalHeight } = e.target;37 unmodified linesisVisible={selected}minWidth={50}minHeight={50}keepAspectRatio={keepRatio}onResizeStart={handleResizeStart}lineClassName="!border-primary !border-2 !border-dashed opacity-60"handleClassName="!w-3.5 !h-3.5 !bg-surface-container-lowest !border-2 !border-primary !rounded-md !shadow-[2px_2px_0px_0px_var(--color-primary)] hover:!scale-110 active:!scale-95 transition-transform"onResize={(e, params) => {setLocalSize({ width: params.width, height: params.height });}}16 unmodified linessrc={imageUrl}alt="Canvas Asset"onLoad={handleImageLoad}className="w-full h-full object-fill pointer-events-none select-none rounded-lg"/>) : (<div className="w-full h-full min-h-[100px] bg-secondary/5 flex flex-col items-center justify-center gap-2 p-4 text-center border-2 border-dashed border-primary/10">
src/features/canvas/components/nodes/ImageNode.jsx+19-4