{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stripe-count",
  "title": "Stripe Count",
  "description": "A huge 184 counts up on an orange band with a dark bold number and a caption above.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/stripe-count/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadFamiljen } from \"@remotion/google-fonts/FamiljenGrotesk\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst familjen = loadFamiljen(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface StripeCountProps {\n  value?: number;\n  from?: number;\n  prefix?: string;\n  suffix?: string;\n  label?: string;\n  stripes?: number;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst ORANGE = \"#FF4F00\";\n\nconst THEMES = {\n  dark: { field: \"#1E1E1E\", ink: \"#FFE7D6\", inkOnAccent: \"#1E1E1E\" },\n  light: { field: \"#FFE7D6\", ink: \"#1E1E1E\", inkOnAccent: \"#1E1E1E\" },\n} as const;\n\nconst TRACK = -0.03;\nconst RISE_AT = 0;\nconst RISE_LEN = 16;\nconst PAINT_AT = 16;\nconst PAINT_END = 76;\nconst LABEL_AT = 66;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IN_OUT = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n  figH: number;\n  label: number;\n  width: (s: string) => number;\n}\n\nfunction format(n: number) {\n  return Math.round(n).toLocaleString(\"en-US\");\n}\n\nfunction measureAll(label: string): Metrics {\n  const canvas = document.createElement(\"canvas\");\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) throw new Error(\"stripe-count: no 2d context\");\n  const fam = `\"${familjen.fontFamily}\"`;\n  ctx.font = `500 100px ${fam}`;\n  const figH = ctx.measureText(\"0123456789\").actualBoundingBoxAscent / 100;\n  const cache = new Map<string, number>();\n  const width = (raw: string) => {\n    const s = raw.replace(/[0-9]/g, \"0\");\n    const hit = cache.get(s);\n    if (hit !== undefined) return hit;\n    ctx.font = `500 100px ${fam}`;\n    const w = ctx.measureText(s).width / 100 + TRACK * Array.from(s).length;\n    cache.set(s, w);\n    return w;\n  };\n  ctx.font = `400 100px ${fam}`;\n  const labelW = label ? ctx.measureText(label).width / 100 : 0;\n  return { figH, label: labelW, width };\n}\n\nfunction useMetrics(label: string) {\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"stripe-count: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      familjen.waitUntilDone(),\n      document.fonts.load(`500 100px \"${familjen.fontFamily}\"`),\n      document.fonts.load(`400 100px \"${familjen.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setState({ key: label, m: measureAll(label) });\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [label, handle]);\n  return state && state.key === label ? state.m : null;\n}\n\nexport function StripeCount({\n  value = 184,\n  from = 0,\n  prefix = \"\",\n  suffix = \"\",\n  label = \"scenes that take your brand colour from one prop\",\n  stripes = 12,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: StripeCountProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const c = THEMES[theme];\n  const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const m = useMetrics(label);\n\n  const transparent = background === \"transparent\";\n  const hot = accent ?? ORANGE;\n  const field = transparent ? c.field : (background ?? c.field);\n\n  if (!m) {\n    return (\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          background: transparent ? \"transparent\" : field,\n        }}\n      />\n    );\n  }\n\n  const portrait = H > W * 1.1;\n  const s = portrait ? W / 1080 : Math.min(W / 1280, H / 720);\n  const pad = Math.min(W, H) * 0.075;\n\n  const paint = (time: number) =>\n    interpolate(time, [PAINT_AT, PAINT_END], [0, 1], {\n      ...CLAMP,\n      easing: EASE_IN_OUT,\n    });\n  const p = paint(t);\n  const text = `${prefix}${format(from + (value - from) * paint(t))}${suffix}`;\n  const finalText = `${prefix}${format(value)}${suffix}`;\n  const wFinal = m.width(finalText);\n\n  const labelFs = (portrait ? 50 : 36) * s;\n  const labelW = Math.min(W - pad * 2, labelFs * (portrait ? 16 : 22));\n  const labelLines = Math.max(1, Math.ceil((m.label * labelFs) / labelW));\n  const bandH = label\n    ? pad * 2 + labelFs * 1.22 * labelLines\n    : H * (portrait ? 0.2 : 0.24);\n\n  const F = Math.min((W - pad * 2) / wFinal, (H - bandH - pad * 2) / m.figH);\n  const figH = m.figH * F;\n  const baseY = H - pad;\n  const right = W - pad;\n\n  const rise = interpolate(t, [RISE_AT, RISE_AT + RISE_LEN], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const top = baseY - figH - F * 0.06;\n  const bottom = Math.min(H, baseY + F * 0.16);\n  const bandClipH = bottom - top;\n  const dy = (1 - rise) * bandClipH;\n\n  const n = Math.max(4, Math.round(stripes));\n  const pitch = (figH + F * 0.06) / n;\n  const firstY = baseY - figH - F * 0.06;\n  const rows = Math.ceil(bandClipH / pitch);\n  const reach = 0.55;\n  const minK = 0.07;\n\n  const outline = 1 - interpolate(p, [0.78, 1], [0, 1], CLAMP);\n  const strokeW = Math.max(1.2, F * 0.0065);\n  const ink = transparent ? c.ink : c.inkOnAccent;\n\n  const labelWords = label ? label.split(\" \") : [];\n\n  const textProps = {\n    x: right,\n    y: baseY + dy,\n    textAnchor: \"end\" as const,\n    fontFamily: familjen.fontFamily,\n    fontWeight: 500,\n    fontSize: F,\n    letterSpacing: `${TRACK}em`,\n    style: { fontVariantNumeric: \"tabular-nums\" as const },\n  };\n\n  return (\n    <AbsoluteFill\n      style={{\n        background: transparent ? \"transparent\" : hot,\n        overflow: \"hidden\",\n      }}\n    >\n      {transparent ? null : (\n        <div\n          style={{\n            position: \"absolute\",\n            left: 0,\n            top: 0,\n            width: W,\n            height: bandH,\n            background: field,\n          }}\n        />\n      )}\n\n      <svg\n        width={W}\n        height={H}\n        style={{ position: \"absolute\", inset: 0 }}\n        aria-hidden\n      >\n        <defs>\n          <clipPath id={`${uid}t`}>\n            <text {...textProps}>{text}</text>\n          </clipPath>\n          <filter id={`${uid}o`} x=\"-5%\" y=\"-20%\" width=\"110%\" height=\"140%\">\n            <feMorphology\n              in=\"SourceAlpha\"\n              operator=\"erode\"\n              radius={strokeW}\n              result=\"in\"\n            />\n            <feComposite in=\"SourceGraphic\" in2=\"in\" operator=\"out\" />\n          </filter>\n          <clipPath id={`${uid}b`}>\n            <rect x={0} y={top} width={W} height={bandClipH} />\n          </clipPath>\n        </defs>\n        <g clipPath={`url(#${uid}b)`}>\n          <g clipPath={`url(#${uid}t)`}>\n            {Array.from({ length: rows }, (_, k) => {\n              const local = interpolate(\n                p * (1 + reach) - (k / Math.max(1, rows - 1)) * reach,\n                [0, 1],\n                [0, 1],\n                { ...CLAMP, easing: EASE_OUT },\n              );\n              const th = pitch * (minK + (1.04 - minK) * local);\n              const yc = firstY + dy + pitch * (k + 0.5);\n              return (\n                <rect\n                  key={`s${k}`}\n                  x={0}\n                  y={yc - th / 2}\n                  width={W}\n                  height={th}\n                  style={{ fill: ink }}\n                />\n              );\n            })}\n          </g>\n          {outline > 0 ? (\n            <text\n              {...textProps}\n              filter={`url(#${uid}o)`}\n              opacity={outline}\n              style={{ ...textProps.style, fill: ink }}\n            >\n              {text}\n            </text>\n          ) : null}\n        </g>\n      </svg>\n\n      {label ? (\n        <div\n          style={{\n            position: \"absolute\",\n            left: pad,\n            width: labelW,\n            top: pad - labelFs * 0.12,\n            display: \"flex\",\n            flexWrap: \"wrap\",\n            columnGap: \"0.26em\",\n            fontFamily: familjen.fontFamily,\n            fontWeight: 400,\n            fontSize: labelFs,\n            lineHeight: 1.22,\n            letterSpacing: \"-0.01em\",\n            color: c.ink,\n          }}\n        >\n          {labelWords.map((w, k) => {\n            const q = interpolate(\n              t,\n              [LABEL_AT + k * 2, LABEL_AT + k * 2 + 16],\n              [0, 1],\n              { ...CLAMP, easing: EASE_OUT },\n            );\n            return (\n              <span\n                key={`${w}-${k}`}\n                style={{\n                  display: \"inline-block\",\n                  opacity: q,\n                  transform: `translateY(${((1 - q) * labelFs * 0.7).toFixed(2)}px)`,\n                }}\n              >\n                {w}\n              </span>\n            );\n          })}\n        </div>\n      ) : null}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/stripe-count.tsx"
    }
  ],
  "type": "registry:component"
}
