Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dotlottie/dotlottie-js

Package Overview
Dependencies
Maintainers
3
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dotlottie/dotlottie-js - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

202

./dist/index.js

@@ -302,3 +302,3 @@ import { strToU8, zip, unzip, strFromU8 } from 'fflate';

name: "@dotlottie/dotlottie-js",
version: "0.1.3",
version: "0.1.4",
type: "module",

@@ -364,3 +364,2 @@ description: "This library helps in creating and modifying .lottie files.",

devDependencies: {
"@lottiefiles/lottie-types": "1.0.1",
"@types/jasmine": "4.3.1",

@@ -433,2 +432,3 @@ "@types/node": "18.0.6",

__publicField(this, "_version");
__publicField(this, "_revision");
__publicField(this, "_customData");

@@ -442,2 +442,3 @@ __publicField(this, "enableDuplicateImageOptimization");

this._customData = options?.customData ?? {};
this._revision = options?.revision ?? 1;
this.enableDuplicateImageOptimization = options?.enableDuplicateImageOptimization ?? false;

@@ -472,2 +473,5 @@ }

}
get revision() {
return this._revision;
}
get author() {

@@ -495,25 +499,29 @@ return this._author;

setCustomData(customData) {
this._customData = customData;
this._customData = customData ?? {};
return this;
}
setAuthor(author) {
this._author = author;
this._author = author ?? "LottieFiles";
return this;
}
setDescription(description) {
this._description = description;
this._description = description ?? "";
return this;
}
setGenerator(generator) {
this._generator = generator;
this._generator = generator ?? `${package_default.name}@${package_default.version}`;
return this;
}
setKeywords(keywords) {
this._keywords = keywords;
this._keywords = keywords ?? "dotLottie";
return this;
}
setVersion(version) {
this._version = version;
this._version = version ?? "1.0";
return this;
}
setRevision(revision) {
this._revision = revision;
return this;
}
removePlugins(...plugins) {

@@ -623,2 +631,3 @@ plugins.forEach((plugin) => {

version: this.version,
revision: this.revision,
keywords: this.keywords,

@@ -633,3 +642,5 @@ author: this.author,

loop: animation.loop,
autoplay: animation.autoplay
autoplay: animation.autoplay,
hover: animation.hover,
intermission: animation.intermission
})),

@@ -705,2 +716,26 @@ ...this.description && this.description.trim() !== "" ? { description: this.description } : {},

}
_requireValidAuthor(author) {
if (!author)
throw createError("Invalid author");
}
_requireValidDescription(description) {
if (!description)
throw createError("Invalid description");
}
_requireValidGenerator(generator) {
if (!generator)
throw createError("Invalid generator");
}
_requireValidKeywords(keywords) {
if (!keywords)
throw createError("Invalid keywords");
}
_requireValidVersion(version) {
if (!version)
throw createError("Invalid version");
}
_requireValidCustomData(customData) {
if (!customData)
throw createError("Invalid customData");
}
};

@@ -719,2 +754,4 @@

__publicField(this, "_autoplay");
__publicField(this, "_hover");
__publicField(this, "_intermission");
__publicField(this, "_defaultActiveAnimation");

@@ -734,2 +771,4 @@ __publicField(this, "_imageAssets", []);

this._defaultActiveAnimation = options.defaultActiveAnimation ?? false;
this._hover = options.hover ?? false;
this._intermission = options.intermission ?? 0;
}

@@ -788,2 +827,3 @@ async toBase64() {

set loop(loop) {
this._requireValidLoop(loop);
this._loop = loop;

@@ -803,2 +843,15 @@ }

}
get hover() {
return this._hover;
}
set hover(hover) {
this._hover = hover;
}
get intermission() {
return this._intermission;
}
set intermission(intermission) {
this._requireValidIntermission(intermission);
this._intermission = intermission;
}
async toArrayBuffer(options = {}) {

@@ -879,2 +932,12 @@ const dataJson = await this.toJSON(options);

}
_requireValidIntermission(intermission) {
if (intermission < 0 || !Number.isInteger(intermission)) {
throw createError("intermission must be a positive number");
}
}
_requireValidLoop(loop) {
if (typeof loop === "number" && (!Number.isInteger(loop) || loop < 0)) {
throw createError("loop must be a positive number or boolean");
}
}
_requireValidOptions(options) {

@@ -894,2 +957,8 @@ this._requireValidId(options.id);

}
if (options.intermission) {
this._requireValidIntermission(options.intermission);
}
if (options.loop) {
this._requireValidLoop(options.loop);
}
}

@@ -1762,45 +1831,74 @@ };

const tmpImages = [];
for (const key of Object.keys(contentObj)) {
const decodedStr = strFromU8(contentObj[key], true);
if (key === "manifest.json") {
const { author, description, generator, version } = JSON.parse(decodedStr);
dotlottie.setVersion(version);
dotlottie.setDescription(description);
dotlottie.setAuthor(author);
dotlottie.setGenerator(generator);
} else if (key.startsWith("animations/") && key.endsWith(".json")) {
const animationId = /animations\/(.+)\.json/u.exec(key)?.[1];
if (!animationId) {
throw createError("Invalid animation id");
if (contentObj["manifest.json"] instanceof Uint8Array) {
try {
const manifest = JSON.parse(strFromU8(contentObj["manifest.json"], false));
const { author, custom, description, generator, keywords, version } = manifest;
if (author) {
this._requireValidAuthor(author);
dotlottie.setAuthor(author);
}
const animation = JSON.parse(decodedStr);
dotlottie.addAnimation({
id: animationId,
data: animation
});
} else if (key.startsWith("images/")) {
const imageId = /images\/(.+)\./u.exec(key)?.[1];
if (!imageId) {
throw createError("Invalid image id");
if (custom) {
this._requireValidCustomData(custom);
dotlottie.setCustomData(custom);
}
let decodedImg = btoa(decodedStr);
const ext = getExtensionTypeFromBase64(decodedImg);
decodedImg = `data:image/${ext};base64,${decodedImg}`;
tmpImages.push(new LottieImage({
id: imageId,
data: decodedImg,
fileName: key.split("/")[1] || ""
}));
}
}
for (const image of tmpImages) {
for (const parentAnimation of dotlottie.animations) {
if (parentAnimation.data) {
const animationAssets = parentAnimation.data.assets;
if (animationAssets) {
for (const asset of animationAssets) {
if ("w" in asset && "h" in asset) {
if (asset.p.includes(image.id)) {
image.parentAnimations.push(parentAnimation);
parentAnimation.imageAssets.push(image);
if (description) {
this._requireValidDescription(description);
dotlottie.setDescription(description);
}
if (generator) {
this._requireValidGenerator(generator);
dotlottie.setGenerator(generator);
}
if (keywords) {
this._requireValidKeywords(keywords);
dotlottie.setKeywords(keywords);
}
if (version) {
this._requireValidVersion(version);
dotlottie.setVersion(version);
}
for (const key of Object.keys(contentObj)) {
const decodedStr = strFromU8(contentObj[key], true);
if (key.startsWith("animations/") && key.endsWith(".json")) {
const animationId = /animations\/(.+)\.json/u.exec(key)?.[1];
if (!animationId) {
throw createError("Invalid animation id");
}
const animation = JSON.parse(decodedStr);
const animationSettings = manifest["animations"].find((anim) => anim.id === animationId);
if (animationSettings === void 0) {
throw createError("Animation not found inside manifest");
}
dotlottie.addAnimation({
id: animationId,
data: animation,
...animationSettings
});
} else if (key.startsWith("images/")) {
const imageId = /images\/(.+)\./u.exec(key)?.[1];
if (!imageId) {
throw createError("Invalid image id");
}
let decodedImg = btoa(decodedStr);
const ext = getExtensionTypeFromBase64(decodedImg);
decodedImg = `data:image/${ext};base64,${decodedImg}`;
tmpImages.push(new LottieImage({
id: imageId,
data: decodedImg,
fileName: key.split("/")[1] || ""
}));
}
}
for (const image of tmpImages) {
for (const parentAnimation of dotlottie.animations) {
if (parentAnimation.data) {
const animationAssets = parentAnimation.data.assets;
if (animationAssets) {
for (const asset of animationAssets) {
if ("w" in asset && "h" in asset) {
if (asset.p.includes(image.id)) {
image.parentAnimations.push(parentAnimation);
parentAnimation.imageAssets.push(image);
}
}
}

@@ -1811,3 +1909,7 @@ }

}
} catch (err) {
throw createError("Invalid manifest inside buffer!");
}
} else {
throw createError("Invalid buffer");
}

@@ -1814,0 +1916,0 @@ } catch (err) {

@@ -1,3 +0,1 @@

import { Animation } from '@lottiefiles/lottie-types';
/**

@@ -89,4 +87,6 @@ * Copyright 2023 Design Barn Inc.

direction?: number;
hover?: boolean;
id: string;
loop?: boolean;
intermission?: number;
loop?: boolean | number;
playMode?: PlayMode;

@@ -130,2 +130,4 @@ speed?: number;

private _autoplay;
private _hover;
private _intermission;
protected _defaultActiveAnimation: boolean;

@@ -149,4 +151,4 @@ protected _imageAssets: LottieImageCommon[];

set playMode(playMode: PlayMode);
get loop(): boolean;
set loop(loop: boolean);
get loop(): boolean | number;
set loop(loop: boolean | number);
get autoplay(): boolean;

@@ -156,2 +158,6 @@ set autoplay(autoplay: boolean);

set defaultActiveAnimation(defaultActiveAnimation: boolean);
get hover(): boolean;
set hover(hover: boolean);
get intermission(): number;
set intermission(intermission: number);
/**

@@ -222,2 +228,14 @@ * Return the animation data as an array buffer.

/**
* Ensure that the provided intermission is a valid, positive number.
* @param intermission - The intermission to validate.
* @throws Error - if the intermission is not a valid number.
*/
private _requireValidIntermission;
/**
* Ensure that the provided loop is a valid, positive number or boolean.
* @param loop - The loop to validate.
* @throws Error - if the loop is not a valid number or boolean.
*/
private _requireValidLoop;
/**
* Ensure that the provided options object is a valid AnimationOptions object.

@@ -248,2 +266,3 @@ * The options object must contain the following mandatory properties: id, data or url.

plugins?: DotLottiePlugin[];
revision?: number;
version?: string;

@@ -262,2 +281,3 @@ }

protected _version?: string;
protected _revision?: number;
protected _customData?: Record<string, unknown>;

@@ -275,2 +295,3 @@ enableDuplicateImageOptimization?: boolean;

get version(): string | undefined;
get revision(): number | undefined;
get author(): string | undefined;

@@ -283,8 +304,9 @@ get description(): string | undefined;

get custom(): Record<string, unknown> | undefined;
setCustomData(customData: Record<string, unknown>): DotLottieCommon;
setAuthor(author: string): DotLottieCommon;
setDescription(description: string): DotLottieCommon;
setGenerator(generator: string): DotLottieCommon;
setKeywords(keywords: string): DotLottieCommon;
setVersion(version: string): DotLottieCommon;
setCustomData(customData: Record<string, unknown> | undefined): DotLottieCommon;
setAuthor(author: string | undefined): DotLottieCommon;
setDescription(description: string | undefined): DotLottieCommon;
setGenerator(generator: string | undefined): DotLottieCommon;
setKeywords(keywords: string | undefined): DotLottieCommon;
setVersion(version: string | undefined): DotLottieCommon;
setRevision(revision: number): DotLottieCommon;
removePlugins(...plugins: DotLottiePlugin[]): DotLottieCommon;

@@ -331,2 +353,8 @@ /**

merge(...dotlotties: DotLottieCommon[]): DotLottieCommon;
protected _requireValidAuthor(author: string | undefined): asserts author is string;
protected _requireValidDescription(description: string | undefined): asserts description is string;
protected _requireValidGenerator(generator: string | undefined): asserts generator is string;
protected _requireValidKeywords(keywords: string | undefined): asserts keywords is string;
protected _requireValidVersion(version: string | undefined): asserts version is string;
protected _requireValidCustomData(customData: Record<string, unknown> | undefined): asserts customData is Record<string, unknown>;
}

@@ -333,0 +361,0 @@

@@ -302,3 +302,3 @@ import { strToU8, zip, unzip, strFromU8 } from 'fflate';

name: "@dotlottie/dotlottie-js",
version: "0.1.3",
version: "0.1.4",
type: "module",

@@ -364,3 +364,2 @@ description: "This library helps in creating and modifying .lottie files.",

devDependencies: {
"@lottiefiles/lottie-types": "1.0.1",
"@types/jasmine": "4.3.1",

@@ -433,2 +432,3 @@ "@types/node": "18.0.6",

__publicField(this, "_version");
__publicField(this, "_revision");
__publicField(this, "_customData");

@@ -442,2 +442,3 @@ __publicField(this, "enableDuplicateImageOptimization");

this._customData = options?.customData ?? {};
this._revision = options?.revision ?? 1;
this.enableDuplicateImageOptimization = options?.enableDuplicateImageOptimization ?? false;

@@ -472,2 +473,5 @@ }

}
get revision() {
return this._revision;
}
get author() {

@@ -495,25 +499,29 @@ return this._author;

setCustomData(customData) {
this._customData = customData;
this._customData = customData ?? {};
return this;
}
setAuthor(author) {
this._author = author;
this._author = author ?? "LottieFiles";
return this;
}
setDescription(description) {
this._description = description;
this._description = description ?? "";
return this;
}
setGenerator(generator) {
this._generator = generator;
this._generator = generator ?? `${package_default.name}@${package_default.version}`;
return this;
}
setKeywords(keywords) {
this._keywords = keywords;
this._keywords = keywords ?? "dotLottie";
return this;
}
setVersion(version) {
this._version = version;
this._version = version ?? "1.0";
return this;
}
setRevision(revision) {
this._revision = revision;
return this;
}
removePlugins(...plugins) {

@@ -623,2 +631,3 @@ plugins.forEach((plugin) => {

version: this.version,
revision: this.revision,
keywords: this.keywords,

@@ -633,3 +642,5 @@ author: this.author,

loop: animation.loop,
autoplay: animation.autoplay
autoplay: animation.autoplay,
hover: animation.hover,
intermission: animation.intermission
})),

@@ -705,2 +716,26 @@ ...this.description && this.description.trim() !== "" ? { description: this.description } : {},

}
_requireValidAuthor(author) {
if (!author)
throw createError("Invalid author");
}
_requireValidDescription(description) {
if (!description)
throw createError("Invalid description");
}
_requireValidGenerator(generator) {
if (!generator)
throw createError("Invalid generator");
}
_requireValidKeywords(keywords) {
if (!keywords)
throw createError("Invalid keywords");
}
_requireValidVersion(version) {
if (!version)
throw createError("Invalid version");
}
_requireValidCustomData(customData) {
if (!customData)
throw createError("Invalid customData");
}
};

@@ -719,2 +754,4 @@

__publicField(this, "_autoplay");
__publicField(this, "_hover");
__publicField(this, "_intermission");
__publicField(this, "_defaultActiveAnimation");

@@ -734,2 +771,4 @@ __publicField(this, "_imageAssets", []);

this._defaultActiveAnimation = options.defaultActiveAnimation ?? false;
this._hover = options.hover ?? false;
this._intermission = options.intermission ?? 0;
}

@@ -788,2 +827,3 @@ async toBase64() {

set loop(loop) {
this._requireValidLoop(loop);
this._loop = loop;

@@ -803,2 +843,15 @@ }

}
get hover() {
return this._hover;
}
set hover(hover) {
this._hover = hover;
}
get intermission() {
return this._intermission;
}
set intermission(intermission) {
this._requireValidIntermission(intermission);
this._intermission = intermission;
}
async toArrayBuffer(options = {}) {

@@ -879,2 +932,12 @@ const dataJson = await this.toJSON(options);

}
_requireValidIntermission(intermission) {
if (intermission < 0 || !Number.isInteger(intermission)) {
throw createError("intermission must be a positive number");
}
}
_requireValidLoop(loop) {
if (typeof loop === "number" && (!Number.isInteger(loop) || loop < 0)) {
throw createError("loop must be a positive number or boolean");
}
}
_requireValidOptions(options) {

@@ -894,2 +957,8 @@ this._requireValidId(options.id);

}
if (options.intermission) {
this._requireValidIntermission(options.intermission);
}
if (options.loop) {
this._requireValidLoop(options.loop);
}
}

@@ -1762,45 +1831,74 @@ };

const tmpImages = [];
for (const key of Object.keys(contentObj)) {
const decodedStr = strFromU8(contentObj[key], true);
if (key === "manifest.json") {
const { author, description, generator, version } = JSON.parse(decodedStr);
dotlottie.setVersion(version);
dotlottie.setDescription(description);
dotlottie.setAuthor(author);
dotlottie.setGenerator(generator);
} else if (key.startsWith("animations/") && key.endsWith(".json")) {
const animationId = /animations\/(.+)\.json/u.exec(key)?.[1];
if (!animationId) {
throw createError("Invalid animation id");
if (contentObj["manifest.json"] instanceof Uint8Array) {
try {
const manifest = JSON.parse(strFromU8(contentObj["manifest.json"], false));
const { author, custom, description, generator, keywords, version } = manifest;
if (author) {
this._requireValidAuthor(author);
dotlottie.setAuthor(author);
}
const animation = JSON.parse(decodedStr);
dotlottie.addAnimation({
id: animationId,
data: animation
});
} else if (key.startsWith("images/")) {
const imageId = /images\/(.+)\./u.exec(key)?.[1];
if (!imageId) {
throw createError("Invalid image id");
if (custom) {
this._requireValidCustomData(custom);
dotlottie.setCustomData(custom);
}
let decodedImg = btoa(decodedStr);
const ext = getExtensionTypeFromBase64(decodedImg);
decodedImg = `data:image/${ext};base64,${decodedImg}`;
tmpImages.push(new LottieImage({
id: imageId,
data: decodedImg,
fileName: key.split("/")[1] || ""
}));
}
}
for (const image of tmpImages) {
for (const parentAnimation of dotlottie.animations) {
if (parentAnimation.data) {
const animationAssets = parentAnimation.data.assets;
if (animationAssets) {
for (const asset of animationAssets) {
if ("w" in asset && "h" in asset) {
if (asset.p.includes(image.id)) {
image.parentAnimations.push(parentAnimation);
parentAnimation.imageAssets.push(image);
if (description) {
this._requireValidDescription(description);
dotlottie.setDescription(description);
}
if (generator) {
this._requireValidGenerator(generator);
dotlottie.setGenerator(generator);
}
if (keywords) {
this._requireValidKeywords(keywords);
dotlottie.setKeywords(keywords);
}
if (version) {
this._requireValidVersion(version);
dotlottie.setVersion(version);
}
for (const key of Object.keys(contentObj)) {
const decodedStr = strFromU8(contentObj[key], true);
if (key.startsWith("animations/") && key.endsWith(".json")) {
const animationId = /animations\/(.+)\.json/u.exec(key)?.[1];
if (!animationId) {
throw createError("Invalid animation id");
}
const animation = JSON.parse(decodedStr);
const animationSettings = manifest["animations"].find((anim) => anim.id === animationId);
if (animationSettings === void 0) {
throw createError("Animation not found inside manifest");
}
dotlottie.addAnimation({
id: animationId,
data: animation,
...animationSettings
});
} else if (key.startsWith("images/")) {
const imageId = /images\/(.+)\./u.exec(key)?.[1];
if (!imageId) {
throw createError("Invalid image id");
}
let decodedImg = btoa(decodedStr);
const ext = getExtensionTypeFromBase64(decodedImg);
decodedImg = `data:image/${ext};base64,${decodedImg}`;
tmpImages.push(new LottieImage({
id: imageId,
data: decodedImg,
fileName: key.split("/")[1] || ""
}));
}
}
for (const image of tmpImages) {
for (const parentAnimation of dotlottie.animations) {
if (parentAnimation.data) {
const animationAssets = parentAnimation.data.assets;
if (animationAssets) {
for (const asset of animationAssets) {
if ("w" in asset && "h" in asset) {
if (asset.p.includes(image.id)) {
image.parentAnimations.push(parentAnimation);
parentAnimation.imageAssets.push(image);
}
}
}

@@ -1811,3 +1909,7 @@ }

}
} catch (err) {
throw createError("Invalid manifest inside buffer!");
}
} else {
throw createError("Invalid buffer");
}

@@ -1814,0 +1916,0 @@ } catch (err) {

@@ -1,3 +0,1 @@

import { Animation } from '@lottiefiles/lottie-types';
/**

@@ -89,4 +87,6 @@ * Copyright 2023 Design Barn Inc.

direction?: number;
hover?: boolean;
id: string;
loop?: boolean;
intermission?: number;
loop?: boolean | number;
playMode?: PlayMode;

@@ -130,2 +130,4 @@ speed?: number;

private _autoplay;
private _hover;
private _intermission;
protected _defaultActiveAnimation: boolean;

@@ -149,4 +151,4 @@ protected _imageAssets: LottieImageCommon[];

set playMode(playMode: PlayMode);
get loop(): boolean;
set loop(loop: boolean);
get loop(): boolean | number;
set loop(loop: boolean | number);
get autoplay(): boolean;

@@ -156,2 +158,6 @@ set autoplay(autoplay: boolean);

set defaultActiveAnimation(defaultActiveAnimation: boolean);
get hover(): boolean;
set hover(hover: boolean);
get intermission(): number;
set intermission(intermission: number);
/**

@@ -222,2 +228,14 @@ * Return the animation data as an array buffer.

/**
* Ensure that the provided intermission is a valid, positive number.
* @param intermission - The intermission to validate.
* @throws Error - if the intermission is not a valid number.
*/
private _requireValidIntermission;
/**
* Ensure that the provided loop is a valid, positive number or boolean.
* @param loop - The loop to validate.
* @throws Error - if the loop is not a valid number or boolean.
*/
private _requireValidLoop;
/**
* Ensure that the provided options object is a valid AnimationOptions object.

@@ -248,2 +266,3 @@ * The options object must contain the following mandatory properties: id, data or url.

plugins?: DotLottiePlugin[];
revision?: number;
version?: string;

@@ -262,2 +281,3 @@ }

protected _version?: string;
protected _revision?: number;
protected _customData?: Record<string, unknown>;

@@ -275,2 +295,3 @@ enableDuplicateImageOptimization?: boolean;

get version(): string | undefined;
get revision(): number | undefined;
get author(): string | undefined;

@@ -283,8 +304,9 @@ get description(): string | undefined;

get custom(): Record<string, unknown> | undefined;
setCustomData(customData: Record<string, unknown>): DotLottieCommon;
setAuthor(author: string): DotLottieCommon;
setDescription(description: string): DotLottieCommon;
setGenerator(generator: string): DotLottieCommon;
setKeywords(keywords: string): DotLottieCommon;
setVersion(version: string): DotLottieCommon;
setCustomData(customData: Record<string, unknown> | undefined): DotLottieCommon;
setAuthor(author: string | undefined): DotLottieCommon;
setDescription(description: string | undefined): DotLottieCommon;
setGenerator(generator: string | undefined): DotLottieCommon;
setKeywords(keywords: string | undefined): DotLottieCommon;
setVersion(version: string | undefined): DotLottieCommon;
setRevision(revision: number): DotLottieCommon;
removePlugins(...plugins: DotLottiePlugin[]): DotLottieCommon;

@@ -331,2 +353,8 @@ /**

merge(...dotlotties: DotLottieCommon[]): DotLottieCommon;
protected _requireValidAuthor(author: string | undefined): asserts author is string;
protected _requireValidDescription(description: string | undefined): asserts description is string;
protected _requireValidGenerator(generator: string | undefined): asserts generator is string;
protected _requireValidKeywords(keywords: string | undefined): asserts keywords is string;
protected _requireValidVersion(version: string | undefined): asserts version is string;
protected _requireValidCustomData(customData: Record<string, unknown> | undefined): asserts customData is Record<string, unknown>;
}

@@ -333,0 +361,0 @@

@@ -14,3 +14,3 @@ import { strToU8, zip, unzip, strFromU8 } from 'fflate';

name: "@dotlottie/dotlottie-js",
version: "0.1.3",
version: "0.1.4",
type: "module",

@@ -76,3 +76,2 @@ description: "This library helps in creating and modifying .lottie files.",

devDependencies: {
"@lottiefiles/lottie-types": "1.0.1",
"@types/jasmine": "4.3.1",

@@ -145,2 +144,3 @@ "@types/node": "18.0.6",

__publicField(this, "_version");
__publicField(this, "_revision");
__publicField(this, "_customData");

@@ -154,2 +154,3 @@ __publicField(this, "enableDuplicateImageOptimization");

this._customData = options?.customData ?? {};
this._revision = options?.revision ?? 1;
this.enableDuplicateImageOptimization = options?.enableDuplicateImageOptimization ?? false;

@@ -184,2 +185,5 @@ }

}
get revision() {
return this._revision;
}
get author() {

@@ -207,25 +211,29 @@ return this._author;

setCustomData(customData) {
this._customData = customData;
this._customData = customData ?? {};
return this;
}
setAuthor(author) {
this._author = author;
this._author = author ?? "LottieFiles";
return this;
}
setDescription(description) {
this._description = description;
this._description = description ?? "";
return this;
}
setGenerator(generator) {
this._generator = generator;
this._generator = generator ?? `${package_default.name}@${package_default.version}`;
return this;
}
setKeywords(keywords) {
this._keywords = keywords;
this._keywords = keywords ?? "dotLottie";
return this;
}
setVersion(version) {
this._version = version;
this._version = version ?? "1.0";
return this;
}
setRevision(revision) {
this._revision = revision;
return this;
}
removePlugins(...plugins) {

@@ -335,2 +343,3 @@ plugins.forEach((plugin) => {

version: this.version,
revision: this.revision,
keywords: this.keywords,

@@ -345,3 +354,5 @@ author: this.author,

loop: animation.loop,
autoplay: animation.autoplay
autoplay: animation.autoplay,
hover: animation.hover,
intermission: animation.intermission
})),

@@ -417,2 +428,26 @@ ...this.description && this.description.trim() !== "" ? { description: this.description } : {},

}
_requireValidAuthor(author) {
if (!author)
throw createError("Invalid author");
}
_requireValidDescription(description) {
if (!description)
throw createError("Invalid description");
}
_requireValidGenerator(generator) {
if (!generator)
throw createError("Invalid generator");
}
_requireValidKeywords(keywords) {
if (!keywords)
throw createError("Invalid keywords");
}
_requireValidVersion(version) {
if (!version)
throw createError("Invalid version");
}
_requireValidCustomData(customData) {
if (!customData)
throw createError("Invalid customData");
}
};

@@ -431,2 +466,4 @@

__publicField(this, "_autoplay");
__publicField(this, "_hover");
__publicField(this, "_intermission");
__publicField(this, "_defaultActiveAnimation");

@@ -446,2 +483,4 @@ __publicField(this, "_imageAssets", []);

this._defaultActiveAnimation = options.defaultActiveAnimation ?? false;
this._hover = options.hover ?? false;
this._intermission = options.intermission ?? 0;
}

@@ -500,2 +539,3 @@ async toBase64() {

set loop(loop) {
this._requireValidLoop(loop);
this._loop = loop;

@@ -515,2 +555,15 @@ }

}
get hover() {
return this._hover;
}
set hover(hover) {
this._hover = hover;
}
get intermission() {
return this._intermission;
}
set intermission(intermission) {
this._requireValidIntermission(intermission);
this._intermission = intermission;
}
async toArrayBuffer(options = {}) {

@@ -591,2 +644,12 @@ const dataJson = await this.toJSON(options);

}
_requireValidIntermission(intermission) {
if (intermission < 0 || !Number.isInteger(intermission)) {
throw createError("intermission must be a positive number");
}
}
_requireValidLoop(loop) {
if (typeof loop === "number" && (!Number.isInteger(loop) || loop < 0)) {
throw createError("loop must be a positive number or boolean");
}
}
_requireValidOptions(options) {

@@ -606,2 +669,8 @@ this._requireValidId(options.id);

}
if (options.intermission) {
this._requireValidIntermission(options.intermission);
}
if (options.loop) {
this._requireValidLoop(options.loop);
}
}

@@ -1024,2 +1093,5 @@ };

const animation = new LottieAnimation(animationOptions);
if (this._animationsMap.get(animationOptions.id)) {
throw createError("Duplicate animation id detected, aborting.");
}
this._animationsMap.set(animation.id, animation);

@@ -1065,45 +1137,74 @@ return this;

const tmpImages = [];
for (const key of Object.keys(contentObj)) {
const decodedStr = strFromU8(contentObj[key], false);
if (key === "manifest.json") {
const { author, description, generator, version } = JSON.parse(decodedStr);
dotlottie.setVersion(version);
dotlottie.setDescription(description);
dotlottie.setAuthor(author);
dotlottie.setGenerator(generator);
} else if (key.startsWith("animations/") && key.endsWith(".json")) {
const animationId = /animations\/(.+)\.json/u.exec(key)?.[1];
if (!animationId) {
throw createError("Invalid animation id");
if (contentObj["manifest.json"] instanceof Uint8Array) {
try {
const manifest = JSON.parse(strFromU8(contentObj["manifest.json"]));
const { author, custom, description, generator, keywords, version } = manifest;
if (author) {
this._requireValidAuthor(author);
dotlottie.setAuthor(author);
}
const animation = JSON.parse(decodedStr);
dotlottie.addAnimation({
id: animationId,
data: animation
});
} else if (key.startsWith("images/")) {
const imageId = /images\/(.+)\./u.exec(key)?.[1];
if (!imageId) {
throw createError("Invalid image id");
if (custom) {
this._requireValidCustomData(custom);
dotlottie.setCustomData(custom);
}
let decodedImg = Buffer.from(decodedStr).toString("base64");
const ext = getExtensionTypeFromBase64(decodedImg);
decodedImg = `data:image/${ext};base64,${decodedImg}`;
tmpImages.push(new LottieImage2({
id: imageId,
data: decodedImg,
fileName: key.split("/")[1] || ""
}));
}
}
for (const image of tmpImages) {
for (const parentAnimation of dotlottie.animations) {
if (parentAnimation.data) {
const animationAssets = parentAnimation.data.assets;
if (animationAssets) {
for (const asset of animationAssets) {
if ("w" in asset && "h" in asset) {
if (asset.p.includes(image.id)) {
image.parentAnimations.push(parentAnimation);
parentAnimation.imageAssets.push(image);
if (description) {
this._requireValidDescription(description);
dotlottie.setDescription(description);
}
if (generator) {
this._requireValidGenerator(generator);
dotlottie.setGenerator(generator);
}
if (keywords) {
this._requireValidKeywords(keywords);
dotlottie.setKeywords(keywords);
}
if (version) {
this._requireValidVersion(version);
dotlottie.setVersion(version);
}
for (const key of Object.keys(contentObj)) {
const decodedStr = strFromU8(contentObj[key], false);
if (key.startsWith("animations/") && key.endsWith(".json")) {
const animationId = /animations\/(.+)\.json/u.exec(key)?.[1];
if (!animationId) {
throw createError("Invalid animation id");
}
const animation = JSON.parse(decodedStr);
const animationSettings = manifest["animations"].find((anim) => anim.id === animationId);
if (animationSettings === void 0) {
throw createError("Animation not found inside manifest");
}
dotlottie.addAnimation({
id: animationId,
data: animation,
...animationSettings
});
} else if (key.startsWith("images/")) {
const imageId = /images\/(.+)\./u.exec(key)?.[1];
if (!imageId) {
throw createError("Invalid image id");
}
let decodedImg = Buffer.from(decodedStr).toString("base64");
const ext = getExtensionTypeFromBase64(decodedImg);
decodedImg = `data:image/${ext};base64,${decodedImg}`;
tmpImages.push(new LottieImage2({
id: imageId,
data: decodedImg,
fileName: key.split("/")[1] || ""
}));
}
}
for (const image of tmpImages) {
for (const parentAnimation of dotlottie.animations) {
if (parentAnimation.data) {
const animationAssets = parentAnimation.data.assets;
if (animationAssets) {
for (const asset of animationAssets) {
if ("w" in asset && "h" in asset) {
if (asset.p.includes(image.id)) {
image.parentAnimations.push(parentAnimation);
parentAnimation.imageAssets.push(image);
}
}
}

@@ -1114,3 +1215,7 @@ }

}
} catch (err) {
throw createError("node Invalid manifest inside buffer!");
}
} else {
throw createError("node Invalid buffer");
}

@@ -1117,0 +1222,0 @@ } catch (err) {

{
"name": "@dotlottie/dotlottie-js",
"version": "0.1.3",
"version": "0.1.4",
"type": "module",

@@ -48,3 +48,2 @@ "description": "This library helps in creating and modifying .lottie files.",

"devDependencies": {
"@lottiefiles/lottie-types": "1.0.1",
"@types/jasmine": "4.3.1",

@@ -51,0 +50,0 @@ "@types/node": "18.0.6",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc