UNPKG

tdesign-vue

Version:
408 lines (400 loc) 16.9 kB
/** * tdesign v1.12.1 * (c) 2025 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var helper = require('../_chunks/dep-882fe8fa.js'); var _defineProperty = require('@babel/runtime/helpers/defineProperty'); var Vue = require('vue'); var tdesignIconsVue = require('tdesign-icons-vue'); var swiper_props = require('./props.js'); var swiper_swiperItem = require('./swiper-item.js'); var hooks_renderTnode = require('../hooks/render-tnode.js'); var utils_renderTnode = require('../utils/render-tnode.js'); var utils_event = require('../utils/event.js'); var configProvider_configReceiver = require('../config-provider/config-receiver.js'); var utils_mixins = require('../utils/mixins.js'); var kebabCase = require('../_chunks/dep-727a349e.js'); require('@vue/composition-api'); require('../_chunks/dep-51fe98f1.js'); require('@babel/runtime/helpers/typeof'); require('../_chunks/dep-6b60413b.js'); require('../_chunks/dep-5ea2b00f.js'); require('../_chunks/dep-9b72cbc5.js'); require('../_chunks/dep-d7270eaf.js'); require('../_chunks/dep-bf70543d.js'); require('../_chunks/dep-f895c884.js'); require('../_chunks/dep-e1cc6f64.js'); require('../_chunks/dep-7b78e8c3.js'); require('../_chunks/dep-68f48b50.js'); require('../_chunks/dep-051ce30d.js'); require('../_chunks/dep-4b30bfe2.js'); require('../_chunks/dep-411a10dd.js'); require('../_chunks/dep-f6069bb1.js'); require('../_chunks/dep-ed8c3176.js'); require('../_chunks/dep-4aa08166.js'); require('../_chunks/dep-ddc1429e.js'); require('../_chunks/dep-65896ff9.js'); require('../_chunks/dep-887c649b.js'); require('../_chunks/dep-28836b00.js'); require('../_chunks/dep-dea23841.js'); require('@babel/runtime/helpers/readOnlyError'); require('../utils/helper.js'); require('@babel/runtime/helpers/objectWithoutProperties'); require('@babel/runtime/helpers/slicedToArray'); require('../_chunks/dep-6247fdbf.js'); require('../_common/js/global-config/default-config.js'); require('../_common/js/global-config/locale/zh_CN.js'); require('../_chunks/dep-3ed0c42e.js'); require('../_chunks/dep-53935099.js'); require('dayjs'); require('../_chunks/dep-403352a7.js'); require('../_chunks/dep-cca66fee.js'); require('../_chunks/dep-4361b357.js'); require('../_chunks/dep-3d682642.js'); require('../_chunks/dep-b65b2f55.js'); require('../_chunks/dep-6e7b8cda.js'); require('../_chunks/dep-98f48ff2.js'); require('../_chunks/dep-80e3757f.js'); require('../_chunks/dep-08d7842c.js'); require('../_chunks/dep-1ca3138c.js'); require('../_chunks/dep-e6ed4b1f.js'); require('../_chunks/dep-c44b2462.js'); require('../_common/js/global-config/t.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue); 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 defaultNavigation = { placement: "inside", showSlideBtn: "always", size: "medium", type: "bars" }; var _Swiper = utils_mixins["default"](Vue__default["default"], classPrefixMixins, configProvider_configReceiver.getGlobalIconMixins()).extend(_objectSpread(_objectSpread({ name: "TSwiper", components: { TSwiperItem: swiper_swiperItem["default"] } }, { swiperTimer: 0, swiperSwitchingTimer: 0 }), {}, { props: _objectSpread({}, swiper_props["default"]), data: function data() { return { currentIndex: 0, isHovering: false, isSwitching: false, swiperItemList: [], showArrow: false }; }, computed: { swiperItemLength: function swiperItemLength() { return this.swiperItemList.length; }, navigationConfig: function navigationConfig() { return _objectSpread(_objectSpread({}, defaultNavigation), hooks_renderTnode.isVNode(this.navigation) ? {} : this.navigation); }, isEnd: function isEnd() { if (this.type === "card") { return !this.loop && this.currentIndex + 1 >= this.swiperItemLength; } return !this.loop && this.currentIndex + 2 >= this.swiperItemLength; }, propsToUpdateSetTimer: function propsToUpdateSetTimer() { return [this.autoplay, this.currentIndex, this.duration, this.interval]; }, swiperWrapClass: function swiperWrapClass() { return _defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"]({}, "".concat(this.componentName, "__wrap"), true), "".concat(this.componentName, "--inside"), this.navigationConfig.placement === "inside"), "".concat(this.componentName, "--outside"), this.navigationConfig.placement === "outside"), "".concat(this.componentName, "--vertical"), this.direction === "vertical"), "".concat(this.componentName, "--large"), this.navigationConfig.size === "large"), "".concat(this.componentName, "--small"), this.navigationConfig.size === "small"); }, containerStyle: function containerStyle() { var offsetHeight = this.height ? "".concat(this.height, "px") : "".concat(this.getWrapAttribute("offsetHeight"), "px"); if (this.type === "card" || this.animation === "fade") { return { height: offsetHeight }; } if (this.animation === "slide") { if (this.direction === "vertical") { return { height: offsetHeight, transform: "translate3d(0, -".concat(this.currentIndex * 100, "%, 0px)"), transition: this.isSwitching ? "transform ".concat(this.duration / 1e3, "s ease") : "" }; } return { msTransform: "translate3d(-".concat(this.currentIndex * 100, "%, 0px, 0px)"), WebkitTransform: "translate3d(-".concat(this.currentIndex * 100, "%, 0px, 0px)"), transform: "translate3d(-".concat(this.currentIndex * 100, "%, 0px, 0px)"), transition: this.isSwitching ? "transform ".concat(this.duration / 1e3, "s ease") : "" }; } return {}; }, swiperItems: function swiperItems() { var _this = this; var h = this.$createElement; return this.swiperItemList.map(function (swiperItem, index) { return h(swiper_swiperItem["default"], helper.helper([{ "attrs": { "index": index, "currentIndex": _this.currentIndex, "isSwitching": _this.isSwitching, "getWrapAttribute": _this.getWrapAttribute, "swiperItemLength": _this.swiperItemLength } }, { "props": _objectSpread(_objectSpread({}, _this.$props), swiperItem.propsData) }]), [swiperItem.children]); }); } }, watch: { propsToUpdateSetTimer: function propsToUpdateSetTimer() { this.setTimer(); }, isSwitching: function isSwitching() { var _this2 = this; if (this.isSwitching) { if (this.swiperSwitchingTimer) clearTimeout(this.swiperSwitchingTimer); this.swiperSwitchingTimer = setTimeout(function () { _this2.isSwitching = false; _this2.swiperSwitchingTimer = 0; if (_this2.isEnd) { _this2.clearTimer(); } }, this.duration + 50); } }, current: function current() { this.swiperTo(this.current, { source: "autoplay" }); } }, mounted: function mounted() { this.updateSwiperItems(); this.setTimer(); this.showArrow = this.navigationConfig.showSlideBtn === "always"; }, updated: function updated() { var _this3 = this; this.$nextTick(function () { _this3.updateSwiperItems(); }); }, methods: { updateSwiperItems: function updateSwiperItems() { var _this$$scopedSlots$de, _this$$scopedSlots, _this4 = this; var originalChildren = ((_this$$scopedSlots$de = (_this$$scopedSlots = this.$scopedSlots)["default"]) === null || _this$$scopedSlots$de === void 0 ? void 0 : _this$$scopedSlots$de.call(_this$$scopedSlots, {})) || []; var swiperItemList = originalChildren.map(function (swiper) { return swiper.componentOptions; }).filter(function (swiper) { return kebabCase.kebabCase(swiper === null || swiper === void 0 ? void 0 : swiper.tag).endsWith("".concat(_this4.componentName, "-item")); }); var isUnchange = swiperItemList.length === this.swiperItemList.length && this.swiperItemList.every(function (swiperItem, index) { return swiperItem === swiperItemList[index]; }); if (isUnchange) return; this.swiperItemList = swiperItemList; }, setTimer: function setTimer() { var _this5 = this; if (this.autoplay && this.interval > 0) { this.clearTimer(); this.swiperTimer = setTimeout(function () { _this5.swiperTo(_this5.currentIndex + 1, { source: "autoplay" }); }, this.currentIndex === 0 ? this.interval - (this.duration + 50) : this.interval); } }, clearTimer: function clearTimer() { if (this.swiperTimer) { clearTimeout(this.swiperTimer); this.swiperTimer = 0; } }, onMouseEnter: function onMouseEnter() { this.isHovering = true; if (this.stopOnHover) { this.clearTimer(); } if (this.navigationConfig.showSlideBtn === "hover") { this.showArrow = true; } }, onMouseLeave: function onMouseLeave() { this.isHovering = false; if (!this.isEnd) { this.setTimer(); } if (this.navigationConfig.showSlideBtn === "hover") { this.showArrow = false; } }, onMouseEnterNavigationItem: function onMouseEnterNavigationItem(i) { if (this.trigger === "hover") { this.swiperTo(i, { source: "hover" }); } }, onClickNavigationItem: function onClickNavigationItem(i) { if (this.trigger === "click") { this.swiperTo(i, { source: "click" }); } }, swiperTo: function swiperTo(index, context) { var targetIndex = index % this.swiperItemLength; utils_event.emitEvent(this, "change", targetIndex, context); this.isSwitching = true; this.currentIndex = targetIndex; }, goNext: function goNext(context) { if (this.isSwitching) return; if (this.type === "card") { return this.swiperTo(this.currentIndex + 1 >= this.swiperItemLength ? 0 : this.currentIndex + 1, context); } return this.swiperTo(this.currentIndex + 1, context); }, goPrevious: function goPrevious(context) { if (this.isSwitching) return; if (this.currentIndex - 1 < 0) { return this.swiperTo(this.swiperItemLength - 1, context); } return this.swiperTo(this.currentIndex - 1, context); }, getWrapAttribute: function getWrapAttribute(attr) { var _this$$refs$swiperWra; return (_this$$refs$swiperWra = this.$refs.swiperWrap) === null || _this$$refs$swiperWra === void 0 || (_this$$refs$swiperWra = _this$$refs$swiperWra.parentNode) === null || _this$$refs$swiperWra === void 0 ? void 0 : _this$$refs$swiperWra[attr]; }, renderPagination: function renderPagination() { var _this6 = this; var h = this.$createElement; var fractionIndex = this.currentIndex + 1 > this.swiperItemLength ? 1 : this.currentIndex + 1; var _this$useGlobalIcon = this.useGlobalIcon({ ChevronLeftIcon: tdesignIconsVue.ChevronLeftIcon, ChevronRightIcon: tdesignIconsVue.ChevronRightIcon }), ChevronLeftIcon = _this$useGlobalIcon.ChevronLeftIcon, ChevronRightIcon = _this$useGlobalIcon.ChevronRightIcon; return h("div", { "class": "".concat(this.componentName, "__arrow") }, [h("div", { "class": "".concat(this.componentName, "__arrow-left"), "on": { "click": function click() { return _this6.goPrevious({ source: "click" }); } } }, [h(ChevronLeftIcon)]), h("div", { "class": "".concat(this.componentName, "__navigation-text-fraction") }, [fractionIndex, "/", this.swiperItemLength]), h("div", { "class": "".concat(this.componentName, "__arrow-right"), "on": { "click": function click() { return _this6.goNext({ source: "click" }); } } }, [h(ChevronRightIcon)])]); }, renderArrow: function renderArrow() { var _this7 = this; var h = this.$createElement; if (!this.showArrow) return null; var _this$useGlobalIcon2 = this.useGlobalIcon({ ChevronLeftIcon: tdesignIconsVue.ChevronLeftIcon, ChevronRightIcon: tdesignIconsVue.ChevronRightIcon }), ChevronLeftIcon = _this$useGlobalIcon2.ChevronLeftIcon, ChevronRightIcon = _this$useGlobalIcon2.ChevronRightIcon; return h("div", { "class": ["".concat(this.componentName, "__arrow"), "".concat(this.componentName, "__arrow--default")] }, [h("div", { "class": "".concat(this.componentName, "__arrow-left"), "on": { "click": function click() { return _this7.goPrevious({ source: "click" }); } } }, [h(ChevronLeftIcon)]), h("div", { "class": "".concat(this.componentName, "__arrow-right"), "on": { "click": function click() { return _this7.goNext({ source: "click" }); } } }, [h(ChevronRightIcon)])]); }, renderNavigation: function renderNavigation() { var _this8 = this; var h = this.$createElement; var navigationSlot = utils_renderTnode.renderTNodeJSX(this, "navigation"); if (hooks_renderTnode.isVNode(this.navigation)) return this.navigation; if (navigationSlot && hooks_renderTnode.isVNode(navigationSlot === null || navigationSlot === void 0 ? void 0 : navigationSlot[0])) return navigationSlot; if (this.navigationConfig.type === "fraction") { return h("div", { "class": ["".concat(this.componentName, "__navigation"), "".concat(this.componentName, "__navigation--fraction")] }, [this.renderPagination()]); } return h("ul", { "class": ["".concat(this.componentName, "__navigation"), _defineProperty__default["default"]({}, "".concat(this.componentName, "__navigation-bars"), this.navigationConfig.type === "bars")] }, [this.swiperItemList.map(function (_, i) { return h("li", { "key": i, "class": ["".concat(_this8.componentName, "__navigation-item"), _defineProperty__default["default"]({}, "".concat(_this8.classPrefix, "-is-active"), i === _this8.currentIndex)], "on": { "mouseenter": function mouseenter() { return _this8.onMouseEnterNavigationItem(i); }, "click": function click() { return _this8.onClickNavigationItem(i); } } }, [h("span")]); })]); }, renderSwiperItems: function renderSwiperItems() { return this.swiperItems; } }, render: function render() { var h = arguments[0]; return h("div", { "class": this.componentName, "on": { "mouseenter": this.onMouseEnter, "mouseleave": this.onMouseLeave }, "ref": "swiperWrap" }, [h("div", { "class": this.swiperWrapClass }, [h("div", { "class": ["".concat(this.componentName, "__content"), _defineProperty__default["default"](_defineProperty__default["default"]({}, "".concat(this.componentName, "-fade"), this.animation === "fade"), "".concat(this.componentName, "-card"), this.type === "card")] }, [h("div", { "class": "".concat(this.componentName, "__container"), "style": this.containerStyle }, [this.renderSwiperItems()])]), this.renderNavigation(), this.renderArrow()])]); } })); exports["default"] = _Swiper; //# sourceMappingURL=swiper.js.map