{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-image-generation-grid",
  "title": "AI Image Generation Grid",
  "description": "A text-to-image workspace: a prompt panel with aspect ratio, style, model and seed controls, a feed of four-image runs that denoise step by step, hover actions to vary, upscale or like each image, and a lightbox with download.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/ai-image-generation-grid/ai-image-generation-grid.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface ImageSet {\n  id: string;\n  /** Words that send a prompt to this set. */\n  keywords: string[];\n  images: string[];\n}\ntype Aspect = \"1:1\" | \"4:5\" | \"3:2\" | \"16:9\";\ntype Style = \"none\" | \"cinematic\" | \"film\" | \"watercolor\" | \"mono\";\ntype Model = \"quality\" | \"turbo\";\ntype Tile = { img: number; v: number; upAt: number | null; fav: boolean };\ntype Job = { id: string; n: number; prompt: string; set: string; aspect: Aspect; style: Style; model: Model; seed: number; from?: string; startedAt: number | null; tiles: Tile[] };\n\nexport interface AIImageGenerationGridProps {\n  /** Photo sets the demo \"generates\" from. Each needs four images. */\n  sets?: ImageSet[];\n  presets?: string[];\n  credits?: number;\n  modelName?: string;\n  /** Called when a generation starts; wire it to your image API. */\n  onGenerate?: (req: { prompt: string; aspect: Aspect; style: Style; model: Model; seed: number }) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", panel: \"#0F0F0F\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", card: \"#151515\", border: \"rgba(255,255,255,0.09)\", hover: \"rgba(255,255,255,0.05)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", accent: \"#FB923C\", accentSoft: \"rgba(251,146,60,0.15)\", tile: \"#141414\", scrim: \"rgba(5,5,5,0.92)\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#FAFAF8\", panel: \"#F3F2EE\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.4)\", card: \"#FFFFFF\", border: \"rgba(10,10,10,0.09)\", hover: \"rgba(10,10,10,0.04)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", accent: \"#EA580C\", accentSoft: \"rgba(234,88,12,0.1)\", tile: \"#E9E8E4\", scrim: \"rgba(250,250,248,0.95)\", ring: \"rgba(10,10,10,0.5)\" },\n};\nconst GRADIENT = \"linear-gradient(90deg,#FB923C,#F472B6,#A78BFA,#60A5FA)\";\n\nconst BASE = \"/demo/blocks/ai-image-generation-grid\";\nconst DEFAULT_SETS: ImageSet[] = [\n  { id: \"glass\", keywords: [\"glass\", \"green\", \"forest\", \"plant\", \"fern\", \"conservatory\", \"garden\", \"mist\"], images: [1, 2, 3, 4].map((i) => `${BASE}/glass-${i}.webp`) },\n  { id: \"neon\", keywords: [\"neon\", \"city\", \"street\", \"rain\", \"night\", \"tokyo\", \"cyber\", \"sign\"], images: [1, 2, 3, 4].map((i) => `${BASE}/neon-${i}.webp`) },\n  { id: \"dune\", keywords: [\"desert\", \"dune\", \"sand\", \"sahara\", \"minimal\", \"golden\"], images: [1, 2, 3, 4].map((i) => `${BASE}/dune-${i}.webp`) },\n];\nconst DEFAULT_PRESETS = [\"A glass conservatory full of ferns, morning mist drifting through\", \"Rain-soaked neon street at night, cinematic reflections\", \"Soft desert dunes at golden hour, long shadows, minimal\", \"An old greenhouse wrapped in vines after the rain\", \"Empty city crossing at 2am, wet asphalt, glowing signs\"];\n\nconst ASPECTS: { id: Aspect; w: number; h: number; px: [number, number]; max: number }[] = [\n  { id: \"1:1\", w: 1, h: 1, px: [1024, 1024], max: 520 },\n  { id: \"4:5\", w: 4, h: 5, px: [896, 1120], max: 460 },\n  { id: \"3:2\", w: 3, h: 2, px: [1216, 816], max: 620 },\n  { id: \"16:9\", w: 16, h: 9, px: [1344, 768], max: 660 },\n];\nconst STYLES: { id: Style; label: string; filter: string }[] = [\n  { id: \"none\", label: \"None\", filter: \"\" },\n  { id: \"cinematic\", label: \"Cinematic\", filter: \"contrast(1.12) saturate(1.2) sepia(0.12)\" },\n  { id: \"film\", label: \"Film\", filter: \"contrast(0.94) saturate(0.82) sepia(0.28) brightness(1.04)\" },\n  { id: \"watercolor\", label: \"Watercolor\", filter: \"saturate(1.35) contrast(0.82) brightness(1.1)\" },\n  { id: \"mono\", label: \"Mono\", filter: \"grayscale(1) contrast(1.18)\" },\n];\nconst MODELS: { id: Model; label: string; steps: number; ms: number; cost: number }[] = [\n  { id: \"quality\", label: \"Quality\", steps: 30, ms: 3400, cost: 4 },\n  { id: \"turbo\", label: \"Turbo\", steps: 8, ms: 1600, cost: 2 },\n];\n// Variations re-frame the same picture: crop, zoom, a small hue shift, sometimes mirrored.\nconst VARIANTS = [\n  { pos: \"50% 50%\", scale: 1, hue: 0, flip: false },\n  { pos: \"28% 45%\", scale: 1.22, hue: -10, flip: false },\n  { pos: \"72% 60%\", scale: 1.3, hue: 12, flip: true },\n  { pos: \"50% 25%\", scale: 1.16, hue: 0, flip: true },\n  { pos: \"40% 75%\", scale: 1.4, hue: -6, flip: false },\n];\nconst UPSCALE_MS = 1600;\nconst STAGGER = 260;\nconst NOISE = `url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1.4 -0.2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")`;\n\nconst clock = () => performance.now();\nconst randomSeed = () => Math.floor(10000 + Math.random() * 89999);\nconst clamp01 = (v: number) => (v < 0 ? 0 : v > 1 ? 1 : v);\nconst modelOf = (m: Model) => MODELS.find((x) => x.id === m)!;\nconst aspectOf = (a: Aspect) => ASPECTS.find((x) => x.id === a)!;\n\nconst INITIAL_JOB: Job = {\n  id: \"j0\",\n  n: 0,\n  prompt: DEFAULT_PRESETS[0],\n  set: \"glass\",\n  aspect: \"4:5\",\n  style: \"none\",\n  model: \"quality\",\n  seed: 48213,\n  startedAt: null,\n  tiles: [0, 1, 2, 3].map((img) => ({ img, v: 0, upAt: null, fav: img === 3 })),\n};\n\nconst Ico = {\n  vary: (\n    <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.9\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"shrink-0\">\n      <path d=\"M4 12a8 8 0 0 1 14-5.3L20 9M20 4v5h-5M20 12a8 8 0 0 1-14 5.3L4 15M4 20v-5h5\" />\n    </svg>\n  ),\n  up: (\n    <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.9\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"shrink-0\">\n      <path d=\"M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7\" />\n    </svg>\n  ),\n  down: (\n    <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.9\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"shrink-0\">\n      <path d=\"M12 4v11M7 10l5 5 5-5M5 20h14\" />\n    </svg>\n  ),\n  heart: (on: boolean) => (\n    <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill={on ? \"currentColor\" : \"none\"} stroke=\"currentColor\" strokeWidth=\"1.9\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"shrink-0\">\n      <path d=\"M12 20s-7.5-4.6-7.5-10A4.3 4.3 0 0 1 12 7.6 4.3 4.3 0 0 1 19.5 10c0 5.4-7.5 10-7.5 10Z\" />\n    </svg>\n  ),\n  dice: (\n    <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" aria-hidden=\"true\" className=\"shrink-0\">\n      <rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"3.5\" />\n      <circle cx=\"9\" cy=\"9\" r=\"1.2\" fill=\"currentColor\" />\n      <circle cx=\"15\" cy=\"15\" r=\"1.2\" fill=\"currentColor\" />\n      <circle cx=\"15\" cy=\"9\" r=\"1.2\" fill=\"currentColor\" />\n      <circle cx=\"9\" cy=\"15\" r=\"1.2\" fill=\"currentColor\" />\n    </svg>\n  ),\n  spark: (\n    <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" aria-hidden=\"true\" className=\"shrink-0\">\n      <path d=\"M12 2.5c.6 4.9 3.6 7.9 8.5 8.5-4.9.6-7.9 3.6-8.5 8.5-.6-4.9-3.6-7.9-8.5-8.5 4.9-.6 7.9-3.6 8.5-8.5Z\" fill=\"currentColor\" />\n    </svg>\n  ),\n};\n\nfunction TileImage({ src, tile, style, p, up }: { src: string; tile: Tile; style: Style; p: number; up: number }) {\n  const v = VARIANTS[tile.v] ?? VARIANTS[0];\n  const st = STYLES.find((s) => s.id === style)?.filter ?? \"\";\n  // Denoise: heavy blur and no colour at the start, sharp and saturated at the end.\n  const blur = (1 - p) * 26 + (up > 0 && up < 1 ? (1 - up) * 1.6 : 0);\n  const filter = `${st} hue-rotate(${v.hue}deg) blur(${blur.toFixed(2)}px) saturate(${(0.15 + 0.85 * p).toFixed(3)}) brightness(${(0.7 + 0.3 * p).toFixed(3)})`;\n  return (\n    // eslint-disable-next-line @next/next/no-img-element\n    <img src={src} alt=\"\" draggable={false} className=\"absolute inset-0 h-full w-full object-cover\" style={{ objectPosition: v.pos, transform: `scale(${(v.scale * (1.08 - 0.08 * p)).toFixed(4)})${v.flip ? \" scaleX(-1)\" : \"\"}`, filter }} />\n  );\n}\n\nfunction ActionBtn({ label, icon, onClick, disabled, pressed, ring }: { label: string; icon: React.ReactNode; onClick: () => void; disabled?: boolean; pressed?: boolean; ring: React.CSSProperties }) {\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      title={label}\n      aria-pressed={pressed}\n      disabled={disabled}\n      onClick={(e) => {\n        e.stopPropagation();\n        onClick();\n      }}\n      className=\"grid h-8 w-8 cursor-pointer place-items-center rounded-lg border-0 outline-none backdrop-blur-md focus-visible:ring-2 disabled:cursor-not-allowed disabled:opacity-40\"\n      style={{ background: \"rgba(10,10,10,0.55)\", color: pressed ? \"#F472B6\" : \"#F5F4F1\", ...ring }}\n    >\n      {icon}\n    </button>\n  );\n}\n\nexport function AIImageGenerationGrid({ sets = DEFAULT_SETS, presets = DEFAULT_PRESETS, credits: creditsProp = 120, modelName = \"Prism 2\", onGenerate, theme = \"dark\", className }: AIImageGenerationGridProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const feedRef = React.useRef<HTMLDivElement>(null);\n  const [jobs, setJobs] = React.useState<Job[]>([INITIAL_JOB]);\n  const [prompt, setPrompt] = React.useState(\"\");\n  const [aspect, setAspect] = React.useState<Aspect>(\"1:1\");\n  const [style, setStyle] = React.useState<Style>(\"none\");\n  const [model, setModel] = React.useState<Model>(\"quality\");\n  const [seed, setSeed] = React.useState(48213);\n  const [seedLocked, setSeedLocked] = React.useState(false);\n  const [credits, setCredits] = React.useState(creditsProp);\n  const [now, setNow] = React.useState(0);\n  const [box, setBox] = React.useState<{ job: string; i: number } | null>(null);\n  const [presetIdx, setPresetIdx] = React.useState(1);\n  const [note, setNote] = React.useState(\"\");\n  const seq = React.useRef(1);\n\n  const genProgress = (job: Job, i: number) => (job.startedAt === null ? 1 : clamp01((now - job.startedAt - i * STAGGER) / modelOf(job.model).ms));\n  const upProgress = (tile: Tile) => (tile.upAt === null ? 0 : clamp01((now - tile.upAt) / UPSCALE_MS));\n  const busy = jobs.some((j) => j.startedAt !== null && j.tiles.some((_, i) => genProgress(j, i) < 1)) || jobs.some((j) => j.tiles.some((tl) => tl.upAt !== null && upProgress(tl) < 1));\n  const generating = jobs.some((j) => j.startedAt !== null && j.tiles.some((_, i) => genProgress(j, i) < 1));\n\n  // A clock that only runs while something is generating or upscaling.\n  const busyRef = React.useRef(false);\n  React.useEffect(() => {\n    busyRef.current = busy;\n  }, [busy]);\n  const [kick, setKick] = React.useState(0);\n  React.useEffect(() => {\n    if (!kick) return;\n    let raf = 0;\n    const loop = () => {\n      setNow(clock());\n      if (busyRef.current) raf = requestAnimationFrame(loop);\n    };\n    raf = requestAnimationFrame(loop);\n    return () => cancelAnimationFrame(raf);\n  }, [kick]);\n  const start = () => {\n    setNow(clock());\n    setKick((k) => k + 1);\n  };\n\n  const pickSet = (text: string, n: number) => {\n    const low = text.toLowerCase();\n    return sets.find((s) => s.keywords.some((k) => low.includes(k)))?.id ?? sets[n % sets.length].id;\n  };\n  const nextSeed = () => (seedLocked ? seed : randomSeed());\n\n  const generate = () => {\n    const text = prompt.trim();\n    const cost = modelOf(model).cost;\n    if (!text || generating) return;\n    if (credits < cost) {\n      setNote(\"Not enough credits for this run.\");\n      return;\n    }\n    const s = nextSeed();\n    setSeed(s);\n    seq.current += 1;\n    const n = seq.current;\n    const job: Job = { id: `j${n}`, n, prompt: text, set: pickSet(text, n), aspect, style, model, seed: s, startedAt: reduce ? null : clock(), tiles: [0, 1, 2, 3].map((img) => ({ img, v: 0, upAt: null, fav: false })) };\n    setJobs((js) => [job, ...js]);\n    setCredits((c) => c - cost);\n    setNote(`Generating 4 images · ${cost} credits`);\n    onGenerate?.({ prompt: text, aspect, style, model, seed: s });\n    feedRef.current?.scrollTo({ top: 0, behavior: reduce ? \"auto\" : \"smooth\" });\n    if (!reduce) start();\n  };\n\n  const vary = (jobId: string, i: number) => {\n    const src = jobs.find((j) => j.id === jobId);\n    if (!src || generating) return;\n    const cost = modelOf(src.model).cost;\n    if (credits < cost) {\n      setNote(\"Not enough credits for variations.\");\n      return;\n    }\n    seq.current += 1;\n    const n = seq.current;\n    const img = src.tiles[i].img;\n    const job: Job = { ...src, id: `j${n}`, n, from: `Variations of image ${i + 1}`, seed: src.seed + n, startedAt: reduce ? null : clock(), tiles: [1, 2, 3, 4].map((v) => ({ img, v, upAt: null, fav: false })) };\n    setJobs((js) => [job, ...js]);\n    setCredits((c) => c - cost);\n    setBox(null);\n    setNote(\"Making 4 variations\");\n    feedRef.current?.scrollTo({ top: 0, behavior: reduce ? \"auto\" : \"smooth\" });\n    if (!reduce) start();\n  };\n\n  const patchTile = (jobId: string, i: number, patch: Partial<Tile>) => setJobs((js) => js.map((j) => (j.id === jobId ? { ...j, tiles: j.tiles.map((tl, k) => (k === i ? { ...tl, ...patch } : tl)) } : j)));\n  const upscale = (jobId: string, i: number) => {\n    const tile = jobs.find((j) => j.id === jobId)?.tiles[i];\n    if (!tile || tile.upAt !== null) return;\n    if (credits < 1) return setNote(\"Not enough credits to upscale.\");\n    patchTile(jobId, i, { upAt: reduce ? -UPSCALE_MS : clock() });\n    setCredits((c) => c - 1);\n    setNote(\"Upscaling to 2×\");\n    if (!reduce) start();\n  };\n\n  const boxJob = box ? jobs.find((j) => j.id === box.job) ?? null : null;\n  React.useEffect(() => {\n    if (!box) return;\n    const key = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        const b = box;\n        setBox(null);\n        requestAnimationFrame(() => document.getElementById(`${uid}-${b.job}-${b.i}`)?.focus({ preventScroll: true }));\n      }\n      if (e.key === \"ArrowRight\") setBox((b) => (b ? { ...b, i: (b.i + 1) % 4 } : b));\n      if (e.key === \"ArrowLeft\") setBox((b) => (b ? { ...b, i: (b.i + 3) % 4 } : b));\n    };\n    window.addEventListener(\"keydown\", key);\n    return () => window.removeEventListener(\"keydown\", key);\n  }, [box, uid]);\n\n  const srcOf = (job: Job, tile: Tile) => sets.find((s) => s.id === job.set)?.images[tile.img] ?? \"\";\n  const cost = modelOf(model).cost;\n  const boxTile = boxJob ? boxJob.tiles[box!.i] : null;\n  const boxAspect = boxJob ? aspectOf(boxJob.aspect) : ASPECTS[0];\n  const boxUp = boxTile ? upProgress(boxTile) : 0;\n  const [boxW, boxH] = boxAspect.px.map((x) => (boxUp >= 1 ? x * 2 : x));\n  const boxSrc = boxJob && boxTile ? srcOf(boxJob, boxTile) : \"\";\n  const ring = { [\"--tw-ring-color\" as string]: p.ring } as React.CSSProperties;\n  const boxBtn = \"flex h-9 cursor-pointer items-center gap-1.5 rounded-lg border px-3 text-[13px] font-medium outline-none focus-visible:ring-2 disabled:cursor-not-allowed disabled:opacity-45\";\n  const boxBtnStyle: React.CSSProperties = { borderColor: p.border, background: p.card, ...ring };\n\n  const segBtn = (on: boolean) => cn(\"h-8 cursor-pointer rounded-lg border px-2.5 text-[12.5px] font-medium outline-none focus-visible:ring-2\", on ? \"\" : \"hover:bg-[var(--h)]\");\n  const segStyle = (on: boolean): React.CSSProperties => ({ background: on ? p.accentSoft : \"transparent\", borderColor: on ? p.accent : p.border, color: on ? p.text : p.muted, [\"--h\" as string]: p.hover, ...ring });\n\n\n  return (\n    <div className={cn(\"@container relative isolate h-[720px] w-full overflow-hidden\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"flex h-full flex-col @[860px]:flex-row\">\n      {/* Controls */}\n      <form\n        className=\"flex shrink-0 flex-col gap-4 border-b p-4 @[860px]:w-[300px] @[860px]:overflow-y-auto @[860px]:border-r @[860px]:border-b-0 @[860px]:p-5\"\n        style={{ background: p.panel, borderColor: p.border }}\n        onSubmit={(e) => {\n          e.preventDefault();\n          generate();\n        }}\n      >\n        <div className=\"flex items-center justify-between\">\n          <span className=\"flex items-center gap-2 text-[14px] font-semibold\">\n            <span style={{ color: p.accent }}>{Ico.spark}</span>\n            {modelName}\n          </span>\n          <span className=\"text-[12px] tabular-nums\" style={{ color: p.muted }} aria-label={`${credits} credits left`}>\n            {credits} credits\n          </span>\n        </div>\n\n        <div className=\"rounded-xl border p-1\" style={{ background: p.card, borderColor: p.border }}>\n          <label htmlFor={`${uid}-prompt`} className=\"sr-only\">\n            Describe the image\n          </label>\n          <textarea\n            id={`${uid}-prompt`}\n            value={prompt}\n            onChange={(e) => setPrompt(e.target.value)}\n            onKeyDown={(e) => {\n              if (e.key === \"Enter\" && (e.metaKey || e.ctrlKey)) {\n                e.preventDefault();\n                generate();\n              }\n            }}\n            rows={3}\n            placeholder=\"Describe an image…\"\n            className=\"block w-full resize-none border-0 bg-transparent px-2.5 pt-2 text-[14px] leading-[1.45] outline-none @[860px]:h-[104px]\"\n            style={{ color: p.text }}\n          />\n          <div className=\"flex items-center justify-between px-1.5 pb-1\">\n            <button\n              type=\"button\"\n              onClick={() => {\n                setPrompt(presets[presetIdx % presets.length]);\n                setPresetIdx((i) => i + 1);\n              }}\n              className=\"flex h-7 cursor-pointer items-center gap-1.5 rounded-md border-0 bg-transparent px-1.5 text-[12px] outline-none hover:bg-[var(--h)] focus-visible:ring-2\"\n              style={{ color: p.muted, [\"--h\" as string]: p.hover, ...ring }}\n            >\n              {Ico.dice} Surprise me\n            </button>\n            <span className=\"text-[11px] tabular-nums\" style={{ color: p.faint }}>\n              {prompt.length}/400\n            </span>\n          </div>\n        </div>\n\n        <div className=\"flex gap-4 overflow-x-auto [scrollbar-width:none] @[860px]:flex-col @[860px]:overflow-visible\">\n          <fieldset className=\"m-0 shrink-0 border-0 p-0\">\n            <legend className=\"mb-2 text-[11px] font-semibold tracking-[0.08em] uppercase\" style={{ color: p.faint }}>\n              Aspect\n            </legend>\n            <div role=\"radiogroup\" aria-label=\"Aspect ratio\" className=\"flex gap-1.5\">\n              {ASPECTS.map((a) => {\n                const on = aspect === a.id;\n                const s = 13 / Math.max(a.w, a.h);\n                return (\n                  <button key={a.id} type=\"button\" role=\"radio\" aria-checked={on} onClick={() => setAspect(a.id)} className={cn(segBtn(on), \"flex items-center gap-1.5\")} style={segStyle(on)}>\n                    <span aria-hidden=\"true\" className=\"rounded-[2px] border-[1.5px]\" style={{ width: a.w * s, height: a.h * s, borderColor: on ? p.accent : p.faint }} />\n                    {a.id}\n                  </button>\n                );\n              })}\n            </div>\n          </fieldset>\n          <fieldset className=\"m-0 shrink-0 border-0 p-0\">\n            <legend className=\"mb-2 text-[11px] font-semibold tracking-[0.08em] uppercase\" style={{ color: p.faint }}>\n              Style\n            </legend>\n            <div role=\"radiogroup\" aria-label=\"Style\" className=\"flex gap-1.5 @[860px]:flex-wrap\">\n              {STYLES.map((s) => (\n                <button key={s.id} type=\"button\" role=\"radio\" aria-checked={style === s.id} onClick={() => setStyle(s.id)} className={segBtn(style === s.id)} style={segStyle(style === s.id)}>\n                  {s.label}\n                </button>\n              ))}\n            </div>\n          </fieldset>\n          <fieldset className=\"m-0 shrink-0 border-0 p-0\">\n            <legend className=\"mb-2 text-[11px] font-semibold tracking-[0.08em] uppercase\" style={{ color: p.faint }}>\n              Model\n            </legend>\n            <div role=\"radiogroup\" aria-label=\"Model\" className=\"relative flex rounded-lg border p-0.5\" style={{ borderColor: p.border }}>\n              {MODELS.map((m) => (\n                <button key={m.id} type=\"button\" role=\"radio\" aria-checked={model === m.id} onClick={() => setModel(m.id)} className=\"relative h-7 flex-1 cursor-pointer rounded-md border-0 bg-transparent px-3 text-[12.5px] font-medium whitespace-nowrap outline-none focus-visible:ring-2\" style={{ color: model === m.id ? p.onText : p.muted, ...ring }}>\n                  {model === m.id && <motion.span layoutId={`${uid}-model`} className=\"absolute inset-0 rounded-md\" style={{ background: p.on }} transition={{ type: \"spring\", stiffness: 500, damping: 38 }} />}\n                  <span className=\"relative\">\n                    {m.label} · {m.steps} steps\n                  </span>\n                </button>\n              ))}\n            </div>\n          </fieldset>\n          <fieldset className=\"m-0 shrink-0 border-0 p-0\">\n            <legend className=\"mb-2 text-[11px] font-semibold tracking-[0.08em] uppercase\" style={{ color: p.faint }}>\n              Seed\n            </legend>\n            <div className=\"flex items-center gap-1.5\">\n              <span className=\"flex h-8 min-w-[84px] items-center rounded-lg border px-2.5 font-mono text-[12.5px] tabular-nums\" style={{ borderColor: p.border, color: p.text }}>\n                {seed}\n              </span>\n              <button type=\"button\" aria-label=\"New random seed\" onClick={() => setSeed(randomSeed())} className=\"grid h-8 w-8 cursor-pointer place-items-center rounded-lg border bg-transparent outline-none hover:bg-[var(--h)] focus-visible:ring-2\" style={{ borderColor: p.border, color: p.muted, [\"--h\" as string]: p.hover, ...ring }}>\n                {Ico.dice}\n              </button>\n              <button type=\"button\" aria-pressed={seedLocked} onClick={() => setSeedLocked((v) => !v)} className={segBtn(seedLocked)} style={segStyle(seedLocked)}>\n                {seedLocked ? \"Locked\" : \"Lock\"}\n              </button>\n            </div>\n          </fieldset>\n        </div>\n\n        <div className=\"@[860px]:mt-auto\">\n          <button type=\"submit\" disabled={!prompt.trim() || generating} className=\"relative flex h-11 w-full cursor-pointer items-center justify-center gap-2 overflow-hidden rounded-xl border-0 text-[14px] font-semibold outline-none focus-visible:ring-2 disabled:cursor-not-allowed disabled:opacity-45\" style={{ background: p.on, color: p.onText, ...ring }}>\n            {generating && !reduce && <motion.span aria-hidden=\"true\" className=\"absolute inset-y-0 w-1/2 opacity-40\" style={{ background: GRADIENT, filter: \"blur(18px)\" }} initial={{ x: \"-100%\" }} animate={{ x: \"220%\" }} transition={{ duration: 1.4, repeat: Infinity, ease: \"easeInOut\" }} />}\n            <span className=\"relative flex items-center gap-2\">\n              {Ico.spark}\n              {generating ? \"Generating…\" : \"Generate\"}\n              <span className=\"rounded-md px-1.5 py-0.5 text-[11px] font-medium\" style={{ background: theme === \"dark\" ? \"rgba(10,10,10,0.1)\" : \"rgba(255,255,255,0.14)\" }}>\n                {cost} cr\n              </span>\n            </span>\n          </button>\n          <p className=\"m-0 mt-2 hidden text-center text-[11.5px] @[860px]:block\" style={{ color: p.faint }}>\n            ⌘ Enter to generate\n          </p>\n          <p className=\"sr-only\" aria-live=\"polite\">\n            {note}\n          </p>\n        </div>\n      </form>\n\n      {/* Feed */}\n      <div ref={feedRef} className=\"relative min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-5 @[860px]:px-8 @[860px]:py-7\">\n        <div className=\"mx-auto max-w-[760px]\">\n          <div className=\"mb-4 flex items-baseline justify-between\">\n            <h3 className=\"m-0 text-[15px] font-semibold\">Generations</h3>\n            <span className=\"text-[12px]\" style={{ color: p.faint }}>\n              {jobs.length} {jobs.length === 1 ? \"run\" : \"runs\"} · {jobs.reduce((n, j) => n + j.tiles.filter((x) => x.fav).length, 0)} liked\n            </span>\n          </div>\n          <ol className=\"m-0 flex list-none flex-col gap-8 p-0\">\n            <AnimatePresence initial={false}>\n              {jobs.map((job) => {\n                const a = aspectOf(job.aspect);\n                const m = modelOf(job.model);\n                return (\n                  <motion.li key={job.id} layout={reduce ? false : \"position\"} initial={reduce ? false : { opacity: 0, y: -12 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.3 }}>\n                    <div className=\"mb-2.5 flex flex-wrap items-center gap-x-2 gap-y-1\">\n                      <p className=\"m-0 min-w-0 flex-1 basis-[240px] text-[13.5px] leading-snug\">{job.from ? <span style={{ color: p.accent }}>{job.from} · </span> : null}{job.prompt}</p>\n                      <span className=\"flex flex-wrap gap-1 text-[11px]\" style={{ color: p.muted }}>\n                        {[job.aspect, STYLES.find((s) => s.id === job.style)!.label, m.label, `seed ${job.seed}`].map((x) => (\n                          <span key={x} className=\"rounded-md px-1.5 py-0.5\" style={{ background: p.hover }}>\n                            {x}\n                          </span>\n                        ))}\n                      </span>\n                    </div>\n                    <div className=\"grid grid-cols-2 gap-2\" style={{ maxWidth: a.max }}>\n                      {job.tiles.map((tile, i) => {\n                        const gp = genProgress(job, i);\n                        const up = upProgress(tile);\n                        const done = gp >= 1;\n                        const step = Math.max(1, Math.round(gp * m.steps));\n                        return (\n                          <div key={i} className=\"group relative overflow-hidden rounded-xl\" style={{ aspectRatio: `${a.w} / ${a.h}`, background: p.tile }}>\n                            <TileImage src={srcOf(job, tile)} tile={tile} style={job.style} p={gp} up={up} />\n                            {!done && (\n                              <>\n                                <span aria-hidden=\"true\" className=\"absolute inset-0 mix-blend-overlay\" style={{ backgroundImage: NOISE, backgroundSize: \"160px\", opacity: 0.95 * (1 - gp) }} />\n                                <span aria-hidden=\"true\" className=\"absolute inset-x-0 h-1/3\" style={{ top: `${-33 + gp * 133}%`, background: \"linear-gradient(180deg, transparent, rgba(255,255,255,0.12), transparent)\" }} />\n                                <span className=\"absolute bottom-2 left-2 rounded-md px-1.5 py-0.5 font-mono text-[10.5px] text-white tabular-nums\" style={{ background: \"rgba(10,10,10,0.55)\" }}>\n                                  {gp <= 0 ? \"Queued\" : `Step ${step}/${m.steps}`}\n                                </span>\n                                <span className=\"absolute inset-x-0 bottom-0 h-0.5\" style={{ background: \"rgba(255,255,255,0.12)\" }}>\n                                  <span className=\"block h-full\" style={{ width: `${gp * 100}%`, background: GRADIENT }} />\n                                </span>\n                              </>\n                            )}\n                            {done && (\n                              <button id={`${uid}-${job.id}-${i}`} type=\"button\" onClick={() => setBox({ job: job.id, i })} aria-label={`Open image ${i + 1} of “${job.prompt}”`} className=\"absolute inset-0 cursor-zoom-in border-0 bg-transparent outline-none focus-visible:ring-2 focus-visible:ring-inset\" style={ring} />\n                            )}\n                            {up > 0 && up < 1 && (\n                              <span className=\"pointer-events-none absolute inset-0 grid place-items-center\" style={{ background: \"rgba(10,10,10,0.25)\" }}>\n                                <span className=\"rounded-full px-2.5 py-1 font-mono text-[11px] text-white tabular-nums\" style={{ background: \"rgba(10,10,10,0.6)\" }}>\n                                  Upscaling {Math.round(up * 100)}%\n                                </span>\n                              </span>\n                            )}\n                            {up >= 1 && (\n                              <span className=\"pointer-events-none absolute top-2 left-2 rounded-md px-1.5 py-0.5 text-[10.5px] font-bold text-white\" style={{ background: GRADIENT }}>\n                                2×\n                              </span>\n                            )}\n                            {tile.fav && done && (\n                              <span className=\"pointer-events-none absolute top-2 right-2 text-[#F472B6] transition-opacity group-hover:opacity-0 group-focus-within:opacity-0\" aria-hidden=\"true\">\n                                {Ico.heart(true)}\n                              </span>\n                            )}\n                            {done && (\n                              <div className=\"absolute top-2 right-2 flex gap-1 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 [@media(hover:none)]:hidden\">\n                                <ActionBtn label=\"Make variations\" icon={Ico.vary} onClick={() => vary(job.id, i)} disabled={generating} ring={ring} />\n                                <ActionBtn label={tile.upAt !== null ? \"Upscaled\" : \"Upscale 2×\"} icon={Ico.up} onClick={() => upscale(job.id, i)} disabled={tile.upAt !== null} ring={ring} />\n                                <ActionBtn label={tile.fav ? \"Unlike\" : \"Like\"} icon={Ico.heart(tile.fav)} onClick={() => patchTile(job.id, i, { fav: !tile.fav })} pressed={tile.fav} ring={ring} />\n                              </div>\n                            )}\n                          </div>\n                        );\n                      })}\n                    </div>\n                  </motion.li>\n                );\n              })}\n            </AnimatePresence>\n          </ol>\n        </div>\n      </div>\n\n      </div>\n\n      {/* Lightbox */}\n      <AnimatePresence>\n        {box && boxJob && boxTile && (\n          <motion.div key=\"box\" role=\"dialog\" aria-modal=\"true\" aria-label={`Image ${box.i + 1} of 4`} initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0 }} transition={{ duration: 0.18 }} className=\"absolute inset-0 z-30 flex flex-col\" style={{ background: p.scrim }}>\n            <>\n                  <div className=\"flex shrink-0 items-center gap-3 px-4 py-3\">\n                    <p className=\"m-0 min-w-0 flex-1 truncate text-[13px]\" style={{ color: p.muted }}>\n                      {boxJob.prompt}\n                    </p>\n                    <span className=\"shrink-0 font-mono text-[11.5px] tabular-nums\" style={{ color: p.faint }}>\n                      {box.i + 1}/4\n                    </span>\n                    <button\n                      type=\"button\"\n                      aria-label=\"Close\"\n                      ref={(el) => {\n                        if (el && !el.dataset.f) {\n                          el.dataset.f = \"1\";\n                          el.focus({ preventScroll: true });\n                        }\n                      }}\n                      onClick={() => setBox(null)}\n                      className=\"grid h-9 w-9 cursor-pointer place-items-center rounded-full border-0 text-[18px] outline-none focus-visible:ring-2\"\n                      style={{ background: p.hover, color: p.text, ...ring }}\n                    >\n                      ×\n                    </button>\n                  </div>\n                  <div className=\"relative flex min-h-0 flex-1 items-center justify-center px-12 pb-2\">\n                    <AnimatePresence mode=\"wait\" initial={false}>\n                      <motion.div key={`${boxJob.id}-${box.i}`} initial={reduce ? false : { opacity: 0, scale: 0.97 }} animate={{ opacity: 1, scale: 1 }} exit={reduce ? undefined : { opacity: 0, scale: 0.98 }} transition={{ duration: 0.16 }} className=\"relative max-h-full overflow-hidden rounded-xl shadow-[0_30px_80px_-20px_rgba(0,0,0,0.7)]\" style={{ aspectRatio: `${boxAspect.w} / ${boxAspect.h}`, height: boxAspect.w / boxAspect.h < 1.2 ? \"100%\" : undefined, width: boxAspect.w / boxAspect.h >= 1.2 ? \"100%\" : undefined, maxWidth: \"100%\" }}>\n                        <TileImage src={boxSrc} tile={boxTile} style={boxJob.style} p={1} up={boxUp} />\n                      </motion.div>\n                    </AnimatePresence>\n                    {([\"prev\", \"next\"] as const).map((d) => (\n                      <button key={d} type=\"button\" aria-label={d === \"prev\" ? \"Previous image\" : \"Next image\"} onClick={() => setBox((b) => (b ? { ...b, i: (b.i + (d === \"next\" ? 1 : 3)) % 4 } : b))} className={cn(\"absolute top-1/2 grid h-9 w-9 -translate-y-1/2 cursor-pointer place-items-center rounded-full border-0 outline-none focus-visible:ring-2\", d === \"prev\" ? \"left-2\" : \"right-2\")} style={{ background: p.hover, color: p.text, ...ring }}>\n                        <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"shrink-0\" style={{ transform: d === \"next\" ? \"rotate(180deg)\" : undefined }}>\n                          <path d=\"m15 18-6-6 6-6\" />\n                        </svg>\n                      </button>\n                    ))}\n                  </div>\n                  <div className=\"flex shrink-0 flex-wrap items-center justify-center gap-2 px-4 pt-2 pb-4\">\n                    <span className=\"mr-1 font-mono text-[11.5px] tabular-nums\" style={{ color: p.faint }}>\n                      {boxW} × {boxH}\n                    </span>\n                    <button type=\"button\" onClick={() => vary(boxJob.id, box.i)} disabled={generating} className={boxBtn} style={{ ...boxBtnStyle, color: p.text }}>\n                      {Ico.vary}\n                      Vary\n                    </button>\n                    <button type=\"button\" onClick={() => upscale(boxJob.id, box.i)} disabled={boxTile.upAt !== null} className={boxBtn} style={{ ...boxBtnStyle, color: p.text }}>\n                      {Ico.up}\n                      {boxTile.upAt !== null ? (boxUp >= 1 ? \"Upscaled\" : \"Upscaling…\") : \"Upscale 2×\"}\n                    </button>\n                    <button type=\"button\" onClick={() => patchTile(boxJob.id, box.i, { fav: !boxTile.fav })} aria-pressed={boxTile.fav} className={boxBtn} style={{ ...boxBtnStyle, color: boxTile.fav ? \"#F472B6\" : p.text }}>\n                      {Ico.heart(boxTile.fav)}\n                      {boxTile.fav ? \"Liked\" : \"Like\"}\n                    </button>\n                    <a href={boxSrc} download={`prism-${boxJob.seed}-${box.i + 1}.webp`} className=\"flex h-9 items-center gap-1.5 rounded-lg px-3 text-[13px] font-semibold no-underline outline-none focus-visible:ring-2\" style={{ background: p.on, color: p.onText, ...ring }}>\n                      {Ico.down}\n                      Download\n                    </a>\n                  </div>\n            </>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}