Update composer dependencies

This commit is contained in:
Kijin Sung 2016-03-22 11:26:00 +09:00
parent 06f5151f8f
commit 365d7cdba9
58 changed files with 1245 additions and 5987 deletions

View file

@ -12,7 +12,7 @@
namespace Leafo\ScssPhp\Base;
/**
* Range class
* Range
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/

View file

@ -12,7 +12,7 @@
namespace Leafo\ScssPhp;
/**
* SCSS block
* Block
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/
@ -31,12 +31,17 @@ class Block
/**
* @var integer
*/
public $sourcePosition;
public $sourceIndex;
/**
* @var integer
*/
public $sourceIndex;
public $sourceLine;
/**
* @var integer
*/
public $sourceColumn;
/**
* @var array

View file

@ -25,7 +25,7 @@ class Colors
*
* @var array
*/
public static $cssColors = array(
public static $cssColors = [
'aliceblue' => '240,248,255',
'antiquewhite' => '250,235,215',
'aqua' => '0,255,255',
@ -145,6 +145,7 @@ class Colors
'plum' => '221,160,221',
'powderblue' => '176,224,230',
'purple' => '128,0,128',
'rebeccapurple' => '102,51,153',
'red' => '255,0,0',
'rosybrown' => '188,143,143',
'royalblue' => '65,105,225',
@ -173,6 +174,6 @@ class Colors
'white' => '255,255,255',
'whitesmoke' => '245,245,245',
'yellow' => '255,255,0',
'yellowgreen' => '154,205,50'
);
'yellowgreen' => '154,205,50',
];
}

File diff suppressed because it is too large Load diff

View file

@ -11,10 +11,8 @@
namespace Leafo\ScssPhp\Compiler;
use Leafo\ScssPhp\Block;
/**
* SCSS compiler environment
* Compiler environment
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/

View file

@ -0,0 +1,21 @@
<?php
/**
* SCSSPHP
*
* @copyright 2012-2015 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
* @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp\Exception;
/**
* Compiler exception
*
* @author Oleksandr Savchenko <traveltino@gmail.com>
*/
class CompilerException extends \Exception
{
}

View file

@ -0,0 +1,21 @@
<?php
/**
* SCSSPHP
*
* @copyright 2012-2015 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
* @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp\Exception;
/**
* Parser Exception
*
* @author Oleksandr Savchenko <traveltino@gmail.com>
*/
class ParserException extends \Exception
{
}

View file

@ -0,0 +1,21 @@
<?php
/**
* SCSSPHP
*
* @copyright 2012-2015 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
* @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp\Exception;
/**
* Server Exception
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/
class ServerException extends \Exception
{
}

View file

@ -14,7 +14,7 @@ namespace Leafo\ScssPhp;
use Leafo\ScssPhp\Formatter\OutputBlock;
/**
* SCSS base formatter
* Base formatter
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
@ -55,6 +55,11 @@ abstract class Formatter
*/
public $assignSeparator;
/**
* @var boolea
*/
public $keepSemicolons;
/**
* Initialize formatter
*
@ -96,6 +101,15 @@ abstract class Formatter
*/
public function stripSemicolon(&$lines)
{
if ($this->keepSemicolons) {
return;
}
if (($count = count($lines))
&& substr($lines[$count - 1], -1) === ';'
) {
$lines[$count - 1] = substr($lines[$count - 1], 0, -1);
}
}
/**

View file

@ -14,7 +14,7 @@ namespace Leafo\ScssPhp\Formatter;
use Leafo\ScssPhp\Formatter;
/**
* SCSS compact formatter
* Compact formatter
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
@ -32,6 +32,7 @@ class Compact extends Formatter
$this->close = "}\n\n";
$this->tagSeparator = ',';
$this->assignSeparator = ':';
$this->keepSemicolons = true;
}
/**

View file

@ -15,7 +15,7 @@ use Leafo\ScssPhp\Formatter;
use Leafo\ScssPhp\Formatter\OutputBlock;
/**
* SCSS compressed formatter
* Compressed formatter
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
@ -33,18 +33,7 @@ class Compressed extends Formatter
$this->close = '}';
$this->tagSeparator = ',';
$this->assignSeparator = ':';
}
/**
* {@inheritdoc}
*/
public function stripSemicolon(&$lines)
{
if (($count = count($lines))
&& substr($lines[$count - 1], -1) === ';'
) {
$lines[$count - 1] = substr($lines[$count - 1], 0, -1);
}
$this->keepSemicolons = false;
}
/**
@ -70,15 +59,4 @@ class Compressed extends Formatter
echo $this->break;
}
}
/**
* {@inherit}
*/
public function format(OutputBlock $block)
{
return parent::format($block);
// TODO: we need to fix the 2 "compressed" tests where the "close" is applied
return trim(str_replace(';}', '}', parent::format($block)));
}
}

View file

@ -15,7 +15,7 @@ use Leafo\ScssPhp\Formatter;
use Leafo\ScssPhp\Formatter\OutputBlock;
/**
* SCSS crunched formatter
* Crunched formatter
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/
@ -33,18 +33,7 @@ class Crunched extends Formatter
$this->close = '}';
$this->tagSeparator = ',';
$this->assignSeparator = ':';
}
/**
* {@inheritdoc}
*/
public function stripSemicolon(&$lines)
{
if (($count = count($lines))
&& substr($lines[$count - 1], -1) === ';'
) {
$lines[$count - 1] = substr($lines[$count - 1], 0, -1);
}
$this->keepSemicolons = false;
}
/**

View file

@ -15,7 +15,7 @@ use Leafo\ScssPhp\Formatter;
use Leafo\ScssPhp\Formatter\OutputBlock;
/**
* SCSS debug formatter
* Debug formatter
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/
@ -33,6 +33,7 @@ class Debug extends Formatter
$this->close = ' }';
$this->tagSeparator = ', ';
$this->assignSeparator = ': ';
$this->keepSemicolons = true;
}
/**

View file

@ -15,7 +15,7 @@ use Leafo\ScssPhp\Formatter;
use Leafo\ScssPhp\Formatter\OutputBlock;
/**
* SCSS expanded formatter
* Expanded formatter
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
@ -33,6 +33,7 @@ class Expanded extends Formatter
$this->close = '}';
$this->tagSeparator = ', ';
$this->assignSeparator = ': ';
$this->keepSemicolons = true;
}
/**

View file

@ -15,7 +15,7 @@ use Leafo\ScssPhp\Formatter;
use Leafo\ScssPhp\Formatter\OutputBlock;
/**
* SCSS nested formatter
* Nested formatter
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
@ -38,6 +38,7 @@ class Nested extends Formatter
$this->close = ' }';
$this->tagSeparator = ', ';
$this->assignSeparator = ': ';
$this->keepSemicolons = true;
}
/**
@ -154,7 +155,7 @@ class Nested extends Formatter
private function adjustAllChildren(OutputBlock $block)
{
// flatten empty nested blocks
$children = array();
$children = [];
foreach ($block->children as $i => $child) {
if (empty($child->lines) && empty($child->children)) {

View file

@ -12,7 +12,7 @@
namespace Leafo\ScssPhp\Formatter;
/**
* SCSS output block
* Output block
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/

View file

@ -12,7 +12,7 @@
namespace Leafo\ScssPhp;
/**
* SCSS node
* Base node
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/
@ -26,10 +26,15 @@ abstract class Node
/**
* @var integer
*/
public $sourcePosition;
public $sourceIndex;
/**
* @var integer
*/
public $sourceIndex;
public $sourceLine;
/**
* @var integer
*/
public $sourceColumn;
}

View file

@ -11,11 +11,12 @@
namespace Leafo\ScssPhp\Node;
use Leafo\ScssPhp\Compiler;
use Leafo\ScssPhp\Node;
use Leafo\ScssPhp\Type;
/**
* SCSS dimension + optional units
* Dimension + optional units
*
* {@internal
* This is a work-in-progress.
@ -37,8 +38,8 @@ class Number extends Node implements \ArrayAccess
*
* @var array
*/
static protected $unitTable = array(
'in' => array(
static protected $unitTable = [
'in' => [
'in' => 1,
'pc' => 6,
'pt' => 72,
@ -46,27 +47,27 @@ class Number extends Node implements \ArrayAccess
'cm' => 2.54,
'mm' => 25.4,
'q' => 101.6,
),
'turn' => array(
'deg' => 180,
'grad' => 200,
'rad' => M_PI,
'turn' => 0.5,
),
's' => array(
's' => 1,
],
'turn' => [
'deg' => 360,
'grad' => 400,
'rad' => 6.28318530717958647692528676, // 2 * M_PI
'turn' => 1,
],
's' => [
's' => 1,
'ms' => 1000,
),
'Hz' => array(
'Hz' => 1,
],
'Hz' => [
'Hz' => 1,
'kHz' => 0.001,
),
'dpi' => array(
'dpi' => 1,
],
'dpi' => [
'dpi' => 1,
'dpcm' => 2.54,
'dppx' => 96,
),
);
],
];
/**
* @var integer|float
@ -74,21 +75,24 @@ class Number extends Node implements \ArrayAccess
public $dimension;
/**
* @var string
* @var array
*/
public $units;
/**
* Initialize number
*
* @param mixed $dimension
* @param string $initialUnit
* @param mixed $dimension
* @param mixed $initialUnit
*/
public function __construct($dimension, $initialUnit)
{
$this->type = Type::T_NUMBER;
$this->dimension = $dimension;
$this->units = $initialUnit;
$this->units = is_array($initialUnit)
? $initialUnit
: ($initialUnit ? [$initialUnit => 1]
: []);
}
/**
@ -100,13 +104,20 @@ class Number extends Node implements \ArrayAccess
*/
public function coerce($units)
{
$value = $this->dimension;
if (isset(self::$unitTable[$this->units][$units])) {
$value *= self::$unitTable[$this->units][$units];
if ($this->unitless()) {
return new Number($this->dimension, $units);
}
return new Number($value, $units);
$dimension = $this->dimension;
foreach (self::$unitTable['in'] as $unit => $conv) {
$from = isset($this->units[$unit]) ? $this->units[$unit] : 0;
$to = isset($units[$unit]) ? $units[$unit] : 0;
$factor = pow($conv, $from - $to);
$dimension /= $factor;
}
return new Number($dimension, $units);
}
/**
@ -116,13 +127,12 @@ class Number extends Node implements \ArrayAccess
*/
public function normalize()
{
if (isset(self::$unitTable['in'][$this->units])) {
$conv = self::$unitTable['in'][$this->units];
$dimension = $this->dimension;
$units = [];
return new Number($this->dimension / $conv, 'in');
}
$this->normalizeUnits($dimension, $units, 'in');
return new Number($this->dimension, $this->units);
return new Number($dimension, $units);
}
/**
@ -130,8 +140,12 @@ class Number extends Node implements \ArrayAccess
*/
public function offsetExists($offset)
{
if ($offset === -3) {
return $this->sourceColumn !== null;
}
if ($offset === -2) {
return $sourceIndex !== null;
return $this->sourceLine !== null;
}
if ($offset === -1
@ -151,11 +165,14 @@ class Number extends Node implements \ArrayAccess
public function offsetGet($offset)
{
switch ($offset) {
case -3:
return $this->sourceColumn;
case -2:
return $this->sourceIndex;
return $this->sourceLine;
case -1:
return $this->sourcePosition;
return $this->sourceIndex;
case 0:
return $this->type;
@ -178,9 +195,11 @@ class Number extends Node implements \ArrayAccess
} elseif ($offset === 2) {
$this->units = $value;
} elseif ($offset == -1) {
$this->sourcePosition = $value;
} elseif ($offset == -2) {
$this->sourceIndex = $value;
} elseif ($offset == -2) {
$this->sourceLine = $value;
} elseif ($offset == -3) {
$this->sourceColumn = $value;
}
}
@ -194,9 +213,11 @@ class Number extends Node implements \ArrayAccess
} elseif ($offset === 2) {
$this->units = null;
} elseif ($offset === -1) {
$this->sourcePosition = null;
} elseif ($offset === -2) {
$this->sourceIndex = null;
} elseif ($offset === -2) {
$this->sourceLine = null;
} elseif ($offset === -3) {
$this->sourceColumn = null;
}
}
@ -207,7 +228,7 @@ class Number extends Node implements \ArrayAccess
*/
public function unitless()
{
return empty($this->units);
return ! array_sum($this->units);
}
/**
@ -217,7 +238,61 @@ class Number extends Node implements \ArrayAccess
*/
public function unitStr()
{
return $this->units;
$numerators = [];
$denominators = [];
foreach ($this->units as $unit => $unitSize) {
if ($unitSize > 0) {
$numerators = array_pad($numerators, count($numerators) + $unitSize, $unit);
continue;
}
if ($unitSize < 0) {
$denominators = array_pad($denominators, count($denominators) + $unitSize, $unit);
continue;
}
}
return implode('*', $numerators) . (count($denominators) ? '/' . implode('*', $denominators) : '');
}
/**
* Output number
*
* @param \Leafo\ScssPhp\Compiler $compiler
*
* @return string
*/
public function output(Compiler $compiler = null)
{
$dimension = round($this->dimension, self::$precision);
$units = array_filter($this->units, function ($unitSize) {
return $unitSize;
});
if (count($units) > 1 && array_sum($units) === 0) {
$dimension = $this->dimension;
$units = [];
$this->normalizeUnits($dimension, $units, 'in');
$dimension = round($dimension, self::$precision);
$units = array_filter($units, function ($unitSize) {
return $unitSize;
});
}
$unitSize = array_sum($units);
if ($compiler && ($unitSize > 1 || $unitSize < 0 || count($units) > 1)) {
$compiler->throwError((string) $dimension . $this->unitStr() . " isn't a valid CSS value.");
}
reset($units);
list($unit, ) = each($units);
return (string) $dimension . $unit;
}
/**
@ -225,12 +300,30 @@ class Number extends Node implements \ArrayAccess
*/
public function __toString()
{
$value = round($this->dimension, self::$precision);
return $this->output();
}
if (empty($this->units)) {
return (string) $value;
/**
* Normalize units
*
* @param integer|float $dimension
* @param array $units
* @param string $baseUnit
*/
private function normalizeUnits(&$dimension, &$units, $baseUnit = 'in')
{
$dimension = $this->dimension;
$units = [];
foreach ($this->units as $unit => $exp) {
if (isset(self::$unitTable[$baseUnit][$unit])) {
$factor = pow(self::$unitTable[$baseUnit][$unit], $exp);
$unit = $baseUnit;
$dimension /= $factor;
}
$units[$unit] = $exp + (isset($units[$unit]) ? $units[$unit] : 0);
}
return (string) $value . $this->units;
}
}

File diff suppressed because it is too large Load diff

View file

@ -12,10 +12,11 @@
namespace Leafo\ScssPhp;
use Leafo\ScssPhp\Compiler;
use Leafo\ScssPhp\Exception\ServerException;
use Leafo\ScssPhp\Version;
/**
* SCSS server
* Server
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
@ -115,13 +116,12 @@ class Server
/**
* Determine whether .scss file needs to be re-compiled.
*
* @param string $in Input path
* @param string $out Output path
* @param string $etag ETag
*
* @return boolean True if compile required.
*/
protected function needsCompile($in, $out, &$etag)
protected function needsCompile($out, &$etag)
{
if (! is_file($out)) {
return true;
@ -207,21 +207,21 @@ class Server
$elapsed = round((microtime(true) - $start), 4);
$v = Version::VERSION;
$t = @date('r');
$t = date('r');
$css = "/* compiled by scssphp $v on $t (${elapsed}s) */\n\n" . $css;
$etag = md5($css);
file_put_contents($out, $css);
file_put_contents(
$this->metadataName($out),
serialize(array(
serialize([
'etag' => $etag,
'imports' => $this->scss->getParsedFiles(),
'vars' => crc32(serialize($this->scss->getVariables())),
))
])
);
return array($css, $etag);
return [$css, $etag];
}
/**
@ -231,11 +231,11 @@ class Server
*
* @return string
*/
protected function createErrorCSS($error)
protected function createErrorCSS(\Exception $error)
{
$message = str_replace(
array("'", "\n"),
array("\\'", "\\A"),
["'", "\n"],
["\\'", "\\A"],
$error->getfile() . ":\n\n" . $error->getMessage()
);
@ -269,11 +269,13 @@ class Server
* @param string $out Output file (.css) optional
*
* @return string|bool
*
* @throws \Leafo\ScssPhp\Exception\ServerException
*/
public function compileFile($in, $out = null)
{
if (! is_readable($in)) {
throw new \Exception('load error: failed to find ' . $in);
throw new ServerException('load error: failed to find ' . $in);
}
$pi = pathinfo($in);
@ -323,7 +325,7 @@ class Server
$output = $this->cacheName($salt . $input);
$etag = $noneMatch = trim($this->getIfNoneMatchHeader(), '"');
if ($this->needsCompile($input, $output, $etag)) {
if ($this->needsCompile($output, $etag)) {
try {
list($css, $etag) = $this->compile($input, $output);
@ -334,7 +336,6 @@ class Server
header('ETag: "' . $etag . '"');
echo $css;
} catch (\Exception $e) {
if ($this->showErrorsAsCSS) {
header('Content-type: text/css');
@ -346,7 +347,6 @@ class Server
echo 'Parse error: ' . $e->getMessage() . "\n";
}
}
return;
@ -365,7 +365,7 @@ class Server
$modifiedSince = $this->getIfModifiedSinceHeader();
$mtime = filemtime($output);
if (@strtotime($modifiedSince) === $mtime) {
if (strtotime($modifiedSince) === $mtime) {
header($protocol . ' 304 Not Modified');
return;
@ -395,19 +395,19 @@ class Server
*
* @return string Compiled CSS results
*
* @throws \Exception
* @throws \Leafo\ScssPhp\Exception\ServerException
*/
public function checkedCachedCompile($in, $out, $force = false)
{
if (! is_file($in) || ! is_readable($in)) {
throw new \Exception('Invalid or unreadable input file specified.');
throw new ServerException('Invalid or unreadable input file specified.');
}
if (is_dir($out) || ! is_writable(file_exists($out) ? $out : dirname($out))) {
throw new \Exception('Invalid or unwritable output file specified.');
throw new ServerException('Invalid or unwritable output file specified.');
}
if ($force || $this->needsCompile($in, $out, $etag)) {
if ($force || $this->needsCompile($out, $etag)) {
list($css, $etag) = $this->compile($in, $out);
} else {
$css = file_get_contents($out);
@ -444,6 +444,10 @@ class Server
$this->scss = $scss;
$this->showErrorsAsCSS = false;
if (! ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
}
/**

View file

@ -12,7 +12,7 @@
namespace Leafo\ScssPhp;
/**
* SCSS block/node types
* Block/node types
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/
@ -59,6 +59,7 @@ class Type
const T_NUMBER = 'number';
const T_RETURN = 'return';
const T_ROOT = 'root';
const T_SCSSPHP_IMPORT_ONCE = 'scssphp-import-once';
const T_SELF = 'self';
const T_STRING = 'string';
const T_UNARY = 'unary';

View file

@ -14,7 +14,7 @@ namespace Leafo\ScssPhp;
use Leafo\ScssPhp\Base\Range;
/**
* SCSS utilties
* Utilties
*
* @author Anthon Pang <anthon.pang@gmail.com>
*/

View file

@ -18,5 +18,5 @@ namespace Leafo\ScssPhp;
*/
class Version
{
const VERSION = 'v0.4.0';
const VERSION = 'v0.6.3';
}