@react-stately/color 3.0.0-nightly.3134 → 3.0.0-nightly.3156
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 +40 -46
- package/dist/main.js.map +1 -1
- package/dist/module.js +39 -46
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -10
- package/src/Color.ts +1 -1
- package/src/index.ts +1 -1
- package/src/useColorAreaState.ts +19 -25
- package/src/useColorFieldState.ts +7 -4
- package/src/useColorSliderState.ts +5 -2
- package/src/useColorWheelState.ts +11 -10
package/dist/main.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
var $4tN2K$reactstatelyutils = require("@react-stately/utils");
|
|
2
2
|
var $4tN2K$internationalizedmessage = require("@internationalized/message");
|
|
3
3
|
var $4tN2K$internationalizednumber = require("@internationalized/number");
|
|
4
|
-
var $4tN2K$reactariautils = require("@react-aria/utils");
|
|
5
4
|
var $4tN2K$react = require("react");
|
|
6
5
|
var $4tN2K$reactstatelyslider = require("@react-stately/slider");
|
|
7
6
|
|
|
7
|
+
function $parcel$export(e, n, v, s) {
|
|
8
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
|
+
}
|
|
8
10
|
function $parcel$exportWildcard(dest, source) {
|
|
9
11
|
Object.keys(source).forEach(function(key) {
|
|
10
12
|
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
@@ -24,13 +26,8 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
24
26
|
function $parcel$interopDefault(a) {
|
|
25
27
|
return a && a.__esModule ? a.default : a;
|
|
26
28
|
}
|
|
27
|
-
function $parcel$export(e, n, v, s) {
|
|
28
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
29
|
-
}
|
|
30
|
-
var $83fe1a57d631223b$exports = {};
|
|
31
29
|
|
|
32
|
-
$parcel$export(
|
|
33
|
-
$parcel$export($83fe1a57d631223b$exports, "normalizeColor", () => $83fe1a57d631223b$export$4cde5df63f53f473);
|
|
30
|
+
$parcel$export(module.exports, "parseColor", () => $83fe1a57d631223b$export$6e865ea70d7724f);
|
|
34
31
|
|
|
35
32
|
var $c0b600cf8eafdee9$exports = {};
|
|
36
33
|
var $b044e7150534af04$exports = {};
|
|
@@ -376,7 +373,7 @@ class $83fe1a57d631223b$var$RGBColor extends $83fe1a57d631223b$var$Color {
|
|
|
376
373
|
minValue: 0,
|
|
377
374
|
maxValue: 255,
|
|
378
375
|
step: 1,
|
|
379
|
-
pageSize:
|
|
376
|
+
pageSize: 17
|
|
380
377
|
};
|
|
381
378
|
case 'alpha':
|
|
382
379
|
return {
|
|
@@ -710,7 +707,6 @@ $parcel$export($af2d7ac9990cfee2$exports, "useColorAreaState", () => $af2d7ac999
|
|
|
710
707
|
|
|
711
708
|
|
|
712
709
|
|
|
713
|
-
|
|
714
710
|
const $af2d7ac9990cfee2$var$DEFAULT_COLOR = $83fe1a57d631223b$export$6e865ea70d7724f('#ffffff');
|
|
715
711
|
const $af2d7ac9990cfee2$var$RGBSet = new Set([
|
|
716
712
|
'red',
|
|
@@ -723,8 +719,7 @@ let $af2d7ac9990cfee2$var$difference = (a, b)=>new Set([
|
|
|
723
719
|
))
|
|
724
720
|
;
|
|
725
721
|
function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
|
|
726
|
-
|
|
727
|
-
let { value: value1 , defaultValue: defaultValue , xChannel: xChannel , yChannel: yChannel , onChange: onChange , onChangeEnd: onChangeEnd , xChannelStep: xChannelStep , yChannelStep: yChannelStep } = props;
|
|
722
|
+
let { value: value1 , defaultValue: defaultValue , xChannel: xChannel , yChannel: yChannel , onChange: onChange , onChangeEnd: onChangeEnd } = props;
|
|
728
723
|
if (!value1 && !defaultValue) defaultValue = $af2d7ac9990cfee2$var$DEFAULT_COLOR;
|
|
729
724
|
let [color, setColor] = $4tN2K$reactstatelyutils.useControlledState(value1 && $83fe1a57d631223b$export$4cde5df63f53f473(value1), defaultValue && $83fe1a57d631223b$export$4cde5df63f53f473(defaultValue), onChange);
|
|
730
725
|
let valueRef = $4tN2K$react.useRef(color);
|
|
@@ -771,10 +766,6 @@ function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
|
|
|
771
766
|
let yChannelRange = color.getChannelRange(channels.yChannel);
|
|
772
767
|
let { minValue: minValueX1 , maxValue: maxValueX1 , step: stepX , pageSize: pageSizeX } = xChannelRange;
|
|
773
768
|
let { minValue: minValueY1 , maxValue: maxValueY1 , step: stepY , pageSize: pageSizeY } = yChannelRange;
|
|
774
|
-
if (isNaN(xChannelStep)) xChannelStep = stepX;
|
|
775
|
-
if (isNaN(yChannelStep)) yChannelStep = stepY;
|
|
776
|
-
let xChannelPageStep = Math.max(pageSizeX, xChannelStep);
|
|
777
|
-
let yChannelPageStep = Math.max(pageSizeY, yChannelStep);
|
|
778
769
|
let [isDragging1, setDragging] = $4tN2K$react.useState(false);
|
|
779
770
|
let isDraggingRef = $4tN2K$react.useRef(false).current;
|
|
780
771
|
let xValue = color.getChannelValue(channels.xChannel);
|
|
@@ -791,10 +782,10 @@ function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
|
|
|
791
782
|
};
|
|
792
783
|
return {
|
|
793
784
|
channels: channels,
|
|
794
|
-
xChannelStep:
|
|
795
|
-
yChannelStep:
|
|
796
|
-
xChannelPageStep:
|
|
797
|
-
yChannelPageStep:
|
|
785
|
+
xChannelStep: stepX,
|
|
786
|
+
yChannelStep: stepY,
|
|
787
|
+
xChannelPageStep: pageSizeX,
|
|
788
|
+
yChannelPageStep: pageSizeY,
|
|
798
789
|
value: color,
|
|
799
790
|
setValue (value) {
|
|
800
791
|
let c = $83fe1a57d631223b$export$4cde5df63f53f473(value);
|
|
@@ -808,17 +799,17 @@ function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
|
|
|
808
799
|
setColorFromPoint (x, y) {
|
|
809
800
|
let { minValue: minValueX , maxValue: maxValueX } = color.getChannelRange(channels.xChannel);
|
|
810
801
|
let { minValue: minValueY , maxValue: maxValueY } = color.getChannelRange(channels.yChannel);
|
|
811
|
-
let newXValue = minValueX + $4tN2K$
|
|
812
|
-
let newYValue = minValueY + (1 - $4tN2K$
|
|
802
|
+
let newXValue = minValueX + $4tN2K$reactstatelyutils.clamp(x, 0, 1) * (maxValueX - minValueX);
|
|
803
|
+
let newYValue = minValueY + (1 - $4tN2K$reactstatelyutils.clamp(y, 0, 1)) * (maxValueY - minValueY);
|
|
813
804
|
let newColor;
|
|
814
805
|
if (newXValue !== xValue) {
|
|
815
806
|
// Round new value to multiple of step, clamp value between min and max
|
|
816
|
-
newXValue = $4tN2K$
|
|
807
|
+
newXValue = $4tN2K$reactstatelyutils.snapValueToStep(newXValue, minValueX, maxValueX, stepX);
|
|
817
808
|
newColor = color.withChannelValue(channels.xChannel, newXValue);
|
|
818
809
|
}
|
|
819
810
|
if (newYValue !== yValue) {
|
|
820
811
|
// Round new value to multiple of step, clamp value between min and max
|
|
821
|
-
newYValue = $4tN2K$
|
|
812
|
+
newYValue = $4tN2K$reactstatelyutils.snapValueToStep(newYValue, minValueY, maxValueY, stepY);
|
|
822
813
|
newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);
|
|
823
814
|
}
|
|
824
815
|
if (newColor) setColor(newColor);
|
|
@@ -832,16 +823,16 @@ function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
|
|
|
832
823
|
};
|
|
833
824
|
},
|
|
834
825
|
incrementX (stepSize) {
|
|
835
|
-
setXValue($4tN2K$
|
|
826
|
+
setXValue(xValue + stepSize > maxValueX1 ? maxValueX1 : $4tN2K$reactstatelyutils.snapValueToStep(xValue + stepSize, minValueX1, maxValueX1, stepX));
|
|
836
827
|
},
|
|
837
828
|
incrementY (stepSize) {
|
|
838
|
-
setYValue($4tN2K$
|
|
829
|
+
setYValue(yValue + stepSize > maxValueY1 ? maxValueY1 : $4tN2K$reactstatelyutils.snapValueToStep(yValue + stepSize, minValueY1, maxValueY1, stepY));
|
|
839
830
|
},
|
|
840
831
|
decrementX (stepSize) {
|
|
841
|
-
setXValue($4tN2K$
|
|
832
|
+
setXValue($4tN2K$reactstatelyutils.snapValueToStep(xValue - stepSize, minValueX1, maxValueX1, stepX));
|
|
842
833
|
},
|
|
843
834
|
decrementY (stepSize) {
|
|
844
|
-
setYValue($4tN2K$
|
|
835
|
+
setYValue($4tN2K$reactstatelyutils.snapValueToStep(yValue - stepSize, minValueY1, maxValueY1, stepY));
|
|
845
836
|
},
|
|
846
837
|
setDragging (isDragging) {
|
|
847
838
|
let wasDragging = isDraggingRef;
|
|
@@ -879,10 +870,11 @@ function $5386a492cfd3234c$export$57bc203e1c9c6d44(props) {
|
|
|
879
870
|
setColor(color.withChannelValue(channel, v));
|
|
880
871
|
},
|
|
881
872
|
onChangeEnd ([v]) {
|
|
882
|
-
// onChange will have already been called with the right value, this is just to trigger
|
|
873
|
+
// onChange will have already been called with the right value, this is just to trigger onChangeEnd
|
|
883
874
|
if (props.onChangeEnd) props.onChangeEnd(color.withChannelValue(channel, v));
|
|
884
875
|
}
|
|
885
876
|
});
|
|
877
|
+
let { step: step , pageSize: pageSize } = color.getChannelRange(channel);
|
|
886
878
|
return {
|
|
887
879
|
...sliderState,
|
|
888
880
|
value: color,
|
|
@@ -908,7 +900,9 @@ function $5386a492cfd3234c$export$57bc203e1c9c6d44(props) {
|
|
|
908
900
|
},
|
|
909
901
|
getThumbValueLabel () {
|
|
910
902
|
return color.formatChannelValue(channel, locale);
|
|
911
|
-
}
|
|
903
|
+
},
|
|
904
|
+
step: step,
|
|
905
|
+
pageSize: pageSize
|
|
912
906
|
};
|
|
913
907
|
}
|
|
914
908
|
|
|
@@ -951,13 +945,14 @@ function $9d7d8736d45f74b8$var$cartesianToAngle(x, y, radius) {
|
|
|
951
945
|
let deg = $9d7d8736d45f74b8$var$radToDeg(Math.atan2(y / radius, x / radius));
|
|
952
946
|
return (deg + 360) % 360;
|
|
953
947
|
}
|
|
954
|
-
const $9d7d8736d45f74b8$var$PAGE_MIN_STEP_SIZE = 6;
|
|
955
948
|
function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
|
|
956
|
-
let { defaultValue: defaultValue , onChange: onChange , onChangeEnd: onChangeEnd
|
|
949
|
+
let { defaultValue: defaultValue , onChange: onChange , onChangeEnd: onChangeEnd } = props;
|
|
957
950
|
if (!props.value && !defaultValue) defaultValue = $9d7d8736d45f74b8$var$DEFAULT_COLOR;
|
|
958
951
|
let [value, setValue] = $4tN2K$reactstatelyutils.useControlledState($83fe1a57d631223b$export$4cde5df63f53f473(props.value), $83fe1a57d631223b$export$4cde5df63f53f473(defaultValue), onChange);
|
|
959
952
|
let valueRef = $4tN2K$react.useRef(value);
|
|
960
953
|
valueRef.current = value;
|
|
954
|
+
let channelRange = value.getChannelRange('hue');
|
|
955
|
+
let { minValue: minValueX , maxValue: maxValueX , step: step , pageSize: pageStep } = channelRange;
|
|
961
956
|
let [isDragging1, setDragging] = $4tN2K$react.useState(false);
|
|
962
957
|
let isDraggingRef = $4tN2K$react.useRef(false).current;
|
|
963
958
|
let hue = value.getChannelValue('hue');
|
|
@@ -971,7 +966,6 @@ function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
|
|
|
971
966
|
setValue(color);
|
|
972
967
|
}
|
|
973
968
|
}
|
|
974
|
-
let pageStep = $9d7d8736d45f74b8$var$PAGE_MIN_STEP_SIZE;
|
|
975
969
|
return {
|
|
976
970
|
value: value,
|
|
977
971
|
step: step,
|
|
@@ -989,18 +983,19 @@ function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
|
|
|
989
983
|
getThumbPosition (radius) {
|
|
990
984
|
return $9d7d8736d45f74b8$var$angleToCartesian(value.getChannelValue('hue'), radius);
|
|
991
985
|
},
|
|
992
|
-
increment (stepSize) {
|
|
993
|
-
let
|
|
994
|
-
|
|
995
|
-
newValue
|
|
996
|
-
|
|
986
|
+
increment (stepSize = 1) {
|
|
987
|
+
let s = Math.max(stepSize, step);
|
|
988
|
+
let newValue = hue + s;
|
|
989
|
+
if (newValue >= maxValueX) // Make sure you can always get back to 0.
|
|
990
|
+
newValue = minValueX;
|
|
991
|
+
setHue($9d7d8736d45f74b8$var$roundToStep($9d7d8736d45f74b8$var$mod(newValue, 360), s));
|
|
997
992
|
},
|
|
998
|
-
decrement (stepSize) {
|
|
993
|
+
decrement (stepSize = 1) {
|
|
999
994
|
let s = Math.max(stepSize, step);
|
|
1000
995
|
if (hue === 0) // We can't just subtract step because this might be the case:
|
|
1001
996
|
// |(previous step) - 0| < step size
|
|
1002
997
|
setHue($9d7d8736d45f74b8$var$roundDown(360 / s) * s);
|
|
1003
|
-
else setHue(hue - s);
|
|
998
|
+
else setHue($9d7d8736d45f74b8$var$roundToStep($9d7d8736d45f74b8$var$mod(hue - s, 360), s));
|
|
1004
999
|
},
|
|
1005
1000
|
setDragging (isDragging) {
|
|
1006
1001
|
let wasDragging = isDraggingRef;
|
|
@@ -1043,7 +1038,8 @@ const $d59d0c2b2ce1568f$var$MAX_COLOR = $83fe1a57d631223b$export$6e865ea70d7724f
|
|
|
1043
1038
|
const $d59d0c2b2ce1568f$var$MIN_COLOR_INT = $d59d0c2b2ce1568f$var$MIN_COLOR.toHexInt();
|
|
1044
1039
|
const $d59d0c2b2ce1568f$var$MAX_COLOR_INT = $d59d0c2b2ce1568f$var$MAX_COLOR.toHexInt();
|
|
1045
1040
|
function $d59d0c2b2ce1568f$export$d52a01683abdfcd6(props) {
|
|
1046
|
-
let {
|
|
1041
|
+
let { value: value1 , defaultValue: defaultValue , onChange: onChange } = props;
|
|
1042
|
+
let { step: step } = $d59d0c2b2ce1568f$var$MIN_COLOR.getChannelRange('red');
|
|
1047
1043
|
let initialValue = $f8b3be23ba4462b1$export$5aadd9c0606af5c2(value1);
|
|
1048
1044
|
let initialDefaultValue = $f8b3be23ba4462b1$export$5aadd9c0606af5c2(defaultValue);
|
|
1049
1045
|
let [colorValue, setColorValue] = $4tN2K$reactstatelyutils.useControlledState(initialValue, initialDefaultValue, onChange);
|
|
@@ -1059,12 +1055,11 @@ function $d59d0c2b2ce1568f$export$d52a01683abdfcd6(props) {
|
|
|
1059
1055
|
return;
|
|
1060
1056
|
}
|
|
1061
1057
|
};
|
|
1062
|
-
$4tN2K$react.
|
|
1058
|
+
let prevValue = $4tN2K$react.useRef(colorValue);
|
|
1059
|
+
if (prevValue.current !== colorValue) {
|
|
1063
1060
|
setInputValue(colorValue ? colorValue.toString('hex') : '');
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
setInputValue
|
|
1067
|
-
]);
|
|
1061
|
+
prevValue.current = colorValue;
|
|
1062
|
+
}
|
|
1068
1063
|
let parsedValue = $4tN2K$react.useMemo(()=>{
|
|
1069
1064
|
let color;
|
|
1070
1065
|
try {
|
|
@@ -1147,7 +1142,6 @@ function $d59d0c2b2ce1568f$var$addColorValue(color, step) {
|
|
|
1147
1142
|
}
|
|
1148
1143
|
|
|
1149
1144
|
|
|
1150
|
-
$parcel$exportWildcard(module.exports, $83fe1a57d631223b$exports);
|
|
1151
1145
|
$parcel$exportWildcard(module.exports, $af2d7ac9990cfee2$exports);
|
|
1152
1146
|
$parcel$exportWildcard(module.exports, $5386a492cfd3234c$exports);
|
|
1153
1147
|
$parcel$exportWildcard(module.exports, $9d7d8736d45f74b8$exports);
|