🎥 Make videos programmatically with React
final update
Jonny Burger2126e866e4e6
diff --git a/packages/bundler/src/error-overlay/entry-basic.ts b/packages/bundler/src/error-overlay/entry-basic.tsindex 845a84ce61..b70617ebe6 100644--- a/packages/bundler/src/error-overlay/entry-basic.ts+++ b/packages/bundler/src/error-overlay/entry-basic.ts@@ -8,7 +8,9 @@ startReportingRuntimeErrors({module.hot.addStatusHandler((status) => {if (status === 'apply') {dismissErrors();- setErrorsRef.current?.setErrors([]);+ setErrorsRef.current?.setErrors({+ type: 'clear',+ });}});}diff --git a/packages/bundler/src/error-overlay/react-overlay/index.ts b/packages/bundler/src/error-overlay/react-overlay/index.tsindex e1eb7c9c72..90d0777304 100644--- a/packages/bundler/src/error-overlay/react-overlay/index.ts+++ b/packages/bundler/src/error-overlay/react-overlay/index.ts@@ -42,7 +42,10 @@ export function startReportingRuntimeErrors(options: RuntimeReportingOptions) {};function update() {- setErrorsRef.current?.setErrors(currentRuntimeErrorRecords);+ setErrorsRef.current?.setErrors({+ type: 'errors',+ errors: currentRuntimeErrorRecords,+ });}stopListeningToRuntimeErrors = listenToRuntimeErrors(diff --git a/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.ts b/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.tsindex c083b51f13..5a2dd927a7 100644--- a/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.ts+++ b/packages/bundler/src/error-overlay/react-overlay/listen-to-runtime-errors.ts@@ -33,6 +33,7 @@ import {} from './effects/proxy-console';import {massage as massageWarning} from './effects/format-warning';import {getStackFrames} from './utils/get-stack-frames';+import {setErrorsRef} from '../remotion-overlay/Overlay';const CONTEXT_SIZE = 3;@@ -45,6 +46,10 @@ export const crashWithFrames =unhandledRejection = false) => {try {+ setErrorsRef.current?.setErrors({+ type: 'symbolicating',+ });+const stackFrames = await getStackFrames(error, CONTEXT_SIZE);if (stackFrames === null || stackFrames === undefined) {diff --git a/packages/bundler/src/error-overlay/remotion-overlay/DismissButton.tsx b/packages/bundler/src/error-overlay/remotion-overlay/DismissButton.tsxnew file mode 100644index 0000000000..a8e5f495e7--- /dev/null+++ b/packages/bundler/src/error-overlay/remotion-overlay/DismissButton.tsx@@ -0,0 +1,38 @@+import {useCallback} from 'react';+import React from 'react';++const size: React.CSSProperties = {+ height: 20,+ width: 20,+};++const style: React.CSSProperties = {+ appearance: 'none',+ WebkitAppearance: 'none',+ backgroundColor: 'transparent',+ border: 'none',+ cursor: 'pointer',+};++export const DismissButton: React.FC = () => {+ const dismiss = useCallback(() => {+ window.location.href = '/';+ }, []);++ return (+ <button type="button" style={style} onClick={dismiss}>+ <svg+ focusable="false"+ role="img"+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 352 512"+ style={size}+ >+ <path+ fill="white"+ d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"+ />+ </svg>+ </button>+ );+};diff --git a/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsx b/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsxindex 4c0631494b..246a1638e7 100644--- a/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsx+++ b/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsx@@ -1,9 +1,12 @@+import {useCallback} from 'react';import React from 'react';import {ErrorRecord} from '../react-overlay/listen-to-runtime-errors';import {AskOnDiscord} from './AskOnDiscord';+import {Button} from './Button';import {OpenInEditor} from './OpenInEditor';import {SearchGithubIssues} from './SearchGitHubIssues';import {StackElement} from './StackFrame';+import {DismissButton} from './DismissButton';const container: React.CSSProperties = {width: '100%',@@ -17,10 +20,10 @@ const container: React.CSSProperties = {};const title: React.CSSProperties = {- fontSize: '1.5em',- fontWeight: 'bold',- lineHeight: 1.5,marginBottom: 8,+ display: 'flex',+ flexDirection: 'row',+ justifyContent: 'center',};const errName: React.CSSProperties = {@@ -42,6 +45,14 @@ const spacer: React.CSSProperties = {display: 'inline-block',};+const left: React.CSSProperties = {+ flex: 1,+ paddingRight: 14,+ lineHeight: 1.5,+ fontSize: '1.5em',+ fontWeight: 'bold',+};+export const ErrorDisplay: React.FC<{display: ErrorRecord;}> = ({display}) => {@@ -56,9 +67,12 @@ export const ErrorDisplay: React.FC<{return (<div style={container}><div style={title}>- <span style={errName}>{display.error.name}</span>- <br />- {display.error.message}+ <div style={left}>+ <span style={errName}>{display.error.name}</span>+ <br />+ {display.error.message}+ </div>+ <DismissButton /></div>{display.stackFrames.length > 0 && window.remotion_editorName ? (<>diff --git a/packages/bundler/src/error-overlay/remotion-overlay/Overlay.tsx b/packages/bundler/src/error-overlay/remotion-overlay/Overlay.tsxindex 7f7c5fb6d7..883b256758 100644--- a/packages/bundler/src/error-overlay/remotion-overlay/Overlay.tsx+++ b/packages/bundler/src/error-overlay/remotion-overlay/Overlay.tsx@@ -1,16 +1,39 @@-import React, {createRef, useImperativeHandle, useState} from 'react';+import React, {+ createRef,+ useCallback,+ useImperativeHandle,+ useState,+} from 'react';import {AbsoluteFill} from 'remotion';import {ErrorRecord} from '../react-overlay/listen-to-runtime-errors';+import {Button} from './Button';import {ErrorDisplay} from './ErrorDisplay';type SetErrors = {- setErrors: (errs: ErrorRecord[]) => void;+ setErrors: (errs: State) => void;};export const setErrorsRef = createRef<SetErrors>();+type State =+ | {+ type: 'clear';+ }+ | {+ type: 'symbolicating';+ }+ | {+ type: 'errors';+ errors: ErrorRecord[];+ };++const BACKGROUND_COLOR = '#1f2428';+const ICON_SIZE = 40;+const rotate: React.CSSProperties = {+ transform: `rotate(90deg)`,+};export const Overlay: React.FC = () => {- const [errors, setErrors] = useState<ErrorRecord[]>([]);+ const [errors, setErrors] = useState<State>({type: 'clear'});useImperativeHandle(setErrorsRef,@@ -20,15 +43,51 @@ export const Overlay: React.FC = () => {[]);- if (errors.length === 0) {+ if (errors.type === 'clear') {+ return null;+ }++ if (errors.type === 'symbolicating') {+ return (+ <AbsoluteFill+ style={{+ backgroundColor: BACKGROUND_COLOR,+ overflow: 'auto',+ justifyContent: 'center',+ alignItems: 'center',+ }}+ >+ <svg+ width={ICON_SIZE}+ height={ICON_SIZE}+ viewBox="-100 -100 400 400"+ style={rotate}+ >+ <path+ fill="#555"+ stroke="#555"+ strokeWidth="100"+ strokeLinejoin="round"+ d="M 2 172 a 196 100 0 0 0 195 5 A 196 240 0 0 0 100 2.259 A 196 240 0 0 0 2 172 z"+ />+ </svg>{' '}+ </AbsoluteFill>+ );+ }++ if (errors.errors.length === 0) {return null;}return (<AbsoluteFill- style={{backgroundColor: '#1f2428', overflow: 'auto', color: 'white'}}+ style={{+ backgroundColor: BACKGROUND_COLOR,+ overflow: 'auto',+ color: 'white',+ }}>- {errors.map((err) => {+ {errors.errors.map((err) => {return <ErrorDisplay key={err.error.stack} display={err} />;})}</AbsoluteFill>diff --git a/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsx b/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsxindex 74b7b037df..4ebd4a85eb 100644--- a/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsx+++ b/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsx@@ -47,7 +47,7 @@ export const StackElement: React.FC<{<div><div style={header}><div style={left}>- <div style={fnName}>{s.functionName}</div>+ <div style={fnName}>{s.functionName ?? '(anonymous function)'}</div><div style={location}>{formatLocation(s._originalFileName as string)}:{s.columnNumber}</div>diff --git a/packages/core/src/default-css.ts b/packages/core/src/default-css.tsindex 51c0b96296..26014eb211 100644--- a/packages/core/src/default-css.ts+++ b/packages/core/src/default-css.ts@@ -27,6 +27,7 @@ export const makeDefaultCSS = (scope: string | null) => {}body {margin: 0;+ background-color: #1f2428}`;}