{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "celebrate",
  "type": "registry:ui",
  "title": "Celebrate",
  "description": "Small, one-time moments for something the player earned: a streak that hits a milestone, a perfect round, a right answer. `Celebrate` wraps the thing that earned it and, each time `play` changes, sends a short burst of rays and a ring out from it.…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "decorative",
    "effect"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/motion-token.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/effects/celebrate.tsx",
      "target": "components/ui/effects/celebrate.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/celebrate v1.0.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/celebrate\n// What changed since: https://ds.interlace.tools/c/celebrate#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — Celebrate, CelebrateCheck, vibrate\n *\n * Small, one-time moments for something the player earned: a streak that\n * hits a milestone, a perfect round, a right answer. `Celebrate` wraps the\n * thing that earned it and, each time `play` changes, sends a short burst of\n * rays and a ring out from it. `CelebrateCheck` is a check mark that draws\n * itself. `vibrate` gives a matching tap on phones that support it.\n *\n * They mark an arrival, once. Nothing loops, nothing covers the content,\n * and the words that say what happened (a result line, a streak count) stay\n * the job of the component being celebrated.\n *\n * ## Anatomy\n *\n *   Celebrate                      (span — data-slot=\"celebrate\", data-tone)\n *     ├─ children                  (the thing being celebrated, untouched)\n *     └─ span aria-hidden          (data-slot=\"celebrate-burst\": a ring and `rays` rays, idle until played)\n *\n *   CelebrateCheck                 (span role=\"img\" — data-slot=\"celebrate-check\")\n *     └─ svg                       (circle + check path, drawn in)\n *\n * ## When it plays\n *\n * `Celebrate` plays when `play` changes to a new truthy value (a count, a\n * key, `true`), never on the first render, so restoring a page does not\n * replay yesterday's moment. `CelebrateCheck` draws in on mount unless\n * `animate={false}`.\n *\n * ## Motion\n *\n * The burst is 600ms, the check 300ms; both animate only `transform`,\n * `opacity` and `stroke-dashoffset`, on the Web Animations API. Under\n * reduced motion the burst does not play at all and the check is simply\n * drawn. `vibrate` is separate from motion and off unless asked for\n * (`haptic` on Celebrate, or a direct call), and it does nothing where the\n * browser has no Vibration API.\n *\n * | Rule | Concept                 | Where in this file                                   |\n * | ---- | ----------------------- | ---------------------------------------------------- |\n * | R4   | Extends native el       | `span` props                                         |\n * | R6   | data-slot per part      | celebrate / -burst / -ring / -ray; celebrate-check   |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                    |\n * | R8   | Enums, not booleans     | `tone`, `size`                                       |\n * | R19  | Tokens only             | primary, success, highlight                          |\n * | R25  | Client component        | the burst runs in the browser                        |\n * | R26  | A11y                    | burst hidden; check named by `label`                 |\n */\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\nimport { motionEase } from '@/lib/motion-token';\n\nexport type CelebrateTone = 'primary' | 'success' | 'highlight';\n\nconst TONE: Record<CelebrateTone, { bg: string; border: string; stroke: string }> = {\n  primary: { bg: 'bg-primary', border: 'border-primary', stroke: 'stroke-primary' },\n  success: { bg: 'bg-success', border: 'border-success', stroke: 'stroke-success' },\n  highlight: { bg: 'bg-highlight', border: 'border-highlight', stroke: 'stroke-highlight' },\n};\n\n/** Named vibration patterns, in ms (on, off, on…). */\nexport const HAPTICS = {\n  tap: [10],\n  success: [12, 60, 18],\n  milestone: [14, 50, 14, 50, 28],\n  miss: [30, 40, 30],\n} as const satisfies Record<string, readonly number[]>;\n\nexport type HapticPattern = keyof typeof HAPTICS;\n\n/** A short vibration where the browser supports it. Returns whether it ran. */\nexport function vibrate(pattern: HapticPattern | readonly number[] = 'tap'): boolean {\n  if (typeof navigator === 'undefined' || typeof navigator.vibrate !== 'function') return false;\n  const p = typeof pattern === 'string' ? HAPTICS[pattern] : pattern;\n  try {\n    return navigator.vibrate([...p]);\n  } catch {\n    return false;\n  }\n}\n\nexport interface CelebrateProps extends React.ComponentPropsWithoutRef<'span'> {\n  /** Plays the burst each time this changes to a new truthy value. Not on the first render. */\n  play?: string | number | boolean | null;\n  /** @default 'primary' */\n  tone?: CelebrateTone;\n  /** How many rays. @default 12 */\n  rays?: number;\n  /** Also vibrate with this pattern when it plays. Off by default. */\n  haptic?: HapticPattern | false;\n}\n\nfunction Celebrate({ play, tone = 'primary', rays = 12, haptic = false, className, children, ...props }: CelebrateProps) {\n  const reduced = useReducedMotion();\n  const rootRef = React.useRef<HTMLSpanElement>(null);\n  const last = React.useRef(play);\n  const count = Math.max(0, Math.min(24, Math.round(rays)));\n\n  React.useEffect(() => {\n    const prev = last.current;\n    last.current = play;\n    if (!play || play === prev) return;\n    if (haptic) vibrate(haptic);\n    const root = rootRef.current;\n    if (reduced || !root) return;\n    const box = root.getBoundingClientRect();\n    const r0 = Math.max(box.width, box.height) / 2;\n    const ring = root.querySelector<HTMLElement>('[data-slot=\"celebrate-ring\"]');\n    const easing = motionEase(root, 'enter');\n    if (ring && typeof ring.animate === 'function') {\n      ring.animate(\n        [\n          { transform: 'scale(0.85)', opacity: 0.6 },\n          { transform: 'scale(1.35)', opacity: 0 },\n        ],\n        { duration: 500, easing },\n      );\n    }\n    root.querySelectorAll<HTMLElement>('[data-slot=\"celebrate-ray\"]').forEach((ray, i) => {\n      if (typeof ray.animate !== 'function') return;\n      const a = (360 / count) * i;\n      const far = r0 + 14 + (i % 2) * 8;\n      ray.animate(\n        [\n          { transform: `rotate(${a}deg) translateY(-${r0}px) scaleY(0.2)`, opacity: 0 },\n          { transform: `rotate(${a}deg) translateY(-${r0 + 6}px) scaleY(1)`, opacity: 1, offset: 0.3 },\n          { transform: `rotate(${a}deg) translateY(-${far}px) scaleY(0.4)`, opacity: 0 },\n        ],\n        { duration: 600, easing },\n      );\n    });\n  }, [play, reduced, haptic, count]);\n\n  const t = TONE[tone];\n  return (\n    <span\n      ref={rootRef}\n      data-slot=\"celebrate\"\n      data-tone={tone}\n      className={cn('relative inline-grid', className)}\n      {...props}\n    >\n      {children}\n      <span\n        aria-hidden\n        data-slot=\"celebrate-burst\"\n        className=\"pointer-events-none absolute inset-0 grid place-items-center overflow-visible\"\n      >\n        <span\n          data-slot=\"celebrate-ring\"\n          className={cn('col-start-1 row-start-1 size-full rounded-full border-2 opacity-0', t.border)}\n        />\n        {Array.from({ length: count }, (_, i) => (\n          <span\n            key={i}\n            data-slot=\"celebrate-ray\"\n            className={cn('col-start-1 row-start-1 h-2 w-0.5 rounded-full opacity-0', t.bg)}\n          />\n        ))}\n      </span>\n    </span>\n  );\n}\nCelebrate.displayName = 'Celebrate';\n\nexport interface CelebrateCheckProps extends Omit<React.ComponentPropsWithoutRef<'span'>, 'children'> {\n  /** Names the mark for assistive tech. Leave out when nearby text already says it; the mark is then hidden. */\n  label?: string;\n  /** Draw in on mount. @default true */\n  animate?: boolean;\n  /** @default 'success' */\n  tone?: CelebrateTone;\n  /** @default 'default' */\n  size?: 'sm' | 'default' | 'lg';\n}\n\nconst CHECK_SIZE = { sm: 'size-5', default: 'size-8', lg: 'size-12' } as const;\nconst CIRCLE = 2 * Math.PI * 10;\nconst TICK = 14;\n\nfunction CelebrateCheck({ label, animate = true, tone = 'success', size = 'default', className, ...props }: CelebrateCheckProps) {\n  const reduced = useReducedMotion();\n  const svgRef = React.useRef<SVGSVGElement>(null);\n\n  React.useEffect(() => {\n    if (!animate || reduced) return;\n    const [circle, tick] = Array.from(svgRef.current?.querySelectorAll<SVGElement>('circle, path') ?? []);\n    const svg = svgRef.current;\n    if (!svg) return;\n    const easing = motionEase(svg, 'enter');\n    if (circle && typeof circle.animate === 'function') {\n      circle.animate([{ strokeDashoffset: `${CIRCLE}` }, { strokeDashoffset: '0' }], { duration: 300, easing });\n    }\n    if (tick && typeof tick.animate === 'function') {\n      tick.animate([{ strokeDashoffset: `${TICK}` }, { strokeDashoffset: `${TICK}`, offset: 0.4 }, { strokeDashoffset: '0' }], {\n        duration: 300,\n        easing,\n      });\n    }\n    // Mount only.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n\n  const t = TONE[tone];\n  return (\n    <span\n      data-slot=\"celebrate-check\"\n      role={label ? 'img' : undefined}\n      aria-label={label}\n      aria-hidden={label ? undefined : true}\n      className={cn('inline-block shrink-0', CHECK_SIZE[size], className)}\n      {...props}\n    >\n      <svg ref={svgRef} viewBox=\"0 0 24 24\" fill=\"none\" strokeWidth=\"2.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className={cn('size-full', t.stroke)}>\n        <circle cx=\"12\" cy=\"12\" r=\"10\" strokeDasharray={CIRCLE} strokeDashoffset={0} transform=\"rotate(-90 12 12)\" />\n        <path d=\"M7.5 12.5l3 3 6-6.5\" strokeDasharray={TICK} strokeDashoffset={0} />\n      </svg>\n    </span>\n  );\n}\nCelebrateCheck.displayName = 'CelebrateCheck';\n\nexport { Celebrate, CelebrateCheck };\n"
    }
  ],
  "meta": {
    "tier": "effect",
    "client": true,
    "minViewport": null,
    "loading": false,
    "version": "1.0.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/celebrate\n\nInstalled to `components/ui/effects/celebrate.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/effects/celebrate';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/celebrate\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
