2017-11-23 12:01:04 -05:00
|
|
|
import postcss from 'postcss'
|
|
|
|
|
import cloneNodes from './cloneNodes'
|
|
|
|
|
|
|
|
|
|
export default function wrapWithVariants(rules, variants) {
|
2020-07-15 17:28:33 -04:00
|
|
|
let foundVariantAtRule = false
|
|
|
|
|
|
|
|
|
|
postcss.root({ nodes: rules }).walkAtRules('variants', () => {
|
|
|
|
|
foundVariantAtRule = true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (foundVariantAtRule) {
|
|
|
|
|
return cloneNodes(rules)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 12:01:04 -05:00
|
|
|
return postcss
|
|
|
|
|
.atRule({
|
|
|
|
|
name: 'variants',
|
|
|
|
|
params: variants.join(', '),
|
|
|
|
|
})
|
2019-07-13 16:52:07 +02:00
|
|
|
.append(cloneNodes(Array.isArray(rules) ? rules : [rules]))
|
2017-11-23 12:01:04 -05:00
|
|
|
}
|