UNPKG

@thorvg/lottie-player

Version:

A web lottie player using ThorVG as a renderer

265 lines (260 loc) 6.5 kB
import { LitElement, PropertyValueMap, TemplateResult } from 'lit'; type EmbindString = ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string; interface ClassHandle { isAliasOf(other: ClassHandle): boolean; delete(): void; deleteLater(): this; isDeleted(): boolean; // @ts-ignore - If targeting lower than ESNext, this symbol might not exist. [Symbol.dispose](): void; clone(): this; } interface TvgLottieAnimation extends ClassHandle { size(): Float32Array; render(): ArrayBuffer; update(): boolean; quality(_0: number): boolean; resize(_0: number, _1: number): void; duration(): number; totalFrame(): number; curFrame(): number; frame(_0: number): boolean; viewport(_0: number, _1: number, _2: number, _3: number): boolean; error(): string; load(_0: EmbindString, _1: EmbindString, _2: number, _3: number): boolean; save(_0: EmbindString, _1: EmbindString): boolean; setAssetResolver(_0: (src: string, data: unknown) => { name: string, buffer: ArrayBuffer, mimetype: string }, _1: any): boolean; } interface LibraryVersion { THORVG_VERSION: string; } declare enum Renderer { SW = "sw", WG = "wg", GL = "gl" } 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 class BaseLottiePlayer 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; /** * 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; protected TVG: TvgLottieAnimation | null; protected canvas?: HTMLCanvasElement; protected config?: RenderConfig; 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; /** * Set rendering quality. * @param value Quality value (1-100). Higher values are likely to support better quality but may impact performance. * @since 1.0 */ setQuality(value: number): void; /** * Return thorvg version * @since 1.0 */ getVersion(): LibraryVersion; render(): TemplateResult; } declare class LottiePlayer extends BaseLottiePlayer { /** * Sets the rendering configurations. * @since 1.0 */ set renderConfig(value: RenderConfig); /** * Gets the current rendering configuration. * @since 1.0 */ get renderConfig(): RenderConfig; /** * 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>; } export { LottiePlayer };