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 通过
This commit is contained in:
2026-09-01 17:38:56 +08:00
parent 903b79dd2b
commit 6b1f329231
11 changed files with 1354 additions and 5 deletions
+574
View File
@@ -0,0 +1,574 @@
"use client";
/**
* HyperSpaceSection — 1:1 port of the original DOM section `fh` + `fp` +
* `fm` + `fg` + `fv` + stagger text `fr` + ellipse-ring `c7` + SVG signature
* `fC` (chunk 4d3f3b68dbbde33a.js):
*
* - The section is 8 viewport heights tall (style height: 8·vh) with a
* sticky inner viewport (top-0, min-h 100vh). Scrolling through it maps
* to segment index floor(scrollTopIntoSection / segmentH) clamped 0..7
* where segmentH = sectionHeight/8.
* - Stages: segments 0-1 → seg0-primary ["Innovate","with","purpose"],
* 2-3 → seg0-secondary ["Innovate","with a","human touch"], 4-5 → seg1
* (ring + four claims), 6-7 → end ["FUTURE-FIRST","ALWAYS"].
* - The section element itself registers as the "hyper-space" image-layer
* target so the WebGL arrow (HyperspaceModel) tracks its screen rect.
* - Its text color follows the arrow-fullscreen progress store (white past
* 0.5) via ARROW_FULLSCREEN_DOM_COLOR_TRANSITION.
*/
import {
memo,
useEffect,
useId,
useLayoutEffect,
useMemo,
useRef,
useState,
} from "react";
import { useWindowSize } from "@/lib/useWindowSize";
import {
useArrowFullscreenPastThreshold,
ARROW_FULLSCREEN_DOM_COLOR_TRANSITION,
} from "@/lib/arrowFullscreen";
import { subscribeScroll, scrollBus } from "@/lib/scrollBus";
import { getLayerTarget } from "@/lib/imageLayers";
export const HYPER_SPACE_SECTION_ID = "hyper-space";
const STAGES = [
{ range: [0, 1], stage: "seg0-primary" },
{ range: [2, 3], stage: "seg0-secondary" },
{ range: [4, 5], stage: "seg1" },
{ range: [6, 7], stage: "end" },
] as const;
type Stage = (typeof STAGES)[number]["stage"];
const SEG0_PRIMARY = ["Innovate", "with", "purpose"];
const SEG0_SECONDARY = ["Innovate", "with a", "human touch"];
const END_LINES = ["FUTURE-FIRST", "ALWAYS"];
const clamp = (v: number, min: number, max: number) =>
Math.min(max, Math.max(min, v));
function stageForSegment(segment: number): Stage | null {
for (const { range, stage } of STAGES) {
const [lo, hi] = range;
if (segment >= lo && segment <= hi) return stage;
}
return null;
}
/** Segment height: sectionHeight/8, falling back to viewport height. */
function segmentHeight(sectionHeight: number | undefined, fallback: number) {
const h = sectionHeight ? sectionHeight / 8 : 0;
return h > 1 ? h : Math.max(1, fallback);
}
// --- Ellipse ring (original c4/c5/c6/c8) ----------------------------------
/** 7 ellipse phase slots (original c4 scratch array). */
const ringScratch = new Float32Array(7);
const RING_ELLIPSES = [0, 1, 2, 3, 4, 5, 6];
const RING_ENTER_SPAN = 300;
const RING_EXIT_SPAN = 345;
const RING_CYCLE_DIST = 300;
const RING_TOTAL_DIST = RING_ENTER_SPAN + RING_CYCLE_DIST + RING_EXIT_SPAN;
/** Semi-axis table for progress 0..300 (original c5): circle of radius 150. */
const RING_AXIS = (() => {
const table = new Float32Array(301);
for (let d = 0; d <= 300; d++) {
const t = d - 150;
const r2 = 22500 - t * t;
table[d] = r2 > 0 ? Math.sqrt(r2) : 0;
}
return table;
})();
function axisAt(d: number): number {
if (d <= 0 || d >= 300) return 0;
const i = Math.floor(d);
const frac = d - i;
return frac <= 0 ? RING_AXIS[i] : RING_AXIS[i] + (RING_AXIS[i + 1] - RING_AXIS[i]) * frac;
}
const Ring = memo(function Ring({
progress01,
size = 344,
className = "",
}: {
progress01: number;
size?: number;
className?: string;
}) {
const id = useId().replace(/:/g, "");
const refs = useRef<(SVGEllipseElement | null)[]>([]);
useLayoutEffect(() => {
const p = progress01 < 0 ? 0 : progress01 > 1 ? 1 : progress01;
let dist = p * RING_TOTAL_DIST;
let phase = 0; // 0 enter, 1 cycle, 2 exit
let d = dist;
if (dist > RING_ENTER_SPAN) {
if (dist <= RING_ENTER_SPAN + RING_CYCLE_DIST) {
phase = 1;
d = dist - RING_ENTER_SPAN;
} else {
phase = 2;
d = dist - RING_ENTER_SPAN - RING_CYCLE_DIST;
}
}
let completed = 0;
for (let i = 0; i < 7; i++) {
const el = refs.current[i];
if (!el) continue;
let dI = 0;
let visible = false;
if (phase === 0) {
const group = Math.floor(d / 50);
visible = d >= 50 * i;
if (visible) {
dI = d - (Math.min(group, 6) - i) * 50;
visible = dI > 0 && dI < 300;
}
} else if (phase === 1) {
dI = ((d + 50 * i) % RING_CYCLE_DIST + RING_CYCLE_DIST) % RING_CYCLE_DIST;
visible = dI > 0 && dI < 300;
} else {
dI = d + 50 * i;
visible = dI > 0 && dI < 300;
}
if (!visible) {
el.style.visibility = "hidden";
continue;
}
const rx = axisAt(dI);
if (rx <= 0) {
el.style.visibility = "hidden";
continue;
}
// Debounce repeat phase values (original c4 dedupe).
let dupe = false;
for (let k = 0; k < completed; k++) {
if (Math.abs(ringScratch[k] - dI) < 0.5) {
dupe = true;
break;
}
}
if (dupe) {
el.style.visibility = "hidden";
continue;
}
ringScratch[completed] = dI;
completed++;
el.style.visibility = "visible";
// Ellipse center rides down the ring box with distance (original cy
// 22 + l); rx full, ry 10% — a squashed orbit sweeping the box.
el.cx.baseVal.value = 172;
el.cy.baseVal.value = 22 + dI;
el.rx.baseVal.value = rx;
el.ry.baseVal.value = 0.1 * rx;
}
}, [progress01]);
return (
<div
className={`pointer-events-none absolute top-1/2 left-1/2 z-0 size-(--sar-size) -translate-x-1/2 -translate-y-1/2 overflow-hidden contain-[layout_paint_style] ${className}`}
style={{ "--sar-size": `${size}px` } as React.CSSProperties}
aria-hidden
>
<svg
width={size}
height={size}
viewBox="0 0 344 344"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className="size-full"
shapeRendering="geometricPrecision"
>
<defs>
<clipPath id={id}>
<polygon points="20,22 324,22 324,322 20,322" />
</clipPath>
</defs>
<g clipPath={`url(#${id})`}>
{RING_ELLIPSES.map((i) => (
<ellipse
key={i}
ref={(el) => {
refs.current[i] = el;
}}
visibility="hidden"
stroke="#C0FE04"
strokeOpacity={1}
strokeWidth={2}
vectorEffect="non-scaling-stroke"
/>
))}
</g>
</svg>
</div>
);
});
// --- Stagger text (original ft cache + fr) ---------------------------------
const staggerCache = new Map<string, number[]>();
/** Deterministic per-char delays (original ft: FNV-1a seeded LCG). */
function charDelays(
text: string,
count: number,
spreadMs: number,
salt?: string
): number[] {
const key = `${text}\u0000${spreadMs}\u0000${salt ?? ""}`;
const cached = staggerCache.get(key);
if (cached) return cached;
let h = 0x811c9dc5;
const seedText = salt ? `${text}\u0000${salt}` : text;
for (let i = 0; i < seedText.length; i++) {
h = Math.imul(h ^ seedText.charCodeAt(i), 0x1000193);
}
let state = h >>> 0;
const next = () => {
state = (state + 0x6d2b79f5) | 0;
state = Math.imul(state ^ (state >>> 15), 1 | state);
state = (state ^ (state + Math.imul(state ^ (state >>> 7), 61 | state))) | 0;
return ((state >>> 0) % 0x100000000) / 0x100000000;
};
const delays: number[] =
count <= 0
? []
: count === 1
? [0]
: Array.from({ length: count }, (_, i) => {
const linear = (i / (count - 1)) * spreadMs * 0.7;
const jitter = next() * spreadMs * 0.35;
return Math.min(spreadMs, linear + jitter);
});
staggerCache.set(key, delays);
return delays;
}
const StaggerText = memo(function StaggerText({
text,
className,
durationSec = 0.23,
staggerSpreadMs = 290,
groupDelayMs = 0,
play = true,
}: {
text: string;
className?: string;
durationSec?: number;
staggerSpreadMs?: number;
groupDelayMs?: number;
play?: boolean;
}) {
const chars = useMemo(() => Array.from(text), [text]);
const [inDelays, outDelays] = useMemo(
() => [
charDelays(text, chars.length, staggerSpreadMs),
charDelays(text, chars.length, staggerSpreadMs, "out"),
],
[chars.length, staggerSpreadMs, text]
);
const playedRef = useRef(false);
useEffect(() => {
if (play) playedRef.current = true;
}, [play]);
if (!(play || playedRef.current)) {
return (
<span className={className} style={{ opacity: 0 }}>
{text}
</span>
);
}
return (
<span className={className}>
{chars.map((ch, i) => {
const delay = ((play ? inDelays[i] : outDelays[i]) + groupDelayMs) / 1e3;
return (
<span
key={`${i}-${ch}`}
className="hsst-char"
style={{
opacity: play ? 0 : 1,
animationName: play ? "hsstFadeIn" : "hsstFadeOut",
animationDuration: `${durationSec}s`,
animationDelay: `${delay}s`,
animationTimingFunction: "linear",
animationFillMode: "forwards",
}}
>
{ch === " " ? "\u00A0" : ch}
</span>
);
})}
</span>
);
});
StaggerText.displayName = "HyperSpaceStaggerText";
// --- Stage scroll state (original fh's inline hook) --------------------------
function useHyperStage(sectionGeom: { top: number; height: number } | null) {
const [segmentIndex, setSegmentIndex] = useState(0);
const [stage, setStage] = useState<Stage | null>(() => stageForSegment(0));
const [seg0Reveal, setSeg0Reveal] = useState(false);
const [staggerGen, setStaggerGen] = useState(0);
const [stageProgress01, setStageProgress01] = useState(0);
const lastSegmentRef = useRef(0);
const stageRef = useRef<Stage | null>(stageForSegment(0));
const inSeg0Ref = useRef(false);
const wasAboveRef = useRef<boolean | null>(null);
const viewportHRef = useRef(0);
// Viewport height (original useWindowSize height).
useEffect(() => {
const update = () => {
viewportHRef.current = window.innerHeight;
};
update();
window.addEventListener("resize", update, { passive: true });
return () => window.removeEventListener("resize", update);
}, []);
useEffect(() => {
const compute = () => {
if (!sectionGeom) return;
const segH = segmentHeight(sectionGeom.height, viewportHRef.current);
const scrollTop = Math.max(0, scrollBus.current);
const intoSection = scrollTop - sectionGeom.top;
const seg = clamp(Math.floor(Math.max(0, intoSection) / segH), 0, 7);
if (seg !== lastSegmentRef.current) {
lastSegmentRef.current = seg;
setSegmentIndex(seg);
}
const nextStage = stageForSegment(seg);
if (nextStage !== stageRef.current) {
stageRef.current = nextStage;
setStage(nextStage);
}
if (!nextStage || (nextStage !== "seg0-primary" && nextStage !== "seg0-secondary")) {
// Leaving seg0 clears the reveal latch (original v.current = false).
if (inSeg0Ref.current) {
inSeg0Ref.current = false;
setSeg0Reveal(false);
}
wasAboveRef.current = null;
} else {
const above = intoSection >= -0.2 * segH;
const prev = wasAboveRef.current;
if (prev === null) {
wasAboveRef.current = above;
if (above) {
inSeg0Ref.current = true;
setSeg0Reveal(true);
setStaggerGen((g) => g + 1);
}
} else if (above !== prev) {
wasAboveRef.current = above;
if (above) {
inSeg0Ref.current = true;
setSeg0Reveal(true);
setStaggerGen((g) => g + 1);
} else {
inSeg0Ref.current = false;
setSeg0Reveal(false);
}
}
}
// Stage progress (original y): within-stage scroll position 0..1.
if (nextStage) {
const found = STAGES.find((s) => s.stage === nextStage);
if (found) {
const [lo, hi] = found.range;
const start = lo * segH;
const into = intoSection - start;
const span = (hi + 1) * segH - start;
setStageProgress01(clamp(into / Math.max(1, span), 0, 1));
}
} else {
setStageProgress01(0);
}
};
compute();
return subscribeScroll(compute);
}, [sectionGeom]);
return { segmentIndex, stage, seg0Reveal, staggerGen, stageProgress01 };
}
// --- Viewport-enter hook (original useHasEnteredViewport, minimal) ----------
function useHasEnteredViewport<T extends Element>({
once = false,
threshold = 0,
rootMargin = "0px",
}: {
once?: boolean;
threshold?: number;
rootMargin?: string;
}) {
const ref = useRef<T | null>(null);
const [hasEntered, setHasEntered] = useState(false);
useEffect(() => {
const el = ref.current;
if (!el) return;
const io = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setHasEntered(true);
if (once) io.disconnect();
} else if (!once) {
setHasEntered(false);
}
},
{ threshold, rootMargin }
);
io.observe(el);
return () => io.disconnect();
}, [once, threshold, rootMargin]);
return { ref, hasEntered };
}
// --- Stage renderers (original fm/fg/fv) -------------------------------------
function Seg0({
stage,
reveal,
staggerGen,
}: {
stage: "seg0-primary" | "seg0-secondary";
reveal: boolean;
staggerGen: number;
}) {
const isPrimary = stage === "seg0-primary";
const lines = isPrimary ? SEG0_PRIMARY : SEG0_SECONDARY;
return (
<div
className="flex flex-col justify-center items-center col-span-12 row-span-6 font-bold text-[7.2svw] lg:text-[6.8svw] uppercase leading-none"
style={{ fontVariationSettings: '"wdth" 120' }}
>
{lines.map((line, i) => (
<StaggerText
key={i === 0 ? `${staggerGen}-${isPrimary ? "primary" : "secondary"}-stable-0` : `${staggerGen}-${isPrimary ? "primary" : "secondary"}-${i}`}
text={line}
play={reveal}
groupDelayMs={100 * i}
/>
))}
</div>
);
}
function Seg1({ ringProgress01 }: { ringProgress01: number }) {
return (
<>
<Ring progress01={ringProgress01} />
<div className="col-span-8 lg:col-span-4 col-start-1 lg:col-start-7 row-start-2 p-2 font-medium text-[5.6svw] lg:text-3xl leading-tight">
<StaggerText text="Building tomorrow's" />
<br />
<StaggerText text="digital products." />
</div>
<div className="col-span-8 lg:col-span-4 col-start-5 lg:col-start-9 row-start-3 p-2 font-medium text-[5.6svw] lg:text-3xl leading-tight">
<StaggerText text="Independent by" />
<br />
<StaggerText text="design & engineering." />
</div>
<div className="col-span-8 lg:col-span-4 col-start-1 lg:col-start-2 row-start-4 p-2 font-medium text-[5.6svw] lg:text-3xl leading-tight">
<StaggerText text="Clarity first." />
<br />
<StaggerText text="Delight second." />
</div>
<div className="col-span-8 lg:col-span-4 col-start-5 lg:col-start-4 row-start-5 p-2 font-medium text-[5.6svw] lg:text-3xl leading-tight">
<StaggerText text="Ship in small loops." />
<br />
<StaggerText text="Aim for long arcs." />
</div>
</>
);
}
function EndStage() {
const { ref, hasEntered } = useHasEnteredViewport<HTMLDivElement>({ threshold: 0.35 });
return (
<div
ref={ref}
className="flex flex-col justify-center items-center col-span-12 row-span-6 font-bold text-[7.2svw] lg:text-[6.8svw] uppercase leading-none"
style={{ fontVariationSettings: '"wdth" 120' }}
>
{END_LINES.map((line, i) => (
<StaggerText key={line} text={line} play={hasEntered} groupDelayMs={100 * i} />
))}
</div>
);
}
// --- Section (original fh) ---------------------------------------------------
export default function HyperSpaceSection() {
const sectionRef = useRef<HTMLElement | null>(null);
const [geom, setGeom] = useState<{ top: number; height: number } | null>(null);
const pastThreshold = useArrowFullscreenPastThreshold();
const { height: viewportH } = useWindowSize();
// Live geometry (original: the shared section-map measures every section).
useEffect(() => {
const measure = () => {
const el = sectionRef.current;
if (el) setGeom({ top: el.offsetTop, height: el.offsetHeight });
};
measure();
window.addEventListener("resize", measure);
document.fonts?.ready?.then(measure).catch(() => {});
const t = window.setTimeout(measure, 500);
return () => {
window.removeEventListener("resize", measure);
window.clearTimeout(t);
};
}, []);
// The WebGL arrow (HyperspaceModel) tracks this section's screen rect via
// the shared layer-registry target record — getLayerTarget creates it on
// first access (the ref callback below fills .current). No texture def is
// registered: unlike the work/about layers, this target is rect-only and
// must NOT appear in the ImageLayers texture pipeline.
const { segmentIndex, stage, seg0Reveal, staggerGen, stageProgress01 } =
useHyperStage(geom);
return (
<section
id={HYPER_SPACE_SECTION_ID}
ref={(el) => {
sectionRef.current = el;
getLayerTarget("hyper-space").current = el;
void el;
}}
className={`relative ${ARROW_FULLSCREEN_DOM_COLOR_TRANSITION} ${
pastThreshold ? "text-white" : "text-l1"
}`}
style={{ height: `${8 * viewportH}px` }}
>
<div
className="top-0 sticky grid grid-cols-12 grid-rows-6 px-4 lg:px-14 py-18 lg:py-24 w-full"
style={{ minHeight: `${viewportH}px` }}
>
{stage === "seg0-primary" || stage === "seg0-secondary" ? (
<Seg0 stage={stage} reveal={seg0Reveal} staggerGen={staggerGen} />
) : stage === "seg1" ? (
<Seg1 ringProgress01={stageProgress01} />
) : stage === "end" ? (
<EndStage />
) : (
<div className="col-span-12 row-span-6" data-segment={segmentIndex} />
)}
</div>
</section>
);
}