Files
personal/components/dom/SmoothScroller.tsx
T
virtheart 6b1f329231 feat: 移植 hyper-space 超空间区块(cursor.glb 条纹箭头 + 8vh 滚动叙事)与箭头全屏白模式
- HyperspaceModel.tsx:1:1 移植原站 cx——cursor.glb 合并几何、屏幕矩形追踪(12 帧缓存+滚动增量修正)、restScale 0.1→峰值 hypot(vw,vh)×1.64/radius 的吞噬缩放(damp 32/s)、shrink 折叠、条纹 shader(uStripeReveal 蓝底→黑底星空放射)、scaleSpinDegrees 180 收拢自旋、指针跟随高光
- HyperSpaceSection.tsx:8 视口高 + sticky,段位推进 seg0-primary/secondary(Innovate with purpose / human touch)→ seg1(进度环 + 四段主张)→ end(FUTURE-FIRST/ALWAYS);逐字符哈希延迟 stagger(hsstFadeIn/Out)
- arrowFullscreen.ts:原站 module 1111 进度 store(setDampedScaleT 阈值翻转订阅,header 0.5 阈值白模式、section 0.5 白模式同步)
- Header:箭头过阈值后整体转白(ARROW_FULLSCREEN_DOM_COLOR_TRANSITION)
- 修复:main 不再是滚动容器(原站 sticky 依赖内部滚动,我们的 Lenis 是窗口级,sticky 永不钉住导致末段文案不出现)
- scrollBus 增加 subscribeScroll/notifyScroll 供 DOM 侧响应式读取;useLightController 从 GlassModels 导出复用
- 验证:glError=0 无反馈环;段位推进/白模式触发与回落/区块顺序 全部 CDP 行为探针通过;build+tsc 通过
2026-09-01 17:38:56 +08:00

92 lines
3.1 KiB
TypeScript

'use client';
import { useEffect } from 'react';
import Lenis from 'lenis';
import { scrollBus, notifyScroll } from '@/lib/scrollBus';
import { scrollEnv } from '@/lib/scrollEnv';
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,
});
scrollEnv.setLenis(lenis);
lenis.scrollTo(0, { immediate: true });
lenis.on('scroll', (e: any) => {
scrollBus.current = e.scroll;
scrollBus.velocity = e.velocity;
scrollBus.progress = e.progress;
updateCameraProgress();
notifyScroll();
});
window.addEventListener('resize', updateCameraProgress);
updateCameraProgress();
function raf(time: number) {
lenis.raf(time);
requestAnimationFrame(raf);
}
requestAnimationFrame(raf);
return () => {
window.removeEventListener('resize', updateCameraProgress);
window.removeEventListener('pageshow', onPageShow);
scrollEnv.setLenis(null);
lenis.destroy();
};
}, []);
return null;
}