{"version":3,"file":"PaginationRoot.cjs","sources":["../../src/Pagination/PaginationRoot.vue"],"sourcesContent":["<script lang=\"ts\">\nimport type { Ref } from 'vue'\nimport type { PrimitiveProps } from '@/Primitive'\nimport { createContext, useForwardExpose } from '@/shared'\n\ntype PaginationRootContext = {\n  page: Ref<number>\n  onPageChange: (value: number) => void\n  pageCount: Ref<number>\n  siblingCount: Ref<number>\n  disabled: Ref<boolean>\n  showEdges: Ref<boolean>\n}\n\nexport interface PaginationRootProps extends PrimitiveProps {\n  /** The controlled value of the current page. Can be binded as `v-model:page`. */\n  page?: number\n  /**\n   * The value of the page that should be active when initially rendered.\n   *\n   * Use when you do not need to control the value state.\n   */\n  defaultPage?: number\n  /** Number of items per page */\n  itemsPerPage: number\n  /** Number of items in your list */\n  total?: number\n  /** Number of sibling should be shown around the current page */\n  siblingCount?: number\n  /** When `true`, prevents the user from interacting with item */\n  disabled?: boolean\n  /** When `true`, always show first page, last page, and ellipsis */\n  showEdges?: boolean\n}\n\nexport type PaginationRootEmits = {\n  /** Event handler called when the page value changes */\n  'update:page': [value: number]\n}\n\nexport const [injectPaginationRootContext, providePaginationRootContext]\n  = createContext<PaginationRootContext>('PaginationRoot')\n</script>\n\n<script setup lang=\"ts\">\nimport { Primitive } from '@/Primitive'\nimport { useVModel } from '@vueuse/core'\nimport { computed, toRefs } from 'vue'\n\nconst props = withDefaults(defineProps<PaginationRootProps>(), {\n  as: 'nav',\n  total: 0,\n  siblingCount: 2,\n  defaultPage: 1,\n  showEdges: false,\n})\nconst emits = defineEmits<PaginationRootEmits>()\n\ndefineSlots<{\n  default: (props: {\n    /** Current page state */\n    page: typeof page.value\n    /** Number of pages */\n    pageCount: typeof pageCount.value\n  }) => any\n}>()\n\nconst { siblingCount, disabled, showEdges } = toRefs(props)\n\nuseForwardExpose()\nconst page = useVModel(props, 'page', emits, {\n  defaultValue: props.defaultPage,\n  passive: (props.page === undefined) as false,\n}) as Ref<number>\n\nconst pageCount = computed(() => Math.max(1, Math.ceil(props.total / (props.itemsPerPage || 1))))\n\nprovidePaginationRootContext({\n  page,\n  onPageChange(value) {\n    page.value = value\n  },\n  pageCount,\n  siblingCount,\n  disabled,\n  showEdges,\n})\n</script>\n\n<template>\n  <Primitive\n    :as=\"as\"\n    :as-child=\"asChild\"\n  >\n    <slot\n      :page=\"page\"\n      :page-count=\"pageCount\"\n    />\n  </Primitive>\n</template>\n"],"names":["createContext","toRefs","useForwardExpose","useVModel","computed"],"mappings":";;;;;;;;AAwCO,MAAM,CAAC,2BAAA,EAA6B,4BAA4B,CAAA,GACnEA,mCAAqC,gBAAgB;;;;;;;;;;;;;;;;AAQzD,IAAA,MAAM,KAAQ,GAAA,OAAA;AAOd,IAAA,MAAM,KAAQ,GAAA,MAAA;AAWd,IAAA,MAAM,EAAE,YAAc,EAAA,QAAA,EAAU,SAAU,EAAA,GAAIC,WAAO,KAAK,CAAA;AAE1D,IAAiBC,wCAAA,EAAA;AACjB,IAAA,MAAM,IAAO,GAAAC,cAAA,CAAU,KAAO,EAAA,MAAA,EAAQ,KAAO,EAAA;AAAA,MAC3C,cAAc,KAAM,CAAA,WAAA;AAAA,MACpB,OAAA,EAAU,MAAM,IAAS,KAAA;AAAA,KAC1B,CAAA;AAED,IAAA,MAAM,SAAY,GAAAC,YAAA,CAAS,MAAM,IAAA,CAAK,IAAI,CAAG,EAAA,IAAA,CAAK,IAAK,CAAA,KAAA,CAAM,KAAS,IAAA,KAAA,CAAM,YAAgB,IAAA,CAAA,CAAE,CAAC,CAAC,CAAA;AAEhG,IAA6B,4BAAA,CAAA;AAAA,MAC3B,IAAA;AAAA,MACA,aAAa,KAAO,EAAA;AAClB,QAAA,IAAA,CAAK,KAAQ,GAAA,KAAA;AAAA,OACf;AAAA,MACA,SAAA;AAAA,MACA,YAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACD,CAAA;;;;;;;;;;;;;;;;;;;;;"}