🎥 Make videos programmatically with React
`@remotion/studio`: Add outline rotation handles (#8255)
Jonny Burger06135ec3a87e
diff --git a/packages/studio/src/components/SelectedOutlineOverlay.tsx b/packages/studio/src/components/SelectedOutlineOverlay.tsxindex d1a188969b..b1b7b83cd3 100644--- a/packages/studio/src/components/SelectedOutlineOverlay.tsx+++ b/packages/studio/src/components/SelectedOutlineOverlay.tsx@@ -27,6 +27,10 @@ import {getEffectDragData,hasEffectDragType,} from './effect-drag-and-drop';+import {+ forceSpecificCursor,+ stopForcingSpecificCursor,+} from './ForceSpecificCursor';import type {ComboboxValue} from './NewComposition/ComboBox';import {showNotification} from './Notifications/NotificationCenter';import {@@ -48,6 +52,10 @@ import {saveSequenceProps,type SaveSequencePropChange,} from './Timeline/save-sequence-prop';+import {+ parseCssRotationToDegrees,+ serializeCssRotation,+} from './Timeline/timeline-rotation-utils';import {parseTranslate,serializeTranslate,@@ -56,9 +64,9 @@ import {getLinkedScale} from './Timeline/TimelineScaleField';import {ENABLE_OUTLINES,getTimelineSequenceSelectionKey,+ useTimelineSelection,type TimelineSelection,type TimelineSelectionInteraction,- useTimelineSelection,} from './Timeline/TimelineSelection';import {getOriginalLocationFromStack} from './Timeline/TimelineStack/get-stack';@@ -82,6 +90,7 @@ type SelectedOutlineTarget = {readonly sequence: TSequence;readonly drag: SelectedOutlineDragTarget | null;readonly scaleDrag: SelectedOutlineScaleDragTarget | null;+ readonly rotationDrag: SelectedOutlineRotationDragTarget | null;readonly uvHandles: readonly SelectedOutlineUvHandle[];};@@ -103,6 +112,7 @@ type SelectedOutlineDragTarget = {};type ScaleFieldSchema = Extract<SequenceFieldSchema, {type: 'scale'}>;+type RotationFieldSchema = Extract<SequenceFieldSchema, {type: 'rotation-css'}>;type SelectedOutlineScaleDragTarget = {readonly propStatus: CanUpdateSequencePropStatusStatic;@@ -114,6 +124,18 @@ type SelectedOutlineScaleDragTarget = {readonly schema: SequenceSchema;};+type SelectedOutlineRotationDragTarget = {+ readonly propStatus:+ | CanUpdateSequencePropStatusStatic+ | CanUpdateSequencePropStatusKeyframed;+ readonly clientId: string;+ readonly fieldDefault: string | undefined;+ readonly fieldSchema: RotationFieldSchema;+ readonly keyframeDisplayOffset: number;+ readonly nodePath: SequencePropsSubscriptionKey;+ readonly schema: SequenceSchema;+};+export type SelectedOutlineDragState = {readonly defaultValue: string | null;readonly key: string;@@ -132,6 +154,14 @@ export type SelectedOutlineScaleDragState = {readonly target: SelectedOutlineScaleDragTarget;};+export type SelectedOutlineRotationDragState = {+ readonly defaultValue: string | null;+ readonly key: string;+ readonly sourceFrame: number;+ readonly startDegrees: number;+ readonly target: SelectedOutlineRotationDragTarget;+};+type SequenceWithSelectedOutline = {readonly depth: number;readonly keyframeDisplayOffset: number;@@ -142,6 +172,7 @@ type SequenceWithSelectedOutline = {const translateFieldKey = 'style.translate';const scaleFieldKey = 'style.scale';+const rotateFieldKey = 'style.rotate';const outlineContainer: React.CSSProperties = {position: 'absolute',@@ -158,6 +189,14 @@ const midpoint = (from: OutlinePoint, to: OutlinePoint): OutlinePoint => {return mixPoint(from, to, 0.5);};+const getOutlineCenter = (points: SelectedOutline['points']): OutlinePoint => {+ const [tl, tr, br, bl] = points;+ return {+ x: (tl.x + tr.x + br.x + bl.x) / 4,+ y: (tl.y + tr.y + br.y + bl.y) / 4,+ };+};+const dot = (left: OutlinePoint, right: OutlinePoint): number => {return left.x * right.x + left.y * right.y;};@@ -170,6 +209,86 @@ const vectorBetween = (from: OutlinePoint, to: OutlinePoint): OutlinePoint => {return {x: to.x - from.x, y: to.y - from.y};};+const getAngleDegrees = (from: OutlinePoint, to: OutlinePoint): number => {+ return Math.atan2(to.y - from.y, to.x - from.x) * (180 / Math.PI);+};++export const getSelectedOutlineRotationDeltaDegrees = ({+ from,+ to,+}: {+ readonly from: number;+ readonly to: number;+}) => {+ return ((((to - from) % 360) + 540) % 360) - 180;+};++export type SelectedOutlineRotationCorner =+ | 'top-left'+ | 'top-right'+ | 'bottom-right'+ | 'bottom-left';++const normalizeRotationCursorDegrees = (rotation: number): number => {+ const normalizedRotation = ((rotation % 360) + 360) % 360;+ return Number(normalizedRotation.toFixed(3));+};++const getRotationCursor = (rotation: number): string => {+ const normalizedRotation = normalizeRotationCursorDegrees(rotation);+ const transform =+ normalizedRotation === 0+ ? ''+ : `<g transform="rotate(${normalizedRotation} 32 32)">`;+ const transformEnd = normalizedRotation === 0 ? '' : '</g>';+ const svg = `<svg width="24" height="24" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">${transform}<g transform="scale(0.876712329)" filter="url(#filter0_d_1_14)"><path d="M10.9111 17.7687C10.3413 18.3701 10.367 19.3195 10.9684 19.8893L20.7687 29.1738C21.3701 29.7436 22.3195 29.7179 22.8893 29.1165C23.459 28.5151 23.4334 27.5657 22.832 26.996L14.1206 18.7431L22.3735 10.0316C22.9432 9.43022 22.9176 8.48082 22.3162 7.91107C21.7148 7.34133 20.7654 7.36699 20.1956 7.96839L10.9111 17.7687ZM49.3923 58.3118C49.9509 58.9235 50.8996 58.9667 51.5114 58.4081L61.481 49.3055C62.0927 48.7469 62.1359 47.7981 61.5773 47.1863C61.0187 46.5745 60.0699 46.5314 59.4581 47.09L50.5963 55.1812L42.5051 46.3194C41.9465 45.7076 40.9977 45.6645 40.386 46.2231C39.7742 46.7817 39.7311 47.7304 40.2896 48.3422L49.3923 58.3118ZM12.6747 18.7431L13 19.8893C22.1283 19.6426 30.7584 21.4283 37.8564 26.6927C44.8518 31.8809 49.734 39.8538 49 56H50.5963H51.5114C52.2774 39.1461 47.6482 30.2198 39.6436 24.2831C31.7416 18.4224 22.3717 17.2467 13 17.5L12.6747 18.7431Z" fill="black"/><path d="M19.1064 6.93652C20.2459 5.73379 22.1448 5.68278 23.3477 6.82227C24.5505 7.96181 24.6022 9.86076 23.4629 11.0635L18.7373 16.0508C26.3487 16.4239 33.9128 18.1651 40.5371 23.0781C44.7339 26.1907 48.0794 30.1189 50.2568 35.4834C51.9666 39.6958 52.9327 44.7395 53.0742 50.8867L58.4463 45.9824C59.6697 44.8654 61.5673 44.9514 62.6846 46.1748C63.8018 47.3985 63.7155 49.296 62.4922 50.4131L52.5225 59.5156C51.337 60.5979 49.5196 60.5507 48.3916 59.4346L48.2842 59.3232L39.1816 49.3535C38.0648 48.1301 38.1507 46.2324 39.374 45.1152C40.5975 43.9979 42.4961 44.0841 43.6133 45.3076L47.4756 49.5381C47.1908 44.7613 46.2876 40.9448 44.9482 37.8291C43.0666 33.4521 40.2851 30.3614 36.9629 27.8975C31.8259 24.0875 25.8071 22.1663 19.2891 21.5732L23.8633 25.9072C25.0662 27.0468 25.1178 28.9457 23.9785 30.1484C22.8746 31.3135 21.0576 31.3982 19.8516 30.3662L19.7373 30.2627L9.93652 20.9785C8.73384 19.839 8.6828 17.9401 9.82227 16.7373L19.1064 6.93652Z" stroke="white" stroke-width="3"/></g>${transformEnd}<defs><filter id="filter0_d_1_14" x="0" y="0" width="72.4696" height="72.3004" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/><feOffset dy="3"/><feGaussianBlur stdDeviation="3.75"/><feComposite in2="hardAlpha" operator="out"/><feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"/><feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_1_14"/><feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_1_14" result="shape"/></filter></defs></svg>`;+ return `url("data:image/svg+xml,${encodeURIComponent(svg)}") 12 12, alias`;+};++const rotationCursorBaseDegrees = {+ 'top-left': 270,+ 'top-right': 0,+ 'bottom-right': 90,+ 'bottom-left': 180,+} satisfies Record<SelectedOutlineRotationCorner, number>;++const getOutlineRotationDegrees = (+ points: SelectedOutline['points'],+): number => {+ const [tl, tr] = points;+ return getAngleDegrees(tl, tr);+};++const getRotationCursorDegrees = (+ points: SelectedOutline['points'],+ corner: SelectedOutlineRotationCorner,+) =>+ normalizeRotationCursorDegrees(+ getOutlineRotationDegrees(points) + rotationCursorBaseDegrees[corner],+ );++export const getSelectedOutlineRotationCornerInfo = (+ points: SelectedOutline['points'],+ corner: SelectedOutlineRotationCorner,+) => {+ const [tl, tr, br, bl] = points;+ const point = {+ 'top-left': tl,+ 'top-right': tr,+ 'bottom-right': br,+ 'bottom-left': bl,+ }[corner];+ const center = getOutlineCenter(points);+ const cursorDegrees = getRotationCursorDegrees(points, corner);++ return {+ center,+ cursor: getRotationCursor(cursorDegrees),+ cursorDegrees,+ point,+ };+};+const rectToPoints = (elementRect: DOMRect,containerRect: DOMRect,@@ -694,6 +813,116 @@ export const getSelectedOutlineScaleDragChanges = ({});};+export const getSelectedOutlineRotationDragStates = ({+ dragTargets,+ getDragOverrides,+ timelinePosition,+}: {+ readonly dragTargets: readonly SelectedOutlineRotationDragTarget[];+ readonly getDragOverrides: GetDragOverrides;+ readonly timelinePosition: number;+}): SelectedOutlineRotationDragState[] => {+ return dragTargets.map((target) => {+ const dragOverrideValue = (getDragOverrides(target.nodePath) ?? {})[+ rotateFieldKey+ ];+ const sourceFrame = timelinePosition - target.keyframeDisplayOffset;+ const effectiveValue = Internals.getEffectiveVisualModeValue({+ propStatus: target.propStatus,+ dragOverrideValue,+ defaultValue: target.fieldDefault,+ frame: sourceFrame,+ shouldResortToDefaultValueIfUndefined: true,+ });++ return {+ defaultValue:+ target.fieldDefault !== undefined+ ? JSON.stringify(target.fieldDefault)+ : null,+ key: Internals.makeSequencePropsSubscriptionKey(target.nodePath),+ sourceFrame,+ startDegrees: parseCssRotationToDegrees(String(effectiveValue ?? '0deg')),+ target,+ };+ });+};++export const getSelectedOutlineRotationDragValues = ({+ dragStates,+ rotationDeltaDegrees,+}: {+ readonly dragStates: readonly SelectedOutlineRotationDragState[];+ readonly rotationDeltaDegrees: number;+}): Map<string, string> => {+ return new Map(+ dragStates.map((dragState) => [+ dragState.key,+ serializeCssRotation(dragState.startDegrees + rotationDeltaDegrees),+ ]),+ );+};++export const getSelectedOutlineRotationDragChanges = ({+ dragStates,+ lastValues,+}: {+ readonly dragStates: readonly SelectedOutlineRotationDragState[];+ readonly lastValues: ReadonlyMap<string, string>;+}): SelectedOutlineDragChange[] => {+ const changes: SelectedOutlineDragChange[] = [];++ for (const dragState of dragStates) {+ const value = lastValues.get(dragState.key);+ if (value === undefined) {+ continue;+ }++ if (dragState.target.propStatus.status === 'keyframed') {+ const startValue = serializeCssRotation(dragState.startDegrees);+ if (value === startValue) {+ continue;+ }++ changes.push({+ type: 'keyframed',+ fileName: dragState.target.nodePath.absolutePath,+ nodePath: dragState.target.nodePath,+ fieldKey: rotateFieldKey,+ sourceFrame: dragState.sourceFrame,+ value,+ schema: dragState.target.schema,+ clientId: dragState.target.clientId,+ });+ continue;+ }++ const stringifiedValue = JSON.stringify(value);+ const shouldSave =+ value !== dragState.target.propStatus.codeValue &&+ !(+ dragState.defaultValue === stringifiedValue &&+ dragState.target.propStatus.codeValue === undefined+ );++ if (!shouldSave) {+ continue;+ }++ changes.push({+ type: 'static',+ fileName: dragState.target.nodePath.absolutePath,+ nodePath: dragState.target.nodePath,+ fieldKey: rotateFieldKey,+ value,+ defaultValue: dragState.defaultValue,+ schema: dragState.target.schema,+ });+ }++ return changes;+};+const clearSelectedOutlineDragOverrides = ({clearDragOverrides,dragStates,@@ -718,6 +947,18 @@ const clearSelectedOutlineScaleDragOverrides = ({}};+const clearSelectedOutlineRotationDragOverrides = ({+ clearDragOverrides,+ dragStates,+}: {+ readonly clearDragOverrides: (nodePath: SequencePropsSubscriptionKey) => void;+ readonly dragStates: readonly SelectedOutlineRotationDragState[];+}) => {+ for (const dragState of dragStates) {+ clearDragOverrides(dragState.target.nodePath);+ }+};+const SelectedOutlinePolygon: React.FC<{readonly allDragTargets: readonly SelectedOutlineDragTarget[];readonly contextMenuValues: readonly ComboboxValue[];@@ -1242,8 +1483,280 @@ const SelectedOutlineScaleEdgeLine: React.FC<{);};+const svgPointToClientPoint = (+ point: OutlinePoint,+ rect: DOMRect,+): OutlinePoint => {+ return {+ x: point.x + rect.left,+ y: point.y + rect.top,+ };+};++const SelectedOutlineRotationCornerHandle: React.FC<{+ readonly allRotationDragTargets: readonly SelectedOutlineRotationDragTarget[];+ readonly contextMenuValues: readonly ComboboxValue[];+ readonly corner: SelectedOutlineRotationCorner;+ readonly dragging: boolean;+ readonly outline: SelectedOutline;+ readonly onDraggingChange: (dragging: boolean) => void;+ readonly onContextMenuOpen: SelectedOutlineContextMenuOpenHandler;+ readonly onHoverChange: (key: string | null) => void;+ readonly onSelect: (+ item: TimelineSelection,+ interaction: TimelineSelectionInteraction,+ ) => void;+ readonly target: SelectedOutlineTarget | undefined;+}> = ({+ allRotationDragTargets,+ contextMenuValues,+ corner,+ dragging,+ outline,+ onDraggingChange,+ onContextMenuOpen,+ onHoverChange,+ onSelect,+ target,+}) => {+ const {getDragOverrides} = useContext(+ Internals.VisualModeDragOverridesContext,+ );+ const {setPropStatuses, setDragOverrides, clearDragOverrides} = useContext(+ Internals.VisualModeSettersContext,+ );+ const timelinePosition = Internals.Timeline.useTimelinePosition();+ const timelinePositionRef = useRef(timelinePosition);+ timelinePositionRef.current = timelinePosition;+ const rotationDrag = target?.rotationDrag ?? null;+ const selected = target?.selected ?? false;+ const circleRef = useRef<SVGCircleElement>(null);+ const cornerInfo = useMemo(+ () => getSelectedOutlineRotationCornerInfo(outline.points, corner),+ [corner, outline.points],+ );++ const onPointerDown = React.useCallback(+ (event: React.PointerEvent<SVGCircleElement>) => {+ if (event.button !== 0 || rotationDrag === null) {+ return;+ }++ event.preventDefault();+ event.stopPropagation();++ const svg = event.currentTarget.ownerSVGElement;+ if (svg === null) {+ return;+ }++ const interaction = getOutlineSelectionInteraction(event);+ const shouldUpdateSelection =+ !selected || interaction.shiftKey || interaction.toggleKey;+ if (shouldUpdateSelection && target !== undefined) {+ onSelect(target.selection, interaction);+ }++ if (interaction.shiftKey || interaction.toggleKey) {+ return;+ }++ onDraggingChange(true);+ forceSpecificCursor(cornerInfo.cursor);++ const svgRect = svg.getBoundingClientRect();+ const center = svgPointToClientPoint(cornerInfo.center, svgRect);+ const dragStates = getSelectedOutlineRotationDragStates({+ dragTargets: selected ? allRotationDragTargets : [rotationDrag],+ getDragOverrides,+ timelinePosition: timelinePositionRef.current,+ });+ let previousAngle = getAngleDegrees(center, {+ x: event.clientX,+ y: event.clientY,+ });+ let accumulatedDelta = 0;+ let lastValues = new Map<string, string>();++ const onPointerMove = (moveEvent: PointerEvent) => {+ moveEvent.preventDefault();++ const nextAngle = getAngleDegrees(center, {+ x: moveEvent.clientX,+ y: moveEvent.clientY,+ });+ accumulatedDelta += getSelectedOutlineRotationDeltaDegrees({+ from: previousAngle,+ to: nextAngle,+ });+ previousAngle = nextAngle;+ lastValues = getSelectedOutlineRotationDragValues({+ dragStates,+ rotationDeltaDegrees: accumulatedDelta,+ });+ forceSpecificCursor(+ getRotationCursor(cornerInfo.cursorDegrees + accumulatedDelta),+ );++ for (const dragState of dragStates) {+ const value = lastValues.get(dragState.key);+ if (value === undefined) {+ throw new Error('Expected rotation drag value to be available');+ }++ if (dragState.target.propStatus.status === 'keyframed') {+ setDragOverrides(+ dragState.target.nodePath,+ rotateFieldKey,+ Internals.makeKeyframedDragOverride({+ status: dragState.target.propStatus,+ frame: dragState.sourceFrame,+ value,+ }),+ );+ } else {+ setDragOverrides(+ dragState.target.nodePath,+ rotateFieldKey,+ Internals.makeStaticDragOverride(value),+ );+ }+ }+ };++ const onPointerUp = () => {+ window.removeEventListener('pointermove', onPointerMove);+ window.removeEventListener('pointerup', onPointerUp);+ window.removeEventListener('pointercancel', onPointerUp);+ stopForcingSpecificCursor();+ onDraggingChange(false);++ const changes = getSelectedOutlineRotationDragChanges({+ dragStates,+ lastValues,+ });++ if (changes.length === 0) {+ clearSelectedOutlineRotationDragOverrides({+ clearDragOverrides,+ dragStates,+ });+ return;+ }++ const staticChanges = changes.filter(+ (change): change is SelectedOutlineStaticDragChange =>+ change.type === 'static',+ );+ const keyframedChanges = changes.filter(+ (change): change is SelectedOutlineKeyframedDragChange =>+ change.type === 'keyframed',+ );++ Promise.all([+ staticChanges.length > 0+ ? saveSequenceProps({+ changes: staticChanges,+ setPropStatuses,+ clientId: rotationDrag.clientId,+ undoLabel:+ changes.length > 1+ ? 'Rotate selected sequences'+ : 'Rotate sequence',+ redoLabel:+ changes.length > 1+ ? 'Rotate selected sequences back'+ : 'Rotate sequence back',+ })+ : Promise.resolve(),+ ...keyframedChanges.map((change) =>+ callAddSequenceKeyframe({+ fileName: change.fileName,+ nodePath: change.nodePath,+ fieldKey: change.fieldKey,+ sourceFrame: change.sourceFrame,+ value: change.value,+ schema: change.schema,+ setPropStatuses,+ clientId: change.clientId,+ }),+ ),+ ])+ .catch((err) => {+ showNotification(+ `Could not save sequence props: ${+ err instanceof Error ? err.message : String(err)+ }`,+ 4000,+ );+ })+ .finally(() => {+ clearSelectedOutlineRotationDragOverrides({+ clearDragOverrides,+ dragStates,+ });+ });+ };++ window.addEventListener('pointermove', onPointerMove);+ window.addEventListener('pointerup', onPointerUp);+ window.addEventListener('pointercancel', onPointerUp);+ },+ [+ allRotationDragTargets,+ clearDragOverrides,+ cornerInfo,+ getDragOverrides,+ onDraggingChange,+ onSelect,+ rotationDrag,+ selected,+ setPropStatuses,+ setDragOverrides,+ target,+ ],+ );++ if (rotationDrag === null) {+ return null;+ }++ return (+ <>+ <circle+ ref={circleRef}+ cx={cornerInfo.point.x}+ cy={cornerInfo.point.y}+ r={12}+ fill="transparent"+ stroke="transparent"+ vectorEffect="non-scaling-stroke"+ pointerEvents="all"+ cursor={cornerInfo.cursor}+ onPointerEnter={() => {+ if (!dragging) {+ onHoverChange(outline.key);+ }+ }}+ onPointerLeave={() => {+ if (!dragging) {+ onHoverChange(null);+ }+ }}+ onPointerDown={onPointerDown}+ />+ <ContextMenuForTarget+ triggerRef={circleRef}+ values={[...contextMenuValues]}+ onOpen={onContextMenuOpen}+ />+ </>+ );+};+const SelectedOutlineElement: React.FC<{readonly allDragTargets: readonly SelectedOutlineDragTarget[];+ readonly allRotationDragTargets: readonly SelectedOutlineRotationDragTarget[];readonly allScaleDragTargets: readonly SelectedOutlineScaleDragTarget[];readonly dragging: boolean;readonly hovered: boolean;@@ -1258,6 +1771,7 @@ const SelectedOutlineElement: React.FC<{readonly target: SelectedOutlineTarget | undefined;}> = ({allDragTargets,+ allRotationDragTargets,allScaleDragTargets,dragging,hovered,@@ -1391,6 +1905,25 @@ const SelectedOutlineElement: React.FC<{/>)): null}+ {target?.containsSelection || hovered+ ? (+ ['top-left', 'top-right', 'bottom-right', 'bottom-left'] as const+ ).map((corner) => (+ <SelectedOutlineRotationCornerHandle+ key={corner}+ allRotationDragTargets={allRotationDragTargets}+ contextMenuValues={emptyContextMenuValues}+ corner={corner}+ dragging={dragging}+ outline={outline}+ onContextMenuOpen={onContextMenuOpen}+ onDraggingChange={onDraggingChange}+ onHoverChange={onHoverChange}+ onSelect={onSelect}+ target={target}+ />+ ))+ : null}</>);};@@ -1461,10 +1994,19 @@ export const SelectedOutlineOverlay: React.FC<{propStatuses,nodePath,)?.[scaleFieldKey];+ const rotationFieldSchema = controls?.schema[rotateFieldKey];+ const rotationPropStatus = Internals.getPropStatusesCtx(+ propStatuses,+ nodePath,+ )?.[rotateFieldKey];const canDragStatus =propStatus?.status === 'static' ||(propStatus?.status === 'keyframed' &&propStatus.interpolationFunction === 'interpolate');+ const canRotationDragStatus =+ rotationPropStatus?.status === 'static' ||+ (rotationPropStatus?.status === 'keyframed' &&+ rotationPropStatus.interpolationFunction === 'interpolate');const canDrag =previewServerState.type === 'connected' &&controls !== null &&@@ -1475,6 +2017,11 @@ export const SelectedOutlineOverlay: React.FC<{controls !== null &&scaleFieldSchema?.type === 'scale' &&scalePropStatus?.status === 'static';+ const canRotationDrag =+ previewServerState.type === 'connected' &&+ controls !== null &&+ rotationFieldSchema?.type === 'rotation-css' &&+ canRotationDragStatus;const canDropEffect =previewServerState.type === 'connected' &&controls?.supportsEffects === true;@@ -1532,6 +2079,17 @@ export const SelectedOutlineOverlay: React.FC<{schema: controls.schema,}: null,+ rotationDrag: canRotationDrag+ ? {+ propStatus: rotationPropStatus,+ clientId: previewServerState.clientId,+ fieldDefault: rotationFieldSchema.default,+ fieldSchema: rotationFieldSchema,+ keyframeDisplayOffset,+ nodePath,+ schema: controls.schema,+ }+ : null,uvHandles: containsSelection? getSelectedUvHandles({propStatuses,@@ -1580,6 +2138,13 @@ export const SelectedOutlineOverlay: React.FC<{target.selected && target.scaleDrag !== null ? [target.scaleDrag] : [],);}, [outlineTargets]);+ const allRotationDragTargets = useMemo(() => {+ return outlineTargets.flatMap((target) =>+ target.selected && target.rotationDrag !== null+ ? [target.rotationDrag]+ : [],+ );+ }, [outlineTargets]);useEffect(() => {if (outlineTargets.length === 0) {@@ -1632,6 +2197,7 @@ export const SelectedOutlineOverlay: React.FC<{<SelectedOutlineElementkey={outline.key}allDragTargets={allDragTargets}+ allRotationDragTargets={allRotationDragTargets}allScaleDragTargets={allScaleDragTargets}dragging={draggingOutline}hovered={hoveredOutlineKey === outline.key}diff --git a/packages/studio/src/components/Timeline/TimelineRotationField.tsx b/packages/studio/src/components/Timeline/TimelineRotationField.tsxindex cb1ce1b531..d0e7f62d4c 100644--- a/packages/studio/src/components/Timeline/TimelineRotationField.tsx+++ b/packages/studio/src/components/Timeline/TimelineRotationField.tsx@@ -12,29 +12,10 @@ import {getTimelineDisplayDecimalPlaces,normalizeTimelineNumber,} from './timeline-field-utils';--const unitPattern = /^([+-]?(?:\d+\.?\d*|\.\d+))(deg|rad|turn|grad)$/;--const unitToDegrees: Record<string, number> = {- deg: 1,- rad: 180 / Math.PI,- turn: 360,- grad: 360 / 400,-};--const parseCssRotationToDegrees = (value: string): number => {- const match = value.trim().match(unitPattern);- if (match) {- return normalizeTimelineNumber(Number(match[1]) * unitToDegrees[match[2]]);- }-- try {- const m = new DOMMatrix(`rotate(${value})`);- return normalizeTimelineNumber(Math.atan2(m.b, m.a) * (180 / Math.PI));- } catch {- return 0;- }-};+import {+ parseCssRotationToDegrees,+ serializeCssRotation,+} from './timeline-rotation-utils';export const TimelineRotationField: React.FC<{readonly field: SchemaFieldInfo;@@ -64,8 +45,9 @@ export const TimelineRotationField: React.FC<{const serializeValue = useCallback((value: number) => {- const normalized = normalizeTimelineNumber(value);- return isCssRotation ? `${normalized}deg` : normalized;+ return isCssRotation+ ? serializeCssRotation(value)+ : normalizeTimelineNumber(value);},[isCssRotation],);diff --git a/packages/studio/src/components/Timeline/timeline-rotation-utils.ts b/packages/studio/src/components/Timeline/timeline-rotation-utils.tsnew file mode 100644index 0000000000..056d41dc13--- /dev/null+++ b/packages/studio/src/components/Timeline/timeline-rotation-utils.ts@@ -0,0 +1,32 @@+import {normalizeTimelineNumber} from './timeline-field-utils';++const unitPattern = /^([+-]?(?:\d+\.?\d*|\.\d+))(deg|rad|turn|grad)$/;++const unitToDegrees: Record<string, number> = {+ deg: 1,+ rad: 180 / Math.PI,+ turn: 360,+ grad: 360 / 400,+};++export const parseCssRotationToDegrees = (value: string): number => {+ const match = value.trim().match(unitPattern);+ if (match) {+ return normalizeTimelineNumber(Number(match[1]) * unitToDegrees[match[2]]);+ }++ if (typeof DOMMatrix === 'undefined') {+ return 0;+ }++ try {+ const m = new DOMMatrix(`rotate(${value})`);+ return normalizeTimelineNumber(Math.atan2(m.b, m.a) * (180 / Math.PI));+ } catch {+ return 0;+ }+};++export const serializeCssRotation = (value: number): string => {+ return `${normalizeTimelineNumber(value)}deg`;+};diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.tsindex 7f31117548..b92242a7c3 100644--- a/packages/studio/src/test/timeline-selection.test.ts+++ b/packages/studio/src/test/timeline-selection.test.ts@@ -22,12 +22,17 @@ import {getSelectedEffectFieldsBySequenceKey,getSelectedOutlineDragChanges,getSelectedOutlineDragValues,+ getSelectedOutlineRotationCornerInfo,+ getSelectedOutlineRotationDeltaDegrees,+ getSelectedOutlineRotationDragChanges,+ getSelectedOutlineRotationDragValues,getSelectedOutlineScaleDragChanges,getSelectedOutlineScaleDragValues,getSelectedOutlineScaleEdgeInfo,getSelectedSequenceKeys,getSequencesWithSelectableOutlines,type SelectedOutlineDragState,+ type SelectedOutlineRotationDragState,type SelectedOutlineScaleDragState,} from '../components/SelectedOutlineOverlay';import {deleteSelectedTimelineItems} from '../components/Timeline/delete-selected-timeline-item';@@ -1977,6 +1982,212 @@ test('Selected outline edge dragging preserves aspect ratio when scale is linkedexpect(lastValues.get(dragStates[0].key)).toBe('2.5 3.75');});+test('Selected outline corner dragging rotates selected sequences', () => {+ const schema = {+ 'style.rotate': {type: 'rotation-css', default: '0deg'},+ } satisfies SequenceSchema;+ const firstNodePath = makeKey(['body', 0]);+ const secondNodePath = makeKey(['body', 1]);+ const dragStates = [+ {+ defaultValue: JSON.stringify('0deg'),+ key: Internals.makeSequencePropsSubscriptionKey(firstNodePath),+ sourceFrame: 12,+ startDegrees: 45,+ target: {+ clientId: 'client',+ propStatus: {status: 'static', codeValue: '45deg'},+ fieldDefault: '0deg',+ fieldSchema: schema['style.rotate'],+ keyframeDisplayOffset: 30,+ nodePath: firstNodePath,+ schema,+ },+ },+ {+ defaultValue: JSON.stringify('0deg'),+ key: Internals.makeSequencePropsSubscriptionKey(secondNodePath),+ sourceFrame: 12,+ startDegrees: -10,+ target: {+ clientId: 'client',+ propStatus: {status: 'static', codeValue: '-10deg'},+ fieldDefault: '0deg',+ fieldSchema: schema['style.rotate'],+ keyframeDisplayOffset: 30,+ nodePath: secondNodePath,+ schema,+ },+ },+ ] satisfies SelectedOutlineRotationDragState[];++ const lastValues = getSelectedOutlineRotationDragValues({+ dragStates,+ rotationDeltaDegrees: 90,+ });++ expect(lastValues.get(dragStates[0].key)).toBe('135deg');+ expect(lastValues.get(dragStates[1].key)).toBe('80deg');+ expect(+ getSelectedOutlineRotationDragChanges({+ dragStates,+ lastValues,+ }),+ ).toEqual([+ {+ type: 'static',+ fileName: '/project/src/Comp.tsx',+ nodePath: firstNodePath,+ fieldKey: 'style.rotate',+ value: '135deg',+ defaultValue: JSON.stringify('0deg'),+ schema,+ },+ {+ type: 'static',+ fileName: '/project/src/Comp.tsx',+ nodePath: secondNodePath,+ fieldKey: 'style.rotate',+ value: '80deg',+ defaultValue: JSON.stringify('0deg'),+ schema,+ },+ ]);+});++test('Selected outline corner dragging keyframed rotation adds a keyframe at the source frame', () => {+ const schema = {+ 'style.rotate': {type: 'rotation-css', default: '0deg'},+ } satisfies SequenceSchema;+ const nodePath = makeKey(['body', 0]);+ const dragStates = [+ {+ defaultValue: JSON.stringify('0deg'),+ key: Internals.makeSequencePropsSubscriptionKey(nodePath),+ sourceFrame: 20,+ startDegrees: 45,+ target: {+ clientId: 'client',+ propStatus: {+ status: 'keyframed',+ interpolationFunction: 'interpolate',+ keyframes: [+ {frame: 0, value: '0deg'},+ {frame: 40, value: '90deg'},+ ],+ easing: ['linear'],+ clamping: {left: 'extend', right: 'extend'},+ posterize: undefined,+ },+ fieldDefault: '0deg',+ fieldSchema: schema['style.rotate'],+ keyframeDisplayOffset: 30,+ nodePath,+ schema,+ },+ },+ ] satisfies SelectedOutlineRotationDragState[];++ const lastValues = getSelectedOutlineRotationDragValues({+ dragStates,+ rotationDeltaDegrees: 15,+ });++ expect(lastValues.get(dragStates[0].key)).toBe('60deg');+ expect(+ getSelectedOutlineRotationDragChanges({+ dragStates,+ lastValues,+ }),+ ).toEqual([+ {+ type: 'keyframed',+ fileName: '/project/src/Comp.tsx',+ nodePath,+ fieldKey: 'style.rotate',+ sourceFrame: 20,+ value: '60deg',+ schema,+ clientId: 'client',+ },+ ]);+ expect(+ getSelectedOutlineRotationDragChanges({+ dragStates,+ lastValues: new Map([[dragStates[0].key, '45deg']]),+ }),+ ).toEqual([]);+});++test('Selected outline rotation delta does not jump at the angle wrap-around', () => {+ const firstStep = getSelectedOutlineRotationDeltaDegrees({+ from: 170,+ to: 175,+ });+ const secondStep = getSelectedOutlineRotationDeltaDegrees({+ from: 175,+ to: -170,+ });++ expect(firstStep + secondStep).toBe(20);+});++test('Selected outline rotation corners use the outline corners and center', () => {+ const points = [+ {x: 0, y: 0},+ {x: 100, y: 0},+ {x: 100, y: 50},+ {x: 0, y: 50},+ ] as const;+ const topRight = getSelectedOutlineRotationCornerInfo(points, 'top-right');++ expect(topRight.point).toEqual({x: 100, y: 0});+ expect(topRight.center).toEqual({x: 50, y: 25});+ expect(topRight.cursor).toContain('data:image/svg+xml');+ expect(decodeURIComponent(topRight.cursor)).toContain(+ '<svg width="24" height="24"',+ );+ expect(topRight.cursor).toContain('") 12 12, alias');+});++test('Selected outline rotation cursors use the outline rotation', () => {+ const points = [+ {x: 0, y: 0},+ {x: 100, y: 0},+ {x: 100, y: 100},+ {x: 0, y: 100},+ ] as const;++ expect(+ getSelectedOutlineRotationCornerInfo(points, 'top-left').cursorDegrees,+ ).toBe(270);+ expect(+ getSelectedOutlineRotationCornerInfo(points, 'top-right').cursorDegrees,+ ).toBe(0);+ expect(+ getSelectedOutlineRotationCornerInfo(points, 'bottom-right').cursorDegrees,+ ).toBe(90);+ expect(+ getSelectedOutlineRotationCornerInfo(points, 'bottom-left').cursorDegrees,+ ).toBe(180);+});++test('Selected outline rotation cursor angle is independent from aspect ratio', () => {+ const points = [+ {x: 0, y: 0},+ {x: 160, y: 0},+ {x: 160, y: 90},+ {x: 0, y: 90},+ ] as const;++ expect(+ getSelectedOutlineRotationCornerInfo(points, 'top-right').cursorDegrees,+ ).toBe(0);+ expect(+ getSelectedOutlineRotationCornerInfo(points, 'bottom-left').cursorDegrees,+ ).toBe(180);+});+test('Selected outline scale edges project pointer movement onto the edge normal', () => {const points = [{x: 0, y: 0},