会员权益

This commit is contained in:
2026-04-29 15:33:58 +08:00
commit 54965243da
2787 changed files with 242809 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
import {
paramsList
} from './params-list.js';
import {
isObject
} from './utils.js';
function getChangedParams(swiperParams, oldParams, children, oldChildren) {
const keys = [];
if (!oldParams) return keys;
const addKey = (key) => {
if (keys.indexOf(key) < 0) keys.push(key);
};
const oldChildrenKeys = oldChildren.map((child) => child.props && child.props.key);
const childrenKeys = children.map((child) => child.props && child.props.key);
if (oldChildrenKeys.join('') !== childrenKeys.join('')) keys.push('children');
if (oldChildren.length !== children.length) keys.push('children');
const watchParams = paramsList.filter((key) => key[0] === '_').map((key) => key.replace(/_/, ''));
watchParams.forEach((key) => {
if (key in swiperParams && key in oldParams) {
if (isObject(swiperParams[key]) && isObject(oldParams[key])) {
const newKeys = Object.keys(swiperParams[key]);
const oldKeys = Object.keys(oldParams[key]);
if (newKeys.length !== oldKeys.length) {
addKey(key);
} else {
newKeys.forEach((newKey) => {
if (swiperParams[key][newKey] !== oldParams[key][newKey]) {
addKey(key);
}
});
oldKeys.forEach((oldKey) => {
if (swiperParams[key][oldKey] !== oldParams[key][oldKey]) addKey(key);
});
}
} else if (swiperParams[key] !== oldParams[key]) {
addKey(key);
}
} else if (key in swiperParams && !(key in oldParams)) {
addKey(key);
} else if (!(key in swiperParams) && key in oldParams) {
addKey(key);
}
});
return keys;
}
export {
getChangedParams
};

View File

@@ -0,0 +1,57 @@
import Swiper from '../../index.js';
import {
isObject,
extend
} from './utils.js';
import {
paramsList
} from './params-list.js';
function getParams(obj = {}) {
const params = {
on: {},
};
const passedParams = {};
extend(params, Swiper.defaults);
extend(params, Swiper.extendedDefaults);
params._emitClasses = true;
params.init = false;
const rest = {};
const allowedParams = paramsList.map((key) => key.replace(/_/, ''));
// Prevent empty Object.keys(obj) array on ios.
const plainObj = Object.assign({}, obj);
Object.keys(plainObj).forEach((key) => {
if (typeof obj[key] === 'undefined') return;
if (allowedParams.indexOf(key) >= 0) {
if (isObject(obj[key])) {
params[key] = {};
passedParams[key] = {};
extend(params[key], obj[key]);
extend(passedParams[key], obj[key]);
} else {
params[key] = obj[key];
passedParams[key] = obj[key];
}
} else if (key.search(/on[A-Z]/) === 0 && typeof obj[key] === 'function') {
params.on[`${key[2].toLowerCase()}${key.substr(3)}`] = obj[key];
} else {
rest[key] = obj[key];
}
});
['navigation', 'pagination', 'scrollbar'].forEach((key) => {
if (params[key] === true) params[key] = {};
if (params[key] === false) delete params[key];
});
return {
params,
passedParams,
rest
};
}
export {
getParams
};

View File

@@ -0,0 +1,40 @@
import Swiper from '../../index.js';
import {
needsNavigation,
needsPagination,
needsScrollbar
} from './utils.js';
function initSwiper(swiperParams, native) {
return new Swiper(swiperParams, native);
}
function mountSwiper({
el,
nextEl,
prevEl,
paginationEl,
scrollbarEl,
swiper
}, swiperParams) {
if (needsNavigation(swiperParams) && nextEl && prevEl) {
swiper.params.navigation.nextEl = nextEl;
swiper.originalParams.navigation.nextEl = nextEl;
swiper.params.navigation.prevEl = prevEl;
swiper.originalParams.navigation.prevEl = prevEl;
}
if (needsPagination(swiperParams) && paginationEl) {
swiper.params.pagination.el = paginationEl;
swiper.originalParams.pagination.el = paginationEl;
}
if (needsScrollbar(swiperParams) && scrollbarEl) {
swiper.params.scrollbar.el = scrollbarEl;
swiper.originalParams.scrollbar.el = scrollbarEl;
}
swiper.init(el);
}
export {
initSwiper,
mountSwiper
};

View File

@@ -0,0 +1,73 @@
import Swiper from '../../index.js';
function calcLoopedSlides(slides, swiperParams) {
let slidesPerViewParams = swiperParams.slidesPerView;
if (swiperParams.breakpoints) {
const breakpoint = Swiper.prototype.getBreakpoint(swiperParams.breakpoints);
const breakpointOnlyParams =
breakpoint in swiperParams.breakpoints ? swiperParams.breakpoints[breakpoint] : undefined;
if (breakpointOnlyParams && breakpointOnlyParams.slidesPerView) {
slidesPerViewParams = breakpointOnlyParams.slidesPerView;
}
}
let loopedSlides = Math.ceil(parseFloat(swiperParams.loopedSlides || slidesPerViewParams, 10));
loopedSlides += swiperParams.loopAdditionalSlides;
if (loopedSlides > slides.length) {
loopedSlides = slides.length;
}
return loopedSlides;
}
function renderLoop(native, swiperParams, data) {
const modifiedValue = data;
if (swiperParams.loopFillGroupWithBlank) {
const blankSlidesNum =
swiperParams.slidesPerGroup - (modifiedValue.length % swiperParams.slidesPerGroup);
if (blankSlidesNum !== swiperParams.slidesPerGroup) {
for (let i = 0; i < blankSlidesNum; i += 1) {
const blankSlide = h('div', {
class: `${swiperParams.slideClass} ${swiperParams.slideBlankClass}`,
});
modifiedValue.push(blankSlide);
}
}
}
if (swiperParams.slidesPerView === 'auto' && !swiperParams.loopedSlides) {
swiperParams.loopedSlides = modifiedValue.length;
}
const loopedSlides = calcLoopedSlides(modifiedValue, swiperParams);
const prependSlides = [];
const appendSlides = [];
const prependValue = [];
const appendValue = [];
modifiedValue.forEach((child, index) => {
if (index < loopedSlides) {
if (!native.loopUpdateData) {
appendValue.push(child);
}
}
if (index < modifiedValue.length && index >= modifiedValue.length - loopedSlides) {
if (!native.loopUpdateData) {
prependValue.push(child);
}
}
})
if (native) {
if (!native.originalDataList) native.originalDataList = [];
native.originalDataList = [...prependValue, ...modifiedValue, ...appendValue];
}
return {
data: [...prependValue, ...modifiedValue, ...appendValue]
};
}
export {
calcLoopedSlides,
renderLoop
};

View File

@@ -0,0 +1,123 @@
/* underscore in name -> watch for changes */
const paramsList = [
'modules',
'init',
'_direction',
'touchEventsTarget',
'initialSlide',
'_speed',
'cssMode',
'updateOnWindowResize',
'resizeObserver',
'nested',
'focusableElements',
'_enabled',
'_width',
'_height',
'preventInteractionOnTransition',
'userAgent',
'url',
'_edgeSwipeDetection',
'_edgeSwipeThreshold',
'_freeMode',
'_autoHeight',
'setWrapperSize',
'virtualTranslate',
'_effect',
'breakpoints',
'_spaceBetween',
'_slidesPerView',
'maxBackfaceHiddenSlides',
'_grid',
'_slidesPerGroup',
'_slidesPerGroupSkip',
'_slidesPerGroupAuto',
'_centeredSlides',
'_centeredSlidesBounds',
'_slidesOffsetBefore',
'_slidesOffsetAfter',
'normalizeSlideIndex',
'_centerInsufficientSlides',
'_watchOverflow',
'roundLengths',
'touchRatio',
'touchAngle',
'simulateTouch',
'_shortSwipes',
'_longSwipes',
'longSwipesRatio',
'longSwipesMs',
'_followFinger',
'allowTouchMove',
'_threshold',
'touchMoveStopPropagation',
'touchStartPreventDefault',
'touchStartForcePreventDefault',
'touchReleaseOnEdges',
'uniqueNavElements',
'_resistance',
'_resistanceRatio',
'_watchSlidesProgress',
'_grabCursor',
'preventClicks',
'preventClicksPropagation',
'_slideToClickedSlide',
'_preloadImages',
'updateOnImagesReady',
'_loop',
'_loopAdditionalSlides',
'_loopedSlides',
'_loopFillGroupWithBlank',
'loopPreventsSlide',
'_rewind',
'_allowSlidePrev',
'_allowSlideNext',
'_swipeHandler',
'_noSwiping',
'noSwipingClass',
'noSwipingSelector',
'passiveListeners',
'containerModifierClass',
'slideClass',
'slideBlankClass',
'slideActiveClass',
'slideDuplicateActiveClass',
'slideVisibleClass',
'slideDuplicateClass',
'slideNextClass',
'slideDuplicateNextClass',
'slidePrevClass',
'slideDuplicatePrevClass',
'wrapperClass',
'runCallbacksOnInit',
'observer',
'observeParents',
'observeSlideChildren',
// modules
'a11y',
'_autoplay',
'_controller',
'coverflowEffect',
'cubeEffect',
'fadeEffect',
'flipEffect',
'creativeEffect',
'cardsEffect',
'panorama',
'hashNavigation',
'history',
'keyboard',
'lazy',
'mousewheel',
'_navigation',
'_pagination',
'parallax',
'_scrollbar',
'_thumbs',
'_virtual',
'zoom',
];
export {
paramsList
};

View File

@@ -0,0 +1,167 @@
import {
isObject,
extend
} from './utils.js';
async function updateSwiper({
swiper,
slides,
passedParams,
changedParams,
nextEl,
prevEl,
paginationEl,
scrollbarEl,
}) {
const updateParams = changedParams.filter((key) => key !== 'children' && key !== 'direction');
const {
params: currentParams,
pagination,
navigation,
scrollbar,
virtual,
thumbs
} = swiper;
let needThumbsInit;
let needControllerInit;
let needPaginationInit;
let needScrollbarInit;
let needNavigationInit;
if (
changedParams.includes('thumbs') &&
passedParams.thumbs &&
passedParams.thumbs.swiper &&
currentParams.thumbs &&
!currentParams.thumbs.swiper
) {
needThumbsInit = true;
}
if (
changedParams.includes('controller') &&
passedParams.controller &&
passedParams.controller.control &&
currentParams.controller &&
!currentParams.controller.control
) {
needControllerInit = true;
}
if (
changedParams.includes('pagination') &&
passedParams.pagination &&
(passedParams.pagination.el || paginationEl) &&
(currentParams.pagination || currentParams.pagination === false) &&
pagination &&
!pagination.el
) {
needPaginationInit = true;
}
if (
changedParams.includes('scrollbar') &&
passedParams.scrollbar &&
(passedParams.scrollbar.el || scrollbarEl) &&
(currentParams.scrollbar || currentParams.scrollbar === false) &&
scrollbar &&
!scrollbar.el
) {
needScrollbarInit = true;
}
if (
changedParams.includes('navigation') &&
passedParams.navigation &&
(passedParams.navigation.prevEl || prevEl) &&
(passedParams.navigation.nextEl || nextEl) &&
(currentParams.navigation || currentParams.navigation === false) &&
navigation &&
!navigation.prevEl &&
!navigation.nextEl
) {
needNavigationInit = true;
}
const destroyModule = (mod) => {
if (!swiper[mod]) return;
swiper[mod].destroy();
if (mod === 'navigation') {
currentParams[mod].prevEl = undefined;
currentParams[mod].nextEl = undefined;
swiper[mod].prevEl = undefined;
swiper[mod].nextEl = undefined;
} else {
currentParams[mod].el = undefined;
swiper[mod].el = undefined;
}
};
updateParams.forEach((key) => {
if (isObject(currentParams[key]) && isObject(passedParams[key])) {
extend(currentParams[key], passedParams[key]);
} else {
const newValue = passedParams[key];
if (
(newValue === true || newValue === false) &&
(key === 'navigation' || key === 'pagination' || key === 'scrollbar')
) {
if (newValue === false) {
destroyModule(key);
}
} else {
currentParams[key] = passedParams[key];
}
}
});
// if (changedParams.includes('virtual') && virtual && currentParams.virtual.enabled) {
// virtual.update();
// }
if (changedParams.includes('children') && virtual && currentParams.virtual.enabled) {
// virtual.slides = slides;
virtual.update(true);
} else if (changedParams.includes('children') && swiper.lazy && swiper.params.lazy.enabled) {
swiper.lazy.load();
}
if (needThumbsInit) {
const initialized = thumbs.init();
if (initialized) thumbs.update(true);
}
if (needControllerInit) {
swiper.controller.control = currentParams.controller.control;
}
if (needPaginationInit) {
if (paginationEl) currentParams.pagination.el = paginationEl;
pagination.init();
pagination.render();
pagination.update();
}
if (needScrollbarInit) {
if (scrollbarEl) currentParams.scrollbar.el = scrollbarEl;
scrollbar.init();
scrollbar.updateSize();
scrollbar.setTranslate();
}
if (needNavigationInit) {
if (nextEl) currentParams.navigation.nextEl = nextEl;
if (prevEl) currentParams.navigation.prevEl = prevEl;
navigation.init();
navigation.update();
}
if (changedParams.includes('allowSlideNext')) {
swiper.allowSlideNext = passedParams.allowSlideNext;
}
if (changedParams.includes('allowSlidePrev')) {
swiper.allowSlidePrev = passedParams.allowSlidePrev;
}
if (changedParams.includes('direction')) {
swiper.changeDirection(passedParams.direction, false);
}
swiper.update();
}
export {
updateSwiper
};

View File

@@ -0,0 +1,60 @@
function isObject(o) {
return (
typeof o === 'object' &&
o !== null &&
o.constructor &&
Object.prototype.toString.call(o).slice(8, -1) === 'Object'
);
}
function extend(target, src) {
const noExtend = ['__proto__', 'constructor', 'prototype'];
Object.keys(src)
.filter((key) => noExtend.indexOf(key) < 0)
.forEach((key) => {
if (typeof target[key] === 'undefined') target[key] = src[key];
else if (isObject(src[key]) && isObject(target[key]) && Object.keys(src[key]).length > 0) {
if (src[key].__swiper__) target[key] = src[key];
else extend(target[key], src[key]);
} else {
target[key] = src[key];
}
});
}
function needsNavigation(props = {}) {
return (
props.navigation &&
typeof props.navigation.nextEl === 'undefined' &&
typeof props.navigation.prevEl === 'undefined'
);
}
function needsPagination(props = {}) {
return props.pagination && typeof props.pagination.el === 'undefined';
}
function needsScrollbar(props = {}) {
return props.scrollbar;
}
function uniqueClasses(classNames = '') {
const classes = classNames
.split(' ')
.map((c) => c.trim())
.filter((c) => !!c);
const unique = [];
classes.forEach((c) => {
if (unique.indexOf(c) < 0) unique.push(c);
});
return unique.join(' ');
}
export {
isObject,
extend,
needsNavigation,
needsPagination,
needsScrollbar,
uniqueClasses
};

View File

@@ -0,0 +1,44 @@
// import { h } from 'vue';
function updateOnVirtualData(swiper) {
if (
!swiper ||
swiper.destroyed ||
!swiper.params.virtual ||
(swiper.params.virtual && !swiper.params.virtual.enabled)
) return;
swiper.updateSlides();
swiper.updateProgress();
swiper.updateSlidesClasses();
if (swiper.lazy && swiper.params.lazy.enabled) {
swiper.lazy.load();
}
if (swiper.parallax && swiper.params.parallax && swiper.params.parallax.enabled) {
swiper.parallax.setTranslate();
}
}
function renderVirtual(swiperRef, slides, virtualData) {
if (!virtualData) return null;
const style = swiperRef.isHorizontal() ? {
[swiperRef.rtlTranslate ? 'right' : 'left']: `${virtualData.offset}px`,
} : {
top: `${virtualData.offset}px`,
};
return slides
.filter((slide, index) => index >= virtualData.from && index <= virtualData.to)
.map((slide) => {
if (!slide.props) slide.props = {};
if (!slide.props.style) slide.props.style = {};
slide.props.swiperRef = swiperRef;
slide.props.style = style;
return h(slide.type, {
...slide.props
}, slide.children);
});
}
export {
renderVirtual,
updateOnVirtualData
};