You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
28 KiB

1 month ago
  1. {"ast":null,"code":"import { getCurrentInstance, useSlots, ref, computed, unref, isVNode, watch, shallowRef, onMounted, onBeforeUnmount, provide } from 'vue';\nimport { throttle } from 'lodash-unified';\nimport { useResizeObserver } from '@vueuse/core';\nimport { CAROUSEL_ITEM_NAME, carouselContextKey } from './constants.mjs';\nimport { useOrderedChildren } from '../../../hooks/use-ordered-children/index.mjs';\nimport { isString } from '@vue/shared';\nimport { debugWarn } from '../../../utils/error.mjs';\nimport { flattedChildren } from '../../../utils/vue/vnode.mjs';\nconst THROTTLE_TIME = 300;\nconst useCarousel = (props, emit, componentName) => {\n const {\n children: items,\n addChild: addItem,\n removeChild: removeItem\n } = useOrderedChildren(getCurrentInstance(), CAROUSEL_ITEM_NAME);\n const slots = useSlots();\n const activeIndex = ref(-1);\n const timer = ref(null);\n const hover = ref(false);\n const root = ref();\n const containerHeight = ref(0);\n const isItemsTwoLength = ref(true);\n const isFirstCall = ref(true);\n const isTransitioning = ref(false);\n const arrowDisplay = computed(() => props.arrow !== \"never\" && !unref(isVertical));\n const hasLabel = computed(() => {\n return items.value.some(item => item.props.label.toString().length > 0);\n });\n const isCardType = computed(() => props.type === \"card\");\n const isVertical = computed(() => props.direction === \"vertical\");\n const containerStyle = computed(() => {\n if (props.height !== \"auto\") {\n return {\n height: props.height\n };\n }\n return {\n height: `${containerHeight.value}px`,\n overflow: \"hidden\"\n };\n });\n const throttledArrowClick = throttle(index => {\n setActiveItem(index);\n }, THROTTLE_TIME, {\n trailing: true\n });\n const throttledIndicatorHover = throttle(index => {\n handleIndicatorHover(index);\n }, THROTTLE_TIME);\n const isTwoLengthShow = index => {\n if (!isItemsTwoLength.value) return true;\n return activeIndex.value <= 1 ? index <= 1 : index > 1;\n };\n function pauseTimer() {\n if (timer.value) {\n clearInterval(timer.value);\n timer.value = null;\n }\n }\n function startTimer() {\n if (props.interval <= 0 || !props.autoplay || timer.value) return;\n timer.value = setInterval(() => playSlides(), props.interval);\n }\n const playSlides = () => {\n if (!isFirstCall.value) {\n isTransitioning.value = true;\n }\n isFirstCall.value = false;\n if (activeIndex.value < items.value.length - 1) {\n activeIndex.value = activeIndex.value + 1;\n } else if (props.loop) {\n activeIndex.value = 0;\n } else {\n isTransitioning.value = false;\n }\n };\n function setActiveItem(index) {\n if (!isFirstCall.value) {\n isTransitioning.value = true;\n }\n isFirstCall.value = false;\n if (isString(index)) {\n const filteredItems = items.value.filter(item => item.props.name === index);\n if (filteredItems.length > 0) {\n index = items.value.indexOf(filteredItems[0]);\n }\n }\n index = Number(index);\n if (Number.isNaN(index) || index !== Math.floor(index)) {\n debugWarn(componentName, \"index must be integer.\");\n return;\n }\n const itemCount = items.value.length;\n const oldIndex = activeIndex.value;\n if (index < 0) {\n activeIndex.value = props.loop ? itemCount - 1 : 0;\n } else if (index >= itemCount) {\n activeIndex.value = props.loop ? 0 : itemCount - 1;\n } else {\n activeIndex.value = index;\n }\n if (oldIndex === activeIndex.value) {\n resetItemPosition(oldIndex);\n }\n resetTimer();\n }\n function resetItemPosition(oldIndex) {\n items.value.forEach((item, index) => {\n item.translateItem(index, activeIndex.value, oldIndex);\n });\n }\n function itemInStage(item, index) {\n var _a, _b, _c, _d;\n const _items = unref(items);\n const itemCount = _items.length;\n if (itemCount === 0 || !item.states.inStage) return false;\n const nextIte