@wordpress/block-editor 15.6.1-next.36001005c.0 → 15.6.1

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.
Files changed (163) hide show
  1. package/build/components/background-image-control/index.js +2 -2
  2. package/build/components/background-image-control/index.js.map +2 -2
  3. package/build/components/block-list/block.js +3 -3
  4. package/build/components/block-list/block.js.map +2 -2
  5. package/build/components/block-list/index.js +2 -2
  6. package/build/components/block-list/index.js.map +1 -1
  7. package/build/components/block-quick-navigation/index.js +0 -1
  8. package/build/components/block-quick-navigation/index.js.map +2 -2
  9. package/build/components/global-styles/border-panel.js +1 -2
  10. package/build/components/global-styles/border-panel.js.map +2 -2
  11. package/build/components/global-styles/color-panel.js +1 -2
  12. package/build/components/global-styles/color-panel.js.map +2 -2
  13. package/build/components/global-styles/dimensions-panel.js +2 -3
  14. package/build/components/global-styles/dimensions-panel.js.map +2 -2
  15. package/build/components/global-styles/filters-panel.js +1 -2
  16. package/build/components/global-styles/filters-panel.js.map +2 -2
  17. package/build/components/global-styles/get-block-css-selector.js +78 -0
  18. package/build/components/global-styles/get-block-css-selector.js.map +7 -0
  19. package/build/components/global-styles/hooks.js +95 -23
  20. package/build/components/global-styles/hooks.js.map +2 -2
  21. package/build/components/global-styles/index.js +14 -0
  22. package/build/components/global-styles/index.js.map +2 -2
  23. package/build/components/global-styles/typography-panel.js +19 -3
  24. package/build/components/global-styles/typography-panel.js.map +2 -2
  25. package/build/components/global-styles/typography-utils.js +49 -2
  26. package/build/components/global-styles/typography-utils.js.map +2 -2
  27. package/build/components/global-styles/use-global-styles-output.js +998 -0
  28. package/build/components/global-styles/use-global-styles-output.js.map +7 -0
  29. package/build/components/global-styles/utils.js +377 -0
  30. package/build/components/global-styles/utils.js.map +2 -2
  31. package/build/components/rich-text/index.js +8 -7
  32. package/build/components/rich-text/index.js.map +2 -2
  33. package/build/hooks/block-bindings.js +111 -170
  34. package/build/hooks/block-bindings.js.map +2 -2
  35. package/build/hooks/block-style-variation.js +10 -6
  36. package/build/hooks/block-style-variation.js.map +2 -2
  37. package/build/hooks/custom-class-name.js +1 -1
  38. package/build/hooks/custom-class-name.js.map +1 -1
  39. package/build/hooks/duotone.js +3 -3
  40. package/build/hooks/duotone.js.map +2 -2
  41. package/build/hooks/fit-text.js +31 -18
  42. package/build/hooks/fit-text.js.map +2 -2
  43. package/build/hooks/font-size.js +6 -5
  44. package/build/hooks/font-size.js.map +2 -2
  45. package/build/hooks/metadata.js +48 -2
  46. package/build/hooks/metadata.js.map +2 -2
  47. package/build/hooks/typography.js +11 -4
  48. package/build/hooks/typography.js.map +3 -3
  49. package/build/hooks/use-typography-props.js +2 -2
  50. package/build/hooks/use-typography-props.js.map +2 -2
  51. package/build/store/private-selectors.js +3 -3
  52. package/build/store/private-selectors.js.map +2 -2
  53. package/build/store/selectors.js +38 -13
  54. package/build/store/selectors.js.map +2 -2
  55. package/build/store/utils.js +2 -1
  56. package/build/store/utils.js.map +2 -2
  57. package/build/utils/fit-text-utils.js +4 -4
  58. package/build/utils/fit-text-utils.js.map +2 -2
  59. package/build-module/components/background-image-control/index.js +1 -1
  60. package/build-module/components/background-image-control/index.js.map +2 -2
  61. package/build-module/components/block-list/block.js +3 -3
  62. package/build-module/components/block-list/block.js.map +2 -2
  63. package/build-module/components/block-list/index.js +2 -2
  64. package/build-module/components/block-list/index.js.map +1 -1
  65. package/build-module/components/block-quick-navigation/index.js +0 -1
  66. package/build-module/components/block-quick-navigation/index.js.map +2 -2
  67. package/build-module/components/global-styles/border-panel.js +1 -2
  68. package/build-module/components/global-styles/border-panel.js.map +2 -2
  69. package/build-module/components/global-styles/color-panel.js +1 -2
  70. package/build-module/components/global-styles/color-panel.js.map +2 -2
  71. package/build-module/components/global-styles/dimensions-panel.js +1 -2
  72. package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
  73. package/build-module/components/global-styles/filters-panel.js +1 -2
  74. package/build-module/components/global-styles/filters-panel.js.map +2 -2
  75. package/build-module/components/global-styles/get-block-css-selector.js +54 -0
  76. package/build-module/components/global-styles/get-block-css-selector.js.map +7 -0
  77. package/build-module/components/global-styles/hooks.js +95 -27
  78. package/build-module/components/global-styles/hooks.js.map +2 -2
  79. package/build-module/components/global-styles/index.js +14 -0
  80. package/build-module/components/global-styles/index.js.map +2 -2
  81. package/build-module/components/global-styles/typography-panel.js +19 -3
  82. package/build-module/components/global-styles/typography-panel.js.map +2 -2
  83. package/build-module/components/global-styles/typography-utils.js +49 -1
  84. package/build-module/components/global-styles/typography-utils.js.map +2 -2
  85. package/build-module/components/global-styles/use-global-styles-output.js +979 -0
  86. package/build-module/components/global-styles/use-global-styles-output.js.map +7 -0
  87. package/build-module/components/global-styles/utils.js +364 -0
  88. package/build-module/components/global-styles/utils.js.map +2 -2
  89. package/build-module/components/rich-text/index.js +8 -7
  90. package/build-module/components/rich-text/index.js.map +2 -2
  91. package/build-module/hooks/block-bindings.js +112 -172
  92. package/build-module/hooks/block-bindings.js.map +2 -2
  93. package/build-module/hooks/block-style-variation.js +12 -4
  94. package/build-module/hooks/block-style-variation.js.map +2 -2
  95. package/build-module/hooks/custom-class-name.js +1 -1
  96. package/build-module/hooks/custom-class-name.js.map +1 -1
  97. package/build-module/hooks/duotone.js +3 -3
  98. package/build-module/hooks/duotone.js.map +2 -2
  99. package/build-module/hooks/fit-text.js +32 -19
  100. package/build-module/hooks/fit-text.js.map +2 -2
  101. package/build-module/hooks/font-size.js +5 -4
  102. package/build-module/hooks/font-size.js.map +2 -2
  103. package/build-module/hooks/metadata.js +46 -1
  104. package/build-module/hooks/metadata.js.map +2 -2
  105. package/build-module/hooks/typography.js +11 -4
  106. package/build-module/hooks/typography.js.map +3 -3
  107. package/build-module/hooks/use-typography-props.js +1 -1
  108. package/build-module/hooks/use-typography-props.js.map +2 -2
  109. package/build-module/store/private-selectors.js +2 -2
  110. package/build-module/store/private-selectors.js.map +2 -2
  111. package/build-module/store/selectors.js +39 -14
  112. package/build-module/store/selectors.js.map +2 -2
  113. package/build-module/store/utils.js +3 -2
  114. package/build-module/store/utils.js.map +2 -2
  115. package/build-module/utils/fit-text-utils.js +4 -4
  116. package/build-module/utils/fit-text-utils.js.map +2 -2
  117. package/build-style/style-rtl.css +6 -10
  118. package/build-style/style.css +6 -10
  119. package/package.json +35 -36
  120. package/src/components/background-image-control/index.js +1 -1
  121. package/src/components/block-card/style.scss +1 -1
  122. package/src/components/block-list/block.js +1 -1
  123. package/src/components/block-list/index.js +2 -2
  124. package/src/components/block-navigation/style.scss +1 -1
  125. package/src/components/block-quick-navigation/index.js +0 -1
  126. package/src/components/block-switcher/style.scss +1 -1
  127. package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
  128. package/src/components/global-styles/border-panel.js +1 -2
  129. package/src/components/global-styles/color-panel.js +1 -2
  130. package/src/components/global-styles/color-panel.native.js +1 -1
  131. package/src/components/global-styles/dimensions-panel.js +1 -2
  132. package/src/components/global-styles/filters-panel.js +1 -2
  133. package/src/components/global-styles/get-block-css-selector.js +114 -0
  134. package/src/components/global-styles/hooks.js +108 -29
  135. package/src/components/global-styles/index.js +8 -0
  136. package/src/components/global-styles/test/typography-utils.js +806 -0
  137. package/src/components/global-styles/test/use-global-styles-output.js +1131 -0
  138. package/src/components/global-styles/test/utils.js +442 -1
  139. package/src/components/global-styles/typography-panel.js +27 -3
  140. package/src/components/global-styles/typography-utils.js +133 -0
  141. package/src/components/global-styles/use-global-styles-output.js +1487 -0
  142. package/src/components/global-styles/utils.js +537 -0
  143. package/src/components/inserter/style.scss +2 -2
  144. package/src/components/multi-selection-inspector/style.scss +1 -1
  145. package/src/components/rich-text/index.js +8 -14
  146. package/src/hooks/block-bindings.js +79 -153
  147. package/src/hooks/block-style-variation.js +12 -4
  148. package/src/hooks/custom-class-name.js +1 -1
  149. package/src/hooks/duotone.js +3 -3
  150. package/src/hooks/fit-text.js +37 -28
  151. package/src/hooks/font-size.js +8 -4
  152. package/src/hooks/metadata.js +89 -0
  153. package/src/hooks/test/metadata.js +316 -0
  154. package/src/hooks/typography.js +15 -4
  155. package/src/hooks/use-typography-props.js +1 -1
  156. package/src/store/private-selectors.js +2 -2
  157. package/src/store/selectors.js +59 -21
  158. package/src/store/test/selectors.js +1 -1
  159. package/src/store/utils.js +2 -1
  160. package/src/style.scss +0 -1
  161. package/src/utils/fit-text-utils.js +4 -16
  162. package/tsconfig.json +0 -1
  163. package/src/components/block-quick-navigation/style.scss +0 -5
@@ -1,4 +1,50 @@
1
+ import {
2
+ getComputedFluidTypographyValue,
3
+ getTypographyValueAndUnit
4
+ } from "../font-sizes/fluid-utils";
1
5
  import { getFontStylesAndWeights } from "../../utils/get-font-styles-and-weights";
6
+ function getTypographyFontSizeValue(preset, settings) {
7
+ const { size: defaultSize } = preset;
8
+ if (!defaultSize || "0" === defaultSize || false === preset?.fluid) {
9
+ return defaultSize;
10
+ }
11
+ if (!isFluidTypographyEnabled(settings?.typography) && !isFluidTypographyEnabled(preset)) {
12
+ return defaultSize;
13
+ }
14
+ let fluidTypographySettings = getFluidTypographyOptionsFromSettings(settings);
15
+ fluidTypographySettings = typeof fluidTypographySettings?.fluid === "object" ? fluidTypographySettings?.fluid : {};
16
+ const fluidFontSizeValue = getComputedFluidTypographyValue({
17
+ minimumFontSize: preset?.fluid?.min,
18
+ maximumFontSize: preset?.fluid?.max,
19
+ fontSize: defaultSize,
20
+ minimumFontSizeLimit: fluidTypographySettings?.minFontSize,
21
+ maximumViewportWidth: fluidTypographySettings?.maxViewportWidth,
22
+ minimumViewportWidth: fluidTypographySettings?.minViewportWidth
23
+ });
24
+ if (!!fluidFontSizeValue) {
25
+ return fluidFontSizeValue;
26
+ }
27
+ return defaultSize;
28
+ }
29
+ function isFluidTypographyEnabled(typographySettings) {
30
+ const fluidSettings = typographySettings?.fluid;
31
+ return true === fluidSettings || fluidSettings && typeof fluidSettings === "object" && Object.keys(fluidSettings).length > 0;
32
+ }
33
+ function getFluidTypographyOptionsFromSettings(settings) {
34
+ const typographySettings = settings?.typography;
35
+ const layoutSettings = settings?.layout;
36
+ const defaultMaxViewportWidth = getTypographyValueAndUnit(
37
+ layoutSettings?.wideSize
38
+ ) ? layoutSettings?.wideSize : null;
39
+ return isFluidTypographyEnabled(typographySettings) && defaultMaxViewportWidth ? {
40
+ fluid: {
41
+ maxViewportWidth: defaultMaxViewportWidth,
42
+ ...typographySettings.fluid
43
+ }
44
+ } : {
45
+ fluid: typographySettings?.fluid
46
+ };
47
+ }
2
48
  function getMergedFontFamiliesAndFontFamilyFaces(settings, selectedFontFamily) {
3
49
  const fontFamiliesFromSettings = settings?.typography?.fontFamilies;
4
50
  const fontFamilies = ["default", "theme", "custom"].flatMap(
@@ -75,6 +121,8 @@ export {
75
121
  findNearestFontStyle,
76
122
  findNearestFontWeight,
77
123
  findNearestStyleAndWeight,
78
- getMergedFontFamiliesAndFontFamilyFaces
124
+ getFluidTypographyOptionsFromSettings,
125
+ getMergedFontFamiliesAndFontFamilyFaces,
126
+ getTypographyFontSizeValue
79
127
  };
80
128
  //# sourceMappingURL=typography-utils.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/global-styles/typography-utils.js"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { getFontStylesAndWeights } from '../../utils/get-font-styles-and-weights';\n\n/**\n * Returns an object of merged font families and the font faces from the selected font family\n * based on the theme.json settings object and the currently selected font family.\n *\n * @param {Object} settings Theme.json settings.\n * @param {string} selectedFontFamily Decoded font family string.\n * @return {Object} Merged font families and font faces from the selected font family.\n */\nexport function getMergedFontFamiliesAndFontFamilyFaces(\n\tsettings,\n\tselectedFontFamily\n) {\n\tconst fontFamiliesFromSettings = settings?.typography?.fontFamilies;\n\n\tconst fontFamilies = [ 'default', 'theme', 'custom' ].flatMap(\n\t\t( key ) => fontFamiliesFromSettings?.[ key ] ?? []\n\t);\n\n\tconst fontFamilyFaces =\n\t\tfontFamilies.find(\n\t\t\t( family ) => family.fontFamily === selectedFontFamily\n\t\t)?.fontFace ?? [];\n\n\treturn { fontFamilies, fontFamilyFaces };\n}\n\n/**\n * Returns the nearest font weight value from the available font weight list based on the new font weight.\n * The nearest font weight is the one with the smallest difference from the new font weight.\n *\n * @param {Array} availableFontWeights Array of available font weights.\n * @param {string} newFontWeightValue New font weight value.\n * @return {string} Nearest font weight.\n */\nexport function findNearestFontWeight(\n\tavailableFontWeights,\n\tnewFontWeightValue\n) {\n\tnewFontWeightValue =\n\t\t'number' === typeof newFontWeightValue\n\t\t\t? newFontWeightValue.toString()\n\t\t\t: newFontWeightValue;\n\tif ( ! newFontWeightValue || typeof newFontWeightValue !== 'string' ) {\n\t\treturn '';\n\t}\n\n\tif ( ! availableFontWeights || availableFontWeights.length === 0 ) {\n\t\treturn newFontWeightValue;\n\t}\n\n\tconst nearestFontWeight = availableFontWeights?.reduce(\n\t\t( nearest, { value: fw } ) => {\n\t\t\tconst currentDiff = Math.abs(\n\t\t\t\tparseInt( fw ) - parseInt( newFontWeightValue )\n\t\t\t);\n\t\t\tconst nearestDiff = Math.abs(\n\t\t\t\tparseInt( nearest ) - parseInt( newFontWeightValue )\n\t\t\t);\n\t\t\treturn currentDiff < nearestDiff ? fw : nearest;\n\t\t},\n\t\tavailableFontWeights[ 0 ]?.value\n\t);\n\n\treturn nearestFontWeight;\n}\n\n/**\n * Returns the nearest font style based on the new font style.\n * Defaults to an empty string if the new font style is not valid or available.\n *\n * @param {Array} availableFontStyles Array of available font weights.\n * @param {string} newFontStyleValue New font style value.\n * @return {string} Nearest font style or an empty string.\n */\nexport function findNearestFontStyle( availableFontStyles, newFontStyleValue ) {\n\tif ( typeof newFontStyleValue !== 'string' || ! newFontStyleValue ) {\n\t\treturn '';\n\t}\n\n\tconst validStyles = [ 'normal', 'italic', 'oblique' ];\n\tif ( ! validStyles.includes( newFontStyleValue ) ) {\n\t\treturn '';\n\t}\n\n\tif (\n\t\t! availableFontStyles ||\n\t\tavailableFontStyles.length === 0 ||\n\t\tavailableFontStyles.find(\n\t\t\t( style ) => style.value === newFontStyleValue\n\t\t)\n\t) {\n\t\treturn newFontStyleValue;\n\t}\n\n\tif (\n\t\tnewFontStyleValue === 'oblique' &&\n\t\t! availableFontStyles.find( ( style ) => style.value === 'oblique' )\n\t) {\n\t\treturn 'italic';\n\t}\n\n\treturn '';\n}\n\n/**\n * Returns the nearest font style and weight based on the available font family faces and the new font style and weight.\n *\n * @param {Array} fontFamilyFaces Array of available font family faces.\n * @param {string} fontStyle New font style. Defaults to previous value.\n * @param {string} fontWeight New font weight. Defaults to previous value.\n * @return {Object} Nearest font style and font weight.\n */\nexport function findNearestStyleAndWeight(\n\tfontFamilyFaces,\n\tfontStyle,\n\tfontWeight\n) {\n\tlet nearestFontStyle = fontStyle;\n\tlet nearestFontWeight = fontWeight;\n\n\tconst { fontStyles, fontWeights, combinedStyleAndWeightOptions } =\n\t\tgetFontStylesAndWeights( fontFamilyFaces );\n\n\t// Check if the new font style and weight are available in the font family faces.\n\tconst hasFontStyle = fontStyles?.some(\n\t\t( { value: fs } ) => fs === fontStyle\n\t);\n\tconst hasFontWeight = fontWeights?.some(\n\t\t( { value: fw } ) => fw?.toString() === fontWeight?.toString()\n\t);\n\n\tif ( ! hasFontStyle ) {\n\t\t/*\n\t\t * Default to italic if oblique is not available.\n\t\t * Or find the nearest font style based on the nearest font weight.\n\t\t */\n\t\tnearestFontStyle = fontStyle\n\t\t\t? findNearestFontStyle( fontStyles, fontStyle )\n\t\t\t: combinedStyleAndWeightOptions?.find(\n\t\t\t\t\t( option ) =>\n\t\t\t\t\t\toption.style.fontWeight ===\n\t\t\t\t\t\tfindNearestFontWeight( fontWeights, fontWeight )\n\t\t\t )?.style?.fontStyle;\n\t}\n\n\tif ( ! hasFontWeight ) {\n\t\t/*\n\t\t * Find the nearest font weight based on available weights.\n\t\t * Or find the nearest font weight based on the nearest font style.\n\t\t */\n\t\tnearestFontWeight = fontWeight\n\t\t\t? findNearestFontWeight( fontWeights, fontWeight )\n\t\t\t: combinedStyleAndWeightOptions?.find(\n\t\t\t\t\t( option ) =>\n\t\t\t\t\t\toption.style.fontStyle ===\n\t\t\t\t\t\t( nearestFontStyle || fontStyle )\n\t\t\t )?.style?.fontWeight;\n\t}\n\n\treturn { nearestFontStyle, nearestFontWeight };\n}\n"],
5
- "mappings": "AAGA,SAAS,+BAA+B;AAUjC,SAAS,wCACf,UACA,oBACC;AACD,QAAM,2BAA2B,UAAU,YAAY;AAEvD,QAAM,eAAe,CAAE,WAAW,SAAS,QAAS,EAAE;AAAA,IACrD,CAAE,QAAS,2BAA4B,GAAI,KAAK,CAAC;AAAA,EAClD;AAEA,QAAM,kBACL,aAAa;AAAA,IACZ,CAAE,WAAY,OAAO,eAAe;AAAA,EACrC,GAAG,YAAY,CAAC;AAEjB,SAAO,EAAE,cAAc,gBAAgB;AACxC;AAUO,SAAS,sBACf,sBACA,oBACC;AACD,uBACC,aAAa,OAAO,qBACjB,mBAAmB,SAAS,IAC5B;AACJ,MAAK,CAAE,sBAAsB,OAAO,uBAAuB,UAAW;AACrE,WAAO;AAAA,EACR;AAEA,MAAK,CAAE,wBAAwB,qBAAqB,WAAW,GAAI;AAClE,WAAO;AAAA,EACR;AAEA,QAAM,oBAAoB,sBAAsB;AAAA,IAC/C,CAAE,SAAS,EAAE,OAAO,GAAG,MAAO;AAC7B,YAAM,cAAc,KAAK;AAAA,QACxB,SAAU,EAAG,IAAI,SAAU,kBAAmB;AAAA,MAC/C;AACA,YAAM,cAAc,KAAK;AAAA,QACxB,SAAU,OAAQ,IAAI,SAAU,kBAAmB;AAAA,MACpD;AACA,aAAO,cAAc,cAAc,KAAK;AAAA,IACzC;AAAA,IACA,qBAAsB,CAAE,GAAG;AAAA,EAC5B;AAEA,SAAO;AACR;AAUO,SAAS,qBAAsB,qBAAqB,mBAAoB;AAC9E,MAAK,OAAO,sBAAsB,YAAY,CAAE,mBAAoB;AACnE,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,CAAE,UAAU,UAAU,SAAU;AACpD,MAAK,CAAE,YAAY,SAAU,iBAAkB,GAAI;AAClD,WAAO;AAAA,EACR;AAEA,MACC,CAAE,uBACF,oBAAoB,WAAW,KAC/B,oBAAoB;AAAA,IACnB,CAAE,UAAW,MAAM,UAAU;AAAA,EAC9B,GACC;AACD,WAAO;AAAA,EACR;AAEA,MACC,sBAAsB,aACtB,CAAE,oBAAoB,KAAM,CAAE,UAAW,MAAM,UAAU,SAAU,GAClE;AACD,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAUO,SAAS,0BACf,iBACA,WACA,YACC;AACD,MAAI,mBAAmB;AACvB,MAAI,oBAAoB;AAExB,QAAM,EAAE,YAAY,aAAa,8BAA8B,IAC9D,wBAAyB,eAAgB;AAG1C,QAAM,eAAe,YAAY;AAAA,IAChC,CAAE,EAAE,OAAO,GAAG,MAAO,OAAO;AAAA,EAC7B;AACA,QAAM,gBAAgB,aAAa;AAAA,IAClC,CAAE,EAAE,OAAO,GAAG,MAAO,IAAI,SAAS,MAAM,YAAY,SAAS;AAAA,EAC9D;AAEA,MAAK,CAAE,cAAe;AAKrB,uBAAmB,YAChB,qBAAsB,YAAY,SAAU,IAC5C,+BAA+B;AAAA,MAC/B,CAAE,WACD,OAAO,MAAM,eACb,sBAAuB,aAAa,UAAW;AAAA,IAChD,GAAG,OAAO;AAAA,EACd;AAEA,MAAK,CAAE,eAAgB;AAKtB,wBAAoB,aACjB,sBAAuB,aAAa,UAAW,IAC/C,+BAA+B;AAAA,MAC/B,CAAE,WACD,OAAO,MAAM,eACX,oBAAoB;AAAA,IACvB,GAAG,OAAO;AAAA,EACd;AAEA,SAAO,EAAE,kBAAkB,kBAAkB;AAC9C;",
4
+ "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/**\n * Internal dependencies\n */\nimport {\n\tgetComputedFluidTypographyValue,\n\tgetTypographyValueAndUnit,\n} from '../font-sizes/fluid-utils';\nimport { getFontStylesAndWeights } from '../../utils/get-font-styles-and-weights';\n\n/**\n * @typedef {Object} FluidPreset\n * @property {string|undefined} max A maximum font size value.\n * @property {?string|undefined} min A minimum font size value.\n */\n\n/**\n * @typedef {Object} Preset\n * @property {?string|?number} size A default font size.\n * @property {string} name A font size name, displayed in the UI.\n * @property {string} slug A font size slug\n * @property {boolean|FluidPreset|undefined} fluid Specifies the minimum and maximum font size value of a fluid font size.\n */\n\n/**\n * @typedef {Object} TypographySettings\n * @property {?string} minViewportWidth Minimum viewport size from which type will have fluidity. Optional if size is specified.\n * @property {?string} maxViewportWidth Maximum size up to which type will have fluidity. Optional if size is specified.\n * @property {?number} scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.\n * @property {?number} minFontSizeFactor How much to scale defaultFontSize by to derive minimumFontSize. Optional.\n * @property {?string} minFontSize The smallest a calculated font size may be. Optional.\n */\n\n/**\n * Returns a font-size value based on a given font-size preset.\n * Takes into account fluid typography parameters and attempts to return a css formula depending on available, valid values.\n *\n * The Core PHP equivalent is wp_get_typography_font_size_value().\n *\n * @param {Preset} preset\n * @param {Object} settings\n * @param {boolean|TypographySettings} settings.typography.fluid Whether fluid typography is enabled, and, optionally, fluid font size options.\n * @param {?Object} settings.typography.layout Layout options.\n *\n * @return {string|*} A font-size value or the value of preset.size.\n */\nexport function getTypographyFontSizeValue( preset, settings ) {\n\tconst { size: defaultSize } = preset;\n\n\t/*\n\t * Catch falsy values and 0/'0'. Fluid calculations cannot be performed on `0`.\n\t * Also return early when a preset font size explicitly disables fluid typography with `false`.\n\t */\n\tif ( ! defaultSize || '0' === defaultSize || false === preset?.fluid ) {\n\t\treturn defaultSize;\n\t}\n\n\t/*\n\t * Return early when fluid typography is disabled in the settings, and there\n\t * are no local settings to enable it for the individual preset.\n\t *\n\t * If this condition isn't met, either the settings or individual preset settings\n\t * have enabled fluid typography.\n\t */\n\tif (\n\t\t! isFluidTypographyEnabled( settings?.typography ) &&\n\t\t! isFluidTypographyEnabled( preset )\n\t) {\n\t\treturn defaultSize;\n\t}\n\n\tlet fluidTypographySettings =\n\t\tgetFluidTypographyOptionsFromSettings( settings );\n\tfluidTypographySettings =\n\t\ttypeof fluidTypographySettings?.fluid === 'object'\n\t\t\t? fluidTypographySettings?.fluid\n\t\t\t: {};\n\n\tconst fluidFontSizeValue = getComputedFluidTypographyValue( {\n\t\tminimumFontSize: preset?.fluid?.min,\n\t\tmaximumFontSize: preset?.fluid?.max,\n\t\tfontSize: defaultSize,\n\t\tminimumFontSizeLimit: fluidTypographySettings?.minFontSize,\n\t\tmaximumViewportWidth: fluidTypographySettings?.maxViewportWidth,\n\t\tminimumViewportWidth: fluidTypographySettings?.minViewportWidth,\n\t} );\n\n\tif ( !! fluidFontSizeValue ) {\n\t\treturn fluidFontSizeValue;\n\t}\n\n\treturn defaultSize;\n}\n\nfunction isFluidTypographyEnabled( typographySettings ) {\n\tconst fluidSettings = typographySettings?.fluid;\n\treturn (\n\t\ttrue === fluidSettings ||\n\t\t( fluidSettings &&\n\t\t\ttypeof fluidSettings === 'object' &&\n\t\t\tObject.keys( fluidSettings ).length > 0 )\n\t);\n}\n\n/**\n * Returns fluid typography settings from theme.json setting object.\n *\n * @param {Object} settings Theme.json settings\n * @param {Object} settings.typography Theme.json typography settings\n * @param {Object} settings.layout Theme.json layout settings\n * @return {TypographySettings} Fluid typography settings\n */\nexport function getFluidTypographyOptionsFromSettings( settings ) {\n\tconst typographySettings = settings?.typography;\n\tconst layoutSettings = settings?.layout;\n\tconst defaultMaxViewportWidth = getTypographyValueAndUnit(\n\t\tlayoutSettings?.wideSize\n\t)\n\t\t? layoutSettings?.wideSize\n\t\t: null;\n\treturn isFluidTypographyEnabled( typographySettings ) &&\n\t\tdefaultMaxViewportWidth\n\t\t? {\n\t\t\t\tfluid: {\n\t\t\t\t\tmaxViewportWidth: defaultMaxViewportWidth,\n\t\t\t\t\t...typographySettings.fluid,\n\t\t\t\t},\n\t\t }\n\t\t: {\n\t\t\t\tfluid: typographySettings?.fluid,\n\t\t };\n}\n\n/**\n * Returns an object of merged font families and the font faces from the selected font family\n * based on the theme.json settings object and the currently selected font family.\n *\n * @param {Object} settings Theme.json settings.\n * @param {string} selectedFontFamily Decoded font family string.\n * @return {Object} Merged font families and font faces from the selected font family.\n */\nexport function getMergedFontFamiliesAndFontFamilyFaces(\n\tsettings,\n\tselectedFontFamily\n) {\n\tconst fontFamiliesFromSettings = settings?.typography?.fontFamilies;\n\n\tconst fontFamilies = [ 'default', 'theme', 'custom' ].flatMap(\n\t\t( key ) => fontFamiliesFromSettings?.[ key ] ?? []\n\t);\n\n\tconst fontFamilyFaces =\n\t\tfontFamilies.find(\n\t\t\t( family ) => family.fontFamily === selectedFontFamily\n\t\t)?.fontFace ?? [];\n\n\treturn { fontFamilies, fontFamilyFaces };\n}\n\n/**\n * Returns the nearest font weight value from the available font weight list based on the new font weight.\n * The nearest font weight is the one with the smallest difference from the new font weight.\n *\n * @param {Array} availableFontWeights Array of available font weights.\n * @param {string} newFontWeightValue New font weight value.\n * @return {string} Nearest font weight.\n */\nexport function findNearestFontWeight(\n\tavailableFontWeights,\n\tnewFontWeightValue\n) {\n\tnewFontWeightValue =\n\t\t'number' === typeof newFontWeightValue\n\t\t\t? newFontWeightValue.toString()\n\t\t\t: newFontWeightValue;\n\tif ( ! newFontWeightValue || typeof newFontWeightValue !== 'string' ) {\n\t\treturn '';\n\t}\n\n\tif ( ! availableFontWeights || availableFontWeights.length === 0 ) {\n\t\treturn newFontWeightValue;\n\t}\n\n\tconst nearestFontWeight = availableFontWeights?.reduce(\n\t\t( nearest, { value: fw } ) => {\n\t\t\tconst currentDiff = Math.abs(\n\t\t\t\tparseInt( fw ) - parseInt( newFontWeightValue )\n\t\t\t);\n\t\t\tconst nearestDiff = Math.abs(\n\t\t\t\tparseInt( nearest ) - parseInt( newFontWeightValue )\n\t\t\t);\n\t\t\treturn currentDiff < nearestDiff ? fw : nearest;\n\t\t},\n\t\tavailableFontWeights[ 0 ]?.value\n\t);\n\n\treturn nearestFontWeight;\n}\n\n/**\n * Returns the nearest font style based on the new font style.\n * Defaults to an empty string if the new font style is not valid or available.\n *\n * @param {Array} availableFontStyles Array of available font weights.\n * @param {string} newFontStyleValue New font style value.\n * @return {string} Nearest font style or an empty string.\n */\nexport function findNearestFontStyle( availableFontStyles, newFontStyleValue ) {\n\tif ( typeof newFontStyleValue !== 'string' || ! newFontStyleValue ) {\n\t\treturn '';\n\t}\n\n\tconst validStyles = [ 'normal', 'italic', 'oblique' ];\n\tif ( ! validStyles.includes( newFontStyleValue ) ) {\n\t\treturn '';\n\t}\n\n\tif (\n\t\t! availableFontStyles ||\n\t\tavailableFontStyles.length === 0 ||\n\t\tavailableFontStyles.find(\n\t\t\t( style ) => style.value === newFontStyleValue\n\t\t)\n\t) {\n\t\treturn newFontStyleValue;\n\t}\n\n\tif (\n\t\tnewFontStyleValue === 'oblique' &&\n\t\t! availableFontStyles.find( ( style ) => style.value === 'oblique' )\n\t) {\n\t\treturn 'italic';\n\t}\n\n\treturn '';\n}\n\n/**\n * Returns the nearest font style and weight based on the available font family faces and the new font style and weight.\n *\n * @param {Array} fontFamilyFaces Array of available font family faces.\n * @param {string} fontStyle New font style. Defaults to previous value.\n * @param {string} fontWeight New font weight. Defaults to previous value.\n * @return {Object} Nearest font style and font weight.\n */\nexport function findNearestStyleAndWeight(\n\tfontFamilyFaces,\n\tfontStyle,\n\tfontWeight\n) {\n\tlet nearestFontStyle = fontStyle;\n\tlet nearestFontWeight = fontWeight;\n\n\tconst { fontStyles, fontWeights, combinedStyleAndWeightOptions } =\n\t\tgetFontStylesAndWeights( fontFamilyFaces );\n\n\t// Check if the new font style and weight are available in the font family faces.\n\tconst hasFontStyle = fontStyles?.some(\n\t\t( { value: fs } ) => fs === fontStyle\n\t);\n\tconst hasFontWeight = fontWeights?.some(\n\t\t( { value: fw } ) => fw?.toString() === fontWeight?.toString()\n\t);\n\n\tif ( ! hasFontStyle ) {\n\t\t/*\n\t\t * Default to italic if oblique is not available.\n\t\t * Or find the nearest font style based on the nearest font weight.\n\t\t */\n\t\tnearestFontStyle = fontStyle\n\t\t\t? findNearestFontStyle( fontStyles, fontStyle )\n\t\t\t: combinedStyleAndWeightOptions?.find(\n\t\t\t\t\t( option ) =>\n\t\t\t\t\t\toption.style.fontWeight ===\n\t\t\t\t\t\tfindNearestFontWeight( fontWeights, fontWeight )\n\t\t\t )?.style?.fontStyle;\n\t}\n\n\tif ( ! hasFontWeight ) {\n\t\t/*\n\t\t * Find the nearest font weight based on available weights.\n\t\t * Or find the nearest font weight based on the nearest font style.\n\t\t */\n\t\tnearestFontWeight = fontWeight\n\t\t\t? findNearestFontWeight( fontWeights, fontWeight )\n\t\t\t: combinedStyleAndWeightOptions?.find(\n\t\t\t\t\t( option ) =>\n\t\t\t\t\t\toption.style.fontStyle ===\n\t\t\t\t\t\t( nearestFontStyle || fontStyle )\n\t\t\t )?.style?.fontWeight;\n\t}\n\n\treturn { nearestFontStyle, nearestFontWeight };\n}\n"],
5
+ "mappings": "AASA;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,+BAA+B;AAsCjC,SAAS,2BAA4B,QAAQ,UAAW;AAC9D,QAAM,EAAE,MAAM,YAAY,IAAI;AAM9B,MAAK,CAAE,eAAe,QAAQ,eAAe,UAAU,QAAQ,OAAQ;AACtE,WAAO;AAAA,EACR;AASA,MACC,CAAE,yBAA0B,UAAU,UAAW,KACjD,CAAE,yBAA0B,MAAO,GAClC;AACD,WAAO;AAAA,EACR;AAEA,MAAI,0BACH,sCAAuC,QAAS;AACjD,4BACC,OAAO,yBAAyB,UAAU,WACvC,yBAAyB,QACzB,CAAC;AAEL,QAAM,qBAAqB,gCAAiC;AAAA,IAC3D,iBAAiB,QAAQ,OAAO;AAAA,IAChC,iBAAiB,QAAQ,OAAO;AAAA,IAChC,UAAU;AAAA,IACV,sBAAsB,yBAAyB;AAAA,IAC/C,sBAAsB,yBAAyB;AAAA,IAC/C,sBAAsB,yBAAyB;A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