{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"reel-collage","type":"registry:component","title":"Reel Collage","description":"Photo reel that shuts into a collage. A picture cuts through a quick reel between two captions and slowly zooms, then shuts like an eyelid while the captions fold into one stacked line; the copy swaps, the lines split, and a scattered collage blooms in around them on a peach flush.","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/reel-collage.tsx","type":"registry:component","target":"components/kuchi/reel-collage.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport type { CSSProperties } from \"react\";\r\nimport {\r\n  Easing,\r\n  getRemotionEnvironment,\r\n  Img,\r\n  interpolate,\r\n  OffthreadVideo,\r\n  Sequence,\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 \"reel collage\": a photo cuts through a quick reel between two captions and\r\n * slowly zooms, then shuts like an eyelid — the frame closes to a hairline while\r\n * the captions fold into one stacked line. The copy swaps, the lines split\r\n * apart, and a scattered collage of the same kind of pictures blooms in around\r\n * them on a peach flush.\r\n *\r\n * Replicated from a 2.6s reference recording. Every curve below was fitted on\r\n * the recording's own timestamps, not eyeballed: the geometry is in reference\r\n * pixels (`REF_W` wide) and scales with the frame, the timing is in frames at\r\n * 30fps.\r\n *\r\n * The ground is a painted world rather than a surface — a warm page, a mint\r\n * glow and a peach flush — so like `announce-title` every one of its colours is\r\n * a prop. The type is the theme's `foreground`.\r\n */\r\n\r\nexport interface ReelCollageProps {\r\n  /** Caption above the reel. */\r\n  topLine?: string;\r\n  /** Caption below the reel. */\r\n  bottomLine?: string;\r\n  /** The first line after the swap — drifts up and left into the collage. */\r\n  swapTop?: string;\r\n  /** The second line after the swap — drifts down and right. */\r\n  swapBottom?: string;\r\n  /** The reel, in cut order. Eight shots; the last is the one that shuts. */\r\n  slides?: string[];\r\n  /**\r\n   * The collage, six pictures, in `COLLAGE` slot order: left, centre, top\r\n   * right, bottom left, bottom right, and the centre-right one on top of it.\r\n   * Image or video URLs — a `.mp4`/`.webm`/`.mov` plays, muted.\r\n   */\r\n  collage?: string[];\r\n  /** The page. */\r\n  background?: string;\r\n  /** The soft glow the whole scene sits on. */\r\n  glowColor?: string;\r\n  /** The flush that rises around the edges as the collage blooms in. */\r\n  flushColor?: string;\r\n  /** Caption ink. Defaults to the theme's `foreground`. */\r\n  textColor?: string;\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n  /**\r\n   * The face this scene paints its words in — a label from `fonts.ts`\r\n   * (\"Inter\", \"Space Grotesk\", \"Instrument Serif\") or a CSS family you have\r\n   * loaded yourself. Unset, the scene keeps the face it was designed around.\r\n   *\r\n   * Overrides `theme.fontFamily`, which is how a brand kit re-skins a whole\r\n   * timeline from one value.\r\n   */\r\n  fontFamily?: string;\r\n  speed?: number;\r\n  className?: string;\r\n}\r\n\r\nconst FONT_FAMILY =\r\n  'Inter, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif';\r\n\r\n/** kuchi's own scenes, as stills. Absolute, because a root-relative default\r\n *  becomes `staticFile()` in a render and 404s in the project this file was\r\n *  just copied into. Pass your own — root-relative or remote, both resolve. */\r\nconst POSTER = (slug: string) =>\r\n  `https://kuchi-media.kalarislabs.com/components/art/art-01.svg?${slug}`;\r\nconst DEMO = (slug: string) => `https://kuchi-media.kalarislabs.com/components/clips/clip-${(slug.length % 6) + 1}.mp4`;\r\nconst DEFAULT_SLIDES = [\r\n  \"orbit-gallery\",\r\n  \"card-rail\",\r\n  \"logo-flicker\",\r\n  \"laptop-frame\",\r\n  \"count-grid\",\r\n  \"status-cycle\",\r\n  \"moodboard-reveal\",\r\n  \"announce-title\",\r\n].map(POSTER);\r\nconst DEFAULT_COLLAGE = [\r\n  \"phone-frame\",\r\n  \"terminal-simulator\",\r\n  \"roster-grant\",\r\n  \"channel-thread\",\r\n  \"hero-launch\",\r\n  \"follower-rush\",\r\n].map(DEMO);\r\n\r\n// ─── Geometry, in reference pixels ────────────────────────────────────────────\r\n/** The reference frame's width. Every length below is a fraction of it. */\r\nexport const REF_W = 712;\r\n\r\n/** Caption type: its size at zoom 1, and the tracking the reference sets it at. */\r\nexport const FONT_SIZE = 19.22;\r\nexport const LETTER_SPACING = \"-0.068em\";\r\n\r\n/** The reel's frame at zoom 1. */\r\nexport const BOX_W = 282.08;\r\n\r\n/**\r\n * Caption baselines, relative to the page centre, at zoom 1: open around the\r\n * reel, and folded into one stacked pair once the reel has shut.\r\n */\r\nexport const CAPTION_OPEN = { top: -110.07, bottom: 125.53 } as const;\r\nexport const CAPTION_SHUT = { top: -5.44, bottom: 13.75 } as const;\r\n\r\n/** The swapped pair starts this far left of centre, then drifts apart. */\r\nconst SWAP_DX = -1.9;\r\n/** Where the swapped lines come to rest: ink centre x, baseline y. */\r\nexport const SWAP_REST = {\r\n  top: { x: -71.0, y: -94.6 },\r\n  bottom: { x: 41.0, y: 104.6 },\r\n} as const;\r\n\r\n/**\r\n * The collage: each picture's resting centre, size, and the scale it blooms\r\n * from. The centre picture starts smaller — it opens out of the gap the lines\r\n * leave behind. Listed bottom to top: the right-hand pair overlap, 5 over 4.\r\n */\r\nexport const COLLAGE = [\r\n  { x: -195.5, y: -38.5, w: 105, h: 117, from: 0.616 },\r\n  { x: -66.5, y: -1, w: 141, h: 96, from: 0.425 },\r\n  { x: 106.5, y: -91.5, w: 161, h: 107, from: 0.554 },\r\n  { x: -153, y: 108, w: 150, h: 102, from: 0.644 },\r\n  { x: 200, y: 97.5, w: 142, h: 97, from: 0.61 },\r\n  { x: 81.5, y: 27.5, w: 139, h: 97, from: 0.601 },\r\n] as const;\r\n\r\n/** The glow and the flush: blurred rounded rectangles behind everything. */\r\nconst GLOW = { dx: 10.9, dy: 6.4, hw: 261.6, hh: 147, r: 128.4, blur: 36.2 };\r\nconst FLUSH = { dx: 4.4, dy: -4.2, hw: 301.8, hh: 151.5, r: 2, blur: 58.6 };\r\n\r\n// ─── Timeline (frames @ 30fps) ────────────────────────────────────────────────\r\n/** Frame each reel shot cuts in on. */\r\nexport const CUTS = [0, 3, 6, 10, 14, 19, 25, 29] as const;\r\n/**\r\n * Each shot sits in the frame a little differently — its own aspect, a hair of\r\n * extra width (`k`), and its centre's offset from the page centre. Measured per\r\n * cut; ignoring it puts every cut up to 2px off where the reference lands it.\r\n */\r\nconst SHOTS = [\r\n  { aspect: 1.505, k: 1.0004, dx: 0.47, dy: 0.1 },\r\n  { aspect: 1.4788, k: 0.9982, dx: 0.78, dy: 0.09 },\r\n  { aspect: 1.4832, k: 1.0038, dx: 1.67, dy: 1.16 },\r\n  { aspect: 1.4561, k: 1.0009, dx: 1.59, dy: 0.93 },\r\n  { aspect: 1.4573, k: 0.9999, dx: 1.8, dy: 0.84 },\r\n  { aspect: 1.4505, k: 0.9988, dx: 1.92, dy: 1.3 },\r\n  { aspect: 1.4465, k: 0.9984, dx: 1.8, dy: 1.14 },\r\n  { aspect: 1.4465, k: 1, dx: 1.3, dy: -0.1 },\r\n] as const;\r\n/** The copy swaps on this frame, mid-way through the split. */\r\nexport const SWAP_AT = 46;\r\n\r\nconst CLAMP = { extrapolateLeft: \"clamp\", extrapolateRight: \"clamp\" } as const;\r\n\r\n/**\r\n * A fitted segment: `from → to` across `[start, end]` on a cubic-bezier. The\r\n * curves are sharp in-outs — slow to leave, one or two frames of real travel,\r\n * then a settle — which is what makes the shut read as a snap rather than a\r\n * slide. None of them freezes: the tails still move > 0.5px a frame at 1280.\r\n */\r\nfunction seg(\r\n  frame: number,\r\n  [start, end]: readonly [number, number],\r\n  [from, to]: readonly [number, number],\r\n  bezier: readonly [number, number, number, number],\r\n): number {\r\n  return interpolate(frame, [start, end], [from, to], {\r\n    ...CLAMP,\r\n    easing: Easing.bezier(...bezier),\r\n  });\r\n}\r\n\r\n/** Caption zoom — the type grows 17% across the reel. */\r\nexport const textZoom = (f: number) =>\r\n  seg(f, [7.59, 37], [1, 1.1741], [0.9062, 0.1924, 0.4104, 1.0142]);\r\n/** Reel zoom — the frame runs a little ahead of the type. */\r\nexport const boxZoom = (f: number) =>\r\n  seg(f, [0.42, 54.55], [1, 1.1852], [0.8548, 0.3903, 0.0817, 1.1691]);\r\n/** How open the reel is, 1 → 0. The eyelid. */\r\nexport const reelOpen = (f: number) =>\r\n  seg(f, [18.71, 37.47], [1, 0], [0.8703, 0, 0.078, 1]);\r\n/** How far apart the captions still are, 1 → 0. Lags the eyelid at the tail. */\r\nexport const captionsOpen = (f: number) =>\r\n  seg(f, [18.4, 38], [1, 0], [0.8766, 0, 0.0413, 1]);\r\n/** The swapped lines' split, 0 → 1. The lower line leaves first. */\r\nexport const splitTop = (f: number) =>\r\n  seg(f, [43.69, 69.24], [0, 1], [0.9243, 0.1575, 0.1018, 0.781]);\r\nexport const splitBottom = (f: number) =>\r\n  seg(f, [40.33, 69.32], [0, 1], [0.9897, 0, 0.1683, 0.7764]);\r\n/** The collage drifts left as it blooms: x offset, reference px. */\r\nexport const collagePan = (f: number) =>\r\n  seg(f, [46.66, 75.15], [57, 0], [0.8112, 0.3372, 0.0414, 0.6655]);\r\n/** The collage's bloom, 0 → 1 — each picture from its own `from` scale to 1. */\r\nexport const collageBloom = (f: number) =>\r\n  seg(f, [48.92, 73.18], [0, 1], [0.5174, -0.3347, 0.0854, 1]);\r\n/** Collage fade-in: linear. The bottom-right picture trails the rest. */\r\nexport const collageOpacity = (f: number, slot: number) =>\r\n  slot === 4\r\n    ? interpolate(f, [50.74, 65.08], [0, 1], CLAMP)\r\n    : interpolate(f, [50.14, 62.3], [0, 1], CLAMP);\r\n/** The flush: up with the bloom, gone once it has landed. */\r\nexport const flushOpacity = (f: number) =>\r\n  interpolate(f, [48, 56, 57.5, 73.5], [0, 1, 1, 0], CLAMP);\r\n\r\n/** The reel shot on screen at `frame`. */\r\nexport const slideAt = (frame: number) =>\r\n  CUTS.reduce<number>((k, cut, i) => (frame >= cut ? i : k), 0);\r\n\r\n/** Rewrite root-relative assets through staticFile everywhere but the Player. */\r\n/** True for a video URL — those play instead of painting a still. */\r\nexport const isVideoSrc = (src: string) =>\r\n  /\\.(mp4|webm|mov|m4v)(?:[?#]|$)/i.test(src);\r\n\r\n/** Seconds into a clip to start from: a media fragment, `clip.mp4#t=2.5`. */\r\nexport const clipStart = (src: string) => {\r\n  const m = /#t=([\\d.]+)/.exec(src);\r\n  return m ? Number(m[1]) : 0;\r\n};\r\n\r\n/**\r\n * A picture or a clip, filling its box. A clip is muted and starts playing at\r\n * `from` (composition frames) — the moment its box appears — so the viewer\r\n * sees it from the top, or from `#t=<seconds>` when the URL carries one (to\r\n * show only a clip's last part). Ceiling: a clip that ends while its box is\r\n * still up goes blank; pick clips at least as long as their box is on screen.\r\n */\r\nfunction Media({\r\n  src,\r\n  style,\r\n  from = 0,\r\n}: {\r\n  src: string;\r\n  style: CSSProperties;\r\n  from?: number;\r\n}) {\r\n  const { fps } = useVideoConfig();\r\n  const resolved = resolveSrc(src.replace(/#.*$/, \"\"));\r\n  if (!isVideoSrc(src)) return <Img src={resolved} style={style} />;\r\n  return (\r\n    <Sequence from={Math.floor(from)} layout=\"none\">\r\n      <OffthreadVideo\r\n        src={resolved}\r\n        muted\r\n        trimBefore={Math.round(clipStart(src) * fps)}\r\n        style={style}\r\n      />\r\n    </Sequence>\r\n  );\r\n}\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\nconst cover: CSSProperties = {\r\n  width: \"100%\",\r\n  height: \"100%\",\r\n  // Preflight's `img { max-width: 100% }` collapses a box sized by its parent.\r\n  maxWidth: \"none\",\r\n  objectFit: \"cover\",\r\n  display: \"block\",\r\n};\r\n\r\nexport function ReelCollage({\r\n  topLine = \"The videos\",\r\n  bottomLine = \"That you ship\",\r\n  swapTop = \"Especially on\",\r\n  swapBottom = \"Launch day\",\r\n  slides = DEFAULT_SLIDES,\r\n  collage = DEFAULT_COLLAGE,\r\n  background = \"#f5f4f2\",\r\n  glowColor = \"#dfe7e3\",\r\n  flushColor = \"#fdc7bc\",\r\n  textColor,\r\n  theme,\r\n  mode,\r\n  fontFamily,\r\n  speed = 1,\r\n  className,\r\n}: ReelCollageProps) {\r\n  const { width, height, fps } = useVideoConfig();\r\n  // The timeline is in 30fps frames; scaled so it runs at the same speed in a\r\n  // composition of any frame rate.\r\n  const tick = (speed * 30) / fps;\r\n  const frame = useCurrentFrame() * tick;\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face = resolveFont(fontFamily ?? t.fontFamily) ?? FONT_FAMILY;\r\n  const ink = textColor ?? t.foreground;\r\n  const u = width / REF_W;\r\n  const cx = width / 2;\r\n  const cy = height / 2;\r\n\r\n  // ── Reel ──────────────────────────────────────────────────────────────────\r\n  const slide = slideAt(frame);\r\n  const shot = SHOTS[slide] ?? SHOTS[0];\r\n  const open = reelOpen(frame);\r\n  const boxW = BOX_W * shot.k * boxZoom(frame) * u;\r\n  const fullH = boxW / shot.aspect;\r\n  const boxH = fullH * open;\r\n  const reelSrc = slides[slide % slides.length];\r\n\r\n  // ── Captions ──────────────────────────────────────────────────────────────\r\n  // Both lines scale by the same zoom, pivoted on their own baseline so the\r\n  // baseline never climbs the pixel grid (motion-quality: \"stuck\" text).\r\n  const zoom = textZoom(frame);\r\n  const apart = captionsOpen(frame);\r\n  const baseline = (openY: number, shutY: number) =>\r\n    zoom * (openY * apart + shutY * (1 - apart));\r\n  const swapped = frame >= SWAP_AT;\r\n  const pTop = splitTop(frame);\r\n  const pBottom = splitBottom(frame);\r\n  const lines = [\r\n    {\r\n      text: swapped ? swapTop : topLine,\r\n      x: (swapped ? SWAP_DX * (1 - pTop) : 0) + SWAP_REST.top.x * pTop,\r\n      y:\r\n        baseline(CAPTION_OPEN.top, CAPTION_SHUT.top) +\r\n        (SWAP_REST.top.y - zoom * CAPTION_SHUT.top) * pTop,\r\n    },\r\n    {\r\n      text: swapped ? swapBottom : bottomLine,\r\n      x: (swapped ? SWAP_DX * (1 - pBottom) : 0) + SWAP_REST.bottom.x * pBottom,\r\n      y:\r\n        baseline(CAPTION_OPEN.bottom, CAPTION_SHUT.bottom) +\r\n        (SWAP_REST.bottom.y - zoom * CAPTION_SHUT.bottom) * pBottom,\r\n    },\r\n  ];\r\n\r\n  // ── Collage ───────────────────────────────────────────────────────────────\r\n  const pan = collagePan(frame);\r\n  const bloom = collageBloom(frame);\r\n  const flush = flushOpacity(frame);\r\n  const isRendering = getRemotionEnvironment().isRendering;\r\n\r\n  const blob = (\r\n    g: typeof GLOW,\r\n    color: string,\r\n    opacity: number,\r\n  ): CSSProperties => ({\r\n    position: \"absolute\",\r\n    left: cx + (g.dx - g.hw) * u,\r\n    top: cy + (g.dy - g.hh) * u,\r\n    width: 2 * g.hw * u,\r\n    height: 2 * g.hh * u,\r\n    borderRadius: g.r * u,\r\n    background: color,\r\n    filter: `blur(${g.blur * u}px)`,\r\n    opacity,\r\n  });\r\n\r\n  return (\r\n    <div\r\n      className={className}\r\n      style={{\r\n        position: \"absolute\",\r\n        inset: 0,\r\n        overflow: \"hidden\",\r\n        backgroundColor: background,\r\n        fontFamily: face,\r\n      }}\r\n    >\r\n      {flush > 0 && <div style={blob(FLUSH, flushColor, flush)} />}\r\n      <div style={blob(GLOW, glowColor, 1)} />\r\n\r\n      {/* ── Reel: a centred window that shuts on a full-size picture ── */}\r\n      {boxH > 0.01 && reelSrc && (\r\n        <div\r\n          style={{\r\n            position: \"absolute\",\r\n            left: cx + shot.dx * u - boxW / 2,\r\n            top: cy + shot.dy * u - boxH / 2,\r\n            width: boxW,\r\n            height: boxH,\r\n            overflow: \"hidden\",\r\n          }}\r\n        >\r\n          {/* The picture keeps its open size; only the window closes on it. */}\r\n          <Media\r\n            src={reelSrc}\r\n            style={{\r\n              ...cover,\r\n              position: \"absolute\",\r\n              left: 0,\r\n              top: (boxH - fullH) / 2,\r\n              height: fullH,\r\n            }}\r\n          />\r\n        </div>\r\n      )}\r\n\r\n      {/* ── Collage ── */}\r\n      {COLLAGE.map((p, slot) => {\r\n        const opacity = collageOpacity(frame, slot);\r\n        const src = collage[slot % collage.length];\r\n        if (opacity <= 0 || !src) return null;\r\n        const scale = p.from + (1 - p.from) * bloom;\r\n        return (\r\n          <div\r\n            key={`${p.x}-${p.y}`}\r\n            style={{\r\n              position: \"absolute\",\r\n              left: cx + (p.x + pan - p.w / 2) * u,\r\n              top: cy + (p.y - p.h / 2) * u,\r\n              width: p.w * u,\r\n              height: p.h * u,\r\n              opacity,\r\n              transform: `scale(${scale})`,\r\n              ...(isRendering ? {} : { willChange: \"transform\" as const }),\r\n            }}\r\n          >\r\n            <Media\r\n              src={src}\r\n              style={cover}\r\n              from={(slot === 4 ? 50.74 : 50.14) / tick}\r\n            />\r\n          </div>\r\n        );\r\n      })}\r\n\r\n      {/* ── Captions: SVG text, so `y` IS the baseline ── */}\r\n      <svg\r\n        width={width}\r\n        height={height}\r\n        style={{ position: \"absolute\", inset: 0, overflow: \"visible\" }}\r\n        aria-hidden\r\n      >\r\n        {lines.map((l, i) => (\r\n          <g\r\n            // biome-ignore lint/suspicious/noArrayIndexKey: two fixed lines\r\n            key={i}\r\n            transform={`translate(${cx + l.x * u} ${cy + l.y * u}) scale(${zoom})`}\r\n          >\r\n            <text\r\n              x={0}\r\n              y={0}\r\n              textAnchor=\"middle\"\r\n              fill={ink}\r\n              style={{\r\n                fontSize: FONT_SIZE * u,\r\n                fontWeight: 500,\r\n                letterSpacing: LETTER_SPACING,\r\n                // Hinting re-snaps the stems at every size; the outline doesn't.\r\n                textRendering: \"geometricPrecision\",\r\n              }}\r\n            >\r\n              {l.text}\r\n            </text>\r\n          </g>\r\n        ))}\r\n      </svg>\r\n    </div>\r\n  );\r\n}\r\n"}]}