xdesign-vue-next
Version:
XDesign Component for vue-next
128 lines (124 loc) • 5.53 kB
JavaScript
/**
* xdesign v1.0.6
* (c) 2023 xdesign
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed, createVNode } from 'vue';
import props from './props.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import '../config-provider/useConfig.js';
import 'lodash/isFunction';
import 'lodash/cloneDeep';
import 'lodash/isString';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/en_US.js';
import '../_chunks/dep-3a1cce9f.js';
import 'lodash/isArray';
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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 = defineComponent({
name: "XSwiperItem",
props: _objectSpread(_objectSpread({}, props), swiperItemProps),
setup: function setup(props2, _ref) {
var slots = _ref.slots;
var prefix = usePrefixClass();
var active = computed(function () {
return props2.index === props2.currentIndex;
});
var disposeIndex = computed(function () {
if (props2.type !== "card") return 0;
if (props2.currentIndex === 0 && props2.index === props2.swiperItemLength - 1) {
return -1;
}
if (props2.currentIndex === props2.swiperItemLength - 1 && props2.index === 0) {
return props2.swiperItemLength;
}
if (props2.index < props2.currentIndex - 1 && props2.currentIndex - props2.index >= props2.swiperItemLength / 2) {
return props2.swiperItemLength + 1;
}
if (props2.index > props2.currentIndex + 1 && props2.index - props2.currentIndex >= props2.swiperItemLength / 2) {
return -2;
}
return props2.index;
});
var translateX = computed(function () {
if (props2.type !== "card") return 0;
var wrapWidth = props2.getWrapAttribute("offsetWidth") || 0;
var translateIndex = !active.value && props2.swiperItemLength > 2 ? disposeIndex.value : props2.index;
var inStage = Math.abs(translateIndex - props2.currentIndex) <= 1;
if (inStage) {
return wrapWidth * ((translateIndex - props2.currentIndex) * (1 - itemWidth * CARD_SCALE) - itemWidth + 1) / 2;
}
if (translateIndex < props2.currentIndex) {
return -itemWidth * (1 + CARD_SCALE) * wrapWidth / 2;
}
return (2 + itemWidth * (CARD_SCALE - 1)) * wrapWidth / 2;
});
var zIndex = computed(function () {
if (props2.type !== "card") return 0;
var translateIndex = !active.value && props2.swiperItemLength > 2 ? disposeIndex.value : props2.index;
var isActivity = translateIndex === props2.currentIndex;
var inStage = Math.round(Math.abs(translateIndex - props2.currentIndex)) <= 1;
if (isActivity) {
return 2;
}
if (inStage) {
return 1;
}
return 0;
});
var itemStyle = computed(function () {
if (props2.animation === "fade") {
return {
opacity: active.value ? 1 : 0,
transition: props2.isSwitching ? "opacity ".concat(props2.duration / 1e3, "s") : "",
zIndex: active.value ? 1 : 0
};
}
if (props2.type === "card") {
var translateIndex = !active.value && props2.swiperItemLength > 2 ? disposeIndex.value : props2.index;
var isActivity = translateIndex === props2.currentIndex;
return {
transform: "translateX(".concat(translateX.value, "px) scale(").concat(isActivity ? 1 : CARD_SCALE, ")"),
transition: "transform ".concat(props2.duration / 1e3, "s ease"),
zIndex: zIndex.value
};
}
return {};
});
return function () {
var _ref2, _slots$default;
return createVNode("div", {
"class": ["".concat(prefix.value, "-swiper__container__item"), (_ref2 = {}, _defineProperty(_ref2, "".concat(prefix.value, "-swiper__card"), props2.type === "card"), _defineProperty(_ref2, "".concat(prefix.value, "-is-active"), props2.type === "card" && active.value), _defineProperty(_ref2, "".concat(prefix.value, "-swiper__fade"), props2.animation === "fade"), _ref2)],
"style": itemStyle.value
}, [((_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots, {})) || []]);
};
}
});
export { _SwiperItem as default };
//# sourceMappingURL=swiper-item.js.map