{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "log-rescale",
  "title": "Log Rescale",
  "description": "A bar chart rescales to a log axis so the final 2.4M bar stands out.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/log-rescale/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/HankenGrotesk\";\nimport { useId } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  interpolateColors,\n  spring,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: sans } = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface LogRescaleDatum {\n  label: string;\n  value: number;\n}\n\nexport interface LogRescaleProps {\n  data?: LogRescaleDatum[];\n  accentIndex?: number;\n  title?: string;\n  accent?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst DEFAULT_DATA: LogRescaleDatum[] = [\n  { label: \"2021\", value: 340 },\n  { label: \"2022\", value: 1200 },\n  { label: \"2023\", value: 4800 },\n  { label: \"2024\", value: 18000 },\n  { label: \"2025\", value: 96000 },\n  { label: \"2026\", value: 2400000 },\n];\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: \"#0A0A0B\",\n    fg: \"#F3F2EF\",\n    muted: \"#8B8A90\",\n    bar: \"#46464D\",\n    barEnd: \"#5E5E66\",\n    grid: \"rgba(243,242,239,0.1)\",\n    minor: \"rgba(243,242,239,0.04)\",\n    base: \"rgba(243,242,239,0.36)\",\n    grain: 0.06,\n    // gradients.sh \"beam\": the hero bar heats from accent blue to ice white.\n    hero: [\"#2e45b7\", \"#3d5bff\", \"#8fb4ff\", \"#e4ebff\"],\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#121214\",\n    muted: \"#6E6C67\",\n    bar: \"#CFCDC6\",\n    barEnd: \"#B9B6AE\",\n    grid: \"rgba(18,18,20,0.1)\",\n    minor: \"rgba(18,18,20,0.045)\",\n    base: \"rgba(18,18,20,0.4)\",\n    grain: 0.045,\n    hero: [\"#24339a\", \"#3d5bff\", \"#6f8fff\", \"#9db4ff\"],\n  },\n} as const;\n\nconst MORPH = [64, 106] as const;\nconst ACCENT_GROW = 24;\nconst LABELS_AT = 100;\n\nfunction compact(v: number) {\n  const fmt = (n: number, suffix: string) => {\n    const r = n >= 100 ? Math.round(n) : Math.round(n * 10) / 10;\n    return `${String(r).replace(/\\.0$/, \"\")}${suffix}`;\n  };\n  if (v >= 1e9) return fmt(v / 1e9, \"B\");\n  if (v >= 1e6) return fmt(v / 1e6, \"M\");\n  if (v >= 1e3) return fmt(v / 1e3, \"k\");\n  return fmt(v, \"\");\n}\n\nfunction niceStep(raw: number) {\n  const pow = 10 ** Math.floor(Math.log10(raw));\n  const f = raw / pow;\n  const nice = f <= 1 ? 1 : f <= 2 ? 2 : f <= 2.5 ? 2.5 : f <= 5 ? 5 : 10;\n  return nice * pow;\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={23}\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\nconst lerp = (a: number, b: number, k: number) => a + (b - a) * k;\n\nexport function LogRescale({\n  data = DEFAULT_DATA,\n  accentIndex,\n  title = \"remocn renders per year\",\n  accent = \"#3B5BFD\",\n  speed = 1,\n  theme = \"dark\",\n}: LogRescaleProps) {\n  const t = useCurrentFrame() * speed;\n  const { width, height, fps } = useVideoConfig();\n  const u = height / 720;\n  const p = THEMES[theme];\n  const heroId = `hero${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n\n  const rows = data.length > 0 ? data : DEFAULT_DATA;\n  const n = rows.length;\n  const values = rows.map((d) => Math.max(d.value, 1e-6));\n  const maxV = Math.max(...values);\n  const minV = Math.min(...values);\n  const ai =\n    accentIndex !== undefined && accentIndex >= 0 && accentIndex < n\n      ? accentIndex\n      : values.indexOf(maxV);\n\n  const step = niceStep(maxV / 5);\n  const linMax = Math.ceil(maxV / step - 1e-9) * step;\n  const lo = 10 ** Math.floor(Math.log10(minV));\n  const hi = 10 ** Math.ceil(Math.log10(maxV) + 1e-9);\n  const decades = Math.round(Math.log10(hi / lo));\n\n  const m = interpolate(t, MORPH, [0, 1], { ...CLAMP, easing: EASE_IO });\n  const linN = (v: number) => v / linMax;\n  const logN = (v: number) =>\n    (Math.log10(Math.max(v, lo)) - Math.log10(lo)) / decades;\n  const norm = (v: number) => lerp(linN(v), logN(v), m);\n\n  const left = width * 0.16;\n  const right = width * 0.88;\n  const top = height * 0.24;\n  const bottom = height * 0.8;\n  const chartH = bottom - top;\n  const yOf = (v: number) => bottom - norm(v) * chartH;\n\n  const intro = interpolate(t, [0, 14], [0, 1], { ...CLAMP, easing: EASE_OUT });\n\n  const tickMap = new Map<number, { lin: boolean; log: boolean }>();\n  for (let v = 0; v <= linMax + step / 2; v += step) {\n    const key = Math.round(v);\n    tickMap.set(key, { lin: true, log: false });\n  }\n  for (let k = 0; k <= decades; k++) {\n    const key = Math.round(lo * 10 ** k);\n    const prev = tickMap.get(key);\n    tickMap.set(key, { lin: prev?.lin ?? false, log: true });\n  }\n  const linA = interpolate(m, [0.02, 0.34], [1, 0], CLAMP);\n  const logA = interpolate(m, [0.48, 0.9], [0, 1], CLAMP);\n  const ticks = [...tickMap.entries()]\n    .sort((a, b) => a[0] - b[0])\n    .map(([v, kind]) => {\n      const y = yOf(v);\n      const a = Math.max(kind.lin ? linA : 0, kind.log ? logA : 0);\n      const edge = interpolate(y, [top - 34 * u, top - 4 * u], [0, 1], CLAMP);\n      return { v, y, a: a * edge * intro };\n    });\n\n  const minors: Array<{ v: number; y: number }> = [];\n  for (let k = 0; k < decades; k++) {\n    for (let j = 2; j <= 9; j++) {\n      const v = lo * 10 ** k * j;\n      minors.push({ v, y: yOf(v) });\n    }\n  }\n  const minorA = interpolate(m, [0.5, 1], [0, 1], CLAMP);\n\n  const slot = (right - left) / n;\n  const bw = Math.min(slot * 0.52, 84 * u);\n\n  const growOf = (i: number) => {\n    if (i === ai) {\n      return spring({\n        frame: t - ACCENT_GROW,\n        fps,\n        config: { damping: 18, stiffness: 70, mass: 0.9 },\n      });\n    }\n    const order = i < ai ? i : i - 1;\n    return interpolate(t, [6 + order * 3, 26 + order * 3], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n  };\n\n  const scaleSwap = interpolate(t, [MORPH[0] + 4, MORPH[0] + 20], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const titleA = interpolate(t, [2, 18], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n\n  const accentBig = interpolate(t, [LABELS_AT, LABELS_AT + 18], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const accentIn = interpolate(\n    t,\n    [ACCENT_GROW + 14, ACCENT_GROW + 26],\n    [0, 1],\n    { ...CLAMP, easing: EASE_OUT },\n  );\n  const dim = interpolate(t, [LABELS_AT, LABELS_AT + 16], [0, 1], CLAMP);\n  const sw = Math.max(1, u);\n  const tagH = 20 * u;\n\n  return (\n    <AbsoluteFill style={{ background: p.bg, overflow: \"hidden\" }}>\n      <svg\n        width={width}\n        height={height}\n        style={{ position: \"absolute\", inset: 0 }}\n        aria-hidden\n      >\n        <defs>\n          <linearGradient\n            id={heroId}\n            gradientUnits=\"userSpaceOnUse\"\n            x1={0}\n            y1={bottom}\n            x2={0}\n            y2={top - chartH * 0.05}\n          >\n            <stop offset={0} stopColor={p.hero[0]} />\n            <stop offset={0.38} stopColor={accent} />\n            <stop offset={0.78} stopColor={p.hero[2]} />\n            <stop offset={1} stopColor={p.hero[3]} />\n          </linearGradient>\n        </defs>\n        {minors.map((mi) =>\n          mi.y > top - 2 * u && mi.y < bottom - 1 ? (\n            <line\n              key={`mi-${mi.v}`}\n              x1={left}\n              x2={right}\n              y1={mi.y}\n              y2={mi.y}\n              stroke={p.minor}\n              strokeWidth={sw}\n              opacity={minorA}\n            />\n          ) : null,\n        )}\n        {ticks.map((tk) =>\n          tk.a > 0.001 && tk.y < bottom - 1 ? (\n            <line\n              key={`g-${tk.v}`}\n              x1={left}\n              x2={right}\n              y1={tk.y}\n              y2={tk.y}\n              stroke={p.grid}\n              strokeWidth={sw}\n              opacity={tk.a}\n            />\n          ) : null,\n        )}\n\n        {rows.map((d, i) => {\n          const g = growOf(i);\n          const h = Math.max(\n            2 * u * Math.min(1, g * 4),\n            norm(values[i]) * chartH * g,\n          );\n          const x = left + slot * (i + 0.5) - bw / 2;\n          const isA = i === ai;\n          const r = Math.min(4 * u, h / 2, bw / 2);\n          const fill = isA\n            ? `url(#${heroId})`\n            : interpolateColors(dim, [0, 1], [p.barEnd, p.bar]);\n          return (\n            <path\n              key={`b-${d.label}`}\n              d={`M${x} ${bottom} L${x} ${bottom - h + r} Q${x} ${bottom - h} ${x + r} ${bottom - h} L${x + bw - r} ${bottom - h} Q${x + bw} ${bottom - h} ${x + bw} ${bottom - h + r} L${x + bw} ${bottom} Z`}\n              fill={fill}\n              opacity={g > 0 ? 1 : 0}\n            />\n          );\n        })}\n\n        <line\n          x1={left}\n          x2={lerp(left, right, intro)}\n          y1={bottom}\n          y2={bottom}\n          stroke={p.base}\n          strokeWidth={Math.max(1, 1.25 * u)}\n        />\n      </svg>\n\n      {ticks.map((tk) =>\n        tk.a > 0.001 ? (\n          <div\n            key={`t-${tk.v}`}\n            style={{\n              position: \"absolute\",\n              left: left - 160 * u,\n              width: 160 * u - 16 * u,\n              top: tk.y - 10 * u,\n              height: 20 * u,\n              lineHeight: `${20 * u}px`,\n              textAlign: \"right\",\n              fontFamily: sans,\n              fontWeight: 400,\n              fontSize: 16 * u,\n              letterSpacing: \"0\",\n              fontVariantNumeric: \"tabular-nums\",\n              color: p.muted,\n              opacity: tk.a,\n              whiteSpace: \"nowrap\",\n            }}\n          >\n            {compact(tk.v)}\n          </div>\n        ) : null,\n      )}\n\n      {rows.map((d, i) => {\n        const x = left + slot * (i + 0.5);\n        const isA = i === ai;\n        const g = growOf(i);\n        const h = norm(values[i]) * chartH * g;\n        const order = i < ai ? i : i - 1;\n        const a = isA\n          ? accentIn\n          : interpolate(\n              t,\n              [LABELS_AT + order * 3, LABELS_AT + 12 + order * 3],\n              [0, 1],\n              { ...CLAMP, easing: EASE_OUT },\n            );\n        const fs = isA ? lerp(20, 60, accentBig) * u : 17 * u;\n        return (\n          <div key={`v-${d.label}`}>\n            <div\n              style={{\n                position: \"absolute\",\n                left: x - 140 * u,\n                width: 280 * u,\n                top: bottom - h - fs * 1.1 - lerp(8, 6, accentBig) * u,\n                height: fs * 1.1,\n                lineHeight: `${fs * 1.1}px`,\n                textAlign: \"center\",\n                fontFamily: sans,\n                fontWeight: 500,\n                fontSize: fs,\n                letterSpacing: isA\n                  ? `${lerp(-0.01, -0.04, accentBig)}em`\n                  : \"-0.005em\",\n                fontVariantNumeric: \"tabular-nums\",\n                color: p.fg,\n                opacity: a,\n                transform: `translateY(${(1 - a) * 6 * u}px)`,\n                whiteSpace: \"nowrap\",\n              }}\n            >\n              {compact(values[i])}\n            </div>\n            <div\n              style={{\n                position: \"absolute\",\n                left: x - 100 * u,\n                width: 200 * u,\n                top: bottom + 14 * u,\n                textAlign: \"center\",\n                fontFamily: sans,\n                fontWeight: isA ? 500 : 400,\n                fontSize: 16 * u,\n                letterSpacing: \"0\",\n                fontVariantNumeric: \"tabular-nums\",\n                color: isA ? p.fg : p.muted,\n                opacity: interpolate(t, [4 + i * 2, 16 + i * 2], [0, 1], CLAMP),\n              }}\n            >\n              {d.label}\n            </div>\n          </div>\n        );\n      })}\n\n      <div\n        style={{\n          position: \"absolute\",\n          left: left - 16 * u - 2 * u,\n          top: height * 0.085,\n          display: \"flex\",\n          alignItems: \"baseline\",\n          justifyContent: \"space-between\",\n          width: right - left + 18 * u,\n          opacity: titleA,\n          transform: `translateY(${(1 - titleA) * 8 * u}px)`,\n        }}\n      >\n        <div\n          style={{\n            fontFamily: sans,\n            fontWeight: 500,\n            fontSize: 28 * u,\n            letterSpacing: \"-0.025em\",\n            color: p.fg,\n          }}\n        >\n          {title}\n        </div>\n        <div\n          style={{\n            display: \"flex\",\n            alignItems: \"center\",\n            gap: 8 * u,\n            fontFamily: sans,\n            fontWeight: 400,\n            fontSize: 17 * u,\n            color: p.muted,\n          }}\n        >\n          <div\n            style={{\n              position: \"relative\",\n              height: tagH,\n              width: 52 * u,\n              overflow: \"hidden\",\n            }}\n          >\n            {[\"Linear\", \"Log\"].map((w, k) => (\n              <div\n                key={w}\n                style={{\n                  position: \"absolute\",\n                  right: 0,\n                  top: (k - scaleSwap) * tagH,\n                  height: tagH,\n                  lineHeight: `${tagH}px`,\n                  color: k === 1 ? p.fg : p.muted,\n                  opacity: k === 0 ? 1 - scaleSwap : scaleSwap,\n                  whiteSpace: \"nowrap\",\n                }}\n              >\n                {w}\n              </div>\n            ))}\n          </div>\n          <div style={{ lineHeight: `${tagH}px` }}>scale</div>\n        </div>\n      </div>\n\n      <AbsoluteFill\n        style={{\n          background: `radial-gradient(ellipse 85% 85% at 50% 50%, transparent 64%, ${p.bg} 100%)`,\n          opacity: 0.5,\n        }}\n      />\n      <Grain opacity={p.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/log-rescale.tsx"
    }
  ],
  "type": "registry:component"
}
