{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flip-countdown",
  "type": "registry:component",
  "title": "Flip Countdown",
  "description": "A split-flap countdown clock. Each digit folds down in 3D with a soft shadow, grouped into days, hours, minutes and seconds.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "transitions",
    "countdown",
    "flip",
    "clock",
    "timer",
    "launch"
  ],
  "docs": "https://hyperblur.dev/effects/flip-countdown",
  "files": [
    {
      "path": "registry/hyperblur/flip-countdown.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/flip-countdown.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface FlipCountdownProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"color\"> {\n  target: string;\n  labels?: string[];\n  color?: string;\n  size?: number;\n  onComplete?: () => void;\n  hideDays?: boolean;\n}\n\nconst css = `\n@keyframes hb-fcd-fold {\n  from { transform: rotateX(0deg); }\n  to { transform: rotateX(-90deg); }\n}\n@keyframes hb-fcd-unfold {\n  from { transform: rotateX(90deg); }\n  to { transform: rotateX(0deg); }\n}\n@keyframes hb-fcd-shade-in {\n  from { opacity: 0; }\n  to { opacity: 1; }\n}\n@keyframes hb-fcd-shade-out {\n  from { opacity: 1; }\n  to { opacity: 0; }\n}\n.hb-fcd {\n  display: flex;\n  justify-content: center;\n  width: 100%;\n  container-type: inline-size;\n}\n.hb-fcd-row {\n  display: flex;\n  align-items: flex-start;\n  justify-content: center;\n  font-size: max(14px, min(var(--hb-fcd-s), calc((100cqw - 6px) / var(--hb-fcd-k))));\n  font-family: var(--hb-fcd-font, ui-sans-serif, system-ui, -apple-system, \"Helvetica Neue\", Arial, sans-serif);\n  font-variant-numeric: tabular-nums;\n  line-height: 1;\n  color: var(--hb-fcd-c);\n}\n.hb-fcd-unit {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 0.22em;\n}\n.hb-fcd-digits { display: flex; gap: 0.06em; }\n.hb-fcd-lab {\n  display: flex;\n  justify-content: center;\n  width: 0;\n  min-width: 100%;\n  font-size: max(9px, 0.22em);\n  font-weight: 500;\n  letter-spacing: 0.12em;\n  text-transform: uppercase;\n  white-space: nowrap;\n  color: rgba(255, 255, 255, 0.5);\n}\n.hb-fcd-sep {\n  flex: 0 0 1px;\n  align-self: flex-start;\n  width: 1px;\n  height: 1.3em;\n  margin: 0 0.2em;\n  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.2), transparent);\n}\n.hb-fcd-tile {\n  position: relative;\n  flex: 0 0 auto;\n  width: 0.85em;\n  height: 1.3em;\n  perspective: 3.2em;\n  border-radius: 0.12em;\n  box-shadow: 0 0.05em 0.16em rgba(0, 0, 0, 0.5);\n}\n.hb-fcd-tile::after {\n  content: \"\";\n  position: absolute;\n  left: 0;\n  right: 0;\n  top: 50%;\n  z-index: 6;\n  height: max(1px, 0.03em);\n  margin-top: calc(max(1px, 0.03em) / -2);\n  background: rgba(0, 0, 0, 0.9);\n}\n.hb-fcd-half {\n  position: absolute;\n  left: 0;\n  right: 0;\n  height: 50%;\n  overflow: hidden;\n  backface-visibility: hidden;\n}\n.hb-fcd-half::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  opacity: 0;\n  pointer-events: none;\n}\n.hb-fcd-top {\n  top: 0;\n  border-radius: 0.12em 0.12em 0 0;\n  background: linear-gradient(180deg, #2a2a2e 0%, #1b1b1e 100%);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09);\n  transform-origin: 50% 100%;\n}\n.hb-fcd-top::after { background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.6)); }\n.hb-fcd-bot {\n  top: 50%;\n  border-radius: 0 0 0.12em 0.12em;\n  background: linear-gradient(180deg, #151517 0%, #1f1f23 100%);\n  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.04);\n  transform-origin: 50% 0;\n}\n.hb-fcd-bot::after { background: linear-gradient(180deg, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0)); }\n.hb-fcd-ch {\n  position: absolute;\n  left: 0;\n  right: 0;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  height: 200%;\n  font-weight: 600;\n  letter-spacing: -0.02em;\n}\n.hb-fcd-top .hb-fcd-ch { top: 0; }\n.hb-fcd-bot .hb-fcd-ch { top: -100%; }\n.hb-fcd-live.hb-fcd-top, .hb-fcd-live.hb-fcd-bot { z-index: 1; }\n.hb-fcd-live.hb-fcd-top::after {\n  opacity: 1;\n  animation: hb-fcd-shade-out 0.6s ease-out forwards;\n}\n.hb-fcd-live.hb-fcd-bot::after { animation: hb-fcd-shade-in 0.3s ease-in forwards; }\n.hb-fcd-flap.hb-fcd-top {\n  z-index: 3;\n  animation: hb-fcd-fold 0.3s ease-in forwards;\n}\n.hb-fcd-flap.hb-fcd-top::after { animation: hb-fcd-shade-in 0.3s ease-in forwards; }\n.hb-fcd-flap.hb-fcd-bot {\n  z-index: 2;\n  animation: hb-fcd-unfold 0.3s ease-out 0.3s both;\n}\n.hb-fcd-flap.hb-fcd-bot::after {\n  opacity: 1;\n  animation: hb-fcd-shade-out 0.3s ease-out 0.3s both;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-fcd-flap, .hb-fcd-flap::after, .hb-fcd-live::after {\n    animation-duration: 1ms !important;\n    animation-delay: 0s !important;\n  }\n}\n`;\n\nconst DEFAULT_LABELS = [\"Days\", \"Hours\", \"Minutes\", \"Seconds\"];\n\nfunction subscribe(onChange: () => void) {\n  const id = window.setInterval(onChange, 250);\n  return () => window.clearInterval(id);\n}\n\nfunction getSnapshot() {\n  return Math.floor(Date.now() / 1000);\n}\n\nfunction getServerSnapshot() {\n  return 0;\n}\n\ninterface Flap {\n  cur: string;\n  prev: string;\n  k: number;\n}\n\nfunction Digit({ value }: { value: string }) {\n  const [flap, setFlap] = React.useState<Flap>({ cur: value, prev: value, k: 0 });\n  if (flap.cur !== value) setFlap({ cur: value, prev: flap.cur, k: flap.k + 1 });\n  const { cur, prev, k } = flap;\n  const live = k > 0 ? \" hb-fcd-live\" : \"\";\n\n  return (\n    <span className=\"hb-fcd-tile\" aria-hidden=\"true\">\n      <span key={`a${k}`} className={`hb-fcd-half hb-fcd-top${live}`}>\n        <span className=\"hb-fcd-ch\">{cur}</span>\n      </span>\n      <span key={`b${k}`} className={`hb-fcd-half hb-fcd-bot${live}`}>\n        <span className=\"hb-fcd-ch\">{k > 0 ? prev : cur}</span>\n      </span>\n      {k > 0 && (\n        <>\n          <span key={`c${k}`} className=\"hb-fcd-half hb-fcd-top hb-fcd-flap\">\n            <span className=\"hb-fcd-ch\">{prev}</span>\n          </span>\n          <span key={`d${k}`} className=\"hb-fcd-half hb-fcd-bot hb-fcd-flap\">\n            <span className=\"hb-fcd-ch\">{cur}</span>\n          </span>\n        </>\n      )}\n    </span>\n  );\n}\n\nexport function FlipCountdown({\n  target,\n  labels = DEFAULT_LABELS,\n  color = \"#ededed\",\n  size = 48,\n  onComplete,\n  hideDays = false,\n  className = \"\",\n  style,\n  ...rest\n}: FlipCountdownProps) {\n  const now = React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n  const ready = now > 0;\n  const targetMs = Date.parse(target);\n  const total = ready && Number.isFinite(targetMs) ? Math.max(0, Math.floor(targetMs / 1000) - now) : 0;\n  const done = ready && total === 0;\n\n  const callback = React.useRef(onComplete);\n  const fired = React.useRef(false);\n\n  React.useEffect(() => {\n    callback.current = onComplete;\n  });\n\n  React.useEffect(() => {\n    fired.current = false;\n  }, [target]);\n\n  React.useEffect(() => {\n    if (!done || fired.current) return;\n    fired.current = true;\n    callback.current?.();\n  }, [done]);\n\n  const days = Math.floor(total / 86400);\n  const dayDigits = Math.max(2, String(days).length);\n  const showDays = !(hideDays && ready && days === 0);\n\n  const units = [\n    { label: labels[0] ?? DEFAULT_LABELS[0], value: days, digits: dayDigits, name: \"day\" },\n    { label: labels[1] ?? DEFAULT_LABELS[1], value: Math.floor((total % 86400) / 3600), digits: 2, name: \"hour\" },\n    { label: labels[2] ?? DEFAULT_LABELS[2], value: Math.floor((total % 3600) / 60), digits: 2, name: \"minute\" },\n    { label: labels[3] ?? DEFAULT_LABELS[3], value: total % 60, digits: 2, name: \"second\" },\n  ].slice(showDays ? 0 : 1);\n\n  const digitCount = units.reduce((sum, u) => sum + u.digits, 0);\n  const fit = digitCount * 0.85 + (digitCount - units.length) * 0.06 + (units.length - 1) * 0.4 + 0.2;\n\n  const spoken = ready\n    ? units.map((u) => `${u.value} ${u.name}${u.value === 1 ? \"\" : \"s\"}`).join(\", \") + \" remaining\"\n    : \"Countdown\";\n\n  const vars = {\n    \"--hb-fcd-s\": `${Math.max(8, size)}px`,\n    \"--hb-fcd-c\": color,\n    \"--hb-fcd-k\": fit.toFixed(3),\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div className={`hb-fcd ${className}`} style={vars} role=\"timer\" aria-label={spoken} {...rest}>\n      <style href=\"hb-flip-countdown\" precedence=\"default\">{css}</style>\n      <div className=\"hb-fcd-row\">\n        {units.map((unit, i) => {\n          const text = ready ? String(unit.value).padStart(unit.digits, \"0\") : \"-\".repeat(unit.digits);\n          return (\n            <React.Fragment key={unit.name}>\n              {i > 0 && <span className=\"hb-fcd-sep\" aria-hidden=\"true\" />}\n              <span className=\"hb-fcd-unit\">\n                <span className=\"hb-fcd-digits\">\n                  {Array.from(text).map((ch, j) => (\n                    <Digit key={j} value={ch} />\n                  ))}\n                </span>\n                <span className=\"hb-fcd-lab\" aria-hidden=\"true\">\n                  {unit.label}\n                </span>\n              </span>\n            </React.Fragment>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}