Skip to content

Commit b257dc9

Browse files
committed
0.12.3: disallow null as prop values in tag functions in van.d.ts
As of 0.12.3, `null` value is not supported as prop values in tag functions. Thus this release update van.d.ts file to keep it consistent. Supporting `null` in prop value in tag functions is a planned feature in 1.0.0 release. Thus the restriction will be released in that release.
1 parent 02dbf30 commit b257dc9

21 files changed

+1058
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Declarative DOM tree composition, reusable components, reactive state binding -
7979

8080
### Ultra-Lightweight
8181

82-
**VanJS** is a very thin layer on top of Vanilla JavaScript and DOM, barely enough to make the DOM manipulation and state binding as ergonomic as (if not more than) React, and it delegates most of work to standard browser APIs implemented in native code. As a result, the bundled size of **VanJS** is just 1.3kB (0.8kB gzipped), which is **more than 100 times** smaller than most popular UI frameworks, making it the smallest reactive UI framework in the world:
82+
**VanJS** is a very thin layer on top of Vanilla JavaScript and DOM, barely enough to make the DOM manipulation and state binding as ergonomic as (if not more than) React, and it delegates most of work to standard browser APIs implemented in native code. As a result, the bundled size of **VanJS** is just 1.3kB (0.8kB gzipped), which is **50~100 times** smaller than most popular UI frameworks, making it the smallest reactive UI framework in the world:
8383

8484
![Size comparison](doc/size_comp.png)
8585

doc/size_comp.png

785 Bytes
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "van-dom",
3-
"version": "0.12.2",
3+
"version": "0.12.3",
44
"description": "VanJS. A minimalist React-like UI library based on vanilla JavaScript and DOM.",
55
"main": "src/van.js",
66
"type": "module",

public/van-0.12.3.d.ts

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
export type State<T> = {
2+
val: T
3+
onnew(l: (val: T, oldVal: T) => void): void
4+
}
5+
6+
// Defining readonly view of State<T> for covariance.
7+
// Basically we want State<string> implements StateView<string | number>
8+
export interface StateView<T> {
9+
readonly val: T
10+
}
11+
12+
export type Primitive = string | number | boolean | bigint
13+
14+
export type PropValue = Primitive | Function
15+
16+
export interface DerivedProp {
17+
readonly deps: unknown[]
18+
readonly f: (...args: readonly any[]) => PropValue
19+
}
20+
21+
export interface Props {
22+
readonly [key: string]: PropValue | StateView<PropValue> | DerivedProp
23+
}
24+
25+
export type ChildDom = Primitive | Node | StateView<Primitive | null | undefined> | readonly ChildDom[] | null | undefined
26+
27+
export type TagFunc<Result> = (first?: Props | ChildDom, ...rest: readonly ChildDom[]) => Result
28+
29+
interface TagsBase {
30+
readonly [key: string]: TagFunc<Element>
31+
}
32+
33+
interface Tags extends TagsBase {
34+
// Register known element types
35+
// Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element
36+
37+
// Main root
38+
readonly html: TagFunc<HTMLHtmlElement>
39+
40+
// Document metadata
41+
readonly base: TagFunc<HTMLBaseElement>
42+
readonly head: TagFunc<HTMLHeadElement>
43+
readonly link: TagFunc<HTMLLinkElement>
44+
readonly meta: TagFunc<HTMLMetaElement>
45+
readonly style: TagFunc<HTMLStyleElement>
46+
readonly title: TagFunc<HTMLTitleElement>
47+
48+
// Sectioning root
49+
readonly body: TagFunc<HTMLBodyElement>
50+
51+
// Content sectioning
52+
readonly h1: TagFunc<HTMLHeadingElement>
53+
readonly h2: TagFunc<HTMLHeadingElement>
54+
readonly h3: TagFunc<HTMLHeadingElement>
55+
readonly h4: TagFunc<HTMLHeadingElement>
56+
readonly h5: TagFunc<HTMLHeadingElement>
57+
readonly h6: TagFunc<HTMLHeadingElement>
58+
59+
// Text content
60+
readonly blockquote: TagFunc<HTMLQuoteElement>
61+
readonly div: TagFunc<HTMLDivElement>
62+
readonly dl: TagFunc<HTMLDListElement>
63+
readonly hr: TagFunc<HTMLHRElement>
64+
readonly li: TagFunc<HTMLLIElement>
65+
readonly menu: TagFunc<HTMLMenuElement>
66+
readonly ol: TagFunc<HTMLOListElement>
67+
readonly p: TagFunc<HTMLParagraphElement>
68+
readonly pre: TagFunc<HTMLPreElement>
69+
readonly ul: TagFunc<HTMLUListElement>
70+
71+
// Inline text semantics
72+
readonly a: TagFunc<HTMLAnchorElement>
73+
readonly br: TagFunc<HTMLBRElement>
74+
readonly data: TagFunc<HTMLDataElement>
75+
readonly q: TagFunc<HTMLQuoteElement>
76+
readonly span: TagFunc<HTMLSpanElement>
77+
readonly time: TagFunc<HTMLTimeElement>
78+
79+
// Image and multimedia
80+
readonly area: TagFunc<HTMLAreaElement>
81+
readonly audio: TagFunc<HTMLAudioElement>
82+
readonly img: TagFunc<HTMLImageElement>
83+
readonly map: TagFunc<HTMLMapElement>
84+
readonly track: TagFunc<HTMLTrackElement>
85+
readonly video: TagFunc<HTMLVideoElement>
86+
87+
// Embedded content
88+
readonly embed: TagFunc<HTMLEmbedElement>
89+
readonly iframe: TagFunc<HTMLIFrameElement>
90+
readonly object: TagFunc<HTMLObjectElement>
91+
readonly picture: TagFunc<HTMLPictureElement>
92+
readonly source: TagFunc<HTMLSourceElement>
93+
94+
// Scripting
95+
readonly canvas: TagFunc<HTMLCanvasElement>
96+
readonly script: TagFunc<HTMLScriptElement>
97+
98+
// Demarcating edits
99+
readonly del: TagFunc<HTMLModElement>
100+
readonly ins: TagFunc<HTMLModElement>
101+
102+
// Table content
103+
readonly caption: TagFunc<HTMLTableCaptionElement>
104+
readonly col: TagFunc<HTMLTableColElement>
105+
readonly colgroup: TagFunc<HTMLTableColElement>
106+
readonly table: TagFunc<HTMLTableElement>
107+
readonly tbody: TagFunc<HTMLTableSectionElement>
108+
readonly td: TagFunc<HTMLTableCellElement>
109+
readonly tfoot: TagFunc<HTMLTableSectionElement>
110+
readonly th: TagFunc<HTMLTableCellElement>
111+
readonly thead: TagFunc<HTMLTableSectionElement>
112+
readonly tr: TagFunc<HTMLTableRowElement>
113+
114+
// Forms
115+
readonly button: TagFunc<HTMLButtonElement>
116+
readonly datalist: TagFunc<HTMLDataListElement>
117+
readonly fieldset: TagFunc<HTMLFieldSetElement>
118+
readonly form: TagFunc<HTMLFormElement>
119+
readonly input: TagFunc<HTMLInputElement>
120+
readonly label: TagFunc<HTMLLabelElement>
121+
readonly legend: TagFunc<HTMLLegendElement>
122+
readonly meter: TagFunc<HTMLMeterElement>
123+
readonly optgroup: TagFunc<HTMLOptGroupElement>
124+
readonly option: TagFunc<HTMLOptionElement>
125+
readonly output: TagFunc<HTMLOutputElement>
126+
readonly progress: TagFunc<HTMLProgressElement>
127+
readonly select: TagFunc<HTMLSelectElement>
128+
readonly textarea: TagFunc<HTMLTextAreaElement>
129+
130+
// Interactive elements
131+
readonly details: TagFunc<HTMLDetailsElement>
132+
readonly dialog: TagFunc<HTMLDialogElement>
133+
134+
// Web Components
135+
readonly slot: TagFunc<HTMLSlotElement>
136+
readonly template: TagFunc<HTMLTemplateElement>
137+
}
138+
139+
type ValOf<T> = T extends StateView<unknown> ? T["val"] : T
140+
141+
type BindFuncArgs<T extends readonly unknown[]> = T extends [infer OnlyOne] ?
142+
[ValOf<OnlyOne>] : T extends [infer First, ...infer Rest extends unknown[]] ?
143+
[ValOf<First>, ...BindFuncArgs<Rest>] : never
144+
145+
type BindFunc<T extends unknown[]> = (...arg: readonly [...BindFuncArgs<T>, Element, ...BindFuncArgs<T>]) => Primitive | Node | null | undefined
146+
147+
declare function bind<T extends unknown[]>(...args: [...T, BindFunc<T>]): Node | []
148+
149+
export interface Van {
150+
readonly state: <T>(initVal: T) => State<T>
151+
readonly add: (dom: Element, ...children: readonly ChildDom[]) => Element
152+
readonly tags: Tags
153+
readonly tagsNS: (namespaceURI: string) => TagsBase
154+
readonly bind: typeof bind
155+
}
156+
157+
declare const van: Van
158+
159+
export default van

public/van-0.12.3.debug.d.ts

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
export type State<T> = {
2+
val: T
3+
onnew(l: (val: T, oldVal: T) => void): void
4+
}
5+
6+
// Defining readonly view of State<T> for covariance.
7+
// Basically we want State<string> implements StateView<string | number>
8+
export interface StateView<T> {
9+
readonly val: T
10+
}
11+
12+
export type Primitive = string | number | boolean | bigint
13+
14+
export type PropValue = Primitive | Function
15+
16+
export interface DerivedProp {
17+
readonly deps: unknown[]
18+
readonly f: (...args: readonly any[]) => PropValue
19+
}
20+
21+
export interface Props {
22+
readonly [key: string]: PropValue | StateView<PropValue> | DerivedProp
23+
}
24+
25+
export type ChildDom = Primitive | Node | StateView<Primitive | null | undefined> | readonly ChildDom[] | null | undefined
26+
27+
export type TagFunc<Result> = (first?: Props | ChildDom, ...rest: readonly ChildDom[]) => Result
28+
29+
interface TagsBase {
30+
readonly [key: string]: TagFunc<Element>
31+
}
32+
33+
interface Tags extends TagsBase {
34+
// Register known element types
35+
// Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element
36+
37+
// Main root
38+
readonly html: TagFunc<HTMLHtmlElement>
39+
40+
// Document metadata
41+
readonly base: TagFunc<HTMLBaseElement>
42+
readonly head: TagFunc<HTMLHeadElement>
43+
readonly link: TagFunc<HTMLLinkElement>
44+
readonly meta: TagFunc<HTMLMetaElement>
45+
readonly style: TagFunc<HTMLStyleElement>
46+
readonly title: TagFunc<HTMLTitleElement>
47+
48+
// Sectioning root
49+
readonly body: TagFunc<HTMLBodyElement>
50+
51+
// Content sectioning
52+
readonly h1: TagFunc<HTMLHeadingElement>
53+
readonly h2: TagFunc<HTMLHeadingElement>
54+
readonly h3: TagFunc<HTMLHeadingElement>
55+
readonly h4: TagFunc<HTMLHeadingElement>
56+
readonly h5: TagFunc<HTMLHeadingElement>
57+
readonly h6: TagFunc<HTMLHeadingElement>
58+
59+
// Text content
60+
readonly blockquote: TagFunc<HTMLQuoteElement>
61+
readonly div: TagFunc<HTMLDivElement>
62+
readonly dl: TagFunc<HTMLDListElement>
63+
readonly hr: TagFunc<HTMLHRElement>
64+
readonly li: TagFunc<HTMLLIElement>
65+
readonly menu: TagFunc<HTMLMenuElement>
66+
readonly ol: TagFunc<HTMLOListElement>
67+
readonly p: TagFunc<HTMLParagraphElement>
68+
readonly pre: TagFunc<HTMLPreElement>
69+
readonly ul: TagFunc<HTMLUListElement>
70+
71+
// Inline text semantics
72+
readonly a: TagFunc<HTMLAnchorElement>
73+
readonly br: TagFunc<HTMLBRElement>
74+
readonly data: TagFunc<HTMLDataElement>
75+
readonly q: TagFunc<HTMLQuoteElement>
76+
readonly span: TagFunc<HTMLSpanElement>
77+
readonly time: TagFunc<HTMLTimeElement>
78+
79+
// Image and multimedia
80+
readonly area: TagFunc<HTMLAreaElement>
81+
readonly audio: TagFunc<HTMLAudioElement>
82+
readonly img: TagFunc<HTMLImageElement>
83+
readonly map: TagFunc<HTMLMapElement>
84+
readonly track: TagFunc<HTMLTrackElement>
85+
readonly video: TagFunc<HTMLVideoElement>
86+
87+
// Embedded content
88+
readonly embed: TagFunc<HTMLEmbedElement>
89+
readonly iframe: TagFunc<HTMLIFrameElement>
90+
readonly object: TagFunc<HTMLObjectElement>
91+
readonly picture: TagFunc<HTMLPictureElement>
92+
readonly source: TagFunc<HTMLSourceElement>
93+
94+
// Scripting
95+
readonly canvas: TagFunc<HTMLCanvasElement>
96+
readonly script: TagFunc<HTMLScriptElement>
97+
98+
// Demarcating edits
99+
readonly del: TagFunc<HTMLModElement>
100+
readonly ins: TagFunc<HTMLModElement>
101+
102+
// Table content
103+
readonly caption: TagFunc<HTMLTableCaptionElement>
104+
readonly col: TagFunc<HTMLTableColElement>
105+
readonly colgroup: TagFunc<HTMLTableColElement>
106+
readonly table: TagFunc<HTMLTableElement>
107+
readonly tbody: TagFunc<HTMLTableSectionElement>
108+
readonly td: TagFunc<HTMLTableCellElement>
109+
readonly tfoot: TagFunc<HTMLTableSectionElement>
110+
readonly th: TagFunc<HTMLTableCellElement>
111+
readonly thead: TagFunc<HTMLTableSectionElement>
112+
readonly tr: TagFunc<HTMLTableRowElement>
113+
114+
// Forms
115+
readonly button: TagFunc<HTMLButtonElement>
116+
readonly datalist: TagFunc<HTMLDataListElement>
117+
readonly fieldset: TagFunc<HTMLFieldSetElement>
118+
readonly form: TagFunc<HTMLFormElement>
119+
readonly input: TagFunc<HTMLInputElement>
120+
readonly label: TagFunc<HTMLLabelElement>
121+
readonly legend: TagFunc<HTMLLegendElement>
122+
readonly meter: TagFunc<HTMLMeterElement>
123+
readonly optgroup: TagFunc<HTMLOptGroupElement>
124+
readonly option: TagFunc<HTMLOptionElement>
125+
readonly output: TagFunc<HTMLOutputElement>
126+
readonly progress: TagFunc<HTMLProgressElement>
127+
readonly select: TagFunc<HTMLSelectElement>
128+
readonly textarea: TagFunc<HTMLTextAreaElement>
129+
130+
// Interactive elements
131+
readonly details: TagFunc<HTMLDetailsElement>
132+
readonly dialog: TagFunc<HTMLDialogElement>
133+
134+
// Web Components
135+
readonly slot: TagFunc<HTMLSlotElement>
136+
readonly template: TagFunc<HTMLTemplateElement>
137+
}
138+
139+
type ValOf<T> = T extends StateView<unknown> ? T["val"] : T
140+
141+
type BindFuncArgs<T extends readonly unknown[]> = T extends [infer OnlyOne] ?
142+
[ValOf<OnlyOne>] : T extends [infer First, ...infer Rest extends unknown[]] ?
143+
[ValOf<First>, ...BindFuncArgs<Rest>] : never
144+
145+
type BindFunc<T extends unknown[]> = (...arg: readonly [...BindFuncArgs<T>, Element, ...BindFuncArgs<T>]) => Primitive | Node | null | undefined
146+
147+
declare function bind<T extends unknown[]>(...args: [...T, BindFunc<T>]): Node | []
148+
149+
export interface Van {
150+
readonly state: <T>(initVal: T) => State<T>
151+
readonly add: (dom: Element, ...children: readonly ChildDom[]) => Element
152+
readonly tags: Tags
153+
readonly tagsNS: (namespaceURI: string) => TagsBase
154+
readonly bind: typeof bind
155+
}
156+
157+
declare const van: Van
158+
159+
export default van

0 commit comments

Comments
 (0)