Skip to content

🎥 Make videos programmatically with React

wipe

Jonny Burger8d92fac7928a
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 2281b691c5..e09c3999a0 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -509,5 +509,22 @@ export const wipePresentationDemo: DemoType = {
fps: 30,
id: "wipe",
autoPlay: true,
- options: [],
+ options: [
+ {
+ type: "enum",
+ name: "direction",
+ default: "from-left",
+ optional: "no",
+ values: [
+ "from-left",
+ "from-top-left",
+ "from-top",
+ "from-top-right",
+ "from-right",
+ "from-bottom-right",
+ "from-bottom",
+ "from-bottom-left",
+ ],
+ },
+ ],
};
diff --git a/packages/docs/components/transitions/previews.tsx b/packages/docs/components/transitions/previews.tsx
index 9371007c4d..d134a61f0d 100644
--- a/packages/docs/components/transitions/previews.tsx
+++ b/packages/docs/components/transitions/previews.tsx
@@ -5,6 +5,7 @@ import { springTiming, TransitionSeries } from "@remotion/transitions";
import { fade } from "@remotion/transitions/fade";
import type { SlideDirection } from "@remotion/transitions/slide";
import { slide } from "@remotion/transitions/slide";
+import type { WipeDirection } from "@remotion/transitions/wipe";
import { wipe } from "@remotion/transitions/wipe";
import React, { useEffect, useRef } from "react";
import { AbsoluteFill } from "remotion";
@@ -125,6 +126,8 @@ export const SlideDemo: React.FC<{
return <SampleTransition effect={slide({ direction })} />;
};
-export const WipeDemo: React.FC = () => {
- return <SampleTransition effect={wipe()} />;
+export const WipeDemo: React.FC<{
+ direction: WipeDirection;
+}> = ({ direction }) => {
+ return <SampleTransition effect={wipe({ direction })} />;
};
diff --git a/packages/docs/docs/transitions/presentations/slide.mdx b/packages/docs/docs/transitions/presentations/slide.mdx
index 47e3155164..4bb795a870 100644
--- a/packages/docs/docs/transitions/presentations/slide.mdx
+++ b/packages/docs/docs/transitions/presentations/slide.mdx
@@ -3,7 +3,7 @@ crumb: "@remotion/transitions - Presentations"
title: "slide()"
---
-A presentation which where the entering slide pushes out the exiting slide.
+A presentation where the entering slide pushes out the exiting slide.
<Demo type="slide" />
@@ -59,9 +59,9 @@ Takes an object with the following properties:
### `direction`
-One of `from-left`, `from-right`, `from-top`, `from-bottom`. TypeScript type:
+One of `from-left`, `from-right`, `from-top`, `from-bottom`.
-```tsx twoslash
+```tsx twoslash title="TypeScript type"
import { SlideDirection } from "@remotion/transitions/slide";
const slideDirection: SlideDirection = "from-left";
diff --git a/packages/docs/docs/transitions/presentations/wipe.mdx b/packages/docs/docs/transitions/presentations/wipe.mdx
index 329ddbb95f..0286f6cde1 100644
--- a/packages/docs/docs/transitions/presentations/wipe.mdx
+++ b/packages/docs/docs/transitions/presentations/wipe.mdx
@@ -3,4 +3,71 @@ crumb: "@remotion/transitions - Presentations"
title: "wipe()"
---
+A presentation where the entering slide slides over the exiting slide.
+
<Demo type="wipe" />
+
+## Example
+
+```tsx twoslash title="FadeTransition.tsx"
+import { AbsoluteFill } from "remotion";
+
+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>
+ );
+};
+// ---cut---
+import { linearTiming, TransitionSeries } from "@remotion/transitions";
+import { wipe } from "@remotion/transitions/wipe";
+
+const BasicTransition = () => {
+ return (
+ <TransitionSeries>
+ <TransitionSeries.Sequence durationInFrames={40}>
+ <Letter color="#0b84f3">A</Letter>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={wipe()}
+ timing={linearTiming({ durationInFrames: 30 })}
+ />
+ <TransitionSeries.Sequence durationInFrames={60}>
+ <Letter color="pink">B</Letter>
+ </TransitionSeries.Sequence>
+ </TransitionSeries>
+ );
+};
+```
+
+## API
+
+Takes an object with the following properties:
+
+### `direction`
+
+One of `from-left`, `from-top-left`, `from-top`, `from-top-right`, `from-right`, `from-bottom-right`, `from-bottom`, `from-bottom-left`.
+
+```tsx twoslash title="TypeScript type"
+import { WipeDirection } from "@remotion/transitions/wipe";
+
+const wipeDirection: WipeDirection = "from-left";
+```
+
+## See also
+
+- [Source code for this presentation](https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/slide.tsx)
+- [Presentations](/docs/transitions/presentations)
diff --git a/packages/transitions/src/presentations/wipe.tsx b/packages/transitions/src/presentations/wipe.tsx
index b5acdfa17d..a9533103cc 100644
--- a/packages/transitions/src/presentations/wipe.tsx
+++ b/packages/transitions/src/presentations/wipe.tsx
@@ -1,216 +1,214 @@
-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)}`);
+ }
};
-type WipeDirection =
- | 'from-left'
- | 'from-top-left'
- | 'from-top'
- | 'from-top-right'
- | 'from-right'
- | 'from-bottom-right'
- | 'from-bottom'
- | 'from-bottom-left';
+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;
+ 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 === 'in'
- ? presentationProgress
- : 1 - presentationProgress;
-
- const path =
- presentationDirection === 'in'
- ? 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%',
- };
- }, []);
-
- 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 === "in"
+ ? presentationProgress
+ : 1 - presentationProgress;
+
+ const path =
+ presentationDirection === "in"
+ ? 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%",
+ };
+ }, []);
+
+ 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 ?? {},
- };
+export const wipe = (props?: WipeProps): TransitionPresentation<WipeProps> => {
+ return {
+ component: WipePresentation,
+ props: props ?? {},
+ };
};