# Subtitle Element

## 1. Shape

```ts
type SubtitleSource =
  | SubtitleWord[]
  | { $ref: string }
  | { src: string };

interface SubtitleClip extends BaseClip {
  type: "subtitle";
  words: SubtitleSource;
  config?: SubtitleConfig;
}
```

Also supports:
- `opacity`
- `animations`
- `keyframes`
- `transition`
- `transform`
- `zIndex`

## 2. `SubtitleWord`

```ts
interface SubtitleWord {
  word: string;
  punctuated_word: string;
  start: number;
  end: number;
  confidence?: number;
}
```

## 3. Supported subtitle sources

### Inline array

```json
{
  "words": [
    {
      "word": "hello",
      "punctuated_word": "Hello",
      "start": 0,
      "end": 0.4
    }
  ]
}
```

### Subtitle asset via `$ref`

```json
{
  "words": { "$ref": "subtitle-main" }
}
```

### External URL

```json
{
  "words": { "src": "https://example.com/subtitle.json" }
}
```

## 4. External subtitle URL rules

The remote endpoint must return JSON in one of these shapes:
- `SubtitleWord[]`
- `{ "words": SubtitleWord[] }`

Public behavior:
- The preview flow accepts `words: { "src": "..." }`
- Preview playback normalizes subtitle data before playback
- If you send `{ src }` directly into a lower-level renderer, subtitle data is not fetched automatically

## 5. `SubtitleConfig`

```ts
interface SubtitleConfig {
  mode?: "batch" | "stream";
  wordsPerBatch?: number;
  fontSize?: number;
  fontFamily?: string;
  fontWeight?: number | string;
  textAlign?: "left" | "center" | "right";
  textBoxWidth?: number | string;
  textColor?: string;
  highlightColor?: string;
  backgroundColor?: string;
  shadowColor?: string;
  shadowBlur?: number;
  borderColor?: string;
  borderWidth?: number;
  fadeInAnimation?: boolean;
  position?: "bottom" | "top" | "center";
  paddingBottom?: number;
}
```

## 6. Currently implemented config fields

- `mode`
- `wordsPerBatch`
- `fontSize`
- `fontFamily`
- `fontWeight`
- `textAlign`
- `textBoxWidth`
- `textColor`
- `highlightColor`
- `backgroundColor`
- `shadowColor`
- `shadowBlur`
- `borderColor`
- `borderWidth`
- `fadeInAnimation`
- `position`
- `paddingBottom`

## 7. Mode behavior

### `batch`
- Displays subtitles in chunks
- Highlights the currently spoken word

### `stream`
- Reveals words one by one

## 8. Whole-block animation behavior

Container-level subtitle animation applies to the full subtitle block, not to the per-word highlight logic.

Important distinction:
- `config.fadeInAnimation` controls fade behavior inside subtitle batches
- `animations / keyframes / transition` control the whole subtitle container

That means you can animate the subtitle block itself with fade, slide, or movement without changing the internal word-highlighting logic.

## 9. Example

```json
{
  "type": "subtitle",
  "start": 0,
  "duration": 8,
  "words": { "$ref": "sub-main" },
  "animations": [
    { "type": "slideIn", "duration": 0.4, "direction": "up" }
  ],
  "config": {
    "position": "bottom",
    "fontSize": 60,
    "highlightColor": "#22d3ee",
    "backgroundColor": "rgba(0,0,0,0.4)"
  }
}
```