wishthis/node_modules/autoprefixer/lib/at-rule.js

36 lines
702 B
JavaScript
Raw Normal View History

2023-08-17 09:47:40 +00:00
let Prefixer = require('./prefixer')
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
class AtRule extends Prefixer {
2022-01-21 08:28:41 +00:00
/**
2023-08-17 09:47:40 +00:00
* Clone and add prefixes for at-rule
*/
add(rule, prefix) {
let prefixed = prefix + rule.name
let already = rule.parent.some(
i => i.name === prefixed && i.params === rule.params
)
2022-01-21 08:28:41 +00:00
if (already) {
2023-08-17 09:47:40 +00:00
return undefined
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
let cloned = this.clone(rule, { name: prefixed })
return rule.parent.insertBefore(rule, cloned)
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
/**
* Clone node with prefixes
*/
process(node) {
let parent = this.parentPrefix(node)
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
for (let prefix of this.prefixes) {
2022-01-21 08:28:41 +00:00
if (!parent || parent === prefix) {
2023-08-17 09:47:40 +00:00
this.add(node, prefix)
2022-01-21 08:28:41 +00:00
}
}
2023-08-17 09:47:40 +00:00
}
}
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
module.exports = AtRule