@aarsteinmedia/dotlottie-player 6.3.2 → 6.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/light.js CHANGED
@@ -1,1727 +1,9 @@
1
- import { isServer, PlayMode, PreserveAspectRatio, namespaceSVG, RendererType, createElementID, PlayerEvents, download, getFilename, clamp } from '@aarsteinmedia/lottie-web/utils';
1
+ import { RendererType, isServer } from '@aarsteinmedia/lottie-web/utils';
2
2
  export { PlayMode, PlayerEvents, RendererType } from '@aarsteinmedia/lottie-web/utils';
3
3
  import Lottie from '@aarsteinmedia/lottie-web/light';
4
- import { convert, getAnimationData } from '@aarsteinmedia/lottie-web/dotlottie';
5
-
6
- /**
7
- * Credit to: Leonardo Favre https://github.com/leofavre/observed-properties.
8
- */ const updateOnConnected = Symbol('UPDATE_ON_CONNECTED');
9
- if (isServer) {
10
- // Mock HTMLElement for server-side rendering
11
- global.HTMLElement = // eslint-disable-next-line @typescript-eslint/no-extraneous-class
12
- class EmptyHTMLElement {
13
- };
14
- }
15
- /**
16
- * HTMLElement enhanced to track property changes.
17
- */ class PropertyCallbackElement extends HTMLElement {
18
- constructor(){
19
- super();
20
- if (updateOnConnected in this) {
21
- this[updateOnConnected] = [];
22
- }
23
- const { observedProperties } = this.constructor;
24
- const { length } = observedProperties;
25
- for(let i = 0; i < length; i++){
26
- const initialValue = this[observedProperties[i]], cachedValue = Symbol(observedProperties[i]);
27
- this[cachedValue] = initialValue;
28
- Object.defineProperty(this, observedProperties[i] ?? '', {
29
- get () {
30
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
31
- return this[cachedValue];
32
- },
33
- set (value) {
34
- const oldValue = this[cachedValue];
35
- this[cachedValue] = value;
36
- this.propertyChangedCallback(observedProperties[i], oldValue, value);
37
- }
38
- });
39
- if (typeof initialValue !== 'undefined' && updateOnConnected in this && Array.isArray(this[updateOnConnected])) {
40
- this[updateOnConnected].push(observedProperties[i]);
41
- }
42
- }
43
- }
44
- connectedCallback() {
45
- let arr = [];
46
- if (updateOnConnected in this && Array.isArray(this[updateOnConnected])) {
47
- arr = this[updateOnConnected];
48
- }
49
- const { length } = arr;
50
- for(let i = 0; i < length; i++){
51
- if (!('propertyChangedCallback' in this) || typeof this.propertyChangedCallback !== 'function') {
52
- continue;
53
- }
54
- if (arr[i] ?? '' in this) {
55
- this.propertyChangedCallback(arr[i] ?? '', undefined, this[arr[i]]);
56
- }
57
- }
58
- }
59
- propertyChangedCallback(_name, _oldValue, _value) {
60
- throw new Error(`${this.constructor.name}: Method propertyChangedCallback is not implemented`);
61
- }
62
- }
63
-
64
- var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-toolbar-height: 35px;\n --lottie-player-toolbar-background-color: #fff;\n --lottie-player-toolbar-icon-color: #000;\n --lottie-player-toolbar-icon-hover-color: #000;\n --lottie-player-toolbar-icon-active-color: #4285f4;\n --lottie-player-seeker-track-color: rgb(0 0 0 / 20%);\n --lottie-player-seeker-thumb-color: #4285f4;\n --lottie-player-seeker-display: block;\n\n width: 100%;\n height: 100%;\n\n &:not([hidden]) {\n display: block;\n }\n\n .main {\n display: flex;\n flex-direction: column;\n height: 100%;\n width: 100%;\n margin: 0;\n padding: 0;\n }\n\n .animation {\n width: 100%;\n height: 100%;\n display: flex;\n margin: 0;\n padding: 0;\n }\n\n [data-controls='true'] .animation {\n height: calc(100% - 35px);\n }\n\n .animation-container {\n position: relative;\n }\n\n .popover {\n position: absolute;\n right: 5px;\n bottom: 40px;\n background-color: var(--lottie-player-toolbar-background-color);\n border-radius: 5px;\n padding: 10px 15px;\n border: solid 2px var(--lottie-player-toolbar-icon-color);\n animation: fade-in 0.2s ease-in-out;\n\n &::before {\n content: '';\n right: 10px;\n border: 7px solid transparent;\n margin-right: -7px;\n height: 0;\n width: 0;\n position: absolute;\n pointer-events: none;\n top: 100%;\n border-top-color: var(--lottie-player-toolbar-icon-color);\n }\n }\n\n .error {\n display: flex;\n margin: auto;\n justify-content: center;\n height: 100%;\n align-items: center;\n\n & svg {\n width: 100%;\n height: auto;\n }\n }\n\n .toolbar {\n display: flex;\n place-items: center center;\n background: var(--lottie-player-toolbar-background-color);\n margin: 0;\n height: 35px;\n padding: 5px;\n border-radius: 5px;\n gap: 5px;\n\n &.has-error {\n pointer-events: none;\n opacity: 0.5;\n }\n\n & button {\n cursor: pointer;\n fill: var(--lottie-player-toolbar-icon-color);\n color: var(--lottie-player-toolbar-icon-color);\n background: none;\n border: 0;\n padding: 0;\n outline: 0;\n height: 100%;\n margin: 0;\n align-items: center;\n gap: 5px;\n opacity: 0.9;\n\n &:not([hidden]) {\n display: flex;\n }\n\n &:hover {\n opacity: 1;\n }\n\n &[data-active='true'] {\n opacity: 1;\n fill: var(--lottie-player-toolbar-icon-active-color);\n }\n\n &:disabled {\n opacity: 0.5;\n }\n\n &:focus {\n outline: 0;\n }\n\n & svg {\n pointer-events: none;\n\n & > * {\n fill: inherit;\n }\n }\n\n &.disabled svg {\n display: none;\n }\n }\n }\n\n .progress-container {\n position: relative;\n width: 100%;\n\n &.simple {\n margin-right: 12px;\n }\n }\n\n & progress {\n appearance: none;\n outline: none;\n position: absolute;\n width: 100%;\n height: 5px;\n border-radius: 3px;\n border: 0;\n top: 0;\n left: 0;\n margin: 7.5px 0;\n background-color: var(--lottie-player-seeker-track-color);\n pointer-events: none;\n\n &::-webkit-progress-inner-element {\n border-radius: 3px;\n overflow: hidden;\n }\n\n &::-webkit-slider-runnable-track {\n background-color: transparent;\n }\n\n &::-webkit-progress-value {\n background-color: var(--lottie-player-seeker-thumb-color);\n }\n }\n\n .seeker {\n appearance: none;\n outline: none;\n width: 100%;\n height: 20px;\n border-radius: 3px;\n border: 0;\n cursor: pointer;\n background-color: transparent;\n\n display: var(--lottie-player-seeker-display);\n color: var(--lottie-player-seeker-thumb-color);\n margin: 0;\n padding: 7.5px 0;\n position: relative;\n z-index: 1;\n\n &::-webkit-slider-runnable-track,\n &::-webkit-slider-thumb {\n appearance: none;\n outline: none;\n }\n\n &::-webkit-slider-thumb {\n height: 15px;\n width: 15px;\n border-radius: 50%;\n border: 0;\n background-color: var(--lottie-player-seeker-thumb-color);\n cursor: pointer;\n -webkit-transition: transform 0.2s ease-in-out;\n transition: transform 0.2s ease-in-out;\n transform: scale(0);\n }\n\n &:hover::-webkit-slider-thumb,\n &:focus::-webkit-slider-thumb {\n transform: scale(1);\n }\n\n &::-moz-range-progress {\n background-color: var(--lottie-player-seeker-thumb-color);\n height: 5px;\n border-radius: 3px;\n }\n\n &::-moz-range-thumb {\n height: 15px;\n width: 15px;\n border-radius: 50%;\n background-color: var(--lottie-player-seeker-thumb-color);\n border: 0;\n cursor: pointer;\n -moz-transition: transform 0.2s ease-in-out;\n transition: transform 0.2s ease-in-out;\n transform: scale(0);\n }\n\n &:hover::-moz-range-thumb,\n &:focus::-moz-range-thumb {\n transform: scale(1);\n }\n\n &::-ms-track {\n width: 100%;\n height: 5px;\n cursor: pointer;\n background: transparent;\n border-color: transparent;\n color: transparent;\n }\n\n &::-ms-fill-upper {\n background: var(--lottie-player-seeker-track-color);\n border-radius: 3px;\n }\n\n &::-ms-fill-lower {\n background-color: var(--lottie-player-seeker-thumb-color);\n border-radius: 3px;\n }\n\n &::-ms-thumb {\n border: 0;\n height: 15px;\n width: 15px;\n border-radius: 50%;\n background: var(--lottie-player-seeker-thumb-color);\n cursor: pointer;\n -ms-transition: transform 0.2s ease-in-out;\n transition: transform 0.2s ease-in-out;\n transform: scale(0);\n }\n\n &:hover::-ms-thumb {\n transform: scale(1);\n }\n\n &:focus {\n &::-ms-thumb {\n transform: scale(1);\n }\n\n &::-ms-fill-lower,\n &::-ms-fill-upper {\n background: var(--lottie-player-seeker-track-color);\n }\n }\n }\n\n & *::-moz-progress-bar {\n background-color: var(--lottie-player-seeker-thumb-color);\n }\n}\n\n@keyframes fade-in {\n 0% {\n opacity: 0;\n }\n\n 100% {\n opacity: 1;\n }\n}\n\n@media (prefers-color-scheme: dark) {\n :host {\n --lottie-player-toolbar-background-color: #000;\n --lottie-player-toolbar-icon-color: #fff;\n --lottie-player-toolbar-icon-hover-color: #fff;\n --lottie-player-seeker-track-color: rgb(255 255 255 / 60%);\n }\n}\n";
65
-
66
- const boomerangIcon = /* HTML */ `
67
- <svg width="24" height="24" aria-hidden="true" focusable="false">
68
- <path
69
- d="m11.8 13.2-.3.3c-.5.5-1.1 1.1-1.7 1.5-.5.4-1 .6-1.5.8-.5.2-1.1.3-1.6.3s-1-.1-1.5-.3c-.6-.2-1-.5-1.4-1-.5-.6-.8-1.2-.9-1.9-.2-.9-.1-1.8.3-2.6.3-.7.8-1.2 1.3-1.6.3-.2.6-.4 1-.5.2-.2.5-.2.8-.3.3 0 .7-.1 1 0 .3 0 .6.1.9.2.9.3 1.7.9 2.4 1.5.4.4.8.7 1.1 1.1l.1.1.4-.4c.6-.6 1.2-1.2 1.9-1.6.5-.3 1-.6 1.5-.7.4-.1.7-.2 1-.2h.9c1 .1 1.9.5 2.6 1.4.4.5.7 1.1.8 1.8.2.9.1 1.7-.2 2.5-.4.9-1 1.5-1.8 2-.4.2-.7.4-1.1.4-.4.1-.8.1-1.2.1-.5 0-.9-.1-1.3-.3-.8-.3-1.5-.9-2.1-1.5-.4-.4-.8-.7-1.1-1.1h-.3zm-1.1-1.1c-.1-.1-.1-.1 0 0-.3-.3-.6-.6-.8-.9-.5-.5-1-.9-1.6-1.2-.4-.3-.8-.4-1.3-.4-.4 0-.8 0-1.1.2-.5.2-.9.6-1.1 1-.2.3-.3.7-.3 1.1 0 .3 0 .6.1.9.1.5.4.9.8 1.2.5.4 1.1.5 1.7.5.5 0 1-.2 1.5-.5.6-.4 1.1-.8 1.6-1.3.1-.3.3-.5.5-.6zM13 12c.5.5 1 1 1.5 1.4.5.5 1.1.9 1.9 1 .4.1.8 0 1.2-.1.3-.1.6-.3.9-.5.4-.4.7-.9.8-1.4.1-.5 0-.9-.1-1.4-.3-.8-.8-1.2-1.7-1.4-.4-.1-.8-.1-1.2 0-.5.1-1 .4-1.4.7-.5.4-1 .8-1.4 1.2-.2.2-.4.3-.5.5z"
70
- />
71
- </svg>
72
- `;
73
-
74
- const convertIcon = /* HTML */ `
75
- <svg
76
- width="24"
77
- height="24"
78
- aria-hidden="true"
79
- focusable="false"
80
- >
81
- <path
82
- d="M17.016 17.016v-4.031h1.969v6h-12v3l-3.984-3.984 3.984-3.984v3h10.031zM6.984 6.984v4.031H5.015v-6h12v-3l3.984 3.984-3.984 3.984v-3H6.984z"
83
- />
84
- </svg>
85
- `;
86
-
87
- const downloadIcon = /* HTML */ `
88
- <svg
89
- width="24"
90
- height="24"
91
- aria-hidden="true"
92
- focusable="false"
93
- >
94
- <path
95
- d="M16.8 10.8 12 15.6l-4.8-4.8h3V3.6h3.6v7.2h3zM12 15.6H3v4.8h18v-4.8h-9zm7.8 2.4h-2.4v-1.2h2.4V18z"
96
- />
97
- </svg>
98
- `;
99
-
100
- const loopIcon = /* HTML */ `
101
- <svg width="24" height="24" aria-hidden="true" focusable="false">
102
- <path
103
- d="M17.016 17.016v-4.031h1.969v6h-12v3l-3.984-3.984 3.984-3.984v3h10.031zM6.984 6.984v4.031H5.015v-6h12v-3l3.984 3.984-3.984 3.984v-3H6.984z"
104
- />
105
- </svg>
106
- `;
107
-
108
- const nextIcon = /* HTML */ `
109
- <svg width="24" height="24" aria-hidden="true" focusable="false">
110
- <path d="m6.1 5.8 9.8 6.2-9.8 6.2V5.8zM16.4 5.8h1.5v12.4h-1.5z" />
111
- </svg>
112
- `;
113
-
114
- const playIcon = /* HTML */ `
115
- <svg width="24" height="24" aria-hidden="true" focusable="false">
116
- <path d="M8.016 5.016L18.985 12 8.016 18.984V5.015z" />
117
- </svg>
118
- `;
119
-
120
- const prevIcon = /* HTML */ `
121
- <svg width="24" height="24" aria-hidden="true" focusable="false">
122
- <path d="M17.9 18.2 8.1 12l9.8-6.2v12.4zm-10.3 0H6.1V5.8h1.5v12.4z" />
123
- </svg>
124
- `;
125
-
126
- const settingsIcon = /* HTML */ `
127
- <svg width="24" height="24" aria-hidden="true" focusable="false">
128
- <circle cx="12" cy="5.4" r="2.5" />
129
- <circle cx="12" cy="12" r="2.5" />
130
- <circle cx="12" cy="18.6" r="2.5" />
131
- </svg>
132
- `;
133
-
134
- const stopIcon = /* HTML */ `
135
- <svg width="24" height="24" aria-hidden="true" focusable="false">
136
- <path d="M6 6h12v12H6V6z" />
137
- </svg>
138
- `;
139
-
140
- var ObjectFit = /*#__PURE__*/ function(ObjectFit) {
141
- ObjectFit["Contain"] = "contain";
142
- ObjectFit["Cover"] = "cover";
143
- ObjectFit["Fill"] = "fill";
144
- ObjectFit["None"] = "none";
145
- ObjectFit["ScaleDown"] = "scale-down";
146
- return ObjectFit;
147
- }({});
148
- var MouseOut = /*#__PURE__*/ function(MouseOut) {
149
- MouseOut["Pause"] = "pause";
150
- MouseOut["Reverse"] = "reverse";
151
- MouseOut["Stop"] = "stop";
152
- MouseOut["Void"] = "void";
153
- return MouseOut;
154
- }({});
155
- var PlayerState = /*#__PURE__*/ function(PlayerState) {
156
- PlayerState["Completed"] = "completed";
157
- PlayerState["Destroyed"] = "destroyed";
158
- PlayerState["Error"] = "error";
159
- PlayerState["Frozen"] = "frozen";
160
- PlayerState["Loading"] = "loading";
161
- PlayerState["Paused"] = "paused";
162
- PlayerState["Playing"] = "playing";
163
- PlayerState["Stopped"] = "stopped";
164
- return PlayerState;
165
- }({});
166
- const tagName = 'dotlottie-player';
167
-
168
- /**
169
- * Render Controls.
170
- */ function renderControls() {
171
- if (!this.shadow) {
172
- throw new Error('No Shadow Element');
173
- }
174
- const slot = this.shadow.querySelector('slot[name=controls]');
175
- if (!slot) {
176
- return;
177
- }
178
- if (!this.controls) {
179
- slot.innerHTML = '';
180
- return;
181
- }
182
- slot.innerHTML = /* HTML */ `<div class="lottie-controls toolbar ${this.playerState === PlayerState.Error ? 'has-error' : ''}" aria-label="Lottie Animation controls"><button class="togglePlay" data-active="${this.autoplay}" aria-label="Toggle Play/Pause">${playIcon}</button> <button class="stop" data-active="${!this.autoplay}" aria-label="Stop">${stopIcon}</button> <button class="prev" aria-label="Previous animation" hidden="false">${prevIcon}</button> <button class="next" aria-label="Next animation" hidden>${nextIcon}</button><form class="progress-container${this.simple ? ' simple' : ''}"><input type="range" class="seeker" min="0" max="100" step="1" value="${this._seeker.toString()}" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${this._seeker.toString()}" tabindex="0" aria-label="Slider for search"><progress max="100" value="${this._seeker}"></progress></form>${this.simple ? '' : /* HTML */ `<button class="toggleLoop" data-active="${this.loop}" tabindex="0" aria-label="Toggle loop">${loopIcon}</button> <button class="toggleBoomerang" data-active="${this.mode === PlayMode.Bounce}" aria-label="Toggle boomerang" tabindex="0">${boomerangIcon}</button> <button class="toggleSettings" aria-label="Settings" aria-haspopup="true" aria-expanded="${this._isSettingsOpen}" aria-controls="${this._identifier}-settings">${settingsIcon}</button><div id="${this._identifier}-settings" class="popover" hidden><button class="convert" aria-label="Convert JSON animation to dotLottie format" aria-label="Convert ${this.isDotLottie ? 'dotLottie animation to JSON format' : 'JSON animation to dotLottie format'}" hidden>${convertIcon} ${this.isDotLottie ? 'Convert to JSON' : 'Convert to dotLottie'}</button> <button class="snapshot" aria-label="Download still image">${downloadIcon} Download still image</button></div>`}</div>`;
183
- const togglePlay = this.shadow.querySelector('.togglePlay');
184
- if (togglePlay instanceof HTMLButtonElement) {
185
- togglePlay.onclick = this.togglePlay;
186
- }
187
- const stopButton = this.shadow.querySelector('.stop');
188
- if (stopButton instanceof HTMLButtonElement) {
189
- stopButton.onclick = this.stop;
190
- }
191
- const prevButton = this.shadow.querySelector('.prev');
192
- if (prevButton instanceof HTMLButtonElement) {
193
- if (this.animations.length > 0 && this.currentAnimation) {
194
- prevButton.hidden = false;
195
- }
196
- prevButton.onclick = this.prev;
197
- }
198
- const nextButton = this.shadow.querySelector('.next');
199
- if (nextButton instanceof HTMLButtonElement) {
200
- if (this.animations.length > 0 && this.currentAnimation < this.animations.length - 1) {
201
- nextButton.hidden = false;
202
- }
203
- nextButton.onclick = this.next;
204
- }
205
- const seeker = this.shadow.querySelector('.seeker');
206
- if (seeker instanceof HTMLInputElement) {
207
- seeker.onchange = this._handleSeekChange;
208
- seeker.onmousedown = this._freeze;
209
- }
210
- if (!this.simple) {
211
- const toggleLoop = this.shadow.querySelector('.toggleLoop');
212
- if (toggleLoop instanceof HTMLButtonElement) {
213
- toggleLoop.onclick = this.toggleLoop;
214
- }
215
- const toggleBoomerang = this.shadow.querySelector('.toggleBoomerang');
216
- if (toggleBoomerang instanceof HTMLButtonElement) {
217
- toggleBoomerang.onclick = this.toggleBoomerang;
218
- }
219
- const convertButton = this.shadow.querySelector('.convert');
220
- if (convertButton instanceof HTMLButtonElement) {
221
- convertButton.onclick = ()=>{
222
- void convert({
223
- isDotLottie: this.isDotLottie,
224
- manifest: this.getManifest(),
225
- src: this.src || this.source
226
- });
227
- };
228
- }
229
- const snapshot = this.shadow.querySelector('.snapshot');
230
- if (snapshot instanceof HTMLButtonElement) {
231
- snapshot.onclick = ()=>this.snapshot(true);
232
- }
233
- const toggleSettings = this.shadow.querySelector('.toggleSettings');
234
- if (toggleSettings instanceof HTMLButtonElement) {
235
- toggleSettings.onclick = this._handleSettingsClick;
236
- toggleSettings.onblur = this._handleBlur;
237
- }
238
- }
239
- }
240
-
241
- const pauseIcon = /* HTML */ `
242
- <svg width="24" height="24" aria-hidden="true" focusable="false">
243
- <path
244
- d="M14.016 5.016H18v13.969h-3.984V5.016zM6 18.984V5.015h3.984v13.969H6z"
245
- />
246
- </svg>
247
- `;
248
-
249
- /**
250
- * Render Player.
251
- */ async function renderPlayer() {
252
- if (!this.shadow || !this.template) {
253
- throw new Error('No Shadow Element or Template');
254
- }
255
- this.template.innerHTML = /* HTML */ `<div class="animation-container main" data-controls="${this.controls ?? false}" lang="${this.description ? document.documentElement.lang : 'en'}" data-loaded="${this._playerState.loaded}"><figure class="animation" style="background:${this.background}" ${this.description ? /* HTML */ `
256
- aria-label="${this.description}"
257
- ` : ''}>${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>`;
258
- this.shadow.adoptedStyleSheets = [
259
- await DotLottiePlayerBase.styles()
260
- ];
261
- this.shadow.appendChild(this.template.content.cloneNode(true));
262
- }
263
-
264
- /**
265
- * Get extension from filename, URL or path.
266
- */ const aspectRatio = (objectFit)=>{
267
- switch(objectFit){
268
- case ObjectFit.Contain:
269
- case ObjectFit.ScaleDown:
270
- {
271
- return PreserveAspectRatio.Contain;
272
- }
273
- case ObjectFit.Cover:
274
- {
275
- return PreserveAspectRatio.Cover;
276
- }
277
- case ObjectFit.Fill:
278
- {
279
- return PreserveAspectRatio.Initial;
280
- }
281
- case ObjectFit.None:
282
- {
283
- return PreserveAspectRatio.None;
284
- }
285
- default:
286
- {
287
- return PreserveAspectRatio.Contain;
288
- }
289
- }
290
- }, handleErrors = (err)=>{
291
- const res = {
292
- message: 'Unknown error',
293
- status: isServer ? 500 : 400
294
- };
295
- if (err && typeof err === 'object') {
296
- if ('message' in err && typeof err.message === 'string') {
297
- res.message = err.message;
298
- }
299
- if ('status' in err) {
300
- res.status = Number(err.status);
301
- }
302
- }
303
- return res;
304
- }, isLottie = (json)=>{
305
- const mandatory = [
306
- 'v',
307
- 'ip',
308
- 'op',
309
- 'layers',
310
- 'fr',
311
- 'w',
312
- 'h'
313
- ];
314
- return mandatory.every((field)=>Object.hasOwn(json, field));
315
- }, isTouch = ()=>'ontouchstart' in window, frameOutput = (frame)=>((frame ?? 0) + 1).toString().padStart(3, '0');
316
-
317
- const notImplemented = 'Method is not implemented', getStyles = async ()=>{
318
- const styleSheet = new CSSStyleSheet();
319
- await styleSheet.replace(css_248z);
320
- return styleSheet;
321
- };
322
- /**
323
- * DotLottie Player Web Component.
324
- */ class DotLottiePlayerBase extends PropertyCallbackElement {
325
- /**
326
- * Attributes to observe.
327
- */ static get observedAttributes() {
328
- return [
329
- 'animateOnScroll',
330
- 'autoplay',
331
- 'controls',
332
- 'direction',
333
- 'hover',
334
- 'loop',
335
- 'mode',
336
- 'playOnClick',
337
- 'playOnVisible',
338
- 'selector',
339
- 'speed',
340
- 'src',
341
- 'subframe'
342
- ];
343
- }
344
- static get observedProperties() {
345
- return [
346
- 'playerState',
347
- '_isSettingsOpen',
348
- '_seeker',
349
- '_currentAnimation',
350
- '_animations'
351
- ];
352
- }
353
- /**
354
- * Return the styles for the component.
355
- */ static get styles() {
356
- return getStyles;
357
- }
358
- /**
359
- * Whether to trigger next frame with scroll.
360
- */ set animateOnScroll(value) {
361
- this.setAttribute('animateOnScroll', Boolean(value).toString());
362
- }
363
- get animateOnScroll() {
364
- const val = this.getAttribute('animateOnScroll');
365
- return val === 'true' || val === '' || val === '1';
366
- }
367
- get animations() {
368
- return this._animations;
369
- }
370
- /**
371
- * Autoplay.
372
- */ set autoplay(value) {
373
- this.setAttribute('autoplay', Boolean(value).toString());
374
- }
375
- get autoplay() {
376
- const val = this.getAttribute('autoplay');
377
- return val === 'true' || val === '' || val === '1';
378
- }
379
- /**
380
- * Background color.
381
- */ set background(value) {
382
- this.setAttribute('background', value);
383
- }
384
- get background() {
385
- return this.getAttribute('background') || 'transparent';
386
- }
387
- /**
388
- * Show controls.
389
- */ set controls(value) {
390
- this.setAttribute('controls', Boolean(value).toString());
391
- }
392
- get controls() {
393
- const val = this.getAttribute('controls');
394
- return val === 'true' || val === '' || val === '1';
395
- }
396
- /**
397
- * Number of times to loop.
398
- */ set count(value) {
399
- this.setAttribute('count', value.toString());
400
- }
401
- get count() {
402
- const val = this.getAttribute('count');
403
- if (val) {
404
- return Number(val);
405
- }
406
- return 0;
407
- }
408
- get currentAnimation() {
409
- return this._currentAnimation;
410
- }
411
- /**
412
- * Delay playback on playOnVisible.
413
- */ set delay(value) {
414
- this.setAttribute('delay', value.toString());
415
- }
416
- get delay() {
417
- const val = this.getAttribute('delay');
418
- if (val) {
419
- return Number(val);
420
- }
421
- return 0;
422
- }
423
- /**
424
- * Description for screen readers.
425
- */ set description(value) {
426
- if (value) {
427
- this.setAttribute('description', value);
428
- }
429
- }
430
- get description() {
431
- return this.getAttribute('description');
432
- }
433
- /**
434
- * Direction of animation.
435
- */ set direction(value) {
436
- this.setAttribute('direction', value.toString());
437
- }
438
- get direction() {
439
- const val = Number(this.getAttribute('direction'));
440
- if (val === -1) {
441
- return val;
442
- }
443
- return 1;
444
- }
445
- /**
446
- * Whether to freeze animation when window loses focus.
447
- */ set dontFreezeOnBlur(value) {
448
- this.setAttribute('dontFreezeOnBlur', Boolean(value).toString());
449
- }
450
- get dontFreezeOnBlur() {
451
- const val = this.getAttribute('dontFreezeOnBlur');
452
- return val === 'true' || val === '' || val === '1';
453
- }
454
- /**
455
- * Whether to play on mouseover.
456
- */ set hover(value) {
457
- this.setAttribute('hover', Boolean(value).toString());
458
- }
459
- get hover() {
460
- const val = this.getAttribute('hover');
461
- return val === 'true' || val === '' || val === '1';
462
- }
463
- /**
464
- * Pause between loop intrations, in miliseconds.
465
- */ set intermission(value) {
466
- this.setAttribute('intermission', value.toString());
467
- }
468
- get intermission() {
469
- const val = Number(this.getAttribute('intermission'));
470
- if (!isNaN(val)) {
471
- return val;
472
- }
473
- return 0;
474
- }
475
- get isDotLottie() {
476
- return this._isDotLottie;
477
- }
478
- /**
479
- * Loop animation.
480
- */ set loop(value) {
481
- this.setAttribute('loop', Boolean(value).toString());
482
- }
483
- get loop() {
484
- const val = this.getAttribute('loop');
485
- return val === 'true' || val === '' || val === '1';
486
- }
487
- /**
488
- * Play mode.
489
- */ set mode(value) {
490
- this.setAttribute('mode', value);
491
- }
492
- get mode() {
493
- const val = this.getAttribute('mode');
494
- if (val === PlayMode.Bounce) {
495
- return val;
496
- }
497
- return PlayMode.Normal;
498
- }
499
- /**
500
- * Action on mouseout.
501
- */ set mouseout(value) {
502
- this.setAttribute('mouseout', value);
503
- }
504
- get mouseout() {
505
- const val = this.getAttribute('mouseout');
506
- switch(val){
507
- case MouseOut.Void:
508
- case MouseOut.Pause:
509
- case MouseOut.Reverse:
510
- {
511
- return val;
512
- }
513
- default:
514
- {
515
- return MouseOut.Stop;
516
- }
517
- }
518
- }
519
- /**
520
- * Resizing to container.
521
- */ set objectfit(value) {
522
- this.setAttribute('objectfit', value);
523
- }
524
- get objectfit() {
525
- const val = this.getAttribute('objectfit');
526
- if (val && Object.values(ObjectFit).includes(val)) {
527
- return val;
528
- }
529
- return ObjectFit.Contain;
530
- }
531
- /**
532
- * Whether to play once or reset,
533
- * if playOnVisible is true.
534
- */ set once(value) {
535
- this.setAttribute('once', Boolean(value).toString());
536
- }
537
- get once() {
538
- const val = this.getAttribute('once');
539
- return val === 'true' || val === '' || val === '1';
540
- }
541
- /**
542
- * Whether to toggle play on click.
543
- */ set playOnClick(value) {
544
- this.setAttribute('playOnClick', Boolean(value).toString());
545
- }
546
- get playOnClick() {
547
- const val = this.getAttribute('playOnClick');
548
- return val === 'true' || val === '' || val === '1';
549
- }
550
- /**
551
- * Play when visible.
552
- */ set playOnVisible(value) {
553
- this.setAttribute('playOnVisible', Boolean(value).toString());
554
- }
555
- get playOnVisible() {
556
- const val = this.getAttribute('playOnVisible');
557
- return val === 'true' || val === '' || val === '1';
558
- }
559
- /**
560
- * Resizing to container (Deprecated).
561
- */ set preserveAspectRatio(value) {
562
- this.setAttribute('preserveAspectRatio', value || PreserveAspectRatio.Contain);
563
- }
564
- get preserveAspectRatio() {
565
- const val = this.getAttribute('preserveAspectRatio');
566
- if (val && Object.values(PreserveAspectRatio).includes(val)) {
567
- return val;
568
- }
569
- return null;
570
- }
571
- /**
572
- * Renderer to use: svg, canvas or html.
573
- */ set renderer(value) {
574
- this.setAttribute('renderer', value);
575
- }
576
- get renderer() {
577
- const val = this.getAttribute('renderer');
578
- if (val === RendererType.Canvas || val === RendererType.HTML) {
579
- return val;
580
- }
581
- return RendererType.SVG;
582
- }
583
- /**
584
- * Play on clicked element by id attribute, other than animation.
585
- */ set selector(value) {
586
- if (value) {
587
- this.setAttribute('selector', value);
588
- return;
589
- }
590
- this.removeAttribute('selector');
591
- }
592
- get selector() {
593
- return this.getAttribute('selector');
594
- }
595
- /**
596
- * Hide advanced controls.
597
- */ set simple(value) {
598
- this.setAttribute('simple', Boolean(value).toString());
599
- }
600
- get simple() {
601
- const val = this.getAttribute('simple');
602
- return val === 'true' || val === '' || val === '1';
603
- }
604
- /**
605
- * Speed.
606
- */ set speed(value) {
607
- this.setAttribute('speed', value.toString());
608
- }
609
- get speed() {
610
- const val = this.getAttribute('speed');
611
- if (val !== null && !isNaN(Number(val))) {
612
- return Number(val);
613
- }
614
- return 1;
615
- }
616
- /**
617
- * Source, either path or JSON string.
618
- */ set src(value) {
619
- this.setAttribute('src', value || '');
620
- }
621
- get src() {
622
- return this.getAttribute('src');
623
- }
624
- /**
625
- * Subframe.
626
- */ set subframe(value) {
627
- this.setAttribute('subframe', Boolean(value).toString());
628
- }
629
- get subframe() {
630
- const val = this.getAttribute('subframe');
631
- return val === 'true' || val === '' || val === '1';
632
- }
633
- constructor(){
634
- super(), this.isLight = false, /**
635
- * Player state.
636
- */ this.playerState = PlayerState.Loading, /**
637
- * Animation Container.
638
- */ this._container = null, this._DOMRect = null, this._errorMessage = 'Something went wrong', this._identifier = this.id || createElementID(), /**
639
- * Whether settings toolbar is open.
640
- */ this._isSettingsOpen = false, this._playerState = {
641
- count: 0,
642
- loaded: false,
643
- prev: PlayerState.Loading,
644
- scrollTimeout: null,
645
- scrollY: 0,
646
- visible: false
647
- }, this._render = renderPlayer, this._renderControls = renderControls, /**
648
- * Seeker.
649
- */ this._seeker = 0, /**
650
- * This is included in watched properties,
651
- * so that next-button will show up
652
- * on load, if controls are visible.
653
- */ this._animations = [], /**
654
- * Which animation to show, if several.
655
- */ this._currentAnimation = 0, this._isBounce = false, this._isDotLottie = false, this._lottieInstance = null, /**
656
- * Multi-animation settings.
657
- */ this._multiAnimationSettings = [];
658
- this._complete = this._complete.bind(this);
659
- this._dataFailed = this._dataFailed.bind(this);
660
- this._dataReady = this._dataReady.bind(this);
661
- this._DOMLoaded = this._DOMLoaded.bind(this);
662
- this._enterFrame = this._enterFrame.bind(this);
663
- this._freeze = this._freeze.bind(this);
664
- this._handleBlur = this._handleBlur.bind(this);
665
- this._handleClick = this._handleClick.bind(this);
666
- this._handleScroll = this._handleScroll.bind(this);
667
- this._handleSeekChange = this._handleSeekChange.bind(this);
668
- this._handleWindowBlur = this._handleWindowBlur.bind(this);
669
- this._loopComplete = this._loopComplete.bind(this);
670
- this._mouseEnter = this._mouseEnter.bind(this);
671
- this._mouseLeave = this._mouseLeave.bind(this);
672
- this._onVisibilityChange = this._onVisibilityChange.bind(this);
673
- this._switchInstance = this._switchInstance.bind(this);
674
- this._handleSettingsClick = this._handleSettingsClick.bind(this);
675
- this.togglePlay = this.togglePlay.bind(this);
676
- this.stop = this.stop.bind(this);
677
- this.prev = this.prev.bind(this);
678
- this.next = this.next.bind(this);
679
- this._renderControls = this._renderControls.bind(this);
680
- this.snapshot = this.snapshot.bind(this);
681
- this.toggleLoop = this.toggleLoop.bind(this);
682
- this.toggleBoomerang = this.toggleBoomerang.bind(this);
683
- this.destroy = this.destroy.bind(this);
684
- this.template = document.createElement('template');
685
- this.shadow = this.attachShadow({
686
- mode: 'open'
687
- });
688
- }
689
- addAnimation(_params) {
690
- throw new Error(notImplemented);
691
- }
692
- /**
693
- * Runs when the value of an attribute is changed on the component.
694
- */ async attributeChangedCallback(name, _oldValue, value) {
695
- if (!this._lottieInstance || !this.shadow || !this._container) {
696
- return;
697
- }
698
- switch(name){
699
- case 'animateOnScroll':
700
- {
701
- if (value === '' || Boolean(value)) {
702
- this._lottieInstance.autoplay = false;
703
- addEventListener('scroll', this._handleScroll, {
704
- capture: true,
705
- passive: true
706
- });
707
- return;
708
- }
709
- removeEventListener('scroll', this._handleScroll, true);
710
- break;
711
- }
712
- case 'autoplay':
713
- {
714
- if (this.animateOnScroll || this.playOnVisible) {
715
- return;
716
- }
717
- if (value === '' || Boolean(value)) {
718
- this.play();
719
- return;
720
- }
721
- this.stop();
722
- break;
723
- }
724
- case 'controls':
725
- {
726
- this._renderControls();
727
- break;
728
- }
729
- case 'direction':
730
- {
731
- if (Number(value) === -1) {
732
- this.setDirection(-1);
733
- return;
734
- }
735
- this.setDirection(1);
736
- break;
737
- }
738
- case 'hover':
739
- {
740
- if (value === '' || Boolean(value)) {
741
- this._container.addEventListener('mouseenter', this._mouseEnter);
742
- this._container.addEventListener('mouseleave', this._mouseLeave);
743
- return;
744
- }
745
- this._container.removeEventListener('mouseenter', this._mouseEnter);
746
- this._container.removeEventListener('mouseleave', this._mouseLeave);
747
- break;
748
- }
749
- case 'loop':
750
- {
751
- const toggleLoop = this.shadow.querySelector('.toggleLoop');
752
- if (toggleLoop instanceof HTMLButtonElement) {
753
- toggleLoop.dataset.active = value;
754
- }
755
- this.setLoop(value === '' || Boolean(value));
756
- break;
757
- }
758
- case 'mode':
759
- {
760
- const toggleBoomerang = this.shadow.querySelector('.toggleBoomerang');
761
- if (toggleBoomerang instanceof HTMLButtonElement) {
762
- toggleBoomerang.dataset.active = (value === PlayMode.Bounce).toString();
763
- }
764
- this._isBounce = value === PlayMode.Bounce;
765
- break;
766
- }
767
- case 'playOnClick':
768
- {
769
- if (value === '' || Boolean(value)) {
770
- this._lottieInstance.autoplay = false;
771
- this._container.addEventListener('click', this._handleClick);
772
- return;
773
- }
774
- this._container.removeEventListener('click', this._handleClick);
775
- break;
776
- }
777
- case 'playOnVisible':
778
- {
779
- if (value === '' || Boolean(value)) {
780
- this._lottieInstance.autoplay = false;
781
- }
782
- break;
783
- }
784
- case 'selector':
785
- {
786
- const selector = document.getElementById(this.selector ?? '');
787
- selector?.addEventListener('click', this._handleClick);
788
- break;
789
- }
790
- case 'speed':
791
- {
792
- const val = Number(value);
793
- if (val && !isNaN(val)) {
794
- this.setSpeed(val);
795
- }
796
- break;
797
- }
798
- case 'src':
799
- {
800
- await this.load(value);
801
- break;
802
- }
803
- case 'subframe':
804
- {
805
- this.setSubframe(value === '' || Boolean(value));
806
- break;
807
- }
808
- }
809
- }
810
- /**
811
- * Initialize everything on component first render.
812
- */ connectedCallback() {
813
- super.connectedCallback();
814
- try {
815
- void (async ()=>{
816
- await this._render();
817
- if (!this.shadow) {
818
- throw new Error('Missing Shadow element');
819
- }
820
- this._container = this.shadow.querySelector('.animation');
821
- // Setup lottie player
822
- await this.load(this.src);
823
- // Add listener for Visibility API's change event.
824
- if (typeof document.hidden !== 'undefined') {
825
- document.addEventListener('visibilitychange', this._onVisibilityChange);
826
- }
827
- if (this._container) {
828
- this._DOMRect = this._container.getBoundingClientRect();
829
- }
830
- // Add intersection observer for detecting component being out-of-view.
831
- this._addIntersectionObserver();
832
- this.dispatchEvent(new CustomEvent(PlayerEvents.Rendered));
833
- })();
834
- } catch (error) {
835
- console.error(error);
836
- this.dispatchEvent(new CustomEvent(PlayerEvents.Error));
837
- }
838
- }
839
- convert(_params) {
840
- throw new Error(notImplemented);
841
- }
842
- /**
843
- * Destroy animation and element.
844
- */ destroy() {
845
- if (!this._lottieInstance?.destroy) {
846
- return;
847
- }
848
- this.playerState = PlayerState.Destroyed;
849
- this._lottieInstance.destroy();
850
- this._lottieInstance = null;
851
- this.dispatchEvent(new CustomEvent(PlayerEvents.Destroyed));
852
- this.remove();
853
- document.removeEventListener('visibilitychange', this._onVisibilityChange);
854
- }
855
- /**
856
- * Cleanup on component destroy.
857
- */ disconnectedCallback() {
858
- // Remove intersection observer for detecting component being out-of-view
859
- if (this._intersectionObserver) {
860
- this._intersectionObserver.disconnect();
861
- this._intersectionObserver = undefined;
862
- }
863
- // Remove the attached Visibility API's change event listener
864
- document.removeEventListener('visibilitychange', this._onVisibilityChange);
865
- // Destroy the animation instance
866
- this.destroy();
867
- }
868
- /**
869
- * Returns the lottie-web instance used in the component.
870
- */ getLottie() {
871
- return this._lottieInstance;
872
- }
873
- /**
874
- * Get Lottie Manifest.
875
- */ getManifest() {
876
- return this._manifest;
877
- }
878
- /**
879
- * Get Multi-animation settings.
880
- */ getMultiAnimationSettings() {
881
- return this._multiAnimationSettings;
882
- }
883
- /**
884
- * Get playback segment.
885
- */ getSegment() {
886
- return this._segment;
887
- }
888
- /**
889
- * Initialize Lottie Web player.
890
- */ async load(src) {
891
- try {
892
- if (!this.shadowRoot || !src) {
893
- return;
894
- }
895
- this.source = src;
896
- // Load the resource
897
- const { animations, isDotLottie, manifest } = await getAnimationData(src);
898
- if (!animations || animations.some((animation)=>!isLottie(animation))) {
899
- throw new Error('Broken or corrupted file');
900
- }
901
- const ldScript = this.parentElement?.querySelector('script[type="application/ld+json"]');
902
- if (ldScript) {
903
- const settings = JSON.parse(ldScript.innerHTML);
904
- if (settings.selector) {
905
- this.selector = settings.selector;
906
- }
907
- if (settings.segment) {
908
- this.setSegment(settings.segment);
909
- }
910
- if (settings.multiAnimationSettings) {
911
- this.setMultiAnimationSettings(settings.multiAnimationSettings);
912
- }
913
- }
914
- this._isBounce = this.mode === PlayMode.Bounce;
915
- if (this._multiAnimationSettings.length > 0 && this._multiAnimationSettings[this._currentAnimation]?.mode) {
916
- this._isBounce = this._multiAnimationSettings[this._currentAnimation]?.mode === PlayMode.Bounce;
917
- }
918
- // Relevant for dotLotties with multiple animations
919
- const firstAnimation = manifest?.animations[0];
920
- if (firstAnimation) {
921
- firstAnimation.autoplay = !this.animateOnScroll && !this.playOnVisible && this.autoplay;
922
- firstAnimation.loop = this.loop;
923
- }
924
- this._isDotLottie = isDotLottie;
925
- this._animations = animations;
926
- this._manifest = manifest ?? {
927
- animations: [
928
- {
929
- autoplay: !this.animateOnScroll && !this.playOnVisible && this.autoplay,
930
- direction: this.direction,
931
- id: createElementID(),
932
- loop: this.loop,
933
- mode: this.mode,
934
- speed: this.speed
935
- }
936
- ]
937
- };
938
- // Clear previous animation, if any
939
- this._lottieInstance?.destroy();
940
- this.playerState = PlayerState.Stopped;
941
- if (!this.animateOnScroll && // !this.playOnVisible &&
942
- (this.autoplay || this._multiAnimationSettings[this._currentAnimation]?.autoplay || this.playOnVisible)) {
943
- this.playerState = PlayerState.Playing;
944
- }
945
- // Initialize lottie player and load animation
946
- this._lottieInstance = this.loadAnimation({
947
- ...this._getOptions(),
948
- animationData: animations[this._currentAnimation]
949
- });
950
- this._addEventListeners();
951
- const speed = this._multiAnimationSettings[this._currentAnimation]?.speed ?? this.speed, direction = this._multiAnimationSettings[this._currentAnimation]?.direction ?? this.direction;
952
- // Set initial playback speed and direction
953
- this._lottieInstance.setSpeed(speed);
954
- this._lottieInstance.setDirection(direction);
955
- this._lottieInstance.setSubframe(Boolean(this.subframe));
956
- // Start playing if autoplay is enabled
957
- if ((this.autoplay || this.animateOnScroll || this.playOnVisible) && this.direction === -1) {
958
- this.seek('99%');
959
- // if (!('IntersectionObserver' in window)) {
960
- // if (!this.animateOnScroll) {
961
- // this.play()
962
- // }
963
- // this._playerState.visible = true
964
- // }
965
- // this._addIntersectionObserver()
966
- }
967
- this._renderControls();
968
- if (this.autoplay || this.playOnVisible) {
969
- const togglePlay = this.shadow?.querySelector('.togglePlay');
970
- if (togglePlay) {
971
- togglePlay.innerHTML = pauseIcon;
972
- }
973
- }
974
- } catch (error) {
975
- console.error(error);
976
- this._errorMessage = handleErrors(error).message;
977
- this.playerState = PlayerState.Error;
978
- this.dispatchEvent(new CustomEvent(PlayerEvents.Error));
979
- }
980
- }
981
- loadAnimation(_config) {
982
- throw new Error(notImplemented);
983
- }
984
- /**
985
- * Skip to next animation.
986
- */ next() {
987
- this._currentAnimation++;
988
- this._switchInstance();
989
- }
990
- /**
991
- * Pause.
992
- */ pause() {
993
- if (!this._lottieInstance) {
994
- return;
995
- }
996
- this._playerState.prev = this.playerState;
997
- let hasError = false;
998
- try {
999
- this._lottieInstance.pause();
1000
- this.dispatchEvent(new CustomEvent(PlayerEvents.Pause));
1001
- } catch (error) {
1002
- hasError = true;
1003
- console.error(error);
1004
- } finally{
1005
- this.playerState = hasError ? PlayerState.Error : PlayerState.Paused;
1006
- }
1007
- }
1008
- /**
1009
- * Play.
1010
- */ play() {
1011
- if (!this._lottieInstance) {
1012
- return;
1013
- }
1014
- this._playerState.prev = this.playerState;
1015
- let hasError = false;
1016
- try {
1017
- this._lottieInstance.play();
1018
- this.dispatchEvent(new CustomEvent(PlayerEvents.Play));
1019
- } catch (error) {
1020
- hasError = true;
1021
- console.error(error);
1022
- } finally{
1023
- this.playerState = hasError ? PlayerState.Error : PlayerState.Playing;
1024
- }
1025
- }
1026
- /**
1027
- * Skip to previous animation.
1028
- */ prev() {
1029
- this._currentAnimation--;
1030
- this._switchInstance(true);
1031
- }
1032
- /**
1033
- * Name: string, oldValue: string, newValue: string.
1034
- */ propertyChangedCallback(name, _oldValue, value) {
1035
- if (!this.shadow) {
1036
- return;
1037
- }
1038
- 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');
1039
- if (!(togglePlay instanceof HTMLButtonElement) || !(stopButton instanceof HTMLButtonElement) || !(nextButton instanceof HTMLButtonElement) || !(prevButton instanceof HTMLButtonElement) || !(seeker instanceof HTMLInputElement) || !(progress instanceof HTMLProgressElement)) {
1040
- return;
1041
- }
1042
- if (name === 'playerState') {
1043
- togglePlay.dataset.active = (value === PlayerState.Playing || value === PlayerState.Paused).toString();
1044
- stopButton.dataset.active = (value === PlayerState.Stopped).toString();
1045
- if (value === PlayerState.Playing) {
1046
- togglePlay.innerHTML = pauseIcon;
1047
- } else {
1048
- togglePlay.innerHTML = playIcon;
1049
- }
1050
- }
1051
- if (name === '_seeker' && typeof value === 'number') {
1052
- seeker.value = value.toString();
1053
- seeker.ariaValueNow = value.toString();
1054
- progress.value = value;
1055
- }
1056
- if (name === '_animations' && Array.isArray(value) && this._currentAnimation + 1 < value.length) {
1057
- nextButton.hidden = false;
1058
- }
1059
- if (name === '_currentAnimation' && typeof value === 'number') {
1060
- nextButton.hidden = value + 1 >= this._animations.length;
1061
- prevButton.hidden = !value;
1062
- }
1063
- if (name === '_isSettingsOpen' && typeof value === 'boolean' && popover instanceof HTMLDivElement && convertButton instanceof HTMLButtonElement && snapshot instanceof HTMLButtonElement) {
1064
- popover.hidden = !value;
1065
- convertButton.hidden = this.isLight;
1066
- snapshot.hidden = this.renderer !== RendererType.SVG;
1067
- }
1068
- }
1069
- /**
1070
- * Reload animation.
1071
- */ async reload() {
1072
- if (!this._lottieInstance || !this.src) {
1073
- return;
1074
- }
1075
- this._lottieInstance.destroy();
1076
- await this.load(this.src);
1077
- }
1078
- /**
1079
- * Seek to a given frame.
1080
- *
1081
- * @param value - Frame to seek to.
1082
- */ seek(value) {
1083
- if (!this._lottieInstance) {
1084
- return;
1085
- }
1086
- // Extract frame number from either number or percentage value
1087
- const matches = value.toString().match(/^(\d+)(%?)$/);
1088
- if (!matches) {
1089
- return;
1090
- }
1091
- // Calculate and set the frame number
1092
- const frame = Math.round(matches[2] === '%' ? this._lottieInstance.totalFrames * Number(matches[1]) / 100 : Number(matches[1]));
1093
- // Set seeker to new frame number
1094
- this._seeker = frame;
1095
- // Send lottie player to the new frame
1096
- if (this.playerState === PlayerState.Playing || this.playerState === PlayerState.Frozen && this._playerState.prev === PlayerState.Playing) {
1097
- this._lottieInstance.goToAndPlay(frame, true);
1098
- this.playerState = PlayerState.Playing;
1099
- return;
1100
- }
1101
- this._lottieInstance.goToAndStop(frame, true);
1102
- this._lottieInstance.pause();
1103
- }
1104
- /**
1105
- * Dynamically set count for loops.
1106
- */ setCount(value) {
1107
- this.count = value;
1108
- }
1109
- /**
1110
- * Animation play direction.
1111
- *
1112
- * @param value - Animation direction.
1113
- */ setDirection(value) {
1114
- if (!this._lottieInstance) {
1115
- return;
1116
- }
1117
- this._lottieInstance.setDirection(value);
1118
- }
1119
- /**
1120
- * Set loop.
1121
- *
1122
- */ setLoop(value) {
1123
- if (!this._lottieInstance) {
1124
- return;
1125
- }
1126
- this._lottieInstance.setLoop(value);
1127
- }
1128
- /**
1129
- * Set Multi-animation settings.
1130
- */ setMultiAnimationSettings(settings) {
1131
- this._multiAnimationSettings = settings;
1132
- }
1133
- /**
1134
- * Set playback segment.
1135
- */ setSegment(segment) {
1136
- this._segment = segment;
1137
- }
1138
- /**
1139
- * Set animation playback speed.
1140
- *
1141
- * @param value - Playback speed.
1142
- */ setSpeed(value = 1) {
1143
- if (!this._lottieInstance) {
1144
- return;
1145
- }
1146
- this._lottieInstance.setSpeed(value);
1147
- }
1148
- /**
1149
- * Toggles subframe, for more smooth animations.
1150
- *
1151
- * @param value - Whether animation uses subframe.
1152
- */ setSubframe(value) {
1153
- if (!this._lottieInstance) {
1154
- return;
1155
- }
1156
- this._lottieInstance.setSubframe(value);
1157
- }
1158
- /**
1159
- * Snapshot and download the current frame as SVG.
1160
- */ snapshot(shouldDownload = true, name = 'AM Lottie') {
1161
- try {
1162
- if (!this.shadowRoot) {
1163
- throw new Error('Unknown error');
1164
- }
1165
- // Get SVG element and serialize markup
1166
- const svgElement = this.shadowRoot.querySelector('.animation svg');
1167
- if (!svgElement) {
1168
- throw new Error('Could not retrieve animation from DOM');
1169
- }
1170
- const data = svgElement instanceof Node ? new XMLSerializer().serializeToString(svgElement) : null;
1171
- if (!data) {
1172
- throw new Error('Could not serialize SVG element');
1173
- }
1174
- if (shouldDownload) {
1175
- download(data, {
1176
- mimeType: 'image/svg+xml',
1177
- name: `${getFilename(this.src || name)}-${frameOutput(this._seeker)}.svg`
1178
- });
1179
- }
1180
- return data;
1181
- } catch (error) {
1182
- console.error(error);
1183
- return null;
1184
- }
1185
- }
1186
- /**
1187
- * Stop.
1188
- */ stop() {
1189
- if (!this._lottieInstance) {
1190
- return;
1191
- }
1192
- this._playerState.prev = this.playerState;
1193
- this._playerState.count = 0;
1194
- try {
1195
- this._lottieInstance.stop();
1196
- this.dispatchEvent(new CustomEvent(PlayerEvents.Stop));
1197
- } finally{
1198
- this.playerState = PlayerState.Stopped;
1199
- }
1200
- }
1201
- /**
1202
- * Toggle Boomerang.
1203
- */ toggleBoomerang() {
1204
- const curr = this._multiAnimationSettings[this._currentAnimation] ?? {};
1205
- if (curr.mode !== undefined) {
1206
- if (curr.mode === PlayMode.Normal) {
1207
- curr.mode = PlayMode.Bounce;
1208
- this._isBounce = true;
1209
- return;
1210
- }
1211
- curr.mode = PlayMode.Normal;
1212
- this._isBounce = false;
1213
- return;
1214
- }
1215
- if (this.mode === PlayMode.Normal) {
1216
- this.mode = PlayMode.Bounce;
1217
- this._isBounce = true;
1218
- return;
1219
- }
1220
- this.mode = PlayMode.Normal;
1221
- this._isBounce = false;
1222
- }
1223
- /**
1224
- * Toggle loop.
1225
- */ toggleLoop() {
1226
- const hasLoop = !this.loop;
1227
- this.loop = hasLoop;
1228
- this.setLoop(hasLoop);
1229
- }
1230
- /**
1231
- * Toggle playing state.
1232
- */ togglePlay() {
1233
- if (!this._lottieInstance) {
1234
- return;
1235
- }
1236
- const { currentFrame, playDirection, totalFrames } = this._lottieInstance;
1237
- if (this.playerState === PlayerState.Playing) {
1238
- this.pause();
1239
- return;
1240
- }
1241
- if (this.playerState !== PlayerState.Completed) {
1242
- this.play();
1243
- return;
1244
- }
1245
- this.playerState = PlayerState.Playing;
1246
- if (this._isBounce) {
1247
- this.setDirection(playDirection * -1);
1248
- this._lottieInstance.goToAndPlay(currentFrame, true);
1249
- return;
1250
- }
1251
- if (playDirection === -1) {
1252
- this._lottieInstance.goToAndPlay(totalFrames, true);
1253
- return;
1254
- }
1255
- this._lottieInstance.goToAndPlay(0, true);
1256
- }
1257
- /**
1258
- * Freeze animation.
1259
- * This internal state pauses animation and is used to differentiate between
1260
- * user requested pauses and component instigated pauses.
1261
- */ _freeze() {
1262
- if (!this._lottieInstance) {
1263
- return;
1264
- }
1265
- this._playerState.prev = this.playerState;
1266
- try {
1267
- this._lottieInstance.pause();
1268
- this.dispatchEvent(new CustomEvent(PlayerEvents.Freeze));
1269
- } finally{
1270
- this.playerState = PlayerState.Frozen;
1271
- }
1272
- }
1273
- /**
1274
- * Handle blur.
1275
- */ _handleBlur() {
1276
- setTimeout(()=>{
1277
- this._toggleSettings(false);
1278
- }, 200);
1279
- }
1280
- /**
1281
- * Handle click.
1282
- */ _handleClick() {
1283
- if (!this.playOnClick && !this.selector) {
1284
- return;
1285
- }
1286
- this.togglePlay();
1287
- }
1288
- /**
1289
- * Handles click and drag actions on the progress track.
1290
- */ _handleSeekChange({ target }) {
1291
- if (!(target instanceof HTMLInputElement) || !this._lottieInstance || isNaN(Number(target.value))) {
1292
- return;
1293
- }
1294
- this.seek(Math.round(Number(target.value) / 100 * this._lottieInstance.totalFrames));
1295
- }
1296
- /**
1297
- * Handle settings click event.
1298
- */ _handleSettingsClick({ target }) {
1299
- this._toggleSettings();
1300
- // Because Safari does not add focus on click, we need to add it manually, so the onblur event will fire
1301
- if (target instanceof HTMLElement) {
1302
- target.focus();
1303
- }
1304
- }
1305
- setOptions(_options) {
1306
- throw new Error('Method not implemented');
1307
- }
1308
- /**
1309
- * Add event listeners.
1310
- */ _addEventListeners() {
1311
- this._toggleEventListeners('add');
1312
- }
1313
- /**
1314
- * Add IntersectionObserver.
1315
- */ _addIntersectionObserver() {
1316
- if (!this._container || this._intersectionObserver) {
1317
- return;
1318
- }
1319
- if (!('IntersectionObserver' in window)) {
1320
- this._intersectionObserverFallback();
1321
- removeEventListener('scroll', this._intersectionObserverFallback, true);
1322
- addEventListener('scroll', this._intersectionObserverFallback, {
1323
- capture: true,
1324
- passive: true
1325
- });
1326
- return;
1327
- }
1328
- this._intersectionObserver = new IntersectionObserver((entries)=>{
1329
- const { length } = entries;
1330
- for(let i = 0; i < length; i++){
1331
- if (!entries[i]?.isIntersecting || document.hidden) {
1332
- if (this.playerState === PlayerState.Playing) {
1333
- this._freeze();
1334
- }
1335
- this._playerState.visible = false;
1336
- continue;
1337
- }
1338
- if (!this.animateOnScroll && !this.playOnVisible && this.playerState === PlayerState.Frozen) {
1339
- this.play();
1340
- }
1341
- if (this.playOnVisible) {
1342
- if (this.playerState === PlayerState.Completed && !this.once) {
1343
- this.playerState = PlayerState.Playing;
1344
- this._lottieInstance?.goToAndPlay(this.direction === 1 ? 0 : this._lottieInstance.totalFrames);
1345
- } else {
1346
- setTimeout(()=>{
1347
- this.play();
1348
- }, this.delay);
1349
- }
1350
- }
1351
- /**
1352
- * If the player is a ways down the page, we need to account for this by
1353
- * setting _playerState.scrollY to the current scroll position. However, we
1354
- * also need to check that the player hasn't been scrolled past, so we check
1355
- * boundingClientRect as well.
1356
- */ if (!this._playerState.scrollY && (entries[i]?.boundingClientRect.y || 0) > 0) {
1357
- this._playerState.scrollY = scrollY;
1358
- }
1359
- this._playerState.visible = true;
1360
- }
1361
- });
1362
- this._intersectionObserver.observe(this._container);
1363
- }
1364
- _complete() {
1365
- if (!this._lottieInstance) {
1366
- return;
1367
- }
1368
- if (this._animations.length > 1) {
1369
- if (this._multiAnimationSettings[this._currentAnimation + 1]?.autoplay) {
1370
- this.next();
1371
- return;
1372
- }
1373
- if (this.loop && this._currentAnimation === this._animations.length - 1) {
1374
- this._currentAnimation = 0;
1375
- this._switchInstance();
1376
- return;
1377
- }
1378
- }
1379
- const { currentFrame, totalFrames } = this._lottieInstance;
1380
- this._seeker = Math.round(currentFrame / totalFrames * 100);
1381
- this.playerState = PlayerState.Completed;
1382
- this.dispatchEvent(new CustomEvent(PlayerEvents.Complete, {
1383
- detail: {
1384
- frame: currentFrame,
1385
- seeker: this._seeker
1386
- }
1387
- }));
1388
- }
1389
- _dataFailed() {
1390
- this.playerState = PlayerState.Error;
1391
- this.dispatchEvent(new CustomEvent(PlayerEvents.Error));
1392
- }
1393
- _dataReady() {
1394
- this.dispatchEvent(new CustomEvent(PlayerEvents.Load));
1395
- }
1396
- _DOMLoaded() {
1397
- this._playerState.loaded = true;
1398
- this.dispatchEvent(new CustomEvent(PlayerEvents.Ready));
1399
- }
1400
- _enterFrame() {
1401
- if (!this._lottieInstance) {
1402
- return;
1403
- }
1404
- const { currentFrame, totalFrames } = this._lottieInstance;
1405
- this._seeker = Math.round(currentFrame / totalFrames * 100);
1406
- this.dispatchEvent(new CustomEvent(PlayerEvents.Frame, {
1407
- detail: {
1408
- frame: currentFrame,
1409
- seeker: this._seeker
1410
- }
1411
- }));
1412
- }
1413
- /**
1414
- * Get options from props.
1415
- */ _getOptions() {
1416
- if (!this._container) {
1417
- throw new Error('Container not rendered');
1418
- }
1419
- const preserveAspectRatio = this.preserveAspectRatio ?? aspectRatio(this.objectfit), currentAnimationSettings = this._multiAnimationSettings.length > 0 ? this._multiAnimationSettings[this._currentAnimation] : undefined, currentAnimationManifest = this._manifest?.animations[this._currentAnimation];
1420
- // Loop
1421
- let hasLoop = Boolean(this.loop);
1422
- if (currentAnimationManifest?.loop !== undefined) {
1423
- hasLoop = Boolean(currentAnimationManifest.loop);
1424
- }
1425
- if (currentAnimationSettings?.loop !== undefined) {
1426
- hasLoop = Boolean(currentAnimationSettings.loop);
1427
- }
1428
- // Autoplay
1429
- let hasAutoplay = Boolean(this.autoplay);
1430
- if (currentAnimationManifest?.autoplay !== undefined) {
1431
- hasAutoplay = Boolean(currentAnimationManifest.autoplay);
1432
- }
1433
- if (currentAnimationSettings?.autoplay !== undefined) {
1434
- hasAutoplay = Boolean(currentAnimationSettings.autoplay);
1435
- }
1436
- if (this.animateOnScroll) {
1437
- hasAutoplay = false;
1438
- }
1439
- // Segment
1440
- let initialSegment = this._segment;
1441
- if (this._segment?.every((val)=>val > 0)) {
1442
- initialSegment = [
1443
- this._segment[0] - 1,
1444
- this._segment[1] - 1
1445
- ];
1446
- }
1447
- if (this._segment?.some((val)=>val < 0)) {
1448
- initialSegment = undefined;
1449
- }
1450
- return this.setOptions({
1451
- container: this._container,
1452
- hasAutoplay,
1453
- hasLoop,
1454
- initialSegment,
1455
- preserveAspectRatio,
1456
- rendererType: this.renderer
1457
- });
1458
- }
1459
- /**
1460
- * Handle scroll.
1461
- */ _handleScroll() {
1462
- if (!this.animateOnScroll || !this._DOMRect || !this._lottieInstance) {
1463
- return;
1464
- }
1465
- if (isServer) {
1466
- console.warn('DotLottie: Scroll animations might not work properly in a Server Side Rendering context. Try to wrap this in a client component.');
1467
- return;
1468
- }
1469
- if (!this._playerState.visible) {
1470
- return;
1471
- }
1472
- if (this._playerState.scrollTimeout) {
1473
- clearTimeout(this._playerState.scrollTimeout);
1474
- }
1475
- this._playerState.scrollTimeout = setTimeout(()=>{
1476
- this.playerState = PlayerState.Paused;
1477
- }, 400);
1478
- const { totalFrames } = this._lottieInstance;
1479
- let scrollPosition = scrollY - this._playerState.scrollY;
1480
- if (scrollY <= this._playerState.scrollY) {
1481
- scrollPosition = this._playerState.scrollY - scrollY;
1482
- }
1483
- const { bottom, height, top } = this._DOMRect;
1484
- let offset = height - bottom;
1485
- if (top >= innerHeight) {
1486
- offset = height;
1487
- }
1488
- const scrollProgress = scrollPosition / (innerHeight + offset), currentFrame = clamp(scrollProgress * (totalFrames - 1), 0, totalFrames);
1489
- requestAnimationFrame(()=>{
1490
- if (currentFrame >= totalFrames) {
1491
- this.playerState = PlayerState.Paused;
1492
- return;
1493
- }
1494
- this.playerState = PlayerState.Playing;
1495
- this._lottieInstance?.goToAndStop(currentFrame, true);
1496
- });
1497
- }
1498
- _handleWindowBlur({ type }) {
1499
- if (this.dontFreezeOnBlur) {
1500
- return;
1501
- }
1502
- if (this.playerState === PlayerState.Playing && type === 'blur') {
1503
- this._freeze();
1504
- }
1505
- if (this.playerState === PlayerState.Frozen && type === 'focus') {
1506
- this.play();
1507
- }
1508
- }
1509
- _intersectionObserverFallback() {
1510
- if (!this._container) {
1511
- return;
1512
- }
1513
- const { bottom, left, right, top } = this._container.getBoundingClientRect();
1514
- this._playerState.visible = top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
1515
- if (this.autoplay || this.playOnVisible || this.playerState === PlayerState.Playing || this.playerState === PlayerState.Frozen) {
1516
- if (this._playerState.visible) {
1517
- this.play();
1518
- } else {
1519
- this._freeze();
1520
- }
1521
- }
1522
- }
1523
- _loopComplete() {
1524
- if (!this._lottieInstance) {
1525
- return;
1526
- }
1527
- const { playDirection, // firstFrame,
1528
- totalFrames } = this._lottieInstance, inPoint = this._segment ? this._segment[0] : 0, outPoint = this._segment ? this._segment[0] : totalFrames;
1529
- if (this.count) {
1530
- if (this._isBounce) {
1531
- this._playerState.count += 0.5;
1532
- } else {
1533
- this._playerState.count += 1;
1534
- }
1535
- if (this._playerState.count >= this.count) {
1536
- this.setLoop(false);
1537
- this.playerState = PlayerState.Completed;
1538
- this.dispatchEvent(new CustomEvent(PlayerEvents.Complete));
1539
- return;
1540
- }
1541
- }
1542
- this.dispatchEvent(new CustomEvent(PlayerEvents.Loop));
1543
- if (this._isBounce) {
1544
- this._lottieInstance.goToAndStop(playDirection === -1 ? inPoint : outPoint * 0.99, true);
1545
- this._lottieInstance.setDirection(playDirection * -1);
1546
- return setTimeout(()=>{
1547
- if (!this.animateOnScroll) {
1548
- this._lottieInstance?.play();
1549
- }
1550
- }, this.intermission);
1551
- }
1552
- this._lottieInstance.goToAndStop(playDirection === -1 ? outPoint * 0.99 : inPoint, true);
1553
- return setTimeout(()=>{
1554
- if (!this.animateOnScroll) {
1555
- this._lottieInstance?.play();
1556
- }
1557
- }, this.intermission);
1558
- }
1559
- /**
1560
- * Handle MouseEnter.
1561
- */ _mouseEnter() {
1562
- if (!this.hover || !this._lottieInstance || isTouch()) {
1563
- return;
1564
- }
1565
- if (this.mouseout === MouseOut.Reverse) {
1566
- this._lottieInstance.setDirection(1);
1567
- }
1568
- if (this.playerState === PlayerState.Completed) {
1569
- this._lottieInstance.goToAndPlay(0, true);
1570
- this.playerState = PlayerState.Playing;
1571
- return;
1572
- }
1573
- if (this.playerState !== PlayerState.Playing) {
1574
- this.play();
1575
- }
1576
- }
1577
- /**
1578
- * Handle MouseLeave.
1579
- */ _mouseLeave() {
1580
- if (!this.hover || !this._lottieInstance || isTouch()) {
1581
- return;
1582
- }
1583
- switch(this.mouseout){
1584
- case MouseOut.Void:
1585
- {
1586
- break;
1587
- }
1588
- case MouseOut.Pause:
1589
- {
1590
- this.pause();
1591
- break;
1592
- }
1593
- case MouseOut.Reverse:
1594
- {
1595
- // const { direction = 1 } =
1596
- // this._multiAnimationSettings.length > 0 ?
1597
- // this._multiAnimationSettings[this._currentAnimation + 1] ?? { direction: 1 } : this,
1598
- // newDirection = direction * -1 as AnimationDirection
1599
- this._lottieInstance.setDirection(-1);
1600
- this.play();
1601
- break;
1602
- }
1603
- default:
1604
- {
1605
- this.stop();
1606
- }
1607
- }
1608
- }
1609
- /**
1610
- * Handle visibility change events.
1611
- */ _onVisibilityChange() {
1612
- if (document.hidden && this.playerState === PlayerState.Playing) {
1613
- this._freeze();
1614
- return;
1615
- }
1616
- if (this.playerState === PlayerState.Frozen) {
1617
- this.play();
1618
- }
1619
- }
1620
- /**
1621
- * Remove event listeners.
1622
- */ _removeEventListeners() {
1623
- this._toggleEventListeners('remove');
1624
- }
1625
- _switchInstance(isPrevious = false) {
1626
- // Bail early if there is not animation to play
1627
- if (!this._animations[this._currentAnimation]) {
1628
- return;
1629
- }
1630
- try {
1631
- // Clear previous animation
1632
- if (this._lottieInstance) {
1633
- this._lottieInstance.destroy();
1634
- }
1635
- // Re-initialize lottie player
1636
- this._lottieInstance = this.loadAnimation({
1637
- ...this._getOptions(),
1638
- animationData: this._animations[this._currentAnimation]
1639
- });
1640
- // Check play mode for current animation
1641
- if (this._multiAnimationSettings[this._currentAnimation]?.mode) {
1642
- this._isBounce = this._multiAnimationSettings[this._currentAnimation]?.mode === PlayMode.Bounce;
1643
- }
1644
- // Remove event listeners to new Lottie instance, and add new
1645
- this._removeEventListeners();
1646
- this._addEventListeners();
1647
- this.dispatchEvent(new CustomEvent(isPrevious ? PlayerEvents.Previous : PlayerEvents.Next));
1648
- if (this._multiAnimationSettings[this._currentAnimation]?.autoplay ?? this.autoplay) {
1649
- if (this.animateOnScroll) {
1650
- this._lottieInstance.goToAndStop(0, true);
1651
- this.playerState = PlayerState.Paused;
1652
- return;
1653
- }
1654
- this._lottieInstance.goToAndPlay(0, true);
1655
- this.playerState = PlayerState.Playing;
1656
- return;
1657
- }
1658
- this._lottieInstance.goToAndStop(0, true);
1659
- this.playerState = PlayerState.Stopped;
1660
- } catch (error) {
1661
- this._errorMessage = handleErrors(error).message;
1662
- this.playerState = PlayerState.Error;
1663
- this.dispatchEvent(new CustomEvent(PlayerEvents.Error));
1664
- }
1665
- }
1666
- /**
1667
- * Toggle event listeners.
1668
- */ _toggleEventListeners(action) {
1669
- const method = action === 'add' ? 'addEventListener' : 'removeEventListener';
1670
- if (this._lottieInstance) {
1671
- this._lottieInstance[method]('enterFrame', this._enterFrame);
1672
- this._lottieInstance[method]('complete', this._complete);
1673
- this._lottieInstance[method]('loopComplete', this._loopComplete);
1674
- this._lottieInstance[method]('DOMLoaded', this._DOMLoaded);
1675
- this._lottieInstance[method]('data_ready', this._dataReady);
1676
- this._lottieInstance[method]('data_failed', this._dataFailed);
1677
- }
1678
- if (this.selector) {
1679
- const selector = document.getElementById(this.selector);
1680
- if (selector) {
1681
- if (this.hover) {
1682
- selector[method]('mouseenter', this._mouseEnter);
1683
- selector[method]('mouseleave', this._mouseLeave);
1684
- } else {
1685
- selector[method]('click', this._handleClick);
1686
- }
1687
- } else {
1688
- this.selector = null;
1689
- }
1690
- }
1691
- if (this._container && !this.selector) {
1692
- if (this.hover) {
1693
- this._container[method]('mouseenter', this._mouseEnter);
1694
- this._container[method]('mouseleave', this._mouseLeave);
1695
- }
1696
- if (this.playOnClick) {
1697
- this._container[method]('click', this._handleClick);
1698
- }
1699
- }
1700
- window[method]('focus', this._handleWindowBlur, {
1701
- capture: false,
1702
- passive: true
1703
- });
1704
- window[method]('blur', this._handleWindowBlur, {
1705
- capture: false,
1706
- passive: true
1707
- });
1708
- if (this.animateOnScroll) {
1709
- window[method]('scroll', this._handleScroll, {
1710
- capture: true,
1711
- passive: true
1712
- });
1713
- }
1714
- }
1715
- /**
1716
- * Toggle show Settings.
1717
- */ _toggleSettings(flag) {
1718
- if (flag === undefined) {
1719
- this._isSettingsOpen = !this._isSettingsOpen;
1720
- return;
1721
- }
1722
- this._isSettingsOpen = flag;
1723
- }
1724
- }
4
+ import { D as DotLottiePlayerBase, t as tagName } from './chunks/DotLottiePlayerBase-B6CMicGB.js';
5
+ export { M as MouseOut, P as PlayerState } from './chunks/DotLottiePlayerBase-B6CMicGB.js';
6
+ import '@aarsteinmedia/lottie-web/dotlottie';
1725
7
 
1726
8
  /**
1727
9
  * DotLottie Player Web Component.
@@ -1761,4 +43,4 @@ if (!isServer) {
1761
43
  customElements.define(tagName, DotLottiePlayerLight);
1762
44
  }
1763
45
 
1764
- export { MouseOut, PlayerState, DotLottiePlayerLight as default, tagName };
46
+ export { DotLottiePlayerLight as default, tagName };