{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "and-you",
  "title": "and You",
  "description": "A list of audiences (\"For the founder who...\") ends on a big \"and you.\".",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/and-you/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Gabarito\";\nimport type React from \"react\";\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 gabarito = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface AndYouProps {\n  clauses?: string[];\n  last?: string;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: { bg: \"#3B1E6E\", ink: \"#FFFFFF\", accent: \"#FF7A6B\" },\n  light: { bg: \"#EDE7FB\", ink: \"#3B1E6E\", accent: \"#D9483A\" },\n} as const;\n\nconst BODY_W = 400;\nconst LAST_W = 500;\nconst TRACK = -0.02;\nconst LAST_TRACK = -0.035;\nconst FONT_PX = 200;\nconst LH = 1.12;\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 Metrics {\n  body: (s: string) => number;\n  last: (s: string) => number;\n  asc: number;\n  desc: number;\n}\n\nfunction measure(): Metrics {\n  const canvas = document.createElement(\"canvas\");\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) throw new Error(\"and-you: no 2d context\");\n  const bodyCache: Record<string, number> = {};\n  const lastCache: Record<string, number> = {};\n  const em = (s: string, w: number, track: number) => {\n    ctx.font = `${w} ${FONT_PX}px \"${gabarito.fontFamily}\"`;\n    return ctx.measureText(s).width / FONT_PX + track * Array.from(s).length;\n  };\n  ctx.font = `${BODY_W} ${FONT_PX}px \"${gabarito.fontFamily}\"`;\n  const fm = ctx.measureText(\"Hxg\");\n  return {\n    body: (s) => {\n      if (bodyCache[s] === undefined) bodyCache[s] = em(s, BODY_W, TRACK);\n      return bodyCache[s];\n    },\n    last: (s) => {\n      if (lastCache[s] === undefined) lastCache[s] = em(s, LAST_W, LAST_TRACK);\n      return lastCache[s];\n    },\n    asc: fm.fontBoundingBoxAscent / FONT_PX,\n    desc: fm.fontBoundingBoxDescent / FONT_PX,\n  };\n}\n\nfunction useMetrics() {\n  const [m, setM] = useState<Metrics | null>(null);\n  const [handle] = useState(() => delayRender(\"and-you: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      gabarito.waitUntilDone(),\n      document.fonts.load(`${BODY_W} 100px \"${gabarito.fontFamily}\"`),\n      document.fonts.load(`${LAST_W} 100px \"${gabarito.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setM(measure());\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [handle]);\n  return m;\n}\n\ninterface Placed {\n  text: string;\n  clause: number;\n  order: number;\n  line: number;\n  x: number;\n}\n\nfunction flow(\n  clauses: string[],\n  room: number,\n  width: (s: string) => number,\n): { words: Placed[]; lastLine: number[] } {\n  const words: Placed[] = [];\n  const lastLine: number[] = [];\n  let line = 0;\n  let cur: string[] = [];\n  clauses.forEach((cl, ci) => {\n    const parts = cl.split(\" \").filter(Boolean);\n    parts.forEach((w, wi) => {\n      const prefix = cur.length > 0 ? `${cur.join(\" \")} ` : \"\";\n      if (cur.length > 0 && width(prefix + w) > room) {\n        line += 1;\n        cur = [];\n        words.push({ text: w, clause: ci, order: wi, line, x: 0 });\n      } else {\n        words.push({\n          text: w,\n          clause: ci,\n          order: wi,\n          line,\n          x: width(prefix),\n        });\n      }\n      cur.push(w);\n    });\n    lastLine.push(line);\n  });\n  return { words, lastLine };\n}\n\nexport function AndYou({\n  clauses = [\n    \"For the founder who launches on Monday,\",\n    \"the designer who just learned React,\",\n    \"the two-person studio,\",\n    \"the student with a weekend project,\",\n  ],\n  last = \"and you.\",\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: AndYouProps) {\n  const frame = useCurrentFrame();\n  const { width: W, height: H, durationInFrames } = useVideoConfig();\n  const t = frame * speed;\n  const D = Math.max(110, durationInFrames);\n  const c = THEMES[theme];\n  const hi = accent ?? c.accent;\n  const stage =\n    background === \"transparent\" ? \"transparent\" : (background ?? c.bg);\n  const list = clauses.length > 0 ? clauses : [\"For everyone who builds,\"];\n  const m = useMetrics();\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 portrait = H > W * 1.1;\n  const marginX = W * (portrait ? 0.08 : 0.065);\n  const marginY = H * (portrait ? 0.07 : 0.1);\n  const room = W - marginX * 2;\n  const F0 = portrait ? W * 0.12 : H * 0.15;\n  const { words, lastLine } = flow(list, room / F0, m.body);\n  const lineH = LH * F0;\n  const heightAt = (k: number) => (lastLine[k] + 1) * lineH;\n  const availH = H - marginY * 2;\n\n  const scrollAt = (k: number) => Math.max(0, heightAt(k) - availH);\n\n  const lastSplit = last.lastIndexOf(\" \");\n  const lastHead = lastSplit > 0 ? last.slice(0, lastSplit + 1) : \"\";\n  const lastTail = lastSplit > 0 ? last.slice(lastSplit + 1) : last;\n  const lastW = Math.max(0.1, m.last(last));\n  const FY = Math.min(\n    H * (portrait ? 0.16 : 0.34),\n    (room * (portrait ? 1 : 0.62)) / lastW,\n  );\n  const lastCap = FY * 0.74;\n  const gapY = H * 0.06;\n  const finalRoomH = H - marginY * 2 - lastCap - gapY;\n  const sFinal = Math.min(1, finalRoomH / heightAt(n - 1), portrait ? 1 : 0.6);\n\n  const start = 6;\n  const cl = Math.min(30, Math.max(14, (D * 0.56 - start) / n));\n  const clauseAt = (k: number) => start + k * cl;\n  const finalAt = clauseAt(n);\n\n  let scroll = scrollAt(0);\n  for (let k = 1; k < n; k++) {\n    const e = interpolate(t, [clauseAt(k) - 2, clauseAt(k) + 12], [0, 1], {\n      ...CLAMP,\n      easing: EASE_IO,\n    });\n    scroll += (scrollAt(k) - scrollAt(k - 1)) * e;\n  }\n  const back = interpolate(t, [finalAt - 4, finalAt + 16], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const s = 1 + (sFinal - 1) * back;\n  const offY = -scroll * (1 - back);\n  const dim = 1 - 0.38 * back;\n\n  const wordStyle: React.CSSProperties = {\n    position: \"absolute\",\n    height: F0,\n    lineHeight: `${F0}px`,\n    whiteSpace: \"pre\",\n    fontFamily: gabarito.fontFamily,\n    fontWeight: BODY_W,\n    fontSize: F0,\n    letterSpacing: `${TRACK}em`,\n    color: c.ink,\n  };\n\n  const nodes = words.map((w, i) => {\n    const at = clauseAt(w.clause) + w.order * 2;\n    const p = interpolate(t, [at, at + 14], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n    if (p <= 0) return null;\n    const lineTop = w.line * lineH;\n    const screenTop = marginY + (offY + lineTop) * s;\n    const seen = interpolate(\n      screenTop,\n      [marginY - lineH * s * 0.5, marginY + lineH * s * 0.05],\n      [0, 1],\n      CLAMP,\n    );\n    return (\n      <div\n        key={`w${i}`}\n        style={{\n          ...wordStyle,\n          left: w.x * F0,\n          top: lineTop + (lineH - F0) / 2,\n          opacity: p * seen,\n          transform: `translateY(${((1 - p) * F0 * 0.35).toFixed(2)}px)`,\n        }}\n      >\n        {w.text}\n      </div>\n    );\n  });\n\n  const lastIn = interpolate(t, [finalAt + 4, finalAt + 22], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const tailIn = interpolate(t, [finalAt + 8, finalAt + 26], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const lastBase = H - marginY;\n  const lastTop = lastBase - ((1 - m.asc - m.desc) / 2 + m.asc) * FY;\n  const lastStyle: React.CSSProperties = {\n    display: \"inline-block\",\n    height: FY,\n    lineHeight: `${FY}px`,\n    whiteSpace: \"pre\",\n    fontFamily: gabarito.fontFamily,\n    fontWeight: LAST_W,\n    fontSize: FY,\n    letterSpacing: `${LAST_TRACK}em`,\n  };\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      <div\n        style={{\n          position: \"absolute\",\n          left: marginX,\n          top: marginY,\n          width: room,\n          transformOrigin: \"0 0\",\n          transform: `scale(${s.toFixed(5)}) translateY(${offY.toFixed(2)}px)`,\n          opacity: dim,\n        }}\n      >\n        {nodes}\n      </div>\n      {lastIn > 0 ? (\n        <div\n          style={{\n            position: \"absolute\",\n            right: marginX,\n            top: lastTop - FY * 0.2,\n            height: FY * 1.45,\n            overflow: \"hidden\",\n            display: \"flex\",\n          }}\n        >\n          <div\n            style={{\n              ...lastStyle,\n              marginTop: FY * 0.2,\n              color: c.ink,\n              transform: `translateY(${((1 - lastIn) * FY * 1.3).toFixed(2)}px)`,\n            }}\n          >\n            {lastHead}\n          </div>\n          <div\n            style={{\n              ...lastStyle,\n              marginTop: FY * 0.2,\n              color: hi,\n              transform: `translateY(${((1 - tailIn) * FY * 1.3).toFixed(2)}px)`,\n            }}\n          >\n            {lastTail}\n          </div>\n        </div>\n      ) : null}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/and-you.tsx"
    }
  ],
  "type": "registry:component"
}
