@@ -11,18 +11,37 @@ import { cubicOut } from '../easing/index.js';
11
11
* @returns {AnimationConfig }
12
12
*/
13
13
export function flip ( node , { from, to } , params = { } ) {
14
+ var { delay = 0 , duration = ( d ) => Math . sqrt ( d ) * 120 , easing = cubicOut } = params ;
15
+
14
16
var style = getComputedStyle ( node ) ;
15
- var zoom = get_zoom ( node ) ; // https://drafts.csswg.org/css-viewport/#effective-zoom
16
17
18
+ // find the transform origin, expressed as a pair of values between 0 and 1
17
19
var transform = style . transform === 'none' ? '' : style . transform ;
18
20
var [ ox , oy ] = style . transformOrigin . split ( ' ' ) . map ( parseFloat ) ;
21
+ ox /= node . clientWidth ;
22
+ oy /= node . clientHeight ;
23
+
24
+ // calculate effect of parent transforms and zoom
25
+ var zoom = get_zoom ( node ) ; // https://drafts.csswg.org/css-viewport/#effective-zoom
26
+ var sx = node . clientWidth / to . width / zoom ;
27
+ var sy = node . clientHeight / to . height / zoom ;
28
+
29
+ // find the starting position of the transform origin
30
+ var fx = from . left + from . width * ox ;
31
+ var fy = from . top + from . height * oy ;
32
+
33
+ // find the ending position of the transform origin
34
+ var tx = to . left + to . width * ox ;
35
+ var ty = to . top + to . height * oy ;
36
+
37
+ // find the translation at the start of the transform
38
+ var dx = ( fx - tx ) * sx ;
39
+ var dy = ( fy - ty ) * sy ;
40
+
41
+ // find the relative scale at the start of the transform
19
42
var dsx = from . width / to . width ;
20
43
var dsy = from . height / to . height ;
21
44
22
- var dx = ( from . left + dsx * ox - ( to . left + ox ) ) / zoom ;
23
- var dy = ( from . top + dsy * oy - ( to . top + oy ) ) / zoom ;
24
- var { delay = 0 , duration = ( d ) => Math . sqrt ( d ) * 120 , easing = cubicOut } = params ;
25
-
26
45
return {
27
46
delay,
28
47
duration : typeof duration === 'function' ? duration ( Math . sqrt ( dx * dx + dy * dy ) ) : duration ,
@@ -32,7 +51,8 @@ export function flip(node, { from, to }, params = {}) {
32
51
var y = u * dy ;
33
52
var sx = t + u * dsx ;
34
53
var sy = t + u * dsy ;
35
- return `transform: ${ transform } scale(${ sx } , ${ sy } ) translate(${ x } px, ${ y } px);` ;
54
+
55
+ return `transform: ${ transform } translate(${ x } px, ${ y } px) scale(${ sx } , ${ sy } );` ;
36
56
}
37
57
} ;
38
58
}
0 commit comments