@wordpress/edit-site 4.15.1-next.4d3b314fd5.0 → 4.17.0

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 (252) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/block-editor/block-inspector-button.js +1 -1
  3. package/build/components/block-editor/block-inspector-button.js.map +1 -1
  4. package/build/components/block-editor/index.js +17 -11
  5. package/build/components/block-editor/index.js.map +1 -1
  6. package/build/components/block-editor/resizable-editor.js +11 -35
  7. package/build/components/block-editor/resizable-editor.js.map +1 -1
  8. package/build/components/editor/index.js +5 -7
  9. package/build/components/editor/index.js.map +1 -1
  10. package/build/components/global-styles/preview.js +85 -50
  11. package/build/components/global-styles/preview.js.map +1 -1
  12. package/build/components/global-styles/screen-style-variations.js +35 -4
  13. package/build/components/global-styles/screen-style-variations.js.map +1 -1
  14. package/build/components/global-styles/screen-typography-element.js +49 -2
  15. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  16. package/build/components/global-styles/typography-panel.js +143 -83
  17. package/build/components/global-styles/typography-panel.js.map +1 -1
  18. package/build/components/global-styles/typography-preview.js +54 -0
  19. package/build/components/global-styles/typography-preview.js.map +1 -0
  20. package/build/components/global-styles/typography-utils.js +39 -176
  21. package/build/components/global-styles/typography-utils.js.map +1 -1
  22. package/build/components/global-styles/use-global-styles-output.js +34 -16
  23. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  24. package/build/components/{header → header-edit-mode}/document-actions/index.js +58 -24
  25. package/build/components/header-edit-mode/document-actions/index.js.map +1 -0
  26. package/build/components/{header → header-edit-mode}/index.js +13 -49
  27. package/build/components/header-edit-mode/index.js.map +1 -0
  28. package/build/components/{header → header-edit-mode}/mode-switcher/index.js +0 -0
  29. package/build/components/header-edit-mode/mode-switcher/index.js.map +1 -0
  30. package/build/components/{header → header-edit-mode}/more-menu/copy-content-menu-item.js +0 -0
  31. package/build/components/header-edit-mode/more-menu/copy-content-menu-item.js.map +1 -0
  32. package/build/components/{header → header-edit-mode}/more-menu/index.js +0 -0
  33. package/build/components/header-edit-mode/more-menu/index.js.map +1 -0
  34. package/build/components/{header → header-edit-mode}/more-menu/site-export.js +0 -0
  35. package/build/components/header-edit-mode/more-menu/site-export.js.map +1 -0
  36. package/build/components/{header → header-edit-mode}/more-menu/welcome-guide-menu-item.js +0 -0
  37. package/build/components/header-edit-mode/more-menu/welcome-guide-menu-item.js.map +1 -0
  38. package/build/components/{header → header-edit-mode}/plugin-more-menu-item/index.js +0 -0
  39. package/build/components/header-edit-mode/plugin-more-menu-item/index.js.map +1 -0
  40. package/build/components/{header → header-edit-mode}/plugin-sidebar-more-menu-item/index.js +0 -0
  41. package/build/components/header-edit-mode/plugin-sidebar-more-menu-item/index.js.map +1 -0
  42. package/build/components/{header → header-edit-mode}/tools-more-menu-group/index.js +0 -0
  43. package/build/components/header-edit-mode/tools-more-menu-group/index.js.map +1 -0
  44. package/build/components/{header → header-edit-mode}/undo-redo/redo.js +0 -0
  45. package/build/components/header-edit-mode/undo-redo/redo.js.map +1 -0
  46. package/build/components/{header → header-edit-mode}/undo-redo/undo.js +0 -0
  47. package/build/components/header-edit-mode/undo-redo/undo.js.map +1 -0
  48. package/build/components/keyboard-shortcuts/index.js +1 -1
  49. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  50. package/build/components/main-dashboard-button/index.js +2 -2
  51. package/build/components/main-dashboard-button/index.js.map +1 -1
  52. package/build/components/{sidebar → sidebar-edit-mode}/constants.js +0 -0
  53. package/build/components/sidebar-edit-mode/constants.js.map +1 -0
  54. package/build/components/{sidebar → sidebar-edit-mode}/default-sidebar.js +0 -0
  55. package/build/components/sidebar-edit-mode/default-sidebar.js.map +1 -0
  56. package/build/components/{sidebar → sidebar-edit-mode}/global-styles-sidebar.js +0 -0
  57. package/build/components/sidebar-edit-mode/global-styles-sidebar.js.map +1 -0
  58. package/build/components/{sidebar → sidebar-edit-mode}/index.js +1 -1
  59. package/build/components/sidebar-edit-mode/index.js.map +1 -0
  60. package/build/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/index.js +0 -0
  61. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/index.js.map +1 -0
  62. package/build/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-inspector.js +0 -0
  63. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js.map +1 -0
  64. package/build/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-menu.js +0 -0
  65. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js.map +1 -0
  66. package/build/components/{sidebar → sidebar-edit-mode}/plugin-sidebar/index.js +1 -1
  67. package/build/components/sidebar-edit-mode/plugin-sidebar/index.js.map +1 -0
  68. package/build/components/{sidebar → sidebar-edit-mode}/settings-header/index.js +2 -2
  69. package/build/components/sidebar-edit-mode/settings-header/index.js.map +1 -0
  70. package/build/components/{sidebar → sidebar-edit-mode}/template-card/index.js +0 -0
  71. package/build/components/sidebar-edit-mode/template-card/index.js.map +1 -0
  72. package/build/components/{sidebar → sidebar-edit-mode}/template-card/template-actions.js +0 -0
  73. package/build/components/sidebar-edit-mode/template-card/template-actions.js.map +1 -0
  74. package/build/components/{sidebar → sidebar-edit-mode}/template-card/template-areas.js +0 -0
  75. package/build/components/sidebar-edit-mode/template-card/template-areas.js.map +1 -0
  76. package/build/index.js +23 -4
  77. package/build/index.js.map +1 -1
  78. package/build-module/components/block-editor/block-inspector-button.js +1 -1
  79. package/build-module/components/block-editor/block-inspector-button.js.map +1 -1
  80. package/build-module/components/block-editor/index.js +16 -10
  81. package/build-module/components/block-editor/index.js.map +1 -1
  82. package/build-module/components/block-editor/resizable-editor.js +10 -34
  83. package/build-module/components/block-editor/resizable-editor.js.map +1 -1
  84. package/build-module/components/editor/index.js +4 -6
  85. package/build-module/components/editor/index.js.map +1 -1
  86. package/build-module/components/global-styles/preview.js +85 -50
  87. package/build-module/components/global-styles/preview.js.map +1 -1
  88. package/build-module/components/global-styles/screen-style-variations.js +36 -6
  89. package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
  90. package/build-module/components/global-styles/screen-typography-element.js +48 -2
  91. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  92. package/build-module/components/global-styles/typography-panel.js +143 -85
  93. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  94. package/build-module/components/global-styles/typography-preview.js +46 -0
  95. package/build-module/components/global-styles/typography-preview.js.map +1 -0
  96. package/build-module/components/global-styles/typography-utils.js +37 -169
  97. package/build-module/components/global-styles/typography-utils.js.map +1 -1
  98. package/build-module/components/global-styles/use-global-styles-output.js +33 -16
  99. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  100. package/build-module/components/{header → header-edit-mode}/document-actions/index.js +53 -24
  101. package/build-module/components/header-edit-mode/document-actions/index.js.map +1 -0
  102. package/build-module/components/{header → header-edit-mode}/index.js +13 -46
  103. package/build-module/components/header-edit-mode/index.js.map +1 -0
  104. package/build-module/components/{header → header-edit-mode}/mode-switcher/index.js +0 -0
  105. package/build-module/components/header-edit-mode/mode-switcher/index.js.map +1 -0
  106. package/build-module/components/{header → header-edit-mode}/more-menu/copy-content-menu-item.js +0 -0
  107. package/build-module/components/header-edit-mode/more-menu/copy-content-menu-item.js.map +1 -0
  108. package/build-module/components/{header → header-edit-mode}/more-menu/index.js +0 -0
  109. package/build-module/components/header-edit-mode/more-menu/index.js.map +1 -0
  110. package/build-module/components/{header → header-edit-mode}/more-menu/site-export.js +0 -0
  111. package/build-module/components/header-edit-mode/more-menu/site-export.js.map +1 -0
  112. package/build-module/components/{header → header-edit-mode}/more-menu/welcome-guide-menu-item.js +0 -0
  113. package/build-module/components/header-edit-mode/more-menu/welcome-guide-menu-item.js.map +1 -0
  114. package/build-module/components/{header → header-edit-mode}/plugin-more-menu-item/index.js +0 -0
  115. package/build-module/components/header-edit-mode/plugin-more-menu-item/index.js.map +1 -0
  116. package/build-module/components/{header → header-edit-mode}/plugin-sidebar-more-menu-item/index.js +0 -0
  117. package/build-module/components/header-edit-mode/plugin-sidebar-more-menu-item/index.js.map +1 -0
  118. package/build-module/components/{header → header-edit-mode}/tools-more-menu-group/index.js +0 -0
  119. package/build-module/components/header-edit-mode/tools-more-menu-group/index.js.map +1 -0
  120. package/build-module/components/{header → header-edit-mode}/undo-redo/redo.js +0 -0
  121. package/build-module/components/header-edit-mode/undo-redo/redo.js.map +1 -0
  122. package/build-module/components/{header → header-edit-mode}/undo-redo/undo.js +0 -0
  123. package/build-module/components/header-edit-mode/undo-redo/undo.js.map +1 -0
  124. package/build-module/components/keyboard-shortcuts/index.js +1 -1
  125. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  126. package/build-module/components/main-dashboard-button/index.js +3 -3
  127. package/build-module/components/main-dashboard-button/index.js.map +1 -1
  128. package/build-module/components/{sidebar → sidebar-edit-mode}/constants.js +0 -0
  129. package/build-module/components/sidebar-edit-mode/constants.js.map +1 -0
  130. package/build-module/components/{sidebar → sidebar-edit-mode}/default-sidebar.js +0 -0
  131. package/build-module/components/sidebar-edit-mode/default-sidebar.js.map +1 -0
  132. package/build-module/components/{sidebar → sidebar-edit-mode}/global-styles-sidebar.js +0 -0
  133. package/build-module/components/sidebar-edit-mode/global-styles-sidebar.js.map +1 -0
  134. package/build-module/components/{sidebar → sidebar-edit-mode}/index.js +1 -1
  135. package/build-module/components/sidebar-edit-mode/index.js.map +1 -0
  136. package/build-module/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/index.js +0 -0
  137. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/index.js.map +1 -0
  138. package/build-module/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-inspector.js +0 -0
  139. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js.map +1 -0
  140. package/build-module/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-menu.js +0 -0
  141. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js.map +1 -0
  142. package/build-module/components/{sidebar → sidebar-edit-mode}/plugin-sidebar/index.js +1 -1
  143. package/build-module/components/sidebar-edit-mode/plugin-sidebar/index.js.map +1 -0
  144. package/build-module/components/{sidebar → sidebar-edit-mode}/settings-header/index.js +2 -2
  145. package/build-module/components/sidebar-edit-mode/settings-header/index.js.map +1 -0
  146. package/build-module/components/{sidebar → sidebar-edit-mode}/template-card/index.js +0 -0
  147. package/build-module/components/sidebar-edit-mode/template-card/index.js.map +1 -0
  148. package/build-module/components/{sidebar → sidebar-edit-mode}/template-card/template-actions.js +0 -0
  149. package/build-module/components/sidebar-edit-mode/template-card/template-actions.js.map +1 -0
  150. package/build-module/components/{sidebar → sidebar-edit-mode}/template-card/template-areas.js +0 -0
  151. package/build-module/components/sidebar-edit-mode/template-card/template-areas.js.map +1 -0
  152. package/build-module/index.js +22 -4
  153. package/build-module/index.js.map +1 -1
  154. package/build-style/style-rtl.css +64 -89
  155. package/build-style/style.css +64 -89
  156. package/package.json +29 -29
  157. package/src/components/block-editor/block-inspector-button.js +1 -1
  158. package/src/components/block-editor/index.js +29 -11
  159. package/src/components/block-editor/resizable-editor.js +8 -37
  160. package/src/components/editor/index.js +2 -4
  161. package/src/components/global-styles/preview.js +81 -60
  162. package/src/components/global-styles/screen-style-variations.js +39 -4
  163. package/src/components/global-styles/screen-typography-element.js +65 -1
  164. package/src/components/global-styles/style.scss +2 -2
  165. package/src/components/global-styles/test/typography-utils.js +333 -103
  166. package/src/components/global-styles/test/use-global-styles-output.js +57 -3
  167. package/src/components/global-styles/typography-panel.js +205 -150
  168. package/src/components/global-styles/typography-preview.js +49 -0
  169. package/src/components/global-styles/typography-utils.js +34 -195
  170. package/src/components/global-styles/use-global-styles-output.js +31 -9
  171. package/src/components/{header → header-edit-mode}/document-actions/index.js +67 -46
  172. package/src/components/{header → header-edit-mode}/document-actions/style.scss +0 -0
  173. package/src/components/{header → header-edit-mode}/index.js +12 -44
  174. package/src/components/{header → header-edit-mode}/mode-switcher/index.js +0 -0
  175. package/src/components/{header → header-edit-mode}/more-menu/copy-content-menu-item.js +0 -0
  176. package/src/components/{header → header-edit-mode}/more-menu/index.js +0 -0
  177. package/src/components/{header → header-edit-mode}/more-menu/site-export.js +0 -0
  178. package/src/components/{header → header-edit-mode}/more-menu/welcome-guide-menu-item.js +0 -0
  179. package/src/components/{header → header-edit-mode}/plugin-more-menu-item/index.js +0 -0
  180. package/src/components/{header → header-edit-mode}/plugin-sidebar-more-menu-item/index.js +0 -0
  181. package/src/components/{header → header-edit-mode}/style.scss +20 -50
  182. package/src/components/{header → header-edit-mode}/tools-more-menu-group/index.js +0 -0
  183. package/src/components/{header → header-edit-mode}/undo-redo/redo.js +0 -0
  184. package/src/components/{header → header-edit-mode}/undo-redo/undo.js +0 -0
  185. package/src/components/keyboard-shortcuts/index.js +1 -1
  186. package/src/components/main-dashboard-button/index.js +3 -3
  187. package/src/components/{sidebar → sidebar-edit-mode}/constants.js +0 -0
  188. package/src/components/{sidebar → sidebar-edit-mode}/default-sidebar.js +0 -0
  189. package/src/components/{sidebar → sidebar-edit-mode}/global-styles-sidebar.js +0 -0
  190. package/src/components/{sidebar → sidebar-edit-mode}/index.js +1 -1
  191. package/src/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/index.js +0 -0
  192. package/src/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-inspector.js +0 -0
  193. package/src/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-menu.js +0 -0
  194. package/src/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/style.scss +0 -0
  195. package/src/components/{sidebar → sidebar-edit-mode}/plugin-sidebar/index.js +1 -1
  196. package/src/components/{sidebar → sidebar-edit-mode}/settings-header/index.js +2 -2
  197. package/src/components/{sidebar → sidebar-edit-mode}/settings-header/style.scss +2 -2
  198. package/src/components/{sidebar → sidebar-edit-mode}/style.scss +2 -2
  199. package/src/components/{sidebar → sidebar-edit-mode}/template-card/index.js +0 -0
  200. package/src/components/{sidebar → sidebar-edit-mode}/template-card/style.scss +0 -0
  201. package/src/components/{sidebar → sidebar-edit-mode}/template-card/template-actions.js +0 -0
  202. package/src/components/{sidebar → sidebar-edit-mode}/template-card/template-areas.js +0 -0
  203. package/src/index.js +24 -3
  204. package/src/style.scss +6 -6
  205. package/build/components/header/document-actions/index.js.map +0 -1
  206. package/build/components/header/index.js.map +0 -1
  207. package/build/components/header/mode-switcher/index.js.map +0 -1
  208. package/build/components/header/more-menu/copy-content-menu-item.js.map +0 -1
  209. package/build/components/header/more-menu/index.js.map +0 -1
  210. package/build/components/header/more-menu/site-export.js.map +0 -1
  211. package/build/components/header/more-menu/welcome-guide-menu-item.js.map +0 -1
  212. package/build/components/header/plugin-more-menu-item/index.js.map +0 -1
  213. package/build/components/header/plugin-sidebar-more-menu-item/index.js.map +0 -1
  214. package/build/components/header/tools-more-menu-group/index.js.map +0 -1
  215. package/build/components/header/undo-redo/redo.js.map +0 -1
  216. package/build/components/header/undo-redo/undo.js.map +0 -1
  217. package/build/components/sidebar/constants.js.map +0 -1
  218. package/build/components/sidebar/default-sidebar.js.map +0 -1
  219. package/build/components/sidebar/global-styles-sidebar.js.map +0 -1
  220. package/build/components/sidebar/index.js.map +0 -1
  221. package/build/components/sidebar/navigation-menu-sidebar/index.js.map +0 -1
  222. package/build/components/sidebar/navigation-menu-sidebar/navigation-inspector.js.map +0 -1
  223. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +0 -1
  224. package/build/components/sidebar/plugin-sidebar/index.js.map +0 -1
  225. package/build/components/sidebar/settings-header/index.js.map +0 -1
  226. package/build/components/sidebar/template-card/index.js.map +0 -1
  227. package/build/components/sidebar/template-card/template-actions.js.map +0 -1
  228. package/build/components/sidebar/template-card/template-areas.js.map +0 -1
  229. package/build-module/components/header/document-actions/index.js.map +0 -1
  230. package/build-module/components/header/index.js.map +0 -1
  231. package/build-module/components/header/mode-switcher/index.js.map +0 -1
  232. package/build-module/components/header/more-menu/copy-content-menu-item.js.map +0 -1
  233. package/build-module/components/header/more-menu/index.js.map +0 -1
  234. package/build-module/components/header/more-menu/site-export.js.map +0 -1
  235. package/build-module/components/header/more-menu/welcome-guide-menu-item.js.map +0 -1
  236. package/build-module/components/header/plugin-more-menu-item/index.js.map +0 -1
  237. package/build-module/components/header/plugin-sidebar-more-menu-item/index.js.map +0 -1
  238. package/build-module/components/header/tools-more-menu-group/index.js.map +0 -1
  239. package/build-module/components/header/undo-redo/redo.js.map +0 -1
  240. package/build-module/components/header/undo-redo/undo.js.map +0 -1
  241. package/build-module/components/sidebar/constants.js.map +0 -1
  242. package/build-module/components/sidebar/default-sidebar.js.map +0 -1
  243. package/build-module/components/sidebar/global-styles-sidebar.js.map +0 -1
  244. package/build-module/components/sidebar/index.js.map +0 -1
  245. package/build-module/components/sidebar/navigation-menu-sidebar/index.js.map +0 -1
  246. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-inspector.js.map +0 -1
  247. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +0 -1
  248. package/build-module/components/sidebar/plugin-sidebar/index.js.map +0 -1
  249. package/build-module/components/sidebar/settings-header/index.js.map +0 -1
  250. package/build-module/components/sidebar/template-card/index.js.map +0 -1
  251. package/build-module/components/sidebar/template-card/template-actions.js.map +0 -1
  252. package/build-module/components/sidebar/template-card/template-areas.js.map +0 -1
@@ -4,68 +4,63 @@
4
4
  * ---------------------------------------------------------------
5
5
  */
6
6
 
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+ import { getComputedFluidTypographyValue } from '@wordpress/block-editor';
11
+ /**
12
+ * @typedef {Object} FluidPreset
13
+ * @property {string|undefined} max A maximum font size value.
14
+ * @property {?string|undefined} min A minimum font size value.
15
+ */
16
+
17
+ /**
18
+ * @typedef {Object} Preset
19
+ * @property {?string|?number} size A default font size.
20
+ * @property {string} name A font size name, displayed in the UI.
21
+ * @property {string} slug A font size slug
22
+ * @property {boolean|FluidPreset|undefined} fluid A font size slug
23
+ */
24
+
7
25
  /**
8
26
  * Returns a font-size value based on a given font-size preset.
9
27
  * Takes into account fluid typography parameters and attempts to return a css formula depending on available, valid values.
10
28
  *
11
- * @param {Object} preset
12
- * @param {string} preset.size A default font size.
13
- * @param {string} preset.name A font size name, displayed in the UI.
14
- * @param {string} preset.slug A font size slug.
15
- * @param {Object} preset.fluid
16
- * @param {string|undefined} preset.fluid.max A maximum font size value.
17
- * @param {string|undefined} preset.fluid.min A minimum font size value.
18
- * @param {Object} typographySettings
19
- * @param {boolean} typographySettings.fluid Whether fluid typography is enabled.
29
+ * @param {Preset} preset
30
+ * @param {Object} typographySettings
31
+ * @param {boolean} typographySettings.fluid Whether fluid typography is enabled.
20
32
  *
21
- * @return {string} An font-size value
33
+ * @return {string|*} A font-size value or the value of preset.size.
22
34
  */
35
+
23
36
  export function getTypographyFontSizeValue(preset, typographySettings) {
37
+ var _preset$fluid, _preset$fluid2;
38
+
24
39
  const {
25
40
  size: defaultSize
26
41
  } = preset;
42
+ /*
43
+ * Catches falsy values and 0/'0'.
44
+ * Fluid calculations cannot be performed on 0.
45
+ */
27
46
 
28
- if (true !== (typographySettings === null || typographySettings === void 0 ? void 0 : typographySettings.fluid)) {
29
- return defaultSize;
30
- } // Defaults.
31
-
32
-
33
- const DEFAULT_MAXIMUM_VIEWPORT_WIDTH = '1600px';
34
- const DEFAULT_MINIMUM_VIEWPORT_WIDTH = '768px';
35
- const DEFAULT_MINIMUM_FONT_SIZE_FACTOR = 0.75;
36
- const DEFAULT_MAXIMUM_FONT_SIZE_FACTOR = 1.5;
37
- const DEFAULT_SCALE_FACTOR = 1; // Font sizes.
38
- // A font size has explicitly bypassed fluid calculations.
39
-
40
- if (false === (preset === null || preset === void 0 ? void 0 : preset.fluid)) {
47
+ if (!defaultSize || '0' === defaultSize) {
41
48
  return defaultSize;
42
49
  }
43
50
 
44
- const fluidFontSizeSettings = (preset === null || preset === void 0 ? void 0 : preset.fluid) || {}; // Try to grab explicit min and max fluid font sizes.
45
-
46
- let minimumFontSizeRaw = fluidFontSizeSettings === null || fluidFontSizeSettings === void 0 ? void 0 : fluidFontSizeSettings.min;
47
- let maximumFontSizeRaw = fluidFontSizeSettings === null || fluidFontSizeSettings === void 0 ? void 0 : fluidFontSizeSettings.max;
48
- const preferredSize = getTypographyValueAndUnit(defaultSize); // Protect against unsupported units.
49
-
50
- if (!(preferredSize !== null && preferredSize !== void 0 && preferredSize.unit)) {
51
+ if (true !== (typographySettings === null || typographySettings === void 0 ? void 0 : typographySettings.fluid)) {
51
52
  return defaultSize;
52
- } // If no fluid min or max font sizes are available, create some using min/max font size factors.
53
-
53
+ } // A font size has explicitly bypassed fluid calculations.
54
54
 
55
- if (!minimumFontSizeRaw) {
56
- minimumFontSizeRaw = preferredSize.value * DEFAULT_MINIMUM_FONT_SIZE_FACTOR + preferredSize.unit;
57
- }
58
55
 
59
- if (!maximumFontSizeRaw) {
60
- maximumFontSizeRaw = preferredSize.value * DEFAULT_MAXIMUM_FONT_SIZE_FACTOR + preferredSize.unit;
56
+ if (false === (preset === null || preset === void 0 ? void 0 : preset.fluid)) {
57
+ return defaultSize;
61
58
  }
62
59
 
63
60
  const fluidFontSizeValue = getComputedFluidTypographyValue({
64
- maximumViewPortWidth: DEFAULT_MAXIMUM_VIEWPORT_WIDTH,
65
- minimumViewPortWidth: DEFAULT_MINIMUM_VIEWPORT_WIDTH,
66
- maximumFontSize: maximumFontSizeRaw,
67
- minimumFontSize: minimumFontSizeRaw,
68
- scaleFactor: DEFAULT_SCALE_FACTOR
61
+ minimumFontSize: preset === null || preset === void 0 ? void 0 : (_preset$fluid = preset.fluid) === null || _preset$fluid === void 0 ? void 0 : _preset$fluid.min,
62
+ maximumFontSize: preset === null || preset === void 0 ? void 0 : (_preset$fluid2 = preset.fluid) === null || _preset$fluid2 === void 0 ? void 0 : _preset$fluid2.max,
63
+ fontSize: defaultSize
69
64
  });
70
65
 
71
66
  if (!!fluidFontSizeValue) {
@@ -74,131 +69,4 @@ export function getTypographyFontSizeValue(preset, typographySettings) {
74
69
 
75
70
  return defaultSize;
76
71
  }
77
- /**
78
- * Internal implementation of clamp() based on available min/max viewport width, and min/max font sizes.
79
- *
80
- * @param {Object} args
81
- * @param {string} args.maximumViewPortWidth Maximum size up to which type will have fluidity.
82
- * @param {string} args.minimumViewPortWidth Minimum viewport size from which type will have fluidity.
83
- * @param {string} args.maximumFontSize Maximum font size for any clamp() calculation.
84
- * @param {string} args.minimumFontSize Minimum font size for any clamp() calculation.
85
- * @param {number} args.scaleFactor A scale factor to determine how fast a font scales within boundaries.
86
- *
87
- * @return {string|null} A font-size value using clamp().
88
- */
89
-
90
- export function getComputedFluidTypographyValue(_ref) {
91
- let {
92
- maximumViewPortWidth,
93
- minimumViewPortWidth,
94
- maximumFontSize,
95
- minimumFontSize,
96
- scaleFactor
97
- } = _ref;
98
- // Grab the minimum font size and normalize it in order to use the value for calculations.
99
- const minimumFontSizeParsed = getTypographyValueAndUnit(minimumFontSize); // We get a 'preferred' unit to keep units consistent when calculating,
100
- // otherwise the result will not be accurate.
101
-
102
- 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.
103
-
104
- const maximumFontSizeParsed = getTypographyValueAndUnit(maximumFontSize, {
105
- coerceTo: fontSizeUnit
106
- }); // Protect against unsupported units.
107
-
108
- if (!minimumFontSizeParsed || !maximumFontSizeParsed) {
109
- return null;
110
- } // Use rem for accessible fluid target font scaling.
111
-
112
-
113
- const minimumFontSizeRem = getTypographyValueAndUnit(minimumFontSize, {
114
- coerceTo: 'rem'
115
- }); // Viewport widths defined for fluid typography. Normalize units
116
-
117
- const maximumViewPortWidthParsed = getTypographyValueAndUnit(maximumViewPortWidth, {
118
- coerceTo: fontSizeUnit
119
- });
120
- const minumumViewPortWidthParsed = getTypographyValueAndUnit(minimumViewPortWidth, {
121
- coerceTo: fontSizeUnit
122
- }); // Protect against unsupported units.
123
-
124
- if (!maximumViewPortWidthParsed || !minumumViewPortWidthParsed || !minimumFontSizeRem) {
125
- return null;
126
- } // Build CSS rule.
127
- // Borrowed from https://websemantics.uk/tools/responsive-font-calculator/.
128
-
129
-
130
- const minViewPortWidthOffsetValue = roundToPrecision(minumumViewPortWidthParsed.value / 100, 3);
131
- const viewPortWidthOffset = minViewPortWidthOffsetValue + fontSizeUnit;
132
- let linearFactor = 100 * ((maximumFontSizeParsed.value - minimumFontSizeParsed.value) / (maximumViewPortWidthParsed.value - minumumViewPortWidthParsed.value));
133
- linearFactor = roundToPrecision(linearFactor, 3) || 1;
134
- const linearFactorScaled = linearFactor * scaleFactor;
135
- const fluidTargetFontSize = `${minimumFontSizeRem.value}${minimumFontSizeRem.unit} + ((1vw - ${viewPortWidthOffset}) * ${linearFactorScaled})`;
136
- return `clamp(${minimumFontSize}, ${fluidTargetFontSize}, ${maximumFontSize})`;
137
- }
138
- /**
139
- *
140
- * @param {string} rawValue Raw size value from theme.json.
141
- * @param {Object|undefined} options Calculation options.
142
- *
143
- * @return {{ unit: string, value: number }|null} An object consisting of `'value'` and `'unit'` properties.
144
- */
145
-
146
- export function getTypographyValueAndUnit(rawValue) {
147
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
148
-
149
- if (!rawValue) {
150
- return null;
151
- }
152
-
153
- const {
154
- coerceTo,
155
- rootSizeValue,
156
- acceptableUnits
157
- } = {
158
- coerceTo: '',
159
- // Default browser font size. Later we could inject some JS to compute this `getComputedStyle( document.querySelector( "html" ) ).fontSize`.
160
- rootSizeValue: 16,
161
- acceptableUnits: ['rem', 'px', 'em'],
162
- ...options
163
- };
164
- const acceptableUnitsGroup = acceptableUnits === null || acceptableUnits === void 0 ? void 0 : acceptableUnits.join('|');
165
- const regexUnits = new RegExp(`^(\\d*\\.?\\d+)(${acceptableUnitsGroup}){1,1}$`);
166
- const matches = rawValue.match(regexUnits); // We need a number value and a unit.
167
-
168
- if (!matches || matches.length < 3) {
169
- return null;
170
- }
171
-
172
- let [, value, unit] = matches;
173
- let returnValue = parseFloat(value);
174
-
175
- if ('px' === coerceTo && ('em' === unit || 'rem' === unit)) {
176
- returnValue = returnValue * rootSizeValue;
177
- unit = coerceTo;
178
- }
179
-
180
- if ('px' === unit && ('em' === coerceTo || 'rem' === coerceTo)) {
181
- returnValue = returnValue / rootSizeValue;
182
- unit = coerceTo;
183
- }
184
-
185
- return {
186
- value: returnValue,
187
- unit
188
- };
189
- }
190
- /**
191
- * Returns a value rounded to defined precision.
192
- * Returns `undefined` if the value is not a valid finite number.
193
- *
194
- * @param {number} value Raw value.
195
- * @param {number} digits The number of digits to appear after the decimal point
196
- *
197
- * @return {number|undefined} Value rounded to standard precision.
198
- */
199
-
200
- export function roundToPrecision(value) {
201
- let digits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
202
- return Number.isFinite(value) ? parseFloat(value.toFixed(digits)) : undefined;
203
- }
204
72
  //# sourceMappingURL=typography-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/global-styles/typography-utils.js"],"names":["getTypographyFontSizeValue","preset","typographySettings","size","defaultSize","fluid","DEFAULT_MAXIMUM_VIEWPORT_WIDTH","DEFAULT_MINIMUM_VIEWPORT_WIDTH","DEFAULT_MINIMUM_FONT_SIZE_FACTOR","DEFAULT_MAXIMUM_FONT_SIZE_FACTOR","DEFAULT_SCALE_FACTOR","fluidFontSizeSettings","minimumFontSizeRaw","min","maximumFontSizeRaw","max","preferredSize","getTypographyValueAndUnit","unit","value","fluidFontSizeValue","getComputedFluidTypographyValue","maximumViewPortWidth","minimumViewPortWidth","maximumFontSize","minimumFontSize","scaleFactor","minimumFontSizeParsed","fontSizeUnit","maximumFontSizeParsed","coerceTo","minimumFontSizeRem","maximumViewPortWidthParsed","minumumViewPortWidthParsed","minViewPortWidthOffsetValue","roundToPrecision","viewPortWidthOffset","linearFactor","linearFactorScaled","fluidTargetFontSize","rawValue","options","rootSizeValue","acceptableUnits","acceptableUnitsGroup","join","regexUnits","RegExp","matches","match","length","returnValue","parseFloat","digits","Number","isFinite","toFixed","undefined"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,0BAAT,CAAqCC,MAArC,EAA6CC,kBAA7C,EAAkE;AACxE,QAAM;AAAEC,IAAAA,IAAI,EAAEC;AAAR,MAAwBH,MAA9B;;AAEA,MAAK,UAASC,kBAAT,aAASA,kBAAT,uBAASA,kBAAkB,CAAEG,KAA7B,CAAL,EAA0C;AACzC,WAAOD,WAAP;AACA,GALuE,CAOxE;;;AACA,QAAME,8BAA8B,GAAG,QAAvC;AACA,QAAMC,8BAA8B,GAAG,OAAvC;AACA,QAAMC,gCAAgC,GAAG,IAAzC;AACA,QAAMC,gCAAgC,GAAG,GAAzC;AACA,QAAMC,oBAAoB,GAAG,CAA7B,CAZwE,CAcxE;AACA;;AACA,MAAK,WAAUT,MAAV,aAAUA,MAAV,uBAAUA,MAAM,CAAEI,KAAlB,CAAL,EAA+B;AAC9B,WAAOD,WAAP;AACA;;AAED,QAAMO,qBAAqB,GAAG,CAAAV,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEI,KAAR,KAAiB,EAA/C,CApBwE,CAsBxE;;AACA,MAAIO,kBAAkB,GAAGD,qBAAH,aAAGA,qBAAH,uBAAGA,qBAAqB,CAAEE,GAAhD;AACA,MAAIC,kBAAkB,GAAGH,qBAAH,aAAGA,qBAAH,uBAAGA,qBAAqB,CAAEI,GAAhD;AACA,QAAMC,aAAa,GAAGC,yBAAyB,CAAEb,WAAF,CAA/C,CAzBwE,CA2BxE;;AACA,MAAK,EAAEY,aAAF,aAAEA,aAAF,eAAEA,aAAa,CAAEE,IAAjB,CAAL,EAA6B;AAC5B,WAAOd,WAAP;AACA,GA9BuE,CAgCxE;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ACA;;AACA,OAAO,SAASiB,gBAAT,CAA2BhB,KAA3B,EAA+C;AAAA,MAAbkC,MAAa,uEAAJ,CAAI;AACrD,SAAOC,MAAM,CAACC,QAAP,CAAiBpC,KAAjB,IACJiC,UAAU,CAAEjC,KAAK,CAACqC,OAAN,CAAeH,MAAf,CAAF,CADN,GAEJI,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/**\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 * @param {Object} preset\n * @param {string} preset.size A default font size.\n * @param {string} preset.name A font size name, displayed in the UI.\n * @param {string} preset.slug A font size slug.\n * @param {Object} preset.fluid\n * @param {string|undefined} preset.fluid.max A maximum font size value.\n * @param {string|undefined} preset.fluid.min A minimum font size value.\n * @param {Object} typographySettings\n * @param {boolean} typographySettings.fluid Whether fluid typography is enabled.\n *\n * @return {string} An font-size value\n */\nexport function getTypographyFontSizeValue( preset, typographySettings ) {\n\tconst { size: defaultSize } = preset;\n\n\tif ( true !== typographySettings?.fluid ) {\n\t\treturn defaultSize;\n\t}\n\n\t// Defaults.\n\tconst DEFAULT_MAXIMUM_VIEWPORT_WIDTH = '1600px';\n\tconst DEFAULT_MINIMUM_VIEWPORT_WIDTH = '768px';\n\tconst DEFAULT_MINIMUM_FONT_SIZE_FACTOR = 0.75;\n\tconst DEFAULT_MAXIMUM_FONT_SIZE_FACTOR = 1.5;\n\tconst DEFAULT_SCALE_FACTOR = 1;\n\n\t// Font sizes.\n\t// A font size has explicitly bypassed fluid calculations.\n\tif ( false === preset?.fluid ) {\n\t\treturn defaultSize;\n\t}\n\n\tconst fluidFontSizeSettings = preset?.fluid || {};\n\n\t// Try to grab explicit min and max fluid font sizes.\n\tlet minimumFontSizeRaw = fluidFontSizeSettings?.min;\n\tlet maximumFontSizeRaw = fluidFontSizeSettings?.max;\n\tconst preferredSize = getTypographyValueAndUnit( defaultSize );\n\n\t// Protect against unsupported units.\n\tif ( ! preferredSize?.unit ) {\n\t\treturn defaultSize;\n\t}\n\n\t// If no fluid min or max font sizes are available, create some using min/max font size factors.\n\tif ( ! minimumFontSizeRaw ) {\n\t\tminimumFontSizeRaw =\n\t\t\tpreferredSize.value * DEFAULT_MINIMUM_FONT_SIZE_FACTOR +\n\t\t\tpreferredSize.unit;\n\t}\n\n\tif ( ! maximumFontSizeRaw ) {\n\t\tmaximumFontSizeRaw =\n\t\t\tpreferredSize.value * DEFAULT_MAXIMUM_FONT_SIZE_FACTOR +\n\t\t\tpreferredSize.unit;\n\t}\n\n\tconst fluidFontSizeValue = getComputedFluidTypographyValue( {\n\t\tmaximumViewPortWidth: DEFAULT_MAXIMUM_VIEWPORT_WIDTH,\n\t\tminimumViewPortWidth: DEFAULT_MINIMUM_VIEWPORT_WIDTH,\n\t\tmaximumFontSize: maximumFontSizeRaw,\n\t\tminimumFontSize: minimumFontSizeRaw,\n\t\tscaleFactor: DEFAULT_SCALE_FACTOR,\n\t} );\n\n\tif ( !! fluidFontSizeValue ) {\n\t\treturn fluidFontSizeValue;\n\t}\n\n\treturn defaultSize;\n}\n\n/**\n * Internal implementation of clamp() based on available min/max viewport width, and min/max font sizes.\n *\n * @param {Object} args\n * @param {string} args.maximumViewPortWidth Maximum size up to which type will have fluidity.\n * @param {string} args.minimumViewPortWidth Minimum viewport size from which type will have fluidity.\n * @param {string} args.maximumFontSize Maximum font size for any clamp() calculation.\n * @param {string} args.minimumFontSize Minimum font size for any clamp() calculation.\n * @param {number} args.scaleFactor A scale factor to determine how fast a font scales within boundaries.\n *\n * @return {string|null} A font-size value using clamp().\n */\nexport function getComputedFluidTypographyValue( {\n\tmaximumViewPortWidth,\n\tminimumViewPortWidth,\n\tmaximumFontSize,\n\tminimumFontSize,\n\tscaleFactor,\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 *\n * @param {string} 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 ( ! rawValue ) {\n\t\treturn null;\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"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/global-styles/typography-utils.js"],"names":["getComputedFluidTypographyValue","getTypographyFontSizeValue","preset","typographySettings","size","defaultSize","fluid","fluidFontSizeValue","minimumFontSize","min","maximumFontSize","max","fontSize"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAASA,+BAAT,QAAgD,yBAAhD;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,0BAAT,CAAqCC,MAArC,EAA6CC,kBAA7C,EAAkE;AAAA;;AACxE,QAAM;AAAEC,IAAAA,IAAI,EAAEC;AAAR,MAAwBH,MAA9B;AAEA;AACD;AACA;AACA;;AACC,MAAK,CAAEG,WAAF,IAAiB,QAAQA,WAA9B,EAA4C;AAC3C,WAAOA,WAAP;AACA;;AAED,MAAK,UAASF,kBAAT,aAASA,kBAAT,uBAASA,kBAAkB,CAAEG,KAA7B,CAAL,EAA0C;AACzC,WAAOD,WAAP;AACA,GAbuE,CAexE;;;AACA,MAAK,WAAUH,MAAV,aAAUA,MAAV,uBAAUA,MAAM,CAAEI,KAAlB,CAAL,EAA+B;AAC9B,WAAOD,WAAP;AACA;;AAED,QAAME,kBAAkB,GAAGP,+BAA+B,CAAE;AAC3DQ,IAAAA,eAAe,EAAEN,MAAF,aAAEA,MAAF,wCAAEA,MAAM,CAAEI,KAAV,kDAAE,cAAeG,GAD2B;AAE3DC,IAAAA,eAAe,EAAER,MAAF,aAAEA,MAAF,yCAAEA,MAAM,CAAEI,KAAV,mDAAE,eAAeK,GAF2B;AAG3DC,IAAAA,QAAQ,EAAEP;AAHiD,GAAF,CAA1D;;AAMA,MAAK,CAAC,CAAEE,kBAAR,EAA6B;AAC5B,WAAOA,kBAAP;AACA;;AAED,SAAOF,WAAP;AACA","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 * WordPress dependencies\n */\nimport { getComputedFluidTypographyValue } from '@wordpress/block-editor';\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 A font size slug\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 * @param {Preset} preset\n * @param {Object} typographySettings\n * @param {boolean} typographySettings.fluid Whether fluid typography is enabled.\n *\n * @return {string|*} A font-size value or the value of preset.size.\n */\nexport function getTypographyFontSizeValue( preset, typographySettings ) {\n\tconst { size: defaultSize } = preset;\n\n\t/*\n\t * Catches falsy values and 0/'0'.\n\t * Fluid calculations cannot be performed on 0.\n\t */\n\tif ( ! defaultSize || '0' === defaultSize ) {\n\t\treturn defaultSize;\n\t}\n\n\tif ( true !== typographySettings?.fluid ) {\n\t\treturn defaultSize;\n\t}\n\n\t// A font size has explicitly bypassed fluid calculations.\n\tif ( false === preset?.fluid ) {\n\t\treturn defaultSize;\n\t}\n\n\tconst fluidFontSizeValue = getComputedFluidTypographyValue( {\n\t\tminimumFontSize: preset?.fluid?.min,\n\t\tmaximumFontSize: preset?.fluid?.max,\n\t\tfontSize: defaultSize,\n\t} );\n\n\tif ( !! fluidFontSizeValue ) {\n\t\treturn fluidFontSizeValue;\n\t}\n\n\treturn defaultSize;\n}\n"]}
@@ -18,6 +18,7 @@ import { __unstablePresetDuotoneFilter as PresetDuotoneFilter, __experimentalGet
18
18
  */
19
19
 
20
20
  import { PRESET_METADATA, ROOT_BLOCK_SELECTOR, scopeSelector } from './utils';
21
+ import { getTypographyFontSizeValue } from './typography-utils';
21
22
  import { GlobalStylesContext } from './context';
22
23
  import { useSetting } from './hooks'; // List of block support features that can have their related styles
23
24
  // generated under their own feature level selector rather than the block's.
@@ -245,6 +246,22 @@ export function getStylesDeclarations() {
245
246
  if (!ruleValue || !!((_ruleValue2 = ruleValue) !== null && _ruleValue2 !== void 0 && _ruleValue2.ref)) {
246
247
  return;
247
248
  }
249
+ } // Calculate fluid typography rules where available.
250
+
251
+
252
+ if (cssProperty === 'font-size') {
253
+ var _tree$settings;
254
+
255
+ /*
256
+ * getTypographyFontSizeValue() will check
257
+ * if fluid typography has been activated and also
258
+ * whether the incoming value can be converted to a fluid value.
259
+ * Values that already have a "clamp()" function will not pass the test,
260
+ * and therefore the original $value will be returned.
261
+ */
262
+ ruleValue = getTypographyFontSizeValue({
263
+ size: ruleValue
264
+ }, tree === null || tree === void 0 ? void 0 : (_tree$settings = tree.settings) === null || _tree$settings === void 0 ? void 0 : _tree$settings.typography);
248
265
  }
249
266
 
250
267
  output.push(`${cssProperty}: ${ruleValue}`);
@@ -266,7 +283,7 @@ export function getStylesDeclarations() {
266
283
  */
267
284
 
268
285
  export function getLayoutStyles(_ref6) {
269
- var _style$spacing, _tree$settings, _tree$settings$layout, _tree$settings2, _tree$settings2$layou;
286
+ var _style$spacing, _tree$settings2, _tree$settings2$layou, _tree$settings3, _tree$settings3$layou;
270
287
 
271
288
  let {
272
289
  tree,
@@ -288,7 +305,7 @@ export function getLayoutStyles(_ref6) {
288
305
  }
289
306
  }
290
307
 
291
- if (gapValue && tree !== null && tree !== void 0 && (_tree$settings = tree.settings) !== null && _tree$settings !== void 0 && (_tree$settings$layout = _tree$settings.layout) !== null && _tree$settings$layout !== void 0 && _tree$settings$layout.definitions) {
308
+ if (gapValue && tree !== null && tree !== void 0 && (_tree$settings2 = tree.settings) !== null && _tree$settings2 !== void 0 && (_tree$settings2$layou = _tree$settings2.layout) !== null && _tree$settings2$layou !== void 0 && _tree$settings2$layou.definitions) {
292
309
  Object.values(tree.settings.layout.definitions).forEach(_ref7 => {
293
310
  let {
294
311
  className,
@@ -334,7 +351,7 @@ export function getLayoutStyles(_ref6) {
334
351
  } // Output base styles
335
352
 
336
353
 
337
- if (selector === ROOT_BLOCK_SELECTOR && tree !== null && tree !== void 0 && (_tree$settings2 = tree.settings) !== null && _tree$settings2 !== void 0 && (_tree$settings2$layou = _tree$settings2.layout) !== null && _tree$settings2$layou !== void 0 && _tree$settings2$layou.definitions) {
354
+ if (selector === ROOT_BLOCK_SELECTOR && tree !== null && tree !== void 0 && (_tree$settings3 = tree.settings) !== null && _tree$settings3 !== void 0 && (_tree$settings3$layou = _tree$settings3.layout) !== null && _tree$settings3$layou !== void 0 && _tree$settings3$layou.definitions) {
338
355
  const validDisplayModes = ['block', 'flex', 'grid'];
339
356
  Object.values(tree.settings.layout.definitions).forEach(_ref9 => {
340
357
  let {
@@ -378,7 +395,7 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
378
395
  return nodes;
379
396
  }
380
397
 
381
- const pickStyleKeys = treeToPickFrom => pickBy(treeToPickFrom, (value, key) => ['border', 'color', 'spacing', 'typography', 'filter'].includes(key)); // Top-level.
398
+ const pickStyleKeys = treeToPickFrom => pickBy(treeToPickFrom, (value, key) => ['border', 'color', 'spacing', 'typography', 'filter', 'outline', 'shadow'].includes(key)); // Top-level.
382
399
 
383
400
 
384
401
  const styles = pickStyleKeys(tree.styles);
@@ -439,7 +456,7 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
439
456
  return nodes;
440
457
  };
441
458
  export const getNodesWithSettings = (tree, blockSelectors) => {
442
- var _tree$settings3, _tree$settings$blocks, _tree$settings4;
459
+ var _tree$settings4, _tree$settings$blocks, _tree$settings5;
443
460
 
444
461
  const nodes = [];
445
462
 
@@ -464,7 +481,7 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
464
481
 
465
482
 
466
483
  const presets = pickPresets(tree.settings);
467
- const custom = (_tree$settings3 = tree.settings) === null || _tree$settings3 === void 0 ? void 0 : _tree$settings3.custom;
484
+ const custom = (_tree$settings4 = tree.settings) === null || _tree$settings4 === void 0 ? void 0 : _tree$settings4.custom;
468
485
 
469
486
  if (!isEmpty(presets) || !!custom) {
470
487
  nodes.push({
@@ -475,7 +492,7 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
475
492
  } // Blocks.
476
493
 
477
494
 
478
- Object.entries((_tree$settings$blocks = (_tree$settings4 = tree.settings) === null || _tree$settings4 === void 0 ? void 0 : _tree$settings4.blocks) !== null && _tree$settings$blocks !== void 0 ? _tree$settings$blocks : {}).forEach(_ref15 => {
495
+ Object.entries((_tree$settings$blocks = (_tree$settings5 = tree.settings) === null || _tree$settings5 === void 0 ? void 0 : _tree$settings5.blocks) !== null && _tree$settings$blocks !== void 0 ? _tree$settings$blocks : {}).forEach(_ref15 => {
479
496
  let [blockName, node] = _ref15;
480
497
  const blockPresets = pickPresets(node);
481
498
  const blockCustom = node.custom;
@@ -513,16 +530,16 @@ export const toCustomProperties = (tree, blockSelectors) => {
513
530
  return ruleset;
514
531
  };
515
532
  export const toStyles = function (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport) {
516
- var _tree$settings5, _tree$settings6;
533
+ var _tree$settings6, _tree$settings7;
517
534
 
518
535
  let disableLayoutStyles = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
519
536
  const nodesWithStyles = getNodesWithStyles(tree, blockSelectors);
520
537
  const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
521
- const useRootPaddingAlign = tree === null || tree === void 0 ? void 0 : (_tree$settings5 = tree.settings) === null || _tree$settings5 === void 0 ? void 0 : _tree$settings5.useRootPaddingAwareAlignments;
538
+ const useRootPaddingAlign = tree === null || tree === void 0 ? void 0 : (_tree$settings6 = tree.settings) === null || _tree$settings6 === void 0 ? void 0 : _tree$settings6.useRootPaddingAwareAlignments;
522
539
  const {
523
540
  contentSize,
524
541
  wideSize
525
- } = (tree === null || tree === void 0 ? void 0 : (_tree$settings6 = tree.settings) === null || _tree$settings6 === void 0 ? void 0 : _tree$settings6.layout) || {};
542
+ } = (tree === null || tree === void 0 ? void 0 : (_tree$settings7 = tree.settings) === null || _tree$settings7 === void 0 ? void 0 : _tree$settings7.layout) || {};
526
543
  /*
527
544
  * Reset default browser margin on the root body element.
528
545
  * This is set on the root selector **before** generating the ruleset
@@ -543,12 +560,12 @@ export const toStyles = function (tree, blockSelectors, hasBlockGapSupport, hasF
543
560
  }
544
561
 
545
562
  if (useRootPaddingAlign) {
546
- ruleset += `padding-right: 0; padding-left: 0; padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom) }
547
- .has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }
548
- .has-global-padding :where(.has-global-padding) { padding-right: 0; padding-left: 0; }
549
- .has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); }
550
- .has-global-padding :where(.has-global-padding) > .alignfull { margin-right: 0; margin-left: 0; }
551
- .has-global-padding > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }
563
+ ruleset += `padding-right: 0; padding-left: 0; padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom) }
564
+ .has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }
565
+ .has-global-padding :where(.has-global-padding) { padding-right: 0; padding-left: 0; }
566
+ .has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); }
567
+ .has-global-padding :where(.has-global-padding) > .alignfull { margin-right: 0; margin-left: 0; }
568
+ .has-global-padding > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }
552
569
  .has-global-padding :where(.has-global-padding) > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: 0; padding-left: 0;`;
553
570
  }
554
571