vendor: 4,309 bytes, lines 1-179
1/** 2 * Swiper 9.0.5 3 * Most modern mobile touch slider and framework with hardware accelerated transitions 4 * https://swiperjs.com 5 * 6 * Copyright 2014-2023 Vladimir Kharlampidi 7 * 8 * Released under the MIT License 9 * 10 * Released on: February 13, 2023 11 */ 12 13(function (global, factory) { 14 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 15 typeof define === 'function' && define.amd ? define(factory) : 16 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Swiper = factory()); 17})(this, (function () { 'use strict'; 18 19 /** 20 * SSR Window 4.0.2 21 * Better handling for window object in SSR environment 22 * https://github.com/nolimits4web/ssr-window 23 * 24 * Copyright 2021, Vladimir Kharlampidi 25 * 26 * Licensed under MIT 27 * 28 * Released on: December 13, 2021 29 */ 30 /* eslint-disable no-param-reassign */ 31 function isObject$1(obj) { 32 return obj !== null && typeof obj === 'object' && 'constructor' in obj && obj.constructor === Object; 33 } 34 function extend$1(target, src) { 35 if (target === void 0) { 36 target = {}; 37 } 38 if (src === void 0) { 39 src = {}; 40 } 41 Object.keys(src).forEach(key => { 42 if (typeof target[key] === 'undefined') target[key] = src[key];else if (isObject$1(src[key]) && isObject$1(target[key]) && Object.keys(src[key]).length > 0) { 43 extend$1(target[key], src[key]); 44 } 45 }); 46 } 47 const ssrDocument = { 48 body: {}, 49 addEventListener() {}, 50 removeEventListener() {}, 51 activeElement: { 52 blur() {}, 53 nodeName: '' 54 }, 55 querySelector() { 56 return null; 57 }, 58 querySelectorAll() { 59 return []; 60 }, 61 getElementById() { 62 return null; 63 }, 64 createEvent() { 65 return { 66 initEvent() {} 67 }; 68 }, 69 createElement() { 70 return { 71 children: [], 72 childNodes: [], 73 style: {}, 74 setAttribute() {}, 75 getElementsByTagName() { 76 return []; 77 } 78 }; 79 }, 80 createElementNS() { 81 return {}; 82 }, 83 importNode() { 84 return null; 85 }, 86 location: { 87 hash: '', 88 host: '', 89 hostname: '', 90 href: '', 91 origin: '', 92 pathname: '', 93 protocol: '', 94 search: '' 95 } 96 }; 97 function getDocument() { 98 const doc = typeof document !== 'undefined' ? document : {}; 99 extend$1(doc, ssrDocument); 100 return doc; 101 } 102 const ssrWindow = { 103 document: ssrDocument, 104 navigator: { 105 userAgent: '' 106 }, 107 location: { 108 hash: '', 109 host: '', 110 hostname: '', 111 href: '', 112 origin: '', 113 pathname: '', 114 protocol: '', 115 search: '' 116 }, 117 history: { 118 replaceState() {}, 119 pushState() {}, 120 go() {}, 121 back() {} 122 }, 123 CustomEvent: function CustomEvent() { 124 return this; 125 }, 126 addEventListener() {}, 127 removeEventListener() {}, 128 getComputedStyle() { 129 return { 130 getPropertyValue() { 131 return ''; 132 } 133 }; 134 }, 135 Image() {}, 136 Date() {}, 137 screen: {}, 138 setTimeout() {}, 139 clearTimeout() {}, 140 matchMedia() { 141 return {}; 142 }, 143 requestAnimationFrame(callback) { 144 if (typeof setTimeout === 'undefined') { 145 callback(); 146 return null; 147 } 148 return setTimeout(callback, 0); 149 }, 150 cancelAnimationFrame(id) { 151 if (typeof setTimeout === 'undefined') { 152 return; 153 } 154 clearTimeout(id); 155 } 156 }; 157 function getWindow() { 158 const win = typeof window !== 'undefined' ? window : {}; 159 extend$1(win, ssrWindow); 160 return win; 161 } 162 163 function deleteProps(obj) { 164 const object = obj; 165 Object.keys(object).forEach(key => { 166 try { 167 object[key] = null; 168 } catch (e) { 169 // no getter for object 170 } 171 try { 172 delete object[key]; 173 } catch (e) { 174 // something got wrong 175 } 176 }); 177 } 178 function nextTick(callback, delay) { 179 if (delay === void 0) {
vendor: 6,590 bytes, lines 180-346
180 delay = 0; 181 } 182 return setTimeout(callback, delay); 183 } 184 function now() { 185 return Date.now(); 186 } 187 function getComputedStyle$1(el) { 188 const window = getWindow(); 189 let style; 190 if (window.getComputedStyle) { 191 style = window.getComputedStyle(el, null); 192 } 193 if (!style && el.currentStyle) { 194 style = el.currentStyle; 195 } 196 if (!style) { 197 style = el.style; 198 } 199 return style; 200 } 201 function getTranslate(el, axis) { 202 if (axis === void 0) { 203 axis = 'x'; 204 } 205 const window = getWindow(); 206 let matrix; 207 let curTransform; 208 let transformMatrix; 209 const curStyle = getComputedStyle$1(el); 210 if (window.WebKitCSSMatrix) { 211 curTransform = curStyle.transform || curStyle.webkitTransform; 212 if (curTransform.split(',').length > 6) { 213 curTransform = curTransform.split(', ').map(a => a.replace(',', '.')).join(', '); 214 } 215 // Some old versions of Webkit choke when 'none' is passed; pass 216 // empty string instead in this case 217 transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform); 218 } else { 219 transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,'); 220 matrix = transformMatrix.toString().split(','); 221 } 222 if (axis === 'x') { 223 // Latest Chrome and webkits Fix 224 if (window.WebKitCSSMatrix) curTransform = transformMatrix.m41; 225 // Crazy IE10 Matrix 226 else if (matrix.length === 16) curTransform = parseFloat(matrix[12]); 227 // Normal Browsers 228 else curTransform = parseFloat(matrix[4]); 229 } 230 if (axis === 'y') { 231 // Latest Chrome and webkits Fix 232 if (window.WebKitCSSMatrix) curTransform = transformMatrix.m42; 233 // Crazy IE10 Matrix 234 else if (matrix.length === 16) curTransform = parseFloat(matrix[13]); 235 // Normal Browsers 236 else curTransform = parseFloat(matrix[5]); 237 } 238 return curTransform || 0; 239 } 240 function isObject(o) { 241 return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) === 'Object'; 242 } 243 function isNode(node) { 244 // eslint-disable-next-line 245 if (typeof window !== 'undefined' && typeof window.HTMLElement !== 'undefined') { 246 return node instanceof HTMLElement; 247 } 248 return node && (node.nodeType === 1 || node.nodeType === 11); 249 } 250 function extend() { 251 const to = Object(arguments.length <= 0 ? undefined : arguments[0]); 252 const noExtend = ['__proto__', 'constructor', 'prototype']; 253 for (let i = 1; i < arguments.length; i += 1) { 254 const nextSource = i < 0 || arguments.length <= i ? undefined : arguments[i]; 255 if (nextSource !== undefined && nextSource !== null && !isNode(nextSource)) { 256 const keysArray = Object.keys(Object(nextSource)).filter(key => noExtend.indexOf(key) < 0); 257 for (let nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) { 258 const nextKey = keysArray[nextIndex]; 259 const desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); 260 if (desc !== undefined && desc.enumerable) { 261 if (isObject(to[nextKey]) && isObject(nextSource[nextKey])) { 262 if (nextSource[nextKey].__swiper__) { 263 to[nextKey] = nextSource[nextKey]; 264 } else { 265 extend(to[nextKey], nextSource[nextKey]); 266 } 267 } else if (!isObject(to[nextKey]) && isObject(nextSource[nextKey])) { 268 to[nextKey] = {}; 269 if (nextSource[nextKey].__swiper__) { 270 to[nextKey] = nextSource[nextKey]; 271 } else { 272 extend(to[nextKey], nextSource[nextKey]); 273 } 274 } else { 275 to[nextKey] = nextSource[nextKey]; 276 } 277 } 278 } 279 } 280 } 281 return to; 282 } 283 function setCSSProperty(el, varName, varValue) { 284 el.style.setProperty(varName, varValue); 285 } 286 function animateCSSModeScroll(_ref) { 287 let { 288 swiper, 289 targetPosition, 290 side 291 } = _ref; 292 const window = getWindow(); 293 const startPosition = -swiper.translate; 294 let startTime = null; 295 let time; 296 const duration = swiper.params.speed; 297 swiper.wrapperEl.style.scrollSnapType = 'none'; 298 window.cancelAnimationFrame(swiper.cssModeFrameID); 299 const dir = targetPosition > startPosition ? 'next' : 'prev'; 300 const isOutOfBound = (current, target) => { 301 return dir === 'next' && current >= target || dir === 'prev' && current <= target; 302 }; 303 const animate = () => { 304 time = new Date().getTime(); 305 if (startTime === null) { 306 startTime = time; 307 } 308 const progress = Math.max(Math.min((time - startTime) / duration, 1), 0); 309 const easeProgress = 0.5 - Math.cos(progress * Math.PI) / 2; 310 let currentPosition = startPosition + easeProgress * (targetPosition - startPosition); 311 if (isOutOfBound(currentPosition, targetPosition)) { 312 currentPosition = targetPosition; 313 } 314 swiper.wrapperEl.scrollTo({ 315 [side]: currentPosition 316 }); 317 if (isOutOfBound(currentPosition, targetPosition)) { 318 swiper.wrapperEl.style.overflow = 'hidden'; 319 swiper.wrapperEl.style.scrollSnapType = ''; 320 setTimeout(() => { 321 swiper.wrapperEl.style.overflow = ''; 322 swiper.wrapperEl.scrollTo({ 323 [side]: currentPosition 324 }); 325 }); 326 window.cancelAnimationFrame(swiper.cssModeFrameID); 327 return; 328 } 329 swiper.cssModeFrameID = window.requestAnimationFrame(animate); 330 }; 331 animate(); 332 } 333 function getSlideTransformEl(slideEl) { 334 return slideEl.querySelector('.swiper-slide-transform') || slideEl.shadowEl && slideEl.shadowEl.querySelector('.swiper-slide-transform') || slideEl; 335 } 336 function elementChildren(element, selector) { 337 if (selector === void 0) { 338 selector = ''; 339 } 340 return [...element.children].filter(el => el.matches(selector)); 341 } 342 function createElement(tag, classes) { 343 if (classes === void 0) { 344 classes = []; 345 } 346 const el = document.createElement(tag);
vendor: 3,621 bytes, lines 347-454
347 el.classList.add(...(Array.isArray(classes) ? classes : [classes])); 348 return el; 349 } 350 function elementOffset(el) { 351 const window = getWindow(); 352 const document = getDocument(); 353 const box = el.getBoundingClientRect(); 354 const body = document.body; 355 const clientTop = el.clientTop || body.clientTop || 0; 356 const clientLeft = el.clientLeft || body.clientLeft || 0; 357 const scrollTop = el === window ? window.scrollY : el.scrollTop; 358 const scrollLeft = el === window ? window.scrollX : el.scrollLeft; 359 return { 360 top: box.top + scrollTop - clientTop, 361 left: box.left + scrollLeft - clientLeft 362 }; 363 } 364 function elementPrevAll(el, selector) { 365 const prevEls = []; 366 while (el.previousElementSibling) { 367 const prev = el.previousElementSibling; // eslint-disable-line 368 if (selector) { 369 if (prev.matches(selector)) prevEls.push(prev); 370 } else prevEls.push(prev); 371 el = prev; 372 } 373 return prevEls; 374 } 375 function elementNextAll(el, selector) { 376 const nextEls = []; 377 while (el.nextElementSibling) { 378 const next = el.nextElementSibling; // eslint-disable-line 379 if (selector) { 380 if (next.matches(selector)) nextEls.push(next); 381 } else nextEls.push(next); 382 el = next; 383 } 384 return nextEls; 385 } 386 function elementStyle(el, prop) { 387 const window = getWindow(); 388 return window.getComputedStyle(el, null).getPropertyValue(prop); 389 } 390 function elementIndex(el) { 391 let child = el; 392 let i; 393 if (child) { 394 i = 0; 395 // eslint-disable-next-line 396 while ((child = child.previousSibling) !== null) { 397 if (child.nodeType === 1) i += 1; 398 } 399 return i; 400 } 401 return undefined; 402 } 403 function elementParents(el, selector) { 404 const parents = []; // eslint-disable-line 405 let parent = el.parentElement; // eslint-disable-line 406 while (parent) { 407 if (selector) { 408 if (parent.matches(selector)) parents.push(parent); 409 } else { 410 parents.push(parent); 411 } 412 parent = parent.parentElement; 413 } 414 return parents; 415 } 416 function elementTransitionEnd(el, callback) { 417 function fireCallBack(e) { 418 if (e.target !== el) return; 419 callback.call(el, e); 420 el.removeEventListener('transitionend', fireCallBack); 421 } 422 if (callback) { 423 el.addEventListener('transitionend', fireCallBack); 424 } 425 } 426 function elementOuterSize(el, size, includeMargins) { 427 const window = getWindow(); 428 if (includeMargins) { 429 return el[size === 'width' ? 'offsetWidth' : 'offsetHeight'] + parseFloat(window.getComputedStyle(el, null).getPropertyValue(size === 'width' ? 'margin-right' : 'margin-top')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue(size === 'width' ? 'margin-left' : 'margin-bottom')); 430 } 431 return el.offsetWidth; 432 } 433 434 let support; 435 function calcSupport() { 436 const window = getWindow(); 437 const document = getDocument(); 438 return { 439 smoothScroll: document.documentElement && 'scrollBehavior' in document.documentElement.style, 440 touch: !!('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch) 441 }; 442 } 443 function getSupport() { 444 if (!support) { 445 support = calcSupport(); 446 } 447 return support; 448 } 449 450 let deviceCached; 451 function calcDevice(_temp) { 452 let { 453 userAgent 454 } = _temp === void 0 ? {} : _temp;
vendor: 13,769 bytes, lines 455-844
455 const support = getSupport(); 456 const window = getWindow(); 457 const platform = window.navigator.platform; 458 const ua = userAgent || window.navigator.userAgent; 459 const device = { 460 ios: false, 461 android: false 462 }; 463 const screenWidth = window.screen.width; 464 const screenHeight = window.screen.height; 465 const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line 466 let ipad = ua.match(/(iPad).*OS\s([\d_]+)/); 467 const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/); 468 const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/); 469 const windows = platform === 'Win32'; 470 let macos = platform === 'MacIntel'; 471 472 // iPadOs 13 fix 473 const iPadScreens = ['1024x1366', '1366x1024', '834x1194', '1194x834', '834x1112', '1112x834', '768x1024', '1024x768', '820x1180', '1180x820', '810x1080', '1080x810']; 474 if (!ipad && macos && support.touch && iPadScreens.indexOf(`${screenWidth}x${screenHeight}`) >= 0) { 475 ipad = ua.match(/(Version)\/([\d.]+)/); 476 if (!ipad) ipad = [0, 1, '13_0_0']; 477 macos = false; 478 } 479 480 // Android 481 if (android && !windows) { 482 device.os = 'android'; 483 device.android = true; 484 } 485 if (ipad || iphone || ipod) { 486 device.os = 'ios'; 487 device.ios = true; 488 } 489 490 // Export object 491 return device; 492 } 493 function getDevice(overrides) { 494 if (overrides === void 0) { 495 overrides = {}; 496 } 497 if (!deviceCached) { 498 deviceCached = calcDevice(overrides); 499 } 500 return deviceCached; 501 } 502 503 let browser; 504 function calcBrowser() { 505 const window = getWindow(); 506 let needPerspectiveFix = false; 507 function isSafari() { 508 const ua = window.navigator.userAgent.toLowerCase(); 509 return ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0; 510 } 511 if (isSafari()) { 512 const ua = String(window.navigator.userAgent); 513 if (ua.includes('Version/')) { 514 const [major, minor] = ua.split('Version/')[1].split(' ')[0].split('.').map(num => Number(num)); 515 needPerspectiveFix = major < 16 || major === 16 && minor < 2; 516 } 517 } 518 return { 519 isSafari: needPerspectiveFix || isSafari(), 520 needPerspectiveFix, 521 isWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent) 522 }; 523 } 524 function getBrowser() { 525 if (!browser) { 526 browser = calcBrowser(); 527 } 528 return browser; 529 } 530 531 function Resize(_ref) { 532 let { 533 swiper, 534 on, 535 emit 536 } = _ref; 537 const window = getWindow(); 538 let observer = null; 539 let animationFrame = null; 540 const resizeHandler = () => { 541 if (!swiper || swiper.destroyed || !swiper.initialized) return; 542 emit('beforeResize'); 543 emit('resize'); 544 }; 545 const createObserver = () => { 546 if (!swiper || swiper.destroyed || !swiper.initialized) return; 547 observer = new ResizeObserver(entries => { 548 animationFrame = window.requestAnimationFrame(() => { 549 const { 550 width, 551 height 552 } = swiper; 553 let newWidth = width; 554 let newHeight = height; 555 entries.forEach(_ref2 => { 556 let { 557 contentBoxSize, 558 contentRect, 559 target 560 } = _ref2; 561 if (target && target !== swiper.el) return; 562 newWidth = contentRect ? contentRect.width : (contentBoxSize[0] || contentBoxSize).inlineSize; 563 newHeight = contentRect ? contentRect.height : (contentBoxSize[0] || contentBoxSize).blockSize; 564 }); 565 if (newWidth !== width || newHeight !== height) { 566 resizeHandler(); 567 } 568 }); 569 }); 570 observer.observe(swiper.el); 571 }; 572 const removeObserver = () => { 573 if (animationFrame) { 574 window.cancelAnimationFrame(animationFrame); 575 } 576 if (observer && observer.unobserve && swiper.el) { 577 observer.unobserve(swiper.el); 578 observer = null; 579 } 580 }; 581 const orientationChangeHandler = () => { 582 if (!swiper || swiper.destroyed || !swiper.initialized) return; 583 emit('orientationchange'); 584 }; 585 on('init', () => { 586 if (swiper.params.resizeObserver && typeof window.ResizeObserver !== 'undefined') { 587 createObserver(); 588 return; 589 } 590 window.addEventListener('resize', resizeHandler); 591 window.addEventListener('orientationchange', orientationChangeHandler); 592 }); 593 on('destroy', () => { 594 removeObserver(); 595 window.removeEventListener('resize', resizeHandler); 596 window.removeEventListener('orientationchange', orientationChangeHandler); 597 }); 598 } 599 600 function Observer(_ref) { 601 let { 602 swiper, 603 extendParams, 604 on, 605 emit 606 } = _ref; 607 const observers = []; 608 const window = getWindow(); 609 const attach = function (target, options) { 610 if (options === void 0) { 611 options = {}; 612 } 613 const ObserverFunc = window.MutationObserver || window.WebkitMutationObserver; 614 const observer = new ObserverFunc(mutations => { 615 // The observerUpdate event should only be triggered 616 // once despite the number of mutations. Additional 617 // triggers are redundant and are very costly 618 if (mutations.length === 1) { 619 emit('observerUpdate', mutations[0]); 620 return; 621 } 622 const observerUpdate = function observerUpdate() { 623 emit('observerUpdate', mutations[0]); 624 }; 625 if (window.requestAnimationFrame) { 626 window.requestAnimationFrame(observerUpdate); 627 } else { 628 window.setTimeout(observerUpdate, 0); 629 } 630 }); 631 observer.observe(target, { 632 attributes: typeof options.attributes === 'undefined' ? true : options.attributes, 633 childList: typeof options.childList === 'undefined' ? true : options.childList, 634 characterData: typeof options.characterData === 'undefined' ? true : options.characterData 635 }); 636 observers.push(observer); 637 }; 638 const init = () => { 639 if (!swiper.params.observer) return; 640 if (swiper.params.observeParents) { 641 const containerParents = elementParents(swiper.el); 642 for (let i = 0; i < containerParents.length; i += 1) { 643 attach(containerParents[i]); 644 } 645 } 646 // Observe container 647 attach(swiper.el, { 648 childList: swiper.params.observeSlideChildren 649 }); 650 651 // Observe wrapper 652 attach(swiper.wrapperEl, { 653 attributes: false 654 }); 655 }; 656 const destroy = () => { 657 observers.forEach(observer => { 658 observer.disconnect(); 659 }); 660 observers.splice(0, observers.length); 661 }; 662 extendParams({ 663 observer: false, 664 observeParents: false, 665 observeSlideChildren: false 666 }); 667 on('init', init); 668 on('destroy', destroy); 669 } 670 671 /* eslint-disable no-underscore-dangle */ 672 673 var eventsEmitter = { 674 on(events, handler, priority) { 675 const self = this; 676 if (!self.eventsListeners || self.destroyed) return self; 677 if (typeof handler !== 'function') return self; 678 const method = priority ? 'unshift' : 'push'; 679 events.split(' ').forEach(event => { 680 if (!self.eventsListeners[event]) self.eventsListeners[event] = []; 681 self.eventsListeners[event][method](handler); 682 }); 683 return self; 684 }, 685 once(events, handler, priority) { 686 const self = this; 687 if (!self.eventsListeners || self.destroyed) return self; 688 if (typeof handler !== 'function') return self; 689 function onceHandler() { 690 self.off(events, onceHandler); 691 if (onceHandler.__emitterProxy) { 692 delete onceHandler.__emitterProxy; 693 } 694 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 695 args[_key] = arguments[_key]; 696 } 697 handler.apply(self, args); 698 } 699 onceHandler.__emitterProxy = handler; 700 return self.on(events, onceHandler, priority); 701 }, 702 onAny(handler, priority) { 703 const self = this; 704 if (!self.eventsListeners || self.destroyed) return self; 705 if (typeof handler !== 'function') return self; 706 const method = priority ? 'unshift' : 'push'; 707 if (self.eventsAnyListeners.indexOf(handler) < 0) { 708 self.eventsAnyListeners[method](handler); 709 } 710 return self; 711 }, 712 offAny(handler) { 713 const self = this; 714 if (!self.eventsListeners || self.destroyed) return self; 715 if (!self.eventsAnyListeners) return self; 716 const index = self.eventsAnyListeners.indexOf(handler); 717 if (index >= 0) { 718 self.eventsAnyListeners.splice(index, 1); 719 } 720 return self; 721 }, 722 off(events, handler) { 723 const self = this; 724 if (!self.eventsListeners || self.destroyed) return self; 725 if (!self.eventsListeners) return self; 726 events.split(' ').forEach(event => { 727 if (typeof handler === 'undefined') { 728 self.eventsListeners[event] = []; 729 } else if (self.eventsListeners[event]) { 730 self.eventsListeners[event].forEach((eventHandler, index) => { 731 if (eventHandler === handler || eventHandler.__emitterProxy && eventHandler.__emitterProxy === handler) { 732 self.eventsListeners[event].splice(index, 1); 733 } 734 }); 735 } 736 }); 737 return self; 738 }, 739 emit() { 740 const self = this; 741 if (!self.eventsListeners || self.destroyed) return self; 742 if (!self.eventsListeners) return self; 743 let events; 744 let data; 745 let context; 746 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 747 args[_key2] = arguments[_key2]; 748 } 749 if (typeof args[0] === 'string' || Array.isArray(args[0])) { 750 events = args[0]; 751 data = args.slice(1, args.length); 752 context = self; 753 } else { 754 events = args[0].events; 755 data = args[0].data; 756 context = args[0].context || self; 757 } 758 data.unshift(context); 759 const eventsArray = Array.isArray(events) ? events : events.split(' '); 760 eventsArray.forEach(event => { 761 if (self.eventsAnyListeners && self.eventsAnyListeners.length) { 762 self.eventsAnyListeners.forEach(eventHandler => { 763 eventHandler.apply(context, [event, ...data]); 764 }); 765 } 766 if (self.eventsListeners && self.eventsListeners[event]) { 767 self.eventsListeners[event].forEach(eventHandler => { 768 eventHandler.apply(context, data); 769 }); 770 } 771 }); 772 return self; 773 } 774 }; 775 776 function updateSize() { 777 const swiper = this; 778 let width; 779 let height; 780 const el = swiper.el; 781 if (typeof swiper.params.width !== 'undefined' && swiper.params.width !== null) { 782 width = swiper.params.width; 783 } else { 784 width = el.clientWidth; 785 } 786 if (typeof swiper.params.height !== 'undefined' && swiper.params.height !== null) { 787 height = swiper.params.height; 788 } else { 789 height = el.clientHeight; 790 } 791 if (width === 0 && swiper.isHorizontal() || height === 0 && swiper.isVertical()) { 792 return; 793 } 794 795 // Subtract paddings 796 width = width - parseInt(elementStyle(el, 'padding-left') || 0, 10) - parseInt(elementStyle(el, 'padding-right') || 0, 10); 797 height = height - parseInt(elementStyle(el, 'padding-top') || 0, 10) - parseInt(elementStyle(el, 'padding-bottom') || 0, 10); 798 if (Number.isNaN(width)) width = 0; 799 if (Number.isNaN(height)) height = 0; 800 Object.assign(swiper, { 801 width, 802 height, 803 size: swiper.isHorizontal() ? width : height 804 }); 805 } 806 807 function updateSlides() { 808 const swiper = this; 809 function getDirectionLabel(property) { 810 if (swiper.isHorizontal()) { 811 return property; 812 } 813 // prettier-ignore 814 return { 815 'width': 'height', 816 'margin-top': 'margin-left', 817 'margin-bottom ': 'margin-right', 818 'margin-left': 'margin-top', 819 'margin-right': 'margin-bottom', 820 'padding-left': 'padding-top', 821 'padding-right': 'padding-bottom', 822 'marginRight': 'marginBottom' 823 }[property]; 824 } 825 function getDirectionPropertyValue(node, label) { 826 return parseFloat(node.getPropertyValue(getDirectionLabel(label)) || 0); 827 } 828 const params = swiper.params; 829 const { 830 wrapperEl, 831 slidesEl, 832 size: swiperSize, 833 rtlTranslate: rtl, 834 wrongRTL 835 } = swiper; 836 const isVirtual = swiper.virtual && params.virtual.enabled; 837 const previousSlidesLength = isVirtual ? swiper.virtual.slides.length : swiper.slides.length; 838 const slides = elementChildren(slidesEl, `.${swiper.params.slideClass}, swiper-slide`); 839 const slidesLength = isVirtual ? swiper.virtual.slides.length : slides.length; 840 let snapGrid = []; 841 const slidesGrid = []; 842 const slidesSizesGrid = []; 843 let offsetBefore = params.slidesOffsetBefore; 844 if (typeof offsetBefore === 'function') {
vendor: 7,923 bytes, lines 845-1021
845 offsetBefore = params.slidesOffsetBefore.call(swiper); 846 } 847 let offsetAfter = params.slidesOffsetAfter; 848 if (typeof offsetAfter === 'function') { 849 offsetAfter = params.slidesOffsetAfter.call(swiper); 850 } 851 const previousSnapGridLength = swiper.snapGrid.length; 852 const previousSlidesGridLength = swiper.slidesGrid.length; 853 let spaceBetween = params.spaceBetween; 854 let slidePosition = -offsetBefore; 855 let prevSlideSize = 0; 856 let index = 0; 857 if (typeof swiperSize === 'undefined') { 858 return; 859 } 860 if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) { 861 spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiperSize; 862 } 863 swiper.virtualSize = -spaceBetween; 864 865 // reset margins 866 slides.forEach(slideEl => { 867 if (rtl) { 868 slideEl.style.marginLeft = ''; 869 } else { 870 slideEl.style.marginRight = ''; 871 } 872 slideEl.style.marginBottom = ''; 873 slideEl.style.marginTop = ''; 874 }); 875 876 // reset cssMode offsets 877 if (params.centeredSlides && params.cssMode) { 878 setCSSProperty(wrapperEl, '--swiper-centered-offset-before', ''); 879 setCSSProperty(wrapperEl, '--swiper-centered-offset-after', ''); 880 } 881 const gridEnabled = params.grid && params.grid.rows > 1 && swiper.grid; 882 if (gridEnabled) { 883 swiper.grid.initSlides(slidesLength); 884 } 885 886 // Calc slides 887 let slideSize; 888 const shouldResetSlideSize = params.slidesPerView === 'auto' && params.breakpoints && Object.keys(params.breakpoints).filter(key => { 889 return typeof params.breakpoints[key].slidesPerView !== 'undefined'; 890 }).length > 0; 891 for (let i = 0; i < slidesLength; i += 1) { 892 slideSize = 0; 893 let slide; 894 if (slides[i]) slide = slides[i]; 895 if (gridEnabled) { 896 swiper.grid.updateSlide(i, slide, slidesLength, getDirectionLabel); 897 } 898 if (slides[i] && elementStyle(slide, 'display') === 'none') continue; // eslint-disable-line 899 900 if (params.slidesPerView === 'auto') { 901 if (shouldResetSlideSize) { 902 slides[i].style[getDirectionLabel('width')] = ``; 903 } 904 const slideStyles = getComputedStyle(slide); 905 const currentTransform = slide.style.transform; 906 const currentWebKitTransform = slide.style.webkitTransform; 907 if (currentTransform) { 908 slide.style.transform = 'none'; 909 } 910 if (currentWebKitTransform) { 911 slide.style.webkitTransform = 'none'; 912 } 913 if (params.roundLengths) { 914 slideSize = swiper.isHorizontal() ? elementOuterSize(slide, 'width', true) : elementOuterSize(slide, 'height', true); 915 } else { 916 // eslint-disable-next-line 917 const width = getDirectionPropertyValue(slideStyles, 'width'); 918 const paddingLeft = getDirectionPropertyValue(slideStyles, 'padding-left'); 919 const paddingRight = getDirectionPropertyValue(slideStyles, 'padding-right'); 920 const marginLeft = getDirectionPropertyValue(slideStyles, 'margin-left'); 921 const marginRight = getDirectionPropertyValue(slideStyles, 'margin-right'); 922 const boxSizing = slideStyles.getPropertyValue('box-sizing'); 923 if (boxSizing && boxSizing === 'border-box') { 924 slideSize = width + marginLeft + marginRight; 925 } else { 926 const { 927 clientWidth, 928 offsetWidth 929 } = slide; 930 slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth); 931 } 932 } 933 if (currentTransform) { 934 slide.style.transform = currentTransform; 935 } 936 if (currentWebKitTransform) { 937 slide.style.webkitTransform = currentWebKitTransform; 938 } 939 if (params.roundLengths) slideSize = Math.floor(slideSize); 940 } else { 941 slideSize = (swiperSize - (params.slidesPerView - 1) * spaceBetween) / params.slidesPerView; 942 if (params.roundLengths) slideSize = Math.floor(slideSize); 943 if (slides[i]) { 944 slides[i].style[getDirectionLabel('width')] = `${slideSize}px`; 945 } 946 } 947 if (slides[i]) { 948 slides[i].swiperSlideSize = slideSize; 949 } 950 slidesSizesGrid.push(slideSize); 951 if (params.centeredSlides) { 952 slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween; 953 if (prevSlideSize === 0 && i !== 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween; 954 if (i === 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween; 955 if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0; 956 if (params.roundLengths) slidePosition = Math.floor(slidePosition); 957 if (index % params.slidesPerGroup === 0) snapGrid.push(slidePosition); 958 slidesGrid.push(slidePosition); 959 } else { 960 if (params.roundLengths) slidePosition = Math.floor(slidePosition); 961 if ((index - Math.min(swiper.params.slidesPerGroupSkip, index)) % swiper.params.slidesPerGroup === 0) snapGrid.push(slidePosition); 962 slidesGrid.push(slidePosition); 963 slidePosition = slidePosition + slideSize + spaceBetween; 964 } 965 swiper.virtualSize += slideSize + spaceBetween; 966 prevSlideSize = slideSize; 967 index += 1; 968 } 969 swiper.virtualSize = Math.max(swiper.virtualSize, swiperSize) + offsetAfter; 970 if (rtl && wrongRTL && (params.effect === 'slide' || params.effect === 'coverflow')) { 971 wrapperEl.style.width = `${swiper.virtualSize + params.spaceBetween}px`; 972 } 973 if (params.setWrapperSize) { 974 wrapperEl.style[getDirectionLabel('width')] = `${swiper.virtualSize + params.spaceBetween}px`; 975 } 976 if (gridEnabled) { 977 swiper.grid.updateWrapperSize(slideSize, snapGrid, getDirectionLabel); 978 } 979 980 // Remove last grid elements depending on width 981 if (!params.centeredSlides) { 982 const newSlidesGrid = []; 983 for (let i = 0; i < snapGrid.length; i += 1) { 984 let slidesGridItem = snapGrid[i]; 985 if (params.roundLengths) slidesGridItem = Math.floor(slidesGridItem); 986 if (snapGrid[i] <= swiper.virtualSize - swiperSize) { 987 newSlidesGrid.push(slidesGridItem); 988 } 989 } 990 snapGrid = newSlidesGrid; 991 if (Math.floor(swiper.virtualSize - swiperSize) - Math.floor(snapGrid[snapGrid.length - 1]) > 1) { 992 snapGrid.push(swiper.virtualSize - swiperSize); 993 } 994 } 995 if (isVirtual && params.loop) { 996 const size = slidesSizesGrid[0] + spaceBetween; 997 if (params.slidesPerGroup > 1) { 998 const groups = Math.ceil((swiper.virtual.slidesBefore + swiper.virtual.slidesAfter) / params.slidesPerGroup); 999 const groupSize = size * params.slidesPerGroup; 1000 for (let i = 0; i < groups; i += 1) { 1001 snapGrid.push(snapGrid[snapGrid.length - 1] + groupSize); 1002 } 1003 } 1004 for (let i = 0; i < swiper.virtual.slidesBefore + swiper.virtual.slidesAfter; i += 1) { 1005 if (params.slidesPerGroup === 1) { 1006 snapGrid.push(snapGrid[snapGrid.length - 1] + size); 1007 } 1008 slidesGrid.push(slidesGrid[slidesGrid.length - 1] + size); 1009 swiper.virtualSize += size; 1010 } 1011 } 1012 if (snapGrid.length === 0) snapGrid = [0]; 1013 if (params.spaceBetween !== 0) { 1014 const key = swiper.isHorizontal() && rtl ? 'marginLeft' : getDirectionLabel('marginRight'); 1015 slides.filter((_, slideIndex) => { 1016 if (!params.cssMode || params.loop) return true; 1017 if (slideIndex === slides.length - 1) { 1018 return false; 1019 } 1020 return true; 1021 }
vendor: 3,821 bytes, lines 1021-1111
1021).forEach(slideEl => { 1022 slideEl.style[key] = `${spaceBetween}px`; 1023 }); 1024 } 1025 if (params.centeredSlides && params.centeredSlidesBounds) { 1026 let allSlidesSize = 0; 1027 slidesSizesGrid.forEach(slideSizeValue => { 1028 allSlidesSize += slideSizeValue + (params.spaceBetween ? params.spaceBetween : 0); 1029 }); 1030 allSlidesSize -= params.spaceBetween; 1031 const maxSnap = allSlidesSize - swiperSize; 1032 snapGrid = snapGrid.map(snap => { 1033 if (snap < 0) return -offsetBefore; 1034 if (snap > maxSnap) return maxSnap + offsetAfter; 1035 return snap; 1036 }); 1037 } 1038 if (params.centerInsufficientSlides) { 1039 let allSlidesSize = 0; 1040 slidesSizesGrid.forEach(slideSizeValue => { 1041 allSlidesSize += slideSizeValue + (params.spaceBetween ? params.spaceBetween : 0); 1042 }); 1043 allSlidesSize -= params.spaceBetween; 1044 if (allSlidesSize < swiperSize) { 1045 const allSlidesOffset = (swiperSize - allSlidesSize) / 2; 1046 snapGrid.forEach((snap, snapIndex) => { 1047 snapGrid[snapIndex] = snap - allSlidesOffset; 1048 }); 1049 slidesGrid.forEach((snap, snapIndex) => { 1050 slidesGrid[snapIndex] = snap + allSlidesOffset; 1051 }); 1052 } 1053 } 1054 Object.assign(swiper, { 1055 slides, 1056 snapGrid, 1057 slidesGrid, 1058 slidesSizesGrid 1059 }); 1060 if (params.centeredSlides && params.cssMode && !params.centeredSlidesBounds) { 1061 setCSSProperty(wrapperEl, '--swiper-centered-offset-before', `${-snapGrid[0]}px`); 1062 setCSSProperty(wrapperEl, '--swiper-centered-offset-after', `${swiper.size / 2 - slidesSizesGrid[slidesSizesGrid.length - 1] / 2}px`); 1063 const addToSnapGrid = -swiper.snapGrid[0]; 1064 const addToSlidesGrid = -swiper.slidesGrid[0]; 1065 swiper.snapGrid = swiper.snapGrid.map(v => v + addToSnapGrid); 1066 swiper.slidesGrid = swiper.slidesGrid.map(v => v + addToSlidesGrid); 1067 } 1068 if (slidesLength !== previousSlidesLength) { 1069 swiper.emit('slidesLengthChange'); 1070 } 1071 if (snapGrid.length !== previousSnapGridLength) { 1072 if (swiper.params.watchOverflow) swiper.checkOverflow(); 1073 swiper.emit('snapGridLengthChange'); 1074 } 1075 if (slidesGrid.length !== previousSlidesGridLength) { 1076 swiper.emit('slidesGridLengthChange'); 1077 } 1078 if (params.watchSlidesProgress) { 1079 swiper.updateSlidesOffset(); 1080 } 1081 if (!isVirtual && !params.cssMode && (params.effect === 'slide' || params.effect === 'fade')) { 1082 const backFaceHiddenClass = `${params.containerModifierClass}backface-hidden`; 1083 const hasClassBackfaceClassAdded = swiper.el.classList.contains(backFaceHiddenClass); 1084 if (slidesLength <= params.maxBackfaceHiddenSlides) { 1085 if (!hasClassBackfaceClassAdded) swiper.el.classList.add(backFaceHiddenClass); 1086 } else if (hasClassBackfaceClassAdded) { 1087 swiper.el.classList.remove(backFaceHiddenClass); 1088 } 1089 } 1090 } 1091 1092 function updateAutoHeight(speed) { 1093 const swiper = this; 1094 const activeSlides = []; 1095 const isVirtual = swiper.virtual && swiper.params.virtual.enabled; 1096 let newHeight = 0; 1097 let i; 1098 if (typeof speed === 'number') { 1099 swiper.setTransition(speed); 1100 } else if (speed === true) { 1101 swiper.setTransition(swiper.params.speed); 1102 } 1103 const getSlideByIndex = index => { 1104 if (isVirtual) { 1105 return swiper.slides.filter(el => parseInt(el.getAttribute('data-swiper-slide-index'), 10) === index)[0]; 1106 } 1107 return swiper.slides[index]; 1108 }; 1109 // Find slides currently in view 1110 if (swiper.params.slidesPerView !== 'auto' && swiper.params.slidesPerView > 1) { 1111 if (swiper.params.centeredSlides) {
vendor: 1,879 bytes, lines 1112-1164
1112 (swiper.visibleSlides || []).forEach(slide => { 1113 activeSlides.push(slide); 1114 }); 1115 } else { 1116 for (i = 0; i < Math.ceil(swiper.params.slidesPerView); i += 1) { 1117 const index = swiper.activeIndex + i; 1118 if (index > swiper.slides.length && !isVirtual) break; 1119 activeSlides.push(getSlideByIndex(index)); 1120 } 1121 } 1122 } else { 1123 activeSlides.push(getSlideByIndex(swiper.activeIndex)); 1124 } 1125 1126 // Find new height from highest slide in view 1127 for (i = 0; i < activeSlides.length; i += 1) { 1128 if (typeof activeSlides[i] !== 'undefined') { 1129 const height = activeSlides[i].offsetHeight; 1130 newHeight = height > newHeight ? height : newHeight; 1131 } 1132 } 1133 1134 // Update Height 1135 if (newHeight || newHeight === 0) swiper.wrapperEl.style.height = `${newHeight}px`; 1136 } 1137 1138 function updateSlidesOffset() { 1139 const swiper = this; 1140 const slides = swiper.slides; 1141 // eslint-disable-next-line 1142 const minusOffset = swiper.isElement ? swiper.isHorizontal() ? swiper.wrapperEl.offsetLeft : swiper.wrapperEl.offsetTop : 0; 1143 for (let i = 0; i < slides.length; i += 1) { 1144 slides[i].swiperSlideOffset = (swiper.isHorizontal() ? slides[i].offsetLeft : slides[i].offsetTop) - minusOffset; 1145 } 1146 } 1147 1148 function updateSlidesProgress(translate) { 1149 if (translate === void 0) { 1150 translate = this && this.translate || 0; 1151 } 1152 const swiper = this; 1153 const params = swiper.params; 1154 const { 1155 slides, 1156 rtlTranslate: rtl, 1157 snapGrid 1158 } = swiper; 1159 if (slides.length === 0) return; 1160 if (typeof slides[0].swiperSlideOffset === 'undefined') swiper.updateSlidesOffset(); 1161 let offsetCenter = -translate; 1162 if (rtl) offsetCenter = translate; 1163 1164 // Visible Slides
vendor: 9,414 bytes, lines 1165-1401
1165 slides.forEach(slideEl => { 1166 slideEl.classList.remove(params.slideVisibleClass); 1167 }); 1168 swiper.visibleSlidesIndexes = []; 1169 swiper.visibleSlides = []; 1170 for (let i = 0; i < slides.length; i += 1) { 1171 const slide = slides[i]; 1172 let slideOffset = slide.swiperSlideOffset; 1173 if (params.cssMode && params.centeredSlides) { 1174 slideOffset -= slides[0].swiperSlideOffset; 1175 } 1176 const slideProgress = (offsetCenter + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + params.spaceBetween); 1177 const originalSlideProgress = (offsetCenter - snapGrid[0] + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + params.spaceBetween); 1178 const slideBefore = -(offsetCenter - slideOffset); 1179 const slideAfter = slideBefore + swiper.slidesSizesGrid[i]; 1180 const isVisible = slideBefore >= 0 && slideBefore < swiper.size - 1 || slideAfter > 1 && slideAfter <= swiper.size || slideBefore <= 0 && slideAfter >= swiper.size; 1181 if (isVisible) { 1182 swiper.visibleSlides.push(slide); 1183 swiper.visibleSlidesIndexes.push(i); 1184 slides[i].classList.add(params.slideVisibleClass); 1185 } 1186 slide.progress = rtl ? -slideProgress : slideProgress; 1187 slide.originalProgress = rtl ? -originalSlideProgress : originalSlideProgress; 1188 } 1189 } 1190 1191 function updateProgress(translate) { 1192 const swiper = this; 1193 if (typeof translate === 'undefined') { 1194 const multiplier = swiper.rtlTranslate ? -1 : 1; 1195 // eslint-disable-next-line 1196 translate = swiper && swiper.translate && swiper.translate * multiplier || 0; 1197 } 1198 const params = swiper.params; 1199 const translatesDiff = swiper.maxTranslate() - swiper.minTranslate(); 1200 let { 1201 progress, 1202 isBeginning, 1203 isEnd, 1204 progressLoop 1205 } = swiper; 1206 const wasBeginning = isBeginning; 1207 const wasEnd = isEnd; 1208 if (translatesDiff === 0) { 1209 progress = 0; 1210 isBeginning = true; 1211 isEnd = true; 1212 } else { 1213 progress = (translate - swiper.minTranslate()) / translatesDiff; 1214 const isBeginningRounded = Math.abs(translate - swiper.minTranslate()) < 1; 1215 const isEndRounded = Math.abs(translate - swiper.maxTranslate()) < 1; 1216 isBeginning = isBeginningRounded || progress <= 0; 1217 isEnd = isEndRounded || progress >= 1; 1218 if (isBeginningRounded) progress = 0; 1219 if (isEndRounded) progress = 1; 1220 } 1221 if (params.loop) { 1222 const firstSlideIndex = elementIndex(swiper.slides.filter(el => el.getAttribute('data-swiper-slide-index') === '0')[0]); 1223 const lastSlideIndex = elementIndex(swiper.slides.filter(el => el.getAttribute('data-swiper-slide-index') * 1 === swiper.slides.length - 1)[0]); 1224 const firstSlideTranslate = swiper.slidesGrid[firstSlideIndex]; 1225 const lastSlideTranslate = swiper.slidesGrid[lastSlideIndex]; 1226 const translateMax = swiper.slidesGrid[swiper.slidesGrid.length - 1]; 1227 const translateAbs = Math.abs(translate); 1228 if (translateAbs >= firstSlideTranslate) { 1229 progressLoop = (translateAbs - firstSlideTranslate) / translateMax; 1230 } else { 1231 progressLoop = (translateAbs + translateMax - lastSlideTranslate) / translateMax; 1232 } 1233 if (progressLoop > 1) progressLoop -= 1; 1234 } 1235 Object.assign(swiper, { 1236 progress, 1237 progressLoop, 1238 isBeginning, 1239 isEnd 1240 }); 1241 if (params.watchSlidesProgress || params.centeredSlides && params.autoHeight) swiper.updateSlidesProgress(translate); 1242 if (isBeginning && !wasBeginning) { 1243 swiper.emit('reachBeginning toEdge'); 1244 } 1245 if (isEnd && !wasEnd) { 1246 swiper.emit('reachEnd toEdge'); 1247 } 1248 if (wasBeginning && !isBeginning || wasEnd && !isEnd) { 1249 swiper.emit('fromEdge'); 1250 } 1251 swiper.emit('progress', progress); 1252 } 1253 1254 function updateSlidesClasses() { 1255 const swiper = this; 1256 const { 1257 slides, 1258 params, 1259 slidesEl, 1260 activeIndex 1261 } = swiper; 1262 const isVirtual = swiper.virtual && params.virtual.enabled; 1263 const getFilteredSlide = selector => { 1264 return elementChildren(slidesEl, `.${params.slideClass}${selector}, swiper-slide${selector}`)[0]; 1265 }; 1266 slides.forEach(slideEl => { 1267 slideEl.classList.remove(params.slideActiveClass, params.slideNextClass, params.slidePrevClass); 1268 }); 1269 let activeSlide; 1270 if (isVirtual) { 1271 if (params.loop) { 1272 let slideIndex = activeIndex - swiper.virtual.slidesBefore; 1273 if (slideIndex < 0) slideIndex = swiper.virtual.slides.length + slideIndex; 1274 if (slideIndex >= swiper.virtual.slides.length) slideIndex -= swiper.virtual.slides.length; 1275 activeSlide = getFilteredSlide(`[data-swiper-slide-index="${slideIndex}"]`); 1276 } else { 1277 activeSlide = getFilteredSlide(`[data-swiper-slide-index="${activeIndex}"]`); 1278 } 1279 } else { 1280 activeSlide = slides[activeIndex]; 1281 } 1282 if (activeSlide) { 1283 // Active classes 1284 activeSlide.classList.add(params.slideActiveClass); 1285 1286 // Next Slide 1287 let nextSlide = elementNextAll(activeSlide, `.${params.slideClass}, swiper-slide`)[0]; 1288 if (params.loop && !nextSlide) { 1289 nextSlide = slides[0]; 1290 } 1291 if (nextSlide) { 1292 nextSlide.classList.add(params.slideNextClass); 1293 } 1294 // Prev Slide 1295 let prevSlide = elementPrevAll(activeSlide, `.${params.slideClass}, swiper-slide`)[0]; 1296 if (params.loop && !prevSlide === 0) { 1297 prevSlide = slides[slides.length - 1]; 1298 } 1299 if (prevSlide) { 1300 prevSlide.classList.add(params.slidePrevClass); 1301 } 1302 } 1303 swiper.emitSlidesClasses(); 1304 } 1305 1306 function getActiveIndexByTranslate(swiper) { 1307 const { 1308 slidesGrid, 1309 params 1310 } = swiper; 1311 const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate; 1312 let activeIndex; 1313 for (let i = 0; i < slidesGrid.length; i += 1) { 1314 if (typeof slidesGrid[i + 1] !== 'undefined') { 1315 if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1] - (slidesGrid[i + 1] - slidesGrid[i]) / 2) { 1316 activeIndex = i; 1317 } else if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1]) { 1318 activeIndex = i + 1; 1319 } 1320 } else if (translate >= slidesGrid[i]) { 1321 activeIndex = i; 1322 } 1323 } 1324 // Normalize slideIndex 1325 if (params.normalizeSlideIndex) { 1326 if (activeIndex < 0 || typeof activeIndex === 'undefined') activeIndex = 0; 1327 } 1328 return activeIndex; 1329 } 1330 function updateActiveIndex(newActiveIndex) { 1331 const swiper = this; 1332 const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate; 1333 const { 1334 snapGrid, 1335 params, 1336 activeIndex: previousIndex, 1337 realIndex: previousRealIndex, 1338 snapIndex: previousSnapIndex 1339 } = swiper; 1340 let activeIndex = newActiveIndex; 1341 let snapIndex; 1342 const getVirtualRealIndex = aIndex => { 1343 let realIndex = aIndex - swiper.virtual.slidesBefore; 1344 if (realIndex < 0) { 1345 realIndex = swiper.virtual.slides.length + realIndex; 1346 } 1347 if (realIndex >= swiper.virtual.slides.length) { 1348 realIndex -= swiper.virtual.slides.length; 1349 } 1350 return realIndex; 1351 }; 1352 if (typeof activeIndex === 'undefined') { 1353 activeIndex = getActiveIndexByTranslate(swiper); 1354 } 1355 if (snapGrid.indexOf(translate) >= 0) { 1356 snapIndex = snapGrid.indexOf(translate); 1357 } else { 1358 const skip = Math.min(params.slidesPerGroupSkip, activeIndex); 1359 snapIndex = skip + Math.floor((activeIndex - skip) / params.slidesPerGroup); 1360 } 1361 if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1; 1362 if (activeIndex === previousIndex) { 1363 if (snapIndex !== previousSnapIndex) { 1364 swiper.snapIndex = snapIndex; 1365 swiper.emit('snapIndexChange'); 1366 } 1367 if (swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) { 1368 swiper.realIndex = getVirtualRealIndex(activeIndex); 1369 } 1370 return; 1371 } 1372 // Get real index 1373 let realIndex; 1374 if (swiper.virtual && params.virtual.enabled && params.loop) { 1375 realIndex = getVirtualRealIndex(activeIndex); 1376 } else if (swiper.slides[activeIndex]) { 1377 realIndex = parseInt(swiper.slides[activeIndex].getAttribute('data-swiper-slide-index') || activeIndex, 10); 1378 } else { 1379 realIndex = activeIndex; 1380 } 1381 Object.assign(swiper, { 1382 snapIndex, 1383 realIndex, 1384 previousIndex, 1385 activeIndex 1386 }); 1387 swiper.emit('activeIndexChange'); 1388 swiper.emit('snapIndexChange'); 1389 if (previousRealIndex !== realIndex) { 1390 swiper.emit('realIndexChange'); 1391 } 1392 if (swiper.initialized || swiper.params.runCallbacksOnInit) { 1393 swiper.emit('slideChange'); 1394 } 1395 } 1396 1397 function updateClickedSlide(e) { 1398 const swiper = this; 1399 const params = swiper.params; 1400 const slide = e.closest(`.${params.slideClass}, swiper-slide`); 1401 let slideFound = false;
vendor: 7,877 bytes, lines 1402-1669
1402 let slideIndex; 1403 if (slide) { 1404 for (let i = 0; i < swiper.slides.length; i += 1) { 1405 if (swiper.slides[i] === slide) { 1406 slideFound = true; 1407 slideIndex = i; 1408 break; 1409 } 1410 } 1411 } 1412 if (slide && slideFound) { 1413 swiper.clickedSlide = slide; 1414 if (swiper.virtual && swiper.params.virtual.enabled) { 1415 swiper.clickedIndex = parseInt(slide.getAttribute('data-swiper-slide-index'), 10); 1416 } else { 1417 swiper.clickedIndex = slideIndex; 1418 } 1419 } else { 1420 swiper.clickedSlide = undefined; 1421 swiper.clickedIndex = undefined; 1422 return; 1423 } 1424 if (params.slideToClickedSlide && swiper.clickedIndex !== undefined && swiper.clickedIndex !== swiper.activeIndex) { 1425 swiper.slideToClickedSlide(); 1426 } 1427 } 1428 1429 var update = { 1430 updateSize, 1431 updateSlides, 1432 updateAutoHeight, 1433 updateSlidesOffset, 1434 updateSlidesProgress, 1435 updateProgress, 1436 updateSlidesClasses, 1437 updateActiveIndex, 1438 updateClickedSlide 1439 }; 1440 1441 function getSwiperTranslate(axis) { 1442 if (axis === void 0) { 1443 axis = this.isHorizontal() ? 'x' : 'y'; 1444 } 1445 const swiper = this; 1446 const { 1447 params, 1448 rtlTranslate: rtl, 1449 translate, 1450 wrapperEl 1451 } = swiper; 1452 if (params.virtualTranslate) { 1453 return rtl ? -translate : translate; 1454 } 1455 if (params.cssMode) { 1456 return translate; 1457 } 1458 let currentTranslate = getTranslate(wrapperEl, axis); 1459 if (rtl) currentTranslate = -currentTranslate; 1460 return currentTranslate || 0; 1461 } 1462 1463 function setTranslate(translate, byController) { 1464 const swiper = this; 1465 const { 1466 rtlTranslate: rtl, 1467 params, 1468 wrapperEl, 1469 progress 1470 } = swiper; 1471 let x = 0; 1472 let y = 0; 1473 const z = 0; 1474 if (swiper.isHorizontal()) { 1475 x = rtl ? -translate : translate; 1476 } else { 1477 y = translate; 1478 } 1479 if (params.roundLengths) { 1480 x = Math.floor(x); 1481 y = Math.floor(y); 1482 } 1483 if (params.cssMode) { 1484 wrapperEl[swiper.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = swiper.isHorizontal() ? -x : -y; 1485 } else if (!params.virtualTranslate) { 1486 wrapperEl.style.transform = `translate3d(${x}px, ${y}px, ${z}px)`; 1487 } 1488 swiper.previousTranslate = swiper.translate; 1489 swiper.translate = swiper.isHorizontal() ? x : y; 1490 1491 // Check if we need to update progress 1492 let newProgress; 1493 const translatesDiff = swiper.maxTranslate() - swiper.minTranslate(); 1494 if (translatesDiff === 0) { 1495 newProgress = 0; 1496 } else { 1497 newProgress = (translate - swiper.minTranslate()) / translatesDiff; 1498 } 1499 if (newProgress !== progress) { 1500 swiper.updateProgress(translate); 1501 } 1502 swiper.emit('setTranslate', swiper.translate, byController); 1503 } 1504 1505 function minTranslate() { 1506 return -this.snapGrid[0]; 1507 } 1508 1509 function maxTranslate() { 1510 return -this.snapGrid[this.snapGrid.length - 1]; 1511 } 1512 1513 function translateTo(translate, speed, runCallbacks, translateBounds, internal) { 1514 if (translate === void 0) { 1515 translate = 0; 1516 } 1517 if (speed === void 0) { 1518 speed = this.params.speed; 1519 } 1520 if (runCallbacks === void 0) { 1521 runCallbacks = true; 1522 } 1523 if (translateBounds === void 0) { 1524 translateBounds = true; 1525 } 1526 const swiper = this; 1527 const { 1528 params, 1529 wrapperEl 1530 } = swiper; 1531 if (swiper.animating && params.preventInteractionOnTransition) { 1532 return false; 1533 } 1534 const minTranslate = swiper.minTranslate(); 1535 const maxTranslate = swiper.maxTranslate(); 1536 let newTranslate; 1537 if (translateBounds && translate > minTranslate) newTranslate = minTranslate;else if (translateBounds && translate < maxTranslate) newTranslate = maxTranslate;else newTranslate = translate; 1538 1539 // Update progress 1540 swiper.updateProgress(newTranslate); 1541 if (params.cssMode) { 1542 const isH = swiper.isHorizontal(); 1543 if (speed === 0) { 1544 wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -newTranslate; 1545 } else { 1546 if (!swiper.support.smoothScroll) { 1547 animateCSSModeScroll({ 1548 swiper, 1549 targetPosition: -newTranslate, 1550 side: isH ? 'left' : 'top' 1551 }); 1552 return true; 1553 } 1554 wrapperEl.scrollTo({ 1555 [isH ? 'left' : 'top']: -newTranslate, 1556 behavior: 'smooth' 1557 }); 1558 } 1559 return true; 1560 } 1561 if (speed === 0) { 1562 swiper.setTransition(0); 1563 swiper.setTranslate(newTranslate); 1564 if (runCallbacks) { 1565 swiper.emit('beforeTransitionStart', speed, internal); 1566 swiper.emit('transitionEnd'); 1567 } 1568 } else { 1569 swiper.setTransition(speed); 1570 swiper.setTranslate(newTranslate); 1571 if (runCallbacks) { 1572 swiper.emit('beforeTransitionStart', speed, internal); 1573 swiper.emit('transitionStart'); 1574 } 1575 if (!swiper.animating) { 1576 swiper.animating = true; 1577 if (!swiper.onTranslateToWrapperTransitionEnd) { 1578 swiper.onTranslateToWrapperTransitionEnd = function transitionEnd(e) { 1579 if (!swiper || swiper.destroyed) return; 1580 if (e.target !== this) return; 1581 swiper.wrapperEl.removeEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd); 1582 swiper.onTranslateToWrapperTransitionEnd = null; 1583 delete swiper.onTranslateToWrapperTransitionEnd; 1584 if (runCallbacks) { 1585 swiper.emit('transitionEnd'); 1586 } 1587 }; 1588 } 1589 swiper.wrapperEl.addEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd); 1590 } 1591 } 1592 return true; 1593 } 1594 1595 var translate = { 1596 getTranslate: getSwiperTranslate, 1597 setTranslate, 1598 minTranslate, 1599 maxTranslate, 1600 translateTo 1601 }; 1602 1603 function setTransition(duration, byController) { 1604 const swiper = this; 1605 if (!swiper.params.cssMode) { 1606 swiper.wrapperEl.style.transitionDuration = `${duration}ms`; 1607 } 1608 swiper.emit('setTransition', duration, byController); 1609 } 1610 1611 function transitionEmit(_ref) { 1612 let { 1613 swiper, 1614 runCallbacks, 1615 direction, 1616 step 1617 } = _ref; 1618 const { 1619 activeIndex, 1620 previousIndex 1621 } = swiper; 1622 let dir = direction; 1623 if (!dir) { 1624 if (activeIndex > previousIndex) dir = 'next';else if (activeIndex < previousIndex) dir = 'prev';else dir = 'reset'; 1625 } 1626 swiper.emit(`transition${step}`); 1627 if (runCallbacks && activeIndex !== previousIndex) { 1628 if (dir === 'reset') { 1629 swiper.emit(`slideResetTransition${step}`); 1630 return; 1631 } 1632 swiper.emit(`slideChangeTransition${step}`); 1633 if (dir === 'next') { 1634 swiper.emit(`slideNextTransition${step}`); 1635 } else { 1636 swiper.emit(`slidePrevTransition${step}`); 1637 } 1638 } 1639 } 1640 1641 function transitionStart(runCallbacks, direction) { 1642 if (runCallbacks === void 0) { 1643 runCallbacks = true; 1644 } 1645 const swiper = this; 1646 const { 1647 params 1648 } = swiper; 1649 if (params.cssMode) return; 1650 if (params.autoHeight) { 1651 swiper.updateAutoHeight(); 1652 } 1653 transitionEmit({ 1654 swiper, 1655 runCallbacks, 1656 direction, 1657 step: 'Start' 1658 }); 1659 } 1660 1661 function transitionEnd(runCallbacks, direction) { 1662 if (runCallbacks === void 0) { 1663 runCallbacks = true; 1664 } 1665 const swiper = this; 1666 const { 1667 params 1668 } = swiper; 1669 swiper.animating = false;
vendor: 4,478 bytes, lines 1670-1793
1670 if (params.cssMode) return; 1671 swiper.setTransition(0); 1672 transitionEmit({ 1673 swiper, 1674 runCallbacks, 1675 direction, 1676 step: 'End' 1677 }); 1678 } 1679 1680 var transition = { 1681 setTransition, 1682 transitionStart, 1683 transitionEnd 1684 }; 1685 1686 function slideTo(index, speed, runCallbacks, internal, initial) { 1687 if (index === void 0) { 1688 index = 0; 1689 } 1690 if (speed === void 0) { 1691 speed = this.params.speed; 1692 } 1693 if (runCallbacks === void 0) { 1694 runCallbacks = true; 1695 } 1696 if (typeof index === 'string') { 1697 index = parseInt(index, 10); 1698 } 1699 const swiper = this; 1700 let slideIndex = index; 1701 if (slideIndex < 0) slideIndex = 0; 1702 const { 1703 params, 1704 snapGrid, 1705 slidesGrid, 1706 previousIndex, 1707 activeIndex, 1708 rtlTranslate: rtl, 1709 wrapperEl, 1710 enabled 1711 } = swiper; 1712 if (swiper.animating && params.preventInteractionOnTransition || !enabled && !internal && !initial) { 1713 return false; 1714 } 1715 const skip = Math.min(swiper.params.slidesPerGroupSkip, slideIndex); 1716 let snapIndex = skip + Math.floor((slideIndex - skip) / swiper.params.slidesPerGroup); 1717 if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1; 1718 const translate = -snapGrid[snapIndex]; 1719 // Normalize slideIndex 1720 if (params.normalizeSlideIndex) { 1721 for (let i = 0; i < slidesGrid.length; i += 1) { 1722 const normalizedTranslate = -Math.floor(translate * 100); 1723 const normalizedGrid = Math.floor(slidesGrid[i] * 100); 1724 const normalizedGridNext = Math.floor(slidesGrid[i + 1] * 100); 1725 if (typeof slidesGrid[i + 1] !== 'undefined') { 1726 if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext - (normalizedGridNext - normalizedGrid) / 2) { 1727 slideIndex = i; 1728 } else if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext) { 1729 slideIndex = i + 1; 1730 } 1731 } else if (normalizedTranslate >= normalizedGrid) { 1732 slideIndex = i; 1733 } 1734 } 1735 } 1736 // Directions locks 1737 if (swiper.initialized && slideIndex !== activeIndex) { 1738 if (!swiper.allowSlideNext && translate < swiper.translate && translate < swiper.minTranslate()) { 1739 return false; 1740 } 1741 if (!swiper.allowSlidePrev && translate > swiper.translate && translate > swiper.maxTranslate()) { 1742 if ((activeIndex || 0) !== slideIndex) { 1743 return false; 1744 } 1745 } 1746 } 1747 if (slideIndex !== (previousIndex || 0) && runCallbacks) { 1748 swiper.emit('beforeSlideChangeStart'); 1749 } 1750 1751 // Update progress 1752 swiper.updateProgress(translate); 1753 let direction; 1754 if (slideIndex > activeIndex) direction = 'next';else if (slideIndex < activeIndex) direction = 'prev';else direction = 'reset'; 1755 1756 // Update Index 1757 if (rtl && -translate === swiper.translate || !rtl && translate === swiper.translate) { 1758 swiper.updateActiveIndex(slideIndex); 1759 // Update Height 1760 if (params.autoHeight) { 1761 swiper.updateAutoHeight(); 1762 } 1763 swiper.updateSlidesClasses(); 1764 if (params.effect !== 'slide') { 1765 swiper.setTranslate(translate); 1766 } 1767 if (direction !== 'reset') { 1768 swiper.transitionStart(runCallbacks, direction); 1769 swiper.transitionEnd(runCallbacks, direction); 1770 } 1771 return false; 1772 } 1773 if (params.cssMode) { 1774 const isH = swiper.isHorizontal(); 1775 const t = rtl ? translate : -translate; 1776 if (speed === 0) { 1777 const isVirtual = swiper.virtual && swiper.params.virtual.enabled; 1778 if (isVirtual) { 1779 swiper.wrapperEl.style.scrollSnapType = 'none'; 1780 swiper._immediateVirtual = true; 1781 } 1782 if (isVirtual && !swiper._cssModeVirtualInitialSet && swiper.params.initialSlide > 0) { 1783 swiper._cssModeVirtualInitialSet = true; 1784 requestAnimationFrame(() => { 1785 wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t; 1786 }); 1787 } else { 1788 wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t; 1789 } 1790 if (isVirtual) { 1791 requestAnimationFrame(() => { 1792 swiper.wrapperEl.style.scrollSnapType = ''; 1793 swiper._immediateVirtual = false;
vendor: 4,286 bytes, lines 1794-1919
1794 }); 1795 } 1796 } else { 1797 if (!swiper.support.smoothScroll) { 1798 animateCSSModeScroll({ 1799 swiper, 1800 targetPosition: t, 1801 side: isH ? 'left' : 'top' 1802 }); 1803 return true; 1804 } 1805 wrapperEl.scrollTo({ 1806 [isH ? 'left' : 'top']: t, 1807 behavior: 'smooth' 1808 }); 1809 } 1810 return true; 1811 } 1812 swiper.setTransition(speed); 1813 swiper.setTranslate(translate); 1814 swiper.updateActiveIndex(slideIndex); 1815 swiper.updateSlidesClasses(); 1816 swiper.emit('beforeTransitionStart', speed, internal); 1817 swiper.transitionStart(runCallbacks, direction); 1818 if (speed === 0) { 1819 swiper.transitionEnd(runCallbacks, direction); 1820 } else if (!swiper.animating) { 1821 swiper.animating = true; 1822 if (!swiper.onSlideToWrapperTransitionEnd) { 1823 swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) { 1824 if (!swiper || swiper.destroyed) return; 1825 if (e.target !== this) return; 1826 swiper.wrapperEl.removeEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd); 1827 swiper.onSlideToWrapperTransitionEnd = null; 1828 delete swiper.onSlideToWrapperTransitionEnd; 1829 swiper.transitionEnd(runCallbacks, direction); 1830 }; 1831 } 1832 swiper.wrapperEl.addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd); 1833 } 1834 return true; 1835 } 1836 1837 function slideToLoop(index, speed, runCallbacks, internal) { 1838 if (index === void 0) { 1839 index = 0; 1840 } 1841 if (speed === void 0) { 1842 speed = this.params.speed; 1843 } 1844 if (runCallbacks === void 0) { 1845 runCallbacks = true; 1846 } 1847 if (typeof index === 'string') { 1848 const indexAsNumber = parseInt(index, 10); 1849 index = indexAsNumber; 1850 } 1851 const swiper = this; 1852 let newIndex = index; 1853 if (swiper.params.loop) { 1854 if (swiper.virtual && swiper.params.virtual.enabled) { 1855 // eslint-disable-next-line 1856 newIndex = newIndex + swiper.virtual.slidesBefore; 1857 } else { 1858 newIndex = elementIndex(swiper.slides.filter(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === newIndex)[0]); 1859 } 1860 } 1861 return swiper.slideTo(newIndex, speed, runCallbacks, internal); 1862 } 1863 1864 /* eslint no-unused-vars: "off" */ 1865 function slideNext(speed, runCallbacks, internal) { 1866 if (speed === void 0) { 1867 speed = this.params.speed; 1868 } 1869 if (runCallbacks === void 0) { 1870 runCallbacks = true; 1871 } 1872 const swiper = this; 1873 const { 1874 enabled, 1875 params, 1876 animating 1877 } = swiper; 1878 if (!enabled) return swiper; 1879 let perGroup = params.slidesPerGroup; 1880 if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) { 1881 perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1); 1882 } 1883 const increment = swiper.activeIndex < params.slidesPerGroupSkip ? 1 : perGroup; 1884 const isVirtual = swiper.virtual && params.virtual.enabled; 1885 if (params.loop) { 1886 if (animating && !isVirtual && params.loopPreventsSliding) return false; 1887 swiper.loopFix({ 1888 direction: 'next' 1889 }); 1890 // eslint-disable-next-line 1891 swiper._clientLeft = swiper.wrapperEl.clientLeft; 1892 } 1893 if (params.rewind && swiper.isEnd) { 1894 return swiper.slideTo(0, speed, runCallbacks, internal); 1895 } 1896 return swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal); 1897 } 1898 1899 /* eslint no-unused-vars: "off" */ 1900 function slidePrev(speed, runCallbacks, internal) { 1901 if (speed === void 0) { 1902 speed = this.params.speed; 1903 } 1904 if (runCallbacks === void 0) { 1905 runCallbacks = true; 1906 } 1907 const swiper = this; 1908 const { 1909 params, 1910 snapGrid, 1911 slidesGrid, 1912 rtlTranslate, 1913 enabled, 1914 animating 1915 } = swiper; 1916 if (!enabled) return swiper; 1917 const isVirtual = swiper.virtual && params.virtual.enabled; 1918 if (params.loop) { 1919 if (animating && !isVirtual && params.loopPreventsSliding) return false;
vendor: 29,270 bytes, lines 1920-2676
1920 swiper.loopFix({ 1921 direction: 'prev' 1922 }); 1923 // eslint-disable-next-line 1924 swiper._clientLeft = swiper.wrapperEl.clientLeft; 1925 } 1926 const translate = rtlTranslate ? swiper.translate : -swiper.translate; 1927 function normalize(val) { 1928 if (val < 0) return -Math.floor(Math.abs(val)); 1929 return Math.floor(val); 1930 } 1931 const normalizedTranslate = normalize(translate); 1932 const normalizedSnapGrid = snapGrid.map(val => normalize(val)); 1933 let prevSnap = snapGrid[normalizedSnapGrid.indexOf(normalizedTranslate) - 1]; 1934 if (typeof prevSnap === 'undefined' && params.cssMode) { 1935 let prevSnapIndex; 1936 snapGrid.forEach((snap, snapIndex) => { 1937 if (normalizedTranslate >= snap) { 1938 // prevSnap = snap; 1939 prevSnapIndex = snapIndex; 1940 } 1941 }); 1942 if (typeof prevSnapIndex !== 'undefined') { 1943 prevSnap = snapGrid[prevSnapIndex > 0 ? prevSnapIndex - 1 : prevSnapIndex]; 1944 } 1945 } 1946 let prevIndex = 0; 1947 if (typeof prevSnap !== 'undefined') { 1948 prevIndex = slidesGrid.indexOf(prevSnap); 1949 if (prevIndex < 0) prevIndex = swiper.activeIndex - 1; 1950 if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) { 1951 prevIndex = prevIndex - swiper.slidesPerViewDynamic('previous', true) + 1; 1952 prevIndex = Math.max(prevIndex, 0); 1953 } 1954 } 1955 if (params.rewind && swiper.isBeginning) { 1956 const lastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1; 1957 return swiper.slideTo(lastIndex, speed, runCallbacks, internal); 1958 } 1959 return swiper.slideTo(prevIndex, speed, runCallbacks, internal); 1960 } 1961 1962 /* eslint no-unused-vars: "off" */ 1963 function slideReset(speed, runCallbacks, internal) { 1964 if (speed === void 0) { 1965 speed = this.params.speed; 1966 } 1967 if (runCallbacks === void 0) { 1968 runCallbacks = true; 1969 } 1970 const swiper = this; 1971 return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal); 1972 } 1973 1974 /* eslint no-unused-vars: "off" */ 1975 function slideToClosest(speed, runCallbacks, internal, threshold) { 1976 if (speed === void 0) { 1977 speed = this.params.speed; 1978 } 1979 if (runCallbacks === void 0) { 1980 runCallbacks = true; 1981 } 1982 if (threshold === void 0) { 1983 threshold = 0.5; 1984 } 1985 const swiper = this; 1986 let index = swiper.activeIndex; 1987 const skip = Math.min(swiper.params.slidesPerGroupSkip, index); 1988 const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup); 1989 const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate; 1990 if (translate >= swiper.snapGrid[snapIndex]) { 1991 // The current translate is on or after the current snap index, so the choice 1992 // is between the current index and the one after it. 1993 const currentSnap = swiper.snapGrid[snapIndex]; 1994 const nextSnap = swiper.snapGrid[snapIndex + 1]; 1995 if (translate - currentSnap > (nextSnap - currentSnap) * threshold) { 1996 index += swiper.params.slidesPerGroup; 1997 } 1998 } else { 1999 // The current translate is before the current snap index, so the choice 2000 // is between the current index and the one before it. 2001 const prevSnap = swiper.snapGrid[snapIndex - 1]; 2002 const currentSnap = swiper.snapGrid[snapIndex]; 2003 if (translate - prevSnap <= (currentSnap - prevSnap) * threshold) { 2004 index -= swiper.params.slidesPerGroup; 2005 } 2006 } 2007 index = Math.max(index, 0); 2008 index = Math.min(index, swiper.slidesGrid.length - 1); 2009 return swiper.slideTo(index, speed, runCallbacks, internal); 2010 } 2011 2012 function slideToClickedSlide() { 2013 const swiper = this; 2014 const { 2015 params, 2016 slidesEl 2017 } = swiper; 2018 const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : params.slidesPerView; 2019 let slideToIndex = swiper.clickedIndex; 2020 let realIndex; 2021 const slideSelector = swiper.isElement ? `swiper-slide` : `.${params.slideClass}`; 2022 if (params.loop) { 2023 if (swiper.animating) return; 2024 realIndex = parseInt(swiper.clickedSlide.getAttribute('data-swiper-slide-index'), 10); 2025 if (params.centeredSlides) { 2026 if (slideToIndex < swiper.loopedSlides - slidesPerView / 2 || slideToIndex > swiper.slides.length - swiper.loopedSlides + slidesPerView / 2) { 2027 swiper.loopFix(); 2028 slideToIndex = elementIndex(elementChildren(slidesEl, `${slideSelector}[data-swiper-slide-index="${realIndex}"]`)[0]); 2029 nextTick(() => { 2030 swiper.slideTo(slideToIndex); 2031 }); 2032 } else { 2033 swiper.slideTo(slideToIndex); 2034 } 2035 } else if (slideToIndex > swiper.slides.length - slidesPerView) { 2036 swiper.loopFix(); 2037 slideToIndex = elementIndex(elementChildren(slidesEl, `${slideSelector}[data-swiper-slide-index="${realIndex}"]`)[0]); 2038 nextTick(() => { 2039 swiper.slideTo(slideToIndex); 2040 }); 2041 } else { 2042 swiper.slideTo(slideToIndex); 2043 } 2044 } else { 2045 swiper.slideTo(slideToIndex); 2046 } 2047 } 2048 2049 var slide = { 2050 slideTo, 2051 slideToLoop, 2052 slideNext, 2053 slidePrev, 2054 slideReset, 2055 slideToClosest, 2056 slideToClickedSlide 2057 }; 2058 2059 function loopCreate(slideRealIndex) { 2060 const swiper = this; 2061 const { 2062 params, 2063 slidesEl 2064 } = swiper; 2065 if (!params.loop || swiper.virtual && swiper.params.virtual.enabled) return; 2066 const slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`); 2067 slides.forEach((el, index) => { 2068 el.setAttribute('data-swiper-slide-index', index); 2069 }); 2070 swiper.loopFix({ 2071 slideRealIndex, 2072 direction: params.centeredSlides ? undefined : 'next' 2073 }); 2074 } 2075 2076 function loopFix(_temp) { 2077 let { 2078 slideRealIndex, 2079 slideTo = true, 2080 direction, 2081 setTranslate, 2082 activeSlideIndex, 2083 byController, 2084 byMousewheel 2085 } = _temp === void 0 ? {} : _temp; 2086 const swiper = this; 2087 if (!swiper.params.loop) return; 2088 swiper.emit('beforeLoopFix'); 2089 const { 2090 slides, 2091 allowSlidePrev, 2092 allowSlideNext, 2093 slidesEl, 2094 params 2095 } = swiper; 2096 swiper.allowSlidePrev = true; 2097 swiper.allowSlideNext = true; 2098 if (swiper.virtual && params.virtual.enabled) { 2099 if (slideTo) { 2100 if (!params.centeredSlides && swiper.snapIndex === 0) { 2101 swiper.slideTo(swiper.virtual.slides.length, 0, false, true); 2102 } else if (params.centeredSlides && swiper.snapIndex < params.slidesPerView) { 2103 swiper.slideTo(swiper.virtual.slides.length + swiper.snapIndex, 0, false, true); 2104 } else if (swiper.snapIndex === swiper.snapGrid.length - 1) { 2105 swiper.slideTo(swiper.virtual.slidesBefore, 0, false, true); 2106 } 2107 } 2108 swiper.allowSlidePrev = allowSlidePrev; 2109 swiper.allowSlideNext = allowSlideNext; 2110 swiper.emit('loopFix'); 2111 return; 2112 } 2113 const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10)); 2114 let loopedSlides = params.loopedSlides || slidesPerView; 2115 if (loopedSlides % params.slidesPerGroup !== 0) { 2116 loopedSlides += params.slidesPerGroup - loopedSlides % params.slidesPerGroup; 2117 } 2118 swiper.loopedSlides = loopedSlides; 2119 const prependSlidesIndexes = []; 2120 const appendSlidesIndexes = []; 2121 let activeIndex = swiper.activeIndex; 2122 if (typeof activeSlideIndex === 'undefined') { 2123 activeSlideIndex = elementIndex(swiper.slides.filter(el => el.classList.contains('swiper-slide-active'))[0]); 2124 } else { 2125 activeIndex = activeSlideIndex; 2126 } 2127 const isNext = direction === 'next' || !direction; 2128 const isPrev = direction === 'prev' || !direction; 2129 let slidesPrepended = 0; 2130 let slidesAppended = 0; 2131 // prepend last slides before start 2132 if (activeSlideIndex < loopedSlides) { 2133 slidesPrepended = loopedSlides - activeSlideIndex; 2134 for (let i = 0; i < loopedSlides - activeSlideIndex; i += 1) { 2135 const index = i - Math.floor(i / slides.length) * slides.length; 2136 prependSlidesIndexes.push(slides.length - index - 1); 2137 } 2138 } else if (activeSlideIndex /* + slidesPerView */ > swiper.slides.length - loopedSlides * 2) { 2139 slidesAppended = activeSlideIndex - (swiper.slides.length - loopedSlides * 2); 2140 for (let i = 0; i < slidesAppended; i += 1) { 2141 const index = i - Math.floor(i / slides.length) * slides.length; 2142 appendSlidesIndexes.push(index); 2143 } 2144 } 2145 if (isPrev) { 2146 prependSlidesIndexes.forEach(index => { 2147 slidesEl.prepend(swiper.slides[index]); 2148 }); 2149 } 2150 if (isNext) { 2151 appendSlidesIndexes.forEach(index => { 2152 slidesEl.append(swiper.slides[index]); 2153 }); 2154 } 2155 swiper.recalcSlides(); 2156 if (params.watchSlidesProgress) { 2157 swiper.updateSlidesOffset(); 2158 } 2159 if (slideTo) { 2160 if (prependSlidesIndexes.length > 0 && isPrev) { 2161 if (typeof slideRealIndex === 'undefined') { 2162 const currentSlideTranslate = swiper.slidesGrid[activeIndex]; 2163 const newSlideTranslate = swiper.slidesGrid[activeIndex + slidesPrepended]; 2164 const diff = newSlideTranslate - currentSlideTranslate; 2165 if (byMousewheel) { 2166 swiper.setTranslate(swiper.translate - diff); 2167 } else { 2168 swiper.slideTo(activeIndex + slidesPrepended, 0, false, true); 2169 if (setTranslate) { 2170 swiper.touches[swiper.isHorizontal() ? 'startX' : 'startY'] += diff; 2171 } 2172 } 2173 } else { 2174 if (setTranslate) { 2175 swiper.slideToLoop(slideRealIndex, 0, false, true); 2176 } 2177 } 2178 } else if (appendSlidesIndexes.length > 0 && isNext) { 2179 if (typeof slideRealIndex === 'undefined') { 2180 const currentSlideTranslate = swiper.slidesGrid[activeIndex]; 2181 const newSlideTranslate = swiper.slidesGrid[activeIndex - slidesAppended]; 2182 const diff = newSlideTranslate - currentSlideTranslate; 2183 if (byMousewheel) { 2184 swiper.setTranslate(swiper.translate - diff); 2185 } else { 2186 swiper.slideTo(activeIndex - slidesAppended, 0, false, true); 2187 if (setTranslate) { 2188 swiper.touches[swiper.isHorizontal() ? 'startX' : 'startY'] += diff; 2189 } 2190 } 2191 } else { 2192 swiper.slideToLoop(slideRealIndex, 0, false, true); 2193 } 2194 } 2195 } 2196 swiper.allowSlidePrev = allowSlidePrev; 2197 swiper.allowSlideNext = allowSlideNext; 2198 if (swiper.controller && swiper.controller.control && !byController) { 2199 const loopParams = { 2200 slideRealIndex, 2201 slideTo: false, 2202 direction, 2203 setTranslate, 2204 activeSlideIndex, 2205 byController: true 2206 }; 2207 if (Array.isArray(swiper.controller.control)) { 2208 swiper.controller.control.forEach(c => { 2209 if (c.params.loop) c.loopFix(loopParams); 2210 }); 2211 } else if (swiper.controller.control instanceof swiper.constructor && swiper.controller.control.params.loop) { 2212 swiper.controller.control.loopFix(loopParams); 2213 } 2214 } 2215 swiper.emit('loopFix'); 2216 } 2217 2218 function loopDestroy() { 2219 const swiper = this; 2220 const { 2221 slides, 2222 params, 2223 slidesEl 2224 } = swiper; 2225 if (!params.loop || swiper.virtual && swiper.params.virtual.enabled) return; 2226 swiper.recalcSlides(); 2227 const newSlidesOrder = []; 2228 slides.forEach(slideEl => { 2229 const index = typeof slideEl.swiperSlideIndex === 'undefined' ? slideEl.getAttribute('data-swiper-slide-index') * 1 : slideEl.swiperSlideIndex; 2230 newSlidesOrder[index] = slideEl; 2231 }); 2232 slides.forEach(slideEl => { 2233 slideEl.removeAttribute('data-swiper-slide-index'); 2234 }); 2235 newSlidesOrder.forEach(slideEl => { 2236 slidesEl.append(slideEl); 2237 }); 2238 swiper.recalcSlides(); 2239 swiper.slideTo(swiper.realIndex, 0); 2240 } 2241 2242 var loop = { 2243 loopCreate, 2244 loopFix, 2245 loopDestroy 2246 }; 2247 2248 function setGrabCursor(moving) { 2249 const swiper = this; 2250 if (!swiper.params.simulateTouch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) return; 2251 const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl; 2252 el.style.cursor = 'move'; 2253 el.style.cursor = moving ? 'grabbing' : 'grab'; 2254 } 2255 2256 function unsetGrabCursor() { 2257 const swiper = this; 2258 if (swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) { 2259 return; 2260 } 2261 swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = ''; 2262 } 2263 2264 var grabCursor = { 2265 setGrabCursor, 2266 unsetGrabCursor 2267 }; 2268 2269 // Modified from https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd 2270 function closestElement(selector, base) { 2271 if (base === void 0) { 2272 base = this; 2273 } 2274 function __closestFrom(el) { 2275 if (!el || el === getDocument() || el === getWindow()) return null; 2276 if (el.assignedSlot) el = el.assignedSlot; 2277 const found = el.closest(selector); 2278 if (!found && !el.getRootNode) { 2279 return null; 2280 } 2281 return found || __closestFrom(el.getRootNode().host); 2282 } 2283 return __closestFrom(base); 2284 } 2285 function onTouchStart(event) { 2286 const swiper = this; 2287 const document = getDocument(); 2288 const window = getWindow(); 2289 const data = swiper.touchEventsData; 2290 data.evCache.push(event); 2291 const { 2292 params, 2293 touches, 2294 enabled 2295 } = swiper; 2296 if (!enabled) return; 2297 if (!params.simulateTouch && event.pointerType === 'mouse') return; 2298 if (swiper.animating && params.preventInteractionOnTransition) { 2299 return; 2300 } 2301 if (!swiper.animating && params.cssMode && params.loop) { 2302 swiper.loopFix(); 2303 } 2304 let e = event; 2305 if (e.originalEvent) e = e.originalEvent; 2306 let targetEl = e.target; 2307 if (params.touchEventsTarget === 'wrapper') { 2308 if (!swiper.wrapperEl.contains(targetEl)) return; 2309 } 2310 if ('which' in e && e.which === 3) return; 2311 if ('button' in e && e.button > 0) return; 2312 if (data.isTouched && data.isMoved) return; 2313 2314 // change target el for shadow root component 2315 const swipingClassHasValue = !!params.noSwipingClass && params.noSwipingClass !== ''; 2316 // eslint-disable-next-line 2317 const eventPath = event.composedPath ? event.composedPath() : event.path; 2318 if (swipingClassHasValue && e.target && e.target.shadowRoot && eventPath) { 2319 targetEl = eventPath[0]; 2320 } 2321 const noSwipingSelector = params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`; 2322 const isTargetShadow = !!(e.target && e.target.shadowRoot); 2323 2324 // use closestElement for shadow root element to get the actual closest for nested shadow root element 2325 if (params.noSwiping && (isTargetShadow ? closestElement(noSwipingSelector, targetEl) : targetEl.closest(noSwipingSelector))) { 2326 swiper.allowClick = true; 2327 return; 2328 } 2329 if (params.swipeHandler) { 2330 if (!targetEl.closest(params.swipeHandler)) return; 2331 } 2332 touches.currentX = e.pageX; 2333 touches.currentY = e.pageY; 2334 const startX = touches.currentX; 2335 const startY = touches.currentY; 2336 2337 // Do NOT start if iOS edge swipe is detected. Otherwise iOS app cannot swipe-to-go-back anymore 2338 2339 const edgeSwipeDetection = params.edgeSwipeDetection || params.iOSEdgeSwipeDetection; 2340 const edgeSwipeThreshold = params.edgeSwipeThreshold || params.iOSEdgeSwipeThreshold; 2341 if (edgeSwipeDetection && (startX <= edgeSwipeThreshold || startX >= window.innerWidth - edgeSwipeThreshold)) { 2342 if (edgeSwipeDetection === 'prevent') { 2343 event.preventDefault(); 2344 } else { 2345 return; 2346 } 2347 } 2348 Object.assign(data, { 2349 isTouched: true, 2350 isMoved: false, 2351 allowTouchCallbacks: true, 2352 isScrolling: undefined, 2353 startMoving: undefined 2354 }); 2355 touches.startX = startX; 2356 touches.startY = startY; 2357 data.touchStartTime = now(); 2358 swiper.allowClick = true; 2359 swiper.updateSize(); 2360 swiper.swipeDirection = undefined; 2361 if (params.threshold > 0) data.allowThresholdMove = false; 2362 let preventDefault = true; 2363 if (targetEl.matches(data.focusableElements)) { 2364 preventDefault = false; 2365 if (targetEl.nodeName === 'SELECT') { 2366 data.isTouched = false; 2367 } 2368 } 2369 if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== targetEl) { 2370 document.activeElement.blur(); 2371 } 2372 const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault; 2373 if ((params.touchStartForcePreventDefault || shouldPreventDefault) && !targetEl.isContentEditable) { 2374 e.preventDefault(); 2375 } 2376 if (swiper.params.freeMode && swiper.params.freeMode.enabled && swiper.freeMode && swiper.animating && !params.cssMode) { 2377 swiper.freeMode.onTouchStart(); 2378 } 2379 swiper.emit('touchStart', e); 2380 } 2381 2382 function onTouchMove(event) { 2383 const document = getDocument(); 2384 const swiper = this; 2385 const data = swiper.touchEventsData; 2386 const { 2387 params, 2388 touches, 2389 rtlTranslate: rtl, 2390 enabled 2391 } = swiper; 2392 if (!enabled) return; 2393 if (!params.simulateTouch && event.pointerType === 'mouse') return; 2394 let e = event; 2395 if (e.originalEvent) e = e.originalEvent; 2396 if (!data.isTouched) { 2397 if (data.startMoving && data.isScrolling) { 2398 swiper.emit('touchMoveOpposite', e); 2399 } 2400 return; 2401 } 2402 const pointerIndex = data.evCache.findIndex(cachedEv => cachedEv.pointerId === e.pointerId); 2403 if (pointerIndex >= 0) data.evCache[pointerIndex] = e; 2404 const targetTouch = data.evCache.length > 1 ? data.evCache[0] : e; 2405 const pageX = targetTouch.pageX; 2406 const pageY = targetTouch.pageY; 2407 if (e.preventedByNestedSwiper) { 2408 touches.startX = pageX; 2409 touches.startY = pageY; 2410 return; 2411 } 2412 if (!swiper.allowTouchMove) { 2413 if (!e.target.matches(data.focusableElements)) { 2414 swiper.allowClick = false; 2415 } 2416 if (data.isTouched) { 2417 Object.assign(touches, { 2418 startX: pageX, 2419 startY: pageY, 2420 prevX: swiper.touches.currentX, 2421 prevY: swiper.touches.currentY, 2422 currentX: pageX, 2423 currentY: pageY 2424 }); 2425 data.touchStartTime = now(); 2426 } 2427 return; 2428 } 2429 if (params.touchReleaseOnEdges && !params.loop) { 2430 if (swiper.isVertical()) { 2431 // Vertical 2432 if (pageY < touches.startY && swiper.translate <= swiper.maxTranslate() || pageY > touches.startY && swiper.translate >= swiper.minTranslate()) { 2433 data.isTouched = false; 2434 data.isMoved = false; 2435 return; 2436 } 2437 } else if (pageX < touches.startX && swiper.translate <= swiper.maxTranslate() || pageX > touches.startX && swiper.translate >= swiper.minTranslate()) { 2438 return; 2439 } 2440 } 2441 if (document.activeElement) { 2442 if (e.target === document.activeElement && e.target.matches(data.focusableElements)) { 2443 data.isMoved = true; 2444 swiper.allowClick = false; 2445 return; 2446 } 2447 } 2448 if (data.allowTouchCallbacks) { 2449 swiper.emit('touchMove', e); 2450 } 2451 if (e.targetTouches && e.targetTouches.length > 1) return; 2452 touches.currentX = pageX; 2453 touches.currentY = pageY; 2454 const diffX = touches.currentX - touches.startX; 2455 const diffY = touches.currentY - touches.startY; 2456 if (swiper.params.threshold && Math.sqrt(diffX ** 2 + diffY ** 2) < swiper.params.threshold) return; 2457 if (typeof data.isScrolling === 'undefined') { 2458 let touchAngle; 2459 if (swiper.isHorizontal() && touches.currentY === touches.startY || swiper.isVertical() && touches.currentX === touches.startX) { 2460 data.isScrolling = false; 2461 } else { 2462 // eslint-disable-next-line 2463 if (diffX * diffX + diffY * diffY >= 25) { 2464 touchAngle = Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180 / Math.PI; 2465 data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : 90 - touchAngle > params.touchAngle; 2466 } 2467 } 2468 } 2469 if (data.isScrolling) { 2470 swiper.emit('touchMoveOpposite', e); 2471 } 2472 if (typeof data.startMoving === 'undefined') { 2473 if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) { 2474 data.startMoving = true; 2475 } 2476 } 2477 if (data.isScrolling || swiper.zoom && swiper.params.zoom && swiper.params.zoom.enabled && data.evCache.length > 1) { 2478 data.isTouched = false; 2479 return; 2480 } 2481 if (!data.startMoving) { 2482 return; 2483 } 2484 swiper.allowClick = false; 2485 if (!params.cssMode && e.cancelable) { 2486 e.preventDefault(); 2487 } 2488 if (params.touchMoveStopPropagation && !params.nested) { 2489 e.stopPropagation(); 2490 } 2491 let diff = swiper.isHorizontal() ? diffX : diffY; 2492 let touchesDiff = swiper.isHorizontal() ? touches.currentX - touches.previousX : touches.currentY - touches.previousY; 2493 if (params.oneWayMovement) { 2494 diff = Math.abs(diff) * (rtl ? 1 : -1); 2495 touchesDiff = Math.abs(touchesDiff) * (rtl ? 1 : -1); 2496 } 2497 touches.diff = diff; 2498 diff *= params.touchRatio; 2499 if (rtl) { 2500 diff = -diff; 2501 touchesDiff = -touchesDiff; 2502 } 2503 const prevTouchesDirection = swiper.touchesDirection; 2504 swiper.swipeDirection = diff > 0 ? 'prev' : 'next'; 2505 swiper.touchesDirection = touchesDiff > 0 ? 'prev' : 'next'; 2506 const isLoop = swiper.params.loop && !params.cssMode; 2507 if (!data.isMoved) { 2508 if (isLoop) { 2509 swiper.loopFix({ 2510 direction: swiper.swipeDirection 2511 }); 2512 } 2513 data.startTranslate = swiper.getTranslate(); 2514 swiper.setTransition(0); 2515 if (swiper.animating) { 2516 const evt = new window.CustomEvent('transitionend', { 2517 bubbles: true, 2518 cancelable: true 2519 }); 2520 swiper.wrapperEl.dispatchEvent(evt); 2521 } 2522 data.allowMomentumBounce = false; 2523 // Grab Cursor 2524 if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) { 2525 swiper.setGrabCursor(true); 2526 } 2527 swiper.emit('sliderFirstMove', e); 2528 } 2529 let loopFixed; 2530 if (data.isMoved && prevTouchesDirection !== swiper.touchesDirection && isLoop && Math.abs(diff) >= 1) { 2531 // need another loop fix 2532 swiper.loopFix({ 2533 direction: swiper.swipeDirection, 2534 setTranslate: true 2535 }); 2536 loopFixed = true; 2537 } 2538 swiper.emit('sliderMove', e); 2539 data.isMoved = true; 2540 data.currentTranslate = diff + data.startTranslate; 2541 let disableParentSwiper = true; 2542 let resistanceRatio = params.resistanceRatio; 2543 if (params.touchReleaseOnEdges) { 2544 resistanceRatio = 0; 2545 } 2546 if (diff > 0) { 2547 if (isLoop && !loopFixed && data.currentTranslate > (params.centeredSlides ? swiper.minTranslate() - swiper.size / 2 : swiper.minTranslate())) { 2548 swiper.loopFix({ 2549 direction: 'prev', 2550 setTranslate: true, 2551 activeSlideIndex: 0 2552 }); 2553 } 2554 if (data.currentTranslate > swiper.minTranslate()) { 2555 disableParentSwiper = false; 2556 if (params.resistance) { 2557 data.currentTranslate = swiper.minTranslate() - 1 + (-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio; 2558 } 2559 } 2560 } else if (diff < 0) { 2561 if (isLoop && !loopFixed && data.currentTranslate < (params.centeredSlides ? swiper.maxTranslate() + swiper.size / 2 : swiper.maxTranslate())) { 2562 swiper.loopFix({ 2563 direction: 'next', 2564 setTranslate: true, 2565 activeSlideIndex: swiper.slides.length - (params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10))) 2566 }); 2567 } 2568 if (data.currentTranslate < swiper.maxTranslate()) { 2569 disableParentSwiper = false; 2570 if (params.resistance) { 2571 data.currentTranslate = swiper.maxTranslate() + 1 - (swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio; 2572 } 2573 } 2574 } 2575 if (disableParentSwiper) { 2576 e.preventedByNestedSwiper = true; 2577 } 2578 2579 // Directions locks 2580 if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) { 2581 data.currentTranslate = data.startTranslate; 2582 } 2583 if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) { 2584 data.currentTranslate = data.startTranslate; 2585 } 2586 if (!swiper.allowSlidePrev && !swiper.allowSlideNext) { 2587 data.currentTranslate = data.startTranslate; 2588 } 2589 2590 // Threshold 2591 if (params.threshold > 0) { 2592 if (Math.abs(diff) > params.threshold || data.allowThresholdMove) { 2593 if (!data.allowThresholdMove) { 2594 data.allowThresholdMove = true; 2595 touches.startX = touches.currentX; 2596 touches.startY = touches.currentY; 2597 data.currentTranslate = data.startTranslate; 2598 touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY; 2599 return; 2600 } 2601 } else { 2602 data.currentTranslate = data.startTranslate; 2603 return; 2604 } 2605 } 2606 if (!params.followFinger || params.cssMode) return; 2607 2608 // Update active index in free mode 2609 if (params.freeMode && params.freeMode.enabled && swiper.freeMode || params.watchSlidesProgress) { 2610 swiper.updateActiveIndex(); 2611 swiper.updateSlidesClasses(); 2612 } 2613 if (swiper.params.freeMode && params.freeMode.enabled && swiper.freeMode) { 2614 swiper.freeMode.onTouchMove(); 2615 } 2616 // Update progress 2617 swiper.updateProgress(data.currentTranslate); 2618 // Update translate 2619 swiper.setTranslate(data.currentTranslate); 2620 } 2621 2622 function onTouchEnd(event) { 2623 const swiper = this; 2624 const data = swiper.touchEventsData; 2625 const pointerIndex = data.evCache.findIndex(cachedEv => cachedEv.pointerId === event.pointerId); 2626 if (pointerIndex >= 0) { 2627 data.evCache.splice(pointerIndex, 1); 2628 } 2629 if (['pointercancel', 'pointerout', 'pointerleave'].includes(event.type)) return; 2630 const { 2631 params, 2632 touches, 2633 rtlTranslate: rtl, 2634 slidesGrid, 2635 enabled 2636 } = swiper; 2637 if (!enabled) return; 2638 if (!params.simulateTouch && event.pointerType === 'mouse') return; 2639 let e = event; 2640 if (e.originalEvent) e = e.originalEvent; 2641 if (data.allowTouchCallbacks) { 2642 swiper.emit('touchEnd', e); 2643 } 2644 data.allowTouchCallbacks = false; 2645 if (!data.isTouched) { 2646 if (data.isMoved && params.grabCursor) { 2647 swiper.setGrabCursor(false); 2648 } 2649 data.isMoved = false; 2650 data.startMoving = false; 2651 return; 2652 } 2653 // Return Grab Cursor 2654 if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) { 2655 swiper.setGrabCursor(false); 2656 } 2657 2658 // Time diff 2659 const touchEndTime = now(); 2660 const timeDiff = touchEndTime - data.touchStartTime; 2661 2662 // Tap, doubleTap, Click 2663 if (swiper.allowClick) { 2664 const pathTree = e.path || e.composedPath && e.composedPath(); 2665 swiper.updateClickedSlide(pathTree && pathTree[0] || e.target); 2666 swiper.emit('tap click', e); 2667 if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) { 2668 swiper.emit('doubleTap doubleClick', e); 2669 } 2670 } 2671 data.lastClickTime = now(); 2672 nextTick(() => { 2673 if (!swiper.destroyed) swiper.allowClick = true; 2674 }); 2675 if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 || data.currentTranslate === data.startTranslate) { 2676 data.isTouched = false;
vendor: 3,671 bytes, lines 2677-2775
2677 data.isMoved = false; 2678 data.startMoving = false; 2679 return; 2680 } 2681 data.isTouched = false; 2682 data.isMoved = false; 2683 data.startMoving = false; 2684 let currentPos; 2685 if (params.followFinger) { 2686 currentPos = rtl ? swiper.translate : -swiper.translate; 2687 } else { 2688 currentPos = -data.currentTranslate; 2689 } 2690 if (params.cssMode) { 2691 return; 2692 } 2693 if (swiper.params.freeMode && params.freeMode.enabled) { 2694 swiper.freeMode.onTouchEnd({ 2695 currentPos 2696 }); 2697 return; 2698 } 2699 2700 // Find current slide 2701 let stopIndex = 0; 2702 let groupSize = swiper.slidesSizesGrid[0]; 2703 for (let i = 0; i < slidesGrid.length; i += i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup) { 2704 const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup; 2705 if (typeof slidesGrid[i + increment] !== 'undefined') { 2706 if (currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) { 2707 stopIndex = i; 2708 groupSize = slidesGrid[i + increment] - slidesGrid[i]; 2709 } 2710 } else if (currentPos >= slidesGrid[i]) { 2711 stopIndex = i; 2712 groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2]; 2713 } 2714 } 2715 let rewindFirstIndex = null; 2716 let rewindLastIndex = null; 2717 if (params.rewind) { 2718 if (swiper.isBeginning) { 2719 rewindLastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1; 2720 } else if (swiper.isEnd) { 2721 rewindFirstIndex = 0; 2722 } 2723 } 2724 // Find current slide size 2725 const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize; 2726 const increment = stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup; 2727 if (timeDiff > params.longSwipesMs) { 2728 // Long touches 2729 if (!params.longSwipes) { 2730 swiper.slideTo(swiper.activeIndex); 2731 return; 2732 } 2733 if (swiper.swipeDirection === 'next') { 2734 if (ratio >= params.longSwipesRatio) swiper.slideTo(params.rewind && swiper.isEnd ? rewindFirstIndex : stopIndex + increment);else swiper.slideTo(stopIndex); 2735 } 2736 if (swiper.swipeDirection === 'prev') { 2737 if (ratio > 1 - params.longSwipesRatio) { 2738 swiper.slideTo(stopIndex + increment); 2739 } else if (rewindLastIndex !== null && ratio < 0 && Math.abs(ratio) > params.longSwipesRatio) { 2740 swiper.slideTo(rewindLastIndex); 2741 } else { 2742 swiper.slideTo(stopIndex); 2743 } 2744 } 2745 } else { 2746 // Short swipes 2747 if (!params.shortSwipes) { 2748 swiper.slideTo(swiper.activeIndex); 2749 return; 2750 } 2751 const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl); 2752 if (!isNavButtonTarget) { 2753 if (swiper.swipeDirection === 'next') { 2754 swiper.slideTo(rewindFirstIndex !== null ? rewindFirstIndex : stopIndex + increment); 2755 } 2756 if (swiper.swipeDirection === 'prev') { 2757 swiper.slideTo(rewindLastIndex !== null ? rewindLastIndex : stopIndex); 2758 } 2759 } else if (e.target === swiper.navigation.nextEl) { 2760 swiper.slideTo(stopIndex + increment); 2761 } else { 2762 swiper.slideTo(stopIndex); 2763 } 2764 } 2765 } 2766 2767 let timeout; 2768 function onResize() { 2769 const swiper = this; 2770 const { 2771 params, 2772 el 2773 } = swiper; 2774 if (el && el.offsetWidth === 0) return; 2775
vendor: 12,463 bytes, lines 2776-3154
2776 // Breakpoints 2777 if (params.breakpoints) { 2778 swiper.setBreakpoint(); 2779 } 2780 2781 // Save locks 2782 const { 2783 allowSlideNext, 2784 allowSlidePrev, 2785 snapGrid 2786 } = swiper; 2787 const isVirtual = swiper.virtual && swiper.params.virtual.enabled; 2788 2789 // Disable locks on resize 2790 swiper.allowSlideNext = true; 2791 swiper.allowSlidePrev = true; 2792 swiper.updateSize(); 2793 swiper.updateSlides(); 2794 swiper.updateSlidesClasses(); 2795 const isVirtualLoop = isVirtual && params.loop; 2796 if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.isBeginning && !swiper.params.centeredSlides && !isVirtualLoop) { 2797 swiper.slideTo(swiper.slides.length - 1, 0, false, true); 2798 } else { 2799 if (swiper.params.loop && !isVirtual) { 2800 swiper.slideToLoop(swiper.realIndex, 0, false, true); 2801 } else { 2802 swiper.slideTo(swiper.activeIndex, 0, false, true); 2803 } 2804 } 2805 if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) { 2806 clearTimeout(timeout); 2807 timeout = setTimeout(() => { 2808 swiper.autoplay.resume(); 2809 }, 500); 2810 } 2811 // Return locks after resize 2812 swiper.allowSlidePrev = allowSlidePrev; 2813 swiper.allowSlideNext = allowSlideNext; 2814 if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) { 2815 swiper.checkOverflow(); 2816 } 2817 } 2818 2819 function onClick(e) { 2820 const swiper = this; 2821 if (!swiper.enabled) return; 2822 if (!swiper.allowClick) { 2823 if (swiper.params.preventClicks) e.preventDefault(); 2824 if (swiper.params.preventClicksPropagation && swiper.animating) { 2825 e.stopPropagation(); 2826 e.stopImmediatePropagation(); 2827 } 2828 } 2829 } 2830 2831 function onScroll() { 2832 const swiper = this; 2833 const { 2834 wrapperEl, 2835 rtlTranslate, 2836 enabled 2837 } = swiper; 2838 if (!enabled) return; 2839 swiper.previousTranslate = swiper.translate; 2840 if (swiper.isHorizontal()) { 2841 swiper.translate = -wrapperEl.scrollLeft; 2842 } else { 2843 swiper.translate = -wrapperEl.scrollTop; 2844 } 2845 // eslint-disable-next-line 2846 if (swiper.translate === 0) swiper.translate = 0; 2847 swiper.updateActiveIndex(); 2848 swiper.updateSlidesClasses(); 2849 let newProgress; 2850 const translatesDiff = swiper.maxTranslate() - swiper.minTranslate(); 2851 if (translatesDiff === 0) { 2852 newProgress = 0; 2853 } else { 2854 newProgress = (swiper.translate - swiper.minTranslate()) / translatesDiff; 2855 } 2856 if (newProgress !== swiper.progress) { 2857 swiper.updateProgress(rtlTranslate ? -swiper.translate : swiper.translate); 2858 } 2859 swiper.emit('setTranslate', swiper.translate, false); 2860 } 2861 2862 const processLazyPreloader = (swiper, imageEl) => { 2863 if (!swiper || swiper.destroyed || !swiper.params) return; 2864 const slideSelector = () => swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`; 2865 const slideEl = imageEl.closest(slideSelector()); 2866 if (slideEl) { 2867 const lazyEl = slideEl.querySelector(`.${swiper.params.lazyPreloaderClass}`); 2868 if (lazyEl) lazyEl.remove(); 2869 } 2870 }; 2871 2872 function onLoad(e) { 2873 const swiper = this; 2874 processLazyPreloader(swiper, e.target); 2875 swiper.update(); 2876 } 2877 2878 let dummyEventAttached = false; 2879 function dummyEventListener() {} 2880 const events = (swiper, method) => { 2881 const document = getDocument(); 2882 const { 2883 params, 2884 el, 2885 wrapperEl, 2886 device 2887 } = swiper; 2888 const capture = !!params.nested; 2889 const domMethod = method === 'on' ? 'addEventListener' : 'removeEventListener'; 2890 const swiperMethod = method; 2891 2892 // Touch Events 2893 el[domMethod]('pointerdown', swiper.onTouchStart, { 2894 passive: false 2895 }); 2896 document[domMethod]('pointermove', swiper.onTouchMove, { 2897 passive: false, 2898 capture 2899 }); 2900 document[domMethod]('pointerup', swiper.onTouchEnd, { 2901 passive: true 2902 }); 2903 document[domMethod]('pointercancel', swiper.onTouchEnd, { 2904 passive: true 2905 }); 2906 document[domMethod]('pointerout', swiper.onTouchEnd, { 2907 passive: true 2908 }); 2909 document[domMethod]('pointerleave', swiper.onTouchEnd, { 2910 passive: true 2911 }); 2912 2913 // Prevent Links Clicks 2914 if (params.preventClicks || params.preventClicksPropagation) { 2915 el[domMethod]('click', swiper.onClick, true); 2916 } 2917 if (params.cssMode) { 2918 wrapperEl[domMethod]('scroll', swiper.onScroll); 2919 } 2920 2921 // Resize handler 2922 if (params.updateOnWindowResize) { 2923 swiper[swiperMethod](device.ios || device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate', onResize, true); 2924 } else { 2925 swiper[swiperMethod]('observerUpdate', onResize, true); 2926 } 2927 2928 // Images loader 2929 el[domMethod]('load', swiper.onLoad, { 2930 capture: true 2931 }); 2932 }; 2933 function attachEvents() { 2934 const swiper = this; 2935 const document = getDocument(); 2936 const { 2937 params 2938 } = swiper; 2939 swiper.onTouchStart = onTouchStart.bind(swiper); 2940 swiper.onTouchMove = onTouchMove.bind(swiper); 2941 swiper.onTouchEnd = onTouchEnd.bind(swiper); 2942 if (params.cssMode) { 2943 swiper.onScroll = onScroll.bind(swiper); 2944 } 2945 swiper.onClick = onClick.bind(swiper); 2946 swiper.onLoad = onLoad.bind(swiper); 2947 if (!dummyEventAttached) { 2948 document.addEventListener('touchstart', dummyEventListener); 2949 dummyEventAttached = true; 2950 } 2951 events(swiper, 'on'); 2952 } 2953 function detachEvents() { 2954 const swiper = this; 2955 events(swiper, 'off'); 2956 } 2957 var events$1 = { 2958 attachEvents, 2959 detachEvents 2960 }; 2961 2962 const isGridEnabled = (swiper, params) => { 2963 return swiper.grid && params.grid && params.grid.rows > 1; 2964 }; 2965 function setBreakpoint() { 2966 const swiper = this; 2967 const { 2968 realIndex, 2969 initialized, 2970 params, 2971 el 2972 } = swiper; 2973 const breakpoints = params.breakpoints; 2974 if (!breakpoints || breakpoints && Object.keys(breakpoints).length === 0) return; 2975 2976 // Get breakpoint for window width and update parameters 2977 const breakpoint = swiper.getBreakpoint(breakpoints, swiper.params.breakpointsBase, swiper.el); 2978 if (!breakpoint || swiper.currentBreakpoint === breakpoint) return; 2979 const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints[breakpoint] : undefined; 2980 const breakpointParams = breakpointOnlyParams || swiper.originalParams; 2981 const wasMultiRow = isGridEnabled(swiper, params); 2982 const isMultiRow = isGridEnabled(swiper, breakpointParams); 2983 const wasEnabled = params.enabled; 2984 if (wasMultiRow && !isMultiRow) { 2985 el.classList.remove(`${params.containerModifierClass}grid`, `${params.containerModifierClass}grid-column`); 2986 swiper.emitContainerClasses(); 2987 } else if (!wasMultiRow && isMultiRow) { 2988 el.classList.add(`${params.containerModifierClass}grid`); 2989 if (breakpointParams.grid.fill && breakpointParams.grid.fill === 'column' || !breakpointParams.grid.fill && params.grid.fill === 'column') { 2990 el.classList.add(`${params.containerModifierClass}grid-column`); 2991 } 2992 swiper.emitContainerClasses(); 2993 } 2994 2995 // Toggle navigation, pagination, scrollbar 2996 ['navigation', 'pagination', 'scrollbar'].forEach(prop => { 2997 const wasModuleEnabled = params[prop] && params[prop].enabled; 2998 const isModuleEnabled = breakpointParams[prop] && breakpointParams[prop].enabled; 2999 if (wasModuleEnabled && !isModuleEnabled) { 3000 swiper[prop].disable(); 3001 } 3002 if (!wasModuleEnabled && isModuleEnabled) { 3003 swiper[prop].enable(); 3004 } 3005 }); 3006 const directionChanged = breakpointParams.direction && breakpointParams.direction !== params.direction; 3007 const needsReLoop = params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged); 3008 if (directionChanged && initialized) { 3009 swiper.changeDirection(); 3010 } 3011 extend(swiper.params, breakpointParams); 3012 const isEnabled = swiper.params.enabled; 3013 Object.assign(swiper, { 3014 allowTouchMove: swiper.params.allowTouchMove, 3015 allowSlideNext: swiper.params.allowSlideNext, 3016 allowSlidePrev: swiper.params.allowSlidePrev 3017 }); 3018 if (wasEnabled && !isEnabled) { 3019 swiper.disable(); 3020 } else if (!wasEnabled && isEnabled) { 3021 swiper.enable(); 3022 } 3023 swiper.currentBreakpoint = breakpoint; 3024 swiper.emit('_beforeBreakpoint', breakpointParams); 3025 if (needsReLoop && initialized) { 3026 swiper.loopDestroy(); 3027 swiper.loopCreate(realIndex); 3028 swiper.updateSlides(); 3029 } 3030 swiper.emit('breakpoint', breakpointParams); 3031 } 3032 3033 function getBreakpoint(breakpoints, base, containerEl) { 3034 if (base === void 0) { 3035 base = 'window'; 3036 } 3037 if (!breakpoints || base === 'container' && !containerEl) return undefined; 3038 let breakpoint = false; 3039 const window = getWindow(); 3040 const currentHeight = base === 'window' ? window.innerHeight : containerEl.clientHeight; 3041 const points = Object.keys(breakpoints).map(point => { 3042 if (typeof point === 'string' && point.indexOf('@') === 0) { 3043 const minRatio = parseFloat(point.substr(1)); 3044 const value = currentHeight * minRatio; 3045 return { 3046 value, 3047 point 3048 }; 3049 } 3050 return { 3051 value: point, 3052 point 3053 }; 3054 }); 3055 points.sort((a, b) => parseInt(a.value, 10) - parseInt(b.value, 10)); 3056 for (let i = 0; i < points.length; i += 1) { 3057 const { 3058 point, 3059 value 3060 } = points[i]; 3061 if (base === 'window') { 3062 if (window.matchMedia(`(min-width: ${value}px)`).matches) { 3063 breakpoint = point; 3064 } 3065 } else if (value <= containerEl.clientWidth) { 3066 breakpoint = point; 3067 } 3068 } 3069 return breakpoint || 'max'; 3070 } 3071 3072 var breakpoints = { 3073 setBreakpoint, 3074 getBreakpoint 3075 }; 3076 3077 function prepareClasses(entries, prefix) { 3078 const resultClasses = []; 3079 entries.forEach(item => { 3080 if (typeof item === 'object') { 3081 Object.keys(item).forEach(classNames => { 3082 if (item[classNames]) { 3083 resultClasses.push(prefix + classNames); 3084 } 3085 }); 3086 } else if (typeof item === 'string') { 3087 resultClasses.push(prefix + item); 3088 } 3089 }); 3090 return resultClasses; 3091 } 3092 function addClasses() { 3093 const swiper = this; 3094 const { 3095 classNames, 3096 params, 3097 rtl, 3098 el, 3099 device 3100 } = swiper; 3101 // prettier-ignore 3102 const suffixes = prepareClasses(['initialized', params.direction, { 3103 'free-mode': swiper.params.freeMode && params.freeMode.enabled 3104 }, { 3105 'autoheight': params.autoHeight 3106 }, { 3107 'rtl': rtl 3108 }, { 3109 'grid': params.grid && params.grid.rows > 1 3110 }, { 3111 'grid-column': params.grid && params.grid.rows > 1 && params.grid.fill === 'column' 3112 }, { 3113 'android': device.android 3114 }, { 3115 'ios': device.ios 3116 }, { 3117 'css-mode': params.cssMode 3118 }, { 3119 'centered': params.cssMode && params.centeredSlides 3120 }, { 3121 'watch-progress': params.watchSlidesProgress 3122 }], params.containerModifierClass); 3123 classNames.push(...suffixes); 3124 el.classList.add(...classNames); 3125 swiper.emitContainerClasses(); 3126 } 3127 3128 function removeClasses() { 3129 const swiper = this; 3130 const { 3131 el, 3132 classNames 3133 } = swiper; 3134 el.classList.remove(...classNames); 3135 swiper.emitContainerClasses(); 3136 } 3137 3138 var classes = { 3139 addClasses, 3140 removeClasses 3141 }; 3142 3143 function checkOverflow() { 3144 const swiper = this; 3145 const { 3146 isLocked: wasLocked, 3147 params 3148 } = swiper; 3149 const { 3150 slidesOffsetBefore 3151 } = params; 3152 if (slidesOffsetBefore) { 3153 const lastSlideIndex = swiper.slides.length - 1; 3154 const lastSlideRightEdge = swiper.slidesGrid[lastSlideIndex] + swiper.slidesSizesGrid[lastSlideIndex] + slidesOffsetBefore * 2;
vendor: 1,588 bytes, lines 3155-3210
3155 swiper.isLocked = swiper.size > lastSlideRightEdge; 3156 } else { 3157 swiper.isLocked = swiper.snapGrid.length === 1; 3158 } 3159 if (params.allowSlideNext === true) { 3160 swiper.allowSlideNext = !swiper.isLocked; 3161 } 3162 if (params.allowSlidePrev === true) { 3163 swiper.allowSlidePrev = !swiper.isLocked; 3164 } 3165 if (wasLocked && wasLocked !== swiper.isLocked) { 3166 swiper.isEnd = false; 3167 } 3168 if (wasLocked !== swiper.isLocked) { 3169 swiper.emit(swiper.isLocked ? 'lock' : 'unlock'); 3170 } 3171 } 3172 var checkOverflow$1 = { 3173 checkOverflow 3174 }; 3175 3176 var defaults = { 3177 init: true, 3178 direction: 'horizontal', 3179 oneWayMovement: false, 3180 touchEventsTarget: 'wrapper', 3181 initialSlide: 0, 3182 speed: 300, 3183 cssMode: false, 3184 updateOnWindowResize: true, 3185 resizeObserver: true, 3186 nested: false, 3187 createElements: false, 3188 enabled: true, 3189 focusableElements: 'input, select, option, textarea, button, video, label', 3190 // Overrides 3191 width: null, 3192 height: null, 3193 // 3194 preventInteractionOnTransition: false, 3195 // ssr 3196 userAgent: null, 3197 url: null, 3198 // To support iOS's swipe-to-go-back gesture (when being used in-app). 3199 edgeSwipeDetection: false, 3200 edgeSwipeThreshold: 20, 3201 // Autoheight 3202 autoHeight: false, 3203 // Set wrapper width 3204 setWrapperSize: false, 3205 // Virtual Translate 3206 virtualTranslate: false, 3207 // Effects 3208 effect: 'slide', 3209 // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip' 3210
vendor: 6,228 bytes, lines 3211-3407
3211 // Breakpoints 3212 breakpoints: undefined, 3213 breakpointsBase: 'window', 3214 // Slides grid 3215 spaceBetween: 0, 3216 slidesPerView: 1, 3217 slidesPerGroup: 1, 3218 slidesPerGroupSkip: 0, 3219 slidesPerGroupAuto: false, 3220 centeredSlides: false, 3221 centeredSlidesBounds: false, 3222 slidesOffsetBefore: 0, 3223 // in px 3224 slidesOffsetAfter: 0, 3225 // in px 3226 normalizeSlideIndex: true, 3227 centerInsufficientSlides: false, 3228 // Disable swiper and hide navigation when container not overflow 3229 watchOverflow: true, 3230 // Round length 3231 roundLengths: false, 3232 // Touches 3233 touchRatio: 1, 3234 touchAngle: 45, 3235 simulateTouch: true, 3236 shortSwipes: true, 3237 longSwipes: true, 3238 longSwipesRatio: 0.5, 3239 longSwipesMs: 300, 3240 followFinger: true, 3241 allowTouchMove: true, 3242 threshold: 5, 3243 touchMoveStopPropagation: false, 3244 touchStartPreventDefault: true, 3245 touchStartForcePreventDefault: false, 3246 touchReleaseOnEdges: false, 3247 // Unique Navigation Elements 3248 uniqueNavElements: true, 3249 // Resistance 3250 resistance: true, 3251 resistanceRatio: 0.85, 3252 // Progress 3253 watchSlidesProgress: false, 3254 // Cursor 3255 grabCursor: false, 3256 // Clicks 3257 preventClicks: true, 3258 preventClicksPropagation: true, 3259 slideToClickedSlide: false, 3260 // loop 3261 loop: false, 3262 loopedSlides: null, 3263 loopPreventsSliding: true, 3264 // rewind 3265 rewind: false, 3266 // Swiping/no swiping 3267 allowSlidePrev: true, 3268 allowSlideNext: true, 3269 swipeHandler: null, 3270 // '.swipe-handler', 3271 noSwiping: true, 3272 noSwipingClass: 'swiper-no-swiping', 3273 noSwipingSelector: null, 3274 // Passive Listeners 3275 passiveListeners: true, 3276 maxBackfaceHiddenSlides: 10, 3277 // NS 3278 containerModifierClass: 'swiper-', 3279 // NEW 3280 slideClass: 'swiper-slide', 3281 slideActiveClass: 'swiper-slide-active', 3282 slideVisibleClass: 'swiper-slide-visible', 3283 slideNextClass: 'swiper-slide-next', 3284 slidePrevClass: 'swiper-slide-prev', 3285 wrapperClass: 'swiper-wrapper', 3286 lazyPreloaderClass: 'swiper-lazy-preloader', 3287 // Callbacks 3288 runCallbacksOnInit: true, 3289 // Internals 3290 _emitClasses: false 3291 }; 3292 3293 function moduleExtendParams(params, allModulesParams) { 3294 return function extendParams(obj) { 3295 if (obj === void 0) { 3296 obj = {}; 3297 } 3298 const moduleParamName = Object.keys(obj)[0]; 3299 const moduleParams = obj[moduleParamName]; 3300 if (typeof moduleParams !== 'object' || moduleParams === null) { 3301 extend(allModulesParams, obj); 3302 return; 3303 } 3304 if (['navigation', 'pagination', 'scrollbar'].indexOf(moduleParamName) >= 0 && params[moduleParamName] === true) { 3305 params[moduleParamName] = { 3306 auto: true 3307 }; 3308 } 3309 if (!(moduleParamName in params && 'enabled' in moduleParams)) { 3310 extend(allModulesParams, obj); 3311 return; 3312 } 3313 if (params[moduleParamName] === true) { 3314 params[moduleParamName] = { 3315 enabled: true 3316 }; 3317 } 3318 if (typeof params[moduleParamName] === 'object' && !('enabled' in params[moduleParamName])) { 3319 params[moduleParamName].enabled = true; 3320 } 3321 if (!params[moduleParamName]) params[moduleParamName] = { 3322 enabled: false 3323 }; 3324 extend(allModulesParams, obj); 3325 }; 3326 } 3327 3328 /* eslint no-param-reassign: "off" */ 3329 const prototypes = { 3330 eventsEmitter, 3331 update, 3332 translate, 3333 transition, 3334 slide, 3335 loop, 3336 grabCursor, 3337 events: events$1, 3338 breakpoints, 3339 checkOverflow: checkOverflow$1, 3340 classes 3341 }; 3342 const extendedDefaults = {}; 3343 class Swiper { 3344 constructor() { 3345 let el; 3346 let params; 3347 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 3348 args[_key] = arguments[_key]; 3349 } 3350 if (args.length === 1 && args[0].constructor && Object.prototype.toString.call(args[0]).slice(8, -1) === 'Object') { 3351 params = args[0]; 3352 } else { 3353 [el, params] = args; 3354 } 3355 if (!params) params = {}; 3356 params = extend({}, params); 3357 if (el && !params.el) params.el = el; 3358 const document = getDocument(); 3359 if (params.el && typeof params.el === 'string' && document.querySelectorAll(params.el).length > 1) { 3360 const swipers = []; 3361 document.querySelectorAll(params.el).forEach(containerEl => { 3362 const newParams = extend({}, params, { 3363 el: containerEl 3364 }); 3365 swipers.push(new Swiper(newParams)); 3366 }); 3367 // eslint-disable-next-line no-constructor-return 3368 return swipers; 3369 } 3370 3371 // Swiper Instance 3372 const swiper = this; 3373 swiper.__swiper__ = true; 3374 swiper.support = getSupport(); 3375 swiper.device = getDevice({ 3376 userAgent: params.userAgent 3377 }); 3378 swiper.browser = getBrowser(); 3379 swiper.eventsListeners = {}; 3380 swiper.eventsAnyListeners = []; 3381 swiper.modules = [...swiper.__modules__]; 3382 if (params.modules && Array.isArray(params.modules)) { 3383 swiper.modules.push(...params.modules); 3384 } 3385 const allModulesParams = {}; 3386 swiper.modules.forEach(mod => { 3387 mod({ 3388 params, 3389 swiper, 3390 extendParams: moduleExtendParams(params, allModulesParams), 3391 on: swiper.on.bind(swiper), 3392 once: swiper.once.bind(swiper), 3393 off: swiper.off.bind(swiper), 3394 emit: swiper.emit.bind(swiper) 3395 }); 3396 }); 3397 3398 // Extend defaults with modules params 3399 const swiperParams = extend({}, defaults, allModulesParams); 3400 3401 // Extend defaults with passed params 3402 swiper.params = extend({}, swiperParams, extendedDefaults, params); 3403 swiper.originalParams = extend({}, swiper.params); 3404 swiper.passedParams = extend({}, params); 3405 3406 // add event listeners 3407 if (swiper.params && swiper.params.on) {
vendor: 4,490 bytes, lines 3408-3550
3408 Object.keys(swiper.params.on).forEach(eventName => { 3409 swiper.on(eventName, swiper.params.on[eventName]); 3410 }); 3411 } 3412 if (swiper.params && swiper.params.onAny) { 3413 swiper.onAny(swiper.params.onAny); 3414 } 3415 3416 // Extend Swiper 3417 Object.assign(swiper, { 3418 enabled: swiper.params.enabled, 3419 el, 3420 // Classes 3421 classNames: [], 3422 // Slides 3423 slides: [], 3424 slidesGrid: [], 3425 snapGrid: [], 3426 slidesSizesGrid: [], 3427 // isDirection 3428 isHorizontal() { 3429 return swiper.params.direction === 'horizontal'; 3430 }, 3431 isVertical() { 3432 return swiper.params.direction === 'vertical'; 3433 }, 3434 // Indexes 3435 activeIndex: 0, 3436 realIndex: 0, 3437 // 3438 isBeginning: true, 3439 isEnd: false, 3440 // Props 3441 translate: 0, 3442 previousTranslate: 0, 3443 progress: 0, 3444 velocity: 0, 3445 animating: false, 3446 // Locks 3447 allowSlideNext: swiper.params.allowSlideNext, 3448 allowSlidePrev: swiper.params.allowSlidePrev, 3449 // Touch Events 3450 touchEventsData: { 3451 isTouched: undefined, 3452 isMoved: undefined, 3453 allowTouchCallbacks: undefined, 3454 touchStartTime: undefined, 3455 isScrolling: undefined, 3456 currentTranslate: undefined, 3457 startTranslate: undefined, 3458 allowThresholdMove: undefined, 3459 // Form elements to match 3460 focusableElements: swiper.params.focusableElements, 3461 // Last click time 3462 lastClickTime: now(), 3463 clickTimeout: undefined, 3464 // Velocities 3465 velocities: [], 3466 allowMomentumBounce: undefined, 3467 startMoving: undefined, 3468 evCache: [] 3469 }, 3470 // Clicks 3471 allowClick: true, 3472 // Touches 3473 allowTouchMove: swiper.params.allowTouchMove, 3474 touches: { 3475 startX: 0, 3476 startY: 0, 3477 currentX: 0, 3478 currentY: 0, 3479 diff: 0 3480 }, 3481 // Images 3482 imagesToLoad: [], 3483 imagesLoaded: 0 3484 }); 3485 swiper.emit('_swiper'); 3486 3487 // Init 3488 if (swiper.params.init) { 3489 swiper.init(); 3490 } 3491 3492 // Return app instance 3493 // eslint-disable-next-line no-constructor-return 3494 return swiper; 3495 } 3496 recalcSlides() { 3497 const swiper = this; 3498 const { 3499 slidesEl, 3500 params 3501 } = swiper; 3502 swiper.slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`); 3503 } 3504 enable() { 3505 const swiper = this; 3506 if (swiper.enabled) return; 3507 swiper.enabled = true; 3508 if (swiper.params.grabCursor) { 3509 swiper.setGrabCursor(); 3510 } 3511 swiper.emit('enable'); 3512 } 3513 disable() { 3514 const swiper = this; 3515 if (!swiper.enabled) return; 3516 swiper.enabled = false; 3517 if (swiper.params.grabCursor) { 3518 swiper.unsetGrabCursor(); 3519 } 3520 swiper.emit('disable'); 3521 } 3522 setProgress(progress, speed) { 3523 const swiper = this; 3524 progress = Math.min(Math.max(progress, 0), 1); 3525 const min = swiper.minTranslate(); 3526 const max = swiper.maxTranslate(); 3527 const current = (max - min) * progress + min; 3528 swiper.translateTo(current, typeof speed === 'undefined' ? 0 : speed); 3529 swiper.updateActiveIndex(); 3530 swiper.updateSlidesClasses(); 3531 } 3532 emitContainerClasses() { 3533 const swiper = this; 3534 if (!swiper.params._emitClasses || !swiper.el) return; 3535 const cls = swiper.el.className.split(' ').filter(className => { 3536 return className.indexOf('swiper') === 0 || className.indexOf(swiper.params.containerModifierClass) === 0; 3537 }); 3538 swiper.emit('_containerClasses', cls.join(' ')); 3539 } 3540 getSlideClasses(slideEl) { 3541 const swiper = this; 3542 if (swiper.destroyed) return ''; 3543 return slideEl.className.split(' ').filter(className => { 3544 return className.indexOf('swiper-slide') === 0 || className.indexOf(swiper.params.slideClass) === 0; 3545 }).join(' '); 3546 } 3547 emitSlidesClasses() { 3548 const swiper = this; 3549 if (!swiper.params._emitClasses || !swiper.el) return; 3550 const updates = [];
vendor: 2,300 bytes, lines 3551-3622
3551 swiper.slides.forEach(slideEl => { 3552 const classNames = swiper.getSlideClasses(slideEl); 3553 updates.push({ 3554 slideEl, 3555 classNames 3556 }); 3557 swiper.emit('_slideClass', slideEl, classNames); 3558 }); 3559 swiper.emit('_slideClasses', updates); 3560 } 3561 slidesPerViewDynamic(view, exact) { 3562 if (view === void 0) { 3563 view = 'current'; 3564 } 3565 if (exact === void 0) { 3566 exact = false; 3567 } 3568 const swiper = this; 3569 const { 3570 params, 3571 slides, 3572 slidesGrid, 3573 slidesSizesGrid, 3574 size: swiperSize, 3575 activeIndex 3576 } = swiper; 3577 let spv = 1; 3578 if (params.centeredSlides) { 3579 let slideSize = slides[activeIndex].swiperSlideSize; 3580 let breakLoop; 3581 for (let i = activeIndex + 1; i < slides.length; i += 1) { 3582 if (slides[i] && !breakLoop) { 3583 slideSize += slides[i].swiperSlideSize; 3584 spv += 1; 3585 if (slideSize > swiperSize) breakLoop = true; 3586 } 3587 } 3588 for (let i = activeIndex - 1; i >= 0; i -= 1) { 3589 if (slides[i] && !breakLoop) { 3590 slideSize += slides[i].swiperSlideSize; 3591 spv += 1; 3592 if (slideSize > swiperSize) breakLoop = true; 3593 } 3594 } 3595 } else { 3596 // eslint-disable-next-line 3597 if (view === 'current') { 3598 for (let i = activeIndex + 1; i < slides.length; i += 1) { 3599 const slideInView = exact ? slidesGrid[i] + slidesSizesGrid[i] - slidesGrid[activeIndex] < swiperSize : slidesGrid[i] - slidesGrid[activeIndex] < swiperSize; 3600 if (slideInView) { 3601 spv += 1; 3602 } 3603 } 3604 } else { 3605 // previous 3606 for (let i = activeIndex - 1; i >= 0; i -= 1) { 3607 const slideInView = slidesGrid[activeIndex] - slidesGrid[i] < swiperSize; 3608 if (slideInView) { 3609 spv += 1; 3610 } 3611 } 3612 } 3613 } 3614 return spv; 3615 } 3616 update() { 3617 const swiper = this; 3618 if (!swiper || swiper.destroyed) return; 3619 const { 3620 snapGrid, 3621 params 3622 } = swiper;
vendor: 2,396 bytes, lines 3623-3680
3623 // Breakpoints 3624 if (params.breakpoints) { 3625 swiper.setBreakpoint(); 3626 } 3627 [...swiper.el.querySelectorAll('[loading="lazy"]')].forEach(imageEl => { 3628 if (imageEl.complete) { 3629 processLazyPreloader(swiper, imageEl); 3630 } 3631 }); 3632 swiper.updateSize(); 3633 swiper.updateSlides(); 3634 swiper.updateProgress(); 3635 swiper.updateSlidesClasses(); 3636 function setTranslate() { 3637 const translateValue = swiper.rtlTranslate ? swiper.translate * -1 : swiper.translate; 3638 const newTranslate = Math.min(Math.max(translateValue, swiper.maxTranslate()), swiper.minTranslate()); 3639 swiper.setTranslate(newTranslate); 3640 swiper.updateActiveIndex(); 3641 swiper.updateSlidesClasses(); 3642 } 3643 let translated; 3644 if (swiper.params.freeMode && swiper.params.freeMode.enabled) { 3645 setTranslate(); 3646 if (swiper.params.autoHeight) { 3647 swiper.updateAutoHeight(); 3648 } 3649 } else { 3650 if ((swiper.params.slidesPerView === 'auto' || swiper.params.slidesPerView > 1) && swiper.isEnd && !swiper.params.centeredSlides) { 3651 translated = swiper.slideTo(swiper.slides.length - 1, 0, false, true); 3652 } else { 3653 translated = swiper.slideTo(swiper.activeIndex, 0, false, true); 3654 } 3655 if (!translated) { 3656 setTranslate(); 3657 } 3658 } 3659 if (params.watchOverflow && snapGrid !== swiper.snapGrid) { 3660 swiper.checkOverflow(); 3661 } 3662 swiper.emit('update'); 3663 } 3664 changeDirection(newDirection, needUpdate) { 3665 if (needUpdate === void 0) { 3666 needUpdate = true; 3667 } 3668 const swiper = this; 3669 const currentDirection = swiper.params.direction; 3670 if (!newDirection) { 3671 // eslint-disable-next-line 3672 newDirection = currentDirection === 'horizontal' ? 'vertical' : 'horizontal'; 3673 } 3674 if (newDirection === currentDirection || newDirection !== 'horizontal' && newDirection !== 'vertical') { 3675 return swiper; 3676 } 3677 swiper.el.classList.remove(`${swiper.params.containerModifierClass}${currentDirection}`); 3678 swiper.el.classList.add(`${swiper.params.containerModifierClass}${newDirection}`); 3679 swiper.emitContainerClasses(); 3680 swiper.params.direction = newDirection;
vendor: 2,096 bytes, lines 3681-3738
3681 swiper.slides.forEach(slideEl => { 3682 if (newDirection === 'vertical') { 3683 slideEl.style.width = ''; 3684 } else { 3685 slideEl.style.height = ''; 3686 } 3687 }); 3688 swiper.emit('changeDirection'); 3689 if (needUpdate) swiper.update(); 3690 return swiper; 3691 } 3692 changeLanguageDirection(direction) { 3693 const swiper = this; 3694 if (swiper.rtl && direction === 'rtl' || !swiper.rtl && direction === 'ltr') return; 3695 swiper.rtl = direction === 'rtl'; 3696 swiper.rtlTranslate = swiper.params.direction === 'horizontal' && swiper.rtl; 3697 if (swiper.rtl) { 3698 swiper.el.classList.add(`${swiper.params.containerModifierClass}rtl`); 3699 swiper.el.dir = 'rtl'; 3700 } else { 3701 swiper.el.classList.remove(`${swiper.params.containerModifierClass}rtl`); 3702 swiper.el.dir = 'ltr'; 3703 } 3704 swiper.update(); 3705 } 3706 mount(element) { 3707 const swiper = this; 3708 if (swiper.mounted) return true; 3709 3710 // Find el 3711 let el = element || swiper.params.el; 3712 if (typeof el === 'string') { 3713 el = document.querySelector(el); 3714 } 3715 if (!el) { 3716 return false; 3717 } 3718 el.swiper = swiper; 3719 if (el.shadowEl) { 3720 swiper.isElement = true; 3721 } 3722 const getWrapperSelector = () => { 3723 return `.${(swiper.params.wrapperClass || '').trim().split(' ').join('.')}`; 3724 }; 3725 const getWrapper = () => { 3726 if (el && el.shadowRoot && el.shadowRoot.querySelector) { 3727 const res = el.shadowRoot.querySelector(getWrapperSelector()); 3728 // Children needs to return slot items 3729 return res; 3730 } 3731 return elementChildren(el, getWrapperSelector())[0]; 3732 }; 3733 // Find Wrapper 3734 let wrapperEl = getWrapper(); 3735 if (!wrapperEl && swiper.params.createElements) { 3736 wrapperEl = createElement('div', swiper.params.wrapperClass); 3737 el.append(wrapperEl); 3738 elementChildren(el, `.${swiper.params.slideClass}
3738`).forEach(slideEl => { 3739 wrapperEl.append(slideEl); 3740 }); 3741 } 3742 Object.assign(swiper, { 3743 el, 3744 wrapperEl, 3745 slidesEl: swiper.isElement ? el : wrapperEl, 3746 mounted: true, 3747 // RTL 3748 rtl: el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl', 3749 rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl'), 3750 wrongRTL: elementStyle(wrapperEl, 'display') === '-webkit-box' 3751 }); 3752 return true; 3753 } 3754 init(el) { 3755 const swiper = this; 3756 if (swiper.initialized) return swiper; 3757 const mounted = swiper.mount(el); 3758 if (mounted === false) return swiper; 3759 swiper.emit('beforeInit'); 3760 3761 // Set breakpoint 3762 if (swiper.params.breakpoints) { 3763 swiper.setBreakpoint(); 3764 } 3765 3766 // Add Classes 3767 swiper.addClasses(); 3768 3769 // Update size 3770 swiper.updateSize(); 3771 3772 // Update slides 3773 swiper.updateSlides(); 3774 if (swiper.params.watchOverflow) { 3775 swiper.checkOverflow(); 3776 } 3777 3778 // Set Grab Cursor 3779 if (swiper.params.grabCursor && swiper.enabled) { 3780 swiper.setGrabCursor(); 3781 } 3782 3783 // Slide To Initial Slide 3784 if (swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) { 3785 swiper.slideTo(swiper.params.initialSlide + swiper.virtual.slidesBefore, 0, swiper.params.runCallbacksOnInit, false, true); 3786 } else { 3787 swiper.slideTo(swiper.params.initialSlide, 0, swiper.params.runCallbacksOnInit, false, true); 3788 } 3789 3790 // Create loop 3791 if (swiper.params.loop) { 3792 swiper.loopCreate(); 3793 } 3794 3795 // Attach events 3796 swiper.attachEvents(); 3797 [...swiper.el.querySelectorAll('[loading="lazy"]')].forEach(imageEl => { 3798 if (imageEl.complete) { 3799 processLazyPreloader(swiper, imageEl); 3800 } else { 3801 imageEl.addEventListener('load', e => { 3802 processLazyPreloader(swiper, e.target); 3803 }); 3804 } 3805 }); 3806 3807 // Init Flag 3808 swiper.initialized = true; 3809 3810 // Emit 3811 swiper.emit('init'); 3812 swiper.emit('afterInit'); 3813 return swiper; 3814 } 3815 destroy(deleteInstance, cleanStyles) { 3816 if (deleteInstance === void 0) { 3817 deleteInstance = true; 3818 } 3819 if (cleanStyles === void 0) { 3820 cleanStyles = true; 3821 } 3822 const swiper = this; 3823 const { 3824 params, 3825 el, 3826 wrapperEl, 3827 slides 3828 } = swiper; 3829 if (typeof swiper.params === 'undefined' || swiper.destroyed) { 3830 return null; 3831 } 3832 swiper.emit('beforeDestroy'); 3833 3834 // Init Flag 3835 swiper.initialized = false; 3836 3837 // Detach events 3838 swiper.detachEvents(); 3839 3840 // Destroy loop 3841 if (params.loop) { 3842 swiper.loopDestroy(); 3843 } 3844 3845 // Cleanup styles 3846 if (cleanStyles) { 3847 swiper.removeClasses(); 3848 el.removeAttribute('style'); 3849 wrapperEl.removeAttribute('style'); 3850 if (slides && slides.length) {
3851 slides.forEach(slideEl => { 3852 slideEl.classList.remove(params.slideVisibleClass, params.slideActiveClass, params.slideNextClass, params.slidePrevClass); 3853 slideEl.removeAttribute('style'); 3854 slideEl.removeAttribute('data-swiper-slide-index'); 3855 }); 3856 } 3857 } 3858 swiper.emit('destroy'); 3859 3860 // Detach emitter events 3861 Object.keys(swiper.eventsListeners).forEach(eventName => { 3862 swiper.off(eventName); 3863 }); 3864 if (deleteInstance !== false) { 3865 swiper.el.swiper = null; 3866 deleteProps(swiper); 3867 } 3868 swiper.destroyed = true; 3869 return null; 3870 } 3871 static extendDefaults(newDefaults) { 3872 extend(extendedDefaults, newDefaults); 3873 } 3874 static get extendedDefaults() { 3875 return extendedDefaults; 3876 } 3877 static get defaults() { 3878 return defaults; 3879 } 3880 static installModule(mod) { 3881 if (!Swiper.prototype.__modules__) Swiper.prototype.__modules__ = []; 3882 const modules = Swiper.prototype.__modules__; 3883 if (typeof mod === 'function' && modules.indexOf(mod) < 0) { 3884 modules.push(mod); 3885 } 3886 } 3887 static use(module) { 3888 if (Array.isArray(module)) { 3889 module.forEach(m => Swiper.installModule(m)); 3890 return Swiper; 3891 } 3892 Swiper.installModule(module); 3893 return Swiper; 3894 } 3895 } 3896 Object.keys(prototypes).forEach(prototypeGroup => { 3897 Object.keys(prototypes[prototypeGroup]).forEach(protoMethod => { 3898 Swiper.prototype[protoMethod] = prototypes[prototypeGroup][protoMethod]; 3899 }); 3900 }); 3901 Swiper.use([Resize, Observer]); 3902 3903 function Virtual(_ref) { 3904 let { 3905 swiper, 3906 extendParams, 3907 on, 3908 emit 3909 } = _ref; 3910 extendParams({ 3911 virtual: { 3912 enabled: false, 3913 slides: [], 3914 cache: true, 3915 renderSlide: null, 3916 renderExternal: null, 3917 renderExternalUpdate: true, 3918 addSlidesBefore: 0, 3919 addSlidesAfter: 0 3920 } 3921 }); 3922 let cssModeTimeout; 3923 const document = getDocument(); 3924 swiper.virtual = { 3925 cache: {}, 3926 from: undefined, 3927 to: undefined, 3928 slides: [], 3929 offset: 0, 3930 slidesGrid: [] 3931 }; 3932 const tempDOM = document.createElement('div');
vendor: 3,258 bytes, lines 3933-4020
3933 function renderSlide(slide, index) { 3934 const params = swiper.params.virtual; 3935 if (params.cache && swiper.virtual.cache[index]) { 3936 return swiper.virtual.cache[index]; 3937 } 3938 // eslint-disable-next-line 3939 let slideEl; 3940 if (params.renderSlide) { 3941 slideEl = params.renderSlide.call(swiper, slide, index); 3942 if (typeof slideEl === 'string') { 3943 tempDOM.innerHTML = slideEl; 3944 slideEl = tempDOM.children[0]; 3945 } 3946 } else if (swiper.isElement) { 3947 slideEl = createElement('swiper-slide'); 3948 } else { 3949 slideEl = createElement('div', swiper.params.slideClass); 3950 } 3951 slideEl.setAttribute('data-swiper-slide-index', index); 3952 if (!params.renderSlide) { 3953 slideEl.textContent = slide; 3954 } 3955 if (params.cache) swiper.virtual.cache[index] = slideEl; 3956 return slideEl; 3957 } 3958 function update(force) { 3959 const { 3960 slidesPerView, 3961 slidesPerGroup, 3962 centeredSlides, 3963 loop: isLoop 3964 } = swiper.params; 3965 const { 3966 addSlidesBefore, 3967 addSlidesAfter 3968 } = swiper.params.virtual; 3969 const { 3970 from: previousFrom, 3971 to: previousTo, 3972 slides, 3973 slidesGrid: previousSlidesGrid, 3974 offset: previousOffset 3975 } = swiper.virtual; 3976 if (!swiper.params.cssMode) { 3977 swiper.updateActiveIndex(); 3978 } 3979 const activeIndex = swiper.activeIndex || 0; 3980 let offsetProp; 3981 if (swiper.rtlTranslate) offsetProp = 'right';else offsetProp = swiper.isHorizontal() ? 'left' : 'top'; 3982 let slidesAfter; 3983 let slidesBefore; 3984 if (centeredSlides) { 3985 slidesAfter = Math.floor(slidesPerView / 2) + slidesPerGroup + addSlidesAfter; 3986 slidesBefore = Math.floor(slidesPerView / 2) + slidesPerGroup + addSlidesBefore; 3987 } else { 3988 slidesAfter = slidesPerView + (slidesPerGroup - 1) + addSlidesAfter; 3989 slidesBefore = (isLoop ? slidesPerView : slidesPerGroup) + addSlidesBefore; 3990 } 3991 let from = activeIndex - slidesBefore; 3992 let to = activeIndex + slidesAfter; 3993 if (!isLoop) { 3994 from = Math.max(from, 0); 3995 to = Math.min(to, slides.length - 1); 3996 } 3997 let offset = (swiper.slidesGrid[from] || 0) - (swiper.slidesGrid[0] || 0); 3998 if (isLoop && activeIndex >= slidesBefore) { 3999 from -= slidesBefore; 4000 if (!centeredSlides) offset += swiper.slidesGrid[0]; 4001 } else if (isLoop && activeIndex < slidesBefore) { 4002 from = -slidesBefore; 4003 if (centeredSlides) offset += swiper.slidesGrid[0]; 4004 } 4005 Object.assign(swiper.virtual, { 4006 from, 4007 to, 4008 offset, 4009 slidesGrid: swiper.slidesGrid, 4010 slidesBefore, 4011 slidesAfter 4012 }); 4013 function onRendered() { 4014 swiper.updateSlides(); 4015 swiper.updateProgress(); 4016 swiper.updateSlidesClasses(); 4017 emit('virtualUpdate'); 4018 } 4019 if (previousFrom === from && previousTo === to && !force) { 4020 if (swiper.slidesGrid !== previousSlidesGrid && offset !== previousOffset) {
vendor: 1,352 bytes, lines 4021-4062
4021 swiper.slides.forEach(slideEl => { 4022 slideEl.style[offsetProp] = `${offset}px`; 4023 }); 4024 } 4025 swiper.updateProgress(); 4026 emit('virtualUpdate'); 4027 return; 4028 } 4029 if (swiper.params.virtual.renderExternal) { 4030 swiper.params.virtual.renderExternal.call(swiper, { 4031 offset, 4032 from, 4033 to, 4034 slides: function getSlides() { 4035 const slidesToRender = []; 4036 for (let i = from; i <= to; i += 1) { 4037 slidesToRender.push(slides[i]); 4038 } 4039 return slidesToRender; 4040 }() 4041 }); 4042 if (swiper.params.virtual.renderExternalUpdate) { 4043 onRendered(); 4044 } else { 4045 emit('virtualUpdate'); 4046 } 4047 return; 4048 } 4049 const prependIndexes = []; 4050 const appendIndexes = []; 4051 const getSlideIndex = index => { 4052 let slideIndex = index; 4053 if (index < 0) { 4054 slideIndex = slides.length + index; 4055 } else if (slideIndex >= slides.length) { 4056 // eslint-disable-next-line 4057 slideIndex = slideIndex - slides.length; 4058 } 4059 return slideIndex; 4060 }; 4061 if (force) { 4062 swiper.slidesEl.querySelectorAll(`.${swiper.params.slideClass}
4062, swiper-slide`).forEach(slideEl => { 4063 slideEl.remove(); 4064 }); 4065 } else { 4066 for (let i = previousFrom; i <= previousTo; i += 1) { 4067 if (i < from || i > to) { 4068 const slideIndex = getSlideIndex(i); 4069 swiper.slidesEl.querySelectorAll(`.${swiper.params.slideClass}[data-swiper-slide-index="${slideIndex}"], swiper-slide[data-swiper-slide-index="${slideIndex}"]`).forEach(slideEl => { 4070 slideEl.remove(); 4071 }); 4072 } 4073 } 4074 } 4075 const loopFrom = isLoop ? -slides.length : 0; 4076 const loopTo = isLoop ? slides.length * 2 : slides.length; 4077 for (let i = loopFrom; i < loopTo; i += 1) { 4078 if (i >= from && i <= to) { 4079 const slideIndex = getSlideIndex(i); 4080 if (typeof previousTo === 'undefined' || force) { 4081 appendIndexes.push(slideIndex); 4082 } else { 4083 if (i > previousTo) appendIndexes.push(slideIndex); 4084 if (i < previousFrom) prependIndexes.push(slideIndex); 4085 } 4086 } 4087 } 4088 appendIndexes.forEach(index => { 4089 swiper.slidesEl.append(renderSlide(slides[index], index)); 4090 }); 4091 if (isLoop) { 4092 for (let i = prependIndexes.length - 1; i >= 0; i -= 1) { 4093 const index = prependIndexes[i]; 4094 swiper.slidesEl.prepend(renderSlide(slides[index], index)); 4095 } 4096 } else { 4097 prependIndexes.sort((a, b) => b - a); 4098 prependIndexes.forEach(index => { 4099 swiper.slidesEl.prepend(renderSlide(slides[index], index)); 4100 }); 4101 } 4102 elementChildren(swiper.slidesEl, '.swiper-slide, swiper-slide').forEach(sli
vendor: 5,323 bytes, lines 4102-4254
4102deEl => { 4103 slideEl.style[offsetProp] = `${offset}px`; 4104 }); 4105 onRendered(); 4106 } 4107 function appendSlide(slides) { 4108 if (typeof slides === 'object' && 'length' in slides) { 4109 for (let i = 0; i < slides.length; i += 1) { 4110 if (slides[i]) swiper.virtual.slides.push(slides[i]); 4111 } 4112 } else { 4113 swiper.virtual.slides.push(slides); 4114 } 4115 update(true); 4116 } 4117 function prependSlide(slides) { 4118 const activeIndex = swiper.activeIndex; 4119 let newActiveIndex = activeIndex + 1; 4120 let numberOfNewSlides = 1; 4121 if (Array.isArray(slides)) { 4122 for (let i = 0; i < slides.length; i += 1) { 4123 if (slides[i]) swiper.virtual.slides.unshift(slides[i]); 4124 } 4125 newActiveIndex = activeIndex + slides.length; 4126 numberOfNewSlides = slides.length; 4127 } else { 4128 swiper.virtual.slides.unshift(slides); 4129 } 4130 if (swiper.params.virtual.cache) { 4131 const cache = swiper.virtual.cache; 4132 const newCache = {}; 4133 Object.keys(cache).forEach(cachedIndex => { 4134 const cachedEl = cache[cachedIndex]; 4135 const cachedElIndex = cachedEl.getAttribute('data-swiper-slide-index'); 4136 if (cachedElIndex) { 4137 cachedEl.setAttribute('data-swiper-slide-index', parseInt(cachedElIndex, 10) + numberOfNewSlides); 4138 } 4139 newCache[parseInt(cachedIndex, 10) + numberOfNewSlides] = cachedEl; 4140 }); 4141 swiper.virtual.cache = newCache; 4142 } 4143 update(true); 4144 swiper.slideTo(newActiveIndex, 0); 4145 } 4146 function removeSlide(slidesIndexes) { 4147 if (typeof slidesIndexes === 'undefined' || slidesIndexes === null) return; 4148 let activeIndex = swiper.activeIndex; 4149 if (Array.isArray(slidesIndexes)) { 4150 for (let i = slidesIndexes.length - 1; i >= 0; i -= 1) { 4151 swiper.virtual.slides.splice(slidesIndexes[i], 1); 4152 if (swiper.params.virtual.cache) { 4153 delete swiper.virtual.cache[slidesIndexes[i]]; 4154 } 4155 if (slidesIndexes[i] < activeIndex) activeIndex -= 1; 4156 activeIndex = Math.max(activeIndex, 0); 4157 } 4158 } else { 4159 swiper.virtual.slides.splice(slidesIndexes, 1); 4160 if (swiper.params.virtual.cache) { 4161 delete swiper.virtual.cache[slidesIndexes]; 4162 } 4163 if (slidesIndexes < activeIndex) activeIndex -= 1; 4164 activeIndex = Math.max(activeIndex, 0); 4165 } 4166 update(true); 4167 swiper.slideTo(activeIndex, 0); 4168 } 4169 function removeAllSlides() { 4170 swiper.virtual.slides = []; 4171 if (swiper.params.virtual.cache) { 4172 swiper.virtual.cache = {}; 4173 } 4174 update(true); 4175 swiper.slideTo(0, 0); 4176 } 4177 on('beforeInit', () => { 4178 if (!swiper.params.virtual.enabled) return; 4179 let domSlidesAssigned; 4180 if (typeof swiper.passedParams.virtual.slides === 'undefined') { 4181 const slides = [...swiper.slidesEl.children].filter(el => el.matches(`.${swiper.params.slideClass}, swiper-slide`)); 4182 if (slides && slides.length) { 4183 swiper.virtual.slides = [...slides]; 4184 domSlidesAssigned = true; 4185 slides.forEach((slideEl, slideIndex) => { 4186 slideEl.setAttribute('data-swiper-slide-index', slideIndex); 4187 swiper.virtual.cache[slideIndex] = slideEl; 4188 slideEl.remove(); 4189 }); 4190 } 4191 } 4192 if (!domSlidesAssigned) { 4193 swiper.virtual.slides = swiper.params.virtual.slides; 4194 } 4195 swiper.classNames.push(`${swiper.params.containerModifierClass}virtual`); 4196 swiper.params.watchSlidesProgress = true; 4197 swiper.originalParams.watchSlidesProgress = true; 4198 if (!swiper.params.initialSlide) { 4199 update(); 4200 } 4201 }); 4202 on('setTranslate', () => { 4203 if (!swiper.params.virtual.enabled) return; 4204 if (swiper.params.cssMode && !swiper._immediateVirtual) { 4205 clearTimeout(cssModeTimeout); 4206 cssModeTimeout = setTimeout(() => { 4207 update(); 4208 }, 100); 4209 } else { 4210 update(); 4211 } 4212 }); 4213 on('init update resize', () => { 4214 if (!swiper.params.virtual.enabled) return; 4215 if (swiper.params.cssMode) { 4216 setCSSProperty(swiper.wrapperEl, '--swiper-virtual-size', `${swiper.virtualSize}px`); 4217 } 4218 }); 4219 Object.assign(swiper.virtual, { 4220 appendSlide, 4221 prependSlide, 4222 removeSlide, 4223 removeAllSlides, 4224 update 4225 }); 4226 } 4227 4228 /* eslint-disable consistent-return */ 4229 function Keyboard(_ref) { 4230 let { 4231 swiper, 4232 extendParams, 4233 on, 4234 emit 4235 } = _ref; 4236 const document = getDocument(); 4237 const window = getWindow(); 4238 swiper.keyboard = { 4239 enabled: false 4240 }; 4241 extendParams({ 4242 keyboard: { 4243 enabled: false, 4244 onlyInViewport: true, 4245 pageUpDown: true 4246 } 4247 }); 4248 function handle(event) { 4249 if (!swiper.enabled) return; 4250 const { 4251 rtlTranslate: rtl 4252 } = swiper; 4253 let e = event; 4254 if (e.originalEvent) e = e.originalEvent; // jquery fix
vendor: 4,274 bytes, lines 4255-4354
4255 const kc = e.keyCode || e.charCode; 4256 const pageUpDown = swiper.params.keyboard.pageUpDown; 4257 const isPageUp = pageUpDown && kc === 33; 4258 const isPageDown = pageUpDown && kc === 34; 4259 const isArrowLeft = kc === 37; 4260 const isArrowRight = kc === 39; 4261 const isArrowUp = kc === 38; 4262 const isArrowDown = kc === 40; 4263 // Directions locks 4264 if (!swiper.allowSlideNext && (swiper.isHorizontal() && isArrowRight || swiper.isVertical() && isArrowDown || isPageDown)) { 4265 return false; 4266 } 4267 if (!swiper.allowSlidePrev && (swiper.isHorizontal() && isArrowLeft || swiper.isVertical() && isArrowUp || isPageUp)) { 4268 return false; 4269 } 4270 if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) { 4271 return undefined; 4272 } 4273 if (document.activeElement && document.activeElement.nodeName && (document.activeElement.nodeName.toLowerCase() === 'input' || document.activeElement.nodeName.toLowerCase() === 'textarea')) { 4274 return undefined; 4275 } 4276 if (swiper.params.keyboard.onlyInViewport && (isPageUp || isPageDown || isArrowLeft || isArrowRight || isArrowUp || isArrowDown)) { 4277 let inView = false; 4278 // Check that swiper should be inside of visible area of window 4279 if (elementParents(swiper.el, `.${swiper.params.slideClass}, swiper-slide`).length > 0 && elementParents(swiper.el, `.${swiper.params.slideActiveClass}`).length === 0) { 4280 return undefined; 4281 } 4282 const el = swiper.el; 4283 const swiperWidth = el.clientWidth; 4284 const swiperHeight = el.clientHeight; 4285 const windowWidth = window.innerWidth; 4286 const windowHeight = window.innerHeight; 4287 const swiperOffset = elementOffset(el); 4288 if (rtl) swiperOffset.left -= el.scrollLeft; 4289 const swiperCoord = [[swiperOffset.left, swiperOffset.top], [swiperOffset.left + swiperWidth, swiperOffset.top], [swiperOffset.left, swiperOffset.top + swiperHeight], [swiperOffset.left + swiperWidth, swiperOffset.top + swiperHeight]]; 4290 for (let i = 0; i < swiperCoord.length; i += 1) { 4291 const point = swiperCoord[i]; 4292 if (point[0] >= 0 && point[0] <= windowWidth && point[1] >= 0 && point[1] <= windowHeight) { 4293 if (point[0] === 0 && point[1] === 0) continue; // eslint-disable-line 4294 inView = true; 4295 } 4296 } 4297 if (!inView) return undefined; 4298 } 4299 if (swiper.isHorizontal()) { 4300 if (isPageUp || isPageDown || isArrowLeft || isArrowRight) { 4301 if (e.preventDefault) e.preventDefault();else e.returnValue = false; 4302 } 4303 if ((isPageDown || isArrowRight) && !rtl || (isPageUp || isArrowLeft) && rtl) swiper.slideNext(); 4304 if ((isPageUp || isArrowLeft) && !rtl || (isPageDown || isArrowRight) && rtl) swiper.slidePrev(); 4305 } else { 4306 if (isPageUp || isPageDown || isArrowUp || isArrowDown) { 4307 if (e.preventDefault) e.preventDefault();else e.returnValue = false; 4308 } 4309 if (isPageDown || isArrowDown) swiper.slideNext(); 4310 if (isPageUp || isArrowUp) swiper.slidePrev(); 4311 } 4312 emit('keyPress', kc); 4313 return undefined; 4314 } 4315 function enable() { 4316 if (swiper.keyboard.enabled) return; 4317 document.addEventListener('keydown', handle); 4318 swiper.keyboard.enabled = true; 4319 } 4320 function disable() { 4321 if (!swiper.keyboard.enabled) return; 4322 document.removeEventListener('keydown', handle); 4323 swiper.keyboard.enabled = false; 4324 } 4325 on('init', () => { 4326 if (swiper.params.keyboard.enabled) { 4327 enable(); 4328 } 4329 }); 4330 on('destroy', () => { 4331 if (swiper.keyboard.enabled) { 4332 disable(); 4333 } 4334 }); 4335 Object.assign(swiper.keyboard, { 4336 enable, 4337 disable 4338 }); 4339 } 4340 4341 /* eslint-disable consistent-return */ 4342 function Mousewheel(_ref) { 4343 let { 4344 swiper, 4345 extendParams, 4346 on, 4347 emit 4348 } = _ref; 4349 const window = getWindow(); 4350 extendParams({ 4351 mousewheel: { 4352 enabled: false, 4353 releaseOnEdges: false, 4354 invert: false,
vendor: 39,919 bytes, lines 4355-5358
4355 forceToAxis: false, 4356 sensitivity: 1, 4357 eventsTarget: 'container', 4358 thresholdDelta: null, 4359 thresholdTime: null 4360 } 4361 }); 4362 swiper.mousewheel = { 4363 enabled: false 4364 }; 4365 let timeout; 4366 let lastScrollTime = now(); 4367 let lastEventBeforeSnap; 4368 const recentWheelEvents = []; 4369 function normalize(e) { 4370 // Reasonable defaults 4371 const PIXEL_STEP = 10; 4372 const LINE_HEIGHT = 40; 4373 const PAGE_HEIGHT = 800; 4374 let sX = 0; 4375 let sY = 0; // spinX, spinY 4376 let pX = 0; 4377 let pY = 0; // pixelX, pixelY 4378 4379 // Legacy 4380 if ('detail' in e) { 4381 sY = e.detail; 4382 } 4383 if ('wheelDelta' in e) { 4384 sY = -e.wheelDelta / 120; 4385 } 4386 if ('wheelDeltaY' in e) { 4387 sY = -e.wheelDeltaY / 120; 4388 } 4389 if ('wheelDeltaX' in e) { 4390 sX = -e.wheelDeltaX / 120; 4391 } 4392 4393 // side scrolling on FF with DOMMouseScroll 4394 if ('axis' in e && e.axis === e.HORIZONTAL_AXIS) { 4395 sX = sY; 4396 sY = 0; 4397 } 4398 pX = sX * PIXEL_STEP; 4399 pY = sY * PIXEL_STEP; 4400 if ('deltaY' in e) { 4401 pY = e.deltaY; 4402 } 4403 if ('deltaX' in e) { 4404 pX = e.deltaX; 4405 } 4406 if (e.shiftKey && !pX) { 4407 // if user scrolls with shift he wants horizontal scroll 4408 pX = pY; 4409 pY = 0; 4410 } 4411 if ((pX || pY) && e.deltaMode) { 4412 if (e.deltaMode === 1) { 4413 // delta in LINE units 4414 pX *= LINE_HEIGHT; 4415 pY *= LINE_HEIGHT; 4416 } else { 4417 // delta in PAGE units 4418 pX *= PAGE_HEIGHT; 4419 pY *= PAGE_HEIGHT; 4420 } 4421 } 4422 4423 // Fall-back if spin cannot be determined 4424 if (pX && !sX) { 4425 sX = pX < 1 ? -1 : 1; 4426 } 4427 if (pY && !sY) { 4428 sY = pY < 1 ? -1 : 1; 4429 } 4430 return { 4431 spinX: sX, 4432 spinY: sY, 4433 pixelX: pX, 4434 pixelY: pY 4435 }; 4436 } 4437 function handleMouseEnter() { 4438 if (!swiper.enabled) return; 4439 swiper.mouseEntered = true; 4440 } 4441 function handleMouseLeave() { 4442 if (!swiper.enabled) return; 4443 swiper.mouseEntered = false; 4444 } 4445 function animateSlider(newEvent) { 4446 if (swiper.params.mousewheel.thresholdDelta && newEvent.delta < swiper.params.mousewheel.thresholdDelta) { 4447 // Prevent if delta of wheel scroll delta is below configured threshold 4448 return false; 4449 } 4450 if (swiper.params.mousewheel.thresholdTime && now() - lastScrollTime < swiper.params.mousewheel.thresholdTime) { 4451 // Prevent if time between scrolls is below configured threshold 4452 return false; 4453 } 4454 4455 // If the movement is NOT big enough and 4456 // if the last time the user scrolled was too close to the current one (avoid continuously triggering the slider): 4457 // Don't go any further (avoid insignificant scroll movement). 4458 if (newEvent.delta >= 6 && now() - lastScrollTime < 60) { 4459 // Return false as a default 4460 return true; 4461 } 4462 // If user is scrolling towards the end: 4463 // If the slider hasn't hit the latest slide or 4464 // if the slider is a loop and 4465 // if the slider isn't moving right now: 4466 // Go to next slide and 4467 // emit a scroll event. 4468 // Else (the user is scrolling towards the beginning) and 4469 // if the slider hasn't hit the first slide or 4470 // if the slider is a loop and 4471 // if the slider isn't moving right now: 4472 // Go to prev slide and 4473 // emit a scroll event. 4474 if (newEvent.direction < 0) { 4475 if ((!swiper.isEnd || swiper.params.loop) && !swiper.animating) { 4476 swiper.slideNext(); 4477 emit('scroll', newEvent.raw); 4478 } 4479 } else if ((!swiper.isBeginning || swiper.params.loop) && !swiper.animating) { 4480 swiper.slidePrev(); 4481 emit('scroll', newEvent.raw); 4482 } 4483 // If you got here is because an animation has been triggered so store the current time 4484 lastScrollTime = new window.Date().getTime(); 4485 // Return false as a default 4486 return false; 4487 } 4488 function releaseScroll(newEvent) { 4489 const params = swiper.params.mousewheel; 4490 if (newEvent.direction < 0) { 4491 if (swiper.isEnd && !swiper.params.loop && params.releaseOnEdges) { 4492 // Return true to animate scroll on edges 4493 return true; 4494 } 4495 } else if (swiper.isBeginning && !swiper.params.loop && params.releaseOnEdges) { 4496 // Return true to animate scroll on edges 4497 return true; 4498 } 4499 return false; 4500 } 4501 function handle(event) { 4502 let e = event; 4503 let disableParentSwiper = true; 4504 if (!swiper.enabled) return; 4505 const params = swiper.params.mousewheel; 4506 if (swiper.params.cssMode) { 4507 e.preventDefault(); 4508 } 4509 let targetEl = swiper.el; 4510 if (swiper.params.mousewheel.eventsTarget !== 'container') { 4511 targetEl = document.querySelector(swiper.params.mousewheel.eventsTarget); 4512 } 4513 const targetElContainsTarget = targetEl && targetEl.contains(e.target); 4514 if (!swiper.mouseEntered && !targetElContainsTarget && !params.releaseOnEdges) return true; 4515 if (e.originalEvent) e = e.originalEvent; // jquery fix 4516 let delta = 0; 4517 const rtlFactor = swiper.rtlTranslate ? -1 : 1; 4518 const data = normalize(e); 4519 if (params.forceToAxis) { 4520 if (swiper.isHorizontal()) { 4521 if (Math.abs(data.pixelX) > Math.abs(data.pixelY)) delta = -data.pixelX * rtlFactor;else return true; 4522 } else if (Math.abs(data.pixelY) > Math.abs(data.pixelX)) delta = -data.pixelY;else return true; 4523 } else { 4524 delta = Math.abs(data.pixelX) > Math.abs(data.pixelY) ? -data.pixelX * rtlFactor : -data.pixelY; 4525 } 4526 if (delta === 0) return true; 4527 if (params.invert) delta = -delta; 4528 4529 // Get the scroll positions 4530 let positions = swiper.getTranslate() + delta * params.sensitivity; 4531 if (positions >= swiper.minTranslate()) positions = swiper.minTranslate(); 4532 if (positions <= swiper.maxTranslate()) positions = swiper.maxTranslate(); 4533 4534 // When loop is true: 4535 // the disableParentSwiper will be true. 4536 // When loop is false: 4537 // if the scroll positions is not on edge, 4538 // then the disableParentSwiper will be true. 4539 // if the scroll on edge positions, 4540 // then the disableParentSwiper will be false. 4541 disableParentSwiper = swiper.params.loop ? true : !(positions === swiper.minTranslate() || positions === swiper.maxTranslate()); 4542 if (disableParentSwiper && swiper.params.nested) e.stopPropagation(); 4543 if (!swiper.params.freeMode || !swiper.params.freeMode.enabled) { 4544 // Register the new event in a variable which stores the relevant data 4545 const newEvent = { 4546 time: now(), 4547 delta: Math.abs(delta), 4548 direction: Math.sign(delta), 4549 raw: event 4550 }; 4551 4552 // Keep the most recent events 4553 if (recentWheelEvents.length >= 2) { 4554 recentWheelEvents.shift(); // only store the last N events 4555 } 4556 4557 const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined; 4558 recentWheelEvents.push(newEvent); 4559 4560 // If there is at least one previous recorded event: 4561 // If direction has changed or 4562 // if the scroll is quicker than the previous one: 4563 // Animate the slider. 4564 // Else (this is the first time the wheel is moved): 4565 // Animate the slider. 4566 if (prevEvent) { 4567 if (newEvent.direction !== prevEvent.direction || newEvent.delta > prevEvent.delta || newEvent.time > prevEvent.time + 150) { 4568 animateSlider(newEvent); 4569 } 4570 } else { 4571 animateSlider(newEvent); 4572 } 4573 4574 // If it's time to release the scroll: 4575 // Return now so you don't hit the preventDefault. 4576 if (releaseScroll(newEvent)) { 4577 return true; 4578 } 4579 } else { 4580 // Freemode or scrollContainer: 4581 4582 // If we recently snapped after a momentum scroll, then ignore wheel events 4583 // to give time for the deceleration to finish. Stop ignoring after 500 msecs 4584 // or if it's a new scroll (larger delta or inverse sign as last event before 4585 // an end-of-momentum snap). 4586 const newEvent = { 4587 time: now(), 4588 delta: Math.abs(delta), 4589 direction: Math.sign(delta) 4590 }; 4591 const ignoreWheelEvents = lastEventBeforeSnap && newEvent.time < lastEventBeforeSnap.time + 500 && newEvent.delta <= lastEventBeforeSnap.delta && newEvent.direction === lastEventBeforeSnap.direction; 4592 if (!ignoreWheelEvents) { 4593 lastEventBeforeSnap = undefined; 4594 let position = swiper.getTranslate() + delta * params.sensitivity; 4595 const wasBeginning = swiper.isBeginning; 4596 const wasEnd = swiper.isEnd; 4597 if (position >= swiper.minTranslate()) position = swiper.minTranslate(); 4598 if (position <= swiper.maxTranslate()) position = swiper.maxTranslate(); 4599 swiper.setTransition(0); 4600 swiper.setTranslate(position); 4601 swiper.updateProgress(); 4602 swiper.updateActiveIndex(); 4603 swiper.updateSlidesClasses(); 4604 if (!wasBeginning && swiper.isBeginning || !wasEnd && swiper.isEnd) { 4605 swiper.updateSlidesClasses(); 4606 } 4607 if (swiper.params.loop) { 4608 swiper.loopFix({ 4609 direction: newEvent.direction < 0 ? 'next' : 'prev', 4610 byMousewheel: true 4611 }); 4612 } 4613 if (swiper.params.freeMode.sticky) { 4614 // When wheel scrolling starts with sticky (aka snap) enabled, then detect 4615 // the end of a momentum scroll by storing recent (N=15?) wheel events. 4616 // 1. do all N events have decreasing or same (absolute value) delta? 4617 // 2. did all N events arrive in the last M (M=500?) msecs? 4618 // 3. does the earliest event have an (absolute value) delta that's 4619 // at least P (P=1?) larger than the most recent event's delta? 4620 // 4. does the latest event have a delta that's smaller than Q (Q=6?) pixels? 4621 // If 1-4 are "yes" then we're near the end of a momentum scroll deceleration. 4622 // Snap immediately and ignore remaining wheel events in this scroll. 4623 // See comment above for "remaining wheel events in this scroll" determination. 4624 // If 1-4 aren't satisfied, then wait to snap until 500ms after the last event. 4625 clearTimeout(timeout); 4626 timeout = undefined; 4627 if (recentWheelEvents.length >= 15) { 4628 recentWheelEvents.shift(); // only store the last N events 4629 } 4630 4631 const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined; 4632 const firstEvent = recentWheelEvents[0]; 4633 recentWheelEvents.push(newEvent); 4634 if (prevEvent && (newEvent.delta > prevEvent.delta || newEvent.direction !== prevEvent.direction)) { 4635 // Increasing or reverse-sign delta means the user started scrolling again. Clear the wheel event log. 4636 recentWheelEvents.splice(0); 4637 } else if (recentWheelEvents.length >= 15 && newEvent.time - firstEvent.time < 500 && firstEvent.delta - newEvent.delta >= 1 && newEvent.delta <= 6) { 4638 // We're at the end of the deceleration of a momentum scroll, so there's no need 4639 // to wait for more events. Snap ASAP on the next tick. 4640 // Also, because there's some remaining momentum we'll bias the snap in the 4641 // direction of the ongoing scroll because it's better UX for the scroll to snap 4642 // in the same direction as the scroll instead of reversing to snap. Therefore, 4643 // if it's already scrolled more than 20% in the current direction, keep going. 4644 const snapToThreshold = delta > 0 ? 0.8 : 0.2; 4645 lastEventBeforeSnap = newEvent; 4646 recentWheelEvents.splice(0); 4647 timeout = nextTick(() => { 4648 swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold); 4649 }, 0); // no delay; move on next tick 4650 } 4651 4652 if (!timeout) { 4653 // if we get here, then we haven't detected the end of a momentum scroll, so 4654 // we'll consider a scroll "complete" when there haven't been any wheel events 4655 // for 500ms. 4656 timeout = nextTick(() => { 4657 const snapToThreshold = 0.5; 4658 lastEventBeforeSnap = newEvent; 4659 recentWheelEvents.splice(0); 4660 swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold); 4661 }, 500); 4662 } 4663 } 4664 4665 // Emit event 4666 if (!ignoreWheelEvents) emit('scroll', e); 4667 4668 // Stop autoplay 4669 if (swiper.params.autoplay && swiper.params.autoplayDisableOnInteraction) swiper.autoplay.stop(); 4670 // Return page scroll on edge positions 4671 if (position === swiper.minTranslate() || position === swiper.maxTranslate()) return true; 4672 } 4673 } 4674 if (e.preventDefault) e.preventDefault();else e.returnValue = false; 4675 return false; 4676 } 4677 function events(method) { 4678 let targetEl = swiper.el; 4679 if (swiper.params.mousewheel.eventsTarget !== 'container') { 4680 targetEl = document.querySelector(swiper.params.mousewheel.eventsTarget); 4681 } 4682 targetEl[method]('mouseenter', handleMouseEnter); 4683 targetEl[method]('mouseleave', handleMouseLeave); 4684 targetEl[method]('wheel', handle); 4685 } 4686 function enable() { 4687 if (swiper.params.cssMode) { 4688 swiper.wrapperEl.removeEventListener('wheel', handle); 4689 return true; 4690 } 4691 if (swiper.mousewheel.enabled) return false; 4692 events('addEventListener'); 4693 swiper.mousewheel.enabled = true; 4694 return true; 4695 } 4696 function disable() { 4697 if (swiper.params.cssMode) { 4698 swiper.wrapperEl.addEventListener(event, handle); 4699 return true; 4700 } 4701 if (!swiper.mousewheel.enabled) return false; 4702 events('removeEventListener'); 4703 swiper.mousewheel.enabled = false; 4704 return true; 4705 } 4706 on('init', () => { 4707 if (!swiper.params.mousewheel.enabled && swiper.params.cssMode) { 4708 disable(); 4709 } 4710 if (swiper.params.mousewheel.enabled) enable(); 4711 }); 4712 on('destroy', () => { 4713 if (swiper.params.cssMode) { 4714 enable(); 4715 } 4716 if (swiper.mousewheel.enabled) disable(); 4717 }); 4718 Object.assign(swiper.mousewheel, { 4719 enable, 4720 disable 4721 }); 4722 } 4723 4724 function createElementIfNotDefined(swiper, originalParams, params, checkProps) { 4725 if (swiper.params.createElements) { 4726 Object.keys(checkProps).forEach(key => { 4727 if (!params[key] && params.auto === true) { 4728 let element = elementChildren(swiper.el, `.${checkProps[key]}`)[0]; 4729 if (!element) { 4730 element = createElement('div', checkProps[key]); 4731 element.className = checkProps[key]; 4732 swiper.el.append(element); 4733 } 4734 params[key] = element; 4735 originalParams[key] = element; 4736 } 4737 }); 4738 } 4739 return params; 4740 } 4741 4742 function Navigation(_ref) { 4743 let { 4744 swiper, 4745 extendParams, 4746 on, 4747 emit 4748 } = _ref; 4749 extendParams({ 4750 navigation: { 4751 nextEl: null, 4752 prevEl: null, 4753 hideOnClick: false, 4754 disabledClass: 'swiper-button-disabled', 4755 hiddenClass: 'swiper-button-hidden', 4756 lockClass: 'swiper-button-lock', 4757 navigationDisabledClass: 'swiper-navigation-disabled' 4758 } 4759 }); 4760 swiper.navigation = { 4761 nextEl: null, 4762 prevEl: null 4763 }; 4764 const makeElementsArray = el => { 4765 if (!Array.isArray(el)) el = [el].filter(e => !!e); 4766 return el; 4767 }; 4768 function getEl(el) { 4769 let res; 4770 if (el && typeof el === 'string' && swiper.isElement) { 4771 res = swiper.el.shadowRoot.querySelector(el); 4772 if (res) return res; 4773 } 4774 if (el) { 4775 if (typeof el === 'string') res = [...document.querySelectorAll(el)]; 4776 if (swiper.params.uniqueNavElements && typeof el === 'string' && res.length > 1 && swiper.el.querySelectorAll(el).length === 1) { 4777 res = swiper.el.querySelector(el); 4778 } 4779 } 4780 if (el && !res) return el; 4781 // if (Array.isArray(res) && res.length === 1) res = res[0]; 4782 return res; 4783 } 4784 function toggleEl(el, disabled) { 4785 const params = swiper.params.navigation; 4786 el = makeElementsArray(el); 4787 el.forEach(subEl => { 4788 if (subEl) { 4789 subEl.classList[disabled ? 'add' : 'remove'](...params.disabledClass.split(' ')); 4790 if (subEl.tagName === 'BUTTON') subEl.disabled = disabled; 4791 if (swiper.params.watchOverflow && swiper.enabled) { 4792 subEl.classList[swiper.isLocked ? 'add' : 'remove'](params.lockClass); 4793 } 4794 } 4795 }); 4796 } 4797 function update() { 4798 // Update Navigation Buttons 4799 const { 4800 nextEl, 4801 prevEl 4802 } = swiper.navigation; 4803 if (swiper.params.loop) { 4804 toggleEl(prevEl, false); 4805 toggleEl(nextEl, false); 4806 return; 4807 } 4808 toggleEl(prevEl, swiper.isBeginning && !swiper.params.rewind); 4809 toggleEl(nextEl, swiper.isEnd && !swiper.params.rewind); 4810 } 4811 function onPrevClick(e) { 4812 e.preventDefault(); 4813 if (swiper.isBeginning && !swiper.params.loop && !swiper.params.rewind) return; 4814 swiper.slidePrev(); 4815 emit('navigationPrev'); 4816 } 4817 function onNextClick(e) { 4818 e.preventDefault(); 4819 if (swiper.isEnd && !swiper.params.loop && !swiper.params.rewind) return; 4820 swiper.slideNext(); 4821 emit('navigationNext'); 4822 } 4823 function init() { 4824 const params = swiper.params.navigation; 4825 swiper.params.navigation = createElementIfNotDefined(swiper, swiper.originalParams.navigation, swiper.params.navigation, { 4826 nextEl: 'swiper-button-next', 4827 prevEl: 'swiper-button-prev' 4828 }); 4829 if (!(params.nextEl || params.prevEl)) return; 4830 let nextEl = getEl(params.nextEl); 4831 let prevEl = getEl(params.prevEl); 4832 Object.assign(swiper.navigation, { 4833 nextEl, 4834 prevEl 4835 }); 4836 nextEl = makeElementsArray(nextEl); 4837 prevEl = makeElementsArray(prevEl); 4838 const initButton = (el, dir) => { 4839 if (el) { 4840 el.addEventListener('click', dir === 'next' ? onNextClick : onPrevClick); 4841 } 4842 if (!swiper.enabled && el) { 4843 el.classList.add(...params.lockClass.split(' ')); 4844 } 4845 }; 4846 nextEl.forEach(el => initButton(el, 'next')); 4847 prevEl.forEach(el => initButton(el, 'prev')); 4848 } 4849 function destroy() { 4850 let { 4851 nextEl, 4852 prevEl 4853 } = swiper.navigation; 4854 nextEl = makeElementsArray(nextEl); 4855 prevEl = makeElementsArray(prevEl); 4856 const destroyButton = (el, dir) => { 4857 el.removeEventListener('click', dir === 'next' ? onNextClick : onPrevClick); 4858 el.classList.remove(...swiper.params.navigation.disabledClass.split(' ')); 4859 }; 4860 nextEl.forEach(el => destroyButton(el, 'next')); 4861 prevEl.forEach(el => destroyButton(el, 'prev')); 4862 } 4863 on('init', () => { 4864 if (swiper.params.navigation.enabled === false) { 4865 // eslint-disable-next-line 4866 disable(); 4867 } else { 4868 init(); 4869 update(); 4870 } 4871 }); 4872 on('toEdge fromEdge lock unlock', () => { 4873 update(); 4874 }); 4875 on('destroy', () => { 4876 destroy(); 4877 }); 4878 on('enable disable', () => { 4879 let { 4880 nextEl, 4881 prevEl 4882 } = swiper.navigation; 4883 nextEl = makeElementsArray(nextEl); 4884 prevEl = makeElementsArray(prevEl); 4885 [...nextEl, ...prevEl].filter(el => !!el).forEach(el => el.classList[swiper.enabled ? 'remove' : 'add'](swiper.params.navigation.lockClass)); 4886 }); 4887 on('click', (_s, e) => { 4888 let { 4889 nextEl, 4890 prevEl 4891 } = swiper.navigation; 4892 nextEl = makeElementsArray(nextEl); 4893 prevEl = makeElementsArray(prevEl); 4894 const targetEl = e.target; 4895 if (swiper.params.navigation.hideOnClick && !prevEl.includes(targetEl) && !nextEl.includes(targetEl)) { 4896 if (swiper.pagination && swiper.params.pagination && swiper.params.pagination.clickable && (swiper.pagination.el === targetEl || swiper.pagination.el.contains(targetEl))) return; 4897 let isHidden; 4898 if (nextEl.length) { 4899 isHidden = nextEl[0].classList.contains(swiper.params.navigation.hiddenClass); 4900 } else if (prevEl.length) { 4901 isHidden = prevEl[0].classList.contains(swiper.params.navigation.hiddenClass); 4902 } 4903 if (isHidden === true) { 4904 emit('navigationShow'); 4905 } else { 4906 emit('navigationHide'); 4907 } 4908 [...nextEl, ...prevEl].filter(el => !!el).forEach(el => el.classList.toggle(swiper.params.navigation.hiddenClass)); 4909 } 4910 }); 4911 const enable = () => { 4912 swiper.el.classList.remove(...swiper.params.navigation.navigationDisabledClass.split(' ')); 4913 init(); 4914 update(); 4915 }; 4916 const disable = () => { 4917 swiper.el.classList.add(...swiper.params.navigation.navigationDisabledClass.split(' ')); 4918 destroy(); 4919 }; 4920 Object.assign(swiper.navigation, { 4921 enable, 4922 disable, 4923 update, 4924 init, 4925 destroy 4926 }); 4927 } 4928 4929 function classesToSelector(classes) { 4930 if (classes === void 0) { 4931 classes = ''; 4932 } 4933 return `.${classes.trim().replace(/([\.:!\/])/g, '\\$1') // eslint-disable-line 4934 .replace(/ /g, '.')}`; 4935 } 4936 4937 function Pagination(_ref) { 4938 let { 4939 swiper, 4940 extendParams, 4941 on, 4942 emit 4943 } = _ref; 4944 const pfx = 'swiper-pagination'; 4945 extendParams({ 4946 pagination: { 4947 el: null, 4948 bulletElement: 'span', 4949 clickable: false, 4950 hideOnClick: false, 4951 renderBullet: null, 4952 renderProgressbar: null, 4953 renderFraction: null, 4954 renderCustom: null, 4955 progressbarOpposite: false, 4956 type: 'bullets', 4957 // 'bullets' or 'progressbar' or 'fraction' or 'custom' 4958 dynamicBullets: false, 4959 dynamicMainBullets: 1, 4960 formatFractionCurrent: number => number, 4961 formatFractionTotal: number => number, 4962 bulletClass: `${pfx}-bullet`, 4963 bulletActiveClass: `${pfx}-bullet-active`, 4964 modifierClass: `${pfx}-`, 4965 currentClass: `${pfx}-current`, 4966 totalClass: `${pfx}-total`, 4967 hiddenClass: `${pfx}-hidden`, 4968 progressbarFillClass: `${pfx}-progressbar-fill`, 4969 progressbarOppositeClass: `${pfx}-progressbar-opposite`, 4970 clickableClass: `${pfx}-clickable`, 4971 lockClass: `${pfx}-lock`, 4972 horizontalClass: `${pfx}-horizontal`, 4973 verticalClass: `${pfx}-vertical`, 4974 paginationDisabledClass: `${pfx}-disabled` 4975 } 4976 }); 4977 swiper.pagination = { 4978 el: null, 4979 bullets: [] 4980 }; 4981 let bulletSize; 4982 let dynamicBulletIndex = 0; 4983 const makeElementsArray = el => { 4984 if (!Array.isArray(el)) el = [el].filter(e => !!e); 4985 return el; 4986 }; 4987 function isPaginationDisabled() { 4988 return !swiper.params.pagination.el || !swiper.pagination.el || Array.isArray(swiper.pagination.el) && swiper.pagination.el.length === 0; 4989 } 4990 function setSideBullets(bulletEl, position) { 4991 const { 4992 bulletActiveClass 4993 } = swiper.params.pagination; 4994 if (!bulletEl) return; 4995 bulletEl = bulletEl[`${position === 'prev' ? 'previous' : 'next'}ElementSibling`]; 4996 if (bulletEl) { 4997 bulletEl.classList.add(`${bulletActiveClass}-${position}`); 4998 bulletEl = bulletEl[`${position === 'prev' ? 'previous' : 'next'}ElementSibling`]; 4999 if (bulletEl) { 5000 bulletEl.classList.add(`${bulletActiveClass}-${position}-${position}`); 5001 } 5002 } 5003 } 5004 function onBulletClick(e) { 5005 const bulletEl = e.target.closest(classesToSelector(swiper.params.pagination.bulletClass)); 5006 if (!bulletEl) { 5007 return; 5008 } 5009 e.preventDefault(); 5010 const index = elementIndex(bulletEl) * swiper.params.slidesPerGroup; 5011 if (swiper.params.loop) { 5012 swiper.slideToLoop(index); 5013 } else { 5014 swiper.slideTo(index); 5015 } 5016 } 5017 function update() { 5018 // Render || Update Pagination bullets/items 5019 const rtl = swiper.rtl; 5020 const params = swiper.params.pagination; 5021 if (isPaginationDisabled()) return; 5022 let el = swiper.pagination.el; 5023 el = makeElementsArray(el); 5024 // Current/Total 5025 let current; 5026 const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length; 5027 const total = swiper.params.loop ? Math.ceil(slidesLength / swiper.params.slidesPerGroup) : swiper.snapGrid.length; 5028 if (swiper.params.loop) { 5029 current = swiper.params.slidesPerGroup > 1 ? Math.floor(swiper.realIndex / swiper.params.slidesPerGroup) : swiper.realIndex; 5030 } else if (typeof swiper.snapIndex !== 'undefined') { 5031 current = swiper.snapIndex; 5032 } else { 5033 current = swiper.activeIndex || 0; 5034 } 5035 // Types 5036 if (params.type === 'bullets' && swiper.pagination.bullets && swiper.pagination.bullets.length > 0) { 5037 const bullets = swiper.pagination.bullets; 5038 let firstIndex; 5039 let lastIndex; 5040 let midIndex; 5041 if (params.dynamicBullets) { 5042 bulletSize = elementOuterSize(bullets[0], swiper.isHorizontal() ? 'width' : 'height', true); 5043 el.forEach(subEl => { 5044 subEl.style[swiper.isHorizontal() ? 'width' : 'height'] = `${bulletSize * (params.dynamicMainBullets + 4)}px`; 5045 }); 5046 if (params.dynamicMainBullets > 1 && swiper.previousIndex !== undefined) { 5047 dynamicBulletIndex += current - (swiper.previousIndex || 0); 5048 if (dynamicBulletIndex > params.dynamicMainBullets - 1) { 5049 dynamicBulletIndex = params.dynamicMainBullets - 1; 5050 } else if (dynamicBulletIndex < 0) { 5051 dynamicBulletIndex = 0; 5052 } 5053 } 5054 firstIndex = Math.max(current - dynamicBulletIndex, 0); 5055 lastIndex = firstIndex + (Math.min(bullets.length, params.dynamicMainBullets) - 1); 5056 midIndex = (lastIndex + firstIndex) / 2; 5057 } 5058 bullets.forEach(bulletEl => { 5059 bulletEl.classList.remove(...['', '-next', '-next-next', '-prev', '-prev-prev', '-main'].map(suffix => `${params.bulletActiveClass}${suffix}`)); 5060 }); 5061 if (el.length > 1) { 5062 bullets.forEach(bullet => { 5063 const bulletIndex = elementIndex(bullet); 5064 if (bulletIndex === current) { 5065 bullet.classList.add(params.bulletActiveClass); 5066 } 5067 if (params.dynamicBullets) { 5068 if (bulletIndex >= firstIndex && bulletIndex <= lastIndex) { 5069 bullet.classList.add(`${params.bulletActiveClass}-main`); 5070 } 5071 if (bulletIndex === firstIndex) { 5072 setSideBullets(bullet, 'prev'); 5073 } 5074 if (bulletIndex === lastIndex) { 5075 setSideBullets(bullet, 'next'); 5076 } 5077 } 5078 }); 5079 } else { 5080 const bullet = bullets[current]; 5081 if (bullet) { 5082 bullet.classList.add(params.bulletActiveClass); 5083 } 5084 if (params.dynamicBullets) { 5085 const firstDisplayedBullet = bullets[firstIndex]; 5086 const lastDisplayedBullet = bullets[lastIndex]; 5087 for (let i = firstIndex; i <= lastIndex; i += 1) { 5088 bullets[i].classList.add(`${params.bulletActiveClass}-main`); 5089 } 5090 setSideBullets(firstDisplayedBullet, 'prev'); 5091 setSideBullets(lastDisplayedBullet, 'next'); 5092 } 5093 } 5094 if (params.dynamicBullets) { 5095 const dynamicBulletsLength = Math.min(bullets.length, params.dynamicMainBullets + 4); 5096 const bulletsOffset = (bulletSize * dynamicBulletsLength - bulletSize) / 2 - midIndex * bulletSize; 5097 const offsetProp = rtl ? 'right' : 'left'; 5098 bullets.forEach(bullet => { 5099 bullet.style[swiper.isHorizontal() ? offsetProp : 'top'] = `${bulletsOffset}px`; 5100 }); 5101 } 5102 } 5103 el.forEach((subEl, subElIndex) => { 5104 if (params.type === 'fraction') { 5105 subEl.querySelectorAll(classesToSelector(params.currentClass)).forEach(fractionEl => { 5106 fractionEl.textContent = params.formatFractionCurrent(current + 1); 5107 }); 5108 subEl.querySelectorAll(classesToSelector(params.totalClass)).forEach(totalEl => { 5109 totalEl.textContent = params.formatFractionTotal(total); 5110 }); 5111 } 5112 if (params.type === 'progressbar') { 5113 let progressbarDirection; 5114 if (params.progressbarOpposite) { 5115 progressbarDirection = swiper.isHorizontal() ? 'vertical' : 'horizontal'; 5116 } else { 5117 progressbarDirection = swiper.isHorizontal() ? 'horizontal' : 'vertical'; 5118 } 5119 const scale = (current + 1) / total; 5120 let scaleX = 1; 5121 let scaleY = 1; 5122 if (progressbarDirection === 'horizontal') { 5123 scaleX = scale; 5124 } else { 5125 scaleY = scale; 5126 } 5127 subEl.querySelectorAll(classesToSelector(params.progressbarFillClass)).forEach(progressEl => { 5128 progressEl.style.transform = `translate3d(0,0,0) scaleX(${scaleX}) scaleY(${scaleY})`; 5129 progressEl.style.transitionDuration = `${swiper.params.speed}ms`; 5130 }); 5131 } 5132 if (params.type === 'custom' && params.renderCustom) { 5133 subEl.innerHTML = params.renderCustom(swiper, current + 1, total); 5134 if (subElIndex === 0) emit('paginationRender', subEl); 5135 } else { 5136 if (subElIndex === 0) emit('paginationRender', subEl); 5137 emit('paginationUpdate', subEl); 5138 } 5139 if (swiper.params.watchOverflow && swiper.enabled) { 5140 subEl.classList[swiper.isLocked ? 'add' : 'remove'](params.lockClass); 5141 } 5142 }); 5143 } 5144 function render() { 5145 // Render Container 5146 const params = swiper.params.pagination; 5147 if (isPaginationDisabled()) return; 5148 const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length; 5149 let el = swiper.pagination.el; 5150 el = makeElementsArray(el); 5151 let paginationHTML = ''; 5152 if (params.type === 'bullets') { 5153 let numberOfBullets = swiper.params.loop ? Math.ceil(slidesLength / swiper.params.slidesPerGroup) : swiper.snapGrid.length; 5154 if (swiper.params.freeMode && swiper.params.freeMode.enabled && numberOfBullets > slidesLength) { 5155 numberOfBullets = slidesLength; 5156 } 5157 for (let i = 0; i < numberOfBullets; i += 1) { 5158 if (params.renderBullet) { 5159 paginationHTML += params.renderBullet.call(swiper, i, params.bulletClass); 5160 } else { 5161 paginationHTML += `<${params.bulletElement} class="${params.bulletClass}"></${params.bulletElement}>`; 5162 } 5163 } 5164 } 5165 if (params.type === 'fraction') { 5166 if (params.renderFraction) { 5167 paginationHTML = params.renderFraction.call(swiper, params.currentClass, params.totalClass); 5168 } else { 5169 paginationHTML = `<span class="${params.currentClass}"></span>` + ' / ' + `<span class="${params.totalClass}"></span>`; 5170 } 5171 } 5172 if (params.type === 'progressbar') { 5173 if (params.renderProgressbar) { 5174 paginationHTML = params.renderProgressbar.call(swiper, params.progressbarFillClass); 5175 } else { 5176 paginationHTML = `<span class="${params.progressbarFillClass}"></span>`; 5177 } 5178 } 5179 el.forEach(subEl => { 5180 if (params.type !== 'custom') { 5181 subEl.innerHTML = paginationHTML || ''; 5182 } 5183 if (params.type === 'bullets') { 5184 swiper.pagination.bullets = [...subEl.querySelectorAll(classesToSelector(params.bulletClass))]; 5185 } 5186 }); 5187 if (params.type !== 'custom') { 5188 emit('paginationRender', el[0]); 5189 } 5190 } 5191 function init() { 5192 swiper.params.pagination = createElementIfNotDefined(swiper, swiper.originalParams.pagination, swiper.params.pagination, { 5193 el: 'swiper-pagination' 5194 }); 5195 const params = swiper.params.pagination; 5196 if (!params.el) return; 5197 let el; 5198 if (typeof params.el === 'string' && swiper.isElement) { 5199 el = swiper.el.shadowRoot.querySelector(params.el); 5200 } 5201 if (!el && typeof params.el === 'string') { 5202 el = [...document.querySelectorAll(params.el)]; 5203 } 5204 if (!el) { 5205 el = params.el; 5206 } 5207 if (!el || el.length === 0) return; 5208 if (swiper.params.uniqueNavElements && typeof params.el === 'string' && Array.isArray(el) && el.length > 1) { 5209 el = [...swiper.el.querySelectorAll(params.el)]; 5210 // check if it belongs to another nested Swiper 5211 if (el.length > 1) { 5212 el = el.filter(subEl => { 5213 if (elementParents(subEl, '.swiper')[0] !== swiper.el) return false; 5214 return true; 5215 })[0]; 5216 } 5217 } 5218 if (Array.isArray(el) && el.length === 1) el = el[0]; 5219 Object.assign(swiper.pagination, { 5220 el 5221 }); 5222 el = makeElementsArray(el); 5223 el.forEach(subEl => { 5224 if (params.type === 'bullets' && params.clickable) { 5225 subEl.classList.add(params.clickableClass); 5226 } 5227 subEl.classList.add(params.modifierClass + params.type); 5228 subEl.classList.add(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 5229 if (params.type === 'bullets' && params.dynamicBullets) { 5230 subEl.classList.add(`${params.modifierClass}${params.type}-dynamic`); 5231 dynamicBulletIndex = 0; 5232 if (params.dynamicMainBullets < 1) { 5233 params.dynamicMainBullets = 1; 5234 } 5235 } 5236 if (params.type === 'progressbar' && params.progressbarOpposite) { 5237 subEl.classList.add(params.progressbarOppositeClass); 5238 } 5239 if (params.clickable) { 5240 subEl.addEventListener('click', onBulletClick); 5241 } 5242 if (!swiper.enabled) { 5243 subEl.classList.add(params.lockClass); 5244 } 5245 }); 5246 } 5247 function destroy() { 5248 const params = swiper.params.pagination; 5249 if (isPaginationDisabled()) return; 5250 let el = swiper.pagination.el; 5251 if (el) { 5252 el = makeElementsArray(el); 5253 el.forEach(subEl => { 5254 subEl.classList.remove(params.hiddenClass); 5255 subEl.classList.remove(params.modifierClass + params.type); 5256 subEl.classList.remove(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 5257 if (params.clickable) { 5258 subEl.removeEventListener('click', onBulletClick); 5259 } 5260 }); 5261 } 5262 if (swiper.pagination.bullets) swiper.pagination.bullets.forEach(subEl => subEl.classList.remove(params.bulletActiveClass)); 5263 } 5264 on('init', () => { 5265 if (swiper.params.pagination.enabled === false) { 5266 // eslint-disable-next-line 5267 disable(); 5268 } else { 5269 init(); 5270 render(); 5271 update(); 5272 } 5273 }); 5274 on('activeIndexChange', () => { 5275 if (typeof swiper.snapIndex === 'undefined') { 5276 update(); 5277 } 5278 }); 5279 on('snapIndexChange', () => { 5280 update(); 5281 }); 5282 on('snapGridLengthChange', () => { 5283 render(); 5284 update(); 5285 }); 5286 on('destroy', () => { 5287 destroy(); 5288 }); 5289 on('enable disable', () => { 5290 let { 5291 el 5292 } = swiper.pagination; 5293 if (el) { 5294 el = makeElementsArray(el); 5295 el.forEach(subEl => subEl.classList[swiper.enabled ? 'remove' : 'add'](swiper.params.pagination.lockClass)); 5296 } 5297 }); 5298 on('lock unlock', () => { 5299 update(); 5300 }); 5301 on('click', (_s, e) => { 5302 const targetEl = e.target; 5303 let { 5304 el 5305 } = swiper.pagination; 5306 if (!Array.isArray(el)) el = [el].filter(element => !!element); 5307 if (swiper.params.pagination.el && swiper.params.pagination.hideOnClick && el && el.length > 0 && !targetEl.classList.contains(swiper.params.pagination.bulletClass)) { 5308 if (swiper.navigation && (swiper.navigation.nextEl && targetEl === swiper.navigation.nextEl || swiper.navigation.prevEl && targetEl === swiper.navigation.prevEl)) return; 5309 const isHidden = el[0].classList.contains(swiper.params.pagination.hiddenClass); 5310 if (isHidden === true) { 5311 emit('paginationShow'); 5312 } else { 5313 emit('paginationHide'); 5314 } 5315 el.forEach(subEl => subEl.classList.toggle(swiper.params.pagination.hiddenClass)); 5316 } 5317 }); 5318 const enable = () => { 5319 swiper.el.classList.remove(swiper.params.pagination.paginationDisabledClass); 5320 let { 5321 el 5322 } = swiper.pagination; 5323 if (el) { 5324 el = makeElementsArray(el); 5325 el.forEach(subEl => subEl.classList.remove(swiper.params.pagination.paginationDisabledClass)); 5326 } 5327 init(); 5328 render(); 5329 update(); 5330 }; 5331 const disable = () => { 5332 swiper.el.classList.add(swiper.params.pagination.paginationDisabledClass); 5333 let { 5334 el 5335 } = swiper.pagination; 5336 if (el) { 5337 el = makeElementsArray(el); 5338 el.forEach(subEl => subEl.classList.add(swiper.params.pagination.paginationDisabledClass)); 5339 } 5340 destroy(); 5341 }; 5342 Object.assign(swiper.pagination, { 5343 enable, 5344 disable, 5345 render, 5346 update, 5347 init, 5348 destroy 5349 }); 5350 } 5351 5352 function Scrollbar(_ref) { 5353 let { 5354 swiper, 5355 extendParams, 5356 on, 5357 emit 5358 } = _ref;
vendor: 5,743 bytes, lines 5358-5528
5358 5359 const document = getDocument(); 5360 let isTouched = false; 5361 let timeout = null; 5362 let dragTimeout = null; 5363 let dragStartPos; 5364 let dragSize; 5365 let trackSize; 5366 let divider; 5367 extendParams({ 5368 scrollbar: { 5369 el: null, 5370 dragSize: 'auto', 5371 hide: false, 5372 draggable: false, 5373 snapOnRelease: true, 5374 lockClass: 'swiper-scrollbar-lock', 5375 dragClass: 'swiper-scrollbar-drag', 5376 scrollbarDisabledClass: 'swiper-scrollbar-disabled', 5377 horizontalClass: `swiper-scrollbar-horizontal`, 5378 verticalClass: `swiper-scrollbar-vertical` 5379 } 5380 }); 5381 swiper.scrollbar = { 5382 el: null, 5383 dragEl: null 5384 }; 5385 function setTranslate() { 5386 if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return; 5387 const { 5388 scrollbar, 5389 rtlTranslate: rtl 5390 } = swiper; 5391 const { 5392 dragEl, 5393 el 5394 } = scrollbar; 5395 const params = swiper.params.scrollbar; 5396 const progress = swiper.params.loop ? swiper.progressLoop : swiper.progress; 5397 let newSize = dragSize; 5398 let newPos = (trackSize - dragSize) * progress; 5399 if (rtl) { 5400 newPos = -newPos; 5401 if (newPos > 0) { 5402 newSize = dragSize - newPos; 5403 newPos = 0; 5404 } else if (-newPos + dragSize > trackSize) { 5405 newSize = trackSize + newPos; 5406 } 5407 } else if (newPos < 0) { 5408 newSize = dragSize + newPos; 5409 newPos = 0; 5410 } else if (newPos + dragSize > trackSize) { 5411 newSize = trackSize - newPos; 5412 } 5413 if (swiper.isHorizontal()) { 5414 dragEl.style.transform = `translate3d(${newPos}px, 0, 0)`; 5415 dragEl.style.width = `${newSize}px`; 5416 } else { 5417 dragEl.style.transform = `translate3d(0px, ${newPos}px, 0)`; 5418 dragEl.style.height = `${newSize}px`; 5419 } 5420 if (params.hide) { 5421 clearTimeout(timeout); 5422 el.style.opacity = 1; 5423 timeout = setTimeout(() => { 5424 el.style.opacity = 0; 5425 el.style.transitionDuration = '400ms'; 5426 }, 1000); 5427 } 5428 } 5429 function setTransition(duration) { 5430 if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return; 5431 swiper.scrollbar.dragEl.style.transitionDuration = `${duration}ms`; 5432 } 5433 function updateSize() { 5434 if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return; 5435 const { 5436 scrollbar 5437 } = swiper; 5438 const { 5439 dragEl, 5440 el 5441 } = scrollbar; 5442 dragEl.style.width = ''; 5443 dragEl.style.height = ''; 5444 trackSize = swiper.isHorizontal() ? el.offsetWidth : el.offsetHeight; 5445 divider = swiper.size / (swiper.virtualSize + swiper.params.slidesOffsetBefore - (swiper.params.centeredSlides ? swiper.snapGrid[0] : 0)); 5446 if (swiper.params.scrollbar.dragSize === 'auto') { 5447 dragSize = trackSize * divider; 5448 } else { 5449 dragSize = parseInt(swiper.params.scrollbar.dragSize, 10); 5450 } 5451 if (swiper.isHorizontal()) { 5452 dragEl.style.width = `${dragSize}px`; 5453 } else { 5454 dragEl.style.height = `${dragSize}px`; 5455 } 5456 if (divider >= 1) { 5457 el.style.display = 'none'; 5458 } else { 5459 el.style.display = ''; 5460 } 5461 if (swiper.params.scrollbar.hide) { 5462 el.style.opacity = 0; 5463 } 5464 if (swiper.params.watchOverflow && swiper.enabled) { 5465 scrollbar.el.classList[swiper.isLocked ? 'add' : 'remove'](swiper.params.scrollbar.lockClass); 5466 } 5467 } 5468 function getPointerPosition(e) { 5469 return swiper.isHorizontal() ? e.clientX : e.clientY; 5470 } 5471 function setDragPosition(e) { 5472 const { 5473 scrollbar, 5474 rtlTranslate: rtl 5475 } = swiper; 5476 const { 5477 el 5478 } = scrollbar; 5479 let positionRatio; 5480 positionRatio = (getPointerPosition(e) - elementOffset(el)[swiper.isHorizontal() ? 'left' : 'top'] - (dragStartPos !== null ? dragStartPos : dragSize / 2)) / (trackSize - dragSize); 5481 positionRatio = Math.max(Math.min(positionRatio, 1), 0); 5482 if (rtl) { 5483 positionRatio = 1 - positionRatio; 5484 } 5485 const position = swiper.minTranslate() + (swiper.maxTranslate() - swiper.minTranslate()) * positionRatio; 5486 swiper.updateProgress(position); 5487 swiper.setTranslate(position); 5488 swiper.updateActiveIndex(); 5489 swiper.updateSlidesClasses(); 5490 } 5491 function onDragStart(e) { 5492 const params = swiper.params.scrollbar; 5493 const { 5494 scrollbar, 5495 wrapperEl 5496 } = swiper; 5497 const { 5498 el, 5499 dragEl 5500 } = scrollbar; 5501 isTouched = true; 5502 dragStartPos = e.target === dragEl ? getPointerPosition(e) - e.target.getBoundingClientRect()[swiper.isHorizontal() ? 'left' : 'top'] : null; 5503 e.preventDefault(); 5504 e.stopPropagation(); 5505 wrapperEl.style.transitionDuration = '100ms'; 5506 dragEl.style.transitionDuration = '100ms'; 5507 setDragPosition(e); 5508 clearTimeout(dragTimeout); 5509 el.style.transitionDuration = '0ms'; 5510 if (params.hide) { 5511 el.style.opacity = 1; 5512 } 5513 if (swiper.params.cssMode) { 5514 swiper.wrapperEl.style['scroll-snap-type'] = 'none'; 5515 } 5516 emit('scrollbarDragStart', e); 5517 } 5518 function onDragMove(e) { 5519 const { 5520 scrollbar, 5521 wrapperEl 5522 } = swiper; 5523 const { 5524 el, 5525 dragEl 5526 } = scrollbar; 5527 if (!isTouched) return; 5528 if (e.preventDefault
vendor: 15,918 bytes, lines 5528-5983
5528) e.preventDefault();else e.returnValue = false; 5529 setDragPosition(e); 5530 wrapperEl.style.transitionDuration = '0ms'; 5531 el.style.transitionDuration = '0ms'; 5532 dragEl.style.transitionDuration = '0ms'; 5533 emit('scrollbarDragMove', e); 5534 } 5535 function onDragEnd(e) { 5536 const params = swiper.params.scrollbar; 5537 const { 5538 scrollbar, 5539 wrapperEl 5540 } = swiper; 5541 const { 5542 el 5543 } = scrollbar; 5544 if (!isTouched) return; 5545 isTouched = false; 5546 if (swiper.params.cssMode) { 5547 swiper.wrapperEl.style['scroll-snap-type'] = ''; 5548 wrapperEl.style.transitionDuration = ''; 5549 } 5550 if (params.hide) { 5551 clearTimeout(dragTimeout); 5552 dragTimeout = nextTick(() => { 5553 el.style.opacity = 0; 5554 el.style.transitionDuration = '400ms'; 5555 }, 1000); 5556 } 5557 emit('scrollbarDragEnd', e); 5558 if (params.snapOnRelease) { 5559 swiper.slideToClosest(); 5560 } 5561 } 5562 function events(method) { 5563 const { 5564 scrollbar, 5565 params 5566 } = swiper; 5567 const el = scrollbar.el; 5568 if (!el) return; 5569 const target = el; 5570 const activeListener = params.passiveListeners ? { 5571 passive: false, 5572 capture: false 5573 } : false; 5574 const passiveListener = params.passiveListeners ? { 5575 passive: true, 5576 capture: false 5577 } : false; 5578 if (!target) return; 5579 const eventMethod = method === 'on' ? 'addEventListener' : 'removeEventListener'; 5580 target[eventMethod]('pointerdown', onDragStart, activeListener); 5581 document[eventMethod]('pointermove', onDragMove, activeListener); 5582 document[eventMethod]('pointerup', onDragEnd, passiveListener); 5583 } 5584 function enableDraggable() { 5585 if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return; 5586 events('on'); 5587 } 5588 function disableDraggable() { 5589 if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return; 5590 events('off'); 5591 } 5592 function init() { 5593 const { 5594 scrollbar, 5595 el: swiperEl 5596 } = swiper; 5597 swiper.params.scrollbar = createElementIfNotDefined(swiper, swiper.originalParams.scrollbar, swiper.params.scrollbar, { 5598 el: 'swiper-scrollbar' 5599 }); 5600 const params = swiper.params.scrollbar; 5601 if (!params.el) return; 5602 let el; 5603 if (typeof params.el === 'string' && swiper.isElement) { 5604 el = swiper.el.shadowRoot.querySelector(params.el); 5605 } 5606 if (!el && typeof params.el === 'string') { 5607 el = document.querySelectorAll(params.el); 5608 } else if (!el) { 5609 el = params.el; 5610 } 5611 if (swiper.params.uniqueNavElements && typeof params.el === 'string' && el.length > 1 && swiperEl.querySelectorAll(params.el).length === 1) { 5612 el = swiperEl.querySelector(params.el); 5613 } 5614 if (el.length > 0) el = el[0]; 5615 el.classList.add(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 5616 let dragEl; 5617 if (el) { 5618 dragEl = el.querySelector(`.${swiper.params.scrollbar.dragClass}`); 5619 if (!dragEl) { 5620 dragEl = createElement('div', swiper.params.scrollbar.dragClass); 5621 el.append(dragEl); 5622 } 5623 } 5624 Object.assign(scrollbar, { 5625 el, 5626 dragEl 5627 }); 5628 if (params.draggable) { 5629 enableDraggable(); 5630 } 5631 if (el) { 5632 el.classList[swiper.enabled ? 'remove' : 'add'](swiper.params.scrollbar.lockClass); 5633 } 5634 } 5635 function destroy() { 5636 const params = swiper.params.scrollbar; 5637 const el = swiper.scrollbar.el; 5638 if (el) { 5639 el.classList.remove(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 5640 } 5641 disableDraggable(); 5642 } 5643 on('init', () => { 5644 if (swiper.params.scrollbar.enabled === false) { 5645 // eslint-disable-next-line 5646 disable(); 5647 } else { 5648 init(); 5649 updateSize(); 5650 setTranslate(); 5651 } 5652 }); 5653 on('update resize observerUpdate lock unlock', () => { 5654 updateSize(); 5655 }); 5656 on('setTranslate', () => { 5657 setTranslate(); 5658 }); 5659 on('setTransition', (_s, duration) => { 5660 setTransition(duration); 5661 }); 5662 on('enable disable', () => { 5663 const { 5664 el 5665 } = swiper.scrollbar; 5666 if (el) { 5667 el.classList[swiper.enabled ? 'remove' : 'add'](swiper.params.scrollbar.lockClass); 5668 } 5669 }); 5670 on('destroy', () => { 5671 destroy(); 5672 }); 5673 const enable = () => { 5674 swiper.el.classList.remove(swiper.params.scrollbar.scrollbarDisabledClass); 5675 if (swiper.scrollbar.el) { 5676 swiper.scrollbar.el.classList.remove(swiper.params.scrollbar.scrollbarDisabledClass); 5677 } 5678 init(); 5679 updateSize(); 5680 setTranslate(); 5681 }; 5682 const disable = () => { 5683 swiper.el.classList.add(swiper.params.scrollbar.scrollbarDisabledClass); 5684 if (swiper.scrollbar.el) { 5685 swiper.scrollbar.el.classList.add(swiper.params.scrollbar.scrollbarDisabledClass); 5686 } 5687 destroy(); 5688 }; 5689 Object.assign(swiper.scrollbar, { 5690 enable, 5691 disable, 5692 updateSize, 5693 setTranslate, 5694 init, 5695 destroy 5696 }); 5697 } 5698 5699 function Parallax(_ref) { 5700 let { 5701 swiper, 5702 extendParams, 5703 on 5704 } = _ref; 5705 extendParams({ 5706 parallax: { 5707 enabled: false 5708 } 5709 }); 5710 const setTransform = (el, progress) => { 5711 const { 5712 rtl 5713 } = swiper; 5714 const rtlFactor = rtl ? -1 : 1; 5715 const p = el.getAttribute('data-swiper-parallax') || '0'; 5716 let x = el.getAttribute('data-swiper-parallax-x'); 5717 let y = el.getAttribute('data-swiper-parallax-y'); 5718 const scale = el.getAttribute('data-swiper-parallax-scale'); 5719 const opacity = el.getAttribute('data-swiper-parallax-opacity'); 5720 const rotate = el.getAttribute('data-swiper-parallax-rotate'); 5721 if (x || y) { 5722 x = x || '0'; 5723 y = y || '0'; 5724 } else if (swiper.isHorizontal()) { 5725 x = p; 5726 y = '0'; 5727 } else { 5728 y = p; 5729 x = '0'; 5730 } 5731 if (x.indexOf('%') >= 0) { 5732 x = `${parseInt(x, 10) * progress * rtlFactor}%`; 5733 } else { 5734 x = `${x * progress * rtlFactor}px`; 5735 } 5736 if (y.indexOf('%') >= 0) { 5737 y = `${parseInt(y, 10) * progress}%`; 5738 } else { 5739 y = `${y * progress}px`; 5740 } 5741 if (typeof opacity !== 'undefined' && opacity !== null) { 5742 const currentOpacity = opacity - (opacity - 1) * (1 - Math.abs(progress)); 5743 el.style.opacity = currentOpacity; 5744 } 5745 let transform = `translate3d(${x}, ${y}, 0px)`; 5746 if (typeof scale !== 'undefined' && scale !== null) { 5747 const currentScale = scale - (scale - 1) * (1 - Math.abs(progress)); 5748 transform += ` scale(${currentScale})`; 5749 } 5750 if (rotate && typeof rotate !== 'undefined' && rotate !== null) { 5751 const currentRotate = rotate * progress * -1; 5752 transform += ` rotate(${currentRotate}deg)`; 5753 } 5754 el.style.transform = transform; 5755 }; 5756 const setTranslate = () => { 5757 const { 5758 el, 5759 slides, 5760 progress, 5761 snapGrid 5762 } = swiper; 5763 elementChildren(el, '[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').forEach(subEl => { 5764 setTransform(subEl, progress); 5765 }); 5766 slides.forEach((slideEl, slideIndex) => { 5767 let slideProgress = slideEl.progress; 5768 if (swiper.params.slidesPerGroup > 1 && swiper.params.slidesPerView !== 'auto') { 5769 slideProgress += Math.ceil(slideIndex / 2) - progress * (snapGrid.length - 1); 5770 } 5771 slideProgress = Math.min(Math.max(slideProgress, -1), 1); 5772 slideEl.querySelectorAll('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale], [data-swiper-parallax-rotate]').forEach(subEl => { 5773 setTransform(subEl, slideProgress); 5774 }); 5775 }); 5776 }; 5777 const setTransition = function (duration) { 5778 if (duration === void 0) { 5779 duration = swiper.params.speed; 5780 } 5781 const { 5782 el 5783 } = swiper; 5784 el.querySelectorAll('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').forEach(parallaxEl => { 5785 let parallaxDuration = parseInt(parallaxEl.getAttribute('data-swiper-parallax-duration'), 10) || duration; 5786 if (duration === 0) parallaxDuration = 0; 5787 parallaxEl.style.transitionDuration = `${parallaxDuration}ms`; 5788 }); 5789 }; 5790 on('beforeInit', () => { 5791 if (!swiper.params.parallax.enabled) return; 5792 swiper.params.watchSlidesProgress = true; 5793 swiper.originalParams.watchSlidesProgress = true; 5794 }); 5795 on('init', () => { 5796 if (!swiper.params.parallax.enabled) return; 5797 setTranslate(); 5798 }); 5799 on('setTranslate', () => { 5800 if (!swiper.params.parallax.enabled) return; 5801 setTranslate(); 5802 }); 5803 on('setTransition', (_swiper, duration) => { 5804 if (!swiper.params.parallax.enabled) return; 5805 setTransition(duration); 5806 }); 5807 } 5808 5809 function Zoom(_ref) { 5810 let { 5811 swiper, 5812 extendParams, 5813 on, 5814 emit 5815 } = _ref; 5816 const window = getWindow(); 5817 extendParams({ 5818 zoom: { 5819 enabled: false, 5820 maxRatio: 3, 5821 minRatio: 1, 5822 toggle: true, 5823 containerClass: 'swiper-zoom-container', 5824 zoomedSlideClass: 'swiper-slide-zoomed' 5825 } 5826 }); 5827 swiper.zoom = { 5828 enabled: false 5829 }; 5830 let currentScale = 1; 5831 let isScaling = false; 5832 let fakeGestureTouched; 5833 let fakeGestureMoved; 5834 const evCache = []; 5835 const gesture = { 5836 slideEl: undefined, 5837 slideWidth: undefined, 5838 slideHeight: undefined, 5839 imageEl: undefined, 5840 imageWrapEl: undefined, 5841 maxRatio: 3 5842 }; 5843 const image = { 5844 isTouched: undefined, 5845 isMoved: undefined, 5846 currentX: undefined, 5847 currentY: undefined, 5848 minX: undefined, 5849 minY: undefined, 5850 maxX: undefined, 5851 maxY: undefined, 5852 width: undefined, 5853 height: undefined, 5854 startX: undefined, 5855 startY: undefined, 5856 touchesStart: {}, 5857 touchesCurrent: {} 5858 }; 5859 const velocity = { 5860 x: undefined, 5861 y: undefined, 5862 prevPositionX: undefined, 5863 prevPositionY: undefined, 5864 prevTime: undefined 5865 }; 5866 let scale = 1; 5867 Object.defineProperty(swiper.zoom, 'scale', { 5868 get() { 5869 return scale; 5870 }, 5871 set(value) { 5872 if (scale !== value) { 5873 const imageEl = gesture.imageEl; 5874 const slideEl = gesture.slideEl; 5875 emit('zoomChange', value, imageEl, slideEl); 5876 } 5877 scale = value; 5878 } 5879 }); 5880 function getDistanceBetweenTouches() { 5881 if (evCache.length < 2) return 1; 5882 const x1 = evCache[0].pageX; 5883 const y1 = evCache[0].pageY; 5884 const x2 = evCache[1].pageX; 5885 const y2 = evCache[1].pageY; 5886 const distance = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2); 5887 return distance; 5888 } 5889 function getScaleOrigin() { 5890 if (evCache.length < 2) return { 5891 x: null, 5892 y: null 5893 }; 5894 const box = gesture.imageEl.getBoundingClientRect(); 5895 return [(evCache[0].pageX + (evCache[1].pageX - evCache[0].pageX) / 2 - box.x) / currentScale, (evCache[0].pageY + (evCache[1].pageY - evCache[0].pageY) / 2 - box.y) / currentScale]; 5896 } 5897 function getSlideSelector() { 5898 return swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`; 5899 } 5900 function eventWithinSlide(e) { 5901 const slideSelector = getSlideSelector(); 5902 if (e.target.matches(slideSelector)) return true; 5903 if (swiper.slides.filter(slideEl => slideEl.contains(e.target)).length > 0) return true; 5904 return false; 5905 } 5906 function eventWithinZoomContainer(e) { 5907 const selector = `.${swiper.params.zoom.containerClass}`; 5908 if (e.target.matches(selector)) return true; 5909 if ([...swiper.el.querySelectorAll(selector)].filter(containerEl => containerEl.contains(e.target)).length > 0) return true; 5910 return false; 5911 } 5912 5913 // Events 5914 function onGestureStart(e) { 5915 if (!eventWithinSlide(e)) return; 5916 const params = swiper.params.zoom; 5917 fakeGestureTouched = false; 5918 fakeGestureMoved = false; 5919 evCache.push(e); 5920 if (evCache.length < 2) { 5921 return; 5922 } 5923 fakeGestureTouched = true; 5924 gesture.scaleStart = getDistanceBetweenTouches(); 5925 if (!gesture.slideEl) { 5926 gesture.slideEl = e.target.closest(`.${swiper.params.slideClass}, swiper-slide`); 5927 if (!gesture.slideEl) gesture.slideEl = swiper.slides[swiper.activeIndex]; 5928 let imageEl = gesture.slideEl.querySelector(`.${params.containerClass}`); 5929 if (imageEl) { 5930 imageEl = imageEl.querySelectorAll('picture, img, svg, canvas, .swiper-zoom-target')[0]; 5931 } 5932 gesture.imageEl = imageEl; 5933 if (imageEl) { 5934 gesture.imageWrapEl = elementParents(gesture.imageEl, `.${params.containerClass}`)[0]; 5935 } else { 5936 gesture.imageWrapEl = undefined; 5937 } 5938 if (!gesture.imageWrapEl) { 5939 gesture.imageEl = undefined; 5940 return; 5941 } 5942 gesture.maxRatio = gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio; 5943 } 5944 if (gesture.imageEl) { 5945 const [originX, originY] = getScaleOrigin(); 5946 gesture.imageEl.style.transformOrigin = `${originX}px ${originY}px`; 5947 gesture.imageEl.style.transitionDuration = '0ms'; 5948 } 5949 isScaling = true; 5950 } 5951 function onGestureChange(e) { 5952 if (!eventWithinSlide(e)) return; 5953 const params = swiper.params.zoom; 5954 const zoom = swiper.zoom; 5955 const pointerIndex = evCache.findIndex(cachedEv => cachedEv.pointerId === e.pointerId); 5956 if (pointerIndex >= 0) evCache[pointerIndex] = e; 5957 if (evCache.length < 2) { 5958 return; 5959 } 5960 fakeGestureMoved = true; 5961 gesture.scaleMove = getDistanceBetweenTouches(); 5962 if (!gesture.imageEl) { 5963 return; 5964 } 5965 zoom.scale = gesture.scaleMove / gesture.scaleStart * currentScale; 5966 if (zoom.scale > gesture.maxRatio) { 5967 zoom.scale = gesture.maxRatio - 1 + (zoom.scale - gesture.maxRatio + 1) ** 0.5; 5968 } 5969 if (zoom.scale < params.minRatio) { 5970 zoom.scale = params.minRatio + 1 - (params.minRatio - zoom.scale + 1) ** 0.5; 5971 } 5972 gesture.imageEl.style.transform = `translate3d(0,0,0) scale(${zoom.scale})`; 5973 } 5974 function onGestureEnd(e) { 5975 if (!eventWithinSlide(e)) return; 5976 const params = swiper.params.zoom; 5977 const zoom = swiper.zoom; 5978 const pointerIndex = evCache.findIndex(cachedEv => cachedEv.pointerId === e.pointerId); 5979 if (pointerIndex >= 0) evCache.splice(pointerIndex, 1); 5980 if (!fakeGestureTouched || !fakeGestureMoved) { 5981 return; 5982 } 5983 fakeGestureTouched = false;
vendor: 4,819 bytes, lines 5984-6074
5984 fakeGestureMoved = false; 5985 if (!gesture.imageEl) return; 5986 zoom.scale = Math.max(Math.min(zoom.scale, gesture.maxRatio), params.minRatio); 5987 gesture.imageEl.style.transitionDuration = `${swiper.params.speed}ms`; 5988 gesture.imageEl.style.transform = `translate3d(0,0,0) scale(${zoom.scale})`; 5989 currentScale = zoom.scale; 5990 isScaling = false; 5991 if (zoom.scale === 1) gesture.slideEl = undefined; 5992 } 5993 function onTouchStart(e) { 5994 const device = swiper.device; 5995 if (!gesture.imageEl) return; 5996 if (image.isTouched) return; 5997 if (device.android && e.cancelable) e.preventDefault(); 5998 image.isTouched = true; 5999 image.touchesStart.x = e.pageX; 6000 image.touchesStart.y = e.pageY; 6001 } 6002 function onTouchMove(e) { 6003 if (!eventWithinSlide(e) || !eventWithinZoomContainer(e)) return; 6004 const zoom = swiper.zoom; 6005 if (!gesture.imageEl) return; 6006 swiper.allowClick = false; 6007 if (!image.isTouched || !gesture.slideEl) return; 6008 if (!image.isMoved) { 6009 image.width = gesture.imageEl.offsetWidth; 6010 image.height = gesture.imageEl.offsetHeight; 6011 image.startX = getTranslate(gesture.imageWrapEl, 'x') || 0; 6012 image.startY = getTranslate(gesture.imageWrapEl, 'y') || 0; 6013 gesture.slideWidth = gesture.slideEl.offsetWidth; 6014 gesture.slideHeight = gesture.slideEl.offsetHeight; 6015 gesture.imageWrapEl.style.transitionDuration = '0ms'; 6016 } 6017 // Define if we need image drag 6018 const scaledWidth = image.width * zoom.scale; 6019 const scaledHeight = image.height * zoom.scale; 6020 if (scaledWidth < gesture.slideWidth && scaledHeight < gesture.slideHeight) return; 6021 image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0); 6022 image.maxX = -image.minX; 6023 image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0); 6024 image.maxY = -image.minY; 6025 image.touchesCurrent.x = evCache.length > 0 ? evCache[0].pageX : e.pageX; 6026 image.touchesCurrent.y = evCache.length > 0 ? evCache[0].pageY : e.pageY; 6027 if (!image.isMoved && !isScaling) { 6028 if (swiper.isHorizontal() && (Math.floor(image.minX) === Math.floor(image.startX) && image.touchesCurrent.x < image.touchesStart.x || Math.floor(image.maxX) === Math.floor(image.startX) && image.touchesCurrent.x > image.touchesStart.x)) { 6029 image.isTouched = false; 6030 return; 6031 } 6032 if (!swiper.isHorizontal() && (Math.floor(image.minY) === Math.floor(image.startY) && image.touchesCurrent.y < image.touchesStart.y || Math.floor(image.maxY) === Math.floor(image.startY) && image.touchesCurrent.y > image.touchesStart.y)) { 6033 image.isTouched = false; 6034 return; 6035 } 6036 } 6037 if (e.cancelable) { 6038 e.preventDefault(); 6039 } 6040 e.stopPropagation(); 6041 image.isMoved = true; 6042 image.currentX = image.touchesCurrent.x - image.touchesStart.x + image.startX; 6043 image.currentY = image.touchesCurrent.y - image.touchesStart.y + image.startY; 6044 if (image.currentX < image.minX) { 6045 image.currentX = image.minX + 1 - (image.minX - image.currentX + 1) ** 0.8; 6046 } 6047 if (image.currentX > image.maxX) { 6048 image.currentX = image.maxX - 1 + (image.currentX - image.maxX + 1) ** 0.8; 6049 } 6050 if (image.currentY < image.minY) { 6051 image.currentY = image.minY + 1 - (image.minY - image.currentY + 1) ** 0.8; 6052 } 6053 if (image.currentY > image.maxY) { 6054 image.currentY = image.maxY - 1 + (image.currentY - image.maxY + 1) ** 0.8; 6055 } 6056 6057 // Velocity 6058 if (!velocity.prevPositionX) velocity.prevPositionX = image.touchesCurrent.x; 6059 if (!velocity.prevPositionY) velocity.prevPositionY = image.touchesCurrent.y; 6060 if (!velocity.prevTime) velocity.prevTime = Date.now(); 6061 velocity.x = (image.touchesCurrent.x - velocity.prevPositionX) / (Date.now() - velocity.prevTime) / 2; 6062 velocity.y = (image.touchesCurrent.y - velocity.prevPositionY) / (Date.now() - velocity.prevTime) / 2; 6063 if (Math.abs(image.touchesCurrent.x - velocity.prevPositionX) < 2) velocity.x = 0; 6064 if (Math.abs(image.touchesCurrent.y - velocity.prevPositionY) < 2) velocity.y = 0; 6065 velocity.prevPositionX = image.touchesCurrent.x; 6066 velocity.prevPositionY = image.touchesCurrent.y; 6067 velocity.prevTime = Date.now(); 6068 gesture.imageWrapEl.style.transform = `translate3d(${image.currentX}px, ${image.currentY}px,0)`; 6069 } 6070 function onTouchEnd() { 6071 const zoom = swiper.zoom; 6072 if (!gesture.imageEl) return; 6073 if (!image.isTouched || !image.isMoved) { 6074 image.isTouched = false;
vendor: 17,093 bytes, lines 6075-6512
6075 image.isMoved = false; 6076 return; 6077 } 6078 image.isTouched = false; 6079 image.isMoved = false; 6080 let momentumDurationX = 300; 6081 let momentumDurationY = 300; 6082 const momentumDistanceX = velocity.x * momentumDurationX; 6083 const newPositionX = image.currentX + momentumDistanceX; 6084 const momentumDistanceY = velocity.y * momentumDurationY; 6085 const newPositionY = image.currentY + momentumDistanceY; 6086 6087 // Fix duration 6088 if (velocity.x !== 0) momentumDurationX = Math.abs((newPositionX - image.currentX) / velocity.x); 6089 if (velocity.y !== 0) momentumDurationY = Math.abs((newPositionY - image.currentY) / velocity.y); 6090 const momentumDuration = Math.max(momentumDurationX, momentumDurationY); 6091 image.currentX = newPositionX; 6092 image.currentY = newPositionY; 6093 6094 // Define if we need image drag 6095 const scaledWidth = image.width * zoom.scale; 6096 const scaledHeight = image.height * zoom.scale; 6097 image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0); 6098 image.maxX = -image.minX; 6099 image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0); 6100 image.maxY = -image.minY; 6101 image.currentX = Math.max(Math.min(image.currentX, image.maxX), image.minX); 6102 image.currentY = Math.max(Math.min(image.currentY, image.maxY), image.minY); 6103 gesture.imageWrapEl.style.transitionDuration = `${momentumDuration}ms`; 6104 gesture.imageWrapEl.style.transform = `translate3d(${image.currentX}px, ${image.currentY}px,0)`; 6105 } 6106 function onTransitionEnd() { 6107 const zoom = swiper.zoom; 6108 if (gesture.slideEl && swiper.previousIndex !== swiper.activeIndex) { 6109 if (gesture.imageEl) { 6110 gesture.imageEl.style.transform = 'translate3d(0,0,0) scale(1)'; 6111 } 6112 if (gesture.imageWrapEl) { 6113 gesture.imageWrapEl.style.transform = 'translate3d(0,0,0)'; 6114 } 6115 zoom.scale = 1; 6116 currentScale = 1; 6117 gesture.slideEl = undefined; 6118 gesture.imageEl = undefined; 6119 gesture.imageWrapEl = undefined; 6120 } 6121 } 6122 function zoomIn(e) { 6123 const zoom = swiper.zoom; 6124 const params = swiper.params.zoom; 6125 if (!gesture.slideEl) { 6126 if (e && e.target) { 6127 gesture.slideEl = e.target.closest(`.${swiper.params.slideClass}, swiper-slide`); 6128 } 6129 if (!gesture.slideEl) { 6130 if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) { 6131 gesture.slideEl = elementChildren(swiper.slidesEl, `.${swiper.params.slideActiveClass}`)[0]; 6132 } else { 6133 gesture.slideEl = swiper.slides[swiper.activeIndex]; 6134 } 6135 } 6136 let imageEl = gesture.slideEl.querySelector(`.${params.containerClass}`); 6137 if (imageEl) { 6138 imageEl = imageEl.querySelectorAll('picture, img, svg, canvas, .swiper-zoom-target')[0]; 6139 } 6140 gesture.imageEl = imageEl; 6141 if (imageEl) { 6142 gesture.imageWrapEl = elementParents(gesture.imageEl, `.${params.containerClass}`)[0]; 6143 } else { 6144 gesture.imageWrapEl = undefined; 6145 } 6146 } 6147 if (!gesture.imageEl || !gesture.imageWrapEl) return; 6148 if (swiper.params.cssMode) { 6149 swiper.wrapperEl.style.overflow = 'hidden'; 6150 swiper.wrapperEl.style.touchAction = 'none'; 6151 } 6152 gesture.slideEl.classList.add(`${params.zoomedSlideClass}`); 6153 let touchX; 6154 let touchY; 6155 let offsetX; 6156 let offsetY; 6157 let diffX; 6158 let diffY; 6159 let translateX; 6160 let translateY; 6161 let imageWidth; 6162 let imageHeight; 6163 let scaledWidth; 6164 let scaledHeight; 6165 let translateMinX; 6166 let translateMinY; 6167 let translateMaxX; 6168 let translateMaxY; 6169 let slideWidth; 6170 let slideHeight; 6171 if (typeof image.touchesStart.x === 'undefined' && e) { 6172 touchX = e.pageX; 6173 touchY = e.pageY; 6174 } else { 6175 touchX = image.touchesStart.x; 6176 touchY = image.touchesStart.y; 6177 } 6178 const forceZoomRatio = typeof e === 'number' ? e : null; 6179 if (currentScale === 1 && forceZoomRatio) { 6180 touchX = undefined; 6181 touchY = undefined; 6182 } 6183 zoom.scale = forceZoomRatio || gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio; 6184 currentScale = forceZoomRatio || gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio; 6185 if (e && !(currentScale === 1 && forceZoomRatio)) { 6186 slideWidth = gesture.slideEl.offsetWidth; 6187 slideHeight = gesture.slideEl.offsetHeight; 6188 offsetX = elementOffset(gesture.slideEl).left + window.scrollX; 6189 offsetY = elementOffset(gesture.slideEl).top + window.scrollY; 6190 diffX = offsetX + slideWidth / 2 - touchX; 6191 diffY = offsetY + slideHeight / 2 - touchY; 6192 imageWidth = gesture.imageEl.offsetWidth; 6193 imageHeight = gesture.imageEl.offsetHeight; 6194 scaledWidth = imageWidth * zoom.scale; 6195 scaledHeight = imageHeight * zoom.scale; 6196 translateMinX = Math.min(slideWidth / 2 - scaledWidth / 2, 0); 6197 translateMinY = Math.min(slideHeight / 2 - scaledHeight / 2, 0); 6198 translateMaxX = -translateMinX; 6199 translateMaxY = -translateMinY; 6200 translateX = diffX * zoom.scale; 6201 translateY = diffY * zoom.scale; 6202 if (translateX < translateMinX) { 6203 translateX = translateMinX; 6204 } 6205 if (translateX > translateMaxX) { 6206 translateX = translateMaxX; 6207 } 6208 if (translateY < translateMinY) { 6209 translateY = translateMinY; 6210 } 6211 if (translateY > translateMaxY) { 6212 translateY = translateMaxY; 6213 } 6214 } else { 6215 translateX = 0; 6216 translateY = 0; 6217 } 6218 gesture.imageWrapEl.style.transitionDuration = '300ms'; 6219 gesture.imageWrapEl.style.transform = `translate3d(${translateX}px, ${translateY}px,0)`; 6220 gesture.imageEl.style.transitionDuration = '300ms'; 6221 gesture.imageEl.style.transform = `translate3d(0,0,0) scale(${zoom.scale})`; 6222 } 6223 function zoomOut() { 6224 const zoom = swiper.zoom; 6225 const params = swiper.params.zoom; 6226 if (!gesture.slideEl) { 6227 if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) { 6228 gesture.slideEl = elementChildren(swiper.slidesEl, `.${swiper.params.slideActiveClass}`)[0]; 6229 } else { 6230 gesture.slideEl = swiper.slides[swiper.activeIndex]; 6231 } 6232 let imageEl = gesture.slideEl.querySelector(`.${params.containerClass}`); 6233 if (imageEl) { 6234 imageEl = imageEl.querySelectorAll('picture, img, svg, canvas, .swiper-zoom-target')[0]; 6235 } 6236 gesture.imageEl = imageEl; 6237 if (imageEl) { 6238 gesture.imageWrapEl = elementParents(gesture.imageEl, `.${params.containerClass}`)[0]; 6239 } else { 6240 gesture.imageWrapEl = undefined; 6241 } 6242 } 6243 if (!gesture.imageEl || !gesture.imageWrapEl) return; 6244 if (swiper.params.cssMode) { 6245 swiper.wrapperEl.style.overflow = ''; 6246 swiper.wrapperEl.style.touchAction = ''; 6247 } 6248 zoom.scale = 1; 6249 currentScale = 1; 6250 gesture.imageWrapEl.style.transitionDuration = '300ms'; 6251 gesture.imageWrapEl.style.transform = 'translate3d(0,0,0)'; 6252 gesture.imageEl.style.transitionDuration = '300ms'; 6253 gesture.imageEl.style.transform = 'translate3d(0,0,0) scale(1)'; 6254 gesture.slideEl.classList.remove(`${params.zoomedSlideClass}`); 6255 gesture.slideEl = undefined; 6256 } 6257 6258 // Toggle Zoom 6259 function zoomToggle(e) { 6260 const zoom = swiper.zoom; 6261 if (zoom.scale && zoom.scale !== 1) { 6262 // Zoom Out 6263 zoomOut(); 6264 } else { 6265 // Zoom In 6266 zoomIn(e); 6267 } 6268 } 6269 function getListeners() { 6270 const passiveListener = swiper.params.passiveListeners ? { 6271 passive: true, 6272 capture: false 6273 } : false; 6274 const activeListenerWithCapture = swiper.params.passiveListeners ? { 6275 passive: false, 6276 capture: true 6277 } : true; 6278 return { 6279 passiveListener, 6280 activeListenerWithCapture 6281 }; 6282 } 6283 6284 // Attach/Detach Events 6285 function enable() { 6286 const zoom = swiper.zoom; 6287 if (zoom.enabled) return; 6288 zoom.enabled = true; 6289 const { 6290 passiveListener, 6291 activeListenerWithCapture 6292 } = getListeners(); 6293 6294 // Scale image 6295 6296 swiper.wrapperEl.addEventListener('pointerdown', onGestureStart, passiveListener); 6297 swiper.wrapperEl.addEventListener('pointermove', onGestureChange, activeListenerWithCapture); 6298 ['pointerup', 'pointercancel'].forEach(eventName => { 6299 swiper.wrapperEl.addEventListener(eventName, onGestureEnd, passiveListener); 6300 }); 6301 6302 // Move image 6303 swiper.wrapperEl.addEventListener('pointermove', onTouchMove, activeListenerWithCapture); 6304 } 6305 function disable() { 6306 const zoom = swiper.zoom; 6307 if (!zoom.enabled) return; 6308 zoom.enabled = false; 6309 const { 6310 passiveListener, 6311 activeListenerWithCapture 6312 } = getListeners(); 6313 6314 // Scale image 6315 swiper.wrapperEl.removeEventListener('pointerdown', onGestureStart, passiveListener); 6316 swiper.wrapperEl.removeEventListener('pointermove', onGestureChange, activeListenerWithCapture); 6317 ['pointerup', 'pointercancel'].forEach(eventName => { 6318 swiper.wrapperEl.removeEventListener(eventName, onGestureEnd, passiveListener); 6319 }); 6320 6321 // Move image 6322 swiper.wrapperEl.removeEventListener('pointermove', onTouchMove, activeListenerWithCapture); 6323 } 6324 on('init', () => { 6325 if (swiper.params.zoom.enabled) { 6326 enable(); 6327 } 6328 }); 6329 on('destroy', () => { 6330 disable(); 6331 }); 6332 on('touchStart', (_s, e) => { 6333 if (!swiper.zoom.enabled) return; 6334 onTouchStart(e); 6335 }); 6336 on('touchEnd', (_s, e) => { 6337 if (!swiper.zoom.enabled) return; 6338 onTouchEnd(); 6339 }); 6340 on('doubleTap', (_s, e) => { 6341 if (!swiper.animating && swiper.params.zoom.enabled && swiper.zoom.enabled && swiper.params.zoom.toggle) { 6342 zoomToggle(e); 6343 } 6344 }); 6345 on('transitionEnd', () => { 6346 if (swiper.zoom.enabled && swiper.params.zoom.enabled) { 6347 onTransitionEnd(); 6348 } 6349 }); 6350 on('slideChange', () => { 6351 if (swiper.zoom.enabled && swiper.params.zoom.enabled && swiper.params.cssMode) { 6352 onTransitionEnd(); 6353 } 6354 }); 6355 Object.assign(swiper.zoom, { 6356 enable, 6357 disable, 6358 in: zoomIn, 6359 out: zoomOut, 6360 toggle: zoomToggle 6361 }); 6362 } 6363 6364 /* eslint no-bitwise: ["error", { "allow": [">>"] }] */ 6365 function Controller(_ref) { 6366 let { 6367 swiper, 6368 extendParams, 6369 on 6370 } = _ref; 6371 extendParams({ 6372 controller: { 6373 control: undefined, 6374 inverse: false, 6375 by: 'slide' // or 'container' 6376 } 6377 }); 6378 6379 swiper.controller = { 6380 control: undefined 6381 }; 6382 function LinearSpline(x, y) { 6383 const binarySearch = function search() { 6384 let maxIndex; 6385 let minIndex; 6386 let guess; 6387 return (array, val) => { 6388 minIndex = -1; 6389 maxIndex = array.length; 6390 while (maxIndex - minIndex > 1) { 6391 guess = maxIndex + minIndex >> 1; 6392 if (array[guess] <= val) { 6393 minIndex = guess; 6394 } else { 6395 maxIndex = guess; 6396 } 6397 } 6398 return maxIndex; 6399 }; 6400 }(); 6401 this.x = x; 6402 this.y = y; 6403 this.lastIndex = x.length - 1; 6404 // Given an x value (x2), return the expected y2 value: 6405 // (x1,y1) is the known point before given value, 6406 // (x3,y3) is the known point after given value. 6407 let i1; 6408 let i3; 6409 this.interpolate = function interpolate(x2) { 6410 if (!x2) return 0; 6411 6412 // Get the indexes of x1 and x3 (the array indexes before and after given x2): 6413 i3 = binarySearch(this.x, x2); 6414 i1 = i3 - 1; 6415 6416 // We have our indexes i1 & i3, so we can calculate already: 6417 // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1 6418 return (x2 - this.x[i1]) * (this.y[i3] - this.y[i1]) / (this.x[i3] - this.x[i1]) + this.y[i1]; 6419 }; 6420 return this; 6421 } 6422 // xxx: for now i will just save one spline function to to 6423 function getInterpolateFunction(c) { 6424 if (!swiper.controller.spline) { 6425 swiper.controller.spline = swiper.params.loop ? new LinearSpline(swiper.slidesGrid, c.slidesGrid) : new LinearSpline(swiper.snapGrid, c.snapGrid); 6426 } 6427 } 6428 function setTranslate(_t, byController) { 6429 const controlled = swiper.controller.control; 6430 let multiplier; 6431 let controlledTranslate; 6432 const Swiper = swiper.constructor; 6433 function setControlledTranslate(c) { 6434 // this will create an Interpolate function based on the snapGrids 6435 // x is the Grid of the scrolled scroller and y will be the controlled scroller 6436 // it makes sense to create this only once and recall it for the interpolation 6437 // the function does a lot of value caching for performance 6438 const translate = swiper.rtlTranslate ? -swiper.translate : swiper.translate; 6439 if (swiper.params.controller.by === 'slide') { 6440 getInterpolateFunction(c); 6441 // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid 6442 // but it did not work out 6443 controlledTranslate = -swiper.controller.spline.interpolate(-translate); 6444 } 6445 if (!controlledTranslate || swiper.params.controller.by === 'container') { 6446 multiplier = (c.maxTranslate() - c.minTranslate()) / (swiper.maxTranslate() - swiper.minTranslate()); 6447 controlledTranslate = (translate - swiper.minTranslate()) * multiplier + c.minTranslate(); 6448 } 6449 if (swiper.params.controller.inverse) { 6450 controlledTranslate = c.maxTranslate() - controlledTranslate; 6451 } 6452 c.updateProgress(controlledTranslate); 6453 c.setTranslate(controlledTranslate, swiper); 6454 c.updateActiveIndex(); 6455 c.updateSlidesClasses(); 6456 } 6457 if (Array.isArray(controlled)) { 6458 for (let i = 0; i < controlled.length; i += 1) { 6459 if (controlled[i] !== byController && controlled[i] instanceof Swiper) { 6460 setControlledTranslate(controlled[i]); 6461 } 6462 } 6463 } else if (controlled instanceof Swiper && byController !== controlled) { 6464 setControlledTranslate(controlled); 6465 } 6466 } 6467 function setTransition(duration, byController) { 6468 const Swiper = swiper.constructor; 6469 const controlled = swiper.controller.control; 6470 let i; 6471 function setControlledTransition(c) { 6472 c.setTransition(duration, swiper); 6473 if (duration !== 0) { 6474 c.transitionStart(); 6475 if (c.params.autoHeight) { 6476 nextTick(() => { 6477 c.updateAutoHeight(); 6478 }); 6479 } 6480 elementTransitionEnd(c.wrapperEl, () => { 6481 if (!controlled) return; 6482 c.transitionEnd(); 6483 }); 6484 } 6485 } 6486 if (Array.isArray(controlled)) { 6487 for (i = 0; i < controlled.length; i += 1) { 6488 if (controlled[i] !== byController && controlled[i] instanceof Swiper) { 6489 setControlledTransition(controlled[i]); 6490 } 6491 } 6492 } else if (controlled instanceof Swiper && byController !== controlled) { 6493 setControlledTransition(controlled); 6494 } 6495 } 6496 function removeSpline() { 6497 if (!swiper.controller.control) return; 6498 if (swiper.controller.spline) { 6499 swiper.controller.spline = undefined; 6500 delete swiper.controller.spline; 6501 } 6502 } 6503 on('beforeInit', () => { 6504 if (typeof window !== 'undefined' && ( 6505 // eslint-disable-line 6506 typeof swiper.params.controller.control === 'string' || swiper.params.controller.control instanceof HTMLElement)) { 6507 const controlElement = document.querySelector(swiper.params.controller.control); 6508 if (controlElement && controlElement.swiper) { 6509 swiper.controller.control = controlElement.swiper; 6510 } else if (controlElement) { 6511 const onControllerSwiper = e => { 6512 swiper.controller.control = e.detail[0];
6513 swiper.update(); 6514 controlElement.removeEventListener('init', onControllerSwiper); 6515 }; 6516 controlElement.addEventListener('init', onControllerSwiper); 6517 } 6518 return; 6519 } 6520 swiper.controller.control = swiper.params.controller.control; 6521 }); 6522 on('update', () => { 6523 removeSpline(); 6524 }); 6525 on('resize', () => { 6526 removeSpline(); 6527 }); 6528 on('observerUpdate', () => { 6529 removeSpline(); 6530 }); 6531 on('setTranslate', (_s, translate, byController) => { 6532 if (!swiper.controller.control) return; 6533 swiper.controller.setTranslate(translate, byController); 6534 }); 6535 on('setTransition', (_s, duration, byController) => { 6536 if (!swiper.controller.control) return; 6537 swiper.controller.setTransition(duration, byController); 6538 }); 6539 Object.assign(swiper.controller, { 6540 setTranslate, 6541 setTransition 6542 }); 6543 } 6544 6545 function A11y(_ref) { 6546 let { 6547 swiper, 6548 extendParams, 6549 on 6550 } = _ref; 6551 extendParams({ 6552 a11y: { 6553 enabled: true, 6554 notificationClass: 'swiper-notification', 6555 prevSlideMessage: 'Previous slide', 6556 nextSlideMessage: 'Next slide', 6557 firstSlideMessage: 'This is the first slide', 6558 lastSlideMessage: 'This is the last slide', 6559 paginationBulletMessage: 'Go to slide {{index}}', 6560 slideLabelMessage: '{{index}} / {{slidesLength}}', 6561 containerMessage: null, 6562 containerRoleDescriptionMessage: null, 6563 itemRoleDescriptionMessage: null, 6564 slideRole: 'group', 6565 id: null 6566 } 6567 }); 6568 swiper.a11y = { 6569 clicked: false 6570 }; 6571 let liveRegion = null; 6572 function notify(message) { 6573 const notification = liveRegion; 6574 if (notification.length === 0) return; 6575 notification.innerHTML = ''; 6576 notification.innerHTML = message; 6577 } 6578 const makeElementsArray = el => { 6579 if (!Array.isArray(el)) el = [el].filter(e => !!e); 6580 return el; 6581 }; 6582 function getRandomNumber(size) { 6583 if (size === void 0) { 6584 size = 16; 6585 } 6586 const randomChar = () => Math.round(16 * Math.random()).toString(16); 6587 return 'x'.repeat(size).replace(/x/g, randomChar); 6588 } 6589 function makeElFocusable(el) { 6590 el = makeElementsArray(el); 6591 el.forEach(subEl => { 6592 subEl.setAttribute('tabIndex', '0'); 6593 }); 6594 } 6595 function makeElNotFocusable(el) { 6596 el = makeElementsArray(el); 6597 el.forEach(subEl => { 6598 subEl.setAttribute('tabIndex', '-1'); 6599 }); 6600 } 6601 function addElRole(el, role) { 6602 el = makeElementsArray(el); 6603 el.forEach(subEl => { 6604 subEl.setAttribute('role', role); 6605 }); 6606 } 6607 function addElRoleDescription(el, description) { 6608 el = makeElementsArray(el); 6609 el.forEach(subEl => { 6610 subEl.setAttribute('aria-roledescription', description); 6611 }); 6612 } 6613 function addElControls(el, controls) { 6614 el = makeElementsArray(el); 6615 el.forEach(subEl => { 6616 subEl.setAttribute('aria-controls', controls); 6617 }); 6618 } 6619 function addElLabel(el, label) { 6620 el = makeElementsArray(el); 6621 el.forEach(subEl => { 6622 subEl.setAttribute('aria-label', label); 6623 }); 6624 } 6625 function addElId(el, id) { 6626 el = makeElementsArray(el); 6627 el.forEach(subEl => { 6628 subEl.setAttribute('id', id); 6629 }); 6630 } 6631 function addElLive(el, live) { 6632 el = makeElementsArray(el); 6633 el.forEach(subEl => { 6634 subEl.setAttribute('aria-live', live); 6635 }); 6636 } 6637 function disableEl(el) { 6638 el = makeElementsArray(el); 6639 el.forEach(subEl => { 6640 subEl.setAttribute('aria-disabled', true); 6641 }); 6642 } 6643 function enableEl(el) { 6644 el = makeElementsArray(el); 6645 el.forEach(subEl => { 6646 subEl.setAttribute('aria-disabled', false); 6647 }); 6648 } 6649 function onEnterOrSpaceKey(e) { 6650 if (e.keyCode !== 13 && e.keyCode !== 32) return; 6651 const params = swiper.params.a11y; 6652 const targetEl = e.target; 6653 if (swiper.pagination && swiper.pagination.el && (targetEl === swiper.pagination.el || swiper.pagination.el.contains(e.target))) { 6654 if (!e.target.matches(classesToSelector(swiper.params.pagination.bulletClass))) return; 6655 } 6656 if (swiper.navigation && swiper.navigation.nextEl && targetEl === swiper.navigation.nextEl) { 6657 if (!(swiper.isEnd && !swiper.params.loop)) { 6658 swiper.slideNext(); 6659 } 6660 if (swiper.isEnd) { 6661 notify(params.lastSlideMessage); 6662 } else { 6663 notify(params.nextSlideMessage); 6664 } 6665 } 6666 if (swiper.navigation && swiper.navigation.prevEl && targetEl === swiper.navigation.prevEl) { 6667 if (!(swiper.isBeginning && !swiper.params.loop)) { 6668 swiper.slidePrev(); 6669 } 6670 if (swiper.isBeginning) { 6671 notify(params.firstSlideMessage); 6672 } else { 6673 notify(params.prevSlideMessage); 6674 } 6675 } 6676 if (swiper.pagination && targetEl.matches(classesToSelector(swiper.params.pagination.bulletClass))) { 6677 targetEl.click(); 6678 } 6679 } 6680 function updateNavigation() { 6681 if (swiper.params.loop || swiper.params.rewind || !swiper.navigation) return; 6682 const { 6683 nextEl, 6684 prevEl 6685 } = swiper.navigation; 6686 if (prevEl) { 6687 if (swiper.isBeginning) { 6688 disableEl(prevEl); 6689 makeElNotFocusable(prevEl); 6690 } else { 6691 enableEl(prevEl); 6692 makeElFocusable(prevEl); 6693 } 6694 } 6695 if (nextEl) { 6696 if (swiper.isEnd) { 6697 disableEl(nextEl); 6698 makeElNotFocusable(nextEl); 6699 } else { 6700 enableEl(nextEl); 6701 makeElFocusable(nextEl); 6702 } 6703 } 6704 } 6705 function hasPagination() { 6706 return swiper.pagination && swiper.pagination.bullets && swiper.pagination.bullets.length; 6707 } 6708 function hasClickablePagination() { 6709 return hasPagination() && swiper.params.pagination.clickable; 6710 } 6711 function updatePagination() { 6712 const params = swiper.params.a11y; 6713 if (!hasPagination()) return;
6714 swiper.pagination.bullets.forEach(bulletEl => { 6715 if (swiper.params.pagination.clickable) { 6716 makeElFocusable(bulletEl); 6717 if (!swiper.params.pagination.renderBullet) { 6718 addElRole(bulletEl, 'button'); 6719 addElLabel(bulletEl, params.paginationBulletMessage.replace(/\{\{index\}\}/, elementIndex(bulletEl) + 1)); 6720 } 6721 } 6722 if (bulletEl.matches(`.${swiper.params.pagination.bulletActiveClass}`)) { 6723 bulletEl.setAttribute('aria-current', 'true'); 6724 } else { 6725 bulletEl.removeAttribute('aria-current'); 6726 } 6727 }); 6728 } 6729 const initNavEl = (el, wrapperId, message) => { 6730 makeElFocusable(el); 6731 if (el.tagName !== 'BUTTON') { 6732 addElRole(el, 'button'); 6733 el.addEventListener('keydown', onEnterOrSpaceKey); 6734 } 6735 addElLabel(el, message); 6736 addElControls(el, wrapperId); 6737 }; 6738 const handlePointerDown = () => { 6739 swiper.a11y.clicked = true; 6740 }; 6741 const handlePointerUp = () => { 6742 requestAnimationFrame(() => { 6743 requestAnimationFrame(() => { 6744 if (!swiper.destroyed) { 6745 swiper.a11y.clicked = false; 6746 } 6747 }); 6748 }); 6749 }; 6750 const handleFocus = e => { 6751 if (swiper.a11y.clicked) return; 6752 const slideEl = e.target.closest(`.${swiper.params.slideClass}, swiper-slide`); 6753 if (!slideEl || !swiper.slides.includes(slideEl)) return; 6754 const isActive = swiper.slides.indexOf(slideEl) === swiper.activeIndex; 6755 const isVisible = swiper.params.watchSlidesProgress && swiper.visibleSlides && swiper.visibleSlides.includes(slideEl); 6756 if (isActive || isVisible) return; 6757 if (e.sourceCapabilities && e.sourceCapabilities.firesTouchEvents) return; 6758 if (swiper.isHorizontal()) { 6759 swiper.el.scrollLeft = 0; 6760 } else { 6761 swiper.el.scrollTop = 0; 6762 } 6763 swiper.slideTo(swiper.slides.indexOf(slideEl), 0); 6764 }; 6765 const initSlides = () => { 6766 const params = swiper.params.a11y; 6767 if (params.itemRoleDescriptionMessage) { 6768 addElRoleDescription(swiper.slides, params.itemRoleDescriptionMessage); 6769 } 6770 if (params.slideRole) { 6771 addElRole(swiper.slides, params.slideRole); 6772 } 6773 const slidesLength = swiper.slides.length; 6774 if (params.slideLabelMessage) { 6775 swiper.slides.forEach((slideEl, index) => { 6776 const slideIndex = swiper.params.loop ? parseInt(slideEl.getAttribute('data-swiper-slide-index'), 10) : index; 6777 const ariaLabelMessage = params.slideLabelMessage.replace(/\{\{index\}\}/, slideIndex + 1).replace(/\{\{slidesLength\}\}/, slidesLength); 6778 addElLabel(slideEl, ariaLabelMessage); 6779 }); 6780 } 6781 }; 6782 const init = () => { 6783 const params = swiper.params.a11y; 6784 swiper.el.append(liveRegion); 6785 6786 // Container 6787 const containerEl = swiper.el; 6788 if (params.containerRoleDescriptionMessage) { 6789 addElRoleDescription(containerEl, params.containerRoleDescriptionMessage); 6790 } 6791 if (params.containerMessage) { 6792 addElLabel(containerEl, params.containerMessage); 6793 } 6794 6795 // Wrapper 6796 const wrapperEl = swiper.wrapperEl; 6797 const wrapperId = params.id || wrapperEl.getAttribute('id') || `swiper-wrapper-${getRandomNumber(16)}`; 6798 const live = swiper.params.autoplay && swiper.params.autoplay.enabled ? 'off' : 'polite'; 6799 addElId(wrapperEl, wrapperId); 6800 addElLive(wrapperEl, live); 6801 6802 // Slide 6803 initSlides(); 6804 6805 // Navigation 6806 let { 6807 nextEl, 6808 prevEl 6809 } = swiper.navigation ? swiper.navigation : {}; 6810 nextEl = makeElementsArray(nextEl); 6811 prevEl = makeElementsArray(prevEl); 6812 if (nextEl) { 6813 nextEl.forEach(el => initNavEl(el, wrapperId, params.nextSlideMessage)); 6814 } 6815 if (prevEl) { 6816 prevEl.forEach(el => initNavEl(el, wrapperId, params.prevSlideMessage)); 6817 } 6818 6819 // Pagination 6820 if (hasClickablePagination()) { 6821 const paginationEl = Array.isArray(swiper.pagination.el) ? swiper.pagination.el : [swiper.pagination.el]; 6822 paginationEl.forEach(el => { 6823 el.addEventListener('keydown', onEnterOrSpaceKey); 6824 }); 6825 } 6826 6827 // Tab focus 6828 swiper.el.addEventListener('focus', handleFocus, true); 6829 swiper.el.addEventListener('pointerdown', handlePointerDown, true); 6830 swiper.el.addEventListener('pointerup', handlePointerUp, true); 6831 }; 6832 function destroy() { 6833 if (liveRegion && liveRegion.length > 0) liveRegion.remove(); 6834 let { 6835 nextEl, 6836 prevEl 6837 } = swiper.navigation ? swiper.navigation : {}; 6838 nextEl = makeElementsArray(nextEl); 6839 prevEl = makeElementsArray(prevEl); 6840 if (nextEl) { 6841 nextEl.forEach(el => el.removeEventListener('keydown', onEnterOrSpaceKey)); 6842 } 6843 if (prevEl) { 6844 prevEl.forEach(el => el.removeEventListener('keydown', onEnterOrSpaceKey)); 6845 } 6846 6847 // Pagination 6848 if (hasClickablePagination()) { 6849 const paginationEl = Array.isArray(swiper.pagination.el) ? swiper.pagination.el : [swiper.pagination.el]; 6850 paginationEl.forEach(el => { 6851 el.removeEventListener('keydown', onEnterOrSpaceKey); 6852 }); 6853 } 6854 6855 // Tab focus 6856 swiper.el.removeEventListener('focus', handleFocus, true); 6857 swiper.el.removeEventListener('pointerdown', handlePointerDown, true); 6858 swiper.el.removeEventListener('pointerup', handlePointerUp, true); 6859 } 6860 on('beforeInit', () => { 6861 liveRegion = createElement('span', swiper.params.a11y.notificationClass); 6862 liveRegion.setAttribute('aria-live', 'assertive'); 6863 liveRegion.setAttribute('aria-atomic', 'true'); 6864 if (swiper.isElement) { 6865 liveRegion.setAttribute('slot', 'container-end'); 6866 } 6867 }); 6868 on('afterInit', () => { 6869 if (!swiper.params.a11y.enabled) return; 6870 init(); 6871 }); 6872 on('slidesLengthChange snapGridLengthChange slidesGridLengthChange', () => { 6873 if (!swiper.params.a11y.enabled) return; 6874 initSlides(); 6875 }); 6876 on('fromEdge toEdge afterInit lock unlock', () => { 6877 if (!swiper.params.a11y.enabled) return; 6878 updateNavigation(); 6879 }); 6880 on('paginationUpdate', () => { 6881 if (!swiper.params.a11y.enabled) return; 6882 updatePagination(); 6883 }); 6884 on('destroy', () => { 6885 if (!swiper.params.a11y.enabled) return; 6886 destroy(); 6887 }); 6888 } 6889 6890 function History(_ref) { 6891 let { 6892 swiper, 6893 extendParams, 6894 on 6895 } = _ref; 6896 extendParams({ 6897 history: { 6898 enabled: false, 6899 root: '', 6900 replaceState: false, 6901 key: 'slides', 6902 keepQuery: false 6903 } 6904 }); 6905 let initialized = false;
vendor: 4,442 bytes, lines 6906-7036
6906 let paths = {}; 6907 const slugify = text => { 6908 return text.toString().replace(/\s+/g, '-').replace(/[^\w-]+/g, '').replace(/--+/g, '-').replace(/^-+/, '').replace(/-+$/, ''); 6909 }; 6910 const getPathValues = urlOverride => { 6911 const window = getWindow(); 6912 let location; 6913 if (urlOverride) { 6914 location = new URL(urlOverride); 6915 } else { 6916 location = window.location; 6917 } 6918 const pathArray = location.pathname.slice(1).split('/').filter(part => part !== ''); 6919 const total = pathArray.length; 6920 const key = pathArray[total - 2]; 6921 const value = pathArray[total - 1]; 6922 return { 6923 key, 6924 value 6925 }; 6926 }; 6927 const setHistory = (key, index) => { 6928 const window = getWindow(); 6929 if (!initialized || !swiper.params.history.enabled) return; 6930 let location; 6931 if (swiper.params.url) { 6932 location = new URL(swiper.params.url); 6933 } else { 6934 location = window.location; 6935 } 6936 const slide = swiper.slides[index]; 6937 let value = slugify(slide.getAttribute('data-history')); 6938 if (swiper.params.history.root.length > 0) { 6939 let root = swiper.params.history.root; 6940 if (root[root.length - 1] === '/') root = root.slice(0, root.length - 1); 6941 value = `${root}/${key ? `${key}/` : ''}${value}`; 6942 } else if (!location.pathname.includes(key)) { 6943 value = `${key ? `${key}/` : ''}${value}`; 6944 } 6945 if (swiper.params.history.keepQuery) { 6946 value += location.search; 6947 } 6948 const currentState = window.history.state; 6949 if (currentState && currentState.value === value) { 6950 return; 6951 } 6952 if (swiper.params.history.replaceState) { 6953 window.history.replaceState({ 6954 value 6955 }, null, value); 6956 } else { 6957 window.history.pushState({ 6958 value 6959 }, null, value); 6960 } 6961 }; 6962 const scrollToSlide = (speed, value, runCallbacks) => { 6963 if (value) { 6964 for (let i = 0, length = swiper.slides.length; i < length; i += 1) { 6965 const slide = swiper.slides[i]; 6966 const slideHistory = slugify(slide.getAttribute('data-history')); 6967 if (slideHistory === value) { 6968 const index = elementIndex(slide); 6969 swiper.slideTo(index, speed, runCallbacks); 6970 } 6971 } 6972 } else { 6973 swiper.slideTo(0, speed, runCallbacks); 6974 } 6975 }; 6976 const setHistoryPopState = () => { 6977 paths = getPathValues(swiper.params.url); 6978 scrollToSlide(swiper.params.speed, paths.value, false); 6979 }; 6980 const init = () => { 6981 const window = getWindow(); 6982 if (!swiper.params.history) return; 6983 if (!window.history || !window.history.pushState) { 6984 swiper.params.history.enabled = false; 6985 swiper.params.hashNavigation.enabled = true; 6986 return; 6987 } 6988 initialized = true; 6989 paths = getPathValues(swiper.params.url); 6990 if (!paths.key && !paths.value) { 6991 if (!swiper.params.history.replaceState) { 6992 window.addEventListener('popstate', setHistoryPopState); 6993 } 6994 return; 6995 } 6996 scrollToSlide(0, paths.value, swiper.params.runCallbacksOnInit); 6997 if (!swiper.params.history.replaceState) { 6998 window.addEventListener('popstate', setHistoryPopState); 6999 } 7000 }; 7001 const destroy = () => { 7002 const window = getWindow(); 7003 if (!swiper.params.history.replaceState) { 7004 window.removeEventListener('popstate', setHistoryPopState); 7005 } 7006 }; 7007 on('init', () => { 7008 if (swiper.params.history.enabled) { 7009 init(); 7010 } 7011 }); 7012 on('destroy', () => { 7013 if (swiper.params.history.enabled) { 7014 destroy(); 7015 } 7016 }); 7017 on('transitionEnd _freeModeNoMomentumRelease', () => { 7018 if (initialized) { 7019 setHistory(swiper.params.history.key, swiper.activeIndex); 7020 } 7021 }); 7022 on('slideChange', () => { 7023 if (initialized && swiper.params.cssMode) { 7024 setHistory(swiper.params.history.key, swiper.activeIndex); 7025 } 7026 }); 7027 } 7028 7029 function HashNavigation(_ref) { 7030 let { 7031 swiper, 7032 extendParams, 7033 emit, 7034 on 7035 } = _ref; 7036 let initialized = false;
7037 const document = getDocument(); 7038 const window = getWindow(); 7039 extendParams({ 7040 hashNavigation: { 7041 enabled: false, 7042 replaceState: false, 7043 watchState: false 7044 } 7045 }); 7046 const onHashChange = () => { 7047 emit('hashChange'); 7048 const newHash = document.location.hash.replace('#', ''); 7049 const activeSlideHash = swiper.slides[swiper.activeIndex].getAttribute('data-hash'); 7050 if (newHash !== activeSlideHash) { 7051 const newIndex = elementIndex(elementChildren(swiper.slidesEl, `.${swiper.params.slideClass}[data-hash="${newHash}"], swiper-slide[data-hash="${newHash}"]`)[0]); 7052 if (typeof newIndex === 'undefined') return; 7053 swiper.slideTo(newIndex); 7054 } 7055 }; 7056 const setHash = () => { 7057 if (!initialized || !swiper.params.hashNavigation.enabled) return; 7058 if (swiper.params.hashNavigation.replaceState && window.history && window.history.replaceState) { 7059 window.history.replaceState(null, null, `#${swiper.slides[swiper.activeIndex].getAttribute('data-hash')}` || ''); 7060 emit('hashSet'); 7061 } else { 7062 const slide = swiper.slides[swiper.activeIndex]; 7063 const hash = slide.getAttribute('data-hash') || slide.getAttribute('data-history'); 7064 document.location.hash = hash || ''; 7065 emit('hashSet'); 7066 } 7067 }; 7068 const init = () => { 7069 if (!swiper.params.hashNavigation.enabled || swiper.params.history && swiper.params.history.enabled) return; 7070 initialized = true; 7071 const hash = document.location.hash.replace('#', ''); 7072 if (hash) { 7073 const speed = 0; 7074 for (let i = 0, length = swiper.slides.length; i < length; i += 1) { 7075 const slide = swiper.slides[i]; 7076 const slideHash = slide.getAttribute('data-hash') || slide.getAttribute('data-history'); 7077 if (slideHash === hash) { 7078 const index = elementIndex(slide); 7079 swiper.slideTo(index, speed, swiper.params.runCallbacksOnInit, true); 7080 } 7081 } 7082 } 7083 if (swiper.params.hashNavigation.watchState) { 7084 window.addEventListener('hashchange', onHashChange); 7085 } 7086 }; 7087 const destroy = () => { 7088 if (swiper.params.hashNavigation.watchState) { 7089 window.removeEventListener('hashchange', onHashChange); 7090 } 7091 }; 7092 on('init', () => { 7093 if (swiper.params.hashNavigation.enabled) { 7094 init(); 7095 } 7096 }); 7097 on('destroy', () => { 7098 if (swiper.params.hashNavigation.enabled) { 7099 destroy(); 7100 } 7101 }); 7102 on('transitionEnd _freeModeNoMomentumRelease', () => { 7103 if (initialized) { 7104 setHash(); 7105 } 7106 }); 7107 on('slideChange', () => { 7108 if (initialized && swiper.params.cssMode) { 7109 setHash(); 7110 } 7111 }); 7112 } 7113 7114 /* eslint no-underscore-dangle: "off" */ 7115 function Autoplay(_ref) { 7116 let { 7117 swiper, 7118 extendParams, 7119 on, 7120 emit, 7121 params 7122 } = _ref; 7123 swiper.autoplay = { 7124 running: false, 7125 paused: false, 7126 timeLeft: 0 7127 }; 7128 extendParams({ 7129 autoplay: { 7130 enabled: false, 7131 delay: 3000, 7132 waitForTransition: true, 7133 disableOnInteraction: true, 7134 stopOnLastSlide: false, 7135 reverseDirection: false, 7136 pauseOnMouseEnter: false 7137 } 7138 }); 7139 let timeout; 7140 let raf; 7141 let autoplayDelayTotal = params && params.autoplay ? params.autoplay.delay : 3000; 7142 let autoplayDelayCurrent = params && params.autoplay ? params.autoplay.delay : 3000; 7143 let autoplayTimeLeft; 7144 let autoplayStartTime = new Date().getTime; 7145 let wasPaused; 7146 let isTouched; 7147 let pausedByTouch; 7148 let touchStartTimeout; 7149 let slideChanged; 7150 let pausedByInteraction; 7151 function onTransitionEnd(e) { 7152 if (!swiper || swiper.destroyed || !swiper.wrapperEl) return; 7153 if (e.target !== swiper.wrapperEl) return; 7154 swiper.wrapperEl.removeEventListener('transitionend', onTransitionEnd); 7155 resume(); 7156 } 7157 const calcTimeLeft = () => { 7158 if (swiper.destroyed || !swiper.autoplay.running) return; 7159 if (swiper.autoplay.paused) { 7160 wasPaused = true; 7161 } else if (wasPaused) { 7162 autoplayDelayCurrent = autoplayTimeLeft; 7163 wasPaused = false;
vendor: 4,615 bytes, lines 7164-7282
7164 } 7165 const timeLeft = swiper.autoplay.paused ? autoplayTimeLeft : autoplayStartTime + autoplayDelayCurrent - new Date().getTime(); 7166 swiper.autoplay.timeLeft = timeLeft; 7167 emit('autoplayTimeLeft', timeLeft, timeLeft / autoplayDelayTotal); 7168 raf = requestAnimationFrame(() => { 7169 calcTimeLeft(); 7170 }); 7171 }; 7172 const getSlideDelay = () => { 7173 let activeSlideEl; 7174 if (swiper.virtual && swiper.params.virtual.enabled) { 7175 activeSlideEl = swiper.slides.filter(slideEl => slideEl.classList.contains('swiper-slide-active'))[0]; 7176 } else { 7177 activeSlideEl = swiper.slides[swiper.activeIndex]; 7178 } 7179 if (!activeSlideEl) return undefined; 7180 const currentSlideDelay = parseInt(activeSlideEl.getAttribute('data-swiper-autoplay'), 10); 7181 return currentSlideDelay; 7182 }; 7183 const run = delayForce => { 7184 if (swiper.destroyed || !swiper.autoplay.running) return; 7185 cancelAnimationFrame(raf); 7186 calcTimeLeft(); 7187 let delay = typeof delayForce === 'undefined' ? swiper.params.autoplay.delay : delayForce; 7188 autoplayDelayTotal = swiper.params.autoplay.delay; 7189 autoplayDelayCurrent = swiper.params.autoplay.delay; 7190 const currentSlideDelay = getSlideDelay(); 7191 if (!Number.isNaN(currentSlideDelay) && currentSlideDelay > 0 && typeof delayForce === 'undefined') { 7192 delay = currentSlideDelay; 7193 autoplayDelayTotal = currentSlideDelay; 7194 autoplayDelayCurrent = currentSlideDelay; 7195 } 7196 autoplayTimeLeft = delay; 7197 const speed = swiper.params.speed; 7198 const proceed = () => { 7199 if (!swiper || swiper.destroyed) return; 7200 if (swiper.params.autoplay.reverseDirection) { 7201 if (!swiper.isBeginning || swiper.params.loop || swiper.params.rewind) { 7202 swiper.slidePrev(speed, true, true); 7203 emit('autoplay'); 7204 } else if (!swiper.params.autoplay.stopOnLastSlide) { 7205 swiper.slideTo(swiper.slides.length - 1, speed, true, true); 7206 emit('autoplay'); 7207 } 7208 } else { 7209 if (!swiper.isEnd || swiper.params.loop || swiper.params.rewind) { 7210 swiper.slideNext(speed, true, true); 7211 emit('autoplay'); 7212 } else if (!swiper.params.autoplay.stopOnLastSlide) { 7213 swiper.slideTo(0, speed, true, true); 7214 emit('autoplay'); 7215 } 7216 } 7217 if (swiper.params.cssMode) { 7218 autoplayStartTime = new Date().getTime(); 7219 requestAnimationFrame(() => { 7220 run(); 7221 }); 7222 } 7223 }; 7224 if (delay > 0) { 7225 clearTimeout(timeout); 7226 timeout = setTimeout(() => { 7227 proceed(); 7228 }, delay); 7229 } else { 7230 requestAnimationFrame(() => { 7231 proceed(); 7232 }); 7233 } 7234 7235 // eslint-disable-next-line 7236 return delay; 7237 }; 7238 const start = () => { 7239 swiper.autoplay.running = true; 7240 run(); 7241 emit('autoplayStart'); 7242 }; 7243 const stop = () => { 7244 swiper.autoplay.running = false; 7245 clearTimeout(timeout); 7246 cancelAnimationFrame(raf); 7247 emit('autoplayStop'); 7248 }; 7249 const pause = (internal, reset) => { 7250 if (swiper.destroyed || !swiper.autoplay.running) return; 7251 clearTimeout(timeout); 7252 if (!internal) { 7253 pausedByInteraction = true; 7254 } 7255 const proceed = () => { 7256 emit('autoplayPause'); 7257 if (swiper.params.autoplay.waitForTransition) { 7258 swiper.wrapperEl.addEventListener('transitionend', onTransitionEnd); 7259 } else { 7260 resume(); 7261 } 7262 }; 7263 swiper.autoplay.paused = true; 7264 if (reset) { 7265 if (slideChanged) { 7266 autoplayTimeLeft = swiper.params.autoplay.delay; 7267 } 7268 slideChanged = false; 7269 proceed(); 7270 return; 7271 } 7272 const delay = autoplayTimeLeft || swiper.params.autoplay.delay; 7273 autoplayTimeLeft = delay - (new Date().getTime() - autoplayStartTime); 7274 if (swiper.isEnd && autoplayTimeLeft < 0 && !swiper.params.loop) return; 7275 if (autoplayTimeLeft < 0) autoplayTimeLeft = 0; 7276 proceed(); 7277 }; 7278 const resume = () => { 7279 if (swiper.isEnd && autoplayTimeLeft < 0 && !swiper.params.loop || swiper.destroyed || !swiper.autoplay.running) return; 7280 autoplayStartTime = new Date().getTime(); 7281 if (pausedByInteraction) { 7282 pausedByInteraction = false;
vendor: 11,567 bytes, lines 7283-7595
7283 run(autoplayTimeLeft); 7284 } else { 7285 run(); 7286 } 7287 swiper.autoplay.paused = false; 7288 emit('autoplayResume'); 7289 }; 7290 const onVisibilityChange = () => { 7291 if (swiper.destroyed || !swiper.autoplay.running) return; 7292 const document = getDocument(); 7293 if (document.visibilityState === 'hidden') { 7294 pausedByInteraction = true; 7295 pause(true); 7296 } 7297 if (document.visibilityState === 'visible') { 7298 resume(); 7299 } 7300 }; 7301 const onPointerEnter = e => { 7302 if (e.pointerType !== 'mouse') return; 7303 pausedByInteraction = true; 7304 pause(true); 7305 }; 7306 const onPointerLeave = e => { 7307 if (e.pointerType !== 'mouse') return; 7308 if (swiper.autoplay.paused) { 7309 resume(); 7310 } 7311 }; 7312 const attachMouseEvents = () => { 7313 if (swiper.params.autoplay.pauseOnMouseEnter) { 7314 swiper.el.addEventListener('pointerenter', onPointerEnter); 7315 swiper.el.addEventListener('pointerleave', onPointerLeave); 7316 } 7317 }; 7318 const detachMouseEvents = () => { 7319 swiper.el.removeEventListener('pointerenter', onPointerEnter); 7320 swiper.el.removeEventListener('pointerleave', onPointerLeave); 7321 }; 7322 const attachDocumentEvents = () => { 7323 const document = getDocument(); 7324 document.addEventListener('visibilitychange', onVisibilityChange); 7325 }; 7326 const detachDocumentEvents = () => { 7327 const document = getDocument(); 7328 document.removeEventListener('visibilitychange', onVisibilityChange); 7329 }; 7330 on('init', () => { 7331 if (swiper.params.autoplay.enabled) { 7332 attachMouseEvents(); 7333 attachDocumentEvents(); 7334 autoplayStartTime = new Date().getTime(); 7335 start(); 7336 } 7337 }); 7338 on('destroy', () => { 7339 detachMouseEvents(); 7340 detachDocumentEvents(); 7341 if (swiper.autoplay.running) { 7342 stop(); 7343 } 7344 }); 7345 on('beforeTransitionStart', (_s, speed, internal) => { 7346 if (swiper.destroyed || !swiper.autoplay.running) return; 7347 if (internal || !swiper.params.autoplay.disableOnInteraction) { 7348 pause(true, true); 7349 } else { 7350 stop(); 7351 } 7352 }); 7353 on('sliderFirstMove', () => { 7354 if (swiper.destroyed || !swiper.autoplay.running) return; 7355 if (swiper.params.autoplay.disableOnInteraction) { 7356 stop(); 7357 return; 7358 } 7359 isTouched = true; 7360 pausedByTouch = false; 7361 pausedByInteraction = false; 7362 touchStartTimeout = setTimeout(() => { 7363 pausedByInteraction = true; 7364 pausedByTouch = true; 7365 pause(true); 7366 }, 200); 7367 }); 7368 on('touchEnd', () => { 7369 if (swiper.destroyed || !swiper.autoplay.running || !isTouched) return; 7370 clearTimeout(touchStartTimeout); 7371 clearTimeout(timeout); 7372 if (swiper.params.autoplay.disableOnInteraction) { 7373 pausedByTouch = false; 7374 isTouched = false; 7375 return; 7376 } 7377 if (pausedByTouch && swiper.params.cssMode) resume(); 7378 pausedByTouch = false; 7379 isTouched = false; 7380 }); 7381 on('slideChange', () => { 7382 if (swiper.destroyed || !swiper.autoplay.running) return; 7383 slideChanged = true; 7384 }); 7385 Object.assign(swiper.autoplay, { 7386 start, 7387 stop, 7388 pause, 7389 resume 7390 }); 7391 } 7392 7393 function Thumb(_ref) { 7394 let { 7395 swiper, 7396 extendParams, 7397 on 7398 } = _ref; 7399 extendParams({ 7400 thumbs: { 7401 swiper: null, 7402 multipleActiveThumbs: true, 7403 autoScrollOffset: 0, 7404 slideThumbActiveClass: 'swiper-slide-thumb-active', 7405 thumbsContainerClass: 'swiper-thumbs' 7406 } 7407 }); 7408 let initialized = false; 7409 let swiperCreated = false; 7410 swiper.thumbs = { 7411 swiper: null 7412 }; 7413 function onThumbClick() { 7414 const thumbsSwiper = swiper.thumbs.swiper; 7415 if (!thumbsSwiper || thumbsSwiper.destroyed) return; 7416 const clickedIndex = thumbsSwiper.clickedIndex; 7417 const clickedSlide = thumbsSwiper.clickedSlide; 7418 if (clickedSlide && clickedSlide.classList.contains(swiper.params.thumbs.slideThumbActiveClass)) return; 7419 if (typeof clickedIndex === 'undefined' || clickedIndex === null) return; 7420 let slideToIndex; 7421 if (thumbsSwiper.params.loop) { 7422 slideToIndex = parseInt(thumbsSwiper.clickedSlide.getAttribute('data-swiper-slide-index'), 10); 7423 } else { 7424 slideToIndex = clickedIndex; 7425 } 7426 if (swiper.params.loop) { 7427 swiper.slideToLoop(slideToIndex); 7428 } else { 7429 swiper.slideTo(slideToIndex); 7430 } 7431 } 7432 function init() { 7433 const { 7434 thumbs: thumbsParams 7435 } = swiper.params; 7436 if (initialized) return false; 7437 initialized = true; 7438 const SwiperClass = swiper.constructor; 7439 if (thumbsParams.swiper instanceof SwiperClass) { 7440 swiper.thumbs.swiper = thumbsParams.swiper; 7441 Object.assign(swiper.thumbs.swiper.originalParams, { 7442 watchSlidesProgress: true, 7443 slideToClickedSlide: false 7444 }); 7445 Object.assign(swiper.thumbs.swiper.params, { 7446 watchSlidesProgress: true, 7447 slideToClickedSlide: false 7448 }); 7449 swiper.thumbs.swiper.update(); 7450 } else if (isObject(thumbsParams.swiper)) { 7451 const thumbsSwiperParams = Object.assign({}, thumbsParams.swiper); 7452 Object.assign(thumbsSwiperParams, { 7453 watchSlidesProgress: true, 7454 slideToClickedSlide: false 7455 }); 7456 swiper.thumbs.swiper = new SwiperClass(thumbsSwiperParams); 7457 swiperCreated = true; 7458 } 7459 swiper.thumbs.swiper.el.classList.add(swiper.params.thumbs.thumbsContainerClass); 7460 swiper.thumbs.swiper.on('tap', onThumbClick); 7461 return true; 7462 } 7463 function update(initial) { 7464 const thumbsSwiper = swiper.thumbs.swiper; 7465 if (!thumbsSwiper || thumbsSwiper.destroyed) return; 7466 const slidesPerView = thumbsSwiper.params.slidesPerView === 'auto' ? thumbsSwiper.slidesPerViewDynamic() : thumbsSwiper.params.slidesPerView; 7467 7468 // Activate thumbs 7469 let thumbsToActivate = 1; 7470 const thumbActiveClass = swiper.params.thumbs.slideThumbActiveClass; 7471 if (swiper.params.slidesPerView > 1 && !swiper.params.centeredSlides) { 7472 thumbsToActivate = swiper.params.slidesPerView; 7473 } 7474 if (!swiper.params.thumbs.multipleActiveThumbs) { 7475 thumbsToActivate = 1; 7476 } 7477 thumbsToActivate = Math.floor(thumbsToActivate); 7478 thumbsSwiper.slides.forEach(slideEl => slideEl.classList.remove(thumbActiveClass)); 7479 if (thumbsSwiper.params.loop || thumbsSwiper.params.virtual && thumbsSwiper.params.virtual.enabled) { 7480 for (let i = 0; i < thumbsToActivate; i += 1) { 7481 elementChildren(thumbsSwiper.slidesEl, `[data-swiper-slide-index="${swiper.realIndex + i}"]`).forEach(slideEl => { 7482 slideEl.classList.add(thumbActiveClass); 7483 }); 7484 } 7485 } else { 7486 for (let i = 0; i < thumbsToActivate; i += 1) { 7487 if (thumbsSwiper.slides[swiper.realIndex + i]) { 7488 thumbsSwiper.slides[swiper.realIndex + i].classList.add(thumbActiveClass); 7489 } 7490 } 7491 } 7492 const autoScrollOffset = swiper.params.thumbs.autoScrollOffset; 7493 const useOffset = autoScrollOffset && !thumbsSwiper.params.loop; 7494 if (swiper.realIndex !== thumbsSwiper.realIndex || useOffset) { 7495 const currentThumbsIndex = thumbsSwiper.activeIndex; 7496 let newThumbsIndex; 7497 let direction; 7498 if (thumbsSwiper.params.loop) { 7499 const newThumbsSlide = thumbsSwiper.slides.filter(slideEl => slideEl.getAttribute('data-swiper-slide-index') === `${swiper.realIndex}`)[0]; 7500 newThumbsIndex = thumbsSwiper.slides.indexOf(newThumbsSlide); 7501 direction = swiper.activeIndex > swiper.previousIndex ? 'next' : 'prev'; 7502 } else { 7503 newThumbsIndex = swiper.realIndex; 7504 direction = newThumbsIndex > swiper.previousIndex ? 'next' : 'prev'; 7505 } 7506 if (useOffset) { 7507 newThumbsIndex += direction === 'next' ? autoScrollOffset : -1 * autoScrollOffset; 7508 } 7509 if (thumbsSwiper.visibleSlidesIndexes && thumbsSwiper.visibleSlidesIndexes.indexOf(newThumbsIndex) < 0) { 7510 if (thumbsSwiper.params.centeredSlides) { 7511 if (newThumbsIndex > currentThumbsIndex) { 7512 newThumbsIndex = newThumbsIndex - Math.floor(slidesPerView / 2) + 1; 7513 } else { 7514 newThumbsIndex = newThumbsIndex + Math.floor(slidesPerView / 2) - 1; 7515 } 7516 } else if (newThumbsIndex > currentThumbsIndex && thumbsSwiper.params.slidesPerGroup === 1) ; 7517 thumbsSwiper.slideTo(newThumbsIndex, initial ? 0 : undefined); 7518 } 7519 } 7520 } 7521 on('beforeInit', () => { 7522 const { 7523 thumbs 7524 } = swiper.params; 7525 if (!thumbs || !thumbs.swiper) return; 7526 if (typeof thumbs.swiper === 'string' || thumbs.swiper instanceof HTMLElement) { 7527 const document = getDocument(); 7528 const getThumbsElementAndInit = () => { 7529 const thumbsElement = typeof thumbs.swiper === 'string' ? document.querySelector(thumbs.swiper) : thumbs.swiper; 7530 if (thumbsElement && thumbsElement.swiper) { 7531 thumbs.swiper = thumbsElement.swiper; 7532 init(); 7533 update(true); 7534 } else if (thumbsElement) { 7535 const onThumbsSwiper = e => { 7536 thumbs.swiper = e.detail[0]; 7537 thumbsElement.removeEventListener('init', onThumbsSwiper); 7538 init(); 7539 update(true); 7540 thumbs.swiper.update(); 7541 swiper.update(); 7542 }; 7543 thumbsElement.addEventListener('init', onThumbsSwiper); 7544 } 7545 return thumbsElement; 7546 }; 7547 const watchForThumbsToAppear = () => { 7548 if (swiper.destroyed) return; 7549 const thumbsElement = getThumbsElementAndInit(); 7550 if (!thumbsElement) { 7551 requestAnimationFrame(watchForThumbsToAppear); 7552 } 7553 }; 7554 requestAnimationFrame(watchForThumbsToAppear); 7555 } else { 7556 init(); 7557 update(true); 7558 } 7559 }); 7560 on('slideChange update resize observerUpdate', () => { 7561 update(); 7562 }); 7563 on('setTransition', (_s, duration) => { 7564 const thumbsSwiper = swiper.thumbs.swiper; 7565 if (!thumbsSwiper || thumbsSwiper.destroyed) return; 7566 thumbsSwiper.setTransition(duration); 7567 }); 7568 on('beforeDestroy', () => { 7569 const thumbsSwiper = swiper.thumbs.swiper; 7570 if (!thumbsSwiper || thumbsSwiper.destroyed) return; 7571 if (swiperCreated) { 7572 thumbsSwiper.destroy(); 7573 } 7574 }); 7575 Object.assign(swiper.thumbs, { 7576 init, 7577 update 7578 }); 7579 } 7580 7581 function freeMode(_ref) { 7582 let { 7583 swiper, 7584 extendParams, 7585 emit, 7586 once 7587 } = _ref; 7588 extendParams({ 7589 freeMode: { 7590 enabled: false, 7591 momentum: true, 7592 momentumRatio: 1, 7593 momentumBounce: true, 7594 momentumBounceRatio: 1, 7595 momentumVelocityRatio: 1,
7596 sticky: false, 7597 minimumVelocity: 0.02 7598 } 7599 }); 7600 function onTouchStart() { 7601 const translate = swiper.getTranslate(); 7602 swiper.setTranslate(translate); 7603 swiper.setTransition(0); 7604 swiper.touchEventsData.velocities.length = 0; 7605 swiper.freeMode.onTouchEnd({ 7606 currentPos: swiper.rtl ? swiper.translate : -swiper.translate 7607 }); 7608 } 7609 function onTouchMove() { 7610 const { 7611 touchEventsData: data, 7612 touches 7613 } = swiper; 7614 // Velocity 7615 if (data.velocities.length === 0) { 7616 data.velocities.push({ 7617 position: touches[swiper.isHorizontal() ? 'startX' : 'startY'], 7618 time: data.touchStartTime 7619 }); 7620 } 7621 data.velocities.push({ 7622 position: touches[swiper.isHorizontal() ? 'currentX' : 'currentY'], 7623 time: now() 7624 }); 7625 } 7626 function onTouchEnd(_ref2) { 7627 let { 7628 currentPos 7629 } = _ref2; 7630 const { 7631 params, 7632 wrapperEl, 7633 rtlTranslate: rtl, 7634 snapGrid, 7635 touchEventsData: data 7636 } = swiper; 7637 // Time diff 7638 const touchEndTime = now(); 7639 const timeDiff = touchEndTime - data.touchStartTime;
vendor: 7,614 bytes, lines 7640-7821
7640 if (currentPos < -swiper.minTranslate()) { 7641 swiper.slideTo(swiper.activeIndex); 7642 return; 7643 } 7644 if (currentPos > -swiper.maxTranslate()) { 7645 if (swiper.slides.length < snapGrid.length) { 7646 swiper.slideTo(snapGrid.length - 1); 7647 } else { 7648 swiper.slideTo(swiper.slides.length - 1); 7649 } 7650 return; 7651 } 7652 if (params.freeMode.momentum) { 7653 if (data.velocities.length > 1) { 7654 const lastMoveEvent = data.velocities.pop(); 7655 const velocityEvent = data.velocities.pop(); 7656 const distance = lastMoveEvent.position - velocityEvent.position; 7657 const time = lastMoveEvent.time - velocityEvent.time; 7658 swiper.velocity = distance / time; 7659 swiper.velocity /= 2; 7660 if (Math.abs(swiper.velocity) < params.freeMode.minimumVelocity) { 7661 swiper.velocity = 0; 7662 } 7663 // this implies that the user stopped moving a finger then released. 7664 // There would be no events with distance zero, so the last event is stale. 7665 if (time > 150 || now() - lastMoveEvent.time > 300) { 7666 swiper.velocity = 0; 7667 } 7668 } else { 7669 swiper.velocity = 0; 7670 } 7671 swiper.velocity *= params.freeMode.momentumVelocityRatio; 7672 data.velocities.length = 0; 7673 let momentumDuration = 1000 * params.freeMode.momentumRatio; 7674 const momentumDistance = swiper.velocity * momentumDuration; 7675 let newPosition = swiper.translate + momentumDistance; 7676 if (rtl) newPosition = -newPosition; 7677 let doBounce = false; 7678 let afterBouncePosition; 7679 const bounceAmount = Math.abs(swiper.velocity) * 20 * params.freeMode.momentumBounceRatio; 7680 let needsLoopFix; 7681 if (newPosition < swiper.maxTranslate()) { 7682 if (params.freeMode.momentumBounce) { 7683 if (newPosition + swiper.maxTranslate() < -bounceAmount) { 7684 newPosition = swiper.maxTranslate() - bounceAmount; 7685 } 7686 afterBouncePosition = swiper.maxTranslate(); 7687 doBounce = true; 7688 data.allowMomentumBounce = true; 7689 } else { 7690 newPosition = swiper.maxTranslate(); 7691 } 7692 if (params.loop && params.centeredSlides) needsLoopFix = true; 7693 } else if (newPosition > swiper.minTranslate()) { 7694 if (params.freeMode.momentumBounce) { 7695 if (newPosition - swiper.minTranslate() > bounceAmount) { 7696 newPosition = swiper.minTranslate() + bounceAmount; 7697 } 7698 afterBouncePosition = swiper.minTranslate(); 7699 doBounce = true; 7700 data.allowMomentumBounce = true; 7701 } else { 7702 newPosition = swiper.minTranslate(); 7703 } 7704 if (params.loop && params.centeredSlides) needsLoopFix = true; 7705 } else if (params.freeMode.sticky) { 7706 let nextSlide; 7707 for (let j = 0; j < snapGrid.length; j += 1) { 7708 if (snapGrid[j] > -newPosition) { 7709 nextSlide = j; 7710 break; 7711 } 7712 } 7713 if (Math.abs(snapGrid[nextSlide] - newPosition) < Math.abs(snapGrid[nextSlide - 1] - newPosition) || swiper.swipeDirection === 'next') { 7714 newPosition = snapGrid[nextSlide]; 7715 } else { 7716 newPosition = snapGrid[nextSlide - 1]; 7717 } 7718 newPosition = -newPosition; 7719 } 7720 if (needsLoopFix) { 7721 once('transitionEnd', () => { 7722 swiper.loopFix(); 7723 }); 7724 } 7725 // Fix duration 7726 if (swiper.velocity !== 0) { 7727 if (rtl) { 7728 momentumDuration = Math.abs((-newPosition - swiper.translate) / swiper.velocity); 7729 } else { 7730 momentumDuration = Math.abs((newPosition - swiper.translate) / swiper.velocity); 7731 } 7732 if (params.freeMode.sticky) { 7733 // If freeMode.sticky is active and the user ends a swipe with a slow-velocity 7734 // event, then durations can be 20+ seconds to slide one (or zero!) slides. 7735 // It's easy to see this when simulating touch with mouse events. To fix this, 7736 // limit single-slide swipes to the default slide duration. This also has the 7737 // nice side effect of matching slide speed if the user stopped moving before 7738 // lifting finger or mouse vs. moving slowly before lifting the finger/mouse. 7739 // For faster swipes, also apply limits (albeit higher ones). 7740 const moveDistance = Math.abs((rtl ? -newPosition : newPosition) - swiper.translate); 7741 const currentSlideSize = swiper.slidesSizesGrid[swiper.activeIndex]; 7742 if (moveDistance < currentSlideSize) { 7743 momentumDuration = params.speed; 7744 } else if (moveDistance < 2 * currentSlideSize) { 7745 momentumDuration = params.speed * 1.5; 7746 } else { 7747 momentumDuration = params.speed * 2.5; 7748 } 7749 } 7750 } else if (params.freeMode.sticky) { 7751 swiper.slideToClosest(); 7752 return; 7753 } 7754 if (params.freeMode.momentumBounce && doBounce) { 7755 swiper.updateProgress(afterBouncePosition); 7756 swiper.setTransition(momentumDuration); 7757 swiper.setTranslate(newPosition); 7758 swiper.transitionStart(true, swiper.swipeDirection); 7759 swiper.animating = true; 7760 elementTransitionEnd(wrapperEl, () => { 7761 if (!swiper || swiper.destroyed || !data.allowMomentumBounce) return; 7762 emit('momentumBounce'); 7763 swiper.setTransition(params.speed); 7764 setTimeout(() => { 7765 swiper.setTranslate(afterBouncePosition); 7766 elementTransitionEnd(wrapperEl, () => { 7767 if (!swiper || swiper.destroyed) return; 7768 swiper.transitionEnd(); 7769 }); 7770 }, 0); 7771 }); 7772 } else if (swiper.velocity) { 7773 emit('_freeModeNoMomentumRelease'); 7774 swiper.updateProgress(newPosition); 7775 swiper.setTransition(momentumDuration); 7776 swiper.setTranslate(newPosition); 7777 swiper.transitionStart(true, swiper.swipeDirection); 7778 if (!swiper.animating) { 7779 swiper.animating = true; 7780 elementTransitionEnd(wrapperEl, () => { 7781 if (!swiper || swiper.destroyed) return; 7782 swiper.transitionEnd(); 7783 }); 7784 } 7785 } else { 7786 swiper.updateProgress(newPosition); 7787 } 7788 swiper.updateActiveIndex(); 7789 swiper.updateSlidesClasses(); 7790 } else if (params.freeMode.sticky) { 7791 swiper.slideToClosest(); 7792 return; 7793 } else if (params.freeMode) { 7794 emit('_freeModeNoMomentumRelease'); 7795 } 7796 if (!params.freeMode.momentum || timeDiff >= params.longSwipesMs) { 7797 swiper.updateProgress(); 7798 swiper.updateActiveIndex(); 7799 swiper.updateSlidesClasses(); 7800 } 7801 } 7802 Object.assign(swiper, { 7803 freeMode: { 7804 onTouchStart, 7805 onTouchMove, 7806 onTouchEnd 7807 } 7808 }); 7809 } 7810 7811 function Grid(_ref) { 7812 let { 7813 swiper, 7814 extendParams 7815 } = _ref; 7816 extendParams({ 7817 grid: { 7818 rows: 1, 7819 fill: 'column' 7820 } 7821 });
7822 let slidesNumberEvenToRows; 7823 let slidesPerRow; 7824 let numFullColumns; 7825 const initSlides = slidesLength => { 7826 const { 7827 slidesPerView 7828 } = swiper.params; 7829 const { 7830 rows, 7831 fill 7832 } = swiper.params.grid; 7833 slidesPerRow = slidesNumberEvenToRows / rows; 7834 numFullColumns = Math.floor(slidesLength / rows); 7835 if (Math.floor(slidesLength / rows) === slidesLength / rows) { 7836 slidesNumberEvenToRows = slidesLength; 7837 } else { 7838 slidesNumberEvenToRows = Math.ceil(slidesLength / rows) * rows; 7839 } 7840 if (slidesPerView !== 'auto' && fill === 'row') { 7841 slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, slidesPerView * rows); 7842 } 7843 }; 7844 const updateSlide = (i, slide, slidesLength, getDirectionLabel) => { 7845 const { 7846 slidesPerGroup, 7847 spaceBetween 7848 } = swiper.params; 7849 const { 7850 rows, 7851 fill 7852 } = swiper.params.grid; 7853 // Set slides order 7854 let newSlideOrderIndex; 7855 let column; 7856 let row; 7857 if (fill === 'row' && slidesPerGroup > 1) { 7858 const groupIndex = Math.floor(i / (slidesPerGroup * rows)); 7859 const slideIndexInGroup = i - rows * slidesPerGroup * groupIndex; 7860 const columnsInGroup = groupIndex === 0 ? slidesPerGroup : Math.min(Math.ceil((slidesLength - groupIndex * rows * slidesPerGroup) / rows), slidesPerGroup); 7861 row = Math.floor(slideIndexInGroup / columnsInGroup); 7862 column = slideIndexInGroup - row * columnsInGroup + groupIndex * slidesPerGroup; 7863 newSlideOrderIndex = column + row * slidesNumberEvenToRows / rows; 7864 slide.style.order = newSlideOrderIndex; 7865 } else if (fill === 'column') { 7866 column = Math.floor(i / rows); 7867 row = i - column * rows; 7868 if (column > numFullColumns || column === numFullColumns && row === rows - 1) { 7869 row += 1; 7870 if (row >= rows) { 7871 row = 0; 7872 column += 1; 7873 } 7874 } 7875 } else { 7876 row = Math.floor(i / slidesPerRow); 7877 column = i - row * slidesPerRow; 7878 } 7879 slide.style[getDirectionLabel('margin-top')] = row !== 0 ? spaceBetween && `${spaceBetween}px` : ''; 7880 }; 7881 const updateWrapperSize = (slideSize, snapGrid, getDirectionLabel) => { 7882 const { 7883 spaceBetween, 7884 centeredSlides, 7885 roundLengths 7886 } = swiper.params; 7887 const { 7888 rows 7889 } = swiper.params.grid; 7890 swiper.virtualSize = (slideSize + spaceBetween) * slidesNumberEvenToRows; 7891 swiper.virtualSize = Math.ceil(swiper.virtualSize / rows) - spaceBetween; 7892 swiper.wrapperEl.style[getDirectionLabel('width')] = `${swiper.virtualSize + spaceBetween}px`; 7893 if (centeredSlides) { 7894 const newSlidesGrid = []; 7895 for (let i = 0; i < snapGrid.length; i += 1) { 7896 let slidesGridItem = snapGrid[i]; 7897 if (roundLengths) slidesGridItem = Math.floor(slidesGridItem); 7898 if (snapGrid[i] < swiper.virtualSize + snapGrid[0]) newSlidesGrid.push(slidesGridItem); 7899 } 7900 snapGrid.splice(0, snapGrid.length); 7901 snapGrid.push(...newSlidesGrid); 7902 } 7903 }; 7904 swiper.grid = { 7905 initSlides, 7906 updateSlide, 7907 updateWrapperSize 7908 }; 7909 } 7910 7911 function appendSlide(slides) { 7912 const swiper = this; 7913 const { 7914 params, 7915 slidesEl 7916 } = swiper; 7917 if (params.loop) { 7918 swiper.loopDestroy(); 7919 } 7920 const appendElement = slideEl => { 7921 if (typeof slideEl === 'string') { 7922 const tempDOM = document.createElement('div'); 7923 tempDOM.innerHTML = slideEl; 7924 slidesEl.append(tempDOM.children[0]); 7925 tempDOM.innerHTML = ''; 7926 } else { 7927 slidesEl.append(slideEl); 7928 } 7929 }; 7930 if (typeof slides === 'object' && 'length' in slides) { 7931 for (let i = 0; i < slides.length; i += 1) { 7932 if (slides[i]) appendElement(slides[i]); 7933 } 7934 } else { 7935 appendElement(slides); 7936 } 7937 swiper.recalcSlides(); 7938 if (params.loop) { 7939 swiper.loopCreate(); 7940 } 7941 if (!params.observer || swiper.isElement) {
vendor: 36,110 bytes, lines 7942-8909
7942 swiper.update(); 7943 } 7944 } 7945 7946 function prependSlide(slides) { 7947 const swiper = this; 7948 const { 7949 params, 7950 activeIndex, 7951 slidesEl 7952 } = swiper; 7953 if (params.loop) { 7954 swiper.loopDestroy(); 7955 } 7956 let newActiveIndex = activeIndex + 1; 7957 const prependElement = slideEl => { 7958 if (typeof slideEl === 'string') { 7959 const tempDOM = document.createElement('div'); 7960 tempDOM.innerHTML = slideEl; 7961 slidesEl.prepend(tempDOM.children[0]); 7962 tempDOM.innerHTML = ''; 7963 } else { 7964 slidesEl.prepend(slideEl); 7965 } 7966 }; 7967 if (typeof slides === 'object' && 'length' in slides) { 7968 for (let i = 0; i < slides.length; i += 1) { 7969 if (slides[i]) prependElement(slides[i]); 7970 } 7971 newActiveIndex = activeIndex + slides.length; 7972 } else { 7973 prependElement(slides); 7974 } 7975 swiper.recalcSlides(); 7976 if (params.loop) { 7977 swiper.loopCreate(); 7978 } 7979 if (!params.observer || swiper.isElement) { 7980 swiper.update(); 7981 } 7982 swiper.slideTo(newActiveIndex, 0, false); 7983 } 7984 7985 function addSlide(index, slides) { 7986 const swiper = this; 7987 const { 7988 params, 7989 activeIndex, 7990 slidesEl 7991 } = swiper; 7992 let activeIndexBuffer = activeIndex; 7993 if (params.loop) { 7994 activeIndexBuffer -= swiper.loopedSlides; 7995 swiper.loopDestroy(); 7996 swiper.recalcSlides(); 7997 } 7998 const baseLength = swiper.slides.length; 7999 if (index <= 0) { 8000 swiper.prependSlide(slides); 8001 return; 8002 } 8003 if (index >= baseLength) { 8004 swiper.appendSlide(slides); 8005 return; 8006 } 8007 let newActiveIndex = activeIndexBuffer > index ? activeIndexBuffer + 1 : activeIndexBuffer; 8008 const slidesBuffer = []; 8009 for (let i = baseLength - 1; i >= index; i -= 1) { 8010 const currentSlide = swiper.slides[i]; 8011 currentSlide.remove(); 8012 slidesBuffer.unshift(currentSlide); 8013 } 8014 if (typeof slides === 'object' && 'length' in slides) { 8015 for (let i = 0; i < slides.length; i += 1) { 8016 if (slides[i]) slidesEl.append(slides[i]); 8017 } 8018 newActiveIndex = activeIndexBuffer > index ? activeIndexBuffer + slides.length : activeIndexBuffer; 8019 } else { 8020 slidesEl.append(slides); 8021 } 8022 for (let i = 0; i < slidesBuffer.length; i += 1) { 8023 slidesEl.append(slidesBuffer[i]); 8024 } 8025 swiper.recalcSlides(); 8026 if (params.loop) { 8027 swiper.loopCreate(); 8028 } 8029 if (!params.observer || swiper.isElement) { 8030 swiper.update(); 8031 } 8032 if (params.loop) { 8033 swiper.slideTo(newActiveIndex + swiper.loopedSlides, 0, false); 8034 } else { 8035 swiper.slideTo(newActiveIndex, 0, false); 8036 } 8037 } 8038 8039 function removeSlide(slidesIndexes) { 8040 const swiper = this; 8041 const { 8042 params, 8043 activeIndex 8044 } = swiper; 8045 let activeIndexBuffer = activeIndex; 8046 if (params.loop) { 8047 activeIndexBuffer -= swiper.loopedSlides; 8048 swiper.loopDestroy(); 8049 } 8050 let newActiveIndex = activeIndexBuffer; 8051 let indexToRemove; 8052 if (typeof slidesIndexes === 'object' && 'length' in slidesIndexes) { 8053 for (let i = 0; i < slidesIndexes.length; i += 1) { 8054 indexToRemove = slidesIndexes[i]; 8055 if (swiper.slides[indexToRemove]) swiper.slides[indexToRemove].remove(); 8056 if (indexToRemove < newActiveIndex) newActiveIndex -= 1; 8057 } 8058 newActiveIndex = Math.max(newActiveIndex, 0); 8059 } else { 8060 indexToRemove = slidesIndexes; 8061 if (swiper.slides[indexToRemove]) swiper.slides[indexToRemove].remove(); 8062 if (indexToRemove < newActiveIndex) newActiveIndex -= 1; 8063 newActiveIndex = Math.max(newActiveIndex, 0); 8064 } 8065 swiper.recalcSlides(); 8066 if (params.loop) { 8067 swiper.loopCreate(); 8068 } 8069 if (!params.observer || swiper.isElement) { 8070 swiper.update(); 8071 } 8072 if (params.loop) { 8073 swiper.slideTo(newActiveIndex + swiper.loopedSlides, 0, false); 8074 } else { 8075 swiper.slideTo(newActiveIndex, 0, false); 8076 } 8077 } 8078 8079 function removeAllSlides() { 8080 const swiper = this; 8081 const slidesIndexes = []; 8082 for (let i = 0; i < swiper.slides.length; i += 1) { 8083 slidesIndexes.push(i); 8084 } 8085 swiper.removeSlide(slidesIndexes); 8086 } 8087 8088 function Manipulation(_ref) { 8089 let { 8090 swiper 8091 } = _ref; 8092 Object.assign(swiper, { 8093 appendSlide: appendSlide.bind(swiper), 8094 prependSlide: prependSlide.bind(swiper), 8095 addSlide: addSlide.bind(swiper), 8096 removeSlide: removeSlide.bind(swiper), 8097 removeAllSlides: removeAllSlides.bind(swiper) 8098 }); 8099 } 8100 8101 function effectInit(params) { 8102 const { 8103 effect, 8104 swiper, 8105 on, 8106 setTranslate, 8107 setTransition, 8108 overwriteParams, 8109 perspective, 8110 recreateShadows, 8111 getEffectParams 8112 } = params; 8113 on('beforeInit', () => { 8114 if (swiper.params.effect !== effect) return; 8115 swiper.classNames.push(`${swiper.params.containerModifierClass}${effect}`); 8116 if (perspective && perspective()) { 8117 swiper.classNames.push(`${swiper.params.containerModifierClass}3d`); 8118 } 8119 const overwriteParamsResult = overwriteParams ? overwriteParams() : {}; 8120 Object.assign(swiper.params, overwriteParamsResult); 8121 Object.assign(swiper.originalParams, overwriteParamsResult); 8122 }); 8123 on('setTranslate', () => { 8124 if (swiper.params.effect !== effect) return; 8125 setTranslate(); 8126 }); 8127 on('setTransition', (_s, duration) => { 8128 if (swiper.params.effect !== effect) return; 8129 setTransition(duration); 8130 }); 8131 on('transitionEnd', () => { 8132 if (swiper.params.effect !== effect) return; 8133 if (recreateShadows) { 8134 if (!getEffectParams || !getEffectParams().slideShadows) return; 8135 // remove shadows 8136 swiper.slides.forEach(slideEl => { 8137 slideEl.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(shadowEl => shadowEl.remove()); 8138 }); 8139 // create new one 8140 recreateShadows(); 8141 } 8142 }); 8143 let requireUpdateOnVirtual; 8144 on('virtualUpdate', () => { 8145 if (swiper.params.effect !== effect) return; 8146 if (!swiper.slides.length) { 8147 requireUpdateOnVirtual = true; 8148 } 8149 requestAnimationFrame(() => { 8150 if (requireUpdateOnVirtual && swiper.slides && swiper.slides.length) { 8151 setTranslate(); 8152 requireUpdateOnVirtual = false; 8153 } 8154 }); 8155 }); 8156 } 8157 8158 function effectTarget(effectParams, slideEl) { 8159 const transformEl = getSlideTransformEl(slideEl); 8160 if (transformEl !== slideEl) { 8161 transformEl.style.backfaceVisibility = 'hidden'; 8162 transformEl.style['-webkit-backface-visibility'] = 'hidden'; 8163 } 8164 return transformEl; 8165 } 8166 8167 function effectVirtualTransitionEnd(_ref) { 8168 let { 8169 swiper, 8170 duration, 8171 transformElements, 8172 allSlides 8173 } = _ref; 8174 const { 8175 activeIndex 8176 } = swiper; 8177 const getSlide = el => { 8178 if (!el.parentElement) { 8179 // assume shadow root 8180 const slide = swiper.slides.filter(slideEl => slideEl.shadowEl && slideEl.shadowEl === el.parentNode)[0]; 8181 return slide; 8182 } 8183 return el.parentElement; 8184 }; 8185 if (swiper.params.virtualTranslate && duration !== 0) { 8186 let eventTriggered = false; 8187 let transitionEndTarget; 8188 if (allSlides) { 8189 transitionEndTarget = transformElements; 8190 } else { 8191 transitionEndTarget = transformElements.filter(transformEl => { 8192 const el = transformEl.classList.contains('swiper-slide-transform') ? getSlide(transformEl) : transformEl; 8193 return elementIndex(el) === activeIndex; 8194 }); 8195 } 8196 transitionEndTarget.forEach(el => { 8197 elementTransitionEnd(el, () => { 8198 if (eventTriggered) return; 8199 if (!swiper || swiper.destroyed) return; 8200 eventTriggered = true; 8201 swiper.animating = false; 8202 const evt = new window.CustomEvent('transitionend', { 8203 bubbles: true, 8204 cancelable: true 8205 }); 8206 swiper.wrapperEl.dispatchEvent(evt); 8207 }); 8208 }); 8209 } 8210 } 8211 8212 function EffectFade(_ref) { 8213 let { 8214 swiper, 8215 extendParams, 8216 on 8217 } = _ref; 8218 extendParams({ 8219 fadeEffect: { 8220 crossFade: false 8221 } 8222 }); 8223 const setTranslate = () => { 8224 const { 8225 slides 8226 } = swiper; 8227 const params = swiper.params.fadeEffect; 8228 for (let i = 0; i < slides.length; i += 1) { 8229 const slideEl = swiper.slides[i]; 8230 const offset = slideEl.swiperSlideOffset; 8231 let tx = -offset; 8232 if (!swiper.params.virtualTranslate) tx -= swiper.translate; 8233 let ty = 0; 8234 if (!swiper.isHorizontal()) { 8235 ty = tx; 8236 tx = 0; 8237 } 8238 const slideOpacity = swiper.params.fadeEffect.crossFade ? Math.max(1 - Math.abs(slideEl.progress), 0) : 1 + Math.min(Math.max(slideEl.progress, -1), 0); 8239 const targetEl = effectTarget(params, slideEl); 8240 targetEl.style.opacity = slideOpacity; 8241 targetEl.style.transform = `translate3d(${tx}px, ${ty}px, 0px)`; 8242 } 8243 }; 8244 const setTransition = duration => { 8245 const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl)); 8246 transformElements.forEach(el => { 8247 el.style.transitionDuration = `${duration}ms`; 8248 }); 8249 effectVirtualTransitionEnd({ 8250 swiper, 8251 duration, 8252 transformElements, 8253 allSlides: true 8254 }); 8255 }; 8256 effectInit({ 8257 effect: 'fade', 8258 swiper, 8259 on, 8260 setTranslate, 8261 setTransition, 8262 overwriteParams: () => ({ 8263 slidesPerView: 1, 8264 slidesPerGroup: 1, 8265 watchSlidesProgress: true, 8266 spaceBetween: 0, 8267 virtualTranslate: !swiper.params.cssMode 8268 }) 8269 }); 8270 } 8271 8272 function EffectCube(_ref) { 8273 let { 8274 swiper, 8275 extendParams, 8276 on 8277 } = _ref; 8278 extendParams({ 8279 cubeEffect: { 8280 slideShadows: true, 8281 shadow: true, 8282 shadowOffset: 20, 8283 shadowScale: 0.94 8284 } 8285 }); 8286 const createSlideShadows = (slideEl, progress, isHorizontal) => { 8287 let shadowBefore = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-left') : slideEl.querySelector('.swiper-slide-shadow-top'); 8288 let shadowAfter = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-right') : slideEl.querySelector('.swiper-slide-shadow-bottom'); 8289 if (!shadowBefore) { 8290 shadowBefore = createElement('div', `swiper-slide-shadow-${isHorizontal ? 'left' : 'top'}`); 8291 slideEl.append(shadowBefore); 8292 } 8293 if (!shadowAfter) { 8294 shadowAfter = createElement('div', `swiper-slide-shadow-${isHorizontal ? 'right' : 'bottom'}`); 8295 slideEl.append(shadowAfter); 8296 } 8297 if (shadowBefore) shadowBefore.style.opacity = Math.max(-progress, 0); 8298 if (shadowAfter) shadowAfter.style.opacity = Math.max(progress, 0); 8299 }; 8300 const recreateShadows = () => { 8301 // create new ones 8302 const isHorizontal = swiper.isHorizontal(); 8303 swiper.slides.forEach(slideEl => { 8304 const progress = Math.max(Math.min(slideEl.progress, 1), -1); 8305 createSlideShadows(slideEl, progress, isHorizontal); 8306 }); 8307 }; 8308 const setTranslate = () => { 8309 const { 8310 el, 8311 wrapperEl, 8312 slides, 8313 width: swiperWidth, 8314 height: swiperHeight, 8315 rtlTranslate: rtl, 8316 size: swiperSize, 8317 browser 8318 } = swiper; 8319 const params = swiper.params.cubeEffect; 8320 const isHorizontal = swiper.isHorizontal(); 8321 const isVirtual = swiper.virtual && swiper.params.virtual.enabled; 8322 let wrapperRotate = 0; 8323 let cubeShadowEl; 8324 if (params.shadow) { 8325 if (isHorizontal) { 8326 cubeShadowEl = swiper.slidesEl.querySelector('.swiper-cube-shadow'); 8327 if (!cubeShadowEl) { 8328 cubeShadowEl = createElement('div', 'swiper-cube-shadow'); 8329 swiper.slidesEl.append(cubeShadowEl); 8330 } 8331 cubeShadowEl.style.height = `${swiperWidth}px`; 8332 } else { 8333 cubeShadowEl = el.querySelector('.swiper-cube-shadow'); 8334 if (!cubeShadowEl) { 8335 cubeShadowEl = createElement('div', 'swiper-cube-shadow'); 8336 el.append(cubeShadowEl); 8337 } 8338 } 8339 } 8340 for (let i = 0; i < slides.length; i += 1) { 8341 const slideEl = slides[i]; 8342 let slideIndex = i; 8343 if (isVirtual) { 8344 slideIndex = parseInt(slideEl.getAttribute('data-swiper-slide-index'), 10); 8345 } 8346 let slideAngle = slideIndex * 90; 8347 let round = Math.floor(slideAngle / 360); 8348 if (rtl) { 8349 slideAngle = -slideAngle; 8350 round = Math.floor(-slideAngle / 360); 8351 } 8352 const progress = Math.max(Math.min(slideEl.progress, 1), -1); 8353 let tx = 0; 8354 let ty = 0; 8355 let tz = 0; 8356 if (slideIndex % 4 === 0) { 8357 tx = -round * 4 * swiperSize; 8358 tz = 0; 8359 } else if ((slideIndex - 1) % 4 === 0) { 8360 tx = 0; 8361 tz = -round * 4 * swiperSize; 8362 } else if ((slideIndex - 2) % 4 === 0) { 8363 tx = swiperSize + round * 4 * swiperSize; 8364 tz = swiperSize; 8365 } else if ((slideIndex - 3) % 4 === 0) { 8366 tx = -swiperSize; 8367 tz = 3 * swiperSize + swiperSize * 4 * round; 8368 } 8369 if (rtl) { 8370 tx = -tx; 8371 } 8372 if (!isHorizontal) { 8373 ty = tx; 8374 tx = 0; 8375 } 8376 const transform = `rotateX(${isHorizontal ? 0 : -slideAngle}deg) rotateY(${isHorizontal ? slideAngle : 0}deg) translate3d(${tx}px, ${ty}px, ${tz}px)`; 8377 if (progress <= 1 && progress > -1) { 8378 wrapperRotate = slideIndex * 90 + progress * 90; 8379 if (rtl) wrapperRotate = -slideIndex * 90 - progress * 90; 8380 } 8381 slideEl.style.transform = transform; 8382 if (params.slideShadows) { 8383 createSlideShadows(slideEl, progress, isHorizontal); 8384 } 8385 } 8386 wrapperEl.style.transformOrigin = `50% 50% -${swiperSize / 2}px`; 8387 wrapperEl.style['-webkit-transform-origin'] = `50% 50% -${swiperSize / 2}px`; 8388 if (params.shadow) { 8389 if (isHorizontal) { 8390 cubeShadowEl.style.transform = `translate3d(0px, ${swiperWidth / 2 + params.shadowOffset}px, ${-swiperWidth / 2}px) rotateX(90deg) rotateZ(0deg) scale(${params.shadowScale})`; 8391 } else { 8392 const shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90; 8393 const multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2); 8394 const scale1 = params.shadowScale; 8395 const scale2 = params.shadowScale / multiplier; 8396 const offset = params.shadowOffset; 8397 cubeShadowEl.style.transform = `scale3d(${scale1}, 1, ${scale2}) translate3d(0px, ${swiperHeight / 2 + offset}px, ${-swiperHeight / 2 / scale2}px) rotateX(-90deg)`; 8398 } 8399 } 8400 const zFactor = (browser.isSafari || browser.isWebView) && browser.needPerspectiveFix ? -swiperSize / 2 : 0; 8401 wrapperEl.style.transform = `translate3d(0px,0,${zFactor}px) rotateX(${swiper.isHorizontal() ? 0 : wrapperRotate}deg) rotateY(${swiper.isHorizontal() ? -wrapperRotate : 0}deg)`; 8402 wrapperEl.style.setProperty('--swiper-cube-translate-z', `${zFactor}px`); 8403 }; 8404 const setTransition = duration => { 8405 const { 8406 el, 8407 slides 8408 } = swiper; 8409 slides.forEach(slideEl => { 8410 slideEl.style.transitionDuration = `${duration}ms`; 8411 slideEl.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(subEl => { 8412 subEl.style.transitionDuration = `${duration}ms`; 8413 }); 8414 }); 8415 if (swiper.params.cubeEffect.shadow && !swiper.isHorizontal()) { 8416 const shadowEl = el.querySelector('.swiper-cube-shadow'); 8417 if (shadowEl) shadowEl.style.transitionDuration = `${duration}ms`; 8418 } 8419 }; 8420 effectInit({ 8421 effect: 'cube', 8422 swiper, 8423 on, 8424 setTranslate, 8425 setTransition, 8426 recreateShadows, 8427 getEffectParams: () => swiper.params.cubeEffect, 8428 perspective: () => true, 8429 overwriteParams: () => ({ 8430 slidesPerView: 1, 8431 slidesPerGroup: 1, 8432 watchSlidesProgress: true, 8433 resistanceRatio: 0, 8434 spaceBetween: 0, 8435 centeredSlides: false, 8436 virtualTranslate: true 8437 }) 8438 }); 8439 } 8440 8441 function createShadow(params, slideEl, side) { 8442 const shadowClass = `swiper-slide-shadow${side ? `-${side}` : ''}`; 8443 const shadowContainer = getSlideTransformEl(slideEl); 8444 let shadowEl = shadowContainer.querySelector(`.${shadowClass}`); 8445 if (!shadowEl) { 8446 shadowEl = createElement('div', `swiper-slide-shadow${side ? `-${side}` : ''}`); 8447 shadowContainer.append(shadowEl); 8448 } 8449 return shadowEl; 8450 } 8451 8452 function EffectFlip(_ref) { 8453 let { 8454 swiper, 8455 extendParams, 8456 on 8457 } = _ref; 8458 extendParams({ 8459 flipEffect: { 8460 slideShadows: true, 8461 limitRotation: true 8462 } 8463 }); 8464 const createSlideShadows = (slideEl, progress, params) => { 8465 let shadowBefore = swiper.isHorizontal() ? slideEl.querySelector('.swiper-slide-shadow-left') : slideEl.querySelector('.swiper-slide-shadow-top'); 8466 let shadowAfter = swiper.isHorizontal() ? slideEl.querySelector('.swiper-slide-shadow-right') : slideEl.querySelector('.swiper-slide-shadow-bottom'); 8467 if (!shadowBefore) { 8468 shadowBefore = createShadow(params, slideEl, swiper.isHorizontal() ? 'left' : 'top'); 8469 } 8470 if (!shadowAfter) { 8471 shadowAfter = createShadow(params, slideEl, swiper.isHorizontal() ? 'right' : 'bottom'); 8472 } 8473 if (shadowBefore) shadowBefore.style.opacity = Math.max(-progress, 0); 8474 if (shadowAfter) shadowAfter.style.opacity = Math.max(progress, 0); 8475 }; 8476 const recreateShadows = () => { 8477 // Set shadows 8478 const params = swiper.params.flipEffect; 8479 swiper.slides.forEach(slideEl => { 8480 let progress = slideEl.progress; 8481 if (swiper.params.flipEffect.limitRotation) { 8482 progress = Math.max(Math.min(slideEl.progress, 1), -1); 8483 } 8484 createSlideShadows(slideEl, progress, params); 8485 }); 8486 }; 8487 const setTranslate = () => { 8488 const { 8489 slides, 8490 rtlTranslate: rtl 8491 } = swiper; 8492 const params = swiper.params.flipEffect; 8493 for (let i = 0; i < slides.length; i += 1) { 8494 const slideEl = slides[i]; 8495 let progress = slideEl.progress; 8496 if (swiper.params.flipEffect.limitRotation) { 8497 progress = Math.max(Math.min(slideEl.progress, 1), -1); 8498 } 8499 const offset = slideEl.swiperSlideOffset; 8500 const rotate = -180 * progress; 8501 let rotateY = rotate; 8502 let rotateX = 0; 8503 let tx = swiper.params.cssMode ? -offset - swiper.translate : -offset; 8504 let ty = 0; 8505 if (!swiper.isHorizontal()) { 8506 ty = tx; 8507 tx = 0; 8508 rotateX = -rotateY; 8509 rotateY = 0; 8510 } else if (rtl) { 8511 rotateY = -rotateY; 8512 } 8513 slideEl.style.zIndex = -Math.abs(Math.round(progress)) + slides.length; 8514 if (params.slideShadows) { 8515 createSlideShadows(slideEl, progress, params); 8516 } 8517 const transform = `translate3d(${tx}px, ${ty}px, 0px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`; 8518 const targetEl = effectTarget(params, slideEl); 8519 targetEl.style.transform = transform; 8520 } 8521 }; 8522 const setTransition = duration => { 8523 const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl)); 8524 transformElements.forEach(el => { 8525 el.style.transitionDuration = `${duration}ms`; 8526 el.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(shadowEl => { 8527 shadowEl.style.transitionDuration = `${duration}ms`; 8528 }); 8529 }); 8530 effectVirtualTransitionEnd({ 8531 swiper, 8532 duration, 8533 transformElements 8534 }); 8535 }; 8536 effectInit({ 8537 effect: 'flip', 8538 swiper, 8539 on, 8540 setTranslate, 8541 setTransition, 8542 recreateShadows, 8543 getEffectParams: () => swiper.params.flipEffect, 8544 perspective: () => true, 8545 overwriteParams: () => ({ 8546 slidesPerView: 1, 8547 slidesPerGroup: 1, 8548 watchSlidesProgress: true, 8549 spaceBetween: 0, 8550 virtualTranslate: !swiper.params.cssMode 8551 }) 8552 }); 8553 } 8554 8555 function EffectCoverflow(_ref) { 8556 let { 8557 swiper, 8558 extendParams, 8559 on 8560 } = _ref; 8561 extendParams({ 8562 coverflowEffect: { 8563 rotate: 50, 8564 stretch: 0, 8565 depth: 100, 8566 scale: 1, 8567 modifier: 1, 8568 slideShadows: true 8569 } 8570 }); 8571 const setTranslate = () => { 8572 const { 8573 width: swiperWidth, 8574 height: swiperHeight, 8575 slides, 8576 slidesSizesGrid 8577 } = swiper; 8578 const params = swiper.params.coverflowEffect; 8579 const isHorizontal = swiper.isHorizontal(); 8580 const transform = swiper.translate; 8581 const center = isHorizontal ? -transform + swiperWidth / 2 : -transform + swiperHeight / 2; 8582 const rotate = isHorizontal ? params.rotate : -params.rotate; 8583 const translate = params.depth; 8584 // Each slide offset from center 8585 for (let i = 0, length = slides.length; i < length; i += 1) { 8586 const slideEl = slides[i]; 8587 const slideSize = slidesSizesGrid[i]; 8588 const slideOffset = slideEl.swiperSlideOffset; 8589 const centerOffset = (center - slideOffset - slideSize / 2) / slideSize; 8590 const offsetMultiplier = typeof params.modifier === 'function' ? params.modifier(centerOffset) : centerOffset * params.modifier; 8591 let rotateY = isHorizontal ? rotate * offsetMultiplier : 0; 8592 let rotateX = isHorizontal ? 0 : rotate * offsetMultiplier; 8593 // var rotateZ = 0 8594 let translateZ = -translate * Math.abs(offsetMultiplier); 8595 let stretch = params.stretch; 8596 // Allow percentage to make a relative stretch for responsive sliders 8597 if (typeof stretch === 'string' && stretch.indexOf('%') !== -1) { 8598 stretch = parseFloat(params.stretch) / 100 * slideSize; 8599 } 8600 let translateY = isHorizontal ? 0 : stretch * offsetMultiplier; 8601 let translateX = isHorizontal ? stretch * offsetMultiplier : 0; 8602 let scale = 1 - (1 - params.scale) * Math.abs(offsetMultiplier); 8603 8604 // Fix for ultra small values 8605 if (Math.abs(translateX) < 0.001) translateX = 0; 8606 if (Math.abs(translateY) < 0.001) translateY = 0; 8607 if (Math.abs(translateZ) < 0.001) translateZ = 0; 8608 if (Math.abs(rotateY) < 0.001) rotateY = 0; 8609 if (Math.abs(rotateX) < 0.001) rotateX = 0; 8610 if (Math.abs(scale) < 0.001) scale = 0; 8611 const slideTransform = `translate3d(${translateX}px,${translateY}px,${translateZ}px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale(${scale})`; 8612 const targetEl = effectTarget(params, slideEl); 8613 targetEl.style.transform = slideTransform; 8614 slideEl.style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1; 8615 if (params.slideShadows) { 8616 // Set shadows 8617 let shadowBeforeEl = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-left') : slideEl.querySelector('.swiper-slide-shadow-top'); 8618 let shadowAfterEl = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-right') : slideEl.querySelector('.swiper-slide-shadow-bottom'); 8619 if (!shadowBeforeEl) { 8620 shadowBeforeEl = createShadow(params, slideEl, isHorizontal ? 'left' : 'top'); 8621 } 8622 if (!shadowAfterEl) { 8623 shadowAfterEl = createShadow(params, slideEl, isHorizontal ? 'right' : 'bottom'); 8624 } 8625 if (shadowBeforeEl) shadowBeforeEl.style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0; 8626 if (shadowAfterEl) shadowAfterEl.style.opacity = -offsetMultiplier > 0 ? -offsetMultiplier : 0; 8627 } 8628 } 8629 }; 8630 const setTransition = duration => { 8631 const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl)); 8632 transformElements.forEach(el => { 8633 el.style.transitionDuration = `${duration}ms`; 8634 el.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(shadowEl => { 8635 shadowEl.style.transitionDuration = `${duration}ms`; 8636 }); 8637 }); 8638 }; 8639 effectInit({ 8640 effect: 'coverflow', 8641 swiper, 8642 on, 8643 setTranslate, 8644 setTransition, 8645 perspective: () => true, 8646 overwriteParams: () => ({ 8647 watchSlidesProgress: true 8648 }) 8649 }); 8650 } 8651 8652 function EffectCreative(_ref) { 8653 let { 8654 swiper, 8655 extendParams, 8656 on 8657 } = _ref; 8658 extendParams({ 8659 creativeEffect: { 8660 limitProgress: 1, 8661 shadowPerProgress: false, 8662 progressMultiplier: 1, 8663 perspective: true, 8664 prev: { 8665 translate: [0, 0, 0], 8666 rotate: [0, 0, 0], 8667 opacity: 1, 8668 scale: 1 8669 }, 8670 next: { 8671 translate: [0, 0, 0], 8672 rotate: [0, 0, 0], 8673 opacity: 1, 8674 scale: 1 8675 } 8676 } 8677 }); 8678 const getTranslateValue = value => { 8679 if (typeof value === 'string') return value; 8680 return `${value}px`; 8681 }; 8682 const setTranslate = () => { 8683 const { 8684 slides, 8685 wrapperEl, 8686 slidesSizesGrid 8687 } = swiper; 8688 const params = swiper.params.creativeEffect; 8689 const { 8690 progressMultiplier: multiplier 8691 } = params; 8692 const isCenteredSlides = swiper.params.centeredSlides; 8693 if (isCenteredSlides) { 8694 const margin = slidesSizesGrid[0] / 2 - swiper.params.slidesOffsetBefore || 0; 8695 wrapperEl.style.transform = `translateX(calc(50% - ${margin}px))`; 8696 } 8697 for (let i = 0; i < slides.length; i += 1) { 8698 const slideEl = slides[i]; 8699 const slideProgress = slideEl.progress; 8700 const progress = Math.min(Math.max(slideEl.progress, -params.limitProgress), params.limitProgress); 8701 let originalProgress = progress; 8702 if (!isCenteredSlides) { 8703 originalProgress = Math.min(Math.max(slideEl.originalProgress, -params.limitProgress), params.limitProgress); 8704 } 8705 const offset = slideEl.swiperSlideOffset; 8706 const t = [swiper.params.cssMode ? -offset - swiper.translate : -offset, 0, 0]; 8707 const r = [0, 0, 0]; 8708 let custom = false; 8709 if (!swiper.isHorizontal()) { 8710 t[1] = t[0]; 8711 t[0] = 0; 8712 } 8713 let data = { 8714 translate: [0, 0, 0], 8715 rotate: [0, 0, 0], 8716 scale: 1, 8717 opacity: 1 8718 }; 8719 if (progress < 0) { 8720 data = params.next; 8721 custom = true; 8722 } else if (progress > 0) { 8723 data = params.prev; 8724 custom = true; 8725 } 8726 // set translate 8727 t.forEach((value, index) => { 8728 t[index] = `calc(${value}px + (${getTranslateValue(data.translate[index])} * ${Math.abs(progress * multiplier)}))`; 8729 }); 8730 // set rotates 8731 r.forEach((value, index) => { 8732 r[index] = data.rotate[index] * Math.abs(progress * multiplier); 8733 }); 8734 slideEl.style.zIndex = -Math.abs(Math.round(slideProgress)) + slides.length; 8735 const translateString = t.join(', '); 8736 const rotateString = `rotateX(${r[0]}deg) rotateY(${r[1]}deg) rotateZ(${r[2]}deg)`; 8737 const scaleString = originalProgress < 0 ? `scale(${1 + (1 - data.scale) * originalProgress * multiplier})` : `scale(${1 - (1 - data.scale) * originalProgress * multiplier})`; 8738 const opacityString = originalProgress < 0 ? 1 + (1 - data.opacity) * originalProgress * multiplier : 1 - (1 - data.opacity) * originalProgress * multiplier; 8739 const transform = `translate3d(${translateString}) ${rotateString} ${scaleString}`; 8740 8741 // Set shadows 8742 if (custom && data.shadow || !custom) { 8743 let shadowEl = slideEl.querySelector('.swiper-slide-shadow'); 8744 if (!shadowEl && data.shadow) { 8745 shadowEl = createShadow(params, slideEl); 8746 } 8747 if (shadowEl) { 8748 const shadowOpacity = params.shadowPerProgress ? progress * (1 / params.limitProgress) : progress; 8749 shadowEl.style.opacity = Math.min(Math.max(Math.abs(shadowOpacity), 0), 1); 8750 } 8751 } 8752 const targetEl = effectTarget(params, slideEl); 8753 targetEl.style.transform = transform; 8754 targetEl.style.opacity = opacityString; 8755 if (data.origin) { 8756 targetEl.style.transformOrigin = opacityString; 8757 } 8758 } 8759 }; 8760 const setTransition = duration => { 8761 const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl)); 8762 transformElements.forEach(el => { 8763 el.style.transitionDuration = `${duration}ms`; 8764 el.querySelectorAll('.swiper-slide-shadow').forEach(shadowEl => { 8765 shadowEl.style.transitionDuration = `${duration}ms`; 8766 }); 8767 }); 8768 effectVirtualTransitionEnd({ 8769 swiper, 8770 duration, 8771 transformElements, 8772 allSlides: true 8773 }); 8774 }; 8775 effectInit({ 8776 effect: 'creative', 8777 swiper, 8778 on, 8779 setTranslate, 8780 setTransition, 8781 perspective: () => swiper.params.creativeEffect.perspective, 8782 overwriteParams: () => ({ 8783 watchSlidesProgress: true, 8784 virtualTranslate: !swiper.params.cssMode 8785 }) 8786 }); 8787 } 8788 8789 function EffectCards(_ref) { 8790 let { 8791 swiper, 8792 extendParams, 8793 on 8794 } = _ref; 8795 extendParams({ 8796 cardsEffect: { 8797 slideShadows: true, 8798 rotate: true, 8799 perSlideRotate: 2, 8800 perSlideOffset: 8 8801 } 8802 }); 8803 const setTranslate = () => { 8804 const { 8805 slides, 8806 activeIndex 8807 } = swiper; 8808 const params = swiper.params.cardsEffect; 8809 const { 8810 startTranslate, 8811 isTouched 8812 } = swiper.touchEventsData; 8813 const currentTranslate = swiper.translate; 8814 for (let i = 0; i < slides.length; i += 1) { 8815 const slideEl = slides[i]; 8816 const slideProgress = slideEl.progress; 8817 const progress = Math.min(Math.max(slideProgress, -4), 4); 8818 let offset = slideEl.swiperSlideOffset; 8819 if (swiper.params.centeredSlides && !swiper.params.cssMode) { 8820 swiper.wrapperEl.style.transform = `translateX(${swiper.minTranslate()}px)`; 8821 } 8822 if (swiper.params.centeredSlides && swiper.params.cssMode) { 8823 offset -= slides[0].swiperSlideOffset; 8824 } 8825 let tX = swiper.params.cssMode ? -offset - swiper.translate : -offset; 8826 let tY = 0; 8827 const tZ = -100 * Math.abs(progress); 8828 let scale = 1; 8829 let rotate = -params.perSlideRotate * progress; 8830 let tXAdd = params.perSlideOffset - Math.abs(progress) * 0.75; 8831 const slideIndex = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.from + i : i; 8832 const isSwipeToNext = (slideIndex === activeIndex || slideIndex === activeIndex - 1) && progress > 0 && progress < 1 && (isTouched || swiper.params.cssMode) && currentTranslate < startTranslate; 8833 const isSwipeToPrev = (slideIndex === activeIndex || slideIndex === activeIndex + 1) && progress < 0 && progress > -1 && (isTouched || swiper.params.cssMode) && currentTranslate > startTranslate; 8834 if (isSwipeToNext || isSwipeToPrev) { 8835 const subProgress = (1 - Math.abs((Math.abs(progress) - 0.5) / 0.5)) ** 0.5; 8836 rotate += -28 * progress * subProgress; 8837 scale += -0.5 * subProgress; 8838 tXAdd += 96 * subProgress; 8839 tY = `${-25 * subProgress * Math.abs(progress)}%`; 8840 } 8841 if (progress < 0) { 8842 // next 8843 tX = `calc(${tX}px + (${tXAdd * Math.abs(progress)}%))`; 8844 } else if (progress > 0) { 8845 // prev 8846 tX = `calc(${tX}px + (-${tXAdd * Math.abs(progress)}%))`; 8847 } else { 8848 tX = `${tX}px`; 8849 } 8850 if (!swiper.isHorizontal()) { 8851 const prevY = tY; 8852 tY = tX; 8853 tX = prevY; 8854 } 8855 const scaleString = progress < 0 ? `${1 + (1 - scale) * progress}` : `${1 - (1 - scale) * progress}`; 8856 const transform = ` 8857 translate3d(${tX}, ${tY}, ${tZ}px) 8858 rotateZ(${params.rotate ? rotate : 0}deg) 8859 scale(${scaleString}) 8860 `; 8861 if (params.slideShadows) { 8862 // Set shadows 8863 let shadowEl = slideEl.querySelector('.swiper-slide-shadow'); 8864 if (!shadowEl) { 8865 shadowEl = createShadow(params, slideEl); 8866 } 8867 if (shadowEl) shadowEl.style.opacity = Math.min(Math.max((Math.abs(progress) - 0.5) / 0.5, 0), 1); 8868 } 8869 slideEl.style.zIndex = -Math.abs(Math.round(slideProgress)) + slides.length; 8870 const targetEl = effectTarget(params, slideEl); 8871 targetEl.style.transform = transform; 8872 } 8873 }; 8874 const setTransition = duration => { 8875 const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl)); 8876 transformElements.forEach(el => { 8877 el.style.transitionDuration = `${duration}ms`; 8878 el.querySelectorAll('.swiper-slide-shadow').forEach(shadowEl => { 8879 shadowEl.style.transitionDuration = `${duration}ms`; 8880 }); 8881 }); 8882 effectVirtualTransitionEnd({ 8883 swiper, 8884 duration, 8885 transformElements 8886 }); 8887 }; 8888 effectInit({ 8889 effect: 'cards', 8890 swiper, 8891 on, 8892 setTranslate, 8893 setTransition, 8894 perspective: () => true, 8895 overwriteParams: () => ({ 8896 watchSlidesProgress: true, 8897 virtualTranslate: !swiper.params.cssMode 8898 }) 8899 }); 8900 } 8901 8902 // Swiper Class 8903 const modules = [Virtual, Keyboard, Mousewheel, Navigation, Pagination, Scrollbar, Parallax, Zoom, Controller, A11y, History, HashNavigation, Autoplay, Thumb, freeMode, Grid, Manipulation, EffectFade, EffectCube, EffectFlip, EffectCoverflow, EffectCreative, EffectCards]; 8904 Swiper.use(modules); 8905 8906 return Swiper; 8907 8908})); 8909//# sourceMappingURL=swiper-bundle.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.