Hero Extension Playbook
Hero work should start from the contract layer and flow downward into runtime and rendering.
Core Hero Extension Points
.vitepress/utils/vitepress/api/frontmatter/hero/HeroFrontmatterApi.ts.vitepress/utils/vitepress/api/frontmatter/hero/HeroTypographyRegistryApi.ts.vitepress/utils/vitepress/api/frontmatter/hero/FloatingElementRegistryApi.ts.vitepress/utils/vitepress/runtime/hero/navAdaptiveState.ts.vitepress/theme/components/hero/background/BackgroundLayer.vue.vitepress/config/shaders/index.ts.vitepress/config/shaders/templates/base-shader.ts
Add a Typography Style
Do not add a new if styleType === ... branch directly in hero components.
Register the style through the typography registry and let the runtime resolve it.
Use one of these registration modes:
- Shared built-in style
Add the definition to
DEFAULT_TYPOGRAPHY_STYLE_DEFINITIONSin.vitepress/utils/vitepress/api/frontmatter/hero/HeroTypographyRegistryApi.ts. - Project-local bootstrap style
Call
heroTypographyRegistry.registerStyle(...)from a startup module imported by.vitepress/theme/index.ts.
Keep the canonical type and all aliases lowercase because the registry normalizes them.
ts
import { heroTypographyRegistry } from "@utils/vitepress/api/frontmatter/hero";
heroTypographyRegistry.registerStyle({
type: "editorial-soft",
aliases: ["soft-editorial"],
motion: {
intensity: 0.9,
title: { x: 6, y: -4, scale: 1.03 },
text: { x: 8, y: 3, scale: 1.02 },
tagline: { x: 4, y: 6, scale: 1.01 },
image: { x: 5, y: -2, scale: 1.015 },
transitionDuration: 520,
transitionDelayStep: 36,
transitionEasing: "cubic-bezier(0.2, 0.9, 0.2, 1)",
},
});Registration checklist:
- Define motion defaults in
HeroTypographyRegistryApi.ts. - Keep the canonical type and aliases lowercase.
- If the new style needs different structure or class hooks, update hero content components or the shared hero typography CSS.
- Verify the resolved style through
.vitepress/utils/vitepress/runtime/hero/typographyState.ts, not by copying motion logic into multiple components. - Add a real frontmatter example and update the docs.
Create a New Hero Page
Use a hero page when the page itself is a landing surface instead of a normal article.
yaml
---
layout: home
hero:
name: Developer Docs
text: Extend Hero, Runtime, and Nav
tagline: Contract-first configuration with shared runtime behavior
typography:
type: floating-tilt
actions:
- theme: brand
text: Hero Extension
link: /en/doc/heroExtension
---Checklist:
- Start from
layout: home. - Keep hero configuration in frontmatter instead of page-local component hacks.
- If the page becomes a main entry point, update the docs hub and locale nav in the same change.
Add a Floating Element Type
ts
import { floatingElementRegistry } from "@utils/vitepress/api/frontmatter/hero";
floatingElementRegistry.registerType({
type: "keyword-chip",
renderAs: "badge",
className: "floating-keyword-chip",
});Add a New Hero Feature
When the feature is author-facing and reusable:
- Add the field to
.vitepress/utils/vitepress/api/frontmatter/hero/HeroFrontmatterApi.tsand normalize it there. - If it needs shared state, timing, observers, or viewport logic, add or extend
.vitepress/utils/vitepress/runtime/hero/**. - Render the feature only after the contract shape is stable.
- Add real examples in both locale trees.
- If it changes home hero actions or named links, update the related nav/home docs at the same time.
Add a Shader Preset
- Create or extend a preset under
.vitepress/config/shaders/**. - Reuse helpers from
.vitepress/config/shaders/templates/base-shader.tswhere possible. - Export the preset from
.vitepress/config/shaders/index.ts. - Reference the preset through normalized frontmatter rather than page-local imports.
Add a New Background Renderer Type
- Add the type to
HeroFrontmatterApi.ts. - Add the rendering branch in
.vitepress/theme/components/hero/background/BackgroundLayer.vue. - Create a dedicated renderer under
.vitepress/theme/components/hero/background/. - Move observers or theme-sensitive lifecycle into shared runtime modules.
- Add real examples in both locale trees.
Extend Nav and Search Visuals
- Put adaptive calculations in
.vitepress/utils/vitepress/runtime/hero/navAdaptiveState.ts. - Put theme-safe value resolution in the shared theme runtime.
- Expose author-facing colors through frontmatter-backed CSS variables.
- Avoid direct DOM theme reads inside nav, search, or hero child components.
Hero Extension Checklist
- The new field or type is normalized in the API layer.
- Rendering components consume normalized values only.
- Theme and resize behavior use shared runtime helpers.
- The change is documented in both
docs/enanddocs/zh. yarn buildpasses before syncing the change elsewhere.