@react-stately/color 3.0.0-nightly.3168 → 3.0.0-nightly.3173
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 +9 -9
- package/src/Color.ts +25 -1
- package/src/useColorAreaState.ts +4 -37
- package/src/useColorWheelState.ts +1 -1
package/dist/main.js
CHANGED
|
@@ -235,6 +235,20 @@ class $83fe1a57d631223b$var$Color {
|
|
|
235
235
|
getChannelName(channel, locale) {
|
|
236
236
|
return $83fe1a57d631223b$var$messages.getStringForLocale(channel, locale);
|
|
237
237
|
}
|
|
238
|
+
getColorSpaceAxes(xyChannels) {
|
|
239
|
+
let { xChannel: xChannel , yChannel: yChannel } = xyChannels;
|
|
240
|
+
let xCh = xChannel || this.getColorChannels().find((c)=>c !== yChannel
|
|
241
|
+
);
|
|
242
|
+
let yCh = yChannel || this.getColorChannels().find((c)=>c !== xCh
|
|
243
|
+
);
|
|
244
|
+
let zCh = this.getColorChannels().find((c)=>c !== xCh && c !== yCh
|
|
245
|
+
);
|
|
246
|
+
return {
|
|
247
|
+
xChannel: xCh,
|
|
248
|
+
yChannel: yCh,
|
|
249
|
+
zChannel: zCh
|
|
250
|
+
};
|
|
251
|
+
}
|
|
238
252
|
}
|
|
239
253
|
const $83fe1a57d631223b$var$HEX_REGEX = /^#(?:([0-9a-f]{3})|([0-9a-f]{6}))$/i;
|
|
240
254
|
// X = <negative/positive number with/without decimal places>
|
|
@@ -410,6 +424,9 @@ class $83fe1a57d631223b$var$RGBColor extends $83fe1a57d631223b$var$Color {
|
|
|
410
424
|
getColorSpace() {
|
|
411
425
|
return 'rgb';
|
|
412
426
|
}
|
|
427
|
+
getColorChannels() {
|
|
428
|
+
return $83fe1a57d631223b$var$RGBColor.colorChannels;
|
|
429
|
+
}
|
|
413
430
|
constructor(red, green, blue, alpha){
|
|
414
431
|
super();
|
|
415
432
|
this.red = red;
|
|
@@ -418,6 +435,11 @@ class $83fe1a57d631223b$var$RGBColor extends $83fe1a57d631223b$var$Color {
|
|
|
418
435
|
this.alpha = alpha;
|
|
419
436
|
}
|
|
420
437
|
}
|
|
438
|
+
$83fe1a57d631223b$var$RGBColor.colorChannels = [
|
|
439
|
+
'red',
|
|
440
|
+
'green',
|
|
441
|
+
'blue'
|
|
442
|
+
];
|
|
421
443
|
// X = <negative/positive number with/without decimal places>
|
|
422
444
|
// before/after a comma, 0 or more whitespaces are allowed
|
|
423
445
|
// - hsb(X, X%, X%)
|
|
@@ -549,6 +571,9 @@ class $83fe1a57d631223b$var$HSBColor extends $83fe1a57d631223b$var$Color {
|
|
|
549
571
|
getColorSpace() {
|
|
550
572
|
return 'hsb';
|
|
551
573
|
}
|
|
574
|
+
getColorChannels() {
|
|
575
|
+
return $83fe1a57d631223b$var$HSBColor.colorChannels;
|
|
576
|
+
}
|
|
552
577
|
constructor(hue, saturation, brightness, alpha){
|
|
553
578
|
super();
|
|
554
579
|
this.hue = hue;
|
|
@@ -557,6 +582,11 @@ class $83fe1a57d631223b$var$HSBColor extends $83fe1a57d631223b$var$Color {
|
|
|
557
582
|
this.alpha = alpha;
|
|
558
583
|
}
|
|
559
584
|
}
|
|
585
|
+
$83fe1a57d631223b$var$HSBColor.colorChannels = [
|
|
586
|
+
'hue',
|
|
587
|
+
'saturation',
|
|
588
|
+
'brightness'
|
|
589
|
+
];
|
|
560
590
|
// X = <negative/positive number with/without decimal places>
|
|
561
591
|
// before/after a comma, 0 or more whitespaces are allowed
|
|
562
592
|
// - hsl(X, X%, X%)
|
|
@@ -691,6 +721,9 @@ class $83fe1a57d631223b$var$HSLColor extends $83fe1a57d631223b$var$Color {
|
|
|
691
721
|
getColorSpace() {
|
|
692
722
|
return 'hsl';
|
|
693
723
|
}
|
|
724
|
+
getColorChannels() {
|
|
725
|
+
return $83fe1a57d631223b$var$HSLColor.colorChannels;
|
|
726
|
+
}
|
|
694
727
|
constructor(hue, saturation, lightness, alpha){
|
|
695
728
|
super();
|
|
696
729
|
this.hue = hue;
|
|
@@ -699,6 +732,11 @@ class $83fe1a57d631223b$var$HSLColor extends $83fe1a57d631223b$var$Color {
|
|
|
699
732
|
this.alpha = alpha;
|
|
700
733
|
}
|
|
701
734
|
}
|
|
735
|
+
$83fe1a57d631223b$var$HSLColor.colorChannels = [
|
|
736
|
+
'hue',
|
|
737
|
+
'saturation',
|
|
738
|
+
'lightness'
|
|
739
|
+
];
|
|
702
740
|
|
|
703
741
|
|
|
704
742
|
var $af2d7ac9990cfee2$exports = {};
|
|
@@ -708,64 +746,24 @@ $parcel$export($af2d7ac9990cfee2$exports, "useColorAreaState", () => $af2d7ac999
|
|
|
708
746
|
|
|
709
747
|
|
|
710
748
|
const $af2d7ac9990cfee2$var$DEFAULT_COLOR = $83fe1a57d631223b$export$6e865ea70d7724f('#ffffff');
|
|
711
|
-
const $af2d7ac9990cfee2$var$RGBSet = new Set([
|
|
712
|
-
'red',
|
|
713
|
-
'green',
|
|
714
|
-
'blue'
|
|
715
|
-
]);
|
|
716
|
-
let $af2d7ac9990cfee2$var$difference = (a, b)=>new Set([
|
|
717
|
-
...a
|
|
718
|
-
].filter((x)=>!b.has(x)
|
|
719
|
-
))
|
|
720
|
-
;
|
|
721
749
|
function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
|
|
722
750
|
let { value: value1 , defaultValue: defaultValue , xChannel: xChannel , yChannel: yChannel , onChange: onChange , onChangeEnd: onChangeEnd } = props;
|
|
723
751
|
if (!value1 && !defaultValue) defaultValue = $af2d7ac9990cfee2$var$DEFAULT_COLOR;
|
|
724
752
|
let [color, setColor] = $4tN2K$reactstatelyutils.useControlledState(value1 && $83fe1a57d631223b$export$4cde5df63f53f473(value1), defaultValue && $83fe1a57d631223b$export$4cde5df63f53f473(defaultValue), onChange);
|
|
725
753
|
let valueRef = $4tN2K$react.useRef(color);
|
|
726
754
|
valueRef.current = color;
|
|
727
|
-
let channels = $4tN2K$react.useMemo(()=>{
|
|
728
|
-
if (!xChannel) switch(yChannel){
|
|
729
|
-
case 'red':
|
|
730
|
-
case 'green':
|
|
731
|
-
xChannel = 'blue';
|
|
732
|
-
break;
|
|
733
|
-
case 'blue':
|
|
734
|
-
xChannel = 'red';
|
|
735
|
-
break;
|
|
736
|
-
default:
|
|
737
|
-
xChannel = 'blue';
|
|
738
|
-
yChannel = 'green';
|
|
739
|
-
}
|
|
740
|
-
else if (!yChannel) switch(xChannel){
|
|
741
|
-
case 'red':
|
|
742
|
-
yChannel = 'green';
|
|
743
|
-
break;
|
|
744
|
-
case 'blue':
|
|
745
|
-
yChannel = 'red';
|
|
746
|
-
break;
|
|
747
|
-
default:
|
|
748
|
-
xChannel = 'blue';
|
|
749
|
-
yChannel = 'green';
|
|
750
|
-
}
|
|
751
|
-
let xyChannels = new Set([
|
|
752
|
-
xChannel,
|
|
753
|
-
yChannel
|
|
754
|
-
]);
|
|
755
|
-
let zChannel = $af2d7ac9990cfee2$var$difference($af2d7ac9990cfee2$var$RGBSet, xyChannels).values().next().value;
|
|
756
|
-
return {
|
|
755
|
+
let channels = $4tN2K$react.useMemo(()=>valueRef.current.getColorSpaceAxes({
|
|
757
756
|
xChannel: xChannel,
|
|
758
|
-
yChannel: yChannel
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
}, [
|
|
757
|
+
yChannel: yChannel
|
|
758
|
+
})
|
|
759
|
+
, [
|
|
762
760
|
xChannel,
|
|
763
761
|
yChannel
|
|
764
762
|
]);
|
|
765
763
|
let xChannelRange = color.getChannelRange(channels.xChannel);
|
|
766
764
|
let yChannelRange = color.getChannelRange(channels.yChannel);
|
|
767
|
-
let { minValue:
|
|
768
|
-
let { minValue:
|
|
765
|
+
let { minValue: minValueX , maxValue: maxValueX , step: stepX , pageSize: pageSizeX } = xChannelRange;
|
|
766
|
+
let { minValue: minValueY , maxValue: maxValueY , step: stepY , pageSize: pageSizeY } = yChannelRange;
|
|
769
767
|
let [isDragging1, setDragging] = $4tN2K$react.useState(false);
|
|
770
768
|
let isDraggingRef = $4tN2K$react.useRef(false).current;
|
|
771
769
|
let xValue = color.getChannelValue(channels.xChannel);
|
|
@@ -797,8 +795,6 @@ function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
|
|
|
797
795
|
yValue: yValue,
|
|
798
796
|
setYValue: setYValue,
|
|
799
797
|
setColorFromPoint (x, y) {
|
|
800
|
-
let { minValue: minValueX , maxValue: maxValueX } = color.getChannelRange(channels.xChannel);
|
|
801
|
-
let { minValue: minValueY , maxValue: maxValueY } = color.getChannelRange(channels.yChannel);
|
|
802
798
|
let newXValue = minValueX + $4tN2K$reactstatelyutils.clamp(x, 0, 1) * (maxValueX - minValueX);
|
|
803
799
|
let newYValue = minValueY + (1 - $4tN2K$reactstatelyutils.clamp(y, 0, 1)) * (maxValueY - minValueY);
|
|
804
800
|
let newColor;
|
|
@@ -815,24 +811,24 @@ function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
|
|
|
815
811
|
if (newColor) setColor(newColor);
|
|
816
812
|
},
|
|
817
813
|
getThumbPosition () {
|
|
818
|
-
let x = (xValue -
|
|
819
|
-
let y = 1 - (yValue -
|
|
814
|
+
let x = (xValue - minValueX) / (maxValueX - minValueX);
|
|
815
|
+
let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);
|
|
820
816
|
return {
|
|
821
817
|
x: x,
|
|
822
818
|
y: y
|
|
823
819
|
};
|
|
824
820
|
},
|
|
825
821
|
incrementX (stepSize) {
|
|
826
|
-
setXValue(xValue + stepSize >
|
|
822
|
+
setXValue(xValue + stepSize > maxValueX ? maxValueX : $4tN2K$reactstatelyutils.snapValueToStep(xValue + stepSize, minValueX, maxValueX, stepX));
|
|
827
823
|
},
|
|
828
824
|
incrementY (stepSize) {
|
|
829
|
-
setYValue(yValue + stepSize >
|
|
825
|
+
setYValue(yValue + stepSize > maxValueY ? maxValueY : $4tN2K$reactstatelyutils.snapValueToStep(yValue + stepSize, minValueY, maxValueY, stepY));
|
|
830
826
|
},
|
|
831
827
|
decrementX (stepSize) {
|
|
832
|
-
setXValue($4tN2K$reactstatelyutils.snapValueToStep(xValue - stepSize,
|
|
828
|
+
setXValue($4tN2K$reactstatelyutils.snapValueToStep(xValue - stepSize, minValueX, maxValueX, stepX));
|
|
833
829
|
},
|
|
834
830
|
decrementY (stepSize) {
|
|
835
|
-
setYValue($4tN2K$reactstatelyutils.snapValueToStep(yValue - stepSize,
|
|
831
|
+
setYValue($4tN2K$reactstatelyutils.snapValueToStep(yValue - stepSize, minValueY, maxValueY, stepY));
|
|
836
832
|
},
|
|
837
833
|
setDragging (isDragging) {
|
|
838
834
|
let wasDragging = isDraggingRef;
|
|
@@ -1005,7 +1001,7 @@ function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
|
|
|
1005
1001
|
},
|
|
1006
1002
|
isDragging: isDragging1,
|
|
1007
1003
|
getDisplayColor () {
|
|
1008
|
-
return value.withChannelValue('saturation', 100).withChannelValue('lightness', 50);
|
|
1004
|
+
return value.toFormat('hsl').withChannelValue('saturation', 100).withChannelValue('lightness', 50);
|
|
1009
1005
|
}
|
|
1010
1006
|
};
|
|
1011
1007
|
}
|