{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "micro-half-star-rating",
  "type": "registry:component",
  "title": "Half Star Rating",
  "description": "A rating that previews half stars under the pointer and commits with a fill sweep from left to right, a springy pop and a burst of sparks from the chosen star. A rolling caption names the score.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "rating",
    "stars",
    "review",
    "particles",
    "slider",
    "micro"
  ],
  "docs": "https://hyperblur.dev/effects/micro-half-star-rating",
  "files": [
    {
      "path": "registry/hyperblur/micro-half-star-rating.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/micro-half-star-rating.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MicroHalfStarRatingProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\"> {\n  value?: number;\n  defaultValue?: number;\n  max?: number;\n  size?: number;\n  accent?: string;\n  labels?: string[];\n  showValue?: boolean;\n  readOnly?: boolean;\n  label?: string;\n  onChange?: (value: number) => void;\n}\n\nconst css = `\n.hb-wf11 {\n  --hb-wf11-c: #ffb547;\n  --hb-wf11-s: 30px;\n  display: inline-flex;\n  align-items: center;\n  gap: 14px;\n  box-sizing: border-box;\n  font-family: inherit;\n  color: #ededed;\n  user-select: none;\n  -webkit-user-select: none;\n}\n.hb-wf11 *, .hb-wf11 *::before, .hb-wf11 *::after { box-sizing: border-box; }\n.hb-wf11-row {\n  position: relative;\n  display: inline-flex;\n  gap: 4px;\n  padding: 4px;\n  border-radius: 10px;\n  outline: none;\n  cursor: pointer;\n  touch-action: none;\n}\n.hb-wf11[data-ro=\"true\"] .hb-wf11-row { cursor: default; }\n.hb-wf11-row:focus-visible { box-shadow: 0 0 0 2px var(--hb-wf11-c); }\n.hb-wf11-st {\n  position: relative;\n  width: var(--hb-wf11-s);\n  height: var(--hb-wf11-s);\n  transition: transform 0.25s cubic-bezier(0.3, 1.7, 0.45, 1);\n}\n.hb-wf11-st svg { position: absolute; left: 0; top: 0; width: var(--hb-wf11-s); height: var(--hb-wf11-s); display: block; }\n.hb-wf11-bg path { fill: #1d1d1d; stroke: #333; stroke-width: 1.2; }\n.hb-wf11-fl {\n  position: absolute;\n  left: 0;\n  top: 0;\n  bottom: 0;\n  overflow: hidden;\n  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1);\n  transition-delay: var(--hb-wf11-d);\n}\n.hb-wf11-fl path { fill: var(--hb-wf11-c); filter: drop-shadow(0 0 6px color-mix(in srgb, var(--hb-wf11-c) 50%, transparent)); }\n.hb-wf11-fl .hb-wf11-hi { fill: #fff; opacity: 0.35; filter: none; }\n.hb-wf11[data-preview=\"true\"] .hb-wf11-fl { transition-delay: 0s; transition-duration: 0.12s; }\n.hb-wf11[data-preview=\"true\"] .hb-wf11-fl path { fill: color-mix(in srgb, var(--hb-wf11-c) 70%, #fff); }\n.hb-wf11-st[data-hot=\"true\"] { transform: scale(1.14); }\n.hb-wf11-st[data-pop=\"a\"] { animation: hb-wf11-pop 0.55s cubic-bezier(0.2, 1.8, 0.4, 1); }\n.hb-wf11-st[data-pop=\"b\"] { animation: hb-wf11-pop2 0.55s cubic-bezier(0.2, 1.8, 0.4, 1); }\n@keyframes hb-wf11-pop { 0% { transform: scale(0.7) rotate(-14deg); } 55% { transform: scale(1.3) rotate(6deg); } 100% { transform: none; } }\n@keyframes hb-wf11-pop2 { 0% { transform: scale(0.7) rotate(14deg); } 55% { transform: scale(1.3) rotate(-6deg); } 100% { transform: none; } }\n.hb-wf11-pt {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  width: var(--hb-wf11-z);\n  height: var(--hb-wf11-z);\n  margin: calc(var(--hb-wf11-z) / -2) 0 0 calc(var(--hb-wf11-z) / -2);\n  background: var(--hb-wf11-pc);\n  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);\n  pointer-events: none;\n  animation: hb-wf11-burst 0.75s cubic-bezier(0.15, 0.7, 0.3, 1) both;\n}\n.hb-wf11-pt[data-round=\"true\"] { clip-path: circle(50%); }\n@keyframes hb-wf11-burst {\n  0% { transform: translate(0, 0) scale(0.2) rotate(0deg); opacity: 1; }\n  60% { opacity: 1; }\n  100% { transform: translate(var(--hb-wf11-x), var(--hb-wf11-y)) scale(1) rotate(var(--hb-wf11-r)); opacity: 0; }\n}\n.hb-wf11-ro { display: flex; flex-direction: column; gap: 3px; min-width: 64px; }\n.hb-wf11-v { font-family: var(--font-mono), ui-monospace, monospace; font-size: 18px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }\n.hb-wf11-v small { font-size: 11px; color: #6f6f6f; font-weight: 500; margin-left: 2px; }\n.hb-wf11-w { font-size: 11.5px; color: #9a9a9a; line-height: 1; height: 12px; overflow: hidden; }\n.hb-wf11-w span { display: block; animation: hb-wf11-w 0.3s cubic-bezier(0.2, 1.3, 0.4, 1); }\n@keyframes hb-wf11-w { from { transform: translateY(100%); opacity: 0; } to { transform: none; opacity: 1; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wf11-st, .hb-wf11-fl { transition: none; }\n  .hb-wf11-st[data-pop], .hb-wf11-w span { animation: none; }\n  .hb-wf11-pt { display: none; }\n}\n`;\n\nconst star = \"M12 2.6l2.8 5.9 6.4.8-4.7 4.4 1.2 6.4L12 17l-5.7 3.1 1.2-6.4-4.7-4.4 6.4-.8z\";\nconst shine = \"M9.6 8.2l1.4-3 .9 1.9z\";\nconst tones = [\"#ffb547\", \"#ffd27a\", \"#ff8a3d\", \"#fff1c9\"];\nconst defaultLabels = [\"Terrible\", \"Bad\", \"Poor\", \"Below average\", \"Okay\", \"Decent\", \"Good\", \"Very good\", \"Great\", \"Outstanding\"];\n\nexport function MicroHalfStarRating({\n  value,\n  defaultValue = 3.5,\n  max = 5,\n  size = 30,\n  accent = \"#ffb547\",\n  labels = defaultLabels,\n  showValue = true,\n  readOnly = false,\n  label = \"Rating\",\n  onChange,\n  className = \"\",\n  style,\n  ...rest\n}: MicroHalfStarRatingProps) {\n  const [inner, setInner] = React.useState(defaultValue);\n  const v = value ?? inner;\n  const [hover, setHover] = React.useState<number | null>(null);\n  const [burst, setBurst] = React.useState<{ id: number; at: number } | null>(null);\n  const rowRef = React.useRef<HTMLDivElement>(null);\n  const shown = hover ?? v;\n\n  React.useEffect(() => {\n    if (!burst) return;\n    const t = window.setTimeout(() => setBurst(null), 800);\n    return () => window.clearTimeout(t);\n  }, [burst]);\n\n  const fromX = (clientX: number) => {\n    const el = rowRef.current;\n    if (!el) return v;\n    const r = el.getBoundingClientRect();\n    const x = clientX - r.left - 4;\n    const unit = size + 4;\n    const raw = x / unit;\n    const idx = Math.floor(raw);\n    const frac = raw - idx;\n    const val = idx + (frac < (size / unit) * 0.5 ? 0.5 : 1);\n    return Math.max(0.5, Math.min(max, val));\n  };\n\n  const commit = (next: number) => {\n    if (readOnly) return;\n    const c = Math.max(0, Math.min(max, Math.round(next * 2) / 2));\n    if (value === undefined) setInner(c);\n    onChange?.(c);\n    if (c > 0) setBurst((b) => ({ id: (b?.id ?? 0) + 1, at: Math.ceil(c) - 1 }));\n  };\n\n  const word = shown > 0 ? labels[Math.min(labels.length - 1, Math.round((shown / max) * labels.length) - 1)] ?? \"\" : \"No rating\";\n\n  return (\n    <div\n      className={`hb-wf11 ${className}`}\n      data-preview={hover !== null}\n      data-ro={readOnly}\n      style={{ ...style, [\"--hb-wf11-c\" as string]: accent, [\"--hb-wf11-s\" as string]: `${size}px` }}\n      {...rest}\n    >\n      <style href=\"hb-micro-half-star-rating\" precedence=\"default\">\n        {css}\n      </style>\n      <div\n        ref={rowRef}\n        className=\"hb-wf11-row\"\n        role=\"slider\"\n        tabIndex={readOnly ? -1 : 0}\n        aria-label={label}\n        aria-valuemin={0}\n        aria-valuemax={max}\n        aria-valuenow={v}\n        aria-valuetext={`${v} out of ${max}`}\n        aria-readonly={readOnly || undefined}\n        onPointerMove={(e) => {\n          if (!readOnly && e.pointerType === \"mouse\") setHover(fromX(e.clientX));\n        }}\n        onPointerLeave={() => setHover(null)}\n        onPointerUp={(e) => {\n          if (readOnly) return;\n          commit(fromX(e.clientX));\n          if (e.pointerType !== \"mouse\") setHover(null);\n        }}\n        onKeyDown={(e) => {\n          if (readOnly) return;\n          if (e.key === \"ArrowRight\" || e.key === \"ArrowUp\") {\n            e.preventDefault();\n            commit(v + 0.5);\n          } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowDown\") {\n            e.preventDefault();\n            commit(v - 0.5);\n          } else if (e.key === \"Home\") {\n            e.preventDefault();\n            commit(0.5);\n          } else if (e.key === \"End\") {\n            e.preventDefault();\n            commit(max);\n          } else if (/^[0-9]$/.test(e.key)) {\n            commit(Number(e.key));\n          }\n        }}\n      >\n        {Array.from({ length: max }, (_, i) => {\n          const f = Math.max(0, Math.min(1, shown - i));\n          const hot = hover !== null && Math.ceil(hover) - 1 === i;\n          return (\n            <span\n              key={i}\n              className=\"hb-wf11-st\"\n              data-hot={hot}\n              data-pop={burst && burst.at === i ? (burst.id % 2 ? \"a\" : \"b\") : undefined}\n              style={{ [\"--hb-wf11-d\" as string]: `${hover !== null ? 0 : i * 55}ms` }}\n              aria-hidden=\"true\"\n            >\n              <svg className=\"hb-wf11-bg\" viewBox=\"0 0 24 24\">\n                <path d={star} strokeLinejoin=\"round\" />\n              </svg>\n              <span className=\"hb-wf11-fl\" style={{ width: `${(f * 100).toFixed(0)}%` }}>\n                <svg viewBox=\"0 0 24 24\">\n                  <path d={star} strokeLinejoin=\"round\" />\n                  <path className=\"hb-wf11-hi\" d={shine} />\n                </svg>\n              </span>\n              {burst && burst.at === i ? (\n                <React.Fragment key={burst.id}>\n                  {Array.from({ length: 12 }, (_, k) => {\n                    const h = Math.imul(k + 1 + burst.id * 17, 2654435761) >>> 0;\n                    const ang = (k / 12) * Math.PI * 2 + ((h % 100) / 100 - 0.5) * 0.5;\n                    const dist = size * (0.9 + ((h >>> 8) % 100) / 110);\n                    return (\n                      <span\n                        key={k}\n                        className=\"hb-wf11-pt\"\n                        data-round={k % 3 === 0}\n                        style={{\n                          [\"--hb-wf11-x\" as string]: `${(Math.cos(ang) * dist).toFixed(1)}px`,\n                          [\"--hb-wf11-y\" as string]: `${(Math.sin(ang) * dist).toFixed(1)}px`,\n                          [\"--hb-wf11-r\" as string]: `${(h % 360) - 180}deg`,\n                          [\"--hb-wf11-z\" as string]: `${(k % 3 === 0 ? 4 : 6 + ((h >>> 4) % 4)).toFixed(0)}px`,\n                          [\"--hb-wf11-pc\" as string]: k % 4 === 0 ? accent : tones[k % tones.length],\n                        }}\n                      />\n                    );\n                  })}\n                </React.Fragment>\n              ) : null}\n            </span>\n          );\n        })}\n      </div>\n      {showValue ? (\n        <div className=\"hb-wf11-ro\" aria-hidden=\"true\">\n          <span className=\"hb-wf11-v\">\n            {shown.toFixed(1)}\n            <small>/ {max}</small>\n          </span>\n          <span className=\"hb-wf11-w\">\n            <span key={word}>{word}</span>\n          </span>\n        </div>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ]
}