Files
personal/docs/02-visual-foundations.md
T
virtheart 040dc24701 docs: 建立实现文档与 AI 复刻提示词合集
- docs/README.md 总览:技术栈、架构一图流、6 条硬性约定(踩坑沉淀)
- 01 逆向方法论:chunk 模块定位、SSR bs4 提取、CDP 探针、验证闭环、事故速查表
- 02 视觉基础:-z-1 层叠三铁律、十字网格 SVG 算法、设计令牌(含 --code-* lab 值)、字体
- 03 滚动/过渡:window Lenis 双模式、scrollEnv、hq:pendingScrollAnchor、cover/reveal 状态机
- 04 WebGL:场景组成、DOM 注册表、CanvasSizeGuard 竞态修复、loadingBus 加载门
- 05 首页区块:ScrambleReveal 算法、WorkSection/HyperSpace/Footer、自定义滚动条、BGM 手势重试
- 06 详情页 MDX:内容管线类型、MdxHeading/TOC/CodeBlock/ArticleFooter 逐类逐值
- 07 口令系统:cookie/API/网格过滤联动/长按锁定
- 08 验证工作流:CDP 断言集、像素三层共存、回归清单
- prompts.md:10 条可直接投喂的复刻提示词(全局约定段 + 每系统一条 + 万能验证条)
2026-09-01 22:55:57 +08:00

7.5 KiB
Raw Blame History

02 · 视觉基础:层叠系统 · 设计令牌 · 字体 · 十字网格

1. 层叠系统(整个站最容易翻车的地方)

原站的 body 直接子元素顺序

0 <div>            ← -z-1 fixed WebGL 容器(R3F Canvas)
1 <div class="z-30 fixed inset-0 pointer-events-none">   ← dot overlay
2 <div class="z-20 fixed inset-0 … mix-blend-difference"> ← 十字网格
3 header (z-50 fixed)
4 <main>…</main>   ← 普通流内容

关键事实(CSS 绘制顺序):没有 z-index 的 fixed 元素按 DOM 顺序画在普通流内容之后——所以原站给 WebGL 容器 -z-1(负值把它压到最底,但仍在根背景之上)。footer 区块是 z-10 relative(原站 2689132c 模块 28192)。

三个铁律

// ① canvas 容器(components/canvas/HeroScene.tsx)
<div className="top-0 left-0 -z-1 fixed w-full h-dvh lg:h-screen pointer-events-none">

// ② 网格(components/dom/BackgroundGrid.tsx)
<div className="z-20 fixed inset-0 w-full h-full pointer-events-none mix-blend-difference">

// ③ footer(components/dom/FooterSection.tsx)
<footer className="z-10 relative …">
/* ④ 背景只挂 html —— CSS 背景传播到画布底色(canvas 之下);挂 body 会
      变成普通流内容画布,盖住 -z-1 的场景(真实事故) */
html { background-color: var(--bg-color); }

网格的挂载门控

BackgroundGrid 复刻原模块 97839 useHomeLoadingGate:

  • 加载期:pathname === "/" && !heavyReady → 返回 null(LoadingOverlay 盖着)
  • 非首页路由 → null(原站详情页根本没有这个 div;用户确认过)
  • ⚠️ 早退必须在所有 hooks 之后:组件常驻 layout,路由切换时若 hook 数量变化 → "Rendered more hooks than during the previous render" 整页崩(真实事故)。模式:
export default function BackgroundGrid() {
  const pathname = usePathname();
  const [size, setSize] = useState({ w: 0, h: 0 });      // hook
  const [heavyReady, setHeavyReady] = useState(pathname !== '/'); // hook
  useEffect(() => { … }, [pathname]);                     // hook
  const paths = useMemo(() => { … }, [w, h]);             // hook
  if (pathname !== '/') return null;                      // ← 全部 hooks 之后
  if (pathname === '/' && !heavyReady) return null;
  return (<div className="z-20 fixed …"><svg …/></div>);
}

网格 SVG 算法(1:1)

  • shape-rendering-crispEdges,竖线 x 坐标 Math.round(x)+0.5(1px 物理对齐)
  • 边距 n:w < 1024 ? 16 : 56;列数 cols:w < 1280 ? 2 : 3,列位置 n + (k/cols)*innerW
  • 横线只有两条:y = h/3 - 12 与 y = 2h/3 + 12(即三分线各让出 12px 缝)
  • 横线在竖线交叉处断开 12px(M x+12 y H x_next-12);竖线在横线处留缝(三段)
  • 交叉点画 #FFFFFF opacity 0.4 的 12px 十字(±6),容器 mix-blend-difference 让白十字在浅底上呈现反相
  • 竖线分三段(横线 y 值 ±24 之间断开)

2. 设计令牌(app/globals.css)

标签色(light 主题)

:root {
  --bg-color: rgb(251, 250, 244);
  --text-color: rgba(0, 0, 0, 1);
  --selection-bg: #c0fe04;          /* 品牌荧光绿 */
  --label: 0, 0, 0;
  --label-d: 54, 54, 48;
  --label-1: rgba(var(--label), 1);        /* 主文字 */
  --label-3: rgba(var(--label-d), 0.32);   /* 三级(链接下划线) */
  /* Tailwind @theme: --color-l1/l2/l3/line/b1/be/selection */
}

text-l1/l2/l3、bg-b1、border-line 都映射到这些;--label-d 用于代码 token 的 rgba 透明变体。

代码 token 色(--code-*,来自原 CSS 的 lab() 精确值)

--code-comment: rgba(var(--label-d), 0.45);
--code-string:  lab(43.8263% -47.6118 18.596);
--code-number:  lab(46.7992% 8.99872 72.9973);
--code-keyword: lab(43.3789% 36.2819 -73.3524);
--code-function: lab(47.3165% -8.24019 -45.3882);
--code-tag:     lab(47.2741% 51.266 23.7532);
--code-operator: rgba(var(--label-d), 0.75);

原站 prism token 类名(token keyword module 等)→ CSS 里按类映射到上述变量;我们的详情页直接复用(token HTML 由原站 SSR 提取,类名一致)。Tailwind v4 原生支持 lab(),构建产物原样保留。

点状下划线(u 元素)

原站的 <u> 不是下划线,是径向渐变点串:

[&_u]:no-underline [&_u]:pb-[6px] [&_u]:[box-decoration-break:clone]
[&_u]:[background-image:radial-gradient(circle_at_center,var(--color-l2)_0.65px,transparent_0.7px)]
[&_u]:[background-size:5px_3px] [&_u]:[background-repeat:repeat-x]
[&_u]:[background-position:left_bottom]

3. 字体(app/layout.tsx localFont)

变量 字体 用途
--font-tiktok TikTokSans.ttf 正文/标题(大标题另加 fontVariationSettings:"wdth" 120)
--font-mono GeistMono[wght].ttf 代码/数字
--font-mono-2 DepartureMono-Regular.otf header/页脚链接(点阵感)

大标题统一类:font-bold text-3xl! lg:text-5xl! leading-tight tracking-tight + style={{fontVariationSettings:'"wdth" 120'}}。

4. 布局骨架

  • Banner:grid grid-cols-12 grid-rows-[auto_1fr] px-4 lg:px-14 py-18 lg:py-24 w-full h-dvh lg:h-screen
  • 大标题行:flex flex-col self-end order-1 lg:order-2 col-span-12 … text-[7.2svw] lg:text-[6svw] 2xl:text-[5svw] xl:text-[5.6svw] uppercase leading-none
  • About 文本列:col-span-12 sm:col-span-7 lg:col-span-8 sm:col-start-6 lg:col-start-5
  • 文章容器:mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px] text-l1
  • 内联链接(MdxA):text-[color:var(--label-1)] underline underline-offset-4 decoration-[color:var(--label-3)] transition-colors lg:hover:decoration-[color:var(--label-2)]

5. 提示词(让 AI 复刻这一层)

我在做 haoqi.design 的 1:1 克隆(Next.js App Router + Tailwind v4 + R3F)。请严格按以下层叠结构实现,这些类名是逐字从原站 bundle 提取的,不要"优化":

  1. WebGL 画布容器:top-0 left-0 -z-1 fixed w-full h-dvh lg:h-screen pointer-events-none(内部一个全屏 Canvas,pointer-events:none)。
  2. 十字网格:z-20 fixed inset-0 mix-blend-difference 的 SVG,仅首页挂载(用 usePathname 门控;早退必须放在所有 hooks 之后,否则路由切换会 hook 数量崩溃)。网格画法:背景 251,250,244;竖线位于内边距 56px(窄屏 16px)起的 2/3 等分点,Math.round(x)+0.5 对齐物理像素,shape-rendering crispEdges;两条横线在垂直三分线各偏移 12px(h/3-12 和 2h/3+12),横线遇竖线断开 12px,交叉点画白色 opacity .4 的 12px 十字。
  3. 背景色只写在 html 根元素(rgb(251,250,244)),绝对不要挂在 body 上——否则 body 背景作为普通流内容会盖住 -z-1 的画布。
  4. footer 用原站的 z-10 relative flex flex-col justify-center p-6 lg:p-16 w-full h-dvh lg:h-screen pointer-events-none。
  5. 设计令牌照抄:主文字 rgba(0,0,0,1)、次要 rgba(54,54,48,.6)、三级 rgba(54,54,48,.32)、分隔线 rgba(54,54,48,.1)、荧光绿 #c0fe04;代码高亮用原站 CSS 的 lab() 值(我会给你 7 个 --code-* 变量的精确值)。字体三套 localFont:TikTokSans(正文+大标题,大标题加 fontVariationSettings "wdth" 120)、GeistMono(代码)、DepartureMono(header 链接)。 完成后用无头 Chrome + CDP 截图验证:首页 banner 文案区域深色像素占比 >5%(证明文字画在场景之上)、场景区域平均色不等于页面底色(场景可见)、网格线带深色像素 >20%。三层必须同时成立。