<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[54274] trunk: Editor: Improves layout block support in `wp_get_layout_style()`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/54274">54274</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/54274","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>hellofromTonya</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-09-21 13:00:29 +0000 (Wed, 21 Sep 2022)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Editor: Improves layout block support in `wp_get_layout_style()`.

This commit merges the remaining changes from [https://github.com/WordPress/gutenberg/pull/40875 Gutenberg PR 40875]. It's Part 2 (see <a href="https://core.trac.wordpress.org/changeset/54162">[54162]</a> for Part 1) of a layout improvement initiative and targets `wp_get_layout_style()` in `layout.php`.

Context:
The overall initiative is to improve layout block support:
>to use centralised layout definitions, output base layout styles from global styles, introduce a layout type semantic classname, reduce duplication of container class and style tag output, and fix blockGap at the block level in global styles.

Changes include:
* Adding an optional parameter `$block_spacing` to `wp_get_layout_style()` for setting a custom spacing on the block.
* Adding handle for the block spacing.
* Using the style engine to to enqueue and render layout styles via `wp_style_engine_get_stylesheet_from_css_rules()`.
* Introduces a new test file for `wp_get_layout_style()`.

Follow-up to <a href="https://core.trac.wordpress.org/changeset/54162">[54162]</a>, <a href="https://core.trac.wordpress.org/changeset/54160">[54160]</a>, <a href="https://core.trac.wordpress.org/changeset/54159">[54159]</a>, <a href="https://core.trac.wordpress.org/changeset/53421">[53421]</a>, <a href="https://core.trac.wordpress.org/changeset/52380">[52380]</a>, <a href="https://core.trac.wordpress.org/changeset/53085">[53085]</a>, <a href="https://core.trac.wordpress.org/changeset/52069">[52069]</a>.

Props andrewserong, isabel_brison, costdev, hellofromTonya.
See <a href="https://core.trac.wordpress.org/ticket/56467">#56467</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportslayoutphp">trunk/src/wp-includes/block-supports/layout.php</a></li>
<li><a href="#trunktestsphpunitdatablocksfixturescore__columnserverhtml">trunk/tests/phpunit/data/blocks/fixtures/core__column.server.html</a></li>
<li><a href="#trunktestsphpunitdatablocksfixturescore__columnsserverhtml">trunk/tests/phpunit/data/blocks/fixtures/core__columns.server.html</a></li>
<li><a href="#trunktestsphpunitdatablocksfixturescore__columns__deprecatedserverhtml">trunk/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html</a></li>
<li><a href="#trunktestsphpunitdatablocksfixturescore__galleryserverhtml">trunk/tests/phpunit/data/blocks/fixtures/core__gallery.server.html</a></li>
<li><a href="#trunktestsphpunitdatablocksfixturescore__gallery__columnsserverhtml">trunk/tests/phpunit/data/blocks/fixtures/core__gallery__columns.server.html</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsblocksupportswpGetLayoutStylephp">trunk/tests/phpunit/tests/block-supports/wpGetLayoutStyle.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportslayoutphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/block-supports/layout.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/layout.php   2022-09-21 12:27:33 UTC (rev 54273)
+++ trunk/src/wp-includes/block-supports/layout.php     2022-09-21 13:00:29 UTC (rev 54274)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -33,24 +33,52 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * Generates the CSS corresponding to the provided layout.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 5.9.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.1.0 Added `$block_spacing` param, use style engine to enqueue styles.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @access private
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string  $selector                      CSS selector.
- * @param array   $layout                        Layout object. The one that is passed has already checked
- *                                               the existence of default block layout.
- * @param boolean $has_block_gap_support         Whether the theme has support for the block gap.
- * @param string  $gap_value                     The block gap value to apply.
- * @param boolean $should_skip_gap_serialization Whether to skip applying the user-defined value set in the editor.
- * @param string  $fallback_gap_value            The custom fallback value for block gap.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string               $selector                      CSS selector.
+ * @param array                $layout                        Layout object. The one that is passed has already checked
+ *                                                            the existence of default block layout.
+ * @param boolean              $has_block_gap_support         Whether the theme has support for the block gap.
+ * @param string|string[]|null $gap_value                     Optional. The block gap value to apply. Default null.
+ * @param boolean              $should_skip_gap_serialization Whether to skip applying the user-defined value set in the editor.
+ * @param string               $fallback_gap_value            The block gap value to apply.
+ * @param array|null           $block_spacing                 Optional. Custom spacing set on the block. Default null.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @return string CSS style.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false, $fallback_gap_value = '0.5em' ) {
-       $layout_type = isset( $layout['type'] ) ? $layout['type'] : 'default';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false, $fallback_gap_value = '0.5em', $block_spacing = null ) {
+       $layout_type   = isset( $layout['type'] ) ? $layout['type'] : 'default';
+       $layout_styles = array();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $style = '';
</del><span class="cx" style="display: block; padding: 0 10px">         if ( 'default' === $layout_type ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $content_size = isset( $layout['contentSize'] ) ? $layout['contentSize'] : '';
-               $wide_size    = isset( $layout['wideSize'] ) ? $layout['wideSize'] : '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( $has_block_gap_support ) {
+                       if ( is_array( $gap_value ) ) {
+                               $gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null;
+                       }
+                       if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
+                               array_push(
+                                       $layout_styles,
+                                       array(
+                                               'selector'     => "$selector > *",
+                                               'declarations' => array(
+                                                       'margin-block-start' => '0',
+                                                       'margin-block-end'   => '0',
+                                               ),
+                                       ),
+                                       array(
+                                               'selector'     => "$selector$selector > * + *",
+                                               'declarations' => array(
+                                                       'margin-block-start' => $gap_value,
+                                                       'margin-block-end'   => '0',
+                                               ),
+                                       )
+                               );
+                       }
+               }
+       } elseif ( 'constrained' === $layout_type ) {
+               $content_size    = isset( $layout['contentSize'] ) ? $layout['contentSize'] : '';
+               $wide_size       = isset( $layout['wideSize'] ) ? $layout['wideSize'] : '';
+               $justify_content = isset( $layout['justifyContent'] ) ? $layout['justifyContent'] : 'center';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $all_max_width_value  = $content_size ? $content_size : $wide_size;
</span><span class="cx" style="display: block; padding: 0 10px">                $wide_max_width_value = $wide_size ? $wide_size : $content_size;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -59,27 +87,102 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $all_max_width_value  = safecss_filter_attr( explode( ';', $all_max_width_value )[0] );
</span><span class="cx" style="display: block; padding: 0 10px">                $wide_max_width_value = safecss_filter_attr( explode( ';', $wide_max_width_value )[0] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $margin_left  = 'left' === $justify_content ? '0 !important' : 'auto !important';
+               $margin_right = 'right' === $justify_content ? '0 !important' : 'auto !important';
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( $content_size || $wide_size ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $style  = "$selector > :where(:not(.alignleft):not(.alignright)) {";
-                       $style .= 'max-width: ' . esc_html( $all_max_width_value ) . ';';
-                       $style .= 'margin-left: auto !important;';
-                       $style .= 'margin-right: auto !important;';
-                       $style .= '}';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 array_push(
+                               $layout_styles,
+                               array(
+                                       'selector'     => "$selector > :where(:not(.alignleft):not(.alignright):not(.alignfull))",
+                                       'declarations' => array(
+                                               'max-width'    => $all_max_width_value,
+                                               'margin-left'  => $margin_left,
+                                               'margin-right' => $margin_right,
+                                       ),
+                               ),
+                               array(
+                                       'selector'     => "$selector > .alignwide",
+                                       'declarations' => array( 'max-width' => $wide_max_width_value ),
+                               ),
+                               array(
+                                       'selector'     => "$selector .alignfull",
+                                       'declarations' => array( 'max-width' => 'none' ),
+                               )
+                       );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $style .= "$selector > .alignwide { max-width: " . esc_html( $wide_max_width_value ) . ';}';
-                       $style .= "$selector .alignfull { max-width: none; }";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( isset( $block_spacing ) ) {
+                               $block_spacing_values = wp_style_engine_get_styles(
+                                       array(
+                                               'spacing' => $block_spacing,
+                                       )
+                               );
+
+                               /*
+                                * Handle negative margins for alignfull children of blocks with custom padding set.
+                                * They're added separately because padding might only be set on one side.
+                                */
+                               if ( isset( $block_spacing_values['declarations']['padding-right'] ) ) {
+                                       $padding_right   = $block_spacing_values['declarations']['padding-right'];
+                                       $layout_styles[] = array(
+                                               'selector'     => "$selector > .alignfull",
+                                               'declarations' => array( 'margin-right' => "calc($padding_right * -1)" ),
+                                       );
+                               }
+                               if ( isset( $block_spacing_values['declarations']['padding-left'] ) ) {
+                                       $padding_left    = $block_spacing_values['declarations']['padding-left'];
+                                       $layout_styles[] = array(
+                                               'selector'     => "$selector > .alignfull",
+                                               'declarations' => array( 'margin-left' => "calc($padding_left * -1)" ),
+                                       );
+                               }
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $style .= "$selector > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }";
-               $style .= "$selector > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }";
-               $style .= "$selector > .aligncenter { margin-left: auto !important; margin-right: auto !important; }";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( 'left' === $justify_content ) {
+                       $layout_styles[] = array(
+                               'selector'     => "$selector > :where(:not(.alignleft):not(.alignright):not(.alignfull))",
+                               'declarations' => array( 'margin-left' => '0 !important' ),
+                       );
+               }
+
+               if ( 'right' === $justify_content ) {
+                       $layout_styles[] = array(
+                               'selector'     => "$selector > :where(:not(.alignleft):not(.alignright):not(.alignfull))",
+                               'declarations' => array( 'margin-right' => '0 !important' ),
+                       );
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( $has_block_gap_support ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( is_array( $gap_value ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $gap_style = $gap_value && ! $should_skip_gap_serialization ? $gap_value : 'var( --wp--style--block-gap )';
-                       $style    .= "$selector > * { margin-block-start: 0; margin-block-end: 0; }";
-                       $style    .= "$selector > * + * { margin-block-start: $gap_style; margin-block-end: 0; }";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
+                               // Get spacing CSS variable from preset value if provided.
+                               if ( is_string( $gap_value ) && str_contains( $gap_value, 'var:preset|spacing|' ) ) {
+                                       $index_to_splice = strrpos( $gap_value, '|' ) + 1;
+                                       $slug            = _wp_to_kebab_case( substr( $gap_value, $index_to_splice ) );
+                                       $gap_value       = "var(--wp--preset--spacing--$slug)";
+                               }
+
+                               array_push(
+                                       $layout_styles,
+                                       array(
+                                               'selector'     => "$selector > *",
+                                               'declarations' => array(
+                                                       'margin-block-start' => '0',
+                                                       'margin-block-end'   => '0',
+                                               ),
+                                       ),
+                                       array(
+                                               'selector'     => "$selector$selector > * + *",
+                                               'declarations' => array(
+                                                       'margin-block-start' => $gap_value,
+                                                       'margin-block-end'   => '0',
+                                               ),
+                                       )
+                               );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        } elseif ( 'flex' === $layout_type ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $layout_orientation = isset( $layout['orientation'] ) ? $layout['orientation'] : 'horizontal';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -90,54 +193,102 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'center' => 'center',
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $vertical_alignment_options = array(
+                       'top'    => 'flex-start',
+                       'center' => 'center',
+                       'bottom' => 'flex-end',
+               );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( 'horizontal' === $layout_orientation ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $justify_content_options += array( 'space-between' => 'space-between' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $flex_wrap_options = array( 'wrap', 'nowrap' );
-               $flex_wrap         = ! empty( $layout['flexWrap'] ) && in_array( $layout['flexWrap'], $flex_wrap_options, true ) ?
-                       $layout['flexWrap'] :
-                       'wrap';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! empty( $layout['flexWrap'] ) && 'nowrap' === $layout['flexWrap'] ) {
+                       $layout_styles[] = array(
+                               'selector'     => $selector,
+                               'declarations' => array( 'flex-wrap' => 'nowrap' ),
+                       );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $style  = "$selector {";
-               $style .= 'display: flex;';
-               if ( $has_block_gap_support ) {
-                       if ( is_array( $gap_value ) ) {
-                               $gap_row    = isset( $gap_value['top'] ) ? $gap_value['top'] : $fallback_gap_value;
-                               $gap_column = isset( $gap_value['left'] ) ? $gap_value['left'] : $fallback_gap_value;
-                               $gap_value  = $gap_row === $gap_column ? $gap_row : $gap_row . ' ' . $gap_column;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( $has_block_gap_support && isset( $gap_value ) ) {
+                       $combined_gap_value = '';
+                       $gap_sides          = is_array( $gap_value ) ? array( 'top', 'left' ) : array( 'top' );
+
+                       foreach ( $gap_sides as $gap_side ) {
+                               $process_value = is_string( $gap_value ) ? $gap_value : _wp_array_get( $gap_value, array( $gap_side ), $fallback_gap_value );
+                               // Get spacing CSS variable from preset value if provided.
+                               if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) {
+                                       $index_to_splice = strrpos( $process_value, '|' ) + 1;
+                                       $slug            = _wp_to_kebab_case( substr( $process_value, $index_to_splice ) );
+                                       $process_value   = "var(--wp--preset--spacing--$slug)";
+                               }
+                               $combined_gap_value .= "$process_value ";
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $gap_style = $gap_value && ! $should_skip_gap_serialization ? $gap_value : "var( --wp--style--block-gap, $fallback_gap_value )";
-                       $style    .= "gap: $gap_style;";
-               } else {
-                       $style .= "gap: $fallback_gap_value;";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $gap_value = trim( $combined_gap_value );
+
+                       if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
+                               $layout_styles[] = array(
+                                       'selector'     => $selector,
+                                       'declarations' => array( 'gap' => $gap_value ),
+                               );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $style .= "flex-wrap: $flex_wrap;";
</del><span class="cx" style="display: block; padding: 0 10px">                 if ( 'horizontal' === $layout_orientation ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $style .= 'align-items: center;';
-                       /**
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 /*
</ins><span class="cx" style="display: block; padding: 0 10px">                          * Add this style only if is not empty for backwards compatibility,
</span><span class="cx" style="display: block; padding: 0 10px">                         * since we intend to convert blocks that had flex layout implemented
</span><span class="cx" style="display: block; padding: 0 10px">                         * by custom css.
</span><span class="cx" style="display: block; padding: 0 10px">                         */
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! empty( $layout['justifyContent'] ) && array_key_exists( $layout['justifyContent'], $justify_content_options ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $style .= "justify-content: {$justify_content_options[ $layout['justifyContent'] ]};";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $layout_styles[] = array(
+                                       'selector'     => $selector,
+                                       'declarations' => array( 'justify-content' => $justify_content_options[ $layout['justifyContent'] ] ),
+                               );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                       if ( ! empty( $layout['verticalAlignment'] ) && array_key_exists( $layout['verticalAlignment'], $vertical_alignment_options ) ) {
+                               $layout_styles[] = array(
+                                       'selector'     => $selector,
+                                       'declarations' => array( 'align-items' => $vertical_alignment_options[ $layout['verticalAlignment'] ] ),
+                               );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $style .= 'flex-direction: column;';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $layout_styles[] = array(
+                               'selector'     => $selector,
+                               'declarations' => array( 'flex-direction' => 'column' ),
+                       );
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( ! empty( $layout['justifyContent'] ) && array_key_exists( $layout['justifyContent'], $justify_content_options ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $style .= "align-items: {$justify_content_options[ $layout['justifyContent'] ]};";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $layout_styles[] = array(
+                                       'selector'     => $selector,
+                                       'declarations' => array( 'align-items' => $justify_content_options[ $layout['justifyContent'] ] ),
+                               );
</ins><span class="cx" style="display: block; padding: 0 10px">                         } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $style .= 'align-items: flex-start;';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $layout_styles[] = array(
+                                       'selector'     => $selector,
+                                       'declarations' => array( 'align-items' => 'flex-start' ),
+                               );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $style .= '}';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $style .= "$selector > * { margin: 0; }";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $layout_styles ) ) {
+               /*
+                * Add to the style engine store to enqueue and render layout styles.
+                * Return compiled layout styles to retain backwards compatibility.
+                * Since https://github.com/WordPress/gutenberg/pull/42452,
+                * wp_enqueue_block_support_styles is no longer called in this block supports file.
+                */
+               return wp_style_engine_get_stylesheet_from_css_rules(
+                       $layout_styles,
+                       array(
+                               'context'  => 'block-supports',
+                               'prettify' => false,
+                       )
+               );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        return $style;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return '';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -158,26 +309,43 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return $block_content;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $block_gap             = wp_get_global_settings( array( 'spacing', 'blockGap' ) );
-       $default_layout        = wp_get_global_settings( array( 'layout' ) );
-       $has_block_gap_support = isset( $block_gap ) ? null !== $block_gap : false;
-       $default_block_layout  = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
-       $used_layout           = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $block_gap              = wp_get_global_settings( array( 'spacing', 'blockGap' ) );
+       $global_layout_settings = wp_get_global_settings( array( 'layout' ) );
+       $has_block_gap_support  = isset( $block_gap ) ? null !== $block_gap : false;
+       $default_block_layout   = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
+       $used_layout            = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout;
+
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! $default_layout ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! $global_layout_settings ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return $block_content;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $used_layout = $default_layout;
</del><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $class_names     = array();
-       $container_class = wp_unique_id( 'wp-container-' );
-       $class_names[]   = $container_class;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $class_names        = array();
+       $layout_definitions = _wp_array_get( $global_layout_settings, array( 'definitions' ), array() );
+       $block_classname    = wp_get_block_default_classname( $block['blockName'] );
+       $container_class    = wp_unique_id( 'wp-container-' );
+       $layout_classname   = '';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // The following section was added to reintroduce a small set of layout classnames that were
-       // removed in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719). It is
-       // not intended to provide an extended set of classes to match all block layout attributes
-       // here.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Set the correct layout type for blocks using legacy content width.
+       if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] || isset( $used_layout['contentSize'] ) && $used_layout['contentSize'] ) {
+               $used_layout['type'] = 'constrained';
+       }
+
+       if (
+               wp_get_global_settings( array( 'useRootPaddingAwareAlignments' ) ) &&
+               isset( $used_layout['type'] ) &&
+               'constrained' === $used_layout['type']
+       ) {
+               $class_names[] = 'has-global-padding';
+       }
+
+       /*
+        * The following section was added to reintroduce a small set of layout classnames that were
+        * removed in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719). It is
+        * not intended to provide an extended set of classes to match all block layout attributes
+        * here.
+        */
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( ! empty( $block['attrs']['layout']['orientation'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $class_names[] = 'is-' . sanitize_title( $block['attrs']['layout']['orientation'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -190,26 +358,66 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $class_names[] = 'is-nowrap';
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
-       // Skip if gap value contains unsupported characters.
-       // Regex for CSS value borrowed from `safecss_filter_attr`, and used here
-       // because we only want to match against the value, not the CSS attribute.
-       if ( is_array( $gap_value ) ) {
-               foreach ( $gap_value as $key => $value ) {
-                       $gap_value[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value;
-               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Get classname for layout type.
+       if ( isset( $used_layout['type'] ) ) {
+               $layout_classname = _wp_array_get( $layout_definitions, array( $used_layout['type'], 'className' ), '' );
</ins><span class="cx" style="display: block; padding: 0 10px">         } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $layout_classname = _wp_array_get( $layout_definitions, array( 'default', 'className' ), '' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), '0.5em' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $layout_classname && is_string( $layout_classname ) ) {
+               $class_names[] = sanitize_title( $layout_classname );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // If a block's block.json skips serialization for spacing or spacing.blockGap,
-       // don't apply the user-defined value to the styles.
-       $should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );
-       $style                         = wp_get_layout_style( ".$container_class", $used_layout, $has_block_gap_support, $gap_value, $should_skip_gap_serialization, $fallback_gap_value );
-       // This assumes the hook only applies to blocks with a single wrapper.
-       // I think this is a reasonable limitation for that particular hook.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+        * Only generate Layout styles if the theme has not opted-out.
+        * Attribute-based Layout classnames are output in all cases.
+        */
+       if ( ! current_theme_supports( 'disable-layout-styles' ) ) {
+
+               $gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
+               /*
+                * Skip if gap value contains unsupported characters.
+                * Regex for CSS value borrowed from `safecss_filter_attr`, and used here
+                * to only match against the value, not the CSS attribute.
+                */
+               if ( is_array( $gap_value ) ) {
+                       foreach ( $gap_value as $key => $value ) {
+                               $gap_value[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value;
+                       }
+               } else {
+                       $gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
+               }
+
+               $fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), '0.5em' );
+               $block_spacing      = _wp_array_get( $block, array( 'attrs', 'style', 'spacing' ), null );
+
+               /*
+                * If a block's block.json skips serialization for spacing or spacing.blockGap,
+                * don't apply the user-defined value to the styles.
+                */
+               $should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );
+
+               $style = wp_get_layout_style(
+                       ".$block_classname.$container_class",
+                       $used_layout,
+                       $has_block_gap_support,
+                       $gap_value,
+                       $should_skip_gap_serialization,
+                       $fallback_gap_value,
+                       $block_spacing
+               );
+
+               // Only add container class and enqueue block support styles if unique styles were generated.
+               if ( ! empty( $style ) ) {
+                       $class_names[] = $container_class;
+               }
+       }
+
+       /*
+        * This assumes the hook only applies to blocks with a single wrapper.
+        * A limitation of this hook is that nested inner blocks wrappers are not yet supported.
+        */
</ins><span class="cx" style="display: block; padding: 0 10px">         $content = preg_replace(
</span><span class="cx" style="display: block; padding: 0 10px">                '/' . preg_quote( 'class="', '/' ) . '/',
</span><span class="cx" style="display: block; padding: 0 10px">                'class="' . esc_attr( implode( ' ', $class_names ) ) . ' ',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -217,8 +425,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                1
</span><span class="cx" style="display: block; padding: 0 10px">        );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        wp_enqueue_block_support_styles( $style );
-
</del><span class="cx" style="display: block; padding: 0 10px">         return $content;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunitdatablocksfixturescore__columnserverhtml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/blocks/fixtures/core__column.server.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/blocks/fixtures/core__column.server.html 2022-09-21 12:27:33 UTC (rev 54273)
+++ trunk/tests/phpunit/data/blocks/fixtures/core__column.server.html   2022-09-21 13:00:29 UTC (rev 54274)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,5 +1,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<div class="wp-container-1 wp-block-column">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<div class="is-layout-flow wp-block-column">
</ins><span class="cx" style="display: block; padding: 0 10px">         
</span><span class="cx" style="display: block; padding: 0 10px">        <p>Column One, Paragraph One</p>
</span><span class="cx" style="display: block; padding: 0 10px">        
</span></span></pre></div>
<a id="trunktestsphpunitdatablocksfixturescore__columnsserverhtml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/blocks/fixtures/core__columns.server.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/blocks/fixtures/core__columns.server.html        2022-09-21 12:27:33 UTC (rev 54273)
+++ trunk/tests/phpunit/data/blocks/fixtures/core__columns.server.html  2022-09-21 13:00:29 UTC (rev 54274)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,7 +1,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<div class="wp-container-1 wp-block-columns has-3-columns">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<div class="is-layout-flex wp-container-1 wp-block-columns has-3-columns">
</ins><span class="cx" style="display: block; padding: 0 10px">         
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        <div class="wp-container-1 wp-block-column">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <div class="is-layout-flow wp-block-column">
</ins><span class="cx" style="display: block; padding: 0 10px">                 
</span><span class="cx" style="display: block; padding: 0 10px">                <p>Column One, Paragraph One</p>
</span><span class="cx" style="display: block; padding: 0 10px">                
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,7 +11,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        </div>
</span><span class="cx" style="display: block; padding: 0 10px">        
</span><span class="cx" style="display: block; padding: 0 10px">        
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        <div class="wp-container-1 wp-block-column">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <div class="is-layout-flow wp-block-column">
</ins><span class="cx" style="display: block; padding: 0 10px">                 
</span><span class="cx" style="display: block; padding: 0 10px">                <p>Column Two, Paragraph One</p>
</span><span class="cx" style="display: block; padding: 0 10px">                
</span></span></pre></div>
<a id="trunktestsphpunitdatablocksfixturescore__columns__deprecatedserverhtml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html    2022-09-21 12:27:33 UTC (rev 54273)
+++ trunk/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html      2022-09-21 13:00:29 UTC (rev 54274)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,5 +1,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<div class="wp-container-1 wp-block-columns has-3-columns">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<div class="is-layout-flex wp-container-1 wp-block-columns has-3-columns">
</ins><span class="cx" style="display: block; padding: 0 10px">         
</span><span class="cx" style="display: block; padding: 0 10px">        <p class="layout-column-1">Column One, Paragraph One</p>
</span><span class="cx" style="display: block; padding: 0 10px">        
</span></span></pre></div>
<a id="trunktestsphpunitdatablocksfixturescore__galleryserverhtml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/blocks/fixtures/core__gallery.server.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/blocks/fixtures/core__gallery.server.html        2022-09-21 12:27:33 UTC (rev 54273)
+++ trunk/tests/phpunit/data/blocks/fixtures/core__gallery.server.html  2022-09-21 13:00:29 UTC (rev 54274)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,5 +1,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<figure class="wp-container-1 wp-block-gallery-1 wp-block-gallery has-nested-images columns-default is-cropped columns-2">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<figure class="is-layout-flex wp-block-gallery-1 wp-block-gallery has-nested-images columns-default is-cropped columns-2">
</ins><span class="cx" style="display: block; padding: 0 10px">         
</span><span class="cx" style="display: block; padding: 0 10px">        <figure class="wp-block-image size-large">
</span><span class="cx" style="display: block; padding: 0 10px">                <img src="https://cldup.com/uuUqE_dXzy.jpg" alt="Image gallery image" />
</span></span></pre></div>
<a id="trunktestsphpunitdatablocksfixturescore__gallery__columnsserverhtml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/blocks/fixtures/core__gallery__columns.server.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/blocks/fixtures/core__gallery__columns.server.html       2022-09-21 12:27:33 UTC (rev 54273)
+++ trunk/tests/phpunit/data/blocks/fixtures/core__gallery__columns.server.html 2022-09-21 13:00:29 UTC (rev 54274)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,5 +1,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<figure class="wp-container-1 wp-block-gallery-1 wp-block-gallery has-nested-images is-cropped columns-1" >
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<figure class="is-layout-flex wp-block-gallery-1 wp-block-gallery has-nested-images is-cropped columns-1" >
</ins><span class="cx" style="display: block; padding: 0 10px">         
</span><span class="cx" style="display: block; padding: 0 10px">        <figure class="wp-block-image size-large">
</span><span class="cx" style="display: block; padding: 0 10px">                <img src="https://cldup.com/uuUqE_dXzy.jpg" alt="Image gallery image" />
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksupportswpGetLayoutStylephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/block-supports/wpGetLayoutStyle.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-supports/wpGetLayoutStyle.php                             (rev 0)
+++ trunk/tests/phpunit/tests/block-supports/wpGetLayoutStyle.php       2022-09-21 13:00:29 UTC (rev 54274)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,253 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group block-supports
+ * @covers ::wp_get_layout_style
+ */
+class Tests_Block_Supports_WpGetLayoutStyle extends WP_UnitTestCase {
+       const ARGS_DEFAULTS = array(
+               'selector'                      => null,
+               'layout'                        => null,
+               'has_block_gap_support'         => false,
+               'gap_value'                     => null,
+               'should_skip_gap_serialization' => false,
+               'fallback_gap_value'            => '0.5em',
+               'block_spacing'                 => null,
+       );
+
+       /**
+        * @dataProvider data_wp_get_layout_style
+        * @ticket       56467
+        *
+        * @param array  $args            Dataset to test.
+        * @param string $expected_output The expected output.
+        */
+       public function test_wp_get_layout_style( array $args, $expected_output ) {
+               $args          = array_merge( static::ARGS_DEFAULTS, $args );
+               $layout_styles = wp_get_layout_style(
+                       $args['selector'],
+                       $args['layout'],
+                       $args['has_block_gap_support'],
+                       $args['gap_value'],
+                       $args['should_skip_gap_serialization'],
+                       $args['fallback_gap_value'],
+                       $args['block_spacing']
+               );
+
+               $this->assertSame( $expected_output, $layout_styles );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array
+        */
+       public function data_wp_get_layout_style() {
+               return array(
+                       'no args should return empty value'            => array(
+                               'args'            => array(),
+                               'expected_output' => '',
+                       ),
+                       'nulled args should return empty value'        => array(
+                               'args'            => array(
+                                       'selector'                      => null,
+                                       'layout'                        => null,
+                                       'has_block_gap_support'         => null,
+                                       'gap_value'                     => null,
+                                       'should_skip_gap_serialization' => null,
+                                       'fallback_gap_value'            => null,
+                                       'block_spacing'                 => null,
+                               ),
+                               'expected_output' => '',
+                       ),
+                       'only selector should return empty value'      => array(
+                               'args'            => array(
+                                       'selector' => '.wp-layout',
+                               ),
+                               'expected_output' => '',
+                       ),
+                       'default layout and block gap support'         => array(
+                               'args'            => array(
+                                       'selector'              => '.wp-layout',
+                                       'has_block_gap_support' => true,
+                                       'gap_value'             => '1em',
+                               ),
+                               'expected_output' => '.wp-layout > *{margin-block-start:0;margin-block-end:0;}.wp-layout.wp-layout > * + *{margin-block-start:1em;margin-block-end:0;}',
+                       ),
+                       'skip serialization should return empty value' => array(
+                               'args'            => array(
+                                       'selector'                      => '.wp-layout',
+                                       'has_block_gap_support'         => true,
+                                       'gap_value'                     => '1em',
+                                       'should_skip_gap_serialization' => true,
+                               ),
+                               'expected_output' => '',
+                       ),
+                       'default layout and axial block gap support'   => array(
+                               'args'            => array(
+                                       'selector'              => '.wp-layout',
+                                       'has_block_gap_support' => true,
+                                       'gap_value'             => array( 'top' => '1em' ),
+                               ),
+                               'expected_output' => '.wp-layout > *{margin-block-start:0;margin-block-end:0;}.wp-layout.wp-layout > * + *{margin-block-start:1em;margin-block-end:0;}',
+                       ),
+                       'constrained layout with sizes'                => array(
+                               'args'            => array(
+                                       'selector' => '.wp-layout',
+                                       'layout'   => array(
+                                               'type'        => 'constrained',
+                                               'contentSize' => '800px',
+                                               'wideSize'    => '1200px',
+                                       ),
+                               ),
+                               'expected_output' => '.wp-layout > :where(:not(.alignleft):not(.alignright):not(.alignfull)){max-width:800px;margin-left:auto !important;margin-right:auto !important;}.wp-layout > .alignwide{max-width:1200px;}.wp-layout .alignfull{max-width:none;}',
+                       ),
+                       'constrained layout with sizes and block spacing' => array(
+                               'args'            => array(
+                                       'selector'      => '.wp-layout',
+                                       'layout'        => array(
+                                               'type'        => 'constrained',
+                                               'contentSize' => '800px',
+                                               'wideSize'    => '1200px',
+                                       ),
+                                       'block_spacing' => array(
+                                               'padding' => array(
+                                                       'left'  => '20px',
+                                                       'right' => '10px',
+                                               ),
+                                       ),
+                               ),
+                               'expected_output' => '.wp-layout > :where(:not(.alignleft):not(.alignright):not(.alignfull)){max-width:800px;margin-left:auto !important;margin-right:auto !important;}.wp-layout > .alignwide{max-width:1200px;}.wp-layout .alignfull{max-width:none;}.wp-layout > .alignfull{margin-right:calc(10px * -1);margin-left:calc(20px * -1);}',
+                       ),
+                       'constrained layout with block gap support'    => array(
+                               'args'            => array(
+                                       'selector'              => '.wp-layout',
+                                       'layout'                => array(
+                                               'type' => 'constrained',
+                                       ),
+                                       'has_block_gap_support' => true,
+                                       'gap_value'             => '2.5rem',
+                               ),
+                               'expected_output' => '.wp-layout > *{margin-block-start:0;margin-block-end:0;}.wp-layout.wp-layout > * + *{margin-block-start:2.5rem;margin-block-end:0;}',
+                       ),
+                       'constrained layout with axial block gap support' => array(
+                               'args'            => array(
+                                       'selector'              => '.wp-layout',
+                                       'layout'                => array(
+                                               'type' => 'constrained',
+                                       ),
+                                       'has_block_gap_support' => true,
+                                       'gap_value'             => array( 'top' => '2.5rem' ),
+                               ),
+                               'expected_output' => '.wp-layout > *{margin-block-start:0;margin-block-end:0;}.wp-layout.wp-layout > * + *{margin-block-start:2.5rem;margin-block-end:0;}',
+                       ),
+                       'constrained layout with block gap support and spacing preset' => array(
+                               'args'            => array(
+                                       'selector'              => '.wp-layout',
+                                       'layout'                => array(
+                                               'type' => 'constrained',
+                                       ),
+                                       'has_block_gap_support' => true,
+                                       'gap_value'             => 'var:preset|spacing|50',
+                               ),
+                               'expected_output' => '.wp-layout > *{margin-block-start:0;margin-block-end:0;}.wp-layout.wp-layout > * + *{margin-block-start:var(--wp--preset--spacing--50);margin-block-end:0;}',
+                       ),
+                       'flex layout with no args should return empty value' => array(
+                               'args'            => array(
+                                       'selector' => '.wp-layout',
+                                       'layout'   => array(
+                                               'type' => 'flex',
+                                       ),
+                               ),
+                               'expected_output' => '',
+                       ),
+                       'horizontal flex layout should return empty value' => array(
+                               'args'            => array(
+                                       'selector' => '.wp-layout',
+                                       'layout'   => array(
+                                               'type'        => 'flex',
+                                               'orientation' => 'horizontal',
+                                       ),
+                               ),
+                               'expected_output' => '',
+                       ),
+                       'flex layout with properties'                  => array(
+                               'args'            => array(
+                                       'selector' => '.wp-layout',
+                                       'layout'   => array(
+                                               'type'              => 'flex',
+                                               'orientation'       => 'horizontal',
+                                               'flexWrap'          => 'nowrap',
+                                               'justifyContent'    => 'left',
+                                               'verticalAlignment' => 'bottom',
+                                       ),
+                               ),
+                               'expected_output' => '.wp-layout{flex-wrap:nowrap;justify-content:flex-start;align-items:flex-end;}',
+                       ),
+                       'flex layout with properties and block gap'    => array(
+                               'args'            => array(
+                                       'selector'              => '.wp-layout',
+                                       'layout'                => array(
+                                               'type'              => 'flex',
+                                               'orientation'       => 'horizontal',
+                                               'flexWrap'          => 'nowrap',
+                                               'justifyContent'    => 'left',
+                                               'verticalAlignment' => 'bottom',
+                                       ),
+                                       'has_block_gap_support' => true,
+                                       'gap_value'             => '29px',
+                               ),
+                               'expected_output' => '.wp-layout{flex-wrap:nowrap;gap:29px;justify-content:flex-start;align-items:flex-end;}',
+                       ),
+                       'flex layout with properties and axial block gap' => array(
+                               'args'            => array(
+                                       'selector'              => '.wp-layout',
+                                       'layout'                => array(
+                                               'type'              => 'flex',
+                                               'orientation'       => 'horizontal',
+                                               'flexWrap'          => 'nowrap',
+                                               'justifyContent'    => 'left',
+                                               'verticalAlignment' => 'bottom',
+                                       ),
+                                       'has_block_gap_support' => true,
+                                       'gap_value'             => array(
+                                               'top'  => '1px',
+                                               'left' => '2px',
+                                       ),
+                               ),
+                               'expected_output' => '.wp-layout{flex-wrap:nowrap;gap:1px 2px;justify-content:flex-start;align-items:flex-end;}',
+                       ),
+                       'flex layout with properties and axial block gap using spacing preset' => array(
+                               'args'            => array(
+                                       'selector'              => '.wp-layout',
+                                       'layout'                => array(
+                                               'type'              => 'flex',
+                                               'orientation'       => 'horizontal',
+                                               'flexWrap'          => 'nowrap',
+                                               'justifyContent'    => 'left',
+                                               'verticalAlignment' => 'bottom',
+                                       ),
+                                       'has_block_gap_support' => true,
+                                       'gap_value'             => array(
+                                               'left' => 'var:preset|spacing|40',
+                                       ),
+                                       'fallback_gap_value'    => '11px',
+                               ),
+                               'expected_output' => '.wp-layout{flex-wrap:nowrap;gap:11px var(--wp--preset--spacing--40);justify-content:flex-start;align-items:flex-end;}',
+                       ),
+                       'vertical flex layout with properties'         => array(
+                               'args'            => array(
+                                       'selector' => '.wp-layout',
+                                       'layout'   => array(
+                                               'type'              => 'flex',
+                                               'orientation'       => 'vertical',
+                                               'flexWrap'          => 'nowrap',
+                                               'justifyContent'    => 'left',
+                                               'verticalAlignment' => 'bottom',
+                                       ),
+                               ),
+                               'expected_output' => '.wp-layout{flex-wrap:nowrap;flex-direction:column;align-items:flex-start;}',
+                       ),
+               );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/block-supports/wpGetLayoutStyle.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>

</body>
</html>