🎥 Make videos programmatically with React
niiice
Jonny Burger16665f06b597
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsxindex 14b491ef4e..366d946cef 100644--- a/packages/docs/components/demos/index.tsx+++ b/packages/docs/components/demos/index.tsx@@ -1,6 +1,7 @@import { useColorMode } from "@docusaurus/theme-common";import { Player } from "@remotion/player";-import React, { useState } from "react";+import React, { useCallback, useMemo, useState } from "react";+import { AbsoluteFill } from "remotion";import { Control } from "./control";import styles from "./styles.module.css";import type { DemoType } from "./types";@@ -34,12 +35,10 @@ export const Demo: React.FC<{const demo = demos.find((d) => d.id === type);const { isDarkTheme } = useColorMode();- if (!demo) {- throw new Error("Demo not found");- }+ const [key, setKey] = useState(() => 0);- const [state, setState] = useState(() =>- demo.options+ const initialState = useMemo(() => {+ return demo.options.map((o) =>[@@ -50,12 +49,24 @@ export const Demo: React.FC<{.reduce((a, b) => {a[b[0]] = b[1];return a;- }, {})- );+ }, {});+ }, [demo.options]);++ const restart = useCallback(() => {+ setState(initialState);+ setKey((k) => k + 1);+ }, [initialState]);++ if (!demo) {+ throw new Error("Demo not found");+ }++ const [state, setState] = useState(() => initialState);return (<div style={container}><Player+ key={key}component={demo.comp}compositionWidth={demo.compWidth}compositionHeight={demo.compHeight}@@ -66,6 +77,24 @@ export const Demo: React.FC<{aspectRatio: demo.compWidth / demo.compHeight,borderBottom: "1px solid var(--ifm-color-emphasis-300)",}}+ errorFallback={({ error }) => {+ return (+ <AbsoluteFill+ style={{+ justifyContent: "center",+ alignItems: "center",+ fontSize: 30,+ textAlign: "center",+ lineHeight: 1.5,+ }}+ >+ {error.message}+ <button onClick={restart} type="button">+ Restart+ </button>+ </AbsoluteFill>+ );+ }}inputProps={{ ...state, darkMode: isDarkTheme }}autoPlay={demo.autoPlay}loopdiff --git a/packages/shapes/src/utils/join-points.ts b/packages/shapes/src/utils/join-points.tsindex 5233781328..80275e2860 100644--- a/packages/shapes/src/utils/join-points.ts+++ b/packages/shapes/src/utils/join-points.ts@@ -58,6 +58,12 @@ export const joinPoints = (const prevVector = [x - prevPoint[0], y - prevPoint[1]] as const;const nextVector = [nextPoint[0] - x, nextPoint[1] - y] as const;+ if (cornerRadius && edgeRoundness !== null) {+ throw new Error(+ `"cornerRadius" and "edgeRoundness" cannot be specified at the same time.`+ );+ }+if (edgeRoundness === null) {const prevVectorMinusRadius = shortenVector(prevVector, cornerRadius);const prevVectorLenght = scaleVectorToLength(prevVector, cornerRadius);