Referência de elementos

Elemento de legendas

1. Estrutura

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

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

3. Fontes de legendas suportadas

Array inline

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

Asset de legenda via $ref

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

URL externa

{
  "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

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

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