{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"block-wordmark","type":"registry:component","title":"Block Wordmark","description":"Logo sting and wordmark animation: blocks build into your brand name. A wordmark builds out of solid blocks — a square scales in, a coloured deck fans out around it and winds back, the stack collapses and stretches into one block per letter, then each block flashes a colour and swaps for its real letterform.","dependencies":["remotion","@remotion/google-fonts"],"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/block-wordmark.tsx","type":"registry:component","target":"components/kuchi/block-wordmark.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport { loadFont as loadUltra } from \"@remotion/google-fonts/Ultra\";\r\nimport { useEffect, useRef, useState } from \"react\";\r\nimport {\r\n  AbsoluteFill,\r\n  continueRender,\r\n  delayRender,\r\n  Easing,\r\n  getRemotionEnvironment,\r\n  interpolate,\r\n  spring,\r\n  useCurrentFrame,\r\n  useCurrentScale,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\nimport {\r\n  mixOklch,\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\n// Loaded through @remotion/google-fonts, never a CSS variable — a Remotion\r\n// bundle has none of the app's CSS, so `var(--font-…)` gets you the right face\r\n// in the Player and a fallback in the mp4 (design-system rule 4). It also has to\r\n// be resident *before* the measurement below, or every block is sized off a\r\n// fallback metric.\r\n//\r\n// Ultra ships a **single** weight (400). That is not a detail to work around: ask\r\n// for a weight Google does not serve and the browser synthesises it, which on a\r\n// slab this heavy smears the serifs and thickens the stems unevenly — and the\r\n// canvas measurement below would then be taken off that fake face and size every\r\n// block wrong. So the weight prop, its customizer control and this call all say\r\n// 400, and none of them offer anything else.\r\nconst { fontFamily: ULTRA, waitUntilDone: ultraReady } = loadUltra(\"normal\", {\r\n  weights: [\"400\"],\r\n  subsets: [\"latin\"],\r\n});\r\n\r\nconst CLAMP = { extrapolateLeft: \"clamp\", extrapolateRight: \"clamp\" } as const;\r\n\r\n// ─── Motion ────────────────────────────────────────────────────────────────────\r\n\r\n/**\r\n * The deck's full turn. This is an aggressive S-curve — it whips through the\r\n * middle third and creeps at both ends — and the repo's motion-quality rule says\r\n * *moderate decelerates only*. That rule is about **type**: an aggressive ease on\r\n * a glyph spends frames moving under half a pixel, the rasteriser rounds them to\r\n * nothing, and the word visibly freezes. Nothing here is a glyph. These are\r\n * solid-colour rounded rectangles with no hinting and no baseline to snap, and\r\n * the whip is the entire read of the beat — the deck has to look *shuffled*, not\r\n * eased. Softening this to `bezier(0.2, 0.6, 0.35, 1)` was measured against the\r\n * reference and destroys it: the fan opens lazily and never snaps shut.\r\n *\r\n * Fitted frame by frame against the reference, this curve lands within 2° of the\r\n * measured angle over the whole 360°.\r\n */\r\nconst SPIN_EASE = Easing.bezier(0.76, 0, 0.24, 1);\r\n\r\n/** The scale-in, and every settle that follows it: `1 - (1 - x)³`. */\r\nconst OUT_EASE = Easing.out(Easing.cubic);\r\n\r\n/** The deck dropping back onto the baseline — accelerating, a fall not a drift. */\r\nconst IN_EASE = Easing.in(Easing.cubic);\r\n\r\n// ─── Measurement ───────────────────────────────────────────────────────────────\r\n\r\n/** An ascender's tab, measured off the glyph. All values in probe px. */\r\ninterface Tab {\r\n  /** How far the glyph's ink rises above the x-height. */\r\n  height: number;\r\n  /** Left edge of that ink, as a fraction of the glyph's ink width. */\r\n  x: number;\r\n  /** Width of that ink, as a fraction of the glyph's ink width. */\r\n  width: number;\r\n}\r\n\r\ninterface Glyph {\r\n  ch: string;\r\n  /** True when the glyph paints no ink (a space) — it gets no block. */\r\n  blank: boolean;\r\n  /** Advance width in layout px at the probe's `fontSize`. */\r\n  advance: number;\r\n  /** `null` when the glyph does not rise above the x-height. */\r\n  tab: Tab | null;\r\n}\r\n\r\ninterface Metrics {\r\n  glyphs: Glyph[];\r\n  /**\r\n   * The x-height, which is the block's side.\r\n   *\r\n   * Not the cap height, which is what the reference *looks* like it uses. Its\r\n   * word is lowercase and its blocks are 69–70px against letters that stand 71–73\r\n   * tall — those letters are \"a\", \"s\" and \"e\", so 72 is that face's **x-height**,\r\n   * and the 27.6px tab on the first block is exactly its ascender minus its\r\n   * x-height. Reading it as cap height happens to work for a face whose caps and\r\n   * ascenders coincide, and then quietly produces no tab at all in Inter, whose\r\n   * ascenders are the same height as its caps. x-height is the reading that\r\n   * survives a change of font.\r\n   */\r\n  xHeight: number;\r\n  /** Distance from a letter box's top edge down to its text baseline. */\r\n  baselineOffset: number;\r\n}\r\n\r\n/**\r\n * Ink metrics come off a canvas, not off the DOM, because the DOM does not\r\n * expose them: `getBoundingClientRect()` measures a span's *layout* box, which\r\n * is the same height for \"b\" and for \"a\". `TextMetrics.actualBoundingBoxAscent`\r\n * is the real ink top, which is the only thing that can tell an ascender from an\r\n * x-height glyph without a hardcoded `bdfhklt` list — and a hardcoded list is\r\n * wrong the moment the text is Greek, Cyrillic, a capital, or an emoji.\r\n */\r\nfunction measureInk(\r\n  glyphs: string[],\r\n  fontFamily: string,\r\n  fontWeight: number | string,\r\n  fontSize: number,\r\n): { xHeight: number; tabs: Map<string, Tab> } | null {\r\n  const canvas = document.createElement(\"canvas\");\r\n  canvas.width = Math.ceil(fontSize * 3);\r\n  canvas.height = Math.ceil(fontSize * 3);\r\n  const ctx = canvas.getContext(\"2d\", { willReadFrequently: true });\r\n  if (!ctx) return null;\r\n  ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;\r\n  ctx.textBaseline = \"alphabetic\";\r\n\r\n  const xHeight = ctx.measureText(\"x\").actualBoundingBoxAscent;\r\n  const capHeight = ctx.measureText(\"H\").actualBoundingBoxAscent;\r\n  if (!(xHeight > 0) || !(capHeight > xHeight)) return null;\r\n\r\n  // Round letters overshoot the x-height by a pixel or so at every size — \"o\"\r\n  // and \"e\" are drawn slightly taller than \"x\" so they don't *look* shorter. A\r\n  // fraction of the x-height-to-cap gap is the right scale for \"meaningfully\r\n  // above\", because that gap is the size of the feature we are looking for.\r\n  const cut = (capHeight - xHeight) * 0.15;\r\n\r\n  const origin = fontSize * 0.5;\r\n  const baseline = Math.round(fontSize * 2);\r\n  const tabs = new Map<string, Tab>();\r\n\r\n  for (const ch of glyphs) {\r\n    const m = ctx.measureText(ch);\r\n    const height = m.actualBoundingBoxAscent - xHeight;\r\n    if (!(height > cut)) continue;\r\n\r\n    // How wide the tab is, and which side it sits on, cannot be read off any\r\n    // metric — \"b\" and \"d\" have identical bounding boxes, and \"B\" has the same\r\n    // box as \"b\" while being solid across its whole width. So rasterise the\r\n    // glyph once and look at where the ink actually is above the x-height.\r\n    ctx.clearRect(0, 0, canvas.width, canvas.height);\r\n    ctx.fillStyle = \"#000\";\r\n    ctx.fillText(ch, origin, baseline);\r\n    // Read the top 60% of the tab, not all the way down to the x-height line.\r\n    // The last rows before that line are where a \"b\"'s bowl and an \"f\"'s crossbar\r\n    // start, and sampling them reports the whole letter as the stem — measured,\r\n    // that inflated Inter's \"b\" tab from 28% of the block to 67%.\r\n    const top = Math.max(0, Math.floor(baseline - m.actualBoundingBoxAscent));\r\n    const bottom = Math.min(canvas.height, top + Math.max(1, height * 0.6));\r\n    const data = ctx.getImageData(\r\n      0,\r\n      top,\r\n      canvas.width,\r\n      Math.ceil(bottom - top),\r\n    ).data;\r\n    let lo = Number.POSITIVE_INFINITY;\r\n    let hi = Number.NEGATIVE_INFINITY;\r\n    for (let i = 3; i < data.length; i += 4) {\r\n      if (data[i] <= 8) continue;\r\n      const x = (i >> 2) % canvas.width;\r\n      if (x < lo) lo = x;\r\n      if (x > hi) hi = x;\r\n    }\r\n    if (lo === Number.POSITIVE_INFINITY) continue;\r\n    const inkLeft = origin - m.actualBoundingBoxLeft;\r\n    const inkWidth = m.actualBoundingBoxRight + m.actualBoundingBoxLeft;\r\n    if (!(inkWidth > 0)) continue;\r\n    tabs.set(ch, {\r\n      height,\r\n      x: Math.max(0, (lo - inkLeft) / inkWidth),\r\n      width: Math.min(1, (hi - lo + 1) / inkWidth),\r\n    });\r\n  }\r\n\r\n  return { xHeight, tabs };\r\n}\r\n\r\n// ─── Props ─────────────────────────────────────────────────────────────────────\r\n\r\nexport interface BlockWordmarkProps {\r\n  /** The word to build. Any text: spaces get no block, emoji get their own. */\r\n  text?: string;\r\n  /** Size the finished wordmark is set at, in px. */\r\n  fontSize?: number;\r\n  /** Defaults to Ultra, loaded through `@remotion/google-fonts`. Ultra has one\r\n   *  weight (400) — see the loader note above before offering another. */\r\n  fontFamily?: string;\r\n  fontWeight?: number | string;\r\n  /** The wordmark's ink. Overrides the design system's `foreground`. */\r\n  color?: string;\r\n  /**\r\n   * The deck's cards and the flash colours, in order. Accepts an array or a\r\n   * comma-separated string (which is what the customizer's text control passes).\r\n   * The lead card is always `color`; these are the ones behind it.\r\n   */\r\n  colors?: string[] | string;\r\n  /** Stage behind the build. Overrides the design system's `background`. */\r\n  background?: string;\r\n\r\n  /** Gap between blocks, as a fraction of the block's side. */\r\n  blockGap?: number;\r\n  /** Corner radius of a block, as a fraction of its side. */\r\n  cornerRadius?: number;\r\n  /**\r\n   * How tall an ascender's tab grows, as a fraction of the block's height.\r\n   * Omitted, it is **measured** per glyph — how far that letter's ink actually\r\n   * rises above the x-height — which is the only value that stays right when the\r\n   * font changes. The reference's own face gives 0.40; Inter gives 0.33.\r\n   */\r\n  ascenderRatio?: number;\r\n  /**\r\n   * Width of that tab, as a fraction of the block's width. Omitted, it is\r\n   * measured too: the stem of a \"b\", the whole width of a \"B\". The reference\r\n   * widens its own stem by about 60% into a chunky flag — `0.415` reproduces it.\r\n   */\r\n  ascenderStemRatio?: number;\r\n  /**\r\n   * `\"square\"` (measured) makes every block a square of side = cap height, so\r\n   * the row is an even rhythm and each block visibly *changes* into its letter.\r\n   * `\"glyph\"` sizes each block to the advance width of the letter it becomes,\r\n   * which makes the resolve nearly in-place.\r\n   */\r\n  blockSizing?: \"square\" | \"glyph\";\r\n  /** Fraction of the frame width the row may occupy before it is scaled to fit. */\r\n  maxWidth?: number;\r\n\r\n  /** Cards in the deck, including the lead one. */\r\n  cards?: number;\r\n  /** Frames between one card's turn starting and the next card's. */\r\n  cardStagger?: number;\r\n  /** Full turns the deck makes while it fans and winds back in. */\r\n  spinTurns?: number;\r\n  /** How far the deck lifts off the baseline as it fans, as a fraction of side. */\r\n  liftRatio?: number;\r\n\r\n  /** Frames the first square takes to scale in. */\r\n  growDuration?: number;\r\n  /** Frames the deck's turn lasts. */\r\n  spinDuration?: number;\r\n  /** Frames a block takes to travel from the square to its slot. */\r\n  splitDuration?: number;\r\n  /** Frames the inner blocks lag the outer ones by. The split runs outside-in. */\r\n  splitStagger?: number;\r\n  /** Frames an ascender's tab takes to grow. */\r\n  ascenderDuration?: number;\r\n  /** Frames the finished block row holds before the letters resolve. */\r\n  holdDuration?: number;\r\n  /** Frames between one letter's flash and the next. The first step is half. */\r\n  flashStagger?: number;\r\n  /** Frames a block stays lit in its flash colour. */\r\n  flashDuration?: number;\r\n  /** Frames from a block lighting up to it being replaced by its letter. */\r\n  flashToSwap?: number;\r\n\r\n  speed?: number;\r\n  className?: string;\r\n  /** Design-system token overrides. */\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n}\r\n\r\n/**\r\n * The accent palette, ours: **one hue, five shades**.\r\n *\r\n * Every card is `primary` walked toward pure white or pure black in OKLCH, so\r\n * the deck is a tonal ramp of the installer's own accent rather than five\r\n * unrelated hues — override `theme.primary` and the whole deck moves with it,\r\n * which a hardcoded set could never do.\r\n *\r\n * **Pure `#fff`/`#000`, deliberately, not `t.background`/`t.foreground`.** Those\r\n * are warm neutrals, and OKLCH interpolation carries their hue: mixing this blue\r\n * 28% toward the warm off-white background measures out at `rgb(0,172,196)` —\r\n * cyan — and 52% lands on `rgb(124,203,178)`, a green. Pure endpoints have no\r\n * hue to contribute, so all five stay on h≈260 and only lightness moves, which\r\n * is what \"shades of one blue\" has to mean.\r\n *\r\n * Alternating darker/lighter rather than a straight ramp: the cards fan out\r\n * overlapping, so neighbours need contrast against *each other*, not just\r\n * against the stage.\r\n *\r\n * The reference's own six colours are its **brand** (design-system rule 5), so\r\n * they are not the default — they are one prop away:\r\n * `colors=\"#ABF25B,#FA361A,#FCCA28,#337DFE,#F99BCA\" color=\"#0000FF\"`.\r\n */\r\nfunction defaultColors(t: KuchiTheme): string[] {\r\n  return [\r\n    t.primary,\r\n    mixOklch(t.primary, \"#000000\", 0.3),\r\n    mixOklch(t.primary, \"#ffffff\", 0.28),\r\n    mixOklch(t.primary, \"#000000\", 0.55),\r\n    mixOklch(t.primary, \"#ffffff\", 0.52),\r\n  ];\r\n}\r\n\r\n/**\r\n * A wordmark that builds itself out of blocks.\r\n *\r\n * 1. A rounded square scales up off the baseline.\r\n * 2. Coloured squares fan out from behind it like a deck being shuffled and wind\r\n *    back in — one full turn each, staggered, about a **shared** pivot on the\r\n *    baseline. The fan is the stagger sampling one S-curve at different times;\r\n *    it opens and closes exactly once.\r\n * 3. The deck lands, dips once, and the square splits into one block per letter,\r\n *    outermost blocks leading. The first ascender grows a tab: the \"b\".\r\n * 4. The row holds, then each block flashes a colour, returns to ink, and is\r\n *    **hard-cut** to its real letterform. The first letter resolves last.\r\n *\r\n * Nothing crossfades and nothing morphs: measured against the reference, at each\r\n * swap frame the ink is already within a handful of pixels of the settled\r\n * wordmark and one frame earlier it is 2,000 off. The cut *is* the effect — a\r\n * spring or a crossfade \"to improve it\" is the one change that breaks it.\r\n */\r\nexport function BlockWordmark({\r\n  text = \"base\",\r\n  fontSize = 160,\r\n  fontFamily,\r\n  fontWeight = 400,\r\n  color,\r\n  colors,\r\n  background,\r\n  blockGap = 0.093,\r\n  cornerRadius = 0.18,\r\n  ascenderRatio,\r\n  ascenderStemRatio,\r\n  blockSizing = \"square\",\r\n  maxWidth = 0.92,\r\n  cards = 6,\r\n  cardStagger = 2,\r\n  spinTurns = 1,\r\n  liftRatio = 0.665,\r\n  growDuration = 9,\r\n  spinDuration = 33,\r\n  splitDuration = 5,\r\n  splitStagger = 1,\r\n  ascenderDuration = 12,\r\n  holdDuration = 54,\r\n  flashStagger = 4,\r\n  flashDuration = 3,\r\n  flashToSwap = 5,\r\n  speed = 1,\r\n  className,\r\n  theme,\r\n  mode,\r\n}: BlockWordmarkProps) {\r\n  const frame = useCurrentFrame() * speed;\r\n  const { width, height, fps } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face = resolveFont(fontFamily ?? t.fontFamily) ?? ULTRA;\r\n  const ink = color ?? t.foreground;\r\n  const stage = background ?? t.background;\r\n  const palette =\r\n    (typeof colors === \"string\"\r\n      ? colors\r\n          .split(\",\")\r\n          .map((c) => c.trim())\r\n          .filter(Boolean)\r\n      : colors) ?? defaultColors(t);\r\n  const deck = palette.length > 0 ? palette : defaultColors(t);\r\n\r\n  // `Array.from` splits by code point, so an emoji stays one glyph instead of\r\n  // becoming two broken surrogate halves.\r\n  const chars = Array.from(text);\r\n\r\n  // Advance widths and the baseline come from the DOM, because they have to\r\n  // agree with the DOM that actually paints the letters. Ink metrics come from a\r\n  // canvas (see `measureInk`). Both are constant across every frame, so measure\r\n  // once behind `delayRender` and only release the render after the measurement\r\n  // has re-rendered — otherwise frame 0 is captured with the wrong geometry.\r\n  const probeRef = useRef<HTMLDivElement>(null);\r\n  const charRefs = useRef<(HTMLSpanElement | null)[]>([]);\r\n  const rulerRef = useRef<HTMLSpanElement>(null);\r\n  const [handle] = useState(() =>\r\n    delayRender(\"block-wordmark: measure glyphs\"),\r\n  );\r\n  const [metrics, setMetrics] = useState<Metrics | null>(null);\r\n  // A `<Player>` paints the whole composition through one `transform: scale()`,\r\n  // so `getBoundingClientRect()` below comes back in *device* px while the canvas\r\n  // metrics in `measureInk` are composition px. Mixing the two lays the letters\r\n  // out on a track ~40% too short and drops them ~50px below the block row — and\r\n  // only on the site, because `renderMedia` runs at scale 1.\r\n  const scale = useCurrentScale({ dontThrowIfOutsideOfRemotion: true });\r\n\r\n  useEffect(() => {\r\n    let cancelled = false;\r\n    const run = () => {\r\n      if (cancelled) return;\r\n      const box = probeRef.current;\r\n      const ruler = rulerRef.current;\r\n      if (!box || !ruler) {\r\n        continueRender(handle);\r\n        return;\r\n      }\r\n      const glyphChars = Array.from(text);\r\n      // Every rect read is divided back into composition px — see `scale`.\r\n      const s = scale || 1;\r\n      const boxTop = box.getBoundingClientRect().top / s;\r\n      const advances = glyphChars.map(\r\n        (_, i) => (charRefs.current[i]?.getBoundingClientRect().width ?? 0) / s,\r\n      );\r\n      // A zero-sized inline-block aligns its bottom edge to the text baseline, so\r\n      // its own top *is* the baseline. `getBoundingClientRect` rather than\r\n      // `offsetTop`, which is rounded to a whole pixel.\r\n      const baselineOffset = ruler.getBoundingClientRect().top / s - boxTop;\r\n      const unique = Array.from(\r\n        new Set(glyphChars.filter((c) => c.trim() !== \"\")),\r\n      );\r\n      const measured = measureInk(unique, face, fontWeight, fontSize);\r\n      setMetrics({\r\n        xHeight: measured?.xHeight ?? fontSize * 0.52,\r\n        baselineOffset: baselineOffset || fontSize * 0.86,\r\n        glyphs: glyphChars.map((ch, i) => ({\r\n          ch,\r\n          blank: ch.trim() === \"\",\r\n          advance: advances[i],\r\n          tab: measured?.tabs.get(ch) ?? null,\r\n        })),\r\n      });\r\n    };\r\n    // Measuring against a fallback face and then swapping in the real one is the\r\n    // classic way to get a wordmark whose blocks are all the wrong width.\r\n    // `document.fonts.ready` on its own is not that gate: it resolves straight\r\n    // away whenever no load happens to be pending when this effect runs, so wait\r\n    // on the loader's own promise too.\r\n    Promise.all([\r\n      ultraReady(),\r\n      typeof document !== \"undefined\" && document.fonts\r\n        ? document.fonts.ready\r\n        : null,\r\n    ]).then(run, run);\r\n    return () => {\r\n      cancelled = true;\r\n    };\r\n    // The deps are the raw inputs, never the derived `chars` array: `Array.from`\r\n    // hands back a new array every render, which would re-run the measurement\r\n    // (and its `delayRender`) forever. `scale` only ever cancels itself back out,\r\n    // so a re-run on resize produces the identical metrics.\r\n  }, [handle, text, face, fontWeight, fontSize, scale]);\r\n\r\n  useEffect(() => {\r\n    if (metrics) continueRender(handle);\r\n  }, [metrics, handle]);\r\n\r\n  // ─── Layout ─────────────────────────────────────────────────────────────────\r\n\r\n  const glyphs =\r\n    metrics?.glyphs ??\r\n    chars.map((ch) => ({\r\n      ch,\r\n      blank: ch.trim() === \"\",\r\n      advance: fontSize * 0.55,\r\n      tab: null as Tab | null,\r\n    }));\r\n  const xHeight = metrics?.xHeight ?? fontSize * 0.52;\r\n  const baselineOffset = metrics?.baselineOffset ?? fontSize * 0.86;\r\n\r\n  // Two independent static layouts, exactly as measured: a row of blocks whose\r\n  // side is the x-height, and a row of letters at their natural advance widths. They are *not* the same row — the blocks are an even rhythm and the\r\n  // letters are not — which is why the resolve has to move and resize each slot\r\n  // rather than just repaint it.\r\n  const letterEnds: number[] = [];\r\n  let letterRun = 0;\r\n  for (const g of glyphs) {\r\n    letterEnds.push(letterRun);\r\n    letterRun += g.advance;\r\n  }\r\n  const letterTotal = letterRun;\r\n\r\n  const gapPx = blockGap * xHeight;\r\n  /** Glyph index of each block — a space produces no block. */\r\n  const blockGlyph: number[] = [];\r\n  const blockStarts: number[] = [];\r\n  const blockWidths: number[] = [];\r\n  const blockOf: number[] = [];\r\n  let blockRun = 0;\r\n  let prevWasBlock = false;\r\n  for (let i = 0; i < glyphs.length; i++) {\r\n    const g = glyphs[i];\r\n    if (g.blank) {\r\n      // A space already separates the blocks either side of it, so it does not\r\n      // also get a `blockGap`; its own advance width is the word space.\r\n      blockRun += g.advance;\r\n      prevWasBlock = false;\r\n      blockOf.push(-1);\r\n      continue;\r\n    }\r\n    if (prevWasBlock) blockRun += gapPx;\r\n    blockOf.push(blockGlyph.length);\r\n    blockGlyph.push(i);\r\n    blockStarts.push(blockRun);\r\n    blockWidths.push(blockSizing === \"glyph\" ? g.advance : xHeight);\r\n    blockRun += blockWidths[blockWidths.length - 1];\r\n    prevWasBlock = true;\r\n  }\r\n  const blockTotal = blockRun;\r\n\r\n  // A long word must not run off the frame. This is a *constant* scale, folded\r\n  // into the measured px and into `font-size` rather than applied as a transform\r\n  // — a static size re-rasterises once, where an animated one boils.\r\n  const fit = Math.min(\r\n    1,\r\n    (width * maxWidth) / Math.max(1, letterTotal, blockTotal),\r\n  );\r\n  const side = xHeight * fit;\r\n  const radius = cornerRadius * side;\r\n  const cx = width / 2;\r\n  /** Height of a block's tab in fitted px — measured, unless overridden. */\r\n  const tabHeightOf = (g: Glyph) =>\r\n    g.tab === null\r\n      ? 0\r\n      : ascenderRatio === undefined\r\n        ? g.tab.height * fit\r\n        : ascenderRatio * side;\r\n  const rowTop =\r\n    side + Math.max(0, ...blockGlyph.map((i) => tabHeightOf(glyphs[i])));\r\n  // The one invariant across the whole build: the baseline. Everything is pinned\r\n  // to it — the deck's pivot, the blocks' bottom edge, the letters. The row is\r\n  // centred on its *ink* box, tab included, not on the square.\r\n  const baselineY = height / 2 + rowTop / 2;\r\n  const letterLeft = (width - letterTotal * fit) / 2;\r\n  const blockLeft = (width - blockTotal * fit) / 2;\r\n\r\n  // ─── Beats ──────────────────────────────────────────────────────────────────\r\n\r\n  const nCards = Math.max(1, Math.round(cards));\r\n  // The deck is visually done half the stagger's spread after the lead card's\r\n  // turn ends. Rounded, because the anticipation dip below peaks on a single\r\n  // frame: at an odd `cardStagger * (nCards - 1)` a fractional `collapseAt` puts\r\n  // that peak between two samples and the beat silently does not happen.\r\n  const collapseAt = Math.round(\r\n    spinDuration + (cardStagger * (nCards - 1)) / 2,\r\n  );\r\n  const splitStart = collapseAt + 2;\r\n  const ascenderStart = splitStart + 2;\r\n  const resolveStart = splitStart + holdDuration;\r\n\r\n  const grow = interpolate(frame, [0, Math.max(1, growDuration)], [0, 1], {\r\n    ...CLAMP,\r\n    easing: OUT_EASE,\r\n  });\r\n\r\n  /**\r\n   * One rigid rotation about an offset origin — spin angle *is* orbit angle.\r\n   *\r\n   * A trailing card's turn is compressed so that it *ends* by `collapseAt`. The\r\n   * stagger is on the starts, so the fan still opens exactly as measured; but a\r\n   * card whose turn ran past the collapse would still be 6° short — a 10px\r\n   * corner sticking out from behind the lead square — on the frame the deck is\r\n   * meant to be gone, and would then either pop out of existence or show through\r\n   * the gaps as the square splits. The lead card (`card === 0`) is never\r\n   * compressed: `collapseAt >= spinDuration` by construction.\r\n   */\r\n  const turn = (card: number) => {\r\n    const start = card * cardStagger;\r\n    const span = Math.max(1, Math.min(spinDuration, collapseAt - start));\r\n    return interpolate(frame - start, [0, span], [0, 360 * spinTurns], {\r\n      ...CLAMP,\r\n      easing: SPIN_EASE,\r\n    });\r\n  };\r\n\r\n  // The lift is one translate shared by every card — a version where each card's\r\n  // lift lags with its own stagger measures much worse against the reference.\r\n  // Out on an overdamped spring, back down on an accelerating fall.\r\n  const lift =\r\n    liftRatio *\r\n    side *\r\n    (spring({\r\n      frame: Math.max(0, frame - 2),\r\n      fps,\r\n      config: { damping: 60, stiffness: 330, mass: 1 },\r\n    }) -\r\n      interpolate(frame, [collapseAt - 9, collapseAt], [0, 1], {\r\n        ...CLAMP,\r\n        easing: IN_EASE,\r\n      }));\r\n\r\n  // One frame of anticipation before the split: the square lifts 3% of its side\r\n  // and squashes about 1%. It is a single frame at 30fps and it is what sells\r\n  // the split.\r\n  const dip = interpolate(\r\n    frame,\r\n    [collapseAt, collapseAt + 1, collapseAt + 3],\r\n    [0, 1, 0],\r\n    CLAMP,\r\n  );\r\n\r\n  /** Blocks travel outside-in: the outermost pair leads, each step in lags. */\r\n  const splitRank = (b: number) => {\r\n    const mid = (blockWidths.length - 1) / 2;\r\n    return Math.round(mid - Math.abs(b - mid));\r\n  };\r\n  const splitProgress = (b: number) =>\r\n    interpolate(\r\n      frame - splitStart - splitRank(b) * splitStagger,\r\n      [0, Math.max(1, splitDuration)],\r\n      [0, 1],\r\n      { ...CLAMP, easing: OUT_EASE },\r\n    );\r\n\r\n  const tabGrow = interpolate(\r\n    frame,\r\n    [ascenderStart, ascenderStart + Math.max(1, ascenderDuration)],\r\n    [0, 1],\r\n    { ...CLAMP, easing: OUT_EASE },\r\n  );\r\n\r\n  // The letters resolve left to right *from the second one*, wrapping to the\r\n  // first letter last, and the first gap is half a step — a deliberately\r\n  // irregular rhythm that a uniform stagger visibly mistimes.\r\n  const order: number[] = [];\r\n  for (let b = 1; b < blockWidths.length; b++) order.push(b);\r\n  if (blockWidths.length > 0) order.push(0);\r\n  const cue = new Map<number, number>();\r\n  order.forEach((b, k) => {\r\n    cue.set(b, k === 0 ? 0 : flashStagger * k - flashStagger / 2);\r\n  });\r\n  const flashOf = new Map<number, string>();\r\n  order.forEach((b, k) => {\r\n    flashOf.set(b, deck[k % deck.length]);\r\n  });\r\n\r\n  const ready = metrics !== null;\r\n  const isRendering = getRemotionEnvironment().isRendering;\r\n  const accel = isRendering ? null : { willChange: \"transform\" as const };\r\n  const squareLeft = cx - side / 2;\r\n\r\n  return (\r\n    <AbsoluteFill\r\n      className={className}\r\n      style={{\r\n        backgroundColor: stage,\r\n        overflow: \"hidden\",\r\n        fontFamily: face,\r\n        fontWeight,\r\n        // Hinting re-snaps every stem as a glyph changes size, so the letterforms\r\n        // literally change shape frame to frame. Off, they hold still.\r\n        textRendering: \"geometricPrecision\",\r\n      }}\r\n    >\r\n      {/* Hidden probe. Laid out with the same face, weight and size as the real\r\n          letters, so its advance widths are the widths that will be painted. */}\r\n      <div\r\n        ref={probeRef}\r\n        aria-hidden\r\n        style={{\r\n          position: \"absolute\",\r\n          left: 0,\r\n          top: 0,\r\n          visibility: \"hidden\",\r\n          pointerEvents: \"none\",\r\n          whiteSpace: \"pre\",\r\n          lineHeight: 1,\r\n          fontSize,\r\n        }}\r\n      >\r\n        {chars.map((ch, i) => (\r\n          <span\r\n            // biome-ignore lint/suspicious/noArrayIndexKey: glyphs are positional and never reorder\r\n            key={i}\r\n            ref={(el) => {\r\n              charRefs.current[i] = el;\r\n            }}\r\n            style={{ display: \"inline-block\", whiteSpace: \"pre\" }}\r\n          >\r\n            {ch}\r\n          </span>\r\n        ))}\r\n        <span\r\n          ref={rulerRef}\r\n          style={{ display: \"inline-block\", width: 0, height: 0 }}\r\n        />\r\n      </div>\r\n\r\n      <AbsoluteFill\r\n        style={{\r\n          opacity: ready ? 1 : 0,\r\n          // The lift moves the deck's shared pivot; the dip squashes it onto the\r\n          // baseline. Both pivot on the baseline, so the bottom edge never moves.\r\n          transformOrigin: `50% ${baselineY}px`,\r\n          transform: `translateY(${-lift - dip * side * 0.03}px) scaleY(${1 - dip * 0.013})`,\r\n        }}\r\n      >\r\n        {/* The deck, back to front. The lead card is the block row below, which\r\n            paints over all of them — it is never occluded. */}\r\n        {frame < collapseAt + 1 &&\r\n          Array.from({ length: nCards - 1 }, (_, i) => nCards - 1 - i).map(\r\n            (k) => (\r\n              <div\r\n                key={`card-${k}`}\r\n                style={{\r\n                  position: \"absolute\",\r\n                  left: squareLeft,\r\n                  top: baselineY - side,\r\n                  width: side,\r\n                  height: side,\r\n                  borderRadius: radius,\r\n                  backgroundColor: deck[(k - 1) % deck.length],\r\n                  // Bottom centre, not the middle. The orbit radius is exactly\r\n                  // half the side because the pivot is on the square's own edge:\r\n                  // get this wrong and the deck spins in place instead of\r\n                  // sweeping.\r\n                  transformOrigin: \"50% 100%\",\r\n                  transform: `rotate(${turn(k)}deg) scale(${grow})`,\r\n                  ...accel,\r\n                }}\r\n              />\r\n            ),\r\n          )}\r\n\r\n        {/* The block row. Every block starts life *as* the lead card — same box,\r\n            same transform — so beats 1–3 draw one square, and the split simply\r\n            lets them walk apart. */}\r\n        {blockWidths.map((w, b) => {\r\n          const p = splitProgress(b);\r\n          const g = glyphs[blockGlyph[b]];\r\n          const swapAt = resolveStart + (cue.get(b) ?? 0) + flashToSwap;\r\n          if (frame >= swapAt) return null;\r\n          const flashOn = resolveStart + (cue.get(b) ?? 0);\r\n          const lit = frame >= flashOn && frame < flashOn + flashDuration;\r\n          const fill = lit ? (flashOf.get(b) ?? ink) : ink;\r\n          const left =\r\n            squareLeft + (blockLeft + blockStarts[b] * fit - squareLeft) * p;\r\n          const bw = side + (w * fit - side) * p;\r\n          const tab = g?.tab ?? null;\r\n          const tabH = tab ? tabGrow * tabHeightOf(g) : 0;\r\n          // Measured off the glyph: a \"b\" gives a narrow stem at its left edge,\r\n          // a \"B\" gives the block's whole width, an emoji gives most of it.\r\n          const tabW = tab ? bw * (ascenderStemRatio ?? tab.width) : 0;\r\n          const tabX = tab\r\n            ? Math.min(Math.max(0, tab.x * bw), Math.max(0, bw - tabW))\r\n            : 0;\r\n          const notched = tabH > radius;\r\n          return (\r\n            <div\r\n              // biome-ignore lint/suspicious/noArrayIndexKey: blocks are a fixed positional row — the index IS a block's identity\r\n              key={`block-${b}`}\r\n              style={{\r\n                position: \"absolute\",\r\n                left,\r\n                top: baselineY - side,\r\n                width: bw,\r\n                height: side,\r\n                borderRadius: radius,\r\n                // Only kill the corner the tab actually lands on, or the flag\r\n                // grows a notch where the two shapes meet.\r\n                borderTopLeftRadius: notched && tabX < 1 ? 0 : radius,\r\n                borderTopRightRadius:\r\n                  notched && tabX + tabW > bw - 1 ? 0 : radius,\r\n                backgroundColor: fill,\r\n                transformOrigin: \"50% 100%\",\r\n                transform: `rotate(${turn(0)}deg) scale(${grow})`,\r\n                ...accel,\r\n              }}\r\n            >\r\n              {/* The tab grows in **height only** — it is full width from the\r\n                  first frame it exists. Scaling the whole silhouette up out of\r\n                  the block would widen the stem too, and that is a different,\r\n                  wrong shape. */}\r\n              {tabH > 0 && (\r\n                <div\r\n                  style={{\r\n                    position: \"absolute\",\r\n                    bottom: \"100%\",\r\n                    left: tabX,\r\n                    width: tabW,\r\n                    height: tabH,\r\n                    backgroundColor: fill,\r\n                    borderTopLeftRadius: radius,\r\n                    borderTopRightRadius: radius,\r\n                  }}\r\n                />\r\n              )}\r\n            </div>\r\n          );\r\n        })}\r\n\r\n        {/* The letters. Each one is cut in at its final position, final size and\r\n            final ink — the flash colour never touches the letterform. */}\r\n        {glyphs.map((g, i) => {\r\n          const b = blockOf[i];\r\n          if (b < 0) return null;\r\n          const swapAt = resolveStart + (cue.get(b) ?? 0) + flashToSwap;\r\n          if (frame < swapAt) return null;\r\n          return (\r\n            <span\r\n              // biome-ignore lint/suspicious/noArrayIndexKey: glyphs are positional and never reorder\r\n              key={`letter-${i}`}\r\n              style={{\r\n                position: \"absolute\",\r\n                left: letterLeft + letterEnds[i] * fit,\r\n                top: baselineY - baselineOffset * fit,\r\n                fontSize: fontSize * fit,\r\n                lineHeight: 1,\r\n                whiteSpace: \"pre\",\r\n                color: ink,\r\n              }}\r\n            >\r\n              {g.ch}\r\n            </span>\r\n          );\r\n        })}\r\n      </AbsoluteFill>\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n"}]}