{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "known-terms",
  "title": "Known Terms",
  "description": "Definitions, \"A scene is a component ...\", build to a green \"Your launch is a deploy.\".",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/known-terms/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Epilogue\";\nimport type React from \"react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  interpolateColors,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst epilogue = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface KnownTermsPair {\n  video: string;\n  dev: string;\n  joiner?: string;\n}\n\nexport interface KnownTermsProps {\n  pairs?: KnownTermsPair[];\n  joiner?: string;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: { bg: \"#111418\", ink: \"#FFFFFF\", accent: \"#5CF2B5\" },\n  light: { bg: \"#F4F6F5\", ink: \"#111418\", accent: \"#12A06B\" },\n} as const;\n\nconst DEFAULT_PAIRS: KnownTermsPair[] = [\n  { video: \"A scene\", dev: \"a component.\" },\n  { video: \"Timing\", dev: \"a prop.\" },\n  { video: \"An edit\", dev: \"a commit.\" },\n  { video: \"A render\", dev: \"a build.\" },\n  { video: \"Your launch\", dev: \"a deploy.\" },\n];\n\nconst WGHT = 500;\nconst JOIN_WGHT = 400;\nconst TRACK = -0.03;\nconst FONT_PX = 200;\nconst LH = 1.22;\nconst INNER = 1.04;\nconst WRAP_COST = 0.1;\nconst GAP_EM = 0.34;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_MOVE = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst STEP = 14;\nconst LEAD = 3;\nconst ARRIVE = 10;\nconst ALONE = 6;\nconst SLIDE = 14;\nconst PUSH_DELAY = 1;\nconst PUSH = 14;\nconst JOIN_IN = 8;\nconst SETTLE = 12;\nconst LINE_LEN = LEAD + ARRIVE + ALONE + SLIDE;\nconst HOLD = 33;\nconst DIM = 0.46;\nconst JOIN_DIM = 0.4;\n\ntype Metrics = Record<string, number>;\n\nconst wKey = (weight: number, s: string) => `${weight}\\u0002${s}`;\n\nfunction measureAll(texts: string[]): Metrics {\n  const canvas = document.createElement(\"canvas\");\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) throw new Error(\"known-terms: no 2d context\");\n  const w: Metrics = {};\n  for (const weight of [WGHT, JOIN_WGHT]) {\n    ctx.font = `${weight} ${FONT_PX}px \"${epilogue.fontFamily}\"`;\n    for (const s of texts) {\n      w[wKey(weight, s)] =\n        ctx.measureText(s).width / FONT_PX + TRACK * Array.from(s).length;\n    }\n  }\n  return w;\n}\n\nfunction useMetrics(texts: string[]) {\n  const key = texts.join(\"\\u0001\");\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"known-terms: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      epilogue.waitUntilDone(),\n      document.fonts.load(`${WGHT} 100px \"${epilogue.fontFamily}\"`),\n      document.fonts.load(`${JOIN_WGHT} 100px \"${epilogue.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setState({ key, m: measureAll(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\nconst splitWords = (s: string) => s.split(\" \").filter(Boolean);\n\nfunction breakBalanced(\n  words: string[],\n  L: number,\n  widthOf: (line: string[]) => number,\n): string[][] {\n  const n = words.length;\n  const lines = Math.max(1, Math.min(L, n));\n  if (lines === 1) return [words];\n  let best: string[][] = [words];\n  let bestW = Number.POSITIVE_INFINITY;\n  const walk = (from: number, left: number, acc: string[][]) => {\n    if (left === 1) {\n      const all = [...acc, words.slice(from)];\n      const w = Math.max(...all.map(widthOf));\n      if (w < bestW) {\n        bestW = w;\n        best = all;\n      }\n      return;\n    }\n    for (let cut = from + 1; cut <= n - left + 1; cut++) {\n      walk(cut, left - 1, [...acc, words.slice(from, cut)]);\n    }\n  };\n  walk(0, lines, []);\n  return best;\n}\n\ninterface Wrap {\n  lines: string[][];\n  w: number;\n}\n\ninterface Layout {\n  score: number;\n  F: number;\n  vs: Wrap[];\n  ds: Wrap[];\n  maxL: number;\n  rowsEm: number[];\n  blockW: number;\n}\n\nexport function KnownTerms({\n  pairs = DEFAULT_PAIRS,\n  joiner = \"is\",\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: KnownTermsProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, durationInFrames } = useVideoConfig();\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 = pairs.length > 0 ? pairs : DEFAULT_PAIRS;\n  const joins = list.map((p) => p.joiner ?? joiner);\n  const m = useMetrics([\n    \" \",\n    ...list.flatMap((p) => [...splitWords(p.video), ...splitWords(p.dev)]),\n    ...joins,\n  ]);\n\n  if (!m) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const n = list.length;\n  const span = durationInFrames * speed;\n  const period =\n    n > 1 ? Math.min(40, Math.max(24, (span - LINE_LEN - HOLD) / (n - 1))) : 0;\n  const starts = list.map((_, k) => k * period);\n\n  const portrait = H > W * 1.1;\n  const marginX = W * (portrait ? 0.08 : 0.07);\n  const measureW = W - marginX * 2;\n  const space = m[wKey(WGHT, \" \")];\n  const lineW = (line: string[]) =>\n    line.reduce((a, w, i) => a + m[wKey(WGHT, w)] + (i > 0 ? space : 0), 0);\n  const options = (text: string): Wrap[] => {\n    const words = splitWords(text);\n    return [1, 2, 3]\n      .filter((L) => L <= Math.max(1, words.length))\n      .map((L) => {\n        const lines = breakBalanced(words, L, lineW);\n        return { lines, w: Math.max(0.1, ...lines.map(lineW)) };\n      });\n  };\n  const vOpts = list.map((p) => options(p.video));\n  const dOpts = list.map((p) => options(p.dev));\n  const joinW = joins.map((j) => m[wKey(JOIN_WGHT, j)]);\n  const maxJ = Math.max(0, ...joinW);\n  const fit = (opts: Wrap[], lim: number) =>\n    opts.find((o) => o.w <= lim + 1e-6) ?? opts[opts.length - 1];\n  const limits = (all: Wrap[][]) =>\n    [...new Set(all.flat().map((o) => Math.round(o.w * 1000) / 1000))].sort(\n      (a, b) => b - a,\n    );\n  const cap = H * (portrait ? 0.075 : 0.13);\n  const availH = H * (portrait ? 0.62 : 0.8);\n  let best: Layout | null = null;\n  for (const limL of limits(vOpts)) {\n    for (const limR of limits(dOpts)) {\n      const vs = vOpts.map((o) => fit(o, limL));\n      const ds = dOpts.map((o) => fit(o, limR));\n      const maxL = Math.max(...vs.map((v) => v.w));\n      const maxR = Math.max(...ds.map((d) => d.w));\n      const rowsEm = vs.map(\n        (v, k) =>\n          (Math.max(v.lines.length, ds[k].lines.length) - 1) * INNER + LH,\n      );\n      const blockW = maxL + GAP_EM * 2 + maxJ + maxR;\n      const size = Math.min(\n        cap,\n        measureW / blockW,\n        availH / rowsEm.reduce((a, r) => a + r, 0),\n      );\n      const extra = [...vs, ...ds].reduce((a, o) => a + o.lines.length - 1, 0);\n      const score = size / (1 + WRAP_COST * extra);\n      if (!best || score > best.score) {\n        best = { score, F: size, vs, ds, maxL, rowsEm, blockW };\n      }\n    }\n  }\n  if (!best) return null;\n  const { F, vs, ds, maxL, rowsEm, blockW } = best;\n\n  const blockLeft = (W - blockW * F) / 2;\n  const gutterL = blockLeft + maxL * F;\n  const joinMid = gutterL + (GAP_EM + maxJ / 2) * F;\n  const devX = gutterL + (GAP_EM * 2 + maxJ) * F;\n  const pitch = INNER * F;\n\n  const ease = (from: number, dur: number, curve = EASE_OUT) =>\n    interpolate(t, [from, from + dur], [0, 1], { ...CLAMP, easing: curve });\n\n  let visible = rowsEm[0] * F;\n  for (let k = 1; k < n; k++) {\n    visible += ease(starts[k], STEP, EASE_MOVE) * rowsEm[k] * F;\n  }\n  const rowTops: number[] = [];\n  let acc = H / 2 - visible / 2;\n  for (let k = 0; k < n; k++) {\n    rowTops.push(acc);\n    acc += rowsEm[k] * F;\n  }\n\n  const textStyle = (weight: number): React.CSSProperties => ({\n    position: \"absolute\",\n    left: 0,\n    top: 0,\n    height: F,\n    lineHeight: `${F}px`,\n    whiteSpace: \"pre\",\n    fontFamily: epilogue.fontFamily,\n    fontWeight: weight,\n    fontSize: F,\n    letterSpacing: `${TRACK}em`,\n  });\n\n  const nodes: React.ReactNode[] = [];\n\n  for (let k = 0; k < n; k++) {\n    const s = starts[k] + (k > 0 ? LEAD : 0);\n    if (t < s - 1) continue;\n    const last = k === n - 1;\n    const top = rowTops[k] + ((LH - 1) * F) / 2;\n    const arrive = ease(s, ARRIVE);\n    const slideAt = s + ARRIVE + ALONE;\n    const slide = ease(slideAt, SLIDE, EASE_MOVE);\n    const push = ease(slideAt + PUSH_DELAY, PUSH);\n    const joinIn = ease(slideAt + SLIDE * 0.72, JOIN_IN);\n    const settled = ease(slideAt + SLIDE, SETTLE);\n    const next = k + 1 < n ? ease(starts[k + 1], STEP + 6, EASE_MOVE) : 0;\n    const lead = last ? 1 : 1 - (1 - DIM) * next;\n\n    const v = vs[k];\n    const vw = v.w * F;\n    const vh = (v.lines.length - 1) * pitch + F;\n    const vx0 = (W - vw) / 2;\n    const vx1 = gutterL - vw;\n    const vx = vx0 + (vx1 - vx0) * slide;\n\n    const termColor = last\n      ? interpolateColors(settled, [0, 1], [c.ink, hi])\n      : c.ink;\n\n    nodes.push(\n      <div\n        key={`v${k}`}\n        style={{\n          position: \"absolute\",\n          left: vx - F * 0.06,\n          top: top - F * 0.16,\n          width: vw + F * 0.2,\n          height: vh + F * 0.36,\n          overflow: \"hidden\",\n          opacity: lead,\n        }}\n      >\n        {v.lines.map((line, i) => (\n          <div\n            key={line.join(\" \")}\n            style={{\n              ...textStyle(WGHT),\n              left: F * 0.06 + vw - lineW(line) * F,\n              top: F * 0.26 + i * pitch,\n              color: termColor,\n              transform: `translateY(${((1 - arrive) * (vh + F * 0.3)).toFixed(2)}px)`,\n            }}\n          >\n            {line.join(\" \")}\n          </div>\n        ))}\n      </div>,\n    );\n\n    if (t < slideAt + PUSH_DELAY - 1) continue;\n\n    const dx0 = W + F * 0.4;\n    const pushed = dx0 + (devX - dx0) * push;\n    const contact = vx + vw + (GAP_EM * 2 + maxJ) * F * 0.7;\n    const dx = Math.max(pushed, contact);\n    ds[k].lines.forEach((line, i) => {\n      nodes.push(\n        <div\n          key={`d${k}-${line.join(\" \")}`}\n          style={{\n            ...textStyle(WGHT),\n            top: top + F * 0.1 + i * pitch,\n            color: termColor,\n            opacity: lead,\n            transform: `translateX(${dx.toFixed(2)}px)`,\n          }}\n        >\n          {line.join(\" \")}\n        </div>,\n      );\n    });\n\n    if (joinIn <= 0) continue;\n    const jw = joinW[k] * F;\n    nodes.push(\n      <div\n        key={`j${k}`}\n        style={{\n          ...textStyle(JOIN_WGHT),\n          top: top + F * 0.1,\n          color: c.ink,\n          opacity: joinIn * JOIN_DIM * (0.6 + 0.4 * lead),\n          transform: `translate(${(joinMid - jw / 2).toFixed(2)}px, ${((1 - joinIn) * F * 0.35).toFixed(2)}px)`,\n        }}\n      >\n        {joins[k]}\n      </div>,\n    );\n  }\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {nodes}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/known-terms.tsx"
    }
  ],
  "type": "registry:component"
}
