//@ts-check const createOptions = () => ({ name: "my-custom-element", css: ":host{}", html: "", ParentClass: HTMLElement, observedAttributes: /** @type {string[]}*/ ([]), }); /** * WIP: minimal API for custom elements. Do not use! * @typedef {ReturnType} Options * @param {Partial} [options] */ export const createCustomElement = (options) => { const { name, css, html, observedAttributes: attrs, ParentClass, } = { ...createOptions(), ...options }; class CustomClass extends ParentClass { static template = document.createElement("template"); static stylesheet = new CSSStyleSheet(); constructor(){ super() } /** * Registers the custom element. If it was already registered, this is a no-op. * @param {string} tag */ static define(tag = name) { if (!customElements.get(tag)) { customElements.define(tag, this); } } static get observedAttributes() { return attrs; } attributeChangedCallback(property, oldValue, newValue) { if (oldValue === newValue) { return; } this[property] = newValue; } /** @type {AbortController|null} */ _abortController = null; /** * If no