@@ -59,7 +59,7 @@ const DEFAULT_EASING = 'cubic-bezier(0.4, 0.0, 0.2, 1)';
5959 * TODO(alanorozco): maybe memoize?
6060 */
6161export function hasAnimations ( element ) {
62- const selector = `${ ANIMATABLE_ELEMENTS_SELECTOR } ,>amp-story-animation` ;
62+ const selector = `${ ANIMATABLE_ELEMENTS_SELECTOR } ,>amp-story-animation,amp-bodymovin-animation ` ;
6363 return ! ! scopedQuerySelector ( element , selector ) ;
6464}
6565
@@ -700,6 +700,12 @@ export class AnimationManager {
700700 } )
701701 )
702702 )
703+ . concat (
704+ Array . prototype . map . call (
705+ this . page_ . querySelectorAll ( 'amp-bodymovin-animation' ) ,
706+ ( el ) => new BodymovinAnimationRunner ( el )
707+ )
708+ )
703709 . filter ( Boolean ) ;
704710 }
705711 return devAssert ( this . runners_ ) ;
@@ -881,3 +887,75 @@ export class AnimationSequence {
881887 return this . subscriptionPromises_ [ id ] ;
882888 }
883889}
890+
891+ export class BodymovinAnimationRunner {
892+ /**
893+ * @param {!Element } bodymovinAnimationEl
894+ */
895+ constructor ( bodymovinAnimationEl ) {
896+ this . bodymovinAnimationEl_ = bodymovinAnimationEl ;
897+ this . pause ( ) ;
898+ }
899+
900+ /**
901+ * Pauses the bodymovin animation.
902+ */
903+ pause ( ) {
904+ this . executeAction_ ( 'pause' ) ;
905+ }
906+
907+ /**
908+ * Plays the bodymovin animation.
909+ */
910+ resume ( ) {
911+ this . executeAction_ ( 'play' ) ;
912+ }
913+
914+ /**
915+ * Starts the bodymovin animation.
916+ */
917+ start ( ) {
918+ this . applyFirstFrame ( ) ;
919+ this . resume ( ) ;
920+ }
921+
922+ /**
923+ * Seeks the bodymovin animation to the first frame.
924+ */
925+ applyFirstFrame ( ) {
926+ this . executeAction_ ( 'seekTo' , {
927+ percent : 0 ,
928+ } ) ;
929+ }
930+
931+ /**
932+ * Seeks the bodymovin animation to the last frame.
933+ */
934+ applyLastFrame ( ) {
935+ this . executeAction_ ( 'seekTo' , {
936+ percent : 1 ,
937+ } ) ;
938+ }
939+
940+ /**
941+ * Cancels the bodymovin animation by pausing it.
942+ */
943+ cancel ( ) {
944+ this . pause ( ) ;
945+ }
946+
947+ /**
948+ * @param {string } method
949+ * @param {=any } args
950+ * @private
951+ */
952+ executeAction_ ( method , args = null ) {
953+ this . bodymovinAnimationEl_ . getImpl ( ) . then ( ( impl ) => {
954+ impl . executeAction ( {
955+ method,
956+ args,
957+ satisfiesTrust : ( ) => true ,
958+ } ) ;
959+ } ) ;
960+ }
961+ }
0 commit comments