4
4
*
5
5
* @typedef {import('hast').Element } HastElement
6
6
* @typedef {import('hast').Properties } HastProperties
7
- *
8
- * @typedef {'html' | 'svg' } Space
9
- * Name of namespace.
10
- *
7
+ */
8
+
9
+ /**
11
10
* @typedef Options
12
11
* Configuration.
13
12
* @property {Space } [space]
14
- * Which space first element in the selector is in.
13
+ * Which space first element in the selector is in (default: `'html'`) .
15
14
*
16
15
* When an `svg` element is created in HTML, the space is automatically
17
16
* switched to SVG.
18
17
*
18
+ * @typedef {'html' | 'svg' } Space
19
+ * Name of namespace.
20
+ *
19
21
* @typedef State
20
22
* Info on current context.
21
23
* @property {Space } space
22
24
* Current space.
23
25
*/
24
26
27
+ import { createParser } from 'css-selector-parser'
25
28
import { ok as assert } from 'devlop'
26
29
import { h , s } from 'hastscript'
27
- import { createParser } from 'css-selector-parser'
28
30
29
31
const cssSelectorParse = createParser ( { syntax : 'selectors-4' } )
30
32
@@ -33,18 +35,18 @@ const cssSelectorParse = createParser({syntax: 'selectors-4'})
33
35
* Create one or more `Element`s from a CSS selector.
34
36
*
35
37
* @param {string | null | undefined } [selector='']
36
- * CSS selector.
37
- * @param {Space | Options | null | undefined } [space='html' ]
38
- * Space or configuration .
38
+ * CSS selector (default: `''`) .
39
+ * @param {Options | Space | null | undefined } [options ]
40
+ * Configuration (optional) .
39
41
* @returns {HastElement }
40
42
* Built tree.
41
43
*/
42
- export function fromSelector ( selector , space ) {
44
+ export function fromSelector ( selector , options ) {
43
45
/** @type {State } */
44
46
const state = {
45
47
space :
46
- ( space && typeof space === 'object' && space . space ) ||
47
- ( typeof space === 'string' && space ) ||
48
+ ( options && typeof options === 'object' && options . space ) ||
49
+ ( typeof options === 'string' && options ) ||
48
50
'html'
49
51
}
50
52
0 commit comments