{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "edge-fit",
  "title": "Edge Fit",
  "description": "A single huge cream word, 'recaps', fills the frame edge to edge with a caption and logo.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/edge-fit/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadAnton } from \"@remotion/google-fonts/Anton\";\nimport { loadFont as loadManrope } from \"@remotion/google-fonts/Manrope\";\nimport type React from \"react\";\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 anton = loadAnton(\"normal\", { weights: [\"400\"], subsets: [\"latin\"] });\nconst manrope = loadManrope(\"normal\", {\n  weights: [\"500\", \"600\"],\n  subsets: [\"latin\"],\n});\n\nexport interface EdgeFitProps {\n  words?: string[];\n  caption?: string;\n  logo?: React.ReactNode | null;\n  letterGap?: number;\n  hold?: number;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst REMOCN_R_PATH =\n  \"M 0.01 0.81 C 0.01 1.73, 0.36 2.79, 1.09 4.13 C 4.91 11.04, 13.45 17.16, 21.7 18.9 C 22.94 19.16, 23.18 19.16, 51.39 19.27 C 76.07 19.36, 80.02 19.4, 81.32 19.57 C 89.89 20.69, 96.2 24.68, 99.38 31.01 C 103.19 38.56, 102.53 50.1, 97.91 57.07 C 94.66 61.96, 89.68 64.99, 83.26 66 C 82.81 66.07, 70.18 66.83, 55.2 67.69 C 24.82 69.43, 27.03 69.23, 24.18 70.4 C 19.9 72.15, 14.84 75.7, 10.65 79.89 C 4.86 85.68, 1.3 91.91, 0.25 98.13 C 0.12 98.85, 0.08 103.13, 0.04 116.66 L 0 134.26 9.5 134.26 L 19 134.26 19.05 119.41 C 19.1 103.27, 19.08 103.82, 19.82 101.04 C 21.79 93.65, 27.86 88.75, 36.45 87.63 C 37.23 87.53, 39.41 87.5, 43.57 87.53 C 50.12 87.59, 50.75 87.65, 53.22 88.45 C 56.61 89.56, 59.67 91.86, 62.02 95.07 C 62.52 95.76, 69.35 103.85, 77.2 113.07 C 85.04 122.28, 91.63 130.04, 91.85 130.32 C 92.07 130.59, 92.5 131.34, 92.82 131.97 C 93.52 133.35, 94.11 133.93, 95.06 134.13 C 95.5 134.23, 98.97 134.26, 106.36 134.23 L 117.01 134.19 100.82 113.07 C 91.91 101.45, 84.52 91.78, 84.39 91.57 C 83.36 89.89, 83.66 87.53, 85.09 86 C 85.79 85.25, 86.36 84.94, 88.07 84.38 C 96.18 81.72, 104.15 76.62, 109.97 70.36 C 120.59 58.93, 124.06 44.32, 119.44 30.43 C 114.59 15.81, 101.93 4.02, 87.64 0.83 C 83.93 0.01, 88.09 0.08, 41.85 0.04 L 0.01 0 0.01 0.81 Z\";\n\nfunction RemocnLogo({ fontSize, color }: { fontSize: number; color: string }) {\n  return (\n    <div\n      style={{\n        display: \"flex\",\n        alignItems: \"baseline\",\n        color,\n        fontFamily: manrope.fontFamily,\n        fontWeight: 600,\n        fontSize,\n        letterSpacing: \"-0.025em\",\n        lineHeight: 1,\n      }}\n    >\n      <svg\n        viewBox=\"0 0 124.06 134.26\"\n        style={{ height: \"0.76em\", width: \"auto\" }}\n        aria-hidden\n      >\n        <path fill=\"currentColor\" d={REMOCN_R_PATH} />\n      </svg>\n      <span style={{ marginLeft: \"0.04em\" }}>emocn</span>\n    </div>\n  );\n}\n\nconst THEMES = {\n  dark: {\n    bg: \"#1B2A6B\",\n    ink: \"#F3E9D2\",\n  },\n  light: {\n    bg: \"#F3E9D2\",\n    ink: \"#1B2A6B\",\n  },\n} as const;\n\nconst TRACK = -0.005;\nconst FONT_PX = 200;\nconst RISE = 6;\nconst LEAD = 3;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\ninterface WordMetrics {\n  chars: string[];\n  adv: number[];\n  inkTop: number;\n  inkBottom: number;\n  inkLeft: number[];\n  inkRight: number[];\n}\n\ninterface Metrics {\n  words: WordMetrics[];\n  baseline: number;\n}\n\nfunction measure(words: string[]): 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: `\"${anton.fontFamily}\"`,\n    fontWeight: \"400\",\n    fontSize: `${FONT_PX}px`,\n    lineHeight: \"1\",\n    letterSpacing: `${TRACK}em`,\n  });\n  document.body.appendChild(probe);\n  const width = (s: string) => {\n    probe.textContent = s;\n    return probe.getBoundingClientRect().width / FONT_PX;\n  };\n  const canvas = document.createElement(\"canvas\");\n  canvas.width = 10;\n  canvas.height = 10;\n  const ctx = canvas.getContext(\"2d\");\n  if (ctx) {\n    ctx.font = `400 ${FONT_PX}px \"${anton.fontFamily}\"`;\n    ctx.letterSpacing = `${TRACK * FONT_PX}px`;\n  }\n\n  const out: WordMetrics[] = words.map((word) => {\n    const chars = Array.from(word);\n    const adv: number[] = [];\n    const inkLeft: number[] = [];\n    const inkRight: number[] = [];\n    let prev = 0;\n    for (let i = 0; i < chars.length; i++) {\n      const x = width(chars.slice(0, i + 1).join(\"\"));\n      adv.push(x - prev);\n      prev = x;\n      const pm = ctx?.measureText(chars.slice(0, i + 1).join(\"\"));\n      inkLeft.push(pm ? pm.actualBoundingBoxLeft / FONT_PX : 0);\n      inkRight.push(pm ? pm.actualBoundingBoxRight / FONT_PX : x);\n    }\n    const wm = ctx?.measureText(word);\n    return {\n      chars,\n      adv,\n      inkTop: wm ? wm.actualBoundingBoxAscent / FONT_PX : 0.75,\n      inkBottom: wm ? wm.actualBoundingBoxDescent / FONT_PX : 0.2,\n      inkLeft,\n      inkRight,\n    };\n  });\n  probe.remove();\n\n  let baseline = 0.8;\n  if (ctx) {\n    const fm = ctx.measureText(\"Hg\");\n    const asc = fm.fontBoundingBoxAscent / FONT_PX;\n    const desc = fm.fontBoundingBoxDescent / FONT_PX;\n    baseline = (1 - (asc + desc)) / 2 + asc;\n  }\n  return { words: out, baseline };\n}\n\nfunction useMetrics(words: string[]) {\n  const key = words.join(\"\\u0001\");\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"edge-fit: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      anton.waitUntilDone(),\n      manrope.waitUntilDone(),\n      document.fonts.load(`400 100px \"${anton.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setState({ key, m: measure(key.split(\"\\u0001\")) });\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\nexport function edgeFitTiming(words: string[], letterGap = 3, hold = 14) {\n  const starts: number[] = [];\n  let at = 0;\n  for (const w of words) {\n    starts.push(at);\n    at += Math.max(1, Array.from(w).length - 1) * letterGap + 10 + hold;\n  }\n  return { starts, end: at };\n}\n\nexport function EdgeFit({\n  words = [\"intros\", \"teasers\", \"recaps\"],\n  caption = \"Fresh from the registry\",\n  logo,\n  letterGap = 3,\n  hold = 14,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: EdgeFitProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, fps } = useVideoConfig();\n  const c = THEMES[theme];\n  const spot = accent ?? c.ink;\n  const list = useMemo(() => (words.length > 0 ? words : [\"remocn\"]), [words]);\n  const m = useMetrics(list);\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 s = portrait ? W / 1080 : Math.min(W / 1280, H / 720);\n  const { starts } = edgeFitTiming(list, letterGap, hold);\n  let wi = 0;\n  for (let i = 0; i < starts.length; i++) if (t >= starts[i]) wi = i;\n  const last = wi === list.length - 1;\n  const wm = m.words[wi];\n  const local = t - starts[wi];\n  const n = wm.chars.length;\n\n  const measureW = W * (portrait ? 0.9 : 0.9);\n  const maxInk = H * (portrait ? 0.3 : 0.66);\n  const inkH = wm.inkTop + wm.inkBottom;\n  const fitOf = (k: number) => {\n    const ink = wm.inkLeft[k - 1] + wm.inkRight[k - 1];\n    return Math.min(measureW / Math.max(0.05, ink), maxInk / inkH);\n  };\n  const arrive = (j: number) =>\n    j === 0\n      ? 1\n      : spring({\n          frame: local - j * letterGap + LEAD,\n          fps,\n          config: { damping: 19, stiffness: 260, mass: 0.6 },\n        });\n  let S = fitOf(1);\n  for (let k = 2; k <= n; k++) S += (fitOf(k) - fitOf(k - 1)) * arrive(k - 1);\n\n  const open = wm.adv.map((_, j) => Math.min(1.04, Math.max(0, arrive(j))));\n  let cursor = 0;\n  const xs: number[] = [];\n  for (let j = 0; j < n; j++) {\n    xs.push(cursor);\n    cursor += wm.adv[j] * open[j];\n  }\n  let shown = 1;\n  for (let j = 1; j < n; j++) if (open[j] > 0.001) shown = j + 1;\n  const kIn = Math.max(1, shown);\n  const blend = shown > 1 ? Math.min(1, open[shown - 1]) : 1;\n  const inkRightPrev = kIn > 1 ? wm.inkRight[kIn - 2] : wm.inkRight[0];\n  const inkRight = inkRightPrev + (wm.inkRight[kIn - 1] - inkRightPrev) * blend;\n  const inkW = (wm.inkLeft[0] + inkRight) * S;\n  const left = (W - inkW) / 2 + wm.inkLeft[0] * S;\n\n  const baseY = H / 2 + ((wm.inkTop - wm.inkBottom) / 2) * S;\n  const boxTop = baseY - m.baseline * S;\n  const maskTop = baseY - wm.inkTop * S - S * 0.04;\n  const maskH = inkH * S + S * 0.08;\n\n  const signAt = starts[list.length - 1] + Math.max(0, n - 1) * letterGap;\n  const sign = last\n    ? interpolate(t, [signAt, signAt + 16], [0, 1], {\n        ...CLAMP,\n        easing: EASE_OUT,\n      })\n    : 0;\n  const smallFs = (portrait ? 38 : 26) * s;\n  const margin = (portrait ? 64 : 48) * s;\n  const logoNode =\n    logo === null\n      ? null\n      : (logo ?? <RemocnLogo fontSize={smallFs * 1.25} color={c.ink} />);\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      <div\n        style={{\n          position: \"absolute\",\n          left: 0,\n          width: W,\n          top: maskTop,\n          height: maskH,\n        }}\n      >\n        {wm.chars.map((ch, j) => {\n          if (open[j] <= 0.001) return null;\n          const first = j === 0;\n          const rp = first\n            ? wi === 0\n              ? interpolate(local, [0, RISE + 2], [0, 1], {\n                  ...CLAMP,\n                  easing: EASE_OUT,\n                })\n              : 1\n            : interpolate(local - j * letterGap, [0, RISE], [0, 1], {\n                ...CLAMP,\n                easing: EASE_OUT,\n              });\n          const x = left + xs[j] * S;\n          return (\n            <div\n              key={`${wi}-${j}-${ch}`}\n              style={{\n                position: \"absolute\",\n                left: x,\n                top: boxTop - maskTop,\n                height: S,\n                lineHeight: `${S}px`,\n                whiteSpace: \"pre\",\n                fontFamily: anton.fontFamily,\n                fontWeight: 400,\n                fontSize: S,\n                opacity: interpolate(rp, [0, 0.55], [0, 1], CLAMP),\n                transform: `translateY(${((1 - rp) * S * 0.22).toFixed(2)}px)`,\n                color: spot,\n              }}\n            >\n              {ch}\n            </div>\n          );\n        })}\n      </div>\n\n      {sign > 0 ? (\n        <>\n          {caption ? (\n            <div\n              style={{\n                position: \"absolute\",\n                left: margin,\n                bottom: margin,\n                fontFamily: anton.fontFamily,\n                fontWeight: 400,\n                fontSize: smallFs,\n                letterSpacing: \"0.005em\",\n                lineHeight: 1,\n                color: c.ink,\n                opacity: sign,\n                transform: `translateY(${((1 - sign) * smallFs * 0.8).toFixed(2)}px)`,\n              }}\n            >\n              {caption}\n            </div>\n          ) : null}\n          {logoNode ? (\n            <div\n              style={{\n                position: \"absolute\",\n                right: margin,\n                bottom: margin,\n                opacity: sign,\n                transform: `translateY(${((1 - sign) * smallFs * 0.8).toFixed(2)}px)`,\n              }}\n            >\n              {logoNode}\n            </div>\n          ) : null}\n        </>\n      ) : null}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/edge-fit.tsx"
    }
  ],
  "type": "registry:component"
}
