@knyt/luthier
Version:
A library for building standardized, type-safe native web components with full SSR and hydration support.
24 lines (23 loc) • 822 B
JavaScript
import {} from "@knyt/tasker";
export class HtmxIntegration {
#shadowRoot;
#htmxObject;
constructor(htmxInput, shadowRoot) {
this.#shadowRoot = shadowRoot;
if (typeof htmxInput === "object") {
// First, attempt to use the provided htmx option.
//The type assertion is necessary. See the `HtmxObject.Compat` type for more details.
this.#htmxObject = htmxInput;
}
else if (typeof htmx === "object") {
// Second, try to use the global `htmx` object.
this.#htmxObject = htmx;
}
else {
console.error(new Error("htmx must be either passed as an option to the element or made available globally."));
}
}
hostUpdated() {
this.#htmxObject?.process(this.#shadowRoot);
}
}