16
16
17
17
import { Curve } from '../bezier-curve-utils.js' ;
18
18
import { getRenderedDimensions } from '../img-dimensions.js' ;
19
- import { createReplacement } from '../replacement -img.js' ;
19
+ import { createImitationImg } from '../imitation -img.js' ;
20
20
import { prepareCropAnimation } from './crop-animation.js' ;
21
21
import { prepareScaleAnimation } from './scale-animation.js' ;
22
22
import { prepareTranslateAnimation } from './translate-animation.js' ;
23
23
24
+ /**
25
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/single-transition-timing-function#ease-in-out
26
+ */
27
+ const EASE_IN_OUT = { x1 : 0.42 , y1 : 0 , x2 : 0.58 , y2 : 1 } ;
28
+
24
29
/**
25
30
* A counter that makes sure the keyframes names are unique.
26
31
*/
@@ -39,33 +44,34 @@ function getKeyframesPrefix(namespace: string): string {
39
44
}
40
45
41
46
/**
42
- * Prepares an animation from one image to another. Creates a a temporary
43
- * replacement image that is transitioned between the two images.
47
+ * Prepares an animation from one image to another. Creates a temporary
48
+ * transition image that is transitioned between the position, size and crop of
49
+ * two images.
44
50
* @param options
45
51
* @param options.transitionContainer The container to place the transition
46
- * image in. Defaults to document.body.
52
+ * image in. This could be useful if you need to place the transition in a
53
+ * container with a specific `z-index` to appear on top of other elements in
54
+ * the page. It can also be useful if you want to have the transition stay
55
+ * within the `ShadowRoot` of a component. Defaults to document.body.
47
56
* @param options.styleContainer The container to place the generated
48
57
* stylesheet in. Defaults to document.head.
49
58
* @param options.srcImg The image to transition from.
50
59
* @param options.targetImg The image to transition to.
51
60
* @param options.srcImgRect The ClientRect for where the transition should
52
- * start from. Defaults to the current rect for srcImg.
61
+ * start from. Specifying this could be useful if you need to hide
62
+ * (`display: none`) the container for `srcImg` in order to layout a page
63
+ * containing `targetImg`. In that case, you can capture the rect for
64
+ * `srcImg` up front and then pass it. Defaults to the current rect for
65
+ * srcImg.
53
66
* @param options.targetImgRect The ClientRect for where the transition should
54
- * end at. Defaults to the current rect for targetImg.
67
+ * end at. Specifying this could be useful if you have not had a chance to
68
+ * perform the layout for the target yet (e.g. in a `display: none`
69
+ * container), but you know where on the screen it will go. Defaults to the
70
+ * current rect for targetImg.
55
71
* @param options.curve Control points for a Bezier curve to use for the
56
72
* animation.
57
73
* @param options.styles Styles to apply to the transitioning Elements. This
58
74
* should include animationDuration. It might also include animationDelay.
59
- * @param options.translateCurve Control points for a Bezier curve to use for
60
- * the translation portion of animation. Defaults to `curve`.
61
- * @param options.translateStyles Styles to apply to the translating Elements.
62
- * This should include animationDuration. It might also include
63
- * animationDelay. Defaults to `styles`.
64
- * @param options.scaleCurve Control points for a Bezier curve to use for
65
- * the translation portion of animation. Defaults to `curve`.
66
- * @param options.scaleStyles Styles to apply to the scaling Elements. This
67
- * should include animationDuration. It might also include animationDelay.
68
- * Defaults to `styles`.
69
75
* @param options.keyframesNamespace A namespace to use for the generated
70
76
* keyframes to ensure they do not clash with existing keyframes.
71
77
*/
@@ -76,12 +82,8 @@ export function prepareImageAnimation({
76
82
targetImg,
77
83
srcImgRect = srcImg . getBoundingClientRect ( ) ,
78
84
targetImgRect = targetImg . getBoundingClientRect ( ) ,
79
- curve,
85
+ curve = EASE_IN_OUT ,
80
86
styles,
81
- translateCurve = curve ,
82
- translateStyles = styles ,
83
- scaleCurve = curve ,
84
- scaleStyles = styles ,
85
87
keyframesNamespace = 'img-transform' ,
86
88
} : {
87
89
transitionContainer : HTMLElement ,
@@ -90,12 +92,8 @@ export function prepareImageAnimation({
90
92
targetImg : HTMLImageElement ,
91
93
srcImgRect ?: ClientRect ,
92
94
targetImgRect ?: ClientRect ,
93
- curve : Curve ,
95
+ curve ? : Curve ,
94
96
styles : Object ,
95
- translateCurve ?: Curve ,
96
- translateStyles ?: Object ,
97
- scaleCurve ?: Curve ,
98
- scaleStyles ?: Object ,
99
97
keyframesNamespace ?: string ,
100
98
} ) : {
101
99
applyAnimation : ( ) => void ,
@@ -118,7 +116,7 @@ export function prepareImageAnimation({
118
116
img,
119
117
imgWidth : largerImgWidth ,
120
118
imgHeight : largerImgHeight ,
121
- } = createReplacement ( largerImg , largerRect ) ;
119
+ } = createImitationImg ( largerImg , largerRect ) ;
122
120
const {
123
121
width : smallerImgWidth ,
124
122
height : smallerImgHeight ,
@@ -138,8 +136,8 @@ export function prepareImageAnimation({
138
136
element : translateElement ,
139
137
largerRect,
140
138
smallerRect,
141
- curve : translateCurve ,
142
- styles : translateStyles ,
139
+ curve,
140
+ styles,
143
141
keyframesPrefix,
144
142
toLarger,
145
143
} ) ;
@@ -149,8 +147,8 @@ export function prepareImageAnimation({
149
147
largerImgHeight,
150
148
smallerImgWidth,
151
149
smallerImgHeight,
152
- curve : scaleCurve ,
153
- styles : scaleStyles ,
150
+ curve,
151
+ styles,
154
152
keyframesPrefix,
155
153
toLarger,
156
154
} ) ;
0 commit comments