@react-stately/color 3.0.0-nightly.3120 → 3.0.0-nightly.3124
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 +189 -25
- package/dist/main.js.map +1 -1
- package/dist/module.js +189 -26
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +56 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -8
- package/src/Color.ts +16 -8
- package/src/index.ts +1 -0
- package/src/useColorAreaState.ts +223 -0
- package/src/useColorSliderState.ts +1 -9
- package/src/useColorWheelState.ts +14 -16
package/dist/main.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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$
|
|
4
|
+
var $4tN2K$reactariautils = require("@react-aria/utils");
|
|
5
5
|
var $4tN2K$react = require("react");
|
|
6
|
+
var $4tN2K$reactstatelyslider = require("@react-stately/slider");
|
|
6
7
|
|
|
7
8
|
function $parcel$exportWildcard(dest, source) {
|
|
8
9
|
Object.keys(source).forEach(function(key) {
|
|
@@ -29,6 +30,7 @@ function $parcel$export(e, n, v, s) {
|
|
|
29
30
|
var $83fe1a57d631223b$exports = {};
|
|
30
31
|
|
|
31
32
|
$parcel$export($83fe1a57d631223b$exports, "parseColor", () => $83fe1a57d631223b$export$6e865ea70d7724f);
|
|
33
|
+
$parcel$export($83fe1a57d631223b$exports, "normalizeColor", () => $83fe1a57d631223b$export$4cde5df63f53f473);
|
|
32
34
|
|
|
33
35
|
var $c0b600cf8eafdee9$exports = {};
|
|
34
36
|
var $b044e7150534af04$exports = {};
|
|
@@ -213,6 +215,10 @@ function $83fe1a57d631223b$export$6e865ea70d7724f(value) {
|
|
|
213
215
|
if (res) return res;
|
|
214
216
|
throw new Error('Invalid color value: ' + value);
|
|
215
217
|
}
|
|
218
|
+
function $83fe1a57d631223b$export$4cde5df63f53f473(v) {
|
|
219
|
+
if (typeof v === 'string') return $83fe1a57d631223b$export$6e865ea70d7724f(v);
|
|
220
|
+
else return v;
|
|
221
|
+
}
|
|
216
222
|
class $83fe1a57d631223b$var$Color {
|
|
217
223
|
toHexInt() {
|
|
218
224
|
return this.toFormat('rgb').toHexInt();
|
|
@@ -369,13 +375,15 @@ class $83fe1a57d631223b$var$RGBColor extends $83fe1a57d631223b$var$Color {
|
|
|
369
375
|
return {
|
|
370
376
|
minValue: 0,
|
|
371
377
|
maxValue: 255,
|
|
372
|
-
step: 1
|
|
378
|
+
step: 1,
|
|
379
|
+
pageSize: 16
|
|
373
380
|
};
|
|
374
381
|
case 'alpha':
|
|
375
382
|
return {
|
|
376
383
|
minValue: 0,
|
|
377
384
|
maxValue: 1,
|
|
378
|
-
step: 0.01
|
|
385
|
+
step: 0.01,
|
|
386
|
+
pageSize: 0.1
|
|
379
387
|
};
|
|
380
388
|
default:
|
|
381
389
|
throw new Error('Unknown color channel: ' + channel);
|
|
@@ -491,20 +499,23 @@ class $83fe1a57d631223b$var$HSBColor extends $83fe1a57d631223b$var$Color {
|
|
|
491
499
|
return {
|
|
492
500
|
minValue: 0,
|
|
493
501
|
maxValue: 360,
|
|
494
|
-
step: 1
|
|
502
|
+
step: 1,
|
|
503
|
+
pageSize: 15
|
|
495
504
|
};
|
|
496
505
|
case 'saturation':
|
|
497
506
|
case 'brightness':
|
|
498
507
|
return {
|
|
499
508
|
minValue: 0,
|
|
500
509
|
maxValue: 100,
|
|
501
|
-
step: 1
|
|
510
|
+
step: 1,
|
|
511
|
+
pageSize: 10
|
|
502
512
|
};
|
|
503
513
|
case 'alpha':
|
|
504
514
|
return {
|
|
505
515
|
minValue: 0,
|
|
506
516
|
maxValue: 1,
|
|
507
|
-
step: 0.01
|
|
517
|
+
step: 0.01,
|
|
518
|
+
pageSize: 0.1
|
|
508
519
|
};
|
|
509
520
|
default:
|
|
510
521
|
throw new Error('Unknown color channel: ' + channel);
|
|
@@ -630,20 +641,23 @@ class $83fe1a57d631223b$var$HSLColor extends $83fe1a57d631223b$var$Color {
|
|
|
630
641
|
return {
|
|
631
642
|
minValue: 0,
|
|
632
643
|
maxValue: 360,
|
|
633
|
-
step: 1
|
|
644
|
+
step: 1,
|
|
645
|
+
pageSize: 15
|
|
634
646
|
};
|
|
635
647
|
case 'saturation':
|
|
636
648
|
case 'lightness':
|
|
637
649
|
return {
|
|
638
650
|
minValue: 0,
|
|
639
651
|
maxValue: 100,
|
|
640
|
-
step: 1
|
|
652
|
+
step: 1,
|
|
653
|
+
pageSize: 10
|
|
641
654
|
};
|
|
642
655
|
case 'alpha':
|
|
643
656
|
return {
|
|
644
657
|
minValue: 0,
|
|
645
658
|
maxValue: 1,
|
|
646
|
-
step: 0.01
|
|
659
|
+
step: 0.01,
|
|
660
|
+
pageSize: 0.1
|
|
647
661
|
};
|
|
648
662
|
default:
|
|
649
663
|
throw new Error('Unknown color channel: ' + channel);
|
|
@@ -690,20 +704,169 @@ class $83fe1a57d631223b$var$HSLColor extends $83fe1a57d631223b$var$Color {
|
|
|
690
704
|
}
|
|
691
705
|
|
|
692
706
|
|
|
707
|
+
var $af2d7ac9990cfee2$exports = {};
|
|
708
|
+
|
|
709
|
+
$parcel$export($af2d7ac9990cfee2$exports, "useColorAreaState", () => $af2d7ac9990cfee2$export$6df7f0e2cabc7eef);
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
const $af2d7ac9990cfee2$var$DEFAULT_COLOR = $83fe1a57d631223b$export$6e865ea70d7724f('#ffffff');
|
|
715
|
+
const $af2d7ac9990cfee2$var$RGBSet = new Set([
|
|
716
|
+
'red',
|
|
717
|
+
'green',
|
|
718
|
+
'blue'
|
|
719
|
+
]);
|
|
720
|
+
let $af2d7ac9990cfee2$var$difference = (a, b)=>new Set([
|
|
721
|
+
...a
|
|
722
|
+
].filter((x)=>!b.has(x)
|
|
723
|
+
))
|
|
724
|
+
;
|
|
725
|
+
function $af2d7ac9990cfee2$export$6df7f0e2cabc7eef(props) {
|
|
726
|
+
// TODO: docs say the step props should be one, but should it be two different values?
|
|
727
|
+
let { value: value1 , defaultValue: defaultValue , xChannel: xChannel , yChannel: yChannel , onChange: onChange , onChangeEnd: onChangeEnd , xChannelStep: xChannelStep , yChannelStep: yChannelStep } = props;
|
|
728
|
+
if (!value1 && !defaultValue) defaultValue = $af2d7ac9990cfee2$var$DEFAULT_COLOR;
|
|
729
|
+
let [color, setColor] = $4tN2K$reactstatelyutils.useControlledState(value1 && $83fe1a57d631223b$export$4cde5df63f53f473(value1), defaultValue && $83fe1a57d631223b$export$4cde5df63f53f473(defaultValue), onChange);
|
|
730
|
+
let valueRef = $4tN2K$react.useRef(color);
|
|
731
|
+
valueRef.current = color;
|
|
732
|
+
let channels = $4tN2K$react.useMemo(()=>{
|
|
733
|
+
if (!xChannel) switch(yChannel){
|
|
734
|
+
case 'red':
|
|
735
|
+
case 'green':
|
|
736
|
+
xChannel = 'blue';
|
|
737
|
+
break;
|
|
738
|
+
case 'blue':
|
|
739
|
+
xChannel = 'red';
|
|
740
|
+
break;
|
|
741
|
+
default:
|
|
742
|
+
xChannel = 'blue';
|
|
743
|
+
yChannel = 'green';
|
|
744
|
+
}
|
|
745
|
+
else if (!yChannel) switch(xChannel){
|
|
746
|
+
case 'red':
|
|
747
|
+
yChannel = 'green';
|
|
748
|
+
break;
|
|
749
|
+
case 'blue':
|
|
750
|
+
yChannel = 'red';
|
|
751
|
+
break;
|
|
752
|
+
default:
|
|
753
|
+
xChannel = 'blue';
|
|
754
|
+
yChannel = 'green';
|
|
755
|
+
}
|
|
756
|
+
let xyChannels = new Set([
|
|
757
|
+
xChannel,
|
|
758
|
+
yChannel
|
|
759
|
+
]);
|
|
760
|
+
let zChannel = $af2d7ac9990cfee2$var$difference($af2d7ac9990cfee2$var$RGBSet, xyChannels).values().next().value;
|
|
761
|
+
return {
|
|
762
|
+
xChannel: xChannel,
|
|
763
|
+
yChannel: yChannel,
|
|
764
|
+
zChannel: zChannel
|
|
765
|
+
};
|
|
766
|
+
}, [
|
|
767
|
+
xChannel,
|
|
768
|
+
yChannel
|
|
769
|
+
]);
|
|
770
|
+
let xChannelRange = color.getChannelRange(channels.xChannel);
|
|
771
|
+
let yChannelRange = color.getChannelRange(channels.yChannel);
|
|
772
|
+
let { minValue: minValueX1 , maxValue: maxValueX1 , step: stepX , pageSize: pageSizeX } = xChannelRange;
|
|
773
|
+
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
|
+
let [isDragging1, setDragging] = $4tN2K$react.useState(false);
|
|
779
|
+
let isDraggingRef = $4tN2K$react.useRef(false).current;
|
|
780
|
+
let xValue = color.getChannelValue(channels.xChannel);
|
|
781
|
+
let yValue = color.getChannelValue(channels.yChannel);
|
|
782
|
+
let setXValue = (v)=>{
|
|
783
|
+
if (v === xValue) return;
|
|
784
|
+
valueRef.current = color.withChannelValue(channels.xChannel, v);
|
|
785
|
+
setColor(valueRef.current);
|
|
786
|
+
};
|
|
787
|
+
let setYValue = (v)=>{
|
|
788
|
+
if (v === yValue) return;
|
|
789
|
+
valueRef.current = color.withChannelValue(channels.yChannel, v);
|
|
790
|
+
setColor(valueRef.current);
|
|
791
|
+
};
|
|
792
|
+
return {
|
|
793
|
+
channels: channels,
|
|
794
|
+
xChannelStep: xChannelStep,
|
|
795
|
+
yChannelStep: yChannelStep,
|
|
796
|
+
xChannelPageStep: xChannelPageStep,
|
|
797
|
+
yChannelPageStep: yChannelPageStep,
|
|
798
|
+
value: color,
|
|
799
|
+
setValue (value) {
|
|
800
|
+
let c = $83fe1a57d631223b$export$4cde5df63f53f473(value);
|
|
801
|
+
valueRef.current = c;
|
|
802
|
+
setColor(c);
|
|
803
|
+
},
|
|
804
|
+
xValue: xValue,
|
|
805
|
+
setXValue: setXValue,
|
|
806
|
+
yValue: yValue,
|
|
807
|
+
setYValue: setYValue,
|
|
808
|
+
setColorFromPoint (x, y) {
|
|
809
|
+
let { minValue: minValueX , maxValue: maxValueX } = color.getChannelRange(channels.xChannel);
|
|
810
|
+
let { minValue: minValueY , maxValue: maxValueY } = color.getChannelRange(channels.yChannel);
|
|
811
|
+
let newXValue = minValueX + $4tN2K$reactariautils.clamp(x, 0, 1) * (maxValueX - minValueX);
|
|
812
|
+
let newYValue = minValueY + (1 - $4tN2K$reactariautils.clamp(y, 0, 1)) * (maxValueY - minValueY);
|
|
813
|
+
let newColor;
|
|
814
|
+
if (newXValue !== xValue) {
|
|
815
|
+
// Round new value to multiple of step, clamp value between min and max
|
|
816
|
+
newXValue = $4tN2K$reactariautils.snapValueToStep(newXValue, minValueX, maxValueX, xChannelStep);
|
|
817
|
+
newColor = color.withChannelValue(channels.xChannel, newXValue);
|
|
818
|
+
}
|
|
819
|
+
if (newYValue !== yValue) {
|
|
820
|
+
// Round new value to multiple of step, clamp value between min and max
|
|
821
|
+
newYValue = $4tN2K$reactariautils.snapValueToStep(newYValue, minValueY, maxValueY, yChannelStep);
|
|
822
|
+
newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);
|
|
823
|
+
}
|
|
824
|
+
if (newColor) setColor(newColor);
|
|
825
|
+
},
|
|
826
|
+
getThumbPosition () {
|
|
827
|
+
let x = (xValue - minValueX1) / (maxValueX1 - minValueX1);
|
|
828
|
+
let y = 1 - (yValue - minValueY1) / (maxValueY1 - minValueY1);
|
|
829
|
+
return {
|
|
830
|
+
x: x,
|
|
831
|
+
y: y
|
|
832
|
+
};
|
|
833
|
+
},
|
|
834
|
+
incrementX (stepSize) {
|
|
835
|
+
setXValue($4tN2K$reactariautils.snapValueToStep(xValue + stepSize, minValueX1, maxValueX1, stepSize));
|
|
836
|
+
},
|
|
837
|
+
incrementY (stepSize) {
|
|
838
|
+
setYValue($4tN2K$reactariautils.snapValueToStep(yValue + stepSize, minValueY1, maxValueY1, stepSize));
|
|
839
|
+
},
|
|
840
|
+
decrementX (stepSize) {
|
|
841
|
+
setXValue($4tN2K$reactariautils.snapValueToStep(xValue - stepSize, minValueX1, maxValueX1, stepSize));
|
|
842
|
+
},
|
|
843
|
+
decrementY (stepSize) {
|
|
844
|
+
setYValue($4tN2K$reactariautils.snapValueToStep(yValue - stepSize, minValueY1, maxValueY1, stepSize));
|
|
845
|
+
},
|
|
846
|
+
setDragging (isDragging) {
|
|
847
|
+
let wasDragging = isDraggingRef;
|
|
848
|
+
isDraggingRef = isDragging;
|
|
849
|
+
if (onChangeEnd && !isDragging && wasDragging) onChangeEnd(valueRef.current);
|
|
850
|
+
setDragging(isDragging);
|
|
851
|
+
},
|
|
852
|
+
isDragging: isDragging1,
|
|
853
|
+
getDisplayColor () {
|
|
854
|
+
return color.withChannelValue('alpha', 1);
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
|
|
693
860
|
var $5386a492cfd3234c$exports = {};
|
|
694
861
|
|
|
695
862
|
$parcel$export($5386a492cfd3234c$exports, "useColorSliderState", () => $5386a492cfd3234c$export$57bc203e1c9c6d44);
|
|
696
863
|
|
|
697
864
|
|
|
698
865
|
|
|
699
|
-
function $5386a492cfd3234c$var$normalizeColor(v) {
|
|
700
|
-
if (typeof v === 'string') return $83fe1a57d631223b$export$6e865ea70d7724f(v);
|
|
701
|
-
else return v;
|
|
702
|
-
}
|
|
703
866
|
function $5386a492cfd3234c$export$57bc203e1c9c6d44(props) {
|
|
704
867
|
let { channel: channel , value: value1 , defaultValue: defaultValue , onChange: onChange , locale: locale , ...otherProps } = props;
|
|
705
868
|
if (value1 == null && defaultValue == null) throw new Error('useColorSliderState requires a value or defaultValue');
|
|
706
|
-
let [color, setColor] = $4tN2K$reactstatelyutils.useControlledState(value1 && $
|
|
869
|
+
let [color, setColor] = $4tN2K$reactstatelyutils.useControlledState(value1 && $83fe1a57d631223b$export$4cde5df63f53f473(value1), defaultValue && $83fe1a57d631223b$export$4cde5df63f53f473(defaultValue), onChange);
|
|
707
870
|
let sliderState = $4tN2K$reactstatelyslider.useSliderState({
|
|
708
871
|
...color.getChannelRange(channel),
|
|
709
872
|
...otherProps,
|
|
@@ -724,7 +887,7 @@ function $5386a492cfd3234c$export$57bc203e1c9c6d44(props) {
|
|
|
724
887
|
...sliderState,
|
|
725
888
|
value: color,
|
|
726
889
|
setValue (value) {
|
|
727
|
-
setColor($
|
|
890
|
+
setColor($83fe1a57d631223b$export$4cde5df63f53f473(value));
|
|
728
891
|
},
|
|
729
892
|
getDisplayColor () {
|
|
730
893
|
switch(channel){
|
|
@@ -756,10 +919,6 @@ $parcel$export($9d7d8736d45f74b8$exports, "useColorWheelState", () => $9d7d8736d
|
|
|
756
919
|
|
|
757
920
|
|
|
758
921
|
|
|
759
|
-
function $9d7d8736d45f74b8$var$normalizeColor(v) {
|
|
760
|
-
if (typeof v === 'string') return $83fe1a57d631223b$export$6e865ea70d7724f(v);
|
|
761
|
-
else return v;
|
|
762
|
-
}
|
|
763
922
|
const $9d7d8736d45f74b8$var$DEFAULT_COLOR = $83fe1a57d631223b$export$6e865ea70d7724f('hsl(0, 100%, 50%)');
|
|
764
923
|
function $9d7d8736d45f74b8$var$roundToStep(value, step) {
|
|
765
924
|
return Math.round(value / step) * step;
|
|
@@ -792,10 +951,11 @@ function $9d7d8736d45f74b8$var$cartesianToAngle(x, y, radius) {
|
|
|
792
951
|
let deg = $9d7d8736d45f74b8$var$radToDeg(Math.atan2(y / radius, x / radius));
|
|
793
952
|
return (deg + 360) % 360;
|
|
794
953
|
}
|
|
954
|
+
const $9d7d8736d45f74b8$var$PAGE_MIN_STEP_SIZE = 6;
|
|
795
955
|
function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
|
|
796
956
|
let { defaultValue: defaultValue , onChange: onChange , onChangeEnd: onChangeEnd , step: step = 1 } = props;
|
|
797
957
|
if (!props.value && !defaultValue) defaultValue = $9d7d8736d45f74b8$var$DEFAULT_COLOR;
|
|
798
|
-
let [value, setValue] = $4tN2K$reactstatelyutils.useControlledState($
|
|
958
|
+
let [value, setValue] = $4tN2K$reactstatelyutils.useControlledState($83fe1a57d631223b$export$4cde5df63f53f473(props.value), $83fe1a57d631223b$export$4cde5df63f53f473(defaultValue), onChange);
|
|
799
959
|
let valueRef = $4tN2K$react.useRef(value);
|
|
800
960
|
valueRef.current = value;
|
|
801
961
|
let [isDragging1, setDragging] = $4tN2K$react.useState(false);
|
|
@@ -811,10 +971,13 @@ function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
|
|
|
811
971
|
setValue(color);
|
|
812
972
|
}
|
|
813
973
|
}
|
|
974
|
+
let pageStep = $9d7d8736d45f74b8$var$PAGE_MIN_STEP_SIZE;
|
|
814
975
|
return {
|
|
815
976
|
value: value,
|
|
977
|
+
step: step,
|
|
978
|
+
pageStep: pageStep,
|
|
816
979
|
setValue (v) {
|
|
817
|
-
let color = $
|
|
980
|
+
let color = $83fe1a57d631223b$export$4cde5df63f53f473(v);
|
|
818
981
|
valueRef.current = color;
|
|
819
982
|
setValue(color);
|
|
820
983
|
},
|
|
@@ -826,14 +989,14 @@ function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
|
|
|
826
989
|
getThumbPosition (radius) {
|
|
827
990
|
return $9d7d8736d45f74b8$var$angleToCartesian(value.getChannelValue('hue'), radius);
|
|
828
991
|
},
|
|
829
|
-
increment (
|
|
830
|
-
let newValue = hue + Math.max(
|
|
992
|
+
increment (stepSize) {
|
|
993
|
+
let newValue = hue + Math.max(stepSize, step);
|
|
831
994
|
if (newValue > 360) // Make sure you can always get back to 0.
|
|
832
995
|
newValue = 0;
|
|
833
996
|
setHue(newValue);
|
|
834
997
|
},
|
|
835
|
-
decrement (
|
|
836
|
-
let s = Math.max(
|
|
998
|
+
decrement (stepSize) {
|
|
999
|
+
let s = Math.max(stepSize, step);
|
|
837
1000
|
if (hue === 0) // We can't just subtract step because this might be the case:
|
|
838
1001
|
// |(previous step) - 0| < step size
|
|
839
1002
|
setHue($9d7d8736d45f74b8$var$roundDown(360 / s) * s);
|
|
@@ -985,6 +1148,7 @@ function $d59d0c2b2ce1568f$var$addColorValue(color, step) {
|
|
|
985
1148
|
|
|
986
1149
|
|
|
987
1150
|
$parcel$exportWildcard(module.exports, $83fe1a57d631223b$exports);
|
|
1151
|
+
$parcel$exportWildcard(module.exports, $af2d7ac9990cfee2$exports);
|
|
988
1152
|
$parcel$exportWildcard(module.exports, $5386a492cfd3234c$exports);
|
|
989
1153
|
$parcel$exportWildcard(module.exports, $9d7d8736d45f74b8$exports);
|
|
990
1154
|
$parcel$exportWildcard(module.exports, $d59d0c2b2ce1568f$exports);
|