@aarsteinmedia/dotlottie-player 5.0.3 → 5.1.0

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/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  Changelog was only added since [3.2.3], so it's not exhaustive. [Please report any missing noteable changes to us](https://github.com/aarsteinmedia/dotlottie-player/issues), and we'll add them promptly.
9
9
 
10
+ ## [5.1.0] - 02-06-2025
11
+
12
+ ### Changed
13
+
14
+ - Dropped `lottie-web` as dependency in favour of `@aarsteinmedia/lottie-web`. This animation engine is based on `lottie-web`, has the same features + it works better in Node SSR environments, it doesn't rely on `eval()` to execute AE expressions, and it is hopefully easier to maintain and expand.
15
+
16
+ ## [5.0.4] - 31-05-2025
17
+
18
+ ### Changed
19
+
20
+ - Fixed bug preventing autoplay on some animations
21
+
10
22
  ## [5.0.3] - 28-05-2025
11
23
 
12
24
  ### Changed
@@ -217,6 +229,7 @@ Changelog was only added since [3.2.3], so it's not exhaustive. [Please report a
217
229
  - Removed dependencies
218
230
  - `@lit`
219
231
 
232
+ [5.0.4]: https://www.npmjs.com/package/@aarsteinmedia/dotlottie-player/v/5.0.4
220
233
  [5.0.3]: https://www.npmjs.com/package/@aarsteinmedia/dotlottie-player/v/5.0.3
221
234
  [5.0.1]: https://www.npmjs.com/package/@aarsteinmedia/dotlottie-player/v/5.0.1
222
235
  [5.0.0]: https://www.npmjs.com/package/@aarsteinmedia/dotlottie-player/v/5.0.0
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { isServer as isServer$1, createElementID, PreserveAspectRatio as PreserveAspectRatio$1 } from '@aarsteinmedia/lottie-web/utils';
2
- import Lottie from 'lottie-web';
1
+ import { isServer, createElementID, PreserveAspectRatio as PreserveAspectRatio$1 } from '@aarsteinmedia/lottie-web/utils';
2
+ import Lottie from '@aarsteinmedia/lottie-web';
3
3
  import { strToU8, strFromU8, zip, unzip as unzip$1 } from 'fflate';
4
4
 
5
5
  /**
6
6
  * Credit to: Leonardo Favre https://github.com/leofavre/observed-properties.
7
7
  */ const updateOnConnected = Symbol('UPDATE_ON_CONNECTED');
8
- if (isServer$1()) {
8
+ if (isServer()) {
9
9
  // Mock HTMLElement for server-side rendering
10
10
  global.HTMLElement = // eslint-disable-next-line @typescript-eslint/no-extraneous-class
11
11
  class EmptyHTMLElement {
@@ -205,7 +205,7 @@ class CustomError extends Error {
205
205
  throw new Error('No animations listed in manifest');
206
206
  }
207
207
  return manifest;
208
- }, isServer = ()=>!(typeof window !== 'undefined' && window.document);
208
+ };
209
209
  /**
210
210
  * Methods used only locally.
211
211
  */ const hasExt = (path)=>{
@@ -972,7 +972,7 @@ const generator = '@aarsteinmedia/dotlottie-player';
972
972
  /**
973
973
  * Runs when the value of an attribute is changed on the component.
974
974
  */ async attributeChangedCallback(name, _oldValue, value) {
975
- if (!this._lottieInstance) {
975
+ if (!this._lottieInstance || !this.shadow) {
976
976
  return;
977
977
  }
978
978
  if (name === 'animateOnScroll') {
@@ -1016,14 +1016,14 @@ const generator = '@aarsteinmedia/dotlottie-player';
1016
1016
  this._container.removeEventListener('mouseleave', this._mouseLeave);
1017
1017
  }
1018
1018
  if (name === 'loop') {
1019
- const toggleLoop = this.shadow?.querySelector('.toggleLoop');
1019
+ const toggleLoop = this.shadow.querySelector('.toggleLoop');
1020
1020
  if (toggleLoop instanceof HTMLButtonElement) {
1021
1021
  toggleLoop.dataset.active = value;
1022
1022
  }
1023
1023
  this.setLoop(value === '' || Boolean(value));
1024
1024
  }
1025
1025
  if (name === 'mode') {
1026
- const toggleBoomerang = this.shadow?.querySelector('.toggleBoomerang');
1026
+ const toggleBoomerang = this.shadow.querySelector('.toggleBoomerang');
1027
1027
  if (toggleBoomerang instanceof HTMLButtonElement) {
1028
1028
  toggleBoomerang.dataset.active = (value === PlayMode.Bounce).toString();
1029
1029
  }
@@ -1094,7 +1094,7 @@ const generator = '@aarsteinmedia/dotlottie-player';
1094
1094
  /**
1095
1095
  * Destroy animation and element.
1096
1096
  */ destroy() {
1097
- if (!this._lottieInstance) {
1097
+ if (!this._lottieInstance?.destroy) {
1098
1098
  return;
1099
1099
  }
1100
1100
  this.playerState = PlayerState.Destroyed;
@@ -1112,12 +1112,10 @@ const generator = '@aarsteinmedia/dotlottie-player';
1112
1112
  this._intersectionObserver.disconnect();
1113
1113
  this._intersectionObserver = undefined;
1114
1114
  }
1115
- // Destroy the animation instance
1116
- if (this._lottieInstance) {
1117
- this._lottieInstance.destroy();
1118
- }
1119
1115
  // Remove the attached Visibility API's change event listener
1120
1116
  document.removeEventListener('visibilitychange', this._onVisibilityChange);
1117
+ // Destroy the animation instance
1118
+ this.destroy();
1121
1119
  }
1122
1120
  /**
1123
1121
  * Returns the lottie-web instance used in the component.
@@ -1158,6 +1156,10 @@ const generator = '@aarsteinmedia/dotlottie-player';
1158
1156
  if (this._multiAnimationSettings.length > 0 && this._multiAnimationSettings[this._currentAnimation]?.mode) {
1159
1157
  this._isBounce = this._multiAnimationSettings[this._currentAnimation].mode === PlayMode.Bounce;
1160
1158
  }
1159
+ if (manifest?.animations.length === 1) {
1160
+ manifest.animations[0].autoplay = this.autoplay;
1161
+ manifest.animations[0].loop = this.loop;
1162
+ }
1161
1163
  this._isDotLottie = Boolean(isDotLottie);
1162
1164
  this._animations = animations;
1163
1165
  this._manifest = manifest ?? {
@@ -1173,15 +1175,12 @@ const generator = '@aarsteinmedia/dotlottie-player';
1173
1175
  ]
1174
1176
  };
1175
1177
  // Clear previous animation, if any
1176
- if (this._lottieInstance) {
1177
- this._lottieInstance.destroy();
1178
- }
1178
+ this._lottieInstance?.destroy();
1179
1179
  this.playerState = PlayerState.Stopped;
1180
1180
  if (!this.animateOnScroll && (this.autoplay || this._multiAnimationSettings[this._currentAnimation]?.autoplay)) {
1181
1181
  this.playerState = PlayerState.Playing;
1182
1182
  }
1183
1183
  // Initialize lottie player and load animation
1184
- // @ts-expect-error TODO:
1185
1184
  this._lottieInstance = Lottie.loadAnimation({
1186
1185
  ...this._getOptions(),
1187
1186
  animationData: animations[this._currentAnimation]
@@ -1258,7 +1257,7 @@ const generator = '@aarsteinmedia/dotlottie-player';
1258
1257
  if (!this.shadow) {
1259
1258
  return;
1260
1259
  }
1261
- const togglePlay = this.shadow.querySelector('.togglePlay'), stop = this.shadow.querySelector('.stop'), prev = this.shadow.querySelector('.prev'), next = this.shadow.querySelector('.next'), seeker = this.shadow.querySelector('.seeker'), progress = this.shadow.querySelector('progress'), popover = this.shadow.querySelector('.popover'), convert = this.shadow.querySelector('.convert');
1260
+ const togglePlay = this.shadow.querySelector('.togglePlay'), stop = this.shadow.querySelector('.stop'), prev = this.shadow.querySelector('.prev'), next = this.shadow.querySelector('.next'), seeker = this.shadow.querySelector('.seeker'), progress = this.shadow.querySelector('progress'), popover = this.shadow.querySelector('.popover'), convert = this.shadow.querySelector('.convert'), snapshot = this.shadow.querySelector('.snapshot');
1262
1261
  if (!(togglePlay instanceof HTMLButtonElement) || !(stop instanceof HTMLButtonElement) || !(next instanceof HTMLButtonElement) || !(prev instanceof HTMLButtonElement) || !(seeker instanceof HTMLInputElement) || !(progress instanceof HTMLProgressElement)) {
1263
1262
  return;
1264
1263
  }
@@ -1280,20 +1279,13 @@ const generator = '@aarsteinmedia/dotlottie-player';
1280
1279
  next.hidden = false;
1281
1280
  }
1282
1281
  if (name === '_currentAnimation' && typeof value === 'number') {
1283
- if (value + 1 >= this._animations.length) {
1284
- next.hidden = true;
1285
- } else {
1286
- next.hidden = false;
1287
- }
1288
- if (value) {
1289
- prev.hidden = false;
1290
- } else {
1291
- prev.hidden = true;
1292
- }
1282
+ next.hidden = value + 1 >= this._animations.length;
1283
+ prev.hidden = Boolean(value);
1293
1284
  }
1294
- if (name === '_isSettingsOpen' && typeof value === 'boolean' && popover instanceof HTMLDivElement && convert instanceof HTMLButtonElement) {
1285
+ if (name === '_isSettingsOpen' && typeof value === 'boolean' && popover instanceof HTMLDivElement && convert instanceof HTMLButtonElement && snapshot instanceof HTMLButtonElement) {
1295
1286
  popover.hidden = !value;
1296
1287
  convert.hidden = this._isDotLottie;
1288
+ snapshot.hidden = this.renderer !== RendererType.SVG;
1297
1289
  }
1298
1290
  }
1299
1291
  /**
@@ -1804,7 +1796,6 @@ const generator = '@aarsteinmedia/dotlottie-player';
1804
1796
  this._lottieInstance.destroy();
1805
1797
  }
1806
1798
  // Re-initialize lottie player
1807
- // @ts-expect-error TODO:
1808
1799
  this._lottieInstance = Lottie.loadAnimation({
1809
1800
  ...this._getOptions(),
1810
1801
  animationData: this._animations[this._currentAnimation]