import { HElement, HElements, HFnc, HObj, HTagAttrs, HTagChildren, HTagHead } from "./hsml"; export function h(tag: HTagHead): HElement; export function h(tag: HTagHead, children: HTagChildren): HElement; export function h(tag: HTagHead, text: string | String | boolean | Boolean | number | Number | Date | null): HElement; export function h(tag: HTagHead, hfnc: HFnc): HElement; export function h(tag: HTagHead, hobj: HObj): HElement; export function h(tag: HTagHead, helement: HElement): HElement; export function h(tag: HTagHead, helements: HElements): HElement; export function h(tag: HTagHead, attrs: HTagAttrs): HElement; export function h(tag: HTagHead, attrs: HTagAttrs, children: HTagChildren): HElement; export function h(tag: HTagHead, attrs: HTagAttrs, text: string | String | boolean | Boolean | number | Number | Date | null): HElement; export function h(tag: HTagHead, attrs: HTagAttrs, hfnc: HFnc): HElement; export function h(tag: HTagHead, attrs: HTagAttrs, hobj: HObj): HElement; export function h(tag: HTagHead, attrs: HTagAttrs, helement: HElement): HElement; export function h(tag: HTagHead, attrs: HTagAttrs, helements: HElements): HElement; export function h( tag: HTagHead, second?: HTagAttrs | HTagChildren | HElement, third?: HTagAttrs | HTagChildren | HElement): HElement { switch (arguments.length) { case 1: return [tag] as HElement; case 2: if (isHElement(second)) { // HElement - wrap in children array return [tag, [second]] as HElement; } else { return [tag, second] as HElement; } case 3: default: if (isHElement(third)) { // HElement - wrap in children array return [tag, second, [third]] as HElement; } else { return [tag, second, third] as HElement; } } } function isHElement(arg: any): boolean { return Array.isArray(arg) && arg.length > 0 && typeof arg[0] === "string"; }