Skip to content

Commit

Permalink
feat: injectCss parent option
Browse files Browse the repository at this point in the history
  • Loading branch information
lideming committed Oct 31, 2023
1 parent b028e29 commit 6235617
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/lib/viewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ export function listenEvents<K extends Array<keyof HTMLElementEventMap>>(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 {
Expand Down
15 changes: 9 additions & 6 deletions src/lib/viewlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/

1 comment on commit 6235617

@vercel
Copy link

@vercel vercel bot commented on 6235617 Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

webfx – ./

webfx.yuuza.net
webfx-git-master-lideming.vercel.app
webfx-lideming.vercel.app

Please sign in to comment.