Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useNpmDownloadCounter } from '~/hooks/useNpmDownloadCounter'
import { homepageNpmStatsSummaryQuery, ossStatsQuery } from '~/queries/stats'
import { useLibrariesOverlay } from '~/contexts/LibrariesOverlayContext'
import { fetchRecentPosts } from '~/utils/blog.functions'
import { usePrefersReducedMotion } from '~/utils/usePrefersReducedMotion'
import { seo } from '~/utils/seo'

export const Route = createFileRoute('/')({
Expand Down Expand Up @@ -565,21 +566,35 @@ function FrameworkAdapterGraph({
}) {
const [activeAdapterIndex, setActiveAdapterIndex] = React.useState(0)
const [flowProgress, setFlowProgress] = React.useState(0)
const [isVisible, setIsVisible] = React.useState(false)
const rootRef = React.useRef<HTMLDivElement>(null)
const prefersReducedMotion = usePrefersReducedMotion()

React.useEffect(() => {
const root = rootRef.current
if (!root) return

const observer = new IntersectionObserver(([entry]) => {
setIsVisible(Boolean(entry?.isIntersecting))
})
observer.observe(root)
return () => observer.disconnect()
}, [])

React.useEffect(() => {
if (!isVisible || prefersReducedMotion !== false) return

const intervalId = window.setInterval(() => {
setActiveAdapterIndex(
(currentIndex) => (currentIndex + 1) % frameworkAdapterNodes.length,
)
}, 1150)

return () => window.clearInterval(intervalId)
}, [])
}, [isVisible, prefersReducedMotion])

React.useEffect(() => {
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
return
}
if (!isVisible || prefersReducedMotion !== false) return

let frameId = 0
let lastUpdate = 0
Expand All @@ -597,13 +612,14 @@ function FrameworkAdapterGraph({
frameId = window.requestAnimationFrame(update)

return () => window.cancelAnimationFrame(frameId)
}, [])
}, [isVisible, prefersReducedMotion])

return (
// The node positions below are hard-coded against a 320×128 grid
// (adapterGraphWidth/Height), so the whole graph is scaled as a unit to
// fill the 460×233 slot rather than re-deriving every coordinate.
<div
ref={rootRef}
aria-hidden="true"
className="relative h-32 w-[320px] shrink-0 scale-[1.35] font-mono text-[10px] font-bold"
>
Expand Down
Loading