interface Opts { class?: string[] | string, id?: string, src?: string, for?: string, type?: string, href?: string, onclick?: (e: E) => void, onchange?: (e: E) => void, } function apply_opts(e: E, o: Opts) { if (o.id) e.id = o.id if (o.onclick) e.onclick = () => o.onclick!(e) if (o.onchange) e.onchange = () => o.onchange!(e) if (o.for) (e as unknown as HTMLLabelElement).htmlFor = o.for if (o.type && e instanceof HTMLInputElement) e.type = o.type if (o.href && e instanceof HTMLAnchorElement) e.href = o.href; if (typeof o?.class == "string") e.classList.add(o.class) if (typeof o?.class == "object") e.classList.add(...o.class) } export function e(name: K, opts: Opts, ...children: (HTMLElement | string)[]): HTMLElementTagNameMap[K] { const el = document.createElement(name) apply_opts(el, opts) for (const c of children) { if (typeof c == "string") el.textContent += c; else el.append(c) } return el }