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
+33
View File
@@ -68,3 +68,36 @@ html::-webkit-scrollbar, body::-webkit-scrollbar {
opacity: 1;
}
}
/* Hyper-space stagger text (original hsst-char / hsstFadeIn / hsstFadeOut). */
.hsst-char {
display: inline-block;
}
@keyframes hsstFadeIn {
0% {
opacity: 0;
}
32% {
opacity: 0.22;
}
62% {
opacity: 0.55;
}
to {
opacity: 1;
}
}
@keyframes hsstFadeOut {
0% {
opacity: 1;
}
38% {
opacity: 0.62;
}
72% {
opacity: 0.28;
}
to {
opacity: 0;
}
}
+11 -1
View File
@@ -2,6 +2,7 @@ import ScrambleReveal from "@/components/dom/ScrambleReveal";
import AboutMedia from "@/components/dom/AboutMedia";
import FooterSection from "@/components/dom/FooterSection";
import WorkSection from "@/components/dom/WorkSection";
import HyperSpaceSection from "@/components/dom/HyperSpaceSection";
/**
* Page content matching the original DOM (haoqi_body.html):
@@ -12,7 +13,11 @@ const PASSCODE_LENGTH = 6;
export default function Home() {
return (
<main className="w-full h-full overflow-y-auto overscroll-contain no-scrollbar">
// NOTE: the original scrolls INSIDE <main> (its Lenis wraps the main
// container), which is what lets its position:sticky children pin. Our
// Lenis is window-level, so main must NOT be a scroll container —
// otherwise sticky (hyper-space section) never pins.
<main className="w-full">
<div>
{/* Banner Section */}
<div
@@ -106,6 +111,11 @@ export default function Home() {
{/* Selected Work grid (id="selected-work", WebGL image layers) */}
<WorkSection />
{/* Hyper-space scroll section (id="hyper-space"): the WebGL
hyperspace arrow (cursor.glb stripes) tracks this section's
screen rect and engulfs the viewport mid-scroll. */}
<HyperSpaceSection />
{/* Contact / Footer Section (#contact, data-section="footer") */}
<FooterSection />
</div>
+1 -1
View File
@@ -307,7 +307,7 @@ function useFloatOffset(enabled: boolean) {
* pointer (raycast onto the z=0 plane) with exponential damping (6/s), and
* falling back to the initial azimuth when the pointer leaves.
*/
function useLightController() {
export function useLightController() {
return useMemo(() => {
const initialAzimuth = Math.atan2(9, 4);
const radius = Math.hypot(4, 9);
+6
View File
@@ -6,6 +6,7 @@ import { PerspectiveCamera } from "@react-three/drei";
import { StickerDrop, StickerCamera } from "@/components/canvas/StickerDrop";
import { HelloModel, CursorStar, FooterModel } from "@/components/canvas/GlassModels";
import { HyperspaceModel } from "@/components/canvas/HyperspaceModel";
import ImageLayers from "@/components/canvas/ImageLayers";
import BackgroundFX from "@/components/canvas/BackgroundFX";
import DotOverlay from "@/components/canvas/DotOverlay";
@@ -156,6 +157,11 @@ export function HeroScene() {
<CursorStar isMobile={isMobile} />
<FooterModel />
{/* Hyper-space arrow (original cC/cx): cursor.glb stripes that scale
up to engulf the viewport while the hyper-space section scrolls
through; reports progress to the arrow-fullscreen store. */}
<HyperspaceModel />
{/* Post FX (original cG): lens-flare star streaks + pointer-driven
fluid refraction + lime dot-trail indicator. */}
<PostFX />
+605
View File
@@ -0,0 +1,605 @@
"use client";
/**
* HyperspaceModel — 1:1 port of the original `cx` (chunk
* 4d3f3b68dbbde33a.js): the cursor.glb arrow whose scale and stripe shader
* build the "hyper-space" scroll sequence. The original caller mounts it as
* `<cC targetRef={hyperSpaceRef} getTargetRect={() => rectMap("hyper-space")}
* scaleSpinDegrees={180} />` — here the DOM target comes from the shared
* layer registry ("hyper-space" key, set by HyperSpaceSection).
*
* Behavior (all from the original useFrame, priority -2):
* - DOM rect tracking: cached for 11 frames, re-measured every 12th frame
* or on any scroll delta (rect shifted by the scroll difference).
* - Visibility: rect.top < viewportBottom + max(2·refMarginPx, 480)
* (approach) and rect.bottom > -(6·refMarginPx) unless fully below the
* leave cap min(0.35vh, restRadius·cssH/vpH·0.45); outside → hidden +
* store reset.
* - Scale: rest 0.1 → peak lerp by reveal = smoothstep01(clamp((vpMid -
* (rect.top + margin))/vpH)); beforeShrink holds the reveal scale,
* shrinking folds back to rest by shrinkT; damped at 32/s.
* - Peak = hypot(vpW, vpH)·autoPeakPadding(1.64)/radius (hyperspace engulf).
* - Stripe reveal uniform + arrowFullscreenProgressStore.setDampedScaleT
* share the same normalized t.
* - Spin: rotY = 180°·clamp(eR/0.4) while approaching; during shrink
* 180°·(1 + clamp((shrinkT-0.6)/0.4)).
* - Shader iTime: 2·clamp01((vpBottom - rect.top)/(vpBottom + rect.h)) —
* the star-field travel time (uScrollDuration = 2).
*/
import { useEffect, useLayoutEffect, useMemo, useRef } from "react";
import * as THREE from "three";
import { useFrame, useLoader, useThree } from "@react-three/fiber";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
import { mergeGeometries } from "three/examples/jsm/utils/BufferGeometryUtils.js";
import { usePointer } from "@/lib/pointer";
import { useIsMobile } from "@/lib/useIsMobile";
import { useLightController } from "@/components/canvas/GlassModels";
import {
arrowFullscreenProgressStore,
} from "@/lib/arrowFullscreen";
import { getLayerTarget } from "@/lib/imageLayers";
import { scrollBus } from "@/lib/scrollBus";
const ACCENT = "#009dff";
const STRIPE_A = "#009dff";
const STRIPE_B = "#64c3ff";
const REST_SCALE = 0.1;
const SCALE_SMOOTHING = 32;
const AUTO_PEAK_PADDING = 1.64;
const REF_MARGIN_PX = 120;
const SCALE_SPIN_DEGREES = 180; // original caller prop
const TILT: [number, number, number] = [0, 0, 45]; // rotationAxisTilt (cy)
const MODEL_POSITION: [number, number, number] = [0, 0, 0];
const LIGHT_Z = 0.5;
const rad = THREE.MathUtils.degToRad;
const SPIN_RADIANS = rad(SCALE_SPIN_DEGREES);
const TILT_RAD: [number, number, number] = [rad(TILT[0]), rad(TILT[1]), rad(TILT[2])];
const NEG_TILT_RAD: [number, number, number] = [-TILT_RAD[0], -TILT_RAD[1], -TILT_RAD[2]];
const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
function centerGeometry(geometry: THREE.BufferGeometry) {
geometry.computeBoundingBox();
const bb = geometry.boundingBox;
if (!bb) return;
const cx = (bb.min.x + bb.max.x) / 2;
const cy = (bb.min.y + bb.max.y) / 2;
const cz = (bb.min.z + bb.max.z) / 2;
if (Math.abs(cx) + Math.abs(cy) + Math.abs(cz) < 1e-8) return;
geometry.translate(-cx, -cy, -cz);
geometry.computeBoundingSphere();
}
const vert = /* glsl */ `
varying vec3 vWorldNormal;
varying vec3 vEyeVector;
void main() {
vec4 worldPos = modelMatrix * vec4(position, 1.0);
vec4 mvPosition = viewMatrix * worldPos;
gl_Position = projectionMatrix * mvPosition;
vWorldNormal = normalize(modelMatrix * vec4(normal, 0.0)).xyz;
vEyeVector = normalize(worldPos.xyz - cameraPosition);
}
`;
const frag = /* glsl */ `
uniform vec3 iResolution;
uniform float iTime;
uniform float uScrollDuration;
uniform vec3 uAccentColor;
uniform vec3 uStripeColorA;
uniform vec3 uStripeColorB;
uniform float uStripeReveal;
uniform float uOpacity;
uniform vec3 uLight;
uniform float uShininess;
uniform float uDiffuseness;
uniform float uSpecularStrength;
uniform float uFresnelPower;
uniform float uFresnelStrength;
uniform vec3 uFresnelSideDir;
varying vec3 vWorldNormal;
varying vec3 vEyeVector;
float hash21(vec2 p) {
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
}
vec3 rgb2hsv(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
vec3 sampleHyperspace(vec2 fragCoord) {
vec2 R = iResolution.xy;
float baseScale = max(1.0, min(R.x, R.y));
vec2 u = (fragCoord * 2.0 - R) / baseScale;
float dur = max(uScrollDuration, 1e-4);
float time = clamp(iTime, 0.0, dur);
float t = clamp(time / dur, 0.0, 1.0);
const float cellDensity = 100.0;
vec2 polar = vec2(atan(u.y, u.x) / 3.0, length(u));
float angleCoord = (6.0 - polar.x) * cellDensity;
float angleId = floor(angleCoord) + 0.5;
float angleCell = abs(fract(angleCoord) - 0.5);
float radialCoord = (6.0 - polar.y) * cellDensity;
vec2 q = vec2(angleId, radialCoord);
float travel = smoothstep(0.0, 1.0, t);
float keepProbability = mix(0.18, 1.0, travel);
float scrollSpeed = mix(0.7, 3.6, travel);
float trailLength = mix(2.7, 0.975, travel);
float raySeq = fract((angleId + 0.5) * 0.61803398875);
float keepEdge = 0.025;
float keepMask = 1.0 - smoothstep(keepProbability - keepEdge, keepProbability + keepEdge, raySeq);
float phaseBase = (q.y * 0.02 + q.x * 0.4) * fract(q.x * 0.61);
vec4 spark = max(
1.0 - fract(vec4(7.0, 6.0, 4.0, 0.0) * 0.02 + phaseBase + time * scrollSpeed) * trailLength,
0.0
);
float channelMix = max(max(spark.r, spark.g), spark.b);
float edge = max(fwidth(channelMix) * 1.5, 2.0 / max(iResolution.y, 1.0));
float star = smoothstep(0.12 - edge, 0.12 + edge, channelMix);
const float starThinness = 0.13;
float thinEdge = max(fwidth(angleCell) * 1.5, 0.002);
float thinMask = 1.0 - smoothstep(starThinness - thinEdge, starThinness + thinEdge, angleCell);
star *= thinMask * keepMask;
float radialBoost = pow(smoothstep(0.1, 1.0, polar.y), 1.25);
float intensity = mix(0.0, 6.5, t * 1.2);
float stripeBlend = hash21(vec2(angleId, 19.713));
vec3 stripeRgb = mix(uStripeColorA, uStripeColorB, stripeBlend);
vec3 hsvA = rgb2hsv(max(uStripeColorA, vec3(1e-5)));
vec3 hsvB = rgb2hsv(max(uStripeColorB, vec3(1e-5)));
float dh = abs(hsvA.x - hsvB.x);
dh = min(dh, 1.0 - dh);
float hueBand = clamp(dh * 1.25 + 0.04, 0.07, 0.24);
vec3 hsv = rgb2hsv(max(stripeRgb, vec3(1e-5)));
float idHash = hash21(vec2(angleId, 6.18));
float idHash2 = hash21(vec2(angleId, 91.7));
float scrollPhase = time * scrollSpeed;
float hueAnim =
sin(scrollPhase * 0.52 + angleId * 0.29 + idHash * 6.2831853) * (hueBand * 0.85);
float hueStripe = (idHash - 0.5) * hueBand * 2.0;
hsv.x = fract(hsv.x + hueStripe + hueAnim);
hsv.y = clamp(hsv.y * mix(0.96, 1.06, idHash2), 0.0, 1.0);
hsv.z = clamp(hsv.z * mix(0.97, 1.05, idHash), 0.0, 1.0);
vec3 sparkColor = hsv2rgb(hsv);
float pulse = mix(0.78, 1.0, smoothstep(0.14, 0.5, channelMix));
sparkColor *= pulse;
return intensity * radialBoost * sparkColor * star;
}
float fresnel(vec3 eyeDir, vec3 normal, float power) {
float fresnelFactor = abs(dot(eyeDir, normal));
float inversefresnelFactor = 1.0 - fresnelFactor;
return pow(inversefresnelFactor, power);
}
float specular(vec3 light, vec3 normal, vec3 eyeDir, float shininess, float diffuseness) {
vec3 lightVector = normalize(-light);
vec3 halfVector = normalize(eyeDir + lightVector);
float NdotL = dot(normal, lightVector);
float NdotH = abs(dot(normal, halfVector));
float kDiffuse = max(0.0, NdotL);
float kSpecular = pow(NdotH, shininess);
return kSpecular + kDiffuse * diffuseness;
}
void main() {
vec2 fragCoord = gl_FragCoord.xy;
vec3 stripes = sampleHyperspace(fragCoord);
float reveal = clamp(uStripeReveal, 0.0, 1.0);
float stripeLuma = dot(stripes, vec3(0.299, 0.587, 0.114));
// 蓝→黑:全屏前压到纯黑底;满 reveal 不再填 accent,间隙为 #000
float darken = smoothstep(0.0, 0.88, reveal);
vec3 darkBase = mix(uAccentColor, vec3(0.0), darken);
float gapMask = (1.0 - smoothstep(0.035, 0.12, stripeLuma)) * reveal;
float crackGuard = 1.0 - smoothstep(0.68, 0.94, reveal);
vec3 rgb = darkBase + stripes * reveal + uAccentColor * gapMask * 0.07 * crackGuard;
vec3 normal = normalize(vWorldNormal);
// 背面须翻转法线,否则高光/Fresnel 在背对相机时会错且易像「穿模」
if (!gl_FrontFacing) {
normal = -normal;
}
vec3 eyeDir = normalize(vEyeVector);
float glossMask = mix(1.0, smoothstep(0.1, 0.48, stripeLuma), reveal);
float specularLight = specular(uLight, normal, eyeDir, uShininess, uDiffuseness);
rgb += specularLight * uSpecularStrength * glossMask;
float f = fresnel(eyeDir, normal, uFresnelPower);
float sideDot = dot(normal, normalize(uFresnelSideDir));
float sideMask = smoothstep(-0.5, 0.5, sideDot);
rgb += f * sideMask * vec3(uFresnelStrength) * glossMask;
float alpha = clamp(uOpacity, 0.0, 1.0);
if (alpha <= 0.0001) discard;
gl_FragColor = vec4(rgb, alpha);
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
`;
type TrackedRect = {
left: number;
top: number;
width: number;
height: number;
right: number;
bottom: number;
};
export function HyperspaceModel() {
const gltf = useLoader(GLTFLoader, "/model/cursor.glb");
const groupRef = useRef<THREE.Group>(null!);
const spinRef = useRef<THREE.Group>(null!);
const meshRef = useRef<THREE.Mesh>(null!);
const materialRef = useRef<THREE.ShaderMaterial>(null!);
const { size, gl, camera } = useThree();
const { uv, insideRef } = usePointer();
const isMobile = useIsMobile();
const mergedGeometry = useMemo(() => {
gltf.scene.updateMatrixWorld(true);
const geometries: THREE.BufferGeometry[] = [];
gltf.scene.traverse((obj: THREE.Object3D) => {
if ((obj as THREE.Mesh).isMesh && (obj as THREE.Mesh).geometry) {
const geo = (obj as THREE.Mesh).geometry.clone();
geo.applyMatrix4((obj as THREE.Mesh).matrixWorld);
geometries.push(geo);
}
});
if (geometries.length === 0) return null;
let merged: THREE.BufferGeometry | null = null;
try {
merged = mergeGeometries(geometries, false);
} catch {
merged = null;
}
if (!merged && geometries.length >= 1) merged = geometries[0];
if (!merged) return null;
centerGeometry(merged);
return merged;
}, [gltf]);
useEffect(() => {
return () => {
mergedGeometry?.dispose();
};
}, [mergedGeometry]);
const uniforms = useMemo(
() => ({
iResolution: { value: new THREE.Vector3(1, 1, 1) },
iTime: { value: 0 },
uScrollDuration: { value: 2 },
uOpacity: { value: 1 },
uAccentColor: { value: new THREE.Color(ACCENT) },
uStripeColorA: { value: new THREE.Color(STRIPE_A) },
uStripeColorB: { value: new THREE.Color(STRIPE_B) },
uStripeReveal: { value: 0 },
uLight: { value: new THREE.Vector3(4, 9, LIGHT_Z) },
uShininess: { value: 40 },
uDiffuseness: { value: 0.1 },
uSpecularStrength: { value: 1.2 },
uFresnelPower: { value: 6 },
uFresnelStrength: { value: 1 },
uFresnelSideDir: { value: new THREE.Vector3(-1, 0.3, 1) },
}),
[]
);
// Cached canvas layout (original L) + rect cache (original G/H/_/j).
const layoutRef = useRef<{ cssH: number; topY: number; bottomY: number } | null>(
null
);
const rectCacheRef = useRef<TrackedRect | null>(null);
const frameCountRef = useRef(0);
const lastScrollRef = useRef({ top: 0, left: 0 });
const layoutSigRef = useRef("");
const scaleRef = useRef(REST_SCALE);
const dampInitRef = useRef(false);
const lightCtl = useLightController();
const worldPos = useMemo(() => new THREE.Vector3(), []);
useEffect(() => {
const invalidate = () => {
layoutRef.current = null;
rectCacheRef.current = null;
layoutSigRef.current = "";
};
window.addEventListener("resize", invalidate);
window.addEventListener("orientationchange", invalidate);
window.visualViewport?.addEventListener("resize", invalidate);
const ro =
typeof ResizeObserver !== "undefined"
? new ResizeObserver(invalidate)
: null;
if (ro) {
ro.observe(gl.domElement);
if (gl.domElement.parentElement) ro.observe(gl.domElement.parentElement);
}
return () => {
window.removeEventListener("resize", invalidate);
window.removeEventListener("orientationchange", invalidate);
window.visualViewport?.removeEventListener("resize", invalidate);
ro?.disconnect();
arrowFullscreenProgressStore.reset();
};
}, [gl]);
const targetRef = getLayerTarget("hyper-space");
useFrame((state, rawDelta) => {
const delta = Math.min(rawDelta, 0.1);
const group = groupRef.current;
const mesh = meshRef.current;
const u = materialRef.current?.uniforms;
if (!group || !mesh || !mergedGeometry || !u) return;
const [px, py, pz] = MODEL_POSITION;
const pixelRatio = Math.max(1, gl.getPixelRatio());
const canvasRect = gl.domElement.getBoundingClientRect();
const vv = window.visualViewport ?? null;
const sig = [
Math.round(canvasRect.top),
Math.round(canvasRect.left),
Math.round(canvasRect.width),
Math.round(canvasRect.height),
pixelRatio,
Math.round(size.width),
Math.round(size.height),
vv ? Math.round(100 * vv.height) / 100 : -1,
vv ? Math.round(100 * vv.offsetTop) / 100 : -1,
vv ? Math.round(1e3 * vv.scale) / 1e3 : -1,
].join("|");
if (sig !== layoutSigRef.current) {
layoutSigRef.current = sig;
layoutRef.current = null;
rectCacheRef.current = null;
}
if (!layoutRef.current) {
const cssH =
canvasRect.height > 0 ? canvasRect.height : Math.max(1, size.height);
const topY = canvasRect.height > 0 ? canvasRect.top : 0;
layoutRef.current = {
cssH,
topY,
bottomY: canvasRect.height > 0 ? canvasRect.bottom : topY + cssH,
};
}
const { cssH, topY, bottomY } = layoutRef.current;
const vw = Math.max(1, size.width);
// --- DOM rect tracking (original: 11-frame cache + scroll-delta shift) ---
const el = targetRef.current;
const scrollTop = Math.max(0, scrollBus.current);
let rect: TrackedRect | null = null;
if (el) {
const n = frameCountRef.current++;
if (rectCacheRef.current && n % 12 !== 0) {
const dTop = scrollTop - lastScrollRef.current.top;
const dLeft = scrollTop - lastScrollRef.current.left;
lastScrollRef.current = { top: scrollTop, left: scrollTop };
if (dTop !== 0 || dLeft !== 0) {
const r = rectCacheRef.current;
r.top -= dTop;
r.bottom -= dTop;
r.left -= dLeft;
r.right -= dLeft;
}
} else {
const b = el.getBoundingClientRect();
rectCacheRef.current = {
left: b.left,
top: b.top,
width: b.width,
height: b.height,
right: b.right,
bottom: b.bottom,
};
lastScrollRef.current = { top: scrollTop, left: scrollTop };
}
rect = rectCacheRef.current;
} else {
rectCacheRef.current = null;
}
if (!(el && rect && rect.width > 0 && rect.height > 0) || !rect) {
group.visible = false;
arrowFullscreenProgressStore.reset();
return;
}
const approachMargin = Math.max(2 * REF_MARGIN_PX, 480);
const viewportMidY = topY + 0.5 * cssH;
const vpWorld = state.viewport.getCurrentViewport(
camera,
worldPos.set(px, py, pz)
);
// Shrink state (original eh): the (margin-shrunk) rect top passing the
// point where it would end folds the arrow back down to rest.
const shrinkStart = viewportMidY + REF_MARGIN_PX - rect.height;
const shrinkEnd = Math.min(bottomY, shrinkStart + cssH);
const shrinkT =
rect.top <= shrinkStart
? 1
: rect.top >= shrinkEnd
? 0
: 1 - THREE.MathUtils.smoothstep(rect.top, shrinkStart, shrinkEnd);
const beforeShrink = rect.top > shrinkEnd;
const shrinking = rect.top <= shrinkEnd && rect.top > shrinkStart;
const leaveCap = Math.min(
0.35 * cssH,
(mergedGeometry.boundingSphere?.radius ?? 1) *
REST_SCALE *
(cssH / Math.max(vpWorld.height, 1e-4)) *
0.45
);
const leftViewport = rect.bottom < -leaveCap;
const inRange =
rect.top < bottomY + approachMargin &&
rect.bottom > -(6 * REF_MARGIN_PX) &&
!leftViewport;
group.visible = inRange;
if (!inRange) {
arrowFullscreenProgressStore.reset();
return;
}
// iTime: 2 × clamp01 — hyperspace star-field travel (uScrollDuration=2).
const canvasH = Math.max(1, size.height);
u.iResolution.value.set(vw * pixelRatio, canvasH * pixelRatio, 1);
const timeSpan = Math.max(1, bottomY + rect.height);
u.iTime.value = 2 * clamp01((bottomY - rect.top) / timeSpan);
// Reveal: smoothstep over (vpMid - (rect.top + margin)) / cssH.
const reveal = THREE.MathUtils.smoothstep(
clamp01((viewportMidY - (rect.top + REF_MARGIN_PX)) / cssH),
0,
1
);
// Vertical anchor: the model rides the clamped rect top/bottom (ex).
const rectTopAdj = rect.top + REF_MARGIN_PX;
const rectBottomAdj = rect.bottom - REF_MARGIN_PX;
const anchorNorm =
((beforeShrink
? Math.max(viewportMidY, rectTopAdj)
: shrinking
? viewportMidY
: Math.min(viewportMidY, rectBottomAdj)) -
topY) /
cssH;
group.position.set(px, (0.5 - anchorNorm) * vpWorld.height + py, pz);
// Scale: rest→peak by reveal, then fold back down (original eE/ew).
const autoPeak =
(Math.hypot(vpWorld.width, vpWorld.height) * AUTO_PEAK_PADDING) /
(mergedGeometry.boundingSphere?.radius ?? 1);
const peak = autoPeak;
const revealed = THREE.MathUtils.lerp(REST_SCALE, peak, reveal);
const targetScale = beforeShrink
? revealed
: shrinking
? THREE.MathUtils.lerp(revealed, REST_SCALE, shrinkT)
: REST_SCALE;
let scaleNow: number;
if (SCALE_SMOOTHING <= 0) {
scaleNow = targetScale;
scaleRef.current = targetScale;
} else if (dampInitRef.current) {
scaleRef.current = THREE.MathUtils.damp(
scaleRef.current,
targetScale,
SCALE_SMOOTHING,
delta
);
scaleNow = scaleRef.current;
} else {
dampInitRef.current = true;
scaleNow = targetScale;
scaleRef.current = targetScale;
}
mesh.scale.setScalar(scaleNow);
// Stripe reveal + store share the same normalized t (original eR).
const scaleSpan = Math.max(peak - REST_SCALE, 1e-6);
const scaleT = clamp01((scaleNow - REST_SCALE) / scaleSpan);
u.uStripeReveal.value = scaleT;
arrowFullscreenProgressStore.setDampedScaleT(scaleT);
// Spin (original eS): wind up while approaching, extra turn in shrink.
let spinY = 0;
if (shrinking) {
spinY = SPIN_RADIANS + clamp01((shrinkT - 0.6) / 0.4) * SPIN_RADIANS;
} else if (beforeShrink) {
spinY = clamp01(scaleT / 0.4) * SPIN_RADIANS;
}
const spinGroup = spinRef.current;
if (spinGroup) {
spinGroup.rotation.x = 0;
spinGroup.rotation.y = spinY;
spinGroup.rotation.z = 0;
}
// Pointer-following specular light (original I.update).
const { x: lx, y: ly } = lightCtl.update({
uv,
inside: insideRef.current && !isMobile,
camera,
delta,
});
u.uLight.value.set(lx, ly, LIGHT_Z);
}, -2);
if (!mergedGeometry) return null;
return (
<group ref={groupRef} visible={false}>
<group rotation={TILT_RAD}>
<group ref={spinRef}>
<group rotation={NEG_TILT_RAD}>
<mesh
ref={meshRef}
geometry={mergedGeometry}
renderOrder={12}
frustumCulled={false}
scale={[REST_SCALE, REST_SCALE, REST_SCALE]}
>
<shaderMaterial
ref={materialRef}
vertexShader={vert}
fragmentShader={frag}
uniforms={uniforms}
transparent
depthWrite={false}
depthTest
toneMapped={false}
side={THREE.FrontSide}
/>
</mesh>
</group>
</group>
</group>
</group>
);
}
+18 -2
View File
@@ -5,6 +5,10 @@ import ScrambleReveal from "@/components/dom/ScrambleReveal";
import { useShellMedia, type ThemeSetting } from "@/lib/shellMedia";
import { useBgm } from "@/lib/useBgm";
import { scrollEnv } from "@/lib/scrollEnv";
import {
useArrowFullscreenPastThreshold,
ARROW_FULLSCREEN_DOM_COLOR_TRANSITION,
} from "@/lib/arrowFullscreen";
/**
* Header — ported from the original (chunk 2689132c4e070b68.js):
@@ -48,6 +52,10 @@ function useBrowserName(): string {
export default function Header() {
const { theme, setTheme, soundEnabled, setSoundEnabled } = useShellMedia();
useBgm(soundEnabled);
// Arrow-fullscreen state: past the 0.5 reveal threshold the whole header
// (and the hyper-space section) turn white over the black stripe base
// (original X = useArrowFullscreenPastThreshold()).
const arrowWhite = useArrowFullscreenPastThreshold();
const [time, setTime] = useState("--:--");
const [coords, setCoords] = useState({ x: "0001", y: "0001" });
@@ -180,7 +188,11 @@ export default function Header() {
"inline-flex shrink-0 items-baseline gap-0 normal-case";
return (
<header className="z-50 fixed inset-0 flex flex-col justify-between font-mono-2 pointer-events-none text-l1">
<header
className={`z-50 fixed inset-0 flex flex-col justify-between font-mono-2 pointer-events-none ${ARROW_FULLSCREEN_DOM_COLOR_TRANSITION} ${
arrowWhite ? "text-white" : "text-l1"
}`}
>
<div className="flex justify-between items-center px-4 lg:px-14 py-4 lg:py-7 text-base">
<a
className={`${dotted} p-2 font-sans font-bold uppercase pointer-events-auto transition-colors duration-300 ease-out`}
@@ -273,7 +285,11 @@ export default function Header() {
animation: "vh-fade-in 0.4s cubic-bezier(0.25, 1, 0.5, 1) both",
}}
>
<div className="flex flex-col bg-be p-2 font-mono-2 text-l1 xl:basis-1/3 basis-1/2">
<div
className={`flex flex-col bg-be p-2 font-mono-2 xl:basis-1/3 basis-1/2 ${ARROW_FULLSCREEN_DOM_COLOR_TRANSITION} ${
arrowWhite ? "text-white" : "text-l1"
}`}
>
{/* Original hint-panel texts omit scrambleColors → the scramble
component's default (true) applies: chars flash the lime
phase colors #c0fe04 → #607F02 while revealing, and the
+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>
);
}
+2 -1
View File
@@ -2,7 +2,7 @@
import { useEffect } from 'react';
import Lenis from 'lenis';
import { scrollBus } from '@/lib/scrollBus';
import { scrollBus, notifyScroll } from '@/lib/scrollBus';
import { scrollEnv } from '@/lib/scrollEnv';
const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
@@ -67,6 +67,7 @@ export default function SmoothScroller() {
scrollBus.velocity = e.velocity;
scrollBus.progress = e.progress;
updateCameraProgress();
notifyScroll();
});
window.addEventListener('resize', updateCameraProgress);
updateCameraProgress();
+70
View File
@@ -0,0 +1,70 @@
"use client";
/**
* Arrow-fullscreen progress store — 1:1 port of the original module 1111
* (arrowFullscreenProgressStore):
*
* The WebGL hyperspace model (cursor.glb stripes) reports its normalized
* scale progress t (restScale→peak) every frame via `setDampedScaleT`.
* DOM consumers (header text color, the hyper-space section itself) read a
* boolean "past threshold" through `useArrowFullscreenPastThreshold`, whose
* subscription only notifies when the boolean flips — so 60fps store writes
* never re-render the header.
*
* Threshold semantics (original `r(mode, snapshot, e)`): "gte" →
* snapshot >= threshold. Server snapshot: 0 >= threshold.
*/
import { useCallback, useSyncExternalStore } from "react";
type Listener = () => void;
let value = 0;
const listeners = new Set<Listener>();
function notify() {
for (const cb of listeners) cb();
}
export const arrowFullscreenProgressStore = {
getSnapshot: () => value,
subscribe(cb: Listener) {
listeners.add(cb);
return () => {
listeners.delete(cb);
};
},
setDampedScaleT(t: number) {
const next = Math.min(1, Math.max(0, t));
if (0.001 >= Math.abs(next - value)) return;
value = next;
notify();
},
reset() {
if (value !== 0) {
value = 0;
notify();
}
},
};
export function readArrowFullscreenPastThreshold(threshold = 0.5): boolean {
return arrowFullscreenProgressStore.getSnapshot() >= threshold;
}
export function useArrowFullscreenPastThreshold(threshold = 0.5): boolean {
return useSyncExternalStore(
arrowFullscreenProgressStore.subscribe,
useCallback(
() => arrowFullscreenProgressStore.getSnapshot() >= threshold,
[threshold]
),
useCallback(() => 0 >= threshold, [threshold])
);
}
/**
* Original constant ARROW_FULLSCREEN_DOM_COLOR_TRANSITION — every DOM
* element whose color follows the arrow fullscreen state carries this.
*/
export const ARROW_FULLSCREEN_DOM_COLOR_TRANSITION =
"transition-colors duration-300 ease-out motion-reduce:transition-none";
+18
View File
@@ -13,3 +13,21 @@ export const scrollBus: ScrollBusState = {
progress: 0,
sP: 0,
};
/**
* Lightweight pub/sub so DOM components (hyper-space section stages) can
* read `scrollBus.current` reactively via useSyncExternalStore — the
* original reads it through `useLenisScrollTop` (module 35231).
*/
const scrollListeners = new Set<() => void>();
export function subscribeScroll(cb: () => void): () => void {
scrollListeners.add(cb);
return () => {
scrollListeners.delete(cb);
};
}
export function notifyScroll() {
for (const cb of scrollListeners) cb();
}
+16
View File
@@ -0,0 +1,16 @@
"use client";
import { useEffect, useState } from "react";
/** Window size (original useWindowSize, module 30468). */
export function useWindowSize() {
const [size, setSize] = useState({ width: 0, height: 0 });
useEffect(() => {
const update = () =>
setSize({ width: window.innerWidth, height: window.innerHeight });
update();
window.addEventListener("resize", update, { passive: true });
return () => window.removeEventListener("resize", update);
}, []);
return size;
}