{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"portal-intro","type":"registry:component","title":"Portal Intro","description":"Sentence-to-picture intro. The lead words fade up one at a time, the line re-sets with a small rounded picture chip inside it and leans in until the chip takes the frame; a title types itself over the picture, lifts away, and the mark and the name arrive.","dependencies":["remotion"],"docs":"Needs a Remotion project. If a frame renders black, the component is drawing on a transparent layer: put a background behind it, e.g. <AbsoluteFill style={{ background: \"#faf9f6\" }}><Component /></AbsoluteFill>. Pass mode=\"dark\" for dark frames.","registryDependencies":["https://kuchi.kalarislabs.com/r/kuchi-ui.json"],"files":[{"path":"components/kuchi/portal-intro.tsx","type":"registry:component","target":"components/kuchi/portal-intro.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport { useEffect, useMemo, useState } from \"react\";\r\nimport {\r\n  AbsoluteFill,\r\n  continueRender,\r\n  delayRender,\r\n  getRemotionEnvironment,\r\n  Img,\r\n  staticFile,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\nimport {\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\n/**\r\n * A sentence with a picture in it, and the picture opening into the frame.\r\n *\r\n * The lead words fade up one at a time while the line drifts in from the left.\r\n * Then the line re-sets with a small rounded chip in the middle of it and the\r\n * rest of the sentence after, and the whole thing leans in — slowly at first,\r\n * then fast — until the chip takes the frame. The picture lands blurred and a\r\n * little small and settles sharp; a title types itself in over it, lifts away,\r\n * and the mark and the name arrive in its place.\r\n *\r\n * Every number below was measured off a screen recording, frame by frame, and\r\n * the scene is built on that recording's own clock: it was captured at 30fps,\r\n * so frame `n` here is frame `n - 1` of the recording and every table is keyed\r\n * in the recording's frames.\r\n *\r\n * ## Two lines, not one line that grows\r\n *\r\n * The first line is only the lead words, centred with a trailing space. The\r\n * second is lead + chip + trail, centred on its own. The recording cuts between\r\n * them on one frame — nothing slides from one layout to the other — so the\r\n * scene does too.\r\n *\r\n * ## The line scales about a fixed point, not its centre\r\n *\r\n * Both lines scale about (PIVOT_X, PIVOT_Y): the second line's measured centre\r\n * drifts right as it grows, by exactly what a pivot 15px left of it predicts\r\n * (to 0.4px over 24 frames). The pivot's height is the chip's centre line, and\r\n * the baseline stays a fixed 7.5px below it at every scale.\r\n *\r\n * ## The chip holds its own picture\r\n *\r\n * It is not a window onto the backdrop: the chip's picture eases out a touch\r\n * and then dives in 2.4x on its own while the line leans in, and the backdrop\r\n * replaces it on the frame the chip opens. Both default to one image.\r\n */\r\n\r\n/** Variable Geist: the recording's weights (450, 500) are between Google's cuts. */\r\nconst FACE = \"Portal Intro Geist\";\r\nconst FACE_URL =\r\n  \"https://cdn.jsdelivr.net/npm/@fontsource-variable/geist@5.2.8/files/geist-latin-wght-normal.woff2\";\r\nlet faceLoad: Promise<unknown> | null = null;\r\nfunction loadFace(): Promise<unknown> {\r\n  if (faceLoad) return faceLoad;\r\n  if (typeof FontFace === \"undefined\") {\r\n    faceLoad = Promise.resolve();\r\n    return faceLoad;\r\n  }\r\n  const face = new FontFace(FACE, `url(${FACE_URL}) format(\"woff2\")`, {\r\n    weight: \"100 900\",\r\n  });\r\n  document.fonts.add(face);\r\n  // A face that fails to load leaves the fallback stack to paint.\r\n  faceLoad = face.load().catch(() => undefined);\r\n  return faceLoad;\r\n}\r\nconst SANS = `\"${FACE}\", Geist, ui-sans-serif, system-ui, sans-serif`;\r\n\r\n/** Absolute, so a copy of this file in another project still finds it. */\r\nconst DEFAULT_IMAGE =\r\n  \"https://kuchi-media.kalarislabs.com/components/art/art-03.svg\";\r\n\r\n/* ─────────────────────────────────────────────────────────────────────────\r\n   The frame, in the recording's own 714 × 402 pixels\r\n   ───────────────────────────────────────────────────────────────────────── */\r\n\r\nexport const REF_W = 714;\r\nexport const REF_H = 402;\r\n/** Recording frame `r` is composition frame `r + LEAD`. */\r\nexport const LEAD = 1;\r\nexport const DURATION = 108;\r\n\r\n/** The point both lines scale about. */\r\nexport const PIVOT_X = 345.17;\r\nexport const PIVOT_Y = 198.93;\r\n/** Where each line is centred, at scale 1. */\r\nexport const CENTRE_A = 357;\r\nexport const CENTRE_B = 360.27;\r\n/** The baseline at scale 1. */\r\nexport const BASELINE = 206.46;\r\n\r\n/** The line's type: size at scale 1, weight, tracking in em. */\r\nexport const LINE_SIZE = 26.834;\r\nexport const LINE_WEIGHT = 450;\r\nexport const LINE_TRACKING = -0.01;\r\n/** Frames between one lead word and the next. */\r\nexport const STAGGER = 6;\r\n/** The chip's corner, in layout px — it scales with the line. */\r\nexport const CHIP_RADIUS = 4.4;\r\n\r\n/** The recording frames each part of the scene owns. */\r\nexport const FIRST_LINE_TO = 22;\r\nexport const SECOND_LINE_TO = 46;\r\nexport const OPEN_AT = 49;\r\nexport const TITLE_FROM = 48;\r\nexport const TITLE_TO = 70;\r\nexport const MARK_FROM = 71;\r\nexport const BRAND_FROM = 73;\r\nexport const BRAND_STAGGER = 2;\r\n\r\n/** The title's type and where it is centred. */\r\nexport const TITLE_SIZE = 30.29;\r\nexport const TITLE_WEIGHT = 500;\r\nexport const TITLE_TRACKING = -0.02;\r\nexport const TITLE_CENTRE = 357.415;\r\n/** The mark and name: sizes, gap, centre, and the name's drop below the mark's centre. */\r\nexport const MARK_SIZE = 29.22;\r\nexport const BRAND_SIZE = 38.19;\r\nexport const BRAND_WEIGHT = 450;\r\nexport const BRAND_TRACKING = -0.03;\r\nexport const BRAND_GAP = 3.25;\r\nexport const BRAND_CENTRE = 356.86;\r\nexport const BRAND_DROP = 10.74;\r\n/** Where the mark settles once the recording runs out, and how fast. */\r\nexport const MARK_REST = 199;\r\nexport const MARK_SETTLE = 0.88;\r\n\r\n/**\r\n * The backdrop is drawn this much larger than the frame, so that at the 0.62\r\n * scale it opens at there is still picture under every edge of the opening.\r\n */\r\nexport const BLEED = 1.5;\r\n\r\n/* ─────────────────────────────────────────────────────────────────────────\r\n   The measured tables, keyed in recording frames\r\n   ───────────────────────────────────────────────────────────────────────── */\r\n\r\nexport type Table = { from: number; v: readonly number[] };\r\n\r\n/** Linear read of a table, clamped at both ends. */\r\nexport function at(t: Table, x: number): number {\r\n  const n = t.v.length;\r\n  const i = x - t.from;\r\n  if (i <= 0) return t.v[0] ?? 0;\r\n  if (i >= n - 1) return t.v[n - 1] ?? 0;\r\n  const i0 = Math.floor(i);\r\n  const a = t.v[i0] ?? 0;\r\n  const b = t.v[i0 + 1] ?? a;\r\n  return a + (b - a) * (i - i0);\r\n}\r\n\r\n/** The whole line's scale, against the size it is set at. */\r\nexport const SCALE: Table = {\r\n  from: -1,\r\n  v: [\r\n    0.948789, 0.948789, 0.948789, 0.949727, 0.9491, 0.94994, 0.950745, 0.950887,\r\n    0.95062, 0.951965, 0.952448, 0.953167, 0.95334, 0.954234, 0.955356,\r\n    0.956136, 0.957932, 0.959057, 0.961321, 0.963993, 0.96696, 0.970379,\r\n    0.97696, 0.985827, 1.00001, 1.01553, 1.02495, 1.03178, 1.0374, 1.04274,\r\n    1.04826, 1.05222, 1.05734, 1.06323, 1.06908, 1.07466, 1.08109, 1.08821,\r\n    1.09531, 1.10385, 1.1126, 1.12312, 1.13474, 1.14857, 1.16463, 1.18435,\r\n    1.21107, 1.26697,\r\n  ],\r\n};\r\n/** How far the first line still has to travel right, in layout px. */\r\nexport const PAN: Table = {\r\n  from: -1,\r\n  v: [\r\n    -57, -44.2, -34.069, -25.946, -20.352, -15.946, -12.41, -9.611, -7.358,\r\n    -5.421, -3.863, -2.598, -1.655, -0.897, -0.338, 0.013, 0.226, 0.236, 0.249,\r\n    0.225, 0.19, 0.086, 0.055, -0.045,\r\n  ],\r\n};\r\n/** A word's opacity, by frames since it began. */\r\nexport const WORD_OPACITY: Table = {\r\n  from: -1,\r\n  v: [\r\n    0, 0.15, 0.317, 0.457, 0.563, 0.642, 0.706, 0.754, 0.804, 0.812, 0.871,\r\n    0.888, 0.909, 0.933, 0.949, 0.964, 0.981, 0.996, 0.988, 0.993, 0.994, 0.999,\r\n    1, 1,\r\n  ],\r\n};\r\n/** How far below its baseline a word still is, by frames since it began. */\r\nexport const WORD_RISE: Table = {\r\n  from: -1,\r\n  v: [\r\n    4.58, 3.907, 3.314, 2.797, 2.348, 1.962, 1.632, 1.354, 1.12, 0.926, 0.764,\r\n    0.629, 0.516, 0.418, 0.333, 0.261, 0.2, 0.148, 0.104, 0.066, 0.034, 0.005,\r\n    0, 0,\r\n  ],\r\n};\r\n/** The room the line makes for the chip, in layout px. */\r\nexport const SLOT: Table = {\r\n  from: 23,\r\n  v: [\r\n    60.732, 65.134, 67.143, 68.482, 69.546, 70.405, 71.05, 71.649, 72.167,\r\n    72.54, 72.803, 73.062, 73.292, 73.382, 73.481, 73.663, 74.218, 75.148,\r\n    76.582, 78.659, 81.609, 85.948, 92.559, 109.382,\r\n  ],\r\n};\r\n/** The chip's drawn width, in layout px. */\r\nexport const CHIP_W: Table = {\r\n  from: 23,\r\n  v: [\r\n    44.508, 45.945, 46.76, 47.144, 47.798, 47.894, 48.001, 48.454, 48.466,\r\n    48.546, 48.653, 48.693, 48.885, 49.032, 49.904, 51.058, 52.22, 54.09,\r\n    56.437, 59.433, 63.447, 69.108, 77.2, 96.579,\r\n  ],\r\n};\r\n/** The chip's drawn height, in layout px. */\r\nexport const CHIP_H: Table = {\r\n  from: 23,\r\n  v: [\r\n    25.253, 26.036, 26.521, 26.778, 26.907, 27.012, 27.039, 27.174, 27.431,\r\n    27.515, 27.597, 27.85, 28.043, 28.097, 28.312, 28.967, 29.719, 30.467,\r\n    31.741, 33.415, 35.677, 38.81, 43.202, 54.168,\r\n  ],\r\n};\r\n/** Where the chip sits in its slot, off centre, in layout px. */\r\nexport const CHIP_DX: Table = {\r\n  from: 23,\r\n  v: [\r\n    -0.662, -1.12, -1.266, -1.491, -1.497, -1.626, -1.705, -1.681, -1.744,\r\n    -1.766, -1.773, -1.828, -1.882, -1.924, -1.888, -1.869, -1.95, -1.931,\r\n    -2.032, -2.236, -2.339, -2.701, -3.151, -4.166,\r\n  ],\r\n};\r\n/** And off the pivot line, in layout px. */\r\nexport const CHIP_DY: Table = {\r\n  from: 23,\r\n  v: [\r\n    0.241, 0.197, 0.166, 0.154, 0.169, 0.179, 0.195, 0.171, 0.192, 0.177, 0.155,\r\n    0.17, 0.16, 0.091, 0.078, 0.107, 0.088, 0.081, 0.074, 0.113, 0.045, 0.09,\r\n    0.022, 0.055,\r\n  ],\r\n};\r\n/** The picture inside the chip, as a zoom over `cover`. */\r\nexport const CHIP_ZOOM: Table = {\r\n  from: 23,\r\n  v: [\r\n    1.3053, 1.2221, 1.1553, 1.1025, 1.062, 1.0324, 1.0126, 1.002, 1, 1.0065,\r\n    1.0215, 1.045, 1.0777, 1.12, 1.1728, 1.2372, 1.3146, 1.4068, 1.5158, 1.6442,\r\n    1.7952, 1.9726, 2.1809, 2.4258,\r\n  ],\r\n};\r\n/** The backdrop's scale once the chip has opened. */\r\nexport const BG_SCALE: Table = {\r\n  from: 47,\r\n  v: [\r\n    0.6285, 0.7741, 0.8335, 0.8644, 0.8844, 0.9068, 0.9271, 0.9434, 0.9558,\r\n    0.9633, 0.9687, 0.9745, 0.9804, 0.9861, 0.993, 0.9972, 1.0004, 1.0028,\r\n    1.0046, 1.0061, 1.0076, 1.0073, 1.0072, 1.0069, 1.0065, 1.0053, 1.0045,\r\n    1.0037, 1.0023, 1.0019, 1.0018, 1.0016, 1.0011, 1.001, 1.0009, 1.0006,\r\n    1.0004, 1.0001, 1, 1,\r\n  ],\r\n};\r\n/** Its drift right, in reference px. */\r\nexport const BG_X: Table = {\r\n  from: 47,\r\n  v: [\r\n    18, 13.45, 9.15, 7.91, 6.79, 4.8494, 3.6476, 3.2565, 1.8995, 1.3861, 0.971,\r\n    1.751, 1.4813, 1.494, 0.9013, 0.7599, 0.5335, 0.4651, 0.3116, 0.215, 0.12,\r\n    0.129, 0.134, 0.143, 0.143, 0.095, 0.092, 0.061, 0.03, 0.028, 0.033, 0.03,\r\n    0.039, 0.038, 0.032, 0.024, 0.008, -0.001, -0.002, -0,\r\n  ],\r\n};\r\n/** Its drift down, in reference px. */\r\nexport const BG_Y: Table = {\r\n  from: 47,\r\n  v: [\r\n    -0.68, -0.7, -0.14, 0.34, 0.36, 0.4344, 0.4116, 0.3287, 0.1941, -0.0261,\r\n    0.0106, -0.1763, -0.3804, -0.3697, -0.3417, -0.3645, -0.2931, -0.2826,\r\n    -0.2109, -0.209, -0.211, -0.19, -0.181, -0.158, -0.115, -0.055, -0.031,\r\n    0.01, 0.054, 0.071, 0.065, 0.069, 0.052, 0.044, 0.036, 0.024, 0.025, 0.015,\r\n    0.005, -0,\r\n  ],\r\n};\r\n/** Its blur, in the backdrop's own px. */\r\nexport const BG_BLUR: Table = {\r\n  from: 47,\r\n  v: [\r\n    14.91, 15.45, 14.33, 10.26, 6.93, 11.7455, 9.8469, 7.6187, 4.426, 3.187,\r\n    1.9011, 1.3233, 0.6, 0.3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r\n    0, 0, 0, 0, 0, 0, 0, 0, 0,\r\n  ],\r\n};\r\n/** The title's baseline. */\r\nexport const TITLE_Y: Table = {\r\n  from: 48,\r\n  v: [\r\n    212.158, 212.105, 212.085, 212.085, 212.085, 212.085, 212.085, 212.085,\r\n    212.085, 212.085, 212.043, 211.919, 211.741, 211.499, 211.188, 210.801,\r\n    210.33, 209.769, 209.094, 208.213, 207.02, 205.165, 201.343,\r\n  ],\r\n};\r\n/** How far below the title's baseline a letter still is, by frames since it began. */\r\nexport const LETTER_RISE: Table = {\r\n  from: 0,\r\n  v: [\r\n    2.104, 1.661, 1.283, 0.964, 0.7, 0.486, 0.317, 0.187, 0.091, 0.026, 0, 0, 0,\r\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r\n  ],\r\n};\r\n/** A letter's opacity, by frames since it began. */\r\nexport const LETTER_OPACITY: Table = {\r\n  from: 0,\r\n  v: [\r\n    0.372, 0.53, 0.64, 0.722, 0.791, 0.851, 0.892, 0.927, 0.953, 0.97, 0.981,\r\n    0.988, 0.995, 0.998, 0.998, 0.995, 0.997, 1, 1, 1, 1, 0.999, 0.995,\r\n  ],\r\n};\r\n/** The mark's centre line. */\r\nexport const MARK_Y: Table = {\r\n  from: 71,\r\n  v: [\r\n    204.337, 203.041, 202.271, 201.782, 201.431, 201.121, 200.837, 200.584,\r\n    200.368, 200.191, 200.046, 199.925, 199.819, 199.717, 199.612, 199.494,\r\n  ],\r\n};\r\n/** The mark's opacity. */\r\nexport const MARK_OPACITY: Table = {\r\n  from: 71,\r\n  v: [\r\n    0.642, 0.845, 0.916, 0.949, 0.975, 0.987, 0.998, 0.998, 0.997, 0.997, 1, 1,\r\n    1, 0.999, 1, 1,\r\n  ],\r\n};\r\n/** How far below its baseline a brand letter still is, by frames since it landed. */\r\nexport const BRAND_RISE: Table = {\r\n  from: 0,\r\n  v: [\r\n    3.059, 2.205, 1.602, 1.188, 0.904, 0.693, 0.528, 0.388, 0.255, 0.13, 0.02,\r\n    0, 0, 0,\r\n  ],\r\n};\r\n/** The two frames the chip spends opening: left, top, right, bottom, radius. */\r\nexport const OPENING: Record<\r\n  number,\r\n  readonly [number, number, number, number, number]\r\n> = {\r\n  47: [108.9, 50.8, 637.35, 347.11, 13.1],\r\n  48: [38.69, 14.06, 698.6, 383.87, 15.9],\r\n};\r\n\r\n/* ─────────────────────────────────────────────────────────────────────────\r\n   Measuring type\r\n   ───────────────────────────────────────────────────────────────────────── */\r\n\r\ntype Metrics = {\r\n  /** Advance of each prefix of the string, so `pre[i]` is where letter i starts. */\r\n  pre: number[];\r\n  /** Ascent and descent, as fractions of the size. */\r\n  asc: number;\r\n  desc: number;\r\n};\r\n\r\nconst FALLBACK = { asc: 0.9, desc: 0.22, char: 0.52 };\r\n\r\n/** Prefix advances with the tracking applied, at `size` px. */\r\nexport function measure(\r\n  text: string,\r\n  size: number,\r\n  weight: number,\r\n  tracking: number,\r\n  face: string,\r\n): Metrics {\r\n  const ctx =\r\n    typeof document === \"undefined\"\r\n      ? null\r\n      : document.createElement(\"canvas\").getContext(\"2d\");\r\n  if (!ctx) {\r\n    return {\r\n      pre: [...Array(text.length + 1).keys()].map(\r\n        (i) => i * size * (FALLBACK.char + tracking),\r\n      ),\r\n      asc: FALLBACK.asc,\r\n      desc: FALLBACK.desc,\r\n    };\r\n  }\r\n  ctx.font = `${weight} ${size}px ${face}`;\r\n  ctx.letterSpacing = `${tracking * size}px`;\r\n  const pre = [...Array(text.length + 1).keys()].map(\r\n    (i) => ctx.measureText(text.slice(0, i)).width,\r\n  );\r\n  const m = ctx.measureText(\"Hg\");\r\n  return {\r\n    pre,\r\n    asc: m.fontBoundingBoxAscent / size,\r\n    desc: m.fontBoundingBoxDescent / size,\r\n  };\r\n}\r\n\r\n/** Rewrite root-relative assets through staticFile everywhere but the Player. */\r\nfunction resolveSrc(src: string): string {\r\n  const isLocal = src.startsWith(\"/\") && !src.startsWith(\"//\");\r\n  if (!isLocal || getRemotionEnvironment().isPlayer) return src;\r\n  const base = staticFile(\"_\").slice(0, -2);\r\n  if (base && src.startsWith(`${base}/`)) return src;\r\n  try {\r\n    return staticFile(src.replace(/^\\/+/, \"\"));\r\n  } catch {\r\n    return src;\r\n  }\r\n}\r\n\r\n/* ─────────────────────────────────────────────────────────────────────────\r\n   The scene\r\n   ───────────────────────────────────────────────────────────────────────── */\r\n\r\nexport interface PortalIntroProps {\r\n  /** The words before the chip. They arrive one at a time. */\r\n  lead?: string;\r\n  /** The words after it, which arrive with the chip. */\r\n  trail?: string;\r\n  /** The picture the chip opens into. */\r\n  image?: string;\r\n  /** The chip's own picture, if it should differ from the backdrop. */\r\n  chipImage?: string;\r\n  /** The title typed over the picture. */\r\n  title?: string;\r\n  /** The name beside the mark. */\r\n  brand?: string;\r\n  /** The mark, drawn in `currentColor` in a MARK_SIZE box. Defaults to kuchi's. */\r\n  logo?: React.ReactNode;\r\n  /** Or the mark as an image URL, when it cannot be passed as an element. */\r\n  logoSrc?: string;\r\n  /** The ink of the title, the mark and the name over the picture. */\r\n  overlay?: string;\r\n  fontFamily?: string;\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n  speed?: number;\r\n  className?: string;\r\n}\r\n\r\nexport function PortalIntro({\r\n  lead = \"your launch video\",\r\n  trail = \"in code\",\r\n  image = DEFAULT_IMAGE,\r\n  chipImage,\r\n  title = \"Introducing\",\r\n  brand = \"kuchi\",\r\n  logo,\r\n  logoSrc,\r\n  overlay = \"#ffffff\",\r\n  fontFamily,\r\n  theme,\r\n  mode = \"light\",\r\n  speed = 1,\r\n  className,\r\n}: PortalIntroProps) {\r\n  const frame = useCurrentFrame() * speed;\r\n  const { width, height } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face = resolveFont(fontFamily) ?? SANS;\r\n  const r = frame - LEAD;\r\n\r\n  const [handle] = useState(() => delayRender(\"portal-intro: font\"));\r\n  const [ready, setReady] = useState(false);\r\n  useEffect(() => {\r\n    loadFace()\r\n      .then(() => document.fonts.ready)\r\n      .finally(() => {\r\n        setReady(true);\r\n        continueRender(handle);\r\n      });\r\n  }, [handle]);\r\n\r\n  const leadWords = useMemo(() => lead.split(/\\s+/).filter(Boolean), [lead]);\r\n  const trailWords = useMemo(() => trail.split(/\\s+/).filter(Boolean), [trail]);\r\n\r\n  const type = useMemo(() => {\r\n    void ready;\r\n    const line = (words: string[]) => {\r\n      const text = words.join(\" \");\r\n      const m = measure(\r\n        `${text} `,\r\n        LINE_SIZE,\r\n        LINE_WEIGHT,\r\n        LINE_TRACKING,\r\n        face,\r\n      );\r\n      // Where each word starts: the prefix up to it, spaces included.\r\n      const starts: number[] = [];\r\n      let i = 0;\r\n      for (const w of words) {\r\n        starts.push(m.pre[i] ?? 0);\r\n        i += w.length + 1;\r\n      }\r\n      return {\r\n        starts,\r\n        width: m.pre[text.length] ?? 0,\r\n        withSpace: m.pre[text.length + 1] ?? 0,\r\n        asc: m.asc,\r\n        desc: m.desc,\r\n      };\r\n    };\r\n    return {\r\n      lead: line(leadWords),\r\n      trail: line(trailWords),\r\n      title: measure(title, TITLE_SIZE, TITLE_WEIGHT, TITLE_TRACKING, face),\r\n      brand: measure(brand, BRAND_SIZE, BRAND_WEIGHT, BRAND_TRACKING, face),\r\n    };\r\n  }, [ready, leadWords, trailWords, title, brand, face]);\r\n\r\n  // `cover`, so a 16:9 composition crops the frame rather than letterboxing it.\r\n  const k = Math.max(width / REF_W, height / REF_H);\r\n  const ink = t.foreground;\r\n  // The stage is one scaled layer, and Chrome snaps glyph baselines inside it —\r\n  // so the grid the type steps on is the stage's own pixel, not the device's.\r\n  const grid = [1, 0] as const;\r\n  const backdrop = resolveSrc(image);\r\n  const chipSrc = resolveSrc(chipImage ?? image);\r\n\r\n  const s = at(SCALE, Math.min(r, SECOND_LINE_TO));\r\n  const toX = (x: number) => PIVOT_X + s * (x - PIVOT_X);\r\n  const toY = (y: number) => PIVOT_Y + s * (y - PIVOT_Y);\r\n\r\n  const nodes: React.ReactNode[] = [];\r\n\r\n  if (r < FIRST_LINE_TO + 0.5) {\r\n    // The lead words alone, centred with their trailing space, drifting in.\r\n    const l = type.lead;\r\n    const x0 = CENTRE_A - l.withSpace / 2 + at(PAN, r);\r\n    leadWords.forEach((w, i) => {\r\n      const kk = r - STAGGER * i;\r\n      if (kk < WORD_OPACITY.from) return;\r\n      nodes.push(\r\n        <Glyphs\r\n          // biome-ignore lint/suspicious/noArrayIndexKey: a word's place in the line is its identity\r\n          key={`a${i}`}\r\n          text={w}\r\n          x={toX(x0 + (l.starts[i] ?? 0))}\r\n          baseline={toY(BASELINE + at(WORD_RISE, kk))}\r\n          size={LINE_SIZE}\r\n          scale={s}\r\n          weight={LINE_WEIGHT}\r\n          tracking={LINE_TRACKING}\r\n          asc={l.asc}\r\n          desc={l.desc}\r\n          color={ink}\r\n          opacity={at(WORD_OPACITY, kk)}\r\n        />,\r\n      );\r\n    });\r\n  }\r\n\r\n  // Where the chip is drawn, in reference px, while it sits in the line.\r\n  let chip: { l: number; t: number; w: number; h: number; r: number } | null =\r\n    null;\r\n  if (r >= FIRST_LINE_TO + 0.5 && r < SECOND_LINE_TO + 0.5) {\r\n    const l = type.lead;\r\n    const tr = type.trail;\r\n    const slot = at(SLOT, r);\r\n    const total = l.withSpace + slot + tr.width;\r\n    const x0 = CENTRE_B - total / 2;\r\n    const slotAt = x0 + l.withSpace;\r\n    const trailAt = slotAt + slot;\r\n    leadWords.forEach((w, i) => {\r\n      nodes.push(\r\n        <Glyphs\r\n          // biome-ignore lint/suspicious/noArrayIndexKey: a word's place in the line is its identity\r\n          key={`b${i}`}\r\n          text={w}\r\n          x={toX(x0 + (l.starts[i] ?? 0))}\r\n          baseline={toY(BASELINE)}\r\n          size={LINE_SIZE}\r\n          scale={s}\r\n          weight={LINE_WEIGHT}\r\n          tracking={LINE_TRACKING}\r\n          asc={l.asc}\r\n          desc={l.desc}\r\n          color={ink}\r\n        />,\r\n      );\r\n    });\r\n    trailWords.forEach((w, i) => {\r\n      nodes.push(\r\n        <Glyphs\r\n          // biome-ignore lint/suspicious/noArrayIndexKey: a word's place in the line is its identity\r\n          key={`c${i}`}\r\n          text={w}\r\n          x={toX(trailAt + (tr.starts[i] ?? 0))}\r\n          baseline={toY(BASELINE)}\r\n          size={LINE_SIZE}\r\n          scale={s}\r\n          weight={LINE_WEIGHT}\r\n          tracking={LINE_TRACKING}\r\n          asc={tr.asc}\r\n          desc={tr.desc}\r\n          color={ink}\r\n        />,\r\n      );\r\n    });\r\n    const cw = at(CHIP_W, r) * s;\r\n    const ch = at(CHIP_H, r) * s;\r\n    const cx = toX(slotAt + slot / 2 + at(CHIP_DX, r));\r\n    const cy = toY(PIVOT_Y + at(CHIP_DY, r));\r\n    chip = { l: cx - cw / 2, t: cy - ch / 2, w: cw, h: ch, r: CHIP_RADIUS * s };\r\n  }\r\n\r\n  // The opening: the two measured frames, then the whole frame.\r\n  let opening: {\r\n    l: number;\r\n    t: number;\r\n    w: number;\r\n    h: number;\r\n    r: number;\r\n  } | null = null;\r\n  if (r >= SECOND_LINE_TO + 0.5) {\r\n    const o = OPENING[Math.round(r)];\r\n    opening =\r\n      o && r < OPEN_AT - 0.5\r\n        ? { l: o[0], t: o[1], w: o[2] - o[0], h: o[3] - o[1], r: o[4] }\r\n        : { l: 0, t: 0, w: REF_W, h: REF_H, r: 0 };\r\n  }\r\n\r\n  const bgScale = at(BG_SCALE, r);\r\n  const bgBlur = at(BG_BLUR, r);\r\n\r\n  return (\r\n    <AbsoluteFill\r\n      className={className}\r\n      style={{ background: t.background, overflow: \"hidden\" }}\r\n    >\r\n      <AbsoluteFill\r\n        style={{\r\n          width: REF_W,\r\n          height: REF_H,\r\n          left: (width - REF_W * k) / 2,\r\n          top: (height - REF_H * k) / 2,\r\n          transform: `scale(${k})`,\r\n          transformOrigin: \"top left\",\r\n          background: t.background,\r\n          overflow: \"hidden\",\r\n          fontFamily: face,\r\n          textRendering: \"geometricPrecision\",\r\n        }}\r\n      >\r\n        {chip ? (\r\n          <div\r\n            style={{\r\n              position: \"absolute\",\r\n              left: chip.l,\r\n              top: chip.t,\r\n              width: chip.w,\r\n              height: chip.h,\r\n              borderRadius: chip.r,\r\n              overflow: \"hidden\",\r\n            }}\r\n          >\r\n            <Img\r\n              src={chipSrc}\r\n              style={{\r\n                width: \"100%\",\r\n                height: \"100%\",\r\n                objectFit: \"cover\",\r\n                transform: `scale(${at(CHIP_ZOOM, r)})`,\r\n              }}\r\n            />\r\n          </div>\r\n        ) : null}\r\n        {opening ? (\r\n          <div\r\n            style={{\r\n              position: \"absolute\",\r\n              left: opening.l,\r\n              top: opening.t,\r\n              width: opening.w,\r\n              height: opening.h,\r\n              borderRadius: opening.r,\r\n              overflow: \"hidden\",\r\n            }}\r\n          >\r\n            <div\r\n              style={{\r\n                position: \"absolute\",\r\n                left: -opening.l - (REF_W * (BLEED - 1)) / 2,\r\n                top: -opening.t - (REF_H * (BLEED - 1)) / 2,\r\n                width: REF_W * BLEED,\r\n                height: REF_H * BLEED,\r\n                transform: `translate(${at(BG_X, r)}px, ${at(BG_Y, r)}px) scale(${bgScale})`,\r\n                filter: bgBlur > 0.05 ? `blur(${bgBlur}px)` : undefined,\r\n              }}\r\n            >\r\n              <Img\r\n                src={backdrop}\r\n                style={{ width: \"100%\", height: \"100%\", objectFit: \"cover\" }}\r\n              />\r\n            </div>\r\n          </div>\r\n        ) : null}\r\n        {nodes}\r\n        {r >= TITLE_FROM && r < TITLE_TO + 0.5 ? (\r\n          <Title\r\n            text={title}\r\n            m={type.title}\r\n            r={r}\r\n            color={overlay}\r\n            grid={grid}\r\n          />\r\n        ) : null}\r\n        {r >= MARK_FROM ? (\r\n          <Brand\r\n            grid={grid}\r\n            text={brand}\r\n            m={type.brand}\r\n            r={r}\r\n            logo={\r\n              logo ??\r\n              (logoSrc ? (\r\n                <Img\r\n                  src={resolveSrc(logoSrc)}\r\n                  style={{\r\n                    width: \"100%\",\r\n                    height: \"100%\",\r\n                    objectFit: \"contain\",\r\n                  }}\r\n                />\r\n              ) : (\r\n                <KUCHIMark />\r\n              ))\r\n            }\r\n            color={overlay}\r\n          />\r\n        ) : null}\r\n      </AbsoluteFill>\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n\r\n/* ─────────────────────────────────────────────────────────────────────────\r\n   Pieces\r\n   ───────────────────────────────────────────────────────────────────────── */\r\n\r\n/** One run of text, its origin on (x, baseline), scaled about that point. */\r\nfunction Glyphs({\r\n  text,\r\n  x,\r\n  baseline,\r\n  size,\r\n  scale = 1,\r\n  weight,\r\n  tracking,\r\n  asc,\r\n  desc,\r\n  color,\r\n  opacity = 1,\r\n  grid,\r\n}: {\r\n  text: string;\r\n  x: number;\r\n  baseline: number;\r\n  size: number;\r\n  scale?: number;\r\n  weight: number;\r\n  tracking: number;\r\n  asc: number;\r\n  desc: number;\r\n  color: string;\r\n  opacity?: number;\r\n  /**\r\n   * The pixel grid baselines snap to, as `[px per reference px, offset]`.\r\n   * Given, the run is drawn as two copies a grid pixel apart and blended —\r\n   * Chrome snaps a text baseline to a whole pixel, so a letter easing\r\n   * up by fractions of one would otherwise climb in visible one-pixel steps,\r\n   * each letter on its own frame: a tremble, not a rise.\r\n   */\r\n  grid?: readonly [number, number];\r\n}) {\r\n  // At `lineHeight: 1` the line box splits the leftover leading evenly, so the\r\n  // baseline sits this far below the box's top.\r\n  const rise = size * (asc + (1 - asc - desc) / 2);\r\n  if (opacity <= 0) return null;\r\n  if (grid && scale === 1) {\r\n    const [k, off] = grid;\r\n    const yd = off + (baseline - rise) * k;\r\n    const lo = Math.floor(yd);\r\n    const f = yd - lo;\r\n    const copy = (top: number, o: number) => (\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: x,\r\n          top: (top - off) / k,\r\n          width: \"max-content\",\r\n          fontSize: size,\r\n          lineHeight: 1,\r\n          fontWeight: weight,\r\n          letterSpacing: `${tracking}em`,\r\n          whiteSpace: \"pre\",\r\n          color,\r\n          opacity: o,\r\n          mixBlendMode: \"plus-lighter\",\r\n        }}\r\n      >\r\n        {text}\r\n      </div>\r\n    );\r\n    return (\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          inset: 0,\r\n          isolation: \"isolate\",\r\n          opacity,\r\n        }}\r\n      >\r\n        {copy(lo, 1 - f)}\r\n        {f > 0.001 ? copy(lo + 1, f) : null}\r\n      </div>\r\n    );\r\n  }\r\n  return (\r\n    <div\r\n      style={{\r\n        position: \"absolute\",\r\n        left: x,\r\n        top: baseline - rise,\r\n        width: \"max-content\",\r\n        transform: scale === 1 ? undefined : `scale(${scale})`,\r\n        transformOrigin: `0 ${rise}px`,\r\n        fontSize: size,\r\n        lineHeight: 1,\r\n        fontWeight: weight,\r\n        letterSpacing: `${tracking}em`,\r\n        whiteSpace: \"pre\",\r\n        color,\r\n        opacity,\r\n      }}\r\n    >\r\n      {text}\r\n    </div>\r\n  );\r\n}\r\n\r\n/** The title: one letter a frame, each fading up and settling as the word lifts. */\r\nfunction Title({\r\n  grid,\r\n  text,\r\n  m,\r\n  r,\r\n  color,\r\n}: {\r\n  grid: readonly [number, number];\r\n  text: string;\r\n  m: Metrics;\r\n  r: number;\r\n  color: string;\r\n}) {\r\n  const x0 = TITLE_CENTRE - (m.pre[text.length] ?? 0) / 2;\r\n  const base = at(TITLE_Y, r);\r\n  return (\r\n    <>\r\n      {[...text].map((c, i) => {\r\n        const kk = r - TITLE_FROM - i;\r\n        if (kk < 0 || c === \" \") return null;\r\n        return (\r\n          <Glyphs\r\n            // biome-ignore lint/suspicious/noArrayIndexKey: a letter's place is its identity\r\n            key={i}\r\n            text={c}\r\n            x={x0 + (m.pre[i] ?? 0)}\r\n            baseline={base + at(LETTER_RISE, kk)}\r\n            size={TITLE_SIZE}\r\n            weight={TITLE_WEIGHT}\r\n            tracking={TITLE_TRACKING}\r\n            asc={m.asc}\r\n            desc={m.desc}\r\n            color={color}\r\n            opacity={at(LETTER_OPACITY, kk)}\r\n            grid={grid}\r\n          />\r\n        );\r\n      })}\r\n    </>\r\n  );\r\n}\r\n\r\n/** The mark fades up rising; the name lands a letter every other frame beside it. */\r\nfunction Brand({\r\n  grid,\r\n  text,\r\n  m,\r\n  r,\r\n  logo,\r\n  color,\r\n}: {\r\n  grid: readonly [number, number];\r\n  text: string;\r\n  m: Metrics;\r\n  r: number;\r\n  logo: React.ReactNode;\r\n  color: string;\r\n}) {\r\n  const last = MARK_Y.from + MARK_Y.v.length - 1;\r\n  const y =\r\n    r <= last\r\n      ? at(MARK_Y, r)\r\n      : MARK_REST + (at(MARK_Y, last) - MARK_REST) * MARK_SETTLE ** (r - last);\r\n  const adv = m.pre[text.length] ?? 0;\r\n  const left = BRAND_CENTRE - (MARK_SIZE + BRAND_GAP + adv) / 2;\r\n  const textAt = left + MARK_SIZE + BRAND_GAP;\r\n  return (\r\n    <>\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left,\r\n          top: 0,\r\n          // A transform, not `top`: Chrome rounds a box's top edge to the device\r\n          // pixel, which would step the mark up a whole pixel at a time.\r\n          transform: `translateY(${y - MARK_SIZE / 2}px)`,\r\n          width: MARK_SIZE,\r\n          height: MARK_SIZE,\r\n          color,\r\n          opacity: at(MARK_OPACITY, r),\r\n          display: \"flex\",\r\n          alignItems: \"center\",\r\n          justifyContent: \"center\",\r\n        }}\r\n      >\r\n        {logo}\r\n      </div>\r\n      {[...text].map((c, i) => {\r\n        const kk = r - BRAND_FROM - BRAND_STAGGER * i;\r\n        if (kk < 0 || c === \" \") return null;\r\n        return (\r\n          <Glyphs\r\n            // biome-ignore lint/suspicious/noArrayIndexKey: a letter's place is its identity\r\n            key={i}\r\n            text={c}\r\n            x={textAt + (m.pre[i] ?? 0)}\r\n            baseline={y + BRAND_DROP + at(BRAND_RISE, kk)}\r\n            size={BRAND_SIZE}\r\n            weight={BRAND_WEIGHT}\r\n            tracking={BRAND_TRACKING}\r\n            asc={m.asc}\r\n            desc={m.desc}\r\n            color={color}\r\n            grid={grid}\r\n          />\r\n        );\r\n      })}\r\n    </>\r\n  );\r\n}\r\n\r\n/** kuchi's mark, on `currentColor`. */\r\nfunction KUCHIMark() {\r\n  return (\r\n    <svg\r\n      viewBox=\"0 0 464 409\"\r\n      width=\"100%\"\r\n      height=\"100%\"\r\n      fill=\"currentColor\"\r\n      aria-hidden\r\n    >\r\n      <g transform=\"translate(0,409) scale(0.1,-0.1)\">\r\n        <path d=\"M899.8 0H3740.2Q4640 0 4640 899.8V3190.2Q4640 4090 3740.2 4090H899.8Q0 4090 0 3190.2V899.8Q0 0 899.8 0Z\" />\r\n      </g>\r\n    </svg>\r\n  );\r\n}\r\n"}]}