UNPKG

tdesign-vue

Version:
130 lines (126 loc) 5.39 kB
/** * tdesign v1.12.1 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import props from './props.js'; import { getClassPrefixMixins } from '../config-provider/config-receiver.js'; import mixins from '../utils/mixins.js'; import 'vue'; import 'lodash-es'; import '../config-provider/context.js'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-c44a474d.js'; import '@babel/runtime/helpers/typeof'; import '../_chunks/dep-d639fbd7.js'; import 'dayjs'; import '../_chunks/dep-3c66615e.js'; import '../config-provider/type.js'; import '../_common/js/global-config/t.js'; import '@babel/runtime/helpers/slicedToArray'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var classPrefixMixins = getClassPrefixMixins("swiper"); var swiperItemProps = { index: { type: Number }, currentIndex: { type: Number }, isSwitching: { type: Boolean, "default": false }, getWrapAttribute: { type: Function }, swiperItemLength: { type: Number, "default": 0 } }; var CARD_SCALE = 210 / 332; var itemWidth = 0.415; var _SwiperItem = mixins(classPrefixMixins).extend({ name: "TSwiperItem", props: _objectSpread(_objectSpread({}, props), swiperItemProps), computed: { active: function active() { return this.index === this.currentIndex; }, disposeIndex: function disposeIndex() { if (this.type !== "card") return 0; if (this.currentIndex === 0 && this.index === this.swiperItemLength - 1) { return -1; } if (this.currentIndex === this.swiperItemLength - 1 && this.index === 0) { return this.swiperItemLength; } if (this.index < this.currentIndex - 1 && this.currentIndex - this.index >= this.swiperItemLength / 2) { return this.swiperItemLength + 1; } if (this.index > this.currentIndex + 1 && this.index - this.currentIndex >= this.swiperItemLength / 2) { return -2; } return this.index; }, translateX: function translateX() { if (this.type !== "card") return 0; var wrapWidth = this.getWrapAttribute("offsetWidth"); var translateIndex = !this.active && this.swiperItemLength > 2 ? this.disposeIndex : this.index; var inStage = Math.abs(translateIndex - this.currentIndex) <= 1; if (inStage) { return wrapWidth * ((translateIndex - this.currentIndex) * (1 - itemWidth * CARD_SCALE) - itemWidth + 1) / 2; } if (translateIndex < this.currentIndex) { return -itemWidth * (1 + CARD_SCALE) * wrapWidth / 2; } return (2 + itemWidth * (CARD_SCALE - 1)) * wrapWidth / 2; }, zIndex: function zIndex() { if (this.type !== "card") return 0; var translateIndex = !this.active && this.swiperItemLength > 2 ? this.disposeIndex : this.index; var isActivity = translateIndex === this.currentIndex; var inStage = Math.round(Math.abs(translateIndex - this.currentIndex)) <= 1; if (isActivity) { return 2; } if (inStage) { return 1; } return 0; }, itemStyle: function itemStyle() { if (this.animation === "fade") { return { opacity: this.active ? 1 : 0, transition: this.isSwitching ? "opacity ".concat(this.duration / 1e3, "s") : "", zIndex: this.active ? 1 : 0 }; } if (this.type === "card") { var translateIndex = !this.active && this.swiperItemLength > 2 ? this.disposeIndex : this.index; var isActivity = translateIndex === this.currentIndex; return { transform: "translateX(".concat(this.translateX, "px) scale(").concat(isActivity ? 1 : CARD_SCALE, ")"), transition: "transform ".concat(this.duration / 1e3, "s ease"), zIndex: this.zIndex }; } return {}; } }, render: function render() { var _this$$scopedSlots$de, _this$$scopedSlots; var h = arguments[0]; return h("div", { "class": ["".concat(this.classPrefix, "-swiper__container__item"), _defineProperty(_defineProperty(_defineProperty({}, "".concat(this.classPrefix, "-swiper__card"), this.type === "card"), "".concat(this.classPrefix, "-is-active"), this.type === "card" && this.active), "".concat(this.classPrefix, "-swiper__fade"), this.animation === "fade")], "style": this.itemStyle }, [((_this$$scopedSlots$de = (_this$$scopedSlots = this.$scopedSlots)["default"]) === null || _this$$scopedSlots$de === void 0 ? void 0 : _this$$scopedSlots$de.call(_this$$scopedSlots, {})) || []]); } }); export { _SwiperItem as default }; //# sourceMappingURL=swiper-item.js.map