MDL-70301 lib: Upgrade scssphp to 1.4.1
[moodle.git] / lib / scssphp / Formatter / Compressed.php
blobd666a66564d982908c8706818b8c01a583744f4d
1 <?php
3 /**
4 * SCSSPHP
6 * @copyright 2012-2020 Leaf Corcoran
8 * @license http://opensource.org/licenses/MIT MIT
10 * @link http://scssphp.github.io/scssphp
13 namespace ScssPhp\ScssPhp\Formatter;
15 use ScssPhp\ScssPhp\Formatter;
17 /**
18 * Compressed formatter
20 * @author Leaf Corcoran <leafot@gmail.com>
22 class Compressed extends Formatter
24 /**
25 * {@inheritdoc}
27 public function __construct()
29 $this->indentLevel = 0;
30 $this->indentChar = ' ';
31 $this->break = '';
32 $this->open = '{';
33 $this->close = '}';
34 $this->tagSeparator = ',';
35 $this->assignSeparator = ':';
36 $this->keepSemicolons = false;
39 /**
40 * {@inheritdoc}
42 public function blockLines(OutputBlock $block)
44 $inner = $this->indentStr();
46 $glue = $this->break . $inner;
48 foreach ($block->lines as $index => $line) {
49 if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') {
50 unset($block->lines[$index]);
51 } elseif (substr($line, 0, 3) === '/*!') {
52 $block->lines[$index] = '/*' . substr($line, 3);
56 $this->write($inner . implode($glue, $block->lines));
58 if (! empty($block->children)) {
59 $this->write($this->break);
63 /**
64 * Output block selectors
66 * @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
68 protected function blockSelectors(OutputBlock $block)
70 $inner = $this->indentStr();
72 $this->write(
73 $inner
74 . implode(
75 $this->tagSeparator,
76 str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
78 . $this->open . $this->break