{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "free-as-in",
  "title": "Free As in",
  "description": "A big \"Free\" is glossed line by line: as in beer, speech, no seats, yours.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/free-as-in/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/AlbertSans\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst albert = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface FreeAsInProps {\n  word?: string;\n  glosses?: string[];\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: { bg: \"#141414\", ink: \"#FFFFFF\", accent: \"#3DD9FF\" },\n  light: { bg: \"#FFFFFF\", ink: \"#000000\", accent: \"#0077B6\" },\n} as const;\n\nconst DEFAULT_GLOSSES = [\n  \"as in beer.\",\n  \"as in speech.\",\n  \"as in no seats.\",\n  \"as in yours.\",\n];\n\nconst TRACK_WORD = -0.045;\nconst TRACK_GLOSS = -0.015;\nconst GLH = 1.22;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nfunction useWidths(keys: string[]) {\n  const key = keys.join(\"\\u0001\");\n  const [state, setState] = useState<{\n    key: string;\n    w: Record<string, number>;\n  } | null>(null);\n  const [handle] = useState(() => delayRender(\"free-as-in: measuring\"));\n  const released = useRef(false);\n  const ref = useRef(keys);\n  ref.current = keys;\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      albert.waitUntilDone(),\n      document.fonts.load(`400 100px \"${albert.fontFamily}\"`),\n      document.fonts.load(`500 100px \"${albert.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n        const w: Record<string, number> = {};\n        for (const k of ref.current) {\n          const cut = k.indexOf(\"|\");\n          const wt = k.slice(0, cut);\n          const s = k.slice(cut + 1);\n          if (ctx) ctx.font = `${wt} 100px \"${albert.fontFamily}\"`;\n          w[k] = ctx ? ctx.measureText(s).width / 100 : s.length * 0.5;\n        }\n        setState({ key, w });\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.w : null;\n}\n\nexport function FreeAsIn({\n  word = \"Free\",\n  glosses = DEFAULT_GLOSSES,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: FreeAsInProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, durationInFrames } = useVideoConfig();\n  const T = durationInFrames * speed;\n  const c = THEMES[theme];\n  const hi = accent ?? c.accent;\n  const stage =\n    background === \"transparent\" ? \"transparent\" : (background ?? c.bg);\n\n  const list = glosses.filter((s) => s.trim().length > 0);\n  const keys = [`500|${word}`, ...list.map((s) => `400|${s}`)];\n  const w = useWidths(keys);\n\n  if (!w) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const adv = (wt: number, s: string, track: number) =>\n    (w[`${wt}|${s}`] ?? 0) + track * Array.from(s).length;\n\n  const portrait = H > W * 1.1;\n  const n = list.length;\n  const left = W * (portrait ? 0.08 : 0.07);\n  const wordEm = Math.max(0.01, adv(500, word, TRACK_WORD));\n  const glossEm = Math.max(0.01, ...list.map((s) => adv(400, s, TRACK_GLOSS)));\n\n  let Fw: number;\n  let Fg: number;\n  let gx: number;\n  let slotY: number;\n  if (portrait) {\n    Fw = Math.min(H * 0.2, (W * 0.84) / wordEm);\n    Fg = Math.min(Fw * 0.3, (W * 0.84) / glossEm);\n    gx = left;\n    slotY = H * 0.5 + Fw * 0.15 + Fg * 1.5;\n  } else {\n    const capW = Math.min(H * 0.46, (W * 0.52) / wordEm);\n    Fw = Math.max(\n      Math.min(H * 0.28, capW),\n      Math.min(capW, (W * 0.87) / (wordEm + 0.13 + glossEm * 0.17)),\n    );\n    gx = left + wordEm * Fw + Fw * 0.13;\n    const avail = W - W * 0.06 - gx;\n    Fg = Math.min(Fw * 0.17, avail / glossEm);\n    slotY = H * 0.8;\n  }\n  const gLine = Fg * GLH;\n  const wordBase = portrait ? H * 0.5 + Fw * 0.15 : slotY;\n\n  const wordIn = interpolate(t, [0, 20], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const first = 22;\n  const tail = 46;\n  const step =\n    n > 0 ? Math.max(12, Math.min(30, (T - first - tail) / Math.max(1, n))) : 0;\n  const startOf = (k: number) => first + k * step;\n  const push = (k: number) =>\n    interpolate(t, [startOf(k), startOf(k) + 12], [0, 1], {\n      ...CLAMP,\n      easing: EASE_IO,\n    });\n\n  const glossNodes = list.map((s, k) => {\n    const enter = interpolate(\n      t,\n      [startOf(k) + (k > 0 ? 5 : 0), startOf(k) + (k > 0 ? 21 : 16)],\n      [0, 1],\n      {\n        ...CLAMP,\n        easing: EASE_OUT,\n      },\n    );\n    if (enter <= 0) return null;\n    let level = 0;\n    for (let j = k + 1; j < n; j++) level += push(j);\n    const last = k === n - 1;\n    const fade = interpolate(level, [0, 1, 3, 4], [1, 0.38, 0.38, 0], CLAMP);\n    if (fade <= 0) return null;\n    const y = portrait\n      ? slotY + level * gLine\n      : slotY - level * gLine + (1 - enter) * Fg * 0.7;\n    const dy = portrait ? (1 - enter) * Fg * 0.7 : 0;\n    return (\n      <text\n        key={`g${k}`}\n        x={gx}\n        y={y + dy}\n        fontSize={Fg}\n        fontWeight={400}\n        letterSpacing={`${TRACK_GLOSS}em`}\n        fill={last ? hi : c.ink}\n        opacity={enter * fade}\n      >\n        {s}\n      </text>\n    );\n  });\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      <svg\n        width={W}\n        height={H}\n        viewBox={`0 0 ${W} ${H}`}\n        style={{ position: \"absolute\", inset: 0 }}\n        fontFamily={albert.fontFamily}\n        aria-hidden\n      >\n        <text\n          x={left - Fw * 0.04}\n          y={wordBase}\n          fontSize={Fw}\n          fontWeight={500}\n          letterSpacing={`${TRACK_WORD}em`}\n          fill={c.ink}\n          opacity={wordIn}\n          transform={`translate(0 ${((1 - wordIn) * Fw * 0.12).toFixed(2)})`}\n        >\n          {word}\n        </text>\n        {glossNodes}\n      </svg>\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/free-as-in.tsx"
    }
  ],
  "type": "registry:component"
}
