Math Curve Loader
boldkit/math-curve-loaderFreeComponent
Animated mathematical curve loader with neubrutalism aesthetics — 8 curve variants including rose, lissajous, butterfly, and more
Live preview
live · rendered by the registry
Rendered by boldkit on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://boldkit.dev/r/math-curve-loader.jsonSource
1/* eslint-disable react-refresh/only-export-components */2import * as React from 'react'3import { cva, type VariantProps } from 'class-variance-authority'4import { cn } from '@/lib/utils'5import { ErrorBoundary } from '@/components/ErrorBoundary'6import {7 buildPath,8 getPoint,9 getAngle,10 getDetailScale,11 getCurvePulseDuration,12 type LoaderCurveKey,13} from '@/lib/math-curves'1415const mathCurveLoaderVariants = cva('', {16 variants: {17 size: {18 xs: 'w-6 h-6',19 sm: 'w-8 h-8',20 md: 'w-12 h-12',21 lg: 'w-16 h-16',22 xl: 'w-24 h-24',23 },24 },25 defaultVariants: {26 size: 'md',27 },28})2930const SPEED_DURATION: Record<string, number> = {31 slow: 9000,32 normal: 5500,33 fast: 3000,34}3536export interface MathCurveLoaderProps37 extends React.SVGAttributes<SVGSVGElement>,38 VariantProps<typeof mathCurveLoaderVariants> {39 curve?: LoaderCurveKey40 speed?: 'slow' | 'normal' | 'fast'41 trackColor?: string42 headColor?: string43 strokeWidth?: number44 headSize?: number45}4647const MathCurveLoader = React.forwardRef<SVGSVGElement, MathCurveLoaderProps>(48 (49 {50 className,51 size,52 curve = 'rose',53 speed = 'normal',54 trackColor,55 headColor,56 strokeWidth = 4,57 headSize = 8,58 'aria-label': ariaLabel = 'Loading',59 ...props60 },61 ref62 ) => {63 const pathRef = React.useRef<SVGPathElement>(null)64 const rectRef = React.useRef<SVGRectElement>(null)65 const rafRef = React.useRef<number>(0)66 const startTimeRef = React.useRef<number>(performance.now())6768 const durationMs = SPEED_DURATION[speed] ?? SPEED_DURATION.normal6970 // Rebuild static track path when curve changes71 const trackPath = React.useMemo(() => buildPath(curve, 1.0), [curve])7273 React.useEffect(() => {74 startTimeRef.current = performance.now()7576 const tick = () => {77 const now = performance.now()78 const elapsed = (now - startTimeRef.current) % durationMs79 const progress = elapsed / durationMs80 const detailScale = getDetailScale(now, getCurvePulseDuration(curve))8182 const { x, y } = getPoint(curve, progress, detailScale)83 const angle = getAngle(curve, progress, detailScale)8485 // Update track path with breathing detail scale86 if (pathRef.current) {87 pathRef.current.setAttribute('d', buildPath(curve, detailScale))88 }8990 // Update head rect position and rotation91 if (rectRef.current) {92 const cx = x93// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from boldkit
All 94 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | boldkit | Components | Free | 2 deps | |
| Alertalert | boldkit | Components | Free | 2 deps | |
| Alert Dialogalert-dialog | boldkit | Components | Free | 1 dep | |
| ASCII Shapesascii-shapes | boldkit | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | boldkit | Components | Free | 1 dep | |
| Avataravatar | boldkit | Components | Free | 1 dep | |
| Badgebadge | boldkit | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | boldkit | Components | Free | 2 deps |
