{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "core-pagination",
  "type": "registry:lib",
  "title": "core/pagination",
  "description": "Framework-free behaviour shared by the ui-* components (pagination); no DOM, no lit. Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [],
  "registryDependencies": [
    "@kanok-ui/core-table"
  ],
  "files": [
    {
      "path": "src/core/pagination.ts",
      "type": "registry:lib",
      "target": "components/ui/core/pagination.ts",
      "content": "/**\n * Rules of a Carbon pagination bar: how many pages, which items the page shows, where previous /\n * next can go, and the texts (templates with `{min}`, `{max}`, `{total}`, `{page}`). With\n * `pagesUnknown` (cursor-based APIs) there is no last page unless the caller says so (`isLastPage`).\n */\nimport { pageCount } from './table.ts';\n\nexport interface PaginationState {\n    /** 1-based. */\n    page: number;\n    pageSize: number;\n    totalItems: number;\n    pagesUnknown?: boolean;\n    /** With `pagesUnknown`: this is the last page. */\n    isLastPage?: boolean;\n}\n\n/** \"10, 25,50\" → [10, 25, 50] (ignores what isn't a positive number). */\nexport const parsePageSizes = (sizes: string) =>\n    sizes\n        .split(',')\n        .map((s) => Number(s.trim()))\n        .filter((n) => n > 0);\n\n/** Fills `{name}` placeholders (unknown names become empty). */\nexport const fillText = (template: string, values: Record<string, number>) => template.replaceAll(/\\{(\\w+)\\}/g, (_, key: string) => String(values[key] ?? ''));\n\n/** Pages there are (at least 1); unbounded when unknown. */\nexport const lastPage = (s: PaginationState) => (s.pagesUnknown ? Number.POSITIVE_INFINITY : pageCount(s.totalItems, Math.max(1, s.pageSize)));\n\n/** The first and last item number the page shows (0–0 for an empty list of known size). */\nexport function itemRange(s: PaginationState) {\n    const min = s.totalItems === 0 && !s.pagesUnknown ? 0 : (s.page - 1) * s.pageSize + 1;\n    const max = s.pagesUnknown ? s.page * s.pageSize : Math.min(s.page * s.pageSize, s.totalItems);\n    return { min, max };\n}\n\n/** `page` kept within 1…last page. */\nexport const clampPage = (page: number, s: PaginationState) => Math.min(Math.max(1, page), lastPage(s));\n\n/** Whether Next is unavailable. */\nexport const atLastPage = (s: PaginationState) => (s.pagesUnknown ? !!s.isLastPage : s.page >= lastPage(s));\n"
    }
  ]
}
