🎥 Make videos programmatically with React
`@remotion/studio`: Add spring easing inspector mode (#8483)
Jonny Burger0083d0338b36
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.tsindex d128d0f769..0eb4125f84 100644--- a/packages/core/src/internals.ts+++ b/packages/core/src/internals.ts@@ -197,6 +197,7 @@ import {import {PixelDensityContext} from './use-pixel-density.js';import type {CanUpdateSequencePropStatusFalse,+ CanUpdateSequencePropStatusEasing,CanUpdateSequencePropStatusKeyframed,CanUpdateSequencePropStatusStatic,DragOverrideValue,@@ -424,6 +425,7 @@ export type {CanUpdateSequencePropsResponseFalse,CanUpdateSequencePropsResponseTrue,CanUpdateSequencePropStatus,+ CanUpdateSequencePropStatusEasing,CanUpdateSequencePropStatusFalse,CanUpdateSequencePropStatusKeyframed,CanUpdateSequencePropStatusStatic,diff --git a/packages/core/src/interpolate-keyframed-status.ts b/packages/core/src/interpolate-keyframed-status.tsindex abcd91e1fc..06accf28c4 100644--- a/packages/core/src/interpolate-keyframed-status.ts+++ b/packages/core/src/interpolate-keyframed-status.ts@@ -15,11 +15,23 @@ type InterpolateKeyframedStatusResult =| null;const easingToFn = (e: CanUpdateSequencePropStatusEasing): EasingFunction => {- if (e === 'linear') {- return Easing.linear;+ switch (e.type) {+ case 'linear':+ return Easing.linear;+ case 'spring':+ return Easing.spring({+ damping: e.damping,+ mass: e.mass,+ overshootClamping: e.overshootClamping,+ stiffness: e.stiffness,+ });+ case 'bezier':+ return bezier(e.x1, e.y1, e.x2, e.y2);+ default:+ throw new TypeError(+ `Unsupported easing: ${JSON.stringify(e satisfies never)}`,+ );}-- return bezier(e[0], e[1], e[2], e[3]);};export const interpolateKeyframedStatus = ({diff --git a/packages/core/src/test/drag-override-value.test.ts b/packages/core/src/test/drag-override-value.test.tsindex aaaf1413b9..0685e64b00 100644--- a/packages/core/src/test/drag-override-value.test.ts+++ b/packages/core/src/test/drag-override-value.test.ts@@ -16,7 +16,7 @@ const makeKeyframedStatus = (): CanUpdateSequencePropStatusKeyframed => ({{frame: 0, value: 2},{frame: 60, value: 4},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,});@@ -37,7 +37,7 @@ test('makeKeyframedDragOverride inserts a new keyframe and preserves easing leng{frame: 30, value: 3},{frame: 60, value: 4},],- easing: ['linear', 'linear'],+ easing: [{type: 'linear'}, {type: 'linear'}],},});@@ -64,7 +64,7 @@ test('makeKeyframedDragOverride replaces an existing keyframe without changing e{frame: 0, value: 2},{frame: 60, value: 5},],- easing: ['linear'],+ easing: [{type: 'linear'}],},});});diff --git a/packages/core/src/test/interpolate-keyframed-status.test.ts b/packages/core/src/test/interpolate-keyframed-status.test.tsindex 8631e1776a..bb3f6c7820 100644--- a/packages/core/src/test/interpolate-keyframed-status.test.ts+++ b/packages/core/src/test/interpolate-keyframed-status.test.ts@@ -11,7 +11,7 @@ test('interpolates linear numeric keyframes', () => {{frame: 0, value: 0},{frame: 60, value: 100},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -29,7 +29,7 @@ test('interpolates linear tuple keyframes', () => {{frame: 0, value: [0, 0.5]},{frame: 60, value: [1, 0.5]},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -48,7 +48,7 @@ test('sorts keyframes before interpolating numeric values', () => {{frame: 50, value: 50},{frame: 0, value: 0},],- easing: ['linear', 'linear'],+ easing: [{type: 'linear'}, {type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -66,7 +66,7 @@ test('clamps when extrapolation is clamp', () => {{frame: 0, value: 0},{frame: 60, value: 100},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},posterize: undefined,},@@ -84,7 +84,7 @@ test('posterizes the frame before interpolating numeric keyframes', () => {{frame: 0, value: 0},{frame: 60, value: 100},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: 3,},@@ -117,7 +117,7 @@ test('interpolates colors', () => {{frame: 0, value: '#000000'},{frame: 60, value: '#ffffff'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},posterize: undefined,},@@ -136,7 +136,7 @@ test('interpolates color keyframes with easing', () => {{frame: 0, value: 'black'},{frame: 60, value: 'white'},],- easing: [[0.42, 0, 1, 1]],+ easing: [{type: 'bezier', x1: 0.42, y1: 0, x2: 1, y2: 1}],clamping: {left: 'clamp', right: 'clamp'},posterize: undefined,},@@ -154,7 +154,7 @@ test('posterizes the frame before interpolating color keyframes', () => {{frame: 0, value: 'black'},{frame: 60, value: 'white'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},posterize: 3,},@@ -172,7 +172,7 @@ test('interpolates translate keyframes', () => {{frame: 0, value: '0px 0px'},{frame: 60, value: '120px 60px'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -190,7 +190,7 @@ test('interpolates rotate keyframes', () => {{frame: 0, value: '0deg'},{frame: 60, value: '120deg'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -208,7 +208,7 @@ test('uses bezier easing', () => {{frame: 0, value: 0},{frame: 60, value: 100},],- easing: [[0.42, 0, 0.58, 1]],+ easing: [{type: 'bezier', x1: 0.42, y1: 0, x2: 0.58, y2: 1}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -227,7 +227,7 @@ test('interpolates scale strings component-wise', () => {{frame: 0, value: 2},{frame: 60, value: '4 8 3'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},diff --git a/packages/core/src/use-schema.ts b/packages/core/src/use-schema.tsindex 1129607f37..ed792c8247 100644--- a/packages/core/src/use-schema.ts+++ b/packages/core/src/use-schema.ts@@ -24,9 +24,34 @@ export type CanUpdateSequencePropStatusKeyframe = {value: unknown;};+export type CanUpdateSequencePropStatusLinearEasing = {+ type: 'linear';+};++export type CanUpdateSequencePropStatusBezierEasing = {+ type: 'bezier';+ x1: number;+ y1: number;+ x2: number;+ y2: number;+};++export type CanUpdateSequencePropStatusSpringEasing = {+ type: 'spring';+ damping: number;+ mass: number;+ stiffness: number;+ overshootClamping: boolean;+};+export type CanUpdateSequencePropStatusEasing =- | 'linear'- | [number, number, number, number];+ | CanUpdateSequencePropStatusLinearEasing+ | CanUpdateSequencePropStatusBezierEasing+ | CanUpdateSequencePropStatusSpringEasing;++export const DEFAULT_LINEAR_EASING: CanUpdateSequencePropStatusLinearEasing = {+ type: 'linear',+};export type CanUpdateSequencePropStatusClamping = {left: ExtrapolateType;@@ -119,7 +144,7 @@ export const makeKeyframedDragOverride = ({);const easing = [...status.easing];while (easing.length < keyframes.length - 1) {- easing.push('linear');+ easing.push(DEFAULT_LINEAR_EASING);}if (easing.length > keyframes.length - 1) {diff --git a/packages/studio-server/src/codemods/effect-param-expression.ts b/packages/studio-server/src/codemods/effect-param-expression.tsindex 9e32c74357..fba522676f 100644--- a/packages/studio-server/src/codemods/effect-param-expression.ts+++ b/packages/studio-server/src/codemods/effect-param-expression.ts@@ -21,7 +21,7 @@ export type RemotionLocalNames = Partial<Record<RemotionImportName, string>>;const isNonLinearEasing = (easing: EffectClipboardKeyframedParam['easing'][number],-) => easing !== 'linear';+) => easing.type !== 'linear';const keyframedParamNeedsEasingImport = (param: EffectClipboardKeyframedParam,@@ -82,17 +82,54 @@ const makeEasingExpression = ({easing: EffectClipboardKeyframedParam['easing'][number];easingLocalName: string;}): ExpressionKind => {- if (easing === 'linear') {- return b.memberExpression(- b.identifier(easingLocalName),- b.identifier('linear'),- ) as ExpressionKind;+ switch (easing.type) {+ case 'linear':+ return b.memberExpression(+ b.identifier(easingLocalName),+ b.identifier('linear'),+ ) as ExpressionKind;+ case 'spring':+ return b.callExpression(+ b.memberExpression(+ b.identifier(easingLocalName),+ b.identifier('spring'),+ ),+ [+ b.objectExpression([+ b.objectProperty(+ b.identifier('damping'),+ parseValueExpression(easing.damping),+ ),+ b.objectProperty(+ b.identifier('mass'),+ parseValueExpression(easing.mass),+ ),+ b.objectProperty(+ b.identifier('stiffness'),+ parseValueExpression(easing.stiffness),+ ),+ b.objectProperty(+ b.identifier('overshootClamping'),+ b.booleanLiteral(easing.overshootClamping),+ ),+ ]),+ ] as never,+ ) as ExpressionKind;+ case 'bezier':+ return b.callExpression(+ b.memberExpression(+ b.identifier(easingLocalName),+ b.identifier('bezier'),+ ),+ [easing.x1, easing.y1, easing.x2, easing.y2].map((value) =>+ parseValueExpression(value),+ ) as never,+ ) as ExpressionKind;+ default:+ throw new Error(+ `Unsupported easing: ${JSON.stringify(easing satisfies never)}`,+ );}-- return b.callExpression(- b.memberExpression(b.identifier(easingLocalName), b.identifier('bezier')),- easing.map((value) => parseValueExpression(value)) as never,- ) as ExpressionKind;};const makeKeyframedOptions = ({diff --git a/packages/studio-server/src/codemods/update-keyframes/update-keyframes.ts b/packages/studio-server/src/codemods/update-keyframes/update-keyframes.tsindex 4a05759000..511f5557c4 100644--- a/packages/studio-server/src/codemods/update-keyframes/update-keyframes.ts+++ b/packages/studio-server/src/codemods/update-keyframes/update-keyframes.ts@@ -15,6 +15,8 @@ import {getKeyframeInterpolationFunctionForSchemaField,isKeyframeInterpolationFunction,isSchemaFieldKeyframable,+ LINEAR_KEYFRAME_EASING,+ parseSpringEasingConfig,type KeyframeInterpolationFunction,} from '@remotion/studio-shared';import type {ExpressionKind, SpreadElementKind} from 'ast-types/lib/gen/kinds';@@ -398,7 +400,7 @@ const setOptionsProperty = ({);};-const isLinearEasing = (easing: KeyframeEasing) => easing === 'linear';+const isLinearEasing = (easing: KeyframeEasing) => easing.type === 'linear';const getKeyframeEasing = (node: Expression): KeyframeEasing | null => {if (node.type === 'TSAsExpression') {@@ -413,7 +415,7 @@ const getKeyframeEasing = (node: Expression): KeyframeEasing | null => {node.property.name === 'linear' &&node.computed === false) {- return 'linear';+ return {type: 'linear'};}if (@@ -422,13 +424,32 @@ const getKeyframeEasing = (node: Expression): KeyframeEasing | null => {node.callee.object.type !== 'Identifier' ||node.callee.object.name !== 'Easing' ||node.callee.property.type !== 'Identifier' ||- node.callee.property.name !== 'bezier' ||- node.callee.computed ||- node.arguments.length !== 4+ node.callee.computed) {return null;}+ if (node.callee.property.name === 'spring') {+ if (node.arguments.length > 1) {+ return null;+ }++ const springConfig = node.arguments[0];+ if (+ springConfig?.type === 'ArgumentPlaceholder' ||+ springConfig?.type === 'JSXNamespacedName' ||+ springConfig?.type === 'SpreadElement'+ ) {+ return null;+ }++ return parseSpringEasingConfig(springConfig);+ }++ if (node.callee.property.name !== 'bezier' || node.arguments.length !== 4) {+ return null;+ }+const values = node.arguments.map((arg) => {if (arg.type === 'ArgumentPlaceholder' ||@@ -445,7 +466,8 @@ const getKeyframeEasing = (node: Expression): KeyframeEasing | null => {return null;}- return values as [number, number, number, number];+ const [x1, y1, x2, y2] = values as [number, number, number, number];+ return {type: 'bezier', x1, y1, x2, y2};};const getKeyframeEasingArray = ({@@ -485,7 +507,7 @@ const getKeyframeEasingArray = ({const easingArray = parsed as KeyframeEasing[];while (easingArray.length < segmentCount) {- easingArray.push('linear');+ easingArray.push(LINEAR_KEYFRAME_EASING);}return easingArray;@@ -508,7 +530,7 @@ const getExistingEasingArray = ({}): KeyframeEasing[] => {const {prop} = findObjectOptionProperty(options, 'easing');if (!prop) {- return new Array(segmentCount).fill('linear');+ return Array.from({length: segmentCount}, () => ({type: 'linear'}));}const easing = getKeyframeEasingArray({@@ -538,17 +560,48 @@ const getExistingEasingArrayOrNull = ({};const createEasingExpression = (easing: KeyframeEasing): ExpressionKind => {- if (easing === 'linear') {- return b.memberExpression(- b.identifier('Easing'),- b.identifier('linear'),- ) as ExpressionKind;+ switch (easing.type) {+ case 'linear':+ return b.memberExpression(+ b.identifier('Easing'),+ b.identifier('linear'),+ ) as ExpressionKind;+ case 'spring':+ return b.callExpression(+ b.memberExpression(b.identifier('Easing'), b.identifier('spring')),+ [+ b.objectExpression([+ b.objectProperty(+ b.identifier('damping'),+ parseValueExpression(easing.damping),+ ),+ b.objectProperty(+ b.identifier('mass'),+ parseValueExpression(easing.mass),+ ),+ b.objectProperty(+ b.identifier('stiffness'),+ parseValueExpression(easing.stiffness),+ ),+ b.objectProperty(+ b.identifier('overshootClamping'),+ b.booleanLiteral(easing.overshootClamping),+ ),+ ]),+ ] as never,+ ) as ExpressionKind;+ case 'bezier':+ return b.callExpression(+ b.memberExpression(b.identifier('Easing'), b.identifier('bezier')),+ [easing.x1, easing.y1, easing.x2, easing.y2].map((value) =>+ parseValueExpression(value),+ ) as never,+ ) as ExpressionKind;+ default:+ throw new Error(+ `Unsupported easing: ${JSON.stringify(easing satisfies never)}`,+ );}-- return b.callExpression(- b.memberExpression(b.identifier('Easing'), b.identifier('bezier')),- easing.map((value) => parseValueExpression(value)) as never,- ) as ExpressionKind;};const createEasingArrayExpression = (@@ -625,7 +678,7 @@ const normalizeEasingAfterAddingKeyframe = ({}while (easing.length < nextSegmentCount) {- easing.push('linear');+ easing.push(LINEAR_KEYFRAME_EASING);}return {@@ -672,7 +725,7 @@ const normalizeEasingAfterRemovingKeyframe = ({}while (easing.length < nextSegmentCount) {- easing.push('linear');+ easing.push(LINEAR_KEYFRAME_EASING);}return {@@ -725,7 +778,7 @@ const normalizeEasingAfterRemovingKeyframes = ({}while (easing.length < nextSegmentCount) {- easing.push('linear');+ easing.push(LINEAR_KEYFRAME_EASING);}return {diff --git a/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts b/packages/studio-server/src/preview-server/routes/can-update-sequence-props.tsindex bb5b2565a2..095d8d84ae 100644--- a/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts+++ b/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts@@ -13,7 +13,11 @@ import type {} from '@babel/types';import {RenderInternals} from '@remotion/renderer';import type {SubscribeToSequencePropsResponse} from '@remotion/studio-shared';-import {isKeyframeInterpolationFunction} from '@remotion/studio-shared';+import {+ isKeyframeInterpolationFunction,+ LINEAR_KEYFRAME_EASING,+ parseSpringEasingConfig,+} from '@remotion/studio-shared';import * as recast from 'recast';import type {CanUpdateSequencePropsResponseTrue,@@ -277,7 +281,7 @@ const getKeyframeEasing = (node: Expression): PropEasing[number] | null => {node.property.name === 'linear' &&node.computed === false) {- return 'linear';+ return {type: 'linear'};}if (@@ -286,13 +290,29 @@ const getKeyframeEasing = (node: Expression): PropEasing[number] | null => {node.callee.object.type !== 'Identifier' ||node.callee.object.name !== 'Easing' ||node.callee.property.type !== 'Identifier' ||- node.callee.property.name !== 'bezier' ||node.callee.computed) {return null;}- if (node.arguments.length !== 4) {+ if (node.callee.property.name === 'spring') {+ if (node.arguments.length > 1) {+ return null;+ }++ const springConfig = node.arguments[0];+ if (+ springConfig?.type === 'ArgumentPlaceholder' ||+ springConfig?.type === 'JSXNamespacedName' ||+ springConfig?.type === 'SpreadElement'+ ) {+ return null;+ }++ return parseSpringEasingConfig(springConfig);+ }++ if (node.callee.property.name !== 'bezier' || node.arguments.length !== 4) {return null;}@@ -312,7 +332,8 @@ const getKeyframeEasing = (node: Expression): PropEasing[number] | null => {return null;}- return values as [number, number, number, number];+ const [x1, y1, x2, y2] = values as [number, number, number, number];+ return {type: 'bezier', x1, y1, x2, y2};};const getKeyframeEasingArray = ({@@ -382,7 +403,7 @@ const getInterpolationMetadata = (right: 'extend',};const defaults = {- easing: new Array(segments).fill('linear') as PropEasing,+ easing: Array.from({length: segments}, () => LINEAR_KEYFRAME_EASING),clamping: defaultClamping,posterize: undefined,};diff --git a/packages/studio-server/src/test/compute-effect-props-status.test.ts b/packages/studio-server/src/test/compute-effect-props-status.test.tsindex 7e071da188..37bdd5e933 100644--- a/packages/studio-server/src/test/compute-effect-props-status.test.ts+++ b/packages/studio-server/src/test/compute-effect-props-status.test.ts@@ -114,7 +114,7 @@ test('computeEffectPropStatus reports keyframes for inline interpolated effect p{frame: 0, value: 0.2},{frame: 100, value: 0.8},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,});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.tsindex 92b8fd28ae..f6a95b1178 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@@ -90,7 +90,7 @@ export const Example: React.FC = () => {{frame: 0, value: 'red'},{frame: 100, value: 'blue'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},posterize: undefined,});@@ -178,12 +178,55 @@ export const Example: React.FC = () => {{frame: 100, value: 'green'},{frame: 200, value: 'blue'},],- easing: [[0.42, 0, 1, 1], 'linear'],+ easing: [{type: 'bezier', x1: 0.42, y1: 0, x2: 1, y2: 1}, {type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},posterize: 2,});});+test('computeSequencePropsStatus should return spring easing metadata', () => {+ const input = `import React from 'react';+import {Easing, Sequence, interpolate, useCurrentFrame} from 'remotion';++export const Example: React.FC = () => {+\tconst frame = useCurrentFrame();+\treturn (+\t\t<Sequence style={{opacity: interpolate(frame, [0, 100], [0, 1], {easing: Easing.spring({damping: 12, mass: 1.5, stiffness: 180, overshootClamping: true})})}} />+\t);+};+`;+ const result = computeSequencePropsStatusFromContent({+ fileContents: input,+ nodePath: getNodePathFromContent(input, 7),+ componentIdentity: null,+ keys: ['style.opacity'],+ effects: [],+ });++ expect(result.canUpdate).toBe(true);+ if (!result.canUpdate) throw new Error('Expected canUpdate to be true');++ expect(result.props['style.opacity']).toEqual({+ status: 'keyframed',+ interpolationFunction: 'interpolate',+ keyframes: [+ {frame: 0, value: 0},+ {frame: 100, value: 1},+ ],+ easing: [+ {+ type: 'spring',+ damping: 12,+ mass: 1.5,+ stiffness: 180,+ overshootClamping: true,+ },+ ],+ clamping: {left: 'extend', right: 'extend'},+ posterize: undefined,+ });+});+test('computeSequencePropsStatus should return keyframes for interpolated translate props', () => {const input = `import React from 'react';import {Sequence, interpolate, useCurrentFrame} from 'remotion';@@ -213,7 +256,7 @@ export const Example: React.FC = () => {{frame: 0, value: '0px 59px'},{frame: 100, value: '100px 20px'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,});@@ -257,8 +300,8 @@ export const Example: React.FC = () => {{frame: 30, value: '124px 40px'},],easing: [- [0, 0, 0.58, 1],- [0.42, 0, 0.6308, 1.1405],+ {type: 'bezier', x1: 0, y1: 0, x2: 0.58, y2: 1},+ {type: 'bezier', x1: 0.42, y1: 0, x2: 0.6308, y2: 1.1405},],clamping: {left: 'clamp', right: 'clamp'},posterize: undefined,@@ -322,7 +365,7 @@ export const Example: React.FC = () => {{frame: 55, value: '19deg'},{frame: 68, value: '23deg'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,});@@ -477,7 +520,7 @@ test('computeSequencePropsStatus should return keyframes for interpolated style{frame: 0, value: 2},{frame: 100, value: 4},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,});@@ -529,8 +572,8 @@ export const Example: React.FC = () => {{frame: 30, value: '1.611 1.611'},],easing: [- [0, 0, 0.58, 1],- [0.42, 0, 0.6308, 1.1405],+ {type: 'bezier', x1: 0, y1: 0, x2: 0.58, y2: 1},+ {type: 'bezier', x1: 0.42, y1: 0, x2: 0.6308, y2: 1.1405},],clamping: {left: 'clamp', right: 'clamp'},posterize: undefined,@@ -572,7 +615,10 @@ export const Example: React.FC = () => {{frame: 50, value: 2},{frame: 100, value: 3},],- easing: [[0.1, 0.2, 0.3, 0.4], 'linear'],+ easing: [+ {type: 'bezier', x1: 0.1, y1: 0.2, x2: 0.3, y2: 0.4},+ {type: 'linear'},+ ],clamping: {left: 'clamp',right: 'identity',@@ -611,7 +657,7 @@ export const Example: React.FC = () => {{frame: 0, value: 1},{frame: 100, value: 3},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: 3,});@@ -647,7 +693,7 @@ export const Example: React.FC = () => {{frame: 0, value: 'red'},{frame: 100, value: 'blue'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},posterize: 3,});diff --git a/packages/studio-server/src/test/paste-effects.test.ts b/packages/studio-server/src/test/paste-effects.test.tsindex a574aa5469..067c312fc8 100644--- a/packages/studio-server/src/test/paste-effects.test.ts+++ b/packages/studio-server/src/test/paste-effects.test.ts@@ -193,7 +193,7 @@ export const Comp = () => {{frame: 0, value: 0},{frame: 100, value: 1},],- easing: [[0.1, 0.2, 0.3, 0.4]],+ easing: [{type: 'bezier', x1: 0.1, y1: 0.2, x2: 0.3, y2: 0.4}],clamping: {left: 'clamp', right: 'wrap'},posterize: 2,},@@ -216,6 +216,57 @@ export const Comp = () => {expect(output).toContain('posterize: 2');});+test('pasteEffects serializes spring easing for keyframed effects', async () => {+ const input = `import {HtmlInCanvas} from '@remotion/html-in-canvas';++export const Comp = () => {+ return (+ <HtmlInCanvas />+ );+};+`;+ const target = makeNodePath(input, getLine(input, '<HtmlInCanvas'));++ const {output} = await pasteEffects({+ input,+ targetFileName: 'Comp.tsx',+ targetSequenceNodePath: target.nodePath,+ type: 'effects-additive',+ effects: [+ {+ callee: 'brightness',+ importPath: '@remotion/effects/brightness',+ params: {+ amount: {+ type: 'keyframed',+ interpolationFunction: 'interpolate',+ keyframes: [+ {frame: 0, value: 0},+ {frame: 100, value: 1},+ ],+ easing: [+ {+ type: 'spring',+ damping: 12,+ mass: 1.5,+ stiffness: 180,+ overshootClamping: true,+ },+ ],+ clamping: {left: 'extend', right: 'extend'},+ },+ },+ },+ ],+ });++ expect(output).toContain('Easing.spring({');+ expect(output).toContain('damping: 12');+ expect(output).toContain('mass: 1.5');+ expect(output).toContain('stiffness: 180');+ expect(output).toContain('overshootClamping: true');+});+test('pasteEffects uses aliased Remotion imports for keyframed effects', async () => {const input = `import {HtmlInCanvas} from '@remotion/html-in-canvas';import {interpolate as i, useCurrentFrame as useFrame} from 'remotion';@@ -245,7 +296,7 @@ export const Comp = () => {{frame: 0, value: 0},{frame: 100, value: 1},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},},},@@ -280,7 +331,7 @@ test('pasteEffects replaces existing effects with mixed static and keyframed par{frame: 0, value: 'red'},{frame: 100, value: 'green'},],- easing: [[0.1, 0.2, 0.3, 0.4]],+ easing: [{type: 'bezier', x1: 0.1, y1: 0.2, x2: 0.3, y2: 0.4}],clamping: {left: 'clamp', right: 'clamp'},posterize: 5,},@@ -324,7 +375,7 @@ test('pasteEffects supports interpolated rotate keyframed params', async () => {{frame: 0, value: '0deg'},{frame: 100, value: '90deg'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},},},diff --git a/packages/studio-server/src/test/update-effect-props.test.ts b/packages/studio-server/src/test/update-effect-props.test.tsindex 16e8c2fad8..8d107ba267 100644--- a/packages/studio-server/src/test/update-effect-props.test.ts+++ b/packages/studio-server/src/test/update-effect-props.test.ts@@ -229,7 +229,7 @@ test('updateEffectProps writes keyframed effect params from clipboard data', (){frame: 0, value: 0},{frame: 30, value: 1},],- easing: [[0.1, 0.2, 0.3, 0.4]],+ easing: [{type: 'bezier', x1: 0.1, y1: 0.2, x2: 0.3, y2: 0.4}],clamping: {left: 'clamp', right: 'extend'},posterize: 2,},diff --git a/packages/studio-server/src/test/update-keyframes.test.ts b/packages/studio-server/src/test/update-keyframes.test.tsindex f22575c752..eecd25d0e3 100644--- a/packages/studio-server/src/test/update-keyframes.test.ts+++ b/packages/studio-server/src/test/update-keyframes.test.ts@@ -226,7 +226,7 @@ export const Example: React.FC = () => {operation: {type: 'easing',segmentIndex: 1,- easing: [0.42, 0, 1, 1],+ easing: {type: 'bezier', x1: 0.42, y1: 0, x2: 1, y2: 1},},},],@@ -238,6 +238,49 @@ export const Example: React.FC = () => {);});+test('updateSequenceKeyframes sets a spring easing segment', async () => {+ const input = `import React from 'react';+import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';++export const Example: React.FC = () => {+\tconst frame = useCurrentFrame();+\treturn (+\t\t<AbsoluteFill>+\t\t\t<div style={{scale: interpolate(frame, [0, 100], [2, 4])}} />+\t\t</AbsoluteFill>+\t);+};+`;+ const {output} = await updateSequenceKeyframes({+ input,+ nodePath: lineColumnToNodePath(input, getLine(input, 'scale')),+ updates: [+ {+ key: 'style.scale',+ operation: {+ type: 'easing',+ segmentIndex: 0,+ easing: {+ type: 'spring',+ damping: 12,+ mass: 1.5,+ stiffness: 180,+ overshootClamping: true,+ },+ },+ },+ ],+ });++ expect(output).toContain('Easing');+ expect(output).toContain('easing: [');+ expect(output).toContain('Easing.spring({');+ expect(output).toContain('damping: 12');+ expect(output).toContain('mass: 1.5');+ expect(output).toContain('stiffness: 180');+ expect(output).toContain('overshootClamping: true');+});+test('updateSequenceKeyframes adds an unaliased Easing import for easing edits', async () => {const input = `import React from 'react';import {AbsoluteFill, Easing as RemotionEasing, interpolate, useCurrentFrame} from 'remotion';@@ -260,7 +303,7 @@ export const Example: React.FC = () => {operation: {type: 'easing',segmentIndex: 1,- easing: [0.42, 0, 1, 1],+ easing: {type: 'bezier', x1: 0.42, y1: 0, x2: 1, y2: 1},},},],@@ -293,7 +336,7 @@ export const Example: React.FC = () => {operation: {type: 'easing',segmentIndex: 1,- easing: [0, 0, 0.58, 1],+ easing: {type: 'bezier', x1: 0, y1: 0, x2: 0.58, y2: 1},},},],@@ -326,7 +369,7 @@ export const Example: React.FC = () => {operation: {type: 'easing',segmentIndex: 1,- easing: 'linear',+ easing: {type: 'linear'},},},],@@ -346,7 +389,7 @@ test('updateSequenceKeyframes sets easing for color keyframes', async () => {operation: {type: 'easing',segmentIndex: 0,- easing: [0.42, 0, 1, 1],+ easing: {type: 'bezier', x1: 0.42, y1: 0, x2: 1, y2: 1},},},],@@ -1091,7 +1134,7 @@ test('updateEffectKeyframes sets one easing segment and fills linear segments',operation: {type: 'easing',segmentIndex: 1,- easing: [0, 0, 0.58, 1],+ easing: {type: 'bezier', x1: 0, y1: 0, x2: 0.58, y2: 1},},},],diff --git a/packages/studio-shared/src/effect-clipboard-data.ts b/packages/studio-shared/src/effect-clipboard-data.tsindex f4881cad88..cce59e91b2 100644--- a/packages/studio-shared/src/effect-clipboard-data.ts+++ b/packages/studio-shared/src/effect-clipboard-data.ts@@ -1,3 +1,4 @@+import type {KeyframeEasing} from './keyframe-easing-presets';import {isKeyframeInterpolationFunction,type KeyframeInterpolationFunction,@@ -18,7 +19,7 @@ export type EffectClipboardKeyframe = {readonly value: unknown;};-export type EffectClipboardEasing = 'linear' | [number, number, number, number];+export type EffectClipboardEasing = KeyframeEasing;export type EffectClipboardExtrapolateType =| 'extend'@@ -107,10 +108,18 @@ const isFiniteNumber = (value: unknown): value is number => {const isEasing = (value: unknown): value is EffectClipboardEasing => {return (- value === 'linear' ||- (Array.isArray(value) &&- value.length === 4 &&- value.every((item) => isFiniteNumber(item)))+ isRecord(value) &&+ (value.type === 'linear' ||+ (value.type === 'bezier' &&+ isFiniteNumber(value.x1) &&+ isFiniteNumber(value.y1) &&+ isFiniteNumber(value.x2) &&+ isFiniteNumber(value.y2)) ||+ (value.type === 'spring' &&+ isFiniteNumber(value.damping) &&+ isFiniteNumber(value.mass) &&+ isFiniteNumber(value.stiffness) &&+ typeof value.overshootClamping === 'boolean')));};diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.tsindex f50b999629..d5550fcd49 100644--- a/packages/studio-shared/src/index.ts+++ b/packages/studio-shared/src/index.ts@@ -122,6 +122,7 @@ export {export {DEFAULT_BUFFER_STATE_DELAY_IN_MILLISECONDS} from './default-buffer-state-delay-in-milliseconds';export {KEYFRAME_EASING_PRESETS,+ LINEAR_KEYFRAME_EASING,type KeyframeEasingPreset,} from './keyframe-easing-presets';export {@@ -181,6 +182,11 @@ export {keyframeInterpolationFunctions,type KeyframeInterpolationFunction,} from './keyframe-interpolation-function';+export {+ DEFAULT_SPRING_EASING,+ parseSpringEasingConfig,+ type SpringKeyframeEasing,+} from './parse-spring-easing-config';export {DEFAULT_TIMELINE_TRACKS} from './max-timeline-tracks';export {Pkgs,diff --git a/packages/studio-shared/src/keyframe-easing-presets.ts b/packages/studio-shared/src/keyframe-easing-presets.tsindex 5948d249a9..f4036f8712 100644--- a/packages/studio-shared/src/keyframe-easing-presets.ts+++ b/packages/studio-shared/src/keyframe-easing-presets.ts@@ -1,4 +1,6 @@-export type KeyframeEasing = 'linear' | [number, number, number, number];+import type {CanUpdateSequencePropStatusEasing} from 'remotion';++export type KeyframeEasing = CanUpdateSequencePropStatusEasing;export type KeyframeEasingPreset = {readonly id: 'ease-in' | 'ease-out' | 'ease-in-out';@@ -6,8 +8,22 @@ export type KeyframeEasingPreset = {readonly easing: KeyframeEasing;};+export const LINEAR_KEYFRAME_EASING: KeyframeEasing = {type: 'linear'};+export const KEYFRAME_EASING_PRESETS: KeyframeEasingPreset[] = [- {id: 'ease-in', label: 'Ease in', easing: [0.42, 0, 1, 1]},- {id: 'ease-out', label: 'Ease out', easing: [0, 0, 0.58, 1]},- {id: 'ease-in-out', label: 'Ease in-out', easing: [0.42, 0, 0.58, 1]},+ {+ id: 'ease-in',+ label: 'Ease in',+ easing: {type: 'bezier', x1: 0.42, y1: 0, x2: 1, y2: 1},+ },+ {+ id: 'ease-out',+ label: 'Ease out',+ easing: {type: 'bezier', x1: 0, y1: 0, x2: 0.58, y2: 1},+ },+ {+ id: 'ease-in-out',+ label: 'Ease in-out',+ easing: {type: 'bezier', x1: 0.42, y1: 0, x2: 0.58, y2: 1},+ },];diff --git a/packages/studio-shared/src/optimistic-add-keyframe.ts b/packages/studio-shared/src/optimistic-add-keyframe.tsindex 7a555bd80b..427f51ef41 100644--- a/packages/studio-shared/src/optimistic-add-keyframe.ts+++ b/packages/studio-shared/src/optimistic-add-keyframe.ts@@ -3,6 +3,7 @@ import {type CanUpdateSequencePropsResponse,type SequenceSchema,} from 'remotion';+import {LINEAR_KEYFRAME_EASING} from './keyframe-easing-presets';import {getKeyframeInterpolationFunction,isSchemaFieldKeyframable,@@ -41,7 +42,7 @@ const addKeyframeToPropStatus = ({);const easing = [...status.easing];while (easing.length < keyframes.length - 1) {- easing.push('linear');+ easing.push(LINEAR_KEYFRAME_EASING);}return {diff --git a/packages/studio-shared/src/optimistic-update-keyframe-settings.ts b/packages/studio-shared/src/optimistic-update-keyframe-settings.tsindex 911dad143d..51fe90a4e5 100644--- a/packages/studio-shared/src/optimistic-update-keyframe-settings.ts+++ b/packages/studio-shared/src/optimistic-update-keyframe-settings.ts@@ -3,6 +3,7 @@ import type {CanUpdateSequencePropStatus,} from 'remotion';import type {KeyframeSettings} from './api-requests';+import {LINEAR_KEYFRAME_EASING} from './keyframe-easing-presets';type KeyframeEasing = Extract<CanUpdateSequencePropStatus,@@ -29,7 +30,7 @@ const updateEasing = ({}const nextEasing = Array.from({length: segmentCount}, (_, index) => {- return easing[index] ?? 'linear';+ return easing[index] ?? LINEAR_KEYFRAME_EASING;});nextEasing[segmentIndex] = value;return nextEasing;diff --git a/packages/studio-shared/src/parse-spring-easing-config.ts b/packages/studio-shared/src/parse-spring-easing-config.tsnew file mode 100644index 0000000000..0ffb2dc494--- /dev/null+++ b/packages/studio-shared/src/parse-spring-easing-config.ts@@ -0,0 +1,138 @@+export type SpringKeyframeEasing = {+ readonly type: 'spring';+ damping: number;+ mass: number;+ overshootClamping: boolean;+ stiffness: number;+};++export const DEFAULT_SPRING_EASING: SpringKeyframeEasing = {+ type: 'spring',+ damping: 10,+ mass: 1,+ overshootClamping: false,+ stiffness: 100,+};++type MinimalAstNode = {+ readonly type: string;+ readonly [key: string]: unknown;+};++const isAstNode = (value: unknown): value is MinimalAstNode => {+ return (+ typeof value === 'object' &&+ value !== null &&+ typeof (value as {type?: unknown}).type === 'string'+ );+};++const getNumericValue = (node: MinimalAstNode): number | null => {+ if (node.type === 'NumericLiteral') {+ return typeof node.value === 'number' ? node.value : null;+ }++ if (+ node.type === 'UnaryExpression' &&+ (node.operator === '-' || node.operator === '+') &&+ isAstNode(node.argument) &&+ node.argument.type === 'NumericLiteral' &&+ typeof node.argument.value === 'number'+ ) {+ return node.operator === '-' ? -node.argument.value : node.argument.value;+ }++ if (node.type === 'TSAsExpression' && isAstNode(node.expression)) {+ return getNumericValue(node.expression);+ }++ return null;+};++const getBooleanValue = (node: MinimalAstNode): boolean | null => {+ if (node.type === 'BooleanLiteral') {+ return typeof node.value === 'boolean' ? node.value : null;+ }++ if (node.type === 'TSAsExpression' && isAstNode(node.expression)) {+ return getBooleanValue(node.expression);+ }++ return null;+};++const getObjectPropertyName = (prop: MinimalAstNode): string | null => {+ if (prop.computed === true || !isAstNode(prop.key)) {+ return null;+ }++ if (prop.key.type === 'Identifier') {+ return typeof prop.key.name === 'string' ? prop.key.name : null;+ }++ if (prop.key.type === 'StringLiteral') {+ return typeof prop.key.value === 'string' ? prop.key.value : null;+ }++ return null;+};++export const parseSpringEasingConfig = (+ node: unknown,+): SpringKeyframeEasing | null => {+ if (node === undefined) {+ return {...DEFAULT_SPRING_EASING};+ }++ if (!isAstNode(node)) {+ return null;+ }++ if (node.type === 'TSAsExpression') {+ return parseSpringEasingConfig(node.expression);+ }++ if (node.type !== 'ObjectExpression' || !Array.isArray(node.properties)) {+ return null;+ }++ const spring: SpringKeyframeEasing = {...DEFAULT_SPRING_EASING};+ for (const prop of node.properties) {+ if (!isAstNode(prop) || prop.type !== 'ObjectProperty') {+ return null;+ }++ const key = getObjectPropertyName(prop);+ if (!key || !isAstNode(prop.value)) {+ return null;+ }++ if (key === 'damping' || key === 'mass' || key === 'stiffness') {+ const numericValue = getNumericValue(prop.value);+ if (+ numericValue === null ||+ !Number.isFinite(numericValue) ||+ numericValue <= 0+ ) {+ return null;+ }++ spring[key] = numericValue;+ continue;+ }++ if (key === 'overshootClamping') {+ const booleanValue = getBooleanValue(prop.value);+ if (booleanValue === null) {+ return null;+ }++ spring.overshootClamping = booleanValue;+ continue;+ }++ return null;+ }++ return spring;+};diff --git a/packages/studio-shared/src/test/effect-clipboard-data.test.ts b/packages/studio-shared/src/test/effect-clipboard-data.test.tsindex 9469114d67..bb93442f88 100644--- a/packages/studio-shared/src/test/effect-clipboard-data.test.ts+++ b/packages/studio-shared/src/test/effect-clipboard-data.test.ts@@ -24,7 +24,7 @@ test('parseEffectClipboardData accepts keyframed v3 effect payloads', () => {{frame: 0, value: 0},{frame: 100, value: 1},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},},},@@ -49,7 +49,7 @@ test('parseEffectClipboardData accepts keyframed v3 effect payloads', () => {{frame: 0, value: 0},{frame: 100, value: 1},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},},},@@ -58,6 +58,61 @@ test('parseEffectClipboardData accepts keyframed v3 effect payloads', () => {});});+test('parseEffectClipboardData accepts spring easing payloads', () => {+ const parsed = parseEffectClipboardData(+ JSON.stringify({+ type: 'effects-additive',+ version: 3,+ remotionClipboard: 'effects',+ effects: [+ {+ callee: 'brightness',+ importPath: '@remotion/effects/brightness',+ params: {+ amount: {+ type: 'keyframed',+ interpolationFunction: 'interpolate',+ keyframes: [+ {frame: 0, value: 0},+ {frame: 100, value: 1},+ ],+ easing: [+ {+ type: 'spring',+ damping: 12,+ mass: 1.5,+ stiffness: 180,+ overshootClamping: true,+ },+ ],+ clamping: {left: 'clamp', right: 'clamp'},+ },+ },+ },+ ],+ }),+ );++ expect(parsed?.effects[0]?.params.amount).toEqual({+ type: 'keyframed',+ interpolationFunction: 'interpolate',+ keyframes: [+ {frame: 0, value: 0},+ {frame: 100, value: 1},+ ],+ easing: [+ {+ type: 'spring',+ damping: 12,+ mass: 1.5,+ stiffness: 180,+ overshootClamping: true,+ },+ ],+ clamping: {left: 'clamp', right: 'clamp'},+ });+});+test('parseEffectClipboardData accepts rotate interpolation functions', () => {const parsed = parseEffectClipboardData(JSON.stringify({@@ -76,7 +131,7 @@ test('parseEffectClipboardData accepts rotate interpolation functions', () => {{frame: 0, value: '0deg'},{frame: 100, value: '90deg'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},},},@@ -92,7 +147,7 @@ test('parseEffectClipboardData accepts rotate interpolation functions', () => {{frame: 0, value: '0deg'},{frame: 100, value: '90deg'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},});});@@ -142,7 +197,7 @@ test('parseEffectClipboardData rejects malformed keyframed payloads', () => {type: 'keyframed',interpolationFunction: 'interpolate',keyframes: [{frame: 0, value: 0}],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},},},@@ -171,7 +226,7 @@ test('parseEffectPropClipboardData accepts keyframed effect prop payloads', () ={frame: 0, value: 0},{frame: 100, value: 1},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},},}),@@ -193,7 +248,7 @@ test('parseEffectPropClipboardData accepts keyframed effect prop payloads', () ={frame: 0, value: 0},{frame: 100, value: 1},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},},});diff --git a/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts b/packages/studio-shared/src/test/optimistic-add-keyframe.test.tsindex fdfb419319..be3f667649 100644--- a/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts+++ b/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts@@ -193,7 +193,7 @@ test('optimisticAddSequenceKeyframe appends a keyframe to an existing interpolat{frame: 0, value: 1},{frame: 60, value: 2},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -222,7 +222,7 @@ test('optimisticAddSequenceKeyframe appends a keyframe to an existing interpolat{frame: 30, value: 1.5},{frame: 60, value: 2},]);- expect(status.easing).toEqual(['linear', 'linear']);+ expect(status.easing).toEqual([{type: 'linear'}, {type: 'linear'}]);});test('optimisticAddSequenceKeyframe updates an existing keyframe at the same frame', () => {@@ -236,7 +236,7 @@ test('optimisticAddSequenceKeyframe updates an existing keyframe at the same fra{frame: 0, value: 1},{frame: 60, value: 2},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -264,7 +264,7 @@ test('optimisticAddSequenceKeyframe updates an existing keyframe at the same fra{frame: 0, value: 1},{frame: 60, value: 3},]);- expect(status.easing).toEqual(['linear']);+ expect(status.easing).toEqual([{type: 'linear'}]);});test('optimisticAddEffectKeyframe appends a keyframe on the target effect', () => {diff --git a/packages/studio-shared/src/test/optimistic-delete-keyframe.test.ts b/packages/studio-shared/src/test/optimistic-delete-keyframe.test.tsindex 2aefdcabf5..256e57d66e 100644--- a/packages/studio-shared/src/test/optimistic-delete-keyframe.test.ts+++ b/packages/studio-shared/src/test/optimistic-delete-keyframe.test.ts@@ -19,7 +19,7 @@ test('optimisticDeleteSequenceKeyframe removes the matching keyframe and an easi{frame: 30, value: 0.5},{frame: 60, value: 1},],- easing: ['linear', 'linear'],+ easing: [{type: 'linear'}, {type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -46,7 +46,7 @@ test('optimisticDeleteSequenceKeyframe removes the matching keyframe and an easi{frame: 0, value: 0},{frame: 60, value: 1},]);- expect(status.easing).toEqual(['linear']);+ expect(status.easing).toEqual([{type: 'linear'}]);});test('optimisticDeleteSequenceKeyframe converts the last keyframe to a static value', () => {@@ -135,7 +135,7 @@ test('optimisticDeleteSequenceKeyframes deletes multiple keyframes in one pass',{frame: 30, value: 200},{frame: 60, value: 300},],- easing: ['linear', 'linear'],+ easing: [{type: 'linear'}, {type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -182,7 +182,7 @@ test('optimisticDeleteEffectKeyframe removes the matching keyframe on the target{frame: 0, value: 0},{frame: 30, value: 1},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -298,7 +298,7 @@ test('optimisticDeleteEffectKeyframes deletes multiple keyframes in one pass', ({frame: 30, value: 0.5},{frame: 60, value: 1},],- easing: ['linear', 'linear'],+ easing: [{type: 'linear'}, {type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},diff --git a/packages/studio-shared/src/test/optimistic-move-keyframe.test.ts b/packages/studio-shared/src/test/optimistic-move-keyframe.test.tsindex 832d87de6b..30ce844c90 100644--- a/packages/studio-shared/src/test/optimistic-move-keyframe.test.ts+++ b/packages/studio-shared/src/test/optimistic-move-keyframe.test.ts@@ -17,7 +17,7 @@ const previous: CanUpdateSequencePropsResponse = {{frame: 20, value: 2},{frame: 40, value: 3},],- easing: ['linear', 'linear'],+ easing: [{type: 'linear'}, {type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -36,7 +36,7 @@ const previous: CanUpdateSequencePropsResponse = {{frame: 0, value: 0.2},{frame: 20, value: 0.5},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -68,7 +68,7 @@ test('optimisticMoveSequenceKeyframes moves multiple keyframes in one field', (){frame: 30, value: 2},{frame: 40, value: 3},]);- expect(status.easing).toEqual(['linear', 'linear']);+ expect(status.easing).toEqual([{type: 'linear'}, {type: 'linear'}]);});test('optimisticMoveSequenceKeyframes resorts when moving past an adjacent keyframe', () => {@@ -91,7 +91,7 @@ test('optimisticMoveSequenceKeyframes resorts when moving past an adjacent keyfr{frame: 30, value: 1},{frame: 40, value: 3},]);- expect(status.easing).toEqual(['linear', 'linear']);+ expect(status.easing).toEqual([{type: 'linear'}, {type: 'linear'}]);});test('optimisticMoveSequenceKeyframes replaces an existing keyframe', () => {@@ -113,7 +113,7 @@ test('optimisticMoveSequenceKeyframes replaces an existing keyframe', () => {{frame: 20, value: 1},{frame: 40, value: 3},]);- expect(status.easing).toEqual(['linear']);+ expect(status.easing).toEqual([{type: 'linear'}]);});test('canMoveKeyframesWithoutCollisions allows moving onto a frame vacated by another selected keyframe', () => {diff --git a/packages/studio-shared/src/test/optimistic-update-keyframe-settings.test.ts b/packages/studio-shared/src/test/optimistic-update-keyframe-settings.test.tsindex d7bfabab43..5cedb76856 100644--- a/packages/studio-shared/src/test/optimistic-update-keyframe-settings.test.ts+++ b/packages/studio-shared/src/test/optimistic-update-keyframe-settings.test.ts@@ -16,7 +16,7 @@ const previous: CanUpdateSequencePropsResponse = {{frame: 20, value: 2},{frame: 40, value: 3},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'wrap'},posterize: 3,},@@ -51,7 +51,7 @@ test('optimisticUpdateSequenceKeyframeSettings updates easing without changing osettings: {type: 'easing',segmentIndex: 1,- easing: [0.42, 0, 1, 1],+ easing: {type: 'bezier', x1: 0.42, y1: 0, x2: 1, y2: 1},},});@@ -64,7 +64,10 @@ test('optimisticUpdateSequenceKeyframeSettings updates easing without changing othrow new Error('expected keyframed status');}- expect(status.easing).toEqual(['linear', [0.42, 0, 1, 1]]);+ expect(status.easing).toEqual([+ {type: 'linear'},+ {type: 'bezier', x1: 0.42, y1: 0, x2: 1, y2: 1},+ ]);expect(status.clamping).toEqual({left: 'clamp', right: 'wrap'});expect(status.posterize).toBe(3);});@@ -77,7 +80,7 @@ test('optimisticUpdateEffectKeyframeSettings updates easing', () => {settings: {type: 'easing',segmentIndex: 0,- easing: [0, 0, 0.58, 1],+ easing: {type: 'bezier', x1: 0, y1: 0, x2: 0.58, y2: 1},},});@@ -95,5 +98,7 @@ test('optimisticUpdateEffectKeyframeSettings updates easing', () => {throw new Error('expected keyframed status');}- expect(status.easing).toEqual([[0, 0, 0.58, 1]]);+ expect(status.easing).toEqual([+ {type: 'bezier', x1: 0, y1: 0, x2: 0.58, y2: 1},+ ]);});diff --git a/packages/studio-shared/src/test/parse-spring-easing-config.test.ts b/packages/studio-shared/src/test/parse-spring-easing-config.test.tsnew file mode 100644index 0000000000..b36862a00d--- /dev/null+++ b/packages/studio-shared/src/test/parse-spring-easing-config.test.ts@@ -0,0 +1,120 @@+import {expect, test} from 'bun:test';+import {+ DEFAULT_SPRING_EASING,+ parseSpringEasingConfig,+} from '../parse-spring-easing-config';++test('parseSpringEasingConfig returns default config for missing argument', () => {+ expect(parseSpringEasingConfig(undefined)).toEqual(DEFAULT_SPRING_EASING);+});++test('parseSpringEasingConfig parses a static spring config object', () => {+ expect(+ parseSpringEasingConfig({+ type: 'ObjectExpression',+ properties: [+ {+ type: 'ObjectProperty',+ computed: false,+ key: {type: 'Identifier', name: 'damping'},+ value: {type: 'NumericLiteral', value: 12},+ },+ {+ type: 'ObjectProperty',+ computed: false,+ key: {type: 'Identifier', name: 'mass'},+ value: {+ type: 'UnaryExpression',+ operator: '+',+ argument: {type: 'NumericLiteral', value: 1.5},+ },+ },+ {+ type: 'ObjectProperty',+ computed: false,+ key: {type: 'StringLiteral', value: 'stiffness'},+ value: {type: 'NumericLiteral', value: 180},+ },+ {+ type: 'ObjectProperty',+ computed: false,+ key: {type: 'Identifier', name: 'overshootClamping'},+ value: {type: 'BooleanLiteral', value: true},+ },+ ],+ }),+ ).toEqual({+ type: 'spring',+ damping: 12,+ mass: 1.5,+ stiffness: 180,+ overshootClamping: true,+ });+});++test('parseSpringEasingConfig unwraps TypeScript casts', () => {+ expect(+ parseSpringEasingConfig({+ type: 'TSAsExpression',+ expression: {+ type: 'ObjectExpression',+ properties: [+ {+ type: 'ObjectProperty',+ computed: false,+ key: {type: 'Identifier', name: 'damping'},+ value: {+ type: 'TSAsExpression',+ expression: {type: 'NumericLiteral', value: 12},+ },+ },+ {+ type: 'ObjectProperty',+ computed: false,+ key: {type: 'Identifier', name: 'overshootClamping'},+ value: {+ type: 'TSAsExpression',+ expression: {type: 'BooleanLiteral', value: true},+ },+ },+ ],+ },+ }),+ ).toEqual({+ ...DEFAULT_SPRING_EASING,+ damping: 12,+ overshootClamping: true,+ });+});++test('parseSpringEasingConfig rejects dynamic or invalid spring configs', () => {+ expect(parseSpringEasingConfig({type: 'Identifier', name: 'config'})).toBe(+ null,+ );++ expect(+ parseSpringEasingConfig({+ type: 'ObjectExpression',+ properties: [+ {+ type: 'ObjectProperty',+ computed: false,+ key: {type: 'Identifier', name: 'damping'},+ value: {type: 'NumericLiteral', value: 0},+ },+ ],+ }),+ ).toBe(null);++ expect(+ parseSpringEasingConfig({+ type: 'ObjectExpression',+ properties: [+ {+ type: 'SpreadElement',+ argument: {type: 'Identifier', name: 'config'},+ },+ ],+ }),+ ).toBe(null);+});diff --git a/packages/studio/src/components/Timeline/EasingEditorModal.tsx b/packages/studio/src/components/Timeline/EasingEditorModal.tsxindex ffc66a55a4..2d623f0d73 100644--- a/packages/studio/src/components/Timeline/EasingEditorModal.tsx+++ b/packages/studio/src/components/Timeline/EasingEditorModal.tsx@@ -6,7 +6,7 @@ import React, {useRef,useState,} from 'react';-import {Internals} from 'remotion';+import {Easing, Internals} from 'remotion';import {StudioServerConnectionCtx} from '../../helpers/client-id';import {BLUE,@@ -14,7 +14,10 @@ import {INPUT_BORDER_COLOR_HOVERED,LIGHT_TEXT,} from '../../helpers/colors';+import {Checkbox} from '../Checkbox';import {InputDragger} from '../NewComposition/InputDragger';+import type {SegmentedControlItem} from '../SegmentedControl';+import {SegmentedControl} from '../SegmentedControl';import type {TimelineSelection} from './TimelineSelection';import type {SelectedEasingUpdate,@@ -26,9 +29,13 @@ import {updateSelectedTimelineEasings,} from './update-selected-easing';-type CubicBezier = [number, number, number, number];+type CubicBezierTuple = [number, number, number, number];+type BezierEasing = Extract<TimelineEasingValue, {type: 'bezier'}>;+type SpringEasing = Extract<TimelineEasingValue, {type: 'spring'}>;type HandleIndex = 0 | 1;type Coordinate = 'x' | 'y';+type EditorMode = 'bezier' | 'spring';+type SpringNumberKey = 'damping' | 'mass' | 'stiffness';const SVG_WIDTH = 560;const SVG_HEIGHT = 320;@@ -38,13 +45,47 @@ const PLOT_WIDTH = 500;const PLOT_HEIGHT = SVG_HEIGHT;const Y_MIN = -2;const Y_MAX = 3;-const LINEAR_BEZIER: CubicBezier = [0.25, 0.25, 0.75, 0.75];+const LINEAR_EASING: TimelineEasingValue = {type: 'linear'};+const LINEAR_BEZIER: CubicBezierTuple = [0.25, 0.25, 0.75, 0.75];+const DEFAULT_SPRING_EASING: SpringEasing = {+ type: 'spring',+ damping: 10,+ mass: 1,+ overshootClamping: false,+ stiffness: 100,+};++const SPRING_LIMITS: Record<+ SpringNumberKey,+ {+ readonly min: number;+ readonly max: number;+ readonly step: number;+ }+> = {+ damping: {min: 1, max: 200, step: 1},+ mass: {min: 0.1, max: 20, step: 0.1},+ stiffness: {min: 1, max: 1000, step: 1},+};++const SPRING_DECIMAL_PLACES: Record<SpringNumberKey, number> = {+ damping: 0,+ mass: 2,+ stiffness: 0,+};const inlineContainer: React.CSSProperties = {width: '100%',minWidth: 0,};+const segmentedControlWrapper: React.CSSProperties = {+ display: 'flex',+ justifyContent: 'center',+ padding: '0 12px',+ marginBottom: 8,+};+const coordinatesGridBase: React.CSSProperties = {display: 'grid',gap: 10,@@ -67,6 +108,11 @@ const coordinateInputWrapper: React.CSSProperties = {alignItems: 'center',};+const checkboxWrapper: React.CSSProperties = {+ ...coordinateInputWrapper,+ paddingLeft: 6,+};+const numberInputStyle: React.CSSProperties = {backgroundColor: INPUT_BACKGROUND,borderRadius: 4,@@ -85,26 +131,100 @@ const clamp = (value: number, min: number, max: number) => {return Math.min(max, Math.max(min, value));};-const sanitizeBezier = (bezier: CubicBezier): CubicBezier => [+const sanitizeBezier = (bezier: CubicBezierTuple): CubicBezierTuple => [clamp(bezier[0], 0, 1),clamp(bezier[1], Y_MIN, Y_MAX),clamp(bezier[2], 0, 1),clamp(bezier[3], Y_MIN, Y_MAX),];-const easingToBezier = (easing: TimelineEasingValue): CubicBezier => {- return easing === 'linear' ? LINEAR_BEZIER : sanitizeBezier(easing);+const isSpringEasing = (+ easing: TimelineEasingValue,+): easing is SpringEasing => {+ return easing.type === 'spring';+};++const isBezierEasing = (+ easing: TimelineEasingValue,+): easing is BezierEasing => {+ return easing.type === 'bezier';+};++const easingToBezier = (easing: TimelineEasingValue): CubicBezierTuple => {+ return isBezierEasing(easing)+ ? sanitizeBezier([easing.x1, easing.y1, easing.x2, easing.y2])+ : LINEAR_BEZIER;+};++const easingToSpring = (easing: TimelineEasingValue): SpringEasing => {+ return isSpringEasing(easing)+ ? sanitizeSpring(easing)+ : DEFAULT_SPRING_EASING;+};++const easingToMode = (easing: TimelineEasingValue): EditorMode => {+ return isSpringEasing(easing) ? 'spring' : 'bezier';};-const roundCoordinate = (value: number) => Math.round(value * 10000) / 10000;+const roundToDecimalPlaces = (value: number, decimalPlaces: number) => {+ const factor = 10 ** decimalPlaces;+ const rounded = Math.round(value * factor) / factor;+ return Object.is(rounded, -0) ? 0 : rounded;+};++const roundCoordinate = (value: number) => roundToDecimalPlaces(value, 4);-const serializeBezier = (bezier: CubicBezier): TimelineEasingValue => {- const rounded = sanitizeBezier(bezier).map(roundCoordinate) as CubicBezier;+const serializeBezier = (bezier: CubicBezierTuple): TimelineEasingValue => {+ const rounded = sanitizeBezier(bezier).map(+ roundCoordinate,+ ) as CubicBezierTuple;if (rounded[0] === rounded[1] && rounded[2] === rounded[3]) {- return 'linear';+ return LINEAR_EASING;+ }++ return {+ type: 'bezier',+ x1: rounded[0],+ y1: rounded[1],+ x2: rounded[2],+ y2: rounded[3],+ };+};++const sanitizeSpringValue = (+ value: number,+ key: SpringNumberKey,+ fallback: number,+) => {+ const limits = SPRING_LIMITS[key];+ if (!Number.isFinite(value)) {+ return fallback;}- return rounded;+ return roundToDecimalPlaces(+ clamp(value, limits.min, limits.max),+ SPRING_DECIMAL_PLACES[key],+ );+};++const sanitizeSpring = (spring: SpringEasing): SpringEasing => ({+ type: 'spring',+ damping: sanitizeSpringValue(+ spring.damping,+ 'damping',+ DEFAULT_SPRING_EASING.damping,+ ),+ mass: sanitizeSpringValue(spring.mass, 'mass', DEFAULT_SPRING_EASING.mass),+ overshootClamping: spring.overshootClamping,+ stiffness: sanitizeSpringValue(+ spring.stiffness,+ 'stiffness',+ DEFAULT_SPRING_EASING.stiffness,+ ),+});++const serializeSpring = (spring: SpringEasing): TimelineEasingValue => {+ return sanitizeSpring(spring);};const formatNumber = (value: number | string) => {@@ -116,6 +236,25 @@ const formatNumber = (value: number | string) => {return String(roundCoordinate(numericValue));};+const formatNumberWithDecimalPlaces =+ (decimalPlaces: number) => (value: number | string) => {+ const numericValue = Number(value);+ if (!Number.isFinite(numericValue)) {+ return String(value);+ }++ return String(roundToDecimalPlaces(numericValue, decimalPlaces));+ };++const springFormatters: Record<+ SpringNumberKey,+ (value: number | string) => string+> = {+ damping: formatNumberWithDecimalPlaces(SPRING_DECIMAL_PLACES.damping),+ mass: formatNumberWithDecimalPlaces(SPRING_DECIMAL_PLACES.mass),+ stiffness: formatNumberWithDecimalPlaces(SPRING_DECIMAL_PLACES.stiffness),+};+const areEasingsEqual = (first: TimelineEasingValue,second: TimelineEasingValue,@@ -124,11 +263,34 @@ const areEasingsEqual = (return true;}- if (first === 'linear' || second === 'linear') {+ if (first.type !== second.type) {return false;}- return first.every((value, index) => value === second[index]);+ switch (first.type) {+ case 'linear':+ return true;+ case 'spring':+ return (+ second.type === 'spring' &&+ first.damping === second.damping &&+ first.mass === second.mass &&+ first.overshootClamping === second.overshootClamping &&+ first.stiffness === second.stiffness+ );+ case 'bezier':+ return (+ second.type === 'bezier' &&+ first.x1 === second.x1 &&+ first.y1 === second.y1 &&+ first.x2 === second.x2 &&+ first.y2 === second.y2+ );+ default:+ throw new Error(+ `Unsupported easing: ${JSON.stringify(first satisfies never)}`,+ );+ }};const getEasingUpdateTargetKey = (update: SelectedEasingUpdate) => {@@ -146,12 +308,46 @@ const xToSvg = (value: number) => PLOT_LEFT + value * PLOT_WIDTH;const yToSvg = (value: number) =>PLOT_TOP + ((Y_MAX - value) / (Y_MAX - Y_MIN)) * PLOT_HEIGHT;-const pointFromBezier = (bezier: CubicBezier, handle: HandleIndex) => {+const pointFromBezier = (bezier: CubicBezierTuple, handle: HandleIndex) => {const x = handle === 0 ? bezier[0] : bezier[2];const y = handle === 0 ? bezier[1] : bezier[3];return {x: xToSvg(x), y: yToSvg(y)};};+const EasingGraphScaffold: React.FC = () => {+ const yZero = yToSvg(0);+ const yOne = yToSvg(1);+ const yZeroLabel = clamp(yZero + 3, 10, SVG_HEIGHT - 4);+ const yOneLabel = clamp(yOne + 3, 10, SVG_HEIGHT - 4);++ return (+ <>+ <line+ x1={PLOT_LEFT}+ y1={yZero}+ x2={PLOT_LEFT + PLOT_WIDTH}+ y2={yZero}+ stroke={INPUT_BORDER_COLOR_HOVERED}+ strokeWidth={1}+ />+ <line+ x1={PLOT_LEFT}+ y1={yOne}+ x2={PLOT_LEFT + PLOT_WIDTH}+ y2={yOne}+ stroke={INPUT_BORDER_COLOR_HOVERED}+ strokeWidth={1}+ />+ <text x={PLOT_LEFT - 22} y={yZeroLabel} fill={LIGHT_TEXT} fontSize={9}>+ 0+ </text>+ <text x={PLOT_LEFT - 22} y={yOneLabel} fill={LIGHT_TEXT} fontSize={9}>+ 1+ </text>+ </>+ );+};+export type EasingEditorState = {initialEasing: TimelineEasingValue;selections: TimelineSelection[];@@ -176,18 +372,27 @@ export const EasingEditor: React.FC<{Internals.OverrideIdsToNodePathsGettersContext,);const svgRef = useRef<SVGSVGElement>(null);+ const [mode, setMode] = useState(() => easingToMode(state.initialEasing));const [bezier, setBezier] = useState(() =>easingToBezier(state.initialEasing),);+ const [spring, setSpring] = useState(() =>+ easingToSpring(state.initialEasing),+ );const bezierRef = useRef(bezier);+ const springRef = useRef(spring);const liveOverrideVersionRef = useRef(0);const pendingOverrideTargetsRef = useRef<SelectedEasingUpdate[]>([]);const [activeHandle, setActiveHandle] = useState<HandleIndex | null>(null);useEffect(() => {const nextBezier = easingToBezier(state.initialEasing);+ const nextSpring = easingToSpring(state.initialEasing);bezierRef.current = nextBezier;+ springRef.current = nextSpring;+ setMode(easingToMode(state.initialEasing));setBezier(nextBezier);+ setSpring(nextSpring);}, [state.initialEasing]);const getCurrentEasingUpdates = useCallback(() => {@@ -334,7 +539,7 @@ export const EasingEditor: React.FC<{);const setBezierAndPreview = useCallback(- (nextBezier: CubicBezier) => {+ (nextBezier: CubicBezierTuple) => {const sanitized = sanitizeBezier(nextBezier);bezierRef.current = sanitized;setBezier(sanitized);@@ -343,6 +548,16 @@ export const EasingEditor: React.FC<{[applyLiveEasing],);+ const setSpringAndPreview = useCallback(+ (nextSpring: SpringEasing) => {+ const sanitized = sanitizeSpring(nextSpring);+ springRef.current = sanitized;+ setSpring(sanitized);+ return applyLiveEasing(serializeSpring(sanitized));+ },+ [applyLiveEasing],+ );+const setCoordinate = useCallback((handle: HandleIndex,@@ -350,7 +565,7 @@ export const EasingEditor: React.FC<{value: number,commit: boolean,) => {- const next = [...bezierRef.current] as CubicBezier;+ const next = [...bezierRef.current] as CubicBezierTuple;const index =handle === 0? coordinate === 'x'@@ -370,6 +585,47 @@ export const EasingEditor: React.FC<{[commitEasing, setBezierAndPreview],);+ const setSpringNumber = useCallback(+ (key: SpringNumberKey, value: number, commit: boolean) => {+ const next = {+ ...springRef.current,+ [key]: sanitizeSpringValue(value, key, DEFAULT_SPRING_EASING[key]),+ };+ const version = setSpringAndPreview(next);++ if (commit) {+ commitEasing(serializeSpring(next), version);+ }+ },+ [commitEasing, setSpringAndPreview],+ );++ const setOvershootClamping = useCallback(() => {+ const next = {+ ...springRef.current,+ overshootClamping: !springRef.current.overshootClamping,+ };+ const version = setSpringAndPreview(next);+ commitEasing(serializeSpring(next), version);+ }, [commitEasing, setSpringAndPreview]);++ const switchMode = useCallback(+ (nextMode: EditorMode) => {+ setMode(nextMode);+ if (mode === nextMode || previewServerState.type !== 'connected') {+ return;+ }++ const easing =+ nextMode === 'spring'+ ? serializeSpring(springRef.current)+ : serializeBezier(bezierRef.current);+ const version = applyLiveEasing(easing);+ commitEasing(easing, version);+ },+ [applyLiveEasing, commitEasing, mode, previewServerState.type],+ );+const getValueFromPointer = useCallback((event: {clientX: number; clientY: number}) => {const svg = svgRef.current;@@ -399,7 +655,7 @@ export const EasingEditor: React.FC<{return;}- const next = [...bezierRef.current] as CubicBezier;+ const next = [...bezierRef.current] as CubicBezierTuple;if (handle === 0) {next[0] = value.x;next[1] = value.y;@@ -463,15 +719,45 @@ export const EasingEditor: React.FC<{const endPoint = useMemo(() => ({x: xToSvg(1), y: yToSvg(1)}), []);const firstHandle = useMemo(() => pointFromBezier(bezier, 0), [bezier]);const secondHandle = useMemo(() => pointFromBezier(bezier, 1), [bezier]);- const path = useMemo(() => {+ const bezierPath = useMemo(() => {return `M ${startPoint.x} ${startPoint.y} C ${firstHandle.x} ${firstHandle.y}, ${secondHandle.x} ${secondHandle.y}, ${endPoint.x} ${endPoint.y}`;}, [endPoint, firstHandle, secondHandle, startPoint]);+ const springPath = useMemo(() => {+ const easing = Easing.spring({+ damping: spring.damping,+ mass: spring.mass,+ overshootClamping: spring.overshootClamping,+ stiffness: spring.stiffness,+ });+ const samples = 80;+ const points: string[] = [];+ for (let i = 0; i <= samples; i++) {+ const t = i / samples;+ const x = xToSvg(t);+ const y = yToSvg(clamp(easing(t), Y_MIN, Y_MAX));+ points.push(`${i === 0 ? 'M' : 'L'} ${x} ${y}`);+ }++ return points.join(' ');+ }, [spring]);- const yZero = yToSvg(0);- const yOne = yToSvg(1);- const yZeroLabel = clamp(yZero + 3, 10, SVG_HEIGHT - 4);- const yOneLabel = clamp(yOne + 3, 10, SVG_HEIGHT - 4);const disabled = previewServerState.type !== 'connected';+ const modeItems = useMemo((): SegmentedControlItem[] => {+ return [+ {+ key: 'bezier',+ label: 'Bezier',+ onClick: () => switchMode('bezier'),+ selected: mode === 'bezier',+ },+ {+ key: 'spring',+ label: 'Spring',+ onClick: () => switchMode('spring'),+ selected: mode === 'spring',+ },+ ];+ }, [mode, switchMode]);const coordinatesGrid = useMemo((): React.CSSProperties => ({...coordinatesGridBase,@@ -483,167 +769,267 @@ export const EasingEditor: React.FC<{return (<div style={inlineContainer}>- <svg- ref={svgRef}- width={SVG_WIDTH}- height={SVG_HEIGHT}- viewBox={`0 0 ${SVG_WIDTH} ${SVG_HEIGHT}`}- style={svgStyle}- aria-label="Bezier curve editor"- >- <line- x1={PLOT_LEFT}- y1={yZero}- x2={PLOT_LEFT + PLOT_WIDTH}- y2={yZero}- stroke={INPUT_BORDER_COLOR_HOVERED}- strokeWidth={1}- />- <line- x1={PLOT_LEFT}- y1={yOne}- x2={PLOT_LEFT + PLOT_WIDTH}- y2={yOne}- stroke={INPUT_BORDER_COLOR_HOVERED}- strokeWidth={1}- />-- <line- x1={startPoint.x}- y1={startPoint.y}- x2={firstHandle.x}- y2={firstHandle.y}- stroke="rgba(255, 255, 255, 0.35)"- strokeWidth={1}- />- <line- x1={endPoint.x}- y1={endPoint.y}- x2={secondHandle.x}- y2={secondHandle.y}- stroke="rgba(255, 255, 255, 0.35)"- strokeWidth={1}- />- <path d={path} fill="none" stroke={BLUE} strokeWidth={3} />- <circle cx={startPoint.x} cy={startPoint.y} r={4} fill="white" />- <circle cx={endPoint.x} cy={endPoint.y} r={4} fill="white" />- <circle- cx={firstHandle.x}- cy={firstHandle.y}- r={6}- fill="white"- stroke={BLUE}- strokeWidth={2}- vectorEffect="non-scaling-stroke"- pointerEvents={disabled ? 'none' : 'all'}- cursor={activeHandle === 0 ? 'grabbing' : 'default'}- onPointerDown={(event) => onHandlePointerDown(0, event)}- />- <circle- cx={secondHandle.x}- cy={secondHandle.y}- r={6}- fill="white"- stroke={BLUE}- strokeWidth={2}- vectorEffect="non-scaling-stroke"- pointerEvents={disabled ? 'none' : 'all'}- cursor={activeHandle === 1 ? 'grabbing' : 'default'}- onPointerDown={(event) => onHandlePointerDown(1, event)}- />- <text x={PLOT_LEFT - 22} y={yZeroLabel} fill={LIGHT_TEXT} fontSize={9}>- 0- </text>- <text x={PLOT_LEFT - 22} y={yOneLabel} fill={LIGHT_TEXT} fontSize={9}>- 1- </text>- </svg>- <div style={coordinatesGrid}>- <div style={coordinateRow}>- <div style={coordinateLabel}>X1</div>- <div style={coordinateInputWrapper}>- <InputDragger- type="number"- value={bezier[0]}- status="ok"- onValueChange={(value) => setCoordinate(0, 'x', value, false)}- onValueChangeEnd={(value) => setCoordinate(0, 'x', value, true)}- onTextChange={() => undefined}- min={0}- max={1}- step={0.01}- formatter={formatNumber}- rightAlign={false}- style={numberInputStyle}- snapToStep={false}- disabled={disabled}+ <div style={segmentedControlWrapper}>+ <SegmentedControl items={modeItems} needsWrapping={false} />+ </div>+ {mode === 'bezier' ? (+ <>+ <svg+ ref={svgRef}+ width={SVG_WIDTH}+ height={SVG_HEIGHT}+ viewBox={`0 0 ${SVG_WIDTH} ${SVG_HEIGHT}`}+ style={svgStyle}+ aria-label="Bezier curve editor"+ >+ <EasingGraphScaffold />+ <line+ x1={startPoint.x}+ y1={startPoint.y}+ x2={firstHandle.x}+ y2={firstHandle.y}+ stroke="rgba(255, 255, 255, 0.35)"+ strokeWidth={1}/>- </div>- </div>- <div style={coordinateRow}>- <div style={coordinateLabel}>Y1</div>- <div style={coordinateInputWrapper}>- <InputDragger- type="number"- value={bezier[1]}- status="ok"- onValueChange={(value) => setCoordinate(0, 'y', value, false)}- onValueChangeEnd={(value) => setCoordinate(0, 'y', value, true)}- onTextChange={() => undefined}- min={Y_MIN}- max={Y_MAX}- step={0.01}- formatter={formatNumber}- rightAlign={false}- style={numberInputStyle}- snapToStep={false}- disabled={disabled}+ <line+ x1={endPoint.x}+ y1={endPoint.y}+ x2={secondHandle.x}+ y2={secondHandle.y}+ stroke="rgba(255, 255, 255, 0.35)"+ strokeWidth={1}/>- </div>- </div>- <div style={coordinateRow}>- <div style={coordinateLabel}>X2</div>- <div style={coordinateInputWrapper}>- <InputDragger- type="number"- value={bezier[2]}- status="ok"- onValueChange={(value) => setCoordinate(1, 'x', value, false)}- onValueChangeEnd={(value) => setCoordinate(1, 'x', value, true)}- onTextChange={() => undefined}- min={0}- max={1}- step={0.01}- formatter={formatNumber}- rightAlign={false}- style={numberInputStyle}- snapToStep={false}- disabled={disabled}+ <path d={bezierPath} fill="none" stroke={BLUE} strokeWidth={3} />+ <circle cx={startPoint.x} cy={startPoint.y} r={4} fill="white" />+ <circle cx={endPoint.x} cy={endPoint.y} r={4} fill="white" />+ <circle+ cx={firstHandle.x}+ cy={firstHandle.y}+ r={6}+ fill="white"+ stroke={BLUE}+ strokeWidth={2}+ vectorEffect="non-scaling-stroke"+ pointerEvents={disabled ? 'none' : 'all'}+ cursor={activeHandle === 0 ? 'grabbing' : 'default'}+ onPointerDown={(event) => onHandlePointerDown(0, event)}/>- </div>- </div>- <div style={coordinateRow}>- <div style={coordinateLabel}>Y2</div>- <div style={coordinateInputWrapper}>- <InputDragger- type="number"- value={bezier[3]}- status="ok"- onValueChange={(value) => setCoordinate(1, 'y', value, false)}- onValueChangeEnd={(value) => setCoordinate(1, 'y', value, true)}- onTextChange={() => undefined}- min={Y_MIN}- max={Y_MAX}- step={0.01}- formatter={formatNumber}- rightAlign={false}- style={numberInputStyle}- snapToStep={false}- disabled={disabled}+ <circle+ cx={secondHandle.x}+ cy={secondHandle.y}+ r={6}+ fill="white"+ stroke={BLUE}+ strokeWidth={2}+ vectorEffect="non-scaling-stroke"+ pointerEvents={disabled ? 'none' : 'all'}+ cursor={activeHandle === 1 ? 'grabbing' : 'default'}+ onPointerDown={(event) => onHandlePointerDown(1, event)}/>+ </svg>+ <div style={coordinatesGrid}>+ <div style={coordinateRow}>+ <div style={coordinateLabel}>X1</div>+ <div style={coordinateInputWrapper}>+ <InputDragger+ type="number"+ value={bezier[0]}+ status="ok"+ onValueChange={(value) => setCoordinate(0, 'x', value, false)}+ onValueChangeEnd={(value) =>+ setCoordinate(0, 'x', value, true)+ }+ onTextChange={() => undefined}+ min={0}+ max={1}+ step={0.01}+ formatter={formatNumber}+ rightAlign={false}+ style={numberInputStyle}+ snapToStep={false}+ disabled={disabled}+ />+ </div>+ </div>+ <div style={coordinateRow}>+ <div style={coordinateLabel}>Y1</div>+ <div style={coordinateInputWrapper}>+ <InputDragger+ type="number"+ value={bezier[1]}+ status="ok"+ onValueChange={(value) => setCoordinate(0, 'y', value, false)}+ onValueChangeEnd={(value) =>+ setCoordinate(0, 'y', value, true)+ }+ onTextChange={() => undefined}+ min={Y_MIN}+ max={Y_MAX}+ step={0.01}+ formatter={formatNumber}+ rightAlign={false}+ style={numberInputStyle}+ snapToStep={false}+ disabled={disabled}+ />+ </div>+ </div>+ <div style={coordinateRow}>+ <div style={coordinateLabel}>X2</div>+ <div style={coordinateInputWrapper}>+ <InputDragger+ type="number"+ value={bezier[2]}+ status="ok"+ onValueChange={(value) => setCoordinate(1, 'x', value, false)}+ onValueChangeEnd={(value) =>+ setCoordinate(1, 'x', value, true)+ }+ onTextChange={() => undefined}+ min={0}+ max={1}+ step={0.01}+ formatter={formatNumber}+ rightAlign={false}+ style={numberInputStyle}+ snapToStep={false}+ disabled={disabled}+ />+ </div>+ </div>+ <div style={coordinateRow}>+ <div style={coordinateLabel}>Y2</div>+ <div style={coordinateInputWrapper}>+ <InputDragger+ type="number"+ value={bezier[3]}+ status="ok"+ onValueChange={(value) => setCoordinate(1, 'y', value, false)}+ onValueChangeEnd={(value) =>+ setCoordinate(1, 'y', value, true)+ }+ onTextChange={() => undefined}+ min={Y_MIN}+ max={Y_MAX}+ step={0.01}+ formatter={formatNumber}+ rightAlign={false}+ style={numberInputStyle}+ snapToStep={false}+ disabled={disabled}+ />+ </div>+ </div></div>- </div>- </div>+ </>+ ) : (+ <>+ <svg+ width={SVG_WIDTH}+ height={SVG_HEIGHT}+ viewBox={`0 0 ${SVG_WIDTH} ${SVG_HEIGHT}`}+ style={svgStyle}+ aria-label="Spring easing curve"+ >+ <EasingGraphScaffold />+ <path d={springPath} fill="none" stroke={BLUE} strokeWidth={3} />+ <circle cx={xToSvg(0)} cy={yToSvg(0)} r={4} fill="white" />+ <circle cx={xToSvg(1)} cy={yToSvg(1)} r={4} fill="white" />+ </svg>+ <div style={coordinatesGrid}>+ <div style={coordinateRow}>+ <div style={coordinateLabel}>Damping</div>+ <div style={coordinateInputWrapper}>+ <InputDragger+ type="number"+ value={spring.damping}+ status="ok"+ onValueChange={(value) =>+ setSpringNumber('damping', value, false)+ }+ onValueChangeEnd={(value) =>+ setSpringNumber('damping', value, true)+ }+ onTextChange={() => undefined}+ min={SPRING_LIMITS.damping.min}+ max={SPRING_LIMITS.damping.max}+ step={SPRING_LIMITS.damping.step}+ formatter={springFormatters.damping}+ rightAlign={false}+ style={numberInputStyle}+ snapToStep={false}+ dragDecimalPlaces={SPRING_DECIMAL_PLACES.damping}+ disabled={disabled}+ />+ </div>+ </div>+ <div style={coordinateRow}>+ <div style={coordinateLabel}>Mass</div>+ <div style={coordinateInputWrapper}>+ <InputDragger+ type="number"+ value={spring.mass}+ status="ok"+ onValueChange={(value) =>+ setSpringNumber('mass', value, false)+ }+ onValueChangeEnd={(value) =>+ setSpringNumber('mass', value, true)+ }+ onTextChange={() => undefined}+ min={SPRING_LIMITS.mass.min}+ max={SPRING_LIMITS.mass.max}+ step={SPRING_LIMITS.mass.step}+ formatter={springFormatters.mass}+ rightAlign={false}+ style={numberInputStyle}+ snapToStep={false}+ dragDecimalPlaces={SPRING_DECIMAL_PLACES.mass}+ disabled={disabled}+ />+ </div>+ </div>+ <div style={coordinateRow}>+ <div style={coordinateLabel}>Stiffness</div>+ <div style={coordinateInputWrapper}>+ <InputDragger+ type="number"+ value={spring.stiffness}+ status="ok"+ onValueChange={(value) =>+ setSpringNumber('stiffness', value, false)+ }+ onValueChangeEnd={(value) =>+ setSpringNumber('stiffness', value, true)+ }+ onTextChange={() => undefined}+ min={SPRING_LIMITS.stiffness.min}+ max={SPRING_LIMITS.stiffness.max}+ step={SPRING_LIMITS.stiffness.step}+ formatter={springFormatters.stiffness}+ rightAlign={false}+ style={numberInputStyle}+ snapToStep={false}+ dragDecimalPlaces={SPRING_DECIMAL_PLACES.stiffness}+ disabled={disabled}+ />+ </div>+ </div>+ <div style={coordinateRow}>+ <div style={coordinateLabel}>Clamp overshoot</div>+ <div style={checkboxWrapper}>+ <Checkbox+ checked={spring.overshootClamping}+ onChange={setOvershootClamping}+ name="spring-overshoot-clamping"+ disabled={disabled}+ variant="small"+ />+ </div>+ </div>+ </div>+ </>+ )}</div>);};diff --git a/packages/studio/src/components/Timeline/TimelineDeleteKeybindings.tsx b/packages/studio/src/components/Timeline/TimelineDeleteKeybindings.tsxindex 0bcfa1dafe..9c52219a2b 100644--- a/packages/studio/src/components/Timeline/TimelineDeleteKeybindings.tsx+++ b/packages/studio/src/components/Timeline/TimelineDeleteKeybindings.tsx@@ -1,3 +1,4 @@+import {LINEAR_KEYFRAME_EASING} from '@remotion/studio-shared';import type React from 'react';import {useContext, useEffect} from 'react';import {Internals} from 'remotion';@@ -92,7 +93,7 @@ export const TimelineDeleteKeybindings: React.FC = () => {propStatuses,setPropStatuses,clientId,- easing: 'linear',+ easing: LINEAR_KEYFRAME_EASING,});if (resetEasingPromise !== null) {diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsxindex 43fae1fc0f..e88a74a66d 100644--- a/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsx+++ b/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsx@@ -1,4 +1,7 @@-import {KEYFRAME_EASING_PRESETS} from '@remotion/studio-shared';+import {+ KEYFRAME_EASING_PRESETS,+ LINEAR_KEYFRAME_EASING,+} from '@remotion/studio-shared';import React, {useCallback, useContext, useMemo, useRef} from 'react';import {Internals, useVideoConfig} from 'remotion';import {StudioServerConnectionCtx} from '../../helpers/client-id';@@ -117,7 +120,7 @@ const TimelineKeyframeEasingLineUnmemoized: React.FC<{label: 'Linear',leftItem: null,disabled: previewServerState.type !== 'connected',- onClick: () => updateEasing('linear'),+ onClick: () => updateEasing(LINEAR_KEYFRAME_EASING),quickSwitcherLabel: null,subMenu: null,value: 'linear',diff --git a/packages/studio/src/components/Timeline/update-selected-easing.ts b/packages/studio/src/components/Timeline/update-selected-easing.tsindex 6b61cac07d..8da20f3604 100644--- a/packages/studio/src/components/Timeline/update-selected-easing.ts+++ b/packages/studio/src/components/Timeline/update-selected-easing.ts@@ -1,5 +1,7 @@+import {LINEAR_KEYFRAME_EASING} from '@remotion/studio-shared';import type {CanUpdateSequencePropStatusKeyframed,+ CanUpdateSequencePropStatusEasing,DragOverrideValue,OverrideIdToNodePaths,PropStatuses,@@ -21,7 +23,7 @@ import type {} from './TimelineSelection';export type EasingSelection = TimelineEasingSelection;-export type TimelineEasingValue = 'linear' | [number, number, number, number];+export type TimelineEasingValue = CanUpdateSequencePropStatusEasing;export type SelectedEasingUpdate =| {readonly type: 'sequence';@@ -112,7 +114,8 @@ export const getSelectedEasingUpdate = ({schema: sequence.controls.schema,segmentIndex: selection.segmentIndex,currentEasing:- sequencePropStatus.easing[selection.segmentIndex] ?? 'linear',+ sequencePropStatus.easing[selection.segmentIndex] ??+ LINEAR_KEYFRAME_EASING,propStatus: sequencePropStatus,};}@@ -148,7 +151,8 @@ export const getSelectedEasingUpdate = ({fieldKey: field.fieldKey,schema: effect.schema,segmentIndex: selection.segmentIndex,- currentEasing: effectPropStatus.easing[selection.segmentIndex] ?? 'linear',+ currentEasing:+ effectPropStatus.easing[selection.segmentIndex] ?? LINEAR_KEYFRAME_EASING,propStatus: effectPropStatus,};};@@ -187,7 +191,7 @@ export const makeEasingDragOverride = ({}): DragOverrideValue => {const nextEasing = [...status.easing];while (nextEasing.length < status.keyframes.length - 1) {- nextEasing.push('linear');+ nextEasing.push(LINEAR_KEYFRAME_EASING);}if (nextEasing.length > status.keyframes.length - 1) {diff --git a/packages/studio/src/test/timeline-keyframes.test.ts b/packages/studio/src/test/timeline-keyframes.test.tsindex e66df64c80..ad401ee5df 100644--- a/packages/studio/src/test/timeline-keyframes.test.ts+++ b/packages/studio/src/test/timeline-keyframes.test.ts@@ -79,7 +79,7 @@ const makeKeyframedStatus = (): CanUpdateSequencePropStatusKeyframed => ({{frame: 0, value: 2},{frame: 60, value: 4},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,});@@ -220,7 +220,7 @@ test('keyframe display offsets follow the parent sequence context', () => {{frame: 0, value: 2},{frame: 60, value: 4},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -240,7 +240,7 @@ test('timeline easing segments connect adjacent display keyframes', () => {{frame: 30, value: 3},{frame: 60, value: 4},],- easing: ['linear', 'linear'],+ easing: [{type: 'linear'}, {type: 'linear'}],};expect(getTimelineEasingSegments(getTimelineKeyframes(status, 30))).toEqual([diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.tsindex 60039621e5..afad47647a 100644--- a/packages/studio/src/test/timeline-selection.test.ts+++ b/packages/studio/src/test/timeline-selection.test.ts@@ -523,7 +523,7 @@ test('copying a keyframed effect creates a structured snapshot', () => {{frame: 0, value: 10},{frame: 100, value: 20},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},posterize: undefined,},@@ -554,7 +554,7 @@ test('copying a keyframed effect creates a structured snapshot', () => {{frame: 0, value: 10},{frame: 100, value: 20},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},},},@@ -588,7 +588,7 @@ test('copying a selected effect prop creates an effect prop payload', () => {{frame: 0, value: 10},{frame: 100, value: 20},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},posterize: undefined,},@@ -624,7 +624,7 @@ test('copying a selected effect prop creates an effect prop payload', () => {{frame: 0, value: 10},{frame: 100, value: 20},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},},});@@ -937,7 +937,7 @@ test('Timeline duration drag is blocked if one selected sequence duration is keystatus: 'keyframed',interpolationFunction: 'interpolate',keyframes: [{frame: 0, value: 15}],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'clamp', right: 'clamp'},posterize: undefined,},@@ -1930,7 +1930,7 @@ test('UV handles are requested for keyframed selected effect props', () => {{frame: 0, value: [0, 0]},{frame: 100, value: [1, 1]},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -2127,7 +2127,7 @@ test('Backspace reset targets selected keyframed sequence props', () => {{frame: 0, value: 0},{frame: 20, value: 0.5},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -2275,7 +2275,7 @@ test('Backspace reset skips keyframed sequence props without defaults', () => {{frame: 0, value: 0},{frame: 20, value: 0.5},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -2562,7 +2562,7 @@ test('Selected outline dragging keyframed translate adds a keyframe at the sourc{frame: 0, value: '0px 0px'},{frame: 40, value: '100px 50px'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -2862,7 +2862,7 @@ test('Selected outline corner dragging keyframed rotation adds a keyframe at the{frame: 0, value: '0deg'},{frame: 40, value: '90deg'},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -3159,7 +3159,7 @@ test('Backspace reset targets selected keyframed effect props', () => {{frame: 0, value: 10},{frame: 20, value: 20},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},@@ -3230,7 +3230,7 @@ test('Backspace reset skips keyframed effect props without defaults', () => {{frame: 0, value: 10},{frame: 20, value: 20},],- easing: ['linear'],+ easing: [{type: 'linear'}],clamping: {left: 'extend', right: 'extend'},posterize: undefined,},