{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "transition-split-flap",
  "type": "registry:component",
  "title": "Transition Split Flap",
  "description": "The view is cut into flaps hinged at the middle, like a station board. Each column drops its top half in turn, left to right, and settles with a small bounce.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "transitions",
    "split flap",
    "departures",
    "board",
    "3d",
    "transition"
  ],
  "docs": "https://hyperblur.dev/effects/transition-split-flap",
  "files": [
    {
      "path": "registry/hyperblur/transition-split-flap.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/transition-split-flap.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TransitionSplitFlapProps 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  stagger?: number;\n  columns?: number;\n}\n\nconst css = `\n.hb-vj9 {\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: #050506;\n}\n.hb-vj9 *, .hb-vj9 *::before, .hb-vj9 *::after { box-sizing: border-box; }\n.hb-vj9-l {\n  grid-area: 1 / 1;\n  display: grid;\n  min-width: 0;\n  min-height: 0;\n  position: relative;\n  z-index: 2;\n  visibility: hidden;\n  transition: visibility 0s linear 0s;\n}\n.hb-vj9-l[data-on=\"true\"] {\n  visibility: visible;\n  transition: visibility 0s linear var(--hb-vj9-t);\n}\n.hb-vj9-board {\n  position: absolute;\n  inset: 0;\n  z-index: 1;\n  pointer-events: none;\n}\n.hb-vj9-col {\n  position: absolute;\n  inset: 0;\n  perspective: 720px;\n}\n.hb-vj9-piece {\n  position: absolute;\n  inset: 0;\n  display: grid;\n}\n.hb-vj9-piece > .hb-vj9-c { display: grid; min-width: 0; min-height: 0; }\n.hb-vj9-flap {\n  position: absolute;\n  inset: 0;\n  transform-style: preserve-3d;\n  transform-origin: 50% 50%;\n  transform: rotateX(-180deg);\n}\n.hb-vj9[data-ran=\"true\"][data-active=\"true\"] .hb-vj9-flap { animation: hb-vj9-flip-a var(--hb-vj9-d) cubic-bezier(0.55, 0, 0.32, 1.22) var(--hb-vj9-in) both; }\n.hb-vj9[data-ran=\"true\"][data-active=\"false\"] .hb-vj9-flap { animation: hb-vj9-flip-b var(--hb-vj9-d) cubic-bezier(0.55, 0, 0.32, 1.22) var(--hb-vj9-in) both; }\n@keyframes hb-vj9-flip-a { from { transform: rotateX(0deg); } to { transform: rotateX(-180deg); } }\n@keyframes hb-vj9-flip-b { from { transform: rotateX(0deg); } to { transform: rotateX(-180deg); } }\n.hb-vj9-face {\n  position: absolute;\n  inset: 0;\n  display: grid;\n  -webkit-backface-visibility: hidden;\n  backface-visibility: hidden;\n}\n.hb-vj9-face[data-face=\"back\"] { transform: rotateX(180deg); }\n.hb-vj9-face > .hb-vj9-c { display: grid; min-width: 0; min-height: 0; }\n.hb-vj9-face::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  pointer-events: none;\n  opacity: 0;\n}\n.hb-vj9-face[data-face=\"front\"]::after { background: linear-gradient(180deg, rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.7) 50%); }\n.hb-vj9-face[data-face=\"back\"]::after { background: linear-gradient(0deg, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.65) 50%); }\n.hb-vj9[data-ran=\"true\"][data-active=\"true\"] .hb-vj9-face[data-face=\"front\"]::after { animation: hb-vj9-dim-a var(--hb-vj9-d) ease-in var(--hb-vj9-in) both; }\n.hb-vj9[data-ran=\"true\"][data-active=\"false\"] .hb-vj9-face[data-face=\"front\"]::after { animation: hb-vj9-dim-b var(--hb-vj9-d) ease-in var(--hb-vj9-in) both; }\n.hb-vj9[data-ran=\"true\"][data-active=\"true\"] .hb-vj9-face[data-face=\"back\"]::after { animation: hb-vj9-lit-a var(--hb-vj9-d) ease-out var(--hb-vj9-in) both; }\n.hb-vj9[data-ran=\"true\"][data-active=\"false\"] .hb-vj9-face[data-face=\"back\"]::after { animation: hb-vj9-lit-b var(--hb-vj9-d) ease-out var(--hb-vj9-in) both; }\n@keyframes hb-vj9-dim-a { from { opacity: 0; } to { opacity: 1; } }\n@keyframes hb-vj9-dim-b { from { opacity: 0; } to { opacity: 1; } }\n@keyframes hb-vj9-lit-a { from { opacity: 1; } to { opacity: 0; } }\n@keyframes hb-vj9-lit-b { from { opacity: 1; } to { opacity: 0; } }\n.hb-vj9-under {\n  position: absolute;\n  inset: 0;\n  pointer-events: none;\n  opacity: 0;\n  background: linear-gradient(0deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0) 50%);\n}\n.hb-vj9[data-ran=\"true\"][data-active=\"true\"] .hb-vj9-under { animation: hb-vj9-dim-a var(--hb-vj9-d) ease-in var(--hb-vj9-in) both; }\n.hb-vj9[data-ran=\"true\"][data-active=\"false\"] .hb-vj9-under { animation: hb-vj9-dim-b var(--hb-vj9-d) ease-in var(--hb-vj9-in) both; }\n.hb-vj9-hinge {\n  position: absolute;\n  left: 0;\n  right: 0;\n  top: 50%;\n  height: 2px;\n  margin-top: -1px;\n  background: linear-gradient(180deg, rgba(0, 0, 0, 0.85), rgba(255, 255, 255, 0.07));\n  pointer-events: none;\n}\n.hb-vj9-seam {\n  position: absolute;\n  top: 0;\n  bottom: 0;\n  width: 2px;\n  margin-left: -1px;\n  background: rgba(0, 0, 0, 0.8);\n  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.05);\n  pointer-events: none;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-vj9-l, .hb-vj9-l[data-on=\"true\"] { transition: none; }\n  .hb-vj9[data-ran=\"true\"] .hb-vj9-flap,\n  .hb-vj9[data-ran=\"true\"] .hb-vj9-face::after,\n  .hb-vj9[data-ran=\"true\"] .hb-vj9-under { 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: \"center\", 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: 22, fontWeight: 600, letterSpacing: \"0.02em\" }}>{title}</strong>\n    </div>\n  );\n}\n\nconst pct = (n: number) => `${n.toFixed(3)}%`;\n\nexport function TransitionSplitFlap({\n  children,\n  from,\n  to,\n  active,\n  defaultActive = false,\n  onActiveChange,\n  autoPlay = false,\n  interval = 2800,\n  duration = 620,\n  stagger = 90,\n  columns = 4,\n  className,\n  style,\n  ...rest\n}: TransitionSplitFlapProps) {\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=\"#141416\" kicker=\"Gate B12\" title=\"LISBON 08:40\" />;\n  const b = to ?? kids[1] ?? <Scene tone=\"#141416\" kicker=\"Gate C03\" title=\"TOKYO 09:15\" />;\n  const oldView = value ? a : b;\n  const newView = value ? b : a;\n  const n = Math.max(1, Math.round(columns));\n  const total = duration + (n - 1) * stagger;\n\n  const vars = {\n    \"--hb-vj9-d\": `${duration}ms`,\n    \"--hb-vj9-t\": `${total}ms`,\n  } as React.CSSProperties;\n\n  const cols = Array.from({ length: n }, (_, i) => {\n    const l = (i / n) * 100;\n    const r = 100 - ((i + 1) / n) * 100;\n    const top = `inset(0% ${pct(r)} 50% ${pct(l)})`;\n    const bottom = `inset(50% ${pct(r)} 0% ${pct(l)})`;\n    const colVars = {\n      perspectiveOrigin: `${pct(l + 50 / n)} 50%`,\n      \"--hb-vj9-in\": `${i * stagger}ms`,\n    } as React.CSSProperties;\n    return (\n      <div key={i} className=\"hb-vj9-col\" style={colVars}>\n        <div className=\"hb-vj9-piece\" style={{ clipPath: top }}>\n          <div className=\"hb-vj9-c\">{newView}</div>\n        </div>\n        <div className=\"hb-vj9-piece\" style={{ clipPath: bottom }}>\n          <div className=\"hb-vj9-c\">{oldView}</div>\n          <div className=\"hb-vj9-under\" />\n        </div>\n        <div className=\"hb-vj9-flap\">\n          <div className=\"hb-vj9-face\" data-face=\"front\" style={{ clipPath: top }}>\n            <div className=\"hb-vj9-c\">{oldView}</div>\n          </div>\n          <div className=\"hb-vj9-face\" data-face=\"back\" style={{ clipPath: bottom }}>\n            <div className=\"hb-vj9-c\">{newView}</div>\n          </div>\n        </div>\n      </div>\n    );\n  });\n\n  return (\n    <div className={[\"hb-vj9\", className].filter(Boolean).join(\" \")} style={{ ...vars, ...style }} data-active={value} data-ran={ran} {...rest}>\n      <style href=\"hb-transition-split-flap\" precedence=\"default\">{css}</style>\n      <div className=\"hb-vj9-board\" aria-hidden=\"true\" inert>\n        {cols}\n        <div className=\"hb-vj9-hinge\" />\n        {Array.from({ length: n - 1 }, (_, i) => (\n          <div key={i} className=\"hb-vj9-seam\" style={{ left: pct(((i + 1) / n) * 100) }} />\n        ))}\n      </div>\n      <div className=\"hb-vj9-l\" data-on={!value} aria-hidden={value} inert={value}>{a}</div>\n      <div className=\"hb-vj9-l\" data-on={value} aria-hidden={!value} inert={!value}>{b}</div>\n    </div>\n  );\n}\n"
    }
  ]
}