8ce5471c25
- lib/passcode.ts:module 58156/28116 移植——primaryPasscodePath("/2026")、buildPasscodeUnlockHref("/unlock/2026?return=%2F")、slotCount:4、品牌名按原站 charCode-1 混淆解码(TikTok)、锁定占位符与字符/散段样式类
- PasscodeAccess.tsx:module 4278 移植——access store(useSyncExternalStore + passcode-access-changed 事件驱动刷新)、usePasscodeAllowed/usePasscodeAccessLookup、submit/logout(POST /api/passcode)
- PasscodeUnlockScreen:4 格圆环输入(inset ring label-1/label-3 + caret-blink 光标)、满 4 位自动提交、错误 shake(WAAPI 等价原 framer x 关键帧抖动)、成功 'Access granted' 600ms 后 replace 回来源、已解锁进入立即跳回
- layout 挂 PasscodeAccessProvider(服务端 cookies 读初始 access);新增 /api/passcode GET/POST(httpOnly cookie 持久化,解锁码经 PASSCODE_CODE 配置,默认 2026)与 /unlock/[scope] 页
- ScrambleReveal 支持 slot part({length,scramble,className,settled}):打散期显示占位字符、收尾替换为交互节点,1:1 原版语义
- 首页 about 段换 c9/c2 移植:锁定点击跳解锁页、解锁显示 TikTok、长按 500ms/右键 confirm 重锁;WorkSection 按 access 过滤,解锁后 TikTok 卡(tt01/tt02 素材)出现在首位
- CDP 全流程验证:锁定→解锁→持久化→重锁 循环 + 错码抖动清空 + 卡片数 10↔11
188 lines
6.4 KiB
TypeScript
188 lines
6.4 KiB
TypeScript
"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";
|
|
import { usePasscodeAccessLookup } from "@/components/dom/PasscodeAccess";
|
|
|
|
/**
|
|
* 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`).
|
|
* - Passcode-protected items are filtered exactly like the original
|
|
* `WORK_ITEMS.filter(t => !t.passcodeProtected || lookup(t.href))`: the
|
|
* TikTok entry only appears once /2026 is unlocked.
|
|
*/
|
|
|
|
// 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);
|
|
const lookup = usePasscodeAccessLookup();
|
|
|
|
// Original `f` — passcode-protected items stay hidden until unlocked.
|
|
const visibleItems = useMemo(
|
|
() => WORK_ITEMS.filter((item) => !item.passcodeProtected || lookup(item.href)),
|
|
[lookup]
|
|
);
|
|
|
|
// Register canvas layer defs for every item (locked ones simply have no
|
|
// target on screen; idempotent data write — 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 = visibleItems.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;
|
|
};
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- ratios-only effect; matches the original mount-time preload
|
|
}, [visibleItems]);
|
|
|
|
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` }}
|
|
>
|
|
{visibleItems.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>
|
|
);
|
|
}
|