UNPKG

ngx-lottie

Version:

<h1 align="center"> <img src="https://raw.githubusercontent.com/ngx-lottie/ngx-lottie/master/docs/assets/lottie.gif"> </h1>

43 lines 1.51 kB
import { Injectable, NgZone, Inject } from '@angular/core'; import { from, of, animationFrameScheduler } from 'rxjs'; import { map, observeOn, publishReplay, refCount } from 'rxjs/operators'; import { LOTTIE_OPTIONS, } from './symbols'; function streamifyPlayerOrLoader(player) { const playerOrLoader = player(); if (playerOrLoader instanceof Promise) { return from(playerOrLoader).pipe(map(module => module.default || module), publishReplay(1), refCount()); } else { return of(playerOrLoader); } } export class AnimationLoader { constructor(ngZone, options) { this.ngZone = ngZone; this.options = options; this.player$ = streamifyPlayerOrLoader(this.options.player).pipe(observeOn(animationFrameScheduler)); } loadAnimation(options) { return this.player$.pipe(map(player => this.createAnimationItem(player, options))); } resolveOptions(options, container) { return Object.assign({ container, renderer: 'svg', loop: true, autoplay: true, }, options); } createAnimationItem(player, options) { return this.ngZone.runOutsideAngular(() => player.loadAnimation(options)); } } AnimationLoader.decorators = [ { type: Injectable } ]; /** @nocollapse */ AnimationLoader.ctorParameters = () => [ { type: NgZone }, { type: undefined, decorators: [{ type: Inject, args: [LOTTIE_OPTIONS,] }] } ]; //# sourceMappingURL=animation-loader.js.map