@react-stately/color 3.5.4-nightly.4555 → 3.5.4-nightly.4560

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 (212) hide show
  1. package/dist/Color.main.js +770 -0
  2. package/dist/Color.main.js.map +1 -0
  3. package/dist/Color.mjs +764 -0
  4. package/dist/Color.module.js +764 -0
  5. package/dist/Color.module.js.map +1 -0
  6. package/dist/ar-AE.main.js +2 -2
  7. package/dist/ar-AE.main.js.map +1 -1
  8. package/dist/ar-AE.mjs +3 -3
  9. package/dist/ar-AE.module.js +2 -2
  10. package/dist/ar-AE.module.js.map +1 -1
  11. package/dist/bg-BG.main.js +2 -2
  12. package/dist/bg-BG.main.js.map +1 -1
  13. package/dist/bg-BG.mjs +3 -3
  14. package/dist/bg-BG.module.js +2 -2
  15. package/dist/bg-BG.module.js.map +1 -1
  16. package/dist/cs-CZ.main.js +2 -2
  17. package/dist/cs-CZ.main.js.map +1 -1
  18. package/dist/cs-CZ.mjs +3 -3
  19. package/dist/cs-CZ.module.js +2 -2
  20. package/dist/cs-CZ.module.js.map +1 -1
  21. package/dist/da-DK.main.js +2 -2
  22. package/dist/da-DK.main.js.map +1 -1
  23. package/dist/da-DK.mjs +3 -3
  24. package/dist/da-DK.module.js +2 -2
  25. package/dist/da-DK.module.js.map +1 -1
  26. package/dist/de-DE.main.js +2 -2
  27. package/dist/de-DE.main.js.map +1 -1
  28. package/dist/de-DE.mjs +3 -3
  29. package/dist/de-DE.module.js +2 -2
  30. package/dist/de-DE.module.js.map +1 -1
  31. package/dist/el-GR.main.js +2 -2
  32. package/dist/el-GR.main.js.map +1 -1
  33. package/dist/el-GR.mjs +3 -3
  34. package/dist/el-GR.module.js +2 -2
  35. package/dist/el-GR.module.js.map +1 -1
  36. package/dist/en-US.main.js +2 -2
  37. package/dist/en-US.main.js.map +1 -1
  38. package/dist/en-US.mjs +3 -3
  39. package/dist/en-US.module.js +2 -2
  40. package/dist/en-US.module.js.map +1 -1
  41. package/dist/es-ES.main.js +2 -2
  42. package/dist/es-ES.main.js.map +1 -1
  43. package/dist/es-ES.mjs +3 -3
  44. package/dist/es-ES.module.js +2 -2
  45. package/dist/es-ES.module.js.map +1 -1
  46. package/dist/et-EE.main.js +2 -2
  47. package/dist/et-EE.main.js.map +1 -1
  48. package/dist/et-EE.mjs +3 -3
  49. package/dist/et-EE.module.js +2 -2
  50. package/dist/et-EE.module.js.map +1 -1
  51. package/dist/fi-FI.main.js +2 -2
  52. package/dist/fi-FI.main.js.map +1 -1
  53. package/dist/fi-FI.mjs +3 -3
  54. package/dist/fi-FI.module.js +2 -2
  55. package/dist/fi-FI.module.js.map +1 -1
  56. package/dist/fr-FR.main.js +2 -2
  57. package/dist/fr-FR.main.js.map +1 -1
  58. package/dist/fr-FR.mjs +3 -3
  59. package/dist/fr-FR.module.js +2 -2
  60. package/dist/fr-FR.module.js.map +1 -1
  61. package/dist/he-IL.main.js +2 -2
  62. package/dist/he-IL.main.js.map +1 -1
  63. package/dist/he-IL.mjs +3 -3
  64. package/dist/he-IL.module.js +2 -2
  65. package/dist/he-IL.module.js.map +1 -1
  66. package/dist/hr-HR.main.js +2 -2
  67. package/dist/hr-HR.main.js.map +1 -1
  68. package/dist/hr-HR.mjs +3 -3
  69. package/dist/hr-HR.module.js +2 -2
  70. package/dist/hr-HR.module.js.map +1 -1
  71. package/dist/hu-HU.main.js +2 -2
  72. package/dist/hu-HU.main.js.map +1 -1
  73. package/dist/hu-HU.mjs +3 -3
  74. package/dist/hu-HU.module.js +2 -2
  75. package/dist/hu-HU.module.js.map +1 -1
  76. package/dist/import.mjs +5 -1303
  77. package/dist/intlStrings.main.js +108 -0
  78. package/dist/intlStrings.main.js.map +1 -0
  79. package/dist/intlStrings.mjs +110 -0
  80. package/dist/intlStrings.module.js +110 -0
  81. package/dist/intlStrings.module.js.map +1 -0
  82. package/dist/it-IT.main.js +2 -2
  83. package/dist/it-IT.main.js.map +1 -1
  84. package/dist/it-IT.mjs +3 -3
  85. package/dist/it-IT.module.js +2 -2
  86. package/dist/it-IT.module.js.map +1 -1
  87. package/dist/ja-JP.main.js +2 -2
  88. package/dist/ja-JP.main.js.map +1 -1
  89. package/dist/ja-JP.mjs +3 -3
  90. package/dist/ja-JP.module.js +2 -2
  91. package/dist/ja-JP.module.js.map +1 -1
  92. package/dist/ko-KR.main.js +2 -2
  93. package/dist/ko-KR.main.js.map +1 -1
  94. package/dist/ko-KR.mjs +3 -3
  95. package/dist/ko-KR.module.js +2 -2
  96. package/dist/ko-KR.module.js.map +1 -1
  97. package/dist/lt-LT.main.js +2 -2
  98. package/dist/lt-LT.main.js.map +1 -1
  99. package/dist/lt-LT.mjs +3 -3
  100. package/dist/lt-LT.module.js +2 -2
  101. package/dist/lt-LT.module.js.map +1 -1
  102. package/dist/lv-LV.main.js +2 -2
  103. package/dist/lv-LV.main.js.map +1 -1
  104. package/dist/lv-LV.mjs +3 -3
  105. package/dist/lv-LV.module.js +2 -2
  106. package/dist/lv-LV.module.js.map +1 -1
  107. package/dist/main.js +10 -1308
  108. package/dist/main.js.map +1 -1
  109. package/dist/module.js +5 -1303
  110. package/dist/module.js.map +1 -1
  111. package/dist/nb-NO.main.js +2 -2
  112. package/dist/nb-NO.main.js.map +1 -1
  113. package/dist/nb-NO.mjs +3 -3
  114. package/dist/nb-NO.module.js +2 -2
  115. package/dist/nb-NO.module.js.map +1 -1
  116. package/dist/nl-NL.main.js +2 -2
  117. package/dist/nl-NL.main.js.map +1 -1
  118. package/dist/nl-NL.mjs +3 -3
  119. package/dist/nl-NL.module.js +2 -2
  120. package/dist/nl-NL.module.js.map +1 -1
  121. package/dist/pl-PL.main.js +2 -2
  122. package/dist/pl-PL.main.js.map +1 -1
  123. package/dist/pl-PL.mjs +3 -3
  124. package/dist/pl-PL.module.js +2 -2
  125. package/dist/pl-PL.module.js.map +1 -1
  126. package/dist/pt-BR.main.js +2 -2
  127. package/dist/pt-BR.main.js.map +1 -1
  128. package/dist/pt-BR.mjs +3 -3
  129. package/dist/pt-BR.module.js +2 -2
  130. package/dist/pt-BR.module.js.map +1 -1
  131. package/dist/pt-PT.main.js +2 -2
  132. package/dist/pt-PT.main.js.map +1 -1
  133. package/dist/pt-PT.mjs +3 -3
  134. package/dist/pt-PT.module.js +2 -2
  135. package/dist/pt-PT.module.js.map +1 -1
  136. package/dist/ro-RO.main.js +2 -2
  137. package/dist/ro-RO.main.js.map +1 -1
  138. package/dist/ro-RO.mjs +3 -3
  139. package/dist/ro-RO.module.js +2 -2
  140. package/dist/ro-RO.module.js.map +1 -1
  141. package/dist/ru-RU.main.js +2 -2
  142. package/dist/ru-RU.main.js.map +1 -1
  143. package/dist/ru-RU.mjs +3 -3
  144. package/dist/ru-RU.module.js +2 -2
  145. package/dist/ru-RU.module.js.map +1 -1
  146. package/dist/sk-SK.main.js +2 -2
  147. package/dist/sk-SK.main.js.map +1 -1
  148. package/dist/sk-SK.mjs +3 -3
  149. package/dist/sk-SK.module.js +2 -2
  150. package/dist/sk-SK.module.js.map +1 -1
  151. package/dist/sl-SI.main.js +2 -2
  152. package/dist/sl-SI.main.js.map +1 -1
  153. package/dist/sl-SI.mjs +3 -3
  154. package/dist/sl-SI.module.js +2 -2
  155. package/dist/sl-SI.module.js.map +1 -1
  156. package/dist/sr-SP.main.js +2 -2
  157. package/dist/sr-SP.main.js.map +1 -1
  158. package/dist/sr-SP.mjs +3 -3
  159. package/dist/sr-SP.module.js +2 -2
  160. package/dist/sr-SP.module.js.map +1 -1
  161. package/dist/sv-SE.main.js +2 -2
  162. package/dist/sv-SE.main.js.map +1 -1
  163. package/dist/sv-SE.mjs +3 -3
  164. package/dist/sv-SE.module.js +2 -2
  165. package/dist/sv-SE.module.js.map +1 -1
  166. package/dist/tr-TR.main.js +2 -2
  167. package/dist/tr-TR.main.js.map +1 -1
  168. package/dist/tr-TR.mjs +3 -3
  169. package/dist/tr-TR.module.js +2 -2
  170. package/dist/tr-TR.module.js.map +1 -1
  171. package/dist/uk-UA.main.js +2 -2
  172. package/dist/uk-UA.main.js.map +1 -1
  173. package/dist/uk-UA.mjs +3 -3
  174. package/dist/uk-UA.module.js +2 -2
  175. package/dist/uk-UA.module.js.map +1 -1
  176. package/dist/useColor.main.js +36 -0
  177. package/dist/useColor.main.js.map +1 -0
  178. package/dist/useColor.mjs +31 -0
  179. package/dist/useColor.module.js +31 -0
  180. package/dist/useColor.module.js.map +1 -0
  181. package/dist/useColorAreaState.main.js +124 -0
  182. package/dist/useColorAreaState.main.js.map +1 -0
  183. package/dist/useColorAreaState.mjs +119 -0
  184. package/dist/useColorAreaState.module.js +119 -0
  185. package/dist/useColorAreaState.module.js.map +1 -0
  186. package/dist/useColorFieldState.main.js +138 -0
  187. package/dist/useColorFieldState.main.js.map +1 -0
  188. package/dist/useColorFieldState.mjs +133 -0
  189. package/dist/useColorFieldState.module.js +133 -0
  190. package/dist/useColorFieldState.module.js.map +1 -0
  191. package/dist/useColorSliderState.main.js +75 -0
  192. package/dist/useColorSliderState.main.js.map +1 -0
  193. package/dist/useColorSliderState.mjs +70 -0
  194. package/dist/useColorSliderState.module.js +70 -0
  195. package/dist/useColorSliderState.module.js.map +1 -0
  196. package/dist/useColorWheelState.main.js +123 -0
  197. package/dist/useColorWheelState.main.js.map +1 -0
  198. package/dist/useColorWheelState.mjs +118 -0
  199. package/dist/useColorWheelState.module.js +118 -0
  200. package/dist/useColorWheelState.module.js.map +1 -0
  201. package/dist/zh-CN.main.js +2 -2
  202. package/dist/zh-CN.main.js.map +1 -1
  203. package/dist/zh-CN.mjs +3 -3
  204. package/dist/zh-CN.module.js +2 -2
  205. package/dist/zh-CN.module.js.map +1 -1
  206. package/dist/zh-TW.main.js +2 -2
  207. package/dist/zh-TW.main.js.map +1 -1
  208. package/dist/zh-TW.mjs +3 -3
  209. package/dist/zh-TW.module.js +2 -2
  210. package/dist/zh-TW.module.js.map +1 -1
  211. package/package.json +9 -9
  212. package/src/Color.ts +13 -10
@@ -0,0 +1,138 @@
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 initialValue = (0, $f8b3be23ba4462b1$exports.useColor)(value);
36
+ let initialDefaultValue = (0, $f8b3be23ba4462b1$exports.useColor)(defaultValue);
37
+ let [colorValue, setColorValue] = (0, $41neA$reactstatelyutils.useControlledState)(initialValue, initialDefaultValue, onChange);
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 (err) {
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
+ setInputValue(value === undefined ? "" : colorValue.toString("hex"));
74
+ return;
75
+ }
76
+ // if it failed to parse, then reset input to formatted version of current number
77
+ if (parsedValue == null) {
78
+ setInputValue(colorValue ? colorValue.toString("hex") : "");
79
+ return;
80
+ }
81
+ safelySetColorValue(parsedValue);
82
+ // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
83
+ let newColorValue = "";
84
+ if (colorValue) newColorValue = colorValue.toString("hex");
85
+ setInputValue(newColorValue);
86
+ };
87
+ let increment = ()=>{
88
+ let newValue = $d59d0c2b2ce1568f$var$addColorValue(parsedValue, step);
89
+ // if we've arrived at the same value that was previously in the state, the
90
+ // input value should be updated to match
91
+ // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
92
+ // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
93
+ if (newValue === colorValue) setInputValue(newValue.toString("hex"));
94
+ safelySetColorValue(newValue);
95
+ validation.commitValidation();
96
+ };
97
+ let decrement = ()=>{
98
+ let newValue = $d59d0c2b2ce1568f$var$addColorValue(parsedValue, -step);
99
+ // if we've arrived at the same value that was previously in the state, the
100
+ // input value should be updated to match
101
+ // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
102
+ // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
103
+ if (newValue === colorValue) setInputValue(newValue.toString("hex"));
104
+ safelySetColorValue(newValue);
105
+ validation.commitValidation();
106
+ };
107
+ let incrementToMax = ()=>safelySetColorValue($d59d0c2b2ce1568f$var$MAX_COLOR);
108
+ let decrementToMin = ()=>safelySetColorValue($d59d0c2b2ce1568f$var$MIN_COLOR);
109
+ let validate = (value)=>{
110
+ var _value_match;
111
+ return value === "" || !!((_value_match = value.match(/^#?[0-9a-f]{0,6}$/i)) === null || _value_match === void 0 ? void 0 : _value_match[0]);
112
+ };
113
+ return {
114
+ ...validation,
115
+ validate: validate,
116
+ colorValue: colorValue,
117
+ inputValue: inputValue,
118
+ setInputValue: setInputValue,
119
+ commit: commit,
120
+ increment: increment,
121
+ incrementToMax: incrementToMax,
122
+ decrement: decrement,
123
+ decrementToMin: decrementToMin
124
+ };
125
+ }
126
+ function $d59d0c2b2ce1568f$var$addColorValue(color, step) {
127
+ let newColor = color ? color : $d59d0c2b2ce1568f$var$MIN_COLOR;
128
+ let colorInt = newColor.toHexInt();
129
+ let clampInt = Math.min(Math.max(colorInt + step, $d59d0c2b2ce1568f$var$MIN_COLOR_INT), $d59d0c2b2ce1568f$var$MAX_COLOR_INT);
130
+ if (clampInt !== colorInt) {
131
+ let newColorString = `#${clampInt.toString(16).padStart(6, "0").toUpperCase()}`;
132
+ newColor = (0, $83fe1a57d631223b$exports.parseColor)(newColorString);
133
+ }
134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W,QAAQ,QAAQ;IAC/B,IAAI,WAAW,SAAS,QAAQ;IAEhC,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,WAAW,MAAM,sCAAgB;IAClE,IAAI,aAAa,UAAU;QACzB,IAAI,iBAAiB,CAAC,CAAC,EAAE,SAAS,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG,KAAK,WAAW,GAAG,CAAC;QAC/E,WAAW,CAAA,GAAA,oCAAS,EAAE;IACxB;IACA,OAAO;AACT","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,\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 initialValue = useColor(value);\n let initialDefaultValue = useColor(defaultValue);\n let [colorValue, setColorValue] = useControlledState<Color>(initialValue, initialDefaultValue, onChange);\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) => {\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 (err) {\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 setInputValue(value === undefined ? '' : colorValue.toString('hex'));\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 };\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 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"}
@@ -0,0 +1,133 @@
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 initialValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(value);
30
+ let initialDefaultValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(defaultValue);
31
+ let [colorValue, setColorValue] = (0, $aP5W6$useControlledState)(initialValue, initialDefaultValue, onChange);
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 (err) {
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
+ setInputValue(value === undefined ? "" : colorValue.toString("hex"));
68
+ return;
69
+ }
70
+ // if it failed to parse, then reset input to formatted version of current number
71
+ if (parsedValue == null) {
72
+ setInputValue(colorValue ? colorValue.toString("hex") : "");
73
+ return;
74
+ }
75
+ safelySetColorValue(parsedValue);
76
+ // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
77
+ let newColorValue = "";
78
+ if (colorValue) newColorValue = colorValue.toString("hex");
79
+ setInputValue(newColorValue);
80
+ };
81
+ let increment = ()=>{
82
+ let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, step);
83
+ // if we've arrived at the same value that was previously in the state, the
84
+ // input value should be updated to match
85
+ // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
86
+ // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
87
+ if (newValue === colorValue) setInputValue(newValue.toString("hex"));
88
+ safelySetColorValue(newValue);
89
+ validation.commitValidation();
90
+ };
91
+ let decrement = ()=>{
92
+ let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, -step);
93
+ // if we've arrived at the same value that was previously in the state, the
94
+ // input value should be updated to match
95
+ // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
96
+ // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
97
+ if (newValue === colorValue) setInputValue(newValue.toString("hex"));
98
+ safelySetColorValue(newValue);
99
+ validation.commitValidation();
100
+ };
101
+ let incrementToMax = ()=>safelySetColorValue($b335ada08155d9c0$var$MAX_COLOR);
102
+ let decrementToMin = ()=>safelySetColorValue($b335ada08155d9c0$var$MIN_COLOR);
103
+ let validate = (value)=>{
104
+ var _value_match;
105
+ return value === "" || !!((_value_match = value.match(/^#?[0-9a-f]{0,6}$/i)) === null || _value_match === void 0 ? void 0 : _value_match[0]);
106
+ };
107
+ return {
108
+ ...validation,
109
+ validate: validate,
110
+ colorValue: colorValue,
111
+ inputValue: inputValue,
112
+ setInputValue: setInputValue,
113
+ commit: commit,
114
+ increment: increment,
115
+ incrementToMax: incrementToMax,
116
+ decrement: decrement,
117
+ decrementToMin: decrementToMin
118
+ };
119
+ }
120
+ function $b335ada08155d9c0$var$addColorValue(color, step) {
121
+ let newColor = color ? color : $b335ada08155d9c0$var$MIN_COLOR;
122
+ let colorInt = newColor.toHexInt();
123
+ let clampInt = Math.min(Math.max(colorInt + step, $b335ada08155d9c0$var$MIN_COLOR_INT), $b335ada08155d9c0$var$MAX_COLOR_INT);
124
+ if (clampInt !== colorInt) {
125
+ let newColorString = `#${clampInt.toString(16).padStart(6, "0").toUpperCase()}`;
126
+ newColor = (0, $799cddbef784668f$export$6e865ea70d7724f)(newColorString);
127
+ }
128
+ return newColor;
129
+ }
130
+
131
+
132
+ export {$b335ada08155d9c0$export$d52a01683abdfcd6 as useColorFieldState};
133
+ //# sourceMappingURL=useColorFieldState.mjs.map
@@ -0,0 +1,133 @@
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 initialValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(value);
30
+ let initialDefaultValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(defaultValue);
31
+ let [colorValue, setColorValue] = (0, $aP5W6$useControlledState)(initialValue, initialDefaultValue, onChange);
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 (err) {
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
+ setInputValue(value === undefined ? "" : colorValue.toString("hex"));
68
+ return;
69
+ }
70
+ // if it failed to parse, then reset input to formatted version of current number
71
+ if (parsedValue == null) {
72
+ setInputValue(colorValue ? colorValue.toString("hex") : "");
73
+ return;
74
+ }
75
+ safelySetColorValue(parsedValue);
76
+ // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
77
+ let newColorValue = "";
78
+ if (colorValue) newColorValue = colorValue.toString("hex");
79
+ setInputValue(newColorValue);
80
+ };
81
+ let increment = ()=>{
82
+ let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, step);
83
+ // if we've arrived at the same value that was previously in the state, the
84
+ // input value should be updated to match
85
+ // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
86
+ // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
87
+ if (newValue === colorValue) setInputValue(newValue.toString("hex"));
88
+ safelySetColorValue(newValue);
89
+ validation.commitValidation();
90
+ };
91
+ let decrement = ()=>{
92
+ let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, -step);
93
+ // if we've arrived at the same value that was previously in the state, the
94
+ // input value should be updated to match
95
+ // ex type 4, press increment, highlight the number in the input, type 4 again, press increment
96
+ // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input
97
+ if (newValue === colorValue) setInputValue(newValue.toString("hex"));
98
+ safelySetColorValue(newValue);
99
+ validation.commitValidation();
100
+ };
101
+ let incrementToMax = ()=>safelySetColorValue($b335ada08155d9c0$var$MAX_COLOR);
102
+ let decrementToMin = ()=>safelySetColorValue($b335ada08155d9c0$var$MIN_COLOR);
103
+ let validate = (value)=>{
104
+ var _value_match;
105
+ return value === "" || !!((_value_match = value.match(/^#?[0-9a-f]{0,6}$/i)) === null || _value_match === void 0 ? void 0 : _value_match[0]);
106
+ };
107
+ return {
108
+ ...validation,
109
+ validate: validate,
110
+ colorValue: colorValue,
111
+ inputValue: inputValue,
112
+ setInputValue: setInputValue,
113
+ commit: commit,
114
+ increment: increment,
115
+ incrementToMax: incrementToMax,
116
+ decrement: decrement,
117
+ decrementToMin: decrementToMin
118
+ };
119
+ }
120
+ function $b335ada08155d9c0$var$addColorValue(color, step) {
121
+ let newColor = color ? color : $b335ada08155d9c0$var$MIN_COLOR;
122
+ let colorInt = newColor.toHexInt();
123
+ let clampInt = Math.min(Math.max(colorInt + step, $b335ada08155d9c0$var$MIN_COLOR_INT), $b335ada08155d9c0$var$MAX_COLOR_INT);
124
+ if (clampInt !== colorInt) {
125
+ let newColorString = `#${clampInt.toString(16).padStart(6, "0").toUpperCase()}`;
126
+ newColor = (0, $799cddbef784668f$export$6e865ea70d7724f)(newColorString);
127
+ }
128
+ return newColor;
129
+ }
130
+
131
+
132
+ export {$b335ada08155d9c0$export$d52a01683abdfcd6 as useColorFieldState};
133
+ //# sourceMappingURL=useColorFieldState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2CD,MAAM,kCAAY,CAAA,GAAA,wCAA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,CAAC,EAAE,SAAS,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG,KAAK,WAAW,GAAG,CAAC;QAC/E,WAAW,CAAA,GAAA,wCAAS,EAAE;IACxB;IACA,OAAO;AACT","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,\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 initialValue = useColor(value);\n let initialDefaultValue = useColor(defaultValue);\n let [colorValue, setColorValue] = useControlledState<Color>(initialValue, initialDefaultValue, onChange);\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) => {\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 (err) {\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 setInputValue(value === undefined ? '' : colorValue.toString('hex'));\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 };\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 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"}
@@ -0,0 +1,75 @@
1
+ var $83fe1a57d631223b$exports = require("./Color.main.js");
2
+ var $93tpS$reactstatelyslider = require("@react-stately/slider");
3
+ var $93tpS$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, "useColorSliderState", () => $5386a492cfd3234c$export$57bc203e1c9c6d44);
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ function $5386a492cfd3234c$export$57bc203e1c9c6d44(props) {
25
+ let { channel: channel, value: value, defaultValue: defaultValue, onChange: onChange, locale: locale, ...otherProps } = props;
26
+ if (value == null && defaultValue == null) throw new Error("useColorSliderState requires a value or defaultValue");
27
+ let [color, setColor] = (0, $93tpS$reactstatelyutils.useControlledState)(value && (0, $83fe1a57d631223b$exports.normalizeColor)(value), defaultValue && (0, $83fe1a57d631223b$exports.normalizeColor)(defaultValue), onChange);
28
+ let sliderState = (0, $93tpS$reactstatelyslider.useSliderState)({
29
+ ...color.getChannelRange(channel),
30
+ ...otherProps,
31
+ // Unused except in getThumbValueLabel, which is overridden below. null to appease TypeScript.
32
+ numberFormatter: null,
33
+ value: color.getChannelValue(channel),
34
+ onChange (v) {
35
+ setColor(color.withChannelValue(channel, v));
36
+ },
37
+ onChangeEnd (v) {
38
+ // onChange will have already been called with the right value, this is just to trigger onChangeEnd
39
+ if (props.onChangeEnd) props.onChangeEnd(color.withChannelValue(channel, v));
40
+ }
41
+ });
42
+ let { step: step, pageSize: pageSize } = color.getChannelRange(channel);
43
+ return {
44
+ ...sliderState,
45
+ value: color,
46
+ setValue (value) {
47
+ setColor((0, $83fe1a57d631223b$exports.normalizeColor)(value));
48
+ },
49
+ getDisplayColor () {
50
+ switch(channel){
51
+ case "hue":
52
+ return (0, $83fe1a57d631223b$exports.parseColor)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
53
+ case "lightness":
54
+ case "brightness":
55
+ case "saturation":
56
+ case "red":
57
+ case "green":
58
+ case "blue":
59
+ return color.withChannelValue("alpha", 1);
60
+ case "alpha":
61
+ return color;
62
+ default:
63
+ throw new Error("Unknown color channel: " + channel);
64
+ }
65
+ },
66
+ getThumbValueLabel () {
67
+ return color.formatChannelValue(channel, locale);
68
+ },
69
+ step: step,
70
+ pageSize: pageSize
71
+ };
72
+ }
73
+
74
+
75
+ //# sourceMappingURL=useColorSliderState.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA0BM,SAAS,0CAAoB,KAA8B;IAChE,IAAI,WAAC,OAAO,SAAE,KAAK,gBAAE,YAAY,YAAE,QAAQ,UAAE,MAAM,EAAE,GAAG,YAAW,GAAG;IACtE,IAAI,SAAS,QAAQ,gBAAgB,MACnC,MAAM,IAAI,MAAM;IAGlB,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,2CAAiB,EAAE,SAAS,CAAA,GAAA,wCAAa,EAAE,QAAQ,gBAAgB,CAAA,GAAA,wCAAa,EAAE,eAAe;IACzH,IAAI,cAAc,CAAA,GAAA,wCAAa,EAAE;QAC/B,GAAG,MAAM,eAAe,CAAC,QAAQ;QACjC,GAAG,UAAU;QACb,8FAA8F;QAC9F,iBAAiB;QACjB,OAAO,MAAM,eAAe,CAAC;QAC7B,UAAS,CAAC;YACR,SAAS,MAAM,gBAAgB,CAAC,SAAS;QAC3C;QACA,aAAY,CAAC;YACX,mGAAmG;YACnG,IAAI,MAAM,WAAW,EACnB,MAAM,WAAW,CAAC,MAAM,gBAAgB,CAAC,SAAS;QAEtD;IACF;IAEA,IAAI,QAAC,IAAI,YAAE,QAAQ,EAAC,GAAG,MAAM,eAAe,CAAC;IAC7C,OAAO;QACL,GAAG,WAAW;QACd,OAAO;QACP,UAAS,KAAK;YACZ,SAAS,CAAA,GAAA,wCAAa,EAAE;QAC1B;QACA;YACE,OAAQ;gBACN,KAAK;oBACH,OAAO,CAAA,GAAA,oCAAS,EAAE,CAAC,IAAI,EAAE,MAAM,eAAe,CAAC,OAAO,YAAY,CAAC;gBACrE,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;oBACH,OAAO,MAAM,gBAAgB,CAAC,SAAS;gBACzC,KAAK;oBACH,OAAO;gBAET;oBACE,MAAM,IAAI,MAAM,4BAA4B;YAChD;QACF;QACA;YACE,OAAO,MAAM,kBAAkB,CAAC,SAAS;QAC3C;cACA;kBACA;IACF;AACF","sources":["packages/@react-stately/color/src/useColorSliderState.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, ColorSliderProps} from '@react-types/color';\nimport {normalizeColor, parseColor} from './Color';\nimport {SliderState, useSliderState} from '@react-stately/slider';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface ColorSliderState extends SliderState {\n /** The current color value represented by the color slider. */\n readonly value: Color,\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void,\n /** Returns the color that should be displayed in the slider instead of `value` or the optional parameter. */\n getDisplayColor(): Color\n}\n\n\nexport interface ColorSliderStateOptions extends ColorSliderProps {\n /** The locale to use for formatting the color channel value. */\n locale: string\n}\n\n/**\n * Provides state management for a color slider component.\n * Color sliders allow users to adjust an individual channel of a color value.\n */\nexport function useColorSliderState(props: ColorSliderStateOptions): ColorSliderState {\n let {channel, value, defaultValue, onChange, locale, ...otherProps} = props;\n if (value == null && defaultValue == null) {\n throw new Error('useColorSliderState requires a value or defaultValue');\n }\n\n let [color, setColor] = useControlledState(value && normalizeColor(value), defaultValue && normalizeColor(defaultValue), onChange);\n let sliderState = useSliderState({\n ...color.getChannelRange(channel),\n ...otherProps,\n // Unused except in getThumbValueLabel, which is overridden below. null to appease TypeScript.\n numberFormatter: null,\n value: color.getChannelValue(channel),\n onChange(v) {\n setColor(color.withChannelValue(channel, v));\n },\n onChangeEnd(v) {\n // onChange will have already been called with the right value, this is just to trigger onChangeEnd\n if (props.onChangeEnd) {\n props.onChangeEnd(color.withChannelValue(channel, v));\n }\n }\n });\n\n let {step, pageSize} = color.getChannelRange(channel);\n return {\n ...sliderState,\n value: color,\n setValue(value) {\n setColor(normalizeColor(value));\n },\n getDisplayColor() {\n switch (channel) {\n case 'hue':\n return parseColor(`hsl(${color.getChannelValue('hue')}, 100%, 50%)`);\n case 'lightness':\n case 'brightness':\n case 'saturation':\n case 'red':\n case 'green':\n case 'blue':\n return color.withChannelValue('alpha', 1);\n case 'alpha': {\n return color;\n }\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n },\n getThumbValueLabel() {\n return color.formatChannelValue(channel, locale);\n },\n step,\n pageSize\n };\n}\n"],"names":[],"version":3,"file":"useColorSliderState.main.js.map"}
@@ -0,0 +1,70 @@
1
+ import {normalizeColor as $799cddbef784668f$export$4cde5df63f53f473, parseColor as $799cddbef784668f$export$6e865ea70d7724f} from "./Color.mjs";
2
+ import {useSliderState as $1Eavr$useSliderState} from "@react-stately/slider";
3
+ import {useControlledState as $1Eavr$useControlledState} from "@react-stately/utils";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $25a25ac0d1624665$export$57bc203e1c9c6d44(props) {
19
+ let { channel: channel, value: value, defaultValue: defaultValue, onChange: onChange, locale: locale, ...otherProps } = props;
20
+ if (value == null && defaultValue == null) throw new Error("useColorSliderState requires a value or defaultValue");
21
+ let [color, setColor] = (0, $1Eavr$useControlledState)(value && (0, $799cddbef784668f$export$4cde5df63f53f473)(value), defaultValue && (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue), onChange);
22
+ let sliderState = (0, $1Eavr$useSliderState)({
23
+ ...color.getChannelRange(channel),
24
+ ...otherProps,
25
+ // Unused except in getThumbValueLabel, which is overridden below. null to appease TypeScript.
26
+ numberFormatter: null,
27
+ value: color.getChannelValue(channel),
28
+ onChange (v) {
29
+ setColor(color.withChannelValue(channel, v));
30
+ },
31
+ onChangeEnd (v) {
32
+ // onChange will have already been called with the right value, this is just to trigger onChangeEnd
33
+ if (props.onChangeEnd) props.onChangeEnd(color.withChannelValue(channel, v));
34
+ }
35
+ });
36
+ let { step: step, pageSize: pageSize } = color.getChannelRange(channel);
37
+ return {
38
+ ...sliderState,
39
+ value: color,
40
+ setValue (value) {
41
+ setColor((0, $799cddbef784668f$export$4cde5df63f53f473)(value));
42
+ },
43
+ getDisplayColor () {
44
+ switch(channel){
45
+ case "hue":
46
+ return (0, $799cddbef784668f$export$6e865ea70d7724f)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
47
+ case "lightness":
48
+ case "brightness":
49
+ case "saturation":
50
+ case "red":
51
+ case "green":
52
+ case "blue":
53
+ return color.withChannelValue("alpha", 1);
54
+ case "alpha":
55
+ return color;
56
+ default:
57
+ throw new Error("Unknown color channel: " + channel);
58
+ }
59
+ },
60
+ getThumbValueLabel () {
61
+ return color.formatChannelValue(channel, locale);
62
+ },
63
+ step: step,
64
+ pageSize: pageSize
65
+ };
66
+ }
67
+
68
+
69
+ export {$25a25ac0d1624665$export$57bc203e1c9c6d44 as useColorSliderState};
70
+ //# sourceMappingURL=useColorSliderState.mjs.map