at-rule.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. var Prefixer = require('./prefixer');
  6. var AtRule = function (_Prefixer) {
  7. _inherits(AtRule, _Prefixer);
  8. function AtRule() {
  9. _classCallCheck(this, AtRule);
  10. return _possibleConstructorReturn(this, _Prefixer.apply(this, arguments));
  11. }
  12. /**
  13. * Clone and add prefixes for at-rule
  14. */
  15. AtRule.prototype.add = function add(rule, prefix) {
  16. var prefixed = prefix + rule.name;
  17. var already = rule.parent.some(function (i) {
  18. return i.name === prefixed && i.params === rule.params;
  19. });
  20. if (already) {
  21. return undefined;
  22. }
  23. var cloned = this.clone(rule, { name: prefixed });
  24. return rule.parent.insertBefore(rule, cloned);
  25. };
  26. /**
  27. * Clone node with prefixes
  28. */
  29. AtRule.prototype.process = function process(node) {
  30. var parent = this.parentPrefix(node);
  31. for (var _iterator = this.prefixes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  32. var _ref;
  33. if (_isArray) {
  34. if (_i >= _iterator.length) break;
  35. _ref = _iterator[_i++];
  36. } else {
  37. _i = _iterator.next();
  38. if (_i.done) break;
  39. _ref = _i.value;
  40. }
  41. var prefix = _ref;
  42. if (!parent || parent === prefix) {
  43. this.add(node, prefix);
  44. }
  45. }
  46. };
  47. return AtRule;
  48. }(Prefixer);
  49. module.exports = AtRule;