3957e36c41
- 详情页补齐原站 MDX 组件:左侧目录(2xl 固定定位、滚动高亮 top≤96、 点击平滑滚动)、标题锚点(hover #、点击复制链接 + replaceState)、 代码块(语言标签 + COPY/COPIED + 原站 prism token HTML 按行号渲染, --code-* 配色变量)、页脚 Metadata(实时视口尺寸 / 正文字符数)与 Work/Contact 按钮(sessionStorage hq:pendingScrollAnchor → 首页过渡后 滚动到对应区块,SmoothScroller 消费) - content/workArticles.ts 重新提取:内联 strong/em/code 片段、标题 id、 代码块语言 + 高亮 HTML + 纯文本(bs4 全量解析 6 篇文章) - 详情页不再显示十字网格(BackgroundGrid 按 pathname 门控,置于全部 hooks 之后避免 hook 数量变化崩溃) - 首页层叠修复:WebGL 容器改为原站的 top-0 left-0 -z-1 fixed(此前 z-auto fixed 按 CSS 绘制顺序盖住 banner 文案与作品说明文字),footer 改为原站的 z-10 relative,body 背景移至 html 根节点(否则普通流 body 背景会盖住 -z-1 场景)
111 lines
4.0 KiB
TypeScript
111 lines
4.0 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useMemo, useState } from 'react';
|
|
import { usePathname } from 'next/navigation';
|
|
import { loadingBus } from '@/lib/loadingBus';
|
|
|
|
/**
|
|
* Background grid — 1:1 port of the original (chunk 2689132c4e070b68.js):
|
|
*
|
|
* - Three cross junctions at thirds of the viewport height (y = h/3 - 12,
|
|
* y = h/3 + 12 + i + 24), i.e. rows at h/3-12 and 2h/3+12, with 12px gaps
|
|
* around the crosses and 12px notches where lines meet the frame.
|
|
* - 2 columns (<1280) / 3 columns of vertical lines between the px paddings
|
|
* (16 mobile / 56 lg), fractions of the inner width.
|
|
* - Whole overlay hidden while the home loading gate is up
|
|
* (`"/"===pathname && !readyToLoadHeavy`); visible at all other times —
|
|
* that is why the original keeps the crosses on screen while scrolling.
|
|
*/
|
|
const LINE = 'rgba(255, 255, 255, 0.1)';
|
|
|
|
export default function BackgroundGrid() {
|
|
const pathname = usePathname();
|
|
const [size, setSize] = useState({ w: 0, h: 0 });
|
|
|
|
useEffect(() => {
|
|
const updateSize = () => {
|
|
setSize({ w: window.innerWidth, h: window.innerHeight });
|
|
};
|
|
updateSize();
|
|
window.addEventListener('resize', updateSize);
|
|
return () => window.removeEventListener('resize', updateSize);
|
|
}, []);
|
|
|
|
// useHomeLoadingGate (original module 97839): "/" && !readyToLoadHeavy.
|
|
// Our equivalent heavy-ready signal is the loading curtain (loadingBus).
|
|
const [heavyReady, setHeavyReady] = useState(pathname !== '/');
|
|
useEffect(() => {
|
|
if (pathname !== '/') {
|
|
setHeavyReady(true);
|
|
return;
|
|
}
|
|
setHeavyReady(loadingBus.getSnapshot().ready);
|
|
return loadingBus.subscribe(() => {
|
|
setHeavyReady(loadingBus.getSnapshot().ready);
|
|
});
|
|
}, [pathname]);
|
|
|
|
const { w, h } = size;
|
|
|
|
const loadingGate = pathname === '/' && !heavyReady;
|
|
|
|
const { verticalPath, horizontalPath, crossPath } = useMemo(() => {
|
|
if (w <= 0 || h <= 0) return { verticalPath: '', horizontalPath: '', crossPath: '' };
|
|
const n = w < 1024 ? 16 : 56;
|
|
const innerW = Math.max(0, w - 2 * n);
|
|
const i = Math.max(0, h / 3 - 12);
|
|
const s = i + 24;
|
|
const a = s + i;
|
|
const cols = w < 1280 ? 2 : 3;
|
|
const xs = Array.from({ length: cols + 1 }, (_, k) => n + (k / cols) * innerW).map(
|
|
(x) => Math.round(x) + 0.5
|
|
);
|
|
const rows = [
|
|
{ startY: 0, endY: i },
|
|
{ startY: s, endY: a },
|
|
{ startY: a + 24, endY: h },
|
|
];
|
|
const u = [i + 12, a + 12];
|
|
const verticalPath = rows
|
|
.map(({ startY, endY }) => xs.map((x) => `M${x} ${startY}V${endY}`).join(''))
|
|
.join('');
|
|
const horizontalPath = u
|
|
.map((y) => {
|
|
if (xs.length < 2) return '';
|
|
const first = xs[0];
|
|
const last = xs[xs.length - 1];
|
|
const mids = xs.slice(0, -1)
|
|
.map((x, k) => `M${x + 12} ${y}H${xs[k + 1] - 12}`)
|
|
.join('');
|
|
return [`M0 ${y}H${first - 12}`, mids, `M${last + 12} ${y}H${w}`].join('');
|
|
})
|
|
.join('');
|
|
const crossPath = xs
|
|
.flatMap((x) => u.flatMap((y) => [`M${x} ${y - 6}V${y + 6}`, `M${x - 6} ${y}H${x + 6}`]))
|
|
.join('');
|
|
return { verticalPath, horizontalPath, crossPath };
|
|
}, [w, h]);
|
|
|
|
// The original mounts this grid in the home route tree only — detail
|
|
// pages (…/reunimos, …/wasm_design_utils) show no crosshair at all.
|
|
// NOTE: placed after every hook — this component persists in the root
|
|
// layout, and an early return before useMemo changes the hook count on
|
|
// route change ("Rendered more hooks than during the previous render").
|
|
if (pathname !== '/') return null;
|
|
|
|
if (loadingGate) return null;
|
|
|
|
return (
|
|
<div className="z-20 fixed inset-0 w-full h-full pointer-events-none mix-blend-difference">
|
|
<svg
|
|
viewBox={`0 0 ${w} ${h}`}
|
|
className="block shape-rendering-crispEdges w-full h-full"
|
|
>
|
|
<path d={verticalPath} stroke={LINE} strokeWidth="1" fill="none" />
|
|
<path d={horizontalPath} stroke={LINE} strokeWidth="1" fill="none" />
|
|
<path d={crossPath} stroke="#FFFFFF" strokeWidth="1" fill="none" opacity="0.4" />
|
|
</svg>
|
|
</div>
|
|
);
|
|
}
|