Skip to content

Commit

Permalink
use HTMLElementTagNameMap to define Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericHeem committed Sep 14, 2024
1 parent 2de975e commit 3b2698b
Showing 1 changed file with 4 additions and 110 deletions.
114 changes: 4 additions & 110 deletions bau/bau.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,118 +135,12 @@ export type TagFunc<Result extends HTMLElement> = (
...rest: readonly ChildDom[]
) => Result;

interface TagsBase {
readonly [key: string]: TagFunc<HTMLElement>;
}

interface Tags extends TagsBase {
// Register known element types
// Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element

// Main root
readonly html: TagFunc<HTMLHtmlElement>;

// Document metadata
readonly base: TagFunc<HTMLBaseElement>;
readonly head: TagFunc<HTMLHeadElement>;
readonly link: TagFunc<HTMLLinkElement>;
readonly meta: TagFunc<HTMLMetaElement>;
readonly style: TagFunc<HTMLStyleElement>;
readonly title: TagFunc<HTMLTitleElement>;

// Sectioning root
readonly body: TagFunc<HTMLBodyElement>;

// Content sectioning
readonly h1: TagFunc<HTMLHeadingElement>;
readonly h2: TagFunc<HTMLHeadingElement>;
readonly h3: TagFunc<HTMLHeadingElement>;
readonly h4: TagFunc<HTMLHeadingElement>;
readonly h5: TagFunc<HTMLHeadingElement>;
readonly h6: TagFunc<HTMLHeadingElement>;

// Text content
readonly blockquote: TagFunc<HTMLQuoteElement>;
readonly div: TagFunc<HTMLDivElement>;
readonly dl: TagFunc<HTMLDListElement>;
readonly hr: TagFunc<HTMLHRElement>;
readonly li: TagFunc<HTMLLIElement>;
readonly menu: TagFunc<HTMLMenuElement>;
readonly ol: TagFunc<HTMLOListElement>;
readonly p: TagFunc<HTMLParagraphElement>;
readonly pre: TagFunc<HTMLPreElement>;
readonly ul: TagFunc<HTMLUListElement>;

// Inline text semantics
readonly a: TagFunc<HTMLAnchorElement>;
readonly br: TagFunc<HTMLBRElement>;
readonly data: TagFunc<HTMLDataElement>;
readonly q: TagFunc<HTMLQuoteElement>;
readonly span: TagFunc<HTMLSpanElement>;
readonly time: TagFunc<HTMLTimeElement>;

// Image and multimedia
readonly area: TagFunc<HTMLAreaElement>;
readonly audio: TagFunc<HTMLAudioElement>;
readonly img: TagFunc<HTMLImageElement>;
readonly map: TagFunc<HTMLMapElement>;
readonly track: TagFunc<HTMLTrackElement>;
readonly video: TagFunc<HTMLVideoElement>;

// Embedded content
readonly embed: TagFunc<HTMLEmbedElement>;
readonly iframe: TagFunc<HTMLIFrameElement>;
readonly object: TagFunc<HTMLObjectElement>;
readonly picture: TagFunc<HTMLPictureElement>;
readonly source: TagFunc<HTMLSourceElement>;

// Scripting
readonly canvas: TagFunc<HTMLCanvasElement>;
readonly script: TagFunc<HTMLScriptElement>;

// Demarcating edits
readonly del: TagFunc<HTMLModElement>;
readonly ins: TagFunc<HTMLModElement>;

// Table content
readonly caption: TagFunc<HTMLTableCaptionElement>;
readonly col: TagFunc<HTMLTableColElement>;
readonly colgroup: TagFunc<HTMLTableColElement>;
readonly table: TagFunc<HTMLTableElement>;
readonly tbody: TagFunc<HTMLTableSectionElement>;
readonly td: TagFunc<HTMLTableCellElement>;
readonly tfoot: TagFunc<HTMLTableSectionElement>;
readonly th: TagFunc<HTMLTableCellElement>;
readonly thead: TagFunc<HTMLTableSectionElement>;
readonly tr: TagFunc<HTMLTableRowElement>;

// Forms
readonly button: TagFunc<HTMLButtonElement>;
readonly datalist: TagFunc<HTMLDataListElement>;
readonly fieldset: TagFunc<HTMLFieldSetElement>;
readonly form: TagFunc<HTMLFormElement>;
readonly input: TagFunc<HTMLInputElement>;
readonly label: TagFunc<HTMLLabelElement>;
readonly legend: TagFunc<HTMLLegendElement>;
readonly meter: TagFunc<HTMLMeterElement>;
readonly optgroup: TagFunc<HTMLOptGroupElement>;
readonly option: TagFunc<HTMLOptionElement>;
readonly output: TagFunc<HTMLOutputElement>;
readonly progress: TagFunc<HTMLProgressElement>;
readonly select: TagFunc<HTMLSelectElement>;
readonly textarea: TagFunc<HTMLTextAreaElement>;

// Interactive elements
readonly details: TagFunc<HTMLDetailsElement>;
readonly dialog: TagFunc<HTMLDialogElement>;

// Web Components
readonly slot: TagFunc<HTMLSlotElement>;
readonly template: TagFunc<HTMLTemplateElement>;
}
type Tags = Readonly<Record<string, TagFunc<Element>>> & {
[K in keyof HTMLElementTagNameMap]: TagFunc<HTMLElementTagNameMap[K]>;
};

declare function state<T>(initVal: T): State<T>;
declare function tagsNS(namespaceURI: string): TagsBase;
declare function tagsNS(namespaceURI: string): Tags;
declare function bind(input: BindInput): HTMLElement;
declare function derive<T>(computed: () => T): ReadonlyState<T>;
declare function loop<T, TElement extends HTMLElement>(
Expand Down

0 comments on commit 3b2698b

Please sign in to comment.