@react-stately/color 3.0.0-beta.8 → 3.0.0-beta.9
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 +51 -55
- package/dist/main.js.map +1 -1
- package/dist/module.js +51 -55
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/Color.ts +25 -1
- package/src/useColorAreaState.ts +4 -37
- package/src/useColorWheelState.ts +1 -1
package/dist/module.js
CHANGED
|
@@ -217,6 +217,20 @@ class $799cddbef784668f$var$Color {
|
|
|
217
217
|
getChannelName(channel, locale) {
|
|
218
218
|
return $799cddbef784668f$var$messages.getStringForLocale(channel, locale);
|
|
219
219
|
}
|
|
220
|
+
getColorSpaceAxes(xyChannels) {
|
|
221
|
+
let { xChannel: xChannel , yChannel: yChannel } = xyChannels;
|
|
222
|
+
let xCh = xChannel || this.getColorChannels().find((c)=>c !== yChannel
|
|
223
|
+
);
|
|
224
|
+
let yCh = yChannel || this.getColorChannels().find((c)=>c !== xCh
|
|
225
|
+
);
|
|
226
|
+
let zCh = this.getColorChannels().find((c)=>c !== xCh && c !== yCh
|
|
227
|
+
);
|
|
228
|
+
return {
|
|
229
|
+
xChannel: xCh,
|
|
230
|
+
yChannel: yCh,
|
|
231
|
+
zChannel: zCh
|
|
232
|
+
};
|
|
233
|
+
}
|
|
220
234
|
}
|
|
221
235
|
const $799cddbef784668f$var$HEX_REGEX = /^#(?:([0-9a-f]{3})|([0-9a-f]{6}))$/i;
|
|
222
236
|
// X = <negative/positive number with/without decimal places>
|
|
@@ -392,6 +406,9 @@ class $799cddbef784668f$var$RGBColor extends $799cddbef784668f$var$Color {
|
|
|
392
406
|
getColorSpace() {
|
|
393
407
|
return 'rgb';
|
|
394
408
|
}
|
|
409
|
+
getColorChannels() {
|
|
410
|
+
return $799cddbef784668f$var$RGBColor.colorChannels;
|
|
411
|
+
}
|
|
395
412
|
constructor(red, green, blue, alpha){
|
|
396
413
|
super();
|
|
397
414
|
this.red = red;
|
|
@@ -400,6 +417,11 @@ class $799cddbef784668f$var$RGBColor extends $799cddbef784668f$var$Color {
|
|
|
400
417
|
this.alpha = alpha;
|
|
401
418
|
}
|
|
402
419
|
}
|
|
420
|
+
$799cddbef784668f$var$RGBColor.colorChannels = [
|
|
421
|
+
'red',
|
|
422
|
+
'green',
|
|
423
|
+
'blue'
|
|
424
|
+
];
|
|
403
425
|
// X = <negative/positive number with/without decimal places>
|
|
404
426
|
// before/after a comma, 0 or more whitespaces are allowed
|
|
405
427
|
// - hsb(X, X%, X%)
|
|
@@ -531,6 +553,9 @@ class $799cddbef784668f$var$HSBColor extends $799cddbef784668f$var$Color {
|
|
|
531
553
|
getColorSpace() {
|
|
532
554
|
return 'hsb';
|
|
533
555
|
}
|
|
556
|
+
getColorChannels() {
|
|
557
|
+
return $799cddbef784668f$var$HSBColor.colorChannels;
|
|
558
|
+
}
|
|
534
559
|
constructor(hue, saturation, brightness, alpha){
|
|
535
560
|
super();
|
|
536
561
|
this.hue = hue;
|
|
@@ -539,6 +564,11 @@ class $799cddbef784668f$var$HSBColor extends $799cddbef784668f$var$Color {
|
|
|
539
564
|
this.alpha = alpha;
|
|
540
565
|
}
|
|
541
566
|
}
|
|
567
|
+
$799cddbef784668f$var$HSBColor.colorChannels = [
|
|
568
|
+
'hue',
|
|
569
|
+
'saturation',
|
|
570
|
+
'brightness'
|
|
571
|
+
];
|
|
542
572
|
// X = <negative/positive number with/without decimal places>
|
|
543
573
|
// before/after a comma, 0 or more whitespaces are allowed
|
|
544
574
|
// - hsl(X, X%, X%)
|
|
@@ -673,6 +703,9 @@ class $799cddbef784668f$var$HSLColor extends $799cddbef784668f$var$Color {
|
|
|
673
703
|
getColorSpace() {
|
|
674
704
|
return 'hsl';
|
|
675
705
|
}
|
|
706
|
+
getColorChannels() {
|
|
707
|
+
return $799cddbef784668f$var$HSLColor.colorChannels;
|
|
708
|
+
}
|
|
676
709
|
constructor(hue, saturation, lightness, alpha){
|
|
677
710
|
super();
|
|
678
711
|
this.hue = hue;
|
|
@@ -681,6 +714,11 @@ class $799cddbef784668f$var$HSLColor extends $799cddbef784668f$var$Color {
|
|
|
681
714
|
this.alpha = alpha;
|
|
682
715
|
}
|
|
683
716
|
}
|
|
717
|
+
$799cddbef784668f$var$HSLColor.colorChannels = [
|
|
718
|
+
'hue',
|
|
719
|
+
'saturation',
|
|
720
|
+
'lightness'
|
|
721
|
+
];
|
|
684
722
|
|
|
685
723
|
|
|
686
724
|
var $6e14a98a7f67141d$exports = {};
|
|
@@ -690,64 +728,24 @@ $parcel$export($6e14a98a7f67141d$exports, "useColorAreaState", () => $6e14a98a7f
|
|
|
690
728
|
|
|
691
729
|
|
|
692
730
|
const $6e14a98a7f67141d$var$DEFAULT_COLOR = $799cddbef784668f$export$6e865ea70d7724f('#ffffff');
|
|
693
|
-
const $6e14a98a7f67141d$var$RGBSet = new Set([
|
|
694
|
-
'red',
|
|
695
|
-
'green',
|
|
696
|
-
'blue'
|
|
697
|
-
]);
|
|
698
|
-
let $6e14a98a7f67141d$var$difference = (a, b)=>new Set([
|
|
699
|
-
...a
|
|
700
|
-
].filter((x)=>!b.has(x)
|
|
701
|
-
))
|
|
702
|
-
;
|
|
703
731
|
function $6e14a98a7f67141d$export$6df7f0e2cabc7eef(props) {
|
|
704
732
|
let { value: value1 , defaultValue: defaultValue , xChannel: xChannel , yChannel: yChannel , onChange: onChange , onChangeEnd: onChangeEnd } = props;
|
|
705
733
|
if (!value1 && !defaultValue) defaultValue = $6e14a98a7f67141d$var$DEFAULT_COLOR;
|
|
706
734
|
let [color, setColor] = $cBgAy$useControlledState(value1 && $799cddbef784668f$export$4cde5df63f53f473(value1), defaultValue && $799cddbef784668f$export$4cde5df63f53f473(defaultValue), onChange);
|
|
707
735
|
let valueRef = $cBgAy$useRef(color);
|
|
708
736
|
valueRef.current = color;
|
|
709
|
-
let channels = $cBgAy$useMemo(()=>{
|
|
710
|
-
if (!xChannel) switch(yChannel){
|
|
711
|
-
case 'red':
|
|
712
|
-
case 'green':
|
|
713
|
-
xChannel = 'blue';
|
|
714
|
-
break;
|
|
715
|
-
case 'blue':
|
|
716
|
-
xChannel = 'red';
|
|
717
|
-
break;
|
|
718
|
-
default:
|
|
719
|
-
xChannel = 'blue';
|
|
720
|
-
yChannel = 'green';
|
|
721
|
-
}
|
|
722
|
-
else if (!yChannel) switch(xChannel){
|
|
723
|
-
case 'red':
|
|
724
|
-
yChannel = 'green';
|
|
725
|
-
break;
|
|
726
|
-
case 'blue':
|
|
727
|
-
yChannel = 'red';
|
|
728
|
-
break;
|
|
729
|
-
default:
|
|
730
|
-
xChannel = 'blue';
|
|
731
|
-
yChannel = 'green';
|
|
732
|
-
}
|
|
733
|
-
let xyChannels = new Set([
|
|
734
|
-
xChannel,
|
|
735
|
-
yChannel
|
|
736
|
-
]);
|
|
737
|
-
let zChannel = $6e14a98a7f67141d$var$difference($6e14a98a7f67141d$var$RGBSet, xyChannels).values().next().value;
|
|
738
|
-
return {
|
|
737
|
+
let channels = $cBgAy$useMemo(()=>valueRef.current.getColorSpaceAxes({
|
|
739
738
|
xChannel: xChannel,
|
|
740
|
-
yChannel: yChannel
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
}, [
|
|
739
|
+
yChannel: yChannel
|
|
740
|
+
})
|
|
741
|
+
, [
|
|
744
742
|
xChannel,
|
|
745
743
|
yChannel
|
|
746
744
|
]);
|
|
747
745
|
let xChannelRange = color.getChannelRange(channels.xChannel);
|
|
748
746
|
let yChannelRange = color.getChannelRange(channels.yChannel);
|
|
749
|
-
let { minValue:
|
|
750
|
-
let { minValue:
|
|
747
|
+
let { minValue: minValueX , maxValue: maxValueX , step: stepX , pageSize: pageSizeX } = xChannelRange;
|
|
748
|
+
let { minValue: minValueY , maxValue: maxValueY , step: stepY , pageSize: pageSizeY } = yChannelRange;
|
|
751
749
|
let [isDragging1, setDragging] = $cBgAy$useState(false);
|
|
752
750
|
let isDraggingRef = $cBgAy$useRef(false).current;
|
|
753
751
|
let xValue = color.getChannelValue(channels.xChannel);
|
|
@@ -779,8 +777,6 @@ function $6e14a98a7f67141d$export$6df7f0e2cabc7eef(props) {
|
|
|
779
777
|
yValue: yValue,
|
|
780
778
|
setYValue: setYValue,
|
|
781
779
|
setColorFromPoint (x, y) {
|
|
782
|
-
let { minValue: minValueX , maxValue: maxValueX } = color.getChannelRange(channels.xChannel);
|
|
783
|
-
let { minValue: minValueY , maxValue: maxValueY } = color.getChannelRange(channels.yChannel);
|
|
784
780
|
let newXValue = minValueX + $cBgAy$clamp(x, 0, 1) * (maxValueX - minValueX);
|
|
785
781
|
let newYValue = minValueY + (1 - $cBgAy$clamp(y, 0, 1)) * (maxValueY - minValueY);
|
|
786
782
|
let newColor;
|
|
@@ -797,24 +793,24 @@ function $6e14a98a7f67141d$export$6df7f0e2cabc7eef(props) {
|
|
|
797
793
|
if (newColor) setColor(newColor);
|
|
798
794
|
},
|
|
799
795
|
getThumbPosition () {
|
|
800
|
-
let x = (xValue -
|
|
801
|
-
let y = 1 - (yValue -
|
|
796
|
+
let x = (xValue - minValueX) / (maxValueX - minValueX);
|
|
797
|
+
let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);
|
|
802
798
|
return {
|
|
803
799
|
x: x,
|
|
804
800
|
y: y
|
|
805
801
|
};
|
|
806
802
|
},
|
|
807
803
|
incrementX (stepSize) {
|
|
808
|
-
setXValue(xValue + stepSize >
|
|
804
|
+
setXValue(xValue + stepSize > maxValueX ? maxValueX : $cBgAy$snapValueToStep(xValue + stepSize, minValueX, maxValueX, stepX));
|
|
809
805
|
},
|
|
810
806
|
incrementY (stepSize) {
|
|
811
|
-
setYValue(yValue + stepSize >
|
|
807
|
+
setYValue(yValue + stepSize > maxValueY ? maxValueY : $cBgAy$snapValueToStep(yValue + stepSize, minValueY, maxValueY, stepY));
|
|
812
808
|
},
|
|
813
809
|
decrementX (stepSize) {
|
|
814
|
-
setXValue($cBgAy$snapValueToStep(xValue - stepSize,
|
|
810
|
+
setXValue($cBgAy$snapValueToStep(xValue - stepSize, minValueX, maxValueX, stepX));
|
|
815
811
|
},
|
|
816
812
|
decrementY (stepSize) {
|
|
817
|
-
setYValue($cBgAy$snapValueToStep(yValue - stepSize,
|
|
813
|
+
setYValue($cBgAy$snapValueToStep(yValue - stepSize, minValueY, maxValueY, stepY));
|
|
818
814
|
},
|
|
819
815
|
setDragging (isDragging) {
|
|
820
816
|
let wasDragging = isDraggingRef;
|
|
@@ -987,7 +983,7 @@ function $ee4262c74a467b07$export$f4301076d9336137(props) {
|
|
|
987
983
|
},
|
|
988
984
|
isDragging: isDragging1,
|
|
989
985
|
getDisplayColor () {
|
|
990
|
-
return value.withChannelValue('saturation', 100).withChannelValue('lightness', 50);
|
|
986
|
+
return value.toFormat('hsl').withChannelValue('saturation', 100).withChannelValue('lightness', 50);
|
|
991
987
|
}
|
|
992
988
|
};
|
|
993
989
|
}
|