@aarsteinmedia/dotlottie-player 5.3.2 → 6.0.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 +7 -0
- package/README.md +24 -11
- package/custom-elements.json +1 -706
- package/dist/{index.d.ts → full.d.ts} +62 -24
- package/dist/{index.js → full.js} +92 -69
- package/dist/light.d.ts +233 -0
- package/dist/light.js +1484 -0
- package/dist/unpkg-full.js +70 -0
- package/dist/unpkg-light.js +68 -0
- package/package.json +17 -11
- package/dist/unpkg.js +0 -70
|
@@ -1,7 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RendererType, PreserveAspectRatio, PlayMode } from '@aarsteinmedia/lottie-web/utils';
|
|
2
2
|
export { PlayMode, PlayerEvents } from '@aarsteinmedia/lottie-web/utils';
|
|
3
|
-
import
|
|
3
|
+
import * as _aarsteinmedia_lottie_web from '@aarsteinmedia/lottie-web';
|
|
4
|
+
import { Vector2, AnimationConfiguration, AnimationData, AnimationDirection, AddAnimationParams, Result, ConvertParams, AnimationItem, LottieManifest, AnimationSettings } from '@aarsteinmedia/lottie-web';
|
|
4
5
|
import { addAnimation, convert } from '@aarsteinmedia/lottie-web/dotlottie';
|
|
6
|
+
import * as _aarsteinmedia_lottie_web_light from '@aarsteinmedia/lottie-web/light';
|
|
7
|
+
|
|
8
|
+
declare class DotLottiePlayerLight extends DotLottiePlayerBase {
|
|
9
|
+
loadAnimation: typeof _aarsteinmedia_lottie_web_light.loadAnimation;
|
|
10
|
+
get renderer(): RendererType;
|
|
11
|
+
constructor();
|
|
12
|
+
protected setOptions({ container, hasAutoplay, hasLoop, initialSegment, preserveAspectRatio, }: {
|
|
13
|
+
container?: HTMLElement;
|
|
14
|
+
rendererType: RendererType;
|
|
15
|
+
initialSegment?: Vector2;
|
|
16
|
+
hasAutoplay: boolean;
|
|
17
|
+
hasLoop: boolean;
|
|
18
|
+
preserveAspectRatio: PreserveAspectRatio;
|
|
19
|
+
}): AnimationConfiguration<RendererType.SVG>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare enum PlayerState {
|
|
23
|
+
Completed = "completed",
|
|
24
|
+
Destroyed = "destroyed",
|
|
25
|
+
Error = "error",
|
|
26
|
+
Frozen = "frozen",
|
|
27
|
+
Loading = "loading",
|
|
28
|
+
Paused = "paused",
|
|
29
|
+
Playing = "playing",
|
|
30
|
+
Stopped = "stopped"
|
|
31
|
+
}
|
|
32
|
+
declare const tagName = "dotlottie-player";
|
|
5
33
|
|
|
6
34
|
type AnimateOnScroll = boolean | '' | null;
|
|
7
35
|
type Autoplay = boolean | '' | 'autoplay' | null;
|
|
@@ -10,11 +38,11 @@ type Loop = boolean | '' | 'loop' | null;
|
|
|
10
38
|
type Subframe = boolean | '' | null;
|
|
11
39
|
declare global {
|
|
12
40
|
interface HTMLElementTagNameMap {
|
|
13
|
-
[tagName]: DotLottiePlayer;
|
|
41
|
+
[tagName]: DotLottiePlayer | DotLottiePlayerLight;
|
|
14
42
|
}
|
|
15
|
-
function dotLottiePlayer(): DotLottiePlayer;
|
|
43
|
+
function dotLottiePlayer(): DotLottiePlayer | DotLottiePlayerLight;
|
|
16
44
|
}
|
|
17
|
-
type JSXLottiePlayer = Omit<Partial<DotLottiePlayer>, 'style'> & {
|
|
45
|
+
type JSXLottiePlayer = Omit<Partial<DotLottiePlayer | DotLottiePlayerLight>, 'style'> & {
|
|
18
46
|
class?: string;
|
|
19
47
|
ref?: React.RefObject<unknown>;
|
|
20
48
|
style?: React.CSSProperties;
|
|
@@ -48,31 +76,19 @@ declare abstract class PropertyCallbackElement extends HTMLElement {
|
|
|
48
76
|
propertyChangedCallback(_name: string, _oldValue: unknown, _value: unknown): void;
|
|
49
77
|
}
|
|
50
78
|
|
|
51
|
-
declare function renderControls(this:
|
|
79
|
+
declare function renderControls(this: DotLottiePlayerBase): void;
|
|
52
80
|
|
|
53
|
-
declare function renderPlayer(this:
|
|
81
|
+
declare function renderPlayer(this: DotLottiePlayerBase): Promise<void>;
|
|
54
82
|
|
|
55
|
-
declare
|
|
56
|
-
Completed = "completed",
|
|
57
|
-
Destroyed = "destroyed",
|
|
58
|
-
Error = "error",
|
|
59
|
-
Frozen = "frozen",
|
|
60
|
-
Loading = "loading",
|
|
61
|
-
Paused = "paused",
|
|
62
|
-
Playing = "playing",
|
|
63
|
-
Stopped = "stopped"
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
declare class DotLottiePlayer extends PropertyCallbackElement {
|
|
83
|
+
declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
67
84
|
static get observedAttributes(): string[];
|
|
68
85
|
static get observedProperties(): string[];
|
|
69
86
|
static get styles(): () => Promise<CSSStyleSheet>;
|
|
70
|
-
|
|
71
|
-
convert: typeof convert;
|
|
87
|
+
isLight: boolean;
|
|
72
88
|
playerState: PlayerState;
|
|
73
89
|
shadow: ShadowRoot | undefined;
|
|
74
90
|
source?: string;
|
|
75
|
-
template
|
|
91
|
+
template?: HTMLTemplateElement;
|
|
76
92
|
set animateOnScroll(value: AnimateOnScroll);
|
|
77
93
|
get animateOnScroll(): AnimateOnScroll;
|
|
78
94
|
get animations(): AnimationData[];
|
|
@@ -137,8 +153,10 @@ declare class DotLottiePlayer extends PropertyCallbackElement {
|
|
|
137
153
|
private _multiAnimationSettings;
|
|
138
154
|
private _segment?;
|
|
139
155
|
constructor();
|
|
156
|
+
addAnimation(_params: AddAnimationParams): Promise<Result>;
|
|
140
157
|
attributeChangedCallback(name: string, _oldValue: unknown, value: string): Promise<void>;
|
|
141
158
|
connectedCallback(): void;
|
|
159
|
+
convert(_params: ConvertParams): Promise<Result>;
|
|
142
160
|
destroy(): void;
|
|
143
161
|
disconnectedCallback(): void;
|
|
144
162
|
getLottie(): AnimationItem | null;
|
|
@@ -146,6 +164,7 @@ declare class DotLottiePlayer extends PropertyCallbackElement {
|
|
|
146
164
|
getMultiAnimationSettings(): AnimationSettings[];
|
|
147
165
|
getSegment(): Vector2 | undefined;
|
|
148
166
|
load(src: string | null): Promise<void>;
|
|
167
|
+
loadAnimation(_config: AnimationConfiguration): AnimationItem;
|
|
149
168
|
next(): void;
|
|
150
169
|
pause(): void;
|
|
151
170
|
play(): void;
|
|
@@ -169,6 +188,14 @@ declare class DotLottiePlayer extends PropertyCallbackElement {
|
|
|
169
188
|
protected _handleBlur(): void;
|
|
170
189
|
protected _handleSeekChange({ target }: Event): void;
|
|
171
190
|
protected _handleSettingsClick({ target }: Event): void;
|
|
191
|
+
protected setOptions(_options: {
|
|
192
|
+
container?: HTMLElement;
|
|
193
|
+
rendererType: RendererType;
|
|
194
|
+
initialSegment?: Vector2;
|
|
195
|
+
hasAutoplay: boolean;
|
|
196
|
+
hasLoop: boolean;
|
|
197
|
+
preserveAspectRatio: PreserveAspectRatio;
|
|
198
|
+
}): AnimationConfiguration<RendererType.SVG | RendererType.Canvas | RendererType.HTML>;
|
|
172
199
|
private _addEventListeners;
|
|
173
200
|
private _addIntersectionObserver;
|
|
174
201
|
private _complete;
|
|
@@ -179,7 +206,6 @@ declare class DotLottiePlayer extends PropertyCallbackElement {
|
|
|
179
206
|
private _getOptions;
|
|
180
207
|
private _handleScroll;
|
|
181
208
|
private _handleWindowBlur;
|
|
182
|
-
private _isLottie;
|
|
183
209
|
private _loopComplete;
|
|
184
210
|
private _mouseEnter;
|
|
185
211
|
private _mouseLeave;
|
|
@@ -190,6 +216,18 @@ declare class DotLottiePlayer extends PropertyCallbackElement {
|
|
|
190
216
|
private _toggleSettings;
|
|
191
217
|
}
|
|
192
218
|
|
|
193
|
-
declare
|
|
219
|
+
declare class DotLottiePlayer extends DotLottiePlayerBase {
|
|
220
|
+
addAnimation: typeof addAnimation;
|
|
221
|
+
convert: typeof convert;
|
|
222
|
+
loadAnimation: typeof _aarsteinmedia_lottie_web.loadAnimation;
|
|
223
|
+
protected setOptions({ container, hasAutoplay, hasLoop, initialSegment, preserveAspectRatio, rendererType }: {
|
|
224
|
+
container?: HTMLElement;
|
|
225
|
+
rendererType: RendererType;
|
|
226
|
+
initialSegment?: Vector2;
|
|
227
|
+
hasAutoplay: boolean;
|
|
228
|
+
hasLoop: boolean;
|
|
229
|
+
preserveAspectRatio: PreserveAspectRatio;
|
|
230
|
+
}): AnimationConfiguration<RendererType>;
|
|
231
|
+
}
|
|
194
232
|
|
|
195
233
|
export { PlayerState, DotLottiePlayer as default, tagName };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isServer, PlayMode, PreserveAspectRatio, namespaceSVG, RendererType, createElementID, PlayerEvents, download, getFilename } from '@aarsteinmedia/lottie-web/utils';
|
|
2
2
|
export { PlayMode, PlayerEvents } from '@aarsteinmedia/lottie-web/utils';
|
|
3
3
|
import Lottie from '@aarsteinmedia/lottie-web';
|
|
4
|
-
import { convert,
|
|
4
|
+
import { convert, getAnimationData, addAnimation } from '@aarsteinmedia/lottie-web/dotlottie';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Credit to: Leonardo Favre https://github.com/leofavre/observed-properties.
|
|
@@ -156,6 +156,7 @@ var PlayerState = /*#__PURE__*/ function(PlayerState) {
|
|
|
156
156
|
PlayerState["Stopped"] = "stopped";
|
|
157
157
|
return PlayerState;
|
|
158
158
|
}({});
|
|
159
|
+
const tagName = 'dotlottie-player';
|
|
159
160
|
|
|
160
161
|
/**
|
|
161
162
|
* Render Controls.
|
|
@@ -241,12 +242,12 @@ const pauseIcon = /* HTML */ `
|
|
|
241
242
|
/**
|
|
242
243
|
* Render Player.
|
|
243
244
|
*/ async function renderPlayer() {
|
|
244
|
-
if (!this.shadow) {
|
|
245
|
-
throw new Error('No Shadow Element');
|
|
245
|
+
if (!this.shadow || !this.template) {
|
|
246
|
+
throw new Error('No Shadow Element or Template');
|
|
246
247
|
}
|
|
247
248
|
this.template.innerHTML = /* HTML */ `<div class="animation-container main" data-controls="${this.controls ?? false}" lang="${this.description ? document.documentElement.lang : 'en'}" aria-label="${this.description ?? 'Lottie animation'}" data-loaded="${this._playerState.loaded}"><figure class="animation" style="background:${this.background}">${this.playerState === PlayerState.Error ? /* HTML */ `<div class="error"><svg preserveAspectRatio="${PreserveAspectRatio.Cover}" xmlns="${namespaceSVG}" width="1920" height="1080" viewBox="0 0 1920 1080" style="white-space:preserve"><path fill="#fff" d="M0 0h1920v1080H0z"/><path fill="#3a6d8b" d="M1190.2 531 1007 212.4c-22-38.2-77.2-38-98.8.5L729.5 531.3c-21.3 37.9 6.1 84.6 49.5 84.6l361.9.3c43.7 0 71.1-47.3 49.3-85.2zM937.3 288.7c.2-7.5 3.3-23.9 23.2-23.9 16.3 0 23 16.1 23 23.5 0 55.3-10.7 197.2-12.2 214.5-.1 1-.9 1.7-1.9 1.7h-18.3c-1 0-1.8-.7-1.9-1.7-1.4-17.5-13.4-162.9-11.9-214.1zm24.2 283.8c-13.1 0-23.7-10.6-23.7-23.7s10.6-23.7 23.7-23.7 23.7 10.6 23.7 23.7-10.6 23.7-23.7 23.7zM722.1 644h112.6v34.4h-70.4V698h58.8v31.7h-58.8v22.6h72.4v36.2H722.1V644zm162 57.1h.6c8.3-12.9 18.2-17.8 31.3-17.8 3 0 5.1.4 6.3 1v32.6h-.8c-22.4-3.8-35.6 6.3-35.6 29.5v42.3h-38.2V685.5h36.4v15.6zm78.9 0h.6c8.3-12.9 18.2-17.8 31.3-17.8 3 0 5.1.4 6.3 1v32.6h-.8c-22.4-3.8-35.6 6.3-35.6 29.5v42.3h-38.2V685.5H963v15.6zm39.5 36.2c0-31.3 22.2-54.8 56.6-54.8 34.4 0 56.2 23.5 56.2 54.8s-21.8 54.6-56.2 54.6c-34.4-.1-56.6-23.3-56.6-54.6zm74 0c0-17.4-6.1-29.1-17.8-29.1-11.7 0-17.4 11.7-17.4 29.1 0 17.4 5.7 29.1 17.4 29.1s17.8-11.8 17.8-29.1zm83.1-36.2h.6c8.3-12.9 18.2-17.8 31.3-17.8 3 0 5.1.4 6.3 1v32.6h-.8c-22.4-3.8-35.6 6.3-35.6 29.5v42.3h-38.2V685.5h36.4v15.6z"/><path fill="none" d="M718.9 807.7h645v285.4h-645z"/><text fill="#3a6d8b" style="text-align:center;position:absolute;left:100%;font-size:47px;font-family:system-ui,-apple-system,BlinkMacSystemFont,'.SFNSText-Regular',sans-serif" x="50%" y="848.017" text-anchor="middle">${this._errorMessage}</text></svg></div>` : ''}</figure><slot name="controls"></slot></div>`;
|
|
248
249
|
this.shadow.adoptedStyleSheets = [
|
|
249
|
-
await
|
|
250
|
+
await DotLottiePlayerBase.styles()
|
|
250
251
|
];
|
|
251
252
|
this.shadow.appendChild(this.template.content.cloneNode(true));
|
|
252
253
|
}
|
|
@@ -291,11 +292,23 @@ const pauseIcon = /* HTML */ `
|
|
|
291
292
|
}
|
|
292
293
|
}
|
|
293
294
|
return res;
|
|
295
|
+
}, isLottie = (json)=>{
|
|
296
|
+
const mandatory = [
|
|
297
|
+
'v',
|
|
298
|
+
'ip',
|
|
299
|
+
'op',
|
|
300
|
+
'layers',
|
|
301
|
+
'fr',
|
|
302
|
+
'w',
|
|
303
|
+
'h'
|
|
304
|
+
];
|
|
305
|
+
return mandatory.every((field)=>Object.hasOwn(json, field));
|
|
294
306
|
}, frameOutput = (frame)=>((frame ?? 0) + 1).toString().padStart(3, '0');
|
|
295
307
|
|
|
308
|
+
const notImplemented = 'Method is not implemented';
|
|
296
309
|
/**
|
|
297
310
|
* DotLottie Player Web Component.
|
|
298
|
-
*/ class
|
|
311
|
+
*/ class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
299
312
|
/**
|
|
300
313
|
* Attributes to observe.
|
|
301
314
|
*/ static get observedAttributes() {
|
|
@@ -525,7 +538,7 @@ const pauseIcon = /* HTML */ `
|
|
|
525
538
|
return Boolean(val === 'true' || val === '' || val === '1');
|
|
526
539
|
}
|
|
527
540
|
constructor(){
|
|
528
|
-
super(), this.
|
|
541
|
+
super(), this.isLight = false, /**
|
|
529
542
|
* Player state.
|
|
530
543
|
*/ this.playerState = PlayerState.Loading, /**
|
|
531
544
|
* Animation Container.
|
|
@@ -579,6 +592,9 @@ const pauseIcon = /* HTML */ `
|
|
|
579
592
|
mode: 'open'
|
|
580
593
|
});
|
|
581
594
|
}
|
|
595
|
+
addAnimation(_params) {
|
|
596
|
+
throw new Error(notImplemented);
|
|
597
|
+
}
|
|
582
598
|
/**
|
|
583
599
|
* Runs when the value of an attribute is changed on the component.
|
|
584
600
|
*/ async attributeChangedCallback(name, _oldValue, value) {
|
|
@@ -678,6 +694,9 @@ const pauseIcon = /* HTML */ `
|
|
|
678
694
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Error));
|
|
679
695
|
}
|
|
680
696
|
}
|
|
697
|
+
convert(_params) {
|
|
698
|
+
throw new Error(notImplemented);
|
|
699
|
+
}
|
|
681
700
|
/**
|
|
682
701
|
* Destroy animation and element.
|
|
683
702
|
*/ destroy() {
|
|
@@ -734,7 +753,7 @@ const pauseIcon = /* HTML */ `
|
|
|
734
753
|
this.source = src;
|
|
735
754
|
// Load the resource
|
|
736
755
|
const { animations, isDotLottie, manifest } = await getAnimationData(src);
|
|
737
|
-
if (!animations || animations.some((animation)=>!
|
|
756
|
+
if (!animations || animations.some((animation)=>!isLottie(animation))) {
|
|
738
757
|
throw new Error('Broken or corrupted file');
|
|
739
758
|
}
|
|
740
759
|
this._isBounce = this.mode === PlayMode.Bounce;
|
|
@@ -766,7 +785,7 @@ const pauseIcon = /* HTML */ `
|
|
|
766
785
|
this.playerState = PlayerState.Playing;
|
|
767
786
|
}
|
|
768
787
|
// Initialize lottie player and load animation
|
|
769
|
-
this._lottieInstance =
|
|
788
|
+
this._lottieInstance = this.loadAnimation({
|
|
770
789
|
...this._getOptions(),
|
|
771
790
|
animationData: animations[this._currentAnimation]
|
|
772
791
|
});
|
|
@@ -803,6 +822,9 @@ const pauseIcon = /* HTML */ `
|
|
|
803
822
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Error));
|
|
804
823
|
}
|
|
805
824
|
}
|
|
825
|
+
loadAnimation(_config) {
|
|
826
|
+
throw new Error(notImplemented);
|
|
827
|
+
}
|
|
806
828
|
/**
|
|
807
829
|
* Skip to next animation.
|
|
808
830
|
*/ next() {
|
|
@@ -849,13 +871,13 @@ const pauseIcon = /* HTML */ `
|
|
|
849
871
|
if (!this.shadow) {
|
|
850
872
|
return;
|
|
851
873
|
}
|
|
852
|
-
const togglePlay = this.shadow.querySelector('.togglePlay'),
|
|
853
|
-
if (!(togglePlay instanceof HTMLButtonElement) || !(
|
|
874
|
+
const togglePlay = this.shadow.querySelector('.togglePlay'), stopButton = this.shadow.querySelector('.stop'), prevButton = this.shadow.querySelector('.prev'), nextButton = this.shadow.querySelector('.next'), seeker = this.shadow.querySelector('.seeker'), progress = this.shadow.querySelector('progress'), popover = this.shadow.querySelector('.popover'), convertButton = this.shadow.querySelector('.convert'), snapshot = this.shadow.querySelector('.snapshot');
|
|
875
|
+
if (!(togglePlay instanceof HTMLButtonElement) || !(stopButton instanceof HTMLButtonElement) || !(nextButton instanceof HTMLButtonElement) || !(prevButton instanceof HTMLButtonElement) || !(seeker instanceof HTMLInputElement) || !(progress instanceof HTMLProgressElement)) {
|
|
854
876
|
return;
|
|
855
877
|
}
|
|
856
878
|
if (name === 'playerState') {
|
|
857
879
|
togglePlay.dataset.active = (value === PlayerState.Playing || value === PlayerState.Paused).toString();
|
|
858
|
-
|
|
880
|
+
stopButton.dataset.active = (value === PlayerState.Stopped).toString();
|
|
859
881
|
if (value === PlayerState.Playing) {
|
|
860
882
|
togglePlay.innerHTML = pauseIcon;
|
|
861
883
|
} else {
|
|
@@ -868,15 +890,15 @@ const pauseIcon = /* HTML */ `
|
|
|
868
890
|
progress.value = value;
|
|
869
891
|
}
|
|
870
892
|
if (name === '_animations' && Array.isArray(value) && this._currentAnimation + 1 < value.length) {
|
|
871
|
-
|
|
893
|
+
nextButton.hidden = false;
|
|
872
894
|
}
|
|
873
895
|
if (name === '_currentAnimation' && typeof value === 'number') {
|
|
874
|
-
|
|
875
|
-
|
|
896
|
+
nextButton.hidden = value + 1 >= this._animations.length;
|
|
897
|
+
prevButton.hidden = !value;
|
|
876
898
|
}
|
|
877
899
|
if (name === '_isSettingsOpen' && typeof value === 'boolean' && popover instanceof HTMLDivElement && convertButton instanceof HTMLButtonElement && snapshot instanceof HTMLButtonElement) {
|
|
878
900
|
popover.hidden = !value;
|
|
879
|
-
convertButton.hidden =
|
|
901
|
+
convertButton.hidden = this.isLight;
|
|
880
902
|
snapshot.hidden = this.renderer !== RendererType.SVG;
|
|
881
903
|
}
|
|
882
904
|
}
|
|
@@ -1108,6 +1130,9 @@ const pauseIcon = /* HTML */ `
|
|
|
1108
1130
|
target.focus();
|
|
1109
1131
|
}
|
|
1110
1132
|
}
|
|
1133
|
+
setOptions(_options) {
|
|
1134
|
+
throw new Error('Method not implemented');
|
|
1135
|
+
}
|
|
1111
1136
|
/**
|
|
1112
1137
|
* Add event listeners.
|
|
1113
1138
|
*/ _addEventListeners() {
|
|
@@ -1191,7 +1216,6 @@ const pauseIcon = /* HTML */ `
|
|
|
1191
1216
|
}
|
|
1192
1217
|
/**
|
|
1193
1218
|
* Get options from props.
|
|
1194
|
-
*
|
|
1195
1219
|
*/ _getOptions() {
|
|
1196
1220
|
if (!this._container) {
|
|
1197
1221
|
throw new Error('Container not rendered');
|
|
@@ -1227,47 +1251,14 @@ const pauseIcon = /* HTML */ `
|
|
|
1227
1251
|
if (this._segment?.some((val)=>val < 0)) {
|
|
1228
1252
|
initialSegment = undefined;
|
|
1229
1253
|
}
|
|
1230
|
-
|
|
1231
|
-
autoplay: hasAutoplay,
|
|
1254
|
+
return this.setOptions({
|
|
1232
1255
|
container: this._container,
|
|
1256
|
+
hasAutoplay,
|
|
1257
|
+
hasLoop,
|
|
1233
1258
|
initialSegment,
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
imagePreserveAspectRatio: preserveAspectRatio
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1240
|
-
switch(this.renderer){
|
|
1241
|
-
case RendererType.SVG:
|
|
1242
|
-
{
|
|
1243
|
-
options.rendererSettings = {
|
|
1244
|
-
...options.rendererSettings,
|
|
1245
|
-
hideOnTransparent: true,
|
|
1246
|
-
preserveAspectRatio,
|
|
1247
|
-
progressiveLoad: true
|
|
1248
|
-
};
|
|
1249
|
-
break;
|
|
1250
|
-
}
|
|
1251
|
-
case RendererType.Canvas:
|
|
1252
|
-
{
|
|
1253
|
-
options.rendererSettings = {
|
|
1254
|
-
...options.rendererSettings,
|
|
1255
|
-
// @ts-expect-error TODO:
|
|
1256
|
-
clearCanvas: true,
|
|
1257
|
-
preserveAspectRatio,
|
|
1258
|
-
progressiveLoad: true
|
|
1259
|
-
};
|
|
1260
|
-
break;
|
|
1261
|
-
}
|
|
1262
|
-
case RendererType.HTML:
|
|
1263
|
-
{
|
|
1264
|
-
options.rendererSettings = {
|
|
1265
|
-
...options.rendererSettings,
|
|
1266
|
-
hideOnTransparent: true
|
|
1267
|
-
};
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
return options;
|
|
1259
|
+
preserveAspectRatio,
|
|
1260
|
+
rendererType: this.renderer
|
|
1261
|
+
});
|
|
1271
1262
|
}
|
|
1272
1263
|
/**
|
|
1273
1264
|
* Handle scroll.
|
|
@@ -1305,18 +1296,6 @@ const pauseIcon = /* HTML */ `
|
|
|
1305
1296
|
this.play();
|
|
1306
1297
|
}
|
|
1307
1298
|
}
|
|
1308
|
-
_isLottie(json) {
|
|
1309
|
-
const mandatory = [
|
|
1310
|
-
'v',
|
|
1311
|
-
'ip',
|
|
1312
|
-
'op',
|
|
1313
|
-
'layers',
|
|
1314
|
-
'fr',
|
|
1315
|
-
'w',
|
|
1316
|
-
'h'
|
|
1317
|
-
];
|
|
1318
|
-
return mandatory.every((field)=>Object.hasOwn(json, field));
|
|
1319
|
-
}
|
|
1320
1299
|
_loopComplete() {
|
|
1321
1300
|
if (!this._lottieInstance) {
|
|
1322
1301
|
return;
|
|
@@ -1394,7 +1373,7 @@ const pauseIcon = /* HTML */ `
|
|
|
1394
1373
|
this._lottieInstance.destroy();
|
|
1395
1374
|
}
|
|
1396
1375
|
// Re-initialize lottie player
|
|
1397
|
-
this._lottieInstance =
|
|
1376
|
+
this._lottieInstance = this.loadAnimation({
|
|
1398
1377
|
...this._getOptions(),
|
|
1399
1378
|
animationData: this._animations[this._currentAnimation]
|
|
1400
1379
|
});
|
|
@@ -1466,10 +1445,54 @@ const pauseIcon = /* HTML */ `
|
|
|
1466
1445
|
}
|
|
1467
1446
|
}
|
|
1468
1447
|
|
|
1448
|
+
/**
|
|
1449
|
+
* DotLottie Player Web Component.
|
|
1450
|
+
*/ class DotLottiePlayer extends DotLottiePlayerBase {
|
|
1451
|
+
setOptions({ container, hasAutoplay, hasLoop, initialSegment, preserveAspectRatio, rendererType }) {
|
|
1452
|
+
const options = {
|
|
1453
|
+
autoplay: hasAutoplay,
|
|
1454
|
+
container,
|
|
1455
|
+
initialSegment,
|
|
1456
|
+
loop: hasLoop,
|
|
1457
|
+
renderer: rendererType,
|
|
1458
|
+
rendererSettings: {
|
|
1459
|
+
imagePreserveAspectRatio: preserveAspectRatio
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
switch(this.renderer){
|
|
1463
|
+
case RendererType.HTML:
|
|
1464
|
+
case RendererType.SVG:
|
|
1465
|
+
{
|
|
1466
|
+
options.rendererSettings = {
|
|
1467
|
+
...options.rendererSettings,
|
|
1468
|
+
hideOnTransparent: true,
|
|
1469
|
+
preserveAspectRatio,
|
|
1470
|
+
progressiveLoad: true
|
|
1471
|
+
};
|
|
1472
|
+
break;
|
|
1473
|
+
}
|
|
1474
|
+
case RendererType.Canvas:
|
|
1475
|
+
{
|
|
1476
|
+
options.rendererSettings = {
|
|
1477
|
+
...options.rendererSettings,
|
|
1478
|
+
// @ts-expect-error TODO:
|
|
1479
|
+
clearCanvas: true,
|
|
1480
|
+
preserveAspectRatio,
|
|
1481
|
+
progressiveLoad: true
|
|
1482
|
+
};
|
|
1483
|
+
break;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return options;
|
|
1487
|
+
}
|
|
1488
|
+
constructor(...args){
|
|
1489
|
+
super(...args), this.addAnimation = addAnimation, this.convert = convert, this.loadAnimation = Lottie.loadAnimation;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1469
1493
|
/**
|
|
1470
1494
|
* Expose DotLottiePlayer class as global variable.
|
|
1471
1495
|
*/ globalThis.dotLottiePlayer = ()=>new DotLottiePlayer();
|
|
1472
|
-
const tagName = 'dotlottie-player';
|
|
1473
1496
|
if (!isServer) {
|
|
1474
1497
|
customElements.define(tagName, DotLottiePlayer);
|
|
1475
1498
|
}
|
package/dist/light.d.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { RendererType, PreserveAspectRatio, PlayMode } from '@aarsteinmedia/lottie-web/utils';
|
|
2
|
+
export { PlayMode, PlayerEvents } from '@aarsteinmedia/lottie-web/utils';
|
|
3
|
+
import * as _aarsteinmedia_lottie_web_light from '@aarsteinmedia/lottie-web/light';
|
|
4
|
+
import * as _aarsteinmedia_lottie_web from '@aarsteinmedia/lottie-web';
|
|
5
|
+
import { Vector2, AnimationConfiguration, AnimationData, AnimationDirection, AddAnimationParams, Result, ConvertParams, AnimationItem, LottieManifest, AnimationSettings } from '@aarsteinmedia/lottie-web';
|
|
6
|
+
import { addAnimation, convert } from '@aarsteinmedia/lottie-web/dotlottie';
|
|
7
|
+
|
|
8
|
+
declare class DotLottiePlayer extends DotLottiePlayerBase {
|
|
9
|
+
addAnimation: typeof addAnimation;
|
|
10
|
+
convert: typeof convert;
|
|
11
|
+
loadAnimation: typeof _aarsteinmedia_lottie_web.loadAnimation;
|
|
12
|
+
protected setOptions({ container, hasAutoplay, hasLoop, initialSegment, preserveAspectRatio, rendererType }: {
|
|
13
|
+
container?: HTMLElement;
|
|
14
|
+
rendererType: RendererType;
|
|
15
|
+
initialSegment?: Vector2;
|
|
16
|
+
hasAutoplay: boolean;
|
|
17
|
+
hasLoop: boolean;
|
|
18
|
+
preserveAspectRatio: PreserveAspectRatio;
|
|
19
|
+
}): AnimationConfiguration<RendererType>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare enum PlayerState {
|
|
23
|
+
Completed = "completed",
|
|
24
|
+
Destroyed = "destroyed",
|
|
25
|
+
Error = "error",
|
|
26
|
+
Frozen = "frozen",
|
|
27
|
+
Loading = "loading",
|
|
28
|
+
Paused = "paused",
|
|
29
|
+
Playing = "playing",
|
|
30
|
+
Stopped = "stopped"
|
|
31
|
+
}
|
|
32
|
+
declare const tagName = "dotlottie-player";
|
|
33
|
+
|
|
34
|
+
type AnimateOnScroll = boolean | '' | null;
|
|
35
|
+
type Autoplay = boolean | '' | 'autoplay' | null;
|
|
36
|
+
type Controls = boolean | '' | 'controls' | null;
|
|
37
|
+
type Loop = boolean | '' | 'loop' | null;
|
|
38
|
+
type Subframe = boolean | '' | null;
|
|
39
|
+
declare global {
|
|
40
|
+
interface HTMLElementTagNameMap {
|
|
41
|
+
[tagName]: DotLottiePlayer | DotLottiePlayerLight;
|
|
42
|
+
}
|
|
43
|
+
function dotLottiePlayer(): DotLottiePlayer | DotLottiePlayerLight;
|
|
44
|
+
}
|
|
45
|
+
type JSXLottiePlayer = Omit<Partial<DotLottiePlayer | DotLottiePlayerLight>, 'style'> & {
|
|
46
|
+
class?: string;
|
|
47
|
+
ref?: React.RefObject<unknown>;
|
|
48
|
+
style?: React.CSSProperties;
|
|
49
|
+
src: string;
|
|
50
|
+
};
|
|
51
|
+
declare module 'react' {
|
|
52
|
+
namespace JSX {
|
|
53
|
+
interface IntrinsicElements {
|
|
54
|
+
[tagName]: JSXLottiePlayer;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
declare module 'react/jsx-runtime' {
|
|
59
|
+
namespace JSX {
|
|
60
|
+
interface IntrinsicElements {
|
|
61
|
+
[tagName]: JSXLottiePlayer;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
declare module 'react/jsx-dev-runtime' {
|
|
66
|
+
namespace JSX {
|
|
67
|
+
interface IntrinsicElements {
|
|
68
|
+
[tagName]: JSXLottiePlayer;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare abstract class PropertyCallbackElement extends HTMLElement {
|
|
74
|
+
constructor();
|
|
75
|
+
connectedCallback(): void;
|
|
76
|
+
propertyChangedCallback(_name: string, _oldValue: unknown, _value: unknown): void;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare function renderControls(this: DotLottiePlayerBase): void;
|
|
80
|
+
|
|
81
|
+
declare function renderPlayer(this: DotLottiePlayerBase): Promise<void>;
|
|
82
|
+
|
|
83
|
+
declare abstract class DotLottiePlayerBase extends PropertyCallbackElement {
|
|
84
|
+
static get observedAttributes(): string[];
|
|
85
|
+
static get observedProperties(): string[];
|
|
86
|
+
static get styles(): () => Promise<CSSStyleSheet>;
|
|
87
|
+
isLight: boolean;
|
|
88
|
+
playerState: PlayerState;
|
|
89
|
+
shadow: ShadowRoot | undefined;
|
|
90
|
+
source?: string;
|
|
91
|
+
template?: HTMLTemplateElement;
|
|
92
|
+
set animateOnScroll(value: AnimateOnScroll);
|
|
93
|
+
get animateOnScroll(): AnimateOnScroll;
|
|
94
|
+
get animations(): AnimationData[];
|
|
95
|
+
set autoplay(value: Autoplay);
|
|
96
|
+
get autoplay(): Autoplay;
|
|
97
|
+
set background(value: string);
|
|
98
|
+
get background(): string;
|
|
99
|
+
set controls(value: Controls);
|
|
100
|
+
get controls(): Controls;
|
|
101
|
+
set count(value: number);
|
|
102
|
+
get count(): number;
|
|
103
|
+
get currentAnimation(): number;
|
|
104
|
+
set description(value: string | null);
|
|
105
|
+
get description(): string | null;
|
|
106
|
+
set direction(value: AnimationDirection);
|
|
107
|
+
get direction(): AnimationDirection;
|
|
108
|
+
set hover(value: boolean);
|
|
109
|
+
get hover(): boolean;
|
|
110
|
+
set intermission(value: number);
|
|
111
|
+
get intermission(): number;
|
|
112
|
+
get isDotLottie(): boolean;
|
|
113
|
+
set loop(value: Loop);
|
|
114
|
+
get loop(): Loop;
|
|
115
|
+
set mode(value: PlayMode);
|
|
116
|
+
get mode(): PlayMode;
|
|
117
|
+
set objectfit(value: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down');
|
|
118
|
+
get objectfit(): "contain" | "cover" | "fill" | "none" | "scale-down";
|
|
119
|
+
set preserveAspectRatio(value: PreserveAspectRatio | null);
|
|
120
|
+
get preserveAspectRatio(): PreserveAspectRatio | null;
|
|
121
|
+
set renderer(value: RendererType);
|
|
122
|
+
get renderer(): RendererType;
|
|
123
|
+
set simple(value: boolean);
|
|
124
|
+
get simple(): boolean;
|
|
125
|
+
set speed(value: number);
|
|
126
|
+
get speed(): number;
|
|
127
|
+
set src(value: string | null);
|
|
128
|
+
get src(): string | null;
|
|
129
|
+
set subframe(value: Subframe);
|
|
130
|
+
get subframe(): Subframe;
|
|
131
|
+
protected _container: HTMLElement | null;
|
|
132
|
+
protected _errorMessage: string;
|
|
133
|
+
protected _identifier: string;
|
|
134
|
+
protected _isSettingsOpen: boolean;
|
|
135
|
+
protected _playerState: {
|
|
136
|
+
prev: PlayerState;
|
|
137
|
+
count: number;
|
|
138
|
+
loaded: boolean;
|
|
139
|
+
visible: boolean;
|
|
140
|
+
scrollY: number;
|
|
141
|
+
scrollTimeout: NodeJS.Timeout | null;
|
|
142
|
+
};
|
|
143
|
+
protected _render: typeof renderPlayer;
|
|
144
|
+
protected _renderControls: typeof renderControls;
|
|
145
|
+
protected _seeker: number;
|
|
146
|
+
private _animations;
|
|
147
|
+
private _currentAnimation;
|
|
148
|
+
private _intersectionObserver?;
|
|
149
|
+
private _isBounce;
|
|
150
|
+
private _isDotLottie;
|
|
151
|
+
private _lottieInstance;
|
|
152
|
+
private _manifest?;
|
|
153
|
+
private _multiAnimationSettings;
|
|
154
|
+
private _segment?;
|
|
155
|
+
constructor();
|
|
156
|
+
addAnimation(_params: AddAnimationParams): Promise<Result>;
|
|
157
|
+
attributeChangedCallback(name: string, _oldValue: unknown, value: string): Promise<void>;
|
|
158
|
+
connectedCallback(): void;
|
|
159
|
+
convert(_params: ConvertParams): Promise<Result>;
|
|
160
|
+
destroy(): void;
|
|
161
|
+
disconnectedCallback(): void;
|
|
162
|
+
getLottie(): AnimationItem | null;
|
|
163
|
+
getManifest(): LottieManifest | undefined;
|
|
164
|
+
getMultiAnimationSettings(): AnimationSettings[];
|
|
165
|
+
getSegment(): Vector2 | undefined;
|
|
166
|
+
load(src: string | null): Promise<void>;
|
|
167
|
+
loadAnimation(_config: AnimationConfiguration): AnimationItem;
|
|
168
|
+
next(): void;
|
|
169
|
+
pause(): void;
|
|
170
|
+
play(): void;
|
|
171
|
+
prev(): void;
|
|
172
|
+
propertyChangedCallback(name: string, _oldValue: unknown, value: unknown): void;
|
|
173
|
+
reload(): Promise<void>;
|
|
174
|
+
seek(value: number | string): void;
|
|
175
|
+
setCount(value: number): void;
|
|
176
|
+
setDirection(value: AnimationDirection): void;
|
|
177
|
+
setLoop(value: boolean): void;
|
|
178
|
+
setMultiAnimationSettings(settings: AnimationSettings[]): void;
|
|
179
|
+
setSegment(segment: Vector2): void;
|
|
180
|
+
setSpeed(value?: number): void;
|
|
181
|
+
setSubframe(value: boolean): void;
|
|
182
|
+
snapshot(shouldDownload?: boolean, name?: string): string | null;
|
|
183
|
+
stop(): void;
|
|
184
|
+
toggleBoomerang(): void;
|
|
185
|
+
toggleLoop(): void;
|
|
186
|
+
togglePlay(): void;
|
|
187
|
+
protected _freeze(): void;
|
|
188
|
+
protected _handleBlur(): void;
|
|
189
|
+
protected _handleSeekChange({ target }: Event): void;
|
|
190
|
+
protected _handleSettingsClick({ target }: Event): void;
|
|
191
|
+
protected setOptions(_options: {
|
|
192
|
+
container?: HTMLElement;
|
|
193
|
+
rendererType: RendererType;
|
|
194
|
+
initialSegment?: Vector2;
|
|
195
|
+
hasAutoplay: boolean;
|
|
196
|
+
hasLoop: boolean;
|
|
197
|
+
preserveAspectRatio: PreserveAspectRatio;
|
|
198
|
+
}): AnimationConfiguration<RendererType.SVG | RendererType.Canvas | RendererType.HTML>;
|
|
199
|
+
private _addEventListeners;
|
|
200
|
+
private _addIntersectionObserver;
|
|
201
|
+
private _complete;
|
|
202
|
+
private _dataFailed;
|
|
203
|
+
private _dataReady;
|
|
204
|
+
private _DOMLoaded;
|
|
205
|
+
private _enterFrame;
|
|
206
|
+
private _getOptions;
|
|
207
|
+
private _handleScroll;
|
|
208
|
+
private _handleWindowBlur;
|
|
209
|
+
private _loopComplete;
|
|
210
|
+
private _mouseEnter;
|
|
211
|
+
private _mouseLeave;
|
|
212
|
+
private _onVisibilityChange;
|
|
213
|
+
private _removeEventListeners;
|
|
214
|
+
private _switchInstance;
|
|
215
|
+
private _toggleEventListeners;
|
|
216
|
+
private _toggleSettings;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
declare class DotLottiePlayerLight extends DotLottiePlayerBase {
|
|
220
|
+
loadAnimation: typeof _aarsteinmedia_lottie_web_light.loadAnimation;
|
|
221
|
+
get renderer(): RendererType;
|
|
222
|
+
constructor();
|
|
223
|
+
protected setOptions({ container, hasAutoplay, hasLoop, initialSegment, preserveAspectRatio, }: {
|
|
224
|
+
container?: HTMLElement;
|
|
225
|
+
rendererType: RendererType;
|
|
226
|
+
initialSegment?: Vector2;
|
|
227
|
+
hasAutoplay: boolean;
|
|
228
|
+
hasLoop: boolean;
|
|
229
|
+
preserveAspectRatio: PreserveAspectRatio;
|
|
230
|
+
}): AnimationConfiguration<RendererType.SVG>;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export { PlayerState, DotLottiePlayerLight as default, tagName };
|