feat: 移植首页 passcode 彩蛋(■■■■■■ → /unlock/2026 解锁 TikTok 品牌名与隐藏作品卡)
- 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
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* PasscodeAccessProvider + hooks — 1:1 port of the original module 4278
|
||||
* (d59f7a97fb1c563f.js): a module-level store (the original React context
|
||||
* store object) with a snapshot + listener set, window-event driven refresh,
|
||||
* and the same POST contract against /api/passcode.
|
||||
*/
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useSyncExternalStore,
|
||||
} from "react";
|
||||
import {
|
||||
PASSCODE_ACCESS_CHANGED_EVENT,
|
||||
PASSCODE_PROTECTED_PATHS,
|
||||
emptyPasscodeAccessState,
|
||||
isPasscodeProtectedPath,
|
||||
normalizePath,
|
||||
workHrefToPath,
|
||||
type PasscodeAccessState,
|
||||
} from "@/lib/passcode";
|
||||
|
||||
async function fetchAccess(): Promise<PasscodeAccessState> {
|
||||
const res = await fetch("/api/passcode", { cache: "no-store" });
|
||||
return res.ok ? ((res.json() as unknown) as Promise<PasscodeAccessState>) : emptyPasscodeAccessState();
|
||||
}
|
||||
|
||||
async function postAccess(body: {
|
||||
scope?: string;
|
||||
code?: string;
|
||||
action?: string;
|
||||
}): Promise<Response> {
|
||||
return fetch("/api/passcode", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
}
|
||||
|
||||
type Store = {
|
||||
snapshot: PasscodeAccessState;
|
||||
listeners: Set<() => void>;
|
||||
refresh: () => Promise<void>;
|
||||
};
|
||||
|
||||
const AccessContext = createContext<Store | null>(null);
|
||||
|
||||
function createStore(initialAccess: PasscodeAccessState): Store {
|
||||
return {
|
||||
snapshot: initialAccess,
|
||||
listeners: new Set(),
|
||||
async refresh() {
|
||||
const next = await fetchAccess();
|
||||
const keys = Object.keys(next);
|
||||
const same =
|
||||
keys.length === Object.keys(this.snapshot).length &&
|
||||
keys.every((k) => next[k] === this.snapshot[k]);
|
||||
if (same) return;
|
||||
this.snapshot = next;
|
||||
this.listeners.forEach((l) => l());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function PasscodeAccessProvider({
|
||||
initialAccess,
|
||||
children,
|
||||
}: {
|
||||
initialAccess: PasscodeAccessState;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const storeRef = useRef<Store | null>(null);
|
||||
if (!storeRef.current) storeRef.current = createStore(initialAccess);
|
||||
|
||||
useEffect(() => {
|
||||
const store = storeRef.current;
|
||||
if (!store) return;
|
||||
const onChange = () => void store.refresh();
|
||||
window.addEventListener(PASSCODE_ACCESS_CHANGED_EVENT, onChange);
|
||||
return () => window.removeEventListener(PASSCODE_ACCESS_CHANGED_EVENT, onChange);
|
||||
}, []);
|
||||
|
||||
return <AccessContext.Provider value={storeRef.current}>{children}</AccessContext.Provider>;
|
||||
}
|
||||
|
||||
/** notifyPasscodeAccessChanged (original `L`). */
|
||||
export function notifyPasscodeAccessChanged() {
|
||||
window.dispatchEvent(new CustomEvent(PASSCODE_ACCESS_CHANGED_EVENT));
|
||||
}
|
||||
|
||||
/** submitPasscodeUnlock (original `B`). */
|
||||
export function submitPasscodeUnlock(scope: string, code: string): Promise<Response> {
|
||||
return postAccess({ scope, code });
|
||||
}
|
||||
|
||||
/** logoutPasscodeAccess (original `j`). */
|
||||
export async function logoutPasscodeAccess(opts?: { reload?: boolean }): Promise<boolean> {
|
||||
const res = await postAccess({ action: "logout" });
|
||||
if (!(res as Response & { ok: boolean }).ok) return false;
|
||||
if (opts?.reload) window.location.reload();
|
||||
notifyPasscodeAccessChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
/** usePasscodeAccessLookup (original `F`): (href) => unlocked?. */
|
||||
export function usePasscodeAccessLookup() {
|
||||
const store = useContext(AccessContext);
|
||||
const fallback = useMemo(() => emptyPasscodeAccessState(), []);
|
||||
const snapshot = useSyncExternalStore(
|
||||
useCallback(
|
||||
(notify: () => void) => {
|
||||
if (!store) return () => {};
|
||||
store.listeners.add(notify);
|
||||
return () => store.listeners.delete(notify);
|
||||
},
|
||||
[store]
|
||||
),
|
||||
() => store?.snapshot ?? fallback,
|
||||
() => store?.snapshot ?? fallback
|
||||
);
|
||||
return useCallback(
|
||||
(href: string) => {
|
||||
const path = workHrefToPath(href) ?? href;
|
||||
// Original: `!S(e) || (s[e] ?? false)` — unprotected paths always pass.
|
||||
if (!isPasscodeProtectedPath(path)) return true;
|
||||
return snapshot[path] ?? false;
|
||||
},
|
||||
[snapshot]
|
||||
);
|
||||
}
|
||||
|
||||
/** usePasscodeAllowed (original `I`). */
|
||||
export function usePasscodeAllowed(path: string): boolean {
|
||||
return usePasscodeAccessLookup()(path);
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* About-paragraph passcode easter egg — 1:1 port of the original components
|
||||
* `c9` + `c2` (chunk 4d3f3b68dbbde33a.js):
|
||||
*
|
||||
* - Locked: the brand label slot scrambles as "■■■■■■" (each char wrapped,
|
||||
* PASSCODE_LOCKED_CHAR_CLASS); clicking navigates through the route
|
||||
* transition to /unlock/2026?return=%2F.
|
||||
* - Unlocked: the slot settles to the "TikTok" button span — long-press
|
||||
* (500ms) or context-menu re-locks (confirm + reload).
|
||||
* - The reveal sequence (ScrambleReveal) treats the label as a slot part, so
|
||||
* its 6 characters participate in the per-char scramble timing.
|
||||
*/
|
||||
import { useCallback, useRef } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import ScrambleReveal from "@/components/dom/ScrambleReveal";
|
||||
import {
|
||||
logoutPasscodeAccess,
|
||||
usePasscodeAllowed,
|
||||
} from "@/components/dom/PasscodeAccess";
|
||||
import {
|
||||
PASSCODE_LOCKED_CHAR_CLASS,
|
||||
PASSCODE_LOCKED_SCRAMBLE_CLASS,
|
||||
buildPasscodeUnlockHref,
|
||||
passcodeLockedPlaceholderText,
|
||||
primaryPasscodePath,
|
||||
revealBrandLabel,
|
||||
revealBrandLabelLength,
|
||||
} from "@/lib/passcode";
|
||||
|
||||
const SCOPE = primaryPasscodePath(); // "/2026"
|
||||
const BRAND = revealBrandLabel(); // "TikTok"
|
||||
const BRAND_LEN = revealBrandLabelLength(); // 6
|
||||
|
||||
function RevealLabelButton() {
|
||||
const allowed = usePasscodeAllowed(SCOPE);
|
||||
const router = useRouter();
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
const clearTimer = useCallback(() => {
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current);
|
||||
timerRef.current = null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const relock = useCallback(async () => {
|
||||
if (
|
||||
window.confirm("Lock protected content again? You will need the passcode to view it.")
|
||||
) {
|
||||
await logoutPasscodeAccess({ reload: true });
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (!allowed) {
|
||||
// TODO(route-system): go through useRouteTransitionController().startNavigation
|
||||
const go = () => {
|
||||
router.push(buildPasscodeUnlockHref(SCOPE, "/"));
|
||||
};
|
||||
return (
|
||||
<span
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label="Protected — enter passcode to reveal"
|
||||
className="inline-flex items-baseline gap-[0.12em] mx-[0.06em] align-baseline cursor-pointer select-text"
|
||||
onClick={go}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
go();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{passcodeLockedPlaceholderText()
|
||||
.split("")
|
||||
.map((ch, i) => (
|
||||
<span key={i} aria-hidden="true" className={PASSCODE_LOCKED_CHAR_CLASS}>
|
||||
{ch}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<span
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={`${BRAND} — long press to lock again`}
|
||||
className="inline mx-[0.06em] align-baseline cursor-default select-none"
|
||||
onPointerDown={() => {
|
||||
clearTimer();
|
||||
timerRef.current = setTimeout(() => void relock(), 500);
|
||||
}}
|
||||
onPointerUp={clearTimer}
|
||||
onPointerLeave={clearTimer}
|
||||
onPointerCancel={clearTimer}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
void relock();
|
||||
}}
|
||||
>
|
||||
{BRAND}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export default function PasscodeRevealText({
|
||||
className,
|
||||
startDelayMs = 300,
|
||||
letterDelayMs = 10,
|
||||
}: {
|
||||
className?: string;
|
||||
startDelayMs?: number;
|
||||
letterDelayMs?: number;
|
||||
}) {
|
||||
const allowed = usePasscodeAllowed(SCOPE);
|
||||
const parts = [
|
||||
"I'm Haoqi Wen, leading Design Engineering and AI exploration at ",
|
||||
{
|
||||
length: BRAND_LEN,
|
||||
scramble: allowed ? BRAND : passcodeLockedPlaceholderText(),
|
||||
className: allowed ? undefined : PASSCODE_LOCKED_SCRAMBLE_CLASS,
|
||||
settled: <RevealLabelButton />,
|
||||
},
|
||||
", engineering, and AI at scale. Outside work, I build design tools for team efficiency.",
|
||||
];
|
||||
return (
|
||||
<ScrambleReveal
|
||||
className={className}
|
||||
parts={parts}
|
||||
startDelayMs={startDelayMs}
|
||||
letterDelayMs={letterDelayMs}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* PasscodeUnlockScreen — 1:1 port of the original module 4278 component `O`
|
||||
* (d59f7a97fb1c563f.js):
|
||||
*
|
||||
* - A fixed z-1000 bg-b1 overlay; a hidden text input holds the code.
|
||||
* - PASSCODE.slotCount circles (inset ring: label-1 filled/current,
|
||||
* label-3 empty); the current slot shows a blinking caret.
|
||||
* - At slotCount characters the code auto-submits: failure shakes the row
|
||||
* (x keyframes 0,-10,10,-8,8,-4,4,0 over 0.5s) and clears; success flips
|
||||
* the hint to "Access granted" and navigates to the return path after
|
||||
* 600ms (router.replace, like the original startNavigation(...,{replace})).
|
||||
* - If the scope is already unlocked the screen immediately returns.
|
||||
* - Renders null when the scope is not passcode-protected.
|
||||
*/
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {
|
||||
PASSCODE,
|
||||
isPasscodeProtectedPath,
|
||||
normalizePath,
|
||||
sanitizePasscodeReturnTo,
|
||||
scopeToPath,
|
||||
} from "@/lib/passcode";
|
||||
import {
|
||||
notifyPasscodeAccessChanged,
|
||||
submitPasscodeUnlock,
|
||||
usePasscodeAllowed,
|
||||
} from "@/components/dom/PasscodeAccess";
|
||||
|
||||
/** Original framer `T.start({x:[0,-10,10,-8,8,-4,4,0], duration:.5, easeInOut})`. */
|
||||
function shake(el: HTMLElement | null): Promise<void> {
|
||||
if (!el || typeof el.animate !== "function") return Promise.resolve();
|
||||
const anim = el.animate(
|
||||
{
|
||||
transform: ["translateX(0)", "translateX(-10px)", "translateX(10px)", "translateX(-8px)", "translateX(8px)", "translateX(-4px)", "translateX(4px)", "translateX(0)"],
|
||||
},
|
||||
{ duration: 500, easing: "ease-in-out" }
|
||||
);
|
||||
return anim.finished.then(
|
||||
() => undefined,
|
||||
() => undefined
|
||||
);
|
||||
}
|
||||
|
||||
export function PasscodeUnlockScreen({
|
||||
scope,
|
||||
returnTo,
|
||||
}: {
|
||||
scope: string;
|
||||
returnTo?: string | null;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const path = scopeToPath(scope);
|
||||
const protectedScope = isPasscodeProtectedPath(path);
|
||||
const target = sanitizePasscodeReturnTo(returnTo) ?? path;
|
||||
const allowed = usePasscodeAllowed(path);
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
const rowRef = useRef<HTMLDivElement | null>(null);
|
||||
const [code, setCode] = useState("");
|
||||
const [status, setStatus] = useState<"idle" | "success">("idle");
|
||||
|
||||
const slotCount = PASSCODE.slotCount;
|
||||
const inputId = `passcode-${path}`;
|
||||
|
||||
useEffect(() => {
|
||||
if (!protectedScope) return;
|
||||
if (allowed) {
|
||||
router.replace(target);
|
||||
return;
|
||||
}
|
||||
inputRef.current?.focus();
|
||||
}, [target, protectedScope, allowed, router]);
|
||||
|
||||
if (!protectedScope) return null;
|
||||
|
||||
const onChange = (value: string) => {
|
||||
if (status === "success") return;
|
||||
const next = value.slice(0, slotCount);
|
||||
setCode(next);
|
||||
if (next.length === slotCount) {
|
||||
void (async () => {
|
||||
const res = await submitPasscodeUnlock(path, next);
|
||||
if (!res.ok) {
|
||||
await shake(rowRef.current);
|
||||
setCode("");
|
||||
inputRef.current?.focus();
|
||||
return;
|
||||
}
|
||||
notifyPasscodeAccessChanged();
|
||||
setStatus("success");
|
||||
window.setTimeout(() => {
|
||||
router.replace(target);
|
||||
}, 600);
|
||||
})();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main
|
||||
className="z-1000 fixed inset-0 flex justify-center items-center bg-b1"
|
||||
onClick={() => inputRef.current?.focus()}
|
||||
>
|
||||
<label className="sr-only" htmlFor={inputId}>
|
||||
Passcode for {path}
|
||||
</label>
|
||||
<input
|
||||
ref={inputRef}
|
||||
id={inputId}
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
value={code}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="absolute opacity-0 w-px h-px"
|
||||
/>
|
||||
<div className="relative" aria-hidden="true">
|
||||
<span
|
||||
className={`-top-10 left-1/2 absolute font-mono text-sm whitespace-nowrap -translate-x-1/2 select-none transition-colors ${
|
||||
status === "success" ? "text-l1" : "text-l3"
|
||||
}`}
|
||||
>
|
||||
{status === "success" ? "Access granted" : "Please enter passcode"}
|
||||
</span>
|
||||
<div ref={rowRef} className="flex gap-3">
|
||||
{Array.from({ length: slotCount }).map((_, i) => {
|
||||
const filled = i < code.length;
|
||||
const current = i === code.length;
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
className="flex justify-center items-center rounded-full w-12 h-12 font-mono tabular-nums text-l1 text-lg transition-shadow duration-300 ease-66"
|
||||
style={{
|
||||
boxShadow: `inset 0 0 0 4px ${
|
||||
filled || current ? "var(--label-1)" : "var(--label-3)"
|
||||
}`,
|
||||
}}
|
||||
>
|
||||
{filled ? (
|
||||
code[i]
|
||||
) : current ? (
|
||||
<span className="block bg-l1 w-px h-5 caret-blink" aria-hidden="true" />
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
/** Kept for parity with the original import surface (normalizePath helper). */
|
||||
export { normalizePath };
|
||||
@@ -4,7 +4,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
/**
|
||||
* 1:1 re-implementation of the original scramble-reveal text (chunk
|
||||
* 2689132c4e070b68.js component `d`):
|
||||
* 2689132c4e070b68.js module 71358 component `d`):
|
||||
*
|
||||
* - charset `ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*+-=?/<>[]{}` picked
|
||||
* randomly per render while a character is "scrambling"
|
||||
@@ -15,15 +15,62 @@ import { useEffect, useMemo, useRef, useState } from "react";
|
||||
* - refresh tick every 40ms; the whole text settles at
|
||||
* startDelayMs + (n-1)*letterDelayMs + 4*letterDelayMs
|
||||
* - starts once when the element enters the viewport (threshold 0.1)
|
||||
*
|
||||
* Parts accept strings or **slot objects** `{ length, scramble?, className?,
|
||||
* settled? }` (original slot parts): while scrambling, slot characters show
|
||||
* `scramble` (default: spaces) with the same per-char delays; once settled
|
||||
* the slot renders `settled` (a React node, e.g. the passcode button) in
|
||||
* place of the characters.
|
||||
*/
|
||||
|
||||
const CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*+-=?/<>[]{}";
|
||||
const COLORS_LIGHT = ["#c0fe04", "#607F02"];
|
||||
|
||||
const randomChar = () => CHARSET[Math.floor(Math.random() * CHARSET.length)];
|
||||
|
||||
export type ScrambleSlotPart = {
|
||||
/** Number of characters this slot occupies in the reveal sequence. */
|
||||
length: number;
|
||||
/** Placeholder characters shown while the slot is scrambling. */
|
||||
scramble?: string;
|
||||
/** Class for the slot wrapper span. */
|
||||
className?: string;
|
||||
/** React node rendered once the reveal has fully settled. */
|
||||
settled?: React.ReactNode;
|
||||
};
|
||||
|
||||
type Part = string | ScrambleSlotPart;
|
||||
|
||||
type NormalizedPart =
|
||||
| { kind: "text"; value: string }
|
||||
| {
|
||||
kind: "slot";
|
||||
length: number;
|
||||
scramble: string;
|
||||
settled?: React.ReactNode;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
function normalizeParts(parts: Part[] | undefined, text: string | undefined): NormalizedPart[] {
|
||||
return (parts ?? [text ?? ""]).map((p) => {
|
||||
if (typeof p === "string") return { kind: "text" as const, value: p };
|
||||
const length = Math.max(0, p.length);
|
||||
const scramble = (p.scramble ?? (length > 0 ? " ".repeat(length) : ""))
|
||||
.slice(0, length)
|
||||
.padEnd(length, " ");
|
||||
return {
|
||||
kind: "slot" as const,
|
||||
length,
|
||||
scramble,
|
||||
settled: p.settled,
|
||||
className: p.className,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
type Props = {
|
||||
text?: string;
|
||||
parts?: string[];
|
||||
parts?: Part[];
|
||||
className?: string;
|
||||
startDelayMs?: number;
|
||||
letterDelayMs?: number;
|
||||
@@ -41,8 +88,8 @@ export default function ScrambleReveal({
|
||||
scrambleColors = true,
|
||||
reverse = false,
|
||||
}: Props) {
|
||||
const strings = useMemo(
|
||||
() => (parts ? parts : [text ?? ""]),
|
||||
const normalized = useMemo(
|
||||
() => normalizeParts(parts, text),
|
||||
[parts, text]
|
||||
);
|
||||
const ref = useRef<HTMLSpanElement>(null);
|
||||
@@ -50,7 +97,10 @@ export default function ScrambleReveal({
|
||||
const [startedAt, setStartedAt] = useState<number | null>(null);
|
||||
const [elapsed, setElapsed] = useState(0);
|
||||
|
||||
const F = strings.join("").length;
|
||||
const F = normalized.reduce(
|
||||
(acc, p) => acc + (p.kind === "text" ? p.value.length : p.length),
|
||||
0
|
||||
);
|
||||
const phaseLen = 2 * letterDelayMs; // j
|
||||
const scrambleWindow = 2 * phaseLen; // D
|
||||
const total = startDelayMs + Math.max(0, F - 1) * letterDelayMs + scrambleWindow;
|
||||
@@ -94,53 +144,82 @@ export default function ScrambleReveal({
|
||||
if (settled || !entered) {
|
||||
return (
|
||||
<span ref={ref} className={className}>
|
||||
{strings.map((s, i) => (
|
||||
<span key={i}>{entered ? s : ""}</span>
|
||||
))}
|
||||
{normalized.map((p, i) =>
|
||||
p.kind === "text" ? (
|
||||
<span key={`text-${i}`}>{entered ? p.value : ""}</span>
|
||||
) : (
|
||||
<span key={`slot-${i}`} className={p.className}>
|
||||
{entered ? p.settled : null}
|
||||
</span>
|
||||
)
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
// recompute random chars on each elapsed tick
|
||||
let index = 0;
|
||||
const totalChars = strings.join("").length;
|
||||
return (
|
||||
<span ref={ref} className={className}>
|
||||
{strings.map((s, si) => (
|
||||
<span key={si}>
|
||||
{s.split("").map((ch, ci) => {
|
||||
const i = index++;
|
||||
// Original `reverse`: character delays run last→first.
|
||||
const order = reverse ? totalChars - 1 - i : i;
|
||||
if (ch === "\n") return <br key={`br-${si}-${ci}`} />;
|
||||
if (ch === " ") return <span key={`sp-${si}-${ci}`}> </span>;
|
||||
const n = order * letterDelayMs;
|
||||
if (V < n) {
|
||||
return (
|
||||
<span key={`c-${si}-${ci}`} style={{ opacity: 0 }}>
|
||||
{ch}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (V < n + scrambleWindow) {
|
||||
const phase = Math.min(
|
||||
1,
|
||||
Math.floor((V - n) / phaseLen)
|
||||
);
|
||||
const color = scrambleColors ? COLORS_LIGHT[phase] : undefined;
|
||||
return (
|
||||
<span
|
||||
key={`c-${si}-${ci}`}
|
||||
style={color ? { color } : undefined}
|
||||
>
|
||||
{randomChar()}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return <span key={`c-${si}-${ci}`}>{ch}</span>;
|
||||
})}
|
||||
</span>
|
||||
))}
|
||||
{normalized.map((p, pi) => {
|
||||
if (p.kind === "text") {
|
||||
return (
|
||||
<span key={`text-${pi}`}>
|
||||
{p.value.split("").map((ch, ci) => {
|
||||
const i = index++;
|
||||
// Original `reverse`: character delays run last→first.
|
||||
const order = reverse ? F - 1 - i : i;
|
||||
if (ch === "\n") return <br key={`br-${pi}-${ci}`} />;
|
||||
if (ch === " ") return <span key={`sp-${pi}-${ci}`}> </span>;
|
||||
const n = order * letterDelayMs;
|
||||
if (V < n) {
|
||||
return (
|
||||
<span key={`c-${pi}-${ci}`} style={{ opacity: 0 }}>
|
||||
{ch}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (V < n + scrambleWindow) {
|
||||
const phase = Math.min(1, Math.floor((V - n) / phaseLen));
|
||||
const color = scrambleColors ? COLORS_LIGHT[phase] : undefined;
|
||||
return (
|
||||
<span key={`c-${pi}-${ci}`} style={color ? { color } : undefined}>
|
||||
{randomChar()}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return <span key={`c-${pi}-${ci}`}>{ch}</span>;
|
||||
})}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span key={`slot-${pi}`} className={p.className}>
|
||||
{p.scramble.split("").map((ch, ci) => {
|
||||
const i = index++;
|
||||
const order = reverse ? F - 1 - i : i;
|
||||
const n = order * letterDelayMs;
|
||||
if (V < n) {
|
||||
return (
|
||||
<span key={`sc-${pi}-${ci}`} style={{ opacity: 0 }}>
|
||||
{ch}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (V < n + scrambleWindow) {
|
||||
const phase = Math.min(1, Math.floor((V - n) / phaseLen));
|
||||
const color = scrambleColors ? COLORS_LIGHT[phase] : undefined;
|
||||
return (
|
||||
<span key={`sc-${pi}-${ci}`} style={color ? { color } : undefined}>
|
||||
{randomChar()}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return <span key={`sc-${pi}-${ci}`}>{ch}</span>;
|
||||
})}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
setLayerDef,
|
||||
touchLayerRegistry,
|
||||
} from "@/lib/imageLayers";
|
||||
import { usePasscodeAccessLookup } from "@/components/dom/PasscodeAccess";
|
||||
|
||||
/**
|
||||
* Selected Work grid — 1:1 port of the original section `h` (chunk
|
||||
@@ -27,8 +28,9 @@ import {
|
||||
* 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.
|
||||
* - 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).
|
||||
@@ -38,9 +40,17 @@ 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();
|
||||
|
||||
// Register canvas layer defs for every visible item (idempotent data
|
||||
// write; the version bump happens once targets exist, in the effect).
|
||||
// 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, {
|
||||
@@ -74,7 +84,7 @@ export default function WorkSection() {
|
||||
if (ratioCache[imageUrl] !== ratio) ratioCache[imageUrl] = ratio;
|
||||
setRatios((prev) => (prev[imageUrl] === ratio ? prev : { ...prev, [imageUrl]: ratio }));
|
||||
};
|
||||
const images = WORK_ITEMS.map((item) => {
|
||||
const images = visibleItems.map((item) => {
|
||||
const img = new Image();
|
||||
img.decoding = "async";
|
||||
img.onload = () => update(item.imageUrl, img.naturalWidth, img.naturalHeight);
|
||||
@@ -88,7 +98,8 @@ export default function WorkSection() {
|
||||
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
|
||||
@@ -100,7 +111,7 @@ export default function WorkSection() {
|
||||
className="grid grid-cols-12 w-full"
|
||||
style={{ rowGap: `${colWidth}px` }}
|
||||
>
|
||||
{WORK_ITEMS.map((item) => (
|
||||
{visibleItems.map((item) => (
|
||||
<WorkCard key={item.href} item={item} ratio={ratios[item.imageUrl]} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user