11import normalizeColor from 'normalize-css-color'
22
33var linear = t => t
4+
45/**
56 * Very handy helper to map input ranges to output ranges with an easing
67 * function and custom behavior outside of the ranges.
78 */
8-
99class Interpolation {
1010 static create ( config ) {
1111 if ( config . outputRange && typeof config . outputRange [ 0 ] === 'string' ) {
@@ -47,8 +47,9 @@ class Interpolation {
4747}
4848
4949function interpolate ( input , inputMin , inputMax , outputMin , outputMax , easing , extrapolateLeft , extrapolateRight ) {
50- var result = input // Extrapolate
51-
50+ var result = input
51+
52+ // Extrapolate
5253 if ( result < inputMin ) {
5354 if ( extrapolateLeft === 'identity' ) {
5455 return result
@@ -77,7 +78,6 @@ function interpolate(input, inputMin, inputMax, outputMin, outputMax, easing, ex
7778 if ( input <= inputMin ) {
7879 return outputMin
7980 }
80-
8181 return outputMax
8282 } // Input Range
8383
@@ -105,9 +105,7 @@ function interpolate(input, inputMin, inputMax, outputMin, outputMax, easing, ex
105105function colorToRgba ( input ) {
106106 var int32Color = normalizeColor ( input )
107107
108- if ( int32Color === null ) {
109- return input
110- }
108+ if ( int32Color === null ) return input
111109
112110 int32Color = int32Color || 0 // $FlowIssue
113111
@@ -119,6 +117,7 @@ function colorToRgba(input) {
119117}
120118
121119var stringShapeRegex = / [ 0 - 9 \. - ] + / g
120+
122121/**
123122 * Supports string shapes by extracting numbers so new values can be computed,
124123 * and recombines those values into new strings of the same shape. Supports
@@ -127,10 +126,10 @@ var stringShapeRegex = /[0-9\.-]+/g
127126 * rgba(123, 42, 99, 0.36) // colors
128127 * -45deg // values with units
129128 */
130-
131129function createInterpolationFromStringOutputRange ( config ) {
132130 var outputRange = config . outputRange
133131 outputRange = outputRange . map ( colorToRgba )
132+
134133 // ->
135134 // [
136135 // [0, 50],
@@ -142,7 +141,6 @@ function createInterpolationFromStringOutputRange(config) {
142141 /* $FlowFixMe(>=0.18.0): `outputRange[0].match()` can return `null`. Need to
143142 * guard against this possibility.
144143 */
145-
146144 var outputRanges = outputRange [ 0 ] . match ( stringShapeRegex ) . map ( ( ) => [ ] )
147145 outputRange . forEach ( value => {
148146 /* $FlowFixMe(>=0.18.0): `value.match()` can return `null`. Need to guard
@@ -152,18 +150,16 @@ function createInterpolationFromStringOutputRange(config) {
152150 outputRanges [ i ] . push ( + number )
153151 } )
154152 } )
155- /* $FlowFixMe(>=0.18.0): `outputRange[0].match()` can return `null`. Need to
156- * guard against this possibility.
157- */
158153
154+ /* $FlowFixMe(>=0.18.0): `outputRange[0].match()` can return `null`. Need to
155+ * guard against this possibility.
156+ */
159157 var interpolations = outputRange [ 0 ] . match ( stringShapeRegex ) . map ( ( value , i ) => {
160- return Interpolation . create ( {
161- ...config ,
162- outputRange : outputRanges [ i ] ,
163- } )
164- } ) // rgba requires that the r,g,b are integers.... so we want to round them, but we *dont* want to
165- // round the opacity (4th column).
158+ return Interpolation . create ( { ...config , outputRange : outputRanges [ i ] } )
159+ } )
166160
161+ // rgba requires that the r,g,b are integers.... so we want to round them, but we *dont* want to
162+ // round the opacity (4th column).
167163 const shouldRound = / ^ r g b / . test ( outputRange [ 0 ] )
168164 return input => {
169165 var i = 0 // 'rgba(0, 100, 200, 0)'
@@ -177,9 +173,7 @@ function createInterpolationFromStringOutputRange(config) {
177173}
178174
179175function findRange ( input , inputRange ) {
180- for ( var i = 1 ; i < inputRange . length - 1 ; ++ i ) {
181- if ( inputRange [ i ] >= input ) break
182- }
176+ for ( var i = 1 ; i < inputRange . length - 1 ; ++ i ) if ( inputRange [ i ] >= input ) break
183177 return i - 1
184178}
185179
0 commit comments