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