-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
28 lines (23 loc) · 824 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const postcss = require('postcss');
const selectorParser = require('postcss-selector-parser');
module.exports = postcss.plugin('postcss-hocus', (opts = {}) => css => {
css.walkRules(rule => {
rule.selector = selectorParser(selectors => {
selectors.walk(node => {
const key = node.value;
if ([ ':hocus', ':pocus' ].includes(key)) {
const parent = node.parent;
const list = parent.parent;
const index = list.nodes.indexOf(parent) + 1;
node.value = ':focus';
list.nodes.splice(index, 0, parent.clone());
if (key === ':pocus') {
node.value = ':active';
list.nodes.splice(index, 0, parent.clone());
}
node.value = ':hover';
}
});
}).process(rule.selector).result;
});
});