Skip to content

Commit

Permalink
MDL-67379 libraries: Upgrade scssphp to 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Jan 15, 2020
1 parent 77d1c41 commit af2c779
Show file tree
Hide file tree
Showing 13 changed files with 1,402 additions and 707 deletions.
18 changes: 9 additions & 9 deletions lib/scssphp/Cache.php
Expand Up @@ -57,12 +57,12 @@ class Cache
public function __construct($options)
{
// check $cacheDir
if (isset($options['cache_dir'])) {
self::$cacheDir = $options['cache_dir'];
if (isset($options['cacheDir'])) {
self::$cacheDir = $options['cacheDir'];
}

if (empty(self::$cacheDir)) {
throw new Exception('cache_dir not set');
throw new Exception('cacheDir not set');
}

if (isset($options['prefix'])) {
Expand All @@ -74,7 +74,7 @@ public function __construct($options)
}

if (isset($options['forceRefresh'])) {
self::$forceRefresh = $options['force_refresh'];
self::$forceRefresh = $options['forceRefresh'];
}

self::checkCacheDir();
Expand All @@ -97,7 +97,7 @@ public function getCache($operation, $what, $options = [], $lastModified = null)
{
$fileCache = self::$cacheDir . self::cacheName($operation, $what, $options);

if ((! self::$forceRefresh || (self::$forceRefresh === 'once' &&
if (((self::$forceRefresh === false) || (self::$forceRefresh === 'once' &&
isset(self::$refreshed[$fileCache]))) && file_exists($fileCache)
) {
$cacheTime = filemtime($fileCache);
Expand Down Expand Up @@ -176,13 +176,13 @@ public static function checkCacheDir()
self::$cacheDir = str_replace('\\', '/', self::$cacheDir);
self::$cacheDir = rtrim(self::$cacheDir, '/') . '/';

if (! file_exists(self::$cacheDir)) {
if (! is_dir(self::$cacheDir)) {
if (! mkdir(self::$cacheDir)) {
throw new Exception('Cache directory couldn\'t be created: ' . self::$cacheDir);
}
} elseif (! is_dir(self::$cacheDir)) {
throw new Exception('Cache directory doesn\'t exist: ' . self::$cacheDir);
} elseif (! is_writable(self::$cacheDir)) {
}

if (! is_writable(self::$cacheDir)) {
throw new Exception('Cache directory isn\'t writable: ' . self::$cacheDir);
}
}
Expand Down
69 changes: 68 additions & 1 deletion lib/scssphp/Colors.php
Expand Up @@ -25,7 +25,7 @@ class Colors
*
* @var array
*/
public static $cssColors = [
protected static $cssColors = [
'aliceblue' => '240,248,255',
'antiquewhite' => '250,235,215',
'aqua' => '0,255,255',
Expand Down Expand Up @@ -176,4 +176,71 @@ class Colors
'yellow' => '255,255,0',
'yellowgreen' => '154,205,50',
];

/**
* Convert named color in a [r,g,b[,a]] array
*
* @param string $colorName
*
* @return array|null
*/
public static function colorNameToRGBa($colorName)
{
if (is_string($colorName) && isset(static::$cssColors[$colorName])) {
$rgba = explode(',', static::$cssColors[$colorName]);

// only case with opacity is transparent, with opacity=0, so we can intval on opacity also
$rgba = array_map('intval', $rgba);

return $rgba;
}

return null;
}

/**
* Reverse conversion : from RGBA to a color name if possible
*
* @param integer $r
* @param integer $g
* @param integer $b
* @param integer $a
*
* @return string|null
*/
public static function RGBaToColorName($r, $g, $b, $a = 1)
{
static $reverseColorTable = null;

if (! is_numeric($r) || ! is_numeric($g) || ! is_numeric($b) || ! is_numeric($a)) {
return null;
}

if ($a < 1) {
# specific case we dont' revert according to spec
#if (! $a && ! $r && ! $g && ! $b) {
# return 'transparent';
#}

return null;
}

if (is_null($reverseColorTable)) {
$reverseColorTable = [];

foreach (static::$cssColors as $name => $rgb_str) {
$rgb_str = explode(',', $rgb_str);

if (count($rgb_str) == 3) {
$reverseColorTable[intval($rgb_str[0])][intval($rgb_str[1])][intval($rgb_str[2])] = $name;
}
}
}

if (isset($reverseColorTable[intval($r)][intval($g)][intval($b)])) {
return $reverseColorTable[intval($r)][intval($g)][intval($b)];
}

return null;
}
}

0 comments on commit af2c779

Please sign in to comment.