Document local setup, env vars, and API in README; sync to Gitea. Co-authored-by: Cursor <cursoragent@cursor.com>
176 lines
4.9 KiB
TypeScript
176 lines
4.9 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
|
|
export function CountUp({
|
|
to,
|
|
duration = 1400,
|
|
decimals = 0,
|
|
prefix = '',
|
|
suffix = '',
|
|
}: {
|
|
to: number;
|
|
duration?: number;
|
|
decimals?: number;
|
|
prefix?: string;
|
|
suffix?: string;
|
|
}) {
|
|
const [val, setVal] = useState(0);
|
|
const started = useRef(false);
|
|
const ref = useRef<HTMLSpanElement>(null);
|
|
|
|
useEffect(() => {
|
|
const el = ref.current;
|
|
if (!el) return;
|
|
|
|
const io = new IntersectionObserver(
|
|
([entry]) => {
|
|
if (!entry.isIntersecting || started.current) return;
|
|
started.current = true;
|
|
const t0 = performance.now();
|
|
const tick = (now: number) => {
|
|
const p = Math.min(1, (now - t0) / duration);
|
|
const eased = 1 - Math.pow(1 - p, 3);
|
|
setVal(to * eased);
|
|
if (p < 1) requestAnimationFrame(tick);
|
|
};
|
|
requestAnimationFrame(tick);
|
|
},
|
|
{ threshold: 0.4 },
|
|
);
|
|
io.observe(el);
|
|
return () => io.disconnect();
|
|
}, [to, duration]);
|
|
|
|
return (
|
|
<span ref={ref}>
|
|
{prefix}
|
|
{val.toFixed(decimals)}
|
|
{suffix}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
export function Sparkline({ data, color = '#FF0000' }: { data: number[]; color?: string }) {
|
|
const id = useId();
|
|
const { points, area, last } = useMemo(() => {
|
|
const max = Math.max(...data);
|
|
const min = Math.min(...data);
|
|
const span = max - min || 1;
|
|
const coords = data.map((v, i) => {
|
|
const x = (i / (data.length - 1)) * 100;
|
|
const y = 28 - ((v - min) / span) * 24;
|
|
return `${x},${y}`;
|
|
});
|
|
const line = coords.join(' ');
|
|
const areaPath = `M0,30 L${line.replace(/ /g, ' L')} L100,30 Z`;
|
|
return { points: line, area: areaPath, last: data[data.length - 1] };
|
|
}, [data]);
|
|
|
|
return (
|
|
<svg className="sparkline" viewBox="0 0 100 30" preserveAspectRatio="none" aria-hidden>
|
|
<defs>
|
|
<linearGradient id={`g-${id}`} x1="0" y1="0" x2="0" y2="1">
|
|
<stop offset="0%" stopColor={color} stopOpacity="0.45" />
|
|
<stop offset="100%" stopColor={color} stopOpacity="0" />
|
|
</linearGradient>
|
|
</defs>
|
|
<path d={area} fill={`url(#g-${id})`} className="spark-area" />
|
|
<polyline
|
|
fill="none"
|
|
stroke={color}
|
|
strokeWidth="2.2"
|
|
strokeLinejoin="round"
|
|
strokeLinecap="round"
|
|
points={points}
|
|
vectorEffect="non-scaling-stroke"
|
|
className="spark-line"
|
|
/>
|
|
<circle cx="100" cy={28 - ((last - Math.min(...data)) / (Math.max(...data) - Math.min(...data) || 1)) * 24} r="2.4" fill={color} className="spark-dot" />
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
export function BarChart({ data }: { data: number[] }) {
|
|
const max = Math.max(...data);
|
|
const days = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
|
|
return (
|
|
<div className="bar-chart" aria-hidden>
|
|
{data.map((v, i) => (
|
|
<div className="bar-col" key={i}>
|
|
<div className="bar" style={{ height: `${(v / max) * 100}%`, animationDelay: `${i * 70}ms` }} />
|
|
<span>{days[i]}</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function PlayIcon({ size = 22 }: { size?: number }) {
|
|
return (
|
|
<svg width={size} height={size} viewBox="0 0 24 24" fill="currentColor" aria-hidden>
|
|
<path d="M8 5.14v13.72L19 12 8 5.14z" />
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
export function YtLogo({ size = 28 }: { size?: number }) {
|
|
return (
|
|
<svg width={size} height={Math.round(size * 0.7)} viewBox="0 0 28 20" aria-hidden>
|
|
<rect width="28" height="20" rx="5" fill="#FF0000" />
|
|
<path d="M11 5.5v9l7.5-4.5L11 5.5z" fill="#fff" />
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
export function CryptoIcon() {
|
|
return (
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden>
|
|
<circle cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="1.8" />
|
|
<path d="M8 12h8M12 7v10" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" />
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
export function CheckIcon() {
|
|
return (
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden>
|
|
<circle cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="1.8" />
|
|
<path d="M8 12.5l2.5 2.5L16 9.5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
export function FloatingBits() {
|
|
const bits = useMemo(
|
|
() =>
|
|
['▶️', '💰', '📈', '🔴', '✨', '💎', '🎯', '📊'].map((emoji, i) => ({
|
|
emoji,
|
|
left: 8 + ((i * 12) % 84),
|
|
delay: i * 0.7,
|
|
dur: 10 + (i % 4) * 2,
|
|
size: 18 + (i % 3) * 6,
|
|
})),
|
|
[],
|
|
);
|
|
|
|
return (
|
|
<div className="float-bits" aria-hidden>
|
|
{bits.map((b) => (
|
|
<span
|
|
key={b.emoji + b.left}
|
|
className="float-bit"
|
|
style={{
|
|
left: `${b.left}%`,
|
|
animationDelay: `${b.delay}s`,
|
|
animationDuration: `${b.dur}s`,
|
|
fontSize: `${b.size}px`,
|
|
}}
|
|
>
|
|
{b.emoji}
|
|
</span>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|