🎥 Make videos programmatically with React
alright
JonnyBurger5ab0ea9261fd
diff --git a/packages/docs/components/demos/RoundedTextBox.tsx b/packages/docs/components/demos/RoundedTextBox.tsxindex dbfc402af2..bb3eef4000 100644--- a/packages/docs/components/demos/RoundedTextBox.tsx+++ b/packages/docs/components/demos/RoundedTextBox.tsx@@ -1,7 +1,8 @@+import {loadFont} from '@remotion/google-fonts/Figtree';import {fitTextOnNLines, measureText} from '@remotion/layout-utils';import type {TextAlign} from '@remotion/rounded-text-box';import {createRoundedTextBox} from '@remotion/rounded-text-box';-import React from 'react';+import React, {useEffect, useState} from 'react';import {AbsoluteFill} from 'remotion';type Props = {@@ -9,27 +10,29 @@ type Props = {readonly maxLines: number;readonly borderRadius: number;readonly horizontalPadding: number;+ readonly text: string;};-const TIKTOK_TEXT_BOX_HORIZONTAL_PADDING = 20;-const text =- 'No matter how much text I am adding, the text always fits on 3 lines and there is corner rounding like on TikTok.';--const boxWidth = 1500;-const fontFamily = 'Proxima Nova';-const fontWeight = 400;+const fontWeight = '700';+const boxWidth = 1100;const lineHeight = 1.5;-const maxFontSize = 200;+const maxFontSize = 70;++const {waitUntilDone, fontFamily} = loadFont('normal', {+ weights: [fontWeight],+ subsets: ['latin'],+});-export const RoundedTextBox: React.FC<Props> = ({+const RoundedTextBoxInner: React.FC<Props> = ({textAlign,maxLines,borderRadius,horizontalPadding,+ text,}) => {const {fontSize, lines} = fitTextOnNLines({maxLines,- maxBoxWidth: boxWidth - TIKTOK_TEXT_BOX_HORIZONTAL_PADDING * 2,+ maxBoxWidth: boxWidth - horizontalPadding * 2,fontFamily,text,fontWeight,@@ -67,7 +70,7 @@ export const RoundedTextBox: React.FC<Props> = ({textAlign,paddingLeft: horizontalPadding,paddingRight: horizontalPadding,- color: 'white',+ color: 'black',}),[fontSize, textAlign, horizontalPadding],);@@ -75,7 +78,7 @@ export const RoundedTextBox: React.FC<Props> = ({return (<AbsoluteFillstyle={{- backgroundColor: 'var(--background)',+ backgroundColor: '#eee',justifyContent: 'center',alignItems: 'center',}}@@ -95,7 +98,7 @@ export const RoundedTextBox: React.FC<Props> = ({overflow: 'visible',}}>- <path fill="black" d={d} />+ <path fill="white" d={d} /></svg><div style={{position: 'relative'}}>{lines.map((line, i) => (@@ -109,3 +112,23 @@ export const RoundedTextBox: React.FC<Props> = ({</AbsoluteFill>);};++export const RoundedTextBox: React.FC<Props> = (props) => {+ const [fontsLoaded, setFontsLoaded] = useState(false);++ useEffect(() => {+ waitUntilDone()+ .then(() => {+ setFontsLoaded(true);+ })+ .catch((err) => {+ console.error(err);+ });+ }, [fontsLoaded]);++ if (!fontsLoaded) {+ return null;+ }++ return <RoundedTextBoxInner {...props} />;+};diff --git a/packages/docs/components/demos/control.tsx b/packages/docs/components/demos/control.tsxindex 45805d1ba2..0878c3e000 100644--- a/packages/docs/components/demos/control.tsx+++ b/packages/docs/components/demos/control.tsx@@ -48,6 +48,14 @@ export const Control = ({[],);+ const textInputStyle = useMemo<React.CSSProperties>(+ () => ({+ width: '100%',+ marginRight: 2,+ }),+ [],+ );+return (<label style={labelStyle} className={styles.item}><div style={left}>@@ -107,6 +115,12 @@ export const Control = ({checked={value as boolean}type={'checkbox'}/>+ ) : option.type === 'string' ? (+ <input+ onChange={(e) => setValue(e.target.value)}+ style={textInputStyle}+ value={value as string}+ />) : null}</label>);diff --git a/packages/docs/components/demos/styles.module.css b/packages/docs/components/demos/styles.module.cssindex d85380cd99..3909578042 100644--- a/packages/docs/components/demos/styles.module.css+++ b/packages/docs/components/demos/styles.module.css@@ -1,47 +1,47 @@.containerrow {- display: grid;- grid-template-columns: 1fr 1fr 1fr;+ display: grid;+ grid-template-columns: 1fr 1fr 1fr;}.item {- grid-gap: 15px;- padding-left: 6px;- padding-right: 6px;- padding-top: 10px;- padding-bottom: 10px;+ grid-gap: 15px;+ padding-left: 6px;+ padding-right: 6px;+ padding-top: 10px;+ padding-bottom: 10px;}.item:not(:last-child) {- border-right: 1px solid var(--ifm-color-emphasis-300);+ border-right: 1px solid var(--ifm-color-emphasis-300);}-@media screen and (min-width: 1301px) {- .containerrow {- grid-template-columns: 1fr 1fr;- }- .item {- border-bottom: 1px solid var(--ifm-color-emphasis-300);- border-right: transparent;- }+@media screen and (min-width: 1301px) {+ .containerrow {+ grid-template-columns: 1fr;+ }+ .item {+ border-bottom: 1px solid var(--ifm-color-emphasis-300);+ border-right: transparent;+ }- .item:nth-child(2n+1):nth-last-child(-n+2),- .item:nth-child(2n+1):nth-last-child(-n+2) ~ .item {- border-bottom: transparent;- }+ .item:nth-child(2n + 1):nth-last-child(-n + 2),+ .item:nth-child(2n + 1):nth-last-child(-n + 2) ~ .item {+ border-bottom: transparent;+ }- .item:nth-child(2n) {- border-right: transparent;- }+ .item:nth-child(2n) {+ border-right: transparent;+ }}@media screen and (max-width: 1300px) {- .containerrow {- grid-template-columns: 1fr;- }- .item {- border-right: transparent ;- }- .item:not(:last-child) {- border-bottom: 1px solid var(--ifm-color-emphasis-300);- }+ .containerrow {+ grid-template-columns: 1fr;+ }+ .item {+ border-right: transparent;+ }+ .item:not(:last-child) {+ border-bottom: 1px solid var(--ifm-color-emphasis-300);+ }}diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.tsindex 891626055b..cd55ac1561 100644--- a/packages/docs/components/demos/types.ts+++ b/packages/docs/components/demos/types.ts@@ -50,6 +50,11 @@ export type Option = {default: string;values: string[];}+ | {+ type: 'string';+ default: string;+ optional: 'no';+ });export type DemoType = {@@ -694,8 +699,8 @@ export const wipePresentationDemo: DemoType = {export const roundedTextBoxDemo: DemoType = {comp: RoundedTextBox,- compHeight: 1080,- compWidth: 1920,+ compHeight: 720,+ compWidth: 1280,durationInFrames: 60,fps: 30,id: 'rounded-text-box',@@ -729,12 +734,19 @@ export const roundedTextBoxDemo: DemoType = {{type: 'numeric',name: 'horizontalPadding',- default: 30,+ default: 20,max: 100,step: 1,min: 0,optional: 'no',},+ {+ type: 'string',+ name: 'text',+ default:+ 'Try editing this text and the parameters! A rounded text box, like you see on TikTok, will be created.',+ optional: 'no',+ },],};