@react-aria/color 3.0.0-beta.30 → 3.0.0-beta.32
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/ar-AE.main.js +11 -0
- package/dist/ar-AE.main.js.map +1 -0
- package/dist/ar-AE.mjs +13 -0
- package/dist/ar-AE.module.js +13 -0
- package/dist/ar-AE.module.js.map +1 -0
- package/dist/bg-BG.main.js +11 -0
- package/dist/bg-BG.main.js.map +1 -0
- package/dist/bg-BG.mjs +13 -0
- package/dist/bg-BG.module.js +13 -0
- package/dist/bg-BG.module.js.map +1 -0
- package/dist/cs-CZ.main.js +11 -0
- package/dist/cs-CZ.main.js.map +1 -0
- package/dist/cs-CZ.mjs +13 -0
- package/dist/cs-CZ.module.js +13 -0
- package/dist/cs-CZ.module.js.map +1 -0
- package/dist/da-DK.main.js +11 -0
- package/dist/da-DK.main.js.map +1 -0
- package/dist/da-DK.mjs +13 -0
- package/dist/da-DK.module.js +13 -0
- package/dist/da-DK.module.js.map +1 -0
- package/dist/de-DE.main.js +11 -0
- package/dist/de-DE.main.js.map +1 -0
- package/dist/de-DE.mjs +13 -0
- package/dist/de-DE.module.js +13 -0
- package/dist/de-DE.module.js.map +1 -0
- package/dist/el-GR.main.js +11 -0
- package/dist/el-GR.main.js.map +1 -0
- package/dist/el-GR.mjs +13 -0
- package/dist/el-GR.module.js +13 -0
- package/dist/el-GR.module.js.map +1 -0
- package/dist/en-US.main.js +11 -0
- package/dist/en-US.main.js.map +1 -0
- package/dist/en-US.mjs +13 -0
- package/dist/en-US.module.js +13 -0
- package/dist/en-US.module.js.map +1 -0
- package/dist/es-ES.main.js +11 -0
- package/dist/es-ES.main.js.map +1 -0
- package/dist/es-ES.mjs +13 -0
- package/dist/es-ES.module.js +13 -0
- package/dist/es-ES.module.js.map +1 -0
- package/dist/et-EE.main.js +11 -0
- package/dist/et-EE.main.js.map +1 -0
- package/dist/et-EE.mjs +13 -0
- package/dist/et-EE.module.js +13 -0
- package/dist/et-EE.module.js.map +1 -0
- package/dist/fi-FI.main.js +11 -0
- package/dist/fi-FI.main.js.map +1 -0
- package/dist/fi-FI.mjs +13 -0
- package/dist/fi-FI.module.js +13 -0
- package/dist/fi-FI.module.js.map +1 -0
- package/dist/fr-FR.main.js +11 -0
- package/dist/fr-FR.main.js.map +1 -0
- package/dist/fr-FR.mjs +13 -0
- package/dist/fr-FR.module.js +13 -0
- package/dist/fr-FR.module.js.map +1 -0
- package/dist/he-IL.main.js +11 -0
- package/dist/he-IL.main.js.map +1 -0
- package/dist/he-IL.mjs +13 -0
- package/dist/he-IL.module.js +13 -0
- package/dist/he-IL.module.js.map +1 -0
- package/dist/hr-HR.main.js +11 -0
- package/dist/hr-HR.main.js.map +1 -0
- package/dist/hr-HR.mjs +13 -0
- package/dist/hr-HR.module.js +13 -0
- package/dist/hr-HR.module.js.map +1 -0
- package/dist/hu-HU.main.js +11 -0
- package/dist/hu-HU.main.js.map +1 -0
- package/dist/hu-HU.mjs +13 -0
- package/dist/hu-HU.module.js +13 -0
- package/dist/hu-HU.module.js.map +1 -0
- package/dist/import.mjs +7 -1357
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/it-IT.main.js +11 -0
- package/dist/it-IT.main.js.map +1 -0
- package/dist/it-IT.mjs +13 -0
- package/dist/it-IT.module.js +13 -0
- package/dist/it-IT.module.js.map +1 -0
- package/dist/ja-JP.main.js +11 -0
- package/dist/ja-JP.main.js.map +1 -0
- package/dist/ja-JP.mjs +13 -0
- package/dist/ja-JP.module.js +13 -0
- package/dist/ja-JP.module.js.map +1 -0
- package/dist/ko-KR.main.js +11 -0
- package/dist/ko-KR.main.js.map +1 -0
- package/dist/ko-KR.mjs +13 -0
- package/dist/ko-KR.module.js +13 -0
- package/dist/ko-KR.module.js.map +1 -0
- package/dist/lt-LT.main.js +11 -0
- package/dist/lt-LT.main.js.map +1 -0
- package/dist/lt-LT.mjs +13 -0
- package/dist/lt-LT.module.js +13 -0
- package/dist/lt-LT.module.js.map +1 -0
- package/dist/lv-LV.main.js +11 -0
- package/dist/lv-LV.main.js.map +1 -0
- package/dist/lv-LV.mjs +13 -0
- package/dist/lv-LV.module.js +13 -0
- package/dist/lv-LV.module.js.map +1 -0
- package/dist/main.js +12 -1360
- package/dist/main.js.map +1 -1
- package/dist/module.js +7 -1357
- package/dist/module.js.map +1 -1
- package/dist/nb-NO.main.js +11 -0
- package/dist/nb-NO.main.js.map +1 -0
- package/dist/nb-NO.mjs +13 -0
- package/dist/nb-NO.module.js +13 -0
- package/dist/nb-NO.module.js.map +1 -0
- package/dist/nl-NL.main.js +11 -0
- package/dist/nl-NL.main.js.map +1 -0
- package/dist/nl-NL.mjs +13 -0
- package/dist/nl-NL.module.js +13 -0
- package/dist/nl-NL.module.js.map +1 -0
- package/dist/pl-PL.main.js +11 -0
- package/dist/pl-PL.main.js.map +1 -0
- package/dist/pl-PL.mjs +13 -0
- package/dist/pl-PL.module.js +13 -0
- package/dist/pl-PL.module.js.map +1 -0
- package/dist/pt-BR.main.js +11 -0
- package/dist/pt-BR.main.js.map +1 -0
- package/dist/pt-BR.mjs +13 -0
- package/dist/pt-BR.module.js +13 -0
- package/dist/pt-BR.module.js.map +1 -0
- package/dist/pt-PT.main.js +11 -0
- package/dist/pt-PT.main.js.map +1 -0
- package/dist/pt-PT.mjs +13 -0
- package/dist/pt-PT.module.js +13 -0
- package/dist/pt-PT.module.js.map +1 -0
- package/dist/ro-RO.main.js +11 -0
- package/dist/ro-RO.main.js.map +1 -0
- package/dist/ro-RO.mjs +13 -0
- package/dist/ro-RO.module.js +13 -0
- package/dist/ro-RO.module.js.map +1 -0
- package/dist/ru-RU.main.js +11 -0
- package/dist/ru-RU.main.js.map +1 -0
- package/dist/ru-RU.mjs +13 -0
- package/dist/ru-RU.module.js +13 -0
- package/dist/ru-RU.module.js.map +1 -0
- package/dist/sk-SK.main.js +11 -0
- package/dist/sk-SK.main.js.map +1 -0
- package/dist/sk-SK.mjs +13 -0
- package/dist/sk-SK.module.js +13 -0
- package/dist/sk-SK.module.js.map +1 -0
- package/dist/sl-SI.main.js +11 -0
- package/dist/sl-SI.main.js.map +1 -0
- package/dist/sl-SI.mjs +13 -0
- package/dist/sl-SI.module.js +13 -0
- package/dist/sl-SI.module.js.map +1 -0
- package/dist/sr-SP.main.js +11 -0
- package/dist/sr-SP.main.js.map +1 -0
- package/dist/sr-SP.mjs +13 -0
- package/dist/sr-SP.module.js +13 -0
- package/dist/sr-SP.module.js.map +1 -0
- package/dist/sv-SE.main.js +11 -0
- package/dist/sv-SE.main.js.map +1 -0
- package/dist/sv-SE.mjs +13 -0
- package/dist/sv-SE.module.js +13 -0
- package/dist/sv-SE.module.js.map +1 -0
- package/dist/tr-TR.main.js +11 -0
- package/dist/tr-TR.main.js.map +1 -0
- package/dist/tr-TR.mjs +13 -0
- package/dist/tr-TR.module.js +13 -0
- package/dist/tr-TR.module.js.map +1 -0
- package/dist/types.d.ts +41 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/uk-UA.main.js +11 -0
- package/dist/uk-UA.main.js.map +1 -0
- package/dist/uk-UA.mjs +13 -0
- package/dist/uk-UA.module.js +13 -0
- package/dist/uk-UA.module.js.map +1 -0
- package/dist/useColorArea.main.js +404 -0
- package/dist/useColorArea.main.js.map +1 -0
- package/dist/useColorArea.mjs +399 -0
- package/dist/useColorArea.module.js +399 -0
- package/dist/useColorArea.module.js.map +1 -0
- package/dist/useColorAreaGradient.main.js +123 -0
- package/dist/useColorAreaGradient.main.js.map +1 -0
- package/dist/useColorAreaGradient.mjs +118 -0
- package/dist/useColorAreaGradient.module.js +118 -0
- package/dist/useColorAreaGradient.module.js.map +1 -0
- package/dist/useColorChannelField.main.js +36 -0
- package/dist/useColorChannelField.main.js.map +1 -0
- package/dist/useColorChannelField.mjs +31 -0
- package/dist/useColorChannelField.module.js +31 -0
- package/dist/useColorChannelField.module.js.map +1 -0
- package/dist/useColorField.main.js +98 -0
- package/dist/useColorField.main.js.map +1 -0
- package/dist/useColorField.mjs +93 -0
- package/dist/useColorField.module.js +93 -0
- package/dist/useColorField.module.js.map +1 -0
- package/dist/useColorSlider.main.js +132 -0
- package/dist/useColorSlider.main.js.map +1 -0
- package/dist/useColorSlider.mjs +127 -0
- package/dist/useColorSlider.module.js +127 -0
- package/dist/useColorSlider.module.js.map +1 -0
- package/dist/useColorSwatch.main.js +67 -0
- package/dist/useColorSwatch.main.js.map +1 -0
- package/dist/useColorSwatch.mjs +62 -0
- package/dist/useColorSwatch.module.js +62 -0
- package/dist/useColorSwatch.module.js.map +1 -0
- package/dist/useColorWheel.main.js +274 -0
- package/dist/useColorWheel.main.js.map +1 -0
- package/dist/useColorWheel.mjs +269 -0
- package/dist/useColorWheel.module.js +269 -0
- package/dist/useColorWheel.module.js.map +1 -0
- package/dist/zh-CN.main.js +11 -0
- package/dist/zh-CN.main.js.map +1 -0
- package/dist/zh-CN.mjs +13 -0
- package/dist/zh-CN.module.js +13 -0
- package/dist/zh-CN.module.js.map +1 -0
- package/dist/zh-TW.main.js +11 -0
- package/dist/zh-TW.main.js.map +1 -0
- package/dist/zh-TW.mjs +13 -0
- package/dist/zh-TW.module.js +13 -0
- package/dist/zh-TW.module.js.map +1 -0
- package/package.json +14 -13
- package/src/index.ts +4 -0
- package/src/useColorArea.ts +32 -23
- package/src/useColorAreaGradient.ts +66 -189
- package/src/useColorChannelField.ts +37 -0
- package/src/useColorField.ts +18 -14
- package/src/useColorSlider.ts +28 -4
- package/src/useColorSwatch.ts +74 -0
- package/src/useColorWheel.ts +19 -5
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import $8t1z9$intlStringsmodulejs from "./intlStrings.mjs";
|
|
2
|
+
import {useColorAreaGradient as $40297c24c53588e6$export$dd62420467d245ca} from "./useColorAreaGradient.mjs";
|
|
3
|
+
import {useGlobalListeners as $8t1z9$useGlobalListeners, focusWithoutScrolling as $8t1z9$focusWithoutScrolling, useFormReset as $8t1z9$useFormReset, mergeProps as $8t1z9$mergeProps, isIOS as $8t1z9$isIOS, isAndroid as $8t1z9$isAndroid, useLabels as $8t1z9$useLabels} from "@react-aria/utils";
|
|
4
|
+
import {useState as $8t1z9$useState, useCallback as $8t1z9$useCallback, useRef as $8t1z9$useRef} from "react";
|
|
5
|
+
import {useKeyboard as $8t1z9$useKeyboard, useMove as $8t1z9$useMove, useFocusWithin as $8t1z9$useFocusWithin, useFocus as $8t1z9$useFocus} from "@react-aria/interactions";
|
|
6
|
+
import {useLocalizedStringFormatter as $8t1z9$useLocalizedStringFormatter, useLocale as $8t1z9$useLocale} from "@react-aria/i18n";
|
|
7
|
+
import {useVisuallyHidden as $8t1z9$useVisuallyHidden} from "@react-aria/visually-hidden";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
function $parcel$interopDefault(a) {
|
|
11
|
+
return a && a.__esModule ? a.default : a;
|
|
12
|
+
}
|
|
13
|
+
/*
|
|
14
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
15
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
17
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
20
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
21
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
22
|
+
* governing permissions and limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function $60bd7d6e45dcddfa$export$2f92a7a615a014f6(props, state) {
|
|
31
|
+
let { isDisabled: isDisabled, inputXRef: inputXRef, inputYRef: inputYRef, containerRef: containerRef, "aria-label": ariaLabel, xName: xName, yName: yName } = props;
|
|
32
|
+
let stringFormatter = (0, $8t1z9$useLocalizedStringFormatter)((0, ($parcel$interopDefault($8t1z9$intlStringsmodulejs))), "@react-aria/color");
|
|
33
|
+
let { addGlobalListener: addGlobalListener, removeGlobalListener: removeGlobalListener } = (0, $8t1z9$useGlobalListeners)();
|
|
34
|
+
let { direction: direction, locale: locale } = (0, $8t1z9$useLocale)();
|
|
35
|
+
let [focusedInput, setFocusedInput] = (0, $8t1z9$useState)(null);
|
|
36
|
+
let focusInput = (0, $8t1z9$useCallback)((inputRef = inputXRef)=>{
|
|
37
|
+
if (inputRef.current) (0, $8t1z9$focusWithoutScrolling)(inputRef.current);
|
|
38
|
+
}, [
|
|
39
|
+
inputXRef
|
|
40
|
+
]);
|
|
41
|
+
(0, $8t1z9$useFormReset)(inputXRef, [
|
|
42
|
+
state.xValue,
|
|
43
|
+
state.yValue
|
|
44
|
+
], ([x, y])=>{
|
|
45
|
+
let newColor = state.value.withChannelValue(state.channels.xChannel, x).withChannelValue(state.channels.yChannel, y);
|
|
46
|
+
state.setValue(newColor);
|
|
47
|
+
});
|
|
48
|
+
let [valueChangedViaKeyboard, setValueChangedViaKeyboard] = (0, $8t1z9$useState)(false);
|
|
49
|
+
let [valueChangedViaInputChangeEvent, setValueChangedViaInputChangeEvent] = (0, $8t1z9$useState)(false);
|
|
50
|
+
let { xChannel: xChannel, yChannel: yChannel, zChannel: zChannel } = state.channels;
|
|
51
|
+
let xChannelStep = state.xChannelStep;
|
|
52
|
+
let yChannelStep = state.yChannelStep;
|
|
53
|
+
let currentPosition = (0, $8t1z9$useRef)(null);
|
|
54
|
+
let { keyboardProps: keyboardProps } = (0, $8t1z9$useKeyboard)({
|
|
55
|
+
onKeyDown (e) {
|
|
56
|
+
// these are the cases that useMove doesn't handle
|
|
57
|
+
if (!/^(PageUp|PageDown|Home|End)$/.test(e.key)) {
|
|
58
|
+
e.continuePropagation();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// same handling as useMove, don't need to stop propagation, useKeyboard will do that for us
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
// remember to set this and unset it so that onChangeEnd is fired
|
|
64
|
+
state.setDragging(true);
|
|
65
|
+
setValueChangedViaKeyboard(true);
|
|
66
|
+
let dir;
|
|
67
|
+
switch(e.key){
|
|
68
|
+
case "PageUp":
|
|
69
|
+
state.incrementY(state.yChannelPageStep);
|
|
70
|
+
dir = "y";
|
|
71
|
+
break;
|
|
72
|
+
case "PageDown":
|
|
73
|
+
state.decrementY(state.yChannelPageStep);
|
|
74
|
+
dir = "y";
|
|
75
|
+
break;
|
|
76
|
+
case "Home":
|
|
77
|
+
direction === "rtl" ? state.incrementX(state.xChannelPageStep) : state.decrementX(state.xChannelPageStep);
|
|
78
|
+
dir = "x";
|
|
79
|
+
break;
|
|
80
|
+
case "End":
|
|
81
|
+
direction === "rtl" ? state.decrementX(state.xChannelPageStep) : state.incrementX(state.xChannelPageStep);
|
|
82
|
+
dir = "x";
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
state.setDragging(false);
|
|
86
|
+
if (dir) {
|
|
87
|
+
let input = dir === "x" ? inputXRef : inputYRef;
|
|
88
|
+
focusInput(input);
|
|
89
|
+
setFocusedInput(dir);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
let moveHandler = {
|
|
94
|
+
onMoveStart () {
|
|
95
|
+
currentPosition.current = null;
|
|
96
|
+
state.setDragging(true);
|
|
97
|
+
},
|
|
98
|
+
onMove ({ deltaX: deltaX, deltaY: deltaY, pointerType: pointerType, shiftKey: shiftKey }) {
|
|
99
|
+
var _containerRef_current;
|
|
100
|
+
let { incrementX: incrementX, decrementX: decrementX, incrementY: incrementY, decrementY: decrementY, xChannelPageStep: xChannelPageStep, xChannelStep: xChannelStep, yChannelPageStep: yChannelPageStep, yChannelStep: yChannelStep, getThumbPosition: getThumbPosition, setColorFromPoint: setColorFromPoint } = state;
|
|
101
|
+
if (currentPosition.current == null) currentPosition.current = getThumbPosition();
|
|
102
|
+
let { width: width, height: height } = ((_containerRef_current = containerRef.current) === null || _containerRef_current === void 0 ? void 0 : _containerRef_current.getBoundingClientRect()) || {
|
|
103
|
+
width: 0,
|
|
104
|
+
height: 0
|
|
105
|
+
};
|
|
106
|
+
let valueChanged = deltaX !== 0 || deltaY !== 0;
|
|
107
|
+
if (pointerType === "keyboard") {
|
|
108
|
+
let deltaXValue = shiftKey && xChannelPageStep > xChannelStep ? xChannelPageStep : xChannelStep;
|
|
109
|
+
let deltaYValue = shiftKey && yChannelPageStep > yChannelStep ? yChannelPageStep : yChannelStep;
|
|
110
|
+
if (deltaX > 0 && direction === "ltr" || deltaX < 0 && direction === "rtl") incrementX(deltaXValue);
|
|
111
|
+
else if (deltaX < 0 && direction === "ltr" || deltaX > 0 && direction === "rtl") decrementX(deltaXValue);
|
|
112
|
+
else if (deltaY > 0) decrementY(deltaYValue);
|
|
113
|
+
else if (deltaY < 0) incrementY(deltaYValue);
|
|
114
|
+
setValueChangedViaKeyboard(valueChanged);
|
|
115
|
+
// set the focused input based on which axis has the greater delta
|
|
116
|
+
focusedInput = valueChanged && Math.abs(deltaY) > Math.abs(deltaX) ? "y" : "x";
|
|
117
|
+
setFocusedInput(focusedInput);
|
|
118
|
+
} else {
|
|
119
|
+
currentPosition.current.x += (direction === "rtl" ? -1 : 1) * deltaX / width;
|
|
120
|
+
currentPosition.current.y += deltaY / height;
|
|
121
|
+
setColorFromPoint(currentPosition.current.x, currentPosition.current.y);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
onMoveEnd () {
|
|
125
|
+
isOnColorArea.current = false;
|
|
126
|
+
state.setDragging(false);
|
|
127
|
+
let input = focusedInput === "x" ? inputXRef : inputYRef;
|
|
128
|
+
focusInput(input);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
let { moveProps: movePropsThumb } = (0, $8t1z9$useMove)(moveHandler);
|
|
132
|
+
let { focusWithinProps: focusWithinProps } = (0, $8t1z9$useFocusWithin)({
|
|
133
|
+
onFocusWithinChange: (focusWithin)=>{
|
|
134
|
+
if (!focusWithin) {
|
|
135
|
+
setValueChangedViaKeyboard(false);
|
|
136
|
+
setValueChangedViaInputChangeEvent(false);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
let currentPointer = (0, $8t1z9$useRef)(undefined);
|
|
141
|
+
let isOnColorArea = (0, $8t1z9$useRef)(false);
|
|
142
|
+
let { moveProps: movePropsContainer } = (0, $8t1z9$useMove)({
|
|
143
|
+
onMoveStart () {
|
|
144
|
+
if (isOnColorArea.current) moveHandler.onMoveStart();
|
|
145
|
+
},
|
|
146
|
+
onMove (e) {
|
|
147
|
+
if (isOnColorArea.current) moveHandler.onMove(e);
|
|
148
|
+
},
|
|
149
|
+
onMoveEnd () {
|
|
150
|
+
if (isOnColorArea.current) moveHandler.onMoveEnd();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
let onThumbDown = (id)=>{
|
|
154
|
+
if (!state.isDragging) {
|
|
155
|
+
currentPointer.current = id;
|
|
156
|
+
setValueChangedViaKeyboard(false);
|
|
157
|
+
focusInput();
|
|
158
|
+
state.setDragging(true);
|
|
159
|
+
if (typeof PointerEvent !== "undefined") addGlobalListener(window, "pointerup", onThumbUp, false);
|
|
160
|
+
else {
|
|
161
|
+
addGlobalListener(window, "mouseup", onThumbUp, false);
|
|
162
|
+
addGlobalListener(window, "touchend", onThumbUp, false);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
let onThumbUp = (e)=>{
|
|
167
|
+
var _e_changedTouches;
|
|
168
|
+
var _e_pointerId;
|
|
169
|
+
let id = (_e_pointerId = e.pointerId) !== null && _e_pointerId !== void 0 ? _e_pointerId : (_e_changedTouches = e.changedTouches) === null || _e_changedTouches === void 0 ? void 0 : _e_changedTouches[0].identifier;
|
|
170
|
+
if (id === currentPointer.current) {
|
|
171
|
+
setValueChangedViaKeyboard(false);
|
|
172
|
+
focusInput();
|
|
173
|
+
state.setDragging(false);
|
|
174
|
+
currentPointer.current = undefined;
|
|
175
|
+
isOnColorArea.current = false;
|
|
176
|
+
if (typeof PointerEvent !== "undefined") removeGlobalListener(window, "pointerup", onThumbUp, false);
|
|
177
|
+
else {
|
|
178
|
+
removeGlobalListener(window, "mouseup", onThumbUp, false);
|
|
179
|
+
removeGlobalListener(window, "touchend", onThumbUp, false);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
let onColorAreaDown = (colorArea, id, clientX, clientY)=>{
|
|
184
|
+
let rect = colorArea.getBoundingClientRect();
|
|
185
|
+
let { width: width, height: height } = rect;
|
|
186
|
+
let x = (clientX - rect.x) / width;
|
|
187
|
+
let y = (clientY - rect.y) / height;
|
|
188
|
+
if (direction === "rtl") x = 1 - x;
|
|
189
|
+
if (x >= 0 && x <= 1 && y >= 0 && y <= 1 && !state.isDragging && currentPointer.current === undefined) {
|
|
190
|
+
isOnColorArea.current = true;
|
|
191
|
+
setValueChangedViaKeyboard(false);
|
|
192
|
+
currentPointer.current = id;
|
|
193
|
+
state.setColorFromPoint(x, y);
|
|
194
|
+
focusInput();
|
|
195
|
+
state.setDragging(true);
|
|
196
|
+
if (typeof PointerEvent !== "undefined") addGlobalListener(window, "pointerup", onColorAreaUp, false);
|
|
197
|
+
else {
|
|
198
|
+
addGlobalListener(window, "mouseup", onColorAreaUp, false);
|
|
199
|
+
addGlobalListener(window, "touchend", onColorAreaUp, false);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
let onColorAreaUp = (e)=>{
|
|
204
|
+
var _e_changedTouches;
|
|
205
|
+
var _e_pointerId;
|
|
206
|
+
let id = (_e_pointerId = e.pointerId) !== null && _e_pointerId !== void 0 ? _e_pointerId : (_e_changedTouches = e.changedTouches) === null || _e_changedTouches === void 0 ? void 0 : _e_changedTouches[0].identifier;
|
|
207
|
+
if (isOnColorArea.current && id === currentPointer.current) {
|
|
208
|
+
isOnColorArea.current = false;
|
|
209
|
+
setValueChangedViaKeyboard(false);
|
|
210
|
+
currentPointer.current = undefined;
|
|
211
|
+
state.setDragging(false);
|
|
212
|
+
focusInput();
|
|
213
|
+
if (typeof PointerEvent !== "undefined") removeGlobalListener(window, "pointerup", onColorAreaUp, false);
|
|
214
|
+
else {
|
|
215
|
+
removeGlobalListener(window, "mouseup", onColorAreaUp, false);
|
|
216
|
+
removeGlobalListener(window, "touchend", onColorAreaUp, false);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
let colorAreaInteractions = isDisabled ? {} : (0, $8t1z9$mergeProps)({
|
|
221
|
+
...typeof PointerEvent !== "undefined" ? {
|
|
222
|
+
onPointerDown: (e)=>{
|
|
223
|
+
if (e.pointerType === "mouse" && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
|
|
224
|
+
onColorAreaDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);
|
|
225
|
+
}
|
|
226
|
+
} : {
|
|
227
|
+
onMouseDown: (e)=>{
|
|
228
|
+
if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
229
|
+
onColorAreaDown(e.currentTarget, undefined, e.clientX, e.clientY);
|
|
230
|
+
},
|
|
231
|
+
onTouchStart: (e)=>{
|
|
232
|
+
onColorAreaDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}, movePropsContainer);
|
|
236
|
+
let thumbInteractions = isDisabled ? {} : (0, $8t1z9$mergeProps)({
|
|
237
|
+
...typeof PointerEvent !== "undefined" ? {
|
|
238
|
+
onPointerDown: (e)=>{
|
|
239
|
+
if (e.pointerType === "mouse" && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
|
|
240
|
+
onThumbDown(e.pointerId);
|
|
241
|
+
}
|
|
242
|
+
} : {
|
|
243
|
+
onMouseDown: (e)=>{
|
|
244
|
+
if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
245
|
+
onThumbDown(undefined);
|
|
246
|
+
},
|
|
247
|
+
onTouchStart: (e)=>{
|
|
248
|
+
onThumbDown(e.changedTouches[0].identifier);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}, focusWithinProps, keyboardProps, movePropsThumb);
|
|
252
|
+
let { focusProps: xInputFocusProps } = (0, $8t1z9$useFocus)({
|
|
253
|
+
onFocus: ()=>{
|
|
254
|
+
setFocusedInput("x");
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
let { focusProps: yInputFocusProps } = (0, $8t1z9$useFocus)({
|
|
258
|
+
onFocus: ()=>{
|
|
259
|
+
setFocusedInput("y");
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
const onChange = (e)=>{
|
|
263
|
+
const { target: target } = e;
|
|
264
|
+
setValueChangedViaInputChangeEvent(true);
|
|
265
|
+
if (target === inputXRef.current) state.setXValue(parseFloat(target.value));
|
|
266
|
+
else if (target === inputYRef.current) state.setYValue(parseFloat(target.value));
|
|
267
|
+
};
|
|
268
|
+
let isMobile = (0, $8t1z9$isIOS)() || (0, $8t1z9$isAndroid)();
|
|
269
|
+
let value = state.getDisplayColor();
|
|
270
|
+
const getAriaValueTextForChannel = (0, $8t1z9$useCallback)((channel)=>{
|
|
271
|
+
const isAfterInput = valueChangedViaInputChangeEvent || valueChangedViaKeyboard;
|
|
272
|
+
return `${isAfterInput ? stringFormatter.format("colorNameAndValue", {
|
|
273
|
+
name: value.getChannelName(channel, locale),
|
|
274
|
+
value: value.formatChannelValue(channel, locale)
|
|
275
|
+
}) : [
|
|
276
|
+
stringFormatter.format("colorNameAndValue", {
|
|
277
|
+
name: value.getChannelName(channel, locale),
|
|
278
|
+
value: value.formatChannelValue(channel, locale)
|
|
279
|
+
}),
|
|
280
|
+
stringFormatter.format("colorNameAndValue", {
|
|
281
|
+
name: value.getChannelName(channel === yChannel ? xChannel : yChannel, locale),
|
|
282
|
+
value: value.formatChannelValue(channel === yChannel ? xChannel : yChannel, locale)
|
|
283
|
+
}),
|
|
284
|
+
stringFormatter.format("colorNameAndValue", {
|
|
285
|
+
name: value.getChannelName(zChannel, locale),
|
|
286
|
+
value: value.formatChannelValue(zChannel, locale)
|
|
287
|
+
})
|
|
288
|
+
].join(", ")}, ${value.getColorName(locale)}`;
|
|
289
|
+
}, [
|
|
290
|
+
locale,
|
|
291
|
+
value,
|
|
292
|
+
stringFormatter,
|
|
293
|
+
valueChangedViaInputChangeEvent,
|
|
294
|
+
valueChangedViaKeyboard,
|
|
295
|
+
xChannel,
|
|
296
|
+
yChannel,
|
|
297
|
+
zChannel
|
|
298
|
+
]);
|
|
299
|
+
let colorPickerLabel = stringFormatter.format("colorPicker");
|
|
300
|
+
let xInputLabellingProps = (0, $8t1z9$useLabels)({
|
|
301
|
+
...props,
|
|
302
|
+
"aria-label": ariaLabel ? stringFormatter.format("colorInputLabel", {
|
|
303
|
+
label: ariaLabel,
|
|
304
|
+
channelLabel: colorPickerLabel
|
|
305
|
+
}) : colorPickerLabel
|
|
306
|
+
});
|
|
307
|
+
let yInputLabellingProps = (0, $8t1z9$useLabels)({
|
|
308
|
+
...props,
|
|
309
|
+
"aria-label": ariaLabel ? stringFormatter.format("colorInputLabel", {
|
|
310
|
+
label: ariaLabel,
|
|
311
|
+
channelLabel: colorPickerLabel
|
|
312
|
+
}) : colorPickerLabel
|
|
313
|
+
});
|
|
314
|
+
let colorAreaLabellingProps = (0, $8t1z9$useLabels)({
|
|
315
|
+
...props,
|
|
316
|
+
"aria-label": ariaLabel ? `${ariaLabel}, ${colorPickerLabel}` : undefined
|
|
317
|
+
}, isMobile ? colorPickerLabel : undefined);
|
|
318
|
+
let ariaRoleDescription = stringFormatter.format("twoDimensionalSlider");
|
|
319
|
+
let { visuallyHiddenProps: visuallyHiddenProps } = (0, $8t1z9$useVisuallyHidden)({
|
|
320
|
+
style: {
|
|
321
|
+
opacity: "0.0001",
|
|
322
|
+
width: "100%",
|
|
323
|
+
height: "100%",
|
|
324
|
+
pointerEvents: "none"
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
let { colorAreaStyleProps: colorAreaStyleProps, thumbStyleProps: thumbStyleProps } = (0, $40297c24c53588e6$export$dd62420467d245ca)({
|
|
328
|
+
direction: direction,
|
|
329
|
+
state: state,
|
|
330
|
+
xChannel: xChannel,
|
|
331
|
+
yChannel: yChannel,
|
|
332
|
+
zChannel: zChannel
|
|
333
|
+
});
|
|
334
|
+
return {
|
|
335
|
+
colorAreaProps: {
|
|
336
|
+
...colorAreaLabellingProps,
|
|
337
|
+
...colorAreaInteractions,
|
|
338
|
+
...colorAreaStyleProps,
|
|
339
|
+
role: "group"
|
|
340
|
+
},
|
|
341
|
+
thumbProps: {
|
|
342
|
+
...thumbInteractions,
|
|
343
|
+
...thumbStyleProps,
|
|
344
|
+
role: "presentation"
|
|
345
|
+
},
|
|
346
|
+
xInputProps: {
|
|
347
|
+
...xInputLabellingProps,
|
|
348
|
+
...visuallyHiddenProps,
|
|
349
|
+
...xInputFocusProps,
|
|
350
|
+
type: "range",
|
|
351
|
+
min: state.value.getChannelRange(xChannel).minValue,
|
|
352
|
+
max: state.value.getChannelRange(xChannel).maxValue,
|
|
353
|
+
step: xChannelStep,
|
|
354
|
+
"aria-roledescription": ariaRoleDescription,
|
|
355
|
+
"aria-valuetext": getAriaValueTextForChannel(xChannel),
|
|
356
|
+
"aria-orientation": "horizontal",
|
|
357
|
+
"aria-describedby": props["aria-describedby"],
|
|
358
|
+
"aria-details": props["aria-details"],
|
|
359
|
+
disabled: isDisabled,
|
|
360
|
+
value: state.value.getChannelValue(xChannel),
|
|
361
|
+
name: xName,
|
|
362
|
+
tabIndex: isMobile || !focusedInput || focusedInput === "x" ? undefined : -1,
|
|
363
|
+
/*
|
|
364
|
+
So that only a single "2d slider" control shows up when listing form elements for screen readers,
|
|
365
|
+
add aria-hidden="true" to the unfocused control when the value has not changed via the keyboard,
|
|
366
|
+
but remove aria-hidden to reveal the input for each channel when the value has changed with the keyboard.
|
|
367
|
+
*/ "aria-hidden": isMobile || !focusedInput || focusedInput === "x" || valueChangedViaKeyboard ? undefined : "true",
|
|
368
|
+
onChange: onChange
|
|
369
|
+
},
|
|
370
|
+
yInputProps: {
|
|
371
|
+
...yInputLabellingProps,
|
|
372
|
+
...visuallyHiddenProps,
|
|
373
|
+
...yInputFocusProps,
|
|
374
|
+
type: "range",
|
|
375
|
+
min: state.value.getChannelRange(yChannel).minValue,
|
|
376
|
+
max: state.value.getChannelRange(yChannel).maxValue,
|
|
377
|
+
step: yChannelStep,
|
|
378
|
+
"aria-roledescription": ariaRoleDescription,
|
|
379
|
+
"aria-valuetext": getAriaValueTextForChannel(yChannel),
|
|
380
|
+
"aria-orientation": "vertical",
|
|
381
|
+
"aria-describedby": props["aria-describedby"],
|
|
382
|
+
"aria-details": props["aria-details"],
|
|
383
|
+
disabled: isDisabled,
|
|
384
|
+
value: state.value.getChannelValue(yChannel),
|
|
385
|
+
name: yName,
|
|
386
|
+
tabIndex: isMobile || focusedInput === "y" ? undefined : -1,
|
|
387
|
+
/*
|
|
388
|
+
So that only a single "2d slider" control shows up when listing form elements for screen readers,
|
|
389
|
+
add aria-hidden="true" to the unfocused input when the value has not changed via the keyboard,
|
|
390
|
+
but remove aria-hidden to reveal the input for each channel when the value has changed with the keyboard.
|
|
391
|
+
*/ "aria-hidden": isMobile || focusedInput === "y" || valueChangedViaKeyboard ? undefined : "true",
|
|
392
|
+
onChange: onChange
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
export {$60bd7d6e45dcddfa$export$2f92a7a615a014f6 as useColorArea};
|
|
399
|
+
//# sourceMappingURL=useColorArea.mjs.map
|