tdesign-vue
Version:
155 lines (147 loc) • 6.53 kB
JavaScript
/**
* tdesign v1.11.2
* (c) 2025 tdesign
* @license MIT
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var swiper_props = require('./props.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../utils/mixins.js');
require('vue');
require('../_chunks/dep-07fb8c0e.js');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-a4a18104.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-27dd8cc6.js');
require('dayjs');
require('../_chunks/dep-87c765cc.js');
require('../_chunks/dep-75cd6d52.js');
require('../_chunks/dep-b1a02818.js');
require('../_chunks/dep-3d8ab37d.js');
require('../_chunks/dep-ecccff93.js');
require('../_chunks/dep-a4308f57.js');
require('../_chunks/dep-a4cecac4.js');
require('../_chunks/dep-ab142eaf.js');
require('../_chunks/dep-6ad3de7c.js');
require('../_chunks/dep-e4278c54.js');
require('../_chunks/dep-fcf0662d.js');
require('../_chunks/dep-8b1e056e.js');
require('../_chunks/dep-5db8defc.js');
require('../_chunks/dep-6e4c473c.js');
require('../_chunks/dep-234b7c02.js');
require('../_chunks/dep-a4747856.js');
require('../_chunks/dep-932dd69e.js');
require('../_chunks/dep-9f4caea4.js');
require('../_chunks/dep-dbd838d6.js');
require('../_chunks/dep-b3120c1b.js');
require('../_chunks/dep-68ba2357.js');
require('../_chunks/dep-173eb46c.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
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__default["default"](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 = configProvider_configReceiver.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 = utils_mixins["default"](classPrefixMixins).extend({
name: "TSwiperItem",
props: _objectSpread(_objectSpread({}, swiper_props["default"]), 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__default["default"](_defineProperty__default["default"](_defineProperty__default["default"]({}, "".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, {})) || []]);
}
});
exports["default"] = _SwiperItem;
//# sourceMappingURL=swiper-item.js.map