1
1
/**
2
2
* @typedef {import('hast').Element} Element
3
3
* @typedef {import('hast').Nodes} Nodes
4
- * @typedef {import('hast').Properties} Properties
5
4
* @typedef {import('hast').Root} Root
6
5
* @typedef {import('hast').RootContent} RootContent
7
6
*
10
9
*/
11
10
12
11
/**
13
- * @typedef {Element | Root} HResult
12
+ * @typedef {Element | Root} Result
14
13
* Result from a `h` (or `s`) call.
15
14
*
16
- * @typedef {number | string} HStyleValue
15
+ * @typedef {number | string} StyleValue
17
16
* Value for a CSS style field.
18
- * @typedef {Record<string, HStyleValue >} HStyle
17
+ * @typedef {Record<string, StyleValue >} Style
19
18
* Supported value of a `style` prop.
20
- * @typedef {boolean | number | string | null | undefined} HPrimitiveValue
19
+ * @typedef {boolean | number | string | null | undefined} PrimitiveValue
21
20
* Primitive property value.
22
- * @typedef {Array<number | string>} HArrayValue
21
+ * @typedef {Array<number | string>} ArrayValue
23
22
* List of property values for space- or comma separated values (such as `className`).
24
- * @typedef {HArrayValue | HPrimitiveValue} HPropertyValue
23
+ * @typedef {ArrayValue | PrimitiveValue} PropertyValue
25
24
* Primitive value or list value.
26
- * @typedef {{[property: string]: HPropertyValue | HStyle }} HProperties
25
+ * @typedef {{[property: string]: PropertyValue | Style }} Properties
27
26
* Acceptable value for element properties.
28
27
*
29
- * @typedef {number | string | null | undefined} HPrimitiveChild
28
+ * @typedef {number | string | null | undefined} PrimitiveChild
30
29
* Primitive children, either ignored (nullish), or turned into text nodes.
31
- * @typedef {Array<HPrimitiveChild | Nodes>} HArrayChildNested
30
+ * @typedef {Array<ArrayChildNested | Nodes | PrimitiveChild >} ArrayChild
32
31
* List of children.
33
- * @typedef {Array<HArrayChildNested | HPrimitiveChild | Nodes >} HArrayChild
34
- * List of children.
35
- * @typedef {HArrayChild | HPrimitiveChild | Nodes} HChild
32
+ * @typedef {Array<Nodes | PrimitiveChild >} ArrayChildNested
33
+ * List of children (deep) .
34
+ * @typedef {ArrayChild | Nodes | PrimitiveChild} Child
36
35
* Acceptable child value.
37
36
*/
38
37
@@ -55,46 +54,46 @@ const own = {}.hasOwnProperty
55
54
* @returns
56
55
* `h`.
57
56
*/
58
- export function core (schema, defaultTagName, caseSensitive) {
57
+ export function createH (schema, defaultTagName, caseSensitive) {
59
58
const adjust = caseSensitive && createAdjustMap(caseSensitive)
60
59
61
60
/**
62
61
* Hyperscript compatible DSL for creating virtual hast trees.
63
62
*
64
63
* @overload
65
64
* @param {null | undefined} [selector]
66
- * @param {...HChild } children
65
+ * @param {...Child } children
67
66
* @returns {Root}
68
67
*
69
68
* @overload
70
69
* @param {string} selector
71
- * @param {HProperties } properties
72
- * @param {...HChild } children
70
+ * @param {Properties } properties
71
+ * @param {...Child } children
73
72
* @returns {Element}
74
73
*
75
74
* @overload
76
75
* @param {string} selector
77
- * @param {...HChild } children
76
+ * @param {...Child } children
78
77
* @returns {Element}
79
78
*
80
79
* @param {string | null | undefined} [selector]
81
80
* Selector.
82
- * @param {HChild | HProperties | null | undefined} [properties]
81
+ * @param {Child | Properties | null | undefined} [properties]
83
82
* Properties (or first child) (default: `undefined`).
84
- * @param {...HChild } children
83
+ * @param {...Child } children
85
84
* Children.
86
- * @returns {HResult }
85
+ * @returns {Result }
87
86
* Result.
88
87
*/
89
88
function h(selector, properties, ...children) {
90
89
let index = -1
91
- /** @type {HResult } */
90
+ /** @type {Result } */
92
91
let node
93
92
94
93
if (selector === undefined || selector === null) {
95
94
node = {type: 'root', children: []}
96
95
// Properties are not supported for roots.
97
- const child = /** @type {HChild } */ (properties)
96
+ const child = /** @type {Child } */ (properties)
98
97
children.unshift(child)
99
98
} else {
100
99
node = parseSelector(selector, defaultTagName)
@@ -138,11 +137,11 @@ export function core(schema, defaultTagName, caseSensitive) {
138
137
/**
139
138
* Check if something is properties or a child.
140
139
*
141
- * @param {HChild | HProperties } value
140
+ * @param {Child | Properties } value
142
141
* Value to check.
143
142
* @param {string} name
144
143
* Tag name.
145
- * @returns {value is HProperties }
144
+ * @returns {value is Properties }
146
145
* Whether `value` is a properties object.
147
146
*/
148
147
function isProperties(value, name) {
@@ -177,15 +176,15 @@ function isProperties(value, name) {
177
176
* Properties object.
178
177
* @param {string} key
179
178
* Property name.
180
- * @param {HPropertyValue | HStyle } value
179
+ * @param {PropertyValue | Style } value
181
180
* Property value.
182
181
* @returns {undefined}
183
182
* Nothing.
184
183
*/
185
184
function addProperty(schema, properties, key, value) {
186
185
const info = find(schema, key)
187
186
let index = -1
188
- /** @type {HPropertyValue } */
187
+ /** @type {PropertyValue } */
189
188
let result
190
189
191
190
// Ignore nullish and NaN values.
@@ -246,7 +245,7 @@ function addProperty(schema, properties, key, value) {
246
245
/**
247
246
* @param {Array<RootContent>} nodes
248
247
* Children.
249
- * @param {HChild } value
248
+ * @param {Child } value
250
249
* Child.
251
250
* @returns {undefined}
252
251
* Nothing.
@@ -280,9 +279,9 @@ function addChild(nodes, value) {
280
279
* Property information.
281
280
* @param {string} name
282
281
* Property name.
283
- * @param {HPrimitiveValue } value
282
+ * @param {PrimitiveValue } value
284
283
* Property value.
285
- * @returns {HPrimitiveValue }
284
+ * @returns {PrimitiveValue }
286
285
* Property value.
287
286
*/
288
287
function parsePrimitive(info, name, value) {
@@ -305,7 +304,7 @@ function parsePrimitive(info, name, value) {
305
304
/**
306
305
* Serialize a `style` object as a string.
307
306
*
308
- * @param {HStyle } value
307
+ * @param {Style } value
309
308
* Style object.
310
309
* @returns {string}
311
310
* CSS string.
0 commit comments