diff options
| author | Josh Kingsley <josh@joshkingsley.me> | 2025-11-23 19:27:57 +0200 |
|---|---|---|
| committer | Josh Kingsley <josh@joshkingsley.me> | 2025-11-23 19:27:57 +0200 |
| commit | 602145c956bb594ca0d0e10601cc4ad1a71cf70d (patch) | |
| tree | d9f9980bd2054cff5819d01379f5c1c55f8eb66d /web/src/html.ts | |
| parent | c2a6efb1b761014a90d90373cad47a14054af40b (diff) | |
feat: integrate web and doc packages
Diffstat (limited to 'web/src/html.ts')
| -rw-r--r-- | web/src/html.ts | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/web/src/html.ts b/web/src/html.ts deleted file mode 100644 index 3fccda3..0000000 --- a/web/src/html.ts +++ /dev/null @@ -1,50 +0,0 @@ -export function createElement<T extends HTMLElement>( - tagName: string, - ...children: (Node | string)[] -): T; - -export function createElement<T extends HTMLElement>( - tagName: string, - attrs: Partial<T>, - ...children: (Node | string)[] -): T; - -export function createElement(tagName: string, ...args: any[]) { - const el = document.createElement(tagName); - - if (args[0]?.constructor === Object) { - const { dataset, style, ...attrs } = args.shift(); - Object.assign(el, attrs); - if (dataset) Object.assign(el.dataset, dataset); - if (style) Object.assign(el.style, style); - } - - el.append(...args.flat()); - - return el; -} - -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: - (_, tagName: string) => - (...args: any[]) => { - return createElement(tagName, ...args); - }, -}); - -export default h; - -export function fragment(...children: (Node | string)[]): DocumentFragment { - const fragment = document.createDocumentFragment(); - fragment.append(...children); - return fragment; -} |
