@aarsteinmedia/dotlottie-player 6.1.0 → 6.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/CHANGELOG.md +8 -1
- package/README.md +1 -0
- package/dist/canvas.d.ts +3 -1
- package/dist/canvas.js +70 -19
- package/dist/full.d.ts +3 -1
- package/dist/full.js +70 -19
- package/dist/light.d.ts +3 -1
- package/dist/light.js +70 -19
- package/dist/svg.d.ts +3 -1
- package/dist/svg.js +70 -19
- package/dist/unpkg-canvas.js +17 -17
- package/dist/unpkg-full.js +17 -17
- package/dist/unpkg-light.js +16 -16
- package/dist/unpkg-svg.js +17 -17
- package/package.json +14 -14
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
Changelog was only added since [3.2.3], so it's not exhaustive. [Please report any missing noteable changes to us](https://github.com/aarsteinmedia/dotlottie-player/issues), and we'll add them promptly.
|
|
9
9
|
|
|
10
|
-
## [6.
|
|
10
|
+
## [6.2.0] - 13-10-2025
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Adjusted length of animation on animateOnScroll, to fit screen height dynamically.
|
|
15
|
+
|
|
16
|
+
## [6.1.1] - 13-10-2025
|
|
11
17
|
|
|
12
18
|
### Changed
|
|
13
19
|
|
|
@@ -17,6 +23,7 @@ Changelog was only added since [3.2.3], so it's not exhaustive. [Please report a
|
|
|
17
23
|
- `once` – Whether, if playOnVisible is true, to play once or anytime animation is in view
|
|
18
24
|
- `playOnClick` – Whether to toggle play on click
|
|
19
25
|
- `playOnVisible` – Play when visible
|
|
26
|
+
- `selector` – Play on clicked element by id attribute
|
|
20
27
|
|
|
21
28
|
## [6.0.5] - 12-09-2025
|
|
22
29
|
|
package/README.md
CHANGED
|
@@ -320,6 +320,7 @@ export default defineNuxtPlugin(({ vueApp }) => {
|
|
|
320
320
|
| `playOnClick` | Whether to toggle play on click | `boolean` | `false` |
|
|
321
321
|
| `playOnVisible` | Play when visible | `boolean` | `false` |
|
|
322
322
|
| `renderer` | Renderer to use | `svg` \| `canvas` \| `html` | `svg` |
|
|
323
|
+
| `selector` | Play on clicked element by id attribute | `string` | `undefined` |
|
|
323
324
|
| `speed` | Animation speed | `number` | `1` |
|
|
324
325
|
| `src` _(required)_ | URL to LottieJSON or dotLottie | `string` | `undefined` |
|
|
325
326
|
| `subframe` | When enabled this can help to reduce flicker on some animations, especially on Safari and iOS devices. | `boolean` | `false` |
|
package/dist/canvas.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(): readonly ["animateOnScroll", "autoplay", "controls", "direction", "hover", "loop", "mode", "playOnClick", "playOnVisible", "speed", "src", "subframe"];
|
|
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;
|
|
@@ -162,6 +162,8 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
162
162
|
get preserveAspectRatio(): PreserveAspectRatio | null;
|
|
163
163
|
set renderer(value: RendererType);
|
|
164
164
|
get renderer(): RendererType;
|
|
165
|
+
set selector(value: string | null);
|
|
166
|
+
get selector(): string | null;
|
|
165
167
|
set simple(value: boolean);
|
|
166
168
|
get simple(): boolean;
|
|
167
169
|
set speed(value: number);
|
package/dist/canvas.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isServer, PlayMode, PreserveAspectRatio, namespaceSVG, RendererType, createElementID, PlayerEvents, download, getFilename } from '@aarsteinmedia/lottie-web/utils';
|
|
1
|
+
import { isServer, PlayMode, PreserveAspectRatio, namespaceSVG, RendererType, createElementID, PlayerEvents, download, getFilename, clamp } from '@aarsteinmedia/lottie-web/utils';
|
|
2
2
|
export { PlayMode, PlayerEvents } from '@aarsteinmedia/lottie-web/utils';
|
|
3
3
|
import Lottie from '@aarsteinmedia/lottie-web/canvas';
|
|
4
4
|
import { convert, getAnimationData } from '@aarsteinmedia/lottie-web/dotlottie';
|
|
@@ -323,6 +323,7 @@ const notImplemented = 'Method is not implemented';
|
|
|
323
323
|
'mode',
|
|
324
324
|
'playOnClick',
|
|
325
325
|
'playOnVisible',
|
|
326
|
+
'selector',
|
|
326
327
|
'speed',
|
|
327
328
|
'src',
|
|
328
329
|
'subframe'
|
|
@@ -572,6 +573,18 @@ const notImplemented = 'Method is not implemented';
|
|
|
572
573
|
return RendererType.SVG;
|
|
573
574
|
}
|
|
574
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
|
+
/**
|
|
575
588
|
* Hide advanced controls.
|
|
576
589
|
*/ set simple(value) {
|
|
577
590
|
this.setAttribute('simple', value.toString());
|
|
@@ -760,6 +773,12 @@ const notImplemented = 'Method is not implemented';
|
|
|
760
773
|
}
|
|
761
774
|
break;
|
|
762
775
|
}
|
|
776
|
+
case 'selector':
|
|
777
|
+
{
|
|
778
|
+
const selector = document.getElementById(this.selector ?? '');
|
|
779
|
+
selector?.addEventListener('click', this._handleClick);
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
763
782
|
case 'speed':
|
|
764
783
|
{
|
|
765
784
|
const val = Number(value);
|
|
@@ -868,6 +887,19 @@ const notImplemented = 'Method is not implemented';
|
|
|
868
887
|
if (!animations || animations.some((animation)=>!isLottie(animation))) {
|
|
869
888
|
throw new Error('Broken or corrupted file');
|
|
870
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
|
+
}
|
|
871
903
|
this._isBounce = this.mode === PlayMode.Bounce;
|
|
872
904
|
if (this._multiAnimationSettings.length > 0 && this._multiAnimationSettings[this._currentAnimation]?.mode) {
|
|
873
905
|
this._isBounce = this._multiAnimationSettings[this._currentAnimation]?.mode === PlayMode.Bounce;
|
|
@@ -1237,7 +1269,7 @@ const notImplemented = 'Method is not implemented';
|
|
|
1237
1269
|
/**
|
|
1238
1270
|
* Handle click.
|
|
1239
1271
|
*/ _handleClick() {
|
|
1240
|
-
if (!this.playOnClick) {
|
|
1272
|
+
if (!this.playOnClick && !this.selector) {
|
|
1241
1273
|
return;
|
|
1242
1274
|
}
|
|
1243
1275
|
this.togglePlay();
|
|
@@ -1423,23 +1455,29 @@ const notImplemented = 'Method is not implemented';
|
|
|
1423
1455
|
console.warn('DotLottie: Scroll animations might not work properly in a Server Side Rendering context. Try to wrap this in a client component.');
|
|
1424
1456
|
return;
|
|
1425
1457
|
}
|
|
1426
|
-
if (this._playerState.visible) {
|
|
1427
|
-
|
|
1428
|
-
clearTimeout(this._playerState.scrollTimeout);
|
|
1429
|
-
}
|
|
1430
|
-
this._playerState.scrollTimeout = setTimeout(()=>{
|
|
1431
|
-
this.playerState = PlayerState.Paused;
|
|
1432
|
-
}, 400);
|
|
1433
|
-
const adjustedScroll = scrollY > this._playerState.scrollY ? scrollY - this._playerState.scrollY : this._playerState.scrollY - scrollY, clampedScroll = Math.min(Math.max(adjustedScroll / 3, 1), this._lottieInstance.totalFrames * 3), roundedScroll = clampedScroll / 3;
|
|
1434
|
-
requestAnimationFrame(()=>{
|
|
1435
|
-
if (roundedScroll < (this._lottieInstance?.totalFrames ?? 0)) {
|
|
1436
|
-
this.playerState = PlayerState.Playing;
|
|
1437
|
-
this._lottieInstance?.goToAndStop(roundedScroll, true);
|
|
1438
|
-
} else {
|
|
1439
|
-
this.playerState = PlayerState.Paused;
|
|
1440
|
-
}
|
|
1441
|
-
});
|
|
1458
|
+
if (!this._playerState.visible) {
|
|
1459
|
+
return;
|
|
1442
1460
|
}
|
|
1461
|
+
if (this._playerState.scrollTimeout) {
|
|
1462
|
+
clearTimeout(this._playerState.scrollTimeout);
|
|
1463
|
+
}
|
|
1464
|
+
this._playerState.scrollTimeout = setTimeout(()=>{
|
|
1465
|
+
this.playerState = PlayerState.Paused;
|
|
1466
|
+
}, 400);
|
|
1467
|
+
const { totalFrames } = this._lottieInstance;
|
|
1468
|
+
let scrollPosition = scrollY - this._playerState.scrollY;
|
|
1469
|
+
if (scrollY <= this._playerState.scrollY) {
|
|
1470
|
+
scrollPosition = this._playerState.scrollY - scrollY;
|
|
1471
|
+
}
|
|
1472
|
+
const scrollProgress = scrollPosition / innerHeight, currentFrame = clamp(scrollProgress * (totalFrames - 1), 1, totalFrames);
|
|
1473
|
+
requestAnimationFrame(()=>{
|
|
1474
|
+
if (currentFrame >= totalFrames) {
|
|
1475
|
+
this.playerState = PlayerState.Paused;
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
this.playerState = PlayerState.Playing;
|
|
1479
|
+
this._lottieInstance?.goToAndStop(currentFrame, true);
|
|
1480
|
+
});
|
|
1443
1481
|
}
|
|
1444
1482
|
_handleWindowBlur({ type }) {
|
|
1445
1483
|
if (this.dontFreezeOnBlur) {
|
|
@@ -1621,7 +1659,20 @@ const notImplemented = 'Method is not implemented';
|
|
|
1621
1659
|
this._lottieInstance[method]('data_ready', this._dataReady);
|
|
1622
1660
|
this._lottieInstance[method]('data_failed', this._dataFailed);
|
|
1623
1661
|
}
|
|
1624
|
-
if (this.
|
|
1662
|
+
if (this.selector) {
|
|
1663
|
+
const selector = document.getElementById(this.selector);
|
|
1664
|
+
if (selector) {
|
|
1665
|
+
if (this.hover) {
|
|
1666
|
+
selector[method]('mouseenter', this._mouseEnter);
|
|
1667
|
+
selector[method]('mouseleave', this._mouseLeave);
|
|
1668
|
+
} else {
|
|
1669
|
+
selector[method]('click', this._handleClick);
|
|
1670
|
+
}
|
|
1671
|
+
} else {
|
|
1672
|
+
this.selector = null;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
if (this._container && !this.selector) {
|
|
1625
1676
|
if (this.hover) {
|
|
1626
1677
|
this._container[method]('mouseenter', this._mouseEnter);
|
|
1627
1678
|
this._container[method]('mouseleave', this._mouseLeave);
|
package/dist/full.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(): readonly ["animateOnScroll", "autoplay", "controls", "direction", "hover", "loop", "mode", "playOnClick", "playOnVisible", "speed", "src", "subframe"];
|
|
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;
|
|
@@ -162,6 +162,8 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
162
162
|
get preserveAspectRatio(): PreserveAspectRatio | null;
|
|
163
163
|
set renderer(value: RendererType);
|
|
164
164
|
get renderer(): RendererType;
|
|
165
|
+
set selector(value: string | null);
|
|
166
|
+
get selector(): string | null;
|
|
165
167
|
set simple(value: boolean);
|
|
166
168
|
get simple(): boolean;
|
|
167
169
|
set speed(value: number);
|
package/dist/full.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isServer, PlayMode, PreserveAspectRatio, namespaceSVG, RendererType, createElementID, PlayerEvents, download, getFilename } from '@aarsteinmedia/lottie-web/utils';
|
|
1
|
+
import { isServer, PlayMode, PreserveAspectRatio, namespaceSVG, RendererType, createElementID, PlayerEvents, download, getFilename, clamp } from '@aarsteinmedia/lottie-web/utils';
|
|
2
2
|
export { PlayMode, PlayerEvents } from '@aarsteinmedia/lottie-web/utils';
|
|
3
3
|
import Lottie from '@aarsteinmedia/lottie-web';
|
|
4
4
|
import { convert, getAnimationData, addAnimation } from '@aarsteinmedia/lottie-web/dotlottie';
|
|
@@ -323,6 +323,7 @@ const notImplemented = 'Method is not implemented';
|
|
|
323
323
|
'mode',
|
|
324
324
|
'playOnClick',
|
|
325
325
|
'playOnVisible',
|
|
326
|
+
'selector',
|
|
326
327
|
'speed',
|
|
327
328
|
'src',
|
|
328
329
|
'subframe'
|
|
@@ -572,6 +573,18 @@ const notImplemented = 'Method is not implemented';
|
|
|
572
573
|
return RendererType.SVG;
|
|
573
574
|
}
|
|
574
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
|
+
/**
|
|
575
588
|
* Hide advanced controls.
|
|
576
589
|
*/ set simple(value) {
|
|
577
590
|
this.setAttribute('simple', value.toString());
|
|
@@ -760,6 +773,12 @@ const notImplemented = 'Method is not implemented';
|
|
|
760
773
|
}
|
|
761
774
|
break;
|
|
762
775
|
}
|
|
776
|
+
case 'selector':
|
|
777
|
+
{
|
|
778
|
+
const selector = document.getElementById(this.selector ?? '');
|
|
779
|
+
selector?.addEventListener('click', this._handleClick);
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
763
782
|
case 'speed':
|
|
764
783
|
{
|
|
765
784
|
const val = Number(value);
|
|
@@ -868,6 +887,19 @@ const notImplemented = 'Method is not implemented';
|
|
|
868
887
|
if (!animations || animations.some((animation)=>!isLottie(animation))) {
|
|
869
888
|
throw new Error('Broken or corrupted file');
|
|
870
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
|
+
}
|
|
871
903
|
this._isBounce = this.mode === PlayMode.Bounce;
|
|
872
904
|
if (this._multiAnimationSettings.length > 0 && this._multiAnimationSettings[this._currentAnimation]?.mode) {
|
|
873
905
|
this._isBounce = this._multiAnimationSettings[this._currentAnimation]?.mode === PlayMode.Bounce;
|
|
@@ -1237,7 +1269,7 @@ const notImplemented = 'Method is not implemented';
|
|
|
1237
1269
|
/**
|
|
1238
1270
|
* Handle click.
|
|
1239
1271
|
*/ _handleClick() {
|
|
1240
|
-
if (!this.playOnClick) {
|
|
1272
|
+
if (!this.playOnClick && !this.selector) {
|
|
1241
1273
|
return;
|
|
1242
1274
|
}
|
|
1243
1275
|
this.togglePlay();
|
|
@@ -1423,23 +1455,29 @@ const notImplemented = 'Method is not implemented';
|
|
|
1423
1455
|
console.warn('DotLottie: Scroll animations might not work properly in a Server Side Rendering context. Try to wrap this in a client component.');
|
|
1424
1456
|
return;
|
|
1425
1457
|
}
|
|
1426
|
-
if (this._playerState.visible) {
|
|
1427
|
-
|
|
1428
|
-
clearTimeout(this._playerState.scrollTimeout);
|
|
1429
|
-
}
|
|
1430
|
-
this._playerState.scrollTimeout = setTimeout(()=>{
|
|
1431
|
-
this.playerState = PlayerState.Paused;
|
|
1432
|
-
}, 400);
|
|
1433
|
-
const adjustedScroll = scrollY > this._playerState.scrollY ? scrollY - this._playerState.scrollY : this._playerState.scrollY - scrollY, clampedScroll = Math.min(Math.max(adjustedScroll / 3, 1), this._lottieInstance.totalFrames * 3), roundedScroll = clampedScroll / 3;
|
|
1434
|
-
requestAnimationFrame(()=>{
|
|
1435
|
-
if (roundedScroll < (this._lottieInstance?.totalFrames ?? 0)) {
|
|
1436
|
-
this.playerState = PlayerState.Playing;
|
|
1437
|
-
this._lottieInstance?.goToAndStop(roundedScroll, true);
|
|
1438
|
-
} else {
|
|
1439
|
-
this.playerState = PlayerState.Paused;
|
|
1440
|
-
}
|
|
1441
|
-
});
|
|
1458
|
+
if (!this._playerState.visible) {
|
|
1459
|
+
return;
|
|
1442
1460
|
}
|
|
1461
|
+
if (this._playerState.scrollTimeout) {
|
|
1462
|
+
clearTimeout(this._playerState.scrollTimeout);
|
|
1463
|
+
}
|
|
1464
|
+
this._playerState.scrollTimeout = setTimeout(()=>{
|
|
1465
|
+
this.playerState = PlayerState.Paused;
|
|
1466
|
+
}, 400);
|
|
1467
|
+
const { totalFrames } = this._lottieInstance;
|
|
1468
|
+
let scrollPosition = scrollY - this._playerState.scrollY;
|
|
1469
|
+
if (scrollY <= this._playerState.scrollY) {
|
|
1470
|
+
scrollPosition = this._playerState.scrollY - scrollY;
|
|
1471
|
+
}
|
|
1472
|
+
const scrollProgress = scrollPosition / innerHeight, currentFrame = clamp(scrollProgress * (totalFrames - 1), 1, totalFrames);
|
|
1473
|
+
requestAnimationFrame(()=>{
|
|
1474
|
+
if (currentFrame >= totalFrames) {
|
|
1475
|
+
this.playerState = PlayerState.Paused;
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
this.playerState = PlayerState.Playing;
|
|
1479
|
+
this._lottieInstance?.goToAndStop(currentFrame, true);
|
|
1480
|
+
});
|
|
1443
1481
|
}
|
|
1444
1482
|
_handleWindowBlur({ type }) {
|
|
1445
1483
|
if (this.dontFreezeOnBlur) {
|
|
@@ -1621,7 +1659,20 @@ const notImplemented = 'Method is not implemented';
|
|
|
1621
1659
|
this._lottieInstance[method]('data_ready', this._dataReady);
|
|
1622
1660
|
this._lottieInstance[method]('data_failed', this._dataFailed);
|
|
1623
1661
|
}
|
|
1624
|
-
if (this.
|
|
1662
|
+
if (this.selector) {
|
|
1663
|
+
const selector = document.getElementById(this.selector);
|
|
1664
|
+
if (selector) {
|
|
1665
|
+
if (this.hover) {
|
|
1666
|
+
selector[method]('mouseenter', this._mouseEnter);
|
|
1667
|
+
selector[method]('mouseleave', this._mouseLeave);
|
|
1668
|
+
} else {
|
|
1669
|
+
selector[method]('click', this._handleClick);
|
|
1670
|
+
}
|
|
1671
|
+
} else {
|
|
1672
|
+
this.selector = null;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
if (this._container && !this.selector) {
|
|
1625
1676
|
if (this.hover) {
|
|
1626
1677
|
this._container[method]('mouseenter', this._mouseEnter);
|
|
1627
1678
|
this._container[method]('mouseleave', this._mouseLeave);
|
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(): readonly ["animateOnScroll", "autoplay", "controls", "direction", "hover", "loop", "mode", "playOnClick", "playOnVisible", "speed", "src", "subframe"];
|
|
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;
|
|
@@ -162,6 +162,8 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
162
162
|
get preserveAspectRatio(): PreserveAspectRatio | null;
|
|
163
163
|
set renderer(value: RendererType);
|
|
164
164
|
get renderer(): RendererType;
|
|
165
|
+
set selector(value: string | null);
|
|
166
|
+
get selector(): string | null;
|
|
165
167
|
set simple(value: boolean);
|
|
166
168
|
get simple(): boolean;
|
|
167
169
|
set speed(value: number);
|
package/dist/light.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isServer, PlayMode, PreserveAspectRatio, namespaceSVG, RendererType, createElementID, PlayerEvents, download, getFilename } from '@aarsteinmedia/lottie-web/utils';
|
|
1
|
+
import { isServer, PlayMode, PreserveAspectRatio, namespaceSVG, RendererType, createElementID, PlayerEvents, download, getFilename, clamp } from '@aarsteinmedia/lottie-web/utils';
|
|
2
2
|
export { PlayMode, PlayerEvents } from '@aarsteinmedia/lottie-web/utils';
|
|
3
3
|
import Lottie from '@aarsteinmedia/lottie-web/light';
|
|
4
4
|
import { convert, getAnimationData } from '@aarsteinmedia/lottie-web/dotlottie';
|
|
@@ -323,6 +323,7 @@ const notImplemented = 'Method is not implemented';
|
|
|
323
323
|
'mode',
|
|
324
324
|
'playOnClick',
|
|
325
325
|
'playOnVisible',
|
|
326
|
+
'selector',
|
|
326
327
|
'speed',
|
|
327
328
|
'src',
|
|
328
329
|
'subframe'
|
|
@@ -572,6 +573,18 @@ const notImplemented = 'Method is not implemented';
|
|
|
572
573
|
return RendererType.SVG;
|
|
573
574
|
}
|
|
574
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
|
+
/**
|
|
575
588
|
* Hide advanced controls.
|
|
576
589
|
*/ set simple(value) {
|
|
577
590
|
this.setAttribute('simple', value.toString());
|
|
@@ -760,6 +773,12 @@ const notImplemented = 'Method is not implemented';
|
|
|
760
773
|
}
|
|
761
774
|
break;
|
|
762
775
|
}
|
|
776
|
+
case 'selector':
|
|
777
|
+
{
|
|
778
|
+
const selector = document.getElementById(this.selector ?? '');
|
|
779
|
+
selector?.addEventListener('click', this._handleClick);
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
763
782
|
case 'speed':
|
|
764
783
|
{
|
|
765
784
|
const val = Number(value);
|
|
@@ -868,6 +887,19 @@ const notImplemented = 'Method is not implemented';
|
|
|
868
887
|
if (!animations || animations.some((animation)=>!isLottie(animation))) {
|
|
869
888
|
throw new Error('Broken or corrupted file');
|
|
870
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
|
+
}
|
|
871
903
|
this._isBounce = this.mode === PlayMode.Bounce;
|
|
872
904
|
if (this._multiAnimationSettings.length > 0 && this._multiAnimationSettings[this._currentAnimation]?.mode) {
|
|
873
905
|
this._isBounce = this._multiAnimationSettings[this._currentAnimation]?.mode === PlayMode.Bounce;
|
|
@@ -1237,7 +1269,7 @@ const notImplemented = 'Method is not implemented';
|
|
|
1237
1269
|
/**
|
|
1238
1270
|
* Handle click.
|
|
1239
1271
|
*/ _handleClick() {
|
|
1240
|
-
if (!this.playOnClick) {
|
|
1272
|
+
if (!this.playOnClick && !this.selector) {
|
|
1241
1273
|
return;
|
|
1242
1274
|
}
|
|
1243
1275
|
this.togglePlay();
|
|
@@ -1423,23 +1455,29 @@ const notImplemented = 'Method is not implemented';
|
|
|
1423
1455
|
console.warn('DotLottie: Scroll animations might not work properly in a Server Side Rendering context. Try to wrap this in a client component.');
|
|
1424
1456
|
return;
|
|
1425
1457
|
}
|
|
1426
|
-
if (this._playerState.visible) {
|
|
1427
|
-
|
|
1428
|
-
clearTimeout(this._playerState.scrollTimeout);
|
|
1429
|
-
}
|
|
1430
|
-
this._playerState.scrollTimeout = setTimeout(()=>{
|
|
1431
|
-
this.playerState = PlayerState.Paused;
|
|
1432
|
-
}, 400);
|
|
1433
|
-
const adjustedScroll = scrollY > this._playerState.scrollY ? scrollY - this._playerState.scrollY : this._playerState.scrollY - scrollY, clampedScroll = Math.min(Math.max(adjustedScroll / 3, 1), this._lottieInstance.totalFrames * 3), roundedScroll = clampedScroll / 3;
|
|
1434
|
-
requestAnimationFrame(()=>{
|
|
1435
|
-
if (roundedScroll < (this._lottieInstance?.totalFrames ?? 0)) {
|
|
1436
|
-
this.playerState = PlayerState.Playing;
|
|
1437
|
-
this._lottieInstance?.goToAndStop(roundedScroll, true);
|
|
1438
|
-
} else {
|
|
1439
|
-
this.playerState = PlayerState.Paused;
|
|
1440
|
-
}
|
|
1441
|
-
});
|
|
1458
|
+
if (!this._playerState.visible) {
|
|
1459
|
+
return;
|
|
1442
1460
|
}
|
|
1461
|
+
if (this._playerState.scrollTimeout) {
|
|
1462
|
+
clearTimeout(this._playerState.scrollTimeout);
|
|
1463
|
+
}
|
|
1464
|
+
this._playerState.scrollTimeout = setTimeout(()=>{
|
|
1465
|
+
this.playerState = PlayerState.Paused;
|
|
1466
|
+
}, 400);
|
|
1467
|
+
const { totalFrames } = this._lottieInstance;
|
|
1468
|
+
let scrollPosition = scrollY - this._playerState.scrollY;
|
|
1469
|
+
if (scrollY <= this._playerState.scrollY) {
|
|
1470
|
+
scrollPosition = this._playerState.scrollY - scrollY;
|
|
1471
|
+
}
|
|
1472
|
+
const scrollProgress = scrollPosition / innerHeight, currentFrame = clamp(scrollProgress * (totalFrames - 1), 1, totalFrames);
|
|
1473
|
+
requestAnimationFrame(()=>{
|
|
1474
|
+
if (currentFrame >= totalFrames) {
|
|
1475
|
+
this.playerState = PlayerState.Paused;
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
this.playerState = PlayerState.Playing;
|
|
1479
|
+
this._lottieInstance?.goToAndStop(currentFrame, true);
|
|
1480
|
+
});
|
|
1443
1481
|
}
|
|
1444
1482
|
_handleWindowBlur({ type }) {
|
|
1445
1483
|
if (this.dontFreezeOnBlur) {
|
|
@@ -1621,7 +1659,20 @@ const notImplemented = 'Method is not implemented';
|
|
|
1621
1659
|
this._lottieInstance[method]('data_ready', this._dataReady);
|
|
1622
1660
|
this._lottieInstance[method]('data_failed', this._dataFailed);
|
|
1623
1661
|
}
|
|
1624
|
-
if (this.
|
|
1662
|
+
if (this.selector) {
|
|
1663
|
+
const selector = document.getElementById(this.selector);
|
|
1664
|
+
if (selector) {
|
|
1665
|
+
if (this.hover) {
|
|
1666
|
+
selector[method]('mouseenter', this._mouseEnter);
|
|
1667
|
+
selector[method]('mouseleave', this._mouseLeave);
|
|
1668
|
+
} else {
|
|
1669
|
+
selector[method]('click', this._handleClick);
|
|
1670
|
+
}
|
|
1671
|
+
} else {
|
|
1672
|
+
this.selector = null;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
if (this._container && !this.selector) {
|
|
1625
1676
|
if (this.hover) {
|
|
1626
1677
|
this._container[method]('mouseenter', this._mouseEnter);
|
|
1627
1678
|
this._container[method]('mouseleave', this._mouseLeave);
|
package/dist/svg.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(): readonly ["animateOnScroll", "autoplay", "controls", "direction", "hover", "loop", "mode", "playOnClick", "playOnVisible", "speed", "src", "subframe"];
|
|
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;
|
|
@@ -162,6 +162,8 @@ declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
|
162
162
|
get preserveAspectRatio(): PreserveAspectRatio | null;
|
|
163
163
|
set renderer(value: RendererType);
|
|
164
164
|
get renderer(): RendererType;
|
|
165
|
+
set selector(value: string | null);
|
|
166
|
+
get selector(): string | null;
|
|
165
167
|
set simple(value: boolean);
|
|
166
168
|
get simple(): boolean;
|
|
167
169
|
set speed(value: number);
|