diff --git a/app/page.tsx b/app/page.tsx index e760a37..74f9f72 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -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() { + {/* Selected Work grid (id="selected-work", WebGL image layers) */} + + {/* Contact / Footer Section (#contact, data-section="footer") */} diff --git a/components/canvas/HeroScene.tsx b/components/canvas/HeroScene.tsx index 21cf52b..011fb7c 100644 --- a/components/canvas/HeroScene.tsx +++ b/components/canvas/HeroScene.tsx @@ -119,6 +119,12 @@ export function HeroScene() { {/* 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). */} - {/* 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. */} - {/* Glass hero models (hello + blue cursor star), refractive tint shader */} + {/* Glass hero models (hello + blue cursor star + footer cnt), refractive tint shader */} - {/* #contact footer model (original: cnt.gltf scale 19, x-180° flip, - section-anchored, scrollSyncFactor 1) */} {/* Post FX (original cG): lens-flare star streaks + pointer-driven diff --git a/components/canvas/ImageLayers.tsx b/components/canvas/ImageLayers.tsx index 39d62f4..e07aa8f 100644 --- a/components/canvas/ImageLayers.tsx +++ b/components/canvas/ImageLayers.tsx @@ -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(() => { - 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 ( diff --git a/components/dom/Header.tsx b/components/dom/Header.tsx index f50b94e..091870c 100644 --- a/components/dom/Header.tsx +++ b/components/dom/Header.tsx @@ -194,7 +194,7 @@ export default function Header() { diff --git a/components/dom/WorkSection.tsx b/components/dom/WorkSection.tsx new file mode 100644 index 0000000..7e1df4b --- /dev/null +++ b/components/dom/WorkSection.tsx @@ -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): + * + * - `
` + * with an inner `grid grid-cols-12` whose `rowGap` is the measured column + * width (container.clientWidth / 12, tracked by ResizeObserver). + * - Each card is `
` wrapping a `group block + * space-y-3 p-2` anchor (next Link for internal routes, for external). + * - The visual is NOT a DOM : 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 = {}; + +export default function WorkSection() { + const [ratios, setRatios] = useState>({ ...ratioCache }); + const [colWidth, setColWidth] = useState(0); + const gridRef = useRef(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 ( +
+
+ {WORK_ITEMS.map((item) => ( + + ))} +
+
+ ); +} + +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 = ( + <> +
{ + target.current = el; + }} + aria-hidden="true" + className="relative w-full pointer-events-none select-none" + style={{ aspectRatio: ratio ?? "1 / 1" }} + > + {item.codingProject && ( + + )} +
+
+ {item.name} +
+ {item.year} + {item.type !== "post" && ( + + )} +
+
+ + ); + + return ( +
+ ); +} diff --git a/lib/imageLayers.ts b/lib/imageLayers.ts index 38829a5..16add02 100644 --- a/lib/imageLayers.ts +++ b/lib/imageLayers.ts @@ -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 = { +export type ImageLayerDef = { + imageUrl: string; + hoverImageUrl?: string; +}; + +const defs = new Map([ + ["about", { imageUrl: "/img/m3.png" }], +]); + +const targets: Record = { 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; diff --git a/lib/workItems.ts b/lib/workItems.ts new file mode 100644 index 0000000..a8d9550 --- /dev/null +++ b/lib/workItems.ts @@ -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", + }, +];