{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "transition-glitch-cut",
  "type": "registry:component",
  "title": "Transition Glitch Cut",
  "description": "A hard digital cut: slices of the new view tear in over the old one with jitter, skew and a split color fringe, while scan bars flash across. Over in about half a second.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "transitions",
    "glitch",
    "cut",
    "rgb split",
    "broadcast",
    "transition"
  ],
  "docs": "https://hyperblur.dev/effects/transition-glitch-cut",
  "files": [
    {
      "path": "registry/hyperblur/transition-glitch-cut.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/transition-glitch-cut.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TransitionGlitchCutProps 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  accent?: string;\n  accentAlt?: string;\n}\n\nfunction hash(n: number) {\n  let h = (n ^ 0x2545f491) >>> 0;\n  h = Math.imul(h ^ (h >>> 15), 0x2c1b3c6d) >>> 0;\n  h = Math.imul(h ^ (h >>> 12), 0x297a2d39) >>> 0;\n  return ((h ^ (h >>> 15)) >>> 0) / 4294967295;\n}\n\nconst FRAMES = 11;\n\nfunction frames(name: string, seed: number, incoming: boolean) {\n  const rows: string[] = [];\n  for (let k = 0; k <= FRAMES; k++) {\n    const p = ((k / FRAMES) * 100).toFixed(2);\n    if (k === FRAMES) {\n      rows.push(\n        incoming\n          ? `${p}% { clip-path: inset(0 0 0 0); transform: translate3d(0, 0, 0); filter: none; }`\n          : `${p}% { clip-path: inset(50% 0 50% 0); transform: translate3d(0, 0, 0); filter: none; }`,\n      );\n      continue;\n    }\n    const h1 = hash(seed * 97 + k * 13);\n    const h2 = hash(seed * 31 + k * 7 + 5);\n    const h3 = hash(seed * 53 + k * 19 + 11);\n    const grow = incoming ? k / FRAMES : 1 - k / FRAMES;\n    const band = 8 + grow * 70 + h3 * 18;\n    const top = Math.max(0, Math.min(100 - band, h1 * (100 - band)));\n    const bottom = Math.max(0, 100 - top - band);\n    const full = incoming ? k >= FRAMES - 2 && h2 > 0.4 : k < 2 && h2 > 0.4;\n    const shift = (h2 - 0.5) * 28 * (1 - Math.abs(k / FRAMES - 0.5));\n    const split = 2 + h3 * 5;\n    const clip = full ? \"inset(0 0 0 0)\" : `inset(${top.toFixed(2)}% 0 ${bottom.toFixed(2)}% 0)`;\n    rows.push(\n      `${p}% { clip-path: ${clip}; transform: translate3d(${shift.toFixed(1)}px, 0, 0) skewX(${((h1 - 0.5) * 8).toFixed(2)}deg); filter: drop-shadow(${split.toFixed(1)}px 0 0 var(--hb-vj11-a)) drop-shadow(${(-split).toFixed(1)}px 0 0 var(--hb-vj11-b)); }`,\n    );\n  }\n  return `@keyframes ${name} { ${rows.join(\" \")} }`;\n}\n\nfunction scan(name: string, seed: number) {\n  const rows: string[] = [];\n  for (let k = 0; k <= FRAMES; k++) {\n    const p = ((k / FRAMES) * 100).toFixed(2);\n    const h = hash(seed * 71 + k * 29);\n    const on = k > 0 && k < FRAMES && h > 0.35;\n    rows.push(`${p}% { opacity: ${on ? (0.5 + h * 0.5).toFixed(2) : \"0\"}; top: ${(h * 92).toFixed(1)}%; height: ${(2 + hash(k * 3 + seed) * 9).toFixed(1)}%; }`);\n  }\n  return `@keyframes ${name} { ${rows.join(\" \")} }`;\n}\n\nconst css = `\n.hb-vj11 {\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: #000000;\n}\n.hb-vj11 *, .hb-vj11 *::before, .hb-vj11 *::after { box-sizing: border-box; }\n.hb-vj11-l {\n  grid-area: 1 / 1;\n  display: grid;\n  min-width: 0;\n  min-height: 0;\n  z-index: 1;\n  visibility: hidden;\n  transition: visibility 0s linear var(--hb-vj11-d);\n}\n.hb-vj11-l[data-on=\"true\"] {\n  z-index: 2;\n  visibility: visible;\n  transition: visibility 0s linear 0s;\n}\n.hb-vj11[data-ran=\"true\"] .hb-vj11-l[data-on=\"true\"] { animation: hb-vj11-in var(--hb-vj11-d) steps(1, end) both; }\n.hb-vj11[data-ran=\"true\"] .hb-vj11-l[data-on=\"false\"] { animation: hb-vj11-out var(--hb-vj11-d) steps(1, end) both; }\n.hb-vj11-bar {\n  position: absolute;\n  left: 0;\n  right: 0;\n  z-index: 3;\n  pointer-events: none;\n  opacity: 0;\n  background:\n    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.9) 0 3px, transparent 3px 7px, color-mix(in srgb, var(--hb-vj11-a) 80%, transparent) 7px 19px, transparent 19px 26px),\n    linear-gradient(90deg, var(--hb-vj11-b), var(--hb-vj11-a));\n  mix-blend-mode: screen;\n}\n.hb-vj11-bar + .hb-vj11-bar { mix-blend-mode: difference; background: #ffffff; }\n.hb-vj11-noise {\n  position: absolute;\n  inset: 0;\n  z-index: 3;\n  pointer-events: none;\n  opacity: 0;\n  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 3px);\n}\n.hb-vj11[data-ran=\"true\"][data-active=\"true\"] .hb-vj11-bar { animation: hb-vj11-s1a var(--hb-vj11-d) steps(1, end) both; }\n.hb-vj11[data-ran=\"true\"][data-active=\"false\"] .hb-vj11-bar { animation: hb-vj11-s1b var(--hb-vj11-d) steps(1, end) both; }\n.hb-vj11[data-ran=\"true\"][data-active=\"true\"] .hb-vj11-bar + .hb-vj11-bar { animation-name: hb-vj11-s2a; }\n.hb-vj11[data-ran=\"true\"][data-active=\"false\"] .hb-vj11-bar + .hb-vj11-bar { animation-name: hb-vj11-s2b; }\n.hb-vj11[data-ran=\"true\"][data-active=\"true\"] .hb-vj11-noise { animation: hb-vj11-na var(--hb-vj11-d) linear both; }\n.hb-vj11[data-ran=\"true\"][data-active=\"false\"] .hb-vj11-noise { animation: hb-vj11-nb var(--hb-vj11-d) linear both; }\n@keyframes hb-vj11-na { 0% { opacity: 0; } 10% { opacity: 1; } 80% { opacity: 0.6; } 100% { opacity: 0; } }\n@keyframes hb-vj11-nb { 0% { opacity: 0; } 10% { opacity: 1; } 80% { opacity: 0.6; } 100% { opacity: 0; } }\n${frames(\"hb-vj11-in\", 3, true)}\n${frames(\"hb-vj11-out\", 8, false)}\n${scan(\"hb-vj11-s1a\", 2)}\n${scan(\"hb-vj11-s1b\", 2)}\n${scan(\"hb-vj11-s2a\", 6)}\n${scan(\"hb-vj11-s2b\", 6)}\n@media (prefers-reduced-motion: reduce) {\n  .hb-vj11-l, .hb-vj11-l[data-on=\"true\"] { transition: none; }\n  .hb-vj11[data-ran=\"true\"] .hb-vj11-l[data-on=\"true\"],\n  .hb-vj11[data-ran=\"true\"] .hb-vj11-l[data-on=\"false\"],\n  .hb-vj11[data-ran=\"true\"] .hb-vj11-bar,\n  .hb-vj11[data-ran=\"true\"] .hb-vj11-noise { animation: none !important; }\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 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 TransitionGlitchCut({\n  children,\n  from,\n  to,\n  active,\n  defaultActive = false,\n  onActiveChange,\n  autoPlay = false,\n  interval = 2400,\n  duration = 560,\n  accent = \"#ff2e63\",\n  accentAlt = \"#22d3ee\",\n  className,\n  style,\n  ...rest\n}: TransitionGlitchCutProps) {\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, #1a1033, #07050d)\" kicker=\"Channel 07\" title=\"Night market, live\" />;\n  const b = to ?? kids[1] ?? <Scene tone=\"linear-gradient(160deg, #0d2a24, #040a09)\" kicker=\"Channel 08\" title=\"Harbor cam\" />;\n\n  const vars = {\n    \"--hb-vj11-d\": `${duration}ms`,\n    \"--hb-vj11-a\": accent,\n    \"--hb-vj11-b\": accentAlt,\n  } as React.CSSProperties;\n\n  return (\n    <div className={[\"hb-vj11\", className].filter(Boolean).join(\" \")} style={{ ...vars, ...style }} data-active={value} data-ran={ran} {...rest}>\n      <style href=\"hb-transition-glitch-cut\" precedence=\"default\">{css}</style>\n      <div className=\"hb-vj11-l\" data-on={!value} aria-hidden={value} inert={value}>{a}</div>\n      <div className=\"hb-vj11-l\" data-on={value} aria-hidden={!value} inert={!value}>{b}</div>\n      <div className=\"hb-vj11-noise\" aria-hidden=\"true\" />\n      <div className=\"hb-vj11-bar\" aria-hidden=\"true\" />\n      <div className=\"hb-vj11-bar\" aria-hidden=\"true\" />\n    </div>\n  );\n}\n"
    }
  ]
}