Skip to content

Commit 2548623

Browse files
committed
Refactor code-style
* Add more docs to JSDoc
1 parent 25193af commit 2548623

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
22
* @typedef {import('hast').Root} Root
3-
* @typedef {Root['children'][number]|Root} Node
3+
* @typedef {import('hast').Content} Content
4+
*/
5+
6+
/**
7+
* @typedef {Root | Content} Node
48
*/
59

610
import {hasProperty} from 'hast-util-has-property'
@@ -18,8 +22,23 @@ const alwaysInteractive = new Set([
1822
])
1923

2024
/**
25+
* Check if the given value is *interactive content*.
26+
*
2127
* @param {Node} node
28+
* Node to check.
2229
* @returns {boolean}
30+
* Whether `node` is an `Element` that is classified as *interactive
31+
* content*.
32+
*
33+
* The following elements are interactive:
34+
*
35+
* * `a` with `href`
36+
* * `audio` or `video` with `controls`
37+
* * `img` or `object` with `useMap`
38+
* * `input` without `hidden`
39+
* * any element with a `tabIndex`
40+
* * the elements `button`, `details`, `embed`, `iframe`, `keygen`, `label`,
41+
* `select`, and `textarea`
2342
*/
2443
export function interactive(node) {
2544
if (!node || typeof node !== 'object' || node.type !== 'element') {

readme.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,18 @@ Check if the given value is [*interactive*][spec].
100100

101101
###### Returns
102102

103-
Whether `node` is an [`Element`][element] categorised as [*interactive*][spec]
104-
(`boolean`).
103+
Whether `node` is an [`Element`][element] that is classified as *interactive
104+
content* (`boolean`).
105+
106+
The following elements are interactive:
107+
108+
* `a` with `href`
109+
* `audio` or `video` with `controls`
110+
* `img` or `object` with `useMap`
111+
* `input` without `hidden`
112+
* any element with a `tabIndex`
113+
* the elements `button`, `details`, `embed`, `iframe`, `keygen`, `label`,
114+
`select`, and `textarea`
105115

106116
## Types
107117

@@ -221,6 +231,6 @@ abide by its terms.
221231

222232
[element]: https://github.com/syntax-tree/hast#element
223233

224-
[spec]: https://html.spec.whatwg.org/#interactive-content
234+
[spec]: https://html.spec.whatwg.org/multipage/dom.html#interactive-content
225235

226236
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

0 commit comments

Comments
 (0)