@react-aria/color 3.0.0-beta.6 → 3.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -1,493 +1,907 @@
1
- import { useSpinButton } from "@react-aria/spinbutton";
2
- import { useFormattedTextField } from "@react-aria/textfield";
3
- import { useKeyboard, useMove, useFocusWithin, useScrollWheel } from "@react-aria/interactions";
4
- import { useCallback, useRef, useState } from "react";
5
- import { useSlider, useSliderThumb } from "@react-aria/slider";
6
- import { useLocale } from "@react-aria/i18n";
7
- import { mergeProps, focusWithoutScrolling, useGlobalListeners, useLabels, useId } from "@react-aria/utils";
8
- import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
9
-
10
- /**
11
- * Provides the behavior and accessibility implementation for a color slider component.
12
- * Color sliders allow users to adjust an individual channel of a color value.
13
- */
14
- export function useColorSlider(props, state) {
15
- let {
16
- trackRef,
17
- inputRef,
18
- orientation,
19
- channel,
20
- 'aria-label': ariaLabel
21
- } = props;
22
- let {
23
- locale,
24
- direction
25
- } = useLocale(); // Provide a default aria-label if there is no other label provided.
26
-
27
- if (!props.label && !ariaLabel && !props['aria-labelledby']) {
28
- ariaLabel = state.value.getChannelName(channel, locale);
29
- } // @ts-ignore - ignore unused incompatible props
30
-
31
-
32
- let {
33
- groupProps,
34
- trackProps,
35
- labelProps,
36
- outputProps
37
- } = useSlider(_babelRuntimeHelpersEsmExtends({}, props, {
38
- 'aria-label': ariaLabel
39
- }), state, trackRef);
40
- let {
41
- inputProps,
42
- thumbProps
43
- } = useSliderThumb({
44
- index: 0,
45
- orientation,
46
- isDisabled: props.isDisabled,
47
- trackRef,
48
- inputRef
49
- }, state);
50
-
51
- let generateBackground = () => {
52
- let value = state.getDisplayColor();
53
- let to;
54
-
55
- if (orientation === 'vertical') {
56
- to = 'top';
57
- } else if (direction === 'ltr') {
58
- to = 'right';
59
- } else {
60
- to = 'left';
61
- }
62
-
63
- switch (channel) {
64
- case 'hue':
65
- return "linear-gradient(to " + to + ", rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)";
66
-
67
- case 'lightness':
68
- {
69
- // We have to add an extra color stop in the middle so that the hue shows up at all.
70
- // Otherwise it will always just be black to white.
71
- let min = state.getThumbMinValue(0);
72
- let max = state.getThumbMaxValue(0);
73
- let start = value.withChannelValue(channel, min).toString('css');
74
- let middle = value.withChannelValue(channel, (max - min) / 2).toString('css');
75
- let end = value.withChannelValue(channel, max).toString('css');
76
- return "linear-gradient(to " + to + ", " + start + ", " + middle + ", " + end + ")";
77
- }
1
+ import {useGlobalListeners as $7KHxM$useGlobalListeners, focusWithoutScrolling as $7KHxM$focusWithoutScrolling, mergeProps as $7KHxM$mergeProps, isIOS as $7KHxM$isIOS, isAndroid as $7KHxM$isAndroid, useLabels as $7KHxM$useLabels, useId as $7KHxM$useId} from "@react-aria/utils";
2
+ import {useRef as $7KHxM$useRef, useCallback as $7KHxM$useCallback, useState as $7KHxM$useState} from "react";
3
+ import {useKeyboard as $7KHxM$useKeyboard, useMove as $7KHxM$useMove, useFocusWithin as $7KHxM$useFocusWithin, useScrollWheel as $7KHxM$useScrollWheel} from "@react-aria/interactions";
4
+ import {useMessageFormatter as $7KHxM$useMessageFormatter, useLocale as $7KHxM$useLocale} from "@react-aria/i18n";
5
+ import {useVisuallyHidden as $7KHxM$useVisuallyHidden} from "@react-aria/visually-hidden";
6
+ import {useSlider as $7KHxM$useSlider, useSliderThumb as $7KHxM$useSliderThumb} from "@react-aria/slider";
7
+ import {useFormattedTextField as $7KHxM$useFormattedTextField} from "@react-aria/textfield";
8
+ import {useSpinButton as $7KHxM$useSpinButton} from "@react-aria/spinbutton";
9
+
10
+ function $parcel$interopDefault(a) {
11
+ return a && a.__esModule ? a.default : a;
12
+ }
13
+ function $parcel$export(e, n, v, s) {
14
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
15
+ }
16
+ var $60bd7d6e45dcddfa$exports = {};
17
+
18
+ $parcel$export($60bd7d6e45dcddfa$exports, "useColorArea", () => $60bd7d6e45dcddfa$export$2f92a7a615a014f6);
19
+
20
+ var $052cfdf4c32eb7c3$exports = {};
21
+ var $eccab2b0118aef08$exports = {};
22
+ $eccab2b0118aef08$exports = JSON.parse("{\"twoDimensionalSlider\":\"شريط تمرير ثنائي الأبعاد\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
23
+
24
+
25
+ var $bf2b4507594e3d45$exports = {};
26
+ $bf2b4507594e3d45$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D плъзгач\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
27
+
28
+
29
+ var $01c08487af7ecd14$exports = {};
30
+ $01c08487af7ecd14$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D posuvník\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
31
+
32
+
33
+ var $5e997db6ea0d10f6$exports = {};
34
+ $5e997db6ea0d10f6$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D-skyder\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
35
+
36
+
37
+ var $fe5998f640a79fd2$exports = {};
38
+ $fe5998f640a79fd2$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D-Schieberegler\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
39
+
40
+
41
+ var $18e4d1d5b500a9ee$exports = {};
42
+ $18e4d1d5b500a9ee$exports = JSON.parse("{\"twoDimensionalSlider\":\"Ρυθμιστικό 2D\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
43
+
44
+
45
+ var $bf90a11a7a42a0f7$exports = {};
46
+ $bf90a11a7a42a0f7$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D slider\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
47
+
48
+
49
+ var $dd0d25f885b5c5f3$exports = {};
50
+ $dd0d25f885b5c5f3$exports = JSON.parse("{\"twoDimensionalSlider\":\"Control deslizante en 2D\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
51
+
52
+
53
+ var $d950967017e3485b$exports = {};
54
+ $d950967017e3485b$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D-liugur\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
55
+
56
+
57
+ var $00a415a3f0ab315a$exports = {};
58
+ $00a415a3f0ab315a$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D-liukusäädin\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
59
+
60
+
61
+ var $d80f30fe86c95741$exports = {};
62
+ $d80f30fe86c95741$exports = JSON.parse("{\"twoDimensionalSlider\":\"Curseur 2D\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
63
+
64
+
65
+ var $6912afb584340a2e$exports = {};
66
+ $6912afb584340a2e$exports = JSON.parse("{\"twoDimensionalSlider\":\"מחוון דו-ממדי\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
67
+
68
+
69
+ var $7b97fcacd84ec90f$exports = {};
70
+ $7b97fcacd84ec90f$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D kliznik\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
71
+
72
+
73
+ var $da9b443e89eebc6b$exports = {};
74
+ $da9b443e89eebc6b$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D csúszka\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
75
+
76
+
77
+ var $35f135b45eb4d95b$exports = {};
78
+ $35f135b45eb4d95b$exports = JSON.parse("{\"twoDimensionalSlider\":\"Dispositivo di scorrimento 2D\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
79
+
80
+
81
+ var $760b09448e39c6cd$exports = {};
82
+ $760b09448e39c6cd$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D スライダー\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
83
+
84
+
85
+ var $fc7b7d43be9703ec$exports = {};
86
+ $fc7b7d43be9703ec$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D 슬라이더\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
87
+
88
+
89
+ var $74918a1664156912$exports = {};
90
+ $74918a1664156912$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D slankiklis\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
91
+
92
+
93
+ var $4e6cde11c2bc9840$exports = {};
94
+ $4e6cde11c2bc9840$exports = JSON.parse("{\"twoDimensionalSlider\":\"Plaknes slīdnis\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
95
+
96
+
97
+ var $6faa3defebc3eb72$exports = {};
98
+ $6faa3defebc3eb72$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D-glidebryter\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
99
+
100
+
101
+ var $6ac9b6b1b7e3ca12$exports = {};
102
+ $6ac9b6b1b7e3ca12$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D-schuifregelaar\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
103
+
104
+
105
+ var $1be8b0ee8841f1e7$exports = {};
106
+ $1be8b0ee8841f1e7$exports = JSON.parse("{\"twoDimensionalSlider\":\"Suwak 2D\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
107
+
108
+
109
+ var $f9507c2d404ed689$exports = {};
110
+ $f9507c2d404ed689$exports = JSON.parse("{\"twoDimensionalSlider\":\"Controle deslizante 2D\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
111
+
112
+
113
+ var $8f872ea59c02d67e$exports = {};
114
+ $8f872ea59c02d67e$exports = JSON.parse("{\"twoDimensionalSlider\":\"Controlo de deslize 2D\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
78
115
 
79
- case 'saturation':
80
- case 'brightness':
81
- case 'red':
82
- case 'green':
83
- case 'blue':
84
- case 'alpha':
85
- {
86
- let start = value.withChannelValue(channel, state.getThumbMinValue(0)).toString('css');
87
- let end = value.withChannelValue(channel, state.getThumbMaxValue(0)).toString('css');
88
- return "linear-gradient(to " + to + ", " + start + ", " + end + ")";
116
+
117
+ var $b03b45b62a7ccae4$exports = {};
118
+ $b03b45b62a7ccae4$exports = JSON.parse("{\"twoDimensionalSlider\":\"Cursor 2D\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
119
+
120
+
121
+ var $f1107d94c09df9b8$exports = {};
122
+ $f1107d94c09df9b8$exports = JSON.parse("{\"twoDimensionalSlider\":\"Двумерный ползунок\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
123
+
124
+
125
+ var $b61325f242fafc7c$exports = {};
126
+ $b61325f242fafc7c$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D jazdec\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
127
+
128
+
129
+ var $f44b7cf39ac8f315$exports = {};
130
+ $f44b7cf39ac8f315$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D-drsnik\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
131
+
132
+
133
+ var $aa8cd83fc8d4982b$exports = {};
134
+ $aa8cd83fc8d4982b$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D клизач\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
135
+
136
+
137
+ var $7c4f4e5bb7c06f1e$exports = {};
138
+ $7c4f4e5bb7c06f1e$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D-reglage\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
139
+
140
+
141
+ var $8045cf930ef745aa$exports = {};
142
+ $8045cf930ef745aa$exports = JSON.parse("{\"twoDimensionalSlider\":\"2B slayt gösterisi\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
143
+
144
+
145
+ var $ee2044a77f24b118$exports = {};
146
+ $ee2044a77f24b118$exports = JSON.parse("{\"twoDimensionalSlider\":\"Повзунок 2D\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
147
+
148
+
149
+ var $4e1dbc65a687dd93$exports = {};
150
+ $4e1dbc65a687dd93$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D 滑块\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
151
+
152
+
153
+ var $b0fef28529309aa6$exports = {};
154
+ $b0fef28529309aa6$exports = JSON.parse("{\"twoDimensionalSlider\":\"2D 滑桿\",\"colorNameAndValue\":\"{name}: {value}\",\"x/y\":\"{x} / {y}\"}");
155
+
156
+
157
+ $052cfdf4c32eb7c3$exports = {
158
+ "ar-AE": $eccab2b0118aef08$exports,
159
+ "bg-BG": $bf2b4507594e3d45$exports,
160
+ "cs-CZ": $01c08487af7ecd14$exports,
161
+ "da-DK": $5e997db6ea0d10f6$exports,
162
+ "de-DE": $fe5998f640a79fd2$exports,
163
+ "el-GR": $18e4d1d5b500a9ee$exports,
164
+ "en-US": $bf90a11a7a42a0f7$exports,
165
+ "es-ES": $dd0d25f885b5c5f3$exports,
166
+ "et-EE": $d950967017e3485b$exports,
167
+ "fi-FI": $00a415a3f0ab315a$exports,
168
+ "fr-FR": $d80f30fe86c95741$exports,
169
+ "he-IL": $6912afb584340a2e$exports,
170
+ "hr-HR": $7b97fcacd84ec90f$exports,
171
+ "hu-HU": $da9b443e89eebc6b$exports,
172
+ "it-IT": $35f135b45eb4d95b$exports,
173
+ "ja-JP": $760b09448e39c6cd$exports,
174
+ "ko-KR": $fc7b7d43be9703ec$exports,
175
+ "lt-LT": $74918a1664156912$exports,
176
+ "lv-LV": $4e6cde11c2bc9840$exports,
177
+ "nb-NO": $6faa3defebc3eb72$exports,
178
+ "nl-NL": $6ac9b6b1b7e3ca12$exports,
179
+ "pl-PL": $1be8b0ee8841f1e7$exports,
180
+ "pt-BR": $f9507c2d404ed689$exports,
181
+ "pt-PT": $8f872ea59c02d67e$exports,
182
+ "ro-RO": $b03b45b62a7ccae4$exports,
183
+ "ru-RU": $f1107d94c09df9b8$exports,
184
+ "sk-SK": $b61325f242fafc7c$exports,
185
+ "sl-SI": $f44b7cf39ac8f315$exports,
186
+ "sr-SP": $aa8cd83fc8d4982b$exports,
187
+ "sv-SE": $7c4f4e5bb7c06f1e$exports,
188
+ "tr-TR": $8045cf930ef745aa$exports,
189
+ "uk-UA": $ee2044a77f24b118$exports,
190
+ "zh-CN": $4e1dbc65a687dd93$exports,
191
+ "zh-TW": $b0fef28529309aa6$exports
192
+ };
193
+
194
+
195
+
196
+
197
+
198
+
199
+ function $60bd7d6e45dcddfa$export$2f92a7a615a014f6(props, state) {
200
+ let { isDisabled: isDisabled , inputXRef: inputXRef , inputYRef: inputYRef , containerRef: containerRef } = props;
201
+ let formatMessage = $7KHxM$useMessageFormatter((/*@__PURE__*/$parcel$interopDefault($052cfdf4c32eb7c3$exports)));
202
+ let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = $7KHxM$useGlobalListeners();
203
+ let { direction: direction , locale: locale } = $7KHxM$useLocale();
204
+ let focusedInputRef = $7KHxM$useRef(null);
205
+ let focusInput = $7KHxM$useCallback((inputRef = inputXRef)=>{
206
+ if (inputRef.current) $7KHxM$focusWithoutScrolling(inputRef.current);
207
+ }, [
208
+ inputXRef
209
+ ]);
210
+ let stateRef = $7KHxM$useRef(null);
211
+ stateRef.current = state;
212
+ let { xChannel: xChannel , yChannel: yChannel } = stateRef.current.channels;
213
+ let xChannelStep1 = stateRef.current.xChannelStep;
214
+ let yChannelStep1 = stateRef.current.xChannelStep;
215
+ let currentPosition = $7KHxM$useRef(null);
216
+ let { keyboardProps: keyboardProps } = $7KHxM$useKeyboard({
217
+ onKeyDown (e) {
218
+ // these are the cases that useMove doesn't handle
219
+ if (!/^(PageUp|PageDown|Home|End)$/.test(e.key)) {
220
+ e.continuePropagation();
221
+ return;
222
+ }
223
+ // same handling as useMove, don't need to stop propagation, useKeyboard will do that for us
224
+ e.preventDefault();
225
+ // remember to set this and unset it so that onChangeEnd is fired
226
+ stateRef.current.setDragging(true);
227
+ switch(e.key){
228
+ case 'PageUp':
229
+ stateRef.current.incrementY(stateRef.current.yChannelPageStep);
230
+ focusedInputRef.current = inputYRef.current;
231
+ break;
232
+ case 'PageDown':
233
+ stateRef.current.decrementY(stateRef.current.yChannelPageStep);
234
+ focusedInputRef.current = inputYRef.current;
235
+ break;
236
+ case 'Home':
237
+ direction === 'rtl' ? stateRef.current.incrementX(stateRef.current.xChannelPageStep) : stateRef.current.decrementX(stateRef.current.xChannelPageStep);
238
+ focusedInputRef.current = inputXRef.current;
239
+ break;
240
+ case 'End':
241
+ direction === 'rtl' ? stateRef.current.decrementX(stateRef.current.xChannelPageStep) : stateRef.current.incrementX(stateRef.current.xChannelPageStep);
242
+ focusedInputRef.current = inputXRef.current;
243
+ break;
244
+ }
245
+ stateRef.current.setDragging(false);
246
+ if (focusedInputRef.current) {
247
+ focusInput(focusedInputRef.current ? focusedInputRef : inputXRef);
248
+ focusedInputRef.current = undefined;
249
+ }
250
+ }
251
+ });
252
+ let moveHandler = {
253
+ onMoveStart () {
254
+ currentPosition.current = null;
255
+ stateRef.current.setDragging(true);
256
+ },
257
+ onMove ({ deltaX: deltaX , deltaY: deltaY , pointerType: pointerType , shiftKey: shiftKey }) {
258
+ let { incrementX: incrementX , decrementX: decrementX , incrementY: incrementY , decrementY: decrementY , xChannelPageStep: xChannelPageStep , xChannelStep: xChannelStep , yChannelPageStep: yChannelPageStep , yChannelStep: yChannelStep , getThumbPosition: getThumbPosition , setColorFromPoint: setColorFromPoint } = stateRef.current;
259
+ if (currentPosition.current == null) currentPosition.current = getThumbPosition();
260
+ let { width: width , height: height } = containerRef.current.getBoundingClientRect();
261
+ if (pointerType === 'keyboard') {
262
+ let deltaXValue = shiftKey && xChannelPageStep > xChannelStep ? xChannelPageStep : xChannelStep;
263
+ let deltaYValue = shiftKey && yChannelPageStep > yChannelStep ? yChannelPageStep : yChannelStep;
264
+ if (deltaX > 0 && direction === 'ltr' || deltaX < 0 && direction === 'rtl') incrementX(deltaXValue);
265
+ else if (deltaX < 0 && direction === 'ltr' || deltaX > 0 && direction === 'rtl') decrementX(deltaXValue);
266
+ else if (deltaY > 0) decrementY(deltaYValue);
267
+ else if (deltaY < 0) incrementY(deltaYValue);
268
+ // set the focused input based on which axis has the greater delta
269
+ focusedInputRef.current = (deltaX !== 0 || deltaY !== 0) && Math.abs(deltaY) > Math.abs(deltaX) ? inputYRef.current : inputXRef.current;
270
+ } else {
271
+ currentPosition.current.x += (direction === 'rtl' ? -1 : 1) * deltaX / width;
272
+ currentPosition.current.y += deltaY / height;
273
+ setColorFromPoint(currentPosition.current.x, currentPosition.current.y);
274
+ }
275
+ },
276
+ onMoveEnd () {
277
+ isOnColorArea.current = undefined;
278
+ stateRef.current.setDragging(false);
279
+ focusInput(focusedInputRef.current ? focusedInputRef : inputXRef);
280
+ focusedInputRef.current = undefined;
281
+ }
282
+ };
283
+ let { moveProps: movePropsThumb } = $7KHxM$useMove(moveHandler);
284
+ let currentPointer = $7KHxM$useRef(undefined);
285
+ let isOnColorArea = $7KHxM$useRef(false);
286
+ let { moveProps: movePropsContainer } = $7KHxM$useMove({
287
+ onMoveStart () {
288
+ if (isOnColorArea.current) moveHandler.onMoveStart();
289
+ },
290
+ onMove (e) {
291
+ if (isOnColorArea.current) moveHandler.onMove(e);
292
+ },
293
+ onMoveEnd () {
294
+ if (isOnColorArea.current) moveHandler.onMoveEnd();
295
+ }
296
+ });
297
+ let onThumbDown = (id)=>{
298
+ if (!state.isDragging) {
299
+ currentPointer.current = id;
300
+ focusInput();
301
+ state.setDragging(true);
302
+ if (typeof PointerEvent !== 'undefined') addGlobalListener(window, 'pointerup', onThumbUp, false);
303
+ else {
304
+ addGlobalListener(window, 'mouseup', onThumbUp, false);
305
+ addGlobalListener(window, 'touchend', onThumbUp, false);
306
+ }
307
+ }
308
+ };
309
+ let onThumbUp = (e)=>{
310
+ var ref;
311
+ var _pointerId;
312
+ let id = (_pointerId = e.pointerId) !== null && _pointerId !== void 0 ? _pointerId : (ref = e.changedTouches) === null || ref === void 0 ? void 0 : ref[0].identifier;
313
+ if (id === currentPointer.current) {
314
+ focusInput();
315
+ state.setDragging(false);
316
+ currentPointer.current = undefined;
317
+ isOnColorArea.current = false;
318
+ if (typeof PointerEvent !== 'undefined') removeGlobalListener(window, 'pointerup', onThumbUp, false);
319
+ else {
320
+ removeGlobalListener(window, 'mouseup', onThumbUp, false);
321
+ removeGlobalListener(window, 'touchend', onThumbUp, false);
322
+ }
89
323
  }
324
+ };
325
+ let onColorAreaDown = (colorArea, id, clientX, clientY)=>{
326
+ let rect = colorArea.getBoundingClientRect();
327
+ let { width: width , height: height } = rect;
328
+ let x = (clientX - rect.x) / width;
329
+ let y = (clientY - rect.y) / height;
330
+ if (direction === 'rtl') x = 1 - x;
331
+ if (x >= 0 && x <= 1 && y >= 0 && y <= 1 && !state.isDragging && currentPointer.current === undefined) {
332
+ isOnColorArea.current = true;
333
+ currentPointer.current = id;
334
+ state.setColorFromPoint(x, y);
335
+ focusInput();
336
+ state.setDragging(true);
337
+ if (typeof PointerEvent !== 'undefined') addGlobalListener(window, 'pointerup', onColorAreaUp, false);
338
+ else {
339
+ addGlobalListener(window, 'mouseup', onColorAreaUp, false);
340
+ addGlobalListener(window, 'touchend', onColorAreaUp, false);
341
+ }
342
+ }
343
+ };
344
+ let onColorAreaUp = (e)=>{
345
+ var ref;
346
+ var _pointerId;
347
+ let id = (_pointerId = e.pointerId) !== null && _pointerId !== void 0 ? _pointerId : (ref = e.changedTouches) === null || ref === void 0 ? void 0 : ref[0].identifier;
348
+ if (isOnColorArea.current && id === currentPointer.current) {
349
+ isOnColorArea.current = false;
350
+ currentPointer.current = undefined;
351
+ state.setDragging(false);
352
+ focusInput();
353
+ if (typeof PointerEvent !== 'undefined') removeGlobalListener(window, 'pointerup', onColorAreaUp, false);
354
+ else {
355
+ removeGlobalListener(window, 'mouseup', onColorAreaUp, false);
356
+ removeGlobalListener(window, 'touchend', onColorAreaUp, false);
357
+ }
358
+ }
359
+ };
360
+ let colorAreaInteractions = isDisabled ? {
361
+ } : $7KHxM$mergeProps({
362
+ ...typeof PointerEvent !== 'undefined' ? {
363
+ onPointerDown: (e)=>{
364
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
365
+ onColorAreaDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);
366
+ }
367
+ } : {
368
+ onMouseDown: (e)=>{
369
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
370
+ onColorAreaDown(e.currentTarget, undefined, e.clientX, e.clientY);
371
+ },
372
+ onTouchStart: (e)=>{
373
+ onColorAreaDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
374
+ }
375
+ }
376
+ }, movePropsContainer);
377
+ let thumbInteractions = isDisabled ? {
378
+ } : $7KHxM$mergeProps({
379
+ ...typeof PointerEvent !== 'undefined' ? {
380
+ onPointerDown: (e)=>{
381
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
382
+ onThumbDown(e.pointerId);
383
+ }
384
+ } : {
385
+ onMouseDown: (e)=>{
386
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
387
+ onThumbDown(undefined);
388
+ },
389
+ onTouchStart: (e)=>{
390
+ onThumbDown(e.changedTouches[0].identifier);
391
+ }
392
+ }
393
+ }, keyboardProps, movePropsThumb);
394
+ let isMobile = $7KHxM$isIOS() || $7KHxM$isAndroid();
395
+ let xInputLabellingProps = $7KHxM$useLabels({
396
+ ...props,
397
+ 'aria-label': isMobile ? state.value.getChannelName(xChannel, locale) : formatMessage('x/y', {
398
+ x: state.value.getChannelName(xChannel, locale),
399
+ y: state.value.getChannelName(yChannel, locale)
400
+ })
401
+ });
402
+ let yInputLabellingProps = $7KHxM$useLabels({
403
+ ...props,
404
+ 'aria-label': isMobile ? state.value.getChannelName(yChannel, locale) : formatMessage('x/y', {
405
+ x: state.value.getChannelName(xChannel, locale),
406
+ y: state.value.getChannelName(yChannel, locale)
407
+ })
408
+ });
409
+ let colorAriaLabellingProps = $7KHxM$useLabels(props);
410
+ let getValueTitle = ()=>[
411
+ formatMessage('colorNameAndValue', {
412
+ name: state.value.getChannelName('red', locale),
413
+ value: state.value.formatChannelValue('red', locale)
414
+ }),
415
+ formatMessage('colorNameAndValue', {
416
+ name: state.value.getChannelName('green', locale),
417
+ value: state.value.formatChannelValue('green', locale)
418
+ }),
419
+ formatMessage('colorNameAndValue', {
420
+ name: state.value.getChannelName('blue', locale),
421
+ value: state.value.formatChannelValue('blue', locale)
422
+ })
423
+ ].join(', ')
424
+ ;
425
+ let ariaRoleDescription = isMobile ? null : formatMessage('twoDimensionalSlider');
426
+ let { visuallyHiddenProps: visuallyHiddenProps } = $7KHxM$useVisuallyHidden({
427
+ style: {
428
+ opacity: '0.0001',
429
+ width: '100%',
430
+ height: '100%',
431
+ pointerEvents: 'none'
432
+ }
433
+ });
434
+ return {
435
+ colorAreaProps: {
436
+ ...colorAriaLabellingProps,
437
+ ...colorAreaInteractions,
438
+ role: 'group'
439
+ },
440
+ gradientProps: {
441
+ role: 'presentation'
442
+ },
443
+ thumbProps: {
444
+ ...thumbInteractions,
445
+ role: 'presentation'
446
+ },
447
+ xInputProps: {
448
+ ...xInputLabellingProps,
449
+ ...visuallyHiddenProps,
450
+ type: 'range',
451
+ min: state.value.getChannelRange(xChannel).minValue,
452
+ max: state.value.getChannelRange(xChannel).maxValue,
453
+ step: xChannelStep1,
454
+ 'aria-roledescription': ariaRoleDescription,
455
+ 'aria-valuetext': isMobile ? formatMessage('colorNameAndValue', {
456
+ name: state.value.getChannelName(xChannel, locale),
457
+ value: state.value.formatChannelValue(xChannel, locale)
458
+ }) : [
459
+ formatMessage('colorNameAndValue', {
460
+ name: state.value.getChannelName(xChannel, locale),
461
+ value: state.value.formatChannelValue(xChannel, locale)
462
+ }),
463
+ formatMessage('colorNameAndValue', {
464
+ name: state.value.getChannelName(yChannel, locale),
465
+ value: state.value.formatChannelValue(yChannel, locale)
466
+ })
467
+ ].join(', '),
468
+ title: getValueTitle(),
469
+ disabled: isDisabled,
470
+ value: state.value.getChannelValue(xChannel),
471
+ tabIndex: 0,
472
+ onChange: (e)=>{
473
+ state.setXValue(parseFloat(e.target.value));
474
+ }
475
+ },
476
+ yInputProps: {
477
+ ...yInputLabellingProps,
478
+ ...visuallyHiddenProps,
479
+ type: 'range',
480
+ min: state.value.getChannelRange(yChannel).minValue,
481
+ max: state.value.getChannelRange(yChannel).maxValue,
482
+ step: yChannelStep1,
483
+ 'aria-roledescription': ariaRoleDescription,
484
+ 'aria-valuetext': isMobile ? formatMessage('colorNameAndValue', {
485
+ name: state.value.getChannelName(yChannel, locale),
486
+ value: state.value.formatChannelValue(yChannel, locale)
487
+ }) : [
488
+ formatMessage('colorNameAndValue', {
489
+ name: state.value.getChannelName(yChannel, locale),
490
+ value: state.value.formatChannelValue(yChannel, locale)
491
+ }),
492
+ formatMessage('colorNameAndValue', {
493
+ name: state.value.getChannelName(xChannel, locale),
494
+ value: state.value.formatChannelValue(xChannel, locale)
495
+ })
496
+ ].join(', '),
497
+ 'aria-orientation': 'vertical',
498
+ title: getValueTitle(),
499
+ disabled: isDisabled,
500
+ value: state.value.getChannelValue(yChannel),
501
+ tabIndex: -1,
502
+ onChange: (e)=>{
503
+ state.setYValue(parseFloat(e.target.value));
504
+ }
505
+ }
506
+ };
507
+ }
90
508
 
91
- default:
92
- throw new Error('Unknown color channel: ' + channel);
93
- }
94
- };
95
-
96
- let thumbPosition = state.getThumbPercent(0);
97
-
98
- if (orientation === 'vertical' || direction === 'rtl') {
99
- thumbPosition = 1 - thumbPosition;
100
- }
101
-
102
- return {
103
- trackProps: _babelRuntimeHelpersEsmExtends({}, mergeProps(groupProps, trackProps), {
104
- style: {
105
- position: 'relative',
106
- touchAction: 'none',
107
- background: generateBackground()
108
- }
109
- }),
110
- inputProps,
111
- thumbProps: _babelRuntimeHelpersEsmExtends({}, thumbProps, {
112
- style: {
113
- touchAction: 'none',
114
- position: 'absolute',
115
- [orientation === 'vertical' ? 'top' : 'left']: thumbPosition * 100 + "%",
116
- transform: 'translate(-50%, -50%)'
117
- }
118
- }),
119
- labelProps,
120
- outputProps
121
- };
509
+
510
+ var $40af666d6c251e36$exports = {};
511
+
512
+ $parcel$export($40af666d6c251e36$exports, "useColorSlider", () => $40af666d6c251e36$export$106b7a4e66508f66);
513
+
514
+
515
+
516
+ function $40af666d6c251e36$export$106b7a4e66508f66(props, state) {
517
+ let { trackRef: trackRef , inputRef: inputRef , orientation: orientation , channel: channel , 'aria-label': ariaLabel } = props;
518
+ let { locale: locale , direction: direction } = $7KHxM$useLocale();
519
+ // Provide a default aria-label if there is no other label provided.
520
+ if (!props.label && !ariaLabel && !props['aria-labelledby']) ariaLabel = state.value.getChannelName(channel, locale);
521
+ // @ts-ignore - ignore unused incompatible props
522
+ let { groupProps: groupProps , trackProps: trackProps , labelProps: labelProps , outputProps: outputProps } = $7KHxM$useSlider({
523
+ ...props,
524
+ 'aria-label': ariaLabel
525
+ }, state, trackRef);
526
+ let { inputProps: inputProps , thumbProps: thumbProps } = $7KHxM$useSliderThumb({
527
+ index: 0,
528
+ orientation: orientation,
529
+ isDisabled: props.isDisabled,
530
+ trackRef: trackRef,
531
+ inputRef: inputRef
532
+ }, state);
533
+ let generateBackground = ()=>{
534
+ let value = state.getDisplayColor();
535
+ let to;
536
+ if (orientation === 'vertical') to = 'top';
537
+ else if (direction === 'ltr') to = 'right';
538
+ else to = 'left';
539
+ switch(channel){
540
+ case 'hue':
541
+ return `linear-gradient(to ${to}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;
542
+ case 'lightness':
543
+ {
544
+ // We have to add an extra color stop in the middle so that the hue shows up at all.
545
+ // Otherwise it will always just be black to white.
546
+ let min = state.getThumbMinValue(0);
547
+ let max = state.getThumbMaxValue(0);
548
+ let start = value.withChannelValue(channel, min).toString('css');
549
+ let middle = value.withChannelValue(channel, (max - min) / 2).toString('css');
550
+ let end = value.withChannelValue(channel, max).toString('css');
551
+ return `linear-gradient(to ${to}, ${start}, ${middle}, ${end})`;
552
+ }
553
+ case 'saturation':
554
+ case 'brightness':
555
+ case 'red':
556
+ case 'green':
557
+ case 'blue':
558
+ case 'alpha':
559
+ {
560
+ let start = value.withChannelValue(channel, state.getThumbMinValue(0)).toString('css');
561
+ let end = value.withChannelValue(channel, state.getThumbMaxValue(0)).toString('css');
562
+ return `linear-gradient(to ${to}, ${start}, ${end})`;
563
+ }
564
+ default:
565
+ throw new Error('Unknown color channel: ' + channel);
566
+ }
567
+ };
568
+ let thumbPosition = state.getThumbPercent(0);
569
+ if (orientation === 'vertical' || direction === 'rtl') thumbPosition = 1 - thumbPosition;
570
+ return {
571
+ trackProps: {
572
+ ...$7KHxM$mergeProps(groupProps, trackProps),
573
+ style: {
574
+ position: 'relative',
575
+ touchAction: 'none',
576
+ background: generateBackground()
577
+ }
578
+ },
579
+ inputProps: inputProps,
580
+ thumbProps: {
581
+ ...thumbProps,
582
+ style: {
583
+ touchAction: 'none',
584
+ position: 'absolute',
585
+ [orientation === 'vertical' ? 'top' : 'left']: `${thumbPosition * 100}%`,
586
+ transform: 'translate(-50%, -50%)'
587
+ }
588
+ },
589
+ labelProps: labelProps,
590
+ outputProps: outputProps
591
+ };
122
592
  }
123
- const $f98eba30513c5bc4d87f6c6540760e68$var$PAGE_MIN_STEP_SIZE = 6;
124
- /**
125
- * Provides the behavior and accessibility implementation for a color wheel component.
126
- * Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.
127
- */
128
-
129
- export function useColorWheel(props, state, inputRef) {
130
- let {
131
- isDisabled,
132
- step = 1,
133
- innerRadius,
134
- outerRadius,
135
- 'aria-label': ariaLabel
136
- } = props;
137
- let {
138
- addGlobalListener,
139
- removeGlobalListener
140
- } = useGlobalListeners();
141
- let thumbRadius = (innerRadius + outerRadius) / 2;
142
- let focusInput = useCallback(() => {
143
- if (inputRef.current) {
144
- focusWithoutScrolling(inputRef.current);
145
- }
146
- }, [inputRef]);
147
- let stateRef = useRef(null);
148
- stateRef.current = state;
149
- let currentPosition = useRef(null);
150
- let moveHandler = {
151
- onMoveStart() {
152
- currentPosition.current = null;
153
- state.setDragging(true);
154
- },
155
-
156
- onMove(_ref) {
157
- let {
158
- deltaX,
159
- deltaY,
160
- pointerType
161
- } = _ref;
162
-
163
- if (currentPosition.current == null) {
164
- currentPosition.current = stateRef.current.getThumbPosition(thumbRadius);
165
- }
166
-
167
- currentPosition.current.x += deltaX;
168
- currentPosition.current.y += deltaY;
169
-
170
- if (pointerType === 'keyboard') {
171
- if (deltaX > 0 || deltaY < 0) {
172
- state.increment();
173
- } else if (deltaX < 0 || deltaY > 0) {
174
- state.decrement();
593
+
594
+
595
+ var $b4a0a4fdc900495e$exports = {};
596
+
597
+ $parcel$export($b4a0a4fdc900495e$exports, "useColorWheel", () => $b4a0a4fdc900495e$export$9064ff4e44b3729a);
598
+
599
+
600
+
601
+
602
+ function $b4a0a4fdc900495e$export$9064ff4e44b3729a(props, state, inputRef) {
603
+ let { isDisabled: isDisabled , innerRadius: innerRadius , outerRadius: outerRadius , 'aria-label': ariaLabel } = props;
604
+ let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = $7KHxM$useGlobalListeners();
605
+ let thumbRadius = (innerRadius + outerRadius) / 2;
606
+ let focusInput = $7KHxM$useCallback(()=>{
607
+ if (inputRef.current) $7KHxM$focusWithoutScrolling(inputRef.current);
608
+ }, [
609
+ inputRef
610
+ ]);
611
+ let stateRef = $7KHxM$useRef(null);
612
+ stateRef.current = state;
613
+ let currentPosition = $7KHxM$useRef(null);
614
+ let { keyboardProps: keyboardProps } = $7KHxM$useKeyboard({
615
+ onKeyDown (e) {
616
+ // these are the cases that useMove doesn't handle
617
+ if (!/^(PageUp|PageDown)$/.test(e.key)) {
618
+ e.continuePropagation();
619
+ return;
620
+ }
621
+ // same handling as useMove, don't need to stop propagation, useKeyboard will do that for us
622
+ e.preventDefault();
623
+ // remember to set this and unset it so that onChangeEnd is fired
624
+ stateRef.current.setDragging(true);
625
+ switch(e.key){
626
+ case 'PageUp':
627
+ e.preventDefault();
628
+ state.increment(stateRef.current.pageStep);
629
+ break;
630
+ case 'PageDown':
631
+ e.preventDefault();
632
+ state.decrement(stateRef.current.pageStep);
633
+ break;
634
+ }
635
+ stateRef.current.setDragging(false);
636
+ }
637
+ });
638
+ let moveHandler = {
639
+ onMoveStart () {
640
+ currentPosition.current = null;
641
+ state.setDragging(true);
642
+ },
643
+ onMove ({ deltaX: deltaX , deltaY: deltaY , pointerType: pointerType , shiftKey: shiftKey }) {
644
+ if (currentPosition.current == null) currentPosition.current = stateRef.current.getThumbPosition(thumbRadius);
645
+ currentPosition.current.x += deltaX;
646
+ currentPosition.current.y += deltaY;
647
+ if (pointerType === 'keyboard') {
648
+ if (deltaX > 0 || deltaY < 0) state.increment(shiftKey ? stateRef.current.pageStep : stateRef.current.step);
649
+ else if (deltaX < 0 || deltaY > 0) state.decrement(shiftKey ? stateRef.current.pageStep : stateRef.current.step);
650
+ } else stateRef.current.setHueFromPoint(currentPosition.current.x, currentPosition.current.y, thumbRadius);
651
+ },
652
+ onMoveEnd () {
653
+ isOnTrack.current = undefined;
654
+ state.setDragging(false);
655
+ focusInput();
656
+ }
657
+ };
658
+ let { moveProps: movePropsThumb } = $7KHxM$useMove(moveHandler);
659
+ let currentPointer = $7KHxM$useRef(undefined);
660
+ let isOnTrack = $7KHxM$useRef(false);
661
+ let { moveProps: movePropsContainer } = $7KHxM$useMove({
662
+ onMoveStart () {
663
+ if (isOnTrack.current) moveHandler.onMoveStart();
664
+ },
665
+ onMove (e) {
666
+ if (isOnTrack.current) moveHandler.onMove(e);
667
+ },
668
+ onMoveEnd () {
669
+ if (isOnTrack.current) moveHandler.onMoveEnd();
175
670
  }
176
- } else {
177
- stateRef.current.setHueFromPoint(currentPosition.current.x, currentPosition.current.y, thumbRadius);
178
- }
179
- },
180
-
181
- onMoveEnd() {
182
- isOnTrack.current = undefined;
183
- state.setDragging(false);
184
- focusInput();
185
- }
186
-
187
- };
188
- let {
189
- moveProps: movePropsThumb
190
- } = useMove(moveHandler);
191
- let currentPointer = useRef(undefined);
192
- let isOnTrack = useRef(false);
193
- let {
194
- moveProps: movePropsContainer
195
- } = useMove({
196
- onMoveStart() {
197
- if (isOnTrack.current) {
198
- moveHandler.onMoveStart();
199
- }
200
- },
201
-
202
- onMove(e) {
203
- if (isOnTrack.current) {
204
- moveHandler.onMove(e);
205
- }
206
- },
207
-
208
- onMoveEnd() {
209
- if (isOnTrack.current) {
210
- moveHandler.onMoveEnd();
211
- }
212
- }
213
-
214
- });
215
-
216
- let onThumbDown = id => {
217
- if (!state.isDragging) {
218
- currentPointer.current = id;
219
- focusInput();
220
- state.setDragging(true);
221
-
222
- if (typeof PointerEvent !== 'undefined') {
223
- addGlobalListener(window, 'pointerup', onThumbUp, false);
224
- } else {
225
- addGlobalListener(window, 'mouseup', onThumbUp, false);
226
- addGlobalListener(window, 'touchend', onThumbUp, false);
227
- }
228
- }
229
- };
230
-
231
- let onThumbUp = e => {
232
- var _e$pointerId, _e$changedTouches;
233
-
234
- let id = (_e$pointerId = e.pointerId) != null ? _e$pointerId : (_e$changedTouches = e.changedTouches) == null ? void 0 : _e$changedTouches[0].identifier;
235
-
236
- if (id === currentPointer.current) {
237
- focusInput();
238
- state.setDragging(false);
239
- currentPointer.current = undefined;
240
- isOnTrack.current = false;
241
-
242
- if (typeof PointerEvent !== 'undefined') {
243
- removeGlobalListener(window, 'pointerup', onThumbUp, false);
244
- } else {
245
- removeGlobalListener(window, 'mouseup', onThumbUp, false);
246
- removeGlobalListener(window, 'touchend', onThumbUp, false);
247
- }
248
- }
249
- };
250
-
251
- let onTrackDown = (track, id, pageX, pageY) => {
252
- let rect = track.getBoundingClientRect();
253
- let x = pageX - rect.x - rect.width / 2;
254
- let y = pageY - rect.y - rect.height / 2;
255
- let radius = Math.sqrt(x * x + y * y);
256
-
257
- if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {
258
- isOnTrack.current = true;
259
- currentPointer.current = id;
260
- stateRef.current.setHueFromPoint(x, y, radius);
261
- focusInput();
262
- state.setDragging(true);
263
-
264
- if (typeof PointerEvent !== 'undefined') {
265
- addGlobalListener(window, 'pointerup', onTrackUp, false);
266
- } else {
267
- addGlobalListener(window, 'mouseup', onTrackUp, false);
268
- addGlobalListener(window, 'touchend', onTrackUp, false);
269
- }
270
- }
271
- };
272
-
273
- let onTrackUp = e => {
274
- var _e$pointerId2, _e$changedTouches2;
275
-
276
- let id = (_e$pointerId2 = e.pointerId) != null ? _e$pointerId2 : (_e$changedTouches2 = e.changedTouches) == null ? void 0 : _e$changedTouches2[0].identifier;
277
-
278
- if (isOnTrack.current && id === currentPointer.current) {
279
- isOnTrack.current = false;
280
- currentPointer.current = undefined;
281
- state.setDragging(false);
282
- focusInput();
283
-
284
- if (typeof PointerEvent !== 'undefined') {
285
- removeGlobalListener(window, 'pointerup', onTrackUp, false);
286
- } else {
287
- removeGlobalListener(window, 'mouseup', onTrackUp, false);
288
- removeGlobalListener(window, 'touchend', onTrackUp, false);
289
- }
290
- }
291
- };
292
-
293
- let {
294
- keyboardProps
295
- } = useKeyboard({
296
- onKeyDown(e) {
297
- switch (e.key) {
298
- case 'PageUp':
299
- e.preventDefault();
300
- state.increment($f98eba30513c5bc4d87f6c6540760e68$var$PAGE_MIN_STEP_SIZE);
301
- break;
302
-
303
- case 'PageDown':
304
- e.preventDefault();
305
- state.decrement($f98eba30513c5bc4d87f6c6540760e68$var$PAGE_MIN_STEP_SIZE);
306
- break;
307
- }
308
- }
309
-
310
- });
311
- let trackInteractions = isDisabled ? {} : mergeProps(_babelRuntimeHelpersEsmExtends({}, typeof PointerEvent !== 'undefined' ? {
312
- onPointerDown: e => {
313
- if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {
314
- return;
315
- }
316
-
317
- onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);
318
- }
319
- } : {
320
- onMouseDown: e => {
321
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {
322
- return;
323
- }
324
-
325
- onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);
326
- },
327
- onTouchStart: e => {
328
- onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
329
- }
330
- }), movePropsContainer);
331
- let thumbInteractions = isDisabled ? {} : mergeProps({
332
- onMouseDown: e => {
333
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {
334
- return;
335
- }
336
-
337
- onThumbDown(undefined);
338
- },
339
- onPointerDown: e => {
340
- if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {
341
- return;
342
- }
343
-
344
- onThumbDown(e.pointerId);
345
- },
346
- onTouchStart: e => {
347
- onThumbDown(e.changedTouches[0].identifier);
348
- }
349
- }, movePropsThumb, keyboardProps);
350
- let {
351
- x,
352
- y
353
- } = state.getThumbPosition(thumbRadius); // Provide a default aria-label if none is given
354
-
355
- let {
356
- locale
357
- } = useLocale();
358
-
359
- if (ariaLabel == null && props['aria-labelledby'] == null) {
360
- ariaLabel = state.value.getChannelName('hue', locale);
361
- }
362
-
363
- let inputLabellingProps = useLabels(_babelRuntimeHelpersEsmExtends({}, props, {
364
- 'aria-label': ariaLabel
365
- }));
366
- return {
367
- trackProps: _babelRuntimeHelpersEsmExtends({}, trackInteractions, {
368
- style: {
369
- position: 'relative',
370
- touchAction: 'none',
371
- width: outerRadius * 2,
372
- height: outerRadius * 2,
373
- background: "\n conic-gradient(\n from 90deg,\n hsl(0, 100%, 50%),\n hsl(30, 100%, 50%),\n hsl(60, 100%, 50%),\n hsl(90, 100%, 50%),\n hsl(120, 100%, 50%),\n hsl(150, 100%, 50%),\n hsl(180, 100%, 50%),\n hsl(210, 100%, 50%),\n hsl(240, 100%, 50%),\n hsl(270, 100%, 50%),\n hsl(300, 100%, 50%),\n hsl(330, 100%, 50%),\n hsl(360, 100%, 50%)\n )\n ",
374
- clipPath: "path(evenodd, \"" + $f98eba30513c5bc4d87f6c6540760e68$var$circlePath(outerRadius, outerRadius, outerRadius) + " " + $f98eba30513c5bc4d87f6c6540760e68$var$circlePath(outerRadius, outerRadius, innerRadius) + "\")"
375
- }
376
- }),
377
- thumbProps: _babelRuntimeHelpersEsmExtends({}, thumbInteractions, {
378
- style: {
379
- position: 'absolute',
380
- left: '50%',
381
- top: '50%',
382
- transform: "translate(calc(" + x + "px - 50%), calc(" + y + "px - 50%))",
383
- touchAction: 'none'
384
- }
385
- }),
386
- inputProps: mergeProps(inputLabellingProps, {
387
- type: 'range',
388
- min: '0',
389
- max: '360',
390
- step: String(step),
391
- 'aria-valuetext': state.value.formatChannelValue('hue', locale),
392
- disabled: isDisabled,
393
- value: "" + state.value.getChannelValue('hue'),
394
- onChange: e => {
395
- state.setHue(parseFloat(e.target.value));
396
- }
397
- })
398
- };
399
- } // Creates an SVG path string for a circle.
400
-
401
- function $f98eba30513c5bc4d87f6c6540760e68$var$circlePath(cx, cy, r) {
402
- return "M " + cx + ", " + cy + " m " + -r + ", 0 a " + r + ", " + r + ", 0, 1, 0, " + r * 2 + ", 0 a " + r + ", " + r + ", 0, 1, 0 " + -r * 2 + ", 0";
671
+ });
672
+ let onThumbDown = (id)=>{
673
+ if (!state.isDragging) {
674
+ currentPointer.current = id;
675
+ focusInput();
676
+ state.setDragging(true);
677
+ if (typeof PointerEvent !== 'undefined') addGlobalListener(window, 'pointerup', onThumbUp, false);
678
+ else {
679
+ addGlobalListener(window, 'mouseup', onThumbUp, false);
680
+ addGlobalListener(window, 'touchend', onThumbUp, false);
681
+ }
682
+ }
683
+ };
684
+ let onThumbUp = (e)=>{
685
+ var ref;
686
+ var _pointerId;
687
+ let id = (_pointerId = e.pointerId) !== null && _pointerId !== void 0 ? _pointerId : (ref = e.changedTouches) === null || ref === void 0 ? void 0 : ref[0].identifier;
688
+ if (id === currentPointer.current) {
689
+ focusInput();
690
+ state.setDragging(false);
691
+ currentPointer.current = undefined;
692
+ isOnTrack.current = false;
693
+ if (typeof PointerEvent !== 'undefined') removeGlobalListener(window, 'pointerup', onThumbUp, false);
694
+ else {
695
+ removeGlobalListener(window, 'mouseup', onThumbUp, false);
696
+ removeGlobalListener(window, 'touchend', onThumbUp, false);
697
+ }
698
+ }
699
+ };
700
+ let onTrackDown = (track, id, pageX, pageY)=>{
701
+ let rect = track.getBoundingClientRect();
702
+ let x = pageX - rect.x - rect.width / 2;
703
+ let y = pageY - rect.y - rect.height / 2;
704
+ let radius = Math.sqrt(x * x + y * y);
705
+ if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {
706
+ isOnTrack.current = true;
707
+ currentPointer.current = id;
708
+ stateRef.current.setHueFromPoint(x, y, radius);
709
+ focusInput();
710
+ state.setDragging(true);
711
+ if (typeof PointerEvent !== 'undefined') addGlobalListener(window, 'pointerup', onTrackUp, false);
712
+ else {
713
+ addGlobalListener(window, 'mouseup', onTrackUp, false);
714
+ addGlobalListener(window, 'touchend', onTrackUp, false);
715
+ }
716
+ }
717
+ };
718
+ let onTrackUp = (e)=>{
719
+ var ref;
720
+ var _pointerId;
721
+ let id = (_pointerId = e.pointerId) !== null && _pointerId !== void 0 ? _pointerId : (ref = e.changedTouches) === null || ref === void 0 ? void 0 : ref[0].identifier;
722
+ if (isOnTrack.current && id === currentPointer.current) {
723
+ isOnTrack.current = false;
724
+ currentPointer.current = undefined;
725
+ state.setDragging(false);
726
+ focusInput();
727
+ if (typeof PointerEvent !== 'undefined') removeGlobalListener(window, 'pointerup', onTrackUp, false);
728
+ else {
729
+ removeGlobalListener(window, 'mouseup', onTrackUp, false);
730
+ removeGlobalListener(window, 'touchend', onTrackUp, false);
731
+ }
732
+ }
733
+ };
734
+ let trackInteractions = isDisabled ? {
735
+ } : $7KHxM$mergeProps({
736
+ ...typeof PointerEvent !== 'undefined' ? {
737
+ onPointerDown: (e)=>{
738
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
739
+ onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);
740
+ }
741
+ } : {
742
+ onMouseDown: (e)=>{
743
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
744
+ onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);
745
+ },
746
+ onTouchStart: (e)=>{
747
+ onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
748
+ }
749
+ }
750
+ }, movePropsContainer);
751
+ let thumbInteractions = isDisabled ? {
752
+ } : $7KHxM$mergeProps({
753
+ onMouseDown: (e)=>{
754
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
755
+ onThumbDown(undefined);
756
+ },
757
+ onPointerDown: (e)=>{
758
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
759
+ onThumbDown(e.pointerId);
760
+ },
761
+ onTouchStart: (e)=>{
762
+ onThumbDown(e.changedTouches[0].identifier);
763
+ }
764
+ }, keyboardProps, movePropsThumb);
765
+ let { x: x1 , y: y1 } = state.getThumbPosition(thumbRadius);
766
+ // Provide a default aria-label if none is given
767
+ let { locale: locale } = $7KHxM$useLocale();
768
+ if (ariaLabel == null && props['aria-labelledby'] == null) ariaLabel = state.value.getChannelName('hue', locale);
769
+ let inputLabellingProps = $7KHxM$useLabels({
770
+ ...props,
771
+ 'aria-label': ariaLabel
772
+ });
773
+ let { minValue: minValue , maxValue: maxValue , step: step } = state.value.getChannelRange('hue');
774
+ return {
775
+ trackProps: {
776
+ ...trackInteractions,
777
+ style: {
778
+ position: 'relative',
779
+ touchAction: 'none',
780
+ width: outerRadius * 2,
781
+ height: outerRadius * 2,
782
+ background: `
783
+ conic-gradient(
784
+ from 90deg,
785
+ hsl(0, 100%, 50%),
786
+ hsl(30, 100%, 50%),
787
+ hsl(60, 100%, 50%),
788
+ hsl(90, 100%, 50%),
789
+ hsl(120, 100%, 50%),
790
+ hsl(150, 100%, 50%),
791
+ hsl(180, 100%, 50%),
792
+ hsl(210, 100%, 50%),
793
+ hsl(240, 100%, 50%),
794
+ hsl(270, 100%, 50%),
795
+ hsl(300, 100%, 50%),
796
+ hsl(330, 100%, 50%),
797
+ hsl(360, 100%, 50%)
798
+ )
799
+ `,
800
+ clipPath: `path(evenodd, "${$b4a0a4fdc900495e$var$circlePath(outerRadius, outerRadius, outerRadius)} ${$b4a0a4fdc900495e$var$circlePath(outerRadius, outerRadius, innerRadius)}")`
801
+ }
802
+ },
803
+ thumbProps: {
804
+ ...thumbInteractions,
805
+ style: {
806
+ position: 'absolute',
807
+ left: '50%',
808
+ top: '50%',
809
+ transform: `translate(calc(${x1}px - 50%), calc(${y1}px - 50%))`,
810
+ touchAction: 'none'
811
+ }
812
+ },
813
+ inputProps: $7KHxM$mergeProps(inputLabellingProps, {
814
+ type: 'range',
815
+ min: String(minValue),
816
+ max: String(maxValue),
817
+ step: String(step),
818
+ 'aria-valuetext': state.value.formatChannelValue('hue', locale),
819
+ disabled: isDisabled,
820
+ value: `${state.value.getChannelValue('hue')}`,
821
+ onChange: (e)=>{
822
+ state.setHue(parseFloat(e.target.value));
823
+ }
824
+ })
825
+ };
403
826
  }
827
+ // Creates an SVG path string for a circle.
828
+ function $b4a0a4fdc900495e$var$circlePath(cx, cy, r) {
829
+ return `M ${cx}, ${cy} m ${-r}, 0 a ${r}, ${r}, 0, 1, 0, ${r * 2}, 0 a ${r}, ${r}, 0, 1, 0 ${-r * 2}, 0`;
830
+ }
831
+
404
832
 
405
- /**
406
- * Provides the behavior and accessibility implementation for a color field component.
407
- * Color fields allow users to enter and adjust a hex color value.
408
- */
409
- export function useColorField(props, state, ref) {
410
- let {
411
- isDisabled,
412
- isReadOnly,
413
- isRequired
414
- } = props;
415
- let {
416
- colorValue,
417
- inputValue,
418
- commit,
419
- increment,
420
- decrement,
421
- incrementToMax,
422
- decrementToMin
423
- } = state;
424
- let inputId = useId();
425
- let {
426
- spinButtonProps
427
- } = useSpinButton({
428
- isDisabled,
429
- isReadOnly,
430
- isRequired,
431
- maxValue: 0xFFFFFF,
432
- minValue: 0,
433
- onIncrement: increment,
434
- onIncrementToMax: incrementToMax,
435
- onDecrement: decrement,
436
- onDecrementToMin: decrementToMin,
437
- value: colorValue ? colorValue.toHexInt() : undefined,
438
- textValue: colorValue ? colorValue.toString('hex') : undefined
439
- });
440
- let [focusWithin, setFocusWithin] = useState(false);
441
- let {
442
- focusWithinProps
443
- } = useFocusWithin({
444
- isDisabled,
445
- onFocusWithinChange: setFocusWithin
446
- });
447
- let onWheel = useCallback(e => {
448
- if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {
449
- return;
450
- }
451
-
452
- if (e.deltaY > 0) {
453
- increment();
454
- } else if (e.deltaY < 0) {
455
- decrement();
456
- }
457
- }, [isReadOnly, isDisabled, decrement, increment]); // If the input isn't supposed to receive input, disable scrolling.
458
-
459
- let scrollingDisabled = isDisabled || isReadOnly || !focusWithin;
460
- useScrollWheel({
461
- onScroll: onWheel,
462
- isDisabled: scrollingDisabled
463
- }, ref);
464
-
465
- let onChange = value => {
466
- state.setInputValue(value);
467
- };
468
-
469
- let {
470
- labelProps,
471
- inputProps
472
- } = useFormattedTextField(mergeProps(props, {
473
- id: inputId,
474
- value: inputValue,
475
- type: 'text',
476
- autoComplete: 'off',
477
- onChange
478
- }), state, ref);
479
- return {
480
- labelProps,
481
- inputProps: mergeProps(inputProps, spinButtonProps, focusWithinProps, {
482
- role: 'textbox',
483
- 'aria-valuemax': null,
484
- 'aria-valuemin': null,
485
- 'aria-valuenow': null,
486
- 'aria-valuetext': null,
487
- autoCorrect: 'off',
488
- spellCheck: 'false',
489
- onBlur: commit
490
- })
491
- };
833
+ var $f6896b05b2ecad12$exports = {};
834
+
835
+ $parcel$export($f6896b05b2ecad12$exports, "useColorField", () => $f6896b05b2ecad12$export$77e32ca575a28fdf);
836
+
837
+
838
+
839
+
840
+
841
+ function $f6896b05b2ecad12$export$77e32ca575a28fdf(props, state, ref) {
842
+ let { isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
843
+ let { colorValue: colorValue , inputValue: inputValue , commit: commit , increment: increment , decrement: decrement , incrementToMax: incrementToMax , decrementToMin: decrementToMin } = state;
844
+ let inputId = $7KHxM$useId();
845
+ let { spinButtonProps: spinButtonProps } = $7KHxM$useSpinButton({
846
+ isDisabled: isDisabled,
847
+ isReadOnly: isReadOnly,
848
+ isRequired: isRequired,
849
+ maxValue: 16777215,
850
+ minValue: 0,
851
+ onIncrement: increment,
852
+ onIncrementToMax: incrementToMax,
853
+ onDecrement: decrement,
854
+ onDecrementToMin: decrementToMin,
855
+ value: colorValue ? colorValue.toHexInt() : undefined,
856
+ textValue: colorValue ? colorValue.toString('hex') : undefined
857
+ });
858
+ let [focusWithin, setFocusWithin] = $7KHxM$useState(false);
859
+ let { focusWithinProps: focusWithinProps } = $7KHxM$useFocusWithin({
860
+ isDisabled: isDisabled,
861
+ onFocusWithinChange: setFocusWithin
862
+ });
863
+ let onWheel = $7KHxM$useCallback((e)=>{
864
+ if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return;
865
+ if (e.deltaY > 0) increment();
866
+ else if (e.deltaY < 0) decrement();
867
+ }, [
868
+ decrement,
869
+ increment
870
+ ]);
871
+ // If the input isn't supposed to receive input, disable scrolling.
872
+ let scrollingDisabled = isDisabled || isReadOnly || !focusWithin;
873
+ $7KHxM$useScrollWheel({
874
+ onScroll: onWheel,
875
+ isDisabled: scrollingDisabled
876
+ }, ref);
877
+ let onChange = (value)=>{
878
+ state.setInputValue(value);
879
+ };
880
+ let { labelProps: labelProps , inputProps: inputProps } = $7KHxM$useFormattedTextField($7KHxM$mergeProps(props, {
881
+ id: inputId,
882
+ value: inputValue,
883
+ defaultValue: undefined,
884
+ type: 'text',
885
+ autoComplete: 'off',
886
+ onChange: onChange
887
+ }), state, ref);
888
+ return {
889
+ labelProps: labelProps,
890
+ inputProps: $7KHxM$mergeProps(inputProps, spinButtonProps, focusWithinProps, {
891
+ role: 'textbox',
892
+ 'aria-valuemax': null,
893
+ 'aria-valuemin': null,
894
+ 'aria-valuenow': null,
895
+ 'aria-valuetext': null,
896
+ autoCorrect: 'off',
897
+ spellCheck: 'false',
898
+ onBlur: commit
899
+ })
900
+ };
492
901
  }
902
+
903
+
904
+
905
+
906
+ export {$60bd7d6e45dcddfa$export$2f92a7a615a014f6 as useColorArea, $40af666d6c251e36$export$106b7a4e66508f66 as useColorSlider, $b4a0a4fdc900495e$export$9064ff4e44b3729a as useColorWheel, $f6896b05b2ecad12$export$77e32ca575a28fdf as useColorField};
493
907
  //# sourceMappingURL=module.js.map