1- define ( [ 'react' ] , function ( React ) {
2- function interpolate ( a , b , t ) {
3- if ( Array . isArray ( b ) ) {
4- return b . map ( function ( x , i ) {
5- return interpolate ( a [ i ] , x , t ) ;
6- } ) ;
7- }
8- if ( typeof b === 'object' ) {
9- var res = { } , k ;
10- for ( var k in b ) {
11- // No need to check hasOwnProperty,
12- // we are working with object literals
13- res [ k ] = interpolate ( a [ k ] , b [ k ] , t ) ;
14- }
15- return res ;
16- }
17- if ( typeof b === 'number' ) {
18- return a + ( b - a ) * t ;
19- }
20- return a ;
21- }
1+ var react = require ( 'React' ) ;
222
23- function copy ( obj ) {
3+ function interpolate ( a , b , t ) {
4+ if ( Array . isArray ( b ) ) {
5+ return b . map ( function ( x , i ) {
6+ return interpolate ( a [ i ] , x , t ) ;
7+ } ) ;
8+ }
9+ if ( typeof b === 'object' ) {
2410 var res = { } , k ;
25- for ( k in obj ) {
26- if ( obj . hasOwnProperty ( k ) ) {
27- res [ k ] = obj [ k ] ;
28- }
11+ for ( var k in b ) {
12+ // No need to check hasOwnProperty,
13+ // we are working with object literals
14+ res [ k ] = interpolate ( a [ k ] , b [ k ] , t ) ;
2915 }
3016 return res ;
3117 }
18+ if ( typeof b === 'number' ) {
19+ return a + ( b - a ) * t ;
20+ }
21+ return a ;
22+ }
23+
24+ function copy ( obj ) {
25+ var res = { } , k ;
26+ for ( k in obj ) {
27+ if ( obj . hasOwnProperty ( k ) ) {
28+ res [ k ] = obj [ k ] ;
29+ }
30+ }
31+ return res ;
32+ }
3233
33- var s = 1.70158 ;
34+ var s = 1.70158 ;
3435
35- var easingTypes = {
36- linear : function ( t ) {
37- return t ;
38- } ,
39- easeInQuad : function ( t ) {
40- return t * t ;
41- } ,
42- easeOutQuad : function ( t ) {
43- return - t * ( t - 2 ) ;
44- } ,
45- easeInOutQuad : function ( t ) {
46- return ( t < 1 / 2 ) ? ( 2 * t * t ) : ( - 2 * t * t + 4 * t - 1 ) ;
47- } ,
48- easeInElastic : function ( t ) {
49- var q = t - 1 ;
50- return - Math . pow ( 2 , 10 * q ) * Math . sin ( ( 2 * q / 0.3 - 0.5 ) * Math . PI ) ;
51- } ,
52- easeOutElastic : function ( t ) {
53- return Math . pow ( 2 , - 10 * t ) * Math . sin ( ( 2 * t / 0.3 - 0.5 ) * Math . PI ) + 1 ;
54- } ,
55- easeInOutElastic : function ( t ) {
56- var q = 2 * t - 1 ;
57- if ( t < 1 / 2 ) return - 0.5 * Math . pow ( 2 , 10 * q ) * Math . sin ( ( q / 0.225 - 0.5 ) * Math . PI ) ;
58- else return Math . pow ( 2 , - 10 * q ) * Math . sin ( ( q / 0.225 - 0.5 ) * Math . PI ) * 0.5 + 1 ;
59- } ,
60- easeInBack : function ( t ) {
61- return t * t * ( ( s + 1 ) * t - s ) ;
62- } ,
63- easeOutBack : function ( t ) {
36+ var easingTypes = {
37+ linear : function ( t ) {
38+ return t ;
39+ } ,
40+ easeInQuad : function ( t ) {
41+ return t * t ;
42+ } ,
43+ easeOutQuad : function ( t ) {
44+ return - t * ( t - 2 ) ;
45+ } ,
46+ easeInOutQuad : function ( t ) {
47+ return ( t < 1 / 2 ) ? ( 2 * t * t ) : ( - 2 * t * t + 4 * t - 1 ) ;
48+ } ,
49+ easeInElastic : function ( t ) {
50+ var q = t - 1 ;
51+ return - Math . pow ( 2 , 10 * q ) * Math . sin ( ( 2 * q / 0.3 - 0.5 ) * Math . PI ) ;
52+ } ,
53+ easeOutElastic : function ( t ) {
54+ return Math . pow ( 2 , - 10 * t ) * Math . sin ( ( 2 * t / 0.3 - 0.5 ) * Math . PI ) + 1 ;
55+ } ,
56+ easeInOutElastic : function ( t ) {
57+ var q = 2 * t - 1 ;
58+ if ( t < 1 / 2 ) return - 0.5 * Math . pow ( 2 , 10 * q ) * Math . sin ( ( q / 0.225 - 0.5 ) * Math . PI ) ;
59+ else return Math . pow ( 2 , - 10 * q ) * Math . sin ( ( q / 0.225 - 0.5 ) * Math . PI ) * 0.5 + 1 ;
60+ } ,
61+ easeInBack : function ( t ) {
62+ return t * t * ( ( s + 1 ) * t - s ) ;
63+ } ,
64+ easeOutBack : function ( t ) {
65+ var q = t - 1 ;
66+ return q * q * ( ( s + 1 ) * q + s ) + 1 ;
67+ } ,
68+ easeInOutBack : function ( t ) {
69+ var r = s * 1.525 ;
70+ if ( t < 1 / 2 ) return 2 * t * t * ( ( r + 1 ) * 2 * t - r )
71+ else {
6472 var q = t - 1 ;
65- return q * q * ( ( s + 1 ) * q + s ) + 1 ;
66- } ,
67- easeInOutBack : function ( t ) {
68- var r = s * 1.525 ;
69- if ( t < 1 / 2 ) return 2 * t * t * ( ( r + 1 ) * 2 * t - r )
70- else {
71- var q = t - 1 ;
72- return 2 * q * q * ( ( r + 1 ) * 2 * q + r ) + 1 ;
73- }
74- } ,
75- easeInBounce : function ( t ) {
76- return 1 - easingTypes . easeOutBounce ( 1 - t ) ;
77- } ,
78- easeOutBounce : function ( t ) {
79- var q = 2.75 * t ;
80- var l = 7.5625 ;
81- if ( q < 1 ) { return l * t * t }
82- else if ( q < 2 ) {
83- var p = t - 1.5 / 2.75 ;
84- return l * p * p + 0.75 ;
85- }
86- else if ( q < 2.5 ) {
87- var p = t - 2.25 / 2.75 ;
88- return l * p * p + 0.9375 ;
89- }
90- else {
91- var p = t - 2.625 / 2.75 ;
92- return l * p * p + 0.984375 ;
93- }
94- } ,
95- easeInOutBounce : function ( t ) {
96- return ( t < 1 / 2 ) ?
97- easingTypes . easeInBounce ( 2 * t ) / 2 :
98- ( easingTypes . easeOutBounce ( 2 * t - 1 ) + 1 ) / 2 ;
73+ return 2 * q * q * ( ( r + 1 ) * 2 * q + r ) + 1 ;
74+ }
75+ } ,
76+ easeInBounce : function ( t ) {
77+ return 1 - easingTypes . easeOutBounce ( 1 - t ) ;
78+ } ,
79+ easeOutBounce : function ( t ) {
80+ var q = 2.75 * t ;
81+ var l = 7.5625 ;
82+ if ( q < 1 ) { return l * t * t }
83+ else if ( q < 2 ) {
84+ var p = t - 1.5 / 2.75 ;
85+ return l * p * p + 0.75 ;
86+ }
87+ else if ( q < 2.5 ) {
88+ var p = t - 2.25 / 2.75 ;
89+ return l * p * p + 0.9375 ;
9990 }
100- } ;
91+ else {
92+ var p = t - 2.625 / 2.75 ;
93+ return l * p * p + 0.984375 ;
94+ }
95+ } ,
96+ easeInOutBounce : function ( t ) {
97+ return ( t < 1 / 2 ) ?
98+ easingTypes . easeInBounce ( 2 * t ) / 2 :
99+ ( easingTypes . easeOutBounce ( 2 * t - 1 ) + 1 ) / 2 ;
100+ }
101+ } ;
101102
102- /*
103- *
104- * TERMS OF USE - EASING EQUATIONS
105- *
106- * Open source under the BSD License.
107- *
108- * Copyright © 2001 Robert Penner
109- * All rights reserved.
110- *
111- * Redistribution and use in source and binary forms, with or without modification,
112- * are permitted provided that the following conditions are met:
113- *
114- * Redistributions of source code must retain the above copyright notice, this list of
115- * conditions and the following disclaimer.
116- * Redistributions in binary form must reproduce the above copyright notice, this list
117- * of conditions and the following disclaimer in the documentation and/or other materials
118- * provided with the distribution.
119- *
120- * Neither the name of the author nor the names of contributors may be used to endorse
121- * or promote products derived from this software without specific prior written permission.
122- *
123- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
124- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
125- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
126- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
127- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
128- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
129- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
130- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
131- * OF THE POSSIBILITY OF SUCH DAMAGE.
132- *
133- */
103+ /*
104+ *
105+ * TERMS OF USE - EASING EQUATIONS
106+ *
107+ * Open source under the BSD License.
108+ *
109+ * Copyright © 2001 Robert Penner
110+ * All rights reserved.
111+ *
112+ * Redistribution and use in source and binary forms, with or without modification,
113+ * are permitted provided that the following conditions are met:
114+ *
115+ * Redistributions of source code must retain the above copyright notice, this list of
116+ * conditions and the following disclaimer.
117+ * Redistributions in binary form must reproduce the above copyright notice, this list
118+ * of conditions and the following disclaimer in the documentation and/or other materials
119+ * provided with the distribution.
120+ *
121+ * Neither the name of the author nor the names of contributors may be used to endorse
122+ * or promote products derived from this software without specific prior written permission.
123+ *
124+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
125+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
126+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
127+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
128+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
129+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
130+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
131+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
132+ * OF THE POSSIBILITY OF SUCH DAMAGE.
133+ *
134+ */
134135
135- return {
136- easing : easingTypes ,
137- Mixin : {
138- animateState : function ( target , options ) {
139- options = options || { } ;
140- var start = Date . now ( ) ;
141- var initialState = copy ( this . state ) ;
142- var duration = options . duration || 500 ;
143- var easing = options . easing || easingTypes . easeInOutQuad ;
144- var self = this ;
136+ module . exports = {
137+ easing : easingTypes ,
138+ Mixin : {
139+ animateState : function ( target , options ) {
140+ options = options || { } ;
141+ var start = Date . now ( ) ;
142+ var initialState = copy ( this . state ) ;
143+ var duration = options . duration || 500 ;
144+ var easing = options . easing || easingTypes . easeInOutQuad ;
145+ var self = this ;
145146
146- function updateState ( ) {
147- var t = Math . min ( Date . now ( ) - start , duration ) / duration ;
148- self . setState ( interpolate ( initialState , target , easing ( t ) ) ) ;
147+ function updateState ( ) {
148+ var t = Math . min ( Date . now ( ) - start , duration ) / duration ;
149+ self . setState ( interpolate ( initialState , target , easing ( t ) ) ) ;
149150
150- if ( t < 1 ) {
151- requestAnimationFrame ( updateState ) ;
152- }
153- else {
154- if ( options . done ) options . done ( ) ;
155- }
151+ if ( t < 1 ) {
152+ requestAnimationFrame ( updateState ) ;
153+ }
154+ else {
155+ if ( options . done ) options . done ( ) ;
156156 }
157-
158- requestAnimationFrame ( updateState ) ;
159157 }
158+
159+ requestAnimationFrame ( updateState ) ;
160160 }
161- } ;
162- } ) ;
161+ }
162+ } ;
0 commit comments