Word Insert
A sentence edits itself, opening a gap and inserting a new word with a gradient.
Source
components/kuchi/word-insert.tsx
1"use client";23import { loadFont } from "@remotion/google-fonts/Manrope";4import { type CSSProperties, type ReactNode, useId, useMemo } from "react";5import {6 AbsoluteFill,7 Easing,8 interpolate,9 useCurrentFrame,10 useVideoConfig,11} from "remotion";1213const { fontFamily: sans } = loadFont("normal", {14 weights: ["500"],15 subsets: ["latin"],16});1718export interface WordInsertProps {19 states?: string[];20 /** Frames between one state of the sentence and the next. */21 beat?: number;22 /** Frames between words as they enter. */23 stagger?: number;24 accent?: string;25 /** Text color; overrides the theme ink. */26 ink?: string;27 background?: string;28 /** Typeface for the sentence. Load it yourself; Manrope by default. */29 fontFamily?: string;30 /** Size of the sentence, around the frame's center. */31 scale?: number;32 /** Frames to hold the first frame before anything moves. */33 delay?: number;34 grain?: boolean;35 theme?: "dark" | "light";36 speed?: number;37}3839// Manrope 500 advance widths (1/1000 em) for ASCII 32–126, punctuation, kerning.40const MANROPE_500 = [41 200, 329, 417, 924, 602, 901, 657, 229, 435, 435, 446, 575, 278, 420, 270,42 403, 626, 406, 579, 563, 596, 581, 621, 513, 591, 621, 314, 318, 622, 750,43 622, 534, 907, 646, 619, 723, 681, 575, 510, 714, 697, 249, 476, 612, 518,44 846, 696, 732, 616, 732, 641, 630, 600, 708, 616, 949, 623, 575, 631, 413,45 403, 413, 673, 660, 506, 563, 600, 561, 601, 591, 363, 600, 605, 249, 263,46 510, 249, 865, 605, 601, 600, 601, 374, 531, 412, 605, 523, 779, 536, 538,47 531, 430, 269, 430, 680,48];49const MANROPE_500_EXTRA: Record<string, number> = {50 "‘": 243,51 "’": 243,52 "“": 399,53 "”": 399,54 "…": 658,55 "–": 540,56 "—": 780,57};58const KERN_PAIRS = [59 "AA-35 AC20 AG20 AO20 AQ20 AS20 AT60 AU20 AV70 AW70 AY60 Af25 At20",60 "Av40 Aw40 Ay50 A’80 A“120 A”80 B,30 B.30 BT20 BV30 BW30 BX30 BY30",61 "C,50 C.50 CA20 CS-30 CV20 CW20 CX30 CY30 D,50 D.50 DA20 DT20 DV30",62 "DW30 DX30 DY30 DZ12 EC25 EG30 EO30 EQ30 ES20 F,115 F.115 FA10 FJ25",63 "Fa20 Fc15 Fd15 Fe15 Fo15 Fq20 G,50 G.50 GA20 GT20 GV30 GW30 GX30 GY30",64 "IY40 J,50 J.50 JA20 KC15 KG35 KO35 KQ30 KS30 Kc40 Kd40 Ke40 Kg30 Ko40",65 "Kq35 Ks20 Kt31 Ku35 Ky45 K“20 LG20 LO20 LQ20 LT100 LV80 LW80 LY100",66 "Lf20 Lt25 Lv35 Lw35 Ly50 L’120 L“120 L”120 O,50 O.50 OA20 OT20 OV30",67 "OW30 OX50 OY30 Ox20 P,160 P.160 PA50 PJ25 PX30 Pa20 Pf-40 Q,30 Q.30",68 "QA20 QT20 QV30 QW30 QX30 QY30 Qx20 RC15 RY12 S,25 S.25 SS-15 SV20",69 "SW20 SX30 SY30 Sy10 T,100 T.100 TA20 TJ80 TT-60 TY-30 Ta70 Tc80 Td80",70 "Te80 Tg80 Tm50 Tn50 To80 Tp50 Tq80 Tr50 Ts60 Tu50 Tv60 Tw60 Tx70 Ty70",71 "Tz60 T”-40 U,20 U.20 UA30 US30 V,60 V.60 VA70 VC20 VG20 VJ30 VO20",72 "VQ20 VS20 Va45 Vc60 Vd60 Ve60 Vg45 Vi20 Vl20 Vm30 Vn30 Vo60 Vp30 Vq45",73 "Vs30 Vu30 Vv30 Vw30 Vx30 Vz20 W,60 W.60 WA70 WC20 WG20 WJ30 WO20 WQ20",74 "WS20 Wa45 Wc60 Wd60 We60 Wg45 Wi20 Wl20 Wm30 Wn30 Wo60 Wp30 Wq45 Ws30",75 "Wu30 Wv30 Ww30 Wx30 Wz20 XC30 XG30 XO30 XQ30 XS20 XT-40 Xc20 Xd20",76 "Xe20 Xo20 Y,140 Y.140 YA70 YC40 YG40 YI25 YJ80 YO40 YQ40 YS30 YT-30",77 "YX20 YY-31 Ya80 Yb25 Yc80 Yd80 Ye80 Yg80 Ym50 Yn50 Yo80 Yp50 Yq80",78 "Yr40 Ys80 Yu40 Yv35 Yw35 Yx30 Yy35 Yz35 ZT-40 Zv60 Zw60 aT60 aV30",79 "aW30 aY60 av20 aw20 ay30 a’30 a“30 a”20 b,20 b.20 bT60 bV30 bW30 bX20",80 "bY80 bv20 bw20 bx20 by30 bz20 b’30 b“30 b”20 c,20 c.20 cT60 cV30 cW30",81 "cY60 cc15 cd15 ce15 ci15 cl15 co15 cy20 c’30 c“30 c”20 dY40 e,20 e.20",82 "eT60 eV30 eW30 eY60 ea10 em15 en15 ep15 ev20 ew20 ex20 ey10 e”30 f,50",83 "f.50 fI-31 fT-60 fa15 fb-31 fc20 fd20 fe20 fh-31 fi-15 fk-31 fl-15",84 "fo20 f’-30 f“-40 f”-30 gT50 gY50 g“50 hT60 h’20 h“30 h”20 i’37 kc10",85 "kd10 ke10 ko10 kq30 ks10 l’37 mT60 mY70 my20 m’40 m“20 m”20 nT60 nY70",86 "ny20 n’40 n“20 n”20 o,20 o.20 oT60 oV30 oW30 oX20 oY80 ov20 ow20 ox12",87 "oy20 oz20 o’20 o“30 o”30 p,20 p.20 pT60 pV30 pW30 pX20 pY80 pv20 pw20",88 "px12 py20 pz20 p’20 p“30 p”30 qY40 r,80 r.80 rY20 ra17 rc10 rd10 re10",89 "rg20 ro10 rs20 ry10 sT50 sV30 sW30 sY60 sv20 sw20 sx20 sy20 s’20 s“30",90 "s”30 tY20 tc22 td22 te22 to22 ty15 uY40 v,80 v.80 vA20 vT60 vY35 va30",91 "vc20 vd20 ve20 vg20 vo20 vq20 vs20 w,80 w.80 wA20 wT60 wY35 wa30 wc20",92 "wd20 we20 wg20 wo20 wq20 ws20 xT50 xY30 xa20 xc20 xd20 xe20 xg20 xo20",93 "xq20 xv10 xw10 y,80 y.80 yA15 yT40 yY35 ya20 yc20 yd20 ye20 yf-40",94 "yg15 yo20 yt-40 y”-30 zT50 zY35 za30 zc40 zd40 ze40 zo40 zq30 zy15",95 "’A120 ’S30 ’a30 ’c75 ’d75 ’e75 ’g30 ’i-30 ’l-30 ’o75 ’q30 ’s80 “A120",96 "“J120 “a30 “c30 “d30 “e30 “g30 “o30 “q30 “s30 “t-30 ”A120 ”J100 ”c30",97 "”d30 ”e30 ”f30 ”g40 ”o30 ”q30 ”s30",98].join(" ");99const KERN = new Map(100 KERN_PAIRS.split(" ").map((p) => [p.slice(0, 2), -Number(p.slice(2)) / 1000]),101);102const TRACK = -0.03;103const ASC = 1.066;104const LINE = 1.366;105const CAP = 0.72;106const SPACE = 0.2 + TRACK;107const LEAD = 1.06;108const MAX_SIZE = 0.2;109const FILL = 0.84;110111const ENTER_STAGGER = 3;112const ENTER_LEN = 18;113const FIRST = 36;114const STEP = 50;115const MOVE = 22;116const INSERT_DELAY = 12;117const INSERT_LEN = 18;118const ACCENT_HOLD = 12;119const SETTLE = 16;120const HOLD = 30;121122const EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);123const EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);124const CLAMP = {125 extrapolateLeft: "clamp",126 extrapolateRight: "clamp",127} as const;128129// Inserted words are painted with one stage-wide gradient (clip-text):130// gradients.sh "aurora" on dark, "ribbon" on light. `null` = the accent.131const THEMES = {132 dark: {133 bg: "#0A0A0B",134 fg: "#F3F2EF",135 grain: 0.07,136 stops: ["#a0f0c8", "#3fb5a3", null, "#b25c9c"],137 },138 light: {139 bg: "#F5F4F0",140 fg: "#121214",141 grain: 0.045,142 stops: [null, "#7a5cff", "#ff3d9a", "#ff8a3d"],143 },144} as const;145146function advance(ch: string) {147 const code = ch.charCodeAt(0);148 if (code >= 32 && code < 127) return MANROPE_500[code - 32] / 1000;149 return (MANROPE_500_EXTRA[ch] ?? 620) / 1000;150}151152function textEm(s: string) {153 let w = 0;154 for (let i = 0; i < s.length; i++) {155 if (i > 0) w += KERN.get(s[i - 1] + s[i]) ?? 0;156 w += advance(s[i]) + TRACK;157 }158 return w;159}160161function wordKey(token: string) {162 return token.toLowerCase().replace(/[^\p{L}\p{N}]/gu, "");163}164165function tokenize(state: string) {166 return state.split(/\s+/).filter(Boolean);167}168169function matchTokens(a: string[], b: string[]) {170 const ka = a.map(wordKey);171 const kb = b.map(wordKey);172 const dp = Array.from({ length: a.length + 1 }, () =>173 new Array<number>(b.length + 1).fill(0),174 );175 for (let i = a.length - 1; i >= 0; i--) {176 for (let j = b.length - 1; j >= 0; j--) {177 dp[i][j] =178 ka[i] === kb[j]179 ? dp[i + 1][j + 1] + 1180 : Math.max(dp[i + 1][j], dp[i][j + 1]);181 }182 }183 const pairs: [number, number][] = [];184 let i = 0;185 let j = 0;186 while (i < a.length && j < b.length) {187 if (ka[i] === kb[j]) {188 pairs.push([i, j]);189 i++;190 j++;191 } else if (dp[i + 1][j] >= dp[i][j + 1]) i++;192 else j++;193 }194 return pairs;195}196197interface Point {198 x: number;199 y: number;200}201202interface Layout {203 tokens: string[];204 x: number[];205 y: number[];206 w: number[];207}208209interface Track {210 key: string;211 idx: (number | null)[];212 virtualFrom: (Point | null)[];213 virtualTo: (Point | null)[];214 bornAt: number;215 bornOrder: number;216}217218interface Plan {219 tracks: Track[];220 owner: number[][];221 pairs: [number, number][][];222}223224function planTracks(states: string[][]): Plan {225 const tracks: Track[] = [];226 const blankIdx = () => states.map(() => null as number | null);227 const blankPt = () => states.map(() => null as Point | null);228 const add = (s: number, j: number, order: number) => {229 const idx = blankIdx();230 idx[s] = j;231 tracks.push({232 key: `t${tracks.length}`,233 idx,234 virtualFrom: blankPt(),235 virtualTo: blankPt(),236 bornAt: s,237 bornOrder: order,238 });239 return tracks.length - 1;240 };241 const owner: number[][] = [states[0].map((_, i) => add(0, i, i))];242 const pairs: [number, number][][] = [[]];243 for (let s = 1; s < states.length; s++) {244 const matched = matchTokens(states[s - 1], states[s]);245 pairs.push(matched);246 const fromB = new Map(matched.map(([i, j]) => [j, i]));247 let order = 0;248 owner.push(249 states[s].map((_, j) => {250 const i = fromB.get(j);251 if (i === undefined) return add(s, j, order++);252 const id = owner[s - 1][i];253 tracks[id].idx[s] = j;254 return id;255 }),256 );257 }258 return { tracks, owner, pairs };259}260261function lineOf(plan: Plan, states: string[][], cut: number | null) {262 const last = states.length - 1;263 return states.map((tokens, s) => {264 let line = 0;265 return tokens.map((_, i) => {266 const lastIdx = plan.tracks[plan.owner[s][i]].idx[last];267 if (cut !== null && lastIdx !== null && lastIdx >= cut) line = 1;268 return line;269 });270 });271}272273function widestLine(states: string[][], lines: number[][]) {274 let widest = 0;275 states.forEach((tokens, s) => {276 const sums = [0, 0];277 const counts = [0, 0];278 tokens.forEach((tok, i) => {279 const l = lines[s][i];280 sums[l] += textEm(tok) + (counts[l] > 0 ? SPACE : 0);281 counts[l]++;282 });283 widest = Math.max(widest, sums[0], sums[1]);284 });285 return widest;286}287288function layoutState(tokens: string[], lines: number[]): Layout {289 const w = tokens.map(textEm);290 const used = [...new Set(lines)];291 const x: number[] = new Array(tokens.length).fill(0);292 const y: number[] = new Array(tokens.length).fill(0);293 used.forEach((line, row) => {294 const members = tokens.map((_, i) => i).filter((i) => lines[i] === line);295 const lineW =296 members.reduce((s, i) => s + w[i], 0) +297 SPACE * Math.max(0, members.length - 1);298 let cursor = -lineW / 2;299 for (const i of members) {300 x[i] = cursor;301 y[i] = (row - (used.length - 1) / 2) * LEAD;302 cursor += w[i] + SPACE;303 }304 });305 return { tokens, x, y, w };306}307308function gapPoint(309 src: Layout,310 dst: Layout,311 dstIndex: number,312 map: Map<number, number>,313): Point {314 const n = dst.tokens.length;315 const sameLine = (a: number, b: number) =>316 Math.abs(dst.y[a] - dst.y[b]) < 1e-6;317 let runStart = dstIndex;318 while (319 runStart > 0 &&320 !map.has(runStart - 1) &&321 sameLine(runStart - 1, dstIndex)322 )323 runStart--;324 let runEnd = dstIndex;325 while (326 runEnd < n - 1 &&327 !map.has(runEnd + 1) &&328 sameLine(runEnd + 1, dstIndex)329 )330 runEnd++;331 const runLeft = dst.x[runStart];332 const runW = dst.x[runEnd] + dst.w[runEnd] - runLeft;333 const at = (k: number) =>334 k >= 0 && k < n && sameLine(k, dstIndex) ? map.get(k) : undefined;335 const prev = at(runStart - 1);336 const next = at(runEnd + 1);337 let left = runLeft;338 let y = dst.y[dstIndex];339 if (prev !== undefined && next !== undefined) {340 left = (src.x[prev] + src.w[prev] + src.x[next]) / 2 - runW / 2;341 y = src.y[prev];342 } else if (prev !== undefined) {343 left = src.x[prev] + src.w[prev] + SPACE;344 y = src.y[prev];345 } else if (next !== undefined) {346 left = src.x[next] - SPACE - runW;347 y = src.y[next];348 }349 return { x: left + (dst.x[dstIndex] - runLeft), y };350}351352function resolveVirtual(plan: Plan, layouts: Layout[]) {353 for (let s = 1; s < layouts.length; s++) {354 const a = layouts[s - 1];355 const b = layouts[s];356 const fromB = new Map(plan.pairs[s].map(([i, j]) => [j, i]));357 const fromA = new Map(plan.pairs[s].map(([i, j]) => [i, j]));358 b.tokens.forEach((_, j) => {359 if (!fromB.has(j))360 plan.tracks[plan.owner[s][j]].virtualFrom[s] = gapPoint(a, b, j, fromB);361 });362 a.tokens.forEach((_, i) => {363 if (!fromA.has(i))364 plan.tracks[plan.owner[s - 1][i]].virtualTo[s] = gapPoint(365 b,366 a,367 i,368 fromA,369 );370 });371 }372 return plan.tracks;373}374375function splitChange(from: string, to: string) {376 let pre = 0;377 while (pre < from.length && pre < to.length && from[pre] === to[pre]) pre++;378 let suf = 0;379 while (380 suf < from.length - pre &&381 suf < to.length - pre &&382 from[from.length - 1 - suf] === to[to.length - 1 - suf]383 )384 suf++;385 return {386 prefix: from.slice(0, pre),387 midFrom: from.slice(pre, from.length - suf),388 midTo: to.slice(pre, to.length - suf),389 suffix: from.slice(from.length - suf),390 };391}392393function Grain({ opacity }: { opacity: number }) {394 const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;395 return (396 <svg397 width="100%"398 height="100%"399 style={{ position: "absolute", inset: 0, opacity, pointerEvents: "none" }}400 aria-hidden401 >402 <filter id={id}>403 <feTurbulence404 type="fractalNoise"405 baseFrequency="0.9"406 numOctaves={2}407 seed={23}408 stitchTiles="stitch"409 />410 <feColorMatrix values="0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0.9 0" />411 </filter>412 <rect width="100%" height="100%" filter={`url(#${id})`} />413 </svg>414 );415}416417const DEFAULT_STATES = [418 "Launch videos.",419 "Launch videos, as code.",420 "Beautiful launch videos, as code.",421];422423export function wordInsertDuration(states: number = DEFAULT_STATES.length) {424 const last = FIRST + Math.max(0, states - 2) * STEP;425 return last + INSERT_DELAY + INSERT_LEN + ACCENT_HOLD + SETTLE + HOLD;426}427428/** The foreground at `scale`, around the frame's center; nothing extra at 1. */429function ScaleLayer({430 scale,431 children,432}: {433 scale: number;434 children: React.ReactNode;435}) {436 if (scale === 1) return children;437 return (438 <AbsoluteFill style={{ transform: `scale(${scale})` }}>439 {children}440 </AbsoluteFill>441 );442}443444export function WordInsert({445 states = DEFAULT_STATES,446 beat = STEP,447 stagger = ENTER_STAGGER,448 accent = "#3B5BFD",449 ink,450 background,451 fontFamily = sans,452 scale = 1,453 delay = 0,454 grain = true,455 theme = "dark",456 speed = 1,457}: WordInsertProps) {458 const t = Math.max(0, useCurrentFrame() - delay) * speed;459 const { width: W, height: H } = useVideoConfig();460 const c = THEMES[theme];461 const stage =462 background === "transparent" ? "transparent" : (background ?? c.bg);463464 const tokenized = useMemo(465 () => (states.length ? states : [""]).map(tokenize),466 [states],467 );468 const fillW = W * FILL;469 const { F, tracks, layouts } = useMemo(() => {470 const plan = planTracks(tokenized);471 const lastLen = tokenized[tokenized.length - 1].length;472 let best = { size: 0, lines: lineOf(plan, tokenized, null) };473 for (let cut = -1; cut < lastLen; cut++) {474 if (cut === 0) continue;475 const lines = lineOf(plan, tokenized, cut < 0 ? null : cut);476 const size = Math.min(477 H * MAX_SIZE,478 fillW / Math.max(0.1, widestLine(tokenized, lines)),479 );480 if (size > best.size + 0.5) best = { size, lines };481 }482 const laid = tokenized.map((tokens, s) =>483 layoutState(tokens, best.lines[s]),484 );485 return { F: best.size, tracks: resolveVirtual(plan, laid), layouts: laid };486 }, [tokenized, fillW, H]);487488 const startOf = (s: number) => FIRST + (s - 1) * beat;489 let cur = 0;490 for (let s = 1; s < layouts.length; s++) if (t >= startOf(s)) cur = s;491 const p =492 cur === 0493 ? 1494 : EASE_IO(495 interpolate(t, [startOf(cur), startOf(cur) + MOVE], [0, 1], CLAMP),496 );497 const prev = Math.max(0, cur - 1);498 const la = layouts[prev];499 const lb = layouts[cur];500 const baseline = H / 2 + (CAP * F) / 2;501502 // One gradient band across the whole measure; each inserted word samples503 // the slice it sits on, drifting a few percent over the shot.504 const final = layouts[layouts.length - 1];505 const bandL = Math.min(0, ...final.x);506 const bandR = Math.max(0, ...final.x.map((v, i) => v + final.w[i]));507 const bandEm = Math.max(0.1, bandR - bandL);508 const drift = 0.04 * bandEm * Math.sin(t * 0.012);509 const stops = c.stops.map((col) => col ?? accent);510 const gradient = `linear-gradient(90deg, ${stops511 .map((col, i) => `${col} ${((i / (stops.length - 1)) * 100).toFixed(1)}%`)512 .join(", ")})`;513 const PAD = 0.1;514 const paint = (text: string, ex: number, extra?: CSSProperties) => (515 <span516 style={{517 ...extra,518 marginLeft: `${-PAD}em`,519 padding: `0 ${PAD}em`,520 color: "transparent",521 backgroundImage: gradient,522 backgroundSize: `${bandEm * 1.1}em 100%`,523 backgroundPosition: `${-(ex - PAD - bandL + bandEm * 0.05) + drift}em 0`,524 backgroundRepeat: "no-repeat",525 WebkitBackgroundClip: "text",526 backgroundClip: "text",527 }}528 >529 {text}530 </span>531 );532533 const words: ReactNode[] = [];534 for (const tr of tracks) {535 const ia = tr.idx[prev];536 const ib = tr.idx[cur];537 if (ia === null && ib === null) continue;538539 let x = 0;540 let y = 0;541 let opacity = 1;542 let rise = 0;543 let content: ReactNode = null;544 // Inserted words carry the gradient for the rest of the shot.545 const born = tr.bornAt > 0;546547 if (cur === 0 && ib !== null) {548 x = lb.x[ib];549 y = lb.y[ib];550 const start = ib * stagger;551 const e = EASE_OUT(552 interpolate(t, [start, start + ENTER_LEN], [0, 1], CLAMP),553 );554 opacity = e;555 rise = (1 - e) * 0.24;556 content = lb.tokens[ib];557 } else if (ia !== null && ib !== null) {558 x = la.x[ia] + (lb.x[ib] - la.x[ia]) * p;559 y = la.y[ia] + (lb.y[ib] - la.y[ia]) * p;560 const from = la.tokens[ia];561 const to = lb.tokens[ib];562 if (from === to || p >= 1) {563 content = to;564 } else {565 const sp = splitChange(from, to);566 const mix = interpolate(p, [0.2, 0.8], [0, 1], CLAMP);567 const preW = textEm(sp.prefix);568 const midW =569 textEm(sp.midFrom) + (textEm(sp.midTo) - textEm(sp.midFrom)) * p;570 const part = (key: string, text: string, left: number, o: number) => {571 const style: CSSProperties = {572 position: "absolute",573 left: `${left}em`,574 top: 0,575 opacity: o,576 };577 if (born)578 return (579 <span key={key} style={style}>580 {paint(text, x + left)}581 </span>582 );583 return (584 <span key={key} style={style}>585 {text}586 </span>587 );588 };589 content = [590 part("pre", sp.prefix, 0, 1),591 part("from", sp.midFrom, preW, 1 - mix),592 part("to", sp.midTo, preW, mix),593 part("suf", sp.suffix, preW + midW, 1),594 ];595 }596 } else if (ib !== null) {597 const from = tr.virtualFrom[cur] ?? { x: lb.x[ib], y: lb.y[ib] };598 x = from.x + (lb.x[ib] - from.x) * p;599 y = from.y + (lb.y[ib] - from.y) * p;600 content = lb.tokens[ib];601 } else if (ia !== null) {602 const to = tr.virtualTo[cur] ?? { x: la.x[ia], y: la.y[ia] };603 x = la.x[ia] + (to.x - la.x[ia]) * p;604 y = la.y[ia] + (to.y - la.y[ia]) * p;605 const out = interpolate(606 t,607 [startOf(cur), startOf(cur) + MOVE * 0.45],608 [0, 1],609 { ...CLAMP, easing: EASE_IO },610 );611 opacity = 1 - out;612 rise = -out * 0.14;613 content = la.tokens[ia];614 }615616 if (tr.bornAt > 0) {617 const start = startOf(tr.bornAt) + INSERT_DELAY + tr.bornOrder * stagger;618 const e = EASE_OUT(619 interpolate(t, [start, start + INSERT_LEN], [0, 1], CLAMP),620 );621 if (tr.bornAt === cur) {622 opacity *= e;623 rise = (1 - e) * 0.32;624 }625 }626 if (born && typeof content === "string") content = paint(content, x);627628 words.push(629 <div630 key={tr.key}631 style={{632 position: "absolute",633 left: `${x}em`,634 top: `${y - ASC + rise}em`,635 opacity,636 color: ink ?? c.fg,637 whiteSpace: "pre",638 }}639 >640 {content}641 </div>,642 );643 }644645 return (646 <AbsoluteFill style={{ background: stage, overflow: "hidden" }}>647 <ScaleLayer scale={scale}>648 <div649 style={{650 position: "absolute",651 left: W / 2,652 top: baseline,653 fontFamily,654 fontWeight: 500,655 fontSize: F,656 lineHeight: LINE,657 letterSpacing: `${TRACK}em`,658 fontKerning: "normal",659 }}660 >661 {words}662 </div>663 </ScaleLayer>664 {grain ? <Grain opacity={c.grain} /> : null}665 </AbsoluteFill>666 );667}









