Files
personal/components/canvas/DotOverlay.tsx
T
virtheart d5a1228aac feat: 暗色主题 + /2026 详情页 + 逐页标题 — 对齐原站剩余缺口
- 暗色主题 1:1:ThemeModeProvider 原逻辑(localStorage 'theme'
  light/dark/system、system 跟随 prefers-color-scheme、<html> class 切换),
  CSS tokens 按原站 .dark 块翻值(--label/--background-deep/--code-*);
  shellMedia 重构为 useSyncExternalStore 单例 store(Header 与 Canvas 共享)
- WebGL 主题分支:BackgroundFX 暗色渐变(#2c4bd5/#00000d/#00344C +
  outputMix .95/edgeIntensity -.82,原 sj 配置)、DotOverlay #0F1111、
  LoadingCurtain #191b1b、玻璃模型暗色参数组(shininess 100/fresnel .72/
  brightness .6/uDark=1 Hard-Light)与暗色 tint(hello #64c3ff、
  footer #8e9dc4/#64c3ff)
- /2026 路由:rewrite 补 2026(此前 404),workArticles 增加 /2026 占位文章
  (原站内容被服务端口令保密无法读取,已注释说明);解锁屏→刷新→服务端
  放行全链路 CDP 验证通过
- 逐页 <title>:app/work/[slug]/layout.tsx generateMetadata 映射作品名
  (reunimos→Reunimos™),受保护 /2026 未解锁时 SSR 'Protected'(原站行为),
  根标题改回原站 'HAOQI©2026'
2026-09-02 14:31:28 +08:00

126 lines
3.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"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<any>(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 (
<mesh renderOrder={10} frustumCulled={false}>
<planeGeometry args={[2, 2]} />
<shaderMaterial
ref={materialRef}
transparent
depthTest={false}
depthWrite={false}
toneMapped={false}
uniforms={uniforms}
vertexShader={`
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = vec4(position.xy, 0.0, 1.0);
}
`}
fragmentShader={`
precision highp float;
varying vec2 vUv;
uniform vec3 uColor;
uniform float uOpacity;
uniform float uPixelSize;
uniform float uRadiusScale;
uniform vec2 uResolution;
void main() {
float a = clamp(uOpacity, 0.0, 1.0);
vec2 normalizedPixelSize = vec2(
uPixelSize / max(uResolution.x, 1.0),
uPixelSize / max(uResolution.y, 1.0)
);
vec2 safePixelSize = max(normalizedPixelSize, vec2(1e-6));
vec2 cellUV = fract(vUv / safePixelSize);
// 与 route_transition 点阵一致:透明度直接映射圆半径。
float radius = uRadiusScale * a;
float distanceFromCenter = distance(cellUV, vec2(0.5));
float aa = fwidth(distanceFromCenter) * 1.5;
float circleMask = smoothstep(radius, radius - aa, distanceFromCenter);
gl_FragColor = vec4(uColor, circleMask);
#include <colorspace_fragment>
}
`}
/>
</mesh>
);
}
export default DotOverlay;