diff --git a/src/lib/viewUtils.ts b/src/lib/viewUtils.ts index 6b2890b..75a95eb 100644 --- a/src/lib/viewUtils.ts +++ b/src/lib/viewUtils.ts @@ -196,8 +196,9 @@ export function listenEvents>(element }; } -export function injectCss(css: string, options?: { tag: string; }) { - document.head.appendChild(buildDOM({ tag: options?.tag ?? 'style', text: css })); +export function injectCss(css: string, options?: { parent?: Node, tag?: string; }) { + const parent = options?.parent ?? document.head; + parent.appendChild(buildDOM({ tag: options?.tag ?? 'style', text: css })); } export class TextCompositionWatcher { diff --git a/src/lib/viewlib.ts b/src/lib/viewlib.ts index 3a4c443..9000b3b 100644 --- a/src/lib/viewlib.ts +++ b/src/lib/viewlib.ts @@ -3,13 +3,16 @@ import { injectCss } from "./viewUtils"; import css from "../../style.css"; -export function getWebfxCss() { return css; } +export function getWebfxCss() { + return css; +} + let cssInjected = false; -export function injectWebfxCss() { - if (!cssInjected) { - injectCss(getWebfxCss(), { tag: 'style.webfx-injected-style' }); - cssInjected = true; - } +export function injectWebfxCss(options?: { parent?: Node }) { + if (!cssInjected) { + injectCss(getWebfxCss(), { ...options, tag: "style.webfx-injected-style" }); + cssInjected = true; + } } // Views and helpers are moved to ../views/