UNPKG

@aarsteinmedia/dotlottie-player

Version:

Web Component for playing Lottie animations in your web app.

63 lines (59 loc) 2.24 kB
import { RendererType, isServer } from '@aarsteinmedia/lottie-web/utils'; export { PlayMode, PlayerEvents, RendererType } from '@aarsteinmedia/lottie-web/utils'; import Lottie from '@aarsteinmedia/lottie-web'; import { addAnimation, convert } from '@aarsteinmedia/lottie-web/dotlottie'; import { D as DotLottiePlayerBase, t as tagName } from './chunks/DotLottiePlayerBase-BBHa6yP8.js'; export { M as MouseOut, P as PlayerState } from './chunks/DotLottiePlayerBase-BBHa6yP8.js'; /** * DotLottie Player Web Component. */ class DotLottiePlayer extends DotLottiePlayerBase { loadAnimation(config) { return Lottie.loadAnimation(config); } setOptions({ container, hasAutoplay, hasLoop, initialSegment, preserveAspectRatio, rendererType }) { const options = { autoplay: hasAutoplay, container, initialSegment, loop: hasLoop, renderer: rendererType, rendererSettings: { imagePreserveAspectRatio: preserveAspectRatio } }; switch(this.renderer){ case RendererType.HTML: case RendererType.SVG: { options.rendererSettings = { ...options.rendererSettings, hideOnTransparent: true, preserveAspectRatio, progressiveLoad: true }; break; } case RendererType.Canvas: { options.rendererSettings = { ...options.rendererSettings, // clearCanvas: true, preserveAspectRatio, progressiveLoad: true }; break; } } return options; } constructor(...args){ super(...args), this.addAnimation = addAnimation, this.convert = convert; } } /** * Expose DotLottiePlayer class as global variable. */ globalThis.dotLottiePlayer = ()=>new DotLottiePlayer(); if (!isServer) { customElements.define(tagName, DotLottiePlayer); } export { DotLottiePlayer as default, tagName };