You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
8.5 KiB

4 years ago
  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 =
  22. /*#__PURE__*/
  23. function (_Container) {
  24. _inheritsLoose(Rule, _Container);
  25. function Rule(defaults) {
  26. var _this;
  27. _this = _Container.call(this, defaults) || this;
  28. _this.type = 'rule';
  29. if (!_this.nodes) _this.nodes = [];
  30. return _this;
  31. }
  32. /**
  33. * An array containing the rules individual selectors.
  34. * Groups of selectors are split at commas.
  35. *
  36. * @type {string[]}
  37. *
  38. * @example
  39. * const root = postcss.parse('a, b { }')
  40. * const rule = root.first
  41. *
  42. * rule.selector //=> 'a, b'
  43. * rule.selectors //=> ['a', 'b']
  44. *
  45. * rule.selectors = ['a', 'strong']
  46. * rule.selector //=> 'a, strong'
  47. */
  48. _createClass(Rule, [{
  49. key: "selectors",
  50. get: function get() {
  51. return _list.default.comma(this.selector);
  52. },
  53. set: function set(values) {
  54. var match = this.selector ? this.selector.match(/,\s*/) : null;
  55. var sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
  56. this.selector = values.join(sep);
  57. }
  58. /**
  59. * @memberof Rule#
  60. * @member {string} selector The rules full selector represented
  61. * as a string.
  62. *
  63. * @example
  64. * const root = postcss.parse('a, b { }')
  65. * const rule = root.first
  66. * rule.selector //=> 'a, b'
  67. */
  68. /**
  69. * @memberof Rule#
  70. * @member {object} raws Information to generate byte-to-byte equal
  71. * node string as it was in the origin input.
  72. *
  73. * Every parser saves its own properties,
  74. * but the default CSS parser uses:
  75. *
  76. * * `before`: the space symbols before the node. It also stores `*`
  77. * and `_` symbols before the declaration (IE hack).
  78. * * `after`: the space symbols after the last child of the node
  79. * to the end of the node.
  80. * * `between`: the symbols between the property and value
  81. * for declarations, selector and `{` for rules, or last parameter
  82. * and `{` for at-rules.
  83. * * `semicolon`: contains `true` if the last child has
  84. * an (optional) semicolon.
  85. * * `ownSemicolon`: contains `true` if there is semicolon after rule.
  86. *
  87. * PostCSS cleans selectors from comments and extra spaces,
  88. * but it stores origin content in raws properties.
  89. * As such, if you dont change a declarations value,
  90. * PostCSS will use the raw value with comments.
  91. *
  92. * @example
  93. * const root = postcss.parse('a {\n color:black\n}')
  94. * root.first.first.raws //=> { before: '', between: ' ', after: '\n' }
  95. */
  96. }]);
  97. return Rule;
  98. }(_container.default);
  99. var _default = Rule;
  100. exports.default = _default;
  101. module.exports = exports.default;
  102. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGUuZXM2Il0sIm5hbWVzIjpbIlJ1bGUiLCJkZWZhdWx0cyIsInR5cGUiLCJub2RlcyIsImxpc3QiLCJjb21tYSIsInNlbGVjdG9yIiwidmFsdWVzIiwibWF0Y2giLCJzZXAiLCJyYXciLCJqb2luIiwiQ29udGFpbmVyIl0sIm1hcHBpbmdzIjoiOzs7OztBQUFBOztBQUNBOzs7Ozs7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