{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tall-count",
  "title": "Tall Count",
  "description": "A tall condensed orange-gradient +240% counts up beside a three-line caption.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/tall-count/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadInstrument } from \"@remotion/google-fonts/InstrumentSans\";\nimport { loadVariableFont } from \"@remotion/google-fonts/RobotoFlex\";\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  spring,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst flex = loadVariableFont(\"oblique 0deg 10deg\", { subsets: [\"latin\"] });\nconst instrument = loadInstrument(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface TallCountProps {\n  value?: number;\n  from?: number;\n  decimals?: number;\n  prefix?: string;\n  suffix?: string;\n  label?: string;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst RISE = [\"#fff1e2\", \"#ff8a3d\", \"#a3301a\", \"#2a0d0a\"] as const;\n\nconst THEMES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    ink: \"#F4F3F0\",\n    muted: \"#9A999F\",\n    fill: [RISE[2], \"#e0703b\", RISE[1], RISE[0], RISE[0]],\n    glow: (a: string) =>\n      [\n        `radial-gradient(70% 48% at 30% 108%, color-mix(in oklab, ${RISE[2]} 40%, transparent) 0%, color-mix(in oklab, ${RISE[3]} 60%, transparent) 46%, transparent 78%)`,\n        `radial-gradient(40% 30% at 86% 110%, color-mix(in oklab, ${a} 16%, transparent) 0%, transparent 80%)`,\n      ].join(\", \"),\n    grain: 0.05,\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    ink: \"#111113\",\n    muted: \"#5E5C57\",\n    fill: [RISE[3], \"#5a1a10\", RISE[2], \"#d9541f\", \"#f07a35\"],\n    glow: (a: string) =>\n      [\n        `radial-gradient(70% 46% at 30% 110%, color-mix(in oklab, ${RISE[1]} 22%, transparent) 0%, transparent 76%)`,\n        `radial-gradient(40% 30% at 86% 112%, color-mix(in oklab, ${a} 10%, transparent) 0%, transparent 80%)`,\n      ].join(\", \"),\n    grain: 0.035,\n  },\n} as const;\n\nconst WDTH = [25, 151] as const;\nconst SAMPLES = [25, 35, 50, 70, 90, 110, 130, 151];\nconst WGHT = 460;\nconst TRACK = -0.01;\nconst YTFI = [738, 788] as const;\n\nconst GROW_AT = 8;\nconst GROW_END = 66;\nconst LIFT_AT = 54;\nconst LABEL_AT = 2;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_GROW = Easing.bezier(0.33, 0, 0.16, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst fvs = (wdth: number, ytfi: number) =>\n  `\"wdth\" ${wdth.toFixed(2)}, \"wght\" ${WGHT}, \"YTFI\" ${ytfi.toFixed(1)}, \"opsz\" 144, \"slnt\" 0`;\n\ntype Curve = number[];\n\ninterface Metrics {\n  digit: Curve;\n  comma: Curve;\n  dot: Curve;\n  prefix: Curve;\n  suffix: Curve;\n  baseline: number;\n  figTop: [number, number];\n}\n\nfunction widthAt(curve: Curve, wdth: number) {\n  const w = Math.min(WDTH[1], Math.max(WDTH[0], wdth));\n  for (let i = 0; i < SAMPLES.length - 1; i++) {\n    if (w <= SAMPLES[i + 1]) {\n      const k = (w - SAMPLES[i]) / (SAMPLES[i + 1] - SAMPLES[i]);\n      return curve[i] + (curve[i + 1] - curve[i]) * k;\n    }\n  }\n  return curve[curve.length - 1];\n}\n\nfunction solveWdth(curve: Curve, target: number) {\n  if (target <= curve[0]) return WDTH[0];\n  for (let i = 0; i < SAMPLES.length - 1; i++) {\n    if (target <= curve[i + 1]) {\n      const k = (target - curve[i]) / Math.max(1e-6, curve[i + 1] - curve[i]);\n      return SAMPLES[i] + (SAMPLES[i + 1] - SAMPLES[i]) * k;\n    }\n  }\n  return WDTH[1];\n}\n\nfunction format(v: number, decimals: number) {\n  return v.toLocaleString(\"en-US\", {\n    minimumFractionDigits: decimals,\n    maximumFractionDigits: decimals,\n  });\n}\n\nfunction measure(prefix: string, suffix: string): Metrics {\n  const probe = document.createElement(\"span\");\n  Object.assign(probe.style, {\n    position: \"absolute\",\n    left: \"-99999px\",\n    top: \"0\",\n    visibility: \"hidden\",\n    whiteSpace: \"pre\",\n    fontFamily: `\"${flex.fontFamily}\"`,\n    fontStyle: \"normal\",\n    fontSize: \"100px\",\n    lineHeight: \"1\",\n    fontVariantNumeric: \"tabular-nums\",\n    letterSpacing: `${TRACK}em`,\n  });\n  document.body.appendChild(probe);\n  const curve = (s: string): Curve =>\n    SAMPLES.map((wd) => {\n      if (!s) return 0;\n      probe.style.fontVariationSettings = fvs(wd, YTFI[0]);\n      probe.textContent = s;\n      return probe.getBoundingClientRect().width / 100;\n    });\n  const m = {\n    digit: curve(\"0\"),\n    comma: curve(\",\"),\n    dot: curve(\".\"),\n    prefix: curve(prefix),\n    suffix: curve(suffix),\n  };\n  probe.remove();\n\n  const canvas = document.createElement(\"canvas\");\n  canvas.width = 400;\n  canvas.height = 400;\n  const ctx = canvas.getContext(\"2d\", { willReadFrequently: true });\n  let baseline = 0.78;\n  const figTop: [number, number] = [0.71, 0.76];\n  if (ctx) {\n    ctx.font = `${WGHT} 200px \"${flex.fontFamily}\"`;\n    const fm = ctx.measureText(\"0\");\n    const asc = fm.fontBoundingBoxAscent / 200;\n    const desc = fm.fontBoundingBoxDescent / 200;\n    baseline = (1 - (asc + desc)) / 2 + asc;\n    figTop[0] = fm.actualBoundingBoxAscent / 200;\n    figTop[1] = figTop[0] * (YTFI[1] / YTFI[0]);\n  }\n  return { ...m, baseline, figTop };\n}\n\nfunction useMetrics(prefix: string, suffix: string) {\n  const key = `${prefix}\\u0001${suffix}`;\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"tall-count: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    const [p, s] = key.split(\"\\u0001\");\n    Promise.all([\n      flex.waitUntilDone(),\n      instrument.waitUntilDone(),\n      document.fonts.load(`${WGHT} 100px \"${flex.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setState({ key, m: measure(p, s) });\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [key, handle]);\n  return state && state.key === key ? state.m : null;\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n  const id = `tc${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  return (\n    <svg\n      width=\"100%\"\n      height=\"100%\"\n      style={{ position: \"absolute\", inset: 0, opacity, pointerEvents: \"none\" }}\n      aria-hidden\n    >\n      <filter id={id}>\n        <feTurbulence\n          type=\"fractalNoise\"\n          baseFrequency=\"0.9\"\n          numOctaves={2}\n          seed={3}\n          stitchTiles=\"stitch\"\n        />\n        <feColorMatrix values=\"0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0.9 0\" />\n      </filter>\n      <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n    </svg>\n  );\n}\n\nexport function TallCount({\n  value = 240,\n  from = 0,\n  decimals = 0,\n  prefix = \"+\",\n  suffix = \"%\",\n  label = \"more watch time on launch posts that move\",\n  accent = \"#3B5BFD\",\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: TallCountProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, fps } = useVideoConfig();\n  const c = THEMES[theme];\n  const m = useMetrics(prefix, suffix);\n  const finalText = useMemo(() => format(value, decimals), [value, decimals]);\n\n  const transparent = background === \"transparent\";\n  const stage = transparent ? \"transparent\" : (background ?? c.bg);\n\n  if (!m) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const portrait = H > W * 1.1;\n  const s = portrait ? W / 1080 : Math.min(W / 1280, H / 720);\n\n  const curveOf = (text: string): Curve =>\n    SAMPLES.map((_, i) => {\n      let w = m.prefix[i] + m.suffix[i];\n      for (const ch of text) {\n        if (ch === \",\") w += m.comma[i];\n        else if (ch === \".\") w += m.dot[i];\n        else w += m.digit[i];\n      }\n      return w;\n    });\n\n  const marginX = W * (portrait ? 0.07 : 0.075);\n  const measureFrame = portrait ? W - marginX * 2 : W * 0.54;\n  const labelGap = W * 0.035;\n  const labelW = W - marginX * 2;\n  const labelFs = (portrait ? 48 : 38) * s;\n  const baseY = portrait ? H * 0.6 : H * 0.84;\n\n  const STRETCH = 0.16;\n  const maxInk = portrait ? H * 0.36 : H * 0.7;\n  const finalCurve = curveOf(finalText);\n  const F1 = Math.min(\n    measureFrame / Math.max(0.1, finalCurve[0] * 1.08),\n    maxInk / (m.figTop[1] * (1 + STRETCH)),\n  );\n  const measureW = Math.min(measureFrame, F1 * finalCurve[0] * 1.08);\n  const F0 = F1 * 0.3;\n  const finalW = widthAt(finalCurve, solveWdth(finalCurve, measureW / F1)) * F1;\n\n  const g = interpolate(t, [GROW_AT, GROW_END], [0, 1], {\n    ...CLAMP,\n    easing: EASE_GROW,\n  });\n  const count = from + (value - from) * g;\n  const text = format(\n    Math.round(count * 10 ** decimals) / 10 ** decimals,\n    decimals,\n  );\n  const curve = curveOf(text);\n  const F = F0 + (F1 - F0) * g;\n  const wdth = Math.min(WDTH[1], solveWdth(curve, measureW / F));\n  const ytfi = YTFI[0] + (YTFI[1] - YTFI[0]) * g * g;\n  const lift = spring({\n    frame: t - LIFT_AT,\n    fps,\n    config: { damping: 11, stiffness: 110, mass: 0.9 },\n  });\n  const sy = 1 + STRETCH * lift;\n  const numW = widthAt(curve, wdth) * F;\n\n  const enter = interpolate(t, [0, 12], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n\n  const numLeft = portrait ? (W - numW) / 2 : marginX;\n  const boxTop = baseY - m.baseline * F;\n  const fill = `linear-gradient(0deg, ${c.fill[0]} ${(100 - (baseY / H) * 100).toFixed(1)}%, ${c.fill[1]} ${(100 - ((baseY - maxInk * 0.35) / H) * 100).toFixed(1)}%, ${c.fill[2]} ${(100 - ((baseY - maxInk * 0.7) / H) * 100).toFixed(1)}%, ${c.fill[3]} ${(100 - ((baseY - maxInk * 1.02) / H) * 100).toFixed(1)}%, ${c.fill[4]} 100%)`;\n\n  const labelP = interpolate(t, [LABEL_AT, LABEL_AT + 18], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const labelTop = portrait ? baseY + labelFs * 1.2 : undefined;\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {transparent ? null : (\n        <div\n          style={{\n            position: \"absolute\",\n            inset: 0,\n            background: c.glow(accent),\n            opacity: interpolate(t, [GROW_AT, GROW_END], [0.35, 1], CLAMP),\n          }}\n        />\n      )}\n\n      <div\n        style={{\n          position: \"absolute\",\n          left: numLeft,\n          top: boxTop,\n          height: F,\n          lineHeight: `${F}px`,\n          whiteSpace: \"pre\",\n          fontFamily: flex.fontFamily,\n          fontStyle: \"normal\",\n          fontSize: F,\n          fontVariantNumeric: \"tabular-nums\",\n          fontVariationSettings: fvs(wdth, ytfi),\n          letterSpacing: `${TRACK}em`,\n          transformOrigin: `0 ${(m.baseline * F).toFixed(2)}px`,\n          transform: `scaleY(${sy.toFixed(4)})`,\n          opacity: enter,\n          filter:\n            enter < 1\n              ? `blur(${((1 - enter) * 10 * s).toFixed(2)}px)`\n              : undefined,\n          backgroundImage: fill,\n          backgroundSize: `${W}px ${H}px`,\n          backgroundPosition: `${-numLeft}px ${-boxTop}px`,\n          WebkitBackgroundClip: \"text\",\n          backgroundClip: \"text\",\n          color: \"transparent\",\n        }}\n      >\n        {prefix}\n        {text}\n        {suffix}\n      </div>\n\n      {label ? (\n        <div\n          style={{\n            position: \"absolute\",\n            left: portrait ? marginX : marginX + finalW + labelGap,\n            width: portrait\n              ? labelW\n              : Math.min(W * 0.32, W - marginX * 2 - finalW - labelGap),\n            ...(portrait\n              ? { top: labelTop, textAlign: \"center\" as const }\n              : { bottom: H - baseY - labelFs * 0.22 }),\n            fontFamily: instrument.fontFamily,\n            fontWeight: 400,\n            fontSize: labelFs,\n            lineHeight: 1.22,\n            letterSpacing: \"-0.012em\",\n            textWrap: \"balance\",\n            color: c.muted,\n            opacity: labelP,\n            transform: `translateY(${((1 - labelP) * labelFs * 0.6).toFixed(2)}px)`,\n          }}\n        >\n          {label}\n        </div>\n      ) : null}\n\n      {transparent ? null : <Grain opacity={c.grain} />}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/tall-count.tsx"
    }
  ],
  "type": "registry:component"
}
