{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "confetti",
  "type": "registry:component",
  "title": "Confetti",
  "description": "A short burst of flat paper pieces in the chart colours from a point, falling and fading on a canvas over the page, started from code (the handle's `fire`) and never under reduced motion; it says nothing and takes no clicks.",
  "categories": [
    "motion"
  ],
  "dependencies": [],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn",
    "@rivier-ui/motion",
    "@rivier-ui/theme-color"
  ],
  "files": [
    {
      "path": "registry/motion/confetti.tsx",
      "type": "registry:component",
      "target": "components/motion/confetti.tsx",
      "content": "\"use client\";\n/**\n * @name confetti\n * @category motion\n * @description A short burst of flat paper pieces in the chart colours from a point, falling and fading on a canvas over the page, started from code (the handle's `fire`) and never under reduced motion; it says nothing and takes no clicks.\n * @when Marking a rare success the person worked for: a first project published, a goal reached. Never for routine actions, never on page load. Say the success in words as well (a toast, a heading): the burst is decoration.\n * @example\n * const confetti = useRef<ConfettiHandle>(null);\n * <Confetti handleRef={confetti} />\n * <Button onClick={(e) => confetti.current?.fire({ x: e.clientX, y: e.clientY })}>Publish</Button>\n */\nimport { useEffect, useImperativeHandle, useRef, type ComponentProps, type Ref } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { useMotionSafe } from \"@/lib/motion\";\nimport { readThemeColor } from \"@/lib/theme-color\";\n\nexport type ConfettiHandle = {\n  /** A burst from a point in the window (clientX, clientY); the middle of the window when left out. */\n  fire: (from?: { x: number; y: number }) => void;\n};\n\nexport type ConfettiProps = Omit<ComponentProps<\"canvas\">, \"children\"> & {\n  handleRef?: Ref<ConfettiHandle>;\n  /** Pieces in one burst. Default 120. */\n  count?: number;\n  /** Seconds a burst lasts. Default 1.8. */\n  duration?: number;\n};\n\ntype Piece = { x: number; y: number; vx: number; vy: number; turn: number; spin: number; w: number; h: number; color: string };\n\nexport function Confetti({ handleRef, count = 120, duration = 1.8, className, ...props }: ConfettiProps) {\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const pieces = useRef<Piece[]>([]);\n  const frame = useRef(0);\n  const started = useRef(0);\n  const safe = useMotionSafe();\n  useEffect(() => () => cancelAnimationFrame(frame.current), []);\n  useImperativeHandle(\n    handleRef,\n    () => ({\n      fire(from) {\n        const node = canvas.current;\n        if (!safe || !node) return;\n        const ratio = Math.min(2, window.devicePixelRatio || 1);\n        node.width = window.innerWidth * ratio;\n        node.height = window.innerHeight * ratio;\n        const context = node.getContext(\"2d\");\n        if (!context) return;\n        context.setTransform(ratio, 0, 0, ratio, 0, 0);\n        const colors = [\"--chart-1\", \"--chart-2\", \"--chart-3\", \"--chart-4\", \"--chart-5\"].map((name) => readThemeColor(name, node));\n        const x = from?.x ?? window.innerWidth / 2;\n        const y = from?.y ?? window.innerHeight / 2;\n        pieces.current = Array.from({ length: count }, (_, i) => {\n          const angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI * 0.9;\n          const speed = 6 + Math.random() * 8;\n          return { x, y, vx: Math.cos(angle) * speed, vy: Math.sin(angle) * speed, turn: Math.random() * Math.PI, spin: (Math.random() - 0.5) * 0.4, w: 6 + Math.random() * 4, h: 3 + Math.random() * 3, color: colors[i % colors.length] ?? \"currentColor\" };\n        });\n        started.current = performance.now();\n        cancelAnimationFrame(frame.current);\n        const step = (now: number): void => {\n          const age = (now - started.current) / 1000;\n          context.clearRect(0, 0, window.innerWidth, window.innerHeight);\n          if (age > duration) return;\n          const fade = Math.max(0, 1 - age / duration);\n          for (const p of pieces.current) {\n            p.vy += 0.35;\n            p.vx *= 0.985;\n            p.x += p.vx;\n            p.y += p.vy;\n            p.turn += p.spin;\n            context.save();\n            context.globalAlpha = fade;\n            context.translate(p.x, p.y);\n            context.rotate(p.turn);\n            context.fillStyle = p.color;\n            context.fillRect(-p.w / 2, -p.h / 2, p.w, p.h);\n            context.restore();\n          }\n          frame.current = requestAnimationFrame(step);\n        };\n        frame.current = requestAnimationFrame(step);\n      },\n    }),\n    [safe, count, duration],\n  );\n  return <canvas ref={canvas} data-slot=\"confetti\" aria-hidden=\"true\" className={cn(\"pointer-events-none fixed inset-0 z-[70] size-full\", className)} {...props} />;\n}\n"
    }
  ],
  "meta": {
    "category": "motion",
    "when": "Marking a rare success the person worked for: a first project published, a goal reached. Never for routine actions, never on page load. Say the success in words as well (a toast, a heading): the burst is decoration.",
    "example": "const confetti = useRef<ConfettiHandle>(null);\n<Confetti handleRef={confetti} />\n<Button onClick={(e) => confetti.current?.fire({ x: e.clientX, y: e.clientY })}>Publish</Button>",
    "client": true
  }
}
