Skip to main content

wrapNode()v4.0.530

Wraps an existing node in an element created with createElement(). The wrapped element becomes the only child of the wrapper, and the wrapper's imports are added.

warning

Draft API: This API is experimental and may change.

wrap-node.ts
import {createElement, getNodes, wrapNode, type CodemodProject} from '@remotion/codemods'; declare const project: CodemodProject; const node = getNodes({project, filePath: 'src/Video.tsx'}).find((candidate) => candidate.tagName === 'div'); if (node) { const result = wrapNode({ project, node, wrapper: createElement({ component: 'Sequence', importPath: 'remotion', props: {from: 30, durationInFrames: 60}, }), }); console.log(result.changes); }

The wrapped element keeps its source formatting.

Options​

project​

An in-memory CodemodProject. The input project is not mutated.

node​

The reference of the node to wrap. See node references.

wrapper​

The wrapper element, created with createElement(). It must not have children. Wrapping in <HtmlInCanvas> or <HtmlInCanvasMotionBlur> copies the wrapped element’s explicit width and height JSX props onto the wrapper. Both must evaluate to positive integers. Local variables, arithmetic, and conditional expressions can be copied. For a function call or property access, bind its result to a local variable and use that variable as the prop. Supply both dimensions after any JSX spread. Passing dimensions in the wrapper props or nesting canvas wrappers throws an error.

When the child has an inline style object, the canvas wrapper takes its CSS position and inset properties such as left and top. A component with explicit offsets and an implicit position gets an absolutely positioned canvas. Other styles, including transforms and opacity, stay on the child. Style references, objects with spreads or computed keys, and an explicitly styled wrapper keep the child’s style intact.

measuredSize​

Optional fallback for canvas wrappers when the wrapped element lacks dimensions the codemod can copy. Supply width and height as positive integers and display as 'inline', 'inline-block' or 'block'. Set verticalAlign to a CSS alignment value or null to use the default. Studio measures the layer at the current frame. Explicit source dimensions take precedence.

Return value​

An object with the following properties.

changes​

An array of {filePath, previousContents, nextContents} file changes.

nodePathRemappings​

An array of {filePath, oldNodePath, newNodePath} mappings. The wrapped element and its descendants receive new paths, and the wrapper is listed with a null old path. See node references.

logLine​

The one-based line of the wrapped element's opening tag in the input source.

Errors​

Throws when the node cannot be found, cannot be wrapped, or the wrapper is invalid. Failed edits leave the input project unchanged.

Compatibility​

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

See also​