# Word-by-Word Highlight Captions (逐词高亮字幕)

A caption line at the bottom brightens word by word at speaking pace while one soft block slides from word to word, and whole lines swap; for talking-head and explainer videos.

- Ref: `video/motion-caption-word-highlight` (code video · motion · tutorial, feature, brand · bilibili, douyin, xiaohongshu, wechat-channels · 5s at 30fps)
- Page: https://uifino.com/en/videos/motion-caption-word-highlight
- Markdown: https://uifino.com/md/videos/motion-caption-word-highlight.md
- Preview image: https://uifino.com/videos/motion-caption-word-highlight/poster.jpg

## Install

- ZIP: https://uifino.com/videos/motion-caption-word-highlight/source.zip

A caption line at the bottom brightens word by word at speaking pace while one soft block slides from word to word, and whole lines swap; for talking-head and explainer videos.

Rendered video: https://uifino.com/videos/motion-caption-word-highlight/preview.mp4

## Beats

- 0-2.58s Read the first line word by word, then clear it as a whole: Caption at the bottom, unspoken words dim, spoken words bright, a soft green block follows; after 0.2 s the whole line blurs out Camera: static. Transition: blur swap on one stage. On-screen text: "We turned great launch videos".
- 2.58-5s Read the second line the same way and hold to the end: Second line blurs in as a whole, the block slides word by word, then fades and the caption stays still Camera: static. On-screen text: "into scripts you can copy".

## Parameters

- `line1` First line, words split by |: default 我们|把|好看的|宣传片
- `line2` Second line, words split by |: default 拆成了|能|照抄的|剧本
- `line1At` Start of the first line: default 0.5s, range 0.3 to 1.5s
- `charsPerSecond` Speech pace, characters per second: default 5.2chars/s, range 3 to 9chars/s
- `finishBy` Latest end of the last word; the pace speeds up to fit: default 4.7s, range 3.5 to 4.8s
- `shiftDuration` Block slide time between words: default 0.14s, range 0.08 to 0.25s
- `blockOpacity` Block opacity: default 0.22, range 0.12 to 0.35
- `fontSize` Max caption size, shrinks when too wide: default 72px, range 44 to 96px
- `accentColor` Block color: default #7FD99A
- `ink` Spoken and current word color: default #ECF2EE
- `dimInk` Unspoken word color: default #8FA096
- `bg` Background color: default #0F1712

## Good for

- Subtitles for voiceover, explainer and tutorial videos
- Lines of 8 to 12 Chinese characters or 4 to 6 English words
- Landscape videos that must keep clear of the platform bottom bar and danmaku

## Not for

- Long scrolling subtitles
- Speech faster than 9 characters per second
- Karaoke lyrics with per-letter bounce

## Source files (plain text)

- https://uifino.com/videos/motion-caption-word-highlight/source/SPEC.md
- https://uifino.com/videos/motion-caption-word-highlight/source/PROMPT.md
- https://uifino.com/videos/motion-caption-word-highlight/source/NOTICE.md
- https://uifino.com/videos/motion-caption-word-highlight/source/project/assets/fonts/OFL.txt
- https://uifino.com/videos/motion-caption-word-highlight/source/project/compositions/caption.html
- https://uifino.com/videos/motion-caption-word-highlight/source/project/hyperframes.json
- https://uifino.com/videos/motion-caption-word-highlight/source/project/index.html

## How to use

- Copy the beats and parameters; replace only the copy, the accent color and the product screenshots.
- `PROMPT.md` has two prompts: one to reproduce this video exactly, one to learn only the technique.
- Build with HyperFrames (`/hyperframes`); the project in the ZIP is a ready starting point.

## Files

| Path | Role | Size |
| :--- | :--- | ---: |
| PROMPT.md | doc | 2.7 KB |
| SPEC.md | doc | 7.0 KB |

### PROMPT.md

```md
# PROMPT：motion-caption-word-highlight

## 照抄复刻
> 给用户的 AI：用 `/hyperframes` 复刻下面这条字幕。

做一条 1920×1080、30 fps、5 秒的逐词高亮字幕，背景是纯深绿色 `#0F1712`，没有渐变，画面上半部分留空。

字幕整行放在画面下方、横向居中，行底边距画面底边 120px，字号 72px、字重 500，西文 Hanken Grotesk、中文 Noto Sans SC，用本地 `@font-face`。不要描边、阴影、加粗。整行最宽不超过画面宽度的 80%（1536px），过宽就缩字号，最小 44px。

两句字幕，每句拆成几个词：
- 第一句「我们 / 把 / 好看的 / 宣传片」，0.5 秒开始读。
- 第二句「拆成了 / 能 / 照抄的 / 剧本」，接在第一句后面。
语速 5.2 字/秒（绝不超过 9 字/秒），每个词的权重 = 汉字数 + 0.45 × 其他字符数（最少 1），词时长 = 权重 ÷ 语速。最后一个词要在 4.7 秒（`finishBy`）前读完：语速 = min(9, max(5.2, 两句总权重 ÷ (4.7 − 第一句开始时间 − 0.69)))，英文词多时会自动加快，所以英文版不会超过 5 秒。词与词之间左右各留 0.17em 的间距。

每一句的动作：
1. 整行模糊 8px 到 0、不透明度 0 到 1，0.3 秒 `expo.out`，在第一个词开始前 0.3 秒进场，没有位移。
2. 所有词一开始是灰绿 `#8FA096`；轮到某个词时，它变成 `#ECF2EE`（0.12 秒 `power3.out`），之后保持亮色。
3. 一个圆角 8px、强调色 `#7FD99A`、不透明度 0.22 的底块罩在当前词后面，宽度比词多左右各 8px、高度等于行高；轮到下一个词时，它的位置和宽度一起滑过去（0.14 秒 `power3.out`，提前 0.04 秒起步）。文字本身不动、不缩放。
4. 读完后停 0.2 秒，整行模糊淡出（0.15 秒 `power3.in`），再空约 0.34 秒进下一句。第二句读完后底块 0.2 秒淡出，字幕静止到片尾。

需要替换的地方：
- 两句文案（`line1`、`line2`，词之间用 `|` 分隔；英文可直接用空格分隔）。
- 底块和文字颜色（`accentColor`、`ink`、`dimInk`），背景（`bg`）。
- 语速（`charsPerSecond`）和第一句开始时间（`line1At`）；有真实旁白时，用旁白里每个词的起止时间代替按字数分配。
- 字幕行底边距 120px 按目标平台调整：B 站、抖音横屏保持 120px；竖屏要抬到至少离底 672px。

## 只学手法
字幕逐词变亮时，用一块半透明的底色块（圆角 8px、强调色 22%）在词与词之间滑动，不让文字本身动；词时长按字数分配（每秒不超过 9 个字），整句用 0.3 秒模糊淡入、0.15 秒模糊淡出换句，字幕行底边留 120px 避开平台按钮和弹幕。
```

### SPEC.md

```md
# SPEC：motion-caption-word-highlight

## LOOK
- 色值（中性色 3 个，强调色 1 个）：背景 `#0F1712`（纯色，没有渐变），已读和当前词 `#ECF2EE`，未读词 `#8FA096`，强调色 `#7FD99A`（只用在底块上，不透明度 0.22，面积不到画面的 1%）。
- 字体：西文 Hanken Grotesk（`assets/fonts/hanken-grotesk.woff2`），中文 Noto Sans SC（`assets/fonts/noto-sans-sc.woff2`），本地 `@font-face`，门禁按用到的字生成子集，OFL 许可。西文排在前，中文兜底。字重 500，没有描边、没有阴影、没有加粗。
- 字号：只有一档，默认 72px，行高 1.3（94px）。整句太宽时自动缩小，下限 44px（见 MOTION 的「自动排版」）。
- 圆角：只有一档 8px（底块）。阴影、边框、描边：无。
- 版式：字幕整行在画面横向居中，行底边距画面底边 120px（行盒 y = 866 到 960px），在 80% 标题安全框（y 108 到 972px）以内。选 120px 是为了避开 B 站、抖音横屏播放器的底部控制条（约 60 到 80px）和滚到画面下半部的弹幕；整行最宽不超过 1536px（画面宽度的 80%）。
- 词与词之间的间距：每个词左右各 0.17em（72px 字号下合计 24.5px），底块左右各多出 0.11em（8px，取整），底块高度 = 行高 94px。
- 画面上半部分故意留空，那是口播人物或讲解画面的位置，字幕不去占它。

## MOTION
- 一个主动作：底块在词与词之间滑动，同时当前词从灰绿变亮。文字本身不动、不缩放、不弹。
- 词时长按字数分配：一个词的权重 = 汉字数 + 0.45 × 其他字符数（最少 1），词时长 = 权重 ÷ 语速。默认语速 5.2 字/秒，每秒不超过 9 个字的上限写在代码里（`Math.min(9, …)`）。
- 底块滑动：时长 0.14 秒，缓动 `power3.out`，在词开始前 0.04 秒起步，词开始时已基本到位；位置和宽度同时过渡，所以不同长度的词之间不会跳。
- 当前词变亮：灰绿 `#8FA096` 到 `#ECF2EE`，0.12 秒，`power3.out`，从该词开始时起。读过的词保持亮色。
- 第一个词的底块：不透明度 0 到 0.22，0.12 秒，`power2.out`，在第一个词开始前 0.04 秒起。
- 整句进场：整行不透明度 0 到 1，同时模糊 8px 到 0，0.3 秒，`expo.out`，在该句第一个词开始前 0.3 秒起，没有位移。
- 整句退场：不透明度 1 到 0，模糊 0 到 8px，0.15 秒（是进场的一半），`power3.in`，在该句最后一个词读完后停 0.2 秒再开始。
- 句间衔接：退场结束后再空 0.04 秒，下一句开始进场，进场结束时第一个词开始读。所以第二句第一个词开始时间 = 第一句读完 + 0.2 + 0.15 + 0.34 秒。
- 第二句读完：底块 0.2 秒淡出（`power2.in`，读完后 0.1 秒起），之后字幕保持完全静止到片尾。
- 语速自适应：代码会算「最后一个词最晚读完的时间」`finishBy`（默认 4.7 秒）：需要的语速 = 两句总权重 ÷（finishBy − line1At − 0.69）。实际语速 = min(9, max(charsPerSecond, 需要的语速))。中文默认值算出来需要 5.13 字/秒，小于 5.2，所以取 5.2。英文词多，会自动加快到 finishBy 之内。
- 自动排版：先用 100px 字号量出两句的最宽宽度，字号 = max(44, min(fontSize, floor(1536 ÷ 最宽宽度 × 100)))。中文默认值下两句都不到 1000px，用 72px。
- 没有运动模糊：底块一次最多滑 250px，0.14 秒，没有拖影也读得清。

## 逐拍节拍表
默认中文，语速 5.2 字/秒，两句权重各 9。

| 拍 | 起止秒 | 画面 | 镜头 | 转场 | 屏幕文案原文 |
| --- | --- | --- | --- | --- | --- |
| line-1 | 0.20 – 2.58 | 整行模糊淡入（0.20 – 0.50），逐词：我们 0.50 – 0.89，把 0.89 – 1.08，好看的 1.08 – 1.65，宣传片 1.65 – 2.23；停 0.2 秒后整行模糊淡出（2.43 – 2.58） | 固定 | 同一舞台上的模糊换句 | 我们 把 好看的 宣传片 |
| line-2 | 2.58 – 5.00 | 整行模糊淡入（2.62 – 2.92），逐词：拆成了 2.92 – 3.50，能 3.50 – 3.69，照抄的 3.69 – 4.27，剧本 4.27 – 4.65；底块 4.75 – 4.95 淡出，字幕静止到 5.00 | 固定 | 无 | 拆成了 能 照抄的 剧本 |

英文版：`line1` 填 `We turned great launch videos`，`line2` 填 `into scripts you can copy`（没有 `|` 时按空格拆词），保留 `finishBy` 默认值即可，语速会自动加快到把第二句读完。临时换成英文跑过门禁截帧确认：整句在 1536px 以内、词能逐个高亮、底块宽度跟着词走。
词的上限：同一句里每个词按权重分配时间，一个单字词（如「把」）只有约 0.19 秒，所以对照真实旁白时，把真实的词起止时间换算成 `charsPerSecond` 和词的切分，或者直接调整 `|` 的位置。

## 参数接线
全部是 `project/compositions/caption.html` 根元素 `data-composition-variables` 里的变量；要改默认值就在 `project/index.html` 里 `id="caption"` 的挂载元素上加 `data-variable-values='{"line1":"We turned great launch videos","line2":"into scripts you can copy"}'`（JSON）。
- line1（我们|把|好看的|宣传片）、line2（拆成了|能|照抄的|剧本）：两句字幕，词之间用 `|` 分隔，没有 `|` 就按空格拆，再没有空格就按单字拆。
- line1At（0.5）：第一句第一个词开始读的时间，秒。
- charsPerSecond（5.2）：语速；finishBy（4.7）：最后一个词最晚读完的时间。
- shiftDuration（0.14）：底块滑动时长；blockOpacity（0.22）：底块不透明度。
- fontSize（72）：最大字号，过宽自动缩小。
- accentColor（#7FD99A）、ink（#ECF2EE）、dimInk（#8FA096）、bg（#0F1712）。
`index.html` 里 `#root` 和 `body` 的底色 `#0F1712` 是写死的兜底，换 `bg` 时一起改。总时长 5 秒写在 `index.html` 根元素和 `caption` 挂载元素的 `data-duration`，要改就一起改。写死的数值（不开放成变量）：进场 0.3 秒、退场 0.15 秒、句间停 0.2 秒、衔接 0.34 秒、行底边距 120px、最大宽度 1536px、词间距 0.17em、底块内边距 0.11em、底块圆角 8px。

## 禁用项
每个字蹦跳或缩放、彩虹色或逐词换色、描边加阴影加粗三件套、整行滚动、逐字打字、点击光圈、呼吸漂浮、小标签和注释、第二种强调色、胶囊形底块。

## 已知取舍
- 门禁会报一条「第一帧是空的」（first_frame_empty）：字幕 0.2 秒才开始进场。BRIEF 的做法是 0.1–0.3 秒进场，避免字幕在第 0 帧像是原本就挂在那里；封面取 1.5 秒（`poster`），不用第 0 帧。
- 画面上半部分是空的，是故意留给口播画面的，单看这条会显得空。
- 「把」「能」这类单字词只有 0.19 秒，这是按字数分配的结果；对照真旁白用时，请换成真实的词切分。
- 字体子集按默认中文文案和 ASCII 生成，换成别的中文词要重新跑门禁。
- 时间线要等字体加载完才注册（要先量字宽），代码里用了 document.fonts.load 的 Promise。
```
