Move styles into code

This commit is contained in:
Ian Gulliver
2024-12-22 16:52:01 -08:00
parent 81b102f44a
commit afe6eed9c2
9 changed files with 138 additions and 49 deletions

19
ts/document.ts Normal file
View File

@@ -0,0 +1,19 @@
export function whenLoaded(callback: () => void) {
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", callback);
} else {
callback();
}
}
export function addStyle(style: string) {
whenLoaded(() => {
addStyleNow(style);
});
}
export function addStyleNow(style: string) {
const sheet = new CSSStyleSheet();
sheet.replaceSync(style);
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
}