{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "like-burst",
  "type": "registry:component",
  "title": "Like Burst",
  "description": "A heart button that fills with a bouncy pop, scatters a ring of particles and rolls its count to the new value.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "social",
    "like",
    "heart",
    "button",
    "burst",
    "counter",
    "favorite"
  ],
  "docs": "https://hyperblur.dev/effects/like-burst",
  "files": [
    {
      "path": "registry/hyperblur/like-burst.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/like-burst.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface LikeBurstProps\n  extends Omit<React.HTMLAttributes<HTMLSpanElement>, \"onChange\" | \"defaultValue\"> {\n  count?: number;\n  liked?: boolean;\n  defaultLiked?: boolean;\n  onChange?: (liked: boolean, count: number) => void;\n  color?: string;\n  size?: number;\n  label?: string;\n}\n\ninterface Roll {\n  from: string;\n  to: string;\n  up: boolean;\n  id: number;\n}\n\ninterface View {\n  total: number;\n  liked: boolean;\n  text: string;\n  bump: number;\n  burst: number;\n  roll: Roll | null;\n}\n\nconst css = `\n.hb-lb {\n  position: relative;\n  display: inline-flex;\n  vertical-align: middle;\n  font-family: inherit;\n}\n.hb-lb-btn {\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  gap: calc(var(--hb-s) * 0.32);\n  margin: 0;\n  padding: calc(var(--hb-s) * 0.3) calc(var(--hb-s) * 0.55) calc(var(--hb-s) * 0.3) calc(var(--hb-s) * 0.45);\n  border: 1px solid #262626;\n  border-radius: 999px;\n  background: #171717;\n  color: #8f8f8f;\n  font: inherit;\n  font-size: calc(var(--hb-s) * 0.6);\n  font-weight: 600;\n  line-height: 1;\n  cursor: pointer;\n  user-select: none;\n  touch-action: manipulation;\n  -webkit-tap-highlight-color: transparent;\n  transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease, transform 0.12s ease;\n}\n.hb-lb-btn:hover { border-color: #3a3a3a; color: #ededed; }\n.hb-lb-btn:active { transform: scale(0.96); }\n.hb-lb-btn:focus-visible { outline: 2px solid var(--hb-c); outline-offset: 3px; }\n.hb-lb-btn[aria-pressed=\"true\"] {\n  border-color: color-mix(in srgb, var(--hb-c) 45%, #262626);\n  background: color-mix(in srgb, var(--hb-c) 10%, #171717);\n  color: #ededed;\n}\n.hb-lb-ico {\n  position: relative;\n  display: inline-flex;\n  width: var(--hb-s);\n  height: var(--hb-s);\n  flex: none;\n}\n.hb-lb-heart {\n  display: block;\n  width: 100%;\n  height: 100%;\n  transform-origin: 50% 60%;\n}\n.hb-lb-heart svg {\n  display: block;\n  width: 100%;\n  height: 100%;\n  fill: transparent;\n  stroke: currentColor;\n  stroke-width: 1.8;\n  stroke-linejoin: round;\n}\n.hb-lb-btn[aria-pressed=\"true\"] .hb-lb-heart svg {\n  fill: var(--hb-c);\n  stroke: var(--hb-c);\n}\n.hb-lb-heart[data-pop=\"like\"] { animation: hb-lb-pop 0.55s cubic-bezier(0.3, 1.5, 0.5, 1); }\n.hb-lb-heart[data-pop=\"unlike\"] { animation: hb-lb-shrink 0.3s ease-out; }\n@keyframes hb-lb-pop {\n  0% { transform: scale(0.55); }\n  40% { transform: scale(1.38); }\n  68% { transform: scale(0.9); }\n  100% { transform: scale(1); }\n}\n@keyframes hb-lb-shrink {\n  0% { transform: scale(1.12); }\n  100% { transform: scale(1); }\n}\n.hb-lb-burst {\n  position: absolute;\n  inset: 0;\n  pointer-events: none;\n}\n.hb-lb-burst i {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  width: var(--hb-ps);\n  height: var(--hb-ps);\n  margin: calc(var(--hb-ps) / -2) 0 0 calc(var(--hb-ps) / -2);\n  border-radius: 50%;\n  background: var(--hb-pc);\n  opacity: 0;\n  animation: hb-lb-fly 0.62s cubic-bezier(0.1, 0.7, 0.3, 1) var(--hb-dl) forwards;\n}\n.hb-lb-burst b {\n  position: absolute;\n  inset: 0;\n  border-radius: 50%;\n  border: 2px solid var(--hb-c);\n  opacity: 0;\n  animation: hb-lb-ring 0.5s ease-out forwards;\n}\n@keyframes hb-lb-fly {\n  0% { opacity: 1; transform: translate(0, 0) scale(0.6); }\n  70% { opacity: 1; }\n  100% { opacity: 0; transform: translate(var(--hb-x), var(--hb-y)) scale(0.2); }\n}\n@keyframes hb-lb-ring {\n  0% { opacity: 0.7; transform: scale(0.4); }\n  100% { opacity: 0; transform: scale(1.9); }\n}\n.hb-lb-count {\n  display: inline-flex;\n  font-variant-numeric: tabular-nums;\n  white-space: pre;\n}\n.hb-lb-roll {\n  display: inline-grid;\n  overflow: hidden;\n  line-height: 1.25;\n  margin: -0.125em 0;\n}\n.hb-lb-roll > span { grid-area: 1 / 1; display: block; }\n.hb-lb-in { animation: hb-lb-up-in 0.38s cubic-bezier(0.3, 1.3, 0.5, 1) both; }\n.hb-lb-out { animation: hb-lb-up-out 0.3s ease-in both; }\n.hb-lb-roll[data-up=\"false\"] .hb-lb-in { animation-name: hb-lb-down-in; }\n.hb-lb-roll[data-up=\"false\"] .hb-lb-out { animation-name: hb-lb-down-out; }\n@keyframes hb-lb-up-in {\n  from { transform: translateY(100%); opacity: 0; }\n  to { transform: translateY(0); opacity: 1; }\n}\n@keyframes hb-lb-up-out {\n  from { transform: translateY(0); opacity: 1; }\n  to { transform: translateY(-100%); opacity: 0; }\n}\n@keyframes hb-lb-down-in {\n  from { transform: translateY(-100%); opacity: 0; }\n  to { transform: translateY(0); opacity: 1; }\n}\n@keyframes hb-lb-down-out {\n  from { transform: translateY(0); opacity: 1; }\n  to { transform: translateY(100%); opacity: 0; }\n}\n.hb-lb-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-lb-btn { transition: none; }\n  .hb-lb-heart[data-pop] { animation: none; }\n  .hb-lb-burst { display: none; }\n  .hb-lb-out { display: none; }\n  .hb-lb-in { animation: none; }\n}\n`;\n\nfunction hash(n: number) {\n  let x = Math.imul(n + 1, 2654435761) ^ 0x9e3779b9;\n  x = Math.imul(x ^ (x >>> 15), 2246822519);\n  x = Math.imul(x ^ (x >>> 13), 3266489917);\n  return ((x ^ (x >>> 16)) >>> 0) / 4294967296;\n}\n\nconst PARTICLES = Array.from({ length: 10 }, (_, i) => {\n  const angle = (i / 10) * Math.PI * 2 + (hash(i) - 0.5) * 0.5;\n  const reach = 0.95 + hash(i + 20) * 0.65;\n  return {\n    x: Math.cos(angle) * reach,\n    y: Math.sin(angle) * reach,\n    s: 0.12 + hash(i + 40) * 0.1,\n    d: Math.round(hash(i + 60) * 60),\n    soft: i % 2 === 1,\n  };\n});\n\nconst heart =\n  \"M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z\";\n\nexport function LikeBurst({\n  count = 0,\n  liked,\n  defaultLiked = false,\n  onChange,\n  color = \"#ff4d6d\",\n  size = 24,\n  label = \"Like\",\n  className = \"\",\n  style,\n  ...rest\n}: LikeBurstProps) {\n  const controlled = liked !== undefined;\n  const [inner, setInner] = React.useState(defaultLiked);\n  const current = controlled ? liked : inner;\n  const [base] = React.useState(current);\n\n  const offset = current === base ? 0 : current ? 1 : -1;\n  const total = Math.max(0, count + offset);\n  const text = total.toLocaleString(\"en-US\");\n\n  const [view, setView] = React.useState<View>({\n    total,\n    liked: current,\n    text,\n    bump: 0,\n    burst: 0,\n    roll: null,\n  });\n\n  if (view.total !== total || view.liked !== current) {\n    const bump = view.bump + 1;\n    setView({\n      total,\n      liked: current,\n      text,\n      bump,\n      burst: current && !view.liked ? view.burst + 1 : view.burst,\n      roll:\n        view.text !== text\n          ? { from: view.text, to: text, up: total > view.total, id: bump }\n          : view.roll,\n    });\n  }\n\n  function toggle() {\n    const next = !current;\n    if (!controlled) setInner(next);\n    const nextOffset = next === base ? 0 : next ? 1 : -1;\n    onChange?.(next, Math.max(0, count + nextOffset));\n  }\n\n  function endRoll() {\n    setView((v) => (v.roll ? { ...v, roll: null } : v));\n  }\n\n  const roll = view.roll;\n  let prefix = view.text;\n  let tail: React.ReactNode = null;\n  if (roll) {\n    let p = 0;\n    while (p < roll.from.length && p < roll.to.length && roll.from[p] === roll.to[p]) p++;\n    prefix = roll.to.slice(0, p);\n    tail = (\n      <span key={roll.id} className=\"hb-lb-roll\" data-up={roll.up ? \"true\" : \"false\"}>\n        <span className=\"hb-lb-out\">{roll.from.slice(p)}</span>\n        <span className=\"hb-lb-in\" onAnimationEnd={endRoll}>\n          {roll.to.slice(p)}\n        </span>\n      </span>\n    );\n  }\n\n  const vars = {\n    \"--hb-s\": `${size}px`,\n    \"--hb-c\": color,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <span className={`hb-lb ${className}`} style={vars} {...rest}>\n      <style href=\"hb-like-burst\" precedence=\"default\">{css}</style>\n      <button type=\"button\" className=\"hb-lb-btn\" aria-pressed={current} aria-label={label} onClick={toggle}>\n        <span className=\"hb-lb-ico\" aria-hidden=\"true\">\n          <span\n            key={`h${view.bump}`}\n            className=\"hb-lb-heart\"\n            data-pop={view.bump > 0 ? (current ? \"like\" : \"unlike\") : undefined}\n          >\n            <svg viewBox=\"0 0 24 24\">\n              <path d={heart} />\n            </svg>\n          </span>\n          {view.burst > 0 && (\n            <span key={`b${view.burst}`} className=\"hb-lb-burst\">\n              <b />\n              {PARTICLES.map((p, i) => (\n                <i\n                  key={i}\n                  style={\n                    {\n                      \"--hb-x\": `${(p.x * size).toFixed(2)}px`,\n                      \"--hb-y\": `${(p.y * size).toFixed(2)}px`,\n                      \"--hb-ps\": `${(p.s * size).toFixed(2)}px`,\n                      \"--hb-dl\": `${p.d}ms`,\n                      \"--hb-pc\": p.soft ? \"color-mix(in srgb, var(--hb-c) 55%, #ffffff)\" : \"var(--hb-c)\",\n                    } as React.CSSProperties\n                  }\n                />\n              ))}\n            </span>\n          )}\n        </span>\n        <span className=\"hb-lb-count\" aria-hidden=\"true\">\n          {prefix}\n          {tail}\n        </span>\n      </button>\n      <span className=\"hb-lb-sr\" role=\"status\" aria-live=\"polite\">\n        {`${text} ${total === 1 ? \"like\" : \"likes\"}`}\n      </span>\n    </span>\n  );\n}\n"
    }
  ]
}