beautify-css.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626
  1. /* AUTO-GENERATED. DO NOT MODIFY. */
  2. /*
  3. The MIT License (MIT)
  4. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  5. Permission is hereby granted, free of charge, to any person
  6. obtaining a copy of this software and associated documentation files
  7. (the "Software"), to deal in the Software without restriction,
  8. including without limitation the rights to use, copy, modify, merge,
  9. publish, distribute, sublicense, and/or sell copies of the Software,
  10. and to permit persons to whom the Software is furnished to do so,
  11. subject to the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  18. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. SOFTWARE.
  22. CSS Beautifier
  23. ---------------
  24. Written by Harutyun Amirjanyan, (amirjanyan@gmail.com)
  25. Based on code initially developed by: Einar Lielmanis, <einar@beautifier.io>
  26. https://beautifier.io/
  27. Usage:
  28. css_beautify(source_text);
  29. css_beautify(source_text, options);
  30. The options are (default in brackets):
  31. indent_size (4) — indentation size,
  32. indent_char (space) — character to indent with,
  33. selector_separator_newline (true) - separate selectors with newline or
  34. not (e.g. "a,\nbr" or "a, br")
  35. end_with_newline (false) - end with a newline
  36. newline_between_rules (true) - add a new line after every css rule
  37. space_around_selector_separator (false) - ensure space around selector separators:
  38. '>', '+', '~' (e.g. "a>b" -> "a > b")
  39. e.g
  40. css_beautify(css_source_text, {
  41. 'indent_size': 1,
  42. 'indent_char': '\t',
  43. 'selector_separator': ' ',
  44. 'end_with_newline': false,
  45. 'newline_between_rules': true,
  46. 'space_around_selector_separator': true
  47. });
  48. */
  49. // http://www.w3.org/TR/CSS21/syndata.html#tokenization
  50. // http://www.w3.org/TR/css3-syntax/
  51. (function() {
  52. /* GENERATED_BUILD_OUTPUT */
  53. var legacy_beautify_css;
  54. /******/ (function() { // webpackBootstrap
  55. /******/ "use strict";
  56. /******/ var __webpack_modules__ = ([
  57. /* 0 */,
  58. /* 1 */,
  59. /* 2 */
  60. /***/ (function(module) {
  61. /*jshint node:true */
  62. /*
  63. The MIT License (MIT)
  64. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  65. Permission is hereby granted, free of charge, to any person
  66. obtaining a copy of this software and associated documentation files
  67. (the "Software"), to deal in the Software without restriction,
  68. including without limitation the rights to use, copy, modify, merge,
  69. publish, distribute, sublicense, and/or sell copies of the Software,
  70. and to permit persons to whom the Software is furnished to do so,
  71. subject to the following conditions:
  72. The above copyright notice and this permission notice shall be
  73. included in all copies or substantial portions of the Software.
  74. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  75. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  76. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  77. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  78. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  79. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  80. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  81. SOFTWARE.
  82. */
  83. function OutputLine(parent) {
  84. this.__parent = parent;
  85. this.__character_count = 0;
  86. // use indent_count as a marker for this.__lines that have preserved indentation
  87. this.__indent_count = -1;
  88. this.__alignment_count = 0;
  89. this.__wrap_point_index = 0;
  90. this.__wrap_point_character_count = 0;
  91. this.__wrap_point_indent_count = -1;
  92. this.__wrap_point_alignment_count = 0;
  93. this.__items = [];
  94. }
  95. OutputLine.prototype.clone_empty = function() {
  96. var line = new OutputLine(this.__parent);
  97. line.set_indent(this.__indent_count, this.__alignment_count);
  98. return line;
  99. };
  100. OutputLine.prototype.item = function(index) {
  101. if (index < 0) {
  102. return this.__items[this.__items.length + index];
  103. } else {
  104. return this.__items[index];
  105. }
  106. };
  107. OutputLine.prototype.has_match = function(pattern) {
  108. for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
  109. if (this.__items[lastCheckedOutput].match(pattern)) {
  110. return true;
  111. }
  112. }
  113. return false;
  114. };
  115. OutputLine.prototype.set_indent = function(indent, alignment) {
  116. if (this.is_empty()) {
  117. this.__indent_count = indent || 0;
  118. this.__alignment_count = alignment || 0;
  119. this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
  120. }
  121. };
  122. OutputLine.prototype._set_wrap_point = function() {
  123. if (this.__parent.wrap_line_length) {
  124. this.__wrap_point_index = this.__items.length;
  125. this.__wrap_point_character_count = this.__character_count;
  126. this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
  127. this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
  128. }
  129. };
  130. OutputLine.prototype._should_wrap = function() {
  131. return this.__wrap_point_index &&
  132. this.__character_count > this.__parent.wrap_line_length &&
  133. this.__wrap_point_character_count > this.__parent.next_line.__character_count;
  134. };
  135. OutputLine.prototype._allow_wrap = function() {
  136. if (this._should_wrap()) {
  137. this.__parent.add_new_line();
  138. var next = this.__parent.current_line;
  139. next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
  140. next.__items = this.__items.slice(this.__wrap_point_index);
  141. this.__items = this.__items.slice(0, this.__wrap_point_index);
  142. next.__character_count += this.__character_count - this.__wrap_point_character_count;
  143. this.__character_count = this.__wrap_point_character_count;
  144. if (next.__items[0] === " ") {
  145. next.__items.splice(0, 1);
  146. next.__character_count -= 1;
  147. }
  148. return true;
  149. }
  150. return false;
  151. };
  152. OutputLine.prototype.is_empty = function() {
  153. return this.__items.length === 0;
  154. };
  155. OutputLine.prototype.last = function() {
  156. if (!this.is_empty()) {
  157. return this.__items[this.__items.length - 1];
  158. } else {
  159. return null;
  160. }
  161. };
  162. OutputLine.prototype.push = function(item) {
  163. this.__items.push(item);
  164. var last_newline_index = item.lastIndexOf('\n');
  165. if (last_newline_index !== -1) {
  166. this.__character_count = item.length - last_newline_index;
  167. } else {
  168. this.__character_count += item.length;
  169. }
  170. };
  171. OutputLine.prototype.pop = function() {
  172. var item = null;
  173. if (!this.is_empty()) {
  174. item = this.__items.pop();
  175. this.__character_count -= item.length;
  176. }
  177. return item;
  178. };
  179. OutputLine.prototype._remove_indent = function() {
  180. if (this.__indent_count > 0) {
  181. this.__indent_count -= 1;
  182. this.__character_count -= this.__parent.indent_size;
  183. }
  184. };
  185. OutputLine.prototype._remove_wrap_indent = function() {
  186. if (this.__wrap_point_indent_count > 0) {
  187. this.__wrap_point_indent_count -= 1;
  188. }
  189. };
  190. OutputLine.prototype.trim = function() {
  191. while (this.last() === ' ') {
  192. this.__items.pop();
  193. this.__character_count -= 1;
  194. }
  195. };
  196. OutputLine.prototype.toString = function() {
  197. var result = '';
  198. if (this.is_empty()) {
  199. if (this.__parent.indent_empty_lines) {
  200. result = this.__parent.get_indent_string(this.__indent_count);
  201. }
  202. } else {
  203. result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
  204. result += this.__items.join('');
  205. }
  206. return result;
  207. };
  208. function IndentStringCache(options, baseIndentString) {
  209. this.__cache = [''];
  210. this.__indent_size = options.indent_size;
  211. this.__indent_string = options.indent_char;
  212. if (!options.indent_with_tabs) {
  213. this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
  214. }
  215. // Set to null to continue support for auto detection of base indent
  216. baseIndentString = baseIndentString || '';
  217. if (options.indent_level > 0) {
  218. baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
  219. }
  220. this.__base_string = baseIndentString;
  221. this.__base_string_length = baseIndentString.length;
  222. }
  223. IndentStringCache.prototype.get_indent_size = function(indent, column) {
  224. var result = this.__base_string_length;
  225. column = column || 0;
  226. if (indent < 0) {
  227. result = 0;
  228. }
  229. result += indent * this.__indent_size;
  230. result += column;
  231. return result;
  232. };
  233. IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
  234. var result = this.__base_string;
  235. column = column || 0;
  236. if (indent_level < 0) {
  237. indent_level = 0;
  238. result = '';
  239. }
  240. column += indent_level * this.__indent_size;
  241. this.__ensure_cache(column);
  242. result += this.__cache[column];
  243. return result;
  244. };
  245. IndentStringCache.prototype.__ensure_cache = function(column) {
  246. while (column >= this.__cache.length) {
  247. this.__add_column();
  248. }
  249. };
  250. IndentStringCache.prototype.__add_column = function() {
  251. var column = this.__cache.length;
  252. var indent = 0;
  253. var result = '';
  254. if (this.__indent_size && column >= this.__indent_size) {
  255. indent = Math.floor(column / this.__indent_size);
  256. column -= indent * this.__indent_size;
  257. result = new Array(indent + 1).join(this.__indent_string);
  258. }
  259. if (column) {
  260. result += new Array(column + 1).join(' ');
  261. }
  262. this.__cache.push(result);
  263. };
  264. function Output(options, baseIndentString) {
  265. this.__indent_cache = new IndentStringCache(options, baseIndentString);
  266. this.raw = false;
  267. this._end_with_newline = options.end_with_newline;
  268. this.indent_size = options.indent_size;
  269. this.wrap_line_length = options.wrap_line_length;
  270. this.indent_empty_lines = options.indent_empty_lines;
  271. this.__lines = [];
  272. this.previous_line = null;
  273. this.current_line = null;
  274. this.next_line = new OutputLine(this);
  275. this.space_before_token = false;
  276. this.non_breaking_space = false;
  277. this.previous_token_wrapped = false;
  278. // initialize
  279. this.__add_outputline();
  280. }
  281. Output.prototype.__add_outputline = function() {
  282. this.previous_line = this.current_line;
  283. this.current_line = this.next_line.clone_empty();
  284. this.__lines.push(this.current_line);
  285. };
  286. Output.prototype.get_line_number = function() {
  287. return this.__lines.length;
  288. };
  289. Output.prototype.get_indent_string = function(indent, column) {
  290. return this.__indent_cache.get_indent_string(indent, column);
  291. };
  292. Output.prototype.get_indent_size = function(indent, column) {
  293. return this.__indent_cache.get_indent_size(indent, column);
  294. };
  295. Output.prototype.is_empty = function() {
  296. return !this.previous_line && this.current_line.is_empty();
  297. };
  298. Output.prototype.add_new_line = function(force_newline) {
  299. // never newline at the start of file
  300. // otherwise, newline only if we didn't just add one or we're forced
  301. if (this.is_empty() ||
  302. (!force_newline && this.just_added_newline())) {
  303. return false;
  304. }
  305. // if raw output is enabled, don't print additional newlines,
  306. // but still return True as though you had
  307. if (!this.raw) {
  308. this.__add_outputline();
  309. }
  310. return true;
  311. };
  312. Output.prototype.get_code = function(eol) {
  313. this.trim(true);
  314. // handle some edge cases where the last tokens
  315. // has text that ends with newline(s)
  316. var last_item = this.current_line.pop();
  317. if (last_item) {
  318. if (last_item[last_item.length - 1] === '\n') {
  319. last_item = last_item.replace(/\n+$/g, '');
  320. }
  321. this.current_line.push(last_item);
  322. }
  323. if (this._end_with_newline) {
  324. this.__add_outputline();
  325. }
  326. var sweet_code = this.__lines.join('\n');
  327. if (eol !== '\n') {
  328. sweet_code = sweet_code.replace(/[\n]/g, eol);
  329. }
  330. return sweet_code;
  331. };
  332. Output.prototype.set_wrap_point = function() {
  333. this.current_line._set_wrap_point();
  334. };
  335. Output.prototype.set_indent = function(indent, alignment) {
  336. indent = indent || 0;
  337. alignment = alignment || 0;
  338. // Next line stores alignment values
  339. this.next_line.set_indent(indent, alignment);
  340. // Never indent your first output indent at the start of the file
  341. if (this.__lines.length > 1) {
  342. this.current_line.set_indent(indent, alignment);
  343. return true;
  344. }
  345. this.current_line.set_indent();
  346. return false;
  347. };
  348. Output.prototype.add_raw_token = function(token) {
  349. for (var x = 0; x < token.newlines; x++) {
  350. this.__add_outputline();
  351. }
  352. this.current_line.set_indent(-1);
  353. this.current_line.push(token.whitespace_before);
  354. this.current_line.push(token.text);
  355. this.space_before_token = false;
  356. this.non_breaking_space = false;
  357. this.previous_token_wrapped = false;
  358. };
  359. Output.prototype.add_token = function(printable_token) {
  360. this.__add_space_before_token();
  361. this.current_line.push(printable_token);
  362. this.space_before_token = false;
  363. this.non_breaking_space = false;
  364. this.previous_token_wrapped = this.current_line._allow_wrap();
  365. };
  366. Output.prototype.__add_space_before_token = function() {
  367. if (this.space_before_token && !this.just_added_newline()) {
  368. if (!this.non_breaking_space) {
  369. this.set_wrap_point();
  370. }
  371. this.current_line.push(' ');
  372. }
  373. };
  374. Output.prototype.remove_indent = function(index) {
  375. var output_length = this.__lines.length;
  376. while (index < output_length) {
  377. this.__lines[index]._remove_indent();
  378. index++;
  379. }
  380. this.current_line._remove_wrap_indent();
  381. };
  382. Output.prototype.trim = function(eat_newlines) {
  383. eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
  384. this.current_line.trim();
  385. while (eat_newlines && this.__lines.length > 1 &&
  386. this.current_line.is_empty()) {
  387. this.__lines.pop();
  388. this.current_line = this.__lines[this.__lines.length - 1];
  389. this.current_line.trim();
  390. }
  391. this.previous_line = this.__lines.length > 1 ?
  392. this.__lines[this.__lines.length - 2] : null;
  393. };
  394. Output.prototype.just_added_newline = function() {
  395. return this.current_line.is_empty();
  396. };
  397. Output.prototype.just_added_blankline = function() {
  398. return this.is_empty() ||
  399. (this.current_line.is_empty() && this.previous_line.is_empty());
  400. };
  401. Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
  402. var index = this.__lines.length - 2;
  403. while (index >= 0) {
  404. var potentialEmptyLine = this.__lines[index];
  405. if (potentialEmptyLine.is_empty()) {
  406. break;
  407. } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
  408. potentialEmptyLine.item(-1) !== ends_with) {
  409. this.__lines.splice(index + 1, 0, new OutputLine(this));
  410. this.previous_line = this.__lines[this.__lines.length - 2];
  411. break;
  412. }
  413. index--;
  414. }
  415. };
  416. module.exports.Output = Output;
  417. /***/ }),
  418. /* 3 */,
  419. /* 4 */,
  420. /* 5 */,
  421. /* 6 */
  422. /***/ (function(module) {
  423. /*jshint node:true */
  424. /*
  425. The MIT License (MIT)
  426. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  427. Permission is hereby granted, free of charge, to any person
  428. obtaining a copy of this software and associated documentation files
  429. (the "Software"), to deal in the Software without restriction,
  430. including without limitation the rights to use, copy, modify, merge,
  431. publish, distribute, sublicense, and/or sell copies of the Software,
  432. and to permit persons to whom the Software is furnished to do so,
  433. subject to the following conditions:
  434. The above copyright notice and this permission notice shall be
  435. included in all copies or substantial portions of the Software.
  436. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  437. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  438. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  439. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  440. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  441. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  442. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  443. SOFTWARE.
  444. */
  445. function Options(options, merge_child_field) {
  446. this.raw_options = _mergeOpts(options, merge_child_field);
  447. // Support passing the source text back with no change
  448. this.disabled = this._get_boolean('disabled');
  449. this.eol = this._get_characters('eol', 'auto');
  450. this.end_with_newline = this._get_boolean('end_with_newline');
  451. this.indent_size = this._get_number('indent_size', 4);
  452. this.indent_char = this._get_characters('indent_char', ' ');
  453. this.indent_level = this._get_number('indent_level');
  454. this.preserve_newlines = this._get_boolean('preserve_newlines', true);
  455. this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
  456. if (!this.preserve_newlines) {
  457. this.max_preserve_newlines = 0;
  458. }
  459. this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
  460. if (this.indent_with_tabs) {
  461. this.indent_char = '\t';
  462. // indent_size behavior changed after 1.8.6
  463. // It used to be that indent_size would be
  464. // set to 1 for indent_with_tabs. That is no longer needed and
  465. // actually doesn't make sense - why not use spaces? Further,
  466. // that might produce unexpected behavior - tabs being used
  467. // for single-column alignment. So, when indent_with_tabs is true
  468. // and indent_size is 1, reset indent_size to 4.
  469. if (this.indent_size === 1) {
  470. this.indent_size = 4;
  471. }
  472. }
  473. // Backwards compat with 1.3.x
  474. this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
  475. this.indent_empty_lines = this._get_boolean('indent_empty_lines');
  476. // valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty']
  477. // For now, 'auto' = all off for javascript, all on for html (and inline javascript).
  478. // other values ignored
  479. this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
  480. }
  481. Options.prototype._get_array = function(name, default_value) {
  482. var option_value = this.raw_options[name];
  483. var result = default_value || [];
  484. if (typeof option_value === 'object') {
  485. if (option_value !== null && typeof option_value.concat === 'function') {
  486. result = option_value.concat();
  487. }
  488. } else if (typeof option_value === 'string') {
  489. result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
  490. }
  491. return result;
  492. };
  493. Options.prototype._get_boolean = function(name, default_value) {
  494. var option_value = this.raw_options[name];
  495. var result = option_value === undefined ? !!default_value : !!option_value;
  496. return result;
  497. };
  498. Options.prototype._get_characters = function(name, default_value) {
  499. var option_value = this.raw_options[name];
  500. var result = default_value || '';
  501. if (typeof option_value === 'string') {
  502. result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
  503. }
  504. return result;
  505. };
  506. Options.prototype._get_number = function(name, default_value) {
  507. var option_value = this.raw_options[name];
  508. default_value = parseInt(default_value, 10);
  509. if (isNaN(default_value)) {
  510. default_value = 0;
  511. }
  512. var result = parseInt(option_value, 10);
  513. if (isNaN(result)) {
  514. result = default_value;
  515. }
  516. return result;
  517. };
  518. Options.prototype._get_selection = function(name, selection_list, default_value) {
  519. var result = this._get_selection_list(name, selection_list, default_value);
  520. if (result.length !== 1) {
  521. throw new Error(
  522. "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
  523. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  524. }
  525. return result[0];
  526. };
  527. Options.prototype._get_selection_list = function(name, selection_list, default_value) {
  528. if (!selection_list || selection_list.length === 0) {
  529. throw new Error("Selection list cannot be empty.");
  530. }
  531. default_value = default_value || [selection_list[0]];
  532. if (!this._is_valid_selection(default_value, selection_list)) {
  533. throw new Error("Invalid Default Value!");
  534. }
  535. var result = this._get_array(name, default_value);
  536. if (!this._is_valid_selection(result, selection_list)) {
  537. throw new Error(
  538. "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
  539. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  540. }
  541. return result;
  542. };
  543. Options.prototype._is_valid_selection = function(result, selection_list) {
  544. return result.length && selection_list.length &&
  545. !result.some(function(item) { return selection_list.indexOf(item) === -1; });
  546. };
  547. // merges child options up with the parent options object
  548. // Example: obj = {a: 1, b: {a: 2}}
  549. // mergeOpts(obj, 'b')
  550. //
  551. // Returns: {a: 2}
  552. function _mergeOpts(allOptions, childFieldName) {
  553. var finalOpts = {};
  554. allOptions = _normalizeOpts(allOptions);
  555. var name;
  556. for (name in allOptions) {
  557. if (name !== childFieldName) {
  558. finalOpts[name] = allOptions[name];
  559. }
  560. }
  561. //merge in the per type settings for the childFieldName
  562. if (childFieldName && allOptions[childFieldName]) {
  563. for (name in allOptions[childFieldName]) {
  564. finalOpts[name] = allOptions[childFieldName][name];
  565. }
  566. }
  567. return finalOpts;
  568. }
  569. function _normalizeOpts(options) {
  570. var convertedOpts = {};
  571. var key;
  572. for (key in options) {
  573. var newKey = key.replace(/-/g, "_");
  574. convertedOpts[newKey] = options[key];
  575. }
  576. return convertedOpts;
  577. }
  578. module.exports.Options = Options;
  579. module.exports.normalizeOpts = _normalizeOpts;
  580. module.exports.mergeOpts = _mergeOpts;
  581. /***/ }),
  582. /* 7 */,
  583. /* 8 */
  584. /***/ (function(module) {
  585. /*jshint node:true */
  586. /*
  587. The MIT License (MIT)
  588. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  589. Permission is hereby granted, free of charge, to any person
  590. obtaining a copy of this software and associated documentation files
  591. (the "Software"), to deal in the Software without restriction,
  592. including without limitation the rights to use, copy, modify, merge,
  593. publish, distribute, sublicense, and/or sell copies of the Software,
  594. and to permit persons to whom the Software is furnished to do so,
  595. subject to the following conditions:
  596. The above copyright notice and this permission notice shall be
  597. included in all copies or substantial portions of the Software.
  598. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  599. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  600. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  601. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  602. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  603. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  604. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  605. SOFTWARE.
  606. */
  607. var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
  608. function InputScanner(input_string) {
  609. this.__input = input_string || '';
  610. this.__input_length = this.__input.length;
  611. this.__position = 0;
  612. }
  613. InputScanner.prototype.restart = function() {
  614. this.__position = 0;
  615. };
  616. InputScanner.prototype.back = function() {
  617. if (this.__position > 0) {
  618. this.__position -= 1;
  619. }
  620. };
  621. InputScanner.prototype.hasNext = function() {
  622. return this.__position < this.__input_length;
  623. };
  624. InputScanner.prototype.next = function() {
  625. var val = null;
  626. if (this.hasNext()) {
  627. val = this.__input.charAt(this.__position);
  628. this.__position += 1;
  629. }
  630. return val;
  631. };
  632. InputScanner.prototype.peek = function(index) {
  633. var val = null;
  634. index = index || 0;
  635. index += this.__position;
  636. if (index >= 0 && index < this.__input_length) {
  637. val = this.__input.charAt(index);
  638. }
  639. return val;
  640. };
  641. // This is a JavaScript only helper function (not in python)
  642. // Javascript doesn't have a match method
  643. // and not all implementation support "sticky" flag.
  644. // If they do not support sticky then both this.match() and this.test() method
  645. // must get the match and check the index of the match.
  646. // If sticky is supported and set, this method will use it.
  647. // Otherwise it will check that global is set, and fall back to the slower method.
  648. InputScanner.prototype.__match = function(pattern, index) {
  649. pattern.lastIndex = index;
  650. var pattern_match = pattern.exec(this.__input);
  651. if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
  652. if (pattern_match.index !== index) {
  653. pattern_match = null;
  654. }
  655. }
  656. return pattern_match;
  657. };
  658. InputScanner.prototype.test = function(pattern, index) {
  659. index = index || 0;
  660. index += this.__position;
  661. if (index >= 0 && index < this.__input_length) {
  662. return !!this.__match(pattern, index);
  663. } else {
  664. return false;
  665. }
  666. };
  667. InputScanner.prototype.testChar = function(pattern, index) {
  668. // test one character regex match
  669. var val = this.peek(index);
  670. pattern.lastIndex = 0;
  671. return val !== null && pattern.test(val);
  672. };
  673. InputScanner.prototype.match = function(pattern) {
  674. var pattern_match = this.__match(pattern, this.__position);
  675. if (pattern_match) {
  676. this.__position += pattern_match[0].length;
  677. } else {
  678. pattern_match = null;
  679. }
  680. return pattern_match;
  681. };
  682. InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
  683. var val = '';
  684. var match;
  685. if (starting_pattern) {
  686. match = this.match(starting_pattern);
  687. if (match) {
  688. val += match[0];
  689. }
  690. }
  691. if (until_pattern && (match || !starting_pattern)) {
  692. val += this.readUntil(until_pattern, until_after);
  693. }
  694. return val;
  695. };
  696. InputScanner.prototype.readUntil = function(pattern, until_after) {
  697. var val = '';
  698. var match_index = this.__position;
  699. pattern.lastIndex = this.__position;
  700. var pattern_match = pattern.exec(this.__input);
  701. if (pattern_match) {
  702. match_index = pattern_match.index;
  703. if (until_after) {
  704. match_index += pattern_match[0].length;
  705. }
  706. } else {
  707. match_index = this.__input_length;
  708. }
  709. val = this.__input.substring(this.__position, match_index);
  710. this.__position = match_index;
  711. return val;
  712. };
  713. InputScanner.prototype.readUntilAfter = function(pattern) {
  714. return this.readUntil(pattern, true);
  715. };
  716. InputScanner.prototype.get_regexp = function(pattern, match_from) {
  717. var result = null;
  718. var flags = 'g';
  719. if (match_from && regexp_has_sticky) {
  720. flags = 'y';
  721. }
  722. // strings are converted to regexp
  723. if (typeof pattern === "string" && pattern !== '') {
  724. // result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags);
  725. result = new RegExp(pattern, flags);
  726. } else if (pattern) {
  727. result = new RegExp(pattern.source, flags);
  728. }
  729. return result;
  730. };
  731. InputScanner.prototype.get_literal_regexp = function(literal_string) {
  732. return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
  733. };
  734. /* css beautifier legacy helpers */
  735. InputScanner.prototype.peekUntilAfter = function(pattern) {
  736. var start = this.__position;
  737. var val = this.readUntilAfter(pattern);
  738. this.__position = start;
  739. return val;
  740. };
  741. InputScanner.prototype.lookBack = function(testVal) {
  742. var start = this.__position - 1;
  743. return start >= testVal.length && this.__input.substring(start - testVal.length, start)
  744. .toLowerCase() === testVal;
  745. };
  746. module.exports.InputScanner = InputScanner;
  747. /***/ }),
  748. /* 9 */,
  749. /* 10 */,
  750. /* 11 */,
  751. /* 12 */,
  752. /* 13 */
  753. /***/ (function(module) {
  754. /*jshint node:true */
  755. /*
  756. The MIT License (MIT)
  757. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  758. Permission is hereby granted, free of charge, to any person
  759. obtaining a copy of this software and associated documentation files
  760. (the "Software"), to deal in the Software without restriction,
  761. including without limitation the rights to use, copy, modify, merge,
  762. publish, distribute, sublicense, and/or sell copies of the Software,
  763. and to permit persons to whom the Software is furnished to do so,
  764. subject to the following conditions:
  765. The above copyright notice and this permission notice shall be
  766. included in all copies or substantial portions of the Software.
  767. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  768. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  769. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  770. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  771. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  772. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  773. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  774. SOFTWARE.
  775. */
  776. function Directives(start_block_pattern, end_block_pattern) {
  777. start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
  778. end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
  779. this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
  780. this.__directive_pattern = / (\w+)[:](\w+)/g;
  781. this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
  782. }
  783. Directives.prototype.get_directives = function(text) {
  784. if (!text.match(this.__directives_block_pattern)) {
  785. return null;
  786. }
  787. var directives = {};
  788. this.__directive_pattern.lastIndex = 0;
  789. var directive_match = this.__directive_pattern.exec(text);
  790. while (directive_match) {
  791. directives[directive_match[1]] = directive_match[2];
  792. directive_match = this.__directive_pattern.exec(text);
  793. }
  794. return directives;
  795. };
  796. Directives.prototype.readIgnored = function(input) {
  797. return input.readUntilAfter(this.__directives_end_ignore_pattern);
  798. };
  799. module.exports.Directives = Directives;
  800. /***/ }),
  801. /* 14 */,
  802. /* 15 */
  803. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  804. /*jshint node:true */
  805. /*
  806. The MIT License (MIT)
  807. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  808. Permission is hereby granted, free of charge, to any person
  809. obtaining a copy of this software and associated documentation files
  810. (the "Software"), to deal in the Software without restriction,
  811. including without limitation the rights to use, copy, modify, merge,
  812. publish, distribute, sublicense, and/or sell copies of the Software,
  813. and to permit persons to whom the Software is furnished to do so,
  814. subject to the following conditions:
  815. The above copyright notice and this permission notice shall be
  816. included in all copies or substantial portions of the Software.
  817. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  818. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  819. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  820. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  821. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  822. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  823. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  824. SOFTWARE.
  825. */
  826. var Beautifier = __webpack_require__(16).Beautifier,
  827. Options = __webpack_require__(17).Options;
  828. function css_beautify(source_text, options) {
  829. var beautifier = new Beautifier(source_text, options);
  830. return beautifier.beautify();
  831. }
  832. module.exports = css_beautify;
  833. module.exports.defaultOptions = function() {
  834. return new Options();
  835. };
  836. /***/ }),
  837. /* 16 */
  838. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  839. /*jshint node:true */
  840. /*
  841. The MIT License (MIT)
  842. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  843. Permission is hereby granted, free of charge, to any person
  844. obtaining a copy of this software and associated documentation files
  845. (the "Software"), to deal in the Software without restriction,
  846. including without limitation the rights to use, copy, modify, merge,
  847. publish, distribute, sublicense, and/or sell copies of the Software,
  848. and to permit persons to whom the Software is furnished to do so,
  849. subject to the following conditions:
  850. The above copyright notice and this permission notice shall be
  851. included in all copies or substantial portions of the Software.
  852. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  853. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  854. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  855. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  856. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  857. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  858. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  859. SOFTWARE.
  860. */
  861. var Options = __webpack_require__(17).Options;
  862. var Output = __webpack_require__(2).Output;
  863. var InputScanner = __webpack_require__(8).InputScanner;
  864. var Directives = __webpack_require__(13).Directives;
  865. var directives_core = new Directives(/\/\*/, /\*\//);
  866. var lineBreak = /\r\n|[\r\n]/;
  867. var allLineBreaks = /\r\n|[\r\n]/g;
  868. // tokenizer
  869. var whitespaceChar = /\s/;
  870. var whitespacePattern = /(?:\s|\n)+/g;
  871. var block_comment_pattern = /\/\*(?:[\s\S]*?)((?:\*\/)|$)/g;
  872. var comment_pattern = /\/\/(?:[^\n\r\u2028\u2029]*)/g;
  873. function Beautifier(source_text, options) {
  874. this._source_text = source_text || '';
  875. // Allow the setting of language/file-type specific options
  876. // with inheritance of overall settings
  877. this._options = new Options(options);
  878. this._ch = null;
  879. this._input = null;
  880. // https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule
  881. this.NESTED_AT_RULE = {
  882. "@page": true,
  883. "@font-face": true,
  884. "@keyframes": true,
  885. // also in CONDITIONAL_GROUP_RULE below
  886. "@media": true,
  887. "@supports": true,
  888. "@document": true
  889. };
  890. this.CONDITIONAL_GROUP_RULE = {
  891. "@media": true,
  892. "@supports": true,
  893. "@document": true
  894. };
  895. }
  896. Beautifier.prototype.eatString = function(endChars) {
  897. var result = '';
  898. this._ch = this._input.next();
  899. while (this._ch) {
  900. result += this._ch;
  901. if (this._ch === "\\") {
  902. result += this._input.next();
  903. } else if (endChars.indexOf(this._ch) !== -1 || this._ch === "\n") {
  904. break;
  905. }
  906. this._ch = this._input.next();
  907. }
  908. return result;
  909. };
  910. // Skips any white space in the source text from the current position.
  911. // When allowAtLeastOneNewLine is true, will output new lines for each
  912. // newline character found; if the user has preserve_newlines off, only
  913. // the first newline will be output
  914. Beautifier.prototype.eatWhitespace = function(allowAtLeastOneNewLine) {
  915. var result = whitespaceChar.test(this._input.peek());
  916. var newline_count = 0;
  917. while (whitespaceChar.test(this._input.peek())) {
  918. this._ch = this._input.next();
  919. if (allowAtLeastOneNewLine && this._ch === '\n') {
  920. if (newline_count === 0 || newline_count < this._options.max_preserve_newlines) {
  921. newline_count++;
  922. this._output.add_new_line(true);
  923. }
  924. }
  925. }
  926. return result;
  927. };
  928. // Nested pseudo-class if we are insideRule
  929. // and the next special character found opens
  930. // a new block
  931. Beautifier.prototype.foundNestedPseudoClass = function() {
  932. var openParen = 0;
  933. var i = 1;
  934. var ch = this._input.peek(i);
  935. while (ch) {
  936. if (ch === "{") {
  937. return true;
  938. } else if (ch === '(') {
  939. // pseudoclasses can contain ()
  940. openParen += 1;
  941. } else if (ch === ')') {
  942. if (openParen === 0) {
  943. return false;
  944. }
  945. openParen -= 1;
  946. } else if (ch === ";" || ch === "}") {
  947. return false;
  948. }
  949. i++;
  950. ch = this._input.peek(i);
  951. }
  952. return false;
  953. };
  954. Beautifier.prototype.print_string = function(output_string) {
  955. this._output.set_indent(this._indentLevel);
  956. this._output.non_breaking_space = true;
  957. this._output.add_token(output_string);
  958. };
  959. Beautifier.prototype.preserveSingleSpace = function(isAfterSpace) {
  960. if (isAfterSpace) {
  961. this._output.space_before_token = true;
  962. }
  963. };
  964. Beautifier.prototype.indent = function() {
  965. this._indentLevel++;
  966. };
  967. Beautifier.prototype.outdent = function() {
  968. if (this._indentLevel > 0) {
  969. this._indentLevel--;
  970. }
  971. };
  972. /*_____________________--------------------_____________________*/
  973. Beautifier.prototype.beautify = function() {
  974. if (this._options.disabled) {
  975. return this._source_text;
  976. }
  977. var source_text = this._source_text;
  978. var eol = this._options.eol;
  979. if (eol === 'auto') {
  980. eol = '\n';
  981. if (source_text && lineBreak.test(source_text || '')) {
  982. eol = source_text.match(lineBreak)[0];
  983. }
  984. }
  985. // HACK: newline parsing inconsistent. This brute force normalizes the this._input.
  986. source_text = source_text.replace(allLineBreaks, '\n');
  987. // reset
  988. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  989. this._output = new Output(this._options, baseIndentString);
  990. this._input = new InputScanner(source_text);
  991. this._indentLevel = 0;
  992. this._nestedLevel = 0;
  993. this._ch = null;
  994. var parenLevel = 0;
  995. var insideRule = false;
  996. // This is the value side of a property value pair (blue in the following ex)
  997. // label { content: blue }
  998. var insidePropertyValue = false;
  999. var enteringConditionalGroup = false;
  1000. var insideAtExtend = false;
  1001. var insideAtImport = false;
  1002. var topCharacter = this._ch;
  1003. var whitespace;
  1004. var isAfterSpace;
  1005. var previous_ch;
  1006. while (true) {
  1007. whitespace = this._input.read(whitespacePattern);
  1008. isAfterSpace = whitespace !== '';
  1009. previous_ch = topCharacter;
  1010. this._ch = this._input.next();
  1011. if (this._ch === '\\' && this._input.hasNext()) {
  1012. this._ch += this._input.next();
  1013. }
  1014. topCharacter = this._ch;
  1015. if (!this._ch) {
  1016. break;
  1017. } else if (this._ch === '/' && this._input.peek() === '*') {
  1018. // /* css comment */
  1019. // Always start block comments on a new line.
  1020. // This handles scenarios where a block comment immediately
  1021. // follows a property definition on the same line or where
  1022. // minified code is being beautified.
  1023. this._output.add_new_line();
  1024. this._input.back();
  1025. var comment = this._input.read(block_comment_pattern);
  1026. // Handle ignore directive
  1027. var directives = directives_core.get_directives(comment);
  1028. if (directives && directives.ignore === 'start') {
  1029. comment += directives_core.readIgnored(this._input);
  1030. }
  1031. this.print_string(comment);
  1032. // Ensures any new lines following the comment are preserved
  1033. this.eatWhitespace(true);
  1034. // Block comments are followed by a new line so they don't
  1035. // share a line with other properties
  1036. this._output.add_new_line();
  1037. } else if (this._ch === '/' && this._input.peek() === '/') {
  1038. // // single line comment
  1039. // Preserves the space before a comment
  1040. // on the same line as a rule
  1041. this._output.space_before_token = true;
  1042. this._input.back();
  1043. this.print_string(this._input.read(comment_pattern));
  1044. // Ensures any new lines following the comment are preserved
  1045. this.eatWhitespace(true);
  1046. } else if (this._ch === '@') {
  1047. this.preserveSingleSpace(isAfterSpace);
  1048. // deal with less propery mixins @{...}
  1049. if (this._input.peek() === '{') {
  1050. this.print_string(this._ch + this.eatString('}'));
  1051. } else {
  1052. this.print_string(this._ch);
  1053. // strip trailing space, if present, for hash property checks
  1054. var variableOrRule = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
  1055. if (variableOrRule.match(/[ :]$/)) {
  1056. // we have a variable or pseudo-class, add it and insert one space before continuing
  1057. variableOrRule = this.eatString(": ").replace(/\s$/, '');
  1058. this.print_string(variableOrRule);
  1059. this._output.space_before_token = true;
  1060. }
  1061. variableOrRule = variableOrRule.replace(/\s$/, '');
  1062. if (variableOrRule === 'extend') {
  1063. insideAtExtend = true;
  1064. } else if (variableOrRule === 'import') {
  1065. insideAtImport = true;
  1066. }
  1067. // might be a nesting at-rule
  1068. if (variableOrRule in this.NESTED_AT_RULE) {
  1069. this._nestedLevel += 1;
  1070. if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
  1071. enteringConditionalGroup = true;
  1072. }
  1073. // might be less variable
  1074. } else if (!insideRule && parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
  1075. insidePropertyValue = true;
  1076. this.indent();
  1077. }
  1078. }
  1079. } else if (this._ch === '#' && this._input.peek() === '{') {
  1080. this.preserveSingleSpace(isAfterSpace);
  1081. this.print_string(this._ch + this.eatString('}'));
  1082. } else if (this._ch === '{') {
  1083. if (insidePropertyValue) {
  1084. insidePropertyValue = false;
  1085. this.outdent();
  1086. }
  1087. // when entering conditional groups, only rulesets are allowed
  1088. if (enteringConditionalGroup) {
  1089. enteringConditionalGroup = false;
  1090. insideRule = (this._indentLevel >= this._nestedLevel);
  1091. } else {
  1092. // otherwise, declarations are also allowed
  1093. insideRule = (this._indentLevel >= this._nestedLevel - 1);
  1094. }
  1095. if (this._options.newline_between_rules && insideRule) {
  1096. if (this._output.previous_line && this._output.previous_line.item(-1) !== '{') {
  1097. this._output.ensure_empty_line_above('/', ',');
  1098. }
  1099. }
  1100. this._output.space_before_token = true;
  1101. // The difference in print_string and indent order is necessary to indent the '{' correctly
  1102. if (this._options.brace_style === 'expand') {
  1103. this._output.add_new_line();
  1104. this.print_string(this._ch);
  1105. this.indent();
  1106. this._output.set_indent(this._indentLevel);
  1107. } else {
  1108. this.indent();
  1109. this.print_string(this._ch);
  1110. }
  1111. this.eatWhitespace(true);
  1112. this._output.add_new_line();
  1113. } else if (this._ch === '}') {
  1114. this.outdent();
  1115. this._output.add_new_line();
  1116. if (previous_ch === '{') {
  1117. this._output.trim(true);
  1118. }
  1119. insideAtImport = false;
  1120. insideAtExtend = false;
  1121. if (insidePropertyValue) {
  1122. this.outdent();
  1123. insidePropertyValue = false;
  1124. }
  1125. this.print_string(this._ch);
  1126. insideRule = false;
  1127. if (this._nestedLevel) {
  1128. this._nestedLevel--;
  1129. }
  1130. this.eatWhitespace(true);
  1131. this._output.add_new_line();
  1132. if (this._options.newline_between_rules && !this._output.just_added_blankline()) {
  1133. if (this._input.peek() !== '}') {
  1134. this._output.add_new_line(true);
  1135. }
  1136. }
  1137. } else if (this._ch === ":") {
  1138. if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
  1139. // 'property: value' delimiter
  1140. // which could be in a conditional group query
  1141. this.print_string(':');
  1142. if (!insidePropertyValue) {
  1143. insidePropertyValue = true;
  1144. this._output.space_before_token = true;
  1145. this.eatWhitespace(true);
  1146. this.indent();
  1147. }
  1148. } else {
  1149. // sass/less parent reference don't use a space
  1150. // sass nested pseudo-class don't use a space
  1151. // preserve space before pseudoclasses/pseudoelements, as it means "in any child"
  1152. if (this._input.lookBack(" ")) {
  1153. this._output.space_before_token = true;
  1154. }
  1155. if (this._input.peek() === ":") {
  1156. // pseudo-element
  1157. this._ch = this._input.next();
  1158. this.print_string("::");
  1159. } else {
  1160. // pseudo-class
  1161. this.print_string(':');
  1162. }
  1163. }
  1164. } else if (this._ch === '"' || this._ch === '\'') {
  1165. this.preserveSingleSpace(isAfterSpace);
  1166. this.print_string(this._ch + this.eatString(this._ch));
  1167. this.eatWhitespace(true);
  1168. } else if (this._ch === ';') {
  1169. if (parenLevel === 0) {
  1170. if (insidePropertyValue) {
  1171. this.outdent();
  1172. insidePropertyValue = false;
  1173. }
  1174. insideAtExtend = false;
  1175. insideAtImport = false;
  1176. this.print_string(this._ch);
  1177. this.eatWhitespace(true);
  1178. // This maintains single line comments on the same
  1179. // line. Block comments are also affected, but
  1180. // a new line is always output before one inside
  1181. // that section
  1182. if (this._input.peek() !== '/') {
  1183. this._output.add_new_line();
  1184. }
  1185. } else {
  1186. this.print_string(this._ch);
  1187. this.eatWhitespace(true);
  1188. this._output.space_before_token = true;
  1189. }
  1190. } else if (this._ch === '(') { // may be a url
  1191. if (this._input.lookBack("url")) {
  1192. this.print_string(this._ch);
  1193. this.eatWhitespace();
  1194. parenLevel++;
  1195. this.indent();
  1196. this._ch = this._input.next();
  1197. if (this._ch === ')' || this._ch === '"' || this._ch === '\'') {
  1198. this._input.back();
  1199. } else if (this._ch) {
  1200. this.print_string(this._ch + this.eatString(')'));
  1201. if (parenLevel) {
  1202. parenLevel--;
  1203. this.outdent();
  1204. }
  1205. }
  1206. } else {
  1207. this.preserveSingleSpace(isAfterSpace);
  1208. this.print_string(this._ch);
  1209. this.eatWhitespace();
  1210. parenLevel++;
  1211. this.indent();
  1212. }
  1213. } else if (this._ch === ')') {
  1214. if (parenLevel) {
  1215. parenLevel--;
  1216. this.outdent();
  1217. }
  1218. this.print_string(this._ch);
  1219. } else if (this._ch === ',') {
  1220. this.print_string(this._ch);
  1221. this.eatWhitespace(true);
  1222. if (this._options.selector_separator_newline && !insidePropertyValue && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
  1223. this._output.add_new_line();
  1224. } else {
  1225. this._output.space_before_token = true;
  1226. }
  1227. } else if ((this._ch === '>' || this._ch === '+' || this._ch === '~') && !insidePropertyValue && parenLevel === 0) {
  1228. //handle combinator spacing
  1229. if (this._options.space_around_combinator) {
  1230. this._output.space_before_token = true;
  1231. this.print_string(this._ch);
  1232. this._output.space_before_token = true;
  1233. } else {
  1234. this.print_string(this._ch);
  1235. this.eatWhitespace();
  1236. // squash extra whitespace
  1237. if (this._ch && whitespaceChar.test(this._ch)) {
  1238. this._ch = '';
  1239. }
  1240. }
  1241. } else if (this._ch === ']') {
  1242. this.print_string(this._ch);
  1243. } else if (this._ch === '[') {
  1244. this.preserveSingleSpace(isAfterSpace);
  1245. this.print_string(this._ch);
  1246. } else if (this._ch === '=') { // no whitespace before or after
  1247. this.eatWhitespace();
  1248. this.print_string('=');
  1249. if (whitespaceChar.test(this._ch)) {
  1250. this._ch = '';
  1251. }
  1252. } else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
  1253. this.print_string(' ');
  1254. this.print_string(this._ch);
  1255. } else {
  1256. this.preserveSingleSpace(isAfterSpace);
  1257. this.print_string(this._ch);
  1258. }
  1259. }
  1260. var sweetCode = this._output.get_code(eol);
  1261. return sweetCode;
  1262. };
  1263. module.exports.Beautifier = Beautifier;
  1264. /***/ }),
  1265. /* 17 */
  1266. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  1267. /*jshint node:true */
  1268. /*
  1269. The MIT License (MIT)
  1270. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1271. Permission is hereby granted, free of charge, to any person
  1272. obtaining a copy of this software and associated documentation files
  1273. (the "Software"), to deal in the Software without restriction,
  1274. including without limitation the rights to use, copy, modify, merge,
  1275. publish, distribute, sublicense, and/or sell copies of the Software,
  1276. and to permit persons to whom the Software is furnished to do so,
  1277. subject to the following conditions:
  1278. The above copyright notice and this permission notice shall be
  1279. included in all copies or substantial portions of the Software.
  1280. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1281. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1282. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1283. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1284. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1285. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1286. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1287. SOFTWARE.
  1288. */
  1289. var BaseOptions = __webpack_require__(6).Options;
  1290. function Options(options) {
  1291. BaseOptions.call(this, options, 'css');
  1292. this.selector_separator_newline = this._get_boolean('selector_separator_newline', true);
  1293. this.newline_between_rules = this._get_boolean('newline_between_rules', true);
  1294. var space_around_selector_separator = this._get_boolean('space_around_selector_separator');
  1295. this.space_around_combinator = this._get_boolean('space_around_combinator') || space_around_selector_separator;
  1296. var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
  1297. this.brace_style = 'collapse';
  1298. for (var bs = 0; bs < brace_style_split.length; bs++) {
  1299. if (brace_style_split[bs] !== 'expand') {
  1300. // default to collapse, as only collapse|expand is implemented for now
  1301. this.brace_style = 'collapse';
  1302. } else {
  1303. this.brace_style = brace_style_split[bs];
  1304. }
  1305. }
  1306. }
  1307. Options.prototype = new BaseOptions();
  1308. module.exports.Options = Options;
  1309. /***/ })
  1310. /******/ ]);
  1311. /************************************************************************/
  1312. /******/ // The module cache
  1313. /******/ var __webpack_module_cache__ = {};
  1314. /******/
  1315. /******/ // The require function
  1316. /******/ function __webpack_require__(moduleId) {
  1317. /******/ // Check if module is in cache
  1318. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  1319. /******/ if (cachedModule !== undefined) {
  1320. /******/ return cachedModule.exports;
  1321. /******/ }
  1322. /******/ // Create a new module (and put it into the cache)
  1323. /******/ var module = __webpack_module_cache__[moduleId] = {
  1324. /******/ // no module.id needed
  1325. /******/ // no module.loaded needed
  1326. /******/ exports: {}
  1327. /******/ };
  1328. /******/
  1329. /******/ // Execute the module function
  1330. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  1331. /******/
  1332. /******/ // Return the exports of the module
  1333. /******/ return module.exports;
  1334. /******/ }
  1335. /******/
  1336. /************************************************************************/
  1337. /******/
  1338. /******/ // startup
  1339. /******/ // Load entry module and return exports
  1340. /******/ // This entry module is referenced by other modules so it can't be inlined
  1341. /******/ var __webpack_exports__ = __webpack_require__(15);
  1342. /******/ legacy_beautify_css = __webpack_exports__;
  1343. /******/
  1344. /******/ })()
  1345. ;
  1346. var css_beautify = legacy_beautify_css;
  1347. /* Footer */
  1348. if (typeof define === "function" && define.amd) {
  1349. // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
  1350. define([], function() {
  1351. return {
  1352. css_beautify: css_beautify
  1353. };
  1354. });
  1355. } else if (typeof exports !== "undefined") {
  1356. // Add support for CommonJS. Just put this file somewhere on your require.paths
  1357. // and you will be able to `var html_beautify = require("beautify").html_beautify`.
  1358. exports.css_beautify = css_beautify;
  1359. } else if (typeof window !== "undefined") {
  1360. // If we're running a web page and don't have either of the above, add our one global
  1361. window.css_beautify = css_beautify;
  1362. } else if (typeof global !== "undefined") {
  1363. // If we don't even have window, try global.
  1364. global.css_beautify = css_beautify;
  1365. }
  1366. }());