@aarsteinmedia/dotlottie-player 2.5.8 → 2.5.10
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/cjs/index.js +165 -55
- package/dist/esm/index.js +165 -55
- package/dist/index.js +2 -2
- package/package.json +17 -14
package/dist/esm/index.js
CHANGED
|
@@ -3,6 +3,8 @@ import { property, query, state, customElement } from 'lit/decorators.js';
|
|
|
3
3
|
import Lottie from 'lottie-web';
|
|
4
4
|
import { strToU8, zip, strFromU8, unzip as unzip$1 } from 'fflate';
|
|
5
5
|
|
|
6
|
+
var name="@aarsteinmedia/dotlottie-player";var version="2.5.10";var description="Web Component for playing Lottie animations in your web app. Previously @johanaarstein/dotlottie-player";var exports={".":{"import":"./dist/esm/index.js",node:"./dist/esm/index.js",require:"./dist/cjs/index.js",types:"./dist/index.d.ts"}};var main="./dist/esm/index.js";var unpkg="./dist/index.js";var module="./dist/esm/index.js";var types="./dist/index.d.ts";var type="module";var homepage="https://www.aarstein.media/en/dotlottie-player";var repository={url:"https://github.com/aarsteinmedia/dotlottie-player.git",type:"git"};var bugs="https://github.com/aarsteinmedia/dotlottie-player/issues";var author={name:"Johan Martin Aarstein",email:"johan@aarstein.media",url:"https://www.aarstein.media",organization:"Aarstein Media"};var license="GPL-2.0-or-later";var scripts={build:"rimraf ./dist && rollup -c","build:types":"rimraf ./types && tsc","build:cem":"npx cem analyze --config cem.config.mjs",prod:"pnpm build:types && pnpm build && pnpm build:cem",dev:"rollup -c -w --environment NODE_ENV:development",lint:"tsc && eslint . --ext .ts","lint:fix":"eslint . --ext .ts --fix"};var dependencies={fflate:"^0.8.2",lit:"^3.1.3","lottie-web":"^5.12.2"};var peerDependencies={"@types/react":">= 16.0.0"};var devDependencies={"@custom-elements-manifest/analyzer":"^0.9.9","@rollup/plugin-commonjs":"^25.0.8","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^15.2.3","@rollup/plugin-replace":"^5.0.5","@swc/core":"^1.5.24","@types/node":"^20.14.1","@typescript-eslint/eslint-plugin":"^7.12.0","@typescript-eslint/parser":"^7.12.0",autoprefixer:"^10.4.19","esbuild-sass-plugin":"^3.3.0",eslint:"^8.57.0","eslint-import-resolver-typescript":"^3.6.1","eslint-plugin-import":"^2.29.1","eslint-plugin-jsdoc":"^48.2.7","eslint-plugin-lit":"^1.14.0","postcss-flexbugs-fixes":"^5.0.2",rimraf:"^5.0.7",rollup:"^4.18.0","rollup-plugin-dts":"^6.1.1","rollup-plugin-html-literals":"^1.1.8","rollup-plugin-livereload":"^2.0.5","rollup-plugin-postcss":"^4.0.2","rollup-plugin-postcss-lit":"^2.1.0","rollup-plugin-serve":"^1.1.1","rollup-plugin-summary":"^2.0.1","rollup-plugin-swc3":"^0.11.2",sass:"^1.77.4","ts-lit-plugin":"^2.0.2",typescript:"^5.4.5"};var customElements="dist/custom-elements.json";var files=["dist","README.md"];var keywords=["lottie","dotlottie","animation","web component","component","lit-element","svg","vector","player"];var publishConfig={access:"public"};var engines={node:">= 8.17.0"};var funding={type:"paypal",url:"https://www.paypal.com/donate/?hosted_button_id=E7C7DMN8KSQ6A"};var pkg = {name:name,version:version,description:description,exports:exports,main:main,unpkg:unpkg,module:module,types:types,type:type,homepage:homepage,repository:repository,bugs:bugs,author:author,license:license,scripts:scripts,dependencies:dependencies,peerDependencies:peerDependencies,devDependencies:devDependencies,customElements:customElements,files:files,keywords:keywords,publishConfig:publishConfig,engines:engines,funding:funding};
|
|
7
|
+
|
|
6
8
|
var PlayerState;
|
|
7
9
|
(function(PlayerState) {
|
|
8
10
|
PlayerState["Completed"] = "completed";
|
|
@@ -39,9 +41,13 @@ var PlayerEvents;
|
|
|
39
41
|
class CustomError extends Error {
|
|
40
42
|
}
|
|
41
43
|
const addExt = (ext, str)=>{
|
|
42
|
-
if (!str)
|
|
44
|
+
if (!str) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
43
47
|
if (getExt(str)) {
|
|
44
|
-
if (getExt(str) === ext)
|
|
48
|
+
if (getExt(str) === ext) {
|
|
49
|
+
return str;
|
|
50
|
+
}
|
|
45
51
|
return `${getFilename(str)}.${ext}`;
|
|
46
52
|
}
|
|
47
53
|
return `${str}.${ext}`;
|
|
@@ -62,7 +68,7 @@ const addExt = (ext, str)=>{
|
|
|
62
68
|
}, base64ToU8 = (str)=>strToU8(isServer() ? Buffer.from(parseBase64(str), 'base64').toString('binary') : atob(parseBase64(str)), true), createDotLottie = async ({ animations, manifest, fileName, shouldDownload = true })=>{
|
|
63
69
|
try {
|
|
64
70
|
if (!animations?.length || !manifest) {
|
|
65
|
-
throw new Error(`Missing or malformed required parameter(s):\n ${
|
|
71
|
+
throw new Error(`Missing or malformed required parameter(s):\n ${animations?.length ? '- manifest\n' : ''} ${manifest ? '- animations\n' : ''}`);
|
|
66
72
|
}
|
|
67
73
|
const name = addExt('lottie', fileName) || `${useId()}.lottie`, dotlottie = {
|
|
68
74
|
'manifest.json': [
|
|
@@ -163,7 +169,11 @@ const addExt = (ext, str)=>{
|
|
|
163
169
|
isDotLottie: false
|
|
164
170
|
};
|
|
165
171
|
}
|
|
166
|
-
const result = await fetch(input
|
|
172
|
+
const result = await fetch(input, {
|
|
173
|
+
headers: {
|
|
174
|
+
'Content-Type': 'application/json; charset=UTF-8'
|
|
175
|
+
}
|
|
176
|
+
});
|
|
167
177
|
if (!result.ok) {
|
|
168
178
|
const error = new CustomError(result.statusText);
|
|
169
179
|
error.status = result.status;
|
|
@@ -223,7 +233,9 @@ const addExt = (ext, str)=>{
|
|
|
223
233
|
});
|
|
224
234
|
return arrayBuffer;
|
|
225
235
|
}, getExt = (str)=>{
|
|
226
|
-
if (!str || !hasExt(str))
|
|
236
|
+
if (!str || !hasExt(str)) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
227
239
|
const ext = str.split('.').pop()?.toLowerCase();
|
|
228
240
|
if (ext === 'jpeg') {
|
|
229
241
|
return 'jpg';
|
|
@@ -252,8 +264,12 @@ const addExt = (ext, str)=>{
|
|
|
252
264
|
};
|
|
253
265
|
}, getManifest = (unzipped)=>{
|
|
254
266
|
const file = strFromU8(unzipped['manifest.json'], false), manifest = JSON.parse(file);
|
|
255
|
-
if (!('animations' in manifest))
|
|
256
|
-
|
|
267
|
+
if (!('animations' in manifest)) {
|
|
268
|
+
throw new Error('Manifest not found');
|
|
269
|
+
}
|
|
270
|
+
if (!manifest.animations.length) {
|
|
271
|
+
throw new Error('No animations listed in manifest');
|
|
272
|
+
}
|
|
257
273
|
return manifest;
|
|
258
274
|
}, getMimeFromExt = (ext)=>{
|
|
259
275
|
switch(ext){
|
|
@@ -292,21 +308,27 @@ const addExt = (ext, str)=>{
|
|
|
292
308
|
const lastDotIndex = path?.split('/').pop()?.lastIndexOf('.');
|
|
293
309
|
return (lastDotIndex ?? 0) > 1 && path && path.length - 1 > (lastDotIndex ?? 0);
|
|
294
310
|
}, isAudio = (asset)=>!('h' in asset) && !('w' in asset) && 'p' in asset && 'e' in asset && 'u' in asset && 'id' in asset, isBase64 = (str)=>{
|
|
295
|
-
if (!str)
|
|
311
|
+
if (!str) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
296
314
|
const regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
297
315
|
return regex.test(parseBase64(str));
|
|
298
|
-
}, isImage = (asset)=>'w' in asset && 'h' in asset && !('xt' in asset) && 'p' in asset, isServer = ()=>!(typeof window !== 'undefined' && window.document), parseBase64 = (str)=>str.substring(str.indexOf(',') + 1), prepareString = (str)=>{
|
|
299
|
-
return str.replace(new RegExp(/"""/, 'g'), '""').replace(/(["'])(.*?)\1/g, (_match, quote, content)=>{
|
|
316
|
+
}, isImage = (asset)=>'w' in asset && 'h' in asset && !('xt' in asset) && 'p' in asset, isServer = ()=>!(typeof window !== 'undefined' && window.document), parseBase64 = (str)=>str.substring(str.indexOf(',') + 1), prepareString = (str)=>str.replace(new RegExp(/"""/, 'g'), '""').replace(/(["'])(.*?)\1/g, (_match, quote, content)=>{
|
|
300
317
|
const replacedContent = content.replace(/[^\w\s\d.#]/g, '');
|
|
301
318
|
return `${quote}${replacedContent}${quote}`;
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
|
|
319
|
+
}), resolveAssets = async (unzipped, assets)=>{
|
|
320
|
+
if (!Array.isArray(assets)) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
305
323
|
const toResolve = [];
|
|
306
324
|
for (const asset of assets){
|
|
307
|
-
if (!isAudio(asset) && !isImage(asset))
|
|
325
|
+
if (!isAudio(asset) && !isImage(asset)) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
308
328
|
const type = isImage(asset) ? 'images' : 'audio', u8 = unzipped?.[`${type}/${asset.p}`];
|
|
309
|
-
if (!u8)
|
|
329
|
+
if (!u8) {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
310
332
|
toResolve.push(new Promise((resolveAsset)=>{
|
|
311
333
|
const assetB64 = isServer() ? Buffer.from(u8).toString('base64') : btoa(u8.reduce((dat, byte)=>`${dat}${String.fromCharCode(byte)}`, ''));
|
|
312
334
|
asset.p = asset.p?.startsWith('data:') || isBase64(asset.p) ? asset.p : `data:${getMimeFromExt(getExt(asset.p))};base64,${assetB64}`;
|
|
@@ -327,14 +349,10 @@ const addExt = (ext, str)=>{
|
|
|
327
349
|
});
|
|
328
350
|
return unzipped;
|
|
329
351
|
}, useId = (prefix)=>{
|
|
330
|
-
const s4 = ()=>
|
|
331
|
-
return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
|
|
332
|
-
};
|
|
352
|
+
const s4 = ()=>((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
|
|
333
353
|
return `${prefix ?? `:${s4()}`}-${s4()}`;
|
|
334
354
|
};
|
|
335
355
|
|
|
336
|
-
var name="@aarsteinmedia/dotlottie-player";var version="2.5.8";var description="Web Component for playing Lottie animations in your web app. Previously @johanaarstein/dotlottie-player";var exports={".":{"import":"./dist/esm/index.js",node:"./dist/esm/index.js",require:"./dist/cjs/index.js",types:"./dist/index.d.ts"}};var main="./dist/esm/index.js";var unpkg="./dist/index.js";var module="./dist/esm/index.js";var types="./dist/index.d.ts";var type="module";var homepage="https://www.aarstein.media/en/dotlottie-player";var repository={url:"https://github.com/aarsteinmedia/dotlottie-player.git",type:"git"};var bugs="https://github.com/aarsteinmedia/dotlottie-player/issues";var author={name:"Johan Martin Aarstein",email:"johan@aarstein.media",url:"https://www.aarstein.media",organization:"Aarstein Media"};var license="GPL-2.0-or-later";var scripts={build:"rimraf ./dist && rollup -c","build:types":"rimraf ./types && tsc","build:cem":"npx cem analyze --config cem.config.mjs",prod:"pnpm build:types && pnpm build && pnpm build:cem",dev:"rollup -c -w --environment NODE_ENV:development",lint:"tsc && eslint . --ext .ts","lint:fix":"eslint . --ext .ts --fix"};var dependencies={fflate:"^0.8.2",lit:"^3.1.3","lottie-web":"^5.12.2"};var peerDependencies={"@types/react":">= 16.0.0"};var devDependencies={"@custom-elements-manifest/analyzer":"^0.9.9","@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^15.2.3","@rollup/plugin-replace":"^5.0.5","@swc/core":"^1.5.5","@types/node":"^20.12.11","@typescript-eslint/eslint-plugin":"^7.8.0","@typescript-eslint/parser":"^7.8.0",autoprefixer:"^10.4.19","esbuild-sass-plugin":"^3.2.0",eslint:"^8.57.0","eslint-plugin-lit":"^1.12.0","postcss-flexbugs-fixes":"^5.0.2",rimraf:"^5.0.5",rollup:"^4.17.2","rollup-plugin-dts":"^6.1.0","rollup-plugin-html-literals":"^1.1.8","rollup-plugin-livereload":"^2.0.5","rollup-plugin-postcss":"^4.0.2","rollup-plugin-postcss-lit":"^2.1.0","rollup-plugin-serve":"^1.1.1","rollup-plugin-summary":"^2.0.0","rollup-plugin-swc3":"^0.11.1",sass:"^1.77.0","ts-lit-plugin":"^2.0.2",typescript:"^5.4.5"};var customElements="dist/custom-elements.json";var files=["dist","README.md"];var keywords=["lottie","dotlottie","animation","web component","component","lit-element","svg","vector","player"];var publishConfig={access:"public"};var engines={node:">= 8.17.0"};var funding={type:"paypal",url:"https://www.paypal.com/donate/?hosted_button_id=E7C7DMN8KSQ6A"};var pkg = {name:name,version:version,description:description,exports:exports,main:main,unpkg:unpkg,module:module,types:types,type:type,homepage:homepage,repository:repository,bugs:bugs,author:author,license:license,scripts:scripts,dependencies:dependencies,peerDependencies:peerDependencies,devDependencies:devDependencies,customElements:customElements,files:files,keywords:keywords,publishConfig:publishConfig,engines:engines,funding:funding};
|
|
337
|
-
|
|
338
356
|
var css_248z = css`*{box-sizing:border-box}:host{--lottie-player-toolbar-height:35px;--lottie-player-toolbar-background-color:#FFF;--lottie-player-toolbar-icon-color:#000;--lottie-player-toolbar-icon-hover-color:#000;--lottie-player-toolbar-icon-active-color:#4285f4;--lottie-player-seeker-track-color:rgba(0, 0, 0, 0.2);--lottie-player-seeker-thumb-color:#4285f4;--lottie-player-seeker-display:block;display:block;width:100%;height:100%}@media (prefers-color-scheme:dark){:host{--lottie-player-toolbar-background-color:#000;--lottie-player-toolbar-icon-color:#FFF;--lottie-player-toolbar-icon-hover-color:#FFF;--lottie-player-seeker-track-color:rgba(255, 255, 255, 0.6)}}.main{display:flex;flex-direction:column;height:100%;width:100%;margin:0;padding:0}.animation{width:100%;height:100%;display:flex}[data-controls=true] .animation{height:calc(100% - 35px)}.animation-container{position:relative}.popover{position:absolute;right:5px;bottom:40px;background-color:var(--lottie-player-toolbar-background-color);border-radius:5px;padding:10px 15px;border:solid 2px var(--lottie-player-toolbar-icon-color);animation:fadeIn .2s ease-in-out}.popover::before{content:"";right:10px;border:7px solid transparent;border-top-color:transparent;margin-right:-7px;height:0;width:0;position:absolute;pointer-events:none;top:100%;border-top-color:var(--lottie-player-toolbar-icon-color)}.toolbar{display:flex;align-items:center;justify-items:center;background:var(--lottie-player-toolbar-background-color);margin:0;height:35px;padding:5px;border-radius:5px;gap:5px}.toolbar.has-error{pointer-events:none;opacity:.5}.toolbar button{cursor:pointer;fill:var(--lottie-player-toolbar-icon-color);color:var(--lottie-player-toolbar-icon-color);display:flex;background:0 0;border:0;padding:0;outline:0;height:100%;margin:0;align-items:center;gap:5px;opacity:.9}.toolbar button:hover{opacity:1}.toolbar button[data-active=true]{opacity:1;fill:var(--lottie-player-toolbar-icon-active-color)}.toolbar button:disabled{opacity:.5}.toolbar button:focus{outline:0}.toolbar button svg{pointer-events:none}.toolbar button svg>*{fill:inherit}.toolbar button.disabled svg{display:none}.progress-container{position:relative;width:100%}.progress-container.simple{margin-right:12px}.seeker{-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:0}.seeker::-webkit-slider-runnable-track,.seeker::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;outline:0}progress{-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:0}.seeker{width:100%;height:20px;border-radius:3px;border:0;cursor:pointer;background-color:transparent;display:var(--lottie-player-seeker-display);color:var(--lottie-player-seeker-thumb-color);margin:0;padding:7.5px 0;position:relative;z-index:1}progress{position:absolute;width:100%;height:5px;border-radius:3px;border:0;top:0;left:0;margin:7.5px 0;background-color:var(--lottie-player-seeker-track-color);pointer-events:none}::-moz-progress-bar{background-color:var(--lottie-player-seeker-thumb-color)}::-webkit-progress-inner-element{border-radius:3px;overflow:hidden}::-webkit-slider-runnable-track{background-color:transparent}::-webkit-progress-value{background-color:var(--lottie-player-seeker-thumb-color)}.seeker::-webkit-slider-thumb{height:15px;width:15px;border-radius:50%;border:0;background-color:var(--lottie-player-seeker-thumb-color);cursor:pointer;-webkit-transition:transform .2s ease-in-out;transition:transform .2s ease-in-out;transform:scale(0)}.seeker:focus::-webkit-slider-thumb,.seeker:hover::-webkit-slider-thumb{transform:scale(1)}.seeker::-moz-range-progress{background-color:var(--lottie-player-seeker-thumb-color);height:5px;border-radius:3px}.seeker::-moz-range-thumb{height:15px;width:15px;border-radius:50%;background-color:var(--lottie-player-seeker-thumb-color);border:0;cursor:pointer;-moz-transition:transform .2s ease-in-out;transition:transform .2s ease-in-out;transform:scale(0)}.seeker:focus::-moz-range-thumb,.seeker:hover::-moz-range-thumb{transform:scale(1)}.seeker::-ms-track{width:100%;height:5px;cursor:pointer;background:0 0;border-color:transparent;color:transparent}.seeker::-ms-fill-upper{background:var(--lottie-player-seeker-track-color);border-radius:3px}.seeker::-ms-fill-lower{background-color:var(--lottie-player-seeker-thumb-color);border-radius:3px}.seeker::-ms-thumb{border:0;height:15px;width:15px;border-radius:50%;background:var(--lottie-player-seeker-thumb-color);cursor:pointer;-ms-transition:transform .2s ease-in-out;transition:transform .2s ease-in-out;transform:scale(0)}.seeker:hover::-ms-thumb{transform:scale(1)}.seeker:focus::-ms-thumb{transform:scale(1)}.seeker:focus::-ms-fill-lower,.seeker:focus::-ms-fill-upper{background:var(--lottie-player-seeker-track-color)}.error{display:flex;margin:auto;justify-content:center;height:100%;align-items:center}.error svg{width:100%;height:auto}@keyframes fadeIn{0%{opacity:0}100%{opacity:1}}`;
|
|
339
357
|
|
|
340
358
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -345,10 +363,35 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
345
363
|
}
|
|
346
364
|
class DotLottiePlayer extends LitElement {
|
|
347
365
|
_getOptions() {
|
|
348
|
-
const preserveAspectRatio = this.preserveAspectRatio ?? (this.objectfit && aspectRatio(this.objectfit)), currentAnimationSettings = this.multiAnimationSettings?.
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
366
|
+
const preserveAspectRatio = this.preserveAspectRatio ?? (this.objectfit && aspectRatio(this.objectfit)), currentAnimationSettings = this.multiAnimationSettings?.length ? this.multiAnimationSettings?.[this._currentAnimation] : undefined, currentAnimationManifest = this._manifest.animations?.[this._currentAnimation];
|
|
367
|
+
let loop = !!this.loop;
|
|
368
|
+
if (currentAnimationManifest.loop !== undefined) {
|
|
369
|
+
loop = !!currentAnimationManifest.loop;
|
|
370
|
+
}
|
|
371
|
+
if (currentAnimationSettings?.loop !== undefined) {
|
|
372
|
+
loop = !!currentAnimationSettings.loop;
|
|
373
|
+
}
|
|
374
|
+
let autoplay = !!this.autoplay;
|
|
375
|
+
if (currentAnimationManifest.autoplay !== undefined) {
|
|
376
|
+
autoplay = !!currentAnimationManifest.autoplay;
|
|
377
|
+
}
|
|
378
|
+
if (currentAnimationSettings?.autoplay !== undefined) {
|
|
379
|
+
autoplay = !!currentAnimationSettings.autoplay;
|
|
380
|
+
}
|
|
381
|
+
if (this.animateOnScroll) {
|
|
382
|
+
autoplay = false;
|
|
383
|
+
}
|
|
384
|
+
let initialSegment = this.segment;
|
|
385
|
+
if (this.segment?.every((val)=>val > 0)) {
|
|
386
|
+
initialSegment = [
|
|
387
|
+
this.segment[0] - 1,
|
|
388
|
+
this.segment[1] - 1
|
|
389
|
+
];
|
|
390
|
+
}
|
|
391
|
+
if (this.segment?.some((val)=>val < 0)) {
|
|
392
|
+
initialSegment = undefined;
|
|
393
|
+
}
|
|
394
|
+
const options = {
|
|
352
395
|
container: this.container,
|
|
353
396
|
loop,
|
|
354
397
|
autoplay,
|
|
@@ -408,13 +451,20 @@ class DotLottiePlayer extends LitElement {
|
|
|
408
451
|
this._intersectionObserver.observe(this.container);
|
|
409
452
|
}
|
|
410
453
|
async load(src) {
|
|
411
|
-
if (!this.shadowRoot)
|
|
454
|
+
if (!this.shadowRoot) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
412
457
|
try {
|
|
413
458
|
const { animations, manifest, isDotLottie } = await getAnimationData(src);
|
|
414
459
|
if (!animations || animations.some((animation)=>!this._isLottie(animation))) {
|
|
415
460
|
throw new Error('Broken or corrupted file');
|
|
416
461
|
}
|
|
417
|
-
this._isBounce = this.
|
|
462
|
+
this._isBounce = this.mode === PlayMode.Bounce;
|
|
463
|
+
if (this.multiAnimationSettings?.length) {
|
|
464
|
+
if (this.multiAnimationSettings[this._currentAnimation]?.mode) {
|
|
465
|
+
this._isBounce = this.multiAnimationSettings[this._currentAnimation].mode === PlayMode.Bounce;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
418
468
|
this._isDotLottie = !!isDotLottie;
|
|
419
469
|
this._animations = animations;
|
|
420
470
|
this._manifest = manifest ?? {
|
|
@@ -429,8 +479,13 @@ class DotLottiePlayer extends LitElement {
|
|
|
429
479
|
}
|
|
430
480
|
]
|
|
431
481
|
};
|
|
432
|
-
if (this._lottieInstance)
|
|
433
|
-
|
|
482
|
+
if (this._lottieInstance) {
|
|
483
|
+
this._lottieInstance.destroy();
|
|
484
|
+
}
|
|
485
|
+
this.currentState = PlayerState.Stopped;
|
|
486
|
+
if (!this.animateOnScroll && (this.autoplay || this.multiAnimationSettings?.[this._currentAnimation]?.autoplay)) {
|
|
487
|
+
this.currentState = PlayerState.Playing;
|
|
488
|
+
}
|
|
434
489
|
this._lottieInstance = Lottie.loadAnimation({
|
|
435
490
|
...this._getOptions(),
|
|
436
491
|
animationData: animations[this._currentAnimation]
|
|
@@ -447,20 +502,25 @@ class DotLottiePlayer extends LitElement {
|
|
|
447
502
|
this.setDirection(direction);
|
|
448
503
|
this.setSubframe(!!this.subframe);
|
|
449
504
|
if (this.autoplay || this.animateOnScroll) {
|
|
450
|
-
if (this.direction === -1)
|
|
505
|
+
if (this.direction === -1) {
|
|
506
|
+
this.seek('99%');
|
|
507
|
+
}
|
|
451
508
|
if (!('IntersectionObserver' in window)) {
|
|
452
|
-
!this.animateOnScroll
|
|
509
|
+
if (!this.animateOnScroll) {
|
|
510
|
+
this.play();
|
|
511
|
+
}
|
|
453
512
|
this._playerState.visible = true;
|
|
454
513
|
}
|
|
455
514
|
this._addIntersectionObserver();
|
|
456
|
-
return;
|
|
457
515
|
}
|
|
458
516
|
}
|
|
459
517
|
getManifest() {
|
|
460
518
|
return this._manifest;
|
|
461
519
|
}
|
|
462
520
|
_addEventListeners() {
|
|
463
|
-
if (!this._lottieInstance)
|
|
521
|
+
if (!this._lottieInstance) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
464
524
|
this._lottieInstance.addEventListener('enterFrame', this._enterFrame);
|
|
465
525
|
this._lottieInstance.addEventListener('complete', this._complete);
|
|
466
526
|
this._lottieInstance.addEventListener('loopComplete', this._loopComplete);
|
|
@@ -487,7 +547,9 @@ class DotLottiePlayer extends LitElement {
|
|
|
487
547
|
}
|
|
488
548
|
}
|
|
489
549
|
_removeEventListeners() {
|
|
490
|
-
if (!this._lottieInstance || !this.container)
|
|
550
|
+
if (!this._lottieInstance || !this.container) {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
491
553
|
this._lottieInstance.removeEventListener('enterFrame', this._enterFrame);
|
|
492
554
|
this._lottieInstance.removeEventListener('complete', this._complete);
|
|
493
555
|
this._lottieInstance.removeEventListener('loopComplete', this._loopComplete);
|
|
@@ -506,7 +568,11 @@ class DotLottiePlayer extends LitElement {
|
|
|
506
568
|
}
|
|
507
569
|
const { totalFrames, playDirection } = this._lottieInstance, inPoint = this.segment ? this.segment[0] : 0, outPoint = this.segment ? this.segment[0] : totalFrames;
|
|
508
570
|
if (this.count) {
|
|
509
|
-
this._isBounce
|
|
571
|
+
if (this._isBounce) {
|
|
572
|
+
this._playerState.count += 0.5;
|
|
573
|
+
} else {
|
|
574
|
+
this._playerState.count += 1;
|
|
575
|
+
}
|
|
510
576
|
if (this._playerState.count >= this.count) {
|
|
511
577
|
this.setLooping(false);
|
|
512
578
|
this.currentState = PlayerState.Completed;
|
|
@@ -519,12 +585,16 @@ class DotLottiePlayer extends LitElement {
|
|
|
519
585
|
this._lottieInstance.goToAndStop(playDirection === -1 ? inPoint : outPoint * 0.99, true);
|
|
520
586
|
this._lottieInstance.setDirection(playDirection * -1);
|
|
521
587
|
return setTimeout(()=>{
|
|
522
|
-
!this.animateOnScroll
|
|
588
|
+
if (!this.animateOnScroll) {
|
|
589
|
+
this._lottieInstance?.play();
|
|
590
|
+
}
|
|
523
591
|
}, this.intermission);
|
|
524
592
|
}
|
|
525
593
|
this._lottieInstance.goToAndStop(playDirection === -1 ? outPoint * 0.99 : inPoint, true);
|
|
526
594
|
return setTimeout(()=>{
|
|
527
|
-
!this.animateOnScroll
|
|
595
|
+
if (!this.animateOnScroll) {
|
|
596
|
+
this._lottieInstance?.play();
|
|
597
|
+
}
|
|
528
598
|
}, this.intermission);
|
|
529
599
|
}
|
|
530
600
|
_enterFrame() {
|
|
@@ -544,8 +614,14 @@ class DotLottiePlayer extends LitElement {
|
|
|
544
614
|
if (!this._lottieInstance) {
|
|
545
615
|
return;
|
|
546
616
|
}
|
|
547
|
-
if (this._animations.length > 1
|
|
548
|
-
|
|
617
|
+
if (this._animations.length > 1) {
|
|
618
|
+
if (this.multiAnimationSettings?.[this._currentAnimation + 1]?.autoplay) {
|
|
619
|
+
return this.next();
|
|
620
|
+
}
|
|
621
|
+
if (this.loop && this._currentAnimation === this._animations.length - 1) {
|
|
622
|
+
this._currentAnimation = 0;
|
|
623
|
+
return this._switchInstance();
|
|
624
|
+
}
|
|
549
625
|
}
|
|
550
626
|
const { currentFrame, totalFrames } = this._lottieInstance;
|
|
551
627
|
this._seeker = Math.floor(currentFrame / totalFrames * 100);
|
|
@@ -621,7 +697,9 @@ class DotLottiePlayer extends LitElement {
|
|
|
621
697
|
}, 400);
|
|
622
698
|
}
|
|
623
699
|
_handleSeekChange({ target }) {
|
|
624
|
-
if (!(target instanceof HTMLInputElement) || !this._lottieInstance || isNaN(Number(target.value)))
|
|
700
|
+
if (!(target instanceof HTMLInputElement) || !this._lottieInstance || isNaN(Number(target.value))) {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
625
703
|
this.seek(Math.floor(Number(target.value) / 100 * this._lottieInstance.totalFrames));
|
|
626
704
|
setTimeout(()=>{
|
|
627
705
|
if (target.parentElement instanceof HTMLFormElement) {
|
|
@@ -681,7 +759,9 @@ class DotLottiePlayer extends LitElement {
|
|
|
681
759
|
return this._lottieInstance;
|
|
682
760
|
}
|
|
683
761
|
play() {
|
|
684
|
-
if (!this._lottieInstance)
|
|
762
|
+
if (!this._lottieInstance) {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
685
765
|
if (this.currentState) {
|
|
686
766
|
this._playerState.prev = this.currentState;
|
|
687
767
|
}
|
|
@@ -692,7 +772,9 @@ class DotLottiePlayer extends LitElement {
|
|
|
692
772
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Play));
|
|
693
773
|
}
|
|
694
774
|
pause() {
|
|
695
|
-
if (!this._lottieInstance)
|
|
775
|
+
if (!this._lottieInstance) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
696
778
|
if (this.currentState) {
|
|
697
779
|
this._playerState.prev = this.currentState;
|
|
698
780
|
}
|
|
@@ -703,7 +785,9 @@ class DotLottiePlayer extends LitElement {
|
|
|
703
785
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Pause));
|
|
704
786
|
}
|
|
705
787
|
stop() {
|
|
706
|
-
if (!this._lottieInstance)
|
|
788
|
+
if (!this._lottieInstance) {
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
707
791
|
if (this.currentState) {
|
|
708
792
|
this._playerState.prev = this.currentState;
|
|
709
793
|
}
|
|
@@ -715,7 +799,9 @@ class DotLottiePlayer extends LitElement {
|
|
|
715
799
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Stop));
|
|
716
800
|
}
|
|
717
801
|
destroy() {
|
|
718
|
-
if (!this._lottieInstance)
|
|
802
|
+
if (!this._lottieInstance) {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
719
805
|
this.currentState = PlayerState.Destroyed;
|
|
720
806
|
this._lottieInstance.destroy();
|
|
721
807
|
this._lottieInstance = null;
|
|
@@ -724,7 +810,9 @@ class DotLottiePlayer extends LitElement {
|
|
|
724
810
|
document.removeEventListener('visibilitychange', this._onVisibilityChange);
|
|
725
811
|
}
|
|
726
812
|
seek(value) {
|
|
727
|
-
if (!this._lottieInstance)
|
|
813
|
+
if (!this._lottieInstance) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
728
816
|
const matches = value.toString().match(/^([0-9]+)(%?)$/);
|
|
729
817
|
if (!matches) {
|
|
730
818
|
return;
|
|
@@ -740,7 +828,9 @@ class DotLottiePlayer extends LitElement {
|
|
|
740
828
|
this._lottieInstance.pause();
|
|
741
829
|
}
|
|
742
830
|
snapshot() {
|
|
743
|
-
if (!this.shadowRoot)
|
|
831
|
+
if (!this.shadowRoot) {
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
744
834
|
const svgElement = this.shadowRoot.querySelector('.animation svg'), data = svgElement instanceof Node ? new XMLSerializer().serializeToString(svgElement) : null;
|
|
745
835
|
if (!data) {
|
|
746
836
|
console.error('Could not serialize data');
|
|
@@ -753,16 +843,22 @@ class DotLottiePlayer extends LitElement {
|
|
|
753
843
|
return data;
|
|
754
844
|
}
|
|
755
845
|
setSubframe(value) {
|
|
756
|
-
if (!this._lottieInstance)
|
|
846
|
+
if (!this._lottieInstance) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
757
849
|
this.subframe = value;
|
|
758
850
|
this._lottieInstance.setSubframe(value);
|
|
759
851
|
}
|
|
760
852
|
setCount(value) {
|
|
761
|
-
if (!this._lottieInstance)
|
|
853
|
+
if (!this._lottieInstance) {
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
762
856
|
this.count = value;
|
|
763
857
|
}
|
|
764
858
|
_freeze() {
|
|
765
|
-
if (!this._lottieInstance)
|
|
859
|
+
if (!this._lottieInstance) {
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
766
862
|
if (this.currentState) {
|
|
767
863
|
this._playerState.prev = this.currentState;
|
|
768
864
|
}
|
|
@@ -773,19 +869,25 @@ class DotLottiePlayer extends LitElement {
|
|
|
773
869
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Freeze));
|
|
774
870
|
}
|
|
775
871
|
async reload() {
|
|
776
|
-
if (!this._lottieInstance)
|
|
872
|
+
if (!this._lottieInstance) {
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
777
875
|
this._lottieInstance.destroy();
|
|
778
876
|
if (this.src) {
|
|
779
877
|
await this.load(this.src);
|
|
780
878
|
}
|
|
781
879
|
}
|
|
782
880
|
setSpeed(value = 1) {
|
|
783
|
-
if (!this._lottieInstance)
|
|
881
|
+
if (!this._lottieInstance) {
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
784
884
|
this.speed = value;
|
|
785
885
|
this._lottieInstance.setSpeed(value);
|
|
786
886
|
}
|
|
787
887
|
setDirection(value) {
|
|
788
|
-
if (!this._lottieInstance)
|
|
888
|
+
if (!this._lottieInstance) {
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
789
891
|
this.direction = value;
|
|
790
892
|
this._lottieInstance.setDirection(value);
|
|
791
893
|
}
|
|
@@ -803,7 +905,9 @@ class DotLottiePlayer extends LitElement {
|
|
|
803
905
|
this.multiAnimationSettings = settings;
|
|
804
906
|
}
|
|
805
907
|
togglePlay() {
|
|
806
|
-
if (!this._lottieInstance)
|
|
908
|
+
if (!this._lottieInstance) {
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
807
911
|
const { currentFrame, playDirection, totalFrames } = this._lottieInstance;
|
|
808
912
|
if (this.currentState === PlayerState.Playing) {
|
|
809
913
|
return this.pause();
|
|
@@ -855,9 +959,13 @@ class DotLottiePlayer extends LitElement {
|
|
|
855
959
|
setTimeout(()=>this._toggleSettings(false), 200);
|
|
856
960
|
}
|
|
857
961
|
_switchInstance(isPrevious = false) {
|
|
858
|
-
if (!this._animations[this._currentAnimation])
|
|
962
|
+
if (!this._animations[this._currentAnimation]) {
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
859
965
|
try {
|
|
860
|
-
if (this._lottieInstance)
|
|
966
|
+
if (this._lottieInstance) {
|
|
967
|
+
this._lottieInstance.destroy();
|
|
968
|
+
}
|
|
861
969
|
this._lottieInstance = Lottie.loadAnimation({
|
|
862
970
|
...this._getOptions(),
|
|
863
971
|
animationData: this._animations[this._currentAnimation]
|
|
@@ -934,7 +1042,9 @@ class DotLottiePlayer extends LitElement {
|
|
|
934
1042
|
this._intersectionObserver.disconnect();
|
|
935
1043
|
this._intersectionObserver = undefined;
|
|
936
1044
|
}
|
|
937
|
-
if (this._lottieInstance)
|
|
1045
|
+
if (this._lottieInstance) {
|
|
1046
|
+
this._lottieInstance.destroy();
|
|
1047
|
+
}
|
|
938
1048
|
document.removeEventListener('visibilitychange', this._onVisibilityChange);
|
|
939
1049
|
}
|
|
940
1050
|
renderControls() {
|