@wordpress/components 23.6.0 → 23.8.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 +43 -4
- package/build/angle-picker-control/angle-circle.js +1 -4
- package/build/angle-picker-control/angle-circle.js.map +1 -1
- package/build/angle-picker-control/index.js +10 -22
- package/build/angle-picker-control/index.js.map +1 -1
- package/build/angle-picker-control/styles/angle-picker-control-styles.js +24 -15
- package/build/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
- package/build/animate/index.js +27 -19
- package/build/animate/index.js.map +1 -1
- package/build/animate/types.js.map +1 -0
- package/build/box-control/axial-input-controls.js.map +1 -1
- package/build/color-picker/color-input.js +0 -4
- package/build/color-picker/color-input.js.map +1 -1
- package/build/color-picker/component.js +5 -4
- package/build/color-picker/component.js.map +1 -1
- package/build/color-picker/hex-input.js.map +1 -1
- package/build/color-picker/hsl-input.js.map +1 -1
- package/build/color-picker/input-with-slider.js.map +1 -1
- package/build/color-picker/legacy-adapter.js.map +1 -1
- package/build/color-picker/picker.js.map +1 -1
- package/build/color-picker/rgb-input.js.map +1 -1
- package/build/color-picker/use-deprecated-props.js.map +1 -1
- package/build/custom-gradient-picker/constants.js +1 -1
- package/build/custom-gradient-picker/constants.js.map +1 -1
- package/build/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
- package/build/custom-gradient-picker/gradient-bar/control-points.js +9 -5
- package/build/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
- package/build/custom-gradient-picker/gradient-bar/index.js +14 -9
- package/build/custom-gradient-picker/gradient-bar/index.js.map +1 -1
- package/build/custom-gradient-picker/gradient-bar/utils.js +34 -54
- package/build/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
- package/build/custom-gradient-picker/index.js +45 -16
- package/build/custom-gradient-picker/index.js.map +1 -1
- package/build/custom-gradient-picker/serializer.js +10 -4
- package/build/custom-gradient-picker/serializer.js.map +1 -1
- package/build/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
- package/build/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
- package/build/custom-gradient-picker/types.js +6 -0
- package/build/custom-gradient-picker/types.js.map +1 -0
- package/build/custom-gradient-picker/utils.js +17 -12
- package/build/custom-gradient-picker/utils.js.map +1 -1
- package/build/drop-zone/index.js +8 -8
- package/build/drop-zone/index.js.map +1 -1
- package/build/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
- package/build/duotone-picker/color-list-picker/index.js.map +1 -0
- package/build/duotone-picker/color-list-picker/types.js +6 -0
- package/build/duotone-picker/color-list-picker/types.js.map +1 -0
- package/build/duotone-picker/custom-duotone-bar.js.map +1 -1
- package/build/duotone-picker/duotone-picker.js +39 -2
- package/build/duotone-picker/duotone-picker.js.map +1 -1
- package/build/duotone-picker/duotone-swatch.js.map +1 -1
- package/build/duotone-picker/index.js.map +1 -1
- package/build/duotone-picker/types.js +6 -0
- package/build/duotone-picker/types.js.map +1 -0
- package/build/duotone-picker/utils.js +13 -11
- package/build/duotone-picker/utils.js.map +1 -1
- package/build/form-token-field/index.js +9 -3
- package/build/form-token-field/index.js.map +1 -1
- package/build/gradient-picker/index.js +61 -9
- package/build/gradient-picker/index.js.map +1 -1
- package/build/gradient-picker/types.js +6 -0
- package/build/gradient-picker/types.js.map +1 -0
- package/build/index.js.map +1 -1
- package/build/mobile/keyboard-aware-flat-list/index.android.js +0 -4
- package/build/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
- package/build/mobile/keyboard-aware-flat-list/index.ios.js +100 -55
- package/build/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
- package/build/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +82 -0
- package/build/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js.map +1 -0
- package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +85 -0
- package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +1 -0
- package/build/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +44 -0
- package/build/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js.map +1 -0
- package/build/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +53 -0
- package/build/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js.map +1 -0
- package/build/navigator/navigator-provider/component.js +4 -2
- package/build/navigator/navigator-provider/component.js.map +1 -1
- package/build/navigator/navigator-screen/component.js +4 -3
- package/build/navigator/navigator-screen/component.js.map +1 -1
- package/build/palette-edit/index.js +1 -2
- package/build/palette-edit/index.js.map +1 -1
- package/build/private-apis.js.map +1 -1
- package/build/query-controls/author-select.js +2 -1
- package/build/query-controls/author-select.js.map +1 -1
- package/build/query-controls/category-select.js +3 -1
- package/build/query-controls/category-select.js.map +1 -1
- package/build/query-controls/index.js +7 -1
- package/build/query-controls/index.js.map +1 -1
- package/build/resizable-box/resize-tooltip/utils.js.map +1 -1
- package/build/sandbox/index.native.js +129 -93
- package/build/sandbox/index.native.js.map +1 -1
- package/build/tab-panel/index.js +1 -1
- package/build/tab-panel/index.js.map +1 -1
- package/build/tools-panel/tools-panel/hook.js +45 -6
- package/build/tools-panel/tools-panel/hook.js.map +1 -1
- package/build/utils/input/input-control.js +1 -1
- package/build/utils/input/input-control.js.map +1 -1
- package/build-module/angle-picker-control/angle-circle.js +1 -4
- package/build-module/angle-picker-control/angle-circle.js.map +1 -1
- package/build-module/angle-picker-control/index.js +12 -21
- package/build-module/angle-picker-control/index.js.map +1 -1
- package/build-module/angle-picker-control/styles/angle-picker-control-styles.js +20 -13
- package/build-module/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
- package/build-module/animate/index.js +25 -17
- package/build-module/animate/index.js.map +1 -1
- package/build-module/box-control/axial-input-controls.js.map +1 -1
- package/build-module/color-picker/color-input.js +0 -4
- package/build-module/color-picker/color-input.js.map +1 -1
- package/build-module/color-picker/component.js +3 -3
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/color-picker/hex-input.js.map +1 -1
- package/build-module/color-picker/hsl-input.js.map +1 -1
- package/build-module/color-picker/input-with-slider.js.map +1 -1
- package/build-module/color-picker/legacy-adapter.js.map +1 -1
- package/build-module/color-picker/picker.js +4 -0
- package/build-module/color-picker/picker.js.map +1 -1
- package/build-module/color-picker/rgb-input.js.map +1 -1
- package/build-module/color-picker/use-deprecated-props.js.map +1 -1
- package/build-module/custom-gradient-picker/constants.js +1 -1
- package/build-module/custom-gradient-picker/constants.js.map +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/control-points.js +9 -4
- package/build-module/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/index.js +14 -8
- package/build-module/custom-gradient-picker/gradient-bar/index.js.map +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/utils.js +34 -54
- package/build-module/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
- package/build-module/custom-gradient-picker/index.js +44 -17
- package/build-module/custom-gradient-picker/index.js.map +1 -1
- package/build-module/custom-gradient-picker/serializer.js +10 -4
- package/build-module/custom-gradient-picker/serializer.js.map +1 -1
- package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
- package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
- package/build-module/custom-gradient-picker/types.js +2 -0
- package/build-module/custom-gradient-picker/utils.js +17 -12
- package/build-module/custom-gradient-picker/utils.js.map +1 -1
- package/build-module/drop-zone/index.js +8 -8
- package/build-module/drop-zone/index.js.map +1 -1
- package/build-module/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
- package/build-module/duotone-picker/color-list-picker/index.js.map +1 -0
- package/build-module/duotone-picker/color-list-picker/types.js +2 -0
- package/build-module/duotone-picker/color-list-picker/types.js.map +1 -0
- package/build-module/duotone-picker/custom-duotone-bar.js.map +1 -1
- package/build-module/duotone-picker/duotone-picker.js +38 -2
- package/build-module/duotone-picker/duotone-picker.js.map +1 -1
- package/build-module/duotone-picker/duotone-swatch.js.map +1 -1
- package/build-module/duotone-picker/index.js.map +1 -1
- package/build-module/duotone-picker/types.js +2 -0
- package/build-module/duotone-picker/types.js.map +1 -0
- package/build-module/duotone-picker/utils.js +17 -11
- package/build-module/duotone-picker/utils.js.map +1 -1
- package/build-module/form-token-field/index.js +9 -4
- package/build-module/form-token-field/index.js.map +1 -1
- package/build-module/gradient-picker/index.js +61 -10
- package/build-module/gradient-picker/index.js.map +1 -1
- package/build-module/gradient-picker/types.js +2 -0
- package/build-module/gradient-picker/types.js.map +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/mobile/keyboard-aware-flat-list/index.android.js +0 -4
- package/build-module/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
- package/build-module/mobile/keyboard-aware-flat-list/index.ios.js +97 -54
- package/build-module/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
- package/build-module/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +73 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js.map +1 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +76 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +1 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +33 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js.map +1 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +40 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js.map +1 -0
- package/build-module/navigator/navigator-provider/component.js +4 -2
- package/build-module/navigator/navigator-provider/component.js.map +1 -1
- package/build-module/navigator/navigator-screen/component.js +4 -3
- package/build-module/navigator/navigator-screen/component.js.map +1 -1
- package/build-module/palette-edit/index.js +1 -2
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/query-controls/author-select.js +2 -1
- package/build-module/query-controls/author-select.js.map +1 -1
- package/build-module/query-controls/category-select.js +3 -1
- package/build-module/query-controls/category-select.js.map +1 -1
- package/build-module/query-controls/index.js +7 -2
- package/build-module/query-controls/index.js.map +1 -1
- package/build-module/resizable-box/resize-tooltip/utils.js.map +1 -1
- package/build-module/sandbox/index.native.js +121 -87
- package/build-module/sandbox/index.native.js.map +1 -1
- package/build-module/tab-panel/index.js +2 -2
- package/build-module/tab-panel/index.js.map +1 -1
- package/build-module/tools-panel/tools-panel/hook.js +45 -6
- package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
- package/build-module/utils/input/input-control.js +1 -1
- package/build-module/utils/input/input-control.js.map +1 -1
- package/build-style/style-rtl.css +41 -29
- package/build-style/style.css +43 -29
- package/build-types/angle-picker-control/angle-circle.d.ts.map +1 -1
- package/build-types/angle-picker-control/index.d.ts.map +1 -1
- package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +6 -1
- package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts.map +1 -1
- package/build-types/animate/index.d.ts +27 -22
- package/build-types/animate/index.d.ts.map +1 -1
- package/build-types/animate/stories/index.d.ts +18 -0
- package/build-types/animate/stories/index.d.ts.map +1 -0
- package/build-types/animate/types.d.ts +30 -0
- package/build-types/animate/types.d.ts.map +1 -0
- package/build-types/border-box-control/border-box-control/hook.d.ts +2 -2
- package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +2 -2
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +2 -2
- package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts +2 -2
- package/build-types/border-control/border-control/hook.d.ts +2 -2
- package/build-types/border-control/border-control-dropdown/hook.d.ts +2 -2
- package/build-types/border-control/border-control-style-picker/hook.d.ts +2 -2
- package/build-types/box-control/styles/box-control-styles.d.ts +5 -5
- package/build-types/button/deprecated.d.ts +2 -2
- package/build-types/card/card/hook.d.ts +2 -2
- package/build-types/card/card-body/hook.d.ts +2 -2
- package/build-types/card/card-divider/hook.d.ts +2 -2
- package/build-types/card/card-footer/hook.d.ts +2 -2
- package/build-types/card/card-header/hook.d.ts +2 -2
- package/build-types/card/card-media/hook.d.ts +2 -2
- package/build-types/color-palette/styles.d.ts +1 -1
- package/build-types/color-picker/color-input.d.ts +1 -11
- package/build-types/color-picker/color-input.d.ts.map +1 -1
- package/build-types/color-picker/component.d.ts +8 -9
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/hex-input.d.ts +1 -10
- package/build-types/color-picker/hex-input.d.ts.map +1 -1
- package/build-types/color-picker/hsl-input.d.ts +1 -10
- package/build-types/color-picker/hsl-input.d.ts.map +1 -1
- package/build-types/color-picker/input-with-slider.d.ts +1 -9
- package/build-types/color-picker/input-with-slider.d.ts.map +1 -1
- package/build-types/color-picker/legacy-adapter.d.ts +1 -3
- package/build-types/color-picker/legacy-adapter.d.ts.map +1 -1
- package/build-types/color-picker/picker.d.ts +4 -7
- package/build-types/color-picker/picker.d.ts.map +1 -1
- package/build-types/color-picker/rgb-input.d.ts +1 -10
- package/build-types/color-picker/rgb-input.d.ts.map +1 -1
- package/build-types/color-picker/stories/index.d.ts +19 -0
- package/build-types/color-picker/stories/index.d.ts.map +1 -0
- package/build-types/color-picker/styles.d.ts +5 -5
- package/build-types/color-picker/test/index.d.ts +2 -0
- package/build-types/color-picker/test/index.d.ts.map +1 -0
- package/build-types/color-picker/types.d.ts +105 -1
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/color-picker/use-deprecated-props.d.ts +1 -44
- package/build-types/color-picker/use-deprecated-props.d.ts.map +1 -1
- package/build-types/combobox-control/styles.d.ts +1 -1
- package/build-types/custom-gradient-picker/constants.d.ts +8 -8
- package/build-types/custom-gradient-picker/constants.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts +7 -7
- package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts +5 -22
- package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/gradient-bar/index.d.ts +3 -9
- package/build-types/custom-gradient-picker/gradient-bar/index.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts +2 -0
- package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts.map +1 -0
- package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts +44 -92
- package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/index.d.ts +27 -6
- package/build-types/custom-gradient-picker/index.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/serializer.d.ts +9 -16
- package/build-types/custom-gradient-picker/serializer.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/stories/index.d.ts +12 -0
- package/build-types/custom-gradient-picker/stories/index.d.ts.map +1 -0
- package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts +3 -2
- package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/test/serializer.d.ts +2 -0
- package/build-types/custom-gradient-picker/test/serializer.d.ts.map +1 -0
- package/build-types/custom-gradient-picker/types.d.ts +118 -0
- package/build-types/custom-gradient-picker/types.d.ts.map +1 -0
- package/build-types/custom-gradient-picker/utils.d.ts +12 -4
- package/build-types/custom-gradient-picker/utils.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts +2 -2
- package/build-types/date-time/date-time/styles.d.ts +1 -1
- package/build-types/date-time/time/styles.d.ts +8 -8
- package/build-types/drop-zone/index.d.ts.map +1 -1
- package/build-types/duotone-picker/color-list-picker/index.d.ts.map +1 -0
- package/build-types/{color-list-picker → duotone-picker/color-list-picker}/types.d.ts +2 -2
- package/build-types/duotone-picker/color-list-picker/types.d.ts.map +1 -0
- package/build-types/duotone-picker/custom-duotone-bar.d.ts +6 -0
- package/build-types/duotone-picker/custom-duotone-bar.d.ts.map +1 -0
- package/build-types/duotone-picker/duotone-picker.d.ts +38 -0
- package/build-types/duotone-picker/duotone-picker.d.ts.map +1 -0
- package/build-types/duotone-picker/duotone-swatch.d.ts +5 -0
- package/build-types/duotone-picker/duotone-swatch.d.ts.map +1 -0
- package/build-types/duotone-picker/index.d.ts +3 -0
- package/build-types/duotone-picker/index.d.ts.map +1 -0
- package/build-types/duotone-picker/stories/duotone-picker.d.ts +12 -0
- package/build-types/duotone-picker/stories/duotone-picker.d.ts.map +1 -0
- package/build-types/duotone-picker/stories/duotone-swatch.d.ts +14 -0
- package/build-types/duotone-picker/stories/duotone-swatch.d.ts.map +1 -0
- package/build-types/duotone-picker/types.d.ts +60 -0
- package/build-types/duotone-picker/types.d.ts.map +1 -0
- package/build-types/duotone-picker/utils.d.ts +52 -0
- package/build-types/duotone-picker/utils.d.ts.map +1 -0
- package/build-types/elevation/hook.d.ts +2 -2
- package/build-types/external-link/styles/external-link-styles.d.ts +1 -1
- package/build-types/flex/flex/hook.d.ts +2 -2
- package/build-types/flex/flex-block/hook.d.ts +2 -2
- package/build-types/flex/flex-item/hook.d.ts +2 -2
- package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +2 -2
- package/build-types/form-token-field/index.d.ts.map +1 -1
- package/build-types/form-token-field/styles.d.ts +1 -1
- package/build-types/form-token-field/types.d.ts +6 -0
- package/build-types/form-token-field/types.d.ts.map +1 -1
- package/build-types/gradient-picker/index.d.ts +49 -11
- package/build-types/gradient-picker/index.d.ts.map +1 -1
- package/build-types/gradient-picker/stories/index.d.ts +14 -0
- package/build-types/gradient-picker/stories/index.d.ts.map +1 -0
- package/build-types/gradient-picker/types.d.ts +87 -0
- package/build-types/gradient-picker/types.d.ts.map +1 -0
- package/build-types/grid/hook.d.ts +2 -2
- package/build-types/h-stack/hook.d.ts +2 -2
- package/build-types/heading/hook.d.ts +2 -2
- package/build-types/index.d.ts +128 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/input-control/styles/input-control-styles.d.ts +2 -2
- package/build-types/item-group/item/hook.d.ts +2 -2
- package/build-types/item-group/item-group/hook.d.ts +2 -2
- package/build-types/navigation/styles/navigation-styles.d.ts +2 -2
- package/build-types/navigator/navigator-back-button/hook.d.ts +2 -2
- package/build-types/navigator/navigator-button/hook.d.ts +2 -2
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
- package/build-types/navigator/stories/index.d.ts +1 -0
- package/build-types/navigator/stories/index.d.ts.map +1 -1
- package/build-types/navigator/types.d.ts +2 -2
- package/build-types/navigator/types.d.ts.map +1 -1
- package/build-types/number-control/index.d.ts +2 -2
- package/build-types/number-control/stories/index.d.ts +2 -2
- package/build-types/palette-edit/index.d.ts.map +1 -1
- package/build-types/palette-edit/styles.d.ts +3 -3
- package/build-types/popover/index.d.ts +1 -1
- package/build-types/popover/stories/e2e/index.d.ts +1 -1
- package/build-types/private-apis.d.ts +2 -3
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/query-controls/author-select.d.ts.map +1 -1
- package/build-types/query-controls/category-select.d.ts.map +1 -1
- package/build-types/query-controls/index.d.ts.map +1 -1
- package/build-types/range-control/index.d.ts +1 -1
- package/build-types/range-control/styles/range-control-styles.d.ts +2 -2
- package/build-types/resizable-box/index.d.ts +1 -1
- package/build-types/resizable-box/resize-tooltip/index.d.ts +1 -1
- package/build-types/resizable-box/resize-tooltip/utils.d.ts +1 -1
- package/build-types/resizable-box/resize-tooltip/utils.d.ts.map +1 -1
- package/build-types/resizable-box/stories/index.d.ts +2 -2
- package/build-types/scrollable/hook.d.ts +2 -2
- package/build-types/search-control/index.d.ts +1 -1
- package/build-types/search-control/stories/index.d.ts +2 -2
- package/build-types/spacer/hook.d.ts +2 -2
- package/build-types/spinner/index.d.ts +1 -1
- package/build-types/surface/hook.d.ts +2 -2
- package/build-types/tab-panel/index.d.ts.map +1 -1
- package/build-types/text/hook.d.ts +2 -2
- package/build-types/text-control/index.d.ts +1 -1
- package/build-types/toolbar/toolbar-button/index.d.ts +2 -2
- package/build-types/tools-panel/tools-panel/hook.d.ts +2 -2
- package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-header/hook.d.ts +2 -2
- package/build-types/tools-panel/tools-panel-item/hook.d.ts +2 -2
- package/build-types/tools-panel/types.d.ts +1 -0
- package/build-types/tools-panel/types.d.ts.map +1 -1
- package/build-types/truncate/hook.d.ts +2 -2
- package/build-types/ui/control-group/hook.d.ts +2 -2
- package/build-types/ui/control-label/hook.d.ts +2 -2
- package/build-types/ui/form-group/form-group.d.ts +2 -2
- package/build-types/ui/form-group/use-form-group.d.ts +2 -2
- package/build-types/unit-control/index.d.ts +1 -1
- package/build-types/unit-control/styles/unit-control-styles.d.ts +2 -2
- package/build-types/utils/input/input-control.d.ts.map +1 -1
- package/build-types/v-stack/hook.d.ts +2 -2
- package/package.json +20 -19
- package/src/angle-picker-control/angle-circle.tsx +0 -1
- package/src/angle-picker-control/index.tsx +14 -27
- package/src/angle-picker-control/styles/angle-picker-control-styles.tsx +16 -9
- package/src/animate/index.tsx +75 -0
- package/src/animate/stories/index.tsx +102 -0
- package/src/animate/types.ts +32 -0
- package/src/border-box-control/stories/index.tsx +1 -1
- package/src/box-control/axial-input-controls.tsx +1 -1
- package/src/circular-option-picker/style.scss +10 -0
- package/src/color-indicator/style.scss +1 -0
- package/src/color-picker/README.md +2 -2
- package/src/color-picker/color-input.tsx +1 -12
- package/src/color-picker/component.tsx +9 -18
- package/src/color-picker/hex-input.tsx +2 -7
- package/src/color-picker/hsl-input.tsx +2 -7
- package/src/color-picker/input-with-slider.tsx +1 -9
- package/src/color-picker/legacy-adapter.tsx +1 -2
- package/src/color-picker/picker.tsx +5 -6
- package/src/color-picker/rgb-input.tsx +2 -7
- package/src/color-picker/stories/index.tsx +51 -0
- package/src/color-picker/test/{index.js → index.tsx} +36 -18
- package/src/color-picker/types.ts +128 -1
- package/src/color-picker/use-deprecated-props.ts +2 -53
- package/src/combobox-control/stories/index.tsx +1 -1
- package/src/custom-gradient-picker/{constants.js → constants.ts} +2 -2
- package/src/custom-gradient-picker/gradient-bar/{control-points.js → control-points.tsx} +171 -134
- package/src/custom-gradient-picker/gradient-bar/{index.js → index.tsx} +32 -10
- package/src/custom-gradient-picker/gradient-bar/test/{utils.js → utils.ts} +58 -31
- package/src/custom-gradient-picker/gradient-bar/utils.ts +193 -0
- package/src/custom-gradient-picker/{index.js → index.tsx} +63 -22
- package/src/custom-gradient-picker/serializer.ts +78 -0
- package/src/custom-gradient-picker/stories/index.tsx +45 -0
- package/src/custom-gradient-picker/style.scss +25 -4
- package/src/custom-gradient-picker/test/{serializer.js → serializer.ts} +39 -33
- package/src/custom-gradient-picker/types.ts +119 -0
- package/src/custom-gradient-picker/{utils.js → utils.ts} +37 -22
- package/src/custom-select-control/test/index.js +6 -4
- package/src/drop-zone/index.tsx +12 -8
- package/src/drop-zone/style.scss +1 -1
- package/src/{color-list-picker → duotone-picker/color-list-picker}/index.tsx +7 -6
- package/src/{color-list-picker → duotone-picker/color-list-picker}/types.ts +2 -2
- package/src/duotone-picker/{custom-duotone-bar.js → custom-duotone-bar.tsx} +7 -1
- package/src/duotone-picker/{duotone-picker.js → duotone-picker.tsx} +39 -2
- package/src/duotone-picker/{duotone-swatch.js → duotone-swatch.tsx} +2 -1
- package/src/duotone-picker/stories/{duotone-picker.js → duotone-picker.tsx} +15 -8
- package/src/duotone-picker/stories/{duotone-swatch.js → duotone-swatch.tsx} +9 -3
- package/src/duotone-picker/types.ts +61 -0
- package/src/duotone-picker/{utils.js → utils.ts} +29 -14
- package/src/flex/flex-item/README.md +1 -1
- package/src/form-token-field/README.md +1 -0
- package/src/form-token-field/index.tsx +10 -3
- package/src/form-token-field/style.scss +0 -7
- package/src/form-token-field/test/index.tsx +1 -0
- package/src/form-token-field/types.ts +6 -0
- package/src/gradient-picker/README.md +16 -23
- package/src/gradient-picker/{index.js → index.tsx} +70 -16
- package/src/gradient-picker/stories/{index.js → index.tsx} +19 -8
- package/src/gradient-picker/types.ts +89 -0
- package/src/item-group/test/index.js +5 -3
- package/src/mobile/keyboard-aware-flat-list/index.android.js +0 -4
- package/src/mobile/keyboard-aware-flat-list/index.ios.js +118 -67
- package/src/mobile/keyboard-aware-flat-list/test/use-keyboard-offset.native.js +203 -0
- package/src/mobile/keyboard-aware-flat-list/test/use-scroll-to-text-input.native.js +140 -0
- package/src/mobile/keyboard-aware-flat-list/test/use-text-input-caret-position.native.js +82 -0
- package/src/mobile/keyboard-aware-flat-list/test/use-text-input-offset.native.js +147 -0
- package/src/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +87 -0
- package/src/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +105 -0
- package/src/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +36 -0
- package/src/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +54 -0
- package/src/navigator/navigator-provider/component.tsx +2 -0
- package/src/navigator/navigator-screen/component.tsx +5 -2
- package/src/navigator/stories/index.tsx +68 -0
- package/src/navigator/test/index.tsx +52 -0
- package/src/navigator/types.ts +2 -1
- package/src/palette-edit/index.tsx +4 -5
- package/src/query-controls/author-select.tsx +1 -0
- package/src/query-controls/category-select.tsx +1 -0
- package/src/query-controls/index.tsx +4 -2
- package/src/resizable-box/resize-tooltip/utils.ts +1 -1
- package/src/sandbox/index.native.js +139 -112
- package/src/slot-fill/test/slot.js +8 -6
- package/src/style.scss +1 -1
- package/src/tab-panel/index.tsx +7 -2
- package/src/tools-panel/test/index.tsx +86 -0
- package/src/tools-panel/tools-panel/hook.ts +44 -4
- package/src/tools-panel/types.ts +1 -0
- package/src/tooltip/test/index.js +251 -301
- package/src/utils/input/input-control.js +1 -0
- package/tsconfig.json +1 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/build/color-list-picker/index.js.map +0 -1
- package/build-module/color-list-picker/index.js.map +0 -1
- package/build-types/color-list-picker/index.d.ts.map +0 -1
- package/build-types/color-list-picker/types.d.ts.map +0 -1
- package/src/animate/index.js +0 -60
- package/src/animate/stories/index.js +0 -53
- package/src/color-picker/stories/index.js +0 -41
- package/src/custom-gradient-picker/gradient-bar/utils.js +0 -189
- package/src/custom-gradient-picker/serializer.js +0 -48
- package/src/custom-gradient-picker/stories/index.js +0 -33
- /package/build/{color-list-picker → animate}/types.js +0 -0
- /package/build-module/{color-list-picker → animate}/types.js +0 -0
- /package/build-module/{color-list-picker → animate}/types.js.map +0 -0
- /package/{build/color-list-picker → build-module/custom-gradient-picker}/types.js.map +0 -0
- /package/build-types/{color-list-picker → duotone-picker/color-list-picker}/index.d.ts +0 -0
- /package/src/custom-gradient-picker/gradient-bar/{constants.js → constants.ts} +0 -0
- /package/src/custom-gradient-picker/styles/{custom-gradient-picker-styles.js → custom-gradient-picker-styles.tsx} +0 -0
- /package/src/{color-list-picker → duotone-picker/color-list-picker}/style.scss +0 -0
- /package/src/duotone-picker/{index.js → index.ts} +0 -0
- /package/src/{index.js → index.ts} +0 -0
- /package/src/{private-apis.js → private-apis.ts} +0 -0
|
@@ -1,47 +1,27 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Internal dependencies
|
|
5
3
|
*/
|
|
6
4
|
import { MINIMUM_DISTANCE_BETWEEN_POINTS } from './constants';
|
|
7
|
-
/**
|
|
8
|
-
* Control point for the gradient bar.
|
|
9
|
-
*
|
|
10
|
-
* @typedef {Object} ControlPoint
|
|
11
|
-
* @property {string} color Color of the control point.
|
|
12
|
-
* @property {number} position Integer position of the control point as a percentage.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Color as parsed from the gradient by gradient-parser.
|
|
17
|
-
*
|
|
18
|
-
* @typedef {Object} Color
|
|
19
|
-
* @property {string} r Red component.
|
|
20
|
-
* @property {string} g Green component.
|
|
21
|
-
* @property {string} b Green component.
|
|
22
|
-
* @property {string} [a] Optional alpha component.
|
|
23
|
-
*/
|
|
24
5
|
|
|
25
6
|
/**
|
|
26
7
|
* Clamps a number between 0 and 100.
|
|
27
8
|
*
|
|
28
|
-
* @param
|
|
9
|
+
* @param value Value to clamp.
|
|
29
10
|
*
|
|
30
|
-
* @return
|
|
11
|
+
* @return Value clamped between 0 and 100.
|
|
31
12
|
*/
|
|
32
|
-
|
|
33
13
|
export function clampPercent(value) {
|
|
34
14
|
return Math.max(0, Math.min(100, value));
|
|
35
15
|
}
|
|
36
16
|
/**
|
|
37
17
|
* Check if a control point is overlapping with another.
|
|
38
18
|
*
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
19
|
+
* @param value Array of control points.
|
|
20
|
+
* @param initialIndex Index of the position to test.
|
|
21
|
+
* @param newPosition New position of the control point.
|
|
22
|
+
* @param minDistance Distance considered to be overlapping.
|
|
43
23
|
*
|
|
44
|
-
* @return
|
|
24
|
+
* @return True if the point is overlapping.
|
|
45
25
|
*/
|
|
46
26
|
|
|
47
27
|
export function isOverlapping(value, initialIndex, newPosition) {
|
|
@@ -59,11 +39,11 @@ export function isOverlapping(value, initialIndex, newPosition) {
|
|
|
59
39
|
/**
|
|
60
40
|
* Adds a control point from an array and returns the new array.
|
|
61
41
|
*
|
|
62
|
-
* @param
|
|
63
|
-
* @param
|
|
64
|
-
* @param
|
|
42
|
+
* @param points Array of control points.
|
|
43
|
+
* @param position Position to insert the new point.
|
|
44
|
+
* @param color Color to update the control point at index.
|
|
65
45
|
*
|
|
66
|
-
* @return
|
|
46
|
+
* @return New array of control points.
|
|
67
47
|
*/
|
|
68
48
|
|
|
69
49
|
export function addControlPoint(points, position, color) {
|
|
@@ -79,25 +59,25 @@ export function addControlPoint(points, position, color) {
|
|
|
79
59
|
/**
|
|
80
60
|
* Removes a control point from an array and returns the new array.
|
|
81
61
|
*
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
62
|
+
* @param points Array of control points.
|
|
63
|
+
* @param index Index to remove.
|
|
84
64
|
*
|
|
85
|
-
* @return
|
|
65
|
+
* @return New array of control points.
|
|
86
66
|
*/
|
|
87
67
|
|
|
88
68
|
export function removeControlPoint(points, index) {
|
|
89
|
-
return points.filter((
|
|
69
|
+
return points.filter((_point, pointIndex) => {
|
|
90
70
|
return pointIndex !== index;
|
|
91
71
|
});
|
|
92
72
|
}
|
|
93
73
|
/**
|
|
94
74
|
* Updates a control point from an array and returns the new array.
|
|
95
75
|
*
|
|
96
|
-
* @param
|
|
97
|
-
* @param
|
|
98
|
-
* @param
|
|
76
|
+
* @param points Array of control points.
|
|
77
|
+
* @param index Index to update.
|
|
78
|
+
* @param newPoint New control point to replace the index.
|
|
99
79
|
*
|
|
100
|
-
* @return
|
|
80
|
+
* @return New array of control points.
|
|
101
81
|
*/
|
|
102
82
|
|
|
103
83
|
export function updateControlPoint(points, index, newPoint) {
|
|
@@ -108,11 +88,11 @@ export function updateControlPoint(points, index, newPoint) {
|
|
|
108
88
|
/**
|
|
109
89
|
* Updates the position of a control point from an array and returns the new array.
|
|
110
90
|
*
|
|
111
|
-
* @param
|
|
112
|
-
* @param
|
|
113
|
-
* @param
|
|
91
|
+
* @param points Array of control points.
|
|
92
|
+
* @param index Index to update.
|
|
93
|
+
* @param newPosition Position to move the control point at index.
|
|
114
94
|
*
|
|
115
|
-
* @return
|
|
95
|
+
* @return New array of control points.
|
|
116
96
|
*/
|
|
117
97
|
|
|
118
98
|
export function updateControlPointPosition(points, index, newPosition) {
|
|
@@ -128,11 +108,11 @@ export function updateControlPointPosition(points, index, newPosition) {
|
|
|
128
108
|
/**
|
|
129
109
|
* Updates the position of a control point from an array and returns the new array.
|
|
130
110
|
*
|
|
131
|
-
* @param
|
|
132
|
-
* @param
|
|
133
|
-
* @param
|
|
111
|
+
* @param points Array of control points.
|
|
112
|
+
* @param index Index to update.
|
|
113
|
+
* @param newColor Color to update the control point at index.
|
|
134
114
|
*
|
|
135
|
-
* @return
|
|
115
|
+
* @return New array of control points.
|
|
136
116
|
*/
|
|
137
117
|
|
|
138
118
|
export function updateControlPointColor(points, index, newColor) {
|
|
@@ -144,11 +124,11 @@ export function updateControlPointColor(points, index, newColor) {
|
|
|
144
124
|
/**
|
|
145
125
|
* Updates the position of a control point from an array and returns the new array.
|
|
146
126
|
*
|
|
147
|
-
* @param
|
|
148
|
-
* @param
|
|
149
|
-
* @param
|
|
127
|
+
* @param points Array of control points.
|
|
128
|
+
* @param position Position of the color stop.
|
|
129
|
+
* @param newColor Color to update the control point at index.
|
|
150
130
|
*
|
|
151
|
-
* @return
|
|
131
|
+
* @return New array of control points.
|
|
152
132
|
*/
|
|
153
133
|
|
|
154
134
|
export function updateControlPointColorByPosition(points, position, newColor) {
|
|
@@ -158,10 +138,10 @@ export function updateControlPointColorByPosition(points, position, newColor) {
|
|
|
158
138
|
/**
|
|
159
139
|
* Gets the horizontal coordinate when dragging a control point with the mouse.
|
|
160
140
|
*
|
|
161
|
-
* @param
|
|
162
|
-
* @param
|
|
141
|
+
* @param mouseXcoordinate Horizontal coordinate of the mouse position.
|
|
142
|
+
* @param containerElement Container for the gradient picker.
|
|
163
143
|
*
|
|
164
|
-
* @return
|
|
144
|
+
* @return Whole number percentage from the left.
|
|
165
145
|
*/
|
|
166
146
|
|
|
167
147
|
export function getHorizontalRelativeGradientPosition(mouseXCoordinate, containerElement) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/gradient-bar/utils.
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/gradient-bar/utils.ts"],"names":["MINIMUM_DISTANCE_BETWEEN_POINTS","clampPercent","value","Math","max","min","isOverlapping","initialIndex","newPosition","minDistance","initialPosition","position","minPosition","maxPosition","some","index","abs","addControlPoint","points","color","nextIndex","findIndex","point","newPoint","newPoints","slice","splice","removeControlPoint","filter","_point","pointIndex","updateControlPoint","newValue","updateControlPointPosition","updateControlPointColor","newColor","updateControlPointColorByPosition","getHorizontalRelativeGradientPosition","mouseXCoordinate","containerElement","x","width","getBoundingClientRect","absolutePositionValue","round"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,+BAAT,QAAgD,aAAhD;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAT,CAAuBC,KAAvB,EAAuC;AAC7C,SAAOC,IAAI,CAACC,GAAL,CAAU,CAAV,EAAaD,IAAI,CAACE,GAAL,CAAU,GAAV,EAAeH,KAAf,CAAb,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,aAAT,CACNJ,KADM,EAENK,YAFM,EAGNC,WAHM,EAKL;AAAA,MADDC,WACC,uEADqBT,+BACrB;AACD,QAAMU,eAAe,GAAGR,KAAK,CAAEK,YAAF,CAAL,CAAsBI,QAA9C;AACA,QAAMC,WAAW,GAAGT,IAAI,CAACE,GAAL,CAAUK,eAAV,EAA2BF,WAA3B,CAApB;AACA,QAAMK,WAAW,GAAGV,IAAI,CAACC,GAAL,CAAUM,eAAV,EAA2BF,WAA3B,CAApB;AAEA,SAAON,KAAK,CAACY,IAAN,CAAY,OAAgBC,KAAhB,KAA2B;AAAA,QAAzB;AAAEJ,MAAAA;AAAF,KAAyB;AAC7C,WACCI,KAAK,KAAKR,YAAV,KACEJ,IAAI,CAACa,GAAL,CAAUL,QAAQ,GAAGH,WAArB,IAAqCC,WAArC,IACCG,WAAW,GAAGD,QAAd,IAA0BA,QAAQ,GAAGE,WAFxC,CADD;AAKA,GANM,CAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,eAAT,CACNC,MADM,EAENP,QAFM,EAGNQ,KAHM,EAIL;AACD,QAAMC,SAAS,GAAGF,MAAM,CAACG,SAAP,CACfC,KAAF,IAAaA,KAAK,CAACX,QAAN,GAAiBA,QADb,C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AAMZ,QAAQ,GAAG,EAChB,GAAGL,MAAM,CAAEH,KAAF,CADO;AAEhBI,IAAAA,KAAK,EAAEgB;AAFS,GAAjB;AAIA,SAAOJ,kBAAkB,CAAEb,MAAF,EAAUH,KAAV,EAAiBQ,QAAjB,CAAzB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASa,iCAAT,CACNlB,MADM,EAENP,QAFM,EAGNwB,QAHM,EAIL;AACD,QAAMpB,KAAK,GAAGG,MAAM,CAACG,SAAP,CAAoBC,KAAF,IAAaA,KAAK,CAACX,QAAN,KAAmBA,QAAlD,CAAd;AACA,SAAOuB,uBAAuB,CAAEhB,MAAF,EAAUH,KAAV,EAAiBoB,QAAjB,CAA9B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAO,SAASE,qCAAT,CACNC,gBADM,EAENC,gBAFM,EAGL;AACD,MAAK,CAAEA,gBAAP,EAA0B;AACzB;AACA;;AACD,QAAM;AAAEC,IAAAA,CAAF;AAAKC,IAAAA;AAAL,MAAeF,gBAAgB,CAACG,qBAAjB,EAArB;AACA,QAAMC,qBAAqB,GAAGL,gBAAgB,GAAGE,CAAjD;AACA,SAAOrC,IAAI,CAACyC,KAAL,CACN3C,YAAY,CAAI0C,qBAAqB,GAAG,GAA1B,GAAkCF,KAApC,CADN,CAAP;AAGA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { MINIMUM_DISTANCE_BETWEEN_POINTS } from './constants';\nimport type { ControlPoint } from '../types';\n\n/**\n * Clamps a number between 0 and 100.\n *\n * @param value Value to clamp.\n *\n * @return Value clamped between 0 and 100.\n */\nexport function clampPercent( value: number ) {\n\treturn Math.max( 0, Math.min( 100, value ) );\n}\n\n/**\n * Check if a control point is overlapping with another.\n *\n * @param value Array of control points.\n * @param initialIndex Index of the position to test.\n * @param newPosition New position of the control point.\n * @param minDistance Distance considered to be overlapping.\n *\n * @return True if the point is overlapping.\n */\nexport function isOverlapping(\n\tvalue: ControlPoint[],\n\tinitialIndex: number,\n\tnewPosition: number,\n\tminDistance: number = MINIMUM_DISTANCE_BETWEEN_POINTS\n) {\n\tconst initialPosition = value[ initialIndex ].position;\n\tconst minPosition = Math.min( initialPosition, newPosition );\n\tconst maxPosition = Math.max( initialPosition, newPosition );\n\n\treturn value.some( ( { position }, index ) => {\n\t\treturn (\n\t\t\tindex !== initialIndex &&\n\t\t\t( Math.abs( position - newPosition ) < minDistance ||\n\t\t\t\t( minPosition < position && position < maxPosition ) )\n\t\t);\n\t} );\n}\n\n/**\n * Adds a control point from an array and returns the new array.\n *\n * @param points Array of control points.\n * @param position Position to insert the new point.\n * @param color Color to update the control point at index.\n *\n * @return New array of control points.\n */\nexport function addControlPoint(\n\tpoints: ControlPoint[],\n\tposition: number,\n\tcolor: ControlPoint[ 'color' ]\n) {\n\tconst nextIndex = points.findIndex(\n\t\t( point ) => point.position > position\n\t);\n\tconst newPoint = { color, position };\n\tconst newPoints = points.slice();\n\tnewPoints.splice( nextIndex - 1, 0, newPoint );\n\treturn newPoints;\n}\n\n/**\n * Removes a control point from an array and returns the new array.\n *\n * @param points Array of control points.\n * @param index Index to remove.\n *\n * @return New array of control points.\n */\nexport function removeControlPoint( points: ControlPoint[], index: number ) {\n\treturn points.filter( ( _point, pointIndex ) => {\n\t\treturn pointIndex !== index;\n\t} );\n}\n/**\n * Updates a control point from an array and returns the new array.\n *\n * @param points Array of control points.\n * @param index Index to update.\n * @param newPoint New control point to replace the index.\n *\n * @return New array of control points.\n */\nexport function updateControlPoint(\n\tpoints: ControlPoint[],\n\tindex: number,\n\tnewPoint: ControlPoint\n) {\n\tconst newValue = points.slice();\n\tnewValue[ index ] = newPoint;\n\treturn newValue;\n}\n\n/**\n * Updates the position of a control point from an array and returns the new array.\n *\n * @param points Array of control points.\n * @param index Index to update.\n * @param newPosition Position to move the control point at index.\n *\n * @return New array of control points.\n */\nexport function updateControlPointPosition(\n\tpoints: ControlPoint[],\n\tindex: number,\n\tnewPosition: ControlPoint[ 'position' ]\n) {\n\tif ( isOverlapping( points, index, newPosition ) ) {\n\t\treturn points;\n\t}\n\tconst newPoint = {\n\t\t...points[ index ],\n\t\tposition: newPosition,\n\t};\n\treturn updateControlPoint( points, index, newPoint );\n}\n\n/**\n * Updates the position of a control point from an array and returns the new array.\n *\n * @param points Array of control points.\n * @param index Index to update.\n * @param newColor Color to update the control point at index.\n *\n * @return New array of control points.\n */\nexport function updateControlPointColor(\n\tpoints: ControlPoint[],\n\tindex: number,\n\tnewColor: ControlPoint[ 'color' ]\n) {\n\tconst newPoint = {\n\t\t...points[ index ],\n\t\tcolor: newColor,\n\t};\n\treturn updateControlPoint( points, index, newPoint );\n}\n\n/**\n * Updates the position of a control point from an array and returns the new array.\n *\n * @param points Array of control points.\n * @param position Position of the color stop.\n * @param newColor Color to update the control point at index.\n *\n * @return New array of control points.\n */\nexport function updateControlPointColorByPosition(\n\tpoints: ControlPoint[],\n\tposition: ControlPoint[ 'position' ],\n\tnewColor: ControlPoint[ 'color' ]\n) {\n\tconst index = points.findIndex( ( point ) => point.position === position );\n\treturn updateControlPointColor( points, index, newColor );\n}\n\n/**\n * Gets the horizontal coordinate when dragging a control point with the mouse.\n *\n * @param mouseXcoordinate Horizontal coordinate of the mouse position.\n * @param containerElement Container for the gradient picker.\n *\n * @return Whole number percentage from the left.\n */\nexport function getHorizontalRelativeGradientPosition(\n\tmouseXcoordinate: number,\n\tcontainerElement: HTMLDivElement\n): number;\nexport function getHorizontalRelativeGradientPosition(\n\tmouseXcoordinate: number,\n\tcontainerElement: null\n): undefined;\nexport function getHorizontalRelativeGradientPosition(\n\tmouseXCoordinate: number,\n\tcontainerElement: HTMLDivElement | null\n) {\n\tif ( ! containerElement ) {\n\t\treturn;\n\t}\n\tconst { x, width } = containerElement.getBoundingClientRect();\n\tconst absolutePositionValue = mouseXCoordinate - x;\n\treturn Math.round(\n\t\tclampPercent( ( absolutePositionValue * 100 ) / width )\n\t);\n}\n"]}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
// @ts-nocheck
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* External dependencies
|
|
6
5
|
*/
|
|
7
6
|
import classnames from 'classnames';
|
|
7
|
+
|
|
8
8
|
/**
|
|
9
9
|
* WordPress dependencies
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
11
|
import deprecated from '@wordpress/deprecated';
|
|
13
12
|
import { __ } from '@wordpress/i18n';
|
|
14
13
|
/**
|
|
@@ -22,7 +21,7 @@ import SelectControl from '../select-control';
|
|
|
22
21
|
import { VStack } from '../v-stack';
|
|
23
22
|
import { getGradientAstWithDefault, getLinearGradientRepresentation, getGradientAstWithControlPoints, getStopCssColor } from './utils';
|
|
24
23
|
import { serializeGradient } from './serializer';
|
|
25
|
-
import { DEFAULT_LINEAR_GRADIENT_ANGLE, HORIZONTAL_GRADIENT_ORIENTATION, GRADIENT_OPTIONS
|
|
24
|
+
import { DEFAULT_LINEAR_GRADIENT_ANGLE, HORIZONTAL_GRADIENT_ORIENTATION, GRADIENT_OPTIONS } from './constants';
|
|
26
25
|
import { AccessoryWrapper, SelectWrapper } from './styles/custom-gradient-picker-styles';
|
|
27
26
|
|
|
28
27
|
const GradientAnglePicker = _ref => {
|
|
@@ -39,7 +38,7 @@ const GradientAnglePicker = _ref => {
|
|
|
39
38
|
onChange(serializeGradient({ ...gradientAST,
|
|
40
39
|
orientation: {
|
|
41
40
|
type: 'angular',
|
|
42
|
-
value: newAngle
|
|
41
|
+
value: `${newAngle}`
|
|
43
42
|
}
|
|
44
43
|
}));
|
|
45
44
|
};
|
|
@@ -63,9 +62,7 @@ const GradientTypePicker = _ref2 => {
|
|
|
63
62
|
|
|
64
63
|
const onSetLinearGradient = () => {
|
|
65
64
|
onChange(serializeGradient({ ...gradientAST,
|
|
66
|
-
|
|
67
|
-
orientation: HORIZONTAL_GRADIENT_ORIENTATION
|
|
68
|
-
}),
|
|
65
|
+
orientation: gradientAST.orientation ? undefined : HORIZONTAL_GRADIENT_ORIENTATION,
|
|
69
66
|
type: 'linear-gradient'
|
|
70
67
|
}));
|
|
71
68
|
};
|
|
@@ -98,30 +95,59 @@ const GradientTypePicker = _ref2 => {
|
|
|
98
95
|
onChange: handleOnChange,
|
|
99
96
|
options: GRADIENT_OPTIONS,
|
|
100
97
|
size: "__unstable-large",
|
|
101
|
-
value: hasGradient
|
|
98
|
+
value: hasGradient ? type : undefined
|
|
102
99
|
});
|
|
103
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* CustomGradientPicker is a React component that renders a UI for specifying
|
|
103
|
+
* linear or radial gradients. Radial gradients are displayed in the picker as
|
|
104
|
+
* a slice of the gradient from the center to the outside.
|
|
105
|
+
*
|
|
106
|
+
* ```jsx
|
|
107
|
+
* import { CustomGradientPicker } from '@wordpress/components';
|
|
108
|
+
* import { useState } from '@wordpress/element';
|
|
109
|
+
*
|
|
110
|
+
* const MyCustomGradientPicker = () => {
|
|
111
|
+
* const [ gradient, setGradient ] = useState();
|
|
112
|
+
*
|
|
113
|
+
* return (
|
|
114
|
+
* <CustomGradientPicker
|
|
115
|
+
* value={ gradient }
|
|
116
|
+
* onChange={ setGradient }
|
|
117
|
+
* />
|
|
118
|
+
* );
|
|
119
|
+
* };
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
104
122
|
|
|
105
|
-
|
|
123
|
+
|
|
124
|
+
export function CustomGradientPicker(_ref3) {
|
|
106
125
|
let {
|
|
107
126
|
/** Start opting into the new margin-free styles that will become the default in a future version. */
|
|
108
127
|
__nextHasNoMargin = false,
|
|
109
128
|
value,
|
|
110
129
|
onChange,
|
|
111
|
-
__experimentalIsRenderedInSidebar
|
|
130
|
+
__experimentalIsRenderedInSidebar = false
|
|
112
131
|
} = _ref3;
|
|
113
|
-
const
|
|
132
|
+
const {
|
|
133
|
+
gradientAST,
|
|
134
|
+
hasGradient
|
|
135
|
+
} = getGradientAstWithDefault(value); // On radial gradients the bar should display a linear gradient.
|
|
114
136
|
// On radial gradients the bar represents a slice of the gradient from the center until the outside.
|
|
115
137
|
// On liner gradients the bar represents the color stops from left to right independently of the angle.
|
|
116
138
|
|
|
117
|
-
const background = getLinearGradientRepresentation(gradientAST);
|
|
118
|
-
const hasGradient = gradientAST.value !== DEFAULT_GRADIENT; // Control points color option may be hex from presets, custom colors will be rgb.
|
|
139
|
+
const background = getLinearGradientRepresentation(gradientAST); // Control points color option may be hex from presets, custom colors will be rgb.
|
|
119
140
|
// The position should always be a percentage.
|
|
120
141
|
|
|
121
|
-
const controlPoints = gradientAST.colorStops.map(colorStop =>
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
142
|
+
const controlPoints = gradientAST.colorStops.map(colorStop => {
|
|
143
|
+
return {
|
|
144
|
+
color: getStopCssColor(colorStop),
|
|
145
|
+
// Although it's already been checked by `hasUnsupportedLength` in `getGradientAstWithDefault`,
|
|
146
|
+
// TypeScript doesn't know that `colorStop.length` is not undefined here.
|
|
147
|
+
// @ts-expect-error
|
|
148
|
+
position: parseInt(colorStop.length.value)
|
|
149
|
+
};
|
|
150
|
+
});
|
|
125
151
|
|
|
126
152
|
if (!__nextHasNoMargin) {
|
|
127
153
|
deprecated('Outer margin styles for wp.components.CustomGradientPicker', {
|
|
@@ -157,4 +183,5 @@ export default function CustomGradientPicker(_ref3) {
|
|
|
157
183
|
onChange: onChange
|
|
158
184
|
}))));
|
|
159
185
|
}
|
|
186
|
+
export default CustomGradientPicker;
|
|
160
187
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/index.js"],"names":["classnames","deprecated","__","AnglePickerControl","CustomGradientBar","Flex","SelectControl","VStack","getGradientAstWithDefault","getLinearGradientRepresentation","getGradientAstWithControlPoints","getStopCssColor","serializeGradient","DEFAULT_LINEAR_GRADIENT_ANGLE","HORIZONTAL_GRADIENT_ORIENTATION","GRADIENT_OPTIONS","DEFAULT_GRADIENT","AccessoryWrapper","SelectWrapper","GradientAnglePicker","gradientAST","hasGradient","onChange","angle","orientation","value","onAngleChange","newAngle","type","GradientTypePicker","onSetLinearGradient","onSetRadialGradient","restGradientAST","handleOnChange","next","CustomGradientPicker","__nextHasNoMargin","__experimentalIsRenderedInSidebar","background","controlPoints","colorStops","map","colorStop","color","position","parseInt","length","since","version","hint","newControlPoints"],"mappings":";AAAA;;AAEA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,kBAAP,MAA+B,yBAA/B;AACA,OAAOC,iBAAP,MAA8B,gBAA9B;AACA,SAASC,IAAT,QAAqB,SAArB;AACA,OAAOC,aAAP,MAA0B,mBAA1B;AACA,SAASC,MAAT,QAAuB,YAAvB;AACA,SACCC,yBADD,EAECC,+BAFD,EAGCC,+BAHD,EAICC,eAJD,QAKO,SALP;AAMA,SAASC,iBAAT,QAAkC,cAAlC;AACA,SACCC,6BADD,EAECC,+BAFD,EAGCC,gBAHD,EAICC,gBAJD,QAKO,aALP;AAMA,SACCC,gBADD,EAECC,aAFD,QAGO,wCAHP;;AAKA,MAAMC,mBAAmB,GAAG,QAA8C;AAAA;;AAAA,MAA5C;AAAEC,IAAAA,WAAF;AAAeC,IAAAA,WAAf;AAA4BC,IAAAA;AAA5B,GAA4C;AACzE,QAAMC,KAAK,4BACVH,WADU,aACVA,WADU,iDACVA,WAAW,CAAEI,WADH,2DACV,uBAA0BC,KADhB,yEACyBZ,6BADpC;;AAEA,QAAMa,aAAa,GAAKC,QAAF,IAAgB;AACrCL,IAAAA,QAAQ,CACPV,iBAAiB,CAAE,EAClB,GAAGQ,WADe;AAElBI,MAAAA,WAAW,EAAE;AACZI,QAAAA,IAAI,EAAE,SADM;AAEZH,QAAAA,KAAK,EAAEE;AAFK;AAFK,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,EAAKW,gBAAF,IAAwB;AAClC5B,MAAAA,QAAQ,CACPV,iBAAiB,CAChBF,+BAA+B,CAC9BU,WAD8B,EAE9B8B,gBAF8B,CADf,CADV,CAAR;AAQA;AAhBF,IAND,EAwBC,cAAC,IAAD;AACC,IAAA,GAAG,EAAG,CADP;AAEC,IAAA,SAAS,EAAC;AAFX,KAIC,cAAC,aAAD,QACC,cAAC,kBAAD;AACC,IAAA,WAAW,EAAG9B,WADf;AAEC,IAAA,WAAW,EAAGC,WAFf;AAGC,IAAA,QAAQ,EAAGC;AAHZ,IADD,CAJD,EAWC,cAAC,gBAAD,QACGF,WAAW,CAACQ,IAAZ,KAAqB,iBAArB,IACD,cAAC,mBAAD;AACC,IAAA,WAAW,EAAGR,WADf;AAEC,IAAA,WAAW,EAAGC,WAFf;AAGC,IAAA,QAAQ,EAAGC;AAHZ,IAFF,CAXD,CAxBD,CADD;AAgDA","sourcesContent":["// @ts-nocheck\n\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport AnglePickerControl from '../angle-picker-control';\nimport CustomGradientBar from './gradient-bar';\nimport { Flex } from '../flex';\nimport SelectControl from '../select-control';\nimport { VStack } from '../v-stack';\nimport {\n\tgetGradientAstWithDefault,\n\tgetLinearGradientRepresentation,\n\tgetGradientAstWithControlPoints,\n\tgetStopCssColor,\n} from './utils';\nimport { serializeGradient } from './serializer';\nimport {\n\tDEFAULT_LINEAR_GRADIENT_ANGLE,\n\tHORIZONTAL_GRADIENT_ORIENTATION,\n\tGRADIENT_OPTIONS,\n\tDEFAULT_GRADIENT,\n} from './constants';\nimport {\n\tAccessoryWrapper,\n\tSelectWrapper,\n} from './styles/custom-gradient-picker-styles';\n\nconst GradientAnglePicker = ( { gradientAST, hasGradient, onChange } ) => {\n\tconst angle =\n\t\tgradientAST?.orientation?.value ?? DEFAULT_LINEAR_GRADIENT_ANGLE;\n\tconst onAngleChange = ( newAngle ) => {\n\t\tonChange(\n\t\t\tserializeGradient( {\n\t\t\t\t...gradientAST,\n\t\t\t\torientation: {\n\t\t\t\t\ttype: 'angular',\n\t\t\t\t\tvalue: newAngle,\n\t\t\t\t},\n\t\t\t} )\n\t\t);\n\t};\n\treturn (\n\t\t<AnglePickerControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tonChange={ onAngleChange }\n\t\t\tvalue={ hasGradient ? angle : '' }\n\t\t/>\n\t);\n};\n\nconst GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {\n\tconst { type } = gradientAST;\n\tconst onSetLinearGradient = () => {\n\t\tonChange(\n\t\t\tserializeGradient( {\n\t\t\t\t...gradientAST,\n\t\t\t\t...( gradientAST.orientation\n\t\t\t\t\t? {}\n\t\t\t\t\t: { orientation: HORIZONTAL_GRADIENT_ORIENTATION } ),\n\t\t\t\ttype: 'linear-gradient',\n\t\t\t} )\n\t\t);\n\t};\n\n\tconst onSetRadialGradient = () => {\n\t\tconst { orientation, ...restGradientAST } = gradientAST;\n\t\tonChange(\n\t\t\tserializeGradient( {\n\t\t\t\t...restGradientAST,\n\t\t\t\ttype: 'radial-gradient',\n\t\t\t} )\n\t\t);\n\t};\n\n\tconst handleOnChange = ( next ) => {\n\t\tif ( next === 'linear-gradient' ) {\n\t\t\tonSetLinearGradient();\n\t\t}\n\t\tif ( next === 'radial-gradient' ) {\n\t\t\tonSetRadialGradient();\n\t\t}\n\t};\n\n\treturn (\n\t\t<SelectControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tclassName=\"components-custom-gradient-picker__type-picker\"\n\t\t\tlabel={ __( 'Type' ) }\n\t\t\tlabelPosition=\"top\"\n\t\t\tonChange={ handleOnChange }\n\t\t\toptions={ GRADIENT_OPTIONS }\n\t\t\tsize=\"__unstable-large\"\n\t\t\tvalue={ hasGradient && type }\n\t\t/>\n\t);\n};\n\nexport default function CustomGradientPicker( {\n\t/** Start opting into the new margin-free styles that will become the default in a future version. */\n\t__nextHasNoMargin = false,\n\tvalue,\n\tonChange,\n\t__experimentalIsRenderedInSidebar,\n} ) {\n\tconst gradientAST = getGradientAstWithDefault( value );\n\t// On radial gradients the bar should display a linear gradient.\n\t// On radial gradients the bar represents a slice of the gradient from the center until the outside.\n\t// On liner gradients the bar represents the color stops from left to right independently of the angle.\n\tconst background = getLinearGradientRepresentation( gradientAST );\n\tconst hasGradient = gradientAST.value !== DEFAULT_GRADIENT;\n\t// Control points color option may be hex from presets, custom colors will be rgb.\n\t// The position should always be a percentage.\n\tconst controlPoints = gradientAST.colorStops.map( ( colorStop ) => ( {\n\t\tcolor: getStopCssColor( colorStop ),\n\t\tposition: parseInt( colorStop.length.value ),\n\t} ) );\n\n\tif ( ! __nextHasNoMargin ) {\n\t\tdeprecated(\n\t\t\t'Outer margin styles for wp.components.CustomGradientPicker',\n\t\t\t{\n\t\t\t\tsince: '6.1',\n\t\t\t\tversion: '6.4',\n\t\t\t\thint: 'Set the `__nextHasNoMargin` prop to true to start opting into the new styles, which will become the default in a future version',\n\t\t\t}\n\t\t);\n\t}\n\n\treturn (\n\t\t<VStack\n\t\t\tspacing={ 4 }\n\t\t\tclassName={ classnames( 'components-custom-gradient-picker', {\n\t\t\t\t'is-next-has-no-margin': __nextHasNoMargin,\n\t\t\t} ) }\n\t\t>\n\t\t\t<CustomGradientBar\n\t\t\t\t__experimentalIsRenderedInSidebar={\n\t\t\t\t\t__experimentalIsRenderedInSidebar\n\t\t\t\t}\n\t\t\t\tbackground={ background }\n\t\t\t\thasGradient={ hasGradient }\n\t\t\t\tvalue={ controlPoints }\n\t\t\t\tonChange={ ( newControlPoints ) => {\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tserializeGradient(\n\t\t\t\t\t\t\tgetGradientAstWithControlPoints(\n\t\t\t\t\t\t\t\tgradientAST,\n\t\t\t\t\t\t\t\tnewControlPoints\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t<Flex\n\t\t\t\tgap={ 3 }\n\t\t\t\tclassName=\"components-custom-gradient-picker__ui-line\"\n\t\t\t>\n\t\t\t\t<SelectWrapper>\n\t\t\t\t\t<GradientTypePicker\n\t\t\t\t\t\tgradientAST={ gradientAST }\n\t\t\t\t\t\thasGradient={ hasGradient }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t/>\n\t\t\t\t</SelectWrapper>\n\t\t\t\t<AccessoryWrapper>\n\t\t\t\t\t{ gradientAST.type === 'linear-gradient' && (\n\t\t\t\t\t\t<GradientAnglePicker\n\t\t\t\t\t\t\tgradientAST={ gradientAST }\n\t\t\t\t\t\t\thasGradient={ hasGradient }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</AccessoryWrapper>\n\t\t\t</Flex>\n\t\t</VStack>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/index.tsx"],"names":["classnames","deprecated","__","AnglePickerControl","CustomGradientBar","Flex","SelectControl","VStack","getGradientAstWithDefault","getLinearGradientRepresentation","getGradientAstWithControlPoints","getStopCssColor","serializeGradient","DEFAULT_LINEAR_GRADIENT_ANGLE","HORIZONTAL_GRADIENT_ORIENTATION","GRADIENT_OPTIONS","AccessoryWrapper","SelectWrapper","GradientAnglePicker","gradientAST","hasGradient","onChange","angle","orientation","value","onAngleChange","newAngle","type","GradientTypePicker","onSetLinearGradient","undefined","onSetRadialGradient","restGradientAST","handleOnChange","next","CustomGradientPicker","__nextHasNoMargin","__experimentalIsRenderedInSidebar","background","controlPoints","colorStops","map","colorStop","color","position","parseInt","length","since","version","hint","newControlPoints"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;;AAGA;AACA;AACA;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,EAAT,QAAmB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WADf;AAEC,IAAA,WAAW,EAAGC,WAFf;AAGC,IAAA,QAAQ,EAAGC;AAHZ,IADD,CAJD,EAWC,cAAC,gBAAD,QACGF,WAAW,CAACQ,IAAZ,KAAqB,iBAArB,IACD,cAAC,mBAAD;AACC,IAAA,WAAW,EAAGR,WADf;AAEC,IAAA,WAAW,EAAGC,WAFf;AAGC,IAAA,QAAQ,EAAGC;AAHZ,IAFF,CAXD,CAxBD,CADD;AAgDA;AAED,eAAec,oBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport type gradientParser from 'gradient-parser';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport AnglePickerControl from '../angle-picker-control';\nimport CustomGradientBar from './gradient-bar';\nimport { Flex } from '../flex';\nimport SelectControl from '../select-control';\nimport { VStack } from '../v-stack';\nimport {\n\tgetGradientAstWithDefault,\n\tgetLinearGradientRepresentation,\n\tgetGradientAstWithControlPoints,\n\tgetStopCssColor,\n} from './utils';\nimport { serializeGradient } from './serializer';\nimport {\n\tDEFAULT_LINEAR_GRADIENT_ANGLE,\n\tHORIZONTAL_GRADIENT_ORIENTATION,\n\tGRADIENT_OPTIONS,\n} from './constants';\nimport {\n\tAccessoryWrapper,\n\tSelectWrapper,\n} from './styles/custom-gradient-picker-styles';\nimport type {\n\tCustomGradientPickerProps,\n\tGradientAnglePickerProps,\n\tGradientTypePickerProps,\n} from './types';\n\nconst GradientAnglePicker = ( {\n\tgradientAST,\n\thasGradient,\n\tonChange,\n}: GradientAnglePickerProps ) => {\n\tconst angle =\n\t\tgradientAST?.orientation?.value ?? DEFAULT_LINEAR_GRADIENT_ANGLE;\n\tconst onAngleChange = ( newAngle: number ) => {\n\t\tonChange(\n\t\t\tserializeGradient( {\n\t\t\t\t...gradientAST,\n\t\t\t\torientation: {\n\t\t\t\t\ttype: 'angular',\n\t\t\t\t\tvalue: `${ newAngle }`,\n\t\t\t\t},\n\t\t\t} )\n\t\t);\n\t};\n\treturn (\n\t\t<AnglePickerControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tonChange={ onAngleChange }\n\t\t\tvalue={ hasGradient ? angle : '' }\n\t\t/>\n\t);\n};\n\nconst GradientTypePicker = ( {\n\tgradientAST,\n\thasGradient,\n\tonChange,\n}: GradientTypePickerProps ) => {\n\tconst { type } = gradientAST;\n\n\tconst onSetLinearGradient = () => {\n\t\tonChange(\n\t\t\tserializeGradient( {\n\t\t\t\t...gradientAST,\n\t\t\t\torientation: gradientAST.orientation\n\t\t\t\t\t? undefined\n\t\t\t\t\t: HORIZONTAL_GRADIENT_ORIENTATION,\n\t\t\t\ttype: 'linear-gradient',\n\t\t\t} as gradientParser.LinearGradientNode )\n\t\t);\n\t};\n\n\tconst onSetRadialGradient = () => {\n\t\tconst { orientation, ...restGradientAST } = gradientAST;\n\t\tonChange(\n\t\t\tserializeGradient( {\n\t\t\t\t...restGradientAST,\n\t\t\t\ttype: 'radial-gradient',\n\t\t\t} )\n\t\t);\n\t};\n\n\tconst handleOnChange = ( next: string ) => {\n\t\tif ( next === 'linear-gradient' ) {\n\t\t\tonSetLinearGradient();\n\t\t}\n\t\tif ( next === 'radial-gradient' ) {\n\t\t\tonSetRadialGradient();\n\t\t}\n\t};\n\n\treturn (\n\t\t<SelectControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tclassName=\"components-custom-gradient-picker__type-picker\"\n\t\t\tlabel={ __( 'Type' ) }\n\t\t\tlabelPosition=\"top\"\n\t\t\tonChange={ handleOnChange }\n\t\t\toptions={ GRADIENT_OPTIONS }\n\t\t\tsize=\"__unstable-large\"\n\t\t\tvalue={ hasGradient ? type : undefined }\n\t\t/>\n\t);\n};\n\n/**\n * CustomGradientPicker is a React component that renders a UI for specifying\n * linear or radial gradients. Radial gradients are displayed in the picker as\n * a slice of the gradient from the center to the outside.\n *\n * ```jsx\n * import { CustomGradientPicker } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyCustomGradientPicker = () => {\n * const [ gradient, setGradient ] = useState();\n *\n * return (\n * <CustomGradientPicker\n *\t\t\tvalue={ gradient }\n *\t\t\tonChange={ setGradient }\n * />\n * );\n * };\n * ```\n */\nexport function CustomGradientPicker( {\n\t/** Start opting into the new margin-free styles that will become the default in a future version. */\n\t__nextHasNoMargin = false,\n\tvalue,\n\tonChange,\n\t__experimentalIsRenderedInSidebar = false,\n}: CustomGradientPickerProps ) {\n\tconst { gradientAST, hasGradient } = getGradientAstWithDefault( value );\n\n\t// On radial gradients the bar should display a linear gradient.\n\t// On radial gradients the bar represents a slice of the gradient from the center until the outside.\n\t// On liner gradients the bar represents the color stops from left to right independently of the angle.\n\tconst background = getLinearGradientRepresentation( gradientAST );\n\n\t// Control points color option may be hex from presets, custom colors will be rgb.\n\t// The position should always be a percentage.\n\tconst controlPoints = gradientAST.colorStops.map( ( colorStop ) => {\n\t\treturn {\n\t\t\tcolor: getStopCssColor( colorStop ),\n\t\t\t// Although it's already been checked by `hasUnsupportedLength` in `getGradientAstWithDefault`,\n\t\t\t// TypeScript doesn't know that `colorStop.length` is not undefined here.\n\t\t\t// @ts-expect-error\n\t\t\tposition: parseInt( colorStop.length.value ),\n\t\t};\n\t} );\n\n\tif ( ! __nextHasNoMargin ) {\n\t\tdeprecated(\n\t\t\t'Outer margin styles for wp.components.CustomGradientPicker',\n\t\t\t{\n\t\t\t\tsince: '6.1',\n\t\t\t\tversion: '6.4',\n\t\t\t\thint: 'Set the `__nextHasNoMargin` prop to true to start opting into the new styles, which will become the default in a future version',\n\t\t\t}\n\t\t);\n\t}\n\n\treturn (\n\t\t<VStack\n\t\t\tspacing={ 4 }\n\t\t\tclassName={ classnames( 'components-custom-gradient-picker', {\n\t\t\t\t'is-next-has-no-margin': __nextHasNoMargin,\n\t\t\t} ) }\n\t\t>\n\t\t\t<CustomGradientBar\n\t\t\t\t__experimentalIsRenderedInSidebar={\n\t\t\t\t\t__experimentalIsRenderedInSidebar\n\t\t\t\t}\n\t\t\t\tbackground={ background }\n\t\t\t\thasGradient={ hasGradient }\n\t\t\t\tvalue={ controlPoints }\n\t\t\t\tonChange={ ( newControlPoints ) => {\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tserializeGradient(\n\t\t\t\t\t\t\tgetGradientAstWithControlPoints(\n\t\t\t\t\t\t\t\tgradientAST,\n\t\t\t\t\t\t\t\tnewControlPoints\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t<Flex\n\t\t\t\tgap={ 3 }\n\t\t\t\tclassName=\"components-custom-gradient-picker__ui-line\"\n\t\t\t>\n\t\t\t\t<SelectWrapper>\n\t\t\t\t\t<GradientTypePicker\n\t\t\t\t\t\tgradientAST={ gradientAST }\n\t\t\t\t\t\thasGradient={ hasGradient }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t/>\n\t\t\t\t</SelectWrapper>\n\t\t\t\t<AccessoryWrapper>\n\t\t\t\t\t{ gradientAST.type === 'linear-gradient' && (\n\t\t\t\t\t\t<GradientAnglePicker\n\t\t\t\t\t\t\tgradientAST={ gradientAST }\n\t\t\t\t\t\t\thasGradient={ hasGradient }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</AccessoryWrapper>\n\t\t\t</Flex>\n\t\t</VStack>\n\t);\n}\n\nexport default CustomGradientPicker;\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
2
4
|
export function serializeGradientColor(_ref) {
|
|
3
5
|
let {
|
|
4
6
|
type,
|
|
@@ -38,7 +40,7 @@ export function serializeGradientColorStop(_ref2) {
|
|
|
38
40
|
})} ${serializeGradientPosition(length)}`;
|
|
39
41
|
}
|
|
40
42
|
export function serializeGradientOrientation(orientation) {
|
|
41
|
-
if (!orientation || orientation.type !== 'angular') {
|
|
43
|
+
if (Array.isArray(orientation) || !orientation || orientation.type !== 'angular') {
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -52,9 +54,13 @@ export function serializeGradient(_ref3) {
|
|
|
52
54
|
} = _ref3;
|
|
53
55
|
const serializedOrientation = serializeGradientOrientation(orientation);
|
|
54
56
|
const serializedColorStops = colorStops.sort((colorStop1, colorStop2) => {
|
|
55
|
-
|
|
57
|
+
const getNumericStopValue = colorStop => {
|
|
58
|
+
var _colorStop$length;
|
|
56
59
|
|
|
57
|
-
|
|
60
|
+
return (colorStop === null || colorStop === void 0 ? void 0 : (_colorStop$length = colorStop.length) === null || _colorStop$length === void 0 ? void 0 : _colorStop$length.value) === undefined ? 0 : parseInt(colorStop.length.value);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return getNumericStopValue(colorStop1) - getNumericStopValue(colorStop2);
|
|
58
64
|
}).map(serializeGradientColorStop);
|
|
59
65
|
return `${type}(${[serializedOrientation, ...serializedColorStops].filter(Boolean).join(',')})`;
|
|
60
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/serializer.
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/serializer.ts"],"names":["serializeGradientColor","type","value","join","serializeGradientPosition","position","serializeGradientColorStop","length","serializeGradientOrientation","orientation","Array","isArray","serializeGradient","colorStops","serializedOrientation","serializedColorStops","sort","colorStop1","colorStop2","getNumericStopValue","colorStop","undefined","parseInt","map","filter","Boolean"],"mappings":"AAAA;AACA;AACA;AAGA,OAAO,SAASA,sBAAT,OAGuB;AAAA,MAHU;AACvCC,IAAAA,IADuC;AAEvCC,IAAAA;AAFuC,GAGV;;AAC7B,MAAKD,IAAI,KAAK,SAAd,EAA0B;AACzB,WAAOC,KAAP;AACA;;AACD,MAAKD,IAAI,KAAK,KAAd,EAAsB;AACrB,W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,QAAQ,CAAEF,SAAS,CAACb,MAAV,CAAiBL,KAAnB,CAFX;AAGA,KAND;;AAQA,WACCiB,mBAAmB,CAAEF,UAAF,CAAnB,GACAE,mBAAmB,CAAED,UAAF,CAFpB;AAIA,GAd2B,EAe3BK,GAf2B,CAetBjB,0BAfsB,CAA7B;AAgBA,SAAQ,GAAGL,IAAM,IAAI,CAAEa,qBAAF,EAAyB,GAAGC,oBAA5B,EACnBS,MADmB,CACXC,OADW,EAEnBtB,IAFmB,CAEb,GAFa,CAEN,GAFf;AAGA","sourcesContent":["/**\n * External dependencies\n */\nimport type gradientParser from 'gradient-parser';\n\nexport function serializeGradientColor( {\n\ttype,\n\tvalue,\n}: gradientParser.ColorStop ) {\n\tif ( type === 'literal' ) {\n\t\treturn value;\n\t}\n\tif ( type === 'hex' ) {\n\t\treturn `#${ value }`;\n\t}\n\treturn `${ type }(${ value.join( ',' ) })`;\n}\n\nexport function serializeGradientPosition(\n\tposition: gradientParser.ColorStop[ 'length' ]\n) {\n\tif ( ! position ) {\n\t\treturn '';\n\t}\n\tconst { value, type } = position;\n\treturn `${ value }${ type }`;\n}\n\nexport function serializeGradientColorStop( {\n\ttype,\n\tvalue,\n\tlength,\n}: gradientParser.ColorStop ) {\n\treturn `${ serializeGradientColor( {\n\t\ttype,\n\t\tvalue,\n\t} as gradientParser.ColorStop ) } ${ serializeGradientPosition( length ) }`;\n}\n\nexport function serializeGradientOrientation(\n\torientation: gradientParser.GradientNode[ 'orientation' ]\n) {\n\tif (\n\t\tArray.isArray( orientation ) ||\n\t\t! orientation ||\n\t\torientation.type !== 'angular'\n\t) {\n\t\treturn;\n\t}\n\treturn `${ orientation.value }deg`;\n}\n\nexport function serializeGradient( {\n\ttype,\n\torientation,\n\tcolorStops,\n}: gradientParser.GradientNode ) {\n\tconst serializedOrientation = serializeGradientOrientation( orientation );\n\tconst serializedColorStops = colorStops\n\t\t.sort( ( colorStop1, colorStop2 ) => {\n\t\t\tconst getNumericStopValue = (\n\t\t\t\tcolorStop: gradientParser.ColorStop\n\t\t\t) => {\n\t\t\t\treturn colorStop?.length?.value === undefined\n\t\t\t\t\t? 0\n\t\t\t\t\t: parseInt( colorStop.length.value );\n\t\t\t};\n\n\t\t\treturn (\n\t\t\t\tgetNumericStopValue( colorStop1 ) -\n\t\t\t\tgetNumericStopValue( colorStop2 )\n\t\t\t);\n\t\t} )\n\t\t.map( serializeGradientColorStop );\n\treturn `${ type }(${ [ serializedOrientation, ...serializedColorStops ]\n\t\t.filter( Boolean )\n\t\t.join( ',' ) })`;\n}\n"]}
|
|
@@ -11,9 +11,9 @@ function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringif
|
|
|
11
11
|
*/
|
|
12
12
|
import { FlexBlock } from '../../flex';
|
|
13
13
|
export const SelectWrapper = /*#__PURE__*/_styled(FlexBlock, process.env.NODE_ENV === "production" ? {
|
|
14
|
-
target: "
|
|
14
|
+
target: "e10bzpgi1"
|
|
15
15
|
} : {
|
|
16
|
-
target: "
|
|
16
|
+
target: "e10bzpgi1",
|
|
17
17
|
label: "SelectWrapper"
|
|
18
18
|
})(process.env.NODE_ENV === "production" ? {
|
|
19
19
|
name: "1gvx10y",
|
|
@@ -21,13 +21,13 @@ export const SelectWrapper = /*#__PURE__*/_styled(FlexBlock, process.env.NODE_EN
|
|
|
21
21
|
} : {
|
|
22
22
|
name: "1gvx10y",
|
|
23
23
|
styles: "flex-grow:5",
|
|
24
|
-
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
24
|
+
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci9zdHlsZXMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci1zdHlsZXMudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVNnRCIsImZpbGUiOiJAd29yZHByZXNzL2NvbXBvbmVudHMvc3JjL2N1c3RvbS1ncmFkaWVudC1waWNrZXIvc3R5bGVzL2N1c3RvbS1ncmFkaWVudC1waWNrZXItc3R5bGVzLnRzeCIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogRXh0ZXJuYWwgZGVwZW5kZW5jaWVzXG4gKi9cbmltcG9ydCBzdHlsZWQgZnJvbSAnQGVtb3Rpb24vc3R5bGVkJztcbi8qKlxuICogSW50ZXJuYWwgZGVwZW5kZW5jaWVzXG4gKi9cbmltcG9ydCB7IEZsZXhCbG9jayB9IGZyb20gJy4uLy4uL2ZsZXgnO1xuXG5leHBvcnQgY29uc3QgU2VsZWN0V3JhcHBlciA9IHN0eWxlZCggRmxleEJsb2NrIClgXG5cdGZsZXgtZ3JvdzogNTtcbmA7XG5cbmV4cG9ydCBjb25zdCBBY2Nlc3NvcnlXcmFwcGVyID0gc3R5bGVkKCBGbGV4QmxvY2sgKWBcblx0ZmxleC1ncm93OiA1O1xuYDtcbiJdfQ== */",
|
|
25
25
|
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
26
26
|
});
|
|
27
27
|
export const AccessoryWrapper = /*#__PURE__*/_styled(FlexBlock, process.env.NODE_ENV === "production" ? {
|
|
28
|
-
target: "
|
|
28
|
+
target: "e10bzpgi0"
|
|
29
29
|
} : {
|
|
30
|
-
target: "
|
|
30
|
+
target: "e10bzpgi0",
|
|
31
31
|
label: "AccessoryWrapper"
|
|
32
32
|
})(process.env.NODE_ENV === "production" ? {
|
|
33
33
|
name: "1gvx10y",
|
|
@@ -35,7 +35,7 @@ export const AccessoryWrapper = /*#__PURE__*/_styled(FlexBlock, process.env.NODE
|
|
|
35
35
|
} : {
|
|
36
36
|
name: "1gvx10y",
|
|
37
37
|
styles: "flex-grow:5",
|
|
38
|
-
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
38
|
+
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci9zdHlsZXMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci1zdHlsZXMudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWFtRCIsImZpbGUiOiJAd29yZHByZXNzL2NvbXBvbmVudHMvc3JjL2N1c3RvbS1ncmFkaWVudC1waWNrZXIvc3R5bGVzL2N1c3RvbS1ncmFkaWVudC1waWNrZXItc3R5bGVzLnRzeCIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogRXh0ZXJuYWwgZGVwZW5kZW5jaWVzXG4gKi9cbmltcG9ydCBzdHlsZWQgZnJvbSAnQGVtb3Rpb24vc3R5bGVkJztcbi8qKlxuICogSW50ZXJuYWwgZGVwZW5kZW5jaWVzXG4gKi9cbmltcG9ydCB7IEZsZXhCbG9jayB9IGZyb20gJy4uLy4uL2ZsZXgnO1xuXG5leHBvcnQgY29uc3QgU2VsZWN0V3JhcHBlciA9IHN0eWxlZCggRmxleEJsb2NrIClgXG5cdGZsZXgtZ3JvdzogNTtcbmA7XG5cbmV4cG9ydCBjb25zdCBBY2Nlc3NvcnlXcmFwcGVyID0gc3R5bGVkKCBGbGV4QmxvY2sgKWBcblx0ZmxleC1ncm93OiA1O1xuYDtcbiJdfQ== */",
|
|
39
39
|
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
40
40
|
});
|
|
41
41
|
//# sourceMappingURL=custom-gradient-picker-styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/styles/custom-gradient-picker-styles.
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/styles/custom-gradient-picker-styles.tsx"],"names":["FlexBlock","SelectWrapper","AccessoryWrapper"],"mappings":";;;;AAAA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,YAA1B;AAEA,OAAO,MAAMC,aAAa,GAAG,qBAAQD,SAAR;AAAA;AAAA;AAAA;AAAA;AAAA,EAAH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAnB;AAIP,OAAO,MAAME,gBAAgB,GAAG,qBAAQF,SAAR;AAAA;AAAA;AAAA;AAAA;AAAA,EAAH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAtB","sourcesContent":["/**\n * External dependencies\n */\nimport styled from '@emotion/styled';\n/**\n * Internal dependencies\n */\nimport { FlexBlock } from '../../flex';\n\nexport const SelectWrapper = styled( FlexBlock )`\n\tflex-grow: 5;\n`;\n\nexport const AccessoryWrapper = styled( FlexBlock )`\n\tflex-grow: 5;\n`;\n"]}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* External dependencies
|
|
5
3
|
*/
|
|
@@ -31,18 +29,23 @@ export function getGradientAstWithDefault(value) {
|
|
|
31
29
|
// gradientAST will contain the gradient AST as parsed by gradient-parser npm module.
|
|
32
30
|
// More information of its structure available at https://www.npmjs.com/package/gradient-parser#ast.
|
|
33
31
|
let gradientAST;
|
|
32
|
+
let hasGradient = !!value;
|
|
33
|
+
const valueToParse = value !== null && value !== void 0 ? value : DEFAULT_GRADIENT;
|
|
34
34
|
|
|
35
35
|
try {
|
|
36
|
-
gradientAST = gradientParser.parse(
|
|
37
|
-
gradientAST.value = value;
|
|
36
|
+
gradientAST = gradientParser.parse(valueToParse)[0];
|
|
38
37
|
} catch (error) {
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.warn('wp.components.CustomGradientPicker failed to parse the gradient with error', error);
|
|
39
40
|
gradientAST = gradientParser.parse(DEFAULT_GRADIENT)[0];
|
|
40
|
-
|
|
41
|
+
hasGradient = false;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
if (((_gradientAST$orientat = gradientAST.orientation) === null || _gradientAST$orientat === void 0 ? void 0 : _gradientAST$orientat.type) === 'directional') {
|
|
44
|
-
gradientAST.orientation
|
|
45
|
-
|
|
44
|
+
if (!Array.isArray(gradientAST.orientation) && ((_gradientAST$orientat = gradientAST.orientation) === null || _gradientAST$orientat === void 0 ? void 0 : _gradientAST$orientat.type) === 'directional') {
|
|
45
|
+
gradientAST.orientation = {
|
|
46
|
+
type: 'angular',
|
|
47
|
+
value: DIRECTIONAL_ORIENTATION_ANGLE_MAP[gradientAST.orientation.value].toString()
|
|
48
|
+
};
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
if (gradientAST.colorStops.some(hasUnsupportedLength)) {
|
|
@@ -52,14 +55,16 @@ export function getGradientAstWithDefault(value) {
|
|
|
52
55
|
const step = 100 / (colorStops.length - 1);
|
|
53
56
|
colorStops.forEach((stop, index) => {
|
|
54
57
|
stop.length = {
|
|
55
|
-
value: step * index
|
|
58
|
+
value: `${step * index}`,
|
|
56
59
|
type: '%'
|
|
57
60
|
};
|
|
58
61
|
});
|
|
59
|
-
gradientAST.value = serializeGradient(gradientAST);
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
return
|
|
64
|
+
return {
|
|
65
|
+
gradientAST,
|
|
66
|
+
hasGradient
|
|
67
|
+
};
|
|
63
68
|
}
|
|
64
69
|
export function getGradientAstWithControlPoints(gradientAST, newControlPoints) {
|
|
65
70
|
return { ...gradientAST,
|
|
@@ -80,7 +85,7 @@ export function getGradientAstWithControlPoints(gradientAST, newControlPoints) {
|
|
|
80
85
|
value: position === null || position === void 0 ? void 0 : position.toString()
|
|
81
86
|
},
|
|
82
87
|
type: a < 1 ? 'rgba' : 'rgb',
|
|
83
|
-
value: a < 1 ? [r
|
|
88
|
+
value: a < 1 ? [`${r}`, `${g}`, `${b}`, `${a}`] : [`${r}`, `${g}`, `${b}`]
|
|
84
89
|
};
|
|
85
90
|
})
|
|
86
91
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/utils.
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/utils.ts"],"names":["gradientParser","colord","extend","namesPlugin","DEFAULT_GRADIENT","HORIZONTAL_GRADIENT_ORIENTATION","DIRECTIONAL_ORIENTATION_ANGLE_MAP","serializeGradient","getLinearGradientRepresentation","gradientAST","type","orientation","colorStops","hasUnsupportedLength","item","length","undefined","getGradientAstWithDefault","value","hasGradient","valueToParse","parse","error","console","warn","Array","isArray","toString","some","step","forEach","stop","index","getGradientAstWithControlPoints","newControlPoints","map","position","color","r","g","b","a","toRgb","getStopCssColor","colorStop","join"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,cAAP,MAA2B,iBAA3B;AACA,SAASC,MAAT,EAAiBC,MAAjB,QAA+B,QAA/B;AACA,OAAOC,WAAP,MAAwB,sBAAxB;AAEA;AACA;AACA;;AACA,SACCC,gBADD,EAECC,+BAFD,EAGCC,iCAHD,QAIO,aAJP;AAKA,SAASC,iBAAT,QAAkC,cAAlC;AAGAL,MAAM,CAAE,CAAEC,WAAF,CAAF,CAAN;AAEA,OAAO,SAASK,+BAAT,CACNC,WADM,EAEL;AACD,SAAOF,iBAAiB,CAAE;AACzBG,IAAAA,IAAI,EAAE,iBADmB;AAEzBC,IAAAA,WAAW,EAAEN,+BAFY;AAGzBO,IAAAA,UAAU,EAAEH,WAAW,CAACG;AAHC,GAAF,CAAxB;AAKA;;AAED,SAASC,oBAAT,CAA+BC,IAA/B,EAAgE;AAC/D,SAAOA,IAAI,CAACC,MAAL,KAAgBC,SAAhB,IAA6BF,IAAI,CAACC,MAAL,CAAYL,IAAZ,KAAqB,GAAzD;AACA;;AAED,OAAO,SAASO,yBAAT,CAAoCC,KAApC,EAA4D;AAAA;;AAClE;AACA;AACA,MAAIT,WAAJ;AACA,MAAIU,WAAW,GAAG,CAAC,CAAED,KAArB;AAEA,QAAME,YAAY,GAAGF,KAAH,aAAGA,KA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dependencies\n */\nimport gradientParser from 'gradient-parser';\nimport { colord, extend } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\n\n/**\n * Internal dependencies\n */\nimport {\n\tDEFAULT_GRADIENT,\n\tHORIZONTAL_GRADIENT_ORIENTATION,\n\tDIRECTIONAL_ORIENTATION_ANGLE_MAP,\n} from './constants';\nimport { serializeGradient } from './serializer';\nimport type { ControlPoint } from './types';\n\nextend( [ namesPlugin ] );\n\nexport function getLinearGradientRepresentation(\n\tgradientAST: gradientParser.GradientNode\n) {\n\treturn serializeGradient( {\n\t\ttype: 'linear-gradient',\n\t\torientation: HORIZONTAL_GRADIENT_ORIENTATION,\n\t\tcolorStops: gradientAST.colorStops,\n\t} );\n}\n\nfunction hasUnsupportedLength( item: gradientParser.ColorStop ) {\n\treturn item.length === undefined || item.length.type !== '%';\n}\n\nexport function getGradientAstWithDefault( value?: string | null ) {\n\t// gradientAST will contain the gradient AST as parsed by gradient-parser npm module.\n\t// More information of its structure available at https://www.npmjs.com/package/gradient-parser#ast.\n\tlet gradientAST: gradientParser.GradientNode | undefined;\n\tlet hasGradient = !! value;\n\n\tconst valueToParse = value ?? DEFAULT_GRADIENT;\n\n\ttry {\n\t\tgradientAST = gradientParser.parse( valueToParse )[ 0 ];\n\t} catch ( error ) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.warn(\n\t\t\t'wp.components.CustomGradientPicker failed to parse the gradient with error',\n\t\t\terror\n\t\t);\n\n\t\tgradientAST = gradientParser.parse( DEFAULT_GRADIENT )[ 0 ];\n\t\thasGradient = false;\n\t}\n\n\tif (\n\t\t! Array.isArray( gradientAST.orientation ) &&\n\t\tgradientAST.orientation?.type === 'directional'\n\t) {\n\t\tgradientAST.orientation = {\n\t\t\ttype: 'angular',\n\t\t\tvalue: DIRECTIONAL_ORIENTATION_ANGLE_MAP[\n\t\t\t\tgradientAST.orientation.value\n\t\t\t].toString(),\n\t\t};\n\t}\n\n\tif ( gradientAST.colorStops.some( hasUnsupportedLength ) ) {\n\t\tconst { colorStops } = gradientAST;\n\t\tconst step = 100 / ( colorStops.length - 1 );\n\t\tcolorStops.forEach( ( stop, index ) => {\n\t\t\tstop.length = {\n\t\t\t\tvalue: `${ step * index }`,\n\t\t\t\ttype: '%',\n\t\t\t};\n\t\t} );\n\t}\n\n\treturn { gradientAST, hasGradient };\n}\n\nexport function getGradientAstWithControlPoints(\n\tgradientAST: gradientParser.GradientNode,\n\tnewControlPoints: ControlPoint[]\n) {\n\treturn {\n\t\t...gradientAST,\n\t\tcolorStops: newControlPoints.map( ( { position, color } ) => {\n\t\t\tconst { r, g, b, a } = colord( color ).toRgb();\n\t\t\treturn {\n\t\t\t\tlength: {\n\t\t\t\t\ttype: '%',\n\t\t\t\t\tvalue: position?.toString(),\n\t\t\t\t},\n\t\t\t\ttype: a < 1 ? 'rgba' : 'rgb',\n\t\t\t\tvalue:\n\t\t\t\t\ta < 1\n\t\t\t\t\t\t? [ `${ r }`, `${ g }`, `${ b }`, `${ a }` ]\n\t\t\t\t\t\t: [ `${ r }`, `${ g }`, `${ b }` ],\n\t\t\t};\n\t\t} ),\n\t} as gradientParser.GradientNode;\n}\n\nexport function getStopCssColor( colorStop: gradientParser.ColorStop ) {\n\tswitch ( colorStop.type ) {\n\t\tcase 'hex':\n\t\t\treturn `#${ colorStop.value }`;\n\t\tcase 'literal':\n\t\t\treturn colorStop.value;\n\t\tcase 'rgb':\n\t\tcase 'rgba':\n\t\t\treturn `${ colorStop.type }(${ colorStop.value.join( ',' ) })`;\n\t\tdefault:\n\t\t\t// Should be unreachable if passing an AST from gradient-parser.\n\t\t\t// See https://github.com/rafaelcaricio/gradient-parser#ast.\n\t\t\treturn 'transparent';\n\t}\n}\n"]}
|