{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"sparkle-text","type":"registry:ui","title":"Sparkle text","description":"Text with small four-point stars that bloom, turn and fade around it at uneven moments, for the one word that should feel special: a reward, a new plan, a finished setup.","dependencies":["clsx","tailwind-merge"],"registryDependencies":["https://caliperui.site/r/styles.json"],"files":[{"path":"ui/lib/cn.ts","type":"registry:ui","target":"components/ui/lib/cn.ts","content":"import { clsx, type ClassValue } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\nconst twMerge = extendTailwindMerge({\n  extend: { theme: { radius: [\"control\", \"surface\", \"overlay\"], shadow: [\"overlay\"] } },\n});\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n"},{"path":"ui/sparkle-text.tsx","type":"registry:ui","target":"components/ui/sparkle-text.tsx","content":"\"use client\";\nimport { useEffect, useRef, useState, type ComponentProps, type CSSProperties } from \"react\";\nimport { cn } from \"./lib/cn\";\nimport \"./sparkle-text.css\";\n\nexport type SparkleTextProps = Omit<ComponentProps<\"span\">, \"color\"> & {\n  /** Colour of the sparkles, or a few colours for each star to pick from; defaults to the accent. */\n  color?: string | string[];\n  /** Turns the sparkles off without changing the text. */\n  disabled?: boolean;\n};\n\ntype Sparkle = { id: number; x: number; y: number; size: number; born: number; tint: number };\n\nconst LIFE = 760;\nconst random = (min: number, max: number) => min + Math.random() * (max - min);\nconst make = (now: number): Sparkle => ({ id: now + Math.random(), x: random(-4, 100), y: random(-10, 92), size: random(9, 17), born: now, tint: Math.floor(random(0, 64)) });\n\n/**\n * Text with small four-point stars that bloom and fade around it at uneven moments, for the one word that should\n * feel special: a reward, a new plan, a finished setup. Only the text is read; the stars are decoration. They stop\n * while the text is off screen and do not appear under reduced motion.\n */\nexport function SparkleText({ color = \"var(--accent)\", disabled = false, className, children, ...props }: SparkleTextProps) {\n  const root = useRef<HTMLSpanElement>(null);\n  const [sparkles, setSparkles] = useState<Sparkle[]>([]);\n\n  useEffect(() => {\n    const element = root.current;\n    if (!element || disabled || matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    let timer = 0;\n    let visible = false;\n    const tick = () => {\n      const now = Date.now();\n      setSparkles((list) => [...list.filter((s) => now - s.born < LIFE), make(now)]);\n      timer = window.setTimeout(tick, random(90, 480));\n    };\n    const observer = new IntersectionObserver(([entry]) => {\n      const next = !!entry?.isIntersecting;\n      if (next === visible) return;\n      visible = next;\n      window.clearTimeout(timer);\n      if (visible) tick();\n    });\n    observer.observe(element);\n    return () => {\n      observer.disconnect();\n      window.clearTimeout(timer);\n      setSparkles([]);\n    };\n  }, [disabled]);\n\n  return (\n    <span ref={root} data-slot=\"sparkle-text\" className={cn(\"relative inline-block\", className)} {...props}>\n      {sparkles.map((s) => (\n        <svg key={s.id} data-slot=\"st-star\" aria-hidden=\"true\" viewBox=\"0 0 20 20\" width={s.size} height={s.size} style={{ left: `${s.x}%`, top: `${s.y}%`, color: typeof color === \"string\" ? color : color[s.tint % color.length] } as CSSProperties}>\n          <path d=\"M10 0Q11.3 8.7 20 10Q11.3 11.3 10 20Q8.7 11.3 0 10Q8.7 8.7 10 0Z\" fill=\"currentColor\" />\n        </svg>\n      ))}\n      <span className=\"relative\">{children}</span>\n    </span>\n  );\n}\n"},{"path":"ui/sparkle-text.css","type":"registry:file","target":"components/ui/sparkle-text.css","content":"/* sparkle-text.tsx's styles; it imports this file. Edit freely. */\n@layer theme, base, components, utilities;\n\n@layer components {\n  /* Sparkle text: stars bloom, turn and fade around the text, behind it. */\n  [data-slot=\"sparkle-text\"] [data-slot=\"st-star\"] { position: absolute; z-index: 0; pointer-events: none; translate: -50% -50%; animation: st-bloom 760ms var(--ease-in-out) forwards; }\n  @media (prefers-reduced-motion: reduce) {\n    [data-slot=\"sparkle-text\"] [data-slot=\"st-star\"] { display: none; }\n  }\n  @keyframes st-bloom { 0% { scale: 0; rotate: 0deg; } 50% { scale: 1; rotate: 90deg; } 100% { scale: 0; rotate: 180deg; } }\n}\n"}],"categories":["motion"],"meta":{"tier":"free","license":"MIT","family":"text-motion","docs":"/docs/components/sparkle-text"}}