"use client"; /** * Work detail pages — 1:1 port of the original MDX detail route * (haoqi.design/reunimos et al.), including: * * - 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, useCallback, useEffect, useState } from "react"; import Link from "next/link"; import { useParams, usePathname } from "next/navigation"; import { WORK_ARTICLES, type ArticleBlock, type InlineSeg, } from "@/content/workArticles"; import { usePasscodeAllowed } from "@/components/dom/PasscodeAccess"; import { PasscodeUnlockScreen } from "@/components/dom/PasscodeUnlockScreen"; import { useRouteTransitionController } from "@/lib/routeTransition"; import { scrollEnv } from "@/lib/scrollEnv"; import ScrambleReveal from "@/components/dom/ScrambleReveal"; import CustomScrollbar from "@/components/dom/CustomScrollbar"; import { PENDING_SCROLL_ANCHOR_SESSION_KEY } from "@/lib/scrollEnv"; export { PENDING_SCROLL_ANCHOR_SESSION_KEY }; 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) => { 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": return (

); case "h2": return ; case "h3": 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 ( ); case "hr": return
; case "list": return block.ordered ? (
    {block.items.map((li, i) => (
  1. ))}
) : (
    {block.items.map((li, i) => (
  • ))}
); case "quote": return (

); 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 (
元信息
{( [ ["最后更新", updated], ["视口尺寸", `${viewport.w}×${viewport.h}`], [ "字数", charCount !== null ? charCount.toLocaleString("zh-CN") : "—", ], ] as const ).map(([label, value]) => (
{label}
))}
链接
{["抖音", "微信", "小红书"].map((label) => ( ))}
); } function Article({ slug }: { slug: string }) { const article = WORK_ARTICLES[slug]; if (!article) { return (

404

该作品的文章尚未完成。

← 返回首页

); } return ( <>

{article.title}

{article.date}

{article.year}

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