{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"departure-board","type":"registry:ui","title":"Departure Board","description":"An airport departures board: every tile flips through the drum until it lands on the next word.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/departure-board.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef, useState, type CSSProperties } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nconst CHARSET = \" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-:/!?&\";\n\nconst css = `\n@keyframes split-flap-top{from{transform:rotateX(0);filter:brightness(1)}to{transform:rotateX(-90deg);filter:brightness(.55)}}\n@keyframes split-flap-bottom{from{transform:rotateX(90deg);filter:brightness(.55)}to{transform:rotateX(0);filter:brightness(1)}}\n@media (prefers-reduced-motion: reduce){[data-flap]{animation:none!important}}`;\n\nconst reduced = () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\nexport interface DepartureBoardProps {\n  /** Words to cycle through. Shorter words are padded to the longest. */\n  words: string[];\n  /** Ms each word stays after it lands. */\n  interval?: number;\n  /** Ms for one flap to fall. */\n  flipDuration?: number;\n  /** Ms between neighbouring tiles starting. */\n  stagger?: number;\n  align?: \"left\" | \"center\";\n  tileColor?: string;\n  textColor?: string;\n  className?: string;\n}\n\nfunction Half({ char, side, animation }: { char: string; side: \"top\" | \"bottom\"; animation?: string }) {\n  const top = side === \"top\";\n  return (\n    <span\n      data-flap={animation ? \"\" : undefined}\n      style={{\n        position: \"absolute\",\n        left: 0,\n        right: 0,\n        height: \"50%\",\n        [top ? \"top\" : \"bottom\"]: 0,\n        overflow: \"hidden\",\n        background: top\n          ? \"linear-gradient(rgb(255 255 255 / .07), rgb(255 255 255 / .02)), var(--flap-tile)\"\n          : \"linear-gradient(rgb(0 0 0 / .12), rgb(0 0 0 / .02)), var(--flap-tile)\",\n        borderRadius: top ? \"0.12em 0.12em 0 0\" : \"0 0 0.12em 0.12em\",\n        transformOrigin: top ? \"50% 100%\" : \"50% 0%\",\n        backfaceVisibility: \"hidden\",\n        animation,\n      }}\n    >\n      <span\n        style={{\n          position: \"absolute\",\n          left: 0,\n          right: 0,\n          height: \"200%\",\n          [top ? \"top\" : \"bottom\"]: 0,\n          display: \"grid\",\n          placeItems: \"center\",\n        }}\n      >\n        {char}\n      </span>\n    </span>\n  );\n}\n\nfunction Tile({ target, delay, flipDuration }: { target: string; delay: number; flipDuration: number }) {\n  const [goal, setGoal] = useState(\" \");\n  const [cur, setCur] = useState(\" \");\n  const [next, setNext] = useState(\" \");\n\n  useEffect(() => {\n    const t = window.setTimeout(() => setGoal(target), delay);\n    return () => window.clearTimeout(t);\n  }, [target, delay]);\n\n  useEffect(() => {\n    // A flap is falling: land it, then pick the next character on the drum.\n    if (cur !== next) {\n      const t = window.setTimeout(() => setCur(next), reduced() ? 0 : flipDuration);\n      return () => window.clearTimeout(t);\n    }\n    if (cur === goal) return;\n    const t = window.setTimeout(() => {\n      const i = CHARSET.indexOf(cur);\n      setNext(reduced() || i < 0 || !CHARSET.includes(goal) ? goal : CHARSET[(i + 1) % CHARSET.length]);\n    }, 0);\n    return () => window.clearTimeout(t);\n  }, [cur, next, goal, flipDuration]);\n\n  const half = flipDuration / 2;\n  return (\n    <span\n      style={{\n        position: \"relative\",\n        display: \"inline-block\",\n        width: \"calc(1ch + 0.36em)\",\n        height: \"1.3em\",\n        perspective: \"5em\",\n        boxShadow: \"0 0.08em 0.2em rgb(0 0 0 / .45)\",\n        borderRadius: \"0.12em\",\n      }}\n    >\n      <Half char={next} side=\"top\" />\n      <Half char={cur} side=\"bottom\" />\n      {cur !== next && (\n        <span key={cur + next}>\n          <Half char={cur} side=\"top\" animation={`split-flap-top ${half}ms ease-in both`} />\n          <Half char={next} side=\"bottom\" animation={`split-flap-bottom ${half}ms ease-out ${half}ms both`} />\n        </span>\n      )}\n      <span style={{ position: \"absolute\", left: 0, right: 0, top: \"50%\", height: \"0.04em\", background: \"rgb(0 0 0 / .6)\" }} />\n    </span>\n  );\n}\n\nexport function DepartureBoard({\n  words,\n  interval = 4200,\n  flipDuration = 55,\n  stagger = 40,\n  align = \"center\",\n  tileColor = \"#1b1b1f\",\n  textColor = \"#f5f5f0\",\n  className,\n}: DepartureBoardProps) {\n  const ref = useRef<HTMLSpanElement>(null);\n  const [index, setIndex] = useState(-1);\n  const list = words.map((w) => w.toUpperCase());\n  const len = Math.max(1, ...list.map((w) => w.length));\n\n  useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    let timer = 0;\n    const io = new IntersectionObserver(([entry]) => {\n      window.clearInterval(timer);\n      if (!entry.isIntersecting) return;\n      setIndex((i) => (i < 0 ? 0 : i));\n      timer = window.setInterval(() => setIndex((i) => (i + 1) % Math.max(1, words.length)), interval);\n    });\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      window.clearInterval(timer);\n    };\n  }, [interval, words.length]);\n\n  const word = index < 0 ? \"\" : (list[index % list.length] ?? \"\");\n  const gap = len - word.length;\n  const padded = (align === \"center\" ? \" \".repeat(Math.floor(gap / 2)) + word : word).padEnd(len, \" \");\n\n  return (\n    <span\n      ref={ref}\n      className={cn(\"font-mono font-bold\", className)}\n      style={\n        {\n          display: \"inline-flex\",\n          gap: \"0.1em\",\n          lineHeight: 1,\n          color: \"var(--flap-text)\",\n          \"--flap-tile\": tileColor,\n          \"--flap-text\": textColor,\n        } as CSSProperties\n      }\n    >\n      <style href=\"departure-board\" precedence=\"default\">\n        {css}\n      </style>\n      <span className=\"sr-only\">\n        {word}\n      </span>\n      <span aria-hidden style={{ display: \"inline-flex\", gap: \"inherit\" }}>\n        {Array.from(padded).map((c, i) => (\n          <Tile key={i} target={c} delay={i * stagger} flipDuration={flipDuration} />\n        ))}\n      </span>\n    </span>\n  );\n}\n"}]}