{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "long-vowel",
  "title": "Long Vowel",
  "description": "A serif word stretches one vowel, 'Waaaaaay', in a warm gradient with an italic caption.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/long-vowel/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadFraunces } from \"@remotion/google-fonts/Fraunces\";\nimport type React from \"react\";\nimport { useEffect, useId, 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 fraunces = loadFraunces(\"normal\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\nloadFraunces(\"italic\", { weights: [\"400\"], subsets: [\"latin\"] });\n\nexport interface LongVowelProps {\n  word?: string;\n  letter?: string;\n  repeat?: number;\n  rest?: string;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    ink: \"#F4F3F0\",\n    muted: \"#B4B2B9\",\n    ramp: (a: string) => [\"#F4F3F0\", \"#fff4ec\", \"#ffb36b\", \"#e2457a\", a],\n    grain: 0.05,\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    ink: \"#111113\",\n    muted: \"#5F5D58\",\n    ramp: (a: string) => [\"#111113\", \"#2a2f8f\", a, \"#d93d73\", \"#e0702c\"],\n    grain: 0.035,\n  },\n} as const;\n\nconst TRACK = -0.035;\nconst REST_TRACK = -0.01;\nconst FONT_PX = 400;\n\nconst RISE_AT = 0;\nconst RISE_LEN = 16;\nconst RISE_GAP = 2;\nconst DRAWL_AT = 28;\nconst DRAWL_GAP = 4;\nconst REST_GAP_AFTER = 4;\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 Metrics {\n  x: number[];\n  width: number;\n  rest: number;\n  asc: number;\n  desc: number;\n  capTop: number;\n  restAsc: number;\n  restDesc: number;\n}\n\nfunction measure(drawn: string, rest: string): Metrics {\n  const canvas = document.createElement(\"canvas\");\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) throw new Error(\"long-vowel: no 2d context\");\n  const fam = `\"${fraunces.fontFamily}\"`;\n  ctx.font = `400 ${FONT_PX}px ${fam}`;\n  const chars = Array.from(drawn);\n  const x: number[] = [];\n  let prefix = \"\";\n  for (let i = 0; i < chars.length; i++) {\n    x.push(ctx.measureText(prefix).width / FONT_PX + TRACK * i);\n    prefix += chars[i];\n  }\n  const width =\n    ctx.measureText(drawn).width / FONT_PX + TRACK * (chars.length - 1);\n  const fm = ctx.measureText(drawn);\n  const capTop = fm.actualBoundingBoxAscent / FONT_PX;\n  const asc = fm.fontBoundingBoxAscent / FONT_PX;\n  const desc = fm.fontBoundingBoxDescent / FONT_PX;\n  ctx.font = `italic 400 ${FONT_PX}px ${fam}`;\n  const rm = ctx.measureText(rest || \" \");\n  return {\n    x,\n    width,\n    rest:\n      rest.length > 0\n        ? rm.width / FONT_PX + REST_TRACK * Array.from(rest).length\n        : 0,\n    asc,\n    desc,\n    capTop,\n    restAsc: rm.actualBoundingBoxAscent / FONT_PX,\n    restDesc: rm.actualBoundingBoxDescent / FONT_PX,\n  };\n}\n\nfunction useMetrics(drawn: string, rest: string) {\n  const [metrics, setMetrics] = useState<Metrics | null>(null);\n  const [handle] = useState(() => delayRender(\"long-vowel: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      fraunces.waitUntilDone(),\n      document.fonts.load(`400 100px \"${fraunces.fontFamily}\"`),\n      document.fonts.load(`italic 400 100px \"${fraunces.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setMetrics(measure(drawn, rest));\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [drawn, rest, handle]);\n  return metrics;\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n  const id = `lv${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  return (\n    <svg\n      width=\"100%\"\n      height=\"100%\"\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        opacity,\n        mixBlendMode: \"overlay\",\n        pointerEvents: \"none\",\n      }}\n      aria-hidden\n    >\n      <filter id={id}>\n        <feTurbulence\n          type=\"fractalNoise\"\n          baseFrequency=\"0.9\"\n          numOctaves={2}\n          seed={5}\n        />\n        <feColorMatrix type=\"saturate\" values=\"0\" />\n      </filter>\n      <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n    </svg>\n  );\n}\n\nfunction rampAt(ramp: readonly string[], u: number) {\n  const s = Math.min(Math.max(u, 0), 1) * (ramp.length - 1);\n  const i = Math.min(Math.floor(s), ramp.length - 2);\n  const f = s - i;\n  return `color-mix(in oklab, ${ramp[i]} ${((1 - f) * 100).toFixed(1)}%, ${ramp[i + 1]})`;\n}\n\nexport function LongVowel({\n  word = \"Way\",\n  letter,\n  repeat = 5,\n  rest = \"less keyframing.\",\n  accent = \"#3B5BFD\",\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: LongVowelProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, fps } = useVideoConfig();\n  const c = THEMES[theme];\n  const bg = background ?? c.bg;\n  const ramp = c.ramp(accent);\n\n  const chars = useMemo(() => Array.from(word), [word]);\n  const hold = useMemo(() => {\n    if (letter) {\n      const i = chars.indexOf(letter);\n      if (i >= 0) return i;\n    }\n    const v = chars.findIndex((ch) => /[aeiouyAEIOUY]/.test(ch));\n    return v >= 0 ? v : Math.max(0, Math.floor((chars.length - 1) / 2));\n  }, [chars, letter]);\n  const copies = Math.max(1, Math.round(repeat));\n  const drawn = useMemo(\n    () =>\n      [\n        ...chars.slice(0, hold + 1),\n        ...Array.from({ length: copies }, () => chars[hold]),\n        ...chars.slice(hold + 1),\n      ].join(\"\"),\n    [chars, hold, copies],\n  );\n  const m = useMetrics(drawn, rest);\n\n  if (!m) {\n    return <div style={{ position: \"absolute\", inset: 0, background: bg }} />;\n  }\n\n  const F = Math.min(H * 0.4, (W * 0.88) / m.width);\n  const R = rest\n    ? Math.min(F * 0.36, (W * 0.84) / Math.max(0.1, m.rest), H * 0.1)\n    : 0;\n  const gap = rest ? F * 0.3 : 0;\n  const blockTop = m.capTop * F;\n  const blockBot = rest ? gap + (m.restAsc + m.restDesc) * R : 0;\n  const baseY = H / 2 + (blockTop - blockBot) / 2;\n  const restBase = baseY + gap + m.restAsc * R;\n\n  const prog = Array.from({ length: copies }, (_, k) =>\n    spring({\n      frame: t - DRAWL_AT - k * DRAWL_GAP,\n      fps,\n      config: { damping: 15, stiffness: 140, mass: 0.8 },\n    }),\n  );\n  const vel = prog.map((_, k) => {\n    const a = spring({\n      frame: t - DRAWL_AT - k * DRAWL_GAP - 1,\n      fps,\n      config: { damping: 15, stiffness: 140, mass: 0.8 },\n    });\n    return prog[k] - a;\n  });\n\n  const n = chars.length + copies;\n  const fx = m.x;\n  const step = (i: number) => (i + 1 < n ? fx[i + 1] - fx[i] : 0);\n  const xs: number[] = [];\n  let shrink = 0;\n  for (let i = 0; i < n; i++) {\n    if (i > hold && i <= hold + copies) {\n      const k = i - hold - 1;\n      shrink += (1 - prog[k]) * step(i - 1);\n    }\n    xs.push(fx[i] - shrink);\n  }\n  const curW = m.width - shrink;\n  const left = (W - curW * F) / 2;\n\n  const maskTop = baseY - m.asc * F;\n  const maskH = (m.asc + m.desc) * F;\n  const lineTop = baseY - (m.asc + (1 - m.asc - m.desc) / 2) * F;\n\n  const drawnChars = Array.from(drawn);\n  const glyphs: React.ReactNode[] = [];\n  for (let i = n - 1; i >= 0; i--) {\n    const ch = drawnChars[i];\n    const isCopy = i > hold && i <= hold + copies;\n    const k = isCopy ? i - hold - 1 : -1;\n    const ri = i <= hold ? i : isCopy ? hold : i - copies;\n    const rp = interpolate(\n      t,\n      [RISE_AT + ri * RISE_GAP, RISE_AT + ri * RISE_GAP + RISE_LEN],\n      [0, 1],\n      { ...CLAMP, easing: EASE_OUT },\n    );\n    const dy = (1 - rp) * maskH * 1.05;\n    let color: string = c.ink;\n    let opacity = 1;\n    let skew = 0;\n    if (isCopy) {\n      const u0 = (k + 1) / copies;\n      const u1 = Math.min(1, (k + 1.6) / copies);\n      color = rampAt(ramp, u0);\n      opacity = interpolate(prog[k], [0, 0.25], [0, 1], CLAMP);\n      skew = Math.max(-14, Math.min(14, -vel[k] * 90));\n      glyphs.push(\n        <div\n          key={`g${i}`}\n          style={{\n            position: \"absolute\",\n            left: left + xs[i] * F,\n            top: lineTop - maskTop + dy,\n            fontFamily: fraunces.fontFamily,\n            fontWeight: 400,\n            fontSize: F,\n            lineHeight: `${F}px`,\n            whiteSpace: \"pre\",\n            opacity,\n            transform: `skewX(${skew.toFixed(2)}deg)`,\n            transformOrigin: `0 ${(m.asc * F).toFixed(1)}px`,\n            backgroundImage: `linear-gradient(90deg, ${color}, ${rampAt(ramp, u1)})`,\n            WebkitBackgroundClip: \"text\",\n            backgroundClip: \"text\",\n            color: \"transparent\",\n          }}\n        >\n          {ch}\n        </div>,\n      );\n      continue;\n    }\n    glyphs.push(\n      <div\n        key={`g${i}`}\n        style={{\n          position: \"absolute\",\n          left: left + xs[i] * F,\n          top: lineTop - maskTop + dy,\n          fontFamily: fraunces.fontFamily,\n          fontWeight: 400,\n          fontSize: F,\n          lineHeight: `${F}px`,\n          whiteSpace: \"pre\",\n          color,\n        }}\n      >\n        {ch}\n      </div>,\n    );\n  }\n\n  const restAt = DRAWL_AT + (copies - 1) * DRAWL_GAP + 14 + REST_GAP_AFTER;\n  const restWords = rest ? rest.split(\" \") : [];\n\n  return (\n    <AbsoluteFill style={{ background: bg, overflow: \"hidden\" }}>\n      <div\n        style={{\n          position: \"absolute\",\n          left: 0,\n          width: W,\n          top: maskTop,\n          height: maskH,\n          overflow: \"hidden\",\n        }}\n      >\n        {glyphs}\n      </div>\n      {rest ? (\n        <div\n          style={{\n            position: \"absolute\",\n            left: 0,\n            width: W,\n            top: restBase - R,\n            height: R * 1.3,\n            overflow: \"hidden\",\n            display: \"flex\",\n            justifyContent: \"center\",\n            fontFamily: fraunces.fontFamily,\n            fontStyle: \"italic\",\n            fontWeight: 400,\n            fontSize: R,\n            lineHeight: `${R}px`,\n            letterSpacing: `${REST_TRACK}em`,\n            color: c.muted,\n            whiteSpace: \"pre\",\n          }}\n        >\n          {restWords.map((w, k) => {\n            const p = interpolate(\n              t,\n              [restAt + k * 3, restAt + k * 3 + 16],\n              [0, 1],\n              { ...CLAMP, easing: EASE_OUT },\n            );\n            return (\n              <span\n                key={`${w}-${k}`}\n                style={{\n                  display: \"inline-block\",\n                  transform: `translateY(${((1 - p) * R * 1.2).toFixed(2)}px)`,\n                }}\n              >\n                {w}\n                {k < restWords.length - 1 ? \" \" : \"\"}\n              </span>\n            );\n          })}\n        </div>\n      ) : null}\n      {bg === \"transparent\" ? null : <Grain opacity={c.grain} />}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/long-vowel.tsx"
    }
  ],
  "type": "registry:component"
}
