# Elemento de legendas

## 1. Estrutura

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

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

Também suporta:
- `opacity`
- `animations`
- `keyframes`
- `transition`
- `transform`
- `zIndex`

## 2. `SubtitleWord`

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

## 3. Fontes de legendas suportadas

### Array inline

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

### Asset de legenda via `$ref`

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

### URL externa

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

## 4. Regras para URL externa de legendas

O endpoint remoto precisa retornar JSON em um destes formatos:
- `SubtitleWord[]`
- `{ "words": SubtitleWord[] }`

Comportamento público:
- O fluxo de preview aceita `words: { "src": "..." }`
- A reprodução em preview normaliza os dados de legenda antes da reprodução
- Se você enviar `{ src }` diretamente para um renderer de nível mais baixo, os dados de legenda não são buscados automaticamente

## 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. Campos de configuração implementados atualmente

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

## 7. Comportamento dos modos

### `batch`
- Exibe legendas em blocos
- Destaca a palavra falada no momento

### `stream`
- Revela as palavras uma a uma

## 8. Comportamento de animação do bloco inteiro

A animação no nível do contêiner se aplica ao bloco inteiro de legendas, não à lógica de destaque palavra por palavra.

Diferença importante:
- `config.fadeInAnimation` controla o comportamento de fade dentro dos lotes de legendas
- `animations / keyframes / transition` controlam o contêiner completo das legendas

Isso significa que você pode animar o bloco de legendas com fade, slide ou movimento sem alterar a lógica interna de destaque das palavras.

## 9. Exemplo

```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)"
  }
}
```