{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "components-pagination",
  "type": "registry:component",
  "title": "Pagination",
  "description": "Previous and next controls around a stable-width page window",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-icons.json",
    "https://gpuixui.sudokw.com/gpuix-primitives.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/components/src/internal/button.tsx",
      "target": "@ui/gpuixui/components/internal/button.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { Props } from \"@gpuix/react\";\nimport type { ReactNode } from \"react\";\nimport {\n  Button as PrimitiveButton,\n  IconButton as PrimitiveIconButton,\n  actionOnColor as primitiveActionOnColor,\n  type ButtonVariant as PrimitiveVariant,\n} from \"../../primitives/button.js\";\nimport { cn } from \"../../tw/index.js\";\nimport * as Schema from \"effect/Schema\";\nimport type { Theme } from \"./theme.js\";\n\nconst ButtonVariants = Schema.Literals([\n  \"primary\",\n  \"secondary\",\n  \"ghost\",\n  \"danger\",\n  \"link\",\n]);\n\nexport type ButtonVariant = typeof ButtonVariants.Type;\n\nexport type ButtonSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface ButtonProps extends Props {\n  readonly variant?: ButtonVariant;\n\n  readonly size?: ButtonSize;\n\n  readonly disabled?: boolean;\n\n  readonly loading?: boolean;\n\n  readonly loadingLabel?: string;\n\n  readonly reducedMotion?: boolean;\n\n  readonly leading?: ReactNode;\n\n  readonly trailing?: ReactNode;\n}\n\nexport interface IconButtonProps extends Props {\n  readonly label: string;\n\n  readonly size?: ButtonSize;\n  readonly disabled?: boolean;\n}\n\ninterface Look {\n  readonly variant: PrimitiveVariant;\n  readonly className: string;\n}\n\nconst LOOKS: Readonly<Record<ButtonVariant, Look>> = {\n  primary: { variant: \"primary\", className: \"\" },\n  secondary: { variant: \"secondary\", className: \"border border-strong\" },\n  ghost: { variant: \"ghost\", className: \"\" },\n  danger: { variant: \"destructive\", className: \"\" },\n\n  link: { variant: \"link\", className: \"underline underline-offset-4\" },\n};\n\nconst lookOf = (variant: unknown): Look =>\n  LOOKS[Schema.is(ButtonVariants)(variant) ? variant : \"secondary\"];\n\nexport const actionOnColor = (theme: Theme, variant: ButtonVariant): string =>\n  primitiveActionOnColor(theme, lookOf(variant).variant);\n\nexport const Button = ({\n  variant = \"secondary\",\n  size = \"md\",\n  disabled = false,\n  onClick,\n  style,\n  \"aria-label\": ariaLabel,\n  ...rest\n}: ButtonProps) => {\n  const look = lookOf(variant);\n  return (\n    <PrimitiveButton\n      {...rest}\n      variant={look.variant}\n      size={size}\n      disabled={disabled}\n      label={ariaLabel}\n      className={cn(look.className)}\n      onActivate={onClick}\n      style={style}\n    />\n  );\n};\n\nexport const IconButton = ({\n  label,\n  size = \"md\",\n  disabled = false,\n  onClick,\n  style,\n  children,\n  ...rest\n}: IconButtonProps) => (\n  <PrimitiveIconButton\n    {...rest}\n    icon={children}\n    variant=\"ghost\"\n    size={size}\n    disabled={disabled}\n    label={label}\n    className=\"text-muted-foreground hover:text-foreground\"\n    onActivate={onClick}\n    style={style}\n  />\n);\n"
    },
    {
      "path": "packages/components/src/internal/parts.ts",
      "target": "@ui/gpuixui/components/internal/parts.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\nimport * as P from \"effect/Predicate\";\nimport {\n  Children,\n  Fragment,\n  isValidElement,\n  type ReactElement,\n  type ReactNode,\n} from \"react\";\n\nexport type PartComponent = (props: never) => ReactNode;\n\nexport type PartChildren =\n  | ReactElement<unknown>\n  | boolean\n  | null\n  | undefined\n  | ReadonlyArray<PartChildren>;\n\nexport interface PartsContract {\n  readonly parent: string;\n\n  readonly family: ReadonlyArray<PartComponent>;\n\n  readonly accepts: ReadonlyArray<PartComponent>;\n\n  readonly hint?: string;\n}\n\nconst componentName = (type: unknown): string =>\n  P.isString(type)\n    ? type\n    : P.isFunction(type)\n      ? type.name || \"anonymous\"\n      : \"element\";\n\nconst fragmentChildren = (element: ReactElement<unknown>): ReactNode =>\n  hasChildren(element.props) ? element.props.children : undefined;\n\nconst hasChildren = (\n  value: unknown,\n): value is { readonly children?: ReactNode } =>\n  P.isObject(value) && \"children\" in value;\n\nconst leaves = (children: ReactNode): ReadonlyArray<unknown> =>\n  Arr.flatMap(Children.toArray(children), (child) =>\n    isValidElement<unknown>(child) && child.type === Fragment\n      ? leaves(fragmentChildren(child))\n      : [child],\n  );\n\nexport const assertParts = (\n  contract: PartsContract,\n  children: ReactNode,\n): void => {\n  Arr.forEach(leaves(children), (leaf) => {\n    if (!isValidElement(leaf)) return;\n    if (Arr.some(contract.accepts, (part) => part === leaf.type)) return;\n    if (!Arr.some(contract.family, (part) => part === leaf.type)) return;\n\n    throw new Error(\n      `${componentName(leaf.type)} cannot be used inside ${contract.parent}.` +\n        (contract.hint === undefined ? \"\" : ` ${contract.hint}`),\n    );\n  });\n};\n"
    },
    {
      "path": "packages/components/src/internal/recipe.ts",
      "target": "@ui/gpuixui/components/internal/recipe.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { createRecipeCache } from \"../../tw/index.js\";\nimport type { Theme } from \"./theme.js\";\n\nexport const recipeStyle: (recipe: string, theme: Theme) => StyleDesc =\n  createRecipeCache(512);\n"
    },
    {
      "path": "packages/components/src/internal/theme.ts",
      "target": "@ui/gpuixui/components/internal/theme.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport * as Schema from \"effect/Schema\";\nimport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  brandTextOn,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  pointerWash,\n  selectionOn,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n  type BoxShadow,\n  type ElevationLevel,\n  type FindHighlightSource,\n  type NativeTextFill,\n  type PlatformName,\n  type PointerWashSurface,\n  type StatusTone,\n  type SyntaxColors,\n  type SyntaxRole,\n  type TextRole,\n  type Theme,\n  type ThemeColors,\n} from \"../../tokens/index.js\";\n\nexport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n};\nexport type {\n  BoxShadow,\n  ElevationLevel,\n  FindHighlightSource,\n  NativeTextFill,\n  PlatformName,\n  StatusTone,\n  SyntaxColors,\n  SyntaxRole,\n  TextRole,\n  Theme,\n};\nexport { ThemeProvider, useTheme } from \"../../tokens/react.js\";\n\nexport const keyboardRing = (theme: Theme, invalid = false): StyleDesc =>\n  controlFocusRing(theme, { invalid }) ?? {};\n\nexport interface ControlRingState {\n  readonly disabled?: boolean;\n\n  readonly invalid?: boolean;\n}\n\nexport const controlRing = (\n  theme: Theme,\n  state: ControlRingState = {},\n): StyleDesc => controlFocusRing(theme, state) ?? {};\n\nexport const pressWash = (theme: Theme, replaced: PointerWashSurface): string =>\n  pointerWash(theme, \"active\", replaced) ?? theme.colors.active;\n\nexport const selectionWash = (theme: Theme): StyleDesc => ({\n  selectionColor: theme.colors.selection,\n});\n\nexport const keepContent: StyleDesc = { keyboardFocusDim: false };\n\nexport const disabledFade = (\n  disabled: boolean,\n): { readonly opacity: number } | undefined =>\n  disabled ? { opacity: disabledOpacity } : undefined;\n\nconst Tones = Schema.Literals([\"info\", \"success\", \"warning\", \"danger\"]);\n\nexport type Tone = typeof Tones.Type;\n\nexport const toneOf = (value: unknown): Tone =>\n  Schema.is(Tones)(value) ? value : \"info\";\n\nexport interface ToneStyle {\n  readonly fg: string;\n  readonly bg: string;\n  readonly border: string;\n}\n\nconst TOKEN_TONE: Readonly<Record<Tone, StatusTone>> = {\n  info: \"info\",\n  success: \"success\",\n  warning: \"warning\",\n  danger: \"destructive\",\n};\n\nexport const tone = (theme: Theme, value: Tone): ToneStyle => {\n  const { background, border, foreground } = statusTone(\n    theme,\n    TOKEN_TONE[value],\n  );\n  return { bg: background, border, fg: foreground };\n};\n\nconst softRoles: Readonly<Record<Tone, keyof ThemeColors>> = {\n  info: \"infoSoft\",\n  success: \"successSoft\",\n  warning: \"warningSoft\",\n  danger: \"destructiveSoft\",\n};\n\nexport const messageLink = (theme: Theme, value: Tone): string =>\n  brandTextOn(theme, softRoles[value]);\n\nexport const messageSelection = (theme: Theme, value: Tone): string =>\n  selectionOn(theme, softRoles[value]);\n\nexport const toneSurface = (theme: Theme, value: Tone): StyleDesc => {\n  const { bg, border, fg } = tone(theme, value);\n  return {\n    backgroundColor: bg,\n    color: fg,\n    borderWidth: theme.borderWidth.thin,\n    borderColor: border,\n  };\n};\n"
    },
    {
      "path": "packages/components/src/pagination.tsx",
      "target": "@ui/gpuixui/components/pagination.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { Props } from \"@gpuix/react\";\nimport {\n  mergeStyles,\n  resolveStyle,\n  type StateStyle,\n} from \"@gpuix/react/floating\";\nimport { Icon } from \"../icons/index.js\";\nimport {\n  cn,\n  PAGINATION_ELLIPSIS,\n  PAGINATION_LIST,\n  PAGINATION_ROOT,\n} from \"../tw/index.js\";\nimport * as Arr from \"effect/Array\";\nimport { createContext, useContext, useMemo } from \"react\";\nimport { Button } from \"./internal/button.js\";\nimport {\n  assertParts,\n  type PartChildren,\n  type PartComponent,\n  type PartsContract,\n} from \"./internal/parts.js\";\nimport { recipeStyle } from \"./internal/recipe.js\";\nimport { controlHeight, useTheme } from \"./internal/theme.js\";\nimport {\n  pageWindow,\n  paginationRange,\n  type PageItem,\n} from \"./pagination/logic.js\";\n\ninterface PaginationContextValue {\n  readonly current: number;\n  readonly pageCount: number;\n  readonly onPageChange: (page: number) => void;\n\n  readonly window: ReadonlyArray<PageItem>;\n}\n\nconst PaginationContext = createContext<PaginationContextValue | undefined>(\n  undefined,\n);\n\nconst usePagination = (): PaginationContextValue => {\n  const value = useContext(PaginationContext);\n  if (value === undefined) {\n    throw new Error(\"Pagination parts must be used inside Pagination\");\n  }\n  return value;\n};\n\nexport interface PaginationProps extends Omit<Props, \"children\"> {\n  readonly page: number;\n\n  readonly pageCount: number;\n  readonly onPageChange: (page: number) => void;\n\n  readonly siblingCount?: number;\n\n  readonly showEdges?: boolean;\n  readonly className?: string;\n  readonly children?: PartChildren;\n}\n\nexport const Pagination = ({\n  page,\n  pageCount,\n  onPageChange,\n  siblingCount = 1,\n  showEdges = true,\n  className,\n  children,\n  style,\n  ...rest\n}: PaginationProps) => {\n  const theme = useTheme();\n  const { current, pageCount: count } = paginationRange(page, pageCount);\n  const window = useMemo(\n    () =>\n      pageWindow({\n        page: current,\n        pageCount: count,\n        siblingCount,\n        showEdges,\n      }),\n    [current, count, siblingCount, showEdges],\n  );\n\n  if (count === 0) return null;\n\n  assertParts(paginationRoot, children);\n\n  return (\n    <PaginationContext.Provider\n      value={{ current, pageCount: count, onPageChange, window }}\n    >\n      <div\n        role=\"navigation\"\n        aria-label=\"Pagination\"\n        {...rest}\n        style={mergeStyles(\n          recipeStyle(cn(PAGINATION_ROOT, className), theme),\n          style,\n        )}\n      >\n        {children}\n      </div>\n    </PaginationContext.Provider>\n  );\n};\n\nexport type PaginationPreviousProps = Props;\n\nexport const PaginationPrevious = ({\n  style,\n  ...rest\n}: PaginationPreviousProps) => {\n  const theme = useTheme();\n  const { current, onPageChange } = usePagination();\n\n  return (\n    <Button\n      variant=\"ghost\"\n      size=\"sm\"\n      aria-label=\"Previous page\"\n      disabled={current <= 1}\n      onClick={() => onPageChange(current - 1)}\n      {...rest}\n      style={mergeStyles(\n        {\n          paddingLeft: theme.spacing.sm,\n          paddingRight: theme.spacing.sm,\n        },\n        style,\n      )}\n    >\n      <Icon name=\"chevron-left\" size=\"md\" color={theme.colors.foreground} />\n      Prev\n    </Button>\n  );\n};\n\nexport type PaginationNextProps = Props;\n\nexport const PaginationNext = ({ style, ...rest }: PaginationNextProps) => {\n  const theme = useTheme();\n  const { current, pageCount, onPageChange } = usePagination();\n\n  return (\n    <Button\n      variant=\"ghost\"\n      size=\"sm\"\n      aria-label=\"Next page\"\n      disabled={current >= pageCount}\n      onClick={() => onPageChange(current + 1)}\n      {...rest}\n      style={mergeStyles(\n        {\n          paddingLeft: theme.spacing.sm,\n          paddingRight: theme.spacing.sm,\n        },\n        style,\n      )}\n    >\n      Next\n      <Icon name=\"chevron-right\" size=\"md\" color={theme.colors.foreground} />\n    </Button>\n  );\n};\n\nexport interface PaginationListProps extends Props {\n  readonly className?: string;\n}\n\nexport const PaginationList = ({\n  className,\n  style,\n  ...rest\n}: PaginationListProps) => {\n  const theme = useTheme();\n  const { window } = usePagination();\n\n  return (\n    <div\n      {...rest}\n      style={mergeStyles(\n        recipeStyle(cn(PAGINATION_LIST, className), theme),\n        style,\n      )}\n    >\n      {Arr.map(window, (entry) =>\n        entry.kind === \"page\" ? (\n          <PaginationItem key={`page-${entry.page}`} page={entry.page} />\n        ) : (\n          <PaginationEllipsis key={`gap-${entry.side}`} />\n        ),\n      )}\n    </div>\n  );\n};\n\nexport interface PaginationItemProps extends Omit<Props, \"style\"> {\n  readonly page: number;\n\n  readonly style?: StateStyle<PaginationItemState>;\n}\n\nexport interface PaginationItemState {\n  readonly active: boolean;\n}\n\nexport const PaginationItem = ({\n  page,\n  style,\n  ...rest\n}: PaginationItemProps) => {\n  const theme = useTheme();\n  const { current, onPageChange } = usePagination();\n  const isCurrent = page === current;\n  const height = controlHeight(theme, \"sm\");\n  const state: PaginationItemState = { active: isCurrent };\n\n  return (\n    <Button\n      variant={isCurrent ? \"primary\" : \"ghost\"}\n      size=\"sm\"\n      aria-label={`Page ${page}`}\n      aria-selected={isCurrent}\n      onClick={isCurrent ? undefined : () => onPageChange(page)}\n      {...rest}\n      style={mergeStyles(\n        {\n          height,\n          minWidth: height,\n          paddingLeft: 0,\n          paddingRight: 0,\n        },\n        resolveStyle(style, state),\n      )}\n    >\n      {String(page)}\n    </Button>\n  );\n};\n\nexport interface PaginationEllipsisProps extends Props {\n  readonly className?: string;\n}\n\nexport const PaginationEllipsis = ({\n  className,\n  style,\n  ...rest\n}: PaginationEllipsisProps) => {\n  const theme = useTheme();\n\n  return (\n    <div\n      {...rest}\n      style={mergeStyles(\n        recipeStyle(cn(PAGINATION_ELLIPSIS, className), theme),\n        style,\n      )}\n    >\n      <Icon\n        name=\"ellipsis\"\n        size=\"xs\"\n        color={theme.colors.mutedForeground}\n        label=\"More pages\"\n      />\n    </div>\n  );\n};\n\nconst paginationParts: ReadonlyArray<PartComponent> = [\n  Pagination,\n  PaginationPrevious,\n  PaginationNext,\n  PaginationList,\n  PaginationItem,\n  PaginationEllipsis,\n];\n\nconst paginationRoot: PartsContract = {\n  parent: \"Pagination\",\n  family: paginationParts,\n  accepts: [\n    PaginationPrevious,\n    PaginationList,\n    PaginationNext,\n\n    PaginationItem,\n    PaginationEllipsis,\n  ],\n  hint: \"Put PaginationPrevious, PaginationList and PaginationNext directly inside Pagination.\",\n};\n\nexport const paginationMeta = {\n  name: \"Pagination\",\n  tier: 2,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"no aria-current in 0.11.0; the current page carries aria-selected\",\n    \"page numbers are the only navigation: there is no page-size control\",\n  ],\n  docs: \"docs/pagination.mdx\",\n  example: \"examples/pagination.example.tsx\",\n  testFile: \"src/behaviour/pagination.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/components/src/pagination/logic.ts",
      "target": "@ui/gpuixui/components/pagination/logic.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\n\nexport type PageItem =\n  | { readonly kind: \"page\"; readonly page: number }\n  | { readonly kind: \"ellipsis\"; readonly side: \"start\" | \"end\" };\n\nexport interface PageWindowInput {\n  readonly page: number;\n\n  readonly pageCount: number;\n\n  readonly siblingCount?: number;\n\n  readonly showEdges?: boolean;\n}\n\nconst page = (value: number): PageItem => ({ kind: \"page\", page: value });\n\nconst ellipsis = (side: \"start\" | \"end\"): PageItem => ({\n  kind: \"ellipsis\",\n  side,\n});\n\nconst clamp = (value: number, low: number, high: number): number =>\n  Math.min(Math.max(value, low), high);\n\nconst countable = (value: number, fallback: number): number =>\n  Number.isFinite(value) ? Math.max(0, Math.trunc(value)) : fallback;\n\nexport const paginationRange = (\n  page: number,\n  pageCount: number,\n): { readonly current: number; readonly pageCount: number } => {\n  const count = countable(pageCount, 0);\n  return {\n    current:\n      count === 0\n        ? 1\n        : clamp(Number.isFinite(page) ? Math.trunc(page) : 1, 1, count),\n    pageCount: count,\n  };\n};\n\nconst pages = (from: number, to: number): ReadonlyArray<PageItem> =>\n  Arr.map(Arr.range(from, Math.max(from, to)), page);\n\nconst between = (\n  low: number,\n  high: number,\n  side: \"start\" | \"end\",\n): ReadonlyArray<PageItem> => {\n  const hidden = high - low - 1;\n  if (hidden <= 0) return [];\n  if (hidden === 1) return [page(low + 1)];\n  return [ellipsis(side)];\n};\n\nexport const pageWindow = ({\n  page: rawPage,\n  pageCount: rawPageCount,\n  siblingCount: rawSiblingCount = 1,\n  showEdges = true,\n}: PageWindowInput): ReadonlyArray<PageItem> => {\n  const { current, pageCount } = paginationRange(rawPage, rawPageCount);\n  if (pageCount === 0) return [];\n\n  const siblings = countable(rawSiblingCount, 1);\n  const left = Math.max(current - siblings, 1);\n  const right = Math.min(current + siblings, pageCount);\n\n  if (!showEdges) return pages(left, right);\n  if (siblings + 5 >= pageCount) return pages(1, pageCount);\n\n  const showStart = left > 2;\n  const showEnd = right < pageCount - 2;\n\n  if (showStart && showEnd) {\n    return [\n      page(1),\n      ...between(1, left, \"start\"),\n      ...pages(left, right),\n      ...between(right, pageCount, \"end\"),\n      page(pageCount),\n    ];\n  }\n  if (showStart) {\n    const from = Math.max(pageCount - (2 + 2 * siblings), 2);\n    return [page(1), ...between(1, from, \"start\"), ...pages(from, pageCount)];\n  }\n  const to = Math.min(3 + 2 * siblings, pageCount - 2);\n  return [...pages(1, to), ...between(to, pageCount, \"end\"), page(pageCount)];\n};\n"
    }
  ],
  "docs": "[Pagination](https://gpuixui.sudokw.com/components/pagination) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/components/pagination",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}