import { type CSSResultGroup } from 'lit'; import Lottie, { type AnimationDirection, type AnimationSegment, type RendererType } from 'lottie-web'; import { PlayerState, PlayMode } from './utils.js'; import AWCElement from '../../internal/awc-element.js'; import AWCIcon from '../icon/icon.component.js'; import AWCIconButton from '../icon-button/icon-button.component.js'; import AWCRange from '../range/range.component.js'; import type { AnimationConfig, AnimationSettings, Autoplay, Controls, Loop, LottieJSON, LottieManifest, ObjectFit, Subframe } from './types.js'; /** * @summary Web Component for playing Lottie animations in your web app. * @documentation https://webcomponents.adeliom.io/?path=/docs/components-lottie-player--documentation * @since 2.0 * * @dependency awc-icon * @dependency awc-icon-button * @dependency awc-range * * * @event awc-lottie-complete - Animation is complete – including all loops * @event awc-lottie-destroyed - Animation is destroyed * @event awc-lottie-error - The source cannot be parsed, fails to load or has format errors * @event awc-lottie-frame - A new frame is entered * @event awc-lottie-freeze - Animation is paused due to player being out of view * @event awc-lottie-load - Animation is loaded * @event awc-lottie-loop - A loop is completed * @event awc-lottie-play - Animation has started playing * @event awc-lottie-pause - Animation has paused * @event awc-lottie-ready - Animation is loaded and player is ready * @event awc-lottie-stop - Animation has stopped * * @error error - Error message slot for when the animation fails to load. * * @csspart base - The component's base wrapper. * @csspart animation - The animation container. * @csspart error - The error container. * @csspart controls - The controls container. * @csspart button - All buttons in the controls. * @csspart button-prev - The previous button. * @csspart button-next - The next button. * @csspart button-playpause - The play/pause button. * @csspart button-stop - The stop button. * @csspart button-loop - The loop button. * @csspart button-boomerang - The boomerang button. * * @cssproperty --toolbar-height - The height of the toolbar. */ export default class AWCLottiePlayer extends AWCElement { static styles: CSSResultGroup; static dependencies: { 'awc-icon': typeof AWCIcon; 'awc-icon-button': typeof AWCIconButton; 'awc-range': typeof AWCRange; }; /** * Play animation on load and if visible. */ autoplay?: Autoplay; /** * Background color */ background?: string; /** * Show controls */ controls?: Controls; /** * Number of times to loop the animation */ count?: number; /** * Current player state */ currentState?: PlayerState; /** * Description for screen readers */ description?: string; /** * Direction of animation (1 = forward, -1 = backward) */ direction?: AnimationDirection; /** * Whether to play on mouseover */ hover?: boolean | undefined; /** * Intermission time in seconds between animation loops */ intermission?: number | undefined; /** * Whether to loop the animation */ loop?: Loop; /** * Play mode (bounce or normal) */ mode?: PlayMode; /** * Multi-animation settings * If set, these will override conflicting settings */ multiAnimationSettings?: AnimationSettings[]; /** * Resizing to container */ objectfit?: ObjectFit; /** * Renderer to use (svg, canvas or html) */ renderer?: RendererType; /** * Play only part of an animation. * E.g. from frame 10 to frame 60 would be [10, 60] */ segment?: AnimationSegment; /** * Hide advanced controls like loop and boomerang */ simple?: boolean; /** * Speed */ speed?: number; /** * JSON/dotLottie data or URL */ src: string; /** * When enabled this can help to reduce flicker on some animations, especially on Safari and iOS devices. */ subframe?: Subframe; /** * Animaiton Container */ protected container: HTMLElement; /** * Seeker */ private _seeker; /** * Which animation to show, if several */ private _currentAnimation; private _intersectionObserver?; private _lottieInstance; private _identifier; private _errorMessage; private _isBounce; private _isDotLottie; private _manifest; /** * This is set to state, so that next-button will show up * on load, if controls are visible */ private _animations; private _playerState; /** * Get options from props * @returns { LottieConfig } */ private _getOptions; /** * Initialize Lottie Web player * @param { string | LottieJSON } src URL to lottie animation, or raw JSON data */ load(src: string | LottieJSON): Promise; /** * Get Lottie Manifest */ getManifest(): LottieManifest; /** * Add event listeners */ private _addEventListeners; /** * Remove event listeners */ private _removeEventListeners; private _loopComplete; private _enterFrame; private _complete; private _DOMLoaded; private _dataReady; private _dataFailed; /** * Handle MouseEnter */ private _mouseEnter; /** * Handle MouseLeave */ private _mouseLeave; /** * Handle visibility change events */ private _onVisibilityChange; /** * Handles click and drag actions on the progress track * @param { Event & { HTMLInputElement } } event */ private _handleSeekChange; private _isLottie; /** * Creates a new dotLottie file, by combinig several animations * @param { [ AnimationConfig ] } configs * @param { string } fileName * @param { boolean } shouldDownload Whether to trigger a download in the browser. * If set to false the function returns an ArrayBuffer. Defaults to true. * */ addAnimation(configs: AnimationConfig[], fileName?: string, shouldDownload?: boolean): Promise; /** * Returns the lottie-web instance used in the component */ getLottie(): Lottie.AnimationItem | null; /** * Play */ play(): void; /** * Pause */ pause(): void; /** * Stop */ stop(): void; /** * Destroy animation and element */ destroy(): void; /** * Seek to a given frame * @param { number | string } value Frame to seek to */ seek(value: number | string): void; /** * Snapshot and download the current frame as SVG */ snapshot(): string | undefined; /** * Toggles subframe, for more smooth animations * @param { boolean } value Whether animation uses subframe */ setSubframe(value: boolean): void; /** * Dynamically set count for loops */ setCount(value: number): void; /** * Freeze animation. * This internal state pauses animation and is used to differentiate between * user requested pauses and component instigated pauses. */ private _freeze; /** * Reload animation */ reload(): Promise; /** * Set animation playback speed * @param { number } value Playback speed */ setSpeed(value?: number): void; /** * Animation play direction * @param { AnimationDirection } value Animation direction */ setDirection(value: AnimationDirection): void; /** * Set loop * @param { boolean } value */ setLooping(value: boolean): void; /** * Set Multi-animation settings * @param { AnimationSettings[] } settings */ setMultiAnimationSettings(settings: AnimationSettings[]): void; /** * Toggle playing state */ togglePlay(): void; /** * Toggle loop */ toggleLooping(): void; /** * Toggle Boomerang */ toggleBoomerang(): void; private _switchInstance; /** * Skip to next animation */ next(): void; /** * Skip to previous animation */ prev(): void; convert({ typeCheck, manifest, animations, src, fileName, shouldDownload }: { /** External type safety */ typeCheck?: boolean; /** Externally added manifest */ manifest?: LottieManifest; /** Externally added animations */ animations?: LottieJSON[]; src?: string; fileName?: string; /** Whether to trigger a download in the browser. Defaults to true */ shouldDownload?: boolean; }): Promise; constructor(); /** * Initialize everything on component first render */ connectedCallback(): void; protected firstUpdated(): Promise; /** * Cleanup on component destroy */ disconnectedCallback(): void; protected renderControls(): import("lit-html").TemplateResult<1>; protected render(): import("lit-html").TemplateResult<1>; }