1
1
/**
2
2
* @typedef {import('hast').Root } Root
3
+ * @typedef {import('hast').Content } Content
3
4
* @typedef {import('hast').Element } Element
4
5
* @typedef {import('hast').Properties } Properties
5
- * @typedef {Root['children'][number] } Child
6
- * @typedef {Child|Root } Node
7
6
* @typedef {import('property-information').Info } Info
8
7
* @typedef {import('property-information').Schema } Schema
8
+ */
9
+
10
+ /**
11
+ * @typedef {Content | Root } Node
12
+ * Any concrete `hast` node.
13
+ * @typedef {Root | Element } HResult
14
+ * Result from a `h` (or `s`) call.
9
15
*
10
- * @typedef {Root|Element } HResult
11
- * @typedef { string|number } HStyleValue
16
+ * @typedef {string | number } HStyleValue
17
+ * Value for a CSS style field.
12
18
* @typedef {Record<string, HStyleValue> } HStyle
13
- * @typedef {string|number|boolean|null|undefined } HPrimitiveValue
14
- * @typedef {Array<string|number> } HArrayValue
15
- * @typedef {HPrimitiveValue|HArrayValue } HPropertyValue
16
- * @typedef {{[property: string]: HPropertyValue|HStyle} } HProperties
17
- * Acceptable properties value.
19
+ * Supported value of a `style` prop.
20
+ * @typedef {string | number | boolean | null | undefined } HPrimitiveValue
21
+ * Primitive property value.
22
+ * @typedef {Array<string | number> } HArrayValue
23
+ * List of property values for space- or comma separated values (such as `className`).
24
+ * @typedef {HPrimitiveValue | HArrayValue } HPropertyValue
25
+ * Primitive value or list value.
26
+ * @typedef {{[property: string]: HPropertyValue | HStyle} } HProperties
27
+ * Acceptable value for element properties.
18
28
*
19
- * @typedef {string|number|null|undefined } HPrimitiveChild
20
- * @typedef {Array<Node|HPrimitiveChild> } HArrayChild
21
- * @typedef {Node|HPrimitiveChild|HArrayChild } HChild
22
- * Acceptable child value
29
+ * @typedef {string | number | null | undefined } HPrimitiveChild
30
+ * Primitive children, either ignored (nullish), or turned into text nodes.
31
+ * @typedef {Array<Node | HPrimitiveChild> } HArrayChild
32
+ * List of children.
33
+ * @typedef {Node | HPrimitiveChild | HArrayChild } HChild
34
+ * Acceptable child value.
23
35
*/
24
36
25
37
import { find , normalize } from 'property-information'
@@ -43,7 +55,7 @@ export function core(schema, defaultTagName, caseSensitive) {
43
55
/**
44
56
* @type {{
45
57
* (): Root
46
- * (selector: null| undefined, ...children: Array<HChild>): Root
58
+ * (selector: null | undefined, ...children: Array<HChild>): Root
47
59
* (selector: string, properties?: HProperties, ...children: Array<HChild>): Element
48
60
* (selector: string, ...children: Array<HChild>): Element
49
61
* }}
@@ -52,8 +64,8 @@ export function core(schema, defaultTagName, caseSensitive) {
52
64
/**
53
65
* Hyperscript compatible DSL for creating virtual hast trees.
54
66
*
55
- * @param {string| null } [selector]
56
- * @param {HProperties| HChild } [properties]
67
+ * @param {string | null } [selector]
68
+ * @param {HProperties | HChild } [properties]
57
69
* @param {Array<HChild> } children
58
70
* @returns {HResult }
59
71
*/
@@ -108,7 +120,7 @@ export function core(schema, defaultTagName, caseSensitive) {
108
120
}
109
121
110
122
/**
111
- * @param {HProperties| HChild } value
123
+ * @param {HProperties | HChild } value
112
124
* @param {string } name
113
125
* @returns {value is HProperties }
114
126
*/
@@ -141,7 +153,7 @@ function isProperties(value, name) {
141
153
* @param {Schema } schema
142
154
* @param {Properties } properties
143
155
* @param {string } key
144
- * @param {HStyle| HPropertyValue } value
156
+ * @param {HStyle | HPropertyValue } value
145
157
* @returns {void }
146
158
*/
147
159
function addProperty ( schema , properties , key , value ) {
@@ -181,7 +193,7 @@ function addProperty(schema, properties, key, value) {
181
193
}
182
194
183
195
if ( Array . isArray ( result ) ) {
184
- /** @type {Array<string| number> } */
196
+ /** @type {Array<string | number> } */
185
197
const finalResult = [ ]
186
198
187
199
while ( ++ index < result . length ) {
@@ -202,7 +214,7 @@ function addProperty(schema, properties, key, value) {
202
214
}
203
215
204
216
/**
205
- * @param {Array<Child > } nodes
217
+ * @param {Array<Content > } nodes
206
218
* @param {HChild } value
207
219
* @returns {void }
208
220
*/
@@ -254,8 +266,12 @@ function parsePrimitive(info, name, value) {
254
266
}
255
267
256
268
/**
269
+ * Serialize a `style` object as a string.
270
+ *
257
271
* @param {HStyle } value
272
+ * Style object.
258
273
* @returns {string }
274
+ * CSS string.
259
275
*/
260
276
function style ( value ) {
261
277
/** @type {Array<string> } */
@@ -273,8 +289,12 @@ function style(value) {
273
289
}
274
290
275
291
/**
292
+ * Create a map to adjust casing.
293
+ *
276
294
* @param {Array<string> } values
295
+ * List of properly cased keys.
277
296
* @returns {Record<string, string> }
297
+ * Map of lowercase keys to uppercase keys.
278
298
*/
279
299
function createAdjustMap ( values ) {
280
300
/** @type {Record<string, string> } */
0 commit comments