🎥 Make videos programmatically with React
make more stuff optional
Jonny Burgerbdbe1dba4ad8
diff --git a/packages/example/src/Transitions/index.tsx b/packages/example/src/Transitions/index.tsxindex c057a2bf46..b3a807af80 100644--- a/packages/example/src/Transitions/index.tsx+++ b/packages/example/src/Transitions/index.tsx@@ -81,6 +81,18 @@ export const BasicTransition: React.FC = () => {</TransitionSeries.Sequence></>))}+ <TransitionSeries.Transition+ timing={makeLinearTiming({durationInFrames: 30})}+ />+ <TransitionSeries.Sequence durationInFrames={90}>+ <Letter color="black">P</Letter>+ </TransitionSeries.Sequence>+ <TransitionSeries.Transition+ timing={makeLinearTiming({durationInFrames: 30})}+ />+ <TransitionSeries.Sequence durationInFrames={90}>+ <Letter color="red">Q</Letter>+ </TransitionSeries.Sequence></TransitionSeries>);};diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsxindex 6246ac73ab..41c0d8acfa 100644--- a/packages/transitions/src/TransitionSeries.tsx+++ b/packages/transitions/src/TransitionSeries.tsx@@ -81,7 +81,7 @@ const TransitionSeriesChildren: FC<{children: React.ReactNode}> = ({const debugInfo = `index = ${i}, duration = ${castedChildAgain.props.durationInFrames}`;- if (!castedChildAgain || !castedChildAgain.props.children) {+ 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.`);@@ -203,20 +203,23 @@ const TransitionSeriesChildren: FC<{children: React.ReactNode}> = ({}if (next && prev && nextProgress !== null && prevProgress !== null) {- const UppercaseNextPresentation = next.props.presentation.component;- const UppercasePrevPresentation = prev.props.presentation.component;+ const nextPresentation = next.props.presentation ?? makeSlidePresentation()+ const prevPresentation = prev.props.presentation ?? makeSlidePresentation()++ const UppercaseNextPresentation = nextPresentation.component;+ const UppercasePrevPresentation = prevPresentation.component;return (// @ts-expect-error<UppercaseNextPresentation- passedProps={next.props.presentation.props ?? {}}+ passedProps={nextPresentation.props ?? {}}presentationDirection="out"presentationProgress={nextProgress}>{/**// @ts-expect-error */}<UppercasePrevPresentation- passedProps={prev.props.presentation.props ?? {}}+ passedProps={prevPresentation.props ?? {}}presentationDirection="in"presentationProgress={prevProgress}>@@ -227,12 +230,14 @@ const TransitionSeriesChildren: FC<{children: React.ReactNode}> = ({}if (prevProgress !== null && prev) {- const UppercasePrevPresentation = prev.props.presentation.component;+ const prevPresentation = prev.props.presentation ?? makeSlidePresentation()++ const UppercasePrevPresentation = prevPresentation.component;return (// @ts-expect-error<UppercasePrevPresentation- passedProps={prev.props.presentation.props ?? {}}+ passedProps={prevPresentation.props ?? {}}presentationDirection="in"presentationProgress={prevProgress}>@@ -242,12 +247,14 @@ const TransitionSeriesChildren: FC<{children: React.ReactNode}> = ({}if (nextProgress !== null && next) {- const UppercaseNextPresentation = next.props.presentation.component;+ const nextPresentation = next.props.presentation ?? makeSlidePresentation()++ const UppercaseNextPresentation = nextPresentation.component;return (// @ts-expect-error<UppercaseNextPresentation- passedProps={next.props.presentation.props ?? {}}+ passedProps={nextPresentation.props ?? {}}presentationDirection="out"presentationProgress={nextProgress}>@@ -284,6 +291,7 @@ TransitionSeries.Transition = TransitionSeriesTransition;export {TransitionSeries};import React from 'react';+import { makeSlidePresentation } from './presentations/Slide.js';type ReactChildArray = ReturnType<typeof React.Children.toArray>;@@ -303,3 +311,4 @@ const flattenChildren = (children: React.ReactNode): ReactChildArray => {return flatChildren;}, []);};+diff --git a/packages/transitions/src/presentations/Slide.tsx b/packages/transitions/src/presentations/Slide.tsxindex e66fbdb4f1..7a4a33ab9a 100644--- a/packages/transitions/src/presentations/Slide.tsx+++ b/packages/transitions/src/presentations/Slide.tsx@@ -8,7 +8,7 @@ import type {type WipeDirection = 'from-left' | 'from-top' | 'from-right' | 'from-bottom';type SlideProps = {- direction: WipeDirection;+ direction?: WipeDirection;};const SlidePresentation: React.FC<@@ -17,11 +17,11 @@ const SlidePresentation: React.FC<children,presentationProgress,presentationDirection,- passedProps: {direction: slideDirection},+ passedProps: {direction = 'from-left'},}) => {const directionStyle = useMemo((): React.CSSProperties => {if (presentationDirection === 'out') {- switch (slideDirection) {+ switch (direction) {case 'from-left':return {transform: `translateX(${presentationProgress * 100}%)`,@@ -39,11 +39,11 @@ const SlidePresentation: React.FC<transform: `translateY(-${presentationProgress * 100}%)`,};default:- throw new Error(`Invalid direction: ${slideDirection}`);+ throw new Error(`Invalid direction: ${direction}`);}}- switch (slideDirection) {+ switch (direction) {case 'from-left':return {transform: `translateX(${-100 + presentationProgress * 100}%)`,@@ -61,9 +61,9 @@ const SlidePresentation: React.FC<transform: `translateY(${100 - presentationProgress * 100}%)`,};default:- throw new Error(`Invalid direction: ${slideDirection}`);+ throw new Error(`Invalid direction: ${direction}`);}- }, [presentationDirection, presentationProgress, slideDirection]);+ }, [presentationDirection, presentationProgress, direction]);const style: React.CSSProperties = useMemo(() => {return {@@ -83,10 +83,10 @@ const SlidePresentation: React.FC<};export const makeSlidePresentation = (- props: SlideProps+ props?: SlideProps): TransitionPresentation<SlideProps> => {return {component: SlidePresentation,- props,+ props: props ?? {},};};diff --git a/packages/transitions/src/presentations/Wipe.tsx b/packages/transitions/src/presentations/Wipe.tsxindex 261dc18e39..584fc7b209 100644--- a/packages/transitions/src/presentations/Wipe.tsx+++ b/packages/transitions/src/presentations/Wipe.tsx@@ -83,7 +83,7 @@ type WipeDirection =| 'from-bottom-left';type WipeProps = {- direction: WipeDirection;+ direction?: WipeDirection;};const makePathOut = (progress: number, direction: WipeDirection) => {@@ -159,7 +159,7 @@ const WipePresentation: React.FC<children,presentationProgress,presentationDirection,- passedProps: {direction: wipeDirection},+ passedProps: {direction = 'from-left'},}) => {const [clipId] = useState(() => String(random(null)));@@ -170,8 +170,8 @@ const WipePresentation: React.FC<const path =presentationDirection === 'in'- ? makePathIn(progressInDirection, wipeDirection)- : makePathOut(progressInDirection, wipeDirection);+ ? makePathIn(progressInDirection, direction)+ : makePathOut(progressInDirection, direction);const style: React.CSSProperties = useMemo(() => {return {@@ -207,10 +207,10 @@ const WipePresentation: React.FC<};export const makeWipePresentation = (- props: WipeProps+ props?: WipeProps): TransitionPresentation<WipeProps> => {return {component: WipePresentation,- props,+ props: props ?? {},};};diff --git a/packages/transitions/src/types.ts b/packages/transitions/src/types.tsindex 153203d48f..38db304e5c 100644--- a/packages/transitions/src/types.ts+++ b/packages/transitions/src/types.ts@@ -11,7 +11,7 @@ export type TransitionSeriesTransitionProps<PresentationProps extends Record<string, unknown>> = {timing: TransitionTiming;- presentation: TransitionPresentation<PresentationProps>;+ presentation?: TransitionPresentation<PresentationProps>;};type LooseComponentType<T> = ComponentType<T> | ((props: T) => React.ReactNode);