130 lines
9.0 KiB
JavaScript
130 lines
9.0 KiB
JavaScript
|
"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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJvb3QuZXM2Il0sIm5hbWVzIjpbIlJvb3QiLCJkZWZhdWx0cyIsInR5cGUiLCJub2RlcyIsInJlbW92ZUNoaWxkIiwiY2hpbGQiLCJpZ25vcmUiLCJpbmRleCIsImxlbmd0aCIsInJhd3MiLCJiZWZvcmUiLCJub3JtYWxpemUiLCJzYW1wbGUiLCJmaXJzdCIsIm5vZGUiLCJ0b1Jlc3VsdCIsIm9wdHMiLCJMYXp5UmVzdWx0IiwicmVxdWlyZSIsIlByb2Nlc3NvciIsImxhenkiLCJzdHJpbmdpZnkiLCJDb250YWluZXIiXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUE7Ozs7OztBQUVBOzs7Ozs7Ozs7O0lBVU1BLEk7Ozs7O0FBQ0osZ0JBQWFDLFFBQWIsRUFBdUI7QUFBQTs7QUFDckIsa0NBQU1BLFFBQU47QUFDQSxVQUFLQyxJQUFMLEdBQVksTUFBWjtBQUNBLFFBQUksQ0FBQyxNQUFLQyxLQUFWLEVBQWlCLE1BQUtBLEtBQUwsR0FBYSxFQUFiO0FBSEk7QUFJdEI7Ozs7U0FFREMsVyxHQUFBLHFCQUFhQyxLQUFiLEVBQW9CQyxNQUFwQixFQUE0QjtBQUMxQixRQUFJQyxLQUFLLEdBQUcsS0FBS0EsS0FBTCxDQUFXRixLQUFYLENBQVo7O0FBRUEsUUFBSSxDQUFDQyxNQUFELElBQVdDLEtBQUssS0FBSyxDQUFyQixJQUEwQixLQUFLSix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