From a658e571ef245a200884ea96198c54188ae650da Mon Sep 17 00:00:00 2001 From: Josh Kingsley Date: Sat, 25 Oct 2025 16:24:53 +0300 Subject: feat(web): setup components --- web/html.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 web/html.ts (limited to 'web/html.ts') diff --git a/web/html.ts b/web/html.ts new file mode 100644 index 0000000..5bfff21 --- /dev/null +++ b/web/html.ts @@ -0,0 +1,26 @@ +export type CreateElement = { + (...children: (Node | string)[]): T; + (attrs: Partial, ...children: (Node | string)[]): T; +}; + +type ElementCreator = { + [K in keyof HTMLElementTagNameMap]: CreateElement; +}; + +const h = new Proxy({} as ElementCreator, { + get: + (_, tag: string) => + (...args: any[]) => { + const el = document.createElement(tag); + + if (typeof args[0] === "object") { + Object.assign(el, args.shift()); + } + + el.append(...args.flat()); + + return el; + }, +}); + +export default h; -- cgit v1.2.3