tdesign-mobile-vue
Version:
tdesign-mobile-vue
97 lines (91 loc) • 3.47 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var core = require('@vueuse/core');
var hooks_useClass = require('../hooks/useClass.js');
var hooks_tnode = require('../hooks/tnode.js');
var config = require('../config.js');
require('../config-provider/useConfig.js');
require('@babel/runtime/helpers/defineProperty');
require('lodash/isFunction');
require('lodash/cloneDeep');
require('lodash/isString');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/mobile/default-config.js');
require('../_common/js/global-config/mobile/locale/zh_CN.js');
require('../_chunks/dep-8d930798.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-a20a5149.js');
require('dayjs');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../hooks/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
var prefix = config["default"].prefix;
var _SwiperItem = vue.defineComponent({
name: "".concat(prefix, "-swiper-item"),
setup: function setup() {
var _inject = vue.inject("parent"),
addChild = _inject.addChild,
removeChild = _inject.removeChild,
isVertical = _inject.isVertical,
root = _inject.root,
items = _inject.items,
setContainerHeight = _inject.setContainerHeight;
var swiperItemClass = hooks_useClass.usePrefixClass("swiper-item");
var readerTNodeJSX = hooks_tnode.useTNodeJSX();
var selfRef = vue.ref(null);
var rootStyle = vue.ref("");
var instance = vue.getCurrentInstance();
var direction = vue.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 = core.useElementBounding(selfRef),
height = _useElementBounding.height;
vue.watch(height, function (val) {
setContainerHeight(val);
});
vue.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
});
});
vue.onUnmounted(function () {
removeChild(instance === null || instance === void 0 ? void 0 : instance.uid);
});
return function () {
return vue.createVNode("div", {
"ref": selfRef,
"class": swiperItemClass.value,
"style": rootStyle.value
}, [readerTNodeJSX("default")]);
};
}
});
exports["default"] = _SwiperItem;
//# sourceMappingURL=swiper-item.js.map