From 4e99a3325318c902cd78ea9f760f46d79acde5c0 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 3 Oct 2022 11:28:16 +0200 Subject: riesencommit (part 1) --- client-web/source/helper.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'client-web/source/helper.ts') diff --git a/client-web/source/helper.ts b/client-web/source/helper.ts index 1ec42aa..d43fc3e 100644 --- a/client-web/source/helper.ts +++ b/client-web/source/helper.ts @@ -7,24 +7,24 @@ import { PREFS } from "./preferences/mod.ts"; -const elem = (s: string) => document.createElement(s) +const elem = (s: K): HTMLElementTagNameMap[K] => document.createElement(s) -interface Opts { class?: string[] | string, id?: string, src?: string, onclick?: (e: HTMLElement) => void } +interface Opts { class?: string[] | string, id?: string, src?: string, onclick?: (e: El) => void } -function apply_opts(e: HTMLElement, o: Opts | undefined) { +function apply_opts(e: El, o: Opts | undefined) { if (!o) return if (o.id) e.id = o.id if (o.onclick) e.onclick = () => o.onclick!(e) if (typeof o?.class == "string") e.classList.add(o.class) if (typeof o?.class == "object") e.classList.add(...o.class) } -const elem_with_content = (s: string) => (c: string, opts?: Opts) => { +const elem_with_content = (s: K) => (c: string, opts?: Opts) => { const e = elem(s) apply_opts(e, opts) e.textContent = c return e } -const elem_with_children = (s: string) => (opts?: Opts, ...cs: (HTMLElement | string)[]) => { +const elem_with_children = (s: K) => (opts?: Opts, ...cs: (HTMLElement | string)[]) => { const e = elem(s) apply_opts(e, opts) for (const c of cs) { @@ -65,7 +65,7 @@ export class OverlayUi { } } -export function image_view(url: string, opts?: Opts): HTMLElement { +export function image_view(url: string, opts?: Opts): HTMLElement { const img = document.createElement("img") apply_opts(img, opts) img.src = url -- cgit v1.2.3-70-g09d2