{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-glow-effect",
  "title": "Glow effect",
  "description": "A component that creates a glowing effect on elements based on cursor movement.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "components/core/glow-effect.tsx",
      "content": "'use client';\nimport { cn } from '@/lib/utils';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { motion, Transition } from 'motion/react';\nimport { useSyncExternalStore } from 'react';\n\nexport type GlowEffectProps = {\n  className?: string;\n  style?: React.CSSProperties;\n  colors?: string[];\n  mode?:\n    'rotate' | 'pulse' | 'breathe' | 'colorShift' | 'flowHorizontal' | 'static';\n  blur?:\n    | number\n    | 'softest'\n    | 'soft'\n    | 'medium'\n    | 'strong'\n    | 'stronger'\n    | 'strongest'\n    | 'none';\n  transition?: Transition;\n  scale?: number;\n  duration?: number;\n};\n\nconst DEFAULT_COLORS = [\n  'var(--primary)',\n  'var(--info)',\n  'var(--success)',\n  'var(--warning)',\n];\n\nconst COLOR_SEPARATOR = '|';\n\nconst CSS_VARIABLE = /^var\\((--[\\w-]+)\\)$/;\n\ntype GlowKeyframes = string | string[] | number[];\n\ntype GlowAnimation = {\n  background: string | string[];\n  scale?: number[];\n  opacity?: number[];\n  transition?: Transition;\n};\n\nfunction subscribeToThemeChange(onChange: () => void) {\n  const observer = new MutationObserver(onChange);\n  observer.observe(document.documentElement, {\n    attributes: true,\n    attributeFilter: ['class', 'style', 'data-theme'],\n  });\n  return () => observer.disconnect();\n}\n\nfunction resolveColor(color: string, rootStyle: CSSStyleDeclaration) {\n  const match = CSS_VARIABLE.exec(color.trim());\n  if (!match) {\n    return color;\n  }\n  const value = rootStyle.getPropertyValue(match[1]).trim();\n  if (!value) {\n    return color;\n  }\n  return value;\n}\n\nfunction firstFrameOf(keyframes: GlowKeyframes) {\n  if (Array.isArray(keyframes)) {\n    return keyframes[0];\n  }\n  return keyframes;\n}\n\nfunction stillFrameOf(animation: GlowAnimation) {\n  const still: Record<string, string | number> = {\n    background: firstFrameOf(animation.background),\n  };\n  if (animation.scale) {\n    still.scale = firstFrameOf(animation.scale);\n  }\n  if (animation.opacity) {\n    still.opacity = firstFrameOf(animation.opacity);\n  }\n  return still;\n}\n\nfunction glowAnimationOf(\n  prefersReducedMotion: boolean | null,\n  animation: GlowAnimation\n) {\n  if (prefersReducedMotion) {\n    return stillFrameOf(animation);\n  }\n  return animation;\n}\n\nexport function GlowEffect({\n  className,\n  style,\n  colors = DEFAULT_COLORS,\n  mode = 'rotate',\n  blur = 'medium',\n  transition,\n  scale = 1,\n  duration = 5,\n}: GlowEffectProps) {\n  const prefersReducedMotion = usePrefersReducedMotion();\n  const colorList = colors.join(COLOR_SEPARATOR);\n\n  // Motion cannot blend var() colours inside a gradient, so token colours are read as values and read again when the theme changes.\n  const resolvedColorList = useSyncExternalStore(\n    subscribeToThemeChange,\n    () => {\n      const rootStyle = getComputedStyle(document.documentElement);\n      return colors\n        .map((color) => resolveColor(color, rootStyle))\n        .join(COLOR_SEPARATOR);\n    },\n    () => colorList\n  );\n  const glowColors = resolvedColorList.split(COLOR_SEPARATOR);\n\n  const BASE_TRANSITION: Transition = {\n    repeat: Infinity,\n    duration: duration,\n    ease: 'linear',\n  };\n\n  const animations: Record<\n    NonNullable<GlowEffectProps['mode']>,\n    GlowAnimation\n  > = {\n    rotate: {\n      background: [\n        `conic-gradient(from 0deg at 50% 50%, ${glowColors.join(', ')})`,\n        `conic-gradient(from 360deg at 50% 50%, ${glowColors.join(', ')})`,\n      ],\n      transition: {\n        ...(transition ?? BASE_TRANSITION),\n      },\n    },\n    pulse: {\n      background: glowColors.map(\n        (color) =>\n          `radial-gradient(circle at 50% 50%, ${color} 0%, transparent 100%)`\n      ),\n      scale: [1 * scale, 1.1 * scale, 1 * scale],\n      opacity: [0.5, 0.8, 0.5],\n      transition: {\n        ...(transition ?? {\n          ...BASE_TRANSITION,\n          repeatType: 'mirror' as const,\n        }),\n      },\n    },\n    breathe: {\n      background: [\n        ...glowColors.map(\n          (color) =>\n            `radial-gradient(circle at 50% 50%, ${color} 0%, transparent 100%)`\n        ),\n      ],\n      scale: [1 * scale, 1.05 * scale, 1 * scale],\n      transition: {\n        ...(transition ?? {\n          ...BASE_TRANSITION,\n          repeatType: 'mirror' as const,\n        }),\n      },\n    },\n    colorShift: {\n      background: glowColors.map((color, index) => {\n        const nextColor = glowColors[(index + 1) % glowColors.length];\n        return `conic-gradient(from 0deg at 50% 50%, ${color} 0%, ${nextColor} 50%, ${color} 100%)`;\n      }),\n      transition: {\n        ...(transition ?? {\n          ...BASE_TRANSITION,\n          repeatType: 'mirror' as const,\n        }),\n      },\n    },\n    flowHorizontal: {\n      background: glowColors.map((color) => {\n        const nextColor =\n          glowColors[(glowColors.indexOf(color) + 1) % glowColors.length];\n        return `linear-gradient(to right, ${color}, ${nextColor})`;\n      }),\n      transition: {\n        ...(transition ?? {\n          ...BASE_TRANSITION,\n          repeatType: 'mirror' as const,\n        }),\n      },\n    },\n    static: {\n      background: `linear-gradient(to right, ${glowColors.join(', ')})`,\n    },\n  };\n\n  const getBlurClass = (blur: GlowEffectProps['blur']) => {\n    if (typeof blur === 'number') {\n      return `blur-[${blur}px]`;\n    }\n\n    const presets = {\n      softest: 'blur-xs',\n      soft: 'blur-sm',\n      medium: 'blur-md',\n      strong: 'blur-lg',\n      stronger: 'blur-xl',\n      strongest: 'blur-xl',\n      none: 'blur-none',\n    };\n\n    return presets[blur as keyof typeof presets];\n  };\n\n  const animate = glowAnimationOf(prefersReducedMotion, animations[mode]);\n\n  return (\n    <motion.div\n      style={\n        {\n          ...style,\n          '--scale': scale,\n          willChange: 'transform',\n          backfaceVisibility: 'hidden',\n        } as React.CSSProperties\n      }\n      animate={animate}\n      className={cn(\n        'pointer-events-none absolute inset-0 h-full w-full',\n        'scale-[var(--scale)] transform-gpu',\n        getBlurClass(blur),\n        className\n      )}\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/core/glow-effect.tsx"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:component"
}