Skip to content

🎥 Make videos programmatically with React

conditional types for v5

Igor Samokhovets8bfa2d5d6f8f
diff --git a/packages/google-fonts/src/base.ts b/packages/google-fonts/src/base.ts
index d6424f4fea..0cb0682901 100644
--- a/packages/google-fonts/src/base.ts
+++ b/packages/google-fonts/src/base.ts
@@ -1,5 +1,5 @@
import {continueRender, delayRender} from 'remotion';
-import {NoReactInternals} from 'remotion/src/no-react';
+import {NoReactInternals} from 'remotion/no-react';
const loadedFonts: Record<string, Promise<void> | undefined> = {};
@@ -27,6 +27,22 @@ const loadFontFaceOrTimeoutAfter20Seconds = (fontFace: FontFace) => {
]);
};
+type FontLoadOptions = {
+ document?: Document;
+ ignoreTooManyRequestsWarning?: boolean;
+};
+
+type V4Options = FontLoadOptions & {
+ weights?: string[];
+ subsets?: string[];
+};
+
+// weights and subsets are required in v5
+type V5Options = FontLoadOptions & {
+ weights: string[];
+ subsets: string[];
+};
+
/**
* @description Load a Google Font for use in Remotion.
* @param meta
@@ -38,12 +54,9 @@ const loadFontFaceOrTimeoutAfter20Seconds = (fontFace: FontFace) => {
export const loadFonts = (
meta: FontInfo,
style?: string,
- options?: {
- weights?: string[];
- subsets?: string[];
- document?: Document;
- ignoreTooManyRequestsWarning?: boolean;
- },
+ options?: typeof NoReactInternals.ENABLE_V5_BREAKING_CHANGES extends true
+ ? V5Options
+ : V4Options,
): {
fontFamily: FontInfo['fontFamily'];
fonts: FontInfo['fonts'];