auto-claude: subtask-3-2 - Add JSDoc to fontLoader.ts
This commit is contained in:
+18
-5
@@ -1,4 +1,13 @@
|
|||||||
// Font loading utility to ensure fonts are loaded before showing content
|
/**
|
||||||
|
* Font Loading Utility
|
||||||
|
* Ensures fonts are loaded before showing content to prevent FOUT/FOIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preload fonts asynchronously
|
||||||
|
* Uses the Font Loading API to ensure Inter font is loaded
|
||||||
|
* Falls back to system fonts on error
|
||||||
|
*/
|
||||||
export const preloadFonts = async () => {
|
export const preloadFonts = async () => {
|
||||||
if ('fonts' in document) {
|
if ('fonts' in document) {
|
||||||
try {
|
try {
|
||||||
@@ -12,14 +21,18 @@ export const preloadFonts = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Call this function as early as possible
|
/**
|
||||||
|
* Initialize font loading process
|
||||||
|
* Should be called as early as possible in the application lifecycle
|
||||||
|
* Adds loading state and fallback timeout to prevent indefinite loading
|
||||||
|
*/
|
||||||
export const initializeFonts = () => {
|
export const initializeFonts = () => {
|
||||||
// Add loading class immediately
|
// Add loading class immediately
|
||||||
document.documentElement.classList.add('fonts-loading');
|
document.documentElement.classList.add('fonts-loading');
|
||||||
|
|
||||||
// Start font loading
|
// Start font loading
|
||||||
preloadFonts();
|
preloadFonts();
|
||||||
|
|
||||||
// Remove loading class after a timeout to prevent indefinite loading state
|
// Remove loading class after a timeout to prevent indefinite loading state
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
document.documentElement.classList.remove('fonts-loading');
|
document.documentElement.classList.remove('fonts-loading');
|
||||||
@@ -27,4 +40,4 @@ export const initializeFonts = () => {
|
|||||||
document.documentElement.classList.add('fonts-fallback');
|
document.documentElement.classList.add('fonts-fallback');
|
||||||
}
|
}
|
||||||
}, 3000);
|
}, 3000);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user