{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"phone-stack","type":"registry:component","title":"Phone Stack","description":"Stacked phone screens with video. Phone screens rise out of a blur from below one after another, and each new one pushes the stack back: the older screens shrink and step up so only their tops peek out above the newest.","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>.","files":[{"path":"components/kuchi/phone-stack.tsx","type":"registry:component","target":"components/kuchi/phone-stack.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  interpolate,\r\n  OffthreadVideo,\r\n  Sequence,\r\n  staticFile,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\n\r\n/**\r\n * A \"phone stack\": phone screens rise out of a blur from below, one after\r\n * another, and each new one pushes the stack back — the older screens shrink\r\n * and step up so only their tops peek out above the newest, which settles in\r\n * front. Every screen plays its own clip under an iOS status bar.\r\n *\r\n * Proportions were measured off a two-screen reference recording (716 × 398,\r\n * 30fps) by tracking each screen's Dynamic Island: a screen one step back is\r\n * 0.83× the size and its top sits 24.6 reference px higher. The rise is the\r\n * reference's long ease-out. Lengths are reference pixels (`REF_W` wide) and\r\n * scale with the frame.\r\n *\r\n * Like `announce-title` it paints a world rather than a surface — a cream page\r\n * with a lavender glow — so it takes no `theme`/`mode`; its colours are props.\r\n */\r\n\r\nexport interface PhoneStackProps {\r\n  /**\r\n   * One clip per screen, in the order they arrive. Video URLs play muted;\r\n   * images show as stills. Absolute URLs or paths under `public/`.\r\n   */\r\n  videos?: string[];\r\n  /** Frames between one screen arriving and the next. */\r\n  stagger?: number;\r\n  /** The page. */\r\n  background?: string;\r\n  /** The glow the stack rises out of. */\r\n  glowColor?: string;\r\n  /** The status bar's ink over the clips. */\r\n  statusColor?: string;\r\n  /** The time in the status bar. */\r\n  time?: string;\r\n  speed?: number;\r\n  className?: string;\r\n}\r\n\r\n/** Creator-style clips, 12s each. 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. */\r\nconst DEFAULT_VIDEOS = [2, 3, 4, 5, 6].map(\r\n  (n) => `https://kuchi-media.kalarislabs.com/components/clips/clip-${n}.mp4`,\r\n);\r\n\r\n// ─── Geometry, in reference pixels ────────────────────────────────────────────\r\nexport const REF_W = 716;\r\nconst REF_H = 398;\r\n/** The front screen at rest: width, top edge, centre line. */\r\nexport const SCREEN = { w: 240, top: 74, cx: 358, radius: 26 } as const;\r\n/** Each step back: the size it keeps, and how far its top climbs (at scale 1). */\r\nexport const STEP_SCALE = 0.83;\r\nexport const STEP_RISE = 24.6;\r\n/** Screens deeper than this fade out as the next one arrives. */\r\nconst DEPTH = 3;\r\n/** An arriving screen starts below the frame, larger, blurred and clear. */\r\nconst ENTER = { top: 400, scale: 1.12, blur: 9 } as const;\r\n\r\n// ─── Timeline (30fps frames) ──────────────────────────────────────────────────\r\n/** One arrival or one step back. */\r\nexport const MOVE = 26;\r\nconst RISE = Easing.bezier(0.16, 1, 0.3, 1);\r\n\r\n/** Where a screen sits `depth` steps back: scale and top edge. */\r\nfunction slot(depth: number) {\r\n  const scale = STEP_SCALE ** depth;\r\n  let top = SCREEN.top;\r\n  for (let d = 1; d <= depth; d++) top -= STEP_RISE * STEP_SCALE ** (d - 1);\r\n  return { scale, top };\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  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 isVideoSrc = (src: string) => /\\.(mp4|webm|mov|m4v)(?:[?#]|$)/i.test(src);\r\n\r\nconst cover: CSSProperties = {\r\n  position: \"absolute\",\r\n  inset: 0,\r\n  width: \"100%\",\r\n  height: \"100%\",\r\n  maxWidth: \"none\",\r\n  objectFit: \"cover\",\r\n};\r\n\r\n/** Signal, Wi-Fi and battery, drawn in `currentColor`. */\r\nfunction StatusIcons({ h }: { h: number }) {\r\n  return (\r\n    <svg\r\n      height={h}\r\n      viewBox=\"0 0 68 12\"\r\n      fill=\"currentColor\"\r\n      aria-hidden\r\n      style={{ display: \"block\" }}\r\n    >\r\n      <rect x=\"0\" y=\"8\" width=\"3\" height=\"4\" rx=\"1\" />\r\n      <rect x=\"5\" y=\"6\" width=\"3\" height=\"6\" rx=\"1\" />\r\n      <rect x=\"10\" y=\"3.5\" width=\"3\" height=\"8.5\" rx=\"1\" />\r\n      <rect x=\"15\" y=\"1\" width=\"3\" height=\"11\" rx=\"1\" />\r\n      <path d=\"M31 2.2c2.6 0 5 1 6.8 2.7l-1.3 1.4A7.9 7.9 0 0 0 31 4.1a7.9 7.9 0 0 0-5.5 2.2l-1.3-1.4A9.8 9.8 0 0 1 31 2.2Zm0 3.8c1.6 0 3 .6 4.1 1.6L33.8 9a3.9 3.9 0 0 0-5.6 0l-1.3-1.4A5.8 5.8 0 0 1 31 6Zm0 3.7 1.6 1.7L31 12l-1.6-1.6L31 9.7Z\" />\r\n      <rect\r\n        x=\"43.5\"\r\n        y=\"1.5\"\r\n        width=\"21\"\r\n        height=\"9\"\r\n        rx=\"2.6\"\r\n        fill=\"none\"\r\n        stroke=\"currentColor\"\r\n        opacity=\"0.45\"\r\n      />\r\n      <rect x=\"45.5\" y=\"3.5\" width=\"17\" height=\"5\" rx=\"1.3\" />\r\n      <rect x=\"65.5\" y=\"4.3\" width=\"1.6\" height=\"3.4\" rx=\"0.8\" opacity=\"0.45\" />\r\n    </svg>\r\n  );\r\n}\r\n\r\nexport function PhoneStack({\r\n  videos = DEFAULT_VIDEOS,\r\n  stagger = 14,\r\n  background = \"#f3f3ee\",\r\n  glowColor = \"#cdb4e6\",\r\n  statusColor = \"#ffffff\",\r\n  time = \"9:41\",\r\n  speed = 1,\r\n  className,\r\n}: PhoneStackProps) {\r\n  const { width, height, fps } = useVideoConfig();\r\n  const tick = (speed * 30) / fps;\r\n  const frame = useCurrentFrame() * tick;\r\n  const u = width / REF_W;\r\n  const dy = (height - REF_H * u) / 2;\r\n  const n = videos.length;\r\n\r\n  // How far a screen has come: 0 below the frame, 1 in front, 2 one step\r\n  // back, … — every arrival after it adds one, on the same eased curve.\r\n  const progress = (i: number) => {\r\n    let p = 0;\r\n    for (let k = i; k < n; k++) {\r\n      p += interpolate(frame, [k * stagger, k * stagger + MOVE], [0, 1], {\r\n        extrapolateLeft: \"clamp\",\r\n        extrapolateRight: \"clamp\",\r\n        easing: RISE,\r\n      });\r\n    }\r\n    return p;\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      }}\r\n    >\r\n      {/* The glow the stack rises out of. */}\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: \"50%\",\r\n          bottom: -0.55 * height,\r\n          width: 1.5 * width,\r\n          height: 1.1 * height,\r\n          transform: \"translateX(-50%)\",\r\n          borderRadius: \"50%\",\r\n          background: glowColor,\r\n          opacity: 0.55,\r\n          filter: `blur(${70 * u}px)`,\r\n        }}\r\n      />\r\n\r\n      {videos.map((src, i) => {\r\n        const p = progress(i);\r\n        if (p <= 0) return null;\r\n        // 0 → 1: the rise. Past 1: steps back, one per later arrival.\r\n        const enter = Math.min(p, 1);\r\n        const depth = Math.max(p - 1, 0);\r\n        const lo = slot(Math.floor(depth));\r\n        const hi = slot(Math.floor(depth) + 1);\r\n        const f = depth - Math.floor(depth);\r\n        const scale =\r\n          enter < 1\r\n            ? ENTER.scale + (1 - ENTER.scale) * enter\r\n            : lo.scale + (hi.scale - lo.scale) * f;\r\n        const top =\r\n          enter < 1\r\n            ? ENTER.top + (SCREEN.top - ENTER.top) * enter\r\n            : lo.top + (hi.top - lo.top) * f;\r\n        const blur = ENTER.blur * (1 - enter);\r\n        const opacity =\r\n          Math.min(1, enter * 2.5) *\r\n          interpolate(depth, [DEPTH - 1, DEPTH], [1, 0], {\r\n            extrapolateLeft: \"clamp\",\r\n            extrapolateRight: \"clamp\",\r\n          });\r\n        if (opacity <= 0) return null;\r\n\r\n        const w = SCREEN.w * scale * u;\r\n        const h = w * (852 / 393);\r\n        const island = { w: 0.32 * w, h: 0.094 * w, top: 0.028 * w };\r\n        const resolved = resolveSrc(src);\r\n        return (\r\n          <div\r\n            key={`${i}-${src}`}\r\n            style={{\r\n              position: \"absolute\",\r\n              left: SCREEN.cx * u - w / 2,\r\n              top: dy + top * u,\r\n              width: w,\r\n              height: h,\r\n              borderRadius: SCREEN.radius * scale * u,\r\n              overflow: \"hidden\",\r\n              backgroundColor: \"#ffffff\",\r\n              boxShadow: `0 ${8 * u}px ${28 * u}px rgba(70, 50, 110, 0.14), 0 0 0 ${0.6 * u}px rgba(255, 255, 255, 0.9)`,\r\n              opacity,\r\n              filter: blur > 0.05 ? `blur(${blur * u}px)` : undefined,\r\n              zIndex: i,\r\n            }}\r\n          >\r\n            {isVideoSrc(src) ? (\r\n              <Sequence from={Math.floor((i * stagger) / tick)} layout=\"none\">\r\n                <OffthreadVideo src={resolved} muted style={cover} />\r\n              </Sequence>\r\n            ) : (\r\n              // biome-ignore lint/performance/noImgElement: Remotion still\r\n              <img src={resolved} alt=\"\" style={cover} />\r\n            )}\r\n            {/* Status bar and Dynamic Island over the clip. */}\r\n            <div\r\n              style={{\r\n                position: \"absolute\",\r\n                left: 0,\r\n                right: 0,\r\n                top: 0,\r\n                height: island.top * 2 + island.h,\r\n                background:\r\n                  \"linear-gradient(to bottom, rgba(0,0,0,0.28), rgba(0,0,0,0))\",\r\n              }}\r\n            />\r\n            <div\r\n              style={{\r\n                position: \"absolute\",\r\n                left: \"50%\",\r\n                top: island.top,\r\n                width: island.w,\r\n                height: island.h,\r\n                transform: \"translateX(-50%)\",\r\n                borderRadius: island.h / 2,\r\n                background: \"#000000\",\r\n              }}\r\n            />\r\n            <div\r\n              style={{\r\n                position: \"absolute\",\r\n                left: 0.09 * w,\r\n                top: island.top,\r\n                height: island.h,\r\n                display: \"flex\",\r\n                alignItems: \"center\",\r\n                color: statusColor,\r\n                fontFamily:\r\n                  '-apple-system, BlinkMacSystemFont, \"SF Pro Text\", \"Segoe UI\", sans-serif',\r\n                fontWeight: 600,\r\n                fontSize: 0.045 * w,\r\n              }}\r\n            >\r\n              {time}\r\n            </div>\r\n            <div\r\n              style={{\r\n                position: \"absolute\",\r\n                right: 0.07 * w,\r\n                top: island.top,\r\n                height: island.h,\r\n                display: \"flex\",\r\n                alignItems: \"center\",\r\n                color: statusColor,\r\n              }}\r\n            >\r\n              <StatusIcons h={0.034 * w} />\r\n            </div>\r\n          </div>\r\n        );\r\n      })}\r\n\r\n      {/* The stack's foot fades into the page and the glow. */}\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: 0,\r\n          right: 0,\r\n          bottom: 0,\r\n          height: 0.38 * height,\r\n          background: `linear-gradient(to bottom, transparent 0%, color-mix(in srgb, ${background} 55%, transparent) 60%, ${background} 100%)`,\r\n          zIndex: 100,\r\n        }}\r\n      />\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: \"50%\",\r\n          bottom: -0.45 * height,\r\n          width: 1.1 * width,\r\n          height: 0.7 * height,\r\n          transform: \"translateX(-50%)\",\r\n          borderRadius: \"50%\",\r\n          background: glowColor,\r\n          opacity: 0.35,\r\n          filter: `blur(${60 * u}px)`,\r\n          zIndex: 101,\r\n        }}\r\n      />\r\n    </div>\r\n  );\r\n}\r\n"}]}