(nonce?: string, target?: ShadowRoot)
| 390 | * @param target - The shadow root to add the style tag to, instead of `document.head`. |
| 391 | */ |
| 392 | export const setupStyleSheet = (nonce?: string, target?: ShadowRoot) => { |
| 393 | if (!nonce) |
| 394 | return // Goober reads window.__nonce__ every time it creates or accesses its style |
| 395 | // element (el.nonce = window.__nonce__). Without this, goober overwrites the |
| 396 | // nonce we set on the pre-created element with undefined, clearing it. |
| 397 | ;(window as any).__nonce__ = nonce |
| 398 | |
| 399 | const root = target ?? document.head |
| 400 | if (root.querySelector('#_goober')) return |
| 401 | const styleTag = document.createElement('style') |
| 402 | const textNode = document.createTextNode('') |
| 403 | styleTag.appendChild(textNode) |
| 404 | styleTag.id = '_goober' |
| 405 | styleTag.setAttribute('nonce', nonce) |
| 406 | root.appendChild(styleTag) |
| 407 | } |
no outgoing calls
no test coverage detected