{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"number-ticker","type":"registry:ui","title":"Number Ticker","description":"An odometer-style number in a squircle window: every digit is a 0-9 strip that rolls to its new value.","dependencies":["motion","figma-squircle","react-use-measure"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/number-ticker.tsx","type":"registry:ui","content":"\"use client\";\n\n// Adapted from Calamansi UI by fujiDevv (MIT License).\n// https://github.com/fujiDevv/calamansi-ui\n\nimport { useMemo, type ReactNode } from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { getSvgPath } from \"figma-squircle\";\nimport useMeasure from \"react-use-measure\";\nimport { cn } from \"@/lib/utils\";\n\nconst DIGITS_UP = [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"];\nconst DIGITS_DOWN = [...DIGITS_UP].reverse();\n\nconst NUMBER = new Intl.NumberFormat(\"en-US\", { maximumFractionDigits: 2 });\nconst FORMAT = (value: number) => NUMBER.format(value);\n\nexport type NumberTickerVariant = \"white\" | \"calamansi\" | \"slate\" | \"citrus\";\n\nconst VARIANTS: Record<NumberTickerVariant, { paint: string; ink: string }> = {\n  white: { paint: \"bg-white dark:bg-[#1c1c1f]\", ink: \"text-foreground\" },\n  calamansi: {\n    paint:\n      \"bg-gradient-to-br from-[#8fa37d] via-[#5c7a67] to-[#39564a] dark:from-[#1b281f] dark:via-[#16221a] dark:to-[#0e1611]\",\n    ink: \"text-white\",\n  },\n  slate: {\n    paint:\n      \"bg-gradient-to-br from-[#a79cb7] via-[#687396] to-[#4a5a7f] dark:from-[#1e1b4b] dark:via-[#1e293b] dark:to-[#0f172a]\",\n    ink: \"text-white\",\n  },\n  citrus: {\n    paint:\n      \"bg-gradient-to-br from-[#d69f7e] via-[#b87152] to-[#7d4128] dark:from-[#2e170c] dark:via-[#22120b] dark:to-[#140a06]\",\n    ink: \"text-white\",\n  },\n};\n\n/** A superellipse surface painted on its own layer, inset to the parent. */\nfunction Squircle({ className, radius = 28, children }: { className?: string; radius?: number; children?: ReactNode }) {\n  const [ref, bounds] = useMeasure({ offsetSize: true });\n  const path = useMemo(\n    () =>\n      bounds.width > 0 && bounds.height > 0\n        ? getSvgPath({ width: bounds.width, height: bounds.height, cornerRadius: radius, cornerSmoothing: 1 })\n        : null,\n    [bounds.width, bounds.height, radius],\n  );\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"pointer-events-none absolute inset-0 block\"\n      style={{ filter: \"drop-shadow(0 14px 28px rgba(0, 0, 0, 0.24))\" }}\n    >\n      <span\n        ref={ref}\n        style={path ? { clipPath: `path('${path}')` } : { borderRadius: radius }}\n        className={cn(\"relative block size-full overflow-hidden\", className)}\n      >\n        {children}\n      </span>\n    </span>\n  );\n}\n\nexport interface NumberTickerProps {\n  value: number;\n  className?: string;\n  /** Surface palette. */\n  variant?: NumberTickerVariant;\n  /** Seconds for each digit to settle. */\n  duration?: number;\n  /** Delay between digits, in seconds. */\n  stagger?: number;\n  /** Roll the digits upward or downward. */\n  direction?: \"up\" | \"down\";\n  /** Static text before the digits. */\n  prefix?: string;\n  /** Static text after the digits. */\n  suffix?: string;\n  /** Turns the number into text. Defaults to a grouped en-US number. */\n  format?: (value: number) => string;\n}\n\n/**\n * An odometer-style number that rolls to each new value, mounted in a squircle\n * window. Every digit is a column of 0-9 that slides to the active digit.\n */\nexport function NumberTicker({\n  value,\n  className,\n  variant = \"calamansi\",\n  duration = 0.7,\n  stagger = 0.05,\n  direction = \"up\",\n  prefix,\n  suffix,\n  format = FORMAT,\n}: NumberTickerProps) {\n  const reduceMotion = useReducedMotion();\n  const text = format(value);\n  const characters = [...text];\n  const palette = VARIANTS[variant] ?? VARIANTS.calamansi;\n\n  return (\n    <span className={cn(\"relative inline-flex p-1.5 font-bold select-none sm:p-2\", palette.ink, className)}>\n      <Squircle className={palette.paint} />\n\n      <span className=\"sr-only\">{`${prefix ?? \"\"}${text}${suffix ?? \"\"}`}</span>\n\n      <span className=\"relative z-10 inline-flex items-center px-2.5 py-1 tabular-nums sm:px-3\">\n        <span aria-hidden className=\"inline-flex items-center tabular-nums drop-shadow-md\">\n          {prefix}\n          {characters.map((character, index) => (\n            // keyed from the right so the ones column stays put as the number grows\n            <DigitColumn\n              key={characters.length - index}\n              character={character}\n              duration={reduceMotion ? 0 : duration}\n              delay={reduceMotion ? 0 : (characters.length - index - 1) * stagger}\n              direction={direction}\n            />\n          ))}\n          {suffix}\n        </span>\n      </span>\n    </span>\n  );\n}\n\nfunction DigitColumn({\n  character,\n  duration,\n  delay,\n  direction,\n}: {\n  character: string;\n  duration: number;\n  delay: number;\n  direction: \"up\" | \"down\";\n}) {\n  if (!/\\d/.test(character)) {\n    return <span className=\"inline-block leading-none\">{character}</span>;\n  }\n\n  const strip = direction === \"down\" ? DIGITS_DOWN : DIGITS_UP;\n  const digit = Number(character);\n  // the strip is ten rows tall, so 10% of its own height is exactly one row\n  const offset = (direction === \"down\" ? 9 - digit : digit) * 10;\n\n  return (\n    <span className=\"relative inline-block h-[1em] overflow-hidden leading-none\" style={{ width: \"0.62em\" }}>\n      <motion.span\n        className=\"absolute inset-x-0 top-0 flex flex-col\"\n        initial={false}\n        animate={{ y: `${-offset}%` }}\n        transition={{ duration, delay, ease: [0.16, 1, 0.3, 1] }}\n        style={{ willChange: \"transform\" }}\n      >\n        {strip.map((row) => (\n          <span key={row} className=\"flex h-[1em] shrink-0 items-center justify-center leading-none\">\n            {row}\n          </span>\n        ))}\n      </motion.span>\n    </span>\n  );\n}\n"}]}