{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stepper-number",
  "type": "registry:component",
  "title": "Number Stepper",
  "description": "A quantity stepper with plus and minus buttons, digits that roll like an odometer and hold to repeat with acceleration.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "stepper",
    "quantity",
    "number",
    "counter",
    "input",
    "cart"
  ],
  "docs": "https://hyperblur.dev/effects/stepper-number",
  "files": [
    {
      "path": "registry/hyperblur/stepper-number.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/stepper-number.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface StepperNumberProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"defaultValue\" | \"onChange\"> {\n  value?: number;\n  defaultValue?: number;\n  onValueChange?: (value: number) => void;\n  min?: number;\n  max?: number;\n  step?: number;\n  label?: string;\n  size?: number;\n  holdDelay?: number;\n  repeatInterval?: number;\n  accent?: string;\n  disabled?: boolean;\n  name?: string;\n}\n\nconst css = `\n.hb-qn9 {\n  display: inline-flex;\n  align-items: center;\n  gap: 2px;\n  box-sizing: border-box;\n  height: var(--hb-qn9-h);\n  padding: 4px;\n  border: 1px solid #2a2a2a;\n  border-radius: 999px;\n  background: #111;\n  font: inherit;\n  color: #ededed;\n  transition: border-color 0.2s ease, box-shadow 0.2s ease;\n}\n.hb-qn9 *, .hb-qn9 *::before, .hb-qn9 *::after { box-sizing: border-box; }\n.hb-qn9:hover { border-color: #3a3a3a; }\n.hb-qn9:focus-within { border-color: color-mix(in srgb, var(--hb-qn9-a) 60%, #2a2a2a); }\n.hb-qn9[data-disabled=\"true\"] { opacity: 0.5; pointer-events: none; }\n.hb-qn9-btn {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: calc(var(--hb-qn9-h) - 10px);\n  height: calc(var(--hb-qn9-h) - 10px);\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 50%;\n  background: #1c1c1c;\n  color: #ededed;\n  cursor: pointer;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-touch-callout: none;\n  -webkit-tap-highlight-color: transparent;\n  touch-action: manipulation;\n  transition: background 0.2s ease, color 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;\n}\n.hb-qn9-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--hb-qn9-a) 28%, #1c1c1c); }\n.hb-qn9-btn:active:not(:disabled) { transform: scale(0.88); background: var(--hb-qn9-a); }\n.hb-qn9-btn:focus-visible { outline: 2px solid var(--hb-qn9-a); outline-offset: 2px; }\n.hb-qn9-btn:disabled { opacity: 0.35; cursor: not-allowed; }\n.hb-qn9-btn svg { width: 40%; height: 40%; display: block; }\n.hb-qn9-btn path { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }\n.hb-qn9-val {\n  position: relative;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  min-width: 3.2ch;\n  height: 100%;\n  padding: 0 8px;\n  border-radius: 10px;\n  font-size: calc(var(--hb-qn9-h) * 0.4);\n  font-weight: 600;\n  font-variant-numeric: tabular-nums;\n  line-height: 1.2;\n  outline: 0;\n  cursor: default;\n}\n.hb-qn9-val:focus-visible { box-shadow: 0 0 0 2px var(--hb-qn9-a); }\n.hb-qn9-roll { display: inline-flex; height: 1.2em; overflow: hidden; mask-image: linear-gradient(180deg, transparent 0, #000 14%, #000 86%, transparent 100%); -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 14%, #000 86%, transparent 100%); }\n.hb-qn9-digit { display: block; width: 0.62em; height: 1.2em; overflow: hidden; text-align: center; }\n.hb-qn9-sign { display: block; width: 0.5em; height: 1.2em; text-align: center; }\n.hb-qn9-strip {\n  display: block;\n  transition: transform 0.45s cubic-bezier(0.3, 1.25, 0.4, 1), filter 0.2s ease;\n}\n.hb-qn9-strip span { display: block; height: 1.2em; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qn9, .hb-qn9-btn, .hb-qn9-strip { transition: none; }\n}\n`;\n\nfunction clamp(n: number, lo: number, hi: number) {\n  return Math.min(hi, Math.max(lo, n));\n}\n\nconst digits = [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"];\n\nfunction Roll({ text }: { text: string }) {\n  const chars = text.split(\"\");\n  return (\n    <span className=\"hb-qn9-roll\" aria-hidden=\"true\">\n      {chars.map((ch, i) => {\n        const fromRight = chars.length - 1 - i;\n        if (ch < \"0\" || ch > \"9\") {\n          return (\n            <span key={`s${fromRight}`} className=\"hb-qn9-sign\">\n              {ch}\n            </span>\n          );\n        }\n        return (\n          <span key={`d${fromRight}`} className=\"hb-qn9-digit\">\n            <span className=\"hb-qn9-strip\" style={{ transform: `translateY(-${Number(ch) * 10}%)` }}>\n              {digits.map((d) => (\n                <span key={d}>{d}</span>\n              ))}\n            </span>\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nexport function StepperNumber({\n  value,\n  defaultValue = 1,\n  onValueChange,\n  min = 0,\n  max = 99,\n  step = 1,\n  label = \"Quantity\",\n  size = 44,\n  holdDelay = 420,\n  repeatInterval = 90,\n  accent = \"#2f7bff\",\n  disabled = false,\n  name,\n  className = \"\",\n  style,\n  ...rest\n}: StepperNumberProps) {\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState(clamp(defaultValue, min, max));\n  const current = controlled ? value : inner;\n  const valueRef = React.useRef(current);\n  const timer = React.useRef(0);\n\n  React.useEffect(() => {\n    valueRef.current = current;\n  });\n\n  React.useEffect(() => {\n    return () => window.clearTimeout(timer.current);\n  }, []);\n\n  function stepBy(dir: 1 | -1, amount = step) {\n    const now = valueRef.current;\n    const next = clamp(now + dir * amount, min, max);\n    if (next === now) return false;\n    valueRef.current = next;\n    if (!controlled) setInner(next);\n    onValueChange?.(next);\n    return true;\n  }\n\n  function jump(target: number) {\n    const now = valueRef.current;\n    const next = clamp(target, min, max);\n    if (next === now) return;\n    valueRef.current = next;\n    if (!controlled) setInner(next);\n    onValueChange?.(next);\n  }\n\n  function stop() {\n    window.clearTimeout(timer.current);\n  }\n\n  function begin(dir: 1 | -1, e: React.PointerEvent<HTMLButtonElement>) {\n    if (e.button !== 0) return;\n    stop();\n    if (!stepBy(dir)) return;\n    let count = 0;\n    const tick = () => {\n      if (!stepBy(dir)) return;\n      count += 1;\n      timer.current = window.setTimeout(tick, Math.max(40, repeatInterval - count * 3));\n    };\n    timer.current = window.setTimeout(tick, holdDelay);\n  }\n\n  function onKey(e: React.KeyboardEvent<HTMLDivElement>) {\n    if (e.key === \"ArrowUp\" || e.key === \"ArrowRight\") stepBy(1);\n    else if (e.key === \"ArrowDown\" || e.key === \"ArrowLeft\") stepBy(-1);\n    else if (e.key === \"PageUp\") stepBy(1, step * 10);\n    else if (e.key === \"PageDown\") stepBy(-1, step * 10);\n    else if (e.key === \"Home\") jump(min);\n    else if (e.key === \"End\") jump(max);\n    else return;\n    e.preventDefault();\n  }\n\n  const vars = {\n    \"--hb-qn9-h\": `${size}px`,\n    \"--hb-qn9-a\": accent,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-stepper-number\" precedence=\"default\">{css}</style>\n      <div\n        role=\"group\"\n        aria-label={label}\n        className={`hb-qn9 ${className}`}\n        style={vars}\n        data-disabled={disabled}\n        {...rest}\n      >\n        <button\n          type=\"button\"\n          className=\"hb-qn9-btn\"\n          aria-label={`Decrease ${label.toLowerCase()}`}\n          disabled={disabled || current <= min}\n          onPointerDown={(e) => begin(-1, e)}\n          onPointerUp={stop}\n          onPointerLeave={stop}\n          onPointerCancel={stop}\n          onContextMenu={(e) => e.preventDefault()}\n          onClick={(e) => {\n            if (e.detail === 0) stepBy(-1);\n          }}\n        >\n          <svg viewBox=\"0 0 16 16\" focusable=\"false\" aria-hidden=\"true\">\n            <path d=\"M3 8h10\" />\n          </svg>\n        </button>\n        <div\n          className=\"hb-qn9-val\"\n          role=\"spinbutton\"\n          tabIndex={disabled ? -1 : 0}\n          aria-label={label}\n          aria-valuemin={min}\n          aria-valuemax={max}\n          aria-valuenow={current}\n          onKeyDown={onKey}\n        >\n          <Roll text={String(current)} />\n        </div>\n        <button\n          type=\"button\"\n          className=\"hb-qn9-btn\"\n          aria-label={`Increase ${label.toLowerCase()}`}\n          disabled={disabled || current >= max}\n          onPointerDown={(e) => begin(1, e)}\n          onPointerUp={stop}\n          onPointerLeave={stop}\n          onPointerCancel={stop}\n          onContextMenu={(e) => e.preventDefault()}\n          onClick={(e) => {\n            if (e.detail === 0) stepBy(1);\n          }}\n        >\n          <svg viewBox=\"0 0 16 16\" focusable=\"false\" aria-hidden=\"true\">\n            <path d=\"M3 8h10M8 3v10\" />\n          </svg>\n        </button>\n        {name ? <input type=\"hidden\" name={name} value={current} /> : null}\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}