{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "social-share-counter",
  "type": "registry:component",
  "title": "Social Share Counter",
  "description": "A share total with odometer digits, a breakdown bar by channel and a chip per channel with its own count. Sharing rolls both numbers, grows the segment and floats a +1 from the chip.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "share",
    "counter",
    "odometer",
    "social",
    "stats",
    "chips"
  ],
  "docs": "https://hyperblur.dev/effects/social-share-counter",
  "files": [
    {
      "path": "registry/hyperblur/social-share-counter.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/social-share-counter.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type SocialProviderId =\n  | \"google\"\n  | \"github\"\n  | \"apple\"\n  | \"x\"\n  | \"linkedin\"\n  | \"discord\"\n  | \"facebook\"\n  | \"microsoft\"\n  | \"slack\"\n  | \"spotify\"\n  | \"twitch\"\n  | \"figma\"\n  | \"email\"\n  | \"link\";\n\nexport interface SocialProviderConfig {\n  id: string;\n  label?: string;\n  icon?: React.ReactNode;\n  color?: string;\n  bg?: string;\n  fg?: string;\n}\n\nexport type SocialProvider = SocialProviderId | SocialProviderConfig;\n\nconst BRANDS: Record<SocialProviderId, { label: string; color: string; bg: string; fg: string }> = {\n  google: { label: \"Google\", color: \"#4285f4\", bg: \"#ffffff\", fg: \"#1f1f1f\" },\n  github: { label: \"GitHub\", color: \"#c9d1d9\", bg: \"#24292f\", fg: \"#ffffff\" },\n  apple: { label: \"Apple\", color: \"#f5f5f7\", bg: \"#000000\", fg: \"#ffffff\" },\n  x: { label: \"X\", color: \"#e7e9ea\", bg: \"#0f1419\", fg: \"#ffffff\" },\n  linkedin: { label: \"LinkedIn\", color: \"#3b8fe0\", bg: \"#0a66c2\", fg: \"#ffffff\" },\n  discord: { label: \"Discord\", color: \"#7983f5\", bg: \"#5865f2\", fg: \"#ffffff\" },\n  facebook: { label: \"Facebook\", color: \"#4a95f5\", bg: \"#1877f2\", fg: \"#ffffff\" },\n  microsoft: { label: \"Microsoft\", color: \"#36b3f0\", bg: \"#2f2f2f\", fg: \"#ffffff\" },\n  slack: { label: \"Slack\", color: \"#e8587f\", bg: \"#4a154b\", fg: \"#ffffff\" },\n  spotify: { label: \"Spotify\", color: \"#1ed760\", bg: \"#1db954\", fg: \"#04140a\" },\n  twitch: { label: \"Twitch\", color: \"#a970ff\", bg: \"#9146ff\", fg: \"#ffffff\" },\n  figma: { label: \"Figma\", color: \"#b17cff\", bg: \"#1e1e1e\", fg: \"#ffffff\" },\n  email: { label: \"Email\", color: \"#f5b450\", bg: \"#2a2014\", fg: \"#ffe8c2\" },\n  link: { label: \"Copy link\", color: \"#a1a1a1\", bg: \"#262626\", fg: \"#ededed\" },\n};\n\nfunction Glyph({ id }: { id: string }) {\n  let body: React.ReactNode;\n  switch (id) {\n    case \"google\":\n      body = <path d=\"M18.4 7.2A8 8 0 1 0 20 12h-7.4\" />;\n      break;\n    case \"github\":\n      body = (\n        <>\n          <circle cx=\"7\" cy=\"5.5\" r=\"2.1\" />\n          <circle cx=\"7\" cy=\"18.5\" r=\"2.1\" />\n          <circle cx=\"17\" cy=\"7\" r=\"2.1\" />\n          <path d=\"M7 7.6v8.8M17 9.1v1.2a3 3 0 0 1-3 3h-4a3 3 0 0 0-3 3\" />\n        </>\n      );\n      break;\n    case \"apple\":\n      body = (\n        <>\n          <path d=\"M12 8.2c-1.7-1.3-4.7-1.2-6 1.1-1.5 2.6-.5 6.9 1.6 9.4 1.1 1.3 2.2 1.6 3.2 1.1.8-.4 1.6-.4 2.4 0 1 .5 2.1.2 3.2-1.1 2.1-2.5 3.1-6.8 1.6-9.4-1.3-2.3-4.3-2.4-6-1.1z\" />\n          <path d=\"M12 8.2c0-1.7.5-2.9 1.6-3.9\" />\n        </>\n      );\n      break;\n    case \"x\":\n      body = <path d=\"M5.5 5.5l13 13M18.5 5.5l-13 13\" />;\n      break;\n    case \"linkedin\":\n      body = (\n        <>\n          <circle cx=\"6.5\" cy=\"6\" r=\"1.3\" fill=\"currentColor\" stroke=\"none\" />\n          <path d=\"M6.5 10v8.5M11 18.5V10m0 3.4c0-2 1.5-3.4 3.3-3.4s3.2 1.4 3.2 3.4v5.1\" />\n        </>\n      );\n      break;\n    case \"discord\":\n      body = (\n        <>\n          <path d=\"M7.6 7.5h8.8a4 4 0 0 1 3.9 3.1l.9 4.1a2.3 2.3 0 0 1-3.9 2.1l-1.9-1.9H8.6l-1.9 1.9a2.3 2.3 0 0 1-3.9-2.1l.9-4.1a4 4 0 0 1 3.9-3.1z\" />\n          <path d=\"M8.2 10.4v2.8M6.8 11.8h2.8\" />\n          <circle cx=\"15.6\" cy=\"11\" r=\".8\" fill=\"currentColor\" stroke=\"none\" />\n          <circle cx=\"17.2\" cy=\"12.6\" r=\".8\" fill=\"currentColor\" stroke=\"none\" />\n        </>\n      );\n      break;\n    case \"facebook\":\n      body = <path d=\"M15.5 4.5h-1.8a2.7 2.7 0 0 0-2.7 2.7v12.3M8.5 11h6.5\" />;\n      break;\n    case \"microsoft\":\n      body = (\n        <>\n          <rect x=\"4.5\" y=\"4.5\" width=\"6.4\" height=\"6.4\" rx=\"1.4\" />\n          <rect x=\"13.1\" y=\"4.5\" width=\"6.4\" height=\"6.4\" rx=\"1.4\" />\n          <rect x=\"4.5\" y=\"13.1\" width=\"6.4\" height=\"6.4\" rx=\"1.4\" />\n          <rect x=\"13.1\" y=\"13.1\" width=\"6.4\" height=\"6.4\" rx=\"1.4\" />\n        </>\n      );\n      break;\n    case \"slack\":\n      body = <path d=\"M10 4.5 8.4 19.5M15.6 4.5 14 19.5M5 9.2h14.5M4.5 14.8H19\" />;\n      break;\n    case \"spotify\":\n      body = <path d=\"M4.5 10.5v3M8.25 7.5v9M12 4.5v15M15.75 8v8M19.5 10.5v3\" />;\n      break;\n    case \"twitch\":\n      body = (\n        <>\n          <path d=\"M6.5 4.5h11a2 2 0 0 1 2 2V14a2 2 0 0 1-2 2H12l-4 3.5V16H6.5a2 2 0 0 1-2-2V6.5a2 2 0 0 1 2-2z\" />\n          <path d=\"M10.2 8.5v3.2M14.4 8.5v3.2\" />\n        </>\n      );\n      break;\n    case \"figma\":\n      body = (\n        <>\n          <path d=\"M12 3.5 18 11l-6 9.5L6 11z\" />\n          <path d=\"M12 3.5v8\" />\n          <circle cx=\"12\" cy=\"13\" r=\"1.5\" />\n        </>\n      );\n      break;\n    case \"email\":\n      body = (\n        <>\n          <rect x=\"3.5\" y=\"5.5\" width=\"17\" height=\"13\" rx=\"2.5\" />\n          <path d=\"m4.5 7.5 7.5 5.5 7.5-5.5\" />\n        </>\n      );\n      break;\n    case \"link\":\n      body = (\n        <>\n          <path d=\"M10.2 13.8a3.6 3.6 0 0 0 5.1 0l3-3a3.6 3.6 0 0 0-5.1-5.1l-1.1 1.1\" />\n          <path d=\"M13.8 10.2a3.6 3.6 0 0 0-5.1 0l-3 3a3.6 3.6 0 0 0 5.1 5.1l1.1-1.1\" />\n        </>\n      );\n      break;\n    default:\n      body = <circle cx=\"12\" cy=\"12\" r=\"7\" />;\n  }\n  return (\n    <svg\n      viewBox=\"0 0 24 24\"\n      width=\"1em\"\n      height=\"1em\"\n      fill=\"none\"\n      stroke=\"currentColor\"\n      strokeWidth={1.9}\n      strokeLinecap=\"round\"\n      strokeLinejoin=\"round\"\n      aria-hidden=\"true\"\n      focusable=\"false\"\n    >\n      {body}\n    </svg>\n  );\n}\n\ninterface ResolvedProvider {\n  id: string;\n  label: string;\n  color: string;\n  bg: string;\n  fg: string;\n  icon: React.ReactNode;\n}\n\nfunction resolveProvider(p: SocialProvider): ResolvedProvider {\n  const cfg: SocialProviderConfig = typeof p === \"string\" ? { id: p } : p;\n  const brand = BRANDS[cfg.id as SocialProviderId] as (typeof BRANDS)[SocialProviderId] | undefined;\n  return {\n    id: cfg.id,\n    label: cfg.label ?? brand?.label ?? cfg.id,\n    color: cfg.color ?? brand?.color ?? \"#2f7bff\",\n    bg: cfg.bg ?? brand?.bg ?? cfg.color ?? \"#2f7bff\",\n    fg: cfg.fg ?? brand?.fg ?? \"#ffffff\",\n    icon: cfg.icon ?? <Glyph id={cfg.id} />,\n  };\n}\n\nexport interface SocialShareCounterProps extends React.HTMLAttributes<HTMLDivElement> {\n  providers?: SocialProvider[];\n  counts?: Record<string, number>;\n  label?: string;\n  url?: string;\n  locale?: string;\n  onShare?: (provider: string, total: number) => void;\n}\n\nconst css = `\n.hb-xc8 { display: flex; flex-direction: column; gap: 12px; width: 100%; box-sizing: border-box; font-family: inherit; color: #ededed; }\n.hb-xc8 *, .hb-xc8 *::before, .hb-xc8 *::after { box-sizing: border-box; }\n.hb-xc8-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }\n.hb-xc8-total { display: flex; align-items: baseline; gap: 7px; min-width: 0; }\n.hb-xc8-num { position: relative; font-size: 26px; font-weight: 650; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }\n.hb-xc8-lbl { font-size: 12px; color: #8f8f8f; }\n.hb-xc8-delta { font-size: 11px; font-weight: 600; color: #3ddc84; font-variant-numeric: tabular-nums; animation: hb-xc8-up 0.9s cubic-bezier(0.22, 1, 0.36, 1) both; }\n.hb-xc8-roll { display: inline-flex; overflow: hidden; height: 1em; line-height: 1; }\n.hb-xc8-col { display: inline-flex; flex-direction: column; transition: transform 0.7s cubic-bezier(0.2, 0.9, 0.2, 1); transition-delay: var(--hb-xc8-dl, 0ms); }\n.hb-xc8-col span, .hb-xc8-sep { display: block; height: 1em; line-height: 1; text-align: center; }\n.hb-xc8-bar { display: flex; gap: 2px; height: 6px; border-radius: 999px; overflow: hidden; background: #1a1a1a; }\n.hb-xc8-seg { height: 100%; min-width: 3px; background: var(--hb-xc8-c); border-radius: 2px; transition: flex-grow 0.7s cubic-bezier(0.2, 0.9, 0.2, 1), filter 0.3s ease; }\n.hb-xc8-seg[data-hot=\"true\"] { filter: brightness(1.35); }\n.hb-xc8-chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: 6px; }\n.hb-xc8-chip {\n  --hb-xc8-c: #7fb3ff;\n  position: relative;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 7px;\n  height: 36px;\n  margin: 0;\n  padding: 0 10px;\n  border: 0;\n  border-radius: 10px;\n  font: inherit;\n  font-size: 12.5px;\n  font-weight: 600;\n  color: #cfcfcf;\n  background: #141414;\n  box-shadow: inset 0 0 0 1px #262626, inset 0 1px 0 rgba(255, 255, 255, 0.04);\n  cursor: pointer;\n  -webkit-tap-highlight-color: transparent;\n  transition: background 0.3s ease, box-shadow 0.3s ease, color 0.3s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-xc8-chip:hover, .hb-xc8-chip:focus-visible { color: #ffffff; background: color-mix(in srgb, var(--hb-xc8-c) 9%, #141414); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-xc8-c) 40%, #262626); }\n.hb-xc8-chip:active { transform: scale(0.94); }\n.hb-xc8-chip:focus-visible { outline: 2px solid var(--hb-xc8-c); outline-offset: 2px; }\n.hb-xc8-chip[data-hit=\"true\"] { color: #ffffff; background: color-mix(in srgb, var(--hb-xc8-c) 18%, #141414); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-xc8-c) 65%, transparent), 0 8px 18px -10px var(--hb-xc8-c); animation: hb-xc8-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xc8-ic { display: inline-flex; font-size: 15px; color: var(--hb-xc8-c); }\n.hb-xc8-ic svg { display: block; }\n.hb-xc8-plus { position: absolute; top: -4px; left: 50%; font-size: 11px; font-weight: 700; color: var(--hb-xc8-c); pointer-events: none; animation: hb-xc8-fly 0.9s cubic-bezier(0.22, 1, 0.36, 1) forwards; }\n@keyframes hb-xc8-pop { 0% { transform: scale(0.92); } 60% { transform: scale(1.05); } 100% { transform: scale(1); } }\n@keyframes hb-xc8-fly { 0% { opacity: 0; transform: translate(-50%, 6px) scale(0.8); } 25% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -18px) scale(1.1); } }\n@keyframes hb-xc8-up { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xc8-col, .hb-xc8-seg, .hb-xc8-chip { transition: none; }\n  .hb-xc8-chip[data-hit=\"true\"], .hb-xc8-delta { animation: none; }\n  .hb-xc8-plus { display: none; }\n}\n`;\n\nfunction Roll({ value, locale }: { value: number; locale: string }) {\n  const text = new Intl.NumberFormat(locale).format(value);\n  const chars = text.split(\"\");\n  return (\n    <span className=\"hb-xc8-roll\" aria-hidden=\"true\">\n      {chars.map((ch, i) => {\n        const fromRight = chars.length - 1 - i;\n        const d = Number(ch);\n        if (Number.isNaN(d) || ch === \" \") {\n          return (\n            <span key={`s${fromRight}`} className=\"hb-xc8-sep\">\n              {ch}\n            </span>\n          );\n        }\n        return (\n          <span\n            key={`d${fromRight}`}\n            className=\"hb-xc8-col\"\n            style={{ transform: `translateY(${-d}em)`, \"--hb-xc8-dl\": `${fromRight * 40}ms` } as React.CSSProperties}\n          >\n            {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((k) => (\n              <span key={k}>{k}</span>\n            ))}\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nconst DEFAULT_COUNTS: Record<string, number> = { x: 4812, linkedin: 2307, facebook: 961, link: 1204 };\n\nexport function SocialShareCounter({\n  providers = [\"x\", \"linkedin\", \"facebook\", \"link\"],\n  counts = DEFAULT_COUNTS,\n  label = \"shares\",\n  url = \"https://northwind.app/blog/shipping-faster\",\n  locale = \"en-US\",\n  onShare,\n  className = \"\",\n  ...rest\n}: SocialShareCounterProps) {\n  const items = providers.map(resolveProvider);\n  const [tally, setTally] = React.useState<Record<string, number>>(() => {\n    const base: Record<string, number> = {};\n    for (const p of items) base[p.id] = counts[p.id] ?? 0;\n    return base;\n  });\n  const [hit, setHit] = React.useState<{ id: string; n: number } | null>(null);\n  const [added, setAdded] = React.useState(0);\n  const timer = React.useRef<number | undefined>(undefined);\n\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  const total = items.reduce((sum, p) => sum + (tally[p.id] ?? 0), 0);\n  const fmt = new Intl.NumberFormat(locale);\n\n  function share(id: string) {\n    if (id === \"link\" && typeof navigator !== \"undefined\" && navigator.clipboard) {\n      navigator.clipboard.writeText(url).catch(() => {});\n    }\n    setTally((t) => ({ ...t, [id]: (t[id] ?? 0) + 1 }));\n    setHit((h) => ({ id, n: (h?.n ?? 0) + 1 }));\n    setAdded((a) => a + 1);\n    onShare?.(id, total + 1);\n    window.clearTimeout(timer.current);\n    timer.current = window.setTimeout(() => setHit(null), 1200);\n  }\n\n  return (\n    <>\n      <style href=\"hb-social-share-counter\" precedence=\"default\">{css}</style>\n      <div className={`hb-xc8 ${className}`} {...rest}>\n        <div className=\"hb-xc8-top\">\n          <div className=\"hb-xc8-total\">\n            <span className=\"hb-xc8-num\">\n              <Roll value={total} locale={locale} />\n              <span style={{ position: \"absolute\", width: 1, height: 1, overflow: \"hidden\", clipPath: \"inset(50%)\" }}>\n                {fmt.format(total)}\n              </span>\n            </span>\n            <span className=\"hb-xc8-lbl\">{label}</span>\n          </div>\n          {added > 0 ? (\n            <span className=\"hb-xc8-delta\" key={added}>\n              +{added} today\n            </span>\n          ) : null}\n        </div>\n        <div className=\"hb-xc8-bar\" aria-hidden=\"true\">\n          {items.map((p) => (\n            <span\n              key={p.id}\n              className=\"hb-xc8-seg\"\n              data-hot={hit?.id === p.id ? \"true\" : undefined}\n              style={{ flexGrow: Math.max(1, tally[p.id] ?? 0), \"--hb-xc8-c\": p.color } as React.CSSProperties}\n            />\n          ))}\n        </div>\n        <div className=\"hb-xc8-chips\">\n          {items.map((p) => {\n            const isHit = hit?.id === p.id;\n            return (\n              <button\n                key={p.id}\n                type=\"button\"\n                className=\"hb-xc8-chip\"\n                style={{ \"--hb-xc8-c\": p.color } as React.CSSProperties}\n                data-hit={isHit ? \"true\" : undefined}\n                aria-label={`${p.id === \"link\" ? \"Copy link\" : `Share to ${p.label}`}, ${fmt.format(tally[p.id] ?? 0)} ${label}`}\n                onClick={() => share(p.id)}\n              >\n                <span className=\"hb-xc8-ic\">{p.icon}</span>\n                <Roll value={tally[p.id] ?? 0} locale={locale} />\n                {isHit ? (\n                  <span className=\"hb-xc8-plus\" key={hit.n} aria-hidden=\"true\">\n                    +1\n                  </span>\n                ) : null}\n              </button>\n            );\n          })}\n        </div>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}