@aarsteinmedia/dotlottie-player 5.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { strToU8, strFromU8, zip, unzip as unzip$1 } from 'fflate';
2
+ import { createElementID } from '@aarsteinmedia/lottie-web/utils';
2
3
  import * as Lottie from 'lottie-web/build/player/lottie.js';
3
4
 
4
5
  var ObjectFit = /*#__PURE__*/ function(ObjectFit) {
@@ -49,6 +50,12 @@ var PreserveAspectRatio = /*#__PURE__*/ function(PreserveAspectRatio) {
49
50
  PreserveAspectRatio["Initial"] = "none";
50
51
  return PreserveAspectRatio;
51
52
  }({});
53
+ var RendererType = /*#__PURE__*/ function(RendererType) {
54
+ RendererType["SVG"] = "svg";
55
+ RendererType["HTML"] = "html";
56
+ RendererType["Canvas"] = "canvas";
57
+ return RendererType;
58
+ }({});
52
59
 
53
60
  class CustomError extends Error {
54
61
  }
@@ -83,14 +90,14 @@ const addExt = (ext, str)=>{
83
90
  * @returns { Uint8Array } UTF-8/Latin-1 binary
84
91
  */ base64ToU8 = (str)=>strToU8(isServer() ? Buffer.from(parseBase64(str), 'base64').toString('binary') : atob(parseBase64(str)), true), /**
85
92
  * Convert a JSON Lottie to dotLottie or combine several animations and download new dotLottie file in your browser.
86
- */ createDotLottie = async ({ animations, fileName, manifest, shouldDownload = true })=>{
93
+ */ createDotLottie = async ({ animations = [], fileName, manifest, shouldDownload = true })=>{
87
94
  try {
88
95
  // Input validation
89
- if (!animations?.length || !manifest) {
90
- throw new Error(`Missing or malformed required parameter(s):\n ${animations?.length ? '- manifest\n' : ''} ${manifest ? '- animations\n' : ''}`);
96
+ if (!animations.length || !manifest) {
97
+ throw new Error(`Missing or malformed required parameter(s):\n ${animations.length ? '- manifest\n' : ''} ${manifest ? '- animations\n' : ''}`);
91
98
  }
92
99
  const manifestCompressionLevel = 0, animationCompressionLevel = 9, // Prepare the dotLottie file
93
- name = addExt('lottie', fileName) || `${useId()}.lottie`, dotlottie = {
100
+ name = addExt('lottie', fileName) || `${createElementID()}.lottie`, dotlottie = {
94
101
  'manifest.json': [
95
102
  strToU8(JSON.stringify(manifest), true),
96
103
  {
@@ -99,20 +106,26 @@ const addExt = (ext, str)=>{
99
106
  ]
100
107
  };
101
108
  // Add animations and assets to the dotLottie file
102
- for (const [i, animation] of animations.entries()){
103
- for (const asset of animation.assets ?? []){
104
- if (!asset.p || !isImage(asset) && !isAudio(asset)) {
109
+ const { length } = animations;
110
+ for(let i = 0; i < length; i++){
111
+ const { length: jLen } = animations[i].assets;
112
+ for(let j = 0; j < jLen; j++){
113
+ if (!animations[i].assets[j].p || !isImage(animations[i].assets[j]) && !isAudio(animations[i].assets[j])) {
114
+ continue;
115
+ }
116
+ const { p: file, u: path } = animations[i].assets[j];
117
+ if (!file) {
105
118
  continue;
106
119
  }
107
- const { p: file, u: path } = asset, // Original asset.id caused issues with multianimations
108
- 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
120
+ // Original asset.id caused issues with multianimations
121
+ const assetId = createElementID(), 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
109
122
  dataURL = isEncoded ? file : await fileToBase64(path ? path.endsWith('/') && `${path}${file}` || `${path}/${file}` : file);
110
- asset.p = `${assetId}.${ext}`;
123
+ animations[i].assets[j].p = `${assetId}.${ext}`;
111
124
  // Asset is embedded, so path empty string
112
- asset.u = '';
125
+ animations[i].assets[j].u = '';
113
126
  // Asset is encoded
114
- asset.e = 1;
115
- dotlottie[`${isAudio(asset) ? 'audio' : 'images'}/${assetId}.${ext}`] = [
127
+ animations[i].assets[j].e = 1;
128
+ dotlottie[`${isAudio(animations[i].assets[j]) ? 'audio' : 'images'}/${assetId}.${ext}`] = [
116
129
  base64ToU8(dataURL),
117
130
  {
118
131
  level: animationCompressionLevel
@@ -120,7 +133,7 @@ const addExt = (ext, str)=>{
120
133
  ];
121
134
  }
122
135
  dotlottie[`animations/${manifest.animations[i].id}.json`] = [
123
- strToU8(JSON.stringify(animation), true),
136
+ strToU8(JSON.stringify(animations[i]), true),
124
137
  {
125
138
  level: animationCompressionLevel
126
139
  }
@@ -137,9 +150,9 @@ const addExt = (ext, str)=>{
137
150
  }, createJSON = ({ animation, fileName, shouldDownload })=>{
138
151
  try {
139
152
  if (!animation) {
140
- throw new Error("Missing or malformed required parameter(s):\n - animation\n'");
153
+ throw new Error("createJSON: Missing or malformed required parameter(s):\n - animation\n'");
141
154
  }
142
- const name = addExt('json', fileName) || `${useId()}.json`, jsonString = JSON.stringify(animation);
155
+ const name = addExt('json', fileName) || `${createElementID()}.json`, jsonString = JSON.stringify(animation);
143
156
  return shouldDownload ? download(jsonString, {
144
157
  mimeType: 'application/json',
145
158
  name
@@ -156,7 +169,7 @@ const addExt = (ext, str)=>{
156
169
  data
157
170
  ], {
158
171
  type: options?.mimeType
159
- }), fileName = options?.name || useId(), dataURL = URL.createObjectURL(blob), link = document.createElement('a');
172
+ }), fileName = options?.name || createElementID(), dataURL = URL.createObjectURL(blob), link = document.createElement('a');
160
173
  link.href = dataURL;
161
174
  link.download = fileName;
162
175
  link.hidden = true;
@@ -195,7 +208,7 @@ const addExt = (ext, str)=>{
195
208
  return {
196
209
  animations,
197
210
  isDotLottie: false,
198
- manifest: undefined
211
+ manifest: null
199
212
  };
200
213
  }
201
214
  const result = await fetch(input, {
@@ -209,19 +222,24 @@ const addExt = (ext, str)=>{
209
222
  throw error;
210
223
  }
211
224
  /**
212
- * Check if file is JSON, first by parsing file name for extension,
213
- * then – if filename has no extension – by cloning the response
214
- * and parsing it for content.
215
- */ const ext = getExt(input);
216
- if (ext === 'json' || !ext) {
217
- if (ext) {
225
+ * Check if file is JSON, first by parsing headers for content-type,
226
+ * than by parsing filename, then – if filename has no extension – by
227
+ * cloning the response and parsing response for content.
228
+ */ let isJSON = true;
229
+ const contentType = result.headers.get('content-type');
230
+ if (contentType === 'application/zip+dotlottie') {
231
+ isJSON = false;
232
+ }
233
+ if (isJSON) {
234
+ const ext = getExt(input);
235
+ if (ext === 'json') {
218
236
  const lottie = await result.json();
219
237
  return {
220
238
  animations: [
221
239
  lottie
222
240
  ],
223
241
  isDotLottie: false,
224
- manifest: undefined
242
+ manifest: null
225
243
  };
226
244
  }
227
245
  const text = await result.clone().text();
@@ -232,9 +250,9 @@ const addExt = (ext, str)=>{
232
250
  lottie
233
251
  ],
234
252
  isDotLottie: false,
235
- manifest: undefined
253
+ manifest: null
236
254
  };
237
- } catch (_e) {
255
+ } catch (error) {
238
256
  /* empty */ }
239
257
  }
240
258
  const { data, manifest } = await getLottieJSON(result);
@@ -248,7 +266,7 @@ const addExt = (ext, str)=>{
248
266
  return {
249
267
  animations: undefined,
250
268
  isDotLottie: false,
251
- manifest: undefined
269
+ manifest: null
252
270
  };
253
271
  }
254
272
  }, getArrayBuffer = async (zippable)=>{
@@ -290,9 +308,16 @@ const addExt = (ext, str)=>{
290
308
  return `${src.split('/').pop()?.replace(/\.[^.]*$/, '').replace(/\W+/g, '-')}${''}` // .toLowerCase()
291
309
  ;
292
310
  }, getLottieJSON = async (resp)=>{
293
- const unzipped = await unzip(resp), manifest = getManifest(unzipped), data = [], toResolve = [];
294
- for (const { id } of manifest.animations){
295
- const str = strFromU8(unzipped[`animations/${id}.json`]), lottie = JSON.parse(prepareString(str));
311
+ const unzipped = await unzip(resp), manifest = getManifest(unzipped), data = [], toResolve = [], { length } = manifest.animations;
312
+ /**
313
+ * Check whether Lottie animations folder is abbreviated.
314
+ */ let animationsFolder = 'animations';
315
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
316
+ if (unzipped[`a/${manifest.animations[0].id}.json`]) {
317
+ animationsFolder = 'a';
318
+ }
319
+ for(let i = 0; i < length; i++){
320
+ const str = strFromU8(unzipped[`${animationsFolder}/${manifest.animations[i].id}.json`]), lottie = JSON.parse(prepareString(str));
296
321
  toResolve.push(resolveAssets(unzipped, lottie.assets));
297
322
  data.push(lottie);
298
323
  }
@@ -360,20 +385,20 @@ const addExt = (ext, str)=>{
360
385
  if (!Array.isArray(assets)) {
361
386
  return;
362
387
  }
363
- const toResolve = [];
364
- for (const asset of assets){
365
- if (!isAudio(asset) && !isImage(asset)) {
388
+ const toResolve = [], { length } = assets;
389
+ for(let i = 0; i < length; i++){
390
+ if (!isAudio(assets[i]) && !isImage(assets[i])) {
366
391
  continue;
367
392
  }
368
- const type = isImage(asset) ? 'images' : 'audio', u8 = unzipped?.[`${type}/${asset.p}`];
393
+ const type = isImage(assets[i]) ? 'images' : 'audio', u8 = unzipped?.[`${type}/${assets[i].p}`];
369
394
  if (!u8) {
370
395
  continue;
371
396
  }
372
397
  toResolve.push(new Promise((resolveAsset)=>{
373
398
  const assetB64 = isServer() ? Buffer.from(u8).toString('base64') : btoa(u8.reduce((dat, byte)=>`${dat}${String.fromCharCode(byte)}`, ''));
374
- asset.p = asset.p?.startsWith('data:') || isBase64(asset.p) ? asset.p : `data:${getMimeFromExt(getExt(asset.p))};base64,${assetB64}`;
375
- asset.e = 1;
376
- asset.u = '';
399
+ assets[i].p = assets[i].p?.startsWith('data:') || isBase64(assets[i].p) ? assets[i].p : `data:${getMimeFromExt(getExt(assets[i].p))};base64,${assetB64}`;
400
+ assets[i].e = 1;
401
+ assets[i].u = '';
377
402
  resolveAsset();
378
403
  }));
379
404
  }
@@ -388,9 +413,6 @@ const addExt = (ext, str)=>{
388
413
  });
389
414
  });
390
415
  return unzipped;
391
- }, useId = (prefix)=>{
392
- const s4 = ()=>((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
393
- return `${prefix ?? `:${s4()}`}_${s4()}`;
394
416
  };
395
417
 
396
418
  /**
@@ -464,42 +486,40 @@ const addExt = (ext, str)=>{
464
486
  /**
465
487
  * Credit to:
466
488
  * @author Leonardo Favre <https://github.com/leofavre/observed-properties>
467
- * @description Enhanced HTML element with reactive state handlers
468
- */ /* eslint-disable @typescript-eslint/ban-ts-comment */ const UPDATE_ON_CONNECTED = Symbol('UPDATE_ON_CONNECTED');
489
+ */ const UPDATE_ON_CONNECTED = Symbol('UPDATE_ON_CONNECTED');
469
490
  if (isServer()) {
470
491
  // Mock HTMLElement for server-side rendering
471
- // @ts-ignore
472
492
  global.HTMLElement = class EmptyHTMLElement {
473
493
  };
474
494
  }
475
495
  /**
476
496
  * HTMLElement enhanced to track property changes
477
- */ class EnhancedElement extends HTMLElement {
497
+ */ class PropertyCallbackElement extends HTMLElement {
478
498
  constructor(){
479
499
  super();
480
- // @ts-ignore
481
500
  const { observedProperties = [] } = this.constructor;
482
501
  if (UPDATE_ON_CONNECTED in this) {
483
502
  this[UPDATE_ON_CONNECTED] = [];
484
503
  }
485
504
  if ('propertyChangedCallback' in this && typeof this.propertyChangedCallback === 'function') {
486
- for (const propName of observedProperties){
487
- const initialValue = this[propName], CACHED_VALUE = Symbol(propName);
488
- // @ts-ignore
505
+ const { length } = observedProperties;
506
+ for(let i = 0; i < length; i++){
507
+ const initialValue = this[observedProperties[i]], CACHED_VALUE = Symbol(observedProperties[i]);
508
+ // @ts-expect-error: ingore
489
509
  this[CACHED_VALUE] = initialValue;
490
- Object.defineProperty(this, propName, {
510
+ Object.defineProperty(this, observedProperties[i], {
491
511
  get () {
492
512
  return this[CACHED_VALUE];
493
513
  },
494
514
  set (value) {
495
515
  const oldValue = this[CACHED_VALUE];
496
516
  this[CACHED_VALUE] = value;
497
- this.propertyChangedCallback(propName, oldValue, value);
517
+ this.propertyChangedCallback(observedProperties[i], oldValue, value);
498
518
  }
499
519
  });
500
520
  if (typeof initialValue !== 'undefined') {
501
521
  if (UPDATE_ON_CONNECTED in this && Array.isArray(this[UPDATE_ON_CONNECTED])) {
502
- this[UPDATE_ON_CONNECTED].push(propName);
522
+ this[UPDATE_ON_CONNECTED].push(observedProperties[i]);
503
523
  }
504
524
  }
505
525
  }
@@ -510,18 +530,19 @@ if (isServer()) {
510
530
  if (UPDATE_ON_CONNECTED in this && Array.isArray(this[UPDATE_ON_CONNECTED])) {
511
531
  arr = this[UPDATE_ON_CONNECTED];
512
532
  }
513
- for (const propName of arr){
533
+ const { length } = arr;
534
+ for(let i = 0; i < length; i++){
514
535
  if (!('propertyChangedCallback' in this) || typeof this.propertyChangedCallback !== 'function') {
515
536
  continue;
516
537
  }
517
- if (propName in this) {
518
- this.propertyChangedCallback(propName, undefined, this[propName]);
538
+ if (arr[i] in this) {
539
+ this.propertyChangedCallback(arr[i], undefined, this[arr[i]]);
519
540
  }
520
541
  }
521
542
  }
522
543
  }
523
544
 
524
- var name="@aarsteinmedia/dotlottie-player";var version="5.0.0";var description="Web Component for playing Lottie animations in your web app. Previously @johanaarstein/dotlottie-player";var exports={".":{"import":"./dist/index.js",node:"./dist/index.js",types:"./dist/index.d.ts"}};var main="./dist/index.js";var unpkg="./dist/unpkg/index.js";var module="./dist/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.js",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 **/*.css","lint:css:fix":"npx stylelint **/*.css --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.4","@eslint/compat":"^1.2.7","@eslint/js":"^9.21.0","@esm-bundle/chai":"4.3.4-fix.0","@open-wc/testing":"^4.0.0","@rollup/plugin-commonjs":"^28.0.2","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^16.0.0","@rollup/plugin-typescript":"^12.1.2","@swc/core":"^1.11.1","@types/mocha":"^10.0.10","@types/node":"^22.13.5","@types/path-browserify":"^1.0.3","@types/react":"^19.0.10","@web/dev-server-esbuild":"^1.0.4","@web/dev-server-import-maps":"^0.2.1","@web/dev-server-rollup":"^0.6.4","@web/test-runner":"^0.20.0","@web/test-runner-playwright":"^0.11.0",autoprefixer:"^10.4.20",esbuild:"^0.25.0",eslint:"^9.21.0","eslint-config-prettier":"^10.0.1","eslint-import-resolver-typescript":"^3.8.3","eslint-plugin-import":"^2.31.0","eslint-plugin-jsdoc":"^50.6.3","eslint-plugin-perfectionist":"^4.9.0","eslint-plugin-prettier":"^5.2.3",globals:"^16.0.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.5.2",react:"^19.0.0",rimraf:"^6.0.1",rollup:"^4.34.8","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":"^3.0.0","rollup-plugin-summary":"^3.0.0","rollup-plugin-swc3":"^0.12.1","rollup-plugin-typescript-paths":"^1.5.0",stylelint:"^16.14.1","stylelint-config-recommended":"^15.0.0","tsc-alias":"^1.8.10",tslib:"^2.8.1",typescript:"^5.7.3","typescript-eslint":"^8.25.0"};var pnpm={onlyBuiltDependencies:["@parcel/watcher","@swc/core","esbuild"]};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:">= 12.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,contributors:contributors,license:license,scripts:scripts,dependencies:dependencies,peerDependencies:peerDependencies,devDependencies:devDependencies,pnpm:pnpm,browserslist:browserslist,customElements:customElements$1,files:files,keywords:keywords,publishConfig:publishConfig,engines:engines,funding:funding};
545
+ var name="@aarsteinmedia/dotlottie-player";var version="5.0.1";var description="Web Component for playing Lottie animations in your web app. Previously @johanaarstein/dotlottie-player";var exports={".":{"import":"./dist/index.js",node:"./dist/index.js",types:"./dist/index.d.ts"}};var main="./dist/index.js";var unpkg="./dist/unpkg/index.js";var module="./dist/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.js",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 **/*.css","lint:css:fix":"npx stylelint **/*.css --fix"};var dependencies={"@aarsteinmedia/lottie-web":"^0.2.21",fflate:"^0.8.2","lottie-web":"^5.13.0"};var peerDependencies={"@types/react":">= 16.0.0"};var devDependencies={"@custom-elements-manifest/analyzer":"^0.10.4","@eslint/compat":"^1.2.9","@eslint/js":"^9.27.0","@esm-bundle/chai":"4.3.4-fix.0","@open-wc/testing":"^4.0.0","@rollup/plugin-commonjs":"^28.0.3","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^16.0.1","@rollup/plugin-typescript":"^12.1.2","@swc/core":"^1.11.29","@types/mocha":"^10.0.10","@types/node":"^22.15.21","@types/path-browserify":"^1.0.3","@types/react":"^19.1.5","@web/dev-server-esbuild":"^1.0.4","@web/dev-server-import-maps":"^0.2.1","@web/dev-server-rollup":"^0.6.4","@web/test-runner":"^0.20.2","@web/test-runner-playwright":"^0.11.0",autoprefixer:"^10.4.21",esbuild:"^0.25.4",eslint:"^9.27.0","eslint-config-prettier":"^10.1.5","eslint-import-resolver-typescript":"^4.3.5","eslint-plugin-import":"^2.31.0","eslint-plugin-jsdoc":"^50.6.17","eslint-plugin-perfectionist":"^4.13.0","eslint-plugin-prettier":"^5.4.0",globals:"^16.1.0","postcss-flexbugs-fixes":"^5.0.2",prettier:"^3.5.3",react:"^19.1.0",rimraf:"^6.0.1",rollup:"^4.41.0","rollup-plugin-dts":"^6.2.1","rollup-plugin-html-literals":"^1.1.8","rollup-plugin-livereload":"^2.0.5","rollup-plugin-postcss":"^4.0.2","rollup-plugin-serve":"^3.0.0","rollup-plugin-summary":"^3.0.1","rollup-plugin-swc3":"^0.12.1","rollup-plugin-typescript-paths":"^1.5.0",stylelint:"^16.19.1","stylelint-config-recommended":"^16.0.0","tsc-alias":"^1.8.16",tslib:"^2.8.1",typescript:"^5.8.3","typescript-eslint":"^8.32.1"};var pnpm={onlyBuiltDependencies:["@parcel/watcher","@swc/core","esbuild","unrs-resolver"]};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:">= 12.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,contributors:contributors,license:license,scripts:scripts,dependencies:dependencies,peerDependencies:peerDependencies,devDependencies:devDependencies,pnpm:pnpm,browserslist:browserslist,customElements:customElements$1,files:files,keywords:keywords,publishConfig:publishConfig,engines:engines,funding:funding};
525
546
 
526
547
  var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-toolbar-height: 35px;\n --lottie-player-toolbar-background-color: #fff;\n --lottie-player-toolbar-icon-color: #000;\n --lottie-player-toolbar-icon-hover-color: #000;\n --lottie-player-toolbar-icon-active-color: #4285f4;\n --lottie-player-seeker-track-color: rgb(0 0 0 / 20%);\n --lottie-player-seeker-thumb-color: #4285f4;\n --lottie-player-seeker-display: block;\n\n width: 100%;\n height: 100%;\n\n &:not([hidden]) {\n display: block;\n }\n\n .main {\n display: flex;\n flex-direction: column;\n height: 100%;\n width: 100%;\n margin: 0;\n padding: 0;\n }\n\n .animation {\n width: 100%;\n height: 100%;\n display: flex;\n margin: 0;\n padding: 0;\n }\n\n [data-controls='true'] .animation {\n height: calc(100% - 35px);\n }\n\n .animation-container {\n position: relative;\n }\n\n .popover {\n position: absolute;\n right: 5px;\n bottom: 40px;\n background-color: var(--lottie-player-toolbar-background-color);\n border-radius: 5px;\n padding: 10px 15px;\n border: solid 2px var(--lottie-player-toolbar-icon-color);\n animation: fade-in 0.2s ease-in-out;\n\n &::before {\n content: '';\n right: 10px;\n border: 7px solid transparent;\n margin-right: -7px;\n height: 0;\n width: 0;\n position: absolute;\n pointer-events: none;\n top: 100%;\n border-top-color: var(--lottie-player-toolbar-icon-color);\n }\n }\n\n .error {\n display: flex;\n margin: auto;\n justify-content: center;\n height: 100%;\n align-items: center;\n\n & svg {\n width: 100%;\n height: auto;\n }\n }\n\n .toolbar {\n display: flex;\n place-items: center center;\n background: var(--lottie-player-toolbar-background-color);\n margin: 0;\n height: 35px;\n padding: 5px;\n border-radius: 5px;\n gap: 5px;\n\n &.has-error {\n pointer-events: none;\n opacity: 0.5;\n }\n\n & button {\n cursor: pointer;\n fill: var(--lottie-player-toolbar-icon-color);\n color: var(--lottie-player-toolbar-icon-color);\n background: none;\n border: 0;\n padding: 0;\n outline: 0;\n height: 100%;\n margin: 0;\n align-items: center;\n gap: 5px;\n opacity: 0.9;\n\n &:not([hidden]) {\n display: flex;\n }\n\n &:hover {\n opacity: 1;\n }\n\n &[data-active='true'] {\n opacity: 1;\n fill: var(--lottie-player-toolbar-icon-active-color);\n }\n\n &:disabled {\n opacity: 0.5;\n }\n\n &:focus {\n outline: 0;\n }\n\n & svg {\n pointer-events: none;\n\n & > * {\n fill: inherit;\n }\n }\n\n &.disabled svg {\n display: none;\n }\n }\n }\n\n .progress-container {\n position: relative;\n width: 100%;\n\n &.simple {\n margin-right: 12px;\n }\n }\n\n .seeker {\n appearance: none;\n outline: none;\n width: 100%;\n height: 20px;\n border-radius: 3px;\n border: 0;\n cursor: pointer;\n background-color: transparent;\n\n display: var(--lottie-player-seeker-display);\n color: var(--lottie-player-seeker-thumb-color);\n margin: 0;\n padding: 7.5px 0;\n position: relative;\n z-index: 1;\n\n &::-webkit-slider-runnable-track,\n &::-webkit-slider-thumb {\n appearance: none;\n outline: none;\n }\n\n &::-webkit-slider-thumb {\n height: 15px;\n width: 15px;\n border-radius: 50%;\n border: 0;\n background-color: var(--lottie-player-seeker-thumb-color);\n cursor: pointer;\n -webkit-transition: transform 0.2s ease-in-out;\n transition: transform 0.2s ease-in-out;\n transform: scale(0);\n }\n\n &:hover::-webkit-slider-thumb,\n &:focus::-webkit-slider-thumb {\n transform: scale(1);\n }\n\n &::-moz-range-progress {\n background-color: var(--lottie-player-seeker-thumb-color);\n height: 5px;\n border-radius: 3px;\n }\n\n &::-moz-range-thumb {\n height: 15px;\n width: 15px;\n border-radius: 50%;\n background-color: var(--lottie-player-seeker-thumb-color);\n border: 0;\n cursor: pointer;\n -moz-transition: transform 0.2s ease-in-out;\n transition: transform 0.2s ease-in-out;\n transform: scale(0);\n }\n\n &:hover::-moz-range-thumb,\n &:focus::-moz-range-thumb {\n transform: scale(1);\n }\n\n &::-ms-track {\n width: 100%;\n height: 5px;\n cursor: pointer;\n background: transparent;\n border-color: transparent;\n color: transparent;\n }\n\n &::-ms-fill-upper {\n background: var(--lottie-player-seeker-track-color);\n border-radius: 3px;\n }\n\n &::-ms-fill-lower {\n background-color: var(--lottie-player-seeker-thumb-color);\n border-radius: 3px;\n }\n\n &::-ms-thumb {\n border: 0;\n height: 15px;\n width: 15px;\n border-radius: 50%;\n background: var(--lottie-player-seeker-thumb-color);\n cursor: pointer;\n -ms-transition: transform 0.2s ease-in-out;\n transition: transform 0.2s ease-in-out;\n transform: scale(0);\n }\n\n &:hover::-ms-thumb {\n transform: scale(1);\n }\n\n &:focus {\n &::-ms-thumb {\n transform: scale(1);\n }\n\n &::-ms-fill-lower,\n &::-ms-fill-upper {\n background: var(--lottie-player-seeker-track-color);\n }\n }\n }\n\n & progress {\n appearance: none;\n outline: none;\n position: absolute;\n width: 100%;\n height: 5px;\n border-radius: 3px;\n border: 0;\n top: 0;\n left: 0;\n margin: 7.5px 0;\n background-color: var(--lottie-player-seeker-track-color);\n pointer-events: none;\n\n &::-webkit-progress-inner-element {\n border-radius: 3px;\n overflow: hidden;\n }\n\n &::-webkit-slider-runnable-track {\n background-color: transparent;\n }\n\n &::-webkit-progress-value {\n background-color: var(--lottie-player-seeker-thumb-color);\n }\n }\n\n & *::-moz-progress-bar {\n background-color: var(--lottie-player-seeker-thumb-color);\n }\n}\n\n@keyframes fade-in {\n 0% {\n opacity: 0;\n }\n\n 100% {\n opacity: 1;\n }\n}\n\n@media (prefers-color-scheme: dark) {\n :host {\n --lottie-player-toolbar-background-color: #000;\n --lottie-player-toolbar-icon-color: #fff;\n --lottie-player-toolbar-icon-hover-color: #fff;\n --lottie-player-seeker-track-color: rgb(255 255 255 / 60%);\n }\n}\n";
527
548
 
@@ -531,7 +552,7 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
531
552
  * @class DotLottiePlayer
532
553
  * @extends { EnhancedElement }
533
554
  * @description Web Component for playing Lottie animations in your web app.
534
- */ class DotLottiePlayer extends EnhancedElement {
555
+ */ class DotLottiePlayer extends PropertyCallbackElement {
535
556
  constructor(){
536
557
  super(), this._renderControls = renderControls, this._render = renderPlayer, /**
537
558
  * Multi-animation settings
@@ -549,7 +570,12 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
549
570
  */ this._seeker = 0, /**
550
571
  * @state
551
572
  * Which animation to show, if several
552
- */ 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 = {
573
+ */ this._currentAnimation = 0, /**
574
+ * @state
575
+ * This is included in watched properties,
576
+ * so that next-button will show up
577
+ * on load, if controls are visible
578
+ */ this._animations = [], this._lottieInstance = null, this._identifier = this.id || createElementID(), this._errorMessage = 'Something went wrong', this._isBounce = false, this._isDotLottie = false, this._playerState = {
553
579
  count: 0,
554
580
  loaded: false,
555
581
  prev: PlayerState.Loading,
@@ -926,10 +952,10 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
926
952
  }
927
953
  get renderer() {
928
954
  const val = this.getAttribute('renderer');
929
- if (val === 'canvas' || val === 'html') {
955
+ if (val === RendererType.Canvas || val === RendererType.HTML) {
930
956
  return val;
931
957
  }
932
- return 'svg';
958
+ return RendererType.SVG;
933
959
  }
934
960
  /**
935
961
  * Hide advanced controls
@@ -989,13 +1015,13 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
989
1015
  }
990
1016
  /**
991
1017
  * Set playback segment
992
- * @param { AnimationSegment } settings
1018
+ * @param { Vector2 } segment
993
1019
  */ setSegment(segment) {
994
1020
  this._segment = segment;
995
1021
  }
996
1022
  /**
997
1023
  * Get playback segment
998
- * @returns { AnimationSegment }
1024
+ * @returns { Vector2 }
999
1025
  */ getSegment() {
1000
1026
  return this._segment;
1001
1027
  }
@@ -1006,10 +1032,10 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
1006
1032
  if (!this._container) {
1007
1033
  throw new Error('Container not rendered');
1008
1034
  }
1009
- const preserveAspectRatio = this.preserveAspectRatio ?? (this.objectfit && aspectRatio(this.objectfit)), currentAnimationSettings = this._multiAnimationSettings?.length ? this._multiAnimationSettings?.[this._currentAnimation] : undefined, currentAnimationManifest = this._manifest.animations?.[this._currentAnimation];
1035
+ const preserveAspectRatio = this.preserveAspectRatio ?? (this.objectfit && aspectRatio(this.objectfit)), currentAnimationSettings = this._multiAnimationSettings?.length ? this._multiAnimationSettings?.[this._currentAnimation] : undefined, currentAnimationManifest = this._manifest?.animations[this._currentAnimation];
1010
1036
  // Loop
1011
1037
  let loop = !!this.loop;
1012
- if (currentAnimationManifest.loop !== undefined && this.loop === undefined) {
1038
+ if (currentAnimationManifest?.loop !== undefined && this.loop === undefined) {
1013
1039
  loop = !!currentAnimationManifest.loop;
1014
1040
  }
1015
1041
  if (currentAnimationSettings?.loop !== undefined) {
@@ -1017,7 +1043,7 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
1017
1043
  }
1018
1044
  // Autoplay
1019
1045
  let autoplay = !!this.autoplay;
1020
- if (currentAnimationManifest.autoplay !== undefined && this.autoplay === undefined) {
1046
+ if (currentAnimationManifest?.autoplay !== undefined && this.autoplay === undefined) {
1021
1047
  autoplay = !!currentAnimationManifest.autoplay;
1022
1048
  }
1023
1049
  if (currentAnimationSettings?.autoplay !== undefined) {
@@ -1060,6 +1086,7 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
1060
1086
  options.rendererSettings = {
1061
1087
  ...options.rendererSettings,
1062
1088
  clearCanvas: true,
1089
+ // @ts-expect-error TODO:
1063
1090
  preserveAspectRatio,
1064
1091
  progressiveLoad: true
1065
1092
  };
@@ -1079,8 +1106,9 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
1079
1106
  return;
1080
1107
  }
1081
1108
  this._intersectionObserver = new IntersectionObserver((entries)=>{
1082
- for (const entry of entries){
1083
- if (!entry.isIntersecting || document.hidden) {
1109
+ const { length } = entries;
1110
+ for(let i = 0; i < length; i++){
1111
+ if (!entries[i].isIntersecting || document.hidden) {
1084
1112
  if (this.playerState === PlayerState.Playing) {
1085
1113
  this._freeze();
1086
1114
  }
@@ -1123,7 +1151,7 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
1123
1151
  {
1124
1152
  autoplay: !this.animateOnScroll && this.autoplay,
1125
1153
  direction: this.direction,
1126
- id: useId(),
1154
+ id: createElementID(),
1127
1155
  loop: this.loop,
1128
1156
  mode: this.mode,
1129
1157
  speed: this.speed
@@ -1139,6 +1167,7 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
1139
1167
  this.playerState = PlayerState.Playing;
1140
1168
  }
1141
1169
  // Initialize lottie player and load animation
1170
+ // @ts-expect-error TODO:
1142
1171
  this._lottieInstance = Lottie.default.loadAnimation({
1143
1172
  ...this._getOptions(),
1144
1173
  animationData: animations[this._currentAnimation]
@@ -1150,7 +1179,7 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
1150
1179
  return;
1151
1180
  }
1152
1181
  this._addEventListeners();
1153
- 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;
1182
+ 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;
1154
1183
  // Set initial playback speed and direction
1155
1184
  this._lottieInstance.setSpeed(speed);
1156
1185
  this._lottieInstance.setDirection(direction);
@@ -1398,27 +1427,31 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
1398
1427
  ] : []
1399
1428
  } } = this.src ? await getAnimationData(this.src) : {};
1400
1429
  try {
1430
+ // @ts-expect-error TODO:
1401
1431
  manifest.generator = pkg.name;
1402
- for (const config of configs){
1403
- const { url } = config, { animations: animationsToAdd } = await getAnimationData(url);
1432
+ const { length } = configs;
1433
+ for(let i = 0; i < length; i++){
1434
+ const { url } = configs[i], { animations: animationsToAdd } = await getAnimationData(url);
1404
1435
  if (!animationsToAdd) {
1405
1436
  throw new Error('No animation loaded');
1406
1437
  }
1407
- if (manifest.animations.some(({ id })=>id === config.id)) {
1438
+ if (manifest?.animations.some(({ id })=>id === configs[i].id)) {
1408
1439
  throw new Error('Duplicate id for animation');
1409
1440
  }
1441
+ // @ts-expect-error TODO:
1410
1442
  manifest.animations = [
1411
1443
  ...manifest.animations,
1412
1444
  {
1413
- id: config.id
1445
+ id: configs[i].id
1414
1446
  }
1415
1447
  ];
1416
- animations?.push(...animationsToAdd);
1448
+ animations.push(...animationsToAdd);
1417
1449
  }
1418
1450
  return {
1419
1451
  result: await createDotLottie({
1420
1452
  animations,
1421
1453
  fileName,
1454
+ // @ts-expect-error TODO:
1422
1455
  manifest,
1423
1456
  shouldDownload
1424
1457
  }),
@@ -1696,6 +1729,7 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
1696
1729
  this._lottieInstance.destroy();
1697
1730
  }
1698
1731
  // Re-initialize lottie player
1732
+ // @ts-expect-error TODO:
1699
1733
  this._lottieInstance = Lottie.default.loadAnimation({
1700
1734
  ...this._getOptions(),
1701
1735
  animationData: this._animations[this._currentAnimation]
@@ -1747,7 +1781,7 @@ var css_248z = "* {\n box-sizing: border-box;\n}\n\n:host {\n --lottie-player-
1747
1781
  });
1748
1782
  }
1749
1783
  return createDotLottie({
1750
- animations: animations || (await getAnimationData(this.src))?.animations,
1784
+ animations: animations || (await getAnimationData(this.src)).animations,
1751
1785
  fileName: `${getFilename(fileName || this.src || 'converted')}.lottie`,
1752
1786
  manifest: {
1753
1787
  ...manifest || this._manifest,