{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card-flip-deck",
  "type": "registry:component",
  "title": "Card Flip Deck",
  "description": "A rolodex of city cards where the front card flips over its top edge to reveal the next. Flip with a click, the wheel, a vertical drag, arrow keys or on a timer.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "cards",
    "deck",
    "flip",
    "rolodex",
    "weather",
    "carousel"
  ],
  "docs": "https://hyperblur.dev/effects/card-flip-deck",
  "files": [
    {
      "path": "registry/hyperblur/card-flip-deck.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/card-flip-deck.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface DeckCity {\n  city: string;\n  country: string;\n  time: string;\n  temp: number;\n  condition: string;\n  night?: boolean;\n  colors?: [string, string];\n  forecast?: number[];\n}\n\nexport interface CardFlipDeckProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  cards?: DeckCity[];\n  index?: number;\n  defaultIndex?: number;\n  onChange?: (index: number) => void;\n  height?: number;\n  autoPlay?: number;\n  unit?: \"C\" | \"F\";\n  accent?: string;\n}\n\nconst defaultCards: DeckCity[] = [\n  { city: \"Lisbon\", country: \"Portugal\", time: \"14:20\", temp: 22, condition: \"Clear, light wind\", colors: [\"#2b6cd9\", \"#ffc58a\"], forecast: [22, 23, 21, 24, 25] },\n  { city: \"Reykjavik\", country: \"Iceland\", time: \"13:20\", temp: 6, condition: \"Low cloud, drizzle\", colors: [\"#4a5a6e\", \"#c7d3dd\"], forecast: [6, 5, 7, 4, 6] },\n  { city: \"Kyoto\", country: \"Japan\", time: \"22:20\", temp: 17, condition: \"Calm, clear night\", night: true, colors: [\"#141a3d\", \"#5b4f9e\"], forecast: [17, 19, 18, 16, 20] },\n  { city: \"Cape Town\", country: \"South Africa\", time: \"15:20\", temp: 19, condition: \"Sunny, strong breeze\", colors: [\"#1f8fb5\", \"#f6e1a5\"], forecast: [19, 21, 20, 18, 22] },\n  { city: \"Vancouver\", country: \"Canada\", time: \"06:20\", temp: 11, condition: \"Sunrise, fog clearing\", colors: [\"#6a4f8f\", \"#ffb38a\"], forecast: [11, 13, 12, 14, 12] },\n  { city: \"Marrakech\", country: \"Morocco\", time: \"14:20\", temp: 31, condition: \"Hot and dry\", colors: [\"#d0652f\", \"#ffd59a\"], forecast: [31, 33, 32, 30, 34] },\n];\n\nconst days = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\"];\n\nconst css = `\n.hb-vl12 {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 12px;\n  width: 100%;\n  max-width: 360px;\n  margin: 0 auto;\n  color: #ededed;\n  font-family: inherit;\n  box-sizing: border-box;\n  outline: none;\n  touch-action: pan-x;\n}\n.hb-vl12 *, .hb-vl12 *::before, .hb-vl12 *::after { box-sizing: border-box; }\n.hb-vl12:focus-visible .hb-vl12-stack { outline: 2px solid var(--hb-vl12-a); outline-offset: 6px; border-radius: 18px; }\n.hb-vl12-stack {\n  position: relative;\n  width: 100%;\n  height: calc(var(--hb-vl12-h) + 22px);\n  perspective: 1100px;\n  perspective-origin: 50% 0%;\n  cursor: grab;\n  user-select: none;\n}\n.hb-vl12-stack:active { cursor: grabbing; }\n.hb-vl12-c {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  height: var(--hb-vl12-h);\n  overflow: hidden;\n  border-radius: 18px;\n  background: linear-gradient(170deg, var(--hb-vl12-c0), var(--hb-vl12-c1));\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 20px 34px -18px rgba(0, 0, 0, 0.9);\n  transform-origin: 50% 0%;\n  transform: translateY(calc(var(--hb-vl12-k) * -7px)) scale(calc(1 - var(--hb-vl12-k) * 0.05));\n  opacity: var(--hb-vl12-o);\n  filter: brightness(calc(1 - var(--hb-vl12-k) * 0.18));\n  backface-visibility: hidden;\n  -webkit-backface-visibility: hidden;\n  transition: transform 0.6s cubic-bezier(0.34, 1.25, 0.64, 1), opacity 0.4s ease, filter 0.4s ease;\n}\n.hb-vl12-c[data-anim=\"out\"] { animation: hb-vl12-out 0.72s cubic-bezier(0.55, 0.06, 0.3, 1); }\n.hb-vl12-c[data-anim=\"in\"] { animation: hb-vl12-in 0.72s cubic-bezier(0.22, 0.8, 0.3, 1); }\n@keyframes hb-vl12-out {\n  0% { transform: none; opacity: 1; filter: none; z-index: 50; }\n  100% { transform: rotateX(-180deg) translateZ(30px); opacity: 1; filter: brightness(1.2); z-index: 50; }\n}\n@keyframes hb-vl12-in {\n  0% { transform: rotateX(-180deg) translateZ(30px); opacity: 1; z-index: 50; }\n  100% { transform: none; opacity: 1; z-index: 50; }\n}\n.hb-vl12-sky { position: absolute; inset: 0; width: 100%; height: 100%; }\n.hb-vl12-body { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 14px 16px; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.25); }\n.hb-vl12-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }\n.hb-vl12-city { margin: 0; font-family: var(--font-grotesk, inherit); font-size: 19px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }\n.hb-vl12-sub { margin: 2px 0 0; font-size: 11px; color: rgba(255, 255, 255, 0.78); }\n.hb-vl12-temp { font-size: 34px; font-weight: 300; letter-spacing: -0.04em; line-height: 0.95; font-variant-numeric: tabular-nums; }\n.hb-vl12-bot { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-top: auto; }\n.hb-vl12-cond { font-size: 11.5px; color: rgba(255, 255, 255, 0.9); white-space: nowrap; }\n.hb-vl12-fc { display: flex; gap: 8px; }\n.hb-vl12-day { display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 9.5px; color: rgba(255, 255, 255, 0.72); }\n.hb-vl12-day b { font-size: 11px; font-weight: 600; color: #ffffff; font-variant-numeric: tabular-nums; }\n.hb-vl12-bar { display: flex; align-items: center; gap: 10px; }\n.hb-vl12-btn {\n  display: grid;\n  place-items: center;\n  width: 30px;\n  height: 30px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 50%;\n  background: #18181b;\n  color: #d6d6da;\n  cursor: pointer;\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);\n  transition: background 0.2s ease, transform 0.2s ease;\n}\n.hb-vl12-btn:hover { background: #222226; }\n.hb-vl12-btn:active { transform: scale(0.9); }\n.hb-vl12-btn:focus-visible { outline: 2px solid var(--hb-vl12-a); outline-offset: 2px; }\n.hb-vl12-count { min-width: 54px; font-family: var(--font-mono, ui-monospace, monospace); font-size: 11px; text-align: center; color: #8f8f8f; font-variant-numeric: tabular-nums; }\n.hb-vl12-count b { color: #ededed; font-weight: 500; }\n.hb-vl12-dots { display: flex; gap: 4px; }\n.hb-vl12-dots span { width: 4px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.18); transition: width 0.4s cubic-bezier(0.34, 1.4, 0.64, 1), background 0.3s ease; }\n.hb-vl12-dots span[data-on=\"true\"] { width: 14px; background: var(--hb-vl12-a); }\n@media (prefers-reduced-motion: reduce) {\n  .hb-vl12 *, .hb-vl12 *::before, .hb-vl12 *::after { transition: none !important; animation: none !important; }\n}\n`;\n\nfunction Sky({ night, uid }: { night?: boolean; uid: string }) {\n  return (\n    <svg className=\"hb-vl12-sky\" viewBox=\"0 0 320 180\" preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\">\n      <defs>\n        <radialGradient id={`${uid}-s`} cx=\"0.5\" cy=\"0.5\" r=\"0.5\">\n          <stop offset=\"0\" stopColor=\"#ffffff\" stopOpacity={night ? 0.5 : 0.75} />\n          <stop offset=\"1\" stopColor=\"#ffffff\" stopOpacity=\"0\" />\n        </radialGradient>\n      </defs>\n      <circle cx=\"248\" cy=\"62\" r=\"64\" fill={`url(#${uid}-s)`} />\n      <circle cx=\"248\" cy=\"62\" r={night ? 16 : 20} fill={night ? \"#f2efe2\" : \"#fff4d8\"} />\n      {night && <circle cx=\"256\" cy=\"56\" r=\"14\" fill=\"#1f2350\" />}\n      {night &&\n        [\n          [40, 30],\n          [92, 52],\n          [150, 22],\n          [196, 40],\n          [120, 70],\n          [64, 84],\n        ].map(([x, y], i) => <circle key={i} cx={x} cy={y} r={i % 2 ? 0.9 : 1.3} fill=\"#ffffff\" opacity=\"0.8\" />)}\n      <path d=\"M0 150 C 60 128, 110 142, 160 134 S 260 120, 320 136 L320 180 L0 180 Z\" fill=\"#000000\" opacity=\"0.16\" />\n      <path d=\"M0 164 C 70 150, 140 162, 200 154 S 290 148, 320 156 L320 180 L0 180 Z\" fill=\"#000000\" opacity=\"0.2\" />\n    </svg>\n  );\n}\n\nexport function CardFlipDeck({\n  cards = defaultCards,\n  index,\n  defaultIndex = 0,\n  onChange,\n  height = 168,\n  autoPlay = 0,\n  unit = \"C\",\n  accent = \"#2f7bff\",\n  className,\n  style,\n  ...rest\n}: CardFlipDeckProps) {\n  const n = cards.length;\n  const [inner, setInner] = React.useState(defaultIndex);\n  const current = (((index ?? inner) % n) + n) % n;\n  const [anim, setAnim] = React.useState<{ card: number; dir: \"out\" | \"in\"; nonce: number } | null>(null);\n  const [paused, setPaused] = React.useState(false);\n  const wheel = React.useRef({ sum: 0, lock: 0 });\n  const drag = React.useRef<{ y: number; id: number } | null>(null);\n  const uid = React.useId().replace(/:/g, \"\");\n\n  const go = React.useCallback(\n    (dir: 1 | -1) => {\n      const next = (current + dir + n) % n;\n      setAnim((prev) => ({ card: dir === 1 ? current : next, dir: dir === 1 ? \"out\" : \"in\", nonce: (prev?.nonce ?? 0) + 1 }));\n      if (index === undefined) setInner(next);\n      onChange?.(next);\n    },\n    [current, n, index, onChange],\n  );\n\n  React.useEffect(() => {\n    if (!autoPlay || paused) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const t = window.setInterval(() => go(1), autoPlay);\n    return () => window.clearInterval(t);\n  }, [autoPlay, paused, go]);\n\n  const toF = (c: number) => (unit === \"F\" ? Math.round((c * 9) / 5 + 32) : c);\n\n  return (\n    <div\n      className={[\"hb-vl12\", className].filter(Boolean).join(\" \")}\n      style={{ \"--hb-vl12-a\": accent, \"--hb-vl12-h\": `${height}px`, ...style } as React.CSSProperties}\n      tabIndex={0}\n      role=\"region\"\n      aria-roledescription=\"carousel\"\n      aria-label=\"City weather\"\n      onPointerEnter={() => setPaused(true)}\n      onPointerLeave={() => setPaused(false)}\n      onFocus={() => setPaused(true)}\n      onBlur={(event) => {\n        if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setPaused(false);\n      }}\n      onKeyDown={(event) => {\n        if (event.target !== event.currentTarget) return;\n        if (event.key === \"ArrowDown\" || event.key === \"ArrowRight\" || event.key === \"PageDown\") {\n          event.preventDefault();\n          go(1);\n        } else if (event.key === \"ArrowUp\" || event.key === \"ArrowLeft\" || event.key === \"PageUp\") {\n          event.preventDefault();\n          go(-1);\n        }\n      }}\n      {...rest}\n    >\n      <style href=\"hb-card-flip-deck\" precedence=\"default\">{css}</style>\n      <div\n        className=\"hb-vl12-stack\"\n        onWheel={(event) => {\n          const now = event.timeStamp;\n          if (now < wheel.current.lock) return;\n          wheel.current.sum += event.deltaY;\n          if (Math.abs(wheel.current.sum) > 40) {\n            go(wheel.current.sum > 0 ? 1 : -1);\n            wheel.current = { sum: 0, lock: now + 520 };\n          }\n        }}\n        onPointerDown={(event) => {\n          drag.current = { y: event.clientY, id: event.pointerId };\n          event.currentTarget.setPointerCapture(event.pointerId);\n        }}\n        onPointerUp={(event) => {\n          const start = drag.current;\n          drag.current = null;\n          if (!start) return;\n          const dy = event.clientY - start.y;\n          if (dy < -30) go(1);\n          else if (dy > 30) go(-1);\n          else go(1);\n        }}\n        onPointerCancel={() => {\n          drag.current = null;\n        }}\n      >\n        {cards.map((card, i) => {\n          const k = (i - current + n) % n;\n          const animated = anim && anim.card === i ? anim : null;\n          const [c0, c1] = card.colors ?? [\"#2b6cd9\", \"#ffc58a\"];\n          return (\n            <div\n              key={animated ? `${i}-${animated.nonce}` : `${i}`}\n              className=\"hb-vl12-c\"\n              data-anim={animated ? animated.dir : undefined}\n              aria-hidden={k !== 0}\n              onAnimationEnd={() => setAnim(null)}\n              style={\n                {\n                  \"--hb-vl12-k\": Math.min(k, 3),\n                  \"--hb-vl12-o\": k <= 2 ? 1 : 0,\n                  \"--hb-vl12-c0\": c0,\n                  \"--hb-vl12-c1\": c1,\n                  zIndex: animated ? n + 1 : n - k,\n                } as React.CSSProperties\n              }\n            >\n              <Sky night={card.night} uid={`${uid}-${i}`} />\n              <div className=\"hb-vl12-body\">\n                <div className=\"hb-vl12-top\">\n                  <div>\n                    <p className=\"hb-vl12-city\">{card.city}</p>\n                    <p className=\"hb-vl12-sub\">\n                      {card.country} / {card.time}\n                    </p>\n                  </div>\n                  <span className=\"hb-vl12-temp\">\n                    {toF(card.temp)}\n                    <span style={{ fontSize: \"0.5em\", verticalAlign: \"top\" }}>&deg;</span>\n                  </span>\n                </div>\n                <div className=\"hb-vl12-bot\">\n                  <span className=\"hb-vl12-cond\">{card.condition}</span>\n                  {card.forecast && (\n                    <span className=\"hb-vl12-fc\">\n                      {card.forecast.slice(0, 5).map((t, d) => (\n                        <span key={d} className=\"hb-vl12-day\">\n                          <b>{toF(t)}&deg;</b>\n                          {days[d]}\n                        </span>\n                      ))}\n                    </span>\n                  )}\n                </div>\n              </div>\n            </div>\n          );\n        })}\n      </div>\n      <div className=\"hb-vl12-bar\">\n        <button type=\"button\" className=\"hb-vl12-btn\" aria-label=\"Previous city\" onClick={() => go(-1)}>\n          <svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" fill=\"none\" aria-hidden=\"true\">\n            <path d=\"M3 7.5L6 4.5l3 3\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n          </svg>\n        </button>\n        <span className=\"hb-vl12-count\" aria-live=\"polite\">\n          <b>{String(current + 1).padStart(2, \"0\")}</b> / {String(n).padStart(2, \"0\")}\n        </span>\n        <span className=\"hb-vl12-dots\" aria-hidden=\"true\">\n          {cards.map((card, i) => (\n            <span key={card.city + i} data-on={i === current ? \"true\" : \"false\"} />\n          ))}\n        </span>\n        <button type=\"button\" className=\"hb-vl12-btn\" aria-label=\"Next city\" onClick={() => go(1)}>\n          <svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" fill=\"none\" aria-hidden=\"true\">\n            <path d=\"M3 4.5l3 3 3-3\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n          </svg>\n        </button>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}