# 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`](/docs/tools/dotlottie-io/api/dotlottie-class).

**Import:**

```javascript
const { DotLottieBuilder } = require("@lottiefiles/dotlottie-io");
```

## Constructor

### `new DotLottieBuilder()`

- **Returns:** `DotLottieBuilder`

## Configuration

### `version(v)`

Set the manifest version string.

- **Parameters:** `v`: `string`
- **Returns:** `void`

### `generator(g)`

Set the generator field in the manifest (e.g. your tool name and version).

- **Parameters:** `g`: `string`
- **Returns:** `void`

### `mergeStrategy(strategy)`

Collision strategy applied when a `LottieFile` source contains clashing IDs. Defaults to `MergeStrategy.Rename`.

- **Parameters:** `strategy`: [`MergeStrategy`](/docs/tools/dotlottie-io/api/dotlottie-merger-class#mergestrategy)
- **Returns:** `void`

### `initialAnimation(id)` / `initialStateMachine(id)`

Set which animation or state machine the player loads first.

- **Parameters:** `id`: `string`
- **Returns:** `void`

## Adding content

```typescript
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): void
```

Each method queues the content for the next `build()` call. Filename collisions across queued assets are resolved at `build()` time using the same [deduplication logic](/docs/tools/dotlottie-io/core-concepts/assets#filename-deduplication) as `DotLottie`'s direct API.

## Building

### `build()`

Consumes the builder's configuration and returns a `DotLottie` instance.

- **Returns:** `DotLottie`
- **Throws:** if any queued content is invalid (for example, an audio file that isn't `.mp3`).

## Example

```javascript
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](/docs/tools/dotlottie-io/guides/creating-a-lottie-file) for a full walkthrough.

Next up: [`DotLottieReader` Class](/docs/tools/dotlottie-io/api/dotlottie-reader-class)
