{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "said-who",
  "title": "Said Who",
  "description": "A big serif pull quote, \"Took me one evening.\", with a backend-engineer attribution.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/said-who/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/YoungSerif\";\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 serif = loadFont(\"normal\", { weights: [\"400\"], subsets: [\"latin\"] });\n\nexport interface SaidWhoProps {\n  quote?: string;\n  highlight?: string;\n  name?: string;\n  details?: string[];\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: { bg: \"#101828\", ink: \"#BFE3FF\", accent: \"#F6C453\" },\n  light: { bg: \"#CFE8FF\", ink: \"#101828\", accent: \"#A66E00\" },\n} as const;\n\nconst TRACK = -0.02;\nconst LH = 1.1;\nconst STEP_SCALE = 0.035;\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\ninterface Tok {\n  text: string;\n  attach: boolean;\n  hot?: boolean;\n}\n\nfunction stripQuotes(s: string) {\n  return s\n    .trim()\n    .replace(/^[\"“”]+/, \"\")\n    .replace(/[\"“”]+$/, \"\");\n}\n\nfunction quoteTokens(quote: string, highlight: string): Tok[] {\n  const body = stripQuotes(quote);\n  const at = highlight ? body.indexOf(highlight) : -1;\n  const out: Tok[] = [];\n  const words = body.split(\" \").filter(Boolean);\n  let cursor = 0;\n  words.forEach((word, i) => {\n    const s = body.indexOf(word, cursor);\n    const e = s + word.length;\n    cursor = e;\n    const hot = at >= 0 && s < at + highlight.length && e > at;\n    let text = word;\n    if (i === 0) text = `“${text}`;\n    if (i === words.length - 1) text = `${text}”`;\n    out.push({ text, attach: false, hot });\n  });\n  return out;\n}\n\nfunction wordTokens(s: string): Tok[] {\n  return s\n    .split(/\\s+/)\n    .filter(Boolean)\n    .map((text) => ({ text, attach: false }));\n}\n\nfunction place(\n  toks: Tok[],\n  adv: (s: string) => number,\n  space: number,\n  maxEm: number,\n) {\n  const pos: { x: number; line: number }[] = [];\n  const widths: number[] = [0];\n  let line = 0;\n  let x = 0;\n  toks.forEach((tk) => {\n    const w = adv(tk.text);\n    const gap = tk.attach || x === 0 ? 0 : space;\n    if (!tk.attach && x > 0 && x + gap + w > maxEm) {\n      line++;\n      widths.push(0);\n      pos.push({ x: 0, line });\n      x = w;\n    } else {\n      pos.push({ x: x + gap, line });\n      x += gap + w;\n    }\n    widths[line] = x;\n  });\n  return { pos, lines: line + 1, widths };\n}\n\nfunction wrap(\n  toks: Tok[],\n  adv: (s: string) => number,\n  space: number,\n  maxEm: number,\n) {\n  const greedy = place(toks, adv, space, maxEm);\n  const L = greedy.lines;\n  if (L <= 1) return greedy;\n  const n = toks.length;\n  const ws = toks.map((tk) => adv(tk.text));\n  const glued = (k: number) => toks[k].attach;\n  const lineW = (i: number, j: number) => {\n    let x = 0;\n    for (let k = i; k < j; k++) x += (k === i || glued(k) ? 0 : space) + ws[k];\n    return x;\n  };\n  const avg = lineW(0, n) / L;\n  const INF = 1e12;\n  const dp = Array.from({ length: L + 1 }, () =>\n    new Array<number>(n + 1).fill(INF),\n  );\n  const back = Array.from({ length: L + 1 }, () =>\n    new Array<number>(n + 1).fill(0),\n  );\n  dp[0][0] = 0;\n  for (let l = 1; l <= L; l++) {\n    for (let j = 1; j <= n; j++) {\n      if (j < n && glued(j)) continue;\n      for (let i = l - 1; i < j; i++) {\n        if (dp[l - 1][i] >= INF) continue;\n        const lw = lineW(i, j);\n        if (lw > maxEm + 1e-6) continue;\n        let cost = (lw - avg) ** 2;\n        if (j < n) {\n          const end = toks[j - 1].text;\n          if (/[.?!…][\"”’]?$/.test(end)) cost -= avg * avg * 0.5;\n          else if (/[,;:—–][\"”’]?$/.test(end)) cost -= avg * avg * 0.15;\n        }\n        if (dp[l - 1][i] + cost < dp[l][j]) {\n          dp[l][j] = dp[l - 1][i] + cost;\n          back[l][j] = i;\n        }\n      }\n    }\n  }\n  if (dp[L][n] >= INF) return greedy;\n  const starts: number[] = [];\n  let j = n;\n  for (let l = L; l > 0; l--) {\n    const i = back[l][j];\n    starts.unshift(i);\n    j = i;\n  }\n  const pos: { x: number; line: number }[] = [];\n  const widths: number[] = [];\n  starts.forEach((s, l) => {\n    const e = l + 1 < starts.length ? starts[l + 1] : n;\n    let x = 0;\n    for (let k = s; k < e; k++) {\n      const gap = k === s || glued(k) ? 0 : space;\n      pos.push({ x: x + gap, line: l });\n      x += gap + ws[k];\n    }\n    widths.push(x);\n  });\n  return { pos, lines: L, widths };\n}\n\nfunction useWidths(strings: string[]) {\n  const key = strings.join(\"\\u0001\");\n  const [state, setState] = useState<{\n    key: string;\n    w: Record<string, number>;\n  } | null>(null);\n  const [handle] = useState(() => delayRender(\"said-who: measuring\"));\n  const released = useRef(false);\n  const ref = useRef(strings);\n  ref.current = strings;\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      serif.waitUntilDone(),\n      document.fonts.load(`400 100px \"${serif.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        if (ctx) ctx.font = `400 100px \"${serif.fontFamily}\"`;\n        for (const s of ref.current) {\n          w[s] = 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 SaidWho({\n  quote = \"Took me one evening.\",\n  highlight = \"one evening\",\n  name = \"Tobias Lind\",\n  details = [\"backend engineer\", \"never edited a video before\"],\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: SaidWhoProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, durationInFrames: T } = 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 qToks = quoteTokens(quote, highlight);\n  const nameToks: Tok[] = [{ text: \"—\", attach: false }, ...wordTokens(name)];\n  const groups: Tok[][] = [nameToks];\n  for (const d of details) {\n    const words = wordTokens(d);\n    if (words.length === 0) continue;\n    groups.push(words);\n  }\n  const attrToks: Tok[] = [];\n  const groupOf: number[] = [];\n  groups.forEach((g, k) => {\n    g.forEach((tk, i) => {\n      attrToks.push(tk);\n      groupOf.push(k);\n      const last = i === g.length - 1;\n      if (last && k < groups.length - 1) {\n        attrToks.push({ text: \",\", attach: true });\n        groupOf.push(k + 1);\n      }\n    });\n  });\n  const m = groups.length - 1;\n  const stateLen = (k: number) => {\n    let n = 0;\n    while (n < groupOf.length && groupOf[n] <= k) n++;\n    return n;\n  };\n  const visibleLen = (k: number) => {\n    const n = stateLen(k);\n    return k < m && attrToks[n - 1]?.text === \",\" ? n - 1 : n;\n  };\n\n  const strings = Array.from(\n    new Set([\n      \" \",\n      ...qToks.map((tk) => tk.text),\n      ...attrToks.map((tk) => tk.text),\n    ]),\n  );\n  const w = useWidths(strings);\n\n  if (!w) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const adv = (s: string) => (w[s] ?? 0) + TRACK * Array.from(s).length;\n  const space = w[\" \"] ?? 0.25;\n\n  const portrait = H > W * 1.1;\n  const unit = Math.min(W, H);\n  const measure = W * (portrait ? 0.84 : 0.8);\n  const maxScale = 1 + STEP_SCALE * m;\n\n  let Fq = portrait ? W * 0.15 : H * 0.17;\n  let qLay = wrap(qToks, adv, space, measure / maxScale / Fq);\n  for (let k = 0; k < 60; k++) {\n    if (\n      qLay.lines <= (portrait ? 4 : 2) &&\n      qLay.lines * LH * Fq * maxScale <= H * 0.46\n    )\n      break;\n    Fq *= 0.96;\n    qLay = wrap(qToks, adv, space, measure / maxScale / Fq);\n  }\n\n  let Fa = Math.max(16, unit * 0.058);\n  const attrLay = (k: number, size: number) =>\n    wrap(attrToks.slice(0, visibleLen(k)), adv, space, measure / size);\n  for (let k = 0; k < 60; k++) {\n    if (attrLay(m, Fa).lines <= (portrait ? 3 : 2) || Fa <= 16) break;\n    Fa *= 0.96;\n  }\n  const aLays = Array.from({ length: m + 1 }, (_, k) => attrLay(k, Fa));\n\n  const intro = 34;\n  const tail = Math.max(36, T * 0.25);\n  const gapC = m > 0 ? Math.max(20, (T - tail - intro) / m) : 1;\n  const TR = Math.min(20, gapC * 0.6);\n  const startOf = (k: number) => intro + gapC * k - TR;\n\n  let cur = 0;\n  for (let k = 1; k <= m; k++) if (t >= startOf(k)) cur = k;\n  const lt = cur > 0 ? t - startOf(cur) : 0;\n  const glide =\n    cur > 0\n      ? interpolate(lt, [0, TR], [0, 1], { ...CLAMP, easing: EASE_IO })\n      : 1;\n  const from = cur > 0 ? cur - 1 : 0;\n\n  const qLineH = LH * Fq;\n  const aLineH = LH * Fa;\n  const gapQA = Fq * 0.62;\n  const qH = qLay.lines * qLineH;\n  const scaleOf = (k: number) => 1 + STEP_SCALE * k;\n  const scale = scaleOf(from) + (scaleOf(cur) - scaleOf(from)) * glide;\n  const aH = (k: number) => aLays[k].lines * aLineH;\n  const attrH = aH(from) + (aH(cur) - aH(from)) * glide;\n  const blockH = qH * scale + gapQA + attrH;\n  const blockTop = H / 2 - blockH / 2;\n  const qTop = blockTop + (qH * scale - qH) / 2;\n  const aTop = blockTop + qH * scale + gapQA;\n\n  const hotAt = m > 0 ? startOf(m) + TR * 0.7 : intro;\n  const hot = interpolate(t, [hotAt, hotAt + 16], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n\n  const quoteNodes = qToks.map((tk, i) => {\n    const p = qLay.pos[i];\n    const lineW = qLay.widths[p.line];\n    const x = W / 2 + (p.x - lineW / 2) * Fq;\n    const y = qTop + p.line * qLineH;\n    const e = interpolate(t, [2 + i * 3, 20 + i * 3], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n    return (\n      <div\n        key={`q${i}`}\n        style={{\n          position: \"absolute\",\n          left: x,\n          top: y,\n          height: qLineH,\n          lineHeight: `${qLineH}px`,\n          fontSize: Fq,\n          whiteSpace: \"pre\",\n          letterSpacing: `${TRACK}em`,\n          color: tk.hot ? interpolateColors(hot, [0, 1], [c.ink, hi]) : c.ink,\n          opacity: e,\n          transform: `translateY(${((1 - e) * Fq * 0.3).toFixed(2)}px)`,\n        }}\n      >\n        {tk.text}\n      </div>\n    );\n  });\n\n  const aXY = (k: number, i: number) => {\n    const p = aLays[k].pos[i];\n    const lineW = aLays[k].widths[p.line];\n    return {\n      x: W / 2 + (p.x - lineW / 2) * Fa,\n      y: p.line * aLineH,\n    };\n  };\n\n  const nameIn = interpolate(t, [18, 34], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const attrNodes: React.ReactNode[] = [];\n  const nTo = visibleLen(cur);\n  const nFrom = visibleLen(from);\n  const placed: { x: number; y: number }[] = [];\n  for (let i = 0; i < nTo; i++) {\n    const tk = attrToks[i];\n    const b = aXY(cur, i);\n    let x = b.x;\n    let y = b.y;\n    let opacity = nameIn;\n    let dy = (1 - nameIn) * Fa * 0.5;\n    if (i < nFrom) {\n      const a = aXY(from, i);\n      x = a.x + (b.x - a.x) * glide;\n      y = a.y + (b.y - a.y) * glide;\n      placed.push({ x, y });\n    } else if (tk.attach && i > 0) {\n      const prev = placed[i - 1];\n      x = prev.x + adv(attrToks[i - 1].text) * Fa;\n      y = prev.y;\n      placed.push({ x, y });\n      opacity = interpolate(lt, [TR * 0.4, TR * 0.4 + 10], [0, 1], CLAMP);\n      dy = 0;\n    } else {\n      placed.push({ x, y });\n      const order = i - nFrom;\n      const s = TR * 0.55 + order * 2;\n      const v = interpolate(lt, [s, s + 16], [0, 1], {\n        ...CLAMP,\n        easing: EASE_OUT,\n      });\n      opacity = v;\n      dy = (1 - v) * Fa * 0.6;\n    }\n    const strong = groupOf[i] === m && m > 0 && tk.text !== \",\";\n    attrNodes.push(\n      <div\n        key={`a${i}`}\n        style={{\n          position: \"absolute\",\n          left: x,\n          top: y,\n          height: aLineH,\n          lineHeight: `${aLineH}px`,\n          fontSize: Fa,\n          whiteSpace: \"pre\",\n          letterSpacing: \"-0.005em\",\n          color: c.ink,\n          opacity: opacity * (strong ? 1 : 0.7),\n          transform: `translateY(${dy.toFixed(2)}px)`,\n        }}\n      >\n        {tk.text}\n      </div>,\n    );\n  }\n\n  return (\n    <AbsoluteFill\n      style={{\n        background: stage,\n        overflow: \"hidden\",\n        fontFamily: serif.fontFamily,\n        fontWeight: 400,\n      }}\n    >\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          transform: `scale(${scale.toFixed(4)})`,\n          transformOrigin: `${W / 2}px ${(qTop + qH / 2).toFixed(2)}px`,\n        }}\n      >\n        {quoteNodes}\n      </div>\n      <div style={{ position: \"absolute\", left: 0, right: 0, top: aTop }}>\n        {attrNodes}\n      </div>\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/said-who.tsx"
    }
  ],
  "type": "registry:component"
}
