1
- /**
2
- * @typedef {import('hast').Element } Element
3
- */
4
-
5
1
import { convertElement } from 'hast-util-is-element'
6
2
7
- /**
8
- * Check if a node is an element with a [*transparent content model*].
9
- *
10
- * @type {import('hast-util-is-element').AssertPredicate<Element & {tagName: 'a' | 'audio' | 'canvas' | 'datalist' | 'dd' | 'del' | 'ins' | 'map' | 'menu' | 'noscript' | 'object' | 'ol' | 'picture' | 'select' | 'table' | 'tbody' | 'tfoot' | 'thead' | 'tr' | 'ul' | 'video'}> }
11
- * @param value
12
- * Thing to check (typically `Node`).
13
- * @returns
14
- * Whether `value` is an element with a transparent content model.
15
- *
16
- * The elements `a`, `audio`, `canvas`, `datalist`, `dd`, `del`, `ins`,
17
- * `map`, `menu`, `noscript`, `object`, `ol`, `picture`, `select`, `table`,
18
- * `tbody`, `tfoot`, `thead`, `tr`, `ul`, and `video` have transparent
19
- * content models.
20
- */
21
- // @ts -expect-error Sure, the assertion matches.
22
- export const transparent = convertElement ( [
3
+ const names = new Set ( [
23
4
'a' ,
24
5
'audio' ,
25
6
'canvas' ,
@@ -42,3 +23,26 @@ export const transparent = convertElement([
42
23
'ul' ,
43
24
'video'
44
25
] )
26
+
27
+ /**
28
+ * Check if a node is an element with a [*transparent content model*].
29
+ *
30
+ * @param value
31
+ * Thing to check (typically `Node`).
32
+ * @returns
33
+ * Whether `value` is an element with a transparent content model.
34
+ *
35
+ * The elements `a`, `audio`, `canvas`, `datalist`, `dd`, `del`, `ins`,
36
+ * `map`, `menu`, `noscript`, `object`, `ol`, `picture`, `select`, `table`,
37
+ * `tbody`, `tfoot`, `thead`, `tr`, `ul`, and `video` have transparent
38
+ * content models.
39
+ */
40
+ export const transparent = convertElement (
41
+ /**
42
+ * @param element
43
+ * @returns {element is {tagName: 'a' | 'audio' | 'canvas' | 'datalist' | 'dd' | 'del' | 'ins' | 'map' | 'menu' | 'noscript' | 'object' | 'ol' | 'picture' | 'select' | 'table' | 'tbody' | 'tfoot' | 'thead' | 'tr' | 'ul' | 'video'} }
44
+ */
45
+ function ( element ) {
46
+ return names . has ( element . tagName )
47
+ }
48
+ )
0 commit comments