@aarsteinmedia/dotlottie-player 2.1.7 → 2.2.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/dist/cjs/index.js CHANGED
@@ -38,7 +38,6 @@ exports.PlayerEvents = void 0;
38
38
  })(exports.PlayerEvents || (exports.PlayerEvents = {}));
39
39
  class CustomError extends Error {
40
40
  }
41
-
42
41
  const addExt = (ext, str)=>{
43
42
  if (!str) return;
44
43
  if (getExt(str)) {
@@ -60,20 +59,10 @@ const addExt = (ext, str)=>{
60
59
  default:
61
60
  return 'xMidYMid meet';
62
61
  }
63
- }, /**
64
- * Convert Base64 encoded string to Uint8Array
65
- * @param { string } str Base64 encoded string
66
- * @returns { Uint8Array} UTF-8/Latin-1 binary
67
- */ base64ToU8 = (str)=>{
62
+ }, base64ToU8 = (str)=>{
68
63
  const parsedStr = str.substring(str.indexOf(',') + 1);
69
64
  return strToU8(isServer() ? Buffer.from(parsedStr, 'base64').toString('binary') : atob(parsedStr));
70
- }, /**
71
- * Convert a JSON Lottie to dotLottie or combine several animations and download new dotLottie file in your browser.
72
- * @param { LottieJSON[] } animations The animations to combine.
73
- * @param { LottieManifest } manifest Manifest of meta information.
74
- * @param { string } filename Name of file to download. If not specified a random string will be generated.
75
- * @param { boolean } triggerDownload Whether to trigger a download in the browser. Defaults to true.
76
- */ createDotLottie = async (animations, manifest, filename, triggerDownload = true)=>{
65
+ }, createDotLottie = async (animations, manifest, filename, triggerDownload = true)=>{
77
66
  try {
78
67
  if (!animations?.length || !manifest) {
79
68
  throw new Error(`Missing or malformed required parameter(s):\n ${!animations?.length ? '- animations\n' : ''} ${!manifest ? '- manifest \n' : ''}`);
@@ -118,11 +107,7 @@ const addExt = (ext, str)=>{
118
107
  } catch (err) {
119
108
  console.error(`❌ ${handleErrors(err).message}`);
120
109
  }
121
- }, /**
122
- * Download file, either SVG or dotLottie.
123
- * @param { string } data The data to be downloaded
124
- * @param { string } name Don't include file extension in the filename
125
- */ download = (data, options)=>{
110
+ }, download = (data, options)=>{
126
111
  const blob = new Blob([
127
112
  data
128
113
  ], {
@@ -173,11 +158,7 @@ const addExt = (ext, str)=>{
173
158
  error.status = result.status;
174
159
  throw error;
175
160
  }
176
- /**
177
- * Check if file is JSON, first by parsing file name for extension,
178
- * then – if filename has no extension – by cloning the response
179
- * and parsing it for content.
180
- */ const ext = getExt(input);
161
+ const ext = getExt(input);
181
162
  if (ext === 'json' || !ext) {
182
163
  if (ext) {
183
164
  const lottie = await result.json();
@@ -225,22 +206,13 @@ const addExt = (ext, str)=>{
225
206
  });
226
207
  });
227
208
  return arrayBuffer;
228
- }, /**
229
- * Get extension from filename, URL or path
230
- * @param { string } str Filename, URL or path
231
- */ getExt = (str)=>{
209
+ }, getExt = (str)=>{
232
210
  if (!str || !hasExt(str)) return;
233
211
  return str.split('.').pop()?.toLowerCase();
234
212
  }, getExtFromB64 = (str)=>{
235
213
  const mime = str.split(':')[1].split(';')[0];
236
214
  return mime.split('/')[1].split('+')[0];
237
- }, /**
238
- * Parse URL to get filename
239
- * @param { string } src The url string
240
- * @param { boolean } keepExt Whether to include file extension
241
- * @returns { string } Filename, in lowercase
242
- */ getFilename = (src, keepExt)=>{
243
- // Because the regex strips all special characters, we need to extract the file extension, so we can add it later if we need it
215
+ }, getFilename = (src, keepExt)=>{
244
216
  const ext = getExt(src);
245
217
  return `${src.replace(/\.[^.]*$/, '').replace(/\W+/g, '')}${keepExt && ext ? `.${ext}` : ''}`.toLowerCase();
246
218
  }, getLottieJSON = async (resp)=>{
@@ -287,11 +259,7 @@ const addExt = (ext, str)=>{
287
259
  return 'w' in asset && 'h' in asset && !('xt' in asset) && 'p' in asset;
288
260
  }, isServer = ()=>{
289
261
  return !(typeof window !== 'undefined' && window.document);
290
- }, /**
291
- * Convert string to Uint8Array
292
- * @param { string } str Base64 encoded string
293
- * @returns { Uint8Array} UTF-8/Latin-1 binary
294
- */ strToU8 = (str)=>{
262
+ }, strToU8 = (str)=>{
295
263
  const u8 = new Uint8Array(str.length);
296
264
  for(let i = 0; i < str.length; i++){
297
265
  u8[i] = str.charCodeAt(i);
@@ -315,7 +283,7 @@ const addExt = (ext, str)=>{
315
283
  await Promise.all(toResolve);
316
284
  }, unzip = async (resp)=>{
317
285
  const u8 = new Uint8Array(await resp.arrayBuffer()), unzipped = await new Promise((resolve, reject)=>{
318
- fflate.unzip(u8, /*{ filter },*/ (err, file)=>{
286
+ fflate.unzip(u8, (err, file)=>{
319
287
  if (err) {
320
288
  reject(err);
321
289
  }
@@ -331,7 +299,7 @@ const addExt = (ext, str)=>{
331
299
  };
332
300
 
333
301
  var name = "@aarsteinmedia/dotlottie-player";
334
- var version = "2.1.7";
302
+ var version = "2.2.0";
335
303
  var description = "Web Component for playing Lottie animations in your web app. Previously @johanaarstein/dotlottie-player";
336
304
  var exports$1 = {
337
305
  ".": {
@@ -384,11 +352,11 @@ var devDependencies = {
384
352
  "@rollup/plugin-json": "^6.0.1",
385
353
  "@rollup/plugin-node-resolve": "^15.2.3",
386
354
  "@rollup/plugin-replace": "^5.0.5",
387
- "@swc/core": "^1.3.95",
388
- "@types/node": "^20.8.10",
355
+ "@swc/core": "^1.3.99",
356
+ "@types/node": "^20.10.0",
389
357
  "@typescript-eslint/eslint-plugin": "^5.62.0",
390
358
  "@typescript-eslint/parser": "^5.62.0",
391
- eslint: "^8.52.0",
359
+ eslint: "^8.54.0",
392
360
  "eslint-plugin-lit": "^1.10.1",
393
361
  rollup: "^3.29.4",
394
362
  "rollup-plugin-dts": "^6.1.0",
@@ -397,7 +365,7 @@ var devDependencies = {
397
365
  "rollup-plugin-swc3": "^0.9.1",
398
366
  shx: "^0.3.4",
399
367
  "ts-lit-plugin": "^1.2.1",
400
- typescript: "^5.2.2"
368
+ typescript: "^5.3.2"
401
369
  };
402
370
  var customElements = "dist/custom-elements.json";
403
371
  var files = [
@@ -460,18 +428,15 @@ function _ts_decorate(decorators, target, key, desc) {
460
428
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
461
429
  return c > 3 && r && Object.defineProperty(target, key, r), r;
462
430
  }
463
- exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
464
- /**
465
- * Get options from props
466
- * @returns { AnimationConfig }
467
- */ _getOptions() {
468
- const preserveAspectRatio = this.preserveAspectRatio ?? (this.objectfit && aspectRatio(this.objectfit)), initialSegment = !this.segment || this.segment.some((val)=>val < 0) ? undefined : this.segment.every((val)=>val > 0) ? [
431
+ class DotLottiePlayer extends lit.LitElement {
432
+ _getOptions() {
433
+ const preserveAspectRatio = this.preserveAspectRatio ?? (this.objectfit && aspectRatio(this.objectfit)), currentAnimation = this._manifest.animations[this._currentAnimation], loop = this.loop !== undefined ? !!this.loop : currentAnimation.loop !== undefined && !!currentAnimation.loop, autoplay = this.autoplay !== undefined ? !!this.autoplay : currentAnimation.autoplay !== undefined && !!currentAnimation.autoplay, initialSegment = !this.segment || this.segment.some((val)=>val < 0) ? undefined : this.segment.every((val)=>val > 0) ? [
469
434
  this.segment[0] - 1,
470
435
  this.segment[1] - 1
471
436
  ] : this.segment, options = {
472
437
  container: this.container,
473
- loop: !!this.loop,
474
- autoplay: !!this.autoplay,
438
+ loop,
439
+ autoplay,
475
440
  renderer: this.renderer,
476
441
  initialSegment,
477
442
  rendererSettings: {
@@ -503,12 +468,8 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
503
468
  }
504
469
  return options;
505
470
  }
506
- /**
507
- * Initialize Lottie Web player
508
- * @param { string | LottieJSON } src URL to lottie animation, or raw JSON data
509
- */ async load(src) {
471
+ async load(src) {
510
472
  if (!this.shadowRoot) return;
511
- // Load the resource
512
473
  try {
513
474
  const { animations, manifest, isDotLottie } = await getAnimationData(src);
514
475
  if (!animations || animations.some((animation)=>!this._isLottie(animation))) {
@@ -528,9 +489,7 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
528
489
  }
529
490
  ]
530
491
  };
531
- // Clear previous animation, if any
532
492
  if (this._lottieInstance) this._lottieInstance.destroy();
533
- // Initialize lottie player and load animation
534
493
  this._lottieInstance = Lottie.loadAnimation({
535
494
  ...this._getOptions(),
536
495
  animationData: animations[this._currentAnimation]
@@ -542,21 +501,19 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
542
501
  return;
543
502
  }
544
503
  this._addEventListeners();
545
- // Set initial playback speed and direction
546
504
  this.setSpeed(this.speed);
547
505
  this.setDirection(this.direction ?? 1);
548
506
  this.setSubframe(!!this.subframe);
549
- // Start playing if autoplay is enabled
550
507
  if (this.autoplay) {
551
508
  if (this.direction === -1) this.seek('99%');
552
509
  this.play();
553
510
  }
554
511
  }
555
- /**
556
- * Add event listeners
557
- */ _addEventListeners() {
512
+ getManifest() {
513
+ return this._manifest;
514
+ }
515
+ _addEventListeners() {
558
516
  if (!this._lottieInstance) return;
559
- // Calculate and save the current progress of the animation
560
517
  this._lottieInstance.addEventListener('enterFrame', ()=>{
561
518
  if (this._lottieInstance) {
562
519
  const { currentFrame, totalFrames } = this._lottieInstance;
@@ -569,7 +526,6 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
569
526
  }));
570
527
  }
571
528
  });
572
- // Handle animation play complete
573
529
  this._lottieInstance.addEventListener('complete', ()=>{
574
530
  this.currentState = exports.PlayerState.Completed;
575
531
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Complete));
@@ -577,7 +533,6 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
577
533
  this.next();
578
534
  }
579
535
  });
580
- //Handle complete loop
581
536
  const loopComplete = ()=>{
582
537
  if (!this._lottieInstance) {
583
538
  return;
@@ -606,22 +561,18 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
606
561
  }, this.intermission);
607
562
  };
608
563
  this._lottieInstance.addEventListener('loopComplete', loopComplete);
609
- // Handle lottie-web ready event
610
564
  this._lottieInstance.addEventListener('DOMLoaded', ()=>{
611
565
  this._playerState.loaded = true;
612
566
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Ready));
613
567
  });
614
- // Handle animation data load complete
615
568
  this._lottieInstance.addEventListener('data_ready', ()=>{
616
569
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Load));
617
570
  });
618
- // Set error state when animation load fail event triggers
619
571
  this._lottieInstance.addEventListener('data_failed', ()=>{
620
572
  this.currentState = exports.PlayerState.Error;
621
573
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Error));
622
574
  });
623
575
  if (this.container) {
624
- // Set handlers to auto play animation on hover if enabled
625
576
  this.container.addEventListener('mouseenter', ()=>{
626
577
  if (this.hover && this.currentState !== exports.PlayerState.Playing) {
627
578
  this.play();
@@ -634,19 +585,14 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
634
585
  });
635
586
  }
636
587
  }
637
- /**
638
- * Handle visibility change events
639
- */ _onVisibilityChange() {
588
+ _onVisibilityChange() {
640
589
  if (document.hidden && this.currentState === exports.PlayerState.Playing) {
641
590
  this._freeze();
642
591
  } else if (this.currentState === exports.PlayerState.Frozen) {
643
592
  this.play();
644
593
  }
645
594
  }
646
- /**
647
- * Handles click and drag actions on the progress track
648
- * @param { Event & { HTMLInputElement } } event
649
- */ _handleSeekChange({ target }) {
595
+ _handleSeekChange({ target }) {
650
596
  if (!(target instanceof HTMLInputElement) || !this._lottieInstance || isNaN(Number(target.value))) return;
651
597
  this.seek(Math.floor(Number(target.value) / 100 * this._lottieInstance.totalFrames));
652
598
  setTimeout(()=>{
@@ -667,13 +613,7 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
667
613
  ];
668
614
  return mandatory.every((field)=>Object.prototype.hasOwnProperty.call(json, field));
669
615
  }
670
- /**
671
- * Creates a new dotLottie file, by combinig several animations
672
- * @param { Config } configs
673
- * @param { string } fileName
674
- * @param { boolean } triggerDownload Whether to trigger a download in the browser.
675
- * If set to false the function returns an ArrayBuffer. Defaults to true.
676
- */ async addAnimation(configs, fileName, triggerDownload = true) {
616
+ async addAnimation(configs, fileName, triggerDownload = true) {
677
617
  try {
678
618
  const oldManifest = this._manifest || {
679
619
  animations: []
@@ -707,14 +647,10 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
707
647
  console.error(handleErrors(err).message);
708
648
  }
709
649
  }
710
- /**
711
- * Returns the lottie-web instance used in the component
712
- */ getLottie() {
650
+ getLottie() {
713
651
  return this._lottieInstance;
714
652
  }
715
- /**
716
- * Play
717
- */ play() {
653
+ play() {
718
654
  if (!this._lottieInstance) return;
719
655
  if (this.currentState) {
720
656
  this._playerState.prev = this.currentState;
@@ -725,9 +661,7 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
725
661
  }, 0);
726
662
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Play));
727
663
  }
728
- /**
729
- * Pause
730
- */ pause() {
664
+ pause() {
731
665
  if (!this._lottieInstance) return;
732
666
  if (this.currentState) {
733
667
  this._playerState.prev = this.currentState;
@@ -738,9 +672,7 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
738
672
  }, 0);
739
673
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Pause));
740
674
  }
741
- /**
742
- * Stop
743
- */ stop() {
675
+ stop() {
744
676
  if (!this._lottieInstance) return;
745
677
  if (this.currentState) {
746
678
  this._playerState.prev = this.currentState;
@@ -752,9 +684,7 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
752
684
  }, 0);
753
685
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Stop));
754
686
  }
755
- /**
756
- * Destroy animation and element
757
- */ destroy() {
687
+ destroy() {
758
688
  if (!this._lottieInstance) return;
759
689
  this.currentState = exports.PlayerState.Destroyed;
760
690
  this._lottieInstance.destroy();
@@ -762,21 +692,14 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
762
692
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Destroyed));
763
693
  this.remove();
764
694
  }
765
- /**
766
- * Seek to a given frame
767
- * @param { number | string } value Frame to seek to
768
- */ seek(value) {
695
+ seek(value) {
769
696
  if (!this._lottieInstance) return;
770
- // Extract frame number from either number or percentage value
771
697
  const matches = value.toString().match(/^([0-9]+)(%?)$/);
772
698
  if (!matches) {
773
699
  return;
774
700
  }
775
- // Calculate and set the frame number
776
701
  const frame = Math.floor(matches[2] === '%' ? this._lottieInstance.totalFrames * Number(matches[1]) / 100 : Number(matches[1]));
777
- // Set seeker to new frame number
778
702
  this._seeker = frame;
779
- // Send lottie player to the new frame
780
703
  if (this.currentState === exports.PlayerState.Playing || this.currentState === exports.PlayerState.Frozen && this._playerState.prev === exports.PlayerState.Playing) {
781
704
  this._lottieInstance.goToAndPlay(frame, true);
782
705
  this.currentState = exports.PlayerState.Playing;
@@ -785,11 +708,8 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
785
708
  this._lottieInstance.pause();
786
709
  }
787
710
  }
788
- /**
789
- * Snapshot and download the current frame as SVG
790
- */ snapshot() {
711
+ snapshot() {
791
712
  if (!this.shadowRoot) return;
792
- // Get SVG element and serialize markup
793
713
  const svgElement = this.shadowRoot.querySelector('.animation svg'), data = svgElement instanceof Node ? new XMLSerializer().serializeToString(svgElement) : null;
794
714
  if (!data) {
795
715
  console.error('Could not serialize data');
@@ -801,19 +721,12 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
801
721
  });
802
722
  return data;
803
723
  }
804
- /**
805
- * Toggles subframe, for more smooth animations
806
- * @param { boolean } value Whether animation uses subframe
807
- */ setSubframe(value) {
724
+ setSubframe(value) {
808
725
  if (!this._lottieInstance) return;
809
726
  this.subframe = value;
810
727
  this._lottieInstance.setSubframe(value);
811
728
  }
812
- /**
813
- * Freeze animation.
814
- * This internal state pauses animation and is used to differentiate between
815
- * user requested pauses and component instigated pauses.
816
- */ _freeze() {
729
+ _freeze() {
817
730
  if (!this._lottieInstance) return;
818
731
  if (this.currentState) {
819
732
  this._playerState.prev = this.currentState;
@@ -824,43 +737,30 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
824
737
  }, 0);
825
738
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Freeze));
826
739
  }
827
- /**
828
- * Reload animation
829
- */ async reload() {
740
+ async reload() {
830
741
  if (!this._lottieInstance) return;
831
742
  this._lottieInstance.destroy();
832
743
  if (this.src) {
833
744
  await this.load(this.src);
834
745
  }
835
746
  }
836
- /**
837
- * Set animation playback speed
838
- * @param { number } value Playback speed
839
- */ setSpeed(value = 1) {
747
+ setSpeed(value = 1) {
840
748
  if (!this._lottieInstance) return;
841
749
  this.speed = value;
842
750
  this._lottieInstance.setSpeed(value);
843
751
  }
844
- /**
845
- * Animation play direction
846
- * @param { AnimationDirection } value Animation direction
847
- */ setDirection(value) {
752
+ setDirection(value) {
848
753
  if (!this._lottieInstance) return;
849
754
  this.direction = value;
850
755
  this._lottieInstance.setDirection(value);
851
756
  }
852
- /**
853
- * Set loop
854
- * @param { boolean } value
855
- */ setLooping(value) {
757
+ setLooping(value) {
856
758
  if (this._lottieInstance) {
857
759
  this.loop = value;
858
760
  this._lottieInstance.setLoop(value);
859
761
  }
860
762
  }
861
- /**
862
- * Toggle playing state
863
- */ togglePlay() {
763
+ togglePlay() {
864
764
  if (!this._lottieInstance) return;
865
765
  const { currentFrame, playDirection, totalFrames } = this._lottieInstance;
866
766
  if (this.currentState === exports.PlayerState.Playing) {
@@ -879,43 +779,32 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
879
779
  }
880
780
  return this.play();
881
781
  }
882
- /**
883
- * Toggle loop
884
- */ toggleLooping() {
782
+ toggleLooping() {
885
783
  this.setLooping(!this.loop);
886
784
  }
887
- /**
888
- * Toggle Boomerang
889
- */ toggleBoomerang() {
785
+ toggleBoomerang() {
890
786
  if (this.mode === exports.PlayMode.Normal) {
891
787
  this.mode = exports.PlayMode.Bounce;
892
788
  } else {
893
789
  this.mode = exports.PlayMode.Normal;
894
790
  }
895
791
  }
896
- /**
897
- * Toggle show Settings
898
- */ _toggleSettings(flag) {
792
+ _toggleSettings(flag) {
899
793
  if (flag === undefined) {
900
794
  this._isSettingsOpen = !this._isSettingsOpen;
901
795
  } else {
902
796
  this._isSettingsOpen = flag;
903
797
  }
904
798
  }
905
- /**
906
- * Handle blur
907
- */ _handleBlur() {
799
+ _handleBlur() {
908
800
  setTimeout(()=>this._toggleSettings(false), 200);
909
801
  }
910
802
  _switchInstance() {
911
- // Clear previous animation
912
803
  if (this._lottieInstance) this._lottieInstance.destroy();
913
- // Re-initialize lottie player
914
804
  this._lottieInstance = Lottie.loadAnimation({
915
805
  ...this._getOptions(),
916
806
  animationData: this._animations[this._currentAnimation]
917
807
  });
918
- // Add event listeners to new Lottie instance
919
808
  this._addEventListeners();
920
809
  if (this.autoplay) {
921
810
  this._lottieInstance?.goToAndPlay(0, true);
@@ -924,25 +813,15 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
924
813
  this._lottieInstance?.goToAndStop(0, true);
925
814
  }
926
815
  }
927
- /**
928
- * Skip to next animation
929
- */ next() {
816
+ next() {
930
817
  this._currentAnimation++;
931
818
  this._switchInstance();
932
819
  }
933
- /**
934
- * Skip to previous animation
935
- */ prev() {
820
+ prev() {
936
821
  this._currentAnimation--;
937
822
  this._switchInstance();
938
823
  }
939
- /**
940
- * Convert JSON Lottie to dotLottie
941
- * @param { boolean | undefined } typeCheck External type safety
942
- * @param { LottieManifest | undefined } manifest Externally added manifest
943
- * @param { LottieJSON[] | undefined } animations Externally added animations
944
- * @param { boolean } download Whether to trigger a download in the browser
945
- */ convert(typeCheck, manifest, animations, fileName, download = true) {
824
+ convert(typeCheck, manifest, animations, fileName, download = true) {
946
825
  if (typeCheck || this._isDotLottie) return;
947
826
  const oldManifest = manifest || this._manifest, newManifest = {
948
827
  ...oldManifest,
@@ -950,23 +829,16 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
950
829
  };
951
830
  return createDotLottie(animations || this._animations, newManifest, `${getFilename(fileName || this.src)}.lottie`, download);
952
831
  }
953
- /**
954
- * Return the styles for the component
955
- * @returns { CSSResult }
956
- */ static get styles() {
832
+ static get styles() {
957
833
  return styles;
958
834
  }
959
- /**
960
- * Initialize everything on component first render
961
- */ connectedCallback() {
835
+ connectedCallback() {
962
836
  super.connectedCallback();
963
- // Add listener for Visibility API's change event.
964
837
  if (typeof document.hidden !== 'undefined') {
965
838
  document.addEventListener('visibilitychange', this._onVisibilityChange);
966
839
  }
967
840
  }
968
841
  async firstUpdated() {
969
- // Add intersection observer for detecting component being out-of-view.
970
842
  if ('IntersectionObserver' in window) {
971
843
  this._intersectionObserver = new IntersectionObserver((entries)=>{
972
844
  if (entries[0].isIntersecting) {
@@ -979,24 +851,18 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
979
851
  });
980
852
  this._intersectionObserver.observe(this.container);
981
853
  }
982
- // Setup lottie player
983
854
  if (this.src) {
984
855
  await this.load(this.src);
985
856
  }
986
857
  this.dispatchEvent(new CustomEvent(exports.PlayerEvents.Rendered));
987
858
  }
988
- /**
989
- * Cleanup on component destroy
990
- */ disconnectedCallback() {
859
+ disconnectedCallback() {
991
860
  super.disconnectedCallback();
992
- // Remove intersection observer for detecting component being out-of-view
993
861
  if (this._intersectionObserver) {
994
862
  this._intersectionObserver.disconnect();
995
863
  this._intersectionObserver = undefined;
996
864
  }
997
- // Destroy the animation instance
998
865
  if (this._lottieInstance) this._lottieInstance.destroy();
999
- // Remove the attached Visibility API's change event listener
1000
866
  document.removeEventListener('visibilitychange', this._onVisibilityChange);
1001
867
  }
1002
868
  renderControls() {
@@ -1008,54 +874,22 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
1008
874
  }
1009
875
  constructor(...args){
1010
876
  super(...args);
1011
- /**
1012
- * Background color
1013
- */ this.background = 'transparent';
1014
- /**
1015
- * Display controls
1016
- */ this.controls = false;
1017
- /**
1018
- * Player state
1019
- */ this.currentState = exports.PlayerState.Loading;
1020
- /**
1021
- * Direction of animation
1022
- */ this.direction = 1;
1023
- /**
1024
- * Whether to play on mouseover
1025
- */ this.hover = false;
1026
- /**
1027
- * Intermission
1028
- */ this.intermission = 0;
1029
- /**
1030
- * Whether to loop
1031
- */ this.loop = false;
1032
- /**
1033
- * Play mode
1034
- */ this.mode = exports.PlayMode.Normal;
1035
- /**
1036
- * Resizing to container
1037
- */ this.objectfit = 'contain';
1038
- /**
1039
- * Renderer to use (svg, canvas or html)
1040
- */ this.renderer = 'svg';
1041
- /**
1042
- * Hide advanced controls
1043
- */ this.simple = false;
1044
- /**
1045
- * Speed
1046
- */ this.speed = 1;
1047
- /**
1048
- * Subframe
1049
- */ this.subframe = true;
1050
- /**
1051
- * Whether settings toolbar is open
1052
- */ this._isSettingsOpen = false;
1053
- /**
1054
- * Seeker
1055
- */ this._seeker = 0;
1056
- /**
1057
- * Which animation to show, if several
1058
- */ this._currentAnimation = 0;
877
+ this.background = 'transparent';
878
+ this.controls = false;
879
+ this.currentState = exports.PlayerState.Loading;
880
+ this.direction = 1;
881
+ this.hover = false;
882
+ this.intermission = 0;
883
+ this.loop = false;
884
+ this.mode = exports.PlayMode.Normal;
885
+ this.objectfit = 'contain';
886
+ this.renderer = 'svg';
887
+ this.simple = false;
888
+ this.speed = 1;
889
+ this.subframe = true;
890
+ this._isSettingsOpen = false;
891
+ this._seeker = 0;
892
+ this._currentAnimation = 0;
1059
893
  this._lottieInstance = null;
1060
894
  this._identifier = this.id || useId('dotlottie');
1061
895
  this._errorMessage = 'Something went wrong';
@@ -1065,135 +899,131 @@ exports.DotLottiePlayer = class DotLottiePlayer extends lit.LitElement {
1065
899
  count: 0,
1066
900
  loaded: false
1067
901
  };
1068
- /**
1069
- * Handle settings click event
1070
- */ this._handleSettingsClick = ({ target })=>{
902
+ this._handleSettingsClick = ({ target })=>{
1071
903
  this._toggleSettings();
1072
- // Because Safari does not add focus on click, we need to add it manually, so the onblur event will fire
1073
904
  if (target instanceof HTMLElement) {
1074
905
  target.focus();
1075
906
  }
1076
907
  };
1077
908
  }
1078
- };
909
+ }
1079
910
  _ts_decorate([
1080
911
  decorators_js.property({
1081
912
  type: Boolean,
1082
913
  reflect: true
1083
914
  })
1084
- ], exports.DotLottiePlayer.prototype, "autoplay", void 0);
915
+ ], DotLottiePlayer.prototype, "autoplay", void 0);
1085
916
  _ts_decorate([
1086
917
  decorators_js.property({
1087
918
  type: String
1088
919
  })
1089
- ], exports.DotLottiePlayer.prototype, "background", void 0);
920
+ ], DotLottiePlayer.prototype, "background", void 0);
1090
921
  _ts_decorate([
1091
922
  decorators_js.property({
1092
923
  type: Boolean,
1093
924
  reflect: true
1094
925
  })
1095
- ], exports.DotLottiePlayer.prototype, "controls", void 0);
926
+ ], DotLottiePlayer.prototype, "controls", void 0);
1096
927
  _ts_decorate([
1097
928
  decorators_js.property({
1098
929
  type: Number
1099
930
  })
1100
- ], exports.DotLottiePlayer.prototype, "count", void 0);
931
+ ], DotLottiePlayer.prototype, "count", void 0);
1101
932
  _ts_decorate([
1102
933
  decorators_js.property({
1103
934
  type: String
1104
935
  })
1105
- ], exports.DotLottiePlayer.prototype, "currentState", void 0);
936
+ ], DotLottiePlayer.prototype, "currentState", void 0);
1106
937
  _ts_decorate([
1107
938
  decorators_js.property({
1108
939
  type: String
1109
940
  })
1110
- ], exports.DotLottiePlayer.prototype, "description", void 0);
941
+ ], DotLottiePlayer.prototype, "description", void 0);
1111
942
  _ts_decorate([
1112
943
  decorators_js.property({
1113
944
  type: Number
1114
945
  })
1115
- ], exports.DotLottiePlayer.prototype, "direction", void 0);
946
+ ], DotLottiePlayer.prototype, "direction", void 0);
1116
947
  _ts_decorate([
1117
948
  decorators_js.property({
1118
949
  type: Boolean
1119
950
  })
1120
- ], exports.DotLottiePlayer.prototype, "hover", void 0);
951
+ ], DotLottiePlayer.prototype, "hover", void 0);
1121
952
  _ts_decorate([
1122
953
  decorators_js.property({
1123
954
  type: Number
1124
955
  })
1125
- ], exports.DotLottiePlayer.prototype, "intermission", void 0);
956
+ ], DotLottiePlayer.prototype, "intermission", void 0);
1126
957
  _ts_decorate([
1127
958
  decorators_js.property({
1128
959
  type: Boolean,
1129
960
  reflect: true
1130
961
  })
1131
- ], exports.DotLottiePlayer.prototype, "loop", void 0);
962
+ ], DotLottiePlayer.prototype, "loop", void 0);
1132
963
  _ts_decorate([
1133
964
  decorators_js.property({
1134
965
  type: String
1135
966
  })
1136
- ], exports.DotLottiePlayer.prototype, "mode", void 0);
967
+ ], DotLottiePlayer.prototype, "mode", void 0);
1137
968
  _ts_decorate([
1138
969
  decorators_js.property({
1139
970
  type: String
1140
971
  })
1141
- ], exports.DotLottiePlayer.prototype, "objectfit", void 0);
972
+ ], DotLottiePlayer.prototype, "objectfit", void 0);
1142
973
  _ts_decorate([
1143
974
  decorators_js.property({
1144
975
  type: String
1145
976
  })
1146
- ], exports.DotLottiePlayer.prototype, "preserveAspectRatio", void 0);
977
+ ], DotLottiePlayer.prototype, "preserveAspectRatio", void 0);
1147
978
  _ts_decorate([
1148
979
  decorators_js.property({
1149
980
  type: String
1150
981
  })
1151
- ], exports.DotLottiePlayer.prototype, "renderer", void 0);
982
+ ], DotLottiePlayer.prototype, "renderer", void 0);
1152
983
  _ts_decorate([
1153
984
  decorators_js.property({
1154
985
  type: Array
1155
986
  })
1156
- ], exports.DotLottiePlayer.prototype, "segment", void 0);
987
+ ], DotLottiePlayer.prototype, "segment", void 0);
1157
988
  _ts_decorate([
1158
989
  decorators_js.property({
1159
990
  type: Boolean
1160
991
  })
1161
- ], exports.DotLottiePlayer.prototype, "simple", void 0);
992
+ ], DotLottiePlayer.prototype, "simple", void 0);
1162
993
  _ts_decorate([
1163
994
  decorators_js.property({
1164
995
  type: Number
1165
996
  })
1166
- ], exports.DotLottiePlayer.prototype, "speed", void 0);
997
+ ], DotLottiePlayer.prototype, "speed", void 0);
1167
998
  _ts_decorate([
1168
999
  decorators_js.property({
1169
1000
  type: String
1170
1001
  })
1171
- ], exports.DotLottiePlayer.prototype, "src", void 0);
1002
+ ], DotLottiePlayer.prototype, "src", void 0);
1172
1003
  _ts_decorate([
1173
1004
  decorators_js.property({
1174
1005
  type: Boolean
1175
1006
  })
1176
- ], exports.DotLottiePlayer.prototype, "subframe", void 0);
1007
+ ], DotLottiePlayer.prototype, "subframe", void 0);
1177
1008
  _ts_decorate([
1178
1009
  decorators_js.query('.animation')
1179
- ], exports.DotLottiePlayer.prototype, "container", void 0);
1010
+ ], DotLottiePlayer.prototype, "container", void 0);
1180
1011
  _ts_decorate([
1181
1012
  decorators_js.state()
1182
- ], exports.DotLottiePlayer.prototype, "_isSettingsOpen", void 0);
1013
+ ], DotLottiePlayer.prototype, "_isSettingsOpen", void 0);
1183
1014
  _ts_decorate([
1184
1015
  decorators_js.state()
1185
- ], exports.DotLottiePlayer.prototype, "_seeker", void 0);
1016
+ ], DotLottiePlayer.prototype, "_seeker", void 0);
1186
1017
  _ts_decorate([
1187
1018
  decorators_js.state()
1188
- ], exports.DotLottiePlayer.prototype, "_currentAnimation", void 0);
1019
+ ], DotLottiePlayer.prototype, "_currentAnimation", void 0);
1189
1020
  _ts_decorate([
1190
1021
  decorators_js.state()
1191
- ], exports.DotLottiePlayer.prototype, "_animations", void 0);
1192
- exports.DotLottiePlayer = _ts_decorate([
1022
+ ], DotLottiePlayer.prototype, "_animations", void 0);
1023
+ DotLottiePlayer = _ts_decorate([
1193
1024
  decorators_js.customElement('dotlottie-player')
1194
- ], exports.DotLottiePlayer);
1025
+ ], DotLottiePlayer);
1026
+
1027
+ globalThis.dotLottiePlayer = ()=>new DotLottiePlayer();
1195
1028
 
1196
- /**
1197
- * Expose DotLottiePlayer class as global variable
1198
- * @returns { DotLottiePlayer }
1199
- */ globalThis.dotLottiePlayer = ()=>new exports.DotLottiePlayer();
1029
+ exports.DotLottiePlayer = DotLottiePlayer;