{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pagination",
  "type": "registry:component",
  "title": "Pagination",
  "description": "Page navigation with ellipsis collapsing, an indicator that slides between pages and a compact variant with a page select.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "site",
    "pagination",
    "pages",
    "navigation",
    "table",
    "list",
    "paging"
  ],
  "docs": "https://hyperblur.dev/effects/pagination",
  "files": [
    {
      "path": "registry/hyperblur/pagination.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/pagination.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PaginationProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\"> {\n  total?: number;\n  page?: number;\n  defaultPage?: number;\n  onPageChange?: (page: number) => void;\n  siblings?: number;\n  boundaries?: number;\n  size?: \"sm\" | \"md\" | \"lg\";\n  variant?: \"full\" | \"compact\";\n  accent?: string;\n}\n\ntype Slot = number | \"gap-start\" | \"gap-end\";\n\nconst css = `\n.hb-pag {\n  --hb-pag-accent: #2f7bff;\n  --hb-pag-h: 34px;\n  --hb-pag-fs: 13px;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  box-sizing: border-box;\n  width: 100%;\n  color: #ededed;\n  font-family: inherit;\n  font-size: var(--hb-pag-fs);\n}\n.hb-pag *, .hb-pag *::before, .hb-pag *::after { box-sizing: border-box; }\n.hb-pag[data-size=\"sm\"] { --hb-pag-h: 28px; --hb-pag-fs: 12px; }\n.hb-pag[data-size=\"lg\"] { --hb-pag-h: 40px; --hb-pag-fs: 14px; }\n.hb-pag-row {\n  display: flex;\n  align-items: center;\n  gap: 4px;\n  max-width: 100%;\n}\n.hb-pag-list {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 2px;\n  min-width: 0;\n}\n.hb-pag-ind {\n  position: absolute;\n  top: 0;\n  left: 0;\n  height: var(--hb-pag-h);\n  width: var(--hb-pag-w, 0px);\n  border-radius: calc(var(--hb-pag-h) * 0.3);\n  background: var(--hb-pag-accent);\n  box-shadow: 0 4px 14px color-mix(in srgb, var(--hb-pag-accent) 38%, transparent);\n  transform: translateX(var(--hb-pag-x, 0px));\n  opacity: 0;\n  pointer-events: none;\n}\n.hb-pag-list[data-ready=\"true\"] .hb-pag-ind { opacity: 1; }\n.hb-pag-list[data-anim=\"true\"] .hb-pag-ind {\n  transition: transform 0.38s cubic-bezier(0.34, 1.25, 0.64, 1), width 0.38s cubic-bezier(0.34, 1.25, 0.64, 1);\n}\n.hb-pag-btn {\n  position: relative;\n  z-index: 1;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  flex: none;\n  min-width: var(--hb-pag-h);\n  height: var(--hb-pag-h);\n  margin: 0;\n  padding: 0 calc(var(--hb-pag-h) * 0.28);\n  border: 0;\n  border-radius: calc(var(--hb-pag-h) * 0.3);\n  background: transparent;\n  color: #a1a1a1;\n  font: inherit;\n  font-weight: 500;\n  font-variant-numeric: tabular-nums;\n  line-height: 1;\n  cursor: pointer;\n  user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  transition: color 0.2s ease, background-color 0.2s ease, opacity 0.2s ease;\n}\n.hb-pag-btn:hover { color: #ededed; background: rgba(255, 255, 255, 0.07); }\n.hb-pag-btn[aria-current=\"page\"] { color: #fff; font-weight: 600; background: transparent; }\n.hb-pag-list:not([data-ready=\"true\"]) .hb-pag-btn[aria-current=\"page\"] { background: var(--hb-pag-accent); }\n.hb-pag-btn:focus-visible, .hb-pag-sel:focus-visible {\n  outline: 2px solid var(--hb-pag-accent);\n  outline-offset: 2px;\n}\n.hb-pag-nav {\n  border: 1px solid #262626;\n  background: #111111;\n  color: #ededed;\n}\n.hb-pag-nav:hover { border-color: #333333; background: #171717; }\n.hb-pag-nav[aria-disabled=\"true\"] { opacity: 0.35; cursor: not-allowed; pointer-events: none; }\n.hb-pag-nav svg, .hb-pag-sel-wrap svg { width: 14px; height: 14px; flex: none; }\n.hb-pag-gap {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  min-width: calc(var(--hb-pag-h) * 0.8);\n  height: var(--hb-pag-h);\n  color: #6b6b6b;\n  letter-spacing: 0.1em;\n  user-select: none;\n}\n.hb-pag-compact {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  color: #8f8f8f;\n}\n.hb-pag-sel-wrap {\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n}\n.hb-pag-sel {\n  appearance: none;\n  height: var(--hb-pag-h);\n  margin: 0;\n  padding: 0 28px 0 12px;\n  border: 1px solid #262626;\n  border-radius: calc(var(--hb-pag-h) * 0.3);\n  background: #111111;\n  color: #ededed;\n  font: inherit;\n  font-weight: 600;\n  font-variant-numeric: tabular-nums;\n  cursor: pointer;\n  transition: border-color 0.2s ease, background-color 0.2s ease;\n}\n.hb-pag-sel:hover { border-color: #333333; background: #171717; }\n.hb-pag-sel-wrap svg {\n  position: absolute;\n  right: 9px;\n  color: #8f8f8f;\n  pointer-events: none;\n}\n.hb-pag-total { white-space: nowrap; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-pag-list[data-anim=\"true\"] .hb-pag-ind, .hb-pag-btn, .hb-pag-sel { transition: none; }\n}\n`;\n\nfunction clamp(value: number, min: number, max: number) {\n  return Math.min(Math.max(value, min), max);\n}\n\nfunction buildSlots(total: number, page: number, siblings: number, boundaries: number): Slot[] {\n  const keep = new Set<number>();\n  for (let i = 1; i <= Math.min(boundaries, total); i += 1) {\n    keep.add(i);\n    keep.add(total - i + 1);\n  }\n  for (let i = page - siblings; i <= page + siblings; i += 1) {\n    if (i >= 1 && i <= total) keep.add(i);\n  }\n  keep.add(page);\n  const sorted = [...keep].sort((a, b) => a - b);\n  const slots: Slot[] = [];\n  sorted.forEach((n, index) => {\n    const prev = sorted[index - 1];\n    if (prev !== undefined) {\n      const gap = n - prev;\n      if (gap === 2) slots.push(prev + 1);\n      else if (gap > 2) slots.push(n < page ? \"gap-start\" : \"gap-end\");\n    }\n    slots.push(n);\n  });\n  return slots;\n}\n\nconst chevronLeft = (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n    <path d=\"M10 3.5 5.5 8 10 12.5\" />\n  </svg>\n);\nconst chevronRight = (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n    <path d=\"m6 3.5 4.5 4.5L6 12.5\" />\n  </svg>\n);\nconst chevronDown = (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n    <path d=\"m4 6.25 4 4 4-4\" />\n  </svg>\n);\n\nexport function Pagination({\n  total = 12,\n  page,\n  defaultPage = 1,\n  onPageChange,\n  siblings = 1,\n  boundaries = 1,\n  size = \"md\",\n  variant = \"full\",\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: PaginationProps) {\n  const count = Math.max(1, Math.floor(total));\n  const [inner, setInner] = React.useState(defaultPage);\n  const current = clamp(page !== undefined ? page : inner, 1, count);\n  const list = React.useRef<HTMLDivElement>(null);\n  const nav = React.useRef<HTMLElement>(null);\n  const buttons = React.useRef(new Map<number, HTMLButtonElement>());\n  const slots = React.useMemo(\n    () => buildSlots(count, current, Math.max(0, siblings), Math.max(0, boundaries)),\n    [count, current, siblings, boundaries],\n  );\n  const selectId = React.useId();\n\n  const measure = React.useCallback(() => {\n    const box = list.current;\n    const el = buttons.current.get(current);\n    if (!box) return;\n    if (!el) {\n      box.dataset.ready = \"false\";\n      return;\n    }\n    box.style.setProperty(\"--hb-pag-x\", `${el.offsetLeft}px`);\n    box.style.setProperty(\"--hb-pag-w\", `${el.offsetWidth}px`);\n    box.dataset.ready = \"true\";\n  }, [current]);\n\n  React.useLayoutEffect(() => {\n    measure();\n  }, [measure, slots, size, variant]);\n\n  React.useEffect(() => {\n    const box = list.current;\n    if (!box) return;\n    const frame = requestAnimationFrame(() => {\n      box.dataset.anim = \"true\";\n    });\n    let observer: ResizeObserver | undefined;\n    if (typeof ResizeObserver !== \"undefined\") {\n      observer = new ResizeObserver(measure);\n      observer.observe(box);\n    }\n    window.addEventListener(\"resize\", measure);\n    return () => {\n      cancelAnimationFrame(frame);\n      observer?.disconnect();\n      window.removeEventListener(\"resize\", measure);\n    };\n  }, [measure, variant, slots]);\n\n  function go(next: number) {\n    const target = clamp(next, 1, count);\n    if (target === current) return;\n    if (page === undefined) setInner(target);\n    onPageChange?.(target);\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLElement>) {\n    const keys = [\"ArrowLeft\", \"ArrowRight\", \"Home\", \"End\"];\n    if (!keys.includes(e.key)) return;\n    const target = e.target as HTMLElement;\n    if (target.tagName === \"SELECT\") return;\n    const focusables = Array.from(\n      nav.current?.querySelectorAll<HTMLElement>(\"button:not(:disabled)\") ?? [],\n    );\n    const index = focusables.indexOf(target);\n    if (index < 0) return;\n    let next = index;\n    if (e.key === \"ArrowLeft\") next = Math.max(0, index - 1);\n    else if (e.key === \"ArrowRight\") next = Math.min(focusables.length - 1, index + 1);\n    else if (e.key === \"Home\") next = 0;\n    else next = focusables.length - 1;\n    e.preventDefault();\n    focusables[next]?.focus();\n  }\n\n  const atStart = current <= 1;\n  const atEnd = current >= count;\n  const vars = { \"--hb-pag-accent\": accent, ...style } as React.CSSProperties;\n\n  const prev = (\n    <button\n      type=\"button\"\n      className=\"hb-pag-btn hb-pag-nav\"\n      aria-label=\"Previous page\"\n      aria-disabled={atStart}\n      onClick={() => go(current - 1)}\n    >\n      {chevronLeft}\n    </button>\n  );\n  const next = (\n    <button\n      type=\"button\"\n      className=\"hb-pag-btn hb-pag-nav\"\n      aria-label=\"Next page\"\n      aria-disabled={atEnd}\n      onClick={() => go(current + 1)}\n    >\n      {chevronRight}\n    </button>\n  );\n\n  return (\n    <nav\n      ref={nav}\n      aria-label=\"Pagination\"\n      className={`hb-pag ${className}`}\n      style={vars}\n      data-size={size}\n      data-variant={variant}\n      onKeyDown={handleKeyDown}\n      {...rest}\n    >\n      <style href=\"hb-pagination\" precedence=\"default\">{css}</style>\n      {variant === \"compact\" ? (\n        <div className=\"hb-pag-row\">\n          {prev}\n          <div className=\"hb-pag-compact\">\n            <label htmlFor={selectId}>Page</label>\n            <span className=\"hb-pag-sel-wrap\">\n              <select\n                id={selectId}\n                className=\"hb-pag-sel\"\n                value={current}\n                onChange={(e) => go(Number(e.target.value))}\n              >\n                {Array.from({ length: count }, (_, i) => (\n                  <option key={i + 1} value={i + 1}>\n                    {i + 1}\n                  </option>\n                ))}\n              </select>\n              {chevronDown}\n            </span>\n            <span className=\"hb-pag-total\">of {count}</span>\n          </div>\n          {next}\n        </div>\n      ) : (\n        <div className=\"hb-pag-row\">\n          {prev}\n          <div ref={list} className=\"hb-pag-list\">\n            <span className=\"hb-pag-ind\" aria-hidden=\"true\" />\n            {slots.map((slot) =>\n              typeof slot === \"number\" ? (\n                <button\n                  key={slot}\n                  ref={(el) => {\n                    if (el) buttons.current.set(slot, el);\n                    else buttons.current.delete(slot);\n                  }}\n                  type=\"button\"\n                  className=\"hb-pag-btn\"\n                  aria-label={`Page ${slot}`}\n                  aria-current={slot === current ? \"page\" : undefined}\n                  onClick={() => go(slot)}\n                >\n                  {slot}\n                </button>\n              ) : (\n                <span key={slot} className=\"hb-pag-gap\" aria-hidden=\"true\">\n                  &hellip;\n                </span>\n              ),\n            )}\n          </div>\n          {next}\n        </div>\n      )}\n    </nav>\n  );\n}\n"
    }
  ]
}