{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pages",
  "title": "Pages",
  "description": "The arithmetic of pages, for the Pagination and the table data: the page count, the range a page shows, and the page that keeps the first item on screen when the page size changes.",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/lib/pages.ts",
      "content": "/*\n * The arithmetic of pages, for everything that splits items into them: the\n * Pagination and the table data. Pages are counted from 1.\n */\n\n/** `page` as a whole page from 1 to `pageCount`, which may be `Infinity` while the count is unknown. */\nexport function clampPage(page: number, pageCount: number): number {\n  if (!Number.isFinite(page)) return 1\n  return Math.min(Math.max(1, Math.round(page)), Math.max(1, Math.floor(pageCount)))\n}\n\n/** How many pages `count` items take; one page when nothing pages them, or when there are none. */\nexport function pageCountOf(count: number, pageSize: number | undefined): number {\n  if (!pageSize || pageSize <= 0) return 1\n  return Math.max(1, Math.ceil(Math.max(0, count) / pageSize))\n}\n\n/** The items a page shows, from 1, out of `count`: 11–20 of 42, or 0–0 of 0. */\nexport function pageRange(\n  page: number,\n  pageSize: number | undefined,\n  count: number,\n): { from: number; to: number; of: number } {\n  if (count <= 0) return { from: 0, to: 0, of: 0 }\n  if (!pageSize || pageSize <= 0) return { from: 1, to: count, of: count }\n  const from = (page - 1) * pageSize + 1\n  return {\n    from: Math.min(from, count),\n    to: Math.min(page * pageSize, count),\n    of: count,\n  }\n}\n\n/** The page that holds the first item of `page` once a page holds `to` items instead of `from`. */\nexport function pageForSize(page: number, from: number, to: number): number {\n  if (from <= 0 || to <= 0) return 1\n  return Math.floor(((Math.max(1, page) - 1) * from) / to) + 1\n}\n",
      "type": "registry:lib",
      "target": "@lib/pages.ts"
    }
  ],
  "type": "registry:lib"
}