123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import { e as extend, p as paramsList, i as isObject, n as needsNavigation, a as needsPagination, b as needsScrollbar } from './update-swiper.mjs';
- import { d as defaults } from './swiper-core.mjs';
- function getParams(obj, splitEvents) {
- if (obj === void 0) {
- obj = {};
- }
- if (splitEvents === void 0) {
- splitEvents = true;
- }
- const params = {
- on: {}
- };
- const events = {};
- const passedParams = {};
- extend(params, defaults);
- params._emitClasses = true;
- params.init = false;
- const rest = {};
- const allowedParams = paramsList.map(key => key.replace(/_/, ''));
- 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') {
- if (splitEvents) {
- events[`${key[2].toLowerCase()}${key.substr(3)}`] = obj[key];
- } else {
- 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,
- events
- };
- }
- function mountSwiper(_ref, swiperParams) {
- let {
- el,
- nextEl,
- prevEl,
- paginationEl,
- scrollbarEl,
- swiper
- } = _ref;
- 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);
- }
- function getChangedParams(swiperParams, oldParams, children, oldChildren, getKey) {
- const keys = [];
- if (!oldParams) return keys;
- const addKey = key => {
- if (keys.indexOf(key) < 0) keys.push(key);
- };
- if (children && oldChildren) {
- const oldChildrenKeys = oldChildren.map(getKey);
- const childrenKeys = children.map(getKey);
- if (oldChildrenKeys.join('') !== childrenKeys.join('')) addKey('children');
- if (oldChildren.length !== children.length) addKey('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);
- }
- }
- });
- return keys;
- }
- const 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.parallax && swiper.params.parallax && swiper.params.parallax.enabled) {
- swiper.parallax.setTranslate();
- }
- };
- export { getChangedParams as a, getParams as g, mountSwiper as m, updateOnVirtualData as u };
|