From 31f870decdeedcf28a4eb3bbfd95912534ae6864 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 4 Mar 2021 11:23:45 +0200 Subject: [PATCH 1/6] fixes #29518 --- lib/blocks.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/blocks.php b/lib/blocks.php index 8fbc900d7ecb19..27a090b1d7bc0c 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -291,10 +291,9 @@ function( $a, $b ) { */ function gutenberg_get_minified_styles( $styles ) { $re1 = '(?sx)("(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')|/\\* (?> .*? \\*/ )'; - $re2 = '(?six)("(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')|\\s*+ ; \\s*+ ( } ) \\s*+|\\s*+ ( [*$~^|]?+= | [{};,>~+-] | !important\\b ) \\s*+|( [[(:] ) \\s++|\\s++ ( [])] )|\\s++ ( : ) \\s*+(?!(?>[^{}"\']++|"(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')*+{)|^ \\s++ | \\s++ \\z|(\\s)\\s+'; + $re2 = '(?six)("(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')|\\s*+ ; \\s*+ ( } ) \\s*+|\\s*+ ( [*$~^|]?+= | [{};,>~] | !important\\b ) \\s*+|\\s*([+-])\\s*(?=[^}]*{)|( [[(:] ) \\s++|\\s++ ( [])] )|\\s+(:)(?![^\\}]*\\{)|^ \\s++ | \\s++ \\z|(\\s)\\s+'; - $styles = preg_replace( "%$re1%", '$1', $styles ); - return preg_replace( "%$re2%", '$1$2$3$4$5$6$7', $styles ); + return preg_replace( array( "%{$re1}%", "%{$re2}%" ), array( '$1', '$1$2$3$4$5$6$7$8' ), $styles ); } /** From b1bb5b31b84cc57ef89cd5c25cad539701154c6a Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 4 Mar 2021 11:31:02 +0200 Subject: [PATCH 2/6] Add test for calc() --- phpunit/class-gutenberg-utils-test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpunit/class-gutenberg-utils-test.php b/phpunit/class-gutenberg-utils-test.php index f683cbd6a64fda..e4f67e3157ca90 100644 --- a/phpunit/class-gutenberg-utils-test.php +++ b/phpunit/class-gutenberg-utils-test.php @@ -149,6 +149,10 @@ public function test_gutenberg_get_minified_styles() { }', 'out' => '#foo{content:" ";bar:0}', ), + array( + 'in' => '.foo { width: calc(50% - .625em) }', + 'out' => '.foo{width:calc(50% - .625em)}', // Preserve spaces inside calc(). + ) ); foreach ( $cases as $case ) { From ed2290445c7ccdad3cc64c5c13adaef5876fd38d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 4 Mar 2021 11:32:48 +0200 Subject: [PATCH 3/6] cs --- lib/blocks.php | 2 +- phpunit/class-gutenberg-utils-test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/blocks.php b/lib/blocks.php index 27a090b1d7bc0c..45b12709b897ca 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -293,7 +293,7 @@ function gutenberg_get_minified_styles( $styles ) { $re1 = '(?sx)("(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')|/\\* (?> .*? \\*/ )'; $re2 = '(?six)("(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')|\\s*+ ; \\s*+ ( } ) \\s*+|\\s*+ ( [*$~^|]?+= | [{};,>~] | !important\\b ) \\s*+|\\s*([+-])\\s*(?=[^}]*{)|( [[(:] ) \\s++|\\s++ ( [])] )|\\s+(:)(?![^\\}]*\\{)|^ \\s++ | \\s++ \\z|(\\s)\\s+'; - return preg_replace( array( "%{$re1}%", "%{$re2}%" ), array( '$1', '$1$2$3$4$5$6$7$8' ), $styles ); + return preg_replace( array( "%{$re1}%", "%{$re2}%" ), array( '$1', '$1$2$3$4$5$6$7$8' ), $styles ); } /** diff --git a/phpunit/class-gutenberg-utils-test.php b/phpunit/class-gutenberg-utils-test.php index e4f67e3157ca90..28e853c131335b 100644 --- a/phpunit/class-gutenberg-utils-test.php +++ b/phpunit/class-gutenberg-utils-test.php @@ -152,7 +152,7 @@ public function test_gutenberg_get_minified_styles() { array( 'in' => '.foo { width: calc(50% - .625em) }', 'out' => '.foo{width:calc(50% - .625em)}', // Preserve spaces inside calc(). - ) + ), ); foreach ( $cases as $case ) { From 47e8a02e95ef9ac871ea20e0784977a46399bdf8 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 8 Mar 2021 12:45:05 +0200 Subject: [PATCH 4/6] add more tests --- phpunit/class-gutenberg-utils-test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/phpunit/class-gutenberg-utils-test.php b/phpunit/class-gutenberg-utils-test.php index 28e853c131335b..84ec6af8246d0b 100644 --- a/phpunit/class-gutenberg-utils-test.php +++ b/phpunit/class-gutenberg-utils-test.php @@ -153,6 +153,18 @@ public function test_gutenberg_get_minified_styles() { 'in' => '.foo { width: calc(50% - .625em) }', 'out' => '.foo{width:calc(50% - .625em)}', // Preserve spaces inside calc(). ), + array( + 'in' => '@supports (-webkit-overflow-scrolling: touch) { .foo { background-attachment: scroll; } }', + 'out' => '@supports (-webkit-overflow-scrolling:touch){.foo{background-attachment:scroll}}', + ), + array( + 'in' => '@media (prefers-reduced-motion: reduce) { .foo { background: linear-gradient(-135deg, #7adcb4 0%, #00d082 100%); background-attachment: scroll; animation: components-animate__appear-animation 0.1s cubic-bezier(0, 0, 0.2, 1) 0s; } }', + 'out' => '@media (prefers-reduced-motion:reduce){.foo{background:linear-gradient(-135deg,#7adcb4 0%,#00d082 100%);background-attachment:scroll;animation:components-animate__appear-animation 0.1s cubic-bezier(0,0,0.2,1) 0s}}', + ), + array( + 'in' => '@keyframes components-animate__appear-animation { from { transform: translateY(-2em) scaleY(0) scaleX(0); } to { transform: translateY(0%) scaleY(1) scaleX(1); } }', + 'out' => '@keyframes components-animate__appear-animation{from{transform:translateY(-2em) scaleY(0) scaleX(0)}to{transform:translateY(0%) scaleY(1) scaleX(1)}}', + ), ); foreach ( $cases as $case ) { From 85fb5888721c889c04a503a75c193e529d64936b Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 8 Mar 2021 14:33:13 +0200 Subject: [PATCH 5/6] Add test for css-vars/calc combo --- phpunit/class-gutenberg-utils-test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpunit/class-gutenberg-utils-test.php b/phpunit/class-gutenberg-utils-test.php index 84ec6af8246d0b..881b137c304c16 100644 --- a/phpunit/class-gutenberg-utils-test.php +++ b/phpunit/class-gutenberg-utils-test.php @@ -165,6 +165,10 @@ public function test_gutenberg_get_minified_styles() { 'in' => '@keyframes components-animate__appear-animation { from { transform: translateY(-2em) scaleY(0) scaleX(0); } to { transform: translateY(0%) scaleY(1) scaleX(1); } }', 'out' => '@keyframes components-animate__appear-animation{from{transform:translateY(-2em) scaleY(0) scaleX(0)}to{transform:translateY(0%) scaleY(1) scaleX(1)}}', ), + array( + 'in' => '.selector { --foo: calc( var(--bar, calc(1em - 10px ) ); }', + 'out' => '.selector{--foo:calc(var(--bar,calc(1em - 10px))}', + ) ); foreach ( $cases as $case ) { From 9bf89fdf2e18cc8fe0c45c5aaec646073cabc9c9 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 8 Mar 2021 14:42:40 +0200 Subject: [PATCH 6/6] cs --- phpunit/class-gutenberg-utils-test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit/class-gutenberg-utils-test.php b/phpunit/class-gutenberg-utils-test.php index 881b137c304c16..58d13d28547e4f 100644 --- a/phpunit/class-gutenberg-utils-test.php +++ b/phpunit/class-gutenberg-utils-test.php @@ -168,7 +168,7 @@ public function test_gutenberg_get_minified_styles() { array( 'in' => '.selector { --foo: calc( var(--bar, calc(1em - 10px ) ); }', 'out' => '.selector{--foo:calc(var(--bar,calc(1em - 10px))}', - ) + ), ); foreach ( $cases as $case ) {