{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"logo-collapse","type":"registry:component","title":"Logo Collapse","description":"Logo reveal intro: a stack of photos flicks through and collapses into your logo. A stack of shots flicked through, collapsing into your mark, and the wordmark landing beside it.","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/logo-collapse.tsx","type":"registry:component","target":"components/kuchi/logo-collapse.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 loadSans } from \"@remotion/google-fonts/InterTight\";\r\nimport type { CSSProperties } from \"react\";\r\nimport { forwardRef, useCallback, useState } from \"react\";\r\nimport {\r\n  AbsoluteFill,\r\n  continueRender,\r\n  delayRender,\r\n  getRemotionEnvironment,\r\n  staticFile,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\nimport {\r\n  Item,\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\n/**\r\n * A stack of shots flicked through, collapsing into the mark, and the wordmark\r\n * landing beside it.\r\n *\r\n * One square card holds the middle of the frame and cuts to the next shot, each\r\n * one smaller and each held for less time than the last, so the sequence winds\r\n * itself up rather than running at a constant clip. At the end of the run the\r\n * card does not shrink away — it *collapses*, overshooting past its resting size\r\n * in a frame and settling back. Then the mark steps aside and the wordmark takes\r\n * the space it made.\r\n *\r\n * ## The cuts are cuts\r\n *\r\n * Nothing cross-fades and nothing tweens between shots. The reference holds each\r\n * card at a fixed size for its whole beat — measured, the box is constant to the\r\n * pixel across every frame of a hold, and then a different size on the next one.\r\n * A card that eased between sizes would read as a zoom; a card that cuts reads as\r\n * a stack of prints being dealt, which is the whole idea.\r\n *\r\n * That is also why `sizes` and `holds` are parallel lists of literals rather than\r\n * a ratio and a duration. The reference's own run is 0.512, 0.476, 0.458, 0.414,\r\n * 0.339 of the frame height on beats of 1, 6, 5, 4, 2 and 4 frames — neither\r\n * series is geometric, and a formula that fitted one would miss the other.\r\n *\r\n * ## The collapse overshoots\r\n *\r\n * 30px, then 24, then 22, on three consecutive frames. Two frames of overshoot is\r\n * the difference between a mark that lands and a mark that is simply smaller than\r\n * the card was — and it is the only place in the scene where anything moves\r\n * between frames rather than cutting.\r\n *\r\n * ## The mark steps aside in two\r\n *\r\n * Centred alone at 294.5; then 282.0 for four frames; then 248.5 as the wordmark\r\n * appears whole. Two steps, held, not an ease — the same grammar as the cards.\r\n */\r\n\r\nconst { fontFamily: SANS } = loadSans(\"normal\", {\r\n  weights: [\"600\", \"700\"],\r\n  subsets: [\"latin\"],\r\n});\r\n\r\n/* ─────────────────────────────────────────────────────────────────────────\r\n   The stage, in the recording's own 592 × 336 pixels\r\n   ───────────────────────────────────────────────────────────────────────── */\r\n\r\nexport const REF_W = 592;\r\nexport const REF_H = 336;\r\n\r\n/** Where the card, and then the mark, sits. */\r\nexport const STAGE_X = 294;\r\nexport const STAGE_Y = 167.5;\r\n\r\n/**\r\n * The mark's box, frame by frame, from the moment the stack runs out.\r\n *\r\n * It lands oversized and settles in three steps rather than easing: 32, 25, 24,\r\n * then 23 for the rest of the scene. Measured on the mark's orange core, which\r\n * is the only part of it a threshold can find honestly — the glow around it\r\n * reads as ink to anything looser and makes the landing look 40% bigger than it\r\n * is.\r\n */\r\nexport const MARK = 22;\r\nexport const LAND: readonly number[] = [32, 25, 24, 24];\r\n\r\n/**\r\n * The tile the stack collapses onto, before the mark is left alone.\r\n *\r\n * This is the beat that is easy to miss and impossible to unsee: the photo card\r\n * does not shrink into the mark, it *cuts* to a plain light tile of 60px with\r\n * the mark sitting on it, holds for two frames, and only then does the tile go.\r\n * It is very faint — luma 233 against the page's 247, which is why nothing\r\n * thresholded at 200 finds it — and it is what makes the collapse read as a\r\n * stack of prints resolving into a logo rather than as a card that shrank.\r\n */\r\nexport const TILE = 60;\r\nexport const TILE_FRAMES = 2;\r\n\r\n/** Left edge of the finished lockup, and where the word starts inside it. */\r\nexport const LOCK_X = 237;\r\nexport const WORD_X = 264;\r\n\r\n/** Cap height of the wordmark, measured on its own ink. */\r\nexport const WORD_CAP = 19.37;\r\n/** Top of the wordmark's box. Measured, not derived from a line-height ratio. */\r\nexport const WORD_TOP = 155.74;\r\n/**\r\n * Cap height → font-size, and the tracking a logotype is set at.\r\n *\r\n * A wordmark is lettering, not type: the reference's is 4.149 cap-widths for six\r\n * glyphs, and the nearest face on the shelf sets the same six at 4.634 — twelve\r\n * per cent loose. That gap is tracking, not the wrong face. Inter Tight at\r\n * −0.073em closes it; every other candidate measured wider still (Archivo 4.786,\r\n * Plus Jakarta 4.877, Space Grotesk 4.975, Manrope 5.011, Poppins 5.715).\r\n */\r\nexport const WORD_EM = 1.326;\r\nexport const WORD_TRACK = -0.073;\r\n\r\n/** The mark's waypoint: where it waits before the wordmark arrives. */\r\nexport const STEP_X = 281.5;\r\n\r\n/** Frames, on the scene's own 30fps clock. */\r\nexport const STEP_AT = 28;\r\nexport const WORD_AT = 30;\r\nexport const DOT_AT: readonly number[] = [37, 42];\r\n\r\n/**\r\n * The two marks that bracket the lockup, and the ping each one arrives on.\r\n *\r\n * They do not simply appear: each lands at 7px in full accent and settles to 4px\r\n * and about a third of its ink over five frames. Measured on both — the upper\r\n * one is already pale and small by the frame the lower one lands, which is the\r\n * only reason you can tell they are two beats and not one.\r\n */\r\nexport const DOTS: readonly (readonly [number, number])[] = [\r\n  [229, 147],\r\n  [229, 191],\r\n];\r\nexport const DOT_IN = 7;\r\nexport const DOT_OUT = 4;\r\nexport const DOT_SETTLE = 5;\r\nexport const DOT_FADE = 0.34;\r\n\r\nexport interface LogoCollapseProps {\r\n  /**\r\n   * The shots, split by `|`. The card cuts through them in order.\r\n   *\r\n   * Not by comma: a `data:` URL has one of its own right after the encoding, and\r\n   * splitting on it hands the browser half a URL and a card that renders as a\r\n   * broken-image glyph.\r\n   */\r\n  images?: string;\r\n  /**\r\n   * Each shot's card, as a share of the frame height.\r\n   *\r\n   * `0.48` is a square; `0.515x0.5625` is a portrait one. Real photo sets are\r\n   * not all one shape, and the reference's second shot is measurably taller\r\n   * than it is wide — forcing it square crops fifteen pixels off a print that\r\n   * was never square.\r\n   */\r\n  sizes?: string;\r\n  /** Frames each shot is held for. */\r\n  holds?: string;\r\n  /** The mark the stack collapses into. */\r\n  mark?: string;\r\n  /** The word that lands beside it. */\r\n  wordmark?: string;\r\n  /** Optional plate behind everything — a paper, a gradient, a still. */\r\n  background?: string;\r\n  /** The brand colour the two bracket marks ping in. Blank uses the accent. */\r\n  accent?: string;\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n  fontFamily?: string;\r\n}\r\n\r\nexport function LogoCollapse({\r\n  images = \"https://kuchi-media.kalarislabs.com/components/art/art-08.svg|https://kuchi-media.kalarislabs.com/components/art/art-01.svg|https://kuchi-media.kalarislabs.com/components/art/art-07.svg|https://kuchi-media.kalarislabs.com/components/art/art-04.svg|https://kuchi-media.kalarislabs.com/components/art/art-04.svg|https://kuchi-media.kalarislabs.com/components/art/art-01.svg\",\r\n  sizes = \"0.82x0.461,0.72x0.405,0.63x0.354,0.55x0.309,0.46x0.259,0.36x0.203\",\r\n  holds = \"1,5,5,4,2,5\",\r\n  mark = \"https://kuchi-media.kalarislabs.com/components/art/mark.svg\",\r\n  wordmark = \"kuchi\",\r\n  background = \"\",\r\n  accent = \"\",\r\n  theme,\r\n  mode = \"light\",\r\n  fontFamily = \"Default\",\r\n}: LogoCollapseProps) {\r\n  const frame = useCurrentFrame();\r\n  const { width, height } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face = resolveFont(fontFamily) ?? SANS;\r\n\r\n  const u = height / REF_H;\r\n  const ox = (width - REF_W * u) / 2;\r\n\r\n  const shots = images\r\n    .split(\"|\")\r\n    .map((s) => s.trim())\r\n    .filter(Boolean);\r\n  const size = sizes.split(\",\").map((s) => {\r\n    const [w, h] = s.trim().split(\"x\");\r\n    const sw = Number(w);\r\n    return [sw, h === undefined ? sw : Number(h)] as const;\r\n  });\r\n  const hold = holds.split(\",\").map((s) => Number(s.trim()));\r\n\r\n  // Which shot is up, and the frame the stack runs out on.\r\n  let at = 0;\r\n  let shot = -1;\r\n  for (let i = 0; i < shots.length; i++) {\r\n    const end = at + (hold[i] ?? 0);\r\n    if (frame < end) {\r\n      shot = i;\r\n      break;\r\n    }\r\n    at = end;\r\n  }\r\n  const collapseAt = hold\r\n    .slice(0, shots.length)\r\n    .reduce((a, b) => a + (b || 0), 0);\r\n\r\n  const ink = t.foreground;\r\n\r\n  return (\r\n    <AbsoluteFill style={{ backgroundColor: t.background }}>\r\n      {background && (\r\n        <Plate\r\n          src={background}\r\n          style={{ position: \"absolute\", inset: 0, objectFit: \"cover\" }}\r\n        />\r\n      )}\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: ox,\r\n          top: 0,\r\n          width: REF_W * u,\r\n          height: REF_H * u,\r\n          fontFamily: face,\r\n          textRendering: \"geometricPrecision\",\r\n        }}\r\n      >\r\n        {shot >= 0 ? (\r\n          <Item key={shot} index={shot}>\r\n            <Plate\r\n              src={shots[shot] ?? \"\"}\r\n              style={box(\r\n                (size[shot]?.[0] ?? 0.4) * REF_H,\r\n                (size[shot]?.[1] ?? 0.4) * REF_H,\r\n                STAGE_X,\r\n                STAGE_Y,\r\n                u,\r\n              )}\r\n            />\r\n          </Item>\r\n        ) : (\r\n          <Lockup\r\n            frame={frame}\r\n            since={frame - collapseAt}\r\n            mark={mark}\r\n            word={wordmark}\r\n            ink={ink}\r\n            accent={accent || t.primary}\r\n            tile={t.muted}\r\n            u={u}\r\n          />\r\n        )}\r\n      </div>\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n\r\n/** A box of `w × h` reference pixels centred on `(cx, cy)`, in real pixels. */\r\nfunction box(\r\n  w: number,\r\n  h: number,\r\n  cx: number,\r\n  cy: number,\r\n  u: number,\r\n): CSSProperties {\r\n  return {\r\n    position: \"absolute\",\r\n    left: (cx - w / 2) * u,\r\n    top: (cy - h / 2) * u,\r\n    width: w * u,\r\n    height: h * u,\r\n    objectFit: \"cover\",\r\n  };\r\n}\r\n\r\n/** The tile, the mark landing, stepping aside, and the word arriving. */\r\nfunction Lockup({\r\n  frame,\r\n  since,\r\n  mark,\r\n  word,\r\n  ink,\r\n  accent,\r\n  tile,\r\n  u,\r\n}: {\r\n  /** The scene's own frame, which the beats below are written in. */\r\n  frame: number;\r\n  /** Frames since the stack ran out, which the landing is written in. */\r\n  since: number;\r\n  mark: string;\r\n  word: string;\r\n  ink: string;\r\n  accent: string;\r\n  tile: string;\r\n  u: number;\r\n}) {\r\n  const size = LAND[since] ?? MARK;\r\n  const worded = frame >= WORD_AT;\r\n  const cx = worded ? LOCK_X + MARK / 2 : frame >= STEP_AT ? STEP_X : STAGE_X;\r\n  return (\r\n    <>\r\n      {since < TILE_FRAMES && (\r\n        <div\r\n          style={{\r\n            ...box(TILE, TILE, STAGE_X, STAGE_Y, u),\r\n            background: tile,\r\n          }}\r\n        />\r\n      )}\r\n      <Plate src={mark} style={box(size, size, cx, STAGE_Y, u)} />\r\n      {worded && (\r\n        <div\r\n          style={{\r\n            position: \"absolute\",\r\n            left: WORD_X * u,\r\n            top: WORD_TOP * u,\r\n            fontSize: WORD_CAP * WORD_EM * u,\r\n            lineHeight: 1,\r\n            fontWeight: 700,\r\n            letterSpacing: `${WORD_TRACK}em`,\r\n            color: ink,\r\n            whiteSpace: \"nowrap\",\r\n          }}\r\n        >\r\n          {word}\r\n        </div>\r\n      )}\r\n      {DOTS.map(([dx, dy], i) => {\r\n        const since = frame - (DOT_AT[i] ?? Number.POSITIVE_INFINITY);\r\n        if (since < 0) return null;\r\n        const k = Math.min(1, since / DOT_SETTLE);\r\n        const d = DOT_IN + (DOT_OUT - DOT_IN) * k;\r\n        return (\r\n          <div\r\n            key={`${dx}-${dy}`}\r\n            style={{\r\n              position: \"absolute\",\r\n              left: (dx - d / 2) * u,\r\n              top: (dy - d / 2) * u,\r\n              width: d * u,\r\n              height: d * u,\r\n              background: accent,\r\n              opacity: 1 + (DOT_FADE - 1) * k,\r\n            }}\r\n          />\r\n        );\r\n      })}\r\n    </>\r\n  );\r\n}\r\n\r\n/**\r\n * A root-relative asset is a `public/` file. Only the site's own Player serves\r\n * it at that path; Remotion Studio and a render know its URL through\r\n * `staticFile()` alone — so every environment but the Player rewrites it.\r\n */\r\nfunction resolveSrc(src: string): string {\r\n  const isLocal = src.startsWith(\"/\") && !src.startsWith(\"//\");\r\n  if (!isLocal || getRemotionEnvironment().isPlayer) return src;\r\n  // A value that already came out of staticFile() carries the static base\r\n  // (`/static-<hash>/…`); running it through again would prefix it twice.\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 * An image that holds the render until it has actually loaded.\r\n *\r\n * Without it a frame can be captured before the picture arrives and the card\r\n * comes out empty — invisible in the Player, where an image simply appears, and\r\n * silent in an mp4 until somebody watches it. Remotion's own `Img` is avoided for\r\n * the reason `hero-launch` documents: it awaits `decode()`, which the headless\r\n * compositor rejects for some progressive JPEGs and hangs the export.\r\n *\r\n * Takes a `ref` so Remotion Studio can outline a shot (see `Item`); its `style`\r\n * already arrives with Studio's merged in.\r\n */\r\nconst Plate = forwardRef<\r\n  HTMLImageElement,\r\n  {\r\n    src: string;\r\n    style: CSSProperties;\r\n  }\r\n>(function Plate({ src, style }, ref) {\r\n  const [handle] = useState(() => delayRender(`logo-collapse: ${src}`));\r\n  const release = useCallback(() => continueRender(handle), [handle]);\r\n  return (\r\n    // biome-ignore lint/performance/noImgElement: Remotion frame, not a Next route.\r\n    <img // eslint-disable-line @remotion/warn-native-media-tag -- onLoad releases the frame; <Img> hangs on some JPEGs\r\n      ref={ref}\r\n      src={resolveSrc(src)}\r\n      alt=\"\"\r\n      // Tailwind's preflight sets `img { max-width: 100% }`, which collapses an\r\n      // image inside a shrink-to-fit box to zero pixels wide on the site while\r\n      // rendering perfectly in an mp4. Size it here and say so.\r\n      style={{ ...style, maxWidth: \"none\" }}\r\n      onLoad={release}\r\n      onError={release}\r\n    />\r\n  );\r\n});\r\n"}]}