-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmini-van-0.4.1.d.ts
More file actions
209 lines (179 loc) · 9.1 KB
/
mini-van-0.4.1.d.ts
File metadata and controls
209 lines (179 loc) · 9.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
export interface State<T> {
val: T
readonly oldVal: T
}
// Defining readonly view of State<T> for covariance.
// Basically we want StateView<string> to implement StateView<string | number>
export type StateView<T> = Readonly<State<T>>
export type Primitive = string | number | boolean | bigint
export type PropValue = Primitive | ((e: any) => void) | null
export type Props = Record<string, PropValue | StateView<PropValue> | (() => PropValue)>
export type ValidChildDomValue<ElementType, TextNodeType> =
Primitive | ElementType | TextNodeType | null | undefined
export type BindingFunc<ElementType, TextNodeType> =
| ((dom?: ElementType | TextNodeType) => ValidChildDomValue<ElementType, TextNodeType>)
| ((dom?: ElementType) => ElementType)
export type ChildDom<ElementType, TextNodeType> =
| ValidChildDomValue<ElementType, TextNodeType>
| StateView<Primitive | null | undefined>
| BindingFunc<ElementType, TextNodeType>
| readonly ChildDom<ElementType, TextNodeType>[]
type AddFunc<ElementType, TextNodeType> =
(dom: ElementType, ...children: readonly ChildDom<ElementType, TextNodeType>[]) => ElementType
export type TagFunc<ElementType, TextNodeType, ResultType = ElementType> =
(first?: Props | ChildDom<ElementType, TextNodeType>,
...rest: readonly ChildDom<ElementType, TextNodeType>[]) => ResultType
type Tags<ElementType, TextNodeType> = Record<string, TagFunc<ElementType, TextNodeType>>
// Tags type in browser context, which contains the signatures to tag functions that return
// specialized DOM elements.
interface BrowserTags extends Tags<Element, Text> {
// Register known element types
// Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element
// Main root
readonly html: TagFunc<Element, Text, HTMLHtmlElement>
// Document metadata
readonly base: TagFunc<Element, Text, HTMLBaseElement>
readonly head: TagFunc<Element, Text, HTMLHeadElement>
readonly link: TagFunc<Element, Text, HTMLLinkElement>
readonly meta: TagFunc<Element, Text, HTMLMetaElement>
readonly style: TagFunc<Element, Text, HTMLStyleElement>
readonly title: TagFunc<Element, Text, HTMLTitleElement>
// Sectioning root
readonly body: TagFunc<Element, Text, HTMLBodyElement>
// Content sectioning
readonly address: TagFunc<Element, Text, HTMLElement>
readonly article: TagFunc<Element, Text, HTMLElement>
readonly aside: TagFunc<Element, Text, HTMLElement>
readonly footer: TagFunc<Element, Text, HTMLElement>
readonly header: TagFunc<Element, Text, HTMLElement>
readonly h1: TagFunc<Element, Text, HTMLHeadingElement>
readonly h2: TagFunc<Element, Text, HTMLHeadingElement>
readonly h3: TagFunc<Element, Text, HTMLHeadingElement>
readonly h4: TagFunc<Element, Text, HTMLHeadingElement>
readonly h5: TagFunc<Element, Text, HTMLHeadingElement>
readonly h6: TagFunc<Element, Text, HTMLHeadingElement>
readonly hgroup: TagFunc<Element, Text, HTMLElement>
readonly main: TagFunc<Element, Text, HTMLElement>
readonly nav: TagFunc<Element, Text, HTMLElement>
readonly section: TagFunc<Element, Text, HTMLElement>
// Text content
readonly blockquote: TagFunc<Element, Text, HTMLQuoteElement>
readonly dd: TagFunc<Element, Text, HTMLElement>
readonly div: TagFunc<Element, Text, HTMLDivElement>
readonly dl: TagFunc<Element, Text, HTMLDListElement>
readonly dt: TagFunc<Element, Text, HTMLElement>
readonly figcaption: TagFunc<Element, Text, HTMLElement>
readonly figure: TagFunc<Element, Text, HTMLElement>
readonly hr: TagFunc<Element, Text, HTMLHRElement>
readonly li: TagFunc<Element, Text, HTMLLIElement>
readonly menu: TagFunc<Element, Text, HTMLMenuElement>
readonly ol: TagFunc<Element, Text, HTMLOListElement>
readonly p: TagFunc<Element, Text, HTMLParagraphElement>
readonly pre: TagFunc<Element, Text, HTMLPreElement>
readonly ul: TagFunc<Element, Text, HTMLUListElement>
// Inline text semantics
readonly a: TagFunc<Element, Text, HTMLAnchorElement>
readonly abbr: TagFunc<Element, Text, HTMLElement>
readonly b: TagFunc<Element, Text, HTMLElement>
readonly bdi: TagFunc<Element, Text, HTMLElement>
readonly bdo: TagFunc<Element, Text, HTMLElement>
readonly br: TagFunc<Element, Text, HTMLBRElement>
readonly cite: TagFunc<Element, Text, HTMLElement>
readonly code: TagFunc<Element, Text, HTMLElement>
readonly data: TagFunc<Element, Text, HTMLDataElement>
readonly dfn: TagFunc<Element, Text, HTMLElement>
readonly em: TagFunc<Element, Text, HTMLElement>
readonly i: TagFunc<Element, Text, HTMLElement>
readonly kbd: TagFunc<Element, Text, HTMLElement>
readonly mark: TagFunc<Element, Text, HTMLElement>
readonly q: TagFunc<Element, Text, HTMLQuoteElement>
readonly rp: TagFunc<Element, Text, HTMLElement>
readonly rt: TagFunc<Element, Text, HTMLElement>
readonly ruby: TagFunc<Element, Text, HTMLElement>
readonly s: TagFunc<Element, Text, HTMLElement>
readonly samp: TagFunc<Element, Text, HTMLElement>
readonly small: TagFunc<Element, Text, HTMLElement>
readonly span: TagFunc<Element, Text, HTMLSpanElement>
readonly strong: TagFunc<Element, Text, HTMLElement>
readonly sub: TagFunc<Element, Text, HTMLElement>
readonly sup: TagFunc<Element, Text, HTMLElement>
readonly time: TagFunc<Element, Text, HTMLTimeElement>
readonly u: TagFunc<Element, Text, HTMLElement>
readonly var: TagFunc<Element, Text, HTMLElement>
readonly wbr: TagFunc<Element, Text, HTMLElement>
// Image and multimedia
readonly area: TagFunc<Element, Text, HTMLAreaElement>
readonly audio: TagFunc<Element, Text, HTMLAudioElement>
readonly img: TagFunc<Element, Text, HTMLImageElement>
readonly map: TagFunc<Element, Text, HTMLMapElement>
readonly track: TagFunc<Element, Text, HTMLTrackElement>
readonly video: TagFunc<Element, Text, HTMLVideoElement>
// Embedded content
readonly embed: TagFunc<Element, Text, HTMLEmbedElement>
readonly iframe: TagFunc<Element, Text, HTMLIFrameElement>
readonly object: TagFunc<Element, Text, HTMLObjectElement>
readonly picture: TagFunc<Element, Text, HTMLPictureElement>
readonly source: TagFunc<Element, Text, HTMLSourceElement>
// Scripting
readonly canvas: TagFunc<Element, Text, HTMLCanvasElement>
readonly noscript: TagFunc<Element, Text, HTMLElement>
readonly script: TagFunc<Element, Text, HTMLScriptElement>
// Demarcating edits
readonly del: TagFunc<Element, Text, HTMLModElement>
readonly ins: TagFunc<Element, Text, HTMLModElement>
// Table content
readonly caption: TagFunc<Element, Text, HTMLTableCaptionElement>
readonly col: TagFunc<Element, Text, HTMLTableColElement>
readonly colgroup: TagFunc<Element, Text, HTMLTableColElement>
readonly table: TagFunc<Element, Text, HTMLTableElement>
readonly tbody: TagFunc<Element, Text, HTMLTableSectionElement>
readonly td: TagFunc<Element, Text, HTMLTableCellElement>
readonly tfoot: TagFunc<Element, Text, HTMLTableSectionElement>
readonly th: TagFunc<Element, Text, HTMLTableCellElement>
readonly thead: TagFunc<Element, Text, HTMLTableSectionElement>
readonly tr: TagFunc<Element, Text, HTMLTableRowElement>
// Forms
readonly button: TagFunc<Element, Text, HTMLButtonElement>
readonly datalist: TagFunc<Element, Text, HTMLDataListElement>
readonly fieldset: TagFunc<Element, Text, HTMLFieldSetElement>
readonly form: TagFunc<Element, Text, HTMLFormElement>
readonly input: TagFunc<Element, Text, HTMLInputElement>
readonly label: TagFunc<Element, Text, HTMLLabelElement>
readonly legend: TagFunc<Element, Text, HTMLLegendElement>
readonly meter: TagFunc<Element, Text, HTMLMeterElement>
readonly optgroup: TagFunc<Element, Text, HTMLOptGroupElement>
readonly option: TagFunc<Element, Text, HTMLOptionElement>
readonly output: TagFunc<Element, Text, HTMLOutputElement>
readonly progress: TagFunc<Element, Text, HTMLProgressElement>
readonly select: TagFunc<Element, Text, HTMLSelectElement>
readonly textarea: TagFunc<Element, Text, HTMLTextAreaElement>
// Interactive elements
readonly details: TagFunc<Element, Text, HTMLDetailsElement>
readonly dialog: TagFunc<Element, Text, HTMLDialogElement>
readonly summary: TagFunc<Element, Text, HTMLElement>
// Web Components
readonly slot: TagFunc<Element, Text, HTMLSlotElement>
readonly template: TagFunc<Element, Text, HTMLTemplateElement>
}
export interface VanObj<ElementType, TextNodeType> {
readonly state: <T>(initVal: T) => State<T>
readonly val: <T>(s: T | StateView<T>) => T
readonly oldVal: <T>(s: T | StateView<T>) => T
readonly derive: <T>(f: () => T) => State<T>
readonly add: AddFunc<ElementType, TextNodeType>
readonly _: (f: () => PropValue) => () => PropValue
readonly tags: Tags<ElementType, TextNodeType>
readonly tagsNS: (namespaceURI: string) => Tags<ElementType, TextNodeType>
// Mini-Van specific API
html: (first?: Props | ChildDom<ElementType, TextNodeType>,
...rest: readonly ChildDom<ElementType, TextNodeType>[]) => string
}
export interface Van extends VanObj<Element, Text> {
readonly vanWithDoc: <ElementType, TextNodeType>(doc: {
createElement(s: any): ElementType,
createTextNode(s: any): TextNodeType,
}) => VanObj<ElementType, TextNodeType>
readonly tags: BrowserTags
}
declare const van: Van
export default van