{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-shine-border",
  "title": "Shine border",
  "description": "A slanted glint that sweeps across the border of a card, on a slow loop or once on hover and keyboard focus.",
  "dependencies": [],
  "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/shine-border.tsx",
      "content": "'use client';\n\nimport { useEffect, useRef } from 'react';\n\nimport { cn } from '@/lib/utils';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\n\nexport type ShineTrigger = 'loop' | 'hover';\n\nconst SWEEP_EASE = 'cubic-bezier(0.77, 0, 0.175, 1)';\n\nconst BEFORE_FRAME = 'translateX(-100%)';\n\nconst AFTER_FRAME = 'translateX(250%)';\n\nfunction frameShapeOf(width: number): React.CSSProperties {\n  return {\n    inset: 'calc(var(--hairline, 1px) * -1)',\n    padding: width,\n    mask: 'linear-gradient(black, black) content-box exclude, linear-gradient(black, black)',\n    WebkitMask:\n      'linear-gradient(black, black) content-box xor, linear-gradient(black, black)',\n  };\n}\n\nfunction loopSweep(band: HTMLElement, sweepMs: number, restMs: number) {\n  const cycleMs = sweepMs + restMs;\n  const sweepShare = sweepMs / cycleMs;\n  return band.animate(\n    [\n      { transform: BEFORE_FRAME, offset: 0, easing: SWEEP_EASE },\n      { transform: AFTER_FRAME, offset: sweepShare },\n      { transform: AFTER_FRAME, offset: 1 },\n    ],\n    { duration: cycleMs, iterations: Infinity }\n  );\n}\n\nfunction singleSweep(band: HTMLElement, sweepMs: number) {\n  return band.animate(\n    [{ transform: BEFORE_FRAME }, { transform: AFTER_FRAME }],\n    {\n      duration: sweepMs,\n      easing: SWEEP_EASE,\n    }\n  );\n}\n\nfunction isRunning(animation: Animation | null) {\n  if (!animation) {\n    return false;\n  }\n  return animation.playState === 'running';\n}\n\nfunction isKeyboardFocus(event: FocusEvent) {\n  const target = event.target;\n  if (!(target instanceof Element)) {\n    return false;\n  }\n  return target.matches(':focus-visible');\n}\n\nexport type ShineBorderProps = {\n  trigger?: ShineTrigger;\n  duration?: number;\n  interval?: number;\n  width?: number;\n  className?: string;\n};\n\nexport function ShineBorder({\n  trigger = 'loop',\n  duration = 1.4,\n  interval = 4,\n  width = 1,\n  className,\n}: ShineBorderProps) {\n  const frameRef = useRef<HTMLSpanElement>(null);\n  const bandRef = useRef<HTMLSpanElement>(null);\n  const prefersReducedMotion = usePrefersReducedMotion();\n  const sweepMs = duration * 1000;\n  const restMs = interval * 1000;\n\n  useEffect(() => {\n    const band = bandRef.current;\n    const isLooping = trigger === 'loop';\n    if (!band || !isLooping) {\n      return;\n    }\n    if (prefersReducedMotion) {\n      return;\n    }\n    const animation = loopSweep(band, sweepMs, restMs);\n    return () => animation.cancel();\n  }, [trigger, sweepMs, restMs, prefersReducedMotion]);\n\n  useEffect(() => {\n    const band = bandRef.current;\n    const owner = frameRef.current?.parentElement;\n    const isHover = trigger === 'hover';\n    if (!band || !owner || !isHover) {\n      return;\n    }\n    if (prefersReducedMotion) {\n      return;\n    }\n    let current: Animation | null = null;\n    const sweep = () => {\n      if (isRunning(current)) {\n        return;\n      }\n      current = singleSweep(band, sweepMs);\n    };\n    const sweepForMouse = (event: PointerEvent) => {\n      if (event.pointerType !== 'mouse') {\n        return;\n      }\n      sweep();\n    };\n    const sweepForKeyboard = (event: FocusEvent) => {\n      if (!isKeyboardFocus(event)) {\n        return;\n      }\n      sweep();\n    };\n    owner.addEventListener('pointerenter', sweepForMouse);\n    owner.addEventListener('focusin', sweepForKeyboard);\n    return () => {\n      owner.removeEventListener('pointerenter', sweepForMouse);\n      owner.removeEventListener('focusin', sweepForKeyboard);\n      current?.cancel();\n    };\n  }, [trigger, sweepMs, prefersReducedMotion]);\n\n  return (\n    <span\n      ref={frameRef}\n      aria-hidden='true'\n      style={frameShapeOf(width)}\n      className={cn(\n        'text-primary pointer-events-none absolute overflow-hidden rounded-[inherit]',\n        className\n      )}\n    >\n      <span\n        ref={bandRef}\n        style={{ transform: BEFORE_FRAME }}\n        className='absolute inset-y-0 left-0 w-2/5 bg-[linear-gradient(110deg,transparent_25%,currentColor_50%,transparent_75%)]'\n      />\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/core/shine-border.tsx"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:component"
}