import { ɵAnimationEngine as AnimationEngine } from '@angular/animations/browser' ; import { Injectable } from '@angular/core' ; import { AnimationEngineAdapter , AnimationEngineMethods , command , DomEventArg , fnArg , FnArg , MessageBus , ObjectStore , PrimitiveArg , Serializer , SerializerTypes , StoreObjectArg } from '../shared' ; @ Injectable ( ) export class BrowserAnimationEngineAdapter extends AnimationEngineAdapter { constructor ( private engine , private serializer , private store , private bus ) { super ( ) ; if ( engine ) { const onRemovalComplete = engine . onRemovalComplete ; engine . onRemovalComplete = ( element , delegate ) => { if ( ! delegate . namespaceId ) { element . parentNode . removeChild ( element ) ; } onRemovalComplete ( element , delegate ) ; } ; } } destroy ( namespaceIdArg , contextArg ) { const [ namespaceId , context ] = this . deserialize ( ... arguments ) ; this . engine . destroy ( namespaceId , context ) ; } disableAnimations ( elementArg , disableArg ) { const [ element , disable ] = this . deserialize ( ... arguments ) ; this . engine . disableAnimations ( element , disable ) ; } flush ( microtaskIdArg ) { const [ microtaskId ] = this . deserialize ( ... arguments ) ; this . engine . flush ( microtaskId ) ; } event ( elementArg , eventNameArg , eventArg ) { this . callServerAnimationEngine ( 'event' , ... arguments ) ; } listen ( namespaceIdArg , elementArg , eventNameArg , eventPhaseArg , listenIdArg ) { const [ namespaceId , element , eventName , eventPhase , listenId ] = this . deserialize ( ... arguments ) ; const unlisten = this . engine . listen ( namespaceId , element , eventName , eventPhase , ( event ) => { this . event ( fnArg ( element , SerializerTypes . STORE_OBJECT ) , fnArg ( eventName ) , fnArg ( event , SerializerTypes . DOM_EVENT ) ) ; return false ; } ) ; this . store . allocateNode ( unlisten , listenId ) ; } onInsert ( namespaceIdArg , elementArg , parentArg , insertBeforeArg ) { const [ namespaceId , element , parent , insertBefore ] = this . deserialize ( ... arguments ) ; this . engine . onInsert ( namespaceId , element , parent , insertBefore ) ; } onRemove ( namespaceIdArg , elementArg , contextArg , isHostElementArg ) { const [ namespaceId , element , context , iHostElement ] = this . deserialize ( ... arguments ) ; this . engine . onRemove ( namespaceId , element , context , iHostElement ) ; } onRemovalComplete ( elementArg , contextArg ) { const [ element , context ] = this . deserialize ( ... arguments ) ; this . engine . onRemovalComplete ( element , context ) ; } process ( namespaceIdArg , elementArg , propertyArg , valueArg ) { const [ namespaceId , element , property , value ] = this . deserialize ( ... arguments ) ; this . engine . process ( namespaceId , element , property , value ) ; } register ( namespaceIdArg , hostElementArg ) { const [ namespaceId , hostElement ] = this . deserialize ( ... arguments ) ; this . engine . register ( namespaceId , hostElement ) ; } registerTrigger ( componentIdArg , namespaceIdArg , hostElementArg , nameArg , metadataArg ) { const [ componentId , namespaceId , hostElement , name , metadata ] = this . deserialize ( ... arguments ) ; this . engine . registerTrigger ( componentId , namespaceId , hostElement , name , metadata ) ; } unlisten ( listenIdArg ) { const [ listenId ] = this . deserialize ( ... arguments ) ; const unlisten = this . store . deserialize ( listenId ) ; if ( typeof unlisten === 'function' ) { unlisten ( ) ; } this . store . deallocateNode ( unlisten ) ; } private callServerAnimationEngine ( method , ... fnArgs ) { const payload = fnArgs . map ( arg => this . serializer . serialize ( arg . value , arg . type ) ) ; this . bus . sendCommand ( command ( 'animation-engine' , method , payload ) ) ; } private deserialize ( ... fnArgs ) { return fnArgs . map ( arg => this . serializer . deserialize ( arg . value , arg . type ) ) as [ ... any [ ] ] ; } }