feat: 详情页 MDX 组件 1:1(目录/锚点/代码块/页脚)与首页层叠修复
- 详情页补齐原站 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 场景)
This commit is contained in:
+18
-2
@@ -26,11 +26,27 @@
|
||||
--label-d: 54, 54, 48;
|
||||
--label-1: rgba(var(--label), 1);
|
||||
--label-3: rgba(var(--label-d), 0.32);
|
||||
|
||||
/* Original code token colors (light theme, chunk 635eb04122aa774f.css) —
|
||||
the MDX CodeBlock maps prism token types to these vars. */
|
||||
--code-comment: rgba(var(--label-d), 0.45);
|
||||
--code-string: lab(43.8263% -47.6118 18.596);
|
||||
--code-number: lab(46.7992% 8.99872 72.9973);
|
||||
--code-keyword: lab(43.3789% 36.2819 -73.3524);
|
||||
--code-function: lab(47.3165% -8.24019 -45.3882);
|
||||
--code-tag: lab(47.2741% 51.266 23.7532);
|
||||
--code-operator: rgba(var(--label-d), 0.75);
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
/* Background lives on the ROOT only — per CSS painting it propagates to the
|
||||
canvas backdrop, so it stays BEHIND the original's -z-1 fixed WebGL host.
|
||||
A body-level background would paint as normal-flow content and cover the
|
||||
scene (the text-over-canvas regression this fixes). */
|
||||
html {
|
||||
background-color: var(--bg-color);
|
||||
}
|
||||
|
||||
body {
|
||||
color: var(--text-color);
|
||||
font-family: var(--font-sans);
|
||||
margin: 0;
|
||||
|
||||
+448
-100
@@ -1,60 +1,238 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Work detail pages — /work/[slug] rendering the original MDX article
|
||||
* markup 1:1 (from https://haoqi.design/reunimos et al.):
|
||||
* Work detail pages — 1:1 port of the original MDX detail route
|
||||
* (haoqi.design/reunimos et al.), including:
|
||||
*
|
||||
* <div class="fixed inset-0 w-full h-full">
|
||||
* <div class="w-full h-full overflow-y-auto overscroll-contain no-scrollbar">
|
||||
* <article data-mdx-article class="mx-auto px-6 py-18 lg:py-24 w-full
|
||||
* max-w-[880px] text-l1">
|
||||
* <header class="pt-[10vh]"> h1 + date + hr + year </header>
|
||||
* <div class="[&_p+p]:mt-3 …"> blocks </div>
|
||||
* </article>
|
||||
*
|
||||
* Content comes from content/workArticles.ts (extracted from the live
|
||||
* pages). Passcode-protected scopes (/2026) render the unlock screen when
|
||||
* locked, exactly like the original.
|
||||
* - MdxHeading (chunk 5a5e6e9b module 31250): h2/h3/h4 with auto id,
|
||||
* hover "#", click → scroll to anchor (-96 offset) + copy URL +
|
||||
* history.replaceState.
|
||||
* - MdxTableOfContents (module 78825): fixed-left nav, 2xl only,
|
||||
* h1–h3 collection from article[data-mdx-article], active heading =
|
||||
* last heading above 96px viewport line, click scrolls via
|
||||
* scrollToMdxAnchorTarget (lerp .1).
|
||||
* - CodeBlock (chunk 4d1355f module 93325): language label + COPY/COPIED
|
||||
* button + numbered lines; the token HTML comes pre-highlighted from the
|
||||
* original SSR (span.token with inline color styles mapped to
|
||||
* --code-* CSS vars) and is injected as-is.
|
||||
* - ArticleFooter (module 54450): Metadata dl (Last Updated / live viewport
|
||||
* Dimensions / live Characters count of the article text) + Links
|
||||
* (Home link; Work/Contact buttons navigate home through the transition
|
||||
* with a pending-scroll anchor in sessionStorage, key "hq:pendingScrollAnchor").
|
||||
*/
|
||||
import { Suspense, useMemo } from "react";
|
||||
import { Suspense, useCallback, useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useParams, usePathname } from "next/navigation";
|
||||
import {
|
||||
WORK_ARTICLES,
|
||||
type ArticleBlock,
|
||||
type InlineSeg,
|
||||
} from "@/content/workArticles";
|
||||
import { usePasscodeAllowed } from "@/components/dom/PasscodeAccess";
|
||||
import { useRouteTransitionController } from "@/lib/routeTransition";
|
||||
import { PasscodeUnlockScreen } from "@/components/dom/PasscodeUnlockScreen";
|
||||
import { buildPasscodeUnlockHref, primaryPasscodePath, scopeToPath } from "@/lib/passcode";
|
||||
import { useRouteTransitionController } from "@/lib/routeTransition";
|
||||
import { scrollEnv } from "@/lib/scrollEnv";
|
||||
import ScrambleReveal from "@/components/dom/ScrambleReveal";
|
||||
import CustomScrollbar from "@/components/dom/CustomScrollbar";
|
||||
|
||||
const PROSE_CLASS =
|
||||
"[&_p+p]:mt-3 [&_p]:mb-0 text-l2 [&_p]:text-sm [&_p]:text-l1 [&_p]:leading-relaxed lg:[&_p]:text-base";
|
||||
export const PENDING_SCROLL_ANCHOR_SESSION_KEY = "hq:pendingScrollAnchor";
|
||||
const MDX_HEADING_ANCHOR_OFFSET_PX = 96;
|
||||
|
||||
const PROSE_CLASS =
|
||||
"space-y-4 [&_p]:text-sm [&_p]:text-l1 [&_p]:leading-relaxed lg:[&_p]:text-base [&_ul]:list-disc [&_ul]:pl-5 [&_ul]:my-0 [&_ul]:space-y-0 [&_ol]:list-decimal [&_ol]:pl-5 [&_ol]:my-0 [&_ol]:space-y-0 [&_li]:text-l1 [&_li]:leading-relaxed [&_li::marker]:text-[var(--selection-bg)] [&_blockquote]:border-l-4 [&_blockquote]:border-[var(--selection-bg)] [&_blockquote]:pl-4 [&_blockquote]:text-l2 [&_blockquote_p]:text-l2 [&_blockquote_li]:text-l2 [&_blockquote_strong]:text-l2 [&_blockquote_em]:text-l2 [&_blockquote_a]:!text-l2 [&_blockquote_a]:underline [&_blockquote_a]:underline-offset-4 [&_blockquote_a]:decoration-[color:var(--label-3)] [&_blockquote_a]:transition-colors [&_blockquote_a]:lg:hover:!text-l1 [&_blockquote_a]:lg:hover:decoration-[color:var(--label-2)] [&_:not(pre)>code]:rounded [&_:not(pre)>code]:bg-[rgba(var(--label-d),0.08)] [&_:not(pre)>code]:px-1.5 [&_:not(pre)>code]:py-0.5 [&_:not(pre)>code]:font-mono [&_:not(pre)>code]:text-[0.9em] [&_:not(pre)>code]:text-l1 [&_hr]:my-8 [&_hr]:h-px [&_hr]:w-full [&_hr]:border-0 [&_hr]:bg-line [&_u]:no-underline [&_u]:pb-[6px] [&_u]:[box-decoration-break:clone] [&_u]:[-webkit-box-decoration-break:clone] [&_u]:[background-image:radial-gradient(circle_at_center,var(--color-l2)_0.65px,transparent_0.7px)] [&_u]:[background-size:5px_3px] [&_u]:[background-repeat:repeat-x] [&_u]:[background-position:left_bottom]";
|
||||
|
||||
/** Original MdxA link class (module 71289). */
|
||||
const MDX_LINK_CLASS =
|
||||
"text-[color:var(--label-1)] underline underline-offset-4 decoration-[color:var(--label-3)] transition-colors lg:hover:decoration-[color:var(--label-2)]";
|
||||
|
||||
/** Original heading classes map (module 31250 `a`). */
|
||||
const HEADING_CLASSES: Record<number, string> = {
|
||||
1: "mt-12 text-2xl leading-tight lg:mt-14 lg:text-[28px]",
|
||||
2: "mt-10 text-xl leading-tight lg:mt-12 lg:text-2xl",
|
||||
3: "mt-8 text-lg leading-snug lg:mt-10 lg:text-xl",
|
||||
4: "mt-7 text-base leading-snug lg:mt-8 lg:text-lg",
|
||||
5: "mt-6 text-sm leading-snug lg:mt-7 lg:text-[17px]",
|
||||
6: "mt-6 text-sm leading-snug uppercase tracking-wide lg:mt-6 lg:text-base lg:normal-case lg:tracking-normal",
|
||||
};
|
||||
|
||||
/** Original slugify (module 31250). */
|
||||
function headingId(text: string): string | undefined {
|
||||
return (
|
||||
text
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[\s\u3000]+/g, "-")
|
||||
.replace(/[^\w\u4e00-\u9fff-]+/g, "")
|
||||
.replace(/-{2,}/g, "-")
|
||||
.replace(/^-+|-+$/g, "") || undefined
|
||||
);
|
||||
}
|
||||
|
||||
/** Original scrollToMdxAnchorTarget (module 31250 `i`). */
|
||||
function scrollToMdxAnchorTarget(el: HTMLElement) {
|
||||
const container = scrollEnv.getContainerEl();
|
||||
if (container) {
|
||||
const top =
|
||||
el.getBoundingClientRect().top -
|
||||
container.getBoundingClientRect().top +
|
||||
container.scrollTop -
|
||||
MDX_HEADING_ANCHOR_OFFSET_PX;
|
||||
scrollEnv.lenisScrollTo(Math.max(0, top), { lerp: 0.1 });
|
||||
return;
|
||||
}
|
||||
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
}
|
||||
|
||||
function MdxHeading({
|
||||
level,
|
||||
text,
|
||||
id,
|
||||
}: {
|
||||
level: 2 | 3 | 4;
|
||||
text: string;
|
||||
id?: string;
|
||||
}) {
|
||||
const anchorId = id ?? headingId(text);
|
||||
const onClick = useCallback(
|
||||
async (e: React.MouseEvent) => {
|
||||
if (!anchorId) return;
|
||||
e.preventDefault();
|
||||
const target = document.getElementById(anchorId);
|
||||
if (target) scrollToMdxAnchorTarget(target);
|
||||
const hash = `#${encodeURIComponent(anchorId)}`;
|
||||
history.replaceState(null, "", hash);
|
||||
const url = `${window.location.origin}${window.location.pathname}${window.location.search}${hash}`;
|
||||
try {
|
||||
await navigator.clipboard?.writeText(url);
|
||||
} catch {}
|
||||
},
|
||||
[anchorId]
|
||||
);
|
||||
const cls = [
|
||||
"group relative scroll-mt-24 font-semibold tracking-tight text-l1 [&:first-child]:mt-0",
|
||||
HEADING_CLASSES[level],
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
const Tag = `h${level}` as "h2";
|
||||
const inner = anchorId ? (
|
||||
<a
|
||||
href={`#${encodeURIComponent(anchorId)}`}
|
||||
onClick={onClick}
|
||||
aria-label={`Copy link to ${text}`}
|
||||
className="relative inline-block text-inherit no-underline"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="absolute top-0 right-full mr-2 hidden text-l3 opacity-0 transition-opacity select-none lg:inline lg:group-hover:opacity-100 lg:hover:text-l1"
|
||||
>
|
||||
#
|
||||
</span>
|
||||
{text}
|
||||
</a>
|
||||
) : (
|
||||
text
|
||||
);
|
||||
return (
|
||||
<Tag id={anchorId} className={cls}>
|
||||
{inner}
|
||||
</Tag>
|
||||
);
|
||||
}
|
||||
|
||||
/** Inline segment renderer (MdxA class for links). */
|
||||
function Inline({ segs }: { segs: InlineSeg[] }) {
|
||||
return (
|
||||
<>
|
||||
{segs.map((s, i) =>
|
||||
s.t === "link" ? (
|
||||
{segs.map((s, i) => {
|
||||
switch (s.t) {
|
||||
case "link":
|
||||
return (
|
||||
<a
|
||||
key={i}
|
||||
href={s.href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline text-l1 underline underline-offset-[0.08em] decoration-solid decoration-(--label-3) transition-[text-decoration-color] duration-150 ease-out lg:[@media(hover:hover)]:hover:decoration-(--label-1)"
|
||||
className={MDX_LINK_CLASS}
|
||||
>
|
||||
{s.v}
|
||||
</a>
|
||||
) : (
|
||||
<span key={i}>{s.v}</span>
|
||||
)
|
||||
)}
|
||||
);
|
||||
case "code":
|
||||
return (
|
||||
<code
|
||||
key={i}
|
||||
className="rounded px-1.5 py-0.5 font-mono text-[0.9em] text-l1 bg-[rgba(var(--label-d),0.08)]"
|
||||
>
|
||||
{s.v}
|
||||
</code>
|
||||
);
|
||||
case "strong":
|
||||
return (
|
||||
<strong key={i} className="font-semibold">
|
||||
{s.v}
|
||||
</strong>
|
||||
);
|
||||
case "em":
|
||||
return <em key={i}>{s.v}</em>;
|
||||
default:
|
||||
return <span key={i}>{s.v}</span>;
|
||||
}
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** CodeBlock — original module 93325 chrome around the pre-highlighted HTML. */
|
||||
function CodeBlock({
|
||||
language,
|
||||
label,
|
||||
html,
|
||||
text,
|
||||
}: {
|
||||
language: string;
|
||||
label: string;
|
||||
html: string;
|
||||
text: string;
|
||||
}) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const onCopy = useCallback(async () => {
|
||||
if (!text) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
setCopied(true);
|
||||
window.setTimeout(() => setCopied(false), 1200);
|
||||
} catch {
|
||||
setCopied(false);
|
||||
}
|
||||
}, [text]);
|
||||
return (
|
||||
<div className="group my-6 overflow-hidden rounded-xl bg-[rgba(var(--label-d),0.03)]">
|
||||
<div className="flex items-center justify-between px-3 py-2 shadow-[inset_0_-1px_0_0_var(--line)] lg:px-4">
|
||||
<span className="px-1 font-mono text-xs tracking-wide text-(--label-3)">
|
||||
{label}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onCopy}
|
||||
aria-label={copied ? "Copied code" : "Copy code"}
|
||||
className="block before:absolute relative before:inset-0 before:border-2 before:border-dotted before:border-transparent before:pointer-events-none before:transition-colors before:duration-200 lg:hover:before:border-l1 cursor-pointer px-1 py-0.5 font-mono text-xs uppercase tracking-wide text-(--label-2) transition-colors lg:hover:text-(--label-1) focus-visible:text-(--label-1) focus-visible:outline-none focus-visible:before:border-l1"
|
||||
>
|
||||
{copied ? "COPIED" : "COPY"}
|
||||
</button>
|
||||
</div>
|
||||
<pre className="overflow-x-auto px-4 py-2 font-mono text-xs leading-relaxed text-(--label-1) lg:px-5 lg:py-2.5 lg:text-sm">
|
||||
<code
|
||||
className={`language-${language}`}
|
||||
// Pre-highlighted token HTML extracted from the original SSR
|
||||
// (span.token, inline color styles → --code-* vars).
|
||||
dangerouslySetInnerHTML={{ __html: html }}
|
||||
/>
|
||||
</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Block({ block }: { block: ArticleBlock }) {
|
||||
switch (block.type) {
|
||||
case "p":
|
||||
@@ -64,9 +242,20 @@ function Block({ block }: { block: ArticleBlock }) {
|
||||
</p>
|
||||
);
|
||||
case "h2":
|
||||
return <h2 className="mt-8 font-bold text-xl! text-l1">{block.text}</h2>;
|
||||
return <MdxHeading level={2} text={block.text} id={block.id} />;
|
||||
case "h3":
|
||||
return <h3 className="mt-6 font-bold text-lg! text-l1">{block.text}</h3>;
|
||||
return <MdxHeading level={3} text={block.text} id={block.id} />;
|
||||
case "h4":
|
||||
return <MdxHeading level={4} text={block.text} id={block.id} />;
|
||||
case "code":
|
||||
return (
|
||||
<CodeBlock
|
||||
language={block.language}
|
||||
label={block.label}
|
||||
html={block.html}
|
||||
text={block.text}
|
||||
/>
|
||||
);
|
||||
case "img":
|
||||
// eslint-disable-next-line @next/next/no-img-element -- original uses plain img with cursor-zoom-in
|
||||
return (
|
||||
@@ -102,29 +291,243 @@ function Block({ block }: { block: ArticleBlock }) {
|
||||
case "quote":
|
||||
return (
|
||||
<blockquote className="border-l-4 border-(--selection-bg) pl-4 text-l2">
|
||||
{block.items.map((q, i) => (
|
||||
<p key={i} className="text-l2">
|
||||
{q}
|
||||
<p className="text-l2">
|
||||
<Inline segs={block.segs} />
|
||||
</p>
|
||||
))}
|
||||
</blockquote>
|
||||
);
|
||||
case "code":
|
||||
return (
|
||||
<pre className="my-4 overflow-x-auto rounded bg-[rgba(var(--label-d),0.08)] p-3 font-mono text-[0.9em] text-l1">
|
||||
<code>{block.text}</code>
|
||||
</pre>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** MdxTableOfContents — original module 78825 (2xl-only fixed left nav). */
|
||||
function MdxTableOfContents() {
|
||||
const [headings, setHeadings] = useState<
|
||||
{ id: string; label: string; level: number }[]
|
||||
>([]);
|
||||
const [active, setActive] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const collect = () => {
|
||||
const article = document.querySelector("article[data-mdx-article]");
|
||||
if (!(article instanceof HTMLElement)) {
|
||||
setHeadings([]);
|
||||
return;
|
||||
}
|
||||
const els = article.querySelectorAll("h1, h2, h3");
|
||||
const next: { id: string; label: string; level: number }[] = [];
|
||||
els.forEach((el) => {
|
||||
if (!(el instanceof HTMLElement)) return;
|
||||
const tag = el.tagName.toLowerCase();
|
||||
if (tag !== "h1" && tag !== "h2" && tag !== "h3") return;
|
||||
const id = el.id;
|
||||
if (!id) return;
|
||||
const level = Number(tag.slice(1));
|
||||
// Label = textContent minus aria-hidden spans (the "#" anchor).
|
||||
const clone = el.cloneNode(true) as HTMLElement;
|
||||
clone
|
||||
.querySelectorAll('span[aria-hidden="true"]')
|
||||
.forEach((s) => s.remove());
|
||||
const label = (clone.textContent ?? "").replace(/\s+/g, " ").trim();
|
||||
next.push({ id, label, level });
|
||||
});
|
||||
setHeadings(next);
|
||||
};
|
||||
collect();
|
||||
const t1 = window.setTimeout(collect, 0);
|
||||
const t2 = window.setTimeout(collect, 150);
|
||||
return () => {
|
||||
window.clearTimeout(t1);
|
||||
window.clearTimeout(t2);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (headings.length === 0) {
|
||||
setActive(null);
|
||||
return;
|
||||
}
|
||||
const update = () => {
|
||||
const els = headings
|
||||
.map((h) => document.getElementById(h.id))
|
||||
.filter((el): el is HTMLElement => el !== null);
|
||||
if (els.length === 0) return;
|
||||
let current = els[0];
|
||||
for (const el of els) {
|
||||
if (el.getBoundingClientRect().top <= MDX_HEADING_ANCHOR_OFFSET_PX)
|
||||
current = el;
|
||||
}
|
||||
setActive(current.id || headings[0].id);
|
||||
};
|
||||
update();
|
||||
window.addEventListener("scroll", update, { passive: true });
|
||||
window.addEventListener("resize", update);
|
||||
const article = document.querySelector<HTMLElement>(
|
||||
"article[data-mdx-article]"
|
||||
);
|
||||
const ro =
|
||||
"undefined" !== typeof ResizeObserver && article
|
||||
? new ResizeObserver(update)
|
||||
: null;
|
||||
if (article) ro?.observe(article);
|
||||
const t = window.setTimeout(update, 100);
|
||||
return () => {
|
||||
window.removeEventListener("scroll", update);
|
||||
window.removeEventListener("resize", update);
|
||||
ro?.disconnect();
|
||||
window.clearTimeout(t);
|
||||
};
|
||||
}, [headings]);
|
||||
|
||||
if (headings.length === 0) return null;
|
||||
return (
|
||||
<nav
|
||||
aria-label="本页目录"
|
||||
className="pointer-events-auto fixed inset-y-0 left-0 z-20 hidden min-h-0 w-[320px] flex-col overflow-hidden 2xl:flex pl-14 pr-2"
|
||||
>
|
||||
<div className="flex flex-col flex-1 min-h-0 overflow-hidden">
|
||||
<div className="flex-1 min-h-0 overflow-y-auto overscroll-y-contain no-scrollbar">
|
||||
<div className="box-border flex min-h-full flex-col py-7">
|
||||
<div className="flex min-h-0 flex-1 flex-col justify-center gap-1 p-2 text-sm leading-snug text-l2">
|
||||
{headings.map((h, i) => {
|
||||
const pad = h.level === 1 ? 0 : h.level === 2 ? 8 : 16;
|
||||
const href = `#${encodeURIComponent(h.id)}`;
|
||||
return (
|
||||
<a
|
||||
key={`${h.id}-${i}`}
|
||||
href={href}
|
||||
title={h.label}
|
||||
aria-current={h.id === active ? "location" : undefined}
|
||||
className={`block min-w-0 shrink-0 cursor-pointer truncate rounded-md py-0.5 transition-colors hover:text-l1 ${h.id === active ? "text-l1" : "text-l2"}`}
|
||||
style={{ paddingLeft: `${pad}px` }}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
setActive(h.id);
|
||||
const el = document.getElementById(h.id);
|
||||
if (el) scrollToMdxAnchorTarget(el);
|
||||
history.replaceState(null, "", href);
|
||||
}}
|
||||
>
|
||||
{h.label}
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
/** Original ArticleFooter (module 54450). */
|
||||
function ArticleFooter({ updated }: { updated: string }) {
|
||||
const pathname = usePathname();
|
||||
const { startNavigation } = useRouteTransitionController();
|
||||
const [viewport, setViewport] = useState({ w: 0, h: 0 });
|
||||
const [charCount, setCharCount] = useState<number | null>(null);
|
||||
const footerRef = useCallback((el: HTMLElement | null) => {
|
||||
if (!el) return;
|
||||
const article = el.closest("[data-mdx-article]");
|
||||
if (article instanceof HTMLElement) {
|
||||
const clone = article.cloneNode(true) as HTMLElement;
|
||||
clone.querySelector("[data-mdx-footer]")?.remove();
|
||||
setCharCount([...(clone.textContent ?? "").trim()].length);
|
||||
}
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
const update = () =>
|
||||
setViewport({ w: window.innerWidth, h: window.innerHeight });
|
||||
update();
|
||||
window.addEventListener("resize", update);
|
||||
return () => window.removeEventListener("resize", update);
|
||||
}, []);
|
||||
const goAnchor = useCallback(
|
||||
(anchor: string) => {
|
||||
if (pathname === "/") scrollEnv.lenisScrollTo(anchor, { lerp: 0.1 });
|
||||
else {
|
||||
sessionStorage.setItem(PENDING_SCROLL_ANCHOR_SESSION_KEY, anchor);
|
||||
startNavigation("/");
|
||||
}
|
||||
},
|
||||
[pathname, startNavigation]
|
||||
);
|
||||
const dotted =
|
||||
"block before:absolute relative before:inset-0 before:border-2 before:border-dotted before:border-transparent before:pointer-events-none before:transition-colors before:duration-200 lg:hover:before:border-l1 inline-block -mx-1 px-1 py-0.5 text-l2 lg:hover:text-l1 text-sm transition-colors";
|
||||
return (
|
||||
<footer
|
||||
ref={footerRef}
|
||||
data-mdx-footer="true"
|
||||
className="bg-[rgba(var(--label-d),0.03)] mt-16 p-4 lg:p-6 rounded-xl"
|
||||
>
|
||||
<div className="mb-5 font-sans font-semibold text-l1 text-base">
|
||||
Metadata
|
||||
</div>
|
||||
<dl className="gap-x-6 gap-y-6 grid grid-cols-2 lg:grid-cols-3">
|
||||
{(
|
||||
[
|
||||
["Last Updated", updated],
|
||||
["Dimensions", `${viewport.w}×${viewport.h}`],
|
||||
[
|
||||
"Characters",
|
||||
charCount !== null ? charCount.toLocaleString("en-US") : "—",
|
||||
],
|
||||
] as const
|
||||
).map(([label, value]) => (
|
||||
<div key={label} className="flex flex-col gap-1.5">
|
||||
<dt className="font-sans font-semibold text-l1 text-sm">{label}</dt>
|
||||
<dd>
|
||||
<ScrambleReveal
|
||||
text={value}
|
||||
className="font-mono tabular-nums text-l2 text-sm"
|
||||
startDelayMs={300}
|
||||
scrambleColors={false}
|
||||
/>
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
<div className="my-6 border-line border-t border-dashed" />
|
||||
<div className="gap-x-6 gap-y-4 grid grid-cols-2 lg:grid-cols-3">
|
||||
<div className="hidden lg:block font-sans font-semibold text-l1 text-sm">
|
||||
Links
|
||||
</div>
|
||||
<div className="flex flex-col items-start gap-1 font-mono">
|
||||
<Link href="/" className={`${dotted} text-left`}>
|
||||
<ScrambleReveal text="Home" startDelayMs={300} scrambleColors={false} />
|
||||
</Link>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => goAnchor("#selected-work")}
|
||||
className={`${dotted} text-left cursor-pointer`}
|
||||
>
|
||||
<ScrambleReveal text="Work" startDelayMs={300} scrambleColors={false} />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => goAnchor("#contact")}
|
||||
className={`${dotted} text-left cursor-pointer`}
|
||||
>
|
||||
<ScrambleReveal text="Contact" startDelayMs={300} scrambleColors={false} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex flex-col items-start gap-1 font-mono">
|
||||
{["Twitter/X", "Figma", "GitHub"].map((label) => (
|
||||
<a key={label} href="#" className={dotted}>
|
||||
<ScrambleReveal text={label} startDelayMs={300} scrambleColors={false} />
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
|
||||
function Article({ slug }: { slug: string }) {
|
||||
const article = WORK_ARTICLES[slug];
|
||||
if (!article) {
|
||||
return (
|
||||
<>
|
||||
<article className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px] text-l1">
|
||||
<header className="pt-[10vh]">
|
||||
<h1 className="font-bold text-3xl! text-l1 lg:text-5xl! leading-tight tracking-tight">
|
||||
@@ -141,21 +544,20 @@ function Article({ slug }: { slug: string }) {
|
||||
</p>
|
||||
</header>
|
||||
</article>
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{/* The window (Lenis) is the scroller — the original nests its own
|
||||
overflow container per route because its Lenis wraps <main>; our
|
||||
Lenis is window-level, so a nested overflow div would swallow the
|
||||
wheel and kill scrolling. */}
|
||||
<MdxTableOfContents />
|
||||
<article
|
||||
data-mdx-article="true"
|
||||
className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px] text-l1"
|
||||
>
|
||||
<header className="pt-[10vh]">
|
||||
<h1 className="font-bold text-3xl! text-l1 lg:text-5xl! leading-tight tracking-tight" style={{ fontVariationSettings: '"wdth" 120' }}>
|
||||
<h1
|
||||
className="font-bold text-3xl! text-l1 lg:text-5xl! leading-tight tracking-tight"
|
||||
style={{ fontVariationSettings: '"wdth" 120' }}
|
||||
>
|
||||
{article.title}
|
||||
</h1>
|
||||
<p className="mt-1 tabular-nums text-l2! text-sm! lg:text-base! leading-relaxed">
|
||||
@@ -181,66 +583,12 @@ function Article({ slug }: { slug: string }) {
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{article.meta && (
|
||||
<footer
|
||||
data-mdx-footer="true"
|
||||
className="bg-[rgba(var(--label-d),0.03)] mt-16 p-4 lg:p-6 rounded-xl"
|
||||
>
|
||||
<div className="mb-5 font-sans font-semibold text-l1 text-base">
|
||||
Metadata
|
||||
</div>
|
||||
<dl className="gap-x-6 gap-y-6 grid grid-cols-2 lg:grid-cols-3">
|
||||
{article.meta.map(([dt, dd]) => (
|
||||
<div key={dt} className="flex flex-col gap-1.5">
|
||||
<dt className="font-sans font-semibold text-l1 text-sm">{dt}</dt>
|
||||
<dd>
|
||||
<span className="font-mono tabular-nums text-l2 text-sm">{dd}</span>
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
<div className="my-6 border-line border-t border-dashed" />
|
||||
<div className="gap-x-6 gap-y-4 grid grid-cols-2 lg:grid-cols-3">
|
||||
<div className="hidden lg:block font-sans font-semibold text-l1 text-sm">
|
||||
Links
|
||||
</div>
|
||||
<div className="flex flex-col items-start gap-1 font-mono">
|
||||
<DetailNavLink href="/">Home</DetailNavLink>
|
||||
<DetailNavLink href="/">Work</DetailNavLink>
|
||||
<DetailNavLink href="/">Contact</DetailNavLink>
|
||||
</div>
|
||||
<div className="flex flex-col items-start gap-1 font-mono">
|
||||
{["Twitter/X", "Figma", "GitHub"].map((label) => (
|
||||
<a
|
||||
key={label}
|
||||
href="#"
|
||||
className="relative before:content-[''] before:absolute before:inset-0 before:border-2 before:border-dotted before:border-transparent before:pointer-events-none before:transition-colors before:duration-200 lg:hover:before:border-l1 inline-block -mx-1 px-1 py-0.5 text-l2 lg:hover:text-l1 text-sm transition-colors"
|
||||
>
|
||||
{label}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
)}
|
||||
<ArticleFooter updated={article.date} />
|
||||
</article>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function DetailNavLink({ href, children }: { href: string; children: string }) {
|
||||
const { startNavigation } = useRouteTransitionController();
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => startNavigation(href)}
|
||||
className="relative before:content-[''] before:absolute before:inset-0 before:border-2 before:border-dotted before:border-transparent before:pointer-events-none before:transition-colors before:duration-200 lg:hover:before:border-l1 inline-block -mx-1 px-1 py-0.5 text-l2 lg:hover:text-l1 text-sm transition-colors text-left cursor-pointer"
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function WorkDetailInner() {
|
||||
const params = useParams<{ slug: string }>();
|
||||
const raw = String(params?.slug ?? "");
|
||||
|
||||
@@ -122,12 +122,14 @@ export function HeroScene() {
|
||||
if (!home) return null;
|
||||
|
||||
return (
|
||||
// 1:1 original stacking: z-auto fixed host BEFORE the grid/main in DOM.
|
||||
// The z-20 BackgroundGrid (rendered after this element) paints above the
|
||||
// canvas with mix-blend-difference — same as the original site.
|
||||
// 1:1 original stacking (chunk 4d3f3b68): the WebGL host is
|
||||
// "top-0 left-0 -z-1 fixed w-full h-dvh lg:h-screen" — a NEGATIVE
|
||||
// z-index, so every in-flow text/section paints ABOVE the scene. A
|
||||
// z-auto fixed host would paint above normal-flow content (CSS paint
|
||||
// order) and hide the banner copy + work captions.
|
||||
<div
|
||||
ref={hostRef}
|
||||
className="fixed inset-0 w-full h-full pointer-events-none"
|
||||
className="top-0 left-0 -z-1 fixed w-full h-dvh lg:h-screen pointer-events-none"
|
||||
>
|
||||
<Canvas
|
||||
dpr={[1, 2]}
|
||||
|
||||
@@ -86,6 +86,13 @@ export default function BackgroundGrid() {
|
||||
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 (
|
||||
|
||||
@@ -35,7 +35,7 @@ export default function FooterSection() {
|
||||
<footer
|
||||
id="contact"
|
||||
data-section="footer"
|
||||
className="relative flex flex-col justify-center p-6 lg:p-16 w-full h-dvh lg:h-screen pointer-events-none"
|
||||
className="z-10 relative flex flex-col justify-center p-6 lg:p-16 w-full h-dvh lg:h-screen pointer-events-none"
|
||||
>
|
||||
<div
|
||||
className="gap-2 grid grid-cols-12 font-bold text-[7.2svw] lg:text-[6svw] 2xl:text-[5svw] xl:text-[5.6svw] uppercase leading-none"
|
||||
|
||||
@@ -56,6 +56,22 @@ export default function SmoothScroller() {
|
||||
requestAnimationFrame(() => window.scrollTo(0, 0));
|
||||
};
|
||||
resetScroll();
|
||||
|
||||
// Pending anchor from a detail page (original module 54450: the
|
||||
// footer "Work"/"Contact" buttons store the anchor in sessionStorage
|
||||
// and navigate "/" through the transition; the home scroller then
|
||||
// smooth-scrolls to it).
|
||||
const pendingAnchor = sessionStorage.getItem('hq:pendingScrollAnchor');
|
||||
if (pendingAnchor) {
|
||||
sessionStorage.removeItem('hq:pendingScrollAnchor');
|
||||
const target = document.querySelector(pendingAnchor);
|
||||
if (target) {
|
||||
requestAnimationFrame(() => requestAnimationFrame(() => {
|
||||
lenis.scrollTo(target as HTMLElement, { lerp: 0.1 });
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
const onPageShow = (e: PageTransitionEvent) => {
|
||||
if (e.persisted) resetScroll();
|
||||
};
|
||||
|
||||
+94
-85
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user