{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"glyph-spill","type":"registry:ui","title":"Glyph Spill","description":"A trail of glyphs or emoji that spills from the pointer inside its container, spinning and fading as it drifts.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/glyph-spill.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useRef, type PointerEvent, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface GlyphSpillProps {\n  /** Glyphs or emoji dropped along the trail, used in order. */\n  items?: string[];\n  /** Colors cycled per glyph. Emoji keep their own colors. */\n  colors?: string[];\n  /** Px the pointer travels between glyphs. */\n  spacing?: number;\n  /** Ms each glyph lives. */\n  lifetime?: number;\n  /** Glyph size in px. */\n  size?: number;\n  /** Degrees each glyph spins while fading. */\n  spin?: number;\n  /** Cap on glyphs alive at once. */\n  maxItems?: number;\n  children?: ReactNode;\n  className?: string;\n}\n\nexport function GlyphSpill({\n  items = [\"✦\", \"✧\", \"✶\", \"⋆\"],\n  colors = [\"#bef264\", \"#67e8f9\", \"#f0abfc\"],\n  spacing = 22,\n  lifetime = 1000,\n  size = 30,\n  spin = 180,\n  maxItems = 60,\n  children,\n  className,\n}: GlyphSpillProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const layer = useRef<HTMLDivElement>(null);\n  const last = useRef<{ x: number; y: number } | null>(null);\n  const count = useRef(0);\n\n  const spawn = (x: number, y: number, angle: number) => {\n    const host = layer.current;\n    if (!host || !items.length) return;\n    const n = count.current++;\n    const el = document.createElement(\"span\");\n    el.textContent = items[n % items.length];\n    el.style.cssText = `position:absolute;left:${x}px;top:${y}px;font-size:${size}px;line-height:1;color:${\n      colors.length ? colors[n % colors.length] : \"currentColor\"\n    };text-shadow:0 0 12px currentColor;will-change:transform,opacity`;\n    host.appendChild(el);\n    while (host.childElementCount > maxItems) host.firstElementChild?.remove();\n    // Drift backwards from the direction of travel, with a little sideways scatter and gravity.\n    const back = 18 + Math.random() * 22;\n    const dx = -Math.cos(angle) * back + (Math.random() - 0.5) * 24;\n    const dy = -Math.sin(angle) * back + (Math.random() - 0.5) * 24 + 18;\n    const r0 = (Math.random() - 0.5) * 60;\n    const r1 = r0 + (Math.random() < 0.5 ? -spin : spin);\n    const anim = el.animate(\n      [\n        { transform: `translate(-50%,-50%) rotate(${r0}deg) scale(0.3)`, opacity: 0, easing: \"cubic-bezier(.2,1.4,.4,1)\" },\n        { transform: `translate(-50%,-50%) rotate(${r0}deg) scale(1.15)`, opacity: 1, offset: 0.12, easing: \"ease-out\" },\n        {\n          transform: `translate(calc(-50% + ${dx * 0.5}px),calc(-50% + ${dy * 0.5}px)) rotate(${(r0 + r1) / 2}deg) scale(0.9)`,\n          opacity: 0.9,\n          offset: 0.55,\n          easing: \"ease-in\",\n        },\n        { transform: `translate(calc(-50% + ${dx}px),calc(-50% + ${dy}px)) rotate(${r1}deg) scale(0.2)`, opacity: 0 },\n      ],\n      { duration: lifetime, fill: \"forwards\" },\n    );\n    anim.onfinish = () => el.remove();\n  };\n\n  const onPointerMove = (e: PointerEvent<HTMLDivElement>) => {\n    if (!root.current || window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const r = root.current.getBoundingClientRect();\n    const x = e.clientX - r.left;\n    const y = e.clientY - r.top;\n    const prev = last.current;\n    if (!prev) {\n      last.current = { x, y };\n      return;\n    }\n    const dist = Math.hypot(x - prev.x, y - prev.y);\n    const step = Math.max(4, spacing);\n    if (dist < step) return;\n    const angle = Math.atan2(y - prev.y, x - prev.x);\n    // Fill fast moves with evenly spaced glyphs so the trail never gaps.\n    const steps = Math.min(8, Math.floor(dist / step));\n    for (let k = 1; k <= steps; k++) {\n      spawn(prev.x + ((x - prev.x) * k) / steps, prev.y + ((y - prev.y) * k) / steps, angle);\n    }\n    last.current = { x, y };\n  };\n\n  return (\n    <div\n      ref={root}\n      className={cn(\"relative overflow-hidden\", className)}\n      onPointerMove={onPointerMove}\n      onPointerLeave={() => (last.current = null)}\n    >\n      {children}\n      <div ref={layer} aria-hidden className=\"pointer-events-none absolute inset-0 select-none\" />\n    </div>\n  );\n}\n"}]}