mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 22:48:55 +00:00
feat(studio): canvas handle chrome — dots, hover-reveal crop, bottom rotate
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.
This commit is contained in:
@@ -25,12 +25,16 @@ interface DomEditCropHandlesProps {
|
||||
onStyleCommit?: (property: string, value: string) => Promise<void> | 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<CropGestureState | null>(null);
|
||||
const [dragging, setDragging] = useState(false);
|
||||
const [hotEdge, setHotEdge] = useState<CropEdge | null>(null);
|
||||
const [state, setState] = useState(() => {
|
||||
const parsed = readElementCropInsets(selection.element);
|
||||
return {
|
||||
@@ -266,6 +263,7 @@ export function DomEditCropHandles({
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Reposition crop"
|
||||
title="Reposition crop"
|
||||
data-dom-edit-crop-handle="true"
|
||||
className="pointer-events-auto absolute rounded-full border-2 border-studio-accent bg-studio-accent/30 shadow-[0_0_0_1px_rgba(0,0,0,0.4)]"
|
||||
style={{
|
||||
@@ -285,31 +283,47 @@ export function DomEditCropHandles({
|
||||
)}
|
||||
{/* Edge handles — drag a side to crop it. Positioned just OUTSIDE the crop
|
||||
edge (via edgeHandlePlacement) so they never overlap the element body:
|
||||
dragging the body always MOVES, only a handle crops. */}
|
||||
dragging the body always MOVES, only a handle crops. The pill is
|
||||
hover-revealed (or shown while dragging / once a crop exists) so the
|
||||
resting selection chrome stays uncluttered; the hit strip is always
|
||||
live, and the title names the affordance. */}
|
||||
{EDGES.map((edge) => {
|
||||
const vertical = edge === "left" || edge === "right";
|
||||
const place = edgeHandlePlacement(edge, cropRect);
|
||||
const revealed = dragging || hasCrop || hotEdge === edge;
|
||||
return (
|
||||
<button
|
||||
key={edge}
|
||||
type="button"
|
||||
aria-label={`Crop ${edge}`}
|
||||
title="Crop"
|
||||
data-dom-edit-crop-handle="true"
|
||||
className="pointer-events-auto absolute rounded-full bg-studio-accent shadow-[0_0_0_1px_rgba(0,0,0,0.4)]"
|
||||
className="pointer-events-auto absolute flex items-center justify-center border-0 bg-transparent p-0"
|
||||
style={{
|
||||
left: place.left,
|
||||
top: place.top,
|
||||
width: vertical ? 5 : 26,
|
||||
height: vertical ? 26 : 5,
|
||||
width: vertical ? EDGE_HIT_THICKNESS : EDGE_HIT_LENGTH,
|
||||
height: vertical ? EDGE_HIT_LENGTH : EDGE_HIT_THICKNESS,
|
||||
transform: place.transform,
|
||||
cursor: vertical ? "ew-resize" : "ns-resize",
|
||||
touchAction: "none",
|
||||
}}
|
||||
onPointerEnter={() => setHotEdge(edge)}
|
||||
onPointerLeave={() => setHotEdge((prev) => (prev === edge ? null : prev))}
|
||||
onPointerDown={(event) => startCropGesture(edge, event)}
|
||||
onPointerMove={updateCropGesture}
|
||||
onPointerUp={finishCropGesture}
|
||||
onPointerCancel={cancelCropGesture}
|
||||
/>
|
||||
>
|
||||
<span
|
||||
className="pointer-events-none rounded-full bg-studio-accent/90 shadow-[0_0_0_1px_rgba(0,0,0,0.4)] transition-opacity duration-100"
|
||||
style={{
|
||||
width: vertical ? 4 : 24,
|
||||
height: vertical ? 24 : 4,
|
||||
opacity: revealed ? 1 : 0,
|
||||
}}
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
|
||||
@@ -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 : (
|
||||
<div
|
||||
key={def.handle}
|
||||
className="absolute w-3 h-3 rounded-sm bg-studio-accent border border-studio-accent/60"
|
||||
className="absolute flex h-4 w-4 items-center justify-center"
|
||||
style={resizeHandleStyle(def, cropOutlineInsetPx ?? undefined)}
|
||||
onPointerDown={(e) => {
|
||||
e.stopPropagation();
|
||||
gestures.startGesture("resize", e, { resizeHandle: def.handle });
|
||||
}}
|
||||
/>
|
||||
>
|
||||
<div className="pointer-events-none h-[9px] w-[9px] rounded-full border-[1.5px] border-studio-accent bg-white shadow-[0_0_3px_rgba(0,0,0,0.45)]" />
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -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 (
|
||||
<div
|
||||
className="pointer-events-none absolute"
|
||||
<button
|
||||
type="button"
|
||||
className="pointer-events-auto absolute flex items-center justify-center border-0 bg-transparent p-0"
|
||||
style={{
|
||||
left: visibleLeft + visibleWidth / 2,
|
||||
top: visibleTop - 34,
|
||||
width: 28,
|
||||
height: 34,
|
||||
top: visibleBottom + 12,
|
||||
width: 22,
|
||||
height: 22,
|
||||
transform: "translateX(-50%)",
|
||||
cursor: "grab",
|
||||
touchAction: "none",
|
||||
}}
|
||||
title="Rotate"
|
||||
aria-label="Rotate selection"
|
||||
onPointerDown={onStartRotate}
|
||||
>
|
||||
<div className="absolute left-1/2 top-3 bottom-0 w-px -translate-x-1/2 bg-studio-accent/60" />
|
||||
<button
|
||||
type="button"
|
||||
className="pointer-events-auto absolute left-1/2 top-0 h-3 w-3 -translate-x-1/2 rounded-full border border-studio-accent bg-studio-accent p-0 shadow-[0_0_0_2px_rgba(60,230,172,0.18)]"
|
||||
style={{ cursor: "grab", touchAction: "none" }}
|
||||
title="Rotate"
|
||||
aria-label="Rotate selection"
|
||||
onPointerDown={onStartRotate}
|
||||
/>
|
||||
</div>
|
||||
<span className="pointer-events-none flex h-[18px] w-[18px] items-center justify-center rounded-full border border-studio-accent/70 bg-studio-surface text-studio-accent shadow-[0_0_3px_rgba(0,0,0,0.45)]">
|
||||
<svg
|
||||
width="11"
|
||||
height="11"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8" />
|
||||
<path d="M21 3v5h-5" />
|
||||
<path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16" />
|
||||
<path d="M8 16H3v5" />
|
||||
</svg>
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user