From f89a40b9b972844e9660abce099bfb86e031ac05 Mon Sep 17 00:00:00 2001 From: Jinny You Date: Thu, 4 Jan 2024 16:56:46 +0900 Subject: [PATCH] web: Add extra feature & property - Support `resize` method - Add `resolution` prop --- web/src/lottie-player.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/web/src/lottie-player.ts b/web/src/lottie-player.ts index 2731eb4d..d218053d 100644 --- a/web/src/lottie-player.ts +++ b/web/src/lottie-player.ts @@ -252,6 +252,15 @@ export class LottiePlayer extends LitElement { @property({ type: Number }) public currentState: PlayerState = PlayerState.Loading; + /** + * original size of the animation (readonly) + * @since 1.0 + */ + @property({ type: Float32Array }) + public get size(): Float32Array { + return Float32Array.from(this._TVG?.size() || [0, 0]); + } + private _TVG?: TvgModule; private _canvas?: HTMLCanvasElement; private _imageData?: ImageData; @@ -491,6 +500,21 @@ export class LottiePlayer extends LitElement { this._render(); } + /** + * Adjust the canvas size. + * @param width The width to resize + * @param height The height to resize + * @since 1.0 + */ + public resize(width: number, height: number) { + this._canvas!.width = width; + this._canvas!.height = height; + + if (this.currentState !== PlayerState.Playing) { + this._render(); + } + } + /** * Destroy animation and lottie-player element. * @since 1.0