summaryrefslogtreecommitdiff
path: root/web/src/html.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/html.ts')
-rw-r--r--web/src/html.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/web/src/html.ts b/web/src/html.ts
new file mode 100644
index 0000000..5bfff21
--- /dev/null
+++ b/web/src/html.ts
@@ -0,0 +1,26 @@
+export type CreateElement<T extends HTMLElement> = {
+ (...children: (Node | string)[]): T;
+ (attrs: Partial<T>, ...children: (Node | string)[]): T;
+};
+
+type ElementCreator = {
+ [K in keyof HTMLElementTagNameMap]: CreateElement<HTMLElementTagNameMap[K]>;
+};
+
+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;