at-rule.js 702 B

1234567891011121314151617181920212223242526272829303132333435
  1. let Prefixer = require('./prefixer')
  2. class AtRule extends Prefixer {
  3. /**
  4. * Clone and add prefixes for at-rule
  5. */
  6. add(rule, prefix) {
  7. let prefixed = prefix + rule.name
  8. let already = rule.parent.some(
  9. i => i.name === prefixed && i.params === rule.params
  10. )
  11. if (already) {
  12. return undefined
  13. }
  14. let cloned = this.clone(rule, { name: prefixed })
  15. return rule.parent.insertBefore(rule, cloned)
  16. }
  17. /**
  18. * Clone node with prefixes
  19. */
  20. process(node) {
  21. let parent = this.parentPrefix(node)
  22. for (let prefix of this.prefixes) {
  23. if (!parent || parent === prefix) {
  24. this.add(node, prefix)
  25. }
  26. }
  27. }
  28. }
  29. module.exports = AtRule