{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-image-loader-03",
  "title": "AI Image Loader 03",
  "description": "An AI image-generation loader, canvas-drawn rolling topographic lines grow in and a top-to-bottom sweep reveals the finished picture, with cycling status messages and a regenerate button.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/ai-image-loader-03/ai-image-loader-03.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype RGB = [number, number, number];\ntype Phase = \"generating\" | \"done\";\ntype Preview = \"auto\" | Phase;\ntype ImageSource = { src: string; srcSet?: string; alt?: string };\n\nexport interface AiImageLoader03Props {\n  preview?: Preview;\n  loop?: boolean;\n  loopDelay?: number;\n  generateSeconds?: number;\n  messages?: string[];\n  cycleSeconds?: number;\n  doneText?: string;\n  showResult?: boolean;\n  image?: ImageSource;\n  scrim?: number;\n  lineCount?: number;\n  lineWidth?: number;\n  amplitude?: number;\n  lineColor?: string;\n  accentColor?: string;\n  accentAmount?: number;\n  speed?: number;\n  intensity?: number;\n  edgeFade?: number;\n  font?: React.CSSProperties;\n  textColor?: string;\n  mutedColor?: string;\n  glowColors?: string[];\n  ringIntensity?: number;\n  ringSize?: number;\n  ringSpeed?: number;\n  background?: string;\n  borderColor?: string;\n  radius?: number;\n  padding?: number;\n  gap?: number;\n  ariaLabel?: string;\n  onComplete?: () => void;\n  onRegenerate?: () => void;\n  className?: string;\n  style?: React.CSSProperties;\n}\n\nconst START_ANGLE = 40;\nconst STATIC_SHIMMER = 72;\nconst RV_MIN = 0;\nconst SWEEP_IN = 2.4;\nconst SWEEP_OUT = 1.0;\nconst FEATHER = 34;\nconst sweepPct = (p: number) => -FEATHER + (100 + FEATHER) * p;\nconst EASE = \"cubic-bezier(0.2, 0.8, 0.2, 1)\";\nconst FONT_FALLBACK = \"Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif\";\nconst HAIRLINE = \"rgba(255,255,255,0.14)\";\nconst HOVER_ON = \"inset 0 0 0 999px rgba(255,255,255,0.07)\";\nconst HOVER_OFF = \"inset 0 0 0 999px rgba(255,255,255,0)\";\nconst RING = \"0 0 0 2px rgba(255,255,255,0.35)\";\nconst NO_RING = \"0 0 0 0 rgba(255,255,255,0)\";\n\nconst DEFAULT_MESSAGES = [\"Composing the scene\", \"Finding the light\", \"Drawing the shapes\", \"Almost there\"];\nconst DEFAULT_GLOW = [\"#7CF3FF\", \"#6EA8FF\", \"#9B7BFF\"];\nconst DEFAULT_IMAGE: ImageSource = {\n  src: \"/demo/ai-image-loader-03.webp\",\n  alt: \"Warm-toned living room with sheer curtains billowing as a woman in a flowing dress walks through a doorway, motion-blurred\",\n};\n\nconst SR_ONLY: React.CSSProperties = {\n  position: \"absolute\",\n  width: 1,\n  height: 1,\n  overflow: \"hidden\",\n  clip: \"rect(0 0 0 0)\",\n  whiteSpace: \"nowrap\",\n};\n\ntype Live = {\n  phase: Phase;\n  hasImage: boolean;\n  time: number;\n  angle: number;\n  rv: number;\n  grow: number;\n  ringSpeed: number;\n  speed: number;\n  lines: number;\n  lineW: number;\n  amp: number;\n  intensity: number;\n  accentAmount: number;\n  base: RGB;\n  accent: RGB;\n  top: number;\n  cardH: number;\n  snap: boolean;\n};\n\nfunction clamp01(v: number) {\n  return Math.min(1, Math.max(0, v));\n}\n\nfunction smooth(v: number) {\n  const t = clamp01(v);\n  return t * t * (3 - 2 * t);\n}\n\nfunction smoother(v: number) {\n  const t = clamp01(v);\n  return t * t * t * (t * (t * 6 - 15) + 10);\n}\n\nfunction parseRgb(input: string, fallback: RGB): RGB {\n  const s = (input || \"\").trim();\n  if (s.startsWith(\"#\")) {\n    let h = s.slice(1);\n    if (h.length === 3 || h.length === 4)\n      h = h\n        .split(\"\")\n        .map((c) => c + c)\n        .join(\"\");\n    const n = parseInt(h.slice(0, 6), 16);\n    if (h.length >= 6 && !Number.isNaN(n)) return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n  }\n  const m = s.match(/rgba?\\(\\s*([\\d.]+)[,\\s]+([\\d.]+)[,\\s]+([\\d.]+)/i);\n  if (m) return [Math.round(+m[1]), Math.round(+m[2]), Math.round(+m[3])];\n  return fallback;\n}\n\nfunction mixRgb(a: RGB, b: RGB, t: number): RGB {\n  return [Math.round(a[0] + (b[0] - a[0]) * t), Math.round(a[1] + (b[1] - a[1]) * t), Math.round(a[2] + (b[2] - a[2]) * t)];\n}\n\nfunction cleanList(list: string[] | undefined, fallback: string[]) {\n  const out = (list ?? []).filter((s): s is string => typeof s === \"string\" && s.trim() !== \"\");\n  return out.length ? out : fallback;\n}\n\nfunction isUsableImageSrc(src?: string) {\n  if (typeof src !== \"string\") return false;\n  const s = src.trim();\n  if (!s) return false;\n  if (s.startsWith(\"data:\")) {\n    const comma = s.indexOf(\",\");\n    if (comma < 0) return false;\n    const payload = s.slice(comma + 1).replace(/\\s/g, \"\");\n    return payload.length > 16 && !payload.includes(\"/*\");\n  }\n  return true;\n}\n\nfunction buildGradient(colors: string[], spread: number) {\n  const arc = Math.max(0.15, Math.min(1, spread)) * 360;\n  const n = colors.length;\n  if (n === 0) return \"linear-gradient(transparent, transparent)\";\n  const stops = colors.map((c, i) => {\n    const at = n === 1 ? 0.5 : 0.1 + (0.8 * i) / (n - 1);\n    return `${c} ${(at * arc).toFixed(1)}deg`;\n  });\n  return `conic-gradient(from var(--gl-angle, ${START_ANGLE}deg), transparent 0deg, ${stops.join(\", \")}, transparent ${arc.toFixed(1)}deg, transparent 360deg)`;\n}\n\nfunction ringStyle(width: number): React.CSSProperties {\n  return {\n    position: \"absolute\",\n    inset: 0,\n    boxSizing: \"border-box\",\n    borderRadius: \"inherit\",\n    padding: width,\n    WebkitMask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n    WebkitMaskComposite: \"xor\",\n    mask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n    maskComposite: \"exclude\",\n  };\n}\n\nconst PTS = 120;\nconst MAX_LINES = 64;\nconst RIDGE = 0.24;\nconst FIELD_Y = new Float32Array(PTS + 1);\nconst FIELD_H = new Float32Array(PTS + 1);\nconst FIELD_MIN = new Float32Array(PTS + 1);\n\nfunction heightAt(u: number, i: number, n: number, t: number) {\n  const v = i / Math.max(1, n - 1);\n  const env = smooth(u * 5) * smooth((1 - u) * 5);\n  let s = 0;\n  for (let k = 0; k < 3; k++) {\n    const c = 0.5 + 0.34 * Math.sin(t * (0.23 + 0.09 * k) + k * 2.3 + v * (1.4 + k * 0.6));\n    const w = 0.075 + 0.03 * Math.sin(t * 0.4 + k * 1.7 + v * 2);\n    const a = 0.55 + 0.45 * Math.sin(t * (0.31 + 0.05 * k) + k * 1.1 + v * 3.1);\n    const d = (u - c) / w;\n    s += a * Math.exp(-0.5 * d * d);\n  }\n  const fine = 0.16 * Math.sin(u * 27 + i * 0.9 + t * 1.6) * Math.sin(u * 9 - t * 0.7 + i * 0.3);\n  return 0.7 * env * (s * 0.55 + fine * (0.3 + s));\n}\n\nfunction lineGeo(h: number, n: number, amp: number) {\n  const maxH = h * 0.22 * amp;\n  const top = maxH * 1.05;\n  return {\n    maxH,\n    top,\n    spacing: Math.max(2, (h - top - 6) / Math.max(1, n - 1)),\n  };\n}\n\nfunction fillLine(i: number, n: number, geo: ReturnType<typeof lineGeo>, t: number, grow: number) {\n  const base = geo.top + i * geo.spacing;\n  for (let k = 0; k <= PTS; k++) {\n    const hh = heightAt(k / PTS, i, n, t);\n    FIELD_H[k] = hh;\n    FIELD_Y[k] = base - hh * geo.maxH * grow;\n  }\n}\n\nfunction lineAlphas(i: number, n: number, intensity: number) {\n  const v = n === 1 ? 1 : i / (n - 1);\n  return {\n    a0: clamp01((0.14 + 0.36 * v) * intensity),\n    a1: clamp01((0.45 + 0.5 * v) * intensity),\n  };\n}\nfunction drawLines(ctx: CanvasRenderingContext2D, w: number, h: number, L: Live) {\n  const n = L.lines;\n  const geo = lineGeo(h, n, L.amp);\n  ctx.lineJoin = \"round\";\n  ctx.lineCap = \"round\";\n  FIELD_MIN.fill(Infinity);\n  const [br, bg, bb] = L.base;\n  const [hr, hg, hb] = mixRgb(L.base, L.accent, L.accentAmount);\n  for (let i = n - 1; i >= 0; i--) {\n    fillLine(i, n, geo, L.time, L.grow);\n    const { a0, a1 } = lineAlphas(i, n, L.intensity);\n    ctx.lineWidth = L.lineW;\n    ctx.strokeStyle = `rgba(${br},${bg},${bb},${a0.toFixed(3)})`;\n    ctx.beginPath();\n    let pen = false;\n    for (let k = 0; k <= PTS; k++) {\n      if (FIELD_Y[k] <= FIELD_MIN[k] + 0.01) {\n        const x = (k / PTS) * w;\n        if (pen) ctx.lineTo(x, FIELD_Y[k]);\n        else ctx.moveTo(x, FIELD_Y[k]);\n        pen = true;\n      } else pen = false;\n    }\n    ctx.stroke();\n    ctx.lineWidth = L.lineW * 1.3;\n    ctx.strokeStyle = `rgba(${hr},${hg},${hb},${a1.toFixed(3)})`;\n    ctx.beginPath();\n    pen = false;\n    for (let k = 0; k <= PTS; k++) {\n      if (FIELD_H[k] > RIDGE && FIELD_Y[k] <= FIELD_MIN[k] + 0.01) {\n        const x = (k / PTS) * w;\n        if (pen) ctx.lineTo(x, FIELD_Y[k]);\n        else ctx.moveTo(x, FIELD_Y[k]);\n        pen = true;\n      } else pen = false;\n    }\n    ctx.stroke();\n    for (let k = 0; k <= PTS; k++) if (FIELD_Y[k] < FIELD_MIN[k]) FIELD_MIN[k] = FIELD_Y[k];\n  }\n  if (L.rv > 0.001 && L.rv < 1) {\n    const front = (sweepPct(smoother(L.rv)) / 100) * L.cardH - L.top;\n    const span = (FEATHER / 100) * L.cardH;\n    ctx.globalCompositeOperation = \"destination-out\";\n    if (front > 0) {\n      ctx.fillStyle = \"#000\";\n      ctx.fillRect(0, 0, w, Math.min(h, front));\n    }\n    const y0 = Math.max(0, front);\n    const y1 = Math.min(h, front + span);\n    if (y1 > y0) {\n      const g = ctx.createLinearGradient(0, front, 0, front + span);\n      g.addColorStop(0, \"rgba(0,0,0,1)\");\n      g.addColorStop(0.45, \"rgba(0,0,0,0.55)\");\n      g.addColorStop(1, \"rgba(0,0,0,0)\");\n      ctx.fillStyle = g;\n      ctx.fillRect(0, y0, w, y1 - y0);\n    }\n    ctx.globalCompositeOperation = \"source-over\";\n  }\n}\n\nfunction useFocusVisible() {\n  const [focusVisible, setFocusVisible] = React.useState(false);\n  return {\n    focusVisible,\n    onFocus: (e: React.FocusEvent<HTMLElement>) => {\n      try {\n        setFocusVisible(e.currentTarget.matches(\":focus-visible\"));\n      } catch {\n        setFocusVisible(true);\n      }\n    },\n    onBlur: () => setFocusVisible(false),\n  };\n}\n\nfunction subscribeReducedMotion(callback: () => void) {\n  if (typeof window === \"undefined\" || typeof window.matchMedia !== \"function\") return () => undefined;\n  const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  if (typeof mq.addEventListener !== \"function\") return () => undefined;\n  mq.addEventListener(\"change\", callback);\n  return () => mq.removeEventListener(\"change\", callback);\n}\nfunction getReducedMotionSnapshot() {\n  return typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\nfunction getReducedMotionServerSnapshot() {\n  return false;\n}\n\nconst RefreshIcon = () => (\n  <svg\n    width={16}\n    height={16}\n    viewBox=\"0 0 24 24\"\n    fill=\"none\"\n    stroke=\"currentColor\"\n    strokeWidth={2}\n    strokeLinecap=\"round\"\n    strokeLinejoin=\"round\"\n    aria-hidden=\"true\"\n    focusable=\"false\"\n    style={{ display: \"block\" }}\n  >\n    <path d=\"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8\" />\n    <path d=\"M21 3v5h-5\" />\n  </svg>\n);\n\ntype RoundButtonProps = {\n  label: string;\n  onClick: () => void;\n  background: string;\n  color: string;\n  children: React.ReactNode;\n};\n\nfunction RoundButton({ label, onClick, background, color, children }: RoundButtonProps) {\n  const [hover, setHover] = React.useState(false);\n  const [pressed, setPressed] = React.useState(false);\n  const focus = useFocusVisible();\n  const release = () => setPressed(false);\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      onClick={onClick}\n      onMouseEnter={() => setHover(true)}\n      onMouseLeave={() => {\n        setHover(false);\n        release();\n      }}\n      onPointerDown={() => setPressed(true)}\n      onPointerUp={release}\n      onPointerLeave={release}\n      onPointerCancel={release}\n      onFocus={focus.onFocus}\n      onBlur={focus.onBlur}\n      style={{\n        width: 34,\n        height: 34,\n        flex: \"none\",\n        margin: 0,\n        padding: 0,\n        display: \"flex\",\n        alignItems: \"center\",\n        justifyContent: \"center\",\n        borderRadius: \"50%\",\n        border: `1px solid ${HAIRLINE}`,\n        background,\n        color,\n        cursor: \"pointer\",\n        outline: \"none\",\n        backdropFilter: \"blur(10px)\",\n        WebkitBackdropFilter: \"blur(10px)\",\n        transform: pressed ? \"scale(0.92)\" : \"scale(1)\",\n        boxShadow: `${hover ? HOVER_ON : HOVER_OFF}, ${focus.focusVisible ? RING : NO_RING}`,\n        transition: \"background-color 0.25s ease, color 0.25s ease, box-shadow 0.2s ease, transform 0.15s ease\",\n      }}\n    >\n      {children}\n    </button>\n  );\n}\n\nexport function AiImageLoader03(props: AiImageLoader03Props) {\n  const {\n    preview = \"auto\",\n    loop = false,\n    loopDelay = 3,\n    generateSeconds = 5,\n    messages = DEFAULT_MESSAGES,\n    cycleSeconds = 3.2,\n    doneText = \"\",\n    showResult = true,\n    image,\n    scrim = 0.55,\n    lineCount = 36,\n    lineWidth = 1,\n    amplitude = 1,\n    lineColor = \"#FFFFFF\",\n    accentColor = \"#9DB8FF\",\n    accentAmount = 0.2,\n    speed = 1.4,\n    intensity = 1,\n    edgeFade = 20,\n    font = { fontSize: 16, lineHeight: 1.3 },\n    textColor = \"#DADADA\",\n    mutedColor = \"#6B6B6B\",\n    glowColors = DEFAULT_GLOW,\n    ringIntensity = 0.4,\n    ringSize = 10,\n    ringSpeed = 40,\n    background = \"rgba(255,255,255,0.035)\",\n    borderColor = \"rgba(255,255,255,0.08)\",\n    radius = 28,\n    padding = 24,\n    gap = 18,\n    ariaLabel = \"AI image generation\",\n    onComplete,\n    onRegenerate,\n    className,\n    style,\n  } = props;\n\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const visualRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const revealRef = React.useRef<HTMLDivElement>(null);\n  const pictureRef = React.useRef<HTMLImageElement>(null);\n  const ringInnerRef = React.useRef<HTMLDivElement>(null);\n  const textEls = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const isVisibleRef = React.useRef(true);\n  const prevPhase = React.useRef<Phase>(\"generating\");\n  const generateTimerRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const loopTimerRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const cycleTimerRef = React.useRef<ReturnType<typeof setInterval> | null>(null);\n  const rafRef = React.useRef(0);\n  const mountedRef = React.useRef(true);\n  const runGenRef = React.useRef(0);\n\n  const configuredImage = image && isUsableImageSrc(image.src) ? image : undefined;\n  const source: ImageSource = configuredImage ?? DEFAULT_IMAGE;\n  const hasImage = showResult && isUsableImageSrc(source.src);\n  const [phase, setPhase] = React.useState<Phase>(\"generating\");\n  const [idx, setIdx] = React.useState(0);\n  const [run, setRun] = React.useState(0);\n  const reduce = React.useSyncExternalStore(subscribeReducedMotion, getReducedMotionSnapshot, getReducedMotionServerSnapshot);\n\n  const messageList = React.useMemo(() => cleanList(messages, DEFAULT_MESSAGES), [messages]);\n  const glowList = React.useMemo(() => cleanList(glowColors, DEFAULT_GLOW), [glowColors]);\n  const glowGradient = React.useMemo(() => buildGradient(glowList, 0.55), [glowList]);\n  const baseRgb = React.useMemo(() => parseRgb(lineColor, [255, 255, 255]), [lineColor]);\n  const accentRgb = React.useMemo(() => parseRgb(accentColor, [157, 184, 255]), [accentColor]);\n  const lineN = Math.max(12, Math.min(MAX_LINES, Math.round(lineCount)));\n\n  const fixed: Phase | null = preview !== \"auto\" ? preview : null;\n  const settled = fixed !== null || reduce;\n  const wanted: Phase = fixed ?? (reduce ? (hasImage ? \"done\" : \"generating\") : phase);\n  const shownPhase: Phase = wanted === \"done\" && hasImage ? \"done\" : \"generating\";\n\n  const liveRef = React.useRef<Live>({\n    phase: shownPhase,\n    hasImage,\n    time: 0,\n    angle: START_ANGLE,\n    rv: RV_MIN,\n    grow: 1,\n    ringSpeed,\n    speed,\n    lines: lineN,\n    lineW: lineWidth,\n    amp: amplitude,\n    intensity,\n    accentAmount,\n    base: baseRgb,\n    accent: accentRgb,\n    top: 0,\n    cardH: 1,\n    snap: false,\n  });\n  React.useLayoutEffect(() => {\n    const live = liveRef.current;\n    live.phase = shownPhase;\n    live.hasImage = hasImage;\n    live.ringSpeed = ringSpeed;\n    live.speed = speed;\n    live.lines = lineN;\n    live.lineW = lineWidth;\n    live.amp = amplitude;\n    live.intensity = intensity;\n    live.accentAmount = accentAmount;\n    live.base = baseRgb;\n    live.accent = accentRgb;\n    live.snap = fixed !== null || reduce;\n  });\n\n  React.useEffect(() => {\n    mountedRef.current = true;\n    return () => {\n      mountedRef.current = false;\n    };\n  }, []);\n\n  const resetKey = `${String(fixed)}|${reduce}|${run}`;\n  const [prevResetKey, setPrevResetKey] = React.useState(resetKey);\n  if (prevResetKey !== resetKey) {\n    setPrevResetKey(resetKey);\n    setPhase(\"generating\");\n    setIdx(0);\n  }\n\n  React.useEffect(() => {\n    if (fixed !== null || reduce) return;\n    liveRef.current.grow = 0.15;\n    if (!hasImage) return;\n    if (generateTimerRef.current) clearTimeout(generateTimerRef.current);\n    const myGen = ++runGenRef.current;\n    generateTimerRef.current = setTimeout(\n      () => {\n        if (!mountedRef.current || runGenRef.current !== myGen) return;\n        setPhase(\"done\");\n      },\n      Math.max(1, generateSeconds) * 1000,\n    );\n    return () => {\n      if (generateTimerRef.current) clearTimeout(generateTimerRef.current);\n    };\n  }, [fixed, reduce, hasImage, run, generateSeconds]);\n\n  React.useEffect(() => {\n    const prev = prevPhase.current;\n    prevPhase.current = phase;\n    if (fixed !== null || reduce) return;\n    if (prev === \"generating\" && phase === \"done\") onComplete?.();\n  }, [phase, fixed, reduce, onComplete]);\n\n  React.useEffect(() => {\n    if (fixed !== null || reduce || !loop || !hasImage || phase !== \"done\") return;\n    if (loopTimerRef.current) clearTimeout(loopTimerRef.current);\n    loopTimerRef.current = setTimeout(\n      () => {\n        if (!mountedRef.current) return;\n        setRun((r) => r + 1);\n      },\n      Math.max(0.5, loopDelay) * 1000,\n    );\n    return () => {\n      if (loopTimerRef.current) clearTimeout(loopTimerRef.current);\n    };\n  }, [fixed, reduce, loop, hasImage, phase, loopDelay]);\n\n  React.useEffect(() => {\n    if (reduce || shownPhase !== \"generating\" || messageList.length < 2) return;\n    if (cycleSeconds <= 0) return;\n    if (cycleTimerRef.current) clearInterval(cycleTimerRef.current);\n    cycleTimerRef.current = setInterval(() => {\n      if (!mountedRef.current) return;\n      if (isVisibleRef.current) setIdx((i) => (i + 1) % messageList.length);\n    }, cycleSeconds * 1000);\n    return () => {\n      if (cycleTimerRef.current) clearInterval(cycleTimerRef.current);\n    };\n  }, [reduce, shownPhase, messageList.length, cycleSeconds]);\n\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el) return;\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        isVisibleRef.current = entry.isIntersecting;\n      },\n      { threshold: 0 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const wrap = visualRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas ? canvas.getContext(\"2d\") : null;\n    if (!root) return;\n\n    let last = performance.now();\n    let w = 0;\n    let h = 0;\n\n    const fit = () => {\n      if (!wrap || !canvas || !ctx) return;\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      w = wrap.clientWidth;\n      h = wrap.clientHeight;\n      canvas.width = Math.max(2, Math.round(w * dpr));\n      canvas.height = Math.max(2, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      liveRef.current.top = wrap.offsetTop || 0;\n      liveRef.current.cardH = Math.max(1, root.clientHeight);\n    };\n\n    const draw = () => {\n      if (!ctx || w <= 0 || h <= 0) return;\n      ctx.clearRect(0, 0, w, h);\n      if (liveRef.current.rv < 1) drawLines(ctx, w, h, liveRef.current);\n    };\n\n    const updateDom = (L: Live) => {\n      const t = L.time;\n      const pos = (100 - 100 * ((t / 2.4) % 1)).toFixed(2);\n      for (const node of textEls.current) if (node) node.style.backgroundPosition = `${pos}% 50%`;\n      if (ringInnerRef.current) ringInnerRef.current.style.opacity = (0.55 + 0.3 * Math.sin(t * 2.2)).toFixed(3);\n      const p = smoother(L.rv);\n      const reveal = revealRef.current;\n      if (reveal) {\n        reveal.style.setProperty(\"--sy\", sweepPct(p).toFixed(2));\n        reveal.style.visibility = L.rv <= 0.001 ? \"hidden\" : \"visible\";\n      }\n    };\n\n    fit();\n\n    const ro = new ResizeObserver(() => {\n      if (!isVisibleRef.current) return;\n      fit();\n      draw();\n    });\n    if (wrap) ro.observe(wrap);\n\n    if (reduce) {\n      const L = liveRef.current;\n      L.time = 3.4;\n      L.grow = 1;\n      L.rv = L.hasImage ? 1 : RV_MIN;\n      root.style.setProperty(\"--gl-angle\", `${START_ANGLE}deg`);\n      draw();\n      return () => {\n        ro.disconnect();\n      };\n    }\n\n    const frame = (now: number) => {\n      const dt = Math.min((now - last) / 1000, 0.05);\n      last = now;\n      if (isVisibleRef.current) {\n        const L = liveRef.current;\n        L.time += dt * L.speed;\n        L.grow += (1 - L.grow) * Math.min(1, dt * 0.9);\n        L.angle = (L.angle + L.ringSpeed * (L.phase === \"done\" ? 0.5 : 1) * dt) % 360;\n        const target = L.phase === \"done\" && L.hasImage ? 1 : RV_MIN;\n        if (L.snap) L.rv = target;\n        else if (target > L.rv) L.rv = Math.min(target, L.rv + dt / SWEEP_IN);\n        else L.rv = Math.max(target, L.rv - dt / SWEEP_OUT);\n        root.style.setProperty(\"--gl-angle\", `${L.angle.toFixed(2)}deg`);\n        draw();\n        updateDom(L);\n      }\n      rafRef.current = requestAnimationFrame(frame);\n    };\n    rafRef.current = requestAnimationFrame(frame);\n\n    return () => {\n      cancelAnimationFrame(rafRef.current);\n      ro.disconnect();\n    };\n  }, [reduce]);\n\n  const handleRegenerate = () => {\n    if (fixed !== null || reduce) return;\n    onRegenerate?.();\n    setRun((r) => r + 1);\n  };\n\n  const typography: React.CSSProperties = {\n    fontFamily: FONT_FALLBACK,\n    fontWeight: 500,\n    lineHeight: 1.3,\n    ...font,\n    margin: 0,\n  };\n\n  const lines = [...messageList, doneText];\n  const doneIndex = lines.length - 1;\n  const cur = shownPhase === \"done\" ? doneIndex : idx % messageList.length;\n  const shimmerGradient = `linear-gradient(90deg, ${mutedColor} 0%, ${mutedColor} 32%, ${textColor} 50%, ${mutedColor} 68%, ${mutedColor} 100%)`;\n  const softRing = Math.max(2, Math.min(18, ringSize * 0.45));\n  const softBlur = ringSize * 0.7;\n  const ringActive = shownPhase === \"generating\";\n  const statusLine = shownPhase === \"done\" ? doneText : messageList[idx % messageList.length];\n  const alt = source.alt || \"Generated image\";\n  const regionLabel = (ariaLabel || \"AI image generation\").trim();\n\n  const ringNode = (\n    <div\n      aria-hidden=\"true\"\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        zIndex: 3,\n        borderRadius: \"inherit\",\n        pointerEvents: \"none\",\n        opacity: ringActive ? ringIntensity : 0,\n        transition: \"opacity 0.8s ease\",\n      }}\n    >\n      <div ref={ringInnerRef} style={{ position: \"absolute\", inset: 0, borderRadius: \"inherit\", opacity: 0.7 }}>\n        <div style={{ position: \"absolute\", inset: 0, borderRadius: \"inherit\", filter: `blur(${softBlur}px)` }}>\n          <div style={{ ...ringStyle(softRing), background: glowGradient }} />\n        </div>\n        <div style={{ ...ringStyle(1.5), background: glowGradient }} />\n      </div>\n    </div>\n  );\n\n  const maskImage = `linear-gradient(180deg,\n        #000 0%,\n        #000 calc(var(--sy, -${FEATHER}) * 1% - 8%),\n        rgba(0,0,0,0.65) calc(var(--sy, -${FEATHER}) * 1%),\n        transparent calc(var(--sy, -${FEATHER}) * 1% + ${FEATHER}%)\n    )`;\n\n  const revealNode = hasImage ? (\n    <div\n      ref={revealRef}\n      aria-hidden={shownPhase !== \"done\"}\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        zIndex: 0,\n        borderRadius: \"inherit\",\n        overflow: \"hidden\",\n        pointerEvents: \"none\",\n        display: settled && shownPhase !== \"done\" ? \"none\" : \"block\",\n        visibility: settled ? \"visible\" : \"hidden\",\n        ...(settled ? {} : { WebkitMaskImage: maskImage, maskImage }),\n      }}\n    >\n      <img\n        ref={pictureRef}\n        src={source.src}\n        srcSet={source.srcSet}\n        alt={shownPhase === \"done\" ? alt : \"\"}\n        decoding=\"async\"\n        draggable={false}\n        style={{ display: \"block\", width: \"100%\", height: \"100%\", objectFit: \"cover\" }}\n      />\n      <div\n        aria-hidden=\"true\"\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          background: `linear-gradient(180deg, rgba(8,8,10,${(0.62 * scrim).toFixed(3)}) 0%, rgba(8,8,10,${(0.22 * scrim).toFixed(3)}) 22%, rgba(8,8,10,0) 42%)`,\n        }}\n      />\n    </div>\n  ) : null;\n\n  const labelNode = (\n    <div aria-hidden=\"true\" style={{ flex: 1, minWidth: 0, display: \"flex\", alignItems: \"center\", overflow: \"hidden\" }}>\n      <div style={{ display: \"grid\", gridTemplateColumns: \"minmax(0, 1fr)\", width: \"100%\", minWidth: 0 }}>\n        {lines.map((text, i) => {\n          const on = i === cur;\n          const shimmer = i !== doneIndex;\n          return (\n            <div\n              key={i}\n              style={{\n                gridArea: \"1 / 1\",\n                display: \"flex\",\n                alignItems: \"baseline\",\n                minWidth: 0,\n                opacity: on ? 1 : 0,\n                transform: on ? \"translateY(0px)\" : \"translateY(6px)\",\n                transition: `opacity 0.6s ease, transform 0.6s ${EASE}`,\n              }}\n            >\n              <span\n                ref={(el) => {\n                  textEls.current[i] = shimmer ? el : null;\n                }}\n                style={\n                  shimmer\n                    ? {\n                        ...typography,\n                        display: \"block\",\n                        minWidth: 0,\n                        overflow: \"hidden\",\n                        textOverflow: \"ellipsis\",\n                        whiteSpace: \"nowrap\",\n                        color: \"transparent\",\n                        backgroundImage: shimmerGradient,\n                        backgroundSize: \"300% 100%\",\n                        backgroundPosition: `${STATIC_SHIMMER}% 50%`,\n                        WebkitBackgroundClip: \"text\",\n                        backgroundClip: \"text\",\n                        WebkitTextFillColor: \"transparent\",\n                      }\n                    : {\n                        ...typography,\n                        display: \"block\",\n                        minWidth: 0,\n                        overflow: \"hidden\",\n                        textOverflow: \"ellipsis\",\n                        whiteSpace: \"nowrap\",\n                        color: \"#FFFFFF\",\n                      }\n                }\n              >\n                {text}\n              </span>\n            </div>\n          );\n        })}\n      </div>\n    </div>\n  );\n\n  const fadePct = Math.max(0, Math.min(40, edgeFade));\n  const edgeMask = fadePct > 0 ? `linear-gradient(90deg, transparent 0%, #000 ${fadePct}%, #000 ${100 - fadePct}%, transparent 100%)` : undefined;\n\n  return (\n    <div\n      ref={rootRef}\n      role=\"region\"\n      aria-label={regionLabel}\n      aria-busy={shownPhase === \"generating\"}\n      aria-live=\"polite\"\n      aria-atomic=\"true\"\n      className={cn(\"relative box-border h-full w-full overflow-hidden\", className)}\n      style={{\n        ...style,\n        borderRadius: radius,\n        background,\n        backgroundImage: \"linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0) 60%)\",\n        border: `1px solid ${borderColor}`,\n        backdropFilter: \"blur(14px)\",\n        WebkitBackdropFilter: \"blur(14px)\",\n      }}\n    >\n      <h2 style={SR_ONLY}>{regionLabel}</h2>\n      <p role=\"status\" style={SR_ONLY}>\n        {statusLine}\n      </p>\n\n      {revealNode}\n\n      <div style={{ position: \"relative\", zIndex: 1, display: \"flex\", flexDirection: \"column\", gap, boxSizing: \"border-box\", width: \"100%\", height: \"100%\", padding }}>\n        <div style={{ flex: \"none\", minHeight: 34, display: \"flex\", alignItems: \"center\", gap: 12 }}>\n          <div\n            style={{\n              flex: 1,\n              minWidth: 0,\n              display: \"flex\",\n              filter: shownPhase === \"done\" ? \"drop-shadow(0 1px 8px rgba(0,0,0,0.45))\" : \"none\",\n            }}\n          >\n            {labelNode}\n          </div>\n          {shownPhase === \"done\" && (\n            <RoundButton label=\"Generate again\" onClick={handleRegenerate} background=\"rgba(20,20,22,0.45)\" color={textColor}>\n              <RefreshIcon />\n            </RoundButton>\n          )}\n        </div>\n\n        <div\n          ref={visualRef}\n          aria-hidden=\"true\"\n          style={{\n            position: \"relative\",\n            flex: 1,\n            minHeight: 0,\n            width: `calc(100% + ${padding * 2}px)`,\n            marginLeft: -padding,\n            marginRight: -padding,\n          }}\n        >\n          <div style={{ position: \"absolute\", inset: 0, WebkitMaskImage: edgeMask, maskImage: edgeMask }}>\n            <canvas ref={canvasRef} aria-hidden=\"true\" style={{ position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\", display: \"block\" }} />\n          </div>\n        </div>\n      </div>\n\n      {ringNode}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}