Files
personal/components/dom/PasscodeRevealText.tsx
T
virtheart 285028c61d feat: 北极新一中文个人站 — MiSans 分片字体 + 全站内容国内化
- 字体: cn-font-split 分片 MiSans(4字重×~88片, unicode-range 按需加载)
  接入 --font-sans/--font-mono/--font-mono-2 栈尾; 修复 next/font 与
  Tailwind @theme 变量重名导致的死规则(--font-geist-mono/--font-departure-mono)
- 内容: 品牌名/首屏/关于/导航/页脚/滚动段/文章页 UI/解锁屏全部中文化;
  元数据 title 北极新一©2026, lang=zh-CN; 日期中文格式
- 彩蛋: 品牌标签 TikTok→小红书(保留 char-code 混淆与口令机制), /2026
  文案改为个人创作手记语境
- 页脚: 邮箱 + 抖音/微信/小红书; 有链接项点击新开主页, 全部支持悬停
  二维码卡片(正方形白衬+object-contain 防变形); 无链接项(微信)点击弹
  二维码浮层
- 移除原作者手写签名动画(AboutMedia)
- 构建: cn-font-split devDependency + onlyBuiltDependencies 允许列表
2026-09-02 17:18:22 +08:00

138 lines
4.1 KiB
TypeScript

"use client";
/**
* About-paragraph passcode easter egg — ported from 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 "小红书" 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 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(); // "小红书"
const BRAND_LEN = revealBrandLabelLength(); // 2
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("要重新锁定受保护的内容吗?再次查看需要输入口令。")
) {
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="受保护内容 — 输入口令后显示"
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} — 长按可重新锁定`}
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 = [
"我是北极新一,一名横跨设计与工程的全栈开发者:Web 前端与后端、Flutter 客户端、AI 应用开发都有实践,也从产品设计一路做到工程落地。工作之外,我常在 ",
{
length: BRAND_LEN,
scramble: allowed ? BRAND : passcodeLockedPlaceholderText(),
className: allowed ? undefined : PASSCODE_LOCKED_SCRAMBLE_CLASS,
settled: <RevealLabelButton />,
},
" 上记录与分享这些探索。",
];
return (
<ScrambleReveal
className={className}
parts={parts}
startDelayMs={startDelayMs}
letterDelayMs={letterDelayMs}
/>
);
}