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 条可直接投喂的复刻提示词(全局约定段 + 每系统一条 + 万能验证条)
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
# 01 · 逆向方法论
|
||||
|
||||
原站 haoqi.design 是**全客户端渲染**(SSR body 里几乎没有内容),所有信息只能从两个来源挖:
|
||||
`haoqi_clone/_next/static/chunks/*.js`(编译产物)和运行中的页面(CDP 探测)。本文记录整套"挖掘→移植→验证"的流程。
|
||||
|
||||
## 1. 资产镜像
|
||||
|
||||
`haoqi_clone/` 保存了原站镜像:`_next/static/chunks/*.js`(全部 JS chunk)、`_next/static/css/*.css`(主题变量来源)、`img/`、`model/`、`sticker_img/`。公开资产(图片/模型/音频)直接复制进 `public/`。
|
||||
|
||||
## 2. 从 chunk 里读组件
|
||||
|
||||
原站是 Turbopack 产物,模块按编号组织:`(globalThis.TURBOPACK||[]).push([..., <moduleId>, (t)=>{...}])`。找组件的方法:
|
||||
|
||||
1. **用独特文案定位模块**:`grep -o "文案片段" *.js` → 找到所在 chunk 与模块号,再往前后各扫几千字符读 JSX 编译体(`(0,s.jsxs)("div",{className:"...",children:[...]})`)。
|
||||
2. **用类名反查**:如 `"z-10 relative"`、`grid-rows-[auto_1fr]` 这类长类名串是唯一指纹。
|
||||
3. **样式表挖变量**:原 CSS 里有 `--code-*`、`--label-*` 的 `lab(...)` 精确值,直接抄。
|
||||
4. 已挖出的关键模块(编号 → 内容):
|
||||
|
||||
| 模块 | 内容 |
|
||||
|---|---|
|
||||
| 31250 | MdxHeading(标题锚点:slugify、hover #、点击复制链接) |
|
||||
| 78825 | MdxTableOfContents(左侧目录:集合、高亮 top≤96、点击滚动) |
|
||||
| 93325 | MdxPre(代码块:语言标签 + COPY + 行号行) |
|
||||
| 54450 | ArticleFooter(Metadata:实时视口尺寸/字符数 + Links) |
|
||||
| 71358 | ScrambleReveal(字符扰动揭示算法) |
|
||||
| 88106 区域 | `PENDING_SCROLL_ANCHOR_SESSION_KEY = "hq:pendingScrollAnchor"` |
|
||||
| 28116 | WORK_ITEMS 数据(含 passcodeProtected 首项) |
|
||||
| 97839 | useHomeLoadingGate(`"/"===pathname && !readyToLoadHeavy`) |
|
||||
|
||||
## 3. 从运行页面提取(CDP)
|
||||
|
||||
Chrome 开远程调试端口,用 websocket 发 `Runtime.evaluate`:
|
||||
|
||||
```bash
|
||||
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
|
||||
--remote-debugging-port=9223 --window-size=1920,1080 \
|
||||
--user-data-dir=/tmp/chrome-probe --no-first-run about:blank &
|
||||
WS=$(curl -s http://localhost:9223/json | python3 -c "…取 page 的 webSocketDebuggerUrl…")
|
||||
```
|
||||
|
||||
本会话沉淀的探针脚本(/tmp):`cdp_nav.py`(导航)、`cdp_step.py`(单条 JS 表达式)、`cdp_shot3.py`(截图)、错误监听器(Runtime.exceptionThrown + Log.entryAdded 合流 pump)。注意:
|
||||
|
||||
- `Page.captureScreenshot` 返回 base64 PNG,**用 PIL 做像素统计**即可"看"页面(当前模型不读图也能验证视觉)。
|
||||
- 原站页面直接打开会报 "Application error"(WebGL/环境原因),SSR + chunk 更可靠。
|
||||
|
||||
## 4. 从 SSR HTML 提取内容(bs4)
|
||||
|
||||
详情页文章在 SSR 里是完整 HTML(`/tmp/detail-*.html`)。用 BeautifulSoup 解析:
|
||||
|
||||
- 文章容器:`article[data-mdx-article]`;块级元素按**文档序扁平收集**(排除 header/footer/pre 内部),因为不同文章的 prose 容器嵌套层级不一样。
|
||||
- 代码块:`pre>code.language-X` 的 `decode_contents()` 就是**原站 prism 高亮后的 token HTML**(span.token + 行号行),直接存进 `content/workArticles.ts`,渲染时 `dangerouslySetInnerHTML`。
|
||||
- 标题:`h2/h3` 的 `id` 和文本(注意文本里混着锚点 `#` span,要剥掉)。
|
||||
- 内联:链接 > code > strong/em 优先级展平成 `InlineSeg` 数组。
|
||||
|
||||
## 5. 验证闭环(每改一处必走)
|
||||
|
||||
1. `npx tsc --noEmit -p .`
|
||||
2. dev server 探测(`next.config.ts` 变更后等 6–8s)
|
||||
3. CDP 断言 DOM 状态(元素存在性 / 计算样式 / rect)
|
||||
4. **像素断言**:截图 → PIL 统计区域深色像素占比(文字可见 ≈ 5–10%),三层共存断言(场景均值 ≠ 页面底色、网格线带 >20%、文案带 >5%)
|
||||
5. `npx next build`
|
||||
6. 中文 `feat:`/`fix:` 提交
|
||||
|
||||
## 6. 踩坑速查(本会话真实事故)
|
||||
|
||||
| 事故 | 根因 | 教训 |
|
||||
|---|---|---|
|
||||
| 首页文案/作品说明消失 | WebGL 容器 `z-auto fixed` 按 CSS 绘制顺序压过普通流 | fixed 层叠必须照抄原站 `-z-1` |
|
||||
| 修完上条场景被盖 | `html, body` 都设了背景色,body 背景画在 `-z-1` 之上 | 背景只挂 `html` 根 |
|
||||
| 详情→首页后整页崩 | BackgroundGrid 在 useMemo 之前 `return null`,路由切换 hook 数量变化 | 常驻组件早退放 hooks 之后 |
|
||||
| 详情页不能滚动 | 嵌套 `fixed + overflow-y-auto` 吞掉滚轮(window 级 Lenis) | 详情页用普通流 + window 滚动 |
|
||||
| BGM 静音 | 挂载时 autoplay 被策略拒绝 | 首次手势 pointerdown/keydown/touchstart 重试 |
|
||||
| canvas 尺寸 1440×150 | R3F 首测与 CSS 竞态,RO 不再触发 | CanvasSizeGuard 检测 mismatch 重跑 setSize |
|
||||
@@ -0,0 +1,136 @@
|
||||
# 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)。
|
||||
|
||||
### 三个铁律
|
||||
|
||||
```tsx
|
||||
// ① 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 …">
|
||||
```
|
||||
|
||||
```css
|
||||
/* ④ 背景只挂 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" 整页崩(真实事故)。模式:
|
||||
|
||||
```tsx
|
||||
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 主题)
|
||||
|
||||
```css
|
||||
: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() 精确值)
|
||||
|
||||
```css
|
||||
--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>` 不是下划线,是**径向渐变点串**:
|
||||
|
||||
```css
|
||||
[&_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%。三层必须同时成立。
|
||||
@@ -0,0 +1,88 @@
|
||||
# 03 · 滚动系统 · 路由过渡 · 锚点定位
|
||||
|
||||
## 1. 双滚动模式(window Lenis vs 原生)
|
||||
|
||||
原站的 Lenis 包在**首页 main 容器**上(内容在容器里滚);详情页是原生容器滚动。我们的 Lenis 是 **window 级**,因此:
|
||||
|
||||
- **首页(pathname === "/")**:挂 Lenis(lerp 默认),window 滚动被接管
|
||||
- **详情页**:`scrollEnv.setLenis(null)` 销毁 Lenis,window 原生滚动
|
||||
- `<main>` 绝不能是滚动容器 —— sticky(hyper-space 区块)只在 window 滚动下 pin(`app/page.tsx` 顶部注释就是这个警告)
|
||||
|
||||
`components/dom/SmoothScroller.tsx` 职责:
|
||||
1. Lenis 生命周期(仅首页创建,其它路由销毁 + rafId 清理)
|
||||
2. 每次路由变更 scroll 重置到顶部(`history.scrollRestoration = 'manual'`;bfcache pageshow persisted 也重置)
|
||||
3. **消费 pending 锚点**(见 §3)
|
||||
4. 每帧更新 `scrollBus.sP`(camera progress:`clamp01((vh - bannerRect.bottom) / (vh*0.75)) * clamp01(footerRect.top / vh)`,驱动 3D 相机)
|
||||
|
||||
## 2. scrollEnv(lib/scrollEnv.ts)— 滚动抽象层
|
||||
|
||||
原站有一个 `scrollEnv` 全局对象,所有组件都通过它滚动而不直接摸 Lenis。我们 1:1:
|
||||
|
||||
```ts
|
||||
scrollEnv.setLenis(instance | null) // SmoothScroller 挂/卸时调用
|
||||
scrollEnv.setContainerEl(el | null) // 我们没有容器滚动 → 一直 null
|
||||
scrollEnv.lenisScrollTo(target, { immediate?, lerp? }) // 数字 | 选择器 | 元素
|
||||
scrollEnv.scrollToTop(behavior) / scrollToBottom(behavior)
|
||||
scrollEnv.getScrollTopPx(): number
|
||||
scrollEnv.getContainerEl(): HTMLElement | null // 详情页锚点滚动用(null → documentElement 回退)
|
||||
```
|
||||
|
||||
`lenisScrollTo` 传选择器/元素时若 Lenis 不在(详情页),回退 `el.scrollIntoView({behavior:"smooth"})`。
|
||||
|
||||
## 3. 跨页锚点:hq:pendingScrollAnchor
|
||||
|
||||
详情页页脚的 **Work / Contact 按钮**要"回到首页并滚到对应区块"。原站做法(模块 54450 + 88106):
|
||||
|
||||
```
|
||||
详情页: sessionStorage.setItem("hq:pendingScrollAnchor", "#selected-work")
|
||||
→ startNavigation("/") // 走 cover/reveal 过渡
|
||||
首页: SmoothScroller 挂载后读取并删除该 key
|
||||
→ requestAnimationFrame×2 后 lenis.scrollTo(目标元素, {lerp: .1})
|
||||
```
|
||||
|
||||
时序要点:必须等过渡 cover 完成 + 首页挂载 + Lenis 就绪,所以用双 rAF 延迟;读到即删(避免刷新后重复滚动)。`app/work/[slug]/page.tsx` 导出常量 `PENDING_SCROLL_ANCHOR_SESSION_KEY = "hq:pendingScrollAnchor"`(与原站字面一致)。
|
||||
|
||||
## 4. 详情页 MDX 锚点滚动(模块 31250 `i`)
|
||||
|
||||
```ts
|
||||
function scrollToMdxAnchorTarget(el: HTMLElement) {
|
||||
const container = scrollEnv.getContainerEl();
|
||||
if (container) {
|
||||
const top = el.getBoundingClientRect().top
|
||||
- container.getBoundingClientRect().top
|
||||
+ container.scrollTop - 96; // MDX_HEADING_ANCHOR_OFFSET_PX = 96
|
||||
scrollEnv.lenisScrollTo(Math.max(0, top), { lerp: 0.1 });
|
||||
return;
|
||||
}
|
||||
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
}
|
||||
```
|
||||
|
||||
96px = 标题落点离视口顶的预留(header 高度)。目录高亮也用同一条线:**最后一个 `getBoundingClientRect().top <= 96` 的标题**为 active。
|
||||
|
||||
## 5. 路由过渡 cover/reveal(lib/routeTransition.tsx + components/dom/RouteTransitionOverlay.tsx)
|
||||
|
||||
复刻原模块 73475。三态机:
|
||||
|
||||
```
|
||||
idle → startNavigation(href)
|
||||
→ phase "cover" : b1 色固定层 0.8s cubic-bezier(0.66,0,0.01,1) 擦入
|
||||
→ 完成后 router.push(href)
|
||||
→ phase "wait" : 新页挂载(重资源可继续加载)
|
||||
→ phase "reveal": 擦出(同 easing)→ idle,overlay 卸载
|
||||
scramble 文字在 reveal 后 100ms 重新允许
|
||||
```
|
||||
|
||||
Context 状态(`useRouteTransitionController`):`targetHref / navigationReplace / startNavigation / clearNavigation / readyToLoadHeavy / heavyLoadProgress / allowScrambleLines`。`readyToLoadHeavy` 同时就是加载门的输入(见 04 §6)。
|
||||
|
||||
调用方:Header 菜单链接、Work 卡片点击、详情页页脚 Home/Work/Contact。z-60 overlay,body 滚动锁定在 cover 期间。
|
||||
|
||||
## 6. 提示词(让 AI 复刻滚动与过渡)
|
||||
|
||||
> 我在克隆 haoqi.design 的滚动与路由行为(Next.js App Router)。要求:
|
||||
> 1. 平滑滚动:window 级 Lenis,只在首页路径挂载;进入详情页要彻底销毁 Lenis(原生 window 滚动),并把 scroll 恢复设为 manual、每次路由变更都回到顶部(pageshow persisted 亦然)。`<main>` 不得设 overflow,因为 sticky 区块依赖 window 滚动。
|
||||
> 2. 建一个 scrollEnv 抽象:setLenis/setContainerEl/lenisScrollTo(target 支持 number|selector|element,带 lerp 与 immediate)/scrollToTop/scrollToBottom/getContainerEl。所有需要编程滚动的组件只准调它,不直接 import Lenis。
|
||||
> 3. 路由过渡:全局 Provider + 固定层 overlay。startNavigation(href) 先播放 0.8s 的 b1 底色覆盖层擦入(cubic-bezier(0.66,0,0.01,1)),擦完才 router.push;新页挂载后擦出;期间禁止重复触发。所有站内跳转(菜单、作品卡、详情页页脚 Home/Work/Contact)都走它。
|
||||
> 4. 详情页页脚 Work/Contact 语义是"回首页并定位区块":先 sessionStorage.setItem("hq:pendingScrollAnchor", "#selected-work"|"#contact"),再 startNavigation("/");首页滚动器挂载后读取并立刻删除该 key,双 requestAnimationFrame 后用 lerp 0.1 平滑滚到目标。
|
||||
> 5. 文章内锚点滚动统一走 scrollToMdxAnchorTarget:有滚动容器时用 rect 差 + scrollTop - 96 计算,lenisScrollTo(max(0,top), lerp .1);没有容器时 scrollIntoView smooth。
|
||||
> 验证:CDP 点击详情页页脚 Work → 3 秒后断言 location.pathname === "/" 且 sessionStorage 里 key 已被删除且 #selected-work 的 top 接近视口预留位;点击 TOC 项断言目标标题 top ≈ 96。
|
||||
@@ -0,0 +1,76 @@
|
||||
# 04 · WebGL 层:场景组成 · DOM 注册表 · 贴纸 · 后期 · 加载门
|
||||
|
||||
唯一 `<Canvas>`(`components/canvas/HeroScene.tsx`),`-z-1 fixed` 容器内,`dpr={[1,2]}`、`gl={{alpha:true, antialias:true}}`、`style={{pointerEvents:"none"}}`。**仅首页挂载**(`if (!home) return null`,原站在路由 reveal 后同样卸载 canvas)。
|
||||
|
||||
> pointer-events 必须显式设 none:R3F 会把容器 div 强制 `pointerEvents:auto`,会吞掉下面 DOM 的所有 hover/点击。本项目所有指针追踪都在 window 级(lib/pointer),canvas 完全不参与命中测试。
|
||||
|
||||
## 1. 场景组成(HeroScene 内的兄弟组件)
|
||||
|
||||
| 组件 | 职责 |
|
||||
|---|---|
|
||||
| `CanvasSizeGuard` | 修复 R3F 首测竞态(见 §7 坑) |
|
||||
| `BackgroundFX` | 背景微噪点/渐变平面 |
|
||||
| `GlassModels` | hello.gltf 玻璃字 + cursor.glb 星标 + footer 模型,随 `scrollBus.sP` 分段入场 |
|
||||
| `ImageLayers` | 把 DOM 注册表里的图片投影成 3D 平面(作品图 + about 头像) |
|
||||
| `StickerDrop` | 贴纸雨(sticker_img 图集),滚动触发掉落 |
|
||||
| `HyperspaceModel` | hyper-space 区块的隧道箭头(cursor.glb 条纹拉伸) |
|
||||
| `DotOverlay` / `PostFX` | z-30 点阵 DOM 覆盖层之外的 WebGL 点缀与后期 |
|
||||
|
||||
相机每帧读 `scrollBus.sP`(0→1 = banner 底到 footer 顶的进度)做位移/旋转。
|
||||
|
||||
## 2. DOM↔WebGL 注册表(lib/imageLayers.ts)
|
||||
|
||||
模式:**DOM 端声明 + Canvas 端订阅**,模块级共享单例。
|
||||
|
||||
```ts
|
||||
// DOM 端(AboutMedia / WorkSection):给每个目标一个 ref
|
||||
const defs = new Map<string, ImageLayerDef>([
|
||||
["about", { imageUrl: "/img/m3.png" }],
|
||||
// WorkSection 挂载时为每张卡片 registerLayer(key, {imageUrl, hoverImageUrl})
|
||||
]);
|
||||
// 渲染后 touchLayerRegistry() bump 版本号 → Canvas 端 ImageLayers 重新读取
|
||||
// Canvas 端:每帧把 targetRef 元素的 getBoundingClientRect() 投影成平面位置/尺寸
|
||||
```
|
||||
|
||||
这是原站 `t.layers`(`{key, imageUrl, hoverImageUrl, targetRef}`)的等价物。注册是纯数据写(渲染期安全、幂等),订阅端用版本号触发重渲染。
|
||||
|
||||
## 3. 贴纸系统(components/canvas/StickerDrop.tsx + lib 内 StickerLayer)
|
||||
|
||||
- 图集来自 `public/sticker_img/`;`loadingBus.mark("stickers")` 报告就绪
|
||||
- 掉落由滚动速度触发(scrollBus),3D 平面 + 随机旋转/延迟
|
||||
- hover 作品卡时贴纸镜像 hover 图(`hoverImageUrl`)
|
||||
|
||||
## 4. 后期(components/webgl/PostFxPasses.ts)
|
||||
|
||||
轻量后期(色调统一 + 轻微 grain),保持 alpha 通道(场景必须透出 `-z-1` 下的根背景色)。
|
||||
|
||||
## 5. AboutMedia(components/dom/AboutMedia.tsx)
|
||||
|
||||
头像不是 `<img>`:DOM 端只有一个 `aspect-square` 占位 div(注册为 `about` 层目标),m3.png 由 ImageLayers 投影成带视差/微旋转的 3D 平面。这就是为什么页面上搜不到 m3 的 img 标签。
|
||||
|
||||
## 6. 加载门(lib/loadingBus.ts + LoadingOverlay)
|
||||
|
||||
```
|
||||
REQUIRED = ["model:hello.gltf", "model:cursor.glb", "stickers", "img:about"]
|
||||
loadingBus.mark(key) → progress = done/4 → ready = 全齐
|
||||
```
|
||||
|
||||
- 各资源加载完调用 `mark`;LoadingOverlay 显示进度(0→100),ready 后幕布揭起
|
||||
- 揭起后 `readyToLoadHeavy=true` → BackgroundGrid 才显示(复刻原模块 97839 `"/"===pathname && !readyToLoadHeavy` 门)
|
||||
- HeroScene 内部 `useAppReady()` 同步这个状态
|
||||
|
||||
## 7. 已踩坑
|
||||
|
||||
- **R3F 尺寸竞态**:canvas 挂载早于 CSS 应用时,react-use-measure 报 300×150/1440×150 而非容器实际尺寸,且容器尺寸不再变化时 ResizeObserver 永不再触发 → canvas.style 永久错误。`CanvasSizeGuard` 连续 40 帧比对 `canvas.style.width/height` 与父容器 `clientWidth/Height`,mismatch 就 `gl.setSize(cw,ch,true) + setSize(cw,ch)` 重跑 R3F 尺寸管线。
|
||||
- **R3F 吞指针**:见开头,容器强制 `pointerEvents:none`。
|
||||
- **canvas 生命周期**:离开首页必须卸载(原站同样),否则详情页背景会有"多余的贴纸/场景"(用户反馈过的真实事故)。
|
||||
|
||||
## 8. 提示词(让 AI 复刻 WebGL 层)
|
||||
|
||||
> 我在克隆 haoqi.design 的 WebGL 层(React Three Fiber + drei,Next.js)。请实现:
|
||||
> 1. 单一全屏 Canvas 挂在 `top-0 left-0 -z-1 fixed w-full h-dvh lg:h-screen pointer-events-none` 容器里,`gl={{alpha:true, antialias:true}}`,dpr [1,2],容器 style 强制 pointerEvents:"none"(R3F 会强制改回 auto,必须覆盖,否则吞掉 DOM hover)。Canvas 只在首页挂载(usePathname 门控,非首页 return null——注意早退要放在所有 hooks 之后)。
|
||||
> 2. 场景含:两枚玻璃质感模型(hello.gltf 大字 + cursor.glb 星标)、作品图片层、贴纸雨、hyper-space 隧道模型、背景微噪平面、轻后期。相机进度用一个全局 scrollBus(0=页面顶,1=footer 顶,公式 clamp01((vh-bannerRect.bottom)/(vh*0.75)) * clamp01(footerRect.top/vh))每帧读取。
|
||||
> 3. 图片层用"DOM 注册表"模式:模块级 Map<key,{imageUrl,hoverImageUrl}>,DOM 组件(作品卡/头像占位 div)渲染后 touch 版本号;Canvas 端订阅并每帧把目标元素 getBoundingClientRect() 投影成带视差的 3D 平面。头像区 DOM 端只是 aspect-square 空占位,图片完全由 WebGL 画。
|
||||
> 4. 加载门:模块级 loadingBus,REQUIRED=["model:hello.gltf","model:cursor.glb","stickers","img:about"],mark() 计数,LoadingOverlay 显示 0→100 进度,ready 后揭幕;揭幕同时才显示十字网格(原站 useHomeLoadingGate)。
|
||||
> 5. 必须处理 R3F 首测竞态:挂载后 40 帧内持续比对 canvas.style 与父容器尺寸,mismatch 时 gl.setSize + setSize 重跑尺寸管线,否则 canvas 会卡在 1440×150。
|
||||
> 验证:截图后用 PIL 断言场景区域平均色 ≠ 页面底色(251,250,244)、canvas width/height 等于视口、离开首页后 canvas 数量为 0。
|
||||
@@ -0,0 +1,83 @@
|
||||
# 05 · 首页区块 · 文字特效 · 自定义滚动条 · BGM
|
||||
|
||||
首页结构(`app/page.tsx`):banner → about(含头像)→ `WorkSection` → `HyperSpaceSection` → `FooterSection`,全部普通流(sticky 依赖 window 滚动)。
|
||||
|
||||
## 1. ScrambleReveal(components/dom/ScrambleReveal.tsx,原模块 71358)
|
||||
|
||||
字符扰动揭示算法(1:1):
|
||||
|
||||
- charset `ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*+-=?/<>[]{}`,扰动中的字符每 40ms 随机换
|
||||
- 第 i 个字符在 `startDelayMs + i*letterDelayMs` 开始扰动,经 **2 个相位 × 2×letterDelayMs** 后定格;相位 0 颜色 `#c0fe04`,相位 1 `#607F02`(`scrambleColors=false` 时不上色)
|
||||
- 整体定格时间 = `startDelayMs + (n-1)*letterDelayMs + 4*letterDelayMs`
|
||||
- IntersectionObserver threshold 0.1 进入视口才开始
|
||||
- **slot 对象** `{ length, scramble?, settled?, className? }`:扰动期显示 `scramble` 字符(默认空格),定格后渲染 `settled` 节点(口令按钮就是这么嵌进文字行的)
|
||||
|
||||
用法:banner 大标题三行 `startDelayMs 300/500/700`;页脚 Metadata 值用 `scrambleColors={false}` + `startDelayMs 300/360/420`(原站 ArticleFooter 的错峰)。
|
||||
|
||||
## 2. PasscodeRevealText(components/dom/PasscodeRevealText.tsx)
|
||||
|
||||
banner 右下文字("I'm Haoqi Wen, leading Design Engineering and AI exploration at ...")。注意原站特征:
|
||||
|
||||
- 每个词是 `inline mx-[0.06em] align-baseline` 的 span
|
||||
- 品牌名 reunimos™ 是**可点击 scramble 链接**(`inline-flex items-baseline gap-[0.12em] mx-[0.06em] align-baseline cursor-pointer select-text`)
|
||||
- 长按可重新锁定的标签(`role:"button"` + `aria-label:"… — long press to lock again"` + pointerdown 500ms 计时)
|
||||
- 锁定态字符类 `PASSCODE_LOCKED_CHAR_CLASS` / 扰动类 `PASSCODE_LOCKED_SCRAMBLE_CLASS`(lib/passcode.ts)
|
||||
|
||||
## 3. WorkSection(components/dom/WorkSection.tsx)
|
||||
|
||||
- `id="selected-work"`,容器 `px-4 lg:px-14 py-18 lg:py-24 w-full`
|
||||
- 卡片 = `article > a.group.block.space-y-3.p-2`:
|
||||
- 图片占位 `relative w-full pointer-events-none select-none` + `aspectRatio`(来自 WORK_ITEMS),图片本体是 WebGL ImageLayers 投影(**hover 换 hoverImageUrl**)
|
||||
- `codingProject` 项右上角 `top-0 right-0 z-10 absolute bg-selection px-1 font-mono-2 text-black text-…` 标签
|
||||
- 说明行 `flex justify-between items-cen… h=20`:名称 + 年份 + 类型(post/tools/event)
|
||||
- 数据 `lib/workItems.ts`(WORK_ITEMS 1:1 来自原模块 28116);`passcodeProtected` 首项(TikTok)在网格里按原站逻辑过滤:`!t.passcodeProtected || lookup(t.href)`,锁定时仍显示品牌标签(见 07)
|
||||
- 点击 → `startNavigation(href)`(cover/reveal 过渡进详情页)
|
||||
|
||||
## 4. HyperSpaceSection(components/dom/HyperSpaceSection.tsx)
|
||||
|
||||
`id="hyper-space"` + `top-0 sticky` 区块;IntersectionObserver(rootMargin `480px 0px 480px 0px`)检测接近 → 通知 WebGL 端 `HyperspaceModel` 放大隧道穿越视口。DOM 端只有占位与少量文字。
|
||||
|
||||
## 5. FooterSection(components/dom/FooterSection.tsx)
|
||||
|
||||
- `id="contact"`,`data-section="footer"`,类 `z-10 relative flex flex-col justify-center p-6 lg:p-16 w-full h-dvh lg:h-screen pointer-events-none`
|
||||
- 邮箱 `chenchun@virtheart.com`(用户指定,非原站 wenhaoqi 的)
|
||||
- 社交链接保持 `#` 占位(原站是 twitter/wenhaoqi 等真实链接,克隆不放)
|
||||
|
||||
## 6. CustomScrollbar(components/dom/CustomScrollbar.tsx)
|
||||
|
||||
原站隐藏原生滚动条(`scrollbar-width:none` + `::-webkit-scrollbar{display:none}`),画自己的:
|
||||
|
||||
- **桌面**:右侧 SVG track+thumb path(`M x y V y2`,按 scrollTop/scrollHeight 实时算),可拖拽(pointer capture),点击 track 跳转
|
||||
- **移动**:右缘圆环进度
|
||||
- 闲置自动隐藏(hideTimer),hover/滚动时出现
|
||||
- window 滚动驱动 → 首页/详情页都能用
|
||||
- ⚠️ 探针调试时注意 thumb 是 `<path>`,别误选 track
|
||||
|
||||
## 7. BGM(lib/useBgm.ts)
|
||||
|
||||
```
|
||||
useBgm(enabled) // Header 里调用
|
||||
① fetch("/bgm.mp3") → objectURL → Audio(volume .35, loop) // 只加载一次
|
||||
② enabled 变化 play/pause
|
||||
③ autoplay 被策略拒绝(NotAllowedError)时:
|
||||
挂一次性手势监听 pointerdown/keydown/touchstart → 重试 play
|
||||
④ 卸载时 revokeObjectURL
|
||||
```
|
||||
|
||||
- 开关状态在 `lib/shellMedia.tsx`(theme + soundEnabled,localStorage 持久化)
|
||||
- `enabledRef` 让"加载一次"的 effect 拿得到最新 enabled(闭包只捕获初始 false 的经典坑)
|
||||
|
||||
## 8. Header(components/dom/Header.tsx)
|
||||
|
||||
`z-50 fixed`;左侧品牌 + 右侧 theme/sound/menu。菜单项点击 → `startNavigation`。theme 切换只切 `--label-*`(暗色令牌已从原 CSS 提取但未启用,路线图项)。
|
||||
|
||||
## 9. 提示词(让 AI 复刻这层)
|
||||
|
||||
> 继续克隆 haoqi.design(Next.js + Tailwind v4,已有 02/03/04 文档中的层叠、滚动、WebGL 基础)。现在实现 DOM 层:
|
||||
> 1. ScrambleReveal 文字组件:字符集 A-Z0-9!@#$%^&*+-=?/<>[]{},每 40ms 随机扰动;第 i 字符在 startDelayMs + i*letterDelayMs 开始、2 个相位(各 2*letterDelayMs)后定格,相位 0 色 #c0fe04 相位 1 色 #607F02(可关);IntersectionObserver threshold .1 触发;支持 slot 对象 {length, scramble, settled, className}(扰动期显示占位字符,定格后渲染真实节点)。banner 大标题三行错峰 300/500/700ms。
|
||||
> 2. banner 区块:grid-cols-12 grid-rows-[auto_1fr],大标题 text-[7.2svw] lg:text-[6svw] uppercase leading-none + fontVariationSettings "wdth" 120;右下介绍文字每个词一个 inline mx-[0.06em] span,品牌词是可点击链接 span,另有长按 500ms 可重新锁定的小按钮(role=button + aria-label)。
|
||||
> 3. 作品网格:数据数组含 name/imageUrl/hoverImageUrl/href/year/type/gridClass/codingProject,卡片是 article>a.group.block.space-y-3.p-2,图片区只放 aspectRatio 占位 div(图片由 WebGL 层投影,hover 换 hoverImageUrl),codingProject 项右上角 bg-selection 角标,说明行 flex justify-between。点击卡片走全局过渡导航。
|
||||
> 4. sticky 的 hyper-space 区块 + IntersectionObserver(rootMargin 480px) 通知 WebGL 放大隧道。
|
||||
> 5. 自定义滚动条:隐藏原生(scrollbar-width:none),SVG path thumb 按滚动位置实时绘制,支持拖拽(pointer capture)与 track 点击,闲置自动隐藏,移动端是圆环进度。
|
||||
> 6. BGM:fetch /bgm.mp3 转 objectURL 只加载一次,Audio loop volume .35;开启时若 play() 被自动播放策略拒绝,挂一次性 pointerdown/keydown/touchstart 手势重试;卸载 revokeObjectURL。开关状态 localStorage 持久化。
|
||||
> 验证:CDP 断言 banner 三行文字文本齐全且 opacity 1;卡片说明行文本完整;滚动条 path 的 d 随滚动变化;静音开关点击后 audio.paused 为 false(在手势后)。
|
||||
@@ -0,0 +1,127 @@
|
||||
# 06 · 详情页 MDX 系统(目录 · 锚点 · 代码块 · 页脚 · 内容管线)
|
||||
|
||||
详情页 = `app/work/[slug]/page.tsx`,复刻原站四个 MDX 组件 + 内容提取管线。URL 与原站一致:`/reunimos` 等根路径 slug 由 `next.config.ts` rewrites 指到 `/work/[slug]`。
|
||||
|
||||
```ts
|
||||
const WORK_SLUGS = ["reunimos","inspire_mono","wasm_design_utils","adrive","shore_icon","teambition"];
|
||||
rewrites: { beforeFiles: WORK_SLUGS.map(s => ({ source: `/${s}`, destination: `/work/${s}` })) }
|
||||
```
|
||||
|
||||
## 1. 内容管线(content/workArticles.ts)
|
||||
|
||||
生成流程(一次性,脚本见 01 §4):
|
||||
|
||||
1. `curl https://haoqi.design/<slug>` 存 SSR HTML
|
||||
2. bs4 解析:按**文档序扁平收集** `article[data-mdx-article]` 下的 p/h2/h3/h4/pre/ul/ol/blockquote/img/hr(排除 header/footer/pre 内部;li 内 p 去重)——不能假设 prose 容器嵌套层级,各文章不一样
|
||||
3. 类型:
|
||||
|
||||
```ts
|
||||
type InlineSeg = { t:"text"|"link"|"code"|"strong"|"em"; v; href? };
|
||||
type ArticleBlock =
|
||||
| { type:"p"; segs: InlineSeg[] }
|
||||
| { type:"h2"|"h3"|"h4"; text; id? }
|
||||
| { type:"code"; language; label; html; text } // html=原站 prism token HTML
|
||||
| { type:"list"; ordered; items: InlineSeg[][] }
|
||||
| { type:"quote"; segs } | { type:"img"; src } | { type:"hr" };
|
||||
type WorkArticle = { title; date; year; iframe: {src,title}|null; blocks: ArticleBlock[] };
|
||||
```
|
||||
|
||||
4. **代码块**取 `code.decode_contents()`(含行号行 `div.gap-4.grid.grid-cols-[auto_1fr]` 与 `span.token`)+ `code.get_text()`(COPY 用纯文本)+ language class → label(Bash/JavaScript…)
|
||||
5. ⚠️ 标题文本要剥掉锚点 `#` span(`lstrip('#')`),否则 TOC 标签和 aria-label 会带 "#"
|
||||
|
||||
数据是纯 TS 常量,无需运行时解析。
|
||||
|
||||
## 2. MdxHeading(原模块 31250)
|
||||
|
||||
```tsx
|
||||
// 类 map(1:1)
|
||||
const HEADING_CLASSES = {
|
||||
1: "mt-12 text-2xl leading-tight lg:mt-14 lg:text-[28px]",
|
||||
2: "mt-10 text-xl leading-tight lg:mt-12 lg:text-2xl",
|
||||
3: "mt-8 text-lg leading-snug lg:mt-10 lg:text-xl",
|
||||
4: "mt-7 text-base leading-snug lg:mt-8 lg:text-lg",
|
||||
};
|
||||
// 基类 "group relative scroll-mt-24 font-semibold tracking-tight text-l1 [&:first-child]:mt-0"
|
||||
```
|
||||
|
||||
- id 优先用原站 SSR 的 id,缺省时 slugify:`trim().toLowerCase().replace(/[\s\u3000]+/g,"-").replace(/[^\w\u4e00-\u9fff-]+/g,"").replace(/-{2,}/g,"-").replace(/^-+|-+$/g,"")`(保留中文!)
|
||||
- 锚点 `<a href="#id" aria-label="Copy link to {text}" class="relative inline-block text-inherit no-underline">`,内含隐藏 `#`(`absolute top-0 right-full mr-2 hidden … lg:group-hover:opacity-100`)
|
||||
- 点击:preventDefault → scrollToMdxAnchorTarget(-96)→ `history.replaceState(null,"",#id)` → 复制完整 URL 到剪贴板
|
||||
|
||||
## 3. MdxTableOfContents(原模块 78825)
|
||||
|
||||
```
|
||||
nav[aria-label="本页目录"]
|
||||
class="pointer-events-auto fixed inset-y-0 left-0 z-20 hidden min-h-0 w-[320px]
|
||||
flex-col overflow-hidden 2xl:flex pl-14 pr-2"
|
||||
└ flex flex-col flex-1 min-h-0 overflow-hidden
|
||||
└ flex-1 min-h-0 overflow-y-auto overscroll-y-contain no-scrollbar
|
||||
└ box-border flex min-h-full flex-col py-7
|
||||
└ flex min-h-0 flex-1 flex-col justify-center gap-1 p-2 text-sm leading-snug text-l2
|
||||
```
|
||||
|
||||
- **只在 2xl(≥1536px)显示**;收集 `article[data-mdx-article]` 内**有 id 的 h1/h2/h3**(label = textContent 剥掉 aria-hidden span)
|
||||
- 无可收集标题 → 渲染 null
|
||||
- 链接:`block min-w-0 shrink-0 cursor-pointer truncate rounded-md py-0.5 transition-colors hover:text-l1 ${active?"text-l1":"text-l2"}`,`paddingLeft = [0,8,16][level-1]`
|
||||
- active:滚动/resize/ResizeObserver 监听,**最后一个 `top <= 96` 的标题**;点击即滚(scrollToMdxAnchorTarget)+ replaceState
|
||||
- 收集时机:effect 内立即 + 0ms + 150ms 各一次(水合后 DOM 才有 id)
|
||||
|
||||
## 4. CodeBlock(原模块 93325)
|
||||
|
||||
```
|
||||
div.group.my-6.overflow-hidden.rounded-xl.bg-[rgba(var(--label-d),0.03)]
|
||||
├ header: flex items-center justify-between px-3 py-2 shadow-[inset_0_-1px_0_0_var(--line)] lg:px-4
|
||||
│ ├ span: px-1 font-mono text-xs tracking-wide text-(--label-3) ← 语言标签
|
||||
│ └ button: COPY/COPIED,dotted 边框 hover(before:border-dotted 体系),
|
||||
│ aria-label Copy code/Copied code,复制成功 1200ms 后还原
|
||||
└ pre: overflow-x-auto px-4 py-2 font-mono text-xs leading-relaxed text-(--label-1) lg:px-5 lg:py-2.5 lg:text-sm
|
||||
└ code.language-{lang} ← dangerouslySetInnerHTML(原站 token HTML,行号行自带)
|
||||
```
|
||||
|
||||
行号行结构(提取来的 HTML 里已有):`div.gap-4.grid.grid-cols-[auto_1fr] > span[aria-hidden].select-none.text-right.tabular-nums.text-(--label-4)` + 内容 span。token 配色靠 `--code-*` 变量(02 §2)。
|
||||
|
||||
## 5. ArticleFooter(原模块 54450)
|
||||
|
||||
```
|
||||
footer[data-mdx-footer]: bg-[rgba(var(--label-d),0.03)] mt-16 p-4 lg:p-6 rounded-xl
|
||||
├ "Metadata" 标题
|
||||
├ dl grid-cols-2 lg:grid-cols-3:Last Updated(文章日期)/ Dimensions(实时 `${innerWidth}×${innerHeight}`,resize 监听)
|
||||
│ / Characters(article.textContent 去 footer 后的字符数,toLocaleString("en-US"))
|
||||
├ 虚线分隔 my-6 border-line border-t border-dashed
|
||||
└ Links grid-cols-2 lg:grid-cols-3(首列 lg 可见标题):
|
||||
Home → <Link href="/">;Work/Contact → sessionStorage pendingAnchor + startNavigation("/")
|
||||
社交列(# 占位)
|
||||
```
|
||||
|
||||
- 值全部经 ScrambleReveal(`font-mono tabular-nums text-l2 text-sm`,startDelay 300/360/420,`scrambleColors=false`)
|
||||
- 字符数统计:`footerRef` 回调里 clone article、`[data-mdx-footer]` 移除后 `textContent.length`(用 `[...str].length` 数 code point)
|
||||
- ⚠️ ScrambleReveal 初始不显示,所以 SSR HTML 里 dd 是空的、按钮文本为空——不是 bug
|
||||
|
||||
## 6. 页面骨架
|
||||
|
||||
```
|
||||
<article data-mdx-article class="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px] text-l1">
|
||||
<header class="pt-[10vh]">
|
||||
h1(font-bold text-3xl! lg:text-5xl! + wdth 120)
|
||||
p(mt-1 tabular-nums text-l2! text-sm! lg:text-base!)=日期
|
||||
div(mt-2 border-line border-b)
|
||||
p(pt-3 …)=年份
|
||||
</header>
|
||||
<div class={PROSE_CLASS}> ← 原站 prose 类全串(58 个类,逐字从 SSR 提取,含
|
||||
[&_p]/[&_ul]/[&_blockquote_*]/[&_:not(pre)>code]/[&_u] 点状下划线 等)
|
||||
blocks… + iframe(reunimos 有 840×600 live 预览)
|
||||
</div>
|
||||
<ArticleFooter/>
|
||||
</article>
|
||||
<MdxTableOfContents/> ← 放 article 之外
|
||||
```
|
||||
|
||||
## 7. 提示词(让 AI 复刻详情页)
|
||||
|
||||
> 克隆 haoqi.design 的文章详情页(Next.js App Router,/work/[slug],根路径 slug 用 beforeFiles rewrites)。内容来自 content/workArticles.ts(我描述结构:每篇文章有 title/date/year/iframe/blocks;blocks 是 p|h2/h3|code|list|img|hr|quote 的可辨析联合类型;code 块带 language/label/html/text 四字段,html 是原站 prism 高亮后的 span.token + 行号行 HTML)。
|
||||
> 1. 文章骨架:article[data-mdx-article],容器 mx-auto px-6 py-18 lg:py-24 max-w-[880px] text-l1;header.pt-[10vh] 放 h1(font-bold text-3xl! lg:text-5xl! + fontVariationSettings wdth 120)、日期、border-line 分隔线、年份。prose 容器类我提供逐字全串(含 [&_p]:text-sm 等任意变体),不要简化。
|
||||
> 2. 标题组件:h2/h3/h4 用原站类 map(mt-10 text-xl…),id 用数据里的(中文 id 保留);标题内套锚点 a[aria-label="Copy link to …"],hidden 的 # 在 lg:group-hover 显示;点击 preventDefault + 滚动到 top-96(lerp .1,走 scrollEnv)+ history.replaceState + 复制完整 URL。
|
||||
> 3. 左侧目录:fixed left-0 w-[320px],仅 2xl:flex,pl-14 pr-2,内层 flex 竖排 min-h-0 overflow-y-auto no-scrollbar,垂直居中;收集有 id 的 h1-h3,缩进 0/8/16px,active = 最后一个 getBoundingClientRect().top<=96 的标题(scroll/resize/ResizeObserver 监听);点击滚动 + replaceState;无标题渲染 null。
|
||||
> 4. 代码块:rounded-xl 组容器 + header(语言标签 font-mono text-xs text-(--label-3),COPY 按钮 dotted before 边框 hover,复制后 COPIED 1200ms 还原,aria-label Copy code/Copied code)+ pre(overflow-x-auto px-4 py-2 font-mono text-xs leading-relaxed)+ code.language-X 用 dangerouslySetInnerHTML 注入预高亮 HTML(行号和配色都来自原站 HTML 与 --code-* 变量,不要自己引入 prism)。
|
||||
> 5. 页脚:bg-[rgba(var(--label-d),0.03)] mt-16 p-4 lg:p-6 rounded-xl;Metadata dl 三列 = 日期 / 实时视口尺寸(resize 监听)/ 正文字符数(clone article 去 footer 后 textContent,toLocaleString en-US);值用 ScrambleReveal(scrambleColors=false,错峰 300/360/420)。Links 区:Home 是 Link,Work/Contact 是 sessionStorage("hq:pendingScrollAnchor") + 全局过渡导航回首页。
|
||||
> 验证(CDP):/wasm_design_utils 有 4 个 pre、TOC 7 项、h2 id=安装、COPY 按钮存在、footer dd 渲染后出现 "宽×高" 和千分位字符数;TOC 点击后目标标题 top≈96。
|
||||
@@ -0,0 +1,62 @@
|
||||
# 07 · 口令保护系统(/2026)
|
||||
|
||||
## 1. 设计
|
||||
|
||||
原站有一个口令保护的隐藏作品(TikTok 卡片,`/2026`)。克隆里默认口令 `2026`(env `PASSCODE_CODE` 可覆盖)。
|
||||
|
||||
```
|
||||
lib/passcode.ts 纯函数/常量(客户端+服务端共用)
|
||||
lib/passcodeServer.ts 服务端读 cookie
|
||||
app/api/passcode/route.ts GET=查状态 / POST=校验+签发 cookie
|
||||
components/dom/PasscodeAccess.tsx Context + hooks
|
||||
components/dom/PasscodeUnlockScreen.tsx 解锁界面
|
||||
components/dom/PasscodeRevealText.tsx banner 里的锁定文案
|
||||
```
|
||||
|
||||
## 2. 数据流
|
||||
|
||||
```
|
||||
cookie hq-passcode-access(JSON: Record<scope, boolean>)
|
||||
GET /api/passcode → 当前 access state(SSR 时由 layout 用 passcodeServer 读)
|
||||
POST /api/passcode {scope, code}
|
||||
→ code === env.PASSCODE_CODE → Set-Cookie 更新 state[scope]=true → {ok:true}
|
||||
→ 否则 401
|
||||
客户端:
|
||||
usePasscodeAccessLookup() // 订阅 state + PASSCODE_ACCESS_CHANGED_EVENT
|
||||
usePasscodeAllowed(path) // path 在 PASSCODE_PROTECTED_PATHS(["/2026"]) 且未解锁 → false
|
||||
notifyPasscodeAccessChanged() // 解锁后广播(同 tab 立即生效)
|
||||
```
|
||||
|
||||
- 路径映射:work 项 `href` → `workHrefToPath`(如 `/2026`);`buildPasscodeUnlockHref(scope, returnTo)` 生成 `/unlock/2026?returnTo=…`;`sanitizePasscodeReturnTo` 防开放重定向(只收站内路径)
|
||||
- 详情页 `/work/2026` 直接渲染 `PasscodeUnlockScreen`(scope 匹配时),同原站行为
|
||||
|
||||
## 3. 与作品网格的联动(复刻原站逻辑)
|
||||
|
||||
```ts
|
||||
// WorkSection 过滤(原站: WORK_ITEMS.filter(t => !t.passcodeProtected || lookup(t.href)))
|
||||
items.filter(t => !t.passcodeProtected || allowed(workHrefToPath(t.href)))
|
||||
// 未解锁 → TikTok 卡片整个隐藏;解锁 → 出现且名称是 revealBrandLabel()(原站 bundle
|
||||
// 里品牌名是混淆字符串,运行时拼出 "TikTok"——我们用同款 revealBrandLabel())
|
||||
```
|
||||
|
||||
用户反馈确认:未解锁时看不到 TikTok 卡片是**预期行为**(issue #5)。
|
||||
|
||||
## 4. 解锁界面(PasscodeUnlockScreen)
|
||||
|
||||
- `z-1000 fixed inset-0 bg-b1` 全屏层;隐藏 input 承接输入(聚焦后 4 格显示)
|
||||
- 4 格槽(`PASSCODE.slotCount=4`);`PASSCODE_LOCKED_CHAR_CLASS`(占位字符)+ `PASSCODE_LOCKED_SCRAMBLE_CLASS`(错误时扰动)
|
||||
- 成功 → `submitPasscodeUnlock` → cookie 签发 → `notifyPasscodeAccessChanged()` → 按 `returnTo` 回到来源页(走全局过渡)
|
||||
|
||||
## 5. 长按锁定(PasscodeRevealText 内)
|
||||
|
||||
banner 品牌词旁的小按钮:`onPointerDown` 起 500ms 计时,`onPointerUp/Leave/Cancel` 清除,触发 logout(清 cookie + 广播 + reload)。`aria-label` 形如 `… — long press to lock again`。
|
||||
|
||||
## 6. 提示词
|
||||
|
||||
> 给克隆站加原站同款口令系统(Next.js App Router):
|
||||
> 1. cookie `hq-passcode-access` 存 JSON Record<scope,boolean>;API 路由 GET 返回状态、POST 校验 scope+code(code 来自 env PASSCODE_CODE,默认 2026),成功 Set-Cookie 并 {ok:true},失败 401。
|
||||
> 2. 客户端 Context + usePasscodeAllowed(path):保护路径列表 PASSCODE_PROTECTED_PATHS=["/2026"];解锁后同 tab 立即生效(自定义事件广播)。workHrefToPath/buildPasscodeUnlockHref/sanitizePasscodeReturnTo(只允许站内 returnTo)。
|
||||
> 3. 作品网格按原站过滤:!passcodeProtected || allowed(href);受保护项的品牌名用运行时 revealBrandLabel() 还原(bundle 里混淆,不要把品牌名写死进数据文件的明文里)。
|
||||
> 4. 解锁页 /unlock/[scope]:z-1000 全屏 bg-b1,隐藏 input 承接,4 格显示,错误时占位字符扰动,成功后广播 + 按 returnTo 过渡返回;详情路由 scope 匹配时原地渲染解锁屏。
|
||||
> 5. banner 文字里含长按 500ms 重新锁定的小按钮(pointerdown 计时,up/leave/cancel 清除,aria-label 带 "long press to lock again")。
|
||||
> 验证:POST 正确口令后 cookie 出现且卡片出现;错误口令 401;清 cookie 后卡片消失。
|
||||
@@ -0,0 +1,114 @@
|
||||
# 08 · 验证工作流(CDP 探针 · 像素断言 · 回归清单)
|
||||
|
||||
原则:**DOM 存在 ≠ 可见,可见 ≠ 在正确的层上**。每轮改动必须跑完整链条。
|
||||
|
||||
## 1. 环境准备
|
||||
|
||||
```bash
|
||||
# dev server(Turbopack;改 next.config.ts 会重启 → 等 6-8s 再探测)
|
||||
pnpm dev # localhost:3000
|
||||
|
||||
# Chrome 调试实例
|
||||
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
|
||||
--remote-debugging-port=9223 --window-size=1920,1080 \
|
||||
--user-data-dir=/tmp/chrome-probe --no-first-run about:blank &
|
||||
|
||||
WS=$(curl -s http://localhost:9223/json | python3 -c \
|
||||
"import json,sys;print([t['webSocketDebuggerUrl'] for t in json.load(sys.stdin) if t['type']=='page'][0])")
|
||||
```
|
||||
|
||||
探针模式(本会话脚本,可重建):
|
||||
|
||||
```python
|
||||
# 单表达式求值(awaitPromise + returnByValue)
|
||||
async with websockets.connect(WS, max_size=50*1024*1024) as ws:
|
||||
await ws.send(json.dumps({"id":1,"method":"Runtime.evaluate",
|
||||
"params":{"expression": EXPR, "returnByValue": True, "awaitPromise": True}}))
|
||||
# pump 消息直到拿到 id==1 的响应;同时收集 Runtime.exceptionThrown / Log.entryAdded
|
||||
```
|
||||
|
||||
⚠️ 一个 ws 连接里**不能有两个协程同时 recv**(ConcurrencyError)——用单一 pump 循环同时收响应和错误事件。`Page.captureScreenshot` 的 base64 直接存 PNG。
|
||||
|
||||
## 2. 标准断言集
|
||||
|
||||
### 首页(/,视口 ≥1660)
|
||||
|
||||
```js
|
||||
JSON.stringify({
|
||||
banner: !!document.querySelector('[data-section=banner]'),
|
||||
h1Texts: [...document.querySelectorAll('[data-section=banner] span')].length,
|
||||
cards: document.querySelectorAll('#selected-work article').length, // 10
|
||||
grid: !!document.querySelector('div.z-20.fixed'), // true
|
||||
canvasZ: getComputedStyle(document.querySelector('canvas').parentElement.parentElement).zIndex, // "-1"
|
||||
header: getComputedStyle(document.querySelector('header')).zIndex, // "50"
|
||||
})
|
||||
```
|
||||
|
||||
### 像素三层共存(截图 → PIL)
|
||||
|
||||
```python
|
||||
def dark(x0,y0,x1,y1,th=360):
|
||||
r = im.crop((int(x0*s),int(y0*s),int(x1*s),int(y1*s))); px=list(r.getdata())
|
||||
return sum(1 for p in px if sum(p)<th)/len(px)
|
||||
dark(1088,96,1604,208) > 0.05 # banner 文案可见(画在场景之上)
|
||||
avg(600,300,1060,700) != (251,250,244)±5 # 场景可见(-z-1 且未被 body 背景盖住)
|
||||
dark(848,150,856,400,700) > 0.20 # 网格竖线可见
|
||||
```
|
||||
|
||||
### 详情页(/wasm_design_utils)
|
||||
|
||||
```js
|
||||
JSON.stringify({
|
||||
pre: document.querySelectorAll('pre').length, // 4
|
||||
toc: document.querySelectorAll('nav[aria-label="本页目录"] a').length, // 7
|
||||
h2id: document.querySelector('h2[id]')?.textContent, // "安装"(无 # 前缀)
|
||||
grid: !!document.querySelector('div.z-20.fixed'), // false ← 详情页无十字线
|
||||
canvas: document.querySelectorAll('canvas').length, // 0
|
||||
label: document.querySelector('h2[id] a')?.getAttribute('aria-label'), // "Copy link to 安装"
|
||||
})
|
||||
```
|
||||
|
||||
交互链:
|
||||
1. TOC 点击"颜色" → `location.hash === '#%E9%A2%9C%E8%89%B2'` 且 `targetTop ≈ 96`
|
||||
2. 深滚动 → `nav a[aria-current=location]` 跟随
|
||||
3. 页脚滚动到底后 dd 出现 `1660×986` 与千分位字符数(SSR 里是空的,正常)
|
||||
4. 点 Work 按钮 → 3s 后 `pathname === "/"`、`sessionStorage.getItem("hq:pendingScrollAnchor") === null`
|
||||
|
||||
### 滚动
|
||||
|
||||
- 详情页 `wheel` 后 `scrollY > 0` 且 thumb `d` 变化(`M 16 … V …`)
|
||||
- 首页 Lenis 开启时滚动仍由 window 驱动(scrollBus.sP ∈ [0,1])
|
||||
|
||||
## 3. 错误监听(导航类回归必须开)
|
||||
|
||||
```python
|
||||
# 单 pump 里同时收集(截断 400 字符足够定位)
|
||||
msg.get("method")=="Runtime.exceptionThrown" → exceptionDetails.exception.description
|
||||
msg.get("method")=="Log.entryAdded" and level=="error" → entry.text
|
||||
```
|
||||
|
||||
"Rendered more hooks than during the previous render" + 页面变 "This page couldn't load" = 常驻组件 hook 数量在路由切换时变化(查早退 return 的位置)。
|
||||
|
||||
## 4. 提交门禁
|
||||
|
||||
```bash
|
||||
npx tsc --noEmit -p . # 类型零错误
|
||||
npx next build # 编译 + 预渲染通过
|
||||
git commit -m "fix/feat: 中文主题
|
||||
|
||||
- 要点正文(改动 + 原因 + 对齐的原站行为)"
|
||||
```
|
||||
|
||||
## 5. 回归清单(发布前手跑一遍)
|
||||
|
||||
- [ ] 首页首载:幕布进度 0→100 → 揭幕 → 网格浮现 → banner 文案 scramble
|
||||
- [ ] 首页文案/作品说明可见(像素断言)
|
||||
- [ ] 3D 场景/贴纸/作品图可见;离开首页 canvas=0、无贴纸残留
|
||||
- [ ] 详情页从根路径 slug 可达;无十字网格;能滚(wheel)
|
||||
- [ ] TOC 高亮跟随 + 点击滚动到 top≈96;标题锚点复制链接
|
||||
- [ ] 代码块 COPY → COPIED → 1200ms 还原
|
||||
- [ ] 页脚 Metadata 实时值;Work/Contact 回首页滚动定位
|
||||
- [ ] /2026 未解锁显示解锁屏;正确口令解锁后 TikTok 卡片出现;长按可锁回
|
||||
- [ ] BGM 首次手势后发声;开关持久化
|
||||
- [ ] 自定义滚动条拖拽/点击 track;移动端圆环
|
||||
- [ ] 缩放窗口 canvas 不卡 1440×150(CanvasSizeGuard)
|
||||
@@ -0,0 +1,53 @@
|
||||
# haoqi.design 1:1 克隆 — 实现文档
|
||||
|
||||
本目录记录这个仓库(对 https://haoqi.design/ 的像素级克隆)中**每一个系统是怎么实现的、为什么这么做、踩过哪些坑**,以及**如果让 AI 复刻某一部分,提示词应该怎么写**。
|
||||
|
||||
## 阅读顺序
|
||||
|
||||
| 文档 | 内容 |
|
||||
|---|---|
|
||||
| [01-methodology.md](01-methodology.md) | 逆向方法论:怎么从原站提取设计、怎么验证、怎么提交 |
|
||||
| [02-visual-foundations.md](02-visual-foundations.md) | 层叠系统 / 设计令牌 / 字体 / 十字网格背景 |
|
||||
| [03-scroll-and-transitions.md](03-scroll-and-transitions.md) | 滚动系统 / 路由过渡 / 锚点定位 |
|
||||
| [04-webgl-canvas.md](04-webgl-canvas.md) | R3F 场景组成 / DOM 注册表 / 贴纸 / 后期 / 加载门 |
|
||||
| [05-home-sections.md](05-home-sections.md) | 首页各区块 / 文字特效 / 自定义滚动条 / BGM |
|
||||
| [06-detail-pages-mdx.md](06-detail-pages-mdx.md) | 详情页 MDX 全套:目录/锚点/代码块/页脚 + 内容管线 |
|
||||
| [07-passcode.md](07-passcode.md) | 口令保护系统(cookie / API / TikTok 卡片) |
|
||||
| [08-verification.md](08-verification.md) | 验证工作流:CDP 探针 / 像素断言 / 回归清单 |
|
||||
| [prompts.md](prompts.md) | **提示词合集**:每个系统让 AI 复刻时的提示词写法 |
|
||||
|
||||
## 技术栈
|
||||
|
||||
- **Next.js(App Router,Turbopack)+ React 19**,`output: "standalone"`(Docker 部署,`node server.js`)
|
||||
- **Tailwind CSS v4**(`@theme` + 任意变体选择器,无 tailwind.config)
|
||||
- **@react-three/fiber + drei**:唯一一个全屏 fixed Canvas(仅首页挂载)
|
||||
- **lenis**:window 级平滑滚动(仅首页)
|
||||
- 无 CMS / 无数据库:文章内容是生成进仓库的 TypeScript 常量(`content/workArticles.ts`)
|
||||
|
||||
## 一图流架构
|
||||
|
||||
```
|
||||
app/layout.tsx (PasscodeAccessProvider + FullscreenTransitionProvider)
|
||||
├─ components/canvas/HeroScene.tsx ← -z-1 fixed 全屏 Canvas(仅 "/" 挂载)
|
||||
├─ components/dom/BackgroundGrid.tsx ← z-20 fixed 十字网格(仅 "/")
|
||||
├─ components/dom/Header.tsx ← z-50 fixed(菜单 / 主题 / 声音开关 + useBgm)
|
||||
├─ <main>{page}</main> ← 普通流内容(永远画在 canvas 之上)
|
||||
├─ components/dom/CustomScrollbar.tsx ← SVG 自定义滚动条
|
||||
├─ components/dom/LoadingOverlay.tsx ← 加载幕布(进度 0→100)
|
||||
└─ components/dom/RouteTransitionOverlay← 路由过渡 cover/reveal(z-60)
|
||||
|
||||
页面:
|
||||
app/page.tsx 首页(banner → about → WorkSection → HyperSpace → Footer)
|
||||
app/work/[slug]/page.tsx 详情页(MDX 文章 + TOC + CodeBlock + ArticleFooter)
|
||||
app/unlock/[scope]/page.tsx 口令解锁页
|
||||
app/api/passcode/route.ts 口令校验 API(cookie 签发)
|
||||
```
|
||||
|
||||
## 硬性约定(违反必出回归)
|
||||
|
||||
1. **背景色只挂在 `html` 根上**,不挂 `body` —— 否则普通流的 body 背景会盖住 `-z-1` 的 WebGL 场景(已踩坑,见 02)。
|
||||
2. **WebGL 容器必须是 `top-0 left-0 -z-1 fixed`**(原站类名 1:1)—— z-auto 的 fixed 会按 CSS 绘制顺序盖住所有普通流文字(已踩坑)。
|
||||
3. **`<main>` 不能是滚动容器** —— sticky 子元素(hyper-space)依赖 window 滚动才能 pin 住。
|
||||
4. **组件里的早退 return 必须放在所有 hooks 之后** —— 常驻 layout 的组件(如 BackgroundGrid)在路由切换时 hook 数量变化会直接崩(已踩坑)。
|
||||
5. 改 `next.config.ts` 后 dev server 会重启,探测前等 6–8 秒。
|
||||
6. 提交前必须过:`npx tsc --noEmit -p .` + `npx next build`;提交信息用中文 `feat:`/`fix:` + 要点正文。
|
||||
@@ -0,0 +1,61 @@
|
||||
# prompts.md · AI 复刻提示词合集
|
||||
|
||||
按系统拆开的一组"可直接投喂"的提示词。设计思路见 01–08 各篇;这里是浓缩版,**每条都可独立使用**(自带上下文)。
|
||||
|
||||
## 使用说明
|
||||
|
||||
1. **先给架构再给细节**:AI 在没有层叠/滚动模型时写的"看起来对"的代码,正是层叠事故的来源。每条提示词开头的全局约定段不可删。
|
||||
2. **把原站提取值直接贴进提示词**(类串/颜色/时长/easing),并明确"逐字使用,不要优化"。
|
||||
3. **每条都带验证断言**:让 AI 自己用 CDP + 像素统计闭环,而不是只靠肉眼看代码。
|
||||
4. 提示词里的"我提供"项 = 从原站 SSR/chunk 提取的数据(方法见 01),投喂前先备好。
|
||||
|
||||
---
|
||||
|
||||
## 0. 全局约定段(放在任何一条提示词的开头)
|
||||
|
||||
> 项目:haoqi.design 的 1:1 克隆。技术栈 Next.js App Router(Turbopack)+ React 19 + Tailwind CSS v4(@theme,无 config 文件)+ @react-three/fiber。所有类名、时长、easing、颜色都是逐字从原站 bundle/CSS 提取的——除非我明确说改,否则照抄,不要"优化"或改写任意变体选择器。
|
||||
> 铁律:① 背景色只挂 html 根;② WebGL 容器是 top-0 left-0 -z-1 fixed;③ <main> 不得是滚动容器(sticky 依赖 window 滚动);④ 常驻 layout 组件的早退 return 放在所有 hooks 之后;⑤ 站内导航一律走全局过渡 startNavigation;⑥ 编程滚动一律走 scrollEnv,不直接摸 Lenis;⑦ 完成后必须 npx tsc --noEmit 和 npx next build 都过,并用无头 Chrome CDP 验证后提交(中文 feat:/fix: 提交信息)。
|
||||
|
||||
---
|
||||
|
||||
## 1. 项目脚手架 + 设计令牌
|
||||
|
||||
> 从零搭 Next.js App Router 项目复刻 haoqi.design 的视觉基础:Tailwind v4 的 @theme 定义令牌——主文字 rgba(0,0,0,1)、次要文字 rgba(54,54,48,.6)、三级 rgba(54,54,48,.32)、分隔线 rgba(54,54,48,.1)、页面底色 rgb(251,250,244)、品牌荧光绿 #c0fe04;再定义 7 个代码高亮 CSS 变量(我提供 lab() 精确值:string lab(43.8263% -47.6118 18.596)、number lab(46.7992% 8.99872 72.9973)、keyword lab(43.3789% 36.2819 -73.3524)、function lab(47.3165% -8.24019 -45.3882)、tag lab(47.2741% 51.266 23.7532)、comment rgba(54,54,48,.45)、operator rgba(54,54,48,.75))。三套 localFont:TikTokSans(--font-tiktok 正文)、GeistMono(--font-mono 代码)、DepartureMono(--font-mono-2 header)。背景色只写在 html 选择器上,body 只放字体/颜色/平滑。大标题一律 font-bold + fontVariationSettings:"wdth" 120。完成后截图断言页面底色与文字对比。
|
||||
|
||||
## 2. 层叠系统 + 十字网格
|
||||
|
||||
> 实现 haoqi.design 的层叠与十字网格:body 直接子元素顺序 = [-z-1 fixed WebGL 容器, z-30 fixed 点阵层, z-20 fixed mix-blend-difference 网格, z-50 fixed header, main(普通流), z-10 relative footer]。网格组件用 usePathname 门控:仅首页显示、且首页加载完成(loadingBus.ready)后才显示;早退放在全部 hooks 之后。SVG 画法:viewBox=视口;竖线在左右内边距 56px(<1024px 用 16px)之间的 2 或 3 等分点(<1280px 2 列),x=Math.round(x)+0.5,shape-rendering crispEdges;两条横线 y=h/3-12 与 2h/3+12;横线遇竖线两侧各断开 12px,竖线在横线区间断成三段;交叉点画 12px 白色 opacity .4 十字。验证:截图统计网格线带深色像素 >20% 且 banner 文案区深色像素 >5%(证明文字在场景之上)。
|
||||
|
||||
## 3. WebGL 场景 + DOM 注册表
|
||||
|
||||
> 用 R3F 实现全屏场景层(容器 top-0 left-0 -z-1 fixed w-full h-dvh lg:h-screen pointer-events-none,Canvas style 强制 pointerEvents:none 且仅首页挂载):① 两枚玻璃模型(hello.gltf、cursor.glb)随滚动入场;② 作品图与头像由"DOM 注册表"驱动——模块级 Map<key,{imageUrl,hoverImageUrl}>,DOM 组件(头像 aspect-square 占位、作品卡占位 div)注册后 touch 版本号,Canvas 端每帧读 getBoundingClientRect() 投影成带视差的 3D 平面,hover 换 hoverImageUrl;③ 贴纸雨(图集加载完 mark 进 loadingBus);④ 相机进度 = clamp01((vh-bannerBottom)/(vh*.75)) * clamp01(footerTop/vh),全局 scrollBus 每帧更新;⑤ 轻后期 + alpha 通道(场景必须透出根背景)。必须处理 R3F 首测竞态:挂载后 40 帧持续比对 canvas.style 与父容器尺寸,mismatch 时 gl.setSize+setSize。验证:canvas 尺寸=视口、场景区平均色≠底色、离开首页 canvas=0。
|
||||
|
||||
## 4. 滚动 + 路由过渡 + 跨页锚点
|
||||
|
||||
> 实现滚动与路由:window 级 Lenis 仅首页挂载(详情页彻底销毁,scrollRestoration=manual、路由变更回顶、pageshow persisted 也回顶);scrollEnv 抽象(lenisScrollTo 支持 number|selector|element 带 lerp/immediate,scrollIntoView 回退);全局过渡 Provider:startNavigation(href) → 0.8s b1 底色覆盖层擦入(cubic-bezier(0.66,0,0.01,1))→ router.push → 新页挂载 → 擦出,期间防重入,z-60。详情页页脚 Work/Contact = sessionStorage["hq:pendingScrollAnchor"] 存锚点 + startNavigation("/");首页滚动器挂载后读取并立即删除该 key,双 rAF 后 lerp .1 滚到目标。文章锚点滚动统一 top-96 偏移。验证:CDP 完整点击链 + sessionStorage 断言。
|
||||
|
||||
## 5. ScrambleReveal 文字系统
|
||||
|
||||
> 实现 scramble 文字组件:字符集 A-Z0-9!@#$%^&*+-=?/<>[]{},40ms tick;第 i 字符 startDelayMs+i*letterDelayMs 开始,2 相位 × 2*letterDelayMs 定格,相位 0 #c0fe04 / 相位 1 #607F02(可关);IntersectionObserver .1 触发;支持 slot {length,scramble,settled,className}(扰动期占位、定格渲染节点)。用在 banner 三行大标题(300/500/700 错峰)与页脚 Metadata(300/360/420,scrambleColors=false)。banner 介绍文字每个词一个 inline mx-[0.06em] span,品牌词是可点击链接 span。验证:水合后文本齐全、扫描态可见 #c0fe04 闪色。
|
||||
|
||||
## 6. 作品网格 + sticky 超空区
|
||||
|
||||
> 作品区(id=selected-work):数据数组含 name/imageUrl/hoverImageUrl/href/year/type/gridClass/codingProject/passcodeProtected;卡片 article>a.group.block.space-y-3.p-2,图片区仅 aspectRatio 占位 div(WebGL 投影),codingProject 项右上角 z-10 absolute bg-selection px-1 font-mono-2 角标,说明行 flex justify-between(名称/年份/类型);点击走 startNavigation。之后一个 top-0 sticky 区块(id=hyper-space),IntersectionObserver rootMargin "480px 0px 480px 0px" 检测接近 → 通知 WebGL 放大隧道穿越。受保护项按 !passcodeProtected || allowed(href) 过滤(口令系统另做)。
|
||||
|
||||
## 7. 详情页 MDX 全套
|
||||
|
||||
> 克隆 haoqi.design 文章页(/work/[slug],根路径 slug 用 beforeFiles rewrites)。内容数据结构我提供:blocks = p(segs)|h2/h3/h4(text,id)|code(language,label,html,text)|list(ordered,items)|quote|img|hr,code.html 是原站 prism 高亮后的 span.token+行号行 HTML。实现:① 文章骨架(article[data-mdx-article] max-w-[880px],header pt-[10vh]:h1 wdth120 + 日期 + 分隔线 + 年份);② prose 容器类逐字全串(我贴,含 [&_u] 径向渐变点状下划线);③ MdxHeading:类 map mt-10 text-xl…,id 中文保留,锚点 a[aria-label="Copy link to …"] + lg:group-hover 显 #,点击滚动 top-96 + replaceState + 复制 URL;④ MdxTableOfContents:fixed left-0 w-[320px] 仅 2xl:flex,收集有 id 的 h1-h3,缩进 0/8/16,active=最后一个 top<=96(scroll/resize/RO 监听),无标题渲染 null;⑤ CodeBlock:rounded-xl 组 + header(语言标签 text-(--label-3) + COPY/COPIED dotted 按钮 1200ms 还原)+ pre(font-mono text-xs leading-relaxed)+ code.language-X dangerouslySetInnerHTML 注入预高亮 HTML(配色走 --code-* 变量,不引入 prism 库);⑥ ArticleFooter:Metadata 三列(日期/实时视口尺寸/字符数 toLocaleString)+ ScrambleReveal 错峰 + Links(Home=Link,Work/Contact=锚点+过渡回首页,社交 # 占位)。
|
||||
|
||||
## 8. 口令系统
|
||||
|
||||
> 加口令保护(原站 /2026):cookie hq-passcode-access 存 Record<scope,boolean>;API GET/POST(code=env PASSCODE_CODE 默认 2026,错误 401);usePasscodeAllowed + 自定义事件同 tab 即时生效;作品网格 !passcodeProtected || allowed(href) 过滤,品牌名运行时 revealBrandLabel() 还原;/unlock/[scope] 全屏 z-1000 bg-b1,隐藏 input、4 格、错误扰动、成功广播 + returnTo(sanitize 只收站内);banner 内长按 500ms 重新锁定按钮(aria-label "… — long press to lock again")。验证:POST 正确口令后卡片出现、错误 401、清 cookie 后消失。
|
||||
|
||||
## 9. 自定义滚动条 + BGM
|
||||
|
||||
> ① 隐藏原生滚动条,SVG 自定义:桌面右侧 track+thumb path(M x y V y2 实时按 scrollTop/scrollHeight),可拖拽(pointer capture)、点击 track 跳转、闲置自动隐藏;移动端右缘圆环进度。② BGM:fetch /bgm.mp3 → objectURL 只加载一次,Audio loop volume .35;enabled 切换 play/pause;play() 被自动播放策略拒绝时挂一次性 pointerdown/keydown/touchstart 手势重试(用 enabledRef 让加载 effect 拿到最新开关状态);卸载 revokeObjectURL;开关 localStorage 持久化。验证:手势后 audio.paused=false;滚动时 path d 变化。
|
||||
|
||||
---
|
||||
|
||||
## 10. 万能验证提示词(每轮改动后)
|
||||
|
||||
> 用无头 Chrome(--remote-debugging-port=9223)+ websocket Runtime.evaluate 对 localhost:3000 做回归:① 首页 banner 文案齐全 opacity 1;② 截图用 PIL 断言三层共存(文案带深色 >5%、场景均值≠底色、网格线带 >20%);③ /wasm_design_utils 有 4 pre、TOC 7 项、无十字网格 div、canvas=0,TOC 点击后目标 top≈96;④ 详情页滚轮可滚;⑤ 页脚 dd 出现实时尺寸与字符数;⑥ 点击页脚 Work 后 3s 内回到 / 且 pendingScrollAnchor 已清除;⑦ 全程收集 Runtime.exceptionThrown 与 Log.error,出现 "Rendered more hooks" 立即报出组件名。最后跑 tsc --noEmit 和 next build。
|
||||
Reference in New Issue
Block a user