@wordpress/edit-site 5.28.5 → 5.30.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/actions/index.js +1 -1
- package/build/components/actions/index.js.map +1 -1
- package/build/components/block-editor/editor-canvas.js +10 -11
- package/build/components/block-editor/editor-canvas.js.map +1 -1
- package/build/components/block-editor/use-site-editor-settings.js +2 -1
- package/build/components/block-editor/use-site-editor-settings.js.map +1 -1
- package/build/components/code-editor/index.js +3 -2
- package/build/components/code-editor/index.js.map +1 -1
- package/build/components/editor/index.js +5 -19
- package/build/components/editor/index.js.map +1 -1
- package/build/components/editor-canvas-container/index.js +1 -1
- package/build/components/editor-canvas-container/index.js.map +1 -1
- package/build/components/global-styles/color-palette-panel.js +9 -0
- package/build/components/global-styles/color-palette-panel.js.map +1 -1
- package/build/components/global-styles/font-families.js +1 -1
- package/build/components/global-styles/font-families.js.map +1 -1
- package/build/components/global-styles/font-library-modal/collection-font-variant.js.map +1 -1
- package/build/components/global-styles/font-library-modal/context.js +11 -0
- package/build/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build/components/global-styles/font-library-modal/font-collection.js +5 -16
- package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
- package/build/components/global-styles/font-library-modal/index.js +2 -2
- package/build/components/global-styles/font-library-modal/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/installed-fonts.js +1 -1
- package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
- package/build/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
- package/build/components/global-styles/font-library-modal/utils/index.js +27 -0
- package/build/components/global-styles/font-library-modal/utils/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/utils/preview-styles.js +1 -1
- package/build/components/global-styles/font-library-modal/utils/preview-styles.js.map +1 -1
- package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
- package/build/components/global-styles/header.js +1 -1
- package/build/components/global-styles/header.js.map +1 -1
- package/build/components/global-styles/highlighted-colors.js +50 -0
- package/build/components/global-styles/highlighted-colors.js.map +1 -0
- package/build/components/global-styles/preview-colors.js +62 -0
- package/build/components/global-styles/preview-colors.js.map +1 -0
- package/build/components/global-styles/preview-iframe.js +131 -0
- package/build/components/global-styles/preview-iframe.js.map +1 -0
- package/build/components/global-styles/preview-styles.js +163 -0
- package/build/components/global-styles/preview-styles.js.map +1 -0
- package/build/components/global-styles/preview-typography.js +65 -0
- package/build/components/global-styles/preview-typography.js.map +1 -0
- package/build/components/global-styles/screen-block-list.js +1 -1
- package/build/components/global-styles/screen-block-list.js.map +1 -1
- package/build/components/global-styles/screen-block.js +1 -1
- package/build/components/global-styles/screen-block.js.map +1 -1
- package/build/components/global-styles/screen-colors.js +10 -2
- package/build/components/global-styles/screen-colors.js.map +1 -1
- package/build/components/global-styles/screen-root.js +2 -2
- package/build/components/global-styles/screen-root.js.map +1 -1
- package/build/components/global-styles/screen-typography.js +10 -2
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/global-styles/style-variations-container.js +12 -84
- package/build/components/global-styles/style-variations-container.js.map +1 -1
- package/build/components/global-styles/{typogrphy-elements.js → typography-elements.js} +1 -1
- package/build/components/global-styles/typography-elements.js.map +1 -0
- package/build/components/global-styles/utils.js +22 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/global-styles/variations/variation.js +90 -0
- package/build/components/global-styles/variations/variation.js.map +1 -0
- package/build/components/global-styles/variations/variations-color.js +36 -0
- package/build/components/global-styles/variations/variations-color.js.map +1 -0
- package/build/components/global-styles/{variations-panel.js → variations/variations-panel.js} +1 -1
- package/build/components/global-styles/variations/variations-panel.js.map +1 -0
- package/build/components/global-styles/variations/variations-typography.js +64 -0
- package/build/components/global-styles/variations/variations-typography.js.map +1 -0
- package/build/components/header-edit-mode/document-tools/index.js +1 -2
- package/build/components/header-edit-mode/document-tools/index.js.map +1 -1
- package/build/components/header-edit-mode/index.js +16 -13
- package/build/components/header-edit-mode/index.js.map +1 -1
- package/build/components/header-edit-mode/more-menu/index.js +17 -6
- package/build/components/header-edit-mode/more-menu/index.js.map +1 -1
- package/build/components/keyboard-shortcuts/edit-mode.js +0 -13
- package/build/components/keyboard-shortcuts/edit-mode.js.map +1 -1
- package/build/components/keyboard-shortcuts/register.js +0 -18
- package/build/components/keyboard-shortcuts/register.js.map +1 -1
- package/build/components/layout/index.js +4 -2
- package/build/components/layout/index.js.map +1 -1
- package/build/components/page-patterns/dataviews-pattern-actions.js +25 -8
- package/build/components/page-patterns/dataviews-pattern-actions.js.map +1 -1
- package/build/components/page-patterns/header.js +2 -1
- package/build/components/page-patterns/header.js.map +1 -1
- package/build/components/page-patterns/index.js +0 -1
- package/build/components/page-patterns/index.js.map +1 -1
- package/build/components/{list/added-by.js → page-templates-template-parts/hooks.js} +1 -61
- package/build/components/page-templates-template-parts/hooks.js.map +1 -0
- package/build/components/page-templates-template-parts/index.js +14 -6
- package/build/components/page-templates-template-parts/index.js.map +1 -1
- package/build/components/revisions/index.js.map +1 -1
- package/build/components/save-button/index.js +2 -1
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/save-panel/index.js +18 -3
- package/build/components/save-panel/index.js.map +1 -1
- package/build/components/sidebar/index.js +1 -1
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar-edit-mode/global-styles-sidebar.js +5 -5
- package/build/components/sidebar-edit-mode/global-styles-sidebar.js.map +1 -1
- package/build/components/sidebar-edit-mode/page-panels/page-status.js.map +1 -1
- package/build/components/sidebar-edit-mode/template-panel/hooks.js +20 -5
- package/build/components/sidebar-edit-mode/template-panel/hooks.js.map +1 -1
- package/build/components/sidebar-edit-mode/template-panel/index.js +48 -5
- package/build/components/sidebar-edit-mode/template-panel/index.js.map +1 -1
- package/build/components/sidebar-edit-mode/template-panel/template-actions.js +2 -9
- package/build/components/sidebar-edit-mode/template-panel/template-actions.js.map +1 -1
- package/build/components/sidebar-navigation-screen-global-styles/index.js +6 -2
- package/build/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-main/index.js +1 -2
- package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/delete-modal.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +0 -3
- package/build/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pattern/use-pattern-details.js +2 -2
- package/build/components/sidebar-navigation-screen-pattern/use-pattern-details.js.map +1 -1
- package/build/components/sidebar-navigation-screen-template/index.js +2 -2
- package/build/components/sidebar-navigation-screen-template/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates-browse/content.js +2 -2
- package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
- package/build/components/start-template-options/index.js.map +1 -1
- package/build/hooks/commands/use-edit-mode-commands.js +3 -171
- package/build/hooks/commands/use-edit-mode-commands.js.map +1 -1
- package/build/hooks/index.js +0 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/push-changes-to-global-styles/index.js +4 -5
- package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +156 -0
- package/build/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js.map +1 -0
- package/build/store/actions.js +19 -50
- package/build/store/actions.js.map +1 -1
- package/build/utils/clone-deep.js +15 -0
- package/build/utils/clone-deep.js.map +1 -0
- package/build-module/components/actions/index.js +1 -1
- package/build-module/components/actions/index.js.map +1 -1
- package/build-module/components/block-editor/editor-canvas.js +10 -11
- package/build-module/components/block-editor/editor-canvas.js.map +1 -1
- package/build-module/components/block-editor/use-site-editor-settings.js +2 -1
- package/build-module/components/block-editor/use-site-editor-settings.js.map +1 -1
- package/build-module/components/code-editor/index.js +3 -2
- package/build-module/components/code-editor/index.js.map +1 -1
- package/build-module/components/editor/index.js +6 -20
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/editor-canvas-container/index.js +2 -2
- package/build-module/components/editor-canvas-container/index.js.map +1 -1
- package/build-module/components/global-styles/color-palette-panel.js +8 -0
- package/build-module/components/global-styles/color-palette-panel.js.map +1 -1
- package/build-module/components/global-styles/font-families.js +1 -1
- package/build-module/components/global-styles/font-families.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/collection-font-variant.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/context.js +12 -1
- package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/font-collection.js +7 -18
- package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/index.js +2 -2
- package/build-module/components/global-styles/font-library-modal/index.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/installed-fonts.js +1 -1
- package/build-module/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/utils/index.js +26 -0
- package/build-module/components/global-styles/font-library-modal/utils/index.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/utils/preview-styles.js +1 -1
- package/build-module/components/global-styles/font-library-modal/utils/preview-styles.js.map +1 -1
- package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
- package/build-module/components/global-styles/header.js +1 -1
- package/build-module/components/global-styles/header.js.map +1 -1
- package/build-module/components/global-styles/highlighted-colors.js +43 -0
- package/build-module/components/global-styles/highlighted-colors.js.map +1 -0
- package/build-module/components/global-styles/preview-colors.js +54 -0
- package/build-module/components/global-styles/preview-colors.js.map +1 -0
- package/build-module/components/global-styles/preview-iframe.js +124 -0
- package/build-module/components/global-styles/preview-iframe.js.map +1 -0
- package/build-module/components/global-styles/preview-styles.js +155 -0
- package/build-module/components/global-styles/preview-styles.js.map +1 -0
- package/build-module/components/global-styles/preview-typography.js +58 -0
- package/build-module/components/global-styles/preview-typography.js.map +1 -0
- package/build-module/components/global-styles/screen-block-list.js +1 -1
- package/build-module/components/global-styles/screen-block-list.js.map +1 -1
- package/build-module/components/global-styles/screen-block.js +1 -1
- package/build-module/components/global-styles/screen-block.js.map +1 -1
- package/build-module/components/global-styles/screen-colors.js +10 -2
- package/build-module/components/global-styles/screen-colors.js.map +1 -1
- package/build-module/components/global-styles/screen-root.js +2 -2
- package/build-module/components/global-styles/screen-root.js.map +1 -1
- package/build-module/components/global-styles/screen-typography.js +10 -2
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/global-styles/style-variations-container.js +13 -85
- package/build-module/components/global-styles/style-variations-container.js.map +1 -1
- package/build-module/components/global-styles/{typogrphy-elements.js → typography-elements.js} +1 -1
- package/build-module/components/global-styles/typography-elements.js.map +1 -0
- package/build-module/components/global-styles/utils.js +21 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/global-styles/variations/variation.js +82 -0
- package/build-module/components/global-styles/variations/variation.js.map +1 -0
- package/build-module/components/global-styles/variations/variations-color.js +28 -0
- package/build-module/components/global-styles/variations/variations-color.js.map +1 -0
- package/build-module/components/global-styles/{variations-panel.js → variations/variations-panel.js} +1 -1
- package/build-module/components/global-styles/variations/variations-panel.js.map +1 -0
- package/build-module/components/global-styles/variations/variations-typography.js +56 -0
- package/build-module/components/global-styles/variations/variations-typography.js.map +1 -0
- package/build-module/components/header-edit-mode/document-tools/index.js +1 -2
- package/build-module/components/header-edit-mode/document-tools/index.js.map +1 -1
- package/build-module/components/header-edit-mode/index.js +17 -14
- package/build-module/components/header-edit-mode/index.js.map +1 -1
- package/build-module/components/header-edit-mode/more-menu/index.js +19 -8
- package/build-module/components/header-edit-mode/more-menu/index.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/edit-mode.js +0 -13
- package/build-module/components/keyboard-shortcuts/edit-mode.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/register.js +0 -18
- package/build-module/components/keyboard-shortcuts/register.js.map +1 -1
- package/build-module/components/layout/index.js +5 -3
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/page-patterns/dataviews-pattern-actions.js +25 -8
- package/build-module/components/page-patterns/dataviews-pattern-actions.js.map +1 -1
- package/build-module/components/page-patterns/header.js +2 -1
- package/build-module/components/page-patterns/header.js.map +1 -1
- package/build-module/components/page-patterns/index.js +0 -1
- package/build-module/components/page-patterns/index.js.map +1 -1
- package/build-module/components/{list/added-by.js → page-templates-template-parts/hooks.js} +2 -59
- package/build-module/components/page-templates-template-parts/hooks.js.map +1 -0
- package/build-module/components/page-templates-template-parts/index.js +13 -5
- package/build-module/components/page-templates-template-parts/index.js.map +1 -1
- package/build-module/components/revisions/index.js.map +1 -1
- package/build-module/components/save-button/index.js +2 -1
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/save-panel/index.js +18 -3
- package/build-module/components/save-panel/index.js.map +1 -1
- package/build-module/components/sidebar/index.js +1 -1
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/global-styles-sidebar.js +5 -5
- package/build-module/components/sidebar-edit-mode/global-styles-sidebar.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/page-panels/page-status.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/template-panel/hooks.js +20 -5
- package/build-module/components/sidebar-edit-mode/template-panel/hooks.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/template-panel/index.js +50 -7
- package/build-module/components/sidebar-edit-mode/template-panel/index.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/template-panel/template-actions.js +2 -9
- package/build-module/components/sidebar-edit-mode/template-panel/template-actions.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-global-styles/index.js +6 -2
- package/build-module/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-main/index.js +1 -2
- package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/delete-modal.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +0 -3
- package/build-module/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/use-pattern-details.js +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/use-pattern-details.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-template/index.js +1 -1
- package/build-module/components/sidebar-navigation-screen-template/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
- package/build-module/components/start-template-options/index.js.map +1 -1
- package/build-module/hooks/commands/use-edit-mode-commands.js +4 -172
- package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -1
- package/build-module/hooks/index.js +0 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/push-changes-to-global-styles/index.js +1 -3
- package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build-module/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +144 -0
- package/build-module/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js.map +1 -0
- package/build-module/store/actions.js +19 -50
- package/build-module/store/actions.js.map +1 -1
- package/build-module/utils/clone-deep.js +9 -0
- package/build-module/utils/clone-deep.js.map +1 -0
- package/build-style/style-rtl.css +152 -472
- package/build-style/style.css +152 -472
- package/package.json +43 -42
- package/src/components/actions/index.js +1 -1
- package/src/components/block-editor/editor-canvas.js +13 -12
- package/src/components/block-editor/style.scss +0 -3
- package/src/components/block-editor/use-site-editor-settings.js +1 -0
- package/src/components/code-editor/index.js +3 -2
- package/src/components/editor/index.js +10 -27
- package/src/components/editor-canvas-container/index.js +2 -5
- package/src/components/{test → error-boundary/test}/error-boundary.js +7 -5
- package/src/components/global-styles/color-palette-panel.js +11 -1
- package/src/components/global-styles/font-families.js +1 -1
- package/src/components/global-styles/font-library-modal/collection-font-variant.js +1 -1
- package/src/components/global-styles/font-library-modal/context.js +24 -0
- package/src/components/global-styles/font-library-modal/font-collection.js +7 -24
- package/src/components/global-styles/font-library-modal/index.js +2 -2
- package/src/components/global-styles/font-library-modal/installed-fonts.js +1 -1
- package/src/components/global-styles/font-library-modal/library-font-variant.js +1 -1
- package/src/components/global-styles/font-library-modal/upload-fonts.js +1 -1
- package/src/components/global-styles/font-library-modal/utils/index.js +34 -0
- package/src/components/global-styles/font-library-modal/utils/preview-styles.js +2 -1
- package/src/components/global-styles/gradients-palette-panel.js +2 -2
- package/src/components/global-styles/header.js +1 -1
- package/src/components/global-styles/highlighted-colors.js +39 -0
- package/src/components/global-styles/preview-colors.js +61 -0
- package/src/components/global-styles/preview-iframe.js +153 -0
- package/src/components/global-styles/preview-styles.js +185 -0
- package/src/components/global-styles/preview-typography.js +62 -0
- package/src/components/global-styles/screen-block-list.js +1 -1
- package/src/components/global-styles/screen-block.js +4 -1
- package/src/components/global-styles/screen-colors.js +13 -1
- package/src/components/global-styles/screen-revisions/style.scss +2 -2
- package/src/components/global-styles/screen-root.js +2 -2
- package/src/components/global-styles/screen-typography.js +19 -2
- package/src/components/global-styles/style-variations-container.js +14 -92
- package/src/components/global-styles/style.scss +1 -35
- package/src/components/global-styles/utils.js +37 -0
- package/src/components/global-styles/variations/style.scss +44 -0
- package/src/components/global-styles/variations/variation.js +93 -0
- package/src/components/global-styles/variations/variations-color.js +30 -0
- package/src/components/global-styles/{variations-panel.js → variations/variations-panel.js} +1 -1
- package/src/components/global-styles/variations/variations-typography.js +85 -0
- package/src/components/header-edit-mode/document-tools/index.js +1 -2
- package/src/components/header-edit-mode/index.js +22 -31
- package/src/components/header-edit-mode/more-menu/index.js +25 -11
- package/src/components/header-edit-mode/style.scss +4 -0
- package/src/components/keyboard-shortcuts/edit-mode.js +0 -11
- package/src/components/keyboard-shortcuts/register.js +0 -19
- package/src/components/layout/index.js +5 -2
- package/src/components/page-patterns/dataviews-pattern-actions.js +41 -10
- package/src/components/page-patterns/header.js +1 -0
- package/src/components/page-patterns/index.js +1 -2
- package/src/components/page-patterns/style.scss +0 -182
- package/src/components/{list/added-by.js → page-templates-template-parts/hooks.js} +1 -66
- package/src/components/page-templates-template-parts/index.js +20 -3
- package/src/components/page-templates-template-parts/style.scss +48 -0
- package/src/components/revisions/index.js +1 -1
- package/src/components/save-button/index.js +2 -1
- package/src/components/save-hub/style.scss +1 -1
- package/src/components/save-panel/index.js +34 -12
- package/src/components/sidebar/index.js +1 -1
- package/src/components/sidebar-button/style.scss +1 -1
- package/src/components/sidebar-edit-mode/global-styles-sidebar.js +5 -7
- package/src/components/sidebar-edit-mode/page-panels/page-status.js +1 -1
- package/src/components/sidebar-edit-mode/style.scss +4 -0
- package/src/components/sidebar-edit-mode/template-panel/hooks.js +37 -24
- package/src/components/sidebar-edit-mode/template-panel/index.js +76 -18
- package/src/components/sidebar-edit-mode/template-panel/style.scss +5 -14
- package/src/components/sidebar-edit-mode/template-panel/template-actions.js +1 -12
- package/src/components/sidebar-navigation-screen-global-styles/index.js +4 -1
- package/src/components/sidebar-navigation-screen-main/index.js +0 -2
- package/src/components/sidebar-navigation-screen-navigation-menu/delete-modal.js +1 -1
- package/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +0 -2
- package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +1 -1
- package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js +1 -1
- package/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js +1 -1
- package/src/components/sidebar-navigation-screen-template/index.js +1 -1
- package/src/components/sidebar-navigation-screen-templates-browse/content.js +1 -1
- package/src/components/start-template-options/index.js +1 -1
- package/src/hooks/commands/use-edit-mode-commands.js +3 -184
- package/src/hooks/index.js +0 -1
- package/src/hooks/push-changes-to-global-styles/index.js +1 -4
- package/src/hooks/use-theme-style-variations/test/use-theme-style-variations-by-property.js +1137 -0
- package/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +159 -0
- package/src/store/actions.js +21 -85
- package/src/store/test/actions.js +0 -75
- package/src/style.scss +3 -8
- package/src/utils/clone-deep.js +8 -0
- package/build/components/global-styles/preview.js +0 -271
- package/build/components/global-styles/preview.js.map +0 -1
- package/build/components/global-styles/typogrphy-elements.js.map +0 -1
- package/build/components/global-styles/variations-panel.js.map +0 -1
- package/build/components/header-edit-mode/mode-switcher/index.js +0 -62
- package/build/components/header-edit-mode/mode-switcher/index.js.map +0 -1
- package/build/components/list/added-by.js.map +0 -1
- package/build/components/list/header.js +0 -55
- package/build/components/list/header.js.map +0 -1
- package/build/components/list/index.js +0 -80
- package/build/components/list/index.js.map +0 -1
- package/build/components/list/table.js +0 -94
- package/build/components/list/table.js.map +0 -1
- package/build/components/list/use-register-shortcuts.js +0 -51
- package/build/components/list/use-register-shortcuts.js.map +0 -1
- package/build/components/page-patterns/duplicate-menu-item.js +0 -93
- package/build/components/page-patterns/duplicate-menu-item.js.map +0 -1
- package/build/components/page-patterns/grid-item.js +0 -223
- package/build/components/page-patterns/grid-item.js.map +0 -1
- package/build/components/page-patterns/grid.js +0 -31
- package/build/components/page-patterns/grid.js.map +0 -1
- package/build/components/page-patterns/no-patterns.js +0 -18
- package/build/components/page-patterns/no-patterns.js.map +0 -1
- package/build/components/page-patterns/patterns-list.js +0 -168
- package/build/components/page-patterns/patterns-list.js.map +0 -1
- package/build/components/page-patterns/rename-menu-item.js +0 -105
- package/build/components/page-patterns/rename-menu-item.js.map +0 -1
- package/build/components/sidebar-edit-mode/template-panel/replace-template-button.js +0 -83
- package/build/components/sidebar-edit-mode/template-panel/replace-template-button.js.map +0 -1
- package/build/components/sidebar-navigation-screen-main/template-part-hint.js +0 -36
- package/build/components/sidebar-navigation-screen-main/template-part-hint.js.map +0 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/edit-button.js +0 -36
- package/build/components/sidebar-navigation-screen-navigation-menu/edit-button.js.map +0 -1
- package/build/hooks/navigation-menu-edit.js +0 -82
- package/build/hooks/navigation-menu-edit.js.map +0 -1
- package/build-module/components/global-styles/preview.js +0 -264
- package/build-module/components/global-styles/preview.js.map +0 -1
- package/build-module/components/global-styles/typogrphy-elements.js.map +0 -1
- package/build-module/components/global-styles/variations-panel.js.map +0 -1
- package/build-module/components/header-edit-mode/mode-switcher/index.js +0 -56
- package/build-module/components/header-edit-mode/mode-switcher/index.js.map +0 -1
- package/build-module/components/list/added-by.js.map +0 -1
- package/build-module/components/list/header.js +0 -47
- package/build-module/components/list/header.js.map +0 -1
- package/build-module/components/list/index.js +0 -72
- package/build-module/components/list/index.js.map +0 -1
- package/build-module/components/list/table.js +0 -86
- package/build-module/components/list/table.js.map +0 -1
- package/build-module/components/list/use-register-shortcuts.js +0 -45
- package/build-module/components/list/use-register-shortcuts.js.map +0 -1
- package/build-module/components/page-patterns/duplicate-menu-item.js +0 -85
- package/build-module/components/page-patterns/duplicate-menu-item.js.map +0 -1
- package/build-module/components/page-patterns/grid-item.js +0 -215
- package/build-module/components/page-patterns/grid-item.js.map +0 -1
- package/build-module/components/page-patterns/grid.js +0 -23
- package/build-module/components/page-patterns/grid.js.map +0 -1
- package/build-module/components/page-patterns/no-patterns.js +0 -11
- package/build-module/components/page-patterns/no-patterns.js.map +0 -1
- package/build-module/components/page-patterns/patterns-list.js +0 -160
- package/build-module/components/page-patterns/patterns-list.js.map +0 -1
- package/build-module/components/page-patterns/rename-menu-item.js +0 -98
- package/build-module/components/page-patterns/rename-menu-item.js.map +0 -1
- package/build-module/components/sidebar-edit-mode/template-panel/replace-template-button.js +0 -76
- package/build-module/components/sidebar-edit-mode/template-panel/replace-template-button.js.map +0 -1
- package/build-module/components/sidebar-navigation-screen-main/template-part-hint.js +0 -29
- package/build-module/components/sidebar-navigation-screen-main/template-part-hint.js.map +0 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/edit-button.js +0 -27
- package/build-module/components/sidebar-navigation-screen-navigation-menu/edit-button.js.map +0 -1
- package/build-module/hooks/navigation-menu-edit.js +0 -75
- package/build-module/hooks/navigation-menu-edit.js.map +0 -1
- package/src/components/global-styles/preview.js +0 -327
- package/src/components/header-edit-mode/mode-switcher/index.js +0 -60
- package/src/components/list/header.js +0 -48
- package/src/components/list/index.js +0 -87
- package/src/components/list/style.scss +0 -188
- package/src/components/list/table.js +0 -140
- package/src/components/list/use-register-shortcuts.js +0 -49
- package/src/components/page-patterns/duplicate-menu-item.js +0 -105
- package/src/components/page-patterns/grid-item.js +0 -331
- package/src/components/page-patterns/grid.js +0 -22
- package/src/components/page-patterns/no-patterns.js +0 -12
- package/src/components/page-patterns/patterns-list.js +0 -229
- package/src/components/page-patterns/rename-menu-item.js +0 -132
- package/src/components/sidebar-edit-mode/template-panel/replace-template-button.js +0 -89
- package/src/components/sidebar-navigation-screen-main/template-part-hint.js +0 -34
- package/src/components/sidebar-navigation-screen-navigation-menu/edit-button.js +0 -22
- package/src/hooks/navigation-menu-edit.js +0 -92
- /package/src/components/global-styles/{typogrphy-elements.js → typography-elements.js} +0 -0
package/build-module/components/global-styles/font-library-modal/library-font-variant.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useContext","CheckboxControl","Flex","privateApis","componentsPrivateApis","getFontFaceVariantName","FontLibraryContext","FontDemo","unlock","LibraryFontVariant","face","font","isFontActivated","toggleActivateFont","isInstalled","fontFace","length","slug","fontStyle","fontWeight","source","handleToggleActivation","displayName","name","kebabCase","checkboxId","createElement","className","justify","align","gap","checked","onChange","__nextHasNoMarginBottom","id","htmlFor","text","onClick"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/library-font-variant.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\nimport {\n\tCheckboxControl,\n\tFlex,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { getFontFaceVariantName } from './utils';\nimport { FontLibraryContext } from './context';\nimport FontDemo from './font-demo';\nimport { unlock } from '../../../lock-unlock';\n\nfunction LibraryFontVariant( { face, font } ) {\n\tconst { isFontActivated, toggleActivateFont } =\n\t\tuseContext( FontLibraryContext );\n\n\tconst isInstalled =\n\t\tfont?.fontFace?.length > 0\n\t\t\t? isFontActivated(\n\t\t\t\t\tfont.slug,\n\t\t\t\t\tface.fontStyle,\n\t\t\t\t\tface.fontWeight,\n\t\t\t\t\tfont.source\n\t\t\t )\n\t\t\t: isFontActivated( font.slug, null, null, font.source );\n\n\tconst handleToggleActivation = () => {\n\t\tif ( font?.fontFace?.length > 0 ) {\n\t\t\ttoggleActivateFont( font, face );\n\t\t\treturn;\n\t\t}\n\t\ttoggleActivateFont( font );\n\t};\n\n\tconst displayName = font.name + ' ' + getFontFaceVariantName( face );\n\tconst { kebabCase } = unlock( componentsPrivateApis );\n\tconst checkboxId = kebabCase(\n\t\t`${ font.slug }-${ getFontFaceVariantName( face ) }`\n\t);\n\n\treturn (\n\t\t<div className=\"font-library-modal__font-card\">\n\t\t\t<Flex justify=\"flex-start\" align=\"center\" gap=\"1rem\">\n\t\t\t\t<CheckboxControl\n\t\t\t\t\tchecked={ isInstalled }\n\t\t\t\t\tonChange={ handleToggleActivation }\n\t\t\t\t\t__nextHasNoMarginBottom
|
|
1
|
+
{"version":3,"names":["useContext","CheckboxControl","Flex","privateApis","componentsPrivateApis","getFontFaceVariantName","FontLibraryContext","FontDemo","unlock","LibraryFontVariant","face","font","isFontActivated","toggleActivateFont","isInstalled","fontFace","length","slug","fontStyle","fontWeight","source","handleToggleActivation","displayName","name","kebabCase","checkboxId","createElement","className","justify","align","gap","checked","onChange","__nextHasNoMarginBottom","id","htmlFor","text","onClick"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/library-font-variant.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\nimport {\n\tCheckboxControl,\n\tFlex,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { getFontFaceVariantName } from './utils';\nimport { FontLibraryContext } from './context';\nimport FontDemo from './font-demo';\nimport { unlock } from '../../../lock-unlock';\n\nfunction LibraryFontVariant( { face, font } ) {\n\tconst { isFontActivated, toggleActivateFont } =\n\t\tuseContext( FontLibraryContext );\n\n\tconst isInstalled =\n\t\tfont?.fontFace?.length > 0\n\t\t\t? isFontActivated(\n\t\t\t\t\tfont.slug,\n\t\t\t\t\tface.fontStyle,\n\t\t\t\t\tface.fontWeight,\n\t\t\t\t\tfont.source\n\t\t\t )\n\t\t\t: isFontActivated( font.slug, null, null, font.source );\n\n\tconst handleToggleActivation = () => {\n\t\tif ( font?.fontFace?.length > 0 ) {\n\t\t\ttoggleActivateFont( font, face );\n\t\t\treturn;\n\t\t}\n\t\ttoggleActivateFont( font );\n\t};\n\n\tconst displayName = font.name + ' ' + getFontFaceVariantName( face );\n\tconst { kebabCase } = unlock( componentsPrivateApis );\n\tconst checkboxId = kebabCase(\n\t\t`${ font.slug }-${ getFontFaceVariantName( face ) }`\n\t);\n\n\treturn (\n\t\t<div className=\"font-library-modal__font-card\">\n\t\t\t<Flex justify=\"flex-start\" align=\"center\" gap=\"1rem\">\n\t\t\t\t<CheckboxControl\n\t\t\t\t\tchecked={ isInstalled }\n\t\t\t\t\tonChange={ handleToggleActivation }\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tid={ checkboxId }\n\t\t\t\t/>\n\t\t\t\t<label htmlFor={ checkboxId }>\n\t\t\t\t\t<FontDemo\n\t\t\t\t\t\tfont={ face }\n\t\t\t\t\t\ttext={ displayName }\n\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GAAGD,SAAS,CAC1B,GAAGb,IAAI,CAACM,IAAM,IAAIZ,sBAAsB,CAAEK,IAAK,CAAG,EACpD,CAAC;EAED,OACCgB,aAAA;IAAKC,SAAS,EAAC;EAA+B,GAC7CD,aAAA,CAACxB,IAAI;IAAC0B,OAAO,EAAC,YAAY;IAACC,KAAK,EAAC,QAAQ;IAACC,GAAG,EAAC;EAAM,GACnDJ,aAAA,CAACzB,eAAe;IACf8B,OAAO,EAAGjB,WAAa;IACvBkB,QAAQ,EAAGX,sBAAwB;IACnCY,uBAAuB;IACvBC,EAAE,EAAGT;EAAY,CACjB,CAAC,EACFC,aAAA;IAAOS,OAAO,EAAGV;EAAY,GAC5BC,aAAA,CAACnB,QAAQ;IACRI,IAAI,EAAGD,IAAM;IACb0B,IAAI,EAAGd,WAAa;IACpBe,OAAO,EAAGhB;EAAwB,CAClC,CACK,CACF,CACF,CAAC;AAER;AAEA,eAAeZ,kBAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","__experimentalSpacer","Spacer","__experimentalText","Text","__experimentalVStack","VStack","Button","DropZone","Notice","FormFileUpload","FlexItem","privateApis","componentsPrivateApis","useContext","useState","ALLOWED_FILE_EXTENSIONS","FontLibraryContext","Font","makeFamiliesFromFaces","loadFontFaceInBrowser","unlock","ProgressBar","UploadFonts","installFonts","notice","setNotice","isUploading","setIsUploading","handleDropZone","files","handleFilesUpload","onFilesUpload","event","target","uniqueFilenames","Set","selectedFiles","allowedFiles","filter","file","has","name","fileExtension","split","pop","toLowerCase","includes","add","length","loadFiles","type","message","fontFacesLoaded","Promise","all","map","fontFile","fontFaceData","getFontFaceMetadata","handleInstall","readFileAsArrayBuffer","resolve","reject","reader","window","FileReader","readAsArrayBuffer","onload","result","onerror","buffer","fontObj","fromDataBuffer","onloadEvent","font","detail","opentype","tables","fontName","get","isItalic","fontWeight","usWeightClass","isVariable","fvar","weightAxis","axes","find","tag","weightRange","minValue","maxValue","fontFamily","fontStyle","fontFaces","fontFamilies","error","createElement","className","onFilesDrop","status","onRemove","accept","ext","join","multiple","onChange","render","openFileDialog","onClick","margin"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/upload-fonts.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\t__experimentalSpacer as Spacer,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n\tButton,\n\tDropZone,\n\tNotice,\n\tFormFileUpload,\n\tFlexItem,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useContext, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ALLOWED_FILE_EXTENSIONS } from './utils/constants';\nimport { FontLibraryContext } from './context';\nimport { Font } from '../../../../lib/lib-font.browser';\nimport makeFamiliesFromFaces from './utils/make-families-from-faces';\nimport { loadFontFaceInBrowser } from './utils';\nimport { unlock } from '../../../lock-unlock';\n\nconst { ProgressBar } = unlock( componentsPrivateApis );\n\nfunction UploadFonts() {\n\tconst { installFonts, notice, setNotice } =\n\t\tuseContext( FontLibraryContext );\n\tconst [ isUploading, setIsUploading ] = useState( false );\n\n\tconst handleDropZone = ( files ) => {\n\t\thandleFilesUpload( files );\n\t};\n\tconst onFilesUpload = ( event ) => {\n\t\thandleFilesUpload( event.target.files );\n\t};\n\n\t/**\n\t * Filters the selected files to only allow the ones with the allowed extensions\n\t *\n\t * @param {Array} files The files to be filtered\n\t * @return {void}\n\t */\n\tconst handleFilesUpload = ( files ) => {\n\t\tsetNotice( null );\n\t\tsetIsUploading( true );\n\t\tconst uniqueFilenames = new Set();\n\t\tconst selectedFiles = [ ...files ];\n\t\tconst allowedFiles = selectedFiles.filter( ( file ) => {\n\t\t\tif ( uniqueFilenames.has( file.name ) ) {\n\t\t\t\treturn false; // Discard duplicates\n\t\t\t}\n\t\t\t// Eliminates files that are not allowed\n\t\t\tconst fileExtension = file.name.split( '.' ).pop().toLowerCase();\n\t\t\tif ( ALLOWED_FILE_EXTENSIONS.includes( fileExtension ) ) {\n\t\t\t\tuniqueFilenames.add( file.name );\n\t\t\t\treturn true; // Keep file if the extension is allowed\n\t\t\t}\n\t\t\treturn false; // Discard file extension not allowed\n\t\t} );\n\t\tif ( allowedFiles.length > 0 ) {\n\t\t\tloadFiles( allowedFiles );\n\t\t} else {\n\t\t\tsetNotice( {\n\t\t\t\ttype: 'error',\n\t\t\t\tmessage: __( 'No fonts found to install.' ),\n\t\t\t} );\n\t\t\tsetIsUploading( false );\n\t\t}\n\t};\n\n\t/**\n\t * Loads the selected files and reads the font metadata\n\t *\n\t * @param {Array} files The files to be loaded\n\t * @return {void}\n\t */\n\tconst loadFiles = async ( files ) => {\n\t\tconst fontFacesLoaded = await Promise.all(\n\t\t\tfiles.map( async ( fontFile ) => {\n\t\t\t\tconst fontFaceData = await getFontFaceMetadata( fontFile );\n\t\t\t\tawait loadFontFaceInBrowser(\n\t\t\t\t\tfontFaceData,\n\t\t\t\t\tfontFaceData.file,\n\t\t\t\t\t'all'\n\t\t\t\t);\n\t\t\t\treturn fontFaceData;\n\t\t\t} )\n\t\t);\n\t\thandleInstall( fontFacesLoaded );\n\t};\n\n\t// Create a function to read the file as array buffer\n\tasync function readFileAsArrayBuffer( file ) {\n\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\tconst reader = new window.FileReader();\n\t\t\treader.readAsArrayBuffer( file );\n\t\t\treader.onload = () => resolve( reader.result );\n\t\t\treader.onerror = reject;\n\t\t} );\n\t}\n\n\tconst getFontFaceMetadata = async ( fontFile ) => {\n\t\tconst buffer = await readFileAsArrayBuffer( fontFile );\n\t\tconst fontObj = new Font( 'Uploaded Font' );\n\t\tfontObj.fromDataBuffer( buffer, fontFile.name );\n\t\t// Assuming that fromDataBuffer triggers onload event and returning a Promise\n\t\tconst onloadEvent = await new Promise(\n\t\t\t( resolve ) => ( fontObj.onload = resolve )\n\t\t);\n\t\tconst font = onloadEvent.detail.font;\n\t\tconst { name } = font.opentype.tables;\n\t\tconst fontName = name.get( 16 ) || name.get( 1 );\n\t\tconst isItalic = name.get( 2 ).toLowerCase().includes( 'italic' );\n\t\tconst fontWeight =\n\t\t\tfont.opentype.tables[ 'OS/2' ].usWeightClass || 'normal';\n\t\tconst isVariable = !! font.opentype.tables.fvar;\n\t\tconst weightAxis =\n\t\t\tisVariable &&\n\t\t\tfont.opentype.tables.fvar.axes.find(\n\t\t\t\t( { tag } ) => tag === 'wght'\n\t\t\t);\n\t\tconst weightRange = weightAxis\n\t\t\t? `${ weightAxis.minValue } ${ weightAxis.maxValue }`\n\t\t\t: null;\n\t\treturn {\n\t\t\tfile: fontFile,\n\t\t\tfontFamily: fontName,\n\t\t\tfontStyle: isItalic ? 'italic' : 'normal',\n\t\t\tfontWeight: weightRange || fontWeight,\n\t\t};\n\t};\n\n\t/**\n\t * Creates the font family definition and sends it to the server\n\t *\n\t * @param {Array} fontFaces The font faces to be installed\n\t * @return {void}\n\t */\n\tconst handleInstall = async ( fontFaces ) => {\n\t\tconst fontFamilies = makeFamiliesFromFaces( fontFaces );\n\n\t\ttry {\n\t\t\tawait installFonts( fontFamilies );\n\t\t\tsetNotice( {\n\t\t\t\ttype: 'success',\n\t\t\t\tmessage: __( 'Fonts were installed successfully.' ),\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tsetNotice( {\n\t\t\t\ttype: 'error',\n\t\t\t\tmessage: error.message,\n\t\t\t} );\n\t\t}\n\n\t\tsetIsUploading( false );\n\t};\n\n\treturn (\n\t\t<div className=\"font-library-modal__tabpanel-layout\">\n\t\t\t<DropZone onFilesDrop={ handleDropZone } />\n\t\t\t<VStack className=\"font-library-modal__local-fonts\">\n\t\t\t\t{ notice && (\n\t\t\t\t\t<Notice\n\t\t\t\t\t\tstatus={ notice.type }\n\t\t\t\t\t\tonRemove={ () => setNotice( null ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ notice.message }\n\t\t\t\t\t</Notice>\n\t\t\t\t) }\n\t\t\t\t{ isUploading && (\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<div className=\"font-library-modal__upload-area\">\n\t\t\t\t\t\t\t<ProgressBar />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t) }\n\t\t\t\t{ ! isUploading && (\n\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\taccept={ ALLOWED_FILE_EXTENSIONS.map(\n\t\t\t\t\t\t\t( ext ) => `.${ ext }`\n\t\t\t\t\t\t).join( ',' ) }\n\t\t\t\t\t\tmultiple={ true }\n\t\t\t\t\t\tonChange={ onFilesUpload }\n\t\t\t\t\t\trender={ ( { openFileDialog } ) => (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tclassName=\"font-library-modal__upload-area\"\n\t\t\t\t\t\t\t\tonClick={ openFileDialog }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Upload font' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<Spacer margin={ 2 } />\n\t\t\t\t<Text className=\"font-library-modal__upload-area__text\">\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Uploaded fonts appear in your library and can be used in your theme. Supported formats: .tff, .otf, .woff, and .woff2.'\n\t\t\t\t\t) }\n\t\t\t\t</Text>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n\nexport default UploadFonts;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SACCC,oBAAoB,IAAIC,MAAM,EAC9BC,kBAAkB,IAAIC,IAAI,EAC1BC,oBAAoB,IAAIC,MAAM,EAC9BC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,cAAc,EACdC,QAAQ,EACRC,WAAW,IAAIC,qBAAqB,QAC9B,uBAAuB;AAC9B,SAASC,UAAU,EAAEC,QAAQ,QAAQ,oBAAoB;;AAEzD;AACA;AACA;AACA,SAASC,uBAAuB,Q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Q,EAAG3E,aAAe;IAC1B4E,MAAM,EAAGA,CAAE;MAAEC;IAAe,CAAC,KAC5BX,aAAA,CAAC3F,MAAM;MACN4F,SAAS,EAAC,iCAAiC;MAC3CW,OAAO,EAAGD;IAAgB,GAExB7G,EAAE,CAAE,aAAc,CACb;EACN,CACH,CACD,EACDkG,aAAA,CAAChG,MAAM;IAAC6G,MAAM,EAAG;EAAG,CAAE,CAAC,EACvBb,aAAA,CAAC9F,IAAI;IAAC+F,SAAS,EAAC;EAAuC,GACpDnG,EAAE,CACH,wHACD,CACK,CACC,CACJ,CAAC;AAER;AAEA,eAAeuB,WAAW"}
|
|
1
|
+
{"version":3,"names":["__","__experimentalSpacer","Spacer","__experimentalText","Text","__experimentalVStack","VStack","Button","DropZone","Notice","FormFileUpload","FlexItem","privateApis","componentsPrivateApis","useContext","useState","ALLOWED_FILE_EXTENSIONS","FontLibraryContext","Font","makeFamiliesFromFaces","loadFontFaceInBrowser","unlock","ProgressBar","UploadFonts","installFonts","notice","setNotice","isUploading","setIsUploading","handleDropZone","files","handleFilesUpload","onFilesUpload","event","target","uniqueFilenames","Set","selectedFiles","allowedFiles","filter","file","has","name","fileExtension","split","pop","toLowerCase","includes","add","length","loadFiles","type","message","fontFacesLoaded","Promise","all","map","fontFile","fontFaceData","getFontFaceMetadata","handleInstall","readFileAsArrayBuffer","resolve","reject","reader","window","FileReader","readAsArrayBuffer","onload","result","onerror","buffer","fontObj","fromDataBuffer","onloadEvent","font","detail","opentype","tables","fontName","get","isItalic","fontWeight","usWeightClass","isVariable","fvar","weightAxis","axes","find","tag","weightRange","minValue","maxValue","fontFamily","fontStyle","fontFaces","fontFamilies","error","createElement","className","onFilesDrop","status","onRemove","accept","ext","join","multiple","onChange","render","openFileDialog","onClick","margin"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/upload-fonts.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\t__experimentalSpacer as Spacer,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n\tButton,\n\tDropZone,\n\tNotice,\n\tFormFileUpload,\n\tFlexItem,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useContext, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ALLOWED_FILE_EXTENSIONS } from './utils/constants';\nimport { FontLibraryContext } from './context';\nimport { Font } from '../../../../lib/lib-font.browser';\nimport makeFamiliesFromFaces from './utils/make-families-from-faces';\nimport { loadFontFaceInBrowser } from './utils';\nimport { unlock } from '../../../lock-unlock';\n\nconst { ProgressBar } = unlock( componentsPrivateApis );\n\nfunction UploadFonts() {\n\tconst { installFonts, notice, setNotice } =\n\t\tuseContext( FontLibraryContext );\n\tconst [ isUploading, setIsUploading ] = useState( false );\n\n\tconst handleDropZone = ( files ) => {\n\t\thandleFilesUpload( files );\n\t};\n\tconst onFilesUpload = ( event ) => {\n\t\thandleFilesUpload( event.target.files );\n\t};\n\n\t/**\n\t * Filters the selected files to only allow the ones with the allowed extensions\n\t *\n\t * @param {Array} files The files to be filtered\n\t * @return {void}\n\t */\n\tconst handleFilesUpload = ( files ) => {\n\t\tsetNotice( null );\n\t\tsetIsUploading( true );\n\t\tconst uniqueFilenames = new Set();\n\t\tconst selectedFiles = [ ...files ];\n\t\tconst allowedFiles = selectedFiles.filter( ( file ) => {\n\t\t\tif ( uniqueFilenames.has( file.name ) ) {\n\t\t\t\treturn false; // Discard duplicates\n\t\t\t}\n\t\t\t// Eliminates files that are not allowed\n\t\t\tconst fileExtension = file.name.split( '.' ).pop().toLowerCase();\n\t\t\tif ( ALLOWED_FILE_EXTENSIONS.includes( fileExtension ) ) {\n\t\t\t\tuniqueFilenames.add( file.name );\n\t\t\t\treturn true; // Keep file if the extension is allowed\n\t\t\t}\n\t\t\treturn false; // Discard file extension not allowed\n\t\t} );\n\t\tif ( allowedFiles.length > 0 ) {\n\t\t\tloadFiles( allowedFiles );\n\t\t} else {\n\t\t\tsetNotice( {\n\t\t\t\ttype: 'error',\n\t\t\t\tmessage: __( 'No fonts found to install.' ),\n\t\t\t} );\n\t\t\tsetIsUploading( false );\n\t\t}\n\t};\n\n\t/**\n\t * Loads the selected files and reads the font metadata\n\t *\n\t * @param {Array} files The files to be loaded\n\t * @return {void}\n\t */\n\tconst loadFiles = async ( files ) => {\n\t\tconst fontFacesLoaded = await Promise.all(\n\t\t\tfiles.map( async ( fontFile ) => {\n\t\t\t\tconst fontFaceData = await getFontFaceMetadata( fontFile );\n\t\t\t\tawait loadFontFaceInBrowser(\n\t\t\t\t\tfontFaceData,\n\t\t\t\t\tfontFaceData.file,\n\t\t\t\t\t'all'\n\t\t\t\t);\n\t\t\t\treturn fontFaceData;\n\t\t\t} )\n\t\t);\n\t\thandleInstall( fontFacesLoaded );\n\t};\n\n\t// Create a function to read the file as array buffer\n\tasync function readFileAsArrayBuffer( file ) {\n\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\tconst reader = new window.FileReader();\n\t\t\treader.readAsArrayBuffer( file );\n\t\t\treader.onload = () => resolve( reader.result );\n\t\t\treader.onerror = reject;\n\t\t} );\n\t}\n\n\tconst getFontFaceMetadata = async ( fontFile ) => {\n\t\tconst buffer = await readFileAsArrayBuffer( fontFile );\n\t\tconst fontObj = new Font( 'Uploaded Font' );\n\t\tfontObj.fromDataBuffer( buffer, fontFile.name );\n\t\t// Assuming that fromDataBuffer triggers onload event and returning a Promise\n\t\tconst onloadEvent = await new Promise(\n\t\t\t( resolve ) => ( fontObj.onload = resolve )\n\t\t);\n\t\tconst font = onloadEvent.detail.font;\n\t\tconst { name } = font.opentype.tables;\n\t\tconst fontName = name.get( 16 ) || name.get( 1 );\n\t\tconst isItalic = name.get( 2 ).toLowerCase().includes( 'italic' );\n\t\tconst fontWeight =\n\t\t\tfont.opentype.tables[ 'OS/2' ].usWeightClass || 'normal';\n\t\tconst isVariable = !! font.opentype.tables.fvar;\n\t\tconst weightAxis =\n\t\t\tisVariable &&\n\t\t\tfont.opentype.tables.fvar.axes.find(\n\t\t\t\t( { tag } ) => tag === 'wght'\n\t\t\t);\n\t\tconst weightRange = weightAxis\n\t\t\t? `${ weightAxis.minValue } ${ weightAxis.maxValue }`\n\t\t\t: null;\n\t\treturn {\n\t\t\tfile: fontFile,\n\t\t\tfontFamily: fontName,\n\t\t\tfontStyle: isItalic ? 'italic' : 'normal',\n\t\t\tfontWeight: weightRange || fontWeight,\n\t\t};\n\t};\n\n\t/**\n\t * Creates the font family definition and sends it to the server\n\t *\n\t * @param {Array} fontFaces The font faces to be installed\n\t * @return {void}\n\t */\n\tconst handleInstall = async ( fontFaces ) => {\n\t\tconst fontFamilies = makeFamiliesFromFaces( fontFaces );\n\n\t\ttry {\n\t\t\tawait installFonts( fontFamilies );\n\t\t\tsetNotice( {\n\t\t\t\ttype: 'success',\n\t\t\t\tmessage: __( 'Fonts were installed successfully.' ),\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tsetNotice( {\n\t\t\t\ttype: 'error',\n\t\t\t\tmessage: error.message,\n\t\t\t} );\n\t\t}\n\n\t\tsetIsUploading( false );\n\t};\n\n\treturn (\n\t\t<div className=\"font-library-modal__tabpanel-layout\">\n\t\t\t<DropZone onFilesDrop={ handleDropZone } />\n\t\t\t<VStack className=\"font-library-modal__local-fonts\">\n\t\t\t\t{ notice && (\n\t\t\t\t\t<Notice\n\t\t\t\t\t\tstatus={ notice.type }\n\t\t\t\t\t\tonRemove={ () => setNotice( null ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ notice.message }\n\t\t\t\t\t</Notice>\n\t\t\t\t) }\n\t\t\t\t{ isUploading && (\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<div className=\"font-library-modal__upload-area\">\n\t\t\t\t\t\t\t<ProgressBar />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t) }\n\t\t\t\t{ ! isUploading && (\n\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\taccept={ ALLOWED_FILE_EXTENSIONS.map(\n\t\t\t\t\t\t\t( ext ) => `.${ ext }`\n\t\t\t\t\t\t).join( ',' ) }\n\t\t\t\t\t\tmultiple\n\t\t\t\t\t\tonChange={ onFilesUpload }\n\t\t\t\t\t\trender={ ( { openFileDialog } ) => (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tclassName=\"font-library-modal__upload-area\"\n\t\t\t\t\t\t\t\tonClick={ openFileDialog }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Upload font' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<Spacer margin={ 2 } />\n\t\t\t\t<Text className=\"font-library-modal__upload-area__text\">\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Uploaded fonts appear in your library and can be used in your theme. Supported formats: .tff, .otf, .woff, and .woff2.'\n\t\t\t\t\t) }\n\t\t\t\t</Text>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n\nexport default UploadFonts;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SACCC,oBAAoB,IAAIC,MAAM,EAC9BC,kBAAkB,IAAIC,IAAI,EAC1BC,oBAAoB,IAAIC,MAAM,EAC9BC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,cAAc,EACdC,QAAQ,EACRC,WAAW,IAAIC,qBAAqB,QAC9B,uBAAuB;AAC9B,SAASC,UAAU,EAAEC,QAAQ,QAAQ,oBAAoB;;AAEzD;AACA;AACA;AACA,SAASC,uBAAuB,QAAQ,mBAAmB;AAC3D,SAASC,kBAAkB,QAAQ,WAAW;AAC9C,SAASC,IAAI,QAAQ,kCAAkC;AACvD,OAAOC,qBAAqB,MAAM,kCAAkC;AACpE,SAASC,qBAAqB,QAAQ,SAAS;AAC/C,SAASC,MAAM,QAAQ,sBAAsB;AAE7C,MAAM;EAAEC;AAAY,CAAC,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AM,EAAG;EAAG,CAAE,CAAC,EACvBb,aAAA,CAAC9F,IAAI;IAAC+F,SAAS,EAAC;EAAuC,GACpDnG,EAAE,CACH,wHACD,CACK,CACC,CACJ,CAAC;AAER;AAEA,eAAeuB,WAAW"}
|
|
@@ -108,6 +108,32 @@ export async function loadFontFaceInBrowser(fontFace, source, addTo = 'all') {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/*
|
|
112
|
+
* Unloads the font face and remove it from the browser.
|
|
113
|
+
* It also removes it from the iframe document.
|
|
114
|
+
*
|
|
115
|
+
* Note that Font faces that were added to the set using the CSS @font-face rule
|
|
116
|
+
* remain connected to the corresponding CSS, and cannot be deleted.
|
|
117
|
+
*
|
|
118
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet/delete.
|
|
119
|
+
*/
|
|
120
|
+
export function unloadFontFaceInBrowser(fontFace, removeFrom = 'all') {
|
|
121
|
+
const unloadFontFace = fonts => {
|
|
122
|
+
fonts.forEach(f => {
|
|
123
|
+
if (f.family === formatFontFaceName(fontFace.fontFamily) && f.weight === fontFace.fontWeight && f.style === fontFace.fontStyle) {
|
|
124
|
+
fonts.delete(f);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
if (removeFrom === 'document' || removeFrom === 'all') {
|
|
129
|
+
unloadFontFace(document.fonts);
|
|
130
|
+
}
|
|
131
|
+
if (removeFrom === 'iframe' || removeFrom === 'all') {
|
|
132
|
+
const iframeDocument = document.querySelector('iframe[name="editor-canvas"]').contentDocument;
|
|
133
|
+
unloadFontFace(iframeDocument.fonts);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
111
137
|
/**
|
|
112
138
|
* Retrieves the display source from a font face src.
|
|
113
139
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["privateApis","componentsPrivateApis","FONT_WEIGHTS","FONT_STYLES","unlock","fetchInstallFontFace","formatFontFaceName","File","window","setUIValuesNeeded","font","extraValues","name","fontFamily","slug","isUrlEncoded","url","decodeURIComponent","getFontFaceVariantName","face","weightName","fontWeight","styleName","fontStyle","mergeFontFaces","existing","incoming","map","Map","set","Array","from","values","mergeFontFamilies","has","fontFace","incomingFontFaces","restIncoming","existingFont","get","mergedFontFaces","loadFontFaceInBrowser","source","addTo","dataSource","arrayBuffer","newFont","FontFace","style","weight","loadedFace","load","document","fonts","add","iframeDocument","querySelector","contentDocument","getDisplaySrcFromFontFace","input","src","isArray","startsWith","encodeURI","makeFontFamilyFormData","formData","FormData","kebabCase","category","familyWithValidParameters","fontFamilySettings","append","JSON","stringify","makeFontFacesFormData","fontFacesFormData","item","faceIndex","file","files","forEach","key","fileId","push","length","batchInstallFontFaces","fontFamilyId","fontFacesData","promises","faceData","responses","Promise","allSettled","results","errors","successes","result","index","status","response","value","id","data","message","reason","downloadFontFaceAssets","all","fetch","Request","then","ok","Error","blob","filename","split","pop","type","checkFontFaceInstalled","collection","findIndex","collectionFontFace"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/utils/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { FONT_WEIGHTS, FONT_STYLES } from './constants';\nimport { unlock } from '../../../../lock-unlock';\nimport { fetchInstallFontFace } from '../resolvers';\nimport { formatFontFaceName } from './preview-styles';\n\n/**\n * Browser dependencies\n */\nconst { File } = window;\n\nexport function setUIValuesNeeded( font, extraValues = {} ) {\n\tif ( ! font.name && ( font.fontFamily || font.slug ) ) {\n\t\tfont.name = font.fontFamily || font.slug;\n\t}\n\treturn {\n\t\t...font,\n\t\t...extraValues,\n\t};\n}\n\nexport function isUrlEncoded( url ) {\n\tif ( typeof url !== 'string' ) {\n\t\treturn false;\n\t}\n\treturn url !== decodeURIComponent( url );\n}\n\nexport function getFontFaceVariantName( face ) {\n\tconst weightName = FONT_WEIGHTS[ face.fontWeight ] || face.fontWeight;\n\tconst styleName =\n\t\tface.fontStyle === 'normal'\n\t\t\t? ''\n\t\t\t: FONT_STYLES[ face.fontStyle ] || face.fontStyle;\n\treturn `${ weightName } ${ styleName }`;\n}\n\nexport function mergeFontFaces( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\tfor ( const face of existing ) {\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\tfor ( const face of incoming ) {\n\t\t// This will overwrite if the src already exists, keeping it unique.\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\treturn Array.from( map.values() );\n}\n\nexport function mergeFontFamilies( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\t// Add the existing array to the map.\n\tfor ( const font of existing ) {\n\t\tmap.set( font.slug, { ...font } );\n\t}\n\t// Add the incoming array to the map, overwriting existing values excepting fontFace that need to be merged.\n\tfor ( const font of incoming ) {\n\t\tif ( map.has( font.slug ) ) {\n\t\t\tconst { fontFace: incomingFontFaces, ...restIncoming } = font;\n\t\t\tconst existingFont = map.get( font.slug );\n\t\t\t// Merge the fontFaces existing with the incoming fontFaces.\n\t\t\tconst mergedFontFaces = mergeFontFaces(\n\t\t\t\texistingFont.fontFace,\n\t\t\t\tincomingFontFaces\n\t\t\t);\n\t\t\t// Except for the fontFace key all the other keys are overwritten with the incoming values.\n\t\t\tmap.set( font.slug, {\n\t\t\t\t...restIncoming,\n\t\t\t\tfontFace: mergedFontFaces,\n\t\t\t} );\n\t\t} else {\n\t\t\tmap.set( font.slug, { ...font } );\n\t\t}\n\t}\n\treturn Array.from( map.values() );\n}\n\n/*\n * Loads the font face from a URL and adds it to the browser.\n * It also adds it to the iframe document.\n */\nexport async function loadFontFaceInBrowser( fontFace, source, addTo = 'all' ) {\n\tlet dataSource;\n\n\tif ( typeof source === 'string' ) {\n\t\tdataSource = `url(${ source })`;\n\t\t// eslint-disable-next-line no-undef\n\t} else if ( source instanceof File ) {\n\t\tdataSource = await source.arrayBuffer();\n\t} else {\n\t\treturn;\n\t}\n\n\tconst newFont = new window.FontFace(\n\t\tformatFontFaceName( fontFace.fontFamily ),\n\t\tdataSource,\n\t\t{\n\t\t\tstyle: fontFace.fontStyle,\n\t\t\tweight: fontFace.fontWeight,\n\t\t}\n\t);\n\n\tconst loadedFace = await newFont.load();\n\n\tif ( addTo === 'document' || addTo === 'all' ) {\n\t\tdocument.fonts.add( loadedFace );\n\t}\n\n\tif ( addTo === 'iframe' || addTo === 'all' ) {\n\t\tconst iframeDocument = document.querySelector(\n\t\t\t'iframe[name=\"editor-canvas\"]'\n\t\t).contentDocument;\n\t\tiframeDocument.fonts.add( loadedFace );\n\t}\n}\n\n/**\n * Retrieves the display source from a font face src.\n *\n * @param {string|string[]} input - The font face src.\n * @return {string|undefined} The display source or undefined if the input is invalid.\n */\nexport function getDisplaySrcFromFontFace( input ) {\n\tif ( ! input ) {\n\t\treturn;\n\t}\n\n\tlet src;\n\tif ( Array.isArray( input ) ) {\n\t\tsrc = input[ 0 ];\n\t} else {\n\t\tsrc = input;\n\t}\n\t// It's expected theme fonts will already be loaded in the browser.\n\tif ( src.startsWith( 'file:.' ) ) {\n\t\treturn;\n\t}\n\tif ( ! isUrlEncoded( src ) ) {\n\t\tsrc = encodeURI( src );\n\t}\n\treturn src;\n}\n\nexport function makeFontFamilyFormData( fontFamily ) {\n\tconst formData = new FormData();\n\tconst { kebabCase } = unlock( componentsPrivateApis );\n\n\tconst { fontFace, category, ...familyWithValidParameters } = fontFamily;\n\tconst fontFamilySettings = {\n\t\t...familyWithValidParameters,\n\t\tslug: kebabCase( fontFamily.slug ),\n\t};\n\n\tformData.append(\n\t\t'font_family_settings',\n\t\tJSON.stringify( fontFamilySettings )\n\t);\n\treturn formData;\n}\n\nexport function makeFontFacesFormData( font ) {\n\tif ( font?.fontFace ) {\n\t\tconst fontFacesFormData = font.fontFace.map( ( item, faceIndex ) => {\n\t\t\tconst face = { ...item };\n\t\t\tconst formData = new FormData();\n\t\t\tif ( face.file ) {\n\t\t\t\t// Normalize to an array, since face.file may be a single file or an array of files.\n\t\t\t\tconst files = Array.isArray( face.file )\n\t\t\t\t\t? face.file\n\t\t\t\t\t: [ face.file ];\n\t\t\t\tconst src = [];\n\n\t\t\t\tfiles.forEach( ( file, key ) => {\n\t\t\t\t\t// Slugified file name because the it might contain spaces or characters treated differently on the server.\n\t\t\t\t\tconst fileId = `file-${ faceIndex }-${ key }`;\n\t\t\t\t\t// Add the files to the formData\n\t\t\t\t\tformData.append( fileId, file, file.name );\n\t\t\t\t\tsrc.push( fileId );\n\t\t\t\t} );\n\n\t\t\t\tface.src = src.length === 1 ? src[ 0 ] : src;\n\t\t\t\tdelete face.file;\n\n\t\t\t\tformData.append( 'font_face_settings', JSON.stringify( face ) );\n\t\t\t} else {\n\t\t\t\tformData.append( 'font_face_settings', JSON.stringify( face ) );\n\t\t\t}\n\t\t\treturn formData;\n\t\t} );\n\n\t\treturn fontFacesFormData;\n\t}\n}\n\nexport async function batchInstallFontFaces( fontFamilyId, fontFacesData ) {\n\tconst promises = fontFacesData.map( ( faceData ) =>\n\t\tfetchInstallFontFace( fontFamilyId, faceData )\n\t);\n\tconst responses = await Promise.allSettled( promises );\n\n\tconst results = {\n\t\terrors: [],\n\t\tsuccesses: [],\n\t};\n\n\tresponses.forEach( ( result, index ) => {\n\t\tif ( result.status === 'fulfilled' ) {\n\t\t\tconst response = result.value;\n\t\t\tif ( response.id ) {\n\t\t\t\tresults.successes.push( response );\n\t\t\t} else {\n\t\t\t\tresults.errors.push( {\n\t\t\t\t\tdata: fontFacesData[ index ],\n\t\t\t\t\tmessage: `Error: ${ response.message }`,\n\t\t\t\t} );\n\t\t\t}\n\t\t} else {\n\t\t\t// Handle network errors or other fetch-related errors\n\t\t\tresults.errors.push( {\n\t\t\t\tdata: fontFacesData[ index ],\n\t\t\t\tmessage: `Fetch error: ${ result.reason.message }`,\n\t\t\t} );\n\t\t}\n\t} );\n\n\treturn results;\n}\n\n/*\n * Downloads a font face asset from a URL to the client and returns a File object.\n */\nexport async function downloadFontFaceAssets( src ) {\n\t// Normalize to an array, since `src` could be a string or array.\n\tsrc = Array.isArray( src ) ? src : [ src ];\n\n\tconst files = await Promise.all(\n\t\tsrc.map( async ( url ) => {\n\t\t\treturn fetch( new Request( url ) )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response.ok ) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Error downloading font face asset from ${ url }. Server responded with status: ${ response.status }`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn response.blob();\n\t\t\t\t} )\n\t\t\t\t.then( ( blob ) => {\n\t\t\t\t\tconst filename = url.split( '/' ).pop();\n\t\t\t\t\tconst file = new File( [ blob ], filename, {\n\t\t\t\t\t\ttype: blob.type,\n\t\t\t\t\t} );\n\t\t\t\t\treturn file;\n\t\t\t\t} );\n\t\t} )\n\t);\n\n\t// If we only have one file return it (not the array). Otherwise return all of them in the array.\n\treturn files.length === 1 ? files[ 0 ] : files;\n}\n\n/*\n * Determine if a given Font Face is present in a given collection.\n * We determine that a font face has been installed by comparing the fontWeight and fontStyle\n *\n * @param {Object} fontFace The Font Face to seek\n * @param {Array} collection The Collection to seek in\n * @returns True if the font face is found in the collection. Otherwise False.\n */\nexport function checkFontFaceInstalled( fontFace, collection ) {\n\treturn (\n\t\t-1 !==\n\t\tcollection.findIndex( ( collectionFontFace ) => {\n\t\t\treturn (\n\t\t\t\tcollectionFontFace.fontWeight === fontFace.fontWeight &&\n\t\t\t\tcollectionFontFace.fontStyle === fontFace.fontStyle\n\t\t\t);\n\t\t} )\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,IAAIC,qBAAqB,QAAQ,uBAAuB;;AAE5E;AACA;AACA;AACA,SAASC,YAAY,EAAEC,WAAW,QAAQ,aAAa;AACvD,SAASC,MAAM,QAAQ,yBAAyB;AAChD,SAASC,oBAAoB,QAAQ,cAAc;AACnD,S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E,CAAEyG,IAAI,CAAE,EAAEC,QAAQ,EAAE;QAC1CG,IAAI,EAAEJ,IAAI,CAACI;MACZ,CAAE,CAAC;MACH,OAAOtC,IAAI;IACZ,CAAE,CAAC;EACL,CAAE,CACH,CAAC;;EAED;EACA,OAAOC,KAAK,CAACK,MAAM,KAAK,CAAC,GAAGL,KAAK,CAAE,CAAC,CAAE,GAAGA,KAAK;AAC/C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASsC,sBAAsBA,CAAElF,QAAQ,EAAEmF,UAAU,EAAG;EAC9D,OACC,CAAC,CAAC,KACFA,UAAU,CAACC,SAAS,CAAIC,kBAAkB,IAAM;IAC/C,OACCA,kBAAkB,CAACnG,UAAU,KAAKc,QAAQ,CAACd,UAAU,IACrDmG,kBAAkB,CAACjG,SAAS,KAAKY,QAAQ,CAACZ,SAAS;EAErD,CAAE,CAAC;AAEL"}
|
|
1
|
+
{"version":3,"names":["privateApis","componentsPrivateApis","FONT_WEIGHTS","FONT_STYLES","unlock","fetchInstallFontFace","formatFontFaceName","File","window","setUIValuesNeeded","font","extraValues","name","fontFamily","slug","isUrlEncoded","url","decodeURIComponent","getFontFaceVariantName","face","weightName","fontWeight","styleName","fontStyle","mergeFontFaces","existing","incoming","map","Map","set","Array","from","values","mergeFontFamilies","has","fontFace","incomingFontFaces","restIncoming","existingFont","get","mergedFontFaces","loadFontFaceInBrowser","source","addTo","dataSource","arrayBuffer","newFont","FontFace","style","weight","loadedFace","load","document","fonts","add","iframeDocument","querySelector","contentDocument","unloadFontFaceInBrowser","removeFrom","unloadFontFace","forEach","f","family","delete","getDisplaySrcFromFontFace","input","src","isArray","startsWith","encodeURI","makeFontFamilyFormData","formData","FormData","kebabCase","category","familyWithValidParameters","fontFamilySettings","append","JSON","stringify","makeFontFacesFormData","fontFacesFormData","item","faceIndex","file","files","key","fileId","push","length","batchInstallFontFaces","fontFamilyId","fontFacesData","promises","faceData","responses","Promise","allSettled","results","errors","successes","result","index","status","response","value","id","data","message","reason","downloadFontFaceAssets","all","fetch","Request","then","ok","Error","blob","filename","split","pop","type","checkFontFaceInstalled","collection","findIndex","collectionFontFace"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/utils/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { FONT_WEIGHTS, FONT_STYLES } from './constants';\nimport { unlock } from '../../../../lock-unlock';\nimport { fetchInstallFontFace } from '../resolvers';\nimport { formatFontFaceName } from './preview-styles';\n\n/**\n * Browser dependencies\n */\nconst { File } = window;\n\nexport function setUIValuesNeeded( font, extraValues = {} ) {\n\tif ( ! font.name && ( font.fontFamily || font.slug ) ) {\n\t\tfont.name = font.fontFamily || font.slug;\n\t}\n\treturn {\n\t\t...font,\n\t\t...extraValues,\n\t};\n}\n\nexport function isUrlEncoded( url ) {\n\tif ( typeof url !== 'string' ) {\n\t\treturn false;\n\t}\n\treturn url !== decodeURIComponent( url );\n}\n\nexport function getFontFaceVariantName( face ) {\n\tconst weightName = FONT_WEIGHTS[ face.fontWeight ] || face.fontWeight;\n\tconst styleName =\n\t\tface.fontStyle === 'normal'\n\t\t\t? ''\n\t\t\t: FONT_STYLES[ face.fontStyle ] || face.fontStyle;\n\treturn `${ weightName } ${ styleName }`;\n}\n\nexport function mergeFontFaces( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\tfor ( const face of existing ) {\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\tfor ( const face of incoming ) {\n\t\t// This will overwrite if the src already exists, keeping it unique.\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\treturn Array.from( map.values() );\n}\n\nexport function mergeFontFamilies( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\t// Add the existing array to the map.\n\tfor ( const font of existing ) {\n\t\tmap.set( font.slug, { ...font } );\n\t}\n\t// Add the incoming array to the map, overwriting existing values excepting fontFace that need to be merged.\n\tfor ( const font of incoming ) {\n\t\tif ( map.has( font.slug ) ) {\n\t\t\tconst { fontFace: incomingFontFaces, ...restIncoming } = font;\n\t\t\tconst existingFont = map.get( font.slug );\n\t\t\t// Merge the fontFaces existing with the incoming fontFaces.\n\t\t\tconst mergedFontFaces = mergeFontFaces(\n\t\t\t\texistingFont.fontFace,\n\t\t\t\tincomingFontFaces\n\t\t\t);\n\t\t\t// Except for the fontFace key all the other keys are overwritten with the incoming values.\n\t\t\tmap.set( font.slug, {\n\t\t\t\t...restIncoming,\n\t\t\t\tfontFace: mergedFontFaces,\n\t\t\t} );\n\t\t} else {\n\t\t\tmap.set( font.slug, { ...font } );\n\t\t}\n\t}\n\treturn Array.from( map.values() );\n}\n\n/*\n * Loads the font face from a URL and adds it to the browser.\n * It also adds it to the iframe document.\n */\nexport async function loadFontFaceInBrowser( fontFace, source, addTo = 'all' ) {\n\tlet dataSource;\n\n\tif ( typeof source === 'string' ) {\n\t\tdataSource = `url(${ source })`;\n\t\t// eslint-disable-next-line no-undef\n\t} else if ( source instanceof File ) {\n\t\tdataSource = await source.arrayBuffer();\n\t} else {\n\t\treturn;\n\t}\n\n\tconst newFont = new window.FontFace(\n\t\tformatFontFaceName( fontFace.fontFamily ),\n\t\tdataSource,\n\t\t{\n\t\t\tstyle: fontFace.fontStyle,\n\t\t\tweight: fontFace.fontWeight,\n\t\t}\n\t);\n\n\tconst loadedFace = await newFont.load();\n\n\tif ( addTo === 'document' || addTo === 'all' ) {\n\t\tdocument.fonts.add( loadedFace );\n\t}\n\n\tif ( addTo === 'iframe' || addTo === 'all' ) {\n\t\tconst iframeDocument = document.querySelector(\n\t\t\t'iframe[name=\"editor-canvas\"]'\n\t\t).contentDocument;\n\t\tiframeDocument.fonts.add( loadedFace );\n\t}\n}\n\n/*\n * Unloads the font face and remove it from the browser.\n * It also removes it from the iframe document.\n *\n * Note that Font faces that were added to the set using the CSS @font-face rule\n * remain connected to the corresponding CSS, and cannot be deleted.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet/delete.\n */\nexport function unloadFontFaceInBrowser( fontFace, removeFrom = 'all' ) {\n\tconst unloadFontFace = ( fonts ) => {\n\t\tfonts.forEach( ( f ) => {\n\t\t\tif (\n\t\t\t\tf.family === formatFontFaceName( fontFace.fontFamily ) &&\n\t\t\t\tf.weight === fontFace.fontWeight &&\n\t\t\t\tf.style === fontFace.fontStyle\n\t\t\t) {\n\t\t\t\tfonts.delete( f );\n\t\t\t}\n\t\t} );\n\t};\n\n\tif ( removeFrom === 'document' || removeFrom === 'all' ) {\n\t\tunloadFontFace( document.fonts );\n\t}\n\n\tif ( removeFrom === 'iframe' || removeFrom === 'all' ) {\n\t\tconst iframeDocument = document.querySelector(\n\t\t\t'iframe[name=\"editor-canvas\"]'\n\t\t).contentDocument;\n\t\tunloadFontFace( iframeDocument.fonts );\n\t}\n}\n\n/**\n * Retrieves the display source from a font face src.\n *\n * @param {string|string[]} input - The font face src.\n * @return {string|undefined} The display source or undefined if the input is invalid.\n */\nexport function getDisplaySrcFromFontFace( input ) {\n\tif ( ! input ) {\n\t\treturn;\n\t}\n\n\tlet src;\n\tif ( Array.isArray( input ) ) {\n\t\tsrc = input[ 0 ];\n\t} else {\n\t\tsrc = input;\n\t}\n\t// It's expected theme fonts will already be loaded in the browser.\n\tif ( src.startsWith( 'file:.' ) ) {\n\t\treturn;\n\t}\n\tif ( ! isUrlEncoded( src ) ) {\n\t\tsrc = encodeURI( src );\n\t}\n\treturn src;\n}\n\nexport function makeFontFamilyFormData( fontFamily ) {\n\tconst formData = new FormData();\n\tconst { kebabCase } = unlock( componentsPrivateApis );\n\n\tconst { fontFace, category, ...familyWithValidParameters } = fontFamily;\n\tconst fontFamilySettings = {\n\t\t...familyWithValidParameters,\n\t\tslug: kebabCase( fontFamily.slug ),\n\t};\n\n\tformData.append(\n\t\t'font_family_settings',\n\t\tJSON.stringify( fontFamilySettings )\n\t);\n\treturn formData;\n}\n\nexport function makeFontFacesFormData( font ) {\n\tif ( font?.fontFace ) {\n\t\tconst fontFacesFormData = font.fontFace.map( ( item, faceIndex ) => {\n\t\t\tconst face = { ...item };\n\t\t\tconst formData = new FormData();\n\t\t\tif ( face.file ) {\n\t\t\t\t// Normalize to an array, since face.file may be a single file or an array of files.\n\t\t\t\tconst files = Array.isArray( face.file )\n\t\t\t\t\t? face.file\n\t\t\t\t\t: [ face.file ];\n\t\t\t\tconst src = [];\n\n\t\t\t\tfiles.forEach( ( file, key ) => {\n\t\t\t\t\t// Slugified file name because the it might contain spaces or characters treated differently on the server.\n\t\t\t\t\tconst fileId = `file-${ faceIndex }-${ key }`;\n\t\t\t\t\t// Add the files to the formData\n\t\t\t\t\tformData.append( fileId, file, file.name );\n\t\t\t\t\tsrc.push( fileId );\n\t\t\t\t} );\n\n\t\t\t\tface.src = src.length === 1 ? src[ 0 ] : src;\n\t\t\t\tdelete face.file;\n\n\t\t\t\tformData.append( 'font_face_settings', JSON.stringify( face ) );\n\t\t\t} else {\n\t\t\t\tformData.append( 'font_face_settings', JSON.stringify( face ) );\n\t\t\t}\n\t\t\treturn formData;\n\t\t} );\n\n\t\treturn fontFacesFormData;\n\t}\n}\n\nexport async function batchInstallFontFaces( fontFamilyId, fontFacesData ) {\n\tconst promises = fontFacesData.map( ( faceData ) =>\n\t\tfetchInstallFontFace( fontFamilyId, faceData )\n\t);\n\tconst responses = await Promise.allSettled( promises );\n\n\tconst results = {\n\t\terrors: [],\n\t\tsuccesses: [],\n\t};\n\n\tresponses.forEach( ( result, index ) => {\n\t\tif ( result.status === 'fulfilled' ) {\n\t\t\tconst response = result.value;\n\t\t\tif ( response.id ) {\n\t\t\t\tresults.successes.push( response );\n\t\t\t} else {\n\t\t\t\tresults.errors.push( {\n\t\t\t\t\tdata: fontFacesData[ index ],\n\t\t\t\t\tmessage: `Error: ${ response.message }`,\n\t\t\t\t} );\n\t\t\t}\n\t\t} else {\n\t\t\t// Handle network errors or other fetch-related errors\n\t\t\tresults.errors.push( {\n\t\t\t\tdata: fontFacesData[ index ],\n\t\t\t\tmessage: `Fetch error: ${ result.reason.message }`,\n\t\t\t} );\n\t\t}\n\t} );\n\n\treturn results;\n}\n\n/*\n * Downloads a font face asset from a URL to the client and returns a File object.\n */\nexport async function downloadFontFaceAssets( src ) {\n\t// Normalize to an array, since `src` could be a string or array.\n\tsrc = Array.isArray( src ) ? src : [ src ];\n\n\tconst files = await Promise.all(\n\t\tsrc.map( async ( url ) => {\n\t\t\treturn fetch( new Request( url ) )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response.ok ) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Error downloading font face asset from ${ url }. Server responded with status: ${ response.status }`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn response.blob();\n\t\t\t\t} )\n\t\t\t\t.then( ( blob ) => {\n\t\t\t\t\tconst filename = url.split( '/' ).pop();\n\t\t\t\t\tconst file = new File( [ blob ], filename, {\n\t\t\t\t\t\ttype: blob.type,\n\t\t\t\t\t} );\n\t\t\t\t\treturn file;\n\t\t\t\t} );\n\t\t} )\n\t);\n\n\t// If we only have one file return it (not the array). Otherwise return all of them in the array.\n\treturn files.length === 1 ? files[ 0 ] : files;\n}\n\n/*\n * Determine if a given Font Face is present in a given collection.\n * We determine that a font face has been installed by comparing the fontWeight and fontStyle\n *\n * @param {Object} fontFace The Font Face to seek\n * @param {Array} collection The Collection to seek in\n * @returns True if the font face is found in the collection. Otherwise False.\n */\nexport function checkFontFaceInstalled( fontFace, collection ) {\n\treturn (\n\t\t-1 !==\n\t\tcollection.findIndex( ( collectionFontFace ) => {\n\t\t\treturn (\n\t\t\t\tcollectionFontFace.fontWeight === fontFace.fontWeight &&\n\t\t\t\tcollectionFontFace.fontStyle === fontFace.fontStyle\n\t\t\t);\n\t\t} )\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,IAAIC,qBAAqB,Q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AO,SAASqC,sBAAsBA,CAAExF,QAAQ,EAAEyF,UAAU,EAAG;EAC9D,OACC,CAAC,CAAC,KACFA,UAAU,CAACC,SAAS,CAAIC,kBAAkB,IAAM;IAC/C,OACCA,kBAAkB,CAACzG,UAAU,KAAKc,QAAQ,CAACd,UAAU,IACrDyG,kBAAkB,CAACvG,SAAS,KAAKY,QAAQ,CAACZ,SAAS;EAErD,CAAE,CAAC;AAEL"}
|
|
@@ -101,7 +101,7 @@ export function getFamilyPreviewStyle(family) {
|
|
|
101
101
|
}
|
|
102
102
|
if (family.fontFace) {
|
|
103
103
|
//get all the font faces with normal style
|
|
104
|
-
const normalFaces = family.fontFace.filter(face => face.fontStyle.toLowerCase() === 'normal');
|
|
104
|
+
const normalFaces = family.fontFace.filter(face => face?.fontStyle && face.fontStyle.toLowerCase() === 'normal');
|
|
105
105
|
if (normalFaces.length > 0) {
|
|
106
106
|
style.fontStyle = 'normal';
|
|
107
107
|
const normalWeights = extractFontWeights(normalFaces);
|
package/build-module/components/global-styles/font-library-modal/utils/preview-styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["findNearest","input","numbers","length","sort","a","b","Math","abs","extractFontWeights","fontFaces","result","forEach","face","weights","String","fontWeight","split","start","parseInt","end","i","push","formatFontFamily","regex","output","trim","formatItem","item","match","replace","includes","map","filter","join","formatFontFaceName","find","window","navigator","userAgent","toLowerCase","getFamilyPreviewStyle","family","style","fontFamily","Array","isArray","fontFace","fontStyle","normalFaces","normalWeights","nearestWeight","getFacePreviewStyle"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/utils/preview-styles.js"],"sourcesContent":["function findNearest( input, numbers ) {\n\t// If the numbers array is empty, return null\n\tif ( numbers.length === 0 ) {\n\t\treturn null;\n\t}\n\t// Sort the array based on the absolute difference with the input\n\tnumbers.sort( ( a, b ) => Math.abs( input - a ) - Math.abs( input - b ) );\n\t// Return the first element (which will be the nearest) from the sorted array\n\treturn numbers[ 0 ];\n}\n\nfunction extractFontWeights( fontFaces ) {\n\tconst result = [];\n\n\tfontFaces.forEach( ( face ) => {\n\t\tconst weights = String( face.fontWeight ).split( ' ' );\n\n\t\tif ( weights.length === 2 ) {\n\t\t\tconst start = parseInt( weights[ 0 ] );\n\t\t\tconst end = parseInt( weights[ 1 ] );\n\n\t\t\tfor ( let i = start; i <= end; i += 100 ) {\n\t\t\t\tresult.push( i );\n\t\t\t}\n\t\t} else if ( weights.length === 1 ) {\n\t\t\tresult.push( parseInt( weights[ 0 ] ) );\n\t\t}\n\t} );\n\n\treturn result;\n}\n\n/*\n * Format the font family to use in the CSS font-family property of a CSS rule.\n *\n * The input can be a string with the font family name or a string with multiple font family names separated by commas.\n * It follows the recommendations from the CSS Fonts Module Level 4.\n * https://www.w3.org/TR/css-fonts-4/#font-family-prop\n *\n * @param {string} input - The font family.\n * @return {string} The formatted font family.\n *\n * Example:\n * formatFontFamily( \"Open Sans, Font+Name, sans-serif\" ) => '\"Open Sans\", \"Font+Name\", sans-serif'\n * formatFontFamily( \"'Open Sans', generic(kai), sans-serif\" ) => '\"Open Sans\", sans-serif'\n * formatFontFamily( \"DotGothic16, Slabo 27px, serif\" ) => '\"DotGothic16\",\"Slabo 27px\",serif'\n * formatFontFamily( \"Mine's, Moe's Typography\" ) => `\"mine's\",\"Moe's Typography\"`\n */\nexport function formatFontFamily( input ) {\n\t// Matches strings that are not exclusively alphabetic characters or hyphens, and do not exactly follow the pattern generic(alphabetic characters or hyphens).\n\tconst regex = /^(?!generic\\([ a-zA-Z\\-]+\\)$)(?!^[a-zA-Z\\-]+$).+/;\n\tconst output = input.trim();\n\n\tconst formatItem = ( item ) => {\n\t\titem = item.trim();\n\t\tif ( item.match( regex ) ) {\n\t\t\t// removes leading and trailing quotes.\n\t\t\titem = item.replace( /^[\"']|[\"']$/g, '' );\n\t\t\treturn `\"${ item }\"`;\n\t\t}\n\t\treturn item;\n\t};\n\n\tif ( output.includes( ',' ) ) {\n\t\treturn output\n\t\t\t.split( ',' )\n\t\t\t.map( formatItem )\n\t\t\t.filter( ( item ) => item !== '' )\n\t\t\t.join( ', ' );\n\t}\n\n\treturn formatItem( output );\n}\n\n/*\n * Format the font face name to use in the font-family property of a font face.\n *\n * The input can be a string with the font face name or a string with multiple font face names separated by commas.\n * It removes the leading and trailing quotes from the font face name.\n *\n * @param {string} input - The font face name.\n * @return {string} The formatted font face name.\n *\n * Example:\n * formatFontFaceName(\"Open Sans\") => \"Open Sans\"\n * formatFontFaceName(\"'Open Sans', sans-serif\") => \"Open Sans\"\n * formatFontFaceName(\", 'Open Sans', 'Helvetica Neue', sans-serif\") => \"Open Sans\"\n */\nexport function formatFontFaceName( input ) {\n\tlet output = input.trim();\n\tif ( output.includes( ',' ) ) {\n\t\toutput = output\n\t\t\t.split( ',' )\n\t\t\t// finds the first item that is not an empty string.\n\t\t\t.find( ( item ) => item.trim() !== '' )\n\t\t\t.trim();\n\t}\n\t// removes leading and trailing quotes.\n\toutput = output.replace( /^[\"']|[\"']$/g, '' );\n\n\t// Firefox needs the font name to be wrapped in double quotes meanwhile other browsers don't.\n\tif ( window.navigator.userAgent.toLowerCase().includes( 'firefox' ) ) {\n\t\toutput = `\"${ output }\"`;\n\t}\n\treturn output;\n}\n\nexport function getFamilyPreviewStyle( family ) {\n\tconst style = { fontFamily: formatFontFamily( family.fontFamily ) };\n\n\tif ( ! Array.isArray( family.fontFace ) ) {\n\t\tstyle.fontWeight = '400';\n\t\tstyle.fontStyle = 'normal';\n\t\treturn style;\n\t}\n\n\tif ( family.fontFace ) {\n\t\t//get all the font faces with normal style\n\t\tconst normalFaces = family.fontFace.filter(\n\t\t\t( face )
|
|
1
|
+
{"version":3,"names":["findNearest","input","numbers","length","sort","a","b","Math","abs","extractFontWeights","fontFaces","result","forEach","face","weights","String","fontWeight","split","start","parseInt","end","i","push","formatFontFamily","regex","output","trim","formatItem","item","match","replace","includes","map","filter","join","formatFontFaceName","find","window","navigator","userAgent","toLowerCase","getFamilyPreviewStyle","family","style","fontFamily","Array","isArray","fontFace","fontStyle","normalFaces","normalWeights","nearestWeight","getFacePreviewStyle"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/utils/preview-styles.js"],"sourcesContent":["function findNearest( input, numbers ) {\n\t// If the numbers array is empty, return null\n\tif ( numbers.length === 0 ) {\n\t\treturn null;\n\t}\n\t// Sort the array based on the absolute difference with the input\n\tnumbers.sort( ( a, b ) => Math.abs( input - a ) - Math.abs( input - b ) );\n\t// Return the first element (which will be the nearest) from the sorted array\n\treturn numbers[ 0 ];\n}\n\nfunction extractFontWeights( fontFaces ) {\n\tconst result = [];\n\n\tfontFaces.forEach( ( face ) => {\n\t\tconst weights = String( face.fontWeight ).split( ' ' );\n\n\t\tif ( weights.length === 2 ) {\n\t\t\tconst start = parseInt( weights[ 0 ] );\n\t\t\tconst end = parseInt( weights[ 1 ] );\n\n\t\t\tfor ( let i = start; i <= end; i += 100 ) {\n\t\t\t\tresult.push( i );\n\t\t\t}\n\t\t} else if ( weights.length === 1 ) {\n\t\t\tresult.push( parseInt( weights[ 0 ] ) );\n\t\t}\n\t} );\n\n\treturn result;\n}\n\n/*\n * Format the font family to use in the CSS font-family property of a CSS rule.\n *\n * The input can be a string with the font family name or a string with multiple font family names separated by commas.\n * It follows the recommendations from the CSS Fonts Module Level 4.\n * https://www.w3.org/TR/css-fonts-4/#font-family-prop\n *\n * @param {string} input - The font family.\n * @return {string} The formatted font family.\n *\n * Example:\n * formatFontFamily( \"Open Sans, Font+Name, sans-serif\" ) => '\"Open Sans\", \"Font+Name\", sans-serif'\n * formatFontFamily( \"'Open Sans', generic(kai), sans-serif\" ) => '\"Open Sans\", sans-serif'\n * formatFontFamily( \"DotGothic16, Slabo 27px, serif\" ) => '\"DotGothic16\",\"Slabo 27px\",serif'\n * formatFontFamily( \"Mine's, Moe's Typography\" ) => `\"mine's\",\"Moe's Typography\"`\n */\nexport function formatFontFamily( input ) {\n\t// Matches strings that are not exclusively alphabetic characters or hyphens, and do not exactly follow the pattern generic(alphabetic characters or hyphens).\n\tconst regex = /^(?!generic\\([ a-zA-Z\\-]+\\)$)(?!^[a-zA-Z\\-]+$).+/;\n\tconst output = input.trim();\n\n\tconst formatItem = ( item ) => {\n\t\titem = item.trim();\n\t\tif ( item.match( regex ) ) {\n\t\t\t// removes leading and trailing quotes.\n\t\t\titem = item.replace( /^[\"']|[\"']$/g, '' );\n\t\t\treturn `\"${ item }\"`;\n\t\t}\n\t\treturn item;\n\t};\n\n\tif ( output.includes( ',' ) ) {\n\t\treturn output\n\t\t\t.split( ',' )\n\t\t\t.map( formatItem )\n\t\t\t.filter( ( item ) => item !== '' )\n\t\t\t.join( ', ' );\n\t}\n\n\treturn formatItem( output );\n}\n\n/*\n * Format the font face name to use in the font-family property of a font face.\n *\n * The input can be a string with the font face name or a string with multiple font face names separated by commas.\n * It removes the leading and trailing quotes from the font face name.\n *\n * @param {string} input - The font face name.\n * @return {string} The formatted font face name.\n *\n * Example:\n * formatFontFaceName(\"Open Sans\") => \"Open Sans\"\n * formatFontFaceName(\"'Open Sans', sans-serif\") => \"Open Sans\"\n * formatFontFaceName(\", 'Open Sans', 'Helvetica Neue', sans-serif\") => \"Open Sans\"\n */\nexport function formatFontFaceName( input ) {\n\tlet output = input.trim();\n\tif ( output.includes( ',' ) ) {\n\t\toutput = output\n\t\t\t.split( ',' )\n\t\t\t// finds the first item that is not an empty string.\n\t\t\t.find( ( item ) => item.trim() !== '' )\n\t\t\t.trim();\n\t}\n\t// removes leading and trailing quotes.\n\toutput = output.replace( /^[\"']|[\"']$/g, '' );\n\n\t// Firefox needs the font name to be wrapped in double quotes meanwhile other browsers don't.\n\tif ( window.navigator.userAgent.toLowerCase().includes( 'firefox' ) ) {\n\t\toutput = `\"${ output }\"`;\n\t}\n\treturn output;\n}\n\nexport function getFamilyPreviewStyle( family ) {\n\tconst style = { fontFamily: formatFontFamily( family.fontFamily ) };\n\n\tif ( ! Array.isArray( family.fontFace ) ) {\n\t\tstyle.fontWeight = '400';\n\t\tstyle.fontStyle = 'normal';\n\t\treturn style;\n\t}\n\n\tif ( family.fontFace ) {\n\t\t//get all the font faces with normal style\n\t\tconst normalFaces = family.fontFace.filter(\n\t\t\t( face ) =>\n\t\t\t\tface?.fontStyle && face.fontStyle.toLowerCase() === 'normal'\n\t\t);\n\t\tif ( normalFaces.length > 0 ) {\n\t\t\tstyle.fontStyle = 'normal';\n\t\t\tconst normalWeights = extractFontWeights( normalFaces );\n\t\t\tconst nearestWeight = findNearest( 400, normalWeights );\n\t\t\tstyle.fontWeight = String( nearestWeight ) || '400';\n\t\t} else {\n\t\t\tstyle.fontStyle =\n\t\t\t\t( family.fontFace.length && family.fontFace[ 0 ].fontStyle ) ||\n\t\t\t\t'normal';\n\t\t\tstyle.fontWeight =\n\t\t\t\t( family.fontFace.length &&\n\t\t\t\t\tString( family.fontFace[ 0 ].fontWeight ) ) ||\n\t\t\t\t'400';\n\t\t}\n\t}\n\n\treturn style;\n}\n\nexport function getFacePreviewStyle( face ) {\n\treturn {\n\t\tfontFamily: formatFontFamily( face.fontFamily ),\n\t\tfontStyle: face.fontStyle || 'normal',\n\t\tfontWeight: face.fontWeight || '400',\n\t};\n}\n"],"mappings":"AAAA,SAASA,WAAWA,CAAEC,KAAK,EAAEC,OAAO,EAAG;EACtC;EACA,IAAKA,OAAO,CAACC,MAAM,KAAK,CAAC,EAAG;IAC3B,OAAO,IAAI;EACZ;EACA;EACAD,OAAO,CAACE,IAAI,CAAE,CAAEC,CAAC,EAAEC,CAAC,KAAMC,IAAI,CAACC,GAAG,CAAEP,KAAK,GAAGI,CAAE,CAAC,GAAGE,IAAI,CAACC,GAAG,CAAEP,KAAK,GAAGK,CAAE,CAAE,CAAC;EACzE;EACA,OAAOJ,OAAO,CAAE,CAAC,CAAE;AACpB;AAEA,SAASO,kBAAkBA,CAAEC,SAAS,EAAG;EACxC,MAAMC,MAAM,GAAG,EAAE;EAEjBD,SAAS,CAACE,OAAO,CAAIC,IAAI,IAAM;IA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AAGP,MAAM,CAACK,QAAQ,CAACd,MAAM,CACvCpB,IAAI,IACLA,IAAI,EAAEmC,SAAS,IAAInC,IAAI,CAACmC,SAAS,CAACR,WAAW,CAAC,CAAC,KAAK,QACtD,CAAC;IACD,IAAKS,WAAW,CAAC9C,MAAM,GAAG,CAAC,EAAG;MAC7BwC,KAAK,CAACK,SAAS,GAAG,QAAQ;MAC1B,MAAME,aAAa,GAAGzC,kBAAkB,CAAEwC,WAAY,CAAC;MACvD,MAAME,aAAa,GAAGnD,WAAW,CAAE,GAAG,EAAEkD,aAAc,CAAC;MACvDP,KAAK,CAAC3B,UAAU,GAAGD,MAAM,CAAEoC,aAAc,CAAC,IAAI,KAAK;IACpD,CAAC,MAAM;MACNR,KAAK,CAACK,SAAS,GACZN,MAAM,CAACK,QAAQ,CAAC5C,MAAM,IAAIuC,MAAM,CAACK,QAAQ,CAAE,CAAC,CAAE,CAACC,SAAS,IAC1D,QAAQ;MACTL,KAAK,CAAC3B,UAAU,GACb0B,MAAM,CAACK,QAAQ,CAAC5C,MAAM,IACvBY,MAAM,CAAE2B,MAAM,CAACK,QAAQ,CAAE,CAAC,CAAE,CAAC/B,UAAW,CAAC,IAC1C,KAAK;IACP;EACD;EAEA,OAAO2B,KAAK;AACb;AAEA,OAAO,SAASS,mBAAmBA,CAAEvC,IAAI,EAAG;EAC3C,OAAO;IACN+B,UAAU,EAAErB,gBAAgB,CAAEV,IAAI,CAAC+B,UAAW,CAAC;IAC/CI,SAAS,EAAEnC,IAAI,CAACmC,SAAS,IAAI,QAAQ;IACrChC,UAAU,EAAEH,IAAI,CAACG,UAAU,IAAI;EAChC,CAAC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useViewportMatch","__experimentalVStack","VStack","__experimentalPaletteEdit","PaletteEdit","__experimentalSpacer","Spacer","DuotonePicker","__","privateApis","blockEditorPrivateApis","Subtitle","unlock","useGlobalSetting","mobilePopoverProps","placement","offset","noop","GradientPalettePanel","name","themeGradients","setThemeGradients","baseThemeGradients","defaultGradients","setDefaultGradients","baseDefaultGradients","customGradients","setCustomGradients","defaultPaletteEnabled","customDuotone","defaultDuotone","themeDuotone","defaultDuotoneEnabled","duotonePalette","isMobileViewport","popoverProps","undefined","createElement","className","spacing","length","canReset","canOnlyChangeValues","gradients","onChange","paletteLabel","paletteLabelHeadingLevel","paletteLabelLevel","emptyMessage","slugPrefix","level","margin","disableCustomDuotone","disableCustomColors","clearable"],"sources":["@wordpress/edit-site/src/components/global-styles/gradients-palette-panel.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\t__experimentalVStack as VStack,\n\t__experimentalPaletteEdit as PaletteEdit,\n\t__experimentalSpacer as Spacer,\n\tDuotonePicker,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Subtitle from './subtitle';\nimport { unlock } from '../../lock-unlock';\n\nconst { useGlobalSetting } = unlock( blockEditorPrivateApis );\nconst mobilePopoverProps = { placement: 'bottom-start', offset: 8 };\n\nconst noop = () => {};\n\nexport default function GradientPalettePanel( { name } ) {\n\tconst [ themeGradients, setThemeGradients ] = useGlobalSetting(\n\t\t'color.gradients.theme',\n\t\tname\n\t);\n\tconst [ baseThemeGradients ] = useGlobalSetting(\n\t\t'color.gradients.theme',\n\t\tname,\n\t\t'base'\n\t);\n\tconst [ defaultGradients, setDefaultGradients ] = useGlobalSetting(\n\t\t'color.gradients.default',\n\t\tname\n\t);\n\tconst [ baseDefaultGradients ] = useGlobalSetting(\n\t\t'color.gradients.default',\n\t\tname,\n\t\t'base'\n\t);\n\tconst [ customGradients, setCustomGradients ] = useGlobalSetting(\n\t\t'color.gradients.custom',\n\t\tname\n\t);\n\n\tconst [ defaultPaletteEnabled ] = useGlobalSetting(\n\t\t'color.defaultGradients',\n\t\tname\n\t);\n\n\tconst [ customDuotone ] = useGlobalSetting( 'color.duotone.custom' ) || [];\n\tconst [ defaultDuotone ] =\n\t\tuseGlobalSetting( 'color.duotone.default' ) || [];\n\tconst [ themeDuotone ] = useGlobalSetting( 'color.duotone.theme' ) || [];\n\tconst [ defaultDuotoneEnabled ] = useGlobalSetting(\n\t\t'color.defaultDuotone'\n\t);\n\n\tconst duotonePalette = [\n\t\t...( customDuotone || [] ),\n\t\t...( themeDuotone || [] ),\n\t\t...( defaultDuotone && defaultDuotoneEnabled ? defaultDuotone : [] ),\n\t];\n\n\tconst isMobileViewport = useViewportMatch( 'small', '<' );\n\tconst popoverProps = isMobileViewport ? mobilePopoverProps : undefined;\n\n\treturn (\n\t\t<VStack\n\t\t\tclassName=\"edit-site-global-styles-gradient-palette-panel\"\n\t\t\tspacing={ 10 }\n\t\t>\n\t\t\t{ !! themeGradients && !! themeGradients.length && (\n\t\t\t\t<PaletteEdit\n\t\t\t\t\tcanReset={ themeGradients !== baseThemeGradients }\n\t\t\t\t\tcanOnlyChangeValues\n\t\t\t\t\tgradients={ themeGradients }\n\t\t\t\t\tonChange={ setThemeGradients }\n\t\t\t\t\tpaletteLabel={ __( 'Theme' ) }\n\t\t\t\t\tpaletteLabelHeadingLevel={ 3 }\n\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! defaultGradients &&\n\t\t\t\t!! defaultGradients.length &&\n\t\t\t\t!! defaultPaletteEnabled && (\n\t\t\t\t\t<PaletteEdit\n\t\t\t\t\t\tcanReset={ defaultGradients !== baseDefaultGradients }\n\t\t\t\t\t\tcanOnlyChangeValues\n\t\t\t\t\t\tgradients={ defaultGradients }\n\t\t\t\t\t\tonChange={ setDefaultGradients }\n\t\t\t\t\t\tpaletteLabel={ __( 'Default' ) }\n\t\t\t\t\t\tpaletteLabelLevel={ 3 }\n\t\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t<PaletteEdit\n\t\t\t\tgradients={ customGradients }\n\t\t\t\tonChange={ setCustomGradients }\n\t\t\t\tpaletteLabel={ __( 'Custom' ) }\n\t\t\t\tpaletteLabelLevel={ 3 }\n\t\t\t\temptyMessage={ __(\n\t\t\t\t\t'Custom gradients are empty! Add some gradients to create your own palette.'\n\t\t\t\t) }\n\t\t\t\tslugPrefix=\"custom-\"\n\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t/>\n\t\t\t{ !! duotonePalette && !! duotonePalette.length && (\n\t\t\t\t<div>\n\t\t\t\t\t<Subtitle level={ 3 }>{ __( 'Duotone' ) }</Subtitle>\n\t\t\t\t\t<Spacer margin={ 3 } />\n\t\t\t\t\t<DuotonePicker\n\t\t\t\t\t\tduotonePalette={ duotonePalette }\n\t\t\t\t\t\tdisableCustomDuotone
|
|
1
|
+
{"version":3,"names":["useViewportMatch","__experimentalVStack","VStack","__experimentalPaletteEdit","PaletteEdit","__experimentalSpacer","Spacer","DuotonePicker","__","privateApis","blockEditorPrivateApis","Subtitle","unlock","useGlobalSetting","mobilePopoverProps","placement","offset","noop","GradientPalettePanel","name","themeGradients","setThemeGradients","baseThemeGradients","defaultGradients","setDefaultGradients","baseDefaultGradients","customGradients","setCustomGradients","defaultPaletteEnabled","customDuotone","defaultDuotone","themeDuotone","defaultDuotoneEnabled","duotonePalette","isMobileViewport","popoverProps","undefined","createElement","className","spacing","length","canReset","canOnlyChangeValues","gradients","onChange","paletteLabel","paletteLabelHeadingLevel","paletteLabelLevel","emptyMessage","slugPrefix","level","margin","disableCustomDuotone","disableCustomColors","clearable"],"sources":["@wordpress/edit-site/src/components/global-styles/gradients-palette-panel.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\t__experimentalVStack as VStack,\n\t__experimentalPaletteEdit as PaletteEdit,\n\t__experimentalSpacer as Spacer,\n\tDuotonePicker,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Subtitle from './subtitle';\nimport { unlock } from '../../lock-unlock';\n\nconst { useGlobalSetting } = unlock( blockEditorPrivateApis );\nconst mobilePopoverProps = { placement: 'bottom-start', offset: 8 };\n\nconst noop = () => {};\n\nexport default function GradientPalettePanel( { name } ) {\n\tconst [ themeGradients, setThemeGradients ] = useGlobalSetting(\n\t\t'color.gradients.theme',\n\t\tname\n\t);\n\tconst [ baseThemeGradients ] = useGlobalSetting(\n\t\t'color.gradients.theme',\n\t\tname,\n\t\t'base'\n\t);\n\tconst [ defaultGradients, setDefaultGradients ] = useGlobalSetting(\n\t\t'color.gradients.default',\n\t\tname\n\t);\n\tconst [ baseDefaultGradients ] = useGlobalSetting(\n\t\t'color.gradients.default',\n\t\tname,\n\t\t'base'\n\t);\n\tconst [ customGradients, setCustomGradients ] = useGlobalSetting(\n\t\t'color.gradients.custom',\n\t\tname\n\t);\n\n\tconst [ defaultPaletteEnabled ] = useGlobalSetting(\n\t\t'color.defaultGradients',\n\t\tname\n\t);\n\n\tconst [ customDuotone ] = useGlobalSetting( 'color.duotone.custom' ) || [];\n\tconst [ defaultDuotone ] =\n\t\tuseGlobalSetting( 'color.duotone.default' ) || [];\n\tconst [ themeDuotone ] = useGlobalSetting( 'color.duotone.theme' ) || [];\n\tconst [ defaultDuotoneEnabled ] = useGlobalSetting(\n\t\t'color.defaultDuotone'\n\t);\n\n\tconst duotonePalette = [\n\t\t...( customDuotone || [] ),\n\t\t...( themeDuotone || [] ),\n\t\t...( defaultDuotone && defaultDuotoneEnabled ? defaultDuotone : [] ),\n\t];\n\n\tconst isMobileViewport = useViewportMatch( 'small', '<' );\n\tconst popoverProps = isMobileViewport ? mobilePopoverProps : undefined;\n\n\treturn (\n\t\t<VStack\n\t\t\tclassName=\"edit-site-global-styles-gradient-palette-panel\"\n\t\t\tspacing={ 10 }\n\t\t>\n\t\t\t{ !! themeGradients && !! themeGradients.length && (\n\t\t\t\t<PaletteEdit\n\t\t\t\t\tcanReset={ themeGradients !== baseThemeGradients }\n\t\t\t\t\tcanOnlyChangeValues\n\t\t\t\t\tgradients={ themeGradients }\n\t\t\t\t\tonChange={ setThemeGradients }\n\t\t\t\t\tpaletteLabel={ __( 'Theme' ) }\n\t\t\t\t\tpaletteLabelHeadingLevel={ 3 }\n\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! defaultGradients &&\n\t\t\t\t!! defaultGradients.length &&\n\t\t\t\t!! defaultPaletteEnabled && (\n\t\t\t\t\t<PaletteEdit\n\t\t\t\t\t\tcanReset={ defaultGradients !== baseDefaultGradients }\n\t\t\t\t\t\tcanOnlyChangeValues\n\t\t\t\t\t\tgradients={ defaultGradients }\n\t\t\t\t\t\tonChange={ setDefaultGradients }\n\t\t\t\t\t\tpaletteLabel={ __( 'Default' ) }\n\t\t\t\t\t\tpaletteLabelLevel={ 3 }\n\t\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t<PaletteEdit\n\t\t\t\tgradients={ customGradients }\n\t\t\t\tonChange={ setCustomGradients }\n\t\t\t\tpaletteLabel={ __( 'Custom' ) }\n\t\t\t\tpaletteLabelLevel={ 3 }\n\t\t\t\temptyMessage={ __(\n\t\t\t\t\t'Custom gradients are empty! Add some gradients to create your own palette.'\n\t\t\t\t) }\n\t\t\t\tslugPrefix=\"custom-\"\n\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t/>\n\t\t\t{ !! duotonePalette && !! duotonePalette.length && (\n\t\t\t\t<div>\n\t\t\t\t\t<Subtitle level={ 3 }>{ __( 'Duotone' ) }</Subtitle>\n\t\t\t\t\t<Spacer margin={ 3 } />\n\t\t\t\t\t<DuotonePicker\n\t\t\t\t\t\tduotonePalette={ duotonePalette }\n\t\t\t\t\t\tdisableCustomDuotone\n\t\t\t\t\t\tdisableCustomColors\n\t\t\t\t\t\tclearable={ false }\n\t\t\t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oBAAsB;IACtDiB,mBAAmB;IACnBC,SAAS,EAAGpB,gBAAkB;IAC9BqB,QAAQ,EAAGpB,mBAAqB;IAChCqB,YAAY,EAAGrC,EAAE,CAAE,SAAU,CAAG;IAChCuC,iBAAiB,EAAG,CAAG;IACvBZ,YAAY,EAAGA;EAAc,CAC7B,CACD,EACFE,aAAA,CAACjC,WAAW;IACXuC,SAAS,EAAGjB,eAAiB;IAC7BkB,QAAQ,EAAGjB,kBAAoB;IAC/BkB,YAAY,EAAGrC,EAAE,CAAE,QAAS,CAAG;IAC/BuC,iBAAiB,EAAG,CAAG;IACvBC,YAAY,EAAGxC,EAAE,CAChB,4EACD,CAAG;IACHyC,UAAU,EAAC,SAAS;IACpBd,YAAY,EAAGA;EAAc,CAC7B,CAAC,EACA,CAAC,CAAEF,cAAc,IAAI,CAAC,CAAEA,cAAc,CAACO,MAAM,IAC9CH,aAAA,cACCA,aAAA,CAAC1B,QAAQ;IAACuC,KAAK,EAAG;EAAG,GAAG1C,EAAE,CAAE,SAAU,CAAa,CAAC,EACpD6B,aAAA,CAAC/B,MAAM;IAAC6C,MAAM,EAAG;EAAG,CAAE,CAAC,EACvBd,aAAA,CAAC9B,aAAa;IACb0B,cAAc,EAAGA,cAAgB;IACjCmB,oBAAoB;IACpBC,mBAAmB;IACnBC,SAAS,EAAG,KAAO;IACnBV,QAAQ,EAAG3B;EAAM,CACjB,CACG,CAEC,CAAC;AAEX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__experimentalHStack","HStack","__experimentalVStack","VStack","__experimentalSpacer","Spacer","__experimentalHeading","Heading","__experimentalView","View","__experimentalNavigatorToParentButton","NavigatorToParentButton","isRTL","__","chevronRight","chevronLeft","ScreenHeader","title","description","onBack","createElement","spacing","marginBottom","paddingX","paddingY","style","minWidth","padding","icon","
|
|
1
|
+
{"version":3,"names":["__experimentalHStack","HStack","__experimentalVStack","VStack","__experimentalSpacer","Spacer","__experimentalHeading","Heading","__experimentalView","View","__experimentalNavigatorToParentButton","NavigatorToParentButton","isRTL","__","chevronRight","chevronLeft","ScreenHeader","title","description","onBack","createElement","spacing","marginBottom","paddingX","paddingY","style","minWidth","padding","icon","size","onClick","className","level"],"sources":["@wordpress/edit-site/src/components/global-styles/header.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\t__experimentalSpacer as Spacer,\n\t__experimentalHeading as Heading,\n\t__experimentalView as View,\n\t__experimentalNavigatorToParentButton as NavigatorToParentButton,\n} from '@wordpress/components';\nimport { isRTL, __ } from '@wordpress/i18n';\nimport { chevronRight, chevronLeft } from '@wordpress/icons';\n\nfunction ScreenHeader( { title, description, onBack } ) {\n\treturn (\n\t\t<VStack spacing={ 0 }>\n\t\t\t<View>\n\t\t\t\t<Spacer marginBottom={ 0 } paddingX={ 4 } paddingY={ 3 }>\n\t\t\t\t\t<HStack spacing={ 2 }>\n\t\t\t\t\t\t<NavigatorToParentButton\n\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t// TODO: This style override is also used in ToolsPanelHeader.\n\t\t\t\t\t\t\t\t// It should be supported out-of-the-box by Button.\n\t\t\t\t\t\t\t\t{ minWidth: 24, padding: 0 }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ticon={ isRTL() ? chevronRight : chevronLeft }\n\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\taria-label={ __( 'Navigate to the previous view' ) }\n\t\t\t\t\t\t\tonClick={ onBack }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Spacer>\n\t\t\t\t\t\t\t<Heading\n\t\t\t\t\t\t\t\tclassName=\"edit-site-global-styles-header\"\n\t\t\t\t\t\t\t\tlevel={ 2 }\n\t\t\t\t\t\t\t\tsize={ 13 }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t</Heading>\n\t\t\t\t\t\t</Spacer>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Spacer>\n\t\t\t</View>\n\t\t\t{ description && (\n\t\t\t\t<p className=\"edit-site-global-styles-header__description\">\n\t\t\t\t\t{ description }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</VStack>\n\t);\n}\n\nexport default ScreenHeader;\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,qBAAqB,IAAIC,OAAO,EAChCC,kBAAkB,IAAIC,IAAI,EAC1BC,qCAAqC,IAAIC,uBAAuB,QAC1D,uBAAuB;AAC9B,SAASC,KAAK,EAAEC,EAAE,QAAQ,iBAAiB;AAC3C,SAASC,YAAY,EAAEC,WAAW,QAAQ,kBAAkB;AAE5D,SAASC,YAAYA,CAAE;EAAEC,KAAK;EAAEC,WAAW;EAAEC;AAAO,CAAC,EAAG;EACvD,OACCC,aAAA,CAACjB,MAAM;IAACkB,OAAO,EAAG;EAAG,GACpBD,aAAA,CAACX,IAAI,QACJW,aAAA,CAACf,MAAM;IAACiB,YAAY,EAAG,CAAG;IAACC,QAAQ,EAAG,CAAG;IAACC,QAAQ,EAAG;EAAG,GACvDJ,aAAA,CAACnB,MAAM;IAACoB,OAAO,EAAG;EAAG,GACpBD,aAAA,CAACT,uBAAuB;IACvBc,KAAK;IACJ;IACA;IACA;MAAEC,QAAQ,EAAE,EAAE;MAAEC,OAAO,EAAE;IAAE,CAC3B;IACDC,IAAI,EAAGhB,KAAK,CAAC,CAAC,GAAGE,YAAY,GAAGC,WAAa;IAC7Cc,IAAI,EAAC,OAAO;IACZ,cAAahB,EAAE,CAAE,+BAAgC,CAAG;IACpDiB,OAAO,EAAGX;EAAQ,CAClB,CAAC,EACFC,aAAA,CAACf,MAAM,QACNe,aAAA,CAACb,OAAO;IACPwB,SAAS,EAAC,gCAAgC;IAC1CC,KAAK,EAAG,CAAG;IACXH,IAAI,EAAG;EAAI,GAETZ,KACM,CACF,CACD,CACD,CACH,CAAC,EACLC,WAAW,IACZE,aAAA;IAAGW,SAAS,EAAC;EAA6C,GACvDb,WACA,CAEG,CAAC;AAEX;AAEA,eAAeF,YAAY"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { __unstableMotion as motion } from '@wordpress/components';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { useStylesPreviewColors } from './hooks';
|
|
11
|
+
export default function HighlightedColors({
|
|
12
|
+
normalizedColorSwatchSize,
|
|
13
|
+
ratio
|
|
14
|
+
}) {
|
|
15
|
+
const {
|
|
16
|
+
highlightedColors
|
|
17
|
+
} = useStylesPreviewColors();
|
|
18
|
+
const scaledSwatchSize = normalizedColorSwatchSize * ratio;
|
|
19
|
+
return highlightedColors.map(({
|
|
20
|
+
slug,
|
|
21
|
+
color
|
|
22
|
+
}, index) => createElement(motion.div, {
|
|
23
|
+
key: slug,
|
|
24
|
+
style: {
|
|
25
|
+
height: scaledSwatchSize,
|
|
26
|
+
width: scaledSwatchSize,
|
|
27
|
+
background: color,
|
|
28
|
+
borderRadius: scaledSwatchSize / 2
|
|
29
|
+
},
|
|
30
|
+
animate: {
|
|
31
|
+
scale: 1,
|
|
32
|
+
opacity: 1
|
|
33
|
+
},
|
|
34
|
+
initial: {
|
|
35
|
+
scale: 0.1,
|
|
36
|
+
opacity: 0
|
|
37
|
+
},
|
|
38
|
+
transition: {
|
|
39
|
+
delay: index === 1 ? 0.2 : 0.1
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=highlighted-colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__unstableMotion","motion","useStylesPreviewColors","HighlightedColors","normalizedColorSwatchSize","ratio","highlightedColors","scaledSwatchSize","map","slug","color","index","createElement","div","key","style","height","width","background","borderRadius","animate","scale","opacity","initial","transition","delay"],"sources":["@wordpress/edit-site/src/components/global-styles/highlighted-colors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __unstableMotion as motion } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { useStylesPreviewColors } from './hooks';\n\nexport default function HighlightedColors( {\n\tnormalizedColorSwatchSize,\n\tratio,\n} ) {\n\tconst { highlightedColors } = useStylesPreviewColors();\n\tconst scaledSwatchSize = normalizedColorSwatchSize * ratio;\n\treturn highlightedColors.map( ( { slug, color }, index ) => (\n\t\t<motion.div\n\t\t\tkey={ slug }\n\t\t\tstyle={ {\n\t\t\t\theight: scaledSwatchSize,\n\t\t\t\twidth: scaledSwatchSize,\n\t\t\t\tbackground: color,\n\t\t\t\tborderRadius: scaledSwatchSize / 2,\n\t\t\t} }\n\t\t\tanimate={ {\n\t\t\t\tscale: 1,\n\t\t\t\topacity: 1,\n\t\t\t} }\n\t\t\tinitial={ {\n\t\t\t\tscale: 0.1,\n\t\t\t\topacity: 0,\n\t\t\t} }\n\t\t\ttransition={ {\n\t\t\t\tdelay: index === 1 ? 0.2 : 0.1,\n\t\t\t} }\n\t\t/>\n\t) );\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,gBAAgB,IAAIC,MAAM,QAAQ,uBAAuB;;AAElE;AACA;AACA;AACA,SAASC,sBAAsB,QAAQ,SAAS;AAEhD,eAAe,SAASC,iBAAiBA,CAAE;EAC1CC,yBAAyB;EACzBC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC;EAAkB,CAAC,GAAGJ,sBAAsB,CAAC,CAAC;EACtD,MAAMK,gBAAgB,GAAGH,yBAAyB,GAAGC,KAAK;EAC1D,OAAOC,iBAAiB,CAACE,GAAG,CAAE,CAAE;IAAEC,IAAI;IAAEC;EAAM,CAAC,EAAEC,KAAK,KACrDC,aAAA,CAACX,MAAM,CAACY,GAAG;IACVC,GAAG,EAAGL,IAAM;IACZM,KAAK,EAAG;MACPC,MAAM,EAAET,gBAAgB;MACxBU,KAAK,EAAEV,gBAAgB;MACvBW,UAAU,EAAER,KAAK;MACjBS,YAAY,EAAEZ,gBAAgB,GAAG;IAClC,CAAG;IACHa,OAAO,EAAG;MACTC,KAAK,EAAE,CAAC;MACRC,OAAO,EAAE;IACV,CAAG;IACHC,OAAO,EAAG;MACTF,KAAK,EAAE,GAAG;MACVC,OAAO,EAAE;IACV,CAAG;IACHE,UAAU,EAAG;MACZC,KAAK,EAAEd,KAAK,KAAK,CAAC,GAAG,GAAG,GAAG;IAC5B;EAAG,CACH,CACA,CAAC;AACJ"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { __experimentalHStack as HStack, __unstableMotion as motion } from '@wordpress/components';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import HighlightedColors from './highlighted-colors';
|
|
11
|
+
import PreviewIframe from './preview-iframe';
|
|
12
|
+
const firstFrameVariants = {
|
|
13
|
+
start: {
|
|
14
|
+
scale: 1,
|
|
15
|
+
opacity: 1
|
|
16
|
+
},
|
|
17
|
+
hover: {
|
|
18
|
+
scale: 0,
|
|
19
|
+
opacity: 0
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const StylesPreviewColors = ({
|
|
23
|
+
label,
|
|
24
|
+
isFocused,
|
|
25
|
+
withHoverView
|
|
26
|
+
}) => {
|
|
27
|
+
return createElement(PreviewIframe, {
|
|
28
|
+
label: label,
|
|
29
|
+
isFocused: isFocused,
|
|
30
|
+
withHoverView: withHoverView
|
|
31
|
+
}, ({
|
|
32
|
+
ratio,
|
|
33
|
+
key
|
|
34
|
+
}) => createElement(motion.div, {
|
|
35
|
+
key: key,
|
|
36
|
+
variants: firstFrameVariants,
|
|
37
|
+
style: {
|
|
38
|
+
height: '100%',
|
|
39
|
+
overflow: 'hidden'
|
|
40
|
+
}
|
|
41
|
+
}, createElement(HStack, {
|
|
42
|
+
spacing: 10 * ratio,
|
|
43
|
+
justify: "center",
|
|
44
|
+
style: {
|
|
45
|
+
height: '100%',
|
|
46
|
+
overflow: 'hidden'
|
|
47
|
+
}
|
|
48
|
+
}, createElement(HighlightedColors, {
|
|
49
|
+
normalizedColorSwatchSize: 66,
|
|
50
|
+
ratio: ratio
|
|
51
|
+
}))));
|
|
52
|
+
};
|
|
53
|
+
export default StylesPreviewColors;
|
|
54
|
+
//# sourceMappingURL=preview-colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__experimentalHStack","HStack","__unstableMotion","motion","HighlightedColors","PreviewIframe","firstFrameVariants","start","scale","opacity","hover","StylesPreviewColors","label","isFocused","withHoverView","createElement","ratio","key","div","variants","style","height","overflow","spacing","justify","normalizedColorSwatchSize"],"sources":["@wordpress/edit-site/src/components/global-styles/preview-colors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalHStack as HStack,\n\t__unstableMotion as motion,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport HighlightedColors from './highlighted-colors';\nimport PreviewIframe from './preview-iframe';\n\nconst firstFrameVariants = {\n\tstart: {\n\t\tscale: 1,\n\t\topacity: 1,\n\t},\n\thover: {\n\t\tscale: 0,\n\t\topacity: 0,\n\t},\n};\n\nconst StylesPreviewColors = ( { label, isFocused, withHoverView } ) => {\n\treturn (\n\t\t<PreviewIframe\n\t\t\tlabel={ label }\n\t\t\tisFocused={ isFocused }\n\t\t\twithHoverView={ withHoverView }\n\t\t>\n\t\t\t{ ( { ratio, key } ) => (\n\t\t\t\t<motion.div\n\t\t\t\t\tkey={ key }\n\t\t\t\t\tvariants={ firstFrameVariants }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\theight: '100%',\n\t\t\t\t\t\toverflow: 'hidden',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\tspacing={ 10 * ratio }\n\t\t\t\t\t\tjustify=\"center\"\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\theight: '100%',\n\t\t\t\t\t\t\toverflow: 'hidden',\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<HighlightedColors\n\t\t\t\t\t\t\tnormalizedColorSwatchSize={ 66 }\n\t\t\t\t\t\t\tratio={ ratio }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</HStack>\n\t\t\t\t</motion.div>\n\t\t\t) }\n\t\t</PreviewIframe>\n\t);\n};\n\nexport default StylesPreviewColors;\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,oBAAoB,IAAIC,MAAM,EAC9BC,gBAAgB,IAAIC,MAAM,QACpB,uBAAuB;;AAE9B;AACA;AACA;AACA,OAAOC,iBAAiB,MAAM,sBAAsB;AACpD,OAAOC,aAAa,MAAM,kBAAkB;AAE5C,MAAMC,kBAAkB,GAAG;EAC1BC,KAAK,EAAE;IACNC,KAAK,EAAE,CAAC;IACRC,OAAO,EAAE;EACV,CAAC;EACDC,KAAK,EAAE;IACNF,KAAK,EAAE,CAAC;IACRC,OAAO,EAAE;EACV;AACD,CAAC;AAED,MAAME,mBAAmB,GAAGA,CAAE;EAAEC,KAAK;EAAEC,SAAS;EAAEC;AAAc,CAAC,KAAM;EACtE,OACCC,aAAA,CAACV,aAAa;IACbO,KAAK,EAAGA,KAAO;IACfC,SAAS,EAAGA,SAAW;IACvBC,aAAa,EAAGA;EAAe,GAE7B,CAAE;IAAEE,KAAK;IAAEC;EAAI,CAAC,KACjBF,aAAA,CAACZ,MAAM,CAACe,GAAG;IACVD,GAAG,EAAGA,GAAK;IACXE,QAAQ,EAAGb,kBAAoB;IAC/Bc,KAAK,EAAG;MACPC,MAAM,EAAE,MAAM;MACdC,QAAQ,EAAE;IACX;EAAG,GAEHP,aAAA,CAACd,MAAM;IACNsB,OAAO,EAAG,EAAE,GAAGP,KAAO;IACtBQ,OAAO,EAAC,QAAQ;IAChBJ,KAAK,EAAG;MACPC,MAAM,EAAE,MAAM;MACdC,QAAQ,EAAE;IACX;EAAG,GAEHP,aAAA,CAACX,iBAAiB;IACjBqB,yBAAyB,EAAG,EAAI;IAChCT,KAAK,EAAGA;EAAO,CACf,CACM,CACG,CAEC,CAAC;AAElB,CAAC;AAED,eAAeL,mBAAmB"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { createElement, Fragment } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { __unstableIframe as Iframe, __unstableEditorStyles as EditorStyles, privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
6
|
+
import { __unstableMotion as motion } from '@wordpress/components';
|
|
7
|
+
import { useThrottle, useReducedMotion, useResizeObserver } from '@wordpress/compose';
|
|
8
|
+
import { useLayoutEffect, useState, useMemo } from '@wordpress/element';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { unlock } from '../../lock-unlock';
|
|
14
|
+
const {
|
|
15
|
+
useGlobalStyle,
|
|
16
|
+
useGlobalStylesOutput
|
|
17
|
+
} = unlock(blockEditorPrivateApis);
|
|
18
|
+
const normalizedWidth = 248;
|
|
19
|
+
const normalizedHeight = 152;
|
|
20
|
+
|
|
21
|
+
// Throttle options for useThrottle. Must be defined outside of the component,
|
|
22
|
+
// so that the object reference is the same on each render.
|
|
23
|
+
const THROTTLE_OPTIONS = {
|
|
24
|
+
leading: true,
|
|
25
|
+
trailing: true
|
|
26
|
+
};
|
|
27
|
+
export default function PreviewIframe({
|
|
28
|
+
children,
|
|
29
|
+
label,
|
|
30
|
+
isFocused,
|
|
31
|
+
withHoverView
|
|
32
|
+
}) {
|
|
33
|
+
const [backgroundColor = 'white'] = useGlobalStyle('color.background');
|
|
34
|
+
const [gradientValue] = useGlobalStyle('color.gradient');
|
|
35
|
+
const [styles] = useGlobalStylesOutput();
|
|
36
|
+
const disableMotion = useReducedMotion();
|
|
37
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
38
|
+
const [containerResizeListener, {
|
|
39
|
+
width
|
|
40
|
+
}] = useResizeObserver();
|
|
41
|
+
const [throttledWidth, setThrottledWidthState] = useState(width);
|
|
42
|
+
const [ratioState, setRatioState] = useState();
|
|
43
|
+
const setThrottledWidth = useThrottle(setThrottledWidthState, 250, THROTTLE_OPTIONS);
|
|
44
|
+
|
|
45
|
+
// Must use useLayoutEffect to avoid a flash of the iframe at the wrong
|
|
46
|
+
// size before the width is set.
|
|
47
|
+
useLayoutEffect(() => {
|
|
48
|
+
if (width) {
|
|
49
|
+
setThrottledWidth(width);
|
|
50
|
+
}
|
|
51
|
+
}, [width, setThrottledWidth]);
|
|
52
|
+
|
|
53
|
+
// Must use useLayoutEffect to avoid a flash of the iframe at the wrong
|
|
54
|
+
// size before the width is set.
|
|
55
|
+
useLayoutEffect(() => {
|
|
56
|
+
const newRatio = throttledWidth ? throttledWidth / normalizedWidth : 1;
|
|
57
|
+
const ratioDiff = newRatio - (ratioState || 0);
|
|
58
|
+
|
|
59
|
+
// Only update the ratio state if the difference is big enough
|
|
60
|
+
// or if the ratio state is not yet set. This is to avoid an
|
|
61
|
+
// endless loop of updates at particular viewport heights when the
|
|
62
|
+
// presence of a scrollbar causes the width to change slightly.
|
|
63
|
+
const isRatioDiffBigEnough = Math.abs(ratioDiff) > 0.1;
|
|
64
|
+
if (isRatioDiffBigEnough || !ratioState) {
|
|
65
|
+
setRatioState(newRatio);
|
|
66
|
+
}
|
|
67
|
+
}, [throttledWidth, ratioState]);
|
|
68
|
+
|
|
69
|
+
// Set a fallbackRatio to use before the throttled ratio has been set.
|
|
70
|
+
const fallbackRatio = width ? width / normalizedWidth : 1;
|
|
71
|
+
/*
|
|
72
|
+
* Use the throttled ratio if it has been calculated, otherwise
|
|
73
|
+
* use the fallback ratio. The throttled ratio is used to avoid
|
|
74
|
+
* an endless loop of updates at particular viewport heights.
|
|
75
|
+
* See: https://github.com/WordPress/gutenberg/issues/55112
|
|
76
|
+
*/
|
|
77
|
+
const ratio = ratioState ? ratioState : fallbackRatio;
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* Reset leaked styles from WP common.css and remove main content layout padding and border.
|
|
81
|
+
* Add pointer cursor to the body to indicate the iframe is interactive,
|
|
82
|
+
* similar to Typography variation previews.
|
|
83
|
+
*/
|
|
84
|
+
const editorStyles = useMemo(() => {
|
|
85
|
+
if (styles) {
|
|
86
|
+
return [...styles, {
|
|
87
|
+
css: 'html{overflow:hidden}body{min-width: 0;padding: 0;border: none;cursor: pointer;}',
|
|
88
|
+
isGlobalStyles: true
|
|
89
|
+
}];
|
|
90
|
+
}
|
|
91
|
+
return styles;
|
|
92
|
+
}, [styles]);
|
|
93
|
+
const isReady = !!width;
|
|
94
|
+
return createElement(Fragment, null, createElement("div", {
|
|
95
|
+
style: {
|
|
96
|
+
position: 'relative'
|
|
97
|
+
}
|
|
98
|
+
}, containerResizeListener), isReady && createElement(Iframe, {
|
|
99
|
+
className: "edit-site-global-styles-preview__iframe",
|
|
100
|
+
style: {
|
|
101
|
+
width: '100%',
|
|
102
|
+
height: normalizedHeight * ratio
|
|
103
|
+
},
|
|
104
|
+
onMouseEnter: () => setIsHovered(true),
|
|
105
|
+
onMouseLeave: () => setIsHovered(false),
|
|
106
|
+
tabIndex: -1
|
|
107
|
+
}, createElement(EditorStyles, {
|
|
108
|
+
styles: editorStyles
|
|
109
|
+
}), createElement(motion.div, {
|
|
110
|
+
style: {
|
|
111
|
+
height: normalizedHeight * ratio,
|
|
112
|
+
width: '100%',
|
|
113
|
+
background: gradientValue !== null && gradientValue !== void 0 ? gradientValue : backgroundColor,
|
|
114
|
+
cursor: withHoverView ? 'pointer' : undefined
|
|
115
|
+
},
|
|
116
|
+
initial: "start",
|
|
117
|
+
animate: (isHovered || isFocused) && !disableMotion && label ? 'hover' : 'start'
|
|
118
|
+
}, [].concat(children) // This makes sure children is always an array.
|
|
119
|
+
.map((child, key) => child({
|
|
120
|
+
ratio,
|
|
121
|
+
key
|
|
122
|
+
})))));
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=preview-iframe.js.map
|