Skip to content

🎥 Make videos programmatically with React

start writing docs

Jonny Burgerad9f70d44ada
diff --git a/packages/docs/docs/importing-assets.md b/packages/docs/docs/importing-assets.md
index ae34e78fed..be22e16068 100644
--- a/packages/docs/docs/importing-assets.md
+++ b/packages/docs/docs/importing-assets.md
@@ -8,7 +8,8 @@ Remotion allows you to include several types of files in your project:
- Images (`.png`, `.svg`, `.jpg`, `.jpeg`, `.webp`, `.gif`, `.bmp`)
- Videos (`.webm`, `.mp4`)
- Audio (`.mp3`, `.wav`, `.aac`)
-- [Fonts (`.woff` and `.woff2`) - read the separate page for fonts](/docs/fonts)
+- [Webfonts - read the separate page for fonts](/docs/fonts)
+- Arbitrary files using the `staticFile()` API
## Using images
@@ -84,3 +85,7 @@ See the [audio guide](/docs/using-audio) for guidance on including audio.
## Using fonts
See the [dedicated page about fonts](/docs/fonts).
+
+## Importing arbitrary files
+
+Create a `/public` folder in your project and use the [`staticFile()`](/docs/staticfile) API to get a URL reference of the asset that you can load into your project.
diff --git a/packages/docs/docs/staticfile.md b/packages/docs/docs/staticfile.md
new file mode 100644
index 0000000000..4e01ba52d2
--- /dev/null
+++ b/packages/docs/docs/staticfile.md
@@ -0,0 +1,6 @@
+---
+id: staticfile
+title: staticFile()
+---
+
+TODO
diff --git a/packages/docs/docs/using-fonts.md b/packages/docs/docs/using-fonts.md
index 0eba6ad7f0..e6e9454d2a 100644
--- a/packages/docs/docs/using-fonts.md
+++ b/packages/docs/docs/using-fonts.md
@@ -3,9 +3,11 @@ title: Using fonts
id: fonts
---
-You can use fonts by loading them in a CSS file using @font-face. Web fonts often ship with a css file declaring the fonts, which you can import using the `@import` statement.
+Here are some ways how you can use custom fonts in Remotion.
-## Example using Google Fonts
+## Google Fonts
+
+Import the CSS that Google Fonts gives you. From version 2.2 on, Remotion will automatically wait until the fonts are loaded.
```css title="font.css"
@import url("https://fonts.googleapis.com/css2?family=Bangers");
@@ -19,30 +21,36 @@ const MyComp: React.FC = () => {
};
```
-**Important when using Webfonts:**
+## Example using local fonts
-- _When using v2.2 or later_: We automatically wait for fonts to be loaded, so you don't need to do anything.
-- _When using an older version of Remotion_: Google Fonts by default appends `?display=swap` to their URLs. Make sure to remove it to ensure the video renders correctly if you have a slow internet connection.
+Put the font into your `/public` folder and use the [`staticFile()`](/docs/staticfile) API to load the font. Use the `FontFace` browser API to load the font. [Click here](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face) to read the syntax that can be used for the Font Face API.
-## Example using local fonts
+Put this somewhere in your app where it gets executed:
-```css title="font.css"
-@font-face {
- font-family: "Bangers";
- font-style: normal;
- font-weight: 400;
- src: url(./bangers.woff2) format("woff2");
-}
-```
+```tsx twoslash title="load-fonts.ts"
+import { continueRender, delayRender, staticFile } from "remotion";
-```tsx twoslash title="MyComp.tsx"
-import "./font.css";
+const waitForFont = delayRender();
+const font = new FontFace(
+ `Bangers`,
+ `url(${staticFile("bangers.woff2")}) format('woff2')`
+);
-const MyComp: React.FC = () => {
- return <div style={{ fontFamily: "Bangers" }}>Hello</div>;
-};
+font
+ .load()
+ .then(() => {
+ document.fonts.add(font);
+ continueRender(waitForFont);
+ })
+ .catch((err) => console.log("Error loading font", err));
```
-### File requirements
+The font is now available for use:
+
+```tsx twoslash title="MyComp.tsx"
+<div style={{ fontFamily: "Bangers" }}>Some text</div>
+```
-Fonts must have one of the following file extensions to be loaded: `woff`, `woff2`, `ttf`, `eot`.
+:::info
+If your Typescript types give errors, install the newest version of the `@types/web` package.
+:::
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index ecfdecb405..c56ba76277 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -65,6 +65,7 @@ module.exports = {
"random",
"register-root",
"spring",
+ "staticfile",
"use-current-frame",
"use-video-config",
"audio",