2024-07-02 22:16:37 -07:00
|
|
|
class OutfitLayer extends HTMLElement {
|
2024-07-02 22:34:51 -07:00
|
|
|
#internals;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.#internals = this.attachInternals();
|
|
|
|
}
|
|
|
|
|
2024-07-02 22:16:37 -07:00
|
|
|
connectedCallback() {
|
|
|
|
setTimeout(() => this.#initializeImage(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#initializeImage() {
|
|
|
|
this.image = this.querySelector("img");
|
|
|
|
if (!this.image) {
|
|
|
|
throw new Error(`<outfit-layer> must contain an <img> tag`);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.image.addEventListener("load", () => this.#setStatus("loaded"));
|
|
|
|
this.image.addEventListener("error", () => this.#setStatus("error"));
|
|
|
|
|
|
|
|
this.#setStatus(this.image.complete ? "loaded" : "loading");
|
|
|
|
}
|
|
|
|
|
|
|
|
#setStatus(newStatus) {
|
2024-07-02 22:34:51 -07:00
|
|
|
this.#internals.states.clear();
|
|
|
|
this.#internals.states.add(newStatus);
|
2024-07-02 22:16:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("outfit-layer", OutfitLayer);
|