{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-confetti",
  "description": "Confetti animation with 4 presets. Also exports useConfetti hook.",
  "dependencies": [
    "canvas-confetti",
    "class-variance-authority"
  ],
  "files": [
    {
      "path": "components/ds/ds-confetti.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva } from \"class-variance-authority\"\nimport { cn } from \"@/lib/utils\"\n\n// ── Types ──────────────────────────────────────────────────────────────────\n\nexport interface ConfettiOptions {\n  /** Number of confetti pieces */\n  particleCount?: number\n  /** Spread angle in degrees */\n  spread?: number\n  /** Initial velocity (pixels per frame) */\n  startVelocity?: number\n  /** Decay factor — how quickly particles slow down (0–1) */\n  decay?: number\n  /** Gravity (1 = normal, 0 = floating) */\n  gravity?: number\n  /** Drift (1 = right) */\n  drift?: number\n  /** Particle colors — defaults to LEMA chart tokens */\n  colors?: string[]\n  /** Confetti shapes */\n  shapes?: (\"square\" | \"circle\" | \"star\")[]\n  /** Scalar for particle size */\n  scalar?: number\n  /** X origin (0 = left, 1 = right, 0.5 = center) */\n  originX?: number\n  /** Y origin (0 = top, 1 = bottom) */\n  originY?: number\n  /** Z-index of the canvas */\n  zIndex?: number\n}\n\nexport type ConfettiVariant = \"burst\" | \"fireworks\" | \"rain\" | \"sides\"\n\nexport interface ConfettiProps extends React.HTMLAttributes<HTMLDivElement> {\n  /** When true, fires the confetti animation */\n  trigger?: boolean\n  /** Preset animation variant */\n  variant?: ConfettiVariant\n  /** Fine-grained options forwarded to canvas-confetti */\n  options?: ConfettiOptions\n  /** Children are rendered inside the wrapper — useful for wrapping a success button */\n  children?: React.ReactNode\n}\n\n// ── Variants ───────────────────────────────────────────────────────────────\n\nexport const confettiContainerVariants = cva(\"relative inline-flex\", {\n  variants: {},\n})\n\n// ── Default colors (LEMA chart token equivalents) ─────────────────────────\n\nconst DEFAULT_COLORS = [\n  \"#6366f1\", // chart-1 violet\n  \"#f59e0b\", // chart-2 amber\n  \"#10b981\", // chart-3 emerald\n  \"#3b82f6\", // chart-4 blue\n  \"#f43f5e\", // chart-5 rose\n  \"#8b5cf6\", // extra violet\n  \"#06b6d4\", // extra cyan\n]\n\n// ── Prefers-reduced-motion helper ────────────────────────────────────────\n\nexport function prefersReducedMotion(): boolean {\n  return (\n    typeof window !== \"undefined\" &&\n    window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n  )\n}\n\n/**\n * Static non-animated celebration for `prefers-reduced-motion` users.\n * Announces via an `aria-live` region and can be overridden by consumers\n * that wish to render a purely decorative static alternative.\n */\nexport function showConfettiStaticFallback(): void {\n  if (typeof document === \"undefined\") return\n  const announcement = document.createElement(\"div\")\n  announcement.setAttribute(\"role\", \"status\")\n  announcement.setAttribute(\"aria-live\", \"polite\")\n  announcement.className = \"sr-only\"\n  announcement.textContent = \"Celebration\"\n  document.body.appendChild(announcement)\n  window.setTimeout(() => announcement.remove(), 1500)\n}\n\n// Re-export under alternative name for backwards-compat with specs that\n// reference `fireConfettiStatic`.\nexport const fireConfettiStatic = showConfettiStaticFallback\n\n// ── Confetti firing logic ─────────────────────────────────────────────────\n\nasync function fireConfetti(\n  variant: ConfettiVariant,\n  options: ConfettiOptions\n) {\n  if (\n    typeof window !== \"undefined\" &&\n    window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n  ) {\n    showConfettiStaticFallback()\n    return\n  }\n\n  const confetti = (await import(\"canvas-confetti\")).default\n\n  const base: Parameters<typeof confetti>[0] = {\n    particleCount: options.particleCount ?? 80,\n    spread: options.spread ?? 70,\n    startVelocity: options.startVelocity ?? 45,\n    decay: options.decay ?? 0.9,\n    gravity: options.gravity ?? 1,\n    drift: options.drift ?? 0,\n    colors: options.colors ?? DEFAULT_COLORS,\n    shapes: options.shapes ?? [\"square\", \"circle\"],\n    scalar: options.scalar ?? 1,\n    zIndex: options.zIndex ?? 9999,\n    origin: {\n      x: options.originX ?? 0.5,\n      y: options.originY ?? 0.6,\n    },\n  }\n\n  switch (variant) {\n    case \"burst\":\n      await confetti({ ...base })\n      break\n\n    case \"fireworks\": {\n      const duration = 2000\n      const end = Date.now() + duration\n      const frame = () => {\n        confetti({\n          ...base,\n          particleCount: 6,\n          origin: { x: Math.random(), y: Math.random() * 0.5 },\n        })\n        if (Date.now() < end) requestAnimationFrame(frame)\n      }\n      frame()\n      break\n    }\n\n    case \"rain\":\n      await confetti({\n        ...base,\n        particleCount: 200,\n        spread: 160,\n        startVelocity: 25,\n        gravity: 0.4,\n        origin: { x: 0.5, y: -0.1 },\n      })\n      break\n\n    case \"sides\":\n      await Promise.all([\n        confetti({ ...base, origin: { x: 0, y: 0.6 }, angle: 60 }),\n        confetti({ ...base, origin: { x: 1, y: 0.6 }, angle: 120 }),\n      ])\n      break\n  }\n}\n\n// ── Confetti ───────────────────────────────────────────────────────────────\n\nexport function Confetti({\n  trigger = false,\n  variant = \"burst\",\n  options = {},\n  children,\n  className,\n  ...props\n}: ConfettiProps) {\n  const prevTrigger = React.useRef(false)\n\n  React.useEffect(() => {\n    if (trigger && !prevTrigger.current) {\n      fireConfetti(variant, options).catch(console.error)\n    }\n    prevTrigger.current = trigger\n  }, [trigger, variant, options])\n\n  if (!children) return null\n\n  return (\n    <div className={cn(confettiContainerVariants(), className)} {...props}>\n      {children}\n    </div>\n  )\n}\n\n// ── useConfetti hook ───────────────────────────────────────────────────────\n\n/**\n * Programmatic confetti — call `fire()` directly without the wrapper component.\n *\n * @example\n * const { fire } = useConfetti()\n * <Button onClick={() => fire(\"fireworks\")}>Celebrate</Button>\n */\nexport function useConfetti() {\n  const fire = React.useCallback(\n    (variant: ConfettiVariant = \"burst\", options: ConfettiOptions = {}) => {\n      fireConfetti(variant, options).catch(console.error)\n    },\n    []\n  )\n  return { fire }\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
