beautify-css.js 51 KB

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