@aarsteinmedia/dotlottie-player 6.0.5 → 6.1.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/CHANGELOG.md +12 -0
- package/README.md +8 -0
- package/dist/canvas.d.ts +16 -2
- package/dist/canvas.js +332 -94
- package/dist/full.d.ts +16 -2
- package/dist/full.js +332 -94
- package/dist/light.d.ts +16 -2
- package/dist/light.js +332 -94
- package/dist/svg.d.ts +16 -2
- package/dist/svg.js +332 -94
- package/dist/unpkg-canvas.js +9 -9
- package/dist/unpkg-full.js +8 -8
- package/dist/unpkg-light.js +5 -5
- package/dist/unpkg-svg.js +8 -8
- package/package.json +16 -15
package/dist/full.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,11 @@ const notImplemented = 'Method is not implemented';
|
|
|
319
319
|
'direction',
|
|
320
320
|
'hover',
|
|
321
321
|
'loop',
|
|
322
|
+
// 'mouseout',
|
|
322
323
|
'mode',
|
|
324
|
+
'playOnClick',
|
|
325
|
+
'playOnVisible',
|
|
326
|
+
'selector',
|
|
323
327
|
'speed',
|
|
324
328
|
'src',
|
|
325
329
|
'subframe'
|
|
@@ -397,6 +401,18 @@ const notImplemented = 'Method is not implemented';
|
|
|
397
401
|
return this._currentAnimation;
|
|
398
402
|
}
|
|
399
403
|
/**
|
|
404
|
+
* Delay playback on playOnVisible.
|
|
405
|
+
*/ set delay(value) {
|
|
406
|
+
this.setAttribute('delay', value.toString());
|
|
407
|
+
}
|
|
408
|
+
get delay() {
|
|
409
|
+
const val = this.getAttribute('delay');
|
|
410
|
+
if (val) {
|
|
411
|
+
return Number(val);
|
|
412
|
+
}
|
|
413
|
+
return 0;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
400
416
|
* Description for screen readers.
|
|
401
417
|
*/ set description(value) {
|
|
402
418
|
if (value) {
|
|
@@ -473,6 +489,26 @@ const notImplemented = 'Method is not implemented';
|
|
|
473
489
|
return PlayMode.Normal;
|
|
474
490
|
}
|
|
475
491
|
/**
|
|
492
|
+
* Action on mouseout.
|
|
493
|
+
*/ set mouseout(value) {
|
|
494
|
+
this.setAttribute('mouseout', value);
|
|
495
|
+
}
|
|
496
|
+
get mouseout() {
|
|
497
|
+
const val = this.getAttribute('mouseout');
|
|
498
|
+
switch(val){
|
|
499
|
+
case 'void':
|
|
500
|
+
case 'pause':
|
|
501
|
+
case 'reverse':
|
|
502
|
+
{
|
|
503
|
+
return val;
|
|
504
|
+
}
|
|
505
|
+
default:
|
|
506
|
+
{
|
|
507
|
+
return 'stop';
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
476
512
|
* Resizing to container.
|
|
477
513
|
*/ set objectfit(value) {
|
|
478
514
|
this.setAttribute('objectfit', value);
|
|
@@ -485,6 +521,34 @@ const notImplemented = 'Method is not implemented';
|
|
|
485
521
|
return ObjectFit.Contain;
|
|
486
522
|
}
|
|
487
523
|
/**
|
|
524
|
+
* Whether to play once or reset,
|
|
525
|
+
* if playOnVisible is true.
|
|
526
|
+
*/ set once(value) {
|
|
527
|
+
this.setAttribute('once', value.toString());
|
|
528
|
+
}
|
|
529
|
+
get once() {
|
|
530
|
+
const val = this.getAttribute('once');
|
|
531
|
+
return val === 'true' || val === '' || val === '1';
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Whether to toggle play on click.
|
|
535
|
+
*/ set playOnClick(value) {
|
|
536
|
+
this.setAttribute('playOnClick', value.toString());
|
|
537
|
+
}
|
|
538
|
+
get playOnClick() {
|
|
539
|
+
const val = this.getAttribute('playOnClick');
|
|
540
|
+
return val === 'true' || val === '' || val === '1';
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Play when visible.
|
|
544
|
+
*/ set playOnVisible(value) {
|
|
545
|
+
this.setAttribute('playOnVisible', value.toString());
|
|
546
|
+
}
|
|
547
|
+
get playOnVisible() {
|
|
548
|
+
const val = this.getAttribute('playOnVisible');
|
|
549
|
+
return val === 'true' || val === '' || val === '1';
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
488
552
|
* Resizing to container (Deprecated).
|
|
489
553
|
*/ set preserveAspectRatio(value) {
|
|
490
554
|
this.setAttribute('preserveAspectRatio', value || PreserveAspectRatio.Contain);
|
|
@@ -509,6 +573,18 @@ const notImplemented = 'Method is not implemented';
|
|
|
509
573
|
return RendererType.SVG;
|
|
510
574
|
}
|
|
511
575
|
/**
|
|
576
|
+
* Play on clicked element by id attribute, other than animation.
|
|
577
|
+
*/ set selector(value) {
|
|
578
|
+
if (value) {
|
|
579
|
+
this.setAttribute('selector', value);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
this.removeAttribute('selector');
|
|
583
|
+
}
|
|
584
|
+
get selector() {
|
|
585
|
+
return this.getAttribute('selector');
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
512
588
|
* Hide advanced controls.
|
|
513
589
|
*/ set simple(value) {
|
|
514
590
|
this.setAttribute('simple', value.toString());
|
|
@@ -578,6 +654,7 @@ const notImplemented = 'Method is not implemented';
|
|
|
578
654
|
this._enterFrame = this._enterFrame.bind(this);
|
|
579
655
|
this._freeze = this._freeze.bind(this);
|
|
580
656
|
this._handleBlur = this._handleBlur.bind(this);
|
|
657
|
+
this._handleClick = this._handleClick.bind(this);
|
|
581
658
|
this._handleScroll = this._handleScroll.bind(this);
|
|
582
659
|
this._handleSeekChange = this._handleSeekChange.bind(this);
|
|
583
660
|
this._handleWindowBlur = this._handleWindowBlur.bind(this);
|
|
@@ -607,74 +684,119 @@ const notImplemented = 'Method is not implemented';
|
|
|
607
684
|
/**
|
|
608
685
|
* Runs when the value of an attribute is changed on the component.
|
|
609
686
|
*/ async attributeChangedCallback(name, _oldValue, value) {
|
|
610
|
-
if (!this._lottieInstance || !this.shadow) {
|
|
687
|
+
if (!this._lottieInstance || !this.shadow || !this._container) {
|
|
611
688
|
return;
|
|
612
689
|
}
|
|
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
|
-
|
|
690
|
+
switch(name){
|
|
691
|
+
case 'animateOnScroll':
|
|
692
|
+
{
|
|
693
|
+
if (value === '' || Boolean(value)) {
|
|
694
|
+
this._lottieInstance.autoplay = false;
|
|
695
|
+
addEventListener('scroll', this._handleScroll, {
|
|
696
|
+
capture: true,
|
|
697
|
+
passive: true
|
|
698
|
+
});
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
removeEventListener('scroll', this._handleScroll, true);
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
case 'autoplay':
|
|
705
|
+
{
|
|
706
|
+
if (this.animateOnScroll || this.playOnVisible) {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
if (value === '' || Boolean(value)) {
|
|
710
|
+
this.play();
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
this.stop();
|
|
714
|
+
break;
|
|
715
|
+
}
|
|
716
|
+
case 'controls':
|
|
717
|
+
{
|
|
718
|
+
this._renderControls();
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
case 'direction':
|
|
722
|
+
{
|
|
723
|
+
if (Number(value) === -1) {
|
|
724
|
+
this.setDirection(-1);
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
this.setDirection(1);
|
|
728
|
+
break;
|
|
729
|
+
}
|
|
730
|
+
case 'hover':
|
|
731
|
+
{
|
|
732
|
+
if (value === '' || Boolean(value)) {
|
|
733
|
+
this._container.addEventListener('mouseenter', this._mouseEnter);
|
|
734
|
+
this._container.addEventListener('mouseleave', this._mouseLeave);
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
this._container.removeEventListener('mouseenter', this._mouseEnter);
|
|
738
|
+
this._container.removeEventListener('mouseleave', this._mouseLeave);
|
|
739
|
+
break;
|
|
740
|
+
}
|
|
741
|
+
case 'loop':
|
|
742
|
+
{
|
|
743
|
+
const toggleLoop = this.shadow.querySelector('.toggleLoop');
|
|
744
|
+
if (toggleLoop instanceof HTMLButtonElement) {
|
|
745
|
+
toggleLoop.dataset.active = value;
|
|
746
|
+
}
|
|
747
|
+
this.setLoop(value === '' || Boolean(value));
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
case 'mode':
|
|
751
|
+
{
|
|
752
|
+
const toggleBoomerang = this.shadow.querySelector('.toggleBoomerang');
|
|
753
|
+
if (toggleBoomerang instanceof HTMLButtonElement) {
|
|
754
|
+
toggleBoomerang.dataset.active = (value === PlayMode.Bounce).toString();
|
|
755
|
+
}
|
|
756
|
+
this._isBounce = value === PlayMode.Bounce;
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
case 'playOnClick':
|
|
760
|
+
{
|
|
761
|
+
if (value === '' || Boolean(value)) {
|
|
762
|
+
this._lottieInstance.autoplay = false;
|
|
763
|
+
this._container.addEventListener('click', this._handleClick);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
this._container.removeEventListener('click', this._handleClick);
|
|
767
|
+
break;
|
|
768
|
+
}
|
|
769
|
+
case 'playOnVisible':
|
|
770
|
+
{
|
|
771
|
+
if (value === '' || Boolean(value)) {
|
|
772
|
+
this._lottieInstance.autoplay = false;
|
|
773
|
+
}
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
case 'selector':
|
|
777
|
+
{
|
|
778
|
+
const selector = document.getElementById(this.selector ?? '');
|
|
779
|
+
selector?.addEventListener('click', this._handleClick);
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
case 'speed':
|
|
783
|
+
{
|
|
784
|
+
const val = Number(value);
|
|
785
|
+
if (val && !isNaN(val)) {
|
|
786
|
+
this.setSpeed(val);
|
|
787
|
+
}
|
|
788
|
+
break;
|
|
789
|
+
}
|
|
790
|
+
case 'src':
|
|
791
|
+
{
|
|
792
|
+
await this.load(value);
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
case 'subframe':
|
|
796
|
+
{
|
|
797
|
+
this.setSubframe(value === '' || Boolean(value));
|
|
798
|
+
break;
|
|
799
|
+
}
|
|
678
800
|
}
|
|
679
801
|
}
|
|
680
802
|
/**
|
|
@@ -688,14 +810,14 @@ const notImplemented = 'Method is not implemented';
|
|
|
688
810
|
throw new Error('Missing Shadow element');
|
|
689
811
|
}
|
|
690
812
|
this._container = this.shadow.querySelector('.animation');
|
|
813
|
+
// Setup lottie player
|
|
814
|
+
await this.load(this.src);
|
|
691
815
|
// Add listener for Visibility API's change event.
|
|
692
816
|
if (typeof document.hidden !== 'undefined') {
|
|
693
817
|
document.addEventListener('visibilitychange', this._onVisibilityChange);
|
|
694
818
|
}
|
|
695
819
|
// Add intersection observer for detecting component being out-of-view.
|
|
696
820
|
this._addIntersectionObserver();
|
|
697
|
-
// Setup lottie player
|
|
698
|
-
await this.load(this.src);
|
|
699
821
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Rendered));
|
|
700
822
|
})();
|
|
701
823
|
} catch (error) {
|
|
@@ -765,13 +887,27 @@ const notImplemented = 'Method is not implemented';
|
|
|
765
887
|
if (!animations || animations.some((animation)=>!isLottie(animation))) {
|
|
766
888
|
throw new Error('Broken or corrupted file');
|
|
767
889
|
}
|
|
890
|
+
const ldScript = this.parentElement?.querySelector('script[type="application/ld+json"]');
|
|
891
|
+
if (ldScript) {
|
|
892
|
+
const settings = JSON.parse(ldScript.innerHTML);
|
|
893
|
+
if (settings.selector) {
|
|
894
|
+
this.selector = settings.selector;
|
|
895
|
+
}
|
|
896
|
+
if (settings.segment) {
|
|
897
|
+
this.setSegment(settings.segment);
|
|
898
|
+
}
|
|
899
|
+
if (settings.multiAnimationSettings) {
|
|
900
|
+
this.setMultiAnimationSettings(settings.multiAnimationSettings);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
768
903
|
this._isBounce = this.mode === PlayMode.Bounce;
|
|
769
904
|
if (this._multiAnimationSettings.length > 0 && this._multiAnimationSettings[this._currentAnimation]?.mode) {
|
|
770
905
|
this._isBounce = this._multiAnimationSettings[this._currentAnimation]?.mode === PlayMode.Bounce;
|
|
771
906
|
}
|
|
907
|
+
// Relevant for dotLotties with multiple animations
|
|
772
908
|
const firstAnimation = manifest?.animations[0];
|
|
773
909
|
if (firstAnimation) {
|
|
774
|
-
firstAnimation.autoplay = this.autoplay;
|
|
910
|
+
firstAnimation.autoplay = !this.animateOnScroll && !this.playOnVisible && this.autoplay;
|
|
775
911
|
firstAnimation.loop = this.loop;
|
|
776
912
|
}
|
|
777
913
|
this._isDotLottie = isDotLottie;
|
|
@@ -779,7 +915,7 @@ const notImplemented = 'Method is not implemented';
|
|
|
779
915
|
this._manifest = manifest ?? {
|
|
780
916
|
animations: [
|
|
781
917
|
{
|
|
782
|
-
autoplay: !this.animateOnScroll && this.autoplay,
|
|
918
|
+
autoplay: !this.animateOnScroll && !this.playOnVisible && this.autoplay,
|
|
783
919
|
direction: this.direction,
|
|
784
920
|
id: createElementID(),
|
|
785
921
|
loop: this.loop,
|
|
@@ -791,7 +927,8 @@ const notImplemented = 'Method is not implemented';
|
|
|
791
927
|
// Clear previous animation, if any
|
|
792
928
|
this._lottieInstance?.destroy();
|
|
793
929
|
this.playerState = PlayerState.Stopped;
|
|
794
|
-
if (!this.animateOnScroll &&
|
|
930
|
+
if (!this.animateOnScroll && // !this.playOnVisible &&
|
|
931
|
+
(this.autoplay || this._multiAnimationSettings[this._currentAnimation]?.autoplay || this.playOnVisible)) {
|
|
795
932
|
this.playerState = PlayerState.Playing;
|
|
796
933
|
}
|
|
797
934
|
// Initialize lottie player and load animation
|
|
@@ -806,20 +943,18 @@ const notImplemented = 'Method is not implemented';
|
|
|
806
943
|
this._lottieInstance.setDirection(direction);
|
|
807
944
|
this._lottieInstance.setSubframe(Boolean(this.subframe));
|
|
808
945
|
// Start playing if autoplay is enabled
|
|
809
|
-
if (this.autoplay || this.animateOnScroll) {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
}
|
|
819
|
-
this._addIntersectionObserver();
|
|
946
|
+
if ((this.autoplay || this.animateOnScroll || this.playOnVisible) && this.direction === -1) {
|
|
947
|
+
this.seek('99%');
|
|
948
|
+
// if (!('IntersectionObserver' in window)) {
|
|
949
|
+
// if (!this.animateOnScroll) {
|
|
950
|
+
// this.play()
|
|
951
|
+
// }
|
|
952
|
+
// this._playerState.visible = true
|
|
953
|
+
// }
|
|
954
|
+
// this._addIntersectionObserver()
|
|
820
955
|
}
|
|
821
956
|
this._renderControls();
|
|
822
|
-
if (this.autoplay) {
|
|
957
|
+
if (this.autoplay || this.playOnVisible) {
|
|
823
958
|
const togglePlay = this.shadow?.querySelector('.togglePlay');
|
|
824
959
|
if (togglePlay) {
|
|
825
960
|
togglePlay.innerHTML = pauseIcon;
|
|
@@ -848,11 +983,15 @@ const notImplemented = 'Method is not implemented';
|
|
|
848
983
|
return;
|
|
849
984
|
}
|
|
850
985
|
this._playerState.prev = this.playerState;
|
|
986
|
+
let hasError = false;
|
|
851
987
|
try {
|
|
852
988
|
this._lottieInstance.pause();
|
|
853
989
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Pause));
|
|
990
|
+
} catch (error) {
|
|
991
|
+
hasError = true;
|
|
992
|
+
console.error(error);
|
|
854
993
|
} finally{
|
|
855
|
-
this.playerState = PlayerState.Paused;
|
|
994
|
+
this.playerState = hasError ? PlayerState.Error : PlayerState.Paused;
|
|
856
995
|
}
|
|
857
996
|
}
|
|
858
997
|
/**
|
|
@@ -862,11 +1001,15 @@ const notImplemented = 'Method is not implemented';
|
|
|
862
1001
|
return;
|
|
863
1002
|
}
|
|
864
1003
|
this._playerState.prev = this.playerState;
|
|
1004
|
+
let hasError = false;
|
|
865
1005
|
try {
|
|
866
1006
|
this._lottieInstance.play();
|
|
867
1007
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Play));
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
hasError = true;
|
|
1010
|
+
console.error(error);
|
|
868
1011
|
} finally{
|
|
869
|
-
this.playerState = PlayerState.Playing;
|
|
1012
|
+
this.playerState = hasError ? PlayerState.Error : PlayerState.Playing;
|
|
870
1013
|
}
|
|
871
1014
|
}
|
|
872
1015
|
/**
|
|
@@ -1124,6 +1267,14 @@ const notImplemented = 'Method is not implemented';
|
|
|
1124
1267
|
}, 200);
|
|
1125
1268
|
}
|
|
1126
1269
|
/**
|
|
1270
|
+
* Handle click.
|
|
1271
|
+
*/ _handleClick() {
|
|
1272
|
+
if (!this.playOnClick && !this.selector) {
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
this.togglePlay();
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1127
1278
|
* Handles click and drag actions on the progress track.
|
|
1128
1279
|
*/ _handleSeekChange({ target }) {
|
|
1129
1280
|
if (!(target instanceof HTMLInputElement) || !this._lottieInstance || isNaN(Number(target.value))) {
|
|
@@ -1151,7 +1302,16 @@ const notImplemented = 'Method is not implemented';
|
|
|
1151
1302
|
/**
|
|
1152
1303
|
* Add IntersectionObserver.
|
|
1153
1304
|
*/ _addIntersectionObserver() {
|
|
1154
|
-
if (!this._container || this._intersectionObserver
|
|
1305
|
+
if (!this._container || this._intersectionObserver) {
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
if (!('IntersectionObserver' in window)) {
|
|
1309
|
+
this._intersectionObserverFallback();
|
|
1310
|
+
removeEventListener('scroll', this._intersectionObserverFallback, true);
|
|
1311
|
+
addEventListener('scroll', this._intersectionObserverFallback, {
|
|
1312
|
+
capture: true,
|
|
1313
|
+
passive: true
|
|
1314
|
+
});
|
|
1155
1315
|
return;
|
|
1156
1316
|
}
|
|
1157
1317
|
this._intersectionObserver = new IntersectionObserver((entries)=>{
|
|
@@ -1164,9 +1324,19 @@ const notImplemented = 'Method is not implemented';
|
|
|
1164
1324
|
this._playerState.visible = false;
|
|
1165
1325
|
continue;
|
|
1166
1326
|
}
|
|
1167
|
-
if (!this.animateOnScroll && this.playerState === PlayerState.Frozen) {
|
|
1327
|
+
if (!this.animateOnScroll && !this.playOnVisible && this.playerState === PlayerState.Frozen) {
|
|
1168
1328
|
this.play();
|
|
1169
1329
|
}
|
|
1330
|
+
if (this.playOnVisible) {
|
|
1331
|
+
if (this.playerState === PlayerState.Completed && !this.once) {
|
|
1332
|
+
this.playerState = PlayerState.Playing;
|
|
1333
|
+
this._lottieInstance?.goToAndPlay(this.direction === 1 ? 0 : this._lottieInstance.totalFrames);
|
|
1334
|
+
} else {
|
|
1335
|
+
setTimeout(()=>{
|
|
1336
|
+
this.play();
|
|
1337
|
+
}, this.delay);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1170
1340
|
/**
|
|
1171
1341
|
* If the player is a ways down the page, we need to account for this by
|
|
1172
1342
|
* setting _playerState.scrollY to the current scroll position. However, we
|
|
@@ -1314,6 +1484,20 @@ const notImplemented = 'Method is not implemented';
|
|
|
1314
1484
|
this.play();
|
|
1315
1485
|
}
|
|
1316
1486
|
}
|
|
1487
|
+
_intersectionObserverFallback() {
|
|
1488
|
+
if (!this._container) {
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
const { bottom, left, right, top } = this._container.getBoundingClientRect();
|
|
1492
|
+
this._playerState.visible = top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
|
1493
|
+
if (this.autoplay || this.playOnVisible || this.playerState === PlayerState.Playing || this.playerState === PlayerState.Frozen) {
|
|
1494
|
+
if (this._playerState.visible) {
|
|
1495
|
+
this.play();
|
|
1496
|
+
} else {
|
|
1497
|
+
this._freeze();
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1317
1501
|
_loopComplete() {
|
|
1318
1502
|
if (!this._lottieInstance) {
|
|
1319
1503
|
return;
|
|
@@ -1353,15 +1537,51 @@ const notImplemented = 'Method is not implemented';
|
|
|
1353
1537
|
/**
|
|
1354
1538
|
* Handle MouseEnter.
|
|
1355
1539
|
*/ _mouseEnter() {
|
|
1356
|
-
if (this.hover
|
|
1540
|
+
if (!this.hover || !this._lottieInstance || isTouch()) {
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
if (this.mouseout === 'reverse') {
|
|
1544
|
+
this._lottieInstance.setDirection(1);
|
|
1545
|
+
}
|
|
1546
|
+
if (this.playerState === PlayerState.Completed) {
|
|
1547
|
+
this._lottieInstance.goToAndPlay(0, true);
|
|
1548
|
+
this.playerState = PlayerState.Playing;
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
if (this.playerState !== PlayerState.Playing) {
|
|
1357
1552
|
this.play();
|
|
1358
1553
|
}
|
|
1359
1554
|
}
|
|
1360
1555
|
/**
|
|
1361
1556
|
* Handle MouseLeave.
|
|
1362
1557
|
*/ _mouseLeave() {
|
|
1363
|
-
if (this.hover
|
|
1364
|
-
|
|
1558
|
+
if (!this.hover || !this._lottieInstance || isTouch()) {
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
switch(this.mouseout){
|
|
1562
|
+
case 'void':
|
|
1563
|
+
{
|
|
1564
|
+
break;
|
|
1565
|
+
}
|
|
1566
|
+
case 'pause':
|
|
1567
|
+
{
|
|
1568
|
+
this.pause();
|
|
1569
|
+
break;
|
|
1570
|
+
}
|
|
1571
|
+
case 'reverse':
|
|
1572
|
+
{
|
|
1573
|
+
// const { direction = 1 } =
|
|
1574
|
+
// this._multiAnimationSettings.length > 0 ?
|
|
1575
|
+
// this._multiAnimationSettings[this._currentAnimation + 1] ?? { direction: 1 } : this,
|
|
1576
|
+
// newDirection = direction * -1 as AnimationDirection
|
|
1577
|
+
this._lottieInstance.setDirection(-1);
|
|
1578
|
+
this.play();
|
|
1579
|
+
break;
|
|
1580
|
+
}
|
|
1581
|
+
default:
|
|
1582
|
+
{
|
|
1583
|
+
this.stop();
|
|
1584
|
+
}
|
|
1365
1585
|
}
|
|
1366
1586
|
}
|
|
1367
1587
|
/**
|
|
@@ -1433,9 +1653,27 @@ const notImplemented = 'Method is not implemented';
|
|
|
1433
1653
|
this._lottieInstance[method]('data_ready', this._dataReady);
|
|
1434
1654
|
this._lottieInstance[method]('data_failed', this._dataFailed);
|
|
1435
1655
|
}
|
|
1436
|
-
if (this.
|
|
1437
|
-
|
|
1438
|
-
|
|
1656
|
+
if (this.selector) {
|
|
1657
|
+
const selector = document.getElementById(this.selector);
|
|
1658
|
+
if (selector) {
|
|
1659
|
+
if (this.hover) {
|
|
1660
|
+
selector[method]('mouseenter', this._mouseEnter);
|
|
1661
|
+
selector[method]('mouseleave', this._mouseLeave);
|
|
1662
|
+
} else {
|
|
1663
|
+
selector[method]('click', this._handleClick);
|
|
1664
|
+
}
|
|
1665
|
+
} else {
|
|
1666
|
+
this.selector = null;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
if (this._container && !this.selector) {
|
|
1670
|
+
if (this.hover) {
|
|
1671
|
+
this._container[method]('mouseenter', this._mouseEnter);
|
|
1672
|
+
this._container[method]('mouseleave', this._mouseLeave);
|
|
1673
|
+
}
|
|
1674
|
+
if (this.playOnClick) {
|
|
1675
|
+
this._container[method]('click', this._handleClick);
|
|
1676
|
+
}
|
|
1439
1677
|
}
|
|
1440
1678
|
window[method]('focus', this._handleWindowBlur, {
|
|
1441
1679
|
capture: false,
|
package/dist/light.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ declare function renderControls(this: DotLottiePlayerBase): void;
|
|
|
111
111
|
declare function renderPlayer(this: DotLottiePlayerBase): Promise<void>;
|
|
112
112
|
|
|
113
113
|
declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
114
|
-
static get observedAttributes():
|
|
114
|
+
static get observedAttributes(): readonly ["animateOnScroll", "autoplay", "controls", "direction", "hover", "loop", "mode", "playOnClick", "playOnVisible", "selector", "speed", "src", "subframe"];
|
|
115
115
|
static get observedProperties(): string[];
|
|
116
116
|
static get styles(): () => Promise<CSSStyleSheet>;
|
|
117
117
|
isLight: boolean;
|
|
@@ -131,6 +131,8 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
131
131
|
set count(value: number);
|
|
132
132
|
get count(): number;
|
|
133
133
|
get currentAnimation(): number;
|
|
134
|
+
set delay(value: number);
|
|
135
|
+
get delay(): number;
|
|
134
136
|
set description(value: string | null);
|
|
135
137
|
get description(): string | null;
|
|
136
138
|
set direction(value: AnimationDirection);
|
|
@@ -146,12 +148,22 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
146
148
|
get loop(): Loop;
|
|
147
149
|
set mode(value: PlayMode);
|
|
148
150
|
get mode(): PlayMode;
|
|
151
|
+
set mouseout(value: 'void' | 'stop' | 'pause' | 'reverse');
|
|
152
|
+
get mouseout(): "void" | "stop" | "pause" | "reverse";
|
|
149
153
|
set objectfit(value: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down');
|
|
150
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;
|
|
151
161
|
set preserveAspectRatio(value: PreserveAspectRatio | null);
|
|
152
162
|
get preserveAspectRatio(): PreserveAspectRatio | null;
|
|
153
163
|
set renderer(value: RendererType);
|
|
154
164
|
get renderer(): RendererType;
|
|
165
|
+
set selector(value: string | null);
|
|
166
|
+
get selector(): string | null;
|
|
155
167
|
set simple(value: boolean);
|
|
156
168
|
get simple(): boolean;
|
|
157
169
|
set speed(value: number);
|
|
@@ -186,7 +198,7 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
186
198
|
private _segment?;
|
|
187
199
|
constructor();
|
|
188
200
|
addAnimation(_params: AddAnimationParams): Promise<Result>;
|
|
189
|
-
attributeChangedCallback(name:
|
|
201
|
+
attributeChangedCallback(name: typeof DotLottiePlayerBase.observedAttributes[number], _oldValue: unknown, value: string): Promise<void>;
|
|
190
202
|
connectedCallback(): void;
|
|
191
203
|
convert(_params: ConvertParams): Promise<Result>;
|
|
192
204
|
destroy(): void;
|
|
@@ -218,6 +230,7 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
218
230
|
togglePlay(): void;
|
|
219
231
|
protected _freeze(): void;
|
|
220
232
|
protected _handleBlur(): void;
|
|
233
|
+
protected _handleClick(): void;
|
|
221
234
|
protected _handleSeekChange({ target }: Event): void;
|
|
222
235
|
protected _handleSettingsClick({ target }: Event): void;
|
|
223
236
|
protected setOptions(_options: {
|
|
@@ -238,6 +251,7 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
238
251
|
private _getOptions;
|
|
239
252
|
private _handleScroll;
|
|
240
253
|
private _handleWindowBlur;
|
|
254
|
+
private _intersectionObserverFallback;
|
|
241
255
|
private _loopComplete;
|
|
242
256
|
private _mouseEnter;
|
|
243
257
|
private _mouseLeave;
|