🎥 Make videos programmatically with React
wipe
Jonny Burger8d92fac7928a
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.tsindex 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.tsxindex 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.mdxindex 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.mdxindex 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.tsxindex 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 0L ${progress} 0L ${progress} 1L 0 1Z`;- case 'from-top-left':- return `+ case "from-top-left":+ return `M 0 0L ${progress * 2} 0L 0 ${progress * 2}Z`;- case 'from-top':- return `+ case "from-top":+ return `M 0 0L 1 0L 1 ${progress}L 0 ${progress}Z`;- case 'from-top-right':- return `+ case "from-top-right":+ return `M 1 0L ${1 - progress * 2} 0L 1 ${progress * 2}Z`;- case 'from-right':- return `+ case "from-right":+ return `M 1 0L 1 1L ${1 - progress} 1L ${1 - progress} 0Z`;- case 'from-bottom-right':- return `+ case "from-bottom-right":+ return `M 1 1L ${1 - progress * 2} 1L 1 ${1 - progress * 2}Z`;- case 'from-bottom':- return `+ case "from-bottom":+ return `M 0 1L 1 1L 1 ${1 - progress}L 0 ${1 - progress}Z`;- case 'from-bottom-left':- return `+ case "from-bottom-left":+ return `M 0 1L 0 ${1 - progress * 2}L ${progress * 2} 1Z`;- 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 1L ${1 - progress} 1L ${1 - progress} 0L 1 0Z`;- case 'from-top-left':- return `+ case "from-top-left":+ return `M 1 1L ${1 - 2 * progress} 1L 1 ${1 - 2 * progress}Z`;- case 'from-top':- return `+ case "from-top":+ return `M 1 1L 0 1L 0 ${1 - progress}L 1 ${1 - progress}Z`;- case 'from-top-right':- return `+ case "from-top-right":+ return `M 0 1L ${progress * 2} 1L 0 ${1 - progress * 2}Z`;- case 'from-right':- return `+ case "from-right":+ return `M 0 0L ${progress} 0L ${progress} 1L 0 1Z`;- case 'from-bottom-right':- return `+ case "from-bottom-right":+ return `M 0 0L ${progress * 2} 0L 0 ${progress * 2}Z`;- case 'from-bottom':- return `+ case "from-bottom":+ return `M 1 0L 0 0L 0 ${progress}L 1 ${progress}Z`;- case 'from-bottom-left':- return `+ case "from-bottom-left":+ return `M 1 0L ${1 - progress * 2} 0L 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 ?? {},+ };};