Web: wykres rysowany scrollem w tle slownika pojec (stroke-dashoffset scrub)

This commit is contained in:
tisachi
2026-10-20 02:20:19 +02:00
parent b2e6172454
commit 8cbbf7d35e

View File

@@ -1,4 +1,4 @@
import type { ReactNode } from 'react';
import { useEffect, useRef, type ReactNode } from 'react';
import {
Activity,
Dumbbell,
@@ -13,6 +13,86 @@ import { StreakDots } from '../components/StreakDots';
import { cn } from '../lib/utils';
import { Section, SectionHeading } from './shared';
// Wykres w tle sekcji — rysowany od lewej do prawej w rytm scrolla.
const CHART_PATH = 'M0,150 L130,118 L250,134 L380,86 L510,112 L650,58 L780,92 L900,44 L1000,66';
function ChartBackdrop() {
const wrapRef = useRef<HTMLDivElement>(null);
const lineRef = useRef<SVGPathElement>(null);
const clipRef = useRef<SVGRectElement>(null);
useEffect(() => {
const wrap = wrapRef.current;
const line = lineRef.current;
const clip = clipRef.current;
if (!wrap || !line || !clip) return;
// jsdom nie implementuje getTotalLength — bez scrubbingu w testach
if (typeof line.getTotalLength !== 'function') return;
const len = line.getTotalLength();
line.style.strokeDasharray = String(len);
const reduce =
typeof window.matchMedia === 'function' &&
window.matchMedia('(prefers-reduced-motion: reduce)').matches;
let raf = 0;
const update = () => {
const r = wrap.getBoundingClientRect();
const vh = window.innerHeight;
const p = reduce ? 1 : Math.min(Math.max((vh - r.top) / (r.height + vh * 0.75), 0), 1);
line.style.strokeDashoffset = String(len * (1 - p));
clip.setAttribute('width', String(p * 1000));
};
const onScroll = () => {
cancelAnimationFrame(raf);
raf = requestAnimationFrame(update);
};
update();
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', onScroll);
return () => {
cancelAnimationFrame(raf);
window.removeEventListener('scroll', onScroll);
window.removeEventListener('resize', onScroll);
};
}, []);
return (
<div ref={wrapRef} aria-hidden="true" className="pointer-events-none absolute inset-0 z-0">
<svg
viewBox="0 0 1000 190"
preserveAspectRatio="none"
className="h-[58%] w-full translate-y-14 opacity-35"
>
<defs>
<linearGradient id="chart-fill" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor="var(--accent)" stopOpacity="0.35" />
<stop offset="100%" stopColor="var(--accent)" stopOpacity="0" />
</linearGradient>
<clipPath id="chart-reveal">
<rect ref={clipRef} x="0" y="0" width="0" height="190" />
</clipPath>
</defs>
<g clipPath="url(#chart-reveal)">
<path d={`${CHART_PATH} L1000,190 L0,190 Z`} fill="url(#chart-fill)" stroke="none" />
</g>
<path
ref={lineRef}
d={CHART_PATH}
fill="none"
stroke="var(--accent)"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
vectorEffect="non-scaling-stroke"
/>
</svg>
</div>
);
}
// Słownik pojęć — podstawowe cegły systemu wyjaśnione obrazkiem, nie żargonem.
// Dla osoby, która widzi FitOS po raz pierwszy: tu dowiaduje się, o co „chodzi”.
@@ -223,36 +303,42 @@ const CONCEPTS: Concept[] = [
export function Concepts() {
return (
<Section id="slownik">
<SectionHeading
kicker="/slownik"
title="Słownik pojęć"
lead="Sześć cegieł, z których zbudowany jest FitOS. Bez znajomości systemu wystarczy ta jedna sekcja, żeby wiedzieć, o co w nim chodzi."
/>
<div className="relative">
<ChartBackdrop />
<div className="mt-12 grid gap-5 sm:grid-cols-2 xl:grid-cols-3">
{CONCEPTS.map((c, i) => (
<Reveal key={c.title} delayMs={(i % 3) * 60} className="h-full">
<article className="window-glow flex h-full flex-col overflow-hidden rounded-lg border border-line bg-(image:--card-grad) shadow-card">
<header className="flex items-center gap-2.5 border-b border-line bg-input px-4 py-3">
<span aria-hidden="true" className="flex items-center gap-1.5">
<span className="size-2.5 rounded-full bg-accent" />
<span className="size-2.5 rounded-full bg-line" />
<span className="size-2.5 rounded-full bg-line" />
</span>
<span className="ml-1 flex items-center gap-1.5 text-accent">
<c.icon size={14} aria-hidden="true" />
<span className="font-mono text-xs tracking-wide text-dim">{c.title}</span>
</span>
</header>
<div className="flex h-32 flex-col justify-center border-b border-line bg-bg/70 px-4">
{c.viz}
</div>
<p className="min-h-[110px] px-4 py-4 text-[12.5px] leading-relaxed text-dim">
{c.desc}
</p>
</article>
</Reveal>
))}
<div className="relative z-10">
<SectionHeading
kicker="/slownik"
title="Słownik pojęć"
lead="Sześć cegieł, z których zbudowany jest FitOS. Bez znajomości systemu wystarczy ta jedna sekcja, żeby wiedzieć, o co w nim chodzi."
/>
<div className="mt-12 grid gap-5 sm:grid-cols-2 xl:grid-cols-3">
{CONCEPTS.map((c, i) => (
<Reveal key={c.title} delayMs={(i % 3) * 60} className="h-full">
<article className="window-glow flex h-full flex-col overflow-hidden rounded-lg border border-line bg-(image:--card-grad) shadow-card">
<header className="flex items-center gap-2.5 border-b border-line bg-input px-4 py-3">
<span aria-hidden="true" className="flex items-center gap-1.5">
<span className="size-2.5 rounded-full bg-accent" />
<span className="size-2.5 rounded-full bg-line" />
<span className="size-2.5 rounded-full bg-line" />
</span>
<span className="ml-1 flex items-center gap-1.5 text-accent">
<c.icon size={14} aria-hidden="true" />
<span className="font-mono text-xs tracking-wide text-dim">{c.title}</span>
</span>
</header>
<div className="flex h-32 flex-col justify-center border-b border-line bg-bg/70 px-4">
{c.viz}
</div>
<p className="min-h-[110px] px-4 py-4 text-[12.5px] leading-relaxed text-dim">
{c.desc}
</p>
</article>
</Reveal>
))}
</div>
</div>
</div>
</Section>
);