xdesign-vue-next
Version:
XDesign Component for vue-next
154 lines (150 loc) • 6.59 kB
JavaScript
/**
* xdesign v1.0.6
* (c) 2023 xdesign
* @license MIT
*/
import { _ as _defineProperty } from '../_chunks/dep-f9e836af.mjs';
import { defineComponent, computed, createVNode } from 'vue';
import props from './props.mjs';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import '../_chunks/dep-82805301.mjs';
import '../config-provider/useConfig.mjs';
import '../_chunks/dep-1cc1c24f.mjs';
import '../_chunks/dep-10a947a6.mjs';
import '../_chunks/dep-b75d8d74.mjs';
import '../_chunks/dep-6ad18815.mjs';
import '../_chunks/dep-91ac8f71.mjs';
import '../_chunks/dep-c4737535.mjs';
import '../_chunks/dep-81c83986.mjs';
import '../_chunks/dep-6aa0223b.mjs';
import '../_chunks/dep-db381ece.mjs';
import '../_chunks/dep-5755c21c.mjs';
import '../_chunks/dep-7f239c43.mjs';
import '../_chunks/dep-6f04869e.mjs';
import '../_chunks/dep-d32fbbb3.mjs';
import '../_chunks/dep-dafada74.mjs';
import '../_chunks/dep-addc2a84.mjs';
import '../_chunks/dep-a95026f2.mjs';
import '../_chunks/dep-068e912d.mjs';
import '../_chunks/dep-6e7b37b8.mjs';
import '../_chunks/dep-e1ab85c5.mjs';
import '../_chunks/dep-5f0e0453.mjs';
import '../_chunks/dep-71f84cf2.mjs';
import '../_chunks/dep-0e832fc7.mjs';
import '../_chunks/dep-69963a8c.mjs';
import '../_chunks/dep-8d1c9a23.mjs';
import '../_chunks/dep-03412fab.mjs';
import '../_chunks/dep-205ff58d.mjs';
import '../_chunks/dep-11fa9c2c.mjs';
import '../_chunks/dep-b09f48fa.mjs';
import '../_chunks/dep-26bf361a.mjs';
import '../_chunks/dep-3ec3335a.mjs';
import '../_chunks/dep-ed4e7c50.mjs';
import '../_chunks/dep-a666b9ad.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/en_US.mjs';
import '../config-provider/type.mjs';
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.mjs.map