|
|
"use strict";
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
exports.default = void 0;
|
|
|
|
|
|
var _container = _interopRequireDefault(require("./container"));
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
|
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
|
|
|
|
|
/**
|
|
|
* Represents a CSS file and contains all its parsed nodes.
|
|
|
*
|
|
|
* @extends Container
|
|
|
*
|
|
|
* @example
|
|
|
* const root = postcss.parse('a{color:black} b{z-index:2}')
|
|
|
* root.type //=> 'root'
|
|
|
* root.nodes.length //=> 2
|
|
|
*/
|
|
|
var Root =
|
|
|
/*#__PURE__*/
|
|
|
function (_Container) {
|
|
|
_inheritsLoose(Root, _Container);
|
|
|
|
|
|
function Root(defaults) {
|
|
|
var _this;
|
|
|
|
|
|
_this = _Container.call(this, defaults) || this;
|
|
|
_this.type = 'root';
|
|
|
if (!_this.nodes) _this.nodes = [];
|
|
|
return _this;
|
|
|
}
|
|
|
|
|
|
var _proto = Root.prototype;
|
|
|
|
|
|
_proto.removeChild = function removeChild(child, ignore) {
|
|
|
var index = this.index(child);
|
|
|
|
|
|
if (!ignore && index === 0 && this.nodes.length > 1) {
|
|
|
this.nodes[1].raws.before = this.nodes[index].raws.before;
|
|
|
}
|
|
|
|
|
|
return _Container.prototype.removeChild.call(this, child);
|
|
|
};
|
|
|
|
|
|
_proto.normalize = function normalize(child, sample, type) {
|
|
|
var nodes = _Container.prototype.normalize.call(this, child);
|
|
|
|
|
|
if (sample) {
|
|
|
if (type === 'prepend') {
|
|
|
if (this.nodes.length > 1) {
|
|
|
sample.raws.before = this.nodes[1].raws.before;
|
|
|
} else {
|
|
|
delete sample.raws.before;
|
|
|
}
|
|
|
} else if (this.first !== sample) {
|
|
|
for (var _iterator = nodes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
|
|
var _ref;
|
|
|
|
|
|
if (_isArray) {
|
|
|
if (_i >= _iterator.length) break;
|
|
|
_ref = _iterator[_i++];
|
|
|
} else {
|
|
|
_i = _iterator.next();
|
|
|
if (_i.done) break;
|
|
|
_ref = _i.value;
|
|
|
}
|
|
|
|
|
|
var node = _ref;
|
|
|
node.raws.before = sample.raws.before;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return nodes;
|
|
|
}
|
|
|
/**
|
|
|
* Returns a {@link Result} instance representing the root’s CSS.
|
|
|
*
|
|
|
* @param {processOptions} [opts] Options with only `to` and `map` keys.
|
|
|
*
|
|
|
* @return {Result} Result with current root’s CSS.
|
|
|
*
|
|
|
* @example
|
|
|
* const root1 = postcss.parse(css1, { from: 'a.css' })
|
|
|
* const root2 = postcss.parse(css2, { from: 'b.css' })
|
|
|
* root1.append(root2)
|
|
|
* const result = root1.toResult({ to: 'all.css', map: true })
|
|
|
*/
|
|
|
;
|
|
|
|
|
|
_proto.toResult = function toResult(opts) {
|
|
|
if (opts === void 0) {
|
|
|
opts = {};
|
|
|
}
|
|
|
|
|
|
var LazyResult = require('./lazy-result');
|
|
|
|
|
|
var Processor = require('./processor');
|
|
|
|
|
|
var lazy = new LazyResult(new Processor(), this, opts);
|
|
|
return lazy.stringify();
|
|
|
}
|
|
|
/**
|
|
|
* @memberof Root#
|
|
|
* @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:
|
|
|
*
|
|
|
* * `after`: the space symbols after the last child to the end of file.
|
|
|
* * `semicolon`: is the last child has an (optional) semicolon.
|
|
|
*
|
|
|
* @example
|
|
|
* postcss.parse('a {}\n').raws //=> { after: '\n' }
|
|
|
* postcss.parse('a {}').raws //=> { after: '' }
|
|
|
*/
|
|
|
;
|
|
|
|
|
|
return Root;
|
|
|
}(_container.default);
|
|
|
|
|
|
var _default = Root;
|
|
|
exports.default = _default;
|
|
|
module.exports = exports.default;
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJvb3QuZXM2Il0sIm5hbWVzIjpbIlJvb3QiLCJkZWZhdWx0cyIsInR5cGUiLCJub2RlcyIsInJlbW92ZUNoaWxkIiwiY2hpbGQiLCJpZ25vcmUiLCJpbmRleCIsImxlbmd0aCIsInJhd3MiLCJiZWZvcmUiLCJub3JtYWxpemUiLCJzYW1wbGUiLCJmaXJzdCIsIm5vZGUiLCJ0b1Jlc3VsdCIsIm9wdHMiLCJMYXp5UmVzdWx0IiwicmVxdWlyZSIsIlByb2Nlc3NvciIsImxhenkiLCJzdHJpbmdpZnkiLCJDb250YWluZXIiXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUE7Ozs7OztBQUVBOzs7Ozs7Ozs7O0lBVU1BLEk7Ozs7O0FBQ0osZ0JBQWFDLFFBQWIsRUFBdUI7QUFBQTs7QUFDckIsa0NBQU1BLFFBQU47QUFDQSxVQUFLQyxJQUFMLEdBQVksTUFBWjtBQUNBLFFBQUksQ0FBQyxNQUFLQyxLQUFWLEVBQWlCLE1BQUtBLEtBQUwsR0FBYSxFQUFiO0FBSEk7QUFJdEI7Ozs7U0FFREMsVyxHQUFBLHFCQUFhQyxLQUFiLEVBQW9CQyxNQUFwQixFQUE0QjtBQUMxQixRQUFJQyxLQUFLLEdBQUcsS0FBS0EsS0FBTCxDQUFXRixLQUFYLENBQVo7O0FBRUEsUUFBSSxDQUFDQyxNQUFELElBQVdDLEtBQUssS0FBSyxDQUFyQixJQUEwQixLQUFLSixLQUFMLENBQVdLLE1BQVgsR0FBb0IsQ0FBbEQsRUFBcUQ7QUFDbkQsV0FBS0wsS0FBTCxDQUFXLENBQVgsRUFBY00sSUFBZCxDQUFtQkMsTUFBbkIsR0FBNEIsS0FBS1AsS0FBTCxDQUFXSSxLQUFYLEVBQWtCRSxJQUFs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