{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "odometer-counter",
  "title": "Odometer Counter",
  "description": "A number that rolls like a car odometer: each digit turns on its own column with a small delay, and separators and currency come from the locale.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/odometer-counter/odometer-counter.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface OdometerCounterProps extends Omit<\n  React.ComponentPropsWithoutRef<\"span\">,\n  \"children\" | \"prefix\"\n> {\n  value?: number;\n  prefix?: string;\n  suffix?: string;\n  /** Digits after the decimal point. */\n  decimals?: number;\n  /** Milliseconds a column takes to roll. */\n  duration?: number;\n  /** Used for separators, e.g. \"en-US\" or \"de-DE\". */\n  locale?: string;\n}\n\nconst DIGITS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\n\nfunction Column({\n  digit,\n  delay,\n  duration,\n}: {\n  digit: number;\n  delay: number;\n  duration: number;\n}) {\n  return (\n    <span\n      className=\"inline-block h-[1.1em] overflow-hidden align-bottom\"\n      style={{\n        WebkitMaskImage:\n          \"linear-gradient(180deg, transparent, #000 14%, #000 86%, transparent)\",\n        maskImage:\n          \"linear-gradient(180deg, transparent, #000 14%, #000 86%, transparent)\",\n      }}\n    >\n      <span\n        className=\"block motion-safe:transition-transform\"\n        style={{\n          transform: `translateY(${-digit * 1.1}em)`,\n          transitionDuration: `${duration}ms`,\n          transitionDelay: `${delay}ms`,\n          transitionTimingFunction: \"cubic-bezier(0.22, 1, 0.36, 1)\",\n        }}\n      >\n        {DIGITS.map((d) => (\n          <span key={d} className=\"block h-[1.1em] leading-[1.1em]\">\n            {d}\n          </span>\n        ))}\n      </span>\n    </span>\n  );\n}\n\nexport function OdometerCounter({\n  value = 48210,\n  prefix = \"\",\n  suffix = \"\",\n  decimals = 0,\n  duration = 1000,\n  locale = \"en-US\",\n  className,\n  style,\n  ...props\n}: OdometerCounterProps) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const [seen, setSeen] = React.useState(false);\n\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        if (!entry.isIntersecting) return;\n        io.disconnect();\n        setSeen(true);\n      },\n      { threshold: 0.2 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  const options = {\n    minimumFractionDigits: decimals,\n    maximumFractionDigits: decimals,\n  };\n  const formatted = new Intl.NumberFormat(locale, options).format(value);\n  const chars = Array.from(formatted);\n\n  return (\n    <span\n      ref={ref}\n      aria-label={`${prefix}${formatted}${suffix}`}\n      role=\"text\"\n      className={`inline-flex tabular-nums ${className ?? \"\"}`}\n      style={{ lineHeight: 1.1, ...style }}\n      {...props}\n    >\n      {prefix && <span aria-hidden=\"true\">{prefix}</span>}\n      {chars.map((c, i) => {\n        // Keyed from the right, so the ones column stays the ones column as the number grows.\n        const place = chars.length - i;\n        return /\\d/.test(c) ? (\n          <span key={place} aria-hidden=\"true\">\n            <Column\n              digit={seen ? Number(c) : 0}\n              delay={Math.min(place, 8) * 40}\n              duration={duration}\n            />\n          </span>\n        ) : (\n          <span key={place} aria-hidden=\"true\">\n            {c}\n          </span>\n        );\n      })}\n      {suffix && <span aria-hidden=\"true\">{suffix}</span>}\n    </span>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}