"use client"; import { useLayoutEffect, useMemo, useRef } from "react"; import { useFrame, useThree } from "@react-three/fiber"; import { Color, Vector2 } from "three"; import { scrollBus } from "@/lib/scrollBus"; import { useResolvedTheme } from "@/lib/shellMedia"; /** * Scroll dot-overlay — 1:1 port of the original `s1` (chunk * 4d3f3b68dbbde33a.js): a fullscreen transparent mesh at renderOrder 10 * whose opacity equals sT(sP) (the banner/footer camera progress). The * page-background-colored dot grid (4px cells, radius .9 × opacity) * melts the WebGL scene (stickers, glass, gradient bg) into the page * background as you scroll past the hero — that IS the "stickers fade * out on scroll" behavior of the original site. Near the footer sP → 0 * and the overlay opens again. * * Light-theme colors (c_): dark "#0F1111", light "#FBFAF4". */ const OVERLAY_COLORS = ["#0F1111", "#FBFAF4"] as const; const OVERLAY_PIXEL_SIZE = 4; const OVERLAY_RADIUS_SCALE = 0.9; const clamp01 = (e: number) => Math.min(1, Math.max(0, e)); /** Original sT: normalize (values > 1 are treated as percentages). */ function sT(e?: number): number { return e === undefined ? 0 : clamp01(e > 1 ? e / 100 : e); } export function DotOverlay() { // Original: resolvedTheme from useThemeMode (s1 picks e[0] dark / e[1] light). const isDark = useResolvedTheme() === "dark"; const size = useThree((s) => s.size); const materialRef = useRef(null); const uniforms = useMemo( () => ({ uColor: { value: new Color() }, uOpacity: { value: 1 }, uPixelSize: { value: OVERLAY_PIXEL_SIZE }, uRadiusScale: { value: OVERLAY_RADIUS_SCALE }, uResolution: { value: new Vector2(1, 1) }, }), [] ); // Theme color: light theme picks the second entry (original e[1]). useLayoutEffect(() => { const [dark, light] = OVERLAY_COLORS; materialRef.current?.uniforms.uColor.value.set(isDark ? dark : light); }, [isDark]); useLayoutEffect(() => { materialRef.current?.uniforms.uResolution.value.set( Math.max(1, size.width), Math.max(1, size.height) ); }, [size.width, size.height]); useFrame(() => { const e = sT(scrollBus.sP); if (materialRef.current) { materialRef.current.uniforms.uOpacity.value = e; } }); return ( } `} /> ); } export default DotOverlay;