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:
2026-09-01 19:21:52 +08:00
parent 71825606a4
commit 8ce5471c25
13 changed files with 864 additions and 72 deletions
+102
View File
@@ -0,0 +1,102 @@
/**
* Passcode constants + pure helpers — 1:1 port of the original modules
* 58156 (paths/href) and 28116 (brand label) from d59f7a97fb1c563f.js.
*
* The single passcode-protected scope is the TikTok work entry (/2026).
* The brand label itself is obfuscated in the original bundle as char codes
* minus one; we keep the same obfuscation.
*/
/** Original module 28116 `d` = "TikTok".charCodes + 1. */
const BRAND_CODES = [85, 106, 108, 85, 112, 108];
/** revealBrandLabel() — decodes to "TikTok". */
export function revealBrandLabel(): string {
let out = "";
for (let i = 0; i < BRAND_CODES.length; i += 1) {
out += String.fromCharCode(BRAND_CODES[i] - 1);
}
return out;
}
/** revealBrandLabelLength() — 6. */
export function revealBrandLabelLength(): number {
return BRAND_CODES.length;
}
/** passcodeLockedPlaceholderText() — "■■■■■■". */
export function passcodeLockedPlaceholderText(): string {
return "■■■■■■";
}
export const PASSCODE_LOCKED_CHAR_CLASS =
"inline-block min-w-[0.62em] text-center text-l1 tabular-nums select-text";
export const PASSCODE_LOCKED_SCRAMBLE_CLASS =
"inline-flex items-baseline gap-[0.12em] mx-[0.06em] select-text [&>span]:inline-block [&>span]:min-w-[0.62em] [&>span]:text-center [&>span]:tabular-nums";
/** Original module 58156 `y` — the unlock screen renders slotCount slots. */
export const PASSCODE = { slotCount: 4 } as const;
/** The work item hrefs guarded by the passcode (module 58156 `x`). */
export const PASSCODE_PROTECTED_PATHS: string[] = ["/2026"];
/** normalizePath (original `T`): trimmed path with a guaranteed leading "/". */
export function normalizePath(path: string): string {
const t = path.trim();
return t ? (t.startsWith("/") ? t : `/${t}`) : "/";
}
/** workHrefToPath (original module 83039 `v`): internal href only. */
export function workHrefToPath(href: string): string | null {
if (href.startsWith("http://") || href.startsWith("https://")) return null;
return normalizePath(href);
}
/**
* buildPasscodeUnlockHref (original `b`):
* "/2026", "/" → "/unlock/2026?return=%2F"
*/
export function buildPasscodeUnlockHref(scope: string, returnTo: string): string {
const safeReturn = sanitizePasscodeReturnTo(returnTo) ?? "/";
const seg = normalizePath(scope).slice(1) || "_";
return `/unlock/${encodeURIComponent(seg)}?return=${encodeURIComponent(safeReturn)}`;
}
/** scopeToPath (original `P`): decoded scope with a guaranteed leading "/". */
export function scopeToPath(scope: string): string {
const decoded = decodeURIComponent(scope);
return decoded.startsWith("/") ? decoded : `/${decoded}`;
}
/** isPasscodeProtectedPath (original `S`). */
export function isPasscodeProtectedPath(path: string): boolean {
const p = normalizePath(path);
return PASSCODE_PROTECTED_PATHS.includes(p);
}
/** emptyPasscodeAccessState (original `A`). */
export function emptyPasscodeAccessState(): Record<string, boolean> {
return Object.fromEntries(PASSCODE_PROTECTED_PATHS.map((p) => [p, false]));
}
/** primaryPasscodePath (original `w`): the first protected path. */
export function primaryPasscodePath(): string {
return PASSCODE_PROTECTED_PATHS[0] ?? "/2026";
}
/** sanitizePasscodeReturnTo (original `C`): same-origin relative path only. */
export function sanitizePasscodeReturnTo(returnTo?: string | null): string | null {
if (!returnTo) return null;
const t = returnTo.trim();
if (!t.startsWith("/") || t.startsWith("//")) return null;
return t;
}
/** Window event the access provider listens to (module 4278 `E`). */
export const PASSCODE_ACCESS_CHANGED_EVENT = "passcode-access-changed";
/** Shared cookie name for the access state (our API contract). */
export const PASSCODE_COOKIE_NAME = "hq-passcode-access";
export type PasscodeAccessState = Record<string, boolean>;