<!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>[56101] trunk: Editor: update duotone support.</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/56101">56101</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/56101","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>isabel_brison</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-06-29 06:19:41 +0000 (Thu, 29 Jun 2023)</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: update duotone support.

Updates duotone support after stabilisation of selectors API and adds a few small code quality and UI improvements.

Props onemaggie, peterwilsoncc, ajlende, audrasjb, mikeschroder, ramonopoly.
Fixes <a href="https://core.trac.wordpress.org/ticket/58555">#58555</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportsduotonephp">trunk/src/wp-includes/block-supports/duotone.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonphp">trunk/src/wp-includes/class-wp-theme-json.php</a></li>
<li><a href="#trunksrcwpincludesdefaultfiltersphp">trunk/src/wp-includes/default-filters.php</a></li>
<li><a href="#trunksrcwpincludesdeprecatedphp">trunk/src/wp-includes/deprecated.php</a></li>
<li><a href="#trunksrcwpincludesglobalstylesandsettingsphp">trunk/src/wp-includes/global-styles-and-settings.php</a></li>
<li><a href="#trunksrcwpincludesscriptloaderphp">trunk/src/wp-includes/script-loader.php</a></li>
<li><a href="#trunksrcwpsettingsphp">trunk/src/wp-settings.php</a></li>
<li><a href="#trunktestsphpunitteststhemewpGetGlobalStylesSvgFiltersphp">trunk/tests/phpunit/tests/theme/wpGetGlobalStylesSvgFilters.php</a></li>
<li><a href="#trunktestsphpunitteststhemewpThemeJsonphp">trunk/tests/phpunit/tests/theme/wpThemeJson.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpduotonephp">trunk/src/wp-includes/class-wp-duotone.php</a></li>
<li><a href="#trunktestsphpunittestsblocksupportsduotonephp">trunk/tests/phpunit/tests/block-supports/duotone.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportsduotonephp"></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/duotone.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/duotone.php  2023-06-28 23:26:16 UTC (rev 56100)
+++ trunk/src/wp-includes/block-supports/duotone.php    2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -32,566 +32,32 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 5.8.0
</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">-/**
- * Takes input from [0, n] and returns it as [0, 1].
- *
- * Direct port of TinyColor's function, lightly simplified to maintain
- * consistency with TinyColor.
- *
- * @see https://github.com/bgrins/TinyColor
- *
- * @since 5.8.0
- * @access private
- *
- * @param mixed $n   Number of unknown type.
- * @param int   $max Upper value of the range to bound to.
- * @return float Value in the range [0, 1].
- */
-function wp_tinycolor_bound01( $n, $max ) {
-       if ( 'string' === gettype( $n ) && str_contains( $n, '.' ) && 1 === (float) $n ) {
-               $n = '100%';
-       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Register the block support.
+WP_Block_Supports::get_instance()->register(
+       'duotone',
+       array(
+               'register_attribute' => array( 'WP_Duotone', 'register_duotone_support' ),
+       )
+);
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $n = min( $max, max( 0, (float) $n ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Set up metadata prior to rendering any blocks.
+add_action( 'wp_loaded', array( 'WP_Duotone', 'set_global_styles_presets' ), 10 );
+add_action( 'wp_loaded', array( 'WP_Duotone', 'set_global_style_block_names' ), 10 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Automatically convert percentage into number.
-       if ( 'string' === gettype( $n ) && str_contains( $n, '%' ) ) {
-               $n = (int) ( $n * $max ) / 100;
-       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Add classnames to blocks using duotone support.
+add_filter( 'render_block', array( 'WP_Duotone', 'render_duotone_support' ), 10, 2 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Handle floating point rounding errors.
-       if ( ( abs( $n - $max ) < 0.000001 ) ) {
-               return 1.0;
-       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Enqueue styles.
+// Block styles (core-block-supports-inline-css) before the style engine (wp_enqueue_stored_styles).
+// Global styles (global-styles-inline-css) after the other global styles (wp_enqueue_global_styles).
+add_action( 'wp_enqueue_scripts', array( 'WP_Duotone', 'output_block_styles' ), 9 );
+add_action( 'wp_enqueue_scripts', array( 'WP_Duotone', 'output_global_styles' ), 11 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Convert into [0, 1] range if it isn't already.
-       return ( $n % $max ) / (float) $max;
-}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Add SVG filters to the footer. Also, for classic themes, output block styles (core-block-supports-inline-css).
+add_action( 'wp_footer', array( 'WP_Duotone', 'output_footer_assets' ), 10 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/**
- * Direct port of tinycolor's boundAlpha function to maintain consistency with
- * how tinycolor works.
- *
- * @see https://github.com/bgrins/TinyColor
- *
- * @since 5.9.0
- * @access private
- *
- * @param mixed $n Number of unknown type.
- * @return float Value in the range [0,1].
- */
-function _wp_tinycolor_bound_alpha( $n ) {
-       if ( is_numeric( $n ) ) {
-               $n = (float) $n;
-               if ( $n >= 0 && $n <= 1 ) {
-                       return $n;
-               }
-       }
-       return 1;
-}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Add styles and SVGs for use in the editor via the EditorStyles component.
+add_filter( 'block_editor_settings_all', array( 'WP_Duotone', 'add_editor_settings' ), 10 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/**
- * Rounds and converts values of an RGB object.
- *
- * Direct port of TinyColor's function, lightly simplified to maintain
- * consistency with TinyColor.
- *
- * @see https://github.com/bgrins/TinyColor
- *
- * @since 5.8.0
- * @access private
- *
- * @param array $rgb_color RGB object.
- * @return array Rounded and converted RGB object.
- */
-function wp_tinycolor_rgb_to_rgb( $rgb_color ) {
-       return array(
-               'r' => wp_tinycolor_bound01( $rgb_color['r'], 255 ) * 255,
-               'g' => wp_tinycolor_bound01( $rgb_color['g'], 255 ) * 255,
-               'b' => wp_tinycolor_bound01( $rgb_color['b'], 255 ) * 255,
-       );
-}
-
-/**
- * Helper function for hsl to rgb conversion.
- *
- * Direct port of TinyColor's function, lightly simplified to maintain
- * consistency with TinyColor.
- *
- * @see https://github.com/bgrins/TinyColor
- *
- * @since 5.8.0
- * @access private
- *
- * @param float $p first component.
- * @param float $q second component.
- * @param float $t third component.
- * @return float R, G, or B component.
- */
-function wp_tinycolor_hue_to_rgb( $p, $q, $t ) {
-       if ( $t < 0 ) {
-               ++$t;
-       }
-       if ( $t > 1 ) {
-               --$t;
-       }
-       if ( $t < 1 / 6 ) {
-               return $p + ( $q - $p ) * 6 * $t;
-       }
-       if ( $t < 1 / 2 ) {
-               return $q;
-       }
-       if ( $t < 2 / 3 ) {
-               return $p + ( $q - $p ) * ( 2 / 3 - $t ) * 6;
-       }
-       return $p;
-}
-
-/**
- * Converts an HSL object to an RGB object with converted and rounded values.
- *
- * Direct port of TinyColor's function, lightly simplified to maintain
- * consistency with TinyColor.
- *
- * @see https://github.com/bgrins/TinyColor
- *
- * @since 5.8.0
- * @access private
- *
- * @param array $hsl_color HSL object.
- * @return array Rounded and converted RGB object.
- */
-function wp_tinycolor_hsl_to_rgb( $hsl_color ) {
-       $h = wp_tinycolor_bound01( $hsl_color['h'], 360 );
-       $s = wp_tinycolor_bound01( $hsl_color['s'], 100 );
-       $l = wp_tinycolor_bound01( $hsl_color['l'], 100 );
-
-       if ( 0 === $s ) {
-               // Achromatic.
-               $r = $l;
-               $g = $l;
-               $b = $l;
-       } else {
-               $q = $l < 0.5 ? $l * ( 1 + $s ) : $l + $s - $l * $s;
-               $p = 2 * $l - $q;
-               $r = wp_tinycolor_hue_to_rgb( $p, $q, $h + 1 / 3 );
-               $g = wp_tinycolor_hue_to_rgb( $p, $q, $h );
-               $b = wp_tinycolor_hue_to_rgb( $p, $q, $h - 1 / 3 );
-       }
-
-       return array(
-               'r' => $r * 255,
-               'g' => $g * 255,
-               'b' => $b * 255,
-       );
-}
-
-/**
- * Parses hex, hsl, and rgb CSS strings using the same regex as TinyColor v1.4.2
- * used in the JavaScript. Only colors output from react-color are implemented.
- *
- * Direct port of TinyColor's function, lightly simplified to maintain
- * consistency with TinyColor.
- *
- * @see https://github.com/bgrins/TinyColor
- * @see https://github.com/casesandberg/react-color/
- *
- * @since 5.8.0
- * @since 5.9.0 Added alpha processing.
- * @access private
- *
- * @param string $color_str CSS color string.
- * @return array RGB object.
- */
-function wp_tinycolor_string_to_rgb( $color_str ) {
-       $color_str = strtolower( trim( $color_str ) );
-
-       $css_integer = '[-\\+]?\\d+%?';
-       $css_number  = '[-\\+]?\\d*\\.\\d+%?';
-
-       $css_unit = '(?:' . $css_number . ')|(?:' . $css_integer . ')';
-
-       $permissive_match3 = '[\\s|\\(]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')\\s*\\)?';
-       $permissive_match4 = '[\\s|\\(]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')\\s*\\)?';
-
-       $rgb_regexp = '/^rgb' . $permissive_match3 . '$/';
-       if ( preg_match( $rgb_regexp, $color_str, $match ) ) {
-               $rgb = wp_tinycolor_rgb_to_rgb(
-                       array(
-                               'r' => $match[1],
-                               'g' => $match[2],
-                               'b' => $match[3],
-                       )
-               );
-
-               $rgb['a'] = 1;
-
-               return $rgb;
-       }
-
-       $rgba_regexp = '/^rgba' . $permissive_match4 . '$/';
-       if ( preg_match( $rgba_regexp, $color_str, $match ) ) {
-               $rgb = wp_tinycolor_rgb_to_rgb(
-                       array(
-                               'r' => $match[1],
-                               'g' => $match[2],
-                               'b' => $match[3],
-                       )
-               );
-
-               $rgb['a'] = _wp_tinycolor_bound_alpha( $match[4] );
-
-               return $rgb;
-       }
-
-       $hsl_regexp = '/^hsl' . $permissive_match3 . '$/';
-       if ( preg_match( $hsl_regexp, $color_str, $match ) ) {
-               $rgb = wp_tinycolor_hsl_to_rgb(
-                       array(
-                               'h' => $match[1],
-                               's' => $match[2],
-                               'l' => $match[3],
-                       )
-               );
-
-               $rgb['a'] = 1;
-
-               return $rgb;
-       }
-
-       $hsla_regexp = '/^hsla' . $permissive_match4 . '$/';
-       if ( preg_match( $hsla_regexp, $color_str, $match ) ) {
-               $rgb = wp_tinycolor_hsl_to_rgb(
-                       array(
-                               'h' => $match[1],
-                               's' => $match[2],
-                               'l' => $match[3],
-                       )
-               );
-
-               $rgb['a'] = _wp_tinycolor_bound_alpha( $match[4] );
-
-               return $rgb;
-       }
-
-       $hex8_regexp = '/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/';
-       if ( preg_match( $hex8_regexp, $color_str, $match ) ) {
-               $rgb = wp_tinycolor_rgb_to_rgb(
-                       array(
-                               'r' => base_convert( $match[1], 16, 10 ),
-                               'g' => base_convert( $match[2], 16, 10 ),
-                               'b' => base_convert( $match[3], 16, 10 ),
-                       )
-               );
-
-               $rgb['a'] = _wp_tinycolor_bound_alpha(
-                       base_convert( $match[4], 16, 10 ) / 255
-               );
-
-               return $rgb;
-       }
-
-       $hex6_regexp = '/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/';
-       if ( preg_match( $hex6_regexp, $color_str, $match ) ) {
-               $rgb = wp_tinycolor_rgb_to_rgb(
-                       array(
-                               'r' => base_convert( $match[1], 16, 10 ),
-                               'g' => base_convert( $match[2], 16, 10 ),
-                               'b' => base_convert( $match[3], 16, 10 ),
-                       )
-               );
-
-               $rgb['a'] = 1;
-
-               return $rgb;
-       }
-
-       $hex4_regexp = '/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/';
-       if ( preg_match( $hex4_regexp, $color_str, $match ) ) {
-               $rgb = wp_tinycolor_rgb_to_rgb(
-                       array(
-                               'r' => base_convert( $match[1] . $match[1], 16, 10 ),
-                               'g' => base_convert( $match[2] . $match[2], 16, 10 ),
-                               'b' => base_convert( $match[3] . $match[3], 16, 10 ),
-                       )
-               );
-
-               $rgb['a'] = _wp_tinycolor_bound_alpha(
-                       base_convert( $match[4] . $match[4], 16, 10 ) / 255
-               );
-
-               return $rgb;
-       }
-
-       $hex3_regexp = '/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/';
-       if ( preg_match( $hex3_regexp, $color_str, $match ) ) {
-               $rgb = wp_tinycolor_rgb_to_rgb(
-                       array(
-                               'r' => base_convert( $match[1] . $match[1], 16, 10 ),
-                               'g' => base_convert( $match[2] . $match[2], 16, 10 ),
-                               'b' => base_convert( $match[3] . $match[3], 16, 10 ),
-                       )
-               );
-
-               $rgb['a'] = 1;
-
-               return $rgb;
-       }
-
-       /*
-        * The JS color picker considers the string "transparent" to be a hex value,
-        * so we need to handle it here as a special case.
-        */
-       if ( 'transparent' === $color_str ) {
-               return array(
-                       'r' => 0,
-                       'g' => 0,
-                       'b' => 0,
-                       'a' => 0,
-               );
-       }
-}
-
-/**
- * Returns the prefixed id for the duotone filter for use as a CSS id.
- *
- * @since 5.9.1
- * @access private
- *
- * @param array $preset Duotone preset value as seen in theme.json.
- * @return string Duotone filter CSS id.
- */
-function wp_get_duotone_filter_id( $preset ) {
-       if ( ! isset( $preset['slug'] ) ) {
-               return '';
-       }
-
-       return 'wp-duotone-' . $preset['slug'];
-}
-
-/**
- * Returns the CSS filter property url to reference the rendered SVG.
- *
- * @since 5.9.0
- * @since 6.1.0 Allow unset for preset colors.
- * @access private
- *
- * @param array $preset Duotone preset value as seen in theme.json.
- * @return string Duotone CSS filter property url value.
- */
-function wp_get_duotone_filter_property( $preset ) {
-       if ( isset( $preset['colors'] ) && 'unset' === $preset['colors'] ) {
-               return 'none';
-       }
-       $filter_id = wp_get_duotone_filter_id( $preset );
-       return "url('#" . $filter_id . "')";
-}
-
-/**
- * Returns the duotone filter SVG string for the preset.
- *
- * @since 5.9.1
- * @access private
- *
- * @param array $preset Duotone preset value as seen in theme.json.
- * @return string Duotone SVG filter.
- */
-function wp_get_duotone_filter_svg( $preset ) {
-       $filter_id = wp_get_duotone_filter_id( $preset );
-
-       $duotone_values = array(
-               'r' => array(),
-               'g' => array(),
-               'b' => array(),
-               'a' => array(),
-       );
-
-       if ( ! isset( $preset['colors'] ) || ! is_array( $preset['colors'] ) ) {
-               $preset['colors'] = array();
-       }
-
-       foreach ( $preset['colors'] as $color_str ) {
-               $color = wp_tinycolor_string_to_rgb( $color_str );
-
-               $duotone_values['r'][] = $color['r'] / 255;
-               $duotone_values['g'][] = $color['g'] / 255;
-               $duotone_values['b'][] = $color['b'] / 255;
-               $duotone_values['a'][] = $color['a'];
-       }
-
-       ob_start();
-
-       ?>
-
-       <svg
-               xmlns="http://www.w3.org/2000/svg"
-               viewBox="0 0 0 0"
-               width="0"
-               height="0"
-               focusable="false"
-               role="none"
-               style="visibility: hidden; position: absolute; left: -9999px; overflow: hidden;"
-       >
-               <defs>
-                       <filter id="<?php echo esc_attr( $filter_id ); ?>">
-                               <feColorMatrix
-                                       color-interpolation-filters="sRGB"
-                                       type="matrix"
-                                       values="
-                                               .299 .587 .114 0 0
-                                               .299 .587 .114 0 0
-                                               .299 .587 .114 0 0
-                                               .299 .587 .114 0 0
-                                       "
-                               />
-                               <feComponentTransfer color-interpolation-filters="sRGB" >
-                                       <feFuncR type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['r'] ) ); ?>" />
-                                       <feFuncG type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['g'] ) ); ?>" />
-                                       <feFuncB type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['b'] ) ); ?>" />
-                                       <feFuncA type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['a'] ) ); ?>" />
-                               </feComponentTransfer>
-                               <feComposite in2="SourceGraphic" operator="in" />
-                       </filter>
-               </defs>
-       </svg>
-
-       <?php
-
-       $svg = ob_get_clean();
-
-       if ( ! SCRIPT_DEBUG ) {
-               // Clean up the whitespace.
-               $svg = preg_replace( "/[\r\n\t ]+/", ' ', $svg );
-               $svg = str_replace( '> <', '><', $svg );
-               $svg = trim( $svg );
-       }
-
-       return $svg;
-}
-
-/**
- * Registers the style and colors block attributes for block types that support it.
- *
- * @since 5.8.0
- * @access private
- *
- * @param WP_Block_Type $block_type Block Type.
- */
-function wp_register_duotone_support( $block_type ) {
-       $has_duotone_support = false;
-       if ( property_exists( $block_type, 'supports' ) ) {
-               $has_duotone_support = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), false );
-       }
-
-       if ( $has_duotone_support ) {
-               if ( ! $block_type->attributes ) {
-                       $block_type->attributes = array();
-               }
-
-               if ( ! array_key_exists( 'style', $block_type->attributes ) ) {
-                       $block_type->attributes['style'] = array(
-                               'type' => 'object',
-                       );
-               }
-       }
-}
-
-/**
- * Renders out the duotone stylesheet and SVG.
- *
- * @since 5.8.0
- * @since 6.1.0 Allow unset for preset colors.
- * @access private
- *
- * @param string $block_content Rendered block content.
- * @param array  $block         Block object.
- * @return string Filtered block content.
- */
-function wp_render_duotone_support( $block_content, $block ) {
-       $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
-
-       $duotone_support = false;
-       if ( $block_type && property_exists( $block_type, 'supports' ) ) {
-               $duotone_support = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), false );
-       }
-
-       $has_duotone_attribute = isset( $block['attrs']['style']['color']['duotone'] );
-
-       if (
-               ! $duotone_support ||
-               ! $has_duotone_attribute
-       ) {
-               return $block_content;
-       }
-
-       $colors          = $block['attrs']['style']['color']['duotone'];
-       $filter_key      = is_array( $colors ) ? implode( '-', $colors ) : $colors;
-       $filter_preset   = array(
-               'slug'   => wp_unique_id( sanitize_key( $filter_key . '-' ) ),
-               'colors' => $colors,
-       );
-       $filter_property = wp_get_duotone_filter_property( $filter_preset );
-       $filter_id       = wp_get_duotone_filter_id( $filter_preset );
-
-       $scope     = '.' . $filter_id;
-       $selectors = explode( ',', $duotone_support );
-       $scoped    = array();
-       foreach ( $selectors as $sel ) {
-               $scoped[] = $scope . ' ' . trim( $sel );
-       }
-       $selector = implode( ', ', $scoped );
-
-       // !important is needed because these styles render before global styles,
-       // and they should be overriding the duotone filters set by global styles.
-       $filter_style = SCRIPT_DEBUG
-               ? $selector . " {\n\tfilter: " . $filter_property . " !important;\n}\n"
-               : $selector . '{filter:' . $filter_property . ' !important;}';
-
-       wp_register_style( $filter_id, false );
-       wp_add_inline_style( $filter_id, $filter_style );
-       wp_enqueue_style( $filter_id );
-
-       if ( 'unset' !== $colors ) {
-               $filter_svg = wp_get_duotone_filter_svg( $filter_preset );
-               add_action(
-                       'wp_footer',
-                       static function () use ( $filter_svg, $selector ) {
-                               echo $filter_svg;
-
-                               /*
-                                * Safari renders elements incorrectly on first paint when the
-                                * SVG filter comes after the content that it is filtering, so
-                                * we force a repaint with a WebKit hack which solves the issue.
-                                */
-                               global $is_safari;
-                               if ( $is_safari ) {
-                                       /*
-                                        * Simply accessing el.offsetHeight flushes layout and style
-                                        * changes in WebKit without having to wait for setTimeout.
-                                        */
-                                       printf(
-                                               '<script>( function() { var el = document.querySelector( %s ); var display = el.style.display; el.style.display = "none"; el.offsetHeight; el.style.display = display; } )();</script>',
-                                               wp_json_encode( $selector )
-                                       );
-                               }
-                       }
-               );
-       }
-
-       // Like the layout hook, this assumes the hook only applies to blocks with a single wrapper.
-       return preg_replace(
-               '/' . preg_quote( 'class="', '/' ) . '/',
-               'class="' . $filter_id . ' ',
-               $block_content,
-               1
-       );
-}
-
-// Register the block support.
-WP_Block_Supports::get_instance()->register(
-       'duotone',
-       array(
-               'register_attribute' => 'wp_register_duotone_support',
-       )
-);
-add_filter( 'render_block', 'wp_render_duotone_support', 10, 2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Migrate the old experimental duotone support flag.
+add_filter( 'block_type_metadata_settings', array( 'WP_Duotone', 'migrate_experimental_duotone_support_flag' ), 10, 2 );
</ins></span></pre></div>
<a id="trunksrcwpincludesclasswpduotonephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/wp-includes/class-wp-duotone.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-duotone.php                                (rev 0)
+++ trunk/src/wp-includes/class-wp-duotone.php  2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,1274 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * WP_Duotone class
+ *
+ * Parts of this source were derived and modified from colord,
+ * released under the MIT license.
+ *
+ * https://github.com/omgovich/colord
+ *
+ * Copyright (c) 2020 Vlad Shilov omgovich@ya.ru
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * @package WordPress
+ * @since 6.3.0
+ */
+
+/**
+ * Manages duotone block supports and global styles.
+ *
+ * @access private
+ */
+class WP_Duotone {
+       /**
+        * Block names from global, theme, and custom styles that use duotone presets and the slug of
+        * the preset they are using.
+        *
+        * Example:
+        *  [
+        *      'core/featured-image' => 'blue-orange',
+        *       â€¦
+        *  ]
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @var array
+        */
+       private static $global_styles_block_names = array();
+
+       /**
+        * An array of duotone filter data from global, theme, and custom presets.
+        *
+        * Example:
+        *  [
+        *      'wp-duotone-blue-orange' => [
+        *          'slug'  => 'blue-orange',
+        *          'colors' => [ '#0000ff', '#ffcc00' ],
+        *      ],
+        *      'wp-duotone-red-yellow' => [
+        *          'slug'   => 'red-yellow',
+        *          'colors' => [ '#cc0000', '#ffff33' ],
+        *      ],
+        *      â€¦
+        *  ]
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @var array
+        */
+       private static $global_styles_presets = array();
+
+       /**
+        * All of the duotone filter data from presets for CSS custom properties on
+        * the page.
+        *
+        * Example:
+        *  [
+        *      'wp-duotone-blue-orange' => [
+        *          'slug'   => 'blue-orange',
+        *          'colors' => [ '#0000ff', '#ffcc00' ],
+        *      ],
+        *      â€¦
+        *  ]
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @var array
+        */
+       private static $used_global_styles_presets = array();
+
+       /**
+        * All of the duotone filter data for SVGs on the page. Includes both
+        * presets and custom filters.
+        *
+        * Example:
+        *  [
+        *      'wp-duotone-blue-orange' => [
+        *          'slug'   => 'blue-orange',
+        *          'colors' => [ '#0000ff', '#ffcc00' ],
+        *      ],
+        *      'wp-duotone-000000-ffffff-2' => [
+        *          'slug'   => '000000-ffffff-2',
+        *          'colors' => [ '#000000', '#ffffff' ],
+        *      ],
+        *      â€¦
+        *  ]
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @var array
+        */
+       private static $used_svg_filter_data = array();
+
+       /**
+        * All of the block CSS declarations for styles on the page.
+        *
+        * Example:
+        *  [
+        *      [
+        *          'selector'     => '.wp-duotone-000000-ffffff-2.wp-block-image img',
+        *          'declarations' => [
+        *              'filter' => 'url(#wp-duotone-000000-ffffff-2)',
+        *          ],
+        *      ],
+        *      â€¦
+        *  ]
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @var array
+        */
+       private static $block_css_declarations = array();
+
+       /**
+        * Clamps a value between an upper and lower bound.
+        *
+        * Direct port of colord's clamp function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/helpers.ts#L23 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param float $number The number to clamp.
+        * @param float $min    The minimum value.
+        * @param float $max    The maximum value.
+        * @return float The clamped value.
+        */
+       private static function colord_clamp( $number, $min = 0, $max = 1 ) {
+               return $number > $max ? $max : ( $number > $min ? $number : $min );
+       }
+
+       /**
+        * Processes and clamps a degree (angle) value properly.
+        *
+        * Direct port of colord's clampHue function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/helpers.ts#L32 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param float $degrees The hue to clamp.
+        * @return float The clamped hue.
+        */
+       private static function colord_clamp_hue( $degrees ) {
+               $degrees = is_finite( $degrees ) ? $degrees % 360 : 0;
+               return $degrees > 0 ? $degrees : $degrees + 360;
+       }
+
+       /**
+        * Converts a hue value to degrees from 0 to 360 inclusive.
+        *
+        * Direct port of colord's parseHue function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/helpers.ts#L40 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param float  $value The hue value to parse.
+        * @param string $unit  The unit of the hue value.
+        * @return float The parsed hue value.
+        */
+       private static function colord_parse_hue( $value, $unit = 'deg' ) {
+               $angle_units = array(
+                       'grad' => 360 / 400,
+                       'turn' => 360,
+                       'rad'  => 360 / ( M_PI * 2 ),
+               );
+
+               $factor = $angle_units[ $unit ];
+               if ( ! $factor ) {
+                       $factor = 1;
+               }
+
+               return (float) $value * $factor;
+       }
+
+       /**
+        * Parses any valid Hex3, Hex4, Hex6 or Hex8 string and converts it to an RGBA object
+        *
+        * Direct port of colord's parseHex function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hex.ts#L8 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $hex The hex string to parse.
+        * @return array|null An array of RGBA values or null if the hex string is invalid.
+        */
+       private static function colord_parse_hex( $hex ) {
+               $is_match = preg_match(
+                       '/^#([0-9a-f]{3,8})$/i',
+                       $hex,
+                       $hex_match
+               );
+
+               if ( ! $is_match ) {
+                       return null;
+               }
+
+               $hex = $hex_match[1];
+
+               if ( 4 >= strlen( $hex ) ) {
+                       return array(
+                               'r' => (int) base_convert( $hex[0] . $hex[0], 16, 10 ),
+                               'g' => (int) base_convert( $hex[1] . $hex[1], 16, 10 ),
+                               'b' => (int) base_convert( $hex[2] . $hex[2], 16, 10 ),
+                               'a' => 4 === strlen( $hex ) ? round( base_convert( $hex[3] . $hex[3], 16, 10 ) / 255, 2 ) : 1,
+                       );
+               }
+
+               if ( 6 === strlen( $hex ) || 8 === strlen( $hex ) ) {
+                       return array(
+                               'r' => (int) base_convert( substr( $hex, 0, 2 ), 16, 10 ),
+                               'g' => (int) base_convert( substr( $hex, 2, 2 ), 16, 10 ),
+                               'b' => (int) base_convert( substr( $hex, 4, 2 ), 16, 10 ),
+                               'a' => 8 === strlen( $hex ) ? round( (int) base_convert( substr( $hex, 6, 2 ), 16, 10 ) / 255, 2 ) : 1,
+                       );
+               }
+
+               return null;
+       }
+
+       /**
+        * Clamps an array of RGBA values.
+        *
+        * Direct port of colord's clampRgba function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/rgb.ts#L5 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param array $rgba The RGBA array to clamp.
+        * @return array The clamped RGBA array.
+        */
+       private static function colord_clamp_rgba( $rgba ) {
+               $rgba['r'] = self::colord_clamp( $rgba['r'], 0, 255 );
+               $rgba['g'] = self::colord_clamp( $rgba['g'], 0, 255 );
+               $rgba['b'] = self::colord_clamp( $rgba['b'], 0, 255 );
+               $rgba['a'] = self::colord_clamp( $rgba['a'] );
+
+               return $rgba;
+       }
+
+       /**
+        * Parses a valid RGB[A] CSS color function/string
+        *
+        * Direct port of colord's parseRgbaString function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/rgbString.ts#L18 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $input The RGBA string to parse.
+        * @return array|null An array of RGBA values or null if the RGB string is invalid.
+        */
+       private static function colord_parse_rgba_string( $input ) {
+               // Functional syntax.
+               $is_match = preg_match(
+                       '/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i',
+                       $input,
+                       $match
+               );
+
+               if ( ! $is_match ) {
+                       // Whitespace syntax.
+                       $is_match = preg_match(
+                               '/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i',
+                               $input,
+                               $match
+                       );
+               }
+
+               if ( ! $is_match ) {
+                       return null;
+               }
+
+               /*
+                * For some reason, preg_match doesn't include empty matches at the end
+                * of the array, so we add them manually to make things easier later.
+                */
+               for ( $i = 1; $i <= 8; $i++ ) {
+                       if ( ! isset( $match[ $i ] ) ) {
+                               $match[ $i ] = '';
+                       }
+               }
+
+               if ( $match[2] !== $match[4] || $match[4] !== $match[6] ) {
+                       return null;
+               }
+
+               return self::colord_clamp_rgba(
+                       array(
+                               'r' => (float) $match[1] / ( $match[2] ? 100 / 255 : 1 ),
+                               'g' => (float) $match[3] / ( $match[4] ? 100 / 255 : 1 ),
+                               'b' => (float) $match[5] / ( $match[6] ? 100 / 255 : 1 ),
+                               'a' => '' === $match[7] ? 1 : (float) $match[7] / ( $match[8] ? 100 : 1 ),
+                       )
+               );
+       }
+
+       /**
+        * Clamps an array of HSLA values.
+        *
+        * Direct port of colord's clampHsla function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsl.ts#L6 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param array $hsla The HSLA array to clamp.
+        * @return array The clamped HSLA array.
+        */
+       private static function colord_clamp_hsla( $hsla ) {
+               $hsla['h'] = self::colord_clamp_hue( $hsla['h'] );
+               $hsla['s'] = self::colord_clamp( $hsla['s'], 0, 100 );
+               $hsla['l'] = self::colord_clamp( $hsla['l'], 0, 100 );
+               $hsla['a'] = self::colord_clamp( $hsla['a'] );
+
+               return $hsla;
+       }
+
+       /**
+        * Converts an HSVA array to RGBA.
+        *
+        * Direct port of colord's hsvaToRgba function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsv.ts#L52 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param array $hsva The HSVA array to convert.
+        * @return array The RGBA array.
+        */
+       private static function colord_hsva_to_rgba( $hsva ) {
+               $h = ( $hsva['h'] / 360 ) * 6;
+               $s = $hsva['s'] / 100;
+               $v = $hsva['v'] / 100;
+               $a = $hsva['a'];
+
+               $hh     = floor( $h );
+               $b      = $v * ( 1 - $s );
+               $c      = $v * ( 1 - ( $h - $hh ) * $s );
+               $d      = $v * ( 1 - ( 1 - $h + $hh ) * $s );
+               $module = $hh % 6;
+
+               return array(
+                       'r' => array( $v, $c, $b, $b, $d, $v )[ $module ] * 255,
+                       'g' => array( $d, $v, $v, $c, $b, $b )[ $module ] * 255,
+                       'b' => array( $b, $b, $d, $v, $v, $c )[ $module ] * 255,
+                       'a' => $a,
+               );
+       }
+
+       /**
+        * Converts an HSLA array to HSVA.
+        *
+        * Direct port of colord's hslaToHsva function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsl.ts#L33 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param array $hsla The HSLA array to convert.
+        * @return array The HSVA array.
+        */
+       private static function colord_hsla_to_hsva( $hsla ) {
+               $h = $hsla['h'];
+               $s = $hsla['s'];
+               $l = $hsla['l'];
+               $a = $hsla['a'];
+
+               $s *= ( $l < 50 ? $l : 100 - $l ) / 100;
+
+               return array(
+                       'h' => $h,
+                       's' => $s > 0 ? ( ( 2 * $s ) / ( $l + $s ) ) * 100 : 0,
+                       'v' => $l + $s,
+                       'a' => $a,
+               );
+       }
+
+       /**
+        * Converts an HSLA array to RGBA.
+        *
+        * Direct port of colord's hslaToRgba function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hsl.ts#L55 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param array $hsla The HSLA array to convert.
+        * @return array The RGBA array.
+        */
+       private static function colord_hsla_to_rgba( $hsla ) {
+               return self::colord_hsva_to_rgba( self::colord_hsla_to_hsva( $hsla ) );
+       }
+
+       /**
+        * Parses a valid HSL[A] CSS color function/string.
+        *
+        * Direct port of colord's parseHslaString function.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/colorModels/hslString.ts#L17 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $input The HSLA string to parse.
+        * @return array|null An array of RGBA values or null if the RGB string is invalid.
+        */
+       private static function colord_parse_hsla_string( $input ) {
+               // Functional syntax.
+               $is_match = preg_match(
+                       '/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i',
+                       $input,
+                       $match
+               );
+
+               if ( ! $is_match ) {
+                       // Whitespace syntax.
+                       $is_match = preg_match(
+                               '/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i',
+                               $input,
+                               $match
+                       );
+               }
+
+               if ( ! $is_match ) {
+                       return null;
+               }
+
+               /*
+                * For some reason, preg_match doesn't include empty matches at the end
+                * of the array, so we add them manually to make things easier later.
+                */
+               for ( $i = 1; $i <= 6; $i++ ) {
+                       if ( ! isset( $match[ $i ] ) ) {
+                               $match[ $i ] = '';
+                       }
+               }
+
+               $hsla = self::colord_clamp_hsla(
+                       array(
+                               'h' => self::colord_parse_hue( $match[1], $match[2] ),
+                               's' => (float) $match[3],
+                               'l' => (float) $match[4],
+                               'a' => '' === $match[5] ? 1 : (float) $match[5] / ( $match[6] ? 100 : 1 ),
+                       )
+               );
+
+               return self::colord_hsla_to_rgba( $hsla );
+       }
+
+       /**
+        * Tries to convert an incoming string into RGBA values.
+        *
+        * Direct port of colord's parse function simplified for our use case. This
+        * version only supports string parsing and only returns RGBA values.
+        *
+        * @link https://github.com/omgovich/colord/blob/3f859e03b0ca622eb15480f611371a0f15c9427f/src/parse.ts#L37 Sourced from colord.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $input The string to parse.
+        * @return array|null An array of RGBA values or null if the string is invalid.
+        */
+       private static function colord_parse( $input ) {
+               $result = self::colord_parse_hex( $input );
+
+               if ( ! $result ) {
+                       $result = self::colord_parse_rgba_string( $input );
+               }
+
+               if ( ! $result ) {
+                       $result = self::colord_parse_hsla_string( $input );
+               }
+
+               return $result;
+       }
+
+       /**
+        * Takes the inline CSS duotone variable from a block and return the slug.
+        *
+        * Handles styles slugs like:
+        * var:preset|duotone|blue-orange
+        * var(--wp--preset--duotone--blue-orange)
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $duotone_attr The duotone attribute from a block.
+        * @return string The slug of the duotone preset or an empty string if no slug is found.
+        */
+       private static function get_slug_from_attribute( $duotone_attr ) {
+               // Uses Branch Reset Groups `(?|…)` to return one capture group.
+               preg_match( '/(?|var:preset\|duotone\|(\S+)|var\(--wp--preset--duotone--(\S+)\))/', $duotone_attr, $matches );
+
+               return ! empty( $matches[1] ) ? $matches[1] : '';
+       }
+
+       /**
+        * Checks if we have a valid duotone preset.
+        *
+        * Valid presets are defined in the $global_styles_presets array.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $duotone_attr The duotone attribute from a block.
+        * @return bool True if the duotone preset present and valid.
+        */
+       private static function is_preset( $duotone_attr ) {
+               $slug      = self::get_slug_from_attribute( $duotone_attr );
+               $filter_id = self::get_filter_id( $slug );
+
+               return array_key_exists( $filter_id, self::$global_styles_presets );
+       }
+
+       /**
+        * Gets the CSS variable name for a duotone preset.
+        *
+        * Example output:
+        *  --wp--preset--duotone--blue-orange
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $slug The slug of the duotone preset.
+        * @return string The CSS variable name.
+        */
+       private static function get_css_custom_property_name( $slug ) {
+               return "--wp--preset--duotone--$slug";
+       }
+
+       /**
+        * Get the ID of the duotone filter.
+        *
+        * Example output:
+        *  wp-duotone-blue-orange
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $slug The slug of the duotone preset.
+        * @return string The ID of the duotone filter.
+        */
+       private static function get_filter_id( $slug ) {
+               return "wp-duotone-$slug";
+       }
+
+       /**
+        * Get the CSS variable for a duotone preset.
+        *
+        * Example output:
+        *  var(--wp--preset--duotone--blue-orange)
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $slug The slug of the duotone preset.
+        * @return string The CSS variable.
+        */
+       private static function get_css_var( $slug ) {
+               $name = self::get_css_custom_property_name( $slug );
+               return "var($name)";
+       }
+
+       /**
+        * Get the URL for a duotone filter.
+        *
+        * Example output:
+        *  url(#wp-duotone-blue-orange)
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $filter_id The ID of the filter.
+        * @return string The URL for the duotone filter.
+        */
+       private static function get_filter_url( $filter_id ) {
+               return "url(#$filter_id)";
+       }
+
+       /**
+        * Gets the SVG for the duotone filter definition.
+        *
+        * Whitespace is removed when SCRIPT_DEBUG is not enabled.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $filter_id The ID of the filter.
+        * @param array  $colors    An array of color strings.
+        * @return string An SVG with a duotone filter definition.
+        */
+       private static function get_filter_svg( $filter_id, $colors ) {
+               $duotone_values = array(
+                       'r' => array(),
+                       'g' => array(),
+                       'b' => array(),
+                       'a' => array(),
+               );
+
+               foreach ( $colors as $color_str ) {
+                       $color = self::colord_parse( $color_str );
+
+                       if ( null === $color ) {
+                               $error_message = sprintf(
+                                       /* translators: %s: duotone colors */
+                                       __( '"%s" in theme.json settings.color.duotone is not a hex or rgb string.' ),
+                                       $color_str
+                               );
+                               _doing_it_wrong( __METHOD__, $error_message, '6.3.0' );
+                       } else {
+                               $duotone_values['r'][] = $color['r'] / 255;
+                               $duotone_values['g'][] = $color['g'] / 255;
+                               $duotone_values['b'][] = $color['b'] / 255;
+                               $duotone_values['a'][] = $color['a'];
+                       }
+               }
+
+               ob_start();
+
+               ?>
+
+               <svg
+                       xmlns="http://www.w3.org/2000/svg"
+                       viewBox="0 0 0 0"
+                       width="0"
+                       height="0"
+                       focusable="false"
+                       role="none"
+                       style="visibility: hidden; position: absolute; left: -9999px; overflow: hidden;"
+               >
+                       <defs>
+                               <filter id="<?php echo esc_attr( $filter_id ); ?>">
+                                       <feColorMatrix
+                                               color-interpolation-filters="sRGB"
+                                               type="matrix"
+                                               values="
+                                                       .299 .587 .114 0 0
+                                                       .299 .587 .114 0 0
+                                                       .299 .587 .114 0 0
+                                                       .299 .587 .114 0 0
+                                               "
+                                       />
+                                       <feComponentTransfer color-interpolation-filters="sRGB" >
+                                               <feFuncR type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['r'] ) ); ?>" />
+                                               <feFuncG type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['g'] ) ); ?>" />
+                                               <feFuncB type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['b'] ) ); ?>" />
+                                               <feFuncA type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['a'] ) ); ?>" />
+                                       </feComponentTransfer>
+                                       <feComposite in2="SourceGraphic" operator="in" />
+                               </filter>
+                       </defs>
+               </svg>
+
+               <?php
+
+               $svg = ob_get_clean();
+
+               if ( ! SCRIPT_DEBUG ) {
+                       // Clean up the whitespace.
+                       $svg = preg_replace( "/[\r\n\t ]+/", ' ', $svg );
+                       $svg = str_replace( '> <', '><', $svg );
+                       $svg = trim( $svg );
+               }
+
+               return $svg;
+       }
+
+       /**
+        * Returns the prefixed id for the duotone filter for use as a CSS id.
+        *
+        * Exported for the deprecated function wp_get_duotone_filter_id().
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        * @deprecated 6.3.0
+        *
+        * @param  array $preset Duotone preset value as seen in theme.json.
+        * @return string        Duotone filter CSS id.
+        */
+       public static function get_filter_id_from_preset( $preset ) {
+               _deprecated_function( __FUNCTION__, '6.3.0' );
+
+               $filter_id = '';
+               if ( isset( $preset['slug'] ) ) {
+                       $filter_id = self::get_filter_id( $preset['slug'] );
+               }
+               return $filter_id;
+       }
+
+       /**
+        * Gets the SVG for the duotone filter definition from a preset.
+        *
+        * Exported for the deprecated function wp_get_duotone_filter_property().
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        * @deprecated 6.3.0
+        *
+        * @param array $preset The duotone preset.
+        * @return string The SVG for the filter definition.
+        */
+       public static function get_filter_svg_from_preset( $preset ) {
+               _deprecated_function( __FUNCTION__, '6.3.0' );
+
+               $filter_id = self::get_filter_id_from_preset( $preset );
+               return self::get_filter_svg( $filter_id, $preset['colors'] );
+       }
+
+       /**
+        * Get the SVGs for the duotone filters.
+        *
+        * Example output:
+        *  <svg><defs><filter id="wp-duotone-blue-orange">…</filter></defs></svg><svg>…</svg>
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param array $sources The duotone presets.
+        * @return string The SVGs for the duotone filters.
+        */
+       private static function get_svg_definitions( $sources ) {
+               $svgs = '';
+               foreach ( $sources as $filter_id => $filter_data ) {
+                       $colors = $filter_data['colors'];
+                       $svgs  .= self::get_filter_svg( $filter_id, $colors );
+               }
+               return $svgs;
+       }
+
+       /**
+        * Get the CSS for global styles.
+        *
+        * Example output:
+        *  body{--wp--preset--duotone--blue-orange:url('#wp-duotone-blue-orange');}
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param array $sources The duotone presets.
+        * @return string The CSS for global styles.
+        */
+       private static function get_global_styles_presets( $sources ) {
+               $css = 'body{';
+               foreach ( $sources as $filter_id => $filter_data ) {
+                       $slug              = $filter_data['slug'];
+                       $colors            = $filter_data['colors'];
+                       $css_property_name = self::get_css_custom_property_name( $slug );
+                       $declaration_value = is_string( $colors ) ? $colors : self::get_filter_url( $filter_id );
+                       $css              .= "$css_property_name:$declaration_value;";
+               }
+               $css .= '}';
+               return $css;
+       }
+
+       /**
+        * Enqueue a block CSS declaration for the page.
+        *
+        * This does not include any SVGs.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $filter_id        The filter ID. e.g. 'wp-duotone-000000-ffffff-2'.
+        * @param string $duotone_selector The block's duotone selector. e.g. '.wp-block-image img'.
+        * @param string $filter_value     The filter CSS value. e.g. 'url(#wp-duotone-000000-ffffff-2)' or 'unset'.
+        */
+       private static function enqueue_block_css( $filter_id, $duotone_selector, $filter_value ) {
+               // Build the CSS selectors to which the filter will be applied.
+               $selectors = explode( ',', $duotone_selector );
+
+               $selectors_scoped = array();
+               foreach ( $selectors as $selector_part ) {
+                       /*
+                        * Assuming the selector part is a subclass selector (not a tag name)
+                        * so we can prepend the filter id class. If we want to support elements
+                        * such as `img` or namespaces, we'll need to add a case for that here.
+                        */
+                       $selectors_scoped[] = '.' . $filter_id . trim( $selector_part );
+               }
+
+               $selector = implode( ', ', $selectors_scoped );
+
+               self::$block_css_declarations[] = array(
+                       'selector'     => $selector,
+                       'declarations' => array(
+                               'filter' => $filter_value,
+                       ),
+               );
+       }
+
+       /**
+        * Enqueue custom filter assets for the page.
+        *
+        * Includes an SVG filter and block CSS declaration.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $filter_id        The filter ID. e.g. 'wp-duotone-000000-ffffff-2'.
+        * @param string $duotone_selector The block's duotone selector. e.g. '.wp-block-image img'.
+        * @param string $filter_value     The filter CSS value. e.g. 'url(#wp-duotone-000000-ffffff-2)' or 'unset'.
+        * @param array  $filter_data      Duotone filter data with 'slug' and 'colors' keys.
+        */
+       private static function enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, $filter_data ) {
+               self::$used_svg_filter_data[ $filter_id ] = $filter_data;
+               self::enqueue_block_css( $filter_id, $duotone_selector, $filter_value );
+       }
+
+       /**
+        * Enqueue preset assets for the page.
+        *
+        * Includes a CSS custom property, SVG filter, and block CSS declaration.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @param string $filter_id        The filter ID. e.g. 'wp-duotone-blue-orange'.
+        * @param string $duotone_selector The block's duotone selector. e.g. '.wp-block-image img'.
+        * @param string $filter_value     The filter CSS value. e.g. 'url(#wp-duotone-blue-orange)' or 'unset'.
+        */
+       private static function enqueue_global_styles_preset( $filter_id, $duotone_selector, $filter_value ) {
+               if ( ! array_key_exists( $filter_id, self::$global_styles_presets ) ) {
+                       $error_message = sprintf(
+                               /* translators: %s: duotone filter ID */
+                               __( 'The duotone id "%s" is not registered in theme.json settings' ),
+                               $filter_id
+                       );
+                       _doing_it_wrong( __METHOD__, $error_message, '6.3.0' );
+                       return;
+               }
+               self::$used_global_styles_presets[ $filter_id ] = self::$global_styles_presets[ $filter_id ];
+               self::enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, self::$global_styles_presets[ $filter_id ] );
+       }
+
+       /**
+        * Registers the style and colors block attributes for block types that support it.
+        *
+        * Block support is added with `supports.filter.duotone` in block.json.
+        *
+        * @since 6.3.0
+        *
+        * @param WP_Block_Type $block_type Block Type.
+        */
+       public static function register_duotone_support( $block_type ) {
+               $has_duotone_support = false;
+               if ( property_exists( $block_type, 'supports' ) ) {
+                       /*
+                        * Previous `color.__experimentalDuotone` support flag is migrated
+                        * to `filter.duotone` via `block_type_metadata_settings` filter.
+                        */
+                       $has_duotone_support = _wp_array_get( $block_type->supports, array( 'filter', 'duotone' ), null );
+               }
+
+               if ( $has_duotone_support ) {
+                       if ( ! $block_type->attributes ) {
+                               $block_type->attributes = array();
+                       }
+
+                       if ( ! array_key_exists( 'style', $block_type->attributes ) ) {
+                               $block_type->attributes['style'] = array(
+                                       'type' => 'object',
+                               );
+                       }
+               }
+       }
+
+       /**
+        * Get the CSS selector for a block type.
+        *
+        * This handles selectors defined in `color.__experimentalDuotone` support
+        * if `filter.duotone` support is not defined.
+        *
+        * @param string $block_name The block name.
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        *
+        * @return string The CSS selector or null if there is no support.
+        */
+       private static function get_selector( $block_name ) {
+               $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );
+
+               if ( $block_type && property_exists( $block_type, 'supports' ) ) {
+                       /*
+                        * Backwards compatibility with `supports.color.__experimentalDuotone`
+                        * is provided via the `block_type_metadata_settings` filter. If
+                        * `supports.filter.duotone` has not been set and the experimental
+                        * property has been, the experimental property value is copied into
+                        * `supports.filter.duotone`.
+                        */
+                       $duotone_support = _wp_array_get( $block_type->supports, array( 'filter', 'duotone' ), false );
+                       if ( ! $duotone_support ) {
+                               return null;
+                       }
+
+                       /*
+                        * If the experimental duotone support was set, that value is to be
+                        * treated as a selector and requires scoping.
+                        */
+                       $experimental_duotone = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), false );
+                       if ( $experimental_duotone ) {
+                               $root_selector = wp_get_block_css_selector( $block_type );
+                               return is_string( $experimental_duotone )
+                                       ? WP_Theme_JSON::scope_selector( $root_selector, $experimental_duotone )
+                                       : $root_selector;
+                       }
+
+                       // Regular filter.duotone support uses filter.duotone selectors with fallbacks.
+                       return wp_get_block_css_selector( $block_type, array( 'filter', 'duotone' ), true );
+               }
+       }
+
+       /**
+        * Scrape all possible duotone presets from global and theme styles and
+        * store them in self::$global_styles_presets.
+        *
+        * Used in conjunction with self::render_duotone_support for blocks that
+        * use duotone preset filters.
+        *
+        * @since 6.3.0
+        */
+       public static function set_global_styles_presets() {
+               // Get the per block settings from the theme.json.
+               $tree              = wp_get_global_settings();
+               $presets_by_origin = _wp_array_get( $tree, array( 'color', 'duotone' ), array() );
+
+               foreach ( $presets_by_origin as $presets ) {
+                       foreach ( $presets as $preset ) {
+                               $filter_id = self::get_filter_id( _wp_to_kebab_case( $preset['slug'] ) );
+
+                               self::$global_styles_presets[ $filter_id ] = $preset;
+                       }
+               }
+       }
+
+       /**
+        * Scrape all block names from global styles and store in self::$global_styles_block_names.
+        *
+        * Used in conjunction with self::render_duotone_support to output the
+        * duotone filters defined in the theme.json global styles.
+        *
+        * @since 6.3.0
+        */
+       public static function set_global_style_block_names() {
+               // Get the per block settings from the theme.json.
+               $tree        = WP_Theme_JSON_Resolver::get_merged_data();
+               $block_nodes = $tree->get_styles_block_nodes();
+               $theme_json  = $tree->get_raw_data();
+
+               foreach ( $block_nodes as $block_node ) {
+                       // This block definition doesn't include any duotone settings. Skip it.
+                       if ( empty( $block_node['duotone'] ) ) {
+                               continue;
+                       }
+
+                       // Value looks like this: 'var(--wp--preset--duotone--blue-orange)' or 'var:preset|duotone|blue-orange'.
+                       $duotone_attr_path = array_merge( $block_node['path'], array( 'filter', 'duotone' ) );
+                       $duotone_attr      = _wp_array_get( $theme_json, $duotone_attr_path, array() );
+
+                       if ( empty( $duotone_attr ) ) {
+                               continue;
+                       }
+                       // If it has a duotone filter preset, save the block name and the preset slug.
+                       $slug = self::get_slug_from_attribute( $duotone_attr );
+
+                       if ( $slug && $slug !== $duotone_attr ) {
+                               self::$global_styles_block_names[ $block_node['name'] ] = $slug;
+                       }
+               }
+       }
+
+       /**
+        * Render out the duotone CSS styles and SVG.
+        *
+        * The hooks self::set_global_style_block_names and self::set_global_styles_presets
+        * must be called before this function.
+        *
+        * @since 6.3.0
+        *
+        * @param  string $block_content Rendered block content.
+        * @param  array  $block         Block object.
+        * @return string                Filtered block content.
+        */
+       public static function render_duotone_support( $block_content, $block ) {
+               $duotone_selector = self::get_selector( $block['blockName'] );
+
+               // The block should have a duotone attribute or have duotone defined in its theme.json to be processed.
+               $has_duotone_attribute     = isset( $block['attrs']['style']['color']['duotone'] );
+               $has_global_styles_duotone = array_key_exists( $block['blockName'], self::$global_styles_block_names );
+
+               if (
+                       empty( $block_content ) ||
+                       ! $duotone_selector ||
+                       ( ! $has_duotone_attribute && ! $has_global_styles_duotone )
+               ) {
+                       return $block_content;
+               }
+
+               // Generate the pieces needed for rendering a duotone to the page.
+               if ( $has_duotone_attribute ) {
+
+                       /*
+                        * Possible values for duotone attribute:
+                        * 1. Array of colors - e.g. array('#000000', '#ffffff').
+                        * 2. Variable for an existing Duotone preset - e.g. 'var:preset|duotone|blue-orange' or 'var(--wp--preset--duotone--blue-orange)''
+                        * 3. A CSS string - e.g. 'unset' to remove globally applied duotone.
+                        */
+
+                       $duotone_attr = $block['attrs']['style']['color']['duotone'];
+                       $is_preset    = is_string( $duotone_attr ) && self::is_preset( $duotone_attr );
+                       $is_css       = is_string( $duotone_attr ) && ! $is_preset;
+                       $is_custom    = is_array( $duotone_attr );
+
+                       if ( $is_preset ) {
+
+                               $slug         = self::get_slug_from_attribute( $duotone_attr ); // e.g. 'blue-orange'.
+                               $filter_id    = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-blue-orange'.
+                               $filter_value = self::get_css_var( $slug ); // e.g. 'var(--wp--preset--duotone--blue-orange)'.
+
+                               // CSS custom property, SVG filter, and block CSS.
+                               self::enqueue_global_styles_preset( $filter_id, $duotone_selector, $filter_value );
+
+                       } elseif ( $is_css ) {
+                               $slug         = wp_unique_id( sanitize_key( $duotone_attr . '-' ) ); // e.g. 'unset-1'.
+                               $filter_id    = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-unset-1'.
+                               $filter_value = $duotone_attr; // e.g. 'unset'.
+
+                               // Just block CSS.
+                               self::enqueue_block_css( $filter_id, $duotone_selector, $filter_value );
+                       } elseif ( $is_custom ) {
+                               $slug         = wp_unique_id( sanitize_key( implode( '-', $duotone_attr ) . '-' ) ); // e.g. '000000-ffffff-2'.
+                               $filter_id    = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-000000-ffffff-2'.
+                               $filter_value = self::get_filter_url( $filter_id ); // e.g. 'url(#wp-duotone-filter-000000-ffffff-2)'.
+                               $filter_data  = array(
+                                       'slug'   => $slug,
+                                       'colors' => $duotone_attr,
+                               );
+
+                               // SVG filter and block CSS.
+                               self::enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, $filter_data );
+                       }
+               } elseif ( $has_global_styles_duotone ) {
+                       $slug         = self::$global_styles_block_names[ $block['blockName'] ]; // e.g. 'blue-orange'.
+                       $filter_id    = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-blue-orange'.
+                       $filter_value = self::get_css_var( $slug ); // e.g. 'var(--wp--preset--duotone--blue-orange)'.
+
+                       // CSS custom property, SVG filter, and block CSS.
+                       self::enqueue_global_styles_preset( $filter_id, $duotone_selector, $filter_value );
+               }
+
+               // Like the layout hook, this assumes the hook only applies to blocks with a single wrapper.
+               $tags = new WP_HTML_Tag_Processor( $block_content );
+               if ( $tags->next_tag() ) {
+                       $tags->add_class( $filter_id );
+               }
+               return $tags->get_updated_html();
+       }
+
+       /**
+        * Appends the used block duotone filter declarations to the inline block supports CSS.
+        *
+        * Uses the declarations saved in earlier calls to self::enqueue_block_css.
+        *
+        * @since 6.3.0
+        */
+       public static function output_block_styles() {
+               if ( ! empty( self::$block_css_declarations ) ) {
+                       wp_style_engine_get_stylesheet_from_css_rules(
+                               self::$block_css_declarations,
+                               array(
+                                       'context' => 'block-supports',
+                               )
+                       );
+               }
+       }
+
+       /**
+        * Appends the used global style duotone filter presets (CSS custom
+        * properties) to the inline global styles CSS.
+        *
+        * Uses the declarations saved in earlier calls to self::enqueue_global_styles_preset.
+        *
+        * @since 6.3.0
+        */
+       public static function output_global_styles() {
+               if ( ! empty( self::$used_global_styles_presets ) ) {
+                       wp_add_inline_style( 'global-styles', self::get_global_styles_presets( self::$used_global_styles_presets ) );
+               }
+       }
+
+       /**
+        * Outputs all necessary SVG for duotone filters, CSS for classic themes.
+        *
+        * Uses the declarations saved in earlier calls to self::enqueue_global_styles_preset
+        * and self::enqueue_custom_filter.
+        *
+        * @since 6.3.0
+        */
+       public static function output_footer_assets() {
+               if ( ! empty( self::$used_svg_filter_data ) ) {
+                       echo self::get_svg_definitions( self::$used_svg_filter_data );
+               }
+
+               // This is for classic themes - in block themes, the CSS is added in the head via wp_add_inline_style in the wp_enqueue_scripts action.
+               if ( ! wp_is_block_theme() && ! empty( self::$used_global_styles_presets ) ) {
+                       wp_add_inline_style( 'core-block-supports', self::get_global_styles_presets( self::$used_global_styles_presets ) );
+               }
+       }
+
+       /**
+        * Adds the duotone SVGs and CSS custom properties to the editor settings.
+        *
+        * This allows the properties to be pulled in by the EditorStyles component
+        * in JS and rendered in the post editor.
+        *
+        * @since 6.3.0
+        *
+        * @param array $settings The block editor settings from the `block_editor_settings_all` filter.
+        * @return array The editor settings with duotone SVGs and CSS custom properties.
+        */
+       public static function add_editor_settings( $settings ) {
+               if ( ! empty( self::$global_styles_presets ) ) {
+                       if ( ! isset( $settings['styles'] ) ) {
+                               $settings['styles'] = array();
+                       }
+
+                       $settings['styles'][] = array(
+                               // For the editor we can add all of the presets by default.
+                               'assets'         => self::get_svg_definitions( self::$global_styles_presets ),
+                               // The 'svgs' type is new in 6.3 and requires the corresponding JS changes in the EditorStyles component to work.
+                               '__unstableType' => 'svgs',
+                               // These styles not generated by global styles, so this must be false or they will be stripped out in wp_get_block_editor_settings.
+                               'isGlobalStyles' => false,
+                       );
+
+                       $settings['styles'][] = array(
+                               // For the editor we can add all of the presets by default.
+                               'css'            => self::get_global_styles_presets( self::$global_styles_presets ),
+                               // This must be set and must be something other than 'theme' or they will be stripped out in the post editor <Editor> component.
+                               '__unstableType' => 'presets',
+                               // These styles are no longer generated by global styles, so this must be false or they will be stripped out in wp_get_block_editor_settings.
+                               'isGlobalStyles' => false,
+                       );
+               }
+
+               return $settings;
+       }
+
+       /**
+        * Migrates the experimental duotone support flag to the stabilized location.
+        *
+        * This moves `supports.color.__experimentalDuotone` to `supports.filter.duotone`.
+        *
+        * @since 6.3.0
+        *
+        * @param array $settings Current block type settings.
+        * @param array $metadata Block metadata as read in via block.json.
+        *
+        * @return array Filtered block type settings.
+        */
+       public static function migrate_experimental_duotone_support_flag( $settings, $metadata ) {
+               $duotone_support = _wp_array_get( $metadata, array( 'supports', 'color', '__experimentalDuotone' ), null );
+
+               if ( ! isset( $settings['supports']['filter']['duotone'] ) && null !== $duotone_support ) {
+                       _wp_array_set( $settings, array( 'supports', 'filter', 'duotone' ), (bool) $duotone_support );
+               }
+
+               return $settings;
+       }
+
+       /**
+        * Gets the CSS filter property value from a preset.
+        *
+        * Exported for the deprecated function wp_get_duotone_filter_id().
+        *
+        * @internal
+        *
+        * @since 6.3.0
+        * @deprecated 6.3.0
+        *
+        * @param array $preset The duotone preset.
+        * @return string The CSS filter property value.
+        */
+       public static function get_filter_css_property_value_from_preset( $preset ) {
+               _deprecated_function( __FUNCTION__, '6.3.0' );
+
+               if ( isset( $preset['colors'] ) && is_string( $preset['colors'] ) ) {
+                       return $preset['colors'];
+               }
+
+               $filter_id = self::get_filter_id_from_preset( $preset );
+
+               return 'url(#' . $filter_id . ')';
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/src/wp-includes/class-wp-duotone.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><a id="trunksrcwpincludesclasswpthemejsonphp"></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/class-wp-theme-json.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-theme-json.php     2023-06-28 23:26:16 UTC (rev 56100)
+++ trunk/src/wp-includes/class-wp-theme-json.php       2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -114,6 +114,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.0.0 Replaced `override` with `prevent_override` and updated the
</span><span class="cx" style="display: block; padding: 0 10px">         *              `prevent_override` value for `color.duotone` to use `color.defaultDuotone`.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.2.0 Added 'shadow' presets.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @since 6.3.0 Replaced value_func for duotone with `null`. Custom properties are handled by class-wp-duotone.php.
</ins><span class="cx" style="display: block; padding: 0 10px">          * @var array
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        const PRESETS_METADATA = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -143,8 +144,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'path'              => array( 'color', 'duotone' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'prevent_override'  => array( 'color', 'defaultDuotone' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'use_default_names' => false,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'value_func'        => 'wp_get_duotone_filter_property',
-                       'css_vars'          => '--wp--preset--duotone--$slug',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'value_func'        => null, // CSS Custom Properties for duotone are handled by block supports in class-wp-duotone.php.
+                       'css_vars'          => null,
</ins><span class="cx" style="display: block; padding: 0 10px">                         'classes'           => array(),
</span><span class="cx" style="display: block; padding: 0 10px">                        'properties'        => array( 'filter' ),
</span><span class="cx" style="display: block; padding: 0 10px">                ),
</span></span></pre></div>
<a id="trunksrcwpincludesdefaultfiltersphp"></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/default-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/default-filters.php 2023-06-28 23:26:16 UTC (rev 56100)
+++ trunk/src/wp-includes/default-filters.php   2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -606,10 +606,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'wp_enqueue_scripts', 'wp_enqueue_stored_styles' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'wp_footer', 'wp_enqueue_stored_styles', 1 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-// SVG filters like duotone have to be loaded at the beginning of the body in both admin and the front-end.
-add_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
-add_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' );
-
</del><span class="cx" style="display: block; padding: 0 10px"> add_action( 'wp_default_styles', 'wp_default_styles' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludesdeprecatedphp"></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/deprecated.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/deprecated.php      2023-06-28 23:26:16 UTC (rev 56100)
+++ trunk/src/wp-includes/deprecated.php        2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4804,3 +4804,501 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        return $image;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Takes input from [0, n] and returns it as [0, 1].
+ *
+ * Direct port of TinyColor's function, lightly simplified to maintain
+ * consistency with TinyColor.
+ *
+ * @link https://github.com/bgrins/TinyColor
+ *
+ * @since 5.8.0
+ * @deprecated 6.3.0
+ *
+ * @access private
+ *
+ * @param mixed $n   Number of unknown type.
+ * @param int   $max Upper value of the range to bound to.
+ * @return float Value in the range [0, 1].
+ */
+function wp_tinycolor_bound01( $n, $max ) {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+       if ( 'string' === gettype( $n ) && str_contains( $n, '.' ) && 1 === (float) $n ) {
+               $n = '100%';
+       }
+
+       $n = min( $max, max( 0, (float) $n ) );
+
+       // Automatically convert percentage into number.
+       if ( 'string' === gettype( $n ) && str_contains( $n, '%' ) ) {
+               $n = (int) ( $n * $max ) / 100;
+       }
+
+       // Handle floating point rounding errors.
+       if ( ( abs( $n - $max ) < 0.000001 ) ) {
+               return 1.0;
+       }
+
+       // Convert into [0, 1] range if it isn't already.
+       return ( $n % $max ) / (float) $max;
+}
+
+/**
+ * Direct port of tinycolor's boundAlpha function to maintain consistency with
+ * how tinycolor works.
+ *
+ * @link https://github.com/bgrins/TinyColor
+ *
+ * @since 5.9.0
+ * @deprecated 6.3.0
+ *
+ * @access private
+ *
+ * @param mixed $n Number of unknown type.
+ * @return float Value in the range [0,1].
+ */
+function _wp_tinycolor_bound_alpha( $n ) {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+
+       if ( is_numeric( $n ) ) {
+               $n = (float) $n;
+               if ( $n >= 0 && $n <= 1 ) {
+                       return $n;
+               }
+       }
+       return 1;
+}
+
+/**
+ * Rounds and converts values of an RGB object.
+ *
+ * Direct port of TinyColor's function, lightly simplified to maintain
+ * consistency with TinyColor.
+ *
+ * @link https://github.com/bgrins/TinyColor
+ *
+ * @since 5.8.0
+ * @deprecated 6.3.0
+ *
+ * @access private
+ *
+ * @param array $rgb_color RGB object.
+ * @return array Rounded and converted RGB object.
+ */
+function wp_tinycolor_rgb_to_rgb( $rgb_color ) {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+
+       return array(
+               'r' => wp_tinycolor_bound01( $rgb_color['r'], 255 ) * 255,
+               'g' => wp_tinycolor_bound01( $rgb_color['g'], 255 ) * 255,
+               'b' => wp_tinycolor_bound01( $rgb_color['b'], 255 ) * 255,
+       );
+}
+
+/**
+ * Helper function for hsl to rgb conversion.
+ *
+ * Direct port of TinyColor's function, lightly simplified to maintain
+ * consistency with TinyColor.
+ *
+ * @link https://github.com/bgrins/TinyColor
+ *
+ * @since 5.8.0
+ * @deprecated 6.3.0
+ *
+ * @access private
+ *
+ * @param float $p first component.
+ * @param float $q second component.
+ * @param float $t third component.
+ * @return float R, G, or B component.
+ */
+function wp_tinycolor_hue_to_rgb( $p, $q, $t ) {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+
+       if ( $t < 0 ) {
+               ++$t;
+       }
+       if ( $t > 1 ) {
+               --$t;
+       }
+       if ( $t < 1 / 6 ) {
+               return $p + ( $q - $p ) * 6 * $t;
+       }
+       if ( $t < 1 / 2 ) {
+               return $q;
+       }
+       if ( $t < 2 / 3 ) {
+               return $p + ( $q - $p ) * ( 2 / 3 - $t ) * 6;
+       }
+       return $p;
+}
+
+/**
+ * Converts an HSL object to an RGB object with converted and rounded values.
+ *
+ * Direct port of TinyColor's function, lightly simplified to maintain
+ * consistency with TinyColor.
+ *
+ * @link https://github.com/bgrins/TinyColor
+ *
+ * @since 5.8.0
+ * @deprecated 6.3.0
+ *
+ * @access private
+ *
+ * @param array $hsl_color HSL object.
+ * @return array Rounded and converted RGB object.
+ */
+function wp_tinycolor_hsl_to_rgb( $hsl_color ) {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+
+       $h = wp_tinycolor_bound01( $hsl_color['h'], 360 );
+       $s = wp_tinycolor_bound01( $hsl_color['s'], 100 );
+       $l = wp_tinycolor_bound01( $hsl_color['l'], 100 );
+
+       if ( 0 === $s ) {
+               // Achromatic.
+               $r = $l;
+               $g = $l;
+               $b = $l;
+       } else {
+               $q = $l < 0.5 ? $l * ( 1 + $s ) : $l + $s - $l * $s;
+               $p = 2 * $l - $q;
+               $r = wp_tinycolor_hue_to_rgb( $p, $q, $h + 1 / 3 );
+               $g = wp_tinycolor_hue_to_rgb( $p, $q, $h );
+               $b = wp_tinycolor_hue_to_rgb( $p, $q, $h - 1 / 3 );
+       }
+
+       return array(
+               'r' => $r * 255,
+               'g' => $g * 255,
+               'b' => $b * 255,
+       );
+}
+
+/**
+ * Parses hex, hsl, and rgb CSS strings using the same regex as TinyColor v1.4.2
+ * used in the JavaScript. Only colors output from react-color are implemented.
+ *
+ * Direct port of TinyColor's function, lightly simplified to maintain
+ * consistency with TinyColor.
+ *
+ * @link https://github.com/bgrins/TinyColor
+ * @link https://github.com/casesandberg/react-color/
+ *
+ * @since 5.8.0
+ * @since 5.9.0 Added alpha processing.
+ * @deprecated 6.3.0
+ *
+ * @access private
+ *
+ * @param string $color_str CSS color string.
+ * @return array RGB object.
+ */
+function wp_tinycolor_string_to_rgb( $color_str ) {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+
+       $color_str = strtolower( trim( $color_str ) );
+
+       $css_integer = '[-\\+]?\\d+%?';
+       $css_number  = '[-\\+]?\\d*\\.\\d+%?';
+
+       $css_unit = '(?:' . $css_number . ')|(?:' . $css_integer . ')';
+
+       $permissive_match3 = '[\\s|\\(]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')\\s*\\)?';
+       $permissive_match4 = '[\\s|\\(]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')\\s*\\)?';
+
+       $rgb_regexp = '/^rgb' . $permissive_match3 . '$/';
+       if ( preg_match( $rgb_regexp, $color_str, $match ) ) {
+               $rgb = wp_tinycolor_rgb_to_rgb(
+                       array(
+                               'r' => $match[1],
+                               'g' => $match[2],
+                               'b' => $match[3],
+                       )
+               );
+
+               $rgb['a'] = 1;
+
+               return $rgb;
+       }
+
+       $rgba_regexp = '/^rgba' . $permissive_match4 . '$/';
+       if ( preg_match( $rgba_regexp, $color_str, $match ) ) {
+               $rgb = wp_tinycolor_rgb_to_rgb(
+                       array(
+                               'r' => $match[1],
+                               'g' => $match[2],
+                               'b' => $match[3],
+                       )
+               );
+
+               $rgb['a'] = _wp_tinycolor_bound_alpha( $match[4] );
+
+               return $rgb;
+       }
+
+       $hsl_regexp = '/^hsl' . $permissive_match3 . '$/';
+       if ( preg_match( $hsl_regexp, $color_str, $match ) ) {
+               $rgb = wp_tinycolor_hsl_to_rgb(
+                       array(
+                               'h' => $match[1],
+                               's' => $match[2],
+                               'l' => $match[3],
+                       )
+               );
+
+               $rgb['a'] = 1;
+
+               return $rgb;
+       }
+
+       $hsla_regexp = '/^hsla' . $permissive_match4 . '$/';
+       if ( preg_match( $hsla_regexp, $color_str, $match ) ) {
+               $rgb = wp_tinycolor_hsl_to_rgb(
+                       array(
+                               'h' => $match[1],
+                               's' => $match[2],
+                               'l' => $match[3],
+                       )
+               );
+
+               $rgb['a'] = _wp_tinycolor_bound_alpha( $match[4] );
+
+               return $rgb;
+       }
+
+       $hex8_regexp = '/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/';
+       if ( preg_match( $hex8_regexp, $color_str, $match ) ) {
+               $rgb = wp_tinycolor_rgb_to_rgb(
+                       array(
+                               'r' => base_convert( $match[1], 16, 10 ),
+                               'g' => base_convert( $match[2], 16, 10 ),
+                               'b' => base_convert( $match[3], 16, 10 ),
+                       )
+               );
+
+               $rgb['a'] = _wp_tinycolor_bound_alpha(
+                       base_convert( $match[4], 16, 10 ) / 255
+               );
+
+               return $rgb;
+       }
+
+       $hex6_regexp = '/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/';
+       if ( preg_match( $hex6_regexp, $color_str, $match ) ) {
+               $rgb = wp_tinycolor_rgb_to_rgb(
+                       array(
+                               'r' => base_convert( $match[1], 16, 10 ),
+                               'g' => base_convert( $match[2], 16, 10 ),
+                               'b' => base_convert( $match[3], 16, 10 ),
+                       )
+               );
+
+               $rgb['a'] = 1;
+
+               return $rgb;
+       }
+
+       $hex4_regexp = '/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/';
+       if ( preg_match( $hex4_regexp, $color_str, $match ) ) {
+               $rgb = wp_tinycolor_rgb_to_rgb(
+                       array(
+                               'r' => base_convert( $match[1] . $match[1], 16, 10 ),
+                               'g' => base_convert( $match[2] . $match[2], 16, 10 ),
+                               'b' => base_convert( $match[3] . $match[3], 16, 10 ),
+                       )
+               );
+
+               $rgb['a'] = _wp_tinycolor_bound_alpha(
+                       base_convert( $match[4] . $match[4], 16, 10 ) / 255
+               );
+
+               return $rgb;
+       }
+
+       $hex3_regexp = '/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/';
+       if ( preg_match( $hex3_regexp, $color_str, $match ) ) {
+               $rgb = wp_tinycolor_rgb_to_rgb(
+                       array(
+                               'r' => base_convert( $match[1] . $match[1], 16, 10 ),
+                               'g' => base_convert( $match[2] . $match[2], 16, 10 ),
+                               'b' => base_convert( $match[3] . $match[3], 16, 10 ),
+                       )
+               );
+
+               $rgb['a'] = 1;
+
+               return $rgb;
+       }
+
+       /*
+        * The JS color picker considers the string "transparent" to be a hex value,
+        * so we need to handle it here as a special case.
+        */
+       if ( 'transparent' === $color_str ) {
+               return array(
+                       'r' => 0,
+                       'g' => 0,
+                       'b' => 0,
+                       'a' => 0,
+               );
+       }
+}
+
+/**
+ * Returns the prefixed id for the duotone filter for use as a CSS id.
+ *
+ * @since 5.9.1
+ * @deprecated 6.3.0
+ *
+ * @access private
+ *
+ * @param array $preset Duotone preset value as seen in theme.json.
+ * @return string Duotone filter CSS id.
+ */
+function wp_get_duotone_filter_id( $preset ) {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+       return WP_Duotone::get_filter_id_from_preset( $preset );
+}
+
+/**
+ * Returns the CSS filter property url to reference the rendered SVG.
+ *
+ * @since 5.9.0
+ * @since 6.1.0 Allow unset for preset colors.
+ * @deprecated 6.3.0
+ *
+ * @access private
+ *
+ * @param array $preset Duotone preset value as seen in theme.json.
+ * @return string Duotone CSS filter property url value.
+ */
+function wp_get_duotone_filter_property( $preset ) {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+       return WP_Duotone::get_filter_css_property_value_from_preset( $preset );
+}
+
+/**
+ * Returns the duotone filter SVG string for the preset.
+ *
+ * @since 5.9.1
+ * @deprecated 6.3.0
+ *
+ * @access private
+ *
+ * @param array $preset Duotone preset value as seen in theme.json.
+ * @return string Duotone SVG filter.
+ */
+function wp_get_duotone_filter_svg( $preset ) {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+       return WP_Duotone::get_filter_svg_from_preset( $preset );
+}
+
+/**
+ * Registers the style and colors block attributes for block types that support it.
+ *
+ * @since 5.8.0
+ * @deprecated 6.3.0 Use WP_Duotone::register_duotone_support() instead.
+ *
+ * @access private
+ *
+ * @param WP_Block_Type $block_type Block Type.
+ */
+function wp_register_duotone_support( $block_type ) {
+       _deprecated_function( __FUNCTION__, '6.3.0', 'WP_Duotone::register_duotone_support' );
+       return WP_Duotone::register_duotone_support( $block_type );
+}
+
+/**
+ * Renders out the duotone stylesheet and SVG.
+ *
+ * @since 5.8.0
+ * @since 6.1.0 Allow unset for preset colors.
+ * @deprecated 6.3.0 Use WP_Duotone::render_duotone_support() instead.
+ * 
+ * @access private
+ *
+ * @param string $block_content Rendered block content.
+ * @param array  $block         Block object.
+ * @return string Filtered block content.
+ */
+function wp_render_duotone_support( $block_content, $block ) {
+       _deprecated_function( __FUNCTION__, '6.3.0', 'WP_Duotone::render_duotone_support' );
+       return WP_Duotone::render_duotone_support( $block_content, $block );
+}
+
+/**
+ * Returns a string containing the SVGs to be referenced as filters (duotone).
+ *
+ * @since 5.9.1
+ * @deprecated 6.3.0 SVG generation is handled on a per-block basis in block supports.
+ *
+ * @return string
+ */
+function wp_get_global_styles_svg_filters() {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+
+       /*
+        * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
+        * developer's workflow.
+        */
+       $can_use_cached = wp_get_development_mode() !== 'theme';
+       $cache_group    = 'theme_json';
+       $cache_key      = 'wp_get_global_styles_svg_filters';
+       if ( $can_use_cached ) {
+               $cached = wp_cache_get( $cache_key, $cache_group );
+               if ( $cached ) {
+                       return $cached;
+               }
+       }
+
+       $supports_theme_json = wp_theme_has_theme_json();
+
+       $origins = array( 'default', 'theme', 'custom' );
+       if ( ! $supports_theme_json ) {
+               $origins = array( 'default' );
+       }
+
+       $tree = WP_Theme_JSON_Resolver::get_merged_data();
+       $svgs = $tree->get_svg_filters( $origins );
+
+       if ( $can_use_cached ) {
+               wp_cache_set( $cache_key, $svgs, $cache_group );
+       }
+
+       return $svgs;
+}
+
+/**
+ * Renders the SVG filters supplied by theme.json.
+ *
+ * Note that this doesn't render the per-block user-defined
+ * filters which are handled by wp_render_duotone_support,
+ * but it should be rendered before the filtered content
+ * in the body to satisfy Safari's rendering quirks.
+ *
+ * @since 5.9.1
+ * @deprecated 6.3.0 SVG generation is handled on a per-block basis in block supports.
+ */
+function wp_global_styles_render_svg_filters() {
+       _deprecated_function( __FUNCTION__, '6.3.0' );
+
+       /*
+        * When calling via the in_admin_header action, we only want to render the
+        * SVGs on block editor pages.
+        */
+       if (
+               is_admin() &&
+               ! get_current_screen()->is_block_editor()
+       ) {
+               return;
+       }
+
+       $filters = wp_get_global_styles_svg_filters();
+       if ( ! empty( $filters ) ) {
+               echo $filters;
+       }
+}
</ins></span></pre></div>
<a id="trunksrcwpincludesglobalstylesandsettingsphp"></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/global-styles-and-settings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/global-styles-and-settings.php      2023-06-28 23:26:16 UTC (rev 56100)
+++ trunk/src/wp-includes/global-styles-and-settings.php        2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -289,45 +289,6 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Returns a string containing the SVGs to be referenced as filters (duotone).
- *
- * @since 5.9.1
- *
- * @return string
- */
-function wp_get_global_styles_svg_filters() {
-       /*
-        * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
-        * developer's workflow.
-        */
-       $can_use_cached = wp_get_development_mode() !== 'theme';
-       $cache_group    = 'theme_json';
-       $cache_key      = 'wp_get_global_styles_svg_filters';
-       if ( $can_use_cached ) {
-               $cached = wp_cache_get( $cache_key, $cache_group );
-               if ( $cached ) {
-                       return $cached;
-               }
-       }
-
-       $supports_theme_json = wp_theme_has_theme_json();
-
-       $origins = array( 'default', 'theme', 'custom' );
-       if ( ! $supports_theme_json ) {
-               $origins = array( 'default' );
-       }
-
-       $tree = WP_Theme_JSON_Resolver::get_merged_data();
-       $svgs = $tree->get_svg_filters( $origins );
-
-       if ( $can_use_cached ) {
-               wp_cache_set( $cache_key, $svgs, $cache_group );
-       }
-
-       return $svgs;
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px">  * Adds global style rules to the inline style for each block.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.1.0
</span></span></pre></div>
<a id="trunksrcwpincludesscriptloaderphp"></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/script-loader.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/script-loader.php   2023-06-28 23:26:16 UTC (rev 56100)
+++ trunk/src/wp-includes/script-loader.php     2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2480,34 +2480,6 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Renders the SVG filters supplied by theme.json.
- *
- * Note that this doesn't render the per-block user-defined
- * filters which are handled by wp_render_duotone_support,
- * but it should be rendered before the filtered content
- * in the body to satisfy Safari's rendering quirks.
- *
- * @since 5.9.1
- */
-function wp_global_styles_render_svg_filters() {
-       /*
-        * When calling via the in_admin_header action, we only want to render the
-        * SVGs on block editor pages.
-        */
-       if (
-               is_admin() &&
-               ! get_current_screen()->is_block_editor()
-       ) {
-               return;
-       }
-
-       $filters = wp_get_global_styles_svg_filters();
-       if ( ! empty( $filters ) ) {
-               echo $filters;
-       }
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px">  * Checks if the editor scripts and styles for all registered block types
</span><span class="cx" style="display: block; padding: 0 10px">  * should be enqueued on the current screen.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span></span></pre></div>
<a id="trunksrcwpsettingsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-settings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-settings.php 2023-06-28 23:26:16 UTC (rev 56100)
+++ trunk/src/wp-settings.php   2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -175,6 +175,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-theme-json-data.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-theme-json.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-theme-json-resolver.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+require ABSPATH . WPINC . '/class-wp-duotone.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/global-styles-and-settings.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-block-template.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/block-template-utils.php';
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksupportsduotonephp"></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/duotone.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-supports/duotone.php                              (rev 0)
+++ trunk/tests/phpunit/tests/block-supports/duotone.php        2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,124 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test the block WP_Duotone class.
+ *
+ * @package WordPress
+ */
+
+class Tests_Block_Supports_DuoTones extends WP_UnitTestCase {
+       /**
+        * Cleans up CSS added to block-supports from duotone styles. We neeed to do this
+        * in order to avoid impacting other tests.
+        */
+       public static function wpTearDownAfterClass() {
+               WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
+       }
+
+       /**
+        * Tests whether the duotone preset class is added to the block.
+        *
+        * @ticket 58555
+        *
+        * @covers ::render_duotone_support
+        */
+       public function test_render_duotone_support_preset() {
+               $block         = array(
+                       'blockName' => 'core/image',
+                       'attrs'     => array( 'style' => array( 'color' => array( 'duotone' => 'var:preset|duotone|blue-orange' ) ) ),
+               );
+               $block_content = '<figure class="wp-block-image size-full"><img src="/my-image.jpg" /></figure>';
+               $expected      = '<figure class="wp-block-image size-full wp-duotone-blue-orange"><img src="/my-image.jpg" /></figure>';
+               $this->assertSame( $expected, WP_Duotone::render_duotone_support( $block_content, $block ) );
+       }
+
+       /**
+        * Tests whether the duotone unset class is added to the block.
+        *
+        * @ticket 58555
+        *
+        * @covers ::render_duotone_support
+        */
+       public function test_render_duotone_support_css() {
+               $block         = array(
+                       'blockName' => 'core/image',
+                       'attrs'     => array( 'style' => array( 'color' => array( 'duotone' => 'unset' ) ) ),
+               );
+               $block_content = '<figure class="wp-block-image size-full"><img src="/my-image.jpg" /></figure>';
+               $expected      = '/<figure class="wp-block-image size-full wp-duotone-unset-\d+"><img src="\\/my-image.jpg" \\/><\\/figure>/';
+               $this->assertMatchesRegularExpression( $expected, WP_Duotone::render_duotone_support( $block_content, $block ) );
+       }
+
+       /**
+        * Tests whether the duotone custom class is added to the block.
+        *
+        * @covers ::render_duotone_support
+        */
+       public function test_render_duotone_support_custom() {
+               $block         = array(
+                       'blockName' => 'core/image',
+                       'attrs'     => array( 'style' => array( 'color' => array( 'duotone' => array( '#FFFFFF', '#000000' ) ) ) ),
+               );
+               $block_content = '<figure class="wp-block-image size-full"><img src="/my-image.jpg" /></figure>';
+               $expected      = '/<figure class="wp-block-image size-full wp-duotone-ffffff-000000-\d+"><img src="\\/my-image.jpg" \\/><\\/figure>/';
+               $this->assertMatchesRegularExpression( $expected, WP_Duotone::render_duotone_support( $block_content, $block ) );
+       }
+
+       /**
+        * Tests whether the slug is extracted from the attribute.
+        *
+        * @dataProvider data_get_slug_from_attribute
+        * @covers ::get_slug_from_attribute
+        */
+       public function test_get_slug_from_attribute( $data_attr, $expected ) {
+
+               $reflection = new ReflectionMethod( 'WP_Duotone', 'get_slug_from_attribute' );
+               $reflection->setAccessible( true );
+
+               $this->assertSame( $expected, $reflection->invoke( null, $data_attr ) );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array[].
+        */
+       public function data_get_slug_from_attribute() {
+               return array(
+                       'pipe-slug'                       => array( 'var:preset|duotone|blue-orange', 'blue-orange' ),
+                       'css-var'                         => array( 'var(--wp--preset--duotone--blue-orange)', 'blue-orange' ),
+                       'css-var-invalid-slug-chars'      => array( 'var(--wp--preset--duotone--.)', '.' ),
+                       'css-var-missing-end-parenthesis' => array( 'var(--wp--preset--duotone--blue-orange', '' ),
+                       'invalid'                         => array( 'not a valid attribute', '' ),
+                       'css-var-no-value'                => array( 'var(--wp--preset--duotone--)', '' ),
+                       'pipe-slug-no-value'              => array( 'var:preset|duotone|', '' ),
+                       'css-var-spaces'                  => array( 'var(--wp--preset--duotone--    ', '' ),
+                       'pipe-slug-spaces'                => array( 'var:preset|duotone|  ', '' ),
+               );
+       }
+
+       /**
+        * @dataProvider data_is_preset
+        */
+       public function test_is_preset( $data_attr, $expected ) {
+               $reflection = new ReflectionMethod( 'WP_Duotone', 'is_preset' );
+               $reflection->setAccessible( true );
+
+               $this->assertSame( $expected, $reflection->invoke( null, $data_attr ) );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array[].
+        */
+       public function data_is_preset() {
+               return array(
+                       'pipe-slug'                       => array( 'var:preset|duotone|blue-orange', true ),
+                       'css-var'                         => array( 'var(--wp--preset--duotone--blue-orange)', true ),
+                       'css-var-invalid-slug-chars'      => array( 'var(--wp--preset--duotone--.)', false ),
+                       'css-var-missing-end-parenthesis' => array( 'var(--wp--preset--duotone--blue-orange', false ),
+                       'invalid'                         => array( 'not a valid attribute', false ),
+               );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/block-supports/duotone.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><a id="trunktestsphpunitteststhemewpGetGlobalStylesSvgFiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme/wpGetGlobalStylesSvgFilters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme/wpGetGlobalStylesSvgFilters.php   2023-06-28 23:26:16 UTC (rev 56100)
+++ trunk/tests/phpunit/tests/theme/wpGetGlobalStylesSvgFilters.php     2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,62 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-/**
- * Tests wp_get_global_styles_svg_filters().
- *
- * @group themes
- */
-class Tests_Theme_wpGetGlobalStylesSvgFilters extends WP_UnitTestCase {
-       public function set_up() {
-               parent::set_up();
-               // Clear caches.
-               wp_clean_themes_cache();
-       }
-
-       public function tear_down() {
-               wp_clean_themes_cache();
-
-               parent::tear_down();
-       }
-
-       /**
-        * Tests that switching themes recalculates the svgs.
-        *
-        * @covers ::wp_get_global_styles_svg_filters
-        *
-        * @ticket 57568
-        */
-       public function test_switching_themes_should_recalculate_svg() {
-               $svg_for_default_theme = wp_get_global_styles_svg_filters();
-               switch_theme( 'block-theme' );
-               $svg_for_block_theme = wp_get_global_styles_svg_filters();
-               switch_theme( WP_DEFAULT_THEME );
-
-               $this->assertStringContainsString( '<svg', $svg_for_default_theme, 'Default theme should contain SVG' );
-               $this->assertStringContainsString( '<svg', $svg_for_default_theme, 'Block theme should contain SVG' );
-               $this->assertNotSame( $svg_for_default_theme, $svg_for_block_theme, 'Cache value should have changed' );
-       }
-
-       /**
-        * Tests that the function relies on the development mode for whether to use caching.
-        *
-        * @ticket 57487
-        *
-        * @covers ::wp_get_global_styles_svg_filters
-        */
-       public function test_caching_is_used_when_developing_theme() {
-               global $_wp_tests_development_mode;
-
-               switch_theme( 'block-theme' );
-
-               // Store SVG in cache.
-               $svg = '<svg></svg>';
-               wp_cache_set( 'wp_get_global_styles_svg_filters', $svg, 'theme_json' );
-
-               // By default, caching should be used, so the above value will be returned.
-               $_wp_tests_development_mode = '';
-               $this->assertSame( $svg, wp_get_global_styles_svg_filters(), 'Caching was not used despite development mode disabled' );
-
-               // When the development mode is set to 'theme', caching should not be used.
-               $_wp_tests_development_mode = 'theme';
-               $this->assertNotSame( $svg, wp_get_global_styles_svg_filters(), 'Caching was used despite theme development mode' );
-       }
-}
</del></span></pre></div>
<a id="trunktestsphpunitteststhemewpThemeJsonphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme/wpThemeJson.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme/wpThemeJson.php   2023-06-28 23:26:16 UTC (rev 56100)
+++ trunk/tests/phpunit/tests/theme/wpThemeJson.php     2023-06-29 06:19:41 UTC (rev 56101)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -636,7 +636,7 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $variables = "body{--wp--preset--color--grey: grey;--wp--preset--gradient--custom-gradient: linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%);--wp--preset--duotone--custom-duotone: url('#wp-duotone-custom-duotone');--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $variables = 'body{--wp--preset--color--grey: grey;--wp--preset--gradient--custom-gradient: linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%);--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}';
</ins><span class="cx" style="display: block; padding: 0 10px">                 $styles    = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: a
 uto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){max-width: var(--wp--style--global--content-size);margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignwide{max-width: var(--wp--style--global--wide-size);}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}.wp-element-button, .wp-block-button__link{box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.66);}.wp-block-group{background: var(--wp--preset--gradient--custom-gradient);border-radius: 10px;padding: 24px;}.wp-block-group a:where(:not(.wp-element-button)){color: #111;}.wp-block-heading{color: #123456;}.wp-block-heading a:where(:not(.wp-element-button)){background-color: 
 #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a:where(:not(.wp-element-button)){background-color: #777;color: #555;}.wp-block-post-excerpt{column-count: 2;}.wp-block-image{margin-bottom: 30px;}.wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder{border-top-left-radius: 10px;border-bottom-right-radius: 1em;}.wp-block-image img, .wp-block-image .components-placeholder{filter: var(--wp--preset--duotone--custom-duotone);}';
</span><span class="cx" style="display: block; padding: 0 10px">                $presets   = '.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-custom-gradient-gradient-background{background: var(--wp--preset--gradient--custom-gradient) !important;}.has-small-font-family{font-family: var(--wp--preset--font-family--small) !important;}.has-big-font-family{font-family: var(--wp--preset--font-family--big) !important;}';
</span><span class="cx" style="display: block; padding: 0 10px">                $all       = $variables . $styles . $presets;
</span></span></pre>
</div>
</div>

</body>
</html>