{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tally-marks",
  "title": "Tally Marks",
  "description": "Hand-drawn tally marks fill rows until they resolve into the 1,240 count.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/tally-marks/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Fraunces\";\nimport { useId, useMemo } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  spring,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: fraunces } = loadFont(\"normal\", {\n  weights: [\"300\", \"400\"],\n  subsets: [\"latin\"],\n});\nloadFont(\"italic\", { weights: [\"300\", \"400\"], subsets: [\"latin\"] });\n\n// gradients.sh \"swirl\" palette\nconst SWIRL = {\n  bg: \"#07060a\",\n  c: [\"#ffe2c4\", \"#ff9a4d\", \"#d2456b\", \"#3a1f6b\"],\n} as const;\n\nexport interface TallyMarksProps {\n  value?: number;\n  label?: string;\n  rows?: number;\n  groupsPerRow?: number;\n  accent?: string;\n  theme?: \"dark\" | \"light\";\n  speed?: number;\n}\n\nconst T0 = 6;\nconst TALLY = 66;\nconst R0 = 0.2;\nconst ROW_IN = 78;\nconst ROW_LEN = 18;\nconst COL_IN = 90;\nconst COL_LEN = 18;\nconst COL_STAGGER = 4;\nconst TIP = COL_IN + COL_LEN + COL_STAGGER;\nconst NUM_IN = TIP + 10;\n\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst THEMES = {\n  dark: {\n    bg: SWIRL.bg,\n    fg: \"#F4F1EC\",\n    muted: \"#9A949C\",\n    stops: [\"#ffc79a\", SWIRL.c[1], SWIRL.c[2], \"#9b4fa6\"],\n    grain: 0.06,\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#121214\",\n    muted: \"#6E6C67\",\n    stops: [\"#ff8a3d\", \"#f2602c\", SWIRL.c[2], \"#7a3a9a\"],\n    grain: 0.045,\n  },\n} as const;\n\nfunction hash(a: number, b: number) {\n  let h = (Math.imul(a, 374761393) + Math.imul(b, 668265263)) | 0;\n  h = Math.imul(h ^ (h >>> 13), 1274126177);\n  h ^= h >>> 16;\n  return (h >>> 0) / 4294967296;\n}\n\nfunction formatNumber(n: number) {\n  return Math.round(Math.abs(n))\n    .toString()\n    .replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\");\n}\n\nfunction solveRate(n: number, d: number, r0: number) {\n  if (r0 * d >= n) return 1e-6;\n  let lo = 1e-6;\n  let hi = 1;\n  for (let i = 0; i < 60; i++) {\n    const mid = (lo + hi) / 2;\n    const f = (r0 / mid) * (Math.exp(mid * d) - 1);\n    if (f > n) hi = mid;\n    else lo = mid;\n  }\n  return (lo + hi) / 2;\n}\n\ninterface Stroke {\n  key: string;\n  row: number;\n  col: number;\n  k: number;\n  slash: boolean;\n  at: number;\n  dur: number;\n  ja: number;\n  jl: number;\n  jx: number;\n  jy: number;\n}\n\nfunction buildStrokes(rows: number, perRow: number): Stroke[] {\n  const n = rows * perRow * 5;\n  const rate = solveRate(n, TALLY, R0);\n  const list: Stroke[] = [];\n  for (let i = 0; i < n; i++) {\n    const g = Math.floor(i / 5);\n    const k = i % 5;\n    const slash = k === 4;\n    const at = T0 + Math.log(1 + (i * rate) / R0) / rate;\n    const prog = i / Math.max(1, n - 1);\n    list.push({\n      key: `s${i}`,\n      row: Math.floor(g / perRow),\n      col: g % perRow,\n      k,\n      slash,\n      at,\n      dur: interpolate(prog, [0, 0.35, 1], [6, 4, 3], CLAMP),\n      ja: (hash(i, 3) - 0.5) * (slash ? 6 : 5),\n      jl: (hash(i, 5) - 0.5) * 0.08,\n      jx: (hash(i, 7) - 0.5) * 2.4,\n      jy: (hash(i, 11) - 0.5) * 4,\n    });\n  }\n  return list;\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 }}\n      aria-hidden\n    >\n      <filter id={id}>\n        <feTurbulence\n          type=\"fractalNoise\"\n          baseFrequency=\"0.9\"\n          numOctaves={2}\n          seed={41}\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 TallyMarks({\n  value = 1240,\n  label = \"videos rendered on launch day\",\n  rows = 4,\n  groupsPerRow = 9,\n  accent = \"#3B5BFD\",\n  theme = \"dark\",\n  speed = 1,\n}: TallyMarksProps) {\n  const t = useCurrentFrame() * speed;\n  const { width, height, fps } = useVideoConfig();\n  const u = Math.min(width / 1280, height / 720);\n  const p = THEMES[theme];\n  const nRows = Math.max(1, Math.min(6, Math.round(rows)));\n  const nCols = Math.max(2, Math.min(14, Math.round(groupsPerRow)));\n  const strokes = useMemo(() => buildStrokes(nRows, nCols), [nRows, nCols]);\n  const gradId = `tm${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  const ruleGradId = `${gradId}r`;\n\n  const cx = width / 2;\n  const cy = height / 2;\n  const sw = 9 * u;\n  const L = 74 * u;\n  const P = 19 * u;\n  const over = 9 * u;\n  const slashDx = 3 * P + 2 * over;\n  const slashDy = 0.6 * L;\n  const slashLen = Math.hypot(slashDx, slashDy);\n  const slashAng = (Math.atan2(slashDx, slashDy) * 180) / Math.PI;\n  const groupW = 3 * P + 2 * over;\n  const pitchX = Math.min(\n    124 * u,\n    (width * 0.84 - groupW) / Math.max(1, nCols - 1),\n  );\n  const pitchY = Math.min(\n    124 * u,\n    (height * 0.66 - L) / Math.max(1, nRows - 1),\n  );\n  const gx0 = cx - ((nCols - 1) * pitchX) / 2;\n  const ry0 = cy - ((nRows - 1) * pitchY) / 2;\n  const midCol = (nCols - 1) / 2;\n  const midRow = (nRows - 1) / 2;\n  const total = nRows * nCols * 5;\n  const rate = useMemo(() => solveRate(total, TALLY, R0), [total]);\n\n  const frameAt = (tt: number) => {\n    const drawn = Math.max(\n      0.2,\n      Math.min(\n        total,\n        (R0 / rate) * (Math.exp(rate * Math.max(0, tt - T0)) - 1),\n      ),\n    );\n    const gi = drawn / 5;\n    const rowsF = gi / nCols;\n    const right =\n      gx0 + Math.min(nCols - 1, Math.max(0, gi - 0.5)) * pitchX + groupW / 2;\n    const leftX = gx0 - groupW / 2;\n    const topY = ry0 - L / 2;\n    const bottom =\n      ry0 + Math.min(nRows - 1, Math.max(0, rowsF - 0.7)) * pitchY + L / 2;\n    const bw = right - leftX;\n    const bh = bottom - topY;\n    const s = Math.max(\n      1,\n      Math.min(2.3, (width * 0.84) / bw, (height * 0.62) / bh),\n    );\n    return { s, fx: (leftX + right) / 2, fy: (topY + bottom) / 2 };\n  };\n  let camS = frameAt(t + 14).s;\n  let camX = 0;\n  let camY = 0;\n  const SAMPLES = [6, 8, 10, 12, 14];\n  for (const d of SAMPLES) {\n    const f = frameAt(t + d);\n    camX += f.fx / SAMPLES.length;\n    camY += f.fy / SAMPLES.length;\n  }\n  const settle = interpolate(t, [T0 + TALLY - 6, ROW_IN], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  camS += (1 - camS) * settle;\n  camX += (cx - camX) * settle;\n  camY += (cy - camY) * settle;\n  const camT = `translate(${cx} ${cy}) scale(${camS}) translate(${-camX} ${-camY})`;\n\n  const text = formatNumber(value);\n  const numSize = 172 * u;\n  const ruleY = cy + 58 * u;\n  const ruleT = 8 * u;\n  const digitCount = text.replace(/,/g, \"\").length;\n  const commaCount = text.length - digitCount;\n  const ruleW = Math.min(\n    width * 0.6,\n    numSize * (0.6 * digitCount + 0.26 * commaCount) * 0.92,\n  );\n\n  const push = interpolate(t, [0, TIP + 30], [0.985, 1.01], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const showStrokes = t < TIP;\n\n  const tip = spring({\n    frame: t - TIP,\n    fps,\n    config: { damping: 22, stiffness: 140, mass: 0.8 },\n  });\n\n  const lines = showStrokes\n    ? strokes.map((s) => {\n        const appear = interpolate(t, [s.at, s.at + s.dur], [0, 1], {\n          ...CLAMP,\n          easing: EASE_OUT,\n        });\n        if (appear <= 0) return null;\n        const rowDelay =\n          (1 - Math.abs(s.row - midRow) / Math.max(1, midRow)) * 2;\n        const rowK = interpolate(\n          t,\n          [ROW_IN + rowDelay, ROW_IN + rowDelay + ROW_LEN],\n          [0, 1],\n          { ...CLAMP, easing: EASE_IO },\n        );\n        const colDelay =\n          (1 - Math.abs(s.col - midCol) / Math.max(1, midCol)) * COL_STAGGER;\n        const colK = interpolate(\n          t,\n          [COL_IN + colDelay, COL_IN + colDelay + COL_LEN],\n          [0, 1],\n          { ...CLAMP, easing: EASE_IO },\n        );\n        const jit = 1 - rowK;\n        const ang = (s.slash ? slashAng * (1 - colK) : 0) + s.ja * jit;\n        const fullLen = s.slash ? slashLen : L * (1 + s.jl * jit);\n        const len = fullLen + (L - fullLen) * colK;\n        const gx = gx0 + s.col * pitchX;\n        const ry = ry0 + s.row * pitchY;\n        const ox = s.slash ? 0 : (s.k - 1.5) * P;\n        const x = gx + (cx - gx) * colK + ox * (1 - colK) + s.jx * u * jit;\n        const y = ry + (cy - ry) * rowK + s.jy * u * jit;\n        const a = (ang * Math.PI) / 180;\n        const dx = Math.sin(a);\n        const dy = -Math.cos(a);\n        const h = len / 2;\n        const vis = len * appear;\n        let x1: number;\n        let y1: number;\n        let x2: number;\n        let y2: number;\n        if (s.slash) {\n          x1 = x - dx * h;\n          y1 = y - dy * h;\n          x2 = x1 + dx * vis;\n          y2 = y1 + dy * vis;\n        } else {\n          x1 = x + dx * h;\n          y1 = y + dy * h;\n          x2 = x1 - dx * vis;\n          y2 = y1 - dy * vis;\n        }\n        return (\n          <line\n            key={s.key}\n            x1={x1}\n            y1={y1}\n            x2={x2}\n            y2={y2}\n            stroke={s.slash ? `url(#${gradId})` : p.fg}\n            strokeWidth={sw * (1 + 0.22 * (1 - appear))}\n            strokeLinecap=\"round\"\n            opacity={Math.min(1, appear * 2.5)}\n          />\n        );\n      })\n    : null;\n\n  const barAng = (90 * tip * Math.PI) / 180;\n  const barLen = L + (ruleW - L) * tip;\n  const barY = cy + (ruleY - cy) * tip;\n  const barT = sw + (ruleT - sw) * Math.min(1, tip);\n  const bdx = Math.sin(barAng) * (barLen / 2);\n  const bdy = -Math.cos(barAng) * (barLen / 2);\n\n  const fieldL = gx0 - groupW / 2;\n  const fieldR = gx0 + (nCols - 1) * pitchX + groupW / 2;\n  const drift = interpolate(t, [0, TIP + 40], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const stops = (\n    <>\n      <stop offset=\"0\" stopColor={p.stops[0]} />\n      <stop offset=\"0.34\" stopColor={p.stops[1]} />\n      <stop offset=\"0.66\" stopColor={p.stops[2]} />\n      <stop offset=\"0.86\" stopColor={p.stops[3]} />\n      <stop offset=\"1\" stopColor={accent} />\n    </>\n  );\n  const chars = text.split(\"\");\n  const label1 = interpolate(t, [NUM_IN + 12, NUM_IN + 30], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n\n  return (\n    <AbsoluteFill style={{ background: p.bg, overflow: \"hidden\" }}>\n      <AbsoluteFill\n        style={{ transform: `scale(${push})`, transformOrigin: \"50% 50%\" }}\n      >\n        <svg\n          width={width}\n          height={height}\n          style={{ position: \"absolute\", inset: 0 }}\n          aria-hidden\n        >\n          <defs>\n            <linearGradient\n              id={gradId}\n              gradientUnits=\"userSpaceOnUse\"\n              x1={fieldL}\n              y1={ry0 - pitchY}\n              x2={fieldR}\n              y2={ry0 + nRows * pitchY}\n            >\n              {stops}\n            </linearGradient>\n            <linearGradient\n              id={ruleGradId}\n              gradientUnits=\"userSpaceOnUse\"\n              x1={cx - ruleW * (0.5 + 0.1 * drift)}\n              y1={barY}\n              x2={cx + ruleW * (0.5 - 0.1 * drift)}\n              y2={barY}\n            >\n              {stops}\n            </linearGradient>\n          </defs>\n          <g transform={camT}>{lines}</g>\n          {showStrokes ? null : (\n            <line\n              x1={cx - bdx}\n              y1={barY - bdy}\n              x2={cx + bdx}\n              y2={barY + bdy}\n              stroke={`url(#${ruleGradId})`}\n              strokeWidth={barT}\n              strokeLinecap=\"round\"\n            />\n          )}\n        </svg>\n\n        {t >= NUM_IN - 1 ? (\n          <div\n            style={{\n              position: \"absolute\",\n              left: 0,\n              right: 0,\n              top: ruleY - 22 * u - numSize * 1.12,\n              height: numSize * 1.12,\n              overflow: \"hidden\",\n              display: \"flex\",\n              justifyContent: \"center\",\n              alignItems: \"flex-end\",\n            }}\n          >\n            {chars.map((ch, i) => {\n              const k = interpolate(\n                t,\n                [NUM_IN + i * 2, NUM_IN + i * 2 + 18],\n                [0, 1],\n                { ...CLAMP, easing: EASE_OUT },\n              );\n              return (\n                <span\n                  key={`${ch}${i.toString()}`}\n                  style={{\n                    display: \"inline-block\",\n                    fontFamily: fraunces,\n                    fontWeight: 300,\n                    fontSize: numSize,\n                    lineHeight: 1.12,\n                    letterSpacing: \"-0.035em\",\n                    fontVariantNumeric: \"lining-nums tabular-nums\",\n                    color: p.fg,\n                    transform: `translateY(${(1 - k) * 105}%)`,\n                  }}\n                >\n                  {ch}\n                </span>\n              );\n            })}\n          </div>\n        ) : null}\n\n        <div\n          style={{\n            position: \"absolute\",\n            left: 0,\n            right: 0,\n            top: ruleY + 26 * u,\n            textAlign: \"center\",\n            fontFamily: fraunces,\n            fontStyle: \"italic\",\n            fontWeight: 300,\n            fontSize: 30 * u,\n            letterSpacing: \"-0.01em\",\n            color: p.muted,\n            whiteSpace: \"nowrap\",\n            opacity: label1,\n            transform: `translateY(${(1 - label1) * 8 * u}px)`,\n          }}\n        >\n          {label}\n        </div>\n      </AbsoluteFill>\n\n      <AbsoluteFill\n        style={{\n          background: `radial-gradient(ellipse 80% 80% at 50% 50%, transparent 62%, ${p.bg} 100%)`,\n          opacity: 0.55,\n        }}\n      />\n      <Grain opacity={p.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/tally-marks.tsx"
    }
  ],
  "type": "registry:component"
}
