{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "moving-text-border",
  "type": "registry:ui",
  "title": "Moving Text Border",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Kinetic card wrapper with animated typography continuously flowing along the rounded perimeter using SVG textPath, dynamic geometry calculation, and zero-distortion responsiveness.",
  "dependencies": [
    "framer-motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/moving-text-border.tsx",
      "content": "\"use client\";\n\nimport React, {\n  useId,\n  useRef,\n  useState,\n  useEffect,\n  useLayoutEffect,\n  useMemo,\n  type ReactNode,\n} from \"react\";\nimport { motion, useReducedMotion } from \"framer-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport type MovingTextBorderStart =\n  | \"top-left\"\n  | \"top-right\"\n  | \"bottom-right\"\n  | \"bottom-left\";\n\nexport interface MovingTextBorderProps\n  extends React.HTMLAttributes<HTMLDivElement> {\n  /** Content rendered inside the moving text border container */\n  children?: ReactNode;\n  /** Text marching around the perimeter */\n  text?: string;\n  /** Duration in seconds for a full loop around the perimeter. Default: 12 */\n  duration?: number;\n  /** Whether the text flows counter-clockwise. Default: false */\n  reverse?: boolean;\n  /** Fill color of the text. Default: \"#a78bfa\" */\n  textColor?: string;\n  /** Font size of the marching text in px. Default: 10 */\n  fontSize?: number;\n  /** Letter spacing of the text in px. Default: 2 */\n  letterSpacing?: number;\n  /** Font weight for the SVG text. Default: 600 */\n  fontWeight?: number | string;\n  /** Corner radius in px matching the container's rounded corners. Default: 16 */\n  borderRadius?: number;\n  /** Optional background track path color */\n  trackColor?: string;\n  /** Width in px of the background track path. Default: 1 */\n  trackWidth?: number;\n  /** Kept for API compatibility. Text is always tiled so the loop is seamless. */\n  autoRepeat?: boolean;\n  /** Add a soft ambient glow to the text. Default: false */\n  glow?: boolean;\n  className?: string;\n  contentClassName?: string;\n  startAt?: MovingTextBorderStart;\n}\n\nexport function MovingTextBorder({\n  children,\n  text = \"AVAILABLE FOR WORK • AVAILABLE FOR WORK • \",\n  duration = 12,\n  reverse = false,\n  textColor = \"#a78bfa\",\n  fontSize = 10,\n  letterSpacing = 2,\n  fontWeight = \"600\",\n  borderRadius = 16,\n  trackColor,\n  trackWidth = 1,\n  autoRepeat = true,\n  glow = false,\n  className,\n  contentClassName,\n  startAt = \"bottom-right\",\n  ...props\n}: MovingTextBorderProps) {\n  const containerRef = useRef<HTMLDivElement>(null);\n  const pathRef = useRef<SVGPathElement>(null);\n  const measureRef = useRef<SVGTextElement>(null);\n  const textPathRef = useRef<SVGTextPathElement>(null);\n\n  const [dimensions, setDimensions] = useState({ width: 400, height: 200 });\n  const [pathLength, setPathLength] = useState(0);\n  const [unitWidth, setUnitWidth] = useState(0);\n\n  const rawId = useId();\n  const pathId = `border-path-${rawId.replace(/[^a-zA-Z0-9-_]/g, \"\")}`;\n  const shouldReduceMotion = useReducedMotion();\n\n  // Measure container\n  useEffect(() => {\n    const el = containerRef.current;\n    if (!el) return;\n\n    const update = () => {\n      const rect = el.getBoundingClientRect();\n      if (rect.width > 0 && rect.height > 0) {\n        setDimensions({\n          width: Math.round(rect.width),\n          height: Math.round(rect.height),\n        });\n      }\n    };\n    update();\n\n    const ro = new ResizeObserver((entries) => {\n      for (const entry of entries) {\n        const { width, height } = entry.contentRect;\n        if (width > 0 && height > 0) {\n          setDimensions({\n            width: Math.round(width),\n            height: Math.round(height),\n          });\n        }\n      }\n    });\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  // Rounded-rect path, starting at top-center, clockwise\n  const svgPathData = useMemo(() => {\n    const inset = 3;\n    const w = Math.max(dimensions.width - inset * 2, 20);\n    const h = Math.max(dimensions.height - inset * 2, 20);\n    const rx = Math.max(2, Math.min(borderRadius - inset, w / 2 - 1, h / 2 - 1));\n\n    const x0 = inset;\n    const y0 = inset;\n    const x1 = x0 + w;\n    const y1 = y0 + h;\n\n    // Clockwise segments, each paired with the point where it begins\n    const top = `H ${x1 - rx}`;\n    const topR = `Q ${x1},${y0} ${x1},${y0 + rx}`;\n    const right = `V ${y1 - rx}`;\n    const botR = `Q ${x1},${y1} ${x1 - rx},${y1}`;\n    const bottom = `H ${x0 + rx}`;\n    const botL = `Q ${x0},${y1} ${x0},${y1 - rx}`;\n    const left = `V ${y0 + rx}`;\n    const topL = `Q ${x0},${y0} ${x0 + rx},${y0}`;\n\n    const starts = {\n      \"top-left\": {\n        m: `M ${x0 + rx},${y0}`,\n        seg: [top, topR, right, botR, bottom, botL, left, topL],\n      },\n      \"top-right\": {\n        m: `M ${x1},${y0 + rx}`,\n        seg: [right, botR, bottom, botL, left, topL, top, topR],\n      },\n      \"bottom-right\": {\n        m: `M ${x1 - rx},${y1}`,\n        seg: [bottom, botL, left, topL, top, topR, right, botR],\n      },\n      \"bottom-left\": {\n        m: `M ${x0},${y1 - rx}`,\n        seg: [left, topL, top, topR, right, botR, bottom, botL],\n      },\n    } as const;\n\n    const { m, seg } = starts[startAt];\n    return [m, ...seg, \"Z\"].join(\" \");\n  }, [dimensions, borderRadius, startAt]);\n\n  // Measure the real path length safely (with fallback for jsdom / SSR)\n  useLayoutEffect(() => {\n    if (pathRef.current && typeof pathRef.current.getTotalLength === \"function\") {\n      setPathLength(pathRef.current.getTotalLength());\n    } else {\n      setPathLength(2 * (dimensions.width + dimensions.height));\n    }\n  }, [svgPathData, dimensions]);\n\n  // Measure the real width of ONE text unit safely (with fallback for jsdom / SSR)\n  useLayoutEffect(() => {\n    if (!measureRef.current) return;\n    const w =\n      typeof measureRef.current.getComputedTextLength === \"function\"\n        ? measureRef.current.getComputedTextLength()\n        : 0;\n    // Fallback estimate if measurement isn't available yet\n    setUnitWidth(w > 0 ? w : text.length * (fontSize * 0.6 + letterSpacing));\n  }, [text, fontSize, letterSpacing, fontWeight]);\n\n  // Tile the text enough to cover the whole path PLUS one extra unit,\n  // so shifting by exactly one unit is visually identical (seamless loop).\n  const fullText = useMemo(() => {\n    if (!text) return \"\";\n    if (!autoRepeat) return text;\n    if (unitWidth <= 0 || pathLength <= 0) return text.repeat(8);\n    const repeatCount = Math.ceil((pathLength + unitWidth) / unitWidth) + 1;\n    return text.repeat(repeatCount);\n  }, [text, unitWidth, pathLength, autoRepeat]);\n\n  // Infinite seamless animation\n  useEffect(() => {\n    const tp = textPathRef.current;\n    if (!tp || unitWidth <= 0 || pathLength <= 0) return;\n\n    // Forward: offset runs -unit -> 0. Reverse: 0 -> -unit.\n    const setOffset = (shift: number) => {\n      const value = reverse ? -shift : -unitWidth + shift;\n      tp.setAttribute(\"startOffset\", `${value}`);\n    };\n\n    if (shouldReduceMotion) {\n      setOffset(0);\n      return;\n    }\n\n    // duration = seconds for text to travel one full lap\n    const speed = pathLength / Math.max(duration, 0.1); // px per second\n    let raf = 0;\n    let last = performance.now();\n    let shift = 0;\n\n    const tick = (now: number) => {\n      const dt = (now - last) / 1000;\n      last = now;\n      shift = (shift + speed * dt) % unitWidth;\n      setOffset(shift);\n      raf = requestAnimationFrame(tick);\n    };\n\n    setOffset(0);\n    raf = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(raf);\n  }, [unitWidth, pathLength, duration, reverse, shouldReduceMotion, fullText]);\n\n  return (\n    <div ref={containerRef} className={cn(\"relative rounded-2xl w-fit h-fit \", className)} {...props}>\n      <svg\n        className=\"pointer-events-none absolute inset-0 h-full w-full overflow-visible\"\n        viewBox={`0 0 ${dimensions.width} ${dimensions.height}`}\n        aria-hidden=\"true\"\n      >\n        <defs>\n          <path ref={pathRef} id={pathId} d={svgPathData} />\n          {glow && (\n            <filter\n              id={`glow-${pathId}`}\n              x=\"-20%\"\n              y=\"-20%\"\n              width=\"140%\"\n              height=\"140%\"\n            >\n              <feGaussianBlur stdDeviation=\"2\" result=\"blur\" />\n              <feMerge>\n                <feMergeNode in=\"blur\" />\n                <feMergeNode in=\"SourceGraphic\" />\n              </feMerge>\n            </filter>\n          )}\n        </defs>\n\n        {/* Hidden element used only to measure one text unit */}\n        <text\n          ref={measureRef}\n          fontSize={fontSize}\n          fontWeight={fontWeight}\n          letterSpacing={letterSpacing}\n          style={{ textTransform: \"uppercase\", visibility: \"hidden\" }}\n        >\n          {text}\n        </text>\n\n        {trackColor && (\n          <path\n            d={svgPathData}\n            fill=\"none\"\n            stroke={trackColor}\n            strokeWidth={trackWidth}\n          />\n        )}\n\n        <motion.text\n          fill={textColor}\n          fontSize={fontSize}\n          fontWeight={fontWeight}\n          letterSpacing={letterSpacing}\n          filter={glow ? `url(#glow-${pathId})` : undefined}\n          style={{ textTransform: \"uppercase\" }}\n          initial={{ opacity: 0 }}\n          animate={{ opacity: 1 }}\n          transition={{ duration: 0.3 }}\n        >\n          <textPath ref={textPathRef} href={`#${pathId}`} startOffset={0}>\n            {fullText}\n          </textPath>\n        </motion.text>\n      </svg>\n\n      <div className={cn(\"relative z-10\", contentClassName)}>\n        {children || (\n          <div className=\"flex flex-col items-center justify-center text-center py-4\">\n            <span className=\"text-sm font-semibold text-neutral-900 dark:text-white\">\n              Moving Text Border\n            </span>\n            <p className=\"mt-1 text-xs text-neutral-500 dark:text-neutral-400 max-w-xs\">\n              Animated typography continuously marching along the perimeter of this card.\n            </p>\n          </div>\n        )}\n      </div>\n    </div>\n  );\n}\n\nexport default MovingTextBorder;",
      "type": "registry:ui",
      "target": "components/ui/moving-text-border.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
