124 lines
9.5 KiB
JavaScript
124 lines
9.5 KiB
JavaScript
|
'use strict';
|
|||
|
|
|||
|
exports.__esModule = true;
|
|||
|
|
|||
|
var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|||
|
|
|||
|
var _container = require('./container');
|
|||
|
|
|||
|
var _container2 = _interopRequireDefault(_container);
|
|||
|
|
|||
|
var _list = require('./list');
|
|||
|
|
|||
|
var _list2 = _interopRequireDefault(_list);
|
|||
|
|
|||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|||
|
|
|||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|||
|
|
|||
|
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; }
|
|||
|
|
|||
|
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; }
|
|||
|
|
|||
|
/**
|
|||
|
* Represents a CSS rule: a selector followed by a declaration block.
|
|||
|
*
|
|||
|
* @extends Container
|
|||
|
*
|
|||
|
* @example
|
|||
|
* const root = postcss.parse('a{}');
|
|||
|
* const rule = root.first;
|
|||
|
* rule.type //=> 'rule'
|
|||
|
* rule.toString() //=> 'a{}'
|
|||
|
*/
|
|||
|
var Rule = function (_Container) {
|
|||
|
_inherits(Rule, _Container);
|
|||
|
|
|||
|
function Rule(defaults) {
|
|||
|
_classCallCheck(this, Rule);
|
|||
|
|
|||
|
var _this = _possibleConstructorReturn(this, _Container.call(this, defaults));
|
|||
|
|
|||
|
_this.type = 'rule';
|
|||
|
if (!_this.nodes) _this.nodes = [];
|
|||
|
return _this;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* An array containing the rule’s individual selectors.
|
|||
|
* Groups of selectors are split at commas.
|
|||
|
*
|
|||
|
* @type {string[]}
|
|||
|
*
|
|||
|
* @example
|
|||
|
* const root = postcss.parse('a, b { }');
|
|||
|
* const rule = root.first;
|
|||
|
*
|
|||
|
* rule.selector //=> 'a, b'
|
|||
|
* rule.selectors //=> ['a', 'b']
|
|||
|
*
|
|||
|
* rule.selectors = ['a', 'strong'];
|
|||
|
* rule.selector //=> 'a, strong'
|
|||
|
*/
|
|||
|
|
|||
|
|
|||
|
_createClass(Rule, [{
|
|||
|
key: 'selectors',
|
|||
|
get: function get() {
|
|||
|
return _list2.default.comma(this.selector);
|
|||
|
},
|
|||
|
set: function set(values) {
|
|||
|
var match = this.selector ? this.selector.match(/,\s*/) : null;
|
|||
|
var sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
|
|||
|
this.selector = values.join(sep);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @memberof Rule#
|
|||
|
* @member {string} selector - the rule’s full selector represented
|
|||
|
* as a string
|
|||
|
*
|
|||
|
* @example
|
|||
|
* const root = postcss.parse('a, b { }');
|
|||
|
* const rule = root.first;
|
|||
|
* rule.selector //=> 'a, b'
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* @memberof Rule#
|
|||
|
* @member {object} raws - Information to generate byte-to-byte equal
|
|||
|
* node string as it was in the origin input.
|
|||
|
*
|
|||
|
* Every parser saves its own properties,
|
|||
|
* but the default CSS parser uses:
|
|||
|
*
|
|||
|
* * `before`: the space symbols before the node. It also stores `*`
|
|||
|
* and `_` symbols before the declaration (IE hack).
|
|||
|
* * `after`: the space symbols after the last child of the node
|
|||
|
* to the end of the node.
|
|||
|
* * `between`: the symbols between the property and value
|
|||
|
* for declarations, selector and `{` for rules, or last parameter
|
|||
|
* and `{` for at-rules.
|
|||
|
* * `semicolon`: contains `true` if the last child has
|
|||
|
* an (optional) semicolon.
|
|||
|
* * `ownSemicolon`: contains `true` if there is semicolon after rule.
|
|||
|
*
|
|||
|
* PostCSS cleans selectors from comments and extra spaces,
|
|||
|
* but it stores origin content in raws properties.
|
|||
|
* As such, if you don’t change a declaration’s value,
|
|||
|
* PostCSS will use the raw value with comments.
|
|||
|
*
|
|||
|
* @example
|
|||
|
* const root = postcss.parse('a {\n color:black\n}')
|
|||
|
* root.first.first.raws //=> { before: '', between: ' ', after: '\n' }
|
|||
|
*/
|
|||
|
|
|||
|
}]);
|
|||
|
|
|||
|
return Rule;
|
|||
|
}(_container2.default);
|
|||
|
|
|||
|
exports.default = Rule;
|
|||
|
module.exports = exports['default'];
|
|||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGUuZXM2Il0sIm5hbWVzIjpbIlJ1bGUiLCJkZWZhdWx0cyIsInR5cGUiLCJub2RlcyIsImxpc3QiLCJjb21tYSIsInNlbGVjdG9yIiwidmFsdWVzIiwibWF0Y2giLCJzZXAiLCJyYXciLCJqb2luIiwiQ29udGFpbmVyIl0sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQTs7OztBQUNBOzs7Ozs7Ozs7Ozs7QUFFQTs7Ozs7Ozs7Ozs7SUFXTUEsSTs7O0FBRUYsZ0JBQVlDLFFBQVosRUFBc0I7QUFBQTs7QUFBQSxpREFDbEIsc0JBQU1BLFFBQU4sQ0FEa0I7O0FBRWxCLFVBQUtDLElBQUwsR0FBWSxNQUFaO0FBQ0EsUUFBSyxDQUFDLE1BQUtDLEtBQVgsRUFBbUIsTUFBS0E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