Skip to content

Commit 65dd7c0

Browse files
authored
wip: HTMLElementAttributeMap 7
1 parent 0bcb115 commit 65dd7c0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/types.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type MediaQuery = string
7373

7474
// based on HTML Living Standard (March 6, 2025)
7575
// https://html.spec.whatwg.org/multipage/dom.html#global-attributes
76-
type HTMLElementGlobalAttribute = {
76+
type HTMLElementGlobalAttributes = {
7777
id: string
7878
class: string // TODO: allow array
7979

@@ -115,15 +115,19 @@ type HTMLElementGlobalAttribute = {
115115
exportparts: string // CSS Shadow Parts
116116
}
117117

118+
// ---------- Factory ----------
119+
118120
type HTMLElementAttributeFactory<T extends Record<string, object>> = {
119-
[K in keyof T | Exclude<keyof HTMLElementTagNameMap, keyof T>]: Partial<HTMLElementGlobalAttribute & (K extends keyof T ? T[K] : {})>
121+
[K in keyof T | Exclude<keyof HTMLElementTagNameMap, keyof T>]: Partial<HTMLElementGlobalAttributes & (K extends keyof T ? T[K] : {})>
120122
}
121123

122124
type HTMLMetaElementAttributeFactory<T extends [string, unknown, object?]> = {
123125
name: T[0]
124126
content: T[1]
125127
} & T[2]
126128

129+
// --------------------
130+
127131
// https://html.spec.whatwg.org/#elements-3
128132
export type HTMLElementAttributeMap = HTMLElementAttributeFactory<{
129133
a: {
@@ -165,7 +169,13 @@ export type HTMLElementAttributeMap = HTMLElementAttributeFactory<{
165169
blockquote: {
166170
cite: string
167171
}
168-
body: {} // generate from WindowEventHandlersEventMap
172+
body: {
173+
[key in Exclude<keyof WindowEventHandlersEventMap,
174+
// not found in https://html.spec.whatwg.org/#the-body-element
175+
"gamepaddisconnected" | "gamepaddisconnected"
176+
>as `on${key}`]: ((this: HTMLBodyElement, event: WindowEventHandlersEventMap[key]) => unknown)
177+
// onafterprint: ((this: WindowEventHandlers, ev: Event) => any) | null;
178+
}
169179
button: {
170180
command: "toggle-popover" | "show-popover" | "hide-popover" | "close" | "show-modal" | `--${string}` // Experimental
171181
commandfor: string // Experimental

0 commit comments

Comments
 (0)