From d8e0c96dafa784726ddb1c5adb9d122e517ebad9 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 31 Aug 2020 10:07:54 +0300 Subject: [PATCH 1/7] print minified css for global styles --- lib/global-styles.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/global-styles.php b/lib/global-styles.php index a90815eb36453..e668f50f17944 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -479,13 +479,11 @@ function gutenberg_experimental_global_styles_resolver_styles( $block_selector, // 1) The style attributes the block has declared support for. // 2) Any CSS custom property attached to the node. if ( in_array( $property, $block_supports, true ) || strstr( $property, '--' ) ) { - $css_declarations .= "\t" . $property . ': ' . $value . ";\n"; + $css_declarations .= $property . ': ' . $value . ';'; } } if ( '' !== $css_declarations ) { - $css_rule .= $block_selector . " {\n"; - $css_rule .= $css_declarations; - $css_rule .= "}\n"; + $css_rule .= $block_selector . '{' . $css_declarations . '}'; } return $css_rule; From a834e9326b716acaa31c91d922c86ad6a2d52670 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 31 Aug 2020 10:14:37 +0300 Subject: [PATCH 2/7] remove additional space character --- lib/global-styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/global-styles.php b/lib/global-styles.php index e668f50f17944..a17a07c1cbeb8 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -479,7 +479,7 @@ function gutenberg_experimental_global_styles_resolver_styles( $block_selector, // 1) The style attributes the block has declared support for. // 2) Any CSS custom property attached to the node. if ( in_array( $property, $block_supports, true ) || strstr( $property, '--' ) ) { - $css_declarations .= $property . ': ' . $value . ';'; + $css_declarations .= $property . ':' . $value . ';'; } } if ( '' !== $css_declarations ) { From 05cdb475e443b64ddb1ad1ab390b075c1df3b252 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 31 Aug 2020 10:20:12 +0300 Subject: [PATCH 3/7] simplify return --- lib/global-styles.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/global-styles.php b/lib/global-styles.php index a17a07c1cbeb8..92e9058cbb3c2 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -470,7 +470,6 @@ function gutenberg_experimental_global_styles_resolver( $tree ) { * @return string The corresponding CSS rule. */ function gutenberg_experimental_global_styles_resolver_styles( $block_selector, $block_supports, $block_styles ) { - $css_rule = ''; $css_declarations = ''; foreach ( $block_styles as $property => $value ) { @@ -483,10 +482,10 @@ function gutenberg_experimental_global_styles_resolver_styles( $block_selector, } } if ( '' !== $css_declarations ) { - $css_rule .= $block_selector . '{' . $css_declarations . '}'; + return $block_selector . '{' . $css_declarations . '}'; } - return $css_rule; + return ''; } /** From 3926fc9cc7e1ab6a907538dbdfcda53472360b77 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 3 Sep 2020 19:07:23 +0300 Subject: [PATCH 4/7] This can be simplified --- lib/global-styles.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/global-styles.php b/lib/global-styles.php index 7368a4380c36e..4425e99a601cf 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -481,11 +481,7 @@ function gutenberg_experimental_global_styles_resolver_styles( $block_selector, $css_declarations .= $property . ':' . $value . ';'; } } - if ( '' !== $css_declarations ) { - return $block_selector . '{' . $css_declarations . '}'; - } - - return ''; + return $css_declarations ? $block_selector . '{' . $css_declarations . '}' : ''; } /** From d6242211b6fa3efe272187aa4a1a3facec58a8d2 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 3 Sep 2020 19:10:02 +0300 Subject: [PATCH 5/7] additional tweak --- lib/global-styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/global-styles.php b/lib/global-styles.php index 4425e99a601cf..6739d34ae9599 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -454,7 +454,7 @@ function gutenberg_experimental_global_styles_resolver( $tree ) { // so that existing link colors themes used didn't break. // We add this here to make it work for themes that opt-in to theme.json // In the future, we may do this differently. - $stylesheet .= 'a { color: var(--wp--style--color--link, #00e); }'; + $stylesheet .= 'a{color:var(--wp--style--color--link, #00e);}'; } return $stylesheet; From fc1d668c02d075c6fcce113d30e8e1f8cb8eed33 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 7 Sep 2020 16:03:13 +0300 Subject: [PATCH 6/7] Add SCRIPT_DEBUG checks for whitespace stripping. --- lib/global-styles.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/global-styles.php b/lib/global-styles.php index 6739d34ae9599..78a6b245fdbec 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -470,6 +470,7 @@ function gutenberg_experimental_global_styles_resolver( $tree ) { * @return string The corresponding CSS rule. */ function gutenberg_experimental_global_styles_resolver_styles( $block_selector, $block_supports, $block_styles ) { + $css_rule = ''; $css_declarations = ''; foreach ( $block_styles as $property => $value ) { @@ -478,10 +479,27 @@ function gutenberg_experimental_global_styles_resolver_styles( $block_selector, // 1) The style attributes the block has declared support for. // 2) Any CSS custom property attached to the node. if ( in_array( $property, $block_supports, true ) || strstr( $property, '--' ) ) { - $css_declarations .= $property . ':' . $value . ';'; + + // Add whitespace if SCRIPT_DEBUG is defined and set to true. + $css_declarations .= ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) + ? "\t" . $property . ': ' . $value . ";\n" + : $property . ':' . $value . ';'; } } - return $css_declarations ? $block_selector . '{' . $css_declarations . '}' : ''; + + if ( '' !== $css_declarations ) { + + // Return minified styles if + if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { + $css_rule .= $block_selector . " {\n"; + $css_rule .= $css_declarations; + $css_rule .= "}\n"; + } else { + $css_rule .= $block_selector . '{' . $css_declarations . '}'; + } + } + + return $css_rule; } /** From d3a9b3a0466fc858055141589fb19fbe97aa330d Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Mon, 7 Sep 2020 16:10:57 +0300 Subject: [PATCH 7/7] Fix incomplete inline comment --- lib/global-styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/global-styles.php b/lib/global-styles.php index 78a6b245fdbec..4365d6aaa272f 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -489,7 +489,7 @@ function gutenberg_experimental_global_styles_resolver_styles( $block_selector, if ( '' !== $css_declarations ) { - // Return minified styles if + // Add whitespace if SCRIPT_DEBUG is defined and set to true. if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { $css_rule .= $block_selector . " {\n"; $css_rule .= $css_declarations;