@aarsteinmedia/dotlottie-player 6.0.4 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +7 -0
- package/dist/canvas.d.ts +277 -0
- package/dist/canvas.js +1696 -0
- package/dist/full.d.ts +45 -3
- package/dist/full.js +293 -95
- package/dist/light.d.ts +45 -3
- package/dist/light.js +293 -95
- package/dist/svg.d.ts +277 -0
- package/dist/svg.js +1695 -0
- package/dist/unpkg-canvas.js +70 -0
- package/dist/unpkg-full.js +8 -8
- package/dist/unpkg-light.js +5 -5
- package/dist/unpkg-svg.js +70 -0
- package/package.json +30 -19
package/dist/light.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import * as _aarsteinmedia_lottie_web_light from '@aarsteinmedia/lottie-web/ligh
|
|
|
4
4
|
import * as _aarsteinmedia_lottie_web from '@aarsteinmedia/lottie-web';
|
|
5
5
|
import { Vector2, AnimationConfiguration, AnimationData, AnimationDirection, AddAnimationParams, Result, ConvertParams, AnimationItem, LottieManifest, AnimationSettings } from '@aarsteinmedia/lottie-web';
|
|
6
6
|
import { addAnimation, convert } from '@aarsteinmedia/lottie-web/dotlottie';
|
|
7
|
+
import * as _aarsteinmedia_lottie_web_canvas from '@aarsteinmedia/lottie-web/canvas';
|
|
8
|
+
import * as _aarsteinmedia_lottie_web_svg from '@aarsteinmedia/lottie-web/svg';
|
|
7
9
|
|
|
8
10
|
declare class DotLottiePlayer extends DotLottiePlayerBase {
|
|
9
11
|
addAnimation: typeof addAnimation;
|
|
@@ -31,6 +33,34 @@ declare enum PlayerState {
|
|
|
31
33
|
}
|
|
32
34
|
declare const tagName = "dotlottie-player";
|
|
33
35
|
|
|
36
|
+
declare class DotLottiePlayerCanvas extends DotLottiePlayerBase {
|
|
37
|
+
loadAnimation: typeof _aarsteinmedia_lottie_web_canvas.loadAnimation;
|
|
38
|
+
get renderer(): RendererType;
|
|
39
|
+
constructor();
|
|
40
|
+
protected setOptions({ container, hasAutoplay, hasLoop, initialSegment, preserveAspectRatio, }: {
|
|
41
|
+
container?: HTMLElement;
|
|
42
|
+
rendererType: RendererType;
|
|
43
|
+
initialSegment?: Vector2;
|
|
44
|
+
hasAutoplay: boolean;
|
|
45
|
+
hasLoop: boolean;
|
|
46
|
+
preserveAspectRatio: PreserveAspectRatio;
|
|
47
|
+
}): AnimationConfiguration<RendererType.Canvas>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class DotLottiePlayerSVG extends DotLottiePlayerBase {
|
|
51
|
+
loadAnimation: typeof _aarsteinmedia_lottie_web_svg.loadAnimation;
|
|
52
|
+
get renderer(): RendererType;
|
|
53
|
+
constructor();
|
|
54
|
+
protected setOptions({ container, hasAutoplay, hasLoop, initialSegment, preserveAspectRatio, }: {
|
|
55
|
+
container?: HTMLElement;
|
|
56
|
+
rendererType: RendererType;
|
|
57
|
+
initialSegment?: Vector2;
|
|
58
|
+
hasAutoplay: boolean;
|
|
59
|
+
hasLoop: boolean;
|
|
60
|
+
preserveAspectRatio: PreserveAspectRatio;
|
|
61
|
+
}): AnimationConfiguration<RendererType.SVG>;
|
|
62
|
+
}
|
|
63
|
+
|
|
34
64
|
type AnimateOnScroll = boolean | '' | null;
|
|
35
65
|
type Autoplay = boolean | '' | 'autoplay' | null;
|
|
36
66
|
type Controls = boolean | '' | 'controls' | null;
|
|
@@ -40,7 +70,7 @@ declare global {
|
|
|
40
70
|
interface HTMLElementTagNameMap {
|
|
41
71
|
[tagName]: DotLottiePlayer | DotLottiePlayerLight;
|
|
42
72
|
}
|
|
43
|
-
function dotLottiePlayer(): DotLottiePlayer | DotLottiePlayerLight;
|
|
73
|
+
function dotLottiePlayer(): DotLottiePlayer | DotLottiePlayerLight | DotLottiePlayerSVG | DotLottiePlayerCanvas;
|
|
44
74
|
}
|
|
45
75
|
type JSXLottiePlayer = Omit<Partial<DotLottiePlayer | DotLottiePlayerLight>, 'style'> & {
|
|
46
76
|
class?: string;
|
|
@@ -81,7 +111,7 @@ declare function renderControls(this: DotLottiePlayerBase): void;
|
|
|
81
111
|
declare function renderPlayer(this: DotLottiePlayerBase): Promise<void>;
|
|
82
112
|
|
|
83
113
|
declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
84
|
-
static get observedAttributes():
|
|
114
|
+
static get observedAttributes(): readonly ["animateOnScroll", "autoplay", "controls", "direction", "hover", "loop", "mode", "playOnClick", "playOnVisible", "speed", "src", "subframe"];
|
|
85
115
|
static get observedProperties(): string[];
|
|
86
116
|
static get styles(): () => Promise<CSSStyleSheet>;
|
|
87
117
|
isLight: boolean;
|
|
@@ -101,6 +131,8 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
101
131
|
set count(value: number);
|
|
102
132
|
get count(): number;
|
|
103
133
|
get currentAnimation(): number;
|
|
134
|
+
set delay(value: number);
|
|
135
|
+
get delay(): number;
|
|
104
136
|
set description(value: string | null);
|
|
105
137
|
get description(): string | null;
|
|
106
138
|
set direction(value: AnimationDirection);
|
|
@@ -116,8 +148,16 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
116
148
|
get loop(): Loop;
|
|
117
149
|
set mode(value: PlayMode);
|
|
118
150
|
get mode(): PlayMode;
|
|
151
|
+
set mouseout(value: 'void' | 'stop' | 'pause' | 'reverse');
|
|
152
|
+
get mouseout(): "void" | "stop" | "pause" | "reverse";
|
|
119
153
|
set objectfit(value: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down');
|
|
120
154
|
get objectfit(): "contain" | "cover" | "fill" | "none" | "scale-down";
|
|
155
|
+
set once(value: boolean);
|
|
156
|
+
get once(): boolean;
|
|
157
|
+
set playOnClick(value: boolean);
|
|
158
|
+
get playOnClick(): boolean;
|
|
159
|
+
set playOnVisible(value: boolean);
|
|
160
|
+
get playOnVisible(): boolean;
|
|
121
161
|
set preserveAspectRatio(value: PreserveAspectRatio | null);
|
|
122
162
|
get preserveAspectRatio(): PreserveAspectRatio | null;
|
|
123
163
|
set renderer(value: RendererType);
|
|
@@ -156,7 +196,7 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
156
196
|
private _segment?;
|
|
157
197
|
constructor();
|
|
158
198
|
addAnimation(_params: AddAnimationParams): Promise<Result>;
|
|
159
|
-
attributeChangedCallback(name:
|
|
199
|
+
attributeChangedCallback(name: typeof DotLottiePlayerBase.observedAttributes[number], _oldValue: unknown, value: string): Promise<void>;
|
|
160
200
|
connectedCallback(): void;
|
|
161
201
|
convert(_params: ConvertParams): Promise<Result>;
|
|
162
202
|
destroy(): void;
|
|
@@ -188,6 +228,7 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
188
228
|
togglePlay(): void;
|
|
189
229
|
protected _freeze(): void;
|
|
190
230
|
protected _handleBlur(): void;
|
|
231
|
+
protected _handleClick(): void;
|
|
191
232
|
protected _handleSeekChange({ target }: Event): void;
|
|
192
233
|
protected _handleSettingsClick({ target }: Event): void;
|
|
193
234
|
protected setOptions(_options: {
|
|
@@ -208,6 +249,7 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
208
249
|
private _getOptions;
|
|
209
250
|
private _handleScroll;
|
|
210
251
|
private _handleWindowBlur;
|
|
252
|
+
private _intersectionObserverFallback;
|
|
211
253
|
private _loopComplete;
|
|
212
254
|
private _mouseEnter;
|
|
213
255
|
private _mouseLeave;
|
package/dist/light.js
CHANGED
|
@@ -303,7 +303,7 @@ const pauseIcon = /* HTML */ `
|
|
|
303
303
|
'h'
|
|
304
304
|
];
|
|
305
305
|
return mandatory.every((field)=>Object.hasOwn(json, field));
|
|
306
|
-
}, frameOutput = (frame)=>((frame ?? 0) + 1).toString().padStart(3, '0');
|
|
306
|
+
}, isTouch = ()=>'ontouchstart' in window, frameOutput = (frame)=>((frame ?? 0) + 1).toString().padStart(3, '0');
|
|
307
307
|
|
|
308
308
|
const notImplemented = 'Method is not implemented';
|
|
309
309
|
/**
|
|
@@ -319,7 +319,10 @@ const notImplemented = 'Method is not implemented';
|
|
|
319
319
|
'direction',
|
|
320
320
|
'hover',
|
|
321
321
|
'loop',
|
|
322
|
+
// 'mouseout',
|
|
322
323
|
'mode',
|
|
324
|
+
'playOnClick',
|
|
325
|
+
'playOnVisible',
|
|
323
326
|
'speed',
|
|
324
327
|
'src',
|
|
325
328
|
'subframe'
|
|
@@ -397,6 +400,18 @@ const notImplemented = 'Method is not implemented';
|
|
|
397
400
|
return this._currentAnimation;
|
|
398
401
|
}
|
|
399
402
|
/**
|
|
403
|
+
* Delay playback on playOnVisible.
|
|
404
|
+
*/ set delay(value) {
|
|
405
|
+
this.setAttribute('delay', value.toString());
|
|
406
|
+
}
|
|
407
|
+
get delay() {
|
|
408
|
+
const val = this.getAttribute('delay');
|
|
409
|
+
if (val) {
|
|
410
|
+
return Number(val);
|
|
411
|
+
}
|
|
412
|
+
return 0;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
400
415
|
* Description for screen readers.
|
|
401
416
|
*/ set description(value) {
|
|
402
417
|
if (value) {
|
|
@@ -473,6 +488,26 @@ const notImplemented = 'Method is not implemented';
|
|
|
473
488
|
return PlayMode.Normal;
|
|
474
489
|
}
|
|
475
490
|
/**
|
|
491
|
+
* Action on mouseout.
|
|
492
|
+
*/ set mouseout(value) {
|
|
493
|
+
this.setAttribute('mouseout', value);
|
|
494
|
+
}
|
|
495
|
+
get mouseout() {
|
|
496
|
+
const val = this.getAttribute('mouseout');
|
|
497
|
+
switch(val){
|
|
498
|
+
case 'void':
|
|
499
|
+
case 'pause':
|
|
500
|
+
case 'reverse':
|
|
501
|
+
{
|
|
502
|
+
return val;
|
|
503
|
+
}
|
|
504
|
+
default:
|
|
505
|
+
{
|
|
506
|
+
return 'stop';
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
476
511
|
* Resizing to container.
|
|
477
512
|
*/ set objectfit(value) {
|
|
478
513
|
this.setAttribute('objectfit', value);
|
|
@@ -485,6 +520,34 @@ const notImplemented = 'Method is not implemented';
|
|
|
485
520
|
return ObjectFit.Contain;
|
|
486
521
|
}
|
|
487
522
|
/**
|
|
523
|
+
* Whether to play once or reset,
|
|
524
|
+
* if playOnVisible is true.
|
|
525
|
+
*/ set once(value) {
|
|
526
|
+
this.setAttribute('once', value.toString());
|
|
527
|
+
}
|
|
528
|
+
get once() {
|
|
529
|
+
const val = this.getAttribute('once');
|
|
530
|
+
return val === 'true' || val === '' || val === '1';
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Whether to toggle play on click.
|
|
534
|
+
*/ set playOnClick(value) {
|
|
535
|
+
this.setAttribute('playOnClick', value.toString());
|
|
536
|
+
}
|
|
537
|
+
get playOnClick() {
|
|
538
|
+
const val = this.getAttribute('playOnClick');
|
|
539
|
+
return val === 'true' || val === '' || val === '1';
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Play when visible.
|
|
543
|
+
*/ set playOnVisible(value) {
|
|
544
|
+
this.setAttribute('playOnVisible', value.toString());
|
|
545
|
+
}
|
|
546
|
+
get playOnVisible() {
|
|
547
|
+
const val = this.getAttribute('playOnVisible');
|
|
548
|
+
return val === 'true' || val === '' || val === '1';
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
488
551
|
* Resizing to container (Deprecated).
|
|
489
552
|
*/ set preserveAspectRatio(value) {
|
|
490
553
|
this.setAttribute('preserveAspectRatio', value || PreserveAspectRatio.Contain);
|
|
@@ -578,6 +641,7 @@ const notImplemented = 'Method is not implemented';
|
|
|
578
641
|
this._enterFrame = this._enterFrame.bind(this);
|
|
579
642
|
this._freeze = this._freeze.bind(this);
|
|
580
643
|
this._handleBlur = this._handleBlur.bind(this);
|
|
644
|
+
this._handleClick = this._handleClick.bind(this);
|
|
581
645
|
this._handleScroll = this._handleScroll.bind(this);
|
|
582
646
|
this._handleSeekChange = this._handleSeekChange.bind(this);
|
|
583
647
|
this._handleWindowBlur = this._handleWindowBlur.bind(this);
|
|
@@ -607,74 +671,113 @@ const notImplemented = 'Method is not implemented';
|
|
|
607
671
|
/**
|
|
608
672
|
* Runs when the value of an attribute is changed on the component.
|
|
609
673
|
*/ async attributeChangedCallback(name, _oldValue, value) {
|
|
610
|
-
if (!this._lottieInstance || !this.shadow) {
|
|
674
|
+
if (!this._lottieInstance || !this.shadow || !this._container) {
|
|
611
675
|
return;
|
|
612
676
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
677
|
+
switch(name){
|
|
678
|
+
case 'animateOnScroll':
|
|
679
|
+
{
|
|
680
|
+
if (value === '' || Boolean(value)) {
|
|
681
|
+
this._lottieInstance.autoplay = false;
|
|
682
|
+
addEventListener('scroll', this._handleScroll, {
|
|
683
|
+
capture: true,
|
|
684
|
+
passive: true
|
|
685
|
+
});
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
removeEventListener('scroll', this._handleScroll, true);
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
case 'autoplay':
|
|
692
|
+
{
|
|
693
|
+
if (this.animateOnScroll || this.playOnVisible) {
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
if (value === '' || Boolean(value)) {
|
|
697
|
+
this.play();
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
this.stop();
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
case 'controls':
|
|
704
|
+
{
|
|
705
|
+
this._renderControls();
|
|
706
|
+
break;
|
|
707
|
+
}
|
|
708
|
+
case 'direction':
|
|
709
|
+
{
|
|
710
|
+
if (Number(value) === -1) {
|
|
711
|
+
this.setDirection(-1);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
this.setDirection(1);
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
case 'hover':
|
|
718
|
+
{
|
|
719
|
+
if (value === '' || Boolean(value)) {
|
|
720
|
+
this._container.addEventListener('mouseenter', this._mouseEnter);
|
|
721
|
+
this._container.addEventListener('mouseleave', this._mouseLeave);
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
this._container.removeEventListener('mouseenter', this._mouseEnter);
|
|
725
|
+
this._container.removeEventListener('mouseleave', this._mouseLeave);
|
|
726
|
+
break;
|
|
727
|
+
}
|
|
728
|
+
case 'loop':
|
|
729
|
+
{
|
|
730
|
+
const toggleLoop = this.shadow.querySelector('.toggleLoop');
|
|
731
|
+
if (toggleLoop instanceof HTMLButtonElement) {
|
|
732
|
+
toggleLoop.dataset.active = value;
|
|
733
|
+
}
|
|
734
|
+
this.setLoop(value === '' || Boolean(value));
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
case 'mode':
|
|
738
|
+
{
|
|
739
|
+
const toggleBoomerang = this.shadow.querySelector('.toggleBoomerang');
|
|
740
|
+
if (toggleBoomerang instanceof HTMLButtonElement) {
|
|
741
|
+
toggleBoomerang.dataset.active = (value === PlayMode.Bounce).toString();
|
|
742
|
+
}
|
|
743
|
+
this._isBounce = value === PlayMode.Bounce;
|
|
744
|
+
break;
|
|
745
|
+
}
|
|
746
|
+
case 'playOnClick':
|
|
747
|
+
{
|
|
748
|
+
if (value === '' || Boolean(value)) {
|
|
749
|
+
this._lottieInstance.autoplay = false;
|
|
750
|
+
this._container.addEventListener('click', this._handleClick);
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
this._container.removeEventListener('click', this._handleClick);
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
case 'playOnVisible':
|
|
757
|
+
{
|
|
758
|
+
if (value === '' || Boolean(value)) {
|
|
759
|
+
this._lottieInstance.autoplay = false;
|
|
760
|
+
}
|
|
761
|
+
break;
|
|
762
|
+
}
|
|
763
|
+
case 'speed':
|
|
764
|
+
{
|
|
765
|
+
const val = Number(value);
|
|
766
|
+
if (val && !isNaN(val)) {
|
|
767
|
+
this.setSpeed(val);
|
|
768
|
+
}
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
case 'src':
|
|
772
|
+
{
|
|
773
|
+
await this.load(value);
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
case 'subframe':
|
|
777
|
+
{
|
|
778
|
+
this.setSubframe(value === '' || Boolean(value));
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
678
781
|
}
|
|
679
782
|
}
|
|
680
783
|
/**
|
|
@@ -688,14 +791,14 @@ const notImplemented = 'Method is not implemented';
|
|
|
688
791
|
throw new Error('Missing Shadow element');
|
|
689
792
|
}
|
|
690
793
|
this._container = this.shadow.querySelector('.animation');
|
|
794
|
+
// Setup lottie player
|
|
795
|
+
await this.load(this.src);
|
|
691
796
|
// Add listener for Visibility API's change event.
|
|
692
797
|
if (typeof document.hidden !== 'undefined') {
|
|
693
798
|
document.addEventListener('visibilitychange', this._onVisibilityChange);
|
|
694
799
|
}
|
|
695
800
|
// Add intersection observer for detecting component being out-of-view.
|
|
696
801
|
this._addIntersectionObserver();
|
|
697
|
-
// Setup lottie player
|
|
698
|
-
await this.load(this.src);
|
|
699
802
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Rendered));
|
|
700
803
|
})();
|
|
701
804
|
} catch (error) {
|
|
@@ -769,9 +872,10 @@ const notImplemented = 'Method is not implemented';
|
|
|
769
872
|
if (this._multiAnimationSettings.length > 0 && this._multiAnimationSettings[this._currentAnimation]?.mode) {
|
|
770
873
|
this._isBounce = this._multiAnimationSettings[this._currentAnimation]?.mode === PlayMode.Bounce;
|
|
771
874
|
}
|
|
875
|
+
// Relevant for dotLotties with multiple animations
|
|
772
876
|
const firstAnimation = manifest?.animations[0];
|
|
773
877
|
if (firstAnimation) {
|
|
774
|
-
firstAnimation.autoplay = this.autoplay;
|
|
878
|
+
firstAnimation.autoplay = !this.animateOnScroll && !this.playOnVisible && this.autoplay;
|
|
775
879
|
firstAnimation.loop = this.loop;
|
|
776
880
|
}
|
|
777
881
|
this._isDotLottie = isDotLottie;
|
|
@@ -779,7 +883,7 @@ const notImplemented = 'Method is not implemented';
|
|
|
779
883
|
this._manifest = manifest ?? {
|
|
780
884
|
animations: [
|
|
781
885
|
{
|
|
782
|
-
autoplay: !this.animateOnScroll && this.autoplay,
|
|
886
|
+
autoplay: !this.animateOnScroll && !this.playOnVisible && this.autoplay,
|
|
783
887
|
direction: this.direction,
|
|
784
888
|
id: createElementID(),
|
|
785
889
|
loop: this.loop,
|
|
@@ -791,7 +895,8 @@ const notImplemented = 'Method is not implemented';
|
|
|
791
895
|
// Clear previous animation, if any
|
|
792
896
|
this._lottieInstance?.destroy();
|
|
793
897
|
this.playerState = PlayerState.Stopped;
|
|
794
|
-
if (!this.animateOnScroll &&
|
|
898
|
+
if (!this.animateOnScroll && // !this.playOnVisible &&
|
|
899
|
+
(this.autoplay || this._multiAnimationSettings[this._currentAnimation]?.autoplay || this.playOnVisible)) {
|
|
795
900
|
this.playerState = PlayerState.Playing;
|
|
796
901
|
}
|
|
797
902
|
// Initialize lottie player and load animation
|
|
@@ -806,20 +911,18 @@ const notImplemented = 'Method is not implemented';
|
|
|
806
911
|
this._lottieInstance.setDirection(direction);
|
|
807
912
|
this._lottieInstance.setSubframe(Boolean(this.subframe));
|
|
808
913
|
// Start playing if autoplay is enabled
|
|
809
|
-
if (this.autoplay || this.animateOnScroll) {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
}
|
|
819
|
-
this._addIntersectionObserver();
|
|
914
|
+
if ((this.autoplay || this.animateOnScroll || this.playOnVisible) && this.direction === -1) {
|
|
915
|
+
this.seek('99%');
|
|
916
|
+
// if (!('IntersectionObserver' in window)) {
|
|
917
|
+
// if (!this.animateOnScroll) {
|
|
918
|
+
// this.play()
|
|
919
|
+
// }
|
|
920
|
+
// this._playerState.visible = true
|
|
921
|
+
// }
|
|
922
|
+
// this._addIntersectionObserver()
|
|
820
923
|
}
|
|
821
924
|
this._renderControls();
|
|
822
|
-
if (this.autoplay) {
|
|
925
|
+
if (this.autoplay || this.playOnVisible) {
|
|
823
926
|
const togglePlay = this.shadow?.querySelector('.togglePlay');
|
|
824
927
|
if (togglePlay) {
|
|
825
928
|
togglePlay.innerHTML = pauseIcon;
|
|
@@ -848,11 +951,15 @@ const notImplemented = 'Method is not implemented';
|
|
|
848
951
|
return;
|
|
849
952
|
}
|
|
850
953
|
this._playerState.prev = this.playerState;
|
|
954
|
+
let hasError = false;
|
|
851
955
|
try {
|
|
852
956
|
this._lottieInstance.pause();
|
|
853
957
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Pause));
|
|
958
|
+
} catch (error) {
|
|
959
|
+
hasError = true;
|
|
960
|
+
console.error(error);
|
|
854
961
|
} finally{
|
|
855
|
-
this.playerState = PlayerState.Paused;
|
|
962
|
+
this.playerState = hasError ? PlayerState.Error : PlayerState.Paused;
|
|
856
963
|
}
|
|
857
964
|
}
|
|
858
965
|
/**
|
|
@@ -862,11 +969,15 @@ const notImplemented = 'Method is not implemented';
|
|
|
862
969
|
return;
|
|
863
970
|
}
|
|
864
971
|
this._playerState.prev = this.playerState;
|
|
972
|
+
let hasError = false;
|
|
865
973
|
try {
|
|
866
974
|
this._lottieInstance.play();
|
|
867
975
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Play));
|
|
976
|
+
} catch (error) {
|
|
977
|
+
hasError = true;
|
|
978
|
+
console.error(error);
|
|
868
979
|
} finally{
|
|
869
|
-
this.playerState = PlayerState.Playing;
|
|
980
|
+
this.playerState = hasError ? PlayerState.Error : PlayerState.Playing;
|
|
870
981
|
}
|
|
871
982
|
}
|
|
872
983
|
/**
|
|
@@ -1124,6 +1235,14 @@ const notImplemented = 'Method is not implemented';
|
|
|
1124
1235
|
}, 200);
|
|
1125
1236
|
}
|
|
1126
1237
|
/**
|
|
1238
|
+
* Handle click.
|
|
1239
|
+
*/ _handleClick() {
|
|
1240
|
+
if (!this.playOnClick) {
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
this.togglePlay();
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1127
1246
|
* Handles click and drag actions on the progress track.
|
|
1128
1247
|
*/ _handleSeekChange({ target }) {
|
|
1129
1248
|
if (!(target instanceof HTMLInputElement) || !this._lottieInstance || isNaN(Number(target.value))) {
|
|
@@ -1151,7 +1270,16 @@ const notImplemented = 'Method is not implemented';
|
|
|
1151
1270
|
/**
|
|
1152
1271
|
* Add IntersectionObserver.
|
|
1153
1272
|
*/ _addIntersectionObserver() {
|
|
1154
|
-
if (!this._container || this._intersectionObserver
|
|
1273
|
+
if (!this._container || this._intersectionObserver) {
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
if (!('IntersectionObserver' in window)) {
|
|
1277
|
+
this._intersectionObserverFallback();
|
|
1278
|
+
removeEventListener('scroll', this._intersectionObserverFallback, true);
|
|
1279
|
+
addEventListener('scroll', this._intersectionObserverFallback, {
|
|
1280
|
+
capture: true,
|
|
1281
|
+
passive: true
|
|
1282
|
+
});
|
|
1155
1283
|
return;
|
|
1156
1284
|
}
|
|
1157
1285
|
this._intersectionObserver = new IntersectionObserver((entries)=>{
|
|
@@ -1164,10 +1292,25 @@ const notImplemented = 'Method is not implemented';
|
|
|
1164
1292
|
this._playerState.visible = false;
|
|
1165
1293
|
continue;
|
|
1166
1294
|
}
|
|
1167
|
-
if (!this.animateOnScroll && this.playerState === PlayerState.Frozen) {
|
|
1295
|
+
if (!this.animateOnScroll && !this.playOnVisible && this.playerState === PlayerState.Frozen) {
|
|
1168
1296
|
this.play();
|
|
1169
1297
|
}
|
|
1170
|
-
if (
|
|
1298
|
+
if (this.playOnVisible) {
|
|
1299
|
+
if (this.playerState === PlayerState.Completed && !this.once) {
|
|
1300
|
+
this.playerState = PlayerState.Playing;
|
|
1301
|
+
this._lottieInstance?.goToAndPlay(this.direction === 1 ? 0 : this._lottieInstance.totalFrames);
|
|
1302
|
+
} else {
|
|
1303
|
+
setTimeout(()=>{
|
|
1304
|
+
this.play();
|
|
1305
|
+
}, this.delay);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* If the player is a ways down the page, we need to account for this by
|
|
1310
|
+
* setting _playerState.scrollY to the current scroll position. However, we
|
|
1311
|
+
* also need to check that the player hasn't been scrolled past, so we check
|
|
1312
|
+
* boundingClientRect as well.
|
|
1313
|
+
*/ if (!this._playerState.scrollY && (entries[i]?.boundingClientRect.y || 0) > 0) {
|
|
1171
1314
|
this._playerState.scrollY = scrollY;
|
|
1172
1315
|
}
|
|
1173
1316
|
this._playerState.visible = true;
|
|
@@ -1309,6 +1452,20 @@ const notImplemented = 'Method is not implemented';
|
|
|
1309
1452
|
this.play();
|
|
1310
1453
|
}
|
|
1311
1454
|
}
|
|
1455
|
+
_intersectionObserverFallback() {
|
|
1456
|
+
if (!this._container) {
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
const { bottom, left, right, top } = this._container.getBoundingClientRect();
|
|
1460
|
+
this._playerState.visible = top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
|
1461
|
+
if (this.autoplay || this.playOnVisible || this.playerState === PlayerState.Playing || this.playerState === PlayerState.Frozen) {
|
|
1462
|
+
if (this._playerState.visible) {
|
|
1463
|
+
this.play();
|
|
1464
|
+
} else {
|
|
1465
|
+
this._freeze();
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1312
1469
|
_loopComplete() {
|
|
1313
1470
|
if (!this._lottieInstance) {
|
|
1314
1471
|
return;
|
|
@@ -1348,15 +1505,51 @@ const notImplemented = 'Method is not implemented';
|
|
|
1348
1505
|
/**
|
|
1349
1506
|
* Handle MouseEnter.
|
|
1350
1507
|
*/ _mouseEnter() {
|
|
1351
|
-
if (this.hover
|
|
1508
|
+
if (!this.hover || !this._lottieInstance || isTouch()) {
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
if (this.mouseout === 'reverse') {
|
|
1512
|
+
this._lottieInstance.setDirection(1);
|
|
1513
|
+
}
|
|
1514
|
+
if (this.playerState === PlayerState.Completed) {
|
|
1515
|
+
this._lottieInstance.goToAndPlay(0, true);
|
|
1516
|
+
this.playerState = PlayerState.Playing;
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
if (this.playerState !== PlayerState.Playing) {
|
|
1352
1520
|
this.play();
|
|
1353
1521
|
}
|
|
1354
1522
|
}
|
|
1355
1523
|
/**
|
|
1356
1524
|
* Handle MouseLeave.
|
|
1357
1525
|
*/ _mouseLeave() {
|
|
1358
|
-
if (this.hover
|
|
1359
|
-
|
|
1526
|
+
if (!this.hover || !this._lottieInstance || isTouch()) {
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
switch(this.mouseout){
|
|
1530
|
+
case 'void':
|
|
1531
|
+
{
|
|
1532
|
+
break;
|
|
1533
|
+
}
|
|
1534
|
+
case 'pause':
|
|
1535
|
+
{
|
|
1536
|
+
this.pause();
|
|
1537
|
+
break;
|
|
1538
|
+
}
|
|
1539
|
+
case 'reverse':
|
|
1540
|
+
{
|
|
1541
|
+
// const { direction = 1 } =
|
|
1542
|
+
// this._multiAnimationSettings.length > 0 ?
|
|
1543
|
+
// this._multiAnimationSettings[this._currentAnimation + 1] ?? { direction: 1 } : this,
|
|
1544
|
+
// newDirection = direction * -1 as AnimationDirection
|
|
1545
|
+
this._lottieInstance.setDirection(-1);
|
|
1546
|
+
this.play();
|
|
1547
|
+
break;
|
|
1548
|
+
}
|
|
1549
|
+
default:
|
|
1550
|
+
{
|
|
1551
|
+
this.stop();
|
|
1552
|
+
}
|
|
1360
1553
|
}
|
|
1361
1554
|
}
|
|
1362
1555
|
/**
|
|
@@ -1428,9 +1621,14 @@ const notImplemented = 'Method is not implemented';
|
|
|
1428
1621
|
this._lottieInstance[method]('data_ready', this._dataReady);
|
|
1429
1622
|
this._lottieInstance[method]('data_failed', this._dataFailed);
|
|
1430
1623
|
}
|
|
1431
|
-
if (this._container
|
|
1432
|
-
|
|
1433
|
-
|
|
1624
|
+
if (this._container) {
|
|
1625
|
+
if (this.hover) {
|
|
1626
|
+
this._container[method]('mouseenter', this._mouseEnter);
|
|
1627
|
+
this._container[method]('mouseleave', this._mouseLeave);
|
|
1628
|
+
}
|
|
1629
|
+
if (this.playOnClick) {
|
|
1630
|
+
this._container[method]('click', this._handleClick);
|
|
1631
|
+
}
|
|
1434
1632
|
}
|
|
1435
1633
|
window[method]('focus', this._handleWindowBlur, {
|
|
1436
1634
|
capture: false,
|