{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"orbit-gallery","type":"registry:component","title":"Orbit Gallery","description":"Image gallery intro: photos spiral into the centre around a title. An image-universe hero: a continuous stream of photos flows along an Archimedean spiral (a vortex) from the frame edges into the center — evenly spaced by arc length, shrinking and rotating to follow the coil, with the title held in the clear middle.","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/orbit-gallery.tsx","type":"registry:component","target":"components/kuchi/orbit-gallery.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport { useMemo, useState } from \"react\";\r\nimport {\r\n  AbsoluteFill,\r\n  Easing,\r\n  getRemotionEnvironment,\r\n  Img,\r\n  interpolate,\r\n  staticFile,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\nimport {\r\n  Item,\r\n  mixOklch,\r\n  parseColor,\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n  withAlpha,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\nconst TWO_PI = Math.PI * 2;\r\n/** Lookup resolution for the arc-length reparameterization table. */\r\nconst ARC_SAMPLES = 1024;\r\n\r\nexport interface OrbitGalleryProps {\r\n  title?: string;\r\n  subtitle?: string;\r\n  /** Pill CTA under the subtitle. Empty string hides it. */\r\n  buttonLabel?: string;\r\n  /**\r\n   * Card artwork URLs, cycled along the spiral stream. A URL that fails to load\r\n   * falls back to a gradient tile rather than breaking playback. Pass `[]` to\r\n   * render self-contained editorial gradient tiles (no network).\r\n   */\r\n  images?: string[];\r\n  /** How many times the Archimedean spiral winds from the edge to the center. */\r\n  turns?: number;\r\n  /** Arc spacing between cards along the stream (smaller = denser). */\r\n  spacing?: number;\r\n  /** Radius scale — larger pushes the outer coils off-frame, same coil gaps. */\r\n  spread?: number;\r\n  /** How much cards shrink toward the center (0 = uniform). */\r\n  sizeAttenuation?: number;\r\n  /** Card long-edge in px at the outer radius, on the reference 600px canvas. */\r\n  imageSize?: number;\r\n  /** Card width / height (portrait < 1). */\r\n  cardAspect?: number;\r\n  /** Percent of the path over which a card fades in at the outer end. */\r\n  fadeIn?: number;\r\n  /** Percent of the path over which a card fades out at the center end. */\r\n  fadeOut?: number;\r\n  /** Corner rounding, matching the reference's 0–20 scale (0 = sharp). */\r\n  cornerRadius?: number;\r\n  /** Seconds for the stream to flow one full turnover into the center. */\r\n  orbitSeconds?: number;\r\n  /** Overrides the design system's `background`. */\r\n  background?: string;\r\n  /** Overrides the design system's `foreground`. */\r\n  textColor?: string;\r\n  /** Design-system token overrides. */\r\n  theme?: Partial<KuchiTheme>;\r\n  /** Defaults to `\"dark\"` — the orbit is a cinematic stage, lit for dark. */\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  /** Tiny captions pinned to the bottom edge. Empty strings hide them. */\r\n  footerLeft?: string;\r\n  footerCenter?: string;\r\n  footerRight?: string;\r\n  speed?: number;\r\n  className?: string;\r\n}\r\n\r\nexport const SAMPLE_IMAGES = Array.from(\r\n  { length: 16 },\r\n  (_, i) => `https://picsum.photos/seed/snap-orbit-${i + 1}/440/560`,\r\n);\r\n\r\n/** Editorial two-stop gradients used for tiles without a (working) photo. */\r\nexport const PLACEHOLDER_FILLS = [\r\n  \"linear-gradient(135deg, #2b5fd9, #14306e)\",\r\n  \"linear-gradient(135deg, #c96f2f, #7a3c12)\",\r\n  \"linear-gradient(135deg, #e8e4da, #b6ad99)\",\r\n  \"linear-gradient(135deg, #c8332b, #6e1511)\",\r\n  \"linear-gradient(135deg, #b9a0d0, #6f5590)\",\r\n  \"linear-gradient(135deg, #4c6b3c, #24361a)\",\r\n  \"linear-gradient(135deg, #1f4dd8, #0d2262)\",\r\n  \"linear-gradient(135deg, #d9d2c5, #a09684)\",\r\n];\r\n\r\nconst FONT_STACK = \"Inter, -apple-system, BlinkMacSystemFont, sans-serif\";\r\n\r\n/**\r\n * Archimedean spiral point at parameter `n` in [0, 1]: n=0 is the outer edge\r\n * (radius R), n=1 is the center (radius 0). Because the radius falls off\r\n * LINEARLY, every coil is separated by the same radial gap (R / turns) — the\r\n * even \"circle to circle\" spacing. `y` is flipped so the spiral reads clockwise\r\n * from the top like the reference.\r\n */\r\nexport function archimedeanPoint(\r\n  n: number,\r\n  R: number,\r\n  turns: number,\r\n): { x: number; y: number } {\r\n  const ang = n * turns * TWO_PI;\r\n  const rad = R * (1 - n);\r\n  return { x: rad * Math.cos(ang), y: -rad * Math.sin(ang) };\r\n}\r\n\r\n/**\r\n * Build the arc-length reparameterization table for a spiral of `turns` turns.\r\n * Sampling the path by even parameter would bunch cards near the center (where\r\n * the coils are short); sampling by even ARC length spaces them evenly. The\r\n * spiral's shape is radius-independent, so the table is built once at R=1 and\r\n * returns, for each even arc fraction, the spiral parameter `n` that lands\r\n * there.\r\n */\r\nexport function buildArcTable(turns: number, samples = 2000): Float64Array {\r\n  const cum = new Float64Array(samples + 1);\r\n  let prev = archimedeanPoint(0, 1, turns);\r\n  for (let k = 1; k <= samples; k++) {\r\n    const pt = archimedeanPoint(k / samples, 1, turns);\r\n    cum[k] = cum[k - 1] + Math.hypot(pt.x - prev.x, pt.y - prev.y);\r\n    prev = pt;\r\n  }\r\n  const total = cum[samples] || 1;\r\n\r\n  const nForArc = new Float64Array(ARC_SAMPLES + 1);\r\n  let j = 0;\r\n  for (let a = 0; a <= ARC_SAMPLES; a++) {\r\n    const target = (a / ARC_SAMPLES) * total;\r\n    while (j < samples && cum[j + 1] < target) j++;\r\n    const seg = cum[j + 1] - cum[j];\r\n    const f2 = seg > 0 ? (target - cum[j]) / seg : 0;\r\n    nForArc[a] = (j + f2) / samples;\r\n  }\r\n  return nForArc;\r\n}\r\n\r\n/** Map an arc fraction `s` in [0, 1) to the spiral parameter `n` (interpolated\r\n * so motion stays smooth, never quantized into visible steps). */\r\nexport function arcToN(s: number, nForArc: Float64Array): number {\r\n  const x = Math.max(0, Math.min(ARC_SAMPLES, s * ARC_SAMPLES));\r\n  const i = Math.floor(x);\r\n  const a = nForArc[i];\r\n  const b = nForArc[Math.min(i + 1, ARC_SAMPLES)];\r\n  return a + (b - a) * (x - i);\r\n}\r\n\r\n/** Radius scale for the spiral: R = 0.48·min · (1 + (spread − 1)·0.18). */\r\nexport function ringRadius(minDim: number, spread: number): number {\r\n  return 0.48 * minDim * (1 + (spread - 1) * 0.18);\r\n}\r\n\r\n/** Card size multiplier from its distance to the center — smaller toward the\r\n * middle. `dist/R` clamped to 1, raised to `sizeAttenuation/2`. */\r\nexport function sizeScale(\r\n  dist: number,\r\n  R: number,\r\n  sizeAttenuation: number,\r\n): number {\r\n  return sizeAttenuation > 0\r\n    ? Math.min(dist / R, 1) ** (sizeAttenuation * 0.5)\r\n    : 1;\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 * One card face: the editorial gradient is always painted as the base layer,\r\n * and a photo (when provided) overlays it. A failed load flips to `errored` so\r\n * the gradient shows through — crucially, the `onError` handler also stops\r\n * Remotion's <Img> from calling cancelRender(), which would otherwise halt the\r\n * whole player when an external image is blocked or slow to fail. */\r\nfunction OrbitTile({ src, fill }: { src: string | undefined; fill: string }) {\r\n  const [errored, setErrored] = useState(false);\r\n  return (\r\n    <>\r\n      <div style={{ position: \"absolute\", inset: 0, backgroundImage: fill }} />\r\n      {src && !errored ? (\r\n        // No crossOrigin: nothing reads these pixels back, and asking for CORS\r\n        // fails every photo from a host that does not send it (most do not),\r\n        // leaving only the gradient.\r\n        <Img\r\n          src={resolveSrc(src)}\r\n          onError={() => setErrored(true)}\r\n          style={{\r\n            position: \"absolute\",\r\n            inset: 0,\r\n            width: \"100%\",\r\n            height: \"100%\",\r\n            objectFit: \"cover\",\r\n          }}\r\n        />\r\n      ) : null}\r\n    </>\r\n  );\r\n}\r\n\r\nexport function OrbitGallery({\r\n  title = \"A whole new universe\",\r\n  subtitle = \"Article — The Design Process\",\r\n  buttonLabel = \"Explore\",\r\n  images,\r\n  turns = 3,\r\n  spacing = 5,\r\n  spread = 7,\r\n  sizeAttenuation = 2,\r\n  imageSize = 172,\r\n  cardAspect = 0.78,\r\n  fadeIn = 20,\r\n  fadeOut = 0,\r\n  cornerRadius = 5,\r\n  orbitSeconds = 40,\r\n  background,\r\n  textColor,\r\n  theme,\r\n  mode,\r\n  fontFamily,\r\n  footerLeft = \"\",\r\n  footerCenter = \"\",\r\n  footerRight = \"\",\r\n  speed = 1,\r\n  className,\r\n}: OrbitGalleryProps) {\r\n  const frame = useCurrentFrame();\r\n  const { width, height, fps, durationInFrames } = useVideoConfig();\r\n  const tokens = useKuchiTheme(theme, mode ?? \"dark\");\r\n  const face = resolveFont(fontFamily ?? tokens.fontFamily) ?? FONT_STACK;\r\n  const stage = background ?? tokens.background;\r\n  const ink = textColor ?? tokens.foreground;\r\n  const t = frame * speed;\r\n\r\n  const minDim = Math.min(width, height);\r\n  const R = ringRadius(minDim, spread);\r\n  const baseSize = imageSize * (minDim / 600);\r\n  const artwork = images ?? SAMPLE_IMAGES;\r\n  const nImgs = artwork.length || 1;\r\n\r\n  // Arc-length table (shape-only, so it depends on `turns` alone).\r\n  const nForArc = useMemo(() => buildArcTable(turns), [turns]);\r\n\r\n  const stepFrac = Math.max(0.005, (spacing * 0.5) / 100);\r\n  const slots = Math.min(400, Math.ceil(1 / stepFrac) + 2);\r\n\r\n  // Seamless inward flow: advance the stream by a whole number of card-steps\r\n  // over the composition so the loop has no visible jump.\r\n  const stepsPerLoop = Math.max(\r\n    1,\r\n    Math.round(durationInFrames / fps / orbitSeconds / stepFrac),\r\n  );\r\n  const base =\r\n    ((((t / durationInFrames) * stepsPerLoop * stepFrac) % 1) + 1) % 1;\r\n\r\n  const cards = [];\r\n  for (let i = 0; i < slots; i++) {\r\n    const s = (((base + i * stepFrac) % 1) + 1) % 1;\r\n    const n = arcToN(s, nForArc);\r\n    cards.push({ key: i, tt: s * 100, n, imgIdx: i % nImgs });\r\n  }\r\n  // Draw outer coils first, center cards last (on top), like the reference.\r\n  cards.sort((a, b) => a.n - b.n);\r\n\r\n  // The stream cycles `images`, so one photo rides the spiral more than once.\r\n  // Studio outlines the largest drawn copy inside the frame (else the largest\r\n  // at all); the others are only pictures of it.\r\n  const best = new Map<\r\n    number,\r\n    { key: number; inFrame: boolean; size: number }\r\n  >();\r\n  for (const card of cards) {\r\n    // Only the copies the loop below draws: same fade, same cut-offs.\r\n    let opacity = 1;\r\n    if (card.tt < fadeIn) opacity = card.tt / fadeIn;\r\n    else if (fadeOut > 0 && card.tt > 100 - fadeOut)\r\n      opacity = (100 - card.tt) / fadeOut;\r\n    if (opacity < 0.01) continue;\r\n    const p = archimedeanPoint(card.n, R, turns);\r\n    const size = sizeScale(Math.hypot(p.x, p.y), R, sizeAttenuation);\r\n    if (size < 0.002) continue;\r\n    const inFrame = Math.abs(p.x) < width / 2 && Math.abs(p.y) < height / 2;\r\n    const held = best.get(card.imgIdx);\r\n    if (\r\n      !held ||\r\n      (inFrame && !held.inFrame) ||\r\n      (inFrame === held.inFrame && size > held.size)\r\n    )\r\n      best.set(card.imgIdx, { key: card.key, inFrame, size });\r\n  }\r\n\r\n  const intro = interpolate(t, [0, 16], [0, 1], {\r\n    extrapolateLeft: \"clamp\",\r\n    extrapolateRight: \"clamp\",\r\n  });\r\n\r\n  const titleSize = Math.min(width * 0.066, height * 0.11);\r\n\r\n  return (\r\n    <AbsoluteFill\r\n      className={className}\r\n      style={{ backgroundColor: stage, fontFamily: face }}\r\n    >\r\n      {cards.map((card) => {\r\n        const p = archimedeanPoint(card.n, R, turns);\r\n        const dist = Math.hypot(p.x, p.y);\r\n\r\n        let opacity = 1;\r\n        if (card.tt < fadeIn) opacity = card.tt / fadeIn;\r\n        else if (fadeOut > 0 && card.tt > 100 - fadeOut)\r\n          opacity = (100 - card.tt) / fadeOut;\r\n        if (opacity < 0.01) return null;\r\n\r\n        const scale = sizeScale(dist, R, sizeAttenuation);\r\n        if (scale < 0.002) return null;\r\n\r\n        // Tangent of the spiral at this point → the card's rotation.\r\n        const p2 = archimedeanPoint(Math.min(card.n + 0.001, 1), R, turns);\r\n        const angleDeg = (Math.atan2(p2.y - p.y, p2.x - p.x) * 180) / Math.PI;\r\n\r\n        // Long edge = baseSize·scale; the short edge follows cardAspect.\r\n        const ch = baseSize * scale;\r\n        const cw = ch * cardAspect;\r\n        const rad = (cornerRadius / 20) * (Math.min(cw, ch) / 2);\r\n\r\n        // Only the few tiny cards passing right behind the title get a light\r\n        // blur (a cheap per-element filter on a handful of small cards — nothing\r\n        // like the frame-wide backdrop blur that stalled the player). Everything\r\n        // in the visible outer band stays sharp.\r\n        const centerBlurR = minDim * 0.16;\r\n        const blurPx = dist < centerBlurR ? (1 - dist / centerBlurR) * 4 : 0;\r\n\r\n        return (\r\n          <Item\r\n            key={card.key}\r\n            index={card.imgIdx}\r\n            // Gradient tiles alone (`images={[]}`) are no photo to select.\r\n            primary={\r\n              artwork.length > 0 && best.get(card.imgIdx)?.key === card.key\r\n            }\r\n          >\r\n            <div\r\n              style={{\r\n                position: \"absolute\",\r\n                left: \"50%\",\r\n                top: \"50%\",\r\n                width: cw,\r\n                height: ch,\r\n                marginLeft: -cw / 2,\r\n                marginTop: -ch / 2,\r\n                zIndex: Math.round(card.n * 8),\r\n                translate: `${p.x.toFixed(2)}px ${p.y.toFixed(2)}px`,\r\n                rotate: `${angleDeg.toFixed(2)}deg`,\r\n                opacity: opacity * intro,\r\n                filter:\r\n                  blurPx > 0.15 ? `blur(${blurPx.toFixed(2)}px)` : undefined,\r\n                borderRadius: rad,\r\n                overflow: \"hidden\",\r\n                backgroundColor: mixOklch(stage, tokens.card, 0.35),\r\n                boxShadow: `0 ${(ch * 0.12).toFixed(1)}px ${(ch * 0.3).toFixed(1)}px ${withAlpha(\r\n                  mixOklch(stage, \"#000\", 0.75),\r\n                  0.4,\r\n                )}`,\r\n              }}\r\n            >\r\n              <OrbitTile\r\n                src={artwork.length ? artwork[card.imgIdx % nImgs] : undefined}\r\n                fill={PLACEHOLDER_FILLS[card.imgIdx % PLACEHOLDER_FILLS.length]}\r\n              />\r\n            </div>\r\n          </Item>\r\n        );\r\n      })}\r\n\r\n      {/* Soft focus pool behind the lockup: a radial dark scrim so the title\r\n          reads. This is a plain gradient (no backdrop-filter) — the earlier\r\n          backdrop blur re-blurred every moving card each frame and froze the\r\n          player. The slight softness behind the text comes from the small\r\n          center cards' own light blur (see `centerBlur` in the card loop). */}\r\n      {/* The scrim deepens the page behind the lockup; with no page there is\r\n          nothing to deepen, and on a transparent one it would be black. */}\r\n      {(title || subtitle || buttonLabel) && parseColor(stage).alpha !== 0 ? (\r\n        <div\r\n          style={{\r\n            position: \"absolute\",\r\n            left: \"50%\",\r\n            top: \"50%\",\r\n            width: width * 0.66,\r\n            height: height * 0.5,\r\n            marginLeft: -(width * 0.66) / 2,\r\n            marginTop: -(height * 0.5) / 2,\r\n            borderRadius: \"50%\",\r\n            backgroundImage: `radial-gradient(ellipse at center, ${withAlpha(\r\n              stage,\r\n              0.62,\r\n            )} 0%, ${withAlpha(stage, 0.34)} 42%, transparent 70%)`,\r\n            opacity: intro,\r\n            zIndex: 9,\r\n          }}\r\n        />\r\n      ) : null}\r\n\r\n      <AbsoluteFill\r\n        style={{\r\n          alignItems: \"center\",\r\n          justifyContent: \"center\",\r\n          textAlign: \"center\",\r\n          zIndex: 10,\r\n        }}\r\n      >\r\n        {title ? (\r\n          <div\r\n            style={{\r\n              fontSize: titleSize,\r\n              fontWeight: 500,\r\n              letterSpacing: \"-0.015em\",\r\n              lineHeight: 1.08,\r\n              color: ink,\r\n              maxWidth: \"82%\",\r\n              opacity: interpolate(t, [8, 34], [0, 1], {\r\n                extrapolateLeft: \"clamp\",\r\n                extrapolateRight: \"clamp\",\r\n              }),\r\n              translate: `0px ${interpolate(t, [8, 34], [titleSize * 0.4, 0], {\r\n                extrapolateLeft: \"clamp\",\r\n                extrapolateRight: \"clamp\",\r\n                easing: Easing.out(Easing.cubic),\r\n              })}px`,\r\n              filter: `blur(${interpolate(t, [8, 30], [8, 0], {\r\n                extrapolateLeft: \"clamp\",\r\n                extrapolateRight: \"clamp\",\r\n              })}px)`,\r\n            }}\r\n          >\r\n            {title}\r\n          </div>\r\n        ) : null}\r\n\r\n        {subtitle ? (\r\n          <div\r\n            style={{\r\n              marginTop: titleSize * 0.42,\r\n              fontSize: titleSize * 0.26,\r\n              letterSpacing: \"0.02em\",\r\n              color: ink,\r\n              opacity:\r\n                0.65 *\r\n                interpolate(t, [16, 40], [0, 1], {\r\n                  extrapolateLeft: \"clamp\",\r\n                  extrapolateRight: \"clamp\",\r\n                }),\r\n              translate: `0px ${interpolate(\r\n                t,\r\n                [16, 40],\r\n                [titleSize * 0.25, 0],\r\n                {\r\n                  extrapolateLeft: \"clamp\",\r\n                  extrapolateRight: \"clamp\",\r\n                  easing: Easing.out(Easing.cubic),\r\n                },\r\n              )}px`,\r\n            }}\r\n          >\r\n            {subtitle}\r\n          </div>\r\n        ) : null}\r\n\r\n        {buttonLabel ? (\r\n          <div\r\n            style={{\r\n              marginTop: titleSize * 0.5,\r\n              padding: `${titleSize * 0.14}px ${titleSize * 0.34}px`,\r\n              borderRadius: 9999,\r\n              backgroundColor: withAlpha(ink, 0.14),\r\n              fontSize: titleSize * 0.23,\r\n              fontWeight: 500,\r\n              color: ink,\r\n              opacity: interpolate(t, [24, 44], [0, 1], {\r\n                extrapolateLeft: \"clamp\",\r\n                extrapolateRight: \"clamp\",\r\n              }),\r\n              scale: String(\r\n                interpolate(t, [24, 48], [0.7, 1], {\r\n                  extrapolateLeft: \"clamp\",\r\n                  extrapolateRight: \"clamp\",\r\n                  easing: Easing.out(Easing.back(1.4)),\r\n                }),\r\n              ),\r\n            }}\r\n          >\r\n            {buttonLabel}\r\n          </div>\r\n        ) : null}\r\n      </AbsoluteFill>\r\n\r\n      {footerLeft || footerCenter || footerRight ? (\r\n        <div\r\n          style={{\r\n            position: \"absolute\",\r\n            left: width * 0.05,\r\n            right: width * 0.05,\r\n            bottom: height * 0.032,\r\n            display: \"flex\",\r\n            justifyContent: \"space-between\",\r\n            fontSize: titleSize * 0.22,\r\n            color: ink,\r\n            opacity:\r\n              0.78 *\r\n              interpolate(t, [30, 50], [0, 1], {\r\n                extrapolateLeft: \"clamp\",\r\n                extrapolateRight: \"clamp\",\r\n              }),\r\n            zIndex: 10,\r\n          }}\r\n        >\r\n          <span>{footerLeft}</span>\r\n          <span>{footerCenter}</span>\r\n          <span>{footerRight}</span>\r\n        </div>\r\n      ) : null}\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n"}]}