@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/main.js CHANGED
@@ -1,535 +1,415 @@
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 $fb1f3$reactariautils = require("@react-aria/utils");
2
+ var $fb1f3$reactariai18n = require("@react-aria/i18n");
3
+ var $fb1f3$reactariaslider = require("@react-aria/slider");
4
+ var $fb1f3$react = require("react");
5
+ var $fb1f3$reactariainteractions = require("@react-aria/interactions");
6
+ var $fb1f3$reactariatextfield = require("@react-aria/textfield");
7
+ var $fb1f3$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 $65c158f0c1f3086b$exports = {};
29
+
30
+ $parcel$export($65c158f0c1f3086b$exports, "useColorSlider", () => $65c158f0c1f3086b$export$106b7a4e66508f66);
31
+
32
+
33
+
34
+ function $65c158f0c1f3086b$export$106b7a4e66508f66(props, state) {
35
+ let { trackRef: trackRef , inputRef: inputRef , orientation: orientation , channel: channel , 'aria-label': ariaLabel } = props;
36
+ let { locale: locale , direction: direction } = $fb1f3$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 } = $fb1f3$reactariaslider.useSlider({
41
+ ...props,
42
+ 'aria-label': ariaLabel
43
+ }, state, trackRef);
44
+ let { inputProps: inputProps , thumbProps: thumbProps } = $fb1f3$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
+ ...$fb1f3$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
-
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
112
 
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 $f52a5d5adb728369$exports = {};
114
+
115
+ $parcel$export($f52a5d5adb728369$exports, "useColorWheel", () => $f52a5d5adb728369$export$9064ff4e44b3729a);
116
+
117
+
118
+
119
+
120
+ const $f52a5d5adb728369$var$PAGE_MIN_STEP_SIZE = 6;
121
+ function $f52a5d5adb728369$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 } = $fb1f3$reactariautils.useGlobalListeners();
124
+ let thumbRadius = (innerRadius + outerRadius) / 2;
125
+ let focusInput = $fb1f3$react.useCallback(()=>{
126
+ if (inputRef.current) $fb1f3$reactariautils.focusWithoutScrolling(inputRef.current);
127
+ }, [
128
+ inputRef
129
+ ]);
130
+ let stateRef = $fb1f3$react.useRef(null);
131
+ stateRef.current = state;
132
+ let currentPosition = $fb1f3$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
-
259
- if (typeof PointerEvent !== 'undefined') {
260
- addGlobalListener(window, 'pointerup', onThumbUp, false);
261
- } else {
262
- addGlobalListener(window, 'mouseup', onThumbUp, false);
263
- addGlobalListener(window, 'touchend', onThumbUp, false);
264
- }
265
- }
266
- };
267
-
268
- let onThumbUp = e => {
269
- var _e$pointerId, _e$changedTouches;
270
-
271
- let id = (_e$pointerId = e.pointerId) != null ? _e$pointerId : (_e$changedTouches = e.changedTouches) == null ? void 0 : _e$changedTouches[0].identifier;
272
-
273
- if (id === currentPointer.current) {
274
- focusInput();
275
- state.setDragging(false);
276
- currentPointer.current = undefined;
277
- isOnTrack.current = false;
278
-
279
- if (typeof PointerEvent !== 'undefined') {
280
- removeGlobalListener(window, 'pointerup', onThumbUp, false);
281
- } else {
282
- removeGlobalListener(window, 'mouseup', onThumbUp, false);
283
- removeGlobalListener(window, 'touchend', onThumbUp, false);
284
- }
285
- }
286
- };
287
-
288
- let onTrackDown = (track, id, pageX, pageY) => {
289
- let rect = track.getBoundingClientRect();
290
- let x = pageX - rect.x - rect.width / 2;
291
- let y = pageY - rect.y - rect.height / 2;
292
- let radius = Math.sqrt(x * x + y * y);
293
-
294
- if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {
295
- isOnTrack.current = true;
296
- currentPointer.current = id;
297
- stateRef.current.setHueFromPoint(x, y, radius);
298
- focusInput();
299
- state.setDragging(true);
300
-
301
- if (typeof PointerEvent !== 'undefined') {
302
- addGlobalListener(window, 'pointerup', onTrackUp, false);
303
- } else {
304
- addGlobalListener(window, 'mouseup', onTrackUp, false);
305
- addGlobalListener(window, 'touchend', onTrackUp, false);
306
- }
307
- }
308
- };
309
-
310
- let onTrackUp = e => {
311
- var _e$pointerId2, _e$changedTouches2;
312
-
313
- let id = (_e$pointerId2 = e.pointerId) != null ? _e$pointerId2 : (_e$changedTouches2 = e.changedTouches) == null ? void 0 : _e$changedTouches2[0].identifier;
314
-
315
- if (isOnTrack.current && id === currentPointer.current) {
316
- isOnTrack.current = false;
317
- currentPointer.current = undefined;
318
- state.setDragging(false);
319
- focusInput();
320
-
321
- if (typeof PointerEvent !== 'undefined') {
322
- removeGlobalListener(window, 'pointerup', onTrackUp, false);
323
- } else {
324
- removeGlobalListener(window, 'mouseup', onTrackUp, false);
325
- removeGlobalListener(window, 'touchend', onTrackUp, false);
326
- }
327
- }
328
- };
329
-
330
- let {
331
- keyboardProps
332
- } = useKeyboard({
333
- onKeyDown(e) {
334
- switch (e.key) {
335
- case 'PageUp':
336
- e.preventDefault();
337
- state.increment($c5e318998f160f365e09b073e8447c3d$var$PAGE_MIN_STEP_SIZE);
338
- break;
339
-
340
- case 'PageDown':
341
- e.preventDefault();
342
- state.decrement($c5e318998f160f365e09b073e8447c3d$var$PAGE_MIN_STEP_SIZE);
343
- break;
344
- }
345
- }
346
-
347
- });
348
- let trackInteractions = isDisabled ? {} : mergeProps(_babelRuntimeHelpersExtends({}, typeof PointerEvent !== 'undefined' ? {
349
- onPointerDown: e => {
350
- if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {
351
- return;
352
- }
353
-
354
- onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);
355
- }
356
- } : {
357
- onMouseDown: e => {
358
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {
359
- return;
360
- }
361
-
362
- onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);
363
- },
364
- onTouchStart: e => {
365
- onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
366
- }
367
- }), movePropsContainer);
368
- let thumbInteractions = isDisabled ? {} : mergeProps({
369
- onMouseDown: e => {
370
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {
371
- return;
372
- }
373
-
374
- onThumbDown(undefined);
375
- },
376
- onPointerDown: e => {
377
- if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {
378
- return;
379
- }
380
-
381
- onThumbDown(e.pointerId);
382
- },
383
- onTouchStart: e => {
384
- onThumbDown(e.changedTouches[0].identifier);
385
- }
386
- }, movePropsThumb, keyboardProps);
387
- let {
388
- x,
389
- y
390
- } = state.getThumbPosition(thumbRadius); // Provide a default aria-label if none is given
391
-
392
- let {
393
- locale
394
- } = useLocale();
395
-
396
- if (ariaLabel == null && props['aria-labelledby'] == null) {
397
- ariaLabel = state.value.getChannelName('hue', locale);
398
- }
399
-
400
- let inputLabellingProps = useLabels(_babelRuntimeHelpersExtends({}, props, {
401
- 'aria-label': ariaLabel
402
- }));
403
- return {
404
- trackProps: _babelRuntimeHelpersExtends({}, trackInteractions, {
405
- style: {
406
- position: 'relative',
407
- touchAction: 'none',
408
- width: outerRadius * 2,
409
- height: outerRadius * 2,
410
- 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 ",
411
- clipPath: "path(evenodd, \"" + $c5e318998f160f365e09b073e8447c3d$var$circlePath(outerRadius, outerRadius, outerRadius) + " " + $c5e318998f160f365e09b073e8447c3d$var$circlePath(outerRadius, outerRadius, innerRadius) + "\")"
412
- }
413
- }),
414
- thumbProps: _babelRuntimeHelpersExtends({}, thumbInteractions, {
415
- style: {
416
- position: 'absolute',
417
- left: '50%',
418
- top: '50%',
419
- transform: "translate(calc(" + x + "px - 50%), calc(" + y + "px - 50%))",
420
- touchAction: 'none'
421
- }
422
- }),
423
- inputProps: mergeProps(inputLabellingProps, {
424
- type: 'range',
425
- min: '0',
426
- max: '360',
427
- step: String(step),
428
- 'aria-valuetext': state.value.formatChannelValue('hue', locale),
429
- disabled: isDisabled,
430
- value: "" + state.value.getChannelValue('hue'),
431
- onChange: e => {
432
- state.setHue(parseFloat(e.target.value));
433
- }
434
- })
435
- };
436
- } // Creates an SVG path string for a circle.
437
-
438
-
439
- exports.useColorWheel = useColorWheel;
440
-
441
- function $c5e318998f160f365e09b073e8447c3d$var$circlePath(cx, cy, r) {
442
- 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 } = $fb1f3$reactariainteractions.useMove(moveHandler);
154
+ let currentPointer = $fb1f3$react.useRef(undefined);
155
+ let isOnTrack = $fb1f3$react.useRef(false);
156
+ let { moveProps: movePropsContainer } = $fb1f3$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
+ let id = e.pointerId ?? e.changedTouches?.[0].identifier;
181
+ if (id === currentPointer.current) {
182
+ focusInput();
183
+ state.setDragging(false);
184
+ currentPointer.current = undefined;
185
+ isOnTrack.current = false;
186
+ if (typeof PointerEvent !== 'undefined') removeGlobalListener(window, 'pointerup', onThumbUp, false);
187
+ else {
188
+ removeGlobalListener(window, 'mouseup', onThumbUp, false);
189
+ removeGlobalListener(window, 'touchend', onThumbUp, false);
190
+ }
191
+ }
192
+ };
193
+ let onTrackDown = (track, id, pageX, pageY)=>{
194
+ let rect = track.getBoundingClientRect();
195
+ let x = pageX - rect.x - rect.width / 2;
196
+ let y = pageY - rect.y - rect.height / 2;
197
+ let radius = Math.sqrt(x * x + y * y);
198
+ if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {
199
+ isOnTrack.current = true;
200
+ currentPointer.current = id;
201
+ stateRef.current.setHueFromPoint(x, y, radius);
202
+ focusInput();
203
+ state.setDragging(true);
204
+ if (typeof PointerEvent !== 'undefined') addGlobalListener(window, 'pointerup', onTrackUp, false);
205
+ else {
206
+ addGlobalListener(window, 'mouseup', onTrackUp, false);
207
+ addGlobalListener(window, 'touchend', onTrackUp, false);
208
+ }
209
+ }
210
+ };
211
+ let onTrackUp = (e)=>{
212
+ let id = e.pointerId ?? e.changedTouches?.[0].identifier;
213
+ if (isOnTrack.current && id === currentPointer.current) {
214
+ isOnTrack.current = false;
215
+ currentPointer.current = undefined;
216
+ state.setDragging(false);
217
+ focusInput();
218
+ if (typeof PointerEvent !== 'undefined') removeGlobalListener(window, 'pointerup', onTrackUp, false);
219
+ else {
220
+ removeGlobalListener(window, 'mouseup', onTrackUp, false);
221
+ removeGlobalListener(window, 'touchend', onTrackUp, false);
222
+ }
223
+ }
224
+ };
225
+ let { keyboardProps: keyboardProps } = $fb1f3$reactariainteractions.useKeyboard({
226
+ onKeyDown (e) {
227
+ switch(e.key){
228
+ case 'PageUp':
229
+ e.preventDefault();
230
+ state.increment($f52a5d5adb728369$var$PAGE_MIN_STEP_SIZE);
231
+ break;
232
+ case 'PageDown':
233
+ e.preventDefault();
234
+ state.decrement($f52a5d5adb728369$var$PAGE_MIN_STEP_SIZE);
235
+ break;
236
+ }
237
+ }
238
+ });
239
+ let trackInteractions = isDisabled ? {
240
+ } : $fb1f3$reactariautils.mergeProps({
241
+ ...typeof PointerEvent !== 'undefined' ? {
242
+ onPointerDown: (e)=>{
243
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
244
+ onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);
245
+ }
246
+ } : {
247
+ onMouseDown: (e)=>{
248
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
249
+ onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);
250
+ },
251
+ onTouchStart: (e)=>{
252
+ onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
253
+ }
254
+ }
255
+ }, movePropsContainer);
256
+ let thumbInteractions = isDisabled ? {
257
+ } : $fb1f3$reactariautils.mergeProps({
258
+ onMouseDown: (e)=>{
259
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
260
+ onThumbDown(undefined);
261
+ },
262
+ onPointerDown: (e)=>{
263
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
264
+ onThumbDown(e.pointerId);
265
+ },
266
+ onTouchStart: (e)=>{
267
+ onThumbDown(e.changedTouches[0].identifier);
268
+ }
269
+ }, movePropsThumb, keyboardProps);
270
+ let { x: x1 , y: y1 } = state.getThumbPosition(thumbRadius);
271
+ // Provide a default aria-label if none is given
272
+ let { locale: locale } = $fb1f3$reactariai18n.useLocale();
273
+ if (ariaLabel == null && props['aria-labelledby'] == null) ariaLabel = state.value.getChannelName('hue', locale);
274
+ let inputLabellingProps = $fb1f3$reactariautils.useLabels({
275
+ ...props,
276
+ 'aria-label': ariaLabel
277
+ });
278
+ return {
279
+ trackProps: {
280
+ ...trackInteractions,
281
+ style: {
282
+ position: 'relative',
283
+ touchAction: 'none',
284
+ width: outerRadius * 2,
285
+ height: outerRadius * 2,
286
+ background: `
287
+ conic-gradient(
288
+ from 90deg,
289
+ hsl(0, 100%, 50%),
290
+ hsl(30, 100%, 50%),
291
+ hsl(60, 100%, 50%),
292
+ hsl(90, 100%, 50%),
293
+ hsl(120, 100%, 50%),
294
+ hsl(150, 100%, 50%),
295
+ hsl(180, 100%, 50%),
296
+ hsl(210, 100%, 50%),
297
+ hsl(240, 100%, 50%),
298
+ hsl(270, 100%, 50%),
299
+ hsl(300, 100%, 50%),
300
+ hsl(330, 100%, 50%),
301
+ hsl(360, 100%, 50%)
302
+ )
303
+ `,
304
+ clipPath: `path(evenodd, "${$f52a5d5adb728369$var$circlePath(outerRadius, outerRadius, outerRadius)} ${$f52a5d5adb728369$var$circlePath(outerRadius, outerRadius, innerRadius)}")`
305
+ }
306
+ },
307
+ thumbProps: {
308
+ ...thumbInteractions,
309
+ style: {
310
+ position: 'absolute',
311
+ left: '50%',
312
+ top: '50%',
313
+ transform: `translate(calc(${x1}px - 50%), calc(${y1}px - 50%))`,
314
+ touchAction: 'none'
315
+ }
316
+ },
317
+ inputProps: $fb1f3$reactariautils.mergeProps(inputLabellingProps, {
318
+ type: 'range',
319
+ min: '0',
320
+ max: '360',
321
+ step: String(step),
322
+ 'aria-valuetext': state.value.formatChannelValue('hue', locale),
323
+ disabled: isDisabled,
324
+ value: `${state.value.getChannelValue('hue')}`,
325
+ onChange: (e)=>{
326
+ state.setHue(parseFloat(e.target.value));
327
+ }
328
+ })
329
+ };
330
+ }
331
+ // Creates an SVG path string for a circle.
332
+ function $f52a5d5adb728369$var$circlePath(cx, cy, r) {
333
+ 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`;
443
334
  }
444
335
 
445
- /**
446
- * Provides the behavior and accessibility implementation for a color field component.
447
- * Color fields allow users to enter and adjust a hex color value.
448
- */
449
- function useColorField(props, state, ref) {
450
- let {
451
- isDisabled,
452
- isReadOnly,
453
- isRequired
454
- } = props;
455
- let {
456
- colorValue,
457
- inputValue,
458
- commit,
459
- increment,
460
- decrement,
461
- incrementToMax,
462
- decrementToMin
463
- } = state;
464
- let inputId = useId();
465
- let {
466
- spinButtonProps
467
- } = useSpinButton({
468
- isDisabled,
469
- isReadOnly,
470
- isRequired,
471
- maxValue: 0xFFFFFF,
472
- minValue: 0,
473
- onIncrement: increment,
474
- onIncrementToMax: incrementToMax,
475
- onDecrement: decrement,
476
- onDecrementToMin: decrementToMin,
477
- value: colorValue ? colorValue.toHexInt() : undefined,
478
- textValue: colorValue ? colorValue.toString('hex') : undefined
479
- });
480
- let [focusWithin, setFocusWithin] = useState(false);
481
- let {
482
- focusWithinProps
483
- } = useFocusWithin({
484
- isDisabled,
485
- onFocusWithinChange: setFocusWithin
486
- });
487
- let onWheel = useCallback(e => {
488
- if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {
489
- return;
490
- }
491
336
 
492
- if (e.deltaY > 0) {
493
- increment();
494
- } else if (e.deltaY < 0) {
495
- decrement();
496
- }
497
- }, [isReadOnly, isDisabled, decrement, increment]); // If the input isn't supposed to receive input, disable scrolling.
337
+ var $a03d78c6bebe68f6$exports = {};
338
+
339
+ $parcel$export($a03d78c6bebe68f6$exports, "useColorField", () => $a03d78c6bebe68f6$export$77e32ca575a28fdf);
340
+
341
+
342
+
343
+
344
+
345
+ function $a03d78c6bebe68f6$export$77e32ca575a28fdf(props, state, ref) {
346
+ let { isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
347
+ let { colorValue: colorValue , inputValue: inputValue , commit: commit , increment: increment , decrement: decrement , incrementToMax: incrementToMax , decrementToMin: decrementToMin } = state;
348
+ let inputId = $fb1f3$reactariautils.useId();
349
+ let { spinButtonProps: spinButtonProps } = $fb1f3$reactariaspinbutton.useSpinButton({
350
+ isDisabled: isDisabled,
351
+ isReadOnly: isReadOnly,
352
+ isRequired: isRequired,
353
+ maxValue: 16777215,
354
+ minValue: 0,
355
+ onIncrement: increment,
356
+ onIncrementToMax: incrementToMax,
357
+ onDecrement: decrement,
358
+ onDecrementToMin: decrementToMin,
359
+ value: colorValue ? colorValue.toHexInt() : undefined,
360
+ textValue: colorValue ? colorValue.toString('hex') : undefined
361
+ });
362
+ let [focusWithin, setFocusWithin] = $fb1f3$react.useState(false);
363
+ let { focusWithinProps: focusWithinProps } = $fb1f3$reactariainteractions.useFocusWithin({
364
+ isDisabled: isDisabled,
365
+ onFocusWithinChange: setFocusWithin
366
+ });
367
+ let onWheel = $fb1f3$react.useCallback((e)=>{
368
+ if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return;
369
+ if (e.deltaY > 0) increment();
370
+ else if (e.deltaY < 0) decrement();
371
+ }, [
372
+ isReadOnly,
373
+ isDisabled,
374
+ decrement,
375
+ increment
376
+ ]);
377
+ // If the input isn't supposed to receive input, disable scrolling.
378
+ let scrollingDisabled = isDisabled || isReadOnly || !focusWithin;
379
+ $fb1f3$reactariainteractions.useScrollWheel({
380
+ onScroll: onWheel,
381
+ isDisabled: scrollingDisabled
382
+ }, ref);
383
+ let onChange = (value)=>{
384
+ state.setInputValue(value);
385
+ };
386
+ let { labelProps: labelProps , inputProps: inputProps } = $fb1f3$reactariatextfield.useFormattedTextField($fb1f3$reactariautils.mergeProps(props, {
387
+ id: inputId,
388
+ value: inputValue,
389
+ defaultValue: undefined,
390
+ type: 'text',
391
+ autoComplete: 'off',
392
+ onChange: onChange
393
+ }), state, ref);
394
+ return {
395
+ labelProps: labelProps,
396
+ inputProps: $fb1f3$reactariautils.mergeProps(inputProps, spinButtonProps, focusWithinProps, {
397
+ role: 'textbox',
398
+ 'aria-valuemax': null,
399
+ 'aria-valuemin': null,
400
+ 'aria-valuenow': null,
401
+ 'aria-valuetext': null,
402
+ autoCorrect: 'off',
403
+ spellCheck: 'false',
404
+ onBlur: commit
405
+ })
406
+ };
407
+ }
498
408
 
499
- let scrollingDisabled = isDisabled || isReadOnly || !focusWithin;
500
- useScrollWheel({
501
- onScroll: onWheel,
502
- isDisabled: scrollingDisabled
503
- }, ref);
504
409
 
505
- let onChange = value => {
506
- state.setInputValue(value);
507
- };
410
+ $parcel$exportWildcard(module.exports, $65c158f0c1f3086b$exports);
411
+ $parcel$exportWildcard(module.exports, $f52a5d5adb728369$exports);
412
+ $parcel$exportWildcard(module.exports, $a03d78c6bebe68f6$exports);
508
413
 
509
- let {
510
- labelProps,
511
- inputProps
512
- } = useFormattedTextField(mergeProps(props, {
513
- id: inputId,
514
- value: inputValue,
515
- type: 'text',
516
- autoComplete: 'off',
517
- onChange
518
- }), state, ref);
519
- return {
520
- labelProps,
521
- inputProps: mergeProps(inputProps, spinButtonProps, focusWithinProps, {
522
- role: 'textbox',
523
- 'aria-valuemax': null,
524
- 'aria-valuemin': null,
525
- 'aria-valuenow': null,
526
- 'aria-valuetext': null,
527
- autoCorrect: 'off',
528
- spellCheck: 'false',
529
- onBlur: commit
530
- })
531
- };
532
- }
533
414
 
534
- exports.useColorField = useColorField;
535
415
  //# sourceMappingURL=main.js.map