@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.
Files changed (328) hide show
  1. package/CHANGELOG.md +32 -4
  2. package/build/angle-picker-control/angle-circle.js +1 -4
  3. package/build/angle-picker-control/angle-circle.js.map +1 -1
  4. package/build/angle-picker-control/index.js +10 -22
  5. package/build/angle-picker-control/index.js.map +1 -1
  6. package/build/angle-picker-control/styles/angle-picker-control-styles.js +24 -15
  7. package/build/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
  8. package/build/animate/index.js +27 -19
  9. package/build/animate/index.js.map +1 -1
  10. package/build/animate/types.js.map +1 -0
  11. package/build/box-control/axial-input-controls.js.map +1 -1
  12. package/build/color-picker/color-input.js +0 -4
  13. package/build/color-picker/color-input.js.map +1 -1
  14. package/build/color-picker/component.js +5 -4
  15. package/build/color-picker/component.js.map +1 -1
  16. package/build/color-picker/hex-input.js.map +1 -1
  17. package/build/color-picker/hsl-input.js.map +1 -1
  18. package/build/color-picker/input-with-slider.js.map +1 -1
  19. package/build/color-picker/legacy-adapter.js.map +1 -1
  20. package/build/color-picker/picker.js.map +1 -1
  21. package/build/color-picker/rgb-input.js.map +1 -1
  22. package/build/color-picker/use-deprecated-props.js.map +1 -1
  23. package/build/custom-gradient-picker/constants.js +1 -1
  24. package/build/custom-gradient-picker/constants.js.map +1 -1
  25. package/build/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
  26. package/build/custom-gradient-picker/gradient-bar/control-points.js +9 -5
  27. package/build/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
  28. package/build/custom-gradient-picker/gradient-bar/index.js +14 -9
  29. package/build/custom-gradient-picker/gradient-bar/index.js.map +1 -1
  30. package/build/custom-gradient-picker/gradient-bar/utils.js +34 -54
  31. package/build/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
  32. package/build/custom-gradient-picker/index.js +45 -16
  33. package/build/custom-gradient-picker/index.js.map +1 -1
  34. package/build/custom-gradient-picker/serializer.js +14 -4
  35. package/build/custom-gradient-picker/serializer.js.map +1 -1
  36. package/build/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
  37. package/build/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
  38. package/build/custom-gradient-picker/types.js +6 -0
  39. package/build/custom-gradient-picker/types.js.map +1 -0
  40. package/build/custom-gradient-picker/utils.js +17 -12
  41. package/build/custom-gradient-picker/utils.js.map +1 -1
  42. package/build/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
  43. package/build/duotone-picker/color-list-picker/index.js.map +1 -0
  44. package/build/duotone-picker/color-list-picker/types.js +6 -0
  45. package/build/duotone-picker/color-list-picker/types.js.map +1 -0
  46. package/build/duotone-picker/custom-duotone-bar.js.map +1 -1
  47. package/build/duotone-picker/duotone-picker.js +39 -2
  48. package/build/duotone-picker/duotone-picker.js.map +1 -1
  49. package/build/duotone-picker/duotone-swatch.js.map +1 -1
  50. package/build/duotone-picker/index.js.map +1 -1
  51. package/build/duotone-picker/types.js +6 -0
  52. package/build/duotone-picker/types.js.map +1 -0
  53. package/build/duotone-picker/utils.js +13 -11
  54. package/build/duotone-picker/utils.js.map +1 -1
  55. package/build/form-token-field/index.js +9 -3
  56. package/build/form-token-field/index.js.map +1 -1
  57. package/build/gradient-picker/index.js +61 -9
  58. package/build/gradient-picker/index.js.map +1 -1
  59. package/build/gradient-picker/types.js +6 -0
  60. package/build/gradient-picker/types.js.map +1 -0
  61. package/build/palette-edit/index.js +1 -2
  62. package/build/palette-edit/index.js.map +1 -1
  63. package/build/resizable-box/resize-tooltip/utils.js.map +1 -1
  64. package/build/sandbox/index.native.js +80 -67
  65. package/build/sandbox/index.native.js.map +1 -1
  66. package/build/tab-panel/index.js +1 -1
  67. package/build/tab-panel/index.js.map +1 -1
  68. package/build/tools-panel/tools-panel/hook.js +45 -6
  69. package/build/tools-panel/tools-panel/hook.js.map +1 -1
  70. package/build/utils/input/input-control.js +1 -1
  71. package/build/utils/input/input-control.js.map +1 -1
  72. package/build-module/angle-picker-control/angle-circle.js +1 -4
  73. package/build-module/angle-picker-control/angle-circle.js.map +1 -1
  74. package/build-module/angle-picker-control/index.js +12 -21
  75. package/build-module/angle-picker-control/index.js.map +1 -1
  76. package/build-module/angle-picker-control/styles/angle-picker-control-styles.js +20 -13
  77. package/build-module/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
  78. package/build-module/animate/index.js +25 -17
  79. package/build-module/animate/index.js.map +1 -1
  80. package/build-module/box-control/axial-input-controls.js.map +1 -1
  81. package/build-module/color-picker/color-input.js +0 -4
  82. package/build-module/color-picker/color-input.js.map +1 -1
  83. package/build-module/color-picker/component.js +3 -3
  84. package/build-module/color-picker/component.js.map +1 -1
  85. package/build-module/color-picker/hex-input.js.map +1 -1
  86. package/build-module/color-picker/hsl-input.js.map +1 -1
  87. package/build-module/color-picker/input-with-slider.js.map +1 -1
  88. package/build-module/color-picker/legacy-adapter.js.map +1 -1
  89. package/build-module/color-picker/picker.js +4 -0
  90. package/build-module/color-picker/picker.js.map +1 -1
  91. package/build-module/color-picker/rgb-input.js.map +1 -1
  92. package/build-module/color-picker/use-deprecated-props.js.map +1 -1
  93. package/build-module/custom-gradient-picker/constants.js +1 -1
  94. package/build-module/custom-gradient-picker/constants.js.map +1 -1
  95. package/build-module/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
  96. package/build-module/custom-gradient-picker/gradient-bar/control-points.js +9 -4
  97. package/build-module/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
  98. package/build-module/custom-gradient-picker/gradient-bar/index.js +14 -8
  99. package/build-module/custom-gradient-picker/gradient-bar/index.js.map +1 -1
  100. package/build-module/custom-gradient-picker/gradient-bar/utils.js +34 -54
  101. package/build-module/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
  102. package/build-module/custom-gradient-picker/index.js +44 -17
  103. package/build-module/custom-gradient-picker/index.js.map +1 -1
  104. package/build-module/custom-gradient-picker/serializer.js +14 -4
  105. package/build-module/custom-gradient-picker/serializer.js.map +1 -1
  106. package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
  107. package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
  108. package/build-module/custom-gradient-picker/types.js +2 -0
  109. package/build-module/custom-gradient-picker/utils.js +17 -12
  110. package/build-module/custom-gradient-picker/utils.js.map +1 -1
  111. package/build-module/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
  112. package/build-module/duotone-picker/color-list-picker/index.js.map +1 -0
  113. package/build-module/duotone-picker/color-list-picker/types.js +2 -0
  114. package/build-module/duotone-picker/color-list-picker/types.js.map +1 -0
  115. package/build-module/duotone-picker/custom-duotone-bar.js.map +1 -1
  116. package/build-module/duotone-picker/duotone-picker.js +38 -2
  117. package/build-module/duotone-picker/duotone-picker.js.map +1 -1
  118. package/build-module/duotone-picker/duotone-swatch.js.map +1 -1
  119. package/build-module/duotone-picker/index.js.map +1 -1
  120. package/build-module/duotone-picker/types.js +2 -0
  121. package/build-module/duotone-picker/types.js.map +1 -0
  122. package/build-module/duotone-picker/utils.js +17 -11
  123. package/build-module/duotone-picker/utils.js.map +1 -1
  124. package/build-module/form-token-field/index.js +9 -4
  125. package/build-module/form-token-field/index.js.map +1 -1
  126. package/build-module/gradient-picker/index.js +61 -10
  127. package/build-module/gradient-picker/index.js.map +1 -1
  128. package/build-module/gradient-picker/types.js +2 -0
  129. package/build-module/gradient-picker/types.js.map +1 -0
  130. package/build-module/palette-edit/index.js +1 -2
  131. package/build-module/palette-edit/index.js.map +1 -1
  132. package/build-module/resizable-box/resize-tooltip/utils.js.map +1 -1
  133. package/build-module/sandbox/index.native.js +70 -58
  134. package/build-module/sandbox/index.native.js.map +1 -1
  135. package/build-module/tab-panel/index.js +2 -2
  136. package/build-module/tab-panel/index.js.map +1 -1
  137. package/build-module/tools-panel/tools-panel/hook.js +45 -6
  138. package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
  139. package/build-module/utils/input/input-control.js +1 -1
  140. package/build-module/utils/input/input-control.js.map +1 -1
  141. package/build-style/style-rtl.css +40 -28
  142. package/build-style/style.css +42 -28
  143. package/build-types/angle-picker-control/angle-circle.d.ts.map +1 -1
  144. package/build-types/angle-picker-control/index.d.ts.map +1 -1
  145. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +5 -0
  146. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts.map +1 -1
  147. package/build-types/animate/index.d.ts +27 -22
  148. package/build-types/animate/index.d.ts.map +1 -1
  149. package/build-types/animate/stories/index.d.ts +18 -0
  150. package/build-types/animate/stories/index.d.ts.map +1 -0
  151. package/build-types/animate/types.d.ts +30 -0
  152. package/build-types/animate/types.d.ts.map +1 -0
  153. package/build-types/color-picker/color-input.d.ts +1 -11
  154. package/build-types/color-picker/color-input.d.ts.map +1 -1
  155. package/build-types/color-picker/component.d.ts +8 -9
  156. package/build-types/color-picker/component.d.ts.map +1 -1
  157. package/build-types/color-picker/hex-input.d.ts +1 -10
  158. package/build-types/color-picker/hex-input.d.ts.map +1 -1
  159. package/build-types/color-picker/hsl-input.d.ts +1 -10
  160. package/build-types/color-picker/hsl-input.d.ts.map +1 -1
  161. package/build-types/color-picker/input-with-slider.d.ts +1 -9
  162. package/build-types/color-picker/input-with-slider.d.ts.map +1 -1
  163. package/build-types/color-picker/legacy-adapter.d.ts +1 -3
  164. package/build-types/color-picker/legacy-adapter.d.ts.map +1 -1
  165. package/build-types/color-picker/picker.d.ts +4 -7
  166. package/build-types/color-picker/picker.d.ts.map +1 -1
  167. package/build-types/color-picker/rgb-input.d.ts +1 -10
  168. package/build-types/color-picker/rgb-input.d.ts.map +1 -1
  169. package/build-types/color-picker/stories/index.d.ts +19 -0
  170. package/build-types/color-picker/stories/index.d.ts.map +1 -0
  171. package/build-types/color-picker/test/index.d.ts +2 -0
  172. package/build-types/color-picker/test/index.d.ts.map +1 -0
  173. package/build-types/color-picker/types.d.ts +105 -1
  174. package/build-types/color-picker/types.d.ts.map +1 -1
  175. package/build-types/color-picker/use-deprecated-props.d.ts +1 -44
  176. package/build-types/color-picker/use-deprecated-props.d.ts.map +1 -1
  177. package/build-types/custom-gradient-picker/constants.d.ts +8 -8
  178. package/build-types/custom-gradient-picker/constants.d.ts.map +1 -1
  179. package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts +7 -7
  180. package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts.map +1 -1
  181. package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts +5 -22
  182. package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts.map +1 -1
  183. package/build-types/custom-gradient-picker/gradient-bar/index.d.ts +3 -9
  184. package/build-types/custom-gradient-picker/gradient-bar/index.d.ts.map +1 -1
  185. package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts +2 -0
  186. package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts.map +1 -0
  187. package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts +44 -92
  188. package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts.map +1 -1
  189. package/build-types/custom-gradient-picker/index.d.ts +27 -6
  190. package/build-types/custom-gradient-picker/index.d.ts.map +1 -1
  191. package/build-types/custom-gradient-picker/serializer.d.ts +13 -16
  192. package/build-types/custom-gradient-picker/serializer.d.ts.map +1 -1
  193. package/build-types/custom-gradient-picker/stories/index.d.ts +12 -0
  194. package/build-types/custom-gradient-picker/stories/index.d.ts.map +1 -0
  195. package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts +3 -2
  196. package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts.map +1 -1
  197. package/build-types/custom-gradient-picker/test/serializer.d.ts +2 -0
  198. package/build-types/custom-gradient-picker/test/serializer.d.ts.map +1 -0
  199. package/build-types/custom-gradient-picker/types.d.ts +120 -0
  200. package/build-types/custom-gradient-picker/types.d.ts.map +1 -0
  201. package/build-types/custom-gradient-picker/utils.d.ts +12 -4
  202. package/build-types/custom-gradient-picker/utils.d.ts.map +1 -1
  203. package/build-types/duotone-picker/color-list-picker/index.d.ts.map +1 -0
  204. package/build-types/{color-list-picker → duotone-picker/color-list-picker}/types.d.ts +2 -2
  205. package/build-types/duotone-picker/color-list-picker/types.d.ts.map +1 -0
  206. package/build-types/duotone-picker/custom-duotone-bar.d.ts +6 -0
  207. package/build-types/duotone-picker/custom-duotone-bar.d.ts.map +1 -0
  208. package/build-types/duotone-picker/duotone-picker.d.ts +38 -0
  209. package/build-types/duotone-picker/duotone-picker.d.ts.map +1 -0
  210. package/build-types/duotone-picker/duotone-swatch.d.ts +5 -0
  211. package/build-types/duotone-picker/duotone-swatch.d.ts.map +1 -0
  212. package/build-types/duotone-picker/index.d.ts +3 -0
  213. package/build-types/duotone-picker/index.d.ts.map +1 -0
  214. package/build-types/duotone-picker/stories/duotone-picker.d.ts +12 -0
  215. package/build-types/duotone-picker/stories/duotone-picker.d.ts.map +1 -0
  216. package/build-types/duotone-picker/stories/duotone-swatch.d.ts +14 -0
  217. package/build-types/duotone-picker/stories/duotone-swatch.d.ts.map +1 -0
  218. package/build-types/duotone-picker/types.d.ts +60 -0
  219. package/build-types/duotone-picker/types.d.ts.map +1 -0
  220. package/build-types/duotone-picker/utils.d.ts +52 -0
  221. package/build-types/duotone-picker/utils.d.ts.map +1 -0
  222. package/build-types/form-token-field/index.d.ts.map +1 -1
  223. package/build-types/form-token-field/types.d.ts +6 -0
  224. package/build-types/form-token-field/types.d.ts.map +1 -1
  225. package/build-types/gradient-picker/index.d.ts +49 -11
  226. package/build-types/gradient-picker/index.d.ts.map +1 -1
  227. package/build-types/gradient-picker/stories/index.d.ts +14 -0
  228. package/build-types/gradient-picker/stories/index.d.ts.map +1 -0
  229. package/build-types/gradient-picker/types.d.ts +87 -0
  230. package/build-types/gradient-picker/types.d.ts.map +1 -0
  231. package/build-types/palette-edit/index.d.ts.map +1 -1
  232. package/build-types/resizable-box/resize-tooltip/utils.d.ts +1 -1
  233. package/build-types/resizable-box/resize-tooltip/utils.d.ts.map +1 -1
  234. package/build-types/tab-panel/index.d.ts.map +1 -1
  235. package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
  236. package/build-types/tools-panel/types.d.ts +1 -0
  237. package/build-types/tools-panel/types.d.ts.map +1 -1
  238. package/build-types/utils/input/input-control.d.ts.map +1 -1
  239. package/package.json +19 -19
  240. package/src/angle-picker-control/angle-circle.tsx +0 -1
  241. package/src/angle-picker-control/index.tsx +14 -27
  242. package/src/angle-picker-control/styles/angle-picker-control-styles.tsx +16 -9
  243. package/src/animate/index.tsx +75 -0
  244. package/src/animate/stories/index.tsx +102 -0
  245. package/src/animate/types.ts +32 -0
  246. package/src/border-box-control/stories/index.tsx +1 -1
  247. package/src/box-control/axial-input-controls.tsx +1 -1
  248. package/src/circular-option-picker/style.scss +10 -0
  249. package/src/color-indicator/style.scss +1 -0
  250. package/src/color-picker/README.md +2 -2
  251. package/src/color-picker/color-input.tsx +1 -12
  252. package/src/color-picker/component.tsx +9 -18
  253. package/src/color-picker/hex-input.tsx +2 -7
  254. package/src/color-picker/hsl-input.tsx +2 -7
  255. package/src/color-picker/input-with-slider.tsx +1 -9
  256. package/src/color-picker/legacy-adapter.tsx +1 -2
  257. package/src/color-picker/picker.tsx +5 -6
  258. package/src/color-picker/rgb-input.tsx +2 -7
  259. package/src/color-picker/stories/index.tsx +51 -0
  260. package/src/color-picker/test/{index.js → index.tsx} +36 -18
  261. package/src/color-picker/types.ts +128 -1
  262. package/src/color-picker/use-deprecated-props.ts +2 -53
  263. package/src/combobox-control/stories/index.tsx +1 -1
  264. package/src/custom-gradient-picker/{constants.js → constants.ts} +2 -2
  265. package/src/custom-gradient-picker/gradient-bar/{control-points.js → control-points.tsx} +171 -134
  266. package/src/custom-gradient-picker/gradient-bar/{index.js → index.tsx} +32 -10
  267. package/src/custom-gradient-picker/gradient-bar/test/{utils.js → utils.ts} +58 -31
  268. package/src/custom-gradient-picker/gradient-bar/utils.ts +193 -0
  269. package/src/custom-gradient-picker/{index.js → index.tsx} +63 -22
  270. package/src/custom-gradient-picker/serializer.ts +82 -0
  271. package/src/custom-gradient-picker/stories/index.tsx +45 -0
  272. package/src/custom-gradient-picker/style.scss +25 -4
  273. package/src/custom-gradient-picker/test/{serializer.js → serializer.ts} +39 -33
  274. package/src/custom-gradient-picker/types.ts +137 -0
  275. package/src/custom-gradient-picker/{utils.js → utils.ts} +37 -22
  276. package/src/custom-select-control/test/index.js +6 -4
  277. package/src/{color-list-picker → duotone-picker/color-list-picker}/index.tsx +7 -6
  278. package/src/{color-list-picker → duotone-picker/color-list-picker}/types.ts +2 -2
  279. package/src/duotone-picker/{custom-duotone-bar.js → custom-duotone-bar.tsx} +7 -1
  280. package/src/duotone-picker/{duotone-picker.js → duotone-picker.tsx} +39 -2
  281. package/src/duotone-picker/{duotone-swatch.js → duotone-swatch.tsx} +2 -1
  282. package/src/duotone-picker/stories/{duotone-picker.js → duotone-picker.tsx} +15 -8
  283. package/src/duotone-picker/stories/{duotone-swatch.js → duotone-swatch.tsx} +9 -3
  284. package/src/duotone-picker/types.ts +61 -0
  285. package/src/duotone-picker/{utils.js → utils.ts} +29 -14
  286. package/src/flex/flex-item/README.md +1 -1
  287. package/src/form-token-field/README.md +1 -0
  288. package/src/form-token-field/index.tsx +10 -3
  289. package/src/form-token-field/style.scss +0 -7
  290. package/src/form-token-field/test/index.tsx +1 -0
  291. package/src/form-token-field/types.ts +6 -0
  292. package/src/gradient-picker/README.md +16 -23
  293. package/src/gradient-picker/{index.js → index.tsx} +70 -16
  294. package/src/gradient-picker/stories/{index.js → index.tsx} +19 -8
  295. package/src/gradient-picker/types.ts +89 -0
  296. package/src/item-group/test/index.js +5 -3
  297. package/src/palette-edit/index.tsx +4 -5
  298. package/src/resizable-box/resize-tooltip/utils.ts +1 -1
  299. package/src/sandbox/index.native.js +71 -78
  300. package/src/slot-fill/test/slot.js +8 -6
  301. package/src/style.scss +1 -1
  302. package/src/tab-panel/index.tsx +7 -2
  303. package/src/tools-panel/test/index.tsx +86 -0
  304. package/src/tools-panel/tools-panel/hook.ts +44 -4
  305. package/src/tools-panel/types.ts +1 -0
  306. package/src/tooltip/test/index.js +251 -301
  307. package/src/utils/input/input-control.js +1 -0
  308. package/tsconfig.json +1 -2
  309. package/tsconfig.tsbuildinfo +1 -1
  310. package/build/color-list-picker/index.js.map +0 -1
  311. package/build-module/color-list-picker/index.js.map +0 -1
  312. package/build-types/color-list-picker/index.d.ts.map +0 -1
  313. package/build-types/color-list-picker/types.d.ts.map +0 -1
  314. package/src/animate/index.js +0 -60
  315. package/src/animate/stories/index.js +0 -53
  316. package/src/color-picker/stories/index.js +0 -41
  317. package/src/custom-gradient-picker/gradient-bar/utils.js +0 -189
  318. package/src/custom-gradient-picker/serializer.js +0 -48
  319. package/src/custom-gradient-picker/stories/index.js +0 -33
  320. /package/build/{color-list-picker → animate}/types.js +0 -0
  321. /package/build-module/{color-list-picker → animate}/types.js +0 -0
  322. /package/build-module/{color-list-picker → animate}/types.js.map +0 -0
  323. /package/{build/color-list-picker → build-module/custom-gradient-picker}/types.js.map +0 -0
  324. /package/build-types/{color-list-picker → duotone-picker/color-list-picker}/index.d.ts +0 -0
  325. /package/src/custom-gradient-picker/gradient-bar/{constants.js → constants.ts} +0 -0
  326. /package/src/custom-gradient-picker/styles/{custom-gradient-picker-styles.js → custom-gradient-picker-styles.tsx} +0 -0
  327. /package/src/{color-list-picker → duotone-picker/color-list-picker}/style.scss +0 -0
  328. /package/src/duotone-picker/{index.js → index.ts} +0 -0
@@ -15,36 +15,16 @@ exports.updateControlPointPosition = updateControlPointPosition;
15
15
 
16
16
  var _constants = require("./constants");
17
17
 
18
- // @ts-nocheck
19
-
20
18
  /**
21
19
  * Internal dependencies
22
20
  */
23
21
 
24
- /**
25
- * Control point for the gradient bar.
26
- *
27
- * @typedef {Object} ControlPoint
28
- * @property {string} color Color of the control point.
29
- * @property {number} position Integer position of the control point as a percentage.
30
- */
31
-
32
- /**
33
- * Color as parsed from the gradient by gradient-parser.
34
- *
35
- * @typedef {Object} Color
36
- * @property {string} r Red component.
37
- * @property {string} g Green component.
38
- * @property {string} b Green component.
39
- * @property {string} [a] Optional alpha component.
40
- */
41
-
42
22
  /**
43
23
  * Clamps a number between 0 and 100.
44
24
  *
45
- * @param {number} value Value to clamp.
25
+ * @param value Value to clamp.
46
26
  *
47
- * @return {number} Value clamped between 0 and 100.
27
+ * @return Value clamped between 0 and 100.
48
28
  */
49
29
  function clampPercent(value) {
50
30
  return Math.max(0, Math.min(100, value));
@@ -52,12 +32,12 @@ function clampPercent(value) {
52
32
  /**
53
33
  * Check if a control point is overlapping with another.
54
34
  *
55
- * @param {ControlPoint[]} value Array of control points.
56
- * @param {number} initialIndex Index of the position to test.
57
- * @param {number} newPosition New position of the control point.
58
- * @param {number} minDistance Distance considered to be overlapping.
35
+ * @param value Array of control points.
36
+ * @param initialIndex Index of the position to test.
37
+ * @param newPosition New position of the control point.
38
+ * @param minDistance Distance considered to be overlapping.
59
39
  *
60
- * @return {boolean} True if the point is overlapping.
40
+ * @return True if the point is overlapping.
61
41
  */
62
42
 
63
43
 
@@ -76,11 +56,11 @@ function isOverlapping(value, initialIndex, newPosition) {
76
56
  /**
77
57
  * Adds a control point from an array and returns the new array.
78
58
  *
79
- * @param {ControlPoint[]} points Array of control points.
80
- * @param {number} position Position to insert the new point.
81
- * @param {Color} color Color to update the control point at index.
59
+ * @param points Array of control points.
60
+ * @param position Position to insert the new point.
61
+ * @param color Color to update the control point at index.
82
62
  *
83
- * @return {ControlPoint[]} New array of control points.
63
+ * @return New array of control points.
84
64
  */
85
65
 
86
66
 
@@ -97,26 +77,26 @@ function addControlPoint(points, position, color) {
97
77
  /**
98
78
  * Removes a control point from an array and returns the new array.
99
79
  *
100
- * @param {ControlPoint[]} points Array of control points.
101
- * @param {number} index Index to remove.
80
+ * @param points Array of control points.
81
+ * @param index Index to remove.
102
82
  *
103
- * @return {ControlPoint[]} New array of control points.
83
+ * @return New array of control points.
104
84
  */
105
85
 
106
86
 
107
87
  function removeControlPoint(points, index) {
108
- return points.filter((point, pointIndex) => {
88
+ return points.filter((_point, pointIndex) => {
109
89
  return pointIndex !== index;
110
90
  });
111
91
  }
112
92
  /**
113
93
  * Updates a control point from an array and returns the new array.
114
94
  *
115
- * @param {ControlPoint[]} points Array of control points.
116
- * @param {number} index Index to update.
117
- * @param {ControlPoint[]} newPoint New control point to replace the index.
95
+ * @param points Array of control points.
96
+ * @param index Index to update.
97
+ * @param newPoint New control point to replace the index.
118
98
  *
119
- * @return {ControlPoint[]} New array of control points.
99
+ * @return New array of control points.
120
100
  */
121
101
 
122
102
 
@@ -128,11 +108,11 @@ function updateControlPoint(points, index, newPoint) {
128
108
  /**
129
109
  * Updates the position of a control point from an array and returns the new array.
130
110
  *
131
- * @param {ControlPoint[]} points Array of control points.
132
- * @param {number} index Index to update.
133
- * @param {number} newPosition Position to move the control point at index.
111
+ * @param points Array of control points.
112
+ * @param index Index to update.
113
+ * @param newPosition Position to move the control point at index.
134
114
  *
135
- * @return {ControlPoint[]} New array of control points.
115
+ * @return New array of control points.
136
116
  */
137
117
 
138
118
 
@@ -149,11 +129,11 @@ function updateControlPointPosition(points, index, newPosition) {
149
129
  /**
150
130
  * Updates the position of a control point from an array and returns the new array.
151
131
  *
152
- * @param {ControlPoint[]} points Array of control points.
153
- * @param {number} index Index to update.
154
- * @param {Color} newColor Color to update the control point at index.
132
+ * @param points Array of control points.
133
+ * @param index Index to update.
134
+ * @param newColor Color to update the control point at index.
155
135
  *
156
- * @return {ControlPoint[]} New array of control points.
136
+ * @return New array of control points.
157
137
  */
158
138
 
159
139
 
@@ -166,11 +146,11 @@ function updateControlPointColor(points, index, newColor) {
166
146
  /**
167
147
  * Updates the position of a control point from an array and returns the new array.
168
148
  *
169
- * @param {ControlPoint[]} points Array of control points.
170
- * @param {number} position Position of the color stop.
171
- * @param {string} newColor Color to update the control point at index.
149
+ * @param points Array of control points.
150
+ * @param position Position of the color stop.
151
+ * @param newColor Color to update the control point at index.
172
152
  *
173
- * @return {ControlPoint[]} New array of control points.
153
+ * @return New array of control points.
174
154
  */
175
155
 
176
156
 
@@ -181,10 +161,10 @@ function updateControlPointColorByPosition(points, position, newColor) {
181
161
  /**
182
162
  * Gets the horizontal coordinate when dragging a control point with the mouse.
183
163
  *
184
- * @param {number} mouseXCoordinate Horizontal coordinate of the mouse position.
185
- * @param {Element} containerElement Container for the gradient picker.
164
+ * @param mouseXcoordinate Horizontal coordinate of the mouse position.
165
+ * @param containerElement Container for the gradient picker.
186
166
  *
187
- * @return {number | undefined} Whole number percentage from the left.
167
+ * @return Whole number percentage from the left.
188
168
  */
189
169
 
190
170
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/gradient-bar/utils.js"],"names":["clampPercent","value","Math","max","min","isOverlapping","initialIndex","newPosition","minDistance","MINIMUM_DISTANCE_BETWEEN_POINTS","initialPosition","position","minPosition","maxPosition","some","index","abs","addControlPoint","points","color","nextIndex","findIndex","point","newPoint","newPoints","slice","splice","removeControlPoint","filter","pointIndex","updateControlPoint","newValue","updateControlPointPosition","updateControlPointColor","newColor","updateControlPointColorByPosition","getHorizontalRelativeGradientPosition","mouseXCoordinate","containerElement","x","width","getBoundingClientRect","absolutePositionValue","round"],"mappings":";;;;;;;;;;;;;;;AAKA;;AALA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,CAAuBC,KAAvB,EAA+B;AACrC,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;;;AACO,SAASI,aAAT,CACNJ,KADM,EAENK,YAFM,E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AAiBmB,QAAjB,CAA9B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,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":["// @ts-nocheck\n\n/**\n * Internal dependencies\n */\nimport { MINIMUM_DISTANCE_BETWEEN_POINTS } from './constants';\n\n/**\n * Control point for the gradient bar.\n *\n * @typedef {Object} ControlPoint\n * @property {string} color Color of the control point.\n * @property {number} position Integer position of the control point as a percentage.\n */\n\n/**\n * Color as parsed from the gradient by gradient-parser.\n *\n * @typedef {Object} Color\n * @property {string} r Red component.\n * @property {string} g Green component.\n * @property {string} b Green component.\n * @property {string} [a] Optional alpha component.\n */\n\n/**\n * Clamps a number between 0 and 100.\n *\n * @param {number} value Value to clamp.\n *\n * @return {number} Value clamped between 0 and 100.\n */\nexport function clampPercent( value ) {\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 {ControlPoint[]} value Array of control points.\n * @param {number} initialIndex Index of the position to test.\n * @param {number} newPosition New position of the control point.\n * @param {number} minDistance Distance considered to be overlapping.\n *\n * @return {boolean} True if the point is overlapping.\n */\nexport function isOverlapping(\n\tvalue,\n\tinitialIndex,\n\tnewPosition,\n\tminDistance = 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 {ControlPoint[]} points Array of control points.\n * @param {number} position Position to insert the new point.\n * @param {Color} color Color to update the control point at index.\n *\n * @return {ControlPoint[]} New array of control points.\n */\nexport function addControlPoint( points, position, color ) {\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 {ControlPoint[]} points Array of control points.\n * @param {number} index Index to remove.\n *\n * @return {ControlPoint[]} New array of control points.\n */\nexport function removeControlPoint( points, index ) {\n\treturn points.filter( ( point, pointIndex ) => {\n\t\treturn pointIndex !== index;\n\t} );\n}\n\n/**\n * Updates a control point from an array and returns the new array.\n *\n * @param {ControlPoint[]} points Array of control points.\n * @param {number} index Index to update.\n * @param {ControlPoint[]} newPoint New control point to replace the index.\n *\n * @return {ControlPoint[]} New array of control points.\n */\nexport function updateControlPoint( points, index, newPoint ) {\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 {ControlPoint[]} points Array of control points.\n * @param {number} index Index to update.\n * @param {number} newPosition Position to move the control point at index.\n *\n * @return {ControlPoint[]} New array of control points.\n */\nexport function updateControlPointPosition( points, index, newPosition ) {\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 {ControlPoint[]} points Array of control points.\n * @param {number} index Index to update.\n * @param {Color} newColor Color to update the control point at index.\n *\n * @return {ControlPoint[]} New array of control points.\n */\nexport function updateControlPointColor( points, index, newColor ) {\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 {ControlPoint[]} points Array of control points.\n * @param {number} position Position of the color stop.\n * @param {string} newColor Color to update the control point at index.\n *\n * @return {ControlPoint[]} New array of control points.\n */\nexport function updateControlPointColorByPosition(\n\tpoints,\n\tposition,\n\tnewColor\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 {number} mouseXCoordinate Horizontal coordinate of the mouse position.\n * @param {Element} containerElement Container for the gradient picker.\n *\n * @return {number | undefined} Whole number percentage from the left.\n */\nexport function getHorizontalRelativeGradientPosition(\n\tmouseXCoordinate,\n\tcontainerElement\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
+ {"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/gradient-bar/utils.ts"],"names":["clampPercent","value","Math","max","min","isOverlapping","initialIndex","newPosition","minDistance","MINIMUM_DISTANCE_BETWEEN_POINTS","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":";;;;;;;;;;;;;;;AAGA;;AAHA;AACA;AAC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AACA;AACA;AACA;;;AACO,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;;;AASO,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,SAAOtC,IAAI,CAAC0C,KAAL,CACN5C,YAAY,CAAI2C,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"]}
@@ -5,7 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = CustomGradientPicker;
8
+ exports.CustomGradientPicker = CustomGradientPicker;
9
+ exports.default = void 0;
9
10
 
10
11
  var _element = require("@wordpress/element");
11
12
 
@@ -33,8 +34,6 @@ var _constants = require("./constants");
33
34
 
34
35
  var _customGradientPickerStyles = require("./styles/custom-gradient-picker-styles");
35
36
 
36
- // @ts-nocheck
37
-
38
37
  /**
39
38
  * External dependencies
40
39
  */
@@ -60,7 +59,7 @@ const GradientAnglePicker = _ref => {
60
59
  onChange((0, _serializer.serializeGradient)({ ...gradientAST,
61
60
  orientation: {
62
61
  type: 'angular',
63
- value: newAngle
62
+ value: `${newAngle}`
64
63
  }
65
64
  }));
66
65
  };
@@ -84,9 +83,7 @@ const GradientTypePicker = _ref2 => {
84
83
 
85
84
  const onSetLinearGradient = () => {
86
85
  onChange((0, _serializer.serializeGradient)({ ...gradientAST,
87
- ...(gradientAST.orientation ? {} : {
88
- orientation: _constants.HORIZONTAL_GRADIENT_ORIENTATION
89
- }),
86
+ orientation: gradientAST.orientation ? undefined : _constants.HORIZONTAL_GRADIENT_ORIENTATION,
90
87
  type: 'linear-gradient'
91
88
  }));
92
89
  };
@@ -119,9 +116,31 @@ const GradientTypePicker = _ref2 => {
119
116
  onChange: handleOnChange,
120
117
  options: _constants.GRADIENT_OPTIONS,
121
118
  size: "__unstable-large",
122
- value: hasGradient && type
119
+ value: hasGradient ? type : undefined
123
120
  });
124
121
  };
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
+
125
144
 
126
145
  function CustomGradientPicker(_ref3) {
127
146
  let {
@@ -129,20 +148,27 @@ function CustomGradientPicker(_ref3) {
129
148
  __nextHasNoMargin = false,
130
149
  value,
131
150
  onChange,
132
- __experimentalIsRenderedInSidebar
151
+ __experimentalIsRenderedInSidebar = false
133
152
  } = _ref3;
134
- const gradientAST = (0, _utils.getGradientAstWithDefault)(value); // On radial gradients the bar should display a linear gradient.
153
+ const {
154
+ gradientAST,
155
+ hasGradient
156
+ } = (0, _utils.getGradientAstWithDefault)(value); // On radial gradients the bar should display a linear gradient.
135
157
  // On radial gradients the bar represents a slice of the gradient from the center until the outside.
136
158
  // On liner gradients the bar represents the color stops from left to right independently of the angle.
137
159
 
138
- const background = (0, _utils.getLinearGradientRepresentation)(gradientAST);
139
- const hasGradient = gradientAST.value !== _constants.DEFAULT_GRADIENT; // Control points color option may be hex from presets, custom colors will be rgb.
160
+ const background = (0, _utils.getLinearGradientRepresentation)(gradientAST); // Control points color option may be hex from presets, custom colors will be rgb.
140
161
  // The position should always be a percentage.
141
162
 
142
- const controlPoints = gradientAST.colorStops.map(colorStop => ({
143
- color: (0, _utils.getStopCssColor)(colorStop),
144
- position: parseInt(colorStop.length.value)
145
- }));
163
+ const controlPoints = gradientAST.colorStops.map(colorStop => {
164
+ return {
165
+ color: (0, _utils.getStopCssColor)(colorStop),
166
+ // Although it's already been checked by `hasUnsupportedLength` in `getGradientAstWithDefault`,
167
+ // TypeScript doesn't know that `colorStop.length` is not undefined here.
168
+ // @ts-expect-error
169
+ position: parseInt(colorStop.length.value)
170
+ };
171
+ });
146
172
 
147
173
  if (!__nextHasNoMargin) {
148
174
  (0, _deprecated.default)('Outer margin styles for wp.components.CustomGradientPicker', {
@@ -178,4 +204,7 @@ function CustomGradientPicker(_ref3) {
178
204
  onChange: onChange
179
205
  }))));
180
206
  }
207
+
208
+ var _default = CustomGradientPicker;
209
+ exports.default = _default;
181
210
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/index.js"],"names":["GradientAnglePicker","gradientAST","hasGradient","onChange","angle","orientation","value","DEFAULT_LINEAR_GRADIENT_ANGLE","onAngleChange","newAngle","type","GradientTypePicker","onSetLinearGradient","HORIZONTAL_GRADIENT_ORIENTATION","onSetRadialGradient","restGradientAST","handleOnChange","next","GRADIENT_OPTIONS","CustomGradientPicker","__nextHasNoMargin","__experimentalIsRenderedInSidebar","background","DEFAULT_GRADIENT","controlPoints","colorStops","map","colorStop","color","position","parseInt","length","since","version","hint","newControlPoints"],"mappings":";;;;;;;;;;;AAKA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AAMA;;AAlCA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AAwBA,MAAMA,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,yEACyBC,wCADpC;;AAEA,QAAMC,aAAa,GAAKC,QAAF,IAAgB;AACrCN,IAAAA,QAAQ,CACP,mCAAmB,EAClB,GAAGF,WADe;AAElBI,MAAAA,WAAW,EAAE;AACZK,QAAAA,IAAI,EAAE,SADM;AAEZJ,QAAAA,KAAK,EAAEG;AAFK;AAFK,KAAnB,CADO,CAAR;AASA,GAVD;;AAWA,SACC,4BAAC,2BAAD;AACC,IAAA,uBAAuB,MADxB;AAEC,IAAA,QAAQ,EAAGD,aAFZ;AAGC,IAAA,KAAK,EAAGN,WAAW,GAAGE,KAAH,GAAW;AAH/B,IADD;AAOA,CArBD;;AAuBA,MAAMO,kBAAkB,GAAG,SAA8C;AAAA,MAA5C;AAAEV,IAAAA,WAAF;AAAeC,IAAAA,WAAf;AAA4BC,IAAAA;AAA5B,GAA4C;AACxE,QAAM;AAAEO,IAAAA;AAAF,MAAWT,WAAjB;;AACA,QAAMW,mBAAmB,GAAG,MAAM;AACjCT,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GC,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":["GradientAnglePicker","gradientAST","hasGradient","onChange","angle","orientation","value","DEFAULT_LINEAR_GRADIENT_ANGLE","onAngleChange","newAngle","type","GradientTypePicker","onSetLinearGradient","undefined","HORIZONTAL_GRADIENT_ORIENTATION","onSetRadialGradient","restGradientAST","handleOnChange","next","GRADIENT_OPTIONS","CustomGradientPicker","__nextHasNoMargin","__experimentalIsRenderedInSidebar","background","controlPoints","colorStops","map","colorStop","color","position","parseInt","length","since","version","hint","newControlPoints"],"mappings":";;;;;;;;;;;;AAGA;;AAMA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AAKA;;AAhCA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AA4BA,MAAMA,mBAAmB,GAAG,QAIK;AAAA;;AAAA,MAJH;AAC7BC,IAAAA,WAD6B;AAE7BC,IAAAA,WAF6B;AAG7BC,IAAAA;AAH6B,GAIG;AAChC,QAAMC,KAAK,4BACVH,WADU,aACVA,WADU,iDACVA,WAAW,CAAEI,WADH,2DACV,uBAA0BC,KADhB,yEACyBC,wCADpC;;AAEA,QAAMC,aAAa,GAAKC,QAAF,IAAwB;AAC7CN,IAAAA,QAAQ,CACP,mCAAmB,EAClB,GAAGF,WADe;AAElBI,MAAAA,WAAW,EAAE;AACZK,QAAAA,IAAI,EAAE,SADM;AAEZJ,QAAAA,KAAK,EAAG,GAAGG,QAAU;AAFT;AAFK,KAAnB,CADO,CAAR;AASA,GAVD;;AAWA,SACC,4BAAC,2BAAD;AACC,IAAA,uBAAuB,MADxB;AAEC,IAAA,QAAQ,EAAGD,aAFZ;AAGC,IAAA,KAAK,EAAGN,WAAW,GAAGE,KAAH,GAAW;AAH/B,IADD;AA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D;AACC,IAAA,GAAG,EAAG,CADP;AAEC,IAAA,SAAS,EAAC;AAFX,KAIC,4BAAC,yCAAD,QACC,4BAAC,kBAAD;AACC,IAAA,WAAW,EAAGlC,WADf;AAEC,IAAA,WAAW,EAAGC,WAFf;AAGC,IAAA,QAAQ,EAAGC;AAHZ,IADD,CAJD,EAWC,4BAAC,4CAAD,QACGF,WAAW,CAACS,IAAZ,KAAqB,iBAArB,IACD,4BAAC,mBAAD;AACC,IAAA,WAAW,EAAGT,WADf;AAEC,IAAA,WAAW,EAAGC,WAFf;AAGC,IAAA,QAAQ,EAAGC;AAHZ,IAFF,CAXD,CAxBD,CADD;AAgDA;;eAEciB,oB","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"]}
@@ -9,7 +9,13 @@ exports.serializeGradientColorStop = serializeGradientColorStop;
9
9
  exports.serializeGradientOrientation = serializeGradientOrientation;
10
10
  exports.serializeGradientPosition = serializeGradientPosition;
11
11
 
12
- // @ts-nocheck
12
+ /**
13
+ * External dependencies
14
+ */
15
+
16
+ /**
17
+ * Internal dependencies
18
+ */
13
19
  function serializeGradientColor(_ref) {
14
20
  let {
15
21
  type,
@@ -52,7 +58,7 @@ function serializeGradientColorStop(_ref2) {
52
58
  }
53
59
 
54
60
  function serializeGradientOrientation(orientation) {
55
- if (!orientation || orientation.type !== 'angular') {
61
+ if (Array.isArray(orientation) || !orientation || orientation.type !== 'angular') {
56
62
  return;
57
63
  }
58
64
 
@@ -67,9 +73,13 @@ function serializeGradient(_ref3) {
67
73
  } = _ref3;
68
74
  const serializedOrientation = serializeGradientOrientation(orientation);
69
75
  const serializedColorStops = colorStops.sort((colorStop1, colorStop2) => {
70
- var _colorStop1$length$va, _colorStop1$length, _colorStop2$length$va, _colorStop2$length;
76
+ const getNumericStopValue = colorStop => {
77
+ var _colorStop$length;
78
+
79
+ 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);
80
+ };
71
81
 
72
- return ((_colorStop1$length$va = colorStop1 === null || colorStop1 === void 0 ? void 0 : (_colorStop1$length = colorStop1.length) === null || _colorStop1$length === void 0 ? void 0 : _colorStop1$length.value) !== null && _colorStop1$length$va !== void 0 ? _colorStop1$length$va : 0) - ((_colorStop2$length$va = colorStop2 === null || colorStop2 === void 0 ? void 0 : (_colorStop2$length = colorStop2.length) === null || _colorStop2$length === void 0 ? void 0 : _colorStop2$length.value) !== null && _colorStop2$length$va !== void 0 ? _colorStop2$length$va : 0);
82
+ return getNumericStopValue(colorStop1) - getNumericStopValue(colorStop2);
73
83
  }).map(serializeGradientColorStop);
74
84
  return `${type}(${[serializedOrientation, ...serializedColorStops].filter(Boolean).join(',')})`;
75
85
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/serializer.js"],"names":["serializeGradientColor","type","value","join","serializeGradientPosition","position","serializeGradientColorStop","length","serializeGradientOrientation","orientation","serializeGradient","col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GF,UAAU,CACrCG,IAD2B,CACrB,CAAEC,UAAF,EAAcC,UAAd,KAA8B;AAAA;;AACpC,WACC,0BAAED,UAAF,aAAEA,UAAF,6CAAEA,UAAU,CAAER,MAAd,uDAAE,mBAAoBL,KAAtB,yEAA+B,CAA/B,8BACEc,UADF,aACEA,UADF,6CACEA,UAAU,CAAET,MADd,uDACE,mBAAoBL,KADtB,yEAC+B,CAD/B,CADD;AAIA,GAN2B,EAO3Be,GAP2B,CAOtBX,0BAPsB,CAA7B;AAQA,SAAQ,GAAGL,IAAM,IAAI,CAAEW,qBAAF,EAAyB,GAAGC,oBAA5B,EACnBK,MADmB,CACXC,OADW,EAEnBhB,IAFmB,CAEb,GAFa,CAEN,GAFf;AAGA","sourcesContent":["// @ts-nocheck\n\nexport function serializeGradientColor( { type, value } ) {\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( position ) {\n\tif ( ! position ) {\n\t\treturn '';\n\t}\n\tconst { value, type } = position;\n\treturn `${ value }${ type }`;\n}\n\nexport function serializeGradientColorStop( { type, value, length } ) {\n\treturn `${ serializeGradientColor( {\n\t\ttype,\n\t\tvalue,\n\t} ) } ${ serializeGradientPosition( length ) }`;\n}\n\nexport function serializeGradientOrientation( orientation ) {\n\tif ( ! orientation || orientation.type !== 'angular' ) {\n\t\treturn;\n\t}\n\treturn `${ orientation.value }deg`;\n}\n\nexport function serializeGradient( { type, orientation, colorStops } ) {\n\tconst serializedOrientation = serializeGradientOrientation( orientation );\n\tconst serializedColorStops = colorStops\n\t\t.sort( ( colorStop1, colorStop2 ) => {\n\t\t\treturn (\n\t\t\t\t( colorStop1?.length?.value ?? 0 ) -\n\t\t\t\t( colorStop2?.length?.value ?? 0 )\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"]}
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;;AAEA;AACA;AACA;AAGO,SAASA,sBAAT,OAGoB;AAAA,MAHa;AACvCC,IAAAA,IADuC;AAEvCC,IAAAA;AAFuC,GAGb;;AAC1B,MAAKD,IAAI,KAAK,SAAd,EAA0B;AACzB,WAAOC,KAAP;AACA;;AACD,MAAKD,IAAI,KAAK,KAAd,EAAsB;AACrB,WAAQ,IAAIC,KAAO,EAAnB;AACA;;AACD,SAAQ,GAAGD,IAAM,IAAIC,KAAK,CAACC,IAAN,CAAY,GAAZ,CAAmB,GAAxC;AACA;;AAEM,SAASC,yBAAT,CACNC,QADM,EAEL;AACD,MAAK,CAAEA,QAAP,EAAkB;AACjB,WAAO,EAAP;AACA;;AACD,QAAM;AAAEH,IAAAA,KAAF;AAASD,IAAAA;AAAT,MAAkBI,QAAxB;AACA,SAAQ,GAAGH,KAAO,GAAGD,IAAM,EAA3B;AACA;;AAEM,SAASK,0BAAT,QAIuB;AAAA,MAJc;AAC3CL,IAAAA,IAD2C;AAE3CC,IAAAA,KAF2C;AAG3CK,IAAAA;AAH2C,GAId;AAC7B,SAAQ,GAAGP,sBAAsB,CAAE;AAClCC,IAAAA,IADkC;AAElCC,IAAAA;AAFkC,GAAF,CAGH,IAAIE,yBAAyB,CAAEG,MAAF,CAAY,EAHvE;AAIA;;AAEM,SAASC,4BAAT,CACNC,WADM,EAEL;AACD,MACCC,KAAK,CAACC,OAAN,CAAeF,WAAf,KACA,CAAEA,WADF,IAEAA,WAAW,CAACR,IAAZ,KAAqB,SAHtB,EAIE;AACD;AACA;;AACD,SAAQ,GAAGQ,WAAW,CAACP,KAAO,KAA9B;AACA;;AAEM,SAASU,iBAAT,QAI0B;AAAA,MAJE;AAClCX,IAAAA,IADkC;AAElCQ,IAAAA,WAFkC;AAGlCI,IAAAA;AAHkC,GAIF;AAChC,QAAMC,qBAAqB,GAAGN,4BAA4B,CAAEC,WAAF,CAA1D;AACA,QAAMM,oBAAoB,GAAGF,UAAU,CACrCG,IAD2B,CACrB,CAAEC,UAAF,EAAcC,UAAd,KAA8B;AACpC,UAAMC,mBAAmB,GACxBC,SAD2B,IAEvB;AAAA;;AACJ,aAAO,CAAAA,SAAS,SAAT,IAAAA,SAAS,WAAT,iCAAAA,SAAS,CAAEb,MAAX,wEAAmBL,KAAnB,MAA6BmB,SAA7B,GACJ,CADI,GAEJC,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/**\n * Internal dependencies\n */\nimport type { ColorStopTypeAndValue } from './types';\n\nexport function serializeGradientColor( {\n\ttype,\n\tvalue,\n}: ColorStopTypeAndValue ) {\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 ColorStopTypeAndValue ) } ${ 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"]}
@@ -14,9 +14,9 @@ var _flex = require("../../flex");
14
14
  function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
15
15
 
16
16
  const SelectWrapper = ( /*#__PURE__*/0, _base.default)(_flex.FlexBlock, process.env.NODE_ENV === "production" ? {
17
- target: "e99xvul1"
17
+ target: "e10bzpgi1"
18
18
  } : {
19
- target: "e99xvul1",
19
+ target: "e10bzpgi1",
20
20
  label: "SelectWrapper"
21
21
  })(process.env.NODE_ENV === "production" ? {
22
22
  name: "1gvx10y",
@@ -24,14 +24,14 @@ const SelectWrapper = ( /*#__PURE__*/0, _base.default)(_flex.FlexBlock, process.
24
24
  } : {
25
25
  name: "1gvx10y",
26
26
  styles: "flex-grow:5",
27
- map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci9zdHlsZXMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci1zdHlsZXMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBU2dEIiwiZmlsZSI6IkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci9zdHlsZXMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci1zdHlsZXMuanMiLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIEV4dGVybmFsIGRlcGVuZGVuY2llc1xuICovXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCc7XG4vKipcbiAqIEludGVybmFsIGRlcGVuZGVuY2llc1xuICovXG5pbXBvcnQgeyBGbGV4QmxvY2sgfSBmcm9tICcuLi8uLi9mbGV4JztcblxuZXhwb3J0IGNvbnN0IFNlbGVjdFdyYXBwZXIgPSBzdHlsZWQoIEZsZXhCbG9jayApYFxuXHRmbGV4LWdyb3c6IDU7XG5gO1xuXG5leHBvcnQgY29uc3QgQWNjZXNzb3J5V3JhcHBlciA9IHN0eWxlZCggRmxleEJsb2NrIClgXG5cdGZsZXgtZ3JvdzogNTtcbmA7XG4iXX0= */",
27
+ map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci9zdHlsZXMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci1zdHlsZXMudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVNnRCIsImZpbGUiOiJAd29yZHByZXNzL2NvbXBvbmVudHMvc3JjL2N1c3RvbS1ncmFkaWVudC1waWNrZXIvc3R5bGVzL2N1c3RvbS1ncmFkaWVudC1waWNrZXItc3R5bGVzLnRzeCIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogRXh0ZXJuYWwgZGVwZW5kZW5jaWVzXG4gKi9cbmltcG9ydCBzdHlsZWQgZnJvbSAnQGVtb3Rpb24vc3R5bGVkJztcbi8qKlxuICogSW50ZXJuYWwgZGVwZW5kZW5jaWVzXG4gKi9cbmltcG9ydCB7IEZsZXhCbG9jayB9IGZyb20gJy4uLy4uL2ZsZXgnO1xuXG5leHBvcnQgY29uc3QgU2VsZWN0V3JhcHBlciA9IHN0eWxlZCggRmxleEJsb2NrIClgXG5cdGZsZXgtZ3JvdzogNTtcbmA7XG5cbmV4cG9ydCBjb25zdCBBY2Nlc3NvcnlXcmFwcGVyID0gc3R5bGVkKCBGbGV4QmxvY2sgKWBcblx0ZmxleC1ncm93OiA1O1xuYDtcbiJdfQ== */",
28
28
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
29
29
  });
30
30
  exports.SelectWrapper = SelectWrapper;
31
31
  const AccessoryWrapper = ( /*#__PURE__*/0, _base.default)(_flex.FlexBlock, process.env.NODE_ENV === "production" ? {
32
- target: "e99xvul0"
32
+ target: "e10bzpgi0"
33
33
  } : {
34
- target: "e99xvul0",
34
+ target: "e10bzpgi0",
35
35
  label: "AccessoryWrapper"
36
36
  })(process.env.NODE_ENV === "production" ? {
37
37
  name: "1gvx10y",
@@ -39,7 +39,7 @@ const AccessoryWrapper = ( /*#__PURE__*/0, _base.default)(_flex.FlexBlock, proce
39
39
  } : {
40
40
  name: "1gvx10y",
41
41
  styles: "flex-grow:5",
42
- map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci9zdHlsZXMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci1zdHlsZXMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBYW1EIiwiZmlsZSI6IkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci9zdHlsZXMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci1zdHlsZXMuanMiLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIEV4dGVybmFsIGRlcGVuZGVuY2llc1xuICovXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCc7XG4vKipcbiAqIEludGVybmFsIGRlcGVuZGVuY2llc1xuICovXG5pbXBvcnQgeyBGbGV4QmxvY2sgfSBmcm9tICcuLi8uLi9mbGV4JztcblxuZXhwb3J0IGNvbnN0IFNlbGVjdFdyYXBwZXIgPSBzdHlsZWQoIEZsZXhCbG9jayApYFxuXHRmbGV4LWdyb3c6IDU7XG5gO1xuXG5leHBvcnQgY29uc3QgQWNjZXNzb3J5V3JhcHBlciA9IHN0eWxlZCggRmxleEJsb2NrIClgXG5cdGZsZXgtZ3JvdzogNTtcbmA7XG4iXX0= */",
42
+ map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci9zdHlsZXMvY3VzdG9tLWdyYWRpZW50LXBpY2tlci1zdHlsZXMudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWFtRCIsImZpbGUiOiJAd29yZHByZXNzL2NvbXBvbmVudHMvc3JjL2N1c3RvbS1ncmFkaWVudC1waWNrZXIvc3R5bGVzL2N1c3RvbS1ncmFkaWVudC1waWNrZXItc3R5bGVzLnRzeCIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogRXh0ZXJuYWwgZGVwZW5kZW5jaWVzXG4gKi9cbmltcG9ydCBzdHlsZWQgZnJvbSAnQGVtb3Rpb24vc3R5bGVkJztcbi8qKlxuICogSW50ZXJuYWwgZGVwZW5kZW5jaWVzXG4gKi9cbmltcG9ydCB7IEZsZXhCbG9jayB9IGZyb20gJy4uLy4uL2ZsZXgnO1xuXG5leHBvcnQgY29uc3QgU2VsZWN0V3JhcHBlciA9IHN0eWxlZCggRmxleEJsb2NrIClgXG5cdGZsZXgtZ3JvdzogNTtcbmA7XG5cbmV4cG9ydCBjb25zdCBBY2Nlc3NvcnlXcmFwcGVyID0gc3R5bGVkKCBGbGV4QmxvY2sgKWBcblx0ZmxleC1ncm93OiA1O1xuYDtcbiJdfQ== */",
43
43
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
44
44
  });
45
45
  exports.AccessoryWrapper = AccessoryWrapper;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/styles/custom-gradient-picker-styles.js"],"names":["SelectWrapper","FlexBlock","AccessoryWrapper"],"mappings":";;;;;;;;;;;AAOA;;;;AAEO,MAAMA,aAAa,GAAG,iCAAQC,eAAR;AAAA;AAAA;AAAA;AAAA;AAAA,EAAH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAnB;;AAIA,MAAMC,gBAAgB,GAAG,iCAAQD,eAAR;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
+ {"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/styles/custom-gradient-picker-styles.tsx"],"names":["SelectWrapper","FlexBlock","AccessoryWrapper"],"mappings":";;;;;;;;;;;AAOA;;;;AAEO,MAAMA,aAAa,GAAG,iCAAQC,eAAR;AAAA;AAAA;AAAA;AAAA;AAAA,EAAH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAnB;;AAIA,MAAMC,gBAAgB,GAAG,iCAAQD,eAAR;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"]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -20,8 +20,6 @@ var _constants = require("./constants");
20
20
 
21
21
  var _serializer = require("./serializer");
22
22
 
23
- // @ts-nocheck
24
-
25
23
  /**
26
24
  * External dependencies
27
25
  */
@@ -49,18 +47,23 @@ function getGradientAstWithDefault(value) {
49
47
  // gradientAST will contain the gradient AST as parsed by gradient-parser npm module.
50
48
  // More information of its structure available at https://www.npmjs.com/package/gradient-parser#ast.
51
49
  let gradientAST;
50
+ let hasGradient = !!value;
51
+ const valueToParse = value !== null && value !== void 0 ? value : _constants.DEFAULT_GRADIENT;
52
52
 
53
53
  try {
54
- gradientAST = _gradientParser.default.parse(value)[0];
55
- gradientAST.value = value;
54
+ gradientAST = _gradientParser.default.parse(valueToParse)[0];
56
55
  } catch (error) {
56
+ // eslint-disable-next-line no-console
57
+ console.warn('wp.components.CustomGradientPicker failed to parse the gradient with error', error);
57
58
  gradientAST = _gradientParser.default.parse(_constants.DEFAULT_GRADIENT)[0];
58
- gradientAST.value = _constants.DEFAULT_GRADIENT;
59
+ hasGradient = false;
59
60
  }
60
61
 
61
- if (((_gradientAST$orientat = gradientAST.orientation) === null || _gradientAST$orientat === void 0 ? void 0 : _gradientAST$orientat.type) === 'directional') {
62
- gradientAST.orientation.type = 'angular';
63
- gradientAST.orientation.value = _constants.DIRECTIONAL_ORIENTATION_ANGLE_MAP[gradientAST.orientation.value].toString();
62
+ if (!Array.isArray(gradientAST.orientation) && ((_gradientAST$orientat = gradientAST.orientation) === null || _gradientAST$orientat === void 0 ? void 0 : _gradientAST$orientat.type) === 'directional') {
63
+ gradientAST.orientation = {
64
+ type: 'angular',
65
+ value: _constants.DIRECTIONAL_ORIENTATION_ANGLE_MAP[gradientAST.orientation.value].toString()
66
+ };
64
67
  }
65
68
 
66
69
  if (gradientAST.colorStops.some(hasUnsupportedLength)) {
@@ -70,14 +73,16 @@ function getGradientAstWithDefault(value) {
70
73
  const step = 100 / (colorStops.length - 1);
71
74
  colorStops.forEach((stop, index) => {
72
75
  stop.length = {
73
- value: step * index,
76
+ value: `${step * index}`,
74
77
  type: '%'
75
78
  };
76
79
  });
77
- gradientAST.value = (0, _serializer.serializeGradient)(gradientAST);
78
80
  }
79
81
 
80
- return gradientAST;
82
+ return {
83
+ gradientAST,
84
+ hasGradient
85
+ };
81
86
  }
82
87
 
83
88
  function getGradientAstWithControlPoints(gradientAST, newControlPoints) {
@@ -99,7 +104,7 @@ function getGradientAstWithControlPoints(gradientAST, newControlPoints) {
99
104
  value: position === null || position === void 0 ? void 0 : position.toString()
100
105
  },
101
106
  type: a < 1 ? 'rgba' : 'rgb',
102
- value: a < 1 ? [r, g, b, a] : [r, g, b]
107
+ value: a < 1 ? [`${r}`, `${g}`, `${b}`, `${a}`] : [`${r}`, `${g}`, `${b}`]
103
108
  };
104
109
  })
105
110
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/utils.js"],"names":["namesPlugin","getLinearGradientRepresentation","gradientAST","type","orientation","HORIZONTAL_GRADIENT_ORIENTATION","colorStops","hasUnsupportedLength","item","length","undefined","getGradientAstWithDefault","value","gradientParser","parse","error","DEFAULT_GRADIENT","DIRECTIONAL_ORIENTATION_ANGLE_MAP","toString","some","step","forEach","stop","index","getGradientAstWithControlPoints","newControlPoints","map","position","color","r","g","b","a","toRgb","getStopCssColor","colorStop","join"],"mappings":";;;;;;;;;;;;AAKA;;AACA;;AACA;;AAKA;;AAKA;;AAjBA;;AAEA;AACA;AACA;;AAKA;AACA;AACA;AAQA,oBAAQ,CAAEA,cAAF,CAAR;;AAEO,SAASC,+BAAT,CAA0CC,WAA1C,EAAwD;AAC9D,SAAO,mCAAmB;AACzBC,IAAAA,IAAI,EAAE,iBADmB;AAEzBC,IAAAA,WAAW,EAAEC,0CAFY;AAGzBC,IAAAA,UAAU,EAAEJ,WAAW,CAACI;AAHC,GAAnB,CAAP;AAKA;;AAED,SAASC,oBAAT,CAA+BC,IAA/B,EAAsC;AACrC,SAAOA,IAAI,CAACC,MAAL,KAAgBC,SAAhB,IAA6BF,IAAI,CAACC,MAAL,CAAYN,IAAZ,KAAqB,GAAzD;AACA;;AAEM,SAASQ,yBAAT,CAAoCC,KAApC,EAA4C;AAAA;;AAClD;AACA;AACA,MAAIV,WAAJ;;AAEA,MAAI;AACHA,IAAAA,WAAW,GAAGW,wBAAeC,KAAf,CAAsBF,KAAtB,EAA+B,CAA/B,CAAd;AACAV,IAAAA,WAAW,CAACU,KAAZ,GAAoBA,KAApB;AACA,GAHD,CAGE,OAAQG,KAAR,EAAgB;AACjBb,IAAAA,WAAW,GAAGW,wBAAeC,K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A,MAAM,EAAE;AACPN,UAAAA,IAAI,EAAE,GADC;AAEPS,UAAAA,KAAK,EAAEe,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAET,QAAV;AAFA,SADF;AAKNf,QAAAA,IAAI,EAAE6B,CAAC,GAAG,CAAJ,GAAQ,MAAR,GAAiB,KALjB;AAMNpB,QAAAA,KAAK,EAAEoB,CAAC,GAAG,CAAJ,GAAQ,CAAEH,CAAF,EAAKC,CAAL,EAAQC,CAAR,EAAWC,CAAX,CAAR,GAAyB,CAAEH,CAAF,EAAKC,CAAL,EAAQC,CAAR;AAN1B,OAAP;AAQA,KAVW;AAFN,GAAP;AAcA;;AAEM,SAASG,eAAT,CAA0BC,SAA1B,EAAsC;AAC5C,UAASA,SAAS,CAAChC,IAAnB;AACC,SAAK,KAAL;AACC,aAAQ,IAAIgC,SAAS,CAACvB,KAAO,EAA7B;;AACD,SAAK,SAAL;AACC,aAAOuB,SAAS,CAACvB,KAAjB;;AACD,SAAK,KAAL;AACA,SAAK,MAAL;AACC,aAAQ,GAAGuB,SAAS,CAAChC,IAAM,IAAIgC,SAAS,CAACvB,KAAV,CAAgBwB,IAAhB,CAAsB,GAAtB,CAA6B,GAA5D;;AACD;AACC;AACA;AACA,aAAO,aAAP;AAXF;AAaA","sourcesContent":["// @ts-nocheck\n\n/**\n * External 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';\n\nextend( [ namesPlugin ] );\n\nexport function getLinearGradientRepresentation( gradientAST ) {\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 ) {\n\treturn item.length === undefined || item.length.type !== '%';\n}\n\nexport function getGradientAstWithDefault( value ) {\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;\n\n\ttry {\n\t\tgradientAST = gradientParser.parse( value )[ 0 ];\n\t\tgradientAST.value = value;\n\t} catch ( error ) {\n\t\tgradientAST = gradientParser.parse( DEFAULT_GRADIENT )[ 0 ];\n\t\tgradientAST.value = DEFAULT_GRADIENT;\n\t}\n\n\tif ( gradientAST.orientation?.type === 'directional' ) {\n\t\tgradientAST.orientation.type = 'angular';\n\t\tgradientAST.orientation.value =\n\t\t\tDIRECTIONAL_ORIENTATION_ANGLE_MAP[\n\t\t\t\tgradientAST.orientation.value\n\t\t\t].toString();\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\tgradientAST.value = serializeGradient( gradientAST );\n\t}\n\n\treturn gradientAST;\n}\n\nexport function getGradientAstWithControlPoints(\n\tgradientAST,\n\tnewControlPoints\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: a < 1 ? [ r, g, b, a ] : [ r, g, b ],\n\t\t\t};\n\t\t} ),\n\t};\n}\n\nexport function getStopCssColor( 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"]}
1
+ {"version":3,"sources":["@wordpress/components/src/custom-gradient-picker/utils.ts"],"names":["namesPlugin","getLinearGradientRepresentation","gradientAST","type","orientation","HORIZONTAL_GRADIENT_ORIENTATION","colorStops","hasUnsupportedLength","item","length","undefined","getGradientAstWithDefault","value","hasGradient","valueToParse","DEFAULT_GRADIENT","gradientParser","parse","error","console","warn","Array","isArray","DIRECTIONAL_ORIENTATION_ANGLE_MAP","toString","some","step","forEach","stop","index","getGradientAstWithControlPoints","newControlPoints","map","position","color","r","g","b","a","toRgb","getStopCssColor","colorStop","join"],"mappings":";;;;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAKA;;AAfA;AACA;AACA;;AAKA;AACA;AACA;AASA,oBAAQ,CAAEA,cAAF,CAAR;;AAEO,SAASC,+BAAT,CACNC,WADM,EAEL;AACD,SAAO,mCAAmB;AACzBC,IAAAA,IAAI,EAAE,iBADmB;AAEzBC,IAAAA,WAAW,EAAEC,0CAFY;AAGzBC,IAAAA,UAAU,EAAEJ,WAAW,CAACI;AAHC,GAAnB,CAAP;AAKA;;AAED,SAASC,oBAAT,CAA+BC,IAA/B,EAAgE;AAC/D,SAAOA,IAAI,CAACC,MAAL,KAAgBC,SAAhB,IAA6BF,IAAI,CAACC,MAAL,CAAYN,IAAZ,KAAqB,GAAzD;AACA;;AAEM,SAASQ,yBAAT,CAAoCC,KAApC,EAA4D;AAAA;;AAClE;AACA;AACA,MAAIV,WAAJ;AACA,MAAIW,WAAW,GAAG,CAAC,CAAED,KAArB;AAEA,QAAME,YAAY,GAAGF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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"]}