Web: diagram rdzenia z wiazaniami mierzonymi w DOM - kafelki o naturalnej wysokosci

This commit is contained in:
tisachi
2026-10-20 00:28:29 +02:00
parent 7baa3d5867
commit f845fdbb04

View File

@@ -1,3 +1,4 @@
import { useEffect, useRef, useState } from 'react';
import {
ArrowRight,
Building2,
@@ -78,62 +79,99 @@ const TRACK_LINKS: { id: TrackId; label: string }[] = [
{ id: 'admin', label: 'Dla administratora' },
];
/** Sekcja „Ekosystem” — rdzeń (od ogółu): mapa uczestników i legenda zazębień. */
export function Ecosystem() {
return (
<Section id="ekosystem">
<SectionHeading
kicker="/rdzen"
title="Ekosystem — rdzeń systemu"
lead="FitOS nie jest aplikacją treningową z dodatkiem siłowni. To rdzeń, w którym potrzeby ćwiczących, trenerów i siłowni zazębiają się nawzajem — nikt nie jest tu użytkownikiem końcowym."
/>
interface Wire {
x1: number;
y1: number;
x2: number;
y2: number;
delay: string;
}
{/* Diagram rdzenia (lg+): przerywane wiązania z przepływem + kafelki dryfujące
niezależnie od animacji wejścia (dryf na wewnętrznym spanie) */}
<Reveal className="relative mt-14 hidden h-[640px] lg:block">
{/* Wiązania w % kontenera — końce dotykają krawędzi kafelków (w-[32%] h-[42%])
niezależnie od szerokości (preserveAspectRatio="none" skaluje obie osie) */}
const HUB_RADIUS = 78;
/**
* Diagram rdzenia (lg+): kafelki uczestników z naturalną wysokością (nic się nie
* ucina), przerywane wiązania mierzone w DOM (ResizeObserver) i delikatny dryf.
*/
function HubDiagram() {
const containerRef = useRef<HTMLDivElement>(null);
const trenerRef = useRef<HTMLDivElement>(null);
const silowniaRef = useRef<HTMLDivElement>(null);
const cwiczacyRef = useRef<HTMLDivElement>(null);
const [wires, setWires] = useState<Wire[]>([]);
useEffect(() => {
const container = containerRef.current;
if (!container) return;
const targets = [
{ el: trenerRef.current, side: 'left' as const, delay: '0s' },
{ el: silowniaRef.current, side: 'left' as const, delay: '-0.5s' },
{ el: cwiczacyRef.current, side: 'right' as const, delay: '-0.9s' },
];
const compute = () => {
const cr = container.getBoundingClientRect();
if (!cr.width || !cr.height) return;
const cx = cr.width / 2;
const cy = cr.height / 2;
const next: Wire[] = [];
for (const t of targets) {
if (!t.el) continue;
const r = t.el.getBoundingClientRect();
const midX = r.left + r.width / 2 - cr.left;
const midY = r.top + r.height / 2 - cr.top;
const dx = midX - cx;
const dy = midY - cy;
const len = Math.hypot(dx, dy) || 1;
next.push({
x1: ((cx + (dx / len) * HUB_RADIUS) / cr.width) * 100,
y1: ((cy + (dy / len) * HUB_RADIUS) / cr.height) * 100,
x2: (((t.side === 'left' ? r.right : r.left) - cr.left) / cr.width) * 100,
y2: (midY / cr.height) * 100,
delay: t.delay,
});
}
setWires(next);
};
compute();
// jsdom nie zna ResizeObserver — wystarczy jednorazowy pomiar (i tak puste recty)
if (typeof ResizeObserver !== 'undefined') {
const observer = new ResizeObserver(compute);
observer.observe(container);
window.addEventListener('resize', compute);
return () => {
observer.disconnect();
window.removeEventListener('resize', compute);
};
}
}, []);
return (
<Reveal className="hidden lg:block">
<div ref={containerRef} className="relative mt-14 h-[600px]">
<svg
aria-hidden="true"
viewBox="0 0 100 100"
preserveAspectRatio="none"
className="absolute inset-0 h-full w-full"
>
<line
className="link-line"
x1="45.5"
y1="40"
x2="32"
y2="25"
vectorEffect="non-scaling-stroke"
stroke="var(--accent)"
strokeOpacity="0.45"
strokeWidth="1.5"
/>
<line
className="link-line"
style={{ animationDelay: '-0.5s' }}
x1="45"
y1="62"
x2="32"
y2="75"
vectorEffect="non-scaling-stroke"
stroke="var(--accent)"
strokeOpacity="0.45"
strokeWidth="1.5"
/>
<line
className="link-line"
style={{ animationDelay: '-0.9s' }}
x1="54.5"
y1="50"
x2="68"
y2="50"
vectorEffect="non-scaling-stroke"
stroke="var(--accent)"
strokeOpacity="0.45"
strokeWidth="1.5"
/>
{wires.map((w) => (
<line
key={`${w.x2}-${w.y2}`}
className="link-line"
style={{ animationDelay: w.delay }}
x1={w.x1}
y1={w.y1}
x2={w.x2}
y2={w.y2}
vectorEffect="non-scaling-stroke"
stroke="var(--accent)"
strokeOpacity="0.45"
strokeWidth="1.5"
/>
))}
</svg>
<div className="window-glow absolute left-1/2 top-1/2 z-10 grid size-40 -translate-x-1/2 -translate-y-1/2 place-items-center rounded-full border border-line bg-(image:--card-grad) shadow-glow">
@@ -144,22 +182,37 @@ export function Ecosystem() {
</div>
</div>
<div className="absolute left-0 top-[2%] z-10 h-[42%] w-[32%]">
<div className="drift-1 h-full">
<ParticipantCard participant={PARTICIPANTS[1]} className="h-full" />
<div ref={trenerRef} className="absolute left-0 top-0 z-10 w-[32%]">
<div className="drift-1">
<ParticipantCard participant={PARTICIPANTS[1]} />
</div>
</div>
<div className="absolute bottom-[2%] left-0 z-10 h-[42%] w-[32%]">
<div className="drift-2 h-full">
<ParticipantCard participant={PARTICIPANTS[2]} className="h-full" />
<div ref={silowniaRef} className="absolute bottom-0 left-0 z-10 w-[32%]">
<div className="drift-2">
<ParticipantCard participant={PARTICIPANTS[2]} />
</div>
</div>
<div className="absolute right-0 top-[29%] z-10 h-[42%] w-[32%]">
<div className="drift-3 h-full">
<ParticipantCard participant={PARTICIPANTS[0]} className="h-full" />
<div ref={cwiczacyRef} className="absolute right-0 top-1/2 z-10 w-[32%] -translate-y-1/2">
<div className="drift-3">
<ParticipantCard participant={PARTICIPANTS[0]} />
</div>
</div>
</Reveal>
</div>
</Reveal>
);
}
/** Sekcja „Ekosystem” — rdzeń (od ogółu): mapa uczestników i legenda zazębień. */
export function Ecosystem() {
return (
<Section id="ekosystem">
<SectionHeading
kicker="/rdzen"
title="Ekosystem — rdzeń systemu"
lead="FitOS nie jest aplikacją treningową z dodatkiem siłowni. To rdzeń, w którym potrzeby ćwiczących, trenerów i siłowni zazębiają się nawzajem — nikt nie jest tu użytkownikiem końcowym."
/>
<HubDiagram />
{/* Telefon/tablet: rdzeń nad listą uczestników */}
<div className="mt-14 flex flex-col gap-4 lg:hidden">