Full Bleed Type
Huge condensed caps words slam in one at a time, the last lit by a sunrise gradient.
Source
components/kuchi/full-bleed-type.tsx
1"use client";23import { loadFont } from "@remotion/google-fonts/BarlowCondensed";4import type React from "react";5import { useId } from "react";6import {7 AbsoluteFill,8 Easing,9 interpolate,10 useCurrentFrame,11 useVideoConfig,12} from "remotion";1314const { fontFamily: display } = loadFont("normal", {15 weights: ["500"],16 subsets: ["latin"],17});1819export interface FullBleedTypeProps {20 /** Words in reading order, one slam each. Set in caps; the last one is lit by the sunrise gradient. */21 words?: string[];22 /** Frames between two slams. */23 beat?: number;24 /** Frames a word takes to slam in, before it settles. */25 slam?: number;26 /** Kept for the shared draft API; the hero word takes the "rise" gradient instead. */27 accent?: string;28 /** Color of every word but the last; overrides the theme ink. */29 ink?: string;30 background?: string;31 /** Typeface for the words. Load it yourself; Barlow Condensed by default. Row widths are fitted to Barlow Condensed. */32 fontFamily?: string;33 /** Size of the word stack, around the frame's center. */34 scale?: number;35 /** Frames to hold the first frame before anything moves. */36 delay?: number;37 theme?: "dark" | "light";38 speed?: number;39}4041// Barlow Condensed 500, per 1000 em, chars 32–126 (harfbuzz): advance, left and right side bearing.42const ADV = [43 200, 261, 274, 599, 426, 776, 564, 137, 254, 254, 361, 440, 189, 320, 202,44 363, 447, 266, 415, 418, 440, 420, 420, 381, 429, 414, 234, 207, 440, 440,45 440, 394, 759, 436, 456, 452, 469, 432, 410, 457, 475, 220, 435, 466, 407,46 530, 501, 462, 451, 450, 453, 426, 439, 477, 457, 646, 449, 442, 401, 318,47 363, 318, 406, 392, 194, 425, 431, 413, 431, 417, 285, 423, 432, 212, 206,48 421, 191, 657, 432, 424, 435, 435, 304, 387, 275, 432, 399, 575, 398, 387,49 365, 298, 159, 298, 471,50];51const LSB = [52 0, 67, 20, 48, 36, 62, 36, 20, -1, 61, 19, 29, 34, 29, 37, 21, 44, 10, 33, 32,53 19, 45, 45, 19, 44, 26, 54, 38, 29, 29, 29, 24, 43, 12, 62, 48, 62, 62, 62,54 48, 62, 62, 19, 62, 62, 60, 62, 48, 61, 48, 62, 36, 30, 57, 31, 26, 32, 32,55 29, 27, 50, 96, 30, 19, 25, 34, 52, 43, 43, 43, 25, 43, 52, 41, -39, 52, 48,56 52, 52, 43, 57, 43, 52, 35, 21, 48, 21, 21, 18, 16, 28, 27, 31, 27, 29,57];58const RSB = [59 200, 66, 21, 48, 35, 62, 42, 21, 62, -1, 19, 29, 38, 29, 37, 50, 44, 51, 24,60 45, 19, 32, 31, 15, 45, 45, 52, 38, 29, 29, 29, 26, 43, 13, 30, 43, 52, 35,61 14, 48, 62, 62, 62, 18, 11, 59, 62, 48, 29, 48, 26, 35, 30, 57, 29, 24, 32,62 30, 33, 96, 21, 27, 32, 19, 23, 43, 44, 33, 53, 38, 29, 45, 47, 43, 41, 25,63 47, 48, 47, 42, 43, 57, 9, 25, 24, 53, 20, 19, 18, 15, 27, 26, 32, 26, 29,64];65const KERN = new Map(66 [67 "+2-9 +7-22 ,--6 ,0-38 ,7-29 ,K-11 ,L-11 ,T-49 ,V-28 ,W-28 ,X10 ,Y-62",68 ",c-6 ,d-6 ,e-6 ,g-6 ,o-6 ,q-6 ,v-13 ,w-13 ,y-13 -,-6 -.-6 -v-15 -w-15",69 "-x-12 -y-15 .--6 .0-38 .7-29 .K-11 .L-11 .T-49 .V-28 .W-28 .X10 .Y-62",70 ".c-6 .d-6 .e-6 .g-6 .o-6 .q-6 .v-13 .w-13 .y-13 /--49 /A-68 /B-12 /C-29",71 "/D-12 /E-12 /F-12 /G-29 /K-17 /L-22 /N-12 /O-29 /P-12 /Q-29 /R-11 /S-11",72 "/a-52 /c-49 /d-49 /e-49 /g-14 /m-9 /n-9 /o-49 /p-9 /q-14 /r-9 /s-22",73 "/u-13 /v-18 /w-18 /y-18 /z-13 11-17 21-27 31-32 41-48 47-50 51-17 61-22",74 "7,-51 7.-51 7/-72 71-6 81-28 91-28 A/7 AA28 AC-13 AG-13 AO-13 AQ-13",75 "AS-21 AT-60 AV-63 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-14 kd-14 ke-14",105 "kf-8 kg-13 ko-14 kq-13 ks-13 kt-8 m,-11 m.-11 mx-9 n,-11 n.-11 nx-9",106 "o,-6 o.-6 ov-15 ow-15 ox-12 oy-15 p,-11 p.-11 px-9 qv-11 qw-11 qy-11",107 "rg-8 rq-8 rv11 rw11 ry11 ss-19 sv-13 sw-13 sx-9 sy-13 v,-13 v--10 v.-13",108 "v/-18 va-9 vc-10 vd-10 ve-10 vg-18 vo-10 vq-18 vs-10 vv11 vw11 vy11",109 "w,-13 w--10 w.-13 w/-18 wa-9 wc-10 wd-10 we-10 wg-18 wo-10 wq-18 ws-10",110 "wv11 ww11 wy11 x--13 xc-13 xd-13 xe-13 xo-13 y,-13 y--10 y.-13 y/-18",111 "ya-9 yc-10 yd-10 ye-10 yg-18 yo-10 yq-18 ys-10 yv11 yw11 yy11 z/9",112 ]113 .join(" ")114 .split(" ")115 .map((p) => [p.slice(0, 2), Number(p.slice(2)) / 1000] as const),116);117const CAP = 0.7;118const TRACK = -0.01;119120// Beat sheet (30fps, speed 1, beat 11):121// -2–45 one word per beat slams in from alternating sides, already at its122// final size, overshoots by ~1% of the frame and settles; rows are123// justified edge to edge, so each word lands in a fixed grid slot124// 46–58 the stack locks: the open leading between rows closes up125// 58– poster hold126const FIRST_AT = -2;127const SLAM_LEN = 8;128const SETTLE_LEN = 6;129const LOCK_LEN = 12;130131const SLAM = Easing.bezier(0.2, 0.9, 0.35, 1);132const SETTLE = Easing.bezier(0.45, 0, 0.55, 1);133const LOCK = Easing.bezier(0.65, 0, 0.2, 1);134const CLAMP = {135 extrapolateLeft: "clamp",136 extrapolateRight: "clamp",137} as const;138139// gradients.sh "rise" (bg #030306): a sunrise lighting the hero word from below.140// The light stage drops the palest stop so the word keeps its edge on off-white.141const THEMES = {142 dark: {143 stage: "#0A0A0B",144 ink: "#F3F2EF",145 rise: ["#fff1e2", "#ff8a3d", "#a3301a"],146 },147 light: {148 stage: "#F5F4F0",149 ink: "#121214",150 rise: ["#ff8a3d", "#a3301a", "#2a0d0a"],151 },152} as const;153154function code(ch: string) {155 const c = ch.charCodeAt(0);156 if (c >= 32 && c < 127) return c - 32;157 if (ch === "’" || ch === "‘") return 7;158 return 46;159}160161function advance(text: string) {162 let adv = 0;163 for (let i = 0; i < text.length; i++) {164 adv += ADV[code(text[i])] / 1000;165 if (i > 0) adv += (KERN.get(text[i - 1] + text[i]) ?? 0) + TRACK;166 }167 return adv;168}169170// A tight word space: the rows read as blocks, not sentences.171const SPACE = 0.15;172173interface Row {174 words: number[];175 /** Pen offset of each word from the row's pen start, in em. */176 offsets: number[];177 lsb: number;178 ink: number;179}180181function buildRow(words: string[], ids: number[]): Row {182 const offsets: number[] = [];183 let pen = 0;184 for (const id of ids) {185 offsets.push(pen);186 pen += advance(words[id]) + SPACE;187 }188 pen -= SPACE;189 const first = words[ids[0]];190 const last = words[ids[ids.length - 1]];191 const lsb = LSB[code(first[0] ?? " ")] / 1000;192 const rsb = RSB[code(last[last.length - 1] ?? " ")] / 1000;193 return { words: ids, offsets, lsb, ink: Math.max(0.2, pen - lsb - rsb) };194}195196/**197 * Groups consecutive words into rows so that, with every row scaled to the198 * full measure, the stack fills the frame height as closely as possible.199 */200function layoutRows(201 words: string[],202 measure: number,203 room: number,204 gap: number,205) {206 const n = words.length;207 let best: Row[] = [];208 let bestScore = Number.POSITIVE_INFINITY;209 for (let mask = 0; mask < 1 << Math.max(0, n - 1); mask++) {210 const rows: Row[] = [];211 let ids: number[] = [];212 for (let i = 0; i < n; i++) {213 ids.push(i);214 if (i === n - 1 || mask & (1 << i)) {215 rows.push(buildRow(words, ids));216 ids = [];217 }218 }219 const height =220 rows.reduce((h, r) => h + (CAP * measure) / r.ink, 0) +221 gap * (rows.length - 1);222 const score = height > room ? (height - room) * 2.5 : room - height;223 if (score < bestScore) {224 bestScore = score;225 best = rows;226 }227 }228 return best;229}230231/** The foreground at `scale`, around the frame's center; nothing extra at 1. */232function ScaleLayer({233 scale,234 children,235}: {236 scale: number;237 children: React.ReactNode;238}) {239 if (scale === 1) return children;240 return (241 <AbsoluteFill style={{ transform: `scale(${scale})` }}>242 {children}243 </AbsoluteFill>244 );245}246247export function FullBleedType({248 words = ["NO", "DAYS", "OFF", "SHIP"],249 beat = 11,250 slam: slamLen = SLAM_LEN,251 ink,252 background,253 fontFamily = display,254 scale = 1,255 delay = 0,256 theme = "dark",257 speed = 1,258}: FullBleedTypeProps) {259 const t = Math.max(0, useCurrentFrame() - delay) * speed;260 const { width: W, height: H } = useVideoConfig();261 const c = THEMES[theme];262 const fg = ink ?? c.ink;263 const stage =264 background === "transparent" ? "transparent" : (background ?? c.stage);265 const gradId = `fb${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;266267 const list = words.map((w) => w.trim().toUpperCase()).filter(Boolean);268 const margin = 0.036 * W;269 const lockGap = 0.026 * H;270 const openGap = 0.075 * H;271 const room = H - 2 * 0.07 * H;272 const rows = layoutRows(list, W - 2 * margin, room, lockGap);273274 const sizes0 = rows.map((r) => (W - 2 * margin) / r.ink);275 const height0 =276 sizes0.reduce((h, s) => h + CAP * s, 0) + lockGap * (rows.length - 1);277 // Too tall even at the best grouping: shrink the whole stack, keep it centered.278 const fit = Math.min(1, room / height0);279 const sizes = sizes0.map((s) => s * fit);280 const measure = (W - 2 * margin) * fit;281 const left = (W - measure) / 2;282283 const lastAt = FIRST_AT + (list.length - 1) * beat;284 const lockAt = lastAt + slamLen + SETTLE_LEN;285 const lock = LOCK(interpolate(t, [lockAt, lockAt + LOCK_LEN], [0, 1], CLAMP));286 const gap = openGap + (lockGap * fit - openGap) * lock;287 const stackH =288 sizes.reduce((h, s) => h + CAP * s, 0) + gap * (rows.length - 1);289290 let y = (H - stackH) / 2;291 const glyphs = rows.flatMap((row, r) => {292 const fs = sizes[r];293 const baseline = y + CAP * fs;294 y = baseline + gap;295 const penX = left - row.lsb * fs;296 return row.words.map((id, j) => {297 const word = list[id];298 const x = penX + row.offsets[j] * fs;299 const w = advance(word) * fs;300 const fromLeft = id % 2 === 0;301 const at = FIRST_AT + id * beat;302 const enter = fromLeft ? -(x + w) - 0.04 * W : W - x + 0.04 * W;303 const over = (fromLeft ? 1 : -1) * 0.011 * W;304 const slam = SLAM(interpolate(t, [at, at + slamLen], [0, 1], CLAMP));305 const settle = SETTLE(306 interpolate(307 t,308 [at + slamLen, at + slamLen + SETTLE_LEN],309 [0, 1],310 CLAMP,311 ),312 );313 const dx = enter + (over - enter) * slam - over * settle;314 return {315 key: `${id}-${word}`,316 word,317 x: x + dx,318 baseline,319 fs,320 hero: id === list.length - 1,321 visible: t >= at,322 };323 });324 });325326 // The sunrise sits on the hero word's baseline and climbs a little over the327 // shot, so the word warms up while it holds.328 const hero = glyphs[glyphs.length - 1];329 const heroCap = hero ? CAP * hero.fs : 0;330 const climb = interpolate(t, [lastAt, lockAt + LOCK_LEN + 30], [0, 1], {331 ...CLAMP,332 easing: Easing.bezier(0.33, 0, 0.3, 1),333 });334 const sunY = hero ? hero.baseline + heroCap * (0.14 - 0.12 * climb) : 0;335336 return (337 <AbsoluteFill style={{ background: stage }}>338 <ScaleLayer scale={scale}>339 <svg340 width={W}341 height={H}342 viewBox={`0 0 ${W} ${H}`}343 style={{ position: "absolute", inset: 0 }}344 aria-label={list.join(" ")}345 role="img"346 >347 <defs>348 <linearGradient349 id={gradId}350 gradientUnits="userSpaceOnUse"351 x1={0}352 y1={sunY}353 x2={0}354 y2={sunY - heroCap * 1.12}355 >356 <stop offset="0" stopColor={c.rise[0]} />357 <stop offset="0.42" stopColor={c.rise[1]} />358 <stop offset="1" stopColor={c.rise[2]} />359 </linearGradient>360 </defs>361 {glyphs.map((g) =>362 g.visible ? (363 <text364 key={g.key}365 x={g.x}366 y={g.baseline}367 fill={g.hero ? `url(#${gradId})` : fg}368 fontFamily={fontFamily}369 fontWeight={500}370 fontSize={g.fs}371 style={{ letterSpacing: `${TRACK}em`, fontKerning: "normal" }}372 >373 {g.word}374 </text>375 ) : null,376 )}377 </svg>378 </ScaleLayer>379 </AbsoluteFill>380 );381}









