"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 (
{RING_ELLIPSES.map((i) => ( { refs.current[i] = el; }} visibility="hidden" stroke="#C0FE04" strokeOpacity={1} strokeWidth={2} vectorEffect="non-scaling-stroke" /> ))}
); }); // --- Stagger text (original ft cache + fr) --------------------------------- const staggerCache = new Map(); /** 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 ( {text} ); } return ( {chars.map((ch, i) => { const delay = ((play ? inDelays[i] : outDelays[i]) + groupDelayMs) / 1e3; return ( {ch === " " ? "\u00A0" : ch} ); })} ); }); 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(() => stageForSegment(0)); const [seg0Reveal, setSeg0Reveal] = useState(false); const [staggerGen, setStaggerGen] = useState(0); const [stageProgress01, setStageProgress01] = useState(0); const lastSegmentRef = useRef(0); const stageRef = useRef(stageForSegment(0)); const inSeg0Ref = useRef(false); const wasAboveRef = useRef(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({ once = false, threshold = 0, rootMargin = "0px", }: { once?: boolean; threshold?: number; rootMargin?: string; }) { const ref = useRef(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 (
{lines.map((line, i) => ( ))}
); } function Seg1({ ringProgress01 }: { ringProgress01: number }) { return ( <>




); } function EndStage() { const { ref, hasEntered } = useHasEnteredViewport({ threshold: 0.35 }); return (
{END_LINES.map((line, i) => ( ))}
); } // --- Section (original fh) --------------------------------------------------- export default function HyperSpaceSection() { const sectionRef = useRef(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 (
{ sectionRef.current = el; getLayerTarget("hyper-space").current = el; void el; }} className={`relative z-30 ${ARROW_FULLSCREEN_DOM_COLOR_TRANSITION} ${ pastThreshold ? "text-white" : "text-l1" }`} style={{ height: `${8 * viewportH}px` }} >
{stage === "seg0-primary" || stage === "seg0-secondary" ? ( ) : stage === "seg1" ? ( ) : stage === "end" ? ( ) : (
)}
); }