-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
25 lines (22 loc) · 913 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
module.exports = (opts) => {
const useCssModulesGlobal = opts && typeof opts.useCssModulesGlobal !== "undefined" ? opts.useCssModulesGlobal : false;
const prefix = opts && typeof opts.prefix !== "undefined" ? opts.prefix : ".using-mouse";
function setPrefix (selector) {
const thePrefix = (useCssModulesGlobal ? ":global(" : "") + prefix + (useCssModulesGlobal ? ")" : "");
return selector
.split(",")
.map((item) => item.indexOf(":hover") > -1 ? item.replace(/^(\s*)/, "$1" + thePrefix + " ") : item)
.join(",");
}
return {
postcssPlugin: 'postcss-prefix-hover',
Root (root) {
root.walkRules((rule) => {
if (rule.selector.indexOf(":hover") > -1) {
rule.selector = setPrefix(rule.selector);
}
});
}
}
}
module.exports.postcss = true;