(cacheKey: string, fontFaces: FontFace[])
| 71 | }; |
| 72 | |
| 73 | const triggerFontLoad = (cacheKey: string, fontFaces: FontFace[]) => { |
| 74 | if (fontStatusCache.has(cacheKey)) { |
| 75 | return; // Already loading or loaded. |
| 76 | } |
| 77 | |
| 78 | fontStatusCache.set(cacheKey, 'loading'); |
| 79 | |
| 80 | // Initial notification for the 'loading' state. |
| 81 | notify(cacheKey); |
| 82 | |
| 83 | const promises = fontFaces.map((font) => loadFont(font)); |
| 84 | |
| 85 | Promise.all(promises) |
| 86 | .then(() => { |
| 87 | fontStatusCache.set(cacheKey, 'loaded'); |
| 88 | }) |
| 89 | .catch((error) => { |
| 90 | fontStatusCache.set(cacheKey, 'failed'); |
| 91 | console.warn(`Failed to load font set: ${cacheKey}`, error); |
| 92 | }) |
| 93 | .finally(() => { |
| 94 | // Final notification for 'loaded' or 'failed' state. |
| 95 | notify(cacheKey); |
| 96 | }); |
| 97 | }; |
| 98 | |
| 99 | export const useFontStatus = ( |
| 100 | family: string, |
no test coverage detected