🎥 Make videos programmatically with React
`@remotion/canvas`: Add `getCanvasKeyframeEasingChange()` and `getCanvasKeyframeSettingsChange()` for editing easings and interpolation settings outside the Studio
JonnyBurger9a95c9ed7870
diff --git a/packages/canvas/src/canvas-internals.ts b/packages/canvas/src/canvas-internals.tsindex e543f673d3..dc93ab2444 100644--- a/packages/canvas/src/canvas-internals.ts+++ b/packages/canvas/src/canvas-internals.ts@@ -118,6 +118,13 @@ export {getMovedCanvasKeyframeStatus,} from './keyframe-move';export type {CanvasKeyframeMoveTarget} from './keyframe-move';+export {getSchemaField} from './keyframes';+export {+ canEditKeyframeEasing,+ getKeyframeSegmentEasing,+ getKeyframeSegments,+} from './keyframe-easing';+export type {KeyframeSegment} from './keyframe-easing';export {canvasOutlineSnapThresholdPx,findCanvasOutlineSnap,diff --git a/packages/canvas/src/index.ts b/packages/canvas/src/index.tsindex 8a789872ff..d1d72a3892 100644--- a/packages/canvas/src/index.ts+++ b/packages/canvas/src/index.ts@@ -52,11 +52,28 @@ export {export type {CanvasKeyframe,CanvasKeyframeChange,+ CanvasKeyframeClamping,+ CanvasKeyframeEasing,CanvasKeyframeOperation,CanvasKeyframeToggle,CanvasKeyframeTrack,} from './keyframes';export type {CanvasKeyframeMove} from './keyframe-move';+export {+ canvasKeyframeEasingPresets,+ getCanvasKeyframeEasingChange,+ getCanvasKeyframeEasingSegments,+} from './keyframe-easing';+export type {+ CanvasKeyframeEasingPreset,+ CanvasKeyframeEasingSegment,+} from './keyframe-easing';+export {+ getCanvasKeyframeSettings,+ getCanvasKeyframeSettingsChange,+} from './keyframe-settings';+export type {CanvasKeyframeSettings} from './keyframe-settings';+export {getCanvasKeyframeChangeOverride} from './keyframe-override';export {startCanvasKeyframeDrag} from './keyframe-drag';export type {CanvasKeyframeDragEnd,diff --git a/packages/canvas/src/keyframe-easing.ts b/packages/canvas/src/keyframe-easing.tsnew file mode 100644index 0000000000..9dddc243fe--- /dev/null+++ b/packages/canvas/src/keyframe-easing.ts@@ -0,0 +1,163 @@+import {+ canEditEasingForInterpolationFunction,+ isInteractivitySchemaFieldHoldOnly,+ KEYFRAME_EASING_PRESETS,+ LINEAR_KEYFRAME_EASING,+} from '@remotion/studio-shared';+import type {+ CanUpdateSequencePropStatus,+ CanUpdateSequencePropStatusKeyframed,+ InteractivitySchema,+ InteractivitySchemaField,+} from 'remotion';+import type {SequenceNodePathInfo} from './get-timeline-sequence-sort-key';+import type {+ CanvasKeyframe,+ CanvasKeyframeChange,+ CanvasKeyframeEasing,+ CanvasKeyframeOperation,+ CanvasKeyframeTrack,+} from './keyframes';+import {getCanvasKeyframes, getSchemaField} from './keyframes';++export type CanvasKeyframeEasingPreset = {+ readonly id: string;+ readonly label: string;+ readonly easing: CanvasKeyframeEasing;+};++/** The easing presets of the Remotion Studio, starting with linear. */+export const canvasKeyframeEasingPresets: readonly CanvasKeyframeEasingPreset[] =+ [+ {id: 'linear', label: 'Linear', easing: LINEAR_KEYFRAME_EASING},+ ...KEYFRAME_EASING_PRESETS,+ ];++/** The span between two adjacent keyframes of a prop, in composition frames. */+export type KeyframeSegment = {+ /** Indexes the `easing` of the prop; the segment after the first keyframe has index 0. */+ readonly segmentIndex: number;+ /** The composition frame of the keyframe that starts the segment. */+ readonly fromFrame: number;+ /** The composition frame of the keyframe that ends the segment. */+ readonly toFrame: number;+};++/** The segment between two adjacent keyframes of a prop, on the composition timeline. */+export type CanvasKeyframeEasingSegment = KeyframeSegment & {+ /** The easing of the segment; linear when the source does not set one. */+ readonly easing: CanvasKeyframeEasing;+};++/** Pairs adjacent keyframes into the segments between them. */+export const getKeyframeSegments = (+ keyframes: readonly CanvasKeyframe[],+): KeyframeSegment[] => {+ return keyframes.flatMap((keyframe, index): KeyframeSegment[] => {+ const nextKeyframe = keyframes[index + 1];+ if (!nextKeyframe) {+ return [];+ }++ return [+ {+ segmentIndex: index,+ fromFrame: keyframe.frame,+ toFrame: nextKeyframe.frame,+ },+ ];+ });+};++/** The easing of a segment; linear when the source does not set one. */+export const getKeyframeSegmentEasing = (+ propStatus: CanUpdateSequencePropStatusKeyframed,+ segmentIndex: number,+): CanvasKeyframeEasing =>+ propStatus.easing[segmentIndex] ?? LINEAR_KEYFRAME_EASING;++/**+ * Whether the easing between the keyframes of a prop can be edited. Boolean,+ * enum and integer fields hold their value until the next keyframe, and the+ * interpolation function must accept an easing.+ */+export const canEditKeyframeEasing = ({+ field,+ propStatus,+}: {+ readonly field: InteractivitySchemaField | undefined;+ readonly propStatus: CanUpdateSequencePropStatus | null | undefined;+}): boolean =>+ propStatus?.status === 'keyframed' &&+ !isInteractivitySchemaFieldHoldOnly(field) &&+ canEditEasingForInterpolationFunction(propStatus.interpolationFunction);++/**+ * The segments between the keyframes of a prop, placed on the composition+ * timeline. Empty when the easing of the prop cannot be edited.+ */+export const getCanvasKeyframeEasingSegments = ({+ track,+ schema,+ key,+ propStatus,+}: {+ readonly track: CanvasKeyframeTrack;+ readonly schema: InteractivitySchema;+ readonly key: string;+ readonly propStatus: CanUpdateSequencePropStatus | null;+}): CanvasKeyframeEasingSegment[] => {+ if (+ propStatus?.status !== 'keyframed' ||+ !canEditKeyframeEasing({field: getSchemaField(schema, key), propStatus})+ ) {+ return [];+ }++ return getKeyframeSegments(getCanvasKeyframes({track, propStatus})).map(+ (segment) => ({+ ...segment,+ easing: getKeyframeSegmentEasing(propStatus, segment.segmentIndex),+ }),+ );+};++/**+ * The change that sets the easing of the segment between two adjacent+ * keyframes. `null` when the easing of the prop cannot be edited or the+ * segment does not exist.+ */+export const getCanvasKeyframeEasingChange = ({+ nodePathInfo,+ schema,+ key,+ propStatus,+ segmentIndex,+ easing,+}: {+ readonly nodePathInfo: SequenceNodePathInfo;+ readonly schema: InteractivitySchema;+ readonly key: string;+ readonly propStatus: CanUpdateSequencePropStatus;+ readonly segmentIndex: number;+ readonly easing: CanvasKeyframeEasing;+}): CanvasKeyframeChange<+ Extract<CanvasKeyframeOperation, {readonly type: 'easing'}>+> | null => {+ if (+ propStatus.status !== 'keyframed' ||+ !canEditKeyframeEasing({field: getSchemaField(schema, key), propStatus}) ||+ !Number.isInteger(segmentIndex) ||+ segmentIndex < 0 ||+ segmentIndex >= propStatus.keyframes.length - 1+ ) {+ return null;+ }++ return {+ nodePathInfo,+ key,+ schema,+ operation: {type: 'easing', segmentIndex, easing},+ };+};diff --git a/packages/canvas/src/keyframe-override.ts b/packages/canvas/src/keyframe-override.tsnew file mode 100644index 0000000000..b1c226c958--- /dev/null+++ b/packages/canvas/src/keyframe-override.ts@@ -0,0 +1,75 @@+import {+ addKeyframeToPropStatus,+ applyKeyframeSettingsToStatus,+ moveKeyframesInPropStatus,+ removeKeyframeFromPropStatus,+} from '@remotion/studio-shared';+import type {CanUpdateSequencePropStatus, DragOverrideValue} from 'remotion';+import type {CanvasKeyframeChange} from './keyframes';++/**+ * Shows a keyframe change on the canvas before the source is updated: how the+ * prop is written after the operation, for `controller.overrides.set()`.+ * `null` when the operation does not apply to the prop, for example an+ * easing of a prop that is not keyframed.+ */+export const getCanvasKeyframeChangeOverride = ({+ propStatus,+ change,+}: {+ readonly propStatus: CanUpdateSequencePropStatus;+ readonly change: CanvasKeyframeChange;+}): DragOverrideValue | null => {+ const {operation} = change;+ if (operation.type === 'add') {+ const status = addKeyframeToPropStatus({+ status: propStatus,+ fieldKey: change.key,+ frame: operation.frame,+ value: operation.value,+ schema: change.schema,+ });+ return status.status === 'keyframed' ? {type: 'keyframed', status} : null;+ }++ if (propStatus.status !== 'keyframed') {+ return null;+ }++ switch (operation.type) {+ case 'remove': {+ const status = removeKeyframeFromPropStatus({+ status: propStatus,+ frame: operation.frame,+ valueWhenLastKeyframeDeleted: operation.valueWhenLastKeyframeDeleted,+ });+ if (status.status === 'keyframed') {+ return {type: 'keyframed', status};+ }++ return status.status === 'static'+ ? {type: 'static', value: status.codeValue}+ : null;+ }++ case 'move': {+ const status = moveKeyframesInPropStatus({+ status: propStatus,+ moves: operation.moves,+ });+ return status.status === 'keyframed' ? {type: 'keyframed', status} : null;+ }++ case 'easing':+ case 'settings':+ return {+ type: 'keyframed',+ status: applyKeyframeSettingsToStatus(propStatus, operation),+ };++ default:+ throw new Error(+ `Unexpected keyframe operation: ${JSON.stringify(operation satisfies never)}`,+ );+ }+};diff --git a/packages/canvas/src/keyframe-settings.ts b/packages/canvas/src/keyframe-settings.tsnew file mode 100644index 0000000000..cc05f24fe4--- /dev/null+++ b/packages/canvas/src/keyframe-settings.ts@@ -0,0 +1,104 @@+import type {+ CanUpdateSequencePropStatusKeyframed,+ ExtrapolateType,+ InteractivitySchema,+ InterpolateOutputOption,+} from 'remotion';+import type {SequenceNodePathInfo} from './get-timeline-sequence-sort-key';+import type {+ CanvasKeyframeChange,+ CanvasKeyframeClamping,+ CanvasKeyframeOperation,+} from './keyframes';++/** The interpolation options of a keyframed prop that an editor can change. */+export type CanvasKeyframeSettings = {+ /**+ * How the prop extrapolates before the first and after the last keyframe.+ * `null` when the interpolation function has no extrapolation options, as+ * `interpolateColors()` does not.+ */+ readonly clamping: CanvasKeyframeClamping | null;+ /**+ * The extrapolation types the prop accepts; `interpolatePaths()` cannot use+ * `identity`. Empty when `clamping` is `null`.+ */+ readonly extrapolateTypes: readonly ExtrapolateType[];+ /** Samples the animation every `posterize` frames; `null` when the value changes on every frame. */+ readonly posterize: number | null;+ /**+ * How the eased progress maps to the values. `null` when the interpolation+ * function has no output modes; only `interpolate()` has them.+ */+ readonly output: InterpolateOutputOption | null;+};++const extrapolateTypes = [+ 'extend',+ 'clamp',+ 'identity',+ 'wrap',+] as const satisfies readonly ExtrapolateType[];++/** Reads the interpolation options of a keyframed prop. */+export const getCanvasKeyframeSettings = (+ propStatus: CanUpdateSequencePropStatusKeyframed,+): CanvasKeyframeSettings => {+ const {interpolationFunction} = propStatus;+ const hasClamping =+ interpolationFunction === 'interpolate' ||+ interpolationFunction === 'interpolatePaths';+ const hasOutput = interpolationFunction === 'interpolate';++ return {+ clamping: hasClamping ? propStatus.clamping : null,+ extrapolateTypes: hasClamping+ ? extrapolateTypes.filter((type) => hasOutput || type !== 'identity')+ : [],+ posterize: propStatus.posterize ?? null,+ output: hasOutput ? (propStatus.output ?? 'linear') : null,+ };+};++/**+ * The change that writes the interpolation options of a keyframed prop. Pass+ * the settings of `getCanvasKeyframeSettings()` with the values you changed.+ */+export const getCanvasKeyframeSettingsChange = ({+ nodePathInfo,+ schema,+ key,+ propStatus,+ settings,+}: {+ readonly nodePathInfo: SequenceNodePathInfo;+ readonly schema: InteractivitySchema;+ readonly key: string;+ readonly propStatus: CanUpdateSequencePropStatusKeyframed;+ readonly settings: CanvasKeyframeSettings;+}): CanvasKeyframeChange<+ Extract<CanvasKeyframeOperation, {readonly type: 'settings'}>+> => {+ const current = getCanvasKeyframeSettings(propStatus);++ return {+ nodePathInfo,+ key,+ schema,+ operation: {+ type: 'settings',+ clamping:+ current.clamping === null+ ? undefined+ : (settings.clamping ?? current.clamping),+ posterize:+ settings.posterize === null || settings.posterize <= 0+ ? undefined+ : settings.posterize,+ output:+ current.output === null+ ? undefined+ : (settings.output ?? current.output),+ },+ };+};diff --git a/packages/canvas/src/keyframes.ts b/packages/canvas/src/keyframes.tsindex 93178d7232..ead48c97a4 100644--- a/packages/canvas/src/keyframes.ts+++ b/packages/canvas/src/keyframes.ts@@ -1,4 +1,11 @@-import type {CanUpdateSequencePropStatus, InteractivitySchema} from 'remotion';+import type {+ CanUpdateSequencePropStatus,+ CanUpdateSequencePropStatusEasing,+ ExtrapolateType,+ InteractivitySchema,+ InteractivitySchemaField,+ InterpolateOutputOption,+} from 'remotion';import {Internals} from 'remotion';import type {SequenceNodePathInfo,@@ -34,6 +41,15 @@ export type CanvasKeyframe = {readonly value: unknown;};+/** The easing between two adjacent keyframes, as `interpolate()` accepts it. */+export type CanvasKeyframeEasing = CanUpdateSequencePropStatusEasing;++/** The `extrapolateLeft` and `extrapolateRight` options of an interpolation. */+export type CanvasKeyframeClamping = {+ readonly left: ExtrapolateType;+ readonly right: ExtrapolateType;+};+/*** An edit of the keyframes of one prop. The frames are in the clock of the* interpolation, as `updateNodeKeyframes()` from @remotion/codemods expects.@@ -54,16 +70,31 @@ export type CanvasKeyframeOperation =| {readonly type: 'move';readonly moves: CanvasKeyframeMove[];+ }+ | {+ /** Sets the easing of the segment between two adjacent keyframes. */+ readonly type: 'easing';+ readonly segmentIndex: number;+ readonly easing: CanvasKeyframeEasing;+ }+ | {+ /** Writes the interpolation options. `undefined` leaves `clamping` and `output` unchanged and removes `posterize`. */+ readonly type: 'settings';+ readonly clamping: CanvasKeyframeClamping | undefined;+ readonly posterize: number | undefined;+ readonly output: InterpolateOutputOption | undefined;};-export type CanvasKeyframeChange = {+export type CanvasKeyframeChange<+ Operation extends CanvasKeyframeOperation = CanvasKeyframeOperation,+> = {/** The registered source node of the sequence. */readonly nodePathInfo: SequenceNodePathInfo;/** The interactivity schema key in dot notation, e.g. `style.opacity`. */readonly key: string;/** The interactivity schema of the element, for the codemods. */readonly schema: InteractivitySchema;- readonly operation: CanvasKeyframeOperation;+ readonly operation: Operation;};/** The keyframes of a prop, placed on the composition timeline. */@@ -127,11 +158,18 @@ export const getCanvasKeyframeDisplayFrame = ({);};+/** The schema field of a key in dot notation, including fields of enum variants. */+export const getSchemaField = (+ schema: InteractivitySchema,+ key: string,+): InteractivitySchemaField | undefined =>+ Internals.getFlatSchemaWithAllKeys(schema)[key];+const getSchemaFieldDefault = (schema: InteractivitySchema,key: string,): unknown => {- const field = Internals.getFlatSchemaWithAllKeys(schema)[key];+ const field = getSchemaField(schema, key);return field !== undefined && 'default' in field ? field.default : undefined;};diff --git a/packages/canvas/src/test/keyframe-easing.test.ts b/packages/canvas/src/test/keyframe-easing.test.tsnew file mode 100644index 0000000000..a1b832d69f--- /dev/null+++ b/packages/canvas/src/test/keyframe-easing.test.ts@@ -0,0 +1,26 @@+import {expect, test} from 'bun:test';+import type {CanUpdateSequencePropStatusKeyframed} from 'remotion';+import {getKeyframeSegments} from '../keyframe-easing';+import {getTimelineKeyframes} from '../keyframe-frames';++test('easing segments connect adjacent display keyframes', () => {+ const status: CanUpdateSequencePropStatusKeyframed = {+ status: 'keyframed',+ keyframeDisplayOffsetAdjustment: null,+ interpolationFunction: 'interpolate',+ keyframes: [+ {frame: 0, value: 2},+ {frame: 30, value: 3},+ {frame: 60, value: 4},+ ],+ easing: [{type: 'linear'}, {type: 'linear'}],+ clamping: {left: 'extend', right: 'extend'},+ posterize: undefined,+ output: undefined,+ };++ expect(getKeyframeSegments(getTimelineKeyframes(status, 30))).toEqual([+ {segmentIndex: 0, fromFrame: 30, toFrame: 60},+ {segmentIndex: 1, fromFrame: 60, toFrame: 90},+ ]);+});diff --git a/packages/docs/docs/canvas/create-canvas-controller.mdx b/packages/docs/docs/canvas/create-canvas-controller.mdxindex 2d17ae0470..8d89069ae8 100644--- a/packages/docs/docs/canvas/create-canvas-controller.mdx+++ b/packages/docs/docs/canvas/create-canvas-controller.mdx@@ -72,7 +72,7 @@ Passing an unchanged mapping is a no-op, so the function may be called from a `tPreview prop values on mounted sequences without changing the source. Overrides are applied to sequences that have a `nodePathInfo`, so register node paths first. They are kept while the composition stays mounted and are not persisted; write the final value to the source, for example with [`updateNodeProps()`](/docs/codemods/update-node-props), and clear the override once the update has been applied.-The Canvas sets overrides itself while an outline is being [moved](/docs/canvas/canvas#onsequencepropschange), and [`startCanvasKeyframeDrag()`](/docs/canvas/start-canvas-keyframe-drag) sets them while keyframes are dragged. Both leave them in place for you to clear after persisting.+The Canvas sets overrides itself while an outline is being [moved](/docs/canvas/canvas#onsequencepropschange), and [`startCanvasKeyframeDrag()`](/docs/canvas/start-canvas-keyframe-drag) sets them while keyframes are dragged. Both leave them in place for you to clear after persisting. [`getCanvasKeyframeChangeOverride()`](/docs/canvas/get-canvas-keyframe-change-override) computes the value that previews any other keyframe change, such as a new easing.#### set()diff --git a/packages/docs/docs/canvas/get-canvas-keyframe-change-override.mdx b/packages/docs/docs/canvas/get-canvas-keyframe-change-override.mdxnew file mode 100644index 0000000000..f0dab61498--- /dev/null+++ b/packages/docs/docs/canvas/get-canvas-keyframe-change-override.mdx@@ -0,0 +1,66 @@+---+image: /generated/articles-docs-canvas-get-canvas-keyframe-change-override.png+title: getCanvasKeyframeChangeOverride()+crumb: '@remotion/canvas'+---++# getCanvasKeyframeChangeOverride()<AvailableFrom v="4.0.530" />++Shows a keyframe change on the canvas before the source is updated. It returns how the prop is written after the change, as a value for [`controller.overrides`](/docs/canvas/create-canvas-controller#overrides). Use it to preview an easing while its curve is being dragged, or to apply a preset without waiting for the bundler.++:::warning++_Experimental API_: This package is not stable. Its public API may change without a major version bump.++:::++```tsx twoslash title="apply-change.ts"+// @moduleResolution: bundler+import {+ getCanvasKeyframeChangeOverride,+ type CanvasController,+ type CanvasKeyframeChange,+} from '@remotion/canvas';+import type {CanUpdateSequencePropStatus} from 'remotion';+declare const controller: CanvasController;+declare const propStatus: CanUpdateSequencePropStatus;+declare const persist: (change: CanvasKeyframeChange) => Promise<void>;+// ---cut---+export const applyChange = async (change: CanvasKeyframeChange) => {+ const override = getCanvasKeyframeChangeOverride({propStatus, change});+ if (override) {+ controller.overrides.set(change.nodePathInfo, change.key, override);+ }++ await persist(change);+ controller.overrides.clear(change.nodePathInfo);+};+```++Clear the override once the composition renders the updated source. Until then, the canvas shows the change even though the source has not caught up, like after [`startCanvasKeyframeDrag()`](/docs/canvas/start-canvas-keyframe-drag).++## Parameters++An object with the following properties:++### propStatus++How the prop is written in the source before the change, as the `props` of [`getNodeProps()`](/docs/codemods/get-node-props) report it.++### change++The `CanvasKeyframeChange` to preview, from [`getCanvasKeyframeEasingChange()`](/docs/canvas/get-canvas-keyframe-easing-change), [`getCanvasKeyframeSettingsChange()`](/docs/canvas/get-canvas-keyframe-settings-change), [`getCanvasKeyframeToggle()`](/docs/canvas/get-canvas-keyframe-toggle) or [`startCanvasKeyframeDrag()`](/docs/canvas/start-canvas-keyframe-drag). Every operation is supported: `add`, `remove`, `move`, `easing` and `settings`.++## Return value++A `DragOverrideValue`: `{type: 'keyframed', status}` with the keyframed status after the operation, or `{type: 'static', value}` when removing the last keyframe leaves a static prop. `null` when the operation does not apply to the prop, for example an `easing` of a prop that is not keyframed.++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering player studio="" hideServers />++## See also++- [`controller.overrides`](/docs/canvas/create-canvas-controller#overrides)+- [`getCanvasKeyframeEasingChange()`](/docs/canvas/get-canvas-keyframe-easing-change)+- [`getCanvasKeyframeSettingsChange()`](/docs/canvas/get-canvas-keyframe-settings-change)diff --git a/packages/docs/docs/canvas/get-canvas-keyframe-easing-change.mdx b/packages/docs/docs/canvas/get-canvas-keyframe-easing-change.mdxnew file mode 100644index 0000000000..e3ca556fe3--- /dev/null+++ b/packages/docs/docs/canvas/get-canvas-keyframe-easing-change.mdx@@ -0,0 +1,107 @@+---+image: /generated/articles-docs-canvas-get-canvas-keyframe-easing-change.png+title: getCanvasKeyframeEasingChange()+crumb: '@remotion/canvas'+---++# getCanvasKeyframeEasingChange()<AvailableFrom v="4.0.530" />++Returns the change that sets the easing between two adjacent keyframes of a prop. Use it to build an easing picker for a selected segment.++:::warning++_Experimental API_: This package is not stable. Its public API may change without a major version bump.++:::++```tsx twoslash title="EasingPicker.tsx"+// @moduleResolution: bundler+import {+ canvasKeyframeEasingPresets,+ getCanvasKeyframeEasingChange,+ type CanvasKeyframeChange,+ type SequenceNodePathInfo,+} from '@remotion/canvas';+import type {CanUpdateSequencePropStatus, InteractivitySchema} from 'remotion';+declare const nodePathInfo: SequenceNodePathInfo;+declare const schema: InteractivitySchema;+declare const propStatus: CanUpdateSequencePropStatus;+declare const segmentIndex: number;+declare const persist: (change: CanvasKeyframeChange) => void;+// ---cut---+export const EasingPicker = () => {+ return (+ <>+ {canvasKeyframeEasingPresets.map((preset) => (+ <button+ key={preset.id}+ onClick={() => {+ const change = getCanvasKeyframeEasingChange({+ nodePathInfo,+ schema,+ key: 'style.opacity',+ propStatus,+ segmentIndex,+ easing: preset.easing,+ });+ if (change) {+ persist(change);+ }+ }}+ >+ {preset.label}+ </button>+ ))}+ </>+ );+};+```++## Parameters++An object with the following properties:++### nodePathInfo++The `SequenceNodePathInfo` of the sequence, from a track or a selection item. It is passed through to the returned change.++### schema++The interactivity schema of the element, from [`track.sequence.controls`](/docs/canvas/create-canvas-controller#sequencecontrols).++### key++The schema key of the prop in dot notation, for example `'style.opacity'`.++### propStatus++How the prop is written in the source, as the `props` of [`getNodeProps()`](/docs/codemods/get-node-props) report it.++### segmentIndex++The segment to change, as reported by [`getCanvasKeyframeEasingSegments()`](/docs/canvas/get-canvas-keyframe-easing-segments).++### easing++The new `CanvasKeyframeEasing`: `{type: 'linear'}`, `{type: 'step1'}` for a hold until the next keyframe, `{type: 'bezier', x1, y1, x2, y2}` or `{type: 'spring', damping, mass, stiffness, overshootClamping, allowTail, durationRestThreshold}`. They are written as [`Easing.linear`](/docs/easing), `Easing.step1`, `Easing.bezier()` and `Easing.spring()`.++## Return value++A `CanvasKeyframeChange` whose `operation` is `{type: 'easing', segmentIndex, easing}`, or `null` when the prop is not keyframed, its easing cannot be edited or the segment does not exist. Persist it with [`updateNodeKeyframes()`](/docs/codemods/update-node-keyframes) like the changes of [`getCanvasKeyframeToggle()`](/docs/canvas/get-canvas-keyframe-toggle#change).++To show the easing on the canvas before the source is updated, for example while a bezier handle is being dragged, pass the change to [`getCanvasKeyframeChangeOverride()`](/docs/canvas/get-canvas-keyframe-change-override).++## Presets++`canvasKeyframeEasingPresets` lists the easings the [Remotion Studio](/docs/studio) offers, starting with linear: ease in, ease out, ease in-out, hold and three springs. Each `CanvasKeyframeEasingPreset` has an `id`, a `label` and an `easing`.++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering player studio="" hideServers />++## See also++- [`getCanvasKeyframeEasingSegments()`](/docs/canvas/get-canvas-keyframe-easing-segments)+- [`getCanvasKeyframeChangeOverride()`](/docs/canvas/get-canvas-keyframe-change-override)+- [`getCanvasKeyframeSettingsChange()`](/docs/canvas/get-canvas-keyframe-settings-change)+- [`updateNodeKeyframes()`](/docs/codemods/update-node-keyframes)diff --git a/packages/docs/docs/canvas/get-canvas-keyframe-easing-segments.mdx b/packages/docs/docs/canvas/get-canvas-keyframe-easing-segments.mdxnew file mode 100644index 0000000000..9d72b5ce08--- /dev/null+++ b/packages/docs/docs/canvas/get-canvas-keyframe-easing-segments.mdx@@ -0,0 +1,107 @@+---+image: /generated/articles-docs-canvas-get-canvas-keyframe-easing-segments.png+title: getCanvasKeyframeEasingSegments()+crumb: '@remotion/canvas'+---++# getCanvasKeyframeEasingSegments()<AvailableFrom v="4.0.530" />++Describes the segments between the keyframes of a prop on the composition timeline, so a timeline can draw the line between two keyframes and let users select it to edit its easing.++:::warning++_Experimental API_: This package is not stable. Its public API may change without a major version bump.++:::++```tsx twoslash title="EasingLines.tsx"+// @moduleResolution: bundler+import {+ getCanvasKeyframeEasingSegments,+ type CanvasKeyframeEasingSegment,+ type TimelineTrackData,+} from '@remotion/canvas';+import type {CanUpdateSequencePropStatus, InteractivitySchema} from 'remotion';+declare const track: TimelineTrackData;+declare const schema: InteractivitySchema;+declare const propStatus: CanUpdateSequencePropStatus;+declare const pixelsPerFrame: number;+declare const select: (segment: CanvasKeyframeEasingSegment) => void;+// ---cut---+export const EasingLines = () => {+ const segments = getCanvasKeyframeEasingSegments({+ track,+ schema,+ key: 'style.opacity',+ propStatus,+ });+ return (+ <div style={{position: 'relative'}}>+ {segments.map((segment) => (+ <button+ key={segment.segmentIndex}+ title={segment.easing.type}+ style={{+ position: 'absolute',+ left: segment.fromFrame * pixelsPerFrame,+ width: (segment.toFrame - segment.fromFrame) * pixelsPerFrame,+ }}+ onClick={() => select(segment)}+ />+ ))}+ </div>+ );+};+```++A prop with `n` keyframes has `n - 1` segments. No segments are returned when the easing of the prop cannot be edited: boolean, enum and integer fields hold their value until the next keyframe, and the interpolation function must accept an easing. The [Remotion Studio](/docs/studio) draws its easing lines from the same data.++## Parameters++An object with the following properties:++### track++The `TimelineTrackData` of the sequence from [`controller.timeline`](/docs/canvas/create-canvas-controller#timeline). Its `keyframeDisplayOffset` and `keyframePlaybackRate` place the segments on the composition timeline.++### schema++The interactivity schema of the element, from [`track.sequence.controls`](/docs/canvas/create-canvas-controller#sequencecontrols). It decides whether the field holds its value between keyframes.++### key++The schema key of the prop in dot notation, for example `'style.opacity'`.++### propStatus++How the prop is written in the source, as the `props` of [`getNodeProps()`](/docs/codemods/get-node-props) report it. `null` or a status other than `'keyframed'` yields no segments.++## Return value++An array of `CanvasKeyframeEasingSegment` objects, ordered like the keyframes.++### segmentIndex++Indexes the easing of the prop; the segment after the first keyframe has index `0`. Pass it to [`getCanvasKeyframeEasingChange()`](/docs/canvas/get-canvas-keyframe-easing-change) and use it in an `easing` selection item.++### fromFrame++The composition frame of the keyframe that starts the segment, as [`getCanvasKeyframes()`](/docs/canvas/get-canvas-keyframes) reports it.++### toFrame++The composition frame of the keyframe that ends the segment.++### easing++The current `CanvasKeyframeEasing` of the segment: `{type: 'linear'}`, `{type: 'step1'}` for a hold, `{type: 'bezier', x1, y1, x2, y2}` or `{type: 'spring', damping, mass, stiffness, overshootClamping, allowTail, durationRestThreshold}`. Segments without an easing in the source are linear.++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering player studio="" hideServers />++## See also++- [`getCanvasKeyframeEasingChange()`](/docs/canvas/get-canvas-keyframe-easing-change)+- [`getCanvasKeyframes()`](/docs/canvas/get-canvas-keyframes)+- [`Easing`](/docs/easing)diff --git a/packages/docs/docs/canvas/get-canvas-keyframe-settings-change.mdx b/packages/docs/docs/canvas/get-canvas-keyframe-settings-change.mdxnew file mode 100644index 0000000000..ee9228128c--- /dev/null+++ b/packages/docs/docs/canvas/get-canvas-keyframe-settings-change.mdx@@ -0,0 +1,94 @@+---+image: /generated/articles-docs-canvas-get-canvas-keyframe-settings-change.png+title: getCanvasKeyframeSettingsChange()+crumb: '@remotion/canvas'+---++# getCanvasKeyframeSettingsChange()<AvailableFrom v="4.0.530" />++Returns the change that writes the [`interpolate()`](/docs/interpolate) options of a keyframed prop: the extrapolation, the `output` mode and `posterize`.++:::warning++_Experimental API_: This package is not stable. Its public API may change without a major version bump.++:::++```tsx twoslash title="PosterizeField.tsx"+// @moduleResolution: bundler+import {+ getCanvasKeyframeSettings,+ getCanvasKeyframeSettingsChange,+ type CanvasKeyframeChange,+ type SequenceNodePathInfo,+} from '@remotion/canvas';+import type {+ CanUpdateSequencePropStatusKeyframed,+ InteractivitySchema,+} from 'remotion';+declare const nodePathInfo: SequenceNodePathInfo;+declare const schema: InteractivitySchema;+declare const propStatus: CanUpdateSequencePropStatusKeyframed;+declare const persist: (change: CanvasKeyframeChange) => void;+// ---cut---+export const PosterizeField = () => {+ const settings = getCanvasKeyframeSettings(propStatus);+ return (+ <input+ type="number"+ min={0}+ value={settings.posterize ?? 0}+ onChange={(event) => {+ const posterize = Number(event.target.value);+ persist(+ getCanvasKeyframeSettingsChange({+ nodePathInfo,+ schema,+ key: 'style.opacity',+ propStatus,+ settings: {...settings, posterize: posterize > 0 ? posterize : null},+ }),+ );+ }}+ />+ );+};+```++## Parameters++An object with the following properties:++### nodePathInfo++The `SequenceNodePathInfo` of the sequence, from a track or a selection item. It is passed through to the returned change.++### schema++The interactivity schema of the element, from [`track.sequence.controls`](/docs/canvas/create-canvas-controller#sequencecontrols).++### key++The schema key of the prop in dot notation, for example `'style.opacity'`.++### propStatus++The `'keyframed'` prop status of the prop, as the `props` of [`getNodeProps()`](/docs/codemods/get-node-props) report it.++### settings++The `CanvasKeyframeSettings` to write. Take the object returned by [`getCanvasKeyframeSettings()`](/docs/canvas/get-canvas-keyframe-settings) and replace the values that changed. Options the interpolation function does not have are left as they are, and a `posterize` of `null` or `0` removes the option. Only offer the `extrapolateTypes` of the settings: `interpolatePaths()` rejects `'identity'`.++## Return value++A `CanvasKeyframeChange` whose `operation` is `{type: 'settings', clamping, posterize, output}`. Persist it with [`updateNodeKeyframes()`](/docs/codemods/update-node-keyframes) like the changes of [`getCanvasKeyframeToggle()`](/docs/canvas/get-canvas-keyframe-toggle#change), and pass it to [`getCanvasKeyframeChangeOverride()`](/docs/canvas/get-canvas-keyframe-change-override) to show the result on the canvas right away.++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering player studio="" hideServers />++## See also++- [`getCanvasKeyframeSettings()`](/docs/canvas/get-canvas-keyframe-settings)+- [`getCanvasKeyframeEasingChange()`](/docs/canvas/get-canvas-keyframe-easing-change)+- [`updateNodeKeyframes()`](/docs/codemods/update-node-keyframes)diff --git a/packages/docs/docs/canvas/get-canvas-keyframe-settings.mdx b/packages/docs/docs/canvas/get-canvas-keyframe-settings.mdxnew file mode 100644index 0000000000..30c6ccddaa--- /dev/null+++ b/packages/docs/docs/canvas/get-canvas-keyframe-settings.mdx@@ -0,0 +1,73 @@+---+image: /generated/articles-docs-canvas-get-canvas-keyframe-settings.png+title: getCanvasKeyframeSettings()+crumb: '@remotion/canvas'+---++# getCanvasKeyframeSettings()<AvailableFrom v="4.0.530" />++Reads the [`interpolate()`](/docs/interpolate) options of a keyframed prop that an editor can change: the extrapolation, the `output` mode and `posterize`. It also tells which options apply to the interpolation function of the prop.++:::warning++_Experimental API_: This package is not stable. Its public API may change without a major version bump.++:::++```tsx twoslash title="InterpolationSettings.tsx"+// @moduleResolution: bundler+import {getCanvasKeyframeSettings} from '@remotion/canvas';+import type {CanUpdateSequencePropStatusKeyframed} from 'remotion';+declare const propStatus: CanUpdateSequencePropStatusKeyframed;+// ---cut---+export const InterpolationSettings = () => {+ const settings = getCanvasKeyframeSettings(propStatus);+ return (+ <>+ {settings.clamping ? (+ <select value={settings.clamping.left}>+ {settings.extrapolateTypes.map((type) => (+ <option key={type}>{type}</option>+ ))}+ </select>+ ) : null}+ <input type="number" value={settings.posterize ?? ''} />+ </>+ );+};+```++## Parameters++### propStatus++The `'keyframed'` prop status of the prop, as the `props` of [`getNodeProps()`](/docs/codemods/get-node-props) report it.++## Return value++A `CanvasKeyframeSettings` object with the following properties.++### clamping++The `extrapolateLeft` and `extrapolateRight` options as `{left, right}`: how the value behaves before the first and after the last keyframe. `null` when the interpolation function has no extrapolation options, as `interpolateColors()` does not.++### extrapolateTypes++The `ExtrapolateType` values the prop accepts: `'extend'`, `'clamp'`, `'identity'` and `'wrap'` for `interpolate()`, without `'identity'` for `interpolatePaths()`. Empty when `clamping` is `null`.++### posterize++The `posterize` option: the animation is sampled every `posterize` frames. `null` when the value changes on every frame.++### output++The `output` option, `'linear'` or `'perceptual-scale'`. `null` when the interpolation function has no output modes; only `interpolate()` has them.++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering player studio="" hideServers />++## See also++- [`getCanvasKeyframeSettingsChange()`](/docs/canvas/get-canvas-keyframe-settings-change)+- [`interpolate()`](/docs/interpolate)diff --git a/packages/docs/docs/canvas/index.mdx b/packages/docs/docs/canvas/index.mdxindex 1a62daa208..132f384d19 100644--- a/packages/docs/docs/canvas/index.mdx+++ b/packages/docs/docs/canvas/index.mdx@@ -140,6 +140,8 @@ Props animated with `interpolate()` are reported as `keyframed` by [`getNodeProp[`getCanvasKeyframes()`](/docs/canvas/get-canvas-keyframes) places the keyframes of a prop on the timeline. [`getCanvasKeyframeToggle()`](/docs/canvas/get-canvas-keyframe-toggle) describes a keyframe button at the playhead and returns the change that adds or removes a keyframe there, while [`getCanvasPropValueAtFrame()`](/docs/canvas/get-canvas-prop-value-at-frame) reads the animated value for an inspector. [`startCanvasKeyframeDrag()`](/docs/canvas/start-canvas-keyframe-drag) moves keyframes with the pointer, previewing the result through `controller.overrides`. Every edit is a `CanvasKeyframeChange` whose `operation` you pass to [`updateNodeKeyframes()`](/docs/codemods/update-node-keyframes).+Between two keyframes, [`getCanvasKeyframeEasingSegments()`](/docs/canvas/get-canvas-keyframe-easing-segments) describes the segments a timeline can draw and select, and [`getCanvasKeyframeEasingChange()`](/docs/canvas/get-canvas-keyframe-easing-change) sets the easing of one, with `canvasKeyframeEasingPresets` for a picker. [`getCanvasKeyframeSettings()`](/docs/canvas/get-canvas-keyframe-settings) and [`getCanvasKeyframeSettingsChange()`](/docs/canvas/get-canvas-keyframe-settings-change) read and write the extrapolation, `output` mode and `posterize` of the interpolation. [`getCanvasKeyframeChangeOverride()`](/docs/canvas/get-canvas-keyframe-change-override) turns any change into an override, so the canvas shows it before the source is updated.+## APIsimport {TableOfContents} from './table-of-contents';diff --git a/packages/docs/docs/canvas/table-of-contents.tsx b/packages/docs/docs/canvas/table-of-contents.tsxindex b6249b27cd..f965c17eff 100644--- a/packages/docs/docs/canvas/table-of-contents.tsx+++ b/packages/docs/docs/canvas/table-of-contents.tsx@@ -62,6 +62,26 @@ export const TableOfContents: React.FC = () => {<strong>startCanvasKeyframeDrag()</strong><div>Move keyframes along the timeline with the pointer</div></TOCItem>+ <TOCItem link="/docs/canvas/get-canvas-keyframe-easing-segments">+ <strong>getCanvasKeyframeEasingSegments()</strong>+ <div>Describe the segments between keyframes on the timeline</div>+ </TOCItem>+ <TOCItem link="/docs/canvas/get-canvas-keyframe-easing-change">+ <strong>getCanvasKeyframeEasingChange()</strong>+ <div>Set the easing between two keyframes</div>+ </TOCItem>+ <TOCItem link="/docs/canvas/get-canvas-keyframe-settings">+ <strong>getCanvasKeyframeSettings()</strong>+ <div>Read the extrapolation, output and posterize options</div>+ </TOCItem>+ <TOCItem link="/docs/canvas/get-canvas-keyframe-settings-change">+ <strong>getCanvasKeyframeSettingsChange()</strong>+ <div>Write the interpolation options of a keyframed prop</div>+ </TOCItem>+ <TOCItem link="/docs/canvas/get-canvas-keyframe-change-override">+ <strong>getCanvasKeyframeChangeOverride()</strong>+ <div>Show a keyframe change before the source is updated</div>+ </TOCItem><TOCItem link="/docs/canvas/get-canvas-prop-value-at-frame"><strong>getCanvasPropValueAtFrame()</strong><div>Read the value of a prop at a frame from the source</div>diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 3d1f504b42..5b8972e503 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -2070,6 +2070,11 @@ const sidebars: SidebarsConfig = {'canvas/get-canvas-keyframes','canvas/get-canvas-keyframe-toggle','canvas/start-canvas-keyframe-drag',+ 'canvas/get-canvas-keyframe-easing-segments',+ 'canvas/get-canvas-keyframe-easing-change',+ 'canvas/get-canvas-keyframe-settings',+ 'canvas/get-canvas-keyframe-settings-change',+ 'canvas/get-canvas-keyframe-change-override','canvas/get-canvas-prop-value-at-frame','canvas/get-canvas-keyframe-source-frame','canvas/get-canvas-keyframe-display-frame',diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.tsindex 656798fdf9..ba6793f4b4 100644--- a/packages/studio-shared/src/index.ts+++ b/packages/studio-shared/src/index.ts@@ -319,6 +319,7 @@ export {getKeyframeInterpolationFunction,getKeyframeInterpolationFunctionForSchemaField,getKeyframeOutputTypeForSchemaField,+ isInteractivitySchemaFieldHoldOnly,isInteractivitySchemaFieldKeyframable,isKeyframeInterpolationFunction,isSchemaFieldHoldOnly,@@ -409,6 +410,7 @@ export {export type {VisualControlChange} from './codemods';export {+ addKeyframeToPropStatus,optimisticAddEffectKeyframe,optimisticAddSequenceKeyframe,} from './optimistic-add-keyframe';@@ -417,6 +419,7 @@ export {optimisticDeleteEffectKeyframes,optimisticDeleteSequenceKeyframe,optimisticDeleteSequenceKeyframes,+ removeKeyframeFromPropStatus,} from './optimistic-delete-keyframe';export {canMoveKeyframesWithoutCollisions,@@ -428,6 +431,7 @@ export {export {optimisticUpdateForEffectPropStatuses} from './optimistic-update-for-effect-prop-statuses';export {optimisticUpdateForPropStatuses} from './optimistic-update-for-prop-statuses';export {+ applyKeyframeSettingsToStatus,optimisticUpdateEffectKeyframeSettings,optimisticUpdateSequenceKeyframeSettings,} from './optimistic-update-keyframe-settings';diff --git a/packages/studio-shared/src/keyframe-interpolation-function.ts b/packages/studio-shared/src/keyframe-interpolation-function.tsindex 890f7e837b..fed3dbc78c 100644--- a/packages/studio-shared/src/keyframe-interpolation-function.ts+++ b/packages/studio-shared/src/keyframe-interpolation-function.ts@@ -158,6 +158,18 @@ export const isSchemaFieldKeyframable = ({return isInteractivitySchemaFieldKeyframable(field);};+export const isInteractivitySchemaFieldHoldOnly = (+ field: InteractivitySchemaField | undefined,+): boolean => {+ return (+ (field?.type === 'boolean' && field.keyframable !== false) ||+ (field?.type === 'enum' && field.keyframable === true) ||+ (field?.type === 'number' &&+ field.integer === true &&+ field.keyframable !== false)+ );+};+export const isSchemaFieldHoldOnly = ({schema,key,@@ -165,13 +177,8 @@ export const isSchemaFieldHoldOnly = ({schema: InteractivitySchema | null;key: string;}): boolean => {- const field = schema ? findFieldInSchema(schema, key) : undefined;- return (- (field?.type === 'boolean' && field.keyframable !== false) ||- (field?.type === 'enum' && field.keyframable === true) ||- (field?.type === 'number' &&- field.integer === true &&- field.keyframable !== false)+ return isInteractivitySchemaFieldHoldOnly(+ schema ? findFieldInSchema(schema, key) : undefined,);};diff --git a/packages/studio-shared/src/optimistic-add-keyframe.ts b/packages/studio-shared/src/optimistic-add-keyframe.tsindex 7deb98f9ce..c55a09fca6 100644--- a/packages/studio-shared/src/optimistic-add-keyframe.ts+++ b/packages/studio-shared/src/optimistic-add-keyframe.ts@@ -33,7 +33,11 @@ const getEasingIndexToDuplicate = ({return Math.min(insertedKeyframeIndex - 1, easingLength - 1);};-const addKeyframeToPropStatus = ({+/**+ * The status of a prop after adding a keyframe: a keyframed prop gets the+ * keyframe inserted or replaced, a static prop becomes keyframed.+ */+export const addKeyframeToPropStatus = ({status,fieldKey,frame,diff --git a/packages/studio-shared/src/optimistic-delete-keyframe.ts b/packages/studio-shared/src/optimistic-delete-keyframe.tsindex 94651c7c15..84856e8e21 100644--- a/packages/studio-shared/src/optimistic-delete-keyframe.ts+++ b/packages/studio-shared/src/optimistic-delete-keyframe.ts@@ -21,7 +21,11 @@ const getEasingIndexToRemove = ({return removedKeyframeIndex;};-const removeKeyframeFromPropStatus = ({+/**+ * The status of a prop after removing the keyframe at `frame`. Removing the+ * last keyframe leaves a static prop.+ */+export const removeKeyframeFromPropStatus = ({status,frame,valueWhenLastKeyframeDeleted,diff --git a/packages/studio-shared/src/optimistic-update-keyframe-settings.ts b/packages/studio-shared/src/optimistic-update-keyframe-settings.tsindex d27441e836..9d6a4b784c 100644--- a/packages/studio-shared/src/optimistic-update-keyframe-settings.ts+++ b/packages/studio-shared/src/optimistic-update-keyframe-settings.ts@@ -1,14 +1,12 @@import type {CanUpdateSequencePropsResponse,- CanUpdateSequencePropStatus,+ CanUpdateSequencePropStatusEasing,+ CanUpdateSequencePropStatusKeyframed,} from 'remotion';import type {KeyframeSettings} from './api-requests';import {LINEAR_KEYFRAME_EASING} from './keyframe-easing-presets';-type KeyframeEasing = Extract<- CanUpdateSequencePropStatus,- {status: 'keyframed'}->['easing'][number];+type KeyframeEasing = CanUpdateSequencePropStatusEasing;const updateEasing = ({easing,@@ -36,14 +34,11 @@ const updateEasing = ({return nextEasing;};-const applySettingsToStatus = (- status: CanUpdateSequencePropStatus | undefined,+/** The keyframed status of a prop after an easing or settings update. */+export const applyKeyframeSettingsToStatus = (+ status: CanUpdateSequencePropStatusKeyframed,settings: KeyframeSettings,-): CanUpdateSequencePropStatus => {- if (!status || status.status !== 'keyframed') {- throw new Error('Expected keyframed status');- }-+): CanUpdateSequencePropStatusKeyframed => {return {...status,...(settings.type === 'settings' && settings.clamping@@ -86,7 +81,7 @@ export const optimisticUpdateSequenceKeyframeSettings = ({...previous,props: {...previous.props,- [fieldKey]: applySettingsToStatus(status, settings),+ [fieldKey]: applyKeyframeSettingsToStatus(status, settings),},};};@@ -128,7 +123,7 @@ export const optimisticUpdateEffectKeyframeSettings = ({...target,props: {...target.props,- [fieldKey]: applySettingsToStatus(status, settings),+ [fieldKey]: applyKeyframeSettingsToStatus(status, settings),},};diff --git a/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx b/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsxindex 9e4fb33c51..a9fa6e8063 100644--- a/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx+++ b/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx@@ -1,3 +1,4 @@+import {CanvasInternals} from '@remotion/canvas';import {canMoveKeyframesWithoutCollisions,moveKeyframesInPropStatus,@@ -45,7 +46,6 @@ import {type TimelineSelection,} from '../Timeline/TimelineSelection';import {TimelineSequenceKeyframedValue} from '../Timeline/TimelineSequencePropItem';-import {canEditEasingForInterpolationFunction} from '../Timeline/update-selected-easing';import {InspectorBackAction,InspectorDetailRow,@@ -65,6 +65,8 @@ import {} from './styles';import {useTrackForSelection} from './use-track-for-selection';+const {canEditKeyframeEasing} = CanvasInternals;+type KeyframeEditorDetails =| {readonly type: 'sequence';@@ -538,12 +540,10 @@ export const KeyframeInspector: React.FC<{</InspectorBackAction><KeyframeEasingNavigatorcurrentSelection={selection}- includeEasings={- details.field.fieldSchema.type !== 'boolean' &&- canEditEasingForInterpolationFunction(- details.propStatus.interpolationFunction,- )- }+ includeEasings={canEditKeyframeEasing({+ field: details.field.fieldSchema,+ propStatus: details.propStatus,+ })}keyframes={details.propStatus.keyframes.map((keyframe) => ({...keyframe,frame:diff --git a/packages/studio/src/components/InspectorPanel/KeyframeSettings.tsx b/packages/studio/src/components/InspectorPanel/KeyframeSettings.tsxindex f28422df48..3bd41c8947 100644--- a/packages/studio/src/components/InspectorPanel/KeyframeSettings.tsx+++ b/packages/studio/src/components/InspectorPanel/KeyframeSettings.tsx@@ -1,4 +1,8 @@-import type {KeyframeSettings as KeyframeSettingsValue} from '@remotion/studio-shared';+import {+ getCanvasKeyframeSettings,+ getCanvasKeyframeSettingsChange,+ type CanvasKeyframeSettings,+} from '@remotion/canvas';import React, {useCallback,useContext,@@ -29,35 +33,26 @@ const keyframeSettingsContainer: React.CSSProperties = {paddingBottom: 0,};-const extrapolateOptions = [- 'extend',- 'clamp',- 'identity',- 'wrap',-] as const satisfies ExtrapolateType[];-const labelForExtrapolate = (value: ExtrapolateType) =>value[0].toUpperCase() + value.slice(1);const getExtrapolateValues = (+ extrapolateTypes: readonly ExtrapolateType[],onSelect: (value: ExtrapolateType) => void,disabled: boolean,- allowIdentity: boolean,): ComboboxValue[] => {- return extrapolateOptions- .filter((value) => allowIdentity || value !== 'identity')- .map((value) => ({- type: 'item',- id: value,- keyHint: null,- label: labelForExtrapolate(value),- leftItem: null,- disabled,- onClick: () => onSelect(value),- quickSwitcherLabel: null,- subMenu: null,- value,- }));+ return extrapolateTypes.map((value) => ({+ type: 'item',+ id: value,+ keyHint: null,+ label: labelForExtrapolate(value),+ leftItem: null,+ disabled,+ onClick: () => onSelect(value),+ quickSwitcherLabel: null,+ subMenu: null,+ value,+ }));};const outputOptions = [@@ -93,29 +88,37 @@ export const KeyframeSettings: React.FC<{const {setPropStatuses} = useContext(Internals.VisualModeSettersContext);const {previewServerState} = useContext(StudioServerConnectionCtx);const {propStatus} = update;- const [posterize, setPosterize] = useState(propStatus.posterize ?? 0);- const canEditExtrapolation =- propStatus.interpolationFunction === 'interpolate' ||- propStatus.interpolationFunction === 'interpolatePaths';- const canEditOutput = propStatus.interpolationFunction === 'interpolate';+ const settings = useMemo(+ () => getCanvasKeyframeSettings(propStatus),+ [propStatus],+ );+ const [posterize, setPosterize] = useState(settings.posterize ?? 0);const disabled = previewServerState.type !== 'connected';useEffect(() => {- setPosterize(propStatus.posterize ?? 0);- }, [propStatus.posterize]);+ setPosterize(settings.posterize ?? 0);+ }, [settings.posterize]);- const save = useCallback(- (settings: KeyframeSettingsValue) => {+ const saveSettings = useCallback(+ (next: Partial<CanvasKeyframeSettings>) => {if (previewServerState.type !== 'connected') {return;}+ const {operation} = getCanvasKeyframeSettingsChange({+ nodePathInfo: update.nodePathInfo,+ schema: update.schema,+ key: update.fieldKey,+ propStatus,+ settings: {...settings, ...next},+ });+if (update.type === 'sequence') {callUpdateSequenceKeyframeSettings({fileName: update.fileName,nodePath: update.nodePath,fieldKey: update.fieldKey,- settings,+ settings: operation,schema: update.schema,setPropStatuses,clientId: previewServerState.clientId,@@ -128,64 +131,44 @@ export const KeyframeSettings: React.FC<{nodePath: update.nodePath,effectIndex: update.effectIndex,fieldKey: update.fieldKey,- settings,+ settings: operation,schema: update.schema,setPropStatuses,clientId: previewServerState.clientId,}).catch(() => undefined);},- [previewServerState, setPropStatuses, update],- );-- const saveSettings = useCallback(- ({- left = propStatus.clamping.left,- output = propStatus.output ?? 'linear',- posterize: nextPosterize = propStatus.posterize ?? 0,- right = propStatus.clamping.right,- }: {- readonly left?: ExtrapolateType;- readonly output?: InterpolateOutputOption;- readonly posterize?: number;- readonly right?: ExtrapolateType;- }) => {- save({- type: 'settings',- clamping: canEditExtrapolation ? {left, right} : undefined,- output: canEditOutput ? output : undefined,- posterize: nextPosterize <= 0 ? undefined : nextPosterize,- });- },- [- canEditExtrapolation,- canEditOutput,- propStatus.clamping.left,- propStatus.clamping.right,- propStatus.output,- propStatus.posterize,- save,- ],+ [previewServerState, propStatus, setPropStatuses, settings, update],);const onSelectLeft = useCallback(- (left: ExtrapolateType) => saveSettings({left}),- [saveSettings],+ (left: ExtrapolateType) => {+ if (settings.clamping) {+ saveSettings({clamping: {...settings.clamping, left}});+ }+ },+ [saveSettings, settings.clamping],);const onSelectRight = useCallback(- (right: ExtrapolateType) => saveSettings({right}),- [saveSettings],+ (right: ExtrapolateType) => {+ if (settings.clamping) {+ saveSettings({clamping: {...settings.clamping, right}});+ }+ },+ [saveSettings, settings.clamping],);const onSelectOutput = useCallback((output: InterpolateOutputOption) => saveSettings({output}),[saveSettings],);const leftValues = useMemo(- () => getExtrapolateValues(onSelectLeft, disabled, canEditOutput),- [canEditOutput, disabled, onSelectLeft],+ () =>+ getExtrapolateValues(settings.extrapolateTypes, onSelectLeft, disabled),+ [disabled, onSelectLeft, settings.extrapolateTypes],);const rightValues = useMemo(- () => getExtrapolateValues(onSelectRight, disabled, canEditOutput),- [canEditOutput, disabled, onSelectRight],+ () =>+ getExtrapolateValues(settings.extrapolateTypes, onSelectRight, disabled),+ [disabled, onSelectRight, settings.extrapolateTypes],);const outputValues = useMemo(() => getOutputValues(onSelectOutput, disabled),@@ -214,12 +197,12 @@ export const KeyframeSettings: React.FC<{sectionId="keyframe-settings"><div style={keyframeSettingsContainer}>- {canEditExtrapolation ? (+ {settings.clamping ? (<><InspectorDetailRow label="Extrapolate left"><Comboboxvalues={leftValues}- selectedId={propStatus.clamping.left}+ selectedId={settings.clamping.left}aria-label="Extrapolate left"style={comboStyle}size="small"@@ -228,7 +211,7 @@ export const KeyframeSettings: React.FC<{<InspectorDetailRow label="Extrapolate right"><Comboboxvalues={rightValues}- selectedId={propStatus.clamping.right}+ selectedId={settings.clamping.right}aria-label="Extrapolate right"style={comboStyle}size="small"@@ -236,11 +219,11 @@ export const KeyframeSettings: React.FC<{</InspectorDetailRow></>) : null}- {canEditOutput ? (+ {settings.output ? (<InspectorDetailRow label="Output"><Comboboxvalues={outputValues}- selectedId={propStatus.output ?? 'linear'}+ selectedId={settings.output}aria-label="Output"style={comboStyle}size="small"diff --git a/packages/studio/src/components/Timeline/EasingEditorModal.tsx b/packages/studio/src/components/Timeline/EasingEditorModal.tsxindex 0f8fb73cb9..24b6fdce88 100644--- a/packages/studio/src/components/Timeline/EasingEditorModal.tsx+++ b/packages/studio/src/components/Timeline/EasingEditorModal.tsx@@ -1,8 +1,8 @@import {- HOLD_KEYFRAME_EASING,- KEYFRAME_EASING_PRESETS,- LINEAR_KEYFRAME_EASING,-} from '@remotion/studio-shared';+ canvasKeyframeEasingPresets,+ type CanvasKeyframeEasingPreset,+} from '@remotion/canvas';+import {HOLD_KEYFRAME_EASING} from '@remotion/studio-shared';import React, {useCallback,useContext,@@ -62,11 +62,6 @@ type EasingGraphLabels = {readonly start: string;readonly end: string;};-type EasingPreset = {- readonly id: string;- readonly label: string;- readonly easing: TimelineEasingValue;-};const SVG_WIDTH = 560;const SVG_HEIGHT = 320;@@ -102,15 +97,6 @@ const DEFAULT_SPRING_EASING: SpringEasing = {overshootClamping: false,stiffness: 100,};-const EDITOR_EASING_PRESETS: readonly EasingPreset[] = [- {- id: 'linear',- label: 'Linear',- easing: LINEAR_KEYFRAME_EASING,- },- ...KEYFRAME_EASING_PRESETS,-];-const SPRING_LIMITS: Record<SpringNumberKey,{@@ -696,7 +682,7 @@ const EasingPresetButton: React.FC<{readonly currentEasing: TimelineEasingValue;readonly disabled: boolean;readonly onClick: (easing: TimelineEasingValue) => void;- readonly preset: EasingPreset;+ readonly preset: CanvasKeyframeEasingPreset;}> = ({currentEasing, disabled, onClick, preset}) => {const selected = areEasingsEqual(currentEasing, preset.easing);const [hovered, setHovered] = useState(false);@@ -840,11 +826,10 @@ export const EasingEditor: React.FC<{pendingOverrideTargetsRef.current = updates;for (const update of updates) {- const dragOverrideValue = makeEasingDragOverride({- status: update.propStatus,- segmentIndex: update.segmentIndex,- easing,- });+ const dragOverrideValue = makeEasingDragOverride({update, easing});+ if (dragOverrideValue === null) {+ continue;+ }if (update.type === 'sequence') {setDragOverrides(update.nodePath, update.fieldKey, dragOverrideValue);@@ -1237,7 +1222,7 @@ export const EasingEditor: React.FC<{renderHeader ? inspectorPresetButtonsWrapper : presetButtonsWrapper}>- {EDITOR_EASING_PRESETS.map((preset) => (+ {canvasKeyframeEasingPresets.map((preset) => (<EasingPresetButtonkey={preset.id}currentEasing={currentEasing}diff --git a/packages/studio/src/components/Timeline/TimelineExpandedKeyframeRow.tsx b/packages/studio/src/components/Timeline/TimelineExpandedKeyframeRow.tsxindex a89386e2f4..0d2ab58179 100644--- a/packages/studio/src/components/Timeline/TimelineExpandedKeyframeRow.tsx+++ b/packages/studio/src/components/Timeline/TimelineExpandedKeyframeRow.tsx@@ -1,3 +1,4 @@+import {CanvasInternals} from '@remotion/canvas';import React, {useContext} from 'react';import {areSequenceNodePathInfosEqual} from '../../helpers/are-sequence-node-path-infos-equal';import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';@@ -5,7 +6,6 @@ import {TIMELINE_ITEM_BORDER_BOTTOM,TIMELINE_PADDING,} from '../../helpers/timeline-layout';-import {getTimelineEasingSegments} from './get-timeline-easing-segments';import type {getTimelineKeyframes} from './get-timeline-keyframes';import {TimelineKeyframeDiamond} from './TimelineKeyframeDiamond';import {TimelineKeyframeEasingLine} from './TimelineKeyframeEasingLine';@@ -16,6 +16,8 @@ import {} from './TimelineSelection';import {TimelineWidthContext} from './TimelineWidthProvider';+const {getKeyframeSegments} = CanvasInternals;+const rowClipper: React.CSSProperties = {boxSizing: 'border-box',marginLeft: -TIMELINE_PADDING,@@ -53,9 +55,7 @@ const TimelineExpandedKeyframeRowUnmemoized: React.FC<selectedBackground: TIMELINE_EXPANDED_SELECTED_BACKGROUND,},);- const easingSegments = canEditEasing- ? getTimelineEasingSegments(keyframes)- : [];+ const easingSegments = canEditEasing ? getKeyframeSegments(keyframes) : [];return (<>diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsxindex 212e2d702b..8c87f0e477 100644--- a/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsx+++ b/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsx@@ -1,7 +1,4 @@-import {- KEYFRAME_EASING_PRESETS,- LINEAR_KEYFRAME_EASING,-} from '@remotion/studio-shared';+import {canvasKeyframeEasingPresets} from '@remotion/canvas';import React, {useCallback, useContext, useMemo, useRef} from 'react';import {Internals, useVideoConfig} from 'remotion';import {StudioServerConnectionCtx} from '../../helpers/client-id';@@ -158,50 +155,27 @@ const TimelineKeyframeEasingLineInteraction: React.FC<});}- return [- {- type: 'item',- id: 'linear',- keyHint: null,- label: 'Linear',- leftItem: (- <EasingPresetPreview- color={LIGHT_TEXT}- easing={LINEAR_KEYFRAME_EASING}- height={18}- nonScalingStroke- strokeWidth={5}- width={18}- />- ),- disabled: previewServerState.type !== 'connected',- onClick: () => updateEasing(LINEAR_KEYFRAME_EASING),- quickSwitcherLabel: null,- subMenu: null,- value: 'linear',- },- ...KEYFRAME_EASING_PRESETS.map((preset) => ({- type: 'item' as const,- id: preset.id,- keyHint: null,- label: preset.label,- leftItem: (- <EasingPresetPreview- color={LIGHT_TEXT}- easing={preset.easing}- height={18}- nonScalingStroke- strokeWidth={5}- width={18}- />- ),- disabled: previewServerState.type !== 'connected',- onClick: () => updateEasing(preset.easing),- quickSwitcherLabel: null,- subMenu: null,- value: preset.id,- })),- ];+ return canvasKeyframeEasingPresets.map((preset) => ({+ type: 'item' as const,+ id: preset.id,+ keyHint: null,+ label: preset.label,+ leftItem: (+ <EasingPresetPreview+ color={LIGHT_TEXT}+ easing={preset.easing}+ height={18}+ nonScalingStroke+ strokeWidth={5}+ width={18}+ />+ ),+ disabled: previewServerState.type !== 'connected',+ onClick: () => updateEasing(preset.easing),+ quickSwitcherLabel: null,+ subMenu: null,+ value: preset.id,+ }));},[onSelect, previewServerState.type, selectable, selected, updateEasing],);diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsxindex b9b13c6fc8..1c295b0022 100644--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx@@ -9,7 +9,6 @@ import {useCanvasSelection,} from '@remotion/canvas';import {- canEditEasingForInterpolationFunction,stringifySequenceExpandedRowKey,type SequenceNodePathMutation,} from '@remotion/studio-shared';@@ -60,7 +59,6 @@ import {buildTimelineTree,flattenVisibleTreeNodes,TIMELINE_PADDING,- type TimelineTreeNode,} from '../../helpers/timeline-layout';import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';import {useKeybinding} from '../../helpers/use-keybinding';@@ -72,8 +70,11 @@ import {type GetIsExpanded,} from '../ExpandedTracksProvider';import {selectOptionsSidebarInspectorPanel} from '../options-sidebar-tabs';-import {getNodeHasKeyframes, getNodeKeyframes} from './get-node-keyframes';-import {getTimelineEasingSegments} from './get-timeline-easing-segments';+import {+ getNodeCanEditEasing,+ getNodeHasKeyframes,+ getNodeKeyframes,+} from './get-node-keyframes';import {getCurrentFrame} from './imperative-state';import {parseKeyframeFieldFromNodePath} from './parse-keyframe-field-from-node-path';import {@@ -94,6 +95,7 @@ const {EMPTY_CANVAS_SELECTION,getCanvasSelectionAfterInteraction,getCanvasSequenceSelectionKey,+ getKeyframeSegments,useCanvasSelectionController,} = CanvasInternals;@@ -647,53 +649,6 @@ export const getSelectableTimelineSequenceSelections = (});};-const getTimelineTreeNodeCanEditEasing = ({- node,- nodePathInfo,- propStatuses,-}: {- readonly node: TimelineTreeNode;- readonly nodePathInfo: SequenceNodePathInfo;- readonly propStatuses: PropStatuses;-}) => {- if (- node.kind !== 'field' ||- node.field === null ||- node.field.fieldSchema.type === 'boolean'- ) {- return false;- }-- if (node.field.kind === 'sequence-field') {- const sequencePropStatus = Internals.getPropStatusesCtx(- propStatuses,- nodePathInfo.sequenceSubscriptionKey,- )?.[node.field.key];- return (- sequencePropStatus?.status === 'keyframed' &&- canEditEasingForInterpolationFunction(- sequencePropStatus.interpolationFunction,- )- );- }-- const effectStatus = Internals.getEffectPropStatusesCtx({- propStatuses,- nodePath: nodePathInfo.sequenceSubscriptionKey,- effectIndex: node.field.effectIndex,- });- const effectPropStatus =- effectStatus.type === 'can-update-effect'- ? effectStatus.props[node.field.key]- : null;- return (- effectPropStatus?.status === 'keyframed' &&- canEditEasingForInterpolationFunction(- effectPropStatus.interpolationFunction,- )- );-};-export const getSelectableTimelineItems = ({getDragOverrides,getEffectDragOverrides,@@ -786,12 +741,12 @@ export const getSelectableTimelineItems = ({frame: keyframe.frame,}),);- const easingSelections = getTimelineTreeNodeCanEditEasing({+ const easingSelections = getNodeCanEditEasing({node,- nodePathInfo,+ nodePath: nodePathInfo.sequenceSubscriptionKey,propStatuses,})- ? getTimelineEasingSegments(keyframes).map(+ ? getKeyframeSegments(keyframes).map((segment): TimelineSelection => ({type: 'easing',nodePathInfo: node.nodePathInfo,diff --git a/packages/studio/src/components/Timeline/get-node-keyframes.ts b/packages/studio/src/components/Timeline/get-node-keyframes.tsindex 0ad90106b7..0f81e11268 100644--- a/packages/studio/src/components/Timeline/get-node-keyframes.ts+++ b/packages/studio/src/components/Timeline/get-node-keyframes.ts@@ -1,3 +1,4 @@+import {CanvasInternals} from '@remotion/canvas';import {Internals,type DragOverrideValue,@@ -9,6 +10,8 @@ import {import type {TimelineTreeNode} from '../../helpers/timeline-layout';import {getTimelineKeyframes} from './get-timeline-keyframes';+const {canEditKeyframeEasing} = CanvasInternals;+const hasOverride = (overrides: Record<string, DragOverrideValue>,key: string,@@ -174,3 +177,40 @@ export const getNodeHasKeyframes = ({effectStatus.props?.[node.field.key]?.status === 'keyframed');};++/** Whether the row of a field shows easing segments between its keyframes. */+export const getNodeCanEditEasing = ({+ node,+ nodePath,+ propStatuses,+}: {+ node: TimelineTreeNode;+ nodePath: SequencePropsSubscriptionKey;+ propStatuses: PropStatuses;+}): boolean => {+ if (node.kind !== 'field' || node.field === null) {+ return false;+ }++ if (node.field.kind === 'sequence-field') {+ return canEditKeyframeEasing({+ field: node.field.fieldSchema,+ propStatus: Internals.getPropStatusesCtx(propStatuses, nodePath)?.[+ node.field.key+ ],+ });+ }++ const effectStatus = Internals.getEffectPropStatusesCtx({+ propStatuses,+ nodePath,+ effectIndex: node.field.effectIndex,+ });+ return canEditKeyframeEasing({+ field: node.field.fieldSchema,+ propStatus:+ effectStatus.type === 'can-update-effect'+ ? effectStatus.props[node.field.key]+ : null,+ });+};diff --git a/packages/studio/src/components/Timeline/get-timeline-easing-segments.ts b/packages/studio/src/components/Timeline/get-timeline-easing-segments.tsdeleted file mode 100644index bbc4f7c5b5..0000000000--- a/packages/studio/src/components/Timeline/get-timeline-easing-segments.ts+++ /dev/null@@ -1,26 +0,0 @@-import type {getTimelineKeyframes} from './get-timeline-keyframes';--export type TimelineEasingSegment = {- readonly fromFrame: number;- readonly toFrame: number;- readonly segmentIndex: number;-};--export const getTimelineEasingSegments = (- keyframes: ReturnType<typeof getTimelineKeyframes>,-): TimelineEasingSegment[] => {- return keyframes.flatMap((keyframe, index) => {- const nextKeyframe = keyframes[index + 1];- if (!nextKeyframe) {- return [];- }-- return [- {- fromFrame: keyframe.frame,- toFrame: nextKeyframe.frame,- segmentIndex: index,- },- ];- });-};diff --git a/packages/studio/src/components/Timeline/update-selected-easing.ts b/packages/studio/src/components/Timeline/update-selected-easing.tsindex bc8fdc90e8..d0937dfc6d 100644--- a/packages/studio/src/components/Timeline/update-selected-easing.ts+++ b/packages/studio/src/components/Timeline/update-selected-easing.ts@@ -1,12 +1,10 @@import {- canEditEasingForInterpolationFunction,- isSchemaFieldHoldOnly,- LINEAR_KEYFRAME_EASING,-} from '@remotion/studio-shared';-export {canEditEasingForInterpolationFunction} from '@remotion/studio-shared';+ CanvasInternals,+ getCanvasKeyframeChangeOverride,+ type CanvasKeyframeEasing,+} from '@remotion/canvas';import type {CanUpdateSequencePropStatusKeyframed,- CanUpdateSequencePropStatusEasing,DragOverrideValue,OverrideIdToNodePaths,PropStatuses,@@ -15,6 +13,7 @@ import type {TSequence,} from 'remotion';import {Internals} from 'remotion';+import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';import {callBatchUpdateKeyframeSettings} from './call-update-keyframe-settings';import {findTrackForNodePathInfo} from './find-track-for-node-path-info';import {parseKeyframeFieldFromNodePath} from './parse-keyframe-field-from-node-path';@@ -24,13 +23,17 @@ import type {TimelineSelection,} from './TimelineSelection';+const {canEditKeyframeEasing, getKeyframeSegmentEasing, getSchemaField} =+ CanvasInternals;+export type EasingSelection = TimelineEasingSelection;-export type TimelineEasingValue = CanUpdateSequencePropStatusEasing;+export type TimelineEasingValue = CanvasKeyframeEasing;export type SelectedEasingUpdate =| {readonly type: 'sequence';readonly fileName: string;readonly nodePath: SequencePropsSubscriptionKey;+ readonly nodePathInfo: SequenceNodePathInfo;readonly fieldKey: string;readonly schema: InteractivitySchema;readonly segmentIndex: number;@@ -41,6 +44,7 @@ export type SelectedEasingUpdate =readonly type: 'effect';readonly fileName: string;readonly nodePath: SequencePropsSubscriptionKey;+ readonly nodePathInfo: SequenceNodePathInfo;readonly effectIndex: number;readonly fieldKey: string;readonly schema: InteractivitySchema;@@ -95,13 +99,10 @@ export const getSelectedEasingUpdate = ({)?.[field.fieldKey];if (sequencePropStatus?.status !== 'keyframed' ||- isSchemaFieldHoldOnly({- schema: sequence.controls.schema,- key: field.fieldKey,- }) ||- !canEditEasingForInterpolationFunction(- sequencePropStatus.interpolationFunction,- )+ !canEditKeyframeEasing({+ field: getSchemaField(sequence.controls.schema, field.fieldKey),+ propStatus: sequencePropStatus,+ })) {return null;}@@ -110,12 +111,14 @@ export const getSelectedEasingUpdate = ({type: 'sequence' as const,fileName,nodePath,+ nodePathInfo: selection.nodePathInfo,fieldKey: field.fieldKey,schema: sequence.controls.schema,segmentIndex: selection.segmentIndex,- currentEasing:- sequencePropStatus.easing[selection.segmentIndex] ??- LINEAR_KEYFRAME_EASING,+ currentEasing: getKeyframeSegmentEasing(+ sequencePropStatus,+ selection.segmentIndex,+ ),propStatus: sequencePropStatus,};}@@ -136,13 +139,10 @@ export const getSelectedEasingUpdate = ({: null;if (effectPropStatus?.status !== 'keyframed' ||- isSchemaFieldHoldOnly({- schema: effect.schema,- key: field.fieldKey,- }) ||- !canEditEasingForInterpolationFunction(- effectPropStatus.interpolationFunction,- )+ !canEditKeyframeEasing({+ field: getSchemaField(effect.schema, field.fieldKey),+ propStatus: effectPropStatus,+ })) {return null;}@@ -151,12 +151,15 @@ export const getSelectedEasingUpdate = ({type: 'effect' as const,fileName,nodePath,+ nodePathInfo: selection.nodePathInfo,effectIndex: field.effectIndex,fieldKey: field.fieldKey,schema: effect.schema,segmentIndex: selection.segmentIndex,- currentEasing:- effectPropStatus.easing[selection.segmentIndex] ?? LINEAR_KEYFRAME_EASING,+ currentEasing: getKeyframeSegmentEasing(+ effectPropStatus,+ selection.segmentIndex,+ ),propStatus: effectPropStatus,};};@@ -184,33 +187,27 @@ export const getSelectedEasingUpdates = ({.filter((update): update is SelectedEasingUpdate => update !== null);};+/** Previews an easing on the segment of a selected easing update. */export const makeEasingDragOverride = ({- status,- segmentIndex,+ update,easing,}: {- readonly status: CanUpdateSequencePropStatusKeyframed;- readonly segmentIndex: number;+ readonly update: SelectedEasingUpdate;readonly easing: TimelineEasingValue;-}): DragOverrideValue => {- const nextEasing = [...status.easing];- while (nextEasing.length < status.keyframes.length - 1) {- nextEasing.push(LINEAR_KEYFRAME_EASING);- }-- if (nextEasing.length > status.keyframes.length - 1) {- nextEasing.length = status.keyframes.length - 1;- }-- nextEasing[segmentIndex] = easing;-- return {- type: 'keyframed',- status: {- ...status,- easing: nextEasing,+}): DragOverrideValue | null => {+ return getCanvasKeyframeChangeOverride({+ propStatus: update.propStatus,+ change: {+ nodePathInfo: update.nodePathInfo,+ key: update.fieldKey,+ schema: update.schema,+ operation: {+ type: 'easing',+ segmentIndex: update.segmentIndex,+ easing,+ },},- };+ });};export const getEasingSelections = (diff --git a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.tsindex 7c62cf12ad..8891c3e525 100644--- a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts+++ b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts@@ -1,4 +1,3 @@-import {canEditEasingForInterpolationFunction} from '@remotion/studio-shared';import {useCallback, useContext, useMemo} from 'react';import {Internals, type TSequence} from 'remotion';import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';@@ -11,7 +10,11 @@ import {import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';import {useRuntimeValueSelector} from '../../helpers/use-runtime-values';import {ExpandedTracksGetterContext} from '../ExpandedTracksProvider';-import {getNodeHasKeyframes, getNodeKeyframes} from './get-node-keyframes';+import {+ getNodeCanEditEasing,+ getNodeHasKeyframes,+ getNodeKeyframes,+} from './get-node-keyframes';import type {getTimelineKeyframes} from './get-timeline-keyframes';import {getCurrentFrame} from './imperative-state';import {@@ -74,53 +77,6 @@ const areTimelineTreeLayoutsEqual = (});};-const getNodeCanEditEasing = ({- node,- nodePath,- propStatuses,-}: {- node: ReturnType<typeof flattenVisibleTreeNodes>[number]['node'];- nodePath: Parameters<typeof getNodeKeyframes>[0]['nodePath'];- propStatuses: Parameters<typeof getNodeKeyframes>[0]['propStatuses'];-}) => {- if (- node.kind !== 'field' ||- node.field === null ||- node.field.fieldSchema.type === 'boolean'- ) {- return false;- }-- if (node.field.kind === 'sequence-field') {- const sequencePropStatus = Internals.getPropStatusesCtx(- propStatuses,- nodePath,- )?.[node.field.key];- return (- sequencePropStatus?.status === 'keyframed' &&- canEditEasingForInterpolationFunction(- sequencePropStatus.interpolationFunction,- )- );- }-- const effectStatus = Internals.getEffectPropStatusesCtx({- propStatuses,- nodePath,- effectIndex: node.field.effectIndex,- });- const effectPropStatus =- effectStatus.type === 'can-update-effect'- ? effectStatus.props[node.field.key]- : null;- return (- effectPropStatus?.status === 'keyframed' &&- canEditEasingForInterpolationFunction(- effectPropStatus.interpolationFunction,- )- );-};-export const useExpandedTrackKeyframeRows = ({sequence,nodePathInfo,diff --git a/packages/studio/src/test/timeline-keyframes.test.ts b/packages/studio/src/test/timeline-keyframes.test.tsindex b381a27921..7bfcdc7306 100644--- a/packages/studio/src/test/timeline-keyframes.test.ts+++ b/packages/studio/src/test/timeline-keyframes.test.ts@@ -8,7 +8,6 @@ import {Internals, type PropStatuses} from 'remotion';import {getInspectorKeyframeSourceFrame} from '../components/InspectorPanel/keyframe-inspector-frame';import {findTrackForNodePathInfo} from '../components/Timeline/find-track-for-node-path-info';import {getNodeKeyframes} from '../components/Timeline/get-node-keyframes';-import {getTimelineEasingSegments} from '../components/Timeline/get-timeline-easing-segments';import {getKeyframeDisplayOffset,getTimelineKeyframes,@@ -482,23 +481,6 @@ test('keyframe display offsets respect the useCurrentFrame coordinate space', ()]);});-test('timeline easing segments connect adjacent display keyframes', () => {- const status: CanUpdateSequencePropStatusKeyframed = {- ...makeKeyframedStatus(),- keyframes: [- {frame: 0, value: 2},- {frame: 30, value: 3},- {frame: 60, value: 4},- ],- easing: [{type: 'linear'}, {type: 'linear'}],- };-- expect(getTimelineEasingSegments(getTimelineKeyframes(status, 30))).toEqual([- {fromFrame: 30, toFrame: 60, segmentIndex: 0},- {fromFrame: 60, toFrame: 90, segmentIndex: 1},- ]);-});-test('getNodeKeyframes shows a temporary sequence keyframe from drag overrides', () => {const nodePath = makeNodePath('sequence');diff --git a/packages/template-vibe-code/README.md b/packages/template-vibe-code/README.mdindex 7709c44ca1..f04d68a188 100644--- a/packages/template-vibe-code/README.md+++ b/packages/template-vibe-code/README.md@@ -6,6 +6,7 @@ A Remotion template that turns the browser into a motion graphics editor: write- **Canvas** – [`@remotion/canvas`](https://www.remotion.dev/docs/canvas) renders the composition with selection outlines. Click a layer on the canvas or in the timeline to select it, drag it to move it (it snaps to the edges and center of the composition, Shift locks the axis, ⌘ disables snapping) or nudge it with the arrow keys. Switch to “Interact” mode to use the composition’s own buttons and inputs.- **Timeline** – every mounted sequence shows up as a track. Drag a track to change its `from`, drag its edges to trim `durationInFrames`, split it at the playhead, duplicate, reorder, wrap and delete. In/out points, zoomable ruler, scrubbing.- **Keyframes** – props animated with `interpolate()` get a keyframe row under their track. Drag keyframes to retime them, click to select them (Shift and ⌘ extend the selection), double-click to jump to them, press ⌫ to delete them. In the inspector, a diamond next to each animatable prop adds or removes a keyframe at the playhead and the arrows jump to the neighboring keyframes.+- **Easing** – click the line between two keyframes to edit the easing of that segment: pick a preset (ease in/out, hold, springs), tweak the bezier handles or the spring parameters with live preview, or right-click the line for a preset. The same inspector edits the `interpolate()` options of the prop: extrapolation, `output` mode and `posterize`. ⌫ resets a selected easing to linear.- **Inspector** – edits props of the selected element directly in the source using [`@remotion/codemods`](https://www.remotion.dev/docs/codemods): position, scale, rotation, opacity, colors, typography, text content, timing and more. Animated props show their value at the playhead; editing one writes a keyframe there. Values computed in code are shown as such. Composition metadata (size, fps, duration) and `defaultProps` are editable too.- **Code editor** – Monaco with multiple files, tabs, compiler diagnostics and “Reveal in code” from any layer.- **Render** – export MP4/WebM videos and PNG/JPEG stills in the browser with [`@remotion/web-renderer`](https://www.remotion.dev/docs/web-renderer).@@ -73,6 +74,8 @@ Moving an outline on the canvas works the same way, but the Canvas owns the gestThe keyframe rows of the timeline read the `interpolate()` calls of each layer with `getNodeProps()` and place them on the composition timeline with [`getCanvasKeyframes()`](https://www.remotion.dev/docs/canvas/get-canvas-keyframes), which accounts for nested sequences and playback rates. Dragging a keyframe runs [`startCanvasKeyframeDrag()`](https://www.remotion.dev/docs/canvas/start-canvas-keyframe-drag) from `@remotion/canvas`: it previews the moved keyframes through `controller.overrides`, keeps them inside the composition, and reports the move when the pointer is released. The diamond buttons of the inspector are described by [`getCanvasKeyframeToggle()`](https://www.remotion.dev/docs/canvas/get-canvas-keyframe-toggle). Every keyframe edit is a `CanvasKeyframeChange`, which the editor passes to `updateNodeKeyframes()`.+The lines between keyframes come from [`getCanvasKeyframeEasingSegments()`](https://www.remotion.dev/docs/canvas/get-canvas-keyframe-easing-segments), which skips props whose easing cannot be edited, such as booleans. Picking a preset or dragging a parameter in the easing inspector builds a change with [`getCanvasKeyframeEasingChange()`](https://www.remotion.dev/docs/canvas/get-canvas-keyframe-easing-change) and the interpolation section uses [`getCanvasKeyframeSettings()`](https://www.remotion.dev/docs/canvas/get-canvas-keyframe-settings) and [`getCanvasKeyframeSettingsChange()`](https://www.remotion.dev/docs/canvas/get-canvas-keyframe-settings-change). Before a change is written, [`getCanvasKeyframeChangeOverride()`](https://www.remotion.dev/docs/canvas/get-canvas-keyframe-change-override) turns it into an override so the canvas shows the new curve immediately.+## Commands**Start the editor**diff --git a/packages/template-vibe-code/src/editor/components/EasingCurve.tsx b/packages/template-vibe-code/src/editor/components/EasingCurve.tsxnew file mode 100644index 0000000000..b9e04eec62--- /dev/null+++ b/packages/template-vibe-code/src/editor/components/EasingCurve.tsx@@ -0,0 +1,117 @@+import type { CanvasKeyframeEasing } from "@remotion/canvas";+import React, { useMemo } from "react";+import { Easing } from "remotion";+import { cn } from "@/lib/utils";+import { clamp } from "../model/values";++// Springs overshoot, so the plot leaves room above 1 and below 0.+const Y_MIN = -0.35;+const Y_MAX = 1.45;+const SAMPLES = 48;++const getEasingFunction = (+ easing: CanvasKeyframeEasing,+): ((progress: number) => number) => {+ switch (easing.type) {+ case "linear":+ return Easing.linear;+ case "step1":+ return Easing.step1;+ case "bezier":+ return Easing.bezier(easing.x1, easing.y1, easing.x2, easing.y2);+ case "spring":+ return Easing.spring({+ allowTail: easing.allowTail ?? undefined,+ damping: easing.damping,+ durationRestThreshold: easing.durationRestThreshold ?? undefined,+ mass: easing.mass,+ overshootClamping: easing.overshootClamping,+ stiffness: easing.stiffness,+ });+ default:+ throw new Error(+ `Unsupported easing: ${JSON.stringify(easing satisfies never)}`,+ );+ }+};++const getEasingPath = (+ easing: CanvasKeyframeEasing,+ width: number,+ height: number,+ padding: number,+): string => {+ const x = (progress: number) => padding + progress * (width - padding * 2);+ const y = (value: number) =>+ padding ++ ((Y_MAX - clamp(value, Y_MIN, Y_MAX)) / (Y_MAX - Y_MIN)) *+ (height - padding * 2);++ if (easing.type === "step1") {+ return `M ${x(0)} ${y(0)} L ${x(1)} ${y(0)} L ${x(1)} ${y(1)}`;+ }++ const fn = getEasingFunction(easing);+ return Array.from({ length: SAMPLES + 1 }, (_, index) => {+ const progress = index / SAMPLES;+ return `${index === 0 ? "M" : "L"} ${x(progress)} ${y(fn(progress))}`;+ }).join(" ");+};++/** Plots an easing from its start value (bottom left) to its end value (top right). */+export const EasingCurve: React.FC<{+ readonly easing: CanvasKeyframeEasing;+ readonly width: number;+ readonly height: number;+ readonly className?: string;+ /** Draws the 0 and 1 guide lines, for the large graph of the inspector. */+ readonly guides?: boolean;+}> = ({ easing, width, height, className, guides = false }) => {+ const padding = 4;+ const path = useMemo(+ () => getEasingPath(easing, width, height, padding),+ [easing, height, width],+ );+ const guideY = (value: number) =>+ padding + ((Y_MAX - value) / (Y_MAX - Y_MIN)) * (height - padding * 2);++ return (+ <svg+ viewBox={`0 0 ${width} ${height}`}+ width={width}+ height={height}+ className={cn("block shrink-0", className)}+ aria-hidden+ >+ {guides ? (+ <>+ <line+ x1={padding}+ x2={width - padding}+ y1={guideY(0)}+ y2={guideY(0)}+ className="stroke-border"+ strokeWidth={1}+ />+ <line+ x1={padding}+ x2={width - padding}+ y1={guideY(1)}+ y2={guideY(1)}+ className="stroke-border"+ strokeWidth={1}+ />+ </>+ ) : null}+ <path+ d={path}+ fill="none"+ stroke="currentColor"+ strokeWidth={guides ? 2 : 1.5}+ strokeLinecap="round"+ strokeLinejoin="round"+ vectorEffect="non-scaling-stroke"+ />+ </svg>+ );+};diff --git a/packages/template-vibe-code/src/editor/components/Inspector/EasingInspector.tsx b/packages/template-vibe-code/src/editor/components/Inspector/EasingInspector.tsxnew file mode 100644index 0000000000..47c2cad12a--- /dev/null+++ b/packages/template-vibe-code/src/editor/components/Inspector/EasingInspector.tsx@@ -0,0 +1,384 @@+"use client";++import {+ canvasKeyframeEasingPresets,+ getCanvasKeyframeSettings,+ getCanvasKeyframeSettingsChange,+ type CanvasKeyframeEasing,+ type CanvasKeyframeSettings,+} from "@remotion/canvas";+import { ChevronLeftIcon } from "lucide-react";+import React, { useState } from "react";+import type { ExtrapolateType, InterpolateOutputOption } from "remotion";+import { cn } from "@/lib/utils";+import {+ findKeyframedProp,+ getEasingChanges,+ type EasingSelectionItem,+ type KeyframedProp,+} from "../../model/keyframes";+import { getLayerLabel } from "../../model/layers";+import { getFieldLabel } from "../../model/schemas";+import { useEditor } from "../../state/editor-context";+import { EasingCurve } from "../EasingCurve";+import { BooleanField, FieldRow, NumberField, SelectField } from "./fields";++type BezierEasing = Extract<CanvasKeyframeEasing, { type: "bezier" }>;+type SpringEasing = Extract<CanvasKeyframeEasing, { type: "spring" }>;++export const areEasingsEqual = (+ first: CanvasKeyframeEasing,+ second: CanvasKeyframeEasing,+): boolean => {+ switch (first.type) {+ case "linear":+ case "step1":+ return first.type === second.type;+ case "bezier":+ return (+ second.type === "bezier" &&+ first.x1 === second.x1 &&+ first.y1 === second.y1 &&+ first.x2 === second.x2 &&+ first.y2 === second.y2+ );+ case "spring":+ return (+ second.type === "spring" &&+ first.damping === second.damping &&+ first.mass === second.mass &&+ first.stiffness === second.stiffness &&+ first.overshootClamping === second.overshootClamping &&+ (first.allowTail ?? null) === (second.allowTail ?? null) &&+ (first.durationRestThreshold ?? null) ===+ (second.durationRestThreshold ?? null)+ );+ default:+ throw new Error(+ `Unsupported easing: ${JSON.stringify(first satisfies never)}`,+ );+ }+};++type EasingFieldsProps<Easing extends CanvasKeyframeEasing> = {+ readonly easing: Easing;+ /** Shows the easing on the canvas while a value is being dragged. */+ readonly onPreview: (easing: Easing) => void;+ readonly onCommit: (easing: Easing) => void;+ readonly onCancel: () => void;+};++const BezierFields: React.FC<EasingFieldsProps<BezierEasing>> = ({+ easing,+ onPreview,+ onCommit,+ onCancel,+}) => {+ // Control points must stay inside the time axis; the value axis may+ // overshoot, which is how "back" easings are written.+ const coordinate = (key: keyof Omit<BezierEasing, "type">, label: string) => (+ <NumberField+ ariaLabel={label}+ unit={label}+ value={easing[key]}+ min={key.startsWith("x") ? 0 : -2}+ max={key.startsWith("x") ? 1 : 3}+ step={0.01}+ onLiveChange={(value) => onPreview({ ...easing, [key]: value })}+ onCommit={(value) => onCommit({ ...easing, [key]: value ?? easing[key] })}+ onCancel={onCancel}+ />+ );++ return (+ <>+ <FieldRow label="Handle 1">+ {coordinate("x1", "X1")}+ {coordinate("y1", "Y1")}+ </FieldRow>+ <FieldRow label="Handle 2">+ {coordinate("x2", "X2")}+ {coordinate("y2", "Y2")}+ </FieldRow>+ </>+ );+};++const springLimits = {+ damping: { min: 1, max: 200, step: 1 },+ mass: { min: 0.1, max: 20, step: 0.1 },+ stiffness: { min: 1, max: 1000, step: 1 },+} as const;++const SpringFields: React.FC<EasingFieldsProps<SpringEasing>> = ({+ easing,+ onPreview,+ onCommit,+ onCancel,+}) => {+ const parameter = (key: keyof typeof springLimits, label: string) => (+ <FieldRow label={label}>+ <NumberField+ ariaLabel={label}+ value={easing[key]}+ {...springLimits[key]}+ onLiveChange={(value) => onPreview({ ...easing, [key]: value })}+ onCommit={(value) =>+ onCommit({ ...easing, [key]: value ?? easing[key] })+ }+ onCancel={onCancel}+ />+ </FieldRow>+ );++ return (+ <>+ {parameter("damping", "Damping")}+ {parameter("mass", "Mass")}+ {parameter("stiffness", "Stiffness")}+ <FieldRow label="Clamp overshoot">+ <BooleanField+ ariaLabel="Clamp overshoot"+ value={easing.overshootClamping}+ onCommit={(overshootClamping) =>+ onCommit({ ...easing, overshootClamping })+ }+ />+ </FieldRow>+ </>+ );+};++const capitalize = (value: string) => value[0].toUpperCase() + value.slice(1);++/** The `interpolate()` options of the prop a segment belongs to. */+const InterpolationSettings: React.FC<{ readonly prop: KeyframedProp }> = ({+ prop,+}) => {+ const { actions } = useEditor();+ const settings = getCanvasKeyframeSettings(prop.propStatus);+ const { clamping } = settings;+ const apply = (next: CanvasKeyframeSettings) => {+ void actions.applyKeyframeChanges([+ getCanvasKeyframeSettingsChange({+ nodePathInfo: prop.layer.nodePathInfo,+ schema: prop.schema,+ key: prop.key,+ propStatus: prop.propStatus,+ settings: next,+ }),+ ]);+ };+ const extrapolateOptions = settings.extrapolateTypes.map((type) => ({+ value: type,+ label: capitalize(type),+ }));++ return (+ <section className="flex flex-col gap-2">+ <h3 className="text-muted-foreground-dim text-[10px] font-semibold tracking-wide uppercase">+ Interpolation+ </h3>+ {clamping ? (+ <>+ <FieldRow label={<span title="extrapolateLeft">Before start</span>}>+ <SelectField+ ariaLabel="Extrapolate left"+ value={clamping.left}+ options={extrapolateOptions}+ onCommit={(left) =>+ apply({+ ...settings,+ clamping: { ...clamping, left: left as ExtrapolateType },+ })+ }+ />+ </FieldRow>+ <FieldRow label={<span title="extrapolateRight">After end</span>}>+ <SelectField+ ariaLabel="Extrapolate right"+ value={clamping.right}+ options={extrapolateOptions}+ onCommit={(right) =>+ apply({+ ...settings,+ clamping: { ...clamping, right: right as ExtrapolateType },+ })+ }+ />+ </FieldRow>+ </>+ ) : null}+ {settings.output ? (+ <FieldRow label="Output">+ <SelectField+ ariaLabel="Output"+ value={settings.output}+ options={[+ { value: "linear", label: "Linear" },+ { value: "perceptual-scale", label: "Perceptual scale" },+ ]}+ onCommit={(output) =>+ apply({ ...settings, output: output as InterpolateOutputOption })+ }+ />+ </FieldRow>+ ) : null}+ <FieldRow label="Posterize">+ <NumberField+ ariaLabel="Posterize"+ value={settings.posterize}+ placeholder="Every frame"+ unit="frames"+ min={0}+ step={1}+ integer+ allowEmpty+ onCommit={(posterize) =>+ apply({+ ...settings,+ posterize:+ posterize === null || posterize <= 0 ? null : posterize,+ })+ }+ onCancel={null}+ />+ </FieldRow>+ </section>+ );+};++/**+ * Edits the easing of the selected segments between keyframes. Presets and+ * parameter changes are previewed on the canvas through overrides and then+ * written to the `interpolate()` call.+ */+export const EasingInspector: React.FC<{+ readonly items: readonly EasingSelectionItem[];+}> = ({ items }) => {+ const { keyframedProps, actions } = useEditor();+ // While a parameter is being dragged, the graph follows the draft.+ const [draft, setDraft] = useState<CanvasKeyframeEasing | null>(null);+ const targets = items.flatMap((item) => {+ const prop = findKeyframedProp(keyframedProps, item);+ const segment = prop?.easingSegments.find(+ (candidate) => candidate.segmentIndex === item.segmentIndex,+ );+ return prop && segment ? [{ prop, segment }] : [];+ });+ const first = targets[0];+ if (!first) {+ return (+ <p className="text-muted-foreground p-3 text-[11px] leading-relaxed">+ The selected easing is no longer in the source.+ </p>+ );+ }++ const { prop, segment } = first;+ const easing = draft ?? segment.easing;+ const changesFor = (next: CanvasKeyframeEasing) =>+ getEasingChanges({ items, keyframedProps, easing: next });+ const preview = (next: CanvasKeyframeEasing) => {+ setDraft(next);+ actions.previewKeyframeChanges(changesFor(next));+ };+ const commit = (next: CanvasKeyframeEasing) => {+ setDraft(null);+ void actions.applyEasing(items, next);+ };+ const cancel = () => {+ setDraft(null);+ actions.cancelKeyframePreviews(changesFor(easing));+ };++ return (+ <div className="flex flex-col gap-4 p-3">+ <div className="flex flex-col gap-1">+ <button+ type="button"+ className="text-muted-foreground hover:text-foreground flex items-center gap-1 self-start text-[11px]"+ onClick={() =>+ actions.selectLayer(prop.layer, {+ shiftKey: false,+ toggleKey: false,+ })+ }+ >+ <ChevronLeftIcon className="size-3" />+ {getLayerLabel(prop.layer)}+ </button>+ <div className="text-sm font-medium">+ {getFieldLabel(prop.key, prop.field)} easing+ </div>+ <div className="text-muted-foreground-dim text-[10px]">+ Frames {segment.fromFrame} – {segment.toFrame}+ {targets.length > 1 ? ` · ${targets.length} segments selected` : ""}+ </div>+ </div>+ <div className="border-border text-primary rounded-md border p-2">+ <EasingCurve+ easing={easing}+ width={240}+ height={140}+ guides+ className="h-auto w-full"+ />+ </div>+ <section className="flex flex-col gap-2">+ <h3 className="text-muted-foreground-dim text-[10px] font-semibold tracking-wide uppercase">+ Presets+ </h3>+ <div className="grid grid-cols-4 gap-1.5">+ {canvasKeyframeEasingPresets.map((preset) => {+ const selected = areEasingsEqual(easing, preset.easing);+ return (+ <button+ key={preset.id}+ type="button"+ title={preset.label}+ aria-label={`Apply ${preset.label} easing`}+ aria-pressed={selected}+ className={cn(+ "flex h-9 items-center justify-center rounded-md border",+ selected+ ? "border-primary bg-primary/15 text-primary"+ : "border-border text-muted-foreground hover:bg-accent hover:text-foreground",+ )}+ onClick={() => commit(preset.easing)}+ >+ <EasingCurve easing={preset.easing} width={32} height={22} />+ </button>+ );+ })}+ </div>+ </section>+ {easing.type === "bezier" ? (+ <section className="flex flex-col gap-2">+ <h3 className="text-muted-foreground-dim text-[10px] font-semibold tracking-wide uppercase">+ Bezier+ </h3>+ <BezierFields+ easing={easing}+ onPreview={preview}+ onCommit={commit}+ onCancel={cancel}+ />+ </section>+ ) : easing.type === "spring" ? (+ <section className="flex flex-col gap-2">+ <h3 className="text-muted-foreground-dim text-[10px] font-semibold tracking-wide uppercase">+ Spring+ </h3>+ <SpringFields+ easing={easing}+ onPreview={preview}+ onCommit={commit}+ onCancel={cancel}+ />+ </section>+ ) : null}+ <InterpolationSettings prop={prop} />+ </div>+ );+};diff --git a/packages/template-vibe-code/src/editor/components/Inspector/InspectorPanel.tsx b/packages/template-vibe-code/src/editor/components/Inspector/InspectorPanel.tsxindex 896be1e5fb..e2fef70692 100644--- a/packages/template-vibe-code/src/editor/components/Inspector/InspectorPanel.tsx+++ b/packages/template-vibe-code/src/editor/components/Inspector/InspectorPanel.tsx@@ -8,10 +8,12 @@ import React, { useMemo } from "react";import { Button } from "@/components/ui/button";import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";import { getSelectedNodes } from "../../hooks/use-editor-shortcuts";+import { getSelectedEasings } from "../../model/keyframes";import { getLayerLabel } from "../../model/layers";import { useEditor } from "../../state/editor-context";import { fallbackSelectionController } from "../../state/fallback-selection";import { CompositionInspector } from "./CompositionInspector";+import { EasingInspector } from "./EasingInspector";import { LayerInspector } from "./LayerInspector";import { RendersPanel } from "./RendersPanel";@@ -28,6 +30,16 @@ const SelectionInspector: React.FC = () => {keys.has(getCanvasSelectionItemKey(layer.selectionItem)),);}, [layers, selection.selectedItems]);+ const selectedEasings = getSelectedEasings(selection.selectedItems);++ if (selectedEasings.length > 0) {+ return (+ <EasingInspector+ key={selectedEasings.map(getCanvasSelectionItemKey).join("\n")}+ items={selectedEasings}+ />+ );+ }if (selectedLayers.length === 0) {return <CompositionInspector />;diff --git a/packages/template-vibe-code/src/editor/components/Timeline/Timeline.tsx b/packages/template-vibe-code/src/editor/components/Timeline/Timeline.tsxindex b43c487978..d4f3575232 100644--- a/packages/template-vibe-code/src/editor/components/Timeline/Timeline.tsx+++ b/packages/template-vibe-code/src/editor/components/Timeline/Timeline.tsx@@ -1,11 +1,13 @@"use client";import {+ canvasKeyframeEasingPresets,getCanvasSelectionItemKey,startCanvasKeyframeDrag,useCanvasSelection,useCanvasSequenceHover,type CanvasKeyframeDragTarget,+ type CanvasKeyframeEasingSegment,type CanvasSelectionInteraction,} from "@remotion/canvas";import { getNodeProps } from "@remotion/codemods";@@ -27,12 +29,20 @@ import React, {useRef,useState,} from "react";+import {+ ContextMenu,+ ContextMenuContent,+ ContextMenuItem,+ ContextMenuTrigger,+} from "@/components/ui/context-menu";import { cn } from "@/lib/utils";import { usePlaybackFrame } from "../../hooks/use-playback";import { getErrorMessage } from "../../hooks/use-preview-host";import {findKeyframedProp,+ getEasingSelectionItem,getKeyframeSelectionItem,+ getSelectedEasings,getSelectedKeyframes,type KeyframedProp,type KeyframeSelectionItem,@@ -50,6 +60,7 @@ import {import { clamp, formatTimecode } from "../../model/values";import { useEditor } from "../../state/editor-context";import { fallbackSelectionController } from "../../state/fallback-selection";+import { EasingCurve } from "../EasingCurve";import { LayerContextMenu } from "../Inspector/LayerActions";import { KeyframeDiamond } from "../KeyframeDiamond";import { ToolbarButton } from "../TopBar";@@ -345,6 +356,96 @@ const TrackRow = memo(function TrackRow({);});+/**+ * The line between two keyframes. Clicking it selects the segment so the+ * inspector can edit its easing; the context menu applies a preset directly.+ */+const EasingSegment: React.FC<{+ readonly prop: KeyframedProp;+ readonly segment: CanvasKeyframeEasingSegment;+ readonly label: string;+ readonly pxPerFrame: number;+ readonly selectedKeys: ReadonlySet<string>;+ readonly keyframeDrag: KeyframeDragState | null;+}> = ({ prop, segment, label, pxPerFrame, selectedKeys, keyframeDrag }) => {+ const { host, actions } = useEditor();+ const item = getEasingSelectionItem(prop, segment);+ const selected = selectedKeys.has(getCanvasSelectionItemKey(item));+ // The line follows the dragged keyframes at its ends.+ const shift = (frame: number) =>+ keyframeDrag?.keys.has(+ getCanvasSelectionItemKey(getKeyframeSelectionItem(prop, frame)),+ )+ ? frame + keyframeDrag.delta+ : frame;+ const from = shift(segment.fromFrame);+ const to = shift(segment.toFrame);++ return (+ <ContextMenu>+ <ContextMenuTrigger asChild>+ <button+ type="button"+ aria-label={`${label} easing from frame ${segment.fromFrame} to ${segment.toFrame}`}+ aria-pressed={selected}+ className="group/easing absolute top-1/2 flex h-3 -translate-y-1/2 items-center px-1"+ style={{+ left: Math.min(from, to) * pxPerFrame,+ width: Math.abs(to - from) * pxPerFrame,+ }}+ onPointerDown={(event) => {+ if (event.button !== 0) {+ return;+ }++ event.preventDefault();+ event.stopPropagation();+ actions.selectKeyframes([item], {+ shiftKey: event.shiftKey,+ toggleKey: event.metaKey || event.ctrlKey,+ });+ }}+ >+ <div+ className={cn(+ "h-0.5 w-full rounded-full",+ selected+ ? "bg-primary"+ : "bg-border group-hover/easing:bg-muted-foreground",+ )}+ />+ </button>+ </ContextMenuTrigger>+ <ContextMenuContent+ onCloseAutoFocus={(event) => event.preventDefault()}+ className="min-w-[160px]"+ >+ {canvasKeyframeEasingPresets.map((preset) => (+ <ContextMenuItem+ key={preset.id}+ onSelect={() => {+ // A preset from the menu of a selected segment applies to the+ // whole selection, like in the Studio.+ const selectedEasings = getSelectedEasings(+ host?.controller.selection.getSnapshot().selectedItems ?? [],+ );+ void actions.applyEasing(+ selected && selectedEasings.length > 0+ ? selectedEasings+ : [item],+ preset.easing,+ );+ }}+ >+ <EasingCurve easing={preset.easing} width={18} height={14} />+ {preset.label}+ </ContextMenuItem>+ ))}+ </ContextMenuContent>+ </ContextMenu>+ );+};+/** A row with the keyframes of one animated prop, below its layer. */const KeyframeRow = memo(function KeyframeRow({prop,@@ -392,6 +493,17 @@ const KeyframeRow = memo(function KeyframeRow({style={{ width: durationInFrames * pxPerFrame }}data-track-area>+ {prop.easingSegments.map((segment) => (+ <EasingSegment+ key={segment.segmentIndex}+ prop={prop}+ segment={segment}+ label={label}+ pxPerFrame={pxPerFrame}+ selectedKeys={selectedKeys}+ keyframeDrag={keyframeDrag}+ />+ ))}{prop.keyframes.map((keyframe) => {if (keyframe.frame < 0 || keyframe.frame >= durationInFrames) {return null;@@ -848,7 +960,8 @@ export const Timeline: React.FC = () => {<span className="flex-1" /><span className="text-muted-foreground-dim hidden font-mono text-[10px] lg:inline">Drag a layer to move it · drag its edges to trim · drag keyframes to- retime them · ⌥ + scroll to zoom+ retime them · click between keyframes to edit the easing · ⌥ + scroll+ to zoom</span><ToolbarButtonsize="icon-xs"diff --git a/packages/template-vibe-code/src/editor/hooks/use-editor-actions.ts b/packages/template-vibe-code/src/editor/hooks/use-editor-actions.tsindex f18bfcd526..b1dd87f9b6 100644--- a/packages/template-vibe-code/src/editor/hooks/use-editor-actions.ts+++ b/packages/template-vibe-code/src/editor/hooks/use-editor-actions.ts@@ -1,9 +1,11 @@"use client";import {+ getCanvasKeyframeChangeOverride,getCanvasKeyframeToggle,getCanvasSelectionItemKey,type CanvasKeyframeChange,+ type CanvasKeyframeEasing,type CanvasSelectionInteraction,type CanvasSequencePropChange,type SequenceNodePathInfo,@@ -38,7 +40,10 @@ import {type SequencePropUpdate,} from "@remotion/codemods";import { useMemo, useRef } from "react";-import type { InteractivitySchema } from "remotion";+import type {+ CanUpdateSequencePropStatus,+ InteractivitySchema,+} from "remotion";import type {PreviewHost,PreviewRenderRequest,@@ -48,8 +53,11 @@ import type { CompositionInfo } from "../model/compositions";import { formatSource } from "../model/format";import {findKeyframedProp,+ getEasingChanges,+ getEasingSelectionItem,getKeyframeSelectionItem,getSelectedKeyframes,+ type EasingSelectionItem,type KeyframedProp,type KeyframeSelectionItem,} from "../model/keyframes";@@ -368,6 +376,55 @@ export const useEditorActions = ({return ok;};+ /**+ * Shows keyframe changes on the canvas before they are written, e.g.+ * while an easing curve is being dragged. Changes of the same prop are+ * applied on top of each other.+ */+ const previewKeyframeChanges = (+ changes: readonly CanvasKeyframeChange[],+ ) => {+ const controller = ref.current.host?.controller;+ if (!controller) {+ return;+ }++ const statuses = new Map<string, CanUpdateSequencePropStatus>();+ for (const change of changes) {+ const sequenceKey = getCanvasSelectionItemKey({+ type: "sequence",+ nodePathInfo: change.nodePathInfo,+ });+ const propKey = `${sequenceKey}\0${change.key}`;+ const propStatus =+ statuses.get(propKey) ??+ ref.current.keyframedProps.find(+ (prop) =>+ prop.key === change.key &&+ getCanvasSelectionItemKey(prop.layer.selectionItem) ===+ sequenceKey,+ )?.propStatus;+ if (!propStatus) {+ continue;+ }++ const override = getCanvasKeyframeChangeOverride({+ propStatus,+ change,+ });+ if (override === null) {+ continue;+ }++ if (override.type === "keyframed") {+ statuses.set(propKey, override.status);+ }++ controller.overrides.set(change.nodePathInfo, change.key, override);+ pendingPreviews.set(sequenceKey, change.nodePathInfo);+ }+ };+const setZoom = (zoom: PreviewZoom) => {dispatch({ type: "set-playback", patch: { zoom } });};@@ -677,6 +734,38 @@ export const ${componentName}: React.FC = () => {*/commitKeyframeChanges: (changes: readonly CanvasKeyframeChange[]) =>commitNodeChanges(groupNodeChanges(changes)),+ previewKeyframeChanges,+ /** Drops the previews of keyframe changes without writing them. */+ cancelKeyframePreviews: (changes: readonly CanvasKeyframeChange[]) => {+ const controller = ref.current.host?.controller;+ for (const { nodePathInfo } of changes) {+ pendingPreviews.delete(+ getCanvasSelectionItemKey({ type: "sequence", nodePathInfo }),+ );+ controller?.overrides.clear(nodePathInfo);+ }+ },+ /**+ * Shows keyframe changes on the canvas right away and writes them to+ * the source, e.g. an easing preset or interpolation settings.+ */+ applyKeyframeChanges: (changes: readonly CanvasKeyframeChange[]) => {+ previewKeyframeChanges(changes);+ return commitNodeChanges(groupNodeChanges(changes));+ },+ /** Gives the easing segments the same easing. */+ applyEasing: (+ items: readonly EasingSelectionItem[],+ easing: CanvasKeyframeEasing,+ ) => {+ const changes = getEasingChanges({+ items,+ keyframedProps: ref.current.keyframedProps,+ easing,+ });+ previewKeyframeChanges(changes);+ return commitNodeChanges(groupNodeChanges(changes));+ },/** Removes the keyframes that are selected on the timeline. */deleteSelectedKeyframes: () => {const { host, keyframedProps, compositionDurationInFrames } =@@ -723,8 +812,13 @@ export const ${componentName}: React.FC = () => {);return commitNodeChanges(groupNodeChanges(changes));},+ /**+ * Selects keyframes and easing segments. With an interaction, Shift+ * selects the range between the anchor and the item along the keyframe+ * rows, where segments sit between their keyframes.+ */selectKeyframes: (- items: readonly KeyframeSelectionItem[],+ items: readonly (KeyframeSelectionItem | EasingSelectionItem)[],interaction: CanvasSelectionInteraction | null,) => {const { host, keyframedProps } = ref.current;@@ -742,9 +836,15 @@ export const ${componentName}: React.FC = () => {item,interaction,keyframedProps.flatMap((prop) =>- prop.keyframes.map((keyframe) =>- getKeyframeSelectionItem(prop, keyframe.frame),- ),+ prop.keyframes.flatMap((keyframe, index) => {+ const segment = prop.easingSegments.find(+ (candidate) => candidate.segmentIndex === index,+ );+ return [+ getKeyframeSelectionItem(prop, keyframe.frame),+ ...(segment ? [getEasingSelectionItem(prop, segment)] : []),+ ];+ }),),);},diff --git a/packages/template-vibe-code/src/editor/hooks/use-editor-shortcuts.ts b/packages/template-vibe-code/src/editor/hooks/use-editor-shortcuts.tsindex 83724c798a..2ab4a116e0 100644--- a/packages/template-vibe-code/src/editor/hooks/use-editor-shortcuts.ts+++ b/packages/template-vibe-code/src/editor/hooks/use-editor-shortcuts.ts@@ -4,6 +4,7 @@ import { getCanvasSelectionItemKey } from "@remotion/canvas";import { useCallback, useEffect, useRef } from "react";import type { PreviewHost, PreviewKeyEvent } from "@/preview/bridge";import type { CompositionInfo } from "../model/compositions";+import { getSelectedEasings } from "../model/keyframes";import { getNodeReference, type Layer } from "../model/layers";import type { EditorState } from "../state/editor-store";import type { EditorActions } from "./use-editor-actions";@@ -172,15 +173,20 @@ export const useEditorShortcuts = ({case "Backspace":case "Delete": {if (event.repeat) return true;- if (- host?.controller.selection- .getSnapshot()- .selectedItems.some((item) => item.type === "keyframe")- ) {+ const selectedItems =+ host?.controller.selection.getSnapshot().selectedItems ?? [];+ if (selectedItems.some((item) => item.type === "keyframe")) {void actions.deleteSelectedKeyframes();return true;}+ // Like in the Studio, deleting an easing segment makes it linear.+ const selectedEasings = getSelectedEasings(selectedItems);+ if (selectedEasings.length > 0) {+ void actions.applyEasing(selectedEasings, { type: "linear" });+ return true;+ }+const selectedNodes = getSelectedNodes(host, layers);if (selectedNodes.length > 0) {void actions.deleteNodes(selectedNodes);diff --git a/packages/template-vibe-code/src/editor/model/keyframes.ts b/packages/template-vibe-code/src/editor/model/keyframes.tsindex cae4659028..6a7ae1b642 100644--- a/packages/template-vibe-code/src/editor/model/keyframes.ts+++ b/packages/template-vibe-code/src/editor/model/keyframes.ts@@ -1,7 +1,12 @@import {+ getCanvasKeyframeEasingChange,+ getCanvasKeyframeEasingSegments,getCanvasKeyframes,getCanvasSelectionItemKey,type CanvasKeyframe,+ type CanvasKeyframeChange,+ type CanvasKeyframeEasing,+ type CanvasKeyframeEasingSegment,type CanvasSelectionItem,type SequenceNodePathInfo,} from "@remotion/canvas";@@ -24,6 +29,8 @@ export type KeyframedProp = {propStatus: CanUpdateSequencePropStatusKeyframed;/** The keyframes placed on the composition timeline. */keyframes: CanvasKeyframe[];+ /** The spans between the keyframes whose easing can be edited. */+ easingSegments: CanvasKeyframeEasingSegment[];/** Identifies the prop in the Canvas selection, e.g. for its keyframes. */nodePathInfo: SequenceNodePathInfo;};@@ -33,6 +40,11 @@ export type KeyframeSelectionItem = Extract<{ type: "keyframe" }>;+export type EasingSelectionItem = Extract<+ CanvasSelectionItem,+ { type: "easing" }+>;+/*** The selection identity of a prop's keyframe row. The Canvas keeps keyframe* selection items under the sequence with the schema key as auxiliary path,@@ -55,6 +67,17 @@ export const getKeyframeSelectionItem = (frame,});+export const getEasingSelectionItem = (+ prop: Pick<KeyframedProp, "nodePathInfo">,+ segment: CanvasKeyframeEasingSegment,+): EasingSelectionItem => ({+ type: "easing",+ nodePathInfo: prop.nodePathInfo,+ fromFrame: segment.fromFrame,+ toFrame: segment.toFrame,+ segmentIndex: segment.segmentIndex,+});+const getKeyframedPropKey = (prop: Pick<KeyframedProp, "nodePathInfo">) =>getCanvasSelectionItemKey({type: "sequence-prop",@@ -110,6 +133,12 @@ export const getKeyframedProps = ({schema,propStatus,keyframes: getCanvasKeyframes({ track: layer.track, propStatus }),+ easingSegments: getCanvasKeyframeEasingSegments({+ track: layer.track,+ schema,+ key,+ propStatus,+ }),nodePathInfo,},];@@ -124,11 +153,43 @@ export const getSelectedKeyframes = ((item): item is KeyframeSelectionItem => item.type === "keyframe",);-/** Finds the keyframed prop a selected keyframe belongs to. */+export const getSelectedEasings = (+ selectedItems: readonly CanvasSelectionItem[],+): EasingSelectionItem[] =>+ selectedItems.filter(+ (item): item is EasingSelectionItem => item.type === "easing",+ );++/** Finds the keyframed prop a selected keyframe or easing segment belongs to. */export const findKeyframedProp = (props: readonly KeyframedProp[],- item: KeyframeSelectionItem,+ item: Pick<KeyframedProp, "nodePathInfo">,): KeyframedProp | null => {- const key = getKeyframedPropKey({ nodePathInfo: item.nodePathInfo });+ const key = getKeyframedPropKey(item);return props.find((prop) => getKeyframedPropKey(prop) === key) ?? null;};++/** The changes that give the selected easing segments the same easing. */+export const getEasingChanges = ({+ items,+ keyframedProps,+ easing,+}: {+ items: readonly EasingSelectionItem[];+ keyframedProps: readonly KeyframedProp[];+ easing: CanvasKeyframeEasing;+}): CanvasKeyframeChange[] =>+ items.flatMap((item) => {+ const prop = findKeyframedProp(keyframedProps, item);+ const change =+ prop &&+ getCanvasKeyframeEasingChange({+ nodePathInfo: prop.layer.nodePathInfo,+ schema: prop.schema,+ key: prop.key,+ propStatus: prop.propStatus,+ segmentIndex: item.segmentIndex,+ easing,+ });+ return change ? [change] : [];+ });diff --git a/packages/template-vibe-code/src/editor/model/shortcuts.ts b/packages/template-vibe-code/src/editor/model/shortcuts.tsindex cd0829e884..8e62cabba0 100644--- a/packages/template-vibe-code/src/editor/model/shortcuts.ts+++ b/packages/template-vibe-code/src/editor/model/shortcuts.ts@@ -30,7 +30,10 @@ export const shortcutGroups: ShortcutGroup[] = [{ keys: ["X"], description: "Clear in / out" },{ keys: ["⌘ A"], description: "Select all layers" },{ keys: ["Esc"], description: "Clear selection" },- { keys: ["⌫"], description: "Delete selected layers or keyframes" },+ {+ keys: ["⌫"],+ description: "Delete selected layers or keyframes, reset easings",+ },{ keys: ["⌘ D"], description: "Duplicate selected layers" },{ keys: ["⌘ ⇧ D"], description: "Split selected layers at playhead" },{ keys: ["⌥ ↑", "⌥ ↓"], description: "Move layer up / down" },