Skip to content

🎥 Make videos programmatically with React

prettier transitions package

Jonny Burger589515d24b09
diff --git a/packages/transitions/package.json b/packages/transitions/package.json
index 7366f97406..a08117f272 100644
--- a/packages/transitions/package.json
+++ b/packages/transitions/package.json
@@ -8,6 +8,7 @@
"types": "dist/index.d.ts",
"scripts": {
"lint": "eslint src --ext ts,tsx",
+ "formatting": "prettier src --check",
"watch": "tsc -w",
"build": "rollup --config rollup.config.js && tsc -d"
},
diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsx
index f11da3fabe..56746ee8d1 100644
--- a/packages/transitions/src/TransitionSeries.tsx
+++ b/packages/transitions/src/TransitionSeries.tsx
@@ -1,313 +1,313 @@
-import type { FC, PropsWithChildren } from "react";
-import { Children, useMemo } from "react";
-import type { LayoutAndStyle, SequencePropsWithoutDuration } from "remotion";
-import { Sequence, useCurrentFrame, useVideoConfig } from "remotion";
-import { slide } from "./presentations/slide.js";
-import type { TransitionSeriesTransitionProps } from "./types.js";
-import { flattenChildren } from "./flatten-children.js";
-import { validateDurationInFrames } from "./validate.js";
+import type {FC, PropsWithChildren} from 'react';
+import {Children, useMemo} from 'react';
+import type {LayoutAndStyle, SequencePropsWithoutDuration} from 'remotion';
+import {Sequence, useCurrentFrame, useVideoConfig} from 'remotion';
+import {flattenChildren} from './flatten-children.js';
+import {slide} from './presentations/slide.js';
+import type {TransitionSeriesTransitionProps} from './types.js';
+import {validateDurationInFrames} from './validate.js';
// eslint-disable-next-line react/function-component-definition
const TransitionSeriesTransition = function <
- PresentationProps extends Record<string, unknown>
+ PresentationProps extends Record<string, unknown>,
>(
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- _props: TransitionSeriesTransitionProps<PresentationProps>
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ _props: TransitionSeriesTransitionProps<PresentationProps>,
) {
- return null;
+ return null;
};
type SeriesSequenceProps = PropsWithChildren<
- {
- durationInFrames: number;
- offset?: number;
- className?: number;
- } & LayoutAndStyle &
- Pick<SequencePropsWithoutDuration, "name">
+ {
+ durationInFrames: number;
+ offset?: number;
+ className?: number;
+ } & LayoutAndStyle &
+ Pick<SequencePropsWithoutDuration, 'name'>
>;
-const SeriesSequence = ({ children }: SeriesSequenceProps) => {
- // eslint-disable-next-line react/jsx-no-useless-fragment
- return <>{children}</>;
+const SeriesSequence = ({children}: SeriesSequenceProps) => {
+ // eslint-disable-next-line react/jsx-no-useless-fragment
+ return <>{children}</>;
};
type TransitionType<PresentationProps extends Record<string, unknown>> = {
- props: TransitionSeriesTransitionProps<PresentationProps>;
- type: typeof TransitionSeriesTransition;
+ props: TransitionSeriesTransitionProps<PresentationProps>;
+ type: typeof TransitionSeriesTransition;
};
type TypeChild<PresentationProps extends Record<string, unknown>> =
- | {
- props: SeriesSequenceProps;
- type: typeof SeriesSequence;
- }
- | TransitionType<PresentationProps>
- | string;
-
-const TransitionSeriesChildren: FC<{ children: React.ReactNode }> = ({
- children,
+ | {
+ props: SeriesSequenceProps;
+ type: typeof SeriesSequence;
+ }
+ | TransitionType<PresentationProps>
+ | string;
+
+const TransitionSeriesChildren: FC<{children: React.ReactNode}> = ({
+ children,
}) => {
- const { fps } = useVideoConfig();
- const frame = useCurrentFrame();
- const childrenValue = useMemo(() => {
- let transitionOffsets = 0;
- let startFrame = 0;
- const flattedChildren = flattenChildren(children);
-
- return Children.map(flattedChildren, (child, i) => {
- const current = child as unknown as TypeChild<Record<string, unknown>>;
- if (typeof current === "string") {
- // Don't throw if it's just some accidential whitespace
- if (current.trim() === "") {
- return null;
- }
-
- throw new TypeError(
- `The <TransitionSeries /> component only accepts a list of <TransitionSeries.Sequence /> components as its children, but you passed a string "${current}"`
- );
- }
-
- const hasPrev = flattedChildren[i - 1] as TypeChild<
- Record<string, unknown>
- >;
- const nextPrev = flattedChildren[i + 1] as TypeChild<
- Record<string, unknown>
- >;
-
- const prev: TransitionType<Record<string, unknown>> | null =
- typeof hasPrev === "string" || typeof hasPrev === "undefined"
- ? null
- : hasPrev.type === TransitionSeriesTransition
- ? (hasPrev as TransitionType<Record<string, unknown>>)
- : null;
-
- const next: TransitionType<Record<string, unknown>> | null =
- typeof nextPrev === "string" || typeof nextPrev === "undefined"
- ? null
- : nextPrev.type === TransitionSeriesTransition
- ? (nextPrev as TransitionType<Record<string, unknown>>)
- : null;
-
- const prevIsTransition =
- typeof hasPrev === "string" || typeof hasPrev === "undefined"
- ? false
- : hasPrev.type === TransitionSeriesTransition;
-
- if (current.type === TransitionSeriesTransition) {
- if (prevIsTransition) {
- throw new TypeError(
- `A <TransitionSeries.Transition /> component must not be followed by another <TransitionSeries.Transition /> component (nth children = ${
- i - 1
- } and ${i})`
- );
- }
-
- return null;
- }
-
- if (current.type !== SeriesSequence) {
- throw new TypeError(
- `The <TransitionSeries /> component only accepts a list of <TransitionSeries.Sequence /> and <TransitionSeries.Transition /> components as its children, but got ${current} instead`
- );
- }
-
- const castedChildAgain = current as {
- props: SeriesSequenceProps;
- type: typeof SeriesSequence;
- };
-
- const debugInfo = `index = ${i}, duration = ${castedChildAgain.props.durationInFrames}`;
-
- if (!castedChildAgain?.props.children) {
- throw new TypeError(
- `A <TransitionSeries.Sequence /> component (${debugInfo}) was detected to not have any children. Delete it to fix this error.`
- );
- }
-
- const durationInFramesProp = castedChildAgain.props.durationInFrames;
- const {
- durationInFrames,
- children: _children,
- ...passedProps
- } = castedChildAgain.props;
- validateDurationInFrames(durationInFramesProp, {
- component: `of a <TransitionSeries.Sequence /> component`,
- allowFloats: true,
- });
- const offset = castedChildAgain.props.offset ?? 0;
- if (Number.isNaN(offset)) {
- throw new TypeError(
- `The "offset" property of a <TransitionSeries.Sequence /> must not be NaN, but got NaN (${debugInfo}).`
- );
- }
-
- if (!Number.isFinite(offset)) {
- throw new TypeError(
- `The "offset" property of a <TransitionSeries.Sequence /> must be finite, but got ${offset} (${debugInfo}).`
- );
- }
-
- if (offset % 1 !== 0) {
- throw new TypeError(
- `The "offset" property of a <TransitionSeries.Sequence /> must be finite, but got ${offset} (${debugInfo}).`
- );
- }
-
- const currentStartFrame = startFrame + offset;
-
- let duration = 0;
-
- if (prev) {
- duration = prev.props.timing.getDurationInFrames({
- fps,
- });
- transitionOffsets -= duration;
- }
-
- let actualStartFrame = currentStartFrame + transitionOffsets;
-
- startFrame += durationInFramesProp + offset;
-
- // Handle the case where the first item is a transition
- if (actualStartFrame < 0) {
- startFrame -= actualStartFrame;
- actualStartFrame = 0;
- }
-
- const inner = (
- <Sequence
- from={Math.floor(actualStartFrame)}
- durationInFrames={durationInFramesProp}
- {...passedProps}
- >
- {child}
- </Sequence>
- );
-
- const nextProgress = next
- ? next.props.timing.getProgress({
- frame:
- frame -
- actualStartFrame -
- durationInFrames +
- next.props.timing.getDurationInFrames({ fps }),
- fps,
- })
- : null;
-
- const prevProgress = prev
- ? prev.props.timing.getProgress({
- frame: frame - actualStartFrame,
- fps,
- })
- : null;
-
- if (
- next &&
- durationInFramesProp < next.props.timing.getDurationInFrames({ fps })
- ) {
- throw new Error(
- `The duration of a <TransitionSeries.Sequence /> must not be shorter than the duration of the next <TransitionSeries.Transition />. The transition is ${next.props.timing.getDurationInFrames(
- { fps }
- )} frames long, but the sequence is only ${durationInFramesProp} frames long (${debugInfo})`
- );
- }
-
- if (
- prev &&
- durationInFramesProp < prev.props.timing.getDurationInFrames({ fps })
- ) {
- throw new Error(
- `The duration of a <TransitionSeries.Sequence /> must not be shorter than the duration of the previous <TransitionSeries.Transition />. The transition is ${prev.props.timing.getDurationInFrames(
- { fps }
- )} frames long, but the sequence is only ${durationInFramesProp} frames long (${debugInfo})`
- );
- }
-
- if (next && prev && nextProgress !== null && prevProgress !== null) {
- const nextPresentation = next.props.presentation ?? slide();
- const prevPresentation = prev.props.presentation ?? slide();
-
- const UppercaseNextPresentation = nextPresentation.component;
- const UppercasePrevPresentation = prevPresentation.component;
-
- return (
- // @ts-expect-error
- <UppercaseNextPresentation
- passedProps={nextPresentation.props ?? {}}
- presentationDirection="exiting"
- presentationProgress={nextProgress}
- >
- {/**
+ const {fps} = useVideoConfig();
+ const frame = useCurrentFrame();
+ const childrenValue = useMemo(() => {
+ let transitionOffsets = 0;
+ let startFrame = 0;
+ const flattedChildren = flattenChildren(children);
+
+ return Children.map(flattedChildren, (child, i) => {
+ const current = child as unknown as TypeChild<Record<string, unknown>>;
+ if (typeof current === 'string') {
+ // Don't throw if it's just some accidential whitespace
+ if (current.trim() === '') {
+ return null;
+ }
+
+ throw new TypeError(
+ `The <TransitionSeries /> component only accepts a list of <TransitionSeries.Sequence /> components as its children, but you passed a string "${current}"`,
+ );
+ }
+
+ const hasPrev = flattedChildren[i - 1] as TypeChild<
+ Record<string, unknown>
+ >;
+ const nextPrev = flattedChildren[i + 1] as TypeChild<
+ Record<string, unknown>
+ >;
+
+ const prev: TransitionType<Record<string, unknown>> | null =
+ typeof hasPrev === 'string' || typeof hasPrev === 'undefined'
+ ? null
+ : hasPrev.type === TransitionSeriesTransition
+ ? (hasPrev as TransitionType<Record<string, unknown>>)
+ : null;
+
+ const next: TransitionType<Record<string, unknown>> | null =
+ typeof nextPrev === 'string' || typeof nextPrev === 'undefined'
+ ? null
+ : nextPrev.type === TransitionSeriesTransition
+ ? (nextPrev as TransitionType<Record<string, unknown>>)
+ : null;
+
+ const prevIsTransition =
+ typeof hasPrev === 'string' || typeof hasPrev === 'undefined'
+ ? false
+ : hasPrev.type === TransitionSeriesTransition;
+
+ if (current.type === TransitionSeriesTransition) {
+ if (prevIsTransition) {
+ throw new TypeError(
+ `A <TransitionSeries.Transition /> component must not be followed by another <TransitionSeries.Transition /> component (nth children = ${
+ i - 1
+ } and ${i})`,
+ );
+ }
+
+ return null;
+ }
+
+ if (current.type !== SeriesSequence) {
+ throw new TypeError(
+ `The <TransitionSeries /> component only accepts a list of <TransitionSeries.Sequence /> and <TransitionSeries.Transition /> components as its children, but got ${current} instead`,
+ );
+ }
+
+ const castedChildAgain = current as {
+ props: SeriesSequenceProps;
+ type: typeof SeriesSequence;
+ };
+
+ const debugInfo = `index = ${i}, duration = ${castedChildAgain.props.durationInFrames}`;
+
+ if (!castedChildAgain?.props.children) {
+ throw new TypeError(
+ `A <TransitionSeries.Sequence /> component (${debugInfo}) was detected to not have any children. Delete it to fix this error.`,
+ );
+ }
+
+ const durationInFramesProp = castedChildAgain.props.durationInFrames;
+ const {
+ durationInFrames,
+ children: _children,
+ ...passedProps
+ } = castedChildAgain.props;
+ validateDurationInFrames(durationInFramesProp, {
+ component: `of a <TransitionSeries.Sequence /> component`,
+ allowFloats: true,
+ });
+ const offset = castedChildAgain.props.offset ?? 0;
+ if (Number.isNaN(offset)) {
+ throw new TypeError(
+ `The "offset" property of a <TransitionSeries.Sequence /> must not be NaN, but got NaN (${debugInfo}).`,
+ );
+ }
+
+ if (!Number.isFinite(offset)) {
+ throw new TypeError(
+ `The "offset" property of a <TransitionSeries.Sequence /> must be finite, but got ${offset} (${debugInfo}).`,
+ );
+ }
+
+ if (offset % 1 !== 0) {
+ throw new TypeError(
+ `The "offset" property of a <TransitionSeries.Sequence /> must be finite, but got ${offset} (${debugInfo}).`,
+ );
+ }
+
+ const currentStartFrame = startFrame + offset;
+
+ let duration = 0;
+
+ if (prev) {
+ duration = prev.props.timing.getDurationInFrames({
+ fps,
+ });
+ transitionOffsets -= duration;
+ }
+
+ let actualStartFrame = currentStartFrame + transitionOffsets;
+
+ startFrame += durationInFramesProp + offset;
+
+ // Handle the case where the first item is a transition
+ if (actualStartFrame < 0) {
+ startFrame -= actualStartFrame;
+ actualStartFrame = 0;
+ }
+
+ const inner = (
+ <Sequence
+ from={Math.floor(actualStartFrame)}
+ durationInFrames={durationInFramesProp}
+ {...passedProps}
+ >
+ {child}
+ </Sequence>
+ );
+
+ const nextProgress = next
+ ? next.props.timing.getProgress({
+ frame:
+ frame -
+ actualStartFrame -
+ durationInFrames +
+ next.props.timing.getDurationInFrames({fps}),
+ fps,
+ })
+ : null;
+
+ const prevProgress = prev
+ ? prev.props.timing.getProgress({
+ frame: frame - actualStartFrame,
+ fps,
+ })
+ : null;
+
+ if (
+ next &&
+ durationInFramesProp < next.props.timing.getDurationInFrames({fps})
+ ) {
+ throw new Error(
+ `The duration of a <TransitionSeries.Sequence /> must not be shorter than the duration of the next <TransitionSeries.Transition />. The transition is ${next.props.timing.getDurationInFrames(
+ {fps},
+ )} frames long, but the sequence is only ${durationInFramesProp} frames long (${debugInfo})`,
+ );
+ }
+
+ if (
+ prev &&
+ durationInFramesProp < prev.props.timing.getDurationInFrames({fps})
+ ) {
+ throw new Error(
+ `The duration of a <TransitionSeries.Sequence /> must not be shorter than the duration of the previous <TransitionSeries.Transition />. The transition is ${prev.props.timing.getDurationInFrames(
+ {fps},
+ )} frames long, but the sequence is only ${durationInFramesProp} frames long (${debugInfo})`,
+ );
+ }
+
+ if (next && prev && nextProgress !== null && prevProgress !== null) {
+ const nextPresentation = next.props.presentation ?? slide();
+ const prevPresentation = prev.props.presentation ?? slide();
+
+ const UppercaseNextPresentation = nextPresentation.component;
+ const UppercasePrevPresentation = prevPresentation.component;
+
+ return (
+ // @ts-expect-error
+ <UppercaseNextPresentation
+ passedProps={nextPresentation.props ?? {}}
+ presentationDirection="exiting"
+ presentationProgress={nextProgress}
+ >
+ {/**
// @ts-expect-error */}
- <UppercasePrevPresentation
- passedProps={prevPresentation.props ?? {}}
- presentationDirection="entering"
- presentationProgress={prevProgress}
- >
- {inner}
- </UppercasePrevPresentation>
- </UppercaseNextPresentation>
- );
- }
-
- if (prevProgress !== null && prev) {
- const prevPresentation = prev.props.presentation ?? slide();
-
- const UppercasePrevPresentation = prevPresentation.component;
-
- return (
- // @ts-expect-error
- <UppercasePrevPresentation
- passedProps={prevPresentation.props ?? {}}
- presentationDirection="entering"
- presentationProgress={prevProgress}
- >
- {inner}
- </UppercasePrevPresentation>
- );
- }
-
- if (nextProgress !== null && next) {
- const nextPresentation = next.props.presentation ?? slide();
-
- const UppercaseNextPresentation = nextPresentation.component;
-
- return (
- // @ts-expect-error
- <UppercaseNextPresentation
- passedProps={nextPresentation.props ?? {}}
- presentationDirection="exiting"
- presentationProgress={nextProgress}
- >
- {inner}
- </UppercaseNextPresentation>
- );
- }
-
- return inner;
- });
- }, [children, fps, frame]);
-
- // eslint-disable-next-line react/jsx-no-useless-fragment
- return <>{childrenValue}</>;
+ <UppercasePrevPresentation
+ passedProps={prevPresentation.props ?? {}}
+ presentationDirection="entering"
+ presentationProgress={prevProgress}
+ >
+ {inner}
+ </UppercasePrevPresentation>
+ </UppercaseNextPresentation>
+ );
+ }
+
+ if (prevProgress !== null && prev) {
+ const prevPresentation = prev.props.presentation ?? slide();
+
+ const UppercasePrevPresentation = prevPresentation.component;
+
+ return (
+ // @ts-expect-error
+ <UppercasePrevPresentation
+ passedProps={prevPresentation.props ?? {}}
+ presentationDirection="entering"
+ presentationProgress={prevProgress}
+ >
+ {inner}
+ </UppercasePrevPresentation>
+ );
+ }
+
+ if (nextProgress !== null && next) {
+ const nextPresentation = next.props.presentation ?? slide();
+
+ const UppercaseNextPresentation = nextPresentation.component;
+
+ return (
+ // @ts-expect-error
+ <UppercaseNextPresentation
+ passedProps={nextPresentation.props ?? {}}
+ presentationDirection="exiting"
+ presentationProgress={nextProgress}
+ >
+ {inner}
+ </UppercaseNextPresentation>
+ );
+ }
+
+ return inner;
+ });
+ }, [children, fps, frame]);
+
+ // eslint-disable-next-line react/jsx-no-useless-fragment
+ return <>{childrenValue}</>;
};
const TransitionSeries: FC<SequencePropsWithoutDuration> & {
- Sequence: typeof SeriesSequence;
- Transition: typeof TransitionSeriesTransition;
-} = ({ children, ...otherProps }) => {
- const frame = useCurrentFrame();
- const showInTimeline = frame < (otherProps.from ?? 0);
-
- return (
- <Sequence showInTimeline={showInTimeline} {...otherProps}>
- <TransitionSeriesChildren>{children}</TransitionSeriesChildren>
- </Sequence>
- );
+ Sequence: typeof SeriesSequence;
+ Transition: typeof TransitionSeriesTransition;
+} = ({children, ...otherProps}) => {
+ const frame = useCurrentFrame();
+ const showInTimeline = frame < (otherProps.from ?? 0);
+
+ return (
+ <Sequence showInTimeline={showInTimeline} {...otherProps}>
+ <TransitionSeriesChildren>{children}</TransitionSeriesChildren>
+ </Sequence>
+ );
};
TransitionSeries.Sequence = SeriesSequence;
TransitionSeries.Transition = TransitionSeriesTransition;
-export { TransitionSeries };
+export {TransitionSeries};
diff --git a/packages/transitions/src/flatten-children.ts b/packages/transitions/src/flatten-children.ts
index 90c989c849..21f8ee074a 100644
--- a/packages/transitions/src/flatten-children.ts
+++ b/packages/transitions/src/flatten-children.ts
@@ -1,21 +1,21 @@
-import type { PropsWithChildren } from "react";
-import React from "react";
+import type {PropsWithChildren} from 'react';
+import React from 'react';
type ReactChildArray = ReturnType<typeof React.Children.toArray>;
export const flattenChildren = (children: React.ReactNode): ReactChildArray => {
- const childrenArray = React.Children.toArray(children);
- return childrenArray.reduce((flatChildren: ReactChildArray, child) => {
- if ((child as React.ReactElement<unknown>).type === React.Fragment) {
- return flatChildren.concat(
- flattenChildren(
- (child as React.ReactElement<PropsWithChildren<unknown>>).props
- .children
- )
- );
- }
+ const childrenArray = React.Children.toArray(children);
+ return childrenArray.reduce((flatChildren: ReactChildArray, child) => {
+ if ((child as React.ReactElement<unknown>).type === React.Fragment) {
+ return flatChildren.concat(
+ flattenChildren(
+ (child as React.ReactElement<PropsWithChildren<unknown>>).props
+ .children,
+ ),
+ );
+ }
- flatChildren.push(child);
- return flatChildren;
- }, []);
+ flatChildren.push(child);
+ return flatChildren;
+ }, []);
};
diff --git a/packages/transitions/src/index.ts b/packages/transitions/src/index.ts
index 33fa7eeb6c..e4ef777429 100644
--- a/packages/transitions/src/index.ts
+++ b/packages/transitions/src/index.ts
@@ -1,10 +1,10 @@
// Timings
-export { springTiming } from './timings/spring-timing.js';
-export { linearTiming } from "./timings/linear-timing.js";
+export {linearTiming} from './timings/linear-timing.js';
+export {springTiming} from './timings/spring-timing.js';
// Component
-export { TransitionSeries } from "./TransitionSeries.js";
+export {TransitionSeries} from './TransitionSeries.js';
export {
- TransitionTiming,
- TransitionPresentation,
- TransitionPresentationComponentProps,
-} from "./types.js";
+ TransitionPresentation,
+ TransitionPresentationComponentProps,
+ TransitionTiming,
+} from './types.js';
diff --git a/packages/transitions/src/presentations/fade.tsx b/packages/transitions/src/presentations/fade.tsx
index d05b832d69..4feef86891 100644
--- a/packages/transitions/src/presentations/fade.tsx
+++ b/packages/transitions/src/presentations/fade.tsx
@@ -1,32 +1,32 @@
-import { useMemo } from "react";
-import { AbsoluteFill } from "remotion";
+import {useMemo} from 'react';
+import {AbsoluteFill} from 'remotion';
import type {
- TransitionPresentation,
- TransitionPresentationComponentProps,
-} from "../types.js";
+ TransitionPresentation,
+ TransitionPresentationComponentProps,
+} from '../types.js';
// No options: https://www.totaltypescript.com/the-empty-object-type-in-typescript
-type FadeProps = Record<string, never>;
+export type FadeProps = Record<string, never>;
const FadePresentation: React.FC<
- TransitionPresentationComponentProps<FadeProps>
-> = ({ children, presentationDirection, presentationProgress }) => {
- const style: React.CSSProperties = useMemo(() => {
- return {
- opacity: presentationDirection === "entering" ? presentationProgress : 1,
- };
- }, [presentationDirection, presentationProgress]);
+ TransitionPresentationComponentProps<FadeProps>
+> = ({children, presentationDirection, presentationProgress}) => {
+ const style: React.CSSProperties = useMemo(() => {
+ return {
+ opacity: presentationDirection === 'entering' ? presentationProgress : 1,
+ };
+ }, [presentationDirection, presentationProgress]);
- return (
- <AbsoluteFill>
- <AbsoluteFill style={style}>{children}</AbsoluteFill>
- </AbsoluteFill>
- );
+ return (
+ <AbsoluteFill>
+ <AbsoluteFill style={style}>{children}</AbsoluteFill>
+ </AbsoluteFill>
+ );
};
export const fade = (props?: FadeProps): TransitionPresentation<FadeProps> => {
- return {
- component: FadePresentation,
- props: props ?? {},
- };
+ return {
+ component: FadePresentation,
+ props: props ?? {},
+ };
};
diff --git a/packages/transitions/src/presentations/flip.tsx b/packages/transitions/src/presentations/flip.tsx
index 0eb585c4e9..019544fdd1 100644
--- a/packages/transitions/src/presentations/flip.tsx
+++ b/packages/transitions/src/presentations/flip.tsx
@@ -11,14 +11,12 @@ export type FlipDirection =
| 'from-top'
| 'from-bottom';
-type FlipPresentationProps = {
+export type FlipProps = {
direction?: FlipDirection;
perspective?: number;
};
-const Flip: React.FC<
- TransitionPresentationComponentProps<FlipPresentationProps>
-> = ({
+const Flip: React.FC<TransitionPresentationComponentProps<FlipProps>> = ({
children,
presentationDirection,
presentationProgress,
@@ -64,8 +62,6 @@ const Flip: React.FC<
);
};
-export const flip = (
- props?: FlipPresentationProps,
-): TransitionPresentation<FlipPresentationProps> => {
+export const flip = (props?: FlipProps): TransitionPresentation<FlipProps> => {
return {component: Flip, props: props ?? {}};
};
diff --git a/packages/transitions/src/presentations/slide.tsx b/packages/transitions/src/presentations/slide.tsx
index 9147f7983b..7b40e412b6 100644
--- a/packages/transitions/src/presentations/slide.tsx
+++ b/packages/transitions/src/presentations/slide.tsx
@@ -1,96 +1,96 @@
-import React, { useMemo } from "react";
-import { AbsoluteFill } from "remotion";
+import React, {useMemo} from 'react';
+import {AbsoluteFill} from 'remotion';
import type {
- TransitionPresentation,
- TransitionPresentationComponentProps,
-} from "../types.js";
+ TransitionPresentation,
+ TransitionPresentationComponentProps,
+} from '../types.js';
export type SlideDirection =
- | "from-left"
- | "from-top"
- | "from-right"
- | "from-bottom";
+ | 'from-left'
+ | 'from-top'
+ | 'from-right'
+ | 'from-bottom';
-type SlideProps = {
- direction?: SlideDirection;
+export type SlideProps = {
+ direction?: SlideDirection;
};
const SlidePresentation: React.FC<
- TransitionPresentationComponentProps<SlideProps>
+ TransitionPresentationComponentProps<SlideProps>
> = ({
- children,
- presentationProgress,
- presentationDirection,
- passedProps: { direction = "from-left" },
+ children,
+ presentationProgress,
+ presentationDirection,
+ passedProps: {direction = 'from-left'},
}) => {
- const directionStyle = useMemo((): React.CSSProperties => {
- if (presentationDirection === "exiting") {
- switch (direction) {
- case "from-left":
- return {
- transform: `translateX(${presentationProgress * 100}%)`,
- };
- case "from-right":
- return {
- transform: `translateX(-${presentationProgress * 100}%)`,
- };
- case "from-top":
- return {
- transform: `translateY(${presentationProgress * 100}%)`,
- };
- case "from-bottom":
- return {
- transform: `translateY(-${presentationProgress * 100}%)`,
- };
- default:
- throw new Error(`Invalid direction: ${direction}`);
- }
- }
+ const directionStyle = useMemo((): React.CSSProperties => {
+ if (presentationDirection === 'exiting') {
+ switch (direction) {
+ case 'from-left':
+ return {
+ transform: `translateX(${presentationProgress * 100}%)`,
+ };
+ case 'from-right':
+ return {
+ transform: `translateX(-${presentationProgress * 100}%)`,
+ };
+ case 'from-top':
+ return {
+ transform: `translateY(${presentationProgress * 100}%)`,
+ };
+ case 'from-bottom':
+ return {
+ transform: `translateY(-${presentationProgress * 100}%)`,
+ };
+ default:
+ throw new Error(`Invalid direction: ${direction}`);
+ }
+ }
- switch (direction) {
- case "from-left":
- return {
- transform: `translateX(${-100 + presentationProgress * 100}%)`,
- };
- case "from-right":
- return {
- transform: `translateX(${100 - presentationProgress * 100}%)`,
- };
- case "from-top":
- return {
- transform: `translateY(${-100 + presentationProgress * 100}%)`,
- };
- case "from-bottom":
- return {
- transform: `translateY(${100 - presentationProgress * 100}%)`,
- };
- default:
- throw new Error(`Invalid direction: ${direction}`);
- }
- }, [presentationDirection, presentationProgress, direction]);
+ switch (direction) {
+ case 'from-left':
+ return {
+ transform: `translateX(${-100 + presentationProgress * 100}%)`,
+ };
+ case 'from-right':
+ return {
+ transform: `translateX(${100 - presentationProgress * 100}%)`,
+ };
+ case 'from-top':
+ return {
+ transform: `translateY(${-100 + presentationProgress * 100}%)`,
+ };
+ case 'from-bottom':
+ return {
+ transform: `translateY(${100 - presentationProgress * 100}%)`,
+ };
+ default:
+ throw new Error(`Invalid direction: ${direction}`);
+ }
+ }, [presentationDirection, presentationProgress, direction]);
- const style: React.CSSProperties = useMemo(() => {
- return {
- width: "100%",
- height: "100%",
- justifyContent: "center",
- alignItems: "center",
- ...directionStyle,
- };
- }, [directionStyle]);
+ const style: React.CSSProperties = useMemo(() => {
+ return {
+ width: '100%',
+ height: '100%',
+ justifyContent: 'center',
+ alignItems: 'center',
+ ...directionStyle,
+ };
+ }, [directionStyle]);
- return (
- <AbsoluteFill>
- <AbsoluteFill style={style}>{children}</AbsoluteFill>
- </AbsoluteFill>
- );
+ return (
+ <AbsoluteFill>
+ <AbsoluteFill style={style}>{children}</AbsoluteFill>
+ </AbsoluteFill>
+ );
};
export const slide = (
- props?: SlideProps
+ props?: SlideProps,
): TransitionPresentation<SlideProps> => {
- return {
- component: SlidePresentation,
- props: props ?? {},
- };
+ return {
+ component: SlidePresentation,
+ props: props ?? {},
+ };
};
diff --git a/packages/transitions/src/presentations/wipe.tsx b/packages/transitions/src/presentations/wipe.tsx
index f93ab5a5be..a9c97e91ab 100644
--- a/packages/transitions/src/presentations/wipe.tsx
+++ b/packages/transitions/src/presentations/wipe.tsx
@@ -1,215 +1,215 @@
-import React, { useMemo, useState } from "react";
-import { AbsoluteFill, random } from "remotion";
+import React, {useMemo, useState} from 'react';
+import {AbsoluteFill, random} from 'remotion';
import type {
- TransitionPresentation,
- TransitionPresentationComponentProps,
-} from "../types.js";
+ TransitionPresentation,
+ TransitionPresentationComponentProps,
+} from '../types.js';
const makePathIn = (progress: number, direction: WipeDirection) => {
- switch (direction) {
- case "from-left":
- return `
+ switch (direction) {
+ case 'from-left':
+ return `
M 0 0
L ${progress} 0
L ${progress} 1
L 0 1
Z`;
- case "from-top-left":
- return `
+ case 'from-top-left':
+ return `
M 0 0
L ${progress * 2} 0
L 0 ${progress * 2}
Z`;
- case "from-top":
- return `
+ case 'from-top':
+ return `
M 0 0
L 1 0
L 1 ${progress}
L 0 ${progress}
Z`;
- case "from-top-right":
- return `
+ case 'from-top-right':
+ return `
M 1 0
L ${1 - progress * 2} 0
L 1 ${progress * 2}
Z`;
- case "from-right":
- return `
+ case 'from-right':
+ return `
M 1 0
L 1 1
L ${1 - progress} 1
L ${1 - progress} 0
Z`;
- case "from-bottom-right":
- return `
+ case 'from-bottom-right':
+ return `
M 1 1
L ${1 - progress * 2} 1
L 1 ${1 - progress * 2}
Z`;
- case "from-bottom":
- return `
+ case 'from-bottom':
+ return `
M 0 1
L 1 1
L 1 ${1 - progress}
L 0 ${1 - progress}
Z`;
- case "from-bottom-left":
- return `
+ case 'from-bottom-left':
+ return `
M 0 1
L 0 ${1 - progress * 2}
L ${progress * 2} 1
Z`;
- default:
- throw new Error(`Unknown direction ${JSON.stringify(direction)}`);
- }
+ default:
+ throw new Error(`Unknown direction ${JSON.stringify(direction)}`);
+ }
};
export type WipeDirection =
- | "from-left"
- | "from-top-left"
- | "from-top"
- | "from-top-right"
- | "from-right"
- | "from-bottom-right"
- | "from-bottom"
- | "from-bottom-left";
-
-type WipeProps = {
- direction?: WipeDirection;
+ | 'from-left'
+ | 'from-top-left'
+ | 'from-top'
+ | 'from-top-right'
+ | 'from-right'
+ | 'from-bottom-right'
+ | 'from-bottom'
+ | 'from-bottom-left';
+
+export type WipeProps = {
+ direction?: WipeDirection;
};
const makePathOut = (progress: number, direction: WipeDirection) => {
- switch (direction) {
- case "from-left":
- return `
+ switch (direction) {
+ case 'from-left':
+ return `
M 1 1
L ${1 - progress} 1
L ${1 - progress} 0
L 1 0
Z`;
- case "from-top-left":
- return `
+ case 'from-top-left':
+ return `
M 1 1
L ${1 - 2 * progress} 1
L 1 ${1 - 2 * progress}
Z`;
- case "from-top":
- return `
+ case 'from-top':
+ return `
M 1 1
L 0 1
L 0 ${1 - progress}
L 1 ${1 - progress}
Z`;
- case "from-top-right":
- return `
+ case 'from-top-right':
+ return `
M 0 1
L ${progress * 2} 1
L 0 ${1 - progress * 2}
Z`;
- case "from-right":
- return `
+ case 'from-right':
+ return `
M 0 0
L ${progress} 0
L ${progress} 1
L 0 1
Z`;
- case "from-bottom-right":
- return `
+ case 'from-bottom-right':
+ return `
M 0 0
L ${progress * 2} 0
L 0 ${progress * 2}
Z`;
- case "from-bottom":
- return `
+ case 'from-bottom':
+ return `
M 1 0
L 0 0
L 0 ${progress}
L 1 ${progress}
Z`;
- case "from-bottom-left":
- return `
+ case 'from-bottom-left':
+ return `
M 1 0
L ${1 - progress * 2} 0
L 1 ${progress * 2}
Z`;
- default:
- throw new Error(`Unknown direction ${JSON.stringify(direction)}`);
- }
+ default:
+ throw new Error(`Unknown direction ${JSON.stringify(direction)}`);
+ }
};
const WipePresentation: React.FC<
- TransitionPresentationComponentProps<WipeProps>
+ TransitionPresentationComponentProps<WipeProps>
> = ({
- children,
- presentationProgress,
- presentationDirection,
- passedProps: { direction = "from-left" },
+ children,
+ presentationProgress,
+ presentationDirection,
+ passedProps: {direction = 'from-left'},
}) => {
- const [clipId] = useState(() => String(random(null)));
-
- const progressInDirection =
- presentationDirection === "entering"
- ? presentationProgress
- : 1 - presentationProgress;
-
- const path =
- presentationDirection === "entering"
- ? makePathIn(progressInDirection, direction)
- : makePathOut(progressInDirection, direction);
-
- const style: React.CSSProperties = useMemo(() => {
- return {
- width: "100%",
- height: "100%",
- justifyContent: "center",
- alignItems: "center",
- clipPath: `url(#${clipId})`,
- };
- }, [clipId]);
-
- const svgStyle: React.CSSProperties = useMemo(() => {
- return {
- width: "100%",
- height: "100%",
- pointerEvents: "none",
- };
- }, []);
-
- return (
- <AbsoluteFill>
- <AbsoluteFill style={style}>{children}</AbsoluteFill>
- <AbsoluteFill>
- <svg viewBox="0 0 1 1" style={svgStyle}>
- <defs>
- <clipPath id={clipId} clipPathUnits="objectBoundingBox">
- <path d={path} fill="black" />
- </clipPath>
- </defs>
- </svg>
- </AbsoluteFill>
- </AbsoluteFill>
- );
+ const [clipId] = useState(() => String(random(null)));
+
+ const progressInDirection =
+ presentationDirection === 'entering'
+ ? presentationProgress
+ : 1 - presentationProgress;
+
+ const path =
+ presentationDirection === 'entering'
+ ? makePathIn(progressInDirection, direction)
+ : makePathOut(progressInDirection, direction);
+
+ const style: React.CSSProperties = useMemo(() => {
+ return {
+ width: '100%',
+ height: '100%',
+ justifyContent: 'center',
+ alignItems: 'center',
+ clipPath: `url(#${clipId})`,
+ };
+ }, [clipId]);
+
+ const svgStyle: React.CSSProperties = useMemo(() => {
+ return {
+ width: '100%',
+ height: '100%',
+ pointerEvents: 'none',
+ };
+ }, []);
+
+ return (
+ <AbsoluteFill>
+ <AbsoluteFill style={style}>{children}</AbsoluteFill>
+ <AbsoluteFill>
+ <svg viewBox="0 0 1 1" style={svgStyle}>
+ <defs>
+ <clipPath id={clipId} clipPathUnits="objectBoundingBox">
+ <path d={path} fill="black" />
+ </clipPath>
+ </defs>
+ </svg>
+ </AbsoluteFill>
+ </AbsoluteFill>
+ );
};
export const wipe = (props?: WipeProps): TransitionPresentation<WipeProps> => {
- return {
- component: WipePresentation,
- props: props ?? {},
- };
+ return {
+ component: WipePresentation,
+ props: props ?? {},
+ };
};
diff --git a/packages/transitions/src/test/transitions.test.tsx b/packages/transitions/src/test/transitions.test.tsx
index 69d757f48c..b8591d217b 100644
--- a/packages/transitions/src/test/transitions.test.tsx
+++ b/packages/transitions/src/test/transitions.test.tsx
@@ -1,76 +1,76 @@
/**
* @vitest-environment jsdom
*/
-import { expect, test } from "vitest";
-import { renderToString } from "react-dom/server";
-import { TransitionSeries } from "../TransitionSeries.js";
-import { AbsoluteFill, Internals } from "remotion";
-import { fade } from "../presentations/fade.js";
-import { linearTiming } from "../timings/linear-timing.js";
import {
- makeMockCompositionManagerContext,
- makeTimelineContext,
-} from "@remotion/test-utils";
+ makeMockCompositionManagerContext,
+ makeTimelineContext,
+} from '@remotion/test-utils';
+import {renderToString} from 'react-dom/server';
+import {AbsoluteFill, Internals} from 'remotion';
+import {expect, test} from 'vitest';
+import {fade} from '../presentations/fade.js';
+import {linearTiming} from '../timings/linear-timing.js';
+import {TransitionSeries} from '../TransitionSeries.js';
const renderForFrame = (frame: number, markup: React.ReactNode) => {
- return renderToString(
- <Internals.CanUseRemotionHooksProvider>
- <Internals.CompositionManager.Provider
- value={makeMockCompositionManagerContext()}
- >
- <Internals.Timeline.TimelineContext.Provider
- value={makeTimelineContext(frame)}
- >
- {markup}
- </Internals.Timeline.TimelineContext.Provider>
- </Internals.CompositionManager.Provider>
- </Internals.CanUseRemotionHooksProvider>
- );
+ return renderToString(
+ <Internals.CanUseRemotionHooksProvider>
+ <Internals.CompositionManager.Provider
+ value={makeMockCompositionManagerContext()}
+ >
+ <Internals.Timeline.TimelineContext.Provider
+ value={makeTimelineContext(frame)}
+ >
+ {markup}
+ </Internals.Timeline.TimelineContext.Provider>
+ </Internals.CompositionManager.Provider>
+ </Internals.CanUseRemotionHooksProvider>,
+ );
};
const Letter: React.FC<{
- children: React.ReactNode;
- color: string;
-}> = ({ children, color }) => {
- return (
- <AbsoluteFill
- style={{
- backgroundColor: color,
- opacity: 0.9,
- justifyContent: "center",
- alignItems: "center",
- fontSize: 200,
- color: "white",
- }}
- >
- {children}
- </AbsoluteFill>
- );
+ children: React.ReactNode;
+ color: string;
+}> = ({children, color}) => {
+ return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: color,
+ opacity: 0.9,
+ justifyContent: 'center',
+ alignItems: 'center',
+ fontSize: 200,
+ color: 'white',
+ }}
+ >
+ {children}
+ </AbsoluteFill>
+ );
};
-test("Should throw if two transitions in a row", () => {
- expect(() => {
- return renderForFrame(
- 10,
- <TransitionSeries>
- <TransitionSeries.Sequence durationInFrames={60}>
- <Letter color="green">C</Letter>
- </TransitionSeries.Sequence>
- <TransitionSeries.Transition
- presentation={fade({})}
- timing={linearTiming({
- durationInFrames: 40,
- })}
- />
- <TransitionSeries.Transition
- presentation={fade({})}
- timing={linearTiming({
- durationInFrames: 40,
- })}
- />
- </TransitionSeries>
- );
- }).toThrow(
- "A <TransitionSeries.Transition /> component must not be followed by another <TransitionSeries.Transition /> component (nth children = 1 and 2)"
- );
+test('Should throw if two transitions in a row', () => {
+ expect(() => {
+ return renderForFrame(
+ 10,
+ <TransitionSeries>
+ <TransitionSeries.Sequence durationInFrames={60}>
+ <Letter color="green">C</Letter>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={fade({})}
+ timing={linearTiming({
+ durationInFrames: 40,
+ })}
+ />
+ <TransitionSeries.Transition
+ presentation={fade({})}
+ timing={linearTiming({
+ durationInFrames: 40,
+ })}
+ />
+ </TransitionSeries>,
+ );
+ }).toThrow(
+ 'A <TransitionSeries.Transition /> component must not be followed by another <TransitionSeries.Transition /> component (nth children = 1 and 2)',
+ );
});
diff --git a/packages/transitions/src/timings/spring-timing.ts b/packages/transitions/src/timings/spring-timing.ts
index 0c11f1cf4a..66a632d55e 100644
--- a/packages/transitions/src/timings/spring-timing.ts
+++ b/packages/transitions/src/timings/spring-timing.ts
@@ -1,45 +1,44 @@
-import type { SpringConfig } from "remotion";
-import { measureSpring, spring } from "remotion";
-import type { TransitionTiming } from "../types.js";
+import type {SpringConfig} from 'remotion';
+import {measureSpring, spring} from 'remotion';
+import type {TransitionTiming} from '../types.js';
const springWithInvalidArgumentRejection: typeof spring = (args) => {
- if (args.to || args.from) {
- throw new Error(
- "to / from values are not supported by springWithRoundUpIfThreshold"
- );
- }
+ if (args.to || args.from) {
+ throw new Error(
+ 'to / from values are not supported by springWithRoundUpIfThreshold',
+ );
+ }
- return spring(args);
+ return spring(args);
};
export const springTiming = (
- options: {
- config?: Partial<SpringConfig>;
- durationInFrames?: number;
- durationRestThreshold?: number;
- } = {}
+ options: {
+ config?: Partial<SpringConfig>;
+ durationInFrames?: number;
+ durationRestThreshold?: number;
+ } = {},
): TransitionTiming => {
- return {
- getDurationInFrames: ({ fps }) => {
- if (options.durationInFrames) {
- return options.durationInFrames;
- }
+ return {
+ getDurationInFrames: ({fps}) => {
+ if (options.durationInFrames) {
+ return options.durationInFrames;
+ }
- return measureSpring({
- config: options.config,
- threshold: options.durationRestThreshold,
- fps,
- });
- },
- getProgress: ({ fps, frame }) => {
- return springWithInvalidArgumentRejection({
- fps,
- frame,
- config: options.config,
- durationInFrames: options.durationInFrames,
- durationRestThreshold: options.durationRestThreshold,
- });
- },
- };
+ return measureSpring({
+ config: options.config,
+ threshold: options.durationRestThreshold,
+ fps,
+ });
+ },
+ getProgress: ({fps, frame}) => {
+ return springWithInvalidArgumentRejection({
+ fps,
+ frame,
+ config: options.config,
+ durationInFrames: options.durationInFrames,
+ durationRestThreshold: options.durationRestThreshold,
+ });
+ },
+ };
};
-
diff --git a/packages/transitions/src/types.ts b/packages/transitions/src/types.ts
index fdb0582eef..e09f75dd5c 100644
--- a/packages/transitions/src/types.ts
+++ b/packages/transitions/src/types.ts
@@ -1,35 +1,35 @@
-import type { ComponentType } from "react";
+import type {ComponentType} from 'react';
-export type PresentationDirection = "entering" | "exiting";
+export type PresentationDirection = 'entering' | 'exiting';
export type TransitionTiming = {
- getDurationInFrames: (options: { fps: number }) => number;
- getProgress: (options: { frame: number; fps: number }) => number;
+ getDurationInFrames: (options: {fps: number}) => number;
+ getProgress: (options: {frame: number; fps: number}) => number;
};
export type TransitionSeriesTransitionProps<
- PresentationProps extends Record<string, unknown>
+ PresentationProps extends Record<string, unknown>,
> = {
- timing: TransitionTiming;
- presentation?: TransitionPresentation<PresentationProps>;
+ timing: TransitionTiming;
+ presentation?: TransitionPresentation<PresentationProps>;
};
type LooseComponentType<T> = ComponentType<T> | ((props: T) => React.ReactNode);
export type TransitionPresentation<
- PresentationProps extends Record<string, unknown>
+ PresentationProps extends Record<string, unknown>,
> = {
- component: LooseComponentType<
- TransitionPresentationComponentProps<PresentationProps>
- >;
- props: PresentationProps;
+ component: LooseComponentType<
+ TransitionPresentationComponentProps<PresentationProps>
+ >;
+ props: PresentationProps;
};
export type TransitionPresentationComponentProps<
- PresentationProps extends Record<string, unknown>
+ PresentationProps extends Record<string, unknown>,
> = {
- presentationProgress: number;
- children: React.ReactNode;
- presentationDirection: PresentationDirection;
- passedProps: PresentationProps;
+ presentationProgress: number;
+ children: React.ReactNode;
+ presentationDirection: PresentationDirection;
+ passedProps: PresentationProps;
};
diff --git a/packages/transitions/src/validate.ts b/packages/transitions/src/validate.ts
index 1f3ad56fd3..4806766e6b 100644
--- a/packages/transitions/src/validate.ts
+++ b/packages/transitions/src/validate.ts
@@ -1,5 +1,5 @@
/* eslint-disable prefer-destructuring */
-import { Internals } from "remotion";
+import {Internals} from 'remotion';
export const validateDurationInFrames: typeof Internals.validateDurationInFrames =
- Internals.validateDurationInFrames;
+ Internals.validateDurationInFrames;