{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "weight-cut",
  "title": "Weight Cut",
  "description": "A large light-weight figure counts up to 6.8 KB as its strokes thin, with a small caps eyebrow.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/weight-cut/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/BarlowCondensed\";\nimport { useEffect, 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 WEIGHTS = [\"100\", \"200\", \"300\", \"400\", \"500\"] as const;\nconst barlow = loadFont(\"normal\", {\n  weights: [...WEIGHTS],\n  subsets: [\"latin\"],\n});\n\nexport interface WeightCutProps {\n  value?: number;\n  from?: number;\n  decimals?: number;\n  prefix?: string;\n  suffix?: string;\n  eyebrow?: string;\n  label?: string;\n  lightWeight?: number;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: {\n    bg: \"#000000\",\n    ink: \"#FFFFFF\",\n    accent: \"#D4FF00\",\n  },\n  light: {\n    bg: \"#D4FF00\",\n    ink: \"#000000\",\n    accent: \"#000000\",\n  },\n} as const;\n\nconst TRACK = 0.01;\nconst SUFFIX_SCALE = 0.3;\n\nconst ENTER_END = 14;\nconst COUNT_AT = 20;\nconst COUNT_END = 78;\nconst LABEL_AT = 64;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_COUNT = Easing.bezier(0.3, 0, 0.12, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n  adv: Record<string, number>;\n  slot: number;\n  stemLight: number;\n  stemHeavy: number;\n  baseline: number;\n  figTop: number;\n}\n\nfunction snapWeight(w: number) {\n  const v = Math.min(500, Math.max(100, w));\n  return Math.round(v / 100) * 100;\n}\n\nfunction measure(chars: string[], light: number): Metrics {\n  const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n  const adv: Record<string, number> = {};\n  let slot = 0.45;\n  let stemLight = 0.02;\n  let stemHeavy = 0.1;\n  let baseline = 0.8;\n  let figTop = 0.7;\n  if (!ctx) {\n    for (const ch of chars) adv[ch] = 0.45;\n    return { adv, slot, stemLight, stemHeavy, baseline, figTop };\n  }\n  const ink = (w: number) => {\n    ctx.font = `${w} 200px \"${barlow.fontFamily}\"`;\n    const mm = ctx.measureText(\"I\");\n    return (mm.actualBoundingBoxLeft + mm.actualBoundingBoxRight) / 200;\n  };\n  stemHeavy = ink(500);\n  stemLight = ink(light);\n  ctx.font = `${light} 200px \"${barlow.fontFamily}\"`;\n  for (const ch of chars) adv[ch] = ctx.measureText(ch).width / 200;\n  slot = Math.max(\n    ...Array.from({ length: 10 }, (_, d) => adv[String(d)] ?? 0.4),\n  );\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 = fm.actualBoundingBoxAscent / 200;\n  return { adv, slot, stemLight, stemHeavy, baseline, figTop };\n}\n\nfunction useMetrics(chars: string[], light: number) {\n  const key = `${light}\\u0002${chars.join(\"\\u0001\")}`;\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"weight-cut: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    const [lw, list] = key.split(\"\\u0002\");\n    Promise.all([\n      barlow.waitUntilDone(),\n      ...WEIGHTS.map((w) =>\n        document.fonts.load(`${w} 100px \"${barlow.fontFamily}\"`),\n      ),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setState({ key, m: measure(list.split(\"\\u0001\"), Number(lw)) });\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 format(v: number, decimals: number) {\n  return v.toLocaleString(\"en-US\", {\n    minimumFractionDigits: decimals,\n    maximumFractionDigits: decimals,\n  });\n}\n\nfunction intDigits(v: number, decimals: number) {\n  const shown = Math.round(Math.abs(v) * 10 ** decimals) / 10 ** decimals;\n  return Math.max(1, Math.floor(shown).toString().length);\n}\n\nexport function WeightCut({\n  value = 6.8,\n  from = 94,\n  decimals = 1,\n  prefix = \"\",\n  suffix = \"KB\",\n  eyebrow = \"Per scene, gzipped\",\n  label = \"Lighter than your logo file.\",\n  lightWeight = 100,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: WeightCutProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, fps } = useVideoConfig();\n  const c = THEMES[theme];\n  const spot = accent ?? c.accent;\n  const light = snapWeight(lightWeight);\n  const chars = useMemo(\n    () =>\n      Array.from(\n        new Set([\"0123456789.,\", prefix, suffix.toUpperCase()].join(\"\")),\n      ),\n    [prefix, suffix],\n  );\n  const m = useMetrics(chars, light);\n\n  const transparent = background === \"transparent\";\n  const stage = transparent ? \"transparent\" : (background ?? c.bg);\n\n  const drops = useMemo(() => {\n    const out: { at: number }[] = [];\n    let prev = intDigits(from, decimals);\n    for (let f = COUNT_AT; f <= COUNT_END; f += 0.25) {\n      const g = EASE_COUNT((f - COUNT_AT) / (COUNT_END - COUNT_AT));\n      const d = intDigits(from + (value - from) * g, decimals);\n      if (d < prev) {\n        for (let k = prev; k > d; k--) out.push({ at: f });\n        prev = d;\n      }\n    }\n    return out;\n  }, [from, value, decimals]);\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 g = interpolate(t, [COUNT_AT, COUNT_END], [0, 1], {\n    ...CLAMP,\n    easing: EASE_COUNT,\n  });\n  const raw = from + (value - from) * g;\n  const shown = Math.round(raw * 10 ** decimals) / 10 ** decimals;\n  const text = `${prefix}${format(shown, decimals)}`;\n  const span = from - value;\n  const heavy = span === 0 ? 0 : Math.min(1, Math.max(0, (raw - value) / span));\n\n  const enter = interpolate(t, [-5, ENTER_END], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const relax = spring({\n    frame: t - (COUNT_END - 10),\n    fps,\n    config: { damping: 18, stiffness: 120, mass: 0.9 },\n  });\n  const closing = drops\n    .filter((d) => t >= d.at)\n    .map((d) =>\n      spring({\n        frame: t - d.at,\n        fps,\n        config: { damping: 16, stiffness: 140, mass: 0.8 },\n      }),\n    )\n    .filter((k) => k < 0.999);\n\n  const sufText = suffix.toUpperCase();\n  const advOf = (ch: string) => m.adv[ch] ?? m.slot;\n  const startText = `${prefix}${format(from, decimals)}`;\n  const startEm =\n    Array.from(startText).reduce(\n      (a, ch) => a + (/[0-9]/.test(ch) ? m.slot : advOf(ch)) + TRACK,\n      0,\n    ) +\n    m.stemHeavy +\n    (sufText\n      ? 0.03 +\n        Array.from(sufText).reduce((a, ch) => a + advOf(ch), 0) * SUFFIX_SCALE +\n        m.stemHeavy * SUFFIX_SCALE\n      : 0);\n\n  const margin = portrait ? W * 0.07 : W * 0.05;\n  const colW = portrait ? 0 : W * 0.28;\n  const roomW = W - margin * 2 - colW;\n  const F = Math.min(\n    roomW / Math.max(0.2, startEm),\n    (H * (portrait ? 0.3 : 0.76)) / m.figTop,\n  );\n  const stroke = Math.max(0, m.stemHeavy - m.stemLight) * F * heavy;\n  const baseY = portrait ? H * 0.62 : H - margin;\n  const boxTop = baseY - m.baseline * F;\n\n  const glyphs: { ch: string; x: number; w: number }[] = [];\n  let x = margin + stroke / 2;\n  for (const k of closing) x += m.slot * F * (1 - k);\n  for (const ch of Array.from(text)) {\n    const natural = advOf(ch);\n    const w =\n      (/[0-9]/.test(ch) ? m.slot + (natural - m.slot) * relax : natural) * F +\n      TRACK * F +\n      stroke;\n    glyphs.push({ ch, x, w });\n    x += w;\n  }\n  const numRight = x;\n  const sufF = F * SUFFIX_SCALE;\n\n  const eyebrowFs = (portrait ? 40 : 26) * s;\n  const labelFs = (portrait ? 72 : 52) * s;\n  const eyebrowP = interpolate(t, [2, 18], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const labelP = interpolate(t, [LABEL_AT, LABEL_AT + 18], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n\n  const figure = {\n    position: \"absolute\" as const,\n    whiteSpace: \"pre\" as const,\n    fontFamily: barlow.fontFamily,\n    fontWeight: light,\n    color: c.ink,\n    WebkitTextStroke:\n      stroke > 0.05 ? `${stroke.toFixed(2)}px ${c.ink}` : undefined,\n  };\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          opacity: enter,\n          transform: `translateY(${((1 - enter) * F * 0.06).toFixed(2)}px)`,\n        }}\n      >\n        {glyphs.map((gl, i) => (\n          <div\n            key={i}\n            style={{\n              ...figure,\n              left: gl.x,\n              width: gl.w,\n              top: boxTop,\n              height: F,\n              lineHeight: `${F}px`,\n              textAlign: \"center\",\n              fontSize: F,\n            }}\n          >\n            {gl.ch}\n          </div>\n        ))}\n        {sufText ? (\n          <div\n            style={{\n              ...figure,\n              left: numRight + F * 0.03,\n              top: baseY - m.baseline * sufF,\n              height: sufF,\n              lineHeight: `${sufF}px`,\n              fontSize: sufF,\n              WebkitTextStroke:\n                stroke > 0.05\n                  ? `${(stroke * SUFFIX_SCALE).toFixed(2)}px ${c.ink}`\n                  : undefined,\n            }}\n          >\n            {sufText}\n          </div>\n        ) : null}\n      </div>\n\n      <div\n        style={{\n          position: \"absolute\",\n          ...(portrait\n            ? { left: margin, right: margin, top: margin * 1.6 }\n            : { right: margin, width: colW - margin * 0.5, top: margin }),\n          display: \"flex\",\n          flexDirection: \"column\",\n          alignItems: \"flex-start\",\n          gap: eyebrowFs * 0.7,\n          fontFamily: barlow.fontFamily,\n          textTransform: \"uppercase\",\n        }}\n      >\n        {eyebrow ? (\n          <div\n            style={{\n              fontWeight: 500,\n              fontSize: eyebrowFs,\n              lineHeight: 1,\n              color: spot,\n              opacity: eyebrowP,\n            }}\n          >\n            {eyebrow}\n          </div>\n        ) : null}\n        {label ? (\n          <div\n            style={{\n              fontWeight: 500,\n              fontSize: labelFs,\n              lineHeight: 0.94,\n              color: c.ink,\n              textWrap: \"balance\",\n              opacity: labelP,\n              transform: `translateY(${((1 - labelP) * labelFs * 0.4).toFixed(2)}px)`,\n            }}\n          >\n            {label}\n          </div>\n        ) : null}\n      </div>\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/weight-cut.tsx"
    }
  ],
  "type": "registry:component"
}
