diff --git a/app/globals.css b/app/globals.css index 625e911..98d9f49 100644 --- a/app/globals.css +++ b/app/globals.css @@ -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; diff --git a/app/work/[slug]/page.tsx b/app/work/[slug]/page.tsx index e71e8c9..d36a227 100644 --- a/app/work/[slug]/page.tsx +++ b/app/work/[slug]/page.tsx @@ -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: * - *
- *
- *
- *
h1 + date + hr + year
- *
blocks
- *
- * - * 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 = { + 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 ? ( + + + {text} + + ) : ( + text + ); + return ( + + {inner} + + ); +} + +/** Inline segment renderer (MdxA class for links). */ function Inline({ segs }: { segs: InlineSeg[] }) { return ( <> - {segs.map((s, i) => - s.t === "link" ? ( - - {s.v} - - ) : ( - {s.v} - ) - )} + {segs.map((s, i) => { + switch (s.t) { + case "link": + return ( + + {s.v} + + ); + case "code": + return ( + + {s.v} + + ); + case "strong": + return ( + + {s.v} + + ); + case "em": + return {s.v}; + default: + return {s.v}; + } + })} ); } +/** 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 ( +
+
+ + {label} + + +
+
+        
+      
+
+ ); +} + function Block({ block }: { block: ArticleBlock }) { switch (block.type) { case "p": @@ -64,9 +242,20 @@ function Block({ block }: { block: ArticleBlock }) {

); case "h2": - return

{block.text}

; + return ; case "h3": - return

{block.text}

; + return ; + case "h4": + return ; + case "code": + return ( + + ); case "img": // eslint-disable-next-line @next/next/no-img-element -- original uses plain img with cursor-zoom-in return ( @@ -102,145 +291,304 @@ function Block({ block }: { block: ArticleBlock }) { case "quote": return (
- {block.items.map((q, i) => ( -

- {q} -

- ))} +

+ +

); - case "code": - return ( -
-          {block.text}
-        
- ); 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(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( + "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 ( + + ); +} + +/** 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(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 ( +
+
+ Metadata +
+
+ {( + [ + ["Last Updated", updated], + ["Dimensions", `${viewport.w}×${viewport.h}`], + [ + "Characters", + charCount !== null ? charCount.toLocaleString("en-US") : "—", + ], + ] as const + ).map(([label, value]) => ( +
+
{label}
+
+ +
+
+ ))} +
+
+
+
+ Links +
+
+ + + + + +
+
+ {["Twitter/X", "Figma", "GitHub"].map((label) => ( + + + + ))} +
+
+
+ ); +} + function Article({ slug }: { slug: string }) { const article = WORK_ARTICLES[slug]; if (!article) { return ( - <> -
-
-

- 404 -

-

- No article for this work yet. -

-
-

- - ← Home - -

-
-
- +
+
+

+ 404 +

+

+ No article for this work yet. +

+
+

+ + ← Home + +

+
+
); } return ( <> - {/* The window (Lenis) is the scroller — the original nests its own - overflow container per route because its Lenis wraps
; our - Lenis is window-level, so a nested overflow div would swallow the - wheel and kill scrolling. */} +
-
-

- {article.title} -

-

- {article.date} -

-
-

- {article.year} -

-
-
- {article.blocks.map((b, i) => ( - - ))} - {article.iframe && ( -