@@ -9,7 +9,6 @@ const DEFAULT_MAXIMUM_VIEWPORT_WIDTH = '1600px';
9
9
const DEFAULT_MINIMUM_VIEWPORT_WIDTH = '768px' ;
10
10
const DEFAULT_SCALE_FACTOR = 1 ;
11
11
const DEFAULT_MINIMUM_FONT_SIZE_FACTOR = 0.75 ;
12
- const DEFAULT_MAXIMUM_FONT_SIZE_FACTOR = 1.5 ;
13
12
const DEFAULT_MINIMUM_FONT_SIZE_LIMIT = '14px' ;
14
13
15
14
/**
@@ -41,7 +40,6 @@ const DEFAULT_MINIMUM_FONT_SIZE_LIMIT = '14px';
41
40
* @param {?string } args.minimumFontSize Minimum font size for any clamp() calculation. Optional.
42
41
* @param {?number } args.scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.
43
42
* @param {?number } args.minimumFontSizeFactor How much to scale defaultFontSize by to derive minimumFontSize. Optional.
44
- * @param {?number } args.maximumFontSizeFactor How much to scale defaultFontSize by to derive maximumFontSize. Optional.
45
43
*
46
44
* @return {string|null } A font-size value using clamp().
47
45
*/
@@ -53,15 +51,8 @@ export function getComputedFluidTypographyValue( {
53
51
maximumViewPortWidth = DEFAULT_MAXIMUM_VIEWPORT_WIDTH ,
54
52
scaleFactor = DEFAULT_SCALE_FACTOR ,
55
53
minimumFontSizeFactor = DEFAULT_MINIMUM_FONT_SIZE_FACTOR ,
56
- maximumFontSizeFactor = DEFAULT_MAXIMUM_FONT_SIZE_FACTOR ,
57
54
minimumFontSizeLimit = DEFAULT_MINIMUM_FONT_SIZE_LIMIT ,
58
55
} ) {
59
- /*
60
- * Caches minimumFontSize in minimumFontSizeValue
61
- * so we can check if minimumFontSize exists later.
62
- */
63
- let minimumFontSizeValue = minimumFontSize ;
64
-
65
56
/*
66
57
* Calculates missing minimumFontSize and maximumFontSize from
67
58
* defaultFontSize if provided.
@@ -75,15 +66,6 @@ export function getComputedFluidTypographyValue( {
75
66
return null ;
76
67
}
77
68
78
- // If no minimumFontSize is provided, derive using min scale factor.
79
- if ( ! minimumFontSizeValue ) {
80
- minimumFontSizeValue =
81
- roundToPrecision (
82
- fontSizeParsed . value * minimumFontSizeFactor ,
83
- 3
84
- ) + fontSizeParsed . unit ;
85
- }
86
-
87
69
// Parses the minimum font size limit, so we can perform checks using it.
88
70
const minimumFontSizeLimitParsed = getTypographyValueAndUnit (
89
71
minimumFontSizeLimit ,
@@ -92,57 +74,51 @@ export function getComputedFluidTypographyValue( {
92
74
}
93
75
) ;
94
76
95
- if ( ! ! minimumFontSizeLimitParsed ?. value ) {
77
+ // Don't enforce minimum font size if a font size has explicitly set a min and max value.
78
+ if (
79
+ ! ! minimumFontSizeLimitParsed ?. value &&
80
+ ! minimumFontSize &&
81
+ ! maximumFontSize
82
+ ) {
96
83
/*
97
84
* If a minimum size was not passed to this function
98
- * and the user-defined font size is lower than `minimumFontSizeLimit` ,
99
- * then uses the user-defined font size as the minimum font-size .
85
+ * and the user-defined font size is lower than $minimum_font_size_limit ,
86
+ * do not calculate a fluid value .
100
87
*/
101
- if (
102
- ! minimumFontSize &&
103
- fontSizeParsed ?. value < minimumFontSizeLimitParsed ?. value
104
- ) {
105
- minimumFontSizeValue = `${ fontSizeParsed . value } ${ fontSizeParsed . unit } ` ;
106
- } else {
107
- const minimumFontSizeParsed = getTypographyValueAndUnit (
108
- minimumFontSizeValue ,
109
- {
110
- coerceTo : fontSizeParsed . unit ,
111
- }
112
- ) ;
113
-
114
- /*
115
- * Otherwise, if the passed or calculated minimum font size is lower than `minimumFontSizeLimit`
116
- * use `minimumFontSizeLimit` instead.
117
- */
118
- if (
119
- ! ! minimumFontSizeParsed ?. value &&
120
- minimumFontSizeParsed . value <
121
- minimumFontSizeLimitParsed . value
122
- ) {
123
- minimumFontSizeValue = `${ minimumFontSizeLimitParsed . value } ${ minimumFontSizeLimitParsed . unit } ` ;
124
- }
88
+ if ( fontSizeParsed ?. value <= minimumFontSizeLimitParsed ?. value ) {
89
+ return null ;
125
90
}
126
91
}
127
92
128
- // If no maximumFontSize is provided, derive using max scale factor .
93
+ // If no fluid max font size is available use the incoming value .
129
94
if ( ! maximumFontSize ) {
130
- maximumFontSize =
131
- roundToPrecision (
132
- fontSizeParsed . value * maximumFontSizeFactor ,
133
- 3
134
- ) + fontSizeParsed . unit ;
95
+ maximumFontSize = `${ fontSizeParsed . value } ${ fontSizeParsed . unit } ` ;
135
96
}
136
- }
137
97
138
- // Return early if one of the provided inputs is not provided.
139
- if ( ! minimumFontSizeValue || ! maximumFontSize ) {
140
- return null ;
98
+ /*
99
+ * If no minimumFontSize is provided, create one using
100
+ * the given font size multiplied by the min font size scale factor.
101
+ */
102
+ if ( ! minimumFontSize ) {
103
+ const calculatedMinimumFontSize = roundToPrecision (
104
+ fontSizeParsed . value * minimumFontSizeFactor ,
105
+ 3
106
+ ) ;
107
+
108
+ // Only use calculated min font size if it's > $minimum_font_size_limit value.
109
+ if (
110
+ ! ! minimumFontSizeLimitParsed ?. value &&
111
+ calculatedMinimumFontSize < minimumFontSizeLimitParsed ?. value
112
+ ) {
113
+ minimumFontSize = `${ minimumFontSizeLimitParsed . value } ${ minimumFontSizeLimitParsed . unit } ` ;
114
+ } else {
115
+ minimumFontSize = `${ calculatedMinimumFontSize } ${ fontSizeParsed . unit } ` ;
116
+ }
117
+ }
141
118
}
142
119
143
120
// Grab the minimum font size and normalize it in order to use the value for calculations.
144
- const minimumFontSizeParsed =
145
- getTypographyValueAndUnit ( minimumFontSizeValue ) ;
121
+ const minimumFontSizeParsed = getTypographyValueAndUnit ( minimumFontSize ) ;
146
122
147
123
// We get a 'preferred' unit to keep units consistent when calculating,
148
124
// otherwise the result will not be accurate.
@@ -159,12 +135,9 @@ export function getComputedFluidTypographyValue( {
159
135
}
160
136
161
137
// Uses rem for accessible fluid target font scaling.
162
- const minimumFontSizeRem = getTypographyValueAndUnit (
163
- minimumFontSizeValue ,
164
- {
165
- coerceTo : 'rem' ,
166
- }
167
- ) ;
138
+ const minimumFontSizeRem = getTypographyValueAndUnit ( minimumFontSize , {
139
+ coerceTo : 'rem' ,
140
+ } ) ;
168
141
169
142
// Viewport widths defined for fluid typography. Normalize units
170
143
const maximumViewPortWidthParsed = getTypographyValueAndUnit (
@@ -205,7 +178,7 @@ export function getComputedFluidTypographyValue( {
205
178
) ;
206
179
const fluidTargetFontSize = `${ minimumFontSizeRem . value } ${ minimumFontSizeRem . unit } + ((1vw - ${ viewPortWidthOffset } ) * ${ linearFactorScaled } )` ;
207
180
208
- return `clamp(${ minimumFontSizeValue } , ${ fluidTargetFontSize } , ${ maximumFontSize } )` ;
181
+ return `clamp(${ minimumFontSize } , ${ fluidTargetFontSize } , ${ maximumFontSize } )` ;
209
182
}
210
183
211
184
/**
0 commit comments