UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

136 lines (128 loc) 5.95 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _defineProperty = require('@babel/runtime/helpers/defineProperty'); var vue = require('vue'); var swiper_props = require('./props.js'); var hooks_useConfig = require('../hooks/useConfig.js'); require('../config-provider/useConfig.js'); require('lodash/isFunction'); require('lodash/cloneDeep'); require('lodash/isString'); require('../config-provider/context.js'); require('lodash/mergeWith'); require('lodash/merge'); require('../_common/js/global-config/default-config.js'); require('../_common/js/global-config/locale/en_US.js'); require('../_chunks/dep-8d10b59f.js'); require('lodash/isArray'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); 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__default["default"](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 = vue.defineComponent({ name: "XSwiperItem", props: _objectSpread(_objectSpread({}, swiper_props["default"]), swiperItemProps), setup: function setup(props2, _ref) { var slots = _ref.slots; var prefix = hooks_useConfig.usePrefixClass(); var active = vue.computed(function () { return props2.index === props2.currentIndex; }); var disposeIndex = vue.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 = vue.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 = vue.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 = vue.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 vue.createVNode("div", { "class": ["".concat(prefix.value, "-swiper__container__item"), (_ref2 = {}, _defineProperty__default["default"](_ref2, "".concat(prefix.value, "-swiper__card"), props2.type === "card"), _defineProperty__default["default"](_ref2, "".concat(prefix.value, "-is-active"), props2.type === "card" && active.value), _defineProperty__default["default"](_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, {})) || []]); }; } }); exports["default"] = _SwiperItem; //# sourceMappingURL=swiper-item.js.map