@react-aria/color 3.0.0-beta.4 → 3.0.0-beta.8

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,475 +1,401 @@
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
- }
78
-
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 + ")";
1
+ import {mergeProps as $l7vYy$mergeProps, useGlobalListeners as $l7vYy$useGlobalListeners, focusWithoutScrolling as $l7vYy$focusWithoutScrolling, useLabels as $l7vYy$useLabels, useId as $l7vYy$useId} from "@react-aria/utils";
2
+ import {useLocale as $l7vYy$useLocale} from "@react-aria/i18n";
3
+ import {useSlider as $l7vYy$useSlider, useSliderThumb as $l7vYy$useSliderThumb} from "@react-aria/slider";
4
+ import {useCallback as $l7vYy$useCallback, useRef as $l7vYy$useRef, useState as $l7vYy$useState} from "react";
5
+ import {useMove as $l7vYy$useMove, useKeyboard as $l7vYy$useKeyboard, useFocusWithin as $l7vYy$useFocusWithin, useScrollWheel as $l7vYy$useScrollWheel} from "@react-aria/interactions";
6
+ import {useFormattedTextField as $l7vYy$useFormattedTextField} from "@react-aria/textfield";
7
+ import {useSpinButton as $l7vYy$useSpinButton} from "@react-aria/spinbutton";
8
+
9
+ function $parcel$export(e, n, v, s) {
10
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
11
+ }
12
+ var $8992d2cc13930492$exports = {};
13
+
14
+ $parcel$export($8992d2cc13930492$exports, "useColorSlider", () => $8992d2cc13930492$export$106b7a4e66508f66);
15
+
16
+
17
+
18
+ function $8992d2cc13930492$export$106b7a4e66508f66(props, state) {
19
+ let { trackRef: trackRef , inputRef: inputRef , orientation: orientation , channel: channel , 'aria-label': ariaLabel } = props;
20
+ let { locale: locale , direction: direction } = $l7vYy$useLocale();
21
+ // Provide a default aria-label if there is no other label provided.
22
+ if (!props.label && !ariaLabel && !props['aria-labelledby']) ariaLabel = state.value.getChannelName(channel, locale);
23
+ // @ts-ignore - ignore unused incompatible props
24
+ let { groupProps: groupProps , trackProps: trackProps , labelProps: labelProps , outputProps: outputProps } = $l7vYy$useSlider({
25
+ ...props,
26
+ 'aria-label': ariaLabel
27
+ }, state, trackRef);
28
+ let { inputProps: inputProps , thumbProps: thumbProps } = $l7vYy$useSliderThumb({
29
+ index: 0,
30
+ orientation: orientation,
31
+ isDisabled: props.isDisabled,
32
+ trackRef: trackRef,
33
+ inputRef: inputRef
34
+ }, state);
35
+ let generateBackground = ()=>{
36
+ let value = state.getDisplayColor();
37
+ let to;
38
+ if (orientation === 'vertical') to = 'top';
39
+ else if (direction === 'ltr') to = 'right';
40
+ else to = 'left';
41
+ switch(channel){
42
+ case 'hue':
43
+ 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%)`;
44
+ case 'lightness':
45
+ {
46
+ // We have to add an extra color stop in the middle so that the hue shows up at all.
47
+ // Otherwise it will always just be black to white.
48
+ let min = state.getThumbMinValue(0);
49
+ let max = state.getThumbMaxValue(0);
50
+ let start = value.withChannelValue(channel, min).toString('css');
51
+ let middle = value.withChannelValue(channel, (max - min) / 2).toString('css');
52
+ let end = value.withChannelValue(channel, max).toString('css');
53
+ return `linear-gradient(to ${to}, ${start}, ${middle}, ${end})`;
54
+ }
55
+ case 'saturation':
56
+ case 'brightness':
57
+ case 'red':
58
+ case 'green':
59
+ case 'blue':
60
+ case 'alpha':
61
+ {
62
+ let start = value.withChannelValue(channel, state.getThumbMinValue(0)).toString('css');
63
+ let end = value.withChannelValue(channel, state.getThumbMaxValue(0)).toString('css');
64
+ return `linear-gradient(to ${to}, ${start}, ${end})`;
65
+ }
66
+ default:
67
+ throw new Error('Unknown color channel: ' + channel);
89
68
  }
90
-
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
- };
69
+ };
70
+ let thumbPosition = state.getThumbPercent(0);
71
+ if (orientation === 'vertical' || direction === 'rtl') thumbPosition = 1 - thumbPosition;
72
+ return {
73
+ trackProps: {
74
+ ...$l7vYy$mergeProps(groupProps, trackProps),
75
+ style: {
76
+ position: 'relative',
77
+ touchAction: 'none',
78
+ background: generateBackground()
79
+ }
80
+ },
81
+ inputProps: inputProps,
82
+ thumbProps: {
83
+ ...thumbProps,
84
+ style: {
85
+ touchAction: 'none',
86
+ position: 'absolute',
87
+ [orientation === 'vertical' ? 'top' : 'left']: `${thumbPosition * 100}%`,
88
+ transform: 'translate(-50%, -50%)'
89
+ }
90
+ },
91
+ labelProps: labelProps,
92
+ outputProps: outputProps
93
+ };
122
94
  }
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
95
 
167
- currentPosition.current.x += deltaX;
168
- currentPosition.current.y += deltaY;
169
96
 
170
- if (pointerType === 'keyboard') {
171
- if (deltaX > 0 || deltaY < 0) {
172
- state.increment();
173
- } else if (deltaX < 0 || deltaY > 0) {
174
- state.decrement();
97
+ var $e8f573825f77431c$exports = {};
98
+
99
+ $parcel$export($e8f573825f77431c$exports, "useColorWheel", () => $e8f573825f77431c$export$9064ff4e44b3729a);
100
+
101
+
102
+
103
+
104
+ const $e8f573825f77431c$var$PAGE_MIN_STEP_SIZE = 6;
105
+ function $e8f573825f77431c$export$9064ff4e44b3729a(props, state, inputRef) {
106
+ let { isDisabled: isDisabled , step: step = 1 , innerRadius: innerRadius , outerRadius: outerRadius , 'aria-label': ariaLabel } = props;
107
+ let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = $l7vYy$useGlobalListeners();
108
+ let thumbRadius = (innerRadius + outerRadius) / 2;
109
+ let focusInput = $l7vYy$useCallback(()=>{
110
+ if (inputRef.current) $l7vYy$focusWithoutScrolling(inputRef.current);
111
+ }, [
112
+ inputRef
113
+ ]);
114
+ let stateRef = $l7vYy$useRef(null);
115
+ stateRef.current = state;
116
+ let currentPosition = $l7vYy$useRef(null);
117
+ let moveHandler = {
118
+ onMoveStart () {
119
+ currentPosition.current = null;
120
+ state.setDragging(true);
121
+ },
122
+ onMove ({ deltaX: deltaX , deltaY: deltaY , pointerType: pointerType }) {
123
+ if (currentPosition.current == null) currentPosition.current = stateRef.current.getThumbPosition(thumbRadius);
124
+ currentPosition.current.x += deltaX;
125
+ currentPosition.current.y += deltaY;
126
+ if (pointerType === 'keyboard') {
127
+ if (deltaX > 0 || deltaY < 0) state.increment();
128
+ else if (deltaX < 0 || deltaY > 0) state.decrement();
129
+ } else stateRef.current.setHueFromPoint(currentPosition.current.x, currentPosition.current.y, thumbRadius);
130
+ },
131
+ onMoveEnd () {
132
+ isOnTrack.current = undefined;
133
+ state.setDragging(false);
134
+ focusInput();
175
135
  }
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
- addGlobalListener(window, 'mouseup', onThumbUp, false);
222
- addGlobalListener(window, 'touchend', onThumbUp, false);
223
- addGlobalListener(window, 'pointerup', onThumbUp, false);
224
- }
225
- };
226
-
227
- let onThumbUp = e => {
228
- var _e$pointerId, _e$changedTouches;
229
-
230
- let id = (_e$pointerId = e.pointerId) != null ? _e$pointerId : (_e$changedTouches = e.changedTouches) == null ? void 0 : _e$changedTouches[0].identifier;
231
-
232
- if (id === currentPointer.current) {
233
- focusInput();
234
- state.setDragging(false);
235
- currentPointer.current = undefined;
236
- isOnTrack.current = false;
237
- removeGlobalListener(window, 'mouseup', onThumbUp, false);
238
- removeGlobalListener(window, 'touchend', onThumbUp, false);
239
- removeGlobalListener(window, 'pointerup', onThumbUp, false);
240
- }
241
- };
242
-
243
- let onTrackDown = (track, id, pageX, pageY) => {
244
- let rect = track.getBoundingClientRect();
245
- let x = pageX - rect.x - rect.width / 2;
246
- let y = pageY - rect.y - rect.height / 2;
247
- let radius = Math.sqrt(x * x + y * y);
248
-
249
- if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {
250
- isOnTrack.current = true;
251
- currentPointer.current = id;
252
- stateRef.current.setHueFromPoint(x, y, radius);
253
- focusInput();
254
- state.setDragging(true);
255
- addGlobalListener(window, 'mouseup', onTrackUp, false);
256
- addGlobalListener(window, 'touchend', onTrackUp, false);
257
- addGlobalListener(window, 'pointerup', onTrackUp, false);
258
- }
259
- };
260
-
261
- let onTrackUp = e => {
262
- var _e$pointerId2, _e$changedTouches2;
263
-
264
- let id = (_e$pointerId2 = e.pointerId) != null ? _e$pointerId2 : (_e$changedTouches2 = e.changedTouches) == null ? void 0 : _e$changedTouches2[0].identifier;
265
-
266
- if (isOnTrack.current && id === currentPointer.current) {
267
- isOnTrack.current = false;
268
- currentPointer.current = undefined;
269
- state.setDragging(false);
270
- focusInput();
271
- removeGlobalListener(window, 'mouseup', onTrackUp, false);
272
- removeGlobalListener(window, 'touchend', onTrackUp, false);
273
- removeGlobalListener(window, 'pointerup', onTrackUp, false);
274
- }
275
- };
276
-
277
- let {
278
- keyboardProps
279
- } = useKeyboard({
280
- onKeyDown(e) {
281
- switch (e.key) {
282
- case 'PageUp':
283
- e.preventDefault();
284
- state.increment($f98eba30513c5bc4d87f6c6540760e68$var$PAGE_MIN_STEP_SIZE);
285
- break;
286
-
287
- case 'PageDown':
288
- e.preventDefault();
289
- state.decrement($f98eba30513c5bc4d87f6c6540760e68$var$PAGE_MIN_STEP_SIZE);
290
- break;
291
- }
292
- }
293
-
294
- });
295
- let trackInteractions = isDisabled ? {} : mergeProps({
296
- onMouseDown: e => {
297
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {
298
- return;
299
- }
300
-
301
- onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);
302
- },
303
- onPointerDown: e => {
304
- if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {
305
- return;
306
- }
307
-
308
- onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);
309
- },
310
- onTouchStart: e => {
311
- onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
312
- }
313
- }, movePropsContainer);
314
- let thumbInteractions = isDisabled ? {} : mergeProps({
315
- onMouseDown: e => {
316
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {
317
- return;
318
- }
319
-
320
- onThumbDown(undefined);
321
- },
322
- onPointerDown: e => {
323
- if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {
324
- return;
325
- }
326
-
327
- onThumbDown(e.pointerId);
328
- },
329
- onTouchStart: e => {
330
- onThumbDown(e.changedTouches[0].identifier);
331
- }
332
- }, movePropsThumb, keyboardProps);
333
- let {
334
- x,
335
- y
336
- } = state.getThumbPosition(thumbRadius); // Provide a default aria-label if none is given
337
-
338
- let {
339
- locale
340
- } = useLocale();
341
-
342
- if (ariaLabel == null && props['aria-labelledby'] == null) {
343
- ariaLabel = state.value.getChannelName('hue', locale);
344
- }
136
+ };
137
+ let { moveProps: movePropsThumb } = $l7vYy$useMove(moveHandler);
138
+ let currentPointer = $l7vYy$useRef(undefined);
139
+ let isOnTrack = $l7vYy$useRef(false);
140
+ let { moveProps: movePropsContainer } = $l7vYy$useMove({
141
+ onMoveStart () {
142
+ if (isOnTrack.current) moveHandler.onMoveStart();
143
+ },
144
+ onMove (e) {
145
+ if (isOnTrack.current) moveHandler.onMove(e);
146
+ },
147
+ onMoveEnd () {
148
+ if (isOnTrack.current) moveHandler.onMoveEnd();
149
+ }
150
+ });
151
+ let onThumbDown = (id)=>{
152
+ if (!state.isDragging) {
153
+ currentPointer.current = id;
154
+ focusInput();
155
+ state.setDragging(true);
156
+ if (typeof PointerEvent !== 'undefined') addGlobalListener(window, 'pointerup', onThumbUp, false);
157
+ else {
158
+ addGlobalListener(window, 'mouseup', onThumbUp, false);
159
+ addGlobalListener(window, 'touchend', onThumbUp, false);
160
+ }
161
+ }
162
+ };
163
+ let onThumbUp = (e)=>{
164
+ var ref;
165
+ var _pointerId;
166
+ let id = (_pointerId = e.pointerId) !== null && _pointerId !== void 0 ? _pointerId : (ref = e.changedTouches) === null || ref === void 0 ? void 0 : ref[0].identifier;
167
+ if (id === currentPointer.current) {
168
+ focusInput();
169
+ state.setDragging(false);
170
+ currentPointer.current = undefined;
171
+ isOnTrack.current = false;
172
+ if (typeof PointerEvent !== 'undefined') removeGlobalListener(window, 'pointerup', onThumbUp, false);
173
+ else {
174
+ removeGlobalListener(window, 'mouseup', onThumbUp, false);
175
+ removeGlobalListener(window, 'touchend', onThumbUp, false);
176
+ }
177
+ }
178
+ };
179
+ let onTrackDown = (track, id, pageX, pageY)=>{
180
+ let rect = track.getBoundingClientRect();
181
+ let x = pageX - rect.x - rect.width / 2;
182
+ let y = pageY - rect.y - rect.height / 2;
183
+ let radius = Math.sqrt(x * x + y * y);
184
+ if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {
185
+ isOnTrack.current = true;
186
+ currentPointer.current = id;
187
+ stateRef.current.setHueFromPoint(x, y, radius);
188
+ focusInput();
189
+ state.setDragging(true);
190
+ if (typeof PointerEvent !== 'undefined') addGlobalListener(window, 'pointerup', onTrackUp, false);
191
+ else {
192
+ addGlobalListener(window, 'mouseup', onTrackUp, false);
193
+ addGlobalListener(window, 'touchend', onTrackUp, false);
194
+ }
195
+ }
196
+ };
197
+ let onTrackUp = (e)=>{
198
+ var ref;
199
+ var _pointerId;
200
+ let id = (_pointerId = e.pointerId) !== null && _pointerId !== void 0 ? _pointerId : (ref = e.changedTouches) === null || ref === void 0 ? void 0 : ref[0].identifier;
201
+ if (isOnTrack.current && id === currentPointer.current) {
202
+ isOnTrack.current = false;
203
+ currentPointer.current = undefined;
204
+ state.setDragging(false);
205
+ focusInput();
206
+ if (typeof PointerEvent !== 'undefined') removeGlobalListener(window, 'pointerup', onTrackUp, false);
207
+ else {
208
+ removeGlobalListener(window, 'mouseup', onTrackUp, false);
209
+ removeGlobalListener(window, 'touchend', onTrackUp, false);
210
+ }
211
+ }
212
+ };
213
+ let { keyboardProps: keyboardProps } = $l7vYy$useKeyboard({
214
+ onKeyDown (e) {
215
+ switch(e.key){
216
+ case 'PageUp':
217
+ e.preventDefault();
218
+ state.increment($e8f573825f77431c$var$PAGE_MIN_STEP_SIZE);
219
+ break;
220
+ case 'PageDown':
221
+ e.preventDefault();
222
+ state.decrement($e8f573825f77431c$var$PAGE_MIN_STEP_SIZE);
223
+ break;
224
+ }
225
+ }
226
+ });
227
+ let trackInteractions = isDisabled ? {
228
+ } : $l7vYy$mergeProps({
229
+ ...typeof PointerEvent !== 'undefined' ? {
230
+ onPointerDown: (e)=>{
231
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
232
+ onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);
233
+ }
234
+ } : {
235
+ onMouseDown: (e)=>{
236
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
237
+ onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);
238
+ },
239
+ onTouchStart: (e)=>{
240
+ onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
241
+ }
242
+ }
243
+ }, movePropsContainer);
244
+ let thumbInteractions = isDisabled ? {
245
+ } : $l7vYy$mergeProps({
246
+ onMouseDown: (e)=>{
247
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
248
+ onThumbDown(undefined);
249
+ },
250
+ onPointerDown: (e)=>{
251
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
252
+ onThumbDown(e.pointerId);
253
+ },
254
+ onTouchStart: (e)=>{
255
+ onThumbDown(e.changedTouches[0].identifier);
256
+ }
257
+ }, movePropsThumb, keyboardProps);
258
+ let { x: x1 , y: y1 } = state.getThumbPosition(thumbRadius);
259
+ // Provide a default aria-label if none is given
260
+ let { locale: locale } = $l7vYy$useLocale();
261
+ if (ariaLabel == null && props['aria-labelledby'] == null) ariaLabel = state.value.getChannelName('hue', locale);
262
+ let inputLabellingProps = $l7vYy$useLabels({
263
+ ...props,
264
+ 'aria-label': ariaLabel
265
+ });
266
+ return {
267
+ trackProps: {
268
+ ...trackInteractions,
269
+ style: {
270
+ position: 'relative',
271
+ touchAction: 'none',
272
+ width: outerRadius * 2,
273
+ height: outerRadius * 2,
274
+ background: `
275
+ conic-gradient(
276
+ from 90deg,
277
+ hsl(0, 100%, 50%),
278
+ hsl(30, 100%, 50%),
279
+ hsl(60, 100%, 50%),
280
+ hsl(90, 100%, 50%),
281
+ hsl(120, 100%, 50%),
282
+ hsl(150, 100%, 50%),
283
+ hsl(180, 100%, 50%),
284
+ hsl(210, 100%, 50%),
285
+ hsl(240, 100%, 50%),
286
+ hsl(270, 100%, 50%),
287
+ hsl(300, 100%, 50%),
288
+ hsl(330, 100%, 50%),
289
+ hsl(360, 100%, 50%)
290
+ )
291
+ `,
292
+ clipPath: `path(evenodd, "${$e8f573825f77431c$var$circlePath(outerRadius, outerRadius, outerRadius)} ${$e8f573825f77431c$var$circlePath(outerRadius, outerRadius, innerRadius)}")`
293
+ }
294
+ },
295
+ thumbProps: {
296
+ ...thumbInteractions,
297
+ style: {
298
+ position: 'absolute',
299
+ left: '50%',
300
+ top: '50%',
301
+ transform: `translate(calc(${x1}px - 50%), calc(${y1}px - 50%))`,
302
+ touchAction: 'none'
303
+ }
304
+ },
305
+ inputProps: $l7vYy$mergeProps(inputLabellingProps, {
306
+ type: 'range',
307
+ min: '0',
308
+ max: '360',
309
+ step: String(step),
310
+ 'aria-valuetext': state.value.formatChannelValue('hue', locale),
311
+ disabled: isDisabled,
312
+ value: `${state.value.getChannelValue('hue')}`,
313
+ onChange: (e)=>{
314
+ state.setHue(parseFloat(e.target.value));
315
+ }
316
+ })
317
+ };
318
+ }
319
+ // Creates an SVG path string for a circle.
320
+ function $e8f573825f77431c$var$circlePath(cx, cy, r) {
321
+ 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`;
322
+ }
345
323
 
346
- let inputLabellingProps = useLabels(_babelRuntimeHelpersEsmExtends({}, props, {
347
- 'aria-label': ariaLabel
348
- }));
349
- return {
350
- trackProps: _babelRuntimeHelpersEsmExtends({}, trackInteractions, {
351
- style: {
352
- position: 'relative',
353
- touchAction: 'none',
354
- width: outerRadius * 2,
355
- height: outerRadius * 2,
356
- 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 ",
357
- clipPath: "path(evenodd, \"" + $f98eba30513c5bc4d87f6c6540760e68$var$circlePath(outerRadius, outerRadius, outerRadius) + " " + $f98eba30513c5bc4d87f6c6540760e68$var$circlePath(outerRadius, outerRadius, innerRadius) + "\")"
358
- }
359
- }),
360
- thumbProps: _babelRuntimeHelpersEsmExtends({}, thumbInteractions, {
361
- style: {
362
- position: 'absolute',
363
- left: '50%',
364
- top: '50%',
365
- transform: "translate(calc(" + x + "px - 50%), calc(" + y + "px - 50%))",
366
- touchAction: 'none'
367
- }
368
- }),
369
- inputProps: mergeProps(inputLabellingProps, {
370
- type: 'range',
371
- min: '0',
372
- max: '360',
373
- step: String(step),
374
- 'aria-valuetext': state.value.formatChannelValue('hue', locale),
375
- disabled: isDisabled,
376
- value: "" + state.value.getChannelValue('hue'),
377
- onChange: e => {
378
- state.setHue(parseFloat(e.target.value));
379
- }
380
- })
381
- };
382
- } // Creates an SVG path string for a circle.
383
324
 
384
- function $f98eba30513c5bc4d87f6c6540760e68$var$circlePath(cx, cy, r) {
385
- 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";
325
+ var $bb9d9837d0b340e7$exports = {};
326
+
327
+ $parcel$export($bb9d9837d0b340e7$exports, "useColorField", () => $bb9d9837d0b340e7$export$77e32ca575a28fdf);
328
+
329
+
330
+
331
+
332
+
333
+ function $bb9d9837d0b340e7$export$77e32ca575a28fdf(props, state, ref) {
334
+ let { isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
335
+ let { colorValue: colorValue , inputValue: inputValue , commit: commit , increment: increment , decrement: decrement , incrementToMax: incrementToMax , decrementToMin: decrementToMin } = state;
336
+ let inputId = $l7vYy$useId();
337
+ let { spinButtonProps: spinButtonProps } = $l7vYy$useSpinButton({
338
+ isDisabled: isDisabled,
339
+ isReadOnly: isReadOnly,
340
+ isRequired: isRequired,
341
+ maxValue: 16777215,
342
+ minValue: 0,
343
+ onIncrement: increment,
344
+ onIncrementToMax: incrementToMax,
345
+ onDecrement: decrement,
346
+ onDecrementToMin: decrementToMin,
347
+ value: colorValue ? colorValue.toHexInt() : undefined,
348
+ textValue: colorValue ? colorValue.toString('hex') : undefined
349
+ });
350
+ let [focusWithin, setFocusWithin] = $l7vYy$useState(false);
351
+ let { focusWithinProps: focusWithinProps } = $l7vYy$useFocusWithin({
352
+ isDisabled: isDisabled,
353
+ onFocusWithinChange: setFocusWithin
354
+ });
355
+ let onWheel = $l7vYy$useCallback((e)=>{
356
+ if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return;
357
+ if (e.deltaY > 0) increment();
358
+ else if (e.deltaY < 0) decrement();
359
+ }, [
360
+ isReadOnly,
361
+ isDisabled,
362
+ decrement,
363
+ increment
364
+ ]);
365
+ // If the input isn't supposed to receive input, disable scrolling.
366
+ let scrollingDisabled = isDisabled || isReadOnly || !focusWithin;
367
+ $l7vYy$useScrollWheel({
368
+ onScroll: onWheel,
369
+ isDisabled: scrollingDisabled
370
+ }, ref);
371
+ let onChange = (value)=>{
372
+ state.setInputValue(value);
373
+ };
374
+ let { labelProps: labelProps , inputProps: inputProps } = $l7vYy$useFormattedTextField($l7vYy$mergeProps(props, {
375
+ id: inputId,
376
+ value: inputValue,
377
+ defaultValue: undefined,
378
+ type: 'text',
379
+ autoComplete: 'off',
380
+ onChange: onChange
381
+ }), state, ref);
382
+ return {
383
+ labelProps: labelProps,
384
+ inputProps: $l7vYy$mergeProps(inputProps, spinButtonProps, focusWithinProps, {
385
+ role: 'textbox',
386
+ 'aria-valuemax': null,
387
+ 'aria-valuemin': null,
388
+ 'aria-valuenow': null,
389
+ 'aria-valuetext': null,
390
+ autoCorrect: 'off',
391
+ spellCheck: 'false',
392
+ onBlur: commit
393
+ })
394
+ };
386
395
  }
387
396
 
388
- /**
389
- * Provides the behavior and accessibility implementation for a color field component.
390
- * Color fields allow users to enter and adjust a hex color value.
391
- */
392
- export function useColorField(props, state, ref) {
393
- let {
394
- isDisabled,
395
- isReadOnly,
396
- isRequired
397
- } = props;
398
- let {
399
- colorValue,
400
- inputValue,
401
- commit,
402
- increment,
403
- decrement,
404
- incrementToMax,
405
- decrementToMin
406
- } = state;
407
- let inputId = useId();
408
- let {
409
- spinButtonProps
410
- } = useSpinButton({
411
- isDisabled,
412
- isReadOnly,
413
- isRequired,
414
- maxValue: 0xFFFFFF,
415
- minValue: 0,
416
- onIncrement: increment,
417
- onIncrementToMax: incrementToMax,
418
- onDecrement: decrement,
419
- onDecrementToMin: decrementToMin,
420
- value: colorValue ? colorValue.toHexInt() : undefined,
421
- textValue: colorValue ? colorValue.toString('hex') : undefined
422
- });
423
- let [focusWithin, setFocusWithin] = useState(false);
424
- let {
425
- focusWithinProps
426
- } = useFocusWithin({
427
- isDisabled,
428
- onFocusWithinChange: setFocusWithin
429
- });
430
- let onWheel = useCallback(e => {
431
- if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {
432
- return;
433
- }
434
-
435
- if (e.deltaY > 0) {
436
- increment();
437
- } else if (e.deltaY < 0) {
438
- decrement();
439
- }
440
- }, [isReadOnly, isDisabled, decrement, increment]); // If the input isn't supposed to receive input, disable scrolling.
441
397
 
442
- let scrollingDisabled = isDisabled || isReadOnly || !focusWithin;
443
- useScrollWheel({
444
- onScroll: onWheel,
445
- isDisabled: scrollingDisabled
446
- }, ref);
447
398
 
448
- let onChange = value => {
449
- state.setInputValue(value);
450
- };
451
399
 
452
- let {
453
- labelProps,
454
- inputProps
455
- } = useFormattedTextField(mergeProps(props, {
456
- id: inputId,
457
- value: inputValue,
458
- type: 'text',
459
- autoComplete: 'off',
460
- onChange
461
- }), state, ref);
462
- return {
463
- labelProps,
464
- inputProps: mergeProps(inputProps, spinButtonProps, focusWithinProps, {
465
- role: 'textbox',
466
- 'aria-valuemax': null,
467
- 'aria-valuemin': null,
468
- 'aria-valuenow': null,
469
- 'aria-valuetext': null,
470
- autoCorrect: 'off',
471
- onBlur: commit
472
- })
473
- };
474
- }
400
+ export {$8992d2cc13930492$export$106b7a4e66508f66 as useColorSlider, $e8f573825f77431c$export$9064ff4e44b3729a as useColorWheel, $bb9d9837d0b340e7$export$77e32ca575a28fdf as useColorField};
475
401
  //# sourceMappingURL=module.js.map