Web: promieniowanie rdzenia ponizej lg (rdzen miedzy paramami kafelkow na tablecie, na telefonie promienie tylko do Trenera i Silowni)

This commit is contained in:
tisachi
2026-10-23 00:41:55 +02:00
parent 8dabd4eb69
commit 300e982ded

View File

@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import { Building2, Dumbbell, Shield, UserRound, type LucideIcon } from 'lucide-react';
import { Brandmark } from '../components/Brandmark';
import { Reveal } from '../components/Reveal';
@@ -53,14 +53,154 @@ interface Wire {
y2: number;
spread: number;
id: string;
// v = ściana pionowa (podstawa trójkąta na bocznej krawędzi, rozrzut w y),
// h = ściana pozioma (podstawa na górnej/dolnej krawędzi, rozrzut w x)
axis: 'v' | 'h';
}
// promień wierzchołka na obwodzie rdzenia — dobrany do rozmiaru rdzenia
const HUB_RADIUS = 78;
const HUB_RADIUS_STACK = 70;
const SPREAD_PX = 52;
// impulsy promieniowania wypełniają cały stożek: wachlarz od wierzchołka
// do równomiernie rozmieszczonych punktów podstawy (frakcje ±1)
const STREAKS = [-1, -0.66, -0.33, 0, 0.33, 0.66, 1];
interface WireTarget {
el: HTMLElement | null;
id: string;
// ściana kafelka, do której biegnie promień (strona bliższa rdzenia)
side: 'left' | 'right' | 'top' | 'bottom';
}
function basePoint(r: DOMRect, cr: DOMRect, side: WireTarget['side']) {
switch (side) {
case 'left':
return { x: r.right - cr.left, y: r.top + r.height / 2 - cr.top };
case 'right':
return { x: r.left - cr.left, y: r.top + r.height / 2 - cr.top };
case 'top':
return { x: r.left + r.width / 2 - cr.left, y: r.bottom - cr.top };
case 'bottom':
return { x: r.left + r.width / 2 - cr.left, y: r.top - cr.top };
}
}
/**
* Promienie—trójkąty mierzone w DOM: wierzchołek na obwodzie rdzenia,
* podstawy na ścianach kafelków. Współrzędne w % kontenera (viewBox 0–100).
*/
function measureWires(
container: HTMLElement,
hubEl: HTMLElement,
targets: WireTarget[],
hubRadius: number,
) {
const cr = container.getBoundingClientRect();
if (!cr.width || !cr.height) return { wires: [] as Wire[], hub: { x: 50, y: 50 } };
const hr = hubEl.getBoundingClientRect();
const cx = hr.left + hr.width / 2 - cr.left;
const cy = hr.top + hr.height / 2 - cr.top;
const wires: 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;
const base = basePoint(r, cr, t.side);
wires.push({
x1: ((cx + (dx / len) * hubRadius) / cr.width) * 100,
y1: ((cy + (dy / len) * hubRadius) / cr.height) * 100,
x2: (base.x / cr.width) * 100,
y2: (base.y / cr.height) * 100,
// połowa podstawy trójkąta jako % wymiaru kontenera w osi rozrzutu
spread: ((t.side === 'left' || t.side === 'right' ? SPREAD_PX / cr.height : SPREAD_PX / cr.width)) * 100,
id: t.id,
axis: t.side === 'left' || t.side === 'right' ? 'v' : 'h',
});
}
return { wires, hub: { x: (cx / cr.width) * 100, y: (cy / cr.height) * 100 } };
}
/** Warstwy SVG: gradienty promieni + maska miękkiego zanikania od rdzenia. */
function RayDefs({
wires,
idPrefix,
hub,
}: {
wires: Wire[];
idPrefix: string;
hub: { x: number; y: number };
}) {
return (
<>
<defs>
{wires.map((w) => (
<linearGradient
key={w.id}
id={`ray-${idPrefix}${w.id}`}
gradientUnits="userSpaceOnUse"
x1={w.x1}
y1={w.y1}
x2={w.x2}
y2={w.y2}
>
<stop offset="0" stopColor="var(--accent)" stopOpacity="0.55" />
<stop offset="1" stopColor="var(--accent)" stopOpacity="0.04" />
</linearGradient>
))}
<radialGradient
id={`ray-glow-${idPrefix}`}
gradientUnits="userSpaceOnUse"
cx={hub.x}
cy={hub.y}
r="50"
>
<stop offset="0" stopColor="#fff" stopOpacity="1" />
<stop offset="1" stopColor="#fff" stopOpacity="0" />
</radialGradient>
<mask id={`ray-soft-${idPrefix}`}>
<rect x="0" y="0" width="100" height="100" fill={`url(#ray-glow-${idPrefix})`} />
</mask>
</defs>
<g mask={`url(#ray-soft-${idPrefix})`}>
{wires.map((w) => (
<g key={w.id}>
<polygon
points={
w.axis === 'v'
? `${w.x1},${w.y1} ${w.x2},${w.y2 - w.spread} ${w.x2},${w.y2 + w.spread}`
: `${w.x1},${w.y1} ${w.x2 - w.spread},${w.y2} ${w.x2 + w.spread},${w.y2}`
}
fill={`url(#ray-${idPrefix}${w.id})`}
/>
{STREAKS.map((f, i) => (
<line
key={f}
className="ray-flow"
style={{ animationDelay: `${-i * 0.42}s` }}
x1={w.x1}
y1={w.y1}
x2={w.axis === 'v' ? w.x2 : w.x2 + w.spread * f}
y2={w.axis === 'v' ? w.y2 + w.spread * f : w.y2}
pathLength={100}
vectorEffect="non-scaling-stroke"
stroke="var(--accent)"
strokeOpacity="0.5"
strokeWidth="2"
strokeLinecap="round"
/>
))}
</g>
))}
</g>
</>
);
}
/**
* Diagram rdzenia (lg+): kafelki uczestników z naturalną wysokością (nic się nie
* ucina) i promienie—trójkąty mierzone w DOM (ResizeObserver): wierzchołek na
@@ -68,48 +208,30 @@ const STREAKS = [-1, -0.66, -0.33, 0, 0.33, 0.66, 1];
*/
function HubDiagram() {
const containerRef = useRef<HTMLDivElement>(null);
const hubRef = useRef<HTMLDivElement>(null);
const trenerRef = useRef<HTMLDivElement>(null);
const silowniaRef = useRef<HTMLDivElement>(null);
const cwiczacyRef = useRef<HTMLDivElement>(null);
const adminRef = useRef<HTMLDivElement>(null);
const [wires, setWires] = useState<Wire[]>([]);
const [hub, setHub] = useState({ x: 50, y: 50 });
useEffect(() => {
const container = containerRef.current;
if (!container) return;
const targets = [
{ el: trenerRef.current, side: 'left' as const, id: 'trener' },
{ el: silowniaRef.current, side: 'left' as const, id: 'silownia' },
{ el: cwiczacyRef.current, side: 'right' as const, id: 'cwiczacy' },
{ el: adminRef.current, side: 'right' as const, id: 'admin' },
];
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,
// połowa podstawy trójkąta jako % wysokości kontenera
spread: (SPREAD_PX / cr.height) * 100,
id: t.id,
});
}
setWires(next);
const hubEl = hubRef.current;
if (!hubEl) return;
const targets: WireTarget[] = [
{ el: trenerRef.current, side: 'left', id: 'trener' },
{ el: silowniaRef.current, side: 'left', id: 'silownia' },
{ el: cwiczacyRef.current, side: 'right', id: 'cwiczacy' },
{ el: adminRef.current, side: 'right', id: 'admin' },
];
const measured = measureWires(container, hubEl, targets, HUB_RADIUS);
setWires(measured.wires);
setHub(measured.hub);
};
compute();
@@ -137,59 +259,13 @@ function HubDiagram() {
preserveAspectRatio="none"
className="absolute inset-0 h-full w-full"
>
<defs>
{wires.map((w) => (
<linearGradient
key={w.id}
id={`ray-${w.id}`}
gradientUnits="userSpaceOnUse"
x1={w.x1}
y1={w.y1}
x2={w.x2}
y2={w.y2}
>
<stop offset="0" stopColor="var(--accent)" stopOpacity="0.55" />
<stop offset="1" stopColor="var(--accent)" stopOpacity="0.04" />
</linearGradient>
))}
<radialGradient id="ray-glow" gradientUnits="userSpaceOnUse" cx="50" cy="50" r="50">
<stop offset="0" stopColor="#fff" stopOpacity="1" />
<stop offset="1" stopColor="#fff" stopOpacity="0" />
</radialGradient>
<mask id="ray-soft">
<rect x="0" y="0" width="100" height="100" fill="url(#ray-glow)" />
</mask>
</defs>
<g mask="url(#ray-soft)">
{wires.map((w) => (
<g key={w.id}>
<polygon
points={`${w.x1},${w.y1} ${w.x2},${w.y2 - w.spread} ${w.x2},${w.y2 + w.spread}`}
fill={`url(#ray-${w.id})`}
/>
{STREAKS.map((f, i) => (
<line
key={f}
className="ray-flow"
style={{ animationDelay: `${-i * 0.42}s` }}
x1={w.x1}
y1={w.y1}
x2={w.x2}
y2={w.y2 + w.spread * f}
pathLength={100}
vectorEffect="non-scaling-stroke"
stroke="var(--accent)"
strokeOpacity="0.5"
strokeWidth="2"
strokeLinecap="round"
/>
))}
</g>
))}
</g>
<RayDefs wires={wires} idPrefix="" hub={hub} />
</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">
<div
ref={hubRef}
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"
>
<div className="text-center">
<Brandmark size={40} className="mx-auto" />
<p className="mt-2 font-display text-sm font-bold text-ink">FitOS</p>
@@ -222,6 +298,119 @@ function HubDiagram() {
);
}
/**
* Diagram rdzenia pod lg: układ pionowy (telefon: ćwiczący, trener, rdzeń,
* siłownia, administrator — promienie tylko do dwóch najbliższych kafelków)
* lub dwie pary nad/pod rdzeniem (tablet sm+: promienie do wszystkich czterech).
*/
function StackDiagram() {
const containerRef = useRef<HTMLDivElement>(null);
const hubRef = useRef<HTMLDivElement>(null);
const cwiczacyRef = useRef<HTMLDivElement>(null);
const trenerRef = useRef<HTMLDivElement>(null);
const silowniaRef = useRef<HTMLDivElement>(null);
const adminRef = useRef<HTMLDivElement>(null);
const [wires, setWires] = useState<Wire[]>([]);
const [hub, setHub] = useState({ x: 50, y: 50 });
const [wide, setWide] = useState(() =>
typeof window !== 'undefined' && typeof window.matchMedia === 'function'
? window.matchMedia('(min-width: 640px)').matches
: true,
);
useEffect(() => {
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;
const mq = window.matchMedia('(min-width: 640px)');
const onChange = () => setWide(mq.matches);
onChange();
mq.addEventListener('change', onChange);
return () => mq.removeEventListener('change', onChange);
}, []);
const compute = useCallback(() => {
const container = containerRef.current;
const hubEl = hubRef.current;
if (!container || !hubEl) return;
const targets: WireTarget[] = [
{ el: cwiczacyRef.current, side: 'top', id: 'cwiczacy' },
{ el: trenerRef.current, side: 'top', id: 'trener' },
{ el: silowniaRef.current, side: 'bottom', id: 'silownia' },
{ el: adminRef.current, side: 'bottom', id: 'admin' },
];
// telefon (1 kolumna): promienie tylko do najbliższych — Trener i Siłownia;
// tablet (2 kolumny): rdzeń między parami — promienie do wszystkich czterech
const visible = wide ? targets : targets.filter((t) => t.id === 'trener' || t.id === 'silownia');
const measured = measureWires(container, hubEl, visible, HUB_RADIUS_STACK);
setWires(measured.wires);
setHub(measured.hub);
}, [wide]);
useEffect(() => {
compute();
// jsdom nie zna ResizeObserver — wystarczy jednorazowy pomiar (i tak puste recty)
if (typeof ResizeObserver !== 'undefined') {
const observer = new ResizeObserver(compute);
if (containerRef.current) observer.observe(containerRef.current);
if (hubRef.current) observer.observe(hubRef.current);
window.addEventListener('resize', compute);
return () => {
observer.disconnect();
window.removeEventListener('resize', compute);
};
}
}, [compute]);
return (
<div ref={containerRef} className="relative mt-14 lg:hidden">
<svg
aria-hidden="true"
viewBox="0 0 100 100"
preserveAspectRatio="none"
className="pointer-events-none absolute inset-0 h-full w-full"
>
<RayDefs wires={wires} idPrefix="s-" hub={hub} />
</svg>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-x-10">
<Reveal className="h-full">
<div ref={cwiczacyRef} className="h-full">
<ParticipantCard participant={PARTICIPANTS[0]} className="h-full" />
</div>
</Reveal>
<Reveal delayMs={60} className="h-full">
<div ref={trenerRef} className="h-full">
<ParticipantCard participant={PARTICIPANTS[1]} className="h-full" />
</div>
</Reveal>
<Reveal className="col-span-full flex justify-center py-10">
<div
ref={hubRef}
className="window-glow relative z-10 grid size-36 place-items-center rounded-full border border-line bg-(image:--card-grad) shadow-glow"
>
<div className="text-center">
<Brandmark size={34} className="mx-auto" />
<p className="mt-1.5 font-display text-sm font-bold text-ink">FitOS</p>
<p className="font-mono text-[10px] text-accent">rdzeń</p>
</div>
</div>
</Reveal>
<Reveal delayMs={120} className="h-full">
<div ref={silowniaRef} className="h-full">
<ParticipantCard participant={PARTICIPANTS[2]} className="h-full" />
</div>
</Reveal>
<Reveal delayMs={180} className="h-full">
<div ref={adminRef} className="h-full">
<ParticipantCard participant={PARTICIPANTS[3]} className="h-full" />
</div>
</Reveal>
</div>
</div>
);
}
/** Sekcja „Ekosystem” — rdzeń (od ogółu): mapa uczestników i legenda zazębień. */
export function Ecosystem() {
return (
@@ -234,25 +423,8 @@ export function Ecosystem() {
<HubDiagram />
{/* Telefon/tablet: rdzeń nad listą uczestników */}
<div className="mt-14 flex flex-col gap-4 lg:hidden">
<Reveal className="flex justify-center">
<div className="window-glow grid size-36 place-items-center rounded-full border border-line bg-(image:--card-grad) shadow-glow">
<div className="text-center">
<Brandmark size={34} className="mx-auto" />
<p className="mt-1.5 font-display text-sm font-bold text-ink">FitOS</p>
<p className="font-mono text-[10px] text-accent">rdzeń</p>
</div>
</div>
</Reveal>
<div className="mt-14 grid gap-4 sm:grid-cols-2">
{PARTICIPANTS.map((p, i) => (
<Reveal key={p.role} delayMs={i * 60} className="h-full">
<ParticipantCard participant={p} className="h-full" />
</Reveal>
))}
</div>
</div>
{/* Telefon/tablet: rdzeń między parami uczestników z promieniowaniem */}
<StackDiagram />
</Section>
);
}