Skip to content

Commit

Permalink
Version 2.4.8-1
Browse files Browse the repository at this point in the history
Enjoy!
  • Loading branch information
tubalmartin committed Aug 8, 2013
1 parent 55b003a commit 9bff809
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 32 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This port is based on version 2.4.8 (Jun 12, 2013) of the [YUI compressor](https
3. [Unit Tests](#unittests)
4. [API Reference](#api)
5. [Who uses this?](#whousesit)
6. [TODOs](#todos)
6. [Changelog](#changelog)

<a name="howtouse"></a>

Expand Down Expand Up @@ -90,6 +90,7 @@ echo $output_css1 . $output_css2;
* Spaces surrounding the `+` operator in `calc()` calculations are not removed. YUI removes them and that is wrong.
* Fix for issue [#2528093](http://yuilibrary.com/projects/yuicompressor/ticket/2528093).
* Fixes for `!important` related issues.
* Fixes @keyframes 0% step bug.

<a name="enhancements"></a>

Expand All @@ -103,7 +104,7 @@ echo $output_css1 . $output_css2;
* Colors compression:
* Percentage and negative RGB values are supported i.e. `rgb(100%, 0%, 0%)` gets minified to `red`.
* HSL colors are compressed too, i.e. `hsl(0, 100%, 50%)` gets minified to `red`. HSL angles are wrapped and values are clipped if needed.
* All CSS properties are lowercased.
* All CSS properties are lowercased.


<a name="unittests"></a>
Expand Down Expand Up @@ -226,10 +227,11 @@ Values & notes: [pcre.recursion_limit documentation](http://php.net/manual/en/pc

* [Minify](https://github.com/mrclay/minify) Minify is an HTTP content server. It compresses sources of content (usually files), combines the result and serves it with appropriate HTTP headers.

<a name="changelog"></a>

## 6. Changelog

<a name="todos"></a>
## 6. TODOs
### 2.4.8-1 8 Aug 2013

* Some shorthand optimizations
* Even better colors compression
* Fix for the @keyframes 0% step bug. Tests added.
* LESS compiler upgraded to version 1.4.1
19 changes: 11 additions & 8 deletions cssmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

/*!
* cssmin.php rev ebaf67b 12/06/2013
* Author: Tubal Martin - http://blog.margenn.com/
* Author: Tubal Martin - http://tubalmartin.me/
* Repo: https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port
*
* This is a PHP port of the CSS minification tool distributed with YUICompressor,
* This is a PHP port of the CSS minification tool distributed with YUICompressor,
* itself a port of the cssmin utility by Isaac Schlueter - http://foohack.com/
* Permission is hereby granted to use the PHP version under the same
* conditions as the YUICompressor.
Expand Down Expand Up @@ -289,7 +289,7 @@ private function minify($css, $linebreak_pos)
// But, be careful not to turn "p :link {...}" into "p:link{...}"
// Swap out any pseudo-class colons with the token, and then swap back.
$css = preg_replace_callback('/(?:^|\})(?:(?:[^\{\:])+\:)+(?:[^\{]*\{)/', array($this, 'replace_colon'), $css);

// Remove spaces before the things that should not have spaces before them.
$css = preg_replace('/\s+([\!\{\}\;\:\>\+\(\)\]\~\=,])/', '$1', $css);

Expand Down Expand Up @@ -317,7 +317,7 @@ private function minify($css, $linebreak_pos)
// lower case some common function that can be values
// NOTE: rgb() isn't useful as we replace with #hex later, as well as and() is already done for us
$css = preg_replace_callback('/([:,\( ]\s*)(attr|color-stop|from|rgba|to|url|(?:-(?:atsc|khtml|moz|ms|o|wap|webkit)-)?(?:calc|max|min|(?:repeating-)?(?:linear|radial)-gradient)|-webkit-gradient)/iS', array($this, 'lowercase_common_functions_values'), $css);

// Put the space back in some cases, to support stuff like
// @media screen and (-webkit-min-device-pixel-ratio:0){
$css = preg_replace('/\band\(/i', 'and (', $css);
Expand All @@ -336,6 +336,9 @@ private function minify($css, $linebreak_pos)
// Replace 0 length units 0(px,em,%) with 0.
$css = preg_replace('/(^|[^0-9])(?:0?\.)?0(?:em|ex|ch|rem|vw|vh|vm|vmin|cm|mm|in|px|pt|pc|%|deg|g?rad|m?s|k?hz)/iS', '${1}0', $css);

// 0% step in a keyframe? restore the % unit
$css = preg_replace('/(@[a-z\-]*?keyframes.*?)0\{/iS', '${1}0%{', $css);

// Replace 0 0; or 0 0 0; or 0 0 0 0; with 0.
$css = preg_replace('/\:0(?: 0){1,3}(;|\}| \!)/', ':0$1', $css);

Expand Down Expand Up @@ -638,22 +641,22 @@ private function lowercase_pseudo_first($matches)
return ':first-'. strtolower($matches[1]) .' '. $matches[2];
}

private function lowercase_directives($matches)
private function lowercase_directives($matches)
{
return '@'. strtolower($matches[1]);
}

private function lowercase_pseudo_elements($matches)
private function lowercase_pseudo_elements($matches)
{
return ':'. strtolower($matches[1]);
}

private function lowercase_common_functions($matches)
private function lowercase_common_functions($matches)
{
return ':'. strtolower($matches[1]) .'(';
}

private function lowercase_common_functions_values($matches)
private function lowercase_common_functions_values($matches)
{
return $matches[1] . strtolower($matches[2]);
}
Expand Down
8 changes: 4 additions & 4 deletions gui/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function stripslashes_deep($value) {
$output['originalSize'] = mb_strlen($_POST['css'], '8bit');
$output['compressedSize'] = mb_strlen($output['css'], '8bit');
$output['bytesSaved'] = $output['originalSize'] - $output['compressedSize'];
$output['compressionRatio'] = round(($output['bytesSaved'] * 100) / ($output['originalSize'] === 0 ? 1 : $output['originalSize']), 2);
$output['compressionRatio'] = round(($output['bytesSaved'] * 100) / ($output['originalSize'] === 0 ? 1 : $output['originalSize']), 2);

// Output data
echo json_encode($output);
Expand All @@ -86,7 +86,7 @@ function stripslashes_deep($value) {
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<a class="brand" href="https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port">YUI CSS compressor - PHP <span class="version">v2.4.8</span></a>
<a class="brand" href="https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port">YUI CSS compressor - PHP <span class="version">v2.4.8-1</span></a>
</div>
</div>
</div>
Expand Down Expand Up @@ -116,7 +116,7 @@ function stripslashes_deep($value) {
<legend>LESS</legend>
<p class="control-group">
<label class="checkbox">
<input type="checkbox" id="enable-less" value="1"> Enable compiler <span class="version">v1.3.0</span>
<input type="checkbox" id="enable-less" value="1"> Enable compiler <span class="version">v1.4.1</span>
</label>
</p>
</fieldset>
Expand Down Expand Up @@ -170,7 +170,7 @@ function stripslashes_deep($value) {
</div>
</div>
</div>
<script type="text/javascript" src="third-party/less-1.3.0.min.js"></script>
<script type="text/javascript" src="third-party/less-1.4.1.min.js"></script>
<script type="text/javascript" src="third-party/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="third-party/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="scripts.js"></script>
Expand Down
8 changes: 4 additions & 4 deletions gui/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ $(function(){
, template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>'
, error = [];

content = '<h3>' + (e.message || 'There is an error in your .less file') +
content = '<h3>' + (e.type || "Syntax") + "Error: " + (e.message || 'There is an error in your .less file') +
'</h3>' + '<p>';

errorline = function (e, i, classname) {
if (e.extract[i]) {
error.push(template.replace(/\{line\}/, parseInt(e.line) + (i - 1))
if (e.extract[i] != undefined) {
error.push(template.replace(/\{line\}/, (parseInt(e.line) || 0) + (i - 1))
.replace(/\{class\}/, classname)
.replace(/\{content\}/, e.extract[i]));
}
Expand Down Expand Up @@ -58,7 +58,7 @@ $(function(){
compressionRatio.html(data.compressionRatio);

outputContainer.slideDown('fast');

// Restore button state
compressBtn.button('reset');
}, 'json');
Expand Down
2 changes: 1 addition & 1 deletion gui/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ pre {
/* APP styles */
.version{font-size:10px;font-style: italic;letter-spacing: 2px}

legend{font-size: 15px; line-height: 20px;}
legend{font-size: 15px; line-height: 20px; margin-bottom:0}
.control-group{margin-bottom:12px;}
#output-container{margin-top:18px}
9 changes: 0 additions & 9 deletions gui/third-party/less-1.3.0.min.js

This file was deleted.

11 changes: 11 additions & 0 deletions gui/third-party/less-1.4.1.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions tests/mine/keyframes.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@keyframes anim {
0% { opacity: 0; }
100% { opacity: 1; }
}
@-o-keyframes anim{
0% { opacity: 0; }
100% { opacity: 1; }
}
1 change: 1 addition & 0 deletions tests/mine/keyframes.css.min
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@keyframes anim{0%{opacity:0}100%{opacity:1}}@-o-keyframes anim{0%{opacity:0}100%{opacity:1}}

0 comments on commit 9bff809

Please sign in to comment.