Fix #1927 string * float error in leafo/lessphp

- dev-master 태그로 업데이트
- PHP 8.0 이상 버전에서 오류를 일으키는 {0} 문법 4군데 재수정
This commit is contained in:
Kijin Sung 2022-07-03 00:00:52 +09:00
parent e258cf7525
commit 1f9056fc08
31 changed files with 4558 additions and 4326 deletions

View file

@ -28,7 +28,7 @@
"guzzlehttp/guzzle": "6.5.*", "guzzlehttp/guzzle": "6.5.*",
"hautelook/phpass": "1.1.*", "hautelook/phpass": "1.1.*",
"jbbcode/jbbcode": "1.4.*", "jbbcode/jbbcode": "1.4.*",
"leafo/lessphp": "0.5.*", "leafo/lessphp": "dev-master",
"league/html-to-markdown": "4.*", "league/html-to-markdown": "4.*",
"matthiasmullie/minify": "1.3.*", "matthiasmullie/minify": "1.3.*",
"matthiasmullie/path-converter": "1.*", "matthiasmullie/path-converter": "1.*",

32
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "24cc938f5e56d40d6c7d2e484b77c5ad", "content-hash": "35b577c08cb08cdd0fc2ed06977a8617",
"packages": [ "packages": [
{ {
"name": "abraham/twitteroauth", "name": "abraham/twitteroauth",
@ -818,24 +818,28 @@
}, },
{ {
"name": "leafo/lessphp", "name": "leafo/lessphp",
"version": "v0.5.0", "version": "dev-master",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/leafo/lessphp.git", "url": "https://github.com/leafo/lessphp.git",
"reference": "0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283" "reference": "1fdc40e77824a692d7f4811ba86ed89669a66135"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/leafo/lessphp/zipball/0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283", "url": "https://api.github.com/repos/leafo/lessphp/zipball/1fdc40e77824a692d7f4811ba86ed89669a66135",
"reference": "0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283", "reference": "1fdc40e77824a692d7f4811ba86ed89669a66135",
"shasum": "" "shasum": ""
}, },
"type": "library", "require-dev": {
"extra": { "phpunit/phpunit": "^5.7.27",
"branch-alias": { "squizlabs/php_codesniffer": "3.3.2"
"dev-master": "0.4.x-dev"
}
}, },
"default-branch": true,
"bin": [
"plessc",
"lessify"
],
"type": "library",
"autoload": { "autoload": {
"classmap": [ "classmap": [
"lessc.inc.php" "lessc.inc.php"
@ -857,9 +861,9 @@
"homepage": "http://leafo.net/lessphp/", "homepage": "http://leafo.net/lessphp/",
"support": { "support": {
"issues": "https://github.com/leafo/lessphp/issues", "issues": "https://github.com/leafo/lessphp/issues",
"source": "https://github.com/leafo/lessphp/tree/v0.5.0" "source": "https://github.com/leafo/lessphp/tree/master"
}, },
"time": "2014-11-24T18:39:20+00:00" "time": "2018-10-16T19:24:03+00:00"
}, },
{ {
"name": "league/html-to-markdown", "name": "league/html-to-markdown",
@ -2014,7 +2018,9 @@
"packages-dev": [], "packages-dev": [],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": {
"leafo/lessphp": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {

1
vendor/bin/lessify vendored Symbolic link
View file

@ -0,0 +1 @@
../leafo/lessphp/lessify

1
vendor/bin/plessc vendored Symbolic link
View file

@ -0,0 +1 @@
../leafo/lessphp/plessc

View file

@ -29,7 +29,7 @@ private static $installed = array (
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'd4ffe761c58924530ae083ba84e2daf5b709c2a6', 'reference' => 'e258cf75257ea48ab849d13f6e7b22a137abf489',
'name' => 'rhymix/rhymix', 'name' => 'rhymix/rhymix',
), ),
'versions' => 'versions' =>
@ -144,12 +144,13 @@ private static $installed = array (
), ),
'leafo/lessphp' => 'leafo/lessphp' =>
array ( array (
'pretty_version' => 'v0.5.0', 'pretty_version' => 'dev-master',
'version' => '0.5.0.0', 'version' => 'dev-master',
'aliases' => 'aliases' =>
array ( array (
0 => '9999999-dev',
), ),
'reference' => '0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283', 'reference' => '1fdc40e77824a692d7f4811ba86ed89669a66135',
), ),
'league/html-to-markdown' => 'league/html-to-markdown' =>
array ( array (
@ -228,7 +229,7 @@ private static $installed = array (
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'd4ffe761c58924530ae083ba84e2daf5b709c2a6', 'reference' => 'e258cf75257ea48ab849d13f6e7b22a137abf489',
), ),
'rmccue/requests' => 'rmccue/requests' =>
array ( array (

View file

@ -16,6 +16,6 @@ return array(
'def43f6c87e4f8dfd0c9e1b1bab14fe8' => $vendorDir . '/symfony/polyfill-iconv/bootstrap.php', 'def43f6c87e4f8dfd0c9e1b1bab14fe8' => $vendorDir . '/symfony/polyfill-iconv/bootstrap.php',
'8170285c807a9f24f165f37b15bc9a36' => $vendorDir . '/defuse/php-encryption/Crypto.php', '8170285c807a9f24f165f37b15bc9a36' => $vendorDir . '/defuse/php-encryption/Crypto.php',
'2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php', '2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
); );

View file

@ -22,6 +22,8 @@ class ComposerAutoloaderInit1e37ff09eb6590c7436f139ffd9070de
return self::$loader; return self::$loader;
} }
require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInit1e37ff09eb6590c7436f139ffd9070de', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInit1e37ff09eb6590c7436f139ffd9070de', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(); self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit1e37ff09eb6590c7436f139ffd9070de', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit1e37ff09eb6590c7436f139ffd9070de', 'loadClassLoader'));

View file

@ -17,8 +17,8 @@ class ComposerStaticInit1e37ff09eb6590c7436f139ffd9070de
'def43f6c87e4f8dfd0c9e1b1bab14fe8' => __DIR__ . '/..' . '/symfony/polyfill-iconv/bootstrap.php', 'def43f6c87e4f8dfd0c9e1b1bab14fe8' => __DIR__ . '/..' . '/symfony/polyfill-iconv/bootstrap.php',
'8170285c807a9f24f165f37b15bc9a36' => __DIR__ . '/..' . '/defuse/php-encryption/Crypto.php', '8170285c807a9f24f165f37b15bc9a36' => __DIR__ . '/..' . '/defuse/php-encryption/Crypto.php',
'2cffec82183ee1cea088009cef9a6fc3' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php', '2cffec82183ee1cea088009cef9a6fc3' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
'2c102faa651ef8ea5874edb585946bce' => __DIR__ . '/..' . '/swiftmailer/swiftmailer/lib/swift_required.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
'2c102faa651ef8ea5874edb585946bce' => __DIR__ . '/..' . '/swiftmailer/swiftmailer/lib/swift_required.php',
); );
public static $prefixLengthsPsr4 = array ( public static $prefixLengthsPsr4 = array (

View file

@ -836,27 +836,31 @@
}, },
{ {
"name": "leafo/lessphp", "name": "leafo/lessphp",
"version": "v0.5.0", "version": "dev-master",
"version_normalized": "0.5.0.0", "version_normalized": "dev-master",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/leafo/lessphp.git", "url": "https://github.com/leafo/lessphp.git",
"reference": "0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283" "reference": "1fdc40e77824a692d7f4811ba86ed89669a66135"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/leafo/lessphp/zipball/0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283", "url": "https://api.github.com/repos/leafo/lessphp/zipball/1fdc40e77824a692d7f4811ba86ed89669a66135",
"reference": "0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283", "reference": "1fdc40e77824a692d7f4811ba86ed89669a66135",
"shasum": "" "shasum": ""
}, },
"time": "2014-11-24T18:39:20+00:00", "require-dev": {
"type": "library", "phpunit/phpunit": "^5.7.27",
"extra": { "squizlabs/php_codesniffer": "3.3.2"
"branch-alias": {
"dev-master": "0.4.x-dev"
}
}, },
"installation-source": "dist", "time": "2018-10-16T19:24:03+00:00",
"default-branch": true,
"bin": [
"plessc",
"lessify"
],
"type": "library",
"installation-source": "source",
"autoload": { "autoload": {
"classmap": [ "classmap": [
"lessc.inc.php" "lessc.inc.php"
@ -876,6 +880,10 @@
], ],
"description": "lessphp is a compiler for LESS written in PHP.", "description": "lessphp is a compiler for LESS written in PHP.",
"homepage": "http://leafo.net/lessphp/", "homepage": "http://leafo.net/lessphp/",
"support": {
"issues": "https://github.com/leafo/lessphp/issues",
"source": "https://github.com/leafo/lessphp/tree/master"
},
"install-path": "../leafo/lessphp" "install-path": "../leafo/lessphp"
}, },
{ {

View file

@ -6,7 +6,7 @@
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'd4ffe761c58924530ae083ba84e2daf5b709c2a6', 'reference' => 'e258cf75257ea48ab849d13f6e7b22a137abf489',
'name' => 'rhymix/rhymix', 'name' => 'rhymix/rhymix',
), ),
'versions' => 'versions' =>
@ -121,12 +121,13 @@
), ),
'leafo/lessphp' => 'leafo/lessphp' =>
array ( array (
'pretty_version' => 'v0.5.0', 'pretty_version' => 'dev-master',
'version' => '0.5.0.0', 'version' => 'dev-master',
'aliases' => 'aliases' =>
array ( array (
0 => '9999999-dev',
), ),
'reference' => '0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283', 'reference' => '1fdc40e77824a692d7f4811ba86ed89669a66135',
), ),
'league/html-to-markdown' => 'league/html-to-markdown' =>
array ( array (
@ -205,7 +206,7 @@
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'd4ffe761c58924530ae083ba84e2daf5b709c2a6', 'reference' => 'e258cf75257ea48ab849d13f6e7b22a137abf489',
), ),
'rmccue/requests' => 'rmccue/requests' =>
array ( array (

26
vendor/composer/platform_check.php vendored Normal file
View file

@ -0,0 +1,26 @@
<?php
// platform_check.php @generated by Composer
$issues = array();
if (!(PHP_VERSION_ID >= 70300)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.3.0". You are running ' . PHP_VERSION . '.';
}
if ($issues) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
} elseif (!headers_sent()) {
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
}
}
trigger_error(
'Composer detected issues in your platform: ' . implode(' ', $issues),
E_USER_ERROR
);
}

40
vendor/leafo/lessphp/.phpcs.xml vendored Normal file
View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset>
<rule ref="PSR2">
<exclude name="Generic.ControlStructures.InlineControlStructure.NotAllowed" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect" />
<exclude name="Generic.WhiteSpace.ScopeIndent.IncorrectExact" />
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
<exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody" />
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
<exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpaceBeforeCloseBrace" />
<exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BodyOnNextLineCASE" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakIndent" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakNotNewLine" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
<exclude name="PSR2.Methods.FunctionCallSignature.CloseBracketLine" />
<exclude name="PSR2.Methods.FunctionCallSignature.ContentAfterOpenBracket" />
<exclude name="PSR2.Methods.FunctionCallSignature.Indent" />
<exclude name="PSR2.Methods.FunctionCallSignature.MultipleArguments" />
<exclude name="PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket" />
<exclude name="PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace" />
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceAfterDefault" />
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction" />
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose" />
<exclude name="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore" />
</rule>
<file>.</file>
<arg name="encoding" value="UTF-8"/>
<arg name="extensions" value="php"/>
<exclude-pattern>vendor</exclude-pattern>
</ruleset>

View file

@ -1,17 +1,17 @@
language: php language: php
php: php:
- 5.3 - 5.6
- 5.4
- 5.5
- hhvm - hhvm
- 7.0
- 7.1
- 7.2
- 7.3
before_script: sudo: false
- composer self-update
- composer install --no-interaction --prefer-source --dev install:
- travis_retry composer install --no-interaction --prefer-source
script: script:
- phpunit tests - composer test
matrix:
fast_finish: true

View file

@ -1,4 +1,4 @@
For ease of distribution, lessphp 0.4.0 is under a dual license. For ease of distribution, lessphp is under a dual license.
You are free to pick which one suits your needs. You are free to pick which one suits your needs.
@ -9,7 +9,7 @@ MIT LICENSE
Copyright (c) 2013 Leaf Corcoran, http://leafo.net/lessphp Copyright (c) 2014 Leaf Corcoran, http://leafo.net/lessphp
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the

View file

@ -34,7 +34,7 @@ result or write it to the path specified by an optional second argument.
echo $less->compileFile("input.less"); echo $less->compileFile("input.less");
``` ```
The `compileChecked` method is like `compileFile`, but it only compiles if the output The `checkedCompile` method is like `compileFile`, but it only compiles if the output
file doesn't exist or it's older than the input file: file doesn't exist or it's older than the input file:
```php ```php

View file

@ -14,12 +14,22 @@
"homepage": "http://leafo.net" "homepage": "http://leafo.net"
} }
], ],
"bin": [
"plessc",
"lessify"
],
"autoload": { "autoload": {
"classmap": ["lessc.inc.php"] "classmap": ["lessc.inc.php"]
}, },
"extra": { "require-dev": {
"branch-alias": { "phpunit/phpunit": "^5.7.27",
"dev-master": "0.4.x-dev" "squizlabs/php_codesniffer": "3.3.2"
} },
"scripts": {
"test": [
"phpunit",
"phpcs -p -s"
],
"fix": "phpcbf"
} }
} }

View file

@ -1023,7 +1023,7 @@ result or write it to the path specified by an optional second argument.
echo $less->compileFile("input.less"); echo $less->compileFile("input.less");
``` ```
The `compileChecked` method is like `compileFile`, but it only compiles if the output The `checkedCompile` method is like `compileFile`, but it only compiles if the output
file doesn't exist or it's older than the input file: file doesn't exist or it's older than the input file:
```php ```php
@ -1239,7 +1239,7 @@ One for PHP and one for LESS.
```php ```php
$less->setVariables(array( $less->setVariables(array(
"url" => "'http://example.com.com/'" "url" => "'http://example.com'"
)); ));
echo $less->compile("body { background: url("@{url}/bg.png"); }"); echo $less->compile("body { background: url("@{url}/bg.png"); }");

View file

@ -81,12 +81,12 @@ class lessc {
return is_file($name); return is_file($name);
} }
static public function compressList($items, $delim) { public static function compressList($items, $delim) {
if (!isset($items[1]) && isset($items[0])) return $items[0]; if (!isset($items[1]) && isset($items[0])) return $items[0];
else return array('list', $delim, $items); else return array('list', $delim, $items);
} }
static public function preg_quote($what) { public static function preg_quote($what) {
return preg_quote($what, '/'); return preg_quote($what, '/');
} }
@ -390,8 +390,8 @@ class lessc {
protected function multiplyMedia($env, $childQueries = null) { protected function multiplyMedia($env, $childQueries = null) {
if (is_null($env) || if (is_null($env) ||
!empty($env->block->type) && $env->block->type != "media") !empty($env->block->type) && $env->block->type != "media"
{ ) {
return $childQueries; return $childQueries;
} }
@ -570,7 +570,7 @@ class lessc {
return true; // not having enough is handled above return true; // not having enough is handled above
} else { } else {
$numMatched = $i + 1; $numMatched = $i + 1;
// greater than becuase default values always match // greater than because default values always match
return $numMatched >= count($orderedArgs); return $numMatched >= count($orderedArgs);
} }
} }
@ -746,8 +746,8 @@ class lessc {
if ($suffix !== null && if ($suffix !== null &&
$subProp[0] == "assign" && $subProp[0] == "assign" &&
is_string($subProp[1]) && is_string($subProp[1]) &&
$subProp[1][0] != $this->vPrefix) $subProp[1][0] != $this->vPrefix
{ ) {
$subProp[2] = array( $subProp[2] = array(
'list', ' ', 'list', ' ',
array($subProp[2], array('keyword', $suffix)) array($subProp[2], array('keyword', $suffix))
@ -774,7 +774,7 @@ class lessc {
case "comment": case "comment":
$out->lines[] = $prop[1]; $out->lines[] = $prop[1];
break; break;
case "import"; case "import":
list(, $importPath, $importId) = $prop; list(, $importPath, $importId) = $prop;
$importPath = $this->reduce($importPath); $importPath = $this->reduce($importPath);
@ -971,12 +971,16 @@ class lessc {
protected function lib_rgbahex($color) { protected function lib_rgbahex($color) {
$color = $this->coerceColor($color); $color = $this->coerceColor($color);
if (is_null($color)) if (is_null($color)) {
$this->throwError("color expected for rgbahex"); $this->throwError("color expected for rgbahex");
}
return sprintf("#%02x%02x%02x%02x", return sprintf("#%02x%02x%02x%02x",
isset($color[4]) ? $color[4] * 255 : 255, isset($color[4]) ? $color[4] * 255 : 255,
$color[1],$color[2], $color[3]); $color[1],
$color[2],
$color[3]
);
} }
protected function lib_argb($color){ protected function lib_argb($color){
@ -1147,7 +1151,9 @@ class lessc {
$hsl = $this->toHSL($color); $hsl = $this->toHSL($color);
$hsl[1] = $hsl[1] + $delta % 360; $hsl[1] = $hsl[1] + $delta % 360;
if ($hsl[1] < 0) $hsl[1] += 360; if ($hsl[1] < 0) {
$hsl[1] += 360;
}
return $this->toRGB($hsl); return $this->toRGB($hsl);
} }
@ -1199,6 +1205,50 @@ class lessc {
return array("number", $num*100, "%"); return array("number", $num*100, "%");
} }
/**
* Mix color with white in variable proportion.
*
* It is the same as calling `mix(#ffffff, @color, @weight)`.
*
* tint(@color, [@weight: 50%]);
*
* http://lesscss.org/functions/#color-operations-tint
*
* @return array Color
*/
protected function lib_tint($args) {
$white = ['color', 255, 255, 255];
if ($args[0] == 'color') {
return $this->lib_mix([ 'list', ',', [$white, $args] ]);
} elseif ($args[0] == "list" && count($args[2]) == 2) {
return $this->lib_mix([ $args[0], $args[1], [$white, $args[2][0], $args[2][1]] ]);
} else {
$this->throwError("tint expects (color, weight)");
}
}
/**
* Mix color with black in variable proportion.
*
* It is the same as calling `mix(#000000, @color, @weight)`
*
* shade(@color, [@weight: 50%]);
*
* http://lesscss.org/functions/#color-operations-shade
*
* @return array Color
*/
protected function lib_shade($args) {
$black = ['color', 0, 0, 0];
if ($args[0] == 'color') {
return $this->lib_mix([ 'list', ',', [$black, $args] ]);
} elseif ($args[0] == "list" && count($args[2]) == 2) {
return $this->lib_mix([ $args[0], $args[1], [$black, $args[2][0], $args[2][1]] ]);
} else {
$this->throwError("shade expects (color, weight)");
}
}
// mixes two colors by weight // mixes two colors by weight
// mix(@color1, @color2, [@weight: 50%]); // mix(@color1, @color2, [@weight: 50%]);
// http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#mix-instance_method // http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#mix-instance_method
@ -1258,22 +1308,35 @@ class lessc {
$lightColor = $this->coerceColor($lightColor); $lightColor = $this->coerceColor($lightColor);
//Figure out which is actually light and dark! //Figure out which is actually light and dark!
if ( $this->lib_luma($darkColor) > $this->lib_luma($lightColor) ) { if ( $this->toLuma($darkColor) > $this->toLuma($lightColor) ) {
$t = $lightColor; $t = $lightColor;
$lightColor = $darkColor; $lightColor = $darkColor;
$darkColor = $t; $darkColor = $t;
} }
$inputColor_alpha = $this->lib_alpha($inputColor); $inputColor_alpha = $this->lib_alpha($inputColor);
if ( ( $this->lib_luma($inputColor) * $inputColor_alpha) < $threshold) { if ( ( $this->toLuma($inputColor) * $inputColor_alpha) < $threshold) {
return $lightColor; return $lightColor;
} }
return $darkColor; return $darkColor;
} }
private function toLuma($color) {
list(, $r, $g, $b) = $this->coerceColor($color);
$r = $r / 255;
$g = $g / 255;
$b = $b / 255;
$r = ($r <= 0.03928) ? $r / 12.92 : pow((($r + 0.055) / 1.055), 2.4);
$g = ($g <= 0.03928) ? $g / 12.92 : pow((($g + 0.055) / 1.055), 2.4);
$b = ($b <= 0.03928) ? $b / 12.92 : pow((($b + 0.055) / 1.055), 2.4);
return (0.2126 * $r) + (0.7152 * $g) + (0.0722 * $b);
}
protected function lib_luma($color) { protected function lib_luma($color) {
$color = $this->coerceColor($color); return array("number", round($this->toLuma($color) * 100, 8), "%");
return (0.2126 * $color[0] / 255) + (0.7152 * $color[1] / 255) + (0.0722 * $color[2] / 255);
} }
@ -1308,7 +1371,9 @@ class lessc {
} }
protected function toHSL($color) { protected function toHSL($color) {
if ($color[0] == 'hsl') return $color; if ($color[0] === 'hsl') {
return $color;
}
$r = $color[1] / 255; $r = $color[1] / 255;
$g = $color[2] / 255; $g = $color[2] / 255;
@ -1321,14 +1386,18 @@ class lessc {
if ($min == $max) { if ($min == $max) {
$S = $H = 0; $S = $H = 0;
} else { } else {
if ($L < 0.5) if ($L < 0.5) {
$S = ($max - $min) / ($max + $min); $S = ($max - $min) / ($max + $min);
else } else {
$S = ($max - $min) / (2.0 - $max - $min); $S = ($max - $min) / (2.0 - $max - $min);
}
if ($r == $max) $H = ($g - $b)/($max - $min); if ($r == $max) {
elseif ($g == $max) $H = 2.0 + ($b - $r)/($max - $min); $H = ($g - $b) / ($max - $min);
elseif ($b == $max) $H = 4.0 + ($r - $g)/($max - $min); } elseif ($g == $max) {
$H = 2.0 + ($b - $r) / ($max - $min);
} elseif ($b == $max) {
$H = 4.0 + ($r - $g) / ($max - $min);
}
} }
@ -1338,17 +1407,29 @@ class lessc {
$L * 100, $L * 100,
); );
if (count($color) > 4) $out[] = $color[4]; // copy alpha if (count($color) > 4) {
// copy alpha
$out[] = $color[4];
}
return $out; return $out;
} }
protected function toRGB_helper($comp, $temp1, $temp2) { protected function toRGB_helper($comp, $temp1, $temp2) {
if ($comp < 0) $comp += 1.0; if ($comp < 0) {
elseif ($comp > 1) $comp -= 1.0; $comp += 1.0;
} elseif ($comp > 1) {
$comp -= 1.0;
}
if (6 * $comp < 1) return $temp1 + ($temp2 - $temp1) * 6 * $comp; if (6 * $comp < 1) {
if (2 * $comp < 1) return $temp2; return $temp1 + ($temp2 - $temp1) * 6 * $comp;
if (3 * $comp < 2) return $temp1 + ($temp2 - $temp1)*((2/3) - $comp) * 6; }
if (2 * $comp < 1) {
return $temp2;
}
if (3 * $comp < 2) {
return $temp1 + ($temp2 - $temp1)*((2/3) - $comp) * 6;
}
return $temp1; return $temp1;
} }
@ -1358,7 +1439,9 @@ class lessc {
* Expects H to be in range of 0 to 360, S and L in 0 to 100 * Expects H to be in range of 0 to 360, S and L in 0 to 100
*/ */
protected function toRGB($color) { protected function toRGB($color) {
if ($color[0] == 'color') return $color; if ($color[0] === 'color') {
return $color;
}
$H = $color[1] / 360; $H = $color[1] / 360;
$S = $color[2] / 100; $S = $color[2] / 100;
@ -1380,7 +1463,10 @@ class lessc {
// $out = array('color', round($r*255), round($g*255), round($b*255)); // $out = array('color', round($r*255), round($g*255), round($b*255));
$out = array('color', $r*255, $g*255, $b*255); $out = array('color', $r*255, $g*255, $b*255);
if (count($color) > 4) $out[] = $color[4]; // copy alpha if (count($color) > 4) {
// copy alpha
$out[] = $color[4];
}
return $out; return $out;
} }
@ -1394,7 +1480,10 @@ class lessc {
*/ */
protected function funcToColor($func) { protected function funcToColor($func) {
$fname = $func[1]; $fname = $func[1];
if ($func[2][0] != 'list') return false; // need a list of arguments if ($func[2][0] != 'list') {
// need a list of arguments
return false;
}
$rawComponents = $func[2][2]; $rawComponents = $func[2][2];
if ($fname == 'hsl' || $fname == 'hsla') { if ($fname == 'hsl' || $fname == 'hsla') {
@ -1404,15 +1493,21 @@ class lessc {
$val = $this->reduce($c); $val = $this->reduce($c);
$val = isset($val[1]) ? floatval($val[1]) : 0; $val = isset($val[1]) ? floatval($val[1]) : 0;
if ($i == 0) $clamp = 360; if ($i == 0) {
elseif ($i < 3) $clamp = 100; $clamp = 360;
else $clamp = 1; } elseif ($i < 3) {
$clamp = 100;
} else {
$clamp = 1;
}
$hsl[] = $this->clamp($val, $clamp); $hsl[] = $this->clamp($val, $clamp);
$i++; $i++;
} }
while (count($hsl) < 4) $hsl[] = 0; while (count($hsl) < 4) {
$hsl[] = 0;
}
return $this->toRGB($hsl); return $this->toRGB($hsl);
} elseif ($fname == 'rgb' || $fname == 'rgba') { } elseif ($fname == 'rgb' || $fname == 'rgba') {
@ -1436,7 +1531,9 @@ class lessc {
$i++; $i++;
} }
while (count($components) < 3) $components[] = 0; while (count($components) < 3) {
$components[] = 0;
}
array_unshift($components, 'color'); array_unshift($components, 'color');
return $this->fixColor($components); return $this->fixColor($components);
} }
@ -1517,8 +1614,11 @@ class lessc {
} }
// convert to a typed value if the result is a php primitive // convert to a typed value if the result is a php primitive
if (is_numeric($ret)) $ret = array('number', $ret, ""); if (is_numeric($ret)) {
elseif (!is_array($ret)) $ret = array('keyword', $ret); $ret = array('number', $ret, "");
} elseif (!is_array($ret)) {
$ret = array('keyword', $ret);
}
return $ret; return $ret;
} }
@ -1581,9 +1681,9 @@ class lessc {
if (isset(self::$cssColors[$name])) { if (isset(self::$cssColors[$name])) {
$rgba = explode(',', self::$cssColors[$name]); $rgba = explode(',', self::$cssColors[$name]);
if(isset($rgba[3])) if (isset($rgba[3])) {
return array('color', $rgba[0], $rgba[1], $rgba[2], $rgba[3]); return array('color', $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
}
return array('color', $rgba[0], $rgba[1], $rgba[2]); return array('color', $rgba[0], $rgba[1], $rgba[2]);
} }
return null; return null;
@ -1610,8 +1710,7 @@ class lessc {
} }
public function toBool($a) { public function toBool($a) {
if ($a) return self::$TRUE; return $a ? self::$TRUE : self::$FALSE;
else return self::$FALSE;
} }
// evaluate an expression // evaluate an expression
@ -1654,8 +1753,12 @@ class lessc {
// make the expression look it did before being parsed // make the expression look it did before being parsed
$paddedOp = $op; $paddedOp = $op;
if ($whiteBefore) $paddedOp = " " . $paddedOp; if ($whiteBefore) {
if ($whiteAfter) $paddedOp .= " "; $paddedOp = " " . $paddedOp;
}
if ($whiteAfter) {
$paddedOp .= " ";
}
return array("string", "", array($left, $paddedOp, $right)); return array("string", "", array($left, $paddedOp, $right));
} }
@ -1719,7 +1822,9 @@ class lessc {
$out[] = $lval % $rval; $out[] = $lval % $rval;
break; break;
case '/': case '/':
if ($rval == 0) $this->throwError("evaluate error: can't divide by zero"); if ($rval == 0) {
$this->throwError("evaluate error: can't divide by zero");
}
$out[] = $lval / $rval; $out[] = $lval / $rval;
break; break;
default: default:
@ -1729,7 +1834,7 @@ class lessc {
return $this->fixColor($out); return $this->fixColor($out);
} }
function lib_red($color){ public function lib_red($color){
$color = $this->coerceColor($color); $color = $this->coerceColor($color);
if (is_null($color)) { if (is_null($color)) {
$this->throwError('color expected for red()'); $this->throwError('color expected for red()');
@ -1738,7 +1843,7 @@ class lessc {
return $color[1]; return $color[1];
} }
function lib_green($color){ public function lib_green($color){
$color = $this->coerceColor($color); $color = $this->coerceColor($color);
if (is_null($color)) { if (is_null($color)) {
$this->throwError('color expected for green()'); $this->throwError('color expected for green()');
@ -1747,7 +1852,7 @@ class lessc {
return $color[2]; return $color[2];
} }
function lib_blue($color){ public function lib_blue($color){
$color = $this->coerceColor($color); $color = $this->coerceColor($color);
if (is_null($color)) { if (is_null($color)) {
$this->throwError('color expected for blue()'); $this->throwError('color expected for blue()');
@ -1841,12 +1946,13 @@ class lessc {
return array('list', ' ', $current->arguments); return array('list', ' ', $current->arguments);
} }
if (isset($current->store[$name])) if (isset($current->store[$name])) {
return $current->store[$name]; return $current->store[$name];
else {
$current = isset($current->storeParent) ?
$current->storeParent : $current->parent;
} }
$current = isset($current->storeParent) ?
$current->storeParent :
$current->parent;
} }
$this->throwError("variable $name is undefined"); $this->throwError("variable $name is undefined");
@ -1857,7 +1963,9 @@ class lessc {
$this->pushEnv(); $this->pushEnv();
$parser = new lessc_parser($this, __METHOD__); $parser = new lessc_parser($this, __METHOD__);
foreach ($args as $name => $strValue) { foreach ($args as $name => $strValue) {
if ($name[0] != '@') $name = '@'.$name; if ($name[0] !== '@') {
$name = '@' . $name;
}
$parser->count = 0; $parser->count = 0;
$parser->buffer = (string)$strValue; $parser->buffer = (string)$strValue;
if (!$parser->propertyValue($value)) { if (!$parser->propertyValue($value)) {
@ -1965,15 +2073,15 @@ class lessc {
if (is_string($in)) { if (is_string($in)) {
$root = $in; $root = $in;
} elseif (is_array($in) and isset($in['root'])) { } elseif (is_array($in) && isset($in['root'])) {
if ($force or ! isset($in['files'])) { if ($force || !isset($in['files'])) {
// If we are forcing a recompile or if for some reason the // If we are forcing a recompile or if for some reason the
// structure does not contain any file information we should // structure does not contain any file information we should
// specify the root to trigger a rebuild. // specify the root to trigger a rebuild.
$root = $in['root']; $root = $in['root'];
} elseif (isset($in['files']) and is_array($in['files'])) { } elseif (isset($in['files']) && is_array($in['files'])) {
foreach ($in['files'] as $fname => $ftime) { foreach ($in['files'] as $fname => $ftime) {
if (!file_exists($fname) or filemtime($fname) > $ftime) { if (!file_exists($fname) || filemtime($fname) > $ftime) {
// One of the files we knew about previously has changed // One of the files we knew about previously has changed
// so we should look at our incoming root again. // so we should look at our incoming root again.
$root = $in['root']; $root = $in['root'];
@ -2416,8 +2524,8 @@ class lessc_parser {
// setting a property // setting a property
if ($this->keyword($key) && $this->assign() && if ($this->keyword($key) && $this->assign() &&
$this->propertyValue($value, $key) && $this->end()) $this->propertyValue($value, $key) && $this->end()
{ ) {
$this->append(array('assign', $key, $value), $s); $this->append(array('assign', $key, $value), $s);
return true; return true;
} else { } else {
@ -2432,8 +2540,8 @@ class lessc_parser {
// media // media
if ($this->literal('@media')) { if ($this->literal('@media')) {
if (($this->mediaQueryList($mediaQueries) || true) if (($this->mediaQueryList($mediaQueries) || true)
&& $this->literal('{')) && $this->literal('{')
{ ) {
$media = $this->pushSpecialBlock("media"); $media = $this->pushSpecialBlock("media");
$media->queries = is_null($mediaQueries) ? array() : $mediaQueries; $media->queries = is_null($mediaQueries) ? array() : $mediaQueries;
return true; return true;
@ -2446,8 +2554,8 @@ class lessc_parser {
if ($this->literal("@", false) && $this->keyword($dirName)) { if ($this->literal("@", false) && $this->keyword($dirName)) {
if ($this->isDirective($dirName, $this->blockDirectives)) { if ($this->isDirective($dirName, $this->blockDirectives)) {
if (($this->openString("{", $dirValue, null, array(";")) || true) && if (($this->openString("{", $dirValue, null, array(";")) || true) &&
$this->literal("{")) $this->literal("{")
{ ) {
$dir = $this->pushSpecialBlock("directive"); $dir = $this->pushSpecialBlock("directive");
$dir->name = $dirName; $dir->name = $dirName;
if (isset($dirValue)) $dir->value = $dirValue; if (isset($dirValue)) $dir->value = $dirValue;
@ -2466,8 +2574,8 @@ class lessc_parser {
// setting a variable // setting a variable
if ($this->variable($var) && $this->assign() && if ($this->variable($var) && $this->assign() &&
$this->propertyValue($value) && $this->end()) $this->propertyValue($value) && $this->end()
{ ) {
$this->append(array('assign', $var, $value), $s); $this->append(array('assign', $var, $value), $s);
return true; return true;
} else { } else {
@ -2482,8 +2590,8 @@ class lessc_parser {
// opening parametric mixin // opening parametric mixin
if ($this->tag($tag, true) && $this->argumentDef($args, $isVararg) && if ($this->tag($tag, true) && $this->argumentDef($args, $isVararg) &&
($this->guards($guards) || true) && ($this->guards($guards) || true) &&
$this->literal('{')) $this->literal('{')
{ ) {
$block = $this->pushBlock($this->fixTags(array($tag))); $block = $this->pushBlock($this->fixTags(array($tag)));
$block->args = $args; $block->args = $args;
$block->isVararg = $isVararg; $block->isVararg = $isVararg;
@ -2543,8 +2651,8 @@ class lessc_parser {
// mixin // mixin
if ($this->mixinTags($tags) && if ($this->mixinTags($tags) &&
($this->argumentDef($argv, $isVararg) || true) && ($this->argumentDef($argv, $isVararg) || true) &&
($this->keyword($suffix) || true) && $this->end()) ($this->keyword($suffix) || true) && $this->end()
{ ) {
$tags = $this->fixTags($tags); $tags = $this->fixTags($tags);
$this->append(array('mixin', $tags, $argv, $suffix), $s); $this->append(array('mixin', $tags, $argv, $suffix), $s);
return true; return true;
@ -2699,8 +2807,8 @@ class lessc_parser {
$inParens = $this->inParens; $inParens = $this->inParens;
if ($this->literal("(") && if ($this->literal("(") &&
($this->inParens = true) && $this->expression($exp) && ($this->inParens = true) && $this->expression($exp) &&
$this->literal(")")) $this->literal(")")
{ ) {
$out = $exp; $out = $exp;
$this->inParens = $inParens; $this->inParens = $inParens;
return true; return true;
@ -2722,8 +2830,8 @@ class lessc_parser {
if ($this->literal("-", false) && if ($this->literal("-", false) &&
(($this->variable($inner) && $inner = array("variable", $inner)) || (($this->variable($inner) && $inner = array("variable", $inner)) ||
$this->unit($inner) || $this->unit($inner) ||
$this->parenValue($inner))) $this->parenValue($inner))
{ ) {
$value = array("unary", "-", $inner); $value = array("unary", "-", $inner);
return true; return true;
} else { } else {
@ -2828,8 +2936,8 @@ class lessc_parser {
if ($this->literal("(") && if ($this->literal("(") &&
$this->keyword($feature) && $this->keyword($feature) &&
($this->literal(":") && $this->expression($value) || true) && ($this->literal(":") && $this->expression($value) || true) &&
$this->literal(")")) $this->literal(")")
{ ) {
$out = array("mediaExp", $feature); $out = array("mediaExp", $feature);
if ($value) $out[] = $value; if ($value) $out[] = $value;
return true; return true;
@ -2968,8 +3076,8 @@ class lessc_parser {
$s = $this->seek(); $s = $this->seek();
if ($this->literal("@{") && if ($this->literal("@{") &&
$this->openString("}", $interp, null, array("'", '"', ";")) && $this->openString("}", $interp, null, array("'", '"', ";")) &&
$this->literal("}", false)) $this->literal("}", false)
{ ) {
$out = array("interpolate", $interp); $out = array("interpolate", $interp);
$this->eatWhiteDefault = $oldWhite; $this->eatWhiteDefault = $oldWhite;
if ($this->eatWhiteDefault) $this->whitespace(); if ($this->eatWhiteDefault) $this->whitespace();
@ -3016,7 +3124,9 @@ class lessc_parser {
// delimiter. // delimiter.
protected function argumentDef(&$args, &$isVararg) { protected function argumentDef(&$args, &$isVararg) {
$s = $this->seek(); $s = $this->seek();
if (!$this->literal('(')) return false; if (!$this->literal('(')) {
return false;
}
$values = array(); $values = array();
$delim = ","; $delim = ",";
@ -3045,7 +3155,9 @@ class lessc_parser {
} }
$values[] = $arg; $values[] = $arg;
if ($isVararg) break; if ($isVararg) {
break;
}
continue; continue;
} else { } else {
$values[] = array("lit", $value); $values[] = array("lit", $value);
@ -3134,7 +3246,9 @@ class lessc_parser {
$this->literal(">"); $this->literal(">");
} }
if (count($tags) == 0) return false; if (!$tags) {
return false;
}
return true; return true;
} }
@ -3211,11 +3325,11 @@ class lessc_parser {
// a space separated list of selectors // a space separated list of selectors
protected function tag(&$tag, $simple = false) { protected function tag(&$tag, $simple = false) {
if ($simple) if ($simple) {
$chars = '^@,:;{}\][>\(\) "\''; $chars = '^@,:;{}\][>\(\) "\'';
else } else {
$chars = '^@,;{}["\''; $chars = '^@,;{}["\'';
}
$s = $this->seek(); $s = $this->seek();
$hasExpression = false; $hasExpression = false;
@ -3320,8 +3434,8 @@ class lessc_parser {
protected function variable(&$name) { protected function variable(&$name) {
$s = $this->seek(); $s = $this->seek();
if ($this->literal($this->lessc->vPrefix, false) && if ($this->literal($this->lessc->vPrefix, false) &&
($this->variable($sub) || $this->keyword($name))) ($this->variable($sub) || $this->keyword($name))
{ ) {
if (!empty($sub)) { if (!empty($sub)) {
$name = array('variable', $sub); $name = array('variable', $sub);
} else { } else {
@ -3764,5 +3878,3 @@ class lessc_formatter_lessjs extends lessc_formatter_classic {
public $assignSeparator = ": "; public $assignSeparator = ": ";
public $selectorSeparator = ","; public $selectorSeparator = ",";
} }

4
vendor/leafo/lessphp/lessify vendored Normal file → Executable file
View file

@ -1,4 +1,4 @@
#!/usr/bin/php #!/usr/bin/env php
<?php <?php
if (php_sapi_name() != "cli") { if (php_sapi_name() != "cli") {
@ -19,5 +19,3 @@ try {
} catch (exception $e) { } catch (exception $e) {
exit("Fatal error: ".$e->getMessage()."\n"); exit("Fatal error: ".$e->getMessage()."\n");
} }

View file

@ -21,25 +21,27 @@ require "lessc.inc.php";
// //
class easyparse { class easyparse {
var $buffer; public $buffer;
var $count; public $count;
function __construct($str) { public function __construct($str) {
$this->count = 0; $this->count = 0;
$this->buffer = trim($str); $this->buffer = trim($str);
} }
function seek($where = null) { public function seek($where = null) {
if ($where === null) return $this->count; if ($where === null) {
else $this->count = $where; return $this->count;
}
$this->count = $where;
return true; return true;
} }
function preg_quote($what) { public function preg_quote($what) {
return preg_quote($what, '/'); return preg_quote($what, '/');
} }
function match($regex, &$out, $eatWhitespace = true) { public function match($regex, &$out, $eatWhitespace = true) {
$r = '/'.$regex.($eatWhitespace ? '\s*' : '').'/Ais'; $r = '/'.$regex.($eatWhitespace ? '\s*' : '').'/Ais';
if (preg_match($r, $this->buffer, $out, null, $this->count)) { if (preg_match($r, $this->buffer, $out, null, $this->count)) {
$this->count += strlen($out[0]); $this->count += strlen($out[0]);
@ -48,17 +50,17 @@ class easyparse {
return false; return false;
} }
function literal($what, $eatWhitespace = true) { public function literal($what, $eatWhitespace = true) {
// this is here mainly prevent notice from { } string accessor // this is here mainly prevent notice from { } string accessor
if ($this->count >= strlen($this->buffer)) return false; if ($this->count >= strlen($this->buffer)) return false;
// shortcut on single letter // shortcut on single letter
if (!$eatWhitespace and strlen($what) == 1) { if (!$eatWhitespace and strlen($what) === 1) {
if ($this->buffer{$this->count} == $what) { if ($this->buffer{$this->count} == $what) {
$this->count++; $this->count++;
return true; return true;
} }
else return false; return false;
} }
return $this->match($this->preg_quote($what), $m, $eatWhitespace); return $this->match($this->preg_quote($what), $m, $eatWhitespace);
@ -70,7 +72,7 @@ class tagparse extends easyparse {
static private $combinators = null; static private $combinators = null;
static private $match_opts = null; static private $match_opts = null;
function parse() { public function parse() {
if (empty(self::$combinators)) { if (empty(self::$combinators)) {
self::$combinators = '(' . implode('|', array_map(array($this, 'preg_quote'), self::$combinators = '(' . implode('|', array_map(array($this, 'preg_quote'),
array('+', '>', '~'))).')'; array('+', '>', '~'))).')';
@ -82,29 +84,31 @@ class tagparse extends easyparse {
$this->buffer = preg_replace('/\s+/', ' ', $this->buffer) . ' '; $this->buffer = preg_replace('/\s+/', ' ', $this->buffer) . ' ';
$tags = array(); $tags = array();
while ($this->tag($t)) $tags[] = $t; while ($this->tag($t)) {
$tags[] = $t;
}
return $tags; return $tags;
} }
static function compileString($string) { public static function compileString($string) {
list(, $delim, $str) = $string; list(, $delim, $str) = $string;
$str = str_replace($delim, "\\" . $delim, $str); $str = str_replace($delim, "\\" . $delim, $str);
$str = str_replace("\n", "\\\n", $str); $str = str_replace("\n", "\\\n", $str);
return $delim . $str . $delim; return $delim . $str . $delim;
} }
static function compilePaths($paths) { public static function compilePaths($paths) {
return implode(', ', array_map(array('self', 'compilePath'), $paths)); return implode(', ', array_map(array('self', 'compilePath'), $paths));
} }
// array of tags // array of tags
static function compilePath($path) { public static function compilePath($path) {
return implode(' ', array_map(array('self', 'compileTag'), $path)); return implode(' ', array_map(array('self', 'compileTag'), $path));
} }
static function compileTag($tag) { public static function compileTag($tag) {
ob_start(); ob_start();
if (isset($tag['comb'])) echo $tag['comb'] . " "; if (isset($tag['comb'])) echo $tag['comb'] . " ";
if (isset($tag['front'])) echo $tag['front']; if (isset($tag['front'])) echo $tag['front'];
@ -118,7 +122,7 @@ class tagparse extends easyparse {
return ob_get_clean(); return ob_get_clean();
} }
function string(&$out) { public function string(&$out) {
$s = $this->seek(); $s = $this->seek();
if ($this->literal('"')) { if ($this->literal('"')) {
@ -179,7 +183,7 @@ class tagparse extends easyparse {
return false; return false;
} }
function tag(&$out) { public function tag(&$out) {
$s = $this->seek(); $s = $this->seek();
$tag = array(); $tag = array();
if ($this->combinator($op)) $tag['comb'] = $op; if ($this->combinator($op)) $tag['comb'] = $op;
@ -219,7 +223,7 @@ class tagparse extends easyparse {
return false; return false;
} }
function ident(&$out) { public function ident(&$out) {
// [-]?{nmstart}{nmchar}* // [-]?{nmstart}{nmchar}*
// nmstart: [_a-z]|{nonascii}|{escape} // nmstart: [_a-z]|{nonascii}|{escape}
// nmchar: [_a-z0-9-]|{nonascii}|{escape} // nmchar: [_a-z0-9-]|{nonascii}|{escape}
@ -230,7 +234,7 @@ class tagparse extends easyparse {
return false; return false;
} }
function value(&$out) { public function value(&$out) {
if ($this->string($str)) { if ($this->string($str)) {
$out = $this->compileString($str); $out = $this->compileString($str);
return true; return true;
@ -242,7 +246,7 @@ class tagparse extends easyparse {
} }
function combinator(&$op) { public function combinator(&$op) {
if ($this->match(self::$combinators, $m)) { if ($this->match(self::$combinators, $m)) {
$op = $m[1]; $op = $m[1];
return true; return true;
@ -252,18 +256,18 @@ class tagparse extends easyparse {
} }
class nodecounter { class nodecounter {
var $count = 0; public $count = 0;
var $children = array(); public $children = array();
var $name; public $name;
var $child_blocks; public $child_blocks;
var $the_block; public $the_block;
function __construct($name) { public function __construct($name) {
$this->name = $name; $this->name = $name;
} }
function dump($stack = null) { public function dump($stack = null) {
if (is_null($stack)) $stack = array(); if (is_null($stack)) $stack = array();
$stack[] = $this->getName(); $stack[] = $this->getName();
echo implode(' -> ', $stack) . " ($this->count)\n"; echo implode(' -> ', $stack) . " ($this->count)\n";
@ -272,7 +276,7 @@ class nodecounter {
} }
} }
static function compileProperties($c, $block) { public static function compileProperties($c, $block) {
foreach ($block as $name => $value) { foreach ($block as $name => $value) {
if ($c->isProperty($name, $value)) { if ($c->isProperty($name, $value)) {
echo $c->compileProperty($name, $value) . "\n"; echo $c->compileProperty($name, $value) . "\n";
@ -280,7 +284,7 @@ class nodecounter {
} }
} }
function compile($c, $path = null) { public function compile($c, $path = null) {
if (is_null($path)) $path = array(); if (is_null($path)) $path = array();
$path[] = $this->name; $path[] = $this->name;
@ -318,12 +322,12 @@ class nodecounter {
} }
function getName() { public function getName() {
if (is_null($this->name)) return "[root]"; if (is_null($this->name)) return "[root]";
else return $this->name; else return $this->name;
} }
function getNode($name) { public function getNode($name) {
if (!isset($this->children[$name])) { if (!isset($this->children[$name])) {
$this->children[$name] = new nodecounter($name); $this->children[$name] = new nodecounter($name);
} }
@ -331,7 +335,7 @@ class nodecounter {
return $this->children[$name]; return $this->children[$name];
} }
function findNode($path) { public function findNode($path) {
$current = $this; $current = $this;
for ($i = 0; $i < count($path); $i++) { for ($i = 0; $i < count($path); $i++) {
$t = tagparse::compileTag($path[$i]); $t = tagparse::compileTag($path[$i]);
@ -341,7 +345,7 @@ class nodecounter {
return $current; return $current;
} }
function addBlock($path, $block) { public function addBlock($path, $block) {
$node = $this->findNode($path); $node = $this->findNode($path);
if (!is_null($node->the_block)) throw new exception("can this happen?"); if (!is_null($node->the_block)) throw new exception("can this happen?");
@ -349,7 +353,7 @@ class nodecounter {
$node->the_block = $block; $node->the_block = $block;
} }
function addToNode($path, $block) { public function addToNode($path, $block) {
$node = $this->findNode($path); $node = $this->findNode($path);
$node->child_blocks[] = $block; $node->child_blocks[] = $block;
} }

0
vendor/leafo/lessphp/package.sh vendored Normal file → Executable file
View file

8
vendor/leafo/lessphp/phpunit.xml.dist vendored Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<testsuites>
<testsuite>
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>

2
vendor/leafo/lessphp/plessc vendored Normal file → Executable file
View file

@ -246,5 +246,3 @@ try {
err($fa.$ex->getMessage()); err($fa.$ex->getMessage());
exit(1); exit(1);
} }
?>

View file

@ -2,7 +2,7 @@
require_once __DIR__ . "/../lessc.inc.php"; require_once __DIR__ . "/../lessc.inc.php";
class ApiTest extends PHPUnit_Framework_TestCase { class ApiTest extends PHPUnit\Framework\TestCase {
public function setUp() { public function setUp() {
$this->less = new lessc(); $this->less = new lessc();
$this->less->importDir = array(__DIR__ . "/inputs/test-imports"); $this->less->importDir = array(__DIR__ . "/inputs/test-imports");

View file

@ -1,7 +1,7 @@
<?php <?php
require_once __DIR__ . "/../lessc.inc.php"; require_once __DIR__ . "/../lessc.inc.php";
class ErrorHandlingTest extends PHPUnit_Framework_TestCase { class ErrorHandlingTest extends PHPUnit\Framework\TestCase {
public function setUp() { public function setUp() {
$this->less = new lessc(); $this->less = new lessc();
} }

View file

@ -12,7 +12,7 @@ function _quote($str) {
return preg_quote($str, "/"); return preg_quote($str, "/");
} }
class InputTest extends PHPUnit_Framework_TestCase { class InputTest extends PHPUnit\Framework\TestCase {
protected static $importDirs = array("inputs/test-imports"); protected static $importDirs = array("inputs/test-imports");
protected static $testDirs = array( protected static $testDirs = array(
@ -49,8 +49,10 @@ class InputTest extends PHPUnit_Framework_TestCase {
} }
public function fileNameProvider() { public function fileNameProvider() {
return array_map(function($a) { return array($a); }, return array_map(
self::findInputNames()); function($a) { return array($a); },
self::findInputNames()
);
} }
// only run when env is set // only run when env is set
@ -59,7 +61,7 @@ class InputTest extends PHPUnit_Framework_TestCase {
file_put_contents(self::outputNameFor($inFname), $css); file_put_contents(self::outputNameFor($inFname), $css);
} }
static public function findInputNames($pattern="*.less") { public static function findInputNames($pattern="*.less") {
$files = array(); $files = array();
foreach (self::$testDirs as $inputDir => $outputDir) { foreach (self::$testDirs as $inputDir => $outputDir) {
$files = array_merge($files, glob(__DIR__ . "/" . $inputDir . "/" . $pattern)); $files = array_merge($files, glob(__DIR__ . "/" . $inputDir . "/" . $pattern));
@ -68,7 +70,7 @@ class InputTest extends PHPUnit_Framework_TestCase {
return array_filter($files, "is_file"); return array_filter($files, "is_file");
} }
static public function outputNameFor($input) { public static function outputNameFor($input) {
$front = _quote(__DIR__ . "/"); $front = _quote(__DIR__ . "/");
$out = preg_replace("/^$front/", "", $input); $out = preg_replace("/^$front/", "", $input);
@ -86,4 +88,3 @@ class InputTest extends PHPUnit_Framework_TestCase {
return __DIR__ . "/" . $out; return __DIR__ . "/" . $out;
} }
} }

View file

@ -1,4 +1,4 @@
lessphp uses [phpunit](https://github.com/sebastianbergmann/phpunit/) for its tests lessphp uses [PHPUnit](https://github.com/sebastianbergmann/phpunit/) for its tests
* `InputTest.php` iterates through all the less files in `inputs/`, compiles * `InputTest.php` iterates through all the less files in `inputs/`, compiles
them, then compares the result with the respective file in `outputs/`. them, then compares the result with the respective file in `outputs/`.

0
vendor/leafo/lessphp/tests/bootstrap.sh vendored Normal file → Executable file
View file

View file

@ -37,6 +37,11 @@ body {
two1: fadeout(#029f23, 10%); two1: fadeout(#029f23, 10%);
two2: fadein(#029f23, -10%); two2: fadein(#029f23, -10%);
tint1: tint(#e0e0e0);
tint2: tint(#e0e0e0, 40%);
shade1: shade(#e0e0e0);
shade2: shade(#e0e0e0, 40%);
three1: fadein(rgba(1,2,3, 0.5), 10%); three1: fadein(rgba(1,2,3, 0.5), 10%);
three2: fadeout(rgba(1,2,3, 0.5), -10%); three2: fadeout(rgba(1,2,3, 0.5), -10%);
@ -95,6 +100,10 @@ fade {
color2: contrast(#fff, red, blue); color2: contrast(#fff, red, blue);
} }
.luma {
color: luma(rgb(100, 200, 30));
}
.percent { .percent {
per: percentage(0.5); per: percentage(0.5);
} }

View file

@ -26,6 +26,10 @@ body {
one2: #abcdef; one2: #abcdef;
two1: rgba(2,159,35,0.9); two1: rgba(2,159,35,0.9);
two2: rgba(2,159,35,0.9); two2: rgba(2,159,35,0.9);
tint1: #f0f0f0;
tint2: #ececec;
shade1: #707070;
shade2: #868686;
three1: rgba(1,2,3,0.6); three1: rgba(1,2,3,0.6);
three2: rgba(1,2,3,0.6); three2: rgba(1,2,3,0.6);
four1: rgba(1,2,3,0); four1: rgba(1,2,3,0);
@ -65,6 +69,9 @@ fade {
color1: #ff0000; color1: #ff0000;
color2: #0000ff; color2: #0000ff;
} }
.luma {
color: 44.11161568%;
}
.percent { .percent {
per: 50%; per: 50%;
} }

View file

@ -15,7 +15,7 @@ class lesscNormalized extends lessc {
public $numberPrecision = 3; public $numberPrecision = 3;
public function compileValue($value) { public function compileValue($value) {
if ($value[0] == "raw_color") { if ($value[0] === "raw_color") {
$value = $this->coerceColor($value); $value = $this->coerceColor($value);
} }
@ -24,7 +24,7 @@ class lesscNormalized extends lessc {
} }
class SortingFormatter extends lessc_formatter_lessjs { class SortingFormatter extends lessc_formatter_lessjs {
function sortKey($block) { public function sortKey($block) {
if (!isset($block->sortKey)) { if (!isset($block->sortKey)) {
sort($block->selectors, SORT_STRING); sort($block->selectors, SORT_STRING);
$block->sortKey = implode(",", $block->selectors); $block->sortKey = implode(",", $block->selectors);
@ -33,7 +33,7 @@ class SortingFormatter extends lessc_formatter_lessjs {
return $block->sortKey; return $block->sortKey;
} }
function sortBlock($block) { public function sortBlock($block) {
usort($block->children, function($a, $b) { usort($block->children, function($a, $b) {
$sort = strcmp($this->sortKey($a), $this->sortKey($b)); $sort = strcmp($this->sortKey($a), $this->sortKey($b));
if ($sort == 0) { if ($sort == 0) {
@ -44,7 +44,7 @@ class SortingFormatter extends lessc_formatter_lessjs {
} }
function block($block) { public function block($block) {
$this->sortBlock($block); $this->sortBlock($block);
return parent::block($block); return parent::block($block);
} }
@ -54,4 +54,3 @@ class SortingFormatter extends lessc_formatter_lessjs {
$less = new lesscNormalized(); $less = new lesscNormalized();
$less->setFormatter(new SortingFormatter); $less->setFormatter(new SortingFormatter);
echo $less->parse(file_get_contents($fname)); echo $less->parse(file_get_contents($fname));