rule.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _container = _interopRequireDefault(require("./container"));
  5. var _list = _interopRequireDefault(require("./list"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  10. /**
  11. * Represents a CSS rule: a selector followed by a declaration block.
  12. *
  13. * @extends Container
  14. *
  15. * @example
  16. * const root = postcss.parse('a{}')
  17. * const rule = root.first
  18. * rule.type //=> 'rule'
  19. * rule.toString() //=> 'a{}'
  20. */
  21. var Rule = /*#__PURE__*/function (_Container) {
  22. _inheritsLoose(Rule, _Container);
  23. function Rule(defaults) {
  24. var _this;
  25. _this = _Container.call(this, defaults) || this;
  26. _this.type = 'rule';
  27. if (!_this.nodes) _this.nodes = [];
  28. return _this;
  29. }
  30. /**
  31. * An array containing the rule’s individual selectors.
  32. * Groups of selectors are split at commas.
  33. *
  34. * @type {string[]}
  35. *
  36. * @example
  37. * const root = postcss.parse('a, b { }')
  38. * const rule = root.first
  39. *
  40. * rule.selector //=> 'a, b'
  41. * rule.selectors //=> ['a', 'b']
  42. *
  43. * rule.selectors = ['a', 'strong']
  44. * rule.selector //=> 'a, strong'
  45. */
  46. _createClass(Rule, [{
  47. key: "selectors",
  48. get: function get() {
  49. return _list.default.comma(this.selector);
  50. },
  51. set: function set(values) {
  52. var match = this.selector ? this.selector.match(/,\s*/) : null;
  53. var sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
  54. this.selector = values.join(sep);
  55. }
  56. /**
  57. * @memberof Rule#
  58. * @member {string} selector The rule’s full selector represented
  59. * as a string.
  60. *
  61. * @example
  62. * const root = postcss.parse('a, b { }')
  63. * const rule = root.first
  64. * rule.selector //=> 'a, b'
  65. */
  66. /**
  67. * @memberof Rule#
  68. * @member {object} raws Information to generate byte-to-byte equal
  69. * node string as it was in the origin input.
  70. *
  71. * Every parser saves its own properties,
  72. * but the default CSS parser uses:
  73. *
  74. * * `before`: the space symbols before the node. It also stores `*`
  75. * and `_` symbols before the declaration (IE hack).
  76. * * `after`: the space symbols after the last child of the node
  77. * to the end of the node.
  78. * * `between`: the symbols between the property and value
  79. * for declarations, selector and `{` for rules, or last parameter
  80. * and `{` for at-rules.
  81. * * `semicolon`: contains `true` if the last child has
  82. * an (optional) semicolon.
  83. * * `ownSemicolon`: contains `true` if there is semicolon after rule.
  84. *
  85. * PostCSS cleans selectors from comments and extra spaces,
  86. * but it stores origin content in raws properties.
  87. * As such, if you don’t change a declaration’s value,
  88. * PostCSS will use the raw value with comments.
  89. *
  90. * @example
  91. * const root = postcss.parse('a {\n color:black\n}')
  92. * root.first.first.raws //=> { before: '', between: ' ', after: '\n' }
  93. */
  94. }]);
  95. return Rule;
  96. }(_container.default);
  97. var _default = Rule;
  98. exports.default = _default;
  99. module.exports = exports.default;
  100. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGUuZXM2Il0sIm5hbWVzIjpbIlJ1bGUiLCJkZWZhdWx0cyIsInR5cGUiLCJub2RlcyIsImxpc3QiLCJjb21tYSIsInNlbGVjdG9yIiwidmFsdWVzIiwibWF0Y2giLCJzZXAiLCJyYXciLCJqb2luIiwiQ29udGFpbmVyIl0sIm1hcHBpbmdzIjo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