ngx-lottie
Version:
<h1 align="center"> <img src="https://raw.githubusercontent.com/ngx-lottie/ngx-lottie/master/docs/assets/lottie.gif"> </h1>
31 lines • 1.4 kB
JavaScript
import { join } from 'path';
import { makeStateKey } from '@angular/platform-browser';
import { transformAnimationFilenameToKey } from 'ngx-lottie';
import { readFileWithAnimationData } from './utils';
function readAndTransferAnimationData(transferState, animations, pathsToAnimations) {
const sources = [];
for (let i = 0, length = animations.length; i < length; i++) {
const path = pathsToAnimations[i];
const source = readFileWithAnimationData(path).then(animationData => {
transferAnimationData(transferState, animations[i], animationData);
});
sources.push(source);
}
return sources;
}
function transferAnimationData(state, animation, animationData) {
animation = transformAnimationFilenameToKey(animation);
const key = makeStateKey(animation);
state.set(key, JSON.parse(animationData));
}
export function appInitializerFactory(options, state) {
const pathsToAnimations = resolveLottiePaths(options);
const sources = readAndTransferAnimationData(state, options.preloadAnimations.animations, pathsToAnimations);
return () => Promise.all(sources);
}
export function resolveLottiePaths({ preloadAnimations }) {
const { folder, animations } = preloadAnimations;
const path = join(process.cwd(), folder);
return animations.map(animation => join(path, animation));
}
//# sourceMappingURL=internals.js.map