UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
[Feat]: ⭐ New component - ScratchToReveal (#184)
dipeshtamang072ff582907602
diff --git a/__registry__/index.tsx b/__registry__/index.tsxindex fb115375..81112cae 100644--- a/__registry__/index.tsx+++ b/__registry__/index.tsx@@ -525,6 +525,19 @@ export const Index: Record<string, any> = {subcategory: "undefined",chunks: [],},+ "scratch-to-reveal": {+ name: "scratch-to-reveal",+ type: "registry:ui",+ registryDependencies: undefined,+ files: ["registry/default/magicui/scratch-to-reveal.tsx"],+ component: React.lazy(+ () => import("@/registry/default/magicui/scratch-to-reveal.tsx"),+ ),+ source: "",+ category: "undefined",+ subcategory: "undefined",+ chunks: [],+ },"fade-text": {name: "fade-text",type: "registry:ui",@@ -1414,6 +1427,19 @@ export const Index: Record<string, any> = {subcategory: "undefined",chunks: [],},+ "scratch-to-reveal-demo": {+ name: "scratch-to-reveal-demo",+ type: "registry:example",+ registryDependencies: ["scratch-to-reveal"],+ files: ["registry/default/example/scratch-to-reveal-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/default/example/scratch-to-reveal-demo.tsx"),+ ),+ source: "",+ category: "undefined",+ subcategory: "undefined",+ chunks: [],+ },"letter-pullup-demo": {name: "letter-pullup-demo",type: "registry:example",diff --git a/config/docs.ts b/config/docs.tsindex a7ea7bb5..f6992f29 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -201,6 +201,12 @@ export const docsConfig: DocsConfig = {items: [],label: "",},+ {+ title: "Scratch To Reveal",+ href: `/docs/components/scratch-to-reveal`,+ items: [],+ label: "New",+ },],},{diff --git a/content/docs/components/scratch-to-reveal.mdx b/content/docs/components/scratch-to-reveal.mdxnew file mode 100644index 00000000..80e16184--- /dev/null+++ b/content/docs/components/scratch-to-reveal.mdx@@ -0,0 +1,55 @@+---+title: Scratch To Reveal+date: 2024-06-28+description: The ScratchToReveal component creates an interactive scratch-off effect with customizable dimensions and animations, revealing hidden content beneath.+author: dipesh_the_dev+published: true+---++<ComponentPreview name="scratch-to-reveal-demo" />++## Installation++<Tabs defaultValue="cli">++<TabsList>+ <TabsTrigger value="cli">CLI</TabsTrigger>+ <TabsTrigger value="manual">Manual</TabsTrigger>+</TabsList>+<TabsContent value="cli">++```bash+npx shadcn@latest add "https://magicui.design/r/scratch-to-reveal"+```++</TabsContent>++<TabsContent value="manual">++<Steps>++<Step>Copy and paste the following code into your project.</Step>++<ComponentSource name="scratch-to-reveal" />++</Steps>++</TabsContent>++</Tabs>++## Props++| Prop | Type | Default | Description |+| -------------------- | -------- | ------- | --------------------------------------------------------------------------------------------- |+| className | string | | The class name to apply to the component. |+| width | number | | Width of the scratch container. |+| height | number | | Height of the scratch container. |+| minScratchPercentage | number | 50 | Minimum percentage of scratched area to be considered as completed (Value between 0 and 100). |+| children | node | | The content to display in the marquee. |+| onCompete | function | | Callback function called when scratch is completed |+| gradientColors | string[] | | Gradient colors for the scratch effect. |++## Credits++- Credit to [dipesh_the_dev](https://www.x.com/dipesh_the_dev)diff --git a/public/r/index.json b/public/r/index.jsonindex da7ef6a4..7c501ed7 100644--- a/public/r/index.json+++ b/public/r/index.json@@ -707,6 +707,19 @@}]},+ {+ "name": "scratch-to-reveal",+ "type": "registry:ui",+ "dependencies": [+ "framer-motion"+ ],+ "files": [+ {+ "path": "magicui/scratch-to-reveal.tsx",+ "type": "registry:ui"+ }+ ]+ },{"name": "fade-text","type": "registry:ui",diff --git a/public/r/styles/default/animated-grid-pattern.json b/public/r/styles/default/animated-grid-pattern.jsonindex f0a53d0e..e49b6dbc 100644--- a/public/r/styles/default/animated-grid-pattern.json+++ b/public/r/styles/default/animated-grid-pattern.json@@ -7,7 +7,7 @@"files": [{"path": "magicui/animated-grid-pattern.tsx",- "content": "\"use client\";\n\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport { motion } from \"framer-motion\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface AnimatedGridPatternProps {\n width?: number;\n height?: number;\n x?: number;\n y?: number;\n strokeDasharray?: any;\n numSquares?: number;\n className?: string;\n maxOpacity?: number;\n duration?: number;\n repeatDelay?: number;\n}\n\nexport default function AnimatedGridPattern({\n width = 40,\n height = 40,\n x = -1,\n y = -1,\n strokeDasharray = 0,\n numSquares = 50,\n className,\n maxOpacity = 0.5,\n duration = 4,\n repeatDelay = 0.5,\n ...props\n}: AnimatedGridPatternProps) {\n const id = useId();\n const containerRef = useRef(null);\n const [dimensions, setDimensions] = useState({ width: 0, height: 0 });\n const [squares, setSquares] = useState(() => generateSquares(numSquares));\n\n function getPos() {\n return [\n Math.floor((Math.random() * dimensions.width) / width),\n Math.floor((Math.random() * dimensions.height) / height),\n ];\n }\n\n // Adjust the generateSquares function to return objects with an id, x, and y\n function generateSquares(count: number) {\n return Array.from({ length: count }, (_, i) => ({\n id: i,\n pos: getPos(),\n }));\n }\n\n // Function to update a single square's position\n const updateSquarePosition = (id: number) => {\n setSquares((currentSquares) =>\n currentSquares.map((sq) =>\n sq.id === id\n ? {\n ...sq,\n pos: getPos(),\n }\n : sq\n )\n );\n };\n\n // Update squares to animate in\n useEffect(() => {\n if (dimensions.width && dimensions.height) {\n setSquares(generateSquares(numSquares));\n }\n }, [dimensions, numSquares]);\n\n // Resize observer to update container dimensions\n useEffect(() => {\n const resizeObserver = new ResizeObserver((entries) => {\n for (let entry of entries) {\n setDimensions({\n width: entry.contentRect.width,\n height: entry.contentRect.height,\n });\n }\n });\n\n if (containerRef.current) {\n resizeObserver.observe(containerRef.current);\n }\n\n return () => {\n if (containerRef.current) {\n resizeObserver.unobserve(containerRef.current);\n }\n };\n }, [containerRef]);\n\n return (\n <svg\n ref={containerRef}\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none absolute inset-0 h-full w-full fill-gray-400/30 stroke-gray-400/30\",\n className\n )}\n {...props}\n >\n <defs>\n <pattern\n id={id}\n width={width}\n height={height}\n patternUnits=\"userSpaceOnUse\"\n x={x}\n y={y}\n >\n <path\n d={`M.5 ${height}V.5H${width}`}\n fill=\"none\"\n strokeDasharray={strokeDasharray}\n />\n </pattern>\n </defs>\n <rect width=\"100%\" height=\"100%\" fill={`url(#${id})`} />\n <svg x={x} y={y} className=\"overflow-visible\">\n {squares.map(({ pos: [x, y], id }, index) => (\n <motion.rect\n initial={{ opacity: 0 }}\n animate={{ opacity: maxOpacity }}\n transition={{\n duration,\n repeat: 1,\n delay: index * 0.1,\n repeatType: \"reverse\",\n }}\n onAnimationComplete={() => updateSquarePosition(id)}\n key={`${x}-${y}-${index}`}\n width={width - 1}\n height={height - 1}\n x={x * width + 1}\n y={y * height + 1}\n fill=\"currentColor\"\n strokeWidth=\"0\"\n />\n ))}\n </svg>\n </svg>\n );\n}\n",+ "content": "\"use client\";\n\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport { motion } from \"framer-motion\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface AnimatedGridPatternProps {\n width?: number;\n height?: number;\n x?: number;\n y?: number;\n strokeDasharray?: any;\n numSquares?: number;\n className?: string;\n maxOpacity?: number;\n duration?: number;\n repeatDelay?: number;\n}\n\nexport default function AnimatedGridPattern({\n width = 40,\n height = 40,\n x = -1,\n y = -1,\n strokeDasharray = 0,\n numSquares = 50,\n className,\n maxOpacity = 0.5,\n duration = 4,\n repeatDelay = 0.5,\n ...props\n}: AnimatedGridPatternProps) {\n const id = useId();\n const containerRef = useRef(null);\n const [dimensions, setDimensions] = useState({ width: 0, height: 0 });\n const [squares, setSquares] = useState(() => generateSquares(numSquares));\n\n function getPos() {\n return [\n Math.floor((Math.random() * dimensions.width) / width),\n Math.floor((Math.random() * dimensions.height) / height),\n ];\n }\n\n // Adjust the generateSquares function to return objects with an id, x, and y\n function generateSquares(count: number) {\n return Array.from({ length: count }, (_, i) => ({\n id: i,\n pos: getPos(),\n }));\n }\n\n // Function to update a single square's position\n const updateSquarePosition = (id: number) => {\n setSquares((currentSquares) =>\n currentSquares.map((sq) =>\n sq.id === id\n ? {\n ...sq,\n pos: getPos(),\n }\n : sq,\n ),\n );\n };\n\n // Update squares to animate in\n useEffect(() => {\n if (dimensions.width && dimensions.height) {\n setSquares(generateSquares(numSquares));\n }\n }, [dimensions, numSquares]);\n\n // Resize observer to update container dimensions\n useEffect(() => {\n const resizeObserver = new ResizeObserver((entries) => {\n for (let entry of entries) {\n setDimensions({\n width: entry.contentRect.width,\n height: entry.contentRect.height,\n });\n }\n });\n\n if (containerRef.current) {\n resizeObserver.observe(containerRef.current);\n }\n\n return () => {\n if (containerRef.current) {\n resizeObserver.unobserve(containerRef.current);\n }\n };\n }, [containerRef]);\n\n return (\n <svg\n ref={containerRef}\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none absolute inset-0 h-full w-full fill-gray-400/30 stroke-gray-400/30\",\n className,\n )}\n {...props}\n >\n <defs>\n <pattern\n id={id}\n width={width}\n height={height}\n patternUnits=\"userSpaceOnUse\"\n x={x}\n y={y}\n >\n <path\n d={`M.5 ${height}V.5H${width}`}\n fill=\"none\"\n strokeDasharray={strokeDasharray}\n />\n </pattern>\n </defs>\n <rect width=\"100%\" height=\"100%\" fill={`url(#${id})`} />\n <svg x={x} y={y} className=\"overflow-visible\">\n {squares.map(({ pos: [x, y], id }, index) => (\n <motion.rect\n initial={{ opacity: 0 }}\n animate={{ opacity: maxOpacity }}\n transition={{\n duration,\n repeat: 1,\n delay: index * 0.1,\n repeatType: \"reverse\",\n }}\n onAnimationComplete={() => updateSquarePosition(id)}\n key={`${x}-${y}-${index}`}\n width={width - 1}\n height={height - 1}\n x={x * width + 1}\n y={y * height + 1}\n fill=\"currentColor\"\n strokeWidth=\"0\"\n />\n ))}\n </svg>\n </svg>\n );\n}\n","type": "registry:ui","target": ""}diff --git a/public/r/styles/default/animated-list.json b/public/r/styles/default/animated-list.jsonindex 1a5e8e79..bc93de81 100644--- a/public/r/styles/default/animated-list.json+++ b/public/r/styles/default/animated-list.json@@ -7,7 +7,7 @@"files": [{"path": "magicui/animated-list.tsx",- "content": "\"use client\";\n\nimport React, { ReactElement, useEffect, useMemo, useState } from \"react\";\nimport { AnimatePresence, motion } from \"framer-motion\";\n\nexport interface AnimatedListProps {\n className?: string;\n children: React.ReactNode;\n delay?: number;\n}\n\nexport const AnimatedList = React.memo(\n ({ className, children, delay = 1000 }: AnimatedListProps) => {\n const [index, setIndex] = useState(0);\n const childrenArray = React.Children.toArray(children);\n\n useEffect(() => {\n const interval = setInterval(() => {\n setIndex((prevIndex) => (prevIndex + 1) % childrenArray.length);\n }, delay);\n\n return () => clearInterval(interval);\n }, [childrenArray.length, delay]);\n\n const itemsToShow = useMemo(\n () => childrenArray.slice(0, index + 1).reverse(),\n [index, childrenArray],\n );\n\n return (\n <div className={`flex flex-col items-center gap-4 ${className}`}>\n <AnimatePresence>\n {itemsToShow.map((item) => (\n <AnimatedListItem key={(item as ReactElement).key}>\n {item}\n </AnimatedListItem>\n ))}\n </AnimatePresence>\n </div>\n );\n },\n);\n\nAnimatedList.displayName = \"AnimatedList\";\n\nexport function AnimatedListItem({ children }: { children: React.ReactNode }) {\n const animations = {\n initial: { scale: 0, opacity: 0 },\n animate: { scale: 1, opacity: 1, originY: 0 },\n exit: { scale: 0, opacity: 0 },\n transition: { type: \"spring\", stiffness: 350, damping: 40 },\n };\n\n return (\n <motion.div {...animations} layout className=\"mx-auto w-full\">\n {children}\n </motion.div>\n );\n}\n",+ "content": "\"use client\";\n\nimport React, { ReactElement, useEffect, useMemo, useState } from \"react\";\nimport { AnimatePresence, motion } from \"framer-motion\";\n\nexport interface AnimatedListProps {\n className?: string;\n children: React.ReactNode;\n delay?: number;\n}\n\nexport const AnimatedList = React.memo(\n ({ className, children, delay = 1000 }: AnimatedListProps) => {\n const [index, setIndex] = useState(0);\n const childrenArray = useMemo(\n () => React.Children.toArray(children),\n [children],\n );\n\n useEffect(() => {\n if (index < childrenArray.length - 1) {\n const timeout = setTimeout(() => {\n setIndex((prevIndex) => prevIndex + 1);\n }, delay);\n\n return () => clearTimeout(timeout);\n }\n }, [index, delay, childrenArray.length]);\n\n const itemsToShow = useMemo(() => {\n const result = childrenArray.slice(0, index + 1).reverse();\n return result;\n }, [index, childrenArray]);\n\n return (\n <div className={`flex flex-col items-center gap-4 ${className}`}>\n <AnimatePresence>\n {itemsToShow.map((item) => (\n <AnimatedListItem key={(item as React.ReactElement).key}>\n {item}\n </AnimatedListItem>\n ))}\n </AnimatePresence>\n </div>\n );\n },\n);\n\nAnimatedList.displayName = \"AnimatedList\";\n\nexport function AnimatedListItem({ children }: { children: React.ReactNode }) {\n const animations = {\n initial: { scale: 0, opacity: 0 },\n animate: { scale: 1, opacity: 1, originY: 0 },\n exit: { scale: 0, opacity: 0 },\n transition: { type: \"spring\", stiffness: 350, damping: 40 },\n };\n\n return (\n <motion.div {...animations} layout className=\"mx-auto w-full\">\n {children}\n </motion.div>\n );\n}\n","type": "registry:ui","target": ""}diff --git a/public/r/styles/default/avatar-circles.json b/public/r/styles/default/avatar-circles.jsonindex 8ea004ac..4957e0ea 100644--- a/public/r/styles/default/avatar-circles.json+++ b/public/r/styles/default/avatar-circles.json@@ -4,7 +4,7 @@"files": [{"path": "magicui/avatar-circles.tsx",- "content": "\"use client\";\n\nimport React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface AvatarCirclesProps {\n className?: string;\n numPeople?: number;\n avatarUrls: string[];\n}\n\nconst AvatarCircles = ({\n numPeople,\n className,\n avatarUrls,\n}: AvatarCirclesProps) => {\n return (\n <div className={cn(\"z-10 flex -space-x-4 rtl:space-x-reverse\", className)}>\n {avatarUrls.map((url, index) => (\n <img\n key={index}\n className=\"h-10 w-10 rounded-full border-2 border-white dark:border-gray-800\"\n src={url}\n width={40}\n height={40}\n alt={`Avatar ${index + 1}`}\n />\n ))}\n <a\n className=\"flex h-10 w-10 items-center justify-center rounded-full border-2 border-white bg-black text-center text-xs font-medium text-white hover:bg-gray-600 dark:border-gray-800 dark:bg-white dark:text-black\"\n href=\"\"\n >\n +{numPeople}\n </a>\n </div>\n );\n};\n\nexport default AvatarCircles;\n",+ "content": "\"use client\";\n\nimport React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface Avatar {\n imageUrl: string;\n profileUrl: string;\n}\ninterface AvatarCirclesProps {\n className?: string;\n numPeople?: number;\n avatarUrls: Avatar[];\n}\n\nconst AvatarCircles = ({\n numPeople,\n className,\n avatarUrls,\n}: AvatarCirclesProps) => {\n return (\n <div className={cn(\"z-10 flex -space-x-4 rtl:space-x-reverse\", className)}>\n {avatarUrls.map((url, index) => (\n <a\n key={index}\n href={url.profileUrl}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n <img\n key={index}\n className=\"h-10 w-10 rounded-full border-2 border-white dark:border-gray-800\"\n src={url.imageUrl}\n width={40}\n height={40}\n alt={`Avatar ${index + 1}`}\n />\n </a>\n ))}\n {(numPeople ?? 0) > 0 && (\n <a\n className=\"flex h-10 w-10 items-center justify-center rounded-full border-2 border-white bg-black text-center text-xs font-medium text-white hover:bg-gray-600 dark:border-gray-800 dark:bg-white dark:text-black\"\n href=\"\"\n >\n +{numPeople}\n </a>\n )}\n </div>\n );\n};\n\nexport default AvatarCircles;\n","type": "registry:ui","target": ""}diff --git a/public/r/styles/default/blur-in.json b/public/r/styles/default/blur-in.jsonindex 1b8937ab..e6889275 100644--- a/public/r/styles/default/blur-in.json+++ b/public/r/styles/default/blur-in.json@@ -7,7 +7,7 @@"files": [{"path": "magicui/blur-in.tsx",- "content": "\"use client\";\n\nimport { motion } from \"framer-motion\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface BlurIntProps {\n word: string;\n className?: string;\n variant?: {\n hidden: { filter: string; opacity: number };\n visible: { filter: string; opacity: number };\n };\n duration?: number;\n}\nconst BlurIn = ({ word, className, variant, duration = 1 }: BlurIntProps) => {\n const defaultVariants = {\n hidden: { filter: \"blur(10px)\", opacity: 0 },\n visible: { filter: \"blur(0px)\", opacity: 1 },\n };\n const combinedVariants = variant || defaultVariants;\n\n return (\n <motion.h1\n initial=\"hidden\"\n animate=\"visible\"\n transition={{ duration }}\n variants={combinedVariants}\n className={cn(\n \"font-display text-center text-4xl font-bold tracking-[-0.02em] drop-shadow-sm md:text-7xl md:leading-[5rem]\",\n className,\n )}\n >\n {word}\n </motion.h1>\n );\n};\n\nexport default BlurIn;\n",+ "content": "\"use client\";\n\nimport { motion } from \"framer-motion\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface BlurInProps {\n word: string;\n className?: string;\n variant?: {\n hidden: { filter: string; opacity: number };\n visible: { filter: string; opacity: number };\n };\n duration?: number;\n}\nconst BlurIn = ({ word, className, variant, duration = 1 }: BlurInProps) => {\n const defaultVariants = {\n hidden: { filter: \"blur(10px)\", opacity: 0 },\n visible: { filter: \"blur(0px)\", opacity: 1 },\n };\n const combinedVariants = variant || defaultVariants;\n\n return (\n <motion.h1\n initial=\"hidden\"\n animate=\"visible\"\n transition={{ duration }}\n variants={combinedVariants}\n className={cn(\n \"font-display text-center text-4xl font-bold tracking-[-0.02em] drop-shadow-sm md:text-7xl md:leading-[5rem]\",\n className,\n )}\n >\n {word}\n </motion.h1>\n );\n};\n\nexport default BlurIn;\n","type": "registry:ui","target": ""}diff --git a/public/r/styles/default/flickering-grid.json b/public/r/styles/default/flickering-grid.jsonindex 090bb281..716a646b 100644--- a/public/r/styles/default/flickering-grid.json+++ b/public/r/styles/default/flickering-grid.json@@ -7,7 +7,7 @@"files": [{"path": "magicui/flickering-grid.tsx",- "content": "\"use client\";\n\nimport React, {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\ninterface FlickeringGridProps {\n squareSize?: number;\n gridGap?: number;\n flickerChance?: number;\n color?: string;\n width?: number;\n height?: number;\n className?: string;\n maxOpacity?: number;\n}\n\nconst FlickeringGrid: React.FC<FlickeringGridProps> = ({\n squareSize = 4,\n gridGap = 6,\n flickerChance = 0.3,\n color = \"rgb(0, 0, 0)\",\n width,\n height,\n className,\n maxOpacity = 0.3,\n}) => {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const [isInView, setIsInView] = useState(false);\n\n const memoizedColor = useMemo(() => {\n const toRGBA = (color: string) => {\n if (typeof window === \"undefined\") {\n return `rgba(0, 0, 0,`;\n }\n const canvas = document.createElement(\"canvas\");\n canvas.width = canvas.height = 1;\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) return \"rgba(255, 0, 0,\";\n ctx.fillStyle = color;\n ctx.fillRect(0, 0, 1, 1);\n const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;\n return `rgba(${r}, ${g}, ${b},`;\n };\n return toRGBA(color);\n }, [color]);\n\n const setupCanvas = useCallback(\n (canvas: HTMLCanvasElement) => {\n const canvasWidth = width || canvas.clientWidth;\n const canvasHeight = height || canvas.clientHeight;\n const dpr = window.devicePixelRatio || 1;\n canvas.width = canvasWidth * dpr;\n canvas.height = canvasHeight * dpr;\n canvas.style.width = `${canvasWidth}px`;\n canvas.style.height = `${canvasHeight}px`;\n const cols = Math.floor(canvasWidth / (squareSize + gridGap));\n const rows = Math.floor(canvasHeight / (squareSize + gridGap));\n\n const squares = new Float32Array(cols * rows);\n for (let i = 0; i < squares.length; i++) {\n squares[i] = Math.random() * maxOpacity;\n }\n\n return {\n width: canvasWidth,\n height: canvasHeight,\n cols,\n rows,\n squares,\n dpr,\n };\n },\n [squareSize, gridGap, width, height, maxOpacity],\n );\n\n const updateSquares = useCallback(\n (squares: Float32Array, deltaTime: number) => {\n for (let i = 0; i < squares.length; i++) {\n if (Math.random() < flickerChance * deltaTime) {\n squares[i] = Math.random() * maxOpacity;\n }\n }\n },\n [flickerChance, maxOpacity],\n );\n\n const drawGrid = useCallback(\n (\n ctx: CanvasRenderingContext2D,\n width: number,\n height: number,\n cols: number,\n rows: number,\n squares: Float32Array,\n dpr: number,\n ) => {\n ctx.clearRect(0, 0, width, height);\n ctx.fillStyle = \"transparent\";\n ctx.fillRect(0, 0, width, height);\n\n for (let i = 0; i < cols; i++) {\n for (let j = 0; j < rows; j++) {\n const opacity = squares[i * rows + j];\n ctx.fillStyle = `${memoizedColor}${opacity})`;\n ctx.fillRect(\n i * (squareSize + gridGap) * dpr,\n j * (squareSize + gridGap) * dpr,\n squareSize * dpr,\n squareSize * dpr,\n );\n }\n }\n },\n [memoizedColor, squareSize, gridGap],\n );\n\n useEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas) return;\n\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) return;\n\n let animationFrameId: number;\n let { width, height, cols, rows, squares, dpr } = setupCanvas(canvas);\n\n let lastTime = 0;\n const animate = (time: number) => {\n if (!isInView) return;\n\n const deltaTime = (time - lastTime) / 1000;\n lastTime = time;\n\n updateSquares(squares, deltaTime);\n drawGrid(ctx, width * dpr, height * dpr, cols, rows, squares, dpr);\n animationFrameId = requestAnimationFrame(animate);\n };\n\n const handleResize = () => {\n ({ width, height, cols, rows, squares, dpr } = setupCanvas(canvas));\n };\n\n const observer = new IntersectionObserver(\n ([entry]) => {\n setIsInView(entry.isIntersecting);\n },\n { threshold: 0 },\n );\n\n observer.observe(canvas);\n\n window.addEventListener(\"resize\", handleResize);\n\n if (isInView) {\n animationFrameId = requestAnimationFrame(animate);\n }\n\n return () => {\n window.removeEventListener(\"resize\", handleResize);\n cancelAnimationFrame(animationFrameId);\n observer.disconnect();\n };\n }, [setupCanvas, updateSquares, drawGrid, width, height, isInView]);\n\n return (\n <canvas\n ref={canvasRef}\n className={`size-full pointer-events-none ${className}`}\n style={{\n width: width || \"100%\",\n height: height || \"100%\",\n }}\n width={width}\n height={height}\n />\n );\n};\n\nexport default FlickeringGrid;\n",+ "content": "\"use client\";\n\nimport React, {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\ninterface FlickeringGridProps {\n squareSize?: number;\n gridGap?: number;\n flickerChance?: number;\n color?: string;\n width?: number;\n height?: number;\n className?: string;\n\n maxOpacity?: number;\n}\n\nconst FlickeringGrid: React.FC<FlickeringGridProps> = ({\n squareSize = 4,\n gridGap = 6,\n flickerChance = 0.3,\n color = \"rgb(0, 0, 0)\",\n width,\n height,\n className,\n maxOpacity = 0.3,\n}) => {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [isInView, setIsInView] = useState(false);\n const [canvasSize, setCanvasSize] = useState({ width: 0, height: 0 });\n\n const memoizedColor = useMemo(() => {\n const toRGBA = (color: string) => {\n if (typeof window === \"undefined\") {\n return `rgba(0, 0, 0,`;\n }\n const canvas = document.createElement(\"canvas\");\n canvas.width = canvas.height = 1;\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) return \"rgba(255, 0, 0,\";\n ctx.fillStyle = color;\n ctx.fillRect(0, 0, 1, 1);\n const [r, g, b] = Array.from(ctx.getImageData(0, 0, 1, 1).data);\n return `rgba(${r}, ${g}, ${b},`;\n };\n return toRGBA(color);\n }, [color]);\n\n const setupCanvas = useCallback(\n (canvas: HTMLCanvasElement, width: number, height: number) => {\n const dpr = window.devicePixelRatio || 1;\n canvas.width = width * dpr;\n canvas.height = height * dpr;\n canvas.style.width = `${width}px`;\n canvas.style.height = `${height}px`;\n const cols = Math.floor(width / (squareSize + gridGap));\n const rows = Math.floor(height / (squareSize + gridGap));\n\n const squares = new Float32Array(cols * rows);\n for (let i = 0; i < squares.length; i++) {\n squares[i] = Math.random() * maxOpacity;\n }\n\n return { cols, rows, squares, dpr };\n },\n [squareSize, gridGap, maxOpacity],\n );\n\n const updateSquares = useCallback(\n (squares: Float32Array, deltaTime: number) => {\n for (let i = 0; i < squares.length; i++) {\n if (Math.random() < flickerChance * deltaTime) {\n squares[i] = Math.random() * maxOpacity;\n }\n }\n },\n [flickerChance, maxOpacity],\n );\n\n const drawGrid = useCallback(\n (\n ctx: CanvasRenderingContext2D,\n width: number,\n height: number,\n cols: number,\n rows: number,\n squares: Float32Array,\n dpr: number,\n ) => {\n ctx.clearRect(0, 0, width, height);\n ctx.fillStyle = \"transparent\";\n ctx.fillRect(0, 0, width, height);\n\n for (let i = 0; i < cols; i++) {\n for (let j = 0; j < rows; j++) {\n const opacity = squares[i * rows + j];\n ctx.fillStyle = `${memoizedColor}${opacity})`;\n ctx.fillRect(\n i * (squareSize + gridGap) * dpr,\n j * (squareSize + gridGap) * dpr,\n squareSize * dpr,\n squareSize * dpr,\n );\n }\n }\n },\n [memoizedColor, squareSize, gridGap],\n );\n\n useEffect(() => {\n const canvas = canvasRef.current;\n const container = containerRef.current;\n if (!canvas || !container) return;\n\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) return;\n\n let animationFrameId: number;\n let gridParams: ReturnType<typeof setupCanvas>;\n\n const updateCanvasSize = () => {\n const newWidth = width || container.clientWidth;\n const newHeight = height || container.clientHeight;\n setCanvasSize({ width: newWidth, height: newHeight });\n gridParams = setupCanvas(canvas, newWidth, newHeight);\n };\n\n updateCanvasSize();\n\n let lastTime = 0;\n const animate = (time: number) => {\n if (!isInView) return;\n\n const deltaTime = (time - lastTime) / 1000;\n lastTime = time;\n\n updateSquares(gridParams.squares, deltaTime);\n drawGrid(\n ctx,\n canvas.width,\n canvas.height,\n gridParams.cols,\n gridParams.rows,\n gridParams.squares,\n gridParams.dpr,\n );\n animationFrameId = requestAnimationFrame(animate);\n };\n\n const resizeObserver = new ResizeObserver(() => {\n updateCanvasSize();\n });\n\n resizeObserver.observe(container);\n\n const intersectionObserver = new IntersectionObserver(\n ([entry]) => {\n setIsInView(entry.isIntersecting);\n },\n { threshold: 0 },\n );\n\n intersectionObserver.observe(canvas);\n\n if (isInView) {\n animationFrameId = requestAnimationFrame(animate);\n }\n\n return () => {\n cancelAnimationFrame(animationFrameId);\n resizeObserver.disconnect();\n intersectionObserver.disconnect();\n };\n }, [setupCanvas, updateSquares, drawGrid, width, height, isInView]);\n\n return (\n <div ref={containerRef} className={`w-full h-full ${className}`}>\n <canvas\n ref={canvasRef}\n className=\"pointer-events-none\"\n style={{\n width: canvasSize.width,\n height: canvasSize.height,\n }}\n />\n </div>\n );\n};\n\nexport default FlickeringGrid;\n","type": "registry:ui","target": ""}diff --git a/public/r/styles/default/hyper-text.json b/public/r/styles/default/hyper-text.jsonindex 10dea453..c043d103 100644--- a/public/r/styles/default/hyper-text.json+++ b/public/r/styles/default/hyper-text.json@@ -7,7 +7,7 @@"files": [{"path": "magicui/hyper-text.tsx",- "content": "\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { AnimatePresence, motion, Variants } from \"framer-motion\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface HyperTextProps {\n text: string;\n duration?: number;\n framerProps?: Variants;\n className?: string;\n animateOnLoad?: boolean;\n}\n\nconst alphabets = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\");\n\nconst getRandomInt = (max: number) => Math.floor(Math.random() * max);\n\nexport default function HyperText({\n text,\n duration = 800,\n framerProps = {\n initial: { opacity: 0, y: -10 },\n animate: { opacity: 1, y: 0 },\n exit: { opacity: 0, y: 3 },\n },\n className,\n animateOnLoad = true,\n}: HyperTextProps) {\n const [displayText, setDisplayText] = useState(text.split(\"\"));\n const [trigger, setTrigger] = useState(false);\n const interations = useRef(0);\n const isFirstRender = useRef(true);\n\n const triggerAnimation = () => {\n interations.current = 0;\n setTrigger(true);\n };\n\n useEffect(() => {\n const interval = setInterval(\n () => {\n if (!animateOnLoad && isFirstRender.current) {\n clearInterval(interval);\n isFirstRender.current = false;\n return;\n }\n if (interations.current < text.length) {\n setDisplayText((t) =>\n t.map((l, i) =>\n l === \" \"\n ? l\n : i <= interations.current\n ? text[i]\n : alphabets[getRandomInt(26)],\n ),\n );\n interations.current = interations.current + 0.1;\n } else {\n setTrigger(false);\n clearInterval(interval);\n }\n },\n duration / (text.length * 10),\n );\n // Clean up interval on unmount\n return () => clearInterval(interval);\n }, [text, duration, trigger, animateOnLoad]);\n\n return (\n <div\n className=\"overflow-hidden py-2 flex cursor-default scale-100\"\n onMouseEnter={triggerAnimation}\n >\n <AnimatePresence mode=\"wait\">\n {displayText.map((letter, i) => (\n <motion.h1\n key={i}\n className={cn(\"font-mono\", letter === \" \" ? \"w-3\" : \"\", className)}\n {...framerProps}\n >\n {letter.toUpperCase()}\n </motion.h1>\n ))}\n </AnimatePresence>\n </div>\n );\n}\n",+ "content": "\"use client\";\n\nimport { AnimatePresence, motion, Variants } from \"framer-motion\";\nimport { useEffect, useRef, useState } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface HyperTextProps {\n text: string;\n duration?: number;\n framerProps?: Variants;\n className?: string;\n animateOnLoad?: boolean;\n}\n\nconst alphabets = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\");\n\nconst getRandomInt = (max: number) => Math.floor(Math.random() * max);\n\nexport default function HyperText({\n text,\n duration = 800,\n framerProps = {\n initial: { opacity: 0, y: -10 },\n animate: { opacity: 1, y: 0 },\n exit: { opacity: 0, y: 3 },\n },\n className,\n animateOnLoad = true,\n}: HyperTextProps) {\n const [displayText, setDisplayText] = useState(text.split(\"\"));\n const [trigger, setTrigger] = useState(false);\n const interations = useRef(0);\n const isFirstRender = useRef(true);\n\n const triggerAnimation = () => {\n interations.current = 0;\n setTrigger(true);\n };\n\n useEffect(() => {\n const interval = setInterval(\n () => {\n if (!animateOnLoad && isFirstRender.current) {\n clearInterval(interval);\n isFirstRender.current = false;\n return;\n }\n if (interations.current < text.length) {\n setDisplayText((t) =>\n t.map((l, i) =>\n l === \" \"\n ? l\n : i <= interations.current\n ? text[i]\n : alphabets[getRandomInt(26)],\n ),\n );\n interations.current = interations.current + 0.1;\n } else {\n setTrigger(false);\n clearInterval(interval);\n }\n },\n duration / (text.length * 10),\n );\n // Clean up interval on unmount\n return () => clearInterval(interval);\n }, [text, duration, trigger, animateOnLoad]);\n\n return (\n <div\n className=\"flex scale-100 cursor-default overflow-hidden py-2\"\n onMouseEnter={triggerAnimation}\n >\n <AnimatePresence mode=\"wait\">\n {displayText.map((letter, i) => (\n <motion.span\n key={i}\n className={cn(\"font-mono\", letter === \" \" ? \"w-3\" : \"\", className)}\n {...framerProps}\n >\n {letter.toUpperCase()}\n </motion.span>\n ))}\n </AnimatePresence>\n </div>\n );\n}\n","type": "registry:ui","target": ""}diff --git a/public/r/styles/default/magic-card.json b/public/r/styles/default/magic-card.jsonindex a9770277..8d93efa6 100644--- a/public/r/styles/default/magic-card.json+++ b/public/r/styles/default/magic-card.json@@ -7,7 +7,7 @@"files": [{"path": "magicui/magic-card.tsx",- "content": "\"use client\";\n\nimport React, { useCallback, useEffect } from \"react\";\nimport { motion, useMotionTemplate, useMotionValue } from \"framer-motion\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface MagicCardProps extends React.HTMLAttributes<HTMLDivElement> {\n gradientSize?: number;\n gradientColor?: string;\n gradientOpacity?: number;\n}\n\nexport function MagicCard({\n children,\n className,\n gradientSize = 200,\n gradientColor = \"#262626\",\n gradientOpacity = 0.8,\n}: MagicCardProps) {\n const mouseX = useMotionValue(-gradientSize);\n const mouseY = useMotionValue(-gradientSize);\n\n const handleMouseMove = useCallback(\n (e: React.MouseEvent<HTMLDivElement>) => {\n const { left, top } = e.currentTarget.getBoundingClientRect();\n mouseX.set(e.clientX - left);\n mouseY.set(e.clientY - top);\n },\n [mouseX, mouseY],\n );\n\n const handleMouseLeave = useCallback(() => {\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }, [mouseX, mouseY, gradientSize]);\n\n useEffect(() => {\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }, [mouseX, mouseY, gradientSize]);\n\n return (\n <div\n onMouseMove={handleMouseMove}\n onMouseLeave={handleMouseLeave}\n className={cn(\n \"group relative flex size-full overflow-hidden rounded-xl bg-neutral-100 dark:bg-neutral-900 border text-black dark:text-white\",\n className,\n )}\n >\n <div className=\"relative z-10\">{children}</div>\n <motion.div\n className=\"pointer-events-none absolute -inset-px rounded-xl opacity-0 transition-opacity duration-300 group-hover:opacity-100\"\n style={{\n background: useMotionTemplate`\n radial-gradient(${gradientSize}px circle at ${mouseX}px ${mouseY}px, ${gradientColor}, transparent 100%)\n `,\n opacity: gradientOpacity,\n }}\n />\n </div>\n );\n}\n",+ "content": "\"use client\";\n\nimport React, { useCallback, useEffect, useRef } from \"react\";\nimport { motion, useMotionTemplate, useMotionValue } from \"framer-motion\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface MagicCardProps extends React.HTMLAttributes<HTMLDivElement> {\n gradientSize?: number;\n gradientColor?: string;\n gradientOpacity?: number;\n}\n\nexport function MagicCard({\n children,\n className,\n gradientSize = 200,\n gradientColor = \"#262626\",\n gradientOpacity = 0.8,\n}: MagicCardProps) {\n const cardRef = useRef<HTMLDivElement>(null);\n const mouseX = useMotionValue(-gradientSize);\n const mouseY = useMotionValue(-gradientSize);\n\n const handleMouseMove = useCallback(\n (e: MouseEvent) => {\n if (cardRef.current) {\n const { left, top } = cardRef.current.getBoundingClientRect();\n const clientX = e.clientX;\n const clientY = e.clientY;\n mouseX.set(clientX - left);\n mouseY.set(clientY - top);\n }\n },\n [mouseX, mouseY],\n );\n\n const handleMouseOut = useCallback(\n (e: MouseEvent) => {\n if (!e.relatedTarget) {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }\n },\n [handleMouseMove, mouseX, gradientSize, mouseY],\n );\n\n const handleMouseEnter = useCallback(() => {\n document.addEventListener(\"mousemove\", handleMouseMove);\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }, [handleMouseMove, mouseX, gradientSize, mouseY]);\n\n useEffect(() => {\n document.addEventListener(\"mousemove\", handleMouseMove);\n document.addEventListener(\"mouseout\", handleMouseOut);\n document.addEventListener(\"mouseenter\", handleMouseEnter);\n\n return () => {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n document.removeEventListener(\"mouseout\", handleMouseOut);\n document.removeEventListener(\"mouseenter\", handleMouseEnter);\n };\n }, [handleMouseEnter, handleMouseMove, handleMouseOut]);\n\n useEffect(() => {\n mouseX.set(-gradientSize);\n mouseY.set(-gradientSize);\n }, [gradientSize, mouseX, mouseY]);\n\n return (\n <div\n ref={cardRef}\n className={cn(\n \"group relative flex size-full overflow-hidden rounded-xl bg-neutral-100 dark:bg-neutral-900 border text-black dark:text-white\",\n className,\n )}\n >\n <div className=\"relative z-10\">{children}</div>\n <motion.div\n className=\"pointer-events-none absolute -inset-px rounded-xl opacity-0 transition-opacity duration-300 group-hover:opacity-100\"\n style={{\n background: useMotionTemplate`\n radial-gradient(${gradientSize}px circle at ${mouseX}px ${mouseY}px, ${gradientColor}, transparent 100%)\n `,\n opacity: gradientOpacity,\n }}\n />\n </div>\n );\n}\n","type": "registry:ui","target": ""}diff --git a/public/r/styles/default/rainbow-button.json b/public/r/styles/default/rainbow-button.jsonindex 528ac8c9..ff3fe9c4 100644--- a/public/r/styles/default/rainbow-button.json+++ b/public/r/styles/default/rainbow-button.json@@ -4,7 +4,7 @@"files": [{"path": "magicui/rainbow-button.tsx",- "content": "import React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\ninterface RainbowButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement> {}\n\nexport function RainbowButton({\n children,\n className,\n ...props\n}: RainbowButtonProps) {\n return (\n <button\n className={cn(\n \"group relative inline-flex h-11 animate-rainbow cursor-pointer items-center justify-center rounded-xl border-0 bg-[length:200%] px-8 py-2 font-medium text-primary-foreground transition-colors [background-clip:padding-box,border-box,border-box] [background-origin:border-box] [border:calc(0.08*1rem)_solid_transparent] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50\",\n\n // before styles\n \"before:absolute before:bottom-[-20%] before:left-1/2 before:z-0 before:h-1/5 before:w-3/5 before:-translate-x-1/2 before:animate-rainbow before:bg-[linear-gradient(90deg,hsl(var(--color-1)),hsl(var(--color-5)),hsl(var(--color-3)),hsl(var(--color-4)),hsl(var(--color-2)))] before:bg-[length:200%] before:[filter:blur(calc(0.8*1rem))]\",\n\n // light mode colors\n \"bg-[linear-gradient(#121213,#121213),linear-gradient(#121213_50%,rgba(18,18,19,0.6)_80%,rgba(18,18,19,0)),linear-gradient(90deg,hsl(var(--color-1)),hsl(var(--color-5)),hsl(var(--color-3)),hsl(var(--color-4)),hsl(var(--color-2)))]\",\n\n // dark mode colors\n \"dark:bg-[linear-gradient(#fff,#fff),linear-gradient(#fff_50%,rgba(255,255,255,0.6)_80%,rgba(0,0,0,0)),linear-gradient(90deg,hsl(var(--color-1)),hsl(var(--color-5)),hsl(var(--color-3)),hsl(var(--color-4)),hsl(var(--color-2)))]\",\n\n className,\n )}\n {...props}\n >\n {children}\n </button>\n );\n}\n",+ "content": "import React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\ninterface RainbowButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement> {}\n\nexport function RainbowButton({\n children,\n className,\n ...props\n}: RainbowButtonProps) {\n return (\n <button\n className={cn(\n \"group relative inline-flex h-11 animate-rainbow cursor-pointer items-center justify-center rounded-xl border-0 bg-[length:200%] px-8 py-2 font-medium text-primary-foreground transition-colors [background-clip:padding-box,border-box,border-box] [background-origin:border-box] [border:calc(0.08*1rem)_solid_transparent] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50\",\n\n // before styles\n \"before:absolute before:bottom-[-20%] before:left-1/2 before:z-0 before:h-1/5 before:w-3/5 before:-translate-x-1/2 before:animate-rainbow before:bg-[linear-gradient(90deg,hsl(var(--color-1)),hsl(var(--color-5)),hsl(var(--color-3)),hsl(var(--color-4)),hsl(var(--color-2)))] before:[filter:blur(calc(0.8*1rem))]\",\n\n // light mode colors\n \"bg-[linear-gradient(#121213,#121213),linear-gradient(#121213_50%,rgba(18,18,19,0.6)_80%,rgba(18,18,19,0)),linear-gradient(90deg,hsl(var(--color-1)),hsl(var(--color-5)),hsl(var(--color-3)),hsl(var(--color-4)),hsl(var(--color-2)))]\",\n\n // dark mode colors\n \"dark:bg-[linear-gradient(#fff,#fff),linear-gradient(#fff_50%,rgba(255,255,255,0.6)_80%,rgba(0,0,0,0)),linear-gradient(90deg,hsl(var(--color-1)),hsl(var(--color-5)),hsl(var(--color-3)),hsl(var(--color-4)),hsl(var(--color-2)))]\",\n\n className,\n )}\n {...props}\n >\n {children}\n </button>\n );\n}\n","type": "registry:ui","target": ""}diff --git a/public/r/styles/default/ripple-button.json b/public/r/styles/default/ripple-button.jsonindex 46d74034..c3d396c6 100644--- a/public/r/styles/default/ripple-button.json+++ b/public/r/styles/default/ripple-button.json@@ -4,7 +4,7 @@"files": [{"path": "magicui/ripple-button.tsx",- "content": "\"use client\";\n\nimport React, { useState, useEffect, MouseEvent } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\ninterface RippleButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n rippleColor?: string;\n duration?: string;\n}\n\nexport default function RippleButton({\n className,\n children,\n rippleColor = \"#ffffff\",\n duration = \"600ms\",\n ...props\n}: RippleButtonProps) {\n const [buttonRipples, setButtonRipples] = useState<\n Array<{ x: number; y: number; size: number; key: number }>\n >([]);\n\n const createRipple = (event: MouseEvent<HTMLButtonElement>) => {\n const button = event.currentTarget;\n const rect = button.getBoundingClientRect();\n const size = Math.max(rect.width, rect.height);\n const x = event.clientX - rect.left - size / 2;\n const y = event.clientY - rect.top - size / 2;\n\n const newRipple = { x, y, size, key: Date.now() };\n setButtonRipples((prevRipples) => [...prevRipples, newRipple]);\n };\n\n useEffect(() => {\n if (buttonRipples.length > 0) {\n const lastRipple = buttonRipples[buttonRipples.length - 1];\n const timeout = setTimeout(() => {\n setButtonRipples((prevRipples) =>\n prevRipples.filter((ripple) => ripple.key !== lastRipple.key),\n );\n }, parseInt(duration));\n return () => clearTimeout(timeout);\n }\n }, [buttonRipples, duration]);\n\n return (\n <button\n className={cn(\n \"relative overflow-hidden text-center cursor-pointer flex justify-center items-center rounded-lg text-white bg-black-500 px-4 py-2 border-2\",\n className,\n )}\n onClick={createRipple}\n {...props}\n >\n <div className=\"relative z-10\">{children}</div>\n <span className=\"absolute inset-0 pointer-events-none\">\n {buttonRipples.map((ripple) => (\n <span\n className=\"absolute animate-rippling bg-white opacity-30 rounded-full\"\n key={ripple.key}\n style={{\n width: `${ripple.size}px`,\n height: `${ripple.size}px`,\n top: `${ripple.y}px`,\n left: `${ripple.x}px`,\n backgroundColor: rippleColor,\n transform: `scale(0)`,\n }}\n />\n ))}\n </span>\n </button>\n );\n}\n",+ "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport React, { MouseEvent, useEffect, useState } from \"react\";\n\ninterface RippleButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n rippleColor?: string;\n duration?: string;\n}\n\nconst RippleButton = React.forwardRef<HTMLButtonElement, RippleButtonProps>(\n (\n {\n className,\n children,\n rippleColor = \"#ffffff\",\n duration = \"600ms\",\n onClick,\n ...props\n },\n ref,\n ) => {\n const [buttonRipples, setButtonRipples] = useState<\n Array<{ x: number; y: number; size: number; key: number }>\n >([]);\n\n const handleClick = (event: MouseEvent<HTMLButtonElement>) => {\n createRipple(event);\n onClick?.(event);\n };\n\n const createRipple = (event: MouseEvent<HTMLButtonElement>) => {\n const button = event.currentTarget;\n const rect = button.getBoundingClientRect();\n const size = Math.max(rect.width, rect.height);\n const x = event.clientX - rect.left - size / 2;\n const y = event.clientY - rect.top - size / 2;\n\n const newRipple = { x, y, size, key: Date.now() };\n setButtonRipples((prevRipples) => [...prevRipples, newRipple]);\n };\n\n useEffect(() => {\n if (buttonRipples.length > 0) {\n const lastRipple = buttonRipples[buttonRipples.length - 1];\n const timeout = setTimeout(() => {\n setButtonRipples((prevRipples) =>\n prevRipples.filter((ripple) => ripple.key !== lastRipple.key),\n );\n }, parseInt(duration));\n return () => clearTimeout(timeout);\n }\n }, [buttonRipples, duration]);\n\n return (\n <button\n className={cn(\n \"relative flex cursor-pointer items-center justify-center overflow-hidden rounded-lg border-2 bg-background px-4 py-2 text-center text-primary\",\n className,\n )}\n onClick={handleClick}\n ref={ref}\n {...props}\n >\n <div className=\"relative z-10\">{children}</div>\n <span className=\"pointer-events-none absolute inset-0\">\n {buttonRipples.map((ripple) => (\n <span\n className=\"absolute animate-rippling rounded-full bg-background opacity-30\"\n key={ripple.key}\n style={{\n width: `${ripple.size}px`,\n height: `${ripple.size}px`,\n top: `${ripple.y}px`,\n left: `${ripple.x}px`,\n backgroundColor: rippleColor,\n transform: `scale(0)`,\n }}\n />\n ))}\n </span>\n </button>\n );\n },\n);\n\nRippleButton.displayName = \"RippleButton\";\n\nexport default RippleButton;\n","type": "registry:ui","target": ""}diff --git a/public/r/styles/default/scratch-to-reveal.json b/public/r/styles/default/scratch-to-reveal.jsonnew file mode 100644index 00000000..f985238e--- /dev/null+++ b/public/r/styles/default/scratch-to-reveal.json@@ -0,0 +1,15 @@+{+ "name": "scratch-to-reveal",+ "type": "registry:ui",+ "dependencies": [+ "framer-motion"+ ],+ "files": [+ {+ "path": "magicui/scratch-to-reveal.tsx",+ "content": "import { cn } from \"@/lib/utils\";\nimport React, { useRef, useEffect, useState } from \"react\";\nimport { motion, useAnimation } from \"framer-motion\";\n\ninterface ScratchToRevealProps {\n children: React.ReactNode;\n width: number;\n height: number;\n minScratchPercentage?: number;\n className?: string;\n onComplete?: () => void;\n gradientColors?: [string, string, string];\n}\n\nconst ScratchToReveal: React.FC<ScratchToRevealProps> = ({\n width,\n height,\n minScratchPercentage = 50,\n onComplete,\n children,\n className,\n gradientColors = [\"#A97CF8\", \"#F38CB8\", \"#FDCC92\"],\n}) => {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const [isScratching, setIsScratching] = useState(false);\n const [isComplete, setIsComplete] = useState(false);\n\n const controls = useAnimation();\n\n useEffect(() => {\n const canvas = canvasRef.current;\n const ctx = canvas?.getContext(\"2d\");\n if (canvas && ctx) {\n ctx.fillStyle = \"#ccc\";\n ctx.fillRect(0, 0, canvas.width, canvas.height);\n const gradient = ctx.createLinearGradient(\n 0,\n 0,\n canvas.width,\n canvas.height\n );\n gradient.addColorStop(0, gradientColors[0]);\n gradient.addColorStop(0.5, gradientColors[1]);\n gradient.addColorStop(1, gradientColors[2]);\n ctx.fillStyle = gradient;\n ctx.fillRect(0, 0, canvas.width, canvas.height);\n }\n }, [gradientColors]);\n\n useEffect(() => {\n const handleDocumentMouseMove = (event: MouseEvent) => {\n if (!isScratching) return;\n scratch(event.clientX, event.clientY);\n };\n\n const handleDocumentTouchMove = (event: TouchEvent) => {\n if (!isScratching) return;\n const touch = event.touches[0];\n scratch(touch.clientX, touch.clientY);\n };\n\n const handleDocumentMouseUp = () => {\n setIsScratching(false);\n checkCompletion();\n };\n\n const handleDocumentTouchEnd = () => {\n setIsScratching(false);\n checkCompletion();\n };\n\n document.addEventListener(\"mousedown\", handleDocumentMouseMove);\n document.addEventListener(\"mousemove\", handleDocumentMouseMove);\n document.addEventListener(\"touchstart\", handleDocumentTouchMove);\n document.addEventListener(\"touchmove\", handleDocumentTouchMove);\n document.addEventListener(\"mouseup\", handleDocumentMouseUp);\n document.addEventListener(\"touchend\", handleDocumentTouchEnd);\n document.addEventListener(\"touchcancel\", handleDocumentTouchEnd);\n\n return () => {\n document.removeEventListener(\"mousedown\", handleDocumentMouseMove);\n document.removeEventListener(\"mousemove\", handleDocumentMouseMove);\n document.removeEventListener(\"touchstart\", handleDocumentTouchMove);\n document.removeEventListener(\"touchmove\", handleDocumentTouchMove);\n document.removeEventListener(\"mouseup\", handleDocumentMouseUp);\n document.removeEventListener(\"touchend\", handleDocumentTouchEnd);\n document.removeEventListener(\"touchcancel\", handleDocumentTouchEnd);\n };\n }, [isScratching]);\n\n const handleMouseDown = () => setIsScratching(true);\n\n const handleTouchStart = () => setIsScratching(true);\n\n const scratch = (clientX: number, clientY: number) => {\n const canvas = canvasRef.current;\n const ctx = canvas?.getContext(\"2d\");\n if (canvas && ctx) {\n const rect = canvas.getBoundingClientRect();\n const x = clientX - rect.left + 16;\n const y = clientY - rect.top + 16;\n ctx.globalCompositeOperation = \"destination-out\";\n ctx.beginPath();\n ctx.arc(x, y, 30, 0, Math.PI * 2);\n ctx.fill();\n }\n };\n\n const startAnimation = async () => {\n await controls.start({\n scale: [1, 1.5, 1],\n rotate: [0, 10, -10, 10, -10, 0],\n transition: { duration: 0.5 },\n });\n\n // Call onComplete after animation finishes\n if (onComplete) {\n onComplete();\n }\n };\n\n const checkCompletion = () => {\n if (isComplete) return;\n\n const canvas = canvasRef.current;\n const ctx = canvas?.getContext(\"2d\");\n if (canvas && ctx) {\n const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);\n const pixels = imageData.data;\n const totalPixels = pixels.length / 4;\n let clearPixels = 0;\n\n for (let i = 3; i < pixels.length; i += 4) {\n if (pixels[i] === 0) clearPixels++;\n }\n\n const percentage = (clearPixels / totalPixels) * 100;\n\n if (percentage >= minScratchPercentage) {\n setIsComplete(true);\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n startAnimation();\n }\n }\n };\n\n return (\n <motion.div\n className={cn(\"relative select-none\", className)}\n style={{\n width,\n height,\n cursor:\n \"url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8Y2lyY2xlIGN4PSIxNiIgY3k9IjE2IiByPSIxNSIgc3R5bGU9ImZpbGw6I2ZmZjtzdHJva2U6IzAwMDtzdHJva2Utd2lkdGg6MXB4OyIgLz4KPC9zdmc+'), auto\",\n }}\n animate={controls}\n >\n <canvas\n ref={canvasRef}\n width={width}\n height={height}\n className=\"absolute left-0 top-0\"\n onMouseDown={handleMouseDown}\n onTouchStart={handleTouchStart}\n ></canvas>\n {children}\n </motion.div>\n );\n};\n\nexport default ScratchToReveal;\n",+ "type": "registry:ui",+ "target": ""+ }+ ]+}\ No newline at end of filediff --git a/public/r/styles/default/shine-border.json b/public/r/styles/default/shine-border.jsonindex 7de0e015..cb8469fc 100644--- a/public/r/styles/default/shine-border.json+++ b/public/r/styles/default/shine-border.json@@ -4,7 +4,7 @@"files": [{"path": "magicui/shine-border.tsx",- "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\n\ntype TColorProp = string | string[];\n\ninterface ShineBorderProps {\n borderRadius?: number;\n borderWidth?: number;\n duration?: number;\n color?: TColorProp;\n className?: string;\n children: React.ReactNode;\n}\n\n/**\n * @name Shine Border\n * @description It is an animated background border effect component with easy to use and configurable props.\n * @param borderRadius defines the radius of the border.\n * @param borderWidth defines the width of the border.\n * @param duration defines the animation duration to be applied on the shining border\n * @param color a string or string array to define border color.\n * @param className defines the class name to be applied to the component\n * @param children contains react node elements.\n */\nexport default function ShineBorder({\n borderRadius = 8,\n borderWidth = 1,\n duration = 14,\n color = \"#000000\",\n className,\n children,\n}: ShineBorderProps) {\n return (\n <div\n style={\n {\n \"--border-radius\": `${borderRadius}px`,\n } as React.CSSProperties\n }\n className={cn(\n \"relative grid min-h-[60px] w-fit min-w-[300px] place-items-center rounded-[--border-radius] bg-white p-3 text-black dark:bg-black dark:text-white\",\n className,\n )}\n >\n <div\n style={\n {\n \"--border-width\": `${borderWidth}px`,\n \"--border-radius\": `${borderRadius}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, ${color instanceof Array ? color.join(\",\") : color},transparent,transparent)`,\n } as React.CSSProperties\n }\n className={`pointer-events-none before:bg-shine-size before:absolute before:inset-0 before:aspect-square before:size-full before:rounded-[--border-radius] before:p-[--border-width] before:will-change-[background-position] before:content-[\"\"] before:![-webkit-mask-composite:xor] before:![mask-composite:exclude] before:[background-image:--background-radial-gradient] before:[background-size:300%_300%] before:[mask:--mask-linear-gradient] motion-safe:before:animate-shine`}\n ></div>\n {children}\n </div>\n );\n}\n",+ "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\n\ntype TColorProp = string | string[];\n\ninterface ShineBorderProps {\n borderRadius?: number;\n borderWidth?: number;\n duration?: number;\n color?: TColorProp;\n className?: string;\n children: React.ReactNode;\n}\n\n/**\n * @name Shine Border\n * @description It is an animated background border effect component with easy to use and configurable props.\n * @param borderRadius defines the radius of the border.\n * @param borderWidth defines the width of the border.\n * @param duration defines the animation duration to be applied on the shining border\n * @param color a string or string array to define border color.\n * @param className defines the class name to be applied to the component\n * @param children contains react node elements.\n */\nexport default function ShineBorder({\n borderRadius = 8,\n borderWidth = 1,\n duration = 14,\n color = \"#000000\",\n className,\n children,\n}: ShineBorderProps) {\n return (\n <div\n style={\n {\n \"--border-radius\": `${borderRadius}px`,\n } as React.CSSProperties\n }\n className={cn(\n \"relative min-h-[60px] w-fit min-w-[300px] place-items-center rounded-[--border-radius] bg-white p-3 text-black dark:bg-black dark:text-white\",\n className,\n )}\n >\n <div\n style={\n {\n \"--border-width\": `${borderWidth}px`,\n \"--border-radius\": `${borderRadius}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, ${color instanceof Array ? color.join(\",\") : color},transparent,transparent)`,\n } as React.CSSProperties\n }\n className={`pointer-events-none before:bg-shine-size before:absolute before:inset-0 before:size-full before:rounded-[--border-radius] before:p-[--border-width] before:will-change-[background-position] before:content-[\"\"] before:![-webkit-mask-composite:xor] before:![mask-composite:exclude] before:[background-image:--background-radial-gradient] before:[background-size:300%_300%] before:[mask:--mask-linear-gradient] motion-safe:before:animate-shine`}\n ></div>\n {children}\n </div>\n );\n}\n","type": "registry:ui","target": ""}diff --git a/registry/default/example/scratch-to-reveal-demo.tsx b/registry/default/example/scratch-to-reveal-demo.tsxnew file mode 100644index 00000000..18b051c6--- /dev/null+++ b/registry/default/example/scratch-to-reveal-demo.tsx@@ -0,0 +1,25 @@+import React from "react";+import ScratchToReveal from "@/components/magicui/scratch-to-reveal";++const ScratchToRevealDemo = () => {+ const handleComplete = () => {+ // Do Something+ };++ return (+ <div>+ <ScratchToReveal+ width={250}+ height={250}+ minScratchPercentage={70}+ className="flex items-center justify-center overflow-hidden rounded-2xl border-2 bg-gray-100"+ onComplete={handleComplete}+ gradientColors={["#A97CF8", "#F38CB8", "#FDCC92"]}+ >+ <p className="text-9xl">😎</p>+ </ScratchToReveal>+ </div>+ );+};++export default ScratchToRevealDemo;diff --git a/registry/default/magicui/scratch-to-reveal.tsx b/registry/default/magicui/scratch-to-reveal.tsxnew file mode 100644index 00000000..22d4d8a5--- /dev/null+++ b/registry/default/magicui/scratch-to-reveal.tsx@@ -0,0 +1,171 @@+import { cn } from "@/lib/utils";+import React, { useRef, useEffect, useState } from "react";+import { motion, useAnimation } from "framer-motion";++interface ScratchToRevealProps {+ children: React.ReactNode;+ width: number;+ height: number;+ minScratchPercentage?: number;+ className?: string;+ onComplete?: () => void;+ gradientColors?: [string, string, string];+}++const ScratchToReveal: React.FC<ScratchToRevealProps> = ({+ width,+ height,+ minScratchPercentage = 50,+ onComplete,+ children,+ className,+ gradientColors = ["#A97CF8", "#F38CB8", "#FDCC92"],+}) => {+ const canvasRef = useRef<HTMLCanvasElement>(null);+ const [isScratching, setIsScratching] = useState(false);+ const [isComplete, setIsComplete] = useState(false);++ const controls = useAnimation();++ useEffect(() => {+ const canvas = canvasRef.current;+ const ctx = canvas?.getContext("2d");+ if (canvas && ctx) {+ ctx.fillStyle = "#ccc";+ ctx.fillRect(0, 0, canvas.width, canvas.height);+ const gradient = ctx.createLinearGradient(+ 0,+ 0,+ canvas.width,+ canvas.height,+ );+ gradient.addColorStop(0, gradientColors[0]);+ gradient.addColorStop(0.5, gradientColors[1]);+ gradient.addColorStop(1, gradientColors[2]);+ ctx.fillStyle = gradient;+ ctx.fillRect(0, 0, canvas.width, canvas.height);+ }+ }, [gradientColors]);++ useEffect(() => {+ const handleDocumentMouseMove = (event: MouseEvent) => {+ if (!isScratching) return;+ scratch(event.clientX, event.clientY);+ };++ const handleDocumentTouchMove = (event: TouchEvent) => {+ if (!isScratching) return;+ const touch = event.touches[0];+ scratch(touch.clientX, touch.clientY);+ };++ const handleDocumentMouseUp = () => {+ setIsScratching(false);+ checkCompletion();+ };++ const handleDocumentTouchEnd = () => {+ setIsScratching(false);+ checkCompletion();+ };++ document.addEventListener("mousedown", handleDocumentMouseMove);+ document.addEventListener("mousemove", handleDocumentMouseMove);+ document.addEventListener("touchstart", handleDocumentTouchMove);+ document.addEventListener("touchmove", handleDocumentTouchMove);+ document.addEventListener("mouseup", handleDocumentMouseUp);+ document.addEventListener("touchend", handleDocumentTouchEnd);+ document.addEventListener("touchcancel", handleDocumentTouchEnd);++ return () => {+ document.removeEventListener("mousedown", handleDocumentMouseMove);+ document.removeEventListener("mousemove", handleDocumentMouseMove);+ document.removeEventListener("touchstart", handleDocumentTouchMove);+ document.removeEventListener("touchmove", handleDocumentTouchMove);+ document.removeEventListener("mouseup", handleDocumentMouseUp);+ document.removeEventListener("touchend", handleDocumentTouchEnd);+ document.removeEventListener("touchcancel", handleDocumentTouchEnd);+ };+ }, [isScratching]);++ const handleMouseDown = () => setIsScratching(true);++ const handleTouchStart = () => setIsScratching(true);++ const scratch = (clientX: number, clientY: number) => {+ const canvas = canvasRef.current;+ const ctx = canvas?.getContext("2d");+ if (canvas && ctx) {+ const rect = canvas.getBoundingClientRect();+ const x = clientX - rect.left + 16;+ const y = clientY - rect.top + 16;+ ctx.globalCompositeOperation = "destination-out";+ ctx.beginPath();+ ctx.arc(x, y, 30, 0, Math.PI * 2);+ ctx.fill();+ }+ };++ const startAnimation = async () => {+ await controls.start({+ scale: [1, 1.5, 1],+ rotate: [0, 10, -10, 10, -10, 0],+ transition: { duration: 0.5 },+ });++ // Call onComplete after animation finishes+ if (onComplete) {+ onComplete();+ }+ };++ const checkCompletion = () => {+ if (isComplete) return;++ const canvas = canvasRef.current;+ const ctx = canvas?.getContext("2d");+ if (canvas && ctx) {+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);+ const pixels = imageData.data;+ const totalPixels = pixels.length / 4;+ let clearPixels = 0;++ for (let i = 3; i < pixels.length; i += 4) {+ if (pixels[i] === 0) clearPixels++;+ }++ const percentage = (clearPixels / totalPixels) * 100;++ if (percentage >= minScratchPercentage) {+ setIsComplete(true);+ ctx.clearRect(0, 0, canvas.width, canvas.height);+ startAnimation();+ }+ }+ };++ return (+ <motion.div+ className={cn("relative select-none", className)}+ style={{+ width,+ height,+ cursor:+ "url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8Y2lyY2xlIGN4PSIxNiIgY3k9IjE2IiByPSIxNSIgc3R5bGU9ImZpbGw6I2ZmZjtzdHJva2U6IzAwMDtzdHJva2Utd2lkdGg6MXB4OyIgLz4KPC9zdmc+'), auto",+ }}+ animate={controls}+ >+ <canvas+ ref={canvasRef}+ width={width}+ height={height}+ className="absolute left-0 top-0"+ onMouseDown={handleMouseDown}+ onTouchStart={handleTouchStart}+ ></canvas>+ {children}+ </motion.div>+ );+};++export default ScratchToReveal;diff --git a/registry/registry-examples.ts b/registry/registry-examples.tsindex 0f504cef..8b175d1c 100644--- a/registry/registry-examples.ts+++ b/registry/registry-examples.ts@@ -314,6 +314,12 @@ export const examples: Registry = [registryDependencies: ["scroll-based-velocity"],files: ["example/scroll-based-velocity-demo.tsx"],},+ {+ name: "scratch-to-reveal-demo",+ type: "registry:example",+ registryDependencies: ["scratch-to-reveal"],+ files: ["example/scratch-to-reveal-demo.tsx"],+ },{name: "letter-pullup-demo",type: "registry:example",diff --git a/registry/registry-ui.ts b/registry/registry-ui.tsindex e742a545..96e48178 100644--- a/registry/registry-ui.ts+++ b/registry/registry-ui.ts@@ -446,6 +446,12 @@ export const ui: Registry = [dependencies: ["framer-motion"],files: ["magicui/scroll-based-velocity.tsx"],},+ {+ name: "scratch-to-reveal",+ type: "registry:ui",+ dependencies: ["framer-motion"],+ files: ["magicui/scratch-to-reveal.tsx"],+ },{name: "fade-text",type: "registry:ui",