-
Notifications
You must be signed in to change notification settings - Fork 1
/
matches-prefixer.js
33 lines (32 loc) · 1 KB
/
matches-prefixer.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
// From: https://gist.github.com/dennisgaebel/4290fd6e5dbba5e9b35e2587dcc20849
const postcss = require('postcss');
module.exports = postcss.plugin('postcss-matches', () => {
return root => {
root.walkRules(rule => {
if (rule.selector.indexOf(':matches(') !== -1) {
mozRule = rule.clone();
webkitRule = rule.clone();
mozRule.selectors = rule.selectors.reduce((all, i) => {
if (i.indexOf(':matches(') !== -1) {
return all.concat([
i.replace(/:matches\(/gi, ':-moz-any(')
])
} else {
return all.concat([i])
}
}, []);
webkitRule.selectors = rule.selectors.reduce((all, i) => {
if (i.indexOf(':matches(') !== -1) {
return all.concat([
i.replace(/:matches\(/gi, ':-webkit-any('),
])
} else {
return all.concat([i])
}
}, []);
root.append(mozRule);
root.append(webkitRule);
}
})
}
});