* Searches a DOM document's head element for style elements with a matching application * identifier attribute (`ng-app-id`) to the provide identifier and adds usage records for each. * @param doc An HTML DOM document instance. * @param appId A string containing an Angular application identifer.
( doc: Document, appId: string, inline: Map<string, UsageRecord<HTMLStyleElement>>, external: Map<string, UsageRecord<HTMLLinkElement>>, )
| 63 | * @returns Whether or not styles were added. |
| 64 | */ |
| 65 | function addServerStyles( |
| 66 | doc: Document, |
| 67 | appId: string, |
| 68 | inline: Map<string, UsageRecord<HTMLStyleElement>>, |
| 69 | external: Map<string, UsageRecord<HTMLLinkElement>>, |
| 70 | ): boolean { |
| 71 | const elements = doc.head?.querySelectorAll<HTMLStyleElement | HTMLLinkElement>( |
| 72 | `style[${APP_ID_ATTRIBUTE_NAME}="${appId}"],link[${APP_ID_ATTRIBUTE_NAME}="${appId}"]`, |
| 73 | ); |
| 74 | |
| 75 | if (!elements || elements.length === 0) return false; |
| 76 | |
| 77 | for (const styleElement of elements) { |
| 78 | styleElement.removeAttribute(APP_ID_ATTRIBUTE_NAME); |
| 79 | if (styleElement instanceof HTMLLinkElement) { |
| 80 | // Only use filename from href |
| 81 | // The href is build time generated with a unique value to prevent duplicates. |
| 82 | external.set(styleElement.href.slice(styleElement.href.lastIndexOf('/') + 1), { |
| 83 | usage: 0, |
| 84 | elements: [styleElement], |
| 85 | }); |
| 86 | } else if (styleElement.textContent) { |
| 87 | inline.set(styleElement.textContent, {usage: 0, elements: [styleElement]}); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Creates a `link` element for the provided external style URL. |
no test coverage detected
searching dependent graphs…