@wordpress/global-styles-ui 1.1.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/LICENSE.md +788 -0
- package/README.md +48 -0
- package/build/background-panel.js +62 -0
- package/build/background-panel.js.map +7 -0
- package/build/block-preview-panel.js +90 -0
- package/build/block-preview-panel.js.map +7 -0
- package/build/color-indicator-wrapper.js +55 -0
- package/build/color-indicator-wrapper.js.map +7 -0
- package/build/color-palette-panel.js +123 -0
- package/build/color-palette-panel.js.map +7 -0
- package/build/color-preview.js +94 -0
- package/build/color-preview.js.map +7 -0
- package/build/color-variations.js +41 -0
- package/build/color-variations.js.map +7 -0
- package/build/confirm-reset-shadow-dialog.js +55 -0
- package/build/confirm-reset-shadow-dialog.js.map +7 -0
- package/build/context.js +37 -0
- package/build/context.js.map +7 -0
- package/build/dimensions-panel.js +89 -0
- package/build/dimensions-panel.js.map +7 -0
- package/build/font-families.js +114 -0
- package/build/font-families.js.map +7 -0
- package/build/font-family-item.js +48 -0
- package/build/font-family-item.js.map +7 -0
- package/build/font-library-modal/collection-font-variant.js +75 -0
- package/build/font-library-modal/collection-font-variant.js.map +7 -0
- package/build/font-library-modal/context.js +386 -0
- package/build/font-library-modal/context.js.map +7 -0
- package/build/font-library-modal/font-card.js +81 -0
- package/build/font-library-modal/font-card.js.map +7 -0
- package/build/font-library-modal/font-collection.js +510 -0
- package/build/font-library-modal/font-collection.js.map +7 -0
- package/build/font-library-modal/font-demo.js +111 -0
- package/build/font-library-modal/font-demo.js.map +7 -0
- package/build/font-library-modal/google-fonts-confirm-dialog.js +58 -0
- package/build/font-library-modal/google-fonts-confirm-dialog.js.map +7 -0
- package/build/font-library-modal/index.js +110 -0
- package/build/font-library-modal/index.js.map +7 -0
- package/build/font-library-modal/installed-fonts.js +453 -0
- package/build/font-library-modal/installed-fonts.js.map +7 -0
- package/build/font-library-modal/lib/inflate.js +2628 -0
- package/build/font-library-modal/lib/inflate.js.map +7 -0
- package/build/font-library-modal/lib/lib-font.browser.d.js +33 -0
- package/build/font-library-modal/lib/lib-font.browser.d.js.map +7 -0
- package/build/font-library-modal/lib/lib-font.browser.js +3788 -0
- package/build/font-library-modal/lib/lib-font.browser.js.map +7 -0
- package/build/font-library-modal/lib/unbrotli.js +3678 -0
- package/build/font-library-modal/lib/unbrotli.js.map +7 -0
- package/build/font-library-modal/library-font-details.js +63 -0
- package/build/font-library-modal/library-font-details.js.map +7 -0
- package/build/font-library-modal/library-font-variant.js +81 -0
- package/build/font-library-modal/library-font-variant.js.map +7 -0
- package/build/font-library-modal/resolvers.js +115 -0
- package/build/font-library-modal/resolvers.js.map +7 -0
- package/build/font-library-modal/types.js +17 -0
- package/build/font-library-modal/types.js.map +7 -0
- package/build/font-library-modal/upload-fonts.js +207 -0
- package/build/font-library-modal/upload-fonts.js.map +7 -0
- package/build/font-library-modal/utils/constants.js +49 -0
- package/build/font-library-modal/utils/constants.js.map +7 -0
- package/build/font-library-modal/utils/filter-fonts.js +39 -0
- package/build/font-library-modal/utils/filter-fonts.js.map +7 -0
- package/build/font-library-modal/utils/fonts-outline.js +51 -0
- package/build/font-library-modal/utils/fonts-outline.js.map +7 -0
- package/build/font-library-modal/utils/index.js +274 -0
- package/build/font-library-modal/utils/index.js.map +7 -0
- package/build/font-library-modal/utils/make-families-from-faces.js +45 -0
- package/build/font-library-modal/utils/make-families-from-faces.js.map +7 -0
- package/build/font-library-modal/utils/preview-styles.js +119 -0
- package/build/font-library-modal/utils/preview-styles.js.map +7 -0
- package/build/font-library-modal/utils/set-immutably.js +40 -0
- package/build/font-library-modal/utils/set-immutably.js.map +7 -0
- package/build/font-library-modal/utils/sort-font-faces.js +59 -0
- package/build/font-library-modal/utils/sort-font-faces.js.map +7 -0
- package/build/font-library-modal/utils/toggleFont.js +67 -0
- package/build/font-library-modal/utils/toggleFont.js.map +7 -0
- package/build/font-sizes/confirm-delete-font-size-dialog.js +60 -0
- package/build/font-sizes/confirm-delete-font-size-dialog.js.map +7 -0
- package/build/font-sizes/confirm-reset-font-sizes-dialog.js +55 -0
- package/build/font-sizes/confirm-reset-font-sizes-dialog.js.map +7 -0
- package/build/font-sizes/font-size-preview.js +50 -0
- package/build/font-sizes/font-size-preview.js.map +7 -0
- package/build/font-sizes/font-size.js +261 -0
- package/build/font-sizes/font-size.js.map +7 -0
- package/build/font-sizes/font-sizes-count.js +40 -0
- package/build/font-sizes/font-sizes-count.js.map +7 -0
- package/build/font-sizes/font-sizes.js +215 -0
- package/build/font-sizes/font-sizes.js.map +7 -0
- package/build/font-sizes/rename-font-size-dialog.js +96 -0
- package/build/font-sizes/rename-font-size-dialog.js.map +7 -0
- package/build/global-styles-ui.js +213 -0
- package/build/global-styles-ui.js.map +7 -0
- package/build/gradients-palette-panel.js +133 -0
- package/build/gradients-palette-panel.js.map +7 -0
- package/build/highlighted-colors.js +57 -0
- package/build/highlighted-colors.js.map +7 -0
- package/build/hooks.js +176 -0
- package/build/hooks.js.map +7 -0
- package/build/icon-with-current-color.js +56 -0
- package/build/icon-with-current-color.js.map +7 -0
- package/build/index.js +51 -0
- package/build/index.js.map +7 -0
- package/build/lock-unlock.js +35 -0
- package/build/lock-unlock.js.map +7 -0
- package/build/navigation-button.js +52 -0
- package/build/navigation-button.js.map +7 -0
- package/build/pagination/index.js +133 -0
- package/build/pagination/index.js.map +7 -0
- package/build/palette.js +93 -0
- package/build/palette.js.map +7 -0
- package/build/preset-colors.js +40 -0
- package/build/preset-colors.js.map +7 -0
- package/build/preview-colors.js +86 -0
- package/build/preview-colors.js.map +7 -0
- package/build/preview-hooks.js +60 -0
- package/build/preview-hooks.js.map +7 -0
- package/build/preview-styles.js +219 -0
- package/build/preview-styles.js.map +7 -0
- package/build/preview-typography.js +72 -0
- package/build/preview-typography.js.map +7 -0
- package/build/preview-wrapper.js +102 -0
- package/build/preview-wrapper.js.map +7 -0
- package/build/provider.js +54 -0
- package/build/provider.js.map +7 -0
- package/build/root-menu.js +72 -0
- package/build/root-menu.js.map +7 -0
- package/build/screen-background.js +58 -0
- package/build/screen-background.js.map +7 -0
- package/build/screen-block-list.js +160 -0
- package/build/screen-block-list.js.map +7 -0
- package/build/screen-block.js +316 -0
- package/build/screen-block.js.map +7 -0
- package/build/screen-color-palette.js +64 -0
- package/build/screen-color-palette.js.map +7 -0
- package/build/screen-colors.js +85 -0
- package/build/screen-colors.js.map +7 -0
- package/build/screen-css.js +68 -0
- package/build/screen-css.js.map +7 -0
- package/build/screen-header.js +61 -0
- package/build/screen-header.js.map +7 -0
- package/build/screen-layout.js +54 -0
- package/build/screen-layout.js.map +7 -0
- package/build/screen-revisions/index.js +147 -0
- package/build/screen-revisions/index.js.map +7 -0
- package/build/screen-revisions/revisions-buttons.js +198 -0
- package/build/screen-revisions/revisions-buttons.js.map +7 -0
- package/build/screen-revisions/types.js +17 -0
- package/build/screen-revisions/types.js.map +7 -0
- package/build/screen-revisions/use-global-styles-revisions.js +163 -0
- package/build/screen-revisions/use-global-styles-revisions.js.map +7 -0
- package/build/screen-root.js +134 -0
- package/build/screen-root.js.map +7 -0
- package/build/screen-shadows.js +49 -0
- package/build/screen-shadows.js.map +7 -0
- package/build/screen-style-variations.js +52 -0
- package/build/screen-style-variations.js.map +7 -0
- package/build/screen-typography-element.js +167 -0
- package/build/screen-typography-element.js.map +7 -0
- package/build/screen-typography.js +65 -0
- package/build/screen-typography.js.map +7 -0
- package/build/shadow-utils.js +125 -0
- package/build/shadow-utils.js.map +7 -0
- package/build/shadows-edit-panel.js +503 -0
- package/build/shadows-edit-panel.js.map +7 -0
- package/build/shadows-panel.js +203 -0
- package/build/shadows-panel.js.map +7 -0
- package/build/size-control/index.js +86 -0
- package/build/size-control/index.js.map +7 -0
- package/build/style-variations-container.js +130 -0
- package/build/style-variations-container.js.map +7 -0
- package/build/style-variations-content.js +52 -0
- package/build/style-variations-content.js.map +7 -0
- package/build/style-variations.js +41 -0
- package/build/style-variations.js.map +7 -0
- package/build/subtitle.js +33 -0
- package/build/subtitle.js.map +7 -0
- package/build/typography-elements.js +117 -0
- package/build/typography-elements.js.map +7 -0
- package/build/typography-example.js +79 -0
- package/build/typography-example.js.map +7 -0
- package/build/typography-panel.js +64 -0
- package/build/typography-panel.js.map +7 -0
- package/build/typography-preview.js +70 -0
- package/build/typography-preview.js.map +7 -0
- package/build/typography-variations.js +41 -0
- package/build/typography-variations.js.map +7 -0
- package/build/utils.js +210 -0
- package/build/utils.js.map +7 -0
- package/build/variations/variation.js +116 -0
- package/build/variations/variation.js.map +7 -0
- package/build/variations/variations-color.js +64 -0
- package/build/variations/variations-color.js.map +7 -0
- package/build/variations/variations-panel.js +69 -0
- package/build/variations/variations-panel.js.map +7 -0
- package/build/variations/variations-typography.js +80 -0
- package/build/variations/variations-typography.js.map +7 -0
- package/build/with-global-styles-provider.js +48 -0
- package/build/with-global-styles-provider.js.map +7 -0
- package/build-module/background-panel.js +38 -0
- package/build-module/background-panel.js.map +7 -0
- package/build-module/block-preview-panel.js +70 -0
- package/build-module/block-preview-panel.js.map +7 -0
- package/build-module/color-indicator-wrapper.js +25 -0
- package/build-module/color-indicator-wrapper.js.map +7 -0
- package/build-module/color-palette-panel.js +97 -0
- package/build-module/color-palette-panel.js.map +7 -0
- package/build-module/color-preview.js +70 -0
- package/build-module/color-preview.js.map +7 -0
- package/build-module/color-variations.js +7 -0
- package/build-module/color-variations.js.map +7 -0
- package/build-module/confirm-reset-shadow-dialog.js +35 -0
- package/build-module/confirm-reset-shadow-dialog.js.map +7 -0
- package/build-module/context.js +13 -0
- package/build-module/context.js.map +7 -0
- package/build-module/dimensions-panel.js +69 -0
- package/build-module/dimensions-panel.js.map +7 -0
- package/build-module/font-families.js +92 -0
- package/build-module/font-families.js.map +7 -0
- package/build-module/font-family-item.js +32 -0
- package/build-module/font-family-item.js.map +7 -0
- package/build-module/font-library-modal/collection-font-variant.js +45 -0
- package/build-module/font-library-modal/collection-font-variant.js.map +7 -0
- package/build-module/font-library-modal/context.js +382 -0
- package/build-module/font-library-modal/context.js.map +7 -0
- package/build-module/font-library-modal/font-card.js +57 -0
- package/build-module/font-library-modal/font-card.js.map +7 -0
- package/build-module/font-library-modal/font-collection.js +510 -0
- package/build-module/font-library-modal/font-collection.js.map +7 -0
- package/build-module/font-library-modal/font-demo.js +94 -0
- package/build-module/font-library-modal/font-demo.js.map +7 -0
- package/build-module/font-library-modal/google-fonts-confirm-dialog.js +45 -0
- package/build-module/font-library-modal/google-fonts-confirm-dialog.js.map +7 -0
- package/build-module/font-library-modal/index.js +83 -0
- package/build-module/font-library-modal/index.js.map +7 -0
- package/build-module/font-library-modal/installed-fonts.js +442 -0
- package/build-module/font-library-modal/installed-fonts.js.map +7 -0
- package/build-module/font-library-modal/lib/inflate.js +2636 -0
- package/build-module/font-library-modal/lib/inflate.js.map +7 -0
- package/build-module/font-library-modal/lib/lib-font.browser.d.js +9 -0
- package/build-module/font-library-modal/lib/lib-font.browser.d.js.map +7 -0
- package/build-module/font-library-modal/lib/lib-font.browser.js +3754 -0
- package/build-module/font-library-modal/lib/lib-font.browser.js.map +7 -0
- package/build-module/font-library-modal/lib/unbrotli.js +3686 -0
- package/build-module/font-library-modal/lib/unbrotli.js.map +7 -0
- package/build-module/font-library-modal/library-font-details.js +36 -0
- package/build-module/font-library-modal/library-font-details.js.map +7 -0
- package/build-module/font-library-modal/library-font-variant.js +51 -0
- package/build-module/font-library-modal/library-font-variant.js.map +7 -0
- package/build-module/font-library-modal/resolvers.js +76 -0
- package/build-module/font-library-modal/resolvers.js.map +7 -0
- package/build-module/font-library-modal/types.js +1 -0
- package/build-module/font-library-modal/types.js.map +7 -0
- package/build-module/font-library-modal/upload-fonts.js +187 -0
- package/build-module/font-library-modal/upload-fonts.js.map +7 -0
- package/build-module/font-library-modal/utils/constants.js +23 -0
- package/build-module/font-library-modal/utils/constants.js.map +7 -0
- package/build-module/font-library-modal/utils/filter-fonts.js +19 -0
- package/build-module/font-library-modal/utils/filter-fonts.js.map +7 -0
- package/build-module/font-library-modal/utils/fonts-outline.js +26 -0
- package/build-module/font-library-modal/utils/fonts-outline.js.map +7 -0
- package/build-module/font-library-modal/utils/index.js +238 -0
- package/build-module/font-library-modal/utils/index.js.map +7 -0
- package/build-module/font-library-modal/utils/make-families-from-faces.js +25 -0
- package/build-module/font-library-modal/utils/make-families-from-faces.js.map +7 -0
- package/build-module/font-library-modal/utils/preview-styles.js +92 -0
- package/build-module/font-library-modal/utils/preview-styles.js.map +7 -0
- package/build-module/font-library-modal/utils/set-immutably.js +16 -0
- package/build-module/font-library-modal/utils/set-immutably.js.map +7 -0
- package/build-module/font-library-modal/utils/sort-font-faces.js +35 -0
- package/build-module/font-library-modal/utils/sort-font-faces.js.map +7 -0
- package/build-module/font-library-modal/utils/toggleFont.js +43 -0
- package/build-module/font-library-modal/utils/toggleFont.js.map +7 -0
- package/build-module/font-sizes/confirm-delete-font-size-dialog.js +40 -0
- package/build-module/font-sizes/confirm-delete-font-size-dialog.js.map +7 -0
- package/build-module/font-sizes/confirm-reset-font-sizes-dialog.js +35 -0
- package/build-module/font-sizes/confirm-reset-font-sizes-dialog.js.map +7 -0
- package/build-module/font-sizes/font-size-preview.js +30 -0
- package/build-module/font-sizes/font-size-preview.js.map +7 -0
- package/build-module/font-sizes/font-size.js +241 -0
- package/build-module/font-sizes/font-size.js.map +7 -0
- package/build-module/font-sizes/font-sizes-count.js +25 -0
- package/build-module/font-sizes/font-sizes-count.js.map +7 -0
- package/build-module/font-sizes/font-sizes.js +200 -0
- package/build-module/font-sizes/font-sizes.js.map +7 -0
- package/build-module/font-sizes/rename-font-size-dialog.js +82 -0
- package/build-module/font-sizes/rename-font-size-dialog.js.map +7 -0
- package/build-module/global-styles-ui.js +182 -0
- package/build-module/global-styles-ui.js.map +7 -0
- package/build-module/gradients-palette-panel.js +118 -0
- package/build-module/gradients-palette-panel.js.map +7 -0
- package/build-module/highlighted-colors.js +37 -0
- package/build-module/highlighted-colors.js.map +7 -0
- package/build-module/hooks.js +144 -0
- package/build-module/hooks.js.map +7 -0
- package/build-module/icon-with-current-color.js +22 -0
- package/build-module/icon-with-current-color.js.map +7 -0
- package/build-module/index.js +13 -0
- package/build-module/index.js.map +7 -0
- package/build-module/lock-unlock.js +10 -0
- package/build-module/lock-unlock.js.map +7 -0
- package/build-module/navigation-button.js +32 -0
- package/build-module/navigation-button.js.map +7 -0
- package/build-module/pagination/index.js +107 -0
- package/build-module/pagination/index.js.map +7 -0
- package/build-module/palette.js +70 -0
- package/build-module/palette.js.map +7 -0
- package/build-module/preset-colors.js +20 -0
- package/build-module/preset-colors.js.map +7 -0
- package/build-module/preview-colors.js +59 -0
- package/build-module/preview-colors.js.map +7 -0
- package/build-module/preview-hooks.js +36 -0
- package/build-module/preview-hooks.js.map +7 -0
- package/build-module/preview-styles.js +193 -0
- package/build-module/preview-styles.js.map +7 -0
- package/build-module/preview-typography.js +42 -0
- package/build-module/preview-typography.js.map +7 -0
- package/build-module/preview-wrapper.js +86 -0
- package/build-module/preview-wrapper.js.map +7 -0
- package/build-module/provider.js +30 -0
- package/build-module/provider.js.map +7 -0
- package/build-module/root-menu.js +58 -0
- package/build-module/root-menu.js.map +7 -0
- package/build-module/screen-background.js +28 -0
- package/build-module/screen-background.js.map +7 -0
- package/build-module/screen-block-list.js +150 -0
- package/build-module/screen-block-list.js.map +7 -0
- package/build-module/screen-block.js +293 -0
- package/build-module/screen-block.js.map +7 -0
- package/build-module/screen-color-palette.js +34 -0
- package/build-module/screen-color-palette.js.map +7 -0
- package/build-module/screen-colors.js +55 -0
- package/build-module/screen-colors.js.map +7 -0
- package/build-module/screen-css.js +48 -0
- package/build-module/screen-css.js.map +7 -0
- package/build-module/screen-header.js +44 -0
- package/build-module/screen-header.js.map +7 -0
- package/build-module/screen-layout.js +24 -0
- package/build-module/screen-layout.js.map +7 -0
- package/build-module/screen-revisions/index.js +121 -0
- package/build-module/screen-revisions/index.js.map +7 -0
- package/build-module/screen-revisions/revisions-buttons.js +178 -0
- package/build-module/screen-revisions/revisions-buttons.js.map +7 -0
- package/build-module/screen-revisions/types.js +1 -0
- package/build-module/screen-revisions/types.js.map +7 -0
- package/build-module/screen-revisions/use-global-styles-revisions.js +145 -0
- package/build-module/screen-revisions/use-global-styles-revisions.js.map +7 -0
- package/build-module/screen-root.js +114 -0
- package/build-module/screen-root.js.map +7 -0
- package/build-module/screen-shadows.js +14 -0
- package/build-module/screen-shadows.js.map +7 -0
- package/build-module/screen-style-variations.js +32 -0
- package/build-module/screen-style-variations.js.map +7 -0
- package/build-module/screen-typography-element.js +141 -0
- package/build-module/screen-typography-element.js.map +7 -0
- package/build-module/screen-typography.js +35 -0
- package/build-module/screen-typography.js.map +7 -0
- package/build-module/shadow-utils.js +98 -0
- package/build-module/shadow-utils.js.map +7 -0
- package/build-module/shadows-edit-panel.js +502 -0
- package/build-module/shadows-edit-panel.js.map +7 -0
- package/build-module/shadows-panel.js +182 -0
- package/build-module/shadows-panel.js.map +7 -0
- package/build-module/size-control/index.js +72 -0
- package/build-module/size-control/index.js.map +7 -0
- package/build-module/style-variations-container.js +100 -0
- package/build-module/style-variations-container.js.map +7 -0
- package/build-module/style-variations-content.js +18 -0
- package/build-module/style-variations-content.js.map +7 -0
- package/build-module/style-variations.js +7 -0
- package/build-module/style-variations.js.map +7 -0
- package/build-module/subtitle.js +9 -0
- package/build-module/subtitle.js.map +7 -0
- package/build-module/typography-elements.js +102 -0
- package/build-module/typography-elements.js.map +7 -0
- package/build-module/typography-example.js +59 -0
- package/build-module/typography-example.js.map +7 -0
- package/build-module/typography-panel.js +44 -0
- package/build-module/typography-panel.js.map +7 -0
- package/build-module/typography-preview.js +50 -0
- package/build-module/typography-preview.js.map +7 -0
- package/build-module/typography-variations.js +7 -0
- package/build-module/typography-variations.js.map +7 -0
- package/build-module/utils.js +179 -0
- package/build-module/utils.js.map +7 -0
- package/build-module/variations/variation.js +86 -0
- package/build-module/variations/variation.js.map +7 -0
- package/build-module/variations/variations-color.js +37 -0
- package/build-module/variations/variations-color.js.map +7 -0
- package/build-module/variations/variations-panel.js +44 -0
- package/build-module/variations/variations-panel.js.map +7 -0
- package/build-module/variations/variations-typography.js +53 -0
- package/build-module/variations/variations-typography.js.map +7 -0
- package/build-module/with-global-styles-provider.js +24 -0
- package/build-module/with-global-styles-provider.js.map +7 -0
- package/build-style/style-rtl.css +717 -0
- package/build-style/style.css +718 -0
- package/build-types/background-panel.d.ts +10 -0
- package/build-types/background-panel.d.ts.map +1 -0
- package/build-types/block-preview-panel.d.ts +7 -0
- package/build-types/block-preview-panel.d.ts.map +1 -0
- package/build-types/color-indicator-wrapper.d.ts +7 -0
- package/build-types/color-indicator-wrapper.d.ts.map +1 -0
- package/build-types/color-palette-panel.d.ts +6 -0
- package/build-types/color-palette-panel.d.ts.map +1 -0
- package/build-types/color-preview.d.ts +2 -0
- package/build-types/color-preview.d.ts.map +1 -0
- package/build-types/color-variations.d.ts +27 -0
- package/build-types/color-variations.d.ts.map +1 -0
- package/build-types/confirm-reset-shadow-dialog.d.ts +10 -0
- package/build-types/confirm-reset-shadow-dialog.d.ts.map +1 -0
- package/build-types/context.d.ts +10 -0
- package/build-types/context.d.ts.map +1 -0
- package/build-types/dimensions-panel.d.ts +2 -0
- package/build-types/dimensions-panel.d.ts.map +1 -0
- package/build-types/font-families.d.ts +4 -0
- package/build-types/font-families.d.ts.map +1 -0
- package/build-types/font-family-item.d.ts +7 -0
- package/build-types/font-family-item.d.ts.map +1 -0
- package/build-types/font-library-modal/collection-font-variant.d.ts +4 -0
- package/build-types/font-library-modal/collection-font-variant.d.ts.map +1 -0
- package/build-types/font-library-modal/context.d.ts +7 -0
- package/build-types/font-library-modal/context.d.ts.map +1 -0
- package/build-types/font-library-modal/font-card.d.ts +9 -0
- package/build-types/font-library-modal/font-card.d.ts.map +1 -0
- package/build-types/font-library-modal/font-collection.d.ts +5 -0
- package/build-types/font-library-modal/font-collection.d.ts.map +1 -0
- package/build-types/font-library-modal/font-demo.d.ts +4 -0
- package/build-types/font-library-modal/font-demo.d.ts.map +1 -0
- package/build-types/font-library-modal/google-fonts-confirm-dialog.d.ts +3 -0
- package/build-types/font-library-modal/google-fonts-confirm-dialog.d.ts.map +1 -0
- package/build-types/font-library-modal/index.d.ts +6 -0
- package/build-types/font-library-modal/index.d.ts.map +1 -0
- package/build-types/font-library-modal/installed-fonts.d.ts +3 -0
- package/build-types/font-library-modal/installed-fonts.d.ts.map +1 -0
- package/build-types/font-library-modal/library-font-details.d.ts +6 -0
- package/build-types/font-library-modal/library-font-details.d.ts.map +1 -0
- package/build-types/font-library-modal/library-font-variant.d.ts +7 -0
- package/build-types/font-library-modal/library-font-variant.d.ts.map +1 -0
- package/build-types/font-library-modal/resolvers.d.ts +43 -0
- package/build-types/font-library-modal/resolvers.d.ts.map +1 -0
- package/build-types/font-library-modal/types.d.ts +133 -0
- package/build-types/font-library-modal/types.d.ts.map +1 -0
- package/build-types/font-library-modal/upload-fonts.d.ts +3 -0
- package/build-types/font-library-modal/upload-fonts.d.ts.map +1 -0
- package/build-types/font-library-modal/utils/constants.d.ts +4 -0
- package/build-types/font-library-modal/utils/constants.d.ts.map +1 -0
- package/build-types/font-library-modal/utils/filter-fonts.d.ts +25 -0
- package/build-types/font-library-modal/utils/filter-fonts.d.ts.map +1 -0
- package/build-types/font-library-modal/utils/fonts-outline.d.ts +7 -0
- package/build-types/font-library-modal/utils/fonts-outline.d.ts.map +1 -0
- package/build-types/font-library-modal/utils/index.d.ts +21 -0
- package/build-types/font-library-modal/utils/index.d.ts.map +1 -0
- package/build-types/font-library-modal/utils/make-families-from-faces.d.ts +6 -0
- package/build-types/font-library-modal/utils/make-families-from-faces.d.ts.map +1 -0
- package/build-types/font-library-modal/utils/preview-styles.d.ts +13 -0
- package/build-types/font-library-modal/utils/preview-styles.d.ts.map +1 -0
- package/build-types/font-library-modal/utils/set-immutably.d.ts +13 -0
- package/build-types/font-library-modal/utils/set-immutably.d.ts.map +1 -0
- package/build-types/font-library-modal/utils/sort-font-faces.d.ts +6 -0
- package/build-types/font-library-modal/utils/sort-font-faces.d.ts.map +1 -0
- package/build-types/font-library-modal/utils/toggleFont.d.ts +38 -0
- package/build-types/font-library-modal/utils/toggleFont.d.ts.map +1 -0
- package/build-types/font-sizes/confirm-delete-font-size-dialog.d.ts +10 -0
- package/build-types/font-sizes/confirm-delete-font-size-dialog.d.ts.map +1 -0
- package/build-types/font-sizes/confirm-reset-font-sizes-dialog.d.ts +10 -0
- package/build-types/font-sizes/confirm-reset-font-sizes-dialog.d.ts.map +1 -0
- package/build-types/font-sizes/font-size-preview.d.ts +7 -0
- package/build-types/font-sizes/font-size-preview.d.ts.map +1 -0
- package/build-types/font-sizes/font-size.d.ts +4 -0
- package/build-types/font-sizes/font-size.d.ts.map +1 -0
- package/build-types/font-sizes/font-sizes-count.d.ts +3 -0
- package/build-types/font-sizes/font-sizes-count.d.ts.map +1 -0
- package/build-types/font-sizes/font-sizes.d.ts +3 -0
- package/build-types/font-sizes/font-sizes.d.ts.map +1 -0
- package/build-types/font-sizes/rename-font-size-dialog.d.ts +9 -0
- package/build-types/font-sizes/rename-font-size-dialog.d.ts.map +1 -0
- package/build-types/global-styles-ui.d.ts +26 -0
- package/build-types/global-styles-ui.d.ts.map +1 -0
- package/build-types/gradients-palette-panel.d.ts +6 -0
- package/build-types/gradients-palette-panel.d.ts.map +1 -0
- package/build-types/highlighted-colors.d.ts +7 -0
- package/build-types/highlighted-colors.d.ts.map +1 -0
- package/build-types/hooks.d.ts +46 -0
- package/build-types/hooks.d.ts.map +1 -0
- package/build-types/icon-with-current-color.d.ts +9 -0
- package/build-types/icon-with-current-color.d.ts.map +1 -0
- package/build-types/index.d.ts +6 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/navigation-button.d.ts +10 -0
- package/build-types/navigation-button.d.ts.map +1 -0
- package/build-types/pagination/index.d.ts +13 -0
- package/build-types/pagination/index.d.ts.map +1 -0
- package/build-types/palette.d.ts +6 -0
- package/build-types/palette.d.ts.map +1 -0
- package/build-types/preset-colors.d.ts +2 -0
- package/build-types/preset-colors.d.ts.map +1 -0
- package/build-types/preview-colors.d.ts +8 -0
- package/build-types/preview-colors.d.ts.map +1 -0
- package/build-types/preview-hooks.d.ts +9 -0
- package/build-types/preview-hooks.d.ts.map +1 -0
- package/build-types/preview-styles.d.ts +9 -0
- package/build-types/preview-styles.d.ts.map +1 -0
- package/build-types/preview-typography.d.ts +8 -0
- package/build-types/preview-typography.d.ts.map +1 -0
- package/build-types/preview-wrapper.d.ts +15 -0
- package/build-types/preview-wrapper.d.ts.map +1 -0
- package/build-types/provider.d.ts +15 -0
- package/build-types/provider.d.ts.map +1 -0
- package/build-types/root-menu.d.ts +3 -0
- package/build-types/root-menu.d.ts.map +1 -0
- package/build-types/screen-background.d.ts +3 -0
- package/build-types/screen-background.d.ts.map +1 -0
- package/build-types/screen-block-list.d.ts +4 -0
- package/build-types/screen-block-list.d.ts.map +1 -0
- package/build-types/screen-block.d.ts +7 -0
- package/build-types/screen-block.d.ts.map +1 -0
- package/build-types/screen-color-palette.d.ts +5 -0
- package/build-types/screen-color-palette.d.ts.map +1 -0
- package/build-types/screen-colors.d.ts +3 -0
- package/build-types/screen-colors.d.ts.map +1 -0
- package/build-types/screen-css.d.ts +3 -0
- package/build-types/screen-css.d.ts.map +1 -0
- package/build-types/screen-header.d.ts +8 -0
- package/build-types/screen-header.d.ts.map +1 -0
- package/build-types/screen-layout.d.ts +3 -0
- package/build-types/screen-layout.d.ts.map +1 -0
- package/build-types/screen-revisions/index.d.ts +6 -0
- package/build-types/screen-revisions/index.d.ts.map +1 -0
- package/build-types/screen-revisions/revisions-buttons.d.ts +23 -0
- package/build-types/screen-revisions/revisions-buttons.d.ts.map +1 -0
- package/build-types/screen-revisions/types.d.ts +17 -0
- package/build-types/screen-revisions/types.d.ts.map +1 -0
- package/build-types/screen-revisions/use-global-styles-revisions.d.ts +17 -0
- package/build-types/screen-revisions/use-global-styles-revisions.d.ts.map +1 -0
- package/build-types/screen-root.d.ts +3 -0
- package/build-types/screen-root.d.ts.map +1 -0
- package/build-types/screen-shadows.d.ts +3 -0
- package/build-types/screen-shadows.d.ts.map +1 -0
- package/build-types/screen-style-variations.d.ts +3 -0
- package/build-types/screen-style-variations.d.ts.map +1 -0
- package/build-types/screen-typography-element.d.ts +28 -0
- package/build-types/screen-typography-element.d.ts.map +1 -0
- package/build-types/screen-typography.d.ts +3 -0
- package/build-types/screen-typography.d.ts.map +1 -0
- package/build-types/shadow-utils.d.ts +126 -0
- package/build-types/shadow-utils.d.ts.map +1 -0
- package/build-types/shadows-edit-panel.d.ts +2 -0
- package/build-types/shadows-edit-panel.d.ts.map +1 -0
- package/build-types/shadows-panel.d.ts +3 -0
- package/build-types/shadows-panel.d.ts.map +1 -0
- package/build-types/size-control/index.d.ts +11 -0
- package/build-types/size-control/index.d.ts.map +1 -0
- package/build-types/stories/index.story.d.ts +6 -0
- package/build-types/stories/index.story.d.ts.map +1 -0
- package/build-types/style-variations-container.d.ts +6 -0
- package/build-types/style-variations-container.d.ts.map +1 -0
- package/build-types/style-variations-content.d.ts +2 -0
- package/build-types/style-variations-content.d.ts.map +1 -0
- package/build-types/style-variations.d.ts +25 -0
- package/build-types/style-variations.d.ts.map +1 -0
- package/build-types/subtitle.d.ts +7 -0
- package/build-types/subtitle.d.ts.map +1 -0
- package/build-types/test/shadow-utils.spec.d.ts +2 -0
- package/build-types/test/shadow-utils.spec.d.ts.map +1 -0
- package/build-types/test/utils.spec.d.ts +2 -0
- package/build-types/test/utils.spec.d.ts.map +1 -0
- package/build-types/typography-elements.d.ts +3 -0
- package/build-types/typography-elements.d.ts.map +1 -0
- package/build-types/typography-example.d.ts +7 -0
- package/build-types/typography-example.d.ts.map +1 -0
- package/build-types/typography-panel.d.ts +7 -0
- package/build-types/typography-panel.d.ts.map +1 -0
- package/build-types/typography-preview.d.ts +8 -0
- package/build-types/typography-preview.d.ts.map +1 -0
- package/build-types/typography-variations.d.ts +27 -0
- package/build-types/typography-variations.d.ts.map +1 -0
- package/build-types/utils.d.ts +63 -0
- package/build-types/utils.d.ts.map +1 -0
- package/build-types/variations/variation.d.ts +10 -0
- package/build-types/variations/variation.d.ts.map +1 -0
- package/build-types/variations/variations-color.d.ts +7 -0
- package/build-types/variations/variations-color.d.ts.map +1 -0
- package/build-types/variations/variations-panel.d.ts +13 -0
- package/build-types/variations/variations-panel.d.ts.map +1 -0
- package/build-types/variations/variations-typography.d.ts +7 -0
- package/build-types/variations/variations-typography.d.ts.map +1 -0
- package/build-types/with-global-styles-provider.d.ts +20 -0
- package/build-types/with-global-styles-provider.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/README.md +99 -0
- package/src/background-panel.tsx +56 -0
- package/src/block-preview-panel.tsx +91 -0
- package/src/color-indicator-wrapper.tsx +34 -0
- package/src/color-palette-panel.tsx +111 -0
- package/src/color-preview.tsx +78 -0
- package/src/color-variations.tsx +35 -0
- package/src/confirm-reset-shadow-dialog.tsx +45 -0
- package/src/context.ts +21 -0
- package/src/dimensions-panel.tsx +85 -0
- package/src/font-families.tsx +127 -0
- package/src/font-family-item.tsx +52 -0
- package/src/font-library-modal/collection-font-variant.tsx +52 -0
- package/src/font-library-modal/context.tsx +591 -0
- package/src/font-library-modal/font-card.tsx +77 -0
- package/src/font-library-modal/font-collection.tsx +592 -0
- package/src/font-library-modal/font-demo.tsx +123 -0
- package/src/font-library-modal/google-fonts-confirm-dialog.tsx +57 -0
- package/src/font-library-modal/index.tsx +110 -0
- package/src/font-library-modal/installed-fonts.tsx +547 -0
- package/src/font-library-modal/lib/inflate.js +4112 -0
- package/src/font-library-modal/lib/lib-font.browser.d.ts +11 -0
- package/src/font-library-modal/lib/lib-font.browser.js +3861 -0
- package/src/font-library-modal/lib/unbrotli.js +2706 -0
- package/src/font-library-modal/library-font-details.tsx +46 -0
- package/src/font-library-modal/library-font-variant.tsx +67 -0
- package/src/font-library-modal/resolvers.tsx +100 -0
- package/src/font-library-modal/style.scss +222 -0
- package/src/font-library-modal/types.ts +176 -0
- package/src/font-library-modal/upload-fonts.tsx +269 -0
- package/src/font-library-modal/utils/constants.ts +23 -0
- package/src/font-library-modal/utils/filter-fonts.ts +47 -0
- package/src/font-library-modal/utils/fonts-outline.ts +33 -0
- package/src/font-library-modal/utils/index.ts +368 -0
- package/src/font-library-modal/utils/make-families-from-faces.ts +34 -0
- package/src/font-library-modal/utils/preview-styles.ts +167 -0
- package/src/font-library-modal/utils/set-immutably.ts +37 -0
- package/src/font-library-modal/utils/sort-font-faces.ts +46 -0
- package/src/font-library-modal/utils/toggleFont.ts +109 -0
- package/src/font-sizes/confirm-delete-font-size-dialog.tsx +51 -0
- package/src/font-sizes/confirm-reset-font-sizes-dialog.tsx +45 -0
- package/src/font-sizes/font-size-preview.tsx +47 -0
- package/src/font-sizes/font-size.tsx +289 -0
- package/src/font-sizes/font-sizes-count.tsx +37 -0
- package/src/font-sizes/font-sizes.tsx +265 -0
- package/src/font-sizes/rename-font-size-dialog.tsx +83 -0
- package/src/global-styles-ui.tsx +292 -0
- package/src/gradients-palette-panel.tsx +126 -0
- package/src/highlighted-colors.tsx +44 -0
- package/src/hooks.ts +251 -0
- package/src/icon-with-current-color.tsx +31 -0
- package/src/index.ts +7 -0
- package/src/lock-unlock.ts +10 -0
- package/src/navigation-button.tsx +53 -0
- package/src/pagination/index.tsx +107 -0
- package/src/pagination/style.scss +7 -0
- package/src/palette.tsx +101 -0
- package/src/preset-colors.tsx +18 -0
- package/src/preview-colors.tsx +68 -0
- package/src/preview-hooks.tsx +58 -0
- package/src/preview-styles.tsx +196 -0
- package/src/preview-typography.tsx +49 -0
- package/src/preview-wrapper.tsx +137 -0
- package/src/provider.tsx +54 -0
- package/src/root-menu.tsx +87 -0
- package/src/screen-background.tsx +37 -0
- package/src/screen-block-list.tsx +198 -0
- package/src/screen-block.tsx +370 -0
- package/src/screen-color-palette.tsx +47 -0
- package/src/screen-colors.tsx +67 -0
- package/src/screen-css.tsx +56 -0
- package/src/screen-header.tsx +56 -0
- package/src/screen-layout.tsx +34 -0
- package/src/screen-revisions/index.tsx +158 -0
- package/src/screen-revisions/revisions-buttons.tsx +259 -0
- package/src/screen-revisions/style.scss +194 -0
- package/src/screen-revisions/types.ts +18 -0
- package/src/screen-revisions/use-global-styles-revisions.tsx +204 -0
- package/src/screen-root.tsx +146 -0
- package/src/screen-shadows.tsx +13 -0
- package/src/screen-style-variations.tsx +36 -0
- package/src/screen-typography-element.tsx +127 -0
- package/src/screen-typography.tsx +41 -0
- package/src/shadow-utils.ts +167 -0
- package/src/shadows-edit-panel.tsx +559 -0
- package/src/shadows-panel.tsx +207 -0
- package/src/size-control/index.tsx +97 -0
- package/src/size-control/style.scss +7 -0
- package/src/stories/index.story.js +410 -0
- package/src/style-variations-container.tsx +153 -0
- package/src/style-variations-content.tsx +24 -0
- package/src/style-variations.tsx +33 -0
- package/src/style.scss +287 -0
- package/src/subtitle.tsx +17 -0
- package/src/test/shadow-utils.spec.js +251 -0
- package/src/test/utils.spec.js +59 -0
- package/src/typography-elements.tsx +113 -0
- package/src/typography-example.tsx +78 -0
- package/src/typography-panel.tsx +56 -0
- package/src/typography-preview.tsx +61 -0
- package/src/typography-variations.tsx +35 -0
- package/src/utils.ts +301 -0
- package/src/variations/style.scss +43 -0
- package/src/variations/variation.tsx +113 -0
- package/src/variations/variations-color.tsx +54 -0
- package/src/variations/variations-panel.tsx +79 -0
- package/src/variations/variations-typography.tsx +65 -0
- package/src/with-global-styles-provider.tsx +44 -0
- package/tsconfig.json +26 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useState, useEffect } from "@wordpress/element";
|
|
3
|
+
import { useSelect, useDispatch } from "@wordpress/data";
|
|
4
|
+
import {
|
|
5
|
+
useEntityRecord,
|
|
6
|
+
useEntityRecords,
|
|
7
|
+
store as coreStore
|
|
8
|
+
} from "@wordpress/core-data";
|
|
9
|
+
import { __ } from "@wordpress/i18n";
|
|
10
|
+
import {
|
|
11
|
+
fetchGetFontFamilyBySlug,
|
|
12
|
+
fetchInstallFontFamily,
|
|
13
|
+
fetchUninstallFontFamily,
|
|
14
|
+
fetchFontCollections,
|
|
15
|
+
fetchFontCollection
|
|
16
|
+
} from "./resolvers";
|
|
17
|
+
import {
|
|
18
|
+
setUIValuesNeeded,
|
|
19
|
+
mergeFontFamilies,
|
|
20
|
+
loadFontFaceInBrowser,
|
|
21
|
+
unloadFontFaceInBrowser,
|
|
22
|
+
getDisplaySrcFromFontFace,
|
|
23
|
+
makeFontFacesFormData,
|
|
24
|
+
makeFontFamilyFormData,
|
|
25
|
+
batchInstallFontFaces,
|
|
26
|
+
checkFontFaceInstalled
|
|
27
|
+
} from "./utils";
|
|
28
|
+
import { setImmutably } from "./utils/set-immutably";
|
|
29
|
+
import { toggleFont } from "./utils/toggleFont";
|
|
30
|
+
import { useSetting } from "../hooks";
|
|
31
|
+
const FontLibraryContext = createContext(
|
|
32
|
+
{}
|
|
33
|
+
);
|
|
34
|
+
FontLibraryContext.displayName = "FontLibraryContext";
|
|
35
|
+
function FontLibraryProvider({ children }) {
|
|
36
|
+
const { saveEntityRecord } = useDispatch(coreStore);
|
|
37
|
+
const { globalStylesId } = useSelect((select) => {
|
|
38
|
+
const { __experimentalGetCurrentGlobalStylesId } = select(coreStore);
|
|
39
|
+
return { globalStylesId: __experimentalGetCurrentGlobalStylesId() };
|
|
40
|
+
}, []);
|
|
41
|
+
const globalStyles = useEntityRecord(
|
|
42
|
+
"root",
|
|
43
|
+
"globalStyles",
|
|
44
|
+
globalStylesId
|
|
45
|
+
);
|
|
46
|
+
const [isInstalling, setIsInstalling] = useState(false);
|
|
47
|
+
const [refreshKey, setRefreshKey] = useState(0);
|
|
48
|
+
const refreshLibrary = () => {
|
|
49
|
+
setRefreshKey(Date.now());
|
|
50
|
+
};
|
|
51
|
+
const { records: libraryPosts = [], isResolving: isResolvingLibrary } = useEntityRecords(
|
|
52
|
+
"postType",
|
|
53
|
+
"wp_font_family",
|
|
54
|
+
{
|
|
55
|
+
refreshKey,
|
|
56
|
+
_embed: true
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
const libraryFonts = (libraryPosts || []).map((fontFamilyPost) => {
|
|
60
|
+
return {
|
|
61
|
+
id: fontFamilyPost.id,
|
|
62
|
+
...fontFamilyPost.font_family_settings || {},
|
|
63
|
+
fontFace: fontFamilyPost?._embedded?.font_faces?.map(
|
|
64
|
+
(face) => face.font_face_settings
|
|
65
|
+
) || []
|
|
66
|
+
};
|
|
67
|
+
}) || [];
|
|
68
|
+
const [fontFamilies, setFontFamilies] = useSetting("typography.fontFamilies");
|
|
69
|
+
const saveFontFamilies = async (fonts) => {
|
|
70
|
+
const updatedGlobalStyles = globalStyles.record;
|
|
71
|
+
setImmutably(
|
|
72
|
+
updatedGlobalStyles ?? {},
|
|
73
|
+
["settings", "typography", "fontFamilies"],
|
|
74
|
+
fonts
|
|
75
|
+
);
|
|
76
|
+
await saveEntityRecord("root", "globalStyles", updatedGlobalStyles);
|
|
77
|
+
};
|
|
78
|
+
const [modalTabOpen, setModalTabOpen] = useState("");
|
|
79
|
+
const [libraryFontSelected, setLibraryFontSelected] = useState(void 0);
|
|
80
|
+
const themeFonts = fontFamilies?.theme ? fontFamilies.theme.map((f) => setUIValuesNeeded(f, { source: "theme" })).sort((a, b) => a.name.localeCompare(b.name)) : [];
|
|
81
|
+
const customFonts = fontFamilies?.custom ? fontFamilies.custom.map((f) => setUIValuesNeeded(f, { source: "custom" })).sort((a, b) => a.name.localeCompare(b.name)) : [];
|
|
82
|
+
const baseCustomFonts = libraryFonts ? libraryFonts.map((f) => setUIValuesNeeded(f, { source: "custom" })).sort((a, b) => a.name.localeCompare(b.name)) : [];
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!modalTabOpen) {
|
|
85
|
+
setLibraryFontSelected(void 0);
|
|
86
|
+
}
|
|
87
|
+
}, [modalTabOpen]);
|
|
88
|
+
const handleSetLibraryFontSelected = (font) => {
|
|
89
|
+
if (!font) {
|
|
90
|
+
setLibraryFontSelected(void 0);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const fonts = font.source === "theme" ? themeFonts : baseCustomFonts;
|
|
94
|
+
const fontSelected = fonts.find((f) => f.slug === font.slug);
|
|
95
|
+
setLibraryFontSelected({
|
|
96
|
+
...fontSelected || font,
|
|
97
|
+
source: font.source
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
const [loadedFontUrls] = useState(/* @__PURE__ */ new Set());
|
|
101
|
+
const getAvailableFontsOutline = (availableFontFamilies) => {
|
|
102
|
+
const outline = availableFontFamilies.reduce(
|
|
103
|
+
(acc, font) => {
|
|
104
|
+
const availableFontFaces = font?.fontFace && font.fontFace?.length > 0 ? font?.fontFace.map(
|
|
105
|
+
(face) => `${face.fontStyle ?? ""}${face.fontWeight ?? ""}`
|
|
106
|
+
) : ["normal400"];
|
|
107
|
+
acc[font.slug] = availableFontFaces;
|
|
108
|
+
return acc;
|
|
109
|
+
},
|
|
110
|
+
{}
|
|
111
|
+
);
|
|
112
|
+
return outline;
|
|
113
|
+
};
|
|
114
|
+
const getActivatedFontsOutline = (source) => {
|
|
115
|
+
switch (source) {
|
|
116
|
+
case "theme":
|
|
117
|
+
return getAvailableFontsOutline(themeFonts);
|
|
118
|
+
case "custom":
|
|
119
|
+
default:
|
|
120
|
+
return getAvailableFontsOutline(customFonts);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const isFontActivated = (slug, style, weight, source) => {
|
|
124
|
+
if (!style && !weight) {
|
|
125
|
+
return !!getActivatedFontsOutline(source)[slug];
|
|
126
|
+
}
|
|
127
|
+
return !!getActivatedFontsOutline(source)[slug]?.includes(
|
|
128
|
+
(style ?? "") + (weight ?? "")
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
const getFontFacesActivated = (slug, source) => {
|
|
132
|
+
return getActivatedFontsOutline(source)[slug] || [];
|
|
133
|
+
};
|
|
134
|
+
async function installFonts(fontFamiliesToInstall) {
|
|
135
|
+
setIsInstalling(true);
|
|
136
|
+
try {
|
|
137
|
+
const fontFamiliesToActivate = [];
|
|
138
|
+
let installationErrors = [];
|
|
139
|
+
for (const fontFamilyToInstall of fontFamiliesToInstall) {
|
|
140
|
+
let isANewFontFamily = false;
|
|
141
|
+
let installedFontFamily = await fetchGetFontFamilyBySlug(
|
|
142
|
+
fontFamilyToInstall.slug
|
|
143
|
+
);
|
|
144
|
+
if (!installedFontFamily) {
|
|
145
|
+
isANewFontFamily = true;
|
|
146
|
+
installedFontFamily = await fetchInstallFontFamily(
|
|
147
|
+
makeFontFamilyFormData(fontFamilyToInstall)
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
const alreadyInstalledFontFaces = installedFontFamily.fontFace && fontFamilyToInstall.fontFace ? installedFontFamily.fontFace.filter(
|
|
151
|
+
(fontFaceToInstall) => fontFaceToInstall && fontFamilyToInstall.fontFace && checkFontFaceInstalled(
|
|
152
|
+
fontFaceToInstall,
|
|
153
|
+
fontFamilyToInstall.fontFace
|
|
154
|
+
)
|
|
155
|
+
) : [];
|
|
156
|
+
if (installedFontFamily.fontFace && fontFamilyToInstall.fontFace) {
|
|
157
|
+
fontFamilyToInstall.fontFace = fontFamilyToInstall.fontFace.filter(
|
|
158
|
+
(fontFaceToInstall) => !checkFontFaceInstalled(
|
|
159
|
+
fontFaceToInstall,
|
|
160
|
+
installedFontFamily.fontFace
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
let successfullyInstalledFontFaces = [];
|
|
165
|
+
let unsuccessfullyInstalledFontFaces = [];
|
|
166
|
+
if (fontFamilyToInstall?.fontFace?.length ?? 0 > 0) {
|
|
167
|
+
const response = await batchInstallFontFaces(
|
|
168
|
+
installedFontFamily.id,
|
|
169
|
+
makeFontFacesFormData(
|
|
170
|
+
fontFamilyToInstall
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
successfullyInstalledFontFaces = response?.successes;
|
|
174
|
+
unsuccessfullyInstalledFontFaces = response?.errors;
|
|
175
|
+
}
|
|
176
|
+
if (successfullyInstalledFontFaces?.length > 0 || alreadyInstalledFontFaces?.length > 0) {
|
|
177
|
+
installedFontFamily.fontFace = [
|
|
178
|
+
...successfullyInstalledFontFaces
|
|
179
|
+
];
|
|
180
|
+
fontFamiliesToActivate.push(installedFontFamily);
|
|
181
|
+
}
|
|
182
|
+
if (installedFontFamily && !fontFamilyToInstall?.fontFace?.length) {
|
|
183
|
+
fontFamiliesToActivate.push(installedFontFamily);
|
|
184
|
+
}
|
|
185
|
+
if (isANewFontFamily && (fontFamilyToInstall?.fontFace?.length ?? 0) > 0 && successfullyInstalledFontFaces?.length === 0) {
|
|
186
|
+
await fetchUninstallFontFamily(installedFontFamily.id);
|
|
187
|
+
}
|
|
188
|
+
installationErrors = installationErrors.concat(
|
|
189
|
+
unsuccessfullyInstalledFontFaces
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
const installationErrorMessages = installationErrors.reduce(
|
|
193
|
+
(unique, item) => unique.includes(item.message) ? unique : [...unique, item.message],
|
|
194
|
+
[]
|
|
195
|
+
);
|
|
196
|
+
if (fontFamiliesToActivate.length > 0) {
|
|
197
|
+
const activeFonts = activateCustomFontFamilies(
|
|
198
|
+
fontFamiliesToActivate
|
|
199
|
+
);
|
|
200
|
+
await saveFontFamilies(activeFonts);
|
|
201
|
+
refreshLibrary();
|
|
202
|
+
}
|
|
203
|
+
if (installationErrorMessages.length > 0) {
|
|
204
|
+
const installError = new Error(__("There was an error installing fonts."));
|
|
205
|
+
installError.installationErrors = installationErrorMessages;
|
|
206
|
+
throw installError;
|
|
207
|
+
}
|
|
208
|
+
} finally {
|
|
209
|
+
setIsInstalling(false);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async function uninstallFontFamily(fontFamilyToUninstall) {
|
|
213
|
+
if (!fontFamilyToUninstall?.id) {
|
|
214
|
+
throw new Error(__("Font family to uninstall is not defined."));
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
const uninstalledFontFamily = await fetchUninstallFontFamily(
|
|
218
|
+
fontFamilyToUninstall.id
|
|
219
|
+
);
|
|
220
|
+
if (uninstalledFontFamily.deleted) {
|
|
221
|
+
const activeFonts = deactivateFontFamily(
|
|
222
|
+
fontFamilyToUninstall
|
|
223
|
+
);
|
|
224
|
+
await saveFontFamilies(activeFonts);
|
|
225
|
+
}
|
|
226
|
+
refreshLibrary();
|
|
227
|
+
return uninstalledFontFamily;
|
|
228
|
+
} catch (error) {
|
|
229
|
+
console.error(
|
|
230
|
+
`There was an error uninstalling the font family:`,
|
|
231
|
+
error
|
|
232
|
+
);
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const deactivateFontFamily = (font) => {
|
|
237
|
+
const initialCustomFonts = fontFamilies?.[font.source ?? ""] ?? [];
|
|
238
|
+
const newCustomFonts = initialCustomFonts.filter(
|
|
239
|
+
(f) => f.slug !== font.slug
|
|
240
|
+
);
|
|
241
|
+
const activeFonts = {
|
|
242
|
+
...fontFamilies,
|
|
243
|
+
[font.source ?? ""]: newCustomFonts
|
|
244
|
+
};
|
|
245
|
+
setFontFamilies(activeFonts);
|
|
246
|
+
if (font.fontFace) {
|
|
247
|
+
font.fontFace.forEach((face) => {
|
|
248
|
+
unloadFontFaceInBrowser(face, "all");
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return activeFonts;
|
|
252
|
+
};
|
|
253
|
+
const activateCustomFontFamilies = (fontsToAdd) => {
|
|
254
|
+
const fontsToActivate = cleanFontsForSave(fontsToAdd);
|
|
255
|
+
const activeFonts = {
|
|
256
|
+
...fontFamilies,
|
|
257
|
+
// Merge the existing custom fonts with the new fonts.
|
|
258
|
+
custom: mergeFontFamilies(fontFamilies?.custom, fontsToActivate)
|
|
259
|
+
};
|
|
260
|
+
setFontFamilies(activeFonts);
|
|
261
|
+
loadFontsInBrowser(fontsToActivate);
|
|
262
|
+
return activeFonts;
|
|
263
|
+
};
|
|
264
|
+
const cleanFontsForSave = (fonts) => {
|
|
265
|
+
return fonts.map(({ id: _familyDbId, fontFace, ...font }) => ({
|
|
266
|
+
...font,
|
|
267
|
+
...fontFace && fontFace.length > 0 ? {
|
|
268
|
+
fontFace: fontFace.map(
|
|
269
|
+
({ id: _faceDbId, ...face }) => face
|
|
270
|
+
)
|
|
271
|
+
} : {}
|
|
272
|
+
}));
|
|
273
|
+
};
|
|
274
|
+
const loadFontsInBrowser = (fonts) => {
|
|
275
|
+
fonts.forEach((font) => {
|
|
276
|
+
if (font.fontFace) {
|
|
277
|
+
font.fontFace.forEach((face) => {
|
|
278
|
+
const displaySrc = getDisplaySrcFromFontFace(
|
|
279
|
+
face?.src ?? ""
|
|
280
|
+
);
|
|
281
|
+
if (displaySrc) {
|
|
282
|
+
loadFontFaceInBrowser(face, displaySrc, "all");
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
const toggleActivateFont = (font, face) => {
|
|
289
|
+
const initialFonts = fontFamilies?.[font.source ?? ""] ?? [];
|
|
290
|
+
const newFonts = toggleFont(font, face, initialFonts);
|
|
291
|
+
setFontFamilies({
|
|
292
|
+
...fontFamilies,
|
|
293
|
+
[font.source ?? ""]: newFonts
|
|
294
|
+
});
|
|
295
|
+
const isFaceActivated = isFontActivated(
|
|
296
|
+
font.slug,
|
|
297
|
+
face?.fontStyle ?? "",
|
|
298
|
+
face?.fontWeight ?? "",
|
|
299
|
+
font.source ?? "custom"
|
|
300
|
+
);
|
|
301
|
+
if (face && isFaceActivated) {
|
|
302
|
+
unloadFontFaceInBrowser(face, "all");
|
|
303
|
+
} else {
|
|
304
|
+
const displaySrc = getDisplaySrcFromFontFace(face?.src ?? "");
|
|
305
|
+
if (face && displaySrc) {
|
|
306
|
+
loadFontFaceInBrowser(face, displaySrc, "all");
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
const loadFontFaceAsset = async (fontFace) => {
|
|
311
|
+
if (!fontFace.src) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const src = getDisplaySrcFromFontFace(fontFace.src);
|
|
315
|
+
if (!src || loadedFontUrls.has(src)) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
loadFontFaceInBrowser(fontFace, src, "document");
|
|
319
|
+
loadedFontUrls.add(src);
|
|
320
|
+
};
|
|
321
|
+
const [collections, setFontCollections] = useState(
|
|
322
|
+
[]
|
|
323
|
+
);
|
|
324
|
+
const getFontCollections = async () => {
|
|
325
|
+
const response = await fetchFontCollections();
|
|
326
|
+
setFontCollections(response);
|
|
327
|
+
};
|
|
328
|
+
const getFontCollection = async (slug) => {
|
|
329
|
+
try {
|
|
330
|
+
const hasData = !!collections.find(
|
|
331
|
+
(collection) => collection.slug === slug
|
|
332
|
+
)?.font_families;
|
|
333
|
+
if (hasData) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const response = await fetchFontCollection(slug);
|
|
337
|
+
const updatedCollections = collections.map(
|
|
338
|
+
(collection) => collection.slug === slug ? { ...collection, ...response } : collection
|
|
339
|
+
);
|
|
340
|
+
setFontCollections(updatedCollections);
|
|
341
|
+
} catch (e) {
|
|
342
|
+
console.error(e);
|
|
343
|
+
throw e;
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
useEffect(() => {
|
|
347
|
+
getFontCollections();
|
|
348
|
+
}, []);
|
|
349
|
+
return /* @__PURE__ */ jsx(
|
|
350
|
+
FontLibraryContext.Provider,
|
|
351
|
+
{
|
|
352
|
+
value: {
|
|
353
|
+
libraryFontSelected,
|
|
354
|
+
handleSetLibraryFontSelected,
|
|
355
|
+
fontFamilies: fontFamilies ?? {},
|
|
356
|
+
baseCustomFonts,
|
|
357
|
+
isFontActivated,
|
|
358
|
+
getFontFacesActivated,
|
|
359
|
+
loadFontFaceAsset,
|
|
360
|
+
installFonts,
|
|
361
|
+
uninstallFontFamily,
|
|
362
|
+
toggleActivateFont,
|
|
363
|
+
getAvailableFontsOutline,
|
|
364
|
+
modalTabOpen,
|
|
365
|
+
setModalTabOpen,
|
|
366
|
+
refreshLibrary,
|
|
367
|
+
saveFontFamilies,
|
|
368
|
+
isResolvingLibrary,
|
|
369
|
+
isInstalling,
|
|
370
|
+
collections,
|
|
371
|
+
getFontCollection
|
|
372
|
+
},
|
|
373
|
+
children
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
var context_default = FontLibraryProvider;
|
|
378
|
+
export {
|
|
379
|
+
FontLibraryContext,
|
|
380
|
+
context_default as default
|
|
381
|
+
};
|
|
382
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/font-library-modal/context.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext, useState, useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseEntityRecord,\n\tuseEntityRecords,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport type {\n\tFontFamilyPreset,\n\tGlobalStylesConfig,\n} from '@wordpress/global-styles-engine';\n\n/**\n * Internal dependencies\n */\nimport {\n\tfetchGetFontFamilyBySlug,\n\tfetchInstallFontFamily,\n\tfetchUninstallFontFamily,\n\tfetchFontCollections,\n\tfetchFontCollection,\n} from './resolvers';\nimport {\n\tsetUIValuesNeeded,\n\tmergeFontFamilies,\n\tloadFontFaceInBrowser,\n\tunloadFontFaceInBrowser,\n\tgetDisplaySrcFromFontFace,\n\tmakeFontFacesFormData,\n\tmakeFontFamilyFormData,\n\tbatchInstallFontFaces,\n\tcheckFontFaceInstalled,\n} from './utils';\nimport { setImmutably } from './utils/set-immutably';\nimport { toggleFont } from './utils/toggleFont';\nimport type {\n\tCollectionFontFamily,\n\tFontCollection,\n\tFontFace,\n\tFontFamily,\n\tFontLibraryState,\n} from './types';\nimport { useSetting } from '../hooks';\n\nexport const FontLibraryContext = createContext< FontLibraryState >(\n\t{} as FontLibraryState\n);\nFontLibraryContext.displayName = 'FontLibraryContext';\n\nfunction FontLibraryProvider( { children }: { children: React.ReactNode } ) {\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { globalStylesId } = useSelect( ( select ) => {\n\t\tconst { __experimentalGetCurrentGlobalStylesId } = select( coreStore );\n\t\treturn { globalStylesId: __experimentalGetCurrentGlobalStylesId() };\n\t}, [] );\n\n\tconst globalStyles = useEntityRecord< GlobalStylesConfig >(\n\t\t'root',\n\t\t'globalStyles',\n\t\tglobalStylesId\n\t);\n\n\tconst [ isInstalling, setIsInstalling ] = useState( false );\n\tconst [ refreshKey, setRefreshKey ] = useState( 0 );\n\n\tconst refreshLibrary = () => {\n\t\tsetRefreshKey( Date.now() );\n\t};\n\n\tconst { records: libraryPosts = [], isResolving: isResolvingLibrary } =\n\t\tuseEntityRecords< CollectionFontFamily >(\n\t\t\t'postType',\n\t\t\t'wp_font_family',\n\t\t\t{\n\t\t\t\trefreshKey,\n\t\t\t\t_embed: true,\n\t\t\t}\n\t\t);\n\n\tconst libraryFonts: FontFamilyPreset[] =\n\t\t( libraryPosts || [] ).map( ( fontFamilyPost ) => {\n\t\t\treturn {\n\t\t\t\tid: fontFamilyPost.id,\n\t\t\t\t...( fontFamilyPost.font_family_settings || {} ),\n\t\t\t\tfontFace:\n\t\t\t\t\tfontFamilyPost?._embedded?.font_faces?.map(\n\t\t\t\t\t\t( face ) => face.font_face_settings\n\t\t\t\t\t) || [],\n\t\t\t};\n\t\t} ) || [];\n\n\t// Global Styles (settings) font families\n\tconst [ fontFamilies, setFontFamilies ] = useSetting<\n\t\tRecord< string, FontFamilyPreset[] > | undefined\n\t>( 'typography.fontFamilies' );\n\n\t/*\n\t * Save the font families to the database.\n\n\t * This function is called when the user activates or deactivates a font family.\n\t * It only updates the global styles post content in the database for new font families.\n\t * This avoids saving other styles/settings changed by the user using other parts of the editor.\n\t *\n\t * It uses the font families from the param to avoid using the font families from an outdated state.\n\t *\n\t * @param {Array} fonts - The font families that will be saved to the database.\n\t */\n\tconst saveFontFamilies = async (\n\t\tfonts:\n\t\t\t| FontFamilyPreset[]\n\t\t\t| Record< string, FontFamilyPreset[] >\n\t\t\t| undefined\n\t) => {\n\t\t// Gets the global styles database post content.\n\t\tconst updatedGlobalStyles = globalStyles.record;\n\n\t\t// Updates the database version of global styles with the edited font families in the client.\n\t\tsetImmutably(\n\t\t\tupdatedGlobalStyles ?? {},\n\t\t\t[ 'settings', 'typography', 'fontFamilies' ],\n\t\t\tfonts\n\t\t);\n\n\t\t// Saves a new version of the global styles in the database.\n\t\tawait saveEntityRecord( 'root', 'globalStyles', updatedGlobalStyles );\n\t};\n\n\t// Library Fonts\n\tconst [ modalTabOpen, setModalTabOpen ] = useState( '' );\n\tconst [ libraryFontSelected, setLibraryFontSelected ] = useState<\n\t\tFontFamily | undefined\n\t>( undefined );\n\n\t// Themes Fonts are the fonts defined in the global styles (database persisted theme.json data).\n\tconst themeFonts = fontFamilies?.theme\n\t\t? fontFamilies.theme\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'theme' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tconst customFonts = fontFamilies?.custom\n\t\t? fontFamilies.custom\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'custom' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tconst baseCustomFonts = libraryFonts\n\t\t? libraryFonts\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'custom' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tuseEffect( () => {\n\t\tif ( ! modalTabOpen ) {\n\t\t\tsetLibraryFontSelected( undefined );\n\t\t}\n\t}, [ modalTabOpen ] );\n\n\tconst handleSetLibraryFontSelected = ( font?: FontFamily ) => {\n\t\t// If font is null, reset the selected font\n\t\tif ( ! font ) {\n\t\t\tsetLibraryFontSelected( undefined );\n\t\t\treturn;\n\t\t}\n\n\t\tconst fonts = font.source === 'theme' ? themeFonts : baseCustomFonts;\n\n\t\t// Tries to find the font in the installed fonts\n\t\tconst fontSelected = fonts.find( ( f ) => f.slug === font.slug );\n\t\t// If the font is not found (it is only defined in custom styles), use the font from custom styles\n\t\tsetLibraryFontSelected( {\n\t\t\t...( fontSelected || font ),\n\t\t\tsource: font.source,\n\t\t} );\n\t};\n\n\t// Demo\n\tconst [ loadedFontUrls ] = useState( new Set() );\n\n\tconst getAvailableFontsOutline = (\n\t\tavailableFontFamilies: FontFamily[]\n\t) => {\n\t\tconst outline: Record< string, string[] > =\n\t\t\tavailableFontFamilies.reduce(\n\t\t\t\t( acc: Record< string, string[] >, font ) => {\n\t\t\t\t\tconst availableFontFaces =\n\t\t\t\t\t\tfont?.fontFace && font.fontFace?.length > 0\n\t\t\t\t\t\t\t? font?.fontFace.map(\n\t\t\t\t\t\t\t\t\t( face ) =>\n\t\t\t\t\t\t\t\t\t\t`${ face.fontStyle ?? '' }${\n\t\t\t\t\t\t\t\t\t\t\tface.fontWeight ?? ''\n\t\t\t\t\t\t\t\t\t\t}`\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: [ 'normal400' ]; // If the font doesn't have fontFace, we assume it is a system font and we add the defaults: normal 400\n\n\t\t\t\t\tacc[ font.slug ] = availableFontFaces;\n\t\t\t\t\treturn acc;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\t\treturn outline;\n\t};\n\n\tconst getActivatedFontsOutline = ( source?: string ) => {\n\t\tswitch ( source ) {\n\t\t\tcase 'theme':\n\t\t\t\treturn getAvailableFontsOutline( themeFonts );\n\t\t\tcase 'custom':\n\t\t\tdefault:\n\t\t\t\treturn getAvailableFontsOutline( customFonts );\n\t\t}\n\t};\n\n\tconst isFontActivated = (\n\t\tslug: string,\n\t\tstyle?: string,\n\t\tweight?: string | number,\n\t\tsource?: string\n\t) => {\n\t\tif ( ! style && ! weight ) {\n\t\t\treturn !! getActivatedFontsOutline( source )[ slug ];\n\t\t}\n\t\treturn !! getActivatedFontsOutline( source )[ slug ]?.includes(\n\t\t\t( style ?? '' ) + ( weight ?? '' )\n\t\t);\n\t};\n\n\tconst getFontFacesActivated = ( slug: string, source?: string ) => {\n\t\treturn getActivatedFontsOutline( source )[ slug ] || [];\n\t};\n\n\tasync function installFonts( fontFamiliesToInstall: FontFamily[] ) {\n\t\tsetIsInstalling( true );\n\t\ttry {\n\t\t\tconst fontFamiliesToActivate = [];\n\t\t\tlet installationErrors: Array< {\n\t\t\t\tmessage: string;\n\t\t\t} > = [];\n\n\t\t\tfor ( const fontFamilyToInstall of fontFamiliesToInstall ) {\n\t\t\t\tlet isANewFontFamily = false;\n\n\t\t\t\t// Get the font family if it already exists.\n\t\t\t\tlet installedFontFamily = await fetchGetFontFamilyBySlug(\n\t\t\t\t\tfontFamilyToInstall.slug\n\t\t\t\t);\n\n\t\t\t\t// Otherwise create it.\n\t\t\t\tif ( ! installedFontFamily ) {\n\t\t\t\t\tisANewFontFamily = true;\n\t\t\t\t\t// Prepare font family form data to install.\n\t\t\t\t\tinstalledFontFamily = await fetchInstallFontFamily(\n\t\t\t\t\t\tmakeFontFamilyFormData( fontFamilyToInstall )\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Collect font faces that have already been installed (to be activated later)\n\t\t\t\tconst alreadyInstalledFontFaces =\n\t\t\t\t\tinstalledFontFamily.fontFace && fontFamilyToInstall.fontFace\n\t\t\t\t\t\t? installedFontFamily.fontFace.filter(\n\t\t\t\t\t\t\t\t( fontFaceToInstall: FontFace ) =>\n\t\t\t\t\t\t\t\t\tfontFaceToInstall &&\n\t\t\t\t\t\t\t\t\tfontFamilyToInstall.fontFace &&\n\t\t\t\t\t\t\t\t\tcheckFontFaceInstalled(\n\t\t\t\t\t\t\t\t\t\tfontFaceToInstall,\n\t\t\t\t\t\t\t\t\t\tfontFamilyToInstall.fontFace\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: [];\n\n\t\t\t\t// Filter out Font Faces that have already been installed (so that they are not re-installed)\n\t\t\t\tif (\n\t\t\t\t\tinstalledFontFamily.fontFace &&\n\t\t\t\t\tfontFamilyToInstall.fontFace\n\t\t\t\t) {\n\t\t\t\t\tfontFamilyToInstall.fontFace =\n\t\t\t\t\t\tfontFamilyToInstall.fontFace.filter(\n\t\t\t\t\t\t\t( fontFaceToInstall ) =>\n\t\t\t\t\t\t\t\t! checkFontFaceInstalled(\n\t\t\t\t\t\t\t\t\tfontFaceToInstall,\n\t\t\t\t\t\t\t\t\tinstalledFontFamily.fontFace\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Install the fonts (upload the font files to the server and create the post in the database).\n\t\t\t\tlet successfullyInstalledFontFaces: FontFace[] = [];\n\t\t\t\tlet unsuccessfullyInstalledFontFaces: {\n\t\t\t\t\tmessage: string;\n\t\t\t\t}[] = [];\n\t\t\t\tif ( fontFamilyToInstall?.fontFace?.length ?? 0 > 0 ) {\n\t\t\t\t\tconst response = await batchInstallFontFaces(\n\t\t\t\t\t\tinstalledFontFamily.id,\n\t\t\t\t\t\tmakeFontFacesFormData(\n\t\t\t\t\t\t\tfontFamilyToInstall as FontFamily\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t\tsuccessfullyInstalledFontFaces = response?.successes;\n\t\t\t\t\tunsuccessfullyInstalledFontFaces = response?.errors;\n\t\t\t\t}\n\n\t\t\t\t// Use the successfully installed font faces\n\t\t\t\t// As well as any font faces that were already installed (those will be activated)\n\t\t\t\tif (\n\t\t\t\t\tsuccessfullyInstalledFontFaces?.length > 0 ||\n\t\t\t\t\talreadyInstalledFontFaces?.length > 0\n\t\t\t\t) {\n\t\t\t\t\t// Use font data from REST API not from client to ensure\n\t\t\t\t\t// correct font information is used.\n\t\t\t\t\tinstalledFontFamily.fontFace = [\n\t\t\t\t\t\t...successfullyInstalledFontFaces,\n\t\t\t\t\t];\n\n\t\t\t\t\tfontFamiliesToActivate.push( installedFontFamily );\n\t\t\t\t}\n\n\t\t\t\t// If it's a system font but was installed successfully, activate it.\n\t\t\t\tif (\n\t\t\t\t\tinstalledFontFamily &&\n\t\t\t\t\t! fontFamilyToInstall?.fontFace?.length\n\t\t\t\t) {\n\t\t\t\t\tfontFamiliesToActivate.push( installedFontFamily );\n\t\t\t\t}\n\n\t\t\t\t// If the font family is new and is not a system font, delete it to avoid having font families without font faces.\n\t\t\t\tif (\n\t\t\t\t\tisANewFontFamily &&\n\t\t\t\t\t( fontFamilyToInstall?.fontFace?.length ?? 0 ) > 0 &&\n\t\t\t\t\tsuccessfullyInstalledFontFaces?.length === 0\n\t\t\t\t) {\n\t\t\t\t\tawait fetchUninstallFontFamily( installedFontFamily.id );\n\t\t\t\t}\n\n\t\t\t\tinstallationErrors = installationErrors.concat(\n\t\t\t\t\tunsuccessfullyInstalledFontFaces\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst installationErrorMessages: string[] =\n\t\t\t\tinstallationErrors.reduce(\n\t\t\t\t\t( unique: string[], item ) =>\n\t\t\t\t\t\tunique.includes( item.message )\n\t\t\t\t\t\t\t? unique\n\t\t\t\t\t\t\t: [ ...unique, item.message ],\n\t\t\t\t\t[]\n\t\t\t\t);\n\n\t\t\tif ( fontFamiliesToActivate.length > 0 ) {\n\t\t\t\t// Activate the font family (add the font family to the global styles).\n\t\t\t\tconst activeFonts = activateCustomFontFamilies(\n\t\t\t\t\tfontFamiliesToActivate\n\t\t\t\t);\n\t\t\t\t// Save the global styles to the database.\n\t\t\t\tawait saveFontFamilies( activeFonts );\n\n\t\t\t\trefreshLibrary();\n\t\t\t}\n\n\t\t\tif ( installationErrorMessages.length > 0 ) {\n\t\t\t\tconst installError: Error & {\n\t\t\t\t\tinstallationErrors?: string[];\n\t\t\t\t} = new Error( __( 'There was an error installing fonts.' ) );\n\n\t\t\t\tinstallError.installationErrors = installationErrorMessages;\n\n\t\t\t\tthrow installError;\n\t\t\t}\n\t\t} finally {\n\t\t\tsetIsInstalling( false );\n\t\t}\n\t}\n\n\tasync function uninstallFontFamily( fontFamilyToUninstall: FontFamily ) {\n\t\tif ( ! fontFamilyToUninstall?.id ) {\n\t\t\tthrow new Error( __( 'Font family to uninstall is not defined.' ) );\n\t\t}\n\t\ttry {\n\t\t\t// Uninstall the font family.\n\t\t\t// (Removes the font files from the server and the posts from the database).\n\t\t\tconst uninstalledFontFamily = await fetchUninstallFontFamily(\n\t\t\t\tfontFamilyToUninstall.id\n\t\t\t);\n\n\t\t\t// Deactivate the font family if delete request is successful\n\t\t\t// (Removes the font family from the global styles).\n\t\t\tif ( uninstalledFontFamily.deleted ) {\n\t\t\t\tconst activeFonts = deactivateFontFamily(\n\t\t\t\t\tfontFamilyToUninstall\n\t\t\t\t);\n\t\t\t\t// Save the global styles to the database.\n\t\t\t\tawait saveFontFamilies( activeFonts );\n\t\t\t}\n\n\t\t\t// Refresh the library (the library font families from database).\n\t\t\trefreshLibrary();\n\n\t\t\treturn uninstalledFontFamily;\n\t\t} catch ( error ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error(\n\t\t\t\t`There was an error uninstalling the font family:`,\n\t\t\t\terror\n\t\t\t);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tconst deactivateFontFamily = ( font: FontFamily ) => {\n\t\t// If the user doesn't have custom fonts defined, include as custom fonts all the theme fonts\n\t\t// We want to save as active all the theme fonts at the beginning\n\t\tconst initialCustomFonts = fontFamilies?.[ font.source ?? '' ] ?? [];\n\t\tconst newCustomFonts = initialCustomFonts.filter(\n\t\t\t( f ) => f.slug !== font.slug\n\t\t);\n\t\tconst activeFonts = {\n\t\t\t...fontFamilies,\n\t\t\t[ font.source ?? '' ]: newCustomFonts,\n\t\t};\n\t\tsetFontFamilies( activeFonts );\n\n\t\tif ( font.fontFace ) {\n\t\t\tfont.fontFace.forEach( ( face ) => {\n\t\t\t\tunloadFontFaceInBrowser( face, 'all' );\n\t\t\t} );\n\t\t}\n\t\treturn activeFonts;\n\t};\n\n\tconst activateCustomFontFamilies = ( fontsToAdd: FontFamily[] ) => {\n\t\tconst fontsToActivate = cleanFontsForSave( fontsToAdd );\n\n\t\tconst activeFonts = {\n\t\t\t...fontFamilies,\n\t\t\t// Merge the existing custom fonts with the new fonts.\n\t\t\tcustom: mergeFontFamilies( fontFamilies?.custom, fontsToActivate ),\n\t\t};\n\n\t\t// Activate the fonts by set the new custom fonts array.\n\t\tsetFontFamilies( activeFonts );\n\n\t\tloadFontsInBrowser( fontsToActivate );\n\n\t\treturn activeFonts;\n\t};\n\n\t// Removes the id from the families and faces to avoid saving that to global styles post content.\n\tconst cleanFontsForSave = ( fonts: FontFamily[] ) => {\n\t\treturn fonts.map( ( { id: _familyDbId, fontFace, ...font } ) => ( {\n\t\t\t...font,\n\t\t\t...( fontFace && fontFace.length > 0\n\t\t\t\t? {\n\t\t\t\t\t\tfontFace: fontFace.map(\n\t\t\t\t\t\t\t( { id: _faceDbId, ...face } ) => face\n\t\t\t\t\t\t),\n\t\t\t\t }\n\t\t\t\t: {} ),\n\t\t} ) );\n\t};\n\n\tconst loadFontsInBrowser = ( fonts: FontFamily[] ) => {\n\t\t// Add custom fonts to the browser.\n\t\tfonts.forEach( ( font ) => {\n\t\t\tif ( font.fontFace ) {\n\t\t\t\tfont.fontFace.forEach( ( face ) => {\n\t\t\t\t\tconst displaySrc = getDisplaySrcFromFontFace(\n\t\t\t\t\t\tface?.src ?? ''\n\t\t\t\t\t);\n\t\t\t\t\tif ( displaySrc ) {\n\t\t\t\t\t\t// Load font faces just in the iframe because they already are in the document.\n\t\t\t\t\t\tloadFontFaceInBrowser( face, displaySrc, 'all' );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t};\n\n\tconst toggleActivateFont = ( font: FontFamily, face?: FontFace ) => {\n\t\t// If the user doesn't have custom fonts defined, include as custom fonts all the theme fonts\n\t\t// We want to save as active all the theme fonts at the beginning\n\t\tconst initialFonts = fontFamilies?.[ font.source ?? '' ] ?? [];\n\t\t// Toggles the received font family or font face\n\t\tconst newFonts = toggleFont( font, face, initialFonts );\n\t\t// Updates the font families activated in global settings:\n\t\tsetFontFamilies( {\n\t\t\t...fontFamilies,\n\t\t\t[ font.source ?? '' ]: newFonts,\n\t\t} );\n\n\t\tconst isFaceActivated = isFontActivated(\n\t\t\tfont.slug,\n\t\t\tface?.fontStyle ?? '',\n\t\t\tface?.fontWeight ?? '',\n\t\t\tfont.source ?? 'custom'\n\t\t);\n\n\t\tif ( face && isFaceActivated ) {\n\t\t\tunloadFontFaceInBrowser( face, 'all' );\n\t\t} else {\n\t\t\tconst displaySrc = getDisplaySrcFromFontFace( face?.src ?? '' );\n\t\t\t// If the font doesn't have a src, don't load it.\n\t\t\tif ( face && displaySrc ) {\n\t\t\t\tloadFontFaceInBrowser( face, displaySrc, 'all' );\n\t\t\t}\n\t\t}\n\t};\n\n\tconst loadFontFaceAsset = async ( fontFace: FontFace ) => {\n\t\t// If the font doesn't have a src, don't load it.\n\t\tif ( ! fontFace.src ) {\n\t\t\treturn;\n\t\t}\n\t\t// Get the src of the font.\n\t\tconst src = getDisplaySrcFromFontFace( fontFace.src );\n\t\t// If the font is already loaded, don't load it again.\n\t\tif ( ! src || loadedFontUrls.has( src ) ) {\n\t\t\treturn;\n\t\t}\n\t\t// Load the font in the browser.\n\t\tloadFontFaceInBrowser( fontFace, src, 'document' );\n\t\t// Add the font to the loaded fonts list.\n\t\tloadedFontUrls.add( src );\n\t};\n\n\t// Font Collections\n\tconst [ collections, setFontCollections ] = useState< FontCollection[] >(\n\t\t[]\n\t);\n\tconst getFontCollections = async () => {\n\t\tconst response = await fetchFontCollections();\n\t\tsetFontCollections( response );\n\t};\n\tconst getFontCollection = async ( slug: string ) => {\n\t\ttry {\n\t\t\tconst hasData = !! collections.find(\n\t\t\t\t( collection ) => collection.slug === slug\n\t\t\t)?.font_families;\n\t\t\tif ( hasData ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst response = await fetchFontCollection( slug );\n\t\t\tconst updatedCollections = collections.map( ( collection ) =>\n\t\t\t\tcollection.slug === slug\n\t\t\t\t\t? { ...collection, ...response }\n\t\t\t\t\t: collection\n\t\t\t);\n\t\t\tsetFontCollections( updatedCollections );\n\t\t} catch ( e ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( e );\n\t\t\tthrow e;\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tgetFontCollections();\n\t}, [] );\n\n\treturn (\n\t\t<FontLibraryContext.Provider\n\t\t\tvalue={ {\n\t\t\t\tlibraryFontSelected,\n\t\t\t\thandleSetLibraryFontSelected,\n\t\t\t\tfontFamilies: fontFamilies ?? {},\n\t\t\t\tbaseCustomFonts,\n\t\t\t\tisFontActivated,\n\t\t\t\tgetFontFacesActivated,\n\t\t\t\tloadFontFaceAsset,\n\t\t\t\tinstallFonts,\n\t\t\t\tuninstallFontFamily,\n\t\t\t\ttoggleActivateFont,\n\t\t\t\tgetAvailableFontsOutline,\n\t\t\t\tmodalTabOpen,\n\t\t\t\tsetModalTabOpen,\n\t\t\t\trefreshLibrary,\n\t\t\t\tsaveFontFamilies,\n\t\t\t\tisResolvingLibrary,\n\t\t\t\tisInstalling,\n\t\t\t\tcollections,\n\t\t\t\tgetFontCollection,\n\t\t\t} }\n\t\t>\n\t\t\t{ children }\n\t\t</FontLibraryContext.Provider>\n\t);\n}\n\nexport default FontLibraryProvider;\n"],
|
|
5
|
+
"mappings": "AAkjBE;AA/iBF,SAAS,eAAe,UAAU,iBAAiB;AACnD,SAAS,WAAW,mBAAmB;AACvC;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QAC/B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,MAEE;AAAA;AAAA,EACH;AAEF;AAEA,IAAO,kBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { _n, sprintf, isRTL } from "@wordpress/i18n";
|
|
3
|
+
import {
|
|
4
|
+
useNavigator,
|
|
5
|
+
__experimentalText as Text,
|
|
6
|
+
Button,
|
|
7
|
+
Flex,
|
|
8
|
+
FlexItem
|
|
9
|
+
} from "@wordpress/components";
|
|
10
|
+
import { Icon, chevronLeft, chevronRight } from "@wordpress/icons";
|
|
11
|
+
import FontDemo from "./font-demo";
|
|
12
|
+
function FontCard({
|
|
13
|
+
font,
|
|
14
|
+
onClick,
|
|
15
|
+
variantsText,
|
|
16
|
+
navigatorPath
|
|
17
|
+
}) {
|
|
18
|
+
const variantsCount = font.fontFace?.length || 1;
|
|
19
|
+
const style = {
|
|
20
|
+
cursor: !!onClick ? "pointer" : "default"
|
|
21
|
+
};
|
|
22
|
+
const navigator = useNavigator();
|
|
23
|
+
return /* @__PURE__ */ jsx(
|
|
24
|
+
Button,
|
|
25
|
+
{
|
|
26
|
+
__next40pxDefaultSize: true,
|
|
27
|
+
onClick: () => {
|
|
28
|
+
onClick();
|
|
29
|
+
if (navigatorPath) {
|
|
30
|
+
navigator.goTo(navigatorPath);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
style,
|
|
34
|
+
className: "font-library-modal__font-card",
|
|
35
|
+
children: /* @__PURE__ */ jsxs(Flex, { justify: "space-between", wrap: false, children: [
|
|
36
|
+
/* @__PURE__ */ jsx(FontDemo, { font }),
|
|
37
|
+
/* @__PURE__ */ jsxs(Flex, { justify: "flex-end", children: [
|
|
38
|
+
/* @__PURE__ */ jsx(FlexItem, { children: /* @__PURE__ */ jsx(Text, { className: "font-library-modal__font-card__count", children: variantsText || sprintf(
|
|
39
|
+
/* translators: %d: Number of font variants. */
|
|
40
|
+
_n(
|
|
41
|
+
"%d variant",
|
|
42
|
+
"%d variants",
|
|
43
|
+
variantsCount
|
|
44
|
+
),
|
|
45
|
+
variantsCount
|
|
46
|
+
) }) }),
|
|
47
|
+
/* @__PURE__ */ jsx(FlexItem, { children: /* @__PURE__ */ jsx(Icon, { icon: isRTL() ? chevronLeft : chevronRight }) })
|
|
48
|
+
] })
|
|
49
|
+
] })
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
var font_card_default = FontCard;
|
|
54
|
+
export {
|
|
55
|
+
font_card_default as default
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=font-card.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/font-library-modal/font-card.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { _n, sprintf, isRTL } from '@wordpress/i18n';\nimport {\n\tuseNavigator,\n\t__experimentalText as Text,\n\tButton,\n\tFlex,\n\tFlexItem,\n} from '@wordpress/components';\nimport { Icon, chevronLeft, chevronRight } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport FontDemo from './font-demo';\nimport type { FontFamily } from './types';\n\nfunction FontCard( {\n\tfont,\n\tonClick,\n\tvariantsText,\n\tnavigatorPath,\n}: {\n\tfont: FontFamily;\n\tonClick: () => void;\n\tvariantsText?: string;\n\tnavigatorPath?: string;\n} ) {\n\tconst variantsCount = font.fontFace?.length || 1;\n\n\tconst style = {\n\t\tcursor: !! onClick ? 'pointer' : 'default',\n\t};\n\n\tconst navigator = useNavigator();\n\n\treturn (\n\t\t<Button\n\t\t\t__next40pxDefaultSize\n\t\t\tonClick={ () => {\n\t\t\t\tonClick();\n\t\t\t\tif ( navigatorPath ) {\n\t\t\t\t\tnavigator.goTo( navigatorPath );\n\t\t\t\t}\n\t\t\t} }\n\t\t\tstyle={ style }\n\t\t\tclassName=\"font-library-modal__font-card\"\n\t\t>\n\t\t\t<Flex justify=\"space-between\" wrap={ false }>\n\t\t\t\t<FontDemo font={ font } />\n\t\t\t\t<Flex justify=\"flex-end\">\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<Text className=\"font-library-modal__font-card__count\">\n\t\t\t\t\t\t\t{ variantsText ||\n\t\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t\t/* translators: %d: Number of font variants. */\n\t\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t\t'%d variant',\n\t\t\t\t\t\t\t\t\t\t'%d variants',\n\t\t\t\t\t\t\t\t\t\tvariantsCount\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\tvariantsCount\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Text>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<Icon icon={ isRTL() ? chevronLeft : chevronRight } />\n\t\t\t\t\t</FlexItem>\n\t\t\t\t</Flex>\n\t\t\t</Flex>\n\t\t</Button>\n\t);\n}\n\nexport default FontCard;\n"],
|
|
5
|
+
"mappings": "AAmDI,cACA,YADA;AAhDJ,SAAS,IAAI,SAAS,aAAa;AACnC;AAAA,EACC;AAAA,EACA,sBAAsB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,MAAM,aAAa,oBAAoB;AAKhD,OAAO,cAAc;AAGrB,SAAS,SAAU;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAKI;AACH,QAAM,gBAAgB,KAAK,UAAU,UAAU;AAE/C,QAAM,QAAQ;AAAA,IACb,QAAQ,CAAC,CAAE,UAAU,YAAY;AAAA,EAClC;AAEA,QAAM,YAAY,aAAa;AAE/B,SACC;AAAA,IAAC;AAAA;AAAA,MACA,uBAAqB;AAAA,MACrB,SAAU,MAAM;AACf,gBAAQ;AACR,YAAK,eAAgB;AACpB,oBAAU,KAAM,aAAc;AAAA,QAC/B;AAAA,MACD;AAAA,MACA;AAAA,MACA,WAAU;AAAA,MAEV,+BAAC,QAAK,SAAQ,iBAAgB,MAAO,OACpC;AAAA,4BAAC,YAAS,MAAc;AAAA,QACxB,qBAAC,QAAK,SAAQ,YACb;AAAA,8BAAC,YACA,8BAAC,QAAK,WAAU,wCACb,0BACD;AAAA;AAAA,YAEC;AAAA,cACC;AAAA,cACA;AAAA,cACA;AAAA,YACD;AAAA,YACA;AAAA,UACD,GACF,GACD;AAAA,UACA,oBAAC,YACA,8BAAC,QAAK,MAAO,MAAM,IAAI,cAAc,cAAe,GACrD;AAAA,WACD;AAAA,SACD;AAAA;AAAA,EACD;AAEF;AAEA,IAAO,oBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|