@lottiefiles/dotlottie-web 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # @lottiefiles/dotlottie-web
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/@lottiefiles/dotlottie-web)
4
- ![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40lottiefiles%2Fdotlottie-web)
5
- ![npm](https://img.shields.io/npm/dt/%40lottiefiles/dotlottie-web)
4
+ ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@lottiefiles/dotlottie-web)
5
+ ![npm](https://img.shields.io/npm/dm/@lottiefiles/dotlottie-web)
6
6
  ![NPM](https://img.shields.io/npm/l/@lottiefiles/dotlottie-web)
7
+ [![](https://data.jsdelivr.com/v1/package/npm/@lottiefiles/dotlottie-web/badge)](https://www.jsdelivr.com/package/npm/@lottiefiles/dotlottie-web)
7
8
 
8
9
  <p align="center">
9
10
  <img src="https://user-images.githubusercontent.com/23125742/201124166-c2a0bc2a-018b-463b-b291-944fb767b5c2.png" />
@@ -56,7 +57,7 @@ After installation, you can import `DotLottie` in your JavaScript or TypeScript
56
57
 
57
58
  ```html
58
59
  <!-- Canvas element where the animation will be rendered -->
59
- <canvas id="my-canvas" width="300px" height="300px"></canvas>
60
+ <canvas id="dotlottie-canvas" style="width: 300px; height:300px;"></canvas>
60
61
  ```
61
62
 
62
63
  ```js
@@ -65,7 +66,7 @@ import { DotLottie } from '@lottiefiles/dotlottie-web';
65
66
  const dotLottie = new DotLottie({
66
67
  autoplay: true,
67
68
  loop: true,
68
- canvas: document.getElementById('my-canvas'),
69
+ canvas: document.querySelector('#dotlottie-canvas'),
69
70
  src: "https://lottie.host/4db68bbd-31f6-4cd8-84eb-189de081159a/IGmMCqhzpt.lottie", // or .json file
70
71
  });
71
72
  ```
@@ -87,14 +88,13 @@ const dotLottie = new DotLottie({
87
88
  <!-- Canvas element where the Lottie animation will be rendered -->
88
89
  <canvas id="canvas" width="300" height="300"></canvas>
89
90
  <script type="module">
90
- import { DotLottie } from "https://unpkg.com/@lottiefiles/dotlottie-web@latest/dist/index.js";
91
+ import { DotLottie } from "https://cdn.jsdelivr.net/npm/@lottiefiles/dotlottie-web/+esm";
91
92
 
92
93
  new DotLottie({
93
94
  autoplay: true,
94
95
  loop: true,
95
96
  canvas: document.getElementById("canvas"),
96
- src:
97
- "https://lottie.host/5f7f4690-6311-4279-82e4-38c2eab146ab/niPwIBUnGa.json"
97
+ src: "https://lottie.host/4db68bbd-31f6-4cd8-84eb-189de081159a/IGmMCqhzpt.lottie", // or .json file
98
98
  });
99
99
  </script>
100
100
  </body>
@@ -1,11 +1,9 @@
1
1
  /**
2
2
  * Copyright 2023 Design Barn Inc.
3
3
  */
4
- /// <reference lib="webworker" />
5
4
  declare const IS_BROWSER: boolean;
6
5
  declare const IS_NODE: boolean;
7
- declare const IS_WEB_WORKER: boolean;
8
6
  declare const MS_TO_SEC_FACTOR = 1000;
9
7
  declare const DEFAULT_BG_COLOR = "#00000000";
10
8
 
11
- export { DEFAULT_BG_COLOR, IS_BROWSER, IS_NODE, IS_WEB_WORKER, MS_TO_SEC_FACTOR };
9
+ export { DEFAULT_BG_COLOR, IS_BROWSER, IS_NODE, MS_TO_SEC_FACTOR };
package/dist/constants.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const IS_BROWSER = typeof window !== "undefined";
2
- const IS_NODE = typeof process !== "undefined" && process.release.name === "node";
3
- const IS_WEB_WORKER = typeof self !== "undefined" && typeof self.postMessage === "function";
2
+ const IS_NODE = typeof process !== "undefined";
4
3
  const MS_TO_SEC_FACTOR = 1e3;
5
4
  const DEFAULT_BG_COLOR = "#00000000";
6
5
 
7
- export { DEFAULT_BG_COLOR, IS_BROWSER, IS_NODE, IS_WEB_WORKER, MS_TO_SEC_FACTOR };
6
+ export { DEFAULT_BG_COLOR, IS_BROWSER, IS_NODE, MS_TO_SEC_FACTOR };
@@ -108,6 +108,7 @@ declare class DotLottie {
108
108
  private _isLoaded;
109
109
  private readonly _animationFrameManager;
110
110
  private _useFrameInterpolation;
111
+ private _imageData;
111
112
  constructor(config: Config);
112
113
  get canvas(): HTMLCanvasElement | OffscreenCanvas;
113
114
  get mode(): Mode;
package/dist/dotlottie.js CHANGED
@@ -37,12 +37,10 @@ class DotLottie {
37
37
  __publicField(this, "_isLoaded", false);
38
38
  __publicField(this, "_animationFrameManager", new AnimationFrameManager());
39
39
  __publicField(this, "_useFrameInterpolation", true);
40
+ __publicField(this, "_imageData", null);
40
41
  this._animationLoop = this._animationLoop.bind(this);
41
42
  this._canvas = config.canvas;
42
43
  this._context = this._canvas.getContext("2d");
43
- if (!this._context) {
44
- throw new Error("2D context not supported or canvas already initialized with another context type.");
45
- }
46
44
  this._loop = config.loop ?? false;
47
45
  this._speed = config.speed ?? 1;
48
46
  this._autoplay = config.autoplay ?? false;
@@ -51,6 +49,7 @@ class DotLottie {
51
49
  this._backgroundColor = config.backgroundColor ?? DEFAULT_BG_COLOR;
52
50
  this._renderConfig = config.renderConfig ?? {};
53
51
  this._useFrameInterpolation = config.useFrameInterpolation ?? true;
52
+ this._direction = this._mode.includes("reverse") ? -1 : 1;
54
53
  RendererLoader.load().then((module) => {
55
54
  this._renderer = new module.Renderer();
56
55
  this.setBackgroundColor(this._backgroundColor);
@@ -266,14 +265,11 @@ class DotLottie {
266
265
  this._renderer.resize(width, height);
267
266
  if (this._renderer.update()) {
268
267
  const buffer = this._renderer.render();
269
- if (buffer.length === 0) {
270
- console.warn("Empty buffer received from renderer.");
271
- return;
268
+ if (this._imageData?.data.length !== buffer.length) {
269
+ this._imageData = this._context.createImageData(width, height);
272
270
  }
273
- const clampedBuffer = new Uint8ClampedArray(buffer);
274
- const imageData = this._context.createImageData(width, height);
275
- imageData.data.set(clampedBuffer);
276
- this._context.putImageData(imageData, 0, 0);
271
+ this._imageData.data.set(buffer);
272
+ this._context.putImageData(this._imageData, 0, 0);
277
273
  }
278
274
  }
279
275
  /**
@@ -9,7 +9,7 @@ interface Renderer {
9
9
  error(): string;
10
10
  frame(no: number): boolean;
11
11
  load(data: string, width: number, height: number): boolean;
12
- render(): Uint8Array;
12
+ render(): Uint8ClampedArray;
13
13
  resize(width: number, height: number): void;
14
14
  setBgColor(color: number): void;
15
15
  size(): Float32Array;
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lottiefiles/dotlottie-web",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "type": "module",
5
5
  "description": "Lottie and DotLottie player for the web",
6
6
  "repository": {
@@ -70,8 +70,8 @@
70
70
  "lint": "eslint --fix .",
71
71
  "stats:eslint": "cross-env TIMING=1 eslint .",
72
72
  "stats:ts": "tsc -p tsconfig.build.json --extendedDiagnostics",
73
- "test": "vitest run --browser.headless --retry 2",
74
- "test:coverage": "pnpm test -- --coverage",
73
+ "test": "vitest run --browser.headless",
74
+ "test:coverage": "vitest run --browser.headless --coverage",
75
75
  "test:watch": "vitest",
76
76
  "type-check": "tsc --noEmit"
77
77
  }