Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 34x 20x 20x 14x 10x 34x 5x 5x 5x 1x 1x | /* eslint-disable max-len */
let postcss = require('postcss')
/*
_ _
| | | |
_ __ ___ ___| |_ ___ ___ ___ ______ _ __ ___ ___ _ _ __| | ___ ______ __ _ _ __ _ _
| '_ \ / _ \/ __| __/ __/ __/ __|______| '_ \/ __|/ _ \ | | |/ _` |/ _ \______/ _` | '_ \| | | |
| |_) | (_) \__ \ || (__\__ \__ \ | |_) \__ \ __/ |_| | (_| | (_) | | (_| | | | | |_| |
| .__/ \___/|___/\__\___|___/___/ | .__/|___/\___|\__,_|\__,_|\___/ \__,_|_| |_|\__, |
| | | | __/ |
|_| |_| |___/
This plugin does the following:
1. It catches instances of :any() selectors within rules, including
badly formed versions
--optionally, modern :is() and :matches() versions
--optionally, already-prefixed :-moz-any() and :-webkit-any() versions
2. It clones and separates the rule in to ones with prefixed :-moz-any() and :-webkit-any() selectors,
separate from non-:any() selectors from the original rule.
*/
const postcssPseudoAny = postcss.plugin('postcss-pseudo-any', ({
matchModern = true,
matchPrefixed = false
} = {}) => {
// eslint-disable-next-line security/detect-non-literal-regexp
let anyRE = new RegExp(`::?(${ matchModern ? 'is|matches|' : '' }${ matchPrefixed ? '(-?(moz|webkit)-)?' : '' }any)\\(`)
return root => {
root.walkRules(rule => {
Eif (rule.selector.match(anyRE)) {
let mozRule = rule.cloneBefore()
let webkitRule = rule.cloneBefore()
let mozSelectors = []
let webkitSelectors = []
rule.selectors = rule.selectors.reduce((arr, sel) => {
if (sel.match(anyRE)) {
mozSelectors.push(sel.replace(anyRE, ':-moz-any('))
webkitSelectors.push(sel.replace(anyRE, ':-webkit-any('))
} else if (sel.length > 0) {
arr.push(sel)
}
return arr
}, [])
mozRule.selectors = mozSelectors
webkitRule.selectors = webkitSelectors
if (rule.selectors.length === 1 && rule.selectors[0] === '') {
rule.remove()
}
}
})
}
})
module.exports = postcssPseudoAny
|