🎥 Make videos programmatically with React
updates
Jonny Burger6775e80355c8
diff --git a/packages/docs/docs/fonts.mdx b/packages/docs/docs/fonts.mdxindex 5b5e591b81..a24ee31460 100644--- a/packages/docs/docs/fonts.mdx+++ b/packages/docs/docs/fonts.mdx@@ -26,10 +26,10 @@ const GoogleFontsComp: React.FC = () => {## Google Fonts using CSS-Import the CSS that Google Fonts gives you. From version 2.2 on, Remotion will automatically wait until the fonts are loaded.+Import the CSS that Google Fonts gives you.:::note-This does not work if you use [`lazyComponent`](/docs/composition#lazycomponent).+From version 2.2 on, Remotion will automatically wait until the fonts are loaded.:::```css title="font.css"@@ -49,7 +49,7 @@ const MyComp: React.FC = () => {_available from v4.0.164_Put the font into your `public/` folder.-Put this somewhere in your app where it gets executed:+Put the [`loadFont()`](/docs/fonts/load-font) call somewhere in your app where it gets executed:```tsx twoslash title="load-fonts.ts"import { loadFont } from "@remotion/fonts";@@ -76,6 +76,28 @@ const fontFamily = "Inter";<div style={{ fontFamily: fontFamily }}>Some text</div>;```-:::info+## Local fonts (manually)++You may load fonts by using the web-native [`FontFace`](https://developer.mozilla.org/en-US/docs/Web/API/FontFace) API.++```tsx twoslash title="load-fonts.ts"+import { continueRender, delayRender, staticFile } from "remotion";++const waitForFont = delayRender();+const font = new FontFace(+ `Bangers`,+ `url('${staticFile("bangers.woff2")}') format('woff2')`,+);++font+ .load()+ .then(() => {+ document.fonts.add(font);+ continueRender(waitForFont);+ })+ .catch((err) => console.log("Error loading font", err));+```++:::noteIf your Typescript types give errors, install the newest version of the `@types/web` package.:::diff --git a/packages/docs/docs/fonts/load-font.mdx b/packages/docs/docs/fonts/load-font.mdxindex 41c7ec8faa..f102dc12ba 100644--- a/packages/docs/docs/fonts/load-font.mdx+++ b/packages/docs/docs/fonts/load-font.mdx@@ -4,6 +4,8 @@ title: loadFont()crumb: "@remotion/fonts"---+# loadFont()<AvailableFrom v="4.0.165" />+_Part of the [`@remotion/fonts`](/docs/fonts) package_Load a local font for use in Remotion.@@ -11,7 +13,7 @@ Automatically blocks the render until the font is ready.## Usage-```tsx twoslash+```tsx twoslash title="MyComp.tsx"import { loadFont } from "@remotion/fonts";import { AbsoluteFill, staticFile } from "remotion";@@ -41,9 +43,12 @@ The name of the font family.### url-Where to load the font from.+Where to load the font from. Can be a local file using [`staticFile()`](/docs/staticfile) or a URL.++### format?-All arguments and options are optional. Use TypeScript autocompletion.+Defines the format of the font file. By default gets derived from the file extension of the URL.+Override with one of the following values explicitly: `woff2`, `woff`, `opentype`, `truetype`.### ascentOverride?@@ -55,10 +60,12 @@ Defines the descent metric for the font.### display?+Equivalent to the CSS [`font-display`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display) property.Determines how a font face is displayed based on whether and when it is downloaded and ready to use.### featureSettings?+Equivalent to the CSS [`font-feature-settings`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-feature-settings) property.Allows control over advanced typographic features in OpenType fonts.### lineGapOverride?@@ -67,16 +74,24 @@ Defines the line gap metric for the font.### stretch?-Allows to specify a normal, condensed, or expanded face.+Equivalent to the CSS [`font-stretch`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-stretch) property.+Specify what kind of stretch the loaded font has.### style?-The font style we want to load. While each font has a different set of styles, common options are: `normal`, `italic` etc.+Equivalent to the CSS [`font-style`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-style) property.+Specify what kind of style the loaded font has.++### weight?++Equivalent to the CSS [`font-weight`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-weight) property.+Specify what kind of weight the loaded font has.### unicodeRange?The range of Unicode code points to be used from the font.-### weight?+## See also-Sets the weight (or boldness) of the font. The weights available depend on the font-family that is currently set.+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/fonts/src/load-font.ts)+- [Fonts](/docs/fonts)diff --git a/packages/example/src/Fonts/index.tsx b/packages/example/src/Fonts/index.tsxindex d28c1b9c25..8af1324a4b 100644--- a/packages/example/src/Fonts/index.tsx+++ b/packages/example/src/Fonts/index.tsx@@ -1,11 +1,12 @@import {loadFont} from '@remotion/fonts';import React from 'react';-import {AbsoluteFill} from 'remotion';+import {AbsoluteFill, staticFile} from 'remotion';loadFont({family: 'Bangers',- url: 'bangers.woff2',+ url: staticFile('bangers.woff2'),weight: '500',+ format: 'opentype',}).then(() => console.log('Font loaded!'));export const FontDemo: React.FC = () => {diff --git a/packages/example/src/webpack-override.mjs b/packages/example/src/webpack-override.mjsindex a72162392d..c86b49b6f2 100644--- a/packages/example/src/webpack-override.mjs+++ b/packages/example/src/webpack-override.mjs@@ -20,6 +20,7 @@ const aliases = {'@remotion/motion-blur': resolveCwd('@remotion/motion-blur'),'@remotion/noise': resolveCwd('@remotion/noise'),'@remotion/paths': resolveCwd('@remotion/paths'),+ '@remotion/fonts': resolveCwd('@remotion/fonts'),'@remotion/player': resolveCwd('@remotion/player'),'@remotion/preload': resolveCwd('@remotion/preload'),'@remotion/rive': resolveCwd('@remotion/rive'),diff --git a/packages/example/tsconfig.json b/packages/example/tsconfig.jsonindex 6e8105a0c3..eef044ac62 100644--- a/packages/example/tsconfig.json+++ b/packages/example/tsconfig.json@@ -19,6 +19,7 @@{"path": "../eslint-config"},{"path": "../eslint-plugin"},{"path": "../gif"},+ {"path": "../fonts"},{"path": "../lambda"},{"path": "../lottie"},{"path": "../media-utils"},diff --git a/packages/fonts/src/get-font-format.ts b/packages/fonts/src/get-font-format.tsindex dd864845ba..230f4cd148 100644--- a/packages/fonts/src/get-font-format.ts+++ b/packages/fonts/src/get-font-format.ts@@ -12,6 +12,8 @@ export const getFontFormat = (url: string): FontFormat => {case 'ttf':return 'truetype';default:- throw new Error(`Unsupported font extension: ${ext}`);+ throw new Error(+ `Could not automatically derive font format from extension: ${ext}. Pass the "format" parameter explicitly.`,+ );}};diff --git a/packages/fonts/src/index.ts b/packages/fonts/src/index.tsindex be9f55f091..7cca773cde 100644--- a/packages/fonts/src/index.ts+++ b/packages/fonts/src/index.ts@@ -1 +1,2 @@-export {loadFont} from './load-font';+export {FontFormat} from './get-font-format';+export {LoadFontOptions, loadFont} from './load-font';diff --git a/packages/fonts/src/load-font.ts b/packages/fonts/src/load-font.tsindex b32b2e46f4..6972386d14 100644--- a/packages/fonts/src/load-font.ts+++ b/packages/fonts/src/load-font.ts@@ -2,7 +2,7 @@ import {cancelRender, continueRender, delayRender} from 'remotion';import type {FontFormat} from './get-font-format';import {getFontFormat} from './get-font-format';-type LoadFontOptions = {+export type LoadFontOptions = {family: string;url: string;ascentOverride?: string;