{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flip-board-text",
  "title": "Flip Board Text",
  "description": "A split-flap departure board: each cell clatters through the alphabet to its letter, one after another, whenever the message changes.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/flip-board-text/flip-board-text.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface FlipBoardTextProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"children\"\n> {\n  /** Messages shown in turn. Use capitals, digits and : - . */\n  messages?: string[];\n  /** Milliseconds between messages. */\n  interval?: number;\n  /** Milliseconds per flap. */\n  step?: number;\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nconst ALPHABET = \" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:-.\";\nconst MESSAGES = [\"DEPARTING 09:40\", \"GATE B12 OPEN\", \"NOW BOARDING\"];\n\nfunction FlipCell({\n  target,\n  step,\n  delay,\n  instant,\n}: {\n  target: string;\n  step: number;\n  delay: number;\n  instant: boolean;\n}) {\n  const flapRef = React.useRef<HTMLSpanElement>(null);\n  const [state, setState] = React.useState({ now: \" \", was: \" \" });\n  const goal = ALPHABET.includes(target) ? target : \" \";\n\n  // Each flap moves one place along the alphabet, like the real thing, until the cell reaches its letter.\n  React.useEffect(() => {\n    if (state.now === goal) {\n      // The last flap has landed, so the bottom half catches up with the top.\n      if (state.was === goal) return;\n      const settle = window.setTimeout(\n        () => setState({ now: goal, was: goal }),\n        step,\n      );\n      return () => window.clearTimeout(settle);\n    }\n    const wait = state.now === state.was ? delay : step;\n    const timer = window.setTimeout(() => {\n      setState((s) => {\n        const next = instant\n          ? goal\n          : ALPHABET[(ALPHABET.indexOf(s.now) + 1) % ALPHABET.length];\n        return { now: next, was: s.now };\n      });\n    }, wait);\n    return () => window.clearTimeout(timer);\n  }, [state, goal, step, delay, instant]);\n\n  React.useEffect(() => {\n    if (instant) return;\n    flapRef.current?.animate(\n      [{ transform: \"rotateX(0deg)\" }, { transform: \"rotateX(-90deg)\" }],\n      { duration: step, easing: \"ease-in\" },\n    );\n  }, [state, step, instant]);\n\n  const half = \"absolute inset-x-0 h-1/2 overflow-hidden text-center\";\n  const glyph = \"absolute inset-x-0 block h-[200%] leading-[1.34em]\";\n  return (\n    <span\n      className=\"relative inline-block h-[1.34em] w-[0.8em] overflow-hidden rounded-[0.1em] [perspective:300px]\"\n      style={{\n        background: \"color-mix(in srgb, currentColor 9%, transparent)\",\n      }}\n    >\n      <span className={`${half} top-0`}>\n        <span className={`${glyph} top-0`}>{state.now}</span>\n      </span>\n      <span className={`${half} bottom-0`}>\n        <span className={`${glyph} bottom-0`}>{state.was}</span>\n      </span>\n      <span\n        ref={flapRef}\n        className={`${half} top-0 origin-bottom backface-hidden`}\n        style={{ transform: \"rotateX(-90deg)\" }}\n      >\n        <span className={`${glyph} top-0`}>{state.was}</span>\n      </span>\n      <span\n        className=\"absolute inset-x-0 top-1/2 h-px\"\n        style={{\n          background: \"color-mix(in srgb, currentColor 22%, transparent)\",\n        }}\n      />\n    </span>\n  );\n}\n\nexport function FlipBoardText({\n  messages = MESSAGES,\n  interval = 3000,\n  step = 34,\n  className,\n  style,\n  ...props\n}: FlipBoardTextProps) {\n  const reduce = useReducedMotion();\n  const [index, setIndex] = React.useState(0);\n  const width = Math.max(1, ...messages.map((m) => m.length));\n  const message = messages[index] ?? \"\";\n  const pad = Math.floor((width - message.length) / 2);\n  const line = (\" \".repeat(pad) + message).padEnd(width, \" \");\n\n  React.useEffect(() => {\n    if (reduce || messages.length < 2) return;\n    const timer = window.setInterval(\n      () => setIndex((i) => (i + 1) % messages.length),\n      interval,\n    );\n    return () => window.clearInterval(timer);\n  }, [reduce, messages.length, interval]);\n\n  return (\n    <div\n      className={`inline-flex gap-[0.08em] font-mono ${className ?? \"\"}`}\n      style={style}\n      role=\"text\"\n      aria-label={message}\n      {...props}\n    >\n      {Array.from(line).map((c, i) => (\n        <FlipCell\n          key={i}\n          target={c.toUpperCase()}\n          step={step}\n          delay={i * 26}\n          instant={reduce}\n        />\n      ))}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}