{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"mist-reveal","type":"registry:component","title":"Mist reveal","description":"The calm wait for a generated image: a slow band of colour drifts while it works, then the mist moves off and the picture sharpens into place.","author":"Hairline UI","dependencies":[],"registryDependencies":["https://hairlineui.com/r/number-roll.json?as=dependency"],"files":[{"path":"registry/mist-reveal.tsx","type":"registry:component","content":"// Hairline UI · mist-reveal · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\n/* ─────────────────────────────────────────────────────────\n * MIST REVEAL: the calm wait for a generated image\n *\n * While your generation runs, a slow band of the theme's chart\n * colours drifts through a quiet well. When the image is ready\n * and has really loaded, the mist moves off towards a corner\n * and the picture sharpens out of a soft blur in the same move.\n * It follows your status, never a timer.\n * ───────────────────────────────────────────────────────── */\n\nimport * as React from \"react\";\nimport { Announce, ErrorFace, ProgressTag, frameClass, useArrival, useNextFrame, useReducedMotion, type RevealProps } from \"./image-arrival\";\n\nexport type { GenerationStatus, RevealLabels } from \"./image-arrival\";\nexport type MistRevealProps = RevealProps;\n\nconst EASE = \"cubic-bezier(0.16, 1, 0.3, 1)\";\nconst REVEAL = 1100;\n\nconst BAND =\n  \"linear-gradient(115deg, transparent 22%, color-mix(in oklab, var(--chart-1) 60%, transparent) 38%, color-mix(in oklab, var(--chart-2) 55%, transparent) 50%, color-mix(in oklab, var(--chart-4) 55%, transparent) 62%, transparent 78%)\";\n\nexport function MistReveal({ src, status, progress, alt, crossOrigin, onReady, onRetry, labels, className }: MistRevealProps) {\n  const reduced = useReducedMotion();\n  const { phase, onLoad, onError, imageRef, finish } = useArrival(src, status, onReady);\n  const revealing = phase === \"revealing\";\n  const go = useNextFrame(revealing && !reduced);\n\n  React.useEffect(() => {\n    if (!revealing) return;\n    const id = window.setTimeout(finish, reduced ? 0 : REVEAL);\n    return () => window.clearTimeout(id);\n  }, [revealing, reduced, finish]);\n\n  const showing = phase === \"shown\" || (revealing && (go || reduced));\n  const misty = phase === \"waiting\" || (revealing && !go && !reduced);\n\n  return (\n    <figure className={frameClass(className)} aria-busy={phase === \"waiting\"}>\n      {src && (\n        // eslint-disable-next-line @next/next/no-img-element\n        <img\n          ref={imageRef}\n          key={src}\n          src={src}\n          alt={alt}\n          crossOrigin={crossOrigin}\n          onLoad={onLoad}\n          onError={onError}\n          draggable={false}\n          className=\"absolute inset-0 size-full object-cover\"\n          style={{\n            opacity: showing ? 1 : 0,\n            filter: showing ? \"blur(0px)\" : \"blur(14px)\",\n            transform: showing ? \"scale(1)\" : \"scale(1.06)\",\n            transition: revealing && !reduced ? `opacity 600ms ease-out, filter ${REVEAL}ms ${EASE}, transform ${REVEAL + 100}ms ${EASE}` : \"none\",\n          }}\n        />\n      )}\n      {(phase === \"waiting\" || revealing) && (\n        <div\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute -inset-[30%]\"\n          style={{\n            opacity: misty ? 0.75 : 0,\n            transform: misty ? \"translate3d(0,0,0) scale(1)\" : \"translate3d(32%,28%,0) scale(1.2)\",\n            transition: revealing ? `opacity ${REVEAL - 200}ms ease-out, transform ${REVEAL}ms ${EASE}` : \"none\",\n          }}\n        >\n          <div className=\"absolute inset-0\" style={{ background: BAND, filter: \"blur(28px)\", animation: reduced ? \"none\" : \"ui-mist-drift 4.6s ease-in-out infinite alternate\" }} />\n        </div>\n      )}\n      {phase === \"waiting\" && <ProgressTag progress={progress} label={labels?.generating ?? \"Generating\"} />}\n      {phase === \"error\" && <ErrorFace labels={labels} onRetry={onRetry} />}\n      <Announce phase={phase} labels={labels} />\n    </figure>\n  );\n}\n"},{"path":"registry/image-arrival.tsx","type":"registry:component","content":"// Hairline UI · mist-reveal · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\n/* ─────────────────────────────────────────────────────────\n * IMAGE ARRIVAL: what the four reveals share.\n *\n * A reveal follows your app's real state, never a timer: it\n * waits while `status` is \"generating\", and it only plays once\n * `status` is \"ready\" and the picture has actually loaded and\n * decoded. An image that was already there when the page loaded\n * is simply shown. \"error\", or a picture that fails to load,\n * shows a failure with Try again.\n * ───────────────────────────────────────────────────────── */\n\nimport * as React from \"react\";\nimport { RotateCcw } from \"lucide-react\";\nimport { NumberRoll } from \"./number-roll\";\n\nexport type GenerationStatus = \"generating\" | \"ready\" | \"error\";\n\nexport interface RevealLabels {\n  generating?: string;\n  ready?: string;\n  failed?: string;\n  retry?: string;\n}\n\nexport interface RevealProps {\n  /** The generated image. It can arrive before or with status \"ready\". */\n  src?: string;\n  /** Your generation's real state. */\n  status: GenerationStatus;\n  /** 0 to 1, if your API reports it. Without it no figure is shown and nothing pretends to know. */\n  progress?: number;\n  alt: string;\n  /** Pass \"anonymous\" when your image host sends CORS headers (needed for pixel effects; others work without). */\n  crossOrigin?: \"anonymous\" | \"use-credentials\";\n  /** Called once the reveal has played (or the image is shown). */\n  onReady?: () => void;\n  /** Shows Try again on failure. */\n  onRetry?: () => void;\n  labels?: RevealLabels;\n  /** Size the frame here, e.g. \"aspect-square w-72\". */\n  className?: string;\n}\n\nexport type ArrivalPhase = \"waiting\" | \"revealing\" | \"shown\" | \"error\";\n\nconst reducedQuery = \"(prefers-reduced-motion: reduce)\";\nconst subscribeReduced = (onChange: () => void) => {\n  const query = window.matchMedia(reducedQuery);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n};\nexport const useReducedMotion = () => React.useSyncExternalStore(subscribeReduced, () => window.matchMedia(reducedQuery).matches, () => false);\n\n/** The phase a reveal is in, and the handlers its <img> needs. Call `finish` when the reveal has played. */\nexport function useArrival(src: string | undefined, status: GenerationStatus, onReady?: () => void) {\n  const [loaded, setLoaded] = React.useState<string | null>(null);\n  const [broken, setBroken] = React.useState<string | null>(null);\n  const [played, setPlayed] = React.useState<string | null>(null);\n  // Only an image seen generating in this mount is revealed; one that was already there is just shown.\n  const [armed, setArmed] = React.useState(status === \"generating\");\n  const [seen, setSeen] = React.useState(status);\n  if (status !== seen) {\n    setSeen(status);\n    if (status === \"generating\") {\n      setArmed(true);\n      setPlayed(null);\n    }\n  }\n\n  const failed = status === \"error\" || (status === \"ready\" && !!src && broken === src);\n  const arrived = status === \"ready\" && !!src && loaded === src;\n  const phase: ArrivalPhase = failed ? \"error\" : !arrived ? \"waiting\" : !armed || played === src ? \"shown\" : \"revealing\";\n\n  const ready = React.useRef(onReady);\n  React.useLayoutEffect(() => {\n    ready.current = onReady;\n  });\n  React.useEffect(() => {\n    if (phase === \"shown\") ready.current?.();\n  }, [phase]);\n\n  const settle = React.useCallback(\n    (img: HTMLImageElement) => {\n      const url = src ?? null;\n      (img.decode ? img.decode() : Promise.resolve()).catch(() => undefined).then(() => setLoaded(url));\n    },\n    [src],\n  );\n  const onLoad = (event: React.SyntheticEvent<HTMLImageElement>) => settle(event.currentTarget);\n  const onError = () => setBroken(src ?? null);\n  // A server-rendered image can finish loading before React attaches onLoad; catch that when the element arrives.\n  const imageRef = React.useCallback(\n    (img: HTMLImageElement | null) => {\n      if (!img || !img.complete) return;\n      if (img.naturalWidth) settle(img);\n      else setBroken(src ?? null);\n    },\n    [settle, src],\n  );\n  const finish = React.useCallback(() => setPlayed(src ?? null), [src]);\n  return { phase, onLoad, onError, imageRef, finish };\n}\n\n/** Two frames later, so a starting state is painted before it changes. */\nexport function useNextFrame(active: boolean) {\n  const [go, setGo] = React.useState(false);\n  if (!active && go) setGo(false);\n  React.useEffect(() => {\n    if (!active) return;\n    let second = 0;\n    const first = requestAnimationFrame(() => {\n      second = requestAnimationFrame(() => setGo(true));\n    });\n    return () => {\n      cancelAnimationFrame(first);\n      cancelAnimationFrame(second);\n    };\n  }, [active]);\n  return active && go;\n}\n\n/** The figure's progress, in a small tag at its foot, only when your API reports a number. */\nexport function ProgressTag({ progress, label }: { progress?: number; label: string }) {\n  if (progress == null || !Number.isFinite(progress)) return null;\n  const pct = Math.round(Math.min(1, Math.max(0, progress)) * 100);\n  return (\n    <span className=\"pointer-events-none absolute bottom-3 left-3 z-10 inline-flex h-6 items-center gap-1.5 rounded-full bg-background/90 px-2.5 text-[11.5px] font-medium text-foreground ring-1 ring-border tabular-nums\">\n      {label}\n      <span aria-hidden=\"true\" className=\"text-muted-foreground\">\n        <NumberRoll value={pct} suffix=\"%\" duration={500} />\n      </span>\n    </span>\n  );\n}\n\n/** What a failed generation shows: what happened, and Try again when the app can retry. */\nexport function ErrorFace({ labels, onRetry }: { labels?: RevealLabels; onRetry?: () => void }) {\n  return (\n    <div className=\"absolute inset-0 z-10 flex flex-col items-center justify-center gap-3 bg-muted p-6 text-center\">\n      <p className=\"max-w-[16rem] text-[13px] leading-snug text-muted-foreground\">{labels?.failed ?? \"This image couldn’t be created.\"}</p>\n      {onRetry && (\n        <button\n          type=\"button\"\n          onClick={onRetry}\n          className=\"inline-flex h-8 cursor-pointer items-center gap-1.5 rounded-full bg-background px-3 text-[12.5px] font-medium text-foreground ring-1 ring-border transition-[background-color,scale] duration-150 hover:bg-accent active:scale-[0.97] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50\"\n        >\n          <RotateCcw className=\"size-3.5\" aria-hidden=\"true\" />\n          {labels?.retry ?? \"Try again\"}\n        </button>\n      )}\n    </div>\n  );\n}\n\n/** The sentence a screen reader hears when the phase changes. */\nexport function Announce({ phase, labels }: { phase: ArrivalPhase; labels?: RevealLabels }) {\n  const text = phase === \"waiting\" ? labels?.generating ?? \"Generating image\" : phase === \"error\" ? labels?.failed ?? \"This image couldn’t be created.\" : labels?.ready ?? \"Image ready\";\n  return (\n    <span role=\"status\" className=\"sr-only\">\n      {text}\n    </span>\n  );\n}\n\n/** The frame: full width unless your className sets one (the default has no specificity, so any width class wins). */\nexport const frameClass = (className = \"\") => `relative isolate [:where(&)]:w-full overflow-hidden rounded-[18px] bg-muted ${className}`;\n"}],"css":{"@keyframes ui-mist-drift":{"from":{"transform":"translate3d(-16%, -9%, 0) rotate(-4deg)"},"to":{"transform":"translate3d(16%, 9%, 0) rotate(4deg)"}}},"docs":"Docs and live preview: https://hairlineui.com/ui/mist-reveal. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}