@aarsteinmedia/dotlottie-player 2.1.8 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -36,7 +36,6 @@ var PlayerEvents;
36
36
  })(PlayerEvents || (PlayerEvents = {}));
37
37
  class CustomError extends Error {
38
38
  }
39
-
40
39
  const addExt = (ext, str)=>{
41
40
  if (!str) return;
42
41
  if (getExt(str)) {
@@ -298,7 +297,7 @@ const addExt = (ext, str)=>{
298
297
  };
299
298
 
300
299
  var name = "@aarsteinmedia/dotlottie-player";
301
- var version = "2.1.8";
300
+ var version = "2.2.1";
302
301
  var description = "Web Component for playing Lottie animations in your web app. Previously @johanaarstein/dotlottie-player";
303
302
  var exports = {
304
303
  ".": {
@@ -429,13 +428,13 @@ function _ts_decorate(decorators, target, key, desc) {
429
428
  }
430
429
  class DotLottiePlayer extends LitElement {
431
430
  _getOptions() {
432
- 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
+ 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 = 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) ? [
433
432
  this.segment[0] - 1,
434
433
  this.segment[1] - 1
435
434
  ] : this.segment, options = {
436
435
  container: this.container,
437
- loop: !!this.loop,
438
- autoplay: !!this.autoplay,
436
+ loop,
437
+ autoplay,
439
438
  renderer: this.renderer,
440
439
  initialSegment,
441
440
  rendererSettings: {
@@ -500,8 +499,9 @@ class DotLottiePlayer extends LitElement {
500
499
  return;
501
500
  }
502
501
  this._addEventListeners();
503
- this.setSpeed(this.speed);
504
- this.setDirection(this.direction ?? 1);
502
+ const speed = this.multiAnimationSettings?.[this._currentAnimation]?.speed ?? this.speed ?? this._manifest.animations[this._currentAnimation].speed, direction = this.multiAnimationSettings?.[this._currentAnimation]?.direction ?? this.direction ?? this._manifest.animations[this._currentAnimation].direction ?? 1;
503
+ this.setSpeed(speed);
504
+ this.setDirection(direction);
505
505
  this.setSubframe(!!this.subframe);
506
506
  if (this.autoplay) {
507
507
  if (this.direction === -1) this.seek('99%');
@@ -536,9 +536,9 @@ class DotLottiePlayer extends LitElement {
536
536
  if (!this._lottieInstance) {
537
537
  return;
538
538
  }
539
- const { firstFrame, totalFrames, playDirection } = this._lottieInstance;
539
+ const { firstFrame, totalFrames, playDirection } = this._lottieInstance, isBounce = this.mode === PlayMode.Bounce || this._manifest.animations[this._currentAnimation].mode === PlayMode.Bounce;
540
540
  if (this.count) {
541
- this.mode === PlayMode.Bounce ? this._playerState.count += 1 : this._playerState.count += 0.5;
541
+ isBounce ? this._playerState.count += 1 : this._playerState.count += 0.5;
542
542
  if (this._playerState.count >= this.count) {
543
543
  this.setLooping(false);
544
544
  this.currentState = PlayerState.Completed;
@@ -547,7 +547,7 @@ class DotLottiePlayer extends LitElement {
547
547
  }
548
548
  }
549
549
  this.dispatchEvent(new CustomEvent(PlayerEvents.Loop));
550
- if (this.mode === PlayMode.Bounce) {
550
+ if (isBounce) {
551
551
  this._lottieInstance?.goToAndStop(playDirection === -1 ? firstFrame : totalFrames * 0.99, true);
552
552
  this._lottieInstance?.setDirection(playDirection * -1);
553
553
  return setTimeout(()=>{
@@ -759,6 +759,11 @@ class DotLottiePlayer extends LitElement {
759
759
  this._lottieInstance.setLoop(value);
760
760
  }
761
761
  }
762
+ setMultiAnimationSettings(settings) {
763
+ if (this._lottieInstance) {
764
+ this.multiAnimationSettings = settings;
765
+ }
766
+ }
762
767
  togglePlay() {
763
768
  if (!this._lottieInstance) return;
764
769
  const { currentFrame, playDirection, totalFrames } = this._lottieInstance;
@@ -964,6 +969,11 @@ _ts_decorate([
964
969
  type: String
965
970
  })
966
971
  ], DotLottiePlayer.prototype, "mode", void 0);
972
+ _ts_decorate([
973
+ property({
974
+ type: Array
975
+ })
976
+ ], DotLottiePlayer.prototype, "multiAnimationSettings", void 0);
967
977
  _ts_decorate([
968
978
  property({
969
979
  type: String
package/dist/index.d.ts CHANGED
@@ -3,34 +3,6 @@ import { LitElement, CSSResult } from 'lit';
3
3
  import { AnimationDirection, RendererType, AnimationSegment, AnimationItem } from 'lottie-web';
4
4
  import { RefObject, CSSProperties } from 'react';
5
5
 
6
- declare enum PlayerState {
7
- Completed = "completed",
8
- Destroyed = "destroyed",
9
- Error = "error",
10
- Frozen = "frozen",
11
- Loading = "loading",
12
- Paused = "paused",
13
- Playing = "playing",
14
- Stopped = "stopped"
15
- }
16
- declare enum PlayMode {
17
- Bounce = "bounce",
18
- Normal = "normal"
19
- }
20
- declare enum PlayerEvents {
21
- Complete = "complete",
22
- Destroyed = "destroyed",
23
- Error = "error",
24
- Frame = "frame",
25
- Freeze = "freeze",
26
- Load = "load",
27
- Loop = "loop",
28
- Pause = "pause",
29
- Play = "play",
30
- Ready = "ready",
31
- Rendered = "rendered",
32
- Stop = "stop"
33
- }
34
6
  interface LottieAsset {
35
7
  e: 0 | 1;
36
8
  id: string;
@@ -66,8 +38,9 @@ interface Config {
66
38
  mode?: PlayMode;
67
39
  speed?: number;
68
40
  }
41
+ type Animations = Omit<Config, 'url'>[];
69
42
  interface LottieManifest {
70
- animations: Omit<Config, 'url'>[];
43
+ animations: Animations;
71
44
  author?: string;
72
45
  description?: string;
73
46
  generator?: string;
@@ -98,6 +71,35 @@ declare global {
98
71
  }
99
72
  }
100
73
 
74
+ declare enum PlayerState {
75
+ Completed = "completed",
76
+ Destroyed = "destroyed",
77
+ Error = "error",
78
+ Frozen = "frozen",
79
+ Loading = "loading",
80
+ Paused = "paused",
81
+ Playing = "playing",
82
+ Stopped = "stopped"
83
+ }
84
+ declare enum PlayMode {
85
+ Bounce = "bounce",
86
+ Normal = "normal"
87
+ }
88
+ declare enum PlayerEvents {
89
+ Complete = "complete",
90
+ Destroyed = "destroyed",
91
+ Error = "error",
92
+ Frame = "frame",
93
+ Freeze = "freeze",
94
+ Load = "load",
95
+ Loop = "loop",
96
+ Pause = "pause",
97
+ Play = "play",
98
+ Ready = "ready",
99
+ Rendered = "rendered",
100
+ Stop = "stop"
101
+ }
102
+
101
103
  declare class DotLottiePlayer extends LitElement {
102
104
  autoplay?: Autoplay;
103
105
  background?: string;
@@ -110,6 +112,7 @@ declare class DotLottiePlayer extends LitElement {
110
112
  intermission?: number | undefined;
111
113
  loop?: Loop;
112
114
  mode?: PlayMode;
115
+ multiAnimationSettings?: Partial<Animations>;
113
116
  objectfit?: ObjectFit;
114
117
  preserveAspectRatio?: PreserveAspectRatio;
115
118
  renderer?: RendererType;
@@ -151,6 +154,7 @@ declare class DotLottiePlayer extends LitElement {
151
154
  setSpeed(value?: number): void;
152
155
  setDirection(value: AnimationDirection): void;
153
156
  setLooping(value: boolean): void;
157
+ setMultiAnimationSettings(settings: Partial<Animations>): void;
154
158
  togglePlay(): void;
155
159
  toggleLooping(): void;
156
160
  toggleBoomerang(): void;