Skip to content

🎥 Make videos programmatically with React

`@remotion/codemods`: Add public APIs for editing Remotion source

JonnyBurger108f04f9ca93
diff --git a/packages/codemods/src/add-content.ts b/packages/codemods/src/add-content.ts
new file mode 100644
index 0000000000..f51e81cdaa
--- /dev/null
+++ b/packages/codemods/src/add-content.ts
@@ -0,0 +1,167 @@
+import type {InsertableCompositionElement} from '@remotion/studio-shared';
+import type {CodemodProject} from './codemod-project';
+import {insertJsxElementIntoProjectWithNodePathRemappings} from './insert-jsx-element';
+import {findProjectFile} from './internals';
+import {
+ getNodeEditResult,
+ type CodemodInsertionResult,
+} from './node-references';
+
+export type CodemodValue =
+ | string
+ | number
+ | boolean
+ | null
+ | CodemodValue[]
+ | {[key: string]: CodemodValue};
+
+export type AddContentOptions<Project extends CodemodProject> = {
+ project: Project;
+ compositionFile: string;
+ compositionId: string;
+ from?: number;
+ durationInFrames?: number;
+ position?: {x: number; y: number};
+};
+
+export type AddMediaOptions<Project extends CodemodProject> =
+ AddContentOptions<Project> & {
+ type: 'image' | 'video' | 'audio' | 'gif' | 'animated-image';
+ src: string;
+ srcType: 'static' | 'remote';
+ dimensions?: {width: number; height: number};
+ };
+
+export type AddComponentOptions<Project extends CodemodProject> =
+ AddContentOptions<Project> & {
+ importName: string;
+ importPath: string;
+ props?: Record<string, CodemodValue>;
+ };
+
+const insertContent = async <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ compositionId,
+ from,
+ durationInFrames,
+ position,
+ element,
+}: AddContentOptions<Project> & {
+ element: InsertableCompositionElement;
+}): Promise<CodemodInsertionResult<Project>> => {
+ if (from !== undefined && (!Number.isInteger(from) || from < 0)) {
+ throw new Error('from must be a non-negative integer');
+ }
+
+ if (
+ durationInFrames !== undefined &&
+ (!Number.isInteger(durationInFrames) || durationInFrames <= 0)
+ ) {
+ throw new Error('durationInFrames must be a positive integer');
+ }
+
+ if (
+ position &&
+ (!Number.isFinite(position.x) || !Number.isFinite(position.y))
+ ) {
+ throw new Error('Position must be finite');
+ }
+
+ const wrapped = from !== undefined || durationInFrames !== undefined;
+ const insertion = await insertJsxElementIntoProjectWithNodePathRemappings({
+ project,
+ request: {
+ compositionFile,
+ compositionId,
+ from: null,
+ element: {...element, position: wrapped ? null : (position ?? null)},
+ },
+ svgMarkupToJsx: () => {
+ throw new Error('SVG markup is not supported by this operation');
+ },
+ wrapInSequence: wrapped
+ ? {
+ dimensions: element.type === 'asset' ? element.dimensions : null,
+ durationInFrames: durationInFrames ?? null,
+ from: from ?? 0,
+ name: null,
+ position: position ?? null,
+ }
+ : null,
+ });
+ const filePath = findProjectFile({project, filePath: insertion.filePath});
+ if (!insertion.insertedNodePath) {
+ throw new Error('Could not locate the inserted JSX node');
+ }
+
+ return {
+ ...getNodeEditResult({
+ project,
+ edits: [
+ {
+ filePath,
+ output: insertion.project.files[insertion.filePath],
+ nodePathRemappings: insertion.nodePathRemappings,
+ },
+ ],
+ }),
+ insertedNode: {filePath, nodePath: insertion.insertedNodePath},
+ };
+};
+
+export const addMedia = <Project extends CodemodProject>({
+ type,
+ src,
+ srcType,
+ dimensions,
+ ...options
+}: AddMediaOptions<Project>): Promise<CodemodInsertionResult<Project>> => {
+ if (
+ dimensions &&
+ (!Number.isFinite(dimensions.width) ||
+ dimensions.width <= 0 ||
+ !Number.isFinite(dimensions.height) ||
+ dimensions.height <= 0)
+ ) {
+ throw new Error('Media dimensions must be positive finite numbers');
+ }
+
+ return insertContent({
+ ...options,
+ element: {
+ type: 'asset',
+ assetType: type,
+ src,
+ srcType,
+ dimensions: dimensions ?? null,
+ durationInFrames: null,
+ position: null,
+ },
+ });
+};
+
+export const addComponent = <Project extends CodemodProject>({
+ importName,
+ importPath,
+ props = {},
+ ...options
+}: AddComponentOptions<Project>): Promise<CodemodInsertionResult<Project>> => {
+ if (!/^[A-Z_$][\w$]*$/.test(importName) || importName === 'default') {
+ throw new Error(
+ 'importName must be a named component export beginning with an uppercase letter, _ or $',
+ );
+ }
+
+ return insertContent({
+ ...options,
+ element: {
+ type: 'component',
+ componentName: importName,
+ importName,
+ importPath,
+ props: Object.entries(props).map(([name, value]) => ({name, value})),
+ position: null,
+ },
+ });
+};
diff --git a/packages/codemods/src/add-solid.ts b/packages/codemods/src/add-solid.ts
index f158293954..78eab62af4 100644
--- a/packages/codemods/src/add-solid.ts
+++ b/packages/codemods/src/add-solid.ts
@@ -1,7 +1,7 @@
-import type {SequenceNodePath} from 'remotion';
-import type {CodemodProject, CodemodResult} from './codemod-project';
+import type {CodemodProject} from './codemod-project';
import {getCodemodResult} from './codemod-project';
import {insertSolidIntoProjectWithNodePathRemappings} from './internals';
+import type {CodemodInsertionResult} from './node-references';
export type AddSolidOptions<Project extends CodemodProject> = {
project: Project;
@@ -14,12 +14,7 @@ export type AddSolidOptions<Project extends CodemodProject> = {
};
export type AddSolidResult<Project extends CodemodProject> =
- CodemodResult<Project> & {
- insertedNode: {
- filePath: string;
- nodePath: SequenceNodePath;
- };
- };
+ CodemodInsertionResult<Project>;
export const addSolid = <Project extends CodemodProject>({
project,
@@ -53,6 +48,10 @@ export const addSolid = <Project extends CodemodProject>({
return {
...getCodemodResult({nextProject: insertion.project, project}),
+ nodePathRemappings: insertion.nodePathRemappings.map((remapping) => ({
+ filePath: insertion.filePath,
+ ...remapping,
+ })),
insertedNode: {
filePath: insertion.filePath,
nodePath: insertedNodePath,
diff --git a/packages/codemods/src/composition-operations.ts b/packages/codemods/src/composition-operations.ts
new file mode 100644
index 0000000000..07cdd5b0c4
--- /dev/null
+++ b/packages/codemods/src/composition-operations.ts
@@ -0,0 +1,359 @@
+import type {RecastCodemod} from '@remotion/studio-shared';
+import * as recast from 'recast';
+import type {CodemodValue} from './add-content';
+import type {CodemodProject, CodemodResult} from './codemod-project';
+import {getCodemodResult} from './codemod-project';
+import {getJsxNodes} from './get-jsx-nodes';
+import {findProjectFile} from './internals';
+import {getJsxNodeProps, updateJsxNodeProps} from './jsx-props';
+import {parseAndApplyCodemod} from './parse-and-apply-codemod';
+import {resolveCompositionComponentInProject} from './resolve-composition-component-location';
+import {parseAst} from './sequence-props/parse-ast';
+
+export type CompositionTarget = {
+ compositionFile: string;
+ compositionId: string;
+};
+
+export type CompositionMetadata = {
+ width: number;
+ height: number;
+ fps: number;
+ durationInFrames: number;
+};
+
+export type FolderReference = {
+ name: string;
+ parentName: string | null;
+};
+
+export type ResolveCompositionComponentOptions = CompositionTarget & {
+ project: CodemodProject;
+};
+
+export const resolveCompositionComponent = ({
+ project,
+ compositionFile,
+ compositionId,
+}: ResolveCompositionComponentOptions) => {
+ const resolved = resolveCompositionComponentInProject({
+ project,
+ compositionFile,
+ compositionId,
+ });
+ return {
+ filePath: findProjectFile({project, filePath: resolved.filePath}),
+ exportName: resolved.exportName,
+ location: {line: resolved.location.line, column: resolved.location.column},
+ canAddContent: resolved.canAddSequence,
+ };
+};
+
+const getCompositionNodes = ({
+ project,
+ compositionFile,
+}: {
+ project: CodemodProject;
+ compositionFile: string;
+}) => {
+ return getJsxNodes({project, filePath: compositionFile})
+ .filter(
+ (node) =>
+ (node.tagName === 'Composition' || node.tagName === 'Still') &&
+ node.componentIdentity === `dev.remotion.remotion.${node.tagName}`,
+ )
+ .map((node) => {
+ const status = getJsxNodeProps({project, node, keys: ['id']}).props.id;
+ return {node, id: status.status === 'static' ? status.codeValue : null};
+ });
+};
+
+const requireComposition = ({
+ project,
+ compositionFile,
+ compositionId,
+}: ResolveCompositionComponentOptions) => {
+ const matches = getCompositionNodes({project, compositionFile}).filter(
+ ({id}) => id === compositionId,
+ );
+ if (matches.length !== 1) {
+ throw new Error(
+ `Expected one composition with ID "${compositionId}" in "${compositionFile}", found ${matches.length}`,
+ );
+ }
+
+ return matches[0].node;
+};
+
+const assertNewCompositionId = ({
+ project,
+ compositionFile,
+ compositionId,
+}: ResolveCompositionComponentOptions) => {
+ if (!/^[a-zA-Z0-9-]+$/.test(compositionId)) {
+ throw new Error(
+ 'Composition IDs may only contain letters, numbers, and hyphens',
+ );
+ }
+
+ if (
+ getCompositionNodes({project, compositionFile}).some(
+ ({id}) => id === compositionId,
+ )
+ ) {
+ throw new Error(
+ `Composition "${compositionId}" already exists in "${compositionFile}"`,
+ );
+ }
+};
+
+const validateMetadata = (metadata: Partial<CompositionMetadata>) => {
+ for (const [key, value] of Object.entries(metadata)) {
+ if (value === undefined) {
+ continue;
+ }
+
+ if (
+ !Number.isFinite(value) ||
+ value <= 0 ||
+ (key !== 'fps' && !Number.isInteger(value))
+ ) {
+ throw new Error(
+ `${key} must be ${key === 'fps' ? 'a positive finite number' : 'a positive integer'}`,
+ );
+ }
+ }
+};
+
+export const editCompositionProject = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ codemod,
+}: {
+ project: Project;
+ compositionFile: string;
+ codemod: RecastCodemod;
+}): CodemodResult<Project> => {
+ const filePath = findProjectFile({project, filePath: compositionFile});
+ if (codemod.type === 'new-composition' || codemod.type === 'new-folder') {
+ const functions = new Set<object>();
+ recast.visit(parseAst(project.files[filePath]), {
+ visitNode(path) {
+ if (
+ !recast.types.namedTypes.JSXElement.check(path.node) &&
+ !recast.types.namedTypes.JSXFragment.check(path.node)
+ ) {
+ this.traverse(path);
+ return false;
+ }
+
+ let parent = path.parentPath;
+ while (parent) {
+ if (recast.types.namedTypes.Function.check(parent.node)) {
+ functions.add(parent.node);
+ break;
+ }
+
+ parent = parent.parentPath;
+ }
+
+ this.traverse(path);
+ return false;
+ },
+ });
+ if (functions.size > 1) {
+ throw new Error(
+ 'Adding registrations requires a file with a single JSX component',
+ );
+ }
+ }
+
+ const {newContents} = parseAndApplyCodemod({
+ input: project.files[filePath],
+ codeMod: codemod,
+ });
+ parseAst(newContents);
+ return getCodemodResult({
+ project,
+ nextProject: {
+ ...project,
+ files: {...project.files, [filePath]: newContents},
+ },
+ });
+};
+
+export type AddCompositionOptions<Project extends CodemodProject> =
+ CompositionTarget & {
+ project: Project;
+ component: {importName: string; importPath: string};
+ metadata: CompositionMetadata;
+ folder?: FolderReference;
+ };
+
+export const addComposition = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ compositionId,
+ component,
+ metadata,
+ folder,
+}: AddCompositionOptions<Project>): CodemodResult<Project> => {
+ assertNewCompositionId({project, compositionFile, compositionId});
+ validateMetadata(metadata);
+ if (!/^[A-Z_$][\w$]*$/.test(component.importName)) {
+ throw new Error(
+ 'component.importName must be a named component export beginning with an uppercase letter, _ or $',
+ );
+ }
+
+ return editCompositionProject({
+ project,
+ compositionFile,
+ codemod: {
+ type: 'new-composition',
+ newId: compositionId,
+ componentName: component.importName,
+ componentImportPath: component.importPath,
+ newWidth: metadata.width,
+ newHeight: metadata.height,
+ newFps: metadata.fps,
+ newDurationInFrames: metadata.durationInFrames,
+ folderName: folder?.name ?? null,
+ parentName: folder?.parentName ?? null,
+ canvasCapture: null,
+ },
+ });
+};
+
+export type RenameCompositionOptions<Project extends CodemodProject> =
+ CompositionTarget & {project: Project; newId: string};
+
+export const renameComposition = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ compositionId,
+ newId,
+}: RenameCompositionOptions<Project>): CodemodResult<Project> => {
+ requireComposition({project, compositionFile, compositionId});
+ if (newId === compositionId) {
+ return getCodemodResult({project, nextProject: project});
+ }
+
+ assertNewCompositionId({project, compositionFile, compositionId: newId});
+ return editCompositionProject({
+ project,
+ compositionFile,
+ codemod: {type: 'rename-composition', idToRename: compositionId, newId},
+ });
+};
+
+export type DuplicateCompositionOptions<Project extends CodemodProject> =
+ CompositionTarget & {
+ project: Project;
+ newId: string;
+ metadata?: Partial<CompositionMetadata>;
+ };
+
+export const duplicateComposition = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ compositionId,
+ newId,
+ metadata = {},
+}: DuplicateCompositionOptions<Project>): CodemodResult<Project> => {
+ const node = requireComposition({project, compositionFile, compositionId});
+ assertNewCompositionId({project, compositionFile, compositionId: newId});
+ validateMetadata(metadata);
+ if (
+ node.tagName === 'Still' &&
+ (metadata.fps !== undefined || metadata.durationInFrames !== undefined)
+ ) {
+ throw new Error('Still registrations do not have fps or durationInFrames');
+ }
+
+ return editCompositionProject({
+ project,
+ compositionFile,
+ codemod: {
+ type: 'duplicate-composition',
+ idToDuplicate: compositionId,
+ newId,
+ tag: node.tagName === 'Still' ? 'Still' : 'Composition',
+ newWidth: metadata.width ?? null,
+ newHeight: metadata.height ?? null,
+ newFps: metadata.fps ?? null,
+ newDurationInFrames: metadata.durationInFrames ?? null,
+ },
+ });
+};
+
+export type DeleteCompositionOptions<Project extends CodemodProject> =
+ CompositionTarget & {project: Project};
+
+export const deleteComposition = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ compositionId,
+}: DeleteCompositionOptions<Project>): CodemodResult<Project> => {
+ requireComposition({project, compositionFile, compositionId});
+ return editCompositionProject({
+ project,
+ compositionFile,
+ codemod: {type: 'delete-composition', idToDelete: compositionId},
+ });
+};
+
+export type UpdateCompositionMetadataOptions<Project extends CodemodProject> =
+ CompositionTarget & {
+ project: Project;
+ metadata: Partial<CompositionMetadata>;
+ };
+
+export const updateCompositionMetadata = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ compositionId,
+ metadata,
+}: UpdateCompositionMetadataOptions<Project>): CodemodResult<Project> => {
+ const node = requireComposition({project, compositionFile, compositionId});
+ validateMetadata(metadata);
+ if (
+ node.tagName === 'Still' &&
+ (metadata.fps !== undefined || metadata.durationInFrames !== undefined)
+ ) {
+ throw new Error('Still registrations do not have fps or durationInFrames');
+ }
+
+ if (Object.values(metadata).every((value) => value === undefined)) {
+ return getCodemodResult({project, nextProject: project});
+ }
+
+ return editCompositionProject({
+ project,
+ compositionFile,
+ codemod: {
+ type: 'update-composition-metadata',
+ idToUpdate: compositionId,
+ newWidth: metadata.width ?? null,
+ newHeight: metadata.height ?? null,
+ newFps: metadata.fps ?? null,
+ newDurationInFrames: metadata.durationInFrames ?? null,
+ },
+ });
+};
+
+export type SetCompositionDefaultPropsOptions<Project extends CodemodProject> =
+ CompositionTarget & {
+ project: Project;
+ defaultProps: Record<string, CodemodValue>;
+ };
+
+export const setCompositionDefaultProps = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ compositionId,
+ defaultProps,
+}: SetCompositionDefaultPropsOptions<Project>) => {
+ const node = requireComposition({project, compositionFile, compositionId});
+ return updateJsxNodeProps({project, node, props: {defaultProps}});
+};
diff --git a/packages/codemods/src/delete-jsx-nodes.ts b/packages/codemods/src/delete-jsx-nodes.ts
index 4f9349b270..8f6896e049 100644
--- a/packages/codemods/src/delete-jsx-nodes.ts
+++ b/packages/codemods/src/delete-jsx-nodes.ts
@@ -1,53 +1,30 @@
-import type {SequenceNodePath} from 'remotion';
-import type {CodemodProject, CodemodResult} from './codemod-project';
-import {getCodemodResult} from './codemod-project';
+import type {CodemodProject} from './codemod-project';
import {deleteJsxNodes as deleteJsxNodesFromSource} from './delete-jsx-nodes-internal';
-import {findProjectFile} from './internals';
+import {
+ getNodeEditResult,
+ groupNodeReferencesByFile,
+ type CodemodNodeResult,
+ type JsxNodeReference,
+} from './node-references';
export type DeleteJsxNodesOptions<Project extends CodemodProject> = {
project: Project;
- nodes: {filePath: string; nodePath: SequenceNodePath}[];
+ nodes: JsxNodeReference[];
};
export const deleteJsxNodes = async <Project extends CodemodProject>({
project,
nodes,
-}: DeleteJsxNodesOptions<Project>): Promise<CodemodResult<Project>> => {
- if (nodes.length === 0) {
- throw new Error('No JSX nodes were specified for deletion');
- }
-
- const nodesByFile = new Map<string, SequenceNodePath[]>();
- for (const node of nodes) {
- const resolvedFilePath = findProjectFile({
- filePath: node.filePath,
- project,
- });
- const nodePaths = nodesByFile.get(resolvedFilePath) ?? [];
- nodePaths.push(node.nodePath);
- nodesByFile.set(resolvedFilePath, nodePaths);
- }
-
- const updates = await Promise.all(
- [...nodesByFile].map(async ([filePath, nodePaths]) => ({
+}: DeleteJsxNodesOptions<Project>): Promise<CodemodNodeResult<Project>> => {
+ const groups = groupNodeReferencesByFile({project, nodes});
+ const edits = await Promise.all(
+ [...groups].map(async ([filePath, nodePaths]) => ({
filePath,
- output: (
- await deleteJsxNodesFromSource({
- input: project.files[filePath],
- nodePaths,
- })
- ).output,
+ ...(await deleteJsxNodesFromSource({
+ input: project.files[filePath],
+ nodePaths,
+ })),
})),
);
- const nextProject = {
- ...project,
- files: {
- ...project.files,
- ...Object.fromEntries(
- updates.map(({filePath, output}) => [filePath, output]),
- ),
- },
- };
-
- return getCodemodResult({nextProject, project});
+ return getNodeEditResult({project, edits});
};
diff --git a/packages/codemods/src/folder-operations.ts b/packages/codemods/src/folder-operations.ts
new file mode 100644
index 0000000000..4cc66c4c45
--- /dev/null
+++ b/packages/codemods/src/folder-operations.ts
@@ -0,0 +1,284 @@
+import type {JSXElement} from '@babel/types';
+import type {CompositionOrFolder, RecastCodemod} from '@remotion/studio-shared';
+import * as recast from 'recast';
+import type {CodemodProject} from './codemod-project';
+import {getCodemodResult} from './codemod-project';
+import {
+ editCompositionProject,
+ type CompositionTarget,
+ type FolderReference,
+} from './composition-operations';
+import {findProjectFile} from './internals';
+import {
+ getCompositionIdFromJSXElement,
+ getFolderNameFromJSXElement,
+} from './recast-mods';
+import {parseAst} from './sequence-props/parse-ast';
+
+export type CompositionTreeItem =
+ | {type: 'composition'; compositionId: string}
+ | ({type: 'folder'} & FolderReference);
+export type CompositionDestination =
+ | {type: 'root'}
+ | {type: 'folder'; folder: FolderReference}
+ | {type: 'before' | 'after'; target: CompositionTreeItem};
+
+type TreeEntry = {item: CompositionTreeItem; parentName: string | null};
+
+const getTreeEntries = ({
+ project,
+ compositionFile,
+}: {
+ project: CodemodProject;
+ compositionFile: string;
+}): TreeEntry[] => {
+ const filePath = findProjectFile({project, filePath: compositionFile});
+ const ast = parseAst(project.files[filePath]);
+ const entries: TreeEntry[] = [];
+ const folders: string[] = [];
+ recast.visit(ast, {
+ visitJSXElement(path) {
+ const element = path.node as JSXElement;
+ const name = getFolderNameFromJSXElement(element);
+ const compositionId = getCompositionIdFromJSXElement(element);
+ const parentName = folders.join('/') || null;
+ if (name !== null) {
+ entries.push({item: {type: 'folder', name, parentName}, parentName});
+ folders.push(name);
+ } else if (compositionId) {
+ entries.push({item: {type: 'composition', compositionId}, parentName});
+ }
+
+ this.traverse(path);
+ if (name !== null) {
+ folders.pop();
+ }
+
+ return false;
+ },
+ });
+ return entries;
+};
+
+const requireTreeItem = (entries: TreeEntry[], item: CompositionTreeItem) => {
+ const matches = entries.filter(({item: entry}) =>
+ item.type === 'composition'
+ ? entry.type === 'composition' &&
+ entry.compositionId === item.compositionId
+ : entry.type === 'folder' &&
+ entry.name === item.name &&
+ entry.parentName === item.parentName,
+ );
+ if (matches.length !== 1) {
+ throw new Error(
+ `Expected one ${item.type} matching ${JSON.stringify(item)}, found ${matches.length}`,
+ );
+ }
+
+ return matches[0];
+};
+
+const toSourceItem = (item: CompositionTreeItem): CompositionOrFolder =>
+ item.type === 'composition'
+ ? item
+ : {type: 'folder', folderName: item.name, parentName: item.parentName};
+
+const moveTreeItem = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ source,
+ destination,
+}: {
+ project: Project;
+ compositionFile: string;
+ source: CompositionTreeItem;
+ destination: CompositionDestination;
+}) => {
+ const entries = getTreeEntries({project, compositionFile});
+ const entry = requireTreeItem(entries, source);
+ let target: Extract<
+ RecastCodemod,
+ {type: 'move-composition-or-folder'}
+ >['destination'];
+ if (destination.type === 'folder') {
+ requireTreeItem(entries, {type: 'folder', ...destination.folder});
+ const parentPath = [destination.folder.parentName, destination.folder.name]
+ .filter(Boolean)
+ .join('/');
+ if (entry.parentName === parentPath) {
+ return getCodemodResult({project, nextProject: project});
+ }
+
+ target = {
+ type: 'folder',
+ folderName: destination.folder.name,
+ parentName: destination.folder.parentName,
+ };
+ } else if (destination.type === 'root') {
+ if (entry.parentName === null) {
+ return getCodemodResult({project, nextProject: project});
+ }
+
+ target = destination;
+ } else {
+ const targetEntry = requireTreeItem(entries, destination.target);
+ if (entry === targetEntry) {
+ return getCodemodResult({project, nextProject: project});
+ }
+
+ target = {type: destination.type, target: toSourceItem(destination.target)};
+ }
+
+ return editCompositionProject({
+ project,
+ compositionFile,
+ codemod: {
+ type: 'move-composition-or-folder',
+ source: toSourceItem(source),
+ destination: target,
+ },
+ });
+};
+
+export type AddFolderOptions<Project extends CodemodProject> = {
+ project: Project;
+ compositionFile: string;
+ folder: FolderReference;
+};
+
+export const addFolder = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ folder,
+}: AddFolderOptions<Project>) => {
+ if (!folder.name || folder.name.includes('/')) {
+ throw new Error('Folder names must be non-empty and cannot contain /');
+ }
+
+ const entries = getTreeEntries({project, compositionFile});
+ if (
+ entries.some(
+ ({item}) =>
+ item.type === 'folder' &&
+ item.name === folder.name &&
+ item.parentName === folder.parentName,
+ )
+ ) {
+ throw new Error('A folder with this name already exists in the parent');
+ }
+
+ if (folder.parentName !== null) {
+ const parts = folder.parentName.split('/');
+ const name = parts.pop()!;
+ requireTreeItem(entries, {
+ type: 'folder',
+ name,
+ parentName: parts.join('/') || null,
+ });
+ }
+
+ return editCompositionProject({
+ project,
+ compositionFile,
+ codemod: {
+ type: 'new-folder',
+ folderName: folder.name,
+ parentName: folder.parentName,
+ },
+ });
+};
+
+export type RenameFolderOptions<Project extends CodemodProject> =
+ AddFolderOptions<Project> & {newName: string};
+
+export const renameFolder = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ folder,
+ newName,
+}: RenameFolderOptions<Project>) => {
+ const entries = getTreeEntries({project, compositionFile});
+ requireTreeItem(entries, {type: 'folder', ...folder});
+ if (newName === folder.name) {
+ return getCodemodResult({project, nextProject: project});
+ }
+
+ if (!newName || newName.includes('/')) {
+ throw new Error('Folder names must be non-empty and cannot contain /');
+ }
+
+ if (
+ entries.some(
+ ({item}) =>
+ item.type === 'folder' &&
+ item.name === newName &&
+ item.parentName === folder.parentName,
+ )
+ ) {
+ throw new Error('A folder with this name already exists in the parent');
+ }
+
+ return editCompositionProject({
+ project,
+ compositionFile,
+ codemod: {
+ type: 'rename-folder',
+ folderName: folder.name,
+ parentName: folder.parentName,
+ newName,
+ },
+ });
+};
+
+export type UnwrapFolderOptions<Project extends CodemodProject> =
+ AddFolderOptions<Project>;
+
+export const unwrapFolder = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ folder,
+}: UnwrapFolderOptions<Project>) => {
+ requireTreeItem(getTreeEntries({project, compositionFile}), {
+ type: 'folder',
+ ...folder,
+ });
+ return editCompositionProject({
+ project,
+ compositionFile,
+ codemod: {
+ type: 'delete-folder',
+ folderName: folder.name,
+ parentName: folder.parentName,
+ },
+ });
+};
+
+export type MoveCompositionOptions<Project extends CodemodProject> =
+ CompositionTarget & {project: Project; destination: CompositionDestination};
+export const moveComposition = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ compositionId,
+ destination,
+}: MoveCompositionOptions<Project>) =>
+ moveTreeItem({
+ project,
+ compositionFile,
+ source: {type: 'composition', compositionId},
+ destination,
+ });
+
+export type MoveFolderOptions<Project extends CodemodProject> =
+ AddFolderOptions<Project> & {destination: CompositionDestination};
+export const moveFolder = <Project extends CodemodProject>({
+ project,
+ compositionFile,
+ folder,
+ destination,
+}: MoveFolderOptions<Project>) =>
+ moveTreeItem({
+ project,
+ compositionFile,
+ source: {type: 'folder', ...folder},
+ destination,
+ });
diff --git a/packages/codemods/src/folder-source-edits.ts b/packages/codemods/src/folder-source-edits.ts
index e0c43dddb0..de56e21a2d 100644
--- a/packages/codemods/src/folder-source-edits.ts
+++ b/packages/codemods/src/folder-source-edits.ts
@@ -1,4 +1,5 @@
import type {
+ ArrowFunctionExpression,
File,
JSXElement,
JSXFragment,
@@ -128,7 +129,7 @@ const getRegistrationRoot = (
): JSXElement | JSXFragment => {
let currentPath: recast.types.NodePath | null = path;
while (currentPath !== null) {
- const node = currentPath.node as ReturnStatement;
+ const node = currentPath.node as ReturnStatement | ArrowFunctionExpression;
if (
node.type === 'ReturnStatement' &&
(node.argument?.type === 'JSXElement' ||
@@ -137,6 +138,13 @@ const getRegistrationRoot = (
return node.argument;
}
+ if (
+ node.type === 'ArrowFunctionExpression' &&
+ (node.body.type === 'JSXElement' || node.body.type === 'JSXFragment')
+ ) {
+ return node.body;
+ }
+
currentPath = currentPath.parentPath ?? null;
}
diff --git a/packages/codemods/src/get-jsx-nodes.ts b/packages/codemods/src/get-jsx-nodes.ts
new file mode 100644
index 0000000000..144f0a3f13
--- /dev/null
+++ b/packages/codemods/src/get-jsx-nodes.ts
@@ -0,0 +1,48 @@
+import * as recast from 'recast';
+import type {JsxComponentIdentity} from 'remotion';
+import type {CodemodProject} from './codemod-project';
+import {captureJsxNodePaths} from './get-node-path-remappings';
+import {findProjectFile} from './internals';
+import type {JsxNodeReference} from './node-references';
+import {recastLocToOffset} from './recast-loc-to-offset';
+import {getJsxComponentIdentity} from './sequence-props/jsx-component-identity';
+import {parseAst} from './sequence-props/parse-ast';
+
+export type JsxNode = JsxNodeReference & {
+ tagName: string;
+ componentIdentity: JsxComponentIdentity | null;
+ location: {line: number; column: number} | null;
+};
+
+export type GetJsxNodesOptions = {
+ project: CodemodProject;
+ filePath: string;
+};
+
+export const getJsxNodes = ({
+ project,
+ filePath,
+}: GetJsxNodesOptions): JsxNode[] => {
+ const resolvedFilePath = findProjectFile({project, filePath});
+ const input = project.files[resolvedFilePath];
+ const ast = parseAst(input);
+ return captureJsxNodePaths(ast).map(({node, nodePath}) => {
+ const offset = node.loc ? recastLocToOffset(input, node.loc.start) : null;
+ return {
+ filePath: resolvedFilePath,
+ nodePath,
+ tagName: recast.print(node.name).code,
+ componentIdentity: getJsxComponentIdentity({ast, jsxElement: node}),
+ location:
+ node.loc && offset !== null
+ ? {
+ line: node.loc.start.line,
+ column: input
+ .slice(0, offset)
+ .split(/\r\n|[\r\n\u2028\u2029]/)
+ .at(-1)!.length,
+ }
+ : null,
+ };
+ });
+};
diff --git a/packages/codemods/src/index.ts b/packages/codemods/src/index.ts
index ac0123fdc2..fdd3a0d356 100644
--- a/packages/codemods/src/index.ts
+++ b/packages/codemods/src/index.ts
@@ -70,6 +70,96 @@ import {
} from './internals';
export {addSolid, type AddSolidOptions, type AddSolidResult} from './add-solid';
+export {
+ addMedia,
+ addComponent,
+ type AddMediaOptions,
+ type AddComponentOptions,
+ type AddContentOptions,
+ type CodemodValue,
+} from './add-content';
+export {
+ getJsxNodes,
+ type GetJsxNodesOptions,
+ type JsxNode,
+} from './get-jsx-nodes';
+export {
+ getJsxNodeProps,
+ updateJsxNodeProps,
+ type GetJsxNodePropsOptions,
+ type UpdateJsxNodePropsOptions,
+ type JsxNodeProps,
+} from './jsx-props';
+export {
+ duplicateJsxNodes,
+ reorderJsxNode,
+ splitSequences,
+ detachAudio,
+ type DuplicateJsxNodesOptions,
+ type DuplicateJsxNodesResult,
+ type ReorderJsxNodeOptions,
+ type SplitSequencesOptions,
+ type DetachAudioOptions,
+} from './jsx-operations';
+export type {
+ JsxNodeReference,
+ JsxNodePathRemapping,
+ CodemodNodeResult,
+ CodemodInsertionResult,
+} from './node-references';
+export {
+ resolveCompositionComponent,
+ addComposition,
+ renameComposition,
+ duplicateComposition,
+ deleteComposition,
+ updateCompositionMetadata,
+ setCompositionDefaultProps,
+ type CompositionTarget,
+ type CompositionMetadata,
+ type FolderReference,
+ type ResolveCompositionComponentOptions,
+ type AddCompositionOptions,
+ type RenameCompositionOptions,
+ type DuplicateCompositionOptions,
+ type DeleteCompositionOptions,
+ type UpdateCompositionMetadataOptions,
+ type SetCompositionDefaultPropsOptions,
+} from './composition-operations';
+export {
+ addFolder,
+ renameFolder,
+ moveComposition,
+ moveFolder,
+ unwrapFolder,
+ type CompositionTreeItem,
+ type CompositionDestination,
+ type AddFolderOptions,
+ type RenameFolderOptions,
+ type MoveCompositionOptions,
+ type MoveFolderOptions,
+ type UnwrapFolderOptions,
+} from './folder-operations';
+export {
+ addEffect,
+ updateEffectProps,
+ deleteEffects,
+ duplicateEffects,
+ reorderEffect,
+ type EffectReference,
+ type AddEffectOptions,
+ type UpdateEffectPropsOptions,
+ type DeleteEffectsOptions,
+ type DuplicateEffectsOptions,
+ type ReorderEffectOptions,
+} from './public-effect-operations';
+export {
+ updateJsxNodeKeyframes,
+ updateEffectKeyframes,
+ type JsxNodeKeyframeUpdate,
+ type UpdateJsxNodeKeyframesOptions,
+ type UpdateEffectKeyframesOptions,
+} from './keyframe-operations';
export type {
CodemodFileChange,
CodemodProject,
diff --git a/packages/codemods/src/insert-jsx-element.ts b/packages/codemods/src/insert-jsx-element.ts
index e128f60653..40e2c3322e 100644
--- a/packages/codemods/src/insert-jsx-element.ts
+++ b/packages/codemods/src/insert-jsx-element.ts
@@ -7,7 +7,6 @@ import type {
FunctionDeclaration,
ImportDeclaration,
ImportDefaultSpecifier,
- ImportSpecifier,
JSXAttribute,
JSXElement,
JSXOpeningElement,
@@ -137,7 +136,7 @@ export const makeInMemoryInsertJsxElementCodemodEnvironment = ({
}): InsertJsxElementCodemodEnvironment => {
const filesByNormalizedPath = new Map(
Object.entries(project.files).map(([fileName, contents]) => [
- normalizeVirtualPath(fileName),
+ resolveVirtualPath(project.rootDir, fileName),
contents,
]),
);
@@ -1486,88 +1485,38 @@ const getImportDeclarations = ({
);
};
-const importDeclarationHasNamespaceSpecifier = (
- importDeclaration: ImportDeclaration,
-) => {
- return importDeclaration.specifiers?.some(
- (specifier) => specifier.type === 'ImportNamespaceSpecifier',
- );
-};
-
-const hasOfficialLocalImport = ({
- ast,
- importedName,
- sourcePath,
-}: {
- ast: File;
- importedName: string;
- sourcePath: string;
-}) => {
- return getImportDeclarations({ast, sourcePath}).some((importDeclaration) => {
- return importDeclaration.specifiers?.some((specifier) => {
- return (
- specifier.type === 'ImportSpecifier' &&
- getImportedName(specifier) === importedName &&
- (specifier.local?.name ?? importedName) === importedName
- );
- });
- });
-};
-
-const addOfficialNamedImport = ({
- ast,
- importedName,
- sourcePath,
-}: {
- ast: File;
- importedName: string;
- sourcePath: string;
-}) => {
- const existingImport = getImportDeclarations({ast, sourcePath}).find(
- (candidate) => !importDeclarationHasNamespaceSpecifier(candidate),
- );
- const importSpecifier = recast.types.builders.importSpecifier(
- recast.types.builders.identifier(importedName),
- ) as unknown as ImportSpecifier;
-
- if (existingImport) {
- existingImport.specifiers = [
- ...(existingImport.specifiers ?? []),
- importSpecifier,
- ];
- return;
- }
-
- const importDeclaration = recast.types.builders.importDeclaration(
- [importSpecifier as never],
- recast.types.builders.stringLiteral(sourcePath),
- ) as unknown as ImportDeclaration;
- insertImportDeclaration(ast, importDeclaration);
-};
-
const ensureOfficialNamedImport = ({
ast,
importedName,
sourcePath,
- label,
}: {
ast: File;
importedName: string;
sourcePath: string;
- label: string;
}) => {
- if (hasOfficialLocalImport({ast, importedName, sourcePath})) {
- return importedName;
- }
+ for (const declaration of getImportDeclarations({ast, sourcePath})) {
+ if (declaration.importKind === 'type') {
+ continue;
+ }
- if (hasTopLevelBinding({ast, name: importedName})) {
- throw new Error(
- `Cannot add ${label} because ${importedName} is already defined`,
+ const existing = declaration.specifiers.find(
+ (specifier) =>
+ specifier.type === 'ImportSpecifier' &&
+ specifier.importKind !== 'type' &&
+ getImportedName(specifier) === importedName,
);
+ if (existing) {
+ return existing.local.name;
+ }
+ }
+
+ let localName = importedName;
+ let suffix = 2;
+ while (hasTopLevelBinding({ast, name: localName})) {
+ localName = `${importedName}${suffix++}`;
}
- addOfficialNamedImport({ast, importedName, sourcePath});
- return importedName;
+ return ensureNamedImport({ast, importedName, sourcePath, localName});
};
const ensureStaticFileImport = (ast: File) => {
@@ -1575,7 +1524,6 @@ const ensureStaticFileImport = (ast: File) => {
ast,
importedName: 'staticFile',
sourcePath: 'remotion',
- label: 'staticFile()',
});
};
@@ -1584,7 +1532,6 @@ const ensureCanvasImageImport = (ast: File) => {
ast,
importedName: 'CanvasImage',
sourcePath: 'remotion',
- label: '<CanvasImage>',
});
};
@@ -1593,7 +1540,6 @@ const ensureAnimatedImageImport = (ast: File) => {
ast,
importedName: 'AnimatedImage',
sourcePath: 'remotion',
- label: '<AnimatedImage>',
});
};
@@ -1602,7 +1548,6 @@ const ensureVideoImport = (ast: File) => {
ast,
importedName: 'Video',
sourcePath: '@remotion/media',
- label: '<Video>',
});
};
@@ -1611,7 +1556,6 @@ const ensureAudioImport = (ast: File) => {
ast,
importedName: 'Audio',
sourcePath: '@remotion/media',
- label: '<Audio>',
});
};
@@ -1620,7 +1564,6 @@ const ensureGifImport = (ast: File) => {
ast,
importedName: 'Gif',
sourcePath: '@remotion/gif',
- label: '<Gif>',
});
};
diff --git a/packages/codemods/src/internals.ts b/packages/codemods/src/internals.ts
index 8dda3182fa..ddcadc6a06 100644
--- a/packages/codemods/src/internals.ts
+++ b/packages/codemods/src/internals.ts
@@ -263,6 +263,9 @@ export const findProjectFile = ({
const rootDir = normalizePath(project.rootDir);
const candidates = [
normalizedInput,
+ ...(normalizedInput.startsWith(`${rootDir}/`)
+ ? [normalizedInput.slice(rootDir.length + 1)]
+ : []),
normalizePath(normalizedInput.replace(/^\/+/, '')),
normalizePath(`/${normalizedInput}`),
normalizePath(`${rootDir}/${normalizedInput.replace(/^\//, '')}`),
diff --git a/packages/codemods/src/jsx-operations.ts b/packages/codemods/src/jsx-operations.ts
new file mode 100644
index 0000000000..61f9e5a278
--- /dev/null
+++ b/packages/codemods/src/jsx-operations.ts
@@ -0,0 +1,197 @@
+import type {CodemodProject} from './codemod-project';
+import {duplicateJsxNodes as duplicateNodesInSource} from './duplicate-jsx-node';
+import {getJsxNodes} from './get-jsx-nodes';
+import {findProjectFile} from './internals';
+import {getJsxNodeProps} from './jsx-props';
+import {
+ getNodeEditResult,
+ getInsertedNodeReferences,
+ getUpdatedNodeReference,
+ groupNodeReferencesByFile,
+ type CodemodNodeResult,
+ type JsxNodeReference,
+} from './node-references';
+import {reorderSequence} from './reorder-sequence';
+import {splitJsxSequences} from './split-jsx-sequence';
+import {splitVideoFromAudio} from './split-video-from-audio';
+
+export type DuplicateJsxNodesOptions<Project extends CodemodProject> = {
+ project: Project;
+ nodes: JsxNodeReference[];
+};
+
+export type DuplicateJsxNodesResult<Project extends CodemodProject> =
+ CodemodNodeResult<Project> & {
+ insertedNodes: JsxNodeReference[];
+ };
+
+export const duplicateJsxNodes = async <Project extends CodemodProject>({
+ project,
+ nodes,
+}: DuplicateJsxNodesOptions<Project>): Promise<
+ DuplicateJsxNodesResult<Project>
+> => {
+ const groups = groupNodeReferencesByFile({project, nodes});
+ const edits = await Promise.all(
+ [...groups].map(async ([filePath, nodePaths]) => ({
+ filePath,
+ ...(await duplicateNodesInSource({
+ input: project.files[filePath],
+ nodePaths,
+ })),
+ })),
+ );
+ const result = getNodeEditResult({project, edits});
+ return {
+ ...result,
+ insertedNodes: getInsertedNodeReferences(result.nodePathRemappings),
+ };
+};
+
+export type ReorderJsxNodeOptions<Project extends CodemodProject> = {
+ project: Project;
+ node: JsxNodeReference;
+ target: JsxNodeReference;
+ position: 'before' | 'after';
+};
+
+export const reorderJsxNode = async <Project extends CodemodProject>({
+ project,
+ node,
+ target,
+ position,
+}: ReorderJsxNodeOptions<Project>) => {
+ const filePath = findProjectFile({project, filePath: node.filePath});
+ if (filePath !== findProjectFile({project, filePath: target.filePath})) {
+ throw new Error(
+ 'JSX nodes must be siblings in the same file to reorder them',
+ );
+ }
+
+ const edit = await reorderSequence({
+ input: project.files[filePath],
+ sourceNodePath: node.nodePath,
+ targetNodePath: target.nodePath,
+ position,
+ });
+ const result = getNodeEditResult({project, edits: [{filePath, ...edit}]});
+ return {...result, updatedNode: getUpdatedNodeReference({...result, node})};
+};
+
+export type SplitSequencesOptions<Project extends CodemodProject> = {
+ project: Project;
+ splits: {node: JsxNodeReference; frame: number}[];
+};
+
+export const splitSequences = async <Project extends CodemodProject>({
+ project,
+ splits,
+}: SplitSequencesOptions<Project>): Promise<
+ DuplicateJsxNodesResult<Project>
+> => {
+ if (splits.length === 0) {
+ throw new Error('Expected at least one sequence to split');
+ }
+
+ const groups = new Map<string, typeof splits>();
+ for (const split of splits) {
+ const filePath = findProjectFile({project, filePath: split.node.filePath});
+ const target = getJsxNodes({project, filePath}).find(
+ (node) =>
+ JSON.stringify(node.nodePath) === JSON.stringify(split.node.nodePath),
+ );
+ if (
+ !target?.componentIdentity ||
+ !/^dev\.remotion\.(remotion\.(Sequence|Video|OffthreadVideo|Audio|experimental_Video|experimental_Audio|Interactive\.[A-Za-z]+)|media\.(Video|Audio))$/.test(
+ target.componentIdentity,
+ )
+ ) {
+ throw new Error(
+ 'Only Remotion sequences, interactive elements, and timeline media can be split',
+ );
+ }
+
+ const status = getJsxNodeProps({
+ project,
+ node: split.node,
+ keys: ['from', 'durationInFrames', 'trimBefore'],
+ });
+ if (Object.values(status.props).some((prop) => prop.status !== 'static')) {
+ throw new Error('Sequence timing must be static to split it');
+ }
+
+ const group = groups.get(filePath) ?? [];
+ if (
+ group.some(
+ (item) =>
+ JSON.stringify(item.node.nodePath) ===
+ JSON.stringify(split.node.nodePath),
+ )
+ ) {
+ throw new Error('A sequence can only be split once per call');
+ }
+
+ group.push(split);
+ groups.set(filePath, group);
+ }
+
+ const edits = await Promise.all(
+ [...groups].map(async ([filePath, group]) => ({
+ filePath,
+ ...(await splitJsxSequences({
+ input: project.files[filePath],
+ splits: group.map(({node, frame}) => ({
+ nodePath: node.nodePath,
+ splitFrame: frame,
+ sequenceKeys: ['from', 'durationInFrames', 'trimBefore'],
+ })),
+ })),
+ })),
+ );
+ const result = getNodeEditResult({project, edits});
+ return {
+ ...result,
+ insertedNodes: getInsertedNodeReferences(result.nodePathRemappings),
+ };
+};
+
+export type DetachAudioOptions<Project extends CodemodProject> = {
+ project: Project;
+ node: JsxNodeReference;
+};
+
+export const detachAudio = async <Project extends CodemodProject>({
+ project,
+ node,
+}: DetachAudioOptions<Project>) => {
+ const filePath = findProjectFile({project, filePath: node.filePath});
+ const target = getJsxNodes({project, filePath}).find(
+ (entry) => JSON.stringify(entry.nodePath) === JSON.stringify(node.nodePath),
+ );
+ if (
+ !target?.componentIdentity ||
+ !/^dev\.remotion\.(remotion\.(Video|OffthreadVideo|experimental_Video)|media\.Video)$/.test(
+ target.componentIdentity,
+ )
+ ) {
+ throw new Error('Audio can only be detached from a Remotion video element');
+ }
+
+ const edit = await splitVideoFromAudio({
+ input: project.files[filePath],
+ nodePath: node.nodePath,
+ });
+ const result = getNodeEditResult({project, edits: [{filePath, ...edit}]});
+ const nodePath = edit.nodePathRemappings.find(
+ (entry) => entry.oldNodePath === null,
+ )?.newNodePath;
+ if (!nodePath) {
+ throw new Error('Could not locate the detached audio element');
+ }
+
+ return {
+ ...result,
+ insertedNode: {filePath, nodePath},
+ updatedNode: getUpdatedNodeReference({...result, node}),
+ };
+};
diff --git a/packages/codemods/src/jsx-props.ts b/packages/codemods/src/jsx-props.ts
new file mode 100644
index 0000000000..eabf614428
--- /dev/null
+++ b/packages/codemods/src/jsx-props.ts
@@ -0,0 +1,154 @@
+import type {
+ CanUpdateSequencePropsResponseTrue,
+ InteractivitySchema,
+ VideoConfigValues,
+} from 'remotion';
+import type {CodemodValue} from './add-content';
+import type {CodemodProject} from './codemod-project';
+import {
+ captureJsxNodePaths,
+ getNodePathRemappings,
+} from './get-node-path-remappings';
+import {findProjectFile} from './internals';
+import {
+ getNodeEditResult,
+ getUpdatedNodeReference,
+ type JsxNodeReference,
+} from './node-references';
+import {
+ computeSequencePropsStatusFromContent,
+ findJsxElementAtNodePath,
+} from './sequence-props';
+import {findEffectsAttr} from './sequence-props/can-update-effect-props';
+import {parseAst} from './sequence-props/parse-ast';
+import {updateMultipleSequenceProps} from './update-sequence-props';
+
+export type GetJsxNodePropsOptions = {
+ project: CodemodProject;
+ node: JsxNodeReference;
+ keys: string[];
+ effectKeys?: string[][];
+ videoConfig?: VideoConfigValues;
+};
+
+export type JsxNodeProps = Pick<
+ CanUpdateSequencePropsResponseTrue,
+ 'props' | 'effects'
+>;
+
+export const getJsxNodeProps = ({
+ project,
+ node,
+ keys,
+ effectKeys,
+ videoConfig,
+}: GetJsxNodePropsOptions): JsxNodeProps => {
+ const filePath = findProjectFile({project, filePath: node.filePath});
+ let effects = effectKeys;
+ if (effects === undefined) {
+ const ast = parseAst(project.files[filePath]);
+ const jsx = findJsxElementAtNodePath(ast, node.nodePath);
+ const attr = jsx ? findEffectsAttr(jsx.attributes) : null;
+ const array =
+ attr?.value?.type === 'JSXExpressionContainer' &&
+ attr.value.expression.type === 'ArrayExpression'
+ ? attr.value.expression
+ : null;
+ effects = array
+ ? array.elements.map((element) => {
+ const config =
+ element?.type === 'CallExpression' ? element.arguments[0] : null;
+ return config?.type === 'ObjectExpression'
+ ? config.properties.flatMap((property) => {
+ if (property.type !== 'ObjectProperty' || property.computed)
+ return [];
+ return property.key.type === 'Identifier'
+ ? [property.key.name]
+ : property.key.type === 'StringLiteral'
+ ? [property.key.value]
+ : [];
+ })
+ : [];
+ })
+ : [];
+ }
+
+ const result = computeSequencePropsStatusFromContent({
+ fileContents: project.files[filePath],
+ nodePath: node.nodePath,
+ componentIdentity: null,
+ keys,
+ effects,
+ videoConfigValues: videoConfig ?? null,
+ });
+ return {props: result.props, effects: result.effects};
+};
+
+export type UpdateJsxNodePropsOptions<Project extends CodemodProject> = {
+ project: Project;
+ node: JsxNodeReference;
+ props: Record<string, CodemodValue | undefined>;
+ schema?: InteractivitySchema;
+ videoConfig?: VideoConfigValues;
+};
+
+export const updateJsxNodeProps = <Project extends CodemodProject>({
+ project,
+ node,
+ props,
+ schema = {},
+ videoConfig,
+}: UpdateJsxNodePropsOptions<Project>) => {
+ const keys = Object.keys(props);
+ if (keys.length === 0) {
+ throw new Error('Expected at least one prop to update');
+ }
+
+ const status = getJsxNodeProps({project, node, keys, videoConfig});
+ for (const key of keys) {
+ if (
+ !key ||
+ key.split('.').some((part) => !part) ||
+ key.split('.').length > 2
+ ) {
+ throw new Error(
+ 'Prop keys must be names or one-level nested paths such as style.opacity',
+ );
+ }
+
+ if (status.props[key]?.status === 'computed') {
+ throw new Error(`Cannot update computed prop "${key}"`);
+ }
+ }
+
+ const filePath = findProjectFile({project, filePath: node.filePath});
+ const input = project.files[filePath];
+ const ast = parseAst(input);
+ const captured = captureJsxNodePaths(ast);
+ const edit = updateMultipleSequenceProps({
+ input,
+ ast,
+ changes: [
+ {
+ nodePath: node.nodePath,
+ updates: Object.entries(props).map(([key, value]) => ({
+ key,
+ value,
+ defaultValue: null,
+ })),
+ schema,
+ videoConfigValues: videoConfig ?? null,
+ },
+ ],
+ });
+ const {nodePathRemappings} = getNodePathRemappings({
+ ast: edit.ast,
+ captured,
+ output: edit.output,
+ });
+ const result = getNodeEditResult({
+ project,
+ edits: [{filePath, output: edit.output, nodePathRemappings}],
+ });
+ return {...result, updatedNode: getUpdatedNodeReference({...result, node})};
+};
diff --git a/packages/codemods/src/keyframe-operations.ts b/packages/codemods/src/keyframe-operations.ts
new file mode 100644
index 0000000000..cd298fc272
--- /dev/null
+++ b/packages/codemods/src/keyframe-operations.ts
@@ -0,0 +1,109 @@
+import type {InteractivitySchema, VideoConfigValues} from 'remotion';
+import type {CodemodProject} from './codemod-project';
+import {findProjectFile} from './internals';
+import {
+ getNodeEditResult,
+ getUnchangedStructureRemappings,
+ getUpdatedNodeReference,
+ type JsxNodeReference,
+} from './node-references';
+import {
+ getEffectSource,
+ type EffectReference,
+} from './public-effect-operations';
+import {
+ updateEffectKeyframes as updateEffectKeyframesInSource,
+ updateSequenceKeyframes,
+ type SequenceKeyframeUpdate,
+} from './update-keyframes';
+
+export type JsxNodeKeyframeUpdate = SequenceKeyframeUpdate;
+
+export type UpdateJsxNodeKeyframesOptions<Project extends CodemodProject> = {
+ project: Project;
+ node: JsxNodeReference;
+ updates: JsxNodeKeyframeUpdate[];
+ schema?: InteractivitySchema;
+ videoConfig?: VideoConfigValues;
+};
+
+export const updateJsxNodeKeyframes = async <Project extends CodemodProject>({
+ project,
+ node,
+ updates,
+ schema,
+ videoConfig,
+}: UpdateJsxNodeKeyframesOptions<Project>) => {
+ if (updates.length === 0) {
+ throw new Error('Expected at least one keyframe update');
+ }
+
+ const filePath = findProjectFile({project, filePath: node.filePath});
+ const input = project.files[filePath];
+ const {output} = await updateSequenceKeyframes({
+ input,
+ nodePath: node.nodePath,
+ updates,
+ schema,
+ videoConfigValues: videoConfig ?? null,
+ });
+ const result = getNodeEditResult({
+ project,
+ edits: [
+ {
+ filePath,
+ output,
+ nodePathRemappings: getUnchangedStructureRemappings({input, output}),
+ },
+ ],
+ });
+ return {...result, updatedNode: getUpdatedNodeReference({...result, node})};
+};
+
+export type UpdateEffectKeyframesOptions<Project extends CodemodProject> = Omit<
+ UpdateJsxNodeKeyframesOptions<Project>,
+ 'node'
+> & {effect: EffectReference};
+
+export const updateEffectKeyframes = async <Project extends CodemodProject>({
+ project,
+ effect,
+ updates,
+ schema,
+ videoConfig,
+}: UpdateEffectKeyframesOptions<Project>) => {
+ if (updates.length === 0) {
+ throw new Error('Expected at least one keyframe update');
+ }
+
+ if (!Number.isInteger(effect.effectIndex) || effect.effectIndex < 0) {
+ throw new Error('Effect index must be a non-negative integer');
+ }
+
+ const {filePath, input} = getEffectSource({project, node: effect});
+ const {output} = await updateEffectKeyframesInSource({
+ input,
+ sequenceNodePath: effect.nodePath,
+ effectIndex: effect.effectIndex,
+ updates,
+ schema,
+ videoConfigValues: videoConfig ?? null,
+ });
+ const result = getNodeEditResult({
+ project,
+ edits: [
+ {
+ filePath,
+ output,
+ nodePathRemappings: getUnchangedStructureRemappings({input, output}),
+ },
+ ],
+ });
+ return {
+ ...result,
+ updatedEffect: {
+ ...getUpdatedNodeReference({...result, node: effect}),
+ effectIndex: effect.effectIndex,
+ },
+ };
+};
diff --git a/packages/codemods/src/node-references.ts b/packages/codemods/src/node-references.ts
new file mode 100644
index 0000000000..a8b25e4ae8
--- /dev/null
+++ b/packages/codemods/src/node-references.ts
@@ -0,0 +1,158 @@
+import type {SequenceNodePath} from 'remotion';
+import type {CodemodProject, CodemodResult} from './codemod-project';
+import {getCodemodResult} from './codemod-project';
+import {captureJsxNodePaths} from './get-node-path-remappings';
+import {findProjectFile} from './internals';
+import {parseAst} from './sequence-props/parse-ast';
+
+export type JsxNodeReference = {
+ filePath: string;
+ nodePath: SequenceNodePath;
+};
+
+export type JsxNodePathRemapping = {
+ filePath: string;
+ oldNodePath: SequenceNodePath | null;
+ newNodePath: SequenceNodePath | null;
+};
+
+export type CodemodNodeResult<Project extends CodemodProject> =
+ CodemodResult<Project> & {nodePathRemappings: JsxNodePathRemapping[]};
+
+export type CodemodInsertionResult<Project extends CodemodProject> =
+ CodemodNodeResult<Project> & {insertedNode: JsxNodeReference};
+
+export type NodeSourceEdit = {
+ filePath: string;
+ output: string;
+ nodePathRemappings: {
+ oldNodePath: SequenceNodePath | null;
+ newNodePath: SequenceNodePath | null;
+ }[];
+};
+
+export const getInsertedNodeReferences = (
+ remappings: JsxNodePathRemapping[],
+): JsxNodeReference[] => {
+ const inserted = remappings.flatMap(({filePath, oldNodePath, newNodePath}) =>
+ oldNodePath === null && newNodePath !== null
+ ? [{filePath, nodePath: newNodePath}]
+ : [],
+ );
+ return inserted.filter(
+ (node) =>
+ !inserted.some((parent) => {
+ if (parent === node || parent.filePath !== node.filePath) return false;
+ const prefix = parent.nodePath.slice(0, -1);
+ return (
+ prefix.length < node.nodePath.length &&
+ prefix.every((part, index) => node.nodePath[index] === part)
+ );
+ }),
+ );
+};
+
+export const getNodeEditResult = <Project extends CodemodProject>({
+ project,
+ edits,
+}: {
+ project: Project;
+ edits: NodeSourceEdit[];
+}): CodemodNodeResult<Project> => {
+ return {
+ ...getCodemodResult({
+ project,
+ nextProject: {
+ ...project,
+ files: {
+ ...project.files,
+ ...Object.fromEntries(
+ edits.map(({filePath, output}) => [filePath, output]),
+ ),
+ },
+ },
+ }),
+ nodePathRemappings: edits.flatMap(({filePath, nodePathRemappings}) =>
+ nodePathRemappings.map((remapping) => ({filePath, ...remapping})),
+ ),
+ };
+};
+
+// Props, effects, and keyframe edits preserve JSX traversal order. Hooks and
+// statements they insert can still change the paths of every node in a function.
+export const getUnchangedStructureRemappings = ({
+ input,
+ output,
+}: {
+ input: string;
+ output: string;
+}): NodeSourceEdit['nodePathRemappings'] => {
+ const before = captureJsxNodePaths(parseAst(input));
+ const after = captureJsxNodePaths(parseAst(output));
+ if (before.length !== after.length) {
+ throw new Error('The edit unexpectedly changed the JSX structure');
+ }
+
+ return before.flatMap((node, index) => {
+ const next = after[index];
+ if (
+ JSON.stringify(node.nodePath) === JSON.stringify(next.nodePath) &&
+ node.signature === next.signature
+ ) {
+ return [];
+ }
+
+ return [{oldNodePath: node.nodePath, newNodePath: next.nodePath}];
+ });
+};
+
+export const getUpdatedNodeReference = ({
+ project,
+ node,
+ nodePathRemappings,
+}: {
+ project: CodemodProject;
+ node: JsxNodeReference;
+ nodePathRemappings: JsxNodePathRemapping[];
+}): JsxNodeReference => {
+ const filePath = findProjectFile({project, filePath: node.filePath});
+ const remapping = nodePathRemappings.find(
+ (entry) =>
+ entry.filePath === filePath &&
+ JSON.stringify(entry.oldNodePath) === JSON.stringify(node.nodePath),
+ );
+ if (remapping?.newNodePath === null) {
+ throw new Error('The JSX node was removed');
+ }
+
+ return {filePath, nodePath: remapping?.newNodePath ?? node.nodePath};
+};
+
+export const groupNodeReferencesByFile = ({
+ project,
+ nodes,
+}: {
+ project: CodemodProject;
+ nodes: JsxNodeReference[];
+}) => {
+ if (nodes.length === 0) {
+ throw new Error('Expected at least one JSX node');
+ }
+
+ const groups = new Map<string, SequenceNodePath[]>();
+ for (const node of nodes) {
+ const filePath = findProjectFile({project, filePath: node.filePath});
+ const paths = groups.get(filePath) ?? [];
+ if (
+ !paths.some(
+ (path) => JSON.stringify(path) === JSON.stringify(node.nodePath),
+ )
+ ) {
+ paths.push(node.nodePath);
+ }
+
+ groups.set(filePath, paths);
+ }
+
+ return groups;
+};
diff --git a/packages/codemods/src/public-effect-operations.ts b/packages/codemods/src/public-effect-operations.ts
new file mode 100644
index 0000000000..09275ca13d
--- /dev/null
+++ b/packages/codemods/src/public-effect-operations.ts
@@ -0,0 +1,350 @@
+import type {InteractivitySchema} from 'remotion';
+import type {CodemodValue} from './add-content';
+import type {CodemodProject} from './codemod-project';
+import {
+ addEffect as addEffectInSource,
+ deleteEffects as deleteEffectsInSource,
+ duplicateEffects as duplicateEffectsInSource,
+ reorderEffect as reorderEffectInSource,
+ updateEffectProps as updateEffectPropsInSource,
+} from './effect-operations';
+import {findProjectFile} from './internals';
+import {getJsxNodeProps} from './jsx-props';
+import {
+ getNodeEditResult,
+ getUnchangedStructureRemappings,
+ getUpdatedNodeReference,
+ type JsxNodeReference,
+} from './node-references';
+import {findJsxElementAtNodePath} from './sequence-props';
+import {findEffectsAttr} from './sequence-props/can-update-effect-props';
+import {parseAst} from './sequence-props/parse-ast';
+
+export type EffectReference = JsxNodeReference & {effectIndex: number};
+
+export const getEffectSource = ({
+ project,
+ node,
+}: {
+ project: CodemodProject;
+ node: JsxNodeReference;
+}) => {
+ const filePath = findProjectFile({project, filePath: node.filePath});
+ const input = project.files[filePath];
+ const ast = parseAst(input);
+ const jsx = findJsxElementAtNodePath(ast, node.nodePath);
+ if (!jsx) {
+ throw new Error('Could not find the JSX node');
+ }
+
+ const attr = findEffectsAttr(jsx.attributes);
+ const lastSpread = jsx.attributes.findLastIndex(
+ (attribute) => attribute.type === 'JSXSpreadAttribute',
+ );
+ if (
+ lastSpread !== -1 &&
+ (attr === null || jsx.attributes.indexOf(attr) < lastSpread)
+ ) {
+ throw new Error(
+ 'Cannot edit effects that may be overridden by a JSX spread',
+ );
+ }
+
+ const value = attr?.value;
+ if (
+ attr &&
+ (value?.type !== 'JSXExpressionContainer' ||
+ value.expression.type !== 'ArrayExpression')
+ ) {
+ throw new Error('Effects must be an inline array');
+ }
+
+ const length =
+ value?.type === 'JSXExpressionContainer' &&
+ value.expression.type === 'ArrayExpression'
+ ? value.expression.elements.length
+ : 0;
+ return {filePath, input, length};
+};
+
+const groupEffects = ({
+ project,
+ effects,
+}: {
+ project: CodemodProject;
+ effects: EffectReference[];
+}) => {
+ if (effects.length === 0) {
+ throw new Error('Expected at least one effect');
+ }
+
+ const groups = new Map<string, EffectReference[]>();
+ for (const effect of effects) {
+ const {filePath, length} = getEffectSource({project, node: effect});
+ if (
+ !Number.isInteger(effect.effectIndex) ||
+ effect.effectIndex < 0 ||
+ effect.effectIndex >= length
+ ) {
+ throw new Error('Effect index is out of range');
+ }
+
+ const group = groups.get(filePath) ?? [];
+ if (
+ !group.some(
+ (entry) =>
+ entry.effectIndex === effect.effectIndex &&
+ JSON.stringify(entry.nodePath) === JSON.stringify(effect.nodePath),
+ )
+ ) {
+ group.push({...effect, filePath});
+ }
+
+ groups.set(filePath, group);
+ }
+
+ return groups;
+};
+
+export type AddEffectOptions<Project extends CodemodProject> = {
+ project: Project;
+ node: JsxNodeReference;
+ importName: string;
+ importPath: string;
+ props?: Record<string, CodemodValue>;
+};
+
+export const addEffect = async <Project extends CodemodProject>({
+ project,
+ node,
+ importName,
+ importPath,
+ props = {},
+}: AddEffectOptions<Project>) => {
+ const {filePath, input, length} = getEffectSource({project, node});
+ const {output} = await addEffectInSource({
+ input,
+ sequenceNodePath: node.nodePath,
+ effectName: importName,
+ effectImportPath: importPath,
+ effectConfig: props,
+ });
+ const result = getNodeEditResult({
+ project,
+ edits: [
+ {
+ filePath,
+ output,
+ nodePathRemappings: getUnchangedStructureRemappings({input, output}),
+ },
+ ],
+ });
+ return {
+ ...result,
+ insertedEffect: {
+ ...getUpdatedNodeReference({...result, node}),
+ effectIndex: length,
+ },
+ };
+};
+
+export type DeleteEffectsOptions<Project extends CodemodProject> = {
+ project: Project;
+ effects: EffectReference[];
+};
+
+export const deleteEffects = async <Project extends CodemodProject>({
+ project,
+ effects,
+}: DeleteEffectsOptions<Project>) => {
+ const groups = groupEffects({project, effects});
+ const edits = await Promise.all(
+ [...groups].map(async ([filePath, group]) => {
+ const input = project.files[filePath];
+ const {output} = await deleteEffectsInSource({
+ input,
+ effects: group.map((effect) => ({
+ type: 'single-effect',
+ sequenceNodePath: effect.nodePath,
+ effectIndex: effect.effectIndex,
+ })),
+ });
+ return {
+ filePath,
+ output,
+ nodePathRemappings: getUnchangedStructureRemappings({input, output}),
+ };
+ }),
+ );
+ return getNodeEditResult({project, edits});
+};
+
+export type DuplicateEffectsOptions<Project extends CodemodProject> =
+ DeleteEffectsOptions<Project>;
+
+export const duplicateEffects = async <Project extends CodemodProject>({
+ project,
+ effects,
+}: DuplicateEffectsOptions<Project>) => {
+ const groups = groupEffects({project, effects});
+ const edits = await Promise.all(
+ [...groups].map(async ([filePath, group]) => {
+ const input = project.files[filePath];
+ const {output} = await duplicateEffectsInSource({
+ input,
+ effects: group.map((effect) => ({
+ sequenceNodePath: effect.nodePath,
+ effectIndex: effect.effectIndex,
+ })),
+ });
+ return {
+ filePath,
+ output,
+ nodePathRemappings: getUnchangedStructureRemappings({input, output}),
+ };
+ }),
+ );
+ const result = getNodeEditResult({project, edits});
+ return {
+ ...result,
+ insertedEffects: [...groups.values()].flatMap((group) =>
+ group.map((effect) => ({
+ ...getUpdatedNodeReference({...result, node: effect}),
+ effectIndex:
+ effect.effectIndex +
+ 1 +
+ group.filter(
+ (other) =>
+ JSON.stringify(other.nodePath) ===
+ JSON.stringify(effect.nodePath) &&
+ other.effectIndex < effect.effectIndex,
+ ).length,
+ })),
+ ),
+ };
+};
+
+export type ReorderEffectOptions<Project extends CodemodProject> = {
+ project: Project;
+ effect: EffectReference;
+ toIndex: number;
+};
+
+export const reorderEffect = async <Project extends CodemodProject>({
+ project,
+ effect,
+ toIndex,
+}: ReorderEffectOptions<Project>) => {
+ const {filePath, input, length} = getEffectSource({project, node: effect});
+ if (
+ !Number.isInteger(toIndex) ||
+ toIndex < 0 ||
+ toIndex >= length ||
+ !Number.isInteger(effect.effectIndex)
+ ) {
+ throw new Error('Effect index is out of range');
+ }
+
+ const {output} = await reorderEffectInSource({
+ input,
+ sequenceNodePath: effect.nodePath,
+ fromIndex: effect.effectIndex,
+ toIndex,
+ });
+ const result = getNodeEditResult({
+ project,
+ edits: [
+ {
+ filePath,
+ output,
+ nodePathRemappings: getUnchangedStructureRemappings({input, output}),
+ },
+ ],
+ });
+ return {
+ ...result,
+ updatedEffect: {
+ ...getUpdatedNodeReference({...result, node: effect}),
+ effectIndex: toIndex,
+ },
+ };
+};
+
+export type UpdateEffectPropsOptions<Project extends CodemodProject> = {
+ project: Project;
+ effect: EffectReference;
+ props: Record<string, CodemodValue>;
+ schema?: InteractivitySchema;
+};
+
+export const updateEffectProps = async <Project extends CodemodProject>({
+ project,
+ effect,
+ props,
+ schema = {},
+}: UpdateEffectPropsOptions<Project>) => {
+ const {filePath, input, length} = getEffectSource({project, node: effect});
+ if (
+ !Number.isInteger(effect.effectIndex) ||
+ effect.effectIndex < 0 ||
+ effect.effectIndex >= length
+ ) {
+ throw new Error('Effect index is out of range');
+ }
+
+ const keys = Object.keys(props);
+ if (keys.length === 0) {
+ throw new Error('Expected at least one effect prop');
+ }
+
+ const status = getJsxNodeProps({
+ project,
+ node: effect,
+ keys: [],
+ effectKeys: Array.from({length: effect.effectIndex + 1}, (_, index) =>
+ index === effect.effectIndex ? keys : [],
+ ),
+ }).effects[effect.effectIndex];
+ if (!status?.canUpdate) {
+ throw new Error(`Cannot update effect: ${status?.reason ?? 'not-found'}`);
+ }
+
+ let output = input;
+ for (const [key, value] of Object.entries(props)) {
+ if (!/^[A-Za-z_$][\w$]*$/.test(key)) {
+ throw new Error('Effect prop names must be JavaScript identifiers');
+ }
+
+ if (status.props[key]?.status === 'computed') {
+ throw new Error(`Cannot update computed effect prop "${key}"`);
+ }
+
+ output = (
+ await updateEffectPropsInSource({
+ input: output,
+ sequenceNodePath: effect.nodePath,
+ effectIndex: effect.effectIndex,
+ update: {key, value, defaultValue: null},
+ schema,
+ })
+ ).output;
+ }
+
+ const result = getNodeEditResult({
+ project,
+ edits: [
+ {
+ filePath,
+ output,
+ nodePathRemappings: getUnchangedStructureRemappings({input, output}),
+ },
+ ],
+ });
+ return {
+ ...result,
+ updatedEffect: {
+ ...getUpdatedNodeReference({...result, node: effect}),
+ effectIndex: effect.effectIndex,
+ },
+ };
+};
diff --git a/packages/codemods/src/recast-mods.ts b/packages/codemods/src/recast-mods.ts
index 4191c2ae81..bcceb4fc59 100644
--- a/packages/codemods/src/recast-mods.ts
+++ b/packages/codemods/src/recast-mods.ts
@@ -472,9 +472,12 @@ const appendElementToRoot = ({
returnStatement,
}: {
element: JSXElement;
- returnStatement: ReturnStatement;
+ returnStatement: ReturnStatement | ArrowFunctionExpression;
}) => {
- const {argument} = returnStatement;
+ const argument =
+ returnStatement.type === 'ArrowFunctionExpression'
+ ? returnStatement.body
+ : returnStatement.argument;
if (argument?.type !== 'JSXFragment' && argument?.type !== 'JSXElement') {
throw new Error('Could not find a root JSX element');
}
@@ -484,14 +487,19 @@ const appendElementToRoot = ({
stripParenthesizedExtra(element),
);
} else {
- returnStatement.argument = wrapInJsxFragment([
+ const fragment = wrapInJsxFragment([
argument as unknown as JSXElement,
element,
]) as never;
+ if (returnStatement.type === 'ArrowFunctionExpression') {
+ returnStatement.body = fragment;
+ } else {
+ returnStatement.argument = fragment;
+ }
}
};
-const getEnclosingReturnStatement = (path: recast.types.NodePath) => {
+const getEnclosingJsxReturn = (path: recast.types.NodePath) => {
let currentPath: recast.types.NodePath | null = path;
while (currentPath !== null) {
if (
@@ -501,6 +509,14 @@ const getEnclosingReturnStatement = (path: recast.types.NodePath) => {
return currentPath.node as unknown as ReturnStatement;
}
+ const node = currentPath.node as ArrowFunctionExpression;
+ if (
+ node?.type === 'ArrowFunctionExpression' &&
+ (node.body.type === 'JSXElement' || node.body.type === 'JSXFragment')
+ ) {
+ return node;
+ }
+
currentPath = currentPath.parentPath ?? null;
}
@@ -719,7 +735,7 @@ const moveCompositionOrFolder = ({
}
}
- const sourceReturnStatement = getEnclosingReturnStatement(sourceItem.path);
+ const sourceReturnStatement = getEnclosingJsxReturn(sourceItem.path);
deleteJsxElementAtPath(sourceItem.path);
const element = stripParenthesizedExtra(sourceItem.node);
if (transformation.destination.type === 'root') {
@@ -840,7 +856,7 @@ const moveCompositionToFolder = ({
const compositionElement = (sourcePath as recast.types.NodePath)
.node as JSXElement;
- const sourceReturnStatement = getEnclosingReturnStatement(sourcePath);
+ const sourceReturnStatement = getEnclosingJsxReturn(sourcePath);
deleteJsxElementAtPath(sourcePath);
if (transformation.folderName === null) {
appendElementToRoot({
diff --git a/packages/codemods/src/sequence-props/parse-ast.ts b/packages/codemods/src/sequence-props/parse-ast.ts
index 11cb97fca2..04567a6cd2 100644
--- a/packages/codemods/src/sequence-props/parse-ast.ts
+++ b/packages/codemods/src/sequence-props/parse-ast.ts
@@ -1,6 +1,6 @@
import type {File} from '@babel/types';
import * as recast from 'recast';
-import * as tsParser from 'recast/parsers/babel-ts';
+import * as tsParser from 'recast/parsers/babel-ts.js';
const normalizeImportSpacing = (input: string) =>
input.replace(/(import[^\n]*\n)\n+(?=import\b)/g, '$1');
diff --git a/packages/codemods/src/test/public-editing.test.ts b/packages/codemods/src/test/public-editing.test.ts
new file mode 100644
index 0000000000..bab99441de
--- /dev/null
+++ b/packages/codemods/src/test/public-editing.test.ts
@@ -0,0 +1,597 @@
+import {expect, test} from 'bun:test';
+import {
+ addComponent,
+ addComposition,
+ addEffect,
+ addFolder,
+ addMedia,
+ addSolid,
+ deleteComposition,
+ deleteEffects,
+ deleteJsxNodes,
+ detachAudio,
+ duplicateComposition,
+ duplicateEffects,
+ duplicateJsxNodes,
+ getJsxNodeProps,
+ getJsxNodes,
+ moveComposition,
+ moveFolder,
+ renameComposition,
+ renameFolder,
+ reorderEffect,
+ reorderJsxNode,
+ resolveCompositionComponent,
+ setCompositionDefaultProps,
+ splitSequences,
+ unwrapFolder,
+ updateCompositionMetadata,
+ updateEffectKeyframes,
+ updateEffectProps,
+ updateJsxNodeKeyframes,
+ updateJsxNodeProps,
+ type CodemodProject,
+} from '../index';
+
+const compositionFile = 'src/Root.tsx';
+const filePath = 'src/Video.tsx';
+const makeProject = () => ({
+ rootDir: '/',
+ entryPoint: 'src/index.ts',
+ files: {
+ 'src/index.ts':
+ "import {registerRoot} from 'remotion'; import {Root} from './Root'; registerRoot(Root);",
+ [compositionFile]: `import {Composition} from 'remotion';
+import {Video} from './Video';
+export const Root = () => <Composition id="Demo" component={Video} width={1280} height={720} fps={30} durationInFrames={90} />;
+`,
+ [filePath]: `import {AbsoluteFill} from 'remotion';
+// Preserve this unrelated formatting.
+const unrelated = {value:"keep"};
+export const Video = () => <AbsoluteFill><div style={{opacity: 0.5}}>Hello</div></AbsoluteFill>;
+`,
+ 'src/Title.tsx':
+ 'export const Title = ({text}: {text: string}) => <div>{text}</div>;',
+ },
+});
+
+const findNode = (
+ project: CodemodProject,
+ tagName: string,
+ sourceFile = filePath,
+) => {
+ const node = getJsxNodes({project, filePath: sourceFile}).find(
+ (item) => item.tagName === tagName,
+ );
+ if (!node) throw new Error(`No ${tagName} in ${sourceFile}`);
+ return node;
+};
+
+test('discover, inspect, edit, animate, and remove JSX through the public API', async () => {
+ const project = makeProject();
+ expect(
+ resolveCompositionComponent({
+ project,
+ compositionFile,
+ compositionId: 'Demo',
+ }),
+ ).toMatchObject({filePath, exportName: 'Video', canAddContent: true});
+ const node = findNode(project, 'div');
+ expect(node.location?.line).toBe(4);
+ expect(
+ getJsxNodeProps({project, node, keys: ['children']}).props.children,
+ ).toMatchObject({status: 'static', codeValue: 'Hello'});
+ const changed = updateJsxNodeProps({
+ project,
+ node,
+ props: {children: 'Goodbye', 'style.opacity': 0.75, title: 'Example'},
+ });
+ expect(changed.project.entryPoint).toBe(project.entryPoint);
+ expect(project.files[filePath]).toContain('Hello');
+ expect(changed.project.files[filePath]).toContain('Goodbye');
+ expect(changed.project.files[filePath]).toContain(
+ 'const unrelated = {value:"keep"};',
+ );
+ const animated = await updateJsxNodeKeyframes({
+ project: changed.project,
+ node: changed.updatedNode,
+ updates: [
+ {key: 'style.opacity', operation: {type: 'add', frame: 0, value: 0}},
+ {key: 'style.opacity', operation: {type: 'add', frame: 30, value: 1}},
+ ],
+ });
+ expect(animated.project.files[filePath]).toContain('useCurrentFrame');
+ expect(
+ animated.nodePathRemappings.some(
+ (entry) =>
+ JSON.stringify(entry.oldNodePath) === JSON.stringify(node.nodePath),
+ ),
+ ).toBe(true);
+ expect(
+ getJsxNodeProps({
+ project: animated.project,
+ node: animated.updatedNode,
+ keys: ['style.opacity'],
+ }).props['style.opacity'],
+ ).toMatchObject({
+ status: 'keyframed',
+ keyframes: [
+ {frame: 0, value: 0},
+ {frame: 30, value: 1},
+ ],
+ });
+ const withoutTitle = updateJsxNodeProps({
+ project: animated.project,
+ node: animated.updatedNode,
+ props: {title: undefined},
+ });
+ expect(withoutTitle.project.files[filePath]).not.toContain('title=');
+ const deleted = await deleteJsxNodes({
+ project: withoutTitle.project,
+ nodes: [withoutTitle.updatedNode],
+ });
+ expect(
+ getJsxNodes({project: deleted.project, filePath}).map(
+ (entry) => entry.tagName,
+ ),
+ ).toEqual(['AbsoluteFill']);
+ expect(
+ deleted.nodePathRemappings.some((entry) => entry.newNodePath === null),
+ ).toBe(true);
+});
+
+test('insert media and components, reorder copies, and delete nodes across files', async () => {
+ const project = makeProject();
+ const media = await addMedia({
+ project,
+ compositionFile,
+ compositionId: 'Demo',
+ type: 'image',
+ src: 'photo.png',
+ srcType: 'static',
+ from: 10,
+ durationInFrames: 30,
+ dimensions: {width: 100, height: 100},
+ });
+ expect(media.project.files[filePath]).toMatch(
+ /staticFile\(["']photo\.png["']\)/,
+ );
+ expect(
+ getJsxNodeProps({
+ project: media.project,
+ node: media.insertedNode,
+ keys: ['from'],
+ }).props.from,
+ ).toMatchObject({codeValue: 10});
+ const added = await addComponent({
+ project: media.project,
+ compositionFile,
+ compositionId: 'Demo',
+ importName: 'Title',
+ importPath: './Title',
+ props: {text: 'A title'},
+ });
+ expect(added.project.files[filePath]).toContain("from './Title'");
+ const duplicated = await duplicateJsxNodes({
+ project: added.project,
+ nodes: [
+ added.insertedNode,
+ findNode(added.project, 'div', 'src/Title.tsx'),
+ ],
+ });
+ expect(duplicated.insertedNodes).toHaveLength(2);
+ expect(duplicated.changes.map((change) => change.filePath)).toEqual([
+ filePath,
+ 'src/Title.tsx',
+ ]);
+ const copiedTitle = duplicated.insertedNodes.find(
+ (node) => node.filePath === filePath,
+ )!;
+ const reordered = await reorderJsxNode({
+ project: duplicated.project,
+ node: copiedTitle,
+ target: added.insertedNode,
+ position: 'before',
+ });
+ const updatedCopy = updateJsxNodeProps({
+ project: reordered.project,
+ node: reordered.updatedNode,
+ props: {text: 'Copied title'},
+ });
+ expect(
+ updatedCopy.project.files[filePath].indexOf('Copied title'),
+ ).toBeLessThan(updatedCopy.project.files[filePath].indexOf('A title'));
+ const deleted = await deleteJsxNodes({
+ project: updatedCopy.project,
+ nodes: [
+ updatedCopy.updatedNode,
+ duplicated.insertedNodes.find(
+ (node) => node.filePath === 'src/Title.tsx',
+ )!,
+ ],
+ });
+ expect(
+ getJsxNodes({project: deleted.project, filePath}).filter(
+ (node) => node.tagName === 'Title',
+ ),
+ ).toHaveLength(1);
+ expect(deleted.project.files['src/Title.tsx']).toContain('{text}');
+ expect(Object.keys(deleted.project.files)).toEqual(
+ Object.keys(project.files),
+ );
+});
+
+test('split timeline media and detach audio', async () => {
+ const project = makeProject();
+ project.files[filePath] = `import {Video, Audio} from '@remotion/media';
+export const VideoComposition = () => <><Video src="video.mp4" from={10} durationInFrames={80} trimBefore={5}/><Audio src="audio.mp3" from={0} durationInFrames={90}/></>;`;
+ const split = await splitSequences({
+ project,
+ splits: [
+ {node: findNode(project, 'Video'), frame: 40},
+ {node: findNode(project, 'Audio'), frame: 40},
+ ],
+ });
+ expect(split.insertedNodes).toHaveLength(2);
+ const secondVideo = split.insertedNodes[0];
+ expect(
+ getJsxNodeProps({
+ project: split.project,
+ node: secondVideo,
+ keys: ['from', 'durationInFrames', 'trimBefore'],
+ }).props,
+ ).toMatchObject({
+ from: {codeValue: 40},
+ durationInFrames: {codeValue: 50},
+ trimBefore: {codeValue: 35},
+ });
+ const detached = await detachAudio({
+ project: split.project,
+ node: secondVideo,
+ });
+ expect(
+ getJsxNodeProps({
+ project: detached.project,
+ node: detached.updatedNode,
+ keys: ['muted'],
+ }).props.muted,
+ ).toMatchObject({codeValue: true});
+ expect(
+ getJsxNodeProps({
+ project: detached.project,
+ node: detached.insertedNode,
+ keys: ['src', 'trimBefore'],
+ }).props,
+ ).toMatchObject({src: {codeValue: 'video.mp4'}, trimBefore: {codeValue: 35}});
+ expect(project.files[filePath]).not.toContain('muted');
+});
+
+test('manage composition registrations and nested folders without changing components', () => {
+ const original = makeProject();
+ let {project} = addComposition({
+ project: original,
+ compositionFile,
+ compositionId: 'Second',
+ component: {importName: 'Title', importPath: './Title'},
+ metadata: {width: 1920, height: 1080, fps: 30, durationInFrames: 60},
+ });
+ project = setCompositionDefaultProps({
+ project,
+ compositionFile,
+ compositionId: 'Second',
+ defaultProps: {text: 'Title'},
+ }).project;
+ project = duplicateComposition({
+ project,
+ compositionFile,
+ compositionId: 'Second',
+ newId: 'Portrait',
+ metadata: {width: 1080, height: 1920},
+ }).project;
+ project = renameComposition({
+ project,
+ compositionFile,
+ compositionId: 'Portrait',
+ newId: 'Vertical',
+ }).project;
+ project = updateCompositionMetadata({
+ project,
+ compositionFile,
+ compositionId: 'Vertical',
+ metadata: {fps: 60, durationInFrames: 120},
+ }).project;
+ project = addFolder({
+ project,
+ compositionFile,
+ folder: {name: 'Social', parentName: null},
+ }).project;
+ project = addFolder({
+ project,
+ compositionFile,
+ folder: {name: 'Archive', parentName: 'Social'},
+ }).project;
+ project = moveComposition({
+ project,
+ compositionFile,
+ compositionId: 'Vertical',
+ destination: {
+ type: 'folder',
+ folder: {name: 'Archive', parentName: 'Social'},
+ },
+ }).project;
+ project = renameFolder({
+ project,
+ compositionFile,
+ folder: {name: 'Archive', parentName: 'Social'},
+ newName: 'Published',
+ }).project;
+ project = moveFolder({
+ project,
+ compositionFile,
+ folder: {name: 'Published', parentName: 'Social'},
+ destination: {type: 'root'},
+ }).project;
+ project = moveFolder({
+ project,
+ compositionFile,
+ folder: {name: 'Published', parentName: null},
+ destination: {type: 'folder', folder: {name: 'Social', parentName: null}},
+ }).project;
+ project = unwrapFolder({
+ project,
+ compositionFile,
+ folder: {name: 'Social', parentName: null},
+ }).project;
+ expect(project.files[compositionFile]).not.toContain('name="Social"');
+ expect(project.files[compositionFile]).toContain('name="Published"');
+ const composition = getJsxNodes({project, filePath: compositionFile}).find(
+ (node) => {
+ const status = getJsxNodeProps({project, node, keys: ['id']}).props.id;
+ return status.status === 'static' && status.codeValue === 'Vertical';
+ },
+ )!;
+ expect(
+ getJsxNodeProps({
+ project,
+ node: composition,
+ keys: ['width', 'height', 'fps', 'durationInFrames', 'defaultProps'],
+ }).props,
+ ).toMatchObject({
+ width: {codeValue: 1080},
+ height: {codeValue: 1920},
+ fps: {codeValue: 60},
+ durationInFrames: {codeValue: 120},
+ defaultProps: {codeValue: {text: 'Title'}},
+ });
+ project = deleteComposition({
+ project,
+ compositionFile,
+ compositionId: 'Second',
+ }).project;
+ expect(project.files[compositionFile]).not.toContain('id="Second"');
+ expect(project.files[filePath]).toBe(original.files[filePath]);
+ expect(project.files['src/Title.tsx']).toBe(original.files['src/Title.tsx']);
+ expect(original.files[compositionFile]).not.toContain('Vertical');
+});
+
+test('add, duplicate, reorder, edit, animate, and delete effects', async () => {
+ const project = makeProject();
+ const node = findNode(project, 'AbsoluteFill');
+ const first = await addEffect({
+ project,
+ node,
+ importName: 'blur',
+ importPath: '@remotion/effects/blur',
+ props: {radius: 1},
+ });
+ const second = await addEffect({
+ project: first.project,
+ node: first.insertedEffect,
+ importName: 'brightness',
+ importPath: '@remotion/effects/brightness',
+ props: {amount: 1},
+ });
+ const duplicate = await duplicateEffects({
+ project: second.project,
+ effects: [first.insertedEffect, second.insertedEffect],
+ });
+ expect(duplicate.insertedEffects.map((effect) => effect.effectIndex)).toEqual(
+ [1, 3],
+ );
+ const reordered = await reorderEffect({
+ project: duplicate.project,
+ effect: duplicate.insertedEffects[1],
+ toIndex: 0,
+ });
+ const edited = await updateEffectProps({
+ project: reordered.project,
+ effect: reordered.updatedEffect,
+ props: {amount: 2},
+ });
+ const animated = await updateEffectKeyframes({
+ project: edited.project,
+ effect: edited.updatedEffect,
+ updates: [
+ {key: 'amount', operation: {type: 'add', frame: 0, value: 1}},
+ {key: 'amount', operation: {type: 'add', frame: 30, value: 2}},
+ ],
+ });
+ const status = getJsxNodeProps({
+ project: animated.project,
+ node: animated.updatedEffect,
+ keys: [],
+ effectKeys: [['amount'], ['radius'], ['radius'], ['amount']],
+ }).effects;
+ expect(status[0]).toMatchObject({
+ canUpdate: true,
+ callee: 'brightness',
+ props: {amount: {status: 'keyframed'}},
+ });
+ const deleted = await deleteEffects({
+ project: animated.project,
+ effects: [
+ animated.updatedEffect,
+ {...animated.updatedEffect, effectIndex: 3},
+ ],
+ });
+ expect(
+ getJsxNodeProps({
+ project: deleted.project,
+ node: animated.updatedEffect,
+ keys: [],
+ effectKeys: [['radius'], ['radius']],
+ }).effects.map((effect) => (effect.canUpdate ? effect.callee : null)),
+ ).toEqual(['blur', 'blur']);
+ expect(deleted.project.files[filePath]).toContain(
+ 'const unrelated = {value:"keep"};',
+ );
+ expect(project.files[filePath]).not.toContain('effects=');
+});
+
+test('reject unsupported expressions and invalid edits atomically', async () => {
+ const project = makeProject();
+ project.files[filePath] =
+ 'export const Video = ({timing, style}) => <div {...timing} style={style}>Hello</div>;';
+ const original = {...project.files};
+ const node = findNode(project, 'div');
+ expect(
+ getJsxNodeProps({project, node, keys: ['from', 'style.opacity']}).props,
+ ).toEqual({
+ from: {status: 'computed'},
+ 'style.opacity': {status: 'computed'},
+ });
+ expect(() =>
+ updateJsxNodeProps({project, node, props: {'style.opacity': 1}}),
+ ).toThrow('computed');
+ expect(() =>
+ duplicateComposition({
+ project,
+ compositionFile,
+ compositionId: 'Demo',
+ newId: 'Demo',
+ }),
+ ).toThrow('already exists');
+ expect(() =>
+ updateCompositionMetadata({
+ project,
+ compositionFile,
+ compositionId: 'Demo',
+ metadata: {fps: -1},
+ }),
+ ).toThrow('positive');
+ await expect(
+ deleteJsxNodes({
+ project,
+ nodes: [node, {filePath: 'missing.tsx', nodePath: []}],
+ }),
+ ).rejects.toThrow();
+ await expect(
+ reorderJsxNode({
+ project,
+ node,
+ target: findNode(project, 'Composition', compositionFile),
+ position: 'before',
+ }),
+ ).rejects.toThrow('same file');
+ expect(project.files).toEqual(original);
+});
+
+test('existing addSolid returns remappings usable by public discovery', () => {
+ const project = makeProject();
+ const inserted = addSolid({
+ project,
+ compositionFile,
+ compositionId: 'Demo',
+ width: 100,
+ height: 100,
+ from: 15,
+ });
+ expect(
+ inserted.nodePathRemappings.some(
+ (entry) =>
+ entry.oldNodePath === null &&
+ JSON.stringify(entry.newNodePath) ===
+ JSON.stringify(inserted.insertedNode.nodePath),
+ ),
+ ).toBe(true);
+ expect(
+ getJsxNodeProps({
+ project: inserted.project,
+ node: inserted.insertedNode,
+ keys: ['from'],
+ }).props.from,
+ ).toMatchObject({status: 'static', codeValue: 15});
+});
+
+test('nested copies return root references and insertion preserves relative keys under a project root', async () => {
+ const original = {...makeProject(), rootDir: '/project'};
+ const media = await addMedia({
+ project: original,
+ compositionFile,
+ compositionId: 'Demo',
+ type: 'video',
+ src: 'https://example.com/video.mp4',
+ srcType: 'remote',
+ from: 0,
+ durationInFrames: 60,
+ });
+ expect(media.insertedNode.filePath).toBe(filePath);
+ expect(Object.keys(media.project.files)).toEqual(Object.keys(original.files));
+ const copy = await duplicateJsxNodes({
+ project: media.project,
+ nodes: [media.insertedNode],
+ });
+ expect(copy.insertedNodes).toHaveLength(1);
+ expect(
+ copy.nodePathRemappings.filter((entry) => entry.oldNodePath === null),
+ ).toHaveLength(2);
+ const split = await splitSequences({
+ project: copy.project,
+ splits: [{node: copy.insertedNodes[0], frame: 30}],
+ });
+ expect(split.insertedNodes).toHaveLength(1);
+ const deleted = await deleteJsxNodes({
+ project: split.project,
+ nodes: split.insertedNodes,
+ });
+ expect(
+ getJsxNodes({project: deleted.project, filePath}).filter(
+ (node) => node.tagName === 'Sequence',
+ ),
+ ).toHaveLength(2);
+});
+
+test('reject ambiguous registration roots and unsupported splitting or audio detachment', async () => {
+ const project = makeProject();
+ project.files[compositionFile] += '\nconst AnotherComponent = () => <div />;';
+ expect(() =>
+ addComposition({
+ project,
+ compositionFile,
+ compositionId: 'Second',
+ component: {importName: 'Title', importPath: './Title'},
+ metadata: {width: 100, height: 100, fps: 30, durationInFrames: 30},
+ }),
+ ).toThrow('single JSX component');
+ const node = findNode(project, 'div');
+ await expect(
+ splitSequences({project, splits: [{node, frame: 10}]}),
+ ).rejects.toThrow('Only Remotion');
+ await expect(detachAudio({project, node})).rejects.toThrow('Remotion video');
+});
+
+test('node discovery and edits use original source locations with tabs and CRLF', () => {
+ const project = makeProject();
+ project.files[filePath] =
+ '\uFEFFexport const Video = () => (\r\n\t<div style={{opacity: 1}}>Hello</div>\r\n);\r\n';
+ const node = findNode(project, 'div');
+ expect(node.location).toEqual({line: 2, column: 1});
+ const edited = updateJsxNodeProps({
+ project,
+ node,
+ props: {'style.opacity': 0.25},
+ });
+ expect(edited.project.files[filePath]).toContain('opacity: 0.25');
+ expect(edited.project.files[filePath].startsWith('\uFEFF')).toBe(true);
+ expect(edited.project.files[filePath]).toContain('\r\n');
+});
diff --git a/packages/docs/docs/codemods/add-component.mdx b/packages/docs/docs/codemods/add-component.mdx
new file mode 100644
index 0000000000..a35416de31
--- /dev/null
+++ b/packages/docs/docs/codemods/add-component.mdx
@@ -0,0 +1,108 @@
+---
+image: /generated/articles-docs-codemods-add-component.png
+title: 'addComponent()'
+crumb: '@remotion/codemods'
+---
+
+# addComponent()<AvailableFrom v="4.0.528" />
+
+Adds an instance of a named component export to a composition, including its import.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="add-component.ts"
+import {addComponent, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = await addComponent({
+ project,
+ compositionFile: 'src/Root.tsx',
+ compositionId: 'MyComposition',
+ importName: 'Title',
+ importPath: './Title',
+ props: {text: 'Hello'},
+ from: 0,
+ durationInFrames: 60,
+});
+
+console.log(result);
+```
+
+Reuses an existing named import where possible and chooses a free local name on conflicts. The imported module must already exist; this operation does not generate the component implementation.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The file registering the composition. The component may be imported from another project file.
+
+### compositionId
+
+The static ID of the composition to edit.
+
+### importName
+
+The named component export to import. Must begin with an uppercase letter, `_`, or `$`. Default exports are not supported.
+
+### importPath
+
+The module specifier to insert. Relative imports are relative to the composition component file receiving the JSX.
+
+### props?
+
+A record of serializable prop values. Defaults to `{}`. Strings are values, not JavaScript expressions.
+
+### from?
+
+The start frame. When supplied, wraps the inserted content in a [`<Sequence>`](/docs/sequence). Must be a non-negative integer. By default, no start frame is set.
+
+### durationInFrames?
+
+A positive integer duration for the wrapper [`<Sequence>`](/docs/sequence). Supplying only a duration creates a wrapper starting at frame `0`. By default, no duration is set.
+
+### position?
+
+An `{x, y}` position in pixels. By default, content starts at the composition origin.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### insertedNode
+
+The inserted component reference, or its wrapper [`<Sequence>`](/docs/sequence) reference when timing is supplied.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/add-content.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/add-composition.mdx b/packages/docs/docs/codemods/add-composition.mdx
new file mode 100644
index 0000000000..0e249ded75
--- /dev/null
+++ b/packages/docs/docs/codemods/add-composition.mdx
@@ -0,0 +1,109 @@
+---
+image: /generated/articles-docs-codemods-add-composition.png
+title: 'addComposition()'
+crumb: '@remotion/codemods'
+---
+
+# addComposition()<AvailableFrom v="4.0.528" />
+
+Adds a [`<Composition>`](/docs/composition) registration referencing an existing named component export.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="add-composition.ts"
+import {addComposition, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = addComposition({
+ project,
+ compositionFile: 'src/Root.tsx',
+ compositionId: 'MyComposition',
+ component: {importName: 'Video', importPath: './Video'},
+ metadata: {width: 1920, height: 1080, fps: 30, durationInFrames: 90},
+});
+
+console.log(result);
+```
+
+Adds the registration and required imports. The component implementation must already exist. Use a file containing one registration component.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### compositionId
+
+The new composition ID. Must contain only letters, numbers, or hyphens and be unused in this file.
+
+### component
+
+The component to register.
+
+#### importName
+
+The named component export.
+
+#### importPath
+
+Its module specifier, relative to the registration file for relative imports.
+
+### metadata
+
+The initial composition metadata.
+
+#### width
+
+A positive integer width in pixels.
+
+#### height
+
+A positive integer height in pixels.
+
+#### fps
+
+A positive, finite frame rate.
+
+#### durationInFrames
+
+A positive integer duration in frames.
+
+### folder?
+
+An existing folder reference `{name, parentName}`. By default, adds the composition at the registration root.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/composition-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/add-effect.mdx b/packages/docs/docs/codemods/add-effect.mdx
new file mode 100644
index 0000000000..7a7fb461f0
--- /dev/null
+++ b/packages/docs/docs/codemods/add-effect.mdx
@@ -0,0 +1,90 @@
+---
+image: /generated/articles-docs-codemods-add-effect.png
+title: 'addEffect()'
+crumb: '@remotion/codemods'
+---
+
+# addEffect()<AvailableFrom v="4.0.528" />
+
+Appends an effect to a node's inline effects array and adds its import.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="add-effect.ts"
+import {addEffect, type CodemodProject, type JsxNodeReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const node: JsxNodeReference;
+
+const result = await addEffect({
+ project,
+ node,
+ importName: 'blur',
+ importPath: '@remotion/effects/blur',
+ props: {radius: 8},
+});
+
+console.log(result);
+```
+
+Creates the `effects` attribute if missing. The JSX component must support effects at runtime. Computed effects arrays and potentially overriding spreads are rejected; packages are not installed.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### node
+
+A [`JsxNodeReference`](/docs/codemods#node-references) from [`getJsxNodes()`](/docs/codemods/get-jsx-nodes) or a previous operation. It contains `filePath` and `nodePath`.
+
+### importName
+
+The effect's named export, such as `blur`.
+
+### importPath
+
+The effect module. Supports `@remotion/effects/*`, `@remotion/light-leaks`, and `@remotion/starburst`.
+
+### props?
+
+Serializable effect configuration. Defaults to `{}`.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### insertedEffect
+
+The new effect reference, including its zero-based `effectIndex`.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/public-effect-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/add-folder.mdx b/packages/docs/docs/codemods/add-folder.mdx
new file mode 100644
index 0000000000..67b37a54e6
--- /dev/null
+++ b/packages/docs/docs/codemods/add-folder.mdx
@@ -0,0 +1,79 @@
+---
+image: /generated/articles-docs-codemods-add-folder.png
+title: 'addFolder()'
+crumb: '@remotion/codemods'
+---
+
+# addFolder()<AvailableFrom v="4.0.528" />
+
+Adds an empty [`<Folder>`](/docs/folder) to the registration tree.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="add-folder.ts"
+import {addFolder, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = addFolder({
+ project,
+ compositionFile: 'src/Root.tsx',
+ folder: {name: 'Social', parentName: null},
+});
+
+console.log(result);
+```
+
+Adds the `Folder` import when needed. The name must be non-empty, contain no `/`, and be unused in its parent. The parent must exist. Use a file containing one registration component.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### folder
+
+Identifies a folder in `compositionFile`.
+
+#### name
+
+The folder name.
+
+#### parentName
+
+The slash-separated path of the parent folder, such as `Social/Published`. Use `null` for a top-level folder.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/folder-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/add-media.mdx b/packages/docs/docs/codemods/add-media.mdx
new file mode 100644
index 0000000000..c3dd96c38d
--- /dev/null
+++ b/packages/docs/docs/codemods/add-media.mdx
@@ -0,0 +1,112 @@
+---
+image: /generated/articles-docs-codemods-add-media.png
+title: 'addMedia()'
+crumb: '@remotion/codemods'
+---
+
+# addMedia()<AvailableFrom v="4.0.528" />
+
+Adds an image, video, audio, GIF, or animated image to a composition component and adds the required imports.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="add-media.ts"
+import {addMedia, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = await addMedia({
+ project,
+ compositionFile: 'src/Root.tsx',
+ compositionId: 'MyComposition',
+ type: 'video',
+ src: 'clip.mp4',
+ srcType: 'static',
+ from: 30,
+ durationInFrames: 90,
+});
+
+console.log(result);
+```
+
+Media files are not copied or downloaded, metadata is not probed, and packages are not installed. The project must already contain the dependencies needed by the generated imports. Relative paths refer to the public directory for `static` media.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The file registering the composition. The component may be imported from another project file.
+
+### compositionId
+
+The static ID of the composition to edit.
+
+### type
+
+One of `image`, `video`, `audio`, `gif`, or `animated-image`.
+
+### src
+
+The URL or public-directory-relative media path.
+
+### srcType
+
+Use `static` to generate a `staticFile(src)` expression, or `remote` for a URL.
+
+### dimensions?
+
+The media's `{width, height}` in pixels. Both must be positive finite numbers. By default, dimensions are not specified.
+
+### from?
+
+The start frame. When supplied, wraps the inserted content in a [`<Sequence>`](/docs/sequence). Must be a non-negative integer. By default, no start frame is set.
+
+### durationInFrames?
+
+A positive integer duration for the wrapper [`<Sequence>`](/docs/sequence). Supplying only a duration creates a wrapper starting at frame `0`. By default, no duration is set.
+
+### position?
+
+An `{x, y}` position in pixels. By default, content starts at the composition origin.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### insertedNode
+
+The inserted element's reference, or the wrapper [`<Sequence>`](/docs/sequence) reference when timing is supplied.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/add-content.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/add-solid.mdx b/packages/docs/docs/codemods/add-solid.mdx
index 527da91168..09511e5bf1 100644
--- a/packages/docs/docs/codemods/add-solid.mdx
+++ b/packages/docs/docs/codemods/add-solid.mdx
@@ -82,6 +82,10 @@ An array describing each changed file with its `filePath`, `previousContents`, a
The `filePath` and `nodePath` of the inserted JSX element. Pass these values as an item in `nodes` to [`deleteJsxNodes()`](/docs/codemods/delete-jsx-nodes) to remove the element again.
+### nodePathRemappings<AvailableFrom v="4.0.528" />
+
+File-qualified `{filePath, oldNodePath, newNodePath}` mappings for keeping node references after the edit. A `null` old path indicates an insertion; a `null` new path indicates removal. See [node references](/docs/codemods#node-references).
+
## Compatibility
<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
diff --git a/packages/docs/docs/codemods/delete-composition.mdx b/packages/docs/docs/codemods/delete-composition.mdx
new file mode 100644
index 0000000000..8e5459130b
--- /dev/null
+++ b/packages/docs/docs/codemods/delete-composition.mdx
@@ -0,0 +1,71 @@
+---
+image: /generated/articles-docs-codemods-delete-composition.png
+title: 'deleteComposition()'
+crumb: '@remotion/codemods'
+---
+
+# deleteComposition()<AvailableFrom v="4.0.528" />
+
+Removes a composition or still registration.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="delete-composition.ts"
+import {deleteComposition, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = deleteComposition({
+ project,
+ compositionFile: 'src/Root.tsx',
+ compositionId: 'MyComposition',
+});
+
+console.log(result);
+```
+
+Keeps component implementations, imports, and media files. A missing or ambiguous composition ID throws an error.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### compositionId
+
+The static ID of the composition to edit.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/composition-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/delete-effects.mdx b/packages/docs/docs/codemods/delete-effects.mdx
new file mode 100644
index 0000000000..cad475da96
--- /dev/null
+++ b/packages/docs/docs/codemods/delete-effects.mdx
@@ -0,0 +1,71 @@
+---
+image: /generated/articles-docs-codemods-delete-effects.png
+title: 'deleteEffects()'
+crumb: '@remotion/codemods'
+---
+
+# deleteEffects()<AvailableFrom v="4.0.528" />
+
+Deletes selected effects from one or more JSX nodes.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="delete-effects.ts"
+import {deleteEffects, type CodemodProject, type EffectReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const effect: EffectReference;
+
+const result = await deleteEffects({
+ project,
+ effects: [effect],
+});
+
+console.log(result);
+```
+
+Indices of later effects shift after deletion. Read effects again with [`getJsxNodeProps()`](/docs/codemods/get-jsx-node-props) before using old effect indices. Imports are preserved.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### effects
+
+Effect references to remove. References may span files and nodes; indices refer to the input project. Duplicate references are deduplicated.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/public-effect-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/delete-jsx-nodes.mdx b/packages/docs/docs/codemods/delete-jsx-nodes.mdx
index cc782b1553..a4c2eb1725 100644
--- a/packages/docs/docs/codemods/delete-jsx-nodes.mdx
+++ b/packages/docs/docs/codemods/delete-jsx-nodes.mdx
@@ -6,7 +6,7 @@ crumb: '@remotion/codemods'
# deleteJsxNodes()<AvailableFrom v="4.0.527" />
-Deletes one or more JSX elements identified by mounted layer node paths. It works with any JSX layer, including [`<Sequence>`](/docs/sequence) and [`<Solid>`](/docs/solid).
+Deletes one or more JSX elements identified by source node references. It works with any JSX layer, including [`<Sequence>`](/docs/sequence) and [`<Solid>`](/docs/solid).
:::warning
@@ -50,7 +50,7 @@ The source file containing the JSX element. Absolute paths emitted by a mounted
#### nodePath
-The `SequenceNodePath` identifying the JSX element to delete. Canvas layers expose it as `nodePathInfo.sequenceSubscriptionKey.nodePath`.
+The `SequenceNodePath` identifying the JSX element to delete. Obtain it from [`getJsxNodes()`](/docs/codemods/get-jsx-nodes), an insertion result, or a mounted layer. Canvas layers expose it as `nodePathInfo.sequenceSubscriptionKey.nodePath`.
## Return value
@@ -64,6 +64,10 @@ A new project containing the transformed source. Unchanged project fields are pr
An array describing each changed file with its `filePath`, `previousContents`, and `nextContents`.
+### nodePathRemappings<AvailableFrom v="4.0.528" />
+
+File-qualified `{filePath, oldNodePath, newNodePath}` mappings for keeping node references after the edit. A `null` old path indicates an insertion; a `null` new path indicates removal. See [node references](/docs/codemods#node-references).
+
## Compatibility
<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
diff --git a/packages/docs/docs/codemods/detach-audio.mdx b/packages/docs/docs/codemods/detach-audio.mdx
new file mode 100644
index 0000000000..7533ac5492
--- /dev/null
+++ b/packages/docs/docs/codemods/detach-audio.mdx
@@ -0,0 +1,79 @@
+---
+image: /generated/articles-docs-codemods-detach-audio.png
+title: 'detachAudio()'
+crumb: '@remotion/codemods'
+---
+
+# detachAudio()<AvailableFrom v="4.0.528" />
+
+Mutes a video element and inserts a corresponding audio element beside it.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="detach-audio.ts"
+import {detachAudio, type CodemodProject, type JsxNodeReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const node: JsxNodeReference;
+
+const result = await detachAudio({
+ project,
+ node,
+});
+
+console.log(result);
+```
+
+Supports recognized Remotion video imports. The audio element uses the same source and copies supported playback and timing props. This edits JSX; it does not extract or write an audio file.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### node
+
+A [`JsxNodeReference`](/docs/codemods#node-references) from [`getJsxNodes()`](/docs/codemods/get-jsx-nodes) or a previous operation. It contains `filePath` and `nodePath`.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### insertedNode
+
+The new audio element reference.
+
+### updatedNode
+
+The muted video element reference.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/jsx-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/duplicate-composition.mdx b/packages/docs/docs/codemods/duplicate-composition.mdx
new file mode 100644
index 0000000000..c234b9614f
--- /dev/null
+++ b/packages/docs/docs/codemods/duplicate-composition.mdx
@@ -0,0 +1,83 @@
+---
+image: /generated/articles-docs-codemods-duplicate-composition.png
+title: 'duplicateComposition()'
+crumb: '@remotion/codemods'
+---
+
+# duplicateComposition()<AvailableFrom v="4.0.528" />
+
+Copies a composition or still registration with a new ID.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="duplicate-composition.ts"
+import {duplicateComposition, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = duplicateComposition({
+ project,
+ compositionFile: 'src/Root.tsx',
+ compositionId: 'MyComposition',
+ newId: 'Portrait',
+ metadata: {width: 1080, height: 1920},
+});
+
+console.log(result);
+```
+
+Both registrations reference the same component implementation. Default props and other registration props are copied. The original registration kind is preserved: a [`<Still>`](/docs/still) remains a [`<Still>`](/docs/still).
+
+[`<Still>`](/docs/still) registrations only support width and height overrides; supplying FPS or duration throws an error.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### compositionId
+
+The static ID of the composition to edit.
+
+### newId
+
+The new ID, containing only letters, numbers, or hyphens. It must be unused in this file.
+
+### metadata?
+
+Overrides for `width`, `height`, `fps`, and `durationInFrames`. Omitted values are copied from the original.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/composition-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/duplicate-effects.mdx b/packages/docs/docs/codemods/duplicate-effects.mdx
new file mode 100644
index 0000000000..b037e1c4af
--- /dev/null
+++ b/packages/docs/docs/codemods/duplicate-effects.mdx
@@ -0,0 +1,75 @@
+---
+image: /generated/articles-docs-codemods-duplicate-effects.png
+title: 'duplicateEffects()'
+crumb: '@remotion/codemods'
+---
+
+# duplicateEffects()<AvailableFrom v="4.0.528" />
+
+Copies selected effects immediately after their originals.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="duplicate-effects.ts"
+import {duplicateEffects, type CodemodProject, type EffectReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const effect: EffectReference;
+
+const result = await duplicateEffects({
+ project,
+ effects: [effect],
+});
+
+console.log(result);
+```
+
+Copies effect configuration expressions, including animations. Existing effect indices may shift; inspect the updated source before reusing other effect references.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### effects
+
+Effect references to duplicate. References may span files and nodes; indices refer to the input project. Duplicate references are deduplicated.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### insertedEffects
+
+References to the copies, with indices in the updated effects arrays.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/public-effect-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/duplicate-jsx-nodes.mdx b/packages/docs/docs/codemods/duplicate-jsx-nodes.mdx
new file mode 100644
index 0000000000..3eee24ea5a
--- /dev/null
+++ b/packages/docs/docs/codemods/duplicate-jsx-nodes.mdx
@@ -0,0 +1,75 @@
+---
+image: /generated/articles-docs-codemods-duplicate-jsx-nodes.png
+title: 'duplicateJsxNodes()'
+crumb: '@remotion/codemods'
+---
+
+# duplicateJsxNodes()<AvailableFrom v="4.0.528" />
+
+Duplicates one or more JSX elements beside their originals.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="duplicate-jsx-nodes.ts"
+import {duplicateJsxNodes, type CodemodProject, type JsxNodeReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const node: JsxNodeReference;
+
+const result = await duplicateJsxNodes({
+ project,
+ nodes: [node],
+});
+
+console.log(result);
+```
+
+Copies JSX source, including props and children. Imported component implementations remain shared. Overlapping ancestor/descendant selections are unsupported.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### nodes
+
+The node references to duplicate. They may belong to different files. All references are resolved against the input project; duplicate references are deduplicated.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### insertedNodes
+
+References to the roots of the new copies, in source order within each file. Descendant references are included in `nodePathRemappings`.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/jsx-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/get-jsx-node-props.mdx b/packages/docs/docs/codemods/get-jsx-node-props.mdx
new file mode 100644
index 0000000000..06b331079e
--- /dev/null
+++ b/packages/docs/docs/codemods/get-jsx-node-props.mdx
@@ -0,0 +1,80 @@
+---
+image: /generated/articles-docs-codemods-get-jsx-node-props.png
+title: 'getJsxNodeProps()'
+crumb: '@remotion/codemods'
+---
+
+# getJsxNodeProps()<AvailableFrom v="4.0.528" />
+
+Inspects props and inline effects without executing the project.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="get-jsx-node-props.ts"
+import {getJsxNodeProps, type CodemodProject, type JsxNodeReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const node: JsxNodeReference;
+
+const result = getJsxNodeProps({
+ project,
+ node,
+ keys: ['children', 'style.opacity'],
+});
+
+console.log(result);
+```
+
+A spread that may override a prop makes that prop computed. Static source values are not resolved runtime props.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### node
+
+A [`JsxNodeReference`](/docs/codemods#node-references) from [`getJsxNodes()`](/docs/codemods/get-jsx-nodes) or a previous operation. It contains `filePath` and `nodePath`.
+
+### keys
+
+The JSX props to inspect. Use `children` for static text or a one-level path such as `style.opacity`.
+
+### effectKeys?
+
+An array of prop-name arrays indexed by effect position. By default, inline effect calls and their explicit configuration keys are discovered from source.
+
+### videoConfig?
+
+The composition's `width`, `height`, `fps`, and `durationInFrames`. Supply these to interpret supported expressions using [`useVideoConfig()`](/docs/use-video-config). By default, those runtime values are unknown.
+
+## Return value
+
+Returns an object with the following properties.
+
+### props
+
+A record keyed by the requested names. Each value has `status: 'static'` with `codeValue`, `status: 'keyframed'` with keyframes and interpolation settings, or `status: 'computed'` when the value cannot be statically understood. A missing prop is static with `codeValue: undefined`.
+
+### effects
+
+An array of effect descriptions. Editable entries include `canUpdate: true`, `effectIndex`, `callee`, `importPath`, and prop statuses. Unsupported entries include `canUpdate: false` and a `reason`. Automatically discovering effects requires an inline array.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/jsx-props.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/get-jsx-nodes.mdx b/packages/docs/docs/codemods/get-jsx-nodes.mdx
new file mode 100644
index 0000000000..cbb4c2e501
--- /dev/null
+++ b/packages/docs/docs/codemods/get-jsx-nodes.mdx
@@ -0,0 +1,78 @@
+---
+image: /generated/articles-docs-codemods-get-jsx-nodes.png
+title: 'getJsxNodes()'
+crumb: '@remotion/codemods'
+---
+
+# getJsxNodes()<AvailableFrom v="4.0.528" />
+
+Lists the JSX elements in a project file in source order.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="get-jsx-nodes.ts"
+import {getJsxNodes, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = getJsxNodes({
+ project,
+ filePath: 'src/Video.tsx',
+});
+
+console.log(result);
+```
+
+This inspects source without executing it. A node rendered multiple times, for example inside `.map()`, still has one source reference. JSX fragments are not listed.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### filePath
+
+The project-relative or absolute source file path.
+
+## Return value
+
+Returns an array. Each entry has the following properties.
+
+### filePath
+
+The matching key in `project.files`.
+
+### nodePath
+
+An opaque path identifying this JSX element in the current source snapshot.
+
+### tagName
+
+The JSX tag name, such as `Sequence`, `div`, or `Interactive.Div`.
+
+### componentIdentity
+
+The recognized component identity, or `null` when it cannot be determined. Import aliases are resolved where supported.
+
+### location
+
+The opening tag's `{line, column}` location, or `null`. Lines are one-based; columns are zero-based.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/get-jsx-nodes.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/index.mdx b/packages/docs/docs/codemods/index.mdx
index 60e65da74b..ead0d0c8c4 100644
--- a/packages/docs/docs/codemods/index.mdx
+++ b/packages/docs/docs/codemods/index.mdx
@@ -7,7 +7,7 @@ crumb: '@remotion/codemods'
# @remotion/codemods<AvailableFrom v="4.0.527" />
-Apply source-to-source transforms to an in-memory Remotion project.
+Edit Remotion source in memory. Discover JSX nodes, insert content, edit props and animations, and manage composition registrations.
:::warning
@@ -15,7 +15,7 @@ _Draft API_: This API is not yet stable. We are in the experimental phase of thi
:::
-The package accepts a record of file paths and source code and returns a new project together with the files that changed. It does not read from or write to the filesystem, so it can run in browsers and server-side JavaScript runtimes.
+The package accepts file paths and source code and returns a new project together with the files that changed. It does not read or write the filesystem, execute the project, download media, or install packages. You control how changes are previewed, saved, and compiled.
## Installation
@@ -25,7 +25,15 @@ Keep the version aligned with the other Remotion packages in the project.
## Project model
-A codemod project contains a `rootDir` and a `files` record. File paths may be project-relative or absolute, but they must consistently identify imports within the project.
+A `CodemodProject` contains the following properties.
+
+### rootDir
+
+The project's root directory, used to resolve imports and file paths.
+
+### files
+
+A `Record<string, string>` mapping file paths to source code. Paths may be project-relative or absolute, but must consistently identify files within the project. Include the project files needed to resolve imported components.
```ts twoslash title="project.ts"
import type {CodemodProject} from '@remotion/codemods';
@@ -33,11 +41,106 @@ import type {CodemodProject} from '@remotion/codemods';
export const project: CodemodProject = {
rootDir: '/',
files: {
- 'src/Root.tsx': `export const Root = () => null;`,
+ 'src/Root.tsx': `import {Composition} from 'remotion';
+import {Video} from './Video';
+export const Root = () => <Composition id="Demo" component={Video} width={1920} height={1080} fps={30} durationInFrames={90} />;`,
+ 'src/Video.tsx': `export const Video = () => <div style={{opacity: 1}}>Hello</div>;`,
},
};
```
+Mutations preserve additional project fields, such as an `entryPoint`. Treat each returned project as the next source snapshot.
+
+## Editing a node<AvailableFrom v="4.0.528" />
+
+Find a node, inspect the properties you want to edit, and pass its reference to a mutation.
+
+```ts twoslash title="edit.ts"
+import {getJsxNodes, getJsxNodeProps, updateJsxNodeProps, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const node = getJsxNodes({project, filePath: 'src/Video.tsx'}).find((candidate) => candidate.tagName === 'div');
+
+if (node) {
+ const {props} = getJsxNodeProps({project, node, keys: ['style.opacity']});
+ if (props['style.opacity'].status === 'static') {
+ const result = updateJsxNodeProps({
+ project,
+ node,
+ props: {'style.opacity': 0.5},
+ });
+ console.log(result.project, result.changes, result.updatedNode);
+ }
+}
+```
+
+## Node references<AvailableFrom v="4.0.528" />
+
+A `JsxNodeReference` contains the following properties.
+
+### filePath
+
+The file containing the JSX element.
+
+### nodePath
+
+The `SequenceNodePath` identifying the element in the current source snapshot. Obtain it from [`getJsxNodes()`](/docs/codemods/get-jsx-nodes), an insertion result, or a mounted layer's `nodePathInfo.sequenceSubscriptionKey.nodePath`. Treat its contents as opaque.
+
+A reference identifies source, not a particular rendered instance. Editing a component used by several compositions changes that shared component. Editing a node inside a loop changes the source used by every iteration.
+
+### Keeping references after edits
+
+JSX mutations return `nodePathRemappings`. Each entry contains `filePath`, `oldNodePath`, and `newNodePath`. Apply a mapping once to references from the input project, matching both the file and old path. A `null` old path means insertion; a `null` new path means removal. An omitted reference keeps its path.
+
+Use `insertedNode`, `insertedNodes`, or `updatedNode` when returned instead of trying to reconstruct a path. Adding hooks, duplicating elements, or changing wrappers can move other nodes as well. After manual source changes or composition-tree edits, discover nodes again.
+
+## Effect references<AvailableFrom v="4.0.528" />
+
+An `EffectReference` extends a node reference with `effectIndex`, the zero-based position in its inline `effects` array. [`getJsxNodeProps()`](/docs/codemods/get-jsx-node-props) inspects effects, and effect mutations return `insertedEffect`, `insertedEffects`, or `updatedEffect` where applicable.
+
+Adding, deleting, duplicating, or reordering effects can shift effect indices. Node-path remappings do not remap effect indices. Inspect the updated effects before reusing other effect references.
+
+## Mutation results
+
+Every mutation returns a `CodemodResult`, synchronously or through a promise as documented on its page.
+
+### project
+
+A project with the modified source files. The input project remains unchanged.
+
+### changes
+
+An array of `CodemodFileChange` objects.
+
+#### filePath
+
+The changed file's key in `project.files`.
+
+#### previousContents
+
+The previous source, or `null` if the file was created.
+
+#### nextContents
+
+The next source, or `null` if the file was deleted.
+
+### nodePathRemappings<AvailableFrom v="4.0.528" />
+
+JSX, effect, and keyframe mutations return these mappings in addition to the shared result. See [node references](#node-references).
+
+## Supported edits
+
+Code must be valid JavaScript or TypeScript with supported JSX structures. Prop inspection distinguishes static values, recognized keyframes, and computed expressions. The package does not evaluate arbitrary JavaScript. Prop updates reject computed values; setting a recognized keyframed prop replaces it with a static value.
+
+Registration edits use explicit composition files and static IDs. They support the original `Composition`, `Still`, and `Folder` import names. Component insertion and resolution support additional import patterns, as documented on their pages.
+
+`CodemodValue` represents serializable strings, numbers, booleans, `null`, arrays, and objects. Strings are values, not executable expressions. [`updateJsxNodeProps()`](/docs/codemods/update-jsx-node-props) also accepts `undefined` to remove a property.
+
+Unsupported edits throw or reject without mutating the input project. Batch operations resolve their references against the same input snapshot. Unrelated source formatting and comments are preserved; edited regions use the surrounding source style.
+
+## APIs
+
import {TableOfContents} from './table-of-contents';
<TableOfContents />
diff --git a/packages/docs/docs/codemods/move-composition.mdx b/packages/docs/docs/codemods/move-composition.mdx
new file mode 100644
index 0000000000..c411718a02
--- /dev/null
+++ b/packages/docs/docs/codemods/move-composition.mdx
@@ -0,0 +1,76 @@
+---
+image: /generated/articles-docs-codemods-move-composition.png
+title: 'moveComposition()'
+crumb: '@remotion/codemods'
+---
+
+# moveComposition()<AvailableFrom v="4.0.528" />
+
+Moves a composition into a folder, to the root, or beside another registration.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="move-composition.ts"
+import {moveComposition, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = moveComposition({
+ project,
+ compositionFile: 'src/Root.tsx',
+ compositionId: 'MyComposition',
+ destination: {type: 'folder', folder: {name: 'Social', parentName: null}},
+});
+
+console.log(result);
+```
+
+The composition and destination must be in the same registration file. Their source must allow a direct JSX-child move. The component implementation and composition ID stay unchanged.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### compositionId
+
+The static ID of the composition to edit.
+
+### destination
+
+Where to move the item within the same file. Use `{type: 'root'}`, `{type: 'folder', folder: {name, parentName}}`, or `{type: 'before' | 'after', target}`. A target is `{type: 'composition', compositionId}` or `{type: 'folder', name, parentName}`. Moving an item into its current parent is a no-op.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/folder-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/move-folder.mdx b/packages/docs/docs/codemods/move-folder.mdx
new file mode 100644
index 0000000000..d9e7af7468
--- /dev/null
+++ b/packages/docs/docs/codemods/move-folder.mdx
@@ -0,0 +1,84 @@
+---
+image: /generated/articles-docs-codemods-move-folder.png
+title: 'moveFolder()'
+crumb: '@remotion/codemods'
+---
+
+# moveFolder()<AvailableFrom v="4.0.528" />
+
+Moves a folder and its contents within a registration file.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="move-folder.ts"
+import {moveFolder, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = moveFolder({
+ project,
+ compositionFile: 'src/Root.tsx',
+ folder: {name: 'Published', parentName: 'Social'},
+ destination: {type: 'root'},
+});
+
+console.log(result);
+```
+
+Moving a folder into itself or a descendant is rejected. A folder with the same name at the destination is also rejected. Update descendant `parentName` paths after the move.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### folder
+
+Identifies a folder in `compositionFile`.
+
+#### name
+
+The folder name.
+
+#### parentName
+
+The slash-separated path of the parent folder, such as `Social/Published`. Use `null` for a top-level folder.
+
+### destination
+
+Where to move the item within the same file. Use `{type: 'root'}`, `{type: 'folder', folder: {name, parentName}}`, or `{type: 'before' | 'after', target}`. A target is `{type: 'composition', compositionId}` or `{type: 'folder', name, parentName}`. Moving an item into its current parent is a no-op.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/folder-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/rename-composition.mdx b/packages/docs/docs/codemods/rename-composition.mdx
new file mode 100644
index 0000000000..3b9aa0d0fc
--- /dev/null
+++ b/packages/docs/docs/codemods/rename-composition.mdx
@@ -0,0 +1,76 @@
+---
+image: /generated/articles-docs-codemods-rename-composition.png
+title: 'renameComposition()'
+crumb: '@remotion/codemods'
+---
+
+# renameComposition()<AvailableFrom v="4.0.528" />
+
+Changes a composition registration's ID.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="rename-composition.ts"
+import {renameComposition, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = renameComposition({
+ project,
+ compositionFile: 'src/Root.tsx',
+ compositionId: 'MyComposition',
+ newId: 'RenamedComposition',
+});
+
+console.log(result);
+```
+
+Changes the ID in source. It does not rename component exports, files, or references elsewhere. Passing the existing ID returns an unchanged project.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### compositionId
+
+The static ID of the composition to edit.
+
+### newId
+
+The new ID, containing only letters, numbers, or hyphens. It must be unused in this file.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/composition-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/rename-folder.mdx b/packages/docs/docs/codemods/rename-folder.mdx
new file mode 100644
index 0000000000..8af08994ad
--- /dev/null
+++ b/packages/docs/docs/codemods/rename-folder.mdx
@@ -0,0 +1,84 @@
+---
+image: /generated/articles-docs-codemods-rename-folder.png
+title: 'renameFolder()'
+crumb: '@remotion/codemods'
+---
+
+# renameFolder()<AvailableFrom v="4.0.528" />
+
+Renames a folder while keeping its contents.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="rename-folder.ts"
+import {renameFolder, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = renameFolder({
+ project,
+ compositionFile: 'src/Root.tsx',
+ folder: {name: 'Social', parentName: null},
+ newName: 'Published',
+});
+
+console.log(result);
+```
+
+After renaming a folder, update the `parentName` paths used to address its descendants. Renaming to the current name is a no-op.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### folder
+
+Identifies a folder in `compositionFile`.
+
+#### name
+
+The folder name.
+
+#### parentName
+
+The slash-separated path of the parent folder, such as `Social/Published`. Use `null` for a top-level folder.
+
+### newName
+
+The new non-empty name, without `/`. It must be unused in the parent folder.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/folder-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/reorder-effect.mdx b/packages/docs/docs/codemods/reorder-effect.mdx
new file mode 100644
index 0000000000..71c9753646
--- /dev/null
+++ b/packages/docs/docs/codemods/reorder-effect.mdx
@@ -0,0 +1,80 @@
+---
+image: /generated/articles-docs-codemods-reorder-effect.png
+title: 'reorderEffect()'
+crumb: '@remotion/codemods'
+---
+
+# reorderEffect()<AvailableFrom v="4.0.528" />
+
+Moves an effect to another index in the same effects array.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="reorder-effect.ts"
+import {reorderEffect, type CodemodProject, type EffectReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const effect: EffectReference;
+
+const result = await reorderEffect({
+ project,
+ effect,
+ toIndex: 0,
+});
+
+console.log(result);
+```
+
+Effect order changes the order of application. Other effects' indices may shift.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### effect
+
+An [`EffectReference`](/docs/codemods#effect-references): `filePath`, `nodePath`, and a zero-based `effectIndex` in the node's inline `effects` array.
+
+### toIndex
+
+The final zero-based index. It must be an integer within the existing array.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### updatedEffect
+
+The moved effect reference with its new index.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/public-effect-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/reorder-jsx-node.mdx b/packages/docs/docs/codemods/reorder-jsx-node.mdx
new file mode 100644
index 0000000000..025952d016
--- /dev/null
+++ b/packages/docs/docs/codemods/reorder-jsx-node.mdx
@@ -0,0 +1,86 @@
+---
+image: /generated/articles-docs-codemods-reorder-jsx-node.png
+title: 'reorderJsxNode()'
+crumb: '@remotion/codemods'
+---
+
+# reorderJsxNode()<AvailableFrom v="4.0.528" />
+
+Moves a JSX element before or after a sibling.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="reorder-jsx-node.ts"
+import {reorderJsxNode, type CodemodProject, type JsxNodeReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const node: JsxNodeReference;
+declare const target: JsxNodeReference;
+
+const result = await reorderJsxNode({
+ project,
+ node,
+ target,
+ position: 'before',
+});
+
+console.log(result);
+```
+
+Both nodes must be direct JSX siblings in the same file. This changes source order and stacking order, not timeline timing. Moving into a different parent or file is unsupported.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### node
+
+A [`JsxNodeReference`](/docs/codemods#node-references) from [`getJsxNodes()`](/docs/codemods/get-jsx-nodes) or a previous operation. It contains `filePath` and `nodePath`.
+
+### target
+
+The sibling node reference to position relative to.
+
+### position
+
+Either `before` or `after`.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### updatedNode
+
+The moved node's reference in the new project.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/jsx-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/resolve-composition-component.mdx b/packages/docs/docs/codemods/resolve-composition-component.mdx
new file mode 100644
index 0000000000..7267c8d33f
--- /dev/null
+++ b/packages/docs/docs/codemods/resolve-composition-component.mdx
@@ -0,0 +1,79 @@
+---
+image: /generated/articles-docs-codemods-resolve-composition-component.png
+title: 'resolveCompositionComponent()'
+crumb: '@remotion/codemods'
+---
+
+# resolveCompositionComponent()<AvailableFrom v="4.0.528" />
+
+Locates the component used by a composition, following supported project imports and re-exports.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="resolve-composition-component.ts"
+import {resolveCompositionComponent, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = resolveCompositionComponent({
+ project,
+ compositionFile: 'src/Root.tsx',
+ compositionId: 'MyComposition',
+});
+
+console.log(result);
+```
+
+The component must return supported JSX. Dynamic component expressions and unresolved imports throw an error. This function does not load or execute components.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The file registering the composition.
+
+### compositionId
+
+The static ID of the composition to edit.
+
+## Return value
+
+Returns an object with the following properties.
+
+### filePath
+
+The component source file, using its key in `project.files`.
+
+### exportName
+
+The resolved export name, or `default`.
+
+### location
+
+The declaration's `{line, column}` location. Lines are one-based; columns are zero-based.
+
+### canAddContent
+
+Whether the component's returned JSX structure supports content insertion.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/composition-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/set-composition-default-props.mdx b/packages/docs/docs/codemods/set-composition-default-props.mdx
new file mode 100644
index 0000000000..dac2cd3c7a
--- /dev/null
+++ b/packages/docs/docs/codemods/set-composition-default-props.mdx
@@ -0,0 +1,84 @@
+---
+image: /generated/articles-docs-codemods-set-composition-default-props.png
+title: 'setCompositionDefaultProps()'
+crumb: '@remotion/codemods'
+---
+
+# setCompositionDefaultProps()<AvailableFrom v="4.0.528" />
+
+Replaces a composition's statically readable default props or adds them when missing.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="set-composition-default-props.ts"
+import {setCompositionDefaultProps, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = setCompositionDefaultProps({
+ project,
+ compositionFile: 'src/Root.tsx',
+ compositionId: 'MyComposition',
+ defaultProps: {title: 'Hello', backgroundColor: '#ffffff'},
+});
+
+console.log(result);
+```
+
+Computed default props and props potentially overridden by a spread are rejected. The component implementation is unchanged.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### compositionId
+
+The static ID of the composition to edit.
+
+### defaultProps
+
+The complete replacement object of serializable prop values. This replaces the object rather than merging it.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### updatedNode
+
+The composition registration's node reference.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/composition-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/split-sequences.mdx b/packages/docs/docs/codemods/split-sequences.mdx
new file mode 100644
index 0000000000..3c7338bcd2
--- /dev/null
+++ b/packages/docs/docs/codemods/split-sequences.mdx
@@ -0,0 +1,83 @@
+---
+image: /generated/articles-docs-codemods-split-sequences.png
+title: 'splitSequences()'
+crumb: '@remotion/codemods'
+---
+
+# splitSequences()<AvailableFrom v="4.0.528" />
+
+Splits supported timing elements into two adjacent JSX elements.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="split-sequences.ts"
+import {splitSequences, type CodemodProject, type JsxNodeReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const node: JsxNodeReference;
+
+const result = await splitSequences({
+ project,
+ splits: [{node, frame: 45}],
+});
+
+console.log(result);
+```
+
+Adjusts `from`, `durationInFrames`, and `trimBefore`. Timing must be static; dynamic timing and spreads that may override it are rejected. The media file itself is unchanged.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### splits
+
+An array of split requests. A node may appear once per call; requests may span files.
+
+#### node
+
+The node reference of a Remotion sequence, interactive element, or supported timeline media element.
+
+#### frame
+
+The integer frame at which to split, in the same parent timeline coordinate system as the node's `from` prop. It must be strictly inside the sequence.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### insertedNodes
+
+References to the new second halves. Each first half keeps its original identity, with any path change listed in `nodePathRemappings`.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/jsx-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/table-of-contents.tsx b/packages/docs/docs/codemods/table-of-contents.tsx
index c0ecb6320e..11e85ca204 100644
--- a/packages/docs/docs/codemods/table-of-contents.tsx
+++ b/packages/docs/docs/codemods/table-of-contents.tsx
@@ -5,13 +5,165 @@ import {TOCItem} from '../../components/TableOfContents/TOCItem';
export const TableOfContents: React.FC = () => {
return (
<Grid>
+ <TOCItem link="/docs/codemods/add-component">
+ <strong>addComponent()</strong>
+ <div>
+ Adds an instance of a named component export to a composition,
+ including its import.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/add-composition">
+ <strong>addComposition()</strong>
+ <div>
+ Adds a &lt;Composition&gt; registration referencing an existing named
+ component export.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/add-effect">
+ <strong>addEffect()</strong>
+ <div>
+ Appends an effect to a node&apos;s inline effects array and adds its
+ import.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/add-folder">
+ <strong>addFolder()</strong>
+ <div>Adds an empty &lt;Folder&gt; to the registration tree.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/add-media">
+ <strong>addMedia()</strong>
+ <div>
+ Adds an image, video, audio, GIF, or animated image to a composition
+ component and adds the required imports.
+ </div>
+ </TOCItem>
<TOCItem link="/docs/codemods/add-solid">
<strong>addSolid()</strong>
- <div>Add a Solid to a composition source file</div>
+ <div>Add a solid to a composition.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/delete-composition">
+ <strong>deleteComposition()</strong>
+ <div>Removes a composition or still registration.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/delete-effects">
+ <strong>deleteEffects()</strong>
+ <div>Deletes selected effects from one or more JSX nodes.</div>
</TOCItem>
<TOCItem link="/docs/codemods/delete-jsx-nodes">
<strong>deleteJsxNodes()</strong>
- <div>Delete mounted JSX layers from their source files</div>
+ <div>Delete JSX nodes across project files.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/detach-audio">
+ <strong>detachAudio()</strong>
+ <div>
+ Mutes a video element and inserts a corresponding audio element beside
+ it.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/duplicate-composition">
+ <strong>duplicateComposition()</strong>
+ <div>Copies a composition or still registration with a new ID.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/duplicate-effects">
+ <strong>duplicateEffects()</strong>
+ <div>Copies selected effects immediately after their originals.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/duplicate-jsx-nodes">
+ <strong>duplicateJsxNodes()</strong>
+ <div>Duplicates one or more JSX elements beside their originals.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/get-jsx-node-props">
+ <strong>getJsxNodeProps()</strong>
+ <div>
+ Inspects props and inline effects without executing the project.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/get-jsx-nodes">
+ <strong>getJsxNodes()</strong>
+ <div>Lists the JSX elements in a project file in source order.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/move-composition">
+ <strong>moveComposition()</strong>
+ <div>
+ Moves a composition into a folder, to the root, or beside another
+ registration.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/move-folder">
+ <strong>moveFolder()</strong>
+ <div>Moves a folder and its contents within a registration file.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/rename-composition">
+ <strong>renameComposition()</strong>
+ <div>Changes a composition registration&apos;s ID.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/rename-folder">
+ <strong>renameFolder()</strong>
+ <div>Renames a folder while keeping its contents.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/reorder-effect">
+ <strong>reorderEffect()</strong>
+ <div>Moves an effect to another index in the same effects array.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/reorder-jsx-node">
+ <strong>reorderJsxNode()</strong>
+ <div>Moves a JSX element before or after a sibling.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/resolve-composition-component">
+ <strong>resolveCompositionComponent()</strong>
+ <div>
+ Locates the component used by a composition, following supported
+ project imports and re-exports.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/set-composition-default-props">
+ <strong>setCompositionDefaultProps()</strong>
+ <div>
+ Replaces a composition&apos;s statically readable default props or
+ adds them when missing.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/split-sequences">
+ <strong>splitSequences()</strong>
+ <div>
+ Splits supported timing elements into two adjacent JSX elements.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/unwrap-folder">
+ <strong>unwrapFolder()</strong>
+ <div>
+ Removes a &lt;Folder&gt; wrapper while keeping its contents in the
+ same position.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/update-composition-metadata">
+ <strong>updateCompositionMetadata()</strong>
+ <div>
+ Updates width, height, FPS, or duration on a composition registration.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/update-effect-keyframes">
+ <strong>updateEffectKeyframes()</strong>
+ <div>
+ Adds, removes, moves, or configures keyframes on an effect property.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/update-effect-props">
+ <strong>updateEffectProps()</strong>
+ <div>
+ Updates explicit properties in an inline effect configuration.
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/update-jsx-node-keyframes">
+ <strong>updateJsxNodeKeyframes()</strong>
+ <div>Adds, removes, moves, or configures keyframes on a JSX prop.</div>
+ </TOCItem>
+ <TOCItem link="/docs/codemods/update-jsx-node-props">
+ <strong>updateJsxNodeProps()</strong>
+ <div>
+ Updates JSX props, nested object properties, and supported text
+ children.
+ </div>
</TOCItem>
</Grid>
);
diff --git a/packages/docs/docs/codemods/unwrap-folder.mdx b/packages/docs/docs/codemods/unwrap-folder.mdx
new file mode 100644
index 0000000000..07b5f88cc3
--- /dev/null
+++ b/packages/docs/docs/codemods/unwrap-folder.mdx
@@ -0,0 +1,95 @@
+---
+image: /generated/articles-docs-codemods-unwrap-folder.png
+title: 'unwrapFolder()'
+crumb: '@remotion/codemods'
+---
+
+# unwrapFolder()<AvailableFrom v="4.0.528" />
+
+Removes a [`<Folder>`](/docs/folder) wrapper while keeping its contents in the same position.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="unwrap-folder.ts"
+import {unwrapFolder, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = unwrapFolder({
+ project,
+ compositionFile: 'src/Root.tsx',
+ folder: {name: 'Social', parentName: null},
+});
+
+console.log(result);
+```
+
+Compositions and child folders move up one level. Their order, props, component implementations, and media files are preserved. Nested child folders remain wrapped.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### folder
+
+Identifies a folder in `compositionFile`.
+
+#### name
+
+The folder name.
+
+#### parentName
+
+The slash-separated path of the parent folder, such as `Social/Published`. Use `null` for a top-level folder.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+## Example transformation
+
+```tsx title="Before"
+<Folder name="Social">
+ <Composition id="Portrait" component={Portrait} />
+ <Folder name="Archive" />
+</Folder>
+```
+
+```tsx title="After"
+<Composition id="Portrait" component={Portrait} />
+<Folder name="Archive" />
+```
+
+These fragments show the children of a registration root; a fragment is inserted when needed to keep the surrounding JSX valid.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/folder-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/update-composition-metadata.mdx b/packages/docs/docs/codemods/update-composition-metadata.mdx
new file mode 100644
index 0000000000..3c4353984b
--- /dev/null
+++ b/packages/docs/docs/codemods/update-composition-metadata.mdx
@@ -0,0 +1,94 @@
+---
+image: /generated/articles-docs-codemods-update-composition-metadata.png
+title: 'updateCompositionMetadata()'
+crumb: '@remotion/codemods'
+---
+
+# updateCompositionMetadata()<AvailableFrom v="4.0.528" />
+
+Updates width, height, FPS, or duration on a composition registration.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="update-composition-metadata.ts"
+import {updateCompositionMetadata, type CodemodProject} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+
+const result = updateCompositionMetadata({
+ project,
+ compositionFile: 'src/Root.tsx',
+ compositionId: 'MyComposition',
+ metadata: {width: 1080, height: 1920},
+});
+
+console.log(result);
+```
+
+Edits the registration props directly, replacing existing expressions for the specified fields. It does not execute or change [`calculateMetadata()`](/docs/calculate-metadata), which may override those values at runtime.
+
+[`<Still>`](/docs/still) registrations only support width and height overrides; supplying FPS or duration throws an error.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### compositionFile
+
+The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with their original import names and static IDs or folder names.
+
+### compositionId
+
+The static ID of the composition to edit.
+
+### metadata
+
+A partial object containing the metadata fields to replace. Omitted fields are unchanged.
+
+#### width?
+
+A positive integer width in pixels. Omitted values are unchanged.
+
+#### height?
+
+A positive integer height in pixels. Omitted values are unchanged.
+
+#### fps?
+
+A positive, finite frame rate. Omitted values are unchanged.
+
+#### durationInFrames?
+
+A positive integer duration in frames. Omitted values are unchanged.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/composition-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/update-effect-keyframes.mdx b/packages/docs/docs/codemods/update-effect-keyframes.mdx
new file mode 100644
index 0000000000..be743396b3
--- /dev/null
+++ b/packages/docs/docs/codemods/update-effect-keyframes.mdx
@@ -0,0 +1,95 @@
+---
+image: /generated/articles-docs-codemods-update-effect-keyframes.png
+title: 'updateEffectKeyframes()'
+crumb: '@remotion/codemods'
+---
+
+# updateEffectKeyframes()<AvailableFrom v="4.0.528" />
+
+Adds, removes, moves, or configures keyframes on an effect property.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="update-effect-keyframes.ts"
+import {updateEffectKeyframes, type CodemodProject, type EffectReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const effect: EffectReference;
+
+const result = await updateEffectKeyframes({
+ project,
+ effect,
+ updates: [
+ {key: 'radius', operation: {type: 'add', frame: 0, value: 0}},
+ {key: 'radius', operation: {type: 'add', frame: 30, value: 12}},
+ ],
+});
+
+console.log(result);
+```
+
+The effect must be a call in an inline effects array with a supported configuration. Required interpolation imports and frame hooks are added. Frame coordinates belong to the interpolation expression's local frame clock.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### effect
+
+An [`EffectReference`](/docs/codemods#effect-references): `filePath`, `nodePath`, and a zero-based `effectIndex` in the node's inline `effects` array.
+
+### updates
+
+An array of `{key, operation}` objects, applied in order. JSX prop keys may use paths such as `style.opacity`. Effect keys name configuration properties.
+
+#### operation
+
+Use `{type: 'add', frame, value}` to add or replace a keyframe; `{type: 'remove', frame, valueWhenLastKeyframeDeleted}` to remove one; `{type: 'move', moves: [{fromFrame, toFrame}]}` to move keyframes; `{type: 'easing', segmentIndex, easing}` to change easing; or `{type: 'settings', clamping, posterize, output}` to change interpolation settings. For settings, pass `undefined` for unchanged fields. `valueWhenLastKeyframeDeleted` supplies the static fallback when removing the final keyframe, or `null` to use the supported default.
+
+### schema?
+
+A Remotion `InteractivitySchema` for schema-specific defaults and enum variants. By default, no schema-specific behavior is applied.
+
+### videoConfig?
+
+The composition's `width`, `height`, `fps`, and `durationInFrames`. Supply these to interpret supported expressions using [`useVideoConfig()`](/docs/use-video-config). By default, those runtime values are unknown.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### updatedEffect
+
+The effect reference in the updated project. The node path may change when a frame hook is inserted.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/keyframe-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/update-effect-props.mdx b/packages/docs/docs/codemods/update-effect-props.mdx
new file mode 100644
index 0000000000..484d1e30e2
--- /dev/null
+++ b/packages/docs/docs/codemods/update-effect-props.mdx
@@ -0,0 +1,84 @@
+---
+image: /generated/articles-docs-codemods-update-effect-props.png
+title: 'updateEffectProps()'
+crumb: '@remotion/codemods'
+---
+
+# updateEffectProps()<AvailableFrom v="4.0.528" />
+
+Updates explicit properties in an inline effect configuration.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="update-effect-props.ts"
+import {updateEffectProps, type CodemodProject, type EffectReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const effect: EffectReference;
+
+const result = await updateEffectProps({
+ project,
+ effect,
+ props: {radius: 12},
+});
+
+console.log(result);
+```
+
+Other effect properties are preserved. Use [`updateEffectKeyframes()`](/docs/codemods/update-effect-keyframes) to edit an animation. The effects array and configuration must be inline.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### effect
+
+An [`EffectReference`](/docs/codemods#effect-references): `filePath`, `nodePath`, and a zero-based `effectIndex` in the node's inline `effects` array.
+
+### props
+
+A non-empty record of serializable values. Keys must be JavaScript identifiers. Computed values are rejected; recognized keyframed values are replaced with static values.
+
+### schema?
+
+A Remotion `InteractivitySchema` for schema-specific defaults and enum variants. By default, no schema-specific behavior is applied.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### updatedEffect
+
+The effect reference in the updated project.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/public-effect-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/update-jsx-node-keyframes.mdx b/packages/docs/docs/codemods/update-jsx-node-keyframes.mdx
new file mode 100644
index 0000000000..f5d2786132
--- /dev/null
+++ b/packages/docs/docs/codemods/update-jsx-node-keyframes.mdx
@@ -0,0 +1,95 @@
+---
+image: /generated/articles-docs-codemods-update-jsx-node-keyframes.png
+title: 'updateJsxNodeKeyframes()'
+crumb: '@remotion/codemods'
+---
+
+# updateJsxNodeKeyframes()<AvailableFrom v="4.0.528" />
+
+Adds, removes, moves, or configures keyframes on a JSX prop.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="update-jsx-node-keyframes.ts"
+import {updateJsxNodeKeyframes, type CodemodProject, type JsxNodeReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const node: JsxNodeReference;
+
+const result = await updateJsxNodeKeyframes({
+ project,
+ node,
+ updates: [
+ {key: 'style.opacity', operation: {type: 'add', frame: 0, value: 0}},
+ {key: 'style.opacity', operation: {type: 'add', frame: 30, value: 1}},
+ ],
+});
+
+console.log(result);
+```
+
+Adds the required interpolation imports and frame hook. Supports recognized inline interpolation expressions; unsupported dynamic expressions throw. Frame coordinates belong to the interpolation expression's local frame clock.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### node
+
+A [`JsxNodeReference`](/docs/codemods#node-references) from [`getJsxNodes()`](/docs/codemods/get-jsx-nodes) or a previous operation. It contains `filePath` and `nodePath`.
+
+### updates
+
+An array of `{key, operation}` objects, applied in order. JSX prop keys may use paths such as `style.opacity`. Effect keys name configuration properties.
+
+#### operation
+
+Use `{type: 'add', frame, value}` to add or replace a keyframe; `{type: 'remove', frame, valueWhenLastKeyframeDeleted}` to remove one; `{type: 'move', moves: [{fromFrame, toFrame}]}` to move keyframes; `{type: 'easing', segmentIndex, easing}` to change easing; or `{type: 'settings', clamping, posterize, output}` to change interpolation settings. For settings, pass `undefined` for unchanged fields. `valueWhenLastKeyframeDeleted` supplies the static fallback when removing the final keyframe, or `null` to use the supported default.
+
+### schema?
+
+A Remotion `InteractivitySchema` for schema-specific defaults and enum variants. By default, no schema-specific behavior is applied.
+
+### videoConfig?
+
+The composition's `width`, `height`, `fps`, and `durationInFrames`. Supply these to interpret supported expressions using [`useVideoConfig()`](/docs/use-video-config). By default, those runtime values are unknown.
+
+## Return value
+
+A promise resolving to an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### updatedNode
+
+The edited JSX node reference. Adding a frame hook can change node paths throughout the component.
+
+## Errors
+
+Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/keyframe-operations.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/docs/codemods/update-jsx-node-props.mdx b/packages/docs/docs/codemods/update-jsx-node-props.mdx
new file mode 100644
index 0000000000..b61a4d5ac1
--- /dev/null
+++ b/packages/docs/docs/codemods/update-jsx-node-props.mdx
@@ -0,0 +1,88 @@
+---
+image: /generated/articles-docs-codemods-update-jsx-node-props.png
+title: 'updateJsxNodeProps()'
+crumb: '@remotion/codemods'
+---
+
+# updateJsxNodeProps()<AvailableFrom v="4.0.528" />
+
+Updates JSX props, nested object properties, and supported text children.
+
+:::warning
+
+_Draft API_: This API is experimental and may change.
+
+:::
+
+```ts twoslash title="update-jsx-node-props.ts"
+import {updateJsxNodeProps, type CodemodProject, type JsxNodeReference} from '@remotion/codemods';
+
+declare const project: CodemodProject;
+declare const node: JsxNodeReference;
+
+const result = updateJsxNodeProps({
+ project,
+ node,
+ props: {'style.opacity': 0.5, title: 'Preview'},
+});
+
+console.log(result);
+```
+
+Throws for computed props, including props potentially overridden by a spread. Setting a keyframed prop replaces the animation with the supplied static value; use [`updateJsxNodeKeyframes()`](/docs/codemods/update-jsx-node-keyframes) to edit its animation. Unchanged surrounding source is preserved.
+
+## Options
+
+### project
+
+An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project is not mutated.
+
+### node
+
+A [`JsxNodeReference`](/docs/codemods#node-references) from [`getJsxNodes()`](/docs/codemods/get-jsx-nodes) or a previous operation. It contains `filePath` and `nodePath`.
+
+### props
+
+A record of new values, such as `{from: 30, 'style.opacity': 0.5}`. A value of `undefined` removes the prop or nested property. Only one level of nested keys is supported. Use `children` to replace static text.
+
+### schema?
+
+A Remotion `InteractivitySchema` for schema-specific defaults and enum variants. By default, no schema-specific behavior is applied.
+
+### videoConfig?
+
+The composition's `width`, `height`, `fps`, and `durationInFrames`. Supply these to interpret supported expressions using [`useVideoConfig()`](/docs/use-video-config). By default, those runtime values are unknown.
+
+## Return value
+
+Returns an object with the following properties.
+
+### project
+
+The updated project. Unchanged files and extra project fields are preserved.
+
+### changes
+
+An array of `{filePath, previousContents, nextContents}` file changes. A `null` content value indicates a created or deleted file.
+
+### nodePathRemappings
+
+An array of `{filePath, oldNodePath, newNodePath}` mappings. A `null` old path indicates an insertion; a `null` new path indicates removal. Apply these mappings to references from the input project. See [node references](/docs/codemods#node-references).
+
+### updatedNode
+
+The edited node's reference in the new project.
+
+## Errors
+
+Throws when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />
+
+## See also
+
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/codemods/src/jsx-props.ts)
+- [`@remotion/codemods`](/docs/codemods)
+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 72e20713c3..28add34204 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -1586,8 +1586,8 @@ const sidebars: SidebarsConfig = {
'miscellaneous/pexels',
'lovable-for-motion-graphics',
],
- },
- {
+ },
+ {
type: 'category',
label: 'Terminology',
link: {
@@ -2040,7 +2040,38 @@ const sidebars: SidebarsConfig = {
type: 'doc',
id: 'codemods/index',
},
- items: ['codemods/add-solid', 'codemods/delete-jsx-nodes'],
+ items: [
+ 'codemods/add-component',
+ 'codemods/add-composition',
+ 'codemods/add-effect',
+ 'codemods/add-folder',
+ 'codemods/add-media',
+ 'codemods/add-solid',
+ 'codemods/delete-composition',
+ 'codemods/delete-effects',
+ 'codemods/delete-jsx-nodes',
+ 'codemods/detach-audio',
+ 'codemods/duplicate-composition',
+ 'codemods/duplicate-effects',
+ 'codemods/duplicate-jsx-nodes',
+ 'codemods/get-jsx-node-props',
+ 'codemods/get-jsx-nodes',
+ 'codemods/move-composition',
+ 'codemods/move-folder',
+ 'codemods/rename-composition',
+ 'codemods/rename-folder',
+ 'codemods/reorder-effect',
+ 'codemods/reorder-jsx-node',
+ 'codemods/resolve-composition-component',
+ 'codemods/set-composition-default-props',
+ 'codemods/split-sequences',
+ 'codemods/unwrap-folder',
+ 'codemods/update-composition-metadata',
+ 'codemods/update-effect-keyframes',
+ 'codemods/update-effect-props',
+ 'codemods/update-jsx-node-keyframes',
+ 'codemods/update-jsx-node-props',
+ ],
},
],
};
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 9745f09866..09969683dd 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -1404,6 +1404,51 @@ export const articles = [
noAi: false,
slug: 'cloudrun/upgrading',
},
+ {
+ id: 'codemods/add-component',
+ title: 'addComponent()',
+ relativePath: 'docs/codemods/add-component.mdx',
+ compId: 'articles-docs-codemods-add-component',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/add-component',
+ },
+ {
+ id: 'codemods/add-composition',
+ title: 'addComposition()',
+ relativePath: 'docs/codemods/add-composition.mdx',
+ compId: 'articles-docs-codemods-add-composition',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/add-composition',
+ },
+ {
+ id: 'codemods/add-effect',
+ title: 'addEffect()',
+ relativePath: 'docs/codemods/add-effect.mdx',
+ compId: 'articles-docs-codemods-add-effect',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/add-effect',
+ },
+ {
+ id: 'codemods/add-folder',
+ title: 'addFolder()',
+ relativePath: 'docs/codemods/add-folder.mdx',
+ compId: 'articles-docs-codemods-add-folder',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/add-folder',
+ },
+ {
+ id: 'codemods/add-media',
+ title: 'addMedia()',
+ relativePath: 'docs/codemods/add-media.mdx',
+ compId: 'articles-docs-codemods-add-media',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/add-media',
+ },
{
id: 'codemods/add-solid',
title: 'addSolid()',
@@ -1413,6 +1458,24 @@ export const articles = [
noAi: false,
slug: 'codemods/add-solid',
},
+ {
+ id: 'codemods/delete-composition',
+ title: 'deleteComposition()',
+ relativePath: 'docs/codemods/delete-composition.mdx',
+ compId: 'articles-docs-codemods-delete-composition',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/delete-composition',
+ },
+ {
+ id: 'codemods/delete-effects',
+ title: 'deleteEffects()',
+ relativePath: 'docs/codemods/delete-effects.mdx',
+ compId: 'articles-docs-codemods-delete-effects',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/delete-effects',
+ },
{
id: 'codemods/delete-jsx-nodes',
title: 'deleteJsxNodes()',
@@ -1422,6 +1485,60 @@ export const articles = [
noAi: false,
slug: 'codemods/delete-jsx-nodes',
},
+ {
+ id: 'codemods/detach-audio',
+ title: 'detachAudio()',
+ relativePath: 'docs/codemods/detach-audio.mdx',
+ compId: 'articles-docs-codemods-detach-audio',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/detach-audio',
+ },
+ {
+ id: 'codemods/duplicate-composition',
+ title: 'duplicateComposition()',
+ relativePath: 'docs/codemods/duplicate-composition.mdx',
+ compId: 'articles-docs-codemods-duplicate-composition',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/duplicate-composition',
+ },
+ {
+ id: 'codemods/duplicate-effects',
+ title: 'duplicateEffects()',
+ relativePath: 'docs/codemods/duplicate-effects.mdx',
+ compId: 'articles-docs-codemods-duplicate-effects',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/duplicate-effects',
+ },
+ {
+ id: 'codemods/duplicate-jsx-nodes',
+ title: 'duplicateJsxNodes()',
+ relativePath: 'docs/codemods/duplicate-jsx-nodes.mdx',
+ compId: 'articles-docs-codemods-duplicate-jsx-nodes',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/duplicate-jsx-nodes',
+ },
+ {
+ id: 'codemods/get-jsx-node-props',
+ title: 'getJsxNodeProps()',
+ relativePath: 'docs/codemods/get-jsx-node-props.mdx',
+ compId: 'articles-docs-codemods-get-jsx-node-props',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/get-jsx-node-props',
+ },
+ {
+ id: 'codemods/get-jsx-nodes',
+ title: 'getJsxNodes()',
+ relativePath: 'docs/codemods/get-jsx-nodes.mdx',
+ compId: 'articles-docs-codemods-get-jsx-nodes',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/get-jsx-nodes',
+ },
{
id: 'codemods/index',
title: '@remotion/codemods',
@@ -1431,6 +1548,141 @@ export const articles = [
noAi: false,
slug: 'codemods/index',
},
+ {
+ id: 'codemods/move-composition',
+ title: 'moveComposition()',
+ relativePath: 'docs/codemods/move-composition.mdx',
+ compId: 'articles-docs-codemods-move-composition',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/move-composition',
+ },
+ {
+ id: 'codemods/move-folder',
+ title: 'moveFolder()',
+ relativePath: 'docs/codemods/move-folder.mdx',
+ compId: 'articles-docs-codemods-move-folder',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/move-folder',
+ },
+ {
+ id: 'codemods/rename-composition',
+ title: 'renameComposition()',
+ relativePath: 'docs/codemods/rename-composition.mdx',
+ compId: 'articles-docs-codemods-rename-composition',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/rename-composition',
+ },
+ {
+ id: 'codemods/rename-folder',
+ title: 'renameFolder()',
+ relativePath: 'docs/codemods/rename-folder.mdx',
+ compId: 'articles-docs-codemods-rename-folder',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/rename-folder',
+ },
+ {
+ id: 'codemods/reorder-effect',
+ title: 'reorderEffect()',
+ relativePath: 'docs/codemods/reorder-effect.mdx',
+ compId: 'articles-docs-codemods-reorder-effect',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/reorder-effect',
+ },
+ {
+ id: 'codemods/reorder-jsx-node',
+ title: 'reorderJsxNode()',
+ relativePath: 'docs/codemods/reorder-jsx-node.mdx',
+ compId: 'articles-docs-codemods-reorder-jsx-node',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/reorder-jsx-node',
+ },
+ {
+ id: 'codemods/resolve-composition-component',
+ title: 'resolveCompositionComponent()',
+ relativePath: 'docs/codemods/resolve-composition-component.mdx',
+ compId: 'articles-docs-codemods-resolve-composition-component',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/resolve-composition-component',
+ },
+ {
+ id: 'codemods/set-composition-default-props',
+ title: 'setCompositionDefaultProps()',
+ relativePath: 'docs/codemods/set-composition-default-props.mdx',
+ compId: 'articles-docs-codemods-set-composition-default-props',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/set-composition-default-props',
+ },
+ {
+ id: 'codemods/split-sequences',
+ title: 'splitSequences()',
+ relativePath: 'docs/codemods/split-sequences.mdx',
+ compId: 'articles-docs-codemods-split-sequences',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/split-sequences',
+ },
+ {
+ id: 'codemods/unwrap-folder',
+ title: 'unwrapFolder()',
+ relativePath: 'docs/codemods/unwrap-folder.mdx',
+ compId: 'articles-docs-codemods-unwrap-folder',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/unwrap-folder',
+ },
+ {
+ id: 'codemods/update-composition-metadata',
+ title: 'updateCompositionMetadata()',
+ relativePath: 'docs/codemods/update-composition-metadata.mdx',
+ compId: 'articles-docs-codemods-update-composition-metadata',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/update-composition-metadata',
+ },
+ {
+ id: 'codemods/update-effect-keyframes',
+ title: 'updateEffectKeyframes()',
+ relativePath: 'docs/codemods/update-effect-keyframes.mdx',
+ compId: 'articles-docs-codemods-update-effect-keyframes',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/update-effect-keyframes',
+ },
+ {
+ id: 'codemods/update-effect-props',
+ title: 'updateEffectProps()',
+ relativePath: 'docs/codemods/update-effect-props.mdx',
+ compId: 'articles-docs-codemods-update-effect-props',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/update-effect-props',
+ },
+ {
+ id: 'codemods/update-jsx-node-keyframes',
+ title: 'updateJsxNodeKeyframes()',
+ relativePath: 'docs/codemods/update-jsx-node-keyframes.mdx',
+ compId: 'articles-docs-codemods-update-jsx-node-keyframes',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/update-jsx-node-keyframes',
+ },
+ {
+ id: 'codemods/update-jsx-node-props',
+ title: 'updateJsxNodeProps()',
+ relativePath: 'docs/codemods/update-jsx-node-props.mdx',
+ compId: 'articles-docs-codemods-update-jsx-node-props',
+ crumb: '@remotion/codemods',
+ noAi: false,
+ slug: 'codemods/update-jsx-node-props',
+ },
{
id: 'color-correction',
title: 'Color correction',
diff --git a/packages/docs/static/generated/articles-docs-codemods-add-component.png b/packages/docs/static/generated/articles-docs-codemods-add-component.png
new file mode 100644
index 0000000000..7c78031fd9
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-add-component.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-add-composition.png b/packages/docs/static/generated/articles-docs-codemods-add-composition.png
new file mode 100644
index 0000000000..7909a49b0b
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-add-composition.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-add-effect.png b/packages/docs/static/generated/articles-docs-codemods-add-effect.png
new file mode 100644
index 0000000000..4b078cde7f
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-add-effect.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-add-folder.png b/packages/docs/static/generated/articles-docs-codemods-add-folder.png
new file mode 100644
index 0000000000..04b5b46596
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-add-folder.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-add-media.png b/packages/docs/static/generated/articles-docs-codemods-add-media.png
new file mode 100644
index 0000000000..a7e1e8a529
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-add-media.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-delete-composition.png b/packages/docs/static/generated/articles-docs-codemods-delete-composition.png
new file mode 100644
index 0000000000..871c9b3d5a
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-delete-composition.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-delete-effects.png b/packages/docs/static/generated/articles-docs-codemods-delete-effects.png
new file mode 100644
index 0000000000..a8dfc7edc2
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-delete-effects.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-detach-audio.png b/packages/docs/static/generated/articles-docs-codemods-detach-audio.png
new file mode 100644
index 0000000000..2b033e4780
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-detach-audio.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-duplicate-composition.png b/packages/docs/static/generated/articles-docs-codemods-duplicate-composition.png
new file mode 100644
index 0000000000..7914fd3edd
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-duplicate-composition.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-duplicate-effects.png b/packages/docs/static/generated/articles-docs-codemods-duplicate-effects.png
new file mode 100644
index 0000000000..2b1d442b86
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-duplicate-effects.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-duplicate-jsx-nodes.png b/packages/docs/static/generated/articles-docs-codemods-duplicate-jsx-nodes.png
new file mode 100644
index 0000000000..1a44407855
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-duplicate-jsx-nodes.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-get-jsx-node-props.png b/packages/docs/static/generated/articles-docs-codemods-get-jsx-node-props.png
new file mode 100644
index 0000000000..c18dd259ee
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-get-jsx-node-props.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-get-jsx-nodes.png b/packages/docs/static/generated/articles-docs-codemods-get-jsx-nodes.png
new file mode 100644
index 0000000000..dc0dcf85dd
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-get-jsx-nodes.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-move-composition.png b/packages/docs/static/generated/articles-docs-codemods-move-composition.png
new file mode 100644
index 0000000000..4dca9182aa
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-move-composition.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-move-folder.png b/packages/docs/static/generated/articles-docs-codemods-move-folder.png
new file mode 100644
index 0000000000..2a9f510716
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-move-folder.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-rename-composition.png b/packages/docs/static/generated/articles-docs-codemods-rename-composition.png
new file mode 100644
index 0000000000..789c12d696
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-rename-composition.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-rename-folder.png b/packages/docs/static/generated/articles-docs-codemods-rename-folder.png
new file mode 100644
index 0000000000..1ad5b44a33
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-rename-folder.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-reorder-effect.png b/packages/docs/static/generated/articles-docs-codemods-reorder-effect.png
new file mode 100644
index 0000000000..5ce28a0078
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-reorder-effect.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-reorder-jsx-node.png b/packages/docs/static/generated/articles-docs-codemods-reorder-jsx-node.png
new file mode 100644
index 0000000000..1ec5aad962
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-reorder-jsx-node.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-resolve-composition-component.png b/packages/docs/static/generated/articles-docs-codemods-resolve-composition-component.png
new file mode 100644
index 0000000000..3fc049ae6e
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-resolve-composition-component.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-set-composition-default-props.png b/packages/docs/static/generated/articles-docs-codemods-set-composition-default-props.png
new file mode 100644
index 0000000000..6bb6b92658
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-set-composition-default-props.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-split-sequences.png b/packages/docs/static/generated/articles-docs-codemods-split-sequences.png
new file mode 100644
index 0000000000..c8e0ae303a
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-split-sequences.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-unwrap-folder.png b/packages/docs/static/generated/articles-docs-codemods-unwrap-folder.png
new file mode 100644
index 0000000000..3bb3c262bc
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-unwrap-folder.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-update-composition-metadata.png b/packages/docs/static/generated/articles-docs-codemods-update-composition-metadata.png
new file mode 100644
index 0000000000..280ab91a9e
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-update-composition-metadata.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-update-effect-keyframes.png b/packages/docs/static/generated/articles-docs-codemods-update-effect-keyframes.png
new file mode 100644
index 0000000000..220fa9ec15
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-update-effect-keyframes.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-update-effect-props.png b/packages/docs/static/generated/articles-docs-codemods-update-effect-props.png
new file mode 100644
index 0000000000..bc37e7b95a
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-update-effect-props.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-update-jsx-node-keyframes.png b/packages/docs/static/generated/articles-docs-codemods-update-jsx-node-keyframes.png
new file mode 100644
index 0000000000..7f9ca5b8eb
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-update-jsx-node-keyframes.png differ
diff --git a/packages/docs/static/generated/articles-docs-codemods-update-jsx-node-props.png b/packages/docs/static/generated/articles-docs-codemods-update-jsx-node-props.png
new file mode 100644
index 0000000000..4fbeb270d9
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-codemods-update-jsx-node-props.png differ