@@ -12,22 +12,48 @@ import { cubicOut } from '../easing/index.js';
12
12
* @returns {AnimationConfig }
13
13
*/
14
14
export function flip ( node , { from, to } , params = { } ) {
15
- const style = getComputedStyle ( node ) ;
16
- const transform = style . transform === 'none' ? '' : style . transform ;
17
- const [ ox , oy ] = style . transformOrigin . split ( ' ' ) . map ( parseFloat ) ;
18
- const dx = from . left + ( from . width * ox ) / to . width - ( to . left + ox ) ;
19
- const dy = from . top + ( from . height * oy ) / to . height - ( to . top + oy ) ;
20
- const { delay = 0 , duration = ( d ) => Math . sqrt ( d ) * 120 , easing = cubicOut } = params ;
15
+ var style = getComputedStyle ( node ) ;
16
+ var zoom = get_zoom ( node ) ; // https://drafts.csswg.org/css-viewport/#effective-zoom
17
+
18
+ var transform = style . transform === 'none' ? '' : style . transform ;
19
+ var [ ox , oy ] = style . transformOrigin . split ( ' ' ) . map ( parseFloat ) ;
20
+ var dsx = from . width / to . width ;
21
+ var dsy = from . height / to . height ;
22
+
23
+ var dx = ( from . left + dsx * ox - ( to . left + ox ) ) / zoom ;
24
+ var dy = ( from . top + dsy * oy - ( to . top + oy ) ) / zoom ;
25
+ var { delay = 0 , duration = ( d ) => Math . sqrt ( d ) * 120 , easing = cubicOut } = params ;
26
+
21
27
return {
22
28
delay,
23
29
duration : typeof duration === 'function' ? duration ( Math . sqrt ( dx * dx + dy * dy ) ) : duration ,
24
30
easing,
25
31
css : ( t , u ) => {
26
- const x = u * dx ;
27
- const y = u * dy ;
28
- const sx = t + ( u * from . width ) / to . width ;
29
- const sy = t + ( u * from . height ) / to . height ;
30
- return `transform: ${ transform } translate (${ x } px , ${ y } px) scale (${ sx } , ${ sy } );` ;
32
+ var x = u * dx ;
33
+ var y = u * dy ;
34
+ var sx = t + u * dsx ;
35
+ var sy = t + u * dsy ;
36
+ return `transform: ${ transform } scale (${ sx } , ${ sy } ) translate (${ x } px , ${ y } px );` ;
31
37
}
32
38
} ;
33
39
}
40
+
41
+ /**
42
+ * @param {Element } element
43
+ */
44
+ function get_zoom ( element ) {
45
+ if ( 'currentCSSZoom' in element ) {
46
+ return /** @type {number } */ ( element . currentCSSZoom ) ;
47
+ }
48
+
49
+ /** @type {Element | null } */
50
+ var current = element ;
51
+ var zoom = 1 ;
52
+
53
+ while ( current !== null ) {
54
+ zoom *= + getComputedStyle ( current ) . zoom ;
55
+ current = /** @type {Element | null } */ ( current . parentNode ) ;
56
+ }
57
+
58
+ return zoom ;
59
+ }
0 commit comments