{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "transition-pixel-dissolve",
  "type": "registry:component",
  "title": "Transition Pixel Dissolve",
  "description": "A grid of square cells blinks on in a diagonal, slightly scattered order, flashing the accent before going solid. The views swap behind the grid and the cells drop away in a second wave.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "transitions",
    "pixel",
    "dissolve",
    "grid",
    "retro",
    "transition"
  ],
  "docs": "https://hyperblur.dev/effects/transition-pixel-dissolve",
  "files": [
    {
      "path": "registry/hyperblur/transition-pixel-dissolve.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/transition-pixel-dissolve.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TransitionPixelDissolveProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n  children?: React.ReactNode;\n  from?: React.ReactNode;\n  to?: React.ReactNode;\n  active?: boolean;\n  defaultActive?: boolean;\n  onActiveChange?: (active: boolean) => void;\n  autoPlay?: boolean;\n  interval?: number;\n  duration?: number;\n  columns?: number;\n  rows?: number;\n  accent?: string;\n  cover?: string;\n}\n\nconst css = `\n.hb-vj3 {\n  position: relative;\n  display: grid;\n  grid-template: minmax(0, 1fr) / minmax(0, 1fr);\n  overflow: hidden;\n  isolation: isolate;\n  box-sizing: border-box;\n  font-family: inherit;\n  background: var(--hb-vj3-cov);\n}\n.hb-vj3 *, .hb-vj3 *::before, .hb-vj3 *::after { box-sizing: border-box; }\n.hb-vj3-l {\n  grid-area: 1 / 1;\n  display: grid;\n  min-width: 0;\n  min-height: 0;\n  visibility: hidden;\n  transition: visibility 0s linear calc(var(--hb-vj3-d) * 0.5);\n}\n.hb-vj3-l[data-on=\"true\"] { visibility: visible; }\n.hb-vj3-grid {\n  position: absolute;\n  inset: 0;\n  z-index: 2;\n  display: grid;\n  grid-template-columns: repeat(var(--hb-vj3-c), 1fr);\n  grid-template-rows: repeat(var(--hb-vj3-r), 1fr);\n  pointer-events: none;\n}\n.hb-vj3-px {\n  opacity: 0;\n  background: var(--hb-vj3-cov);\n  transform: scale(1.04);\n}\n.hb-vj3[data-ran=\"true\"][data-active=\"true\"] .hb-vj3-px {\n  animation:\n    hb-vj3-in-a var(--hb-vj3-seg) cubic-bezier(0.3, 0.7, 0.2, 1) var(--hb-vj3-t1) both,\n    hb-vj3-out-a var(--hb-vj3-seg) cubic-bezier(0.6, 0, 0.8, 0.4) var(--hb-vj3-t2) forwards;\n}\n.hb-vj3[data-ran=\"true\"][data-active=\"false\"] .hb-vj3-px {\n  animation:\n    hb-vj3-in-b var(--hb-vj3-seg) cubic-bezier(0.3, 0.7, 0.2, 1) var(--hb-vj3-t1) both,\n    hb-vj3-out-b var(--hb-vj3-seg) cubic-bezier(0.6, 0, 0.8, 0.4) var(--hb-vj3-t2) forwards;\n}\n@keyframes hb-vj3-in-a {\n  0% { opacity: 0; transform: scale(0.35); background: var(--hb-vj3-acc); }\n  55% { opacity: 1; transform: scale(1.04); background: var(--hb-vj3-acc); }\n  100% { opacity: 1; transform: scale(1.04); background: var(--hb-vj3-cov); }\n}\n@keyframes hb-vj3-out-a {\n  0% { opacity: 1; transform: scale(1.04); background: var(--hb-vj3-cov); }\n  45% { opacity: 1; background: var(--hb-vj3-soft); }\n  100% { opacity: 0; transform: scale(0.35); background: var(--hb-vj3-soft); }\n}\n@keyframes hb-vj3-in-b {\n  0% { opacity: 0; transform: scale(0.35); background: var(--hb-vj3-acc); }\n  55% { opacity: 1; transform: scale(1.04); background: var(--hb-vj3-acc); }\n  100% { opacity: 1; transform: scale(1.04); background: var(--hb-vj3-cov); }\n}\n@keyframes hb-vj3-out-b {\n  0% { opacity: 1; transform: scale(1.04); background: var(--hb-vj3-cov); }\n  45% { opacity: 1; background: var(--hb-vj3-soft); }\n  100% { opacity: 0; transform: scale(0.35); background: var(--hb-vj3-soft); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-vj3-l { transition: none; }\n  .hb-vj3[data-ran=\"true\"][data-active=\"true\"] .hb-vj3-px,\n  .hb-vj3[data-ran=\"true\"][data-active=\"false\"] .hb-vj3-px { animation: none; }\n}\n`;\n\nfunction useSwap(\n  active: boolean | undefined,\n  defaultActive: boolean,\n  onActiveChange: ((active: boolean) => void) | undefined,\n  autoPlay: boolean,\n  interval: number,\n) {\n  const [inner, setInner] = React.useState(defaultActive);\n  const controlled = active !== undefined;\n  const value = controlled ? active : inner;\n  const set = React.useCallback(\n    (next: boolean) => {\n      if (!controlled) setInner(next);\n      onActiveChange?.(next);\n    },\n    [controlled, onActiveChange],\n  );\n  React.useEffect(() => {\n    if (!autoPlay) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const id = window.setTimeout(() => set(!value), interval);\n    return () => window.clearTimeout(id);\n  }, [autoPlay, interval, value, set]);\n  return value;\n}\n\nfunction hash(n: number) {\n  let h = (n ^ 0x9e3779b9) >>> 0;\n  h = Math.imul(h ^ (h >>> 16), 0x85ebca6b) >>> 0;\n  h = Math.imul(h ^ (h >>> 13), 0xc2b2ae35) >>> 0;\n  return ((h ^ (h >>> 16)) >>> 0) / 4294967295;\n}\n\nfunction Scene({ tone, kicker, title }: { tone: string; kicker: string; title: string }) {\n  return (\n    <div style={{ display: \"grid\", alignContent: \"end\", gap: 4, padding: 20, minHeight: 180, background: tone, color: \"#ededed\" }}>\n      <span style={{ fontSize: 11, letterSpacing: \"0.14em\", textTransform: \"uppercase\", color: \"rgba(237,237,237,0.6)\" }}>{kicker}</span>\n      <strong style={{ fontSize: 20, fontWeight: 600, letterSpacing: \"-0.01em\" }}>{title}</strong>\n    </div>\n  );\n}\n\nexport function TransitionPixelDissolve({\n  children,\n  from,\n  to,\n  active,\n  defaultActive = false,\n  onActiveChange,\n  autoPlay = false,\n  interval = 2800,\n  duration = 1300,\n  columns = 14,\n  rows = 8,\n  accent = \"#2f7bff\",\n  cover = \"#08090c\",\n  className,\n  style,\n  ...rest\n}: TransitionPixelDissolveProps) {\n  const value = useSwap(active, defaultActive, onActiveChange, autoPlay, interval);\n  const [prev, setPrev] = React.useState(value);\n  const [ran, setRan] = React.useState(false);\n  if (prev !== value) {\n    setPrev(value);\n    setRan(true);\n  }\n  const kids = React.Children.toArray(children);\n  const a = from ?? kids[0] ?? <Scene tone=\"linear-gradient(160deg, #0f3b3a, #071312)\" kicker=\"Lisbon\" title=\"21° and clear\" />;\n  const b = to ?? kids[1] ?? <Scene tone=\"linear-gradient(160deg, #1e2a44, #090c14)\" kicker=\"Reykjavik\" title=\"4° with sleet\" />;\n  const c = Math.max(2, Math.round(columns));\n  const r = Math.max(2, Math.round(rows));\n  const seg = duration * 0.16;\n\n  const vars = {\n    \"--hb-vj3-d\": `${duration}ms`,\n    \"--hb-vj3-seg\": `${seg.toFixed(0)}ms`,\n    \"--hb-vj3-c\": c,\n    \"--hb-vj3-r\": r,\n    \"--hb-vj3-acc\": accent,\n    \"--hb-vj3-soft\": `color-mix(in srgb, ${accent} 35%, ${cover})`,\n    \"--hb-vj3-cov\": cover,\n  } as React.CSSProperties;\n\n  const cells = Array.from({ length: c * r }, (_, i) => {\n    const col = i % c;\n    const row = Math.floor(i / c);\n    const diag = (col / (c - 1) + row / (r - 1)) / 2;\n    const o1 = 0.6 * diag + 0.4 * hash(i * 7 + 3);\n    const o2 = 0.6 * diag + 0.4 * hash(i * 13 + 11);\n    const t1 = o1 * duration * 0.32;\n    const t2 = duration * 0.52 + o2 * duration * 0.32;\n    return (\n      <span\n        key={i}\n        className=\"hb-vj3-px\"\n        style={{ \"--hb-vj3-t1\": `${t1.toFixed(0)}ms`, \"--hb-vj3-t2\": `${t2.toFixed(0)}ms` } as React.CSSProperties}\n      />\n    );\n  });\n\n  return (\n    <div className={[\"hb-vj3\", className].filter(Boolean).join(\" \")} style={{ ...vars, ...style }} data-active={value} data-ran={ran} {...rest}>\n      <style href=\"hb-transition-pixel-dissolve\" precedence=\"default\">{css}</style>\n      <div className=\"hb-vj3-l\" data-on={!value} aria-hidden={value} inert={value}>{a}</div>\n      <div className=\"hb-vj3-l\" data-on={value} aria-hidden={!value} inert={!value}>{b}</div>\n      <div className=\"hb-vj3-grid\" aria-hidden=\"true\">{cells}</div>\n    </div>\n  );\n}\n"
    }
  ]
}