@react-stately/color 3.9.4 → 3.10.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 (233) hide show
  1. package/dist/import.mjs +7 -9
  2. package/dist/main.js +14 -16
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +7 -9
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +12 -0
  7. package/package.json +17 -20
  8. package/src/index.ts +12 -16
  9. package/dist/Color.main.js +0 -766
  10. package/dist/Color.main.js.map +0 -1
  11. package/dist/Color.mjs +0 -759
  12. package/dist/Color.module.js +0 -759
  13. package/dist/Color.module.js.map +0 -1
  14. package/dist/ar-AE.main.js +0 -42
  15. package/dist/ar-AE.main.js.map +0 -1
  16. package/dist/ar-AE.mjs +0 -44
  17. package/dist/ar-AE.module.js +0 -44
  18. package/dist/ar-AE.module.js.map +0 -1
  19. package/dist/bg-BG.main.js +0 -42
  20. package/dist/bg-BG.main.js.map +0 -1
  21. package/dist/bg-BG.mjs +0 -44
  22. package/dist/bg-BG.module.js +0 -44
  23. package/dist/bg-BG.module.js.map +0 -1
  24. package/dist/cs-CZ.main.js +0 -42
  25. package/dist/cs-CZ.main.js.map +0 -1
  26. package/dist/cs-CZ.mjs +0 -44
  27. package/dist/cs-CZ.module.js +0 -44
  28. package/dist/cs-CZ.module.js.map +0 -1
  29. package/dist/da-DK.main.js +0 -42
  30. package/dist/da-DK.main.js.map +0 -1
  31. package/dist/da-DK.mjs +0 -44
  32. package/dist/da-DK.module.js +0 -44
  33. package/dist/da-DK.module.js.map +0 -1
  34. package/dist/de-DE.main.js +0 -42
  35. package/dist/de-DE.main.js.map +0 -1
  36. package/dist/de-DE.mjs +0 -44
  37. package/dist/de-DE.module.js +0 -44
  38. package/dist/de-DE.module.js.map +0 -1
  39. package/dist/el-GR.main.js +0 -42
  40. package/dist/el-GR.main.js.map +0 -1
  41. package/dist/el-GR.mjs +0 -44
  42. package/dist/el-GR.module.js +0 -44
  43. package/dist/el-GR.module.js.map +0 -1
  44. package/dist/en-US.main.js +0 -42
  45. package/dist/en-US.main.js.map +0 -1
  46. package/dist/en-US.mjs +0 -44
  47. package/dist/en-US.module.js +0 -44
  48. package/dist/en-US.module.js.map +0 -1
  49. package/dist/es-ES.main.js +0 -42
  50. package/dist/es-ES.main.js.map +0 -1
  51. package/dist/es-ES.mjs +0 -44
  52. package/dist/es-ES.module.js +0 -44
  53. package/dist/es-ES.module.js.map +0 -1
  54. package/dist/et-EE.main.js +0 -42
  55. package/dist/et-EE.main.js.map +0 -1
  56. package/dist/et-EE.mjs +0 -44
  57. package/dist/et-EE.module.js +0 -44
  58. package/dist/et-EE.module.js.map +0 -1
  59. package/dist/fi-FI.main.js +0 -42
  60. package/dist/fi-FI.main.js.map +0 -1
  61. package/dist/fi-FI.mjs +0 -44
  62. package/dist/fi-FI.module.js +0 -44
  63. package/dist/fi-FI.module.js.map +0 -1
  64. package/dist/fr-FR.main.js +0 -42
  65. package/dist/fr-FR.main.js.map +0 -1
  66. package/dist/fr-FR.mjs +0 -44
  67. package/dist/fr-FR.module.js +0 -44
  68. package/dist/fr-FR.module.js.map +0 -1
  69. package/dist/he-IL.main.js +0 -42
  70. package/dist/he-IL.main.js.map +0 -1
  71. package/dist/he-IL.mjs +0 -44
  72. package/dist/he-IL.module.js +0 -44
  73. package/dist/he-IL.module.js.map +0 -1
  74. package/dist/hr-HR.main.js +0 -42
  75. package/dist/hr-HR.main.js.map +0 -1
  76. package/dist/hr-HR.mjs +0 -44
  77. package/dist/hr-HR.module.js +0 -44
  78. package/dist/hr-HR.module.js.map +0 -1
  79. package/dist/hu-HU.main.js +0 -42
  80. package/dist/hu-HU.main.js.map +0 -1
  81. package/dist/hu-HU.mjs +0 -44
  82. package/dist/hu-HU.module.js +0 -44
  83. package/dist/hu-HU.module.js.map +0 -1
  84. package/dist/intlStrings.main.js +0 -108
  85. package/dist/intlStrings.main.js.map +0 -1
  86. package/dist/intlStrings.mjs +0 -110
  87. package/dist/intlStrings.module.js +0 -110
  88. package/dist/intlStrings.module.js.map +0 -1
  89. package/dist/it-IT.main.js +0 -42
  90. package/dist/it-IT.main.js.map +0 -1
  91. package/dist/it-IT.mjs +0 -44
  92. package/dist/it-IT.module.js +0 -44
  93. package/dist/it-IT.module.js.map +0 -1
  94. package/dist/ja-JP.main.js +0 -42
  95. package/dist/ja-JP.main.js.map +0 -1
  96. package/dist/ja-JP.mjs +0 -44
  97. package/dist/ja-JP.module.js +0 -44
  98. package/dist/ja-JP.module.js.map +0 -1
  99. package/dist/ko-KR.main.js +0 -42
  100. package/dist/ko-KR.main.js.map +0 -1
  101. package/dist/ko-KR.mjs +0 -44
  102. package/dist/ko-KR.module.js +0 -44
  103. package/dist/ko-KR.module.js.map +0 -1
  104. package/dist/lt-LT.main.js +0 -42
  105. package/dist/lt-LT.main.js.map +0 -1
  106. package/dist/lt-LT.mjs +0 -44
  107. package/dist/lt-LT.module.js +0 -44
  108. package/dist/lt-LT.module.js.map +0 -1
  109. package/dist/lv-LV.main.js +0 -42
  110. package/dist/lv-LV.main.js.map +0 -1
  111. package/dist/lv-LV.mjs +0 -44
  112. package/dist/lv-LV.module.js +0 -44
  113. package/dist/lv-LV.module.js.map +0 -1
  114. package/dist/nb-NO.main.js +0 -42
  115. package/dist/nb-NO.main.js.map +0 -1
  116. package/dist/nb-NO.mjs +0 -44
  117. package/dist/nb-NO.module.js +0 -44
  118. package/dist/nb-NO.module.js.map +0 -1
  119. package/dist/nl-NL.main.js +0 -42
  120. package/dist/nl-NL.main.js.map +0 -1
  121. package/dist/nl-NL.mjs +0 -44
  122. package/dist/nl-NL.module.js +0 -44
  123. package/dist/nl-NL.module.js.map +0 -1
  124. package/dist/pl-PL.main.js +0 -42
  125. package/dist/pl-PL.main.js.map +0 -1
  126. package/dist/pl-PL.mjs +0 -44
  127. package/dist/pl-PL.module.js +0 -44
  128. package/dist/pl-PL.module.js.map +0 -1
  129. package/dist/pt-BR.main.js +0 -42
  130. package/dist/pt-BR.main.js.map +0 -1
  131. package/dist/pt-BR.mjs +0 -44
  132. package/dist/pt-BR.module.js +0 -44
  133. package/dist/pt-BR.module.js.map +0 -1
  134. package/dist/pt-PT.main.js +0 -42
  135. package/dist/pt-PT.main.js.map +0 -1
  136. package/dist/pt-PT.mjs +0 -44
  137. package/dist/pt-PT.module.js +0 -44
  138. package/dist/pt-PT.module.js.map +0 -1
  139. package/dist/ro-RO.main.js +0 -42
  140. package/dist/ro-RO.main.js.map +0 -1
  141. package/dist/ro-RO.mjs +0 -44
  142. package/dist/ro-RO.module.js +0 -44
  143. package/dist/ro-RO.module.js.map +0 -1
  144. package/dist/ru-RU.main.js +0 -42
  145. package/dist/ru-RU.main.js.map +0 -1
  146. package/dist/ru-RU.mjs +0 -44
  147. package/dist/ru-RU.module.js +0 -44
  148. package/dist/ru-RU.module.js.map +0 -1
  149. package/dist/sk-SK.main.js +0 -42
  150. package/dist/sk-SK.main.js.map +0 -1
  151. package/dist/sk-SK.mjs +0 -44
  152. package/dist/sk-SK.module.js +0 -44
  153. package/dist/sk-SK.module.js.map +0 -1
  154. package/dist/sl-SI.main.js +0 -42
  155. package/dist/sl-SI.main.js.map +0 -1
  156. package/dist/sl-SI.mjs +0 -44
  157. package/dist/sl-SI.module.js +0 -44
  158. package/dist/sl-SI.module.js.map +0 -1
  159. package/dist/sr-SP.main.js +0 -42
  160. package/dist/sr-SP.main.js.map +0 -1
  161. package/dist/sr-SP.mjs +0 -44
  162. package/dist/sr-SP.module.js +0 -44
  163. package/dist/sr-SP.module.js.map +0 -1
  164. package/dist/sv-SE.main.js +0 -42
  165. package/dist/sv-SE.main.js.map +0 -1
  166. package/dist/sv-SE.mjs +0 -44
  167. package/dist/sv-SE.module.js +0 -44
  168. package/dist/sv-SE.module.js.map +0 -1
  169. package/dist/tr-TR.main.js +0 -42
  170. package/dist/tr-TR.main.js.map +0 -1
  171. package/dist/tr-TR.mjs +0 -44
  172. package/dist/tr-TR.module.js +0 -44
  173. package/dist/tr-TR.module.js.map +0 -1
  174. package/dist/types.d.ts +0 -198
  175. package/dist/types.d.ts.map +0 -1
  176. package/dist/uk-UA.main.js +0 -42
  177. package/dist/uk-UA.main.js.map +0 -1
  178. package/dist/uk-UA.mjs +0 -44
  179. package/dist/uk-UA.module.js +0 -44
  180. package/dist/uk-UA.module.js.map +0 -1
  181. package/dist/useColor.main.js +0 -36
  182. package/dist/useColor.main.js.map +0 -1
  183. package/dist/useColor.mjs +0 -31
  184. package/dist/useColor.module.js +0 -31
  185. package/dist/useColor.module.js.map +0 -1
  186. package/dist/useColorAreaState.main.js +0 -133
  187. package/dist/useColorAreaState.main.js.map +0 -1
  188. package/dist/useColorAreaState.mjs +0 -128
  189. package/dist/useColorAreaState.module.js +0 -128
  190. package/dist/useColorAreaState.module.js.map +0 -1
  191. package/dist/useColorChannelFieldState.main.js +0 -65
  192. package/dist/useColorChannelFieldState.main.js.map +0 -1
  193. package/dist/useColorChannelFieldState.mjs +0 -60
  194. package/dist/useColorChannelFieldState.module.js +0 -60
  195. package/dist/useColorChannelFieldState.module.js.map +0 -1
  196. package/dist/useColorFieldState.main.js +0 -142
  197. package/dist/useColorFieldState.main.js.map +0 -1
  198. package/dist/useColorFieldState.mjs +0 -137
  199. package/dist/useColorFieldState.module.js +0 -137
  200. package/dist/useColorFieldState.module.js.map +0 -1
  201. package/dist/useColorPickerState.main.js +0 -27
  202. package/dist/useColorPickerState.main.js.map +0 -1
  203. package/dist/useColorPickerState.mjs +0 -22
  204. package/dist/useColorPickerState.module.js +0 -22
  205. package/dist/useColorPickerState.module.js.map +0 -1
  206. package/dist/useColorSliderState.main.js +0 -93
  207. package/dist/useColorSliderState.main.js.map +0 -1
  208. package/dist/useColorSliderState.mjs +0 -88
  209. package/dist/useColorSliderState.module.js +0 -88
  210. package/dist/useColorSliderState.module.js.map +0 -1
  211. package/dist/useColorWheelState.main.js +0 -135
  212. package/dist/useColorWheelState.main.js.map +0 -1
  213. package/dist/useColorWheelState.mjs +0 -130
  214. package/dist/useColorWheelState.module.js +0 -130
  215. package/dist/useColorWheelState.module.js.map +0 -1
  216. package/dist/zh-CN.main.js +0 -42
  217. package/dist/zh-CN.main.js.map +0 -1
  218. package/dist/zh-CN.mjs +0 -44
  219. package/dist/zh-CN.module.js +0 -44
  220. package/dist/zh-CN.module.js.map +0 -1
  221. package/dist/zh-TW.main.js +0 -42
  222. package/dist/zh-TW.main.js.map +0 -1
  223. package/dist/zh-TW.mjs +0 -44
  224. package/dist/zh-TW.module.js +0 -44
  225. package/dist/zh-TW.module.js.map +0 -1
  226. package/src/Color.ts +0 -792
  227. package/src/useColor.ts +0 -28
  228. package/src/useColorAreaState.ts +0 -202
  229. package/src/useColorChannelFieldState.ts +0 -74
  230. package/src/useColorFieldState.ts +0 -197
  231. package/src/useColorPickerState.ts +0 -29
  232. package/src/useColorSliderState.ts +0 -109
  233. package/src/useColorWheelState.ts +0 -196
@@ -1,60 +0,0 @@
1
- import {useColor as $aa90ad8b2b1d015f$export$5aadd9c0606af5c2} from "./useColor.module.js";
2
- import {useNumberFieldState as $52OvP$useNumberFieldState} from "@react-stately/numberfield";
3
- import {useControlledState as $52OvP$useControlledState} from "@react-stately/utils";
4
- import {useState as $52OvP$useState, useMemo as $52OvP$useMemo} from "react";
5
-
6
-
7
-
8
-
9
-
10
- function $31a863bb88e75dd6$export$b9fc0d69c9190c4a(props) {
11
- let { channel: channel, colorSpace: colorSpace, locale: locale } = props;
12
- let initialValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(props.value);
13
- let initialDefaultValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(props.defaultValue);
14
- let [colorValue, setColor] = (0, $52OvP$useControlledState)(initialValue, initialDefaultValue !== null && initialDefaultValue !== void 0 ? initialDefaultValue : null, props.onChange);
15
- let color = $31a863bb88e75dd6$var$useConvertColor(colorValue, colorSpace);
16
- let [initialColorValue] = (0, $52OvP$useState)(colorValue);
17
- let defaultColorValue = initialDefaultValue !== null && initialDefaultValue !== void 0 ? initialDefaultValue : initialColorValue;
18
- let defaultColor = $31a863bb88e75dd6$var$useConvertColor(defaultColorValue, colorSpace);
19
- let value = color.getChannelValue(channel);
20
- let range = color.getChannelRange(channel);
21
- let formatOptions = (0, $52OvP$useMemo)(()=>color.getChannelFormatOptions(channel), [
22
- color,
23
- channel
24
- ]);
25
- let multiplier = formatOptions.style === 'percent' && range.maxValue === 100 ? 100 : 1;
26
- let numberFieldState = (0, $52OvP$useNumberFieldState)({
27
- locale: locale,
28
- value: colorValue === null ? NaN : value / multiplier,
29
- defaultValue: defaultColorValue === null ? NaN : defaultColor.getChannelValue(channel) / multiplier,
30
- onChange: (v)=>{
31
- if (!Number.isNaN(v)) setColor(color.withChannelValue(channel, v * multiplier));
32
- else setColor(null);
33
- },
34
- minValue: range.minValue / multiplier,
35
- maxValue: range.maxValue / multiplier,
36
- step: range.step / multiplier,
37
- formatOptions: formatOptions
38
- });
39
- return {
40
- ...numberFieldState,
41
- colorValue: color,
42
- defaultColorValue: defaultColorValue,
43
- setColorValue: setColor
44
- };
45
- }
46
- function $31a863bb88e75dd6$var$useConvertColor(colorValue, colorSpace) {
47
- let black = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)('#000');
48
- return (0, $52OvP$useMemo)(()=>{
49
- let nonNullColorValue = colorValue || black;
50
- return colorSpace && nonNullColorValue ? nonNullColorValue.toFormat(colorSpace) : nonNullColorValue;
51
- }, [
52
- black,
53
- colorValue,
54
- colorSpace
55
- ]);
56
- }
57
-
58
-
59
- export {$31a863bb88e75dd6$export$b9fc0d69c9190c4a as useColorChannelFieldState};
60
- //# sourceMappingURL=useColorChannelFieldState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;AA4BO,SAAS,0CAA0B,KAAoC;IAC5E,IAAI,WAAC,OAAO,cAAE,UAAU,UAAE,MAAM,EAAC,GAAG;IACpC,IAAI,eAAe,CAAA,GAAA,yCAAO,EAAE,MAAM,KAAK;IACvC,IAAI,sBAAsB,CAAA,GAAA,yCAAO,EAAE,MAAM,YAAY;IACrD,IAAI,CAAC,YAAY,SAAS,GAAG,CAAA,GAAA,yBAAiB,EAAE,cAAc,gCAAA,iCAAA,sBAAuB,MAAM,MAAM,QAAQ;IACzG,IAAI,QAAQ,sCAAgB,YAAY;IACxC,IAAI,CAAC,kBAAkB,GAAG,CAAA,GAAA,eAAO,EAAE;IACnC,IAAI,oBAAoB,gCAAA,iCAAA,sBAAuB;IAC/C,IAAI,eAAe,sCAAgB,mBAAmB;IACtD,IAAI,QAAQ,MAAM,eAAe,CAAC;IAClC,IAAI,QAAQ,MAAM,eAAe,CAAC;IAClC,IAAI,gBAAgB,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,uBAAuB,CAAC,UAAU;QAAC;QAAO;KAAQ;IAC1F,IAAI,aAAa,cAAc,KAAK,KAAK,aAAa,MAAM,QAAQ,KAAK,MAAM,MAAM;IAErF,IAAI,mBAAmB,CAAA,GAAA,0BAAkB,EAAE;gBACzC;QACA,OAAO,eAAe,OAAO,MAAM,QAAQ;QAC3C,cAAc,sBAAsB,OAAO,MAAM,aAAa,eAAe,CAAC,WAAW;QACzF,UAAU,CAAC;YACT,IAAI,CAAC,OAAO,KAAK,CAAC,IAChB,SAAS,MAAM,gBAAgB,CAAC,SAAS,IAAI;iBAE7C,SAAS;QAEb;QACA,UAAU,MAAM,QAAQ,GAAG;QAC3B,UAAU,MAAM,QAAQ,GAAG;QAC3B,MAAM,MAAM,IAAI,GAAG;uBACnB;IACF;IAEA,OAAO;QACL,GAAG,gBAAgB;QACnB,YAAY;2BACZ;QACA,eAAe;IACjB;AACF;AAEA,SAAS,sCAAgB,UAAwB,EAAE,UAAyC;IAC1F,IAAI,QAAQ,CAAA,GAAA,yCAAO,EAAE;IACrB,OAAO,CAAA,GAAA,cAAM,EAAE;QACb,IAAI,oBAAoB,cAAc;QACtC,OAAO,cAAc,oBAAoB,kBAAkB,QAAQ,CAAC,cAAc;IACpF,GAAG;QAAC;QAAO;QAAY;KAAW;AACpC","sources":["packages/@react-stately/color/src/useColorChannelFieldState.ts"],"sourcesContent":["import {Color, ColorChannel, ColorFieldProps, ColorSpace} from '@react-types/color';\nimport {NumberFieldState, useNumberFieldState} from '@react-stately/numberfield';\nimport {useColor} from './useColor';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorChannelFieldProps extends ColorFieldProps {\n colorSpace?: ColorSpace,\n channel: ColorChannel\n}\n\nexport interface ColorChannelFieldStateOptions extends ColorChannelFieldProps {\n locale: string\n}\n\nexport interface ColorChannelFieldState extends NumberFieldState {\n /** The current value of the field. */\n colorValue: Color,\n /** The default value of the field. */\n defaultColorValue: Color | null,\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void\n}\n\n/**\n * Provides state management for a color channel field, allowing users to edit the\n * value of an individual color channel.\n */\nexport function useColorChannelFieldState(props: ColorChannelFieldStateOptions): ColorChannelFieldState {\n let {channel, colorSpace, locale} = props;\n let initialValue = useColor(props.value);\n let initialDefaultValue = useColor(props.defaultValue);\n let [colorValue, setColor] = useControlledState(initialValue, initialDefaultValue ?? null, props.onChange);\n let color = useConvertColor(colorValue, colorSpace);\n let [initialColorValue] = useState(colorValue);\n let defaultColorValue = initialDefaultValue ?? initialColorValue;\n let defaultColor = useConvertColor(defaultColorValue, colorSpace);\n let value = color.getChannelValue(channel);\n let range = color.getChannelRange(channel);\n let formatOptions = useMemo(() => color.getChannelFormatOptions(channel), [color, channel]);\n let multiplier = formatOptions.style === 'percent' && range.maxValue === 100 ? 100 : 1;\n\n let numberFieldState = useNumberFieldState({\n locale,\n value: colorValue === null ? NaN : value / multiplier,\n defaultValue: defaultColorValue === null ? NaN : defaultColor.getChannelValue(channel) / multiplier,\n onChange: (v) => {\n if (!Number.isNaN(v)) {\n setColor(color.withChannelValue(channel, v * multiplier));\n } else {\n setColor(null);\n }\n },\n minValue: range.minValue / multiplier,\n maxValue: range.maxValue / multiplier,\n step: range.step / multiplier,\n formatOptions\n });\n\n return {\n ...numberFieldState,\n colorValue: color,\n defaultColorValue,\n setColorValue: setColor\n };\n}\n\nfunction useConvertColor(colorValue: Color | null, colorSpace: ColorSpace | null | undefined) {\n let black = useColor('#000')!;\n return useMemo(() => {\n let nonNullColorValue = colorValue || black;\n return colorSpace && nonNullColorValue ? nonNullColorValue.toFormat(colorSpace) : nonNullColorValue;\n }, [black, colorValue, colorSpace]);\n}\n"],"names":[],"version":3,"file":"useColorChannelFieldState.module.js.map"}
@@ -1,142 +0,0 @@
1
- var $83fe1a57d631223b$exports = require("./Color.main.js");
2
- var $f8b3be23ba4462b1$exports = require("./useColor.main.js");
3
- var $41neA$reactstatelyform = require("@react-stately/form");
4
- var $41neA$reactstatelyutils = require("@react-stately/utils");
5
- var $41neA$react = require("react");
6
-
7
-
8
- function $parcel$export(e, n, v, s) {
9
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
- }
11
-
12
- $parcel$export(module.exports, "useColorFieldState", () => $d59d0c2b2ce1568f$export$d52a01683abdfcd6);
13
- /*
14
- * Copyright 2020 Adobe. All rights reserved.
15
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
- * you may not use this file except in compliance with the License. You may obtain a copy
17
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software distributed under
20
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
- * OF ANY KIND, either express or implied. See the License for the specific language
22
- * governing permissions and limitations under the License.
23
- */
24
-
25
-
26
-
27
-
28
- const $d59d0c2b2ce1568f$var$MIN_COLOR = (0, $83fe1a57d631223b$exports.parseColor)('#000000');
29
- const $d59d0c2b2ce1568f$var$MAX_COLOR = (0, $83fe1a57d631223b$exports.parseColor)('#FFFFFF');
30
- const $d59d0c2b2ce1568f$var$MIN_COLOR_INT = $d59d0c2b2ce1568f$var$MIN_COLOR.toHexInt();
31
- const $d59d0c2b2ce1568f$var$MAX_COLOR_INT = $d59d0c2b2ce1568f$var$MAX_COLOR.toHexInt();
32
- function $d59d0c2b2ce1568f$export$d52a01683abdfcd6(props) {
33
- let { value: value, defaultValue: defaultValue, onChange: onChange } = props;
34
- let { step: step } = $d59d0c2b2ce1568f$var$MIN_COLOR.getChannelRange('red');
35
- let initialDefaultValue = (0, $f8b3be23ba4462b1$exports.useColor)(defaultValue);
36
- let [colorValue, setColorValue] = (0, $41neA$reactstatelyutils.useControlledState)((0, $f8b3be23ba4462b1$exports.useColor)(value), initialDefaultValue, onChange);
37
- let [initialValue] = (0, $41neA$react.useState)(colorValue);
38
- let [inputValue, setInputValue] = (0, $41neA$react.useState)(()=>(value || defaultValue) && colorValue ? colorValue.toString('hex') : '');
39
- let validation = (0, $41neA$reactstatelyform.useFormValidationState)({
40
- ...props,
41
- value: colorValue
42
- });
43
- let safelySetColorValue = (newColor)=>{
44
- if (!colorValue || !newColor) {
45
- setColorValue(newColor);
46
- return;
47
- }
48
- if (newColor.toHexInt() !== colorValue.toHexInt()) {
49
- setColorValue(newColor);
50
- return;
51
- }
52
- };
53
- let [prevValue, setPrevValue] = (0, $41neA$react.useState)(colorValue);
54
- if (prevValue !== colorValue) {
55
- setInputValue(colorValue ? colorValue.toString('hex') : '');
56
- setPrevValue(colorValue);
57
- }
58
- let parsedValue = (0, $41neA$react.useMemo)(()=>{
59
- let color;
60
- try {
61
- color = (0, $83fe1a57d631223b$exports.parseColor)(inputValue.startsWith('#') ? inputValue : `#${inputValue}`);
62
- } catch {
63
- color = null;
64
- }
65
- return color;
66
- }, [
67
- inputValue
68
- ]);
69
- let commit = ()=>{
70
- // Set to empty state if input value is empty
71
- if (!inputValue.length) {
72
- safelySetColorValue(null);
73
- if (value === undefined || colorValue === null) setInputValue('');
74
- else setInputValue(colorValue.toString('hex'));
75
- return;
76
- }
77
- // if it failed to parse, then reset input to formatted version of current number
78
- if (parsedValue == null) {
79
- setInputValue(colorValue ? colorValue.toString('hex') : '');
80
- return;
81
- }
82
- safelySetColorValue(parsedValue);
83
- // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
84
- let newColorValue = '';
85
- if (colorValue) newColorValue = colorValue.toString('hex');
86
- setInputValue(newColorValue);
87
- validation.commitValidation();
88
- };
89
- let increment = ()=>{
90
- let newValue = $d59d0c2b2ce1568f$var$addColorValue(parsedValue, step);
91
- // if we've arrived at the same value that was previously in the state, the
92
- // input value should be updated to match
93
- // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
94
- // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
95
- if (newValue === colorValue) setInputValue(newValue.toString('hex'));
96
- safelySetColorValue(newValue);
97
- validation.commitValidation();
98
- };
99
- let decrement = ()=>{
100
- let newValue = $d59d0c2b2ce1568f$var$addColorValue(parsedValue, -step);
101
- // if we've arrived at the same value that was previously in the state, the
102
- // input value should be updated to match
103
- // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
104
- // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
105
- if (newValue === colorValue) setInputValue(newValue.toString('hex'));
106
- safelySetColorValue(newValue);
107
- validation.commitValidation();
108
- };
109
- let incrementToMax = ()=>safelySetColorValue($d59d0c2b2ce1568f$var$MAX_COLOR);
110
- let decrementToMin = ()=>safelySetColorValue($d59d0c2b2ce1568f$var$MIN_COLOR);
111
- let validate = (value)=>{
112
- var _value_match;
113
- return value === '' || !!((_value_match = value.match(/^#?[0-9a-f]{0,6}$/i)) === null || _value_match === void 0 ? void 0 : _value_match[0]);
114
- };
115
- return {
116
- ...validation,
117
- validate: validate,
118
- colorValue: colorValue,
119
- defaultColorValue: initialDefaultValue !== null && initialDefaultValue !== void 0 ? initialDefaultValue : initialValue,
120
- setColorValue: setColorValue,
121
- inputValue: inputValue,
122
- setInputValue: setInputValue,
123
- commit: commit,
124
- increment: increment,
125
- incrementToMax: incrementToMax,
126
- decrement: decrement,
127
- decrementToMin: decrementToMin
128
- };
129
- }
130
- function $d59d0c2b2ce1568f$var$addColorValue(color, step) {
131
- let newColor = color ? color : $d59d0c2b2ce1568f$var$MIN_COLOR;
132
- let colorInt = newColor.toHexInt();
133
- let clampInt = Math.min(Math.max(colorInt + step, $d59d0c2b2ce1568f$var$MIN_COLOR_INT), $d59d0c2b2ce1568f$var$MAX_COLOR_INT);
134
- if (clampInt !== colorInt) {
135
- let newColorString = `#${clampInt.toString(16).padStart(6, '0').toUpperCase()}`;
136
- newColor = (0, $83fe1a57d631223b$exports.parseColor)(newColorString);
137
- }
138
- return newColor;
139
- }
140
-
141
-
142
- //# sourceMappingURL=useColorFieldState.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":"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","sources":["packages/@react-stately/color/src/useColorFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Color, ColorFieldProps} from '@react-types/color';\nimport {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {parseColor} from './Color';\nimport {useColor} from './useColor';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n readonly inputValue: string,\n /**\n * The currently parsed color value, or null if the field is empty.\n * Updated based on the `inputValue` as the user types.\n */\n readonly colorValue: Color | null,\n /** The default value of the color field. */\n readonly defaultColorValue: Color | null,\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void,\n /** Sets the current text value of the input. */\n setInputValue(value: string): void,\n /**\n * Updates the input value based on the currently parsed color value.\n * Typically this is called when the field is blurred.\n */\n commit(): void,\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void,\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void,\n /** Sets the current value to the maximum color value, and fires `onChange`. */\n incrementToMax(): void,\n /** Sets the current value to the minimum color value, and fires `onChange`. */\n decrementToMin(): void,\n /**\n * Validates a user input string.\n * Values can be partially entered, and may be valid even if they cannot currently be parsed to a color.\n * Can be used to implement validation as a user types.\n */\n validate(value: string): boolean\n}\n\nconst MIN_COLOR = parseColor('#000000');\nconst MAX_COLOR = parseColor('#FFFFFF');\nconst MIN_COLOR_INT = MIN_COLOR.toHexInt();\nconst MAX_COLOR_INT = MAX_COLOR.toHexInt();\n\n/**\n * Provides state management for a color field component. Color fields allow\n * users to enter and adjust a hex color value.\n */\nexport function useColorFieldState(\n props: ColorFieldProps\n): ColorFieldState {\n let {\n value,\n defaultValue,\n onChange\n } = props;\n let {step} = MIN_COLOR.getChannelRange('red');\n\n let initialDefaultValue = useColor(defaultValue);\n let [colorValue, setColorValue] = useControlledState<Color | null>(useColor(value), initialDefaultValue!, onChange);\n let [initialValue] = useState(colorValue);\n let [inputValue, setInputValue] = useState(() => (value || defaultValue) && colorValue ? colorValue.toString('hex') : '');\n\n let validation = useFormValidationState({\n ...props,\n value: colorValue\n });\n\n let safelySetColorValue = (newColor: Color | null) => {\n if (!colorValue || !newColor) {\n setColorValue(newColor);\n return;\n }\n if (newColor.toHexInt() !== colorValue.toHexInt()) {\n setColorValue(newColor);\n return;\n }\n };\n\n let [prevValue, setPrevValue] = useState(colorValue);\n if (prevValue !== colorValue) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n setPrevValue(colorValue);\n }\n\n let parsedValue = useMemo(() => {\n let color;\n try {\n color = parseColor(inputValue.startsWith('#') ? inputValue : `#${inputValue}`);\n } catch {\n color = null;\n }\n return color;\n }, [inputValue]);\n\n let commit = () => {\n // Set to empty state if input value is empty\n if (!inputValue.length) {\n safelySetColorValue(null);\n if (value === undefined || colorValue === null) {\n setInputValue('');\n } else {\n setInputValue(colorValue.toString('hex'));\n }\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (parsedValue == null) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n return;\n }\n\n safelySetColorValue(parsedValue);\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n let newColorValue = '';\n if (colorValue) {\n newColorValue = colorValue.toString('hex');\n }\n setInputValue(newColorValue);\n validation.commitValidation();\n };\n\n let increment = () => {\n let newValue = addColorValue(parsedValue, step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let decrement = () => {\n let newValue = addColorValue(parsedValue, -step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let incrementToMax = () => safelySetColorValue(MAX_COLOR);\n let decrementToMin = () => safelySetColorValue(MIN_COLOR);\n\n let validate = (value: string) => value === '' || !!value.match(/^#?[0-9a-f]{0,6}$/i)?.[0];\n\n return {\n ...validation,\n validate,\n colorValue,\n defaultColorValue: initialDefaultValue ?? initialValue,\n setColorValue,\n inputValue,\n setInputValue,\n commit,\n increment,\n incrementToMax,\n decrement,\n decrementToMin\n };\n}\n\nfunction addColorValue(color: Color, step: number) {\n let newColor = color ? color : MIN_COLOR;\n let colorInt = newColor.toHexInt();\n\n let clampInt = Math.min(Math.max(colorInt + step, MIN_COLOR_INT), MAX_COLOR_INT);\n if (clampInt !== colorInt) {\n let newColorString = `#${clampInt.toString(16).padStart(6, '0').toUpperCase()}`;\n newColor = parseColor(newColorString);\n }\n return newColor;\n}\n"],"names":[],"version":3,"file":"useColorFieldState.main.js.map"}
@@ -1,137 +0,0 @@
1
- import {parseColor as $799cddbef784668f$export$6e865ea70d7724f} from "./Color.mjs";
2
- import {useColor as $aa90ad8b2b1d015f$export$5aadd9c0606af5c2} from "./useColor.mjs";
3
- import {useFormValidationState as $aP5W6$useFormValidationState} from "@react-stately/form";
4
- import {useControlledState as $aP5W6$useControlledState} from "@react-stately/utils";
5
- import {useState as $aP5W6$useState, useMemo as $aP5W6$useMemo} from "react";
6
-
7
- /*
8
- * Copyright 2020 Adobe. All rights reserved.
9
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License. You may obtain a copy
11
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software distributed under
14
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
- * OF ANY KIND, either express or implied. See the License for the specific language
16
- * governing permissions and limitations under the License.
17
- */
18
-
19
-
20
-
21
-
22
- const $b335ada08155d9c0$var$MIN_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)('#000000');
23
- const $b335ada08155d9c0$var$MAX_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)('#FFFFFF');
24
- const $b335ada08155d9c0$var$MIN_COLOR_INT = $b335ada08155d9c0$var$MIN_COLOR.toHexInt();
25
- const $b335ada08155d9c0$var$MAX_COLOR_INT = $b335ada08155d9c0$var$MAX_COLOR.toHexInt();
26
- function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
27
- let { value: value, defaultValue: defaultValue, onChange: onChange } = props;
28
- let { step: step } = $b335ada08155d9c0$var$MIN_COLOR.getChannelRange('red');
29
- let initialDefaultValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(defaultValue);
30
- let [colorValue, setColorValue] = (0, $aP5W6$useControlledState)((0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(value), initialDefaultValue, onChange);
31
- let [initialValue] = (0, $aP5W6$useState)(colorValue);
32
- let [inputValue, setInputValue] = (0, $aP5W6$useState)(()=>(value || defaultValue) && colorValue ? colorValue.toString('hex') : '');
33
- let validation = (0, $aP5W6$useFormValidationState)({
34
- ...props,
35
- value: colorValue
36
- });
37
- let safelySetColorValue = (newColor)=>{
38
- if (!colorValue || !newColor) {
39
- setColorValue(newColor);
40
- return;
41
- }
42
- if (newColor.toHexInt() !== colorValue.toHexInt()) {
43
- setColorValue(newColor);
44
- return;
45
- }
46
- };
47
- let [prevValue, setPrevValue] = (0, $aP5W6$useState)(colorValue);
48
- if (prevValue !== colorValue) {
49
- setInputValue(colorValue ? colorValue.toString('hex') : '');
50
- setPrevValue(colorValue);
51
- }
52
- let parsedValue = (0, $aP5W6$useMemo)(()=>{
53
- let color;
54
- try {
55
- color = (0, $799cddbef784668f$export$6e865ea70d7724f)(inputValue.startsWith('#') ? inputValue : `#${inputValue}`);
56
- } catch {
57
- color = null;
58
- }
59
- return color;
60
- }, [
61
- inputValue
62
- ]);
63
- let commit = ()=>{
64
- // Set to empty state if input value is empty
65
- if (!inputValue.length) {
66
- safelySetColorValue(null);
67
- if (value === undefined || colorValue === null) setInputValue('');
68
- else setInputValue(colorValue.toString('hex'));
69
- return;
70
- }
71
- // if it failed to parse, then reset input to formatted version of current number
72
- if (parsedValue == null) {
73
- setInputValue(colorValue ? colorValue.toString('hex') : '');
74
- return;
75
- }
76
- safelySetColorValue(parsedValue);
77
- // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
78
- let newColorValue = '';
79
- if (colorValue) newColorValue = colorValue.toString('hex');
80
- setInputValue(newColorValue);
81
- validation.commitValidation();
82
- };
83
- let increment = ()=>{
84
- let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, step);
85
- // if we've arrived at the same value that was previously in the state, the
86
- // input value should be updated to match
87
- // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
88
- // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
89
- if (newValue === colorValue) setInputValue(newValue.toString('hex'));
90
- safelySetColorValue(newValue);
91
- validation.commitValidation();
92
- };
93
- let decrement = ()=>{
94
- let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, -step);
95
- // if we've arrived at the same value that was previously in the state, the
96
- // input value should be updated to match
97
- // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
98
- // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
99
- if (newValue === colorValue) setInputValue(newValue.toString('hex'));
100
- safelySetColorValue(newValue);
101
- validation.commitValidation();
102
- };
103
- let incrementToMax = ()=>safelySetColorValue($b335ada08155d9c0$var$MAX_COLOR);
104
- let decrementToMin = ()=>safelySetColorValue($b335ada08155d9c0$var$MIN_COLOR);
105
- let validate = (value)=>{
106
- var _value_match;
107
- return value === '' || !!((_value_match = value.match(/^#?[0-9a-f]{0,6}$/i)) === null || _value_match === void 0 ? void 0 : _value_match[0]);
108
- };
109
- return {
110
- ...validation,
111
- validate: validate,
112
- colorValue: colorValue,
113
- defaultColorValue: initialDefaultValue !== null && initialDefaultValue !== void 0 ? initialDefaultValue : initialValue,
114
- setColorValue: setColorValue,
115
- inputValue: inputValue,
116
- setInputValue: setInputValue,
117
- commit: commit,
118
- increment: increment,
119
- incrementToMax: incrementToMax,
120
- decrement: decrement,
121
- decrementToMin: decrementToMin
122
- };
123
- }
124
- function $b335ada08155d9c0$var$addColorValue(color, step) {
125
- let newColor = color ? color : $b335ada08155d9c0$var$MIN_COLOR;
126
- let colorInt = newColor.toHexInt();
127
- let clampInt = Math.min(Math.max(colorInt + step, $b335ada08155d9c0$var$MIN_COLOR_INT), $b335ada08155d9c0$var$MAX_COLOR_INT);
128
- if (clampInt !== colorInt) {
129
- let newColorString = `#${clampInt.toString(16).padStart(6, '0').toUpperCase()}`;
130
- newColor = (0, $799cddbef784668f$export$6e865ea70d7724f)(newColorString);
131
- }
132
- return newColor;
133
- }
134
-
135
-
136
- export {$b335ada08155d9c0$export$d52a01683abdfcd6 as useColorFieldState};
137
- //# sourceMappingURL=useColorFieldState.module.js.map
@@ -1,137 +0,0 @@
1
- import {parseColor as $799cddbef784668f$export$6e865ea70d7724f} from "./Color.module.js";
2
- import {useColor as $aa90ad8b2b1d015f$export$5aadd9c0606af5c2} from "./useColor.module.js";
3
- import {useFormValidationState as $aP5W6$useFormValidationState} from "@react-stately/form";
4
- import {useControlledState as $aP5W6$useControlledState} from "@react-stately/utils";
5
- import {useState as $aP5W6$useState, useMemo as $aP5W6$useMemo} from "react";
6
-
7
- /*
8
- * Copyright 2020 Adobe. All rights reserved.
9
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
- * you may not use this file except in compliance with the License. You may obtain a copy
11
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software distributed under
14
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
- * OF ANY KIND, either express or implied. See the License for the specific language
16
- * governing permissions and limitations under the License.
17
- */
18
-
19
-
20
-
21
-
22
- const $b335ada08155d9c0$var$MIN_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)('#000000');
23
- const $b335ada08155d9c0$var$MAX_COLOR = (0, $799cddbef784668f$export$6e865ea70d7724f)('#FFFFFF');
24
- const $b335ada08155d9c0$var$MIN_COLOR_INT = $b335ada08155d9c0$var$MIN_COLOR.toHexInt();
25
- const $b335ada08155d9c0$var$MAX_COLOR_INT = $b335ada08155d9c0$var$MAX_COLOR.toHexInt();
26
- function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
27
- let { value: value, defaultValue: defaultValue, onChange: onChange } = props;
28
- let { step: step } = $b335ada08155d9c0$var$MIN_COLOR.getChannelRange('red');
29
- let initialDefaultValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(defaultValue);
30
- let [colorValue, setColorValue] = (0, $aP5W6$useControlledState)((0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(value), initialDefaultValue, onChange);
31
- let [initialValue] = (0, $aP5W6$useState)(colorValue);
32
- let [inputValue, setInputValue] = (0, $aP5W6$useState)(()=>(value || defaultValue) && colorValue ? colorValue.toString('hex') : '');
33
- let validation = (0, $aP5W6$useFormValidationState)({
34
- ...props,
35
- value: colorValue
36
- });
37
- let safelySetColorValue = (newColor)=>{
38
- if (!colorValue || !newColor) {
39
- setColorValue(newColor);
40
- return;
41
- }
42
- if (newColor.toHexInt() !== colorValue.toHexInt()) {
43
- setColorValue(newColor);
44
- return;
45
- }
46
- };
47
- let [prevValue, setPrevValue] = (0, $aP5W6$useState)(colorValue);
48
- if (prevValue !== colorValue) {
49
- setInputValue(colorValue ? colorValue.toString('hex') : '');
50
- setPrevValue(colorValue);
51
- }
52
- let parsedValue = (0, $aP5W6$useMemo)(()=>{
53
- let color;
54
- try {
55
- color = (0, $799cddbef784668f$export$6e865ea70d7724f)(inputValue.startsWith('#') ? inputValue : `#${inputValue}`);
56
- } catch {
57
- color = null;
58
- }
59
- return color;
60
- }, [
61
- inputValue
62
- ]);
63
- let commit = ()=>{
64
- // Set to empty state if input value is empty
65
- if (!inputValue.length) {
66
- safelySetColorValue(null);
67
- if (value === undefined || colorValue === null) setInputValue('');
68
- else setInputValue(colorValue.toString('hex'));
69
- return;
70
- }
71
- // if it failed to parse, then reset input to formatted version of current number
72
- if (parsedValue == null) {
73
- setInputValue(colorValue ? colorValue.toString('hex') : '');
74
- return;
75
- }
76
- safelySetColorValue(parsedValue);
77
- // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
78
- let newColorValue = '';
79
- if (colorValue) newColorValue = colorValue.toString('hex');
80
- setInputValue(newColorValue);
81
- validation.commitValidation();
82
- };
83
- let increment = ()=>{
84
- let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, step);
85
- // if we've arrived at the same value that was previously in the state, the
86
- // input value should be updated to match
87
- // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
88
- // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
89
- if (newValue === colorValue) setInputValue(newValue.toString('hex'));
90
- safelySetColorValue(newValue);
91
- validation.commitValidation();
92
- };
93
- let decrement = ()=>{
94
- let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, -step);
95
- // if we've arrived at the same value that was previously in the state, the
96
- // input value should be updated to match
97
- // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
98
- // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
99
- if (newValue === colorValue) setInputValue(newValue.toString('hex'));
100
- safelySetColorValue(newValue);
101
- validation.commitValidation();
102
- };
103
- let incrementToMax = ()=>safelySetColorValue($b335ada08155d9c0$var$MAX_COLOR);
104
- let decrementToMin = ()=>safelySetColorValue($b335ada08155d9c0$var$MIN_COLOR);
105
- let validate = (value)=>{
106
- var _value_match;
107
- return value === '' || !!((_value_match = value.match(/^#?[0-9a-f]{0,6}$/i)) === null || _value_match === void 0 ? void 0 : _value_match[0]);
108
- };
109
- return {
110
- ...validation,
111
- validate: validate,
112
- colorValue: colorValue,
113
- defaultColorValue: initialDefaultValue !== null && initialDefaultValue !== void 0 ? initialDefaultValue : initialValue,
114
- setColorValue: setColorValue,
115
- inputValue: inputValue,
116
- setInputValue: setInputValue,
117
- commit: commit,
118
- increment: increment,
119
- incrementToMax: incrementToMax,
120
- decrement: decrement,
121
- decrementToMin: decrementToMin
122
- };
123
- }
124
- function $b335ada08155d9c0$var$addColorValue(color, step) {
125
- let newColor = color ? color : $b335ada08155d9c0$var$MIN_COLOR;
126
- let colorInt = newColor.toHexInt();
127
- let clampInt = Math.min(Math.max(colorInt + step, $b335ada08155d9c0$var$MIN_COLOR_INT), $b335ada08155d9c0$var$MAX_COLOR_INT);
128
- if (clampInt !== colorInt) {
129
- let newColorString = `#${clampInt.toString(16).padStart(6, '0').toUpperCase()}`;
130
- newColor = (0, $799cddbef784668f$export$6e865ea70d7724f)(newColorString);
131
- }
132
- return newColor;
133
- }
134
-
135
-
136
- export {$b335ada08155d9c0$export$d52a01683abdfcd6 as useColorFieldState};
137
- //# sourceMappingURL=useColorFieldState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":"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","sources":["packages/@react-stately/color/src/useColorFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Color, ColorFieldProps} from '@react-types/color';\nimport {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {parseColor} from './Color';\nimport {useColor} from './useColor';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n readonly inputValue: string,\n /**\n * The currently parsed color value, or null if the field is empty.\n * Updated based on the `inputValue` as the user types.\n */\n readonly colorValue: Color | null,\n /** The default value of the color field. */\n readonly defaultColorValue: Color | null,\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void,\n /** Sets the current text value of the input. */\n setInputValue(value: string): void,\n /**\n * Updates the input value based on the currently parsed color value.\n * Typically this is called when the field is blurred.\n */\n commit(): void,\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void,\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void,\n /** Sets the current value to the maximum color value, and fires `onChange`. */\n incrementToMax(): void,\n /** Sets the current value to the minimum color value, and fires `onChange`. */\n decrementToMin(): void,\n /**\n * Validates a user input string.\n * Values can be partially entered, and may be valid even if they cannot currently be parsed to a color.\n * Can be used to implement validation as a user types.\n */\n validate(value: string): boolean\n}\n\nconst MIN_COLOR = parseColor('#000000');\nconst MAX_COLOR = parseColor('#FFFFFF');\nconst MIN_COLOR_INT = MIN_COLOR.toHexInt();\nconst MAX_COLOR_INT = MAX_COLOR.toHexInt();\n\n/**\n * Provides state management for a color field component. Color fields allow\n * users to enter and adjust a hex color value.\n */\nexport function useColorFieldState(\n props: ColorFieldProps\n): ColorFieldState {\n let {\n value,\n defaultValue,\n onChange\n } = props;\n let {step} = MIN_COLOR.getChannelRange('red');\n\n let initialDefaultValue = useColor(defaultValue);\n let [colorValue, setColorValue] = useControlledState<Color | null>(useColor(value), initialDefaultValue!, onChange);\n let [initialValue] = useState(colorValue);\n let [inputValue, setInputValue] = useState(() => (value || defaultValue) && colorValue ? colorValue.toString('hex') : '');\n\n let validation = useFormValidationState({\n ...props,\n value: colorValue\n });\n\n let safelySetColorValue = (newColor: Color | null) => {\n if (!colorValue || !newColor) {\n setColorValue(newColor);\n return;\n }\n if (newColor.toHexInt() !== colorValue.toHexInt()) {\n setColorValue(newColor);\n return;\n }\n };\n\n let [prevValue, setPrevValue] = useState(colorValue);\n if (prevValue !== colorValue) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n setPrevValue(colorValue);\n }\n\n let parsedValue = useMemo(() => {\n let color;\n try {\n color = parseColor(inputValue.startsWith('#') ? inputValue : `#${inputValue}`);\n } catch {\n color = null;\n }\n return color;\n }, [inputValue]);\n\n let commit = () => {\n // Set to empty state if input value is empty\n if (!inputValue.length) {\n safelySetColorValue(null);\n if (value === undefined || colorValue === null) {\n setInputValue('');\n } else {\n setInputValue(colorValue.toString('hex'));\n }\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (parsedValue == null) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n return;\n }\n\n safelySetColorValue(parsedValue);\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n let newColorValue = '';\n if (colorValue) {\n newColorValue = colorValue.toString('hex');\n }\n setInputValue(newColorValue);\n validation.commitValidation();\n };\n\n let increment = () => {\n let newValue = addColorValue(parsedValue, step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let decrement = () => {\n let newValue = addColorValue(parsedValue, -step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let incrementToMax = () => safelySetColorValue(MAX_COLOR);\n let decrementToMin = () => safelySetColorValue(MIN_COLOR);\n\n let validate = (value: string) => value === '' || !!value.match(/^#?[0-9a-f]{0,6}$/i)?.[0];\n\n return {\n ...validation,\n validate,\n colorValue,\n defaultColorValue: initialDefaultValue ?? initialValue,\n setColorValue,\n inputValue,\n setInputValue,\n commit,\n increment,\n incrementToMax,\n decrement,\n decrementToMin\n };\n}\n\nfunction addColorValue(color: Color, step: number) {\n let newColor = color ? color : MIN_COLOR;\n let colorInt = newColor.toHexInt();\n\n let clampInt = Math.min(Math.max(colorInt + step, MIN_COLOR_INT), MAX_COLOR_INT);\n if (clampInt !== colorInt) {\n let newColorString = `#${clampInt.toString(16).padStart(6, '0').toUpperCase()}`;\n newColor = parseColor(newColorString);\n }\n return newColor;\n}\n"],"names":[],"version":3,"file":"useColorFieldState.module.js.map"}
@@ -1,27 +0,0 @@
1
- var $83fe1a57d631223b$exports = require("./Color.main.js");
2
- var $f8b3be23ba4462b1$exports = require("./useColor.main.js");
3
- var $1Pz5H$reactstatelyutils = require("@react-stately/utils");
4
-
5
-
6
- function $parcel$export(e, n, v, s) {
7
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
- }
9
-
10
- $parcel$export(module.exports, "useColorPickerState", () => $f31788ea48a5c383$export$dc6b73b623f8645f);
11
-
12
-
13
-
14
- function $f31788ea48a5c383$export$dc6b73b623f8645f(props) {
15
- let value = (0, $f8b3be23ba4462b1$exports.useColor)(props.value);
16
- let defaultValue = (0, $f8b3be23ba4462b1$exports.useColor)(props.defaultValue || '#000000');
17
- let [color, setColor] = (0, $1Pz5H$reactstatelyutils.useControlledState)(value || undefined, defaultValue, props.onChange);
18
- return {
19
- color: color,
20
- setColor (color) {
21
- if (color != null) setColor(color || (0, $83fe1a57d631223b$exports.parseColor)('#000000'));
22
- }
23
- };
24
- }
25
-
26
-
27
- //# sourceMappingURL=useColorPickerState.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;;AAeO,SAAS,0CAAoB,KAAuB;IACzD,IAAI,QAAQ,CAAA,GAAA,kCAAO,EAAE,MAAM,KAAK;IAChC,IAAI,eAAe,CAAA,GAAA,kCAAO,EAAE,MAAM,YAAY,IAAI;IAClD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,2CAAiB,EAAE,SAAS,WAAW,cAAc,MAAM,QAAQ;IAE3F,OAAO;eACL;QACA,UAAS,KAAK;YACZ,IAAI,SAAS,MACX,SAAS,SAAS,CAAA,GAAA,oCAAS,EAAE;QAEjC;IACF;AACF","sources":["packages/@react-stately/color/src/useColorPickerState.ts"],"sourcesContent":["import {Color} from '@react-types/color';\nimport {parseColor} from './Color';\nimport {useColor} from './useColor';\nimport {useControlledState} from '@react-stately/utils';\nimport {ValueBase} from '@react-types/shared';\n\nexport interface ColorPickerProps extends ValueBase<string | Color, Color> {}\n\nexport interface ColorPickerState {\n /** The current color value of the color picker. */\n color: Color,\n /** Sets the current color value of the color picker. */\n setColor(color: Color | null): void\n}\n\nexport function useColorPickerState(props: ColorPickerProps): ColorPickerState {\n let value = useColor(props.value);\n let defaultValue = useColor(props.defaultValue || '#000000')!;\n let [color, setColor] = useControlledState(value || undefined, defaultValue, props.onChange);\n \n return {\n color,\n setColor(color) {\n if (color != null) {\n setColor(color || parseColor('#000000'));\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useColorPickerState.main.js.map"}
@@ -1,22 +0,0 @@
1
- import {parseColor as $799cddbef784668f$export$6e865ea70d7724f} from "./Color.mjs";
2
- import {useColor as $aa90ad8b2b1d015f$export$5aadd9c0606af5c2} from "./useColor.mjs";
3
- import {useControlledState as $5GESt$useControlledState} from "@react-stately/utils";
4
-
5
-
6
-
7
-
8
- function $309d2b7669014898$export$dc6b73b623f8645f(props) {
9
- let value = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(props.value);
10
- let defaultValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(props.defaultValue || '#000000');
11
- let [color, setColor] = (0, $5GESt$useControlledState)(value || undefined, defaultValue, props.onChange);
12
- return {
13
- color: color,
14
- setColor (color) {
15
- if (color != null) setColor(color || (0, $799cddbef784668f$export$6e865ea70d7724f)('#000000'));
16
- }
17
- };
18
- }
19
-
20
-
21
- export {$309d2b7669014898$export$dc6b73b623f8645f as useColorPickerState};
22
- //# sourceMappingURL=useColorPickerState.module.js.map
@@ -1,22 +0,0 @@
1
- import {parseColor as $799cddbef784668f$export$6e865ea70d7724f} from "./Color.module.js";
2
- import {useColor as $aa90ad8b2b1d015f$export$5aadd9c0606af5c2} from "./useColor.module.js";
3
- import {useControlledState as $5GESt$useControlledState} from "@react-stately/utils";
4
-
5
-
6
-
7
-
8
- function $309d2b7669014898$export$dc6b73b623f8645f(props) {
9
- let value = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(props.value);
10
- let defaultValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(props.defaultValue || '#000000');
11
- let [color, setColor] = (0, $5GESt$useControlledState)(value || undefined, defaultValue, props.onChange);
12
- return {
13
- color: color,
14
- setColor (color) {
15
- if (color != null) setColor(color || (0, $799cddbef784668f$export$6e865ea70d7724f)('#000000'));
16
- }
17
- };
18
- }
19
-
20
-
21
- export {$309d2b7669014898$export$dc6b73b623f8645f as useColorPickerState};
22
- //# sourceMappingURL=useColorPickerState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;AAeO,SAAS,0CAAoB,KAAuB;IACzD,IAAI,QAAQ,CAAA,GAAA,yCAAO,EAAE,MAAM,KAAK;IAChC,IAAI,eAAe,CAAA,GAAA,yCAAO,EAAE,MAAM,YAAY,IAAI;IAClD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,yBAAiB,EAAE,SAAS,WAAW,cAAc,MAAM,QAAQ;IAE3F,OAAO;eACL;QACA,UAAS,KAAK;YACZ,IAAI,SAAS,MACX,SAAS,SAAS,CAAA,GAAA,wCAAS,EAAE;QAEjC;IACF;AACF","sources":["packages/@react-stately/color/src/useColorPickerState.ts"],"sourcesContent":["import {Color} from '@react-types/color';\nimport {parseColor} from './Color';\nimport {useColor} from './useColor';\nimport {useControlledState} from '@react-stately/utils';\nimport {ValueBase} from '@react-types/shared';\n\nexport interface ColorPickerProps extends ValueBase<string | Color, Color> {}\n\nexport interface ColorPickerState {\n /** The current color value of the color picker. */\n color: Color,\n /** Sets the current color value of the color picker. */\n setColor(color: Color | null): void\n}\n\nexport function useColorPickerState(props: ColorPickerProps): ColorPickerState {\n let value = useColor(props.value);\n let defaultValue = useColor(props.defaultValue || '#000000')!;\n let [color, setColor] = useControlledState(value || undefined, defaultValue, props.onChange);\n \n return {\n color,\n setColor(color) {\n if (color != null) {\n setColor(color || parseColor('#000000'));\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useColorPickerState.module.js.map"}