From 105fe00702199480d62657db6fc88c03a30d4672 Mon Sep 17 00:00:00 2001 From: ukimsanov Date: Thu, 9 Jul 2026 14:55:36 -0700 Subject: [PATCH] =?UTF-8?q?feat(studio):=20canvas=20handle=20chrome=20?= =?UTF-8?q?=E2=80=94=20dots,=20hover-reveal=20crop,=20bottom=20rotate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Selection chrome restyle per user feedback: - Corner resize handles are 9px circular dots (white fill, accent border, soft shadow) instead of 12px accent squares; pointer target stays 16px via an invisible hit square centered on the corner. - The mid-side crop bars read as mystery controls — now hover-reveal (opacity 0 at rest, fade in when the pointer enters the edge hit strip, during a crop drag, or when a crop is committed), restyled as short accent pills clearly distinct from the resize dots, with "Crop" / "Reposition crop" tooltips. Hit strips sit flush outside the crop edge; corners stay free for resize, per the component's original constraint. - Rotate handle: knob + 1px stem replaced with an attached circular-arrows chip at BOTTOM-center, 12px below the bbox — no connecting line. Rotation math is center+delta based, so handle position doesn't enter it; Shift 15-degree snap intact. Verified the bottom crop strip (0-12px) and rotate hit (from +12px) touch but don't overlap. --- .../components/editor/DomEditCropHandles.tsx | 58 ++++++++++++------- .../src/components/editor/DomEditOverlay.tsx | 15 +++-- .../components/editor/DomEditRotateHandle.tsx | 55 ++++++++++++------ 3 files changed, 84 insertions(+), 44 deletions(-) diff --git a/packages/studio/src/components/editor/DomEditCropHandles.tsx b/packages/studio/src/components/editor/DomEditCropHandles.tsx index 9f83a90ba7..0d69ca3c23 100644 --- a/packages/studio/src/components/editor/DomEditCropHandles.tsx +++ b/packages/studio/src/components/editor/DomEditCropHandles.tsx @@ -25,12 +25,16 @@ interface DomEditCropHandlesProps { onStyleCommit?: (property: string, value: string) => Promise | void; } -// Gap (px) between an edge handle and the element edge, so the handle sits -// clear of the element body and can't intercept a move-drag. -const EDGE_HANDLE_GAP = 8; +// Hit-strip size (px) for an edge crop handle: THICKNESS extends outward from +// the crop edge (flush against it, never over the element body, so a body +// drag always MOVES), LENGTH runs along the edge. The visible pill is smaller +// and centered inside the strip. +const EDGE_HIT_THICKNESS = 12; +const EDGE_HIT_LENGTH = 32; -/** Place an edge handle just OUTSIDE the given crop edge (translate pushes it - * fully past the boundary). Keeps the element body free for moving. */ +/** Place an edge handle's hit strip just OUTSIDE the given crop edge + * (translate pushes it fully past the boundary). Keeps the element body free + * for moving. Corners stay free for the selection's own resize handles. */ function edgeHandlePlacement( edge: CropEdge, rect: { left: number; top: number; width: number; height: number }, @@ -38,23 +42,15 @@ function edgeHandlePlacement( const cx = rect.left + rect.width / 2; const cy = rect.top + rect.height / 2; if (edge === "top") { - return { left: cx, top: rect.top - EDGE_HANDLE_GAP, transform: "translate(-50%, -100%)" }; + return { left: cx, top: rect.top, transform: "translate(-50%, -100%)" }; } if (edge === "bottom") { - return { - left: cx, - top: rect.top + rect.height + EDGE_HANDLE_GAP, - transform: "translate(-50%, 0)", - }; + return { left: cx, top: rect.top + rect.height, transform: "translate(-50%, 0)" }; } if (edge === "left") { - return { left: rect.left - EDGE_HANDLE_GAP, top: cy, transform: "translate(-100%, -50%)" }; + return { left: rect.left, top: cy, transform: "translate(-100%, -50%)" }; } - return { - left: rect.left + rect.width + EDGE_HANDLE_GAP, - top: cy, - transform: "translate(0, -50%)", - }; + return { left: rect.left + rect.width, top: cy, transform: "translate(0, -50%)" }; } const EDGES: CropEdge[] = ["top", "right", "bottom", "left"]; @@ -77,6 +73,7 @@ export function DomEditCropHandles({ }: DomEditCropHandlesProps) { const gestureRef = useRef(null); const [dragging, setDragging] = useState(false); + const [hotEdge, setHotEdge] = useState(null); const [state, setState] = useState(() => { const parsed = readElementCropInsets(selection.element); return { @@ -266,6 +263,7 @@ export function DomEditCropHandles({ ); })} diff --git a/packages/studio/src/components/editor/DomEditOverlay.tsx b/packages/studio/src/components/editor/DomEditOverlay.tsx index f2594b8618..d04519567b 100644 --- a/packages/studio/src/components/editor/DomEditOverlay.tsx +++ b/packages/studio/src/components/editor/DomEditOverlay.tsx @@ -58,13 +58,18 @@ const RESIZE_HANDLE_DEFS: Array<{ { handle: "se", cursor: "nwse-resize", x: "right", y: "bottom" }, ]; +// Visible dot is 9px; the pointer target is a 16px invisible square centered +// on the corner so click targets don't shrink with the smaller dot. +const RESIZE_HANDLE_HIT_PX = 16; + function resizeHandleStyle( def: (typeof RESIZE_HANDLE_DEFS)[number], cropInset?: { top: number; right: number; bottom: number; left: number }, ): React.CSSProperties { const style: React.CSSProperties = { cursor: def.cursor, touchAction: "none" }; - style[def.x] = (def.x === "left" ? (cropInset?.left ?? 0) : (cropInset?.right ?? 0)) - 6; - style[def.y] = (def.y === "top" ? (cropInset?.top ?? 0) : (cropInset?.bottom ?? 0)) - 6; + const half = RESIZE_HANDLE_HIT_PX / 2; + style[def.x] = (def.x === "left" ? (cropInset?.left ?? 0) : (cropInset?.right ?? 0)) - half; + style[def.y] = (def.y === "top" ? (cropInset?.top ?? 0) : (cropInset?.bottom ?? 0)) - half; return style; } @@ -525,13 +530,15 @@ export const DomEditOverlay = memo(function DomEditOverlay({ def.handle !== "se" && !selection.capabilities.canApplyManualOffset ? null : (
{ e.stopPropagation(); gestures.startGesture("resize", e, { resizeHandle: def.handle }); }} - /> + > +
+
), )}
diff --git a/packages/studio/src/components/editor/DomEditRotateHandle.tsx b/packages/studio/src/components/editor/DomEditRotateHandle.tsx index 846539c50c..d76cb826f8 100644 --- a/packages/studio/src/components/editor/DomEditRotateHandle.tsx +++ b/packages/studio/src/components/editor/DomEditRotateHandle.tsx @@ -1,8 +1,12 @@ import type { PointerEvent as ReactPointerEvent } from "react"; import type { OverlayRect } from "./domEditOverlayGeometry"; -/** Rotate grab-handle above the selection. Anchors to the crop outline when - * the element is cropped so it stays next to what's visible on screen. */ +/** Rotate handle below the selection: an attached circular-arrows icon chip + * (no connecting stem). Anchors to the crop outline when the element is + * cropped so it stays next to what's visible on screen. Presentation only — + * the rotation gesture measures pointer angles from the element CENTER + * (resolveDomEditRotationGesture), so the handle position doesn't affect the + * math. Sits 12px below the bbox, past the bottom crop handle's hit strip. */ export function DomEditRotateHandle({ overlayRect, cropOutlineInsetPx, @@ -15,27 +19,42 @@ export function DomEditRotateHandle({ const inset = cropOutlineInsetPx ?? { top: 0, right: 0, bottom: 0, left: 0 }; const visibleLeft = overlayRect.left + inset.left; const visibleWidth = Math.max(0, overlayRect.width - inset.left - inset.right); - const visibleTop = overlayRect.top + inset.top; + const visibleBottom = overlayRect.top + overlayRect.height - inset.bottom; return ( -
-
-
+ + + + ); }