Files
UmbraCi 79d646b904 feat(editor): support image corner drag resizing with aspect ratio lock (#12690)
* feat(editor): support image corner drag resizing with aspect ratio lock

- Implement circular corner drag handles (ResizeTopLeft, ResizeTopRight, ResizeBottomLeft, ResizeBottomRight) using theme selection color.

- Update useDragResize hook to track coordinates as {x,y} object and handle aspect-ratio locked sizing for corner drags.

- Set overflow: visible on ImageWrapper to prevent corner handles from being clipped, and fade them in on hover.

* refactor(editor): simplify ResizeCorner styles by removing background and shadow properties

* fix(editor): fix corner resize speed and sync inputs in real-time

* fix(editor): improve corner resize cursor tracking and drag cursors

Project corner drag deltas onto the aspect-ratio vector so resizing
follows the pointer at 1x speed. Add a body class and global cursor
styles during image/media resize drags.

* refactor(editor): use relative import path inside shared directory

* fix(editor): resolve typescript type mismatch on dragging property in PDF component
2026-06-24 21:05:50 -04:00

103 lines
1.9 KiB
TypeScript

import styled from "styled-components";
import { s } from "../../styles";
export const ResizeLeft = styled.div<{ $dragging: boolean }>`
cursor: ew-resize;
position: absolute;
left: -4px;
top: 30%;
bottom: 30%;
width: 8px;
user-select: none;
opacity: ${(props) => (props.$dragging ? 1 : 0)};
transition: opacity 150ms ease-in-out;
&:after {
content: "";
position: absolute;
left: 8px;
top: 50%;
transform: translateY(-50%);
width: 6px;
height: 25%;
min-height: 20px;
border-radius: 4px;
background: ${s("menuBackground")};
box-shadow: 0 0 0 1px ${s("textSecondary")};
opacity: 0.75;
}
@media print {
display: none;
}
`;
export const ResizeRight = styled(ResizeLeft)`
left: initial;
right: -4px;
&:after {
left: initial;
right: 8px;
}
`;
export const ResizeBottom = styled(ResizeLeft)`
cursor: ns-resize;
left: 30%;
right: 30%;
top: initial;
bottom: 8px;
width: auto;
height: 8px;
&:after {
left: 50%;
bottom: 8px;
transform: translateX(-50%);
width: 25%;
height: 6px;
min-width: 20px;
min-height: 0;
}
`;
export const ResizeCorner = styled.div<{ $dragging: boolean }>`
position: absolute;
width: 8px;
height: 8px;
border-radius: 50%;
z-index: 10;
user-select: none;
opacity: ${(props) => (props.$dragging ? 1 : 0)};
transition: opacity 150ms ease-in-out;
@media print {
display: none;
}
`;
export const ResizeTopLeft = styled(ResizeCorner)`
cursor: nwse-resize;
top: -4px;
left: -4px;
`;
export const ResizeTopRight = styled(ResizeCorner)`
cursor: nesw-resize;
top: -4px;
right: -4px;
`;
export const ResizeBottomLeft = styled(ResizeCorner)`
cursor: nesw-resize;
bottom: -4px;
left: -4px;
`;
export const ResizeBottomRight = styled(ResizeCorner)`
cursor: nwse-resize;
bottom: -4px;
right: -4px;
`;