framer-motion 5.1.0 → 5.2.0

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.
@@ -929,6 +929,46 @@
929
929
  return functions ? functions.map(applyDefaultFilter).join(' ') : v;
930
930
  } });
931
931
 
932
+ function hueToRgb(p, q, t) {
933
+ if (t < 0)
934
+ t += 1;
935
+ if (t > 1)
936
+ t -= 1;
937
+ if (t < 1 / 6)
938
+ return p + (q - p) * 6 * t;
939
+ if (t < 1 / 2)
940
+ return q;
941
+ if (t < 2 / 3)
942
+ return p + (q - p) * (2 / 3 - t) * 6;
943
+ return p;
944
+ }
945
+ function hslaToRgba({ hue, saturation, lightness, alpha }) {
946
+ hue /= 360;
947
+ saturation /= 100;
948
+ lightness /= 100;
949
+ let red = 0;
950
+ let green = 0;
951
+ let blue = 0;
952
+ if (!saturation) {
953
+ red = green = blue = lightness;
954
+ }
955
+ else {
956
+ const q = lightness < 0.5
957
+ ? lightness * (1 + saturation)
958
+ : lightness + saturation - lightness * saturation;
959
+ const p = 2 * lightness - q;
960
+ red = hueToRgb(p, q, hue + 1 / 3);
961
+ green = hueToRgb(p, q, hue);
962
+ blue = hueToRgb(p, q, hue - 1 / 3);
963
+ }
964
+ return {
965
+ red: Math.round(red * 255),
966
+ green: Math.round(green * 255),
967
+ blue: Math.round(blue * 255),
968
+ alpha,
969
+ };
970
+ }
971
+
932
972
  const mixLinearColor = (from, to, v) => {
933
973
  const fromExpo = from * from;
934
974
  const toExpo = to * to;
@@ -938,24 +978,25 @@
938
978
  const getColorType = (v) => colorTypes.find((type) => type.test(v));
939
979
  const notAnimatable = (color) => `'${color}' is not an animatable color. Use the equivalent color code instead.`;
940
980
  const mixColor = (from, to) => {
941
- const fromColorType = getColorType(from);
942
- const toColorType = getColorType(to);
981
+ let fromColorType = getColorType(from);
982
+ let toColorType = getColorType(to);
943
983
  invariant(!!fromColorType, notAnimatable(from));
944
984
  invariant(!!toColorType, notAnimatable(to));
945
- invariant(fromColorType.transform === toColorType.transform, "Both colors must be hex/RGBA, OR both must be HSLA.");
946
- if (!fromColorType ||
947
- !toColorType ||
948
- fromColorType.transform !== toColorType.transform) {
949
- return (p) => `${p > 0 ? to : from}`;
950
- }
951
- const fromColor = fromColorType.parse(from);
952
- const toColor = toColorType.parse(to);
985
+ let fromColor = fromColorType.parse(from);
986
+ let toColor = toColorType.parse(to);
987
+ if (fromColorType === hsla) {
988
+ fromColor = hslaToRgba(fromColor);
989
+ fromColorType = rgba;
990
+ }
991
+ if (toColorType === hsla) {
992
+ toColor = hslaToRgba(toColor);
993
+ toColorType = rgba;
994
+ }
953
995
  const blended = Object.assign({}, fromColor);
954
- const mixFunc = fromColorType === hsla ? mix : mixLinearColor;
955
996
  return (v) => {
956
997
  for (const key in blended) {
957
998
  if (key !== "alpha") {
958
- blended[key] = mixFunc(fromColor[key], toColor[key], v);
999
+ blended[key] = mixLinearColor(fromColor[key], toColor[key], v);
959
1000
  }
960
1001
  }
961
1002
  blended.alpha = mix(fromColor.alpha, toColor.alpha, v);