@wordpress/components 23.6.0 → 23.7.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 +32 -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 +14 -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/{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/palette-edit/index.js +1 -2
- package/build/palette-edit/index.js.map +1 -1
- package/build/resizable-box/resize-tooltip/utils.js.map +1 -1
- package/build/sandbox/index.native.js +80 -67
- 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 +14 -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/{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/palette-edit/index.js +1 -2
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/resizable-box/resize-tooltip/utils.js.map +1 -1
- package/build-module/sandbox/index.native.js +70 -58
- 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 +40 -28
- package/build-style/style.css +42 -28
- 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 +5 -0
- 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/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/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/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 +13 -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 +120 -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/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/form-token-field/index.d.ts.map +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/palette-edit/index.d.ts.map +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/tab-panel/index.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
- package/build-types/tools-panel/types.d.ts +1 -0
- package/build-types/tools-panel/types.d.ts.map +1 -1
- package/build-types/utils/input/input-control.d.ts.map +1 -1
- package/package.json +19 -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 +82 -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 +137 -0
- package/src/custom-gradient-picker/{utils.js → utils.ts} +37 -22
- package/src/custom-select-control/test/index.js +6 -4
- 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/palette-edit/index.tsx +4 -5
- package/src/resizable-box/resize-tooltip/utils.ts +1 -1
- package/src/sandbox/index.native.js +71 -78
- 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 -2
- 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
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { MINIMUM_DISTANCE_BETWEEN_POINTS } from './constants';
|
|
5
|
+
import type { ControlPoint } from '../types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Clamps a number between 0 and 100.
|
|
9
|
+
*
|
|
10
|
+
* @param value Value to clamp.
|
|
11
|
+
*
|
|
12
|
+
* @return Value clamped between 0 and 100.
|
|
13
|
+
*/
|
|
14
|
+
export function clampPercent( value: number ) {
|
|
15
|
+
return Math.max( 0, Math.min( 100, value ) );
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Check if a control point is overlapping with another.
|
|
20
|
+
*
|
|
21
|
+
* @param value Array of control points.
|
|
22
|
+
* @param initialIndex Index of the position to test.
|
|
23
|
+
* @param newPosition New position of the control point.
|
|
24
|
+
* @param minDistance Distance considered to be overlapping.
|
|
25
|
+
*
|
|
26
|
+
* @return True if the point is overlapping.
|
|
27
|
+
*/
|
|
28
|
+
export function isOverlapping(
|
|
29
|
+
value: ControlPoint[],
|
|
30
|
+
initialIndex: number,
|
|
31
|
+
newPosition: number,
|
|
32
|
+
minDistance: number = MINIMUM_DISTANCE_BETWEEN_POINTS
|
|
33
|
+
) {
|
|
34
|
+
const initialPosition = value[ initialIndex ].position;
|
|
35
|
+
const minPosition = Math.min( initialPosition, newPosition );
|
|
36
|
+
const maxPosition = Math.max( initialPosition, newPosition );
|
|
37
|
+
|
|
38
|
+
return value.some( ( { position }, index ) => {
|
|
39
|
+
return (
|
|
40
|
+
index !== initialIndex &&
|
|
41
|
+
( Math.abs( position - newPosition ) < minDistance ||
|
|
42
|
+
( minPosition < position && position < maxPosition ) )
|
|
43
|
+
);
|
|
44
|
+
} );
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Adds a control point from an array and returns the new array.
|
|
49
|
+
*
|
|
50
|
+
* @param points Array of control points.
|
|
51
|
+
* @param position Position to insert the new point.
|
|
52
|
+
* @param color Color to update the control point at index.
|
|
53
|
+
*
|
|
54
|
+
* @return New array of control points.
|
|
55
|
+
*/
|
|
56
|
+
export function addControlPoint(
|
|
57
|
+
points: ControlPoint[],
|
|
58
|
+
position: number,
|
|
59
|
+
color: ControlPoint[ 'color' ]
|
|
60
|
+
) {
|
|
61
|
+
const nextIndex = points.findIndex(
|
|
62
|
+
( point ) => point.position > position
|
|
63
|
+
);
|
|
64
|
+
const newPoint = { color, position };
|
|
65
|
+
const newPoints = points.slice();
|
|
66
|
+
newPoints.splice( nextIndex - 1, 0, newPoint );
|
|
67
|
+
return newPoints;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Removes a control point from an array and returns the new array.
|
|
72
|
+
*
|
|
73
|
+
* @param points Array of control points.
|
|
74
|
+
* @param index Index to remove.
|
|
75
|
+
*
|
|
76
|
+
* @return New array of control points.
|
|
77
|
+
*/
|
|
78
|
+
export function removeControlPoint( points: ControlPoint[], index: number ) {
|
|
79
|
+
return points.filter( ( _point, pointIndex ) => {
|
|
80
|
+
return pointIndex !== index;
|
|
81
|
+
} );
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Updates a control point from an array and returns the new array.
|
|
85
|
+
*
|
|
86
|
+
* @param points Array of control points.
|
|
87
|
+
* @param index Index to update.
|
|
88
|
+
* @param newPoint New control point to replace the index.
|
|
89
|
+
*
|
|
90
|
+
* @return New array of control points.
|
|
91
|
+
*/
|
|
92
|
+
export function updateControlPoint(
|
|
93
|
+
points: ControlPoint[],
|
|
94
|
+
index: number,
|
|
95
|
+
newPoint: ControlPoint
|
|
96
|
+
) {
|
|
97
|
+
const newValue = points.slice();
|
|
98
|
+
newValue[ index ] = newPoint;
|
|
99
|
+
return newValue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Updates the position of a control point from an array and returns the new array.
|
|
104
|
+
*
|
|
105
|
+
* @param points Array of control points.
|
|
106
|
+
* @param index Index to update.
|
|
107
|
+
* @param newPosition Position to move the control point at index.
|
|
108
|
+
*
|
|
109
|
+
* @return New array of control points.
|
|
110
|
+
*/
|
|
111
|
+
export function updateControlPointPosition(
|
|
112
|
+
points: ControlPoint[],
|
|
113
|
+
index: number,
|
|
114
|
+
newPosition: ControlPoint[ 'position' ]
|
|
115
|
+
) {
|
|
116
|
+
if ( isOverlapping( points, index, newPosition ) ) {
|
|
117
|
+
return points;
|
|
118
|
+
}
|
|
119
|
+
const newPoint = {
|
|
120
|
+
...points[ index ],
|
|
121
|
+
position: newPosition,
|
|
122
|
+
};
|
|
123
|
+
return updateControlPoint( points, index, newPoint );
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Updates the position of a control point from an array and returns the new array.
|
|
128
|
+
*
|
|
129
|
+
* @param points Array of control points.
|
|
130
|
+
* @param index Index to update.
|
|
131
|
+
* @param newColor Color to update the control point at index.
|
|
132
|
+
*
|
|
133
|
+
* @return New array of control points.
|
|
134
|
+
*/
|
|
135
|
+
export function updateControlPointColor(
|
|
136
|
+
points: ControlPoint[],
|
|
137
|
+
index: number,
|
|
138
|
+
newColor: ControlPoint[ 'color' ]
|
|
139
|
+
) {
|
|
140
|
+
const newPoint = {
|
|
141
|
+
...points[ index ],
|
|
142
|
+
color: newColor,
|
|
143
|
+
};
|
|
144
|
+
return updateControlPoint( points, index, newPoint );
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Updates the position of a control point from an array and returns the new array.
|
|
149
|
+
*
|
|
150
|
+
* @param points Array of control points.
|
|
151
|
+
* @param position Position of the color stop.
|
|
152
|
+
* @param newColor Color to update the control point at index.
|
|
153
|
+
*
|
|
154
|
+
* @return New array of control points.
|
|
155
|
+
*/
|
|
156
|
+
export function updateControlPointColorByPosition(
|
|
157
|
+
points: ControlPoint[],
|
|
158
|
+
position: ControlPoint[ 'position' ],
|
|
159
|
+
newColor: ControlPoint[ 'color' ]
|
|
160
|
+
) {
|
|
161
|
+
const index = points.findIndex( ( point ) => point.position === position );
|
|
162
|
+
return updateControlPointColor( points, index, newColor );
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Gets the horizontal coordinate when dragging a control point with the mouse.
|
|
167
|
+
*
|
|
168
|
+
* @param mouseXcoordinate Horizontal coordinate of the mouse position.
|
|
169
|
+
* @param containerElement Container for the gradient picker.
|
|
170
|
+
*
|
|
171
|
+
* @return Whole number percentage from the left.
|
|
172
|
+
*/
|
|
173
|
+
export function getHorizontalRelativeGradientPosition(
|
|
174
|
+
mouseXcoordinate: number,
|
|
175
|
+
containerElement: HTMLDivElement
|
|
176
|
+
): number;
|
|
177
|
+
export function getHorizontalRelativeGradientPosition(
|
|
178
|
+
mouseXcoordinate: number,
|
|
179
|
+
containerElement: null
|
|
180
|
+
): undefined;
|
|
181
|
+
export function getHorizontalRelativeGradientPosition(
|
|
182
|
+
mouseXCoordinate: number,
|
|
183
|
+
containerElement: HTMLDivElement | null
|
|
184
|
+
) {
|
|
185
|
+
if ( ! containerElement ) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const { x, width } = containerElement.getBoundingClientRect();
|
|
189
|
+
const absolutePositionValue = mouseXCoordinate - x;
|
|
190
|
+
return Math.round(
|
|
191
|
+
clampPercent( ( absolutePositionValue * 100 ) / width )
|
|
192
|
+
);
|
|
193
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* External dependencies
|
|
5
3
|
*/
|
|
6
4
|
import classnames from 'classnames';
|
|
5
|
+
import type gradientParser from 'gradient-parser';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* WordPress dependencies
|
|
@@ -30,23 +29,31 @@ import {
|
|
|
30
29
|
DEFAULT_LINEAR_GRADIENT_ANGLE,
|
|
31
30
|
HORIZONTAL_GRADIENT_ORIENTATION,
|
|
32
31
|
GRADIENT_OPTIONS,
|
|
33
|
-
DEFAULT_GRADIENT,
|
|
34
32
|
} from './constants';
|
|
35
33
|
import {
|
|
36
34
|
AccessoryWrapper,
|
|
37
35
|
SelectWrapper,
|
|
38
36
|
} from './styles/custom-gradient-picker-styles';
|
|
37
|
+
import type {
|
|
38
|
+
CustomGradientPickerProps,
|
|
39
|
+
GradientAnglePickerProps,
|
|
40
|
+
GradientTypePickerProps,
|
|
41
|
+
} from './types';
|
|
39
42
|
|
|
40
|
-
const GradientAnglePicker = ( {
|
|
43
|
+
const GradientAnglePicker = ( {
|
|
44
|
+
gradientAST,
|
|
45
|
+
hasGradient,
|
|
46
|
+
onChange,
|
|
47
|
+
}: GradientAnglePickerProps ) => {
|
|
41
48
|
const angle =
|
|
42
49
|
gradientAST?.orientation?.value ?? DEFAULT_LINEAR_GRADIENT_ANGLE;
|
|
43
|
-
const onAngleChange = ( newAngle ) => {
|
|
50
|
+
const onAngleChange = ( newAngle: number ) => {
|
|
44
51
|
onChange(
|
|
45
52
|
serializeGradient( {
|
|
46
53
|
...gradientAST,
|
|
47
54
|
orientation: {
|
|
48
55
|
type: 'angular',
|
|
49
|
-
value: newAngle
|
|
56
|
+
value: `${ newAngle }`,
|
|
50
57
|
},
|
|
51
58
|
} )
|
|
52
59
|
);
|
|
@@ -60,17 +67,22 @@ const GradientAnglePicker = ( { gradientAST, hasGradient, onChange } ) => {
|
|
|
60
67
|
);
|
|
61
68
|
};
|
|
62
69
|
|
|
63
|
-
const GradientTypePicker = ( {
|
|
70
|
+
const GradientTypePicker = ( {
|
|
71
|
+
gradientAST,
|
|
72
|
+
hasGradient,
|
|
73
|
+
onChange,
|
|
74
|
+
}: GradientTypePickerProps ) => {
|
|
64
75
|
const { type } = gradientAST;
|
|
76
|
+
|
|
65
77
|
const onSetLinearGradient = () => {
|
|
66
78
|
onChange(
|
|
67
79
|
serializeGradient( {
|
|
68
80
|
...gradientAST,
|
|
69
|
-
|
|
70
|
-
?
|
|
71
|
-
:
|
|
81
|
+
orientation: gradientAST.orientation
|
|
82
|
+
? undefined
|
|
83
|
+
: HORIZONTAL_GRADIENT_ORIENTATION,
|
|
72
84
|
type: 'linear-gradient',
|
|
73
|
-
} )
|
|
85
|
+
} as gradientParser.LinearGradientNode )
|
|
74
86
|
);
|
|
75
87
|
};
|
|
76
88
|
|
|
@@ -84,7 +96,7 @@ const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {
|
|
|
84
96
|
);
|
|
85
97
|
};
|
|
86
98
|
|
|
87
|
-
const handleOnChange = ( next ) => {
|
|
99
|
+
const handleOnChange = ( next: string ) => {
|
|
88
100
|
if ( next === 'linear-gradient' ) {
|
|
89
101
|
onSetLinearGradient();
|
|
90
102
|
}
|
|
@@ -102,30 +114,57 @@ const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {
|
|
|
102
114
|
onChange={ handleOnChange }
|
|
103
115
|
options={ GRADIENT_OPTIONS }
|
|
104
116
|
size="__unstable-large"
|
|
105
|
-
value={ hasGradient
|
|
117
|
+
value={ hasGradient ? type : undefined }
|
|
106
118
|
/>
|
|
107
119
|
);
|
|
108
120
|
};
|
|
109
121
|
|
|
110
|
-
|
|
122
|
+
/**
|
|
123
|
+
* CustomGradientPicker is a React component that renders a UI for specifying
|
|
124
|
+
* linear or radial gradients. Radial gradients are displayed in the picker as
|
|
125
|
+
* a slice of the gradient from the center to the outside.
|
|
126
|
+
*
|
|
127
|
+
* ```jsx
|
|
128
|
+
* import { CustomGradientPicker } from '@wordpress/components';
|
|
129
|
+
* import { useState } from '@wordpress/element';
|
|
130
|
+
*
|
|
131
|
+
* const MyCustomGradientPicker = () => {
|
|
132
|
+
* const [ gradient, setGradient ] = useState();
|
|
133
|
+
*
|
|
134
|
+
* return (
|
|
135
|
+
* <CustomGradientPicker
|
|
136
|
+
* value={ gradient }
|
|
137
|
+
* onChange={ setGradient }
|
|
138
|
+
* />
|
|
139
|
+
* );
|
|
140
|
+
* };
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export function CustomGradientPicker( {
|
|
111
144
|
/** Start opting into the new margin-free styles that will become the default in a future version. */
|
|
112
145
|
__nextHasNoMargin = false,
|
|
113
146
|
value,
|
|
114
147
|
onChange,
|
|
115
|
-
__experimentalIsRenderedInSidebar,
|
|
116
|
-
} ) {
|
|
117
|
-
const gradientAST = getGradientAstWithDefault( value );
|
|
148
|
+
__experimentalIsRenderedInSidebar = false,
|
|
149
|
+
}: CustomGradientPickerProps ) {
|
|
150
|
+
const { gradientAST, hasGradient } = getGradientAstWithDefault( value );
|
|
151
|
+
|
|
118
152
|
// On radial gradients the bar should display a linear gradient.
|
|
119
153
|
// On radial gradients the bar represents a slice of the gradient from the center until the outside.
|
|
120
154
|
// On liner gradients the bar represents the color stops from left to right independently of the angle.
|
|
121
155
|
const background = getLinearGradientRepresentation( gradientAST );
|
|
122
|
-
|
|
156
|
+
|
|
123
157
|
// Control points color option may be hex from presets, custom colors will be rgb.
|
|
124
158
|
// The position should always be a percentage.
|
|
125
|
-
const controlPoints = gradientAST.colorStops.map( ( colorStop ) =>
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
159
|
+
const controlPoints = gradientAST.colorStops.map( ( colorStop ) => {
|
|
160
|
+
return {
|
|
161
|
+
color: getStopCssColor( colorStop ),
|
|
162
|
+
// Although it's already been checked by `hasUnsupportedLength` in `getGradientAstWithDefault`,
|
|
163
|
+
// TypeScript doesn't know that `colorStop.length` is not undefined here.
|
|
164
|
+
// @ts-expect-error
|
|
165
|
+
position: parseInt( colorStop.length.value ),
|
|
166
|
+
};
|
|
167
|
+
} );
|
|
129
168
|
|
|
130
169
|
if ( ! __nextHasNoMargin ) {
|
|
131
170
|
deprecated(
|
|
@@ -187,3 +226,5 @@ export default function CustomGradientPicker( {
|
|
|
187
226
|
</VStack>
|
|
188
227
|
);
|
|
189
228
|
}
|
|
229
|
+
|
|
230
|
+
export default CustomGradientPicker;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type gradientParser from 'gradient-parser';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
import type { ColorStopTypeAndValue } from './types';
|
|
9
|
+
|
|
10
|
+
export function serializeGradientColor( {
|
|
11
|
+
type,
|
|
12
|
+
value,
|
|
13
|
+
}: ColorStopTypeAndValue ) {
|
|
14
|
+
if ( type === 'literal' ) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
if ( type === 'hex' ) {
|
|
18
|
+
return `#${ value }`;
|
|
19
|
+
}
|
|
20
|
+
return `${ type }(${ value.join( ',' ) })`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function serializeGradientPosition(
|
|
24
|
+
position: gradientParser.ColorStop[ 'length' ]
|
|
25
|
+
) {
|
|
26
|
+
if ( ! position ) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
const { value, type } = position;
|
|
30
|
+
return `${ value }${ type }`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function serializeGradientColorStop( {
|
|
34
|
+
type,
|
|
35
|
+
value,
|
|
36
|
+
length,
|
|
37
|
+
}: gradientParser.ColorStop ) {
|
|
38
|
+
return `${ serializeGradientColor( {
|
|
39
|
+
type,
|
|
40
|
+
value,
|
|
41
|
+
} as ColorStopTypeAndValue ) } ${ serializeGradientPosition( length ) }`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function serializeGradientOrientation(
|
|
45
|
+
orientation: gradientParser.GradientNode[ 'orientation' ]
|
|
46
|
+
) {
|
|
47
|
+
if (
|
|
48
|
+
Array.isArray( orientation ) ||
|
|
49
|
+
! orientation ||
|
|
50
|
+
orientation.type !== 'angular'
|
|
51
|
+
) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
return `${ orientation.value }deg`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function serializeGradient( {
|
|
58
|
+
type,
|
|
59
|
+
orientation,
|
|
60
|
+
colorStops,
|
|
61
|
+
}: gradientParser.GradientNode ) {
|
|
62
|
+
const serializedOrientation = serializeGradientOrientation( orientation );
|
|
63
|
+
const serializedColorStops = colorStops
|
|
64
|
+
.sort( ( colorStop1, colorStop2 ) => {
|
|
65
|
+
const getNumericStopValue = (
|
|
66
|
+
colorStop: gradientParser.ColorStop
|
|
67
|
+
) => {
|
|
68
|
+
return colorStop?.length?.value === undefined
|
|
69
|
+
? 0
|
|
70
|
+
: parseInt( colorStop.length.value );
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
getNumericStopValue( colorStop1 ) -
|
|
75
|
+
getNumericStopValue( colorStop2 )
|
|
76
|
+
);
|
|
77
|
+
} )
|
|
78
|
+
.map( serializeGradientColorStop );
|
|
79
|
+
return `${ type }(${ [ serializedOrientation, ...serializedColorStops ]
|
|
80
|
+
.filter( Boolean )
|
|
81
|
+
.join( ',' ) })`;
|
|
82
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
5
|
+
/**
|
|
6
|
+
* WordPress dependencies
|
|
7
|
+
*/
|
|
8
|
+
import { useState } from '@wordpress/element';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import CustomGradientPicker from '../';
|
|
14
|
+
|
|
15
|
+
const meta: ComponentMeta< typeof CustomGradientPicker > = {
|
|
16
|
+
title: 'Components/CustomGradientPicker',
|
|
17
|
+
component: CustomGradientPicker,
|
|
18
|
+
parameters: {
|
|
19
|
+
actions: { argTypesRegex: '^on.*' },
|
|
20
|
+
controls: { expanded: true },
|
|
21
|
+
docs: { source: { state: 'open' } },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export default meta;
|
|
25
|
+
|
|
26
|
+
const CustomGradientPickerWithState: ComponentStory<
|
|
27
|
+
typeof CustomGradientPicker
|
|
28
|
+
> = ( { onChange, ...props } ) => {
|
|
29
|
+
const [ gradient, setGradient ] = useState< string >();
|
|
30
|
+
return (
|
|
31
|
+
<CustomGradientPicker
|
|
32
|
+
{ ...props }
|
|
33
|
+
value={ gradient }
|
|
34
|
+
onChange={ ( newGradient ) => {
|
|
35
|
+
setGradient( newGradient );
|
|
36
|
+
onChange( newGradient );
|
|
37
|
+
} }
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const Default = CustomGradientPickerWithState.bind( {} );
|
|
43
|
+
Default.args = {
|
|
44
|
+
__nextHasNoMargin: true,
|
|
45
|
+
};
|
|
@@ -7,14 +7,30 @@ $components-custom-gradient-picker__padding: $grid-unit-20; // 48px container, 1
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
.components-custom-gradient-picker__gradient-bar:not(.has-gradient) {
|
|
11
|
-
opacity: 0.4;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
10
|
.components-custom-gradient-picker__gradient-bar {
|
|
15
11
|
border-radius: $radius-block-ui;
|
|
16
12
|
width: 100%;
|
|
17
13
|
height: $grid-unit-60;
|
|
14
|
+
position: relative;
|
|
15
|
+
z-index: 1;
|
|
16
|
+
|
|
17
|
+
&.has-gradient {
|
|
18
|
+
// The background image creates a checkerboard pattern. Ignore rtlcss to
|
|
19
|
+
// make it work both in LTR and RTL.
|
|
20
|
+
// See https://github.com/WordPress/gutenberg/pull/42510
|
|
21
|
+
/*rtl:begin:ignore*/
|
|
22
|
+
background-image:
|
|
23
|
+
repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200),
|
|
24
|
+
repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200);
|
|
25
|
+
background-position: 0 0, 12px 12px;
|
|
26
|
+
/*rtl:end:ignore*/
|
|
27
|
+
background-size: calc(2 * 12px) calc(2 * 12px);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.components-custom-gradient-picker__gradient-bar-background {
|
|
31
|
+
position: absolute;
|
|
32
|
+
inset: 0;
|
|
33
|
+
}
|
|
18
34
|
|
|
19
35
|
.components-custom-gradient-picker__markers-container {
|
|
20
36
|
position: relative;
|
|
@@ -109,3 +125,8 @@ $components-custom-gradient-picker__padding: $grid-unit-20; // 48px container, 1
|
|
|
109
125
|
}
|
|
110
126
|
}
|
|
111
127
|
}
|
|
128
|
+
|
|
129
|
+
.components-custom-gradient-picker__ui-line {
|
|
130
|
+
position: relative;
|
|
131
|
+
z-index: 0;
|
|
132
|
+
}
|
|
@@ -12,24 +12,30 @@ import {
|
|
|
12
12
|
describe( 'It should serialize a gradient', () => {
|
|
13
13
|
test( 'serializeGradientColor', () => {
|
|
14
14
|
expect(
|
|
15
|
-
serializeGradientColor( {
|
|
15
|
+
serializeGradientColor( {
|
|
16
|
+
type: 'rgba',
|
|
17
|
+
value: [ '1', '2', '3', '0.5' ],
|
|
18
|
+
} )
|
|
16
19
|
).toBe( 'rgba(1,2,3,0.5)' );
|
|
17
20
|
|
|
18
21
|
expect(
|
|
19
|
-
serializeGradientColor( {
|
|
22
|
+
serializeGradientColor( {
|
|
23
|
+
type: 'rgb',
|
|
24
|
+
value: [ '255', '0', '0' ],
|
|
25
|
+
} )
|
|
20
26
|
).toBe( 'rgb(255,0,0)' );
|
|
21
27
|
} );
|
|
22
28
|
|
|
23
29
|
test( 'serializeGradientPosition', () => {
|
|
24
|
-
expect( serializeGradientPosition( { type: '%', value: 70 } ) ).toBe(
|
|
30
|
+
expect( serializeGradientPosition( { type: '%', value: '70' } ) ).toBe(
|
|
25
31
|
'70%'
|
|
26
32
|
);
|
|
27
33
|
|
|
28
|
-
expect( serializeGradientPosition( { type: '%', value: 0 } ) ).toBe(
|
|
34
|
+
expect( serializeGradientPosition( { type: '%', value: '0' } ) ).toBe(
|
|
29
35
|
'0%'
|
|
30
36
|
);
|
|
31
37
|
|
|
32
|
-
expect( serializeGradientPosition( { type: 'px', value: 4 } ) ).toBe(
|
|
38
|
+
expect( serializeGradientPosition( { type: 'px', value: '4' } ) ).toBe(
|
|
33
39
|
'4px'
|
|
34
40
|
);
|
|
35
41
|
} );
|
|
@@ -38,35 +44,35 @@ describe( 'It should serialize a gradient', () => {
|
|
|
38
44
|
expect(
|
|
39
45
|
serializeGradientColorStop( {
|
|
40
46
|
type: 'rgba',
|
|
41
|
-
value: [ 1, 2, 3, 0.5 ],
|
|
42
|
-
length: { type: '%', value: 70 },
|
|
47
|
+
value: [ '1', '2', '3', '0.5' ],
|
|
48
|
+
length: { type: '%', value: '70' },
|
|
43
49
|
} )
|
|
44
50
|
).toBe( 'rgba(1,2,3,0.5) 70%' );
|
|
45
51
|
|
|
46
52
|
expect(
|
|
47
53
|
serializeGradientColorStop( {
|
|
48
54
|
type: 'rgb',
|
|
49
|
-
value: [ 255, 0, 0 ],
|
|
50
|
-
length: { type: '%', value: 0 },
|
|
55
|
+
value: [ '255', '0', '0' ],
|
|
56
|
+
length: { type: '%', value: '0' },
|
|
51
57
|
} )
|
|
52
58
|
).toBe( 'rgb(255,0,0) 0%' );
|
|
53
59
|
|
|
54
60
|
expect(
|
|
55
61
|
serializeGradientColorStop( {
|
|
56
62
|
type: 'rgba',
|
|
57
|
-
value: [ 1, 2, 3, 0.5 ],
|
|
58
|
-
length: { type: 'px', value: 100 },
|
|
63
|
+
value: [ '1', '2', '3', '0.5' ],
|
|
64
|
+
length: { type: 'px', value: '100' },
|
|
59
65
|
} )
|
|
60
66
|
).toBe( 'rgba(1,2,3,0.5) 100px' );
|
|
61
67
|
} );
|
|
62
68
|
|
|
63
69
|
test( 'serializeGradientOrientation', () => {
|
|
64
70
|
expect(
|
|
65
|
-
serializeGradientOrientation( { type: 'angular', value: 40 } )
|
|
71
|
+
serializeGradientOrientation( { type: 'angular', value: '40' } )
|
|
66
72
|
).toBe( '40deg' );
|
|
67
73
|
|
|
68
74
|
expect(
|
|
69
|
-
serializeGradientOrientation( { type: 'angular', value: 0 } )
|
|
75
|
+
serializeGradientOrientation( { type: 'angular', value: '0' } )
|
|
70
76
|
).toBe( '0deg' );
|
|
71
77
|
} );
|
|
72
78
|
|
|
@@ -74,17 +80,17 @@ describe( 'It should serialize a gradient', () => {
|
|
|
74
80
|
expect(
|
|
75
81
|
serializeGradient( {
|
|
76
82
|
type: 'linear-gradient',
|
|
77
|
-
orientation: { type: 'angular', value: 40 },
|
|
83
|
+
orientation: { type: 'angular', value: '40' },
|
|
78
84
|
colorStops: [
|
|
79
85
|
{
|
|
80
86
|
type: 'rgba',
|
|
81
|
-
value: [ 1, 2, 3, 0.5 ],
|
|
82
|
-
length: { type: '%', value: 70 },
|
|
87
|
+
value: [ '1', '2', '3', '0.5' ],
|
|
88
|
+
length: { type: '%', value: '70' },
|
|
83
89
|
},
|
|
84
90
|
{
|
|
85
91
|
type: 'rgba',
|
|
86
|
-
value: [ 255, 1, 1, 0.9 ],
|
|
87
|
-
length: { type: '%', value: 40 },
|
|
92
|
+
value: [ '255', '1', '1', '0.9' ],
|
|
93
|
+
length: { type: '%', value: '40' },
|
|
88
94
|
},
|
|
89
95
|
],
|
|
90
96
|
} )
|
|
@@ -98,13 +104,13 @@ describe( 'It should serialize a gradient', () => {
|
|
|
98
104
|
colorStops: [
|
|
99
105
|
{
|
|
100
106
|
type: 'rgba',
|
|
101
|
-
value: [ 1, 2, 3, 0.5 ],
|
|
102
|
-
length: { type: '%', value: 70 },
|
|
107
|
+
value: [ '1', '2', '3', '0.5' ],
|
|
108
|
+
length: { type: '%', value: '70' },
|
|
103
109
|
},
|
|
104
110
|
{
|
|
105
111
|
type: 'rgba',
|
|
106
|
-
value: [ 255, 1, 1, 0.9 ],
|
|
107
|
-
length: { type: '%', value: 40 },
|
|
112
|
+
value: [ '255', '1', '1', '0.9' ],
|
|
113
|
+
length: { type: '%', value: '40' },
|
|
108
114
|
},
|
|
109
115
|
],
|
|
110
116
|
} )
|
|
@@ -117,12 +123,12 @@ describe( 'It should serialize a gradient', () => {
|
|
|
117
123
|
{
|
|
118
124
|
type: 'hex',
|
|
119
125
|
value: '000',
|
|
120
|
-
length: { type: '%', value: 70 },
|
|
126
|
+
length: { type: '%', value: '70' },
|
|
121
127
|
},
|
|
122
128
|
{
|
|
123
129
|
type: 'hex',
|
|
124
130
|
value: 'fff',
|
|
125
|
-
length: { type: '%', value: 40 },
|
|
131
|
+
length: { type: '%', value: '40' },
|
|
126
132
|
},
|
|
127
133
|
],
|
|
128
134
|
} )
|
|
@@ -131,27 +137,27 @@ describe( 'It should serialize a gradient', () => {
|
|
|
131
137
|
expect(
|
|
132
138
|
serializeGradient( {
|
|
133
139
|
type: 'linear-gradient',
|
|
134
|
-
orientation: { type: 'angular', value: 0 },
|
|
140
|
+
orientation: { type: 'angular', value: '0' },
|
|
135
141
|
colorStops: [
|
|
136
142
|
{
|
|
137
143
|
type: 'rgba',
|
|
138
|
-
value: [ 1, 2, 3, 0.5 ],
|
|
139
|
-
length: { type: '%', value: 0 },
|
|
144
|
+
value: [ '1', '2', '3', '0.5' ],
|
|
145
|
+
length: { type: '%', value: '0' },
|
|
140
146
|
},
|
|
141
147
|
{
|
|
142
148
|
type: 'rgba',
|
|
143
|
-
value: [ 255, 1, 1, 0.9 ],
|
|
144
|
-
length: { type: '%', value: 40 },
|
|
149
|
+
value: [ '255', '1', '1', '0.9' ],
|
|
150
|
+
length: { type: '%', value: '40' },
|
|
145
151
|
},
|
|
146
152
|
{
|
|
147
153
|
type: 'rgba',
|
|
148
|
-
value: [ 1, 2, 3, 0.5 ],
|
|
149
|
-
length: { type: '%', value: 100 },
|
|
154
|
+
value: [ '1', '2', '3', '0.5' ],
|
|
155
|
+
length: { type: '%', value: '100' },
|
|
150
156
|
},
|
|
151
157
|
{
|
|
152
158
|
type: 'rgba',
|
|
153
|
-
value: [ 10, 20, 30, 0.5 ],
|
|
154
|
-
length: { type: '%', value: 20 },
|
|
159
|
+
value: [ '10', '20', '30', '0.5' ],
|
|
160
|
+
length: { type: '%', value: '20' },
|
|
155
161
|
},
|
|
156
162
|
],
|
|
157
163
|
} )
|