{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scrubbable-number-input",
  "type": "registry:ui",
  "title": "Scrubbable Number Input",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Figma and Blender-inspired tactile numeric input with horizontal pointer drag scrubbing, elastic housing displacement, and kinetic digit roll.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/scrubbable-number-input.tsx",
      "content": "\"use client\";\n\nimport React, { useRef, useState } from \"react\";\nimport {\n  AnimatePresence,\n  motion,\n  useMotionValue,\n  useSpring,\n  useReducedMotion,\n} from \"framer-motion\";\nimport { MoveHorizontal, Minus, Plus } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ScrubbableNumberInputProps {\n  /** Label shown on the left side of the scrubbable pill. Default: \"Stiffness\" */\n  label?: string;\n  /** Controlled numeric value */\n  value?: number;\n  /** Uncontrolled initial numeric value. Default: 240 */\n  defaultValue?: number;\n  /** Minimum value. Default: 0 */\n  min?: number;\n  /** Maximum value. Default: 1000 */\n  max?: number;\n  /** Base increment step per scrub unit. Default: 5 */\n  step?: number;\n  /** Pixels of horizontal drag required per step increment. Default: 4 */\n  pixelsPerStep?: number;\n  /** Unit suffix displayed next to the value. Default: \"N/m\" */\n  unit?: string;\n  /** Callback fired when numeric value changes */\n  onChange?: (value: number) => void;\n  className?: string;\n}\n\nexport function ScrubbableNumberInput({\n  label = \"Stiffness\",\n  value: controlledValue,\n  defaultValue = 240,\n  min = 0,\n  max = 1000,\n  step = 5,\n  pixelsPerStep = 4,\n  unit = \"N/m\",\n  onChange,\n  className,\n}: ScrubbableNumberInputProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const [internalValue, setInternalValue] = useState<number>(() =>\n    Math.min(max, Math.max(min, defaultValue))\n  );\n  const [isScrubbing, setIsScrubbing] = useState(false);\n  const [direction, setDirection] = useState<1 | -1>(1);\n\n  const startXRef = useRef<number>(0);\n  const startValRef = useRef<number>(defaultValue);\n\n  const currentValue =\n    controlledValue !== undefined ? controlledValue : internalValue;\n\n  // Elastic housing horizontal tug\n  const tugX = useMotionValue(0);\n  const springTugX = useSpring(tugX, {\n    stiffness: 380,\n    damping: 24,\n    mass: 0.4,\n  });\n\n  const commitValue = (nextRaw: number) => {\n    const stepped = Math.round((nextRaw - min) / step) * step + min;\n    const clamped = Math.min(max, Math.max(min, stepped));\n    if (clamped !== currentValue) {\n      setDirection(clamped > currentValue ? 1 : -1);\n      if (controlledValue === undefined) {\n        setInternalValue(clamped);\n      }\n      onChange?.(clamped);\n    }\n  };\n\n  const handlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n    if ((e.target as HTMLElement).closest(\"button\")) return;\n    e.currentTarget.setPointerCapture(e.pointerId);\n    setIsScrubbing(true);\n    startXRef.current = e.clientX;\n    startValRef.current = currentValue;\n  };\n\n  const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (!isScrubbing) return;\n    const deltaX = e.clientX - startXRef.current;\n    const modifier = e.shiftKey ? 5 : e.altKey ? 0.2 : 1;\n    const stepsMoved = Math.round(deltaX / pixelsPerStep);\n    const nextVal = startValRef.current + stepsMoved * step * modifier;\n\n    // Subtle spring tug feedback capped at +-10px\n    const clampedTug = Math.max(-10, Math.min(10, deltaX * 0.12));\n    tugX.set(shouldReduceMotion ? 0 : clampedTug);\n\n    commitValue(nextVal);\n  };\n\n  const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (e.currentTarget.hasPointerCapture(e.pointerId)) {\n      e.currentTarget.releasePointerCapture(e.pointerId);\n    }\n    setIsScrubbing(false);\n    tugX.set(0);\n  };\n\n  const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    const multiplier = e.shiftKey ? 10 : 1;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      commitValue(currentValue + step * multiplier);\n    } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowDown\") {\n      e.preventDefault();\n      commitValue(currentValue - step * multiplier);\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      commitValue(min);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      commitValue(max);\n    }\n  };\n\n  return (\n    <motion.div\n      role=\"spinbutton\"\n      tabIndex={0}\n      aria-label={label}\n      aria-valuemin={min}\n      aria-valuemax={max}\n      aria-valuenow={currentValue}\n      aria-valuetext={`${currentValue} ${unit}`}\n      onPointerDown={handlePointerDown}\n      onPointerMove={handlePointerMove}\n      onPointerUp={handlePointerUp}\n      onPointerCancel={handlePointerUp}\n      onKeyDown={handleKeyDown}\n      style={{ x: shouldReduceMotion ? 0 : springTugX }}\n      className={cn(\n        \"group inline-flex w-full max-w-xs cursor-ew-resize select-none touch-none items-center justify-between gap-3 rounded-2xl border bg-white px-4 py-3 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black dark:bg-[#0A0A0A] dark:focus-visible:ring-white\",\n        isScrubbing\n          ? \"border-black shadow-sm dark:border-white\"\n          : \"border-neutral-200 hover:border-neutral-400 dark:border-[#222222] dark:hover:border-[#383838]\",\n        className\n      )}\n    >\n      {/* Left Scrub Label */}\n      <div className=\"flex items-center gap-2\">\n        <MoveHorizontal\n          aria-hidden=\"true\"\n          className={cn(\n            \"h-3.5 w-3.5 transition-colors\",\n            isScrubbing\n              ? \"text-black dark:text-white\"\n              : \"text-neutral-400 group-hover:text-neutral-600 dark:group-hover:text-neutral-300\"\n          )}\n        />\n        <span className=\"text-xs font-semibold text-neutral-600 dark:text-neutral-300\">\n          {label}\n        </span>\n      </div>\n\n      {/* Right Value + Stepper Controls */}\n      <div className=\"flex items-center gap-2\">\n        <button\n          type=\"button\"\n          tabIndex={-1}\n          aria-label={`Decrease ${label}`}\n          onClick={() => commitValue(currentValue - step)}\n          disabled={currentValue <= min}\n          className=\"flex h-6 w-6 items-center justify-center rounded-lg border border-neutral-200 text-neutral-500 transition-colors hover:border-black hover:text-black disabled:opacity-30 dark:border-[#262626] dark:hover:border-white dark:hover:text-white\"\n        >\n          <Minus className=\"h-3 w-3\" />\n        </button>\n\n        <div className=\"relative flex min-w-[4.5rem] items-baseline justify-end overflow-hidden font-mono text-sm font-semibold tabular-nums text-black dark:text-white\">\n          <AnimatePresence mode=\"popLayout\" initial={false}>\n            <motion.span\n              key={currentValue}\n              initial={\n                shouldReduceMotion\n                  ? { opacity: 1 }\n                  : { y: direction * 12, opacity: 0 }\n              }\n              animate={{ y: 0, opacity: 1 }}\n              exit={\n                shouldReduceMotion\n                  ? { opacity: 0 }\n                  : { y: direction * -12, opacity: 0 }\n              }\n              transition={{ type: \"spring\", stiffness: 420, damping: 28 }}\n              className=\"inline-block\"\n            >\n              {currentValue}\n            </motion.span>\n          </AnimatePresence>\n          {unit && (\n            <span className=\"ml-1 text-[10px] font-normal text-neutral-400\">\n              {unit}\n            </span>\n          )}\n        </div>\n\n        <button\n          type=\"button\"\n          tabIndex={-1}\n          aria-label={`Increase ${label}`}\n          onClick={() => commitValue(currentValue + step)}\n          disabled={currentValue >= max}\n          className=\"flex h-6 w-6 items-center justify-center rounded-lg border border-neutral-200 text-neutral-500 transition-colors hover:border-black hover:text-black disabled:opacity-30 dark:border-[#262626] dark:hover:border-white dark:hover:text-white\"\n        >\n          <Plus className=\"h-3 w-3\" />\n        </button>\n      </div>\n    </motion.div>\n  );\n}\n\nexport default ScrubbableNumberInput;\n",
      "type": "registry:ui",
      "target": "components/ui/scrubbable-number-input.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
