🎥 Make videos programmatically with React
import {expect, test} from 'bun:test';
import {mkdtempSync, readFileSync, rmSync, writeFileSync} from 'node:fs';
import {tmpdir} from 'node:os';
import path from 'node:path';
import {NoReactInternals} from 'remotion/no-react';
import {parseAst} from '../codemods/parse-ast';
import {JsxElementIdentityMismatchError} from '../preview-server/jsx-component-identity';
import {
computeSequencePropsStatus,
computeSequencePropsStatusFromContent,
computeSequencePropsStatusFromFilenameByLocation,
lineColumnToNodePath,
lineColumnsToNodePaths,
} from '../preview-server/routes/can-update-sequence-props';
const getNodePath = (filePath: string, line: number) => {
const content = readFileSync(filePath, 'utf-8');
const ast = parseAst(content);
const result = lineColumnToNodePath(ast, line);
if (!result) {
throw new Error(`No JSX element found at line ${line} in ${filePath}`);
}
return result;
};
const getNodePathFromContent = (content: string, line: number) => {
const ast = parseAst(content);
const result = lineColumnToNodePath(ast, line);
if (!result) {
throw new Error(`No JSX element found at line ${line}`);
}
return result;
};
const videoConfigValues = {
durationInFrames: 120,
fps: 30,
height: 1080,
width: 1920,
};
const getSourceLocation = (source: string, search: string) => {
const index = source.indexOf(search);
if (index === -1) {
throw new Error(`Could not find ${search}`);
}
const linesBeforeMatch = source.slice(0, index).split('\n');
return {
line: linesBeforeMatch.length,
column: linesBeforeMatch.at(-1)?.length ?? 0,
};
};
test('computeSequencePropsStatus should distinguish JSX elements on the same line', () => {
const input = `import React from 'react';
import {AbsoluteFill, Sequence} from 'remotion';
export const Example: React.FC = () => {
return <AbsoluteFill><Sequence name="Hook" durationInFrames={150}><HeroScene /></Sequence><Sequence name="Create" from={150} durationInFrames={150}><CreateScene /></Sequence></AbsoluteFill>;
};
export const Fallback = () => <><Sequence name="First" /><Sequence name="Fallback" from={300} /></>;
`;
const remotionRoot = mkdtempSync(
path.join(tmpdir(), 'remotion-jsx-location-'),
);
const fileName = 'Example.tsx';
writeFileSync(path.join(remotionRoot, fileName), input);
try {
const getStatus = (search: string, columnOffset = 0) => {
const location = getSourceLocation(input, search);
return computeSequencePropsStatusFromFilenameByLocation({
fileContentsCache: null,
fileName,
line: location.line,
column: location.column + columnOffset,
componentIdentity: 'dev.remotion.remotion.Sequence',
keys: ['name', 'from'],
effects: [],
remotionRoot,
logLevel: 'info',
});
};
const hook = getStatus('<Sequence name="Hook"');
expect(hook.success).toBe(true);
if (!hook.success) {
throw new Error('Expected the Hook sequence to be found');
}
expect(hook.status.props.name).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'Hook',
});
const create = getStatus('<Sequence name="Create"');
expect(create.success).toBe(true);
if (!create.success) {
throw new Error('Expected the Create sequence to be found');
}
expect(create.status.props).toMatchObject({
name: {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'Create',
},
from: {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 150,
},
});
const child = getStatus('<HeroScene');
expect(child).toEqual({
success: false,
status: {canUpdate: false, reason: 'not-found'},
});
const fallback = getStatus('<Sequence name="Fallback"', 1);
expect(fallback.success).toBe(true);
if (!fallback.success) {
throw new Error('Expected the line fallback to find the last sequence');
}
expect(fallback.status.props).toMatchObject({
name: {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'Fallback',
},
from: {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 300,
},
});
} finally {
rmSync(remotionRoot, {recursive: true, force: true});
}
});
test('lineColumnsToNodePaths matches individual location resolution', () => {
const input = `export const Example = () => (
<div><span /><span><strong /></span></div>
);`;
const ast = parseAst(input);
const targets = [
getSourceLocation(input, '<div>'),
getSourceLocation(input, '<span />'),
getSourceLocation(input, '<span><strong'),
getSourceLocation(input, '<strong'),
{...getSourceLocation(input, '<strong'), column: 999},
];
expect(lineColumnsToNodePaths({ast, targets, fileContents: input})).toEqual(
targets.map(({line, column}) =>
lineColumnToNodePath(ast, line, column, input),
),
);
});
test('computeSequencePropsStatus should ignore source locations outside the project', () => {
const remotionRoot = mkdtempSync(
path.join(tmpdir(), 'remotion-jsx-location-'),
);
try {
expect(
computeSequencePropsStatusFromFilenameByLocation({
fileContentsCache: null,
fileName: '../studio/RefreshCompositionOverlay.js',
line: 1,
column: 1,
componentIdentity: null,
keys: [],
effects: [],
remotionRoot,
logLevel: 'info',
}),
).toEqual({
success: false,
status: {canUpdate: false, reason: 'not-found'},
});
} finally {
rmSync(remotionRoot, {recursive: true, force: true});
}
});
test('computeSequencePropsStatus should treat staticFile() asset props as static', () => {
const input = `import {Img, staticFile} from 'remotion';
export const Example = () => {
return <Img src={staticFile('1.jpg')} />;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 4),
componentIdentity: null,
keys: ['src'],
assetKeys: ['src'],
effects: [],
});
expect(result.props.src).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: `${NoReactInternals.FILE_TOKEN}1.jpg`,
});
});
// https://github.com/remotion-dev/remotion/issues/10717
// Props passed via a JSX spread are invisible to the parser. Reporting them as
// static(undefined) made the Studio delete the runtime values of `from` /
// `durationInFrames`, mounting every <Sequence> at every frame.
test('computeSequencePropsStatus should treat props that a spread attribute may override as computed', () => {
const input = `import {Sequence} from 'remotion';
export const Example = ({timing}: {timing: {from: number; durationInFrames: number}}) => {
return (
<>
<Sequence from={10} {...timing} name="Scene" style={{opacity: 0.5}}>
<div />
</Sequence>
<Sequence {...timing} />
</>
);
};
`;
const spreadMayOverride = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 6),
componentIdentity: null,
keys: ['from', 'durationInFrames', 'name', 'style.opacity'],
effects: [],
});
expect(spreadMayOverride.props).toEqual({
// Written before the spread, so the spread may override it
from: {status: 'computed'},
// Only provided by the spread
durationInFrames: {status: 'computed'},
// Written after the spread, so they win at runtime and stay editable
name: {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'Scene',
},
'style.opacity': {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 0.5,
},
});
const spreadMayProvide = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 9),
componentIdentity: null,
keys: ['from', 'children'],
effects: [],
});
// With an empty element body, the spread may provide both props
expect(spreadMayProvide.props).toEqual({
from: {status: 'computed'},
children: {status: 'computed'},
});
});
test('computeSequencePropsStatus should parse video config numeric expressions', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame, useVideoConfig} from 'remotion';
export const Example: React.FC = () => {
const frame = useCurrentFrame();
const {fps, durationInFrames} = useVideoConfig();
return (
<Sequence
premountFor={(2 * fps) as number}
postmountFor={fps * 2.5}
offset={-1 * fps}
from={fps / 2}
style={{scale: interpolate(frame, [0, 3.33 * fps, durationInFrames], [2, 3, 4])}}
/>
);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 8),
componentIdentity: null,
keys: ['premountFor', 'postmountFor', 'offset', 'from', 'style.scale'],
effects: [],
});
expect(result.props.premountFor).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: undefined,
numericExpression: {
type: 'video-config-multiplication',
identifier: 'fps',
multiplier: 2,
binding: {type: 'video-config', field: 'fps'},
factorPosition: 'left',
},
});
expect(result.props.postmountFor).toMatchObject({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: undefined,
numericExpression: {
type: 'video-config-multiplication',
factorPosition: 'right',
},
});
expect(result.props.from).toEqual({status: 'computed'});
expect(result.props.offset).toMatchObject({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: undefined,
numericExpression: {multiplier: -1},
});
expect(result.props['style.scale']).toMatchObject({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
keyframes: [
{frame: 0, value: 2},
{
frame: {
type: 'video-config-multiplication',
identifier: 'fps',
binding: {type: 'video-config', field: 'fps'},
},
value: 3,
frameExpression: {
type: 'video-config-multiplication',
identifier: 'fps',
},
},
{
frame: {
type: 'video-config-value',
identifier: 'durationInFrames',
binding: {type: 'video-config', field: 'durationInFrames'},
},
value: 4,
frameExpression: {
type: 'video-config-value',
identifier: 'durationInFrames',
},
},
],
});
for (const durationInFrames of [120, 240]) {
const evaluated = NoReactInternals.evaluateSourcePropStatuses(
result.props,
{...videoConfigValues, durationInFrames},
);
expect(evaluated.premountFor).toMatchObject({codeValue: 60});
expect(evaluated.postmountFor).toMatchObject({codeValue: 75});
expect(evaluated.offset).toMatchObject({codeValue: -30});
expect(evaluated['style.scale']).toMatchObject({
keyframes: [{frame: 0}, {frame: 99.9}, {frame: durationInFrames}],
});
}
});
test('computeSequencePropsStatus should parse multiplication by a numeric constant', () => {
const input = `import {Sequence} from 'remotion';
const fps = 30;
export const ShortAudioLoop = () => {
return <Sequence from={-8 * fps} layout="none" />;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 6),
componentIdentity: null,
keys: ['from'],
effects: [],
});
expect(result.props.from).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: undefined,
numericExpression: {
type: 'video-config-multiplication',
identifier: 'fps',
multiplier: -8,
binding: {type: 'constant', value: 30},
factorPosition: 'left',
},
});
});
test('computeSequencePropsStatus should expand a static border shorthand', () => {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = () => {
return <AbsoluteFill style={{border: '12px dashed rgba(1, 2, 3, 0.5)'}} />;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 4),
componentIdentity: null,
keys: ['style.borderWidth', 'style.borderStyle', 'style.borderColor'],
effects: [],
});
expect(result.props['style.borderWidth']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 12,
});
expect(result.props['style.borderStyle']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'dashed',
});
expect(result.props['style.borderColor']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'rgba(1, 2, 3, 0.5)',
});
});
test('computeSequencePropsStatus should expand static border radius shorthands', () => {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = () => {
return (
<>
<AbsoluteFill style={{borderRadius: 12}} />
<AbsoluteFill style={{borderRadius: '10px 20px 30px 40px'}} />
</>
);
};
`;
const keys = [
'style.borderTopLeftRadius',
'style.borderTopRightRadius',
'style.borderBottomRightRadius',
'style.borderBottomLeftRadius',
];
const numeric = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 6),
componentIdentity: null,
keys,
effects: [],
});
const pixelValues = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys,
effects: [],
});
expect(numeric.props).toMatchObject({
'style.borderTopLeftRadius': {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 12,
},
'style.borderTopRightRadius': {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 12,
},
'style.borderBottomRightRadius': {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 12,
},
'style.borderBottomLeftRadius': {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 12,
},
});
expect(pixelValues.props).toMatchObject({
'style.borderTopLeftRadius': {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 10,
},
'style.borderTopRightRadius': {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 20,
},
'style.borderBottomRightRadius': {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 30,
},
'style.borderBottomLeftRadius': {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 40,
},
});
});
test('computeSequencePropsStatus should normalize uniform border radius shorthands', () => {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = () => {
return (
<>
<AbsoluteFill style={{borderRadius: 12}} />
<AbsoluteFill style={{borderRadius: '10px'}} />
<AbsoluteFill style={{borderRadius: '8px 8px 8px 8px'}} />
<AbsoluteFill style={{borderRadius: '10px 20px'}} />
</>
);
};
`;
const getStatus = (line: number) =>
computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, line),
componentIdentity: null,
keys: [
'style.borderRadius',
'style.borderTopLeftRadius',
'style.borderTopRightRadius',
'style.borderBottomRightRadius',
'style.borderBottomLeftRadius',
],
effects: [],
});
expect(getStatus(6).props['style.borderRadius']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 12,
});
expect(getStatus(7).props['style.borderRadius']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 10,
});
expect(getStatus(8).props['style.borderRadius']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 8,
});
expect(getStatus(9).props['style.borderRadius']).toEqual({
status: 'computed',
});
expect(getStatus(9).props['style.borderTopLeftRadius']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 10,
});
});
test('computeSequencePropsStatus should recognize numeric border radius keyframes', () => {
const input = `import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';
export const Example = () => {
const frame = useCurrentFrame();
return <AbsoluteFill style={{borderRadius: interpolate(frame, [0, 30], [0, 24])}} />;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 5),
componentIdentity: null,
keys: ['style.borderRadius'],
effects: [],
});
expect(result.props['style.borderRadius']).toMatchObject({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 0, value: 0},
{frame: 30, value: 24},
],
});
});
test('computeSequencePropsStatus should not guess complex border radius shorthands', () => {
for (const borderRadius of ["'50%'", "'10px / 20px'", 'radius']) {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = ({radius}: {radius: string}) => {
return <AbsoluteFill style={{borderRadius: ${borderRadius}}} />;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 4),
componentIdentity: null,
keys: ['style.borderTopLeftRadius'],
effects: [],
});
expect(result.props['style.borderTopLeftRadius']).toEqual({
status: 'computed',
});
}
});
test('computeSequencePropsStatus should reject mixed border radius representations', () => {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = () => {
return (
<>
<AbsoluteFill style={{borderTopLeftRadius: 8, borderRadius: 2}} />
<AbsoluteFill style={{borderRadius: 2, borderTopLeftRadius: 8}} />
</>
);
};
`;
const getStatus = (line: number) =>
computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, line),
componentIdentity: null,
keys: [
'style.borderRadius',
'style.borderTopLeftRadius',
'style.borderTopRightRadius',
'style.borderBottomRightRadius',
'style.borderBottomLeftRadius',
],
effects: [],
});
for (const line of [6, 7]) {
expect(Object.values(getStatus(line).props)).toEqual(
new Array(5).fill({status: 'computed'}),
);
}
});
test('computeSequencePropsStatus should not guess a dynamic border shorthand', () => {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = ({border}: {border: string}) => {
return <AbsoluteFill style={{border}} />;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 4),
componentIdentity: null,
keys: ['style.borderWidth', 'style.borderStyle', 'style.borderColor'],
effects: [],
});
expect(result.props['style.borderWidth']).toEqual({status: 'computed'});
expect(result.props['style.borderStyle']).toEqual({status: 'computed'});
expect(result.props['style.borderColor']).toEqual({status: 'computed'});
});
test('computeSequencePropsStatus should treat side-specific borders as computed', () => {
const sideProperties = [
"borderLeft: '1px solid red'",
'borderRightWidth: 2',
"borderTopStyle: 'dashed'",
"'borderBottomColor': 'blue'",
];
for (const sideProperty of sideProperties) {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = () => {
return <AbsoluteFill style={{${sideProperty}}} />;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 4),
componentIdentity: null,
keys: ['style.borderWidth', 'style.borderStyle', 'style.borderColor'],
effects: [],
});
expect(result.props['style.borderWidth']).toEqual({status: 'computed'});
expect(result.props['style.borderStyle']).toEqual({status: 'computed'});
expect(result.props['style.borderColor']).toEqual({status: 'computed'});
}
});
test('computeSequencePropsStatus should respect border property order', () => {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = () => {
return (
<>
<AbsoluteFill style={{borderWidth: 8, border: '2px solid red'}} />
<AbsoluteFill style={{border: '2px solid red', borderWidth: 8}} />
</>
);
};
`;
const beforeShorthand = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 6),
componentIdentity: null,
keys: ['style.borderWidth'],
effects: [],
});
const afterShorthand = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.borderWidth'],
effects: [],
});
expect(beforeShorthand.props['style.borderWidth']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 2,
});
expect(afterShorthand.props['style.borderWidth']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 8,
});
});
test('computeSequencePropsStatus should apply border shorthand defaults', () => {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = () => {
return <AbsoluteFill style={{border: 'solid'}} />;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 4),
componentIdentity: null,
keys: ['style.borderWidth', 'style.borderStyle', 'style.borderColor'],
effects: [],
});
expect(result.props['style.borderWidth']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 3,
});
expect(result.props['style.borderStyle']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'solid',
});
expect(result.props['style.borderColor']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'currentColor',
});
});
test('computeSequencePropsStatus should expand a color-only background shorthand', () => {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = () => {
return <AbsoluteFill style={{background: 'rgba(1, 2, 3, 0.5)'}} />;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 4),
componentIdentity: null,
keys: ['style.backgroundColor'],
effects: [],
});
expect(result.props['style.backgroundColor']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'rgba(1, 2, 3, 0.5)',
});
});
test('computeSequencePropsStatus should treat complex and dynamic background shorthands as computed', () => {
const inputs = [
`import {AbsoluteFill} from 'remotion';
export const Example = () => {
return <AbsoluteFill style={{background: 'linear-gradient(red, blue)'}} />;
};
`,
`import {AbsoluteFill} from 'remotion';
export const Example = ({background}: {background: string}) => {
return <AbsoluteFill style={{background}} />;
};
`,
];
for (const input of inputs) {
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 4),
componentIdentity: null,
keys: ['style.backgroundColor'],
effects: [],
});
expect(result.props['style.backgroundColor']).toEqual({
status: 'computed',
});
}
});
test('computeSequencePropsStatus should respect background property order', () => {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = () => {
return (
<>
<AbsoluteFill style={{backgroundColor: 'blue', background: 'red'}} />
<AbsoluteFill style={{background: 'red', backgroundColor: 'blue'}} />
</>
);
};
`;
const beforeShorthand = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 6),
componentIdentity: null,
keys: ['style.backgroundColor'],
effects: [],
});
const afterShorthand = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.backgroundColor'],
effects: [],
});
expect(beforeShorthand.props['style.backgroundColor']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'red',
});
expect(afterShorthand.props['style.backgroundColor']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'blue',
});
});
test('computeSequencePropsStatus should allow an independent background image', () => {
const input = `import {AbsoluteFill} from 'remotion';
export const Example = () => {
return (
<AbsoluteFill
style={{
backgroundImage: 'linear-gradient(red, blue)',
backgroundColor: 'black',
}}
/>
);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 5),
componentIdentity: null,
keys: ['style.backgroundColor'],
effects: [],
});
expect(result.props['style.backgroundColor']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'black',
});
});
test('canUpdateSequenceProps should flag computed props', () => {
const filePath = path.join(__dirname, 'snapshots', 'light-leak-computed.tsx');
const result = computeSequencePropsStatus({
fileContentsCache: null,
fileName: filePath,
nodePath: getNodePath(filePath, 8),
componentIdentity: null,
keys: ['durationInFrames', 'seed', 'hueShift', 'nonExistentProp'],
effects: [],
remotionRoot: '/',
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) {
throw new Error('Expected canUpdate to be true');
}
expect(result.props.durationInFrames).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 60,
});
expect(result.props.hueShift).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 30,
});
expect(result.props.seed).toEqual({status: 'computed'});
expect(result.props.nonExistentProp).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: undefined,
});
});
test('computeSequencePropsStatus should return keyframes for interpolated color props', () => {
const input = `import React from 'react';
import {Solid, interpolateColors, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Solid color={interpolateColors(frame, [0, 100], ['red', 'blue'])} width={100} height={100} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['color'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props.color).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolateColors',
keyframes: [
{frame: 0, value: 'red'},
{frame: 100, value: 'blue'},
],
easing: [{type: 'linear'}],
clamping: {left: 'clamp', right: 'clamp'},
posterize: undefined,
output: undefined,
});
});
test('computeSequencePropsStatus should reject a node path with the wrong component identity', () => {
const input = `import React from 'react';
import {Interactive} from 'remotion';
import {Star} from '@remotion/shapes';
export const Example: React.FC = () => {
\treturn (
\t\t<Interactive.Div>
\t\t\t<Star points={20} innerRadius={174} outerRadius={207} />
\t\t</Interactive.Div>
\t);
};
`;
expect(() =>
computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: 'dev.remotion.shapes.Star',
keys: ['points'],
effects: [],
}),
).toThrow(JsxElementIdentityMismatchError);
});
test('computeSequencePropsStatus should match hyphenated package imports by component identity', () => {
const input = `import React from 'react';
import {Highlight} from '@remotion/rough-notation';
export const Example: React.FC = () => {
\treturn (
\t\t<Highlight progress={1} color="yellow">
\t\t\tHighlighted
\t\t</Highlight>
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 6),
componentIdentity: 'dev.remotion.roughNotation.Highlight',
keys: ['progress', 'color'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props.progress).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 1,
});
expect(result.props.color).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'yellow',
});
});
test('computeSequencePropsStatus should match namespace imports by component identity', () => {
const input = `import React from 'react';
import * as Remotion from 'remotion';
export const Example: React.FC = () => {
\treturn (
\t\t<Remotion.Sequence from={10} durationInFrames={20} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 6),
componentIdentity: 'dev.remotion.remotion.Sequence',
keys: ['from'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props.from).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 10,
});
});
test('computeSequencePropsStatus should return easing for interpolated color props', () => {
const input = `import React from 'react';
import {Easing, Solid, interpolateColors, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Solid color={interpolateColors(frame, [0, 100, 200], ['red', 'green', 'blue'], {easing: [Easing.bezier(0.42, 0, 1, 1), Easing.linear], posterize: 2})} width={100} height={100} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['color'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props.color).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolateColors',
keyframes: [
{frame: 0, value: 'red'},
{frame: 100, value: 'green'},
{frame: 200, value: 'blue'},
],
easing: [{type: 'bezier', x1: 0.42, y1: 0, x2: 1, y2: 1}, {type: 'linear'}],
clamping: {left: 'clamp', right: 'clamp'},
posterize: 2,
output: undefined,
});
});
test('computeSequencePropsStatus should return spring easing metadata', () => {
const input = `import React from 'react';
import {Easing, Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{opacity: interpolate(frame, [0, 100], [0, 1], {easing: Easing.spring({damping: 12, mass: 1.5, stiffness: 180, allowTail: true, durationRestThreshold: 0.1, overshootClamping: true})})}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.opacity'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.opacity']).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 0, value: 0},
{frame: 100, value: 1},
],
easing: [
{
type: 'spring',
allowTail: true,
damping: 12,
durationRestThreshold: 0.1,
mass: 1.5,
stiffness: 180,
overshootClamping: true,
},
],
clamping: {left: 'extend', right: 'extend'},
posterize: undefined,
output: undefined,
});
});
test('computeSequencePropsStatus should return keyframes for interpolated translate props', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{translate: interpolate(frame, [0, 100], ['0px 59px', '100px 20px'])}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.translate'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.translate']).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 0, value: '0px 59px'},
{frame: 100, value: '100px 20px'},
],
easing: [{type: 'linear'}],
clamping: {left: 'extend', right: 'extend'},
posterize: undefined,
output: undefined,
});
});
test('percentage translate values are computed while other style props remain editable', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
const frame = useCurrentFrame();
return (
<>
<Sequence style={{translate: interpolate(frame, [0, 100], ['0% 0px', '-20% 0px']), opacity: 0.5}} />
<Sequence style={{translate: '20% 0px'}} />
<Sequence style={{translate: interpolate(frame, [0, 100], ['0px 0px', '20px 0px'])}} />
</>
);
};
`;
const getProps = (line: number) => {
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, line),
componentIdentity: null,
keys: ['style.translate', 'style.opacity'],
effects: [],
});
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
return result.props;
};
expect(getProps(8)['style.translate']).toEqual({status: 'computed'});
expect(getProps(8)['style.opacity']).toMatchObject({
status: 'static',
codeValue: 0.5,
});
expect(getProps(9)['style.translate']).toEqual({status: 'computed'});
expect(getProps(10)['style.translate']).toMatchObject({
status: 'keyframed',
});
});
test('computeSequencePropsStatus preserves the useCurrentFrame coordinate space across userland timing components', () => {
const input = `import React from 'react';
import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';
import {Timing} from './Timing';
export const Example: React.FC = () => {
const frame = useCurrentFrame();
return (
<Timing durationInFrames={30} from={-5} trimBefore={3}>
<AbsoluteFill
style={{
backgroundColor: 'dodgerblue',
translate: interpolate(frame, [10, 20], ['0px 0px', '500px 0px']),
}}
/>
</Timing>
);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 9),
componentIdentity: null,
keys: ['style.backgroundColor', 'style.translate'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.translate']).toMatchObject({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: 8,
keyframes: [
{frame: 10, value: '0px 0px'},
{frame: 20, value: '500px 0px'},
],
});
expect(result.props['style.backgroundColor']).toEqual({
status: 'static',
codeValue: 'dodgerblue',
keyframeDisplayOffsetAdjustment: 8,
});
});
test('computeSequencePropsStatus distinguishes a zero-offset outer frame clock from a local frame clock', () => {
const input = `import React from 'react';
import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';
import {Timing} from './Timing';
export const Example: React.FC = () => {
const frame = useCurrentFrame();
return (
<Timing from={0}>
<AbsoluteFill style={{opacity: interpolate(frame, [10, 20], [0, 1])}} />
</Timing>
);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 9),
componentIdentity: null,
keys: ['style.opacity'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.opacity']).toMatchObject({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: 0,
keyframes: [
{frame: 10, value: 0},
{frame: 20, value: 1},
],
});
});
test('computeSequencePropsStatus resolves affine aliases of useCurrentFrame', () => {
const input = `import React from 'react';
import {AbsoluteFill, Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
const frame = useCurrentFrame();
const captureFrame = frame + 30;
let mutableCaptureFrame = frame + 30;
return (
<AbsoluteFill from={-30}>
<Sequence
style={{
rotate: interpolate(captureFrame, [30, 60], ['0deg', '30deg']),
opacity: interpolate(captureFrame - 10, [20, 50], [0, 1]),
scale: interpolate(frame * 2, [0, 60], [1, 2]),
translate: interpolate(mutableCaptureFrame, [30, 60], ['0px', '10px']),
}}
/>
</AbsoluteFill>
);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 10),
componentIdentity: null,
keys: ['style.rotate', 'style.opacity', 'style.scale', 'style.translate'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.rotate']).toMatchObject({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: 0,
keyframes: [
{frame: 30, value: '0deg'},
{frame: 60, value: '30deg'},
],
});
expect(result.props['style.opacity']).toMatchObject({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: 10,
keyframes: [
{frame: 20, value: 0},
{frame: 50, value: 1},
],
});
expect(result.props['style.scale']).toEqual({status: 'computed'});
expect(result.props['style.translate']).toEqual({status: 'computed'});
});
test('computeSequencePropsStatus reports computed when a timing component offset is uncertain', () => {
const input = `import React from 'react';
import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';
import {Timing, getTimingProps} from './Timing';
export const Example: React.FC = () => {
const frame = useCurrentFrame();
const timingProps = getTimingProps();
return (
<Timing {...timingProps}>
<AbsoluteFill
style={{
backgroundColor: 'dodgerblue',
translate: interpolate(frame, [10, 20], ['0px 0px', '500px 0px']),
}}
/>
</Timing>
);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 10),
componentIdentity: null,
keys: ['style.backgroundColor', 'style.translate'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.translate']).toEqual({status: 'computed'});
expect(result.props['style.backgroundColor']).toEqual({status: 'computed'});
});
test('computeSequencePropsStatus does not treat an outer frame clock as local across a loop', () => {
const input = `import React from 'react';
import {AbsoluteFill, Interactive, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
const frame = useCurrentFrame();
return (
<AbsoluteFill loop trimAfter={20}>
<Interactive.Div
name="Title"
style={{
opacity: interpolate(frame, [5, 26], [0, 1]),
translate: interpolate(frame, [5, 26], ['0px 22px', '0px 0px']),
}}
/>
</AbsoluteFill>
);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 8),
componentIdentity: null,
keys: ['name', 'style.opacity', 'style.translate'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props.name).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'Title',
canKeyframe: false,
});
expect(result.props['style.opacity']).toEqual({status: 'computed'});
expect(result.props['style.translate']).toEqual({status: 'computed'});
});
test('computeSequencePropsStatus keeps an outer frame clock editable when looping is disabled', () => {
const input = `import React from 'react';
import {AbsoluteFill, Interactive, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
const frame = useCurrentFrame();
return (
<AbsoluteFill loop={false} trimAfter={20}>
<Interactive.Div style={{opacity: interpolate(frame, [5, 26], [0, 1])}} />
</AbsoluteFill>
);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 8),
componentIdentity: null,
keys: ['style.opacity'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.opacity']).toMatchObject({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: 0,
});
});
test('computeSequencePropsStatus should return keyframes for String-wrapped interpolated translate props', () => {
const input = `import React from 'react';
import {Easing, Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{translate: String(interpolate(frame, [0, 16, 30], ['0px 59px', '100px 20px', '124px 40px'], {
\t\t\textrapolateLeft: 'clamp',
\t\t\textrapolateRight: 'clamp',
\t\t\teasing: [
\t\t\t\tEasing.bezier(0, 0, 0.58, 1),
\t\t\t\tEasing.bezier(0.42, 0, 0.6308, 1.1405),
\t\t\t],
\t\t}))}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.translate'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.translate']).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 0, value: '0px 59px'},
{frame: 16, value: '100px 20px'},
{frame: 30, value: '124px 40px'},
],
easing: [
{type: 'bezier', x1: 0, y1: 0, x2: 0.58, y2: 1},
{type: 'bezier', x1: 0.42, y1: 0, x2: 0.6308, y2: 1.1405},
],
clamping: {left: 'clamp', right: 'clamp'},
posterize: undefined,
output: undefined,
});
});
test('computeSequencePropsStatus should flag interpolations over computed values as computed', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\tconst progress = interpolate(frame, [0, 100], [0, 1], {posterize: 3});
\treturn (
\t\t<Sequence style={{translate: interpolate(progress, [0, 1], ['0px 59px', '100px 20px'])}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 8),
componentIdentity: null,
keys: ['style.translate'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.translate']).toEqual({
status: 'computed',
});
});
test('computeSequencePropsStatus should return keyframes for interpolated rotate props', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{rotate: interpolate(frame, [55, 68], ['19deg', '23deg'])}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.rotate'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.rotate']).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 55, value: '19deg'},
{frame: 68, value: '23deg'},
],
easing: [{type: 'linear'}],
clamping: {left: 'extend', right: 'extend'},
posterize: undefined,
output: undefined,
});
});
test('computeSequencePropsStatus should explain why outside-project file reads were blocked', () => {
const remotionRoot = path.join(__dirname, 'snapshots');
const fileName = '../outside.tsx';
const absolutePath = path.resolve(remotionRoot, fileName);
expect(() =>
computeSequencePropsStatus({
fileContentsCache: null,
fileName,
nodePath: [],
componentIdentity: null,
keys: [],
effects: [],
remotionRoot,
}),
).toThrow(
`Cannot read a file outside the project: "${fileName}" resolves to "${absolutePath}", but the project root is "${remotionRoot}".`,
);
});
test('computeSequencePropsStatus should detect static nested props', () => {
const filePath = path.join(__dirname, 'snapshots', 'nested-props.tsx');
const result = computeSequencePropsStatus({
fileContentsCache: null,
fileName: filePath,
nodePath: getNodePath(filePath, 7),
componentIdentity: null,
keys: ['style.opacity', 'style.scale'],
effects: [],
remotionRoot: '/',
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.opacity']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 0.5,
});
expect(result.props['style.scale']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 2,
});
});
test('computeSequencePropsStatus should flag computed nested props', () => {
const filePath = path.join(__dirname, 'snapshots', 'nested-props.tsx');
const result = computeSequencePropsStatus({
fileContentsCache: null,
fileName: filePath,
nodePath: getNodePath(filePath, 8),
componentIdentity: null,
keys: ['style.opacity', 'style.scale'],
effects: [],
remotionRoot: '/',
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
// opacity uses getOpacity() — computed
expect(result.props['style.opacity']).toEqual({
status: 'computed',
});
// scale is static
expect(result.props['style.scale']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 2,
});
});
test('computeSequencePropsStatus should preserve nested props from object spreads', () => {
const input = `import {Interactive} from 'remotion';
const sharedStyle = {color: 'white'};
export const Example = () => {
return (
<>
<Interactive.Div style={{...sharedStyle, fontSize: 40}} />
<Interactive.Div style={{color: 'red', ...sharedStyle}} />
<Interactive.Div style={{...sharedStyle, color: 'red'}} />
</>
);
};
`;
const getColorStatus = (line: number) => {
return computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, line),
componentIdentity: null,
keys: ['style.color'],
effects: [],
}).props['style.color'];
};
expect(getColorStatus(8)).toEqual({status: 'computed'});
expect(getColorStatus(9)).toEqual({status: 'computed'});
expect(getColorStatus(10)).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'red',
});
});
test('computeSequencePropsStatus should flag computed when parent is not an object', () => {
const filePath = path.join(__dirname, 'snapshots', 'nested-props.tsx');
const result = computeSequencePropsStatus({
fileContentsCache: null,
fileName: filePath,
nodePath: getNodePath(filePath, 9),
componentIdentity: null,
keys: ['style.opacity'],
effects: [],
remotionRoot: '/',
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
// style={dynamicStyles} — entire parent is computed
expect(result.props['style.opacity']).toEqual({
status: 'computed',
});
});
test('computeSequencePropsStatus should report unset nested props as undefined', () => {
const filePath = path.join(__dirname, 'snapshots', 'nested-props.tsx');
const result = computeSequencePropsStatus({
fileContentsCache: null,
fileName: filePath,
nodePath: getNodePath(filePath, 7),
componentIdentity: null,
keys: ['style.rotate'],
effects: [],
remotionRoot: '/',
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.rotate']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: undefined,
});
});
test('computeSequencePropsStatus should report unset when parent attribute missing', () => {
const filePath = path.join(__dirname, 'snapshots', 'nested-props.tsx');
const result = computeSequencePropsStatus({
fileContentsCache: null,
fileName: filePath,
nodePath: getNodePath(filePath, 10),
componentIdentity: null,
keys: ['style.opacity'],
effects: [],
remotionRoot: '/',
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.opacity']).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: undefined,
});
});
test('computeSequencePropsStatus should return keyframes for interpolated style props', () => {
const filePath = path.join(__dirname, 'snapshots', 'keyframed-props.tsx');
const result = computeSequencePropsStatus({
fileContentsCache: null,
fileName: filePath,
nodePath: getNodePath(filePath, 8),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
remotionRoot: '/',
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 0, value: 2},
{frame: 100, value: 4},
],
easing: [{type: 'linear'}],
clamping: {left: 'extend', right: 'extend'},
posterize: undefined,
output: undefined,
});
});
test('computeSequencePropsStatus should return keyframes for String-wrapped interpolated scale props', () => {
const input = `import React from 'react';
import {Easing, Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{scale: String(
\t\t\tinterpolate(
\t\t\t\tframe,
\t\t\t\t[0, 16, 30],
\t\t\t\t['1.105 1.105', '1.37 0.77', '1.611 1.611'],
\t\t\t\t{
\t\t\t\t\textrapolateLeft: 'clamp',
\t\t\t\t\textrapolateRight: 'clamp',
\t\t\t\t\teasing: [
\t\t\t\t\t\tEasing.bezier(0, 0, 0.58, 1),
\t\t\t\t\t\tEasing.bezier(0.42, 0, 0.6308, 1.1405),
\t\t\t\t\t],
\t\t\t\t},
\t\t\t),
\t\t)}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 0, value: '1.105 1.105'},
{frame: 16, value: '1.37 0.77'},
{frame: 30, value: '1.611 1.611'},
],
easing: [
{type: 'bezier', x1: 0, y1: 0, x2: 0.58, y2: 1},
{type: 'bezier', x1: 0.42, y1: 0, x2: 0.6308, y2: 1.1405},
],
clamping: {left: 'clamp', right: 'clamp'},
posterize: undefined,
output: undefined,
});
});
test('computeSequencePropsStatus should parse easing arrays and clamping', () => {
const input = `import React from 'react';
import {Easing, Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{scale: interpolate(frame, [0, 50, 100], [1, 2, 3], {
\t\t\teasing: [Easing.bezier(0.1, 0.2, 0.3, 0.4), Easing.linear],
\t\t\textrapolateLeft: 'clamp',
\t\t\textrapolateRight: 'identity',
\t\t})}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 0, value: 1},
{frame: 50, value: 2},
{frame: 100, value: 3},
],
easing: [
{type: 'bezier', x1: 0.1, y1: 0.2, x2: 0.3, y2: 0.4},
{type: 'linear'},
],
clamping: {
left: 'clamp',
right: 'identity',
},
posterize: undefined,
output: undefined,
});
});
test('computeSequencePropsStatus should parse posterize on interpolated props', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{scale: interpolate(frame, [0, 100], [1, 3], {posterize: 3})}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 0, value: 1},
{frame: 100, value: 3},
],
easing: [{type: 'linear'}],
clamping: {left: 'extend', right: 'extend'},
posterize: 3,
output: undefined,
});
});
test('computeSequencePropsStatus should parse output on interpolated props', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{scale: interpolate(frame, [0, 100], [1, 3], {output: 'perceptual-scale'})}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 0, value: 1},
{frame: 100, value: 3},
],
easing: [{type: 'linear'}],
clamping: {left: 'extend', right: 'extend'},
posterize: undefined,
output: 'perceptual-scale',
});
});
test('computeSequencePropsStatus should parse posterize on interpolated color props', () => {
const input = `import React from 'react';
import {Solid, interpolateColors, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Solid color={interpolateColors(frame, [0, 100], ['red', 'blue'], {posterize: 3})} width={100} height={100} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['color'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props.color).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolateColors',
keyframes: [
{frame: 0, value: 'red'},
{frame: 100, value: 'blue'},
],
easing: [{type: 'linear'}],
clamping: {left: 'clamp', right: 'clamp'},
posterize: 3,
output: undefined,
});
});
test('computeSequencePropsStatus should bail on output for interpolated color props', () => {
const input = `import React from 'react';
import {Solid, interpolateColors, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Solid color={interpolateColors(frame, [0, 100], ['red', 'blue'], {output: 'perceptual-scale'})} width={100} height={100} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['color'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props.color).toEqual({
status: 'computed',
});
});
test('computeSequencePropsStatus should bail on computed posterize expressions', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\tconst posterize = 3;
\treturn (
\t\t<Sequence style={{scale: interpolate(frame, [0, 100], [1, 3], {posterize})}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 8),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toEqual({
status: 'computed',
});
});
test('computeSequencePropsStatus should bail on arithmetic posterize expressions', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{scale: interpolate(frame, [0, 100], [1, 3], {posterize: 5 + 5})}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toEqual({
status: 'computed',
});
});
test('computeSequencePropsStatus should bail on computed output expressions', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\tconst output = 'perceptual-scale';
\treturn (
\t\t<Sequence style={{scale: interpolate(frame, [0, 100], [1, 3], {output})}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 8),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toEqual({
status: 'computed',
});
});
test('computeSequencePropsStatus should represent Easing.cubic as bezier easing metadata', () => {
const input = `import React from 'react';
import {Easing, Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{scale: interpolate(frame, [0, 100], [1, 3], {
\t\t\teasing: Easing.cubic,
\t\t})}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toEqual({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
interpolationFunction: 'interpolate',
keyframes: [
{frame: 0, value: 1},
{frame: 100, value: 3},
],
easing: [{type: 'bezier', x1: 1 / 3, y1: 0, x2: 2 / 3, y2: 0}],
clamping: {left: 'extend', right: 'extend'},
posterize: undefined,
output: undefined,
});
});
test('computeSequencePropsStatus should represent supported Easing helpers as bezier easing metadata', () => {
const input = `import React from 'react';
import {Easing, Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{scale: interpolate(frame, [0, 20, 40, 60, 80, 100, 120, 140, 160], [0, 1, 2, 3, 4, 5, 6, 7, 8], {
\t\t\teasing: [Easing.ease, Easing.quad, Easing.back(), Easing.back(2), Easing.poly(2), Easing.in(Easing.cubic), Easing.out(Easing.quad), Easing.out(Easing.ease)],
\t\t})}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toMatchObject({
status: 'keyframed',
keyframeDisplayOffsetAdjustment: null,
easing: [
{type: 'bezier', x1: 0.42, y1: 0, x2: 1, y2: 1},
{type: 'bezier', x1: 1 / 3, y1: 0, x2: 2 / 3, y2: 1 / 3},
{type: 'bezier', x1: 1 / 3, y1: 0, x2: 2 / 3, y2: -1.70158 / 3},
{type: 'bezier', x1: 1 / 3, y1: 0, x2: 2 / 3, y2: -2 / 3},
{type: 'bezier', x1: 1 / 3, y1: 0, x2: 2 / 3, y2: 1 / 3},
{type: 'bezier', x1: 1 / 3, y1: 0, x2: 2 / 3, y2: 0},
{
type: 'bezier',
x1: 1 - 2 / 3,
y1: 1 - 1 / 3,
x2: 1 - 1 / 3,
y2: 1,
},
{type: 'bezier', x1: 0, y1: 0, x2: 1 - 0.42, y2: 1},
],
});
});
test('computeSequencePropsStatus should bail on unsupported easing expressions', () => {
const input = `import React from 'react';
import {Easing, Sequence, interpolate, useCurrentFrame} from 'remotion';
export const Example: React.FC = () => {
\tconst frame = useCurrentFrame();
\treturn (
\t\t<Sequence style={{scale: interpolate(frame, [0, 100], [1, 3], {
\t\t\teasing: Easing.inOut(Easing.quad),
\t\t})}} />
\t);
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 7),
componentIdentity: null,
keys: ['style.scale'],
effects: [],
});
expect(result.canUpdate).toBe(true);
if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
expect(result.props['style.scale']).toEqual({
status: 'computed',
});
});
test('computeSequencePropsStatus should detect static JSX text children', () => {
const input = `import React from 'react';
import {Interactive} from 'remotion';
export const Example: React.FC = () => {
return <Interactive.P>Hello</Interactive.P>;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 5),
componentIdentity: null,
keys: ['children'],
effects: [],
});
expect(result.props.children).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'Hello',
});
});
test('computeSequencePropsStatus should detect static children attribute', () => {
const input = `import React from 'react';
import {Interactive} from 'remotion';
export const Example: React.FC = () => {
return <Interactive.P children="Hello" />;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 5),
componentIdentity: null,
keys: ['children'],
effects: [],
});
expect(result.props.children).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'Hello',
});
});
test('computeSequencePropsStatus should prefer static children attribute over JSX children', () => {
const input = `import React from 'react';
import {Interactive} from 'remotion';
export const Example: React.FC = () => {
return <Interactive.P children="Hello">Stale</Interactive.P>;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 5),
componentIdentity: null,
keys: ['children'],
effects: [],
});
expect(result.props.children).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: 'Hello',
});
});
test('computeSequencePropsStatus should detect empty JSX text children', () => {
const input = `import React from 'react';
import {Interactive} from 'remotion';
export const Example: React.FC = () => {
return <Interactive.P></Interactive.P>;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 5),
componentIdentity: null,
keys: ['children'],
effects: [],
});
expect(result.props.children).toEqual({
status: 'static',
keyframeDisplayOffsetAdjustment: null,
codeValue: '',
});
});
test('computeSequencePropsStatus should reject non-static text children', () => {
const input = `import React from 'react';
import {Interactive} from 'remotion';
export const Example: React.FC<{text: string}> = ({text}) => {
return <Interactive.P>{text}</Interactive.P>;
};
`;
const result = computeSequencePropsStatusFromContent({
fileContents: input,
nodePath: getNodePathFromContent(input, 5),
componentIdentity: null,
keys: ['children'],
effects: [],
});
expect(result.props.children).toEqual({status: 'computed'});
});