From: GoalSmashers Date: Thu, 29 Nov 2012 22:26:31 +0000 (+0000) Subject: Fixed #32 - hsl/hsla colors processing. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=e97d45767172b8e7e5871f2e70119a083520a2fe;p=clean-css.git Fixed #32 - hsl/hsla colors processing. --- diff --git a/lib/clean.js b/lib/clean.js index d9bb4fd2..3188753c 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -144,6 +144,14 @@ var CleanCSS = { replace(/(\s|:|,)0(px|em|ex|cm|mm|in|pt|pc|%)/g, '$1' + '0'); replace(/rect\(0(px|em|ex|cm|mm|in|pt|pc|%)/g, 'rect(0'); + // restore 0% in hsl/hsla + replace(/(hsl|hsla)\(([^\)]+)\)/g, function(match, colorFunction, colorDef) { + var tokens = colorDef.split(','); + if (tokens[1] == "0") tokens[1] = '0%'; + if (tokens[2] == "0") tokens[2] = '0%'; + return colorFunction + "(" + tokens.join(',') + ")"; + }); + // none to 0 replace(/(border|border-top|border-right|border-bottom|border-left|outline):none/g, '$1:0'); diff --git a/test/unit-test.js b/test/unit-test.js index b08cb65d..1ba9cea0 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -304,7 +304,11 @@ vows.describe('clean-units').addBatch({ 'p{border:1px solid #f94311}' ], 'colors and colons': 'a{background-image:linear-gradient(top,red,#e6e6e6)}', - 'colors and parentheses': 'a{background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6))}' + 'colors and parentheses': 'a{background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6))}', + 'hsl percents': 'a{color:hsl(1,0%,0%)}', + 'hsla percents': 'a{color:hsl(1,0%,0%)}', + 'hsl one percent': 'a{color:hsl(80,100%,0%)}', + 'hsla custom ': 'a{color:hsl(80,30%,50%,.5)}', }), 'font weights': cssContext({ 'font-weight:normal to 400': [