Text Highlight
Text highlight animation: marker highlighter, underline, strikethrough and shimmer on a word. Animated emphasis on one span inside a static sentence — marker sweep, color shift, underline, strikethrough-replace, or shimmer.
Source
components/kuchi/text-highlight.tsx
1"use client";23import {4 Easing,5 getRemotionEnvironment,6 Img,7 interpolate,8 interpolateColors,9 spring,10 staticFile,11 useCurrentFrame,12 useVideoConfig,13} from "remotion";14import {15 parseColor,16 resolveFont,17 rgbToOklch,18 type KuchiTheme,19 useKuchiTheme,20 withAlpha,21} from "@/lib/kuchi-ui";2223export type TextHighlightPreset =24 | "logo-wipe"25 | "marker"26 | "color"27 | "underline"28 | "strikethrough"29 | "shimmer";3031export interface TextHighlightSpringConfig {32 damping?: number;33 mass?: number;34 stiffness?: number;35}3637/**38 * Rewrite root-relative assets through staticFile everywhere but the Player —39 * Remotion Studio serves `public/` through it as much as a render does.40 *41 * A page serves `/logo/mark.png` from `public/`; a Remotion bundle does not —42 * it 404s, and `<Img>` turns that into a `cancelRender` that kills the whole43 * render rather than showing a broken image. Same helper as `logo-flicker`,44 * `logo-assemble` and `moodboard-reveal`; kept per-file on purpose, because a45 * registry component has to stand alone in whatever project copies it.46 */47function resolveSrc(src: string): string {48 const isLocal = src.startsWith("/") && !src.startsWith("//");49 if (!isLocal || getRemotionEnvironment().isPlayer) return src;50 // A value that already came out of staticFile() carries the static base51 // (`/static-<hash>/…`); running it through again would prefix it twice.52 const base = staticFile("_").slice(0, -2);53 if (base && src.startsWith(`${base}/`)) return src;54 try {55 return staticFile(src.replace(/^\/+/, ""));56 } catch {57 return src;58 }59}6061/** The lighter of two colours — a specular highlight follows the light, not the mode. */62function lighterOf(a: string, b: string): string {63 return (rgbToOklch(parseColor(a)).l ?? 0) >=64 (rgbToOklch(parseColor(b)).l ?? 0)65 ? a66 : b;67}6869/** Default line thickness for underline/strikethrough, derived from font size. */70export function defaultThickness(fontSize: number): number {71 return Math.max(2, Math.round(fontSize * 0.08));72}7374/**75 * Strikethrough timeline. The line draws over `drawDuration` frames (0–40% of76 * the emphasis window), then the old text crossfades into the replacement77 * over half that long (40–60%), then holds.78 */79export function strikethroughPhases(80 startAt: number,81 drawDuration: number,82): { drawStart: number; drawEnd: number; fadeStart: number; fadeEnd: number } {83 const drawEnd = startAt + drawDuration;84 return {85 drawStart: startAt,86 drawEnd,87 fadeStart: drawEnd,88 fadeEnd: drawEnd + drawDuration * 0.5,89 };90}9192/**93 * Apparent size of something travelling toward the camera. `travel` is 0 at rest94 * and 1 at the eye. Size goes as `1 / (1 - travel)`, so it creeps for most of the95 * trip and then blows up right at the end — which is the whole character of a96 * thing coming at your face, and is not something an easing curve can fake. The97 * reference bears this out: the mark sat at 1.4x for over half the rush and then98 * went to 12x in the last few frames.99 */100export function perspectiveScale(travel: number, maxScale: number): number {101 if (maxScale <= 1) return 1;102 const p = 1 - 1 / maxScale;103 return 1 / (1 - p * Math.min(Math.max(travel, 0), 0.9999));104}105106/**107 * The mark's lateral position along the swing, in *world* units — before the projection108 * multiplies it by the apparent scale.109 *110 * `drift · travel` is the crossing: it carries the mark from the lockup out past the lens111 * on the far side. `out · sin(π · travel)` is the bow: nought at both ends, widest in the112 * middle, and it is the whole difference between a line and an arc. Subtract it and the113 * mark swings wide on the way out, comes round, and the crossing brings it back through114 * and away — one curve, no corner in it.115 *116 * It turns, and turning is not doubling back. A pendulum at the end of its swing has not117 * changed its mind; it is still going, and the moment its lateral speed passes through118 * nought it is travelling at you faster than ever. What you must not do — what a *drift*119 * does — is take it off one way and then send something else back the other.120 */121export function swingWorldX(122 travel: number,123 drift: number,124 out: number,125): number {126 return drift * travel - out * Math.sin(Math.PI * travel);127}128129/**130 * How much the projection magnifies the bow at its widest.131 *132 * The swing is authored in world space and what you *see* is that world path multiplied by133 * the apparent scale — so the arc is at its widest on screen not where the bow is widest134 * (halfway) but where `sin(π · travel) · perspectiveScale(travel)` peaks, out around135 * travel ≈ 0.8, by which point the mark is already several times its resting size. That is136 * the arc doing what an arc coming at your face does: it opens up as it gets near.137 *138 * This finds that peak, and it is the only reason `swingOut` can be quoted in the unit139 * anyone actually thinks in — a fraction of the frame — instead of in world units nobody140 * can picture. It is a good approximation rather than an identity: by the time the bow is141 * at its widest the rightward crossing is already pulling against it, and eats about a142 * fifth. Hence "about" in the prop.143 */144export function swingGain(maxScale: number): number {145 let peak = 1;146 for (let i = 1; i < 128; i++) {147 const t = i / 128;148 const v = Math.sin(Math.PI * t) * perspectiveScale(t, maxScale);149 if (v > peak) peak = v;150 }151 return peak;152}153154/**155 * How far the ink has to reach to close the frame.156 *157 * Nothing here measures the word, so nothing knows where the mark actually *is* — only158 * that the lockup is centred and the mark sits at its left end, which puts its resting159 * centre somewhere in `[0, width / 2]` for any string. The swing then carries it160 * `driftPx` further. This is the distance from the worst of those positions to the161 * furthest corner of the frame, so the last frame is flat colour for a two-letter162 * wordmark and a frame-wide one alike.163 *164 * The old code used a flat `0.85 × diagonal`, which was true only while the mark stayed165 * near the middle. Send it out to one side and the far corner is further away than that166 * — the ink stops just short, and a wedge of backdrop survives in the corner.167 */168export function inkReach(169 width: number,170 height: number,171 driftPx: number,172): number {173 const nearest = driftPx; // a wordmark that fills the frame: the mark rests at its left edge174 const furthest = width / 2 + driftPx; // an empty one: the mark rests at the centre175 const horizontal = Math.max(176 Math.abs(nearest),177 Math.abs(furthest),178 Math.abs(width - nearest),179 Math.abs(width - furthest),180 );181 return Math.hypot(horizontal, height / 2) * 1.05;182}183184/**185 * How much of the mark's swing the ink *does not* follow.186 *187 * Ink is emitted, not carried: the mark punches away and its colour is left in the wake.188 * Pin the disc to the mark and it flies out to the side with it, which drags the burst189 * off-centre — and then the furthest corner of the frame is the one *behind* the mark, so190 * the last thing on screen is a colour edge closing backwards, against the direction the191 * whole shot is travelling.192 *193 * Not 1, though. At nought lag the disc is born under the mark's centre knot, where there194 * is nothing to see; every step away from that walks its birth out toward the mark's flank,195 * where there is.196 */197const INK_LAG = 0.7;198199/** The wipe: the mark leaves and arrives at a standstill, and actually arrives. */200const WIPE_EASE = Easing.bezier(0.2, 0.6, 0.35, 1);201/**202 * The rush — this is the *travel*, not the size. Measured off the reference it is203 * very nearly a constant approach with a little acceleration off the mark; all the204 * drama is the perspective above, not the curve.205 */206const RUSH_EASE = Easing.bezier(0.45, 0.2, 0.45, 1);207208/**209 * Default mark: the kuchi mark, the same path `public/logo.svg` draws.210 *211 * Inline and vector on purpose. The rush blows the mark up ~40x, which is where212 * a raster placeholder turns to mush, and it is drawn in `accentColor` so the213 * mark and the wordmark stay one lockup instead of two colours that have to be214 * kept in step by hand. Override it with the `logo` prop — anything that215 * renders will do — or with `logoSrc` for the easy path.216 *217 * The box is square, like the `<Img>` branch below; the mark is 464x409, so it218 * letterboxes inside it exactly the way `objectFit: "contain"` would.219 */220function SnapMark({ size, color }: { size: number; color: string }) {221 return (222 <svg223 width={size}224 height={size}225 viewBox="0 0 464 409"226 fill="none"227 aria-hidden="true"228 style={{ display: "block" }}229 >230 <title>mark</title>231 <g transform="translate(0,409) scale(0.1,-0.1)">232 <path233 d="M899.8 0H3740.2Q4640 0 4640 899.8V3190.2Q4640 4090 3740.2 4090H899.8Q0 4090 0 3190.2V899.8Q0 0 899.8 0Z"234 fill={color}235 />236 </g>237 </svg>238 );239}240241export interface TextHighlightProps {242 before?: string;243 highlight: string;244 after?: string;245 preset?: TextHighlightPreset;246 /** Overrides the design system's `foreground`. */247 baseColor?: string;248 /** Overrides the design system's `primary`. */249 accentColor?: string;250 /** Design-system token overrides. */251 theme?: Partial<KuchiTheme>;252 mode?: "light" | "dark";253 /**254 * The face this scene paints its words in — a label from `fonts.ts`255 * ("Inter", "Space Grotesk", "Instrument Serif") or a CSS family you have256 * loaded yourself. Unset, the scene keeps the face it was designed around.257 *258 * Overrides `theme.fontFamily`, which is how a brand kit re-skins a whole259 * timeline from one value.260 */261 fontFamily?: string;262 /**263 * Final color of the highlighted span. Defaults to `accentColor` for the264 * "color" and "strikethrough" presets and to `baseColor` otherwise.265 */266 highlightedTextColor?: string;267 /** Strikethrough only: text that crossfades in over the struck span. */268 replaceWith?: string;269 /** Frame at which the emphasis starts. */270 startAt?: number;271 /** Frames the draw/sweep takes. */272 drawDuration?: number;273 springConfig?: TextHighlightSpringConfig;274 /** Underline/strikethrough line thickness. Defaults to round(fontSize * 0.08). */275 thickness?: number;276 /** Shimmer only: color of the sweeping shine. */277 shineColor?: string;278279 /** logo-wipe only: the mark. Defaults to the kuchi mark in `accentColor`. */280 logo?: React.ReactNode;281 /**282 * logo-wipe only: URL of a logo image, the easy way to pass a mark. Loaded283 * through Remotion's `<Img>`, so the frame waits for it instead of rendering a284 * hole. A root-relative path (`/logo/mark.png`) is served by your dev server on285 * a page and by `staticFile()` in a render — this resolves it for both, so you286 * do not have to. An absolute URL is passed through untouched.287 *288 * The rush blows this up to fill the frame — around 40x. Ship art with the289 * resolution to survive that (a few hundred pixels will turn to mush), or an290 * SVG via `logo`, which will not. `logo` wins if you pass both.291 */292 logoSrc?: string;293 /** logo-wipe only: mark size as a multiple of `fontSize`. */294 logoScale?: number;295 /** logo-wipe only: turns the mark spins while it wipes the word open. */296 spinTurns?: number;297 /** logo-wipe only: frames the finished lockup rests before the mark rushes you. */298 holdDuration?: number;299 /** logo-wipe only: frames the rush takes. */300 rushDuration?: number;301 /**302 * logo-wipe only: how many times its resting size the mark reaches by the end of the303 * rush.304 *305 * It has to be big enough that the mark's own body **overruns the frame** — at the306 * defaults it starts about 59px across and 42x takes it past 2,400px against a 1,280px307 * frame. That is not showmanship, it is what makes the ending possible at all. The ink308 * has to close over the *left* of the frame while the mark is travelling *right*, and309 * the only way to do that without something sweeping leftward across the screen — a310 * wall, a roller, call it what you like; it is a second momentum and it looks cheap —311 * is for the mark to already be lying over that ground when its ink spreads. Shrink312 * this and the ending has to fetch its colour from somewhere off-stage.313 *314 * Note it is the mark's *box* that overruns the frame, not its ink. A logo with gaps in315 * it scales its holes by exactly as much, so the backdrop keeps showing through them316 * however big it gets — measured on the bundled clover, solid-ink coverage would take317 * 396x. That is what the ink is for.318 */319 rushScale?: number;320 /**321 * logo-wipe only: where the swing *ends up*, as a fraction of the composition width.322 * Positive is right — the mark crosses the frame and goes out past your shoulder.323 *324 * This is the crossing, not the arc. `swingOut` is the arc.325 */326 rushDrift?: number;327 /**328 * logo-wipe only: about how far the mark bows out to the *left* on its way, at the widest329 * point of the arc, as a fraction of the composition width. (About: the rightward crossing330 * is already pulling against the bow by the time it peaks, and eats roughly a fifth of it.)331 *332 * This is what makes the rush a swing instead of a slide. The mark leaves the lockup,333 * arcs wide, comes round, and passes the lens on the other side — a semicircle from the334 * screen to your eye, and it is a single curve with no corner in it.335 *336 * It is not free decoration. The mark has to be *lying over the left of the frame* when337 * its ink bursts, or the colour has to come and find that ground from somewhere, which338 * means something sweeping backwards across the screen. The bow is what puts it there:339 * it is still left of centre at the moment it goes off, so the ink is born on the left340 * and opens out to the right, following the mark out. Take the bow away and the ink has341 * to close leftward against everything else in the shot.342 *343 * Keep it under about a third of the width. The mark rests at the left end of a centred344 * lockup, so a long wordmark starts it near the left edge already, and a big enough bow345 * will walk it off the side — and a mark that leaves the frame has to come back, which is346 * the one thing this ending must never do.347 */348 swingOut?: number;349 /**350 * logo-wipe only: the colour the mark's ink floods out in, and the colour the frame351 * ends on. Defaults to `accentColor`; set it to your mark's own colour if you pass a352 * `logoSrc` that is not the accent. Set it to `"transparent"` to end on the giant mark353 * with the backdrop still showing through it.354 *355 * The ink is a **shape** and it comes **out of the mark** — a hard-edged disc born356 * inside the mark's own centre knot, where it cannot be seen, which then outruns it.357 * Both of those are load-bearing. Slide a coloured rectangle in from an edge instead and358 * it reads as paint being rolled onto the screen by something off-stage. Fade one up to359 * opaque and you get a half-transparent film lying over the backdrop for several frames,360 * which reads as nothing but "the screen turned blue". Ink coming out of the mark is the361 * mark *arriving*, which is the thing that is actually happening.362 *363 * It is keyed to the mark's size, never to the clock, so it cannot begin before the mark364 * already overruns the frame.365 */366 coverColor?: string;367368 fontSize?: number;369 fontWeight?: number;370 speed?: number;371 className?: string;372}373374export function TextHighlight({375 before = "",376 highlight,377 after = "",378 preset = "logo-wipe",379 baseColor,380 accentColor,381 theme,382 mode,383 fontFamily,384 highlightedTextColor,385 replaceWith,386 startAt = 6,387 drawDuration = 14,388 springConfig,389 thickness,390 shineColor,391 logo,392 logoSrc,393 logoScale = 1.05,394 spinTurns = 1,395 holdDuration = 12,396 rushDuration = 24,397 rushScale = 42,398 rushDrift = 0.55,399 swingOut = 0.25,400 coverColor,401 fontSize = 56,402 fontWeight = 600,403 speed = 1,404 className,405}: TextHighlightProps) {406 const frame = useCurrentFrame() * speed;407 const { fps, width, height } = useVideoConfig();408 const t = useKuchiTheme(theme, mode);409 const face =410 resolveFont(fontFamily ?? t.fontFamily) ??411 "Inter, -apple-system, BlinkMacSystemFont, sans-serif";412 const base = baseColor ?? t.foreground;413 const accent = accentColor ?? t.primary;414 // A gloss sweep is white light in both modes, so it takes whichever of the415 // page's two extremes is actually the lighter one rather than a fixed token.416 const shine = shineColor ?? lighterOf(t.card, t.foreground);417418 const emphasisColor =419 highlightedTextColor ??420 (preset === "color" || preset === "strikethrough" ? accent : base);421 const lineThickness = thickness ?? defaultThickness(fontSize);422423 // High-damping sweep (no bounce) shared by marker + underline.424 const sweep = spring({425 frame: frame - startAt,426 fps,427 config: { damping: 18, ...springConfig },428 durationInFrames: drawDuration,429 });430431 const textStyle: React.CSSProperties = {432 fontSize,433 fontWeight,434 color: base,435 letterSpacing: "-0.02em",436 lineHeight: 1.25,437 fontFamily: face,438 whiteSpace: "pre-wrap",439 textAlign: "center",440 maxWidth: "80%",441 };442443 if (preset === "logo-wipe") {444 // 0 → 1 as the mark travels from the word's right end to its left end.445 const wipe = interpolate(frame, [startAt, startAt + drawDuration], [0, 1], {446 extrapolateLeft: "clamp",447 extrapolateRight: "clamp",448 easing: WIPE_EASE,449 });450 // The wipe edge, as a fraction of the word's own width. It is the one number451 // the whole reveal turns on: the word is clipped to everything right of it,452 // and the mark rides it. Everything is a percentage of the word's box, so453 // nothing here needs measuring.454 const edge = (1 - wipe) * 100;455456 const rushStart = startAt + drawDuration + holdDuration;457 const travel = interpolate(458 frame,459 [rushStart, rushStart + rushDuration],460 [0, 1],461 {462 extrapolateLeft: "clamp",463 extrapolateRight: "clamp",464 easing: RUSH_EASE,465 },466 );467468 const markSize = fontSize * logoScale;469 // How big the mark is *right now*, as a multiple of its resting size.470 const rushed = perspectiveScale(travel, rushScale);471 const markBox = markSize * rushed;472 const diagonal = Math.hypot(width, height);473474 // The swing, and it is built where it belongs: in *world* space, then projected.475 //476 // The world path is a crossing with a bow pulled out of it (`swingWorldX`), and the477 // projection multiplies it by the apparent scale. That one multiply is the whole478 // effect. The same world path is a nudge while the mark is far away and a whip across479 // the frame once it is at the lens, which is what an arc coming at your face actually480 // does — it opens up as it arrives. Author the offset in screen pixels instead and no481 // curve you pick will fix it: you get a shape sliding around on glass, in front of the482 // scene rather than through it. I shipped that too.483 //484 // `swingGain` is what lets `swingOut` be quoted as a fraction of the frame: it is the485 // factor the projection applies to the bow at its widest, so dividing it back out here486 // means the arc lands exactly as wide on screen as the prop asked for.487 const worldDrift = (rushDrift * width) / rushScale;488 const worldBow = (swingOut * width) / swingGain(rushScale);489 const swingPx = rushed * swingWorldX(travel, worldDrift, worldBow);490491 // The ink, keyed to the mark's size — never to the clock, so it cannot begin while492 // the mark is small.493 //494 // Where the window *opens* is the whole ballgame, and the honest answer came out of495 // rendering the frames rather than reasoning about them. Under a perspective rush the496 // apparent size goes as 1/(1-travel), so every size threshold near the top is crossed497 // within a frame or two of every other one, and the disc has to lay down the entire498 // frame in whatever frames are left. Measured, on the fill it puts on screen:499 //500 // gate at 1.00 × diagonal 52 → 88 → 100 a cut, in two frames501 // gate at 0.50 × diagonal 6 → 54 → 83 → 100 still a cut, in three502 // gate at 0.25 × diagonal 4 → 17 → 49 → 77 → 93 → 100503 //504 // So it opens at a quarter of the diagonal, which sounds far too early and is not:505 // the disc is *born inside the mark's own centre knot* (radius = 3% of the box) where506 // there is nothing to see, and it does not clear the mark's ink for another three507 // frames. It cannot look like a blue screen with a logo on it, because at the moment508 // it starts it is smaller than the logo.509 const flood = interpolate(510 markBox,511 [diagonal * 0.55, diagonal * 1.45],512 [0, 1],513 { extrapolateLeft: "clamp", extrapolateRight: "clamp" },514 );515 // Where the ink actually sits, which is behind the mark — so the reach it has to516 // manage is measured from there, not from wherever the mark has whipped off to.517 const inkPx = swingPx * (1 - INK_LAG);518 const floodRadius =519 flood <= 0520 ? 0521 : interpolate(522 flood,523 [0, 1],524 [525 markBox * 0.03,526 inkReach(width, height, rushDrift * width * (1 - INK_LAG)),527 ],528 );529530 return (531 <div532 style={{533 position: "absolute",534 inset: 0,535 display: "flex",536 alignItems: "center",537 justifyContent: "center",538 // The mark grows well past the frame. Nothing may crop it.539 overflow: "visible",540 }}541 >542 {/* The lockup. The left padding reserves the mark's slot, so flex centres543 [mark][word] as one object rather than centring the word alone and544 leaving the mark hanging off the side. */}545 <div546 className={className}547 style={{548 position: "relative",549 paddingLeft: markSize + fontSize * 0.3,550 }}551 >552 <span553 style={{554 ...textStyle,555 position: "relative",556 display: "inline-block",557 maxWidth: undefined,558 whiteSpace: "nowrap",559 }}560 >561 {/* Only what is right of the edge exists yet. A clip, not a fade —562 the letters arrive already solid, the way a lid sliding off a563 thing reveals it. Percentages resolve against this span's own box,564 which is what makes the whole reveal measurement-free. */}565 <span566 style={{567 display: "block",568 clipPath: `inset(0 0 0 ${edge}%)`,569 // The word does not leave — it gets swallowed. The mark blows up straight570 // through it on its way out, and the ink takes what is left, so nothing571 // fades: a word that is *erased* is worth more than a word that was572 // already gone. It also means the frame is never empty, which is what573 // fading it cost when the mark went with it.574 //575 // The reference runs the wordmark from the accent into the base576 // colour, left to right. Painted through the glyphs, so it moves577 // with them and needs no second element.578 backgroundImage: `linear-gradient(90deg, ${accent}, ${emphasisColor})`,579 backgroundClip: "text",580 WebkitBackgroundClip: "text",581 color: "transparent",582 }}583 >584 {highlight}585 </span>586587 {/* The mark. `left` is a percentage of the word's box, so it rides the588 wipe edge exactly; `-100%` of its own width parks it just clear of589 the letters, which is where it comes to rest as the logo.590591 Two nested elements, and the nesting is load-bearing. The outer one592 *places* the mark — including the sideways swing of the rush, which593 has to live out here in frame pixels. Put the swing inside the594 scale and it would be multiplied by it, so a 200px swing becomes a595 2,800px one the moment the mark is 14x. The inner one only spins596 and grows, about its own centre. */}597 <div598 aria-hidden="true"599 style={{600 position: "absolute",601 top: "50%",602 left: `${edge}%`,603 // `max-content`, and it is not optional. This box is absolutely604 // positioned at `left: 100%` for most of the wipe, so the width605 // available to it is (containing block - left) = *zero*, and an606 // auto-width box there is shrink-to-fit: it asks its content for a607 // minimum width and collapses to that. An <svg width={58}> answers608 // "58" and holds it open. An <img> under Tailwind's preflight609 // (`img { max-width: 100% }`) answers "I can be 0" — so the box610 // collapses, 100% of 0 is 0, and the mark renders zero pixels wide.611 // Which is a blank frame and a Player with nothing to draw.612 //613 // It does not reproduce in a Remotion render: a bundle has no614 // preflight. It reproduces in every project that installs this.615 width: "max-content",616 translate: `calc(-100% - ${fontSize * 0.16}px + ${swingPx}px) -50%`,617 }}618 >619 {/* The last beat, and it is a shape — not an opacity, and not something620 arriving from off-stage.621622 The mark cannot close its own holes by growing, because they grow with623 it. So its ink floods out from the middle of it: a disc, in the mark's624 own colour, centred on the mark and carried along by it. It starts life625 *inside* the mark's centre knot, where it cannot be seen, and then626 outruns it.627628 This is also the only way the frame can end on flat colour while the mark629 is on its way *out to the right*. The colour has to close over the left of630 the frame too, and there are exactly two ways to get it there: something631 travelling leftwards across the screen — which is a second momentum, and632 it reads as paint being rolled on by an off-stage hand — or the mark633 already lying over that ground when its ink spreads. Hence the size: by634 the time the ink moves, the mark's arms are past all four corners, and635 what closes the left of the frame is the gaps between them filling in.636 That is ink arriving, and it is the only thing that reads as one gesture.637638 Both ends are keyed to the mark's *size*, never to the clock, so it cannot639 start before the mark has already overrun the frame. */}640 <div641 aria-hidden="true"642 style={{643 position: "absolute",644 left: "50%",645 top: "50%",646 // Back out the share of the swing the ink does not follow (INK_LAG),647 // in frame pixels — the mark pulls ahead of its own colour.648 translate: `calc(-50% - ${swingPx - inkPx}px) -50%`,649 borderRadius: "50%",650 background: coverColor ?? accent,651 width: 2 * floodRadius,652 height: 2 * floodRadius,653 }}654 />655 <div656 style={{657 transformOrigin: "50% 50%",658 rotate: `${spinTurns * 360 * wipe + 30 * travel}deg`,659 // Grows into the lockup, rests, then comes at you. The two are660 // separate — the first clamps once the wipe lands, the second is661 // 1 until the rush starts — so they simply multiply.662 scale: `${663 interpolate(wipe, [0, 1], [0.55, 1], {664 extrapolateLeft: "clamp",665 extrapolateRight: "clamp",666 }) * rushed667 }`,668 }}669 >670 {/* `logo` (any node — an SVG scales forever) beats `logoSrc` (a671 URL, the easy path) beats the built-in mark. */}672 {logo ??673 (logoSrc ? (674 // Remotion's <Img>, not <img>: it holds the frame until the675 // image has decoded. A bare <img> renders frame 0 as a hole676 // and you find out from someone else's screenshot.677 <Img678 src={resolveSrc(logoSrc)}679 alt=""680 style={{681 display: "block",682 width: markSize,683 height: markSize,684 // Tailwind's preflight caps every img at `max-width: 100%`.685 // Here that is a bug, not a safety net — see the note on686 // the placement box above. Opt out explicitly.687 maxWidth: "none",688 objectFit: "contain",689 }}690 />691 ) : (692 <SnapMark size={markSize} color={accent} />693 ))}694 </div>695 </div>696 </span>697 </div>698 </div>699 );700 }701702 let highlightNode: React.ReactNode;703704 if (preset === "marker") {705 highlightNode = (706 <span style={{ position: "relative", display: "inline-block" }}>707 <span708 aria-hidden709 style={{710 position: "absolute",711 inset: "-0.02em -0.12em",712 background: withAlpha(accent, 0.16),713 borderRadius: "0.12em",714 transformOrigin: "left center",715 transform: `scaleX(${sweep})`,716 zIndex: 0,717 }}718 />719 <span720 style={{721 position: "relative",722 zIndex: 1,723 color: interpolateColors(724 interpolate(sweep, [0.5, 0.85], [0, 1], {725 extrapolateLeft: "clamp",726 extrapolateRight: "clamp",727 }),728 [0, 1],729 [base, emphasisColor],730 ),731 }}732 >733 {highlight}734 </span>735 </span>736 );737 } else if (preset === "color") {738 highlightNode = (739 <span740 style={{741 color: interpolateColors(742 interpolate(frame, [startAt, startAt + drawDuration], [0, 1], {743 extrapolateLeft: "clamp",744 extrapolateRight: "clamp",745 }),746 [0, 1],747 [base, emphasisColor],748 ),749 }}750 >751 {highlight}752 </span>753 );754 } else if (preset === "underline") {755 highlightNode = (756 <span style={{ position: "relative", display: "inline-block" }}>757 <span758 style={{759 color: interpolateColors(760 interpolate(sweep, [0.5, 0.85], [0, 1], {761 extrapolateLeft: "clamp",762 extrapolateRight: "clamp",763 }),764 [0, 1],765 [base, emphasisColor],766 ),767 }}768 >769 {highlight}770 </span>771 <span772 aria-hidden773 style={{774 position: "absolute",775 left: 0,776 right: 0,777 bottom: "-0.06em",778 height: lineThickness,779 background: accent,780 borderRadius: lineThickness / 2,781 transformOrigin: "left center",782 transform: `scaleX(${sweep})`,783 }}784 />785 </span>786 );787 } else if (preset === "strikethrough") {788 const phases = strikethroughPhases(startAt, drawDuration);789 highlightNode = (790 <span791 style={{792 display: "inline-grid",793 verticalAlign: "baseline",794 justifyItems: "center",795 }}796 >797 <span798 style={{799 gridArea: "1 / 1",800 position: "relative",801 whiteSpace: "pre",802 opacity: interpolate(803 frame,804 [phases.fadeStart, phases.fadeEnd],805 [1, 0],806 { extrapolateLeft: "clamp", extrapolateRight: "clamp" },807 ),808 }}809 >810 {highlight}811 <span812 aria-hidden813 style={{814 position: "absolute",815 left: 0,816 top: "50%",817 height: lineThickness,818 width: `${interpolate(819 frame,820 [phases.drawStart, phases.drawEnd],821 [0, 100],822 { extrapolateLeft: "clamp", extrapolateRight: "clamp" },823 )}%`,824 background: accent,825 transform: "translateY(-50%)",826 borderRadius: lineThickness / 2,827 }}828 />829 </span>830 <span831 style={{832 gridArea: "1 / 1",833 whiteSpace: "pre",834 color: emphasisColor,835 opacity: interpolate(836 frame,837 [phases.fadeStart, phases.fadeEnd],838 [0, 1],839 { extrapolateLeft: "clamp", extrapolateRight: "clamp" },840 ),841 transform: `translateY(${interpolate(842 frame,843 [phases.fadeStart, phases.fadeEnd],844 [8, 0],845 { extrapolateLeft: "clamp", extrapolateRight: "clamp" },846 )}px)`,847 }}848 >849 {replaceWith ?? highlight}850 </span>851 </span>852 );853 } else {854 // shimmer855 highlightNode = (856 <span style={{ position: "relative", display: "inline-block" }}>857 <span style={{ color: emphasisColor }}>{highlight}</span>858 <span859 aria-hidden860 style={{861 position: "absolute",862 inset: 0,863 color: "transparent",864 backgroundClip: "text",865 WebkitBackgroundClip: "text",866 backgroundImage: `linear-gradient(110deg, transparent 30%, ${shine} 50%, transparent 70%)`,867 backgroundSize: "200% 100%",868 backgroundPosition: `${interpolate(869 frame,870 [startAt, startAt + drawDuration],871 [200, -100],872 { extrapolateLeft: "clamp", extrapolateRight: "clamp" },873 )}% 50%`,874 }}875 >876 {highlight}877 </span>878 </span>879 );880 }881882 return (883 <div884 style={{885 position: "absolute",886 inset: 0,887 display: "flex",888 alignItems: "center",889 justifyContent: "center",890 }}891 >892 <span className={className} style={textStyle}>893 {before}894 {highlightNode}895 {after}896 </span>897 </div>898 );899}









