{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-image-grid",
  "title": "AI Image Grid",
  "description": "An AI image generator fills a result with a generated render and Download button.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "registryDependencies": ["@remocn/gsh"],
  "files": [
    {
      "path": "registry/remocn/ai-image-grid/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Figtree\";\nimport { loadFont as loadMono } from \"@remotion/google-fonts/GeistMono\";\nimport { useId } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  Img,\n  interpolate,\n  spring,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\nimport type { GradientParams } from \"@/lib/remocn/gsh/gradient-engine\";\nimport { GshGround } from \"@/lib/remocn/gsh/gsh-ground\";\nimport type { GshPresetId } from \"@/lib/remocn/gsh/presets\";\n\nconst { fontFamily } = loadFont(\"normal\", {\n  weights: [\"300\", \"400\"],\n  subsets: [\"latin\"],\n});\nconst { fontFamily: monoFamily } = loadMono(\"normal\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\n\nexport interface AiImageGridProps {\n  prompt?: string;\n  /** Real images for the tiles; procedural art is used for missing ones. */\n  images?: string[];\n  model?: string;\n  layout?: \"2x2\" | \"3x2\";\n  /** Index of the tile that gets picked and zoomed. */\n  pick?: number;\n  accent?: string;\n  speed?: number;\n  theme?: \"light\" | \"dark\";\n  ground?: GshPresetId;\n  groundParams?: Partial<GradientParams>;\n}\n\nconst TYPE_START = 10;\nconst CHARS_PER_FRAME = 1.2;\nconst GEN = 60;\nconst DIFFUSE = [46, 58, 40, 64, 52, 44];\nconst STAGGER = 3;\n\nconst ENTER = Easing.bezier(0.32, 0.72, 0, 1);\nconst ENTER_SOFT = Easing.bezier(0.22, 1, 0.36, 1);\nconst MOVE = Easing.bezier(0.65, 0, 0.35, 1);\nconst EXIT = Easing.bezier(0.55, 0, 1, 0.45);\nconst HEAVY = { mass: 1, damping: 26, stiffness: 120 };\nconst CARD = { mass: 0.8, damping: 18, stiffness: 160 };\nconst CHIP = { mass: 0.5, damping: 12, stiffness: 200 };\nconst MORPH = { damping: 200 };\n\nconst clamp01 = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\nconst lerp = (a: number, b: number, t: number) => a + (b - a) * t;\nconst ramp = (\n  f: number,\n  from: number,\n  len: number,\n  easing: (t: number) => number = ENTER,\n) => interpolate(f, [from, from + len], [0, 1], { ...clamp01, easing });\n\nfunction withAlpha(color: string, alpha: number) {\n  const hex = color.replace(\"#\", \"\");\n  const full = hex.length === 3 ? hex.replace(/(.)/g, \"$1$1\") : hex;\n  if (!/^[0-9a-fA-F]{6}$/.test(full)) return color;\n  const n = Number.parseInt(full, 16);\n  return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;\n}\n\nconst PALETTES = {\n  dark: {\n    dark: true,\n    card: \"rgba(20,18,17,0.94)\",\n    text: \"#F3EFEA\",\n    muted: \"rgba(243,239,234,0.7)\",\n    faint: \"rgba(243,239,234,0.3)\",\n    tile: \"#1C1A19\",\n    shimmer: \"rgba(255,255,255,0.06)\",\n    rule: \"rgba(255,255,255,0.08)\",\n    depth:\n      \"inset 0 1px 0 rgba(255,255,255,0.06), 0 0 0 1px rgba(255,255,255,0.08), 0 30px 70px -24px rgba(0,0,0,0.75)\",\n    tileDepth:\n      \"0 0 0 1px rgba(255,255,255,0.1), 0 18px 40px -18px rgba(0,0,0,0.7)\",\n    solid: \"#F3EFEA\",\n    onSolid: \"#151312\",\n    ghost: \"rgba(255,255,255,0.08)\",\n  },\n  light: {\n    dark: false,\n    card: \"#FFFFFF\",\n    text: \"#1B1917\",\n    muted: \"rgba(27,25,23,0.62)\",\n    faint: \"rgba(27,25,23,0.3)\",\n    tile: \"#ECEAE6\",\n    shimmer: \"rgba(255,255,255,0.7)\",\n    rule: \"rgba(0,0,0,0.07)\",\n    depth:\n      \"0 0 0 1px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.06), 0 24px 50px -20px rgba(40,30,20,0.28)\",\n    tileDepth:\n      \"0 0 0 1px rgba(0,0,0,0.08), 0 16px 34px -18px rgba(40,30,20,0.35)\",\n    solid: \"#1B1917\",\n    onSolid: \"#FFFFFF\",\n    ghost: \"rgba(0,0,0,0.05)\",\n  },\n};\ntype Palette = (typeof PALETTES)[\"dark\"];\n\ninterface Scene {\n  sky: [string, string, string];\n  sun: string;\n  sunAt: [number, number];\n  glass: [string, string, string];\n  ground: string;\n  fog: string;\n  s: number;\n  n: number;\n  cy: number;\n  hMax: number;\n  water?: boolean;\n  island?: boolean;\n}\n\nconst SCENES: Scene[] = [\n  {\n    sky: [\"#3B2E7E\", \"#E96D8B\", \"#FFC38A\"],\n    sun: \"#FFE7B0\",\n    sunAt: [292, 118],\n    glass: [\"#7C8CF0\", \"#3A3F9E\", \"#FFD9C2\"],\n    ground: \"#4C3B7A\",\n    fog: \"#FFB59A\",\n    s: 20,\n    n: 7,\n    cy: 128,\n    hMax: 92,\n  },\n  {\n    sky: [\"#12355E\", \"#3FA3C9\", \"#F8D9A6\"],\n    sun: \"#FFF4D6\",\n    sunAt: [96, 132],\n    glass: [\"#7FD3E6\", \"#1F6E8C\", \"#E8FBFF\"],\n    ground: \"#17425C\",\n    fog: \"#BFE6F0\",\n    s: 32,\n    n: 4,\n    cy: 150,\n    hMax: 120,\n  },\n  {\n    sky: [\"#241A4A\", \"#9C5BD6\", \"#FFB3C7\"],\n    sun: \"#FFE2EC\",\n    sunAt: [210, 96],\n    glass: [\"#C9A4FF\", \"#5B3A9E\", \"#FFE4F1\"],\n    ground: \"#3A2266\",\n    fog: \"#FFC4DA\",\n    s: 22,\n    n: 5,\n    cy: 118,\n    hMax: 80,\n    island: true,\n  },\n  {\n    sky: [\"#0E2240\", \"#E07A4F\", \"#FFD08A\"],\n    sun: \"#FFF1C9\",\n    sunAt: [200, 150],\n    glass: [\"#FFB27A\", \"#6B3A5E\", \"#FFE6C8\"],\n    ground: \"#2A2348\",\n    fog: \"#FFB98A\",\n    s: 18,\n    n: 8,\n    cy: 96,\n    hMax: 70,\n    water: true,\n  },\n  {\n    sky: [\"#1D2B4F\", \"#5E7FD6\", \"#CFE1FF\"],\n    sun: \"#FFFFFF\",\n    sunAt: [320, 90],\n    glass: [\"#A9C4FF\", \"#34508F\", \"#F2F7FF\"],\n    ground: \"#26385F\",\n    fog: \"#D8E6FF\",\n    s: 26,\n    n: 5,\n    cy: 130,\n    hMax: 104,\n  },\n  {\n    sky: [\"#2B1B3D\", \"#D9617A\", \"#FFCF9E\"],\n    sun: \"#FFEBC2\",\n    sunAt: [80, 104],\n    glass: [\"#FF9FB0\", \"#7A2E5E\", \"#FFE0D0\"],\n    ground: \"#3E2148\",\n    fog: \"#FFAE9E\",\n    s: 24,\n    n: 6,\n    cy: 112,\n    hMax: 96,\n  },\n];\n\nfunction hash(n: number) {\n  const x = Math.sin(n * 12.9898 + 78.233) * 43758.5453;\n  return x - Math.floor(x);\n}\n\nfunction City({ sc, seed, uid }: { sc: Scene; seed: number; uid: string }) {\n  const { s, n, cy, hMax } = sc;\n  const cx = 200;\n  const cells: { i: number; j: number }[] = [];\n  for (let d = 0; d <= 2 * (n - 1); d++)\n    for (let i = 0; i < n; i++) {\n      const j = d - i;\n      if (j >= 0 && j < n) cells.push({ i, j });\n    }\n  const baseY = cy + ((n - 1) * s) / 2;\n  const pts = (p: number[][]) => p.map((q) => q.join(\",\")).join(\" \");\n  const top = [\n    [cx, cy - s / 2],\n    [cx + n * s, cy - s / 2 + (n * s) / 2],\n    [cx, cy - s / 2 + n * s],\n    [cx - n * s, cy - s / 2 + (n * s) / 2],\n  ];\n  return (\n    <g>\n      {sc.island && (\n        <>\n          <polygon\n            points={pts([top[3], top[2], [cx, top[2][1] + 78]])}\n            fill={sc.ground}\n          />\n          <polygon\n            points={pts([top[2], top[1], [cx, top[2][1] + 78]])}\n            fill=\"#000\"\n            opacity={0.35}\n          />\n        </>\n      )}\n      <polygon points={pts(top)} fill={sc.ground} />\n      {cells.map(({ i, j }) => {\n        const r = hash(seed * 97 + i * 13 + j * 7);\n        if (r < 0.16) {\n          const x = cx + (i - j) * s;\n          const y = cy + ((i + j) * s) / 2;\n          return (\n            <g key={`${i}-${j}`}>\n              <circle\n                cx={x}\n                cy={y - 5}\n                r={s * 0.32}\n                fill=\"#5FBF9A\"\n                opacity={0.85}\n              />\n              <circle\n                cx={x - 2}\n                cy={y - 7}\n                r={s * 0.14}\n                fill=\"#B8F0D4\"\n                opacity={0.6}\n              />\n            </g>\n          );\n        }\n        const h = 12 + r ** 1.6 * hMax * (1 - (i + j) / (4 * n));\n        const w = s * (0.78 + 0.18 * hash(r * 31));\n        const x = cx + (i - j) * s;\n        const y = cy + ((i + j) * s) / 2;\n        const L = [x - w, y];\n        const B = [x, y + w / 2];\n        const R = [x + w, y];\n        const T = [x, y - w / 2];\n        const up = (p: number[]) => [p[0], p[1] - h];\n        const lines = Math.floor(h / 7);\n        return (\n          <g key={`${i}-${j}`}>\n            <polygon\n              points={pts([L, B, up(B), up(L)])}\n              fill={sc.glass[0]}\n              opacity={0.92}\n            />\n            <polygon\n              points={pts([B, R, up(R), up(B)])}\n              fill={sc.glass[1]}\n              opacity={0.94}\n            />\n            <polygon\n              points={pts([B, R, up(R), up(B)])}\n              fill={`url(#${uid}refl)`}\n            />\n            <polygon\n              points={pts([L, B, up(B), up(L)])}\n              fill={`url(#${uid}shade)`}\n            />\n            {Array.from({ length: lines }, (_, k) => {\n              const yy = 5 + k * 7;\n              return (\n                <path\n                  key={yy}\n                  d={`M${L[0]} ${L[1] - yy}L${B[0]} ${B[1] - yy}L${R[0]} ${R[1] - yy}`}\n                  stroke=\"#FFFFFF\"\n                  strokeOpacity={0.16}\n                  strokeWidth={0.6}\n                  fill=\"none\"\n                />\n              );\n            })}\n            <polygon\n              points={pts([up(L), up(B), up(R), up(T)])}\n              fill={sc.glass[2]}\n            />\n            <line\n              x1={B[0]}\n              y1={B[1]}\n              x2={B[0]}\n              y2={B[1] - h}\n              stroke=\"#FFFFFF\"\n              strokeOpacity={0.55}\n              strokeWidth={0.8}\n            />\n            {r > 0.7 && <circle cx={x} cy={y - h} r={1.6} fill=\"#FFFFFF\" />}\n          </g>\n        );\n      })}\n      {sc.island && (\n        <ellipse\n          cx={cx}\n          cy={baseY + 96}\n          rx={150}\n          ry={14}\n          fill=\"#FFFFFF\"\n          opacity={0.25}\n        />\n      )}\n    </g>\n  );\n}\n\nfunction CityArt({ index }: { index: number }) {\n  const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const sc = SCENES[index % SCENES.length];\n  const waterY = 222;\n  return (\n    <svg\n      viewBox=\"0 0 400 300\"\n      preserveAspectRatio=\"xMidYMid slice\"\n      style={{ width: \"100%\", height: \"100%\", display: \"block\" }}\n      aria-hidden=\"true\"\n    >\n      <defs>\n        <linearGradient id={`${uid}sky`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n          <stop offset=\"0\" stopColor={sc.sky[0]} />\n          <stop offset=\"0.55\" stopColor={sc.sky[1]} />\n          <stop offset=\"1\" stopColor={sc.sky[2]} />\n        </linearGradient>\n        <radialGradient id={`${uid}glow`}>\n          <stop offset=\"0\" stopColor={sc.sun} stopOpacity={0.9} />\n          <stop offset=\"1\" stopColor={sc.sun} stopOpacity={0} />\n        </radialGradient>\n        <linearGradient id={`${uid}refl`} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\">\n          <stop offset=\"0\" stopColor=\"#FFFFFF\" stopOpacity={0.45} />\n          <stop offset=\"0.5\" stopColor=\"#FFFFFF\" stopOpacity={0} />\n        </linearGradient>\n        <linearGradient id={`${uid}shade`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n          <stop offset=\"0\" stopColor=\"#FFFFFF\" stopOpacity={0.18} />\n          <stop offset=\"1\" stopColor=\"#000000\" stopOpacity={0.22} />\n        </linearGradient>\n        <linearGradient id={`${uid}fog`} x1=\"0\" y1=\"1\" x2=\"0\" y2=\"0\">\n          <stop offset=\"0\" stopColor={sc.fog} stopOpacity={0.75} />\n          <stop offset=\"0.45\" stopColor={sc.fog} stopOpacity={0} />\n        </linearGradient>\n        <radialGradient id={`${uid}vig`} cx=\"0.5\" cy=\"0.45\" r=\"0.75\">\n          <stop offset=\"0.6\" stopColor=\"#000\" stopOpacity={0} />\n          <stop offset=\"1\" stopColor=\"#000\" stopOpacity={0.35} />\n        </radialGradient>\n        <clipPath id={`${uid}below`}>\n          <rect x={0} y={waterY} width={400} height={300 - waterY} />\n        </clipPath>\n      </defs>\n      <rect width={400} height={300} fill={`url(#${uid}sky)`} />\n      <circle\n        cx={sc.sunAt[0]}\n        cy={sc.sunAt[1]}\n        r={150}\n        fill={`url(#${uid}glow)`}\n      />\n      <circle cx={sc.sunAt[0]} cy={sc.sunAt[1]} r={22} fill={sc.sun} />\n      {[0, 1, 2, 3, 4, 5, 6, 7].map((k) => (\n        <rect\n          key={k}\n          x={k * 52 - 10 + hash(index + k) * 20}\n          y={200 - hash(k * 3 + index) * 60}\n          width={30 + hash(k + 9) * 20}\n          height={120}\n          fill={sc.sky[0]}\n          opacity={0.18}\n        />\n      ))}\n      {sc.water ? (\n        <>\n          <rect\n            x={0}\n            y={waterY}\n            width={400}\n            height={80}\n            fill={sc.sky[0]}\n            opacity={0.6}\n          />\n          <g clipPath={`url(#${uid}below)`} opacity={0.35}>\n            <g transform={`translate(0 ${2 * waterY}) scale(1 -1)`}>\n              <City sc={sc} seed={index + 1} uid={uid} />\n            </g>\n          </g>\n          {[0, 1, 2, 3, 4].map((k) => (\n            <rect\n              key={k}\n              x={sc.sunAt[0] - 30 + k * 6}\n              y={waterY + 8 + k * 12}\n              width={60 - k * 12}\n              height={1.4}\n              fill={sc.sun}\n              opacity={0.7}\n            />\n          ))}\n        </>\n      ) : null}\n      <City sc={sc} seed={index + 1} uid={uid} />\n      <rect width={400} height={300} fill={`url(#${uid}fog)`} />\n      <rect width={400} height={300} fill={`url(#${uid}vig)`} />\n    </svg>\n  );\n}\n\nfunction Cursor({\n  x,\n  y,\n  press,\n  opacity,\n}: {\n  x: number;\n  y: number;\n  press: number;\n  opacity: number;\n}) {\n  return (\n    <svg\n      width={24}\n      height={28}\n      viewBox=\"0 0 20 24\"\n      style={{\n        position: \"absolute\",\n        left: x - 2.4,\n        top: y - 2.4,\n        opacity,\n        transformOrigin: \"2px 2px\",\n        transform: `scale(${1 - 0.12 * press})`,\n        filter: \"drop-shadow(0 2px 4px rgba(0,0,0,0.3))\",\n        overflow: \"visible\",\n        zIndex: 10,\n      }}\n    >\n      <path\n        d=\"M2 2 L2 19.5 L6.6 15.4 L9.8 22.4 L12.9 21 L9.8 14.2 L16 14.2 Z\"\n        fill=\"#FFFFFF\"\n        stroke=\"#111114\"\n        strokeWidth={1.2}\n        strokeLinejoin=\"round\"\n      />\n    </svg>\n  );\n}\n\nconst ICONS: Record<string, string> = {\n  up: \"M12 19V5M6 11l6-6 6 6\",\n  down: \"M12 4v11M7 10l5 5 5-5M5 20h14\",\n  attach: \"M16 8l-6.5 6.5a2 2 0 0 0 2.8 2.8L19 10.6a4 4 0 0 0-5.6-5.6L6.6 11.7\",\n  vary: \"M4 12a8 8 0 0 1 14-5.3M20 4v4h-4M20 12a8 8 0 0 1-14 5.3M4 20v-4h4\",\n  upscale: \"M14 4h6v6M20 4l-7 7M10 20H4v-6M4 20l7-7\",\n};\n\nfunction Glyph({\n  name,\n  color,\n  size = 18,\n}: {\n  name: string;\n  color: string;\n  size?: number;\n}) {\n  return (\n    <svg\n      width={size}\n      height={size}\n      viewBox=\"0 0 24 24\"\n      aria-hidden=\"true\"\n      style={{ flexShrink: 0 }}\n    >\n      <path\n        d={ICONS[name]}\n        fill=\"none\"\n        stroke={color}\n        strokeWidth={1.5}\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      />\n    </svg>\n  );\n}\n\nfunction Tile({\n  index,\n  src,\n  local,\n  dur,\n  c,\n  frame,\n}: {\n  index: number;\n  src?: string;\n  local: number;\n  dur: number;\n  c: Palette;\n  frame: number;\n}) {\n  const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const p = interpolate(local, [6, 6 + dur], [0, 1], {\n    ...clamp01,\n    easing: MOVE,\n  });\n  const blur = (1 - p) ** 1.4 * 26;\n  const noise = (1 - p) ** 1.1 * 0.62;\n  const pct = Math.round(interpolate(p, [0, 1], [0, 100]));\n  const done = interpolate(p, [0.94, 1], [1, 0], {\n    ...clamp01,\n    easing: EXIT,\n  });\n  const sweep = ((local * 2.4) % 140) - 20;\n  return (\n    <div\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        background: c.tile,\n        overflow: \"hidden\",\n      }}\n    >\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          opacity: 1 - interpolate(p, [0, 0.25], [0, 1], clamp01),\n          background: `linear-gradient(105deg, transparent ${sweep - 20}%, ${c.shimmer} ${sweep}%, transparent ${sweep + 20}%)`,\n        }}\n      />\n      <div\n        style={{\n          position: \"absolute\",\n          inset: -30,\n          opacity: interpolate(p, [0, 0.22], [0, 1], clamp01),\n          filter: `blur(${blur}px) saturate(${1 + 0.4 * (1 - p)})`,\n          transform: `scale(${1 + 0.06 * (1 - p)})`,\n        }}\n      >\n        <div style={{ position: \"absolute\", inset: 30 }}>\n          {src ? (\n            <Img\n              src={src}\n              style={{ width: \"100%\", height: \"100%\", objectFit: \"cover\" }}\n            />\n          ) : (\n            <CityArt index={index} />\n          )}\n        </div>\n      </div>\n      {noise > 0.01 && (\n        <svg\n          width=\"100%\"\n          height=\"100%\"\n          style={{ position: \"absolute\", inset: 0, opacity: noise }}\n          aria-hidden=\"true\"\n        >\n          <filter id={`${uid}n`}>\n            <feTurbulence\n              type=\"fractalNoise\"\n              baseFrequency=\"0.85\"\n              numOctaves={2}\n              seed={Math.floor(frame / 2) + index * 7}\n            />\n            <feColorMatrix values=\"0.9 0 0 0 0.05  0 0.9 0 0 0.05  0 0 0.9 0 0.08  0 0 0 0.85 0\" />\n          </filter>\n          <rect width=\"100%\" height=\"100%\" filter={`url(#${uid}n)`} />\n        </svg>\n      )}\n      {done > 0 && local > 0 && (\n        <div\n          style={{\n            position: \"absolute\",\n            left: 12,\n            bottom: 12,\n            height: 30,\n            padding: \"0 12px\",\n            borderRadius: 999,\n            display: \"flex\",\n            alignItems: \"center\",\n            background: \"rgba(12,11,10,0.46)\",\n            backdropFilter: \"blur(10px)\",\n            color: \"#fff\",\n            fontFamily: monoFamily,\n            fontSize: 16,\n            fontVariantNumeric: \"tabular-nums\",\n            opacity: done,\n          }}\n        >\n          {String(pct).padStart(2, \" \")}%\n        </div>\n      )}\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          borderRadius: \"inherit\",\n          boxShadow: `inset 0 0 0 1px ${c.dark ? \"rgba(255,255,255,0.1)\" : \"rgba(0,0,0,0.1)\"}`,\n        }}\n      />\n    </div>\n  );\n}\n\ntype Key = { f: number; x: number; y: number };\nfunction along(frame: number, keys: Key[]) {\n  if (frame <= keys[0].f) return keys[0];\n  for (let i = 1; i < keys.length; i++) {\n    const a = keys[i - 1];\n    const b = keys[i];\n    if (frame <= b.f) {\n      const t = ENTER(\n        Math.min(1, Math.max(0, (frame - a.f) / Math.max(1, b.f - a.f))),\n      );\n      const dx = b.x - a.x;\n      const dy = b.y - a.y;\n      const len = Math.hypot(dx, dy) || 1;\n      const arc = Math.sin(t * Math.PI) * Math.min(48, len * 0.16);\n      return {\n        x: a.x + dx * t + (-dy / len) * arc,\n        y: a.y + dy * t + (dx / len) * arc,\n      };\n    }\n  }\n  return keys[keys.length - 1];\n}\n\nfunction pressAt(frame: number, fps: number, clicks: number[]) {\n  let v = 0;\n  for (const k of clicks) {\n    if (frame < k - 4) continue;\n    if (frame < k) {\n      v = Math.max(v, ramp(frame, k - 4, 4, MOVE));\n    } else {\n      v = Math.max(v, 1 - spring({ frame: frame - k, fps, config: CHIP }));\n    }\n  }\n  return v;\n}\n\nexport function AiImageGrid({\n  prompt = \"isometric glass city at sunrise, soft light\",\n  images = [],\n  model = \"remocn Image 2\",\n  layout = \"2x2\",\n  pick = 1,\n  accent = \"#3B5BFD\",\n  speed = 1,\n  theme = \"dark\",\n  ground,\n  groundParams,\n}: AiImageGridProps) {\n  const frame = useCurrentFrame() * speed;\n  const { width, height, fps } = useVideoConfig();\n  const tall = height > width * 1.2;\n  const u = tall ? width / 640 : Math.min(width / 1280, height / 720);\n  const dw = width / u;\n  const dh = height / u;\n  const c = PALETTES[theme];\n\n  const count = layout === \"3x2\" ? 6 : 4;\n  const cols = tall ? 2 : count === 6 ? 3 : 2;\n  const rows = count / cols;\n  const gap = 8;\n  const colW = tall ? 576 : cols === 3 ? 744 : 584;\n  const tw = (colW - gap * (cols - 1)) / cols;\n  const th = tw * 0.75;\n  const gridH = rows * th + (rows - 1) * gap;\n  const cardW = tall ? 576 : 640;\n  const cardH = 118;\n  const stackH = gridH + 28 + cardH;\n  const gx = (dw - colW) / 2;\n  const gy = (dh - stackH) / 2;\n  const rects = Array.from({ length: count }, (_, i) => ({\n    x: gx + (i % cols) * (tw + gap),\n    y: gy + Math.floor(i / cols) * (th + gap),\n  }));\n  const pickIdx = Math.min(Math.max(0, pick), count - 1);\n  const resolved = Math.max(\n    ...rects.map((_, i) => i * STAGGER + 6 + DIFFUSE[i % DIFFUSE.length]),\n  );\n  const PICK = GEN + 6 + resolved + 20;\n\n  const typed = Math.floor(Math.max(0, frame - TYPE_START) * CHARS_PER_FRAME);\n  const text = prompt.slice(0, typed);\n  const caretOn = Math.floor(frame / 8) % 2 === 0 || typed < prompt.length;\n\n  const cardX = (dw - cardW) / 2;\n  const introY = (dh - cardH) / 2;\n  const dockY = gy + gridH + 28;\n  const INTRO_S = 1.08;\n  const sendLocal = { x: cardW - 20 - 22, y: cardH - 16 - 22 };\n  const sendIntro = {\n    x: cardX + cardW / 2 + (sendLocal.x - cardW / 2) * INTRO_S,\n    y: introY + cardH / 2 + (sendLocal.y - cardH / 2) * INTRO_S,\n  };\n\n  const enter = spring({ frame, fps, config: HEAVY });\n  const dock = spring({ frame: frame - GEN - 2, fps, config: HEAVY });\n  const cardOut = ramp(frame, PICK, 10, EXIT);\n  const cardY = lerp(introY, dockY, dock) + (1 - enter) * 60 + cardOut * 60;\n  const cardS = lerp(INTRO_S, 1, dock) * (0.96 + 0.04 * enter);\n\n  const pickRect = rects[pickIdx];\n  const tilePt = { x: pickRect.x + tw * 0.56, y: pickRect.y + th * 0.5 };\n  const cur = along(frame, [\n    { f: 26, x: dw * 0.8, y: dh * 0.78 },\n    { f: GEN - 3, ...sendIntro },\n    { f: GEN + 8, ...sendIntro },\n    { f: GEN + 34, x: dw * 0.78, y: dh * 0.5 },\n    { f: PICK - 30, x: dw * 0.78, y: dh * 0.5 },\n    { f: PICK - 4, ...tilePt },\n  ]);\n  const curOpacity = ramp(frame, 24, 8) * (1 - ramp(frame, PICK + 4, 8, EXIT));\n  const press = pressAt(frame, fps, [GEN, PICK]);\n  const sendPress = pressAt(frame, fps, [GEN]);\n  const generating = frame >= GEN && frame < GEN + 6 + resolved;\n\n  const hover = spring({ frame: frame - (PICK - 8), fps, config: CHIP });\n  const othersOut = ramp(frame, PICK + 2, 9, EXIT);\n  const z = spring({\n    frame: frame - PICK - 2,\n    fps,\n    config: MORPH,\n    durationInFrames: 26,\n  });\n\n  const heroW = tall ? 576 : 664;\n  const heroH = heroW * 0.75;\n  const detailsH = tall ? 300 : 0;\n  const heroX = tall ? (dw - heroW) / 2 : 88;\n  const heroY = tall ? (dh - heroH - 48 - detailsH) / 2 : (dh - heroH) / 2;\n  const hero = {\n    x: lerp(pickRect.x, heroX, z),\n    y: lerp(pickRect.y, heroY, z),\n    w: lerp(tw, heroW, z),\n    h: lerp(th, heroH, z),\n  };\n  const det = tall\n    ? { x: heroX, y: heroY + heroH + 48, w: heroW }\n    : {\n        x: heroX + heroW + 56,\n        y: heroY + heroH / 2 - 140,\n        w: dw - (heroX + heroW + 56) - 80,\n      };\n  const d1 = ramp(frame, PICK + 10, 16);\n  const d2 = ramp(frame, PICK + 14, 16);\n  const d3 = spring({ frame: frame - PICK - 18, fps, config: CARD });\n\n  const push = interpolate(frame, [0, 240], [1, 1.03], clamp01);\n  const tileLocal = (i: number) => frame - GEN - 6 - i * STAGGER;\n\n  return (\n    <AbsoluteFill\n      style={{ overflow: \"hidden\", WebkitFontSmoothing: \"antialiased\" }}\n    >\n      <GshGround\n        preset={ground ?? (c.dark ? \"static-sunset\" : \"paper-crease\")}\n        params={\n          groundParams ??\n          (c.dark || ground\n            ? undefined\n            : {\n                colors: [\"#e98d63\", \"#f4c3a2\", \"#efe3d8\", \"#6a4636\"],\n                background: \"#f1ebe4\",\n              })\n        }\n        timeOffset={c.dark ? 4 : 3}\n        timeScale={0.4}\n      />\n      <AbsoluteFill\n        style={{\n          background: c.dark\n            ? \"radial-gradient(70% 80% at 50% 50%, rgba(12,9,8,0.5), rgba(12,9,8,0.18))\"\n            : \"radial-gradient(70% 80% at 50% 50%, rgba(244,239,233,0.45), rgba(244,239,233,0.1))\",\n        }}\n      />\n      <div\n        style={{\n          position: \"absolute\",\n          left: 0,\n          top: 0,\n          width: dw,\n          height: dh,\n          transform: `scale(${u})`,\n          transformOrigin: \"0 0\",\n          fontFamily,\n          color: c.text,\n        }}\n      >\n        <div\n          style={{\n            position: \"absolute\",\n            inset: 0,\n            transform: `scale(${push})`,\n            transformOrigin: \"50% 50%\",\n          }}\n        >\n          {rects.map((r, i) => {\n            const local = tileLocal(i);\n            if (local < -1) return null;\n            const pop = spring({ frame: local, fps, config: CARD });\n            const isPick = i === pickIdx;\n            const h = isPick ? hover : 0;\n            const out = isPick ? 0 : othersOut;\n            return (\n              <div\n                key={`${r.x}-${r.y}`}\n                style={{\n                  position: \"absolute\",\n                  left: r.x,\n                  top: r.y,\n                  width: tw,\n                  height: th,\n                  borderRadius: 14,\n                  overflow: \"hidden\",\n                  opacity:\n                    ramp(local, 0, 6, ENTER_SOFT) *\n                    (1 - out) *\n                    (isPick && z > 0.001 ? 0 : 1),\n                  transform: `translateY(${(1 - pop) * 28 + out * 10}px) scale(${(0.95 + 0.05 * pop) * (1 + 0.02 * h) * (1 - 0.03 * out)})`,\n                  boxShadow: `0 0 0 ${2 * h}px ${accent}, ${c.tileDepth}`,\n                }}\n              >\n                <Tile\n                  index={i}\n                  src={images[i]}\n                  local={local}\n                  dur={DIFFUSE[i % DIFFUSE.length]}\n                  c={c}\n                  frame={frame}\n                />\n              </div>\n            );\n          })}\n\n          <div\n            style={{\n              position: \"absolute\",\n              left: cardX,\n              top: cardY,\n              width: cardW,\n              height: cardH,\n              borderRadius: 20,\n              background: c.card,\n              backdropFilter: c.dark ? \"blur(24px)\" : undefined,\n              boxShadow: c.depth,\n              boxSizing: \"border-box\",\n              padding: \"20px 22px 0\",\n              opacity: ramp(frame, 0, 10, ENTER_SOFT) * (1 - cardOut),\n              transform: `scale(${cardS})`,\n              transformOrigin: \"50% 50%\",\n            }}\n          >\n            <div\n              style={{\n                fontSize: 20,\n                lineHeight: \"28px\",\n                height: 28,\n                letterSpacing: \"-0.01em\",\n                color: text ? c.text : c.faint,\n                whiteSpace: \"nowrap\",\n                overflow: \"hidden\",\n              }}\n            >\n              {text || \"Describe an image\"}\n              {frame < GEN && (\n                <span\n                  style={{\n                    display: \"inline-block\",\n                    width: 2,\n                    height: 22,\n                    marginLeft: 2,\n                    verticalAlign: \"-4px\",\n                    background: accent,\n                    opacity: caretOn ? 1 : 0,\n                  }}\n                />\n              )}\n            </div>\n            <div\n              style={{\n                position: \"absolute\",\n                left: 22,\n                bottom: 22,\n                display: \"flex\",\n                alignItems: \"center\",\n                gap: 10,\n                fontSize: 16,\n                color: c.muted,\n                whiteSpace: \"nowrap\",\n              }}\n            >\n              <Glyph name=\"attach\" color={c.muted} size={18} />\n              <span>{model}</span>\n              <span style={{ color: c.faint }}>·</span>\n              <span>4:3</span>\n              <span style={{ color: c.faint }}>·</span>\n              <span style={{ fontVariantNumeric: \"tabular-nums\" }}>\n                {count} images\n              </span>\n            </div>\n            <div\n              style={{\n                position: \"absolute\",\n                left: sendLocal.x - 22,\n                top: sendLocal.y - 22,\n                width: 44,\n                height: 44,\n                borderRadius: 999,\n                background: c.solid,\n                display: \"flex\",\n                alignItems: \"center\",\n                justifyContent: \"center\",\n                transform: `scale(${1 - 0.04 * sendPress})`,\n                opacity: text.length > 0 ? 1 : 0.35,\n              }}\n            >\n              {generating ? (\n                <svg\n                  width={20}\n                  height={20}\n                  viewBox=\"0 0 20 20\"\n                  aria-hidden=\"true\"\n                  style={{ transform: `rotate(${frame * 12}deg)` }}\n                >\n                  <circle\n                    cx={10}\n                    cy={10}\n                    r={7}\n                    fill=\"none\"\n                    stroke={withAlpha(c.onSolid, 0.25)}\n                    strokeWidth={1.5}\n                  />\n                  <path\n                    d=\"M10 3a7 7 0 0 1 7 7\"\n                    fill=\"none\"\n                    stroke={c.onSolid}\n                    strokeWidth={1.5}\n                    strokeLinecap=\"round\"\n                  />\n                </svg>\n              ) : (\n                <Glyph name=\"up\" color={c.onSolid} size={20} />\n              )}\n            </div>\n          </div>\n\n          {z > 0.001 && (\n            <>\n              <div\n                style={{\n                  position: \"absolute\",\n                  left: hero.x,\n                  top: hero.y,\n                  width: hero.w,\n                  height: hero.h,\n                  borderRadius: lerp(14, 20, z),\n                  overflow: \"hidden\",\n                  boxShadow: `0 0 0 ${2 * (1 - z)}px ${accent}, ${c.tileDepth}, 0 40px 90px -30px rgba(0,0,0,${0.5 * z})`,\n                }}\n              >\n                <Tile\n                  index={pickIdx}\n                  src={images[pickIdx]}\n                  local={999}\n                  dur={1}\n                  c={c}\n                  frame={frame}\n                />\n              </div>\n              <div\n                style={{\n                  position: \"absolute\",\n                  left: det.x,\n                  top: det.y,\n                  width: det.w,\n                  padding: tall ? \"0 4px\" : 0,\n                  boxSizing: \"border-box\",\n                }}\n              >\n                <div\n                  style={{\n                    fontFamily: monoFamily,\n                    fontSize: 16,\n                    color: c.muted,\n                    letterSpacing: \"0.02em\",\n                    opacity: d1,\n                    transform: `translateY(${(1 - d1) * 14}px)`,\n                  }}\n                >\n                  {pickIdx + 1} of {count} · {model}\n                </div>\n                <div\n                  style={{\n                    marginTop: 16,\n                    fontSize: tall ? 46 : 38,\n                    fontWeight: 300,\n                    lineHeight: 1.12,\n                    letterSpacing: \"-0.025em\",\n                    textWrap: \"balance\",\n                    opacity: d1,\n                    transform: `translateY(${(1 - d1) * 22}px)`,\n                  }}\n                >\n                  {prompt}\n                </div>\n                <div\n                  style={{\n                    marginTop: 20,\n                    display: \"flex\",\n                    gap: 18,\n                    fontFamily: monoFamily,\n                    fontSize: 16,\n                    color: c.muted,\n                    fontVariantNumeric: \"tabular-nums\",\n                    opacity: d2,\n                    transform: `translateY(${(1 - d2) * 14}px)`,\n                  }}\n                >\n                  <span>2048 × 1536</span>\n                  <span>seed 48213</span>\n                  <span>9.4 s</span>\n                </div>\n                <div\n                  style={{\n                    marginTop: tall ? 36 : 32,\n                    display: \"flex\",\n                    gap: 10,\n                    opacity: Math.min(1, d3 * 1.4),\n                    transform: `translateY(${(1 - d3) * 18}px)`,\n                  }}\n                >\n                  {[\n                    { l: \"Vary\", i: \"vary\" },\n                    { l: \"Upscale\", i: \"upscale\" },\n                  ].map((b) => (\n                    <div\n                      key={b.l}\n                      style={{\n                        height: 46,\n                        padding: \"0 18px 0 14px\",\n                        borderRadius: 999,\n                        background: c.ghost,\n                        boxShadow: `inset 0 0 0 1px ${c.rule}`,\n                        display: \"flex\",\n                        alignItems: \"center\",\n                        gap: 8,\n                        fontSize: 17,\n                      }}\n                    >\n                      <Glyph name={b.i} color={c.text} size={18} />\n                      {b.l}\n                    </div>\n                  ))}\n                  <div\n                    style={{\n                      height: 46,\n                      padding: \"0 20px 0 16px\",\n                      borderRadius: 999,\n                      background: c.solid,\n                      color: c.onSolid,\n                      display: \"flex\",\n                      alignItems: \"center\",\n                      gap: 8,\n                      fontSize: 17,\n                    }}\n                  >\n                    <Glyph name=\"down\" color={c.onSolid} size={18} />\n                    Download\n                  </div>\n                </div>\n              </div>\n            </>\n          )}\n          <Cursor x={cur.x} y={cur.y} press={press} opacity={curOpacity} />\n        </div>\n      </div>\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/ai-image-grid.tsx"
    }
  ],
  "type": "registry:component"
}
