DotLottieBuilder Class
API reference for the DotLottieBuilder class in dotlottie-io — a stateful builder for constructing .lottie packages.
DotLottieBuilder Class
A stateful builder for constructing .lottie packages. Configure it with the methods below, then call build() to produce a DotLottie.
Import:
const { DotLottieBuilder } = require("@lottiefiles/dotlottie-io");Constructor
new DotLottieBuilder()
Returns:
DotLottieBuilder
Configuration
version(v)
Set the manifest version string.
Parameters:
v:stringReturns:
void
generator(g)
Set the generator field in the manifest (e.g. your tool name and version).
Parameters:
g:stringReturns:
void
mergeStrategy(strategy)
Collision strategy applied when a LottieFile source contains clashing IDs. Defaults to MergeStrategy.Rename.
Parameters:
strategy:MergeStrategyReturns:
void
initialAnimation(id) / initialStateMachine(id)
Set which animation or state machine the player loads first.
Parameters:
id:stringReturns:
void
Adding content
builder.addAnimation(id: string, jsonData: Buffer | string, options?: AnimationOptions): void
builder.addTheme(id: string, name: string | null, jsonData: Buffer | string): void
builder.addStateMachine(id: string, name: string | null, jsonData: Buffer | string): void
builder.addImage(filename: string, data: Buffer): void
builder.addFont(filename: string, data: Buffer): void
builder.addAudio(filename: string, data: Buffer): voidEach method queues the content for the next build() call. Filename collisions across queued assets are resolved at build() time using the same deduplication logic as DotLottie's direct API.
Building
build()
Consumes the builder's configuration and returns a DotLottie instance.
Returns:
DotLottieThrows: if any queued content is invalid (for example, an audio file that isn't
.mp3).
Example
const { DotLottieBuilder } = require("@lottiefiles/dotlottie-io");
const builder = new DotLottieBuilder();
builder.generator("my-tool v1.0");
builder.initialAnimation("intro");
builder.addAnimation("intro", JSON.stringify(introJson));
builder.addAnimation("hero", JSON.stringify(heroJson));
builder.addAudio("click.mp3", clickMp3Buffer);
const dl = builder.build();
console.log(dl.animationIds()); // ['intro', 'hero']
console.log(dl.audioFilenames()); // ['click.mp3']See How to Create a .lottie File for a full walkthrough.
Next up: DotLottieReader Class