@wordpress/edit-site 4.16.0 → 4.18.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.
- package/CHANGELOG.md +4 -0
- package/build/components/app/index.js +8 -3
- package/build/components/app/index.js.map +1 -1
- package/build/components/block-editor/block-inspector-button.js +1 -1
- package/build/components/block-editor/block-inspector-button.js.map +1 -1
- package/build/components/block-editor/index.js +17 -11
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/editor/index.js +14 -20
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/border-panel.js +2 -1
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/global-styles-provider.js +6 -5
- package/build/components/global-styles/global-styles-provider.js.map +1 -1
- package/build/components/global-styles/preview.js +84 -49
- package/build/components/global-styles/preview.js.map +1 -1
- package/build/components/global-styles/screen-style-variations.js +35 -4
- package/build/components/global-styles/screen-style-variations.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +16 -2
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/typography-utils.js +39 -176
- package/build/components/global-styles/typography-utils.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +27 -9
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/{header → header-edit-mode}/document-actions/index.js +58 -24
- package/build/components/header-edit-mode/document-actions/index.js.map +1 -0
- package/build/components/{header → header-edit-mode}/index.js +14 -55
- package/build/components/header-edit-mode/index.js.map +1 -0
- package/build/components/{header → header-edit-mode}/mode-switcher/index.js +0 -0
- package/build/components/header-edit-mode/mode-switcher/index.js.map +1 -0
- package/build/components/{header → header-edit-mode}/more-menu/copy-content-menu-item.js +0 -0
- package/build/components/header-edit-mode/more-menu/copy-content-menu-item.js.map +1 -0
- package/build/components/{header → header-edit-mode}/more-menu/index.js +0 -0
- package/build/components/header-edit-mode/more-menu/index.js.map +1 -0
- package/build/components/{header → header-edit-mode}/more-menu/site-export.js +0 -0
- package/build/components/header-edit-mode/more-menu/site-export.js.map +1 -0
- package/build/components/{header → header-edit-mode}/more-menu/welcome-guide-menu-item.js +0 -0
- package/build/components/header-edit-mode/more-menu/welcome-guide-menu-item.js.map +1 -0
- package/build/components/{header → header-edit-mode}/plugin-more-menu-item/index.js +0 -0
- package/build/components/header-edit-mode/plugin-more-menu-item/index.js.map +1 -0
- package/build/components/{header → header-edit-mode}/plugin-sidebar-more-menu-item/index.js +0 -0
- package/build/components/header-edit-mode/plugin-sidebar-more-menu-item/index.js.map +1 -0
- package/build/components/{header → header-edit-mode}/tools-more-menu-group/index.js +0 -0
- package/build/components/header-edit-mode/tools-more-menu-group/index.js.map +1 -0
- package/build/components/{header → header-edit-mode}/undo-redo/redo.js +0 -0
- package/build/components/header-edit-mode/undo-redo/redo.js.map +1 -0
- package/build/components/{header → header-edit-mode}/undo-redo/undo.js +0 -0
- package/build/components/header-edit-mode/undo-redo/undo.js.map +1 -0
- package/build/components/keyboard-shortcut-help-modal/shortcut.js +1 -7
- package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +6 -6
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/navigation-sidebar/navigation-panel/index.js +9 -8
- package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
- package/build/components/save-button/index.js +17 -13
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/{sidebar → sidebar-edit-mode}/constants.js +0 -0
- package/build/components/sidebar-edit-mode/constants.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/default-sidebar.js +0 -0
- package/build/components/sidebar-edit-mode/default-sidebar.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/global-styles-sidebar.js +0 -0
- package/build/components/sidebar-edit-mode/global-styles-sidebar.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/index.js +1 -1
- package/build/components/sidebar-edit-mode/index.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/index.js +0 -0
- package/build/components/sidebar-edit-mode/navigation-menu-sidebar/index.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-inspector.js +0 -0
- package/build/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-menu.js +0 -0
- package/build/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/plugin-sidebar/index.js +1 -1
- package/build/components/sidebar-edit-mode/plugin-sidebar/index.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/settings-header/index.js +2 -2
- package/build/components/sidebar-edit-mode/settings-header/index.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/template-card/index.js +0 -0
- package/build/components/sidebar-edit-mode/template-card/index.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/template-card/template-actions.js +0 -0
- package/build/components/sidebar-edit-mode/template-card/template-actions.js.map +1 -0
- package/build/components/{sidebar → sidebar-edit-mode}/template-card/template-areas.js +0 -0
- package/build/components/sidebar-edit-mode/template-card/template-areas.js.map +1 -0
- package/build/index.js +8 -13
- package/build/index.js.map +1 -1
- package/build/store/actions.js +15 -0
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +28 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +13 -0
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/app/index.js +8 -3
- package/build-module/components/app/index.js.map +1 -1
- package/build-module/components/block-editor/block-inspector-button.js +1 -1
- package/build-module/components/block-editor/block-inspector-button.js.map +1 -1
- package/build-module/components/block-editor/index.js +16 -10
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/editor/index.js +14 -20
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +2 -1
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/global-styles-provider.js +7 -6
- package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
- package/build-module/components/global-styles/preview.js +84 -49
- package/build-module/components/global-styles/preview.js.map +1 -1
- package/build-module/components/global-styles/screen-style-variations.js +36 -6
- package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +15 -2
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/typography-utils.js +37 -169
- package/build-module/components/global-styles/typography-utils.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +26 -9
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/{header → header-edit-mode}/document-actions/index.js +53 -24
- package/build-module/components/header-edit-mode/document-actions/index.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/index.js +14 -52
- package/build-module/components/header-edit-mode/index.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/mode-switcher/index.js +0 -0
- package/build-module/components/header-edit-mode/mode-switcher/index.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/more-menu/copy-content-menu-item.js +0 -0
- package/build-module/components/header-edit-mode/more-menu/copy-content-menu-item.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/more-menu/index.js +0 -0
- package/build-module/components/header-edit-mode/more-menu/index.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/more-menu/site-export.js +0 -0
- package/build-module/components/header-edit-mode/more-menu/site-export.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/more-menu/welcome-guide-menu-item.js +0 -0
- package/build-module/components/header-edit-mode/more-menu/welcome-guide-menu-item.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/plugin-more-menu-item/index.js +0 -0
- package/build-module/components/header-edit-mode/plugin-more-menu-item/index.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/plugin-sidebar-more-menu-item/index.js +0 -0
- package/build-module/components/header-edit-mode/plugin-sidebar-more-menu-item/index.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/tools-more-menu-group/index.js +0 -0
- package/build-module/components/header-edit-mode/tools-more-menu-group/index.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/undo-redo/redo.js +0 -0
- package/build-module/components/header-edit-mode/undo-redo/redo.js.map +1 -0
- package/build-module/components/{header → header-edit-mode}/undo-redo/undo.js +0 -0
- package/build-module/components/header-edit-mode/undo-redo/undo.js.map +1 -0
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +1 -6
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +6 -6
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/navigation-sidebar/navigation-panel/index.js +9 -7
- package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
- package/build-module/components/save-button/index.js +19 -15
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/{sidebar → sidebar-edit-mode}/constants.js +0 -0
- package/build-module/components/sidebar-edit-mode/constants.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/default-sidebar.js +0 -0
- package/build-module/components/sidebar-edit-mode/default-sidebar.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/global-styles-sidebar.js +0 -0
- package/build-module/components/sidebar-edit-mode/global-styles-sidebar.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/index.js +1 -1
- package/build-module/components/sidebar-edit-mode/index.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/index.js +0 -0
- package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/index.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-inspector.js +0 -0
- package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-menu.js +0 -0
- package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/plugin-sidebar/index.js +1 -1
- package/build-module/components/sidebar-edit-mode/plugin-sidebar/index.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/settings-header/index.js +2 -2
- package/build-module/components/sidebar-edit-mode/settings-header/index.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/template-card/index.js +0 -0
- package/build-module/components/sidebar-edit-mode/template-card/index.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/template-card/template-actions.js +0 -0
- package/build-module/components/sidebar-edit-mode/template-card/template-actions.js.map +1 -0
- package/build-module/components/{sidebar → sidebar-edit-mode}/template-card/template-areas.js +0 -0
- package/build-module/components/sidebar-edit-mode/template-card/template-areas.js.map +1 -0
- package/build-module/index.js +8 -6
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +13 -0
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +26 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +11 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +63 -86
- package/build-style/style.css +63 -86
- package/package.json +29 -29
- package/src/components/app/index.js +11 -2
- package/src/components/block-editor/block-inspector-button.js +1 -1
- package/src/components/block-editor/index.js +29 -11
- package/src/components/block-editor/style.scss +1 -0
- package/src/components/editor/index.js +18 -29
- package/src/components/global-styles/border-panel.js +1 -0
- package/src/components/global-styles/global-styles-provider.js +5 -6
- package/src/components/global-styles/preview.js +80 -59
- package/src/components/global-styles/screen-style-variations.js +39 -4
- package/src/components/global-styles/style.scss +1 -0
- package/src/components/global-styles/test/typography-utils.js +333 -103
- package/src/components/global-styles/test/use-global-styles-output.js +57 -3
- package/src/components/global-styles/typography-panel.js +15 -1
- package/src/components/global-styles/typography-utils.js +34 -195
- package/src/components/global-styles/use-global-styles-output.js +16 -0
- package/src/components/{header → header-edit-mode}/document-actions/index.js +67 -46
- package/src/components/{header → header-edit-mode}/document-actions/style.scss +0 -0
- package/src/components/{header → header-edit-mode}/index.js +14 -53
- package/src/components/{header → header-edit-mode}/mode-switcher/index.js +0 -0
- package/src/components/{header → header-edit-mode}/more-menu/copy-content-menu-item.js +0 -0
- package/src/components/{header → header-edit-mode}/more-menu/index.js +0 -0
- package/src/components/{header → header-edit-mode}/more-menu/site-export.js +0 -0
- package/src/components/{header → header-edit-mode}/more-menu/welcome-guide-menu-item.js +0 -0
- package/src/components/{header → header-edit-mode}/plugin-more-menu-item/index.js +0 -0
- package/src/components/{header → header-edit-mode}/plugin-sidebar-more-menu-item/index.js +0 -0
- package/src/components/{header → header-edit-mode}/style.scss +20 -50
- package/src/components/{header → header-edit-mode}/tools-more-menu-group/index.js +0 -0
- package/src/components/{header → header-edit-mode}/undo-redo/redo.js +0 -0
- package/src/components/{header → header-edit-mode}/undo-redo/undo.js +0 -0
- package/src/components/keyboard-shortcut-help-modal/shortcut.js +15 -18
- package/src/components/keyboard-shortcuts/index.js +4 -3
- package/src/components/navigation-sidebar/navigation-panel/index.js +30 -24
- package/src/components/navigation-sidebar/navigation-toggle/test/__snapshots__/index.js.snap +41 -0
- package/src/components/navigation-sidebar/navigation-toggle/test/index.js +10 -12
- package/src/components/save-button/index.js +14 -14
- package/src/components/{sidebar → sidebar-edit-mode}/constants.js +0 -0
- package/src/components/{sidebar → sidebar-edit-mode}/default-sidebar.js +0 -0
- package/src/components/{sidebar → sidebar-edit-mode}/global-styles-sidebar.js +0 -0
- package/src/components/{sidebar → sidebar-edit-mode}/index.js +1 -1
- package/src/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/index.js +0 -0
- package/src/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-inspector.js +0 -0
- package/src/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/navigation-menu.js +0 -0
- package/src/components/{sidebar → sidebar-edit-mode}/navigation-menu-sidebar/style.scss +0 -0
- package/src/components/{sidebar → sidebar-edit-mode}/plugin-sidebar/index.js +1 -1
- package/src/components/{sidebar → sidebar-edit-mode}/settings-header/index.js +2 -2
- package/src/components/{sidebar → sidebar-edit-mode}/settings-header/style.scss +2 -2
- package/src/components/{sidebar → sidebar-edit-mode}/style.scss +1 -1
- package/src/components/{sidebar → sidebar-edit-mode}/template-card/index.js +0 -0
- package/src/components/{sidebar → sidebar-edit-mode}/template-card/style.scss +0 -0
- package/src/components/{sidebar → sidebar-edit-mode}/template-card/template-actions.js +0 -0
- package/src/components/{sidebar → sidebar-edit-mode}/template-card/template-areas.js +0 -0
- package/src/index.js +13 -6
- package/src/store/actions.js +13 -0
- package/src/store/reducer.js +19 -0
- package/src/store/selectors.js +11 -0
- package/src/style.scss +6 -6
- package/build/components/header/document-actions/index.js.map +0 -1
- package/build/components/header/index.js.map +0 -1
- package/build/components/header/mode-switcher/index.js.map +0 -1
- package/build/components/header/more-menu/copy-content-menu-item.js.map +0 -1
- package/build/components/header/more-menu/index.js.map +0 -1
- package/build/components/header/more-menu/site-export.js.map +0 -1
- package/build/components/header/more-menu/welcome-guide-menu-item.js.map +0 -1
- package/build/components/header/plugin-more-menu-item/index.js.map +0 -1
- package/build/components/header/plugin-sidebar-more-menu-item/index.js.map +0 -1
- package/build/components/header/tools-more-menu-group/index.js.map +0 -1
- package/build/components/header/undo-redo/redo.js.map +0 -1
- package/build/components/header/undo-redo/undo.js.map +0 -1
- package/build/components/main-dashboard-button/index.js +0 -41
- package/build/components/main-dashboard-button/index.js.map +0 -1
- package/build/components/sidebar/constants.js.map +0 -1
- package/build/components/sidebar/default-sidebar.js.map +0 -1
- package/build/components/sidebar/global-styles-sidebar.js.map +0 -1
- package/build/components/sidebar/index.js.map +0 -1
- package/build/components/sidebar/navigation-menu-sidebar/index.js.map +0 -1
- package/build/components/sidebar/navigation-menu-sidebar/navigation-inspector.js.map +0 -1
- package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +0 -1
- package/build/components/sidebar/plugin-sidebar/index.js.map +0 -1
- package/build/components/sidebar/settings-header/index.js.map +0 -1
- package/build/components/sidebar/template-card/index.js.map +0 -1
- package/build/components/sidebar/template-card/template-actions.js.map +0 -1
- package/build/components/sidebar/template-card/template-areas.js.map +0 -1
- package/build-module/components/header/document-actions/index.js.map +0 -1
- package/build-module/components/header/index.js.map +0 -1
- package/build-module/components/header/mode-switcher/index.js.map +0 -1
- package/build-module/components/header/more-menu/copy-content-menu-item.js.map +0 -1
- package/build-module/components/header/more-menu/index.js.map +0 -1
- package/build-module/components/header/more-menu/site-export.js.map +0 -1
- package/build-module/components/header/more-menu/welcome-guide-menu-item.js.map +0 -1
- package/build-module/components/header/plugin-more-menu-item/index.js.map +0 -1
- package/build-module/components/header/plugin-sidebar-more-menu-item/index.js.map +0 -1
- package/build-module/components/header/tools-more-menu-group/index.js.map +0 -1
- package/build-module/components/header/undo-redo/redo.js.map +0 -1
- package/build-module/components/header/undo-redo/undo.js.map +0 -1
- package/build-module/components/main-dashboard-button/index.js +0 -32
- package/build-module/components/main-dashboard-button/index.js.map +0 -1
- package/build-module/components/sidebar/constants.js.map +0 -1
- package/build-module/components/sidebar/default-sidebar.js.map +0 -1
- package/build-module/components/sidebar/global-styles-sidebar.js.map +0 -1
- package/build-module/components/sidebar/index.js.map +0 -1
- package/build-module/components/sidebar/navigation-menu-sidebar/index.js.map +0 -1
- package/build-module/components/sidebar/navigation-menu-sidebar/navigation-inspector.js.map +0 -1
- package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +0 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js.map +0 -1
- package/build-module/components/sidebar/settings-header/index.js.map +0 -1
- package/build-module/components/sidebar/template-card/index.js.map +0 -1
- package/build-module/components/sidebar/template-card/template-actions.js.map +0 -1
- package/build-module/components/sidebar/template-card/template-areas.js.map +0 -1
- package/src/components/main-dashboard-button/index.js +0 -28
|
@@ -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 {
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
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}
|
|
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 (
|
|
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
|
-
|
|
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
|
-
} //
|
|
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 (
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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,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KAAJ,EAAWD,IAAX,IAAoB8B,OAAxB;AAEA,MAAIG,WAAW,GAAGC,UAAU,CAAEjC,KAAF,CAA5B;;AAEA,MAAK,SAASW,QAAT,KAAuB,SAASZ,IAAT,IAAiB,UAAUA,IAAlD,CAAL,EAAgE;AAC/DiC,IAAAA,WAAW,GAAGA,WAAW,GAAGT,aAA5B;AACAxB,IAAAA,IAAI,GAAGY,QAAP;AACA;;AAED,MAAK,SAASZ,IAAT,KAAmB,SAASY,QAAT,IAAqB,UAAUA,QAAlD,CAAL,EAAoE;AACnEqB,IAAAA,WAAW,GAAGA,WAAW,GAAGT,aAA5B;AACAxB,IAAAA,IAAI,GAAGY,QAAP;AACA;;AAED,SAAO;AACNX,IAAAA,KAAK,EAAEgC,WADD;AAENjC,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;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$
|
|
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$
|
|
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$
|
|
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 {
|
|
@@ -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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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
|