-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (28 loc) · 943 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
29
30
31
32
33
34
35
module.exports = (opts = {}) => {
const target = /:[hp]ocus/;
return {
postcssPlugin: 'postcss-hocus-pocus',
Rule(rule) {
const newSelectors = []
rule.selectors.forEach((selector, idx) => {
if (target.test(selector)) {
const colonIndex = selector.indexOf(':')
const preSelector = selector.slice(0, colonIndex);
let postSelector = ''
if (selector.length - colonIndex - 1 !== 5) {
postSelector = selector.slice(colonIndex+6,)
}
newSelectors.push(`${preSelector}:hover${postSelector}`);
newSelectors.push(`${preSelector}:focus${postSelector}`);
if (selector.includes(':pocus')) {
newSelectors.push(`${preSelector}:active${postSelector}`);
}
} else {
newSelectors.push(selector)
}
})
rule.selectors = newSelectors
}
}
}
module.exports.postcss = true