Skip to content

Commit

Permalink
On par with clean-css 2.0.4.
Browse files Browse the repository at this point in the history
* Adds normalization to HSL color space.
  • Loading branch information
Jakub Pawlowicz committed Dec 19, 2013
1 parent 7e562b5 commit e826399
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions clean-css.js
Expand Up @@ -10,7 +10,7 @@ var options = {
};
var cleanOptions = {};
var fromStdin = !process.env['__DIRECT__'] && !process.stdin.isTTY;
var version = '2.0.3';
var version = '2.0.4';

// Arguments parsing (to drop optimist dependency)
var argv = process.argv.slice(2);
Expand Down Expand Up @@ -139,8 +139,22 @@ function ColorHSLToHex(data) {
var hslToRgb = function(h, s, l) {
var r, g, b;

// normalize hue orientation b/w 0 and 360 degrees
h = h % 360;
if (h < 0)
h += 360;
h = ~~h / 360;

if (s < 0)
s = 0;
else if (s > 100)
s = 100;
s = ~~s / 100;

if (l < 0)
l = 0;
else if (l > 100)
l = 100;
l = ~~l / 100;

if (s === 0) {
Expand Down Expand Up @@ -169,7 +183,7 @@ function ColorHSLToHex(data) {

return {
process: function() {
return data.replace(/hsl\((\d+),(\d+)%?,(\d+)%?\)/g, function(match, hue, saturation, lightness) {
return data.replace(/hsl\((-?\d+),(-?\d+)%?,(-?\d+)%?\)/g, function(match, hue, saturation, lightness) {
var asRgb = hslToRgb(hue, saturation, lightness);
var redAsHex = asRgb[0].toString(16);
var greenAsHex = asRgb[1].toString(16);
Expand Down
2 changes: 1 addition & 1 deletion test/binary-test.js
Expand Up @@ -49,7 +49,7 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({
}),
'version': binaryContext('-v', {
'should output help': function(error, stdout) {
assert.equal(stdout, '2.0.3\n');
assert.equal(stdout, '2.0.4\n');
}
}),
'stdin': pipedContext('a{color: #f00}', '', {
Expand Down

0 comments on commit e826399

Please sign in to comment.