From: GoalSmashers Date: Sat, 17 Nov 2012 23:03:09 +0000 (+0000) Subject: Added collapsing (margin|padding|border-width) with 2 values into one, e.g. padding... X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=88daadfcf41b37a52abf3ee4a879b19ab8a143e5;p=clean-css.git Added collapsing (margin|padding|border-width) with 2 values into one, e.g. padding:1px 1px => padding:1px --- diff --git a/lib/clean.js b/lib/clean.js index f010cf7e..a4a1ddd5 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -159,7 +159,7 @@ var CleanCSS = { replace(/:0 0 0 0([^\.])/g, ':0$1'); replace(/([: ,=\-])0\.(\d)/g, '$1.$2'); - // same values into one + // same 4 values into one replace(/(padding|margin|border\-width):([\d\w\.%]+) ([\d\w\.%]+) ([\d\w\.%]+) ([\d\w\.%]+)/g, function(match, property, size1, size2, size3, size4) { if (size1 === size2 && size1 === size3 && size1 === size4) return property + ":" + size1; @@ -167,6 +167,14 @@ var CleanCSS = { return match; }); + // same 2 values into one + replace(/(padding|margin|border\-width):([\d\w\.%]+) ([\d\w\.%]+)([;}])/g, function(match, property, size1, size2, suffix) { + if (size1 === size2) + return property + ":" + size1 + suffix; + else + return match; + }); + // restore rect(...) zeros syntax for 4 zeros replace(/rect\(\s?0(\s|,)0[ ,]0[ ,]0\s?\)/g, 'rect(0$10$10$10)'); diff --git a/test/data/big-min.css b/test/data/big-min.css index 7e4793ae..71d7f7fd 100644 --- a/test/data/big-min.css +++ b/test/data/big-min.css @@ -511,7 +511,7 @@ article .liste_carre_999{margin-top:5px} .fleuve .twit .texte_twit .nom,.article .twit .texte_twit .nom{display:block;color:#41c8f5;font-weight:700} .fleuve .grid_3.titre_video{font-weight:700} .fleuve section article{margin-bottom:0} -.saisie{background-color:#f8f9fb;border:1px solid #b9c0c5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;padding:3px 3px;font-size:1.2rem;color:#747b83;outline:0} +.saisie{background-color:#f8f9fb;border:1px solid #b9c0c5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;padding:3px;font-size:1.2rem;color:#747b83;outline:0} .saisie:focus{border-color:#8b9299} .radio_ou_checkbox,input[type="radio"],input[type="checkbox"]{cursor:pointer} input[type="radio"],input[type="checkbox"]{vertical-align:bottom;margin-bottom:.2rem} diff --git a/test/unit-test.js b/test/unit-test.js index 193dec1b..ed18a27f 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -265,18 +265,30 @@ vows.describe('clean-units').addBatch({ ] }), 'shorthands': cssContext({ - 'padding - same values': [ + 'padding - same 4 values': [ 'div{padding:1px 1px 1px 1px}', 'div{padding:1px}' ], - 'margin - same values': [ + 'margin - same 4 values': [ 'div{margin:1% 1% 1% 1%}', 'div{margin:1%}' ], - 'border-width - same values': [ + 'border-width - same 4 values': [ 'div{border-width:1em 1em 1em 1em}', 'div{border-width:1em}' ], + 'padding - same 2 values': [ + 'div{padding:1px 1px}', + 'div{padding:1px}' + ], + 'margin - same 2 values': [ + 'div{margin:5% 5%}', + 'div{margin:5%}' + ], + 'border-width - same 2 values': [ + 'div{border-width:.5em .5em}', + 'div{border-width:.5em}' + ], 'different units': 'div{padding:1px 1em 1% 1rem}', 'fractions': [ 'div{margin:.1em .1em .1em .1em}',