Files
t/ts/document.ts

30 lines
862 B
TypeScript
Raw Permalink Normal View History

import { waitForEvent } from "./event";
export async function awaitLoaded() {
2024-12-22 16:52:01 -08:00
if (document.readyState === "loading") {
await waitForEvent(document, "DOMContentLoaded");
2024-12-22 16:52:01 -08:00
}
}
export async function addStyle(style: string) {
await awaitLoaded();
addStyleNow(style);
2024-12-22 16:52:01 -08:00
}
export function addStyleNow(style: string) {
const sheet = new CSSStyleSheet();
sheet.replaceSync(style);
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
}
export async function awaitCustomElements() {
await Promise.allSettled([
customElements.whenDefined("sl-card"),
customElements.whenDefined("sl-icon"),
customElements.whenDefined("sl-input"),
customElements.whenDefined("sl-tab"),
customElements.whenDefined("sl-tab-group"),
customElements.whenDefined("sl-tab-panel"),
]);
}