<!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>[58171] trunk: Editor: pass fluid typography theme.json settings to `wp_get_typography_font_size_value`.</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/58171">58171</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/58171","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>2024-05-18 23:16:09 +0000 (Sat, 18 May 2024)</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: pass fluid typography theme.json settings to `wp_get_typography_font_size_value`.
Updates `wp_get_typography_font_size_value` to accept an array of theme.json settings instead of a boolean derived from global state.
Props ramonopoly, audrasjb.
Fixes <a href="https://core.trac.wordpress.org/ticket/61118">#61118</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportstypographyphp">trunk/src/wp-includes/block-supports/typography.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonphp">trunk/src/wp-includes/class-wp-theme-json.php</a></li>
<li><a href="#trunktestsphpunittestsblocksupportstypographyphp">trunk/tests/phpunit/tests/block-supports/typography.php</a></li>
<li><a href="#trunktestsphpunitteststhemewpThemeJsonphp">trunk/tests/phpunit/tests/theme/wpThemeJson.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportstypographyphp"></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/typography.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/typography.php 2024-05-18 20:30:57 UTC (rev 58170)
+++ trunk/src/wp-includes/block-supports/typography.php 2024-05-18 23:16:09 UTC (rev 58171)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -498,8 +498,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.2.0 Added 'settings.typography.fluid.minFontSize' support.
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.3.0 Using layout.wideSize as max viewport width, and logarithmic scale factor to calculate minimum font scale.
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.4.0 Added configurable min and max viewport width values to the typography.fluid theme.json schema.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.6.0 Deprecated bool argument $should_use_fluid_typography.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $preset {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $preset {
</ins><span class="cx" style="display: block; padding: 0 10px"> * Required. fontSizes preset value as seen in theme.json.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $name Name of the font size preset.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -506,11 +507,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $slug Kebab-case, unique identifier for the font size preset.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string|int|float $size CSS font-size value, including units if applicable.
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
- * Default is false.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param bool|array $settings Optional Theme JSON settings array that overrides any global theme settings.
+ * Default is false.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string|null Font-size value or null if a size is not passed in $preset.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_get_typography_font_size_value( $preset, $should_use_fluid_typography = false ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+
+function wp_get_typography_font_size_value( $preset, $settings = array() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $preset['size'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return null;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -523,25 +526,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $preset['size'];
</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">- // Checks if fluid font sizes are activated.
- $global_settings = wp_get_global_settings();
- $typography_settings = isset( $global_settings['typography'] ) ? $global_settings['typography'] : array();
- $layout_settings = isset( $global_settings['layout'] ) ? $global_settings['layout'] : array();
-
- if (
- isset( $typography_settings['fluid'] ) &&
- ( true === $typography_settings['fluid'] || is_array( $typography_settings['fluid'] ) )
- ) {
- $should_use_fluid_typography = true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * As a boolean (deprecated since 6.6), $settings acts as an override to switch fluid typography "on" (`true`) or "off" (`false`).
+ */
+ if ( is_bool( $settings ) ) {
+ _deprecated_argument( __FUNCTION__, '6.6.0', __( '`boolean` type for second argument `$settings` is deprecated. Use `array()` instead.' ) );
+ $settings = array(
+ 'typography' => array(
+ 'fluid' => $settings,
+ ),
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Fallback to global settings as default.
+ $global_settings = wp_get_global_settings();
+ $settings = wp_parse_args(
+ $settings,
+ $global_settings
+ );
+
+ $typography_settings = isset( $settings['typography'] ) ? $settings['typography'] : array();
+ $should_use_fluid_typography = ! empty( $typography_settings['fluid'] );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $should_use_fluid_typography ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $preset['size'];
</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">- $fluid_settings = isset( $typography_settings['fluid'] ) && is_array( $typography_settings['fluid'] )
- ? $typography_settings['fluid']
- : array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // $typography_settings['fluid'] can be a bool or an array. Normalize to array.
+ $fluid_settings = is_array( $typography_settings['fluid'] ) ? $typography_settings['fluid'] : array();
+ $layout_settings = isset( $settings['layout'] ) ? $settings['layout'] : array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Defaults.
</span><span class="cx" style="display: block; padding: 0 10px"> $default_maximum_viewport_width = '1600px';
</span></span></pre></div>
<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 2024-05-18 20:30:57 UTC (rev 58170)
+++ trunk/src/wp-includes/class-wp-theme-json.php 2024-05-18 23:16:09 UTC (rev 58171)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1831,6 +1831,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * </code>
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.6.0 Passing $settings to the callbacks defined in static::PRESETS_METADATA.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $settings Settings to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $preset_metadata One of the PRESETS_METADATA values.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1857,7 +1858,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> is_callable( $preset_metadata['value_func'] )
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $value_func = $preset_metadata['value_func'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $value = call_user_func( $value_func, $preset );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $value = call_user_func( $value_func, $preset, $settings );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> // If we don't have a value, then don't add it to the result.
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2050,6 +2051,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0 Added the `$settings` and `$properties` parameters.
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.1.0 Added `$theme_json`, `$selector`, and `$use_root_padding` parameters.
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0 Output a `min-height: unset` rule when `aspect-ratio` is set.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.6.0 Passing current theme JSON settings to wp_get_typography_font_size_value().
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $styles Styles to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $settings Theme settings.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2117,8 +2119,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * whether the incoming value can be converted to a fluid value.
</span><span class="cx" style="display: block; padding: 0 10px"> * Values that already have a clamp() function will not pass the test,
</span><span class="cx" style="display: block; padding: 0 10px"> * and therefore the original $value will be returned.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Pass the current theme_json settings to override any global settings.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $value = wp_get_typography_font_size_value( array( 'size' => $value ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $value = wp_get_typography_font_size_value( array( 'size' => $value ), $settings );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'aspect-ratio' === $css_property ) {
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksupportstypographyphp"></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/block-supports/typography.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-supports/typography.php 2024-05-18 20:30:57 UTC (rev 58170)
+++ trunk/tests/phpunit/tests/block-supports/typography.php 2024-05-18 23:16:09 UTC (rev 58171)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -294,12 +294,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 56467
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 57065
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 58523
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 61118
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::wp_get_typography_font_size_value
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @dataProvider data_generate_font_size_preset_fixtures
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $font_size_preset {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $font_size_preset {
</ins><span class="cx" style="display: block; padding: 0 10px"> * Required. fontSizes preset value as seen in theme.json.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $name Name of the font size preset.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -306,11 +307,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $slug Kebab-case unique identifier for the font size preset.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $size CSS font-size value, including units where applicable.
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
- * @param string $expected_output Expected output.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param bool $settings Theme JSON settings array that overrides any global theme settings.
+ * @param string $expected_output Expected output.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_wp_get_typography_font_size_value( $font_size_preset, $should_use_fluid_typography, $expected_output ) {
- $actual = wp_get_typography_font_size_value( $font_size_preset, $should_use_fluid_typography );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_wp_get_typography_font_size_value( $font_size_preset, $settings, $expected_output ) {
+ $actual = wp_get_typography_font_size_value( $font_size_preset, $settings );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected_output, $actual );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -323,124 +324,223 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function data_generate_font_size_preset_fixtures() {
</span><span class="cx" style="display: block; padding: 0 10px"> return array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns value when fluid typography is deactivated' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '28px',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => false,
- 'expected_output' => '28px',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => null,
+ 'expected_output' => '28px',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns value where font size is 0' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => 0,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 0,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 0,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> "returns value where font size is '0'" => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '0',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => '0',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => '0',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns value where `size` is `null`' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => false,
- 'expected_output' => null,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => null,
+ 'expected_output' => null,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns value when fluid is `false`' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '28px',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => '28px',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => false,
+ ),
+ ),
+ 'expected_output' => '28px',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'returns value when fluid is empty array' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => array(),
+ ),
+ ),
+ 'expected_output' => '28px',
+ ),
+ 'returns clamp value with minViewportWidth override' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => array(
+ 'minViewportWidth' => '500px',
+ ),
+ ),
+ ),
+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 5px) * 0.918), 28px)',
+ ),
+ 'returns clamp value with maxViewportWidth override' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => array(
+ 'maxViewportWidth' => '500px',
+ ),
+ ),
+ ),
+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 5.608), 28px)',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'returns clamp value with layout.wideSize override' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ 'layout' => array(
+ 'wideSize' => '500px',
+ ),
+ ),
+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 5.608), 28px)',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'returns already clamped value' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => 'clamp(21px, 1.313rem + ((1vw - 7.68px) * 2.524), 42px)',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(21px, 1.313rem + ((1vw - 7.68px) * 2.524), 42px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(21px, 1.313rem + ((1vw - 7.68px) * 2.524), 42px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns value with unsupported unit' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '1000%',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => '1000%',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => '1000%',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value with rem min and max units' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '1.75rem',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(1.119rem, 1.119rem + ((1vw - 0.2rem) * 0.789), 1.75rem)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(1.119rem, 1.119rem + ((1vw - 0.2rem) * 0.789), 1.75rem)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value with em min and max units' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '1.75em',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(1.119em, 1.119rem + ((1vw - 0.2em) * 0.789), 1.75em)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(1.119em, 1.119rem + ((1vw - 0.2em) * 0.789), 1.75em)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value for floats' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '70.175px',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(37.897px, 2.369rem + ((1vw - 3.2px) * 2.522), 70.175px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(37.897px, 2.369rem + ((1vw - 3.2px) * 2.522), 70.175px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'coerces integer to `px` and returns clamp value' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => 33,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(20.515px, 1.282rem + ((1vw - 3.2px) * 0.975), 33px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(20.515px, 1.282rem + ((1vw - 3.2px) * 0.975), 33px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'coerces float to `px` and returns clamp value' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => 70.175,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(37.897px, 2.369rem + ((1vw - 3.2px) * 2.522), 70.175px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(37.897px, 2.369rem + ((1vw - 3.2px) * 2.522), 70.175px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value when `fluid` is empty array' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '28px',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 0.789), 28px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 0.789), 28px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value when `fluid` is `null`' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '28px',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 0.789), 28px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 0.789), 28px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value where min and max fluid values defined' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '80px',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'min' => '70px',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -447,12 +547,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'max' => '125px',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(70px, 4.375rem + ((1vw - 3.2px) * 4.297), 125px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(70px, 4.375rem + ((1vw - 3.2px) * 4.297), 125px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value where max is equal to size' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '7.8125rem',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'min' => '4.375rem',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -459,12 +563,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'max' => '7.8125rem',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(4.375rem, 4.375rem + ((1vw - 0.2rem) * 4.298), 7.8125rem)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(4.375rem, 4.375rem + ((1vw - 0.2rem) * 4.298), 7.8125rem)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value if min font size is greater than max' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '3rem',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'min' => '5rem',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -471,12 +579,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'max' => '32px',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(5rem, 5rem + ((1vw - 0.2rem) * -3.75), 32px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(5rem, 5rem + ((1vw - 0.2rem) * -3.75), 32px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns value with invalid min/max fluid units' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '10em',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'min' => '20vw',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -483,28 +595,40 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'max' => '50%',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => '10em',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => '10em',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns value when size is < lower bounds and no fluid min/max set' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '3px',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => '3px',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => '3px',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns value when size is equal to lower bounds and no fluid min/max set' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '14px',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => '14px',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => '14px',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value with different min max units' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '28px',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'min' => '20px',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -511,34 +635,46 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'max' => '50rem',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(20px, 1.25rem + ((1vw - 3.2px) * 60.938), 50rem)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(20px, 1.25rem + ((1vw - 3.2px) * 60.938), 50rem)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value where no fluid max size is set' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '50px',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'min' => '2.6rem',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(2.6rem, 2.6rem + ((1vw - 0.2rem) * 0.656), 50px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(2.6rem, 2.6rem + ((1vw - 0.2rem) * 0.656), 50px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value where no fluid min size is set' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '28px',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'max' => '80px',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 4.851), 80px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 4.851), 80px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'should not apply lower bound test when fluid values are set' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '1.5rem',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'min' => '0.5rem',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -545,34 +681,46 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'max' => '5rem',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(0.5rem, 0.5rem + ((1vw - 0.2rem) * 5.625), 5rem)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(0.5rem, 0.5rem + ((1vw - 0.2rem) * 5.625), 5rem)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'should not apply lower bound test when only fluid min is set' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '20px',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'min' => '12px',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(12px, 0.75rem + ((1vw - 3.2px) * 0.625), 20px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(12px, 0.75rem + ((1vw - 3.2px) * 0.625), 20px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'should not apply lower bound test when only fluid max is set' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '0.875rem',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'max' => '20rem',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 23.906), 20rem)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 23.906), 20rem)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'returns clamp value when min and max font sizes are equal' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size_preset' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size_preset' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '4rem',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'min' => '30px',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -579,40 +727,205 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'max' => '30px',
</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">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(30px, 1.875rem + ((1vw - 3.2px) * 1), 30px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(30px, 1.875rem + ((1vw - 3.2px) * 1), 30px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'should apply scaled min font size for em values when custom min font size is not set' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '12rem',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(5.174rem, 5.174rem + ((1vw - 0.2rem) * 8.533), 12rem)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(5.174rem, 5.174rem + ((1vw - 0.2rem) * 8.533), 12rem)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'should apply scaled min font size for px values when custom min font size is not set' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '200px',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'should_use_fluid_typography' => true,
- 'expected_output' => 'clamp(85.342px, 5.334rem + ((1vw - 3.2px) * 8.958), 200px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(85.342px, 5.334rem + ((1vw - 3.2px) * 8.958), 200px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'should not apply scaled min font size for minimum font size when custom min font size is set' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_size' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_size' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'size' => '200px',
</span><span class="cx" style="display: block; padding: 0 10px"> 'fluid' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'min' => '100px',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ ),
+ ),
+ 'expected_output' => 'clamp(100px, 6.25rem + ((1vw - 3.2px) * 7.813), 200px)',
+ ),
+ );
+ }
+
+ /**
+ * Tests backwards compatibility for deprecated second argument $should_use_fluid_typography.
+ *
+ * @ticket 61118
+ *
+ * @covers ::wp_get_typography_font_size_value
+ *
+ * @expectedDeprecated wp_get_typography_font_size_value
+ *
+ * @dataProvider data_generate_font_size_preset_should_use_fluid_typography_deprecated_fixtures
+ *
+ * @param array $font_size {
+ * Required. A font size as represented in the fontSizes preset format as seen in theme.json.
+ *
+ * @type string $name Name of the font size preset.
+ * @type string $slug Kebab-case unique identifier for the font size preset.
+ * @type string $size CSS font-size value, including units where applicable.
+ * }
+ * @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
+ * @param string $expected_output Expected output of wp_get_typography_font_size_value().
+ */
+ public function test_wp_get_typography_font_size_value_should_use_fluid_typography_deprecated( $font_size, $should_use_fluid_typography, $expected_output ) {
+ $actual = wp_get_typography_font_size_value( $font_size, $should_use_fluid_typography );
+
+ $this->assertSame( $expected_output, $actual );
+ }
+
+ /**
+ * Data provider for test_wp_get_typography_font_size_value_should_use_fluid_typography_deprecated.
+ *
+ * @return array
+ */
+ public function data_generate_font_size_preset_should_use_fluid_typography_deprecated_fixtures() {
+ return array(
+ 'returns value when fluid typography is deactivated' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
+ 'should_use_fluid_typography' => false,
+ 'expected_output' => '28px',
+ ),
+ 'returns clamp value when fluid typography is activated' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'should_use_fluid_typography' => true,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'expected_output' => 'clamp(100px, 6.25rem + ((1vw - 3.2px) * 7.813), 200px)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 0.789), 28px)',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Tests that theme json settings passed to wp_get_typography_font_size_value
+ * override global theme settings.
+ *
+ * @ticket 61118
+ *
+ * @covers ::wp_get_typography_font_size_value
+ *
+ * @dataProvider data_generate_should_override_theme_settings_fixtures
+ *
+ * @param array $font_size {
+ * Required. A font size as represented in the fontSizes preset format as seen in theme.json.
+ *
+ * @type string $name Name of the font size preset.
+ * @type string $slug Kebab-case unique identifier for the font size preset.
+ * @type string $size CSS font-size value, including units where applicable.
+ * }
+ * @param bool $settings Theme JSON settings array that overrides any global theme settings.
+ * @param string $expected_output Expected output of wp_get_typography_font_size_value().
+ */
+ public function test_should_override_theme_settings( $font_size, $settings, $expected_output ) {
+ switch_theme( 'block-theme-child-with-fluid-typography' );
+ $actual = wp_get_typography_font_size_value( $font_size, $settings );
+
+ $this->assertSame( $expected_output, $actual );
+ }
+
+ /**
+ * Data provider for test_wp_get_typography_font_size_value_should_use_fluid_typography_deprecated.
+ *
+ * @return array
+ */
+ public function data_generate_should_override_theme_settings_fixtures() {
+ return array(
+ 'returns clamp value when theme activates fluid typography' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
+ 'settings' => null,
+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 0.789), 28px)',
+ ),
+ 'returns value when settings argument deactivates fluid typography' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => false,
+ ),
+ ),
+ 'expected_output' => '28px',
+ ),
+
+ 'returns clamp value when settings argument sets a fluid.minViewportWidth value' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => array(
+ 'minViewportWidth' => '500px',
+ ),
+ ),
+ ),
+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 5px) * 0.918), 28px)',
+ ),
+
+ 'returns clamp value when settings argument sets a layout.wideSize value' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
+ 'settings' => array(
+ 'layout' => array(
+ 'wideSize' => '500px',
+ ),
+ ),
+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 5.608), 28px)',
+ ),
+
+ 'returns clamp value with maxViewportWidth preferred over fallback layout.wideSize value' => array(
+ 'font_size' => array(
+ 'size' => '28px',
+ ),
+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => array(
+ 'maxViewportWidth' => '1000px',
+ ),
+ ),
+ 'layout' => array(
+ 'wideSize' => '500px',
+ ),
+ ),
+ 'expected_output' => 'clamp(17.905px, 1.119rem + ((1vw - 3.2px) * 1.485), 28px)',
+ ),
+ );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Tests that custom font sizes are converted to fluid values
</span><span class="cx" style="display: block; padding: 0 10px"> * in inline block supports styles
</span><span class="cx" style="display: block; padding: 0 10px"> * when "settings.typography.fluid" is set to true.
</span></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 2024-05-18 20:30:57 UTC (rev 58170)
+++ trunk/tests/phpunit/tests/theme/wpThemeJson.php 2024-05-18 23:16:09 UTC (rev 58171)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1417,6 +1417,70 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Tests that settings passed to WP_Theme_JSON override merged theme data.
+ *
+ * @ticket 61118
+ */
+ public function test_get_stylesheet_generates_fluid_typography_values() {
+ register_block_type(
+ 'test/clamp-me',
+ array(
+ 'api_version' => 3,
+ )
+ );
+ $theme_json = new WP_Theme_JSON(
+ array(
+ 'version' => WP_Theme_JSON::LATEST_SCHEMA,
+ 'settings' => array(
+ 'typography' => array(
+ 'fluid' => true,
+ 'fontSizes' => array(
+ array(
+ 'size' => '16px',
+ 'slug' => 'pickles',
+ 'name' => 'Pickles',
+ ),
+ array(
+ 'size' => '22px',
+ 'slug' => 'toast',
+ 'name' => 'Toast',
+ ),
+ ),
+ ),
+ ),
+ 'styles' => array(
+ 'typography' => array(
+ 'fontSize' => '1em',
+ ),
+ 'elements' => array(
+ 'h1' => array(
+ 'typography' => array(
+ 'fontSize' => '100px',
+ ),
+ ),
+ ),
+ 'blocks' => array(
+ 'test/clamp-me' => array(
+ 'typography' => array(
+ 'fontSize' => '48px',
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'default'
+ );
+
+ unregister_block_type( 'test/clamp-me' );
+
+ // Results also include root site blocks styles.
+ $this->assertSame(
+ 'body{--wp--preset--font-size--pickles: clamp(14px, 0.875rem + ((1vw - 3.2px) * 0.156), 16px);--wp--preset--font-size--toast: clamp(14.642px, 0.915rem + ((1vw - 3.2px) * 0.575), 22px);}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;mar
gin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}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{font-size: clamp(0.875em, 0.875rem + ((1vw - 0.2em) * 0.156), 1em);}h1{font-size: clamp(50.171px, 3.136rem + ((1vw - 3.2px) * 3.893), 100px);}.wp-block-test-clamp-me{font-size: clamp(27.894px, 1.743rem + ((1vw - 3.2px) * 1.571), 48px);}.has-pickles-font-size{font-size: var(--wp--preset--font-size--pickles) !important;}.has-toast-font-size{font-size: var(--wp--preset--font-size--toast) !important;}',
+ $theme_json->get_stylesheet()
+ );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> public function test_allow_indirect_properties() {
</span><span class="cx" style="display: block; padding: 0 10px"> $actual = WP_Theme_JSON::remove_insecure_properties(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span></span></pre>
</div>
</div>
</body>
</html>