Skip to content

Commit

Permalink
wait until done
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBurger committed Dec 28, 2023
1 parent 9ee857b commit 22f4ae1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/docs/docs/google-fonts/load-font.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@ Unicode range information about the font.
}
```

### `waitUntilDone`<AvailableFrom v="4.0.83"/>

A function that returns a promise that resolves when the font is loaded.

```tsx title="Load a font in the background"
import { loadFont } from "@remotion/google-fonts/Lobster";

loadFont("normal", {
weights: ["400"],
subsets: ["latin"],
})
.waitUntilDone()
.then(() => {
console.log("Done loading");
});
```

## See also

- [Fonts](/docs/fonts)
Expand Down
7 changes: 6 additions & 1 deletion packages/google-fonts/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const loadFonts = (
fontFamily: FontInfo["fontFamily"];
fonts: FontInfo["fonts"];
unicodeRanges: FontInfo["unicodeRanges"];
waitUntilDone: () => Promise<undefined>;
} => {
const promises: Promise<void>[] = [];
const styles = style ? [style] : Object.keys(meta.fonts);
for (const style of styles) {
// Don't load fonts on server
Expand Down Expand Up @@ -93,7 +95,7 @@ export const loadFonts = (
);

// Load font-face
fontFace
const promise = fontFace
.load()
.then(() => {
(options?.document ?? document).fonts.add(fontFace);
Expand All @@ -104,6 +106,8 @@ export const loadFonts = (
loadedFonts[fontKey] = false;
throw err;
});

promises.push(promise);
}
}
}
Expand All @@ -112,5 +116,6 @@ export const loadFonts = (
fontFamily: meta.fontFamily,
fonts: meta.fonts,
unicodeRanges: meta.unicodeRanges,
waitUntilDone: () => Promise.all<void>(promises).then(() => undefined),
};
};

2 comments on commit 22f4ae1

@vercel
Copy link

@vercel vercel bot commented on 22f4ae1 Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bugs – ./packages/bugs

bugs-git-main-remotion.vercel.app
bugs-five.vercel.app
bugs.remotion.dev
bugs-remotion.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 22f4ae1 Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.