{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shed-weight",
  "title": "Shed Weight",
  "description": "'Sharp at any size.' repeats at growing sizes, weight adjusting per size, with pt labels.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/shed-weight/index.tsx",
      "content": "\"use client\";\n\nimport { loadVariableFont } from \"@remotion/google-fonts/BricolageGrotesque\";\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 bricolage = loadVariableFont(\"normal\", { subsets: [\"latin\"] });\n\nexport interface ShedWeightProps {\n  text?: string;\n  sizes?: number;\n  showSizes?: boolean;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: {\n    bg: \"#16130F\",\n    ink: \"#F2EFE8\",\n    muted: \"rgba(242,239,232,0.5)\",\n    accent: \"#E5342A\",\n    rule: \"rgba(242,239,232,0.2)\",\n    grain: 0.05,\n  },\n  light: {\n    bg: \"#F2EFE8\",\n    ink: \"#111111\",\n    muted: \"rgba(17,17,17,0.5)\",\n    accent: \"#E5342A\",\n    rule: \"rgba(17,17,17,0.18)\",\n    grain: 0.035,\n  },\n} as const;\n\nconst OPSZ_MIN = 12;\nconst OPSZ_MAX = 96;\nconst WGHT = 460;\nconst TRACK_SMALL = 0.012;\nconst TRACK_LARGE = -0.036;\nconst RATIO = 1.42;\n\nconst FIRST_AT = 4;\nconst STEP_MIN = 6;\nconst STEP_MAX = 11;\nconst RULE_LEN = 14;\nconst RISE_LEN = 16;\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\nconst fvs = (opsz: number) =>\n  `\"opsz\" ${opsz.toFixed(1)}, \"wght\" ${WGHT}, \"wdth\" 100`;\n\ninterface Metrics {\n  widths: number[];\n  cap: number;\n  desc: number;\n  baseline: number;\n}\n\nfunction cuts(n: number) {\n  return Array.from({ length: n }, (_, k) => {\n    const u = n > 1 ? k / (n - 1) : 1;\n    return {\n      opsz: OPSZ_MIN + (OPSZ_MAX - OPSZ_MIN) * u,\n      track: TRACK_SMALL + (TRACK_LARGE - TRACK_SMALL) * u,\n    };\n  });\n}\n\nfunction measure(text: string, n: number): Metrics {\n  const probe = document.createElement(\"span\");\n  Object.assign(probe.style, {\n    position: \"absolute\",\n    left: \"-99999px\",\n    top: \"0\",\n    visibility: \"hidden\",\n    whiteSpace: \"pre\",\n    fontFamily: `\"${bricolage.fontFamily}\"`,\n    fontSize: \"100px\",\n    lineHeight: \"1\",\n  });\n  document.body.appendChild(probe);\n  const widths = cuts(n).map(({ opsz, track }) => {\n    probe.style.fontVariationSettings = fvs(opsz);\n    probe.style.letterSpacing = `${track}em`;\n    probe.textContent = text;\n    return probe.getBoundingClientRect().width / 100 - track;\n  });\n  probe.remove();\n  let cap = 0.72;\n  let desc = 0.22;\n  let baseline = 0.8;\n  const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n  if (ctx) {\n    ctx.font = `${WGHT} 100px \"${bricolage.fontFamily}\"`;\n    const fm = ctx.measureText(\"Hgy\");\n    cap = ctx.measureText(\"H\").actualBoundingBoxAscent / 100;\n    desc = fm.actualBoundingBoxDescent / 100;\n    const asc = fm.fontBoundingBoxAscent / 100;\n    const d = fm.fontBoundingBoxDescent / 100;\n    baseline = (1 - (asc + d)) / 2 + asc;\n  }\n  return { widths, cap, desc, baseline };\n}\n\nfunction useMetrics(text: string, n: number) {\n  const key = `${n}\\u0000${text}`;\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"shed-weight: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    const [count, tx] = key.split(\"\\u0000\");\n    Promise.all([\n      bricolage.waitUntilDone(),\n      document.fonts.load(`${WGHT} 100px \"${bricolage.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setState({ key, m: measure(tx, Number(count)) });\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 Grain({ opacity }: { opacity: number }) {\n  const id = `sw${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={4}\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 ShedWeight({\n  text = \"Sharp at any size.\",\n  sizes = 6,\n  showSizes = true,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: ShedWeightProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const c = THEMES[theme];\n  const spot = accent ?? c.accent;\n  const n = Math.max(2, Math.min(9, Math.round(sizes)));\n  const m = useMetrics(text, n);\n\n  const transparent = background === \"transparent\";\n  const stage = transparent ? \"transparent\" : (background ?? c.bg);\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 M = Math.min(W, H) * (portrait ? 0.08 : 0.075);\n  const tagSize = portrait ? W * 0.024 : H * 0.024;\n  const tagW = showSizes ? tagSize * 3.6 : 0;\n  const scaleOf = (k: number) => RATIO ** (k - (n - 1));\n  const lead = (k: number) =>\n    m.cap * scaleOf(k) + m.desc * scaleOf(k - 1) * 1.35;\n  let stackEm = m.cap * scaleOf(0);\n  for (let k = 1; k < n; k++) stackEm += lead(k);\n  const usableW = W - M * 2 - tagW;\n  const usableH = H - M * 2 - (portrait ? H * 0.12 : 0);\n  const fitW = Math.min(\n    ...m.widths.map((w, k) => usableW / Math.max(0.1, w * scaleOf(k))),\n  );\n  const F = Math.min(fitW, usableH / stackEm);\n  const baseLast = H - M * (portrait ? 2.4 : 1.25);\n  const room = baseLast - M * 1.4 - m.cap * scaleOf(0) * F;\n  const natural = (stackEm - m.cap * scaleOf(0)) * F;\n  const stretch = Math.max(1, Math.min(1.7, room / Math.max(1, natural)));\n  const bases: number[] = new Array(n).fill(0);\n  bases[n - 1] = baseLast;\n  for (let k = n - 1; k > 0; k--)\n    bases[k - 1] = bases[k] - lead(k) * F * stretch;\n\n  const list = cuts(n);\n  const startAt: number[] = [];\n  let at = FIRST_AT;\n  for (let k = 0; k < n; k++) {\n    startAt.push(at);\n    const u = n > 1 ? k / (n - 1) : 1;\n    at += STEP_MIN + (STEP_MAX - STEP_MIN) * u;\n  }\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {list.map(({ opsz, track }, k) => {\n        const size = F * scaleOf(k);\n        const base = bases[k];\n        const last = k === n - 1;\n        const ruleP = interpolate(\n          t,\n          [startAt[k] - 4, startAt[k] - 4 + RULE_LEN],\n          [0, 1],\n          { ...CLAMP, easing: EASE_IN_OUT },\n        );\n        const rise = interpolate(\n          t,\n          [startAt[k], startAt[k] + RISE_LEN],\n          [0, 1],\n          { ...CLAMP, easing: EASE_OUT },\n        );\n        const ruleH = last\n          ? Math.max(2, size * 0.014)\n          : Math.max(1, Math.min(2, size * 0.02));\n        const maskTop = base - size * (m.cap + 0.3);\n        return (\n          <div key={`cut-${k}`}>\n            <div\n              style={{\n                position: \"absolute\",\n                left: last ? 0 : M,\n                top: base + Math.max(2, size * 0.04),\n                width: last ? W : W - M * 2,\n                height: ruleH,\n                background: last ? spot : c.rule,\n                transformOrigin: \"0% 50%\",\n                transform: `scaleX(${ruleP.toFixed(4)})`,\n              }}\n            />\n            <div\n              style={{\n                position: \"absolute\",\n                left: 0,\n                top: maskTop,\n                width: W,\n                height: base - maskTop + size * (m.desc + 0.06),\n                overflow: \"hidden\",\n              }}\n            >\n              <div\n                style={{\n                  position: \"absolute\",\n                  left: M,\n                  top: base - maskTop - m.baseline * size,\n                  height: size,\n                  lineHeight: `${size}px`,\n                  whiteSpace: \"pre\",\n                  fontFamily: bricolage.fontFamily,\n                  fontSize: size,\n                  fontVariationSettings: fvs(opsz),\n                  letterSpacing: `${track}em`,\n                  color: c.ink,\n                  transform: `translateY(${((1 - rise) * size * 1.05).toFixed(2)}px)`,\n                }}\n              >\n                {text}\n              </div>\n            </div>\n            {showSizes ? (\n              <div\n                style={{\n                  position: \"absolute\",\n                  right: M,\n                  top: base - tagSize * 0.78,\n                  fontFamily: bricolage.fontFamily,\n                  fontVariationSettings: fvs(12),\n                  fontSize: tagSize,\n                  lineHeight: 1,\n                  letterSpacing: \"0.01em\",\n                  fontFeatureSettings: '\"tnum\" 1',\n                  whiteSpace: \"pre\",\n                  color: last ? spot : c.muted,\n                  opacity: rise,\n                }}\n              >\n                {`${Math.round(opsz)} pt`}\n              </div>\n            ) : null}\n          </div>\n        );\n      })}\n      {transparent ? null : <Grain opacity={c.grain} />}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/shed-weight.tsx"
    }
  ],
  "type": "registry:component"
}
