diff --git a/app/globals.css b/app/globals.css index 98d9f49..c16b561 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1,34 +1,40 @@ @import "tailwindcss"; +/* Theme color indirection: utilities (text-l1, bg-b1, …) reference these + tokens, and the .dark block (below) flips their values — the same + light/dark token pairs the original stylesheet emits. */ @theme { --font-sans: var(--font-tiktok), sans-serif; --font-mono: var(--font-mono), monospace; --font-mono-2: var(--font-mono-2), monospace; - - --color-l1: rgba(0, 0, 0, 1); - --color-l2: rgba(54, 54, 48, 0.6); - --color-l3: rgba(54, 54, 48, 0.32); - --color-line: rgba(54, 54, 48, 0.1); - --color-b1: rgb(251, 250, 244); - --color-be: #efede7; + + --color-l1: var(--label-1); + --color-l2: var(--label-2); + --color-l3: var(--label-3); + --color-line: var(--line); + --color-b1: rgb(var(--background-deep)); + --color-be: var(--background-elevated); --color-selection: #c0fe04; } :root { - --bg-color: rgb(251, 250, 244); - --text-color: rgba(0, 0, 0, 1); - --grid-dot: rgba(54, 54, 48, 0.1); + --bg-color: rgb(var(--background-deep)); + --text-color: var(--label-1); + --grid-dot: var(--line); --selection-bg: #c0fe04; - /* Original label tokens (light theme): --label-1 = primary label, - --label-3 = tertiary label (link underline decoration color). */ + /* Light theme tokens (chunk 635eb04122aa774f.css :root). */ --label: 0, 0, 0; --label-d: 54, 54, 48; + --background-deep: 251, 250, 244; + --background-elevated: #efede7; --label-1: rgba(var(--label), 1); + --label-2: rgba(var(--label-d), 0.6); --label-3: rgba(var(--label-d), 0.32); + --label-4: rgba(var(--label-d), 0.18); + --line: rgba(var(--label-d), 0.1); - /* Original code token colors (light theme, chunk 635eb04122aa774f.css) — - the MDX CodeBlock maps prism token types to these vars. */ + /* Original code token colors (light theme). */ --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); @@ -38,6 +44,30 @@ --code-operator: rgba(var(--label-d), 0.75); } +/* Dark theme (original .dark block: ThemeModeProvider adds the class to + ; localStorage "theme" ∈ light|dark|system, system follows + prefers-color-scheme). */ +.dark { + color-scheme: dark; + --label: 255, 255, 255; + --label-d: 230, 232, 232; + --background-deep: 15, 17, 17; + --background-elevated: #191b1b; + --label-1: rgba(var(--label), 1); + --label-2: rgba(var(--label-d), 0.6); + --label-3: rgba(var(--label-d), 0.32); + --label-4: rgba(var(--label-d), 0.16); + --line: rgba(var(--label-d), 0.08); + + --code-comment: rgba(var(--label-d), 0.5); + --code-string: lab(80.5863% -36.0539 14.2351); + --code-number: lab(81.7507% 5.58251 51.1676); + --code-keyword: lab(74.3615% 26.3244 -70.4223); + --code-function: lab(78.8788% -11.9607 -42.8116); + --code-tag: lab(76.4079% 47.9123 21.2271); + --code-operator: rgba(var(--label-d), 0.85); +} + /* 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 diff --git a/app/layout.tsx b/app/layout.tsx index 6541ee2..fadc7a0 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -31,7 +31,9 @@ const departureMono = localFont({ }); export const metadata: Metadata = { - title: "HAOQI©2026 - Clone", + // Original home title (index.html): HAOQI©2026. Detail pages override via + // generateMetadata in app/work/[slug]/layout.tsx (original: per-page title). + title: "HAOQI©2026", description: "Digital Product Designer & Builder © 2026", }; diff --git a/app/work/[slug]/layout.tsx b/app/work/[slug]/layout.tsx new file mode 100644 index 0000000..5bb6fc6 --- /dev/null +++ b/app/work/[slug]/layout.tsx @@ -0,0 +1,33 @@ +import type { Metadata } from "next"; +import { WORK_ARTICLES } from "@/content/workArticles"; +import { isPasscodeProtectedPath } from "@/lib/passcode"; +import { getPasscodeAccessServer } from "@/lib/passcodeServer"; + +/** + * Per-page : the original detail route sets <title> to the work name + * (haoqi.design/reunimos → "Reunimos™"). The protected /2026 is gated on the + * server — without the access cookie its SSR title is "Protected"; once + * unlocked the server renders the article. We mirror both states. Lives in a + * segment layout so `params` contains the slug for both /work/[slug] and its + * root rewrite. + */ +export async function generateMetadata({ + params, +}: { + params: Promise<{ slug: string }>; +}): Promise<Metadata> { + const { slug } = await params; + const path = `/${slug}`; + if (isPasscodeProtectedPath(path)) { + const access = await getPasscodeAccessServer(); + if (!access[path]) return { title: "Protected" }; + } + const article = WORK_ARTICLES[path]; + return { title: article ? article.title : "HAOQI©2026" }; +} + +export default function WorkLayout({ + children, +}: Readonly<{ children: React.ReactNode }>) { + return children; +} diff --git a/components/canvas/BackgroundFX.tsx b/components/canvas/BackgroundFX.tsx index 48ccf98..0fcc609 100644 --- a/components/canvas/BackgroundFX.tsx +++ b/components/canvas/BackgroundFX.tsx @@ -19,6 +19,7 @@ import { } from "three"; import { usePointer } from "@/lib/pointer"; import { scrollBus } from "@/lib/scrollBus"; +import { useResolvedTheme } from "@/lib/shellMedia"; /** * Animated background — 1:1 port of the original `sz` + `sV` + `s$` @@ -39,6 +40,11 @@ import { scrollBus } from "@/lib/scrollBus"; const BG_COLOR = "#ffead6"; const VIGNETTE_COLOR = "#6196ff"; const OUTPUT_COLOR = "#acffb9"; +// Dark branch (original sL/sH/s_ + sj.dark): deep blue bg, near-black +// vignette, teal output; stronger output mix, much stronger edge falloff. +const DARK_BG_COLOR = "#2c4bd5"; +const DARK_VIGNETTE_COLOR = "#00000d"; +const DARK_OUTPUT_COLOR = "#00344C"; const OUTPUT_MIX = 0.65; const MOUSE_POS = new Vector2(0.5, -0.1); const CENTER = new Vector2(0.5, 0.5); @@ -548,9 +554,32 @@ export function BackgroundFX() { [] ); - const bgColor = useMemo(() => toVec3(BG_COLOR), []); - const vignetteColor = useMemo(() => toVec3(VIGNETTE_COLOR), []); - const outputColor = useMemo(() => toVec3(OUTPUT_COLOR), []); + const isDark = useResolvedTheme() === "dark"; + // sj: light {outputMix:.65, edgeIntensity:-.16} / dark {outputMix:.95, + // edgeIntensity:-.82} — swapped on theme flip (original sz reads + // resolvedTheme and re-seeds the uniforms per branch). + const bgColor = useMemo(() => toVec3(isDark ? DARK_BG_COLOR : BG_COLOR), [isDark]); + const vignetteColor = useMemo( + () => toVec3(isDark ? DARK_VIGNETTE_COLOR : VIGNETTE_COLOR), + [isDark] + ); + const outputColor = useMemo( + () => toVec3(isDark ? DARK_OUTPUT_COLOR : OUTPUT_COLOR), + [isDark] + ); + + // sj dark branch values + clear color: keep the RT clear in sync so the + // first pre-pass composites over the right base after a theme flip. + useEffect(() => { + materials.outputMaterial.uniforms.uOutputMix.value = isDark ? 0.95 : 0.65; + materials.vignetteMaterial.uniforms.uEdgeIntensity.value = isDark + ? -0.82 + : -0.16; + gl.setClearColor(new Color(isDark ? DARK_BG_COLOR : BG_COLOR), 1); + gl.setRenderTarget(rtsRef.current.read); + gl.clear(); + gl.setRenderTarget(null); + }, [isDark, materials, gl]); // Internal ortho scene for pre-passes (original v/A + first-pass mesh). const preScene = useMemo(() => new Scene(), []); diff --git a/components/canvas/DotOverlay.tsx b/components/canvas/DotOverlay.tsx index 9512ebf..99138f2 100644 --- a/components/canvas/DotOverlay.tsx +++ b/components/canvas/DotOverlay.tsx @@ -4,6 +4,7 @@ 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 @@ -30,8 +31,8 @@ function sT(e?: number): number { } export function DotOverlay() { - // Light-only theme (original: resolvedTheme from useThemeMode). - const isDark = false; + // 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); diff --git a/components/canvas/GlassModels.tsx b/components/canvas/GlassModels.tsx index 83da644..5ebef4a 100644 --- a/components/canvas/GlassModels.tsx +++ b/components/canvas/GlassModels.tsx @@ -8,6 +8,7 @@ import { mergeGeometries } from "three/examples/jsm/utils/BufferGeometryUtils.js import { scrollBus } from "@/lib/scrollBus"; import { usePointer } from "@/lib/pointer"; import { loadingBus } from "@/lib/loadingBus"; +import { useResolvedTheme } from "@/lib/shellMedia"; /** * Glass models for the hero section, reverse-engineered 1:1 from the @@ -259,6 +260,25 @@ const LIGHT_PARAMS = { lightZ: 0.5, }; +// Dark-theme branch of the same cloned controls (original dark* control +// values): the glass switches to Hard-Light duotone mixing (uDark 1) with a +// different highlight/fresnel response. +const DARK_PARAMS = { + shininess: 100, + diffuseness: 0.05, + fresnelPower: 3, + fresnelStrength: 0.72, + brightness: 0.6, + contrast: 0.98, + gamma: 1, + saturation: 1.2, + tintMix: 1, + tintThicknessMinAlpha: 1, + tintThicknessMaxAlpha: 0.4, + tintColorA: "#64c3ff", + tintColorB: "#8e9dc4", +}; + // Default uniforms from the bundle's uniform factory const IOR = { R: 1.15, Y: 1.16, G: 1.18, C: 1.22, B: 1.22, P: 1.22 }; @@ -495,6 +515,35 @@ function GlassModel({ uniforms.uTintLocalYRange.value.set(tintYRange[0], tintYRange[1]); }, [tintYRange, uniforms]); + // Theme branch (original cf(controls, theme) + E useMemo): swap the + // highlight/fresnel response and tint colors when the resolved theme + // flips. Per-model tingColor overrides: m[0]/m[1] light A/B, + // m[2]/m[3] dark A/B, missing entries fall back to the theme defaults. + const isDark = useResolvedTheme() === "dark"; + useEffect(() => { + const P = isDark ? DARK_PARAMS : LIGHT_PARAMS; + uniforms.uShininess.value = P.shininess; + uniforms.uDiffuseness.value = P.diffuseness; + uniforms.uFresnelPower.value = P.fresnelPower; + uniforms.uFresnelStrength.value = P.fresnelStrength; + uniforms.uBrightness.value = P.brightness; + uniforms.uContrast.value = P.contrast; + uniforms.uGamma.value = P.gamma; + uniforms.uSaturation.value = P.saturation; + uniforms.uTintMix.value = P.tintMix; + uniforms.uTintThicknessMinAlpha.value = P.tintThicknessMinAlpha; + uniforms.uTintThicknessMaxAlpha.value = P.tintThicknessMaxAlpha; + const tintA = isDark + ? (tintColors?.[2] ?? DARK_PARAMS.tintColorA) + : (tintColors?.[0] ?? LIGHT_PARAMS.tintColorA); + const tintB = isDark + ? (tintColors?.[3] ?? DARK_PARAMS.tintColorB) + : (tintColors?.[1] ?? LIGHT_PARAMS.tintColorB); + uniforms.uTintColorA.value.copy(hexToVec4(tintA)); + uniforms.uTintColorB.value.copy(hexToVec4(tintB)); + uniforms.uDark.value = isDark ? 1 : 0; + }, [isDark, tintColors, uniforms]); + useEffect(() => { const drawingBufferSize = gl.getDrawingBufferSize(new THREE.Vector2()); uniforms.uScreenResolutionPx.value.set( @@ -675,9 +724,9 @@ export function CursorStar({ isMobile = false }: { isMobile?: boolean }) { afterRotation={[0, 720, 0]} rotation={[0, 0, 0]} scale={0.1} - // Original tingColor light theme: tint A and B are BOTH #009dff - // (m[0]/m[1]); #64c3ff (m[2]/m[3]) is the dark-theme value. - tintColors={["#009dff", "#009dff"]} + // Original tingColor: light m[0]/m[1] both #009dff, dark m[2]/m[3] + // both #64c3ff. + tintColors={["#009dff", "#009dff", "#64c3ff", "#64c3ff"]} tintEnabled isMobile={isMobile} scrollSyncFactor={0.72} @@ -714,7 +763,7 @@ export function FooterModel() { beforeRotation={[-180, 0, 0]} rotation={[0, 0, 0]} scale={19} - tintColors={["#FFFFFF", "#009dff"]} + tintColors={["#FFFFFF", "#009dff", "#8e9dc4", "#64c3ff"]} tintEnabled sectionTopDocY={geom.top} sectionHeightPx={geom.height} diff --git a/components/canvas/LoadingCurtain.tsx b/components/canvas/LoadingCurtain.tsx index 816b90e..1aeff5d 100644 --- a/components/canvas/LoadingCurtain.tsx +++ b/components/canvas/LoadingCurtain.tsx @@ -6,6 +6,7 @@ import { Canvas, useFrame, useThree } from "@react-three/fiber"; import { Color, MathUtils, UnsignedByteType } from "three"; import { Effect, BlendFunction } from "postprocessing"; import { EffectComposer } from "@react-three/postprocessing"; +import { useResolvedTheme } from "@/lib/shellMedia"; import { customCubic } from "@/lib/customCubic"; /** @@ -253,8 +254,9 @@ function RadialHoleMask({ const { size } = useThree(); const invalidate = useThree((s) => s.invalidate); - // Light theme picks f[1] (#efede7). - const color = CURTAIN_COLORS[1]; + // Original f(p): dark picks f[0] (#191b1b), light picks f[1] (#efede7). + const isDark = useResolvedTheme() === "dark"; + const color = isDark ? CURTAIN_COLORS[0] : CURTAIN_COLORS[1]; const uniforms = useMemo( () => ({ diff --git a/content/workArticles.ts b/content/workArticles.ts index 99af93c..4bc6a32 100644 --- a/content/workArticles.ts +++ b/content/workArticles.ts @@ -273,4 +273,18 @@ export const WORK_ARTICLES: Record<string, WorkArticle> = { { type: "p", segs: [{ t: "link", v: "teambition.com", href: "https://www.teambition.com/" }] }, ], }, + // /2026 — the passcode-protected TikTok post. The original article body is + // server-gated behind the site's secret passcode and therefore unreadable; + // this is stand-in content in the same structure (swap in real copy if it + // ever becomes available). + "/2026": { + title: "TikTok", + date: "May 31, 2026", + year: "2022-2026", + iframe: null, + blocks: [ + { type: "p", segs: [{ t: "text", v: "This article is passcode-protected on the original site, so its content could not be cloned. What is known from the public bundle: it is a post dated 2022-2026 about design engineering and AI exploration work, protected behind the 4-digit passcode flow." }] }, + { type: "p", segs: [{ t: "text", v: "Everything around it — the card, the locked brand label, the unlock screen, and this route — is reproduced 1:1. Unlock with the clone's passcode (default 2026, override with PASSCODE_CODE) to read this page like on the original." }] }, + ], + }, }; diff --git a/lib/shellMedia.tsx b/lib/shellMedia.tsx index c48d4df..c2af72c 100644 --- a/lib/shellMedia.tsx +++ b/lib/shellMedia.tsx @@ -1,20 +1,76 @@ "use client"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useSyncExternalStore } from "react"; /** - * Shell media state (theme + sound) — mirrors the original useShellMedia / - * useThemeMode contract: theme ∈ {light, dark, system}, persisted to - * localStorage; soundEnabled persisted likewise (original keys - * "hq-theme" / "hq-sound"; namespaced here). The THEME cycle is - * light → dark → system, keyboard [L]/[D]/[A] shortcuts live in the - * header component (original ASCIIThemeToggle behavior). + * Shell media state (theme + sound) — 1:1 port of the original + * ThemeModeProvider (chunk 2689132c4e070b68.js module 90975) + ShellMedia + * sound store (module 23525): + * + * - theme ∈ {light, dark, system}, persisted to localStorage "theme" + * (original key, kept verbatim for parity); default "light". + * - resolvedTheme = theme === "system" + * ? (matchMedia("(prefers-color-scheme: dark)").matches ? dark : light) + * : theme; + * <html> gets BOTH the resolved class (light/dark) and the setting, so + * CSS tokens flip via the .dark block in globals.css. + * - "system" follows OS changes live (original matchMedia change listener). + * - soundEnabled persisted to localStorage "sound" ("on"/"off", original + * keys). + * + * Implemented as a module-singleton external store (useSyncExternalStore) + * instead of the original context: the header and the canvas components + * (DotOverlay, LoadingCurtain, GlassModels) live in different trees and the + * canvas reads theme without re-mounting. */ export type ThemeSetting = "light" | "dark" | "system"; +export type ResolvedTheme = "light" | "dark"; -const THEME_KEY = "vh-theme"; -const SOUND_KEY = "vh-sound"; +const THEME_KEY = "theme"; +const SOUND_KEY = "sound"; +const SETTINGS: ThemeSetting[] = ["light", "dark", "system"]; + +type ShellMediaState = { + theme: ThemeSetting; + resolvedTheme: ResolvedTheme; + soundEnabled: boolean; +}; + +let state: ShellMediaState = { + theme: "light", + resolvedTheme: "light", + soundEnabled: false, +}; + +const listeners = new Set<() => void>(); +let hydrated = false; +let mediaQuery: MediaQueryList | null = null; + +function emit() { + for (const l of listeners) l(); +} + +function setState(patch: Partial<ShellMediaState>) { + state = { ...state, ...patch }; + emit(); +} + +function resolve(theme: ThemeSetting): ResolvedTheme { + if (theme !== "system") return theme; + return window.matchMedia("(prefers-color-scheme: dark)").matches + ? "dark" + : "light"; +} + +/** Mirror the resolved theme onto <html> (original: classList + remove/add). */ +function applyDocument(theme: ThemeSetting) { + const el = document.documentElement; + const resolved = resolve(theme); + el.classList.remove("light", "dark"); + el.classList.add(resolved); + el.dataset.themeSetting = theme; +} function readStored(key: string): string | null { try { @@ -24,44 +80,95 @@ function readStored(key: string): string | null { } } -export function useShellMedia() { - const [theme, setThemeState] = useState<ThemeSetting>("light"); - const [soundEnabled, setSoundEnabledState] = useState(false); +function writeStored(key: string, value: string) { + try { + window.localStorage.setItem(key, value); + } catch {} +} - useEffect(() => { - const t = readStored(THEME_KEY); - if (t === "light" || t === "dark" || t === "system") setThemeState(t); - setSoundEnabledState(readStored(SOUND_KEY) === "1"); - }, []); +function hydrate() { + if (hydrated || typeof window === "undefined") return; + hydrated = true; + const stored = readStored(THEME_KEY); + const theme: ThemeSetting = SETTINGS.includes(stored as ThemeSetting) + ? (stored as ThemeSetting) + : "light"; + mediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); + mediaQuery.addEventListener("change", onSystemChange); + state = { ...state, theme, resolvedTheme: resolve(theme) }; + applyDocument(theme); + state = { + ...state, + soundEnabled: readStored(SOUND_KEY) === "on", + }; +} - // Theme is light-only in this port: system/dark resolve to light. - useEffect(() => { - document.documentElement.dataset.themeSetting = theme; - }, [theme]); +function onSystemChange() { + if (state.theme !== "system") return; + const resolved = resolve("system"); + applyDocument("system"); + setState({ resolvedTheme: resolved }); +} - const setTheme = useCallback((next: ThemeSetting) => { - setThemeState(next); - try { - window.localStorage.setItem(THEME_KEY, next); - } catch {} - }, []); +if (typeof window !== "undefined") { + // SSR-safe: hydrate on the first client access (module evaluation happens + // before first paint for the header, matching the original effect timing + // closely enough that no flash is observable). + hydrate(); +} - const setSoundEnabled = useCallback((next: boolean) => { - setSoundEnabledState(next); - try { - window.localStorage.setItem(SOUND_KEY, next ? "1" : "0"); - } catch {} - }, []); +function setTheme(next: ThemeSetting) { + writeStored(THEME_KEY, next); + applyDocument(next); + setState({ theme: next, resolvedTheme: resolve(next) }); +} - return { theme, setTheme, soundEnabled, setSoundEnabled }; +function setSoundEnabled(next: boolean) { + writeStored(SOUND_KEY, next ? "on" : "off"); + setState({ soundEnabled: next }); +} + +function subscribe(listener: () => void) { + listeners.add(listener); + return () => listeners.delete(listener); +} + +const getSnapshot = () => state; + +export function useShellMedia(): ShellMediaState & { + setTheme: (next: ThemeSetting) => void; + setSoundEnabled: (next: boolean) => void; +} { + const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot); + // Stable identity via module-level functions (no per-render closures). + return useSnapshotWithActions(snapshot); +} + +// Keep the actions on the same object shape as the original hook return. +function useSnapshotWithActions( + snapshot: ShellMediaState +): ShellMediaState & { + setTheme: (next: ThemeSetting) => void; + setSoundEnabled: (next: boolean) => void; +} { + return { + ...snapshot, + setTheme, + setSoundEnabled, + }; +} + +export function getResolvedTheme(): ResolvedTheme { + return state.resolvedTheme; +} + +export function subscribeShellMedia(listener: () => void) { + return subscribe(listener); +} + +export function useResolvedTheme(): ResolvedTheme { + const s = useShellMedia(); + return s.resolvedTheme; } export type ShellMedia = ReturnType<typeof useShellMedia>; - -let contextValue: ShellMedia | null = null; - -/** Module-singleton variant (no provider tree needed for this port). */ -export function useShellMediaSingleton(): ShellMedia { - const own = useShellMedia(); - return contextValue ?? own; -} diff --git a/next.config.ts b/next.config.ts index 3ea5534..e50a597 100644 --- a/next.config.ts +++ b/next.config.ts @@ -10,6 +10,8 @@ const WORK_SLUGS = [ "adrive", "shore_icon", "teambition", + // The passcode-protected TikTok post (original: haoqi.design/2026). + "2026", ]; const nextConfig: NextConfig = {