@remotion/google-fonts 4.0.277 → 4.0.279

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ export declare const loadFontFromInfo: (meta: import("./base").FontInfo, style?: string, options?: {
2
+ weights?: string[];
3
+ subsets?: string[];
4
+ document?: Document;
5
+ }) => {
6
+ fontFamily: import("./base").FontInfo["fontFamily"];
7
+ fonts: import("./base").FontInfo["fonts"];
8
+ unicodeRanges: import("./base").FontInfo["unicodeRanges"];
9
+ waitUntilDone: () => Promise<undefined>;
10
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadFontFromInfo = void 0;
4
+ const base_1 = require("./base");
5
+ exports.loadFontFromInfo = base_1.loadFonts;
@@ -0,0 +1,76 @@
1
+ // src/base.ts
2
+ import { continueRender, delayRender } from "remotion";
3
+ var loadedFonts = {};
4
+ var loadFonts = (meta, style, options) => {
5
+ const promises = [];
6
+ const styles = style ? [style] : Object.keys(meta.fonts);
7
+ for (const style2 of styles) {
8
+ if (typeof FontFace === "undefined") {
9
+ continue;
10
+ }
11
+ if (!meta.fonts[style2]) {
12
+ throw new Error(`The font ${meta.fontFamily} does not have a style ${style2}`);
13
+ }
14
+ const weights = options?.weights ?? Object.keys(meta.fonts[style2]);
15
+ for (const weight of weights) {
16
+ if (!meta.fonts[style2][weight]) {
17
+ throw new Error(`The font ${meta.fontFamily} does not have a weight ${weight} in style ${style2}`);
18
+ }
19
+ const subsets = options?.subsets ?? Object.keys(meta.fonts[style2][weight]);
20
+ for (const subset of subsets) {
21
+ let font = meta.fonts[style2]?.[weight]?.[subset];
22
+ if (!font) {
23
+ throw new Error(`weight: ${weight} subset: ${subset} is not available for '${meta.fontFamily}'`);
24
+ }
25
+ let fontKey = `${meta.fontFamily}-${style2}-${weight}-${subset}`;
26
+ const previousPromise = loadedFonts[fontKey];
27
+ if (previousPromise) {
28
+ promises.push(previousPromise);
29
+ continue;
30
+ }
31
+ const handle = delayRender(`Fetching ${meta.fontFamily} font ${JSON.stringify({
32
+ style: style2,
33
+ weight,
34
+ subset
35
+ })}`, { timeoutInMilliseconds: 60000 });
36
+ const fontFace = new FontFace(meta.fontFamily, `url(${font}) format('woff2')`, {
37
+ weight,
38
+ style: style2,
39
+ unicodeRange: meta.unicodeRanges[subset]
40
+ });
41
+ let attempts = 2;
42
+ const tryToLoad = () => {
43
+ const promise = fontFace.load().then(() => {
44
+ (options?.document ?? document).fonts.add(fontFace);
45
+ continueRender(handle);
46
+ }).catch((err) => {
47
+ loadedFonts[fontKey] = undefined;
48
+ if (attempts === 0) {
49
+ throw err;
50
+ } else {
51
+ attempts--;
52
+ tryToLoad();
53
+ }
54
+ });
55
+ loadedFonts[fontKey] = promise;
56
+ promises.push(promise);
57
+ };
58
+ tryToLoad();
59
+ }
60
+ }
61
+ }
62
+ return {
63
+ fontFamily: meta.fontFamily,
64
+ fonts: meta.fonts,
65
+ unicodeRanges: meta.unicodeRanges,
66
+ waitUntilDone: () => Promise.all(promises).then(() => {
67
+ return;
68
+ })
69
+ };
70
+ };
71
+
72
+ // src/from-info.ts
73
+ var loadFontFromInfo = loadFonts;
74
+ export {
75
+ loadFontFromInfo
76
+ };