🎥 Make videos programmatically with React
docs: migrate a few more API-Core docs
Frenco45d67611cc81
diff --git a/packages/docs/docs/delay-render.md b/packages/docs/docs/delay-render.mdindex fac2122502..2c504b8266 100644--- a/packages/docs/docs/delay-render.md+++ b/packages/docs/docs/delay-render.md@@ -22,7 +22,7 @@ This method is useful if you for example want to call an API to fetch data befor## Example-```tsx+```tsx twoslashimport {useEffect, useState} from 'react';import {continueRender, delayRender} from 'remotion';diff --git a/packages/docs/docs/get-audio-data.md b/packages/docs/docs/get-audio-data.mdindex dfa986c63d..dd65090835 100644--- a/packages/docs/docs/get-audio-data.md+++ b/packages/docs/docs/get-audio-data.md@@ -26,7 +26,11 @@ A string pointing to an audio asset.## Example-```ts+```ts twoslash+// @module: ESNext+// @target: ESNext+import {Audio} from "remotion";+// ---cut---import {getAudioData} from '@remotion/media-utils';import music from './music.mp3';diff --git a/packages/docs/docs/get-audio-duration.md b/packages/docs/docs/get-audio-duration.mdindex 3f08a0089f..fd8e3367c0 100644--- a/packages/docs/docs/get-audio-duration.md+++ b/packages/docs/docs/get-audio-duration.md@@ -19,7 +19,11 @@ A string pointing to an audio asset## Example-```tsx+```tsx twoslash+// @module: ESNext+// @target: ESNext+import {Audio} from 'remotion'+// ---cut---import {getAudioDuration} from '@remotion/media-utils';import music from './music.mp3';diff --git a/packages/docs/docs/get-input-props.md b/packages/docs/docs/get-input-props.mdindex 4961faaa83..12c3b00b31 100644--- a/packages/docs/docs/get-input-props.md+++ b/packages/docs/docs/get-input-props.md@@ -23,7 +23,9 @@ npx remotion render --props='{"hello": "world"}' src/index.tsx my-composition ouYou can then access the props in JavaScript:-```tsx+```tsx twoslash+const getInputProps = () => ({hello: "world"} as const)+// ---cut---const {hello} = getInputProps() // "world"```diff --git a/packages/docs/docs/get-video-metadata.md b/packages/docs/docs/get-video-metadata.mdindex bd50b44f3f..a50de49e94 100644--- a/packages/docs/docs/get-video-metadata.md+++ b/packages/docs/docs/get-video-metadata.md@@ -25,7 +25,11 @@ A string pointing to an asset.## Example-```tsx+```tsx twoslash+// @module: ESNext+// @target: ESNext+import {Audio} from 'remotion'+// ---cut---import {getVideoMetadata} from '@remotion/media-utils';import video from '../video.mp4';diff --git a/packages/docs/docs/get-waveform-portion.md b/packages/docs/docs/get-waveform-portion.mdindex 85b93e3879..180ae2f8d5 100644--- a/packages/docs/docs/get-waveform-portion.md+++ b/packages/docs/docs/get-waveform-portion.md@@ -27,8 +27,12 @@ An object with the following arguments:## Example-```tsx-import {getAudioData} from '@remotion/media-utils';+```tsx twoslash+// @module: ESNext+// @target: ESNext+import {Audio} from 'remotion'+// ---cut---+import {getAudioData, getWaveformPortion} from '@remotion/media-utils';import music from './music.mp3';const audioData = await getAudioData(music); /* {@@ -40,7 +44,7 @@ const audioData = await getAudioData(music); /* {isRemote: false} */-await waveformPortion = getWaveformPortion({+const waveformPortion = await getWaveformPortion({audioData,// Will select time range of 20-40 secondsstartTimeInSeconds: 20,diff --git a/packages/docs/docs/interpolate-colors.md b/packages/docs/docs/interpolate-colors.mdindex 3afee4d1c1..bfb94fb294 100644--- a/packages/docs/docs/interpolate-colors.md+++ b/packages/docs/docs/interpolate-colors.md@@ -25,17 +25,19 @@ In this example, we are interpolating colors from red to yellow. At frame 0 (theUsing the following snippet, we can calculate the current color for any frame:-```tsx+```tsx twoslash+let color = ''+// ---cut---import {useCurrentFrame, interpolateColors} from 'remotion';const frame = useCurrentFrame(); // 10-const color = interpolateColors(frame,+color = interpolateColors(frame,[0, 20],['red', 'yellow']); // rgba(255, 128, 0, 1)-const color = interpolateColors(frame,+color = interpolateColors(frame,[0, 20],['#ff0000', '#ffff00']); // rgba(255, 128, 0, 1)@@ -47,19 +49,21 @@ In this example, we are interpolating colors from red to yellow. At frame 0 (theUsing the following snippet, we can calculate the current color for any frame:-```tsx+```tsx twoslash+let color = ''+// ---cut---import {useCurrentFrame, interpolateColors} from 'remotion'const frame = useCurrentFrame(); // 10// RGB colors-const color = interpolateColors(frame,+color = interpolateColors(frame,[0, 20],['rgb(255, 0, 0)', 'rgb(255, 255, 0)']); // rgba(255, 128, 0, 1)// RGBA colors-const color = interpolateColors(frame,+color = interpolateColors(frame,[0, 20],['rgba(255, 0, 0, 1)', 'rgba(255, 255, 0, 0)']); // rgba(255, 128, 0, 0.5)@@ -71,18 +75,20 @@ In this example, we are interpolating colors from red to yellow. At frame 0 (theUsing the following snippet, we can calculate the current color for any frame:-```tsx+```ts twoslash+let color = ''+// ---cut---import {useCurrentFrame, interpolateColors} from 'remotion'const frame = useCurrentFrame(); // 10//hsl example-const color = interpolateColors(frame,+color = interpolateColors(frame,[0, 20],['hsl(0, 100%, 50%)', 'hsl(60, 100%, 50%)']); // rgba(255, 128, 0, 1)//hsla example-const color = interpolateColors(frame,+color = interpolateColors(frame,[0, 20],['hsla(0, 100%, 50%, 1)', 'hsla(60, 100%, 50%, 1)']); // rgba(255, 128, 0, 1)@@ -92,7 +98,7 @@ const color = interpolateColors(frame,Interpolating CSS color names is also supported.-```tsx+```ts twoslashimport {useCurrentFrame, interpolateColors} from 'remotion'const frame = useCurrentFrame(); // 10diff --git a/packages/docs/docs/interpolate.mdx b/packages/docs/docs/interpolate.mdxindex 8e39b634f3..b8c9aa7738 100644--- a/packages/docs/docs/interpolate.mdx+++ b/packages/docs/docs/interpolate.mdx@@ -22,7 +22,7 @@ At frame 20, we want the opacity to be 1.Using the following snippet, we can calculate the current opacity for any frame:-```tsx+```ts twoslashimport {useCurrentFrame, interpolate} from 'remotion'const frame = useCurrentFrame(); // 10@@ -40,8 +40,8 @@ At the end, the opacity should be 0.We can interpolate over multiple points in one go and use [`useVideoConfig()`](/docs/use-video-config) to determine the duration of the composition.-```tsx-import {useCurrentFrame, interpolate} from 'remotion'+```ts twoslash+import {useCurrentFrame, interpolate, useVideoConfig} from 'remotion'const frame = useCurrentFrame();const {durationInFrames} = useVideoConfig();@@ -60,8 +60,8 @@ Let's assume we want to animate an object on the X axis from 0 to 200 pixels andLet's create a spring:-```tsx-import {useCurrentFrame, interpolate, spring} from 'remotion';+```twoslash include example+import {useCurrentFrame, interpolate, spring, useVideoConfig} from 'remotion';const frame = useCurrentFrame();const {fps} = useVideoConfig();@@ -69,33 +69,51 @@ const driver = spring({frame,fps});+// - spring+```++```ts twoslash+// @include: example-spring```A [`spring()`](/docs/spring) animation with it's default settings will animate from 0 to 1.Given that knowledge, we can interpolate the spring value to go from 0 to 200.-```tsx+```ts twoslash+// @include: example-spring+// ---cut---const marginLeft = interpolate(driver, [0, 1], [0, 200])```We can then apply it to an HTML element.-```tsx-<div style={{marginLeft}}></div>+```tsx twoslash {1}+// @include: example-spring+const marginLeft = interpolate(driver, [0, 1], [0, 200])+// ---cut---+const Component: React.FC = () => (+ <div style={{marginLeft}}></div>+)```## Example: Prevent the output from going outside the output rangeConsider the following interpolation which is supposed to animate the scale over 20 frames:-```tsx+```tsx twoslash+import {interpolate, useCurrentFrame} from 'remotion'+const frame = useCurrentFrame();+// ---cut---const scale = interpolate(frame, [0, 20], [0, 1])```This works, but after 20 frames, the value keeps growing. For example, at frame 40, the scale will be `2`.To prevent this, this we can use the `extrapolateLeft` and `extrapolateRight` options and set them to `'clamp'` to prevent the result going outside the output range.-```tsx+```tsx twoslash+import {interpolate, useCurrentFrame} from 'remotion'+const frame = useCurrentFrame();+// ---cut---const scale = interpolate(frame, [0, 20], [0, 1], {extrapolateRight: 'clamp'});@@ -130,7 +148,9 @@ Same as [extrapolateLeft](#extrapolateleft), except for values outside right theExample:-```tsx+```tsx twoslash+import {interpolate} from 'remotion'+// ---cut---interpolate(1.5, [0, 1], [0, 2], {extrapolateRight: 'extend'}) // 3interpolate(1.5, [0, 1], [0, 2], {extrapolateRight: 'clamp'}) // 2interpolate(1.5, [0, 1], [0, 2], {extrapolateRight: 'identity'}) // 1.5@@ -143,7 +163,10 @@ _Default_: `(x) => x`Function which allows you to customize the input, for example to apply a certain easing function.By default, the input is left unmodified, resulting in a pure linear interpolation. [Read the documentation for the built-in easing functions](/docs/easing).-```tsx+```ts twoslash+import {useCurrentFrame} from 'remotion';+const frame = useCurrentFrame();+// ---cut---import {interpolate, Easing} from 'remotion';interpolate(frame, [0, 100], [0, 1], {diff --git a/packages/docs/docs/measure-spring.md b/packages/docs/docs/measure-spring.mdindex bd2d10b735..b650a4d8ac 100644--- a/packages/docs/docs/measure-spring.md+++ b/packages/docs/docs/measure-spring.md@@ -7,14 +7,10 @@ _Available from v2.0.8_Based on a [spring()](/docs/spring) configuration and the frame rate, return how long it takes for a spring animation to settle.-```tsx-import {- measureSpring,- SpringConfig-} from 'remotion';+```tsx twoslash+import {measureSpring, SpringConfig} from 'remotion';--const config: SpringConfig = {+const config: Partial<SpringConfig> = {damping: 200,}diff --git a/packages/docs/docs/overwriting-webpack-config.md b/packages/docs/docs/overwriting-webpack-config.mdindex 74e0126706..aabad731d2 100644--- a/packages/docs/docs/overwriting-webpack-config.md+++ b/packages/docs/docs/overwriting-webpack-config.md@@ -18,7 +18,6 @@ In your `remotion.config.ts` file, you can call `Config.Bundler.overrideWebpackCOverriding the Webpack config uses the reducer pattern - pass in a function that takes as it's argument a Webpack configuration and return a new Webpack configuration.```ts twoslash-// @errors: 2532 2488import {Config} from 'remotion';Config.Bundling.overrideWebpackConfig((currentConfiguration) => {@@ -27,7 +26,7 @@ Config.Bundling.overrideWebpackConfig((currentConfiguration) => {module: {...currentConfiguration.module,rules: [- ...currentConfiguration.module.rules,+ ...(currentConfiguration.module?.rules ?? []),// Add more loaders here],},diff --git a/packages/docs/docs/parametrized-rendering.md b/packages/docs/docs/parametrized-rendering.mdindex d09ddb732d..07ab9beb2a 100644--- a/packages/docs/docs/parametrized-rendering.md+++ b/packages/docs/docs/parametrized-rendering.md@@ -102,7 +102,7 @@ await renderFrames({When using GitHub Actions, you need to adjust the file at `.github/workflows/render-video.yml` to make the inputs in the `workflow_dispatch` section manually match the shape of the props your root component accepts.-```yml {3,7}+```yaml {3, 7}workflow_dispatch:inputs:titleText:diff --git a/packages/docs/docs/random.md b/packages/docs/docs/random.mdindex 0d2eb518e7..b746ba1961 100644--- a/packages/docs/docs/random.md+++ b/packages/docs/docs/random.md@@ -5,10 +5,12 @@ title: random()The `random()` API will give your deterministic pseudorandom values. Unlike the `Math.random()` function, Remotions function takes in a seed which can be a `number` or a `string`. If the seed is the same, the output is always the same.-```ts+```ts twoslash+// @errors: 2554+const random = (seed: number | string | null) => 0.07301638228818774 as const+// ---cut---const rand = random(1); // 0.07301638228818774-const rand = random(1); // still 0.07301638228818774-+const rand2 = random(1); // still 0.07301638228818774const randomCoordinates = new Array(10).fill(true).map((a, i) => {return {@@ -28,7 +30,9 @@ Randomness can be used to create to create interesting visualizations, such as pCalling `Math.random()` results in an ESLint warning in Remotion since often it leads to bugs in rendering. If you are sure you want a true random number, and want to bypass this message without adding an ignore comment, use `random(null)`-```ts+```ts twoslash+const random = (seed: number | string | null) => Math.random()+// ---cut---// Passing null will result in a different value every time.random(null) === random(null) // false```diff --git a/packages/docs/docs/register-root.md b/packages/docs/docs/register-root.mdindex f3f921c9da..24ddd3ff56 100644--- a/packages/docs/docs/register-root.md+++ b/packages/docs/docs/register-root.md@@ -15,7 +15,7 @@ The list of compositions can be updated without reloading the page, but calling```tsximport {registerRoot} from 'remotion';-import {RemotionVideo} from './RemotionVideo';+import {RemotionVideo} from './Video';registerRoot(RemotionVideo);```diff --git a/packages/docs/docs/spring.md b/packages/docs/docs/spring.mdindex ca3e5d5754..e044bc58cc 100644--- a/packages/docs/docs/spring.md+++ b/packages/docs/docs/spring.md@@ -7,7 +7,9 @@ Delightful and smooth animation primitive. Calculates a position based on physicExample:-```tsx+```tsx twoslash+import {useCurrentFrame, useVideoConfig, spring} from "remotion";+// ---cut---const frame = useCurrentFrame()const videoConfig = useVideoConfig()diff --git a/packages/docs/docs/use-current-frame.md b/packages/docs/docs/use-current-frame.mdindex 159955ff6d..ea2b2ecd59 100644--- a/packages/docs/docs/use-current-frame.md+++ b/packages/docs/docs/use-current-frame.md@@ -9,7 +9,7 @@ If the component you are writing is wrapped in a `<Sequence>`, `useCurrentFrame`Say the timeline marker is positioned at frame 25. In the example below, `useCurrentFrame` will return `20`, except within the Subtitle component, where it will return `15` because it is within a sequence that starts at frame 10.-```tsx+```tsx twoslashimport {useCurrentFrame, Sequence} from 'remotion';const Title = () => {