feat: 移植 Selected Work 区块(10 个作品卡片 + WebGL 图像层注册表),修复 canvas 吞掉 DOM 悬停

- WorkSection.tsx:1:1 还原原站 work 区块(selected-work 网格、rowGap=clientWidth/12、纵横比缓存、Coding Project 徽章、元数据行、外链/内链卡片)
- workItems.ts:从 d59f7a97 数据文件提取的 10 个作品条目(passcode 保护的 /2026 TikTok 条目按原站默认过滤)
- imageLayers.ts:重构为注册表(defs/targets/订阅版本号),ImageLayers 通过 useSyncExternalStore 响应 DOM 卡片注册
- HeroScene:Canvas 容器强制 pointer-events:none,指针跟踪全部走窗口级,避免吞掉 work 卡片悬停
- Header:Work 按钮滚动至 selected-work
This commit is contained in:
2026-09-01 16:37:19 +08:00
parent e3e5a3663e
commit eac0785cf6
7 changed files with 400 additions and 16 deletions
+4
View File
@@ -1,6 +1,7 @@
import ScrambleReveal from "@/components/dom/ScrambleReveal";
import AboutMedia from "@/components/dom/AboutMedia";
import FooterSection from "@/components/dom/FooterSection";
import WorkSection from "@/components/dom/WorkSection";
/**
* Page content matching the original DOM (haoqi_body.html):
@@ -102,6 +103,9 @@ export default function Home() {
</div>
</div>
{/* Selected Work grid (id="selected-work", WebGL image layers) */}
<WorkSection />
{/* Contact / Footer Section (#contact, data-section="footer") */}
<FooterSection />
</div>
+9 -5
View File
@@ -119,6 +119,12 @@ export function HeroScene() {
<Canvas
dpr={[1, 2]}
gl={{ alpha: true, antialias: true }}
// R3F forces pointerEvents:auto on its container div, which would
// swallow every pointer event for the DOM beneath the fixed canvas
// (work-card hovers, link hovers). All pointer tracking in this port
// is window-level (lib/pointer), so the canvas is fully transparent
// to hit-testing — matching the original site.
style={{ pointerEvents: "none" }}
>
<CanvasSizeGuard />
{/* Camera rig: horizontal FOV 60/38, distance lerp(24, 32, sP),
@@ -141,15 +147,13 @@ export function HeroScene() {
glass FBO pass (which renders with a layer-0 camera mask). */}
<StickerDrop />
{/* DOM-tracked image layers (about section m3.png), rendered above
stickers via renderOrder 20. */}
{/* DOM-tracked image layers (about + selected-work cards), rendered
above stickers via renderOrder 20. */}
<ImageLayers />
{/* Glass hero models (hello + blue cursor star), refractive tint shader */}
{/* Glass hero models (hello + blue cursor star + footer cnt), refractive tint shader */}
<HelloModel isMobile={isMobile} />
<CursorStar isMobile={isMobile} />
{/* #contact footer model (original: cnt.gltf scale 19, x-180° flip,
section-anchored, scrollSyncFactor 1) */}
<FooterModel />
{/* Post FX (original cG): lens-flare star streaks + pointer-driven
+19 -6
View File
@@ -1,11 +1,17 @@
"use client";
import { Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Suspense, useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
import { useFrame, useLoader, useThree } from "@react-three/fiber";
import * as THREE from "three";
import { scrollBus } from "@/lib/scrollBus";
import { useIsMobile } from "@/lib/useIsMobile";
import { imageLayerTargets } from "@/lib/imageLayers";
import {
getLayerDef,
getLayerKeys,
getLayerRegistryVersion,
imageLayerTargets,
subscribeLayerRegistry,
} from "@/lib/imageLayers";
import { loadingBus } from "@/lib/loadingBus";
/**
@@ -499,11 +505,18 @@ function ImageLayer({ def }: { def: ImageLayerDef }) {
/** Canvas-side entry: renders every registered image layer. */
export function ImageLayers() {
const version = useSyncExternalStore(
subscribeLayerRegistry,
getLayerRegistryVersion,
getLayerRegistryVersion
);
const defs = useMemo<ImageLayerDef[]>(() => {
const layers: ImageLayerDef[] = [];
if (imageLayerTargets.about) layers.push({ key: "about", imageUrl: "/img/m3.png" });
return layers;
}, []);
void version;
return getLayerKeys().map((key) => {
const def = getLayerDef(key)!;
return { key, imageUrl: def.imageUrl, hoverImageUrl: def.hoverImageUrl };
});
}, [version]);
return (
<Suspense fallback={null}>
+1 -1
View File
@@ -194,7 +194,7 @@ export default function Header() {
<button
type="button"
className={`${dotted} p-2 uppercase cursor-pointer`}
onClick={() => scrollEnv.scrollToSection('[data-section="about"]')}
onClick={() => scrollEnv.scrollToSection("#selected-work")}
>
<ScrambleReveal text="Work" startDelayMs={300} scrambleColors={false} />
</button>
+176
View File
@@ -0,0 +1,176 @@
"use client";
import { useEffect, useMemo, useRef, useState } from "react";
import {
SELECTED_WORK_SECTION_ID,
WORK_ITEMS,
type WorkItem,
} from "@/lib/workItems";
import {
getLayerTarget,
setLayerDef,
touchLayerRegistry,
} from "@/lib/imageLayers";
/**
* Selected Work grid — 1:1 port of the original section `h` (chunk
* 2689132c4e070b68.js, exports SELECTED_WORK_SECTION_ID / default):
*
* - `<section id="selected-work" className="px-4 lg:px-14 py-18 lg:py-24 w-full">`
* with an inner `grid grid-cols-12` whose `rowGap` is the measured column
* width (container.clientWidth / 12, tracked by ResizeObserver).
* - Each card is `<article className={gridClass}>` wrapping a `group block
* space-y-3 p-2` anchor (next Link for internal routes, <a> for external).
* - The visual is NOT a DOM <img>: the anchor's first child is an
* aspect-ratio placeholder div registered as a WebGL image-layer target;
* the canvas-side ImageLayers projects imageUrl/hoverImageUrl onto its
* screen rect (curl + negative reveal + hover dot mask).
* - Aspect ratios come from preloading each imageUrl and reading
* naturalWidth/naturalHeight into a module-level cache (original `o`).
* - The passcode-protected first item (/2026, brand "TikTok") is omitted
* exactly like the original's default-unlocked state.
*/
// Module-level cache mirroring the original `o` (persists across remounts).
const ratioCache: Record<string, string> = {};
export default function WorkSection() {
const [ratios, setRatios] = useState<Record<string, string>>({ ...ratioCache });
const [colWidth, setColWidth] = useState(0);
const gridRef = useRef<HTMLDivElement | null>(null);
// Register canvas layer defs for every visible item (idempotent data
// write; the version bump happens once targets exist, in the effect).
useMemo(() => {
for (const item of WORK_ITEMS) {
setLayerDef(item.href, {
imageUrl: item.imageUrl,
hoverImageUrl: item.hoverImageUrl,
});
}
}, []);
useEffect(() => {
touchLayerRegistry();
}, []);
// rowGap = column width (original RO on the grid container).
useEffect(() => {
const el = gridRef.current;
if (!el) return;
const measure = () => setColWidth(el.clientWidth / 12);
measure();
const ro = new ResizeObserver(measure);
ro.observe(el);
return () => ro.disconnect();
}, []);
// Preload images → natural aspect ratios (original effect).
useEffect(() => {
let cancelled = false;
const update = (imageUrl: string, w: number, h: number) => {
if (cancelled || w <= 0 || h <= 0) return;
const ratio = `${w} / ${h}`;
if (ratioCache[imageUrl] !== ratio) ratioCache[imageUrl] = ratio;
setRatios((prev) => (prev[imageUrl] === ratio ? prev : { ...prev, [imageUrl]: ratio }));
};
const images = WORK_ITEMS.map((item) => {
const img = new Image();
img.decoding = "async";
img.onload = () => update(item.imageUrl, img.naturalWidth, img.naturalHeight);
img.src = item.imageUrl;
if (img.complete && img.naturalWidth > 0 && img.naturalHeight > 0) {
update(item.imageUrl, img.naturalWidth, img.naturalHeight);
}
return img;
});
return () => {
cancelled = true;
for (const img of images) img.onload = null;
};
}, []);
return (
<section
id={SELECTED_WORK_SECTION_ID}
className="px-4 lg:px-14 py-18 lg:py-24 w-full"
>
<div
ref={gridRef}
className="grid grid-cols-12 w-full"
style={{ rowGap: `${colWidth}px` }}
>
{WORK_ITEMS.map((item) => (
<WorkCard key={item.href} item={item} ratio={ratios[item.imageUrl]} />
))}
</div>
</section>
);
}
function WorkCard({ item, ratio }: { item: WorkItem; ratio?: string }) {
const external = item.href.startsWith("http://") || item.href.startsWith("https://");
const cls = "group block space-y-3 p-2";
const label = `${item.name} - ${item.year}${external ? " (external)" : ""}`;
const target = getLayerTarget(item.href);
const body = (
<>
<div
ref={(el) => {
target.current = el;
}}
aria-hidden="true"
className="relative w-full pointer-events-none select-none"
style={{ aspectRatio: ratio ?? "1 / 1" }}
>
{item.codingProject && (
<span
className="top-0 right-0 z-10 absolute bg-selection px-1 font-mono-2 text-black text-xs uppercase pointer-events-none select-none"
aria-hidden="true"
>
Coding Project
</span>
)}
</div>
<div className="flex justify-between items-center gap-3 min-w-0 text-xs lg:text-sm uppercase">
<span className="flex-1 min-w-0 truncate">{item.name}</span>
<div className="flex items-center gap-2 sm:gap-3 font-mono-2 tabular-nums whitespace-nowrap shrink-0">
<span>{item.year}</span>
{item.type !== "post" && (
<span className="hidden lg:inline-flex items-center gap-1" aria-hidden="true">
<span>{item.type}</span>
<span>↗</span>
</span>
)}
</div>
</div>
</>
);
return (
<article className={item.gridClass ?? "col-span-12 lg:col-span-6 xl:col-span-4"}>
{external ? (
<a
href={item.href}
target="_blank"
rel="noopener noreferrer"
className={cls}
aria-label={label}
>
{body}
</a>
) : (
// Internal detail routes (/reunimos, /inspire_mono, …) are not ported
// yet — keep the anchor for markup parity but don't navigate to a 404.
<a
href={item.href}
className={cls}
aria-label={label}
onClick={(e) => e.preventDefault()}
>
{body}
</a>
)}
</article>
);
}
+71 -4
View File
@@ -1,11 +1,78 @@
/**
* Shared DOM-target registry for WebGL image layers (original `t.layers`:
* `{ key, imageUrl, hoverImageUrl, targetRef }`). The page component attaches
* the DOM element; the canvas-side ImageLayers component reads the same
* object (both live in the client bundle, so it is one shared instance).
* `{ key, imageUrl, hoverImageUrl, targetRef }`).
*
* - The page component attaches a DOM element per key and registers its
* texture def (SelectedWorkSection, AboutMedia).
* - The canvas-side ImageLayers component subscribes to the registry and
* renders one layer per (key, def) pair.
* - Both live in the client bundle, so it is one shared module instance.
*
* Registration is a plain data write (safe during render, idempotent);
* `touchLayerRegistry()` bumps the version so subscribers re-render — call
* it from an effect after the DOM refs have been attached.
*/
export type ImageLayerTarget = { current: HTMLElement | null };
export const imageLayerTargets: Record<string, ImageLayerTarget> = {
export type ImageLayerDef = {
imageUrl: string;
hoverImageUrl?: string;
};
const defs = new Map<string, ImageLayerDef>([
["about", { imageUrl: "/img/m3.png" }],
]);
const targets: Record<string, ImageLayerTarget> = {
about: { current: null },
};
const listeners = new Set<() => void>();
let version = 0;
function emit() {
for (const cb of listeners) cb();
}
export function setLayerDef(key: string, def: ImageLayerDef) {
const prev = defs.get(key);
if (prev && prev.imageUrl === def.imageUrl && prev.hoverImageUrl === def.hoverImageUrl) {
if (!targets[key]) targets[key] = { current: null };
return;
}
defs.set(key, def);
if (!targets[key]) targets[key] = { current: null };
}
export function getLayerTarget(key: string): ImageLayerTarget {
if (!targets[key]) targets[key] = { current: null };
return targets[key];
}
export function getLayerKeys(): string[] {
return [...defs.keys()];
}
export function getLayerDef(key: string): ImageLayerDef | undefined {
return defs.get(key);
}
export function subscribeLayerRegistry(cb: () => void): () => void {
listeners.add(cb);
return () => {
listeners.delete(cb);
};
}
export function getLayerRegistryVersion(): number {
return version;
}
/** Notify subscribers that defs/targets changed. Safe to call repeatedly. */
export function touchLayerRegistry() {
version += 1;
emit();
}
// Back-compat: the about target accessed directly by AboutMedia.
export const imageLayerTargets = targets;
+120
View File
@@ -0,0 +1,120 @@
/**
* WORK_ITEMS — 1:1 from the original d59f7a97fb1c563f.js (module 28116),
* minus the passcode-protected entry (the original grid also omits it until
* the passcode is unlocked: `WORK_ITEMS.filter(t => !t.passcodeProtected ||
* lookup(t.href))` — the locked one reveals the brand label "TikTok").
*
* Internal hrefs (/reunimos, /inspire_mono, …) are detail-page routes that
* do not exist in this clone yet; WorkSection renders them as inert links
* until the route system is ported.
*/
export type WorkItem = {
name: string;
imageUrl: string;
hoverImageUrl: string;
href: string;
year: string;
type: "post" | "tools" | "event";
gridClass: string;
codingProject?: boolean;
};
export const SELECTED_WORK_SECTION_ID = "selected-work";
export const WORK_ITEMS: WorkItem[] = [
{
name: "Reunimos™",
imageUrl: "/work/reunimos01.png",
hoverImageUrl: "/work/reunimos02.png",
href: "/reunimos",
year: "2024-2026",
type: "post",
gridClass: "col-span-12 lg:col-span-8 lg:col-start-5",
codingProject: true,
},
{
name: "Inspire Mono",
imageUrl: "/work/inspire_mono_01.png",
hoverImageUrl: "/work/inspire_mono_02.png",
href: "/inspire_mono",
year: "2025",
type: "post",
gridClass: "col-span-12 lg:col-start-1 lg:col-span-6 xl:col-span-5",
codingProject: true,
},
{
name: "Wasm design utils",
imageUrl: "/work/wasm01.png",
hoverImageUrl: "/work/wasm02.png",
href: "/wasm_design_utils",
year: "2025",
type: "post",
gridClass: "col-span-12 lg:col-span-6 xl:col-span-5 lg:col-start-7 xl:col-start-7",
codingProject: true,
},
{
name: "VectorSymbols",
imageUrl: "/work/vs01.png",
hoverImageUrl: "/work/vs02.png",
href: "https://www.figma.com/community/plugin/1255914175202017737/vectorsymbols",
year: "2023",
type: "tools",
gridClass: "col-span-6 lg:col-start-5 lg:col-span-4 xl:col-start-6 xl:col-span-3",
codingProject: true,
},
{
name: "DarkSide",
imageUrl: "/work/ds01.png",
hoverImageUrl: "/work/ds02.png",
href: "https://www.figma.com/community/plugin/986289377230504703/darkside",
year: "2021",
type: "tools",
gridClass: "col-span-6 lg:col-start-9 lg:col-span-4 xl:col-start-10 xl:col-span-3",
codingProject: true,
},
{
name: "aDrive 阿里云盘",
imageUrl: "/work/ali01.png",
hoverImageUrl: "/work/ali02.png",
href: "/adrive",
year: "2020-2022",
type: "post",
gridClass: "col-span-12 lg:col-start-1 lg:col-span-4 xl:col-start-1 xl:col-span-3",
},
{
name: "Shore Icon",
imageUrl: "/work/si.png",
hoverImageUrl: "/work/si02.png",
href: "/shore_icon",
year: "2022",
type: "post",
gridClass: "col-span-6 lg:col-start-5 lg:col-span-4 xl:col-start-5 xl:col-span-3",
},
{
name: "Teambition",
imageUrl: "/work/c4.png",
hoverImageUrl: "/work/c4.png",
href: "/teambition",
year: "2018-2020",
type: "post",
gridClass: "col-span-6 lg:col-start-9 lg:col-span-4 xl:col-start-9 xl:col-span-3",
},
{
name: "FoF: See Hear Touch",
imageUrl: "/work/s01.png",
hoverImageUrl: "/work/s02.png",
href: "https://friends.figma.com/events/details/figma-shanghai-presents-see-hear-touch/",
year: "2022",
type: "event",
gridClass: "col-span-6 lg:col-start-5 lg:col-span-4 xl:col-start-6 xl:col-span-3",
},
{
name: "FoF: Design System",
imageUrl: "/work/sd01.png",
hoverImageUrl: "/work/sd02.png",
href: "https://friends.figma.com/events/details/figma-shanghai-presents-design-system/",
year: "2021",
type: "event",
gridClass: "col-span-6 lg:col-start-9 lg:col-span-4 xl:col-start-10 xl:col-span-3",
},
];