{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "split-flap",
  "title": "Split-Flap Display",
  "author": "VenusUI",
  "description": "An airport departures-board display whose letters flip through to new text.",
  "files": [
    {
      "path": "registry/default/ui/split-flap.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/** Characters each flap can show, in the order it flips through them. */\nconst DEFAULT_CHARSET = \" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:.-/!?\"\n\ninterface SplitFlapProps extends Omit<React.ComponentProps<\"div\">, \"children\"> {\n  /** Text to show. It's padded or cut to `length`. Unknown characters show as spaces. */\n  value: string\n  /** Number of flaps. Defaults to the value's length. */\n  length?: number\n  /** Milliseconds per flip. Each flap flips through the charset until it reaches its letter. */\n  speed?: number\n  charset?: string\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (onChange) => {\n      const media = window.matchMedia(\"(prefers-reduced-motion: reduce)\")\n      media.addEventListener(\"change\", onChange)\n      return () => media.removeEventListener(\"change\", onChange)\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false\n  )\n}\n\n/** Half of a character: the top or bottom half of a full-size glyph, clipped. */\nfunction Half({ char, half, className, style }: { char: string; half: \"top\" | \"bottom\"; className?: string; style?: React.CSSProperties }) {\n  return (\n    <span\n      className={cn(\n        \"absolute inset-x-0 h-1/2 overflow-hidden bg-neutral-900 backface-hidden\",\n        half === \"top\" ? \"top-0 origin-bottom rounded-t-[inherit]\" : \"bottom-0 origin-top rounded-b-[inherit]\",\n        half === \"top\" ? \"bg-linear-to-b from-neutral-800 to-neutral-900\" : \"bg-linear-to-b from-neutral-900 to-neutral-950\",\n        className\n      )}\n      style={style}\n    >\n      <span className={cn(\"absolute inset-x-0 flex h-[200%] items-center justify-center\", half === \"top\" ? \"top-0\" : \"bottom-0\")}>{char}</span>\n    </span>\n  )\n}\n\nfunction Flap({ target, charset, speed, reduced }: { target: string; charset: string; speed: number; reduced: boolean }) {\n  const [current, setCurrent] = React.useState(target)\n  const [previous, setPrevious] = React.useState(target)\n  const [flip, setFlip] = React.useState(0)\n\n  React.useEffect(() => {\n    if (reduced) {\n      const id = setTimeout(() => {\n        setPrevious(target)\n        setCurrent(target)\n      }, 0)\n      return () => clearTimeout(id)\n    }\n    if (current === target) return\n    const id = setTimeout(() => {\n      const index = charset.indexOf(current)\n      const next = charset[(index + 1) % charset.length] ?? target\n      setPrevious(current)\n      setCurrent(next)\n      setFlip((n) => n + 1)\n    }, speed)\n    return () => clearTimeout(id)\n  }, [current, target, charset, speed, reduced])\n\n  return (\n    <span className=\"relative inline-block h-[1.5em] w-[1.05em] rounded-[0.12em] text-neutral-100 shadow-[0_2px_4px_rgb(0_0_0/0.35)] perspective-[300px]\">\n      {/* Static halves: the new top and the old bottom. */}\n      <Half char={current} half=\"top\" />\n      <Half char={previous} half=\"bottom\" />\n      {/* Flaps: the old top falls, then the new bottom lands. */}\n      {flip > 0 && !reduced ? (\n        <React.Fragment key={flip}>\n          <Half char={previous} half=\"top\" style={{ animation: `split-flap-top ${speed * 0.5}ms ease-in forwards` }} />\n          <Half\n            char={current}\n            half=\"bottom\"\n            className=\"[transform:rotateX(90deg)]\"\n            style={{ animation: `split-flap-bottom ${speed * 0.5}ms ease-out ${speed * 0.5}ms forwards` }}\n          />\n        </React.Fragment>\n      ) : null}\n      {/* The hinge line across the middle. */}\n      <span aria-hidden=\"true\" className=\"absolute inset-x-0 top-1/2 h-px -translate-y-px bg-black/70\" />\n    </span>\n  )\n}\n\n/**\n * A split-flap display, like an airport departures board. When `value`\n * changes, each flap flips through the characters to its new letter.\n * Screen readers get the text itself; with reduced motion it switches\n * without flipping.\n */\nfunction SplitFlap({ value, length, speed = 70, charset = DEFAULT_CHARSET, className, ...props }: SplitFlapProps) {\n  const reduced = useReducedMotion()\n  const size = length ?? value.length\n  const text = value.toUpperCase().padEnd(size, \" \").slice(0, size)\n  const chars = [...text].map((c) => (charset.includes(c) ? c : \" \"))\n\n  return (\n    <div data-slot=\"split-flap\" className={cn(\"inline-flex gap-[0.08em] font-mono text-3xl leading-none font-semibold\", className)} {...props}>\n      <span className=\"sr-only\">{value}</span>\n      <span aria-hidden=\"true\" className=\"inline-flex gap-[0.08em]\">\n        {chars.map((c, i) => (\n          <Flap key={i} target={c} charset={charset} speed={speed} reduced={reduced} />\n        ))}\n      </span>\n    </div>\n  )\n}\n\nexport { SplitFlap }\n",
      "type": "registry:ui"
    }
  ],
  "css": {
    "@keyframes split-flap-top": {
      "from": {
        "transform": "rotateX(0deg)"
      },
      "to": {
        "transform": "rotateX(-90deg)"
      }
    },
    "@keyframes split-flap-bottom": {
      "from": {
        "transform": "rotateX(90deg)"
      },
      "to": {
        "transform": "rotateX(0deg)"
      }
    }
  },
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "text",
    "animations"
  ],
  "type": "registry:ui"
}