forked from zhurui/management
908 lines
74 KiB
JavaScript
908 lines
74 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 _declaration = require('./declaration');
|
||
|
||
var _declaration2 = _interopRequireDefault(_declaration);
|
||
|
||
var _comment = require('./comment');
|
||
|
||
var _comment2 = _interopRequireDefault(_comment);
|
||
|
||
var _node = require('./node');
|
||
|
||
var _node2 = _interopRequireDefault(_node);
|
||
|
||
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; }
|
||
|
||
function cleanSource(nodes) {
|
||
return nodes.map(function (i) {
|
||
if (i.nodes) i.nodes = cleanSource(i.nodes);
|
||
delete i.source;
|
||
return i;
|
||
});
|
||
}
|
||
|
||
/**
|
||
* The {@link Root}, {@link AtRule}, and {@link Rule} container nodes
|
||
* inherit some common methods to help work with their children.
|
||
*
|
||
* Note that all containers can store any content. If you write a rule inside
|
||
* a rule, PostCSS will parse it.
|
||
*
|
||
* @extends Node
|
||
* @abstract
|
||
*/
|
||
|
||
var Container = function (_Node) {
|
||
_inherits(Container, _Node);
|
||
|
||
function Container() {
|
||
_classCallCheck(this, Container);
|
||
|
||
return _possibleConstructorReturn(this, _Node.apply(this, arguments));
|
||
}
|
||
|
||
Container.prototype.push = function push(child) {
|
||
child.parent = this;
|
||
this.nodes.push(child);
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Iterates through the container’s immediate children,
|
||
* calling `callback` for each child.
|
||
*
|
||
* Returning `false` in the callback will break iteration.
|
||
*
|
||
* This method only iterates through the container’s immediate children.
|
||
* If you need to recursively iterate through all the container’s descendant
|
||
* nodes, use {@link Container#walk}.
|
||
*
|
||
* Unlike the for `{}`-cycle or `Array#forEach` this iterator is safe
|
||
* if you are mutating the array of child nodes during iteration.
|
||
* PostCSS will adjust the current index to match the mutations.
|
||
*
|
||
* @param {childIterator} callback - iterator receives each node and index
|
||
*
|
||
* @return {false|undefined} returns `false` if iteration was broke
|
||
*
|
||
* @example
|
||
* const root = postcss.parse('a { color: black; z-index: 1 }');
|
||
* const rule = root.first;
|
||
*
|
||
* for ( let decl of rule.nodes ) {
|
||
* decl.cloneBefore({ prop: '-webkit-' + decl.prop });
|
||
* // Cycle will be infinite, because cloneBefore moves the current node
|
||
* // to the next index
|
||
* }
|
||
*
|
||
* rule.each(decl => {
|
||
* decl.cloneBefore({ prop: '-webkit-' + decl.prop });
|
||
* // Will be executed only for color and z-index
|
||
* });
|
||
*/
|
||
|
||
|
||
Container.prototype.each = function each(callback) {
|
||
if (!this.lastEach) this.lastEach = 0;
|
||
if (!this.indexes) this.indexes = {};
|
||
|
||
this.lastEach += 1;
|
||
var id = this.lastEach;
|
||
this.indexes[id] = 0;
|
||
|
||
if (!this.nodes) return undefined;
|
||
|
||
var index = void 0,
|
||
result = void 0;
|
||
while (this.indexes[id] < this.nodes.length) {
|
||
index = this.indexes[id];
|
||
result = callback(this.nodes[index], index);
|
||
if (result === false) break;
|
||
|
||
this.indexes[id] += 1;
|
||
}
|
||
|
||
delete this.indexes[id];
|
||
|
||
return result;
|
||
};
|
||
|
||
/**
|
||
* Traverses the container’s descendant nodes, calling callback
|
||
* for each node.
|
||
*
|
||
* Like container.each(), this method is safe to use
|
||
* if you are mutating arrays during iteration.
|
||
*
|
||
* If you only need to iterate through the container’s immediate children,
|
||
* use {@link Container#each}.
|
||
*
|
||
* @param {childIterator} callback - iterator receives each node and index
|
||
*
|
||
* @return {false|undefined} returns `false` if iteration was broke
|
||
*
|
||
* @example
|
||
* root.walk(node => {
|
||
* // Traverses all descendant nodes.
|
||
* });
|
||
*/
|
||
|
||
|
||
Container.prototype.walk = function walk(callback) {
|
||
return this.each(function (child, i) {
|
||
var result = callback(child, i);
|
||
if (result !== false && child.walk) {
|
||
result = child.walk(callback);
|
||
}
|
||
return result;
|
||
});
|
||
};
|
||
|
||
/**
|
||
* Traverses the container’s descendant nodes, calling callback
|
||
* for each declaration node.
|
||
*
|
||
* If you pass a filter, iteration will only happen over declarations
|
||
* with matching properties.
|
||
*
|
||
* Like {@link Container#each}, this method is safe
|
||
* to use if you are mutating arrays during iteration.
|
||
*
|
||
* @param {string|RegExp} [prop] - string or regular expression
|
||
* to filter declarations by property name
|
||
* @param {childIterator} callback - iterator receives each node and index
|
||
*
|
||
* @return {false|undefined} returns `false` if iteration was broke
|
||
*
|
||
* @example
|
||
* root.walkDecls(decl => {
|
||
* checkPropertySupport(decl.prop);
|
||
* });
|
||
*
|
||
* root.walkDecls('border-radius', decl => {
|
||
* decl.remove();
|
||
* });
|
||
*
|
||
* root.walkDecls(/^background/, decl => {
|
||
* decl.value = takeFirstColorFromGradient(decl.value);
|
||
* });
|
||
*/
|
||
|
||
|
||
Container.prototype.walkDecls = function walkDecls(prop, callback) {
|
||
if (!callback) {
|
||
callback = prop;
|
||
return this.walk(function (child, i) {
|
||
if (child.type === 'decl') {
|
||
return callback(child, i);
|
||
}
|
||
});
|
||
} else if (prop instanceof RegExp) {
|
||
return this.walk(function (child, i) {
|
||
if (child.type === 'decl' && prop.test(child.prop)) {
|
||
return callback(child, i);
|
||
}
|
||
});
|
||
} else {
|
||
return this.walk(function (child, i) {
|
||
if (child.type === 'decl' && child.prop === prop) {
|
||
return callback(child, i);
|
||
}
|
||
});
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Traverses the container’s descendant nodes, calling callback
|
||
* for each rule node.
|
||
*
|
||
* If you pass a filter, iteration will only happen over rules
|
||
* with matching selectors.
|
||
*
|
||
* Like {@link Container#each}, this method is safe
|
||
* to use if you are mutating arrays during iteration.
|
||
*
|
||
* @param {string|RegExp} [selector] - string or regular expression
|
||
* to filter rules by selector
|
||
* @param {childIterator} callback - iterator receives each node and index
|
||
*
|
||
* @return {false|undefined} returns `false` if iteration was broke
|
||
*
|
||
* @example
|
||
* const selectors = [];
|
||
* root.walkRules(rule => {
|
||
* selectors.push(rule.selector);
|
||
* });
|
||
* console.log(`Your CSS uses ${selectors.length} selectors`);
|
||
*/
|
||
|
||
|
||
Container.prototype.walkRules = function walkRules(selector, callback) {
|
||
if (!callback) {
|
||
callback = selector;
|
||
|
||
return this.walk(function (child, i) {
|
||
if (child.type === 'rule') {
|
||
return callback(child, i);
|
||
}
|
||
});
|
||
} else if (selector instanceof RegExp) {
|
||
return this.walk(function (child, i) {
|
||
if (child.type === 'rule' && selector.test(child.selector)) {
|
||
return callback(child, i);
|
||
}
|
||
});
|
||
} else {
|
||
return this.walk(function (child, i) {
|
||
if (child.type === 'rule' && child.selector === selector) {
|
||
return callback(child, i);
|
||
}
|
||
});
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Traverses the container’s descendant nodes, calling callback
|
||
* for each at-rule node.
|
||
*
|
||
* If you pass a filter, iteration will only happen over at-rules
|
||
* that have matching names.
|
||
*
|
||
* Like {@link Container#each}, this method is safe
|
||
* to use if you are mutating arrays during iteration.
|
||
*
|
||
* @param {string|RegExp} [name] - string or regular expression
|
||
* to filter at-rules by name
|
||
* @param {childIterator} callback - iterator receives each node and index
|
||
*
|
||
* @return {false|undefined} returns `false` if iteration was broke
|
||
*
|
||
* @example
|
||
* root.walkAtRules(rule => {
|
||
* if ( isOld(rule.name) ) rule.remove();
|
||
* });
|
||
*
|
||
* let first = false;
|
||
* root.walkAtRules('charset', rule => {
|
||
* if ( !first ) {
|
||
* first = true;
|
||
* } else {
|
||
* rule.remove();
|
||
* }
|
||
* });
|
||
*/
|
||
|
||
|
||
Container.prototype.walkAtRules = function walkAtRules(name, callback) {
|
||
if (!callback) {
|
||
callback = name;
|
||
return this.walk(function (child, i) {
|
||
if (child.type === 'atrule') {
|
||
return callback(child, i);
|
||
}
|
||
});
|
||
} else if (name instanceof RegExp) {
|
||
return this.walk(function (child, i) {
|
||
if (child.type === 'atrule' && name.test(child.name)) {
|
||
return callback(child, i);
|
||
}
|
||
});
|
||
} else {
|
||
return this.walk(function (child, i) {
|
||
if (child.type === 'atrule' && child.name === name) {
|
||
return callback(child, i);
|
||
}
|
||
});
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Traverses the container’s descendant nodes, calling callback
|
||
* for each comment node.
|
||
*
|
||
* Like {@link Container#each}, this method is safe
|
||
* to use if you are mutating arrays during iteration.
|
||
*
|
||
* @param {childIterator} callback - iterator receives each node and index
|
||
*
|
||
* @return {false|undefined} returns `false` if iteration was broke
|
||
*
|
||
* @example
|
||
* root.walkComments(comment => {
|
||
* comment.remove();
|
||
* });
|
||
*/
|
||
|
||
|
||
Container.prototype.walkComments = function walkComments(callback) {
|
||
return this.walk(function (child, i) {
|
||
if (child.type === 'comment') {
|
||
return callback(child, i);
|
||
}
|
||
});
|
||
};
|
||
|
||
/**
|
||
* Inserts new nodes to the end of the container.
|
||
*
|
||
* @param {...(Node|object|string|Node[])} children - new nodes
|
||
*
|
||
* @return {Node} this node for methods chain
|
||
*
|
||
* @example
|
||
* const decl1 = postcss.decl({ prop: 'color', value: 'black' });
|
||
* const decl2 = postcss.decl({ prop: 'background-color', value: 'white' });
|
||
* rule.append(decl1, decl2);
|
||
*
|
||
* root.append({ name: 'charset', params: '"UTF-8"' }); // at-rule
|
||
* root.append({ selector: 'a' }); // rule
|
||
* rule.append({ prop: 'color', value: 'black' }); // declaration
|
||
* rule.append({ text: 'Comment' }) // comment
|
||
*
|
||
* root.append('a {}');
|
||
* root.first.append('color: black; z-index: 1');
|
||
*/
|
||
|
||
|
||
Container.prototype.append = function append() {
|
||
for (var _len = arguments.length, children = Array(_len), _key = 0; _key < _len; _key++) {
|
||
children[_key] = arguments[_key];
|
||
}
|
||
|
||
for (var _iterator = children, _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 child = _ref;
|
||
|
||
var nodes = this.normalize(child, this.last);
|
||
for (var _iterator2 = nodes, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||
var _ref2;
|
||
|
||
if (_isArray2) {
|
||
if (_i2 >= _iterator2.length) break;
|
||
_ref2 = _iterator2[_i2++];
|
||
} else {
|
||
_i2 = _iterator2.next();
|
||
if (_i2.done) break;
|
||
_ref2 = _i2.value;
|
||
}
|
||
|
||
var node = _ref2;
|
||
this.nodes.push(node);
|
||
}
|
||
}
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Inserts new nodes to the start of the container.
|
||
*
|
||
* @param {...(Node|object|string|Node[])} children - new nodes
|
||
*
|
||
* @return {Node} this node for methods chain
|
||
*
|
||
* @example
|
||
* const decl1 = postcss.decl({ prop: 'color', value: 'black' });
|
||
* const decl2 = postcss.decl({ prop: 'background-color', value: 'white' });
|
||
* rule.prepend(decl1, decl2);
|
||
*
|
||
* root.append({ name: 'charset', params: '"UTF-8"' }); // at-rule
|
||
* root.append({ selector: 'a' }); // rule
|
||
* rule.append({ prop: 'color', value: 'black' }); // declaration
|
||
* rule.append({ text: 'Comment' }) // comment
|
||
*
|
||
* root.append('a {}');
|
||
* root.first.append('color: black; z-index: 1');
|
||
*/
|
||
|
||
|
||
Container.prototype.prepend = function prepend() {
|
||
for (var _len2 = arguments.length, children = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
||
children[_key2] = arguments[_key2];
|
||
}
|
||
|
||
children = children.reverse();
|
||
for (var _iterator3 = children, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||
var _ref3;
|
||
|
||
if (_isArray3) {
|
||
if (_i3 >= _iterator3.length) break;
|
||
_ref3 = _iterator3[_i3++];
|
||
} else {
|
||
_i3 = _iterator3.next();
|
||
if (_i3.done) break;
|
||
_ref3 = _i3.value;
|
||
}
|
||
|
||
var child = _ref3;
|
||
|
||
var nodes = this.normalize(child, this.first, 'prepend').reverse();
|
||
for (var _iterator4 = nodes, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
|
||
var _ref4;
|
||
|
||
if (_isArray4) {
|
||
if (_i4 >= _iterator4.length) break;
|
||
_ref4 = _iterator4[_i4++];
|
||
} else {
|
||
_i4 = _iterator4.next();
|
||
if (_i4.done) break;
|
||
_ref4 = _i4.value;
|
||
}
|
||
|
||
var node = _ref4;
|
||
this.nodes.unshift(node);
|
||
}for (var id in this.indexes) {
|
||
this.indexes[id] = this.indexes[id] + nodes.length;
|
||
}
|
||
}
|
||
return this;
|
||
};
|
||
|
||
Container.prototype.cleanRaws = function cleanRaws(keepBetween) {
|
||
_Node.prototype.cleanRaws.call(this, keepBetween);
|
||
if (this.nodes) {
|
||
for (var _iterator5 = this.nodes, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
|
||
var _ref5;
|
||
|
||
if (_isArray5) {
|
||
if (_i5 >= _iterator5.length) break;
|
||
_ref5 = _iterator5[_i5++];
|
||
} else {
|
||
_i5 = _iterator5.next();
|
||
if (_i5.done) break;
|
||
_ref5 = _i5.value;
|
||
}
|
||
|
||
var node = _ref5;
|
||
node.cleanRaws(keepBetween);
|
||
}
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Insert new node before old node within the container.
|
||
*
|
||
* @param {Node|number} exist - child or child’s index.
|
||
* @param {Node|object|string|Node[]} add - new node
|
||
*
|
||
* @return {Node} this node for methods chain
|
||
*
|
||
* @example
|
||
* rule.insertBefore(decl, decl.clone({ prop: '-webkit-' + decl.prop }));
|
||
*/
|
||
|
||
|
||
Container.prototype.insertBefore = function insertBefore(exist, add) {
|
||
exist = this.index(exist);
|
||
|
||
var type = exist === 0 ? 'prepend' : false;
|
||
var nodes = this.normalize(add, this.nodes[exist], type).reverse();
|
||
for (var _iterator6 = nodes, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
|
||
var _ref6;
|
||
|
||
if (_isArray6) {
|
||
if (_i6 >= _iterator6.length) break;
|
||
_ref6 = _iterator6[_i6++];
|
||
} else {
|
||
_i6 = _iterator6.next();
|
||
if (_i6.done) break;
|
||
_ref6 = _i6.value;
|
||
}
|
||
|
||
var node = _ref6;
|
||
this.nodes.splice(exist, 0, node);
|
||
}var index = void 0;
|
||
for (var id in this.indexes) {
|
||
index = this.indexes[id];
|
||
if (exist <= index) {
|
||
this.indexes[id] = index + nodes.length;
|
||
}
|
||
}
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Insert new node after old node within the container.
|
||
*
|
||
* @param {Node|number} exist - child or child’s index
|
||
* @param {Node|object|string|Node[]} add - new node
|
||
*
|
||
* @return {Node} this node for methods chain
|
||
*/
|
||
|
||
|
||
Container.prototype.insertAfter = function insertAfter(exist, add) {
|
||
exist = this.index(exist);
|
||
|
||
var nodes = this.normalize(add, this.nodes[exist]).reverse();
|
||
for (var _iterator7 = nodes, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
|
||
var _ref7;
|
||
|
||
if (_isArray7) {
|
||
if (_i7 >= _iterator7.length) break;
|
||
_ref7 = _iterator7[_i7++];
|
||
} else {
|
||
_i7 = _iterator7.next();
|
||
if (_i7.done) break;
|
||
_ref7 = _i7.value;
|
||
}
|
||
|
||
var node = _ref7;
|
||
this.nodes.splice(exist + 1, 0, node);
|
||
}var index = void 0;
|
||
for (var id in this.indexes) {
|
||
index = this.indexes[id];
|
||
if (exist < index) {
|
||
this.indexes[id] = index + nodes.length;
|
||
}
|
||
}
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Removes node from the container and cleans the parent properties
|
||
* from the node and its children.
|
||
*
|
||
* @param {Node|number} child - child or child’s index
|
||
*
|
||
* @return {Node} this node for methods chain
|
||
*
|
||
* @example
|
||
* rule.nodes.length //=> 5
|
||
* rule.removeChild(decl);
|
||
* rule.nodes.length //=> 4
|
||
* decl.parent //=> undefined
|
||
*/
|
||
|
||
|
||
Container.prototype.removeChild = function removeChild(child) {
|
||
child = this.index(child);
|
||
this.nodes[child].parent = undefined;
|
||
this.nodes.splice(child, 1);
|
||
|
||
var index = void 0;
|
||
for (var id in this.indexes) {
|
||
index = this.indexes[id];
|
||
if (index >= child) {
|
||
this.indexes[id] = index - 1;
|
||
}
|
||
}
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Removes all children from the container
|
||
* and cleans their parent properties.
|
||
*
|
||
* @return {Node} this node for methods chain
|
||
*
|
||
* @example
|
||
* rule.removeAll();
|
||
* rule.nodes.length //=> 0
|
||
*/
|
||
|
||
|
||
Container.prototype.removeAll = function removeAll() {
|
||
for (var _iterator8 = this.nodes, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
|
||
var _ref8;
|
||
|
||
if (_isArray8) {
|
||
if (_i8 >= _iterator8.length) break;
|
||
_ref8 = _iterator8[_i8++];
|
||
} else {
|
||
_i8 = _iterator8.next();
|
||
if (_i8.done) break;
|
||
_ref8 = _i8.value;
|
||
}
|
||
|
||
var node = _ref8;
|
||
node.parent = undefined;
|
||
}this.nodes = [];
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Passes all declaration values within the container that match pattern
|
||
* through callback, replacing those values with the returned result
|
||
* of callback.
|
||
*
|
||
* This method is useful if you are using a custom unit or function
|
||
* and need to iterate through all values.
|
||
*
|
||
* @param {string|RegExp} pattern - replace pattern
|
||
* @param {object} opts - options to speed up the search
|
||
* @param {string|string[]} opts.props - an array of property names
|
||
* @param {string} opts.fast - string that’s used
|
||
* to narrow down values and speed up
|
||
the regexp search
|
||
* @param {function|string} callback - string to replace pattern
|
||
* or callback that returns a new
|
||
* value.
|
||
* The callback will receive
|
||
* the same arguments as those
|
||
* passed to a function parameter
|
||
* of `String#replace`.
|
||
*
|
||
* @return {Node} this node for methods chain
|
||
*
|
||
* @example
|
||
* root.replaceValues(/\d+rem/, { fast: 'rem' }, string => {
|
||
* return 15 * parseInt(string) + 'px';
|
||
* });
|
||
*/
|
||
|
||
|
||
Container.prototype.replaceValues = function replaceValues(pattern, opts, callback) {
|
||
if (!callback) {
|
||
callback = opts;
|
||
opts = {};
|
||
}
|
||
|
||
this.walkDecls(function (decl) {
|
||
if (opts.props && opts.props.indexOf(decl.prop) === -1) return;
|
||
if (opts.fast && decl.value.indexOf(opts.fast) === -1) return;
|
||
|
||
decl.value = decl.value.replace(pattern, callback);
|
||
});
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Returns `true` if callback returns `true`
|
||
* for all of the container’s children.
|
||
*
|
||
* @param {childCondition} condition - iterator returns true or false.
|
||
*
|
||
* @return {boolean} is every child pass condition
|
||
*
|
||
* @example
|
||
* const noPrefixes = rule.every(i => i.prop[0] !== '-');
|
||
*/
|
||
|
||
|
||
Container.prototype.every = function every(condition) {
|
||
return this.nodes.every(condition);
|
||
};
|
||
|
||
/**
|
||
* Returns `true` if callback returns `true` for (at least) one
|
||
* of the container’s children.
|
||
*
|
||
* @param {childCondition} condition - iterator returns true or false.
|
||
*
|
||
* @return {boolean} is some child pass condition
|
||
*
|
||
* @example
|
||
* const hasPrefix = rule.some(i => i.prop[0] === '-');
|
||
*/
|
||
|
||
|
||
Container.prototype.some = function some(condition) {
|
||
return this.nodes.some(condition);
|
||
};
|
||
|
||
/**
|
||
* Returns a `child`’s index within the {@link Container#nodes} array.
|
||
*
|
||
* @param {Node} child - child of the current container.
|
||
*
|
||
* @return {number} child index
|
||
*
|
||
* @example
|
||
* rule.index( rule.nodes[2] ) //=> 2
|
||
*/
|
||
|
||
|
||
Container.prototype.index = function index(child) {
|
||
if (typeof child === 'number') {
|
||
return child;
|
||
} else {
|
||
return this.nodes.indexOf(child);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* The container’s first child.
|
||
*
|
||
* @type {Node}
|
||
*
|
||
* @example
|
||
* rule.first == rules.nodes[0];
|
||
*/
|
||
|
||
|
||
Container.prototype.normalize = function normalize(nodes, sample) {
|
||
var _this2 = this;
|
||
|
||
if (typeof nodes === 'string') {
|
||
var parse = require('./parse');
|
||
nodes = cleanSource(parse(nodes).nodes);
|
||
} else if (Array.isArray(nodes)) {
|
||
nodes = nodes.slice(0);
|
||
for (var _iterator9 = nodes, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) {
|
||
var _ref9;
|
||
|
||
if (_isArray9) {
|
||
if (_i9 >= _iterator9.length) break;
|
||
_ref9 = _iterator9[_i9++];
|
||
} else {
|
||
_i9 = _iterator9.next();
|
||
if (_i9.done) break;
|
||
_ref9 = _i9.value;
|
||
}
|
||
|
||
var i = _ref9;
|
||
|
||
if (i.parent) i.parent.removeChild(i, 'ignore');
|
||
}
|
||
} else if (nodes.type === 'root') {
|
||
nodes = nodes.nodes.slice(0);
|
||
for (var _iterator10 = nodes, _isArray10 = Array.isArray(_iterator10), _i11 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) {
|
||
var _ref10;
|
||
|
||
if (_isArray10) {
|
||
if (_i11 >= _iterator10.length) break;
|
||
_ref10 = _iterator10[_i11++];
|
||
} else {
|
||
_i11 = _iterator10.next();
|
||
if (_i11.done) break;
|
||
_ref10 = _i11.value;
|
||
}
|
||
|
||
var _i10 = _ref10;
|
||
|
||
if (_i10.parent) _i10.parent.removeChild(_i10, 'ignore');
|
||
}
|
||
} else if (nodes.type) {
|
||
nodes = [nodes];
|
||
} else if (nodes.prop) {
|
||
if (typeof nodes.value === 'undefined') {
|
||
throw new Error('Value field is missed in node creation');
|
||
} else if (typeof nodes.value !== 'string') {
|
||
nodes.value = String(nodes.value);
|
||
}
|
||
nodes = [new _declaration2.default(nodes)];
|
||
} else if (nodes.selector) {
|
||
var Rule = require('./rule');
|
||
nodes = [new Rule(nodes)];
|
||
} else if (nodes.name) {
|
||
var AtRule = require('./at-rule');
|
||
nodes = [new AtRule(nodes)];
|
||
} else if (nodes.text) {
|
||
nodes = [new _comment2.default(nodes)];
|
||
} else {
|
||
throw new Error('Unknown node type in node creation');
|
||
}
|
||
|
||
var processed = nodes.map(function (i) {
|
||
if (typeof i.before !== 'function') i = _this2.rebuild(i);
|
||
|
||
if (i.parent) i.parent.removeChild(i);
|
||
if (typeof i.raws.before === 'undefined') {
|
||
if (sample && typeof sample.raws.before !== 'undefined') {
|
||
i.raws.before = sample.raws.before.replace(/[^\s]/g, '');
|
||
}
|
||
}
|
||
i.parent = _this2;
|
||
return i;
|
||
});
|
||
|
||
return processed;
|
||
};
|
||
|
||
Container.prototype.rebuild = function rebuild(node, parent) {
|
||
var _this3 = this;
|
||
|
||
var fix = void 0;
|
||
if (node.type === 'root') {
|
||
var Root = require('./root');
|
||
fix = new Root();
|
||
} else if (node.type === 'atrule') {
|
||
var AtRule = require('./at-rule');
|
||
fix = new AtRule();
|
||
} else if (node.type === 'rule') {
|
||
var Rule = require('./rule');
|
||
fix = new Rule();
|
||
} else if (node.type === 'decl') {
|
||
fix = new _declaration2.default();
|
||
} else if (node.type === 'comment') {
|
||
fix = new _comment2.default();
|
||
}
|
||
|
||
for (var i in node) {
|
||
if (i === 'nodes') {
|
||
fix.nodes = node.nodes.map(function (j) {
|
||
return _this3.rebuild(j, fix);
|
||
});
|
||
} else if (i === 'parent' && parent) {
|
||
fix.parent = parent;
|
||
} else if (node.hasOwnProperty(i)) {
|
||
fix[i] = node[i];
|
||
}
|
||
}
|
||
|
||
return fix;
|
||
};
|
||
|
||
/**
|
||
* @memberof Container#
|
||
* @member {Node[]} nodes - an array containing the container’s children
|
||
*
|
||
* @example
|
||
* const root = postcss.parse('a { color: black }');
|
||
* root.nodes.length //=> 1
|
||
* root.nodes[0].selector //=> 'a'
|
||
* root.nodes[0].nodes[0].prop //=> 'color'
|
||
*/
|
||
|
||
_createClass(Container, [{
|
||
key: 'first',
|
||
get: function get() {
|
||
if (!this.nodes) return undefined;
|
||
return this.nodes[0];
|
||
}
|
||
|
||
/**
|
||
* The container’s last child.
|
||
*
|
||
* @type {Node}
|
||
*
|
||
* @example
|
||
* rule.last == rule.nodes[rule.nodes.length - 1];
|
||
*/
|
||
|
||
}, {
|
||
key: 'last',
|
||
get: function get() {
|
||
if (!this.nodes) return undefined;
|
||
return this.nodes[this.nodes.length - 1];
|
||
}
|
||
}]);
|
||
|
||
return Container;
|
||
}(_node2.default);
|
||
|
||
exports.default = Container;
|
||
|
||
/**
|
||
* @callback childCondition
|
||
* @param {Node} node - container child
|
||
* @param {number} index - child index
|
||
* @param {Node[]} nodes - all container children
|
||
* @return {boolean}
|
||
*/
|
||
|
||
/**
|
||
* @callback childIterator
|
||
* @param {Node} node - container child
|
||
* @param {number} index - child index
|
||
* @return {false|undefined} returning `false` will break iteration
|
||
*/
|
||
|
||
module.exports = exports['default'];
|
||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbnRhaW5lci5lczYiXSwibmFtZXMiOlsiY2xlYW5Tb3VyY2UiLCJub2RlcyIsIm1hcCIsImkiLCJzb3VyY2UiLCJDb250YWluZXIiLCJwdXNoIiwiY2hpbGQiLCJwYXJlbnQiLCJlYWNoIiwiY2FsbGJhY2siLCJsYXN0RWFjaCIsImluZGV4ZXMiLCJpZCIsInVuZGVmaW5lZCIsImluZGV4IiwicmVzdWx0IiwibGVuZ3RoIiwid2FsayIsIndhbGtEZWNscyIsInByb3AiLCJ0eXBlIiwiUmVnRXhwIiwidGVzdCIsIndhbGtSdWxlcyIsInNlbGVjdG9yIiwid2Fsa0F0UnVsZXMiLCJuYW1lIiwid2Fsa0NvbW1lbnRzIiwiYXBwZW5kIiwiY2hpbGRyZW4iLCJub3JtYWxpemUiLCJsYXN0Iiwibm9kZSIsInByZXBlbmQiLCJyZXZlcnNlIiwiZmlyc3QiLCJ1bnNoaWZ0IiwiY2xlYW5SYXdzIiwia2VlcEJldHdlZW4iLCJpbnNlcnRCZWZvcmUiLCJleGlzdCIsImFkZCIsInNwbGljZSIsImluc2VydEFmdGVyIiwicmVtb3ZlQ2hpbGQiLCJyZW1vdmVBbGwiLCJyZXBsYWNlVmFsdWVzIiwicGF0dGVybiIsIm9wdHMiLCJwcm9wcyIsImluZGV4T2YiLCJkZWNsIiwiZmFzdCIsInZhbHVlIiwicmVwbGFjZSIsImV2ZXJ5IiwiY29uZGl0aW9uIiwic29tZSIsInNhbXBsZSIsInBhcnNlIiwicmVxdWlyZSIsIkFycmF5IiwiaXNBcnJheSIsInNsaWNlIiwiRXJyb3IiLCJTdHJpbmciLCJEZWNsYXJhdGlvbiIsIlJ1bGUiLCJBdFJ1bGUiLCJ0ZXh0IiwiQ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AgICAgICAgICAgcmV0dXJuIGNhbGxiYWNrKGNoaWxkLCBpKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIGlmICggcHJvcCBpbnN0YW5jZW9mIFJlZ0V4cCApIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLndhbGsoIChjaGlsZCwgaSkgPT4ge1xuICAgICAgICAgICAgICAgIGlmICggY2hpbGQudHlwZSA9PT0gJ2RlY2wnICYmIHByb3AudGVzdChjaGlsZC5wcm9wKSApIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNhbGxiYWNrKGNoaWxkLCBpKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLndhbGsoIChjaGlsZCwgaSkgPT4ge1xuICAgICAgICAgICAgICAgIGlmICggY2hpbGQudHlwZSA9PT0gJ2RlY2wnICYmIGNoaWxkLnByb3AgPT09IHByb3AgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjayhjaGlsZCwgaSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBUcmF2ZXJzZXMgdGhlIGNvbnRhaW5lcuKAmXMgZGVzY2VuZGFudCBub2RlcywgY2FsbGluZyBjYWxsYmFja1xuICAgICAqIGZvciBlYWNoIHJ1bGUgbm9kZS5cbiAgICAgKlxuICAgICAqIElmIHlvdSBwYXNzIGEgZmlsdGVyLCBpdGVyYXRpb24gd2lsbCBvbmx5IGhhcHBlbiBvdmVyIHJ1bGVzXG4gICAgICogd2l0aCBtYXRjaGluZyBzZWxlY3RvcnMuXG4gICAgICpcbiAgICAgKiBMaWtlIHtAbGluayBDb250YWluZXIjZWFjaH0sIHRoaXMgbWV0aG9kIGlzIHNhZmVcbiAgICAgKiB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ICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSBpZiAoIHNlbGVjdG9yIGluc3RhbmNlb2YgUmVnRXhwICkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMud2FsayggKGNoaWxkLCBpKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKCBjaGlsZC50eXBlID09PSAncnVsZScgJiYgc2VsZWN0b3IudGVzdChjaGlsZC5zZWxlY3RvcikgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjayhjaGlsZCwgaSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy53YWxrKCAoY2hpbGQsIGkpID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoIGNoaWxkLnR5cGUgPT09ICdydWxlJyAmJiBjaGlsZC5zZWxlY3RvciA9PT0gc2VsZWN0b3IgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjayhjaGlsZCwgaSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBUcmF2ZXJzZXMgdGhlIGNvbnRhaW5lcuKAmXMgZGVzY2VuZGFudCBub2RlcywgY2FsbGluZyBjYWxsYmFja1xuICAgICAqIGZvciBlYWNoIGF0LXJ1bGUgbm9kZS5cbiAgICAgKlxuICAgICAqIElmIHlvdSBwYXNzIGEgZmlsdGVyLCBpdGVyYXRpb24gd2lsbCBvbmx5IGhhcHBlbiBvdmVyIGF0LXJ1bGVzXG4gICAgICogdGhhdCBoYXZlIG1hdGNoaW5nIG5hbWVzLlxuICAgICAqXG4gICAgICogTGlrZSB7QGxpbmsgQ29udGFpbmVyI2VhY2h9LCB0aGlzIG1ldGhvZCBpcyBzYWZlXG4gICAgICogdG8gdXNlIGlmIHlvdSBhc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iAoIGNoaWxkLnR5cGUgPT09ICdhdHJ1bGUnICkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gY2FsbGJhY2soY2hpbGQsIGkpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2UgaWYgKCBuYW1lIGluc3RhbmNlb2YgUmVnRXhwICkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMud2FsayggKGNoaWxkLCBpKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKCBjaGlsZC50eXBlID09PSAnYXRydWxlJyAmJiBuYW1lLnRlc3QoY2hpbGQubmFtZSkgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjayhjaGlsZCwgaSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy53YWxrKCAoY2hpbGQsIGkpID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoIGNoaWxkLnR5cGUgPT09ICdhdHJ1bGUnICYmIGNoaWxkLm5hbWUgPT09IG5hbWUgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjayhjaGlsZCwgaSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBUcmF2ZXJzZXMgdGhlIGNvbnRhaW5lcuKAmXMgZGVzY2VuZGFudCBub2RlcywgY2FsbGluZyBjYWxsYmFja1xuICAgICAqIGZvciBlYWNoIGNvbW1lbnQgbm9kZS5cbiAgICAgKlxuICAgICAqIExpa2Uge0BsaW5rIENvbnRhaW5lciNlYWNofSwgdGhpcyBtZXRob2QgaXMgc2FmZVxuICAgICAqIHRvIHVzZSBpZiB5b3UgYXJlIG11dGF0aW5nIGFycmF5cyBkdXJpbmcgaXRlcmF0aW9uLlxuICAgICAqXG4gICA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QgcmV0dXJucyBhIG5ld1xuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdmFsdWUuXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBUaGUgY2FsbGJhY2sgd2lsbCByZWNlaXZlXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGUgc2FtZSBhcmd1bWVudHMgYXMgdGhvc2VcbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBhc3NlZCB0byBhIGZ1bmN0aW9uIHBhcmFtZXRlclxuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2YgYFN0cmluZyNyZXBsYWNlYC5cbiAgICAgKlxuICAgICAqIEByZXR1cm4ge05vZGV9IHRoaXMgbm9kZSBmb3IgbWV0aG9kcyBjaGFpblxuICAgICAqXG4gICAgICogQGV4YW1wbGVcbiAgICAgKiByb290LnJlcGxhY2VWYWx1ZXMoL1xcZCtyZW0vLCB7IGZhc3Q6ICdyZW0nIH0sIHN0cmluZyA9PiB7XG4gICAgICogICByZXR1cm4gMTUgKiBwYXJzZUludChzdHJpbmcpICsgJ3B4JztcbiAgICAgKiB9KTtcbiAgICAgKi9cbiAgICByZXBsYWNlVmFsdWVzKHBhdHRlcm4sIG9wdHMsIGNhbGxiYWNrKSB7XG4gICAgICAgIGlmICggIWNhbGxiYWNrICkge1xuICAgICAgICAgICAgY2FsbGJhY2sgPSBvcHRzO1xuICAgICAgICAgICAgb3B0cyA9IHsgfTtcbiAgICAgICAgfVxuXG4gICAgICAgIHRoaXMud2Fsa0RlY2xzKCBkZWNsID0+IHtcbiAgICAgICAgICAgIGlmICggb3B0cy5wcm9wcyAmJiBvcHRzLnByb3BzLmluZGV4T2YoZGVjbC5wcm9wKSA9PT0gLTEgKSByZXR1cm47XG4gICAgICAgICAgICBpZiAoIG9wdHMuZmFzdCAgJiYgZGVjbC52YW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GNoaWxkIHBhc3MgY29uZGl0aW9uXG4gICAgICpcbiAgICAgKiBAZXhhbXBsZVxuICAgICAqIGNvbnN0IGhhc1ByZWZpeCA9IHJ1bGUuc29tZShpID0+IGkucHJvcFswXSA9PT0gJy0nKTtcbiAgICAgKi9cbiAgICBzb21lKGNvbmRpdGlvbikge1xuICAgICAgICByZXR1cm4gdGhpcy5ub2Rlcy5zb21lKGNvbmRpdGlvbik7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogUmV0dXJucyBhIGBjaGlsZGDigJlzIGluZGV4IHdpdGhpbiB0aGUge0BsaW5rIENvbnRhaW5lciNub2Rlc30gYXJyYXkuXG4gICAgICpcbiAgICAgKiBAcGFyYW0ge05vZGV9IGNoaWxkIC0gY2hpbGQgb2YgdGhlIGN1cnJlbnQgY29udGFpbmVyLlxuICAgICAqXG4gICAgICogQHJldHVybiB7bnVtYmVyfSBjaGlsZCBpbmRleFxuICAgICAqXG4gICAgICogQGV4YW1wbGVcbiAgICAgKiBydWxlLmluZGV4KCBydWxlLm5vZGVzWzJdICkgLy89PiAyXG4gICAgICovXG4gICAgaW5kZXgoY2hpbGQpIHtcbiAgICAgICAgaWYgKCB0eXBlb2YgY2hpbGQgPT09ICdudW1iZXInICkge1xuICAgICAgICAgICAgcmV0dXJuIGNoaWxkO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMubm9kZXMuaW5kZXhPZihjaGlsZCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBUaGUgY29udGFpbmVy4oCZcyBmaXJzdCBjaGlsZC5cbiAgICAgKlxuICAgICAqIEB0eXBlIHtOb2RlfVxuICAgICAqXG4gICAgICogQGV4YW1wbGVcbiAgICAgKiBydWxlLmZpcnN0ID09IHJ1bGVzLm5vZGVzWzBdO1xuICAgICAqL1xuICAgIGdldCBmaXJzdCgpIHtcbiAgICAgICAgaWYgKCAhdGhpcy5ub2RlcyApIHJldHVyb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gKSB7XG4gICAgICAgICAgICAgICAgaWYgKCBpLnBhcmVudCApIGkucGFyZW50LnJlbW92ZUNoaWxkKGksICdpZ25vcmUnKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIGlmICggbm9kZXMudHlwZSApIHtcbiAgICAgICAgICAgIG5vZGVzID0gW25vZGVzXTtcbiAgICAgICAgfSBlbHNlIGlmICggbm9kZXMucHJvcCApIHtcbiAgICAgICAgICAgIGlmICggdHlwZW9mIG5vZGVzLnZhbHVlID09PSAndW5kZWZpbmVkJyApIHtcbiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ1ZhbHVlIGZpZWxkIGlzIG1pc3NlZCBpbiBub2RlIGNyZWF0aW9uJyk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKCB0eXBlb2Ygbm9kZXMudmFsdWUgIT09ICdzdHJpbmcnICkge1xuICAgICAgICAgICAgICAgIG5vZGVzLnZhbHVlID0gU3RyaW5nKG5vZGVzLnZhbHVlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIG5vZGVzID0gW25ldyBEZWNsYXJhdGlvbihub2RlcyldO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2Rlcy5zZWxlY3RvciApIHtcbiAgICAgICAgICAgIGxldCBSdWxlID0gcmVxdWlyZSgnLi9ydWxlJyk7XG4gICAgICAgICAgICBub2RlcyA9IFtuZXcgUnVsZShub2RlcyldO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2Rlcy5uYW1lICkge1xuICAgICAgICAgICAgbGV0IEF0UnVsZSA9IHJlcXVpcmUoJy4vYXQtcnVsZScpO1xuICAgICAgICAgICAgbm9kZXMgPSBbbmV3IEF0UnVsZShub2RlcyldO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2Rlcy50ZXh0ICkge1xuICAgICAgICAgICAgbm9kZXMgPSBbbmV3IENvbW1lbnQobm9kZXMpXTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignVW5rbm93biBub2RlIHR5cGUgaW4gbm9kZSBjcmVhdGlvbicpO1xuICAgICAgICB9XG5cbiAgICAgICAgbGV0IHByb2Nlc3NlZCA9IG5vZGVzLm1hcCggaSA9PiB7XG4gICAgICAgICAgICBpZiAoIHR5cGVvZiBpLmJlZm9yZSAhPT0gJ2Z1bmN0aW9uJyApIGkgPSB0aGlzLnJlYnVpbGQoaSk7XG5cbiAgICAgICAgICAgIGlmICggaS5wYXJlbnQgKSBpLnBhcmVudC5yZW1vdmVDaGlsZChpKTtcbiAgICAgICAgICAgIGlmICggdHlwZW9mIGkucmF3cy5iZWZvcmUgPT09ICd1bmRlZmluZWQnICkge1xuICAgICAgICAgICAgICAgIGlmICggc2FtcGxlICYmIHR5cGVvZiBzYW1wbGUucmF3cy5iZWZvcmUgIT09ICd1bmRlZmluZWQnICkge1xuICAgICAgICAgICAgICAgICAgICBpLnJhd3MuYmVmb3JlID0gc2FtcGxlLnJhd3MuYmVmb3JlLnJlcGxhY2UoL1teXFxzXS9nLCAnJyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaS5wYXJlbnQgPSB0aGlzO1xuICAgICAgICAgICAgcmV0dXJuIGk7XG4gICAgICAgIH0pO1xuXG4gICAgICAgIHJldHVybiBwcm9jZXNzZWQ7XG4gICAgfVxuXG4gICAgcmVidWlsZChub2RlLCBwYXJlbnQpIHtcbiAgICAgICAgbGV0IGZpeDtcbiAgICAgICAgaWYgKCBub2RlLnR5cGUgPT09ICdyb290JyApIHtcbiAgICAgICAgICAgIGxldCBSb290ID0gcmVxdWlyZSgnLi9yb290Jyk7XG4gICAgICAgICAgICBmaXggPSBuZXcgUm9vdCgpO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2RlLnR5cGUgPT09ICdhdHJ1bGUnICkge1xuICAgICAgICAgICAgbGV0IEF0UnVsZSA9IHJlcXVpcmUoJy4vYXQtcnVsZScpO1xuICAgICAgICAgICAgZml4ID0gbmV3IEF0UnVsZSgpO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2RlLnR5cGUgPT09ICdydWxlJyApIHtcbiAgICAgICAgICAgIGxldCBSdWxlID0gcmVxdWlyZSgnLi9ydWxlJyk7XG4gICAgICAgICAgICBmaXggPSBuZXcgUnVsZSgpO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2RlLnR5cGUgPT09ICdkZWNsJyApIHtcbiAgICAgICAgICAgIGZpeCA9IG5ldyBEZWNsYXJhdGlvbigpO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2RlLnR5cGUgPT09ICdjb21tZW50JyApIHtcbiAgICAgICAgICAgIGZpeCA9IG5ldyBDb21tZW50KCk7XG4gICAgICAgIH1cblxuICAgICAgICBmb3IgKCBsZXQgaSBpbiBub2RlICkge1xuICAgICAgICAgICAgaWYgKCBpID09PSAnbm9kZXMnICkge1xuICAgICAgICAgICAgICAgIGZpeC5ub2RlcyA9IG5vZGUubm9kZXMubWFwKCBqID0+IHRoaXMucmVidWlsZChqLCBmaXgpICk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKCBpID09PSAncGFyZW50JyAmJiBwYXJlbnQgKSB7XG4gICAgICAgICAgICAgICAgZml4LnBhcmVudCA9IHBhcmVudDtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIG5vZGUuaGFzT3duUHJvcGVydHkoaSkgKSB7XG4gICAgICAgICAgICAgICAgZml4W2ldID0gbm9kZVtpXTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiBmaXg7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogQG1lbWJlcm9mIENvbnRhaW5lciNcbiAgICAgKiBAbWVtYmVyIHtOb2RlW119IG5vZGVzIC0gYW4gYXJyYXkgY29udGFpbmluZyB0aGUgY29udGFpbmVy4oCZcyBjaGlsZHJlblxuICAgICAqXG4gICAgICogQGV4YW1wbGVcbiAgICAgKiBjb25zdCByb290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