Skip to content

🎥 Make videos programmatically with React

remotion: Add interpolateRotate API

Jonny Burgereeb5e305a331
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index aa4b4bf2a2..a33c9c672a 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -191,6 +191,10 @@ export {
interpolateColors,
type InterpolateColorsOptions,
} from './interpolate-colors.js';
+export {
+ interpolateRotate,
+ type InterpolateRotateOptions,
+} from './interpolate-rotate.js';
export {
interpolateTranslate,
type InterpolateTranslateOptions,
diff --git a/packages/core/src/interpolate-keyframed-status.ts b/packages/core/src/interpolate-keyframed-status.ts
index b40caebc25..4fd5774ef7 100644
--- a/packages/core/src/interpolate-keyframed-status.ts
+++ b/packages/core/src/interpolate-keyframed-status.ts
@@ -1,6 +1,7 @@
import {bezier} from './bezier.js';
import {Easing} from './easing.js';
import {interpolateColors} from './interpolate-colors.js';
+import {interpolateRotate} from './interpolate-rotate.js';
import {interpolateTranslate} from './interpolate-translate.js';
import type {EasingFunction} from './interpolate.js';
import {interpolate} from './interpolate.js';
@@ -77,6 +78,27 @@ export const interpolateKeyframedStatus = ({
}
}
+ if (interpolationFunction === 'interpolateRotate') {
+ if (!outputs.every((v) => typeof v === 'string')) {
+ return null;
+ }
+
+ if (keyframes.length === 1) {
+ return outputs[0] as string;
+ }
+
+ try {
+ return interpolateRotate(frame, inputRange, outputs as string[], {
+ easing: easing.map(easingToFn),
+ extrapolateLeft: clamping.left,
+ extrapolateRight: clamping.right,
+ posterize: status.posterize,
+ });
+ } catch {
+ return null;
+ }
+ }
+
if (interpolationFunction !== 'interpolate') {
return null;
}
diff --git a/packages/core/src/interpolate-rotate.ts b/packages/core/src/interpolate-rotate.ts
new file mode 100644
index 0000000000..11eb66ba23
--- /dev/null
+++ b/packages/core/src/interpolate-rotate.ts
@@ -0,0 +1,71 @@
+import {interpolate, type InterpolateOptions} from './interpolate.js';
+
+export type InterpolateRotateOptions = InterpolateOptions;
+
+const degreesValueRegex = /^([+-]?(?:\d+\.?\d*|\.\d+))deg$/;
+
+const parseRotate = (value: string): number => {
+ if (typeof value !== 'string') {
+ throw new TypeError(
+ `outputRange must contain only strings, but got ${typeof value}`,
+ );
+ }
+
+ const match = degreesValueRegex.exec(value.trim());
+ if (match === null) {
+ throw new TypeError(
+ `interpolateRotate() only supports deg values, but got "${value}"`,
+ );
+ }
+
+ return Number(match[1]);
+};
+
+/*
+ * @description Allows you to map a range of values to CSS rotate values using degree units.
+ * @see [Documentation](https://remotion.dev/docs/interpolate-rotate)
+ */
+export const interpolateRotate = (
+ input: number,
+ inputRange: readonly number[],
+ outputRange: readonly string[],
+ options?: InterpolateRotateOptions,
+): string => {
+ if (typeof input === 'undefined') {
+ throw new TypeError('input can not be undefined');
+ }
+
+ if (typeof inputRange === 'undefined') {
+ throw new TypeError('inputRange can not be undefined');
+ }
+
+ if (typeof outputRange === 'undefined') {
+ throw new TypeError('outputRange can not be undefined');
+ }
+
+ if (inputRange.length !== outputRange.length) {
+ throw new TypeError(
+ 'inputRange (' +
+ inputRange.length +
+ ' values provided) and outputRange (' +
+ outputRange.length +
+ ' values provided) must have the same length',
+ );
+ }
+
+ const parsedOutputRange = outputRange.map((rotateValue) =>
+ parseRotate(rotateValue),
+ );
+ if (parsedOutputRange.length === 0) {
+ throw new TypeError('outputRange must have at least 1 element');
+ }
+
+ const interpolatedValue = interpolate(
+ input,
+ inputRange,
+ parsedOutputRange,
+ options,
+ );
+
+ return `${interpolatedValue}deg`;
+};
diff --git a/packages/core/src/no-react.ts b/packages/core/src/no-react.ts
index 76d7015dad..80cabf76df 100644
--- a/packages/core/src/no-react.ts
+++ b/packages/core/src/no-react.ts
@@ -15,6 +15,10 @@ export type {
ExtrapolateType,
InterpolateOptions,
} from './interpolate';
+export {
+ interpolateRotate,
+ type InterpolateRotateOptions,
+} from './interpolate-rotate';
export {
interpolateTranslate,
type InterpolateTranslateOptions,
diff --git a/packages/core/src/test/interpolate-keyframed-status.test.ts b/packages/core/src/test/interpolate-keyframed-status.test.ts
index d0ac266649..dfca154087 100644
--- a/packages/core/src/test/interpolate-keyframed-status.test.ts
+++ b/packages/core/src/test/interpolate-keyframed-status.test.ts
@@ -132,6 +132,25 @@ test('interpolates translate keyframes', () => {
expect(result).toBe('60px 30px');
});
+test('interpolates rotate keyframes', () => {
+ const result = interpolateKeyframedStatus({
+ frame: 30,
+ status: {
+ status: 'keyframed',
+ codeValue: undefined,
+ interpolationFunction: 'interpolateRotate',
+ keyframes: [
+ {frame: 0, value: '0deg'},
+ {frame: 60, value: '120deg'},
+ ],
+ easing: ['linear'],
+ clamping: {left: 'extend', right: 'extend'},
+ posterize: undefined,
+ },
+ });
+ expect(result).toBe('60deg');
+});
+
test('uses bezier easing', () => {
const result = interpolateKeyframedStatus({
frame: 30,
diff --git a/packages/core/src/test/interpolateRotate.test.ts b/packages/core/src/test/interpolateRotate.test.ts
new file mode 100644
index 0000000000..b87ac42339
--- /dev/null
+++ b/packages/core/src/test/interpolateRotate.test.ts
@@ -0,0 +1,65 @@
+import {describe, expect, test} from 'bun:test';
+import {Easing} from '../easing.js';
+import {interpolateRotate} from '../interpolate-rotate.js';
+import {expectToThrow} from './expect-to-throw.js';
+
+describe('interpolateRotate()', () => {
+ test('interpolates degree values', () => {
+ expect(interpolateRotate(15, [0, 30], ['0deg', '100deg'])).toBe('50deg');
+ });
+
+ test('interpolates negative and decimal degree values', () => {
+ expect(interpolateRotate(15, [0, 30], ['-10.5deg', '20.5deg'])).toBe(
+ '5deg',
+ );
+ });
+
+ test('supports multiple keyframes', () => {
+ expect(interpolateRotate(45, [0, 30, 60], ['0deg', '60deg', '0deg'])).toBe(
+ '30deg',
+ );
+ });
+
+ test('supports easing', () => {
+ expect(
+ interpolateRotate(15, [0, 30], ['0deg', '100deg'], {
+ easing: Easing.quad,
+ }),
+ ).toBe('25deg');
+ });
+
+ test('supports extrapolation', () => {
+ expect(
+ interpolateRotate(45, [0, 30], ['0deg', '100deg'], {
+ extrapolateRight: 'clamp',
+ }),
+ ).toBe('100deg');
+ });
+
+ test('supports posterization', () => {
+ expect(
+ interpolateRotate(19, [0, 30], ['0deg', '90deg'], {
+ posterize: 10,
+ }),
+ ).toBe('30deg');
+ });
+
+ test('returns the only output value for a single keyframe', () => {
+ expect(interpolateRotate(15, [0], ['10deg'])).toBe('10deg');
+ });
+
+ test('throws if output range contains non-degree units', () => {
+ expectToThrow(
+ () => interpolateRotate(15, [0, 30], ['0deg', '1turn']),
+ /only supports deg values/,
+ );
+ expectToThrow(
+ () => interpolateRotate(15, [0, 30], ['0deg', '1rad']),
+ /only supports deg values/,
+ );
+ expectToThrow(
+ () => interpolateRotate(15, [0, 30], ['0deg', '10']),
+ /only supports deg values/,
+ );
+ });
+});
diff --git a/packages/core/src/use-schema.ts b/packages/core/src/use-schema.ts
index 037d8f2dd7..360ea9588a 100644
--- a/packages/core/src/use-schema.ts
+++ b/packages/core/src/use-schema.ts
@@ -33,6 +33,7 @@ export type CanUpdateSequencePropStatusClamping = {
export type CanUpdateSequencePropStatusInterpolationFunction =
| 'interpolate'
| 'interpolateColors'
+ | 'interpolateRotate'
| 'interpolateTranslate';
export type CanUpdateSequencePropStatusComputed = {
diff --git a/packages/docs/docs/interpolate-rotate.mdx b/packages/docs/docs/interpolate-rotate.mdx
new file mode 100644
index 0000000000..e38b24c434
--- /dev/null
+++ b/packages/docs/docs/interpolate-rotate.mdx
@@ -0,0 +1,76 @@
+---
+image: /generated/articles-docs-interpolate-rotate.png
+title: interpolateRotate()
+id: interpolate-rotate
+crumb: 'API'
+---
+
+# interpolateRotate()<AvailableFrom v="4.0.472" />
+
+Allows you to map a range of values to CSS rotate values using degree units.
+
+## API
+
+Takes three to four arguments:
+
+1. The input value.
+2. The range of values that you expect the input to assume.
+3. The range of output rotate values that you want the input to map to.
+4. Options object. Optional.
+
+`inputRange` and `outputRange` must have the same length and at least one rotate value.
+With one rotate value, `interpolateRotate()` always returns the only output value.
+
+Rotate values must be `deg` values, for example `0deg`, `-45deg`, or `180.5deg`.
+
+## Returns
+
+A CSS rotate value using `deg` units.
+
+## Example
+
+```tsx twoslash
+import {interpolateRotate, useCurrentFrame} from 'remotion';
+
+const frame = useCurrentFrame();
+
+const rotate = interpolateRotate(frame, [0, 30], ['0deg', '90deg']);
+```
+
+This returns `45deg` at frame `15`.
+
+You can use the value with the CSS `rotate` property:
+
+```tsx twoslash
+import {interpolateRotate, useCurrentFrame} from 'remotion';
+
+export const MyComposition: React.FC = () => {
+ const frame = useCurrentFrame();
+ const rotate = interpolateRotate(frame, [0, 30], ['0deg', '90deg']);
+
+ return <div style={{rotate}}>Hello</div>;
+};
+```
+
+## Supported units
+
+Only `deg` values are supported.
+Other CSS angle units such as `rad`, `grad`, `turn`, or unitless values will throw an error.
+
+## Options
+
+The options are the same as [`interpolate()`](/docs/interpolate):
+
+- [`extrapolateLeft`](/docs/interpolate#extrapolateleft)
+- [`extrapolateRight`](/docs/interpolate#extrapolateright)
+- [`easing`](/docs/interpolate#easing)
+- [`posterize`](/docs/interpolate#posterize)
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/interpolate-rotate.ts)
+- [interpolate()](/docs/interpolate)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 7b4ae27383..027c8e622b 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -160,6 +160,7 @@ const sidebars: SidebarsConfig = {
'iframe',
'img',
'interpolate-colors',
+ 'interpolate-rotate',
'interpolate-translate',
'interpolate',
'loop',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 26c4422c9a..0f0b7e77e6 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -2546,6 +2546,15 @@ export const articles = [
noAi: false,
slug: 'interpolate-colors',
},
+ {
+ id: 'interpolate-rotate',
+ title: 'interpolateRotate()',
+ relativePath: 'docs/interpolate-rotate.mdx',
+ compId: 'articles-docs-interpolate-rotate',
+ crumb: 'API',
+ noAi: false,
+ slug: 'interpolate-rotate',
+ },
{
id: 'interpolate-translate',
title: 'interpolateTranslate()',
diff --git a/packages/docs/static/generated/articles-docs-interpolate-rotate.png b/packages/docs/static/generated/articles-docs-interpolate-rotate.png
new file mode 100644
index 0000000000..8065ed8fa6
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-interpolate-rotate.png differ
diff --git a/packages/studio-server/src/codemods/paste-effects.ts b/packages/studio-server/src/codemods/paste-effects.ts
index 37ce6e5ef2..1a97092034 100644
--- a/packages/studio-server/src/codemods/paste-effects.ts
+++ b/packages/studio-server/src/codemods/paste-effects.ts
@@ -35,6 +35,8 @@ type RemotionImportName =
| 'Easing'
| 'interpolate'
| 'interpolateColors'
+ | 'interpolateRotate'
+ | 'interpolateTranslate'
| 'useCurrentFrame';
type RemotionLocalNames = Partial<Record<RemotionImportName, string>>;
@@ -71,7 +73,7 @@ const keyframedParamNeedsEasingImport = (
param: EffectClipboardKeyframedParam,
) => {
return (
- param.interpolationFunction === 'interpolate' &&
+ param.interpolationFunction !== 'interpolateColors' &&
param.easing.some(isNonLinearEasing)
);
};
@@ -147,7 +149,7 @@ const makeKeyframedOptions = ({
}): ObjectExpression | null => {
const properties: ObjectProperty[] = [];
- if (param.interpolationFunction === 'interpolate') {
+ if (param.interpolationFunction !== 'interpolateColors') {
if (param.clamping.left !== 'extend') {
properties.push(
b.objectProperty(
diff --git a/packages/studio-server/src/test/compute-sequence-props-status.test.ts b/packages/studio-server/src/test/compute-sequence-props-status.test.ts
index 47c4c01cc7..283ed71a1c 100644
--- a/packages/studio-server/src/test/compute-sequence-props-status.test.ts
+++ b/packages/studio-server/src/test/compute-sequence-props-status.test.ts
@@ -129,6 +129,41 @@ export const Example: React.FC = () => {
});
});
+test('computeSequencePropsStatus should return keyframes for interpolated rotate props', () => {
+ const input = `import React from 'react';
+import {Sequence, interpolateRotate, useCurrentFrame} from 'remotion';
+
+export const Example: React.FC = () => {
+\tconst frame = useCurrentFrame();
+\treturn (
+\t\t<Sequence style={{rotate: interpolateRotate(frame, [55, 68], ['19deg', '23deg'])}} />
+\t);
+};
+`;
+ const result = computeSequencePropsStatusFromContent({
+ fileContents: input,
+ nodePath: getNodePathFromContent(input, 7),
+ keys: ['style.rotate'],
+ effects: [],
+ });
+
+ expect(result.canUpdate).toBe(true);
+ if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
+
+ expect(result.props['style.rotate']).toEqual({
+ status: 'keyframed',
+ codeValue: undefined,
+ interpolationFunction: 'interpolateRotate',
+ keyframes: [
+ {frame: 55, value: '19deg'},
+ {frame: 68, value: '23deg'},
+ ],
+ easing: ['linear'],
+ clamping: {left: 'extend', right: 'extend'},
+ posterize: undefined,
+ });
+});
+
test('computeSequencePropsStatus should explain why outside-project file reads were blocked', () => {
const remotionRoot = path.join(__dirname, 'snapshots');
const fileName = '../outside.tsx';
diff --git a/packages/studio-server/src/test/paste-effects.test.ts b/packages/studio-server/src/test/paste-effects.test.ts
index fc600c5a9c..1e26b1f339 100644
--- a/packages/studio-server/src/test/paste-effects.test.ts
+++ b/packages/studio-server/src/test/paste-effects.test.ts
@@ -298,3 +298,39 @@ test('pasteEffects replaces existing effects with mixed static and keyframed par
expect(output).toContain('amount: 0.7');
expect(output).not.toMatch(/color: ['"]blue['"]/);
});
+
+test('pasteEffects supports interpolateRotate keyframed params', async () => {
+ const input = buildInput(`<>
+ <HtmlInCanvas effects={[tint({color: "blue"})]} />
+ </>`);
+ const target = makeNodePath(input, 9);
+
+ const {output} = await pasteEffects({
+ input,
+ targetFileName: 'Comp.tsx',
+ targetSequenceNodePath: target.nodePath,
+ type: 'effects-replacing',
+ effects: [
+ {
+ callee: 'tint',
+ importPath: '@remotion/effects/tint',
+ params: {
+ angle: {
+ type: 'keyframed',
+ interpolationFunction: 'interpolateRotate',
+ keyframes: [
+ {frame: 0, value: '0deg'},
+ {frame: 100, value: '90deg'},
+ ],
+ easing: ['linear'],
+ clamping: {left: 'extend', right: 'extend'},
+ },
+ },
+ },
+ ],
+ });
+
+ expect(output).toContain(
+ "angle: interpolateRotate(frame, [0, 100], ['0deg', '90deg'])",
+ );
+});
diff --git a/packages/studio-server/src/test/update-keyframes-imports.test.ts b/packages/studio-server/src/test/update-keyframes-imports.test.ts
index dd698df65f..6985d7eb74 100644
--- a/packages/studio-server/src/test/update-keyframes-imports.test.ts
+++ b/packages/studio-server/src/test/update-keyframes-imports.test.ts
@@ -24,6 +24,13 @@ const translateSchema = {
},
} satisfies SequenceSchema;
+const rotateSchema = {
+ 'style.rotate': {
+ type: 'rotation-css',
+ default: '0deg',
+ },
+} satisfies SequenceSchema;
+
// ---------------------------------------------------------------------------
// Sequence: imports
// ---------------------------------------------------------------------------
@@ -103,6 +110,32 @@ export const Example: React.FC = () => {
expect(serialized).toContain('const frame = useCurrentFrame();');
});
+test('adds interpolateRotate import for rotate conversion', () => {
+ const input = `import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+export const Example: React.FC = () => {
+\treturn <AbsoluteFill style={{rotate: '0deg'}} />;
+};
+`;
+ const {serialized} = updateSequenceKeyframesAst({
+ input,
+ nodePath: lineColumnToNodePath(input, getLine(input, '<AbsoluteFill')),
+ schema: rotateSchema,
+ updates: [
+ {
+ key: 'style.rotate',
+ operation: {type: 'add', frame: 44, value: '19deg'},
+ },
+ ],
+ });
+
+ expect(serialized).toContain('interpolateRotate');
+ expect(serialized).not.toContain('interpolateColors');
+ expect(serialized).toContain('useCurrentFrame');
+ expect(serialized).toContain('const frame = useCurrentFrame();');
+});
+
test('creates a new remotion import when one is missing entirely', () => {
const input = `import React from 'react';
diff --git a/packages/studio-server/src/test/update-keyframes.test.ts b/packages/studio-server/src/test/update-keyframes.test.ts
index df4c76e1ee..ab6f705f0a 100644
--- a/packages/studio-server/src/test/update-keyframes.test.ts
+++ b/packages/studio-server/src/test/update-keyframes.test.ts
@@ -39,6 +39,13 @@ const translateSchema = {
},
} satisfies SequenceSchema;
+const rotateSchema = {
+ 'style.rotate': {
+ type: 'rotation-css',
+ default: '0deg',
+ },
+} satisfies SequenceSchema;
+
const translateInput = `import React from 'react';
import {AbsoluteFill} from 'remotion';
@@ -51,6 +58,18 @@ export const Example: React.FC = () => {
};
`;
+const rotateInput = `import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+export const Example: React.FC = () => {
+\treturn (
+\t\t<AbsoluteFill>
+\t\t\t<div style={{rotate: '19deg'}} />
+\t\t</AbsoluteFill>
+\t);
+};
+`;
+
const effectInput = `import {tint} from '@remotion/effects/tint';
import {HtmlInCanvas} from '@remotion/html-in-canvas';
import {interpolate, useCurrentFrame} from 'remotion';
@@ -259,6 +278,55 @@ test('updateSequenceKeyframes migrates translate away from interpolateColors', a
expect(output).toContain("['0px 59px', '100px 20px']");
});
+test('updateSequenceKeyframes converts static rotate to interpolateRotate', async () => {
+ const {output, oldValueStrings} = await updateSequenceKeyframes({
+ input: rotateInput,
+ nodePath: lineColumnToNodePath(rotateInput, getLine(rotateInput, 'rotate')),
+ schema: rotateSchema,
+ updates: [
+ {
+ key: 'style.rotate',
+ operation: {type: 'add', frame: 55, value: '19deg'},
+ },
+ ],
+ });
+
+ expect(oldValueStrings).toEqual(["'19deg'"]);
+ expect(output).toContain("rotate: interpolateRotate(frame, [55], ['19deg'])");
+ expect(output).toContain('interpolateRotate');
+});
+
+test('updateSequenceKeyframes migrates rotate away from interpolateColors', async () => {
+ const input = rotateInput
+ .replace(
+ "import {AbsoluteFill} from 'remotion';",
+ "import {AbsoluteFill, interpolateColors, useCurrentFrame} from 'remotion';",
+ )
+ .replace('return (', 'const frame = useCurrentFrame();\n\treturn (')
+ .replace(
+ "rotate: '19deg'",
+ "rotate: interpolateColors(frame, [55], ['19deg'])",
+ );
+ const {output, oldValueStrings} = await updateSequenceKeyframes({
+ input,
+ nodePath: lineColumnToNodePath(input, getLine(input, 'rotate')),
+ schema: rotateSchema,
+ updates: [
+ {
+ key: 'style.rotate',
+ operation: {type: 'add', frame: 68, value: '23deg'},
+ },
+ ],
+ });
+
+ expect(oldValueStrings).toEqual([
+ "interpolateColors(frame, [55], ['19deg'])",
+ ]);
+ expect(output).toContain('rotate: interpolateRotate(');
+ expect(output).toContain('[55, 68]');
+ expect(output).toContain("['19deg', '23deg']");
+});
+
test('updateSequenceKeyframes returns a node path that still resolves after inserting a frame hook', async () => {
const input = `import {starburst} from '@remotion/starburst';
import React from 'react';
diff --git a/packages/studio-shared/src/effect-clipboard-data.ts b/packages/studio-shared/src/effect-clipboard-data.ts
index f5b2455981..d5538a3e8d 100644
--- a/packages/studio-shared/src/effect-clipboard-data.ts
+++ b/packages/studio-shared/src/effect-clipboard-data.ts
@@ -1,3 +1,8 @@
+import {
+ isKeyframeInterpolationFunction,
+ type KeyframeInterpolationFunction,
+} from './keyframe-interpolation-function';
+
export type EffectClipboardPasteType = 'effects-additive' | 'effects-replacing';
export type EffectClipboardStaticParam = {
@@ -6,8 +11,7 @@ export type EffectClipboardStaticParam = {
};
export type EffectClipboardInterpolationFunction =
- | 'interpolate'
- | 'interpolateColors';
+ KeyframeInterpolationFunction;
export type EffectClipboardKeyframe = {
readonly frame: number;
@@ -120,8 +124,8 @@ const isEffectClipboardParam = (
? value.keyframes.length - 1
: null;
return (
- (value.interpolationFunction === 'interpolate' ||
- value.interpolationFunction === 'interpolateColors') &&
+ typeof value.interpolationFunction === 'string' &&
+ isKeyframeInterpolationFunction(value.interpolationFunction) &&
Array.isArray(value.keyframes) &&
value.keyframes.length > 0 &&
value.keyframes.every(isKeyframe) &&
diff --git a/packages/studio-shared/src/keyframe-interpolation-function.ts b/packages/studio-shared/src/keyframe-interpolation-function.ts
index b2250420b4..2765e4675c 100644
--- a/packages/studio-shared/src/keyframe-interpolation-function.ts
+++ b/packages/studio-shared/src/keyframe-interpolation-function.ts
@@ -3,6 +3,7 @@ import type {SequenceFieldSchema, SequenceSchema} from 'remotion';
export const keyframeInterpolationFunctions = [
'interpolate',
'interpolateColors',
+ 'interpolateRotate',
'interpolateTranslate',
] as const;
@@ -65,6 +66,10 @@ export const getKeyframeInterpolationFunctionForSchemaField = ({
return 'interpolateTranslate';
}
+ if (field?.type === 'rotation-css') {
+ return 'interpolateRotate';
+ }
+
if (field?.type === 'color') {
return 'interpolateColors';
}
diff --git a/packages/studio-shared/src/test/effect-clipboard-data.test.ts b/packages/studio-shared/src/test/effect-clipboard-data.test.ts
index e0e6f275a3..6b3dacb5de 100644
--- a/packages/studio-shared/src/test/effect-clipboard-data.test.ts
+++ b/packages/studio-shared/src/test/effect-clipboard-data.test.ts
@@ -56,6 +56,45 @@ test('parseEffectClipboardData accepts keyframed v3 effect payloads', () => {
});
});
+test('parseEffectClipboardData accepts rotate interpolation functions', () => {
+ const parsed = parseEffectClipboardData(
+ JSON.stringify({
+ type: 'effects-additive',
+ version: 3,
+ remotionClipboard: 'effects',
+ effects: [
+ {
+ callee: 'customEffect',
+ importPath: '@remotion/effects/custom-effect',
+ params: {
+ angle: {
+ type: 'keyframed',
+ interpolationFunction: 'interpolateRotate',
+ keyframes: [
+ {frame: 0, value: '0deg'},
+ {frame: 100, value: '90deg'},
+ ],
+ easing: ['linear'],
+ clamping: {left: 'extend', right: 'extend'},
+ },
+ },
+ },
+ ],
+ }),
+ );
+
+ expect(parsed?.effects[0]?.params.angle).toEqual({
+ type: 'keyframed',
+ interpolationFunction: 'interpolateRotate',
+ keyframes: [
+ {frame: 0, value: '0deg'},
+ {frame: 100, value: '90deg'},
+ ],
+ easing: ['linear'],
+ clamping: {left: 'extend', right: 'extend'},
+ });
+});
+
test('parseEffectClipboardData reports old v2 effect payloads as unsupported', () => {
const payload = JSON.stringify({
type: 'effects-replacing',
diff --git a/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts b/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts
index e391a39fea..407f8ba48f 100644
--- a/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts
+++ b/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts
@@ -76,6 +76,45 @@ test('optimisticAddSequenceKeyframe uses interpolateTranslate for translate fiel
expect(status.keyframes).toEqual([{frame: 44, value: '0px 59px'}]);
});
+test('optimisticAddSequenceKeyframe uses interpolateRotate for rotation-css fields', () => {
+ const previous: CanUpdateSequencePropsResponse = {
+ canUpdate: true,
+ props: {
+ 'style.rotate': {
+ status: 'static',
+ codeValue: '0deg',
+ },
+ },
+ effects: [],
+ };
+ const schema = {
+ 'style.rotate': {
+ type: 'rotation-css',
+ default: '0deg',
+ },
+ } satisfies SequenceSchema;
+
+ const updated = optimisticAddSequenceKeyframe({
+ previous,
+ fieldKey: 'style.rotate',
+ frame: 44,
+ value: '19deg',
+ schema,
+ });
+
+ if (!updated.canUpdate) {
+ throw new Error('expected updateable sequence');
+ }
+
+ const status = updated.props['style.rotate'];
+ if (!status || status.status !== 'keyframed') {
+ throw new Error('expected keyframed status');
+ }
+
+ expect(status.interpolationFunction).toBe('interpolateRotate');
+ expect(status.keyframes).toEqual([{frame: 44, value: '19deg'}]);
+});
+
test('optimisticAddSequenceKeyframe ignores non-keyframable fields', () => {
const previous: CanUpdateSequencePropsResponse = {
canUpdate: true,
diff --git a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
index a5423b87fb..8c90a2eccd 100644
--- a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
+++ b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
@@ -1,4 +1,5 @@
import {
+ isKeyframeInterpolationFunction,
parseEffectClipboardDataResult,
type EffectClipboardData,
type EffectClipboardInterpolationFunction,
@@ -123,7 +124,7 @@ type CopyableEffectStatus = React.ContextType<
const isClipboardInterpolationFunction = (
value: string,
): value is EffectClipboardInterpolationFunction => {
- return value === 'interpolate' || value === 'interpolateColors';
+ return isKeyframeInterpolationFunction(value);
};
const effectStatusToSnapshot = (