( href: string, contentWindow = window as Window )
| 350 | }); |
| 351 | |
| 352 | const loadStyle = ( |
| 353 | href: string, |
| 354 | contentWindow = window as Window |
| 355 | ): Promise<Event> => |
| 356 | new Promise((resolve, reject) => { |
| 357 | const loadedStyles = [ |
| 358 | ...contentWindow.document.querySelectorAll("link[rel=stylesheet]"), |
| 359 | ] as HTMLLinkElement[]; |
| 360 | |
| 361 | if (loadedStyles.some((loadedStyle) => loadedStyle.href.endsWith(href))) { |
| 362 | resolve(new Event("Already loaded.")); |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | const link = contentWindow.document.createElement("link"); |
| 367 | |
| 368 | link.rel = "stylesheet"; |
| 369 | link.fetchPriority = "high"; |
| 370 | link.href = href; |
| 371 | link.addEventListener("error", reject, ONE_TIME_PASSIVE_EVENT); |
| 372 | link.addEventListener("load", resolve, ONE_TIME_PASSIVE_EVENT); |
| 373 | |
| 374 | contentWindow.document.head.append(link); |
| 375 | }); |
| 376 | |
| 377 | export const loadFiles = async ( |
| 378 | files?: string[], |
no test coverage detected