44 *
55 * Tool for sorting CSS properties in specific order
66 *
7- * @version 2.12 (build e784736-1301040046 )
7+ * @version 2.13 (build bb516f2-1306162139 )
88 * @author Vyacheslav Oliyanchuk (miripiruni) <mail@csscomb.com>
99 * @license MIT
1010 * @web http://csscomb.com/
@@ -213,8 +213,13 @@ class csscomb{
213213 "-ms-background-position-y",
214214 "background-position-x",
215215 "background-position-y",
216+ "-webkit-background-clip",
217+ "-moz-background-clip",
216218 "background-clip",
217219 "background-origin",
220+ "-webkit-background-size",
221+ "-moz-background-size",
222+ "-o-background-size",
218223 "background-size",
219224 "background-repeat",
220225 "box-decoration-break",
@@ -687,8 +692,13 @@ class csscomb{
687692 "-ms-background-position-x",
688693 "background-position-y",
689694 "-ms-background-position-y",
695+ "-webkit-background-clip",
696+ "-moz-background-clip",
690697 "background-clip",
691698 "background-origin",
699+ "-webkit-background-size",
700+ "-moz-background-size",
701+ "-o-background-size",
692702 "background-size",
693703 "box-decoration-break",
694704 "-webkit-box-shadow",
@@ -903,7 +913,7 @@ function preprocess() {
903913 $ pos = strpos ($ this ->code ['edited ' ], $ value );
904914 if ($ pos !== false ) {
905915 $ this ->code ['edited ' ] = substr_replace ($ this ->code ['edited ' ],"interpolation " .$ key .'__ ' ,$ pos ,strlen ($ value ));
906- }
916+ }
907917 }
908918
909919 // 5. Закрываем сложности парсинга {}
@@ -1089,7 +1099,14 @@ function parse_rules() {
10891099 if ($ this ->mode === 'properties ' ) {
10901100 $ this ->code ['edited ' ] = "\n" .$ this ->code ['edited ' ];
10911101 $ this ->code ['resorted ' ] = $ this ->parse_child ($ this ->code ['edited ' ]);
1092- $ this ->code ['resorted ' ] = substr ($ this ->code ['resorted ' ], 1 );
1102+ // Remove first line if it's empty
1103+ if (strpos ($ this ->code ['resorted ' ], "\n" ) === 0 ) {
1104+ $ this ->code ['resorted ' ] = substr ($ this ->code ['resorted ' ], 1 );
1105+ }
1106+ // Remove all new lines if css initially didn't have any
1107+ if (substr_count ($ this ->code ['edited ' ], "\n" ) === 1 ) {
1108+ $ this ->code ['resorted ' ] = str_replace ("\n" , '' , $ this ->code ['resorted ' ]);
1109+ }
10931110 }
10941111 }
10951112
@@ -1180,15 +1197,15 @@ function parse_child($value = '') {
11801197 preg_match_all ('@
11811198 (^\s*\@[^;]+?[;])|(^\s*\.[^;:]+?[;])
11821199 @isx ' , $ value , $ first_imports );
1183- foreach ($ first_imports [0 ] as &$ first_import ) {
1184- $ value = str_replace ($ first_import , '' , $ value );
1185- }
11861200
11871201 // Все остальные
11881202 preg_match_all ('@
11891203 (?<=[;}])(\s*\@[^;]+?[;])|(?<=[;}])(\s*\.[^;:]+?[;])
11901204 @ismx ' , $ value , $ imports );
11911205 // Удаляем их из общей строки
1206+ foreach ($ first_imports [0 ] as &$ first_import ) {
1207+ $ value = str_replace ($ first_import , '' , $ value );
1208+ }
11921209 foreach ($ imports [1 ] as &$ import ) {
11931210 $ value = str_replace ($ import , '' , $ value );
11941211 }
@@ -1204,14 +1221,14 @@ function parse_child($value = '') {
12041221 @ismx ' , $ value , $ properties );
12051222 // Удаляем их из общей строки
12061223 foreach ($ properties [0 ] as &$ property ) {
1207- $ value = str_replace ($ property , '' , $ value );
1224+ $ value = str_replace ($ property , '' , $ value );
12081225 }
12091226 // Сортируем свойства
12101227 $ props = $ properties [0 ];
12111228 $ props = $ this ->resort_properties ($ props );
12121229
12131230 // 5. Если осталось ещё что-то, оставляем «как есть»
1214-
1231+
12151232 // 6. Склеиваем всё обратно в следующем порядке:
12161233 // переменные, включения, простые свойства, вложенные {}
12171234 $ value = implode ('' , $ vars [0 ]).implode ('' , $ first_imports [0 ]).implode ('' , $ imports [1 ]).implode ('' , $ imports [2 ]).implode ('' , $ block_imports ).implode ('' , $ props ).$ nested_string .$ value ;
@@ -1432,7 +1449,11 @@ function resort_properties($prop) {
14321449 if (count ($ resorted ) > 0 ) { // Если свойства разделены на группы
14331450 $ resorted = $ this ->separate_property_group ($ resorted );
14341451 }
1435- if (count ($ undefined ) > 0 ) {
1452+ if (
1453+ count ($ undefined ) > 0 AND
1454+ // проверяем, что $undefined[0] не начинается с пустой строки
1455+ substr_count (substr ($ undefined [0 ], 0 , 2 ), "\n\n" ) === 0
1456+ ) {
14361457 $ undefined [0 ] = "\n" .$ undefined [0 ];
14371458 }
14381459 }
@@ -1500,7 +1521,7 @@ function postprocess() {
15001521 .*?[^;]
15011522 ;)
15021523 #ismx ' ,
1503- '/* $1 */ ' ,
1524+ '/*$1 */ ' ,
15041525 $ this ->code ['resorted ' ]
15051526 );
15061527 }
0 commit comments