🎥 Make videos programmatically with React
Premount inserted and timed elements
JonnyBurger489d82a75c32
diff --git a/packages/browser-studio/src/browser-studio-operations.ts b/packages/browser-studio/src/browser-studio-operations.tsindex c1410f7246..9338200a2e 100644--- a/packages/browser-studio/src/browser-studio-operations.ts+++ b/packages/browser-studio/src/browser-studio-operations.ts@@ -161,6 +161,7 @@ const insertIntoProject = async ({element: createElementFromInsertable({element: request.element,from: request.from,+ premountFor: request.premountFor,wrapInSequence,}),target: {@@ -2192,6 +2193,7 @@ export const createBrowserStudioOperations = ({nodePath,captions,durationInFrames,+ premountFor,}) => {try {const project = getProject();@@ -2205,6 +2207,7 @@ export const createBrowserStudioOperations = ({nodePath,captions,durationInFrames,+ premountFor,importPath: elementFile.importPath,});const nodePathMutation = controller.applyMutation({@@ -2601,6 +2604,7 @@ export const createBrowserStudioOperations = ({type: 'component',},from: componentOwnsSequence ? request.from : null,+ premountFor: request.premountFor,},wrapInSequence: componentOwnsSequence? nulldiff --git a/packages/browser-studio/src/test/browser-studio-operations.test.ts b/packages/browser-studio/src/test/browser-studio-operations.test.tsindex d3456ea360..8601ffec30 100644--- a/packages/browser-studio/src/test/browser-studio-operations.test.ts+++ b/packages/browser-studio/src/test/browser-studio-operations.test.ts@@ -183,6 +183,7 @@ export const MyComponent = () => <AbsoluteFill>Existing</AbsoluteFill>;compositionFile: 'src/index.tsx',compositionId: 'MyComp',from: null,+ premountFor: null,element: {type: 'solid',width: 1280,@@ -294,6 +295,7 @@ export const Root = () => <Composition id="MyComp" component={Component} duratiocompositionFile: fileName,compositionId: 'MyComp',from: null,+ premountFor: null,element: {type: 'solid',width: 1280,@@ -420,6 +422,7 @@ registerRoot(Root);`,fileName: 'src/Composition.tsx',nodePath: subscription.nodePath.nodePath,durationInFrames: 20,+ premountFor: 30,captions: [{text: ' Hello',@@ -484,6 +487,7 @@ registerRoot(Root);`,fileName: 'src/Composition.tsx',nodePath: currentSubscription.nodePath.nodePath,durationInFrames: 20,+ premountFor: 30,captions: [{text: ' Again',@@ -535,6 +539,7 @@ test('reports invalid timeline Solid input without changing the project', asynccompositionFile: '/project/src/Composition.tsx',compositionId: 'MyComp',from: 1.5,+ premountFor: null,element: {type: 'solid',width: 1280,diff --git a/packages/browser-studio/src/test/browser-studio-project-operations.test.ts b/packages/browser-studio/src/test/browser-studio-project-operations.test.tsindex bdd4056449..6b8fe1d3a7 100644--- a/packages/browser-studio/src/test/browser-studio-project-operations.test.ts+++ b/packages/browser-studio/src/test/browser-studio-project-operations.test.ts@@ -140,6 +140,7 @@ test('mutates virtual files, emits events, and preserves undo and redo history',position: null,},from: null,+ premountFor: null,});if (!insertResult.success) {throw new Error(insertResult.reason);@@ -574,6 +575,7 @@ export const LowerThird = ({logoSrc}: {logoSrc: string}) => <>element,expectedFileState: preflight.plan.expectedFileState,from: 12,+ premountFor: null,overwriteExisting: false,position: {x: 24, y: 48},undoRedoNavigation: null,@@ -636,6 +638,7 @@ export const LowerThird = ({logoSrc}: {logoSrc: string}) => <>element,expectedFileState: null,from: null,+ premountFor: null,overwriteExisting: false,position: null,undoRedoNavigation: null,@@ -730,6 +733,7 @@ const makeElementAssetFixture = () => {},expectedFileState: null,from: null,+ premountFor: null,overwriteExisting: false,position: null,undoRedoNavigation: null,@@ -871,6 +875,7 @@ test('installs an Element into a new composition as one undoable mutation', asynelement,expectedFileState: preflight.plan.expectedFileState,from: null,+ premountFor: null,overwriteExisting: false,position: null,undoRedoNavigation: {@@ -991,6 +996,7 @@ test('installs component-owned Element timing and initial props', async () => {element,expectedFileState: preflight.plan.expectedFileState,from: 30,+ premountFor: null,overwriteExisting: false,position: {x: 24, y: 48},undoRedoNavigation: null,@@ -1080,6 +1086,7 @@ test('rejects contradictory component-owned Element initial props', async () =>},expectedFileState: null,from: 30,+ premountFor: null,overwriteExisting: false,position: {x: 24, y: 48},undoRedoNavigation: null,@@ -1188,6 +1195,7 @@ test('inserts generic elements with pinned Remotion dependencies', async () => {type: 'asset',},from: 12,+ premountFor: null,});if (!result.success) {throw new Error(result.reason);@@ -1224,6 +1232,7 @@ test('rejects inline SVG importing in Browser Studio', async () => {type: 'svg',},from: null,+ premountFor: null,});expect(result).toMatchObject({diff --git a/packages/browser-studio/src/test/download-project.test.ts b/packages/browser-studio/src/test/download-project.test.tsindex 1cea4a07ce..efdfb85882 100644--- a/packages/browser-studio/src/test/download-project.test.ts+++ b/packages/browser-studio/src/test/download-project.test.ts@@ -39,6 +39,7 @@ test('downloads the current Browser Studio project as a runnable archive', asyncposition: null,},from: null,+ premountFor: null,});expect(insertResult.success).toBe(true);diff --git a/packages/codemods/src/basic-captions-element-source.ts b/packages/codemods/src/basic-captions-element-source.tsindex 9a1ade51c0..f92af8c16f 100644--- a/packages/codemods/src/basic-captions-element-source.ts+++ b/packages/codemods/src/basic-captions-element-source.ts@@ -9,6 +9,7 @@ import {useCurrentFrame,useVideoConfig,type InteractiveBaseProps,+ type InteractivePremountProps,type InteractiveTransformProps,type InteractivitySchema,type SequenceControls,@@ -16,6 +17,7 @@ import {} from 'remotion';type BasicCaptionsProps = InteractiveBaseProps &+ InteractivePremountProps &InteractiveTransformProps &Pick<SequenceProps, 'from' | 'durationInFrames' | 'trimBefore' | 'width' | 'height'> & {readonly captions: Caption[];@@ -79,6 +81,7 @@ const BasicCaptionsContent: React.FC<{const basicCaptionsSchema = {...Interactive.baseSchema,...Interactive.captionsSchema,+ ...Interactive.premountSchema,width: {type: 'number',min: 1,@@ -124,7 +127,6 @@ const BasicCaptionsInner: React.FC<}) => {return (<Sequence- layout="none"{...interactiveProps}controls={controls}name={name ?? 'Basic captions'}diff --git a/packages/codemods/src/generate-canvas-capture-composition.ts b/packages/codemods/src/generate-canvas-capture-composition.tsindex f824092da0..bc310c5b99 100644--- a/packages/codemods/src/generate-canvas-capture-composition.ts+++ b/packages/codemods/src/generate-canvas-capture-composition.ts@@ -288,6 +288,7 @@ export const ${previewComponentName} = () => {return (<AbsoluteFilldurationInFrames={${durationInFrames}}+ premountFor={${fps}}style={{width: ${videoWidth},height: ${videoHeight},diff --git a/packages/codemods/src/insert-basic-captions.ts b/packages/codemods/src/insert-basic-captions.tsindex 556b8a539f..f2d0b87c5a 100644--- a/packages/codemods/src/insert-basic-captions.ts+++ b/packages/codemods/src/insert-basic-captions.ts@@ -30,6 +30,7 @@ export const insertBasicCaptions = ({nodePath,captions,durationInFrames,+ premountFor,importPath = './basic-captions.element',prettierConfigOverride = null,}: {@@ -44,6 +45,7 @@ export const insertBasicCaptions = ({pageBreakAfter?: boolean;}[];durationInFrames: number | null;+ premountFor: number | null;importPath?: string;prettierConfigOverride?: Record<string, unknown> | null;}): {@@ -51,6 +53,13 @@ export const insertBasicCaptions = ({logLine: number;nodePathRemappings: SequenceNodePathRemapping[];} => {+ if (+ premountFor !== null &&+ (!Number.isInteger(premountFor) || premountFor < 0)+ ) {+ throw new Error('premountFor must be a non-negative integer');+ }+const ast = parseAst(input);const captured = captureJsxNodePaths(ast);const importSnapshots = captureImportSnapshots(ast);@@ -105,9 +114,14 @@ export const insertBasicCaptions = ({(attribute) =>attribute.type === 'JSXAttribute' &&attribute.name.type === 'JSXIdentifier' &&- ['from', 'durationInFrames', 'trimBefore', 'playbackRate'].includes(- attribute.name.name,- ),+ [+ 'from',+ 'durationInFrames',+ 'trimBefore',+ 'playbackRate',+ 'premountFor',+ 'postmountFor',+ ].includes(attribute.name.name),).map((attribute) => recast.print(attribute).code);if (@@ -120,6 +134,13 @@ export const insertBasicCaptions = ({copiedAttributes.push(`durationInFrames={${durationInFrames}}`);}+ if (+ premountFor !== null &&+ !copiedAttributes.some((attribute) => attribute.startsWith('premountFor'))+ ) {+ copiedAttributes.push(`premountFor={${premountFor}}`);+ }+const elementSource = `<${captionsLocalName} captions={${JSON.stringify(captions, null, 2)}} ${copiedAttributes.join(' ')} />`;const parsedElement = parseAst(`const element = (${elementSource});`).program.body[0];diff --git a/packages/codemods/src/insert-jsx-element.ts b/packages/codemods/src/insert-jsx-element.tsindex cf97ff159e..512497cf11 100644--- a/packages/codemods/src/insert-jsx-element.ts+++ b/packages/codemods/src/insert-jsx-element.ts@@ -963,6 +963,7 @@ const createSequenceWrappedElement = ({durationInFrames,from,name,+ premountFor,position,sequenceLocalName,}: {@@ -971,6 +972,7 @@ const createSequenceWrappedElement = ({durationInFrames: number | null;from: number | null;name: string | null;+ premountFor: number | null;position: InsertableCompositionElementPosition | null;sequenceLocalName: string;}): namedTypes.JSXElement => {@@ -979,6 +981,9 @@ const createSequenceWrappedElement = ({recast.types.builders.jsxIdentifier(sequenceLocalName),[...(from === null ? [] : [createNumberAttribute('from', from)]),+ ...(premountFor === null+ ? []+ : [createNumberAttribute('premountFor', premountFor)]),...(name === null ? [] : [createStringAttribute('name', name)]),...(dimensions !== null? [@@ -1005,12 +1010,14 @@ const createSvgElement = async ({from,interactiveLocalName,markup,+ premountFor,position,}: {environment: CodemodEnvironment;from: number | null;interactiveLocalName: string;markup: string;+ premountFor: number | null;position: InsertableCompositionElementPosition | null;}): Promise<namedTypes.JSXElement> => {const svgElement = await environment.svgMarkupToJsx(markup);@@ -1020,6 +1027,10 @@ const createSvgElement = async ({attributes.push(createNumberAttribute('from', from));}+ if (premountFor !== null) {+ attributes.push(createNumberAttribute('premountFor', premountFor));+ }+const styleAttribute = attributes.find((attribute) =>attribute.type === 'JSXAttribute' &&@@ -2089,12 +2100,14 @@ const createInsertableJsxElement = ({element,environment,from,+ premountFor,}: {ast: File;destinationFileName: string;element: PipelineInsertableElement;environment: CodemodEnvironment;from: number | null;+ premountFor: number | null;}): Promise<namedTypes.JSXElement> => {if (element.type === 'svg') {return createSvgElement({@@ -2102,6 +2115,7 @@ const createInsertableJsxElement = ({from,interactiveLocalName: ensureInteractiveImport(ast),markup: element.markup,+ premountFor,position: element.position,});}@@ -2130,6 +2144,7 @@ export const insertJsxElementIntoComposition = async ({element,environment,from,+ premountFor,prettierConfigOverride,wrapInSequence,}: {@@ -2138,6 +2153,7 @@ export const insertJsxElementIntoComposition = async ({element: InsertableCompositionElement;environment: CodemodEnvironment;from: number | null;+ premountFor: number | null;prettierConfigOverride: Record<string, unknown> | null;wrapInSequence: {dimensions: {width: number; height: number} | null;@@ -2168,6 +2184,13 @@ export const insertJsxElementIntoComposition = async ({throw new Error('from must be a non-negative integer');}+ if (+ premountFor !== null &&+ (!Number.isInteger(premountFor) || premountFor < 0)+ ) {+ throw new Error('premountFor must be a non-negative integer');+ }+if (element.position !== null &&(!Number.isFinite(element.position.x) ||@@ -2227,6 +2250,7 @@ export const insertJsxElementIntoComposition = async ({element,environment,from,+ premountFor: sequenceWrapper === null ? premountFor : null,});const finalElementToInsert = sequenceWrapper? createSequenceWrappedElement({@@ -2235,6 +2259,7 @@ export const insertJsxElementIntoComposition = async ({durationInFrames: sequenceWrapper.durationInFrames ?? null,from: sequenceWrapper.from,name: sequenceWrapper.name,+ premountFor,position: sequenceWrapper.position,sequenceLocalName: ensureSequenceImport(ast),})@@ -2320,6 +2345,7 @@ export const insertJsxElementIntoProjectWithNodePathRemappings = async ({svgMarkupToJsx,}),from: request.from,+ premountFor: request.premountFor,prettierConfigOverride: null,wrapInSequence,});diff --git a/packages/codemods/src/insertable-element.ts b/packages/codemods/src/insertable-element.tsindex eea89bc3ec..39e058ea45 100644--- a/packages/codemods/src/insertable-element.ts+++ b/packages/codemods/src/insertable-element.ts@@ -62,10 +62,12 @@ const toCodemodValue = (value: unknown): CodemodValue => {export const createElementFromInsertable = ({element,from,+ premountFor,wrapInSequence,}: {element: InsertableCompositionElement;from: number | null;+ premountFor: number | null;wrapInSequence: InsertableSequenceWrapper | null;}): CodemodElement => {if (element.type === 'svg' || element.type === 'composition') {@@ -76,6 +78,13 @@ export const createElementFromInsertable = ({throw new Error('from must be a non-negative integer');}+ if (+ premountFor !== null &&+ (!Number.isInteger(premountFor) || premountFor < 0)+ ) {+ throw new Error('premountFor must be a non-negative integer');+ }+if (element.position !== null &&(!Number.isFinite(element.position.x) ||@@ -182,7 +191,9 @@ export const createElementFromInsertable = ({}if (sequence === null) {- return inner;+ return premountFor === null+ ? inner+ : inner.withProp('premountFor', premountFor);}return createElement({@@ -190,6 +201,7 @@ export const createElementFromInsertable = ({importPath: 'remotion',props: {...(sequence.from === null ? {} : {from: sequence.from}),+ ...(premountFor === null ? {} : {premountFor}),...(sequence.name === null ? {} : {name: sequence.name}),...(sequence.dimensions === null? {}diff --git a/packages/codemods/src/precompose-jsx-nodes.ts b/packages/codemods/src/precompose-jsx-nodes.tsindex 823bddc238..631f0bc459 100644--- a/packages/codemods/src/precompose-jsx-nodes.ts+++ b/packages/codemods/src/precompose-jsx-nodes.ts@@ -1337,7 +1337,16 @@ const getPrecompositionPlan = ({}const key = attribute.name.name;- if (!['name', 'from', 'durationInFrames', 'layout'].includes(key)) {+ if (+ ![+ 'name',+ 'from',+ 'durationInFrames',+ 'layout',+ 'premountFor',+ 'postmountFor',+ ].includes(key)+ ) {throw new Error('The selected sequence has unsupported props');}diff --git a/packages/codemods/src/split-video-from-audio.ts b/packages/codemods/src/split-video-from-audio.tsindex 37794bd1e5..c30bcc2139 100644--- a/packages/codemods/src/split-video-from-audio.ts+++ b/packages/codemods/src/split-video-from-audio.ts@@ -44,6 +44,8 @@ const audioProps = ['src','from','durationInFrames',+ 'premountFor',+ 'postmountFor','trimBefore','trimAfter','playbackRate',diff --git a/packages/codemods/src/test/fixtures/canvas-capture-composition.txt b/packages/codemods/src/test/fixtures/canvas-capture-composition.txtindex ffdba89a8e..b3d6db1bd9 100644--- a/packages/codemods/src/test/fixtures/canvas-capture-composition.txt+++ b/packages/codemods/src/test/fixtures/canvas-capture-composition.txt@@ -15,6 +15,7 @@ export const CanvasCapturePreview = () => {return (<AbsoluteFilldurationInFrames={500}+ premountFor={60}style={{width: 3026,height: 1386,diff --git a/packages/codemods/src/test/insert-solid.test.ts b/packages/codemods/src/test/insert-solid.test.tsindex 5710b9562d..9dbfb146bc 100644--- a/packages/codemods/src/test/insert-solid.test.ts+++ b/packages/codemods/src/test/insert-solid.test.ts@@ -138,6 +138,7 @@ export const Root = () => <Composition id = "MyComp" component={MyComposition}/>element: createElementFromInsertable({element: {height: 720, position: null, type: 'solid', width: 1280},from: null,+ premountFor: null,wrapInSequence: null,}),target: {@@ -176,6 +177,7 @@ export const Root = () => <Composition id = "MyComp" component={MyComposition}/>compositionId: 'MyComp',element: {height: 720, position: null, type: 'solid', width: 1280},from: null,+ premountFor: null,},svgMarkupToJsx: () => {throw new Error('SVG conversion should not be called');@@ -213,6 +215,7 @@ export const Root = () => <Composition id="MyComp" component={MyComposition}/>;type: 'asset',},from: null,+ premountFor: null,wrapInSequence: null,}),target,@@ -232,6 +235,7 @@ export const Root = () => <Composition id="MyComp" component={MyComposition}/>;type: 'component',},from: 12,+ premountFor: null,wrapInSequence: {dimensions: {width: 400, height: 300},durationInFrames: 60,diff --git a/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx b/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsxindex a5eda28ca8..462118dba1 100644--- a/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx+++ b/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx@@ -5,6 +5,7 @@ import {type HtmlInCanvasOnPaint,Interactive,type InteractiveBaseProps,+ type InteractivePremountProps,type InteractivitySchema,Internals,type SequenceControls,@@ -12,17 +13,19 @@ import {useVideoConfig,} from 'remotion';-export type HtmlInCanvasMotionBlurProps = InteractiveBaseProps & {- readonly children: React.ReactNode;- readonly width: number;- readonly height: number;- readonly shutterAngle?: number;- readonly samples?: number;- readonly disabled?: boolean;-};+export type HtmlInCanvasMotionBlurProps = InteractiveBaseProps &+ InteractivePremountProps & {+ readonly children: React.ReactNode;+ readonly width: number;+ readonly height: number;+ readonly shutterAngle?: number;+ readonly samples?: number;+ readonly disabled?: boolean;+ };const htmlInCanvasMotionBlurSchema = {...Interactive.baseSchema,+ ...Interactive.premountSchema,shutterAngle: {type: 'number',min: 0,@@ -126,7 +129,11 @@ const HtmlInCanvasMotionBlurInner: React.FC<freeze,hidden,name,+ premountFor,+ postmountFor,showInTimeline,+ styleWhilePremounted,+ styleWhilePostmounted,controls,}) => {const {durationInFrames: compositionDurationInFrames} = useVideoConfig();@@ -242,7 +249,11 @@ const HtmlInCanvasMotionBlurInner: React.FC<freeze={freeze}hidden={hidden}name={name ?? '<HtmlInCanvasMotionBlur>'}+ premountFor={premountFor}+ postmountFor={postmountFor}showInTimeline={showInTimeline}+ styleWhilePremounted={styleWhilePremounted}+ styleWhilePostmounted={styleWhilePostmounted}{...{controls}}onPaint={onPaint}_remotionInternalCanvasSiblings={sampleElements.slice(1)}diff --git a/packages/studio-server/src/helpers/resolve-composition-component.ts b/packages/studio-server/src/helpers/resolve-composition-component.tsindex 287bfbae9e..7cbfa15667 100644--- a/packages/studio-server/src/helpers/resolve-composition-component.ts+++ b/packages/studio-server/src/helpers/resolve-composition-component.ts@@ -90,6 +90,7 @@ export const insertJsxElementIntoComposition = async ({compositionId,element,from,+ premountFor,prettierConfigOverride,wrapInSequence = null,sourceFileOverrides,@@ -99,6 +100,7 @@ export const insertJsxElementIntoComposition = async ({compositionId: string;element: InsertableCompositionElement;from: number | null;+ premountFor: number | null;prettierConfigOverride: Record<string, unknown> | null;wrapInSequence?: {dimensions: {width: number; height: number} | null;@@ -136,6 +138,7 @@ export const insertJsxElementIntoComposition = async ({element,environment,from,+ premountFor,prettierConfigOverride,wrapInSequence: sequence,});@@ -144,6 +147,7 @@ export const insertJsxElementIntoComposition = async ({const codemodElement = createElementFromInsertable({element,from,+ premountFor,wrapInSequence: sequence,});const location = await resolveCompositionComponentWithFileCodemod({diff --git a/packages/studio-server/src/preview-server/routes/insert-basic-captions.ts b/packages/studio-server/src/preview-server/routes/insert-basic-captions.tsindex 4ac0b11ca3..2a950bd4ec 100644--- a/packages/studio-server/src/preview-server/routes/insert-basic-captions.ts+++ b/packages/studio-server/src/preview-server/routes/insert-basic-captions.ts@@ -30,7 +30,7 @@ export const insertBasicCaptionsHandler: ApiHandler<InsertBasicCaptionsRequest,InsertBasicCaptionsResponse> = ({- input: {fileName, nodePath, captions, durationInFrames},+ input: {fileName, nodePath, captions, durationInFrames, premountFor},remotionRoot,logLevel,}) =>@@ -73,6 +73,7 @@ export const insertBasicCaptionsHandler: ApiHandler<nodePath,captions,durationInFrames,+ premountFor,importPath: elementFile.importPath,});const nodePathMutation = broadcastSequenceNodePathMutation(diff --git a/packages/studio-server/src/preview-server/routes/insert-composition-element.ts b/packages/studio-server/src/preview-server/routes/insert-composition-element.tsindex d191392236..2619004c22 100644--- a/packages/studio-server/src/preview-server/routes/insert-composition-element.ts+++ b/packages/studio-server/src/preview-server/routes/insert-composition-element.ts@@ -221,7 +221,7 @@ export const insertCompositionElementHandler: ApiHandler<InsertCompositionElementRequest,InsertCompositionElementResponse> = ({- input: {compositionFile, compositionId, element, from},+ input: {compositionFile, compositionId, element, from, premountFor},remotionRoot,logLevel,}) =>@@ -235,6 +235,13 @@ export const insertCompositionElementHandler: ApiHandler<throw new Error('from must be a non-negative integer');}+ if (+ premountFor !== null &&+ (!Number.isInteger(premountFor) || premountFor < 0)+ ) {+ throw new Error('premountFor must be a non-negative integer');+ }+const elementLabel = getElementLabel(element);RenderInternals.Log.trace(@@ -256,6 +263,7 @@ export const insertCompositionElementHandler: ApiHandler<compositionId,element,from,+ premountFor,prettierConfigOverride: null,sourceFileOverrides: null,});diff --git a/packages/studio-server/src/preview-server/routes/insert-element.ts b/packages/studio-server/src/preview-server/routes/insert-element.tsindex 088692657c..1f8ba0b096 100644--- a/packages/studio-server/src/preview-server/routes/insert-element.ts+++ b/packages/studio-server/src/preview-server/routes/insert-element.ts@@ -78,6 +78,7 @@ export const insertElementHandler: ApiHandler<installationName,expectedFileState,from,+ premountFor,position,overwriteExisting,undoRedoNavigation,@@ -343,6 +344,7 @@ export const insertElementHandler: ApiHandler<position: componentOwnsSequence ? position : null,},from: componentOwnsSequence ? from : null,+ premountFor,prettierConfigOverride: null,wrapInSequence: componentOwnsSequence? nulldiff --git a/packages/studio-server/src/test/insert-basic-captions.test.ts b/packages/studio-server/src/test/insert-basic-captions.test.tsindex 37b73aea2d..9ef77d8794 100644--- a/packages/studio-server/src/test/insert-basic-captions.test.ts+++ b/packages/studio-server/src/test/insert-basic-captions.test.ts@@ -73,6 +73,7 @@ export const Comp = () => (nodePath: lineContainingToNodePath(current, tag),captions,durationInFrames,+ premountFor: 30,},entryPoint,remotionRoot,@@ -142,6 +143,7 @@ export const Comp = () => <Audio src="voice.mp3" />;`;},],durationInFrames: 30,+ premountFor: 30,});expect(output).toContain('<>');@@ -184,6 +186,7 @@ export const Comp = () => <Audio src="voice.mp3" />;`;nodePath: lineContainingToNodePath(input, '<Audio'),captions,durationInFrames: 30,+ premountFor: 30,importPath: localElement.importPath,});const second = insertBasicCaptions({@@ -191,6 +194,7 @@ export const Comp = () => <Audio src="voice.mp3" />;`;nodePath: lineContainingToNodePath(first.output, '<Audio'),captions,durationInFrames: 30,+ premountFor: 30,importPath: localElement.importPath,});expect(second.output.match(/<BasicCaptions captions/g)).toHaveLength(2);diff --git a/packages/studio-server/src/test/insert-element.test.ts b/packages/studio-server/src/test/insert-element.test.tsindex f1b433b334..fd7bb30f53 100644--- a/packages/studio-server/src/test/insert-element.test.ts+++ b/packages/studio-server/src/test/insert-element.test.ts@@ -83,6 +83,10 @@ const element: InsertElementRequest['element'] = {sourceCode: incomingElementSource,};+type InsertElementTestRequest = Omit<InsertElementRequest, 'premountFor'> & {+ premountFor?: number | null;+};+const makeFixture = () => {const remotionRoot = mkdtempSync(path.join(tmpdir(), 'remotion-element-'));const outsideRoot = mkdtempSync(@@ -121,14 +125,14 @@ const makeFixture = () => {addNewClientListener: () => () => undefined,});- const callHandlerWithInput = (input: InsertElementRequest) => {+ const callHandlerWithInput = (input: InsertElementTestRequest) => {return insertElementHandler({binariesDirectory: null,configFile: null,getDefaultCodingAgent: () => null,getDefaultEditor: () => null,entryPoint: compositionFile,- input,+ input: {...input, premountFor: input.premountFor ?? null},logLevel: 'error',methods: {addJob: () => undefined,@@ -282,7 +286,7 @@ export const LowerThird = ({logoSrc, ...props}: {logoSrc: string} & SequenceProp);`,};- const request: InsertElementRequest = {+ const request: InsertElementTestRequest = {installationName: null,compositionFile: 'Root.tsx',compositionId: 'target',@@ -755,7 +759,7 @@ test('installs independent named copies into the same and another composition',compositionSource.replace('id="target"', 'id="interview"'),);- const input: InsertElementRequest = {+ const input: InsertElementTestRequest = {installationName: 'speaker-name',compositionFile: 'Root.tsx',compositionId: 'target',diff --git a/packages/studio-server/src/test/node-path-mutation-routes.test.ts b/packages/studio-server/src/test/node-path-mutation-routes.test.tsindex 7dc0952a70..c4ca03f5fe 100644--- a/packages/studio-server/src/test/node-path-mutation-routes.test.ts+++ b/packages/studio-server/src/test/node-path-mutation-routes.test.ts@@ -226,6 +226,7 @@ test('JSX structure routes broadcast and return node path mutations before writiposition: null,},from: null,+ premountFor: null,},});if (!insertResponse.success) {diff --git a/packages/studio-server/src/test/resolve-composition-component.test.ts b/packages/studio-server/src/test/resolve-composition-component.test.tsindex 9ea8174a55..148f5438f6 100644--- a/packages/studio-server/src/test/resolve-composition-component.test.ts+++ b/packages/studio-server/src/test/resolve-composition-component.test.ts@@ -4,7 +4,7 @@ import os from 'node:os';import path from 'node:path';import {NoReactInternals} from 'remotion/no-react';import {- insertJsxElementIntoComposition,+ insertJsxElementIntoComposition as insertJsxElementIntoCompositionInternal,resolveCompositionComponent,} from '../helpers/resolve-composition-component';import {insertCompositionElementHandler} from '../preview-server/routes/insert-composition-element';@@ -12,6 +12,18 @@ import {lineContainingToNodePath} from './test-utils';const remotionRoot = path.join(__dirname, '..', '..', '..', 'example');+const insertJsxElementIntoComposition = (+ input: Omit<+ Parameters<typeof insertJsxElementIntoCompositionInternal>[0],+ 'premountFor'+ > & {premountFor?: number | null},+) => {+ return insertJsxElementIntoCompositionInternal({+ ...input,+ premountFor: input.premountFor ?? null,+ });+};+test('resolves a statically imported composition component', async () => {const location = await resolveCompositionComponent({remotionRoot,@@ -2010,6 +2022,7 @@ test('rejects inserting a composition whose component is not exported', async ()position: null,},from: null,+ premountFor: null,},entryPoint: path.join(tempDir, 'Root.tsx'),remotionRoot: tempDir,@@ -2204,6 +2217,7 @@ test('rejects composition insertion requests that traverse out of the project roposition: null,},from: null,+ premountFor: null,},entryPoint: path.join(tempDir, 'Root.tsx'),remotionRoot: tempDir,diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.tsindex c326653ec6..e88ed19533 100644--- a/packages/studio-shared/src/api-requests.ts+++ b/packages/studio-shared/src/api-requests.ts@@ -985,6 +985,7 @@ export type InsertBasicCaptionsRequest = {fileName: string;nodePath: SequenceNodePath;durationInFrames: number | null;+ premountFor: number | null;captions: {text: string;startMs: number;@@ -1062,6 +1063,7 @@ export type InsertCompositionElementRequest = {compositionId: string;element: InsertableCompositionElement;from: number | null;+ premountFor: number | null;};export type InsertCompositionElementResponse =@@ -1141,6 +1143,7 @@ export type InsertElementRequest = {element: InstallableElement;expectedFileState: ElementInstallExpectedFileState | null;from: number | null;+ premountFor: number | null;position: InsertableCompositionElementPosition | null;overwriteExisting: boolean;undoRedoNavigation: UndoRedoNavigation | null;diff --git a/packages/studio/src/components/Canvas.tsx b/packages/studio/src/components/Canvas.tsxindex fecf712553..b05abd7585 100644--- a/packages/studio/src/components/Canvas.tsx+++ b/packages/studio/src/components/Canvas.tsx@@ -1467,6 +1467,7 @@ export const Canvas: React.FC<{destinationDimensions:contentDimensions === 'none' ? null : contentDimensions,dropPosition,+ fps: config.fps,html: figmaHtml,});} finally {@@ -1487,6 +1488,7 @@ export const Canvas: React.FC<{destinationDimensions:contentDimensions === 'none' ? null : contentDimensions,dropPosition,+ fps: config.fps,markup: svgMarkup,});} finally {diff --git a/packages/studio/src/components/ElementInstallConfirmation.tsx b/packages/studio/src/components/ElementInstallConfirmation.tsxindex 285a5518a2..cb4f71c78a 100644--- a/packages/studio/src/components/ElementInstallConfirmation.tsx+++ b/packages/studio/src/components/ElementInstallConfirmation.tsx@@ -799,6 +799,10 @@ export const ElementInstallConfirmation: React.FC<{// The insert operation revalidates this even if the name preflight is pending.expectedFileState: activePlan?.expectedFileState ?? {exists: false},from: mode === 'new-composition' ? null : request.from,+ premountFor:+ mode === 'new-composition'+ ? newCompositionValues.fps+ : (currentCompositionMetadata?.fps ?? null),overwriteExisting,position: mode === 'new-composition' ? null : request.position,undoRedoNavigation:@@ -851,6 +855,8 @@ export const ElementInstallConfirmation: React.FC<{selectComposition,newCompositionValues.folder.folderName,newCompositionValues.folder.parentName,+ newCompositionValues.fps,+ currentCompositionMetadata?.fps,]);const cancel = useCallback(() => {diff --git a/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx b/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsxindex bbed99f20c..04e3835a82 100644--- a/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx+++ b/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx@@ -1,5 +1,5 @@import React, {useCallback, useContext, useMemo} from 'react';-import {Internals} from 'remotion';+import {Internals, useVideoConfig} from 'remotion';import {StudioServerConnectionCtx} from '../../helpers/client-id';import type {TimelineTrackData} from '../../helpers/get-timeline-sequence-sort-key';import {isStudioInteractivityEnabled} from '../../helpers/interactivity-enabled';@@ -126,6 +126,7 @@ const SequenceSourceQuickActions: React.FC<{readonly line: number;};}> = ({selection, track, validatedLocation}) => {+ const {fps} = useVideoConfig();const timelinePosition = Internals.Timeline.useTimelinePosition();const {previewServerState} = useContext(StudioServerConnectionCtx);const {setSelectedModal} = useContext(SetSelectedModalContext);@@ -192,12 +193,14 @@ const SequenceSourceQuickActions: React.FC<{durationInFrames: Number.isFinite(mediaSequence.duration)? mediaSequence.duration: null,+ premountFor: fps,},});}, [selection.nodePathInfo,setSelectedModal,mediaSequence,+ fps,transcriptionDisabledReason,]);const onRemoveBackground = useCallback(() => {diff --git a/packages/studio/src/components/InspectorPanel/use-composition-actions.ts b/packages/studio/src/components/InspectorPanel/use-composition-actions.tsindex f632b665f1..1084062487 100644--- a/packages/studio/src/components/InspectorPanel/use-composition-actions.ts+++ b/packages/studio/src/components/InspectorPanel/use-composition-actions.ts@@ -75,7 +75,7 @@ export const useCompositionActions = () => {currentCompositionId !== null &&compositionFile !== null;const canInsertAsset = canShowInsertAsset && !isAddingAsset;- const canShowInsertComposition = canShowInsertAsset;+ const canShowInsertComposition = canShowInsertAsset && videoConfig !== null;const canInsertComposition = canShowInsertComposition && !isAddingComposition;const canShowGenerateWithAgent =previewInteractive &&@@ -99,6 +99,7 @@ export const useCompositionActions = () => {compositionFile,compositionId: currentCompositionId,from: null,+ premountFor: videoConfig.fps,element: {type: 'solid',width: videoConfig.width,@@ -218,7 +219,8 @@ export const useCompositionActions = () => {if (!canInsertComposition ||currentCompositionId === null ||- compositionFile === null+ compositionFile === null ||+ videoConfig === null) {return;}@@ -244,6 +246,7 @@ export const useCompositionActions = () => {compositionFile,compositionId: currentCompositionId,dropPosition: null,+ fps: videoConfig.fps,from: null,preferCompositionStart: null,});@@ -263,6 +266,7 @@ export const useCompositionActions = () => {canInsertComposition,compositionFile,currentCompositionId,+ videoConfig,],);diff --git a/packages/studio/src/components/RenderQueue/CaptionQueueProcessor.tsx b/packages/studio/src/components/RenderQueue/CaptionQueueProcessor.tsxindex b9cf63ad3b..b438902a3b 100644--- a/packages/studio/src/components/RenderQueue/CaptionQueueProcessor.tsx+++ b/packages/studio/src/components/RenderQueue/CaptionQueueProcessor.tsx@@ -133,6 +133,7 @@ export const CaptionQueueProcessor: React.FC = () => {fileName: job.target.fileName,nodePath: job.target.nodePath.nodePath,durationInFrames: job.target.durationInFrames,+ premountFor: job.target.premountFor,captions,};const browserStudioOperations = getBrowserStudioOperations();diff --git a/packages/studio/src/components/RenderQueue/caption-job-types.ts b/packages/studio/src/components/RenderQueue/caption-job-types.tsindex 83546fb4b3..9cf8c8fb72 100644--- a/packages/studio/src/components/RenderQueue/caption-job-types.ts+++ b/packages/studio/src/components/RenderQueue/caption-job-types.ts@@ -29,6 +29,7 @@ export type AddCaptionJobParams = {fileName: string;nodePath: SequencePropsSubscriptionKey;durationInFrames: number | null;+ premountFor: number | null;} | null;model: WhisperWebGpuModel;language: string | null;diff --git a/packages/studio/src/components/Timeline/Timeline.tsx b/packages/studio/src/components/Timeline/Timeline.tsxindex c6bfdec4b7..2f0bb48a1a 100644--- a/packages/studio/src/components/Timeline/Timeline.tsx+++ b/packages/studio/src/components/Timeline/Timeline.tsx@@ -162,6 +162,7 @@ const TimelineContextMenuArea: React.FC<{compositionFile,compositionId: currentCompositionId,from: null,+ premountFor: videoConfig.fps,element: {type: 'solid',width: videoConfig.width,diff --git a/packages/studio/src/components/handle-drop.ts b/packages/studio/src/components/handle-drop.tsindex cde4367d18..b326566229 100644--- a/packages/studio/src/components/handle-drop.ts+++ b/packages/studio/src/components/handle-drop.ts@@ -123,6 +123,7 @@ export const handleDrop = async ({compositionFile,compositionId,dropPosition,+ fps,from,preferCompositionStart,});@@ -164,6 +165,7 @@ export const handleDrop = async ({compositionFile,compositionId,dropPosition,+ fps,from,preferCompositionStart,});diff --git a/packages/studio/src/components/import-assets.ts b/packages/studio/src/components/import-assets.tsindex c9fd2b9bf5..47651c971f 100644--- a/packages/studio/src/components/import-assets.ts+++ b/packages/studio/src/components/import-assets.ts@@ -678,11 +678,13 @@ const insertCompositionElement = async ({compositionId,element,from,+ premountFor,}: {compositionFile: string;compositionId: string;element: InsertableCompositionElement;from: number | null;+ premountFor: number | null;}) => {const requiredPackage = getRequiredPackageForInsertableElement(element);const browserStudioOperations = getBrowserStudioOperations();@@ -692,7 +694,13 @@ const insertCompositionElement = async ({);}- const request = {compositionFile, compositionId, element, from};+ const request = {+ compositionFile,+ compositionId,+ element,+ from,+ premountFor,+ };const result = browserStudioOperations? await browserStudioOperations.insertCompositionElement(request): await callApi('/api/insert-composition-element', request);@@ -791,6 +799,7 @@ export const importAssets = async ({from,preferCompositionStart,}),+ premountFor: fps,element: {type: 'svg',markup: new TextDecoder().decode(contents),@@ -851,6 +860,7 @@ export const importAssets = async ({from,preferCompositionStart,}),+ premountFor: fps,element: {...element,dimensions: resolvedDimensions,@@ -886,12 +896,14 @@ export const importFigmaClipboard = async ({compositionId,destinationDimensions,dropPosition,+ fps,html,}: {compositionFile: string;compositionId: string;destinationDimensions: Dimensions | null;dropPosition: InsertElementDropPosition | null;+ fps: number;html: string;}) => {// Figma clipboard conversion requires the SVGR-based pipeline in@@ -921,6 +933,7 @@ export const importFigmaClipboard = async ({compositionId,destinationDimensions,dropPosition,+ fps,markup: converted.svg,});} catch (error) {@@ -938,12 +951,14 @@ export const insertSvgMarkup = async ({compositionId,destinationDimensions,dropPosition,+ fps,markup,}: {compositionFile: string;compositionId: string;destinationDimensions: Dimensions | null;dropPosition: InsertElementDropPosition | null;+ fps: number;markup: string;}) => {try {@@ -964,6 +979,7 @@ export const insertSvgMarkup = async ({compositionFile,compositionId,from: null,+ premountFor: fps,element: {type: 'svg',markup,@@ -1035,6 +1051,7 @@ export const importRemoteAsset = async ({from,preferCompositionStart,}),+ premountFor: fps,element: {...element,dimensions,@@ -1100,6 +1117,7 @@ export const insertRemoteAudio = async ({from,preferCompositionStart,}),+ premountFor: fps,});} catch (error) {showNotification(@@ -1164,6 +1182,7 @@ export const insertExistingAssets = async ({from,preferCompositionStart,}),+ premountFor: fps,element: {...element,dimensions,@@ -1197,6 +1216,7 @@ export const insertComponent = async ({compositionFile,compositionId,dropPosition,+ fps,from,preferCompositionStart,}: {@@ -1204,6 +1224,7 @@ export const insertComponent = async ({compositionFile: string;compositionId: string;dropPosition: InsertElementDropPosition | null;+ fps: number;from: number | null;preferCompositionStart: boolean | null;}) => {@@ -1216,6 +1237,7 @@ export const insertComponent = async ({from,preferCompositionStart,}),+ premountFor: fps,element: {type: 'component',componentName: component.componentName,@@ -1253,6 +1275,7 @@ export const insertComposition = async ({compositionFile,compositionId,dropPosition,+ fps,from,preferCompositionStart,}: {@@ -1260,6 +1283,7 @@ export const insertComposition = async ({compositionFile: string;compositionId: string;dropPosition: InsertElementDropPosition | null;+ fps: number;from: number | null;preferCompositionStart: boolean | null;}) => {@@ -1294,6 +1318,7 @@ export const insertComposition = async ({from,preferCompositionStart,}),+ premountFor: fps,element: {type: 'composition',compositionId: composition.compositionId,@@ -1327,6 +1352,7 @@ export const insertElement = async ({expectedFileState,position,from,+ premountFor,overwriteExisting,undoRedoNavigation,newComposition,@@ -1338,6 +1364,7 @@ export const insertElement = async ({expectedFileState: ElementInstallExpectedFileState;position: InsertableCompositionElementPosition | null;from: number | null;+ premountFor: number | null;overwriteExisting: boolean;undoRedoNavigation: InsertElementRequest['undoRedoNavigation'];newComposition: InsertElementRequest['newComposition'];@@ -1354,6 +1381,7 @@ export const insertElement = async ({element,expectedFileState,from,+ premountFor,overwriteExisting,position,undoRedoNavigation,diff --git a/packages/studio/src/state/modals.ts b/packages/studio/src/state/modals.tsindex ab9a1fc52a..b0fcc0dba0 100644--- a/packages/studio/src/state/modals.ts+++ b/packages/studio/src/state/modals.ts@@ -167,6 +167,7 @@ export type TranscriptionModalState = {fileName: string;nodePath: SequencePropsSubscriptionKey;durationInFrames: number | null;+ premountFor: number | null;} | null;};diff --git a/packages/studio/src/test/caption-queue-processor.test.tsx b/packages/studio/src/test/caption-queue-processor.test.tsxindex 54396b60f7..1cf16c4581 100644--- a/packages/studio/src/test/caption-queue-processor.test.tsx+++ b/packages/studio/src/test/caption-queue-processor.test.tsx@@ -397,6 +397,7 @@ test('downloads a model in the queued job before transcribing', async () => {videoConfigValues: null,},durationInFrames: 90,+ premountFor: 30,},src: '/static/clip.mp4',});@@ -415,6 +416,7 @@ test('downloads a model in the queued job before transcribing', async () => {fileName: '/project/Root.tsx',nodePath: [0],durationInFrames: 90,+ premountFor: 30,captions: [{text: 'Hello',@@ -487,6 +489,7 @@ test('downloads a model in the queued job before transcribing', async () => {fileName: '/project/Browser.tsx',nodePath: [0],durationInFrames: 45,+ premountFor: 30,captions: (insertedRequests[0].body as {captions: unknown}).captions,},]);diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsxindex cdbb305312..a314cababa 100644--- a/packages/transitions/src/TransitionSeries.tsx+++ b/packages/transitions/src/TransitionSeries.tsx@@ -100,7 +100,9 @@ const SeriesOverlayInner: FC<InternalTransitionSeriesOverlayProps> = ({return null;};-const transitionSeriesOverlaySchema = {} satisfies InteractivitySchema;+const transitionSeriesOverlaySchema = {+ ...Internals.premountSchema,+} satisfies InteractivitySchema;const SeriesOverlay = Interactive.withSchema({Component: SeriesOverlayInner as unknown as React.ComponentType<@@ -311,6 +313,10 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({readonly children: React.ReactNode;readonly index: number;readonly controls: SequenceControls | null | undefined;+ readonly premountFor: number | undefined;+ readonly postmountFor: number | undefined;+ readonly styleWhilePremounted: React.CSSProperties | undefined;+ readonly styleWhilePostmounted: React.CSSProperties | undefined;};type RenderState = {@@ -342,6 +348,10 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({_remotionInternalDocumentationLink="https://www.remotion.dev/docs/transitions/transitionseries"controls={info.controls ?? undefined}layout="absolute-fill"+ premountFor={info.premountFor}+ postmountFor={info.postmountFor}+ styleWhilePremounted={info.styleWhilePremounted}+ styleWhilePostmounted={info.styleWhilePostmounted}>{info.children}</SequenceWithoutSchema>@@ -478,6 +488,10 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({children: overlayProps.children,index: i,controls: overlayProps.controls,+ premountFor: overlayProps.premountFor,+ postmountFor: overlayProps.postmountFor,+ styleWhilePremounted: overlayProps.styleWhilePremounted,+ styleWhilePostmounted: overlayProps.styleWhilePostmounted,};return renderNext({diff --git a/packages/transitions/src/types.ts b/packages/transitions/src/types.tsindex c981607079..a7f49a6a43 100644--- a/packages/transitions/src/types.ts+++ b/packages/transitions/src/types.ts@@ -1,5 +1,6 @@import type React from 'react';import type {ComponentType} from 'react';+import type {AbsoluteFillLayout} from 'remotion';import type {DrawFunction} from './TransitionSeries';export type PresentationDirection = 'entering' | 'exiting';@@ -40,7 +41,13 @@ export type TransitionPresentationComponentProps<bothEnteringAndExiting: boolean;};-export type TransitionSeriesOverlayProps = {+export type TransitionSeriesOverlayProps = Pick<+ AbsoluteFillLayout,+ | 'premountFor'+ | 'postmountFor'+ | 'styleWhilePremounted'+ | 'styleWhilePostmounted'+> & {readonly durationInFrames: number;readonly offset?: number;readonly children: React.ReactNode;