Skip to content

Commit

Permalink
Added better zeros processing for rect(...) syntax (clip property).
Browse files Browse the repository at this point in the history
  • Loading branch information
GoalSmashers committed Oct 28, 2012
1 parent 08076cb commit 39763dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/clean.js
Expand Up @@ -141,7 +141,8 @@ var CleanCSS = {
});

// zero + unit to zero
replace(/(\s|:)0(px|em|ex|cm|mm|in|pt|pc|%)/g, '$1' + '0');
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');

// none to 0
replace(/(border|border-top|border-right|border-bottom|border-left|outline):none/g, '$1:0');
Expand All @@ -150,9 +151,12 @@ var CleanCSS = {
replace(/(background):none([;}])/g, '$1:0$2');

// multiple zeros into one
replace(/0 0 0 0([^\.])/g, '0$1');
replace(/:0 0 0 0([^\.])/g, ':0$1');
replace(/([: ,=\-])0\.(\d)/g, '$1.$2');

// restore rect(...) zeros syntax for 4 zeros
replace(/rect\(\s?0(\s|,)0[ ,]0[ ,]0\s?\)/g, 'rect(0$10$10$10)');

// empty elements
if (options.removeEmpty)
replace(/[^}]+?{\s*?}/g, '');
Expand Down
21 changes: 21 additions & 0 deletions test/unit-test.js
Expand Up @@ -229,6 +229,27 @@ vows.describe('clean-units').addBatch({
'multiple zeros with fractions #2': [
'div{padding:0 0 0 .5em}',
'div{padding:0 0 0 .5em}'
],
'rect zeros #1': 'div{clip:rect(0 0 0 0)}',
'rect zeros #2': [
'div{clip:rect(0px 0px 0px 0px)}',
'div{clip:rect(0 0 0 0)}'
],
'rect zeros #3': [
'div{clip:rect( 0px 0px 0px 0px )}',
'div{clip:rect(0 0 0 0)}'
],
'rect zeros #4': [
'div{clip:rect(0px, 0px, 0px, 0px)}',
'div{clip:rect(0,0,0,0)}'
],
'rect zeros #5': [
'div{clip:rect(0.5% 0px 0px 0px)}',
'div{clip:rect(0.5% 0 0 0)}'
],
'rect zeros #6': [
'div{clip:rect(0px 0px 0px 10px)}',
'div{clip:rect(0 0 0 10px)}'
]
}),
'floats': cssContext({
Expand Down

0 comments on commit 39763dc

Please sign in to comment.