Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

fix: build fix

Arghya Das1b3a287e42cc
diff --git a/public/r/aurora-text.json b/public/r/aurora-text.json
index f5887a68..4fcc869c 100644
--- a/public/r/aurora-text.json
+++ b/public/r/aurora-text.json
@@ -7,7 +7,7 @@
"files": [
{
"path": "registry/magicui/aurora-text.tsx",
- "content": "\"use client\";\n\nimport React, { memo } from \"react\";\n\ninterface AuroraTextProps {\n children: React.ReactNode;\n className?: string;\n colors?: string[];\n speed?: number;\n}\n\nexport const AuroraText = memo(\n ({\n children,\n className = \"\",\n colors = [\"#FF0080\", \"#7928CA\", \"#0070F3\", \"#38bdf8\"],\n speed = 1,\n }: AuroraTextProps) => {\n const gradientStyle = {\n backgroundImage: `linear-gradient(135deg, ${colors.join(\", \")}, ${colors[0]})`,\n WebkitBackgroundClip: \"text\",\n WebkitTextFillColor: \"transparent\",\n animationDuration: `${10 / speed}s`,\n };\n\n return (\n <span className={`relative inline-block ${className}`}>\n <span className=\"sr-only\">{children}</span>\n <span\n className=\"relative animate-aurora bg-[length:200%_auto] bg-clip-text text-transparent\"\n style={gradientStyle}\n aria-hidden=\"true\"\n >\n {children}\n </span>\n </span>\n );\n }\n);\n\nAuroraText.displayName = \"AuroraText\";\n",
+ "content": "\"use client\";\n\nimport React, { memo } from \"react\";\n\ninterface AuroraTextProps {\n children: React.ReactNode;\n className?: string;\n colors?: string[];\n speed?: number;\n}\n\nexport const AuroraText = memo(\n ({\n children,\n className = \"\",\n colors = [\"#FF0080\", \"#7928CA\", \"#0070F3\", \"#38bdf8\"],\n speed = 1,\n }: AuroraTextProps) => {\n const gradientStyle = {\n backgroundImage: `linear-gradient(135deg, ${colors.join(\", \")}, ${colors[0]})`,\n WebkitBackgroundClip: \"text\",\n WebkitTextFillColor: \"transparent\",\n animationDuration: `${10 / speed}s`,\n };\n\n return (\n <span className={`relative inline-block ${className}`}>\n <span className=\"sr-only\">{children}</span>\n <span\n className=\"relative animate-aurora bg-[length:200%_auto] bg-clip-text text-transparent\"\n style={gradientStyle}\n aria-hidden=\"true\"\n >\n {children}\n </span>\n </span>\n );\n },\n);\n\nAuroraText.displayName = \"AuroraText\";\n",
"type": "registry:ui",
"target": "components/magicui/aurora-text.tsx"
}
diff --git a/public/r/code-comparison.json b/public/r/code-comparison.json
index f41d894f..0bcc6380 100644
--- a/public/r/code-comparison.json
+++ b/public/r/code-comparison.json
@@ -11,7 +11,7 @@
"files": [
{
"path": "registry/magicui/code-comparison.tsx",
- "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n transformerNotationDiff,\n transformerNotationFocus,\n} from \"@shikijs/transformers\";\nimport { FileIcon } from \"lucide-react\";\nimport { useTheme } from \"next-themes\";\nimport { useEffect, useState } from \"react\";\n\ninterface CodeComparisonProps {\n beforeCode: string;\n afterCode: string;\n language: string;\n filename: string;\n lightTheme: string;\n darkTheme: string;\n\n highlightColor?: string;\n}\n\nexport function CodeComparison({\n beforeCode,\n afterCode,\n language,\n filename,\n lightTheme,\n darkTheme,\n highlightColor = \"#ff3333\",\n}: CodeComparisonProps) {\n const { theme, systemTheme } = useTheme();\n const [highlightedBefore, setHighlightedBefore] = useState(\"\");\n const [highlightedAfter, setHighlightedAfter] = useState(\"\");\n\n const [hasLeftFocus, setHasLeftFocus] = useState(false);\n const [hasRightFocus, setHasRightFocus] = useState(false);\n\n useEffect(() => {\n // Check if highlighted code contains any focused elements after it's set\n if (highlightedBefore || highlightedAfter) {\n const hasBeforeFocus = highlightedBefore.includes('class=\"line focused\"');\n const hasAfterFocus = highlightedAfter.includes('class=\"line focused\"');\n setHasLeftFocus(hasBeforeFocus);\n setHasRightFocus(hasAfterFocus);\n }\n }, [highlightedBefore, highlightedAfter]);\n\n useEffect(() => {\n const currentTheme = theme === \"system\" ? systemTheme : theme;\n const selectedTheme = currentTheme === \"dark\" ? darkTheme : lightTheme;\n\n async function highlightCode() {\n try {\n const { codeToHtml } = await import(\"shiki\");\n const { transformerNotationHighlight } = await import(\n \"@shikijs/transformers\"\n );\n\n const before = await codeToHtml(beforeCode, {\n lang: language,\n theme: selectedTheme,\n transformers: [\n transformerNotationHighlight({ matchAlgorithm: \"v3\" }),\n transformerNotationDiff({ matchAlgorithm: \"v3\" }),\n transformerNotationFocus({ matchAlgorithm: \"v3\" }),\n ],\n });\n const after = await codeToHtml(afterCode, {\n lang: language,\n theme: selectedTheme,\n transformers: [\n transformerNotationHighlight({ matchAlgorithm: \"v3\" }),\n transformerNotationDiff({ matchAlgorithm: \"v3\" }),\n transformerNotationFocus({ matchAlgorithm: \"v3\" }),\n ],\n });\n setHighlightedBefore(before);\n setHighlightedAfter(after);\n } catch (error) {\n console.error(\"Error highlighting code:\", error);\n setHighlightedBefore(`<pre>${beforeCode}</pre>`);\n setHighlightedAfter(`<pre>${afterCode}</pre>`);\n }\n }\n highlightCode();\n }, [\n theme,\n systemTheme,\n beforeCode,\n afterCode,\n language,\n lightTheme,\n darkTheme,\n highlightColor,\n ]);\n\n const renderCode = (code: string, highlighted: string) => {\n if (highlighted) {\n return (\n <div\n style={\n {\n \"--highlight-color\": highlightColor,\n } as React.CSSProperties\n }\n className={cn(\n \"h-full w-full overflow-auto bg-background font-mono text-xs\",\n \"[&>pre]:h-full [&>pre]:!w-screen [&>pre]:py-2\",\n \"[&>pre>code]:!inline-block [&>pre>code]:!w-full\",\n \"[&>pre>code>span]:!inline-block [&>pre>code>span]:w-full [&>pre>code>span]:px-4 [&>pre>code>span]:py-0.5\",\n \"[&>pre>code>.highlighted]:inline-block [&>pre>code>.highlighted]:w-full [&>pre>code>.highlighted]:!bg-[var(--highlight-color)]\",\n \"group-hover/left:[&>pre>code>:not(.focused)]:!opacity-100 group-hover/left:[&>pre>code>:not(.focused)]:!blur-none\",\n \"group-hover/right:[&>pre>code>:not(.focused)]:!opacity-100 group-hover/right:[&>pre>code>:not(.focused)]:!blur-none\",\n \"[&>pre>code>.add]:bg-[rgba(16,185,129,.16)] [&>pre>code>.remove]:bg-[rgba(244,63,94,.16)]\",\n \"group-hover/left:[&>pre>code>:not(.focused)]:transition-all group-hover/left:[&>pre>code>:not(.focused)]:duration-300\",\n \"group-hover/right:[&>pre>code>:not(.focused)]:transition-all group-hover/right:[&>pre>code>:not(.focused)]:duration-300\"\n )}\n dangerouslySetInnerHTML={{ __html: highlighted }}\n />\n );\n } else {\n return (\n <pre className=\"h-full overflow-auto break-all bg-background p-4 font-mono text-xs text-foreground\">\n {code}\n </pre>\n );\n }\n };\n return (\n <div className=\"mx-auto w-full max-w-5xl\">\n <div className=\"group relative w-full overflow-hidden rounded-md border border-border\">\n <div className=\"relative grid md:grid-cols-2\">\n <div\n className={cn(\n \"leftside group/left border-primary/20 md:border-r\",\n hasLeftFocus &&\n \"[&>div>pre>code>:not(.focused)]:!opacity-50 [&>div>pre>code>:not(.focused)]:!blur-[0.095rem]\",\n \"[&>div>pre>code>:not(.focused)]:transition-all [&>div>pre>code>:not(.focused)]:duration-300\"\n )}\n >\n <div className=\"flex items-center border-b border-primary/20 bg-accent p-2 text-sm text-foreground\">\n <FileIcon className=\"mr-2 h-4 w-4\" />\n {filename}\n <span className=\"ml-auto hidden md:block\">before</span>\n </div>\n {renderCode(beforeCode, highlightedBefore)}\n </div>\n <div\n className={cn(\n \"rightside group/right border-t border-primary/20 md:border-t-0\",\n hasRightFocus &&\n \"[&>div>pre>code>:not(.focused)]:!opacity-50 [&>div>pre>code>:not(.focused)]:!blur-[0.095rem]\",\n \"[&>div>pre>code>:not(.focused)]:transition-all [&>div>pre>code>:not(.focused)]:duration-300\"\n )}\n >\n <div className=\"flex items-center border-b border-primary/20 bg-accent p-2 text-sm text-foreground\">\n <FileIcon className=\"mr-2 h-4 w-4\" />\n {filename}\n <span className=\"ml-auto hidden md:block\">after</span>\n </div>\n {renderCode(afterCode, highlightedAfter)}\n </div>\n </div>\n <div className=\"absolute left-1/2 top-1/2 flex h-8 w-8 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-md border border-primary/20 bg-accent text-xs text-foreground\">\n VS\n </div>\n </div>\n </div>\n );\n}\n",
+ "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n transformerNotationDiff,\n transformerNotationFocus,\n} from \"@shikijs/transformers\";\nimport { FileIcon } from \"lucide-react\";\nimport { useTheme } from \"next-themes\";\nimport { useEffect, useState, useMemo } from \"react\";\n\ninterface CodeComparisonProps {\n beforeCode: string;\n afterCode: string;\n language: string;\n filename: string;\n lightTheme: string;\n darkTheme: string;\n highlightColor?: string;\n}\n\nexport function CodeComparison({\n beforeCode,\n afterCode,\n language,\n filename,\n lightTheme,\n darkTheme,\n highlightColor = \"#ff3333\",\n}: CodeComparisonProps) {\n const { theme, systemTheme } = useTheme();\n const [highlightedBefore, setHighlightedBefore] = useState(\"\");\n const [highlightedAfter, setHighlightedAfter] = useState(\"\");\n const [hasLeftFocus, setHasLeftFocus] = useState(false);\n const [hasRightFocus, setHasRightFocus] = useState(false);\n\n const selectedTheme = useMemo(() => {\n const currentTheme = theme === \"system\" ? systemTheme : theme;\n return currentTheme === \"dark\" ? darkTheme : lightTheme;\n }, [theme, systemTheme, darkTheme, lightTheme]);\n\n useEffect(() => {\n if (highlightedBefore || highlightedAfter) {\n setHasLeftFocus(highlightedBefore.includes('class=\"line focused\"'));\n setHasRightFocus(highlightedAfter.includes('class=\"line focused\"'));\n }\n }, [highlightedBefore, highlightedAfter]);\n\n useEffect(() => {\n async function highlightCode() {\n try {\n const { codeToHtml } = await import(\"shiki\");\n const { transformerNotationHighlight } = await import(\n \"@shikijs/transformers\"\n );\n\n const before = await codeToHtml(beforeCode, {\n lang: language,\n theme: selectedTheme,\n transformers: [\n transformerNotationHighlight({ matchAlgorithm: \"v3\" }),\n transformerNotationDiff({ matchAlgorithm: \"v3\" }),\n transformerNotationFocus({ matchAlgorithm: \"v3\" }),\n ],\n });\n const after = await codeToHtml(afterCode, {\n lang: language,\n theme: selectedTheme,\n transformers: [\n transformerNotationHighlight({ matchAlgorithm: \"v3\" }),\n transformerNotationDiff({ matchAlgorithm: \"v3\" }),\n transformerNotationFocus({ matchAlgorithm: \"v3\" }),\n ],\n });\n setHighlightedBefore(before);\n setHighlightedAfter(after);\n } catch (error) {\n console.error(\"Error highlighting code:\", error);\n setHighlightedBefore(`<pre>${beforeCode}</pre>`);\n setHighlightedAfter(`<pre>${afterCode}</pre>`);\n }\n }\n highlightCode();\n }, [beforeCode, afterCode, language, selectedTheme]);\n\n const renderCode = (code: string, highlighted: string) => {\n if (highlighted) {\n return (\n <div\n style={{ \"--highlight-color\": highlightColor } as React.CSSProperties}\n className={cn(\n \"h-full w-full overflow-auto bg-background font-mono text-xs\",\n \"[&>pre]:h-full [&>pre]:!w-screen [&>pre]:py-2\",\n \"[&>pre>code]:!inline-block [&>pre>code]:!w-full\",\n \"[&>pre>code>span]:!inline-block [&>pre>code>span]:w-full [&>pre>code>span]:px-4 [&>pre>code>span]:py-0.5\",\n \"[&>pre>code>.highlighted]:inline-block [&>pre>code>.highlighted]:w-full [&>pre>code>.highlighted]:!bg-[var(--highlight-color)]\",\n \"group-hover/left:[&>pre>code>:not(.focused)]:!opacity-100 group-hover/left:[&>pre>code>:not(.focused)]:!blur-none\",\n \"group-hover/right:[&>pre>code>:not(.focused)]:!opacity-100 group-hover/right:[&>pre>code>:not(.focused)]:!blur-none\",\n \"[&>pre>code>.add]:bg-[rgba(16,185,129,.16)] [&>pre>code>.remove]:bg-[rgba(244,63,94,.16)]\",\n \"group-hover/left:[&>pre>code>:not(.focused)]:transition-all group-hover/left:[&>pre>code>:not(.focused)]:duration-300\",\n \"group-hover/right:[&>pre>code>:not(.focused)]:transition-all group-hover/right:[&>pre>code>:not(.focused)]:duration-300\",\n )}\n dangerouslySetInnerHTML={{ __html: highlighted }}\n />\n );\n } else {\n return (\n <pre className=\"h-full overflow-auto break-all bg-background p-4 font-mono text-xs text-foreground\">\n {code}\n </pre>\n );\n }\n };\n\n return (\n <div className=\"mx-auto w-full max-w-5xl\">\n <div className=\"group relative w-full overflow-hidden rounded-md border border-border\">\n <div className=\"relative grid md:grid-cols-2\">\n <div\n className={cn(\n \"leftside group/left border-primary/20 md:border-r\",\n hasLeftFocus &&\n \"[&>div>pre>code>:not(.focused)]:!opacity-50 [&>div>pre>code>:not(.focused)]:!blur-[0.095rem]\",\n \"[&>div>pre>code>:not(.focused)]:transition-all [&>div>pre>code>:not(.focused)]:duration-300\",\n )}\n >\n <div className=\"flex items-center border-b border-primary/20 bg-accent p-2 text-sm text-foreground\">\n <FileIcon className=\"mr-2 h-4 w-4\" />\n {filename}\n <span className=\"ml-auto hidden md:block\">before</span>\n </div>\n {renderCode(beforeCode, highlightedBefore)}\n </div>\n <div\n className={cn(\n \"rightside group/right border-t border-primary/20 md:border-t-0\",\n hasRightFocus &&\n \"[&>div>pre>code>:not(.focused)]:!opacity-50 [&>div>pre>code>:not(.focused)]:!blur-[0.095rem]\",\n \"[&>div>pre>code>:not(.focused)]:transition-all [&>div>pre>code>:not(.focused)]:duration-300\",\n )}\n >\n <div className=\"flex items-center border-b border-primary/20 bg-accent p-2 text-sm text-foreground\">\n <FileIcon className=\"mr-2 h-4 w-4\" />\n {filename}\n <span className=\"ml-auto hidden md:block\">after</span>\n </div>\n {renderCode(afterCode, highlightedAfter)}\n </div>\n </div>\n <div className=\"absolute left-1/2 top-1/2 hidden h-8 w-8 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-md border border-primary/20 bg-accent text-xs text-foreground md:flex\">\n VS\n </div>\n </div>\n </div>\n );\n}\n",
"type": "registry:ui",
"target": "components/magicui/code-comparison.tsx"
}
diff --git a/public/r/particles.json b/public/r/particles.json
index 17203aa0..93548285 100644
--- a/public/r/particles.json
+++ b/public/r/particles.json
@@ -7,7 +7,7 @@
"files": [
{
"path": "registry/magicui/particles.tsx",
- "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport React, {\n ComponentPropsWithoutRef,\n useEffect,\n useRef,\n useState,\n} from \"react\";\n\ninterface MousePosition {\n x: number;\n y: number;\n}\n\nfunction MousePosition(): MousePosition {\n const [mousePosition, setMousePosition] = useState<MousePosition>({\n x: 0,\n y: 0,\n });\n\n useEffect(() => {\n const handleMouseMove = (event: MouseEvent) => {\n setMousePosition({ x: event.clientX, y: event.clientY });\n };\n\n window.addEventListener(\"mousemove\", handleMouseMove);\n\n return () => {\n window.removeEventListener(\"mousemove\", handleMouseMove);\n };\n }, []);\n\n return mousePosition;\n}\n\ninterface ParticlesProps extends ComponentPropsWithoutRef<\"div\"> {\n className?: string;\n quantity?: number;\n staticity?: number;\n ease?: number;\n size?: number;\n refresh?: boolean;\n color?: string;\n vx?: number;\n vy?: number;\n}\n\nfunction hexToRgb(hex: string): number[] {\n hex = hex.replace(\"#\", \"\");\n\n if (hex.length === 3) {\n hex = hex\n .split(\"\")\n .map((char) => char + char)\n .join(\"\");\n }\n\n const hexInt = parseInt(hex, 16);\n const red = (hexInt >> 16) & 255;\n const green = (hexInt >> 8) & 255;\n const blue = hexInt & 255;\n return [red, green, blue];\n}\n\ntype Circle = {\n x: number;\n y: number;\n translateX: number;\n translateY: number;\n size: number;\n alpha: number;\n targetAlpha: number;\n dx: number;\n dy: number;\n magnetism: number;\n};\n\nexport const Particles: React.FC<ParticlesProps> = ({\n className = \"\",\n quantity = 100,\n staticity = 50,\n ease = 50,\n size = 0.4,\n refresh = false,\n color = \"#ffffff\",\n vx = 0,\n vy = 0,\n ...props\n}) => {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const canvasContainerRef = useRef<HTMLDivElement>(null);\n const context = useRef<CanvasRenderingContext2D | null>(null);\n const circles = useRef<Circle[]>([]);\n const mousePosition = MousePosition();\n const mouse = useRef<{ x: number; y: number }>({ x: 0, y: 0 });\n const canvasSize = useRef<{ w: number; h: number }>({ w: 0, h: 0 });\n const dpr = typeof window !== \"undefined\" ? window.devicePixelRatio : 1;\n const rafID = useRef<number | null>(null);\n const resizeTimeout = useRef<NodeJS.Timeout>();\n\n useEffect(() => {\n if (canvasRef.current) {\n context.current = canvasRef.current.getContext(\"2d\");\n }\n initCanvas();\n animate();\n\n const handleResize = () => {\n if (resizeTimeout.current) {\n clearTimeout(resizeTimeout.current);\n }\n resizeTimeout.current = setTimeout(() => {\n initCanvas();\n }, 200);\n };\n\n window.addEventListener(\"resize\", handleResize);\n\n return () => {\n if (rafID.current != null) {\n window.cancelAnimationFrame(rafID.current);\n }\n if (resizeTimeout.current) {\n clearTimeout(resizeTimeout.current);\n }\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [color]);\n\n useEffect(() => {\n onMouseMove();\n }, [mousePosition.x, mousePosition.y]);\n\n useEffect(() => {\n initCanvas();\n }, [refresh]);\n\n const initCanvas = () => {\n resizeCanvas();\n drawParticles();\n };\n\n const onMouseMove = () => {\n if (canvasRef.current) {\n const rect = canvasRef.current.getBoundingClientRect();\n const { w, h } = canvasSize.current;\n const x = mousePosition.x - rect.left - w / 2;\n const y = mousePosition.y - rect.top - h / 2;\n const inside = x < w / 2 && x > -w / 2 && y < h / 2 && y > -h / 2;\n if (inside) {\n mouse.current.x = x;\n mouse.current.y = y;\n }\n }\n };\n\n const resizeCanvas = () => {\n if (canvasContainerRef.current && canvasRef.current && context.current) {\n canvasSize.current.w = canvasContainerRef.current.offsetWidth;\n canvasSize.current.h = canvasContainerRef.current.offsetHeight;\n\n canvasRef.current.width = canvasSize.current.w * dpr;\n canvasRef.current.height = canvasSize.current.h * dpr;\n canvasRef.current.style.width = `${canvasSize.current.w}px`;\n canvasRef.current.style.height = `${canvasSize.current.h}px`;\n context.current.scale(dpr, dpr);\n\n // Clear existing particles and create new ones with exact quantity\n circles.current = [];\n for (let i = 0; i < quantity; i++) {\n const circle = circleParams();\n drawCircle(circle);\n }\n }\n };\n\n const circleParams = (): Circle => {\n const x = Math.floor(Math.random() * canvasSize.current.w);\n const y = Math.floor(Math.random() * canvasSize.current.h);\n const translateX = 0;\n const translateY = 0;\n const pSize = Math.floor(Math.random() * 2) + size;\n const alpha = 0;\n const targetAlpha = parseFloat((Math.random() * 0.6 + 0.1).toFixed(1));\n const dx = (Math.random() - 0.5) * 0.1;\n const dy = (Math.random() - 0.5) * 0.1;\n const magnetism = 0.1 + Math.random() * 4;\n return {\n x,\n y,\n translateX,\n translateY,\n size: pSize,\n alpha,\n targetAlpha,\n dx,\n dy,\n magnetism,\n };\n };\n\n const rgb = hexToRgb(color);\n\n const drawCircle = (circle: Circle, update = false) => {\n if (context.current) {\n const { x, y, translateX, translateY, size, alpha } = circle;\n context.current.translate(translateX, translateY);\n context.current.beginPath();\n context.current.arc(x, y, size, 0, 2 * Math.PI);\n context.current.fillStyle = `rgba(${rgb.join(\", \")}, ${alpha})`;\n context.current.fill();\n context.current.setTransform(dpr, 0, 0, dpr, 0, 0);\n\n if (!update) {\n circles.current.push(circle);\n }\n }\n };\n\n const clearContext = () => {\n if (context.current) {\n context.current.clearRect(\n 0,\n 0,\n canvasSize.current.w,\n canvasSize.current.h,\n );\n }\n };\n\n const drawParticles = () => {\n clearContext();\n const particleCount = quantity;\n for (let i = 0; i < particleCount; i++) {\n const circle = circleParams();\n drawCircle(circle);\n }\n };\n\n const remapValue = (\n value: number,\n start1: number,\n end1: number,\n start2: number,\n end2: number,\n ): number => {\n const remapped =\n ((value - start1) * (end2 - start2)) / (end1 - start1) + start2;\n return remapped > 0 ? remapped : 0;\n };\n\n const animate = () => {\n clearContext();\n circles.current.forEach((circle: Circle, i: number) => {\n // Handle the alpha value\n const edge = [\n circle.x + circle.translateX - circle.size, // distance from left edge\n canvasSize.current.w - circle.x - circle.translateX - circle.size, // distance from right edge\n circle.y + circle.translateY - circle.size, // distance from top edge\n canvasSize.current.h - circle.y - circle.translateY - circle.size, // distance from bottom edge\n ];\n const closestEdge = edge.reduce((a, b) => Math.min(a, b));\n const remapClosestEdge = parseFloat(\n remapValue(closestEdge, 0, 20, 0, 1).toFixed(2),\n );\n if (remapClosestEdge > 1) {\n circle.alpha += 0.02;\n if (circle.alpha > circle.targetAlpha) {\n circle.alpha = circle.targetAlpha;\n }\n } else {\n circle.alpha = circle.targetAlpha * remapClosestEdge;\n }\n circle.x += circle.dx + vx;\n circle.y += circle.dy + vy;\n circle.translateX +=\n (mouse.current.x / (staticity / circle.magnetism) - circle.translateX) /\n ease;\n circle.translateY +=\n (mouse.current.y / (staticity / circle.magnetism) - circle.translateY) /\n ease;\n\n drawCircle(circle, true);\n\n // circle gets out of the canvas\n if (\n circle.x < -circle.size ||\n circle.x > canvasSize.current.w + circle.size ||\n circle.y < -circle.size ||\n circle.y > canvasSize.current.h + circle.size\n ) {\n // remove the circle from the array\n circles.current.splice(i, 1);\n // create a new circle\n const newCircle = circleParams();\n drawCircle(newCircle);\n }\n });\n rafID.current = window.requestAnimationFrame(animate);\n };\n\n return (\n <div\n className={cn(\"pointer-events-none\", className)}\n ref={canvasContainerRef}\n aria-hidden=\"true\"\n {...props}\n >\n <canvas ref={canvasRef} className=\"size-full\" />\n </div>\n );\n};\n",
+ "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport React, {\n ComponentPropsWithoutRef,\n useEffect,\n useRef,\n useState,\n} from \"react\";\n\ninterface MousePosition {\n x: number;\n y: number;\n}\n\nfunction MousePosition(): MousePosition {\n const [mousePosition, setMousePosition] = useState<MousePosition>({\n x: 0,\n y: 0,\n });\n\n useEffect(() => {\n const handleMouseMove = (event: MouseEvent) => {\n setMousePosition({ x: event.clientX, y: event.clientY });\n };\n\n window.addEventListener(\"mousemove\", handleMouseMove);\n\n return () => {\n window.removeEventListener(\"mousemove\", handleMouseMove);\n };\n }, []);\n\n return mousePosition;\n}\n\ninterface ParticlesProps extends ComponentPropsWithoutRef<\"div\"> {\n className?: string;\n quantity?: number;\n staticity?: number;\n ease?: number;\n size?: number;\n refresh?: boolean;\n color?: string;\n vx?: number;\n vy?: number;\n}\n\nfunction hexToRgb(hex: string): number[] {\n hex = hex.replace(\"#\", \"\");\n\n if (hex.length === 3) {\n hex = hex\n .split(\"\")\n .map((char) => char + char)\n .join(\"\");\n }\n\n const hexInt = parseInt(hex, 16);\n const red = (hexInt >> 16) & 255;\n const green = (hexInt >> 8) & 255;\n const blue = hexInt & 255;\n return [red, green, blue];\n}\n\ntype Circle = {\n x: number;\n y: number;\n translateX: number;\n translateY: number;\n size: number;\n alpha: number;\n targetAlpha: number;\n dx: number;\n dy: number;\n magnetism: number;\n};\n\nexport const Particles: React.FC<ParticlesProps> = ({\n className = \"\",\n quantity = 100,\n staticity = 50,\n ease = 50,\n size = 0.4,\n refresh = false,\n color = \"#ffffff\",\n vx = 0,\n vy = 0,\n ...props\n}) => {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const canvasContainerRef = useRef<HTMLDivElement>(null);\n const context = useRef<CanvasRenderingContext2D | null>(null);\n const circles = useRef<Circle[]>([]);\n const mousePosition = MousePosition();\n const mouse = useRef<{ x: number; y: number }>({ x: 0, y: 0 });\n const canvasSize = useRef<{ w: number; h: number }>({ w: 0, h: 0 });\n const dpr = typeof window !== \"undefined\" ? window.devicePixelRatio : 1;\n const rafID = useRef<number | null>(null);\n const resizeTimeout = useRef<NodeJS.Timeout | null>(null);\n\n useEffect(() => {\n if (canvasRef.current) {\n context.current = canvasRef.current.getContext(\"2d\");\n }\n initCanvas();\n animate();\n\n const handleResize = () => {\n if (resizeTimeout.current) {\n clearTimeout(resizeTimeout.current);\n }\n resizeTimeout.current = setTimeout(() => {\n initCanvas();\n }, 200);\n };\n\n window.addEventListener(\"resize\", handleResize);\n\n return () => {\n if (rafID.current != null) {\n window.cancelAnimationFrame(rafID.current);\n }\n if (resizeTimeout.current) {\n clearTimeout(resizeTimeout.current);\n }\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [color]);\n\n useEffect(() => {\n onMouseMove();\n }, [mousePosition.x, mousePosition.y]);\n\n useEffect(() => {\n initCanvas();\n }, [refresh]);\n\n const initCanvas = () => {\n resizeCanvas();\n drawParticles();\n };\n\n const onMouseMove = () => {\n if (canvasRef.current) {\n const rect = canvasRef.current.getBoundingClientRect();\n const { w, h } = canvasSize.current;\n const x = mousePosition.x - rect.left - w / 2;\n const y = mousePosition.y - rect.top - h / 2;\n const inside = x < w / 2 && x > -w / 2 && y < h / 2 && y > -h / 2;\n if (inside) {\n mouse.current.x = x;\n mouse.current.y = y;\n }\n }\n };\n\n const resizeCanvas = () => {\n if (canvasContainerRef.current && canvasRef.current && context.current) {\n canvasSize.current.w = canvasContainerRef.current.offsetWidth;\n canvasSize.current.h = canvasContainerRef.current.offsetHeight;\n\n canvasRef.current.width = canvasSize.current.w * dpr;\n canvasRef.current.height = canvasSize.current.h * dpr;\n canvasRef.current.style.width = `${canvasSize.current.w}px`;\n canvasRef.current.style.height = `${canvasSize.current.h}px`;\n context.current.scale(dpr, dpr);\n\n // Clear existing particles and create new ones with exact quantity\n circles.current = [];\n for (let i = 0; i < quantity; i++) {\n const circle = circleParams();\n drawCircle(circle);\n }\n }\n };\n\n const circleParams = (): Circle => {\n const x = Math.floor(Math.random() * canvasSize.current.w);\n const y = Math.floor(Math.random() * canvasSize.current.h);\n const translateX = 0;\n const translateY = 0;\n const pSize = Math.floor(Math.random() * 2) + size;\n const alpha = 0;\n const targetAlpha = parseFloat((Math.random() * 0.6 + 0.1).toFixed(1));\n const dx = (Math.random() - 0.5) * 0.1;\n const dy = (Math.random() - 0.5) * 0.1;\n const magnetism = 0.1 + Math.random() * 4;\n return {\n x,\n y,\n translateX,\n translateY,\n size: pSize,\n alpha,\n targetAlpha,\n dx,\n dy,\n magnetism,\n };\n };\n\n const rgb = hexToRgb(color);\n\n const drawCircle = (circle: Circle, update = false) => {\n if (context.current) {\n const { x, y, translateX, translateY, size, alpha } = circle;\n context.current.translate(translateX, translateY);\n context.current.beginPath();\n context.current.arc(x, y, size, 0, 2 * Math.PI);\n context.current.fillStyle = `rgba(${rgb.join(\", \")}, ${alpha})`;\n context.current.fill();\n context.current.setTransform(dpr, 0, 0, dpr, 0, 0);\n\n if (!update) {\n circles.current.push(circle);\n }\n }\n };\n\n const clearContext = () => {\n if (context.current) {\n context.current.clearRect(\n 0,\n 0,\n canvasSize.current.w,\n canvasSize.current.h,\n );\n }\n };\n\n const drawParticles = () => {\n clearContext();\n const particleCount = quantity;\n for (let i = 0; i < particleCount; i++) {\n const circle = circleParams();\n drawCircle(circle);\n }\n };\n\n const remapValue = (\n value: number,\n start1: number,\n end1: number,\n start2: number,\n end2: number,\n ): number => {\n const remapped =\n ((value - start1) * (end2 - start2)) / (end1 - start1) + start2;\n return remapped > 0 ? remapped : 0;\n };\n\n const animate = () => {\n clearContext();\n circles.current.forEach((circle: Circle, i: number) => {\n // Handle the alpha value\n const edge = [\n circle.x + circle.translateX - circle.size, // distance from left edge\n canvasSize.current.w - circle.x - circle.translateX - circle.size, // distance from right edge\n circle.y + circle.translateY - circle.size, // distance from top edge\n canvasSize.current.h - circle.y - circle.translateY - circle.size, // distance from bottom edge\n ];\n const closestEdge = edge.reduce((a, b) => Math.min(a, b));\n const remapClosestEdge = parseFloat(\n remapValue(closestEdge, 0, 20, 0, 1).toFixed(2),\n );\n if (remapClosestEdge > 1) {\n circle.alpha += 0.02;\n if (circle.alpha > circle.targetAlpha) {\n circle.alpha = circle.targetAlpha;\n }\n } else {\n circle.alpha = circle.targetAlpha * remapClosestEdge;\n }\n circle.x += circle.dx + vx;\n circle.y += circle.dy + vy;\n circle.translateX +=\n (mouse.current.x / (staticity / circle.magnetism) - circle.translateX) /\n ease;\n circle.translateY +=\n (mouse.current.y / (staticity / circle.magnetism) - circle.translateY) /\n ease;\n\n drawCircle(circle, true);\n\n // circle gets out of the canvas\n if (\n circle.x < -circle.size ||\n circle.x > canvasSize.current.w + circle.size ||\n circle.y < -circle.size ||\n circle.y > canvasSize.current.h + circle.size\n ) {\n // remove the circle from the array\n circles.current.splice(i, 1);\n // create a new circle\n const newCircle = circleParams();\n drawCircle(newCircle);\n }\n });\n rafID.current = window.requestAnimationFrame(animate);\n };\n\n return (\n <div\n className={cn(\"pointer-events-none\", className)}\n ref={canvasContainerRef}\n aria-hidden=\"true\"\n {...props}\n >\n <canvas ref={canvasRef} className=\"size-full\" />\n </div>\n );\n};\n",
"type": "registry:ui",
"target": "components/magicui/particles.tsx"
}
diff --git a/public/r/shine-border.json b/public/r/shine-border.json
index 8785fbe7..f86bc5f2 100644
--- a/public/r/shine-border.json
+++ b/public/r/shine-border.json
@@ -7,7 +7,7 @@
"files": [
{
"path": "registry/magicui/shine-border.tsx",
- "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport * as React from \"react\";\n\ninterface ShineBorderProps extends React.HTMLAttributes<HTMLDivElement> {\n /**\n * Width of the border in pixels\n * @default 1\n */\n borderWidth?: number;\n /**\n * Duration of the animation in seconds\n * @default 14\n */\n duration?: number;\n /**\n * Color of the border, can be a single color or an array of colors\n * @default \"#000000\"\n */\n shineColor?: string | string[];\n}\n\n/**\n * Shine Border\n *\n * An animated background border effect component with configurable properties.\n */\nexport function ShineBorder({\n borderWidth = 1,\n duration = 14,\n shineColor = \"#000000\",\n className,\n style,\n ...props\n}: ShineBorderProps) {\n return (\n <div\n style={\n {\n \"--border-width\": `${borderWidth}px`,\n \"--duration\": `${duration}s`,\n \"--mask-linear-gradient\": `linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)`,\n \"--background-radial-gradient\": `radial-gradient(transparent,transparent, ${Array.isArray(shineColor) ? shineColor.join(\",\") : shineColor},transparent,transparent)`,\n backgroundImage: \"var(--background-radial-gradient)\",\n backgroundSize: \"300% 300%\",\n mask: \"var(--mask-linear-gradient)\",\n WebkitMaskComposite: \"xor\",\n maskComposite: \"exclude\",\n ...style,\n } as React.CSSProperties\n }\n className={cn(\n \"pointer-events-none absolute inset-0 size-full rounded-[inherit] p-[--border-width] will-change-[background-position] motion-safe:animate-shine\",\n className,\n )}\n {...props}\n />\n );\n}\n",
+ "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface ShineBorderProps extends React.HTMLAttributes<HTMLDivElement> {\n /**\n * Width of the border in pixels\n * @default 1\n */\n borderWidth?: number;\n /**\n * Duration of the animation in seconds\n * @default 14\n */\n duration?: number;\n /**\n * Color of the border, can be a single color or an array of colors\n * @default \"#000000\"\n */\n shineColor?: string | string[];\n}\n\n/**\n * Shine Border\n *\n * An animated background border effect component with configurable properties.\n */\nexport function ShineBorder({\n borderWidth = 1,\n duration = 14,\n shineColor = \"#000000\",\n className,\n style,\n ...props\n}: ShineBorderProps) {\n return (\n <div\n style={\n {\n \"--border-width\": `${borderWidth}px`,\n \"--duration\": `${duration}s`,\n backgroundImage: `radial-gradient(transparent,transparent, ${Array.isArray(shineColor) ? shineColor.join(\",\") : shineColor},transparent,transparent)`,\n backgroundSize: \"300% 300%\",\n mask: `linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)`,\n WebkitMask: `linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)`,\n WebkitMaskComposite: \"xor\",\n maskComposite: \"exclude\",\n padding: \"var(--border-width)\",\n ...style,\n } as React.CSSProperties\n }\n className={cn(\n \"pointer-events-none absolute inset-0 size-full rounded-[inherit] will-change-[background-position] motion-safe:animate-shine\",\n className,\n )}\n {...props}\n />\n );\n}\n",
"type": "registry:ui",
"target": "components/magicui/shine-border.tsx"
}
diff --git a/public/r/text-animate.json b/public/r/text-animate.json
index 099fc6a4..c5ee4b52 100644
--- a/public/r/text-animate.json
+++ b/public/r/text-animate.json
@@ -4,7 +4,9 @@
"type": "registry:ui",
"title": "Text Animate",
"description": "A text animation component that animates text using a variety of different animations.",
- "dependencies": ["motion"],
+ "dependencies": [
+ "motion"
+ ],
"files": [
{
"path": "registry/magicui/text-animate.tsx",
@@ -13,4 +15,4 @@
"target": "components/magicui/text-animate.tsx"
}
]
-}
+}
\ No newline at end of file