@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,196 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {Color, ColorWheelProps} from '@react-types/color';
14
- import {normalizeColor, parseColor} from './Color';
15
- import {useControlledState} from '@react-stately/utils';
16
- import {useMemo, useRef, useState} from 'react';
17
-
18
- export interface ColorWheelState {
19
- /** The current color value represented by the color wheel. */
20
- readonly value: Color,
21
- /** The default color value. */
22
- readonly defaultValue: Color,
23
- /** Sets the color value represented by the color wheel, and triggers `onChange`. */
24
- setValue(value: string | Color): void,
25
-
26
- /** The current value of the hue channel displayed by the color wheel. */
27
- readonly hue: number,
28
- /** Sets the hue channel of the current color value and triggers `onChange`. */
29
- setHue(value: number): void,
30
-
31
- /** Sets the hue channel of the current color value based on the given coordinates and radius of the color wheel, and triggers `onChange`. */
32
- setHueFromPoint(x: number, y: number, radius: number): void,
33
- /** Returns the coordinates of the thumb relative to the center point of the color wheel. */
34
- getThumbPosition(radius: number): {x: number, y: number},
35
-
36
- /** Increments the hue by the given amount (defaults to 1). */
37
- increment(stepSize?: number): void,
38
- /** Decrements the hue by the given amount (defaults to 1). */
39
- decrement(stepSize?: number): void,
40
-
41
- /** Whether the color wheel is currently being dragged. */
42
- readonly isDragging: boolean,
43
- /** Sets whether the color wheel is being dragged. */
44
- setDragging(value: boolean): void,
45
- /** Returns the color that should be displayed in the color wheel instead of `value`. */
46
- getDisplayColor(): Color,
47
- /** The step value of the hue channel, used when incrementing and decrementing. */
48
- step: number,
49
- /** The page step value of the hue channel, used when incrementing and decrementing. */
50
- pageStep: number,
51
-
52
- /** Whether the color wheel is disabled. */
53
- readonly isDisabled: boolean
54
- }
55
-
56
- const DEFAULT_COLOR = parseColor('hsl(0, 100%, 50%)');
57
-
58
- function roundToStep(value: number, step: number): number {
59
- return Math.round(value / step) * step;
60
- }
61
-
62
- function mod(n: number, m: number) {
63
- return ((n % m) + m) % m;
64
- }
65
-
66
- function roundDown(v: number) {
67
- let r = Math.floor(v);
68
- if (r === v) {
69
- return v - 1;
70
- } else {
71
- return r;
72
- }
73
- }
74
-
75
- function degToRad(deg: number) {
76
- return deg * Math.PI / 180;
77
- }
78
-
79
- function radToDeg(rad: number) {
80
- return rad * 180 / Math.PI;
81
- }
82
-
83
- // 0deg = 3 o'clock. increases clockwise
84
- function angleToCartesian(angle: number, radius: number): {x: number, y: number} {
85
- let rad = degToRad(360 - angle + 90);
86
- let x = Math.sin(rad) * (radius);
87
- let y = Math.cos(rad) * (radius);
88
- return {x, y};
89
- }
90
-
91
- function cartesianToAngle(x: number, y: number, radius: number): number {
92
- let deg = radToDeg(Math.atan2(y / radius, x / radius));
93
- return (deg + 360) % 360;
94
- }
95
-
96
- /**
97
- * Provides state management for a color wheel component.
98
- * Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.
99
- */
100
- export function useColorWheelState(props: ColorWheelProps): ColorWheelState {
101
- let {value: propsValue, defaultValue, onChange, onChangeEnd} = props;
102
-
103
- if (!propsValue && !defaultValue) {
104
- defaultValue = DEFAULT_COLOR;
105
- }
106
- if (propsValue) {
107
- propsValue = normalizeColor(propsValue);
108
- }
109
- if (defaultValue) {
110
- defaultValue = normalizeColor(defaultValue);
111
- }
112
-
113
- // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default
114
- let [stateValue, setValueState] = useControlledState<Color>(propsValue as Color, defaultValue as Color, onChange);
115
- let [initialValue] = useState(stateValue);
116
- let value = useMemo(() => {
117
- let colorSpace = stateValue.getColorSpace();
118
- return colorSpace === 'hsl' || colorSpace === 'hsb' ? stateValue : stateValue.toFormat('hsl');
119
- }, [stateValue]);
120
- let valueRef = useRef(value);
121
- let setValue = (value: Color) => {
122
- valueRef.current = value;
123
- setValueState(value);
124
- };
125
-
126
- let channelRange = value.getChannelRange('hue');
127
- let {minValue: minValueX, maxValue: maxValueX, step: step, pageSize: pageStep} = channelRange;
128
- let [isDragging, setDragging] = useState(false);
129
- let isDraggingRef = useRef(false);
130
-
131
- let hue = value.getChannelValue('hue');
132
- function setHue(v: number) {
133
- if (v > 360) {
134
- // Make sure you can always get back to 0.
135
- v = 0;
136
- }
137
- v = roundToStep(mod(v, 360), step);
138
- if (hue !== v) {
139
- let color = value.withChannelValue('hue', v);
140
- setValue(color);
141
- }
142
- }
143
-
144
- return {
145
- value,
146
- defaultValue: propsValue !== undefined ? initialValue : defaultValue as Color,
147
- step,
148
- pageStep,
149
- setValue(v) {
150
- let color = normalizeColor(v);
151
- setValue(color);
152
- },
153
- hue,
154
- setHue,
155
- setHueFromPoint(x, y, radius) {
156
- setHue(cartesianToAngle(x, y, radius));
157
- },
158
- getThumbPosition(radius) {
159
- return angleToCartesian(value.getChannelValue('hue'), radius);
160
- },
161
- increment(stepSize = 1) {
162
- let s = Math.max(stepSize, step);
163
- let newValue = hue + s;
164
- if (newValue >= maxValueX) {
165
- // Make sure you can always get back to 0.
166
- newValue = minValueX;
167
- }
168
- setHue(roundToStep(mod(newValue, 360), s));
169
- },
170
- decrement(stepSize = 1) {
171
- let s = Math.max(stepSize, step);
172
- if (hue === 0) {
173
- // We can't just subtract step because this might be the case:
174
- // |(previous step) - 0| < step size
175
- setHue(roundDown(360 / s) * s);
176
- } else {
177
- setHue(roundToStep(mod(hue - s, 360), s));
178
- }
179
- },
180
- setDragging(isDragging) {
181
- let wasDragging = isDraggingRef.current;
182
- isDraggingRef.current = isDragging;
183
-
184
- if (onChangeEnd && !isDragging && wasDragging) {
185
- onChangeEnd(valueRef.current);
186
- }
187
-
188
- setDragging(isDragging);
189
- },
190
- isDragging,
191
- getDisplayColor() {
192
- return value.toFormat('hsl').withChannelValue('saturation', 100).withChannelValue('lightness', 50).withChannelValue('alpha', 1);
193
- },
194
- isDisabled: props.isDisabled || false
195
- };
196
- }