{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "carousel-page-count",
  "type": "registry:component",
  "title": "Carousel Page Count",
  "description": "A swipeable carousel with a rolling two-digit page counter, a progress hairline and arrow buttons that disable at both ends.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "carousel",
    "counter",
    "pagination",
    "slides",
    "arrows",
    "swipe"
  ],
  "docs": "https://hyperblur.dev/effects/carousel-page-count",
  "files": [
    {
      "path": "registry/hyperblur/carousel-page-count.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/carousel-page-count.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PageCountSlide {\n  title: string;\n  caption?: string;\n  src?: string;\n  from?: string;\n  to?: string;\n}\n\nexport interface CarouselPageCountProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  slides?: PageCountSlide[];\n  value?: number;\n  defaultValue?: number;\n  onChange?: (index: number) => void;\n  autoPlay?: number;\n  ratio?: string;\n  accent?: string;\n}\n\nconst defaults: PageCountSlide[] = [\n  { title: \"Morning ferry\", caption: \"Cold light over the harbor\", from: \"#f6a85b\", to: \"#5b2a86\" },\n  { title: \"Salt flats\", caption: \"Where the sky goes flat\", from: \"#9fd3e6\", to: \"#2a4a6b\" },\n  { title: \"Night orchard\", caption: \"Lanterns between the rows\", from: \"#2b3b66\", to: \"#0a0f1f\" },\n  { title: \"Rose cliffs\", caption: \"Low tide, late afternoon\", from: \"#f2c6a0\", to: \"#b4505a\" },\n  { title: \"Fern valley\", caption: \"The hour after rain\", from: \"#a6e3b4\", to: \"#14593f\" },\n  { title: \"Violet pass\", caption: \"Above the cloud line\", from: \"#c9b6ff\", to: \"#2b2a6e\" },\n  { title: \"Ember road\", caption: \"Late August, dry grass\", from: \"#ffd37a\", to: \"#c4452f\" },\n  { title: \"Glass bay\", caption: \"Slack water at dusk\", from: \"#7fe0e0\", to: \"#123b55\" },\n];\n\nconst css = `\n.hb-za2 {\n  --hb-za2-c: #2f7bff;\n  box-sizing: border-box;\n  position: relative;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n  outline: none;\n}\n.hb-za2 *, .hb-za2 *::before, .hb-za2 *::after { box-sizing: border-box; }\n.hb-za2:focus-visible { outline: 2px solid var(--hb-za2-c); outline-offset: 4px; border-radius: 16px; }\n.hb-za2-view {\n  position: relative;\n  overflow: hidden;\n  aspect-ratio: var(--hb-za2-r);\n  border: 1px solid #262626;\n  border-radius: 14px;\n  background: #111111;\n  touch-action: pan-y;\n  cursor: grab;\n}\n.hb-za2-view[data-drag=\"true\"] { cursor: grabbing; }\n.hb-za2-track {\n  display: flex;\n  height: 100%;\n  transform: translate3d(calc(var(--hb-za2-i) * -100% + var(--hb-za2-dx, 0px)), 0, 0);\n  transition: transform 0.55s cubic-bezier(0.22, 0.9, 0.24, 1);\n}\n.hb-za2-view[data-drag=\"true\"] .hb-za2-track { transition: none; }\n.hb-za2-slide {\n  position: relative;\n  flex: 0 0 100%;\n  min-width: 0;\n  overflow: hidden;\n  user-select: none;\n  -webkit-user-select: none;\n}\n.hb-za2-art { position: absolute; inset: 0; background-size: cover; background-position: center; }\n.hb-za2-art::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background:\n    radial-gradient(circle at 76% 28%, rgba(255, 255, 255, 0.55) 0, rgba(255, 255, 255, 0.12) 14%, transparent 15%),\n    linear-gradient(180deg, transparent 38%, rgba(0, 0, 0, 0.62) 100%);\n}\n.hb-za2-copy { position: absolute; left: 14px; right: 14px; bottom: 11px; display: flex; flex-direction: column; gap: 1px; }\n.hb-za2-copy b { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }\n.hb-za2-copy span { font-size: 12px; color: rgba(255, 255, 255, 0.72); }\n.hb-za2-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }\n.hb-za2-count {\n  display: inline-flex;\n  align-items: baseline;\n  gap: 6px;\n  font-size: 22px;\n  line-height: 1;\n  font-weight: 600;\n  letter-spacing: -0.02em;\n  font-variant-numeric: tabular-nums;\n}\n.hb-za2-digits { display: inline-flex; }\n.hb-za2-digit {\n  position: relative;\n  display: block;\n  width: 0.62em;\n  height: 1.1em;\n  overflow: hidden;\n  -webkit-mask-image: linear-gradient(180deg, transparent, #000 22%, #000 78%, transparent);\n  mask-image: linear-gradient(180deg, transparent, #000 22%, #000 78%, transparent);\n}\n.hb-za2-reel {\n  display: flex;\n  flex-direction: column;\n  transform: translateY(calc(var(--hb-za2-d) * -1.1em));\n  transition: transform 0.6s cubic-bezier(0.22, 0.9, 0.24, 1);\n}\n.hb-za2-reel i { display: block; height: 1.1em; line-height: 1.1em; font-style: normal; text-align: center; }\n.hb-za2-sep { font-size: 14px; font-weight: 500; color: #6b6b6b; }\n.hb-za2-total { font-size: 14px; font-weight: 500; color: #8f8f8f; }\n.hb-za2-meter { flex: 1 1 auto; min-width: 24px; height: 3px; overflow: hidden; background: #262626; border-radius: 999px; }\n.hb-za2-meter span {\n  display: block;\n  height: 100%;\n  background: var(--hb-za2-c);\n  border-radius: inherit;\n  transform-origin: left center;\n  transform: scaleX(var(--hb-za2-p));\n  transition: transform 0.55s cubic-bezier(0.22, 0.9, 0.24, 1);\n}\n.hb-za2-arrows { display: flex; gap: 8px; }\n.hb-za2-btn {\n  display: grid;\n  place-items: center;\n  width: 34px;\n  height: 34px;\n  margin: 0;\n  padding: 0;\n  color: #ededed;\n  background: #171717;\n  border: 1px solid #2a2a2a;\n  border-radius: 999px;\n  cursor: pointer;\n  transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease, transform 0.2s ease;\n}\n.hb-za2-btn:hover:not(:disabled) { background: #202020; border-color: #3a3a3a; }\n.hb-za2-btn:active:not(:disabled) { transform: scale(0.93); }\n.hb-za2-btn:focus-visible { outline: 2px solid var(--hb-za2-c); outline-offset: 2px; }\n.hb-za2-btn:disabled { opacity: 0.32; cursor: not-allowed; }\n.hb-za2-btn svg { width: 15px; height: 15px; }\n.hb-za2-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-za2-track, .hb-za2-reel, .hb-za2-meter span, .hb-za2-btn { transition: none; }\n}\n`;\n\nfunction Digits({ value, width }: { value: number; width: number }) {\n  const text = String(value).padStart(width, \"0\");\n  return (\n    <span className=\"hb-za2-digits\" aria-hidden=\"true\">\n      {text.split(\"\").map((ch, k) => (\n        <span key={k} className=\"hb-za2-digit\">\n          <span className=\"hb-za2-reel\" style={{ \"--hb-za2-d\": Number(ch) } as React.CSSProperties}>\n            {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((n) => (\n              <i key={n}>{n}</i>\n            ))}\n          </span>\n        </span>\n      ))}\n    </span>\n  );\n}\n\nexport function CarouselPageCount({\n  slides,\n  value,\n  defaultValue = 0,\n  onChange,\n  autoPlay = 0,\n  ratio = \"16 / 9\",\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  onPointerEnter,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  ...rest\n}: CarouselPageCountProps) {\n  const items = slides && slides.length ? slides : defaults;\n  const total = items.length;\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState(defaultValue);\n  const index = Math.min(total - 1, Math.max(0, controlled ? value : inner));\n  const [paused, setPaused] = React.useState(false);\n  const [drag, setDrag] = React.useState<number | null>(null);\n  const start = React.useRef<{ x: number; id: number; w: number } | null>(null);\n  const latest = React.useRef(onChange);\n  const width = String(total).length;\n\n  React.useEffect(() => {\n    latest.current = onChange;\n  }, [onChange]);\n\n  const set = React.useCallback(\n    (next: number) => {\n      const clamped = Math.min(total - 1, Math.max(0, next));\n      if (clamped === index) return;\n      if (!controlled) setInner(clamped);\n      latest.current?.(clamped);\n    },\n    [controlled, index, total],\n  );\n\n  React.useEffect(() => {\n    if (!autoPlay || paused || drag !== null) return;\n    const id = window.setTimeout(() => set(index >= total - 1 ? 0 : index + 1), autoPlay);\n    return () => window.clearTimeout(id);\n  }, [autoPlay, paused, drag, index, total, set]);\n\n  const vars = {\n    \"--hb-za2-c\": accent,\n    \"--hb-za2-r\": ratio,\n    \"--hb-za2-i\": index,\n    \"--hb-za2-p\": ((index + 1) / total).toFixed(4),\n    \"--hb-za2-dx\": drag !== null ? `${drag.toFixed(1)}px` : \"0px\",\n    ...style,\n  } as React.CSSProperties;\n\n  function down(e: React.PointerEvent<HTMLDivElement>) {\n    if (e.pointerType === \"mouse\" && e.button !== 0) return;\n    start.current = { x: e.clientX, id: e.pointerId, w: e.currentTarget.clientWidth };\n  }\n\n  function move(e: React.PointerEvent<HTMLDivElement>) {\n    const s = start.current;\n    if (!s || s.id !== e.pointerId) return;\n    const dx = e.clientX - s.x;\n    if (drag === null && Math.abs(dx) < 6) return;\n    if (drag === null) e.currentTarget.setPointerCapture(e.pointerId);\n    let eased = dx;\n    if ((index === 0 && dx > 0) || (index === total - 1 && dx < 0)) eased = dx * 0.3;\n    setDrag(eased);\n  }\n\n  function up(e: React.PointerEvent<HTMLDivElement>) {\n    const s = start.current;\n    if (!s || s.id !== e.pointerId) return;\n    start.current = null;\n    const dx = drag ?? 0;\n    setDrag(null);\n    if (Math.abs(dx) > Math.min(70, s.w * 0.18)) set(index + (dx < 0 ? 1 : -1));\n  }\n\n  return (\n    <div\n      className={`hb-za2 ${className}`}\n      style={vars}\n      role=\"group\"\n      aria-roledescription=\"carousel\"\n      aria-label=\"Gallery\"\n      tabIndex={0}\n      onKeyDown={(e) => {\n        onKeyDown?.(e);\n        if (e.key === \"ArrowRight\") {\n          e.preventDefault();\n          set(index + 1);\n        } else if (e.key === \"ArrowLeft\") {\n          e.preventDefault();\n          set(index - 1);\n        } else if (e.key === \"Home\") {\n          e.preventDefault();\n          set(0);\n        } else if (e.key === \"End\") {\n          e.preventDefault();\n          set(total - 1);\n        }\n      }}\n      onPointerEnter={(e) => {\n        onPointerEnter?.(e);\n        setPaused(true);\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        setPaused(false);\n      }}\n      onFocus={(e) => {\n        onFocus?.(e);\n        setPaused(true);\n      }}\n      onBlur={(e) => {\n        onBlur?.(e);\n        setPaused(false);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-carousel-page-count\" precedence=\"default\">{css}</style>\n      <div\n        className=\"hb-za2-view\"\n        data-drag={drag !== null}\n        onPointerDown={down}\n        onPointerMove={move}\n        onPointerUp={up}\n        onPointerCancel={up}\n      >\n        <div className=\"hb-za2-track\">\n          {items.map((slide, i) => (\n            <div\n              key={i}\n              className=\"hb-za2-slide\"\n              role=\"group\"\n              aria-roledescription=\"slide\"\n              aria-label={`${i + 1} of ${total}`}\n              aria-hidden={i !== index}\n            >\n              <div\n                className=\"hb-za2-art\"\n                style={{\n                  background: slide.src\n                    ? `center / cover url(${slide.src})`\n                    : `linear-gradient(150deg, ${slide.from ?? \"#2f7bff\"}, ${slide.to ?? \"#101a33\"})`,\n                }}\n              />\n              <div className=\"hb-za2-copy\">\n                <b>{slide.title}</b>\n                {slide.caption ? <span>{slide.caption}</span> : null}\n              </div>\n            </div>\n          ))}\n        </div>\n      </div>\n      <div className=\"hb-za2-bar\">\n        <div className=\"hb-za2-count\">\n          <Digits value={index + 1} width={width} />\n          <span className=\"hb-za2-sep\" aria-hidden=\"true\">/</span>\n          <span className=\"hb-za2-total\" aria-hidden=\"true\">{String(total).padStart(width, \"0\")}</span>\n          <span className=\"hb-za2-sr\" role=\"status\" aria-live=\"polite\">\n            Slide {index + 1} of {total}\n          </span>\n        </div>\n        <div className=\"hb-za2-meter\" aria-hidden=\"true\">\n          <span />\n        </div>\n        <div className=\"hb-za2-arrows\">\n          <button type=\"button\" className=\"hb-za2-btn\" aria-label=\"Previous slide\" disabled={index === 0} onClick={() => set(index - 1)}>\n            <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d=\"M10 3 5 8l5 5\" />\n            </svg>\n          </button>\n          <button type=\"button\" className=\"hb-za2-btn\" aria-label=\"Next slide\" disabled={index === total - 1} onClick={() => set(index + 1)}>\n            <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d=\"m6 3 5 5-5 5\" />\n            </svg>\n          </button>\n        </div>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}