{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "counter-reveal",
  "title": "Counter Reveal",
  "description": "A huge front word reveals through the counters of its letters on a blue gradient.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/counter-reveal/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Sora\";\nimport { useId, useMemo } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: sora } = loadFont(\"normal\", {\n  weights: [\"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface CounterRevealProps {\n  /**\n   * Huge front word. Letters with embedded outlines (the default \"Beta\")\n   * get real counter windows; any other letter falls back to live text.\n   */\n  word?: string;\n  /** The line seen through the counters, then revealed in full. */\n  line?: string;\n  accent?: string;\n  theme?: \"dark\" | \"light\";\n  speed?: number;\n}\n\n// Sora 500 advance widths (per 1000 em) for ASCII 32–126, and full outlines\n// (outer contours + counters, overlaps removed) for the default word, in the\n// same units with the baseline at y = 0, y down. Extracted offline from the\n// Google Fonts Sora build (fontTools + skia-pathops).\nconst SORA_500 = [\n  222, 303, 452, 702, 652, 864, 702, 264, 382, 382, 568, 592, 266, 506, 266,\n  365, 750, 423, 623, 620, 652, 630, 668, 585, 647, 668, 266, 266, 592, 590,\n  592, 556, 1124, 765, 684, 797, 788, 598, 560, 832, 803, 320, 641, 703, 549,\n  937, 858, 865, 649, 865, 710, 682, 602, 785, 719, 1052, 705, 654, 652, 382,\n  365, 382, 587, 581, 300, 581, 694, 608, 694, 616, 380, 679, 644, 317, 324,\n  595, 296, 973, 644, 678, 694, 694, 414, 543, 429, 634, 572, 873, 574, 555,\n  493, 382, 375, 382, 511,\n];\n\nconst GLYPHS: Record<string, { outer: string; holes: string }> = {\n  B: {\n    outer:\n      \"M98 4V-735H348Q470 -735 532 -684Q594 -632 594 -536V-522Q594 -454 562 -414Q543 -390 516 -374Q563 -357 592 -321Q624 -281 624 -212V-198Q624 -134 596 -88Q569 -43 514 -20Q460 4 378 4Z\",\n    holes:\n      \"M217 -320V-96H390Q444 -96 474 -126Q503 -156 503 -208Q503 -261 474 -290Q445 -320 390 -320ZM217 -635V-416H363Q420 -416 446 -446Q473 -477 473 -525Q473 -574 446 -604Q420 -635 363 -635Z\",\n  },\n  e: {\n    outer:\n      \"M321 18Q251 18 199 -6Q147 -30 114 -70Q81 -109 64 -158Q48 -208 48 -260V-279Q48 -332 64 -382Q81 -431 114 -470Q147 -510 198 -534Q248 -557 315 -557Q402 -557 460 -519Q518 -481 547 -420Q576 -360 576 -290V-243H160Q163 -204 176 -172Q193 -130 229 -106Q265 -81 321 -81Q377 -81 413 -106Q449 -130 457 -163H566Q555 -108 522 -67Q488 -26 437 -4Q386 18 321 18Z\",\n    holes:\n      \"M163 -322H462Q458 -351 448 -375Q431 -415 398 -436Q365 -458 315 -458Q263 -458 228 -434Q193 -410 176 -368Q167 -347 163 -322Z\",\n  },\n  t: {\n    outer:\n      \"M307 6Q240 6 194 -12Q148 -30 124 -74Q101 -118 101 -193V-452H12V-539H101V-696H212V-539H388V-452H212V-183Q212 -141 234 -118Q257 -96 298 -96H388V6Z\",\n    holes: \"\",\n  },\n  a: {\n    outer:\n      \"M411 0V-105Q405 -83 394 -65Q372 -27 332 -6Q293 14 236 14Q177 14 133 -6Q89 -27 65 -66Q41 -106 41 -161Q41 -219 68 -257Q96 -295 147 -314Q198 -333 269 -333H392V-343Q392 -393 366 -419Q340 -445 289 -445Q261 -445 227 -444Q193 -443 160 -442Q128 -440 103 -438V-539Q125 -541 152 -542Q178 -544 206 -545Q235 -546 261 -546Q343 -546 397 -525Q451 -504 478 -458Q504 -413 504 -337V0Z\",\n    holes:\n      \"M392 -256H266Q213 -256 185 -230Q157 -205 157 -164Q157 -123 185 -98Q213 -74 266 -74Q297 -74 325 -86Q353 -97 372 -124Q390 -151 392 -200Z\",\n  },\n};\n\nconst CAP = 0.73;\nconst WORD_TRACK = -0.03;\nconst LINE_TRACK = -0.035;\nconst WORD_SPACE = 0.24;\n\n// Beats (frames at 30fps).\nconst ENTER = -6; // first letter is already mid-rise on frame 0\nconst ENTER_LEN = 20;\nconst STAGGER = 3;\nconst EXIT = 66;\nconst EXIT_LEN = 26;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IO = Easing.bezier(0.7, 0, 0.3, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\n// The ground under the plate is a gradients.sh palette: \"mesh\" (blue family,\n// sits with the accent) for dark, \"pixel-glass\" for light. `tint` is the line\n// while it is seen through the counters, `ink` once it is uncovered.\nconst THEMES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    fg: \"#F3F2EF\",\n    ink: \"#F5F4F0\",\n    tint: \"#0A0F33\",\n    grain: 0.07,\n    ground: \"#0a0d24\",\n    blobs: [\n      [\"#ecdcf2\", 86, 94, 30],\n      [\"#2e45b7\", 16, 20, 100],\n      [\"#8796ee\", 84, 22, 62],\n      [\"#0e1645\", 20, 86, 100],\n      [\"accent\", 52, 50, 58],\n    ],\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#121214\",\n    ink: \"#121214\",\n    tint: \"#2B1D6E\",\n    grain: 0.045,\n    ground: \"#f4f3f1\",\n    blobs: [\n      [\"#7a3cff\", 18, 24, 78],\n      [\"#ff4fb8\", 84, 28, 62],\n      [\"#3d6bff\", 72, 88, 82],\n      [\"accent\", 24, 82, 50],\n    ],\n  },\n} as const;\n\nexport const counterRevealDuration = EXIT + EXIT_LEN + 40;\n\nfunction advance(ch: string) {\n  const code = ch.charCodeAt(0);\n  return (code >= 32 && code < 127 ? SORA_500[code - 32] : 640) / 1000;\n}\n\nfunction layoutRow(text: string, track: number) {\n  const chars = Array.from(text);\n  const xs: number[] = [];\n  let x = 0;\n  chars.forEach((ch, i) => {\n    xs.push(x);\n    const a = ch === \" \" ? WORD_SPACE : advance(ch);\n    x += a + (i < chars.length - 1 ? track : 0);\n  });\n  return { chars, xs, width: x };\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n  const id = `g${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={29}\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 CounterReveal({\n  word = \"Beta\",\n  line = \"Out now.\",\n  accent = \"#3B5BFD\",\n  theme = \"dark\",\n  speed = 1,\n}: CounterRevealProps) {\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\n  const front = useMemo(() => layoutRow(word, WORD_TRACK), [word]);\n  const back = useMemo(() => layoutRow(line, LINE_TRACK), [line]);\n\n  // Front word fills the frame edge to edge.\n  const F = Math.min((W * 0.96) / front.width, (H * 0.66) / CAP);\n  const wordLeft = W / 2 - (front.width * F) / 2;\n  const baseline = H / 2 + (CAP * F) / 2;\n\n  // Back line at poster size; while it hides behind the windows it is set\n  // much larger and darker, so its strokes register inside the counters.\n  const B = Math.min((W * 0.86) / back.width, (H * 0.34) / CAP);\n  const lineLeft = W / 2 - (back.width * B) / 2;\n  const lineBase = H / 2 + (CAP * B) / 2;\n  const end = EXIT + EXIT_LEN;\n  const drift = EASE_IO(interpolate(t, [0, end], [0, 1], CLAMP));\n  const lineShift = (1 - drift) * W * 0.45;\n  const shrink = EASE_IO(interpolate(t, [EXIT - 6, end + 4], [0, 1], CLAMP));\n  const settle = interpolate(t, [end, end + 36], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const lineScale = (1.9 - 0.9 * shrink) * (1 + 0.03 * settle);\n  const tint = c.tint;\n  // Blobs drift a few percent over the shot, deterministic in frame.\n  const flow = interpolate(t, [0, counterRevealDuration], [0, 1], CLAMP);\n  const ground = [\n    ...c.blobs.map(([col, x, y, a], i) => {\n      const dx = (i % 2 ? -5 : 5) * flow;\n      const dy = (i % 3 === 0 ? 4 : -3) * flow;\n      const cc = col === \"accent\" ? accent : col;\n      return `radial-gradient(85% 95% at ${x + dx}% ${y + dy}%, color-mix(in oklab, ${cc} ${a}%, transparent) 0%, transparent 68%)`;\n    }),\n    c.ground,\n  ].join(\", \");\n\n  const exit = EASE_IO(interpolate(t, [EXIT, end], [0, 1], CLAMP));\n  const plateY = -exit * H * 1.04;\n  const push = 1 + 0.025 * interpolate(t, [ENTER_LEN, EXIT], [0, 1], CLAMP);\n  // Screen y of the plate's trailing edge: below it the line is already\n  // uncovered and shows in its final ink; through the windows it stays dark.\n  const edgeY = plateY + baseline + (H - baseline) * push;\n\n  const rise = (i: number) =>\n    EASE_OUT(\n      interpolate(\n        t,\n        [ENTER + i * STAGGER, ENTER + i * STAGGER + ENTER_LEN],\n        [0, 1],\n        CLAMP,\n      ),\n    );\n  const glyphAt = (i: number) =>\n    `translate(${wordLeft + front.xs[i] * F} ${baseline + (1 - rise(i)) * CAP * F * 1.08}) scale(${F / 1000})`;\n\n  const maskId = `m${uid}`;\n  const clipId = `c${uid}`;\n  const edgeId = `e${uid}`;\n  // Holes in the plate overshoot by a hair; the glyph drawn on top hides it.\n  const pad = (Math.max(1.5, 0.004 * F) * 1000) / F;\n\n  return (\n    <AbsoluteFill style={{ background: c.ground, overflow: \"hidden\" }}>\n      <div style={{ position: \"absolute\", inset: 0, background: ground }} />\n      <svg\n        width={W}\n        height={H}\n        viewBox={`0 0 ${W} ${H}`}\n        style={{ position: \"absolute\", inset: 0 }}\n        aria-hidden\n      >\n        <defs>\n          <clipPath id={clipId}>\n            <rect\n              x={-W}\n              y={-H}\n              width={W * 3}\n              height={H + baseline + 0.02 * F}\n            />\n          </clipPath>\n          <clipPath id={edgeId}>\n            <rect x={0} y={edgeY} width={W} height={Math.max(0, H - edgeY)} />\n          </clipPath>\n          <mask id={maskId} maskUnits=\"userSpaceOnUse\">\n            <rect x={-W} y={-H} width={W * 3} height={H * 3} fill=\"white\" />\n            <g clipPath={`url(#${clipId})`}>\n              {front.chars.map((ch, i) => {\n                const g = GLYPHS[ch];\n                if (!g?.holes) return null;\n                return (\n                  <path\n                    key={`${i}-${ch}`}\n                    d={g.holes}\n                    fill=\"black\"\n                    stroke=\"black\"\n                    strokeWidth={pad}\n                    strokeLinejoin=\"round\"\n                    transform={glyphAt(i)}\n                  />\n                );\n              })}\n            </g>\n          </mask>\n        </defs>\n\n        <g\n          transform={`translate(${W / 2 + lineShift} ${H / 2}) scale(${lineScale}) translate(${-W / 2} ${-H / 2})`}\n        >\n          <text\n            x={back.xs.map((x) => lineLeft + x * B).join(\" \")}\n            y={lineBase}\n            fontFamily={sora}\n            fontWeight={500}\n            fontSize={B}\n            fill={tint}\n            style={{ fontOpticalSizing: \"none\" }}\n          >\n            {back.chars.join(\"\")}\n          </text>\n        </g>\n\n        <g transform={`translate(0 ${plateY})`}>\n          <g\n            transform={`translate(${W / 2} ${baseline}) scale(${push}) translate(${-W / 2} ${-baseline})`}\n          >\n            <rect\n              x={-W}\n              y={-H}\n              width={W * 3}\n              height={H * 2}\n              fill={c.bg}\n              mask={`url(#${maskId})`}\n            />\n            <g clipPath={`url(#${clipId})`} fill={c.fg}>\n              {front.chars.map((ch, i) => {\n                const g = GLYPHS[ch];\n                if (g) {\n                  return (\n                    <path\n                      key={`${i}-${ch}`}\n                      d={g.outer + g.holes}\n                      fillRule=\"evenodd\"\n                      transform={glyphAt(i)}\n                    />\n                  );\n                }\n                return (\n                  <text\n                    key={`${i}-${ch}`}\n                    transform={glyphAt(i)}\n                    fontFamily={sora}\n                    fontWeight={500}\n                    fontSize={1000}\n                    style={{ fontOpticalSizing: \"none\" }}\n                  >\n                    {ch}\n                  </text>\n                );\n              })}\n            </g>\n          </g>\n        </g>\n        <g clipPath={`url(#${edgeId})`}>\n          <g\n            transform={`translate(${W / 2 + lineShift} ${H / 2}) scale(${lineScale}) translate(${-W / 2} ${-H / 2})`}\n          >\n            <text\n              x={back.xs.map((x) => lineLeft + x * B).join(\" \")}\n              y={lineBase}\n              fontFamily={sora}\n              fontWeight={500}\n              fontSize={B}\n              fill={c.ink}\n              style={{ fontOpticalSizing: \"none\" }}\n            >\n              {back.chars.join(\"\")}\n            </text>\n          </g>\n        </g>\n      </svg>\n      <Grain opacity={c.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/counter-reveal.tsx"
    }
  ],
  "type": "registry:component"
}
