Skip to content

Commit a5ec04e

Browse files
committed
Refactor to move implementation to lib/
1 parent bed8594 commit a5ec04e

File tree

3 files changed

+62
-60
lines changed

3 files changed

+62
-60
lines changed

index.js

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1 @@
1-
/**
2-
* @typedef {import('hast').Root} Root
3-
* @typedef {import('hast').Content} Content
4-
*/
5-
6-
/**
7-
* @typedef {Root | Content} Node
8-
*/
9-
10-
import {hasProperty} from 'hast-util-has-property'
11-
12-
// Always interactive nodes.
13-
const alwaysInteractive = new Set([
14-
'button',
15-
'details',
16-
'embed',
17-
'iframe',
18-
'keygen',
19-
'label',
20-
'select',
21-
'textarea'
22-
])
23-
24-
/**
25-
* Check if the given value is *interactive content*.
26-
*
27-
* @param {Node} node
28-
* Node to check.
29-
* @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`
42-
*/
43-
export function interactive(node) {
44-
if (!node || typeof node !== 'object' || node.type !== 'element') {
45-
return false
46-
}
47-
48-
const name = node.tagName
49-
50-
return (
51-
(name === 'a' && hasProperty(node, 'href')) ||
52-
(name === 'audio' && hasProperty(node, 'controls')) ||
53-
(name === 'video' && hasProperty(node, 'controls')) ||
54-
(name === 'object' && hasProperty(node, 'useMap')) ||
55-
(name === 'img' && hasProperty(node, 'useMap')) ||
56-
(name === 'input' && (node.properties || {}).type !== 'hidden') ||
57-
hasProperty(node, 'tabIndex') ||
58-
alwaysInteractive.has(name)
59-
)
60-
}
1+
export {interactive} from './lib/index.js'

lib/index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @typedef {import('hast').Root} Root
3+
* @typedef {import('hast').Content} Content
4+
*/
5+
6+
/**
7+
* @typedef {Root | Content} Node
8+
*/
9+
10+
import {hasProperty} from 'hast-util-has-property'
11+
12+
// Always interactive nodes.
13+
const alwaysInteractive = new Set([
14+
'button',
15+
'details',
16+
'embed',
17+
'iframe',
18+
'keygen',
19+
'label',
20+
'select',
21+
'textarea'
22+
])
23+
24+
/**
25+
* Check if the given value is *interactive content*.
26+
*
27+
* @param {Node} node
28+
* Node to check.
29+
* @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`
42+
*/
43+
export function interactive(node) {
44+
if (!node || typeof node !== 'object' || node.type !== 'element') {
45+
return false
46+
}
47+
48+
const name = node.tagName
49+
50+
return (
51+
(name === 'a' && hasProperty(node, 'href')) ||
52+
(name === 'audio' && hasProperty(node, 'controls')) ||
53+
(name === 'video' && hasProperty(node, 'controls')) ||
54+
(name === 'object' && hasProperty(node, 'useMap')) ||
55+
(name === 'img' && hasProperty(node, 'useMap')) ||
56+
(name === 'input' && (node.properties || {}).type !== 'hidden') ||
57+
hasProperty(node, 'tabIndex') ||
58+
alwaysInteractive.has(name)
59+
)
60+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"main": "index.js",
3030
"types": "index.d.ts",
3131
"files": [
32+
"lib/",
3233
"index.d.ts",
3334
"index.js"
3435
],

0 commit comments

Comments
 (0)