(
el: Element,
animationOpts: ElementKeyframeAnimationOption<T> | ElementKeyframeAnimationOption<T>[],
animatableModel: Model<AnimationOptionMixin>
)
| 57 | } |
| 58 | |
| 59 | export function applyKeyframeAnimation<T extends Record<string, any>>( |
| 60 | el: Element, |
| 61 | animationOpts: ElementKeyframeAnimationOption<T> | ElementKeyframeAnimationOption<T>[], |
| 62 | animatableModel: Model<AnimationOptionMixin> |
| 63 | ) { |
| 64 | if (!animatableModel.isAnimationEnabled() || !animationOpts) { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | if (isArray(animationOpts)) { |
| 69 | each(animationOpts, singleAnimationOpts => { |
| 70 | applyKeyframeAnimation(el, singleAnimationOpts, animatableModel); |
| 71 | }); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | const keyframes = animationOpts.keyframes; |
| 76 | let duration = animationOpts.duration; |
| 77 | |
| 78 | if (animatableModel && duration == null) { |
| 79 | // Default to use duration of config. |
| 80 | // NOTE: animation config from payload will be ignored because they are mainly for transitions. |
| 81 | const config = getAnimationConfig('enter', animatableModel, 0); |
| 82 | duration = config && config.duration; |
| 83 | } |
| 84 | |
| 85 | if (!keyframes || !duration) { |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | const stateToRestore: StateToRestore = getStateToRestore(el); |
| 90 | |
| 91 | each(ELEMENT_ANIMATABLE_PROPS, (targetPropName) => { |
| 92 | if (targetPropName && !(el as any)[targetPropName]) { |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | let animator: ReturnType<Element['animate']>; |
| 97 | let endFrameIsSet = false; |
| 98 | |
| 99 | // Sort keyframes by percent. |
| 100 | keyframes.sort((a, b) => a.percent - b.percent); |
| 101 | |
| 102 | each(keyframes, kf => { |
| 103 | // Stop current animation. |
| 104 | const animators = el.animators; |
| 105 | const kfValues = targetPropName ? kf[targetPropName] : kf; |
| 106 | |
| 107 | if (__DEV__) { |
| 108 | if (kf.percent >= 1) { |
| 109 | endFrameIsSet = true; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if (!kfValues) { |
| 114 | return; |
| 115 | } |
| 116 |
no test coverage detected
searching dependent graphs…