2024-12-23 14:09:06 -08:00
|
|
|
import { waitForEvent } from "./event";
|
|
|
|
|
|
|
|
|
|
export async function awaitLoaded() {
|
2024-12-22 16:52:01 -08:00
|
|
|
if (document.readyState === "loading") {
|
2024-12-23 14:09:06 -08:00
|
|
|
await waitForEvent(document, "DOMContentLoaded");
|
2024-12-22 16:52:01 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 14:09:06 -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];
|
|
|
|
|
}
|
2024-12-23 14:09:06 -08:00
|
|
|
|
|
|
|
|
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"),
|
|
|
|
|
]);
|
|
|
|
|
}
|