@aarsteinmedia/dotlottie-player 4.0.3 → 4.0.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/CHANGELOG.md +157 -0
- package/dist/cjs/index.js +313 -82
- package/dist/esm/index.js +313 -82
- package/dist/index.js +2 -2
- package/package.json +4 -3
package/dist/cjs/index.js
CHANGED
|
@@ -100,12 +100,20 @@ const addExt = (ext, str)=>{
|
|
|
100
100
|
default:
|
|
101
101
|
return 'xMidYMid meet';
|
|
102
102
|
}
|
|
103
|
-
},
|
|
103
|
+
}, /**
|
|
104
|
+
* Convert Base64 encoded string to Uint8Array
|
|
105
|
+
* @param { string } str Base64 encoded string
|
|
106
|
+
* @returns { Uint8Array } UTF-8/Latin-1 binary
|
|
107
|
+
*/ base64ToU8 = (str)=>fflate.strToU8(isServer() ? Buffer.from(parseBase64(str), 'base64').toString('binary') : atob(parseBase64(str)), true), /**
|
|
108
|
+
* Convert a JSON Lottie to dotLottie or combine several animations and download new dotLottie file in your browser.
|
|
109
|
+
*/ createDotLottie = async ({ animations, fileName, manifest, shouldDownload = true })=>{
|
|
104
110
|
try {
|
|
111
|
+
// Input validation
|
|
105
112
|
if (!animations?.length || !manifest) {
|
|
106
113
|
throw new Error(`Missing or malformed required parameter(s):\n ${animations?.length ? '- manifest\n' : ''} ${manifest ? '- animations\n' : ''}`);
|
|
107
114
|
}
|
|
108
|
-
const manifestCompressionLevel = 0, animationCompressionLevel = 9,
|
|
115
|
+
const manifestCompressionLevel = 0, animationCompressionLevel = 9, // Prepare the dotLottie file
|
|
116
|
+
name = addExt('lottie', fileName) || `${useId()}.lottie`, dotlottie = {
|
|
109
117
|
'manifest.json': [
|
|
110
118
|
fflate.strToU8(JSON.stringify(manifest), true),
|
|
111
119
|
{
|
|
@@ -113,14 +121,19 @@ const addExt = (ext, str)=>{
|
|
|
113
121
|
}
|
|
114
122
|
]
|
|
115
123
|
};
|
|
124
|
+
// Add animations and assets to the dotLottie file
|
|
116
125
|
for (const [i, animation] of animations.entries()){
|
|
117
126
|
for (const asset of animation.assets ?? []){
|
|
118
127
|
if (!asset.p || !isImage(asset) && !isAudio(asset)) {
|
|
119
128
|
continue;
|
|
120
129
|
}
|
|
121
|
-
const { p: file, u: path } = asset,
|
|
130
|
+
const { p: file, u: path } = asset, // Original asset.id caused issues with multianimations
|
|
131
|
+
assetId = useId('asset'), isEncoded = file.startsWith('data:'), ext = isEncoded ? getExtFromB64(file) : getExt(file), // Check if the asset is already base64-encoded. If not, get path, fetch it, and encode it
|
|
132
|
+
dataURL = isEncoded ? file : await fileToBase64(path ? path.endsWith('/') && `${path}${file}` || `${path}/${file}` : file);
|
|
122
133
|
asset.p = `${assetId}.${ext}`;
|
|
134
|
+
// Asset is embedded, so path empty string
|
|
123
135
|
asset.u = '';
|
|
136
|
+
// Asset is encoded
|
|
124
137
|
asset.e = 1;
|
|
125
138
|
dotlottie[`${isAudio(asset) ? 'audio' : 'images'}/${assetId}.${ext}`] = [
|
|
126
139
|
base64ToU8(dataURL),
|
|
@@ -157,7 +170,11 @@ const addExt = (ext, str)=>{
|
|
|
157
170
|
} catch (err) {
|
|
158
171
|
console.error(`❌ ${handleErrors(err).message}`);
|
|
159
172
|
}
|
|
160
|
-
},
|
|
173
|
+
}, /**
|
|
174
|
+
* Download file, either SVG or dotLottie.
|
|
175
|
+
* @param { string } data The data to be downloaded
|
|
176
|
+
* @param { string } name Don't include file extension in the filename
|
|
177
|
+
*/ download = (data, options)=>{
|
|
161
178
|
const blob = new Blob([
|
|
162
179
|
data
|
|
163
180
|
], {
|
|
@@ -214,7 +231,11 @@ const addExt = (ext, str)=>{
|
|
|
214
231
|
error.status = result.status;
|
|
215
232
|
throw error;
|
|
216
233
|
}
|
|
217
|
-
|
|
234
|
+
/**
|
|
235
|
+
* Check if file is JSON, first by parsing file name for extension,
|
|
236
|
+
* then – if filename has no extension – by cloning the response
|
|
237
|
+
* and parsing it for content.
|
|
238
|
+
*/ const ext = getExt(input);
|
|
218
239
|
if (ext === 'json' || !ext) {
|
|
219
240
|
if (ext) {
|
|
220
241
|
const lottie = await result.json();
|
|
@@ -267,7 +288,10 @@ const addExt = (ext, str)=>{
|
|
|
267
288
|
});
|
|
268
289
|
});
|
|
269
290
|
return arrayBuffer;
|
|
270
|
-
},
|
|
291
|
+
}, /**
|
|
292
|
+
* Get extension from filename, URL or path
|
|
293
|
+
* @param { string } str Filename, URL or path
|
|
294
|
+
*/ getExt = (str)=>{
|
|
271
295
|
if (typeof str !== 'string' || !str || !hasExt(str)) {
|
|
272
296
|
return;
|
|
273
297
|
}
|
|
@@ -275,9 +299,16 @@ const addExt = (ext, str)=>{
|
|
|
275
299
|
}, getExtFromB64 = (str)=>{
|
|
276
300
|
const mime = str.split(':')[1].split(';')[0], ext = mime.split('/')[1].split('+')[0];
|
|
277
301
|
return ext;
|
|
278
|
-
},
|
|
302
|
+
}, /**
|
|
303
|
+
* Parse URL to get filename
|
|
304
|
+
* @param { string } src The url string
|
|
305
|
+
* @param { boolean } keepExt Whether to include file extension
|
|
306
|
+
* @returns { string } Filename, in lowercase
|
|
307
|
+
*/ getFilename = (src, keepExt)=>{
|
|
308
|
+
// Because the regex strips all special characters, we need to extract the file extension, so we can add it later if we need it
|
|
279
309
|
getExt(src);
|
|
280
|
-
return `${src.split('/').pop()?.replace(/\.[^.]*$/, '').replace(/\W+/g, '-')}${''}
|
|
310
|
+
return `${src.split('/').pop()?.replace(/\.[^.]*$/, '').replace(/\W+/g, '-')}${''}` // .toLowerCase()
|
|
311
|
+
;
|
|
281
312
|
}, getLottieJSON = async (resp)=>{
|
|
282
313
|
const unzipped = await unzip(resp), manifest = getManifest(unzipped), data = [], toResolve = [];
|
|
283
314
|
for (const { id } of manifest.animations){
|
|
@@ -369,7 +400,7 @@ const addExt = (ext, str)=>{
|
|
|
369
400
|
await Promise.all(toResolve);
|
|
370
401
|
}, unzip = async (resp)=>{
|
|
371
402
|
const u8 = new Uint8Array(await resp.arrayBuffer()), unzipped = await new Promise((resolve, reject)=>{
|
|
372
|
-
fflate.unzip(u8, (err, file)=>{
|
|
403
|
+
fflate.unzip(u8, /* { filter }, */ (err, file)=>{
|
|
373
404
|
if (err) {
|
|
374
405
|
reject(err);
|
|
375
406
|
}
|
|
@@ -382,15 +413,19 @@ const addExt = (ext, str)=>{
|
|
|
382
413
|
return `${prefix ?? `:${s4()}`}_${s4()}`;
|
|
383
414
|
};
|
|
384
415
|
|
|
385
|
-
|
|
386
|
-
|
|
416
|
+
/**
|
|
417
|
+
* Render Player
|
|
418
|
+
*/ function renderPlayer() {
|
|
419
|
+
this.template.innerHTML = /* HTML */ `<div class="animation-container main" data-controls="${this.controls ?? false}" lang="${this.description ? document?.documentElement?.lang : 'en'}" role="img" aria-label="${this.description ?? 'Lottie animation'}" data-loaded="${this._playerState.loaded}"><figure class="animation" style="background:${this.background}">${this.playerState === PlayerState.Error ? /* HTML */ `<div class="error"><svg preserveAspectRatio="xMidYMid slice" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="1920" height="1080" viewBox="0 0 1920 1080"><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>`;
|
|
387
420
|
this.shadow.adoptedStyleSheets = [
|
|
388
421
|
DotLottiePlayer.styles
|
|
389
422
|
];
|
|
390
423
|
this.shadow.appendChild(this.template.content.cloneNode(true));
|
|
391
424
|
}
|
|
392
425
|
|
|
393
|
-
|
|
426
|
+
/**
|
|
427
|
+
* Render Controls
|
|
428
|
+
*/ function renderControls() {
|
|
394
429
|
const slot = this.shadow.querySelector('slot[name=controls]');
|
|
395
430
|
if (!slot) {
|
|
396
431
|
return;
|
|
@@ -399,7 +434,7 @@ function renderControls() {
|
|
|
399
434
|
slot.innerHTML = '';
|
|
400
435
|
return;
|
|
401
436
|
}
|
|
402
|
-
slot.innerHTML = `<div class="lottie-controls toolbar ${this.playerState === PlayerState.Error ? 'has-error' : ''}" aria-label="Lottie Animation controls"><button class="togglePlay" data-active="false" aria-label="Toggle Play/Pause"><svg width="24" height="24" aria-hidden="true" focusable="false"><path d="M8.016 5.016L18.985 12 8.016 18.984V5.015z"/></svg></button> <button class="stop" data-active="true" aria-label="Stop"><svg width="24" height="24" aria-hidden="true" focusable="false"><path d="M6 6h12v12H6V6z"/></svg></button> <button class="prev" aria-label="Previous animation" hidden><svg width="24" height="24" aria-hidden="true" focusable="false"><path d="M17.9 18.2 8.1 12l9.8-6.2v12.4zm-10.3 0H6.1V5.8h1.5v12.4z"/></svg></button> <button class="next" aria-label="Next animation" hidden><svg width="24" height="24" aria-hidden="true" focusable="false"><path d="m6.1 5.8 9.8 6.2-9.8 6.2V5.8zM16.4 5.8h1.5v12.4h-1.5z"/></svg></button><form class="progress-container${this.simple ? ' simple' : ''}"><input class="seeker" type="range" min="0" max="100" step="1" value="${this._seeker.toString()}" aria-valuemin="0" aria-valuemax="100" role="slider" aria-valuenow="${this._seeker.toString()}" tabindex="0" aria-label="Slider for search"><progress max="100" value="${this._seeker}"></progress></form>${this.simple ? '' : `<button class="toggleLoop" data-active="${this.loop}" tabindex="0" aria-label="Toggle loop"><svg width="24" height="24" aria-hidden="true" focusable="false"><path 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"/></svg></button> <button class="toggleBoomerang" data-active="${this.mode === PlayMode.Bounce}" aria-label="Toggle boomerang" tabindex="0"><svg width="24" height="24" aria-hidden="true" focusable="false"><path 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"/></svg></button> <button class="toggleSettings" aria-label="Settings" aria-haspopup="true" aria-expanded="${!!this._isSettingsOpen}" aria-controls="${this._identifier}-settings"><svg width="24" height="24" aria-hidden="true" focusable="false"><circle cx="12" cy="5.4" r="2.5"/><circle cx="12" cy="12" r="2.5"/><circle cx="12" cy="18.6" r="2.5"/></svg></button><div id="${this._identifier}-settings" class="popover" hidden><button class="convert" aria-label="Convert JSON animation to dotLottie format" hidden><svg width="24" height="24" aria-hidden="true" focusable="false"><path 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"/></svg> Convert to dotLottie</button> <button class="snapshot" aria-label="Download still image"><svg width="24" height="24" aria-hidden="true" focusable="false"><path 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"/></svg> Download still image</button></div>`}</div>`;
|
|
437
|
+
slot.innerHTML = /* HTML */ `<div class="lottie-controls toolbar ${this.playerState === PlayerState.Error ? 'has-error' : ''}" aria-label="Lottie Animation controls"><button class="togglePlay" data-active="false" aria-label="Toggle Play/Pause"><svg width="24" height="24" aria-hidden="true" focusable="false"><path d="M8.016 5.016L18.985 12 8.016 18.984V5.015z"/></svg></button> <button class="stop" data-active="true" aria-label="Stop"><svg width="24" height="24" aria-hidden="true" focusable="false"><path d="M6 6h12v12H6V6z"/></svg></button> <button class="prev" aria-label="Previous animation" hidden><svg width="24" height="24" aria-hidden="true" focusable="false"><path d="M17.9 18.2 8.1 12l9.8-6.2v12.4zm-10.3 0H6.1V5.8h1.5v12.4z"/></svg></button> <button class="next" aria-label="Next animation" hidden><svg width="24" height="24" aria-hidden="true" focusable="false"><path d="m6.1 5.8 9.8 6.2-9.8 6.2V5.8zM16.4 5.8h1.5v12.4h-1.5z"/></svg></button><form class="progress-container${this.simple ? ' simple' : ''}"><input class="seeker" type="range" min="0" max="100" step="1" value="${this._seeker.toString()}" aria-valuemin="0" aria-valuemax="100" role="slider" 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"><svg width="24" height="24" aria-hidden="true" focusable="false"><path 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"/></svg></button> <button class="toggleBoomerang" data-active="${this.mode === PlayMode.Bounce}" aria-label="Toggle boomerang" tabindex="0"><svg width="24" height="24" aria-hidden="true" focusable="false"><path 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"/></svg></button> <button class="toggleSettings" aria-label="Settings" aria-haspopup="true" aria-expanded="${!!this._isSettingsOpen}" aria-controls="${this._identifier}-settings"><svg width="24" height="24" aria-hidden="true" focusable="false"><circle cx="12" cy="5.4" r="2.5"/><circle cx="12" cy="12" r="2.5"/><circle cx="12" cy="18.6" r="2.5"/></svg></button><div id="${this._identifier}-settings" class="popover" hidden><button class="convert" aria-label="Convert JSON animation to dotLottie format" hidden><svg width="24" height="24" aria-hidden="true" focusable="false"><path 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"/></svg> Convert to dotLottie</button> <button class="snapshot" aria-label="Download still image"><svg width="24" height="24" aria-hidden="true" focusable="false"><path 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"/></svg> Download still image</button></div>`}</div>`;
|
|
403
438
|
const togglePlay = this.shadow.querySelector('.togglePlay');
|
|
404
439
|
if (togglePlay instanceof HTMLButtonElement) {
|
|
405
440
|
togglePlay.onclick = this.togglePlay;
|
|
@@ -446,8 +481,14 @@ function renderControls() {
|
|
|
446
481
|
}
|
|
447
482
|
}
|
|
448
483
|
|
|
449
|
-
|
|
484
|
+
/**
|
|
485
|
+
* Credit to:
|
|
486
|
+
* @author Leonardo Favre <https://github.com/leofavre/observed-properties>
|
|
487
|
+
* @description Enhanced HTML element with reactive state handlers
|
|
488
|
+
*/ /* eslint-disable @typescript-eslint/ban-ts-comment */ const UPDATE_ON_CONNECTED = Symbol('UPDATE_ON_CONNECTED');
|
|
450
489
|
if (isServer()) {
|
|
490
|
+
// Mock HTMLElement for server-side rendering
|
|
491
|
+
// @ts-ignore
|
|
451
492
|
global.HTMLElement = class EmptyHTMLElement {
|
|
452
493
|
};
|
|
453
494
|
}
|
|
@@ -468,6 +509,7 @@ let EnhancedElement = class EnhancedElement extends HTMLElement {
|
|
|
468
509
|
}
|
|
469
510
|
constructor(){
|
|
470
511
|
super();
|
|
512
|
+
// @ts-ignore
|
|
471
513
|
const { observedProperties = [] } = this.constructor;
|
|
472
514
|
if (UPDATE_ON_CONNECTED in this) {
|
|
473
515
|
this[UPDATE_ON_CONNECTED] = [];
|
|
@@ -475,6 +517,7 @@ let EnhancedElement = class EnhancedElement extends HTMLElement {
|
|
|
475
517
|
if ('propertyChangedCallback' in this && typeof this.propertyChangedCallback === 'function') {
|
|
476
518
|
for (const propName of observedProperties){
|
|
477
519
|
const initialValue = this[propName], CACHED_VALUE = Symbol(propName);
|
|
520
|
+
// @ts-ignore
|
|
478
521
|
this[CACHED_VALUE] = initialValue;
|
|
479
522
|
Object.defineProperty(this, propName, {
|
|
480
523
|
get () {
|
|
@@ -496,34 +539,46 @@ let EnhancedElement = class EnhancedElement extends HTMLElement {
|
|
|
496
539
|
}
|
|
497
540
|
};
|
|
498
541
|
|
|
499
|
-
var $schema="https://json.schemastore.org/package";var name="@aarsteinmedia/dotlottie-player";var version="4.0.
|
|
542
|
+
var $schema="https://json.schemastore.org/package";var name="@aarsteinmedia/dotlottie-player";var version="4.0.4";var description="Web Component for playing Lottie animations in your web app. Previously @johanaarstein/dotlottie-player";var exports$1={".":{"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$1="./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:"git+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 contributors=[{name:"Anthony Colpron",email:"anthonycolpron@gmail.com",url:"https://github.com/anthony-colpron"}];var license="GPL-2.0-or-later";var scripts={test:"wtr",prebuild:"rimraf ./dist",build:"rollup -c","prebuild:types":"rimraf ./types","build:types":"tsc -p ./tsconfig.prod.json && tsc-alias","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:js":"eslint","lint:js:fix":"eslint --fix","lint:css":"npx stylelint **/*.scss","lint:css:fix":"npx stylelint **/*.scss --fix","lint:pkg":"npmPkgJsonLint .","lint:pkg:fix":"npmPkgJsonLint . --fix"};var dependencies={fflate:"^0.8.2","lottie-web":"^5.12.2"};var peerDependencies={"@types/react":">= 16.0.0"};var devDependencies={"@custom-elements-manifest/analyzer":"^0.10.3","@eslint/compat":"^1.2.2","@eslint/eslintrc":"^3.1.0","@eslint/js":"^9.13.0","@esm-bundle/chai":"4.3.4-fix.0","@open-wc/testing":"^4.0.0","@rollup/plugin-commonjs":"^28.0.1","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^15.3.0","@rollup/plugin-typescript":"^11.1.6","@swc/core":"^1.7.42","@types/mocha":"^10.0.9","@types/node":"^22.8.5","@typescript-eslint/eslint-plugin":"^8.12.2","@typescript-eslint/parser":"^8.12.2","@web/dev-server-esbuild":"^1.0.2","@web/dev-server-import-maps":"^0.2.1","@web/dev-server-rollup":"^0.6.4","@web/test-runner":"^0.19.0","@web/test-runner-playwright":"^0.11.0",autoprefixer:"^10.4.20",esbuild:"^0.24.0","esbuild-sass-plugin":"^3.3.1",eslint:"^9.13.0","eslint-config-prettier":"^9.1.0","eslint-import-resolver-typescript":"^3.6.3","eslint-plugin-import":"^2.31.0","eslint-plugin-jsdoc":"^48.11.0","eslint-plugin-perfectionist":"^3.9.1","eslint-plugin-prettier":"^5.2.1",globals:"^15.11.0","npm-package-json-lint":"^8.0.0","npm-package-json-lint-config-default":"^7.0.1","postcss-flexbugs-fixes":"^5.0.2",prettier:"^3.3.3",rimraf:"^6.0.1",rollup:"^4.24.3","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-serve":"^1.1.1","rollup-plugin-summary":"^2.0.1","rollup-plugin-swc3":"^0.12.1","rollup-plugin-typescript-paths":"^1.5.0",sass:"^1.80.5",stylelint:"^16.10.0","stylelint-config-standard-scss":"^13.1.0","tsc-alias":"^1.8.10",tslib:"^2.8.0",typescript:"^5.6.3"};var browserslist={production:[">0.3%","not dead","not op_mini all"],development:["last 1 chrome version","last 1 firefox version","last 1 safari version"]};var customElements$1="custom-elements.json";var files=["CHANGELOG.md","custom-elements.json","dist","README.md"];var keywords=["lottie","dotlottie","animation","web component","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 = {$schema:$schema,name:name,version:version,description:description,exports:exports$1,main:main,unpkg:unpkg,module:module$1,types:types,type:type,homepage:homepage,repository:repository,bugs:bugs,author:author,contributors:contributors,license:license,scripts:scripts,dependencies:dependencies,peerDependencies:peerDependencies,devDependencies:devDependencies,browserslist:browserslist,customElements:customElements$1,files:files,keywords:keywords,publishConfig:publishConfig,engines:engines,funding:funding};
|
|
500
543
|
|
|
501
544
|
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 display: block;\n width: 100%;\n height: 100%;\n}\n:host .main {\n display: flex;\n flex-direction: column;\n height: 100%;\n width: 100%;\n margin: 0;\n padding: 0;\n}\n:host .animation {\n width: 100%;\n height: 100%;\n display: flex;\n margin: 0;\n padding: 0;\n}\n:host [data-controls=true] .animation {\n height: calc(100% - 35px);\n}\n:host .animation-container {\n position: relative;\n}\n:host .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:host .popover::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:host .error {\n display: flex;\n margin: auto;\n justify-content: center;\n height: 100%;\n align-items: center;\n}\n:host .error svg {\n width: 100%;\n height: auto;\n}\n:host .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:host .toolbar.has-error {\n pointer-events: none;\n opacity: 0.5;\n}\n:host .toolbar 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:host .toolbar button:not([hidden]) {\n display: flex;\n}\n:host .toolbar button:hover {\n opacity: 1;\n}\n:host .toolbar button[data-active=true] {\n opacity: 1;\n fill: var(--lottie-player-toolbar-icon-active-color);\n}\n:host .toolbar button:disabled {\n opacity: 0.5;\n}\n:host .toolbar button:focus {\n outline: 0;\n}\n:host .toolbar button svg {\n pointer-events: none;\n}\n:host .toolbar button svg > * {\n fill: inherit;\n}\n:host .toolbar button.disabled svg {\n display: none;\n}\n:host .progress-container {\n position: relative;\n width: 100%;\n}\n:host .progress-container.simple {\n margin-right: 12px;\n}\n:host .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 /* background-color: var(--lottie-player-seeker-track-color); */\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:host .seeker::-webkit-slider-runnable-track, :host .seeker::-webkit-slider-thumb {\n appearance: none;\n outline: none;\n}\n:host .seeker::-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:host .seeker:hover::-webkit-slider-thumb, :host .seeker:focus::-webkit-slider-thumb {\n transform: scale(1);\n}\n:host .seeker::-moz-range-progress {\n background-color: var(--lottie-player-seeker-thumb-color);\n height: 5px;\n border-radius: 3px;\n}\n:host .seeker::-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:host .seeker:hover::-moz-range-thumb, :host .seeker:focus::-moz-range-thumb {\n transform: scale(1);\n}\n:host .seeker::-ms-track {\n width: 100%;\n height: 5px;\n cursor: pointer;\n background: transparent;\n border-color: transparent;\n color: transparent;\n}\n:host .seeker::-ms-fill-upper {\n background: var(--lottie-player-seeker-track-color);\n border-radius: 3px;\n}\n:host .seeker::-ms-fill-lower {\n background-color: var(--lottie-player-seeker-thumb-color);\n border-radius: 3px;\n}\n:host .seeker::-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:host .seeker:hover::-ms-thumb {\n transform: scale(1);\n}\n:host .seeker:focus::-ms-thumb {\n transform: scale(1);\n}\n:host .seeker:focus::-ms-fill-lower, :host .seeker:focus::-ms-fill-upper {\n background: var(--lottie-player-seeker-track-color);\n}\n:host 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:host ::-moz-progress-bar {\n background-color: var(--lottie-player-seeker-thumb-color);\n}\n:host ::-webkit-progress-inner-element {\n border-radius: 3px;\n overflow: hidden;\n}\n:host ::-webkit-slider-runnable-track {\n background-color: transparent;\n}\n:host ::-webkit-progress-value {\n background-color: var(--lottie-player-seeker-thumb-color);\n}\n\n@keyframes fade-in {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\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}";
|
|
502
545
|
|
|
503
546
|
let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
504
|
-
|
|
547
|
+
/**
|
|
548
|
+
* Initialize everything on component first render
|
|
549
|
+
*/ async connectedCallback() {
|
|
505
550
|
super.connectedCallback();
|
|
506
551
|
this._render();
|
|
507
552
|
this._container = this.shadow.querySelector('.animation');
|
|
508
553
|
this._renderControls();
|
|
554
|
+
// Add listener for Visibility API's change event.
|
|
509
555
|
if (typeof document.hidden !== 'undefined') {
|
|
510
556
|
document.addEventListener('visibilitychange', this._onVisibilityChange);
|
|
511
557
|
}
|
|
558
|
+
// Add intersection observer for detecting component being out-of-view.
|
|
512
559
|
this._addIntersectionObserver();
|
|
560
|
+
// Setup lottie player
|
|
513
561
|
await this.load(this.src);
|
|
514
562
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Rendered));
|
|
515
563
|
}
|
|
516
|
-
|
|
564
|
+
/**
|
|
565
|
+
* Cleanup on component destroy
|
|
566
|
+
*/ disconnectedCallback() {
|
|
567
|
+
// Remove intersection observer for detecting component being out-of-view
|
|
517
568
|
if (this._intersectionObserver) {
|
|
518
569
|
this._intersectionObserver.disconnect();
|
|
519
570
|
this._intersectionObserver = undefined;
|
|
520
571
|
}
|
|
572
|
+
// Destroy the animation instance
|
|
521
573
|
if (this._lottieInstance) {
|
|
522
574
|
this._lottieInstance.destroy();
|
|
523
575
|
}
|
|
576
|
+
// Remove the attached Visibility API's change event listener
|
|
524
577
|
document.removeEventListener('visibilitychange', this._onVisibilityChange);
|
|
525
578
|
}
|
|
526
|
-
|
|
579
|
+
/**
|
|
580
|
+
* Attributes to observe
|
|
581
|
+
*/ static get observedAttributes() {
|
|
527
582
|
return [
|
|
528
583
|
'animateOnScroll',
|
|
529
584
|
'autoplay',
|
|
@@ -537,7 +592,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
537
592
|
'subframe'
|
|
538
593
|
];
|
|
539
594
|
}
|
|
540
|
-
|
|
595
|
+
/**
|
|
596
|
+
* Runs when the value of an attribute is changed on the component
|
|
597
|
+
*/ async attributeChangedCallback(name, _oldValue, value) {
|
|
541
598
|
if (!this._lottieInstance) {
|
|
542
599
|
return;
|
|
543
600
|
}
|
|
@@ -616,6 +673,7 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
616
673
|
'_animations'
|
|
617
674
|
];
|
|
618
675
|
}
|
|
676
|
+
// name: string, oldValue: string, newValue: string
|
|
619
677
|
propertyChangedCallback(name, _oldValue, value) {
|
|
620
678
|
if (!this.shadow) {
|
|
621
679
|
return;
|
|
@@ -628,9 +686,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
628
686
|
togglePlay.dataset.active = (value === PlayerState.Playing || value === PlayerState.Paused).toString();
|
|
629
687
|
stop.dataset.active = (value === PlayerState.Stopped).toString();
|
|
630
688
|
if (value === PlayerState.Playing) {
|
|
631
|
-
togglePlay.innerHTML = `<svg width="24" height="24" aria-hidden="true" focusable="false"><path d="M14.016 5.016H18v13.969h-3.984V5.016zM6 18.984V5.015h3.984v13.969H6z"/></svg>`;
|
|
689
|
+
togglePlay.innerHTML = /* HTML */ `<svg width="24" height="24" aria-hidden="true" focusable="false"><path d="M14.016 5.016H18v13.969h-3.984V5.016zM6 18.984V5.015h3.984v13.969H6z"/></svg>`;
|
|
632
690
|
} else {
|
|
633
|
-
togglePlay.innerHTML = `<svg width="24" height="24" aria-hidden="true" focusable="false"><path d="M8.016 5.016L18.985 12 8.016 18.984V5.015z"/></svg>`;
|
|
691
|
+
togglePlay.innerHTML = /* HTML */ `<svg width="24" height="24" aria-hidden="true" focusable="false"><path d="M8.016 5.016L18.985 12 8.016 18.984V5.015z"/></svg>`;
|
|
634
692
|
}
|
|
635
693
|
}
|
|
636
694
|
if (name === '_seeker' && typeof value === 'number') {
|
|
@@ -660,7 +718,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
660
718
|
convert.hidden = this._isDotLottie;
|
|
661
719
|
}
|
|
662
720
|
}
|
|
663
|
-
|
|
721
|
+
/**
|
|
722
|
+
* Whether to trigger next frame with scroll
|
|
723
|
+
*/ set animateOnScroll(value) {
|
|
664
724
|
this.setAttribute('animateOnScroll', (!!value).toString());
|
|
665
725
|
}
|
|
666
726
|
get animateOnScroll() {
|
|
@@ -670,7 +730,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
670
730
|
}
|
|
671
731
|
return false;
|
|
672
732
|
}
|
|
673
|
-
|
|
733
|
+
/**
|
|
734
|
+
* Autoplay
|
|
735
|
+
*/ set autoplay(value) {
|
|
674
736
|
this.setAttribute('autoplay', (!!value).toString());
|
|
675
737
|
}
|
|
676
738
|
get autoplay() {
|
|
@@ -680,13 +742,17 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
680
742
|
}
|
|
681
743
|
return false;
|
|
682
744
|
}
|
|
683
|
-
|
|
745
|
+
/**
|
|
746
|
+
* Background color
|
|
747
|
+
*/ set background(value) {
|
|
684
748
|
this.setAttribute('background', value);
|
|
685
749
|
}
|
|
686
750
|
get background() {
|
|
687
751
|
return this.getAttribute('background') || 'transparent';
|
|
688
752
|
}
|
|
689
|
-
|
|
753
|
+
/**
|
|
754
|
+
* Show controls
|
|
755
|
+
*/ set controls(value) {
|
|
690
756
|
this.setAttribute('controls', (!!value).toString());
|
|
691
757
|
}
|
|
692
758
|
get controls() {
|
|
@@ -696,7 +762,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
696
762
|
}
|
|
697
763
|
return false;
|
|
698
764
|
}
|
|
699
|
-
|
|
765
|
+
/**
|
|
766
|
+
* Number of times to loop
|
|
767
|
+
*/ set count(value) {
|
|
700
768
|
this.setAttribute('count', value.toString());
|
|
701
769
|
}
|
|
702
770
|
get count() {
|
|
@@ -706,13 +774,17 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
706
774
|
}
|
|
707
775
|
return 0;
|
|
708
776
|
}
|
|
709
|
-
|
|
777
|
+
/**
|
|
778
|
+
* Description for screen readers
|
|
779
|
+
*/ set description(value) {
|
|
710
780
|
this.setAttribute('description', value);
|
|
711
781
|
}
|
|
712
782
|
get description() {
|
|
713
783
|
return this.getAttribute('description') || '';
|
|
714
784
|
}
|
|
715
|
-
|
|
785
|
+
/**
|
|
786
|
+
* Direction of animation
|
|
787
|
+
*/ set direction(value) {
|
|
716
788
|
this.setAttribute('direction', value.toString());
|
|
717
789
|
}
|
|
718
790
|
get direction() {
|
|
@@ -722,7 +794,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
722
794
|
}
|
|
723
795
|
return 1;
|
|
724
796
|
}
|
|
725
|
-
|
|
797
|
+
/**
|
|
798
|
+
* Whether to play on mouseover
|
|
799
|
+
*/ set hover(value) {
|
|
726
800
|
this.setAttribute('hover', value.toString());
|
|
727
801
|
}
|
|
728
802
|
get hover() {
|
|
@@ -732,7 +806,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
732
806
|
}
|
|
733
807
|
return false;
|
|
734
808
|
}
|
|
735
|
-
|
|
809
|
+
/**
|
|
810
|
+
* Pause between loop intrations, in miliseconds
|
|
811
|
+
*/ set intermission(value) {
|
|
736
812
|
this.setAttribute('intermission', value.toString());
|
|
737
813
|
}
|
|
738
814
|
get intermission() {
|
|
@@ -742,7 +818,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
742
818
|
}
|
|
743
819
|
return 0;
|
|
744
820
|
}
|
|
745
|
-
|
|
821
|
+
/**
|
|
822
|
+
* Loop animation
|
|
823
|
+
*/ set loop(value) {
|
|
746
824
|
this.setAttribute('loop', (!!value).toString());
|
|
747
825
|
}
|
|
748
826
|
get loop() {
|
|
@@ -752,7 +830,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
752
830
|
}
|
|
753
831
|
return false;
|
|
754
832
|
}
|
|
755
|
-
|
|
833
|
+
/**
|
|
834
|
+
* Play mode
|
|
835
|
+
*/ set mode(value) {
|
|
756
836
|
this.setAttribute('mode', value.toString());
|
|
757
837
|
}
|
|
758
838
|
get mode() {
|
|
@@ -762,7 +842,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
762
842
|
}
|
|
763
843
|
return PlayMode.Normal;
|
|
764
844
|
}
|
|
765
|
-
|
|
845
|
+
/**
|
|
846
|
+
* Resizing to container
|
|
847
|
+
*/ set objectfit(value) {
|
|
766
848
|
this.setAttribute('objectfit', value);
|
|
767
849
|
}
|
|
768
850
|
get objectfit() {
|
|
@@ -772,7 +854,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
772
854
|
}
|
|
773
855
|
return ObjectFit.Contain;
|
|
774
856
|
}
|
|
775
|
-
|
|
857
|
+
/**
|
|
858
|
+
* Resizing to container (Deprecated)
|
|
859
|
+
*/ set preserveAspectRatio(value) {
|
|
776
860
|
this.setAttribute('preserveAspectRatio', value || PreserveAspectRatio.Contain);
|
|
777
861
|
}
|
|
778
862
|
get preserveAspectRatio() {
|
|
@@ -782,7 +866,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
782
866
|
}
|
|
783
867
|
return null;
|
|
784
868
|
}
|
|
785
|
-
|
|
869
|
+
/**
|
|
870
|
+
* Renderer to use: svg, canvas or html
|
|
871
|
+
*/ set renderer(value) {
|
|
786
872
|
this.setAttribute('renderer', value);
|
|
787
873
|
}
|
|
788
874
|
get renderer() {
|
|
@@ -792,7 +878,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
792
878
|
}
|
|
793
879
|
return 'svg';
|
|
794
880
|
}
|
|
795
|
-
|
|
881
|
+
/**
|
|
882
|
+
* Hide advanced controls
|
|
883
|
+
*/ set simple(value) {
|
|
796
884
|
this.setAttribute('simple', value.toString());
|
|
797
885
|
}
|
|
798
886
|
get simple() {
|
|
@@ -802,7 +890,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
802
890
|
}
|
|
803
891
|
return false;
|
|
804
892
|
}
|
|
805
|
-
|
|
893
|
+
/**
|
|
894
|
+
* Speed
|
|
895
|
+
*/ set speed(value) {
|
|
806
896
|
this.setAttribute('speed', value?.toString());
|
|
807
897
|
}
|
|
808
898
|
get speed() {
|
|
@@ -812,13 +902,17 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
812
902
|
}
|
|
813
903
|
return 1;
|
|
814
904
|
}
|
|
815
|
-
|
|
905
|
+
/**
|
|
906
|
+
* Source, either path or JSON string
|
|
907
|
+
*/ set src(value) {
|
|
816
908
|
this.setAttribute('src', value || '');
|
|
817
909
|
}
|
|
818
910
|
get src() {
|
|
819
911
|
return this.getAttribute('src');
|
|
820
912
|
}
|
|
821
|
-
|
|
913
|
+
/**
|
|
914
|
+
* Subframe
|
|
915
|
+
*/ set subframe(value) {
|
|
822
916
|
this.setAttribute('subframe', (!!value).toString());
|
|
823
917
|
}
|
|
824
918
|
get subframe() {
|
|
@@ -828,29 +922,45 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
828
922
|
}
|
|
829
923
|
return false;
|
|
830
924
|
}
|
|
831
|
-
|
|
925
|
+
/**
|
|
926
|
+
* Get Multi-animation settings
|
|
927
|
+
* @returns { AnimationSettings[] }
|
|
928
|
+
*/ getMultiAnimationSettings() {
|
|
832
929
|
return this._multiAnimationSettings;
|
|
833
930
|
}
|
|
834
|
-
|
|
931
|
+
/**
|
|
932
|
+
* Set Multi-animation settings
|
|
933
|
+
* @param { AnimationSettings[] } settings
|
|
934
|
+
*/ setMultiAnimationSettings(settings) {
|
|
835
935
|
if (!this._lottieInstance) {
|
|
836
936
|
return;
|
|
837
937
|
}
|
|
838
938
|
this._multiAnimationSettings = settings;
|
|
839
939
|
}
|
|
840
|
-
|
|
940
|
+
/**
|
|
941
|
+
* Set playback segment
|
|
942
|
+
* @param { AnimationSegment } settings
|
|
943
|
+
*/ setSegment(segment) {
|
|
841
944
|
if (!this._lottieInstance) {
|
|
842
945
|
return;
|
|
843
946
|
}
|
|
844
947
|
this._segment = segment;
|
|
845
948
|
}
|
|
846
|
-
|
|
949
|
+
/**
|
|
950
|
+
* Get playback segment
|
|
951
|
+
* @returns { AnimationSegment }
|
|
952
|
+
*/ getSegment() {
|
|
847
953
|
return this._segment;
|
|
848
954
|
}
|
|
849
|
-
|
|
955
|
+
/**
|
|
956
|
+
* Get options from props
|
|
957
|
+
* @returns { AnimationConfig }
|
|
958
|
+
*/ _getOptions() {
|
|
850
959
|
if (!this._container) {
|
|
851
960
|
throw new Error('Container not rendered');
|
|
852
961
|
}
|
|
853
962
|
const preserveAspectRatio = this.preserveAspectRatio ?? (this.objectfit && aspectRatio(this.objectfit)), currentAnimationSettings = this._multiAnimationSettings?.length ? this._multiAnimationSettings?.[this._currentAnimation] : undefined, currentAnimationManifest = this._manifest.animations?.[this._currentAnimation];
|
|
963
|
+
// Loop
|
|
854
964
|
let loop = !!this.loop;
|
|
855
965
|
if (currentAnimationManifest.loop !== undefined && this.loop === undefined) {
|
|
856
966
|
loop = !!currentAnimationManifest.loop;
|
|
@@ -858,6 +968,7 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
858
968
|
if (currentAnimationSettings?.loop !== undefined) {
|
|
859
969
|
loop = !!currentAnimationSettings.loop;
|
|
860
970
|
}
|
|
971
|
+
// Autoplay
|
|
861
972
|
let autoplay = !!this.autoplay;
|
|
862
973
|
if (currentAnimationManifest.autoplay !== undefined && this.autoplay === undefined) {
|
|
863
974
|
autoplay = !!currentAnimationManifest.autoplay;
|
|
@@ -868,6 +979,7 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
868
979
|
if (this.animateOnScroll) {
|
|
869
980
|
autoplay = false;
|
|
870
981
|
}
|
|
982
|
+
// Segment
|
|
871
983
|
let initialSegment = this._segment;
|
|
872
984
|
if (this._segment?.every((val)=>val > 0)) {
|
|
873
985
|
initialSegment = [
|
|
@@ -913,7 +1025,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
913
1025
|
}
|
|
914
1026
|
return options;
|
|
915
1027
|
}
|
|
916
|
-
|
|
1028
|
+
/**
|
|
1029
|
+
* Add IntersectionObserver
|
|
1030
|
+
*/ _addIntersectionObserver() {
|
|
917
1031
|
if (!this._container || this._intersectionObserver || !('IntersectionObserver' in window)) {
|
|
918
1032
|
return;
|
|
919
1033
|
}
|
|
@@ -937,10 +1051,13 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
937
1051
|
});
|
|
938
1052
|
this._intersectionObserver.observe(this._container);
|
|
939
1053
|
}
|
|
940
|
-
|
|
1054
|
+
/**
|
|
1055
|
+
* Initialize Lottie Web player
|
|
1056
|
+
*/ async load(src) {
|
|
941
1057
|
if (!this.shadowRoot || !src) {
|
|
942
1058
|
return;
|
|
943
1059
|
}
|
|
1060
|
+
// Load the resource
|
|
944
1061
|
try {
|
|
945
1062
|
const { animations, isDotLottie, manifest } = await getAnimationData(src);
|
|
946
1063
|
if (!animations || animations.some((animation)=>!this._isLottie(animation))) {
|
|
@@ -966,6 +1083,7 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
966
1083
|
}
|
|
967
1084
|
]
|
|
968
1085
|
};
|
|
1086
|
+
// Clear previous animation, if any
|
|
969
1087
|
if (this._lottieInstance) {
|
|
970
1088
|
this._lottieInstance.destroy();
|
|
971
1089
|
}
|
|
@@ -973,6 +1091,7 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
973
1091
|
if (!this.animateOnScroll && (this.autoplay || this._multiAnimationSettings?.[this._currentAnimation]?.autoplay)) {
|
|
974
1092
|
this.playerState = PlayerState.Playing;
|
|
975
1093
|
}
|
|
1094
|
+
// Initialize lottie player and load animation
|
|
976
1095
|
this._lottieInstance = Lottie__namespace.default.loadAnimation({
|
|
977
1096
|
...this._getOptions(),
|
|
978
1097
|
animationData: animations[this._currentAnimation]
|
|
@@ -985,9 +1104,11 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
985
1104
|
}
|
|
986
1105
|
this._addEventListeners();
|
|
987
1106
|
const speed = this._multiAnimationSettings?.[this._currentAnimation]?.speed ?? this.speed ?? this._manifest.animations[this._currentAnimation].speed, direction = this._multiAnimationSettings?.[this._currentAnimation]?.direction ?? this.direction ?? this._manifest.animations[this._currentAnimation].direction ?? 1;
|
|
1107
|
+
// Set initial playback speed and direction
|
|
988
1108
|
this._lottieInstance.setSpeed(speed);
|
|
989
1109
|
this._lottieInstance.setDirection(direction);
|
|
990
1110
|
this._lottieInstance.setSubframe(!!this.subframe);
|
|
1111
|
+
// Start playing if autoplay is enabled
|
|
991
1112
|
if (this.autoplay || this.animateOnScroll) {
|
|
992
1113
|
if (this.direction === -1) {
|
|
993
1114
|
this.seek('99%');
|
|
@@ -1001,10 +1122,14 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1001
1122
|
this._addIntersectionObserver();
|
|
1002
1123
|
}
|
|
1003
1124
|
}
|
|
1004
|
-
|
|
1125
|
+
/**
|
|
1126
|
+
* Get Lottie Manifest
|
|
1127
|
+
*/ getManifest() {
|
|
1005
1128
|
return this._manifest;
|
|
1006
1129
|
}
|
|
1007
|
-
|
|
1130
|
+
/**
|
|
1131
|
+
* Toggle event listeners
|
|
1132
|
+
*/ _toggleEventListeners(action) {
|
|
1008
1133
|
const method = action === 'add' ? 'addEventListener' : 'removeEventListener';
|
|
1009
1134
|
if (this._lottieInstance) {
|
|
1010
1135
|
this._lottieInstance[method]('enterFrame', this._enterFrame);
|
|
@@ -1033,17 +1158,22 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1033
1158
|
});
|
|
1034
1159
|
}
|
|
1035
1160
|
}
|
|
1036
|
-
|
|
1161
|
+
/**
|
|
1162
|
+
* Add event listeners
|
|
1163
|
+
*/ _addEventListeners() {
|
|
1037
1164
|
this._toggleEventListeners('add');
|
|
1038
1165
|
}
|
|
1039
|
-
|
|
1166
|
+
/**
|
|
1167
|
+
* Remove event listeners
|
|
1168
|
+
*/ _removeEventListeners() {
|
|
1040
1169
|
this._toggleEventListeners('remove');
|
|
1041
1170
|
}
|
|
1042
1171
|
_loopComplete() {
|
|
1043
1172
|
if (!this._lottieInstance) {
|
|
1044
1173
|
return;
|
|
1045
1174
|
}
|
|
1046
|
-
const { playDirection,
|
|
1175
|
+
const { playDirection, // firstFrame,
|
|
1176
|
+
totalFrames } = this._lottieInstance, inPoint = this._segment ? this._segment[0] : 0, outPoint = this._segment ? this._segment[0] : totalFrames;
|
|
1047
1177
|
if (this.count) {
|
|
1048
1178
|
if (this._isBounce) {
|
|
1049
1179
|
this._playerState.count += 0.5;
|
|
@@ -1129,17 +1259,23 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1129
1259
|
this.play();
|
|
1130
1260
|
}
|
|
1131
1261
|
}
|
|
1132
|
-
|
|
1262
|
+
/**
|
|
1263
|
+
* Handle MouseEnter
|
|
1264
|
+
*/ _mouseEnter() {
|
|
1133
1265
|
if (this.hover && this.playerState !== PlayerState.Playing) {
|
|
1134
1266
|
this.play();
|
|
1135
1267
|
}
|
|
1136
1268
|
}
|
|
1137
|
-
|
|
1269
|
+
/**
|
|
1270
|
+
* Handle MouseLeave
|
|
1271
|
+
*/ _mouseLeave() {
|
|
1138
1272
|
if (this.hover && this.playerState === PlayerState.Playing) {
|
|
1139
1273
|
this.stop();
|
|
1140
1274
|
}
|
|
1141
1275
|
}
|
|
1142
|
-
|
|
1276
|
+
/**
|
|
1277
|
+
* Handle visibility change events
|
|
1278
|
+
*/ _onVisibilityChange() {
|
|
1143
1279
|
if (document.hidden && this.playerState === PlayerState.Playing) {
|
|
1144
1280
|
this._freeze();
|
|
1145
1281
|
return;
|
|
@@ -1148,7 +1284,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1148
1284
|
this.play();
|
|
1149
1285
|
}
|
|
1150
1286
|
}
|
|
1151
|
-
|
|
1287
|
+
/**
|
|
1288
|
+
* Handle scroll
|
|
1289
|
+
*/ _handleScroll() {
|
|
1152
1290
|
if (!this.animateOnScroll || !this._lottieInstance) {
|
|
1153
1291
|
return;
|
|
1154
1292
|
}
|
|
@@ -1174,7 +1312,10 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1174
1312
|
});
|
|
1175
1313
|
}
|
|
1176
1314
|
}
|
|
1177
|
-
|
|
1315
|
+
/**
|
|
1316
|
+
* Handles click and drag actions on the progress track
|
|
1317
|
+
* @param { Event & { HTMLInputElement } } event
|
|
1318
|
+
*/ _handleSeekChange({ target }) {
|
|
1178
1319
|
if (!(target instanceof HTMLInputElement) || !this._lottieInstance || isNaN(Number(target.value))) {
|
|
1179
1320
|
return;
|
|
1180
1321
|
}
|
|
@@ -1192,7 +1333,16 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1192
1333
|
];
|
|
1193
1334
|
return mandatory.every((field)=>Object.prototype.hasOwnProperty.call(json, field));
|
|
1194
1335
|
}
|
|
1195
|
-
|
|
1336
|
+
/**
|
|
1337
|
+
* Creates a new dotLottie file, by combinig several animations
|
|
1338
|
+
* @param { [ AnimationConfig ] } configs
|
|
1339
|
+
* @param { string } fileName
|
|
1340
|
+
* @param { boolean } shouldDownload Whether to trigger a download in the browser.
|
|
1341
|
+
* If set to false the function returns an ArrayBuffer. Defaults to true.
|
|
1342
|
+
*
|
|
1343
|
+
*/ async addAnimation(configs, fileName, shouldDownload = true) {
|
|
1344
|
+
// Initialize meta object for animation, with fallbacks for
|
|
1345
|
+
// when the method is called indepenently
|
|
1196
1346
|
const { animations = [], manifest = {
|
|
1197
1347
|
animations: this.src ? [
|
|
1198
1348
|
{
|
|
@@ -1234,10 +1384,14 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1234
1384
|
};
|
|
1235
1385
|
}
|
|
1236
1386
|
}
|
|
1237
|
-
|
|
1387
|
+
/**
|
|
1388
|
+
* Returns the lottie-web instance used in the component
|
|
1389
|
+
*/ getLottie() {
|
|
1238
1390
|
return this._lottieInstance;
|
|
1239
1391
|
}
|
|
1240
|
-
|
|
1392
|
+
/**
|
|
1393
|
+
* Play
|
|
1394
|
+
*/ async play() {
|
|
1241
1395
|
if (!this._lottieInstance) {
|
|
1242
1396
|
return;
|
|
1243
1397
|
}
|
|
@@ -1251,7 +1405,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1251
1405
|
this.playerState = PlayerState.Playing;
|
|
1252
1406
|
}
|
|
1253
1407
|
}
|
|
1254
|
-
|
|
1408
|
+
/**
|
|
1409
|
+
* Pause
|
|
1410
|
+
*/ pause() {
|
|
1255
1411
|
if (!this._lottieInstance) {
|
|
1256
1412
|
return;
|
|
1257
1413
|
}
|
|
@@ -1265,7 +1421,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1265
1421
|
this.playerState = PlayerState.Paused;
|
|
1266
1422
|
}
|
|
1267
1423
|
}
|
|
1268
|
-
|
|
1424
|
+
/**
|
|
1425
|
+
* Stop
|
|
1426
|
+
*/ stop() {
|
|
1269
1427
|
if (!this._lottieInstance) {
|
|
1270
1428
|
return;
|
|
1271
1429
|
}
|
|
@@ -1280,7 +1438,9 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1280
1438
|
this.playerState = PlayerState.Stopped;
|
|
1281
1439
|
}
|
|
1282
1440
|
}
|
|
1283
|
-
|
|
1441
|
+
/**
|
|
1442
|
+
* Destroy animation and element
|
|
1443
|
+
*/ destroy() {
|
|
1284
1444
|
if (!this._lottieInstance) {
|
|
1285
1445
|
return;
|
|
1286
1446
|
}
|
|
@@ -1291,16 +1451,23 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1291
1451
|
this.remove();
|
|
1292
1452
|
document.removeEventListener('visibilitychange', this._onVisibilityChange);
|
|
1293
1453
|
}
|
|
1294
|
-
|
|
1454
|
+
/**
|
|
1455
|
+
* Seek to a given frame
|
|
1456
|
+
* @param { number | string } value Frame to seek to
|
|
1457
|
+
*/ seek(value) {
|
|
1295
1458
|
if (!this._lottieInstance) {
|
|
1296
1459
|
return;
|
|
1297
1460
|
}
|
|
1461
|
+
// Extract frame number from either number or percentage value
|
|
1298
1462
|
const matches = value.toString().match(/^([0-9]+)(%?)$/);
|
|
1299
1463
|
if (!matches) {
|
|
1300
1464
|
return;
|
|
1301
1465
|
}
|
|
1466
|
+
// Calculate and set the frame number
|
|
1302
1467
|
const frame = Math.round(matches[2] === '%' ? this._lottieInstance.totalFrames * Number(matches[1]) / 100 : Number(matches[1]));
|
|
1468
|
+
// Set seeker to new frame number
|
|
1303
1469
|
this._seeker = frame;
|
|
1470
|
+
// Send lottie player to the new frame
|
|
1304
1471
|
if (this.playerState === PlayerState.Playing || this.playerState === PlayerState.Frozen && this._playerState.prev === PlayerState.Playing) {
|
|
1305
1472
|
this._lottieInstance.goToAndPlay(frame, true);
|
|
1306
1473
|
this.playerState = PlayerState.Playing;
|
|
@@ -1309,10 +1476,13 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1309
1476
|
this._lottieInstance.goToAndStop(frame, true);
|
|
1310
1477
|
this._lottieInstance.pause();
|
|
1311
1478
|
}
|
|
1312
|
-
|
|
1479
|
+
/**
|
|
1480
|
+
* Snapshot and download the current frame as SVG
|
|
1481
|
+
*/ snapshot() {
|
|
1313
1482
|
if (!this.shadowRoot || !this.src) {
|
|
1314
1483
|
return;
|
|
1315
1484
|
}
|
|
1485
|
+
// Get SVG element and serialize markup
|
|
1316
1486
|
const svgElement = this.shadowRoot.querySelector('.animation svg'), data = svgElement instanceof Node ? new XMLSerializer().serializeToString(svgElement) : null;
|
|
1317
1487
|
if (!data) {
|
|
1318
1488
|
console.error('Could not serialize data');
|
|
@@ -1324,19 +1494,28 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1324
1494
|
});
|
|
1325
1495
|
return data;
|
|
1326
1496
|
}
|
|
1327
|
-
|
|
1497
|
+
/**
|
|
1498
|
+
* Toggles subframe, for more smooth animations
|
|
1499
|
+
* @param { boolean } value Whether animation uses subframe
|
|
1500
|
+
*/ setSubframe(value) {
|
|
1328
1501
|
if (!this._lottieInstance) {
|
|
1329
1502
|
return;
|
|
1330
1503
|
}
|
|
1331
1504
|
this._lottieInstance.setSubframe(value);
|
|
1332
1505
|
}
|
|
1333
|
-
|
|
1506
|
+
/**
|
|
1507
|
+
* Dynamically set count for loops
|
|
1508
|
+
*/ setCount(value) {
|
|
1334
1509
|
if (!this._lottieInstance) {
|
|
1335
1510
|
return;
|
|
1336
1511
|
}
|
|
1337
1512
|
this.count = value;
|
|
1338
1513
|
}
|
|
1339
|
-
|
|
1514
|
+
/**
|
|
1515
|
+
* Freeze animation.
|
|
1516
|
+
* This internal state pauses animation and is used to differentiate between
|
|
1517
|
+
* user requested pauses and component instigated pauses.
|
|
1518
|
+
*/ _freeze() {
|
|
1340
1519
|
if (!this._lottieInstance) {
|
|
1341
1520
|
return;
|
|
1342
1521
|
}
|
|
@@ -1350,32 +1529,45 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1350
1529
|
this.playerState = PlayerState.Frozen;
|
|
1351
1530
|
}
|
|
1352
1531
|
}
|
|
1353
|
-
|
|
1532
|
+
/**
|
|
1533
|
+
* Reload animation
|
|
1534
|
+
*/ async reload() {
|
|
1354
1535
|
if (!this._lottieInstance || !this.src) {
|
|
1355
1536
|
return;
|
|
1356
1537
|
}
|
|
1357
1538
|
this._lottieInstance.destroy();
|
|
1358
1539
|
await this.load(this.src);
|
|
1359
1540
|
}
|
|
1360
|
-
|
|
1541
|
+
/**
|
|
1542
|
+
* Set animation playback speed
|
|
1543
|
+
* @param { number } value Playback speed
|
|
1544
|
+
*/ setSpeed(value = 1) {
|
|
1361
1545
|
if (!this._lottieInstance) {
|
|
1362
1546
|
return;
|
|
1363
1547
|
}
|
|
1364
1548
|
this._lottieInstance.setSpeed(value);
|
|
1365
1549
|
}
|
|
1366
|
-
|
|
1550
|
+
/**
|
|
1551
|
+
* Animation play direction
|
|
1552
|
+
* @param { AnimationDirection } value Animation direction
|
|
1553
|
+
*/ setDirection(value) {
|
|
1367
1554
|
if (!this._lottieInstance) {
|
|
1368
1555
|
return;
|
|
1369
1556
|
}
|
|
1370
1557
|
this._lottieInstance.setDirection(value);
|
|
1371
1558
|
}
|
|
1372
|
-
|
|
1559
|
+
/**
|
|
1560
|
+
* Set loop
|
|
1561
|
+
* @param { boolean } value
|
|
1562
|
+
*/ setLoop(value) {
|
|
1373
1563
|
if (!this._lottieInstance) {
|
|
1374
1564
|
return;
|
|
1375
1565
|
}
|
|
1376
1566
|
this._lottieInstance.setLoop(value);
|
|
1377
1567
|
}
|
|
1378
|
-
|
|
1568
|
+
/**
|
|
1569
|
+
* Toggle playing state
|
|
1570
|
+
*/ togglePlay() {
|
|
1379
1571
|
if (!this._lottieInstance) {
|
|
1380
1572
|
return;
|
|
1381
1573
|
}
|
|
@@ -1396,12 +1588,16 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1396
1588
|
}
|
|
1397
1589
|
return this._lottieInstance.goToAndPlay(0, true);
|
|
1398
1590
|
}
|
|
1399
|
-
|
|
1591
|
+
/**
|
|
1592
|
+
* Toggle loop
|
|
1593
|
+
*/ toggleLoop() {
|
|
1400
1594
|
const val = !this.loop;
|
|
1401
1595
|
this.loop = val;
|
|
1402
1596
|
this.setLoop(val);
|
|
1403
1597
|
}
|
|
1404
|
-
|
|
1598
|
+
/**
|
|
1599
|
+
* Toggle Boomerang
|
|
1600
|
+
*/ toggleBoomerang() {
|
|
1405
1601
|
const curr = this._multiAnimationSettings?.[this._currentAnimation];
|
|
1406
1602
|
if (curr?.mode !== undefined) {
|
|
1407
1603
|
if (curr.mode === PlayMode.Normal) {
|
|
@@ -1421,31 +1617,40 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1421
1617
|
this.mode = PlayMode.Normal;
|
|
1422
1618
|
this._isBounce = false;
|
|
1423
1619
|
}
|
|
1424
|
-
|
|
1620
|
+
/**
|
|
1621
|
+
* Toggle show Settings
|
|
1622
|
+
*/ _toggleSettings(flag) {
|
|
1425
1623
|
if (flag === undefined) {
|
|
1426
1624
|
this._isSettingsOpen = !this._isSettingsOpen;
|
|
1427
1625
|
return;
|
|
1428
1626
|
}
|
|
1429
1627
|
this._isSettingsOpen = flag;
|
|
1430
1628
|
}
|
|
1431
|
-
|
|
1629
|
+
/**
|
|
1630
|
+
* Handle blur
|
|
1631
|
+
*/ _handleBlur() {
|
|
1432
1632
|
setTimeout(()=>this._toggleSettings(false), 200);
|
|
1433
1633
|
}
|
|
1434
1634
|
_switchInstance(isPrevious = false) {
|
|
1635
|
+
// Bail early if there is not animation to play
|
|
1435
1636
|
if (!this._animations[this._currentAnimation]) {
|
|
1436
1637
|
return;
|
|
1437
1638
|
}
|
|
1438
1639
|
try {
|
|
1640
|
+
// Clear previous animation
|
|
1439
1641
|
if (this._lottieInstance) {
|
|
1440
1642
|
this._lottieInstance.destroy();
|
|
1441
1643
|
}
|
|
1644
|
+
// Re-initialize lottie player
|
|
1442
1645
|
this._lottieInstance = Lottie__namespace.default.loadAnimation({
|
|
1443
1646
|
...this._getOptions(),
|
|
1444
1647
|
animationData: this._animations[this._currentAnimation]
|
|
1445
1648
|
});
|
|
1649
|
+
// Check play mode for current animation
|
|
1446
1650
|
if (this._multiAnimationSettings?.[this._currentAnimation]?.mode) {
|
|
1447
1651
|
this._isBounce = this._multiAnimationSettings[this._currentAnimation].mode === PlayMode.Bounce;
|
|
1448
1652
|
}
|
|
1653
|
+
// Remove event listeners to new Lottie instance, and add new
|
|
1449
1654
|
this._removeEventListeners();
|
|
1450
1655
|
this._addEventListeners();
|
|
1451
1656
|
this.dispatchEvent(new CustomEvent(isPrevious ? PlayerEvents.Previous : PlayerEvents.Next));
|
|
@@ -1467,11 +1672,15 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1467
1672
|
this.dispatchEvent(new CustomEvent(PlayerEvents.Error));
|
|
1468
1673
|
}
|
|
1469
1674
|
}
|
|
1470
|
-
|
|
1675
|
+
/**
|
|
1676
|
+
* Skip to next animation
|
|
1677
|
+
*/ next() {
|
|
1471
1678
|
this._currentAnimation++;
|
|
1472
1679
|
this._switchInstance();
|
|
1473
1680
|
}
|
|
1474
|
-
|
|
1681
|
+
/**
|
|
1682
|
+
* Skip to previous animation
|
|
1683
|
+
*/ prev() {
|
|
1475
1684
|
this._currentAnimation--;
|
|
1476
1685
|
this._switchInstance(true);
|
|
1477
1686
|
}
|
|
@@ -1493,21 +1702,40 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1493
1702
|
shouldDownload
|
|
1494
1703
|
});
|
|
1495
1704
|
}
|
|
1496
|
-
|
|
1705
|
+
/**
|
|
1706
|
+
* Return the styles for the component
|
|
1707
|
+
*/ static get styles() {
|
|
1497
1708
|
const styleSheet = new CSSStyleSheet();
|
|
1498
1709
|
styleSheet.replace(css_248z);
|
|
1499
1710
|
return styleSheet;
|
|
1500
1711
|
}
|
|
1501
1712
|
constructor(){
|
|
1502
|
-
super(), this._renderControls = renderControls, this._render = renderPlayer,
|
|
1713
|
+
super(), this._renderControls = renderControls, this._render = renderPlayer, /**
|
|
1714
|
+
* Multi-animation settings
|
|
1715
|
+
*/ this._multiAnimationSettings = [], /**
|
|
1716
|
+
* @state
|
|
1717
|
+
* Player state
|
|
1718
|
+
*/ this.playerState = PlayerState.Loading, /**
|
|
1719
|
+
* @state
|
|
1720
|
+
* Whether settings toolbar is open
|
|
1721
|
+
*/ this._isSettingsOpen = false, /**
|
|
1722
|
+
* @state
|
|
1723
|
+
* Seeker
|
|
1724
|
+
*/ this._seeker = 0, /**
|
|
1725
|
+
* @state
|
|
1726
|
+
* Which animation to show, if several
|
|
1727
|
+
*/ this._currentAnimation = 0, this._lottieInstance = null, this._identifier = this.id || useId('dotlottie'), this._errorMessage = 'Something went wrong', this._isBounce = false, this._isDotLottie = false, this._playerState = {
|
|
1503
1728
|
count: 0,
|
|
1504
1729
|
loaded: false,
|
|
1505
1730
|
prev: PlayerState.Loading,
|
|
1506
1731
|
scrollTimeout: null,
|
|
1507
1732
|
scrollY: 0,
|
|
1508
1733
|
visible: false
|
|
1509
|
-
},
|
|
1734
|
+
}, /**
|
|
1735
|
+
* Handle settings click event
|
|
1736
|
+
*/ this._handleSettingsClick = ({ target })=>{
|
|
1510
1737
|
this._toggleSettings();
|
|
1738
|
+
// Because Safari does not add focus on click, we need to add it manually, so the onblur event will fire
|
|
1511
1739
|
if (target instanceof HTMLElement) {
|
|
1512
1740
|
target.focus();
|
|
1513
1741
|
}
|
|
@@ -1544,7 +1772,10 @@ let DotLottiePlayer = class DotLottiePlayer extends EnhancedElement {
|
|
|
1544
1772
|
}
|
|
1545
1773
|
};
|
|
1546
1774
|
|
|
1547
|
-
|
|
1775
|
+
/**
|
|
1776
|
+
* Expose DotLottiePlayer class as global variable
|
|
1777
|
+
* @returns { DotLottiePlayer }
|
|
1778
|
+
*/ globalThis.dotLottiePlayer = ()=>new DotLottiePlayer();
|
|
1548
1779
|
const tagName = 'dotlottie-player';
|
|
1549
1780
|
if (!isServer()) {
|
|
1550
1781
|
customElements.define('dotlottie-player', DotLottiePlayer);
|