UNPKG

@thorvg/lottie-player

Version:

A web lottie player using ThorVG as a renderer

242 lines (239 loc) 5.51 kB
import { LitElement, PropertyValueMap, TemplateResult } from 'lit'; interface LibraryVersion { THORVG_VERSION: string; } declare enum Renderer { SW = "sw", WG = "wg", GL = "gl" } declare enum InitStatus { IDLE = "idle", FAILED = "failed", REQUESTED = "requested", INITIALIZED = "initialized" } type RenderConfig = { enableDevicePixelRatio?: boolean; renderer?: Renderer; }; declare enum FileType { JSON = "json", LOT = "lot", JPG = "jpg", PNG = "png", SVG = "svg" } declare enum PlayerState { Destroyed = "destroyed",// Player is destroyed by `destroy()` method Error = "error",// An error occurred Loading = "loading",// Player is loading Paused = "paused",// Player is paused Playing = "playing",// Player is playing Stopped = "stopped",// Player is stopped Frozen = "frozen" } declare enum PlayMode { Bounce = "bounce", Normal = "normal" } declare enum PlayerEvent { Complete = "complete", Destroyed = "destroyed", Error = "error", Frame = "frame", Freeze = "freeze", Load = "load", Loop = "loop", Pause = "pause", Play = "play", Ready = "ready", Stop = "stop" } declare class LottiePlayer extends LitElement { /** * Lottie animation JSON data or URL to JSON. * @since 1.0 */ src?: string; /** * Custom WASM URL for ThorVG engine * @since 1.0 */ wasmUrl?: string; /** * File type. * @since 1.0 */ fileType: FileType; /** * Rendering configurations. * @since 1.0 */ renderConfig?: RenderConfig; /** * Animation speed. * @since 1.0 */ speed: number; /** * Autoplay animation on load. * @since 1.0 */ autoPlay: boolean; /** * Number of times to loop animation. * @since 1.0 */ count?: number; /** * Whether to loop animation. * @since 1.0 */ loop: boolean; /** * Direction of animation. * @since 1.0 */ direction: number; /** * Play mode. * @since 1.0 */ mode: PlayMode; /** * Intermission * @since 1.0 */ intermission: number; /** * total frame of current animation (readonly) * @since 1.0 */ totalFrame: number; /** * current frame of current animation (readonly) * @since 1.0 */ currentFrame: number; /** * Player state * @since 1.0 */ currentState: PlayerState; /** * original size of the animation (readonly) * @since 1.0 */ get size(): Float32Array; private _TVG?; private _canvas?; private _imageData?; private _beginTime; private _counter; private _timer?; private _observer?; private _observable; private _init; private _viewport; private _observerCallback; protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void; protected createRenderRoot(): HTMLElement | DocumentFragment; private _animLoop; private _loadBytes; private _flush; private _render; private _update; private _frame; /** * Configure and load * @param src Lottie animation JSON data or URL to JSON. * @param fileType The file type of the data to be loaded, defaults to JSON * @since 1.0 */ load(src: string | object, fileType?: FileType): Promise<void>; /** * Start playing animation. * @since 1.0 */ play(): void; /** * Pause animation. * @since 1.0 */ pause(): void; /** * Stop animation. * @since 1.0 */ stop(): void; /** * Freeze animation. * @since 1.0 */ freeze(): void; /** * Seek to a given frame * @param frame Frame number to move * @since 1.0 */ seek(frame: number): Promise<void>; /** * Adjust the canvas size. * @param width The width to resize * @param height The height to resize * @since 1.0 */ resize(width: number, height: number): void; /** * Destroy animation and lottie-player element. * @since 1.0 */ destroy(): void; /** * Terminate module and release resources * @since 1.0 */ term(): void; /** * Sets the repeating of the animation. * @param value Whether to enable repeating. Boolean true enables repeating. * @since 1.0 */ setLooping(value: boolean): void; /** * Animation play direction. * @param value Direction values. (1: forward, -1: backward) * @since 1.0 */ setDirection(value: number): void; /** * Set animation play speed. * @param value Playback speed. (any positive number) * @since 1.0 */ setSpeed(value: number): void; /** * Set a background color. (default: 0x00000000) * @param value Hex(#fff) or string(red) of background color * @since 1.0 */ setBgColor(value: string): void; /** * Save current animation to png image * @since 1.0 */ save2png(): void; /** * Save current animation to gif image * @since 1.0 */ save2gif(src: string): Promise<void>; /** * Return thorvg version * @since 1.0 */ getVersion(): LibraryVersion; render(): TemplateResult; } export { FileType, InitStatus, type LibraryVersion, LottiePlayer, PlayMode, PlayerEvent, PlayerState, type RenderConfig, Renderer };