Skip to content

🎥 Make videos programmatically with React

change interpolate styles

ChetanKarwa67df0d14813a
diff --git a/packages/animation-utils/README.md b/packages/animation-utils/README.md
index 3099505ee0..982a628fa8 100644
--- a/packages/animation-utils/README.md
+++ b/packages/animation-utils/README.md
@@ -1,20 +1,21 @@
# `@remotion/animation-utils`
-## useInterpolateStyles
+## interpolateStyles
-A React hook to interpolate styles based on the current frame.
+_Available from v2.0.3_
+
+Allows you to map a range of values to styles.
**Documentation: https://remotion.dev/animation-utils**
### Usage
-```tsx
-import {useInterpolateStyles} from '@remotion/animation-utils';
+```tsx twoslash
+import {interpolateStyles} from '@remotion/animation-utils';
import {useMemo} from 'react';
import {AbsoluteFill} from 'remotion';
export default function Example() {
- const inputRangeInFrames = useMemo(() => [0, 100], []);
const outputStyles = useMemo(
() => [
{
@@ -26,10 +27,8 @@ export default function Example() {
],
[],
);
- const styles = useInterpolateStyles({
- inputRangeInFrames,
- outputStyles,
- });
+ const frame = useCurrentFrame();
+ const styles = interpolateStyles(frame, [0, 100], outputStyles);
return (
<AbsoluteFill
style={{
@@ -58,7 +57,7 @@ A type-safe function to create string for the `transform` CSS property.
### Usage
-```tsx
+```tsx twoslash
import {makeTransform, rotate, translateX} from '@remotion/animation-utils';
import {AbsoluteFill} from 'remotion';
diff --git a/packages/animation-utils/src/index.ts b/packages/animation-utils/src/index.ts
index e764a35262..d55a705d61 100644
--- a/packages/animation-utils/src/index.ts
+++ b/packages/animation-utils/src/index.ts
@@ -1,5 +1,5 @@
+export * from './transformation-helpers/interpolate-styles/index.js';
export * from './transformation-helpers/make-transform';
-export * from './transformation-helpers/use-interpolate-styles';
export type {
AngleUnit,
LengthPercentageUnit,
diff --git a/packages/animation-utils/src/transformation-helpers/use-interpolate-styles/constants.ts b/packages/animation-utils/src/transformation-helpers/interpolate-styles/constants.ts
similarity index 100%
rename from packages/animation-utils/src/transformation-helpers/use-interpolate-styles/constants.ts
rename to packages/animation-utils/src/transformation-helpers/interpolate-styles/constants.ts
diff --git a/packages/animation-utils/src/transformation-helpers/interpolate-styles/index.tsx b/packages/animation-utils/src/transformation-helpers/interpolate-styles/index.tsx
new file mode 100644
index 0000000000..43b73f0281
--- /dev/null
+++ b/packages/animation-utils/src/transformation-helpers/interpolate-styles/index.tsx
@@ -0,0 +1,243 @@
+import {interpolate, interpolateColors} from 'remotion';
+import type {
+ CSSPropertiesKey,
+ CSSPropertiesValue,
+ Style,
+ UnitNumberAndFunction,
+} from '../../type';
+import {breakDownValueIntoUnitNumberAndFunctions} from './utils';
+
+const interpolatedPropertyPart = (
+ inputValue: number,
+ inputRange: number[],
+ initialStylePropertyPart: UnitNumberAndFunction,
+ finalStylePropertyPart: UnitNumberAndFunction,
+ initialStyleProperty: CSSPropertiesValue,
+ finalStyleProperty: CSSPropertiesValue,
+): string => {
+ if (finalStylePropertyPart === undefined) {
+ throw new TypeError(
+ `The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`,
+ );
+ }
+
+ if (initialStylePropertyPart.color) {
+ if (!finalStylePropertyPart.color) {
+ throw new TypeError(
+ `The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`,
+ );
+ }
+
+ const interpolatedColor = interpolateColors(inputValue, inputRange, [
+ initialStylePropertyPart.color,
+ finalStylePropertyPart.color as string,
+ ]);
+ return `${interpolatedColor}`;
+ }
+
+ if (initialStylePropertyPart.function) {
+ if (
+ !finalStylePropertyPart?.function ||
+ initialStylePropertyPart.function.name !==
+ finalStylePropertyPart.function?.name
+ ) {
+ throw new TypeError(
+ `The start and end values must be of the same type. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`,
+ );
+ }
+
+ const endValuePartFunction = finalStylePropertyPart.function;
+ const endValuePartFunctionArgs = endValuePartFunction.values || [];
+ const interpolatedFunctionArgs =
+ initialStylePropertyPart.function.values.reduce(
+ (acc: string, startValuePartFunctionArg, index) => {
+ const endValuePartFunctionArg = endValuePartFunctionArgs[index];
+ const interpolatedArg = interpolatedPropertyPart(
+ inputValue,
+ inputRange,
+ startValuePartFunctionArg,
+ endValuePartFunctionArg,
+ initialStyleProperty,
+ finalStyleProperty,
+ );
+ return `${acc}, ${interpolatedArg}`;
+ },
+ '',
+ );
+ return `${
+ initialStylePropertyPart.function.name
+ }(${interpolatedFunctionArgs.slice(2)})`;
+ }
+
+ if (typeof initialStylePropertyPart.number === 'undefined') {
+ return `${initialStylePropertyPart.unit}`;
+ }
+
+ if (initialStylePropertyPart.unit !== finalStylePropertyPart.unit) {
+ throw new TypeError(
+ `The units of the start and end values must match. Start value: ${initialStyleProperty}, end value: ${finalStyleProperty}`,
+ );
+ }
+
+ const startNumber = initialStylePropertyPart.number;
+ const endNumber = finalStylePropertyPart.number || 0;
+ const interpolatedNumber = interpolate(inputValue, inputRange, [
+ startNumber,
+ endNumber,
+ ]);
+ const interpolatedUnit = initialStylePropertyPart.unit;
+ return `${interpolatedNumber}${interpolatedUnit}`;
+};
+
+const interpolateProperty = (
+ inputValue: number,
+ inputRange: number[],
+ initialStyleProperty: CSSPropertiesValue,
+ finalStyleProperty: CSSPropertiesValue,
+) => {
+ if (typeof initialStyleProperty !== typeof finalStyleProperty) {
+ return initialStyleProperty;
+ }
+
+ if (typeof initialStyleProperty === 'number') {
+ return interpolate(inputValue, inputRange, [
+ initialStyleProperty,
+ finalStyleProperty as number,
+ ]);
+ }
+
+ const initialStylePropertyParts =
+ breakDownValueIntoUnitNumberAndFunctions(initialStyleProperty);
+ const finalStylePropertyParts =
+ breakDownValueIntoUnitNumberAndFunctions(finalStyleProperty);
+
+ const interpolatedValue = initialStylePropertyParts.reduce(
+ (acc, initialStylePropertyPart, index) => {
+ return `${acc} ${interpolatedPropertyPart(
+ inputValue,
+ inputRange,
+ initialStylePropertyPart,
+ finalStylePropertyParts[index],
+ initialStyleProperty,
+ finalStyleProperty,
+ )}`;
+ },
+ '',
+ );
+ return interpolatedValue.slice(1);
+};
+
+const interpolateStylesFunction = (
+ inputValue: number,
+ [startingValue, endingValue]: number[],
+ initialStyle: Style,
+ finalStyle: Style,
+): Style => {
+ return Object.keys(initialStyle).reduce((acc, key) => {
+ return {
+ ...acc,
+ [key]: interpolateProperty(
+ inputValue,
+ [startingValue, endingValue],
+ initialStyle[key as CSSPropertiesKey],
+ finalStyle[key as CSSPropertiesKey],
+ ),
+ };
+ }, {});
+};
+
+function checkInputRange(arr: readonly number[]) {
+ if (arr.length < 2) {
+ throw new Error('inputRange must have at least 2 elements');
+ }
+
+ for (let index = 0; index < arr.length; index++) {
+ if (typeof arr[index] !== 'number') {
+ throw new Error(`inputRange must contain only numbers`);
+ }
+
+ if (arr[index] === -Infinity || arr[index] === Infinity) {
+ throw new Error(
+ `inputRange must contain only finite numbers, but got [${arr.join(
+ ',',
+ )}]`,
+ );
+ }
+
+ if (index > 0 && !(arr[index] > arr[index - 1])) {
+ throw new Error(
+ `inputRange must be strictly monotonically non-decreasing but got [${arr.join(
+ ',',
+ )}]`,
+ );
+ }
+ }
+}
+
+function checkStylesRange(arr: readonly Style[]) {
+ if (arr.length < 2) {
+ throw new Error('outputStyles must have at least 2 elements');
+ }
+
+ for (const index in arr) {
+ if (typeof arr[index] !== 'object') {
+ throw new Error('outputStyles must contain only objects');
+ }
+ }
+}
+
+/**
+ * @description This function allows you to map a range of values to colors using a concise syntax.
+ * @see [Documentation](https://www.remotion.dev/docs/interpolate-colors)
+ */
+export const interpolateStyles = (
+ input: number,
+ inputRange: number[],
+ outputStylesRange: Style[],
+) => {
+ if (typeof input === 'undefined') {
+ throw new Error('input can not be undefined');
+ }
+
+ if (typeof inputRange === 'undefined') {
+ throw new Error('inputRange can not be undefined');
+ }
+
+ if (typeof outputStylesRange === 'undefined') {
+ throw new Error('outputRange can not be undefined');
+ }
+
+ if (inputRange.length !== outputStylesRange.length) {
+ throw new Error(
+ 'inputRange (' +
+ inputRange.length +
+ ') and outputStylesRange (' +
+ outputStylesRange.length +
+ ') must have the same length',
+ );
+ }
+
+ checkInputRange(inputRange);
+ checkStylesRange(outputStylesRange);
+
+ if (input < inputRange[0]) {
+ return outputStylesRange[0];
+ }
+
+ if (input >= inputRange[inputRange.length - 1]) {
+ return outputStylesRange[outputStylesRange.length - 1];
+ }
+
+ const startIndex = inputRange.findIndex((step) => input < step) - 1;
+ const endIndex = startIndex + 1;
+ const startingValue = inputRange[startIndex];
+ const endingValue = inputRange[endIndex];
+ const initialStyle = outputStylesRange[startIndex];
+ const finalStyle = outputStylesRange[endIndex];
+ return interpolateStylesFunction(
+ input,
+ [startingValue, endingValue],
+ initialStyle,
+ finalStyle,
+ );
+};
diff --git a/packages/animation-utils/src/transformation-helpers/use-interpolate-styles/utils.ts b/packages/animation-utils/src/transformation-helpers/interpolate-styles/utils.ts
similarity index 100%
rename from packages/animation-utils/src/transformation-helpers/use-interpolate-styles/utils.ts
rename to packages/animation-utils/src/transformation-helpers/interpolate-styles/utils.ts
diff --git a/packages/animation-utils/src/transformation-helpers/use-interpolate-styles/index.tsx b/packages/animation-utils/src/transformation-helpers/use-interpolate-styles/index.tsx
deleted file mode 100644
index 18d63bf032..0000000000
--- a/packages/animation-utils/src/transformation-helpers/use-interpolate-styles/index.tsx
+++ /dev/null
@@ -1,232 +0,0 @@
-import {useEffect, useMemo, useState} from 'react';
-import {
- interpolate,
- interpolateColors,
- useCurrentFrame,
- useVideoConfig,
-} from 'remotion';
-import type {
- CSSPropertiesKey,
- CSSPropertiesValue,
- InterpolateStylesParams,
- Style,
- UnitNumberAndFunction,
-} from '../../type';
-import {breakDownValueIntoUnitNumberAndFunctions} from './utils';
-
-const getInterpolatedPartValue = (
- currentFrame: number,
- inputRange: number[],
- startValuePart: UnitNumberAndFunction,
- endValuePart: UnitNumberAndFunction,
- startValue: CSSPropertiesValue,
- endValue: CSSPropertiesValue,
-): string => {
- if (endValuePart === undefined) {
- throw new TypeError(
- `The start and end values must be of the same type. Start value: ${startValue}, end value: ${endValue}`,
- );
- }
-
- if (startValuePart.color) {
- if (!endValuePart.color) {
- throw new TypeError(
- `The start and end values must be of the same type. Start value: ${startValue}, end value: ${endValue}`,
- );
- }
-
- const interpolatedColor = interpolateColors(currentFrame, inputRange, [
- startValuePart.color,
- endValuePart.color as string,
- ]);
- return `${interpolatedColor}`;
- }
-
- if (startValuePart.function) {
- if (
- !endValuePart?.function ||
- startValuePart.function.name !== endValuePart.function?.name
- ) {
- throw new TypeError(
- `The start and end values must be of the same type. Start value: ${startValue}, end value: ${endValue}`,
- );
- }
-
- const endValuePartFunction = endValuePart.function;
- const endValuePartFunctionArgs = endValuePartFunction.values || [];
- const interpolatedFunctionArgs = startValuePart.function.values.reduce(
- (acc: string, startValuePartFunctionArg, index) => {
- const endValuePartFunctionArg = endValuePartFunctionArgs[index];
- const interpolatedArg = getInterpolatedPartValue(
- currentFrame,
- inputRange,
- startValuePartFunctionArg,
- endValuePartFunctionArg,
- startValue,
- endValue,
- );
- return `${acc}, ${interpolatedArg}`;
- },
- '',
- );
- return `${startValuePart.function.name}(${interpolatedFunctionArgs.slice(
- 2,
- )})`;
- }
-
- if (typeof startValuePart.number === 'undefined') {
- return `${startValuePart.unit}`;
- }
-
- if (startValuePart.unit !== endValuePart.unit) {
- throw new TypeError(
- `The units of the start and end values must match. Start value: ${startValue}, end value: ${endValue}`,
- );
- }
-
- const startNumber = startValuePart.number;
- const endNumber = endValuePart.number || 0;
- const interpolatedNumber = interpolate(currentFrame, inputRange, [
- startNumber,
- endNumber,
- ]);
- const interpolatedUnit = startValuePart.unit;
- return `${interpolatedNumber}${interpolatedUnit}`;
-};
-
-const getInterpolatedPropertyValue = (
- currentFrame: number,
- inputRange: number[],
- startValue: CSSPropertiesValue,
- endValue: CSSPropertiesValue,
-) => {
- if (typeof startValue !== typeof endValue) {
- return startValue;
- }
-
- if (typeof startValue === 'number') {
- return interpolate(currentFrame, inputRange, [
- startValue,
- endValue as number,
- ]);
- }
-
- const startValueParts = breakDownValueIntoUnitNumberAndFunctions(startValue);
- const endValueArray = breakDownValueIntoUnitNumberAndFunctions(endValue);
-
- const interpolatedValue = startValueParts.reduce(
- (acc, startValuePart, index) => {
- const interpolatedValuePart = getInterpolatedPartValue(
- currentFrame,
- inputRange,
- startValuePart,
- endValueArray[index],
- startValue,
- endValue,
- );
- return `${acc} ${interpolatedValuePart}`;
- },
- '',
- );
- return interpolatedValue.slice(1);
-};
-
-const interpolateStyles = (
- frame: number,
- [startFrame, endFrame]: number[],
- startStyle: Style,
- endStyle: Style,
-): Style => {
- const interpolatedStyle = Object.keys(startStyle).reduce((acc, key) => {
- const interpolatedValue = getInterpolatedPropertyValue(
- frame,
- [startFrame, endFrame],
- startStyle[key as CSSPropertiesKey],
- endStyle[key as CSSPropertiesKey],
- );
- return {
- ...acc,
- [key]: interpolatedValue,
- };
- }, {});
- return interpolatedStyle;
-};
-
-export const useInterpolateStyles = ({
- inputRangeInFrames,
- inputRangeInSeconds,
- outputStyles,
-}: InterpolateStylesParams) => {
- useEffect(() => {
- console.log('rerendering because of inputRangeInFrames');
- }, [inputRangeInFrames]);
- useEffect(() => {
- console.log('rerendering because of inputRangeInSeconds');
- }, [inputRangeInSeconds]);
- useEffect(() => {
- console.log('rerendering because of outputStyles');
- }, [outputStyles]);
- const [currentStyles, setCurrentStyles] = useState<Style>({});
- const [areInputsValid, setAreInputsValid] = useState(false);
- const frame = useCurrentFrame();
- const {fps} = useVideoConfig();
-
- const interpolateFrameSteps = useMemo(
- () =>
- inputRangeInFrames ||
- inputRangeInSeconds?.map((duration) => Math.round(duration * fps)) ||
- [],
- [fps, inputRangeInFrames, inputRangeInSeconds],
- );
-
- useEffect(() => {
- if (interpolateFrameSteps.length !== outputStyles.length) {
- throw new TypeError(
- `The number of steps in the interpolation must match the number of output styles.`,
- );
- } else if (interpolateFrameSteps.length < 2) {
- throw new TypeError(
- `The number of steps in the interpolation must be at least 2.`,
- );
- } else {
- setAreInputsValid(true);
- }
- }, [interpolateFrameSteps, outputStyles]);
-
- useEffect(() => {
- const updateCurrentStyles = () => {
- if (!areInputsValid) {
- return outputStyles[0] || {};
- }
-
- if (frame < interpolateFrameSteps[0]) {
- setCurrentStyles(outputStyles[0]);
- return;
- }
-
- if (frame >= interpolateFrameSteps[interpolateFrameSteps.length - 1]) {
- setCurrentStyles(outputStyles[outputStyles.length - 1]);
- return;
- }
-
- const startIndex =
- interpolateFrameSteps.findIndex((step) => frame < step) - 1;
- const endIndex = startIndex + 1;
- const startFrame = interpolateFrameSteps[startIndex];
- const endFrame = interpolateFrameSteps[endIndex];
- const startStyle = outputStyles[startIndex];
- const endStyle = outputStyles[endIndex];
- const currentFrameStyles = interpolateStyles(
- frame,
- [startFrame, endFrame],
- startStyle,
- endStyle,
- );
- setCurrentStyles(currentFrameStyles);
- };
-
- updateCurrentStyles();
- }, [areInputsValid, frame, interpolateFrameSteps, outputStyles]);
-
- return currentStyles;
-};
diff --git a/packages/animation-utils/src/type.ts b/packages/animation-utils/src/type.ts
index 34c5af9ab2..dc64928afa 100644
--- a/packages/animation-utils/src/type.ts
+++ b/packages/animation-utils/src/type.ts
@@ -1,3 +1,4 @@
+import type {breakDownValueIntoUnitNumberAndFunctions} from './transformation-helpers/interpolate-styles/utils';
import type {
matrix,
matrix3d,
@@ -21,7 +22,6 @@ import type {
translateY,
translateZ,
} from './transformation-helpers/make-transform';
-import type {breakDownValueIntoUnitNumberAndFunctions} from './transformation-helpers/use-interpolate-styles/utils';
type TransformFunction = () => string;
type LengthUnit =
@@ -99,18 +99,6 @@ type Style = React.CSSProperties;
type CSSPropertiesKey = keyof Style;
type CSSPropertiesValue = Style[CSSPropertiesKey];
-type InterpolateStylesParams =
- | {
- inputRangeInFrames: number[];
- inputRangeInSeconds?: number[];
- outputStyles: Style[];
- }
- | {
- inputRangeInFrames?: number[];
- inputRangeInSeconds: number[];
- outputStyles: Style[];
- };
-
type UnitNumberAndFunctions = ReturnType<
typeof breakDownValueIntoUnitNumberAndFunctions
>;
@@ -127,6 +115,5 @@ export type {
Style,
CSSPropertiesKey,
CSSPropertiesValue,
- InterpolateStylesParams,
UnitNumberAndFunction,
};
diff --git a/packages/docs/components/TableOfContents/animation-utils.tsx b/packages/docs/components/TableOfContents/animation-utils.tsx
index ddf9cb5538..119159aa16 100644
--- a/packages/docs/components/TableOfContents/animation-utils.tsx
+++ b/packages/docs/components/TableOfContents/animation-utils.tsx
@@ -12,11 +12,9 @@ export const TableOfContents: React.FC = () => {
Type-safe function to create string for the transform CSS property
</div>
</TOCItem>
- <TOCItem link="/docs/animation-utils/use-interpolate-styles">
- <strong>useInterpolateStyles()</strong>
- <div>
- React hook to interpolate styles based on the current frame.
- </div>
+ <TOCItem link="/docs/animation-utils/interpolate-styles">
+ <strong>interpolateStyles()</strong>
+ <div>Map a range of values to Styles</div>
</TOCItem>
</Grid>
</div>
diff --git a/packages/docs/docs/animation-utils/interpolate-styles.md b/packages/docs/docs/animation-utils/interpolate-styles.md
new file mode 100644
index 0000000000..36e91aa0ea
--- /dev/null
+++ b/packages/docs/docs/animation-utils/interpolate-styles.md
@@ -0,0 +1,59 @@
+---
+image: /generated/articles-docs-animation-utils-interpolate-styles.png
+title: interpolateStyles()
+id: interpolate-styles
+crumb: "@remotion/animation-utils"
+---
+
+_Part of the [`@remotion/animation-utils`](/docs/animation-utils) package._
+
+This function provides a convenient way to interpolate styles based on a specified range of values, allowing for smooth animations between different styles.
+
+## API
+
+### `interpolateStyles(options: InterpolateStylesParams): Style`
+
+### Params
+
+1. The input value.
+2. The range of values that you expect the input to assume.
+3. The range of output styles that you want the input to map to.
+
+### Return value
+
+- A style object representing the interpolated styles based on the current frame.
+
+### Example
+
+```tsx twoslash
+// ---cut---
+import {
+ interpolateStyles,
+ makeTransform,
+ translateY,
+} from "@remotion/animation-utils";
+
+const MyComponent: React.FC = () => {
+ const animatedStyles = interpolateStyles({
+ inputRangeInFrames: [0, 30, 60],
+ outputStyles: [
+ { opacity: 0, transform: makeTransform([translateY(-50)]) },
+ { opacity: 1, transform: makeTransform([translateY(0)]) },
+ { opacity: 0, transform: makeTransform([translateY(50)]) },
+ ],
+ });
+
+ return <div style={animatedStyles}>Animating Styles!</div>;
+};
+```
+
+### Usage Notes
+
+- Ensure that the `inputRange` and `outputStylesRange` arrays contain at least two values to facilitate interpolation between styles.
+
+- The `outputStylesRange` array must have the same number of elements as `inputRange`. Each style in `outputStylesRange` corresponds to a specific value in the input range.
+
+## See also
+
+- [Source code for this hook](https://github.com/remotion-dev/remotion/blob/main/packages/animation-utils/src/transformation-helpers/interpolate-styles/index.tsx)
+- [`@remotion/animation-utils`](/docs/animation-utils)
diff --git a/packages/docs/docs/animation-utils/make-transform.md b/packages/docs/docs/animation-utils/make-transform.md
index 698e6db6a6..9ad5612ae1 100644
--- a/packages/docs/docs/animation-utils/make-transform.md
+++ b/packages/docs/docs/animation-utils/make-transform.md
@@ -20,6 +20,17 @@ Generates a combined CSS transform property string by applying an array of trans
- **transforms**: _Required_.
An array of transformation functions obtained from the provided utility functions.
+## Usage
+
+```ts twoslash
+import { makeTransform, rotate, translate } from "@remotion/animation-utils";
+
+const transforms = [rotate(45), translate(50, 50)];
+
+const combinedTransform = makeTransform(transforms);
+// Result: "rotate(45deg) translate(50px, 50px)"
+```
+
## Transformation Functions
| Function | Description |
@@ -46,17 +57,6 @@ Generates a combined CSS transform property string by applying an array of trans
| **translateY(y, unit = 'px')** | Translates an element along the vertical axis in 2D space. |
| **translateZ(z, unit = 'px')** | Translates an element along the z-axis in 3D space. |
-## Usage
-
-```typescript
-import { makeTransform, rotate, translate } from "@remotion/animation-utils";
-
-const transforms = [rotate(45), translate(50, 50)];
-
-const combinedTransform = makeTransform(transforms);
-// Result: "rotate(45deg) translate(50px, 50px)"
-```
-
## See also
- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/animation-utils/src/transformation-helpers/make-transform/index.ts)
diff --git a/packages/docs/docs/animation-utils/use-interpolate-styles.md b/packages/docs/docs/animation-utils/use-interpolate-styles.md
deleted file mode 100644
index 4806c9fd65..0000000000
--- a/packages/docs/docs/animation-utils/use-interpolate-styles.md
+++ /dev/null
@@ -1,63 +0,0 @@
----
-image: /generated/articles-docs-animation-utils-use-interpolate-styles.png
-title: useInterpolateStyles()
-id: use-interpolate-styles
-crumb: "@remotion/animation-utils"
----
-
-_Part of the [`@remotion/animation-utils`](/docs/animation-utils) package._
-
-This hook provides a convenient way to interpolate styles based on a specified range of frames or seconds, allowing for smooth animations between different styles.
-
-## API
-
-### `useInterpolateStyles(options: InterpolateStylesParams): Style`
-
-#### Parameters
-
-- **inputRangeInFrames**: _Optional_. An array of frame steps for interpolation.
-- **inputRangeInSeconds**: _Optional_. An array of duration steps in seconds for interpolation.
-- **outputStyles**: _Required_. An array of styles to be interpolated.
-
-### Return value
-
-- A style object representing the interpolated styles based on the current frame.
-
-### Example
-
-```tsx twoslash
-// ---cut---
-import {
- useInterpolateStyles,
- makeTransform,
- translateY,
-} from "@remotion/animation-utils";
-
-const MyComponent: React.FC = () => {
- const animatedStyles = useInterpolateStyles({
- inputRangeInFrames: [0, 30, 60],
- outputStyles: [
- { opacity: 0, transform: makeTransform([translateY(-50)]) },
- { opacity: 1, transform: makeTransform([translateY(0)]) },
- { opacity: 0, transform: makeTransform([translateY(50)]) },
- ],
- });
-
- return <div style={animatedStyles}>Animating Styles!</div>;
-};
-```
-
-### Usage Notes
-
-- Ensure that the `inputRangeInFrames` or `inputRangeInSeconds` arrays contain at least two values to facilitate interpolation between styles.
-
-- The `outputStyles` array must have the same number of elements as either `inputRangeInFrames` or `inputRangeInSeconds`. Each style in `outputStyles` corresponds to a specific frame or time interval in the input range.
-
-### Dependencies
-
-- The hook internally relies on Remotion's `useCurrentFrame` and `useVideoConfig` hooks to synchronize with the video playback.
-
-## See also
-
-- [Source code for this hook](https://github.com/remotion-dev/remotion/blob/main/packages/animation-utils/src/transformation-helpers/use-interpolate-styles/index.tsx)
-- [`@remotion/animation-utils`](/docs/animation-utils)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 2e719e6e93..c5ced3bae9 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -187,7 +187,7 @@ module.exports = {
},
items: [
"animation-utils/make-transform",
- "animation-utils/use-interpolate-styles",
+ "animation-utils/interpolate-styles",
],
},
{
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index b2e31df3c6..abb2f02a55 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -1414,10 +1414,10 @@ export const articles = [
crumb: null,
},
{
- id: "animation-utils/use-interpolate-styles",
- title: "useInterpolateStyles()",
- relativePath: "docs/animation-utils/use-interpolate-styles.md",
- compId: "articles-docs-animation-utils-use-interpolate-styles",
+ id: "animation-utils/interpolate-styles",
+ title: "interpolateStyles()",
+ relativePath: "docs/animation-utils/interpolate-styles.md",
+ compId: "articles-docs-animation-utils-interpolate-styles",
crumb: "@remotion/animation-utils",
},
{