UNPKG

react-native-redash

Version:

Utility library for React Native Reanimated

2 lines 2.14 kB
import Animated from"react-native-reanimated";var cond=Animated.cond,add=Animated.add,multiply=Animated.multiply,lessThan=Animated.lessThan,abs=Animated.abs,modulo=Animated.modulo,round=Animated.round,interpolate=Animated.interpolate,divide=Animated.divide,sub=Animated.sub,color=Animated.color,Extrapolate=Animated.Extrapolate,Node=Animated.Node;function match(condsAndResPairs){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;if(condsAndResPairs.length-offset===1){return condsAndResPairs[offset];}if(condsAndResPairs.length-offset===0){return undefined;}return cond(condsAndResPairs[offset],condsAndResPairs[offset+1],match(condsAndResPairs,offset+2));}function colorHSV(h,s,v){var c=multiply(v,s);var hh=divide(h,60);var x=multiply(c,sub(1,abs(sub(modulo(hh,2),1))));var m=sub(v,c);var colorRGB=function colorRGB(r,g,b){return color(round(multiply(255,add(r,m))),round(multiply(255,add(g,m))),round(multiply(255,add(b,m))));};return match([lessThan(h,60),colorRGB(c,x,0),lessThan(h,120),colorRGB(x,c,0),lessThan(h,180),colorRGB(0,c,x),lessThan(h,240),colorRGB(0,x,c),lessThan(h,300),colorRGB(x,0,c),colorRGB(c,0,x)]);}var rgbToHsv=function rgbToHsv(c){var r=c.r/255;var g=c.g/255;var b=c.b/255;var ma=Math.max(r,g,b);var mi=Math.min(r,g,b);var h=0;var v=ma;var d=ma-mi;var s=ma===0?0:d/ma;if(ma===mi){h=0;}else{switch(ma){case r:h=(g-b)/d+(g<b?6:0);break;case g:h=(b-r)/d+2;break;case b:h=(r-g)/d+4;break;default:}h/=6;}return{h:h*360,s:s,v:v};};var interpolateColors=function interpolateColors(animationValue,inputRange,colors){var colorsAsHSV=colors.map(function(c){return rgbToHsv(c);});var h=interpolate(animationValue,{inputRange:inputRange,outputRange:colorsAsHSV.map(function(c){return c.h;}),extrapolate:Extrapolate.CLAMP});var s=interpolate(animationValue,{inputRange:inputRange,outputRange:colorsAsHSV.map(function(c){return c.s;}),extrapolate:Extrapolate.CLAMP});var v=interpolate(animationValue,{inputRange:inputRange,outputRange:colorsAsHSV.map(function(c){return c.v;}),extrapolate:Extrapolate.CLAMP});return colorHSV(h,s,v);};export default interpolateColors; //# sourceMappingURL=Colors.js.map