Roster Grant
Access granted animation: a cursor clicks a CTA and team avatars switch on. Three rows of roster cards stream past a call to action, a pointer walks in and clicks it, and the monograms start turning to the accent one every seven frames — top row, middle, bottom, top, bottom, middle, so it reads as a system granting rather than a list iterating.
Source
components/kuchi/roster-grant.tsx
1"use client";23import { loadFont as loadSans } from "@remotion/google-fonts/Inter";4import { type CSSProperties, forwardRef, type ReactNode, useMemo } from "react";5import {6 AbsoluteFill,7 getRemotionEnvironment,8 interpolate,9 useCurrentFrame,10 useVideoConfig,11} from "remotion";12import {13 Item,14 mixOklch,15 parseColor,16 resolveFont,17 type KuchiTheme,18 useKuchiTheme,19 withAlpha,20} from "@/lib/kuchi-ui";2122/**23 * Three rows of roster cards drifting past a pill, a pointer that clicks it,24 * and then the roster lighting up one card at a time.25 *26 * It is the "and everyone gets it" shot: the outer rows stream in opposite27 * directions, the middle row parts around a single call to action, a pointer28 * walks in and presses it, the pill flips to the accent, and a beat later the29 * monograms start turning over — not left to right but sprinkled, one every30 * seven frames, so it reads as a system granting rather than a list iterating.31 *32 * Beat by beat, measured off the reference at 30fps:33 *34 * | beat | seconds | what moves |35 * | --- | --- | --- |36 * | settle | 0 – 3.0 | camera 1.184 → 1, the middle row closing on the pill |37 * | approach | 0 – 1.32 | pointer (123, 90) → (104, −3) |38 * | press | 1.62 – 2.33 | pill 1 → 0.931 → 1 |39 * | flip | 1.69 | pill goes accent, on one frame |40 * | leave | 2.05 – 3.1 | pointer out to (178, 79) |41 * | grant | 2.333 + n/30 × 7 | one monogram per step |42 * | push | 3.0 – 4.0 | the whole scene pans left, accelerating |43 *44 * The camera and the middle row settle on the **same shape** — a plain45 * `exp(-t / τ)`, no knots — and on nearly the same clock: τ = 0.75 for the46 * pull-back, 0.80 and 0.91 for the gap the middle row leaves either side of the47 * pill. Near enough that the two read as one settle; far enough that forcing48 * them onto one number leaves a card 5px wide through the first half second.49 *50 * The outer rows do **not** run off that clock, and that is the whole texture51 * of the shot. Row 1 covers 372px in four seconds and row 3 covers 355, but row52 * 3 spends a quarter of its travel in the first 0.3s and row 1 does not — so53 * the two are never symmetric about the pill and the frame never reads as a54 * pattern. Fitting both to a shared exponential was tried; it came out 10px55 * wrong through the middle of the shot, which is a third of a card gap, and the56 * rows visibly locked into step. They are measured knots because they are not a57 * formula.58 */5960const { fontFamily: SANS } = loadSans("normal", {61 weights: ["400", "500"],62 subsets: ["latin"],63});6465/* ─────────────────────────────────────────────────────────────────────────66 Geometry, in the reference's own 712×398 pixels67 ───────────────────────────────────────────────────────────────────────── */6869export const REF_W = 712;70export const REF_H = 398;7172/**73 * What the pull-back scales about, and what every content coordinate below is74 * measured from.75 *76 * Horizontally it is where the pill's centre sits for the first fifty frames of77 * the reference without moving a pixel — 356, the middle of the frame. It is78 * the camera's fixed point by measurement, not by assumption.79 */80export const ORIGIN = { x: 356, y: 200 };8182/** Row centre to row centre, at scale 1. */83export const ROW_PITCH = 109.5;8485/**86 * A card, at scale 1.87 *88 * Fixed width, left-aligned content — worth stating because the reference only89 * makes it obvious once: its longest name ends 134px short of the card's right90 * edge. Content-sized chips would have made the rows ragged and the pitch91 * unmeasurable, and the pitch is what the whole marquee is fitted to.92 */93export const CARD = { w: 286, h: 76, radius: 8, gap: 26 };94export const CARD_PITCH = CARD.w + CARD.gap;9596/** Inside a card. */97export const AVATAR = { size: 48, padX: 17.5, initials: 24 };98export const TEXT_X = AVATAR.padX + AVATAR.size + 12;99/** Line boxes at `lineHeight: 1`, offset from the card's top edge. */100export const NAME = { size: 20, top: 16.7, weight: 500 };101export const ROLE = { size: 13, top: 43.3, weight: 400 };102103/** The pill. Content-sized: the padding is measured, the width follows the label. */104export const PILL = {105 h: 43,106 radius: 8,107 padX: 43,108 label: 20,109 /** The reference sets "Give access" with a double word space. */110 wordSpacing: 5,111 iconGap: 22,112 iconW: 24,113 iconH: 20,114};115116/**117 * The pointer — lucide's `MousePointer2`, and where its tip sits in that icon's118 * own 24×24 box.119 *120 * 22, not the reference's 14: the reference draws a plain disc, and an arrow of121 * the same *height* reads smaller because most of its box is empty. 22 puts the122 * arrow's ink at about the disc's weight.123 */124export const CURSOR = { size: 22, tip: { x: 4.04, y: 4.69 } };125126/* ─────────────────────────────────────────────────────────────────────────127 Curves — every number below was read off the reference's own frames128 ───────────────────────────────────────────────────────────────────────── */129130/** The camera's clock. The middle row settles on the same shape a shade slower. */131export const TAU = 0.753;132export const ZOOM = 0.184;133134export function ease(t: number): number {135 return Math.exp(-Math.max(0, t) / TAU);136}137138/**139 * The camera, as a multiple of the settled scale.140 *141 * 1.184 at the first frame down to 1 — fitted, not knotted, because a pure142 * exponential lands inside a pixel at every one of the eleven frames it was143 * checked against. It never actually arrives, which is the point: this shot is144 * still shedding scale at frame 90, and a shot that truly settles reads as a145 * freeze-frame with a marquee glued on.146 */147export function cameraScale(t: number): number {148 return 1 + ZOOM * ease(t);149}150151function knots(152 ts: readonly number[],153 vs: readonly number[],154 t: number,155): number {156 return interpolate(t, ts as number[], vs as number[], {157 extrapolateLeft: "clamp",158 extrapolateRight: "clamp",159 });160}161162/**163 * The top row, streaming left, in content px — its **own** drift, with the164 * camera and the exit pan both taken out.165 *166 * Tracked by aligning each frame against the next *in content space*, undoing167 * the camera first, so what is left is the row's motion and nothing else. A168 * plain screen-space correlation cannot tell a row sliding left from a camera169 * pulling back, and cheerfully reports a decelerating drift for a scene that170 * has none.171 *172 * Then the pan is subtracted, and that subtraction is the check on the whole173 * decomposition: the raw track runs to −372 and never flattens, but −372 minus174 * the pan lands on −258.8 at 3.73 and stays there to the last frame. The rows175 * stop; the camera does not. Left in as measured, the pan gets counted twice176 * and the top row is 34px past the reference by the final second.177 */178export const ROW1_T = [179 0, 0.322, 0.564, 0.964, 1.455, 1.964, 3.172, 3.497, 3.73, 4.005,180];181export const ROW1_V = [182 0, -69.7, -104.5, -144.2, -178.2, -204.5, -242.8, -248.9, -254.8, -258.8,183];184185/** The bottom row, streaming right — front-loaded where the top row is not. */186export const ROW3_T = [187 0, 0.164, 0.247, 0.322, 0.564, 0.805, 1.047, 1.405, 1.855, 2.447, 3.047,188 3.364, 4.005,189];190export const ROW3_V = [191 0, 58.2, 93.6, 119.7, 175.8, 216.2, 247.4, 282.6, 314.5, 342.2, 357.9, 363,192 365,193];194195/** Where a row sits, in content px. The middle row does not drift at all. */196export function rowDrift(row: 0 | 1 | 2, t: number): number {197 if (row === 0) return knots(ROW1_T, ROW1_V, t);198 if (row === 2) return knots(ROW3_T, ROW3_V, t);199 return 0;200}201202/**203 * Where each outer row's slot 0 starts, so the first frame frames like the204 * reference's.205 *206 * Free parameters — the content is ours, so which card sits where is a choice —207 * but not arbitrary ones: these put every monogram within 10px of the208 * reference's for all 121 frames, which is what lets the two clips be diffed209 * on top of each other rather than only compared beat for beat.210 */211export const ROW_PHASE = [-118, 0, -142.3];212213/**214 * The push out of the shot, in content px.215 *216 * Zero for three seconds and then everything — rows, pill, pointer — leaves217 * together, which is what makes it read as a camera and not as more marquee.218 * Measured on the pill's own centre, the one thing in frame with no drift of219 * its own to subtract first.220 */221export const PAN_T = [222 0, 2.95, 3.014, 3.247, 3.447, 3.564, 3.73, 3.814, 3.93, 3.972, 4.005,223];224export const PAN_V = [225 0, 0, -1, -6.5, -16.5, -25.5, -43.4, -55.9, -82.4, -95.4, -113.4,226];227228export function pan(t: number): number {229 return knots(PAN_T, PAN_V, t);230}231232/**233 * How much room the middle row leaves either side of the pill, in content px,234 * as `[floor, amplitude, time constant]`.235 *236 * Its two flanking cards close in — 91 → 51 on the left, 123 → 65 on the right237 * — on the same shape as the camera and, near enough, the same clock: 0.80s and238 * 0.91s against the camera's 0.75s. Near enough to read as one settle, far239 * enough that sharing the camera's number literally puts the right-hand card 5px240 * wide through the first half second.241 *242 * They are asymmetric and stay asymmetric, which is why this is two rows and not243 * one gap: forcing them equal put the right-hand card 14px wrong for a whole244 * second, and a card 14px out of place beside a pill that never moves is the one245 * misalignment the eye finds.246 *247 * This is also the reading that killed "the middle row is a marquee too". Over248 * four seconds its left card travels *right* by 40px while its right card249 * travels left by 58, and no single translation does that.250 */251export const CLEARANCE = {252 left: [51, 57.3, 0.805],253 right: [65, 79.7, 0.91],254} as const;255256export function clearance(side: "left" | "right", t: number): number {257 const [floor, amp, tau] = CLEARANCE[side];258 return floor + amp * Math.exp(-Math.max(0, t) / tau);259}260261/**262 * The pill's own scale under the press.263 *264 * Down in 0.18s, back in 0.53s — three times as long coming up as going down,265 * which is the whole reason a click feels like a click. Symmetric, it feels266 * like a bounce.267 */268export const PRESS_T = [269 1.622, 1.689, 1.764, 1.805, 1.897, 1.964, 2.047, 2.122, 2.205, 2.255, 2.33,270];271export const PRESS_V = [272 1, 0.969, 0.946, 0.931, 0.949, 0.958, 0.968, 0.977, 0.986, 0.995, 1,273];274275export function pressScale(t: number): number {276 return knots(PRESS_T, PRESS_V, t);277}278279/** When the pill turns over. Instant in the reference — no crossfade to find. */280export const FLIP_AT = 1.689;281282/**283 * The pointer, in content px from `ORIGIN`.284 *285 * It arrives in two moves, not one: a fast approach that eases out to a hover286 * about 30px below the pill around t = 0.9, then a second, *accelerating* drop287 * onto the target. That second move peaks at 112px/s — quicker than anything in288 * the first — and it is what makes the click read as a decision rather than as289 * an arrival.290 */291export const CURSOR_T = [292 0, 0.164, 0.247, 0.322, 0.414, 0.489, 0.564, 0.722, 0.889, 0.93, 1.047, 1.164,293 1.289, 1.405, 2.03, 2.089, 2.172, 2.255, 2.33, 2.414, 2.505, 2.605, 2.73,294 2.897, 3.089, 3.289, 3.497, 3.689, 4.005,295];296export const CURSOR_X = [297 123, 117.8, 110.6, 106, 103.8, 102.3, 101.7, 101.3, 101.6, 101.6, 101.8,298 102.5, 103.6, 103.7, 104.9, 107, 112.1, 121.1, 133, 143, 150.2, 158, 163.6,299 168.8, 173, 175.4, 177.9, 178.4, 178.2,300];301export const CURSOR_Y = [302 89.5, 85.4, 76.1, 65.6, 56.6, 49.1, 43.2, 35.4, 30.2, 28.2, 22.2, 13.8, -0.2,303 -2.6, -2.6, 0.5, 5.8, 16.4, 29.6, 40.4, 48.3, 56.8, 62.7, 65.6, 72.9, 75.8,304 77.6, 78.5, 78.7,305];306307/**308 * How far inside the pill's trailing edge the pointer comes to rest, in309 * reference px.310 *311 * Measured: it stops 104px right of centre on a pill 122px wide either side —312 * 18px in from the edge, past the icon rather than on it. Kept as an *inset*313 * rather than as an absolute x, because the pill is content-sized and a short314 * label would otherwise leave the pointer clicking thin air beside it.315 */316export const LAND_INSET = 18;317/** The pill the track was measured against, half-width in content px. */318export const REF_PILL_HALF = 122;319320/**321 * The pointer's place at `t`, in content px from `ORIGIN`.322 *323 * The measured track is the track everywhere except over the pill: there x is324 * pulled in to the pill's own trailing edge, and the pull fades in across the325 * pill's height so no frame ever jumps. Scaling the *whole* track by the pill's326 * width instead moved the pointer's entry and exit too — 13px at the first327 * frame, on a path that has nothing to do with how wide the button is.328 */329export function cursorAt(330 t: number,331 pillHalf: number,332): { x: number; y: number } {333 const x = knots(CURSOR_T, CURSOR_X, t);334 const y = knots(CURSOR_T, CURSOR_Y, t);335 const over = Math.min(1, Math.max(0, (PILL.h * 1.5 - Math.abs(y)) / PILL.h));336 const pull = Math.max(0, x - (pillHalf - LAND_INSET));337 return { x: x - pull * over, y };338}339340/**341 * When the first monogram turns over, and how often after that.342 *343 * Seven frames, not the 7.25 the five measured onsets average to. Four of those344 * five land on a 7-frame grid off 2.333 to the frame; averaging instead put345 * three of them a frame late to buy back one that is two frames early, and a346 * cascade that is consistently a frame behind is worse than one that is right347 * four times out of five.348 */349export const GRANT_AT = 70 / 30;350export const GRANT_STEP = 7 / 30;351352export function granted(order: number, t: number): boolean {353 // A frame's worth of slack, because `70 / 30 + 2 * (7 / 30)` is 2.8000000000000003354 // and the frame it is supposed to fire on is 2.8. Without it the third turn355 // lands one frame late and nothing in the code says why.356 return t + 1e-6 >= GRANT_AT + GRANT_STEP * order;357}358359/* ─────────────────────────────────────────────────────────────────────────360 Content361 ───────────────────────────────────────────────────────────────────────── */362363export interface RosterEntry {364 /** Shown large. */365 name: string;366 /** Shown small, under it. */367 role: string;368 /** Two characters at most. Derived from `name` when omitted. */369 initials?: string;370}371372/**373 * What kuchi is granting: its own registry.374 *375 * Four per row, because at this pitch a row shows three cards at once and a376 * roster of three tiles visibly across the frame.377 */378export const KUCHI_ROSTER: readonly (readonly RosterEntry[])[] = [379 [380 { name: "Text Reveal", role: "Animation" },381 { name: "Prompt Send", role: "Composition" },382 { name: "Logo Drift", role: "Background" },383 { name: "Word Flip", role: "Animation" },384 ],385 [386 { name: "Count Grid", role: "Composition" },387 { name: "Agent Steps", role: "Composition" },388 { name: "Type Morph", role: "Animation" },389 { name: "Text Swell", role: "Animation" },390 ],391 [392 { name: "Karaoke Captions", role: "Composition" },393 { name: "Search Typing", role: "Composition" },394 { name: "Text Highlight", role: "Animation" },395 { name: "Orbit Gallery", role: "Composition" },396 ],397];398399/**400 * Which turn each row takes, over two passes of the three rows.401 *402 * The reference goes top, middle, bottom, top, **bottom, middle** — the second403 * pass swaps the last two, so no row ever grants twice running and the sixth404 * monogram does not land where the third did. Six is the whole visible cascade;405 * it repeats from there.406 */407export const TURNS = [408 [0, 3],409 [1, 5],410 [2, 4],411] as const;412413export function turnOf(row: number, step: number): number {414 return 6 * Math.floor(step / 2) + (TURNS[row % 3]?.[step % 2] ?? 0);415}416417/**418 * Which roster entry a row starts its cascade on.419 *420 * Not entry 0. The marquee has moved 200-odd pixels by the time anything is421 * granted, so whichever entry sits at slot 0 is wherever the drift table left422 * it — keyed on entry 0, the cascade opened on a card whose avatar was 73px off423 * the left edge, and the reference's frame-70 grant did not appear until frame424 * 78. Seeding on the entry nearest the middle of the frame at `GRANT_AT` puts425 * the first monogram where a viewer is already looking, for any phase, any426 * drift and any roster length.427 *428 * Keyed on the roster entry rather than on the marquee slot, so every copy of a429 * card on screen turns over on the same frame: a component is installed once,430 * not once per place it is drawn.431 */432export function grantSeed(433 row: 0 | 1 | 2,434 len: number,435 pillHalf: number,436): number {437 // The *monogram's* distance from the middle, not the card's: a card can be438 // half on screen with its avatar 65px past the left edge, and a grant nobody439 // can see is a grant that did not happen. Seeding on the card instead put the440 // second turn nine frames behind the reference's.441 const reach = REF_W / 2 / cameraScale(GRANT_AT);442 let left = Number.NEGATIVE_INFINITY;443 let leftSlot: number | null = null;444 let near = Number.POSITIVE_INFINITY;445 let nearSlot = 0;446 for (const { slot, u } of slotsFor(row, GRANT_AT, pillHalf)) {447 const disc = u - CARD.w / 2 + AVATAR.padX + AVATAR.size / 2;448 if (Math.abs(disc) > reach - AVATAR.size / 2) continue;449 if (disc <= 0 && disc > left) {450 left = disc;451 leftSlot = slot;452 }453 if (Math.abs(disc) < near) {454 near = Math.abs(disc);455 nearSlot = slot;456 }457 }458 // The nearest monogram *left* of centre, not simply the nearest — because the459 // next entry in the roster is one slot to the right, and a cascade seeded on460 // the right-hand card sends its own second turn off the right edge. That is461 // what the reference does in all three rows, and the one row where it cannot462 // (the middle: the pill hides the card to its left) is the one row it seeds on463 // the right.464 const best = leftSlot ?? nearSlot;465 return ((best % len) + len) % len;466}467468export function grantOrderOf(469 row: 0 | 1 | 2,470 entryIndex: number,471 len: number,472 seed: number,473): number {474 return turnOf(row, (((entryIndex - seed) % len) + len) % len);475}476477export function initialsOf(entry: RosterEntry): string {478 if (entry.initials) return entry.initials;479 return entry.name480 .split(/\s+/)481 .slice(0, 2)482 .map((w) => w[0] ?? "")483 .join("")484 .toUpperCase();485}486487/* ─────────────────────────────────────────────────────────────────────────488 Layout489 ───────────────────────────────────────────────────────────────────────── */490491/**492 * Inter's advance widths, in em, for the characters a button label uses.493 *494 * The pill is drawn `width: max-content`, so the *drawn* pill is always exactly495 * its content plus its padding and no label can ever be cramped. This table is496 * for everything that has to know how wide that pill will be **before** it is497 * drawn — where the middle row's cards sit either side of it, and where the498 * pointer lands on it.499 *500 * It replaced "0.52em to the character", which read a 130px label as 216 and501 * left the pill 30px wider than its own contents: balanced padding, and 15px502 * too much of it on each side. A per-character table is 30 lines of data and it503 * gets "Install all" to within a pixel; a single average cannot get any label504 * right, because the whole point of a label is that you do not know it yet.505 */506const ADVANCE: Record<string, number> = {507 " ": 0.26,508 "-": 0.35,509 ".": 0.27,510 ",": 0.27,511 "'": 0.19,512 "!": 0.29,513 a: 0.541,514 b: 0.578,515 c: 0.512,516 d: 0.578,517 e: 0.541,518 f: 0.34,519 g: 0.578,520 h: 0.552,521 i: 0.24,522 j: 0.24,523 k: 0.512,524 l: 0.24,525 m: 0.827,526 n: 0.552,527 o: 0.571,528 p: 0.578,529 q: 0.578,530 r: 0.351,531 s: 0.501,532 t: 0.35,533 u: 0.552,534 v: 0.499,535 w: 0.753,536 x: 0.501,537 y: 0.499,538 z: 0.474,539 A: 0.665,540 B: 0.654,541 C: 0.677,542 D: 0.7,543 E: 0.6,544 F: 0.578,545 G: 0.72,546 H: 0.71,547 I: 0.273,548 J: 0.531,549 K: 0.644,550 L: 0.57,551 M: 0.872,552 N: 0.73,553 O: 0.747,554 P: 0.635,555 Q: 0.747,556 R: 0.635,557 S: 0.614,558 T: 0.601,559 U: 0.71,560 V: 0.665,561 W: 0.948,562 X: 0.632,563 Y: 0.619,564 Z: 0.601,565};566/** Digits are one width in Inter, and anything unlisted gets a lowercase mean. */567const ADVANCE_FALLBACK = (ch: string) => (/[0-9]/.test(ch) ? 0.6 : 0.55);568569/** How wide the label's text runs, in reference px. */570export function labelWidth(label: string): number {571 let em = 0;572 let spaces = 0;573 for (const ch of label) {574 em += ADVANCE[ch] ?? ADVANCE_FALLBACK(ch);575 if (ch === " ") spaces++;576 }577 return em * PILL.label + spaces * PILL.wordSpacing;578}579580/** The pill's width, in reference px — content plus the measured padding. */581export function pillWidth(label: string): number {582 return PILL.padX * 2 + labelWidth(label.trim()) + PILL.iconGap + PILL.iconW;583}584585/**586 * Where a card sits at rest, in reference px — before the row's own motion.587 *588 * Rows 0 and 2 are plain marquees on a pitch. Row 1 is two stacks anchored to589 * the pill's edges at their *closed* clearance, with the slot behind the pill590 * left empty — see `CLEARANCE` for why it cannot be a marquee.591 */592export function slotRest(593 row: 0 | 1 | 2,594 slot: number,595 pillHalf: number,596): number {597 if (row !== 1) return (ROW_PHASE[row] ?? 0) + slot * CARD_PITCH;598 const edge = pillHalf + CARD.w / 2;599 return slot < 0600 ? -(edge + CLEARANCE.left[0]) + (slot + 1) * CARD_PITCH601 : edge + CLEARANCE.right[0] + slot * CARD_PITCH;602}603604/**605 * How far a row (or, for the middle row, one of its two stacks) has moved from606 * rest at `t` — the one number that is animated, per group, per frame.607 */608export function rowShift(row: 0 | 1 | 2, slot: number, t: number): number {609 if (row !== 1) return rowDrift(row, t);610 const side = slot < 0 ? "left" : "right";611 const open = clearance(side, t) - CLEARANCE[side][0];612 return side === "left" ? -open : open;613}614615/** Where a card actually is at `t`, in reference px. */616export function slotsFor(617 row: 0 | 1 | 2,618 t: number,619 pillHalf: number,620): { slot: number; u: number }[] {621 return slotRange(row, pillHalf).map((slot) => ({622 slot,623 u: slotRest(row, slot, pillHalf) + rowShift(row, slot, t),624 }));625}626627/**628 * Every slot of a row that reaches the frame at **any** point in the clip.629 *630 * Fixed, so the DOM never changes: a card that is drawn is drawn for all 120631 * frames and only its group's `translateX` moves. Mounting and unmounting cards632 * as they cross the edge is a layout pass on a frame that also has to composite633 * a camera move, and it lands on exactly the frames a marquee is least able to634 * hide it — the ones where something is entering.635 */636export function slotRange(row: 0 | 1 | 2, pillHalf: number): number[] {637 let lo = Number.POSITIVE_INFINITY;638 let hi = Number.NEGATIVE_INFINITY;639 // 0.05s is a quarter of the fastest thing in the clip; the union cannot open640 // and close again between two samples.641 for (let t = 0; t <= 4.2; t += 0.05) {642 const reach = REF_W / 2 / cameraScale(t) + CARD.w;643 lo = Math.min(lo, -pan(t) - reach);644 hi = Math.max(hi, -pan(t) + reach);645 }646 // The middle row's stacks are indexed -1, -2, … and 0, 1, … — there is no647 // centre slot to skip, because the pill *is* the gap.648 const out: number[] = [];649 for (let slot = -12; slot <= 12; slot++) {650 let seen = false;651 for (let t = 0; t <= 4.2 && !seen; t += 0.05) {652 const u = slotRest(row, slot, pillHalf) + rowShift(row, slot, t);653 if (u > lo && u < hi) seen = true;654 }655 if (seen) out.push(slot);656 }657 return out;658}659660/* ─────────────────────────────────────────────────────────────────────────661 Component662 ───────────────────────────────────────────────────────────────────────── */663664export interface RosterGrantProps {665 /** Three rows of cards. Each row repeats across the frame. */666 rows?: readonly (readonly RosterEntry[])[];667 /** The pill's label. */668 label?: string;669 /** Overrides the design system's `primary` for the pill and the monograms. */670 accentColor?: string;671 /** Design-system token overrides. */672 theme?: Partial<KuchiTheme>;673 mode?: "light" | "dark";674 /**675 * The face this scene paints its words in — a label from `fonts.ts` or a CSS676 * family you have loaded yourself. Overrides `theme.fontFamily`.677 */678 fontFamily?: string;679 /** 1 is the measured speed. */680 speed?: number;681}682683export function RosterGrant({684 rows = KUCHI_ROSTER,685 label = "Install all",686 accentColor,687 theme,688 mode,689 fontFamily,690 speed = 1,691}: RosterGrantProps) {692 const frame = useCurrentFrame();693 const { fps, width, height } = useVideoConfig();694 // `frame * speed`, so 2 is twice as fast — the convention every other timed695 // scene in this registry uses.696 const t = (frame * speed) / fps;697698 const th = useKuchiTheme(theme, mode);699 const accent = accentColor ?? th.primary;700 const face = resolveFont(fontFamily ?? th.fontFamily) ?? SANS;701702 // Reference px → render px. The whole scene is laid out once in the703 // reference's own 712×398 and then scaled here, so nothing below this line704 // depends on the render size.705 const k = Math.min(width / REF_W, height / REF_H);706 const ox = (width - REF_W * k) / 2;707 const oy = (height - REF_H * k) / 2;708709 const half = pillWidth(label) / 2;710 const point = cursorAt(t, half);711712 // A hairline that belongs to the palette: the token walked most of the way713 // back toward the fill it edges, because `border` at full strength is a714 // shadcn *control* border and these are 76px chips, not controls.715 const edge = mixOklch(th.secondary, th.border, 0.55);716717 // `will-change` is right for the Player and wrong for the render. One718 // continuous tab with an 8ms budget wants the camera handed to the719 // compositor; a render is spread across parallel tabs, each of which would720 // inherit a stale raster from whatever scale *it* drew last.721 const live = !getRemotionEnvironment().isRendering722 ? { willChange: "transform" as const }723 : null;724725 // Fixed for the whole clip, so this is a `useMemo` and not a per-frame scan.726 const ranges = useMemo(727 () => [slotRange(0, half), slotRange(1, half), slotRange(2, half)],728 [half],729 );730731 const groups: ReactNode[] = [];732 // An entry's index in `rows` read row by row — what Studio calls it by.733 let base = 0;734 for (const row of [0, 1, 2] as const) {735 const roster = rows[row] ?? [];736 const first = base;737 base += roster.length;738 if (roster.length === 0) continue;739 const seed = grantSeed(row, roster.length, half);740 // A row repeats its entries across the frame. Studio outlines the copy741 // nearest the middle of the frame; the others are only pictures of it.742 const nearest = new Map<number, number>();743 const held = new Map<number, number>();744 for (const slot of ranges[row] ?? []) {745 const i = ((slot % roster.length) + roster.length) % roster.length;746 const d = Math.abs(747 slotRest(row, slot, half) + rowShift(row, slot, t) + pan(t),748 );749 if (d < (held.get(i) ?? Number.POSITIVE_INFINITY)) {750 held.set(i, d);751 nearest.set(i, slot);752 }753 }754 const y = ORIGIN.y + (row - 1) * ROW_PITCH - CARD.h / 2;755 // One group per thing that moves: a whole row, or — for the middle row —756 // each side of the pill, which close in at different rates.757 const sides = row === 1 ? ([-1, 1] as const) : ([0] as const);758 for (const side of sides) {759 const slots = (ranges[row] ?? []).filter((n) =>760 row === 1 ? (side < 0 ? n < 0 : n >= 0) : true,761 );762 if (slots.length === 0) continue;763 groups.push(764 <div765 key={`${row}:${side}`}766 style={{767 position: "absolute",768 inset: 0,769 transform: `translateX(${rowShift(row, side, t)}px)`,770 ...live,771 }}772 >773 {slots.map((slot) => {774 const i = ((slot % roster.length) + roster.length) % roster.length;775 const entry = roster[i];776 if (!entry) return null;777 return (778 <Item779 key={slot}780 index={first + i}781 primary={nearest.get(i) === slot}782 >783 <Card784 accent={accent}785 edge={edge}786 entry={entry}787 left={slotRest(row, slot, half) + ORIGIN.x - CARD.w / 2}788 on={granted(grantOrderOf(row, i, roster.length, seed), t)}789 th={th}790 top={y}791 />792 </Item>793 );794 })}795 </div>,796 );797 }798 }799800 return (801 <AbsoluteFill802 style={{803 backgroundColor: th.background,804 fontFamily: face,805 // Hinting re-snaps every stem as the camera scale slides and the806 // letterforms boil. This is the fix, and it is not optional in a scene807 // that never stops scaling.808 textRendering: "geometricPrecision",809 overflow: "hidden",810 }}811 >812 {/* A transparent page asks for no page, and the backdrop is the page. */}813 {parseColor(th.background).alpha !== 0 && (814 <Backdrop accent={accent} th={th} />815 )}816 <div817 style={{818 position: "absolute",819 left: ox,820 top: oy,821 width: REF_W,822 height: REF_H,823 transform: `scale(${k})`,824 transformOrigin: "0 0",825 }}826 >827 {/* The camera. Everything under it is laid out once, at scale 1, and828 nothing in the scene animates a size or a position — only this829 transform and one `translateX` per row. Transforms do not reflow;830 an animated `fontSize` re-shapes every glyph in the frame on every831 frame, which is the most expensive thing a browser can be asked to832 do per frame and the reason the same scene can measure correct and833 still look like it is sticking. */}834 <div835 style={{836 position: "absolute",837 inset: 0,838 transform: `translateX(${pan(t) * cameraScale(t)}px) scale(${cameraScale(t)})`,839 transformOrigin: `${ORIGIN.x}px ${ORIGIN.y}px`,840 ...live,841 }}842 >843 {groups}844 <Pill845 accent={accent}846 label={label}847 on={t >= FLIP_AT}848 press={pressScale(t)}849 th={th}850 />851 <Pointer color={th.foreground} rim={th.background} at={point} />852 </div>853 </div>854 </AbsoluteFill>855 );856}857858/* ─────────────────────────────────────────────────────────────────────────859 Pieces — all laid out in reference px, none of them animated860 ───────────────────────────────────────────────────────────────────────── */861862/**863 * One roster card. Takes a `ref` and a `style` on top of its own so Remotion864 * Studio can outline it and nudge it (see `Item`).865 */866const Card = forwardRef<867 HTMLDivElement,868 {869 accent: string;870 edge: string;871 entry: RosterEntry;872 left: number;873 on: boolean;874 th: KuchiTheme;875 top: number;876 style?: CSSProperties;877 }878>(function Card({ accent, edge, entry, left, on, th, top, style }, ref) {879 return (880 <div881 ref={ref}882 style={{883 ...style,884 position: "absolute",885 left,886 top,887 width: CARD.w,888 height: CARD.h,889 borderRadius: CARD.radius,890 background: th.secondary,891 // A hairline and nothing else. A drop shadow under nine light chips on892 // a light page is nine grey smears — and the reference's own card edge893 // is five levels of luma, which is a border, not a shadow.894 boxShadow: `inset 0 0 0 1px ${edge}`,895 overflow: "hidden",896 }}897 >898 <div899 style={{900 position: "absolute",901 left: AVATAR.padX,902 top: (CARD.h - AVATAR.size) / 2,903 width: AVATAR.size,904 height: AVATAR.size,905 borderRadius: "50%",906 background: on ? accent : th.card,907 color: on ? th.primaryForeground : th.foreground,908 display: "flex",909 alignItems: "center",910 justifyContent: "center",911 fontSize: AVATAR.initials,912 fontWeight: 500,913 lineHeight: 1,914 }}915 >916 {initialsOf(entry)}917 </div>918 <div919 style={{920 position: "absolute",921 left: TEXT_X,922 top: NAME.top,923 right: 10,924 fontSize: NAME.size,925 fontWeight: NAME.weight,926 lineHeight: 1,927 color: th.foreground,928 whiteSpace: "nowrap",929 overflow: "hidden",930 textOverflow: "ellipsis",931 }}932 >933 {entry.name}934 </div>935 <div936 style={{937 position: "absolute",938 left: TEXT_X,939 top: ROLE.top,940 right: 10,941 fontSize: ROLE.size,942 fontWeight: ROLE.weight,943 lineHeight: 1,944 color: th.mutedForeground,945 whiteSpace: "nowrap",946 overflow: "hidden",947 textOverflow: "ellipsis",948 }}949 >950 {entry.role}951 </div>952 </div>953 );954});955956function Pill({957 accent,958 label,959 on,960 press,961 th,962}: {963 accent: string;964 label: string;965 on: boolean;966 press: number;967 th: KuchiTheme;968}) {969 const fill = on ? accent : th.foreground;970 return (971 <div972 style={{973 position: "absolute",974 left: ORIGIN.x,975 top: ORIGIN.y,976 // `max-content`, so the pill is its own contents plus the measured977 // padding and a long label can never be cramped inside a guessed width.978 width: "max-content",979 height: PILL.h,980 padding: `0 ${PILL.padX}px`,981 boxSizing: "border-box",982 transform: `translate(-50%, -50%) scale(${press})`,983 borderRadius: PILL.radius,984 background: fill,985 color: on ? th.primaryForeground : th.background,986 display: "flex",987 alignItems: "center",988 justifyContent: "center",989 gap: PILL.iconGap,990 fontSize: PILL.label,991 fontWeight: 500,992 wordSpacing: PILL.wordSpacing,993 lineHeight: 1,994 whiteSpace: "nowrap",995 // A 1px lighter rim along the top, which is what the reference has and996 // what stops a saturated pill reading as a sticker, plus a glow in the997 // pill's *own* colour — so it can never be the grey smear a neutral998 // drop shadow would be on this page.999 boxShadow: [1000 `inset 0 1px 0 ${withAlpha("#ffffff", 0.22)}`,1001 `0 10px 26px -6px ${withAlpha(fill, 0.34)}`,1002 ].join(", "),1003 }}1004 >1005 <span>{label}</span>1006 <svg1007 width={PILL.iconW}1008 height={PILL.iconH}1009 viewBox="0 0 24 20"1010 fill="none"1011 stroke="currentColor"1012 strokeWidth={1.8}1013 strokeLinecap="round"1014 strokeLinejoin="round"1015 aria-hidden1016 >1017 <title>Install</title>1018 <path d="M12 1.5v10.5" />1019 <path d="M7.5 7.5 12 12l4.5-4.5" />1020 <path d="M3.5 14.5v3a1.5 1.5 0 0 0 1.5 1.5h14a1.5 1.5 0 0 0 1.5-1.5v-3" />1021 </svg>1022 </div>1023 );1024}10251026/**1027 * The pointer — lucide's `MousePointer2`, filled, with a rim in the page colour1028 * so it reads over a card, over the pill and over the backdrop alike.1029 *1030 * Positioned by its **tip**, not its centre: the reference's pointer is a plain1031 * disc and the tracked point is that disc's middle, but an arrow's hotspot is1032 * the point it is drawn from. Anchoring the box instead puts the click a third1033 * of the glyph away from where the reference clicked.1034 */1035function Pointer({1036 at,1037 color,1038 rim,1039}: {1040 at: { x: number; y: number };1041 color: string;1042 rim: string;1043}) {1044 return (1045 <svg1046 width={CURSOR.size}1047 height={CURSOR.size}1048 viewBox="0 0 24 24"1049 style={{1050 position: "absolute",1051 left: 0,1052 top: 0,1053 transform: `translate(${ORIGIN.x + at.x - CURSOR.tip.x * (CURSOR.size / 24)}px, ${ORIGIN.y + at.y - CURSOR.tip.y * (CURSOR.size / 24)}px)`,1054 overflow: "visible",1055 }}1056 aria-hidden1057 >1058 <title>Pointer</title>1059 <path1060 d="M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"1061 fill={color}1062 stroke={rim}1063 strokeWidth={1.6}1064 strokeLinejoin="round"1065 />1066 </svg>1067 );1068}10691070/**1071 * The page under it all.1072 *1073 * The reference's backdrop is a mesh: white through the middle of the top edge,1074 * a wash of its brand indigo climbing out of the bottom-right, and a lighter1075 * core right behind the pill. Its *shape* is worth keeping and its paint is1076 * not — so the wash here is the accent, at the alphas measured off the1077 * reference, and it follows a user's theme instead of a stranger's brand.1078 */1079function Backdrop({ accent, th }: { accent: string; th: KuchiTheme }) {1080 return (1081 <AbsoluteFill1082 style={{1083 background: [1084 `radial-gradient(58% 44% at 50% 46%, ${withAlpha(th.card, 0.9)} 0%, ${withAlpha(th.card, 0)} 100%)`,1085 `radial-gradient(78% 62% at 64% 116%, ${withAlpha(accent, 0.42)} 0%, ${withAlpha(accent, 0)} 100%)`,1086 `radial-gradient(52% 46% at -4% -8%, ${withAlpha(accent, 0.16)} 0%, ${withAlpha(accent, 0)} 100%)`,1087 th.background,1088 ].join(", "),1089 }}1090 />1091 );1092}10931094export default RosterGrant;









