# Typed Like a Letter (写信式逐字打出)

An opening line types itself one character at a time like a letter: 55 to 90 ms per key, longer stops at commas and full stops, a cursor that blinks only while idle and retracts when done; for the first line of a launch film.

- Ref: `video/motion-text-typewriter-letter` (code video · motion · launch, brand · any · 5.5s at 30fps)
- Page: https://uifino.com/en/videos/motion-text-typewriter-letter
- Markdown: https://uifino.com/md/videos/motion-text-typewriter-letter.md
- Preview image: https://uifino.com/videos/motion-text-typewriter-letter/poster.jpg

## Install

- ZIP: https://uifino.com/videos/motion-text-typewriter-letter/source.zip

An opening line types itself one character at a time like a letter: 55 to 90 ms per key, longer stops at commas and full stops, a cursor that blinks only while idle and retracts when done; for the first line of a launch film.

Rendered video: https://uifino.com/videos/motion-text-typewriter-letter/preview.mp4

## Beats

- 0-1s Show the cursor first so the viewer knows something is about to be written: Paper ground, cursor at the line start: solid 0.3 s, off 0.5 s, on 0.2 s Camera: static.
- 1-1.113s The first two characters and the comma (English: "Hi."): Characters pop in one by one, 55 and 58 ms apart, cursor solid right after the newest one Camera: static. On-screen text: "Hi.".
- 1.113-1.463s The pause after the comma, like a person thinking: 0.35 s stop; the cursor only starts to blink after 0.3 s and is cut off after about 0.05 s Camera: static.
- 1.463-2.315s Type the rest of the sentence in one run: 13 characters at 55 to 90 ms each, fixed seed, same every render; cursor stays solid Camera: static. On-screen text: "This is what we spent a year on.".
- 2.315-3.115s Rest after the full stop, one cursor blink: Solid 0.3 s, off 0.5 s (2.615 to 3.115 s) Camera: static.
- 3.115-3.315s The cursor goes away: Cursor comes on and collapses to its center, 0.2 s, power3.in Camera: static.
- 3.315-5.5s Let the sentence be read: The sentence stays fully still for 2.185 s Camera: static. On-screen text: "Hi. This is what we spent a year on.".

## Parameters

- `text` Sentence to type: default 你好，这是我们准备了一年的东西。
- `fontSize` Max font size: default 88px, range 56 to 120px
- `startAt` First character time: default 1s, range 0.3 to 2s
- `seed` Random seed: default 7, range 1 to 999
- `gapMin` Shortest key gap: default 0.055s, range 0.03 to 0.1s
- `gapMax` Longest key gap: default 0.09s, range 0.05 to 0.15s
- `commaPause` Pause after a comma: default 0.35s, range 0.2 to 0.6s
- `endPause` Pause after a sentence end: default 0.6s, range 0.3 to 1s
- `blinkAfter` Idle time before blinking: default 0.3s, range 0.2 to 0.6s
- `blinkPeriod` Blink period: default 1s, range 0.6 to 1.4s
- `retractDelay` Last character to cursor retract: default 0.8s, range 0.4 to 1.5s
- `ink` Text and cursor color: default #121212
- `bg` Background: default #F6F5F2

## Good for

- The first line of a launch or brand film
- One sentence that fits on a single line
- A clean ground where one sentence is the whole point

## Not for

- Multi-line or multi-paragraph copy
- Whole-sentence fades or word-by-word reveals
- Demos that need typos and backspacing (this one never deletes)

## Source files (plain text)

- https://uifino.com/videos/motion-text-typewriter-letter/source/SPEC.md
- https://uifino.com/videos/motion-text-typewriter-letter/source/PROMPT.md
- https://uifino.com/videos/motion-text-typewriter-letter/source/NOTICE.md
- https://uifino.com/videos/motion-text-typewriter-letter/source/project/assets/fonts/OFL.txt
- https://uifino.com/videos/motion-text-typewriter-letter/source/project/compositions/typewriter.html
- https://uifino.com/videos/motion-text-typewriter-letter/source/project/hyperframes.json
- https://uifino.com/videos/motion-text-typewriter-letter/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 | 4.0 KB |
| SPEC.md | doc | 6.4 KB |

### PROMPT.md

```md
# PROMPT：motion-text-typewriter-letter

## 照抄复刻
用 `/hyperframes` 做一条 1920×1080、30 fps、5.5 秒的动效：一句开场白像写信一样逐字打出，打完光标收起，整句静止。

1. 画面：纯色底 `#F6F5F2`；整句单行，字 `#121212`，中文 Noto Serif SC、西文 Instrument Sans，字重 500，本地 `@font-face`，字号 88px（上限；整句超过 1536px 时缩小：字号 = min(88, floor(1536 / 整句在 100px 下的宽度 × 100))），行高 1.3，字距 0。整句按完整句子先排好并左右居中（中文默认文案宽 1408px，左边缘 x=256），行中线 y=540。每个字单独一个 span，初始 opacity 0，所以打字不会推动版面。没有任何别的元素、颜色和文字。
2. 文案：「你好，这是我们准备了一年的东西。」英文：Hi. This is what we spent a year on.
3. 光标：宽 4px、高 92px（宽 = round(字号 × 0.045)，高 = round(字号 × 1.05)）的 `#121212` 纯色竖条，圆角 0，没有阴影和发光；垂直居中在 y=540；左边缘贴在最新一个字的右边缘外 3px。第一个字之前停在行首。
4. 出字：每个字在自己的时间点瞬间出现（opacity 0 到 1，0.001 秒），没有淡入、位移或缩放；光标同一时刻跳到它右边，不滑动。第一个字 1.0 秒出现。
5. 节奏：相邻两字间隔 55 到 90 毫秒，用固定种子的伪随机（mulberry32，种子 7，间隔 = 0.055 + 随机数 × 0.035 秒），每次渲染一样。逗号类（，、；：和英文 , ; :）后面隔 0.35 秒，句末类（。！？…和后面跟空格的英文句点）后面隔 0.6 秒，停顿替换随机间隔，不叠加。默认中文文案各字出现的秒数：1.000、1.055、1.113、1.463、1.542、1.615、1.684、1.756、1.819、1.894、1.974、2.038、2.099、2.180、2.253、2.315。
6. 光标行为：打字时常亮；停下超过 0.3 秒才开始闪：停下后 0.3 秒内常亮，之后灭 0.5 秒、亮 0.5 秒，周期 1 秒；下一个字出现时立刻亮。第一个字之前的 0 到 1.0 秒也一样（0.3 到 0.8 秒灭）。不要用 `repeat: -1`，把每次亮灭写成时间线上的定点 `fromTo`。
7. 收起：最后一个字出现 0.8 秒后（中文版 3.115 秒），光标 `scaleY` 从 1 到 0，0.2 秒，`power3.in`，之后不再出现；3.315 秒起整句完全静止到 5.5 秒。
8. 禁止：整句或逐字淡入、字符位移或缩放入场、键盘或打字机图标、音效图标、彩色或发光的光标、光标滑动、退格改字、下划线、第二行文字。
9. 时间线里所有 `fromTo` 都带 `immediateRender: false`，并先用 `gsap.set` 把每个字设成 opacity 0、光标设成行首；排版要等字体加载完（`document.fonts.load`）再量宽。

需要替换的地方（在 `index.html` 里 `id="typewriter"` 的挂载元素上写 `data-variable-values='{"text":"Hi. This is what we spent a year on."}'` 传入；换新汉字后要重新生成字体子集）：
- 文案：`text`。英文句子默认打到 4.02 秒、收起到 5.02 秒，只能读约 1.5 秒；英文请直接用 `data-variable-values='{"text":"Hi. This is what we spent a year on.","startAt":0.4}'`，最后一个字 3.42 秒，整句可读 2.08 秒。也可以把总时长改成 7 秒（`index.html` 和 `typewriter.html` 的 `data-duration` 一起改）。
- 颜色：`ink`（字和光标）、`bg`（底色，`index.html` 里的兜底底色一起改）。
- 字号：`fontSize`（88）。
- 节奏：`startAt`（1.0）、`seed`（7）、`gapMin`（0.055）、`gapMax`（0.09）、`commaPause`（0.35）、`endPause`（0.6）。
- 光标：`blinkAfter`（0.3）、`blinkPeriod`（1）、`retractDelay`（0.8）。
- 不要加产品界面和其他文字。

## 只学手法
把整句先排好再让每个字瞬间出现，字间隔 55 到 90 毫秒（固定种子的伪随机），逗号后停 0.35 秒、句末停 0.6 秒；光标是同色细竖条，打字时常亮、停下超过 0.3 秒才按 1 秒周期闪，打完 0.8 秒后用 0.2 秒收起，之后整句静止。
```

### SPEC.md

```md
# SPEC：motion-text-typewriter-letter

## LOOK
- 色值：底 `#F6F5F2`，字 `#121212`，光标 `#121212`（和字同色）。次要字 `#6B6966`、线 `#E2DFD8`、强调色 `#D4412A` 这条片不用：画面只有一句话，加任何第二种颜色都是装饰。中性色 3 个以内，0 个强调色。
- 字体：中文 Noto Serif SC（字重 500），西文 Instrument Sans（字重 500），本地 `@font-face`，`assets/fonts/noto-serif-sc.woff2`、`assets/fonts/instrument-sans.woff2`。中文句子只用到 Noto Serif SC，英文句子只用到 Instrument Sans，同一条片里两个字体族都声明。
- 字号：只有 1 档，88px（最大值）。整句宽度超过 1536px（画面宽度的 80%，标题安全区）时按比例缩小：字号 = min(88, floor(1536 / 整句在 100px 下的宽度 × 100))。中文默认文案算出来是 88px，整句宽 1408px。行高 1.3。字距 0。
- 光标：宽 4px（`round(字号 × 0.045)`），高 `round(字号 × 1.05)` = 92px，纯色 `#121212`，圆角 0，没有阴影、没有发光。光标左边缘离刚打出的字右边缘 `round(字号 × 0.03)` = 3px。
- 版式：整句单行，打字前就按完整句子排好版并居中（左边缘 x = (1920 − 句宽) / 2 = 256px，行中线 y = 540px），字一个一个显出来时不会推动版面。
- 圆角：无，光标 0。阴影：无。渐变：无。背景：纯色。

## MOTION
- 出字：每个字在自己的时间点瞬间出现（opacity 0 到 1，时长 0.001 秒），没有淡入、没有位移、没有缩放。
- 键间隔：每字 55–90 毫秒，用固定种子的伪随机（mulberry32，种子 7）：间隔 = 0.055 + 随机数 × 0.035 秒。种子写死，每次渲染一样。
- 停顿：逗号类（`，` `,` `、` `；` `;` `：` `:`）后下一个字隔 0.35 秒；句末类（`。` `！` `？` `!` `?` `…`，以及后面跟空格的 `.`）后隔 0.6 秒。停顿替换随机间隔，不叠加。
- 光标：打字时常亮，随最新的字跳到它右边（瞬移，不滑动）。停下超过 0.3 秒才开始闪：停下后前 0.3 秒常亮，之后灭 0.5 秒、亮 0.5 秒，周期 1 秒，下一个字出来时立刻亮。开场（0 到 1.0 秒）也按同一规则：0.3 秒起灭到 0.8 秒，0.8 秒亮到打字开始。
- 收起：最后一个字出来 0.8 秒后，光标 `scaleY` 1 到 0，0.2 秒，`power3.in`（从中心向内收），之后不再出现。整句从此静止。
- 缓动只用两个：瞬时（出字、光标跳位、闪烁）和 `power3.in`（收起）。

## 逐拍节拍表
默认中文文案（16 个字符，含逗号和句号）。字出现时间（秒）按种子 7 算出：

1.000 你 / 1.055 好 / 1.113 ， / 1.463 这 / 1.542 是 / 1.615 我 / 1.684 们 / 1.756 准 / 1.819 备 / 1.894 了 / 1.974 一 / 2.038 年 / 2.099 的 / 2.180 东 / 2.253 西 / 2.315 。

| 拍 | 起止秒 | 画面 | 镜头 | 转场 | 屏幕文案原文 |
| --- | --- | --- | --- | --- | --- |
| wait | 0.00 – 1.00 | 纸色底，光标在行首常亮；0.3 秒起灭 0.5 秒再亮，等打字开始 | 固定 | 无 | |
| type-1 | 1.00 – 1.113 | 「你好，」三个字间隔 55、58 毫秒 | 固定 | 无 | 你好， |
| comma | 1.113 – 1.463 | 逗号后停 0.35 秒，光标 0.3 秒后开始灭（只灭约 0.05 秒就被下一个字打断） | 固定 | 无 | 你好， |
| type-2 | 1.463 – 2.315 | 「这是我们准备了一年的东西。」连续打出，每字 55–90 毫秒 | 固定 | 无 | 你好，这是我们准备了一年的东西。 |
| end-idle | 2.315 – 3.115 | 句号出来后光标常亮 0.3 秒，灭 0.5 秒（2.615 – 3.115），3.115 亮 | 固定 | 无 | 同上 |
| retract | 3.115 – 3.315 | 光标从中心向内收没 | 固定 | 无 | 同上 |
| hold | 3.315 – 5.50 | 整句完全静止 2.185 秒 | 固定 | 无 | 同上 |

英文版「Hi. This is what we spent a year on.」：36 个字符，`Hi.` 后的 `.` 属于句末（后面是空格），停 0.6 秒；最后一个字符在 4.020 秒，光标收起到 5.02 秒，距 5.5 秒只剩 0.48 秒的静止。默认英文只有约 1.5 秒完整可读。用英文时把 `startAt` 调到 0.4（`data-variable-values='{"text":"Hi. This is what we spent a year on.","startAt":0.4}'`）：最后一个字 3.42 秒，整句可读到 5.5 秒共 2.08 秒，满足至少 2 秒；也可以把 `index.html`、`typewriter.html` 的 `data-duration` 一起改成 7。

## 参数接线
全部是 `project/compositions/typewriter.html` 根元素 `data-composition-variables` 里的变量，用户的 AI 在 `project/index.html` 里 `id="typewriter"` 的挂载元素上写 `data-variable-values='{"text":"Hi. This is what we spent a year on."}'` 覆盖。
- text（默认中文句子）：要打的句子。换了新汉字后要重跑门禁生成字体子集。
- fontSize（88）：最大字号，超宽按整句缩小。
- startAt（1.0）：第一个字出现的秒。
- seed（7）：伪随机种子。
- gapMin（0.055）、gapMax（0.09）：每字间隔范围，秒。
- commaPause（0.35）、endPause（0.6）：逗号类、句末类之后的停顿，秒。
- blinkAfter（0.3）：停下多久后才开始闪，秒。
- blinkPeriod（1）：闪烁周期，秒，亮灭各一半。
- retractDelay（0.8）：最后一个字出来后多久收起光标，秒。
- ink（#121212）、bg（#F6F5F2）：字和光标色、底色。`index.html` 里的 `#F6F5F2` 是兜底底色，换底色时一起改。
总时长 5.5 秒写在 `index.html` 和 `typewriter.html` 的 `data-duration`，要改就一起改。

## 禁用项
整句或逐字淡入、字符位移或缩放入场、键盘、打字机、音效图标、彩色或发光的光标、光标滑动、打字过程中的任何镜头运动、下划线和装饰线、第二行文字、标签。

## 已知取舍
- 光标 0 到 1.0 秒的开场闪烁和逗号后的 0.05 秒闪烁：按 BRIEF「停顿超过 0.3 秒才开始闪」实现，逗号停 0.35 秒只多出 0.05 秒，灭一两帧就被下一个字打断，是规则的直接结果。
- 强调色 `#D4412A`、次要字、线条色没用上：只有一句话，不为了「用满配色」添东西。
- first_frame_empty 警告保留：第 0 帧只有行首一根 4px 光标（已在 draft.mp4 第 0 秒帧确认看得到），检查只认大块内容，这条本来就是先光标、后打字的入场。poster 取 2.8 秒（光标已收、整句静止）。
- 时间线要等字体加载完才注册（要先量字宽排版），代码里用了 document.fonts.load 的 Promise。
```
