(nonce?: string, target?: ShadowRoot)
| 307 | // Sets up the goober stylesheet |
| 308 | // Adds a nonce to the style tag if needed |
| 309 | export const setupStyleSheet = (nonce?: string, target?: ShadowRoot) => { |
| 310 | if (!nonce) |
| 311 | return // Goober reads window.__nonce__ every time it creates or accesses its style |
| 312 | // element (el.nonce = window.__nonce__). Without this, goober overwrites the |
| 313 | // nonce we set on the pre-created element with undefined, clearing it. |
| 314 | ;(window as any).__nonce__ = nonce |
| 315 | |
| 316 | const root = target ?? document.head |
| 317 | if (root.querySelector('#_goober')) return |
| 318 | const styleTag = document.createElement('style') |
| 319 | const textNode = document.createTextNode('') |
| 320 | styleTag.appendChild(textNode) |
| 321 | styleTag.id = '_goober' |
| 322 | styleTag.setAttribute('nonce', nonce) |
| 323 | root.appendChild(styleTag) |
| 324 | } |
no outgoing calls
no test coverage detected