# Typography

> 用语义标签与统一文字角色呈现标题、正文、说明和行内内容。

网页来源：/components/typography

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

接入前置：[开始使用](/raw/components/getting-started.md)（Vue、样式、主题与图标 Provider）。

## 基本用法

`as` 决定 HTML 语义，默认是段落 `p`。标题使用 `h1`–`h6`，正文、说明和重要内容保留各自语义；组件不增加段间距，间距由外层布局安排。

### 示例：typography/basic

文件：`basic.vue`

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

<template>
  <div class="grid gap-qk-surface p-qk-surface" data-typography-basic>
    <QuireTypography as="h2">把想法写清楚</QuireTypography>
    <QuireTypography>从共同目标开始，为计划补充背景、参与者和下一步。</QuireTypography>
    <QuireTypography as="h3">给下一位参与者留下线索</QuireTypography>
    <QuireTypography>用<strong>明确的措辞</strong>说明决定，也留出空间解释<em>为什么要做</em>。</QuireTypography>
    <QuireTypography as="small" class="text-qk-text-secondary">最后整理于 2026 年 9 月 · 约 3 分钟阅读</QuireTypography>
  </div>
</template>
```

## 选择文字角色

`variant` 一次应用字体、字号、行高、字重和字距，不改变 `as` 的标签。九种角色与[文字规范](/raw/design/typography.md)相同，适合让不同语义元素使用一致的外观。

### 示例：typography/roles

文件：`roles.vue`

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

const roles = [
  ["display", "让内容成为焦点"], ["pageTitle", "项目工作空间"], ["sectionTitle", "从共同目标开始"],
  ["heading", "本周工作安排"], ["body", "整理讨论中的关键结论，让信息清楚、连贯。"],
  ["control", "查看全部文档"], ["compact", "12 份文档 · 最近更新"],
  ["helper", "更改会自动保存。"], ["code", "editor.commands.focus()"]
] satisfies [QuireKitTypographyVariant, string][];
</script>

<template>
  <div class="grid gap-qk-group p-qk-surface" data-typography-roles>
    <div v-for="[variant, text] in roles" :key="variant" class="grid gap-qk-inline">
      <QuireTypography as="span" variant="helper" class="text-qk-text-secondary">{{ variant }}</QuireTypography>
      <QuireTypography :as="variant === 'code' ? 'code' : 'p'" :variant="variant" :data-role="variant">{{ text }}</QuireTypography>
    </div>
    <QuireTypography as="h3" variant="compact" data-role-override>这仍然是 h3 标题，外观使用 compact 角色。</QuireTypography>
  </div>
</template>
```

`h1` 默认使用 `pageTitle`，`h2` 使用 `sectionTitle`，`h3`–`h6` 使用 `heading`。更深的标题继续保留语义层级，外观不必继续缩小。

## 行内代码

`as="code"` 默认展示纯代码文字。设置 `code-style="inline"` 可添加与 Markdown 相同的背景、边框和内边距，适合正文中的命令、属性名和标识；长内容仍能折行。`variant="code"` 只选择字体角色，不自动添加底框。

### 示例：typography/code

文件：`code.vue`

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

<template>
  <div class="grid gap-qk-surface p-qk-surface" data-typography-code>
    <QuireTypography>代码文字：<QuireTypography as="code">editor.commands.focus()</QuireTypography></QuireTypography>
    <QuireTypography>行内代码：调用 <QuireTypography as="code" code-style="inline">editor.commands.focus()</QuireTypography> 将焦点移回编辑器。</QuireTypography>
    <QuireTypography>长标识会随正文折行：<QuireTypography as="code" code-style="inline">document.settings.collaboration.defaultPermissions</QuireTypography>。</QuireTypography>
  </div>
</template>
```

纯 HTML 可使用 `<code class="qk-typography qk-typography--inline-code">`。整块源码使用 [CodeBlock](/raw/components/code-block.md)，Prose 正文中的行内代码默认已有这一外观。

## 行内语义

使用 `strong` 表示重要内容，`em` 表示语气强调，`mark` 标记相关文字，`del` / `ins` 表示删除与插入，`sub` / `sup` 表示上下标。既可嵌套原生标签，也可以给 Typography 设置相应 `as`。

### 示例：typography/inline

文件：`inline.vue`

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

<template>
  <div class="grid gap-qk-surface p-qk-surface" data-typography-inline>
    <QuireTypography>请在<strong>周五前</strong>确认计划，先说明<em>为什么要做</em>，再标出<mark>需要共同决定的部分</mark>。</QuireTypography>
    <QuireTypography>时间从 <del>9 月 18 日</del> 调整为 <ins>9 月 21 日</ins>。<s>旧安排</s>已不再适用。</QuireTypography>
    <QuireTypography>水的化学式为 H<sub>2</sub>O，面积以 m<sup>2</sup> 计量；变量 <var>n</var> 表示参与人数。</QuireTypography>
    <QuireTypography>应用程序接口（<QuireTypography as="abbr" title="Application Programming Interface">API</QuireTypography>）示例调用 <code>editor.commands.focus()</code>，返回 <samp>true</samp>。</QuireTypography>
    <QuireTypography>用 <QuireTypography as="mark">组件标记重点</QuireTypography>，并参考 <cite>项目协作指南</cite> 的说明。</QuireTypography>
    <QuireTypography class="text-qk-text-secondary">辅助文字中的 <strong>重要内容</strong> 继承当前颜色。<QuireTypography as="a" href="#" @click.prevent>查看补充说明</QuireTypography>。</QuireTypography>
  </div>
</template>
```

文字和强调继承上下文颜色；`mark` 使用随主题变化的高亮背景。`as="abbr"` 的 `title` 通过 [Tooltip](/raw/components/tooltip.md) 展示：悬停或 Tab 聚焦点状下划线即可查看，Esc 关闭。关键缩写仍应在正文里展开说明。链接须提供 `href`；业务命令使用 [Button](/raw/components/button.md)。

## 纯 HTML 与样式隔离

原生元素或容器使用 `qk-typography`，获得同一套语义样式。`qk-type-body`、`qk-type-heading` 等工具类可直接应用完整角色，颜色通过父级或语义颜色 class 设置。

### 示例：typography/native

文件：`native.vue`

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

<template>
  <div class="grid gap-qk-group p-qk-surface" data-typography-native>
    <div class="qk-typography grid gap-qk-surface" data-native-text>
      <h3>原生 HTML</h3>
      <p>通过 <code>qk-typography</code> 应用语义排版，<strong>强调继承文字色</strong>。</p>
      <div data-qk-not-typography class="flex flex-wrap items-center gap-qk-inline" data-typography-island>
        <QuireButton>保留按钮自己的排版</QuireButton>
        <QuireTypography as="span" variant="helper">独立的说明文字</QuireTypography>
      </div>
    </div>
    <div class="grid gap-qk-surface" data-component-text>
      <QuireTypography as="h3">Vue 组件</QuireTypography>
      <QuireTypography>通过 <code>QuireTypography</code> 应用语义排版，<strong>强调继承文字色</strong>。</QuireTypography>
    </div>
    <p class="qk-type-helper text-qk-text-secondary m-0">只需要完整角色时，也可以直接使用 qk-type-helper。</p>
  </div>
</template>
```

嵌入控件时用 `data-qk-not-typography` 隔离后代样式；在隔离区内再次使用 Typography 可开启独立排版。该作用域与 Prose 共用 `data-qk-not-prose` 隔离标记，需要支持 CSS `@scope` 的浏览器。

## 与其他组件组合

文字展示可以组合 [Clipboard](/raw/components/clipboard.md)、[Editable](/raw/components/editable.md)、[Kbd](/raw/components/kbd.md) 和 [CodeBlock](/raw/components/code-block.md)。这些组件负责复制、编辑、键帽和代码操作，Typography 负责说明与文字层级。

### 示例：typography/composition

文件：`composition.vue`

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

<template>
  <div class="p-qk-surface" data-typography-composition>
    <QuireCard as="section" title="分享项目说明" description="把文档编号交给协作者，方便继续讨论。">
      <div class="grid gap-qk-surface">
        <div class="flex flex-wrap items-center gap-qk-inline">
          <QuireTypography as="code">QK-2026-0916</QuireTypography>
          <QuireClipboard value="QK-2026-0916" mode="icon" size="xs" />
        </div>
        <QuireTypography class="text-qk-text-secondary">返回文档后，使用 <QuireKbd :keys="['⌘', 'K']" label="Command 加 K" /> 查找需要的操作。</QuireTypography>
      </div>
    </QuireCard>
  </div>
</template>
```

## 选择 Typography 还是 Prose

| 需要呈现的内容 | 使用方式 |
| --- | --- |
| 卡片标题、正文、表单辅助文字 | Typography；外层布局组织间距。 |
| 一篇含标题、段落、列表、引用、表格的文章 | [Prose](/raw/components/prose.md)；统一整篇内容的阅读节奏。 |
| 没有 Vue 的语义 HTML | `qk-typography` / `qk-prose`，均由 UnoCSS preset 或独立 `quirekit.css` 提供。 |

## 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
```

#### 公开实例成员

无。
