feat: 移植原版背景/点阵遮罩/入场幕布,修复贴纸淡出与 cursor 颜色
- BackgroundFX: 1:1 移植原版 sz 多通道程序化背景(vignette→swirl→sine→shatter→bokeh→output,30% 分辨率 ping-pong,指针跟随、进度门控跳帧) - DotOverlay: 移植原版 s1 滚动点阵遮罩(renderOrder 10,uOpacity=sT(sP))——贴纸随滚动溶入页面底色的原版机制 - LoadingCurtain+LoadingOverlay: 移植原版入场流程(径向圆洞幕布 + MaskedDots 点阵化后处理 + 居中进度条,字体/重资产 5:5 计时轴) - sP 修正: f2 无 footer 时取 1(原版语义),相机 lerp(24,32,sP) 拉远恢复;视差 y 系数修正为 0.6 - 相机: ready 门控 intro dolly(lerp(A+8,A,customCubic),1.2s)+ 鼠标视差(lag .18/leave .05) - GlassModels: cursor 贴色修正为亮色主题 #009dff/#009dff;新增指针跟随高光控制器 ca() - 刷新回顶: scrollRestoration=manual + pageshow(bfcache) 双 rAF 重置 + lenis immediate - 新增 lib/pointer.ts、lib/loadingBus.ts、lib/customCubic.ts;loadingBus 打点: 模型/贴纸/about 图
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
useEffect,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
} from "react";
|
||||
import { loadingBus } from "@/lib/loadingBus";
|
||||
import LoadingCurtain from "@/components/canvas/LoadingCurtain";
|
||||
|
||||
/** Stable server snapshot (must be cached — a fresh object would loop). */
|
||||
const SERVER_SNAPSHOT = { progress: 0, ready: false };
|
||||
|
||||
function useHeavyLoad() {
|
||||
return useSyncExternalStore(
|
||||
loadingBus.subscribe,
|
||||
loadingBus.getSnapshot,
|
||||
() => SERVER_SNAPSHOT
|
||||
);
|
||||
}
|
||||
|
||||
function useFontsReady() {
|
||||
const [fontsReady, setFontsReady] = useState(false);
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const fonts = (document as any).fonts;
|
||||
if (!fonts) {
|
||||
setFontsReady(true);
|
||||
return;
|
||||
}
|
||||
fonts.ready.then(() => {
|
||||
if (!cancelled) setFontsReady(true);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
return fontsReady;
|
||||
}
|
||||
|
||||
const clamp = (v: number, min: number, max: number) =>
|
||||
Math.min(max, Math.max(min, v));
|
||||
|
||||
/**
|
||||
* Heavy-asset readiness for the camera intro dolly (original cV's `p`:
|
||||
* models + image layers ready — fonts are NOT part of this gate).
|
||||
*/
|
||||
export function useAppReady(): boolean {
|
||||
const heavy = useHeavyLoad();
|
||||
|
||||
// Safety valve: a stalled asset must never soft-lock the page.
|
||||
useEffect(() => {
|
||||
const safety = window.setTimeout(() => loadingBus.forceReady(), 6000);
|
||||
return () => window.clearTimeout(safety);
|
||||
}, []);
|
||||
|
||||
return heavy.ready;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry loading flow — port of the original route-transition controller
|
||||
* (module 34841) for the entry case on "/":
|
||||
*
|
||||
* 1. entry:wait — curtain fully closed (initialProgress 1), centered
|
||||
* 140px bar shows 50%·fontsReady + 50%·heavyLoadProgress.
|
||||
* 2. readyToLoadHeavy && fontsReady → hold 250ms → bar fades (250ms)
|
||||
* → 250ms later the curtain opens (0.8s customCubic radial hole +
|
||||
* dot mask) — reveal phase.
|
||||
* 3. Curtain reveal completes (+0.9s grace) → idle: unmount everything.
|
||||
*/
|
||||
export function LoadingOverlay() {
|
||||
const heavy = useHeavyLoad();
|
||||
const fontsReady = useFontsReady();
|
||||
|
||||
// wait → fading → reveal → (unmount when reveal completes)
|
||||
const [phase, setPhase] = useState<"wait" | "fading" | "reveal">("wait");
|
||||
const [mounted, setMounted] = useState(true);
|
||||
|
||||
const progress = Math.round(clamp(50 * +fontsReady + heavy.progress / 2, 0, 100));
|
||||
const assetsDone = heavy.ready && fontsReady;
|
||||
|
||||
useEffect(() => {
|
||||
if (!assetsDone || phase !== "wait") return;
|
||||
// Original: 250ms hold → fade the bar → 250ms later open the curtain.
|
||||
const t1 = window.setTimeout(() => setPhase("fading"), 250);
|
||||
return () => window.clearTimeout(t1);
|
||||
}, [assetsDone, phase]);
|
||||
|
||||
useEffect(() => {
|
||||
if (phase !== "fading") return;
|
||||
const t2 = window.setTimeout(() => setPhase("reveal"), 250);
|
||||
return () => window.clearTimeout(t2);
|
||||
}, [phase]);
|
||||
|
||||
if (!mounted) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<LoadingCurtain
|
||||
open={phase === "reveal"}
|
||||
duration={0.8}
|
||||
initialProgress={1}
|
||||
resetKey={`entry:${phase}`}
|
||||
onComplete={(open) => {
|
||||
if (open) {
|
||||
// Reveal finished — a beat later the curtain canvas unmounts.
|
||||
window.setTimeout(() => setMounted(false), 900);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{phase !== "reveal" && (
|
||||
<ProgressBar progress={progress} fading={phase === "fading"} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** Centered 140px progress bar (original `b`). */
|
||||
function ProgressBar({ progress, fading }: { progress: number; fading: boolean }) {
|
||||
const clamped = clamp(progress, 0, 100);
|
||||
return (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className={`left-1/2 top-1/2 z-40 fixed flex h-4 w-[140px] -translate-x-1/2 -translate-y-1/2 items-center justify-center pointer-events-none ${
|
||||
fading ? "opacity-0" : "opacity-100"
|
||||
}`}
|
||||
style={{ transition: "opacity 250ms cubic-bezier(0.25, 1, 0.5, 1)" }}
|
||||
>
|
||||
<div className="relative h-1.5 w-full overflow-hidden rounded-full bg-l3">
|
||||
<div
|
||||
className="absolute inset-y-0 left-0 rounded-full bg-l1"
|
||||
style={{
|
||||
width: `${clamped}%`,
|
||||
transition: "width 520ms cubic-bezier(0.22, 1, 0.36, 1)",
|
||||
willChange: "width",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LoadingOverlay;
|
||||
@@ -4,18 +4,70 @@ import { useEffect } from 'react';
|
||||
import Lenis from 'lenis';
|
||||
import { scrollBus } from '@/lib/scrollBus';
|
||||
|
||||
const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
|
||||
|
||||
/**
|
||||
* Lenis smooth scrolling + the original sP camera-progress computation
|
||||
* (banner/footer section geometry):
|
||||
* f1 = clamp((vh - bannerBottom) / max(1, vh - .25vh), 0, 1)
|
||||
* f2 = footer ? clamp(footerTop / vh, 0, 1) : 1
|
||||
* sP = f1 * f2
|
||||
* f2 measures the footer's distance ABOVE: it is 1 while the footer is
|
||||
* further than one viewport away and falls to 0 as the footer top reaches
|
||||
* the viewport top. Until the footer section exists we keep f2 at 1 —
|
||||
* matching the original's behavior for most of the page (sP → 1 after
|
||||
* ~0.75 viewport of scroll, which drives the dot-overlay fade and the
|
||||
* camera pull-back).
|
||||
*/
|
||||
export default function SmoothScroller() {
|
||||
useEffect(() => {
|
||||
// Refresh must always start at the top (original behavior: no anchor
|
||||
// → scroll to 0; also re-asserted on bfcache pageshow).
|
||||
if ('scrollRestoration' in window.history) {
|
||||
window.history.scrollRestoration = 'manual';
|
||||
}
|
||||
const resetScroll = () => {
|
||||
if (window.location.hash) return;
|
||||
window.scrollTo(0, 0);
|
||||
requestAnimationFrame(() => window.scrollTo(0, 0));
|
||||
};
|
||||
resetScroll();
|
||||
const onPageShow = (e: PageTransitionEvent) => {
|
||||
if (e.persisted) resetScroll();
|
||||
};
|
||||
window.addEventListener('pageshow', onPageShow);
|
||||
|
||||
const updateCameraProgress = () => {
|
||||
const vh = Math.max(1, window.innerHeight);
|
||||
const banner = document.querySelector('[data-section="banner"]');
|
||||
const footer = document.querySelector('[data-section="footer"]');
|
||||
if (!banner) {
|
||||
scrollBus.sP = 0;
|
||||
return;
|
||||
}
|
||||
const bannerRect = banner.getBoundingClientRect();
|
||||
const f1 = clamp01((vh - bannerRect.bottom) / Math.max(1, vh - 0.25 * vh));
|
||||
const f2 = footer
|
||||
? clamp01(footer.getBoundingClientRect().top / vh)
|
||||
: 1;
|
||||
scrollBus.sP = f1 * f2;
|
||||
};
|
||||
|
||||
const lenis = new Lenis({
|
||||
lerp: 0.1,
|
||||
smoothWheel: true,
|
||||
});
|
||||
|
||||
lenis.scrollTo(0, { immediate: true });
|
||||
|
||||
lenis.on('scroll', (e: any) => {
|
||||
scrollBus.current = e.scroll;
|
||||
scrollBus.velocity = e.velocity;
|
||||
scrollBus.progress = e.progress;
|
||||
updateCameraProgress();
|
||||
});
|
||||
window.addEventListener('resize', updateCameraProgress);
|
||||
updateCameraProgress();
|
||||
|
||||
function raf(time: number) {
|
||||
lenis.raf(time);
|
||||
@@ -25,6 +77,8 @@ export default function SmoothScroller() {
|
||||
requestAnimationFrame(raf);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('resize', updateCameraProgress);
|
||||
window.removeEventListener('pageshow', onPageShow);
|
||||
lenis.destroy();
|
||||
};
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user