@aarsteinmedia/dotlottie-player 2.5.8 → 2.5.10

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/dist/cjs/index.js CHANGED
@@ -5,6 +5,8 @@ var decorators_js = require('lit/decorators.js');
5
5
  var Lottie = require('lottie-web');
6
6
  var fflate = require('fflate');
7
7
 
8
+ var name="@aarsteinmedia/dotlottie-player";var version="2.5.10";var description="Web Component for playing Lottie animations in your web app. Previously @johanaarstein/dotlottie-player";var exports$1={".":{"import":"./dist/esm/index.js",node:"./dist/esm/index.js",require:"./dist/cjs/index.js",types:"./dist/index.d.ts"}};var main="./dist/esm/index.js";var unpkg="./dist/index.js";var module$1="./dist/esm/index.js";var types="./dist/index.d.ts";var type="module";var homepage="https://www.aarstein.media/en/dotlottie-player";var repository={url:"https://github.com/aarsteinmedia/dotlottie-player.git",type:"git"};var bugs="https://github.com/aarsteinmedia/dotlottie-player/issues";var author={name:"Johan Martin Aarstein",email:"johan@aarstein.media",url:"https://www.aarstein.media",organization:"Aarstein Media"};var license="GPL-2.0-or-later";var scripts={build:"rimraf ./dist && rollup -c","build:types":"rimraf ./types && tsc","build:cem":"npx cem analyze --config cem.config.mjs",prod:"pnpm build:types && pnpm build && pnpm build:cem",dev:"rollup -c -w --environment NODE_ENV:development",lint:"tsc && eslint . --ext .ts","lint:fix":"eslint . --ext .ts --fix"};var dependencies={fflate:"^0.8.2",lit:"^3.1.3","lottie-web":"^5.12.2"};var peerDependencies={"@types/react":">= 16.0.0"};var devDependencies={"@custom-elements-manifest/analyzer":"^0.9.9","@rollup/plugin-commonjs":"^25.0.8","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^15.2.3","@rollup/plugin-replace":"^5.0.5","@swc/core":"^1.5.24","@types/node":"^20.14.1","@typescript-eslint/eslint-plugin":"^7.12.0","@typescript-eslint/parser":"^7.12.0",autoprefixer:"^10.4.19","esbuild-sass-plugin":"^3.3.0",eslint:"^8.57.0","eslint-import-resolver-typescript":"^3.6.1","eslint-plugin-import":"^2.29.1","eslint-plugin-jsdoc":"^48.2.7","eslint-plugin-lit":"^1.14.0","postcss-flexbugs-fixes":"^5.0.2",rimraf:"^5.0.7",rollup:"^4.18.0","rollup-plugin-dts":"^6.1.1","rollup-plugin-html-literals":"^1.1.8","rollup-plugin-livereload":"^2.0.5","rollup-plugin-postcss":"^4.0.2","rollup-plugin-postcss-lit":"^2.1.0","rollup-plugin-serve":"^1.1.1","rollup-plugin-summary":"^2.0.1","rollup-plugin-swc3":"^0.11.2",sass:"^1.77.4","ts-lit-plugin":"^2.0.2",typescript:"^5.4.5"};var customElements="dist/custom-elements.json";var files=["dist","README.md"];var keywords=["lottie","dotlottie","animation","web component","component","lit-element","svg","vector","player"];var publishConfig={access:"public"};var engines={node:">= 8.17.0"};var funding={type:"paypal",url:"https://www.paypal.com/donate/?hosted_button_id=E7C7DMN8KSQ6A"};var pkg = {name:name,version:version,description:description,exports:exports$1,main:main,unpkg:unpkg,module:module$1,types:types,type:type,homepage:homepage,repository:repository,bugs:bugs,author:author,license:license,scripts:scripts,dependencies:dependencies,peerDependencies:peerDependencies,devDependencies:devDependencies,customElements:customElements,files:files,keywords:keywords,publishConfig:publishConfig,engines:engines,funding:funding};
9
+
8
10
  exports.PlayerState = void 0;
9
11
  (function(PlayerState) {
10
12
  PlayerState["Completed"] = "completed";
@@ -41,9 +43,13 @@ exports.PlayerEvents = void 0;
41
43
  class CustomError extends Error {
42
44
  }
43
45
  const addExt = (ext, str)=>{
44
- if (!str) return;
46
+ if (!str) {
47
+ return;
48
+ }
45
49
  if (getExt(str)) {
46
- if (getExt(str) === ext) return str;
50
+ if (getExt(str) === ext) {
51
+ return str;
52
+ }
47
53
  return `${getFilename(str)}.${ext}`;
48
54
  }
49
55
  return `${str}.${ext}`;
@@ -64,7 +70,7 @@ const addExt = (ext, str)=>{
64
70
  }, base64ToU8 = (str)=>fflate.strToU8(isServer() ? Buffer.from(parseBase64(str), 'base64').toString('binary') : atob(parseBase64(str)), true), createDotLottie = async ({ animations, manifest, fileName, shouldDownload = true })=>{
65
71
  try {
66
72
  if (!animations?.length || !manifest) {
67
- throw new Error(`Missing or malformed required parameter(s):\n ${!animations?.length ? '- animations\n' : ''} ${!manifest ? '- manifest \n' : ''}`);
73
+ throw new Error(`Missing or malformed required parameter(s):\n ${animations?.length ? '- manifest\n' : ''} ${manifest ? '- animations\n' : ''}`);
68
74
  }
69
75
  const name = addExt('lottie', fileName) || `${useId()}.lottie`, dotlottie = {
70
76
  'manifest.json': [
@@ -165,7 +171,11 @@ const addExt = (ext, str)=>{
165
171
  isDotLottie: false
166
172
  };
167
173
  }
168
- const result = await fetch(input);
174
+ const result = await fetch(input, {
175
+ headers: {
176
+ 'Content-Type': 'application/json; charset=UTF-8'
177
+ }
178
+ });
169
179
  if (!result.ok) {
170
180
  const error = new CustomError(result.statusText);
171
181
  error.status = result.status;
@@ -225,7 +235,9 @@ const addExt = (ext, str)=>{
225
235
  });
226
236
  return arrayBuffer;
227
237
  }, getExt = (str)=>{
228
- if (!str || !hasExt(str)) return;
238
+ if (!str || !hasExt(str)) {
239
+ return;
240
+ }
229
241
  const ext = str.split('.').pop()?.toLowerCase();
230
242
  if (ext === 'jpeg') {
231
243
  return 'jpg';
@@ -254,8 +266,12 @@ const addExt = (ext, str)=>{
254
266
  };
255
267
  }, getManifest = (unzipped)=>{
256
268
  const file = fflate.strFromU8(unzipped['manifest.json'], false), manifest = JSON.parse(file);
257
- if (!('animations' in manifest)) throw new Error('Manifest not found');
258
- if (!manifest.animations.length) throw new Error('No animations listed in manifest');
269
+ if (!('animations' in manifest)) {
270
+ throw new Error('Manifest not found');
271
+ }
272
+ if (!manifest.animations.length) {
273
+ throw new Error('No animations listed in manifest');
274
+ }
259
275
  return manifest;
260
276
  }, getMimeFromExt = (ext)=>{
261
277
  switch(ext){
@@ -294,21 +310,27 @@ const addExt = (ext, str)=>{
294
310
  const lastDotIndex = path?.split('/').pop()?.lastIndexOf('.');
295
311
  return (lastDotIndex ?? 0) > 1 && path && path.length - 1 > (lastDotIndex ?? 0);
296
312
  }, isAudio = (asset)=>!('h' in asset) && !('w' in asset) && 'p' in asset && 'e' in asset && 'u' in asset && 'id' in asset, isBase64 = (str)=>{
297
- if (!str) return false;
313
+ if (!str) {
314
+ return false;
315
+ }
298
316
  const regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
299
317
  return regex.test(parseBase64(str));
300
- }, isImage = (asset)=>'w' in asset && 'h' in asset && !('xt' in asset) && 'p' in asset, isServer = ()=>!(typeof window !== 'undefined' && window.document), parseBase64 = (str)=>str.substring(str.indexOf(',') + 1), prepareString = (str)=>{
301
- return str.replace(new RegExp(/"""/, 'g'), '""').replace(/(["'])(.*?)\1/g, (_match, quote, content)=>{
318
+ }, isImage = (asset)=>'w' in asset && 'h' in asset && !('xt' in asset) && 'p' in asset, isServer = ()=>!(typeof window !== 'undefined' && window.document), parseBase64 = (str)=>str.substring(str.indexOf(',') + 1), prepareString = (str)=>str.replace(new RegExp(/"""/, 'g'), '""').replace(/(["'])(.*?)\1/g, (_match, quote, content)=>{
302
319
  const replacedContent = content.replace(/[^\w\s\d.#]/g, '');
303
320
  return `${quote}${replacedContent}${quote}`;
304
- });
305
- }, resolveAssets = async (unzipped, assets)=>{
306
- if (!Array.isArray(assets)) return;
321
+ }), resolveAssets = async (unzipped, assets)=>{
322
+ if (!Array.isArray(assets)) {
323
+ return;
324
+ }
307
325
  const toResolve = [];
308
326
  for (const asset of assets){
309
- if (!isAudio(asset) && !isImage(asset)) continue;
327
+ if (!isAudio(asset) && !isImage(asset)) {
328
+ continue;
329
+ }
310
330
  const type = isImage(asset) ? 'images' : 'audio', u8 = unzipped?.[`${type}/${asset.p}`];
311
- if (!u8) continue;
331
+ if (!u8) {
332
+ continue;
333
+ }
312
334
  toResolve.push(new Promise((resolveAsset)=>{
313
335
  const assetB64 = isServer() ? Buffer.from(u8).toString('base64') : btoa(u8.reduce((dat, byte)=>`${dat}${String.fromCharCode(byte)}`, ''));
314
336
  asset.p = asset.p?.startsWith('data:') || isBase64(asset.p) ? asset.p : `data:${getMimeFromExt(getExt(asset.p))};base64,${assetB64}`;
@@ -329,14 +351,10 @@ const addExt = (ext, str)=>{
329
351
  });
330
352
  return unzipped;
331
353
  }, useId = (prefix)=>{
332
- const s4 = ()=>{
333
- return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
334
- };
354
+ const s4 = ()=>((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
335
355
  return `${prefix ?? `:${s4()}`}-${s4()}`;
336
356
  };
337
357
 
338
- var name="@aarsteinmedia/dotlottie-player";var version="2.5.8";var description="Web Component for playing Lottie animations in your web app. Previously @johanaarstein/dotlottie-player";var exports$1={".":{"import":"./dist/esm/index.js",node:"./dist/esm/index.js",require:"./dist/cjs/index.js",types:"./dist/index.d.ts"}};var main="./dist/esm/index.js";var unpkg="./dist/index.js";var module$1="./dist/esm/index.js";var types="./dist/index.d.ts";var type="module";var homepage="https://www.aarstein.media/en/dotlottie-player";var repository={url:"https://github.com/aarsteinmedia/dotlottie-player.git",type:"git"};var bugs="https://github.com/aarsteinmedia/dotlottie-player/issues";var author={name:"Johan Martin Aarstein",email:"johan@aarstein.media",url:"https://www.aarstein.media",organization:"Aarstein Media"};var license="GPL-2.0-or-later";var scripts={build:"rimraf ./dist && rollup -c","build:types":"rimraf ./types && tsc","build:cem":"npx cem analyze --config cem.config.mjs",prod:"pnpm build:types && pnpm build && pnpm build:cem",dev:"rollup -c -w --environment NODE_ENV:development",lint:"tsc && eslint . --ext .ts","lint:fix":"eslint . --ext .ts --fix"};var dependencies={fflate:"^0.8.2",lit:"^3.1.3","lottie-web":"^5.12.2"};var peerDependencies={"@types/react":">= 16.0.0"};var devDependencies={"@custom-elements-manifest/analyzer":"^0.9.9","@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^15.2.3","@rollup/plugin-replace":"^5.0.5","@swc/core":"^1.5.5","@types/node":"^20.12.11","@typescript-eslint/eslint-plugin":"^7.8.0","@typescript-eslint/parser":"^7.8.0",autoprefixer:"^10.4.19","esbuild-sass-plugin":"^3.2.0",eslint:"^8.57.0","eslint-plugin-lit":"^1.12.0","postcss-flexbugs-fixes":"^5.0.2",rimraf:"^5.0.5",rollup:"^4.17.2","rollup-plugin-dts":"^6.1.0","rollup-plugin-html-literals":"^1.1.8","rollup-plugin-livereload":"^2.0.5","rollup-plugin-postcss":"^4.0.2","rollup-plugin-postcss-lit":"^2.1.0","rollup-plugin-serve":"^1.1.1","rollup-plugin-summary":"^2.0.0","rollup-plugin-swc3":"^0.11.1",sass:"^1.77.0","ts-lit-plugin":"^2.0.2",typescript:"^5.4.5"};var customElements="dist/custom-elements.json";var files=["dist","README.md"];var keywords=["lottie","dotlottie","animation","web component","component","lit-element","svg","vector","player"];var publishConfig={access:"public"};var engines={node:">= 8.17.0"};var funding={type:"paypal",url:"https://www.paypal.com/donate/?hosted_button_id=E7C7DMN8KSQ6A"};var pkg = {name:name,version:version,description:description,exports:exports$1,main:main,unpkg:unpkg,module:module$1,types:types,type:type,homepage:homepage,repository:repository,bugs:bugs,author:author,license:license,scripts:scripts,dependencies:dependencies,peerDependencies:peerDependencies,devDependencies:devDependencies,customElements:customElements,files:files,keywords:keywords,publishConfig:publishConfig,engines:engines,funding:funding};
339
-
340
358
  var css_248z = lit.css`*{box-sizing:border-box}:host{--lottie-player-toolbar-height:35px;--lottie-player-toolbar-background-color:#FFF;--lottie-player-toolbar-icon-color:#000;--lottie-player-toolbar-icon-hover-color:#000;--lottie-player-toolbar-icon-active-color:#4285f4;--lottie-player-seeker-track-color:rgba(0, 0, 0, 0.2);--lottie-player-seeker-thumb-color:#4285f4;--lottie-player-seeker-display:block;display:block;width:100%;height:100%}@media (prefers-color-scheme:dark){:host{--lottie-player-toolbar-background-color:#000;--lottie-player-toolbar-icon-color:#FFF;--lottie-player-toolbar-icon-hover-color:#FFF;--lottie-player-seeker-track-color:rgba(255, 255, 255, 0.6)}}.main{display:flex;flex-direction:column;height:100%;width:100%;margin:0;padding:0}.animation{width:100%;height:100%;display:flex}[data-controls=true] .animation{height:calc(100% - 35px)}.animation-container{position:relative}.popover{position:absolute;right:5px;bottom:40px;background-color:var(--lottie-player-toolbar-background-color);border-radius:5px;padding:10px 15px;border:solid 2px var(--lottie-player-toolbar-icon-color);animation:fadeIn .2s ease-in-out}.popover::before{content:"";right:10px;border:7px solid transparent;border-top-color:transparent;margin-right:-7px;height:0;width:0;position:absolute;pointer-events:none;top:100%;border-top-color:var(--lottie-player-toolbar-icon-color)}.toolbar{display:flex;align-items:center;justify-items:center;background:var(--lottie-player-toolbar-background-color);margin:0;height:35px;padding:5px;border-radius:5px;gap:5px}.toolbar.has-error{pointer-events:none;opacity:.5}.toolbar button{cursor:pointer;fill:var(--lottie-player-toolbar-icon-color);color:var(--lottie-player-toolbar-icon-color);display:flex;background:0 0;border:0;padding:0;outline:0;height:100%;margin:0;align-items:center;gap:5px;opacity:.9}.toolbar button:hover{opacity:1}.toolbar button[data-active=true]{opacity:1;fill:var(--lottie-player-toolbar-icon-active-color)}.toolbar button:disabled{opacity:.5}.toolbar button:focus{outline:0}.toolbar button svg{pointer-events:none}.toolbar button svg>*{fill:inherit}.toolbar button.disabled svg{display:none}.progress-container{position:relative;width:100%}.progress-container.simple{margin-right:12px}.seeker{-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:0}.seeker::-webkit-slider-runnable-track,.seeker::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;outline:0}progress{-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:0}.seeker{width:100%;height:20px;border-radius:3px;border:0;cursor:pointer;background-color:transparent;display:var(--lottie-player-seeker-display);color:var(--lottie-player-seeker-thumb-color);margin:0;padding:7.5px 0;position:relative;z-index:1}progress{position:absolute;width:100%;height:5px;border-radius:3px;border:0;top:0;left:0;margin:7.5px 0;background-color:var(--lottie-player-seeker-track-color);pointer-events:none}::-moz-progress-bar{background-color:var(--lottie-player-seeker-thumb-color)}::-webkit-progress-inner-element{border-radius:3px;overflow:hidden}::-webkit-slider-runnable-track{background-color:transparent}::-webkit-progress-value{background-color:var(--lottie-player-seeker-thumb-color)}.seeker::-webkit-slider-thumb{height:15px;width:15px;border-radius:50%;border:0;background-color:var(--lottie-player-seeker-thumb-color);cursor:pointer;-webkit-transition:transform .2s ease-in-out;transition:transform .2s ease-in-out;transform:scale(0)}.seeker:focus::-webkit-slider-thumb,.seeker:hover::-webkit-slider-thumb{transform:scale(1)}.seeker::-moz-range-progress{background-color:var(--lottie-player-seeker-thumb-color);height:5px;border-radius:3px}.seeker::-moz-range-thumb{height:15px;width:15px;border-radius:50%;background-color:var(--lottie-player-seeker-thumb-color);border:0;cursor:pointer;-moz-transition:transform .2s ease-in-out;transition:transform .2s ease-in-out;transform:scale(0)}.seeker:focus::-moz-range-thumb,.seeker:hover::-moz-range-thumb{transform:scale(1)}.seeker::-ms-track{width:100%;height:5px;cursor:pointer;background:0 0;border-color:transparent;color:transparent}.seeker::-ms-fill-upper{background:var(--lottie-player-seeker-track-color);border-radius:3px}.seeker::-ms-fill-lower{background-color:var(--lottie-player-seeker-thumb-color);border-radius:3px}.seeker::-ms-thumb{border:0;height:15px;width:15px;border-radius:50%;background:var(--lottie-player-seeker-thumb-color);cursor:pointer;-ms-transition:transform .2s ease-in-out;transition:transform .2s ease-in-out;transform:scale(0)}.seeker:hover::-ms-thumb{transform:scale(1)}.seeker:focus::-ms-thumb{transform:scale(1)}.seeker:focus::-ms-fill-lower,.seeker:focus::-ms-fill-upper{background:var(--lottie-player-seeker-track-color)}.error{display:flex;margin:auto;justify-content:center;height:100%;align-items:center}.error svg{width:100%;height:auto}@keyframes fadeIn{0%{opacity:0}100%{opacity:1}}`;
341
359
 
342
360
  function _ts_decorate(decorators, target, key, desc) {
@@ -347,10 +365,35 @@ function _ts_decorate(decorators, target, key, desc) {
347
365
  }
348
366
  class DotLottiePlayer extends lit.LitElement {
349
367
  _getOptions() {
350
- const preserveAspectRatio = this.preserveAspectRatio ?? (this.objectfit && aspectRatio(this.objectfit)), currentAnimationSettings = this.multiAnimationSettings?.[this._currentAnimation], currentAnimationManifest = this._manifest.animations?.[this._currentAnimation], loop = currentAnimationSettings?.loop !== undefined ? !!currentAnimationSettings.loop : this.loop !== undefined ? !!this.loop : currentAnimationManifest.loop !== undefined && !!currentAnimationManifest.loop, autoplay = !this.animateOnScroll && (currentAnimationSettings?.autoplay !== undefined ? !!currentAnimationSettings.autoplay : this.autoplay !== undefined ? !!this.autoplay : currentAnimationManifest.autoplay !== undefined && !!currentAnimationManifest.autoplay), initialSegment = !this.segment || this.segment.some((val)=>val < 0) ? undefined : this.segment.every((val)=>val > 0) ? [
351
- this.segment[0] - 1,
352
- this.segment[1] - 1
353
- ] : this.segment, options = {
368
+ const preserveAspectRatio = this.preserveAspectRatio ?? (this.objectfit && aspectRatio(this.objectfit)), currentAnimationSettings = this.multiAnimationSettings?.length ? this.multiAnimationSettings?.[this._currentAnimation] : undefined, currentAnimationManifest = this._manifest.animations?.[this._currentAnimation];
369
+ let loop = !!this.loop;
370
+ if (currentAnimationManifest.loop !== undefined) {
371
+ loop = !!currentAnimationManifest.loop;
372
+ }
373
+ if (currentAnimationSettings?.loop !== undefined) {
374
+ loop = !!currentAnimationSettings.loop;
375
+ }
376
+ let autoplay = !!this.autoplay;
377
+ if (currentAnimationManifest.autoplay !== undefined) {
378
+ autoplay = !!currentAnimationManifest.autoplay;
379
+ }
380
+ if (currentAnimationSettings?.autoplay !== undefined) {
381
+ autoplay = !!currentAnimationSettings.autoplay;
382
+ }
383
+ if (this.animateOnScroll) {
384
+ autoplay = false;
385
+ }
386
+ let initialSegment = this.segment;
387
+ if (this.segment?.every((val)=>val > 0)) {
388
+ initialSegment = [
389
+ this.segment[0] - 1,
390
+ this.segment[1] - 1
391
+ ];
392
+ }
393
+ if (this.segment?.some((val)=>val < 0)) {
394
+ initialSegment = undefined;
395
+ }
396
+ const options = {
354
397
  container: this.container,
355
398
  loop,
356
399
  autoplay,
@@ -410,13 +453,20 @@ class DotLottiePlayer extends lit.LitElement {
410
453
  this._intersectionObserver.observe(this.container);
411
454
  }
412
455
  async load(src) {
413
- if (!this.shadowRoot) return;
456
+ if (!this.shadowRoot) {
457
+ return;
458
+ }
414
459
  try {
415
460
  const { animations, manifest, isDotLottie } = await getAnimationData(src);
416
461
  if (!animations || animations.some((animation)=>!this._isLottie(animation))) {
417
462
  throw new Error('Broken or corrupted file');
418
463
  }
419
- this._isBounce = this.multiAnimationSettings?.[this._currentAnimation]?.mode !== undefined ? this.multiAnimationSettings?.[this._currentAnimation]?.mode === exports.PlayMode.Bounce : this.mode === exports.PlayMode.Bounce;
464
+ this._isBounce = this.mode === exports.PlayMode.Bounce;
465
+ if (this.multiAnimationSettings?.length) {
466
+ if (this.multiAnimationSettings[this._currentAnimation]?.mode) {
467
+ this._isBounce = this.multiAnimationSettings[this._currentAnimation].mode === exports.PlayMode.Bounce;
468
+ }
469
+ }
420
470
  this._isDotLottie = !!isDotLottie;
421
471
  this._animations = animations;
422
472
  this._manifest = manifest ?? {
@@ -431,8 +481,13 @@ class DotLottiePlayer extends lit.LitElement {
431
481
  }
432
482
  ]
433
483
  };
434
- if (this._lottieInstance) this._lottieInstance.destroy();
435
- this.currentState = this.autoplay && !this.animateOnScroll ? exports.PlayerState.Playing : exports.PlayerState.Stopped;
484
+ if (this._lottieInstance) {
485
+ this._lottieInstance.destroy();
486
+ }
487
+ this.currentState = exports.PlayerState.Stopped;
488
+ if (!this.animateOnScroll && (this.autoplay || this.multiAnimationSettings?.[this._currentAnimation]?.autoplay)) {
489
+ this.currentState = exports.PlayerState.Playing;
490
+ }
436
491
  this._lottieInstance = Lottie.loadAnimation({
437
492
  ...this._getOptions(),
438
493
  animationData: animations[this._currentAnimation]
@@ -449,20 +504,25 @@ class DotLottiePlayer extends lit.LitElement {
449
504
  this.setDirection(direction);
450
505
  this.setSubframe(!!this.subframe);
451
506
  if (this.autoplay || this.animateOnScroll) {
452
- if (this.direction === -1) this.seek('99%');
507
+ if (this.direction === -1) {
508
+ this.seek('99%');
509
+ }
453
510
  if (!('IntersectionObserver' in window)) {
454
- !this.animateOnScroll && this.play();
511
+ if (!this.animateOnScroll) {
512
+ this.play();
513
+ }
455
514
  this._playerState.visible = true;
456
515
  }
457
516
  this._addIntersectionObserver();
458
- return;
459
517
  }
460
518
  }
461
519
  getManifest() {
462
520
  return this._manifest;
463
521
  }
464
522
  _addEventListeners() {
465
- if (!this._lottieInstance) return;
523
+ if (!this._lottieInstance) {
524
+ return;
525
+ }
466
526
  this._lottieInstance.addEventListener('enterFrame', this._enterFrame);
467
527
  this._lottieInstance.addEventListener('complete', this._complete);
468
528
  this._lottieInstance.addEventListener('loopComplete', this._loopComplete);
@@ -489,7 +549,9 @@ class DotLottiePlayer extends lit.LitElement {
489
549
  }
490
550
  }
491
551
  _removeEventListeners() {
492
- if (!this._lottieInstance || !this.container) return;
552
+ if (!this._lottieInstance || !this.container) {
553
+ return;
554
+ }
493
555
  this._lottieInstance.removeEventListener('enterFrame', this._enterFrame);
494
556
  this._lottieInstance.removeEventListener('complete', this._complete);
495
557
  this._lottieInstance.removeEventListener('loopComplete', this._loopComplete);
@@ -508,7 +570,11 @@ class DotLottiePlayer extends lit.LitElement {
508
570
  }
509
571
  const { totalFrames, playDirection } = this._lottieInstance, inPoint = this.segment ? this.segment[0] : 0, outPoint = this.segment ? this.segment[0] : totalFrames;
510
572
  if (this.count) {
511
- this._isBounce ? this._playerState.count += 0.5 : this._playerState.count += 1;
573
+ if (this._isBounce) {
574
+ this._playerState.count += 0.5;
575
+ } else {
576
+ this._playerState.count += 1;
577
+ }
512
578
  if (this._playerState.count >= this.count) {
513
579
  this.setLooping(false);
514
580
  this.currentState = exports.PlayerState.Completed;
@@ -521,12 +587,16 @@ class DotLottiePlayer extends lit.LitElement {
521
587
  this._lottieInstance.goToAndStop(playDirection === -1 ? inPoint : outPoint * 0.99, true);
522
588
  this._lottieInstance.setDirection(playDirection * -1);
523
589
  return setTimeout(()=>{
524
- !this.animateOnScroll && this._lottieInstance?.play();
590
+ if (!this.animateOnScroll) {
591
+ this._lottieInstance?.play();
592
+ }
525
593
  }, this.intermission);
526
594
  }
527
595
  this._lottieInstance.goToAndStop(playDirection === -1 ? outPoint * 0.99 : inPoint, true);
528
596
  return setTimeout(()=>{
529
- !this.animateOnScroll && this._lottieInstance?.play();
597
+ if (!this.animateOnScroll) {
598
+ this._lottieInstance?.play();
599
+ }
530
600
  }, this.intermission);
531
601
  }
532
602
  _enterFrame() {
@@ -546,8 +616,14 @@ class DotLottiePlayer extends lit.LitElement {
546
616
  if (!this._lottieInstance) {
547
617
  return;
548
618
  }
549
- if (this._animations.length > 1 && this.multiAnimationSettings?.[this._currentAnimation + 1]?.autoplay) {
550
- return this.next();
619
+ if (this._animations.length > 1) {
620
+ if (this.multiAnimationSettings?.[this._currentAnimation + 1]?.autoplay) {
621
+ return this.next();
622
+ }
623
+ if (this.loop && this._currentAnimation === this._animations.length - 1) {
624
+ this._currentAnimation = 0;
625
+ return this._switchInstance();
626
+ }
551
627
  }
552
628
  const { currentFrame, totalFrames } = this._lottieInstance;
553
629
  this._seeker = Math.floor(currentFrame / totalFrames * 100);
@@ -623,7 +699,9 @@ class DotLottiePlayer extends lit.LitElement {
623
699
  }, 400);
624
700
  }
625
701
  _handleSeekChange({ target }) {
626
- if (!(target instanceof HTMLInputElement) || !this._lottieInstance || isNaN(Number(target.value))) return;
702
+ if (!(target instanceof HTMLInputElement) || !this._lottieInstance || isNaN(Number(target.value))) {
703
+ return;
704
+ }
627
705
  this.seek(Math.floor(Number(target.value) / 100 * this._lottieInstance.totalFrames));
628
706
  setTimeout(()=>{
629
707
  if (target.parentElement instanceof HTMLFormElement) {
@@ -683,7 +761,9 @@ class DotLottiePlayer extends lit.LitElement {
683
761
  return this._lottieInstance;
684
762
  }
685
763
  play() {
686
- if (!this._lottieInstance) return;
764
+ if (!this._lottieInstance) {
765
+ return;
766
+ }
687
767
  if (this.currentState) {
688
768
  this._playerState.prev = this.currentState;
689
769
  }
@@ -694,7 +774,9 @@ class DotLottiePlayer extends lit.LitElement {
694
774
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Play));
695
775
  }
696
776
  pause() {
697
- if (!this._lottieInstance) return;
777
+ if (!this._lottieInstance) {
778
+ return;
779
+ }
698
780
  if (this.currentState) {
699
781
  this._playerState.prev = this.currentState;
700
782
  }
@@ -705,7 +787,9 @@ class DotLottiePlayer extends lit.LitElement {
705
787
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Pause));
706
788
  }
707
789
  stop() {
708
- if (!this._lottieInstance) return;
790
+ if (!this._lottieInstance) {
791
+ return;
792
+ }
709
793
  if (this.currentState) {
710
794
  this._playerState.prev = this.currentState;
711
795
  }
@@ -717,7 +801,9 @@ class DotLottiePlayer extends lit.LitElement {
717
801
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Stop));
718
802
  }
719
803
  destroy() {
720
- if (!this._lottieInstance) return;
804
+ if (!this._lottieInstance) {
805
+ return;
806
+ }
721
807
  this.currentState = exports.PlayerState.Destroyed;
722
808
  this._lottieInstance.destroy();
723
809
  this._lottieInstance = null;
@@ -726,7 +812,9 @@ class DotLottiePlayer extends lit.LitElement {
726
812
  document.removeEventListener('visibilitychange', this._onVisibilityChange);
727
813
  }
728
814
  seek(value) {
729
- if (!this._lottieInstance) return;
815
+ if (!this._lottieInstance) {
816
+ return;
817
+ }
730
818
  const matches = value.toString().match(/^([0-9]+)(%?)$/);
731
819
  if (!matches) {
732
820
  return;
@@ -742,7 +830,9 @@ class DotLottiePlayer extends lit.LitElement {
742
830
  this._lottieInstance.pause();
743
831
  }
744
832
  snapshot() {
745
- if (!this.shadowRoot) return;
833
+ if (!this.shadowRoot) {
834
+ return;
835
+ }
746
836
  const svgElement = this.shadowRoot.querySelector('.animation svg'), data = svgElement instanceof Node ? new XMLSerializer().serializeToString(svgElement) : null;
747
837
  if (!data) {
748
838
  console.error('Could not serialize data');
@@ -755,16 +845,22 @@ class DotLottiePlayer extends lit.LitElement {
755
845
  return data;
756
846
  }
757
847
  setSubframe(value) {
758
- if (!this._lottieInstance) return;
848
+ if (!this._lottieInstance) {
849
+ return;
850
+ }
759
851
  this.subframe = value;
760
852
  this._lottieInstance.setSubframe(value);
761
853
  }
762
854
  setCount(value) {
763
- if (!this._lottieInstance) return;
855
+ if (!this._lottieInstance) {
856
+ return;
857
+ }
764
858
  this.count = value;
765
859
  }
766
860
  _freeze() {
767
- if (!this._lottieInstance) return;
861
+ if (!this._lottieInstance) {
862
+ return;
863
+ }
768
864
  if (this.currentState) {
769
865
  this._playerState.prev = this.currentState;
770
866
  }
@@ -775,19 +871,25 @@ class DotLottiePlayer extends lit.LitElement {
775
871
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Freeze));
776
872
  }
777
873
  async reload() {
778
- if (!this._lottieInstance) return;
874
+ if (!this._lottieInstance) {
875
+ return;
876
+ }
779
877
  this._lottieInstance.destroy();
780
878
  if (this.src) {
781
879
  await this.load(this.src);
782
880
  }
783
881
  }
784
882
  setSpeed(value = 1) {
785
- if (!this._lottieInstance) return;
883
+ if (!this._lottieInstance) {
884
+ return;
885
+ }
786
886
  this.speed = value;
787
887
  this._lottieInstance.setSpeed(value);
788
888
  }
789
889
  setDirection(value) {
790
- if (!this._lottieInstance) return;
890
+ if (!this._lottieInstance) {
891
+ return;
892
+ }
791
893
  this.direction = value;
792
894
  this._lottieInstance.setDirection(value);
793
895
  }
@@ -805,7 +907,9 @@ class DotLottiePlayer extends lit.LitElement {
805
907
  this.multiAnimationSettings = settings;
806
908
  }
807
909
  togglePlay() {
808
- if (!this._lottieInstance) return;
910
+ if (!this._lottieInstance) {
911
+ return;
912
+ }
809
913
  const { currentFrame, playDirection, totalFrames } = this._lottieInstance;
810
914
  if (this.currentState === exports.PlayerState.Playing) {
811
915
  return this.pause();
@@ -857,9 +961,13 @@ class DotLottiePlayer extends lit.LitElement {
857
961
  setTimeout(()=>this._toggleSettings(false), 200);
858
962
  }
859
963
  _switchInstance(isPrevious = false) {
860
- if (!this._animations[this._currentAnimation]) return;
964
+ if (!this._animations[this._currentAnimation]) {
965
+ return;
966
+ }
861
967
  try {
862
- if (this._lottieInstance) this._lottieInstance.destroy();
968
+ if (this._lottieInstance) {
969
+ this._lottieInstance.destroy();
970
+ }
863
971
  this._lottieInstance = Lottie.loadAnimation({
864
972
  ...this._getOptions(),
865
973
  animationData: this._animations[this._currentAnimation]
@@ -936,7 +1044,9 @@ class DotLottiePlayer extends lit.LitElement {
936
1044
  this._intersectionObserver.disconnect();
937
1045
  this._intersectionObserver = undefined;
938
1046
  }
939
- if (this._lottieInstance) this._lottieInstance.destroy();
1047
+ if (this._lottieInstance) {
1048
+ this._lottieInstance.destroy();
1049
+ }
940
1050
  document.removeEventListener('visibilitychange', this._onVisibilityChange);
941
1051
  }
942
1052
  renderControls() {