a zip code crypto-currency system good for red ONLY

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. 'use strict';
  2. exports.__esModule = true;
  3. 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; }; }();
  4. var _declaration = require('./declaration');
  5. var _declaration2 = _interopRequireDefault(_declaration);
  6. var _comment = require('./comment');
  7. var _comment2 = _interopRequireDefault(_comment);
  8. var _node = require('./node');
  9. var _node2 = _interopRequireDefault(_node);
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12. 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; }
  13. 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; }
  14. function cleanSource(nodes) {
  15. return nodes.map(function (i) {
  16. if (i.nodes) i.nodes = cleanSource(i.nodes);
  17. delete i.source;
  18. return i;
  19. });
  20. }
  21. /**
  22. * The {@link Root}, {@link AtRule}, and {@link Rule} container nodes
  23. * inherit some common methods to help work with their children.
  24. *
  25. * Note that all containers can store any content. If you write a rule inside
  26. * a rule, PostCSS will parse it.
  27. *
  28. * @extends Node
  29. * @abstract
  30. */
  31. var Container = function (_Node) {
  32. _inherits(Container, _Node);
  33. function Container() {
  34. _classCallCheck(this, Container);
  35. return _possibleConstructorReturn(this, _Node.apply(this, arguments));
  36. }
  37. Container.prototype.push = function push(child) {
  38. child.parent = this;
  39. this.nodes.push(child);
  40. return this;
  41. };
  42. /**
  43. * Iterates through the container’s immediate children,
  44. * calling `callback` for each child.
  45. *
  46. * Returning `false` in the callback will break iteration.
  47. *
  48. * This method only iterates through the container’s immediate children.
  49. * If you need to recursively iterate through all the container’s descendant
  50. * nodes, use {@link Container#walk}.
  51. *
  52. * Unlike the for `{}`-cycle or `Array#forEach` this iterator is safe
  53. * if you are mutating the array of child nodes during iteration.
  54. * PostCSS will adjust the current index to match the mutations.
  55. *
  56. * @param {childIterator} callback - iterator receives each node and index
  57. *
  58. * @return {false|undefined} returns `false` if iteration was broke
  59. *
  60. * @example
  61. * const root = postcss.parse('a { color: black; z-index: 1 }');
  62. * const rule = root.first;
  63. *
  64. * for ( let decl of rule.nodes ) {
  65. * decl.cloneBefore({ prop: '-webkit-' + decl.prop });
  66. * // Cycle will be infinite, because cloneBefore moves the current node
  67. * // to the next index
  68. * }
  69. *
  70. * rule.each(decl => {
  71. * decl.cloneBefore({ prop: '-webkit-' + decl.prop });
  72. * // Will be executed only for color and z-index
  73. * });
  74. */
  75. Container.prototype.each = function each(callback) {
  76. if (!this.lastEach) this.lastEach = 0;
  77. if (!this.indexes) this.indexes = {};
  78. this.lastEach += 1;
  79. var id = this.lastEach;
  80. this.indexes[id] = 0;
  81. if (!this.nodes) return undefined;
  82. var index = void 0,
  83. result = void 0;
  84. while (this.indexes[id] < this.nodes.length) {
  85. index = this.indexes[id];
  86. result = callback(this.nodes[index], index);
  87. if (result === false) break;
  88. this.indexes[id] += 1;
  89. }
  90. delete this.indexes[id];
  91. return result;
  92. };
  93. /**
  94. * Traverses the container’s descendant nodes, calling callback
  95. * for each node.
  96. *
  97. * Like container.each(), this method is safe to use
  98. * if you are mutating arrays during iteration.
  99. *
  100. * If you only need to iterate through the container’s immediate children,
  101. * use {@link Container#each}.
  102. *
  103. * @param {childIterator} callback - iterator receives each node and index
  104. *
  105. * @return {false|undefined} returns `false` if iteration was broke
  106. *
  107. * @example
  108. * root.walk(node => {
  109. * // Traverses all descendant nodes.
  110. * });
  111. */
  112. Container.prototype.walk = function walk(callback) {
  113. return this.each(function (child, i) {
  114. var result = callback(child, i);
  115. if (result !== false && child.walk) {
  116. result = child.walk(callback);
  117. }
  118. return result;
  119. });
  120. };
  121. /**
  122. * Traverses the container’s descendant nodes, calling callback
  123. * for each declaration node.
  124. *
  125. * If you pass a filter, iteration will only happen over declarations
  126. * with matching properties.
  127. *
  128. * Like {@link Container#each}, this method is safe
  129. * to use if you are mutating arrays during iteration.
  130. *
  131. * @param {string|RegExp} [prop] - string or regular expression
  132. * to filter declarations by property name
  133. * @param {childIterator} callback - iterator receives each node and index
  134. *
  135. * @return {false|undefined} returns `false` if iteration was broke
  136. *
  137. * @example
  138. * root.walkDecls(decl => {
  139. * checkPropertySupport(decl.prop);
  140. * });
  141. *
  142. * root.walkDecls('border-radius', decl => {
  143. * decl.remove();
  144. * });
  145. *
  146. * root.walkDecls(/^background/, decl => {
  147. * decl.value = takeFirstColorFromGradient(decl.value);
  148. * });
  149. */
  150. Container.prototype.walkDecls = function walkDecls(prop, callback) {
  151. if (!callback) {
  152. callback = prop;
  153. return this.walk(function (child, i) {
  154. if (child.type === 'decl') {
  155. return callback(child, i);
  156. }
  157. });
  158. } else if (prop instanceof RegExp) {
  159. return this.walk(function (child, i) {
  160. if (child.type === 'decl' && prop.test(child.prop)) {
  161. return callback(child, i);
  162. }
  163. });
  164. } else {
  165. return this.walk(function (child, i) {
  166. if (child.type === 'decl' && child.prop === prop) {
  167. return callback(child, i);
  168. }
  169. });
  170. }
  171. };
  172. /**
  173. * Traverses the container’s descendant nodes, calling callback
  174. * for each rule node.
  175. *
  176. * If you pass a filter, iteration will only happen over rules
  177. * with matching selectors.
  178. *
  179. * Like {@link Container#each}, this method is safe
  180. * to use if you are mutating arrays during iteration.
  181. *
  182. * @param {string|RegExp} [selector] - string or regular expression
  183. * to filter rules by selector
  184. * @param {childIterator} callback - iterator receives each node and index
  185. *
  186. * @return {false|undefined} returns `false` if iteration was broke
  187. *
  188. * @example
  189. * const selectors = [];
  190. * root.walkRules(rule => {
  191. * selectors.push(rule.selector);
  192. * });
  193. * console.log(`Your CSS uses ${selectors.length} selectors`);
  194. */
  195. Container.prototype.walkRules = function walkRules(selector, callback) {
  196. if (!callback) {
  197. callback = selector;
  198. return this.walk(function (child, i) {
  199. if (child.type === 'rule') {
  200. return callback(child, i);
  201. }
  202. });
  203. } else if (selector instanceof RegExp) {
  204. return this.walk(function (child, i) {
  205. if (child.type === 'rule' && selector.test(child.selector)) {
  206. return callback(child, i);
  207. }
  208. });
  209. } else {
  210. return this.walk(function (child, i) {
  211. if (child.type === 'rule' && child.selector === selector) {
  212. return callback(child, i);
  213. }
  214. });
  215. }
  216. };
  217. /**
  218. * Traverses the container’s descendant nodes, calling callback
  219. * for each at-rule node.
  220. *
  221. * If you pass a filter, iteration will only happen over at-rules
  222. * that have matching names.
  223. *
  224. * Like {@link Container#each}, this method is safe
  225. * to use if you are mutating arrays during iteration.
  226. *
  227. * @param {string|RegExp} [name] - string or regular expression
  228. * to filter at-rules by name
  229. * @param {childIterator} callback - iterator receives each node and index
  230. *
  231. * @return {false|undefined} returns `false` if iteration was broke
  232. *
  233. * @example
  234. * root.walkAtRules(rule => {
  235. * if ( isOld(rule.name) ) rule.remove();
  236. * });
  237. *
  238. * let first = false;
  239. * root.walkAtRules('charset', rule => {
  240. * if ( !first ) {
  241. * first = true;
  242. * } else {
  243. * rule.remove();
  244. * }
  245. * });
  246. */
  247. Container.prototype.walkAtRules = function walkAtRules(name, callback) {
  248. if (!callback) {
  249. callback = name;
  250. return this.walk(function (child, i) {
  251. if (child.type === 'atrule') {
  252. return callback(child, i);
  253. }
  254. });
  255. } else if (name instanceof RegExp) {
  256. return this.walk(function (child, i) {
  257. if (child.type === 'atrule' && name.test(child.name)) {
  258. return callback(child, i);
  259. }
  260. });
  261. } else {
  262. return this.walk(function (child, i) {
  263. if (child.type === 'atrule' && child.name === name) {
  264. return callback(child, i);
  265. }
  266. });
  267. }
  268. };
  269. /**
  270. * Traverses the container’s descendant nodes, calling callback
  271. * for each comment node.
  272. *
  273. * Like {@link Container#each}, this method is safe
  274. * to use if you are mutating arrays during iteration.
  275. *
  276. * @param {childIterator} callback - iterator receives each node and index
  277. *
  278. * @return {false|undefined} returns `false` if iteration was broke
  279. *
  280. * @example
  281. * root.walkComments(comment => {
  282. * comment.remove();
  283. * });
  284. */
  285. Container.prototype.walkComments = function walkComments(callback) {
  286. return this.walk(function (child, i) {
  287. if (child.type === 'comment') {
  288. return callback(child, i);
  289. }
  290. });
  291. };
  292. /**
  293. * Inserts new nodes to the end of the container.
  294. *
  295. * @param {...(Node|object|string|Node[])} children - new nodes
  296. *
  297. * @return {Node} this node for methods chain
  298. *
  299. * @example
  300. * const decl1 = postcss.decl({ prop: 'color', value: 'black' });
  301. * const decl2 = postcss.decl({ prop: 'background-color', value: 'white' });
  302. * rule.append(decl1, decl2);
  303. *
  304. * root.append({ name: 'charset', params: '"UTF-8"' }); // at-rule
  305. * root.append({ selector: 'a' }); // rule
  306. * rule.append({ prop: 'color', value: 'black' }); // declaration
  307. * rule.append({ text: 'Comment' }) // comment
  308. *
  309. * root.append('a {}');
  310. * root.first.append('color: black; z-index: 1');
  311. */
  312. Container.prototype.append = function append() {
  313. for (var _len = arguments.length, children = Array(_len), _key = 0; _key < _len; _key++) {
  314. children[_key] = arguments[_key];
  315. }
  316. for (var _iterator = children, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  317. var _ref;
  318. if (_isArray) {
  319. if (_i >= _iterator.length) break;
  320. _ref = _iterator[_i++];
  321. } else {
  322. _i = _iterator.next();
  323. if (_i.done) break;
  324. _ref = _i.value;
  325. }
  326. var child = _ref;
  327. var nodes = this.normalize(child, this.last);
  328. for (var _iterator2 = nodes, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
  329. var _ref2;
  330. if (_isArray2) {
  331. if (_i2 >= _iterator2.length) break;
  332. _ref2 = _iterator2[_i2++];
  333. } else {
  334. _i2 = _iterator2.next();
  335. if (_i2.done) break;
  336. _ref2 = _i2.value;
  337. }
  338. var node = _ref2;
  339. this.nodes.push(node);
  340. }
  341. }
  342. return this;
  343. };
  344. /**
  345. * Inserts new nodes to the start of the container.
  346. *
  347. * @param {...(Node|object|string|Node[])} children - new nodes
  348. *
  349. * @return {Node} this node for methods chain
  350. *
  351. * @example
  352. * const decl1 = postcss.decl({ prop: 'color', value: 'black' });
  353. * const decl2 = postcss.decl({ prop: 'background-color', value: 'white' });
  354. * rule.prepend(decl1, decl2);
  355. *
  356. * root.append({ name: 'charset', params: '"UTF-8"' }); // at-rule
  357. * root.append({ selector: 'a' }); // rule
  358. * rule.append({ prop: 'color', value: 'black' }); // declaration
  359. * rule.append({ text: 'Comment' }) // comment
  360. *
  361. * root.append('a {}');
  362. * root.first.append('color: black; z-index: 1');
  363. */
  364. Container.prototype.prepend = function prepend() {
  365. for (var _len2 = arguments.length, children = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  366. children[_key2] = arguments[_key2];
  367. }
  368. children = children.reverse();
  369. for (var _iterator3 = children, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
  370. var _ref3;
  371. if (_isArray3) {
  372. if (_i3 >= _iterator3.length) break;
  373. _ref3 = _iterator3[_i3++];
  374. } else {
  375. _i3 = _iterator3.next();
  376. if (_i3.done) break;
  377. _ref3 = _i3.value;
  378. }
  379. var child = _ref3;
  380. var nodes = this.normalize(child, this.first, 'prepend').reverse();
  381. for (var _iterator4 = nodes, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
  382. var _ref4;
  383. if (_isArray4) {
  384. if (_i4 >= _iterator4.length) break;
  385. _ref4 = _iterator4[_i4++];
  386. } else {
  387. _i4 = _iterator4.next();
  388. if (_i4.done) break;
  389. _ref4 = _i4.value;
  390. }
  391. var node = _ref4;
  392. this.nodes.unshift(node);
  393. }for (var id in this.indexes) {
  394. this.indexes[id] = this.indexes[id] + nodes.length;
  395. }
  396. }
  397. return this;
  398. };
  399. Container.prototype.cleanRaws = function cleanRaws(keepBetween) {
  400. _Node.prototype.cleanRaws.call(this, keepBetween);
  401. if (this.nodes) {
  402. for (var _iterator5 = this.nodes, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
  403. var _ref5;
  404. if (_isArray5) {
  405. if (_i5 >= _iterator5.length) break;
  406. _ref5 = _iterator5[_i5++];
  407. } else {
  408. _i5 = _iterator5.next();
  409. if (_i5.done) break;
  410. _ref5 = _i5.value;
  411. }
  412. var node = _ref5;
  413. node.cleanRaws(keepBetween);
  414. }
  415. }
  416. };
  417. /**
  418. * Insert new node before old node within the container.
  419. *
  420. * @param {Node|number} exist - child or child’s index.
  421. * @param {Node|object|string|Node[]} add - new node
  422. *
  423. * @return {Node} this node for methods chain
  424. *
  425. * @example
  426. * rule.insertBefore(decl, decl.clone({ prop: '-webkit-' + decl.prop }));
  427. */
  428. Container.prototype.insertBefore = function insertBefore(exist, add) {
  429. exist = this.index(exist);
  430. var type = exist === 0 ? 'prepend' : false;
  431. var nodes = this.normalize(add, this.nodes[exist], type).reverse();
  432. for (var _iterator6 = nodes, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
  433. var _ref6;
  434. if (_isArray6) {
  435. if (_i6 >= _iterator6.length) break;
  436. _ref6 = _iterator6[_i6++];
  437. } else {
  438. _i6 = _iterator6.next();
  439. if (_i6.done) break;
  440. _ref6 = _i6.value;
  441. }
  442. var node = _ref6;
  443. this.nodes.splice(exist, 0, node);
  444. }var index = void 0;
  445. for (var id in this.indexes) {
  446. index = this.indexes[id];
  447. if (exist <= index) {
  448. this.indexes[id] = index + nodes.length;
  449. }
  450. }
  451. return this;
  452. };
  453. /**
  454. * Insert new node after old node within the container.
  455. *
  456. * @param {Node|number} exist - child or child’s index
  457. * @param {Node|object|string|Node[]} add - new node
  458. *
  459. * @return {Node} this node for methods chain
  460. */
  461. Container.prototype.insertAfter = function insertAfter(exist, add) {
  462. exist = this.index(exist);
  463. var nodes = this.normalize(add, this.nodes[exist]).reverse();
  464. for (var _iterator7 = nodes, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
  465. var _ref7;
  466. if (_isArray7) {
  467. if (_i7 >= _iterator7.length) break;
  468. _ref7 = _iterator7[_i7++];
  469. } else {
  470. _i7 = _iterator7.next();
  471. if (_i7.done) break;
  472. _ref7 = _i7.value;
  473. }
  474. var node = _ref7;
  475. this.nodes.splice(exist + 1, 0, node);
  476. }var index = void 0;
  477. for (var id in this.indexes) {
  478. index = this.indexes[id];
  479. if (exist < index) {
  480. this.indexes[id] = index + nodes.length;
  481. }
  482. }
  483. return this;
  484. };
  485. /**
  486. * Removes node from the container and cleans the parent properties
  487. * from the node and its children.
  488. *
  489. * @param {Node|number} child - child or child’s index
  490. *
  491. * @return {Node} this node for methods chain
  492. *
  493. * @example
  494. * rule.nodes.length //=> 5
  495. * rule.removeChild(decl);
  496. * rule.nodes.length //=> 4
  497. * decl.parent //=> undefined
  498. */
  499. Container.prototype.removeChild = function removeChild(child) {
  500. child = this.index(child);
  501. this.nodes[child].parent = undefined;
  502. this.nodes.splice(child, 1);
  503. var index = void 0;
  504. for (var id in this.indexes) {
  505. index = this.indexes[id];
  506. if (index >= child) {
  507. this.indexes[id] = index - 1;
  508. }
  509. }
  510. return this;
  511. };
  512. /**
  513. * Removes all children from the container
  514. * and cleans their parent properties.
  515. *
  516. * @return {Node} this node for methods chain
  517. *
  518. * @example
  519. * rule.removeAll();
  520. * rule.nodes.length //=> 0
  521. */
  522. Container.prototype.removeAll = function removeAll() {
  523. for (var _iterator8 = this.nodes, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
  524. var _ref8;
  525. if (_isArray8) {
  526. if (_i8 >= _iterator8.length) break;
  527. _ref8 = _iterator8[_i8++];
  528. } else {
  529. _i8 = _iterator8.next();
  530. if (_i8.done) break;
  531. _ref8 = _i8.value;
  532. }
  533. var node = _ref8;
  534. node.parent = undefined;
  535. }this.nodes = [];
  536. return this;
  537. };
  538. /**
  539. * Passes all declaration values within the container that match pattern
  540. * through callback, replacing those values with the returned result
  541. * of callback.
  542. *
  543. * This method is useful if you are using a custom unit or function
  544. * and need to iterate through all values.
  545. *
  546. * @param {string|RegExp} pattern - replace pattern
  547. * @param {object} opts - options to speed up the search
  548. * @param {string|string[]} opts.props - an array of property names
  549. * @param {string} opts.fast - string that’s used
  550. * to narrow down values and speed up
  551. the regexp search
  552. * @param {function|string} callback - string to replace pattern
  553. * or callback that returns a new
  554. * value.
  555. * The callback will receive
  556. * the same arguments as those
  557. * passed to a function parameter
  558. * of `String#replace`.
  559. *
  560. * @return {Node} this node for methods chain
  561. *
  562. * @example
  563. * root.replaceValues(/\d+rem/, { fast: 'rem' }, string => {
  564. * return 15 * parseInt(string) + 'px';
  565. * });
  566. */
  567. Container.prototype.replaceValues = function replaceValues(pattern, opts, callback) {
  568. if (!callback) {
  569. callback = opts;
  570. opts = {};
  571. }
  572. this.walkDecls(function (decl) {
  573. if (opts.props && opts.props.indexOf(decl.prop) === -1) return;
  574. if (opts.fast && decl.value.indexOf(opts.fast) === -1) return;
  575. decl.value = decl.value.replace(pattern, callback);
  576. });
  577. return this;
  578. };
  579. /**
  580. * Returns `true` if callback returns `true`
  581. * for all of the container’s children.
  582. *
  583. * @param {childCondition} condition - iterator returns true or false.
  584. *
  585. * @return {boolean} is every child pass condition
  586. *
  587. * @example
  588. * const noPrefixes = rule.every(i => i.prop[0] !== '-');
  589. */
  590. Container.prototype.every = function every(condition) {
  591. return this.nodes.every(condition);
  592. };
  593. /**
  594. * Returns `true` if callback returns `true` for (at least) one
  595. * of the container’s children.
  596. *
  597. * @param {childCondition} condition - iterator returns true or false.
  598. *
  599. * @return {boolean} is some child pass condition
  600. *
  601. * @example
  602. * const hasPrefix = rule.some(i => i.prop[0] === '-');
  603. */
  604. Container.prototype.some = function some(condition) {
  605. return this.nodes.some(condition);
  606. };
  607. /**
  608. * Returns a `child`’s index within the {@link Container#nodes} array.
  609. *
  610. * @param {Node} child - child of the current container.
  611. *
  612. * @return {number} child index
  613. *
  614. * @example
  615. * rule.index( rule.nodes[2] ) //=> 2
  616. */
  617. Container.prototype.index = function index(child) {
  618. if (typeof child === 'number') {
  619. return child;
  620. } else {
  621. return this.nodes.indexOf(child);
  622. }
  623. };
  624. /**
  625. * The container’s first child.
  626. *
  627. * @type {Node}
  628. *
  629. * @example
  630. * rule.first == rules.nodes[0];
  631. */
  632. Container.prototype.normalize = function normalize(nodes, sample) {
  633. var _this2 = this;
  634. if (typeof nodes === 'string') {
  635. var parse = require('./parse');
  636. nodes = cleanSource(parse(nodes).nodes);
  637. } else if (Array.isArray(nodes)) {
  638. nodes = nodes.slice(0);
  639. for (var _iterator9 = nodes, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) {
  640. var _ref9;
  641. if (_isArray9) {
  642. if (_i9 >= _iterator9.length) break;
  643. _ref9 = _iterator9[_i9++];
  644. } else {
  645. _i9 = _iterator9.next();
  646. if (_i9.done) break;
  647. _ref9 = _i9.value;
  648. }
  649. var i = _ref9;
  650. if (i.parent) i.parent.removeChild(i, 'ignore');
  651. }
  652. } else if (nodes.type === 'root') {
  653. nodes = nodes.nodes.slice(0);
  654. for (var _iterator10 = nodes, _isArray10 = Array.isArray(_iterator10), _i11 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) {
  655. var _ref10;
  656. if (_isArray10) {
  657. if (_i11 >= _iterator10.length) break;
  658. _ref10 = _iterator10[_i11++];
  659. } else {
  660. _i11 = _iterator10.next();
  661. if (_i11.done) break;
  662. _ref10 = _i11.value;
  663. }
  664. var _i10 = _ref10;
  665. if (_i10.parent) _i10.parent.removeChild(_i10, 'ignore');
  666. }
  667. } else if (nodes.type) {
  668. nodes = [nodes];
  669. } else if (nodes.prop) {
  670. if (typeof nodes.value === 'undefined') {
  671. throw new Error('Value field is missed in node creation');
  672. } else if (typeof nodes.value !== 'string') {
  673. nodes.value = String(nodes.value);
  674. }
  675. nodes = [new _declaration2.default(nodes)];
  676. } else if (nodes.selector) {
  677. var Rule = require('./rule');
  678. nodes = [new Rule(nodes)];
  679. } else if (nodes.name) {
  680. var AtRule = require('./at-rule');
  681. nodes = [new AtRule(nodes)];
  682. } else if (nodes.text) {
  683. nodes = [new _comment2.default(nodes)];
  684. } else {
  685. throw new Error('Unknown node type in node creation');
  686. }
  687. var processed = nodes.map(function (i) {
  688. if (typeof i.before !== 'function') i = _this2.rebuild(i);
  689. if (i.parent) i.parent.removeChild(i);
  690. if (typeof i.raws.before === 'undefined') {
  691. if (sample && typeof sample.raws.before !== 'undefined') {
  692. i.raws.before = sample.raws.before.replace(/[^\s]/g, '');
  693. }
  694. }
  695. i.parent = _this2;
  696. return i;
  697. });
  698. return processed;
  699. };
  700. Container.prototype.rebuild = function rebuild(node, parent) {
  701. var _this3 = this;
  702. var fix = void 0;
  703. if (node.type === 'root') {
  704. var Root = require('./root');
  705. fix = new Root();
  706. } else if (node.type === 'atrule') {
  707. var AtRule = require('./at-rule');
  708. fix = new AtRule();
  709. } else if (node.type === 'rule') {
  710. var Rule = require('./rule');
  711. fix = new Rule();
  712. } else if (node.type === 'decl') {
  713. fix = new _declaration2.default();
  714. } else if (node.type === 'comment') {
  715. fix = new _comment2.default();
  716. }
  717. for (var i in node) {
  718. if (i === 'nodes') {
  719. fix.nodes = node.nodes.map(function (j) {
  720. return _this3.rebuild(j, fix);
  721. });
  722. } else if (i === 'parent' && parent) {
  723. fix.parent = parent;
  724. } else if (node.hasOwnProperty(i)) {
  725. fix[i] = node[i];
  726. }
  727. }
  728. return fix;
  729. };
  730. /**
  731. * @memberof Container#
  732. * @member {Node[]} nodes - an array containing the container’s children
  733. *
  734. * @example
  735. * const root = postcss.parse('a { color: black }');
  736. * root.nodes.length //=> 1
  737. * root.nodes[0].selector //=> 'a'
  738. * root.nodes[0].nodes[0].prop //=> 'color'
  739. */
  740. _createClass(Container, [{
  741. key: 'first',
  742. get: function get() {
  743. if (!this.nodes) return undefined;
  744. return this.nodes[0];
  745. }
  746. /**
  747. * The container’s last child.
  748. *
  749. * @type {Node}
  750. *
  751. * @example
  752. * rule.last == rule.nodes[rule.nodes.length - 1];
  753. */
  754. }, {
  755. key: 'last',
  756. get: function get() {
  757. if (!this.nodes) return undefined;
  758. return this.nodes[this.nodes.length - 1];
  759. }
  760. }]);
  761. return Container;
  762. }(_node2.default);
  763. exports.default = Container;
  764. /**
  765. * @callback childCondition
  766. * @param {Node} node - container child
  767. * @param {number} index - child index
  768. * @param {Node[]} nodes - all container children
  769. * @return {boolean}
  770. */
  771. /**
  772. * @callback childIterator
  773. * @param {Node} node - container child
  774. * @param {number} index - child index
  775. * @return {false|undefined} returning `false` will break iteration
  776. */
  777. module.exports = exports['default'];
  778. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbnRhaW5lci5lczYiXSwibmFtZXMiOlsiY2xlYW5Tb3VyY2UiLCJub2RlcyIsIm1hcCIsImkiLCJzb3VyY2UiLCJDb250YWluZXIiLCJwdXNoIiwiY2hpbGQiLCJwYXJlbnQiLCJlYWNoIiwiY2FsbGJhY2siLCJsYXN0RWFjaCIsImluZGV4ZXMiLCJpZCIsInVuZGVmaW5lZCIsImluZGV4IiwicmVzdWx0IiwibGVuZ3RoIiwid2FsayIsIndhbGtEZWNscyIsInByb3AiLCJ0eXBlIiwiUmVnRXhwIiwidGVzdCIsIndhbGtSdWxlcyIsInNlbGVjdG9yIiwid2Fsa0F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BlcnR5U3VwcG9ydChkZWNsLnByb3ApO1xuICAgICAqIH0pO1xuICAgICAqXG4gICAgICogcm9vdC53YWxrRGVjbHMoJ2JvcmRlci1yYWRpdXMnLCBkZWNsID0+IHtcbiAgICAgKiAgIGRlY2wucmVtb3ZlKCk7XG4gICAgICogfSk7XG4gICAgICpcbiAgICAgKiByb290LndhbGtEZWNscygvXmJhY2tncm91bmQvLCBkZWNsID0+IHtcbiAgICAgKiAgIGRlY2wudmFsdWUgPSB0YWtlRmlyc3RDb2xvckZyb21HcmFkaWVudChkZWNsLnZhbHVlKTtcbiAgICAgKiB9KTtcbiAgICAgKi9cbiAgICB3YWxrRGVjbHMocHJvcCwgY2FsbGJhY2spIHtcbiAgICAgICAgaWYgKCAhY2FsbGJhY2sgKSB7XG4gICAgICAgICAgICBjYWxsYmFjayA9IHByb3A7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy53YWxrKCAoY2hpbGQsIGkpID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoIGNoaWxkLnR5cGUgPT09ICdkZWNsJyApIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNhbGxiYWNrKGNoaWxkLCBpKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIGlmICggcHJvcCBpbnN0YW5jZW9mIFJlZ0V4cCApIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLndhbGsoIChjaGlsZCwgaSkgPT4ge1xuICAgICAgICAgICAgICAgIGlmICggY2hpbGQudHlwZSA9PT0gJ2RlY2wnICYmIHByb3AudGVzdChjaGlsZC5wcm9wKSApIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNhbGxiYWNrKGNoaWxkLCBpKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLndhbGsoIChjaGlsZCwgaSkgPT4ge1xu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pcbiAgICAgKiBAZXhhbXBsZVxuICAgICAqIGNvbnN0IHNlbGVjdG9ycyA9IFtdO1xuICAgICAqIHJvb3Qud2Fsa1J1bGVzKHJ1bGUgPT4ge1xuICAgICAqICAgc2VsZWN0b3JzLnB1c2gocnVsZS5zZWxlY3Rvcik7XG4gICAgICogfSk7XG4gICAgICogY29uc29sZS5sb2coYFlvdXIgQ1NTIHVzZXMgJHtzZWxlY3RvcnMubGVuZ3RofSBzZWxlY3RvcnNgKTtcbiAgICAgKi9cbiAgICB3YWxrUnVsZXMoc2VsZWN0b3IsIGNhbGxiYWNrKSB7XG4gICAgICAgIGlmICggIWNhbGxiYWNrICkge1xuICAgICAgICAgICAgY2FsbGJhY2sgPSBzZWxlY3RvcjtcblxuICAgICAgICAgICAgcmV0dXJuIHRoaXMud2FsayggKGNoaWxkLCBpKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKCBjaGlsZC50eXBlID09PSAncnVsZScgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjayhjaGlsZCwgaSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSBpZiAoIHNlbGVjdG9yIGluc3RhbmNlb2YgUmVnRXhwICkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMud2FsayggKGNoaWxkLCBpKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKCBjaGlsZC50eXBlID09PSAncnVsZScgJiYgc2VsZWN0b3IudGVzdChjaGlsZC5zZWxlY3RvcikgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjayhjaGlsZCwgaSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy53YWxrKCAoY2hpbGQsIGkpID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoIGNoaWxkLnR5cGUgPT09ICdyd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AgICAqIHJvb3Qud2Fsa0F0UnVsZXMocnVsZSA9PiB7XG4gICAgICogICBpZiAoIGlzT2xkKHJ1bGUubmFtZSkgKSBydWxlLnJlbW92ZSgpO1xuICAgICAqIH0pO1xuICAgICAqXG4gICAgICogbGV0IGZpcnN0ID0gZmFsc2U7XG4gICAgICogcm9vdC53YWxrQXRSdWxlcygnY2hhcnNldCcsIHJ1bGUgPT4ge1xuICAgICAqICAgaWYgKCAhZmlyc3QgKSB7XG4gICAgICogICAgIGZpcnN0ID0gdHJ1ZTtcbiAgICAgKiAgIH0gZWxzZSB7XG4gICAgICogICAgIHJ1bGUucmVtb3ZlKCk7XG4gICAgICogICB9XG4gICAgICogfSk7XG4gICAgICovXG4gICAgd2Fsa0F0UnVsZXMobmFtZSwgY2FsbGJhY2spIHtcbiAgICAgICAgaWYgKCAhY2FsbGJhY2sgKSB7XG4gICAgICAgICAgICBjYWxsYmFjayA9IG5hbWU7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy53YWxrKCAoY2hpbGQsIGkpID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoIGNoaWxkLnR5cGUgPT09ICdhdHJ1bGUnICkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gY2FsbGJhY2soY2hpbGQsIGkpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2UgaWYgKCBuYW1lIGluc3RhbmNlb2YgUmVnRXhwICkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMud2FsayggKGNoaWxkLCBpKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKCBjaGlsZC50eXBlID09PSAnYXRydWxlJyAmJiBuYW1lLnRlc3QoY2hpbGQubmFtZSkgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjayhjaGlsZCwgaSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAg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OyAgICAgICAgICAgICAgICAgICAgICAgLy8gcnVsZVxuICAgICAqIHJ1bGUuYXBwZW5kKHsgcHJvcDogJ2NvbG9yJywgdmFsdWU6ICdibGFjaycgfSk7ICAgICAgIC8vIGRlY2xhcmF0aW9uXG4gICAgICogcnVsZS5hcHBlbmQoeyB0ZXh0OiAnQ29tbWVudCcgfSkgICAgICAgICAgICAgICAgICAgICAgLy8gY29tbWVudFxuICAgICAqXG4gICAgICogcm9vdC5hcHBlbmQoJ2Ege30nKTtcbiAgICAgKiByb290LmZpcnN0LmFwcGVuZCgnY29sb3I6IGJsYWNrOyB6LWluZGV4OiAxJyk7XG4gICAgICovXG4gICAgcHJlcGVuZCguLi5jaGlsZHJlbikge1xuICAgICAgICBjaGlsZHJlbiA9IGNoaWxkcmVuLnJldmVyc2UoKTtcbiAgICAgICAgZm9yICggbGV0IGNoaWxkIG9mIGNoaWxkcmVuICkge1xuICAgICAgICAgICAgbGV0IG5vZGVzID0gdGhpcy5ub3JtYWxpemUoY2hpbGQsIHRoaXMuZmlyc3QsICdwcmVwZW5kJykucmV2ZXJzZSgpO1xuICAgICAgICAgICAgZm9yICggbGV0IG5vZGUgb2Ygbm9kZXMgKSB0aGlzLm5vZGVzLnVuc2hpZnQobm9kZSk7XG4gICAgICAgICAgICBmb3IgKCBsZXQgaWQgaW4gdGhpcy5pbmRleGVzICkge1xuICAgICAgICAgICAgICAgIHRoaXMuaW5kZXhlc1tpZF0gPSB0aGlzLmluZGV4ZXNbaWRdICsgbm9kZXMubGVuZ3RoO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGNsZWFuUmF3cyhrZWVwQmV0d2Vlbikge1xuICAgICAgICBzdXBlci5jbGVhblJhd3Moa2VlcEJldHdlZW4pO1xuICAgICAgICBpZiAoIHRoaXMubm9kZXMgKSB7XG4gICAgICAgICAgICBmb3IgKCBsZXQgbm9kZSBvZiB0aGlzLm5vZGVz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biAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFJlbW92ZXMgbm9kZSBmcm9tIHRoZSBjb250YWluZXIgYW5kIGNsZWFucyB0aGUgcGFyZW50IHByb3BlcnRpZXNcbiAgICAgKiBmcm9tIHRoZSBub2RlIGFuZCBpdHMgY2hpbGRyZW4uXG4gICAgICpcbiAgICAgKiBAcGFyYW0ge05vZGV8bnVtYmVyfSBjaGlsZCAtIGNoaWxkIG9yIGNoaWxk4oCZcyBpbmRleFxuICAgICAqXG4gICAgICogQHJldHVybiB7Tm9kZX0gdGhpcyBub2RlIGZvciBtZXRob2RzIGNoYWluXG4gICAgICpcbiAgICAgKiBAZXhhbXBsZVxuICAgICAqIHJ1bGUubm9kZXMubGVuZ3RoICAvLz0+IDVcbiAgICAgKiBydWxlLnJlbW92ZUNoaWxkKGRlY2wpO1xuICAgICAqIHJ1bGUubm9kZXMubGVuZ3RoICAvLz0+IDRcbiAgICAgKiBkZWNsLnBhcmVudCAgICAgICAgLy89PiB1bmRlZmluZWRcbiAgICAgKi9cbiAgICByZW1vdmVDaGlsZChjaGlsZCkge1xuICAgICAgICBjaGlsZCA9IHRoaXMuaW5kZXgoY2hpbGQpO1xuICAgICAgICB0aGlzLm5vZGVzW2NoaWxkXS5wYXJlbnQgPSB1bmRlZmluZWQ7XG4gICAgICAgIHRoaXMubm9kZXMuc3BsaWNlKGNoaWxkLCAxKTtcblxuICAgICAgICBsZXQgaW5kZXg7XG4gICAgICAgIGZvciAoIGxldCBpZCBpbiB0aGlzLmluZGV4ZXMgKSB7XG4gICAgICAgICAgICBpbmRleCA9IHRoaXMuaW5kZXhlc1tpZF07XG4gICAgICAgICAgICBpZiAoIGluZGV4ID49IGNoaWxkICkge1xuICAgICAgICAgICAgICAgIHRoaXMuaW5kZXhlc1tpZF0gPSBpbmRleCAtIDE7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1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dHMgICAgICAgICAgICAgICAgLSBvcHRpb25zIHRvIHNwZWVkIHVwIHRoZSBzZWFyY2hcbiAgICAgKiBAcGFyYW0ge3N0cmluZ3xzdHJpbmdbXX0gb3B0cy5wcm9wcyAtIGFuIGFycmF5IG9mIHByb3BlcnR5IG5hbWVzXG4gICAgICogQHBhcmFtIHtzdHJpbmd9IG9wdHMuZmFzdCAgICAgICAgICAgLSBzdHJpbmcgdGhhdOKAmXMgdXNlZFxuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdG8gbmFycm93IGRvd24gdmFsdWVzIGFuZCBzcGVlZCB1cFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhlIHJlZ2V4cCBzZWFyY2hcbiAgICAgKiBAcGFyYW0ge2Z1bmN0aW9ufHN0cmluZ30gY2FsbGJhY2sgICAtIHN0cmluZyB0byByZXBsYWNlIHBhdHRlcm5cbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9yIGNhbGxiYWNrIHRoYXQgcmV0dXJucyBhIG5ld1xuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdmFsdWUuXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBUaGUgY2FsbGJhY2sgd2lsbCByZWNlaXZlXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGUgc2FtZSBhcmd1bWVudHMgYXMgdGhvc2VcbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBhc3NlZCB0byBhIGZ1bmN0aW9uIHBhcmFtZXRlclxuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2YgYFN0cmluZyNyZXBsYWNlYC5cbiAgICAgKlxuICAgICAqIEByZXR1cm4ge05vZGV9IHRoaXMgbm9kZSBmb3IgbWV0aG9kcy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gICAgICAgaWYgKCB0eXBlb2Ygbm9kZXMgPT09ICdzdHJpbmcnICkge1xuICAgICAgICAgICAgbGV0IHBhcnNlID0gcmVxdWlyZSgnLi9wYXJzZScpO1xuICAgICAgICAgICAgbm9kZXMgPSBjbGVhblNvdXJjZShwYXJzZShub2Rlcykubm9kZXMpO1xuICAgICAgICB9IGVsc2UgaWYgKCBBcnJheS5pc0FycmF5KG5vZGVzKSApIHtcbiAgICAgICAgICAgIG5vZGVzID0gbm9kZXMuc2xpY2UoMCk7XG4gICAgICAgICAgICBmb3IgKCBsZXQgaSBvZiBub2RlcyApIHtcbiAgICAgICAgICAgICAgICBpZiAoIGkucGFyZW50ICkgaS5wYXJlbnQucmVtb3ZlQ2hpbGQoaSwgJ2lnbm9yZScpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKCBub2Rlcy50eXBlID09PSAncm9vdCcgKSB7XG4gICAgICAgICAgICBub2RlcyA9IG5vZGVzLm5vZGVzLnNsaWNlKDApO1xuICAgICAgICAgICAgZm9yICggbGV0IGkgb2Ygbm9kZXMgKSB7XG4gICAgICAgICAgICAgICAgaWYgKCBpLnBhcmVudCApIGkucGFyZW50LnJlbW92ZUNoaWxkKGksICdpZ25vcmUnKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIGlmICggbm9kZXMudHlwZSApIHtcbiAgICAgICAgICAgIG5vZGVzID0gW25vZGVzXTtcbiAgICAgICAgfSBlbHNlIGlmICggbm9kZXMucHJvcCApIHtcbiAgICAgICAgICAgIGlmICggdHlwZW9mIG5vZGVzLnZhbHVlID09PSAndW5kZWZpbmVkJyApIHtcbiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ1ZhbHVlIGZpZWxkIGlzIG1pc3NlZCBpbiBub2RlIGNyZWF0aW9uJyk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKCB0eXBlb2Ygbm9kZXMudmFsdWUgIT09ICdzdHJpbmcnICkge1xuICAgICAgICAgICAgICAgIG5vZGVzLnZhbHVlID0gU3RyaW5nKG5vZGVzLnZhbHVlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIG5vZGVzID0gW25ldyBEZWNsYXJhdGlvbihub2RlcyldO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2Rlcy5zZWxlY3RvciApIHtcbiAgICAgICAgICAgIGxldCBSdWxlID0gcmVxdWlyZSgnLi9ydWxlJyk7XG4gICAgICAgICAgICBub2RlcyA9IFtuZXcgUnVsZShub2RlcyldO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2Rlcy5uYW1lICkge1xuICAgICAgICAgICAgbGV0IEF0UnVsZSA9IHJlcXVpcmUoJy4vYXQtcnVsZScpO1xuICAgICAgICAgICAgbm9kZXMgPSBbbmV3IEF0UnVsZShub2RlcyldO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2Rlcy50ZXh0ICkge1xuICAgICAgICAgICAgbm9kZXMgPSBbbmV3IENvbW1lbnQobm9kZXMpXTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignVW5rbm93biBub2RlIHR5cGUgaW4gbm9kZSBjcmVhdGlvbicpO1xuICAgICAgICB9XG5cbiAgICAgICAgbGV0IHByb2Nlc3NlZCA9IG5vZGVzLm1hcCggaSA9PiB7XG4gICAgICAgICAgICBpZiAoIHR5cGVvZiBpLmJlZm9yZSAhPT0gJ2Z1bmN0aW9uJyApIGkgPSB0aGlzLnJlYnVpbGQoaSk7XG5cbiAgICAgICAgICAgIGlmICggaS5wYXJlbnQgKSBpLnBhcmVudC5yZW1vdmVDaGlsZChpKTtcbiAgICAgICAgICAgIGlmICggdHlwZW9mIGkucmF3cy5iZWZvcmUgPT09ICd1bmRlZmluZWQnICkge1xuICAgICAgICAgICAgICAgIGlmICggc2FtcGxlICYmIHR5cGVvZiBzYW1wbGUucmF3cy5iZWZvcmUgIT09ICd1bmRlZmluZWQnICkge1xuICAgICAgICAgICAgICAgICAgICBpLnJhd3MuYmVmb3JlID0gc2FtcGxlLnJhd3MuYmVmb3JlLnJlcGxhY2UoL1teXFxzXS9nLCAnJyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaS5wYXJlbnQgPSB0aGlzO1xuICAgICAgICAgICAgcmV0dXJuIGk7XG4gICAgICAgIH0pO1xuXG4gICAgICAgIHJldHVybiBwcm9jZXNzZWQ7XG4gICAgfVxuXG4gICAgcmVidWlsZChub2RlLCBwYXJlbnQpIHtcbiAgICAgICAgbGV0IGZpeDtcbiAgICAgICAgaWYgKCBub2RlLnR5cGUgPT09ICdyb290JyApIHtcbiAgICAgICAgICAgIGxldCBSb290ID0gcmVxdWlyZSgnLi9yb290Jyk7XG4gICAgICAgICAgICBmaXggPSBuZXcgUm9vdCgpO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2RlLnR5cGUgPT09ICdhdHJ1bGUnICkge1xuICAgICAgICAgICAgbGV0IEF0UnVsZSA9IHJlcXVpcmUoJy4vYXQtcnVsZScpO1xuICAgICAgICAgICAgZml4ID0gbmV3IEF0UnVsZSgpO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2RlLnR5cGUgPT09ICdydWxlJyApIHtcbiAgICAgICAgICAgIGxldCBSdWxlID0gcmVxdWlyZSgnLi9ydWxlJyk7XG4gICAgICAgICAgICBmaXggPSBuZXcgUnVsZSgpO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2RlLnR5cGUgPT09ICdkZWNsJyApIHtcbiAgICAgICAgICAgIGZpeCA9IG5ldyBEZWNsYXJhdGlvbigpO1xuICAgICAgICB9IGVsc2UgaWYgKCBub2RlLnR5cGUgPT09ICdjb21tZW50JyApIHtcbiAgICAgICAgICAgIGZpeCA9IG5ldyBDb21tZW50KCk7XG4gICAgICAgIH1cblxuICAgICAgICBmb3IgKCBsZXQgaSBpbiBub2RlICkge1xuICAgICAgICAgICAgaWYgKCBpID09PSAnbm9kZXMnICkge1xuICAgICAgICAgICAgICAgIGZpeC5ub2RlcyA9IG5vZGUubm9kZXMubWFwKCBqID0+IHRoaXMucmVidWlsZChqLCBmaXgpICk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKCBpID09PSAncGFyZW50JyAmJiBwYXJlbnQgKSB7XG4gICAgICAgICAgICAgICAgZml4LnBhcmVudCA9IHBhcmVudDtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIG5vZGUuaGFzT3duUHJvcGVydHkoaSkgKSB7XG4gICAgICAgICAgICAgICAgZml4W2ldID0gbm9kZVtpXTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiBmaXg7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogQG1lbWJlcm9mIENvbnRhaW5lciNcbiAgICAgKiBAbWVtYmVyIHtOb2RlW119IG5vZGVzIC0gYW4gYXJyYXkgY29udGFpbmluZyB0aGUgY29udGFpbmVy4oCZcyBjaGlsZHJlblxuICAgICAqXG4gICAgICogQGV4YW1wbGVcbiAgICAgKiBjb25zdCByb290ID0gcG9zdGNzcy5wYXJzZSgnYSB7IGNvbG9yOiBibGFjayB9Jyk7XG4gICAgICogcm9vdC5ub2Rlcy5sZW5ndGggICAgICAgICAgIC8vPT4gMVxuICAgICAqIHJvb3Qubm9kZXNbMF0uc2VsZWN0b3IgICAgICAvLz0+ICdhJ1xuICAgICAqIHJvb3Qubm9kZXNbMF0ubm9kZXNbMF0ucHJvcCAvLz0+ICdjb2xvcidcbiAgICAgKi9cblxufVxuXG5leHBvcnQgZGVmYXVsdCBDb250YWluZXI7XG5cblxuLyoqXG4gKiBAY2FsbGJhY2sgY2hpbGRDb25kaXRpb25cbiAqIEBwYXJhbSB7Tm9kZX0gbm9kZSAgICAtIGNvbnRhaW5lciBjaGlsZFxuICogQHBhcmFtIHtudW1iZXJ9IGluZGV4IC0gY2hpbGQgaW5kZXhcbiAqIEBwYXJhbSB7Tm9kZVtdfSBub2RlcyA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