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

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,397 @@
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 $kLMEb$mergeProps, useGlobalListeners as $kLMEb$useGlobalListeners, focusWithoutScrolling as $kLMEb$focusWithoutScrolling, useLabels as $kLMEb$useLabels, useId as $kLMEb$useId} from "@react-aria/utils";
2
+ import {useLocale as $kLMEb$useLocale} from "@react-aria/i18n";
3
+ import {useSlider as $kLMEb$useSlider, useSliderThumb as $kLMEb$useSliderThumb} from "@react-aria/slider";
4
+ import {useCallback as $kLMEb$useCallback, useRef as $kLMEb$useRef, useState as $kLMEb$useState} from "react";
5
+ import {useMove as $kLMEb$useMove, useKeyboard as $kLMEb$useKeyboard, useFocusWithin as $kLMEb$useFocusWithin, useScrollWheel as $kLMEb$useScrollWheel} from "@react-aria/interactions";
6
+ import {useFormattedTextField as $kLMEb$useFormattedTextField} from "@react-aria/textfield";
7
+ import {useSpinButton as $kLMEb$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 $d35c65941a2de674$exports = {};
13
+
14
+ $parcel$export($d35c65941a2de674$exports, "useColorSlider", () => $d35c65941a2de674$export$106b7a4e66508f66);
15
+
16
+
17
+
18
+ function $d35c65941a2de674$export$106b7a4e66508f66(props, state) {
19
+ let { trackRef: trackRef , inputRef: inputRef , orientation: orientation , channel: channel , 'aria-label': ariaLabel } = props;
20
+ let { locale: locale , direction: direction } = $kLMEb$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 } = $kLMEb$useSlider({
25
+ ...props,
26
+ 'aria-label': ariaLabel
27
+ }, state, trackRef);
28
+ let { inputProps: inputProps , thumbProps: thumbProps } = $kLMEb$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
+ ...$kLMEb$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
95
 
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
96
 
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();
97
+ var $29049ccc426e44cb$exports = {};
98
+
99
+ $parcel$export($29049ccc426e44cb$exports, "useColorWheel", () => $29049ccc426e44cb$export$9064ff4e44b3729a);
100
+
101
+
102
+
103
+
104
+ const $29049ccc426e44cb$var$PAGE_MIN_STEP_SIZE = 6;
105
+ function $29049ccc426e44cb$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 } = $kLMEb$useGlobalListeners();
108
+ let thumbRadius = (innerRadius + outerRadius) / 2;
109
+ let focusInput = $kLMEb$useCallback(()=>{
110
+ if (inputRef.current) $kLMEb$focusWithoutScrolling(inputRef.current);
111
+ }, [
112
+ inputRef
113
+ ]);
114
+ let stateRef = $kLMEb$useRef(null);
115
+ stateRef.current = state;
116
+ let currentPosition = $kLMEb$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
-
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
- }
136
+ };
137
+ let { moveProps: movePropsThumb } = $kLMEb$useMove(moveHandler);
138
+ let currentPointer = $kLMEb$useRef(undefined);
139
+ let isOnTrack = $kLMEb$useRef(false);
140
+ let { moveProps: movePropsContainer } = $kLMEb$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
+ let id = e.pointerId ?? e.changedTouches?.[0].identifier;
165
+ if (id === currentPointer.current) {
166
+ focusInput();
167
+ state.setDragging(false);
168
+ currentPointer.current = undefined;
169
+ isOnTrack.current = false;
170
+ if (typeof PointerEvent !== 'undefined') removeGlobalListener(window, 'pointerup', onThumbUp, false);
171
+ else {
172
+ removeGlobalListener(window, 'mouseup', onThumbUp, false);
173
+ removeGlobalListener(window, 'touchend', onThumbUp, false);
174
+ }
175
+ }
176
+ };
177
+ let onTrackDown = (track, id, pageX, pageY)=>{
178
+ let rect = track.getBoundingClientRect();
179
+ let x = pageX - rect.x - rect.width / 2;
180
+ let y = pageY - rect.y - rect.height / 2;
181
+ let radius = Math.sqrt(x * x + y * y);
182
+ if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {
183
+ isOnTrack.current = true;
184
+ currentPointer.current = id;
185
+ stateRef.current.setHueFromPoint(x, y, radius);
186
+ focusInput();
187
+ state.setDragging(true);
188
+ if (typeof PointerEvent !== 'undefined') addGlobalListener(window, 'pointerup', onTrackUp, false);
189
+ else {
190
+ addGlobalListener(window, 'mouseup', onTrackUp, false);
191
+ addGlobalListener(window, 'touchend', onTrackUp, false);
192
+ }
193
+ }
194
+ };
195
+ let onTrackUp = (e)=>{
196
+ let id = e.pointerId ?? e.changedTouches?.[0].identifier;
197
+ if (isOnTrack.current && id === currentPointer.current) {
198
+ isOnTrack.current = false;
199
+ currentPointer.current = undefined;
200
+ state.setDragging(false);
201
+ focusInput();
202
+ if (typeof PointerEvent !== 'undefined') removeGlobalListener(window, 'pointerup', onTrackUp, false);
203
+ else {
204
+ removeGlobalListener(window, 'mouseup', onTrackUp, false);
205
+ removeGlobalListener(window, 'touchend', onTrackUp, false);
206
+ }
207
+ }
208
+ };
209
+ let { keyboardProps: keyboardProps } = $kLMEb$useKeyboard({
210
+ onKeyDown (e) {
211
+ switch(e.key){
212
+ case 'PageUp':
213
+ e.preventDefault();
214
+ state.increment($29049ccc426e44cb$var$PAGE_MIN_STEP_SIZE);
215
+ break;
216
+ case 'PageDown':
217
+ e.preventDefault();
218
+ state.decrement($29049ccc426e44cb$var$PAGE_MIN_STEP_SIZE);
219
+ break;
220
+ }
221
+ }
222
+ });
223
+ let trackInteractions = isDisabled ? {
224
+ } : $kLMEb$mergeProps({
225
+ ...typeof PointerEvent !== 'undefined' ? {
226
+ onPointerDown: (e)=>{
227
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
228
+ onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);
229
+ }
230
+ } : {
231
+ onMouseDown: (e)=>{
232
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
233
+ onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);
234
+ },
235
+ onTouchStart: (e)=>{
236
+ onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
237
+ }
238
+ }
239
+ }, movePropsContainer);
240
+ let thumbInteractions = isDisabled ? {
241
+ } : $kLMEb$mergeProps({
242
+ onMouseDown: (e)=>{
243
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
244
+ onThumbDown(undefined);
245
+ },
246
+ onPointerDown: (e)=>{
247
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
248
+ onThumbDown(e.pointerId);
249
+ },
250
+ onTouchStart: (e)=>{
251
+ onThumbDown(e.changedTouches[0].identifier);
252
+ }
253
+ }, movePropsThumb, keyboardProps);
254
+ let { x: x1 , y: y1 } = state.getThumbPosition(thumbRadius);
255
+ // Provide a default aria-label if none is given
256
+ let { locale: locale } = $kLMEb$useLocale();
257
+ if (ariaLabel == null && props['aria-labelledby'] == null) ariaLabel = state.value.getChannelName('hue', locale);
258
+ let inputLabellingProps = $kLMEb$useLabels({
259
+ ...props,
260
+ 'aria-label': ariaLabel
261
+ });
262
+ return {
263
+ trackProps: {
264
+ ...trackInteractions,
265
+ style: {
266
+ position: 'relative',
267
+ touchAction: 'none',
268
+ width: outerRadius * 2,
269
+ height: outerRadius * 2,
270
+ background: `
271
+ conic-gradient(
272
+ from 90deg,
273
+ hsl(0, 100%, 50%),
274
+ hsl(30, 100%, 50%),
275
+ hsl(60, 100%, 50%),
276
+ hsl(90, 100%, 50%),
277
+ hsl(120, 100%, 50%),
278
+ hsl(150, 100%, 50%),
279
+ hsl(180, 100%, 50%),
280
+ hsl(210, 100%, 50%),
281
+ hsl(240, 100%, 50%),
282
+ hsl(270, 100%, 50%),
283
+ hsl(300, 100%, 50%),
284
+ hsl(330, 100%, 50%),
285
+ hsl(360, 100%, 50%)
286
+ )
287
+ `,
288
+ clipPath: `path(evenodd, "${$29049ccc426e44cb$var$circlePath(outerRadius, outerRadius, outerRadius)} ${$29049ccc426e44cb$var$circlePath(outerRadius, outerRadius, innerRadius)}")`
289
+ }
290
+ },
291
+ thumbProps: {
292
+ ...thumbInteractions,
293
+ style: {
294
+ position: 'absolute',
295
+ left: '50%',
296
+ top: '50%',
297
+ transform: `translate(calc(${x1}px - 50%), calc(${y1}px - 50%))`,
298
+ touchAction: 'none'
299
+ }
300
+ },
301
+ inputProps: $kLMEb$mergeProps(inputLabellingProps, {
302
+ type: 'range',
303
+ min: '0',
304
+ max: '360',
305
+ step: String(step),
306
+ 'aria-valuetext': state.value.formatChannelValue('hue', locale),
307
+ disabled: isDisabled,
308
+ value: `${state.value.getChannelValue('hue')}`,
309
+ onChange: (e)=>{
310
+ state.setHue(parseFloat(e.target.value));
311
+ }
312
+ })
313
+ };
314
+ }
315
+ // Creates an SVG path string for a circle.
316
+ function $29049ccc426e44cb$var$circlePath(cx, cy, r) {
317
+ 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`;
318
+ }
362
319
 
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
320
 
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";
321
+ var $42d92523b2461444$exports = {};
322
+
323
+ $parcel$export($42d92523b2461444$exports, "useColorField", () => $42d92523b2461444$export$77e32ca575a28fdf);
324
+
325
+
326
+
327
+
328
+
329
+ function $42d92523b2461444$export$77e32ca575a28fdf(props, state, ref) {
330
+ let { isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
331
+ let { colorValue: colorValue , inputValue: inputValue , commit: commit , increment: increment , decrement: decrement , incrementToMax: incrementToMax , decrementToMin: decrementToMin } = state;
332
+ let inputId = $kLMEb$useId();
333
+ let { spinButtonProps: spinButtonProps } = $kLMEb$useSpinButton({
334
+ isDisabled: isDisabled,
335
+ isReadOnly: isReadOnly,
336
+ isRequired: isRequired,
337
+ maxValue: 16777215,
338
+ minValue: 0,
339
+ onIncrement: increment,
340
+ onIncrementToMax: incrementToMax,
341
+ onDecrement: decrement,
342
+ onDecrementToMin: decrementToMin,
343
+ value: colorValue ? colorValue.toHexInt() : undefined,
344
+ textValue: colorValue ? colorValue.toString('hex') : undefined
345
+ });
346
+ let [focusWithin, setFocusWithin] = $kLMEb$useState(false);
347
+ let { focusWithinProps: focusWithinProps } = $kLMEb$useFocusWithin({
348
+ isDisabled: isDisabled,
349
+ onFocusWithinChange: setFocusWithin
350
+ });
351
+ let onWheel = $kLMEb$useCallback((e)=>{
352
+ if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return;
353
+ if (e.deltaY > 0) increment();
354
+ else if (e.deltaY < 0) decrement();
355
+ }, [
356
+ isReadOnly,
357
+ isDisabled,
358
+ decrement,
359
+ increment
360
+ ]);
361
+ // If the input isn't supposed to receive input, disable scrolling.
362
+ let scrollingDisabled = isDisabled || isReadOnly || !focusWithin;
363
+ $kLMEb$useScrollWheel({
364
+ onScroll: onWheel,
365
+ isDisabled: scrollingDisabled
366
+ }, ref);
367
+ let onChange = (value)=>{
368
+ state.setInputValue(value);
369
+ };
370
+ let { labelProps: labelProps , inputProps: inputProps } = $kLMEb$useFormattedTextField($kLMEb$mergeProps(props, {
371
+ id: inputId,
372
+ value: inputValue,
373
+ defaultValue: undefined,
374
+ type: 'text',
375
+ autoComplete: 'off',
376
+ onChange: onChange
377
+ }), state, ref);
378
+ return {
379
+ labelProps: labelProps,
380
+ inputProps: $kLMEb$mergeProps(inputProps, spinButtonProps, focusWithinProps, {
381
+ role: 'textbox',
382
+ 'aria-valuemax': null,
383
+ 'aria-valuemin': null,
384
+ 'aria-valuenow': null,
385
+ 'aria-valuetext': null,
386
+ autoCorrect: 'off',
387
+ spellCheck: 'false',
388
+ onBlur: commit
389
+ })
390
+ };
403
391
  }
404
392
 
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
393
 
459
- let scrollingDisabled = isDisabled || isReadOnly || !focusWithin;
460
- useScrollWheel({
461
- onScroll: onWheel,
462
- isDisabled: scrollingDisabled
463
- }, ref);
464
394
 
465
- let onChange = value => {
466
- state.setInputValue(value);
467
- };
468
395
 
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
- };
492
- }
396
+ export {$d35c65941a2de674$export$106b7a4e66508f66 as useColorSlider, $29049ccc426e44cb$export$9064ff4e44b3729a as useColorWheel, $42d92523b2461444$export$77e32ca575a28fdf as useColorField};
493
397
  //# sourceMappingURL=module.js.map