@wordpress/block-editor 10.0.5 → 10.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ### Bug Fix
6
+
7
+ - `FontSizePicker`: Update fluid utils so that only string, floats and integers are treated as valid font sizes for the purposes of fluid typography ([#44847](https://github.com/WordPress/gutenberg/pull/44847))
8
+ - `getTypographyClassesAndStyles()`: Ensure that font sizes are transformed into fluid values if fluid typography is activated ([#44852](https://github.com/WordPress/gutenberg/pull/44852))
9
+
10
+ ## 10.2.0 (2022-10-05)
11
+
12
+ ## 10.1.0 (2022-09-21)
13
+
5
14
  ## 10.0.0 (2022-09-13)
6
15
 
7
16
  ### Breaking change
package/README.md CHANGED
@@ -395,6 +395,45 @@ _Returns_
395
395
 
396
396
  - `?Object`: Color object included in the colors array whose color property equals colorValue. Returns undefined if no color object matches this requirement.
397
397
 
398
+ ### getComputedFluidTypographyValue
399
+
400
+ Computes a fluid font-size value that uses clamp(). A minimum and maxinmum
401
+ font size OR a single font size can be specified.
402
+
403
+ If a single font size is specified, it is scaled up and down by
404
+ minimumFontSizeFactor and maximumFontSizeFactor to arrive at the minimum and
405
+ maximum sizes.
406
+
407
+ _Usage_
408
+
409
+ ```js
410
+ // Calculate fluid font-size value from a minimum and maximum value.
411
+ const fontSize = getComputedFluidTypographyValue( {
412
+ minimumFontSize: '20px',
413
+ maximumFontSize: '45px',
414
+ } );
415
+ // Calculate fluid font-size value from a single font size.
416
+ const fontSize = getComputedFluidTypographyValue( {
417
+ fontSize: '30px',
418
+ } );
419
+ ```
420
+
421
+ _Parameters_
422
+
423
+ - _args_ `Object`:
424
+ - _args.minimumViewPortWidth_ `?string`: Minimum viewport size from which type will have fluidity. Optional if fontSize is specified.
425
+ - _args.maximumViewPortWidth_ `?string`: Maximum size up to which type will have fluidity. Optional if fontSize is specified.
426
+ - _args.fontSize_ `[string|number]`: Size to derive maximumFontSize and minimumFontSize from, if necessary. Optional if minimumFontSize and maximumFontSize are specified.
427
+ - _args.maximumFontSize_ `?string`: Maximum font size for any clamp() calculation. Optional.
428
+ - _args.minimumFontSize_ `?string`: Minimum font size for any clamp() calculation. Optional.
429
+ - _args.scaleFactor_ `?number`: A scale factor to determine how fast a font scales within boundaries. Optional.
430
+ - _args.minimumFontSizeFactor_ `?number`: How much to scale defaultFontSize by to derive minimumFontSize. Optional.
431
+ - _args.maximumFontSizeFactor_ `?number`: How much to scale defaultFontSize by to derive maximumFontSize. Optional.
432
+
433
+ _Returns_
434
+
435
+ - `string|null`: A font-size value using clamp().
436
+
398
437
  ### getFontSize
399
438
 
400
439
  Returns the font size object based on an array of named font sizes and the namedFontSize and customFontSize values.
@@ -482,6 +521,7 @@ attributes.
482
521
  _Parameters_
483
522
 
484
523
  - _attributes_ `Object`: Block attributes.
524
+ - _isFluidFontSizeActive_ `boolean`: Whether the function should try to convert font sizes to fluid values.
485
525
 
486
526
  _Returns_
487
527
 
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getComputedFluidTypographyValue = getComputedFluidTypographyValue;
7
+ exports.getTypographyValueAndUnit = getTypographyValueAndUnit;
8
+ exports.roundToPrecision = roundToPrecision;
9
+
10
+ /**
11
+ * The fluid utilities must match the backend equivalent.
12
+ * See: gutenberg_get_typography_font_size_value() in lib/block-supports/typography.php
13
+ * ---------------------------------------------------------------
14
+ */
15
+ // Defaults.
16
+ const DEFAULT_MAXIMUM_VIEWPORT_WIDTH = '1600px';
17
+ const DEFAULT_MINIMUM_VIEWPORT_WIDTH = '768px';
18
+ const DEFAULT_SCALE_FACTOR = 1;
19
+ const DEFAULT_MINIMUM_FONT_SIZE_FACTOR = 0.75;
20
+ const DEFAULT_MAXIMUM_FONT_SIZE_FACTOR = 1.5;
21
+ /**
22
+ * Computes a fluid font-size value that uses clamp(). A minimum and maxinmum
23
+ * font size OR a single font size can be specified.
24
+ *
25
+ * If a single font size is specified, it is scaled up and down by
26
+ * minimumFontSizeFactor and maximumFontSizeFactor to arrive at the minimum and
27
+ * maximum sizes.
28
+ *
29
+ * @example
30
+ * ```js
31
+ * // Calculate fluid font-size value from a minimum and maximum value.
32
+ * const fontSize = getComputedFluidTypographyValue( {
33
+ * minimumFontSize: '20px',
34
+ * maximumFontSize: '45px'
35
+ * } );
36
+ * // Calculate fluid font-size value from a single font size.
37
+ * const fontSize = getComputedFluidTypographyValue( {
38
+ * fontSize: '30px',
39
+ * } );
40
+ * ```
41
+ *
42
+ * @param {Object} args
43
+ * @param {?string} args.minimumViewPortWidth Minimum viewport size from which type will have fluidity. Optional if fontSize is specified.
44
+ * @param {?string} args.maximumViewPortWidth Maximum size up to which type will have fluidity. Optional if fontSize is specified.
45
+ * @param {string|number} [args.fontSize] Size to derive maximumFontSize and minimumFontSize from, if necessary. Optional if minimumFontSize and maximumFontSize are specified.
46
+ * @param {?string} args.maximumFontSize Maximum font size for any clamp() calculation. Optional.
47
+ * @param {?string} args.minimumFontSize Minimum font size for any clamp() calculation. Optional.
48
+ * @param {?number} args.scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.
49
+ * @param {?number} args.minimumFontSizeFactor How much to scale defaultFontSize by to derive minimumFontSize. Optional.
50
+ * @param {?number} args.maximumFontSizeFactor How much to scale defaultFontSize by to derive maximumFontSize. Optional.
51
+ *
52
+ * @return {string|null} A font-size value using clamp().
53
+ */
54
+
55
+ function getComputedFluidTypographyValue(_ref) {
56
+ let {
57
+ minimumFontSize,
58
+ maximumFontSize,
59
+ fontSize,
60
+ minimumViewPortWidth = DEFAULT_MINIMUM_VIEWPORT_WIDTH,
61
+ maximumViewPortWidth = DEFAULT_MAXIMUM_VIEWPORT_WIDTH,
62
+ scaleFactor = DEFAULT_SCALE_FACTOR,
63
+ minimumFontSizeFactor = DEFAULT_MINIMUM_FONT_SIZE_FACTOR,
64
+ maximumFontSizeFactor = DEFAULT_MAXIMUM_FONT_SIZE_FACTOR
65
+ } = _ref;
66
+
67
+ // Calculate missing minimumFontSize and maximumFontSize from
68
+ // defaultFontSize if provided.
69
+ if (fontSize && (!minimumFontSize || !maximumFontSize)) {
70
+ // Parse default font size.
71
+ const fontSizeParsed = getTypographyValueAndUnit(fontSize); // Protect against invalid units.
72
+
73
+ if (!(fontSizeParsed !== null && fontSizeParsed !== void 0 && fontSizeParsed.unit)) {
74
+ return null;
75
+ } // If no minimumFontSize is provided, derive using min scale factor.
76
+
77
+
78
+ if (!minimumFontSize) {
79
+ minimumFontSize = fontSizeParsed.value * minimumFontSizeFactor + fontSizeParsed.unit;
80
+ } // If no maximumFontSize is provided, derive using max scale factor.
81
+
82
+
83
+ if (!maximumFontSize) {
84
+ maximumFontSize = fontSizeParsed.value * maximumFontSizeFactor + fontSizeParsed.unit;
85
+ }
86
+ } // Return early if one of the provided inputs is not provided.
87
+
88
+
89
+ if (!minimumFontSize || !maximumFontSize) {
90
+ return null;
91
+ } // Grab the minimum font size and normalize it in order to use the value for calculations.
92
+
93
+
94
+ const minimumFontSizeParsed = getTypographyValueAndUnit(minimumFontSize); // We get a 'preferred' unit to keep units consistent when calculating,
95
+ // otherwise the result will not be accurate.
96
+
97
+ const fontSizeUnit = (minimumFontSizeParsed === null || minimumFontSizeParsed === void 0 ? void 0 : minimumFontSizeParsed.unit) || 'rem'; // Grab the maximum font size and normalize it in order to use the value for calculations.
98
+
99
+ const maximumFontSizeParsed = getTypographyValueAndUnit(maximumFontSize, {
100
+ coerceTo: fontSizeUnit
101
+ }); // Protect against unsupported units.
102
+
103
+ if (!minimumFontSizeParsed || !maximumFontSizeParsed) {
104
+ return null;
105
+ } // Use rem for accessible fluid target font scaling.
106
+
107
+
108
+ const minimumFontSizeRem = getTypographyValueAndUnit(minimumFontSize, {
109
+ coerceTo: 'rem'
110
+ }); // Viewport widths defined for fluid typography. Normalize units
111
+
112
+ const maximumViewPortWidthParsed = getTypographyValueAndUnit(maximumViewPortWidth, {
113
+ coerceTo: fontSizeUnit
114
+ });
115
+ const minumumViewPortWidthParsed = getTypographyValueAndUnit(minimumViewPortWidth, {
116
+ coerceTo: fontSizeUnit
117
+ }); // Protect against unsupported units.
118
+
119
+ if (!maximumViewPortWidthParsed || !minumumViewPortWidthParsed || !minimumFontSizeRem) {
120
+ return null;
121
+ } // Build CSS rule.
122
+ // Borrowed from https://websemantics.uk/tools/responsive-font-calculator/.
123
+
124
+
125
+ const minViewPortWidthOffsetValue = roundToPrecision(minumumViewPortWidthParsed.value / 100, 3);
126
+ const viewPortWidthOffset = minViewPortWidthOffsetValue + fontSizeUnit;
127
+ let linearFactor = 100 * ((maximumFontSizeParsed.value - minimumFontSizeParsed.value) / (maximumViewPortWidthParsed.value - minumumViewPortWidthParsed.value));
128
+ linearFactor = roundToPrecision(linearFactor, 3) || 1;
129
+ const linearFactorScaled = linearFactor * scaleFactor;
130
+ const fluidTargetFontSize = `${minimumFontSizeRem.value}${minimumFontSizeRem.unit} + ((1vw - ${viewPortWidthOffset}) * ${linearFactorScaled})`;
131
+ return `clamp(${minimumFontSize}, ${fluidTargetFontSize}, ${maximumFontSize})`;
132
+ }
133
+ /**
134
+ * Internal method that checks a string for a unit and value and returns an array consisting of `'value'` and `'unit'`, e.g., [ '42', 'rem' ].
135
+ * A raw font size of `value + unit` is expected. If the value is an integer, it will convert to `value + 'px'`.
136
+ *
137
+ * @param {string|number} rawValue Raw size value from theme.json.
138
+ * @param {Object|undefined} options Calculation options.
139
+ *
140
+ * @return {{ unit: string, value: number }|null} An object consisting of `'value'` and `'unit'` properties.
141
+ */
142
+
143
+
144
+ function getTypographyValueAndUnit(rawValue) {
145
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
146
+
147
+ if (typeof rawValue !== 'string' && typeof rawValue !== 'number') {
148
+ return null;
149
+ } // Converts numeric values to pixel values by default.
150
+
151
+
152
+ if (isFinite(rawValue)) {
153
+ rawValue = `${rawValue}px`;
154
+ }
155
+
156
+ const {
157
+ coerceTo,
158
+ rootSizeValue,
159
+ acceptableUnits
160
+ } = {
161
+ coerceTo: '',
162
+ // Default browser font size. Later we could inject some JS to compute this `getComputedStyle( document.querySelector( "html" ) ).fontSize`.
163
+ rootSizeValue: 16,
164
+ acceptableUnits: ['rem', 'px', 'em'],
165
+ ...options
166
+ };
167
+ const acceptableUnitsGroup = acceptableUnits === null || acceptableUnits === void 0 ? void 0 : acceptableUnits.join('|');
168
+ const regexUnits = new RegExp(`^(\\d*\\.?\\d+)(${acceptableUnitsGroup}){1,1}$`);
169
+ const matches = rawValue.match(regexUnits); // We need a number value and a unit.
170
+
171
+ if (!matches || matches.length < 3) {
172
+ return null;
173
+ }
174
+
175
+ let [, value, unit] = matches;
176
+ let returnValue = parseFloat(value);
177
+
178
+ if ('px' === coerceTo && ('em' === unit || 'rem' === unit)) {
179
+ returnValue = returnValue * rootSizeValue;
180
+ unit = coerceTo;
181
+ }
182
+
183
+ if ('px' === unit && ('em' === coerceTo || 'rem' === coerceTo)) {
184
+ returnValue = returnValue / rootSizeValue;
185
+ unit = coerceTo;
186
+ }
187
+
188
+ return {
189
+ value: returnValue,
190
+ unit
191
+ };
192
+ }
193
+ /**
194
+ * Returns a value rounded to defined precision.
195
+ * Returns `undefined` if the value is not a valid finite number.
196
+ *
197
+ * @param {number} value Raw value.
198
+ * @param {number} digits The number of digits to appear after the decimal point
199
+ *
200
+ * @return {number|undefined} Value rounded to standard precision.
201
+ */
202
+
203
+
204
+ function roundToPrecision(value) {
205
+ let digits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
206
+ return Number.isFinite(value) ? parseFloat(value.toFixed(digits)) : undefined;
207
+ }
208
+ //# sourceMappingURL=fluid-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/font-sizes/fluid-utils.js"],"names":["DEFAULT_MAXIMUM_VIEWPORT_WIDTH","DEFAULT_MINIMUM_VIEWPORT_WIDTH","DEFAULT_SCALE_FACTOR","DEFAULT_MINIMUM_FONT_SIZE_FACTOR","DEFAULT_MAXIMUM_FONT_SIZE_FACTOR","getComputedFluidTypographyValue","minimumFontSize","maximumFontSize","fontSize","minimumViewPortWidth","maximumViewPortWidth","scaleFactor","minimumFontSizeFactor","maximumFontSizeFactor","fontSizeParsed","getTypographyValueAndUnit","unit","value","minimumFontSizeParsed","fontSizeUnit","maximumFontSizeParsed","coerceTo","minimumFontSizeRem","maximumViewPortWidthParsed","minumumViewPortWidthParsed","minViewPortWidthOffsetValue","roundToPrecision","viewPortWidthOffset","linearFactor","linearFactorScaled","fluidTargetFontSize","rawValue","options","isFinite","rootSizeValue","acceptableUnits","acceptableUnitsGroup","join","regexUnits","RegExp","matches","match","length","returnValue","parseFloat","digits","Number","toFixed","undefined"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA;AACA,MAAMA,8BAA8B,GAAG,QAAvC;AACA,MAAMC,8BAA8B,GAAG,OAAvC;AACA,MAAMC,oBAAoB,GAAG,CAA7B;AACA,MAAMC,gCAAgC,GAAG,IAAzC;AACA,MAAMC,gCAAgC,GAAG,GAAzC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,+BAAT,OASH;AAAA,MAT6C;AAChDC,IAAAA,eADgD;AAEhDC,IAAAA,eAFgD;AAGhDC,IAAAA,QAHgD;AAIhDC,IAAAA,oBAAoB,GAAGR,8BAJyB;AAKhDS,IAAAA,oBAAoB,GAAGV,8BALyB;AAMhDW,IAAAA,WAAW,GAAGT,oBANkC;AAOhDU,IAAAA,qBAAqB,GAAGT,gCAPwB;AAQhDU,IAAAA,qBAAqB,GAAGT;AARwB,GAS7C;;AACH;AACA;AACA,MAAKI,QAAQ,KAAM,CA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AA+C;AAAA,MAAb4B,MAAa,uEAAJ,CAAI;AACrD,SAAOC,MAAM,CAACb,QAAP,CAAiBhB,KAAjB,IACJ2B,UAAU,CAAE3B,KAAK,CAAC8B,OAAN,CAAeF,MAAf,CAAF,CADN,GAEJG,SAFH;AAGA","sourcesContent":["/**\n * The fluid utilities must match the backend equivalent.\n * See: gutenberg_get_typography_font_size_value() in lib/block-supports/typography.php\n * ---------------------------------------------------------------\n */\n\n// Defaults.\nconst DEFAULT_MAXIMUM_VIEWPORT_WIDTH = '1600px';\nconst DEFAULT_MINIMUM_VIEWPORT_WIDTH = '768px';\nconst DEFAULT_SCALE_FACTOR = 1;\nconst DEFAULT_MINIMUM_FONT_SIZE_FACTOR = 0.75;\nconst DEFAULT_MAXIMUM_FONT_SIZE_FACTOR = 1.5;\n\n/**\n * Computes a fluid font-size value that uses clamp(). A minimum and maxinmum\n * font size OR a single font size can be specified.\n *\n * If a single font size is specified, it is scaled up and down by\n * minimumFontSizeFactor and maximumFontSizeFactor to arrive at the minimum and\n * maximum sizes.\n *\n * @example\n * ```js\n * // Calculate fluid font-size value from a minimum and maximum value.\n * const fontSize = getComputedFluidTypographyValue( {\n * minimumFontSize: '20px',\n * maximumFontSize: '45px'\n * } );\n * // Calculate fluid font-size value from a single font size.\n * const fontSize = getComputedFluidTypographyValue( {\n * fontSize: '30px',\n * } );\n * ```\n *\n * @param {Object} args\n * @param {?string} args.minimumViewPortWidth Minimum viewport size from which type will have fluidity. Optional if fontSize is specified.\n * @param {?string} args.maximumViewPortWidth Maximum size up to which type will have fluidity. Optional if fontSize is specified.\n * @param {string|number} [args.fontSize] Size to derive maximumFontSize and minimumFontSize from, if necessary. Optional if minimumFontSize and maximumFontSize are specified.\n * @param {?string} args.maximumFontSize Maximum font size for any clamp() calculation. Optional.\n * @param {?string} args.minimumFontSize Minimum font size for any clamp() calculation. Optional.\n * @param {?number} args.scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.\n * @param {?number} args.minimumFontSizeFactor How much to scale defaultFontSize by to derive minimumFontSize. Optional.\n * @param {?number} args.maximumFontSizeFactor How much to scale defaultFontSize by to derive maximumFontSize. Optional.\n *\n * @return {string|null} A font-size value using clamp().\n */\nexport function getComputedFluidTypographyValue( {\n\tminimumFontSize,\n\tmaximumFontSize,\n\tfontSize,\n\tminimumViewPortWidth = DEFAULT_MINIMUM_VIEWPORT_WIDTH,\n\tmaximumViewPortWidth = DEFAULT_MAXIMUM_VIEWPORT_WIDTH,\n\tscaleFactor = DEFAULT_SCALE_FACTOR,\n\tminimumFontSizeFactor = DEFAULT_MINIMUM_FONT_SIZE_FACTOR,\n\tmaximumFontSizeFactor = DEFAULT_MAXIMUM_FONT_SIZE_FACTOR,\n} ) {\n\t// Calculate missing minimumFontSize and maximumFontSize from\n\t// defaultFontSize if provided.\n\tif ( fontSize && ( ! minimumFontSize || ! maximumFontSize ) ) {\n\t\t// Parse default font size.\n\t\tconst fontSizeParsed = getTypographyValueAndUnit( fontSize );\n\n\t\t// Protect against invalid units.\n\t\tif ( ! fontSizeParsed?.unit ) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// If no minimumFontSize is provided, derive using min scale factor.\n\t\tif ( ! minimumFontSize ) {\n\t\t\tminimumFontSize =\n\t\t\t\tfontSizeParsed.value * minimumFontSizeFactor +\n\t\t\t\tfontSizeParsed.unit;\n\t\t}\n\n\t\t// If no maximumFontSize is provided, derive using max scale factor.\n\t\tif ( ! maximumFontSize ) {\n\t\t\tmaximumFontSize =\n\t\t\t\tfontSizeParsed.value * maximumFontSizeFactor +\n\t\t\t\tfontSizeParsed.unit;\n\t\t}\n\t}\n\n\t// Return early if one of the provided inputs is not provided.\n\tif ( ! minimumFontSize || ! maximumFontSize ) {\n\t\treturn null;\n\t}\n\n\t// Grab the minimum font size and normalize it in order to use the value for calculations.\n\tconst minimumFontSizeParsed = getTypographyValueAndUnit( minimumFontSize );\n\n\t// We get a 'preferred' unit to keep units consistent when calculating,\n\t// otherwise the result will not be accurate.\n\tconst fontSizeUnit = minimumFontSizeParsed?.unit || 'rem';\n\n\t// Grab the maximum font size and normalize it in order to use the value for calculations.\n\tconst maximumFontSizeParsed = getTypographyValueAndUnit( maximumFontSize, {\n\t\tcoerceTo: fontSizeUnit,\n\t} );\n\n\t// Protect against unsupported units.\n\tif ( ! minimumFontSizeParsed || ! maximumFontSizeParsed ) {\n\t\treturn null;\n\t}\n\n\t// Use rem for accessible fluid target font scaling.\n\tconst minimumFontSizeRem = getTypographyValueAndUnit( minimumFontSize, {\n\t\tcoerceTo: 'rem',\n\t} );\n\n\t// Viewport widths defined for fluid typography. Normalize units\n\tconst maximumViewPortWidthParsed = getTypographyValueAndUnit(\n\t\tmaximumViewPortWidth,\n\t\t{ coerceTo: fontSizeUnit }\n\t);\n\tconst minumumViewPortWidthParsed = getTypographyValueAndUnit(\n\t\tminimumViewPortWidth,\n\t\t{ coerceTo: fontSizeUnit }\n\t);\n\n\t// Protect against unsupported units.\n\tif (\n\t\t! maximumViewPortWidthParsed ||\n\t\t! minumumViewPortWidthParsed ||\n\t\t! minimumFontSizeRem\n\t) {\n\t\treturn null;\n\t}\n\n\t// Build CSS rule.\n\t// Borrowed from https://websemantics.uk/tools/responsive-font-calculator/.\n\tconst minViewPortWidthOffsetValue = roundToPrecision(\n\t\tminumumViewPortWidthParsed.value / 100,\n\t\t3\n\t);\n\n\tconst viewPortWidthOffset = minViewPortWidthOffsetValue + fontSizeUnit;\n\tlet linearFactor =\n\t\t100 *\n\t\t( ( maximumFontSizeParsed.value - minimumFontSizeParsed.value ) /\n\t\t\t( maximumViewPortWidthParsed.value -\n\t\t\t\tminumumViewPortWidthParsed.value ) );\n\tlinearFactor = roundToPrecision( linearFactor, 3 ) || 1;\n\tconst linearFactorScaled = linearFactor * scaleFactor;\n\tconst fluidTargetFontSize = `${ minimumFontSizeRem.value }${ minimumFontSizeRem.unit } + ((1vw - ${ viewPortWidthOffset }) * ${ linearFactorScaled })`;\n\n\treturn `clamp(${ minimumFontSize }, ${ fluidTargetFontSize }, ${ maximumFontSize })`;\n}\n\n/**\n * Internal method that checks a string for a unit and value and returns an array consisting of `'value'` and `'unit'`, e.g., [ '42', 'rem' ].\n * A raw font size of `value + unit` is expected. If the value is an integer, it will convert to `value + 'px'`.\n *\n * @param {string|number} rawValue Raw size value from theme.json.\n * @param {Object|undefined} options Calculation options.\n *\n * @return {{ unit: string, value: number }|null} An object consisting of `'value'` and `'unit'` properties.\n */\nexport function getTypographyValueAndUnit( rawValue, options = {} ) {\n\tif ( typeof rawValue !== 'string' && typeof rawValue !== 'number' ) {\n\t\treturn null;\n\t}\n\n\t// Converts numeric values to pixel values by default.\n\tif ( isFinite( rawValue ) ) {\n\t\trawValue = `${ rawValue }px`;\n\t}\n\n\tconst { coerceTo, rootSizeValue, acceptableUnits } = {\n\t\tcoerceTo: '',\n\t\t// Default browser font size. Later we could inject some JS to compute this `getComputedStyle( document.querySelector( \"html\" ) ).fontSize`.\n\t\trootSizeValue: 16,\n\t\tacceptableUnits: [ 'rem', 'px', 'em' ],\n\t\t...options,\n\t};\n\n\tconst acceptableUnitsGroup = acceptableUnits?.join( '|' );\n\tconst regexUnits = new RegExp(\n\t\t`^(\\\\d*\\\\.?\\\\d+)(${ acceptableUnitsGroup }){1,1}$`\n\t);\n\n\tconst matches = rawValue.match( regexUnits );\n\n\t// We need a number value and a unit.\n\tif ( ! matches || matches.length < 3 ) {\n\t\treturn null;\n\t}\n\n\tlet [ , value, unit ] = matches;\n\n\tlet returnValue = parseFloat( value );\n\n\tif ( 'px' === coerceTo && ( 'em' === unit || 'rem' === unit ) ) {\n\t\treturnValue = returnValue * rootSizeValue;\n\t\tunit = coerceTo;\n\t}\n\n\tif ( 'px' === unit && ( 'em' === coerceTo || 'rem' === coerceTo ) ) {\n\t\treturnValue = returnValue / rootSizeValue;\n\t\tunit = coerceTo;\n\t}\n\n\treturn {\n\t\tvalue: returnValue,\n\t\tunit,\n\t};\n}\n\n/**\n * Returns a value rounded to defined precision.\n * Returns `undefined` if the value is not a valid finite number.\n *\n * @param {number} value Raw value.\n * @param {number} digits The number of digits to appear after the decimal point\n *\n * @return {number|undefined} Value rounded to standard precision.\n */\nexport function roundToPrecision( value, digits = 3 ) {\n\treturn Number.isFinite( value )\n\t\t? parseFloat( value.toFixed( digits ) )\n\t\t: undefined;\n}\n"]}
@@ -11,6 +11,12 @@ Object.defineProperty(exports, "FontSizePicker", {
11
11
  return _fontSizePicker.default;
12
12
  }
13
13
  });
14
+ Object.defineProperty(exports, "getComputedFluidTypographyValue", {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _fluidUtils.getComputedFluidTypographyValue;
18
+ }
19
+ });
14
20
  Object.defineProperty(exports, "getFontSize", {
15
21
  enumerable: true,
16
22
  get: function () {
@@ -38,6 +44,8 @@ Object.defineProperty(exports, "withFontSizes", {
38
44
 
39
45
  var _utils = require("./utils");
40
46
 
47
+ var _fluidUtils = require("./fluid-utils");
48
+
41
49
  var _fontSizePicker = _interopRequireDefault(require("./font-size-picker"));
42
50
 
43
51
  var _withFontSizes = _interopRequireDefault(require("./with-font-sizes"));
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/font-sizes/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAKA;;AACA","sourcesContent":["export {\n\tgetFontSize,\n\tgetFontSizeClass,\n\tgetFontSizeObjectByValue,\n} from './utils';\nexport { default as FontSizePicker } from './font-size-picker';\nexport { default as withFontSizes } from './with-font-sizes';\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/font-sizes/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAKA;;AACA;;AACA","sourcesContent":["export {\n\tgetFontSize,\n\tgetFontSizeClass,\n\tgetFontSizeObjectByValue,\n} from './utils';\nexport { getComputedFluidTypographyValue } from './fluid-utils';\nexport { default as FontSizePicker } from './font-size-picker';\nexport { default as withFontSizes } from './with-font-sizes';\n"]}
@@ -22,6 +22,8 @@ var _tokenList = _interopRequireDefault(require("@wordpress/token-list"));
22
22
 
23
23
  var _compose = require("@wordpress/compose");
24
24
 
25
+ var _data = require("@wordpress/data");
26
+
25
27
  var _fontSizes = require("../components/font-sizes");
26
28
 
27
29
  var _typography = require("./typography");
@@ -30,6 +32,8 @@ var _utils = require("./utils");
30
32
 
31
33
  var _useSetting = _interopRequireDefault(require("../components/use-setting"));
32
34
 
35
+ var _store = require("../store");
36
+
33
37
  /**
34
38
  * WordPress dependencies
35
39
  */
@@ -278,10 +282,66 @@ function addTransforms(result, source, index, results) {
278
282
  };
279
283
  return (0, _utils.transformStyles)(activeSupports, MIGRATION_PATHS, result, source, index, results);
280
284
  }
285
+ /**
286
+ * Allow custom font sizes to appear fluid when fluid typography is enabled at
287
+ * the theme level.
288
+ *
289
+ * Adds a custom getEditWrapperProps() callback to all block types that support
290
+ * font sizes. Then, if fluid typography is enabled, this callback will swap any
291
+ * custom font size in style.fontSize with a fluid font size (i.e. one that uses
292
+ * clamp()).
293
+ *
294
+ * It's important that this hook runs after 'core/style/addEditProps' sets
295
+ * style.fontSize as otherwise fontSize will be overwritten.
296
+ *
297
+ * @param {Object} blockType Block settings object.
298
+ */
299
+
300
+
301
+ function addEditPropsForFluidCustomFontSizes(blockType) {
302
+ if (!(0, _blocks.hasBlockSupport)(blockType, FONT_SIZE_SUPPORT_KEY) || (0, _utils.shouldSkipSerialization)(blockType, _typography.TYPOGRAPHY_SUPPORT_KEY, 'fontSize')) {
303
+ return blockType;
304
+ }
305
+
306
+ const existingGetEditWrapperProps = blockType.getEditWrapperProps;
307
+
308
+ blockType.getEditWrapperProps = attributes => {
309
+ var _wrapperProps$style, _select$getSettings$_, _select$getSettings$_2;
310
+
311
+ const wrapperProps = existingGetEditWrapperProps ? existingGetEditWrapperProps(attributes) : {};
312
+ const fontSize = wrapperProps === null || wrapperProps === void 0 ? void 0 : (_wrapperProps$style = wrapperProps.style) === null || _wrapperProps$style === void 0 ? void 0 : _wrapperProps$style.fontSize; // TODO: This sucks! We should be using useSetting( 'typography.fluid' )
313
+ // or even useSelect( blockEditorStore ). We can't do either here
314
+ // because getEditWrapperProps is a plain JavaScript function called by
315
+ // BlockListBlock and not a React component rendered within
316
+ // BlockListContext.Provider. If we set fontSize using editor.
317
+ // BlockListBlock instead of using getEditWrapperProps then the value is
318
+ // clobbered when the core/style/addEditProps filter runs.
319
+
320
+ const isFluidTypographyEnabled = !!((_select$getSettings$_ = (0, _data.select)(_store.store).getSettings().__experimentalFeatures) !== null && _select$getSettings$_ !== void 0 && (_select$getSettings$_2 = _select$getSettings$_.typography) !== null && _select$getSettings$_2 !== void 0 && _select$getSettings$_2.fluid);
321
+ const newFontSize = fontSize && isFluidTypographyEnabled ? (0, _fontSizes.getComputedFluidTypographyValue)({
322
+ fontSize
323
+ }) : null;
324
+
325
+ if (newFontSize === null) {
326
+ return wrapperProps;
327
+ }
328
+
329
+ return { ...wrapperProps,
330
+ style: { ...(wrapperProps === null || wrapperProps === void 0 ? void 0 : wrapperProps.style),
331
+ fontSize: newFontSize
332
+ }
333
+ };
334
+ };
335
+
336
+ return blockType;
337
+ }
281
338
 
282
339
  (0, _hooks.addFilter)('blocks.registerBlockType', 'core/font/addAttribute', addAttributes);
283
340
  (0, _hooks.addFilter)('blocks.getSaveContent.extraProps', 'core/font/addSaveProps', addSaveProps);
284
341
  (0, _hooks.addFilter)('blocks.registerBlockType', 'core/font/addEditProps', addEditProps);
285
342
  (0, _hooks.addFilter)('editor.BlockListBlock', 'core/font-size/with-font-size-inline-styles', withFontSizeInlineStyles);
286
343
  (0, _hooks.addFilter)('blocks.switchToBlockType.transformedBlock', 'core/font-size/addTransforms', addTransforms);
344
+ (0, _hooks.addFilter)('blocks.registerBlockType', 'core/font-size/addEditPropsForFluidCustomFontSizes', addEditPropsForFluidCustomFontSizes, // Run after 'core/style/addEditProps' so that the style object has already
345
+ // been translated into inline CSS.
346
+ 11);
287
347
  //# sourceMappingURL=font-size.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/hooks/font-size.js"],"names":["FONT_SIZE_SUPPORT_KEY","addAttributes","settings","attributes","fontSize","Object","assign","type","addSaveProps","props","blockType","TYPOGRAPHY_SUPPORT_KEY","classes","TokenList","className","add","newClassName","value","undefined","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","FontSizeEdit","style","setAttributes","fontSizes","onChange","fontSizeSlug","slug","typography","fontSizeObject","fontSizeValue","size","hasFontSizeValue","resetFontSize","useIsFontSizeDisabled","name","blockName","hasFontSizes","length","withFontSizeInlineStyles","BlockListBlock","wrapperProps","newProps","MIGRATION_PATHS","addTransforms","result","source","index","results","destinationBlockType","activeSupports"],"mappings":";;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAMA;;AACA;;AAKA;;AAvBA;AACA;AACA;;AAMA;AACA;AACA;AAeO,MAAMA,qBAAqB,GAAG,qBAA9B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,SAASC,aAAT,CAAwBC,QAAxB,EAAmC;AAClC,MAAK,CAAE,6BAAiBA,QAAjB,EAA2BF,qBAA3B,CAAP,EAA4D;AAC3D,WAAOE,QAAP;AACA,GAHiC,CAKlC;;;AACA,MAAK,CAAEA,QAAQ,CAACC,UAAT,CAAoBC,QAA3B,EAAsC;AACrCC,IAAAA,MAAM,CAACC,MAAP,CAAeJ,QAAQ,CAACC,UAAxB,EAAoC;AACnCC,MAAAA,QAAQ,EAAE;AACTG,QAAAA,IAAI,EAAE;AADG;AADyB,KAApC;AAKA;;AAED,SAAOL,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASM,YAAT,CAAuBC,KAAvB,EAA8BC,SAA9B,EAAyCP,UAAzC,EAAsD;AACrD,MAAK,CAAE,6BAAiBO,SAAjB,EAA4BV,qBAA5B,CAAP,EAA6D;AAC5D,WAAOS,K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W,0BAAX,EAAuC,wBAAvC,EAAiEW,YAAjE;AAEA,sBACC,uBADD,EAEC,6CAFD,EAGCqB,wBAHD;AAMA,sBACC,2CADD,EAEC,8BAFD,EAGCK,aAHD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport TokenList from '@wordpress/token-list';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetFontSize,\n\tgetFontSizeClass,\n\tgetFontSizeObjectByValue,\n\tFontSizePicker,\n} from '../components/font-sizes';\nimport { TYPOGRAPHY_SUPPORT_KEY } from './typography';\nimport {\n\tcleanEmptyObject,\n\ttransformStyles,\n\tshouldSkipSerialization,\n} from './utils';\nimport useSetting from '../components/use-setting';\n\nexport const FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';\n\n/**\n * Filters registered block settings, extending attributes to include\n * `fontSize` and `fontWeight` attributes.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBlockSupport( settings, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify a default value if needed.\n\tif ( ! settings.attributes.fontSize ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tfontSize: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * Override props assigned to save component to inject font size.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif ( ! hasBlockSupport( blockType, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn props;\n\t}\n\n\tif (\n\t\tshouldSkipSerialization( blockType, TYPOGRAPHY_SUPPORT_KEY, 'fontSize' )\n\t) {\n\t\treturn props;\n\t}\n\n\t// Use TokenList to dedupe classes.\n\tconst classes = new TokenList( props.className );\n\tclasses.add( getFontSizeClass( attributes.fontSize ) );\n\tconst newClassName = classes.value;\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Filters registered block settings to expand the block edit wrapper\n * by applying the desired styles and classnames.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addEditProps( settings ) {\n\tif ( ! hasBlockSupport( settings, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\t\treturn addSaveProps( props, settings, attributes );\n\t};\n\n\treturn settings;\n}\n\n/**\n * Inspector control panel containing the font size related configuration\n *\n * @param {Object} props\n *\n * @return {WPElement} Font size edit element.\n */\nexport function FontSizeEdit( props ) {\n\tconst {\n\t\tattributes: { fontSize, style },\n\t\tsetAttributes,\n\t} = props;\n\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\n\tconst onChange = ( value ) => {\n\t\tconst fontSizeSlug = getFontSizeObjectByValue( fontSizes, value ).slug;\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( {\n\t\t\t\t...style,\n\t\t\t\ttypography: {\n\t\t\t\t\t...style?.typography,\n\t\t\t\t\tfontSize: fontSizeSlug ? undefined : value,\n\t\t\t\t},\n\t\t\t} ),\n\t\t\tfontSize: fontSizeSlug,\n\t\t} );\n\t};\n\n\tconst fontSizeObject = getFontSize(\n\t\tfontSizes,\n\t\tfontSize,\n\t\tstyle?.typography?.fontSize\n\t);\n\n\tconst fontSizeValue =\n\t\tfontSizeObject?.size || style?.typography?.fontSize || fontSize;\n\n\treturn (\n\t\t<FontSizePicker\n\t\t\tonChange={ onChange }\n\t\t\tvalue={ fontSizeValue }\n\t\t\twithReset={ false }\n\t\t\tsize=\"__unstable-large\"\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n\n/**\n * Checks if there is a current value set for the font size block support.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a font size value set.\n */\nexport function hasFontSizeValue( props ) {\n\tconst { fontSize, style } = props.attributes;\n\treturn !! fontSize || !! style?.typography?.fontSize;\n}\n\n/**\n * Resets the font size block support attribute. This can be used when\n * disabling the font size support controls for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetFontSize( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tfontSize: undefined,\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\ttypography: {\n\t\t\t\t...style?.typography,\n\t\t\t\tfontSize: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if font-size settings have been disabled.\n *\n * @param {string} name The name of the block.\n * @return {boolean} Whether setting is disabled.\n */\nexport function useIsFontSizeDisabled( { name: blockName } = {} ) {\n\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\tconst hasFontSizes = !! fontSizes?.length;\n\n\treturn (\n\t\t! hasBlockSupport( blockName, FONT_SIZE_SUPPORT_KEY ) || ! hasFontSizes\n\t);\n}\n\n/**\n * Add inline styles for font sizes.\n * Ideally, this is not needed and themes load the font-size classes on the\n * editor.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nconst withFontSizeInlineStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\t\tconst {\n\t\t\tname: blockName,\n\t\t\tattributes: { fontSize, style },\n\t\t\twrapperProps,\n\t\t} = props;\n\n\t\t// Only add inline styles if the block supports font sizes,\n\t\t// doesn't skip serialization of font sizes,\n\t\t// doesn't already have an inline font size,\n\t\t// and does have a class to extract the font size from.\n\t\tif (\n\t\t\t! hasBlockSupport( blockName, FONT_SIZE_SUPPORT_KEY ) ||\n\t\t\tshouldSkipSerialization(\n\t\t\t\tblockName,\n\t\t\t\tTYPOGRAPHY_SUPPORT_KEY,\n\t\t\t\t'fontSize'\n\t\t\t) ||\n\t\t\t! fontSize ||\n\t\t\tstyle?.typography?.fontSize\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst fontSizeValue = getFontSize(\n\t\t\tfontSizes,\n\t\t\tfontSize,\n\t\t\tstyle?.typography?.fontSize\n\t\t).size;\n\n\t\tconst newProps = {\n\t\t\t...props,\n\t\t\twrapperProps: {\n\t\t\t\t...wrapperProps,\n\t\t\t\tstyle: {\n\t\t\t\t\tfontSize: fontSizeValue,\n\t\t\t\t\t...wrapperProps?.style,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...newProps } />;\n\t},\n\t'withFontSizeInlineStyles'\n);\n\nconst MIGRATION_PATHS = {\n\tfontSize: [ [ 'fontSize' ], [ 'style', 'typography', 'fontSize' ] ],\n};\n\nexport function addTransforms( result, source, index, results ) {\n\tconst destinationBlockType = result.name;\n\tconst activeSupports = {\n\t\tfontSize: hasBlockSupport(\n\t\t\tdestinationBlockType,\n\t\t\tFONT_SIZE_SUPPORT_KEY\n\t\t),\n\t};\n\treturn transformStyles(\n\t\tactiveSupports,\n\t\tMIGRATION_PATHS,\n\t\tresult,\n\t\tsource,\n\t\tindex,\n\t\tresults\n\t);\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/font/addAttribute',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/font/addSaveProps',\n\taddSaveProps\n);\n\naddFilter( 'blocks.registerBlockType', 'core/font/addEditProps', addEditProps );\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/font-size/with-font-size-inline-styles',\n\twithFontSizeInlineStyles\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/font-size/addTransforms',\n\taddTransforms\n);\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/hooks/font-size.js"],"names":["FONT_SIZE_SUPPORT_KEY","addAttributes","settings","attributes","fontSize","Object","assign","type","addSaveProps","props","blockType","TYPOGRAPHY_SUPPORT_KEY","classes","TokenList","className","add","newClassName","value","undefined","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","FontSizeEdit","style","setAttributes","fontSizes","onChange","fontSizeSlug","slug","typography","fontSizeObject","fontSizeValue","size","hasFontSizeValue","resetFontSize","useIsFontSizeDisabled","name","blockName","hasFontSizes","length","withFontSizeInlineStyles","BlockListBlock","wrapperProps","newProps","MIGRATION_PATHS","addTransforms","result","source","index","results","destinationBlockType","activeSupports","addEditPropsForFluidCustomFontSizes","isFluidTypographyEnabled","blockEditorStore","getSettings","__experimentalFeatures","fluid","newFontSize"],"mappings":";;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAOA;;AACA;;AAKA;;AACA;;AA1BA;AACA;AACA;;AAOA;AACA;AACA;AAiBO,MAAMA,qBAAqB,GAAG,qBAA9B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,SAASC,aAAT,CAAwBC,QAAxB,EAAmC;AAClC,MAAK,CAAE,6BAAiBA,QAAjB,EAA2BF,qBAA3B,CAAP,EAA4D;AAC3D,WAAOE,QAAP;AACA,GAHiC,CAKlC;;;AACA,MAAK,CAAEA,QAAQ,CAACC,UAAT,CAAoBC,QAA3B,EAAsC;AACrCC,IAAAA,MAAM,CAACC,MAAP,CAAeJ,QAAQ,CAACC,UAAxB,EAAoC;AACnCC,MAAAA,QAAQ,EAAE;AACTG,QAAAA,IAAI,EAAE;AADG;AADyB,KAApC;AAKA;;AAED,SAAOL,QAAP;AACA;AAED;AACA;A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D,EAEC,wBAFD,EAGCT,aAHD;AAMA,sBACC,kCADD,EAEC,wBAFD,EAGCO,YAHD;AAMA,sBAAW,0BAAX,EAAuC,wBAAvC,EAAiEW,YAAjE;AAEA,sBACC,uBADD,EAEC,6CAFD,EAGCqB,wBAHD;AAMA,sBACC,2CADD,EAEC,8BAFD,EAGCK,aAHD;AAMA,sBACC,0BADD,EAEC,oDAFD,EAGCO,mCAHD,EAIC;AACA;AACA,EAND","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport TokenList from '@wordpress/token-list';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { select } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetFontSize,\n\tgetFontSizeClass,\n\tgetFontSizeObjectByValue,\n\tFontSizePicker,\n\tgetComputedFluidTypographyValue,\n} from '../components/font-sizes';\nimport { TYPOGRAPHY_SUPPORT_KEY } from './typography';\nimport {\n\tcleanEmptyObject,\n\ttransformStyles,\n\tshouldSkipSerialization,\n} from './utils';\nimport useSetting from '../components/use-setting';\nimport { store as blockEditorStore } from '../store';\n\nexport const FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';\n\n/**\n * Filters registered block settings, extending attributes to include\n * `fontSize` and `fontWeight` attributes.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBlockSupport( settings, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify a default value if needed.\n\tif ( ! settings.attributes.fontSize ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tfontSize: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * Override props assigned to save component to inject font size.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif ( ! hasBlockSupport( blockType, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn props;\n\t}\n\n\tif (\n\t\tshouldSkipSerialization( blockType, TYPOGRAPHY_SUPPORT_KEY, 'fontSize' )\n\t) {\n\t\treturn props;\n\t}\n\n\t// Use TokenList to dedupe classes.\n\tconst classes = new TokenList( props.className );\n\tclasses.add( getFontSizeClass( attributes.fontSize ) );\n\tconst newClassName = classes.value;\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Filters registered block settings to expand the block edit wrapper\n * by applying the desired styles and classnames.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addEditProps( settings ) {\n\tif ( ! hasBlockSupport( settings, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\t\treturn addSaveProps( props, settings, attributes );\n\t};\n\n\treturn settings;\n}\n\n/**\n * Inspector control panel containing the font size related configuration\n *\n * @param {Object} props\n *\n * @return {WPElement} Font size edit element.\n */\nexport function FontSizeEdit( props ) {\n\tconst {\n\t\tattributes: { fontSize, style },\n\t\tsetAttributes,\n\t} = props;\n\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\n\tconst onChange = ( value ) => {\n\t\tconst fontSizeSlug = getFontSizeObjectByValue( fontSizes, value ).slug;\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( {\n\t\t\t\t...style,\n\t\t\t\ttypography: {\n\t\t\t\t\t...style?.typography,\n\t\t\t\t\tfontSize: fontSizeSlug ? undefined : value,\n\t\t\t\t},\n\t\t\t} ),\n\t\t\tfontSize: fontSizeSlug,\n\t\t} );\n\t};\n\n\tconst fontSizeObject = getFontSize(\n\t\tfontSizes,\n\t\tfontSize,\n\t\tstyle?.typography?.fontSize\n\t);\n\n\tconst fontSizeValue =\n\t\tfontSizeObject?.size || style?.typography?.fontSize || fontSize;\n\n\treturn (\n\t\t<FontSizePicker\n\t\t\tonChange={ onChange }\n\t\t\tvalue={ fontSizeValue }\n\t\t\twithReset={ false }\n\t\t\tsize=\"__unstable-large\"\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n\n/**\n * Checks if there is a current value set for the font size block support.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a font size value set.\n */\nexport function hasFontSizeValue( props ) {\n\tconst { fontSize, style } = props.attributes;\n\treturn !! fontSize || !! style?.typography?.fontSize;\n}\n\n/**\n * Resets the font size block support attribute. This can be used when\n * disabling the font size support controls for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetFontSize( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tfontSize: undefined,\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\ttypography: {\n\t\t\t\t...style?.typography,\n\t\t\t\tfontSize: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if font-size settings have been disabled.\n *\n * @param {string} name The name of the block.\n * @return {boolean} Whether setting is disabled.\n */\nexport function useIsFontSizeDisabled( { name: blockName } = {} ) {\n\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\tconst hasFontSizes = !! fontSizes?.length;\n\n\treturn (\n\t\t! hasBlockSupport( blockName, FONT_SIZE_SUPPORT_KEY ) || ! hasFontSizes\n\t);\n}\n\n/**\n * Add inline styles for font sizes.\n * Ideally, this is not needed and themes load the font-size classes on the\n * editor.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nconst withFontSizeInlineStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\t\tconst {\n\t\t\tname: blockName,\n\t\t\tattributes: { fontSize, style },\n\t\t\twrapperProps,\n\t\t} = props;\n\n\t\t// Only add inline styles if the block supports font sizes,\n\t\t// doesn't skip serialization of font sizes,\n\t\t// doesn't already have an inline font size,\n\t\t// and does have a class to extract the font size from.\n\t\tif (\n\t\t\t! hasBlockSupport( blockName, FONT_SIZE_SUPPORT_KEY ) ||\n\t\t\tshouldSkipSerialization(\n\t\t\t\tblockName,\n\t\t\t\tTYPOGRAPHY_SUPPORT_KEY,\n\t\t\t\t'fontSize'\n\t\t\t) ||\n\t\t\t! fontSize ||\n\t\t\tstyle?.typography?.fontSize\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst fontSizeValue = getFontSize(\n\t\t\tfontSizes,\n\t\t\tfontSize,\n\t\t\tstyle?.typography?.fontSize\n\t\t).size;\n\n\t\tconst newProps = {\n\t\t\t...props,\n\t\t\twrapperProps: {\n\t\t\t\t...wrapperProps,\n\t\t\t\tstyle: {\n\t\t\t\t\tfontSize: fontSizeValue,\n\t\t\t\t\t...wrapperProps?.style,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...newProps } />;\n\t},\n\t'withFontSizeInlineStyles'\n);\n\nconst MIGRATION_PATHS = {\n\tfontSize: [ [ 'fontSize' ], [ 'style', 'typography', 'fontSize' ] ],\n};\n\nexport function addTransforms( result, source, index, results ) {\n\tconst destinationBlockType = result.name;\n\tconst activeSupports = {\n\t\tfontSize: hasBlockSupport(\n\t\t\tdestinationBlockType,\n\t\t\tFONT_SIZE_SUPPORT_KEY\n\t\t),\n\t};\n\treturn transformStyles(\n\t\tactiveSupports,\n\t\tMIGRATION_PATHS,\n\t\tresult,\n\t\tsource,\n\t\tindex,\n\t\tresults\n\t);\n}\n\n/**\n * Allow custom font sizes to appear fluid when fluid typography is enabled at\n * the theme level.\n *\n * Adds a custom getEditWrapperProps() callback to all block types that support\n * font sizes. Then, if fluid typography is enabled, this callback will swap any\n * custom font size in style.fontSize with a fluid font size (i.e. one that uses\n * clamp()).\n *\n * It's important that this hook runs after 'core/style/addEditProps' sets\n * style.fontSize as otherwise fontSize will be overwritten.\n *\n * @param {Object} blockType Block settings object.\n */\nfunction addEditPropsForFluidCustomFontSizes( blockType ) {\n\tif (\n\t\t! hasBlockSupport( blockType, FONT_SIZE_SUPPORT_KEY ) ||\n\t\tshouldSkipSerialization( blockType, TYPOGRAPHY_SUPPORT_KEY, 'fontSize' )\n\t) {\n\t\treturn blockType;\n\t}\n\n\tconst existingGetEditWrapperProps = blockType.getEditWrapperProps;\n\n\tblockType.getEditWrapperProps = ( attributes ) => {\n\t\tconst wrapperProps = existingGetEditWrapperProps\n\t\t\t? existingGetEditWrapperProps( attributes )\n\t\t\t: {};\n\n\t\tconst fontSize = wrapperProps?.style?.fontSize;\n\n\t\t// TODO: This sucks! We should be using useSetting( 'typography.fluid' )\n\t\t// or even useSelect( blockEditorStore ). We can't do either here\n\t\t// because getEditWrapperProps is a plain JavaScript function called by\n\t\t// BlockListBlock and not a React component rendered within\n\t\t// BlockListContext.Provider. If we set fontSize using editor.\n\t\t// BlockListBlock instead of using getEditWrapperProps then the value is\n\t\t// clobbered when the core/style/addEditProps filter runs.\n\t\tconst isFluidTypographyEnabled =\n\t\t\t!! select( blockEditorStore ).getSettings().__experimentalFeatures\n\t\t\t\t?.typography?.fluid;\n\n\t\tconst newFontSize =\n\t\t\tfontSize && isFluidTypographyEnabled\n\t\t\t\t? getComputedFluidTypographyValue( { fontSize } )\n\t\t\t\t: null;\n\n\t\tif ( newFontSize === null ) {\n\t\t\treturn wrapperProps;\n\t\t}\n\n\t\treturn {\n\t\t\t...wrapperProps,\n\t\t\tstyle: {\n\t\t\t\t...wrapperProps?.style,\n\t\t\t\tfontSize: newFontSize,\n\t\t\t},\n\t\t};\n\t};\n\n\treturn blockType;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/font/addAttribute',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/font/addSaveProps',\n\taddSaveProps\n);\n\naddFilter( 'blocks.registerBlockType', 'core/font/addEditProps', addEditProps );\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/font-size/with-font-size-inline-styles',\n\twithFontSizeInlineStyles\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/font-size/addTransforms',\n\taddTransforms\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/font-size/addEditPropsForFluidCustomFontSizes',\n\taddEditPropsForFluidCustomFontSizes,\n\t// Run after 'core/style/addEditProps' so that the style object has already\n\t// been translated into inline CSS.\n\t11\n);\n"]}
@@ -15,6 +15,8 @@ var _style = require("./style");
15
15
 
16
16
  var _fontSizes = require("../components/font-sizes");
17
17
 
18
+ var _fluidUtils = require("../components/font-sizes/fluid-utils");
19
+
18
20
  /**
19
21
  * External dependencies
20
22
  */
@@ -30,14 +32,26 @@ var _fontSizes = require("../components/font-sizes");
30
32
  * Provides the CSS class names and inline styles for a block's typography support
31
33
  * attributes.
32
34
  *
33
- * @param {Object} attributes Block attributes.
35
+ * @param {Object} attributes Block attributes.
36
+ * @param {boolean} isFluidFontSizeActive Whether the function should try to convert font sizes to fluid values.
34
37
  *
35
38
  * @return {Object} Typography block support derived CSS classes & styles.
36
39
  */
37
- function getTypographyClassesAndStyles(attributes) {
40
+ function getTypographyClassesAndStyles(attributes, isFluidFontSizeActive) {
38
41
  var _attributes$style;
39
42
 
40
- const typographyStyles = (attributes === null || attributes === void 0 ? void 0 : (_attributes$style = attributes.style) === null || _attributes$style === void 0 ? void 0 : _attributes$style.typography) || {};
43
+ let typographyStyles = (attributes === null || attributes === void 0 ? void 0 : (_attributes$style = attributes.style) === null || _attributes$style === void 0 ? void 0 : _attributes$style.typography) || {};
44
+
45
+ if (isFluidFontSizeActive) {
46
+ var _attributes$style2, _attributes$style2$ty;
47
+
48
+ typographyStyles = { ...typographyStyles,
49
+ fontSize: (0, _fluidUtils.getComputedFluidTypographyValue)({
50
+ fontSize: attributes === null || attributes === void 0 ? void 0 : (_attributes$style2 = attributes.style) === null || _attributes$style2 === void 0 ? void 0 : (_attributes$style2$ty = _attributes$style2.typography) === null || _attributes$style2$ty === void 0 ? void 0 : _attributes$style2$ty.fontSize
51
+ })
52
+ };
53
+ }
54
+
41
55
  const style = (0, _style.getInlineStyles)({
42
56
  typography: typographyStyles
43
57
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/hooks/use-typography-props.js"],"names":["getTypographyClassesAndStyles","attributes","typographyStyles","style","typography","fontFamilyClassName","fontFamily","className","fontSize"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAIA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,6BAAT,CAAwCC,UAAxC,EAAqD;AAAA;;AAC3D,QAAMC,gBAAgB,GAAG,CAAAD,UAAU,SAAV,IAAAA,UAAU,WAAV,iCAAAA,UAAU,CAAEE,KAAZ,wEAAmBC,UAAnB,KAAiC,EAA1D;AACA,QAAMD,KAAK,GAAG,4BAAiB;AAAEC,IAAAA,UAAU,EAAEF;AAAd,GAAjB,CAAd;AACA,QAAMG,mBAAmB,GAAG,CAAC,EAAEJ,UAAF,aAAEA,UAAF,eAAEA,UAAU,CAAEK,UAAd,CAAD,GACxB,OAAO,uBAAWL,UAAU,CAACK,UAAtB,CAAoC,cADnB,GAEzB,EAFH;AAIA,QAAMC,SAAS,GAAG,yBACjBF,mBADiB,EAEjB,iCAAkBJ,UAAlB,aAAkBA,UAAlB,uBAAkBA,UAAU,CAAEO,QAA9B,CAFiB,CAAlB;AAKA,SAAO;AACND,IAAAA,SADM;AAENJ,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * Internal dependencies\n */\nimport { getInlineStyles } from './style';\nimport { getFontSizeClass } from '../components/font-sizes';\n\n// This utility is intended to assist where the serialization of the typography\n// block support is being skipped for a block but the typography related CSS\n// styles still need to be generated so they can be applied to inner elements.\n\n/**\n * Provides the CSS class names and inline styles for a block's typography support\n * attributes.\n *\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Typography block support derived CSS classes & styles.\n */\nexport function getTypographyClassesAndStyles( attributes ) {\n\tconst typographyStyles = attributes?.style?.typography || {};\n\tconst style = getInlineStyles( { typography: typographyStyles } );\n\tconst fontFamilyClassName = !! attributes?.fontFamily\n\t\t? `has-${ kebabCase( attributes.fontFamily ) }-font-family`\n\t\t: '';\n\n\tconst className = classnames(\n\t\tfontFamilyClassName,\n\t\tgetFontSizeClass( attributes?.fontSize )\n\t);\n\n\treturn {\n\t\tclassName,\n\t\tstyle,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/hooks/use-typography-props.js"],"names":["getTypographyClassesAndStyles","attributes","isFluidFontSizeActive","typographyStyles","style","typography","fontSize","fontFamilyClassName","fontFamily","className"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAXA;AACA;AACA;;AAIA;AACA;AACA;AAKA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,6BAAT,CACNC,UADM,EAENC,qBAFM,EAGL;AAAA;;AACD,MAAIC,gBAAgB,GAAG,CAAAF,UAAU,SAAV,IAAAA,UAAU,WAAV,iCAAAA,UAAU,CAAEG,KAAZ,wEAAmBC,UAAnB,KAAiC,EAAxD;;AAEA,MAAKH,qBAAL,EAA6B;AAAA;;AAC5BC,IAAAA,gBAAgB,GAAG,EAClB,GAAGA,gBADe;AAElBG,MAAAA,QAAQ,EAAE,iDAAiC;AAC1CA,QAAAA,QAAQ,EAAEL,UAAF,aAAEA,UAAF,6CAAEA,UAAU,CAAEG,KAAd,gFAAE,mBAAmBC,UAArB,0DAAE,sBAA+BC;AADC,OAAjC;AAFQ,KAAnB;AAMA;;AAED,QAAMF,KAAK,GAAG,4BAAiB;AAAEC,IAAAA,UAAU,EAAEF;AAAd,GAAjB,CAAd;AACA,QAAMI,mBAAmB,GAAG,CAAC,EAAEN,UAAF,aAAEA,UAAF,eAAEA,UAAU,CAAEO,UAAd,CAAD,GACxB,OAAO,uBAAWP,UAAU,CAACO,UAAtB,CAAoC,cADnB,GAEzB,EAFH;AAIA,QAAMC,SAAS,GAAG,yBACjBF,mBADiB,EAEjB,iCAAkBN,UAAlB,aAAkBA,UAAlB,uBAAkBA,UAAU,CAAEK,QAA9B,CAFiB,CAAlB;AAKA,SAAO;AACNG,IAAAA,SADM;AAENL,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * Internal dependencies\n */\nimport { getInlineStyles } from './style';\nimport { getFontSizeClass } from '../components/font-sizes';\nimport { getComputedFluidTypographyValue } from '../components/font-sizes/fluid-utils';\n\n// This utility is intended to assist where the serialization of the typography\n// block support is being skipped for a block but the typography related CSS\n// styles still need to be generated so they can be applied to inner elements.\n\n/**\n * Provides the CSS class names and inline styles for a block's typography support\n * attributes.\n *\n * @param {Object} attributes Block attributes.\n * @param {boolean} isFluidFontSizeActive Whether the function should try to convert font sizes to fluid values.\n *\n * @return {Object} Typography block support derived CSS classes & styles.\n */\nexport function getTypographyClassesAndStyles(\n\tattributes,\n\tisFluidFontSizeActive\n) {\n\tlet typographyStyles = attributes?.style?.typography || {};\n\n\tif ( isFluidFontSizeActive ) {\n\t\ttypographyStyles = {\n\t\t\t...typographyStyles,\n\t\t\tfontSize: getComputedFluidTypographyValue( {\n\t\t\t\tfontSize: attributes?.style?.typography?.fontSize,\n\t\t\t} ),\n\t\t};\n\t}\n\n\tconst style = getInlineStyles( { typography: typographyStyles } );\n\tconst fontFamilyClassName = !! attributes?.fontFamily\n\t\t? `has-${ kebabCase( attributes.fontFamily ) }-font-family`\n\t\t: '';\n\n\tconst className = classnames(\n\t\tfontFamilyClassName,\n\t\tgetFontSizeClass( attributes?.fontSize )\n\t);\n\n\treturn {\n\t\tclassName,\n\t\tstyle,\n\t};\n}\n"]}