{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"hero-number-counter-with-motion-blur-on-fast-digits","type":"registry:component","title":"Hero Number Counter With Motion Blur","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/hero-number-counter-with-motion-blur-on-fast-digits.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n// Sample figure for a made-up window cleaner.\nconst VALUE = 23418;\nconst DURATION = 2200; // ms for the count\nconst MAX_BLUR = 6; // px of blur on a digit that is changing faster than the eye can read\n\nconst fmt = new Intl.NumberFormat(\"en-US\");\nconst easeOut = (t: number) => 1 - Math.pow(1 - t, 4);\nconst easeOutSpeed = (t: number) => 4 * Math.pow(1 - t, 3); // derivative of easeOut\n\nexport default function HeroNumberBlurCounter() {\n  const reduce = useReducedMotion();\n  const rootRef = useRef<HTMLElement>(null);\n  const [t, setT] = useState(1);\n\n  useEffect(() => {\n    const el = rootRef.current;\n    if (!el || reduce) {\n      setT(1);\n      return;\n    }\n    setT(0);\n    let raf = 0;\n    let start = 0;\n    let elapsed = 0;\n    let visible = false;\n    const tick = (now: number) => {\n      if (!start) start = now - elapsed;\n      elapsed = now - start;\n      const p = Math.min(1, elapsed / DURATION);\n      setT(p);\n      if (p < 1 && visible) raf = requestAnimationFrame(tick);\n    };\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        visible = entry.isIntersecting;\n        cancelAnimationFrame(raf);\n        start = 0;\n        if (visible) raf = requestAnimationFrame(tick);\n      },\n      { threshold: 0.3 },\n    );\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [reduce]);\n\n  const value = Math.round(VALUE * easeOut(t));\n  // Units per 16ms frame; a digit in place p changes speed / 10^p times per frame.\n  const speed = t >= 1 ? 0 : (VALUE * easeOutSpeed(t) * 16) / DURATION;\n  const text = fmt.format(value);\n  const chars = text.split(\"\");\n  let place = chars.filter((c) => /\\d/.test(c)).length;\n\n  return (\n    <section ref={rootRef} className=\"relative overflow-hidden bg-[#f7f9fb] px-5 py-16 text-[#0f1b2a] sm:py-24\">\n      <div\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0\"\n        style={{ background: \"radial-gradient(70% 55% at 50% 45%, rgba(188,207,226,.45), rgba(247,249,251,0) 70%)\" }}\n      />\n      <div className=\"relative mx-auto flex max-w-4xl flex-col items-center text-center\">\n        <p className=\"text-sm font-medium uppercase tracking-[0.2em] text-[#40566e]\">Tidewell Window Cleaning</p>\n        <h2 className=\"mt-6 font-semibold leading-none tracking-[-0.04em]\">\n          <span className=\"sr-only\">{fmt.format(VALUE)} windows cleaned since 2019</span>\n          <span aria-hidden=\"true\" className=\"grid justify-items-center text-[clamp(4.5rem,19vw,11rem)] tabular-nums\">\n            <span className=\"invisible col-start-1 row-start-1\">{fmt.format(VALUE)}</span>\n            <span className=\"col-start-1 row-start-1 flex\">\n              {chars.map((c, i) => {\n                if (!/\\d/.test(c)) return <span key={i} className=\"text-[#8aa0b6]\">{c}</span>;\n                place -= 1;\n                const rate = speed / Math.pow(10, place);\n                const blur = Math.min(MAX_BLUR, Math.max(0, (rate - 0.15) * 5));\n                return (\n                  <span\n                    key={i}\n                    className=\"inline-block\"\n                    style={{\n                      filter: blur > 0.05 ? `blur(${blur.toFixed(2)}px)` : undefined,\n                      transform: blur > 0.05 ? `scaleY(${1 + blur * 0.02})` : undefined,\n                      opacity: 1 - blur * 0.06,\n                    }}\n                  >\n                    {c}\n                  </span>\n                );\n              })}\n            </span>\n          </span>\n        </h2>\n        <p aria-hidden=\"true\" className=\"mt-4 text-lg text-[#33475c] sm:text-xl\">windows cleaned since 2019</p>\n        <span aria-hidden=\"true\" className=\"mt-8 h-px w-24 bg-[#0f1b2a]/20\" />\n        <p className=\"mt-8 max-w-md text-base leading-relaxed text-[#33475c]\">\n          Fast digits soften while they spin and sharpen as they slow, the way a real dial looks in motion. A sample figure for a made-up firm.\n        </p>\n        <a\n          href=\"#\"\n          className=\"mt-8 inline-flex h-11 items-center rounded-full bg-[#0f1b2a] px-6 text-sm font-medium text-white transition hover:bg-[#22344a] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#0f1b2a] focus-visible:ring-offset-2\"\n        >\n          Book a clean\n        </a>\n      </div>\n    </section>\n  );\n}\n"}]}
