stringifier.js 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. 'use strict';
  2. exports.__esModule = true;
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. var defaultRaw = {
  5. colon: ': ',
  6. indent: ' ',
  7. beforeDecl: '\n',
  8. beforeRule: '\n',
  9. beforeOpen: ' ',
  10. beforeClose: '\n',
  11. beforeComment: '\n',
  12. after: '\n',
  13. emptyBody: '',
  14. commentLeft: ' ',
  15. commentRight: ' '
  16. };
  17. function capitalize(str) {
  18. return str[0].toUpperCase() + str.slice(1);
  19. }
  20. var Stringifier = function () {
  21. function Stringifier(builder) {
  22. _classCallCheck(this, Stringifier);
  23. this.builder = builder;
  24. }
  25. Stringifier.prototype.stringify = function stringify(node, semicolon) {
  26. this[node.type](node, semicolon);
  27. };
  28. Stringifier.prototype.root = function root(node) {
  29. this.body(node);
  30. if (node.raws.after) this.builder(node.raws.after);
  31. };
  32. Stringifier.prototype.comment = function comment(node) {
  33. var left = this.raw(node, 'left', 'commentLeft');
  34. var right = this.raw(node, 'right', 'commentRight');
  35. this.builder('/*' + left + node.text + right + '*/', node);
  36. };
  37. Stringifier.prototype.decl = function decl(node, semicolon) {
  38. var between = this.raw(node, 'between', 'colon');
  39. var string = node.prop + between + this.rawValue(node, 'value');
  40. if (node.important) {
  41. string += node.raws.important || ' !important';
  42. }
  43. if (semicolon) string += ';';
  44. this.builder(string, node);
  45. };
  46. Stringifier.prototype.rule = function rule(node) {
  47. this.block(node, this.rawValue(node, 'selector'));
  48. if (node.raws.ownSemicolon) {
  49. this.builder(node.raws.ownSemicolon, node, 'end');
  50. }
  51. };
  52. Stringifier.prototype.atrule = function atrule(node, semicolon) {
  53. var name = '@' + node.name;
  54. var params = node.params ? this.rawValue(node, 'params') : '';
  55. if (typeof node.raws.afterName !== 'undefined') {
  56. name += node.raws.afterName;
  57. } else if (params) {
  58. name += ' ';
  59. }
  60. if (node.nodes) {
  61. this.block(node, name + params);
  62. } else {
  63. var end = (node.raws.between || '') + (semicolon ? ';' : '');
  64. this.builder(name + params + end, node);
  65. }
  66. };
  67. Stringifier.prototype.body = function body(node) {
  68. var last = node.nodes.length - 1;
  69. while (last > 0) {
  70. if (node.nodes[last].type !== 'comment') break;
  71. last -= 1;
  72. }
  73. var semicolon = this.raw(node, 'semicolon');
  74. for (var i = 0; i < node.nodes.length; i++) {
  75. var child = node.nodes[i];
  76. var before = this.raw(child, 'before');
  77. if (before) this.builder(before);
  78. this.stringify(child, last !== i || semicolon);
  79. }
  80. };
  81. Stringifier.prototype.block = function block(node, start) {
  82. var between = this.raw(node, 'between', 'beforeOpen');
  83. this.builder(start + between + '{', node, 'start');
  84. var after = void 0;
  85. if (node.nodes && node.nodes.length) {
  86. this.body(node);
  87. after = this.raw(node, 'after');
  88. } else {
  89. after = this.raw(node, 'after', 'emptyBody');
  90. }
  91. if (after) this.builder(after);
  92. this.builder('}', node, 'end');
  93. };
  94. Stringifier.prototype.raw = function raw(node, own, detect) {
  95. var value = void 0;
  96. if (!detect) detect = own;
  97. // Already had
  98. if (own) {
  99. value = node.raws[own];
  100. if (typeof value !== 'undefined') return value;
  101. }
  102. var parent = node.parent;
  103. // Hack for first rule in CSS
  104. if (detect === 'before') {
  105. if (!parent || parent.type === 'root' && parent.first === node) {
  106. return '';
  107. }
  108. }
  109. // Floating child without parent
  110. if (!parent) return defaultRaw[detect];
  111. // Detect style by other nodes
  112. var root = node.root();
  113. if (!root.rawCache) root.rawCache = {};
  114. if (typeof root.rawCache[detect] !== 'undefined') {
  115. return root.rawCache[detect];
  116. }
  117. if (detect === 'before' || detect === 'after') {
  118. return this.beforeAfter(node, detect);
  119. } else {
  120. var method = 'raw' + capitalize(detect);
  121. if (this[method]) {
  122. value = this[method](root, node);
  123. } else {
  124. root.walk(function (i) {
  125. value = i.raws[own];
  126. if (typeof value !== 'undefined') return false;
  127. });
  128. }
  129. }
  130. if (typeof value === 'undefined') value = defaultRaw[detect];
  131. root.rawCache[detect] = value;
  132. return value;
  133. };
  134. Stringifier.prototype.rawSemicolon = function rawSemicolon(root) {
  135. var value = void 0;
  136. root.walk(function (i) {
  137. if (i.nodes && i.nodes.length && i.last.type === 'decl') {
  138. value = i.raws.semicolon;
  139. if (typeof value !== 'undefined') return false;
  140. }
  141. });
  142. return value;
  143. };
  144. Stringifier.prototype.rawEmptyBody = function rawEmptyBody(root) {
  145. var value = void 0;
  146. root.walk(function (i) {
  147. if (i.nodes && i.nodes.length === 0) {
  148. value = i.raws.after;
  149. if (typeof value !== 'undefined') return false;
  150. }
  151. });
  152. return value;
  153. };
  154. Stringifier.prototype.rawIndent = function rawIndent(root) {
  155. if (root.raws.indent) return root.raws.indent;
  156. var value = void 0;
  157. root.walk(function (i) {
  158. var p = i.parent;
  159. if (p && p !== root && p.parent && p.parent === root) {
  160. if (typeof i.raws.before !== 'undefined') {
  161. var parts = i.raws.before.split('\n');
  162. value = parts[parts.length - 1];
  163. value = value.replace(/[^\s]/g, '');
  164. return false;
  165. }
  166. }
  167. });
  168. return value;
  169. };
  170. Stringifier.prototype.rawBeforeComment = function rawBeforeComment(root, node) {
  171. var value = void 0;
  172. root.walkComments(function (i) {
  173. if (typeof i.raws.before !== 'undefined') {
  174. value = i.raws.before;
  175. if (value.indexOf('\n') !== -1) {
  176. value = value.replace(/[^\n]+$/, '');
  177. }
  178. return false;
  179. }
  180. });
  181. if (typeof value === 'undefined') {
  182. value = this.raw(node, null, 'beforeDecl');
  183. } else if (value) {
  184. value = value.replace(/[^\s]/g, '');
  185. }
  186. return value;
  187. };
  188. Stringifier.prototype.rawBeforeDecl = function rawBeforeDecl(root, node) {
  189. var value = void 0;
  190. root.walkDecls(function (i) {
  191. if (typeof i.raws.before !== 'undefined') {
  192. value = i.raws.before;
  193. if (value.indexOf('\n') !== -1) {
  194. value = value.replace(/[^\n]+$/, '');
  195. }
  196. return false;
  197. }
  198. });
  199. if (typeof value === 'undefined') {
  200. value = this.raw(node, null, 'beforeRule');
  201. } else if (value) {
  202. value = value.replace(/[^\s]/g, '');
  203. }
  204. return value;
  205. };
  206. Stringifier.prototype.rawBeforeRule = function rawBeforeRule(root) {
  207. var value = void 0;
  208. root.walk(function (i) {
  209. if (i.nodes && (i.parent !== root || root.first !== i)) {
  210. if (typeof i.raws.before !== 'undefined') {
  211. value = i.raws.before;
  212. if (value.indexOf('\n') !== -1) {
  213. value = value.replace(/[^\n]+$/, '');
  214. }
  215. return false;
  216. }
  217. }
  218. });
  219. if (value) value = value.replace(/[^\s]/g, '');
  220. return value;
  221. };
  222. Stringifier.prototype.rawBeforeClose = function rawBeforeClose(root) {
  223. var value = void 0;
  224. root.walk(function (i) {
  225. if (i.nodes && i.nodes.length > 0) {
  226. if (typeof i.raws.after !== 'undefined') {
  227. value = i.raws.after;
  228. if (value.indexOf('\n') !== -1) {
  229. value = value.replace(/[^\n]+$/, '');
  230. }
  231. return false;
  232. }
  233. }
  234. });
  235. if (value) value = value.replace(/[^\s]/g, '');
  236. return value;
  237. };
  238. Stringifier.prototype.rawBeforeOpen = function rawBeforeOpen(root) {
  239. var value = void 0;
  240. root.walk(function (i) {
  241. if (i.type !== 'decl') {
  242. value = i.raws.between;
  243. if (typeof value !== 'undefined') return false;
  244. }
  245. });
  246. return value;
  247. };
  248. Stringifier.prototype.rawColon = function rawColon(root) {
  249. var value = void 0;
  250. root.walkDecls(function (i) {
  251. if (typeof i.raws.between !== 'undefined') {
  252. value = i.raws.between.replace(/[^\s:]/g, '');
  253. return false;
  254. }
  255. });
  256. return value;
  257. };
  258. Stringifier.prototype.beforeAfter = function beforeAfter(node, detect) {
  259. var value = void 0;
  260. if (node.type === 'decl') {
  261. value = this.raw(node, null, 'beforeDecl');
  262. } else if (node.type === 'comment') {
  263. value = this.raw(node, null, 'beforeComment');
  264. } else if (detect === 'before') {
  265. value = this.raw(node, null, 'beforeRule');
  266. } else {
  267. value = this.raw(node, null, 'beforeClose');
  268. }
  269. var buf = node.parent;
  270. var depth = 0;
  271. while (buf && buf.type !== 'root') {
  272. depth += 1;
  273. buf = buf.parent;
  274. }
  275. if (value.indexOf('\n') !== -1) {
  276. var indent = this.raw(node, null, 'indent');
  277. if (indent.length) {
  278. for (var step = 0; step < depth; step++) {
  279. value += indent;
  280. }
  281. }
  282. }
  283. return value;
  284. };
  285. Stringifier.prototype.rawValue = function rawValue(node, prop) {
  286. var value = node[prop];
  287. var raw = node.raws[prop];
  288. if (raw && raw.value === value) {
  289. return raw.raw;
  290. } else {
  291. return value;
  292. }
  293. };
  294. return Stringifier;
  295. }();
  296. exports.default = Stringifier;
  297. module.exports = exports['default'];
  298. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0cmluZ2lmaWVyLmVzNiJdLCJuYW1lcyI6WyJkZWZhdWx0UmF3IiwiY29sb24iLCJpbmRlbnQiLCJiZWZvcmVEZWNsIiwiYmVmb3JlUnVsZSIsImJlZm9yZU9wZW4iLCJiZWZvcmVDbG9zZSIsImJlZm9yZUNvbW1lbnQiLCJhZnRlciIsImVtcHR5Qm9keSIsImNvbW1lbnRMZWZ0IiwiY29tbWVudFJpZ2h0IiwiY2FwaXRhbGl6ZSIsInN0ciIsInRvVXBwZXJDYXNlIiwic2xpY2UiLCJTdHJpbmdpZmllciIsImJ1aWxkZXIiLCJzdHJpbmdpZnkiLCJub2RlIiwic2VtaWNvbG9uIiwidHlwZSIsInJvb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YgKCBub2RlLnJhd3Mub3duU2VtaWNvbG9uICkge1xuICAgICAgICAgICAgdGhpcy5idWlsZGVyKG5vZGUucmF3cy5vd25TZW1pY29sb24sIG5vZGUsICdlbmQnKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGF0cnVsZShub2RlLCBzZW1pY29sb24pIHtcbiAgICAgICAgbGV0IG5hbWUgICA9ICdAJyArIG5vZGUubmFtZTtcbiAgICAgICAgbGV0IHBhcmFtcyA9IG5vZGUucGFyYW1zID8gdGhpcy5yYXdWYWx1ZShub2RlLCAncGFyYW1zJykgOiAnJztcblxuICAgICAgICBpZiAoIHR5cGVvZiBub2RlLnJhd3MuYWZ0ZXJOYW1lICE9PSAndW5kZWZpbmVkJyApIHtcbiAgICAgICAgICAgIG5hbWUgKz0gbm9kZS5yYXdzLmFmdGVyTmFtZTtcbiAgICAgICAgfSBlbHNlIGlmICggcGFyYW1zICkge1xuICAgICAgICAgICAgbmFtZSArPSAnICc7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoIG5vZGUubm9kZXMgKSB7XG4gICAgICAgICAgICB0aGlzLmJsb2NrKG5vZGUsIG5hbWUgKyBwYXJhbXMpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbGV0IGVuZCA9IChub2RlLnJhd3MuYmV0d2VlbiB8fCAnJykgKyAoc2VtaWNvbG9uID8gJzsnIDogJycpO1xuICAgICAgICAgICAgdGhpcy5idWlsZGVyKG5hbWUgKyBwYXJhbXMgKyBlbmQsIG5vZGUpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgYm9keShub2RlKSB7XG4gICAgICAgIGxldCBsYXN0ID0gbm9kZS5ub2Rlcy5sZW5ndGggLSAxO1xuICAgICAgICB3aGlsZSAoIGxhc3QgPiAwICkge1xuICAgICAgICAgICAgaWYgKCBub2RlLm5vZGVzW2xhc3RdLnR5cGUgIT09ICdjb21tZW50JyApIGJyZWFrO1xuICAgICAgICAgICAgbGFzdCAtPSAxO1xuIC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gICAgICAgaWYgKCBkZXRlY3QgPT09ICdiZWZvcmUnIHx8IGRldGVjdCA9PT0gJ2FmdGVyJyApIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLmJlZm9yZUFmdGVyKG5vZGUsIGRldGVjdCk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBsZXQgbWV0aG9kID0gJ3JhdycgKyBjYXBpdGFsaXplKGRldGVjdCk7XG4gICAgICAgICAgICBpZiAoIHRoaXNbbWV0aG9kXSApIHtcbiAgICAgICAgICAgICAgICB2YWx1ZSA9IHRoaXNbbWV0aG9kXShyb290LCBub2RlKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcm9vdC53YWxrKCBpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgdmFsdWUgPSBpLnJhd3Nbb3duXTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKCB0eXBlb2YgdmFsdWUgIT09ICd1bmRlZmluZWQnICkgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgaWYgKCB0eXBlb2YgdmFsdWUgPT09ICd1bmRlZmluZWQnICkgdmFsdWUgPSBkZWZhdWx0UmF3W2RldGVjdF07XG5cbiAgICAgICAgcm9vdC5yYXdDYWNoZVtkZXRlY3RdID0gdmFsdWU7XG4gICAgICAgIHJldHVybiB2YWx1ZTtcbiAgICB9XG5cbiAgICByYXdTZW1pY29sb24ocm9vdCkge1xuICAgICAgICBsZXQgdmFsdWU7XG4gICAgICAgIHJvb3Qud2FsayggaSA9PiB7XG4gICAgICAgICAgICBpZiAoIGkubm9kZXMgJiYgaS5ub2Rlcy5sZW5ndGggJiYgaS5sYXN0LnR5cGUgPT09ICdkZWNsJyApIHtcbiAgICAgICAgICAgICAgICB2YWx1ZSA9IGkucmF3cy5zZW1pY29sb247XG4gICAgICAgICAgICAgICAgaWYgKCB0eXBlb2YgdmFsdWUgIT09ICd1bmRlZmluZWQnICkgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgICAgcmV0dXJuIHZhbHVlO1xuICAgIH1cblxuICAgIHJhd0VtcHR5Qm9keShyb290KSB7XG4gICAgICAgIGxldCB2YWx1ZTtcbiAgICAgICAgcm9vdC53YWxrKCBpID0+IHtcbiAgICAgICAgICAgIGlmICggaS5ub2RlcyAmJiBpLm5vZGVzLmxlbmd0aCA9PT0gMCApIHtcbiAgICAgICAgICAgICAgICB2YWx1ZSA9IGkucmF3cy5hZnRlcjtcbiAgICAgICAgICAgICAgICBpZiAoIHR5cGVvZiB2YWx1ZSAhPT0gJ3VuZGVmaW5lZCcgKSByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgICByZXR1cm4gdmFsdWU7XG4gICAgfVxuXG4gICAgcmF3SW5kZW50KHJvb3QpIHtcbiAgICAgICAgaWYgKCByb290LnJhd3MuaW5kZW50ICkgcmV0dXJuIHJvb3QucmF3cy5pbmRlbnQ7XG4gICAgICAgIGxldCB2YWx1ZTtcbiAgICAgICAgcm9vdC53YWxrKCBpID0+IHtcbiAgICAgICAgICAgIGxldCBwID0gaS5wYXJlbnQ7XG4gICAgICAgICAgICBpZiAoIHAgJiYgcCAhPT0gcm9vdCAmJiBwLnBhcmVudCAmJiBwLnBhcmVudCA9PT0gcm9vdCApIHtcbiAgICAgICAgICAgICAgICBpZiAoIHR5cGVvZiBpLnJhd3MuYmVmb3JlICE9PSAndW5kZWZpbmVkJyApIHtcbiAgICAgICAgICAgICAgICAgICAgbGV0IHBhcnRzID0gaS5yYXdzLmJlZm9yZS5zcGxpdCgnXFxuJyk7XG4gICAgICAgICAgICAgICAgICAgIHZhbHVlID0gcGFydHNbcGFydHMubGVuZ3RoIC0gMV07XG4gICAgICAgICAgICAgICAgICAgIHZhbHVlID0gdmFsdWUucmVwbGFjZSgvW15cXHNdL2csICcnKTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIHJldHVybiB2YWx1ZTtcbiAgICB9XG5cbiAgICByYXdCZWZvcmVDb21tZW50KHJvb3QsIG5vZGUpIHtcbiAgICAgICAgbGV0IHZhbHVlO1xuICAgICAgICByb290LndhbGtDb21tZW50cyggaSA9PiB7XG4gICAgICAgICAgICBpZiAoIHR5cGVvZiBpLnJhd3MuYmVmb3JlICE9PSAndW5kZWZpbmVkJyApIHtcbiAgICAgICAgICAgICAgICB2YWx1ZSA9IGkucmF3cy5iZWZvcmU7XG4gICAgICAgICAgICAgICAgaWYgKCB2YWx1ZS5pbmRleE9mKCdcXG4nKSAhPT0gLTEgKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhbHVlID0gdmFsdWUucmVwbGFjZSgvW15cXG5dKyQvLCAnJyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIGlmICggdHlwZW9mIHZhbHVlID09PSAndW5kZWZpbmVkJyApIHtcbiAgICAgICAgICAgIHZhbHVlID0gdGhpcy5yYXcobm9kZSwgbnVsbCwgJ2JlZm9yZURlY2wnKTtcbiAgICAgICAgfSBlbHNlIGlmICggdmFsdWUgKSB7XG4gICAgICAgICAgICB2YWx1ZSA9IHZhbHVlLnJlcGxhY2UoL1teXFxzXS9nLCAnJyk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHZhbHVlO1xuICAgIH1cblxuICAgIHJhd0JlZm9yZURlY2wocm9vdCwgbm9kZSkge1xuICAgICAgICBsZXQgdmFsdWU7XG4gICAgICAgIHJvb3Qud2Fsa0RlY2xzKCBpID0+IHtcbiAgICAgICAgICAgIGlmICggdHlwZW9mIGkucmF3cy5iZWZvcmUgIT09ICd1bmRlZmluZWQnICkge1xuICAgICAgICAgICAgICAgIHZhbHVlID0gaS5yYXdzLmJlZm9yZTtcbiAgICAgICAgICAgICAgICBpZiAoIHZhbHVlLmluZGV4T2YoJ1xcbicpICE9PSAtMSApIHtcbiAgICAgICAgICAgICAgICAgICAgdmFsdWUgPSB2YWx1ZS5yZXBsYWNlKC9bXlxcbl0rJC8sICcnKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgICAgaWYgKCB0eXBlb2YgdmFsdWUgPT09ICd1bmRlZmluZWQnICkge1xuICAgICAgICAgICAgdmFsdWUgPSB0aGlzLnJhdyhub2RlLCBudWxsLCAnYmVmb3JlUnVsZScpO1xuICAgICAgICB9IGVsc2UgaWYgKCB2YWx1ZSApIHtcbiAgICAgICAgICAgIHZhbHVlID0gdmFsdWUucmVwbGFjZSgvW15cXHNdL2csICcnKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdmFsdWU7XG4gICAgfVxuXG4gICAgcmF3QmVmb3JlUnVsZShyb290KSB7XG4gICAgICAgIGxldCB2YWx1ZTtcbiAgICAgICAgcm9vdC53YWxrKCBpID0+IHtcbiAgICAgICAgICAgIGlmICggaS5ub2RlcyAmJiAoaS5wYXJlbnQgIT09IHJvb3QgfHwgcm9vdC5maXJzdCAhPT0gaSkgKSB7XG4gICAgICAgICAgICAgICAgaWYgKCB0eXBlb2YgaS5yYXdzLmJlZm9yZSAhPT0gJ3VuZGVmaW5lZCcgKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhbHVlID0gaS5yYXdzLmJlZm9yZTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKCB2YWx1ZS5pbmRleE9mKCdcXG4nKSAhPT0gLTEgKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YWx1ZSA9IHZhbHVlLnJlcGxhY2UoL1teXFxuXSskLywgJycpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgICBpZiAoIHZhbHVlICkgdmFsdWUgPSB2YWx1ZS5yZXBsYWNlKC9bXlxcc10vZywgJycpO1xuICAgICAgICByZXR1cm4gdmFsdWU7XG4gICAgfVxuXG4gICAgcmF3QmVmb3JlQ2xvc2Uocm9vdCkge1xuICAgICAgICBsZXQgdmFsdWU7XG4gICAgICAgIHJvb3Qud2FsayggaSA9PiB7XG4gICAgICAgICAgICBpZiAoIGkubm9kZXMgJiYgaS5ub2Rlcy5sZW5ndGggPiAwICkge1xuICAgICAgICAgICAgICAgIGlmICggdHlwZW9mIGkucmF3cy5hZnRlciAhPT0gJ3VuZGVmaW5lZCcgKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhbHVlID0gaS5yYXdzLmFmdGVyO1xuICAgICAgICAgICAgICAgICAgICBpZiAoIHZhbHVlLmluZGV4T2YoJ1xcbicpICE9PSAtMSApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhbHVlID0gdmFsdWUucmVwbGFjZSgvW15cXG5dKyQvLCAnJyk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIGlmICggdmFsdWUgKSB2YWx1ZSA9IHZhbHVlLnJlcGxhY2UoL1teXFxzXS9nLCAnJyk7XG4gICAgICAgIHJldHVybiB2YWx1ZTtcbiAgICB9XG5cbiAgICByYXdCZWZvcmVPcGVuKHJvb3QpIHtcbiAgICAgICAgbGV0IHZhbHVlO1xuICAgICAgICByb290LndhbGsoIGkgPT4ge1xuICAgICAgICAgICAgaWYgKCBpLnR5cGUgIT09ICdkZWNsJyApIHtcbiAgICAgICAgICAgICAgICB2YWx1ZSA9IGkucmF3cy5iZXR3ZWVuO1xuICAgICAgICAgICAgICAgIGlmICggdHlwZW9mIHZhbHVlICE9PSAndW5kZWZpbmVkJyApIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIHJldHVybiB2YWx1ZTtcbiAgICB9XG5cbiAgICByYXdDb2xvbihyb290KSB7XG4gICAgICAgIGxldCB2YWx1ZTtcbiAgICAgICAgcm9vdC53YWxrRGVjbHMoIGkgPT4ge1xuICAgICAgICAgICAgaWYgKCB0eXBlb2YgaS5yYXdzLmJldHdlZW4gIT09ICd1bmRlZmluZWQnICkge1xuICAgICAgICAgICAgICAgIHZhbHVlID0gaS5yYXdzLmJldHdlZW4ucmVwbGFjZSgvW15cXHM6XS9nLCAnJyk7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgICAgcmV0dXJuIHZhbHVlO1xuICAgIH1cblxuICAgIGJlZm9yZUFmdGVyKG5vZGUsIGRldGVjdCkge1xuICAgICAgICBsZXQgdmFsdWU7XG4gICAgICAgIGlmICggbm9kZS50eXBlID09PSAnZGVjbCcgKSB7XG4gICAgICAgICAgICB2YWx1ZSA9IHRoaXMucmF3KG5vZGUsIG51bGwsICdiZWZvcmVEZWNsJyk7XG4gICAgICAgIH0gZWxzZSBpZiAoIG5vZGUudHlwZSA9PT0gJ2NvbW1lbnQnICkge1xuICAgICAgICAgICAgdmFsdWUgPSB0aGlzLnJhdyhub2RlLCBudWxsLCAnYmVmb3JlQ29tbWVudCcpO1xuICAgICAgICB9IGVsc2UgaWYgKCBkZXRlY3QgPT09ICdiZWZvcmUnICkge1xuICAgICAgICAgICAgdmFsdWUgPSB0aGlzLnJhdyhub2RlLCBudWxsLCAnYmVmb3JlUnVsZScpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdmFsdWUgPSB0aGlzLnJhdyhub2RlLCBudWxsLCAnYmVmb3JlQ2xvc2UnKTtcbiAgICAgICAgfVxuXG4gICAgICAgIGxldCBidWYgICA9IG5vZGUucGFyZW50O1xuICAgICAgICBsZXQgZGVwdGggPSAwO1xuICAgICAgICB3aGlsZSAoIGJ1ZiAmJiBidWYudHlwZSAhPT0gJ3Jvb3QnICkge1xuICAgICAgICAgICAgZGVwdGggKz0gMTtcbiAgICAgICAgICAgIGJ1ZiA9IGJ1Zi5wYXJlbnQ7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoIHZhbHVlLmluZGV4T2YoJ1xcbicpICE9PSAtMSApIHtcbiAgICAgICAgICAgIGxldCBpbmRlbnQgPSB0aGlzLnJhdyhub2RlLCBudWxsLCAnaW5kZW50Jyk7XG4gICAgICAgICAgICBpZiAoIGluZGVudC5sZW5ndGggKSB7XG4gICAgICAgICAgICAgICAgZm9yICggbGV0IHN0ZXAgPSAwOyBzdGVwIDwgZGVwdGg7IHN0ZXArKyApIHZhbHVlICs9IGluZGVudDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiB2YWx1ZTtcbiAgICB9XG5cbiAgICByYXdWYWx1ZShub2RlLCBwcm9wKSB7XG4gICAgICAgIGxldCB2YWx1ZSA9IG5vZGVbcHJvcF07XG4gICAgICAgIGxldCByYXcgICA9IG5vZGUucmF3c1twcm9wXTtcbiAgICAgICAgaWYgKCByYXcgJiYgcmF3LnZhbHVlID09PSB2YWx1ZSApIHtcbiAgICAgICAgICAgIHJldHVybiByYXcucmF3O1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIHZhbHVlO1xuICAgICAgICB9XG4gICAgfVxuXG59XG5cbmV4cG9ydCBkZWZhdWx0IFN0cmluZ2lmaWVyO1xuIl19