@remotion/google-fonts 4.0.529 → 4.0.531

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,387 @@
1
+ // src/base.ts
2
+ import { continueRender, delayRender } from "remotion";
3
+ import { NoReactInternals } from "remotion/no-react";
4
+
5
+ // src/resolve-font-subsets.ts
6
+ var isChunkSubset = (subset) => /^\[\d+\]$/.test(subset);
7
+ var compareChunkSubsets = (a, b) => {
8
+ return Number(a.slice(1, -1)) - Number(b.slice(1, -1));
9
+ };
10
+ var resolveFontSubsetKeys = ({
11
+ availableSubsetKeys,
12
+ metaSubsets,
13
+ requestedSubset
14
+ }) => {
15
+ if (availableSubsetKeys.includes(requestedSubset)) {
16
+ return [requestedSubset];
17
+ }
18
+ if (!metaSubsets.includes(requestedSubset)) {
19
+ return [requestedSubset];
20
+ }
21
+ const chunkSubsets = availableSubsetKeys.filter(isChunkSubset).sort(compareChunkSubsets);
22
+ return chunkSubsets.length === 0 ? [requestedSubset] : chunkSubsets;
23
+ };
24
+
25
+ // src/base.ts
26
+ var loadedFonts = {};
27
+ var withResolvers = function() {
28
+ let resolve;
29
+ let reject;
30
+ const promise = new Promise((res, rej) => {
31
+ resolve = res;
32
+ reject = rej;
33
+ });
34
+ return { promise, resolve, reject };
35
+ };
36
+ var loadFontFaceOrTimeoutAfter20Seconds = (fontFace) => {
37
+ const timeout = withResolvers();
38
+ const int = setTimeout(() => {
39
+ timeout.reject(new Error("Timed out loading Google Font"));
40
+ }, 18000);
41
+ return Promise.race([
42
+ fontFace.load().then(() => {
43
+ clearTimeout(int);
44
+ }),
45
+ timeout.promise
46
+ ]);
47
+ };
48
+ var loadFonts = (meta, style, options) => {
49
+ const weightsAndSubsetsAreSpecified = Array.isArray(options?.weights) && Array.isArray(options?.subsets) && options.weights.length > 0 && options.subsets.length > 0;
50
+ if (NoReactInternals.ENABLE_V5_BREAKING_CHANGES && !weightsAndSubsetsAreSpecified) {
51
+ throw new Error("Loading Google Fonts without specifying weights and subsets is not supported in Remotion v5. Please specify the weights and subsets you need.");
52
+ }
53
+ const promises = [];
54
+ const styles = style ? [style] : Object.keys(meta.fonts);
55
+ let fontsLoaded = 0;
56
+ for (const style2 of styles) {
57
+ if (typeof FontFace === "undefined") {
58
+ continue;
59
+ }
60
+ if (!meta.fonts[style2]) {
61
+ throw new Error(`The font ${meta.fontFamily} does not have a style ${style2}`);
62
+ }
63
+ const weights = options?.weights ?? Object.keys(meta.fonts[style2]);
64
+ for (const weight of weights) {
65
+ if (!meta.fonts[style2][weight]) {
66
+ throw new Error(`The font ${meta.fontFamily} does not have a weight ${weight} in style ${style2}`);
67
+ }
68
+ const requestedSubsets = options?.subsets ?? Object.keys(meta.fonts[style2][weight]);
69
+ const availableSubsetKeys = Object.keys(meta.fonts[style2][weight]);
70
+ const subsets = [
71
+ ...new Set(requestedSubsets.flatMap((requestedSubset) => resolveFontSubsetKeys({
72
+ availableSubsetKeys,
73
+ metaSubsets: meta.subsets,
74
+ requestedSubset
75
+ })))
76
+ ];
77
+ for (const subset of subsets) {
78
+ let font = meta.fonts[style2]?.[weight]?.[subset];
79
+ if (!font) {
80
+ throw new Error(`weight: ${weight} subset: ${subset} is not available for '${meta.fontFamily}'`);
81
+ }
82
+ let fontKey = `${meta.fontFamily}-${style2}-${weight}-${subset}`;
83
+ const previousPromise = loadedFonts[fontKey];
84
+ if (previousPromise) {
85
+ promises.push(previousPromise);
86
+ continue;
87
+ }
88
+ const baseLabel = `Fetching ${meta.fontFamily} font ${JSON.stringify({
89
+ style: style2,
90
+ weight,
91
+ subset
92
+ })}`;
93
+ const label = weightsAndSubsetsAreSpecified ? baseLabel : `${baseLabel}. This might be caused by loading too many font variations. Read more: https://www.remotion.dev/docs/troubleshooting/font-loading-errors#render-timeout-when-loading-google-fonts`;
94
+ const handle = delayRender(label, { timeoutInMilliseconds: 60000 });
95
+ fontsLoaded++;
96
+ const registerFont = (fontData) => {
97
+ NoReactInternals.registerFontFace({
98
+ ascentOverride: null,
99
+ descentOverride: null,
100
+ display: null,
101
+ featureSettings: null,
102
+ fontFamily: meta.fontFamily,
103
+ fontData,
104
+ fontUrl: font,
105
+ format: "woff2",
106
+ lineGapOverride: null,
107
+ style: style2,
108
+ weight,
109
+ stretch: null,
110
+ unicodeRange: meta.unicodeRanges[subset] ?? null,
111
+ variant: null
112
+ });
113
+ };
114
+ let attempts = 2;
115
+ const tryToLoad = () => {
116
+ return NoReactInternals.fetchFontData(font).then((fontData) => {
117
+ const fontFace = new FontFace(meta.fontFamily, fontData, {
118
+ weight,
119
+ style: style2,
120
+ unicodeRange: meta.unicodeRanges[subset]
121
+ });
122
+ return loadFontFaceOrTimeoutAfter20Seconds(fontFace).then(() => {
123
+ (options?.document ?? document).fonts.add(fontFace);
124
+ registerFont(fontData);
125
+ continueRender(handle);
126
+ });
127
+ }).catch((err) => {
128
+ if (attempts === 0) {
129
+ loadedFonts[fontKey] = undefined;
130
+ throw err;
131
+ }
132
+ attempts--;
133
+ return tryToLoad();
134
+ });
135
+ };
136
+ const promise = tryToLoad();
137
+ loadedFonts[fontKey] = promise;
138
+ promises.push(promise);
139
+ }
140
+ }
141
+ if (fontsLoaded > 20 && !options?.ignoreTooManyRequestsWarning) {
142
+ console.warn(`Made ${fontsLoaded} network requests to load fonts for ${meta.fontFamily}. Consider loading fewer weights and subsets by passing options to loadFont(). Disable this warning by passing "ignoreTooManyRequestsWarning: true" to "options".`);
143
+ }
144
+ }
145
+ return {
146
+ fontFamily: meta.fontFamily,
147
+ fonts: meta.fonts,
148
+ unicodeRanges: meta.unicodeRanges,
149
+ waitUntilDone: () => Promise.all(promises).then(() => {
150
+ return;
151
+ })
152
+ };
153
+ };
154
+ var loadVariableFonts = (meta, style, options) => {
155
+ if (!meta.variable) {
156
+ throw new Error(`${meta.fontFamily} is not available as a variable font`);
157
+ }
158
+ if (options.subsets.length === 0) {
159
+ throw new Error("Pass at least one subset to loadVariableFont()");
160
+ }
161
+ const fontFacesForStyle = meta.variable.fontFaces.filter((fontFace) => fontFace.style === style);
162
+ if (fontFacesForStyle.length === 0) {
163
+ throw new Error(`The variable font ${meta.fontFamily} does not have a style ${style}`);
164
+ }
165
+ const availableSubsetKeys = fontFacesForStyle.map((fontFace) => fontFace.subset);
166
+ const subsets = [
167
+ ...new Set(options.subsets.flatMap((requestedSubset) => resolveFontSubsetKeys({
168
+ availableSubsetKeys,
169
+ metaSubsets: meta.subsets,
170
+ requestedSubset
171
+ })))
172
+ ];
173
+ const promises = [];
174
+ for (const subset of subsets) {
175
+ if (typeof FontFace === "undefined") {
176
+ continue;
177
+ }
178
+ const font = fontFacesForStyle.find((fontFace) => fontFace.subset === subset);
179
+ if (!font) {
180
+ throw new Error(`subset: ${subset} is not available for the variable font '${meta.fontFamily}'`);
181
+ }
182
+ const fontKey = [
183
+ meta.fontFamily,
184
+ "variable",
185
+ font.style,
186
+ font.weight,
187
+ font.stretch,
188
+ font.subset,
189
+ font.src
190
+ ].join("-");
191
+ const previousPromise = loadedFonts[fontKey];
192
+ if (previousPromise) {
193
+ promises.push(previousPromise);
194
+ continue;
195
+ }
196
+ const handle = delayRender(`Fetching variable ${meta.fontFamily} font ${JSON.stringify({
197
+ style,
198
+ subset
199
+ })}`, { timeoutInMilliseconds: 60000 });
200
+ const descriptors = {
201
+ style: font.style,
202
+ weight: font.weight,
203
+ unicodeRange: font.unicodeRange
204
+ };
205
+ if (font.stretch) {
206
+ descriptors.stretch = font.stretch;
207
+ }
208
+ const registerFont = (fontData) => {
209
+ NoReactInternals.registerFontFace({
210
+ ascentOverride: null,
211
+ descentOverride: null,
212
+ display: null,
213
+ featureSettings: null,
214
+ fontFamily: meta.fontFamily,
215
+ fontData,
216
+ fontUrl: font.src,
217
+ format: "woff2",
218
+ lineGapOverride: null,
219
+ style: font.style,
220
+ weight: font.weight,
221
+ stretch: font.stretch,
222
+ unicodeRange: font.unicodeRange,
223
+ variant: null
224
+ });
225
+ };
226
+ let attempts = 2;
227
+ const tryToLoad = () => {
228
+ return NoReactInternals.fetchFontData(font.src).then((fontData) => {
229
+ const fontFace = new FontFace(meta.fontFamily, fontData, descriptors);
230
+ return loadFontFaceOrTimeoutAfter20Seconds(fontFace).then(() => {
231
+ (options.document ?? document).fonts.add(fontFace);
232
+ registerFont(fontData);
233
+ continueRender(handle);
234
+ });
235
+ }).catch((err) => {
236
+ if (attempts === 0) {
237
+ loadedFonts[fontKey] = undefined;
238
+ throw err;
239
+ }
240
+ attempts--;
241
+ return tryToLoad();
242
+ });
243
+ };
244
+ const promise = tryToLoad();
245
+ loadedFonts[fontKey] = promise;
246
+ promises.push(promise);
247
+ }
248
+ if (subsets.length > 20 && !options.ignoreTooManyRequestsWarning) {
249
+ console.warn(`Made ${subsets.length} network requests to load the variable font ${meta.fontFamily}. Consider loading fewer subsets. Disable this warning by passing "ignoreTooManyRequestsWarning: true" to "options".`);
250
+ }
251
+ return {
252
+ fontFamily: meta.fontFamily,
253
+ axes: meta.variable.axes,
254
+ waitUntilDone: () => Promise.all(promises).then(() => {
255
+ return;
256
+ })
257
+ };
258
+ };
259
+
260
+ // src/Kripa.ts
261
+ var getInfo = () => ({
262
+ fontFamily: "Kripa",
263
+ importName: "Kripa",
264
+ version: "v2",
265
+ url: "https://fonts.googleapis.com/css2?family=Kripa:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900",
266
+ unicodeRanges: {
267
+ devanagari: "U+0900-097F, U+1CD0-1CF9, U+200C-200D, U+20A8, U+20B9, U+20F0, U+25CC, U+A830-A839, U+A8E0-A8FF, U+11B00-11B09",
268
+ vietnamese: "U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB",
269
+ "latin-ext": "U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF",
270
+ latin: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"
271
+ },
272
+ fonts: {
273
+ normal: {
274
+ "100": {
275
+ devanagari: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhU6K0Hew.woff2",
276
+ vietnamese: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzha6K0Hew.woff2",
277
+ "latin-ext": "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzhb6K0Hew.woff2",
278
+ latin: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhV6K0.woff2"
279
+ },
280
+ "200": {
281
+ devanagari: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhU6K0Hew.woff2",
282
+ vietnamese: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzha6K0Hew.woff2",
283
+ "latin-ext": "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzhb6K0Hew.woff2",
284
+ latin: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhV6K0.woff2"
285
+ },
286
+ "300": {
287
+ devanagari: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhU6K0Hew.woff2",
288
+ vietnamese: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzha6K0Hew.woff2",
289
+ "latin-ext": "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzhb6K0Hew.woff2",
290
+ latin: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhV6K0.woff2"
291
+ },
292
+ "400": {
293
+ devanagari: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhU6K0Hew.woff2",
294
+ vietnamese: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzha6K0Hew.woff2",
295
+ "latin-ext": "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzhb6K0Hew.woff2",
296
+ latin: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhV6K0.woff2"
297
+ },
298
+ "500": {
299
+ devanagari: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhU6K0Hew.woff2",
300
+ vietnamese: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzha6K0Hew.woff2",
301
+ "latin-ext": "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzhb6K0Hew.woff2",
302
+ latin: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhV6K0.woff2"
303
+ },
304
+ "600": {
305
+ devanagari: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhU6K0Hew.woff2",
306
+ vietnamese: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzha6K0Hew.woff2",
307
+ "latin-ext": "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzhb6K0Hew.woff2",
308
+ latin: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhV6K0.woff2"
309
+ },
310
+ "700": {
311
+ devanagari: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhU6K0Hew.woff2",
312
+ vietnamese: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzha6K0Hew.woff2",
313
+ "latin-ext": "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzhb6K0Hew.woff2",
314
+ latin: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhV6K0.woff2"
315
+ },
316
+ "800": {
317
+ devanagari: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhU6K0Hew.woff2",
318
+ vietnamese: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzha6K0Hew.woff2",
319
+ "latin-ext": "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzhb6K0Hew.woff2",
320
+ latin: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhV6K0.woff2"
321
+ },
322
+ "900": {
323
+ devanagari: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhU6K0Hew.woff2",
324
+ vietnamese: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzha6K0Hew.woff2",
325
+ "latin-ext": "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzhb6K0Hew.woff2",
326
+ latin: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhV6K0.woff2"
327
+ }
328
+ }
329
+ },
330
+ subsets: ["devanagari", "latin", "latin-ext", "vietnamese"],
331
+ variable: {
332
+ axes: {
333
+ wght: {
334
+ min: 100,
335
+ max: 900
336
+ }
337
+ },
338
+ fontFaces: [
339
+ {
340
+ style: "normal",
341
+ weight: "100 900",
342
+ stretch: null,
343
+ subset: "devanagari",
344
+ unicodeRange: "U+0900-097F, U+1CD0-1CF9, U+200C-200D, U+20A8, U+20B9, U+20F0, U+25CC, U+A830-A839, U+A8E0-A8FF, U+11B00-11B09",
345
+ src: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhU6K0Hew.woff2"
346
+ },
347
+ {
348
+ style: "normal",
349
+ weight: "100 900",
350
+ stretch: null,
351
+ subset: "vietnamese",
352
+ unicodeRange: "U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB",
353
+ src: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzha6K0Hew.woff2"
354
+ },
355
+ {
356
+ style: "normal",
357
+ weight: "100 900",
358
+ stretch: null,
359
+ subset: "latin-ext",
360
+ unicodeRange: "U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF",
361
+ src: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2Kyyzhb6K0Hew.woff2"
362
+ },
363
+ {
364
+ style: "normal",
365
+ weight: "100 900",
366
+ stretch: null,
367
+ subset: "latin",
368
+ unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD",
369
+ src: "https://fonts.gstatic.com/s/kripa/v2/UMBcrPhJt2KyyzhV6K0.woff2"
370
+ }
371
+ ],
372
+ url: "https://fonts.googleapis.com/css2?family=Kripa:wght@100..900"
373
+ }
374
+ });
375
+ var fontFamily = "Kripa";
376
+ var loadFont = (style, options) => {
377
+ return loadFonts(getInfo(), style, options);
378
+ };
379
+ var loadVariableFont = (style, options) => {
380
+ return loadVariableFonts(getInfo(), style, options);
381
+ };
382
+ export {
383
+ loadVariableFont,
384
+ loadFont,
385
+ getInfo,
386
+ fontFamily
387
+ };