| 20260 | return null; |
| 20261 | } |
| 20262 | async load(fonts) { |
| 20263 | let params = ""; |
| 20264 | const existingLang = Object.keys(this.rangesByLang); |
| 20265 | const langNeedsToLoad = fonts.filter((font) => !existingLang.includes(font)); |
| 20266 | if (langNeedsToLoad.length === 0) { |
| 20267 | return; |
| 20268 | } |
| 20269 | for (const font of langNeedsToLoad) { |
| 20270 | params += `family=${font}&`; |
| 20271 | } |
| 20272 | params += "display=swap"; |
| 20273 | const API = `https://fonts.googleapis.com/css2?${params}`; |
| 20274 | const fontFace = await (await fetch(API, { |
| 20275 | headers: { |
| 20276 | // Make sure it returns TTF. |
| 20277 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36" |
| 20278 | } |
| 20279 | })).text(); |
| 20280 | this.addDetectors(fontFace); |
| 20281 | } |
| 20282 | addDetectors(input) { |
| 20283 | const regex = /font-family:\s*'(.+?)';.+?unicode-range:\s*(.+?);/gms; |
| 20284 | const matches = input.matchAll(regex); |