(anchor, css)
| 8 | * @param {{ hash: string, code: string }} css |
| 9 | */ |
| 10 | export function append_styles(anchor, css) { |
| 11 | // Use `queue_micro_task` to ensure `anchor` is in the DOM, otherwise getRootNode() will yield wrong results |
| 12 | effect(() => { |
| 13 | var root = anchor.getRootNode(); |
| 14 | |
| 15 | var target = /** @type {ShadowRoot} */ (root).host |
| 16 | ? /** @type {ShadowRoot} */ (root) |
| 17 | : /** @type {Document} */ (root).head ?? /** @type {Document} */ (root.ownerDocument).head; |
| 18 | |
| 19 | // Always querying the DOM is roughly the same perf as additionally checking for presence in a map first assuming |
| 20 | // that you'll get cache hits half of the time, so we just always query the dom for simplicity and code savings. |
| 21 | if (!target.querySelector('#' + css.hash)) { |
| 22 | const style = create_element('style'); |
| 23 | style.id = css.hash; |
| 24 | style.textContent = css.code; |
| 25 | |
| 26 | target.appendChild(style); |
| 27 | |
| 28 | if (DEV) { |
| 29 | register_style(css.hash, style); |
| 30 | } |
| 31 | } |
| 32 | }); |
| 33 | } |
nothing calls this directly
no test coverage detected