@dotlottie/dotlottie-js
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -0,1 +1,2 @@ | ||
import { ZipOptions } from 'fflate'; | ||
import { Animation } from '@lottiefiles/lottie-types'; | ||
@@ -33,2 +34,3 @@ | ||
url?: string; | ||
zipOptions?: ZipOptions; | ||
} | ||
@@ -41,3 +43,6 @@ declare class LottieImageCommon { | ||
protected _parentAnimations: LottieAnimationCommon[]; | ||
protected _zipOptions: ZipOptions; | ||
constructor(options: ImageOptions); | ||
get zipOptions(): ZipOptions; | ||
set zipOptions(zipOptions: ZipOptions); | ||
/** | ||
@@ -129,2 +134,3 @@ * Ensure that the provided id is a valid string. | ||
url?: string; | ||
zipOptions?: ZipOptions; | ||
} | ||
@@ -142,2 +148,3 @@ declare class LottieAnimationCommon { | ||
private _intermission; | ||
private _zipOptions; | ||
protected _defaultActiveAnimation: boolean; | ||
@@ -149,2 +156,4 @@ protected _imageAssets: LottieImageCommon[]; | ||
toBase64(): Promise<string>; | ||
get zipOptions(): ZipOptions; | ||
set zipOptions(zipOptions: ZipOptions); | ||
get id(): string; | ||
@@ -278,2 +287,3 @@ set id(id: string); | ||
url?: string; | ||
zipOptions?: ZipOptions; | ||
} | ||
@@ -285,3 +295,6 @@ declare class LottieThemeCommon { | ||
protected readonly _animationsMap: Map<string, LottieAnimationCommon>; | ||
protected _zipOptions: ZipOptions; | ||
constructor(options: ThemeOptions); | ||
get zipOptions(): ZipOptions; | ||
set zipOptions(zipOptions: ZipOptions); | ||
get id(): string; | ||
@@ -321,2 +334,5 @@ set id(id: string | undefined); | ||
} | ||
interface ConversionOptions { | ||
zipOptions?: ZipOptions; | ||
} | ||
declare class DotLottieCommon { | ||
@@ -335,9 +351,9 @@ protected readonly _animationsMap: Map<string, LottieAnimationCommon>; | ||
constructor(options?: DotLottieOptions); | ||
toBase64(): Promise<string>; | ||
toBase64(_options?: ConversionOptions | undefined): Promise<string>; | ||
create(_options?: DotLottieOptions): DotLottieCommon; | ||
download(_fileName: string): Promise<void>; | ||
download(_fileName: string, _options?: ConversionOptions | undefined): Promise<void>; | ||
addPlugins(..._plugins: DotLottiePlugin[]): DotLottieCommon; | ||
addAnimation(_animationOptions: AnimationOptions): DotLottieCommon; | ||
fromArrayBuffer(_arrayBuffer: ArrayBuffer): Promise<DotLottieCommon>; | ||
toArrayBuffer(): Promise<ArrayBuffer>; | ||
toArrayBuffer(_options?: ConversionOptions | undefined): Promise<ArrayBuffer>; | ||
get plugins(): DotLottiePlugin[]; | ||
@@ -395,3 +411,3 @@ get version(): string | undefined; | ||
build(): Promise<DotLottieCommon>; | ||
toBlob(): Promise<Blob>; | ||
toBlob(options?: ConversionOptions | undefined): Promise<Blob>; | ||
/** | ||
@@ -430,6 +446,6 @@ * Creates a DotLottie instance from a url to a dotlottie file | ||
addAnimation(animationOptions: AnimationOptions): DotLottie; | ||
toBase64(): Promise<string>; | ||
download(fileName: string): Promise<void>; | ||
toBase64(options: ConversionOptions | undefined): Promise<string>; | ||
download(fileName: string, options?: ConversionOptions | undefined): Promise<void>; | ||
create(options?: DotLottieOptions): DotLottieCommon; | ||
toArrayBuffer(): Promise<ArrayBuffer>; | ||
toArrayBuffer(options: ConversionOptions | undefined): Promise<ArrayBuffer>; | ||
/** | ||
@@ -436,0 +452,0 @@ * Creates a DotLottie instance from an array buffer |
@@ -0,1 +1,2 @@ | ||
import { ZipOptions } from 'fflate'; | ||
import { Animation } from '@lottiefiles/lottie-types'; | ||
@@ -33,2 +34,3 @@ | ||
url?: string; | ||
zipOptions?: ZipOptions; | ||
} | ||
@@ -41,3 +43,6 @@ declare class LottieImageCommon { | ||
protected _parentAnimations: LottieAnimationCommon[]; | ||
protected _zipOptions: ZipOptions; | ||
constructor(options: ImageOptions); | ||
get zipOptions(): ZipOptions; | ||
set zipOptions(zipOptions: ZipOptions); | ||
/** | ||
@@ -129,2 +134,3 @@ * Ensure that the provided id is a valid string. | ||
url?: string; | ||
zipOptions?: ZipOptions; | ||
} | ||
@@ -142,2 +148,3 @@ declare class LottieAnimationCommon { | ||
private _intermission; | ||
private _zipOptions; | ||
protected _defaultActiveAnimation: boolean; | ||
@@ -149,2 +156,4 @@ protected _imageAssets: LottieImageCommon[]; | ||
toBase64(): Promise<string>; | ||
get zipOptions(): ZipOptions; | ||
set zipOptions(zipOptions: ZipOptions); | ||
get id(): string; | ||
@@ -278,2 +287,3 @@ set id(id: string); | ||
url?: string; | ||
zipOptions?: ZipOptions; | ||
} | ||
@@ -285,3 +295,6 @@ declare class LottieThemeCommon { | ||
protected readonly _animationsMap: Map<string, LottieAnimationCommon>; | ||
protected _zipOptions: ZipOptions; | ||
constructor(options: ThemeOptions); | ||
get zipOptions(): ZipOptions; | ||
set zipOptions(zipOptions: ZipOptions); | ||
get id(): string; | ||
@@ -321,2 +334,5 @@ set id(id: string | undefined); | ||
} | ||
interface ConversionOptions { | ||
zipOptions?: ZipOptions; | ||
} | ||
declare class DotLottieCommon { | ||
@@ -335,9 +351,9 @@ protected readonly _animationsMap: Map<string, LottieAnimationCommon>; | ||
constructor(options?: DotLottieOptions); | ||
toBase64(): Promise<string>; | ||
toBase64(_options?: ConversionOptions | undefined): Promise<string>; | ||
create(_options?: DotLottieOptions): DotLottieCommon; | ||
download(_fileName: string): Promise<void>; | ||
download(_fileName: string, _options?: ConversionOptions | undefined): Promise<void>; | ||
addPlugins(..._plugins: DotLottiePlugin[]): DotLottieCommon; | ||
addAnimation(_animationOptions: AnimationOptions): DotLottieCommon; | ||
fromArrayBuffer(_arrayBuffer: ArrayBuffer): Promise<DotLottieCommon>; | ||
toArrayBuffer(): Promise<ArrayBuffer>; | ||
toArrayBuffer(_options?: ConversionOptions | undefined): Promise<ArrayBuffer>; | ||
get plugins(): DotLottiePlugin[]; | ||
@@ -395,3 +411,3 @@ get version(): string | undefined; | ||
build(): Promise<DotLottieCommon>; | ||
toBlob(): Promise<Blob>; | ||
toBlob(options?: ConversionOptions | undefined): Promise<Blob>; | ||
/** | ||
@@ -430,6 +446,6 @@ * Creates a DotLottie instance from a url to a dotlottie file | ||
create(): DotLottieCommon; | ||
toBase64(): Promise<string>; | ||
download(_fileName: string): Promise<void>; | ||
toBase64(options: ConversionOptions | undefined): Promise<string>; | ||
download(_fileName: string, _options?: ConversionOptions | undefined): Promise<void>; | ||
addAnimation(animationOptions: AnimationOptions): DotLottieCommon; | ||
toArrayBuffer(): Promise<ArrayBuffer>; | ||
toArrayBuffer(options: ConversionOptions | undefined): Promise<ArrayBuffer>; | ||
/** | ||
@@ -436,0 +452,0 @@ * Creates a DotLottie instance from an array buffer |
@@ -14,3 +14,3 @@ import { strToU8, zip, unzip, strFromU8 } from 'fflate'; | ||
name: "@dotlottie/dotlottie-js", | ||
version: "0.2.1", | ||
version: "0.3.0", | ||
type: "module", | ||
@@ -141,2 +141,3 @@ description: "This library helps in creating and modifying .lottie files.", | ||
__publicField(this, "_animationsMap", /* @__PURE__ */ new Map()); | ||
__publicField(this, "_zipOptions"); | ||
this._requireValidId(options.id); | ||
@@ -152,3 +153,10 @@ this._id = options.id; | ||
} | ||
this._zipOptions = options.zipOptions ?? {}; | ||
} | ||
get zipOptions() { | ||
return this._zipOptions; | ||
} | ||
set zipOptions(zipOptions) { | ||
this._zipOptions = zipOptions; | ||
} | ||
get id() { | ||
@@ -237,3 +245,3 @@ return this._id; | ||
} | ||
async toBase64() { | ||
async toBase64(_options = void 0) { | ||
throw createError("toBase64() method not implemented in concrete class!"); | ||
@@ -244,3 +252,3 @@ } | ||
} | ||
async download(_fileName) { | ||
async download(_fileName, _options = void 0) { | ||
throw createError("download(fileName:string) method not implemented in concrete class!"); | ||
@@ -257,3 +265,3 @@ } | ||
} | ||
async toArrayBuffer() { | ||
async toArrayBuffer(_options = void 0) { | ||
throw createError("toArrayBuffer(): Promise<ArrayBuffer> is not implemented in concrete class!"); | ||
@@ -493,4 +501,4 @@ } | ||
} | ||
async toBlob() { | ||
const arrayBuffer = await this.toArrayBuffer(); | ||
async toBlob(options = void 0) { | ||
const arrayBuffer = await this.toArrayBuffer(options); | ||
return new Blob([arrayBuffer], { type: "application/zip" }); | ||
@@ -633,2 +641,3 @@ } | ||
__publicField(this, "_intermission"); | ||
__publicField(this, "_zipOptions"); | ||
__publicField(this, "_defaultActiveAnimation"); | ||
@@ -640,2 +649,3 @@ __publicField(this, "_imageAssets", []); | ||
this._id = options.id; | ||
this._zipOptions = options.zipOptions ?? {}; | ||
if (options.data) | ||
@@ -657,2 +667,8 @@ this._data = options.data; | ||
} | ||
get zipOptions() { | ||
return this._zipOptions; | ||
} | ||
set zipOptions(zipOptions) { | ||
this._zipOptions = zipOptions; | ||
} | ||
get id() { | ||
@@ -874,4 +890,6 @@ return this._id; | ||
__publicField(this, "_parentAnimations"); | ||
__publicField(this, "_zipOptions"); | ||
this._requireValidId(options.id); | ||
this._requireValidFileName(options.fileName); | ||
this._zipOptions = options.zipOptions ?? {}; | ||
if (options.data) { | ||
@@ -891,2 +909,8 @@ this._data = options.data; | ||
} | ||
get zipOptions() { | ||
return this._zipOptions; | ||
} | ||
set zipOptions(zipOptions) { | ||
this._zipOptions = zipOptions; | ||
} | ||
_requireValidId(id) { | ||
@@ -1273,7 +1297,7 @@ if (!id) | ||
} | ||
async toBase64() { | ||
const data = await this.toArrayBuffer(); | ||
async toBase64(options) { | ||
const data = await this.toArrayBuffer(options); | ||
return Buffer.from(data).toString("base64"); | ||
} | ||
async download(_fileName) { | ||
async download(_fileName, _options = void 0) { | ||
throw createError("Cannot download dotlottie in a non-browser environment"); | ||
@@ -1289,14 +1313,19 @@ } | ||
} | ||
async toArrayBuffer() { | ||
async toArrayBuffer(options) { | ||
const manifest = this._buildManifest(); | ||
const dotlottie = { | ||
"manifest.json": strToU8(JSON.stringify(manifest)) | ||
"manifest.json": [ | ||
strToU8(JSON.stringify(manifest)), | ||
{ | ||
level: 0 | ||
} | ||
] | ||
}; | ||
for (const animation of this.animations) { | ||
const json = await animation.toJSON(); | ||
dotlottie[`animations/${animation.id}.json`] = strToU8(JSON.stringify(json)); | ||
dotlottie[`animations/${animation.id}.json`] = [strToU8(JSON.stringify(json)), animation.zipOptions]; | ||
const imageAssets = animation.imageAssets; | ||
for (const asset of imageAssets) { | ||
const dataAsString = await asset.toDataURL(); | ||
dotlottie[`images/${asset.fileName}`] = base64ToUint8Array(dataAsString); | ||
dotlottie[`images/${asset.fileName}`] = [base64ToUint8Array(dataAsString), asset.zipOptions]; | ||
} | ||
@@ -1306,6 +1335,6 @@ } | ||
const lss = await theme.toString(); | ||
dotlottie[`themes/${theme.id}.lss`] = strToU8(lss); | ||
dotlottie[`themes/${theme.id}.lss`] = [strToU8(lss), theme.zipOptions]; | ||
} | ||
const dotlottieArrayBuffer = await new Promise((resolve, reject) => { | ||
zip(dotlottie, (err, data) => { | ||
zip(dotlottie, options?.zipOptions || {}, (err, data) => { | ||
if (err) { | ||
@@ -1312,0 +1341,0 @@ reject(err); |
{ | ||
"name": "@dotlottie/dotlottie-js", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "This library helps in creating and modifying .lottie files.", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
445624
6647