# 文字

> 按正文、控件、标题等语义角色选择文字样式，字号、行高、字重和字距一同应用。

网页来源：/design/typography

版本：@quirekit/ui 0.3.1；源码修订：d79a6b48d00e+worktree。此文档对应当前源码构建，接入方式以开始使用为准。

### 当前默认值与语义映射

下表与网页 Token 图谱使用同一份源码生成数据；未标注主题的值适用于全部内置主题。base 是基础值，theme 是语义角色，css 是实际 CSS 变量。自定义主题应通过 createTheme 计算。

| 名称 | 值 / 主题 | 依赖 |
| --- | --- | --- |
| base.typography.family.product | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif |  |
| base.typography.family.mono | "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "PingFang SC", "Microsoft YaHei", monospace |  |
| base.typography.size.12 | 12px |  |
| base.typography.size.13 | 13px |  |
| base.typography.size.14 | 14px |  |
| base.typography.size.16 | 16px |  |
| base.typography.size.20 | 20px |  |
| base.typography.size.28 | 28px |  |
| base.typography.size.40 | 40px |  |
| base.typography.lineHeight.12 | 1.6667 |  |
| base.typography.lineHeight.13 | 1.6154 |  |
| base.typography.lineHeight.14 | 1.5714 |  |
| base.typography.lineHeight.16 | 1.5 |  |
| base.typography.lineHeight.20 | 1.4 |  |
| base.typography.lineHeight.28 | 1.2857 |  |
| base.typography.lineHeight.40 | 1.2 |  |
| base.typography.weight.regular | 400 |  |
| base.typography.weight.medium | 500 |  |
| base.typography.weight.semibold | 600 |  |
| base.typography.letterSpacing.normal | normal |  |
| base.typography.letterSpacing.tight | -0.01em |  |
| theme.typography.display.fontFamily | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | base.typography.family.product |
| theme.typography.display.fontSize | 40px | base.typography.size.40 |
| theme.typography.display.lineHeight | 1.2 | base.typography.lineHeight.40 |
| theme.typography.display.fontWeight | 600 | base.typography.weight.semibold |
| theme.typography.display.letterSpacing | -0.01em | base.typography.letterSpacing.tight |
| theme.typography.pageTitle.fontFamily | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | base.typography.family.product |
| theme.typography.pageTitle.fontSize | 28px | base.typography.size.28 |
| theme.typography.pageTitle.lineHeight | 1.2857 | base.typography.lineHeight.28 |
| theme.typography.pageTitle.fontWeight | 600 | base.typography.weight.semibold |
| theme.typography.pageTitle.letterSpacing | -0.01em | base.typography.letterSpacing.tight |
| theme.typography.sectionTitle.fontFamily | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | base.typography.family.product |
| theme.typography.sectionTitle.fontSize | 20px | base.typography.size.20 |
| theme.typography.sectionTitle.lineHeight | 1.4 | base.typography.lineHeight.20 |
| theme.typography.sectionTitle.fontWeight | 600 | base.typography.weight.semibold |
| theme.typography.sectionTitle.letterSpacing | -0.01em | base.typography.letterSpacing.tight |
| theme.typography.heading.fontFamily | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | base.typography.family.product |
| theme.typography.heading.fontSize | 16px | base.typography.size.16 |
| theme.typography.heading.lineHeight | 1.5 | base.typography.lineHeight.16 |
| theme.typography.heading.fontWeight | 600 | base.typography.weight.semibold |
| theme.typography.heading.letterSpacing | normal | base.typography.letterSpacing.normal |
| theme.typography.body.fontFamily | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | base.typography.family.product |
| theme.typography.body.fontSize | 14px | base.typography.size.14 |
| theme.typography.body.lineHeight | 1.5714 | base.typography.lineHeight.14 |
| theme.typography.body.fontWeight | 400 | base.typography.weight.regular |
| theme.typography.body.letterSpacing | normal | base.typography.letterSpacing.normal |
| theme.typography.control.fontFamily | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | base.typography.family.product |
| theme.typography.control.fontSize | 14px | base.typography.size.14 |
| theme.typography.control.lineHeight | 1.5714 | base.typography.lineHeight.14 |
| theme.typography.control.fontWeight | 500 | base.typography.weight.medium |
| theme.typography.control.letterSpacing | normal | base.typography.letterSpacing.normal |
| theme.typography.compact.fontFamily | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | base.typography.family.product |
| theme.typography.compact.fontSize | 13px | base.typography.size.13 |
| theme.typography.compact.lineHeight | 1.6154 | base.typography.lineHeight.13 |
| theme.typography.compact.fontWeight | 400 | base.typography.weight.regular |
| theme.typography.compact.letterSpacing | normal | base.typography.letterSpacing.normal |
| theme.typography.helper.fontFamily | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | base.typography.family.product |
| theme.typography.helper.fontSize | 12px | base.typography.size.12 |
| theme.typography.helper.lineHeight | 1.6667 | base.typography.lineHeight.12 |
| theme.typography.helper.fontWeight | 400 | base.typography.weight.regular |
| theme.typography.helper.letterSpacing | normal | base.typography.letterSpacing.normal |
| theme.typography.code.fontFamily | "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "PingFang SC", "Microsoft YaHei", monospace | base.typography.family.mono |
| theme.typography.code.fontSize | 12px | base.typography.size.12 |
| theme.typography.code.lineHeight | 1.6667 | base.typography.lineHeight.12 |
| theme.typography.code.fontWeight | 400 | base.typography.weight.regular |
| theme.typography.code.letterSpacing | normal | base.typography.letterSpacing.normal |
| css.--qk-type-display-font-family | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | theme.typography.display.fontFamily |
| css.--qk-type-display-font-size | 40px | theme.typography.display.fontSize |
| css.--qk-type-display-line-height | 1.2 | theme.typography.display.lineHeight |
| css.--qk-type-display-font-weight | 600 | theme.typography.display.fontWeight |
| css.--qk-type-display-letter-spacing | -0.01em | theme.typography.display.letterSpacing |
| css.--qk-type-page-title-font-family | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | theme.typography.pageTitle.fontFamily |
| css.--qk-type-page-title-font-size | 28px | theme.typography.pageTitle.fontSize |
| css.--qk-type-page-title-line-height | 1.2857 | theme.typography.pageTitle.lineHeight |
| css.--qk-type-page-title-font-weight | 600 | theme.typography.pageTitle.fontWeight |
| css.--qk-type-page-title-letter-spacing | -0.01em | theme.typography.pageTitle.letterSpacing |
| css.--qk-type-section-title-font-family | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | theme.typography.sectionTitle.fontFamily |
| css.--qk-type-section-title-font-size | 20px | theme.typography.sectionTitle.fontSize |
| css.--qk-type-section-title-line-height | 1.4 | theme.typography.sectionTitle.lineHeight |
| css.--qk-type-section-title-font-weight | 600 | theme.typography.sectionTitle.fontWeight |
| css.--qk-type-section-title-letter-spacing | -0.01em | theme.typography.sectionTitle.letterSpacing |
| css.--qk-type-heading-font-family | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | theme.typography.heading.fontFamily |
| css.--qk-type-heading-font-size | 16px | theme.typography.heading.fontSize |
| css.--qk-type-heading-line-height | 1.5 | theme.typography.heading.lineHeight |
| css.--qk-type-heading-font-weight | 600 | theme.typography.heading.fontWeight |
| css.--qk-type-heading-letter-spacing | normal | theme.typography.heading.letterSpacing |
| css.--qk-type-body-font-family | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | theme.typography.body.fontFamily |
| css.--qk-type-body-font-size | 14px | theme.typography.body.fontSize |
| css.--qk-type-body-line-height | 1.5714 | theme.typography.body.lineHeight |
| css.--qk-type-body-font-weight | 400 | theme.typography.body.fontWeight |
| css.--qk-type-body-letter-spacing | normal | theme.typography.body.letterSpacing |
| css.--qk-type-control-font-family | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | theme.typography.control.fontFamily |
| css.--qk-type-control-font-size | 14px | theme.typography.control.fontSize |
| css.--qk-type-control-line-height | 1.5714 | theme.typography.control.lineHeight |
| css.--qk-type-control-font-weight | 500 | theme.typography.control.fontWeight |
| css.--qk-type-control-letter-spacing | normal | theme.typography.control.letterSpacing |
| css.--qk-type-compact-font-family | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | theme.typography.compact.fontFamily |
| css.--qk-type-compact-font-size | 13px | theme.typography.compact.fontSize |
| css.--qk-type-compact-line-height | 1.6154 | theme.typography.compact.lineHeight |
| css.--qk-type-compact-font-weight | 400 | theme.typography.compact.fontWeight |
| css.--qk-type-compact-letter-spacing | normal | theme.typography.compact.letterSpacing |
| css.--qk-type-helper-font-family | -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif | theme.typography.helper.fontFamily |
| css.--qk-type-helper-font-size | 12px | theme.typography.helper.fontSize |
| css.--qk-type-helper-line-height | 1.6667 | theme.typography.helper.lineHeight |
| css.--qk-type-helper-font-weight | 400 | theme.typography.helper.fontWeight |
| css.--qk-type-helper-letter-spacing | normal | theme.typography.helper.letterSpacing |
| css.--qk-type-code-font-family | "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "PingFang SC", "Microsoft YaHei", monospace | theme.typography.code.fontFamily |
| css.--qk-type-code-font-size | 12px | theme.typography.code.fontSize |
| css.--qk-type-code-line-height | 1.6667 | theme.typography.code.lineHeight |
| css.--qk-type-code-font-weight | 400 | theme.typography.code.fontWeight |
| css.--qk-type-code-letter-spacing | normal | theme.typography.code.letterSpacing |

## 排版的三个层级

| 层级 | 负责什么 | 入口 |
| --- | --- | --- |
| 文字角色 | 字体、字号、行高、字重与字距的完整组合 | `qk-type-*`，共九种角色。 |
| 单个文字元素 | 保留标签语义，应用角色，继承上下文颜色 | [Typography](/raw/components/typography.md) / `qk-typography`。 |
| 连续内容 | 在同一套文字角色上，安排段落、列表、引用、表格与媒体的阅读节奏 | [Prose](/raw/components/prose.md) / `qk-prose`。 |

卡片标题、字段说明使用 Typography，由布局容器安排间距；文章和 Markdown 使用 Prose，由内容结构形成段间距。两者共用字阶，Prose 不另设标题字号或字重。

## 行高使用无单位比例

正文采用 14px 字号与约 22px 行高，基础比例为 `1.5714`，参考 [Ant Design 字体规范](https://ant.design/docs/spec/font-cn/)。这是字阶与行高的设计配对；其他字号使用各自的比例。

| 文字角色 | 字号 | 无单位行高 | 默认行盒约高 |
| --- | --- | --- | --- |
| helper / code | 12px | 1.6667 | 20px |
| compact | 13px | 1.6154 | 21px |
| body / control | 14px | 1.5714 | 22px |
| heading | 16px | 1.5 | 24px |
| sectionTitle | 20px | 1.4 | 28px |
| pageTitle | 28px | 1.2857 | 36px |
| display | 40px | 1.2 | 48px |

13/21 是 QuireKit 对既有紧凑字号的扩展。基础 `typography.lineHeight` 按配对字号索引，语义角色引用对应比例。CSS 变量保存无单位值；例如正文改为 18px 后，行高自动变为约 28.29px。比例保留四位小数，因此浏览器计算值可能与整数像素存在极小差异。

### 示例：typography/line-height

文件：`line-height.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { QuireProse, QuireSwitch } from "@quirekit/ui/vue";
const enlarged = ref(false);
</script>
<template>
  <div class="grid gap-qk-surface p-qk-surface" data-line-height-example>
    <QuireSwitch v-model:checked="enlarged" label="放大正文至 18px" />
    <QuireProse><p :style="enlarged ? { fontSize: '18px' } : undefined" data-scalable-paragraph>清楚的行间距离，让中文、English 和数字 0123456789 都有足够的阅读空间。字号改变时，无单位行高随文字同比变化；段落仍保持自然换行，长时间阅读也更轻松。</p></QuireProse>
  </div>
</template>
```

行高安排每一行的阅读空间，段落间距由 Prose 的结构样式安排。Button、Input 等控件的外框高度仍由尺寸 token 决定；Kbd 的单行键帽几何沿用自身合同。

## 文字的选择依据

文字样式按任务选择：正文支持连续阅读，控件标签帮助快速操作，标题建立结构，辅助说明补充上下文。字号、行高、字重和字距共同形成角色；单独加粗或变淡不能代替清楚的信息组织。

中文、拉丁字母、数字与代码的宽度和视觉重心不同。预览应包含真实语言与内容长度，不能仅用短英文标签判断对齐。辅助文字仍需要可读，不应为追求层级而无限缩小或淡化。

## 用 HTML 语义表达结构与强调

标题使用 `h1`–`h6`，正文使用 `p`，重要内容使用 `strong`，语气强调使用 `em`，代码使用 `code`。标题和正文可以共用 `text.primary`；强调属于 HTML 语义与排版，不需要另设文字颜色层级。

`QuireTypography` 将这些语义映射到现有排版规范，默认渲染 `p`，颜色继承所在上下文。它也支持原生 HTML 子元素，不必为每个行内标签重复添加样式。

```vue
<script setup lang="ts">
import { QuireTypography } from "@quirekit/ui/vue";
</script>

<template>
  <QuireTypography as="h2">季度计划</QuireTypography>
  <QuireTypography>
    请在<strong>周五前</strong>确认目标，优先说明<em>为什么要做</em>。
  </QuireTypography>
  <QuireTypography as="h3" variant="compact">保留 h3 语义的紧凑标题</QuireTypography>
</template>
```

| 属性 | 用途 |
| --- | --- |
| `as` | 原生标签，默认 `p`。支持标题、段落、强调、链接、代码、标记、增删文字、上下标与缩写；完整用法见 [Typography](/raw/components/typography.md)。 |
| `variant` | 可选外观覆盖：`display`、`pageTitle`、`sectionTitle`、`heading`、`body`、`control`、`compact`、`helper`、`code`。只调整排版，不改变标签语义。 |

组件不提供颜色属性；通过父级颜色或现有语义颜色 class 设置前景。`id`、`lang`、`aria-*` 等原生属性继续传给输出元素。

| HTML 语义 | 默认排版 |
| --- | --- |
| `h1` / `h2` | `pageTitle` / `sectionTitle`。 |
| `h3`–`h6` | `heading`；保持真实标题层级，需要时通过 `variant` 选择外观。 |
| `p` / `div` | `body`。 |
| `small` | `helper`。 |
| `code` / `pre` | `code`；代码块保留缩进并独立横向滚动。 |
| `span` | 继承所在文字的排版。 |
| `strong` | 继承字号与颜色，字重引用标题的 semibold token，默认 600。 |
| `em` | 继承字号与颜色，使用斜体表达语气强调。 |

非 Vue 页面可以在语义元素或其容器上添加 `qk-typography`，获得同一套样式：

```html
<article class="qk-typography">
  <h2>季度计划</h2>
  <p>请在<strong>周五前</strong>确认目标，优先说明<em>为什么要做</em>。</p>
  <p>调用 <code>editor.commands.focus()</code> 返回编辑。</p>
</article>
```

这套样式通过 UnoCSS preset 与独立样式表共同提供，只在显式添加 `qk-typography` 的范围内应用，不接管全局 HTML。段落、标题与代码块的默认外边距归零，段间距由布局容器组织；文字颜色由上下文或颜色工具类决定。`mark` 使用主题的轻背景。嵌入控件使用 `data-qk-not-typography` 隔离后代样式；与 Prose 一样，需要支持 CSS `@scope` 的浏览器。

## 一次应用完整角色

使用 `qk-type-body`、`qk-type-control`、`qk-type-heading` 或 `qk-type-code` 一次应用字体、字号、行高、字重和字距。完整角色还包括 `display`、`page-title`、`section-title`、`compact` 和 `helper`。这些 class 同时提供于 UnoCSS 与独立样式表。

```html
<h2 class="qk-type-heading text-qk-text-primary">季度计划</h2>
<p class="qk-type-body text-qk-text-primary">为当前任务说明下一步。</p>
<code class="qk-type-code">editor.commands.focus()</code>
```

文字角色不设置颜色，也不替代 `h1`、`p`、`label`、`code` 等 HTML 语义。优先通过 Typography 或 `qk-typography` 表达语义；需要组合已有组件时，可以直接应用完整角色。现有 `text-qk-*` 继续只配对字号与行高，适用于已经由组件负责字体和字重的场景。

## 字体与代码

产品正文使用系统界面字体。代码使用 [JetBrains Mono](https://github.com/JetBrains/JetBrainsMono)，回退至系统等宽字体；中文使用 PingFang SC、Microsoft YaHei 或可用的系统字体，不要求代码字体包含中文字形。

设计站已本地加载 JetBrains Mono。消费者可显式安装可选的 `@quirekit/font-pack`，按需导入其中的字体样式，不依赖外部字体服务：

```ts
import "@quirekit/font-pack/jetbrains-mono.css";
```

纯 CSS 消费者可在 `@quirekit/unocss-preset/quirekit.css` 旁导入上述字体 CSS。该入口仅声明 `@font-face`，不设置宿主页面字体；字体使用 OFL-1.1 许可，许可证与资源一同分发。不导入时继续使用系统回退字体。

| 场景 | 排版约定 |
| --- | --- |
| 行内代码 | 使用 `qk-type-code`；随正文换行，背景与内边距由容器决定。 |
| 标题内代码 | Typography / Prose 中的 `h1`–`h6` 内 `code`、`samp` 继承标题字号、行高、字重和字距，保留等宽字体。 |
| 代码块 | 使用 `qk-type-code`，保留缩进并独立横向滚动；不压缩代码行高。 |
| 快捷键 | 使用 Kbd 组件，沿用同一等宽字体；尺寸、单行行高与键帽几何由 Kbd 负责。 |

代码角色关闭连字，让 `=>`、`!==` 等字符保持独立；字体不会改变复制内容。计数、页码等普通界面数字可以单独使用等宽数字，不必切换整段文字的字体。

## 字重按文字职责选择

基础字重收敛为 regular 400、medium 500、semibold 600。菜单不会因为选中才加粗，字号和 size 变化也不自动改变字重。

| 职责 | 默认字重 | 应用方式 |
| --- | --- | --- |
| 正文、输入值、说明、状态反馈、快捷键 | 400 | 使用 body / helper / code 的字重；快捷键保留等宽字体。 |
| 菜单主项、导航链接与展开按钮、命令名称、列表分组标签 | 500 | 使用 control 字重；Menu 由组件 typography Token 映射。主项在默认、hover、展开、当前页与禁用时保持一致。 |
| 页面、分节与内容标题，以及正文中的重要内容 | 600 | 标题使用 heading / sectionTitle / pageTitle；行内 strong 仅引用同一字重，不继承标题字号。 |

组合组件应给说明文字明确的 400，防止继承主项的 500；分组标签属于产品文字，不使用快捷键的等宽字体。当前页、hover、按下与 focus 通过背景、文字颜色和焦点轮廓区分，避免加粗导致文字宽度与布局跳动。

这是文字职责的标准，不要求所有可点击文字都相同。普通 Button 目前由自身配方使用 body 的 400；菜单和导航具有连续扫描的需求，明确使用 500。组件采用其他角色时，应在配方和文档中说明用途，不用零散的数字覆盖。

## 文字如何验收

检查默认、悬停、展开、选中和禁用时的计算字重，确认主项 500、说明 400 且文字宽度稳定。再检查长标题、换行标签、中英文混排、连续数字与放大后的正文。观察基线、行间距离、截断和完整信息的获取方式。省略号可以表达空间限制，但关键内容应有可访问的完整呈现。文字对比度的 AA／AAA 门槛见[色彩语义角色](/raw/design/color.md#色板生成后再选择语义角色)，页面中的阅读宽度见[布局与阅读节奏](/raw/design/layout.md)。

## 组件 API

### QuireTypography

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| as | 否 | "p" | Native element to render; defaults to a paragraph. |
| variant | 否 | — | Optional typography role overriding the element's default appearance. |
| codeStyle | 否 | — | Optional Markdown-like surface for as="code"; plain preserves unboxed code text. |
| title | 否 | — | Expansion shown by Tooltip for abbr; native title for other text elements. |

**as**

```ts
QuireKitTypographyElement | undefined
```

```ts
undefined | "p" | "span" | "div" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "strong" | "b" | "em" | "i" | "cite" | "dfn" | "a" | "code" | "pre" | "kbd" | "samp" | "var" | "small" | "mark" | "del" | "s" | "ins" | "u" | "sub" | "sup" | "abbr"
```

**variant**

```ts
keyof QuireKitSemanticTypographyTokens | undefined
```

```ts
undefined | "code" | "display" | "pageTitle" | "sectionTitle" | "heading" | "body" | "control" | "compact" | "helper"
```

**codeStyle**

```ts
"plain" | "inline" | undefined
```

```ts
undefined | "plain" | "inline"
```

**title**

```ts
string | undefined
```

```ts
undefined | string
```

#### Events

无。

#### Slots

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| default | 否 | — | Native text content; isolate embedded controls with data-qk-not-typography. |

**default**

```ts
any
```

#### 公开实例成员

无。
