"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 (
); }