Files
heroui-vue/docs/migrations/M15-typography.md
T
2026-10-22 13:07:13 +08:00

106 lines
7.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# M15 Typography 交接报告
实施日期:2026-10-22。状态:实施者自测完成,待集成人复核。**未提交、未推送、未宣布验收通过。**
## 1. 起点与范围
| 项 | 值 |
| ---------- | ------------------------------------------------------------------------------------------ |
| 起始 HEAD | `bcadbea`(feat: add Checkbox and Radio field families) |
| 工作区起点 | 干净;无未提交修改 |
| 上游基线 | HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`../heroui` 只读) |
| 范围 | Typography、TypographyHeading、TypographyParagraph、TypographyCode、TypographyProse 及文档 |
本轮实现 M15,按顺序继续 M16 EmptyState、M17 Breadcrumbs;三批共享入口只做必要增量。
## 2. 上游核对
- 实际导出:`Typography` 是带 `Root`、`Heading`、`Paragraph`、`Code`、`Prose` 的对象;同时命名导出 `TypographyRoot`、`Heading`、`Paragraph`、`Code`、`Prose`。
- 实现:`TypographyRoot` 基于 React Aria Components `Text`,`type` 默认 `body`,映射到 `p`;`h1`–`h6` 映射到同名标题,`code` 映射到 `code`。默认 `align="start"`、`color="default"`,`truncate` 与 `weight` 未指定。
- 子部件:`Heading` 的 `level` 默认 `1`;`Paragraph` 的 `size` 默认 `base`,映射 `body` / `body-sm` / `body-xs`;`Code` 固定 `type="code"`;`Prose` 固定 `div`。
- tv:`typographyVariants` 提供 `type`(10 项)、`align`(start/center/end/justify)、`color`(default/muted)、`truncate`、`weight`(normal/medium/semibold/bold),另有 `prose` slot。
- CSS:`packages/styles/components/typography.css` 的标题、正文、代码、prose 后代元素和修饰类全部按基线数值移植。
- 文档/示例:固定基线有 1 个中文 Typography 页和 6 个示例:`default`、`typography-scale`、`primitives`、`prose`、`render-props`、`custom-styles`。
## 3. Vue 实现与 API 对照
Vue 使用独立命名组件,替代 React 的对象子部件:
| 上游 | Vue |
| ------------------------ | ------------------------------------------------------------ |
| `Typography` / `.Root` | `Typography` |
| `Typography.Heading` | `TypographyHeading` |
| `Typography.Paragraph` | `TypographyParagraph` |
| `Typography.Code` | `TypographyCode` |
| `Typography.Prose` | `TypographyProse` |
| `render` 元素替换 | `as` 字符串 |
| `className` / `children` | `class` / 默认插槽 |
| React 属性与事件 | Vue `$attrs`、原生属性和事件;`inheritAttrs: false` 显式透传 |
公共属性保持基线名称与默认值:`type='body'`、`align='start'`、`color='default'`、`truncate=false`,`weight` 未指定;Heading `level=1`,Paragraph `size='base'`。`TypographyProse` 固定 `div`,不提供 `as`,与上游一致。
DOM/类名:根元素 `data-slot="typography"`、`data-type`;tv 类为 `hv-typography--{type}`、`--align-*`、`--color-*`、`--weight-*`、`--truncate`。`TypographyProse` 根类为 `hv-typography-prose`,`data-slot="prose"`。
## 4. 变更文件
新增:
- `packages/styles/components/typography.css`
- `packages/vue/src/components/typography/Typography.vue`
- `packages/vue/src/components/typography/TypographyHeading.vue`
- `packages/vue/src/components/typography/TypographyParagraph.vue`
- `packages/vue/src/components/typography/TypographyCode.vue`
- `packages/vue/src/components/typography/TypographyProse.vue`
- `apps/docs/components/typography.md`
- `apps/docs/demos/typography-default.vue`
- `apps/docs/demos/typography-typography-scale.vue`
- `apps/docs/demos/typography-primitives.vue`
- `apps/docs/demos/typography-prose.vue`
- `apps/docs/demos/typography-render-props.vue`
- `apps/docs/demos/typography-custom-styles.vue`
共享增量:
- `packages/styles/src/index.ts`:`typographyVariants` / `TypographyVariants`
- `packages/styles/index.css`:Typography CSS 入口
- `packages/vue/src/index.ts`、`packages/vue/src/types.ts`:组件与 Props 导出
- `apps/docs/.vitepress/theme/Layout.vue`、`apps/docs/components.md`:导航与总览
- `tests/typography-empty-breadcrumbs.test.ts`:三批共用的行为测试文件(本批含 Typography 用例)
- `tests/ssr.test.ts`:三批共用的组合 SSR 用例
## 5. 验证结果
| 入口 | 文件数 | 通过数 | 含 SSR |
| ----------------- | ------ | ------ | ------------------- |
| `pnpm test` | 17 | 284 | 是(ssr.test.ts 6) |
| `pnpm test:unit` | 16 | 278 | 否 |
| `pnpm test:ssr` | 1 | 6 | 是 |
| `pnpm typecheck` | — | 通过 | — |
| `pnpm build:docs` | — | 通过 | — |
| `pnpm format` | — | 通过 | — |
`build:docs` 仅有 VitePress chunk >500 kB 提示。新增测试文件 `tests/typography-empty-breadcrumbs.test.ts` 共 24 项,已加入 `test:unit`;其中覆盖 Typography 的默认元素映射、五个具名部件、全部变体、`as`、动态 attrs/class 和 SSR 组合。
浏览器(127.0.0.1:5173,桌面 800×655 与 390×900 同源 iframe,浅色/深色):
- Typography 页 6 个预览、6 张表(类型映射 + 5 个 API 表);桌面表宽 724px,窄屏 350px,`table-layout:fixed`、`scrollWidth == clientWidth`,无水平溢出。
- 浅色计算样式:h1 36/40、h2 30/36、body 16/28、body-sm 14/24、body-xs 12/20、code 14/20;深色颜色切换到主题深色变量。
- 窄屏组件 h1 保持 36px;此前文档全局 `h1` 媒体规则会把预览 h1 压到 28px,已把规则收回 `.docs-main > h1`。
- 预览内 `code` 保持 14px,不被文档正文的 12px 内联代码样式覆盖。
## 6. 差异与限制
- React 对象子部件访问方式改为独立具名导出;名称加 `Typography` 前缀以避免公共命名冲突,这是 Vue 适配差异。
- `render` 函数可由任意 React 元素/组件返回;Vue 仅支持 `as` 字符串标签。需要组件级多态时应由调用方使用插槽或包装组件。
- `TypographyProse` 固定 `div`,与上游一致;没有额外的 `as`。
- 未做自动逐像素对比;截图接口返回 “Screenshot needs a visible tab”,本条只有 DOM/计算样式证据。
- 未验证读屏、RTL、触屏、Nuxt 水合和独立安装 dist。
- 未提交、未推送,不能据本报告宣称集成验收通过。
## 7. 最短复核步骤
1. `git diff -- packages/styles/components/typography.css packages/styles/src/index.ts packages/vue/src/components/typography apps/docs/components/typography.md apps/docs/demos/typography-*.vue`
2. 运行 `npx --yes pnpm@11.25.0 typecheck && npx --yes pnpm@11.25.0 test:unit && npx --yes pnpm@11.25.0 test:ssr && npx --yes pnpm@11.25.0 format`。
3. 打开 `http://127.0.0.1:5173/components/typography`,核对 6 个示例、6 张表、浅/深色和 390px 宽度;重点检查 h1 36px 与预览 code 14px。
4. 复核 `render-props` 示例已明确改写为 `as`,并确认文档没有把 React 对象访问方式写成 Vue API。