# 标题

## 使用方法

`Heading` 用于渲染页面和区块的标题：`level` 决定语义层级（h1–h6），`type` 可以在不改变语义的前提下调整视觉样式，两者搭配能同时照顾文档结构与视觉设计。从独立入口导入即可，结构样式会随组件自动加载：

```vue
<script setup lang="ts">
import { Heading } from '@astryx-vue/core/Heading'
</script>

<template>
  <Heading :level="1">
    页面标题
  </Heading>
  <Heading :level="2" type="display-2">
    数据概览
  </Heading>
</template>
```

## 最佳实践

| 指引 | 实践 |
| --- | --- |
| 推荐 | 按文档大纲选择 `level`，保持层级连贯、不跳级，屏幕阅读器和搜索引擎才能正确理解页面结构。 |
| 推荐 | 需要营销页或大号展示效果时，用 `type="display-*"` 覆盖视觉样式，同时保留语义正确的 `level`。 |
| 推荐 | 层级较低的次要标题可以使用 `color="secondary"`，让它在视觉上退后一步，主要标题更突出。 |
| 避免 | 为了视觉大小而选用与页面结构不符的 `level`：视觉样式交给 `type` 控制，语义层级仍由 `level` 决定。 |
| 避免 | 在标题中塞入长段落：标题应简短概括内容，详细说明放到正文里。 |

## 示例

### 卡片网格

响应式卡片网格。标题和说明被截断，让每张卡片高度一致。

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Heading } from '@astryx-vue/core/Heading'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <Card :width="300">
    <VStack :gap="2">
      <Heading :level="3">
        Card Title
      </Heading>
      <Text type="body" display="block" :max-lines="2">
        This is a card description that might be quite long and needs to be truncated after two lines to keep the card compact and uniform.
      </Text>
      <Text type="supporting" display="block">
        Updated 1 hour ago
      </Text>
    </VStack>
  </Card>
</template>
```

### 页面层级

真实页面布局，用 h1 到 h3 和配套说明展示标题层级。

```vue
<script setup lang="ts">
import { Heading } from '@astryx-vue/core/Heading'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <VStack :gap="6" width="100%" style="max-width: 400px">
    <VStack>
      <Heading :level="1">
        Dashboard Overview
      </Heading>
      <Text type="supporting" display="block">
        Last updated 5 minutes ago
      </Text>
    </VStack>
    <VStack>
      <Heading :level="2">
        Recent Activity
      </Heading>
      <Text type="body" display="block">
        Here's what's been happening in your workspace.
      </Text>
    </VStack>
    <VStack>
      <Heading :level="3">
        Today
      </Heading>
      <Text type="body" display="block">
        • Project Alpha updated<br>
        • 3 new comments<br>
        • Task completed
      </Text>
    </VStack>
  </VStack>
</template>
```

### 截断

在有限宽度里把标题截成一行或两行，并以省略号结尾。截断后悬停可读全文。

```vue
<script setup lang="ts">
import { Heading } from '@astryx-vue/core/Heading'
</script>

<template>
  <div class="heading-preview__clamp">
    <div class="heading-preview__box">
      <Heading :level="2" :max-lines="1">
        Very Long Heading That Will Be Truncated To One Line With Ellipsis
      </Heading>
    </div>
    <div class="heading-preview__box">
      <Heading :level="2" :max-lines="2">
        Very Long Heading That Will Be Truncated To Two Lines To Keep Card Layout Compact
      </Heading>
    </div>
  </div>
</template>
```

### 大纲与对齐

视觉层级和读屏层级可以分开。删除线和对齐跟着标题走。

```vue
<script setup lang="ts">
import { Heading } from '@astryx-vue/core/Heading'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <VStack :gap="2" style="width: 100%; max-width: 360px">
    <Heading :level="2" :accessibility-level="1" justify="center">
      Quarterly review
    </Heading>
    <Heading :level="3" has-strikethrough justify="start">
      Draft agenda
    </Heading>
    <Text as="p" justify="center" text-wrap="balance">
      The visual size stays on the page. The outline level is what assistive technology reads.
    </Text>
  </VStack>
</template>
```

## Props

| 名称 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `level` | `HeadingLevel` | - | 标题层级（1–6），决定渲染 h1–h6 中的哪个语义元素。数字字符串按数字读；没写或不是 1–6 时按 2 级渲染，并在开发时给出警告。 |
| `type` | `HeadingType` | - | 视觉类型变体，可选 display-1、display-2、display-3、body、large、label、supporting。 |
| `color` | `HeadingColor` | `'primary'` | 标题的文字颜色，可选 primary、secondary、accent、inherit。 |
| `weight` | `HeadingWeight` | - | 字重覆盖，可选 regular、medium、semibold、bold。 |
| `display` | `HeadingDisplay` | `'block'` | 显示类型：`block` 或 `inline`。 |
| `accessibilityLevel` | `1 \| 2 \| 3 \| 4 \| 5 \| 6` | - | 和视觉 `level` 不同时，读屏使用的大纲级别。元素仍是 `h{level}`。 |
| `textWrap` | `'wrap' \| 'nowrap' \| 'balance' \| 'pretty'` | - | CSS `text-wrap`。 |
| `wordBreak` | `'break-word' \| 'break-all'` | 单行截断为 `break-all`，多行为 `break-word` | 截断时长词如何断开。没有截断时，比一行还长的串（URL、ID）会换行（`overflow-wrap: break-word`），普通文档流里不会撑出横向滚动。放在 flex 行里时，记得给 flex 子项设 `min-width: 0` 让它能收缩。你自己设了 `overflow-wrap: anywhere` 的容器管不到这里的文字；Astryx 自带的容器会把它们的换行方式传进来。 |
| `justify` | `'start' \| 'center' \| 'end'` | `'start'` | 对齐方式。`start` 和 `end` 跟随书写方向。 |
| `hasCapsize` | `boolean` | `false` | 用 `text-box-trim` 裁掉大写字母高度以上的空白和基线以下的空白，让字形贴住盒子边缘。打开后强制块级布局。 |
| `hasStrikethrough` | `boolean` | `false` | 给文字加删除线。 |
| `hasTruncateTooltip` | `boolean \| 'above' \| 'below' \| 'start' \| 'end'` | `true` | 截断之后要不要把全文放进提示。`false` 关掉，同时也不再测量。没被截断时不会弹出。提示等到第一次悬停、轻点或键盘聚焦才挂载，在那之前元素上没有提示层，也没有 `aria-describedby`。 |
| `maxLines` | `number` | `0` | 最大显示行数，超出部分截断并显示省略号，0 表示不截断。 |

## 原生属性

根元素为 `<h1>` 至 `<h6>`。

以下内容传入根元素：

- HTML 属性。
- `aria-*` 属性。自己写的 `aria-level` 优先于 `accessibilityLevel` 算出的值。
- `data-*` 属性。
- `class`。
- `style`。`maxLines` 大于 1 时，行数截断会替换 `style` 里的 `-webkit-line-clamp`。
