@aarsteinmedia/dotlottie-player 2.5.9 → 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': [
@@ -229,7 +235,9 @@ const addExt = (ext, str)=>{
229
235
  });
230
236
  return arrayBuffer;
231
237
  }, getExt = (str)=>{
232
- if (!str || !hasExt(str)) return;
238
+ if (!str || !hasExt(str)) {
239
+ return;
240
+ }
233
241
  const ext = str.split('.').pop()?.toLowerCase();
234
242
  if (ext === 'jpeg') {
235
243
  return 'jpg';
@@ -258,8 +266,12 @@ const addExt = (ext, str)=>{
258
266
  };
259
267
  }, getManifest = (unzipped)=>{
260
268
  const file = fflate.strFromU8(unzipped['manifest.json'], false), manifest = JSON.parse(file);
261
- if (!('animations' in manifest)) throw new Error('Manifest not found');
262
- 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
+ }
263
275
  return manifest;
264
276
  }, getMimeFromExt = (ext)=>{
265
277
  switch(ext){
@@ -298,21 +310,27 @@ const addExt = (ext, str)=>{
298
310
  const lastDotIndex = path?.split('/').pop()?.lastIndexOf('.');
299
311
  return (lastDotIndex ?? 0) > 1 && path && path.length - 1 > (lastDotIndex ?? 0);
300
312
  }, isAudio = (asset)=>!('h' in asset) && !('w' in asset) && 'p' in asset && 'e' in asset && 'u' in asset && 'id' in asset, isBase64 = (str)=>{
301
- if (!str) return false;
313
+ if (!str) {
314
+ return false;
315
+ }
302
316
  const regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
303
317
  return regex.test(parseBase64(str));
304
- }, 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)=>{
305
- 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)=>{
306
319
  const replacedContent = content.replace(/[^\w\s\d.#]/g, '');
307
320
  return `${quote}${replacedContent}${quote}`;
308
- });
309
- }, resolveAssets = async (unzipped, assets)=>{
310
- if (!Array.isArray(assets)) return;
321
+ }), resolveAssets = async (unzipped, assets)=>{
322
+ if (!Array.isArray(assets)) {
323
+ return;
324
+ }
311
325
  const toResolve = [];
312
326
  for (const asset of assets){
313
- if (!isAudio(asset) && !isImage(asset)) continue;
327
+ if (!isAudio(asset) && !isImage(asset)) {
328
+ continue;
329
+ }
314
330
  const type = isImage(asset) ? 'images' : 'audio', u8 = unzipped?.[`${type}/${asset.p}`];
315
- if (!u8) continue;
331
+ if (!u8) {
332
+ continue;
333
+ }
316
334
  toResolve.push(new Promise((resolveAsset)=>{
317
335
  const assetB64 = isServer() ? Buffer.from(u8).toString('base64') : btoa(u8.reduce((dat, byte)=>`${dat}${String.fromCharCode(byte)}`, ''));
318
336
  asset.p = asset.p?.startsWith('data:') || isBase64(asset.p) ? asset.p : `data:${getMimeFromExt(getExt(asset.p))};base64,${assetB64}`;
@@ -333,14 +351,10 @@ const addExt = (ext, str)=>{
333
351
  });
334
352
  return unzipped;
335
353
  }, useId = (prefix)=>{
336
- const s4 = ()=>{
337
- return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
338
- };
354
+ const s4 = ()=>((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
339
355
  return `${prefix ?? `:${s4()}`}-${s4()}`;
340
356
  };
341
357
 
342
- var name="@aarsteinmedia/dotlottie-player";var version="2.5.9";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.7","@types/node":"^20.12.12","@typescript-eslint/eslint-plugin":"^7.9.0","@typescript-eslint/parser":"^7.9.0",autoprefixer:"^10.4.19","esbuild-sass-plugin":"^3.2.0",eslint:"^8.57.0","eslint-plugin-lit":"^1.13.0","postcss-flexbugs-fixes":"^5.0.2",rimraf:"^5.0.7",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.2",sass:"^1.77.1","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};
343
-
344
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}}`;
345
359
 
346
360
  function _ts_decorate(decorators, target, key, desc) {
@@ -351,10 +365,35 @@ function _ts_decorate(decorators, target, key, desc) {
351
365
  }
352
366
  class DotLottiePlayer extends lit.LitElement {
353
367
  _getOptions() {
354
- 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) ? [
355
- this.segment[0] - 1,
356
- this.segment[1] - 1
357
- ] : 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 = {
358
397
  container: this.container,
359
398
  loop,
360
399
  autoplay,
@@ -414,13 +453,20 @@ class DotLottiePlayer extends lit.LitElement {
414
453
  this._intersectionObserver.observe(this.container);
415
454
  }
416
455
  async load(src) {
417
- if (!this.shadowRoot) return;
456
+ if (!this.shadowRoot) {
457
+ return;
458
+ }
418
459
  try {
419
460
  const { animations, manifest, isDotLottie } = await getAnimationData(src);
420
461
  if (!animations || animations.some((animation)=>!this._isLottie(animation))) {
421
462
  throw new Error('Broken or corrupted file');
422
463
  }
423
- 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
+ }
424
470
  this._isDotLottie = !!isDotLottie;
425
471
  this._animations = animations;
426
472
  this._manifest = manifest ?? {
@@ -435,8 +481,13 @@ class DotLottiePlayer extends lit.LitElement {
435
481
  }
436
482
  ]
437
483
  };
438
- if (this._lottieInstance) this._lottieInstance.destroy();
439
- this.currentState = (this.autoplay || this.multiAnimationSettings?.[this._currentAnimation].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
+ }
440
491
  this._lottieInstance = Lottie.loadAnimation({
441
492
  ...this._getOptions(),
442
493
  animationData: animations[this._currentAnimation]
@@ -453,20 +504,25 @@ class DotLottiePlayer extends lit.LitElement {
453
504
  this.setDirection(direction);
454
505
  this.setSubframe(!!this.subframe);
455
506
  if (this.autoplay || this.animateOnScroll) {
456
- if (this.direction === -1) this.seek('99%');
507
+ if (this.direction === -1) {
508
+ this.seek('99%');
509
+ }
457
510
  if (!('IntersectionObserver' in window)) {
458
- !this.animateOnScroll && this.play();
511
+ if (!this.animateOnScroll) {
512
+ this.play();
513
+ }
459
514
  this._playerState.visible = true;
460
515
  }
461
516
  this._addIntersectionObserver();
462
- return;
463
517
  }
464
518
  }
465
519
  getManifest() {
466
520
  return this._manifest;
467
521
  }
468
522
  _addEventListeners() {
469
- if (!this._lottieInstance) return;
523
+ if (!this._lottieInstance) {
524
+ return;
525
+ }
470
526
  this._lottieInstance.addEventListener('enterFrame', this._enterFrame);
471
527
  this._lottieInstance.addEventListener('complete', this._complete);
472
528
  this._lottieInstance.addEventListener('loopComplete', this._loopComplete);
@@ -493,7 +549,9 @@ class DotLottiePlayer extends lit.LitElement {
493
549
  }
494
550
  }
495
551
  _removeEventListeners() {
496
- if (!this._lottieInstance || !this.container) return;
552
+ if (!this._lottieInstance || !this.container) {
553
+ return;
554
+ }
497
555
  this._lottieInstance.removeEventListener('enterFrame', this._enterFrame);
498
556
  this._lottieInstance.removeEventListener('complete', this._complete);
499
557
  this._lottieInstance.removeEventListener('loopComplete', this._loopComplete);
@@ -512,7 +570,11 @@ class DotLottiePlayer extends lit.LitElement {
512
570
  }
513
571
  const { totalFrames, playDirection } = this._lottieInstance, inPoint = this.segment ? this.segment[0] : 0, outPoint = this.segment ? this.segment[0] : totalFrames;
514
572
  if (this.count) {
515
- 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
+ }
516
578
  if (this._playerState.count >= this.count) {
517
579
  this.setLooping(false);
518
580
  this.currentState = exports.PlayerState.Completed;
@@ -525,12 +587,16 @@ class DotLottiePlayer extends lit.LitElement {
525
587
  this._lottieInstance.goToAndStop(playDirection === -1 ? inPoint : outPoint * 0.99, true);
526
588
  this._lottieInstance.setDirection(playDirection * -1);
527
589
  return setTimeout(()=>{
528
- !this.animateOnScroll && this._lottieInstance?.play();
590
+ if (!this.animateOnScroll) {
591
+ this._lottieInstance?.play();
592
+ }
529
593
  }, this.intermission);
530
594
  }
531
595
  this._lottieInstance.goToAndStop(playDirection === -1 ? outPoint * 0.99 : inPoint, true);
532
596
  return setTimeout(()=>{
533
- !this.animateOnScroll && this._lottieInstance?.play();
597
+ if (!this.animateOnScroll) {
598
+ this._lottieInstance?.play();
599
+ }
534
600
  }, this.intermission);
535
601
  }
536
602
  _enterFrame() {
@@ -633,7 +699,9 @@ class DotLottiePlayer extends lit.LitElement {
633
699
  }, 400);
634
700
  }
635
701
  _handleSeekChange({ target }) {
636
- 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
+ }
637
705
  this.seek(Math.floor(Number(target.value) / 100 * this._lottieInstance.totalFrames));
638
706
  setTimeout(()=>{
639
707
  if (target.parentElement instanceof HTMLFormElement) {
@@ -693,7 +761,9 @@ class DotLottiePlayer extends lit.LitElement {
693
761
  return this._lottieInstance;
694
762
  }
695
763
  play() {
696
- if (!this._lottieInstance) return;
764
+ if (!this._lottieInstance) {
765
+ return;
766
+ }
697
767
  if (this.currentState) {
698
768
  this._playerState.prev = this.currentState;
699
769
  }
@@ -704,7 +774,9 @@ class DotLottiePlayer extends lit.LitElement {
704
774
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Play));
705
775
  }
706
776
  pause() {
707
- if (!this._lottieInstance) return;
777
+ if (!this._lottieInstance) {
778
+ return;
779
+ }
708
780
  if (this.currentState) {
709
781
  this._playerState.prev = this.currentState;
710
782
  }
@@ -715,7 +787,9 @@ class DotLottiePlayer extends lit.LitElement {
715
787
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Pause));
716
788
  }
717
789
  stop() {
718
- if (!this._lottieInstance) return;
790
+ if (!this._lottieInstance) {
791
+ return;
792
+ }
719
793
  if (this.currentState) {
720
794
  this._playerState.prev = this.currentState;
721
795
  }
@@ -727,7 +801,9 @@ class DotLottiePlayer extends lit.LitElement {
727
801
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Stop));
728
802
  }
729
803
  destroy() {
730
- if (!this._lottieInstance) return;
804
+ if (!this._lottieInstance) {
805
+ return;
806
+ }
731
807
  this.currentState = exports.PlayerState.Destroyed;
732
808
  this._lottieInstance.destroy();
733
809
  this._lottieInstance = null;
@@ -736,7 +812,9 @@ class DotLottiePlayer extends lit.LitElement {
736
812
  document.removeEventListener('visibilitychange', this._onVisibilityChange);
737
813
  }
738
814
  seek(value) {
739
- if (!this._lottieInstance) return;
815
+ if (!this._lottieInstance) {
816
+ return;
817
+ }
740
818
  const matches = value.toString().match(/^([0-9]+)(%?)$/);
741
819
  if (!matches) {
742
820
  return;
@@ -752,7 +830,9 @@ class DotLottiePlayer extends lit.LitElement {
752
830
  this._lottieInstance.pause();
753
831
  }
754
832
  snapshot() {
755
- if (!this.shadowRoot) return;
833
+ if (!this.shadowRoot) {
834
+ return;
835
+ }
756
836
  const svgElement = this.shadowRoot.querySelector('.animation svg'), data = svgElement instanceof Node ? new XMLSerializer().serializeToString(svgElement) : null;
757
837
  if (!data) {
758
838
  console.error('Could not serialize data');
@@ -765,16 +845,22 @@ class DotLottiePlayer extends lit.LitElement {
765
845
  return data;
766
846
  }
767
847
  setSubframe(value) {
768
- if (!this._lottieInstance) return;
848
+ if (!this._lottieInstance) {
849
+ return;
850
+ }
769
851
  this.subframe = value;
770
852
  this._lottieInstance.setSubframe(value);
771
853
  }
772
854
  setCount(value) {
773
- if (!this._lottieInstance) return;
855
+ if (!this._lottieInstance) {
856
+ return;
857
+ }
774
858
  this.count = value;
775
859
  }
776
860
  _freeze() {
777
- if (!this._lottieInstance) return;
861
+ if (!this._lottieInstance) {
862
+ return;
863
+ }
778
864
  if (this.currentState) {
779
865
  this._playerState.prev = this.currentState;
780
866
  }
@@ -785,19 +871,25 @@ class DotLottiePlayer extends lit.LitElement {
785
871
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Freeze));
786
872
  }
787
873
  async reload() {
788
- if (!this._lottieInstance) return;
874
+ if (!this._lottieInstance) {
875
+ return;
876
+ }
789
877
  this._lottieInstance.destroy();
790
878
  if (this.src) {
791
879
  await this.load(this.src);
792
880
  }
793
881
  }
794
882
  setSpeed(value = 1) {
795
- if (!this._lottieInstance) return;
883
+ if (!this._lottieInstance) {
884
+ return;
885
+ }
796
886
  this.speed = value;
797
887
  this._lottieInstance.setSpeed(value);
798
888
  }
799
889
  setDirection(value) {
800
- if (!this._lottieInstance) return;
890
+ if (!this._lottieInstance) {
891
+ return;
892
+ }
801
893
  this.direction = value;
802
894
  this._lottieInstance.setDirection(value);
803
895
  }
@@ -815,7 +907,9 @@ class DotLottiePlayer extends lit.LitElement {
815
907
  this.multiAnimationSettings = settings;
816
908
  }
817
909
  togglePlay() {
818
- if (!this._lottieInstance) return;
910
+ if (!this._lottieInstance) {
911
+ return;
912
+ }
819
913
  const { currentFrame, playDirection, totalFrames } = this._lottieInstance;
820
914
  if (this.currentState === exports.PlayerState.Playing) {
821
915
  return this.pause();
@@ -867,9 +961,13 @@ class DotLottiePlayer extends lit.LitElement {
867
961
  setTimeout(()=>this._toggleSettings(false), 200);
868
962
  }
869
963
  _switchInstance(isPrevious = false) {
870
- if (!this._animations[this._currentAnimation]) return;
964
+ if (!this._animations[this._currentAnimation]) {
965
+ return;
966
+ }
871
967
  try {
872
- if (this._lottieInstance) this._lottieInstance.destroy();
968
+ if (this._lottieInstance) {
969
+ this._lottieInstance.destroy();
970
+ }
873
971
  this._lottieInstance = Lottie.loadAnimation({
874
972
  ...this._getOptions(),
875
973
  animationData: this._animations[this._currentAnimation]
@@ -946,7 +1044,9 @@ class DotLottiePlayer extends lit.LitElement {
946
1044
  this._intersectionObserver.disconnect();
947
1045
  this._intersectionObserver = undefined;
948
1046
  }
949
- if (this._lottieInstance) this._lottieInstance.destroy();
1047
+ if (this._lottieInstance) {
1048
+ this._lottieInstance.destroy();
1049
+ }
950
1050
  document.removeEventListener('visibilitychange', this._onVisibilityChange);
951
1051
  }
952
1052
  renderControls() {