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