feat: 路由转场+详情页+自定义滚动条+常显网格线+邮箱修复

- 新增 FullscreenTransitionProvider + RouteTransitionOverlay:
  cover(0.8s b1 遮罩 wipe) → push → reveal 状态机(原 73475/34841 移植),
  Work 卡片与详情页链接全部走 startNavigation(同路径点击回顶部)
- 新增 app/work/[slug] 详情页:content/workArticles.ts 从原站 6 个详情页
  1:1 提取(MDX 文章+Metadata+iframe 预览+Links),/2026 锁定时渲染解锁屏
- 新增 CustomScrollbar:桌面右缘 SVG 轨道+拖拽 thumb(188 轨道/min20)、
  点击跳转、2s 自动隐藏;移动端底部进度环回顶按钮(原 72443 移植)
- BackgroundGrid 重写为原版算法(3 行十字/12px 缺口/12 列内分数纵线,
  主页 loading 时隐藏其余时间常显);层叠改为原版结构:canvas z-auto
  最前 → grid z-20 → DOM 内容,移除各 section 的 z-30
- 修复 BGM:持久化开启时首次手势自动恢复播放(autoplay 策略被拒后
  pointerdown/keydown/touchstart 重试),enabled 闭包改用 ref
- 页脚邮箱改为 chenchun@virtheart.com
This commit is contained in:
2026-09-01 20:33:36 +08:00
parent 8ce5471c25
commit a844b26250
15 changed files with 1325 additions and 84 deletions
+131
View File
@@ -0,0 +1,131 @@
"use client";
/**
* FullscreenTransitionProvider — 1:1 port of the original module 73475
* (chunk d59f7a97fb1c563f.js): a context holding the navigation intent
* (targetHref), the cover/reveal phase flags and the scramble-lines gate.
*/
import {
createContext,
useCallback,
useContext,
useMemo,
useState,
type ReactNode,
} from "react";
type TransitionState = {
menuOpen: boolean;
setMenuOpen: (open: boolean) => void;
targetHref: string | null;
navigationReplace: boolean;
startNavigation: (href: string, opts?: { replace?: boolean }) => void;
clearNavigation: () => void;
readyToLoadHeavy: boolean;
setReadyToLoadHeavy: (ready: boolean) => void;
heavyLoadProgress: number;
setHeavyLoadProgress: (progress: number) => void;
allowScrambleLines: boolean;
setAllowScrambleLines: (allow: boolean) => void;
};
const FullscreenTransitionContext = createContext<TransitionState | null>(null);
export function useFullscreenTransitionController(): TransitionState {
const ctx = useContext(FullscreenTransitionContext);
if (!ctx)
throw new Error(
"useFullscreenTransitionController must be used within FullscreenTransitionProvider"
);
return ctx;
}
export function useRouteTransitionController(): {
targetHref: string | null;
navigationReplace: boolean;
startNavigation: (href: string, opts?: { replace?: boolean }) => void;
clearNavigation: () => void;
readyToLoadHeavy: boolean;
setReadyToLoadHeavy: (ready: boolean) => void;
heavyLoadProgress: number;
setHeavyLoadProgress: (progress: number) => void;
allowScrambleLines: boolean;
setAllowScrambleLines: (allow: boolean) => void;
} {
const ctx = useContext(FullscreenTransitionContext);
if (!ctx)
throw new Error(
"useRouteTransitionController must be used within FullscreenTransitionProvider"
);
return {
targetHref: ctx.targetHref,
navigationReplace: ctx.navigationReplace,
startNavigation: ctx.startNavigation,
clearNavigation: ctx.clearNavigation,
readyToLoadHeavy: ctx.readyToLoadHeavy,
setReadyToLoadHeavy: ctx.setReadyToLoadHeavy,
heavyLoadProgress: ctx.heavyLoadProgress,
setHeavyLoadProgress: ctx.setHeavyLoadProgress,
allowScrambleLines: ctx.allowScrambleLines,
setAllowScrambleLines: ctx.setAllowScrambleLines,
};
}
export function FullscreenTransitionProvider({
children,
}: {
children: ReactNode;
}) {
const [menuOpen, setMenuOpen] = useState(false);
const [target, setTarget] = useState<{ href: string; replace: boolean } | null>(
null
);
const [readyToLoadHeavy, setReadyToLoadHeavy] = useState(false);
const [heavyLoadProgress, setHeavyLoadProgress] = useState(0);
const [allowScrambleLines, setAllowScrambleLines] = useState(false);
const startNavigation = useCallback(
(href: string, opts?: { replace?: boolean }) => {
setReadyToLoadHeavy(false);
setHeavyLoadProgress(0);
setTarget((prev) => prev ?? { href, replace: opts?.replace ?? false });
},
[]
);
const clearNavigation = useCallback(() => {
setTarget(null);
}, []);
const value = useMemo(
() => ({
menuOpen,
setMenuOpen,
targetHref: target?.href ?? null,
navigationReplace: target?.replace ?? false,
startNavigation,
clearNavigation,
readyToLoadHeavy,
setReadyToLoadHeavy,
heavyLoadProgress,
setHeavyLoadProgress,
allowScrambleLines,
setAllowScrambleLines,
}),
[
menuOpen,
target,
startNavigation,
clearNavigation,
readyToLoadHeavy,
heavyLoadProgress,
allowScrambleLines,
]
);
return (
<FullscreenTransitionContext.Provider value={value}>
{children}
</FullscreenTransitionContext.Provider>
);
}
+35 -2
View File
@@ -4,8 +4,11 @@
* Scroll environment — module singleton mirroring the original
* `scrollEnv` (module 29680): holds the Lenis instance so header
* shortcuts (coords click → top, [T] top, [B] bottom, Work/Contact
* anchors) can scroll from anywhere. SmoothScroller registers the
* instance on mount.
* anchors) and the custom scrollbar can scroll from anywhere.
*
* Our clone scrolls the WINDOW (the original scrolls inside <main>);
* the container-el surface is kept for API parity — the container is
* document.documentElement.
*/
type LenisLike = {
@@ -16,6 +19,13 @@ type LenisLike = {
} | null;
let lenis: LenisLike = null;
let containerEl: HTMLElement | null = null;
const containerListeners = new Set<(el: HTMLElement | null) => void>();
function getContainer(): HTMLElement | null {
if (containerEl) return containerEl;
return typeof document === "undefined" ? null : document.documentElement;
}
export const scrollEnv = {
setLenis(instance: LenisLike) {
@@ -24,6 +34,29 @@ export const scrollEnv = {
getLenis() {
return lenis;
},
/** Original scrollEnv.setContainerEl (our scroller is the window). */
setContainerEl(el: HTMLElement | null) {
containerEl = el;
containerListeners.forEach((l) => l(el));
},
getContainerEl(): HTMLElement | null {
return getContainer();
},
subscribeContainerEl(listener: (el: HTMLElement | null) => void) {
containerListeners.add(listener);
return () => containerListeners.delete(listener);
},
/** Current scroll top in px (window scroller). */
getScrollTopPx(): number {
return window.scrollY || document.documentElement.scrollTop || 0;
},
/** Original lenisScrollTo: smoothed by Lenis unless immediate. */
lenisScrollTo(target: number | string | HTMLElement, opts?: { immediate?: boolean; lerp?: number }) {
const t = typeof target === "number" ? Math.max(0, target) : target;
if (lenis) lenis.scrollTo(t, { lerp: 0.1, immediate: !!opts?.immediate });
else if (typeof t === "number") window.scrollTo({ top: t, behavior: opts?.immediate ? "auto" : "smooth" });
else (t as HTMLElement).scrollIntoView({ behavior: opts?.immediate ? "auto" : "smooth" });
},
scrollToTop(behavior: "smooth" | "auto" = "smooth") {
if (lenis) lenis.scrollTo(0, { lerp: 0.1, immediate: behavior === "auto" });
else window.scrollTo({ top: 0, behavior });
+39 -1
View File
@@ -11,6 +11,10 @@ import { useEffect, useRef } from "react";
export function useBgm(enabled: boolean) {
const audioRef = useRef<HTMLAudioElement | null>(null);
const readyRef = useRef(false);
// Track the latest enabled state for the load-once effect (its closure
// captures the initial false otherwise).
const enabledRef = useRef(enabled);
enabledRef.current = enabled;
useEffect(() => {
let cancelled = false;
@@ -31,7 +35,7 @@ export function useBgm(enabled: boolean) {
audio.volume = 0.35;
audioRef.current = audio;
readyRef.current = true;
if (enabled) void audio.play().catch(() => {});
if (enabledRef.current) void audio.play().catch(() => {});
})
.catch((err) => {
if (!cancelled) console.warn("Failed to load BGM:", err);
@@ -55,4 +59,38 @@ export function useBgm(enabled: boolean) {
if (enabled) void audio.play().catch(() => {});
else audio.pause();
}, [enabled]);
// Autoplay-policy recovery: when sound is persisted ON, the mount-time
// play() is rejected (NotAllowedError — no user gesture yet) and the
// header would show SOUND[|] forever while staying silent. Retry on the
// first user gesture (click / key / touch), like the original which
// resumes music as soon as the user interacts.
const retriedRef = useRef(false);
useEffect(() => {
if (!enabled || retriedRef.current) return;
const tryPlay = () => {
const audio = audioRef.current;
if (!audio || !readyRef.current) return;
if (!audio.paused) {
retriedRef.current = true;
cleanup();
return;
}
audio
.play()
.then(() => {
retriedRef.current = true;
cleanup();
})
.catch(() => {});
};
const events = ["pointerdown", "keydown", "touchstart"] as const;
const cleanup = () => {
for (const ev of events)
window.removeEventListener(ev, tryPlay, { capture: true });
};
for (const ev of events)
window.addEventListener(ev, tryPlay, { capture: true });
return cleanup;
}, [enabled]);
}
+3 -3
View File
@@ -4,9 +4,9 @@
* via `WORK_ITEMS.filter(t => !t.passcodeProtected || lookup(t.href))` — the
* locked one reveals the brand label "TikTok"; see WorkSection).
*
* Internal hrefs (/reunimos, /inspire_mono, …) are detail-page routes that
* do not exist in this clone yet; WorkSection renders them as inert links
* until the route system is ported.
* Internal detail routes render app/work/[slug]/page.tsx (content extracted
* 1:1 from the original pages); clicks go through the cover/reveal
* transition (startNavigation).
*/
import { revealBrandLabel } from "@/lib/passcode";