UNPKG

tdesign-mobile-vue

Version:
95 lines (91 loc) 3.46 kB
/** * tdesign v1.7.0 * (c) 2024 TDesign Group * @license MIT */ import { defineComponent, inject, ref, getCurrentInstance, computed, watch, onMounted, onUnmounted, createVNode } from 'vue'; import { useElementBounding } from '@vueuse/core'; import { usePrefixClass } from '../hooks/useClass.js'; import { useTNodeJSX } from '../hooks/tnode.js'; import config from '../config.js'; import '../config-provider/useConfig.js'; import '@babel/runtime/helpers/defineProperty'; import 'lodash/isFunction'; import 'lodash/cloneDeep'; import 'lodash/isString'; import '../config-provider/context.js'; import 'lodash/mergeWith'; import 'lodash/merge'; import 'lodash/isArray'; import '../_common/js/global-config/mobile/default-config.js'; import '../_common/js/global-config/mobile/locale/zh_CN.js'; import '../_chunks/dep-6c582337.js'; import '@babel/runtime/helpers/typeof'; import '../_chunks/dep-38637d40.js'; import 'dayjs'; import '../_chunks/dep-959cdc59.js'; import '../config-provider/type.js'; import 'lodash/camelCase'; import 'lodash/kebabCase'; import '../hooks/render-tnode.js'; import 'lodash/isEmpty'; import 'lodash/isObject'; var prefix = config.prefix; var _SwiperItem = defineComponent({ name: "".concat(prefix, "-swiper-item"), setup: function setup() { var _inject = inject("parent"), addChild = _inject.addChild, removeChild = _inject.removeChild, isVertical = _inject.isVertical, root = _inject.root, items = _inject.items, setContainerHeight = _inject.setContainerHeight; var swiperItemClass = usePrefixClass("swiper-item"); var readerTNodeJSX = useTNodeJSX(); var selfRef = ref(null); var rootStyle = ref(""); var instance = getCurrentInstance(); var direction = computed(function () { return isVertical.value ? "Y" : "X"; }); var calcTranslateStyle = function calcTranslateStyle(index, activeIndex) { var _root$value, _root$value2; var distance = (_root$value = (_root$value2 = root.value) === null || _root$value2 === void 0 ? void 0 : _root$value2[isVertical.value ? "offsetHeight" : "offsetWidth"]) !== null && _root$value !== void 0 ? _root$value : 0; var lastItemIndex = items.value.length - 1; var step = index - activeIndex; if (activeIndex === lastItemIndex && index === 0) { step = 1; } if (activeIndex === 0 && index === lastItemIndex && index !== 1) { step = -1; } if (activeIndex === index) step = 0; rootStyle.value = "transform: translate".concat(direction.value, "(").concat(step * distance, "px)"); }; var _useElementBounding = useElementBounding(selfRef), height = _useElementBounding.height; watch(height, function (val) { setContainerHeight(val); }); onMounted(function () { addChild({ proxy: instance === null || instance === void 0 ? void 0 : instance.proxy, uid: instance === null || instance === void 0 ? void 0 : instance.uid, calcTranslateStyle: calcTranslateStyle }); }); onUnmounted(function () { removeChild(instance === null || instance === void 0 ? void 0 : instance.uid); }); return function () { return createVNode("div", { "ref": selfRef, "class": swiperItemClass.value, "style": rootStyle.value }, [readerTNodeJSX("default")]); }; } }); export { _SwiperItem as default }; //# sourceMappingURL=swiper-item.js.map