🎥 Make videos programmatically with React
`@remotion/studio`: Copy and paste keyframes (#9267)
Jonny Burger6c1ae53d91f2
diff --git a/packages/studio-shared/src/easing-clipboard-data.ts b/packages/studio-shared/src/easing-clipboard-data.tsindex 12ed047dea..a83e2b6d13 100644--- a/packages/studio-shared/src/easing-clipboard-data.ts+++ b/packages/studio-shared/src/easing-clipboard-data.ts@@ -28,7 +28,7 @@ const isFiniteNumber = (value: unknown): value is number => {return typeof value === 'number' && Number.isFinite(value);};-const isEasing = (value: unknown): value is KeyframeEasing => {+export const isKeyframeEasing = (value: unknown): value is KeyframeEasing => {return (isRecord(value) &&(value.type === 'linear' ||@@ -51,7 +51,9 @@ const isEasing = (value: unknown): value is KeyframeEasing => {);};-const normalizeEasing = (easing: KeyframeEasing): KeyframeEasing => {+export const normalizeKeyframeEasing = (+ easing: KeyframeEasing,+): KeyframeEasing => {if (easing.type !== 'spring') {return easing;}@@ -83,7 +85,7 @@ export const parseEasingClipboardDataResult = (};}- if (parsed.type !== 'easing' || !isEasing(parsed.easing)) {+ if (parsed.type !== 'easing' || !isKeyframeEasing(parsed.easing)) {return {status: 'invalid'};}@@ -93,7 +95,7 @@ export const parseEasingClipboardDataResult = (type: 'easing',version: 1,remotionClipboard: 'easing',- easing: normalizeEasing(parsed.easing),+ easing: normalizeKeyframeEasing(parsed.easing),},};} catch {diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.tsindex 9250532ced..e097ed6288 100644--- a/packages/studio-shared/src/index.ts+++ b/packages/studio-shared/src/index.ts@@ -228,6 +228,7 @@ export {type KeyframeEasingPreset,} from './keyframe-easing-presets';export {+ canEditEasingForInterpolationFunction,getKeyframeInterpolationFunction,getKeyframeInterpolationFunctionForSchemaField,isInteractivitySchemaFieldKeyframable,@@ -236,6 +237,14 @@ export {keyframeInterpolationFunctions,type KeyframeInterpolationFunction,} from './keyframe-interpolation-function';+export {+ isKeyframeClipboardFieldType,+ parseKeyframeClipboardData,+ parseKeyframeClipboardDataResult,+ type KeyframeClipboardData,+ type KeyframeClipboardDataParseResult,+ type KeyframeClipboardFieldType,+} from './keyframe-clipboard-data';export {DEFAULT_TIMELINE_TRACKS} from './max-timeline-tracks';export {Pkgs,diff --git a/packages/studio-shared/src/keyframe-clipboard-data.ts b/packages/studio-shared/src/keyframe-clipboard-data.tsnew file mode 100644index 0000000000..427c356d6a--- /dev/null+++ b/packages/studio-shared/src/keyframe-clipboard-data.ts@@ -0,0 +1,178 @@+import type {InteractivitySchemaField} from 'remotion';+import {+ isKeyframeEasing,+ normalizeKeyframeEasing,+} from './easing-clipboard-data';+import type {KeyframeEasing} from './keyframe-easing-presets';++// Keep this exhaustive so every new schema field requires an explicit clipboard+// compatibility decision.+const KEYFRAME_CLIPBOARD_FIELD_TYPE_SUPPORT = {+ array: false,+ asset: false,+ boolean: false,+ color: true,+ enum: false,+ 'font-family': false,+ hidden: false,+ number: true,+ 'rotation-css': true,+ 'rotation-degrees': true,+ scale: true,+ 'text-content': false,+ 'transform-origin': true,+ translate: true,+ 'uv-coordinate': true,+} as const satisfies Record<InteractivitySchemaField['type'], boolean>;++type KeyframeClipboardFieldTypeSupport =+ typeof KEYFRAME_CLIPBOARD_FIELD_TYPE_SUPPORT;++export type KeyframeClipboardFieldType = {+ [FieldType in keyof KeyframeClipboardFieldTypeSupport]: KeyframeClipboardFieldTypeSupport[FieldType] extends true+ ? FieldType+ : never;+}[keyof KeyframeClipboardFieldTypeSupport];++export type KeyframeClipboardData = {+ readonly type: 'keyframe';+ readonly version: 1;+ readonly remotionClipboard: 'keyframe';+ readonly fieldType: KeyframeClipboardFieldType | null;+ readonly keyframes: readonly {+ readonly frameOffset: number;+ readonly value: unknown;+ }[];+ readonly easing: readonly KeyframeEasing[];+};++export type KeyframeClipboardDataParseResult =+ | {+ readonly status: 'valid';+ readonly data: KeyframeClipboardData;+ }+ | {+ readonly status: 'unsupported-version';+ readonly version: unknown;+ }+ | {+ readonly status: 'invalid';+ };++const isRecord = (value: unknown): value is Record<string, unknown> => {+ return typeof value === 'object' && value !== null && !Array.isArray(value);+};++export const isKeyframeClipboardFieldType = (+ value: unknown,+): value is KeyframeClipboardFieldType => {+ return (+ typeof value === 'string' &&+ Object.hasOwn(KEYFRAME_CLIPBOARD_FIELD_TYPE_SUPPORT, value) &&+ KEYFRAME_CLIPBOARD_FIELD_TYPE_SUPPORT[+ value as keyof KeyframeClipboardFieldTypeSupport+ ]+ );+};++const isKeyframeClipboardEntry = (+ value: unknown,+): value is KeyframeClipboardData['keyframes'][number] => {+ return (+ isRecord(value) &&+ Number.isInteger(value.frameOffset) &&+ Object.hasOwn(value, 'value')+ );+};++const areValidKeyframes = (+ value: unknown,+): value is KeyframeClipboardData['keyframes'] => {+ if (!Array.isArray(value) || value.length === 0) {+ return false;+ }++ let previousOffset = -1;+ for (const keyframe of value) {+ if (+ !isKeyframeClipboardEntry(keyframe) ||+ keyframe.frameOffset <= previousOffset+ ) {+ return false;+ }++ previousOffset = keyframe.frameOffset;+ }++ return value[0]?.frameOffset === 0;+};++const parseEasings = ({+ value,+ keyframeCount,+}: {+ value: unknown;+ keyframeCount: number;+}): KeyframeEasing[] | null => {+ if (+ Array.isArray(value) &&+ value.length === Math.max(0, keyframeCount - 1) &&+ value.every(isKeyframeEasing)+ ) {+ return value.map(normalizeKeyframeEasing);+ }++ return null;+};++export const parseKeyframeClipboardDataResult = (+ value: string,+): KeyframeClipboardDataParseResult => {+ try {+ const parsed: unknown = JSON.parse(value);+ if (!isRecord(parsed) || parsed.remotionClipboard !== 'keyframe') {+ return {status: 'invalid'};+ }++ if (parsed.version !== 1) {+ return {status: 'unsupported-version', version: parsed.version};+ }++ const easing = parseEasings({+ value: parsed.easing,+ keyframeCount: Array.isArray(parsed.keyframes)+ ? parsed.keyframes.length+ : 0,+ });+ if (+ parsed.type !== 'keyframe' ||+ !areValidKeyframes(parsed.keyframes) ||+ easing === null ||+ (parsed.fieldType !== null &&+ !isKeyframeClipboardFieldType(parsed.fieldType))+ ) {+ return {status: 'invalid'};+ }++ return {+ status: 'valid',+ data: {+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: parsed.fieldType,+ keyframes: parsed.keyframes,+ easing,+ },+ };+ } catch {+ return {status: 'invalid'};+ }+};++export const parseKeyframeClipboardData = (+ value: string,+): KeyframeClipboardData | null => {+ const result = parseKeyframeClipboardDataResult(value);+ return result.status === 'valid' ? result.data : null;+};diff --git a/packages/studio-shared/src/keyframe-interpolation-function.ts b/packages/studio-shared/src/keyframe-interpolation-function.tsindex 0b9a4a615c..fc7298b91c 100644--- a/packages/studio-shared/src/keyframe-interpolation-function.ts+++ b/packages/studio-shared/src/keyframe-interpolation-function.ts@@ -8,6 +8,57 @@ export const keyframeInterpolationFunctions = [export type KeyframeInterpolationFunction =(typeof keyframeInterpolationFunctions)[number];+// Keep these tables exhaustive so every schema field requires explicit+// keyframe and interpolation decisions.+const KEYFRAME_FIELD_TYPE_SUPPORT = {+ array: false,+ asset: false,+ boolean: false,+ color: true,+ enum: false,+ 'font-family': false,+ hidden: true,+ number: true,+ 'rotation-css': true,+ 'rotation-degrees': true,+ scale: true,+ 'text-content': false,+ 'transform-origin': true,+ translate: true,+ 'uv-coordinate': true,+} as const satisfies Record<InteractivitySchemaField['type'], boolean>;++type KeyframeInterpolationStrategy =+ | KeyframeInterpolationFunction+ | 'infer'+ | 'unsupported';++const KEYFRAME_FIELD_TYPE_INTERPOLATION = {+ array: 'unsupported',+ asset: 'unsupported',+ boolean: 'unsupported',+ color: 'interpolateColors',+ enum: 'unsupported',+ 'font-family': 'unsupported',+ hidden: 'infer',+ number: 'infer',+ 'rotation-css': 'interpolate',+ 'rotation-degrees': 'infer',+ scale: 'interpolate',+ 'text-content': 'unsupported',+ 'transform-origin': 'interpolate',+ translate: 'interpolate',+ 'uv-coordinate': 'infer',+} as const satisfies Record<+ InteractivitySchemaField['type'],+ KeyframeInterpolationStrategy+>;++const KEYFRAME_INTERPOLATION_EASING_SUPPORT = {+ interpolate: true,+ interpolateColors: true,+} as const satisfies Record<KeyframeInterpolationFunction, boolean>;+export const isKeyframeInterpolationFunction = (name: string,): name is KeyframeInterpolationFunction => {@@ -16,6 +67,12 @@ export const isKeyframeInterpolationFunction = ();};+export const canEditEasingForInterpolationFunction = (+ interpolationFunction: string,+): boolean =>+ isKeyframeInterpolationFunction(interpolationFunction) &&+ KEYFRAME_INTERPOLATION_EASING_SUPPORT[interpolationFunction];+export const isInteractivitySchemaFieldKeyframable = (field: InteractivitySchemaField | undefined,): boolean => {@@ -23,17 +80,7 @@ export const isInteractivitySchemaFieldKeyframable = (return true;}- if (- field.type === 'array' ||- field.type === 'boolean' ||- field.type === 'enum' ||- field.type === 'font-family' ||- field.type === 'asset'- ) {- return false;- }-- return field.keyframable !== false;+ return KEYFRAME_FIELD_TYPE_SUPPORT[field.type] && field.keyframable !== false;};const findFieldInSchema = (@@ -80,20 +127,12 @@ export const getKeyframeInterpolationFunctionForSchemaField = ({}): KeyframeInterpolationFunction | null => {const field = schema ? findFieldInSchema(schema, key) : undefined;- if (field?.type === 'color') {- return 'interpolateColors';- }-- if (- field?.type === 'scale' ||- field?.type === 'translate' ||- field?.type === 'transform-origin' ||- field?.type === 'rotation-css'- ) {- return 'interpolate';+ if (!field) {+ return null;}- return null;+ const strategy = KEYFRAME_FIELD_TYPE_INTERPOLATION[field.type];+ return strategy === 'infer' || strategy === 'unsupported' ? null : strategy;};export const getKeyframeInterpolationFunction = ({diff --git a/packages/studio-shared/src/schema-field-info.ts b/packages/studio-shared/src/schema-field-info.tsindex 3ae3797b61..c9b14bb6c2 100644--- a/packages/studio-shared/src/schema-field-info.ts+++ b/packages/studio-shared/src/schema-field-info.ts@@ -5,6 +5,7 @@ import type {GetDragOverrides,GetEffectDragOverrides,InteractivitySchema,+ InteractivitySchemaField,PropStatuses,SequenceControls,SequencePropsSubscriptionKey,@@ -110,25 +111,43 @@ const sortSchemaFields = <T extends SchemaFieldInfo>(fields: T[]): T[] => {.map(({field}) => field);};-const SUPPORTED_SCHEMA_TYPES = [- 'number',- 'boolean',- 'rotation-css',- 'rotation-degrees',- 'translate',- 'transform-origin',- 'scale',- 'uv-coordinate',- 'color',- 'text-content',- 'font-family',- 'asset',- 'array',- 'enum',- 'hidden',-] as const;--type SupportedSchemaType = (typeof SUPPORTED_SCHEMA_TYPES)[number];+// Keep this exhaustive so every schema field requires an explicit timeline UI+// support decision.+const TIMELINE_SCHEMA_FIELD_TYPE_SUPPORT = {+ array: true,+ asset: true,+ boolean: true,+ color: true,+ enum: true,+ 'font-family': true,+ hidden: false,+ number: true,+ 'rotation-css': true,+ 'rotation-degrees': true,+ scale: true,+ 'text-content': true,+ 'transform-origin': true,+ translate: true,+ 'uv-coordinate': true,+} as const satisfies Record<InteractivitySchemaField['type'], boolean>;++type TimelineSchemaFieldTypeSupport = typeof TIMELINE_SCHEMA_FIELD_TYPE_SUPPORT;++type SupportedSchemaType = {+ [FieldType in keyof TimelineSchemaFieldTypeSupport]: TimelineSchemaFieldTypeSupport[FieldType] extends true+ ? FieldType+ : never;+}[keyof TimelineSchemaFieldTypeSupport];++type SupportedSchemaField = Extract<+ InteractivitySchemaField,+ {type: SupportedSchemaType}+>;++const isTimelineSchemaFieldSupported = (+ field: InteractivitySchemaField,+): field is SupportedSchemaField =>+ TIMELINE_SCHEMA_FIELD_TYPE_SUPPORT[field.type];const getArrayRowCount = ({fieldSchema,@@ -222,15 +241,12 @@ export const getFieldsToShow = ({const fields = Object.entries(activeSchema).map(([key, fieldSchema]): InteractivitySchemaFieldInfo | null => {- const typeName = fieldSchema.type;- if (SUPPORTED_SCHEMA_TYPES.indexOf(typeName) === -1) {- throw new Error(`Unsupported field type: ${typeName}`);- }-- if (typeName === 'hidden') {+ if (!isTimelineSchemaFieldSupported(fieldSchema)) {return null;}+ const typeName = fieldSchema.type;+if (fieldSchema.type === 'number' && fieldSchema.hiddenFromList) {return null;}@@ -292,11 +308,12 @@ export const getEffectFieldsToShow = ({const fields = Object.entries(activeSchema).map(([key, fieldSchema]): EffectSchemaFieldInfo | null => {- const typeName = fieldSchema.type;- if (typeName === 'hidden') {+ if (!isTimelineSchemaFieldSupported(fieldSchema)) {return null;}+ const typeName = fieldSchema.type;+if (fieldSchema.type === 'number' && fieldSchema.hiddenFromList) {return null;}@@ -307,10 +324,6 @@ export const getEffectFieldsToShow = ({return null;}- if (SUPPORTED_SCHEMA_TYPES.indexOf(typeName) === -1) {- throw new Error(`Unsupported field type: ${typeName}`);- }-return {kind: 'effect-field',key,diff --git a/packages/studio-shared/src/test/keyframe-clipboard-data.test.ts b/packages/studio-shared/src/test/keyframe-clipboard-data.test.tsnew file mode 100644index 0000000000..09eedf0e4f--- /dev/null+++ b/packages/studio-shared/src/test/keyframe-clipboard-data.test.ts@@ -0,0 +1,105 @@+import {expect, test} from 'bun:test';+import {+ parseKeyframeClipboardData,+ parseKeyframeClipboardDataResult,+} from '../keyframe-clipboard-data';++test('parses keyframe clipboard data', () => {+ expect(+ parseKeyframeClipboardData(+ JSON.stringify({+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: 'number',+ keyframes: [+ {frameOffset: 0, value: 0.5},+ {frameOffset: 20, value: 1},+ ],+ easing: [{type: 'linear'}],+ }),+ ),+ ).toEqual({+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: 'number',+ keyframes: [+ {frameOffset: 0, value: 0.5},+ {frameOffset: 20, value: 1},+ ],+ easing: [{type: 'linear'}],+ });+});++test('allows keyframes without a schema field type', () => {+ expect(+ parseKeyframeClipboardData(+ JSON.stringify({+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: null,+ keyframes: [{frameOffset: 0, value: '#ff0000'}],+ easing: [],+ }),+ ),+ ).not.toBe(null);+});++test('rejects invalid and unsupported keyframe clipboard data', () => {+ expect(+ parseKeyframeClipboardDataResult(+ JSON.stringify({+ type: 'keyframe',+ version: 2,+ remotionClipboard: 'keyframe',+ fieldType: 'number',+ keyframes: [{frameOffset: 0, value: 1}],+ easing: [],+ }),+ ),+ ).toEqual({status: 'unsupported-version', version: 2});+ expect(+ parseKeyframeClipboardData(+ JSON.stringify({+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: 'array',+ keyframes: [{frameOffset: 0, value: []}],+ easing: [],+ }),+ ),+ ).toBe(null);+ expect(+ parseKeyframeClipboardData(+ JSON.stringify({+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: 'number',+ keyframes: [+ {frameOffset: 10, value: 1},+ {frameOffset: 5, value: 2},+ ],+ easing: [{type: 'linear'}],+ }),+ ),+ ).toBe(null);+ expect(+ parseKeyframeClipboardData(+ JSON.stringify({+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: 'number',+ keyframes: [+ {frameOffset: 0, value: 1},+ {frameOffset: 10, value: 2},+ ],+ easing: [],+ }),+ ),+ ).toBe(null);+});diff --git a/packages/studio-shared/src/test/keyframe-interpolation-function.test.ts b/packages/studio-shared/src/test/keyframe-interpolation-function.test.tsindex 15069cd27f..ec7080e25e 100644--- a/packages/studio-shared/src/test/keyframe-interpolation-function.test.ts+++ b/packages/studio-shared/src/test/keyframe-interpolation-function.test.ts@@ -1,10 +1,28 @@import {expect, test} from 'bun:test';import type {InteractivitySchema} from 'remotion';import {+ canEditEasingForInterpolationFunction,getKeyframeInterpolationFunctionForSchemaField,+ isInteractivitySchemaFieldKeyframable,isSchemaFieldKeyframable,} from '../keyframe-interpolation-function';+test('known interpolation functions explicitly support easing', () => {+ expect(canEditEasingForInterpolationFunction('interpolate')).toBe(true);+ expect(canEditEasingForInterpolationFunction('interpolateColors')).toBe(true);+ expect(canEditEasingForInterpolationFunction('unknown')).toBe(false);+});++test('field type keyframe support is explicit', () => {+ expect(isInteractivitySchemaFieldKeyframable({type: 'hidden'})).toBe(true);+ expect(+ isInteractivitySchemaFieldKeyframable({+ type: 'text-content',+ default: '',+ }),+ ).toBe(false);+});+test('isSchemaFieldKeyframable rejects enum fields', () => {const schema = {layout: {diff --git a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsxindex 35965723b4..67cf5edaaa 100644--- a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx+++ b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx@@ -1,5 +1,6 @@import {isKeyframeInterpolationFunction,+ parseKeyframeClipboardDataResult,parseEasingClipboardDataResult,parseEffectClipboardDataResult,parseEffectPropClipboardDataResult,@@ -10,9 +11,10 @@ import {type EffectClipboardPasteType,type EffectClipboardSnapshot,type EffectPropClipboardData,+ type KeyframeClipboardData,} from '@remotion/studio-shared';import type React from 'react';-import {useContext, useEffect} from 'react';+import {useContext, useEffect, useRef} from 'react';import {Internals,type OverrideIdToNodePaths,@@ -31,6 +33,12 @@ import {import {callApi} from '../call-api';import {useConfirmationDialog} from '../ConfirmationDialog';import {showNotification} from '../Notifications/NotificationCenter';+import {callAddKeyframes} from './call-add-keyframe';+import {callDeleteKeyframes} from './call-delete-keyframe';+import {+ callUpdateEffectKeyframeSettings,+ callUpdateSequenceKeyframeSettings,+} from './call-update-keyframe-settings';import {deleteSelectedTimelineItems,getTimelineSelectionAfterDeletingItems,@@ -41,6 +49,10 @@ import {type EffectsClipboardEnvelope,} from './effects-clipboard';import {findTrackForNodePathInfo} from './find-track-for-node-path-info';+import {+ getKeyframeClipboardDataFromSelections,+ getPasteKeyframeTarget,+} from './keyframe-clipboard';import {saveEffectProp} from './save-effect-prop';import {useCurrentTimelineSelectionStateAsRef,@@ -55,7 +67,11 @@ import {} from './update-selected-easing';const makeClipboardText = (- payload: EffectClipboardData | EffectPropClipboardData | EasingClipboardData,+ payload:+ | EffectClipboardData+ | EffectPropClipboardData+ | EasingClipboardData+ | KeyframeClipboardData,) => JSON.stringify(payload);const makeTargetKey = (nodePath: SequencePropsSubscriptionKey): string => {@@ -622,6 +638,9 @@ export const getPasteEffectPropTarget = ({export const TimelineClipboardKeybindings: React.FC = () => {const keybindings = useKeybinding();+ const timelinePosition = Internals.Timeline.useTimelinePosition();+ const timelinePositionRef = useRef(timelinePosition);+ timelinePositionRef.current = timelinePosition;const {previewServerState} = useContext(StudioServerConnectionCtx);const {canSelect} = useTimelineSelection();const currentSelection = useCurrentTimelineSelectionStateAsRef();@@ -653,6 +672,46 @@ export const TimelineClipboardKeybindings: React.FC = () => {return;}+ const keyframeSelections = selectedItems.filter(+ (selection) => selection.type === 'keyframe',+ );+ if (keyframeSelections.length > 0) {+ e.preventDefault();+ if (+ selectedItems.some(+ (selection) =>+ selection.type !== 'keyframe' && selection.type !== 'easing',+ )+ ) {+ showNotification('Select only keyframes and easings to copy', 3000);+ return;+ }++ const payload = getKeyframeClipboardDataFromSelections({+ selections: selectedItems,+ sequences,+ overrideIdsToNodePaths: overrideIdToNodePathMappings,+ propStatuses,+ });+ if (payload === null) {+ showNotification(+ 'Select a continuous keyframe range from one property to copy',+ 3000,+ );+ return;+ }++ navigator.clipboard+ .writeText(makeClipboardText(payload))+ .catch((err) => {+ showNotification(+ `Could not copy keyframe: ${(err as Error).message}`,+ 2000,+ );+ });+ return;+ }+const easingSelections = getEasingSelections(selectedItems);if (easingSelections.length > 0) {e.preventDefault();@@ -883,6 +942,134 @@ export const TimelineClipboardKeybindings: React.FC = () => {.then(() => {const propStatuses = propStatusesRef.current;const sequences = sequencesRef.current;+ const keyframeResult = parseKeyframeClipboardDataResult(text);+ if (keyframeResult.status !== 'invalid') {+ if (keyframeResult.status === 'unsupported-version') {+ showNotification(+ 'Cannot paste keyframe copied from a different Remotion Studio version',+ 4000,+ );+ return;+ }++ const keyframeTarget = getPasteKeyframeTarget({+ selectedItems,+ payload: keyframeResult.data,+ timelinePosition: timelinePositionRef.current,+ sequences,+ overrideIdsToNodePaths: overrideIdToNodePathMappings,+ propStatuses,+ });+ if (keyframeTarget.type !== 'valid') {+ switch (keyframeTarget.type) {+ case 'none':+ showNotification(+ 'Select a property or keyframe to paste onto',+ 3000,+ );+ return;+ case 'multiple':+ showNotification(+ 'Select one property or keyframe to paste onto',+ 3000,+ );+ return;+ case 'uncopyable':+ showNotification(+ 'Cannot paste onto a property that cannot be updated',+ 3000,+ );+ return;+ case 'incompatible':+ showNotification(+ 'The copied keyframe is not compatible with this property',+ 3000,+ );+ return;+ default:+ throw new Error(+ `Unexpected paste target: ${keyframeTarget satisfies never}`,+ );+ }+ }++ const changes = keyframeTarget.keyframes.map((keyframe) => ({+ fileName: keyframeTarget.fileName,+ nodePath: keyframeTarget.nodePath,+ fieldKey: keyframeTarget.fieldKey,+ sourceFrame: keyframe.sourceFrame,+ value: keyframe.value,+ schema: keyframeTarget.schema,+ }));+ const {effectIndex} = keyframeTarget;++ const deletions = keyframeTarget.keyframesToDelete.map(+ (sourceFrame) => ({+ fileName: keyframeTarget.fileName,+ nodePath: keyframeTarget.nodePath,+ fieldKey: keyframeTarget.fieldKey,+ sourceFrame,+ schema: keyframeTarget.schema,+ }),+ );++ return callDeleteKeyframes({+ sequenceKeyframes: effectIndex === null ? deletions : [],+ effectKeyframes:+ effectIndex === null+ ? []+ : deletions.map((deletion) => ({+ ...deletion,+ effectIndex,+ })),+ setPropStatuses,+ clientId,+ })+ .then(() =>+ callAddKeyframes({+ sequenceKeyframes: effectIndex === null ? changes : [],+ effectKeyframes:+ effectIndex === null+ ? []+ : changes.map((change) => ({...change, effectIndex})),+ setPropStatuses,+ clientId,+ }),+ )+ .then(async () => {+ for (const [index, easing] of keyframeTarget.easing.entries()) {+ const settings = {+ type: 'easing' as const,+ segmentIndex:+ keyframeTarget.firstEasingSegmentIndex + index,+ easing,+ };+ if (effectIndex === null) {+ await callUpdateSequenceKeyframeSettings({+ fileName: keyframeTarget.fileName,+ nodePath: keyframeTarget.nodePath,+ fieldKey: keyframeTarget.fieldKey,+ settings,+ schema: keyframeTarget.schema,+ setPropStatuses,+ clientId,+ });+ } else {+ await callUpdateEffectKeyframeSettings({+ fileName: keyframeTarget.fileName,+ nodePath: keyframeTarget.nodePath,+ effectIndex,+ fieldKey: keyframeTarget.fieldKey,+ settings,+ schema: keyframeTarget.schema,+ setPropStatuses,+ clientId,+ });+ }+ }+ });+ }+const easingResult = parseEasingClipboardDataResult(text);if (easingResult.status !== 'invalid') {e.preventDefault();@@ -1085,10 +1272,7 @@ export const TimelineClipboardKeybindings: React.FC = () => {});}).catch((err) => {- showNotification(- `Could not paste effects: ${(err as Error).message}`,- 3000,- );+ showNotification(`Could not paste: ${(err as Error).message}`, 3000);});};@@ -1113,6 +1297,7 @@ export const TimelineClipboardKeybindings: React.FC = () => {previewServerState,sequencesRef,setPropStatuses,+ timelinePositionRef,]);return null;diff --git a/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsx b/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsxindex 884922d1c0..b1ae466a81 100644--- a/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsx+++ b/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsx@@ -38,11 +38,7 @@ export type TimelinePrimitiveFieldInfo = Omit<export const isTimelinePrimitiveFieldInfo = (field: SchemaFieldInfo,): field is TimelinePrimitiveFieldInfo => {- return (- field.typeName !== 'array' &&- field.typeName !== 'hidden' &&- field.fieldSchema.type !== 'array'- );+ return field.typeName !== 'array' && field.fieldSchema.type !== 'array';};export const TimelinePrimitiveFieldValue: React.FC<{diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsxindex 81bae5fd2d..402c8fcf81 100644--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx@@ -1,4 +1,7 @@-import {stringifySequenceExpandedRowKey} from '@remotion/studio-shared';+import {+ canEditEasingForInterpolationFunction,+ stringifySequenceExpandedRowKey,+} from '@remotion/studio-shared';import React, {createContext,useCallback,@@ -495,12 +498,36 @@ export const getTimelineMarqueeSelection = ({readonly lockedSelectionKind: TimelineMarqueeSelectionKind | null;readonly selectedItems: readonly TimelineSelection[];} => {- const intersectingCandidates = candidates.filter((candidate) => {+ const geometricallyIntersectingCandidates = candidates.filter((candidate) => {return (getTimelineMarqueeSelectionKind(candidate.item) !== null &&timelineMarqueeRectsIntersect(candidate.rect, marqueeRect));});+ const intersectingKeyframes = new Set(+ geometricallyIntersectingCandidates.flatMap((candidate) => {+ if (candidate.item.type !== 'keyframe') {+ return [];+ }++ return [+ `${timelineNodePathInfoToKey(candidate.item.nodePathInfo)}.${candidate.item.frame}`,+ ];+ }),+ );+ const intersectingCandidates = geometricallyIntersectingCandidates.filter(+ (candidate) => {+ if (candidate.item.type !== 'easing') {+ return true;+ }++ const fieldKey = timelineNodePathInfoToKey(candidate.item.nodePathInfo);+ return (+ intersectingKeyframes.has(`${fieldKey}.${candidate.item.fromFrame}`) &&+ intersectingKeyframes.has(`${fieldKey}.${candidate.item.toFrame}`)+ );+ },+ );const getFirstIntersectingSelectionKind = () =>intersectingCandidates.length === 0? null@@ -754,12 +781,6 @@ export const getSelectableTimelineSequenceSelections = (});};-const canEditEasingForInterpolationFunction = (- interpolationFunction: string,-): boolean =>- interpolationFunction === 'interpolate' ||- interpolationFunction === 'interpolateColors';-const getTimelineTreeNodeCanEditEasing = ({node,nodePathInfo,diff --git a/packages/studio/src/components/Timeline/keyframe-clipboard.ts b/packages/studio/src/components/Timeline/keyframe-clipboard.tsnew file mode 100644index 0000000000..2f350ef1e0--- /dev/null+++ b/packages/studio/src/components/Timeline/keyframe-clipboard.ts@@ -0,0 +1,475 @@+import type {+ KeyframeClipboardData,+ KeyframeClipboardFieldType,+} from '@remotion/studio-shared';+import {+ isKeyframeClipboardFieldType,+ LINEAR_KEYFRAME_EASING,+} from '@remotion/studio-shared';+import {+ Internals,+ type CanUpdateSequencePropStatus,+ type InteractivitySchema,+ type OverrideIdToNodePaths,+ type PropStatuses,+ type SequencePropsSubscriptionKey,+ type TSequence,+} from 'remotion';+import {findTrackForNodePathInfo} from './find-track-for-node-path-info';+import {parseKeyframeFieldFromNodePath} from './parse-keyframe-field-from-node-path';+import type {TimelineSelection} from './TimelineSelection';++type KeyframeFieldIdentity =+ | {readonly type: 'sequence'; readonly fieldKey: string}+ | {+ readonly type: 'effect';+ readonly effectIndex: number;+ readonly fieldKey: string;+ };++type ResolvedKeyframeField = {+ readonly identity: KeyframeFieldIdentity;+ readonly nodePath: SequencePropsSubscriptionKey;+ readonly fileName: string;+ readonly schema: InteractivitySchema;+ readonly fieldType: KeyframeClipboardFieldType | null;+ readonly propStatus: CanUpdateSequencePropStatus;+ readonly keyframeDisplayOffset: number;+};++const getKeyframeClipboardFieldType = ({+ schema,+ fieldKey,+}: {+ readonly schema: InteractivitySchema;+ readonly fieldKey: string;+}): KeyframeClipboardFieldType | null => {+ const field = Internals.getFlatSchemaWithAllKeys(schema)[fieldKey];+ if (!field) {+ return null;+ }++ return isKeyframeClipboardFieldType(field.type) ? field.type : null;+};++const getKeyframeFieldIdentity = (+ selection: TimelineSelection,+): KeyframeFieldIdentity | null => {+ if (selection.type === 'keyframe' || selection.type === 'easing') {+ return parseKeyframeFieldFromNodePath(selection.nodePathInfo.auxiliaryKeys);+ }++ if (selection.type === 'sequence-prop') {+ return {type: 'sequence', fieldKey: selection.key};+ }++ if (selection.type === 'sequence-effect-prop') {+ return {+ type: 'effect',+ effectIndex: selection.i,+ fieldKey: selection.key,+ };+ }++ return null;+};++const resolveKeyframeField = ({+ selection,+ sequences,+ overrideIdsToNodePaths,+ propStatuses,+}: {+ readonly selection: TimelineSelection;+ readonly sequences: TSequence[];+ readonly overrideIdsToNodePaths: OverrideIdToNodePaths;+ readonly propStatuses: PropStatuses;+}): ResolvedKeyframeField | null => {+ if (+ selection.type !== 'keyframe' &&+ selection.type !== 'easing' &&+ selection.type !== 'sequence-prop' &&+ selection.type !== 'sequence-effect-prop'+ ) {+ return null;+ }++ const identity = getKeyframeFieldIdentity(selection);+ if (identity === null) {+ return null;+ }++ const track = findTrackForNodePathInfo({+ sequences,+ overrideIdsToNodePaths,+ nodePathInfo: selection.nodePathInfo,+ });+ if (!track || track.nodePathInfo === null) {+ return null;+ }++ const nodePath = track.nodePathInfo.sequenceSubscriptionKey;+ if (identity.type === 'sequence') {+ if (!track.sequence.controls) {+ return null;+ }++ const sequencePropStatus = Internals.getPropStatusesCtx(+ propStatuses,+ nodePath,+ )?.[identity.fieldKey];+ if (!sequencePropStatus || sequencePropStatus.status === 'computed') {+ return null;+ }++ const {schema} = track.sequence.controls;+ return {+ identity,+ nodePath,+ fileName: nodePath.absolutePath,+ schema,+ fieldType: getKeyframeClipboardFieldType({+ schema,+ fieldKey: identity.fieldKey,+ }),+ propStatus: sequencePropStatus,+ keyframeDisplayOffset: track.keyframeDisplayOffset,+ };+ }++ const effect = track.sequence.effects[identity.effectIndex];+ const effectStatus = Internals.getEffectPropStatusesCtx({+ propStatuses,+ nodePath,+ effectIndex: identity.effectIndex,+ });+ const effectPropStatus =+ effectStatus.type === 'can-update-effect'+ ? effectStatus.props?.[identity.fieldKey]+ : null;+ if (!effect || !effectPropStatus || effectPropStatus.status === 'computed') {+ return null;+ }++ return {+ identity,+ nodePath,+ fileName: nodePath.absolutePath,+ schema: effect.schema,+ fieldType: getKeyframeClipboardFieldType({+ schema: effect.schema,+ fieldKey: identity.fieldKey,+ }),+ propStatus: effectPropStatus,+ keyframeDisplayOffset: track.keyframeDisplayOffset,+ };+};++const areResolvedFieldsEqual = (+ first: ResolvedKeyframeField,+ second: ResolvedKeyframeField,+): boolean => {+ if (+ Internals.makeSequencePropsSubscriptionKey(first.nodePath) !==+ Internals.makeSequencePropsSubscriptionKey(second.nodePath)+ ) {+ return false;+ }++ if (first.identity.type !== second.identity.type) {+ return false;+ }++ if (first.identity.fieldKey !== second.identity.fieldKey) {+ return false;+ }++ return (+ first.identity.type === 'sequence' ||+ (second.identity.type === 'effect' &&+ first.identity.effectIndex === second.identity.effectIndex)+ );+};++export const getKeyframeClipboardDataFromSelections = ({+ selections,+ sequences,+ overrideIdsToNodePaths,+ propStatuses,+}: {+ readonly selections: readonly TimelineSelection[];+ readonly sequences: TSequence[];+ readonly overrideIdsToNodePaths: OverrideIdToNodePaths;+ readonly propStatuses: PropStatuses;+}): KeyframeClipboardData | null => {+ const keyframeSelections = selections.filter(+ (selection): selection is Extract<TimelineSelection, {type: 'keyframe'}> =>+ selection.type === 'keyframe',+ );+ const easingSelections = selections.filter(+ (selection): selection is Extract<TimelineSelection, {type: 'easing'}> =>+ selection.type === 'easing',+ );+ if (+ keyframeSelections.length + easingSelections.length !==+ selections.length+ ) {+ return null;+ }++ const resolvedFields = keyframeSelections.map((selection) => ({+ selection,+ resolved: resolveKeyframeField({+ selection,+ sequences,+ overrideIdsToNodePaths,+ propStatuses,+ }),+ }));+ const firstResolved = resolvedFields[0]?.resolved;+ if (+ firstResolved === null ||+ firstResolved === undefined ||+ resolvedFields.some(+ ({resolved}) =>+ resolved === null || !areResolvedFieldsEqual(firstResolved, resolved),+ )+ ) {+ return null;+ }++ const keyframedPropStatus = firstResolved.propStatus;+ if (keyframedPropStatus.status !== 'keyframed') {+ return null;+ }++ const keyframes: {readonly frame: number; readonly value: unknown}[] = [];+ for (const {selection} of resolvedFields) {+ const sourceFrame = selection.frame - firstResolved.keyframeDisplayOffset;+ const keyframe = keyframedPropStatus.keyframes.find(+ (item) => item.frame === sourceFrame,+ );+ if (+ keyframe === undefined ||+ JSON.stringify(keyframe.value) === undefined+ ) {+ return null;+ }++ keyframes.push({frame: sourceFrame, value: keyframe.value});+ }++ keyframes.sort((first, second) => first.frame - second.frame);+ const firstFrame = keyframes[0]?.frame;+ if (firstFrame === undefined) {+ return null;+ }++ const keyframeIndexes = keyframes.map((keyframe) =>+ keyframedPropStatus.keyframes.findIndex(+ (item) => item.frame === keyframe.frame,+ ),+ );+ if (+ keyframeIndexes.some(+ (index, position) =>+ index === -1 ||+ (position > 0 && index !== keyframeIndexes[position - 1] + 1),+ )+ ) {+ return null;+ }++ const firstKeyframeIndex = keyframeIndexes[0];+ const lastKeyframeIndex = keyframeIndexes.at(-1);+ if (firstKeyframeIndex === undefined || lastKeyframeIndex === undefined) {+ return null;+ }++ for (const easingSelection of easingSelections) {+ const resolved = resolveKeyframeField({+ selection: easingSelection,+ sequences,+ overrideIdsToNodePaths,+ propStatuses,+ });+ if (+ resolved === null ||+ !areResolvedFieldsEqual(firstResolved, resolved) ||+ easingSelection.segmentIndex < firstKeyframeIndex ||+ easingSelection.segmentIndex >= lastKeyframeIndex+ ) {+ return null;+ }+ }++ return {+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: firstResolved.fieldType,+ keyframes: keyframes.map((keyframe) => {+ return {+ frameOffset: keyframe.frame - firstFrame,+ value: keyframe.value,+ };+ }),+ easing: keyframeIndexes.slice(0, -1).map((index) => {+ return keyframedPropStatus.easing[index] ?? LINEAR_KEYFRAME_EASING;+ }),+ };+};++export type PasteKeyframeTarget =+ | {+ readonly type: 'valid';+ readonly fileName: string;+ readonly nodePath: SequencePropsSubscriptionKey;+ readonly fieldKey: string;+ readonly effectIndex: number | null;+ readonly keyframes: readonly {+ readonly sourceFrame: number;+ readonly value: unknown;+ }[];+ readonly keyframesToDelete: readonly number[];+ readonly easing: KeyframeClipboardData['easing'];+ readonly firstEasingSegmentIndex: number;+ readonly schema: InteractivitySchema;+ }+ | {+ readonly type: 'none' | 'multiple' | 'uncopyable' | 'incompatible';+ };++const isKeyframeValueCompatible = ({+ value,+ fieldType,+}: {+ readonly value: unknown;+ readonly fieldType: KeyframeClipboardFieldType | null;+}): boolean => {+ if (fieldType === null) {+ return true;+ }++ if (fieldType === 'number' || fieldType === 'rotation-degrees') {+ return typeof value === 'number' && Number.isFinite(value);+ }++ if (fieldType === 'scale') {+ return (+ (typeof value === 'number' && Number.isFinite(value)) ||+ typeof value === 'string'+ );+ }++ if (fieldType === 'uv-coordinate') {+ return (+ Array.isArray(value) &&+ value.length === 2 &&+ value.every((item) => typeof item === 'number' && Number.isFinite(item))+ );+ }++ return typeof value === 'string';+};++export const getPasteKeyframeTarget = ({+ selectedItems,+ payload,+ timelinePosition,+ sequences,+ overrideIdsToNodePaths,+ propStatuses,+}: {+ readonly selectedItems: readonly TimelineSelection[];+ readonly payload: KeyframeClipboardData;+ readonly timelinePosition: number;+ readonly sequences: TSequence[];+ readonly overrideIdsToNodePaths: OverrideIdToNodePaths;+ readonly propStatuses: PropStatuses;+}): PasteKeyframeTarget => {+ if (selectedItems.length === 0) {+ return {type: 'none'};+ }++ const selection = selectedItems[0];+ if (!selection || getKeyframeFieldIdentity(selection) === null) {+ return {type: 'none'};+ }++ const resolvedFields = selectedItems.map((item) =>+ resolveKeyframeField({+ selection: item,+ sequences,+ overrideIdsToNodePaths,+ propStatuses,+ }),+ );+ const resolved = resolvedFields[0];+ if (resolved === null) {+ return {type: 'uncopyable'};+ }++ if (+ resolvedFields.some(+ (field) => field === null || !areResolvedFieldsEqual(resolved, field),+ )+ ) {+ return {type: 'multiple'};+ }++ const keyframes = payload.keyframes.map((keyframe) => ({+ sourceFrame:+ timelinePosition - resolved.keyframeDisplayOffset + keyframe.frameOffset,+ value: keyframe.value,+ }));+ const firstFrame = keyframes[0]?.sourceFrame;+ const lastFrame = keyframes.at(-1)?.sourceFrame;+ if (firstFrame === undefined || lastFrame === undefined) {+ return {type: 'incompatible'};+ }++ const existingFrames =+ resolved.propStatus.status === 'keyframed'+ ? resolved.propStatus.keyframes.map((keyframe) => keyframe.frame)+ : [];+ const keyframesToDelete = existingFrames.filter(+ (frame) => frame >= firstFrame && frame <= lastFrame,+ );+ const finalFrames = [+ ...existingFrames.filter(+ (frame) => frame < firstFrame || frame > lastFrame,+ ),+ ...keyframes.map((keyframe) => keyframe.sourceFrame),+ ].sort((first, second) => first - second);+ const firstEasingSegmentIndex = finalFrames.indexOf(firstFrame);++ if (+ resolved.fieldType !== payload.fieldType ||+ payload.keyframes.some(+ (keyframe) =>+ !isKeyframeValueCompatible({+ value: keyframe.value,+ fieldType: payload.fieldType,+ }),+ )+ ) {+ return {type: 'incompatible'};+ }++ return {+ type: 'valid',+ fileName: resolved.fileName,+ nodePath: resolved.nodePath,+ fieldKey: resolved.identity.fieldKey,+ effectIndex:+ resolved.identity.type === 'effect'+ ? resolved.identity.effectIndex+ : null,+ keyframes,+ keyframesToDelete,+ easing: payload.easing,+ firstEasingSegmentIndex,+ schema: resolved.schema,+ };+};diff --git a/packages/studio/src/components/Timeline/timeline-field-display-utils.ts b/packages/studio/src/components/Timeline/timeline-field-display-utils.tsindex cd87d26fc5..ab796b86a8 100644--- a/packages/studio/src/components/Timeline/timeline-field-display-utils.ts+++ b/packages/studio/src/components/Timeline/timeline-field-display-utils.ts@@ -395,10 +395,11 @@ export const formatTimelineFieldValueForDisplay = ({case 'boolean':case 'color':case 'enum':+ case 'font-family':case 'hidden':return formatUnknownTimelineValueForDisplay(value);default:- return formatUnknownTimelineValueForDisplay(value);+ throw new Error(`Unsupported field type: ${fieldSchema satisfies never}`);}};diff --git a/packages/studio/src/components/Timeline/update-selected-easing.ts b/packages/studio/src/components/Timeline/update-selected-easing.tsindex 07fb0ed6d0..be7bb6db7c 100644--- a/packages/studio/src/components/Timeline/update-selected-easing.ts+++ b/packages/studio/src/components/Timeline/update-selected-easing.ts@@ -1,4 +1,8 @@-import {LINEAR_KEYFRAME_EASING} from '@remotion/studio-shared';+import {+ canEditEasingForInterpolationFunction,+ LINEAR_KEYFRAME_EASING,+} from '@remotion/studio-shared';+export {canEditEasingForInterpolationFunction} from '@remotion/studio-shared';import type {CanUpdateSequencePropStatusKeyframed,CanUpdateSequencePropStatusEasing,@@ -47,12 +51,6 @@ export type SelectedEasingUpdate =readonly propStatus: CanUpdateSequencePropStatusKeyframed;};-export const canEditEasingForInterpolationFunction = (- interpolationFunction: string,-): boolean =>- interpolationFunction === 'interpolate' ||- interpolationFunction === 'interpolateColors';-const isEasingSelection = (selection: TimelineSelection,): selection is EasingSelection => selection.type === 'easing';diff --git a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.tsindex ec651024dd..613c8c2e78 100644--- a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts+++ b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts@@ -1,3 +1,4 @@+import {canEditEasingForInterpolationFunction} from '@remotion/studio-shared';import {useContext, useMemo} from 'react';import {Internals, type TSequence} from 'remotion';import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';@@ -17,12 +18,6 @@ import {} from './timeline-expanded-filter';import {useTimelineSelection} from './TimelineSelection';-const canEditEasingForInterpolationFunction = (- interpolationFunction: string,-): boolean =>- interpolationFunction === 'interpolate' ||- interpolationFunction === 'interpolateColors';-export type ExpandedTrackKeyframeRow = {readonly height: number;readonly keyframes: ReturnType<typeof getTimelineKeyframes>;diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.tsindex a1f5e512bf..04ab9e9041 100644--- a/packages/studio/src/test/timeline-selection.test.ts+++ b/packages/studio/src/test/timeline-selection.test.ts@@ -69,6 +69,11 @@ import {isDuplicatableEffectSelection,isDuplicatableSequenceRowSelection,} from '../components/Timeline/duplicate-selected-timeline-item';+import {+ getKeyframeClipboardDataFromSelections,+ getPasteKeyframeTarget,+ type PasteKeyframeTarget,+} from '../components/Timeline/keyframe-clipboard';import {getTimelinePropResetTargets} from '../components/Timeline/reset-selected-timeline-props';import {shouldSubscribeToSequenceProps} from '../components/Timeline/should-subscribe-to-sequence-props';import {@@ -381,7 +386,6 @@ test('timeline marquee locks to sequences after capturing a sequence first', ()test('timeline marquee locks to keyframes and easings after capturing a keyframe first', () => {const keyframe = makeNodePathInfo(['body', 0], ['controls', 'opacity']);const sequence = makeNodePathInfo(['body', 1], []);- const easing = makeNodePathInfo(['body', 2], ['controls', 'scale']);const result = getTimelineMarqueeSelection({lockedSelectionKind: null,@@ -398,13 +402,17 @@ test('timeline marquee locks to keyframes and easings after capturing a keyframe{item: {type: 'easing',- nodePathInfo: easing,+ nodePathInfo: keyframe,fromFrame: 20,toFrame: 30,segmentIndex: 0,},rect: {left: 40, top: 0, right: 50, bottom: 10},},+ {+ item: {type: 'keyframe', nodePathInfo: keyframe, frame: 30},+ rect: {left: 60, top: 0, right: 70, bottom: 10},+ },],});@@ -413,14 +421,58 @@ test('timeline marquee locks to keyframes and easings after capturing a keyframe{type: 'keyframe', nodePathInfo: keyframe, frame: 20},{type: 'easing',- nodePathInfo: easing,+ nodePathInfo: keyframe,fromFrame: 20,toFrame: 30,segmentIndex: 0,},+ {type: 'keyframe', nodePathInfo: keyframe, frame: 30},]);});+test('timeline marquee selects easing only when both endpoint keyframes intersect', () => {+ const nodePathInfo = makeNodePathInfo(['body', 0], ['controls', 'opacity']);+ const easing = {+ type: 'easing' as const,+ nodePathInfo,+ fromFrame: 20,+ toFrame: 30,+ segmentIndex: 0,+ };+ const candidates = [+ {+ item: {type: 'keyframe' as const, nodePathInfo, frame: 20},+ rect: {left: 0, top: 0, right: 10, bottom: 10},+ },+ {+ item: easing,+ rect: {left: 20, top: 0, right: 80, bottom: 10},+ },+ {+ item: {type: 'keyframe' as const, nodePathInfo, frame: 30},+ rect: {left: 90, top: 0, right: 100, bottom: 10},+ },+ ];++ expect(+ getTimelineMarqueeSelection({+ lockedSelectionKind: null,+ marqueeRect: {left: 20, top: 0, right: 80, bottom: 10},+ candidates,+ }),+ ).toEqual({lockedSelectionKind: null, selectedItems: []});+ expect(+ getTimelineMarqueeSelection({+ lockedSelectionKind: null,+ marqueeRect: {left: 0, top: 0, right: 100, bottom: 10},+ candidates,+ }),+ ).toEqual({+ lockedSelectionKind: 'keyframes-and-easings',+ selectedItems: [candidates[0].item, easing, candidates[2].item],+ });+});+test('timeline marquee keeps its locked item kind while dragging', () => {const keyframe = makeNodePathInfo(['body', 0], ['controls', 'opacity']);const sequence = makeNodePathInfo(['body', 1], []);@@ -735,6 +787,287 @@ test('copying a selected effect prop creates an effect prop payload', () => {});});+test('copying selected keyframes preserves their frame deltas', () => {+ const nodePathInfo = makeNodePathInfo(['body', 0], ['controls', 'opacity']);+ const nodePath = nodePathInfo.sequenceSubscriptionKey;+ const schema = {+ opacity: {type: 'number', default: 1, hiddenFromList: false},+ } satisfies InteractivitySchema;+ const propStatuses = {+ [Internals.makeSequencePropsSubscriptionKey(nodePath)]: {+ canUpdate: true,+ props: {+ opacity: {+ status: 'keyframed',+ interpolationFunction: 'interpolate',+ keyframes: [+ {frame: 10, value: 0.4},+ {frame: 30, value: 0.8},+ ],+ easing: [],+ clamping: {left: 'clamp', right: 'clamp'},+ posterize: undefined,+ output: undefined,+ },+ },+ effects: [],+ },+ } satisfies PropStatuses;++ expect(+ getKeyframeClipboardDataFromSelections({+ selections: [+ {type: 'keyframe', nodePathInfo, frame: 30},+ {type: 'keyframe', nodePathInfo, frame: 10},+ {+ type: 'easing',+ nodePathInfo,+ fromFrame: 10,+ toFrame: 30,+ segmentIndex: 0,+ },+ ],+ sequences: [makeTimelineSequence({schema, from: 20})],+ overrideIdsToNodePaths: {override: nodePath},+ propStatuses,+ }),+ ).toEqual({+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: 'number',+ keyframes: [+ {frameOffset: 0, value: 0.4},+ {frameOffset: 20, value: 0.8},+ ],+ easing: [{type: 'linear'}],+ });+});++test('copying selected keyframes requires one property', () => {+ const opacityNodePathInfo = makeNodePathInfo(+ ['body', 0],+ ['controls', 'opacity'],+ );+ const otherNodePathInfo = makeNodePathInfo(+ ['body', 0],+ ['controls', 'otherOpacity'],+ );+ const nodePath = opacityNodePathInfo.sequenceSubscriptionKey;+ const schema = {+ opacity: {type: 'number', default: 1, hiddenFromList: false},+ otherOpacity: {type: 'number', default: 1, hiddenFromList: false},+ } satisfies InteractivitySchema;+ const propStatuses = {+ [Internals.makeSequencePropsSubscriptionKey(nodePath)]: {+ canUpdate: true,+ props: {+ opacity: {+ status: 'keyframed',+ interpolationFunction: 'interpolate',+ keyframes: [{frame: 10, value: 0.4}],+ easing: [],+ clamping: {left: 'clamp', right: 'clamp'},+ posterize: undefined,+ output: undefined,+ },+ otherOpacity: {+ status: 'keyframed',+ interpolationFunction: 'interpolate',+ keyframes: [{frame: 30, value: 2}],+ easing: [],+ clamping: {left: 'clamp', right: 'clamp'},+ posterize: undefined,+ output: undefined,+ },+ },+ effects: [],+ },+ } satisfies PropStatuses;++ expect(+ getKeyframeClipboardDataFromSelections({+ selections: [+ {type: 'keyframe', nodePathInfo: opacityNodePathInfo, frame: 10},+ {type: 'keyframe', nodePathInfo: otherNodePathInfo, frame: 30},+ ],+ sequences: [makeTimelineSequence({schema})],+ overrideIdsToNodePaths: {override: nodePath},+ propStatuses,+ }),+ ).toBe(null);+});++test('pasting keyframes targets one selected property at the playhead', () => {+ const nodePathInfo = makeNodePathInfo(['body', 0], ['controls', 'opacity']);+ const nodePath = nodePathInfo.sequenceSubscriptionKey;+ const schema = {+ opacity: {type: 'number', default: 1, hiddenFromList: false},+ } satisfies InteractivitySchema;+ const propStatuses = {+ [Internals.makeSequencePropsSubscriptionKey(nodePath)]: {+ canUpdate: true,+ props: {+ opacity: {status: 'static', codeValue: 1},+ },+ effects: [],+ },+ } satisfies PropStatuses;++ expect(+ getPasteKeyframeTarget({+ selectedItems: [+ {type: 'keyframe', nodePathInfo, frame: 10},+ {type: 'keyframe', nodePathInfo, frame: 30},+ ],+ payload: {+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: 'number',+ keyframes: [+ {frameOffset: 0, value: 0.4},+ {frameOffset: 20, value: 0.8},+ ],+ easing: [{type: 'linear'}],+ },+ timelinePosition: 50,+ sequences: [makeTimelineSequence({schema, from: 20})],+ overrideIdsToNodePaths: {override: nodePath},+ propStatuses,+ }),+ ).toEqual({+ type: 'valid',+ fileName: '/project/src/Comp.tsx',+ nodePath,+ fieldKey: 'opacity',+ effectIndex: null,+ keyframes: [+ {sourceFrame: 50, value: 0.4},+ {sourceFrame: 70, value: 0.8},+ ],+ keyframesToDelete: [],+ easing: [{type: 'linear'}],+ firstEasingSegmentIndex: 0,+ schema,+ } satisfies PasteKeyframeTarget);+});++test('pasting keyframes replaces the destination range and preserves easing', () => {+ const nodePathInfo = makeNodePathInfo(['body', 0], ['controls', 'opacity']);+ const nodePath = nodePathInfo.sequenceSubscriptionKey;+ const schema = {+ opacity: {type: 'number', default: 1, hiddenFromList: false},+ } satisfies InteractivitySchema;+ const propStatuses = {+ [Internals.makeSequencePropsSubscriptionKey(nodePath)]: {+ canUpdate: true,+ props: {+ opacity: {+ status: 'keyframed',+ interpolationFunction: 'interpolate',+ keyframes: [+ {frame: 40, value: 0},+ {frame: 60, value: 0.5},+ {frame: 80, value: 1},+ ],+ easing: [{type: 'linear'}, {type: 'linear'}],+ clamping: {left: 'clamp', right: 'clamp'},+ posterize: undefined,+ output: undefined,+ },+ },+ effects: [],+ },+ } satisfies PropStatuses;+ const copiedEasing = {+ type: 'bezier',+ x1: 0.42,+ y1: 0,+ x2: 0.58,+ y2: 1,+ } as const;++ expect(+ getPasteKeyframeTarget({+ selectedItems: [{type: 'sequence-prop', nodePathInfo, key: 'opacity'}],+ payload: {+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: 'number',+ keyframes: [+ {frameOffset: 0, value: 0.25},+ {frameOffset: 20, value: 0.75},+ ],+ easing: [copiedEasing],+ },+ timelinePosition: 50,+ sequences: [makeTimelineSequence({schema})],+ overrideIdsToNodePaths: {override: nodePath},+ propStatuses,+ }),+ ).toEqual({+ type: 'valid',+ fileName: '/project/src/Comp.tsx',+ nodePath,+ fieldKey: 'opacity',+ effectIndex: null,+ keyframes: [+ {sourceFrame: 50, value: 0.25},+ {sourceFrame: 70, value: 0.75},+ ],+ keyframesToDelete: [60],+ easing: [copiedEasing],+ firstEasingSegmentIndex: 1,+ schema,+ } satisfies PasteKeyframeTarget);+});++test('pasting a keyframe rejects an incompatible property', () => {+ const nodePathInfo = makeNodePathInfo(+ ['body', 0],+ ['controls', 'background'],+ );+ const nodePath = nodePathInfo.sequenceSubscriptionKey;+ const schema = {+ background: {type: 'color', default: '#ffffff'},+ } satisfies InteractivitySchema;+ const propStatuses = {+ [Internals.makeSequencePropsSubscriptionKey(nodePath)]: {+ canUpdate: true,+ props: {+ background: {status: 'static', codeValue: '#ffffff'},+ },+ effects: [],+ },+ } satisfies PropStatuses;++ expect(+ getPasteKeyframeTarget({+ selectedItems: [+ {+ type: 'sequence-prop',+ nodePathInfo,+ key: 'background',+ },+ ],+ payload: {+ type: 'keyframe',+ version: 1,+ remotionClipboard: 'keyframe',+ fieldType: 'number',+ keyframes: [{frameOffset: 0, value: 0.4}],+ easing: [],+ },+ timelinePosition: 50,+ sequences: [makeTimelineSequence({schema})],+ overrideIdsToNodePaths: {override: nodePath},+ propStatuses,+ }),+ ).toEqual({type: 'incompatible'} satisfies PasteKeyframeTarget);+});+test('copying a selected sequence easing creates an easing payload', () => {const opacityNodePathInfo = makeNodePathInfo(['body', 0],