diff --git a/src/app/globals.css b/src/app/globals.css index 806dcb2..ccd1eb1 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -218,6 +218,32 @@ .animate-marquee { animation: marquee 32s linear infinite; } .animate-marquee-fast { animation: marquee 18s linear infinite; } .animate-marquee-rev { animation: marquee-rev 36s linear infinite; } +.marquee-container:hover .marquee-track, +.marquee-container:focus-within .marquee-track { animation-play-state: paused; } + +/* Crow silhouettes scatter once as each new 404 thought appears. */ +@keyframes crow-flight { + 0% { opacity: 0; transform: translate(0, 12px) scale(0.35); } + 18% { opacity: 1; } + 100% { opacity: 0; transform: translate(var(--crow-x), var(--crow-y)) rotate(var(--crow-turn)) scale(0.8); } +} +@keyframes crow-wings { + from { transform: scaleY(1) rotate(-6deg); } + to { transform: scaleY(0.35) rotate(6deg); } +} +@keyframes quote-materialize { + 0%, 25% { opacity: 0; filter: blur(4px); transform: translateY(5px); } + 100% { opacity: 1; filter: blur(0); transform: translateY(0); } +} +.crow-flight { color: hsl(var(--ink)); animation: crow-flight 1.2s ease-out both; } +.crow-wings { animation: crow-wings 0.16s ease-in-out 8 alternate; } +.quote-transition .quote-copy { animation: quote-materialize 1.1s ease-out both; } +html.safe-mode .crow-scatter { display: none; } +html.safe-mode .quote-copy { animation: none; } +@media (prefers-reduced-motion: reduce) { + .crow-scatter { display: none; } + .quote-transition .quote-copy { animation: none; } +} @keyframes glitch-layer { 0%, 86%, 95%, 100% { clip-path: inset(0 0 100% 0); transform: translate(0); } diff --git a/src/components/cyber/__tests__/marquee.test.tsx b/src/components/cyber/__tests__/marquee.test.tsx new file mode 100644 index 0000000..28bf2c1 --- /dev/null +++ b/src/components/cyber/__tests__/marquee.test.tsx @@ -0,0 +1,26 @@ +import { act, render } from '@testing-library/react'; +import { Marquee } from '../primitives'; + +test('maintains a steady pixel speed as the strip grows and disconnects its observer', () => { + let measure: () => void = () => {}; + const disconnect = jest.fn(); + const original = global.ResizeObserver; + global.ResizeObserver = jest.fn().mockImplementation((callback) => { + measure = callback; + return { observe: jest.fn(), disconnect }; + }); + const width = jest.spyOn(HTMLElement.prototype, 'scrollWidth', 'get').mockReturnValue(960); + try { + const view = render(); + const track = view.container.querySelector('.marquee-track') as HTMLElement; + expect(track.style.animationDuration).toBe('20s'); + width.mockReturnValue(1920); + act(() => measure()); + expect(track.style.animationDuration).toBe('40s'); + view.unmount(); + expect(disconnect).toHaveBeenCalledTimes(1); + } finally { + width.mockRestore(); + global.ResizeObserver = original; + } +}); diff --git a/src/components/cyber/__tests__/not-found-screen.test.tsx b/src/components/cyber/__tests__/not-found-screen.test.tsx new file mode 100644 index 0000000..eb6d2cd --- /dev/null +++ b/src/components/cyber/__tests__/not-found-screen.test.tsx @@ -0,0 +1,36 @@ +import { act, fireEvent, render, screen } from '@testing-library/react'; +import { NotFoundScreen } from '../not-found-screen'; +import { NOT_FOUND_QUOTES } from '@/lib/not-found-quotes'; + +jest.mock('next/dynamic', () => () => function Eye() { return
; }); + +describe('404 quote rotation', () => { + beforeEach(() => { + sessionStorage.clear(); + jest.useFakeTimers(); + jest.setSystemTime(new Date('2026-10-07T13:00:00Z')); + }); + afterEach(() => jest.useRealTimers()); + + it('rotates on schedule, keeps the refresh cadence, and clears its timer on unmount', () => { + const first = render(); + act(() => jest.advanceTimersByTime(17000)); + expect(screen.getByRole('blockquote')).toHaveTextContent(NOT_FOUND_QUOTES[1]); + first.unmount(); + expect(jest.getTimerCount()).toBe(0); + const refreshed = render(); + expect(screen.getByRole('blockquote')).toHaveTextContent(NOT_FOUND_QUOTES[1]); + act(() => jest.advanceTimersByTime(3000)); + expect(screen.getByRole('blockquote')).toHaveTextContent(NOT_FOUND_QUOTES[2]); + refreshed.unmount(); + }); + + it('lets readers pause and resume the changing quotes', () => { + render(); + fireEvent.click(screen.getByRole('button', { name: 'Pause quotes' })); + act(() => jest.advanceTimersByTime(30000)); + expect(screen.getByRole('blockquote')).toHaveTextContent(NOT_FOUND_QUOTES[0]); + fireEvent.click(screen.getByRole('button', { name: 'Resume quotes' })); + expect(screen.getByRole('blockquote')).toHaveTextContent(NOT_FOUND_QUOTES[3]); + }); +}); diff --git a/src/components/cyber/crow-scatter.tsx b/src/components/cyber/crow-scatter.tsx new file mode 100644 index 0000000..f200275 --- /dev/null +++ b/src/components/cyber/crow-scatter.tsx @@ -0,0 +1,26 @@ +import type { CSSProperties } from 'react'; + +// Original vector silhouettes, inspired by Itachi's crow-scattering illusion. +// Reference: https://tenor.com/view/sharingan-genjutsu-itachi-crow-corvos-gif-19016658 +export function CrowScatter() { + return
+ {Array.from({ length: 18 }, (_, index) => { + const angle = (index / 18) * Math.PI * 2; + const radius = 100 + (index % 4) * 35; + const style = { + left: `${20 + (index % 6) * 11}%`, + top: `${25 + (index % 3) * 20}%`, + '--crow-x': `${Math.cos(angle) * radius}px`, + '--crow-y': `${Math.sin(angle) * radius - 35}px`, + '--crow-turn': `${Math.cos(angle) * 35}deg`, + animationDelay: `${(index % 5) * 35}ms`, + } as CSSProperties; + return + + + + + ; + })} +
; +} diff --git a/src/components/cyber/not-found-screen.tsx b/src/components/cyber/not-found-screen.tsx index 9d80ab4..8f11cf4 100644 --- a/src/components/cyber/not-found-screen.tsx +++ b/src/components/cyber/not-found-screen.tsx @@ -2,31 +2,48 @@ import dynamic from 'next/dynamic'; import Link from 'next/link'; -import { useEffect, useRef, useState } from 'react'; -import { NOT_FOUND_QUOTES, takeNotFoundQuote } from '@/lib/not-found-quotes'; +import { useEffect, useState } from 'react'; +import { NOT_FOUND_QUOTES, getQuoteClock, quoteIndexAt, QUOTE_INTERVAL_MS } from '@/lib/not-found-quotes'; +import { CrowScatter } from './crow-scatter'; const SharinganEye = dynamic(() => import('./sharingan').then((module) => module.SharinganEye), { ssr: false, loading: () =>
Opening eye…
, }); -// Also keeps rotation working when the browser blocks session storage. -let fallbackIndex = 0; +// In-memory continuity for browsers that block storage. +let fallbackAnchor: number | undefined; export function NotFoundScreen() { const [quoteIndex, setQuoteIndex] = useState(0); - const selected = useRef(false); + const [ready, setReady] = useState(false); + const [paused, setPaused] = useState(false); useEffect(() => { - if (selected.current) return; - selected.current = true; + if (paused) return; + const now = Date.now(); + let anchor: number; try { - setQuoteIndex(takeNotFoundQuote(window.sessionStorage)); + anchor = getQuoteClock(window.sessionStorage, now); } catch { - setQuoteIndex(fallbackIndex); - fallbackIndex = (fallbackIndex + 1) % NOT_FOUND_QUOTES.length; + fallbackAnchor ??= now; + anchor = fallbackAnchor; } - }, []); + let timer: ReturnType; + const update = () => { + clearTimeout(timer); + const current = Date.now(); + setQuoteIndex(quoteIndexAt(anchor, current)); + setReady(true); + timer = setTimeout(update, QUOTE_INTERVAL_MS - (Math.max(0, current - anchor) % QUOTE_INTERVAL_MS)); + }; + update(); + document.addEventListener('visibilitychange', update); + return () => { + clearTimeout(timer); + document.removeEventListener('visibilitychange', update); + }; + }, [paused]); return (
@@ -56,10 +73,16 @@ export function NotFoundScreen() {

Even this eye cannot locate your page.

-
-

Intercepted thought // {String(quoteIndex + 1).padStart(2, '0')} / 10

-
“{NOT_FOUND_QUOTES[quoteIndex]}”
-

Original words // another thought on your next visit

+
+

Intercepted thought // {String(quoteIndex + 1).padStart(2, '0')} / {NOT_FOUND_QUOTES.length}

+
+ {ready && } +
“{NOT_FOUND_QUOTES[quoteIndex]}”
+
+

Original words // new thought every 10 seconds

+
diff --git a/src/components/cyber/primitives.tsx b/src/components/cyber/primitives.tsx index b4b5bd8..796023d 100644 --- a/src/components/cyber/primitives.tsx +++ b/src/components/cyber/primitives.tsx @@ -124,17 +124,30 @@ export function Marquee({ itemClassName, reverse = false, separator = '•', + pixelsPerSecond, }: { items: string[]; className?: string; itemClassName?: string; reverse?: boolean; separator?: ReactNode; + pixelsPerSecond?: number; }) { + const trackRef = useRef(null); + const [duration, setDuration] = useState(null); + useEffect(() => { + const track = trackRef.current; + if (!track || !pixelsPerSecond || pixelsPerSecond <= 0) return; + const measure = () => setDuration(track.scrollWidth / 2 / pixelsPerSecond); + measure(); + const observer = new ResizeObserver(measure); + observer.observe(track); + return () => observer.disconnect(); + }, [pixelsPerSecond, items]); const list = [...items, ...items]; return ( -
-
+
+
{list.map((item, i) => ( {item} diff --git a/src/components/sections/__tests__/certificate-list.test.tsx b/src/components/sections/__tests__/certificate-list.test.tsx new file mode 100644 index 0000000..6e04498 --- /dev/null +++ b/src/components/sections/__tests__/certificate-list.test.tsx @@ -0,0 +1,27 @@ +import { render, screen } from '@testing-library/react'; +import type { ReactNode } from 'react'; +import { CertificateList } from '../certificate-list'; + +jest.mock('@/components/cyber/primitives', () => ({ + Reveal: ({ children }: { children: ReactNode }) =>
  • {children}
  • , +})); + +test('shows four certificates and preserves the rest behind a native disclosure', () => { + const certificates = Array.from({ length: 9 }, (_, i) => ({ name: `Certificate ${i + 1}`, issuer: 'Issuer', year: 2026, url: `https://example.com/${i}` })); + render(); + expect(screen.getByText('Certificate 1').closest('ul')?.children).toHaveLength(4); + expect(screen.getByText('Show all 9 certificates (+5)')).toBeVisible(); + expect(screen.getByText('Certificate 9')).not.toBeVisible(); + const details = screen.getByText('Certificate 9').closest('details')!; + details.open = true; + expect(screen.getByText('Certificate 9')).toBeVisible(); + expect(screen.getByRole('link', { name: /Certificate 9/ })).toHaveAttribute('href', 'https://example.com/8'); + details.open = false; + expect(screen.getByText('Certificate 1').closest('ul')?.children).toHaveLength(4); +}); + +test('does not add an unnecessary disclosure for a short list', () => { + render(); + expect(screen.getAllByRole('listitem')).toHaveLength(1); + expect(screen.queryByText(/Show all/)).not.toBeInTheDocument(); +}); diff --git a/src/components/sections/about.tsx b/src/components/sections/about.tsx index 27dbf56..9242bb9 100644 --- a/src/components/sections/about.tsx +++ b/src/components/sections/about.tsx @@ -1,3 +1,4 @@ +import { CertificateList, type Certificate } from './certificate-list'; import { Github, Linkedin, ArrowUpRight } from 'lucide-react'; import { Reveal, ScrambleText, TiltCard } from '@/components/cyber/primitives'; @@ -16,12 +17,7 @@ interface Education { duration: string; } -interface Certificate { - name: string; - issuer: string; - year: number; - url?: string | null; -} + export function AboutSection({ personalData, @@ -164,35 +160,7 @@ export function AboutSection({ {'// clearances'} 資格 -
      - {certificates.map((cert, i) => ( - - {(() => { - const body = ( - <> -
      -

      {cert.name}

      -

      - {cert.issuer} - {cert.url && ' · verify ↗'} -

      -
      - {cert.year} - - ); - const cls = - 'clip-notch-sm group relative flex items-center justify-between gap-4 bg-card px-4 py-3 transition-colors hover:bg-signal hover:text-ink'; - return cert.url ? ( - - {body} - - ) : ( -
      {body}
      - ); - })()} -
      - ))} -
    +
    )}
    diff --git a/src/components/sections/certificate-list.tsx b/src/components/sections/certificate-list.tsx new file mode 100644 index 0000000..dd5494f --- /dev/null +++ b/src/components/sections/certificate-list.tsx @@ -0,0 +1,42 @@ +import { Reveal } from '@/components/cyber/primitives'; + +export interface Certificate { + name: string; + issuer: string; + year: number; + url?: string | null; +} + +function CertificateCards({ certificates }: { certificates: Certificate[] }) { + return ( +
      + {certificates.map((cert, i) => { + const body = <> +
      +

      {cert.name}

      +

      {cert.issuer}{cert.url && ' · verify ↗'}

      +
      + {cert.year} + ; + const className = 'clip-notch-sm group relative flex items-center justify-between gap-4 bg-card px-4 py-3 transition-colors hover:bg-signal hover:text-ink'; + return + {cert.url ? {body} :
      {body}
      } +
      ; + })} +
    + ); +} + +export function CertificateList({ certificates }: { certificates: Certificate[] }) { + const limit = 4; + return <> + + {certificates.length > limit &&
    + + Show all {certificates.length} certificates (+{certificates.length - limit}) + Show fewer certificates + +
    +
    } + ; +} diff --git a/src/components/sections/skills.tsx b/src/components/sections/skills.tsx index 28f44f5..e124417 100644 --- a/src/components/sections/skills.tsx +++ b/src/components/sections/skills.tsx @@ -87,8 +87,8 @@ export function SkillsSection({ skills }: { skills: Skills | null }) { {all.length > 0 && (
    - - + + )} diff --git a/src/lib/__tests__/not-found-quotes.test.ts b/src/lib/__tests__/not-found-quotes.test.ts index 831702b..8381e84 100644 --- a/src/lib/__tests__/not-found-quotes.test.ts +++ b/src/lib/__tests__/not-found-quotes.test.ts @@ -1,16 +1,27 @@ -import { NOT_FOUND_QUOTES, NOT_FOUND_QUOTE_KEY, takeNotFoundQuote } from '../not-found-quotes'; +import { NOT_FOUND_QUOTES, NOT_FOUND_QUOTE_KEY, getQuoteClock, quoteIndexAt } from '../not-found-quotes'; -describe('lost-route quote rotation', () => { +describe('lost-route quote clock', () => { + const now = 1_790_000_000_000; beforeEach(() => sessionStorage.clear()); - it('cycles through ten distinct quotes and wraps on the next visit', () => { - expect(new Set(NOT_FOUND_QUOTES).size).toBe(10); - expect(Array.from({ length: 11 }, () => takeNotFoundQuote(sessionStorage))).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]); + it('has twenty distinct quotes and changes at ten-second boundaries', () => { + expect(new Set(NOT_FOUND_QUOTES).size).toBe(20); + expect(quoteIndexAt(now, now + 9999)).toBe(0); + expect(quoteIndexAt(now, now + 10000)).toBe(1); + expect(quoteIndexAt(now, now + 199999)).toBe(19); + expect(quoteIndexAt(now, now + 200000)).toBe(0); }); - it.each(['NaN', '-1', '10', '1.5', 'Infinity'])('recovers from an invalid saved index: %s', (value) => { + it('preserves the clock on refresh and catches up after an inactive tab', () => { + expect(getQuoteClock(sessionStorage, now)).toBe(now); + const anchor = getQuoteClock(sessionStorage, now + 17000); + expect(anchor).toBe(now); + expect(quoteIndexAt(anchor, now + 20000)).toBe(2); + expect(quoteIndexAt(anchor, now + 65000)).toBe(6); + }); + + it.each(['NaN', '-1', '0', '1.5', 'Infinity', String(now + 1)])('recovers from an invalid saved clock: %s', (value) => { sessionStorage.setItem(NOT_FOUND_QUOTE_KEY, value); - expect(takeNotFoundQuote(sessionStorage)).toBe(0); - expect(takeNotFoundQuote(sessionStorage)).toBe(1); + expect(getQuoteClock(sessionStorage, now)).toBe(now); }); }); diff --git a/src/lib/not-found-quotes.ts b/src/lib/not-found-quotes.ts index 34a8381..f53eeea 100644 --- a/src/lib/not-found-quotes.ts +++ b/src/lib/not-found-quotes.ts @@ -10,15 +10,30 @@ export const NOT_FOUND_QUOTES = [ 'Access denied is a boundary. Not found is a question.', 'The hardest truth: waiting will not create the missing page.', 'Lost is a location, not an identity.', + 'A perfect illusion still breaks when you ask the right question.', + 'The truth does not become kinder because you look away.', + 'Every mask hides a face. Every silence hides a story.', + 'You can patch a system. You must choose to change yourself.', + 'Some battles end only when you stop fighting your own reflection.', + 'No map can replace the courage to take the next step.', + 'The empty page cannot answer for the life you postponed.', + 'A crow leaves no footprints in the sky. Keep looking anyway.', + 'Knowing the vulnerability is not the same as fixing it.', + 'Even in the dark, you can decide which way to turn.', ] as const; -export const NOT_FOUND_QUOTE_KEY = 'nd-404-next-quote'; +export const NOT_FOUND_QUOTE_KEY = 'nd-404-quote-clock'; +export const QUOTE_INTERVAL_MS = 10_000; -/** Persist the next index, so reloads and return visits cycle without repeats. */ -export function takeNotFoundQuote(storage: Pick): number { +/** A persistent clock keeps the same ten-second cadence across refreshes. */ +export function getQuoteClock(storage: Pick, now: number): number { const value = storage.getItem(NOT_FOUND_QUOTE_KEY); - const parsed = value === null ? 0 : Number(value); - const index = Number.isInteger(parsed) && parsed >= 0 && parsed < NOT_FOUND_QUOTES.length ? parsed : 0; - storage.setItem(NOT_FOUND_QUOTE_KEY, String((index + 1) % NOT_FOUND_QUOTES.length)); - return index; + const saved = value === null ? NaN : Number(value); + if (Number.isSafeInteger(saved) && saved > 0 && saved <= now) return saved; + storage.setItem(NOT_FOUND_QUOTE_KEY, String(now)); + return now; +} + +export function quoteIndexAt(anchor: number, now: number): number { + return Math.floor(Math.max(0, now - anchor) / QUOTE_INTERVAL_MS) % NOT_FOUND_QUOTES.length; }