{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "core-pagination-nav",
  "type": "registry:lib",
  "title": "core/pagination-nav",
  "description": "Framework-free behaviour shared by the ui-* components (pagination-nav); 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": [],
  "files": [
    {
      "path": "src/core/pagination-nav.ts",
      "type": "registry:lib",
      "target": "components/ui/core/pagination-nav.ts",
      "content": "/**\n * Carbon `PaginationNav` behaviour, framework-free: which page buttons show, where the \"…\" overflow\n * selects go and how they follow the current page (Carbon's `calculateCuts` and `pageWouldBeHidden`,\n * the same in @carbon/react and @carbon/web-components). Pages are 0-based, as Carbon's.\n */\nexport interface NavCuts {\n    /** Pages hidden after the first one (in the front overflow select). */\n    front: number;\n    /** Pages hidden before the last one (in the back overflow select). */\n    back: number;\n}\n\nexport type NavSize = 'sm' | 'md' | 'lg';\n\n/** How many page items show: `itemsShown` (at least 4); on a narrow screen Carbon falls back to a number by size. */\nexport function navItemsShown(itemsShown: number, size: NavSize = 'lg', narrow = false): number {\n    let bySize = 4;\n    if (size === 'md') bySize = itemsShown === 4 ? itemsShown : 5;\n    else if (size === 'sm') bySize = Math.min(Math.max(itemsShown, 4), 7);\n    return Math.max(itemsShown >= 4 && !narrow ? itemsShown : bySize, 4);\n}\n\n/** The pages hidden in front of and behind the current one so that `shown` items fit (Carbon `calculateCuts`). */\nexport function calculateCuts(page: number, total: number, shown: number, splitPoint: number | null = null): NavCuts {\n    if (shown >= total) return { front: 0, back: 0 };\n    const split = splitPoint || Math.ceil(shown / 2) - 1;\n    let front = page + 1 - split;\n    let back = total - page - (shown - split) + 1;\n    if (front <= 1) {\n        back -= front <= 0 ? Math.abs(front) + 1 : 0;\n        front = 0;\n    }\n    if (back <= 1) {\n        front -= back <= 0 ? Math.abs(back) + 1 : 0;\n        back = 0;\n    }\n    return { front, back };\n}\n\n/** Whether `page` sits in an overflow (or is the first page while there is a front one) with these cuts. */\nfunction hidden(page: number, total: number, shown: number, cuts: NavCuts) {\n    const inFront = (page >= (shown <= 4 && page > 1 ? 0 : 1) && page <= cuts.front) || page === 0;\n    const inBack = page >= total - cuts.back - 1 && page <= total - 2;\n    return inFront || inBack;\n}\n\n/** The cuts after moving from `previous` to `page`: unchanged while the page is visible, else recut toward where it went (Carbon). */\nexport function nextCuts(cuts: NavCuts, page: number, previous: number, total: number, shown: number): NavCuts {\n    if (!hidden(page, total, shown, cuts)) return cuts;\n    const backward = shown > 4 ? 2 : 1;\n    const split = page > previous ? shown - 3 : backward;\n    return calculateCuts(page, total, shown, split);\n}\n\nexport type NavItem = { kind: 'page'; page: number; active: boolean } | { kind: 'overflow'; from: number; count: number };\n\n/** The row, in order: the first page, the front overflow, the pages around the current one, the back overflow, the last page. */\nexport function navItems(page: number, total: number, shown: number, cuts: NavCuts): NavItem[] {\n    const item = (p: number): NavItem => ({ kind: 'page', page: p, active: p === page });\n    const overflow = (from: number, count: number): NavItem[] => {\n        if (count > 1) return [{ kind: 'overflow', from, count }];\n        return count === 1 ? [item(from)] : [];\n    };\n    const startOffset = shown <= 4 && page > 1 ? 0 : 1;\n    const items: NavItem[] = [];\n    if (shown >= 5 || (shown <= 4 && page <= 1)) items.push(item(0));\n    items.push(...overflow(startOffset, cuts.front));\n    for (let p = startOffset + cuts.front; p < total - (1 + cuts.back); p++) items.push(item(p));\n    items.push(...overflow(total - cuts.back - 1, cuts.back));\n    if (total > 1) items.push(item(total - 1));\n    return items;\n}\n\n/** The page Previous / Next go to (wrapping with `loop`), or the same page at an end. */\nexport function navStep(page: number, total: number, delta: -1 | 1, loop: boolean): number {\n    const next = page + delta;\n    if (next < 0) return loop ? total - 1 : 0;\n    if (next >= total) return loop ? 0 : total - 1;\n    return next;\n}\n"
    }
  ]
}
