@@ -18,48 +18,48 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Block |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - public $type; |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + public $type; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var \Leafo\ScssPhp\Block |
|
| 28 | - */ |
|
| 29 | - public $parent; |
|
| 26 | + /** |
|
| 27 | + * @var \Leafo\ScssPhp\Block |
|
| 28 | + */ |
|
| 29 | + public $parent; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - public $sourceName; |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + public $sourceName; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var integer |
|
| 38 | - */ |
|
| 39 | - public $sourceIndex; |
|
| 36 | + /** |
|
| 37 | + * @var integer |
|
| 38 | + */ |
|
| 39 | + public $sourceIndex; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var integer |
|
| 43 | - */ |
|
| 44 | - public $sourceLine; |
|
| 41 | + /** |
|
| 42 | + * @var integer |
|
| 43 | + */ |
|
| 44 | + public $sourceLine; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var integer |
|
| 48 | - */ |
|
| 49 | - public $sourceColumn; |
|
| 46 | + /** |
|
| 47 | + * @var integer |
|
| 48 | + */ |
|
| 49 | + public $sourceColumn; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var array |
|
| 53 | - */ |
|
| 54 | - public $selectors; |
|
| 51 | + /** |
|
| 52 | + * @var array |
|
| 53 | + */ |
|
| 54 | + public $selectors; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var array |
|
| 58 | - */ |
|
| 59 | - public $comments; |
|
| 56 | + /** |
|
| 57 | + * @var array |
|
| 58 | + */ |
|
| 59 | + public $comments; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var array |
|
| 63 | - */ |
|
| 64 | - public $children; |
|
| 61 | + /** |
|
| 62 | + * @var array |
|
| 63 | + */ |
|
| 64 | + public $children; |
|
| 65 | 65 | } |
@@ -18,23 +18,23 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class Node |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - public $type; |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + public $type; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var integer |
|
| 28 | - */ |
|
| 29 | - public $sourceIndex; |
|
| 26 | + /** |
|
| 27 | + * @var integer |
|
| 28 | + */ |
|
| 29 | + public $sourceIndex; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var integer |
|
| 33 | - */ |
|
| 34 | - public $sourceLine; |
|
| 31 | + /** |
|
| 32 | + * @var integer |
|
| 33 | + */ |
|
| 34 | + public $sourceLine; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var integer |
|
| 38 | - */ |
|
| 39 | - public $sourceColumn; |
|
| 36 | + /** |
|
| 37 | + * @var integer |
|
| 38 | + */ |
|
| 39 | + public $sourceColumn; |
|
| 40 | 40 | } |
@@ -18,23 +18,23 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Environment |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var \Leafo\ScssPhp\Block |
|
| 23 | - */ |
|
| 24 | - public $block; |
|
| 21 | + /** |
|
| 22 | + * @var \Leafo\ScssPhp\Block |
|
| 23 | + */ |
|
| 24 | + public $block; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var \Leafo\ScssPhp\Compiler\Environment |
|
| 28 | - */ |
|
| 29 | - public $parent; |
|
| 26 | + /** |
|
| 27 | + * @var \Leafo\ScssPhp\Compiler\Environment |
|
| 28 | + */ |
|
| 29 | + public $parent; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - public $store; |
|
| 31 | + /** |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + public $store; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var integer |
|
| 38 | - */ |
|
| 39 | - public $depth; |
|
| 36 | + /** |
|
| 37 | + * @var integer |
|
| 38 | + */ |
|
| 39 | + public $depth; |
|
| 40 | 40 | } |
@@ -28,303 +28,303 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class Number extends Node implements \ArrayAccess |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @var integer |
|
| 33 | - */ |
|
| 34 | - static public $precision = 10; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @see http://www.w3.org/TR/2012/WD-css3-values-20120308/ |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - static protected $unitTable = [ |
|
| 42 | - 'in' => [ |
|
| 43 | - 'in' => 1, |
|
| 44 | - 'pc' => 6, |
|
| 45 | - 'pt' => 72, |
|
| 46 | - 'px' => 96, |
|
| 47 | - 'cm' => 2.54, |
|
| 48 | - 'mm' => 25.4, |
|
| 49 | - 'q' => 101.6, |
|
| 50 | - ], |
|
| 51 | - 'turn' => [ |
|
| 52 | - 'deg' => 360, |
|
| 53 | - 'grad' => 400, |
|
| 54 | - 'rad' => 6.28318530717958647692528676, // 2 * M_PI |
|
| 55 | - 'turn' => 1, |
|
| 56 | - ], |
|
| 57 | - 's' => [ |
|
| 58 | - 's' => 1, |
|
| 59 | - 'ms' => 1000, |
|
| 60 | - ], |
|
| 61 | - 'Hz' => [ |
|
| 62 | - 'Hz' => 1, |
|
| 63 | - 'kHz' => 0.001, |
|
| 64 | - ], |
|
| 65 | - 'dpi' => [ |
|
| 66 | - 'dpi' => 1, |
|
| 67 | - 'dpcm' => 2.54, |
|
| 68 | - 'dppx' => 96, |
|
| 69 | - ], |
|
| 70 | - ]; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var integer|float |
|
| 74 | - */ |
|
| 75 | - public $dimension; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - public $units; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Initialize number |
|
| 84 | - * |
|
| 85 | - * @param mixed $dimension |
|
| 86 | - * @param mixed $initialUnit |
|
| 87 | - */ |
|
| 88 | - public function __construct($dimension, $initialUnit) |
|
| 89 | - { |
|
| 90 | - $this->type = Type::T_NUMBER; |
|
| 91 | - $this->dimension = $dimension; |
|
| 92 | - $this->units = is_array($initialUnit) |
|
| 93 | - ? $initialUnit |
|
| 94 | - : ($initialUnit ? [$initialUnit => 1] |
|
| 95 | - : []); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Coerce number to target units |
|
| 100 | - * |
|
| 101 | - * @param array $units |
|
| 102 | - * |
|
| 103 | - * @return \Leafo\ScssPhp\Node\Number |
|
| 104 | - */ |
|
| 105 | - public function coerce($units) |
|
| 106 | - { |
|
| 107 | - if ($this->unitless()) { |
|
| 108 | - return new Number($this->dimension, $units); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $dimension = $this->dimension; |
|
| 112 | - |
|
| 113 | - foreach (static::$unitTable['in'] as $unit => $conv) { |
|
| 114 | - $from = isset($this->units[$unit]) ? $this->units[$unit] : 0; |
|
| 115 | - $to = isset($units[$unit]) ? $units[$unit] : 0; |
|
| 116 | - $factor = pow($conv, $from - $to); |
|
| 117 | - $dimension /= $factor; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return new Number($dimension, $units); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Normalize number |
|
| 125 | - * |
|
| 126 | - * @return \Leafo\ScssPhp\Node\Number |
|
| 127 | - */ |
|
| 128 | - public function normalize() |
|
| 129 | - { |
|
| 130 | - $dimension = $this->dimension; |
|
| 131 | - $units = []; |
|
| 132 | - |
|
| 133 | - $this->normalizeUnits($dimension, $units, 'in'); |
|
| 134 | - |
|
| 135 | - return new Number($dimension, $units); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * {@inheritdoc} |
|
| 140 | - */ |
|
| 141 | - public function offsetExists($offset) |
|
| 142 | - { |
|
| 143 | - if ($offset === -3) { |
|
| 144 | - return $this->sourceColumn !== null; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - if ($offset === -2) { |
|
| 148 | - return $this->sourceLine !== null; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if ($offset === -1 |
|
| 152 | - || $offset === 0 |
|
| 153 | - || $offset === 1 |
|
| 154 | - || $offset === 2 |
|
| 155 | - ) { |
|
| 156 | - return true; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return false; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * {@inheritdoc} |
|
| 164 | - */ |
|
| 165 | - public function offsetGet($offset) |
|
| 166 | - { |
|
| 167 | - switch ($offset) { |
|
| 168 | - case -3: |
|
| 169 | - return $this->sourceColumn; |
|
| 170 | - |
|
| 171 | - case -2: |
|
| 172 | - return $this->sourceLine; |
|
| 173 | - |
|
| 174 | - case -1: |
|
| 175 | - return $this->sourceIndex; |
|
| 176 | - |
|
| 177 | - case 0: |
|
| 178 | - return $this->type; |
|
| 179 | - |
|
| 180 | - case 1: |
|
| 181 | - return $this->dimension; |
|
| 182 | - |
|
| 183 | - case 2: |
|
| 184 | - return $this->units; |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * {@inheritdoc} |
|
| 190 | - */ |
|
| 191 | - public function offsetSet($offset, $value) |
|
| 192 | - { |
|
| 193 | - if ($offset === 1) { |
|
| 194 | - $this->dimension = $value; |
|
| 195 | - } elseif ($offset === 2) { |
|
| 196 | - $this->units = $value; |
|
| 197 | - } elseif ($offset == -1) { |
|
| 198 | - $this->sourceIndex = $value; |
|
| 199 | - } elseif ($offset == -2) { |
|
| 200 | - $this->sourceLine = $value; |
|
| 201 | - } elseif ($offset == -3) { |
|
| 202 | - $this->sourceColumn = $value; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * {@inheritdoc} |
|
| 208 | - */ |
|
| 209 | - public function offsetUnset($offset) |
|
| 210 | - { |
|
| 211 | - if ($offset === 1) { |
|
| 212 | - $this->dimension = null; |
|
| 213 | - } elseif ($offset === 2) { |
|
| 214 | - $this->units = null; |
|
| 215 | - } elseif ($offset === -1) { |
|
| 216 | - $this->sourceIndex = null; |
|
| 217 | - } elseif ($offset === -2) { |
|
| 218 | - $this->sourceLine = null; |
|
| 219 | - } elseif ($offset === -3) { |
|
| 220 | - $this->sourceColumn = null; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Returns true if the number is unitless |
|
| 226 | - * |
|
| 227 | - * @return boolean |
|
| 228 | - */ |
|
| 229 | - public function unitless() |
|
| 230 | - { |
|
| 231 | - return ! array_sum($this->units); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Returns unit(s) as the product of numerator units divided by the product of denominator units |
|
| 236 | - * |
|
| 237 | - * @return string |
|
| 238 | - */ |
|
| 239 | - public function unitStr() |
|
| 240 | - { |
|
| 241 | - $numerators = []; |
|
| 242 | - $denominators = []; |
|
| 243 | - |
|
| 244 | - foreach ($this->units as $unit => $unitSize) { |
|
| 245 | - if ($unitSize > 0) { |
|
| 246 | - $numerators = array_pad($numerators, count($numerators) + $unitSize, $unit); |
|
| 247 | - continue; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - if ($unitSize < 0) { |
|
| 251 | - $denominators = array_pad($denominators, count($denominators) + $unitSize, $unit); |
|
| 252 | - continue; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - return implode('*', $numerators) . (count($denominators) ? '/' . implode('*', $denominators) : ''); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Output number |
|
| 261 | - * |
|
| 262 | - * @param \Leafo\ScssPhp\Compiler $compiler |
|
| 263 | - * |
|
| 264 | - * @return string |
|
| 265 | - */ |
|
| 266 | - public function output(Compiler $compiler = null) |
|
| 267 | - { |
|
| 268 | - $dimension = round($this->dimension, static::$precision); |
|
| 269 | - |
|
| 270 | - $units = array_filter($this->units, function ($unitSize) { |
|
| 271 | - return $unitSize; |
|
| 272 | - }); |
|
| 273 | - |
|
| 274 | - if (count($units) > 1 && array_sum($units) === 0) { |
|
| 275 | - $dimension = $this->dimension; |
|
| 276 | - $units = []; |
|
| 277 | - |
|
| 278 | - $this->normalizeUnits($dimension, $units, 'in'); |
|
| 279 | - |
|
| 280 | - $dimension = round($dimension, static::$precision); |
|
| 281 | - $units = array_filter($units, function ($unitSize) { |
|
| 282 | - return $unitSize; |
|
| 283 | - }); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $unitSize = array_sum($units); |
|
| 287 | - |
|
| 288 | - if ($compiler && ($unitSize > 1 || $unitSize < 0 || count($units) > 1)) { |
|
| 289 | - $compiler->throwError((string) $dimension . $this->unitStr() . " isn't a valid CSS value."); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - reset($units); |
|
| 293 | - $unit = key($units); |
|
| 294 | - $dimension = number_format($dimension, static::$precision, '.', ''); |
|
| 295 | - |
|
| 296 | - return (static::$precision ? rtrim(rtrim($dimension, '0'), '.') : $dimension) . $unit; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * {@inheritdoc} |
|
| 301 | - */ |
|
| 302 | - public function __toString() |
|
| 303 | - { |
|
| 304 | - return $this->output(); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Normalize units |
|
| 309 | - * |
|
| 310 | - * @param integer|float $dimension |
|
| 311 | - * @param array $units |
|
| 312 | - * @param string $baseUnit |
|
| 313 | - */ |
|
| 314 | - private function normalizeUnits(&$dimension, &$units, $baseUnit = 'in') |
|
| 315 | - { |
|
| 316 | - $dimension = $this->dimension; |
|
| 317 | - $units = []; |
|
| 318 | - |
|
| 319 | - foreach ($this->units as $unit => $exp) { |
|
| 320 | - if (isset(static::$unitTable[$baseUnit][$unit])) { |
|
| 321 | - $factor = pow(static::$unitTable[$baseUnit][$unit], $exp); |
|
| 322 | - |
|
| 323 | - $unit = $baseUnit; |
|
| 324 | - $dimension /= $factor; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $units[$unit] = $exp + (isset($units[$unit]) ? $units[$unit] : 0); |
|
| 328 | - } |
|
| 329 | - } |
|
| 31 | + /** |
|
| 32 | + * @var integer |
|
| 33 | + */ |
|
| 34 | + static public $precision = 10; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @see http://www.w3.org/TR/2012/WD-css3-values-20120308/ |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + static protected $unitTable = [ |
|
| 42 | + 'in' => [ |
|
| 43 | + 'in' => 1, |
|
| 44 | + 'pc' => 6, |
|
| 45 | + 'pt' => 72, |
|
| 46 | + 'px' => 96, |
|
| 47 | + 'cm' => 2.54, |
|
| 48 | + 'mm' => 25.4, |
|
| 49 | + 'q' => 101.6, |
|
| 50 | + ], |
|
| 51 | + 'turn' => [ |
|
| 52 | + 'deg' => 360, |
|
| 53 | + 'grad' => 400, |
|
| 54 | + 'rad' => 6.28318530717958647692528676, // 2 * M_PI |
|
| 55 | + 'turn' => 1, |
|
| 56 | + ], |
|
| 57 | + 's' => [ |
|
| 58 | + 's' => 1, |
|
| 59 | + 'ms' => 1000, |
|
| 60 | + ], |
|
| 61 | + 'Hz' => [ |
|
| 62 | + 'Hz' => 1, |
|
| 63 | + 'kHz' => 0.001, |
|
| 64 | + ], |
|
| 65 | + 'dpi' => [ |
|
| 66 | + 'dpi' => 1, |
|
| 67 | + 'dpcm' => 2.54, |
|
| 68 | + 'dppx' => 96, |
|
| 69 | + ], |
|
| 70 | + ]; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var integer|float |
|
| 74 | + */ |
|
| 75 | + public $dimension; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + public $units; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Initialize number |
|
| 84 | + * |
|
| 85 | + * @param mixed $dimension |
|
| 86 | + * @param mixed $initialUnit |
|
| 87 | + */ |
|
| 88 | + public function __construct($dimension, $initialUnit) |
|
| 89 | + { |
|
| 90 | + $this->type = Type::T_NUMBER; |
|
| 91 | + $this->dimension = $dimension; |
|
| 92 | + $this->units = is_array($initialUnit) |
|
| 93 | + ? $initialUnit |
|
| 94 | + : ($initialUnit ? [$initialUnit => 1] |
|
| 95 | + : []); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Coerce number to target units |
|
| 100 | + * |
|
| 101 | + * @param array $units |
|
| 102 | + * |
|
| 103 | + * @return \Leafo\ScssPhp\Node\Number |
|
| 104 | + */ |
|
| 105 | + public function coerce($units) |
|
| 106 | + { |
|
| 107 | + if ($this->unitless()) { |
|
| 108 | + return new Number($this->dimension, $units); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $dimension = $this->dimension; |
|
| 112 | + |
|
| 113 | + foreach (static::$unitTable['in'] as $unit => $conv) { |
|
| 114 | + $from = isset($this->units[$unit]) ? $this->units[$unit] : 0; |
|
| 115 | + $to = isset($units[$unit]) ? $units[$unit] : 0; |
|
| 116 | + $factor = pow($conv, $from - $to); |
|
| 117 | + $dimension /= $factor; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return new Number($dimension, $units); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Normalize number |
|
| 125 | + * |
|
| 126 | + * @return \Leafo\ScssPhp\Node\Number |
|
| 127 | + */ |
|
| 128 | + public function normalize() |
|
| 129 | + { |
|
| 130 | + $dimension = $this->dimension; |
|
| 131 | + $units = []; |
|
| 132 | + |
|
| 133 | + $this->normalizeUnits($dimension, $units, 'in'); |
|
| 134 | + |
|
| 135 | + return new Number($dimension, $units); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * {@inheritdoc} |
|
| 140 | + */ |
|
| 141 | + public function offsetExists($offset) |
|
| 142 | + { |
|
| 143 | + if ($offset === -3) { |
|
| 144 | + return $this->sourceColumn !== null; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + if ($offset === -2) { |
|
| 148 | + return $this->sourceLine !== null; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if ($offset === -1 |
|
| 152 | + || $offset === 0 |
|
| 153 | + || $offset === 1 |
|
| 154 | + || $offset === 2 |
|
| 155 | + ) { |
|
| 156 | + return true; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return false; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * {@inheritdoc} |
|
| 164 | + */ |
|
| 165 | + public function offsetGet($offset) |
|
| 166 | + { |
|
| 167 | + switch ($offset) { |
|
| 168 | + case -3: |
|
| 169 | + return $this->sourceColumn; |
|
| 170 | + |
|
| 171 | + case -2: |
|
| 172 | + return $this->sourceLine; |
|
| 173 | + |
|
| 174 | + case -1: |
|
| 175 | + return $this->sourceIndex; |
|
| 176 | + |
|
| 177 | + case 0: |
|
| 178 | + return $this->type; |
|
| 179 | + |
|
| 180 | + case 1: |
|
| 181 | + return $this->dimension; |
|
| 182 | + |
|
| 183 | + case 2: |
|
| 184 | + return $this->units; |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * {@inheritdoc} |
|
| 190 | + */ |
|
| 191 | + public function offsetSet($offset, $value) |
|
| 192 | + { |
|
| 193 | + if ($offset === 1) { |
|
| 194 | + $this->dimension = $value; |
|
| 195 | + } elseif ($offset === 2) { |
|
| 196 | + $this->units = $value; |
|
| 197 | + } elseif ($offset == -1) { |
|
| 198 | + $this->sourceIndex = $value; |
|
| 199 | + } elseif ($offset == -2) { |
|
| 200 | + $this->sourceLine = $value; |
|
| 201 | + } elseif ($offset == -3) { |
|
| 202 | + $this->sourceColumn = $value; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * {@inheritdoc} |
|
| 208 | + */ |
|
| 209 | + public function offsetUnset($offset) |
|
| 210 | + { |
|
| 211 | + if ($offset === 1) { |
|
| 212 | + $this->dimension = null; |
|
| 213 | + } elseif ($offset === 2) { |
|
| 214 | + $this->units = null; |
|
| 215 | + } elseif ($offset === -1) { |
|
| 216 | + $this->sourceIndex = null; |
|
| 217 | + } elseif ($offset === -2) { |
|
| 218 | + $this->sourceLine = null; |
|
| 219 | + } elseif ($offset === -3) { |
|
| 220 | + $this->sourceColumn = null; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Returns true if the number is unitless |
|
| 226 | + * |
|
| 227 | + * @return boolean |
|
| 228 | + */ |
|
| 229 | + public function unitless() |
|
| 230 | + { |
|
| 231 | + return ! array_sum($this->units); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Returns unit(s) as the product of numerator units divided by the product of denominator units |
|
| 236 | + * |
|
| 237 | + * @return string |
|
| 238 | + */ |
|
| 239 | + public function unitStr() |
|
| 240 | + { |
|
| 241 | + $numerators = []; |
|
| 242 | + $denominators = []; |
|
| 243 | + |
|
| 244 | + foreach ($this->units as $unit => $unitSize) { |
|
| 245 | + if ($unitSize > 0) { |
|
| 246 | + $numerators = array_pad($numerators, count($numerators) + $unitSize, $unit); |
|
| 247 | + continue; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + if ($unitSize < 0) { |
|
| 251 | + $denominators = array_pad($denominators, count($denominators) + $unitSize, $unit); |
|
| 252 | + continue; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + return implode('*', $numerators) . (count($denominators) ? '/' . implode('*', $denominators) : ''); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Output number |
|
| 261 | + * |
|
| 262 | + * @param \Leafo\ScssPhp\Compiler $compiler |
|
| 263 | + * |
|
| 264 | + * @return string |
|
| 265 | + */ |
|
| 266 | + public function output(Compiler $compiler = null) |
|
| 267 | + { |
|
| 268 | + $dimension = round($this->dimension, static::$precision); |
|
| 269 | + |
|
| 270 | + $units = array_filter($this->units, function ($unitSize) { |
|
| 271 | + return $unitSize; |
|
| 272 | + }); |
|
| 273 | + |
|
| 274 | + if (count($units) > 1 && array_sum($units) === 0) { |
|
| 275 | + $dimension = $this->dimension; |
|
| 276 | + $units = []; |
|
| 277 | + |
|
| 278 | + $this->normalizeUnits($dimension, $units, 'in'); |
|
| 279 | + |
|
| 280 | + $dimension = round($dimension, static::$precision); |
|
| 281 | + $units = array_filter($units, function ($unitSize) { |
|
| 282 | + return $unitSize; |
|
| 283 | + }); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $unitSize = array_sum($units); |
|
| 287 | + |
|
| 288 | + if ($compiler && ($unitSize > 1 || $unitSize < 0 || count($units) > 1)) { |
|
| 289 | + $compiler->throwError((string) $dimension . $this->unitStr() . " isn't a valid CSS value."); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + reset($units); |
|
| 293 | + $unit = key($units); |
|
| 294 | + $dimension = number_format($dimension, static::$precision, '.', ''); |
|
| 295 | + |
|
| 296 | + return (static::$precision ? rtrim(rtrim($dimension, '0'), '.') : $dimension) . $unit; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * {@inheritdoc} |
|
| 301 | + */ |
|
| 302 | + public function __toString() |
|
| 303 | + { |
|
| 304 | + return $this->output(); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Normalize units |
|
| 309 | + * |
|
| 310 | + * @param integer|float $dimension |
|
| 311 | + * @param array $units |
|
| 312 | + * @param string $baseUnit |
|
| 313 | + */ |
|
| 314 | + private function normalizeUnits(&$dimension, &$units, $baseUnit = 'in') |
|
| 315 | + { |
|
| 316 | + $dimension = $this->dimension; |
|
| 317 | + $units = []; |
|
| 318 | + |
|
| 319 | + foreach ($this->units as $unit => $exp) { |
|
| 320 | + if (isset(static::$unitTable[$baseUnit][$unit])) { |
|
| 321 | + $factor = pow(static::$unitTable[$baseUnit][$unit], $exp); |
|
| 322 | + |
|
| 323 | + $unit = $baseUnit; |
|
| 324 | + $dimension /= $factor; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $units[$unit] = $exp + (isset($units[$unit]) ? $units[$unit] : 0); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | 330 | } |
@@ -21,181 +21,181 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Nested extends Formatter |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var integer |
|
| 26 | - */ |
|
| 27 | - private $depth; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * {@inheritdoc} |
|
| 31 | - */ |
|
| 32 | - public function __construct() |
|
| 33 | - { |
|
| 34 | - $this->indentLevel = 0; |
|
| 35 | - $this->indentChar = ' '; |
|
| 36 | - $this->break = "\n"; |
|
| 37 | - $this->open = ' {'; |
|
| 38 | - $this->close = ' }'; |
|
| 39 | - $this->tagSeparator = ', '; |
|
| 40 | - $this->assignSeparator = ': '; |
|
| 41 | - $this->keepSemicolons = true; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * {@inheritdoc} |
|
| 46 | - */ |
|
| 47 | - protected function indentStr() |
|
| 48 | - { |
|
| 49 | - $n = $this->depth - 1; |
|
| 50 | - |
|
| 51 | - return str_repeat($this->indentChar, max($this->indentLevel + $n, 0)); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * {@inheritdoc} |
|
| 56 | - */ |
|
| 57 | - protected function blockLines(OutputBlock $block) |
|
| 58 | - { |
|
| 59 | - $inner = $this->indentStr(); |
|
| 60 | - |
|
| 61 | - $glue = $this->break . $inner; |
|
| 62 | - |
|
| 63 | - foreach ($block->lines as $index => $line) { |
|
| 64 | - if (substr($line, 0, 2) === '/*') { |
|
| 65 | - $block->lines[$index] = preg_replace('/(\r|\n)+/', $glue, $line); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $this->write($inner . implode($glue, $block->lines)); |
|
| 70 | - |
|
| 71 | - if (! empty($block->children)) { |
|
| 72 | - $this->write($this->break); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * {@inheritdoc} |
|
| 78 | - */ |
|
| 79 | - protected function blockSelectors(OutputBlock $block) |
|
| 80 | - { |
|
| 81 | - $inner = $this->indentStr(); |
|
| 82 | - |
|
| 83 | - $this->write($inner |
|
| 84 | - . implode($this->tagSeparator, $block->selectors) |
|
| 85 | - . $this->open . $this->break); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * {@inheritdoc} |
|
| 90 | - */ |
|
| 91 | - protected function blockChildren(OutputBlock $block) |
|
| 92 | - { |
|
| 93 | - foreach ($block->children as $i => $child) { |
|
| 94 | - $this->block($child); |
|
| 95 | - |
|
| 96 | - if ($i < count($block->children) - 1) { |
|
| 97 | - $this->write($this->break); |
|
| 98 | - |
|
| 99 | - if (isset($block->children[$i + 1])) { |
|
| 100 | - $next = $block->children[$i + 1]; |
|
| 101 | - |
|
| 102 | - if ($next->depth === max($block->depth, 1) && $child->depth >= $next->depth) { |
|
| 103 | - $this->write($this->break); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * {@inheritdoc} |
|
| 112 | - */ |
|
| 113 | - protected function block(OutputBlock $block) |
|
| 114 | - { |
|
| 115 | - if ($block->type === 'root') { |
|
| 116 | - $this->adjustAllChildren($block); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if (empty($block->lines) && empty($block->children)) { |
|
| 120 | - return; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $this->currentBlock = $block; |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - $this->depth = $block->depth; |
|
| 127 | - |
|
| 128 | - if (! empty($block->selectors)) { |
|
| 129 | - $this->blockSelectors($block); |
|
| 130 | - |
|
| 131 | - $this->indentLevel++; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if (! empty($block->lines)) { |
|
| 135 | - $this->blockLines($block); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if (! empty($block->children)) { |
|
| 139 | - $this->blockChildren($block); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - if (! empty($block->selectors)) { |
|
| 143 | - $this->indentLevel--; |
|
| 144 | - |
|
| 145 | - $this->write($this->close); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - if ($block->type === 'root') { |
|
| 149 | - $this->write($this->break); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Adjust the depths of all children, depth first |
|
| 155 | - * |
|
| 156 | - * @param \Leafo\ScssPhp\Formatter\OutputBlock $block |
|
| 157 | - */ |
|
| 158 | - private function adjustAllChildren(OutputBlock $block) |
|
| 159 | - { |
|
| 160 | - // flatten empty nested blocks |
|
| 161 | - $children = []; |
|
| 162 | - |
|
| 163 | - foreach ($block->children as $i => $child) { |
|
| 164 | - if (empty($child->lines) && empty($child->children)) { |
|
| 165 | - if (isset($block->children[$i + 1])) { |
|
| 166 | - $block->children[$i + 1]->depth = $child->depth; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - continue; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - $children[] = $child; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $count = count($children); |
|
| 176 | - |
|
| 177 | - for ($i = 0; $i < $count; $i++) { |
|
| 178 | - $depth = $children[$i]->depth; |
|
| 179 | - $j = $i + 1; |
|
| 180 | - |
|
| 181 | - if (isset($children[$j]) && $depth < $children[$j]->depth) { |
|
| 182 | - $childDepth = $children[$j]->depth; |
|
| 183 | - |
|
| 184 | - for (; $j < $count; $j++) { |
|
| 185 | - if ($depth < $children[$j]->depth && $childDepth >= $children[$j]->depth) { |
|
| 186 | - $children[$j]->depth = $depth + 1; |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - $block->children = $children; |
|
| 193 | - |
|
| 194 | - // make relative to parent |
|
| 195 | - foreach ($block->children as $child) { |
|
| 196 | - $this->adjustAllChildren($child); |
|
| 197 | - |
|
| 198 | - $child->depth = $child->depth - $block->depth; |
|
| 199 | - } |
|
| 200 | - } |
|
| 24 | + /** |
|
| 25 | + * @var integer |
|
| 26 | + */ |
|
| 27 | + private $depth; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * {@inheritdoc} |
|
| 31 | + */ |
|
| 32 | + public function __construct() |
|
| 33 | + { |
|
| 34 | + $this->indentLevel = 0; |
|
| 35 | + $this->indentChar = ' '; |
|
| 36 | + $this->break = "\n"; |
|
| 37 | + $this->open = ' {'; |
|
| 38 | + $this->close = ' }'; |
|
| 39 | + $this->tagSeparator = ', '; |
|
| 40 | + $this->assignSeparator = ': '; |
|
| 41 | + $this->keepSemicolons = true; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * {@inheritdoc} |
|
| 46 | + */ |
|
| 47 | + protected function indentStr() |
|
| 48 | + { |
|
| 49 | + $n = $this->depth - 1; |
|
| 50 | + |
|
| 51 | + return str_repeat($this->indentChar, max($this->indentLevel + $n, 0)); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * {@inheritdoc} |
|
| 56 | + */ |
|
| 57 | + protected function blockLines(OutputBlock $block) |
|
| 58 | + { |
|
| 59 | + $inner = $this->indentStr(); |
|
| 60 | + |
|
| 61 | + $glue = $this->break . $inner; |
|
| 62 | + |
|
| 63 | + foreach ($block->lines as $index => $line) { |
|
| 64 | + if (substr($line, 0, 2) === '/*') { |
|
| 65 | + $block->lines[$index] = preg_replace('/(\r|\n)+/', $glue, $line); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $this->write($inner . implode($glue, $block->lines)); |
|
| 70 | + |
|
| 71 | + if (! empty($block->children)) { |
|
| 72 | + $this->write($this->break); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * {@inheritdoc} |
|
| 78 | + */ |
|
| 79 | + protected function blockSelectors(OutputBlock $block) |
|
| 80 | + { |
|
| 81 | + $inner = $this->indentStr(); |
|
| 82 | + |
|
| 83 | + $this->write($inner |
|
| 84 | + . implode($this->tagSeparator, $block->selectors) |
|
| 85 | + . $this->open . $this->break); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * {@inheritdoc} |
|
| 90 | + */ |
|
| 91 | + protected function blockChildren(OutputBlock $block) |
|
| 92 | + { |
|
| 93 | + foreach ($block->children as $i => $child) { |
|
| 94 | + $this->block($child); |
|
| 95 | + |
|
| 96 | + if ($i < count($block->children) - 1) { |
|
| 97 | + $this->write($this->break); |
|
| 98 | + |
|
| 99 | + if (isset($block->children[$i + 1])) { |
|
| 100 | + $next = $block->children[$i + 1]; |
|
| 101 | + |
|
| 102 | + if ($next->depth === max($block->depth, 1) && $child->depth >= $next->depth) { |
|
| 103 | + $this->write($this->break); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * {@inheritdoc} |
|
| 112 | + */ |
|
| 113 | + protected function block(OutputBlock $block) |
|
| 114 | + { |
|
| 115 | + if ($block->type === 'root') { |
|
| 116 | + $this->adjustAllChildren($block); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if (empty($block->lines) && empty($block->children)) { |
|
| 120 | + return; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $this->currentBlock = $block; |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + $this->depth = $block->depth; |
|
| 127 | + |
|
| 128 | + if (! empty($block->selectors)) { |
|
| 129 | + $this->blockSelectors($block); |
|
| 130 | + |
|
| 131 | + $this->indentLevel++; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if (! empty($block->lines)) { |
|
| 135 | + $this->blockLines($block); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if (! empty($block->children)) { |
|
| 139 | + $this->blockChildren($block); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + if (! empty($block->selectors)) { |
|
| 143 | + $this->indentLevel--; |
|
| 144 | + |
|
| 145 | + $this->write($this->close); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + if ($block->type === 'root') { |
|
| 149 | + $this->write($this->break); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Adjust the depths of all children, depth first |
|
| 155 | + * |
|
| 156 | + * @param \Leafo\ScssPhp\Formatter\OutputBlock $block |
|
| 157 | + */ |
|
| 158 | + private function adjustAllChildren(OutputBlock $block) |
|
| 159 | + { |
|
| 160 | + // flatten empty nested blocks |
|
| 161 | + $children = []; |
|
| 162 | + |
|
| 163 | + foreach ($block->children as $i => $child) { |
|
| 164 | + if (empty($child->lines) && empty($child->children)) { |
|
| 165 | + if (isset($block->children[$i + 1])) { |
|
| 166 | + $block->children[$i + 1]->depth = $child->depth; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + continue; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + $children[] = $child; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $count = count($children); |
|
| 176 | + |
|
| 177 | + for ($i = 0; $i < $count; $i++) { |
|
| 178 | + $depth = $children[$i]->depth; |
|
| 179 | + $j = $i + 1; |
|
| 180 | + |
|
| 181 | + if (isset($children[$j]) && $depth < $children[$j]->depth) { |
|
| 182 | + $childDepth = $children[$j]->depth; |
|
| 183 | + |
|
| 184 | + for (; $j < $count; $j++) { |
|
| 185 | + if ($depth < $children[$j]->depth && $childDepth >= $children[$j]->depth) { |
|
| 186 | + $children[$j]->depth = $depth + 1; |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + $block->children = $children; |
|
| 193 | + |
|
| 194 | + // make relative to parent |
|
| 195 | + foreach ($block->children as $child) { |
|
| 196 | + $this->adjustAllChildren($child); |
|
| 197 | + |
|
| 198 | + $child->depth = $child->depth - $block->depth; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | 201 | } |
@@ -21,48 +21,48 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Expanded extends Formatter |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * {@inheritdoc} |
|
| 26 | - */ |
|
| 27 | - public function __construct() |
|
| 28 | - { |
|
| 29 | - $this->indentLevel = 0; |
|
| 30 | - $this->indentChar = ' '; |
|
| 31 | - $this->break = "\n"; |
|
| 32 | - $this->open = ' {'; |
|
| 33 | - $this->close = '}'; |
|
| 34 | - $this->tagSeparator = ', '; |
|
| 35 | - $this->assignSeparator = ': '; |
|
| 36 | - $this->keepSemicolons = true; |
|
| 37 | - } |
|
| 24 | + /** |
|
| 25 | + * {@inheritdoc} |
|
| 26 | + */ |
|
| 27 | + public function __construct() |
|
| 28 | + { |
|
| 29 | + $this->indentLevel = 0; |
|
| 30 | + $this->indentChar = ' '; |
|
| 31 | + $this->break = "\n"; |
|
| 32 | + $this->open = ' {'; |
|
| 33 | + $this->close = '}'; |
|
| 34 | + $this->tagSeparator = ', '; |
|
| 35 | + $this->assignSeparator = ': '; |
|
| 36 | + $this->keepSemicolons = true; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * {@inheritdoc} |
|
| 41 | - */ |
|
| 42 | - protected function indentStr() |
|
| 43 | - { |
|
| 44 | - return str_repeat($this->indentChar, $this->indentLevel); |
|
| 45 | - } |
|
| 39 | + /** |
|
| 40 | + * {@inheritdoc} |
|
| 41 | + */ |
|
| 42 | + protected function indentStr() |
|
| 43 | + { |
|
| 44 | + return str_repeat($this->indentChar, $this->indentLevel); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * {@inheritdoc} |
|
| 49 | - */ |
|
| 50 | - protected function blockLines(OutputBlock $block) |
|
| 51 | - { |
|
| 52 | - $inner = $this->indentStr(); |
|
| 47 | + /** |
|
| 48 | + * {@inheritdoc} |
|
| 49 | + */ |
|
| 50 | + protected function blockLines(OutputBlock $block) |
|
| 51 | + { |
|
| 52 | + $inner = $this->indentStr(); |
|
| 53 | 53 | |
| 54 | - $glue = $this->break . $inner; |
|
| 54 | + $glue = $this->break . $inner; |
|
| 55 | 55 | |
| 56 | - foreach ($block->lines as $index => $line) { |
|
| 57 | - if (substr($line, 0, 2) === '/*') { |
|
| 58 | - $block->lines[$index] = preg_replace('/(\r|\n)+/', $glue, $line); |
|
| 59 | - } |
|
| 60 | - } |
|
| 56 | + foreach ($block->lines as $index => $line) { |
|
| 57 | + if (substr($line, 0, 2) === '/*') { |
|
| 58 | + $block->lines[$index] = preg_replace('/(\r|\n)+/', $glue, $line); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $this->write($inner . implode($glue, $block->lines)); |
|
| 62 | + $this->write($inner . implode($glue, $block->lines)); |
|
| 63 | 63 | |
| 64 | - if (empty($block->selectors) || ! empty($block->children)) { |
|
| 65 | - $this->write($this->break); |
|
| 66 | - } |
|
| 67 | - } |
|
| 64 | + if (empty($block->selectors) || ! empty($block->children)) { |
|
| 65 | + $this->write($this->break); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -21,101 +21,101 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Debug extends Formatter |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * {@inheritdoc} |
|
| 26 | - */ |
|
| 27 | - public function __construct() |
|
| 28 | - { |
|
| 29 | - $this->indentLevel = 0; |
|
| 30 | - $this->indentChar = ''; |
|
| 31 | - $this->break = "\n"; |
|
| 32 | - $this->open = ' {'; |
|
| 33 | - $this->close = ' }'; |
|
| 34 | - $this->tagSeparator = ', '; |
|
| 35 | - $this->assignSeparator = ': '; |
|
| 36 | - $this->keepSemicolons = true; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * {@inheritdoc} |
|
| 41 | - */ |
|
| 42 | - protected function indentStr() |
|
| 43 | - { |
|
| 44 | - return str_repeat(' ', $this->indentLevel); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * {@inheritdoc} |
|
| 49 | - */ |
|
| 50 | - protected function blockLines(OutputBlock $block) |
|
| 51 | - { |
|
| 52 | - $indent = $this->indentStr(); |
|
| 53 | - |
|
| 54 | - if (empty($block->lines)) { |
|
| 55 | - $this->write("{$indent}block->lines: []\n"); |
|
| 56 | - |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - foreach ($block->lines as $index => $line) { |
|
| 61 | - $this->write("{$indent}block->lines[{$index}]: $line\n"); |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * {@inheritdoc} |
|
| 67 | - */ |
|
| 68 | - protected function blockSelectors(OutputBlock $block) |
|
| 69 | - { |
|
| 70 | - $indent = $this->indentStr(); |
|
| 71 | - |
|
| 72 | - if (empty($block->selectors)) { |
|
| 73 | - $this->write("{$indent}block->selectors: []\n"); |
|
| 74 | - |
|
| 75 | - return; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - foreach ($block->selectors as $index => $selector) { |
|
| 79 | - $this->write("{$indent}block->selectors[{$index}]: $selector\n"); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * {@inheritdoc} |
|
| 85 | - */ |
|
| 86 | - protected function blockChildren(OutputBlock $block) |
|
| 87 | - { |
|
| 88 | - $indent = $this->indentStr(); |
|
| 89 | - |
|
| 90 | - if (empty($block->children)) { |
|
| 91 | - $this->write("{$indent}block->children: []\n"); |
|
| 92 | - |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $this->indentLevel++; |
|
| 97 | - |
|
| 98 | - foreach ($block->children as $i => $child) { |
|
| 99 | - $this->block($child); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $this->indentLevel--; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * {@inheritdoc} |
|
| 107 | - */ |
|
| 108 | - protected function block(OutputBlock $block) |
|
| 109 | - { |
|
| 110 | - $indent = $this->indentStr(); |
|
| 111 | - |
|
| 112 | - $this->write("{$indent}block->type: {$block->type}\n" . |
|
| 113 | - "{$indent}block->depth: {$block->depth}\n"); |
|
| 114 | - |
|
| 115 | - $this->currentBlock = $block; |
|
| 116 | - |
|
| 117 | - $this->blockSelectors($block); |
|
| 118 | - $this->blockLines($block); |
|
| 119 | - $this->blockChildren($block); |
|
| 120 | - } |
|
| 24 | + /** |
|
| 25 | + * {@inheritdoc} |
|
| 26 | + */ |
|
| 27 | + public function __construct() |
|
| 28 | + { |
|
| 29 | + $this->indentLevel = 0; |
|
| 30 | + $this->indentChar = ''; |
|
| 31 | + $this->break = "\n"; |
|
| 32 | + $this->open = ' {'; |
|
| 33 | + $this->close = ' }'; |
|
| 34 | + $this->tagSeparator = ', '; |
|
| 35 | + $this->assignSeparator = ': '; |
|
| 36 | + $this->keepSemicolons = true; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * {@inheritdoc} |
|
| 41 | + */ |
|
| 42 | + protected function indentStr() |
|
| 43 | + { |
|
| 44 | + return str_repeat(' ', $this->indentLevel); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * {@inheritdoc} |
|
| 49 | + */ |
|
| 50 | + protected function blockLines(OutputBlock $block) |
|
| 51 | + { |
|
| 52 | + $indent = $this->indentStr(); |
|
| 53 | + |
|
| 54 | + if (empty($block->lines)) { |
|
| 55 | + $this->write("{$indent}block->lines: []\n"); |
|
| 56 | + |
|
| 57 | + return; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + foreach ($block->lines as $index => $line) { |
|
| 61 | + $this->write("{$indent}block->lines[{$index}]: $line\n"); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * {@inheritdoc} |
|
| 67 | + */ |
|
| 68 | + protected function blockSelectors(OutputBlock $block) |
|
| 69 | + { |
|
| 70 | + $indent = $this->indentStr(); |
|
| 71 | + |
|
| 72 | + if (empty($block->selectors)) { |
|
| 73 | + $this->write("{$indent}block->selectors: []\n"); |
|
| 74 | + |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + foreach ($block->selectors as $index => $selector) { |
|
| 79 | + $this->write("{$indent}block->selectors[{$index}]: $selector\n"); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * {@inheritdoc} |
|
| 85 | + */ |
|
| 86 | + protected function blockChildren(OutputBlock $block) |
|
| 87 | + { |
|
| 88 | + $indent = $this->indentStr(); |
|
| 89 | + |
|
| 90 | + if (empty($block->children)) { |
|
| 91 | + $this->write("{$indent}block->children: []\n"); |
|
| 92 | + |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $this->indentLevel++; |
|
| 97 | + |
|
| 98 | + foreach ($block->children as $i => $child) { |
|
| 99 | + $this->block($child); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $this->indentLevel--; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * {@inheritdoc} |
|
| 107 | + */ |
|
| 108 | + protected function block(OutputBlock $block) |
|
| 109 | + { |
|
| 110 | + $indent = $this->indentStr(); |
|
| 111 | + |
|
| 112 | + $this->write("{$indent}block->type: {$block->type}\n" . |
|
| 113 | + "{$indent}block->depth: {$block->depth}\n"); |
|
| 114 | + |
|
| 115 | + $this->currentBlock = $block; |
|
| 116 | + |
|
| 117 | + $this->blockSelectors($block); |
|
| 118 | + $this->blockLines($block); |
|
| 119 | + $this->blockChildren($block); |
|
| 120 | + } |
|
| 121 | 121 | } |
@@ -18,48 +18,48 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class OutputBlock |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - public $type; |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + public $type; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var integer |
|
| 28 | - */ |
|
| 29 | - public $depth; |
|
| 26 | + /** |
|
| 27 | + * @var integer |
|
| 28 | + */ |
|
| 29 | + public $depth; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - public $selectors; |
|
| 31 | + /** |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + public $selectors; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - public $lines; |
|
| 36 | + /** |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + public $lines; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - public $children; |
|
| 41 | + /** |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + public $children; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var \Leafo\ScssPhp\Formatter\OutputBlock |
|
| 48 | - */ |
|
| 49 | - public $parent; |
|
| 46 | + /** |
|
| 47 | + * @var \Leafo\ScssPhp\Formatter\OutputBlock |
|
| 48 | + */ |
|
| 49 | + public $parent; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - public $sourceName; |
|
| 51 | + /** |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + public $sourceName; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var integer |
|
| 58 | - */ |
|
| 59 | - public $sourceLine; |
|
| 56 | + /** |
|
| 57 | + * @var integer |
|
| 58 | + */ |
|
| 59 | + public $sourceLine; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var integer |
|
| 63 | - */ |
|
| 64 | - public $sourceColumn; |
|
| 61 | + /** |
|
| 62 | + * @var integer |
|
| 63 | + */ |
|
| 64 | + public $sourceColumn; |
|
| 65 | 65 | } |
@@ -21,42 +21,42 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Compressed extends Formatter |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * {@inheritdoc} |
|
| 26 | - */ |
|
| 27 | - public function __construct() |
|
| 28 | - { |
|
| 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; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * {@inheritdoc} |
|
| 41 | - */ |
|
| 42 | - public function blockLines(OutputBlock $block) |
|
| 43 | - { |
|
| 44 | - $inner = $this->indentStr(); |
|
| 45 | - |
|
| 46 | - $glue = $this->break . $inner; |
|
| 47 | - |
|
| 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); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $this->write($inner . implode($glue, $block->lines)); |
|
| 57 | - |
|
| 58 | - if (! empty($block->children)) { |
|
| 59 | - $this->write($this->break); |
|
| 60 | - } |
|
| 61 | - } |
|
| 24 | + /** |
|
| 25 | + * {@inheritdoc} |
|
| 26 | + */ |
|
| 27 | + public function __construct() |
|
| 28 | + { |
|
| 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; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * {@inheritdoc} |
|
| 41 | + */ |
|
| 42 | + public function blockLines(OutputBlock $block) |
|
| 43 | + { |
|
| 44 | + $inner = $this->indentStr(); |
|
| 45 | + |
|
| 46 | + $glue = $this->break . $inner; |
|
| 47 | + |
|
| 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); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $this->write($inner . implode($glue, $block->lines)); |
|
| 57 | + |
|
| 58 | + if (! empty($block->children)) { |
|
| 59 | + $this->write($this->break); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | } |