vendor: 4,308 bytes, lines 1-179
1/** 2 * Swiper 9.0.1 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 2, 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,032 bytes, lines 1920-2667
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 } = _temp === void 0 ? {} : _temp; 2085 const swiper = this; 2086 if (!swiper.params.loop) return; 2087 swiper.emit('beforeLoopFix'); 2088 const { 2089 slides, 2090 allowSlidePrev, 2091 allowSlideNext, 2092 slidesEl, 2093 params 2094 } = swiper; 2095 swiper.allowSlidePrev = true; 2096 swiper.allowSlideNext = true; 2097 if (swiper.virtual && params.virtual.enabled) { 2098 if (slideTo) { 2099 if (!params.centeredSlides && swiper.snapIndex === 0) { 2100 swiper.slideTo(swiper.virtual.slides.length, 0, false, true); 2101 } else if (params.centeredSlides && swiper.snapIndex < params.slidesPerView) { 2102 swiper.slideTo(swiper.virtual.slides.length + swiper.snapIndex, 0, false, true); 2103 } else if (swiper.snapIndex === swiper.snapGrid.length - 1) { 2104 swiper.slideTo(swiper.virtual.slidesBefore, 0, false, true); 2105 } 2106 } 2107 swiper.allowSlidePrev = allowSlidePrev; 2108 swiper.allowSlideNext = allowSlideNext; 2109 swiper.emit('loopFix'); 2110 return; 2111 } 2112 const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10)); 2113 let loopedSlides = params.loopedSlides || slidesPerView; 2114 if (loopedSlides % params.slidesPerGroup !== 0) { 2115 loopedSlides += params.slidesPerGroup - loopedSlides % params.slidesPerGroup; 2116 } 2117 swiper.loopedSlides = loopedSlides; 2118 const prependSlidesIndexes = []; 2119 const appendSlidesIndexes = []; 2120 let activeIndex = swiper.activeIndex; 2121 if (typeof activeSlideIndex === 'undefined') { 2122 activeSlideIndex = elementIndex(swiper.slides.filter(el => el.classList.contains('swiper-slide-active'))[0]); 2123 } else { 2124 activeIndex = activeSlideIndex; 2125 } 2126 const isNext = direction === 'next' || !direction; 2127 const isPrev = direction === 'prev' || !direction; 2128 let slidesPrepended = 0; 2129 let slidesAppended = 0; 2130 // prepend last slides before start 2131 if (activeSlideIndex < loopedSlides) { 2132 slidesPrepended = loopedSlides - activeSlideIndex; 2133 for (let i = 0; i < loopedSlides - activeSlideIndex; i += 1) { 2134 const index = i - Math.floor(i / slides.length) * slides.length; 2135 prependSlidesIndexes.push(slides.length - index - 1); 2136 } 2137 } else if (activeSlideIndex /* + slidesPerView */ > swiper.slides.length - loopedSlides * 2) { 2138 slidesAppended = activeSlideIndex - (swiper.slides.length - loopedSlides * 2); 2139 for (let i = 0; i < slidesAppended; i += 1) { 2140 const index = i - Math.floor(i / slides.length) * slides.length; 2141 appendSlidesIndexes.push(index); 2142 } 2143 } 2144 if (isPrev) { 2145 prependSlidesIndexes.forEach(index => { 2146 slidesEl.prepend(swiper.slides[index]); 2147 }); 2148 } 2149 if (isNext) { 2150 appendSlidesIndexes.forEach(index => { 2151 slidesEl.append(swiper.slides[index]); 2152 }); 2153 } 2154 swiper.recalcSlides(); 2155 if (params.watchSlidesProgress) { 2156 swiper.updateSlidesOffset(); 2157 } 2158 if (slideTo) { 2159 if (prependSlidesIndexes.length > 0 && isPrev) { 2160 if (typeof slideRealIndex === 'undefined') { 2161 const currentSlideTranslate = swiper.slidesGrid[activeIndex]; 2162 const newSlideTranslate = swiper.slidesGrid[activeIndex + slidesPrepended]; 2163 const diff = newSlideTranslate - currentSlideTranslate; 2164 swiper.slideTo(activeIndex + slidesPrepended, 0, false, true); 2165 if (setTranslate) { 2166 swiper.touches[swiper.isHorizontal() ? 'startX' : 'startY'] += diff; 2167 } 2168 } else { 2169 if (setTranslate) { 2170 swiper.slideToLoop(slideRealIndex, 0, false, true); 2171 } 2172 } 2173 } else if (appendSlidesIndexes.length > 0 && isNext) { 2174 if (typeof slideRealIndex === 'undefined') { 2175 const currentSlideTranslate = swiper.slidesGrid[activeIndex]; 2176 const newSlideTranslate = swiper.slidesGrid[activeIndex - slidesAppended]; 2177 const diff = newSlideTranslate - currentSlideTranslate; 2178 swiper.slideTo(activeIndex - slidesAppended, 0, false, true); 2179 if (setTranslate) { 2180 swiper.touches[swiper.isHorizontal() ? 'startX' : 'startY'] += diff; 2181 } 2182 } else { 2183 swiper.slideToLoop(slideRealIndex, 0, false, true); 2184 } 2185 } 2186 } 2187 swiper.allowSlidePrev = allowSlidePrev; 2188 swiper.allowSlideNext = allowSlideNext; 2189 if (swiper.controller && swiper.controller.control && !byController) { 2190 const loopParams = { 2191 slideRealIndex, 2192 slideTo: false, 2193 direction, 2194 setTranslate, 2195 activeSlideIndex, 2196 byController: true 2197 }; 2198 if (Array.isArray(swiper.controller.control)) { 2199 swiper.controller.control.forEach(c => { 2200 if (c.params.loop) c.loopFix(loopParams); 2201 }); 2202 } else if (swiper.controller.control instanceof swiper.constructor && swiper.controller.control.params.loop) { 2203 swiper.controller.control.loopFix(loopParams); 2204 } 2205 } 2206 swiper.emit('loopFix'); 2207 } 2208 2209 function loopDestroy() { 2210 const swiper = this; 2211 const { 2212 slides, 2213 params, 2214 slidesEl 2215 } = swiper; 2216 if (!params.loop || swiper.virtual && swiper.params.virtual.enabled) return; 2217 swiper.recalcSlides(); 2218 const newSlidesOrder = []; 2219 slides.forEach(slideEl => { 2220 const index = typeof slideEl.swiperSlideIndex === 'undefined' ? slideEl.getAttribute('data-swiper-slide-index') * 1 : slideEl.swiperSlideIndex; 2221 newSlidesOrder[index] = slideEl; 2222 }); 2223 slides.forEach(slideEl => { 2224 slideEl.removeAttribute('data-swiper-slide-index'); 2225 }); 2226 newSlidesOrder.forEach(slideEl => { 2227 slidesEl.append(slideEl); 2228 }); 2229 swiper.recalcSlides(); 2230 swiper.slideTo(swiper.realIndex, 0); 2231 } 2232 2233 var loop = { 2234 loopCreate, 2235 loopFix, 2236 loopDestroy 2237 }; 2238 2239 function setGrabCursor(moving) { 2240 const swiper = this; 2241 if (!swiper.params.simulateTouch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) return; 2242 const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl; 2243 el.style.cursor = 'move'; 2244 el.style.cursor = moving ? 'grabbing' : 'grab'; 2245 } 2246 2247 function unsetGrabCursor() { 2248 const swiper = this; 2249 if (swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) { 2250 return; 2251 } 2252 swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = ''; 2253 } 2254 2255 var grabCursor = { 2256 setGrabCursor, 2257 unsetGrabCursor 2258 }; 2259 2260 // Modified from https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd 2261 function closestElement(selector, base) { 2262 if (base === void 0) { 2263 base = this; 2264 } 2265 function __closestFrom(el) { 2266 if (!el || el === getDocument() || el === getWindow()) return null; 2267 if (el.assignedSlot) el = el.assignedSlot; 2268 const found = el.closest(selector); 2269 if (!found && !el.getRootNode) { 2270 return null; 2271 } 2272 return found || __closestFrom(el.getRootNode().host); 2273 } 2274 return __closestFrom(base); 2275 } 2276 function onTouchStart(event) { 2277 const swiper = this; 2278 const document = getDocument(); 2279 const window = getWindow(); 2280 const data = swiper.touchEventsData; 2281 data.evCache.push(event); 2282 const { 2283 params, 2284 touches, 2285 enabled 2286 } = swiper; 2287 if (!enabled) return; 2288 if (!params.simulateTouch && event.pointerType === 'mouse') return; 2289 if (swiper.animating && params.preventInteractionOnTransition) { 2290 return; 2291 } 2292 if (!swiper.animating && params.cssMode && params.loop) { 2293 swiper.loopFix(); 2294 } 2295 let e = event; 2296 if (e.originalEvent) e = e.originalEvent; 2297 let targetEl = e.target; 2298 if (params.touchEventsTarget === 'wrapper') { 2299 if (!swiper.wrapperEl.contains(targetEl)) return; 2300 } 2301 if ('which' in e && e.which === 3) return; 2302 if ('button' in e && e.button > 0) return; 2303 if (data.isTouched && data.isMoved) return; 2304 2305 // change target el for shadow root component 2306 const swipingClassHasValue = !!params.noSwipingClass && params.noSwipingClass !== ''; 2307 // eslint-disable-next-line 2308 const eventPath = event.composedPath ? event.composedPath() : event.path; 2309 if (swipingClassHasValue && e.target && e.target.shadowRoot && eventPath) { 2310 targetEl = eventPath[0]; 2311 } 2312 const noSwipingSelector = params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`; 2313 const isTargetShadow = !!(e.target && e.target.shadowRoot); 2314 2315 // use closestElement for shadow root element to get the actual closest for nested shadow root element 2316 if (params.noSwiping && (isTargetShadow ? closestElement(noSwipingSelector, targetEl) : targetEl.closest(noSwipingSelector))) { 2317 swiper.allowClick = true; 2318 return; 2319 } 2320 if (params.swipeHandler) { 2321 if (!targetEl.closest(params.swipeHandler)) return; 2322 } 2323 touches.currentX = e.pageX; 2324 touches.currentY = e.pageY; 2325 const startX = touches.currentX; 2326 const startY = touches.currentY; 2327 2328 // Do NOT start if iOS edge swipe is detected. Otherwise iOS app cannot swipe-to-go-back anymore 2329 2330 const edgeSwipeDetection = params.edgeSwipeDetection || params.iOSEdgeSwipeDetection; 2331 const edgeSwipeThreshold = params.edgeSwipeThreshold || params.iOSEdgeSwipeThreshold; 2332 if (edgeSwipeDetection && (startX <= edgeSwipeThreshold || startX >= window.innerWidth - edgeSwipeThreshold)) { 2333 if (edgeSwipeDetection === 'prevent') { 2334 event.preventDefault(); 2335 } else { 2336 return; 2337 } 2338 } 2339 Object.assign(data, { 2340 isTouched: true, 2341 isMoved: false, 2342 allowTouchCallbacks: true, 2343 isScrolling: undefined, 2344 startMoving: undefined 2345 }); 2346 touches.startX = startX; 2347 touches.startY = startY; 2348 data.touchStartTime = now(); 2349 swiper.allowClick = true; 2350 swiper.updateSize(); 2351 swiper.swipeDirection = undefined; 2352 if (params.threshold > 0) data.allowThresholdMove = false; 2353 let preventDefault = true; 2354 if (targetEl.matches(data.focusableElements)) { 2355 preventDefault = false; 2356 if (targetEl.nodeName === 'SELECT') { 2357 data.isTouched = false; 2358 } 2359 } 2360 if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== targetEl) { 2361 document.activeElement.blur(); 2362 } 2363 const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault; 2364 if ((params.touchStartForcePreventDefault || shouldPreventDefault) && !targetEl.isContentEditable) { 2365 e.preventDefault(); 2366 } 2367 if (swiper.params.freeMode && swiper.params.freeMode.enabled && swiper.freeMode && swiper.animating && !params.cssMode) { 2368 swiper.freeMode.onTouchStart(); 2369 } 2370 swiper.emit('touchStart', e); 2371 } 2372 2373 function onTouchMove(event) { 2374 const document = getDocument(); 2375 const swiper = this; 2376 const data = swiper.touchEventsData; 2377 const { 2378 params, 2379 touches, 2380 rtlTranslate: rtl, 2381 enabled 2382 } = swiper; 2383 if (!enabled) return; 2384 if (!params.simulateTouch && event.pointerType === 'mouse') return; 2385 let e = event; 2386 if (e.originalEvent) e = e.originalEvent; 2387 if (!data.isTouched) { 2388 if (data.startMoving && data.isScrolling) { 2389 swiper.emit('touchMoveOpposite', e); 2390 } 2391 return; 2392 } 2393 const pointerIndex = data.evCache.findIndex(cachedEv => cachedEv.pointerId === e.pointerId); 2394 if (pointerIndex >= 0) data.evCache[pointerIndex] = e; 2395 const targetTouch = data.evCache.length > 1 ? data.evCache[0] : e; 2396 const pageX = targetTouch.pageX; 2397 const pageY = targetTouch.pageY; 2398 if (e.preventedByNestedSwiper) { 2399 touches.startX = pageX; 2400 touches.startY = pageY; 2401 return; 2402 } 2403 if (!swiper.allowTouchMove) { 2404 if (!e.target.matches(data.focusableElements)) { 2405 swiper.allowClick = false; 2406 } 2407 if (data.isTouched) { 2408 Object.assign(touches, { 2409 startX: pageX, 2410 startY: pageY, 2411 prevX: swiper.touches.currentX, 2412 prevY: swiper.touches.currentY, 2413 currentX: pageX, 2414 currentY: pageY 2415 }); 2416 data.touchStartTime = now(); 2417 } 2418 return; 2419 } 2420 if (params.touchReleaseOnEdges && !params.loop) { 2421 if (swiper.isVertical()) { 2422 // Vertical 2423 if (pageY < touches.startY && swiper.translate <= swiper.maxTranslate() || pageY > touches.startY && swiper.translate >= swiper.minTranslate()) { 2424 data.isTouched = false; 2425 data.isMoved = false; 2426 return; 2427 } 2428 } else if (pageX < touches.startX && swiper.translate <= swiper.maxTranslate() || pageX > touches.startX && swiper.translate >= swiper.minTranslate()) { 2429 return; 2430 } 2431 } 2432 if (document.activeElement) { 2433 if (e.target === document.activeElement && e.target.matches(data.focusableElements)) { 2434 data.isMoved = true; 2435 swiper.allowClick = false; 2436 return; 2437 } 2438 } 2439 if (data.allowTouchCallbacks) { 2440 swiper.emit('touchMove', e); 2441 } 2442 if (e.targetTouches && e.targetTouches.length > 1) return; 2443 touches.currentX = pageX; 2444 touches.currentY = pageY; 2445 const diffX = touches.currentX - touches.startX; 2446 const diffY = touches.currentY - touches.startY; 2447 if (swiper.params.threshold && Math.sqrt(diffX ** 2 + diffY ** 2) < swiper.params.threshold) return; 2448 if (typeof data.isScrolling === 'undefined') { 2449 let touchAngle; 2450 if (swiper.isHorizontal() && touches.currentY === touches.startY || swiper.isVertical() && touches.currentX === touches.startX) { 2451 data.isScrolling = false; 2452 } else { 2453 // eslint-disable-next-line 2454 if (diffX * diffX + diffY * diffY >= 25) { 2455 touchAngle = Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180 / Math.PI; 2456 data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : 90 - touchAngle > params.touchAngle; 2457 } 2458 } 2459 } 2460 if (data.isScrolling) { 2461 swiper.emit('touchMoveOpposite', e); 2462 } 2463 if (typeof data.startMoving === 'undefined') { 2464 if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) { 2465 data.startMoving = true; 2466 } 2467 } 2468 if (data.isScrolling || swiper.zoom && swiper.params.zoom && swiper.params.zoom.enabled && data.evCache.length > 1) { 2469 data.isTouched = false; 2470 return; 2471 } 2472 if (!data.startMoving) { 2473 return; 2474 } 2475 swiper.allowClick = false; 2476 if (!params.cssMode && e.cancelable) { 2477 e.preventDefault(); 2478 } 2479 if (params.touchMoveStopPropagation && !params.nested) { 2480 e.stopPropagation(); 2481 } 2482 let diff = swiper.isHorizontal() ? diffX : diffY; 2483 let touchesDiff = swiper.isHorizontal() ? touches.currentX - touches.previousX : touches.currentY - touches.previousY; 2484 if (params.oneWayMovement) { 2485 diff = Math.abs(diff) * (rtl ? 1 : -1); 2486 touchesDiff = Math.abs(touchesDiff) * (rtl ? 1 : -1); 2487 } 2488 touches.diff = diff; 2489 diff *= params.touchRatio; 2490 if (rtl) { 2491 diff = -diff; 2492 touchesDiff = -touchesDiff; 2493 } 2494 const prevTouchesDirection = swiper.touchesDirection; 2495 swiper.swipeDirection = diff > 0 ? 'prev' : 'next'; 2496 swiper.touchesDirection = touchesDiff > 0 ? 'prev' : 'next'; 2497 const isLoop = swiper.params.loop && !(swiper.virtual && swiper.params.virtual.enabled) && !params.cssMode; 2498 if (!data.isMoved) { 2499 if (isLoop) { 2500 swiper.loopFix({ 2501 direction: swiper.swipeDirection 2502 }); 2503 } 2504 data.startTranslate = swiper.getTranslate(); 2505 swiper.setTransition(0); 2506 if (swiper.animating) { 2507 const evt = new window.CustomEvent('transitionend', { 2508 bubbles: true, 2509 cancelable: true 2510 }); 2511 swiper.wrapperEl.dispatchEvent(evt); 2512 } 2513 data.allowMomentumBounce = false; 2514 // Grab Cursor 2515 if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) { 2516 swiper.setGrabCursor(true); 2517 } 2518 swiper.emit('sliderFirstMove', e); 2519 } 2520 let loopFixed; 2521 if (data.isMoved && prevTouchesDirection !== swiper.touchesDirection && isLoop && Math.abs(diff) >= 1) { 2522 // need another loop fix 2523 swiper.loopFix({ 2524 direction: swiper.swipeDirection, 2525 setTranslate: true 2526 }); 2527 loopFixed = true; 2528 } 2529 swiper.emit('sliderMove', e); 2530 data.isMoved = true; 2531 data.currentTranslate = diff + data.startTranslate; 2532 let disableParentSwiper = true; 2533 let resistanceRatio = params.resistanceRatio; 2534 if (params.touchReleaseOnEdges) { 2535 resistanceRatio = 0; 2536 } 2537 if (diff > 0) { 2538 if (isLoop && !loopFixed && data.currentTranslate > (params.centeredSlides ? swiper.minTranslate() - swiper.size / 2 : swiper.minTranslate())) { 2539 swiper.loopFix({ 2540 direction: 'prev', 2541 setTranslate: true, 2542 activeSlideIndex: 0 2543 }); 2544 } 2545 if (data.currentTranslate > swiper.minTranslate()) { 2546 disableParentSwiper = false; 2547 if (params.resistance) { 2548 data.currentTranslate = swiper.minTranslate() - 1 + (-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio; 2549 } 2550 } 2551 } else if (diff < 0) { 2552 if (isLoop && !loopFixed && data.currentTranslate < (params.centeredSlides ? swiper.maxTranslate() + swiper.size / 2 : swiper.maxTranslate())) { 2553 swiper.loopFix({ 2554 direction: 'next', 2555 setTranslate: true, 2556 activeSlideIndex: swiper.slides.length - (params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10))) 2557 }); 2558 } 2559 if (data.currentTranslate < swiper.maxTranslate()) { 2560 disableParentSwiper = false; 2561 if (params.resistance) { 2562 data.currentTranslate = swiper.maxTranslate() + 1 - (swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio; 2563 } 2564 } 2565 } 2566 if (disableParentSwiper) { 2567 e.preventedByNestedSwiper = true; 2568 } 2569 2570 // Directions locks 2571 if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) { 2572 data.currentTranslate = data.startTranslate; 2573 } 2574 if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) { 2575 data.currentTranslate = data.startTranslate; 2576 } 2577 if (!swiper.allowSlidePrev && !swiper.allowSlideNext) { 2578 data.currentTranslate = data.startTranslate; 2579 } 2580 2581 // Threshold 2582 if (params.threshold > 0) { 2583 if (Math.abs(diff) > params.threshold || data.allowThresholdMove) { 2584 if (!data.allowThresholdMove) { 2585 data.allowThresholdMove = true; 2586 touches.startX = touches.currentX; 2587 touches.startY = touches.currentY; 2588 data.currentTranslate = data.startTranslate; 2589 touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY; 2590 return; 2591 } 2592 } else { 2593 data.currentTranslate = data.startTranslate; 2594 return; 2595 } 2596 } 2597 if (!params.followFinger || params.cssMode) return; 2598 2599 // Update active index in free mode 2600 if (params.freeMode && params.freeMode.enabled && swiper.freeMode || params.watchSlidesProgress) { 2601 swiper.updateActiveIndex(); 2602 swiper.updateSlidesClasses(); 2603 } 2604 if (swiper.params.freeMode && params.freeMode.enabled && swiper.freeMode) { 2605 swiper.freeMode.onTouchMove(); 2606 } 2607 // Update progress 2608 swiper.updateProgress(data.currentTranslate); 2609 // Update translate 2610 swiper.setTranslate(data.currentTranslate); 2611 } 2612 2613 function onTouchEnd(event) { 2614 const swiper = this; 2615 const data = swiper.touchEventsData; 2616 const pointerIndex = data.evCache.findIndex(cachedEv => cachedEv.pointerId === event.pointerId); 2617 if (pointerIndex >= 0) { 2618 data.evCache.splice(pointerIndex, 1); 2619 } 2620 if (['pointercancel', 'pointerout', 'pointerleave'].includes(event.type)) return; 2621 const { 2622 params, 2623 touches, 2624 rtlTranslate: rtl, 2625 slidesGrid, 2626 enabled 2627 } = swiper; 2628 if (!enabled) return; 2629 if (!params.simulateTouch && event.pointerType === 'mouse') return; 2630 let e = event; 2631 if (e.originalEvent) e = e.originalEvent; 2632 if (data.allowTouchCallbacks) { 2633 swiper.emit('touchEnd', e); 2634 } 2635 data.allowTouchCallbacks = false; 2636 if (!data.isTouched) { 2637 if (data.isMoved && params.grabCursor) { 2638 swiper.setGrabCursor(false); 2639 } 2640 data.isMoved = false; 2641 data.startMoving = false; 2642 return; 2643 } 2644 // Return Grab Cursor 2645 if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) { 2646 swiper.setGrabCursor(false); 2647 } 2648 2649 // Time diff 2650 const touchEndTime = now(); 2651 const timeDiff = touchEndTime - data.touchStartTime; 2652 2653 // Tap, doubleTap, Click 2654 if (swiper.allowClick) { 2655 const pathTree = e.path || e.composedPath && e.composedPath(); 2656 swiper.updateClickedSlide(pathTree && pathTree[0] || e.target); 2657 swiper.emit('tap click', e); 2658 if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) { 2659 swiper.emit('doubleTap doubleClick', e); 2660 } 2661 } 2662 data.lastClickTime = now(); 2663 nextTick(() => { 2664 if (!swiper.destroyed) swiper.allowClick = true; 2665 }); 2666 if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 || data.currentTranslate === data.startTranslate) { 2667 data.isTouched = false;
vendor: 3,671 bytes, lines 2668-2766
2668 data.isMoved = false; 2669 data.startMoving = false; 2670 return; 2671 } 2672 data.isTouched = false; 2673 data.isMoved = false; 2674 data.startMoving = false; 2675 let currentPos; 2676 if (params.followFinger) { 2677 currentPos = rtl ? swiper.translate : -swiper.translate; 2678 } else { 2679 currentPos = -data.currentTranslate; 2680 } 2681 if (params.cssMode) { 2682 return; 2683 } 2684 if (swiper.params.freeMode && params.freeMode.enabled) { 2685 swiper.freeMode.onTouchEnd({ 2686 currentPos 2687 }); 2688 return; 2689 } 2690 2691 // Find current slide 2692 let stopIndex = 0; 2693 let groupSize = swiper.slidesSizesGrid[0]; 2694 for (let i = 0; i < slidesGrid.length; i += i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup) { 2695 const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup; 2696 if (typeof slidesGrid[i + increment] !== 'undefined') { 2697 if (currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) { 2698 stopIndex = i; 2699 groupSize = slidesGrid[i + increment] - slidesGrid[i]; 2700 } 2701 } else if (currentPos >= slidesGrid[i]) { 2702 stopIndex = i; 2703 groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2]; 2704 } 2705 } 2706 let rewindFirstIndex = null; 2707 let rewindLastIndex = null; 2708 if (params.rewind) { 2709 if (swiper.isBeginning) { 2710 rewindLastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1; 2711 } else if (swiper.isEnd) { 2712 rewindFirstIndex = 0; 2713 } 2714 } 2715 // Find current slide size 2716 const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize; 2717 const increment = stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup; 2718 if (timeDiff > params.longSwipesMs) { 2719 // Long touches 2720 if (!params.longSwipes) { 2721 swiper.slideTo(swiper.activeIndex); 2722 return; 2723 } 2724 if (swiper.swipeDirection === 'next') { 2725 if (ratio >= params.longSwipesRatio) swiper.slideTo(params.rewind && swiper.isEnd ? rewindFirstIndex : stopIndex + increment);else swiper.slideTo(stopIndex); 2726 } 2727 if (swiper.swipeDirection === 'prev') { 2728 if (ratio > 1 - params.longSwipesRatio) { 2729 swiper.slideTo(stopIndex + increment); 2730 } else if (rewindLastIndex !== null && ratio < 0 && Math.abs(ratio) > params.longSwipesRatio) { 2731 swiper.slideTo(rewindLastIndex); 2732 } else { 2733 swiper.slideTo(stopIndex); 2734 } 2735 } 2736 } else { 2737 // Short swipes 2738 if (!params.shortSwipes) { 2739 swiper.slideTo(swiper.activeIndex); 2740 return; 2741 } 2742 const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl); 2743 if (!isNavButtonTarget) { 2744 if (swiper.swipeDirection === 'next') { 2745 swiper.slideTo(rewindFirstIndex !== null ? rewindFirstIndex : stopIndex + increment); 2746 } 2747 if (swiper.swipeDirection === 'prev') { 2748 swiper.slideTo(rewindLastIndex !== null ? rewindLastIndex : stopIndex); 2749 } 2750 } else if (e.target === swiper.navigation.nextEl) { 2751 swiper.slideTo(stopIndex + increment); 2752 } else { 2753 swiper.slideTo(stopIndex); 2754 } 2755 } 2756 } 2757 2758 let timeout; 2759 function onResize() { 2760 const swiper = this; 2761 const { 2762 params, 2763 el 2764 } = swiper; 2765 if (el && el.offsetWidth === 0) return; 2766
vendor: 12,398 bytes, lines 2767-3144
2767 // Breakpoints 2768 if (params.breakpoints) { 2769 swiper.setBreakpoint(); 2770 } 2771 2772 // Save locks 2773 const { 2774 allowSlideNext, 2775 allowSlidePrev, 2776 snapGrid 2777 } = swiper; 2778 const isVirtual = swiper.virtual && swiper.params.virtual.enabled; 2779 2780 // Disable locks on resize 2781 swiper.allowSlideNext = true; 2782 swiper.allowSlidePrev = true; 2783 swiper.updateSize(); 2784 swiper.updateSlides(); 2785 swiper.updateSlidesClasses(); 2786 const isVirtualLoop = isVirtual && params.loop; 2787 if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.isBeginning && !swiper.params.centeredSlides && !isVirtualLoop) { 2788 swiper.slideTo(swiper.slides.length - 1, 0, false, true); 2789 } else { 2790 if (swiper.params.loop && !isVirtual) { 2791 swiper.slideToLoop(swiper.realIndex, 0, false, true); 2792 } else { 2793 swiper.slideTo(swiper.activeIndex, 0, false, true); 2794 } 2795 } 2796 if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) { 2797 clearTimeout(timeout); 2798 timeout = setTimeout(() => { 2799 swiper.autoplay.resume(); 2800 }, 500); 2801 } 2802 // Return locks after resize 2803 swiper.allowSlidePrev = allowSlidePrev; 2804 swiper.allowSlideNext = allowSlideNext; 2805 if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) { 2806 swiper.checkOverflow(); 2807 } 2808 } 2809 2810 function onClick(e) { 2811 const swiper = this; 2812 if (!swiper.enabled) return; 2813 if (!swiper.allowClick) { 2814 if (swiper.params.preventClicks) e.preventDefault(); 2815 if (swiper.params.preventClicksPropagation && swiper.animating) { 2816 e.stopPropagation(); 2817 e.stopImmediatePropagation(); 2818 } 2819 } 2820 } 2821 2822 function onScroll() { 2823 const swiper = this; 2824 const { 2825 wrapperEl, 2826 rtlTranslate, 2827 enabled 2828 } = swiper; 2829 if (!enabled) return; 2830 swiper.previousTranslate = swiper.translate; 2831 if (swiper.isHorizontal()) { 2832 swiper.translate = -wrapperEl.scrollLeft; 2833 } else { 2834 swiper.translate = -wrapperEl.scrollTop; 2835 } 2836 // eslint-disable-next-line 2837 if (swiper.translate === 0) swiper.translate = 0; 2838 swiper.updateActiveIndex(); 2839 swiper.updateSlidesClasses(); 2840 let newProgress; 2841 const translatesDiff = swiper.maxTranslate() - swiper.minTranslate(); 2842 if (translatesDiff === 0) { 2843 newProgress = 0; 2844 } else { 2845 newProgress = (swiper.translate - swiper.minTranslate()) / translatesDiff; 2846 } 2847 if (newProgress !== swiper.progress) { 2848 swiper.updateProgress(rtlTranslate ? -swiper.translate : swiper.translate); 2849 } 2850 swiper.emit('setTranslate', swiper.translate, false); 2851 } 2852 2853 const processLazyPreloader = (swiper, imageEl) => { 2854 const slideSelector = () => swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`; 2855 const slideEl = imageEl.closest(slideSelector()); 2856 if (slideEl) { 2857 const lazyEl = slideEl.querySelector(`.${swiper.params.lazyPreloaderClass}`); 2858 if (lazyEl) lazyEl.remove(); 2859 } 2860 }; 2861 2862 function onLoad(e) { 2863 const swiper = this; 2864 processLazyPreloader(swiper, e.target); 2865 swiper.update(); 2866 } 2867 2868 let dummyEventAttached = false; 2869 function dummyEventListener() {} 2870 const events = (swiper, method) => { 2871 const document = getDocument(); 2872 const { 2873 params, 2874 el, 2875 wrapperEl, 2876 device 2877 } = swiper; 2878 const capture = !!params.nested; 2879 const domMethod = method === 'on' ? 'addEventListener' : 'removeEventListener'; 2880 const swiperMethod = method; 2881 2882 // Touch Events 2883 el[domMethod]('pointerdown', swiper.onTouchStart, { 2884 passive: false 2885 }); 2886 document[domMethod]('pointermove', swiper.onTouchMove, { 2887 passive: false, 2888 capture 2889 }); 2890 document[domMethod]('pointerup', swiper.onTouchEnd, { 2891 passive: true 2892 }); 2893 document[domMethod]('pointercancel', swiper.onTouchEnd, { 2894 passive: true 2895 }); 2896 document[domMethod]('pointerout', swiper.onTouchEnd, { 2897 passive: true 2898 }); 2899 document[domMethod]('pointerleave', swiper.onTouchEnd, { 2900 passive: true 2901 }); 2902 2903 // Prevent Links Clicks 2904 if (params.preventClicks || params.preventClicksPropagation) { 2905 el[domMethod]('click', swiper.onClick, true); 2906 } 2907 if (params.cssMode) { 2908 wrapperEl[domMethod]('scroll', swiper.onScroll); 2909 } 2910 2911 // Resize handler 2912 if (params.updateOnWindowResize) { 2913 swiper[swiperMethod](device.ios || device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate', onResize, true); 2914 } else { 2915 swiper[swiperMethod]('observerUpdate', onResize, true); 2916 } 2917 2918 // Images loader 2919 el[domMethod]('load', swiper.onLoad, { 2920 capture: true 2921 }); 2922 }; 2923 function attachEvents() { 2924 const swiper = this; 2925 const document = getDocument(); 2926 const { 2927 params 2928 } = swiper; 2929 swiper.onTouchStart = onTouchStart.bind(swiper); 2930 swiper.onTouchMove = onTouchMove.bind(swiper); 2931 swiper.onTouchEnd = onTouchEnd.bind(swiper); 2932 if (params.cssMode) { 2933 swiper.onScroll = onScroll.bind(swiper); 2934 } 2935 swiper.onClick = onClick.bind(swiper); 2936 swiper.onLoad = onLoad.bind(swiper); 2937 if (!dummyEventAttached) { 2938 document.addEventListener('touchstart', dummyEventListener); 2939 dummyEventAttached = true; 2940 } 2941 events(swiper, 'on'); 2942 } 2943 function detachEvents() { 2944 const swiper = this; 2945 events(swiper, 'off'); 2946 } 2947 var events$1 = { 2948 attachEvents, 2949 detachEvents 2950 }; 2951 2952 const isGridEnabled = (swiper, params) => { 2953 return swiper.grid && params.grid && params.grid.rows > 1; 2954 }; 2955 function setBreakpoint() { 2956 const swiper = this; 2957 const { 2958 realIndex, 2959 initialized, 2960 params, 2961 el 2962 } = swiper; 2963 const breakpoints = params.breakpoints; 2964 if (!breakpoints || breakpoints && Object.keys(breakpoints).length === 0) return; 2965 2966 // Get breakpoint for window width and update parameters 2967 const breakpoint = swiper.getBreakpoint(breakpoints, swiper.params.breakpointsBase, swiper.el); 2968 if (!breakpoint || swiper.currentBreakpoint === breakpoint) return; 2969 const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints[breakpoint] : undefined; 2970 const breakpointParams = breakpointOnlyParams || swiper.originalParams; 2971 const wasMultiRow = isGridEnabled(swiper, params); 2972 const isMultiRow = isGridEnabled(swiper, breakpointParams); 2973 const wasEnabled = params.enabled; 2974 if (wasMultiRow && !isMultiRow) { 2975 el.classList.remove(`${params.containerModifierClass}grid`, `${params.containerModifierClass}grid-column`); 2976 swiper.emitContainerClasses(); 2977 } else if (!wasMultiRow && isMultiRow) { 2978 el.classList.add(`${params.containerModifierClass}grid`); 2979 if (breakpointParams.grid.fill && breakpointParams.grid.fill === 'column' || !breakpointParams.grid.fill && params.grid.fill === 'column') { 2980 el.classList.add(`${params.containerModifierClass}grid-column`); 2981 } 2982 swiper.emitContainerClasses(); 2983 } 2984 2985 // Toggle navigation, pagination, scrollbar 2986 ['navigation', 'pagination', 'scrollbar'].forEach(prop => { 2987 const wasModuleEnabled = params[prop] && params[prop].enabled; 2988 const isModuleEnabled = breakpointParams[prop] && breakpointParams[prop].enabled; 2989 if (wasModuleEnabled && !isModuleEnabled) { 2990 swiper[prop].disable(); 2991 } 2992 if (!wasModuleEnabled && isModuleEnabled) { 2993 swiper[prop].enable(); 2994 } 2995 }); 2996 const directionChanged = breakpointParams.direction && breakpointParams.direction !== params.direction; 2997 const needsReLoop = params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged); 2998 if (directionChanged && initialized) { 2999 swiper.changeDirection(); 3000 } 3001 extend(swiper.params, breakpointParams); 3002 const isEnabled = swiper.params.enabled; 3003 Object.assign(swiper, { 3004 allowTouchMove: swiper.params.allowTouchMove, 3005 allowSlideNext: swiper.params.allowSlideNext, 3006 allowSlidePrev: swiper.params.allowSlidePrev 3007 }); 3008 if (wasEnabled && !isEnabled) { 3009 swiper.disable(); 3010 } else if (!wasEnabled && isEnabled) { 3011 swiper.enable(); 3012 } 3013 swiper.currentBreakpoint = breakpoint; 3014 swiper.emit('_beforeBreakpoint', breakpointParams); 3015 if (needsReLoop && initialized) { 3016 swiper.loopDestroy(); 3017 swiper.loopCreate(realIndex); 3018 swiper.updateSlides(); 3019 } 3020 swiper.emit('breakpoint', breakpointParams); 3021 } 3022 3023 function getBreakpoint(breakpoints, base, containerEl) { 3024 if (base === void 0) { 3025 base = 'window'; 3026 } 3027 if (!breakpoints || base === 'container' && !containerEl) return undefined; 3028 let breakpoint = false; 3029 const window = getWindow(); 3030 const currentHeight = base === 'window' ? window.innerHeight : containerEl.clientHeight; 3031 const points = Object.keys(breakpoints).map(point => { 3032 if (typeof point === 'string' && point.indexOf('@') === 0) { 3033 const minRatio = parseFloat(point.substr(1)); 3034 const value = currentHeight * minRatio; 3035 return { 3036 value, 3037 point 3038 }; 3039 } 3040 return { 3041 value: point, 3042 point 3043 }; 3044 }); 3045 points.sort((a, b) => parseInt(a.value, 10) - parseInt(b.value, 10)); 3046 for (let i = 0; i < points.length; i += 1) { 3047 const { 3048 point, 3049 value 3050 } = points[i]; 3051 if (base === 'window') { 3052 if (window.matchMedia(`(min-width: ${value}px)`).matches) { 3053 breakpoint = point; 3054 } 3055 } else if (value <= containerEl.clientWidth) { 3056 breakpoint = point; 3057 } 3058 } 3059 return breakpoint || 'max'; 3060 } 3061 3062 var breakpoints = { 3063 setBreakpoint, 3064 getBreakpoint 3065 }; 3066 3067 function prepareClasses(entries, prefix) { 3068 const resultClasses = []; 3069 entries.forEach(item => { 3070 if (typeof item === 'object') { 3071 Object.keys(item).forEach(classNames => { 3072 if (item[classNames]) { 3073 resultClasses.push(prefix + classNames); 3074 } 3075 }); 3076 } else if (typeof item === 'string') { 3077 resultClasses.push(prefix + item); 3078 } 3079 }); 3080 return resultClasses; 3081 } 3082 function addClasses() { 3083 const swiper = this; 3084 const { 3085 classNames, 3086 params, 3087 rtl, 3088 el, 3089 device 3090 } = swiper; 3091 // prettier-ignore 3092 const suffixes = prepareClasses(['initialized', params.direction, { 3093 'free-mode': swiper.params.freeMode && params.freeMode.enabled 3094 }, { 3095 'autoheight': params.autoHeight 3096 }, { 3097 'rtl': rtl 3098 }, { 3099 'grid': params.grid && params.grid.rows > 1 3100 }, { 3101 'grid-column': params.grid && params.grid.rows > 1 && params.grid.fill === 'column' 3102 }, { 3103 'android': device.android 3104 }, { 3105 'ios': device.ios 3106 }, { 3107 'css-mode': params.cssMode 3108 }, { 3109 'centered': params.cssMode && params.centeredSlides 3110 }, { 3111 'watch-progress': params.watchSlidesProgress 3112 }], params.containerModifierClass); 3113 classNames.push(...suffixes); 3114 el.classList.add(...classNames); 3115 swiper.emitContainerClasses(); 3116 } 3117 3118 function removeClasses() { 3119 const swiper = this; 3120 const { 3121 el, 3122 classNames 3123 } = swiper; 3124 el.classList.remove(...classNames); 3125 swiper.emitContainerClasses(); 3126 } 3127 3128 var classes = { 3129 addClasses, 3130 removeClasses 3131 }; 3132 3133 function checkOverflow() { 3134 const swiper = this; 3135 const { 3136 isLocked: wasLocked, 3137 params 3138 } = swiper; 3139 const { 3140 slidesOffsetBefore 3141 } = params; 3142 if (slidesOffsetBefore) { 3143 const lastSlideIndex = swiper.slides.length - 1; 3144 const lastSlideRightEdge = swiper.slidesGrid[lastSlideIndex] + swiper.slidesSizesGrid[lastSlideIndex] + slidesOffsetBefore * 2;
vendor: 1,588 bytes, lines 3145-3200
3145 swiper.isLocked = swiper.size > lastSlideRightEdge; 3146 } else { 3147 swiper.isLocked = swiper.snapGrid.length === 1; 3148 } 3149 if (params.allowSlideNext === true) { 3150 swiper.allowSlideNext = !swiper.isLocked; 3151 } 3152 if (params.allowSlidePrev === true) { 3153 swiper.allowSlidePrev = !swiper.isLocked; 3154 } 3155 if (wasLocked && wasLocked !== swiper.isLocked) { 3156 swiper.isEnd = false; 3157 } 3158 if (wasLocked !== swiper.isLocked) { 3159 swiper.emit(swiper.isLocked ? 'lock' : 'unlock'); 3160 } 3161 } 3162 var checkOverflow$1 = { 3163 checkOverflow 3164 }; 3165 3166 var defaults = { 3167 init: true, 3168 direction: 'horizontal', 3169 oneWayMovement: false, 3170 touchEventsTarget: 'wrapper', 3171 initialSlide: 0, 3172 speed: 300, 3173 cssMode: false, 3174 updateOnWindowResize: true, 3175 resizeObserver: true, 3176 nested: false, 3177 createElements: false, 3178 enabled: true, 3179 focusableElements: 'input, select, option, textarea, button, video, label', 3180 // Overrides 3181 width: null, 3182 height: null, 3183 // 3184 preventInteractionOnTransition: false, 3185 // ssr 3186 userAgent: null, 3187 url: null, 3188 // To support iOS's swipe-to-go-back gesture (when being used in-app). 3189 edgeSwipeDetection: false, 3190 edgeSwipeThreshold: 20, 3191 // Autoheight 3192 autoHeight: false, 3193 // Set wrapper width 3194 setWrapperSize: false, 3195 // Virtual Translate 3196 virtualTranslate: false, 3197 // Effects 3198 effect: 'slide', 3199 // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip' 3200
vendor: 6,228 bytes, lines 3201-3397
3201 // Breakpoints 3202 breakpoints: undefined, 3203 breakpointsBase: 'window', 3204 // Slides grid 3205 spaceBetween: 0, 3206 slidesPerView: 1, 3207 slidesPerGroup: 1, 3208 slidesPerGroupSkip: 0, 3209 slidesPerGroupAuto: false, 3210 centeredSlides: false, 3211 centeredSlidesBounds: false, 3212 slidesOffsetBefore: 0, 3213 // in px 3214 slidesOffsetAfter: 0, 3215 // in px 3216 normalizeSlideIndex: true, 3217 centerInsufficientSlides: false, 3218 // Disable swiper and hide navigation when container not overflow 3219 watchOverflow: true, 3220 // Round length 3221 roundLengths: false, 3222 // Touches 3223 touchRatio: 1, 3224 touchAngle: 45, 3225 simulateTouch: true, 3226 shortSwipes: true, 3227 longSwipes: true, 3228 longSwipesRatio: 0.5, 3229 longSwipesMs: 300, 3230 followFinger: true, 3231 allowTouchMove: true, 3232 threshold: 5, 3233 touchMoveStopPropagation: false, 3234 touchStartPreventDefault: true, 3235 touchStartForcePreventDefault: false, 3236 touchReleaseOnEdges: false, 3237 // Unique Navigation Elements 3238 uniqueNavElements: true, 3239 // Resistance 3240 resistance: true, 3241 resistanceRatio: 0.85, 3242 // Progress 3243 watchSlidesProgress: false, 3244 // Cursor 3245 grabCursor: false, 3246 // Clicks 3247 preventClicks: true, 3248 preventClicksPropagation: true, 3249 slideToClickedSlide: false, 3250 // loop 3251 loop: false, 3252 loopedSlides: null, 3253 loopPreventsSliding: true, 3254 // rewind 3255 rewind: false, 3256 // Swiping/no swiping 3257 allowSlidePrev: true, 3258 allowSlideNext: true, 3259 swipeHandler: null, 3260 // '.swipe-handler', 3261 noSwiping: true, 3262 noSwipingClass: 'swiper-no-swiping', 3263 noSwipingSelector: null, 3264 // Passive Listeners 3265 passiveListeners: true, 3266 maxBackfaceHiddenSlides: 10, 3267 // NS 3268 containerModifierClass: 'swiper-', 3269 // NEW 3270 slideClass: 'swiper-slide', 3271 slideActiveClass: 'swiper-slide-active', 3272 slideVisibleClass: 'swiper-slide-visible', 3273 slideNextClass: 'swiper-slide-next', 3274 slidePrevClass: 'swiper-slide-prev', 3275 wrapperClass: 'swiper-wrapper', 3276 lazyPreloaderClass: 'swiper-lazy-preloader', 3277 // Callbacks 3278 runCallbacksOnInit: true, 3279 // Internals 3280 _emitClasses: false 3281 }; 3282 3283 function moduleExtendParams(params, allModulesParams) { 3284 return function extendParams(obj) { 3285 if (obj === void 0) { 3286 obj = {}; 3287 } 3288 const moduleParamName = Object.keys(obj)[0]; 3289 const moduleParams = obj[moduleParamName]; 3290 if (typeof moduleParams !== 'object' || moduleParams === null) { 3291 extend(allModulesParams, obj); 3292 return; 3293 } 3294 if (['navigation', 'pagination', 'scrollbar'].indexOf(moduleParamName) >= 0 && params[moduleParamName] === true) { 3295 params[moduleParamName] = { 3296 auto: true 3297 }; 3298 } 3299 if (!(moduleParamName in params && 'enabled' in moduleParams)) { 3300 extend(allModulesParams, obj); 3301 return; 3302 } 3303 if (params[moduleParamName] === true) { 3304 params[moduleParamName] = { 3305 enabled: true 3306 }; 3307 } 3308 if (typeof params[moduleParamName] === 'object' && !('enabled' in params[moduleParamName])) { 3309 params[moduleParamName].enabled = true; 3310 } 3311 if (!params[moduleParamName]) params[moduleParamName] = { 3312 enabled: false 3313 }; 3314 extend(allModulesParams, obj); 3315 }; 3316 } 3317 3318 /* eslint no-param-reassign: "off" */ 3319 const prototypes = { 3320 eventsEmitter, 3321 update, 3322 translate, 3323 transition, 3324 slide, 3325 loop, 3326 grabCursor, 3327 events: events$1, 3328 breakpoints, 3329 checkOverflow: checkOverflow$1, 3330 classes 3331 }; 3332 const extendedDefaults = {}; 3333 class Swiper { 3334 constructor() { 3335 let el; 3336 let params; 3337 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 3338 args[_key] = arguments[_key]; 3339 } 3340 if (args.length === 1 && args[0].constructor && Object.prototype.toString.call(args[0]).slice(8, -1) === 'Object') { 3341 params = args[0]; 3342 } else { 3343 [el, params] = args; 3344 } 3345 if (!params) params = {}; 3346 params = extend({}, params); 3347 if (el && !params.el) params.el = el; 3348 const document = getDocument(); 3349 if (params.el && typeof params.el === 'string' && document.querySelectorAll(params.el).length > 1) { 3350 const swipers = []; 3351 document.querySelectorAll(params.el).forEach(containerEl => { 3352 const newParams = extend({}, params, { 3353 el: containerEl 3354 }); 3355 swipers.push(new Swiper(newParams)); 3356 }); 3357 // eslint-disable-next-line no-constructor-return 3358 return swipers; 3359 } 3360 3361 // Swiper Instance 3362 const swiper = this; 3363 swiper.__swiper__ = true; 3364 swiper.support = getSupport(); 3365 swiper.device = getDevice({ 3366 userAgent: params.userAgent 3367 }); 3368 swiper.browser = getBrowser(); 3369 swiper.eventsListeners = {}; 3370 swiper.eventsAnyListeners = []; 3371 swiper.modules = [...swiper.__modules__]; 3372 if (params.modules && Array.isArray(params.modules)) { 3373 swiper.modules.push(...params.modules); 3374 } 3375 const allModulesParams = {}; 3376 swiper.modules.forEach(mod => { 3377 mod({ 3378 params, 3379 swiper, 3380 extendParams: moduleExtendParams(params, allModulesParams), 3381 on: swiper.on.bind(swiper), 3382 once: swiper.once.bind(swiper), 3383 off: swiper.off.bind(swiper), 3384 emit: swiper.emit.bind(swiper) 3385 }); 3386 }); 3387 3388 // Extend defaults with modules params 3389 const swiperParams = extend({}, defaults, allModulesParams); 3390 3391 // Extend defaults with passed params 3392 swiper.params = extend({}, swiperParams, extendedDefaults, params); 3393 swiper.originalParams = extend({}, swiper.params); 3394 swiper.passedParams = extend({}, params); 3395 3396 // add event listeners 3397 if (swiper.params && swiper.params.on) {
vendor: 4,490 bytes, lines 3398-3540
3398 Object.keys(swiper.params.on).forEach(eventName => { 3399 swiper.on(eventName, swiper.params.on[eventName]); 3400 }); 3401 } 3402 if (swiper.params && swiper.params.onAny) { 3403 swiper.onAny(swiper.params.onAny); 3404 } 3405 3406 // Extend Swiper 3407 Object.assign(swiper, { 3408 enabled: swiper.params.enabled, 3409 el, 3410 // Classes 3411 classNames: [], 3412 // Slides 3413 slides: [], 3414 slidesGrid: [], 3415 snapGrid: [], 3416 slidesSizesGrid: [], 3417 // isDirection 3418 isHorizontal() { 3419 return swiper.params.direction === 'horizontal'; 3420 }, 3421 isVertical() { 3422 return swiper.params.direction === 'vertical'; 3423 }, 3424 // Indexes 3425 activeIndex: 0, 3426 realIndex: 0, 3427 // 3428 isBeginning: true, 3429 isEnd: false, 3430 // Props 3431 translate: 0, 3432 previousTranslate: 0, 3433 progress: 0, 3434 velocity: 0, 3435 animating: false, 3436 // Locks 3437 allowSlideNext: swiper.params.allowSlideNext, 3438 allowSlidePrev: swiper.params.allowSlidePrev, 3439 // Touch Events 3440 touchEventsData: { 3441 isTouched: undefined, 3442 isMoved: undefined, 3443 allowTouchCallbacks: undefined, 3444 touchStartTime: undefined, 3445 isScrolling: undefined, 3446 currentTranslate: undefined, 3447 startTranslate: undefined, 3448 allowThresholdMove: undefined, 3449 // Form elements to match 3450 focusableElements: swiper.params.focusableElements, 3451 // Last click time 3452 lastClickTime: now(), 3453 clickTimeout: undefined, 3454 // Velocities 3455 velocities: [], 3456 allowMomentumBounce: undefined, 3457 startMoving: undefined, 3458 evCache: [] 3459 }, 3460 // Clicks 3461 allowClick: true, 3462 // Touches 3463 allowTouchMove: swiper.params.allowTouchMove, 3464 touches: { 3465 startX: 0, 3466 startY: 0, 3467 currentX: 0, 3468 currentY: 0, 3469 diff: 0 3470 }, 3471 // Images 3472 imagesToLoad: [], 3473 imagesLoaded: 0 3474 }); 3475 swiper.emit('_swiper'); 3476 3477 // Init 3478 if (swiper.params.init) { 3479 swiper.init(); 3480 } 3481 3482 // Return app instance 3483 // eslint-disable-next-line no-constructor-return 3484 return swiper; 3485 } 3486 recalcSlides() { 3487 const swiper = this; 3488 const { 3489 slidesEl, 3490 params 3491 } = swiper; 3492 swiper.slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`); 3493 } 3494 enable() { 3495 const swiper = this; 3496 if (swiper.enabled) return; 3497 swiper.enabled = true; 3498 if (swiper.params.grabCursor) { 3499 swiper.setGrabCursor(); 3500 } 3501 swiper.emit('enable'); 3502 } 3503 disable() { 3504 const swiper = this; 3505 if (!swiper.enabled) return; 3506 swiper.enabled = false; 3507 if (swiper.params.grabCursor) { 3508 swiper.unsetGrabCursor(); 3509 } 3510 swiper.emit('disable'); 3511 } 3512 setProgress(progress, speed) { 3513 const swiper = this; 3514 progress = Math.min(Math.max(progress, 0), 1); 3515 const min = swiper.minTranslate(); 3516 const max = swiper.maxTranslate(); 3517 const current = (max - min) * progress + min; 3518 swiper.translateTo(current, typeof speed === 'undefined' ? 0 : speed); 3519 swiper.updateActiveIndex(); 3520 swiper.updateSlidesClasses(); 3521 } 3522 emitContainerClasses() { 3523 const swiper = this; 3524 if (!swiper.params._emitClasses || !swiper.el) return; 3525 const cls = swiper.el.className.split(' ').filter(className => { 3526 return className.indexOf('swiper') === 0 || className.indexOf(swiper.params.containerModifierClass) === 0; 3527 }); 3528 swiper.emit('_containerClasses', cls.join(' ')); 3529 } 3530 getSlideClasses(slideEl) { 3531 const swiper = this; 3532 if (swiper.destroyed) return ''; 3533 return slideEl.className.split(' ').filter(className => { 3534 return className.indexOf('swiper-slide') === 0 || className.indexOf(swiper.params.slideClass) === 0; 3535 }).join(' '); 3536 } 3537 emitSlidesClasses() { 3538 const swiper = this; 3539 if (!swiper.params._emitClasses || !swiper.el) return; 3540 const updates = [];
vendor: 2,300 bytes, lines 3541-3612
3541 swiper.slides.forEach(slideEl => { 3542 const classNames = swiper.getSlideClasses(slideEl); 3543 updates.push({ 3544 slideEl, 3545 classNames 3546 }); 3547 swiper.emit('_slideClass', slideEl, classNames); 3548 }); 3549 swiper.emit('_slideClasses', updates); 3550 } 3551 slidesPerViewDynamic(view, exact) { 3552 if (view === void 0) { 3553 view = 'current'; 3554 } 3555 if (exact === void 0) { 3556 exact = false; 3557 } 3558 const swiper = this; 3559 const { 3560 params, 3561 slides, 3562 slidesGrid, 3563 slidesSizesGrid, 3564 size: swiperSize, 3565 activeIndex 3566 } = swiper; 3567 let spv = 1; 3568 if (params.centeredSlides) { 3569 let slideSize = slides[activeIndex].swiperSlideSize; 3570 let breakLoop; 3571 for (let i = activeIndex + 1; i < slides.length; i += 1) { 3572 if (slides[i] && !breakLoop) { 3573 slideSize += slides[i].swiperSlideSize; 3574 spv += 1; 3575 if (slideSize > swiperSize) breakLoop = true; 3576 } 3577 } 3578 for (let i = activeIndex - 1; i >= 0; i -= 1) { 3579 if (slides[i] && !breakLoop) { 3580 slideSize += slides[i].swiperSlideSize; 3581 spv += 1; 3582 if (slideSize > swiperSize) breakLoop = true; 3583 } 3584 } 3585 } else { 3586 // eslint-disable-next-line 3587 if (view === 'current') { 3588 for (let i = activeIndex + 1; i < slides.length; i += 1) { 3589 const slideInView = exact ? slidesGrid[i] + slidesSizesGrid[i] - slidesGrid[activeIndex] < swiperSize : slidesGrid[i] - slidesGrid[activeIndex] < swiperSize; 3590 if (slideInView) { 3591 spv += 1; 3592 } 3593 } 3594 } else { 3595 // previous 3596 for (let i = activeIndex - 1; i >= 0; i -= 1) { 3597 const slideInView = slidesGrid[activeIndex] - slidesGrid[i] < swiperSize; 3598 if (slideInView) { 3599 spv += 1; 3600 } 3601 } 3602 } 3603 } 3604 return spv; 3605 } 3606 update() { 3607 const swiper = this; 3608 if (!swiper || swiper.destroyed) return; 3609 const { 3610 snapGrid, 3611 params 3612 } = swiper;
vendor: 2,396 bytes, lines 3613-3670
3613 // Breakpoints 3614 if (params.breakpoints) { 3615 swiper.setBreakpoint(); 3616 } 3617 [...swiper.el.querySelectorAll('[loading="lazy"]')].forEach(imageEl => { 3618 if (imageEl.complete) { 3619 processLazyPreloader(swiper, imageEl); 3620 } 3621 }); 3622 swiper.updateSize(); 3623 swiper.updateSlides(); 3624 swiper.updateProgress(); 3625 swiper.updateSlidesClasses(); 3626 function setTranslate() { 3627 const translateValue = swiper.rtlTranslate ? swiper.translate * -1 : swiper.translate; 3628 const newTranslate = Math.min(Math.max(translateValue, swiper.maxTranslate()), swiper.minTranslate()); 3629 swiper.setTranslate(newTranslate); 3630 swiper.updateActiveIndex(); 3631 swiper.updateSlidesClasses(); 3632 } 3633 let translated; 3634 if (swiper.params.freeMode && swiper.params.freeMode.enabled) { 3635 setTranslate(); 3636 if (swiper.params.autoHeight) { 3637 swiper.updateAutoHeight(); 3638 } 3639 } else { 3640 if ((swiper.params.slidesPerView === 'auto' || swiper.params.slidesPerView > 1) && swiper.isEnd && !swiper.params.centeredSlides) { 3641 translated = swiper.slideTo(swiper.slides.length - 1, 0, false, true); 3642 } else { 3643 translated = swiper.slideTo(swiper.activeIndex, 0, false, true); 3644 } 3645 if (!translated) { 3646 setTranslate(); 3647 } 3648 } 3649 if (params.watchOverflow && snapGrid !== swiper.snapGrid) { 3650 swiper.checkOverflow(); 3651 } 3652 swiper.emit('update'); 3653 } 3654 changeDirection(newDirection, needUpdate) { 3655 if (needUpdate === void 0) { 3656 needUpdate = true; 3657 } 3658 const swiper = this; 3659 const currentDirection = swiper.params.direction; 3660 if (!newDirection) { 3661 // eslint-disable-next-line 3662 newDirection = currentDirection === 'horizontal' ? 'vertical' : 'horizontal'; 3663 } 3664 if (newDirection === currentDirection || newDirection !== 'horizontal' && newDirection !== 'vertical') { 3665 return swiper; 3666 } 3667 swiper.el.classList.remove(`${swiper.params.containerModifierClass}${currentDirection}`); 3668 swiper.el.classList.add(`${swiper.params.containerModifierClass}${newDirection}`); 3669 swiper.emitContainerClasses(); 3670 swiper.params.direction = newDirection;
vendor: 2,096 bytes, lines 3671-3728
3671 swiper.slides.forEach(slideEl => { 3672 if (newDirection === 'vertical') { 3673 slideEl.style.width = ''; 3674 } else { 3675 slideEl.style.height = ''; 3676 } 3677 }); 3678 swiper.emit('changeDirection'); 3679 if (needUpdate) swiper.update(); 3680 return swiper; 3681 } 3682 changeLanguageDirection(direction) { 3683 const swiper = this; 3684 if (swiper.rtl && direction === 'rtl' || !swiper.rtl && direction === 'ltr') return; 3685 swiper.rtl = direction === 'rtl'; 3686 swiper.rtlTranslate = swiper.params.direction === 'horizontal' && swiper.rtl; 3687 if (swiper.rtl) { 3688 swiper.el.classList.add(`${swiper.params.containerModifierClass}rtl`); 3689 swiper.el.dir = 'rtl'; 3690 } else { 3691 swiper.el.classList.remove(`${swiper.params.containerModifierClass}rtl`); 3692 swiper.el.dir = 'ltr'; 3693 } 3694 swiper.update(); 3695 } 3696 mount(element) { 3697 const swiper = this; 3698 if (swiper.mounted) return true; 3699 3700 // Find el 3701 let el = element || swiper.params.el; 3702 if (typeof el === 'string') { 3703 el = document.querySelector(el); 3704 } 3705 if (!el) { 3706 return false; 3707 } 3708 el.swiper = swiper; 3709 if (el.shadowEl) { 3710 swiper.isElement = true; 3711 } 3712 const getWrapperSelector = () => { 3713 return `.${(swiper.params.wrapperClass || '').trim().split(' ').join('.')}`; 3714 }; 3715 const getWrapper = () => { 3716 if (el && el.shadowRoot && el.shadowRoot.querySelector) { 3717 const res = el.shadowRoot.querySelector(getWrapperSelector()); 3718 // Children needs to return slot items 3719 return res; 3720 } 3721 return elementChildren(el, getWrapperSelector())[0]; 3722 }; 3723 // Find Wrapper 3724 let wrapperEl = getWrapper(); 3725 if (!wrapperEl && swiper.params.createElements) { 3726 wrapperEl = createElement('div', swiper.params.wrapperClass); 3727 el.append(wrapperEl); 3728 elementChildren(el, `.${swiper.params.slideClass}
3728`).forEach(slideEl => { 3729 wrapperEl.append(slideEl); 3730 }); 3731 } 3732 Object.assign(swiper, { 3733 el, 3734 wrapperEl, 3735 slidesEl: swiper.isElement ? el : wrapperEl, 3736 mounted: true, 3737 // RTL 3738 rtl: el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl', 3739 rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl'), 3740 wrongRTL: elementStyle(wrapperEl, 'display') === '-webkit-box' 3741 }); 3742 return true; 3743 } 3744 init(el) { 3745 const swiper = this; 3746 if (swiper.initialized) return swiper; 3747 const mounted = swiper.mount(el); 3748 if (mounted === false) return swiper; 3749 swiper.emit('beforeInit'); 3750 3751 // Set breakpoint 3752 if (swiper.params.breakpoints) { 3753 swiper.setBreakpoint(); 3754 } 3755 3756 // Add Classes 3757 swiper.addClasses(); 3758 3759 // Update size 3760 swiper.updateSize(); 3761 3762 // Update slides 3763 swiper.updateSlides(); 3764 if (swiper.params.watchOverflow) { 3765 swiper.checkOverflow(); 3766 } 3767 3768 // Set Grab Cursor 3769 if (swiper.params.grabCursor && swiper.enabled) { 3770 swiper.setGrabCursor(); 3771 } 3772 3773 // Slide To Initial Slide 3774 if (swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) { 3775 swiper.slideTo(swiper.params.initialSlide + swiper.virtual.slidesBefore, 0, swiper.params.runCallbacksOnInit, false, true); 3776 } else { 3777 swiper.slideTo(swiper.params.initialSlide, 0, swiper.params.runCallbacksOnInit, false, true); 3778 } 3779 3780 // Create loop 3781 if (swiper.params.loop) { 3782 swiper.loopCreate(); 3783 } 3784 3785 // Attach events 3786 swiper.attachEvents(); 3787 [...swiper.el.querySelectorAll('[loading="lazy"]')].forEach(imageEl => { 3788 if (imageEl.complete) { 3789 processLazyPreloader(swiper, imageEl); 3790 } else { 3791 imageEl.addEventListener('load', e => { 3792 processLazyPreloader(swiper, e.target); 3793 }); 3794 } 3795 }); 3796 3797 // Init Flag 3798 swiper.initialized = true; 3799 3800 // Emit 3801 swiper.emit('init'); 3802 swiper.emit('afterInit'); 3803 return swiper; 3804 } 3805 destroy(deleteInstance, cleanStyles) { 3806 if (deleteInstance === void 0) { 3807 deleteInstance = true; 3808 } 3809 if (cleanStyles === void 0) { 3810 cleanStyles = true; 3811 } 3812 const swiper = this; 3813 const { 3814 params, 3815 el, 3816 wrapperEl, 3817 slides 3818 } = swiper; 3819 if (typeof swiper.params === 'undefined' || swiper.destroyed) { 3820 return null; 3821 } 3822 swiper.emit('beforeDestroy'); 3823 3824 // Init Flag 3825 swiper.initialized = false; 3826 3827 // Detach events 3828 swiper.detachEvents(); 3829 3830 // Destroy loop 3831 if (params.loop) { 3832 swiper.loopDestroy(); 3833 } 3834 3835 // Cleanup styles 3836 if (cleanStyles) { 3837 swiper.removeClasses(); 3838 el.removeAttribute('style'); 3839 wrapperEl.removeAttribute('style'); 3840 if (slides && slides.length) {
vendor: 5,646 bytes, lines 3841-4010
3841 slides.forEach(slideEl => { 3842 slideEl.classList.remove(params.slideVisibleClass, params.slideActiveClass, params.slideNextClass, params.slidePrevClass); 3843 slideEl.removeAttribute('style'); 3844 slideEl.removeAttribute('data-swiper-slide-index'); 3845 }); 3846 } 3847 } 3848 swiper.emit('destroy'); 3849 3850 // Detach emitter events 3851 Object.keys(swiper.eventsListeners).forEach(eventName => { 3852 swiper.off(eventName); 3853 }); 3854 if (deleteInstance !== false) { 3855 swiper.el.swiper = null; 3856 deleteProps(swiper); 3857 } 3858 swiper.destroyed = true; 3859 return null; 3860 } 3861 static extendDefaults(newDefaults) { 3862 extend(extendedDefaults, newDefaults); 3863 } 3864 static get extendedDefaults() { 3865 return extendedDefaults; 3866 } 3867 static get defaults() { 3868 return defaults; 3869 } 3870 static installModule(mod) { 3871 if (!Swiper.prototype.__modules__) Swiper.prototype.__modules__ = []; 3872 const modules = Swiper.prototype.__modules__; 3873 if (typeof mod === 'function' && modules.indexOf(mod) < 0) { 3874 modules.push(mod); 3875 } 3876 } 3877 static use(module) { 3878 if (Array.isArray(module)) { 3879 module.forEach(m => Swiper.installModule(m)); 3880 return Swiper; 3881 } 3882 Swiper.installModule(module); 3883 return Swiper; 3884 } 3885 } 3886 Object.keys(prototypes).forEach(prototypeGroup => { 3887 Object.keys(prototypes[prototypeGroup]).forEach(protoMethod => { 3888 Swiper.prototype[protoMethod] = prototypes[prototypeGroup][protoMethod]; 3889 }); 3890 }); 3891 Swiper.use([Resize, Observer]); 3892 3893 function Virtual(_ref) { 3894 let { 3895 swiper, 3896 extendParams, 3897 on, 3898 emit 3899 } = _ref; 3900 extendParams({ 3901 virtual: { 3902 enabled: false, 3903 slides: [], 3904 cache: true, 3905 renderSlide: null, 3906 renderExternal: null, 3907 renderExternalUpdate: true, 3908 addSlidesBefore: 0, 3909 addSlidesAfter: 0 3910 } 3911 }); 3912 let cssModeTimeout; 3913 const document = getDocument(); 3914 swiper.virtual = { 3915 cache: {}, 3916 from: undefined, 3917 to: undefined, 3918 slides: [], 3919 offset: 0, 3920 slidesGrid: [] 3921 }; 3922 const tempDOM = document.createElement('div'); 3923 function renderSlide(slide, index) { 3924 const params = swiper.params.virtual; 3925 if (params.cache && swiper.virtual.cache[index]) { 3926 return swiper.virtual.cache[index]; 3927 } 3928 // eslint-disable-next-line 3929 let slideEl; 3930 if (params.renderSlide) { 3931 slideEl = params.renderSlide.call(swiper, slide, index); 3932 if (typeof slideEl === 'string') { 3933 tempDOM.innerHTML = slideEl; 3934 slideEl = tempDOM.children[0]; 3935 } 3936 } else if (swiper.isElement) { 3937 slideEl = createElement('swiper-slide'); 3938 } else { 3939 slideEl = createElement('div', swiper.params.slideClass); 3940 } 3941 slideEl.setAttribute('data-swiper-slide-index', index); 3942 if (!params.renderSlide) { 3943 slideEl.textContent = slide; 3944 } 3945 if (params.cache) swiper.virtual.cache[index] = slideEl; 3946 return slideEl; 3947 } 3948 function update(force) { 3949 const { 3950 slidesPerView, 3951 slidesPerGroup, 3952 centeredSlides, 3953 loop: isLoop 3954 } = swiper.params; 3955 const { 3956 addSlidesBefore, 3957 addSlidesAfter 3958 } = swiper.params.virtual; 3959 const { 3960 from: previousFrom, 3961 to: previousTo, 3962 slides, 3963 slidesGrid: previousSlidesGrid, 3964 offset: previousOffset 3965 } = swiper.virtual; 3966 if (!swiper.params.cssMode) { 3967 swiper.updateActiveIndex(); 3968 } 3969 const activeIndex = swiper.activeIndex || 0; 3970 let offsetProp; 3971 if (swiper.rtlTranslate) offsetProp = 'right';else offsetProp = swiper.isHorizontal() ? 'left' : 'top'; 3972 let slidesAfter; 3973 let slidesBefore; 3974 if (centeredSlides) { 3975 slidesAfter = Math.floor(slidesPerView / 2) + slidesPerGroup + addSlidesAfter; 3976 slidesBefore = Math.floor(slidesPerView / 2) + slidesPerGroup + addSlidesBefore; 3977 } else { 3978 slidesAfter = slidesPerView + (slidesPerGroup - 1) + addSlidesAfter; 3979 slidesBefore = (isLoop ? slidesPerView : slidesPerGroup) + addSlidesBefore; 3980 } 3981 let from = activeIndex - slidesBefore; 3982 let to = activeIndex + slidesAfter; 3983 if (!isLoop) { 3984 from = Math.max(from, 0); 3985 to = Math.min(to, slides.length - 1); 3986 } 3987 let offset = (swiper.slidesGrid[from] || 0) - (swiper.slidesGrid[0] || 0); 3988 if (isLoop && activeIndex >= slidesBefore) { 3989 from -= slidesBefore; 3990 if (!centeredSlides) offset += swiper.slidesGrid[0]; 3991 } else if (isLoop && activeIndex < slidesBefore) { 3992 from = -slidesBefore; 3993 if (centeredSlides) offset += swiper.slidesGrid[0]; 3994 } 3995 Object.assign(swiper.virtual, { 3996 from, 3997 to, 3998 offset, 3999 slidesGrid: swiper.slidesGrid, 4000 slidesBefore, 4001 slidesAfter 4002 }); 4003 function onRendered() { 4004 swiper.updateSlides(); 4005 swiper.updateProgress(); 4006 swiper.updateSlidesClasses(); 4007 emit('virtualUpdate'); 4008 } 4009 if (previousFrom === from && previousTo === to && !force) { 4010 if (swiper.slidesGrid !== previousSlidesGrid && offset !== previousOffset) {
vendor: 1,352 bytes, lines 4011-4052
4011 swiper.slides.forEach(slideEl => { 4012 slideEl.style[offsetProp] = `${offset}px`; 4013 }); 4014 } 4015 swiper.updateProgress(); 4016 emit('virtualUpdate'); 4017 return; 4018 } 4019 if (swiper.params.virtual.renderExternal) { 4020 swiper.params.virtual.renderExternal.call(swiper, { 4021 offset, 4022 from, 4023 to, 4024 slides: function getSlides() { 4025 const slidesToRender = []; 4026 for (let i = from; i <= to; i += 1) { 4027 slidesToRender.push(slides[i]); 4028 } 4029 return slidesToRender; 4030 }() 4031 }); 4032 if (swiper.params.virtual.renderExternalUpdate) { 4033 onRendered(); 4034 } else { 4035 emit('virtualUpdate'); 4036 } 4037 return; 4038 } 4039 const prependIndexes = []; 4040 const appendIndexes = []; 4041 const getSlideIndex = index => { 4042 let slideIndex = index; 4043 if (index < 0) { 4044 slideIndex = slides.length + index; 4045 } else if (slideIndex >= slides.length) { 4046 // eslint-disable-next-line 4047 slideIndex = slideIndex - slides.length; 4048 } 4049 return slideIndex; 4050 }; 4051 if (force) { 4052 swiper.slidesEl.querySelectorAll(`.${swiper.params.slideClass}
4052, swiper-slide`).forEach(slideEl => { 4053 slideEl.remove(); 4054 }); 4055 } else { 4056 for (let i = previousFrom; i <= previousTo; i += 1) { 4057 if (i < from || i > to) { 4058 const slideIndex = getSlideIndex(i); 4059 swiper.slidesEl.querySelectorAll(`.${swiper.params.slideClass}[data-swiper-slide-index="${slideIndex}"], swiper-slide[data-swiper-slide-index="${slideIndex}"]`).forEach(slideEl => { 4060 slideEl.remove(); 4061 }); 4062 } 4063 } 4064 } 4065 const loopFrom = isLoop ? -slides.length : 0; 4066 const loopTo = isLoop ? slides.length * 2 : slides.length; 4067 for (let i = loopFrom; i < loopTo; i += 1) { 4068 if (i >= from && i <= to) { 4069 const slideIndex = getSlideIndex(i); 4070 if (typeof previousTo === 'undefined' || force) { 4071 appendIndexes.push(slideIndex); 4072 } else { 4073 if (i > previousTo) appendIndexes.push(slideIndex); 4074 if (i < previousFrom) prependIndexes.push(slideIndex); 4075 } 4076 } 4077 } 4078 appendIndexes.forEach(index => { 4079 swiper.slidesEl.append(renderSlide(slides[index], index)); 4080 }); 4081 if (isLoop) { 4082 for (let i = prependIndexes.length - 1; i >= 0; i -= 1) { 4083 const index = prependIndexes[i]; 4084 swiper.slidesEl.prepend(renderSlide(slides[index], index)); 4085 } 4086 } else { 4087 prependIndexes.sort((a, b) => b - a); 4088 prependIndexes.forEach(index => { 4089 swiper.slidesEl.prepend(renderSlide(slides[index], index)); 4090 }); 4091 } 4092 elementChildren(swiper.slidesEl, '.swiper-slide, swiper-slide').forEach(sli
vendor: 5,301 bytes, lines 4092-4244
4092deEl => { 4093 slideEl.style[offsetProp] = `${offset}px`; 4094 }); 4095 onRendered(); 4096 } 4097 function appendSlide(slides) { 4098 if (typeof slides === 'object' && 'length' in slides) { 4099 for (let i = 0; i < slides.length; i += 1) { 4100 if (slides[i]) swiper.virtual.slides.push(slides[i]); 4101 } 4102 } else { 4103 swiper.virtual.slides.push(slides); 4104 } 4105 update(true); 4106 } 4107 function prependSlide(slides) { 4108 const activeIndex = swiper.activeIndex; 4109 let newActiveIndex = activeIndex + 1; 4110 let numberOfNewSlides = 1; 4111 if (Array.isArray(slides)) { 4112 for (let i = 0; i < slides.length; i += 1) { 4113 if (slides[i]) swiper.virtual.slides.unshift(slides[i]); 4114 } 4115 newActiveIndex = activeIndex + slides.length; 4116 numberOfNewSlides = slides.length; 4117 } else { 4118 swiper.virtual.slides.unshift(slides); 4119 } 4120 if (swiper.params.virtual.cache) { 4121 const cache = swiper.virtual.cache; 4122 const newCache = {}; 4123 Object.keys(cache).forEach(cachedIndex => { 4124 const cachedEl = cache[cachedIndex]; 4125 const cachedElIndex = cachedEl.getAttribute('data-swiper-slide-index'); 4126 if (cachedElIndex) { 4127 cachedEl.setAttribute('data-swiper-slide-index', parseInt(cachedElIndex, 10) + numberOfNewSlides); 4128 } 4129 newCache[parseInt(cachedIndex, 10) + numberOfNewSlides] = cachedEl; 4130 }); 4131 swiper.virtual.cache = newCache; 4132 } 4133 update(true); 4134 swiper.slideTo(newActiveIndex, 0); 4135 } 4136 function removeSlide(slidesIndexes) { 4137 if (typeof slidesIndexes === 'undefined' || slidesIndexes === null) return; 4138 let activeIndex = swiper.activeIndex; 4139 if (Array.isArray(slidesIndexes)) { 4140 for (let i = slidesIndexes.length - 1; i >= 0; i -= 1) { 4141 swiper.virtual.slides.splice(slidesIndexes[i], 1); 4142 if (swiper.params.virtual.cache) { 4143 delete swiper.virtual.cache[slidesIndexes[i]]; 4144 } 4145 if (slidesIndexes[i] < activeIndex) activeIndex -= 1; 4146 activeIndex = Math.max(activeIndex, 0); 4147 } 4148 } else { 4149 swiper.virtual.slides.splice(slidesIndexes, 1); 4150 if (swiper.params.virtual.cache) { 4151 delete swiper.virtual.cache[slidesIndexes]; 4152 } 4153 if (slidesIndexes < activeIndex) activeIndex -= 1; 4154 activeIndex = Math.max(activeIndex, 0); 4155 } 4156 update(true); 4157 swiper.slideTo(activeIndex, 0); 4158 } 4159 function removeAllSlides() { 4160 swiper.virtual.slides = []; 4161 if (swiper.params.virtual.cache) { 4162 swiper.virtual.cache = {}; 4163 } 4164 update(true); 4165 swiper.slideTo(0, 0); 4166 } 4167 on('beforeInit', () => { 4168 if (!swiper.params.virtual.enabled) return; 4169 let domSlidesAssigned; 4170 if (typeof swiper.passedParams.virtual.slides === 'undefined') { 4171 const slides = swiper.slidesEl.querySelectorAll(`.${swiper.params.slideClass}, swiper-slide`); 4172 if (slides && slides.length) { 4173 swiper.virtual.slides = [...slides]; 4174 domSlidesAssigned = true; 4175 slides.forEach((slideEl, slideIndex) => { 4176 slideEl.setAttribute('data-swiper-slide-index', slideIndex); 4177 swiper.virtual.cache[slideIndex] = slideEl; 4178 slideEl.remove(); 4179 }); 4180 } 4181 } 4182 if (!domSlidesAssigned) { 4183 swiper.virtual.slides = swiper.params.virtual.slides; 4184 } 4185 swiper.classNames.push(`${swiper.params.containerModifierClass}virtual`); 4186 swiper.params.watchSlidesProgress = true; 4187 swiper.originalParams.watchSlidesProgress = true; 4188 if (!swiper.params.initialSlide) { 4189 update(); 4190 } 4191 }); 4192 on('setTranslate', () => { 4193 if (!swiper.params.virtual.enabled) return; 4194 if (swiper.params.cssMode && !swiper._immediateVirtual) { 4195 clearTimeout(cssModeTimeout); 4196 cssModeTimeout = setTimeout(() => { 4197 update(); 4198 }, 100); 4199 } else { 4200 update(); 4201 } 4202 }); 4203 on('init update resize', () => { 4204 if (!swiper.params.virtual.enabled) return; 4205 if (swiper.params.cssMode) { 4206 setCSSProperty(swiper.wrapperEl, '--swiper-virtual-size', `${swiper.virtualSize}px`); 4207 } 4208 }); 4209 Object.assign(swiper.virtual, { 4210 appendSlide, 4211 prependSlide, 4212 removeSlide, 4213 removeAllSlides, 4214 update 4215 }); 4216 } 4217 4218 /* eslint-disable consistent-return */ 4219 function Keyboard(_ref) { 4220 let { 4221 swiper, 4222 extendParams, 4223 on, 4224 emit 4225 } = _ref; 4226 const document = getDocument(); 4227 const window = getWindow(); 4228 swiper.keyboard = { 4229 enabled: false 4230 }; 4231 extendParams({ 4232 keyboard: { 4233 enabled: false, 4234 onlyInViewport: true, 4235 pageUpDown: true 4236 } 4237 }); 4238 function handle(event) { 4239 if (!swiper.enabled) return; 4240 const { 4241 rtlTranslate: rtl 4242 } = swiper; 4243 let e = event; 4244 if (e.originalEvent) e = e.originalEvent; // jquery fix
vendor: 4,274 bytes, lines 4245-4344
4245 const kc = e.keyCode || e.charCode; 4246 const pageUpDown = swiper.params.keyboard.pageUpDown; 4247 const isPageUp = pageUpDown && kc === 33; 4248 const isPageDown = pageUpDown && kc === 34; 4249 const isArrowLeft = kc === 37; 4250 const isArrowRight = kc === 39; 4251 const isArrowUp = kc === 38; 4252 const isArrowDown = kc === 40; 4253 // Directions locks 4254 if (!swiper.allowSlideNext && (swiper.isHorizontal() && isArrowRight || swiper.isVertical() && isArrowDown || isPageDown)) { 4255 return false; 4256 } 4257 if (!swiper.allowSlidePrev && (swiper.isHorizontal() && isArrowLeft || swiper.isVertical() && isArrowUp || isPageUp)) { 4258 return false; 4259 } 4260 if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) { 4261 return undefined; 4262 } 4263 if (document.activeElement && document.activeElement.nodeName && (document.activeElement.nodeName.toLowerCase() === 'input' || document.activeElement.nodeName.toLowerCase() === 'textarea')) { 4264 return undefined; 4265 } 4266 if (swiper.params.keyboard.onlyInViewport && (isPageUp || isPageDown || isArrowLeft || isArrowRight || isArrowUp || isArrowDown)) { 4267 let inView = false; 4268 // Check that swiper should be inside of visible area of window 4269 if (elementParents(swiper.el, `.${swiper.params.slideClass}, swiper-slide`).length > 0 && elementParents(swiper.el, `.${swiper.params.slideActiveClass}`).length === 0) { 4270 return undefined; 4271 } 4272 const el = swiper.el; 4273 const swiperWidth = el.clientWidth; 4274 const swiperHeight = el.clientHeight; 4275 const windowWidth = window.innerWidth; 4276 const windowHeight = window.innerHeight; 4277 const swiperOffset = elementOffset(el); 4278 if (rtl) swiperOffset.left -= el.scrollLeft; 4279 const swiperCoord = [[swiperOffset.left, swiperOffset.top], [swiperOffset.left + swiperWidth, swiperOffset.top], [swiperOffset.left, swiperOffset.top + swiperHeight], [swiperOffset.left + swiperWidth, swiperOffset.top + swiperHeight]]; 4280 for (let i = 0; i < swiperCoord.length; i += 1) { 4281 const point = swiperCoord[i]; 4282 if (point[0] >= 0 && point[0] <= windowWidth && point[1] >= 0 && point[1] <= windowHeight) { 4283 if (point[0] === 0 && point[1] === 0) continue; // eslint-disable-line 4284 inView = true; 4285 } 4286 } 4287 if (!inView) return undefined; 4288 } 4289 if (swiper.isHorizontal()) { 4290 if (isPageUp || isPageDown || isArrowLeft || isArrowRight) { 4291 if (e.preventDefault) e.preventDefault();else e.returnValue = false; 4292 } 4293 if ((isPageDown || isArrowRight) && !rtl || (isPageUp || isArrowLeft) && rtl) swiper.slideNext(); 4294 if ((isPageUp || isArrowLeft) && !rtl || (isPageDown || isArrowRight) && rtl) swiper.slidePrev(); 4295 } else { 4296 if (isPageUp || isPageDown || isArrowUp || isArrowDown) { 4297 if (e.preventDefault) e.preventDefault();else e.returnValue = false; 4298 } 4299 if (isPageDown || isArrowDown) swiper.slideNext(); 4300 if (isPageUp || isArrowUp) swiper.slidePrev(); 4301 } 4302 emit('keyPress', kc); 4303 return undefined; 4304 } 4305 function enable() { 4306 if (swiper.keyboard.enabled) return; 4307 document.addEventListener('keydown', handle); 4308 swiper.keyboard.enabled = true; 4309 } 4310 function disable() { 4311 if (!swiper.keyboard.enabled) return; 4312 document.removeEventListener('keydown', handle); 4313 swiper.keyboard.enabled = false; 4314 } 4315 on('init', () => { 4316 if (swiper.params.keyboard.enabled) { 4317 enable(); 4318 } 4319 }); 4320 on('destroy', () => { 4321 if (swiper.keyboard.enabled) { 4322 disable(); 4323 } 4324 }); 4325 Object.assign(swiper.keyboard, { 4326 enable, 4327 disable 4328 }); 4329 } 4330 4331 /* eslint-disable consistent-return */ 4332 function Mousewheel(_ref) { 4333 let { 4334 swiper, 4335 extendParams, 4336 on, 4337 emit 4338 } = _ref; 4339 const window = getWindow(); 4340 extendParams({ 4341 mousewheel: { 4342 enabled: false, 4343 releaseOnEdges: false, 4344 invert: false,
vendor: 39,706 bytes, lines 4345-5343
4345 forceToAxis: false, 4346 sensitivity: 1, 4347 eventsTarget: 'container', 4348 thresholdDelta: null, 4349 thresholdTime: null 4350 } 4351 }); 4352 swiper.mousewheel = { 4353 enabled: false 4354 }; 4355 let timeout; 4356 let lastScrollTime = now(); 4357 let lastEventBeforeSnap; 4358 const recentWheelEvents = []; 4359 function normalize(e) { 4360 // Reasonable defaults 4361 const PIXEL_STEP = 10; 4362 const LINE_HEIGHT = 40; 4363 const PAGE_HEIGHT = 800; 4364 let sX = 0; 4365 let sY = 0; // spinX, spinY 4366 let pX = 0; 4367 let pY = 0; // pixelX, pixelY 4368 4369 // Legacy 4370 if ('detail' in e) { 4371 sY = e.detail; 4372 } 4373 if ('wheelDelta' in e) { 4374 sY = -e.wheelDelta / 120; 4375 } 4376 if ('wheelDeltaY' in e) { 4377 sY = -e.wheelDeltaY / 120; 4378 } 4379 if ('wheelDeltaX' in e) { 4380 sX = -e.wheelDeltaX / 120; 4381 } 4382 4383 // side scrolling on FF with DOMMouseScroll 4384 if ('axis' in e && e.axis === e.HORIZONTAL_AXIS) { 4385 sX = sY; 4386 sY = 0; 4387 } 4388 pX = sX * PIXEL_STEP; 4389 pY = sY * PIXEL_STEP; 4390 if ('deltaY' in e) { 4391 pY = e.deltaY; 4392 } 4393 if ('deltaX' in e) { 4394 pX = e.deltaX; 4395 } 4396 if (e.shiftKey && !pX) { 4397 // if user scrolls with shift he wants horizontal scroll 4398 pX = pY; 4399 pY = 0; 4400 } 4401 if ((pX || pY) && e.deltaMode) { 4402 if (e.deltaMode === 1) { 4403 // delta in LINE units 4404 pX *= LINE_HEIGHT; 4405 pY *= LINE_HEIGHT; 4406 } else { 4407 // delta in PAGE units 4408 pX *= PAGE_HEIGHT; 4409 pY *= PAGE_HEIGHT; 4410 } 4411 } 4412 4413 // Fall-back if spin cannot be determined 4414 if (pX && !sX) { 4415 sX = pX < 1 ? -1 : 1; 4416 } 4417 if (pY && !sY) { 4418 sY = pY < 1 ? -1 : 1; 4419 } 4420 return { 4421 spinX: sX, 4422 spinY: sY, 4423 pixelX: pX, 4424 pixelY: pY 4425 }; 4426 } 4427 function handleMouseEnter() { 4428 if (!swiper.enabled) return; 4429 swiper.mouseEntered = true; 4430 } 4431 function handleMouseLeave() { 4432 if (!swiper.enabled) return; 4433 swiper.mouseEntered = false; 4434 } 4435 function animateSlider(newEvent) { 4436 if (swiper.params.mousewheel.thresholdDelta && newEvent.delta < swiper.params.mousewheel.thresholdDelta) { 4437 // Prevent if delta of wheel scroll delta is below configured threshold 4438 return false; 4439 } 4440 if (swiper.params.mousewheel.thresholdTime && now() - lastScrollTime < swiper.params.mousewheel.thresholdTime) { 4441 // Prevent if time between scrolls is below configured threshold 4442 return false; 4443 } 4444 4445 // If the movement is NOT big enough and 4446 // if the last time the user scrolled was too close to the current one (avoid continuously triggering the slider): 4447 // Don't go any further (avoid insignificant scroll movement). 4448 if (newEvent.delta >= 6 && now() - lastScrollTime < 60) { 4449 // Return false as a default 4450 return true; 4451 } 4452 // If user is scrolling towards the end: 4453 // If the slider hasn't hit the latest slide or 4454 // if the slider is a loop and 4455 // if the slider isn't moving right now: 4456 // Go to next slide and 4457 // emit a scroll event. 4458 // Else (the user is scrolling towards the beginning) and 4459 // if the slider hasn't hit the first slide or 4460 // if the slider is a loop and 4461 // if the slider isn't moving right now: 4462 // Go to prev slide and 4463 // emit a scroll event. 4464 if (newEvent.direction < 0) { 4465 if ((!swiper.isEnd || swiper.params.loop) && !swiper.animating) { 4466 swiper.slideNext(); 4467 emit('scroll', newEvent.raw); 4468 } 4469 } else if ((!swiper.isBeginning || swiper.params.loop) && !swiper.animating) { 4470 swiper.slidePrev(); 4471 emit('scroll', newEvent.raw); 4472 } 4473 // If you got here is because an animation has been triggered so store the current time 4474 lastScrollTime = new window.Date().getTime(); 4475 // Return false as a default 4476 return false; 4477 } 4478 function releaseScroll(newEvent) { 4479 const params = swiper.params.mousewheel; 4480 if (newEvent.direction < 0) { 4481 if (swiper.isEnd && !swiper.params.loop && params.releaseOnEdges) { 4482 // Return true to animate scroll on edges 4483 return true; 4484 } 4485 } else if (swiper.isBeginning && !swiper.params.loop && params.releaseOnEdges) { 4486 // Return true to animate scroll on edges 4487 return true; 4488 } 4489 return false; 4490 } 4491 function handle(event) { 4492 let e = event; 4493 let disableParentSwiper = true; 4494 if (!swiper.enabled) return; 4495 const params = swiper.params.mousewheel; 4496 if (swiper.params.cssMode) { 4497 e.preventDefault(); 4498 } 4499 let targetEl = swiper.el; 4500 if (swiper.params.mousewheel.eventsTarget !== 'container') { 4501 targetEl = document.querySelector(swiper.params.mousewheel.eventsTarget); 4502 } 4503 const targetElContainsTarget = targetEl && targetEl.contains(e.target); 4504 if (!swiper.mouseEntered && !targetElContainsTarget && !params.releaseOnEdges) return true; 4505 if (e.originalEvent) e = e.originalEvent; // jquery fix 4506 let delta = 0; 4507 const rtlFactor = swiper.rtlTranslate ? -1 : 1; 4508 const data = normalize(e); 4509 if (params.forceToAxis) { 4510 if (swiper.isHorizontal()) { 4511 if (Math.abs(data.pixelX) > Math.abs(data.pixelY)) delta = -data.pixelX * rtlFactor;else return true; 4512 } else if (Math.abs(data.pixelY) > Math.abs(data.pixelX)) delta = -data.pixelY;else return true; 4513 } else { 4514 delta = Math.abs(data.pixelX) > Math.abs(data.pixelY) ? -data.pixelX * rtlFactor : -data.pixelY; 4515 } 4516 if (delta === 0) return true; 4517 if (params.invert) delta = -delta; 4518 4519 // Get the scroll positions 4520 let positions = swiper.getTranslate() + delta * params.sensitivity; 4521 if (positions >= swiper.minTranslate()) positions = swiper.minTranslate(); 4522 if (positions <= swiper.maxTranslate()) positions = swiper.maxTranslate(); 4523 4524 // When loop is true: 4525 // the disableParentSwiper will be true. 4526 // When loop is false: 4527 // if the scroll positions is not on edge, 4528 // then the disableParentSwiper will be true. 4529 // if the scroll on edge positions, 4530 // then the disableParentSwiper will be false. 4531 disableParentSwiper = swiper.params.loop ? true : !(positions === swiper.minTranslate() || positions === swiper.maxTranslate()); 4532 if (disableParentSwiper && swiper.params.nested) e.stopPropagation(); 4533 if (!swiper.params.freeMode || !swiper.params.freeMode.enabled) { 4534 // Register the new event in a variable which stores the relevant data 4535 const newEvent = { 4536 time: now(), 4537 delta: Math.abs(delta), 4538 direction: Math.sign(delta), 4539 raw: event 4540 }; 4541 4542 // Keep the most recent events 4543 if (recentWheelEvents.length >= 2) { 4544 recentWheelEvents.shift(); // only store the last N events 4545 } 4546 4547 const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined; 4548 recentWheelEvents.push(newEvent); 4549 4550 // If there is at least one previous recorded event: 4551 // If direction has changed or 4552 // if the scroll is quicker than the previous one: 4553 // Animate the slider. 4554 // Else (this is the first time the wheel is moved): 4555 // Animate the slider. 4556 if (prevEvent) { 4557 if (newEvent.direction !== prevEvent.direction || newEvent.delta > prevEvent.delta || newEvent.time > prevEvent.time + 150) { 4558 animateSlider(newEvent); 4559 } 4560 } else { 4561 animateSlider(newEvent); 4562 } 4563 4564 // If it's time to release the scroll: 4565 // Return now so you don't hit the preventDefault. 4566 if (releaseScroll(newEvent)) { 4567 return true; 4568 } 4569 } else { 4570 // Freemode or scrollContainer: 4571 4572 // If we recently snapped after a momentum scroll, then ignore wheel events 4573 // to give time for the deceleration to finish. Stop ignoring after 500 msecs 4574 // or if it's a new scroll (larger delta or inverse sign as last event before 4575 // an end-of-momentum snap). 4576 const newEvent = { 4577 time: now(), 4578 delta: Math.abs(delta), 4579 direction: Math.sign(delta) 4580 }; 4581 const ignoreWheelEvents = lastEventBeforeSnap && newEvent.time < lastEventBeforeSnap.time + 500 && newEvent.delta <= lastEventBeforeSnap.delta && newEvent.direction === lastEventBeforeSnap.direction; 4582 if (!ignoreWheelEvents) { 4583 lastEventBeforeSnap = undefined; 4584 if (swiper.params.loop) { 4585 swiper.loopFix(); 4586 } 4587 let position = swiper.getTranslate() + delta * params.sensitivity; 4588 const wasBeginning = swiper.isBeginning; 4589 const wasEnd = swiper.isEnd; 4590 if (position >= swiper.minTranslate()) position = swiper.minTranslate(); 4591 if (position <= swiper.maxTranslate()) position = swiper.maxTranslate(); 4592 swiper.setTransition(0); 4593 swiper.setTranslate(position); 4594 swiper.updateProgress(); 4595 swiper.updateActiveIndex(); 4596 swiper.updateSlidesClasses(); 4597 if (!wasBeginning && swiper.isBeginning || !wasEnd && swiper.isEnd) { 4598 swiper.updateSlidesClasses(); 4599 } 4600 if (swiper.params.freeMode.sticky) { 4601 // When wheel scrolling starts with sticky (aka snap) enabled, then detect 4602 // the end of a momentum scroll by storing recent (N=15?) wheel events. 4603 // 1. do all N events have decreasing or same (absolute value) delta? 4604 // 2. did all N events arrive in the last M (M=500?) msecs? 4605 // 3. does the earliest event have an (absolute value) delta that's 4606 // at least P (P=1?) larger than the most recent event's delta? 4607 // 4. does the latest event have a delta that's smaller than Q (Q=6?) pixels? 4608 // If 1-4 are "yes" then we're near the end of a momentum scroll deceleration. 4609 // Snap immediately and ignore remaining wheel events in this scroll. 4610 // See comment above for "remaining wheel events in this scroll" determination. 4611 // If 1-4 aren't satisfied, then wait to snap until 500ms after the last event. 4612 clearTimeout(timeout); 4613 timeout = undefined; 4614 if (recentWheelEvents.length >= 15) { 4615 recentWheelEvents.shift(); // only store the last N events 4616 } 4617 4618 const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined; 4619 const firstEvent = recentWheelEvents[0]; 4620 recentWheelEvents.push(newEvent); 4621 if (prevEvent && (newEvent.delta > prevEvent.delta || newEvent.direction !== prevEvent.direction)) { 4622 // Increasing or reverse-sign delta means the user started scrolling again. Clear the wheel event log. 4623 recentWheelEvents.splice(0); 4624 } else if (recentWheelEvents.length >= 15 && newEvent.time - firstEvent.time < 500 && firstEvent.delta - newEvent.delta >= 1 && newEvent.delta <= 6) { 4625 // We're at the end of the deceleration of a momentum scroll, so there's no need 4626 // to wait for more events. Snap ASAP on the next tick. 4627 // Also, because there's some remaining momentum we'll bias the snap in the 4628 // direction of the ongoing scroll because it's better UX for the scroll to snap 4629 // in the same direction as the scroll instead of reversing to snap. Therefore, 4630 // if it's already scrolled more than 20% in the current direction, keep going. 4631 const snapToThreshold = delta > 0 ? 0.8 : 0.2; 4632 lastEventBeforeSnap = newEvent; 4633 recentWheelEvents.splice(0); 4634 timeout = nextTick(() => { 4635 swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold); 4636 }, 0); // no delay; move on next tick 4637 } 4638 4639 if (!timeout) { 4640 // if we get here, then we haven't detected the end of a momentum scroll, so 4641 // we'll consider a scroll "complete" when there haven't been any wheel events 4642 // for 500ms. 4643 timeout = nextTick(() => { 4644 const snapToThreshold = 0.5; 4645 lastEventBeforeSnap = newEvent; 4646 recentWheelEvents.splice(0); 4647 swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold); 4648 }, 500); 4649 } 4650 } 4651 4652 // Emit event 4653 if (!ignoreWheelEvents) emit('scroll', e); 4654 4655 // Stop autoplay 4656 if (swiper.params.autoplay && swiper.params.autoplayDisableOnInteraction) swiper.autoplay.stop(); 4657 // Return page scroll on edge positions 4658 if (position === swiper.minTranslate() || position === swiper.maxTranslate()) return true; 4659 } 4660 } 4661 if (e.preventDefault) e.preventDefault();else e.returnValue = false; 4662 return false; 4663 } 4664 function events(method) { 4665 let targetEl = swiper.el; 4666 if (swiper.params.mousewheel.eventsTarget !== 'container') { 4667 targetEl = document.querySelector(swiper.params.mousewheel.eventsTarget); 4668 } 4669 targetEl[method]('mouseenter', handleMouseEnter); 4670 targetEl[method]('mouseleave', handleMouseLeave); 4671 targetEl[method]('wheel', handle); 4672 } 4673 function enable() { 4674 if (swiper.params.cssMode) { 4675 swiper.wrapperEl.removeEventListener('wheel', handle); 4676 return true; 4677 } 4678 if (swiper.mousewheel.enabled) return false; 4679 events('addEventListener'); 4680 swiper.mousewheel.enabled = true; 4681 return true; 4682 } 4683 function disable() { 4684 if (swiper.params.cssMode) { 4685 swiper.wrapperEl.addEventListener(event, handle); 4686 return true; 4687 } 4688 if (!swiper.mousewheel.enabled) return false; 4689 events('removeEventListener'); 4690 swiper.mousewheel.enabled = false; 4691 return true; 4692 } 4693 on('init', () => { 4694 if (!swiper.params.mousewheel.enabled && swiper.params.cssMode) { 4695 disable(); 4696 } 4697 if (swiper.params.mousewheel.enabled) enable(); 4698 }); 4699 on('destroy', () => { 4700 if (swiper.params.cssMode) { 4701 enable(); 4702 } 4703 if (swiper.mousewheel.enabled) disable(); 4704 }); 4705 Object.assign(swiper.mousewheel, { 4706 enable, 4707 disable 4708 }); 4709 } 4710 4711 function createElementIfNotDefined(swiper, originalParams, params, checkProps) { 4712 if (swiper.params.createElements) { 4713 Object.keys(checkProps).forEach(key => { 4714 if (!params[key] && params.auto === true) { 4715 let element = elementChildren(swiper.el, `.${checkProps[key]}`)[0]; 4716 if (!element) { 4717 element = createElement('div', checkProps[key]); 4718 element.className = checkProps[key]; 4719 swiper.el.append(element); 4720 } 4721 params[key] = element; 4722 originalParams[key] = element; 4723 } 4724 }); 4725 } 4726 return params; 4727 } 4728 4729 function Navigation(_ref) { 4730 let { 4731 swiper, 4732 extendParams, 4733 on, 4734 emit 4735 } = _ref; 4736 extendParams({ 4737 navigation: { 4738 nextEl: null, 4739 prevEl: null, 4740 hideOnClick: false, 4741 disabledClass: 'swiper-button-disabled', 4742 hiddenClass: 'swiper-button-hidden', 4743 lockClass: 'swiper-button-lock', 4744 navigationDisabledClass: 'swiper-navigation-disabled' 4745 } 4746 }); 4747 swiper.navigation = { 4748 nextEl: null, 4749 prevEl: null 4750 }; 4751 const makeElementsArray = el => { 4752 if (!Array.isArray(el)) el = [el].filter(e => !!e); 4753 return el; 4754 }; 4755 function getEl(el) { 4756 let res; 4757 if (el && typeof el === 'string' && swiper.isElement) { 4758 res = swiper.el.shadowRoot.querySelector(el); 4759 if (res) return res; 4760 } 4761 if (el) { 4762 if (typeof el === 'string') res = [...document.querySelectorAll(el)]; 4763 if (swiper.params.uniqueNavElements && typeof el === 'string' && res.length > 1 && swiper.el.querySelectorAll(el).length === 1) { 4764 res = swiper.el.querySelector(el); 4765 } 4766 } 4767 if (el && !res) return el; 4768 // if (Array.isArray(res) && res.length === 1) res = res[0]; 4769 return res; 4770 } 4771 function toggleEl(el, disabled) { 4772 const params = swiper.params.navigation; 4773 el = makeElementsArray(el); 4774 el.forEach(subEl => { 4775 if (subEl) { 4776 subEl.classList[disabled ? 'add' : 'remove'](params.disabledClass); 4777 if (subEl.tagName === 'BUTTON') subEl.disabled = disabled; 4778 if (swiper.params.watchOverflow && swiper.enabled) { 4779 subEl.classList[swiper.isLocked ? 'add' : 'remove'](params.lockClass); 4780 } 4781 } 4782 }); 4783 } 4784 function update() { 4785 // Update Navigation Buttons 4786 const { 4787 nextEl, 4788 prevEl 4789 } = swiper.navigation; 4790 if (swiper.params.loop) { 4791 toggleEl(prevEl, false); 4792 toggleEl(nextEl, false); 4793 return; 4794 } 4795 toggleEl(prevEl, swiper.isBeginning && !swiper.params.rewind); 4796 toggleEl(nextEl, swiper.isEnd && !swiper.params.rewind); 4797 } 4798 function onPrevClick(e) { 4799 e.preventDefault(); 4800 if (swiper.isBeginning && !swiper.params.loop && !swiper.params.rewind) return; 4801 swiper.slidePrev(); 4802 emit('navigationPrev'); 4803 } 4804 function onNextClick(e) { 4805 e.preventDefault(); 4806 if (swiper.isEnd && !swiper.params.loop && !swiper.params.rewind) return; 4807 swiper.slideNext(); 4808 emit('navigationNext'); 4809 } 4810 function init() { 4811 const params = swiper.params.navigation; 4812 swiper.params.navigation = createElementIfNotDefined(swiper, swiper.originalParams.navigation, swiper.params.navigation, { 4813 nextEl: 'swiper-button-next', 4814 prevEl: 'swiper-button-prev' 4815 }); 4816 if (!(params.nextEl || params.prevEl)) return; 4817 let nextEl = getEl(params.nextEl); 4818 let prevEl = getEl(params.prevEl); 4819 Object.assign(swiper.navigation, { 4820 nextEl, 4821 prevEl 4822 }); 4823 nextEl = makeElementsArray(nextEl); 4824 prevEl = makeElementsArray(prevEl); 4825 const initButton = (el, dir) => { 4826 if (el) { 4827 el.addEventListener('click', dir === 'next' ? onNextClick : onPrevClick); 4828 } 4829 if (!swiper.enabled && el) { 4830 el.classList.add(params.lockClass); 4831 } 4832 }; 4833 nextEl.forEach(el => initButton(el, 'next')); 4834 prevEl.forEach(el => initButton(el, 'prev')); 4835 } 4836 function destroy() { 4837 let { 4838 nextEl, 4839 prevEl 4840 } = swiper.navigation; 4841 nextEl = makeElementsArray(nextEl); 4842 prevEl = makeElementsArray(prevEl); 4843 const destroyButton = (el, dir) => { 4844 el.removeEventListener('click', dir === 'next' ? onNextClick : onPrevClick); 4845 el.classList.remove(swiper.params.navigation.disabledClass); 4846 }; 4847 nextEl.forEach(el => destroyButton(el, 'next')); 4848 prevEl.forEach(el => destroyButton(el, 'prev')); 4849 } 4850 on('init', () => { 4851 if (swiper.params.navigation.enabled === false) { 4852 // eslint-disable-next-line 4853 disable(); 4854 } else { 4855 init(); 4856 update(); 4857 } 4858 }); 4859 on('toEdge fromEdge lock unlock', () => { 4860 update(); 4861 }); 4862 on('destroy', () => { 4863 destroy(); 4864 }); 4865 on('enable disable', () => { 4866 let { 4867 nextEl, 4868 prevEl 4869 } = swiper.navigation; 4870 nextEl = makeElementsArray(nextEl); 4871 prevEl = makeElementsArray(prevEl); 4872 [...nextEl, ...prevEl].filter(el => !!el).forEach(el => el.classList[swiper.enabled ? 'remove' : 'add'](swiper.params.navigation.lockClass)); 4873 }); 4874 on('click', (_s, e) => { 4875 let { 4876 nextEl, 4877 prevEl 4878 } = swiper.navigation; 4879 nextEl = makeElementsArray(nextEl); 4880 prevEl = makeElementsArray(prevEl); 4881 const targetEl = e.target; 4882 if (swiper.params.navigation.hideOnClick && !prevEl.includes(targetEl) && !nextEl.includes(targetEl)) { 4883 if (swiper.pagination && swiper.params.pagination && swiper.params.pagination.clickable && (swiper.pagination.el === targetEl || swiper.pagination.el.contains(targetEl))) return; 4884 let isHidden; 4885 if (nextEl.length) { 4886 isHidden = nextEl[0].classList.contains(swiper.params.navigation.hiddenClass); 4887 } else if (prevEl.length) { 4888 isHidden = prevEl[0].classList.contains(swiper.params.navigation.hiddenClass); 4889 } 4890 if (isHidden === true) { 4891 emit('navigationShow'); 4892 } else { 4893 emit('navigationHide'); 4894 } 4895 [...nextEl, ...prevEl].filter(el => !!el).forEach(el => el.classList.toggle(swiper.params.navigation.hiddenClass)); 4896 } 4897 }); 4898 const enable = () => { 4899 swiper.el.classList.remove(swiper.params.navigation.navigationDisabledClass); 4900 init(); 4901 update(); 4902 }; 4903 const disable = () => { 4904 swiper.el.classList.add(swiper.params.navigation.navigationDisabledClass); 4905 destroy(); 4906 }; 4907 Object.assign(swiper.navigation, { 4908 enable, 4909 disable, 4910 update, 4911 init, 4912 destroy 4913 }); 4914 } 4915 4916 function classesToSelector(classes) { 4917 if (classes === void 0) { 4918 classes = ''; 4919 } 4920 return `.${classes.trim().replace(/([\.:!\/])/g, '\\$1') // eslint-disable-line 4921 .replace(/ /g, '.')}`; 4922 } 4923 4924 function Pagination(_ref) { 4925 let { 4926 swiper, 4927 extendParams, 4928 on, 4929 emit 4930 } = _ref; 4931 const pfx = 'swiper-pagination'; 4932 extendParams({ 4933 pagination: { 4934 el: null, 4935 bulletElement: 'span', 4936 clickable: false, 4937 hideOnClick: false, 4938 renderBullet: null, 4939 renderProgressbar: null, 4940 renderFraction: null, 4941 renderCustom: null, 4942 progressbarOpposite: false, 4943 type: 'bullets', 4944 // 'bullets' or 'progressbar' or 'fraction' or 'custom' 4945 dynamicBullets: false, 4946 dynamicMainBullets: 1, 4947 formatFractionCurrent: number => number, 4948 formatFractionTotal: number => number, 4949 bulletClass: `${pfx}-bullet`, 4950 bulletActiveClass: `${pfx}-bullet-active`, 4951 modifierClass: `${pfx}-`, 4952 currentClass: `${pfx}-current`, 4953 totalClass: `${pfx}-total`, 4954 hiddenClass: `${pfx}-hidden`, 4955 progressbarFillClass: `${pfx}-progressbar-fill`, 4956 progressbarOppositeClass: `${pfx}-progressbar-opposite`, 4957 clickableClass: `${pfx}-clickable`, 4958 lockClass: `${pfx}-lock`, 4959 horizontalClass: `${pfx}-horizontal`, 4960 verticalClass: `${pfx}-vertical`, 4961 paginationDisabledClass: `${pfx}-disabled` 4962 } 4963 }); 4964 swiper.pagination = { 4965 el: null, 4966 bullets: [] 4967 }; 4968 let bulletSize; 4969 let dynamicBulletIndex = 0; 4970 const makeElementsArray = el => { 4971 if (!Array.isArray(el)) el = [el].filter(e => !!e); 4972 return el; 4973 }; 4974 function isPaginationDisabled() { 4975 return !swiper.params.pagination.el || !swiper.pagination.el || Array.isArray(swiper.pagination.el) && swiper.pagination.el.length === 0; 4976 } 4977 function setSideBullets(bulletEl, position) { 4978 const { 4979 bulletActiveClass 4980 } = swiper.params.pagination; 4981 if (!bulletEl) return; 4982 bulletEl = bulletEl[`${position === 'prev' ? 'previous' : 'next'}ElementSibling`]; 4983 if (bulletEl) { 4984 bulletEl.classList.add(`${bulletActiveClass}-${position}`); 4985 bulletEl = bulletEl[`${position === 'prev' ? 'previous' : 'next'}ElementSibling`]; 4986 if (bulletEl) { 4987 bulletEl.classList.add(`${bulletActiveClass}-${position}-${position}`); 4988 } 4989 } 4990 } 4991 function onBulletClick(e) { 4992 const isBullet = e.target.matches(classesToSelector(swiper.params.pagination.bulletClass)); 4993 if (!isBullet) return; 4994 e.preventDefault(); 4995 const index = elementIndex(e.target) * swiper.params.slidesPerGroup; 4996 if (swiper.params.loop) { 4997 swiper.slideToLoop(index); 4998 } else { 4999 swiper.slideTo(index); 5000 } 5001 } 5002 function update() { 5003 // Render || Update Pagination bullets/items 5004 const rtl = swiper.rtl; 5005 const params = swiper.params.pagination; 5006 if (isPaginationDisabled()) return; 5007 let el = swiper.pagination.el; 5008 el = makeElementsArray(el); 5009 // Current/Total 5010 let current; 5011 const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length; 5012 const total = swiper.params.loop ? Math.ceil(slidesLength / swiper.params.slidesPerGroup) : swiper.snapGrid.length; 5013 if (swiper.params.loop) { 5014 current = swiper.params.slidesPerGroup > 1 ? Math.floor(swiper.realIndex / swiper.params.slidesPerGroup) : swiper.realIndex; 5015 } else if (typeof swiper.snapIndex !== 'undefined') { 5016 current = swiper.snapIndex; 5017 } else { 5018 current = swiper.activeIndex || 0; 5019 } 5020 // Types 5021 if (params.type === 'bullets' && swiper.pagination.bullets && swiper.pagination.bullets.length > 0) { 5022 const bullets = swiper.pagination.bullets; 5023 let firstIndex; 5024 let lastIndex; 5025 let midIndex; 5026 if (params.dynamicBullets) { 5027 bulletSize = elementOuterSize(bullets[0], swiper.isHorizontal() ? 'width' : 'height', true); 5028 el.forEach(subEl => { 5029 subEl.style[swiper.isHorizontal() ? 'width' : 'height'] = `${bulletSize * (params.dynamicMainBullets + 4)}px`; 5030 }); 5031 if (params.dynamicMainBullets > 1 && swiper.previousIndex !== undefined) { 5032 dynamicBulletIndex += current - (swiper.previousIndex || 0); 5033 if (dynamicBulletIndex > params.dynamicMainBullets - 1) { 5034 dynamicBulletIndex = params.dynamicMainBullets - 1; 5035 } else if (dynamicBulletIndex < 0) { 5036 dynamicBulletIndex = 0; 5037 } 5038 } 5039 firstIndex = Math.max(current - dynamicBulletIndex, 0); 5040 lastIndex = firstIndex + (Math.min(bullets.length, params.dynamicMainBullets) - 1); 5041 midIndex = (lastIndex + firstIndex) / 2; 5042 } 5043 bullets.forEach(bulletEl => { 5044 bulletEl.classList.remove(...['', '-next', '-next-next', '-prev', '-prev-prev', '-main'].map(suffix => `${params.bulletActiveClass}${suffix}`)); 5045 }); 5046 if (el.length > 1) { 5047 bullets.forEach(bullet => { 5048 const bulletIndex = elementIndex(bullet); 5049 if (bulletIndex === current) { 5050 bullet.classList.add(params.bulletActiveClass); 5051 } 5052 if (params.dynamicBullets) { 5053 if (bulletIndex >= firstIndex && bulletIndex <= lastIndex) { 5054 bullet.classList.add(`${params.bulletActiveClass}-main`); 5055 } 5056 if (bulletIndex === firstIndex) { 5057 setSideBullets(bullet, 'prev'); 5058 } 5059 if (bulletIndex === lastIndex) { 5060 setSideBullets(bullet, 'next'); 5061 } 5062 } 5063 }); 5064 } else { 5065 const bullet = bullets[current]; 5066 if (bullet) { 5067 bullet.classList.add(params.bulletActiveClass); 5068 } 5069 if (params.dynamicBullets) { 5070 const firstDisplayedBullet = bullets[firstIndex]; 5071 const lastDisplayedBullet = bullets[lastIndex]; 5072 for (let i = firstIndex; i <= lastIndex; i += 1) { 5073 bullets[i].classList.add(`${params.bulletActiveClass}-main`); 5074 } 5075 setSideBullets(firstDisplayedBullet, 'prev'); 5076 setSideBullets(lastDisplayedBullet, 'next'); 5077 } 5078 } 5079 if (params.dynamicBullets) { 5080 const dynamicBulletsLength = Math.min(bullets.length, params.dynamicMainBullets + 4); 5081 const bulletsOffset = (bulletSize * dynamicBulletsLength - bulletSize) / 2 - midIndex * bulletSize; 5082 const offsetProp = rtl ? 'right' : 'left'; 5083 bullets.forEach(bullet => { 5084 bullet.style[swiper.isHorizontal() ? offsetProp : 'top'] = `${bulletsOffset}px`; 5085 }); 5086 } 5087 } 5088 el.forEach((subEl, subElIndex) => { 5089 if (params.type === 'fraction') { 5090 subEl.querySelectorAll(classesToSelector(params.currentClass)).forEach(fractionEl => { 5091 fractionEl.textContent = params.formatFractionCurrent(current + 1); 5092 }); 5093 subEl.querySelectorAll(classesToSelector(params.totalClass)).forEach(totalEl => { 5094 totalEl.textContent = params.formatFractionTotal(total); 5095 }); 5096 } 5097 if (params.type === 'progressbar') { 5098 let progressbarDirection; 5099 if (params.progressbarOpposite) { 5100 progressbarDirection = swiper.isHorizontal() ? 'vertical' : 'horizontal'; 5101 } else { 5102 progressbarDirection = swiper.isHorizontal() ? 'horizontal' : 'vertical'; 5103 } 5104 const scale = (current + 1) / total; 5105 let scaleX = 1; 5106 let scaleY = 1; 5107 if (progressbarDirection === 'horizontal') { 5108 scaleX = scale; 5109 } else { 5110 scaleY = scale; 5111 } 5112 subEl.querySelectorAll(classesToSelector(params.progressbarFillClass)).forEach(progressEl => { 5113 progressEl.style.transform = `translate3d(0,0,0) scaleX(${scaleX}) scaleY(${scaleY})`; 5114 progressEl.style.transitionDuration = `${swiper.params.speed}ms`; 5115 }); 5116 } 5117 if (params.type === 'custom' && params.renderCustom) { 5118 subEl.innerHTML = params.renderCustom(swiper, current + 1, total); 5119 if (subElIndex === 0) emit('paginationRender', subEl); 5120 } else { 5121 if (subElIndex === 0) emit('paginationRender', subEl); 5122 emit('paginationUpdate', subEl); 5123 } 5124 if (swiper.params.watchOverflow && swiper.enabled) { 5125 subEl.classList[swiper.isLocked ? 'add' : 'remove'](params.lockClass); 5126 } 5127 }); 5128 } 5129 function render() { 5130 // Render Container 5131 const params = swiper.params.pagination; 5132 if (isPaginationDisabled()) return; 5133 const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length; 5134 let el = swiper.pagination.el; 5135 el = makeElementsArray(el); 5136 let paginationHTML = ''; 5137 if (params.type === 'bullets') { 5138 let numberOfBullets = swiper.params.loop ? Math.ceil(slidesLength / swiper.params.slidesPerGroup) : swiper.snapGrid.length; 5139 if (swiper.params.freeMode && swiper.params.freeMode.enabled && numberOfBullets > slidesLength) { 5140 numberOfBullets = slidesLength; 5141 } 5142 for (let i = 0; i < numberOfBullets; i += 1) { 5143 if (params.renderBullet) { 5144 paginationHTML += params.renderBullet.call(swiper, i, params.bulletClass); 5145 } else { 5146 paginationHTML += `<${params.bulletElement} class="${params.bulletClass}"></${params.bulletElement}>`; 5147 } 5148 } 5149 } 5150 if (params.type === 'fraction') { 5151 if (params.renderFraction) { 5152 paginationHTML = params.renderFraction.call(swiper, params.currentClass, params.totalClass); 5153 } else { 5154 paginationHTML = `<span class="${params.currentClass}"></span>` + ' / ' + `<span class="${params.totalClass}"></span>`; 5155 } 5156 } 5157 if (params.type === 'progressbar') { 5158 if (params.renderProgressbar) { 5159 paginationHTML = params.renderProgressbar.call(swiper, params.progressbarFillClass); 5160 } else { 5161 paginationHTML = `<span class="${params.progressbarFillClass}"></span>`; 5162 } 5163 } 5164 el.forEach(subEl => { 5165 if (params.type !== 'custom') { 5166 subEl.innerHTML = paginationHTML || ''; 5167 } 5168 if (params.type === 'bullets') { 5169 swiper.pagination.bullets = [...subEl.querySelectorAll(classesToSelector(params.bulletClass))]; 5170 } 5171 }); 5172 if (params.type !== 'custom') { 5173 emit('paginationRender', el[0]); 5174 } 5175 } 5176 function init() { 5177 swiper.params.pagination = createElementIfNotDefined(swiper, swiper.originalParams.pagination, swiper.params.pagination, { 5178 el: 'swiper-pagination' 5179 }); 5180 const params = swiper.params.pagination; 5181 if (!params.el) return; 5182 let el; 5183 if (typeof params.el === 'string' && swiper.isElement) { 5184 el = swiper.el.shadowRoot.querySelector(params.el); 5185 } 5186 if (!el && typeof params.el === 'string') { 5187 el = [...document.querySelectorAll(params.el)]; 5188 } 5189 if (!el) { 5190 el = params.el; 5191 } 5192 if (!el || el.length === 0) return; 5193 if (swiper.params.uniqueNavElements && typeof params.el === 'string' && Array.isArray(el) && el.length > 1) { 5194 el = [...swiper.el.querySelectorAll(params.el)]; 5195 // check if it belongs to another nested Swiper 5196 if (el.length > 1) { 5197 el = el.filter(subEl => { 5198 if (elementParents(subEl, '.swiper')[0] !== swiper.el) return false; 5199 return true; 5200 })[0]; 5201 } 5202 } 5203 if (Array.isArray(el) && el.length === 1) el = el[0]; 5204 Object.assign(swiper.pagination, { 5205 el 5206 }); 5207 el = makeElementsArray(el); 5208 el.forEach(subEl => { 5209 if (params.type === 'bullets' && params.clickable) { 5210 subEl.classList.add(params.clickableClass); 5211 } 5212 subEl.classList.add(params.modifierClass + params.type); 5213 subEl.classList.add(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 5214 if (params.type === 'bullets' && params.dynamicBullets) { 5215 subEl.classList.add(`${params.modifierClass}${params.type}-dynamic`); 5216 dynamicBulletIndex = 0; 5217 if (params.dynamicMainBullets < 1) { 5218 params.dynamicMainBullets = 1; 5219 } 5220 } 5221 if (params.type === 'progressbar' && params.progressbarOpposite) { 5222 subEl.classList.add(params.progressbarOppositeClass); 5223 } 5224 if (params.clickable) { 5225 subEl.addEventListener('click', onBulletClick); 5226 } 5227 if (!swiper.enabled) { 5228 subEl.classList.add(params.lockClass); 5229 } 5230 }); 5231 } 5232 function destroy() { 5233 const params = swiper.params.pagination; 5234 if (isPaginationDisabled()) return; 5235 let el = swiper.pagination.el; 5236 if (el) { 5237 el = makeElementsArray(el); 5238 el.forEach(subEl => { 5239 subEl.classList.remove(params.hiddenClass); 5240 subEl.classList.remove(params.modifierClass + params.type); 5241 subEl.classList.remove(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 5242 if (params.clickable) { 5243 subEl.removeEventListener('click', onBulletClick); 5244 } 5245 }); 5246 } 5247 if (swiper.pagination.bullets) swiper.pagination.bullets.forEach(subEl => subEl.classList.remove(params.bulletActiveClass)); 5248 } 5249 on('init', () => { 5250 if (swiper.params.pagination.enabled === false) { 5251 // eslint-disable-next-line 5252 disable(); 5253 } else { 5254 init(); 5255 render(); 5256 update(); 5257 } 5258 }); 5259 on('activeIndexChange', () => { 5260 if (typeof swiper.snapIndex === 'undefined') { 5261 update(); 5262 } 5263 }); 5264 on('snapIndexChange', () => { 5265 update(); 5266 }); 5267 on('snapGridLengthChange', () => { 5268 render(); 5269 update(); 5270 }); 5271 on('destroy', () => { 5272 destroy(); 5273 }); 5274 on('enable disable', () => { 5275 let { 5276 el 5277 } = swiper.pagination; 5278 if (el) { 5279 el = makeElementsArray(el); 5280 el.forEach(subEl => subEl.classList[swiper.enabled ? 'remove' : 'add'](swiper.params.pagination.lockClass)); 5281 } 5282 }); 5283 on('lock unlock', () => { 5284 update(); 5285 }); 5286 on('click', (_s, e) => { 5287 const targetEl = e.target; 5288 let { 5289 el 5290 } = swiper.pagination; 5291 if (!Array.isArray(el)) el = [el].filter(element => !!element); 5292 if (swiper.params.pagination.el && swiper.params.pagination.hideOnClick && el && el.length > 0 && !targetEl.classList.contains(swiper.params.pagination.bulletClass)) { 5293 if (swiper.navigation && (swiper.navigation.nextEl && targetEl === swiper.navigation.nextEl || swiper.navigation.prevEl && targetEl === swiper.navigation.prevEl)) return; 5294 const isHidden = el[0].classList.contains(swiper.params.pagination.hiddenClass); 5295 if (isHidden === true) { 5296 emit('paginationShow'); 5297 } else { 5298 emit('paginationHide'); 5299 } 5300 el.forEach(subEl => subEl.classList.toggle(swiper.params.pagination.hiddenClass)); 5301 } 5302 }); 5303 const enable = () => { 5304 swiper.el.classList.remove(swiper.params.pagination.paginationDisabledClass); 5305 let { 5306 el 5307 } = swiper.pagination; 5308 if (el) { 5309 el = makeElementsArray(el); 5310 el.forEach(subEl => subEl.classList.remove(swiper.params.pagination.paginationDisabledClass)); 5311 } 5312 init(); 5313 render(); 5314 update(); 5315 }; 5316 const disable = () => { 5317 swiper.el.classList.add(swiper.params.pagination.paginationDisabledClass); 5318 let { 5319 el 5320 } = swiper.pagination; 5321 if (el) { 5322 el = makeElementsArray(el); 5323 el.forEach(subEl => subEl.classList.add(swiper.params.pagination.paginationDisabledClass)); 5324 } 5325 destroy(); 5326 }; 5327 Object.assign(swiper.pagination, { 5328 enable, 5329 disable, 5330 render, 5331 update, 5332 init, 5333 destroy 5334 }); 5335 } 5336 5337 function Scrollbar(_ref) { 5338 let { 5339 swiper, 5340 extendParams, 5341 on, 5342 emit 5343 } = _ref;
vendor: 5,743 bytes, lines 5343-5513
5343 5344 const document = getDocument(); 5345 let isTouched = false; 5346 let timeout = null; 5347 let dragTimeout = null; 5348 let dragStartPos; 5349 let dragSize; 5350 let trackSize; 5351 let divider; 5352 extendParams({ 5353 scrollbar: { 5354 el: null, 5355 dragSize: 'auto', 5356 hide: false, 5357 draggable: false, 5358 snapOnRelease: true, 5359 lockClass: 'swiper-scrollbar-lock', 5360 dragClass: 'swiper-scrollbar-drag', 5361 scrollbarDisabledClass: 'swiper-scrollbar-disabled', 5362 horizontalClass: `swiper-scrollbar-horizontal`, 5363 verticalClass: `swiper-scrollbar-vertical` 5364 } 5365 }); 5366 swiper.scrollbar = { 5367 el: null, 5368 dragEl: null 5369 }; 5370 function setTranslate() { 5371 if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return; 5372 const { 5373 scrollbar, 5374 rtlTranslate: rtl 5375 } = swiper; 5376 const { 5377 dragEl, 5378 el 5379 } = scrollbar; 5380 const params = swiper.params.scrollbar; 5381 const progress = swiper.params.loop ? swiper.progressLoop : swiper.progress; 5382 let newSize = dragSize; 5383 let newPos = (trackSize - dragSize) * progress; 5384 if (rtl) { 5385 newPos = -newPos; 5386 if (newPos > 0) { 5387 newSize = dragSize - newPos; 5388 newPos = 0; 5389 } else if (-newPos + dragSize > trackSize) { 5390 newSize = trackSize + newPos; 5391 } 5392 } else if (newPos < 0) { 5393 newSize = dragSize + newPos; 5394 newPos = 0; 5395 } else if (newPos + dragSize > trackSize) { 5396 newSize = trackSize - newPos; 5397 } 5398 if (swiper.isHorizontal()) { 5399 dragEl.style.transform = `translate3d(${newPos}px, 0, 0)`; 5400 dragEl.style.width = `${newSize}px`; 5401 } else { 5402 dragEl.style.transform = `translate3d(0px, ${newPos}px, 0)`; 5403 dragEl.style.height = `${newSize}px`; 5404 } 5405 if (params.hide) { 5406 clearTimeout(timeout); 5407 el.style.opacity = 1; 5408 timeout = setTimeout(() => { 5409 el.style.opacity = 0; 5410 el.style.transitionDuration = '400ms'; 5411 }, 1000); 5412 } 5413 } 5414 function setTransition(duration) { 5415 if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return; 5416 swiper.scrollbar.dragEl.style.transitionDuration = `${duration}ms`; 5417 } 5418 function updateSize() { 5419 if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return; 5420 const { 5421 scrollbar 5422 } = swiper; 5423 const { 5424 dragEl, 5425 el 5426 } = scrollbar; 5427 dragEl.style.width = ''; 5428 dragEl.style.height = ''; 5429 trackSize = swiper.isHorizontal() ? el.offsetWidth : el.offsetHeight; 5430 divider = swiper.size / (swiper.virtualSize + swiper.params.slidesOffsetBefore - (swiper.params.centeredSlides ? swiper.snapGrid[0] : 0)); 5431 if (swiper.params.scrollbar.dragSize === 'auto') { 5432 dragSize = trackSize * divider; 5433 } else { 5434 dragSize = parseInt(swiper.params.scrollbar.dragSize, 10); 5435 } 5436 if (swiper.isHorizontal()) { 5437 dragEl.style.width = `${dragSize}px`; 5438 } else { 5439 dragEl.style.height = `${dragSize}px`; 5440 } 5441 if (divider >= 1) { 5442 el.style.display = 'none'; 5443 } else { 5444 el.style.display = ''; 5445 } 5446 if (swiper.params.scrollbar.hide) { 5447 el.style.opacity = 0; 5448 } 5449 if (swiper.params.watchOverflow && swiper.enabled) { 5450 scrollbar.el.classList[swiper.isLocked ? 'add' : 'remove'](swiper.params.scrollbar.lockClass); 5451 } 5452 } 5453 function getPointerPosition(e) { 5454 return swiper.isHorizontal() ? e.clientX : e.clientY; 5455 } 5456 function setDragPosition(e) { 5457 const { 5458 scrollbar, 5459 rtlTranslate: rtl 5460 } = swiper; 5461 const { 5462 el 5463 } = scrollbar; 5464 let positionRatio; 5465 positionRatio = (getPointerPosition(e) - elementOffset(el)[swiper.isHorizontal() ? 'left' : 'top'] - (dragStartPos !== null ? dragStartPos : dragSize / 2)) / (trackSize - dragSize); 5466 positionRatio = Math.max(Math.min(positionRatio, 1), 0); 5467 if (rtl) { 5468 positionRatio = 1 - positionRatio; 5469 } 5470 const position = swiper.minTranslate() + (swiper.maxTranslate() - swiper.minTranslate()) * positionRatio; 5471 swiper.updateProgress(position); 5472 swiper.setTranslate(position); 5473 swiper.updateActiveIndex(); 5474 swiper.updateSlidesClasses(); 5475 } 5476 function onDragStart(e) { 5477 const params = swiper.params.scrollbar; 5478 const { 5479 scrollbar, 5480 wrapperEl 5481 } = swiper; 5482 const { 5483 el, 5484 dragEl 5485 } = scrollbar; 5486 isTouched = true; 5487 dragStartPos = e.target === dragEl ? getPointerPosition(e) - e.target.getBoundingClientRect()[swiper.isHorizontal() ? 'left' : 'top'] : null; 5488 e.preventDefault(); 5489 e.stopPropagation(); 5490 wrapperEl.style.transitionDuration = '100ms'; 5491 dragEl.style.transitionDuration = '100ms'; 5492 setDragPosition(e); 5493 clearTimeout(dragTimeout); 5494 el.style.transitionDuration = '0ms'; 5495 if (params.hide) { 5496 el.style.opacity = 1; 5497 } 5498 if (swiper.params.cssMode) { 5499 swiper.wrapperEl.style['scroll-snap-type'] = 'none'; 5500 } 5501 emit('scrollbarDragStart', e); 5502 } 5503 function onDragMove(e) { 5504 const { 5505 scrollbar, 5506 wrapperEl 5507 } = swiper; 5508 const { 5509 el, 5510 dragEl 5511 } = scrollbar; 5512 if (!isTouched) return; 5513 if (e.preventDefault
vendor: 16,387 bytes, lines 5513-5981
5513) e.preventDefault();else e.returnValue = false; 5514 setDragPosition(e); 5515 wrapperEl.style.transitionDuration = '0ms'; 5516 el.style.transitionDuration = '0ms'; 5517 dragEl.style.transitionDuration = '0ms'; 5518 emit('scrollbarDragMove', e); 5519 } 5520 function onDragEnd(e) { 5521 const params = swiper.params.scrollbar; 5522 const { 5523 scrollbar, 5524 wrapperEl 5525 } = swiper; 5526 const { 5527 el 5528 } = scrollbar; 5529 if (!isTouched) return; 5530 isTouched = false; 5531 if (swiper.params.cssMode) { 5532 swiper.wrapperEl.style['scroll-snap-type'] = ''; 5533 wrapperEl.style.transitionDuration = ''; 5534 } 5535 if (params.hide) { 5536 clearTimeout(dragTimeout); 5537 dragTimeout = nextTick(() => { 5538 el.style.opacity = 0; 5539 el.style.transitionDuration = '400ms'; 5540 }, 1000); 5541 } 5542 emit('scrollbarDragEnd', e); 5543 if (params.snapOnRelease) { 5544 swiper.slideToClosest(); 5545 } 5546 } 5547 function events(method) { 5548 const { 5549 scrollbar, 5550 params 5551 } = swiper; 5552 const el = scrollbar.el; 5553 if (!el) return; 5554 const target = el; 5555 const activeListener = params.passiveListeners ? { 5556 passive: false, 5557 capture: false 5558 } : false; 5559 const passiveListener = params.passiveListeners ? { 5560 passive: true, 5561 capture: false 5562 } : false; 5563 if (!target) return; 5564 const eventMethod = method === 'on' ? 'addEventListener' : 'removeEventListener'; 5565 target[eventMethod]('pointerdown', onDragStart, activeListener); 5566 document[eventMethod]('pointermove', onDragMove, activeListener); 5567 document[eventMethod]('pointerup', onDragEnd, passiveListener); 5568 } 5569 function enableDraggable() { 5570 if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return; 5571 events('on'); 5572 } 5573 function disableDraggable() { 5574 if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return; 5575 events('off'); 5576 } 5577 function init() { 5578 const { 5579 scrollbar, 5580 el: swiperEl 5581 } = swiper; 5582 swiper.params.scrollbar = createElementIfNotDefined(swiper, swiper.originalParams.scrollbar, swiper.params.scrollbar, { 5583 el: 'swiper-scrollbar' 5584 }); 5585 const params = swiper.params.scrollbar; 5586 if (!params.el) return; 5587 let el; 5588 if (typeof params.el === 'string' && swiper.isElement) { 5589 el = swiper.el.shadowRoot.querySelector(params.el); 5590 } 5591 if (!el && typeof params.el === 'string') { 5592 el = document.querySelectorAll(params.el); 5593 } else if (!el) { 5594 el = params.el; 5595 } 5596 if (swiper.params.uniqueNavElements && typeof params.el === 'string' && el.length > 1 && swiperEl.querySelectorAll(params.el).length === 1) { 5597 el = swiperEl.querySelector(params.el); 5598 } 5599 if (el.length > 0) el = el[0]; 5600 el.classList.add(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 5601 let dragEl; 5602 if (el) { 5603 el.querySelector(`.${swiper.params.scrollbar.dragClass}`); 5604 if (!dragEl) { 5605 dragEl = createElement('div', swiper.params.scrollbar.dragClass); 5606 el.append(dragEl); 5607 } 5608 } 5609 Object.assign(scrollbar, { 5610 el, 5611 dragEl 5612 }); 5613 if (params.draggable) { 5614 enableDraggable(); 5615 } 5616 if (el) { 5617 el.classList[swiper.enabled ? 'remove' : 'add'](swiper.params.scrollbar.lockClass); 5618 } 5619 } 5620 function destroy() { 5621 const params = swiper.params.scrollbar; 5622 const el = swiper.scrollbar.el; 5623 if (el) { 5624 el.classList.remove(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 5625 } 5626 disableDraggable(); 5627 } 5628 on('init', () => { 5629 if (swiper.params.scrollbar.enabled === false) { 5630 // eslint-disable-next-line 5631 disable(); 5632 } else { 5633 init(); 5634 updateSize(); 5635 setTranslate(); 5636 } 5637 }); 5638 on('update resize observerUpdate lock unlock', () => { 5639 updateSize(); 5640 }); 5641 on('setTranslate', () => { 5642 setTranslate(); 5643 }); 5644 on('setTransition', (_s, duration) => { 5645 setTransition(duration); 5646 }); 5647 on('enable disable', () => { 5648 const { 5649 el 5650 } = swiper.scrollbar; 5651 if (el) { 5652 el.classList[swiper.enabled ? 'remove' : 'add'](swiper.params.scrollbar.lockClass); 5653 } 5654 }); 5655 on('destroy', () => { 5656 destroy(); 5657 }); 5658 const enable = () => { 5659 swiper.el.classList.remove(swiper.params.scrollbar.scrollbarDisabledClass); 5660 if (swiper.scrollbar.el) { 5661 swiper.scrollbar.el.classList.remove(swiper.params.scrollbar.scrollbarDisabledClass); 5662 } 5663 init(); 5664 updateSize(); 5665 setTranslate(); 5666 }; 5667 const disable = () => { 5668 swiper.el.classList.add(swiper.params.scrollbar.scrollbarDisabledClass); 5669 if (swiper.scrollbar.el) { 5670 swiper.scrollbar.el.classList.add(swiper.params.scrollbar.scrollbarDisabledClass); 5671 } 5672 destroy(); 5673 }; 5674 Object.assign(swiper.scrollbar, { 5675 enable, 5676 disable, 5677 updateSize, 5678 setTranslate, 5679 init, 5680 destroy 5681 }); 5682 } 5683 5684 function Parallax(_ref) { 5685 let { 5686 swiper, 5687 extendParams, 5688 on 5689 } = _ref; 5690 extendParams({ 5691 parallax: { 5692 enabled: false 5693 } 5694 }); 5695 const setTransform = (el, progress) => { 5696 const { 5697 rtl 5698 } = swiper; 5699 const rtlFactor = rtl ? -1 : 1; 5700 const p = el.getAttribute('data-swiper-parallax') || '0'; 5701 let x = el.getAttribute('data-swiper-parallax-x'); 5702 let y = el.getAttribute('data-swiper-parallax-y'); 5703 const scale = el.getAttribute('data-swiper-parallax-scale'); 5704 const opacity = el.getAttribute('data-swiper-parallax-opacity'); 5705 const rotate = el.getAttribute('data-swiper-parallax-rotate'); 5706 if (x || y) { 5707 x = x || '0'; 5708 y = y || '0'; 5709 } else if (swiper.isHorizontal()) { 5710 x = p; 5711 y = '0'; 5712 } else { 5713 y = p; 5714 x = '0'; 5715 } 5716 if (x.indexOf('%') >= 0) { 5717 x = `${parseInt(x, 10) * progress * rtlFactor}%`; 5718 } else { 5719 x = `${x * progress * rtlFactor}px`; 5720 } 5721 if (y.indexOf('%') >= 0) { 5722 y = `${parseInt(y, 10) * progress}%`; 5723 } else { 5724 y = `${y * progress}px`; 5725 } 5726 if (typeof opacity !== 'undefined' && opacity !== null) { 5727 const currentOpacity = opacity - (opacity - 1) * (1 - Math.abs(progress)); 5728 el.style.opacity = currentOpacity; 5729 } 5730 let transform = `translate3d(${x}, ${y}, 0px)`; 5731 if (typeof scale !== 'undefined' && scale !== null) { 5732 const currentScale = scale - (scale - 1) * (1 - Math.abs(progress)); 5733 transform += ` scale(${currentScale})`; 5734 } 5735 if (rotate && typeof rotate !== 'undefined' && rotate !== null) { 5736 const currentRotate = rotate * progress * -1; 5737 transform += ` rotate(${currentRotate}deg)`; 5738 } 5739 el.style.transform = transform; 5740 }; 5741 const setTranslate = () => { 5742 const { 5743 el, 5744 slides, 5745 progress, 5746 snapGrid 5747 } = swiper; 5748 elementChildren(el, '[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').forEach(subEl => { 5749 setTransform(subEl, progress); 5750 }); 5751 slides.forEach((slideEl, slideIndex) => { 5752 let slideProgress = slideEl.progress; 5753 if (swiper.params.slidesPerGroup > 1 && swiper.params.slidesPerView !== 'auto') { 5754 slideProgress += Math.ceil(slideIndex / 2) - progress * (snapGrid.length - 1); 5755 } 5756 slideProgress = Math.min(Math.max(slideProgress, -1), 1); 5757 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 => { 5758 setTransform(subEl, slideProgress); 5759 }); 5760 }); 5761 }; 5762 const setTransition = function (duration) { 5763 if (duration === void 0) { 5764 duration = swiper.params.speed; 5765 } 5766 const { 5767 el 5768 } = swiper; 5769 el.querySelectorAll('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').forEach(parallaxEl => { 5770 let parallaxDuration = parseInt(parallaxEl.getAttribute('data-swiper-parallax-duration'), 10) || duration; 5771 if (duration === 0) parallaxDuration = 0; 5772 parallaxEl.style.transitionDuration = `${parallaxDuration}ms`; 5773 }); 5774 }; 5775 on('beforeInit', () => { 5776 if (!swiper.params.parallax.enabled) return; 5777 swiper.params.watchSlidesProgress = true; 5778 swiper.originalParams.watchSlidesProgress = true; 5779 }); 5780 on('init', () => { 5781 if (!swiper.params.parallax.enabled) return; 5782 setTranslate(); 5783 }); 5784 on('setTranslate', () => { 5785 if (!swiper.params.parallax.enabled) return; 5786 setTranslate(); 5787 }); 5788 on('setTransition', (_swiper, duration) => { 5789 if (!swiper.params.parallax.enabled) return; 5790 setTransition(duration); 5791 }); 5792 } 5793 5794 function Zoom(_ref) { 5795 let { 5796 swiper, 5797 extendParams, 5798 on, 5799 emit 5800 } = _ref; 5801 const window = getWindow(); 5802 extendParams({ 5803 zoom: { 5804 enabled: false, 5805 maxRatio: 3, 5806 minRatio: 1, 5807 toggle: true, 5808 containerClass: 'swiper-zoom-container', 5809 zoomedSlideClass: 'swiper-slide-zoomed' 5810 } 5811 }); 5812 swiper.zoom = { 5813 enabled: false 5814 }; 5815 let currentScale = 1; 5816 let isScaling = false; 5817 let fakeGestureTouched; 5818 let fakeGestureMoved; 5819 const evCache = []; 5820 const gesture = { 5821 slideEl: undefined, 5822 slideWidth: undefined, 5823 slideHeight: undefined, 5824 imageEl: undefined, 5825 imageWrapEl: undefined, 5826 maxRatio: 3 5827 }; 5828 const image = { 5829 isTouched: undefined, 5830 isMoved: undefined, 5831 currentX: undefined, 5832 currentY: undefined, 5833 minX: undefined, 5834 minY: undefined, 5835 maxX: undefined, 5836 maxY: undefined, 5837 width: undefined, 5838 height: undefined, 5839 startX: undefined, 5840 startY: undefined, 5841 touchesStart: {}, 5842 touchesCurrent: {} 5843 }; 5844 const velocity = { 5845 x: undefined, 5846 y: undefined, 5847 prevPositionX: undefined, 5848 prevPositionY: undefined, 5849 prevTime: undefined 5850 }; 5851 let scale = 1; 5852 Object.defineProperty(swiper.zoom, 'scale', { 5853 get() { 5854 return scale; 5855 }, 5856 set(value) { 5857 if (scale !== value) { 5858 const imageEl = gesture.imageEl; 5859 const slideEl = gesture.slideEl; 5860 emit('zoomChange', value, imageEl, slideEl); 5861 } 5862 scale = value; 5863 } 5864 }); 5865 function getDistanceBetweenTouches() { 5866 if (evCache.length < 2) return 1; 5867 const x1 = evCache[0].pageX; 5868 const y1 = evCache[0].pageY; 5869 const x2 = evCache[1].pageX; 5870 const y2 = evCache[1].pageY; 5871 const distance = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2); 5872 return distance; 5873 } 5874 function getSlideSelector() { 5875 return swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`; 5876 } 5877 function eventWithinSlide(e) { 5878 const slideSelector = getSlideSelector(); 5879 if (e.target.matches(slideSelector)) return true; 5880 if (swiper.slides.filter(slideEl => slideEl.contains(e.target)).length > 0) return true; 5881 return false; 5882 } 5883 function eventWithinZoomContainer(e) { 5884 const selector = `.${swiper.params.zoom.containerClass}`; 5885 if (e.target.matches(selector)) return true; 5886 if ([...swiper.el.querySelectorAll(selector)].filter(containerEl => containerEl.contains(e.target)).length > 0) return true; 5887 return false; 5888 } 5889 5890 // Events 5891 function onGestureStart(e) { 5892 if (!eventWithinSlide(e)) return; 5893 const params = swiper.params.zoom; 5894 fakeGestureTouched = false; 5895 fakeGestureMoved = false; 5896 evCache.push(e); 5897 if (evCache.length < 2) { 5898 return; 5899 } 5900 fakeGestureTouched = true; 5901 gesture.scaleStart = getDistanceBetweenTouches(); 5902 if (!gesture.slideEl) { 5903 gesture.slideEl = e.target.closest(`.${swiper.params.slideClass}, swiper-slide`); 5904 if (!gesture.slideEl) gesture.slideEl = swiper.slides[swiper.activeIndex]; 5905 let imageEl = gesture.slideEl.querySelector(`.${params.containerClass}`); 5906 if (imageEl) { 5907 imageEl = imageEl.querySelectorAll('picture, img, svg, canvas, .swiper-zoom-target')[0]; 5908 } 5909 gesture.imageEl = imageEl; 5910 if (imageEl) { 5911 gesture.imageWrapEl = elementParents(gesture.imageEl, `.${params.containerClass}`)[0]; 5912 } else { 5913 gesture.imageWrapEl = undefined; 5914 } 5915 if (!gesture.imageWrapEl) { 5916 gesture.imageEl = undefined; 5917 return; 5918 } 5919 gesture.maxRatio = gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio; 5920 } 5921 if (gesture.imageEl) { 5922 gesture.imageEl.style.transitionDuration = '0ms'; 5923 } 5924 isScaling = true; 5925 } 5926 function onGestureChange(e) { 5927 if (!eventWithinSlide(e)) return; 5928 const params = swiper.params.zoom; 5929 const zoom = swiper.zoom; 5930 const pointerIndex = evCache.findIndex(cachedEv => cachedEv.pointerId === e.pointerId); 5931 if (pointerIndex >= 0) evCache[pointerIndex] = e; 5932 if (evCache.length < 2) { 5933 return; 5934 } 5935 fakeGestureMoved = true; 5936 gesture.scaleMove = getDistanceBetweenTouches(); 5937 if (!gesture.imageEl) { 5938 return; 5939 } 5940 zoom.scale = gesture.scaleMove / gesture.scaleStart * currentScale; 5941 if (zoom.scale > gesture.maxRatio) { 5942 zoom.scale = gesture.maxRatio - 1 + (zoom.scale - gesture.maxRatio + 1) ** 0.5; 5943 } 5944 if (zoom.scale < params.minRatio) { 5945 zoom.scale = params.minRatio + 1 - (params.minRatio - zoom.scale + 1) ** 0.5; 5946 } 5947 gesture.imageEl.style.transform = `translate3d(0,0,0) scale(${zoom.scale})`; 5948 } 5949 function onGestureEnd(e) { 5950 if (!eventWithinSlide(e)) return; 5951 const params = swiper.params.zoom; 5952 const zoom = swiper.zoom; 5953 const pointerIndex = evCache.findIndex(cachedEv => cachedEv.pointerId === e.pointerId); 5954 if (pointerIndex >= 0) evCache.splice(pointerIndex, 1); 5955 if (!fakeGestureTouched || !fakeGestureMoved) { 5956 return; 5957 } 5958 fakeGestureTouched = false; 5959 fakeGestureMoved = false; 5960 if (!gesture.imageE) return; 5961 zoom.scale = Math.max(Math.min(zoom.scale, gesture.maxRatio), params.minRatio); 5962 gesture.imageEl.style.transitionDuration = `${swiper.params.speed}ms`; 5963 gesture.imageEl.style.transform = `translate3d(0,0,0) scale(${zoom.scale})`; 5964 currentScale = zoom.scale; 5965 isScaling = false; 5966 if (zoom.scale === 1) gesture.slideEl = undefined; 5967 } 5968 function onTouchStart(e) { 5969 const device = swiper.device; 5970 if (!gesture.imageEl) return; 5971 if (image.isTouched) return; 5972 if (device.android && e.cancelable) e.preventDefault(); 5973 image.isTouched = true; 5974 image.touchesStart.x = e.pageX; 5975 image.touchesStart.y = e.pageY; 5976 } 5977 function onTouchMove(e) { 5978 if (!eventWithinSlide(e) || !eventWithinZoomContainer(e)) return; 5979 const zoom = swiper.zoom; 5980 if (!gesture.imageEl) return; 5981 swiper.allowClick = false;
vendor: 5,596 bytes, lines 5982-6084
5982 if (!image.isTouched || !gesture.slideEl) return; 5983 if (!image.isMoved) { 5984 image.width = gesture.imageEl.offsetWidth; 5985 image.height = gesture.imageEl.offsetHeight; 5986 image.startX = getTranslate(gesture.imageWrapEl, 'x') || 0; 5987 image.startY = getTranslate(gesture.imageWrapEl, 'y') || 0; 5988 gesture.slideWidth = gesture.slideEl.offsetWidth; 5989 gesture.slideHeight = gesture.slideEl.offsetHeight; 5990 gesture.imageWrapEl.style.transitionDuration = '0ms'; 5991 } 5992 // Define if we need image drag 5993 const scaledWidth = image.width * zoom.scale; 5994 const scaledHeight = image.height * zoom.scale; 5995 if (scaledWidth < gesture.slideWidth && scaledHeight < gesture.slideHeight) return; 5996 image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0); 5997 image.maxX = -image.minX; 5998 image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0); 5999 image.maxY = -image.minY; 6000 image.touchesCurrent.x = evCache.length > 0 ? evCache[0].pageX : e.pageX; 6001 image.touchesCurrent.y = evCache.length > 0 ? evCache[0].pageY : e.pageY; 6002 if (!image.isMoved && !isScaling) { 6003 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)) { 6004 image.isTouched = false; 6005 return; 6006 } 6007 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)) { 6008 image.isTouched = false; 6009 return; 6010 } 6011 } 6012 if (e.cancelable) { 6013 e.preventDefault(); 6014 } 6015 e.stopPropagation(); 6016 image.isMoved = true; 6017 image.currentX = image.touchesCurrent.x - image.touchesStart.x + image.startX; 6018 image.currentY = image.touchesCurrent.y - image.touchesStart.y + image.startY; 6019 if (image.currentX < image.minX) { 6020 image.currentX = image.minX + 1 - (image.minX - image.currentX + 1) ** 0.8; 6021 } 6022 if (image.currentX > image.maxX) { 6023 image.currentX = image.maxX - 1 + (image.currentX - image.maxX + 1) ** 0.8; 6024 } 6025 if (image.currentY < image.minY) { 6026 image.currentY = image.minY + 1 - (image.minY - image.currentY + 1) ** 0.8; 6027 } 6028 if (image.currentY > image.maxY) { 6029 image.currentY = image.maxY - 1 + (image.currentY - image.maxY + 1) ** 0.8; 6030 } 6031 6032 // Velocity 6033 if (!velocity.prevPositionX) velocity.prevPositionX = image.touchesCurrent.x; 6034 if (!velocity.prevPositionY) velocity.prevPositionY = image.touchesCurrent.y; 6035 if (!velocity.prevTime) velocity.prevTime = Date.now(); 6036 velocity.x = (image.touchesCurrent.x - velocity.prevPositionX) / (Date.now() - velocity.prevTime) / 2; 6037 velocity.y = (image.touchesCurrent.y - velocity.prevPositionY) / (Date.now() - velocity.prevTime) / 2; 6038 if (Math.abs(image.touchesCurrent.x - velocity.prevPositionX) < 2) velocity.x = 0; 6039 if (Math.abs(image.touchesCurrent.y - velocity.prevPositionY) < 2) velocity.y = 0; 6040 velocity.prevPositionX = image.touchesCurrent.x; 6041 velocity.prevPositionY = image.touchesCurrent.y; 6042 velocity.prevTime = Date.now(); 6043 gesture.imageWrapEl.style.transform = `translate3d(${image.currentX}px, ${image.currentY}px,0)`; 6044 } 6045 function onTouchEnd() { 6046 const zoom = swiper.zoom; 6047 if (!gesture.imageEl) return; 6048 if (!image.isTouched || !image.isMoved) { 6049 image.isTouched = false; 6050 image.isMoved = false; 6051 return; 6052 } 6053 image.isTouched = false; 6054 image.isMoved = false; 6055 let momentumDurationX = 300; 6056 let momentumDurationY = 300; 6057 const momentumDistanceX = velocity.x * momentumDurationX; 6058 const newPositionX = image.currentX + momentumDistanceX; 6059 const momentumDistanceY = velocity.y * momentumDurationY; 6060 const newPositionY = image.currentY + momentumDistanceY; 6061 6062 // Fix duration 6063 if (velocity.x !== 0) momentumDurationX = Math.abs((newPositionX - image.currentX) / velocity.x); 6064 if (velocity.y !== 0) momentumDurationY = Math.abs((newPositionY - image.currentY) / velocity.y); 6065 const momentumDuration = Math.max(momentumDurationX, momentumDurationY); 6066 image.currentX = newPositionX; 6067 image.currentY = newPositionY; 6068 6069 // Define if we need image drag 6070 const scaledWidth = image.width * zoom.scale; 6071 const scaledHeight = image.height * zoom.scale; 6072 image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0); 6073 image.maxX = -image.minX; 6074 image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0); 6075 image.maxY = -image.minY; 6076 image.currentX = Math.max(Math.min(image.currentX, image.maxX), image.minX); 6077 image.currentY = Math.max(Math.min(image.currentY, image.maxY), image.minY); 6078 gesture.imageWrapEl.style.transitionDuration = `${momentumDuration}ms`; 6079 gesture.imageWrapEl.style.transform = `translate3d(${image.currentX}px, ${image.currentY}px,0)`; 6080 } 6081 function onTransitionEnd() { 6082 const zoom = swiper.zoom; 6083 if (gesture.slideEl && swiper.previousIndex !== swiper.activeIndex) { 6084 if (gesture.imageEl) {
vendor: 33,304 bytes, lines 6085-7011
6085 gesture.imageEl.style.transform = 'translate3d(0,0,0) scale(1)'; 6086 } 6087 if (gesture.imageWrapEl) { 6088 gesture.imageWrapEl.style.transform = 'translate3d(0,0,0)'; 6089 } 6090 zoom.scale = 1; 6091 currentScale = 1; 6092 gesture.slideEl = undefined; 6093 gesture.imageEl = undefined; 6094 gesture.imageWrapEl = undefined; 6095 } 6096 } 6097 function zoomIn(e) { 6098 const zoom = swiper.zoom; 6099 const params = swiper.params.zoom; 6100 if (!gesture.slideEl) { 6101 if (e && e.target) { 6102 gesture.slideEl = e.target.closest(`.${swiper.params.slideClass}, swiper-slide`); 6103 } 6104 if (!gesture.slideEl) { 6105 if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) { 6106 gesture.slideEl = elementChildren(swiper.slidesEl, `.${swiper.params.slideActiveClass}`)[0]; 6107 } else { 6108 gesture.slideEl = swiper.slides[swiper.activeIndex]; 6109 } 6110 } 6111 let imageEl = gesture.slideEl.querySelector(`.${params.containerClass}`); 6112 if (imageEl) { 6113 imageEl = imageEl.querySelectorAll('picture, img, svg, canvas, .swiper-zoom-target')[0]; 6114 } 6115 gesture.imageEl = imageEl; 6116 if (imageEl) { 6117 gesture.imageWrapEl = elementParents(gesture.imageEl, `.${params.containerClass}`)[0]; 6118 } else { 6119 gesture.imageWrapEl = undefined; 6120 } 6121 } 6122 if (!gesture.imageEl || !gesture.imageWrapEl) return; 6123 if (swiper.params.cssMode) { 6124 swiper.wrapperEl.style.overflow = 'hidden'; 6125 swiper.wrapperEl.style.touchAction = 'none'; 6126 } 6127 gesture.slideEl.classList.add(`${params.zoomedSlideClass}`); 6128 let touchX; 6129 let touchY; 6130 let offsetX; 6131 let offsetY; 6132 let diffX; 6133 let diffY; 6134 let translateX; 6135 let translateY; 6136 let imageWidth; 6137 let imageHeight; 6138 let scaledWidth; 6139 let scaledHeight; 6140 let translateMinX; 6141 let translateMinY; 6142 let translateMaxX; 6143 let translateMaxY; 6144 let slideWidth; 6145 let slideHeight; 6146 if (typeof image.touchesStart.x === 'undefined' && e) { 6147 touchX = e.pageX; 6148 touchY = e.pageY; 6149 } else { 6150 touchX = image.touchesStart.x; 6151 touchY = image.touchesStart.y; 6152 } 6153 const forceZoomRatio = typeof e === 'number' ? e : null; 6154 if (currentScale === 1 && forceZoomRatio) { 6155 touchX = undefined; 6156 touchY = undefined; 6157 } 6158 zoom.scale = forceZoomRatio || gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio; 6159 currentScale = forceZoomRatio || gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio; 6160 if (e && !(currentScale === 1 && forceZoomRatio)) { 6161 slideWidth = gesture.slideEl.offsetWidth; 6162 slideHeight = gesture.slideEl.offsetHeight; 6163 offsetX = elementOffset(gesture.slideEl).left + window.scrollX; 6164 offsetY = elementOffset(gesture.slideEl).top + window.scrollY; 6165 diffX = offsetX + slideWidth / 2 - touchX; 6166 diffY = offsetY + slideHeight / 2 - touchY; 6167 imageWidth = gesture.imageEl.offsetWidth; 6168 imageHeight = gesture.imageEl.offsetHeight; 6169 scaledWidth = imageWidth * zoom.scale; 6170 scaledHeight = imageHeight * zoom.scale; 6171 translateMinX = Math.min(slideWidth / 2 - scaledWidth / 2, 0); 6172 translateMinY = Math.min(slideHeight / 2 - scaledHeight / 2, 0); 6173 translateMaxX = -translateMinX; 6174 translateMaxY = -translateMinY; 6175 translateX = diffX * zoom.scale; 6176 translateY = diffY * zoom.scale; 6177 if (translateX < translateMinX) { 6178 translateX = translateMinX; 6179 } 6180 if (translateX > translateMaxX) { 6181 translateX = translateMaxX; 6182 } 6183 if (translateY < translateMinY) { 6184 translateY = translateMinY; 6185 } 6186 if (translateY > translateMaxY) { 6187 translateY = translateMaxY; 6188 } 6189 } else { 6190 translateX = 0; 6191 translateY = 0; 6192 } 6193 gesture.imageWrapEl.style.transitionDuration = '300ms'; 6194 gesture.imageWrapEl.style.transform = `translate3d(${translateX}px, ${translateY}px,0)`; 6195 gesture.imageEl.style.transitionDuration = '300ms'; 6196 gesture.imageEl.style.transform = `translate3d(0,0,0) scale(${zoom.scale})`; 6197 } 6198 function zoomOut() { 6199 const zoom = swiper.zoom; 6200 const params = swiper.params.zoom; 6201 if (!gesture.slideEl) { 6202 if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) { 6203 gesture.slideEl = elementChildren(swiper.slidesEl, `.${swiper.params.slideActiveClass}`)[0]; 6204 } else { 6205 gesture.slideEl = swiper.slides[swiper.activeIndex]; 6206 } 6207 let imageEl = gesture.slideEl.querySelector(`.${params.containerClass}`); 6208 if (imageEl) { 6209 imageEl = imageEl.querySelectorAll('picture, img, svg, canvas, .swiper-zoom-target')[0]; 6210 } 6211 gesture.imageEl = imageEl; 6212 if (imageEl) { 6213 gesture.imageWrapEl = elementParents(gesture.imageEl, `.${params.containerClass}`)[0]; 6214 } else { 6215 gesture.imageWrapEl = undefined; 6216 } 6217 } 6218 if (!gesture.imageEl || !gesture.imageWrapEl) return; 6219 if (swiper.params.cssMode) { 6220 swiper.wrapperEl.style.overflow = ''; 6221 swiper.wrapperEl.style.touchAction = ''; 6222 } 6223 zoom.scale = 1; 6224 currentScale = 1; 6225 gesture.imageWrapEl.style.transitionDuration = '300ms'; 6226 gesture.imageWrapEl.style.transform = 'translate3d(0,0,0)'; 6227 gesture.imageEl.style.transitionDuration = '300ms'; 6228 gesture.imageEl.style.transform = 'translate3d(0,0,0) scale(1)'; 6229 gesture.slideEl.classList.remove(`${params.zoomedSlideClass}`); 6230 gesture.slideEl = undefined; 6231 } 6232 6233 // Toggle Zoom 6234 function zoomToggle(e) { 6235 const zoom = swiper.zoom; 6236 if (zoom.scale && zoom.scale !== 1) { 6237 // Zoom Out 6238 zoomOut(); 6239 } else { 6240 // Zoom In 6241 zoomIn(e); 6242 } 6243 } 6244 function getListeners() { 6245 const passiveListener = swiper.params.passiveListeners ? { 6246 passive: true, 6247 capture: false 6248 } : false; 6249 const activeListenerWithCapture = swiper.params.passiveListeners ? { 6250 passive: false, 6251 capture: true 6252 } : true; 6253 return { 6254 passiveListener, 6255 activeListenerWithCapture 6256 }; 6257 } 6258 6259 // Attach/Detach Events 6260 function enable() { 6261 const zoom = swiper.zoom; 6262 if (zoom.enabled) return; 6263 zoom.enabled = true; 6264 const { 6265 passiveListener, 6266 activeListenerWithCapture 6267 } = getListeners(); 6268 6269 // Scale image 6270 6271 swiper.wrapperEl.addEventListener('pointerdown', onGestureStart, passiveListener); 6272 swiper.wrapperEl.addEventListener('pointermove', onGestureChange, activeListenerWithCapture); 6273 ['pointerup', 'pointercancel'].forEach(eventName => { 6274 swiper.wrapperEl.addEventListener(eventName, onGestureEnd, passiveListener); 6275 }); 6276 6277 // Move image 6278 swiper.wrapperEl.addEventListener('pointermove', onTouchMove, activeListenerWithCapture); 6279 } 6280 function disable() { 6281 const zoom = swiper.zoom; 6282 if (!zoom.enabled) return; 6283 zoom.enabled = false; 6284 const { 6285 passiveListener, 6286 activeListenerWithCapture 6287 } = getListeners(); 6288 6289 // Scale image 6290 swiper.wrapperEl.removeEventListener('pointerdown', onGestureStart, passiveListener); 6291 swiper.wrapperEl.removeEventListener('pointermove', onGestureChange, activeListenerWithCapture); 6292 ['pointerup', 'pointercancel'].forEach(eventName => { 6293 swiper.wrapperEl.removeEventListener(eventName, onGestureEnd, passiveListener); 6294 }); 6295 6296 // Move image 6297 swiper.wrapperEl.removeEventListener('pointermove', onTouchMove, activeListenerWithCapture); 6298 } 6299 on('init', () => { 6300 if (swiper.params.zoom.enabled) { 6301 enable(); 6302 } 6303 }); 6304 on('destroy', () => { 6305 disable(); 6306 }); 6307 on('touchStart', (_s, e) => { 6308 if (!swiper.zoom.enabled) return; 6309 onTouchStart(e); 6310 }); 6311 on('touchEnd', (_s, e) => { 6312 if (!swiper.zoom.enabled) return; 6313 onTouchEnd(); 6314 }); 6315 on('doubleTap', (_s, e) => { 6316 if (!swiper.animating && swiper.params.zoom.enabled && swiper.zoom.enabled && swiper.params.zoom.toggle) { 6317 zoomToggle(e); 6318 } 6319 }); 6320 on('transitionEnd', () => { 6321 if (swiper.zoom.enabled && swiper.params.zoom.enabled) { 6322 onTransitionEnd(); 6323 } 6324 }); 6325 on('slideChange', () => { 6326 if (swiper.zoom.enabled && swiper.params.zoom.enabled && swiper.params.cssMode) { 6327 onTransitionEnd(); 6328 } 6329 }); 6330 Object.assign(swiper.zoom, { 6331 enable, 6332 disable, 6333 in: zoomIn, 6334 out: zoomOut, 6335 toggle: zoomToggle 6336 }); 6337 } 6338 6339 /* eslint no-bitwise: ["error", { "allow": [">>"] }] */ 6340 function Controller(_ref) { 6341 let { 6342 swiper, 6343 extendParams, 6344 on 6345 } = _ref; 6346 extendParams({ 6347 controller: { 6348 control: undefined, 6349 inverse: false, 6350 by: 'slide' // or 'container' 6351 } 6352 }); 6353 6354 swiper.controller = { 6355 control: undefined 6356 }; 6357 function LinearSpline(x, y) { 6358 const binarySearch = function search() { 6359 let maxIndex; 6360 let minIndex; 6361 let guess; 6362 return (array, val) => { 6363 minIndex = -1; 6364 maxIndex = array.length; 6365 while (maxIndex - minIndex > 1) { 6366 guess = maxIndex + minIndex >> 1; 6367 if (array[guess] <= val) { 6368 minIndex = guess; 6369 } else { 6370 maxIndex = guess; 6371 } 6372 } 6373 return maxIndex; 6374 }; 6375 }(); 6376 this.x = x; 6377 this.y = y; 6378 this.lastIndex = x.length - 1; 6379 // Given an x value (x2), return the expected y2 value: 6380 // (x1,y1) is the known point before given value, 6381 // (x3,y3) is the known point after given value. 6382 let i1; 6383 let i3; 6384 this.interpolate = function interpolate(x2) { 6385 if (!x2) return 0; 6386 6387 // Get the indexes of x1 and x3 (the array indexes before and after given x2): 6388 i3 = binarySearch(this.x, x2); 6389 i1 = i3 - 1; 6390 6391 // We have our indexes i1 & i3, so we can calculate already: 6392 // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1 6393 return (x2 - this.x[i1]) * (this.y[i3] - this.y[i1]) / (this.x[i3] - this.x[i1]) + this.y[i1]; 6394 }; 6395 return this; 6396 } 6397 // xxx: for now i will just save one spline function to to 6398 function getInterpolateFunction(c) { 6399 if (!swiper.controller.spline) { 6400 swiper.controller.spline = swiper.params.loop ? new LinearSpline(swiper.slidesGrid, c.slidesGrid) : new LinearSpline(swiper.snapGrid, c.snapGrid); 6401 } 6402 } 6403 function setTranslate(_t, byController) { 6404 const controlled = swiper.controller.control; 6405 let multiplier; 6406 let controlledTranslate; 6407 const Swiper = swiper.constructor; 6408 function setControlledTranslate(c) { 6409 // this will create an Interpolate function based on the snapGrids 6410 // x is the Grid of the scrolled scroller and y will be the controlled scroller 6411 // it makes sense to create this only once and recall it for the interpolation 6412 // the function does a lot of value caching for performance 6413 const translate = swiper.rtlTranslate ? -swiper.translate : swiper.translate; 6414 if (swiper.params.controller.by === 'slide') { 6415 getInterpolateFunction(c); 6416 // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid 6417 // but it did not work out 6418 controlledTranslate = -swiper.controller.spline.interpolate(-translate); 6419 } 6420 if (!controlledTranslate || swiper.params.controller.by === 'container') { 6421 multiplier = (c.maxTranslate() - c.minTranslate()) / (swiper.maxTranslate() - swiper.minTranslate()); 6422 controlledTranslate = (translate - swiper.minTranslate()) * multiplier + c.minTranslate(); 6423 } 6424 if (swiper.params.controller.inverse) { 6425 controlledTranslate = c.maxTranslate() - controlledTranslate; 6426 } 6427 c.updateProgress(controlledTranslate); 6428 c.setTranslate(controlledTranslate, swiper); 6429 c.updateActiveIndex(); 6430 c.updateSlidesClasses(); 6431 } 6432 if (Array.isArray(controlled)) { 6433 for (let i = 0; i < controlled.length; i += 1) { 6434 if (controlled[i] !== byController && controlled[i] instanceof Swiper) { 6435 setControlledTranslate(controlled[i]); 6436 } 6437 } 6438 } else if (controlled instanceof Swiper && byController !== controlled) { 6439 setControlledTranslate(controlled); 6440 } 6441 } 6442 function setTransition(duration, byController) { 6443 const Swiper = swiper.constructor; 6444 const controlled = swiper.controller.control; 6445 let i; 6446 function setControlledTransition(c) { 6447 c.setTransition(duration, swiper); 6448 if (duration !== 0) { 6449 c.transitionStart(); 6450 if (c.params.autoHeight) { 6451 nextTick(() => { 6452 c.updateAutoHeight(); 6453 }); 6454 } 6455 elementTransitionEnd(c.wrapperEl, () => { 6456 if (!controlled) return; 6457 c.transitionEnd(); 6458 }); 6459 } 6460 } 6461 if (Array.isArray(controlled)) { 6462 for (i = 0; i < controlled.length; i += 1) { 6463 if (controlled[i] !== byController && controlled[i] instanceof Swiper) { 6464 setControlledTransition(controlled[i]); 6465 } 6466 } 6467 } else if (controlled instanceof Swiper && byController !== controlled) { 6468 setControlledTransition(controlled); 6469 } 6470 } 6471 function removeSpline() { 6472 if (!swiper.controller.control) return; 6473 if (swiper.controller.spline) { 6474 swiper.controller.spline = undefined; 6475 delete swiper.controller.spline; 6476 } 6477 } 6478 on('beforeInit', () => { 6479 if (typeof window !== 'undefined' && ( 6480 // eslint-disable-line 6481 typeof swiper.params.controller.control === 'string' || swiper.params.controller.control instanceof HTMLElement)) { 6482 const controlElement = document.querySelector(swiper.params.controller.control); 6483 if (controlElement && controlElement.swiper) { 6484 swiper.controller.control = controlElement.swiper; 6485 } else if (controlElement) { 6486 const onControllerSwiper = e => { 6487 swiper.controller.control = e.detail[0]; 6488 swiper.update(); 6489 controlElement.removeEventListener('init', onControllerSwiper); 6490 }; 6491 controlElement.addEventListener('init', onControllerSwiper); 6492 } 6493 return; 6494 } 6495 swiper.controller.control = swiper.params.controller.control; 6496 }); 6497 on('update', () => { 6498 removeSpline(); 6499 }); 6500 on('resize', () => { 6501 removeSpline(); 6502 }); 6503 on('observerUpdate', () => { 6504 removeSpline(); 6505 }); 6506 on('setTranslate', (_s, translate, byController) => { 6507 if (!swiper.controller.control) return; 6508 swiper.controller.setTranslate(translate, byController); 6509 }); 6510 on('setTransition', (_s, duration, byController) => { 6511 if (!swiper.controller.control) return; 6512 swiper.controller.setTransition(duration, byController); 6513 }); 6514 Object.assign(swiper.controller, { 6515 setTranslate, 6516 setTransition 6517 }); 6518 } 6519 6520 function A11y(_ref) { 6521 let { 6522 swiper, 6523 extendParams, 6524 on 6525 } = _ref; 6526 extendParams({ 6527 a11y: { 6528 enabled: true, 6529 notificationClass: 'swiper-notification', 6530 prevSlideMessage: 'Previous slide', 6531 nextSlideMessage: 'Next slide', 6532 firstSlideMessage: 'This is the first slide', 6533 lastSlideMessage: 'This is the last slide', 6534 paginationBulletMessage: 'Go to slide {{index}}', 6535 slideLabelMessage: '{{index}} / {{slidesLength}}', 6536 containerMessage: null, 6537 containerRoleDescriptionMessage: null, 6538 itemRoleDescriptionMessage: null, 6539 slideRole: 'group', 6540 id: null 6541 } 6542 }); 6543 swiper.a11y = { 6544 clicked: false 6545 }; 6546 let liveRegion = null; 6547 function notify(message) { 6548 const notification = liveRegion; 6549 if (notification.length === 0) return; 6550 notification.innerHTML = ''; 6551 notification.innerHTML = message; 6552 } 6553 const makeElementsArray = el => { 6554 if (!Array.isArray(el)) el = [el].filter(e => !!e); 6555 return el; 6556 }; 6557 function getRandomNumber(size) { 6558 if (size === void 0) { 6559 size = 16; 6560 } 6561 const randomChar = () => Math.round(16 * Math.random()).toString(16); 6562 return 'x'.repeat(size).replace(/x/g, randomChar); 6563 } 6564 function makeElFocusable(el) { 6565 el = makeElementsArray(el); 6566 el.forEach(subEl => { 6567 subEl.setAttribute('tabIndex', '0'); 6568 }); 6569 } 6570 function makeElNotFocusable(el) { 6571 el = makeElementsArray(el); 6572 el.forEach(subEl => { 6573 subEl.setAttribute('tabIndex', '-1'); 6574 }); 6575 } 6576 function addElRole(el, role) { 6577 el = makeElementsArray(el); 6578 el.forEach(subEl => { 6579 subEl.setAttribute('role', role); 6580 }); 6581 } 6582 function addElRoleDescription(el, description) { 6583 el = makeElementsArray(el); 6584 el.forEach(subEl => { 6585 subEl.setAttribute('aria-roledescription', description); 6586 }); 6587 } 6588 function addElControls(el, controls) { 6589 el = makeElementsArray(el); 6590 el.forEach(subEl => { 6591 subEl.setAttribute('aria-controls', controls); 6592 }); 6593 } 6594 function addElLabel(el, label) { 6595 el = makeElementsArray(el); 6596 el.forEach(subEl => { 6597 subEl.setAttribute('aria-label', label); 6598 }); 6599 } 6600 function addElId(el, id) { 6601 el = makeElementsArray(el); 6602 el.forEach(subEl => { 6603 subEl.setAttribute('id', id); 6604 }); 6605 } 6606 function addElLive(el, live) { 6607 el = makeElementsArray(el); 6608 el.forEach(subEl => { 6609 subEl.setAttribute('aria-live', live); 6610 }); 6611 } 6612 function disableEl(el) { 6613 el = makeElementsArray(el); 6614 el.forEach(subEl => { 6615 subEl.setAttribute('aria-disabled', true); 6616 }); 6617 } 6618 function enableEl(el) { 6619 el = makeElementsArray(el); 6620 el.forEach(subEl => { 6621 subEl.setAttribute('aria-disabled', false); 6622 }); 6623 } 6624 function onEnterOrSpaceKey(e) { 6625 if (e.keyCode !== 13 && e.keyCode !== 32) return; 6626 const params = swiper.params.a11y; 6627 const targetEl = e.target; 6628 if (swiper.pagination && swiper.pagination.el && (targetEl === swiper.pagination.el || swiper.pagination.el.contains(e.target))) { 6629 if (!e.target.matches(classesToSelector(swiper.params.pagination.bulletClass))) return; 6630 } 6631 if (swiper.navigation && swiper.navigation.nextEl && targetEl === swiper.navigation.nextEl) { 6632 if (!(swiper.isEnd && !swiper.params.loop)) { 6633 swiper.slideNext(); 6634 } 6635 if (swiper.isEnd) { 6636 notify(params.lastSlideMessage); 6637 } else { 6638 notify(params.nextSlideMessage); 6639 } 6640 } 6641 if (swiper.navigation && swiper.navigation.prevEl && targetEl === swiper.navigation.prevEl) { 6642 if (!(swiper.isBeginning && !swiper.params.loop)) { 6643 swiper.slidePrev(); 6644 } 6645 if (swiper.isBeginning) { 6646 notify(params.firstSlideMessage); 6647 } else { 6648 notify(params.prevSlideMessage); 6649 } 6650 } 6651 if (swiper.pagination && targetEl.matches(classesToSelector(swiper.params.pagination.bulletClass))) { 6652 targetEl.click(); 6653 } 6654 } 6655 function updateNavigation() { 6656 if (swiper.params.loop || swiper.params.rewind || !swiper.navigation) return; 6657 const { 6658 nextEl, 6659 prevEl 6660 } = swiper.navigation; 6661 if (prevEl) { 6662 if (swiper.isBeginning) { 6663 disableEl(prevEl); 6664 makeElNotFocusable(prevEl); 6665 } else { 6666 enableEl(prevEl); 6667 makeElFocusable(prevEl); 6668 } 6669 } 6670 if (nextEl) { 6671 if (swiper.isEnd) { 6672 disableEl(nextEl); 6673 makeElNotFocusable(nextEl); 6674 } else { 6675 enableEl(nextEl); 6676 makeElFocusable(nextEl); 6677 } 6678 } 6679 } 6680 function hasPagination() { 6681 return swiper.pagination && swiper.pagination.bullets && swiper.pagination.bullets.length; 6682 } 6683 function hasClickablePagination() { 6684 return hasPagination() && swiper.params.pagination.clickable; 6685 } 6686 function updatePagination() { 6687 const params = swiper.params.a11y; 6688 if (!hasPagination()) return; 6689 swiper.pagination.bullets.forEach(bulletEl => { 6690 if (swiper.params.pagination.clickable) { 6691 makeElFocusable(bulletEl); 6692 if (!swiper.params.pagination.renderBullet) { 6693 addElRole(bulletEl, 'button'); 6694 addElLabel(bulletEl, params.paginationBulletMessage.replace(/\{\{index\}\}/, elementIndex(bulletEl) + 1)); 6695 } 6696 } 6697 if (bulletEl.matches(`.${swiper.params.pagination.bulletActiveClass}`)) { 6698 bulletEl.setAttribute('aria-current', 'true'); 6699 } else { 6700 bulletEl.removeAttribute('aria-current'); 6701 } 6702 }); 6703 } 6704 const initNavEl = (el, wrapperId, message) => { 6705 makeElFocusable(el); 6706 if (el.tagName !== 'BUTTON') { 6707 addElRole(el, 'button'); 6708 el.addEventListener('keydown', onEnterOrSpaceKey); 6709 } 6710 addElLabel(el, message); 6711 addElControls(el, wrapperId); 6712 }; 6713 const handlePointerDown = () => { 6714 swiper.a11y.clicked = true; 6715 }; 6716 const handlePointerUp = () => { 6717 requestAnimationFrame(() => { 6718 requestAnimationFrame(() => { 6719 if (!swiper.destroyed) { 6720 swiper.a11y.clicked = false; 6721 } 6722 }); 6723 }); 6724 }; 6725 const handleFocus = e => { 6726 if (swiper.a11y.clicked) return; 6727 const slideEl = e.target.closest(`.${swiper.params.slideClass}, swiper-slide`); 6728 if (!slideEl || !swiper.slides.includes(slideEl)) return; 6729 const isActive = swiper.slides.indexOf(slideEl) === swiper.activeIndex; 6730 const isVisible = swiper.params.watchSlidesProgress && swiper.visibleSlides && swiper.visibleSlides.includes(slideEl); 6731 if (isActive || isVisible) return; 6732 if (e.sourceCapabilities && e.sourceCapabilities.firesTouchEvents) return; 6733 if (swiper.isHorizontal()) { 6734 swiper.el.scrollLeft = 0; 6735 } else { 6736 swiper.el.scrollTop = 0; 6737 } 6738 swiper.slideTo(swiper.slides.indexOf(slideEl), 0); 6739 }; 6740 const initSlides = () => { 6741 const params = swiper.params.a11y; 6742 if (params.itemRoleDescriptionMessage) { 6743 addElRoleDescription(swiper.slides, params.itemRoleDescriptionMessage); 6744 } 6745 if (params.slideRole) { 6746 addElRole(swiper.slides, params.slideRole); 6747 } 6748 const slidesLength = swiper.slides.length; 6749 if (params.slideLabelMessage) { 6750 swiper.slides.forEach((slideEl, index) => { 6751 const slideIndex = swiper.params.loop ? parseInt(slideEl.getAttribute('data-swiper-slide-index'), 10) : index; 6752 const ariaLabelMessage = params.slideLabelMessage.replace(/\{\{index\}\}/, slideIndex + 1).replace(/\{\{slidesLength\}\}/, slidesLength); 6753 addElLabel(slideEl, ariaLabelMessage); 6754 }); 6755 } 6756 }; 6757 const init = () => { 6758 const params = swiper.params.a11y; 6759 swiper.el.append(liveRegion); 6760 6761 // Container 6762 const containerEl = swiper.el; 6763 if (params.containerRoleDescriptionMessage) { 6764 addElRoleDescription(containerEl, params.containerRoleDescriptionMessage); 6765 } 6766 if (params.containerMessage) { 6767 addElLabel(containerEl, params.containerMessage); 6768 } 6769 6770 // Wrapper 6771 const wrapperEl = swiper.wrapperEl; 6772 const wrapperId = params.id || wrapperEl.getAttribute('id') || `swiper-wrapper-${getRandomNumber(16)}`; 6773 const live = swiper.params.autoplay && swiper.params.autoplay.enabled ? 'off' : 'polite'; 6774 addElId(wrapperEl, wrapperId); 6775 addElLive(wrapperEl, live); 6776 6777 // Slide 6778 initSlides(); 6779 6780 // Navigation 6781 let { 6782 nextEl, 6783 prevEl 6784 } = swiper.navigation ? swiper.navigation : {}; 6785 nextEl = makeElementsArray(nextEl); 6786 prevEl = makeElementsArray(prevEl); 6787 if (nextEl) { 6788 nextEl.forEach(el => initNavEl(el, wrapperId, params.nextSlideMessage)); 6789 } 6790 if (prevEl) { 6791 prevEl.forEach(el => initNavEl(el, wrapperId, params.prevSlideMessage)); 6792 } 6793 6794 // Pagination 6795 if (hasClickablePagination()) { 6796 const paginationEl = Array.isArray(swiper.pagination.el) ? swiper.pagination.el : [swiper.pagination.el]; 6797 paginationEl.forEach(el => { 6798 el.addEventListener('keydown', onEnterOrSpaceKey); 6799 }); 6800 } 6801 6802 // Tab focus 6803 swiper.el.addEventListener('focus', handleFocus, true); 6804 swiper.el.addEventListener('pointerdown', handlePointerDown, true); 6805 swiper.el.addEventListener('pointerup', handlePointerUp, true); 6806 }; 6807 function destroy() { 6808 if (liveRegion && liveRegion.length > 0) liveRegion.remove(); 6809 let { 6810 nextEl, 6811 prevEl 6812 } = swiper.navigation ? swiper.navigation : {}; 6813 nextEl = makeElementsArray(nextEl); 6814 prevEl = makeElementsArray(prevEl); 6815 if (nextEl) { 6816 nextEl.forEach(el => el.removeEventListener('keydown', onEnterOrSpaceKey)); 6817 } 6818 if (prevEl) { 6819 prevEl.forEach(el => el.removeEventListener('keydown', onEnterOrSpaceKey)); 6820 } 6821 6822 // Pagination 6823 if (hasClickablePagination()) { 6824 const paginationEl = Array.isArray(swiper.pagination.el) ? swiper.pagination.el : [swiper.pagination.el]; 6825 paginationEl.forEach(el => { 6826 el.removeEventListener('keydown', onEnterOrSpaceKey); 6827 }); 6828 } 6829 6830 // Tab focus 6831 swiper.el.removeEventListener('focus', handleFocus, true); 6832 swiper.el.removeEventListener('pointerdown', handlePointerDown, true); 6833 swiper.el.removeEventListener('pointerup', handlePointerUp, true); 6834 } 6835 on('beforeInit', () => { 6836 liveRegion = createElement('span', swiper.params.a11y.notificationClass); 6837 liveRegion.setAttribute('aria-live', 'assertive'); 6838 liveRegion.setAttribute('aria-atomic', 'true'); 6839 if (swiper.isElement) { 6840 liveRegion.setAttribute('slot', 'container-end'); 6841 } 6842 }); 6843 on('afterInit', () => { 6844 if (!swiper.params.a11y.enabled) return; 6845 init(); 6846 }); 6847 on('slidesLengthChange snapGridLengthChange slidesGridLengthChange', () => { 6848 if (!swiper.params.a11y.enabled) return; 6849 initSlides(); 6850 }); 6851 on('fromEdge toEdge afterInit lock unlock', () => { 6852 if (!swiper.params.a11y.enabled) return; 6853 updateNavigation(); 6854 }); 6855 on('paginationUpdate', () => { 6856 if (!swiper.params.a11y.enabled) return; 6857 updatePagination(); 6858 }); 6859 on('destroy', () => { 6860 if (!swiper.params.a11y.enabled) return; 6861 destroy(); 6862 }); 6863 } 6864 6865 function History(_ref) { 6866 let { 6867 swiper, 6868 extendParams, 6869 on 6870 } = _ref; 6871 extendParams({ 6872 history: { 6873 enabled: false, 6874 root: '', 6875 replaceState: false, 6876 key: 'slides', 6877 keepQuery: false 6878 } 6879 }); 6880 let initialized = false; 6881 let paths = {}; 6882 const slugify = text => { 6883 return text.toString().replace(/\s+/g, '-').replace(/[^\w-]+/g, '').replace(/--+/g, '-').replace(/^-+/, '').replace(/-+$/, ''); 6884 }; 6885 const getPathValues = urlOverride => { 6886 const window = getWindow(); 6887 let location; 6888 if (urlOverride) { 6889 location = new URL(urlOverride); 6890 } else { 6891 location = window.location; 6892 } 6893 const pathArray = location.pathname.slice(1).split('/').filter(part => part !== ''); 6894 const total = pathArray.length; 6895 const key = pathArray[total - 2]; 6896 const value = pathArray[total - 1]; 6897 return { 6898 key, 6899 value 6900 }; 6901 }; 6902 const setHistory = (key, index) => { 6903 const window = getWindow(); 6904 if (!initialized || !swiper.params.history.enabled) return; 6905 let location; 6906 if (swiper.params.url) { 6907 location = new URL(swiper.params.url); 6908 } else { 6909 location = window.location; 6910 } 6911 const slide = swiper.slides[index]; 6912 let value = slugify(slide.getAttribute('data-history')); 6913 if (swiper.params.history.root.length > 0) { 6914 let root = swiper.params.history.root; 6915 if (root[root.length - 1] === '/') root = root.slice(0, root.length - 1); 6916 value = `${root}/${key}/${value}`; 6917 } else if (!location.pathname.includes(key)) { 6918 value = `${key}/${value}`; 6919 } 6920 if (swiper.params.history.keepQuery) { 6921 value += location.search; 6922 } 6923 const currentState = window.history.state; 6924 if (currentState && currentState.value === value) { 6925 return; 6926 } 6927 if (swiper.params.history.replaceState) { 6928 window.history.replaceState({ 6929 value 6930 }, null, value); 6931 } else { 6932 window.history.pushState({ 6933 value 6934 }, null, value); 6935 } 6936 }; 6937 const scrollToSlide = (speed, value, runCallbacks) => { 6938 if (value) { 6939 for (let i = 0, length = swiper.slides.length; i < length; i += 1) { 6940 const slide = swiper.slides[i]; 6941 const slideHistory = slugify(slide.getAttribute('data-history')); 6942 if (slideHistory === value) { 6943 const index = elementIndex(slide); 6944 swiper.slideTo(index, speed, runCallbacks); 6945 } 6946 } 6947 } else { 6948 swiper.slideTo(0, speed, runCallbacks); 6949 } 6950 }; 6951 const setHistoryPopState = () => { 6952 paths = getPathValues(swiper.params.url); 6953 scrollToSlide(swiper.params.speed, paths.value, false); 6954 }; 6955 const init = () => { 6956 const window = getWindow(); 6957 if (!swiper.params.history) return; 6958 if (!window.history || !window.history.pushState) { 6959 swiper.params.history.enabled = false; 6960 swiper.params.hashNavigation.enabled = true; 6961 return; 6962 } 6963 initialized = true; 6964 paths = getPathValues(swiper.params.url); 6965 if (!paths.key && !paths.value) { 6966 if (!swiper.params.history.replaceState) { 6967 window.addEventListener('popstate', setHistoryPopState); 6968 } 6969 return; 6970 } 6971 scrollToSlide(0, paths.value, swiper.params.runCallbacksOnInit); 6972 if (!swiper.params.history.replaceState) { 6973 window.addEventListener('popstate', setHistoryPopState); 6974 } 6975 }; 6976 const destroy = () => { 6977 const window = getWindow(); 6978 if (!swiper.params.history.replaceState) { 6979 window.removeEventListener('popstate', setHistoryPopState); 6980 } 6981 }; 6982 on('init', () => { 6983 if (swiper.params.history.enabled) { 6984 init(); 6985 } 6986 }); 6987 on('destroy', () => { 6988 if (swiper.params.history.enabled) { 6989 destroy(); 6990 } 6991 }); 6992 on('transitionEnd _freeModeNoMomentumRelease', () => { 6993 if (initialized) { 6994 setHistory(swiper.params.history.key, swiper.activeIndex); 6995 } 6996 }); 6997 on('slideChange', () => { 6998 if (initialized && swiper.params.cssMode) { 6999 setHistory(swiper.params.history.key, swiper.activeIndex); 7000 } 7001 }); 7002 } 7003 7004 function HashNavigation(_ref) { 7005 let { 7006 swiper, 7007 extendParams, 7008 emit, 7009 on 7010 } = _ref; 7011 let initialized = false;
7012 const document = getDocument(); 7013 const window = getWindow(); 7014 extendParams({ 7015 hashNavigation: { 7016 enabled: false, 7017 replaceState: false, 7018 watchState: false 7019 } 7020 }); 7021 const onHashChange = () => { 7022 emit('hashChange'); 7023 const newHash = document.location.hash.replace('#', ''); 7024 const activeSlideHash = swiper.slides[swiper.activeIndex].getAttribute('data-hash'); 7025 if (newHash !== activeSlideHash) { 7026 const newIndex = elementIndex(elementChildren(swiper.slidesEl, `.${swiper.params.slideClass}[data-hash="${newHash}"], swiper-slide[data-hash="${newHash}"]`)[0]); 7027 if (typeof newIndex === 'undefined') return; 7028 swiper.slideTo(newIndex); 7029 } 7030 }; 7031 const setHash = () => { 7032 if (!initialized || !swiper.params.hashNavigation.enabled) return; 7033 if (swiper.params.hashNavigation.replaceState && window.history && window.history.replaceState) { 7034 window.history.replaceState(null, null, `#${swiper.slides[swiper.activeIndex].getAttribute('data-hash')}` || ''); 7035 emit('hashSet'); 7036 } else { 7037 const slide = swiper.slides[swiper.activeIndex]; 7038 const hash = slide.getAttribute('data-hash') || slide.getAttribute('data-history'); 7039 document.location.hash = hash || ''; 7040 emit('hashSet'); 7041 } 7042 }; 7043 const init = () => { 7044 if (!swiper.params.hashNavigation.enabled || swiper.params.history && swiper.params.history.enabled) return; 7045 initialized = true; 7046 const hash = document.location.hash.replace('#', ''); 7047 if (hash) { 7048 const speed = 0; 7049 for (let i = 0, length = swiper.slides.length; i < length; i += 1) { 7050 const slide = swiper.slides[i]; 7051 const slideHash = slide.getAttribute('data-hash') || slide.getAttribute('data-history'); 7052 if (slideHash === hash) { 7053 const index = elementIndex(slide); 7054 swiper.slideTo(index, speed, swiper.params.runCallbacksOnInit, true); 7055 } 7056 } 7057 } 7058 if (swiper.params.hashNavigation.watchState) { 7059 window.addEventListener('hashchange', onHashChange); 7060 } 7061 }; 7062 const destroy = () => { 7063 if (swiper.params.hashNavigation.watchState) { 7064 window.removeEventListener('hashchange', onHashChange); 7065 } 7066 }; 7067 on('init', () => { 7068 if (swiper.params.hashNavigation.enabled) { 7069 init(); 7070 } 7071 }); 7072 on('destroy', () => { 7073 if (swiper.params.hashNavigation.enabled) { 7074 destroy(); 7075 } 7076 }); 7077 on('transitionEnd _freeModeNoMomentumRelease', () => { 7078 if (initialized) { 7079 setHash(); 7080 } 7081 }); 7082 on('slideChange', () => { 7083 if (initialized && swiper.params.cssMode) { 7084 setHash(); 7085 } 7086 }); 7087 } 7088 7089 /* eslint no-underscore-dangle: "off" */ 7090 function Autoplay(_ref) { 7091 let { 7092 swiper, 7093 extendParams, 7094 on, 7095 emit, 7096 params 7097 } = _ref; 7098 swiper.autoplay = { 7099 running: false, 7100 paused: false, 7101 timeLeft: 0 7102 }; 7103 extendParams({ 7104 autoplay: { 7105 enabled: false, 7106 delay: 3000, 7107 waitForTransition: true, 7108 disableOnInteraction: true, 7109 stopOnLastSlide: false, 7110 reverseDirection: false, 7111 pauseOnMouseEnter: false 7112 } 7113 }); 7114 let timeout; 7115 let raf; 7116 let autoplayDelayTotal = params && params.autoplay ? params.autoplay.delay : 3000; 7117 let autoplayDelayCurrent = params && params.autoplay ? params.autoplay.delay : 3000; 7118 let autoplayTimeLeft; 7119 let autoplayStartTime = new Date().getTime; 7120 let wasPaused; 7121 let isTouched; 7122 let pausedByTouch; 7123 let touchStartTimeout; 7124 let slideChanged; 7125 let pausedByInteraction; 7126 function onTransitionEnd(e) { 7127 if (!swiper || swiper.destroyed || !swiper.wrapperEl) return; 7128 if (e.target !== swiper.wrapperEl) return; 7129 swiper.wrapperEl.removeEventListener('transitionend', onTransitionEnd); 7130 resume(); 7131 } 7132 const calcTimeLeft = () => { 7133 if (swiper.destroyed || !swiper.autoplay.running) return; 7134 if (swiper.autoplay.paused) { 7135 wasPaused = true; 7136 } else if (wasPaused) { 7137 autoplayDelayCurrent = autoplayTimeLeft; 7138 wasPaused = false;
vendor: 4,564 bytes, lines 7139-7256
7139 } 7140 const timeLeft = swiper.autoplay.paused ? autoplayTimeLeft : autoplayStartTime + autoplayDelayCurrent - new Date().getTime(); 7141 swiper.autoplay.timeLeft = timeLeft; 7142 emit('autoplayTimeLeft', timeLeft, timeLeft / autoplayDelayTotal); 7143 raf = requestAnimationFrame(() => { 7144 calcTimeLeft(); 7145 }); 7146 }; 7147 const getSlideDelay = () => { 7148 let activeSlideEl; 7149 if (swiper.virtual && swiper.params.virtual.enabled) { 7150 activeSlideEl = swiper.slides.filter(slideEl => slideEl.classList.contains('swiper-slide-active'))[0]; 7151 } else { 7152 activeSlideEl = swiper.slides[swiper.activeIndex]; 7153 } 7154 if (!activeSlideEl) return undefined; 7155 const currentSlideDelay = parseInt(activeSlideEl.getAttribute('data-swiper-autoplay'), 10); 7156 return currentSlideDelay; 7157 }; 7158 const run = delayForce => { 7159 if (swiper.destroyed || !swiper.autoplay.running) return; 7160 cancelAnimationFrame(raf); 7161 calcTimeLeft(); 7162 let delay = typeof delayForce === 'undefined' ? swiper.params.autoplay.delay : delayForce; 7163 autoplayDelayTotal = swiper.params.autoplay.delay; 7164 autoplayDelayCurrent = swiper.params.autoplay.delay; 7165 const currentSlideDelay = getSlideDelay(); 7166 if (!Number.isNaN(currentSlideDelay) && currentSlideDelay > 0 && typeof delayForce === 'undefined') { 7167 delay = currentSlideDelay; 7168 autoplayDelayTotal = currentSlideDelay; 7169 autoplayDelayCurrent = currentSlideDelay; 7170 } 7171 autoplayTimeLeft = delay; 7172 const speed = swiper.params.speed; 7173 const proceed = () => { 7174 if (swiper.params.autoplay.reverseDirection) { 7175 if (!swiper.isBeginning || swiper.params.loop || swiper.params.rewind) { 7176 swiper.slidePrev(speed, true, true); 7177 emit('autoplay'); 7178 } else if (!swiper.params.autoplay.stopOnLastSlide) { 7179 swiper.slideTo(swiper.slides.length - 1, speed, true, true); 7180 emit('autoplay'); 7181 } 7182 } else { 7183 if (!swiper.isEnd || swiper.params.loop || swiper.params.rewind) { 7184 swiper.slideNext(speed, true, true); 7185 emit('autoplay'); 7186 } else if (!swiper.params.autoplay.stopOnLastSlide) { 7187 swiper.slideTo(0, speed, true, true); 7188 emit('autoplay'); 7189 } 7190 } 7191 if (swiper.params.cssMode) { 7192 autoplayStartTime = new Date().getTime(); 7193 requestAnimationFrame(() => { 7194 run(); 7195 }); 7196 } 7197 }; 7198 if (delay > 0) { 7199 clearTimeout(timeout); 7200 timeout = setTimeout(() => { 7201 proceed(); 7202 }, delay); 7203 } else { 7204 requestAnimationFrame(() => { 7205 proceed(); 7206 }); 7207 } 7208 7209 // eslint-disable-next-line 7210 return delay; 7211 }; 7212 const start = () => { 7213 swiper.autoplay.running = true; 7214 run(); 7215 emit('autoplayStart'); 7216 }; 7217 const stop = () => { 7218 swiper.autoplay.running = false; 7219 clearTimeout(timeout); 7220 cancelAnimationFrame(raf); 7221 emit('autoplayStop'); 7222 }; 7223 const pause = (internal, reset) => { 7224 if (swiper.destroyed || !swiper.autoplay.running) return; 7225 clearTimeout(timeout); 7226 if (!internal) { 7227 pausedByInteraction = true; 7228 } 7229 const proceed = () => { 7230 emit('autoplayPause'); 7231 if (swiper.params.autoplay.waitForTransition) { 7232 swiper.wrapperEl.addEventListener('transitionend', onTransitionEnd); 7233 } else { 7234 resume(); 7235 } 7236 }; 7237 swiper.autoplay.paused = true; 7238 if (reset) { 7239 if (slideChanged) { 7240 autoplayTimeLeft = swiper.params.autoplay.delay; 7241 } 7242 slideChanged = false; 7243 proceed(); 7244 return; 7245 } 7246 const delay = autoplayTimeLeft || swiper.params.autoplay.delay; 7247 autoplayTimeLeft = delay - (new Date().getTime() - autoplayStartTime); 7248 if (swiper.isEnd && autoplayTimeLeft < 0 && !swiper.params.loop) return; 7249 if (autoplayTimeLeft < 0) autoplayTimeLeft = 0; 7250 proceed(); 7251 }; 7252 const resume = () => { 7253 if (swiper.isEnd && autoplayTimeLeft < 0 && !swiper.params.loop || swiper.destroyed || !swiper.autoplay.running) return; 7254 autoplayStartTime = new Date().getTime(); 7255 if (pausedByInteraction) { 7256 pausedByInteraction = false;
vendor: 60,815 bytes, lines 7257-8881
7257 run(autoplayTimeLeft); 7258 } else { 7259 run(); 7260 } 7261 swiper.autoplay.paused = false; 7262 emit('autoplayResume'); 7263 }; 7264 const onVisibilityChange = () => { 7265 if (swiper.destroyed || !swiper.autoplay.running) return; 7266 const document = getDocument(); 7267 if (document.visibilityState === 'hidden') { 7268 pausedByInteraction = true; 7269 pause(true); 7270 } 7271 if (document.visibilityState === 'visible') { 7272 resume(); 7273 } 7274 }; 7275 const onPointerEnter = e => { 7276 if (e.pointerType !== 'mouse') return; 7277 pausedByInteraction = true; 7278 pause(true); 7279 }; 7280 const onPointerLeave = e => { 7281 if (e.pointerType !== 'mouse') return; 7282 if (swiper.autoplay.paused) { 7283 resume(); 7284 } 7285 }; 7286 const attachMouseEvents = () => { 7287 if (swiper.params.autoplay.pauseOnMouseEnter) { 7288 swiper.el.addEventListener('pointerenter', onPointerEnter); 7289 swiper.el.addEventListener('pointerleave', onPointerLeave); 7290 } 7291 }; 7292 const detachMouseEvents = () => { 7293 swiper.el.removeEventListener('pointerenter', onPointerEnter); 7294 swiper.el.removeEventListener('pointerleave', onPointerLeave); 7295 }; 7296 const attachDocumentEvents = () => { 7297 const document = getDocument(); 7298 document.addEventListener('visibilitychange', onVisibilityChange); 7299 }; 7300 const detachDocumentEvents = () => { 7301 const document = getDocument(); 7302 document.removeEventListener('visibilitychange', onVisibilityChange); 7303 }; 7304 on('init', () => { 7305 if (swiper.params.autoplay.enabled) { 7306 attachMouseEvents(); 7307 attachDocumentEvents(); 7308 autoplayStartTime = new Date().getTime(); 7309 start(); 7310 } 7311 }); 7312 on('destroy', () => { 7313 detachMouseEvents(); 7314 detachDocumentEvents(); 7315 if (swiper.autoplay.running) { 7316 stop(); 7317 } 7318 }); 7319 on('beforeTransitionStart', (_s, speed, internal) => { 7320 if (swiper.destroyed || !swiper.autoplay.running) return; 7321 if (internal || !swiper.params.autoplay.disableOnInteraction) { 7322 pause(true, true); 7323 } else { 7324 stop(); 7325 } 7326 }); 7327 on('sliderFirstMove', () => { 7328 if (swiper.destroyed || !swiper.autoplay.running) return; 7329 if (swiper.params.autoplay.disableOnInteraction) { 7330 stop(); 7331 return; 7332 } 7333 isTouched = true; 7334 pausedByTouch = false; 7335 pausedByInteraction = false; 7336 touchStartTimeout = setTimeout(() => { 7337 pausedByInteraction = true; 7338 pausedByTouch = true; 7339 pause(true); 7340 }, 200); 7341 }); 7342 on('touchEnd', () => { 7343 if (swiper.destroyed || !swiper.autoplay.running || !isTouched) return; 7344 clearTimeout(touchStartTimeout); 7345 clearTimeout(timeout); 7346 if (swiper.params.autoplay.disableOnInteraction) { 7347 pausedByTouch = false; 7348 isTouched = false; 7349 return; 7350 } 7351 if (pausedByTouch && swiper.params.cssMode) resume(); 7352 pausedByTouch = false; 7353 isTouched = false; 7354 }); 7355 on('slideChange', () => { 7356 if (swiper.destroyed || !swiper.autoplay.running) return; 7357 slideChanged = true; 7358 }); 7359 Object.assign(swiper.autoplay, { 7360 start, 7361 stop, 7362 pause, 7363 resume 7364 }); 7365 } 7366 7367 function Thumb(_ref) { 7368 let { 7369 swiper, 7370 extendParams, 7371 on 7372 } = _ref; 7373 extendParams({ 7374 thumbs: { 7375 swiper: null, 7376 multipleActiveThumbs: true, 7377 autoScrollOffset: 0, 7378 slideThumbActiveClass: 'swiper-slide-thumb-active', 7379 thumbsContainerClass: 'swiper-thumbs' 7380 } 7381 }); 7382 let initialized = false; 7383 let swiperCreated = false; 7384 swiper.thumbs = { 7385 swiper: null 7386 }; 7387 function onThumbClick() { 7388 const thumbsSwiper = swiper.thumbs.swiper; 7389 if (!thumbsSwiper || thumbsSwiper.destroyed) return; 7390 const clickedIndex = thumbsSwiper.clickedIndex; 7391 const clickedSlide = thumbsSwiper.clickedSlide; 7392 if (clickedSlide && clickedSlide.classList.contains(swiper.params.thumbs.slideThumbActiveClass)) return; 7393 if (typeof clickedIndex === 'undefined' || clickedIndex === null) return; 7394 let slideToIndex; 7395 if (thumbsSwiper.params.loop) { 7396 slideToIndex = parseInt(thumbsSwiper.clickedSlide.getAttribute('data-swiper-slide-index'), 10); 7397 } else { 7398 slideToIndex = clickedIndex; 7399 } 7400 if (swiper.params.loop) { 7401 swiper.slideToLoop(slideToIndex); 7402 } else { 7403 swiper.slideTo(slideToIndex); 7404 } 7405 } 7406 function init() { 7407 const { 7408 thumbs: thumbsParams 7409 } = swiper.params; 7410 if (initialized) return false; 7411 initialized = true; 7412 const SwiperClass = swiper.constructor; 7413 if (thumbsParams.swiper instanceof SwiperClass) { 7414 swiper.thumbs.swiper = thumbsParams.swiper; 7415 Object.assign(swiper.thumbs.swiper.originalParams, { 7416 watchSlidesProgress: true, 7417 slideToClickedSlide: false 7418 }); 7419 Object.assign(swiper.thumbs.swiper.params, { 7420 watchSlidesProgress: true, 7421 slideToClickedSlide: false 7422 }); 7423 swiper.thumbs.swiper.update(); 7424 } else if (isObject(thumbsParams.swiper)) { 7425 const thumbsSwiperParams = Object.assign({}, thumbsParams.swiper); 7426 Object.assign(thumbsSwiperParams, { 7427 watchSlidesProgress: true, 7428 slideToClickedSlide: false 7429 }); 7430 swiper.thumbs.swiper = new SwiperClass(thumbsSwiperParams); 7431 swiperCreated = true; 7432 } 7433 swiper.thumbs.swiper.el.classList.add(swiper.params.thumbs.thumbsContainerClass); 7434 swiper.thumbs.swiper.on('tap', onThumbClick); 7435 return true; 7436 } 7437 function update(initial) { 7438 const thumbsSwiper = swiper.thumbs.swiper; 7439 if (!thumbsSwiper || thumbsSwiper.destroyed) return; 7440 const slidesPerView = thumbsSwiper.params.slidesPerView === 'auto' ? thumbsSwiper.slidesPerViewDynamic() : thumbsSwiper.params.slidesPerView; 7441 7442 // Activate thumbs 7443 let thumbsToActivate = 1; 7444 const thumbActiveClass = swiper.params.thumbs.slideThumbActiveClass; 7445 if (swiper.params.slidesPerView > 1 && !swiper.params.centeredSlides) { 7446 thumbsToActivate = swiper.params.slidesPerView; 7447 } 7448 if (!swiper.params.thumbs.multipleActiveThumbs) { 7449 thumbsToActivate = 1; 7450 } 7451 thumbsToActivate = Math.floor(thumbsToActivate); 7452 thumbsSwiper.slides.forEach(slideEl => slideEl.classList.remove(thumbActiveClass)); 7453 if (thumbsSwiper.params.loop || thumbsSwiper.params.virtual && thumbsSwiper.params.virtual.enabled) { 7454 for (let i = 0; i < thumbsToActivate; i += 1) { 7455 elementChildren(thumbsSwiper.slidesEl, `[data-swiper-slide-index="${swiper.realIndex + i}"]`).forEach(slideEl => { 7456 slideEl.classList.add(thumbActiveClass); 7457 }); 7458 } 7459 } else { 7460 for (let i = 0; i < thumbsToActivate; i += 1) { 7461 thumbsSwiper.slides[swiper.realIndex + i].classList.add(thumbActiveClass); 7462 } 7463 } 7464 const autoScrollOffset = swiper.params.thumbs.autoScrollOffset; 7465 const useOffset = autoScrollOffset && !thumbsSwiper.params.loop; 7466 if (swiper.realIndex !== thumbsSwiper.realIndex || useOffset) { 7467 const currentThumbsIndex = thumbsSwiper.activeIndex; 7468 let newThumbsIndex; 7469 let direction; 7470 if (thumbsSwiper.params.loop) { 7471 const newThumbsSlide = thumbsSwiper.slides.filter(slideEl => slideEl.getAttribute('data-swiper-slide-index') === `${swiper.realIndex}`)[0]; 7472 newThumbsIndex = thumbsSwiper.slides.indexOf(newThumbsSlide); 7473 direction = swiper.activeIndex > swiper.previousIndex ? 'next' : 'prev'; 7474 } else { 7475 newThumbsIndex = swiper.realIndex; 7476 direction = newThumbsIndex > swiper.previousIndex ? 'next' : 'prev'; 7477 } 7478 if (useOffset) { 7479 newThumbsIndex += direction === 'next' ? autoScrollOffset : -1 * autoScrollOffset; 7480 } 7481 if (thumbsSwiper.visibleSlidesIndexes && thumbsSwiper.visibleSlidesIndexes.indexOf(newThumbsIndex) < 0) { 7482 if (thumbsSwiper.params.centeredSlides) { 7483 if (newThumbsIndex > currentThumbsIndex) { 7484 newThumbsIndex = newThumbsIndex - Math.floor(slidesPerView / 2) + 1; 7485 } else { 7486 newThumbsIndex = newThumbsIndex + Math.floor(slidesPerView / 2) - 1; 7487 } 7488 } else if (newThumbsIndex > currentThumbsIndex && thumbsSwiper.params.slidesPerGroup === 1) ; 7489 thumbsSwiper.slideTo(newThumbsIndex, initial ? 0 : undefined); 7490 } 7491 } 7492 } 7493 on('beforeInit', () => { 7494 const { 7495 thumbs 7496 } = swiper.params; 7497 if (!thumbs || !thumbs.swiper) return; 7498 if (typeof thumbs.swiper === 'string' || thumbs.swiper instanceof HTMLElement) { 7499 const document = getDocument(); 7500 const getThumbsElementAndInit = () => { 7501 const thumbsElement = typeof thumbs.swiper === 'string' ? document.querySelector(thumbs.swiper) : thumbs.swiper; 7502 if (thumbsElement && thumbsElement.swiper) { 7503 thumbs.swiper = thumbsElement.swiper; 7504 init(); 7505 update(true); 7506 } else if (thumbsElement) { 7507 const onThumbsSwiper = e => { 7508 thumbs.swiper = e.detail[0]; 7509 thumbsElement.removeEventListener('init', onThumbsSwiper); 7510 init(); 7511 update(true); 7512 thumbs.swiper.update(); 7513 swiper.update(); 7514 }; 7515 thumbsElement.addEventListener('init', onThumbsSwiper); 7516 } 7517 return thumbsElement; 7518 }; 7519 const watchForThumbsToAppear = () => { 7520 if (swiper.destroyed) return; 7521 const thumbsElement = getThumbsElementAndInit(); 7522 if (!thumbsElement) { 7523 requestAnimationFrame(watchForThumbsToAppear); 7524 } 7525 }; 7526 requestAnimationFrame(watchForThumbsToAppear); 7527 } else { 7528 init(); 7529 update(true); 7530 } 7531 }); 7532 on('slideChange update resize observerUpdate', () => { 7533 update(); 7534 }); 7535 on('setTransition', (_s, duration) => { 7536 const thumbsSwiper = swiper.thumbs.swiper; 7537 if (!thumbsSwiper || thumbsSwiper.destroyed) return; 7538 thumbsSwiper.setTransition(duration); 7539 }); 7540 on('beforeDestroy', () => { 7541 const thumbsSwiper = swiper.thumbs.swiper; 7542 if (!thumbsSwiper || thumbsSwiper.destroyed) return; 7543 if (swiperCreated) { 7544 thumbsSwiper.destroy(); 7545 } 7546 }); 7547 Object.assign(swiper.thumbs, { 7548 init, 7549 update 7550 }); 7551 } 7552 7553 function freeMode(_ref) { 7554 let { 7555 swiper, 7556 extendParams, 7557 emit, 7558 once 7559 } = _ref; 7560 extendParams({ 7561 freeMode: { 7562 enabled: false, 7563 momentum: true, 7564 momentumRatio: 1, 7565 momentumBounce: true, 7566 momentumBounceRatio: 1, 7567 momentumVelocityRatio: 1, 7568 sticky: false, 7569 minimumVelocity: 0.02 7570 } 7571 }); 7572 function onTouchStart() { 7573 const translate = swiper.getTranslate(); 7574 swiper.setTranslate(translate); 7575 swiper.setTransition(0); 7576 swiper.touchEventsData.velocities.length = 0; 7577 swiper.freeMode.onTouchEnd({ 7578 currentPos: swiper.rtl ? swiper.translate : -swiper.translate 7579 }); 7580 } 7581 function onTouchMove() { 7582 const { 7583 touchEventsData: data, 7584 touches 7585 } = swiper; 7586 // Velocity 7587 if (data.velocities.length === 0) { 7588 data.velocities.push({ 7589 position: touches[swiper.isHorizontal() ? 'startX' : 'startY'], 7590 time: data.touchStartTime 7591 }); 7592 } 7593 data.velocities.push({ 7594 position: touches[swiper.isHorizontal() ? 'currentX' : 'currentY'], 7595 time: now() 7596 }); 7597 } 7598 function onTouchEnd(_ref2) { 7599 let { 7600 currentPos 7601 } = _ref2; 7602 const { 7603 params, 7604 wrapperEl, 7605 rtlTranslate: rtl, 7606 snapGrid, 7607 touchEventsData: data 7608 } = swiper; 7609 // Time diff 7610 const touchEndTime = now(); 7611 const timeDiff = touchEndTime - data.touchStartTime; 7612 if (currentPos < -swiper.minTranslate()) { 7613 swiper.slideTo(swiper.activeIndex); 7614 return; 7615 } 7616 if (currentPos > -swiper.maxTranslate()) { 7617 if (swiper.slides.length < snapGrid.length) { 7618 swiper.slideTo(snapGrid.length - 1); 7619 } else { 7620 swiper.slideTo(swiper.slides.length - 1); 7621 } 7622 return; 7623 } 7624 if (params.freeMode.momentum) { 7625 if (data.velocities.length > 1) { 7626 const lastMoveEvent = data.velocities.pop(); 7627 const velocityEvent = data.velocities.pop(); 7628 const distance = lastMoveEvent.position - velocityEvent.position; 7629 const time = lastMoveEvent.time - velocityEvent.time; 7630 swiper.velocity = distance / time; 7631 swiper.velocity /= 2; 7632 if (Math.abs(swiper.velocity) < params.freeMode.minimumVelocity) { 7633 swiper.velocity = 0; 7634 } 7635 // this implies that the user stopped moving a finger then released. 7636 // There would be no events with distance zero, so the last event is stale. 7637 if (time > 150 || now() - lastMoveEvent.time > 300) { 7638 swiper.velocity = 0; 7639 } 7640 } else { 7641 swiper.velocity = 0; 7642 } 7643 swiper.velocity *= params.freeMode.momentumVelocityRatio; 7644 data.velocities.length = 0; 7645 let momentumDuration = 1000 * params.freeMode.momentumRatio; 7646 const momentumDistance = swiper.velocity * momentumDuration; 7647 let newPosition = swiper.translate + momentumDistance; 7648 if (rtl) newPosition = -newPosition; 7649 let doBounce = false; 7650 let afterBouncePosition; 7651 const bounceAmount = Math.abs(swiper.velocity) * 20 * params.freeMode.momentumBounceRatio; 7652 let needsLoopFix; 7653 if (newPosition < swiper.maxTranslate()) { 7654 if (params.freeMode.momentumBounce) { 7655 if (newPosition + swiper.maxTranslate() < -bounceAmount) { 7656 newPosition = swiper.maxTranslate() - bounceAmount; 7657 } 7658 afterBouncePosition = swiper.maxTranslate(); 7659 doBounce = true; 7660 data.allowMomentumBounce = true; 7661 } else { 7662 newPosition = swiper.maxTranslate(); 7663 } 7664 if (params.loop && params.centeredSlides) needsLoopFix = true; 7665 } else if (newPosition > swiper.minTranslate()) { 7666 if (params.freeMode.momentumBounce) { 7667 if (newPosition - swiper.minTranslate() > bounceAmount) { 7668 newPosition = swiper.minTranslate() + bounceAmount; 7669 } 7670 afterBouncePosition = swiper.minTranslate(); 7671 doBounce = true; 7672 data.allowMomentumBounce = true; 7673 } else { 7674 newPosition = swiper.minTranslate(); 7675 } 7676 if (params.loop && params.centeredSlides) needsLoopFix = true; 7677 } else if (params.freeMode.sticky) { 7678 let nextSlide; 7679 for (let j = 0; j < snapGrid.length; j += 1) { 7680 if (snapGrid[j] > -newPosition) { 7681 nextSlide = j; 7682 break; 7683 } 7684 } 7685 if (Math.abs(snapGrid[nextSlide] - newPosition) < Math.abs(snapGrid[nextSlide - 1] - newPosition) || swiper.swipeDirection === 'next') { 7686 newPosition = snapGrid[nextSlide]; 7687 } else { 7688 newPosition = snapGrid[nextSlide - 1]; 7689 } 7690 newPosition = -newPosition; 7691 } 7692 if (needsLoopFix) { 7693 once('transitionEnd', () => { 7694 swiper.loopFix(); 7695 }); 7696 } 7697 // Fix duration 7698 if (swiper.velocity !== 0) { 7699 if (rtl) { 7700 momentumDuration = Math.abs((-newPosition - swiper.translate) / swiper.velocity); 7701 } else { 7702 momentumDuration = Math.abs((newPosition - swiper.translate) / swiper.velocity); 7703 } 7704 if (params.freeMode.sticky) { 7705 // If freeMode.sticky is active and the user ends a swipe with a slow-velocity 7706 // event, then durations can be 20+ seconds to slide one (or zero!) slides. 7707 // It's easy to see this when simulating touch with mouse events. To fix this, 7708 // limit single-slide swipes to the default slide duration. This also has the 7709 // nice side effect of matching slide speed if the user stopped moving before 7710 // lifting finger or mouse vs. moving slowly before lifting the finger/mouse. 7711 // For faster swipes, also apply limits (albeit higher ones). 7712 const moveDistance = Math.abs((rtl ? -newPosition : newPosition) - swiper.translate); 7713 const currentSlideSize = swiper.slidesSizesGrid[swiper.activeIndex]; 7714 if (moveDistance < currentSlideSize) { 7715 momentumDuration = params.speed; 7716 } else if (moveDistance < 2 * currentSlideSize) { 7717 momentumDuration = params.speed * 1.5; 7718 } else { 7719 momentumDuration = params.speed * 2.5; 7720 } 7721 } 7722 } else if (params.freeMode.sticky) { 7723 swiper.slideToClosest(); 7724 return; 7725 } 7726 if (params.freeMode.momentumBounce && doBounce) { 7727 swiper.updateProgress(afterBouncePosition); 7728 swiper.setTransition(momentumDuration); 7729 swiper.setTranslate(newPosition); 7730 swiper.transitionStart(true, swiper.swipeDirection); 7731 swiper.animating = true; 7732 elementTransitionEnd(wrapperEl, () => { 7733 if (!swiper || swiper.destroyed || !data.allowMomentumBounce) return; 7734 emit('momentumBounce'); 7735 swiper.setTransition(params.speed); 7736 setTimeout(() => { 7737 swiper.setTranslate(afterBouncePosition); 7738 elementTransitionEnd(wrapperEl, () => { 7739 if (!swiper || swiper.destroyed) return; 7740 swiper.transitionEnd(); 7741 }); 7742 }, 0); 7743 }); 7744 } else if (swiper.velocity) { 7745 emit('_freeModeNoMomentumRelease'); 7746 swiper.updateProgress(newPosition); 7747 swiper.setTransition(momentumDuration); 7748 swiper.setTranslate(newPosition); 7749 swiper.transitionStart(true, swiper.swipeDirection); 7750 if (!swiper.animating) { 7751 swiper.animating = true; 7752 elementTransitionEnd(wrapperEl, () => { 7753 if (!swiper || swiper.destroyed) return; 7754 swiper.transitionEnd(); 7755 }); 7756 } 7757 } else { 7758 swiper.updateProgress(newPosition); 7759 } 7760 swiper.updateActiveIndex(); 7761 swiper.updateSlidesClasses(); 7762 } else if (params.freeMode.sticky) { 7763 swiper.slideToClosest(); 7764 return; 7765 } else if (params.freeMode) { 7766 emit('_freeModeNoMomentumRelease'); 7767 } 7768 if (!params.freeMode.momentum || timeDiff >= params.longSwipesMs) { 7769 swiper.updateProgress(); 7770 swiper.updateActiveIndex(); 7771 swiper.updateSlidesClasses(); 7772 } 7773 } 7774 Object.assign(swiper, { 7775 freeMode: { 7776 onTouchStart, 7777 onTouchMove, 7778 onTouchEnd 7779 } 7780 }); 7781 } 7782 7783 function Grid(_ref) { 7784 let { 7785 swiper, 7786 extendParams 7787 } = _ref; 7788 extendParams({ 7789 grid: { 7790 rows: 1, 7791 fill: 'column' 7792 } 7793 }); 7794 let slidesNumberEvenToRows; 7795 let slidesPerRow; 7796 let numFullColumns; 7797 const initSlides = slidesLength => { 7798 const { 7799 slidesPerView 7800 } = swiper.params; 7801 const { 7802 rows, 7803 fill 7804 } = swiper.params.grid; 7805 slidesPerRow = slidesNumberEvenToRows / rows; 7806 numFullColumns = Math.floor(slidesLength / rows); 7807 if (Math.floor(slidesLength / rows) === slidesLength / rows) { 7808 slidesNumberEvenToRows = slidesLength; 7809 } else { 7810 slidesNumberEvenToRows = Math.ceil(slidesLength / rows) * rows; 7811 } 7812 if (slidesPerView !== 'auto' && fill === 'row') { 7813 slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, slidesPerView * rows); 7814 } 7815 }; 7816 const updateSlide = (i, slide, slidesLength, getDirectionLabel) => { 7817 const { 7818 slidesPerGroup, 7819 spaceBetween 7820 } = swiper.params; 7821 const { 7822 rows, 7823 fill 7824 } = swiper.params.grid; 7825 // Set slides order 7826 let newSlideOrderIndex; 7827 let column; 7828 let row; 7829 if (fill === 'row' && slidesPerGroup > 1) { 7830 const groupIndex = Math.floor(i / (slidesPerGroup * rows)); 7831 const slideIndexInGroup = i - rows * slidesPerGroup * groupIndex; 7832 const columnsInGroup = groupIndex === 0 ? slidesPerGroup : Math.min(Math.ceil((slidesLength - groupIndex * rows * slidesPerGroup) / rows), slidesPerGroup); 7833 row = Math.floor(slideIndexInGroup / columnsInGroup); 7834 column = slideIndexInGroup - row * columnsInGroup + groupIndex * slidesPerGroup; 7835 newSlideOrderIndex = column + row * slidesNumberEvenToRows / rows; 7836 slide.style.order = newSlideOrderIndex; 7837 } else if (fill === 'column') { 7838 column = Math.floor(i / rows); 7839 row = i - column * rows; 7840 if (column > numFullColumns || column === numFullColumns && row === rows - 1) { 7841 row += 1; 7842 if (row >= rows) { 7843 row = 0; 7844 column += 1; 7845 } 7846 } 7847 } else { 7848 row = Math.floor(i / slidesPerRow); 7849 column = i - row * slidesPerRow; 7850 } 7851 slide.style[getDirectionLabel('margin-top')] = row !== 0 ? spaceBetween && `${spaceBetween}px` : ''; 7852 }; 7853 const updateWrapperSize = (slideSize, snapGrid, getDirectionLabel) => { 7854 const { 7855 spaceBetween, 7856 centeredSlides, 7857 roundLengths 7858 } = swiper.params; 7859 const { 7860 rows 7861 } = swiper.params.grid; 7862 swiper.virtualSize = (slideSize + spaceBetween) * slidesNumberEvenToRows; 7863 swiper.virtualSize = Math.ceil(swiper.virtualSize / rows) - spaceBetween; 7864 swiper.wrapperEl.style[getDirectionLabel('width')] = `${swiper.virtualSize + spaceBetween}px`; 7865 if (centeredSlides) { 7866 const newSlidesGrid = []; 7867 for (let i = 0; i < snapGrid.length; i += 1) { 7868 let slidesGridItem = snapGrid[i]; 7869 if (roundLengths) slidesGridItem = Math.floor(slidesGridItem); 7870 if (snapGrid[i] < swiper.virtualSize + snapGrid[0]) newSlidesGrid.push(slidesGridItem); 7871 } 7872 snapGrid.splice(0, snapGrid.length); 7873 snapGrid.push(...newSlidesGrid); 7874 } 7875 }; 7876 swiper.grid = { 7877 initSlides, 7878 updateSlide, 7879 updateWrapperSize 7880 }; 7881 } 7882 7883 function appendSlide(slides) { 7884 const swiper = this; 7885 const { 7886 params, 7887 slidesEl 7888 } = swiper; 7889 if (params.loop) { 7890 swiper.loopDestroy(); 7891 } 7892 const appendElement = slideEl => { 7893 if (typeof slideEl === 'string') { 7894 const tempDOM = document.createElement('div'); 7895 tempDOM.innerHTML = slideEl; 7896 slidesEl.append(tempDOM.children[0]); 7897 tempDOM.innerHTML = ''; 7898 } else { 7899 slidesEl.append(slideEl); 7900 } 7901 }; 7902 if (typeof slides === 'object' && 'length' in slides) { 7903 for (let i = 0; i < slides.length; i += 1) { 7904 if (slides[i]) appendElement(slides[i]); 7905 } 7906 } else { 7907 appendElement(slides); 7908 } 7909 swiper.recalcSlides(); 7910 if (params.loop) { 7911 swiper.loopCreate(); 7912 } 7913 if (!params.observer || swiper.isElement) { 7914 swiper.update(); 7915 } 7916 } 7917 7918 function prependSlide(slides) { 7919 const swiper = this; 7920 const { 7921 params, 7922 activeIndex, 7923 slidesEl 7924 } = swiper; 7925 if (params.loop) { 7926 swiper.loopDestroy(); 7927 } 7928 let newActiveIndex = activeIndex + 1; 7929 const prependElement = slideEl => { 7930 if (typeof slideEl === 'string') { 7931 const tempDOM = document.createElement('div'); 7932 tempDOM.innerHTML = slideEl; 7933 slidesEl.prepend(tempDOM.children[0]); 7934 tempDOM.innerHTML = ''; 7935 } else { 7936 slidesEl.prepend(slideEl); 7937 } 7938 }; 7939 if (typeof slides === 'object' && 'length' in slides) { 7940 for (let i = 0; i < slides.length; i += 1) { 7941 if (slides[i]) prependElement(slides[i]); 7942 } 7943 newActiveIndex = activeIndex + slides.length; 7944 } else { 7945 prependElement(slides); 7946 } 7947 swiper.recalcSlides(); 7948 if (params.loop) { 7949 swiper.loopCreate(); 7950 } 7951 if (!params.observer || swiper.isElement) { 7952 swiper.update(); 7953 } 7954 swiper.slideTo(newActiveIndex, 0, false); 7955 } 7956 7957 function addSlide(index, slides) { 7958 const swiper = this; 7959 const { 7960 params, 7961 activeIndex, 7962 slidesEl 7963 } = swiper; 7964 let activeIndexBuffer = activeIndex; 7965 if (params.loop) { 7966 activeIndexBuffer -= swiper.loopedSlides; 7967 swiper.loopDestroy(); 7968 swiper.recalcSlides(); 7969 } 7970 const baseLength = swiper.slides.length; 7971 if (index <= 0) { 7972 swiper.prependSlide(slides); 7973 return; 7974 } 7975 if (index >= baseLength) { 7976 swiper.appendSlide(slides); 7977 return; 7978 } 7979 let newActiveIndex = activeIndexBuffer > index ? activeIndexBuffer + 1 : activeIndexBuffer; 7980 const slidesBuffer = []; 7981 for (let i = baseLength - 1; i >= index; i -= 1) { 7982 const currentSlide = swiper.slides[i]; 7983 currentSlide.remove(); 7984 slidesBuffer.unshift(currentSlide); 7985 } 7986 if (typeof slides === 'object' && 'length' in slides) { 7987 for (let i = 0; i < slides.length; i += 1) { 7988 if (slides[i]) slidesEl.append(slides[i]); 7989 } 7990 newActiveIndex = activeIndexBuffer > index ? activeIndexBuffer + slides.length : activeIndexBuffer; 7991 } else { 7992 slidesEl.append(slides); 7993 } 7994 for (let i = 0; i < slidesBuffer.length; i += 1) { 7995 slidesEl.append(slidesBuffer[i]); 7996 } 7997 swiper.recalcSlides(); 7998 if (params.loop) { 7999 swiper.loopCreate(); 8000 } 8001 if (!params.observer || swiper.isElement) { 8002 swiper.update(); 8003 } 8004 if (params.loop) { 8005 swiper.slideTo(newActiveIndex + swiper.loopedSlides, 0, false); 8006 } else { 8007 swiper.slideTo(newActiveIndex, 0, false); 8008 } 8009 } 8010 8011 function removeSlide(slidesIndexes) { 8012 const swiper = this; 8013 const { 8014 params, 8015 activeIndex 8016 } = swiper; 8017 let activeIndexBuffer = activeIndex; 8018 if (params.loop) { 8019 activeIndexBuffer -= swiper.loopedSlides; 8020 swiper.loopDestroy(); 8021 } 8022 let newActiveIndex = activeIndexBuffer; 8023 let indexToRemove; 8024 if (typeof slidesIndexes === 'object' && 'length' in slidesIndexes) { 8025 for (let i = 0; i < slidesIndexes.length; i += 1) { 8026 indexToRemove = slidesIndexes[i]; 8027 if (swiper.slides[indexToRemove]) swiper.slides[indexToRemove].remove(); 8028 if (indexToRemove < newActiveIndex) newActiveIndex -= 1; 8029 } 8030 newActiveIndex = Math.max(newActiveIndex, 0); 8031 } else { 8032 indexToRemove = slidesIndexes; 8033 if (swiper.slides[indexToRemove]) swiper.slides[indexToRemove].remove(); 8034 if (indexToRemove < newActiveIndex) newActiveIndex -= 1; 8035 newActiveIndex = Math.max(newActiveIndex, 0); 8036 } 8037 swiper.recalcSlides(); 8038 if (params.loop) { 8039 swiper.loopCreate(); 8040 } 8041 if (!params.observer || swiper.isElement) { 8042 swiper.update(); 8043 } 8044 if (params.loop) { 8045 swiper.slideTo(newActiveIndex + swiper.loopedSlides, 0, false); 8046 } else { 8047 swiper.slideTo(newActiveIndex, 0, false); 8048 } 8049 } 8050 8051 function removeAllSlides() { 8052 const swiper = this; 8053 const slidesIndexes = []; 8054 for (let i = 0; i < swiper.slides.length; i += 1) { 8055 slidesIndexes.push(i); 8056 } 8057 swiper.removeSlide(slidesIndexes); 8058 } 8059 8060 function Manipulation(_ref) { 8061 let { 8062 swiper 8063 } = _ref; 8064 Object.assign(swiper, { 8065 appendSlide: appendSlide.bind(swiper), 8066 prependSlide: prependSlide.bind(swiper), 8067 addSlide: addSlide.bind(swiper), 8068 removeSlide: removeSlide.bind(swiper), 8069 removeAllSlides: removeAllSlides.bind(swiper) 8070 }); 8071 } 8072 8073 function effectInit(params) { 8074 const { 8075 effect, 8076 swiper, 8077 on, 8078 setTranslate, 8079 setTransition, 8080 overwriteParams, 8081 perspective, 8082 recreateShadows, 8083 getEffectParams 8084 } = params; 8085 on('beforeInit', () => { 8086 if (swiper.params.effect !== effect) return; 8087 swiper.classNames.push(`${swiper.params.containerModifierClass}${effect}`); 8088 if (perspective && perspective()) { 8089 swiper.classNames.push(`${swiper.params.containerModifierClass}3d`); 8090 } 8091 const overwriteParamsResult = overwriteParams ? overwriteParams() : {}; 8092 Object.assign(swiper.params, overwriteParamsResult); 8093 Object.assign(swiper.originalParams, overwriteParamsResult); 8094 }); 8095 on('setTranslate', () => { 8096 if (swiper.params.effect !== effect) return; 8097 setTranslate(); 8098 }); 8099 on('setTransition', (_s, duration) => { 8100 if (swiper.params.effect !== effect) return; 8101 setTransition(duration); 8102 }); 8103 on('transitionEnd', () => { 8104 if (swiper.params.effect !== effect) return; 8105 if (recreateShadows) { 8106 if (!getEffectParams || !getEffectParams().slideShadows) return; 8107 // remove shadows 8108 swiper.slides.forEach(slideEl => { 8109 slideEl.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(shadowEl => shadowEl.remove()); 8110 }); 8111 // create new one 8112 recreateShadows(); 8113 } 8114 }); 8115 let requireUpdateOnVirtual; 8116 on('virtualUpdate', () => { 8117 if (swiper.params.effect !== effect) return; 8118 if (!swiper.slides.length) { 8119 requireUpdateOnVirtual = true; 8120 } 8121 requestAnimationFrame(() => { 8122 if (requireUpdateOnVirtual && swiper.slides && swiper.slides.length) { 8123 setTranslate(); 8124 requireUpdateOnVirtual = false; 8125 } 8126 }); 8127 }); 8128 } 8129 8130 function effectTarget(effectParams, slideEl) { 8131 const transformEl = getSlideTransformEl(slideEl); 8132 if (transformEl !== slideEl) { 8133 transformEl.style.backfaceVisibility = 'hidden'; 8134 transformEl.style['-webkit-backface-visibility'] = 'hidden'; 8135 } 8136 return transformEl; 8137 } 8138 8139 function effectVirtualTransitionEnd(_ref) { 8140 let { 8141 swiper, 8142 duration, 8143 transformElements, 8144 allSlides 8145 } = _ref; 8146 const { 8147 activeIndex 8148 } = swiper; 8149 const getSlide = el => { 8150 if (!el.parentElement) { 8151 // assume shadow root 8152 const slide = swiper.slides.filter(slideEl => slideEl.shadowEl && slideEl.shadowEl === el.parentNode)[0]; 8153 return slide; 8154 } 8155 return el.parentElement; 8156 }; 8157 if (swiper.params.virtualTranslate && duration !== 0) { 8158 let eventTriggered = false; 8159 let transitionEndTarget; 8160 if (allSlides) { 8161 transitionEndTarget = transformElements; 8162 } else { 8163 transitionEndTarget = transformElements.filter(transformEl => { 8164 const el = transformEl.classList.contains('swiper-slide-transform') ? getSlide(transformEl) : transformEl; 8165 return elementIndex(el) === activeIndex; 8166 }); 8167 } 8168 transitionEndTarget.forEach(el => { 8169 elementTransitionEnd(el, () => { 8170 if (eventTriggered) return; 8171 if (!swiper || swiper.destroyed) return; 8172 eventTriggered = true; 8173 swiper.animating = false; 8174 const evt = new window.CustomEvent('transitionend', { 8175 bubbles: true, 8176 cancelable: true 8177 }); 8178 swiper.wrapperEl.dispatchEvent(evt); 8179 }); 8180 }); 8181 } 8182 } 8183 8184 function EffectFade(_ref) { 8185 let { 8186 swiper, 8187 extendParams, 8188 on 8189 } = _ref; 8190 extendParams({ 8191 fadeEffect: { 8192 crossFade: false 8193 } 8194 }); 8195 const setTranslate = () => { 8196 const { 8197 slides 8198 } = swiper; 8199 const params = swiper.params.fadeEffect; 8200 for (let i = 0; i < slides.length; i += 1) { 8201 const slideEl = swiper.slides[i]; 8202 const offset = slideEl.swiperSlideOffset; 8203 let tx = -offset; 8204 if (!swiper.params.virtualTranslate) tx -= swiper.translate; 8205 let ty = 0; 8206 if (!swiper.isHorizontal()) { 8207 ty = tx; 8208 tx = 0; 8209 } 8210 const slideOpacity = swiper.params.fadeEffect.crossFade ? Math.max(1 - Math.abs(slideEl.progress), 0) : 1 + Math.min(Math.max(slideEl.progress, -1), 0); 8211 const targetEl = effectTarget(params, slideEl); 8212 targetEl.style.opacity = slideOpacity; 8213 targetEl.style.transform = `translate3d(${tx}px, ${ty}px, 0px)`; 8214 } 8215 }; 8216 const setTransition = duration => { 8217 const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl)); 8218 transformElements.forEach(el => { 8219 el.style.transitionDuration = `${duration}ms`; 8220 }); 8221 effectVirtualTransitionEnd({ 8222 swiper, 8223 duration, 8224 transformElements, 8225 allSlides: true 8226 }); 8227 }; 8228 effectInit({ 8229 effect: 'fade', 8230 swiper, 8231 on, 8232 setTranslate, 8233 setTransition, 8234 overwriteParams: () => ({ 8235 slidesPerView: 1, 8236 slidesPerGroup: 1, 8237 watchSlidesProgress: true, 8238 spaceBetween: 0, 8239 virtualTranslate: !swiper.params.cssMode 8240 }) 8241 }); 8242 } 8243 8244 function EffectCube(_ref) { 8245 let { 8246 swiper, 8247 extendParams, 8248 on 8249 } = _ref; 8250 extendParams({ 8251 cubeEffect: { 8252 slideShadows: true, 8253 shadow: true, 8254 shadowOffset: 20, 8255 shadowScale: 0.94 8256 } 8257 }); 8258 const createSlideShadows = (slideEl, progress, isHorizontal) => { 8259 let shadowBefore = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-left') : slideEl.querySelector('.swiper-slide-shadow-top'); 8260 let shadowAfter = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-right') : slideEl.querySelector('.swiper-slide-shadow-bottom'); 8261 if (!shadowBefore) { 8262 shadowBefore = createElement('div', `swiper-slide-shadow-${isHorizontal ? 'left' : 'top'}`); 8263 slideEl.append(shadowBefore); 8264 } 8265 if (!shadowAfter) { 8266 shadowAfter = createElement('div', `swiper-slide-shadow-${isHorizontal ? 'right' : 'bottom'}`); 8267 slideEl.append(shadowAfter); 8268 } 8269 if (shadowBefore) shadowBefore.style.opacity = Math.max(-progress, 0); 8270 if (shadowAfter) shadowAfter.style.opacity = Math.max(progress, 0); 8271 }; 8272 const recreateShadows = () => { 8273 // create new ones 8274 const isHorizontal = swiper.isHorizontal(); 8275 swiper.slides.forEach(slideEl => { 8276 const progress = Math.max(Math.min(slideEl.progress, 1), -1); 8277 createSlideShadows(slideEl, progress, isHorizontal); 8278 }); 8279 }; 8280 const setTranslate = () => { 8281 const { 8282 el, 8283 wrapperEl, 8284 slides, 8285 width: swiperWidth, 8286 height: swiperHeight, 8287 rtlTranslate: rtl, 8288 size: swiperSize, 8289 browser 8290 } = swiper; 8291 const params = swiper.params.cubeEffect; 8292 const isHorizontal = swiper.isHorizontal(); 8293 const isVirtual = swiper.virtual && swiper.params.virtual.enabled; 8294 let wrapperRotate = 0; 8295 let cubeShadowEl; 8296 if (params.shadow) { 8297 if (isHorizontal) { 8298 cubeShadowEl = swiper.slidesEl.querySelector('.swiper-cube-shadow'); 8299 if (!cubeShadowEl) { 8300 cubeShadowEl = createElement('div', 'swiper-cube-shadow'); 8301 swiper.slidesEl.append(cubeShadowEl); 8302 } 8303 cubeShadowEl.style.height = `${swiperWidth}px`; 8304 } else { 8305 cubeShadowEl = el.querySelector('.swiper-cube-shadow'); 8306 if (!cubeShadowEl) { 8307 cubeShadowEl = createElement('div', 'swiper-cube-shadow'); 8308 el.append(cubeShadowEl); 8309 } 8310 } 8311 } 8312 for (let i = 0; i < slides.length; i += 1) { 8313 const slideEl = slides[i]; 8314 let slideIndex = i; 8315 if (isVirtual) { 8316 slideIndex = parseInt(slideEl.getAttribute('data-swiper-slide-index'), 10); 8317 } 8318 let slideAngle = slideIndex * 90; 8319 let round = Math.floor(slideAngle / 360); 8320 if (rtl) { 8321 slideAngle = -slideAngle; 8322 round = Math.floor(-slideAngle / 360); 8323 } 8324 const progress = Math.max(Math.min(slideEl.progress, 1), -1); 8325 let tx = 0; 8326 let ty = 0; 8327 let tz = 0; 8328 if (slideIndex % 4 === 0) { 8329 tx = -round * 4 * swiperSize; 8330 tz = 0; 8331 } else if ((slideIndex - 1) % 4 === 0) { 8332 tx = 0; 8333 tz = -round * 4 * swiperSize; 8334 } else if ((slideIndex - 2) % 4 === 0) { 8335 tx = swiperSize + round * 4 * swiperSize; 8336 tz = swiperSize; 8337 } else if ((slideIndex - 3) % 4 === 0) { 8338 tx = -swiperSize; 8339 tz = 3 * swiperSize + swiperSize * 4 * round; 8340 } 8341 if (rtl) { 8342 tx = -tx; 8343 } 8344 if (!isHorizontal) { 8345 ty = tx; 8346 tx = 0; 8347 } 8348 const transform = `rotateX(${isHorizontal ? 0 : -slideAngle}deg) rotateY(${isHorizontal ? slideAngle : 0}deg) translate3d(${tx}px, ${ty}px, ${tz}px)`; 8349 if (progress <= 1 && progress > -1) { 8350 wrapperRotate = slideIndex * 90 + progress * 90; 8351 if (rtl) wrapperRotate = -slideIndex * 90 - progress * 90; 8352 } 8353 slideEl.style.transform = transform; 8354 if (params.slideShadows) { 8355 createSlideShadows(slideEl, progress, isHorizontal); 8356 } 8357 } 8358 wrapperEl.style.transformOrigin = `50% 50% -${swiperSize / 2}px`; 8359 wrapperEl.style['-webkit-transform-origin'] = `50% 50% -${swiperSize / 2}px`; 8360 if (params.shadow) { 8361 if (isHorizontal) { 8362 cubeShadowEl.style.transform = `translate3d(0px, ${swiperWidth / 2 + params.shadowOffset}px, ${-swiperWidth / 2}px) rotateX(90deg) rotateZ(0deg) scale(${params.shadowScale})`; 8363 } else { 8364 const shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90; 8365 const multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2); 8366 const scale1 = params.shadowScale; 8367 const scale2 = params.shadowScale / multiplier; 8368 const offset = params.shadowOffset; 8369 cubeShadowEl.style.transform = `scale3d(${scale1}, 1, ${scale2}) translate3d(0px, ${swiperHeight / 2 + offset}px, ${-swiperHeight / 2 / scale2}px) rotateX(-90deg)`; 8370 } 8371 } 8372 const zFactor = (browser.isSafari || browser.isWebView) && browser.needPerspectiveFix ? -swiperSize / 2 : 0; 8373 wrapperEl.style.transform = `translate3d(0px,0,${zFactor}px) rotateX(${swiper.isHorizontal() ? 0 : wrapperRotate}deg) rotateY(${swiper.isHorizontal() ? -wrapperRotate : 0}deg)`; 8374 wrapperEl.style.setProperty('--swiper-cube-translate-z', `${zFactor}px`); 8375 }; 8376 const setTransition = duration => { 8377 const { 8378 el, 8379 slides 8380 } = swiper; 8381 slides.forEach(slideEl => { 8382 slideEl.style.transitionDuration = `${duration}ms`; 8383 slideEl.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(subEl => { 8384 subEl.style.transitionDuration = `${duration}ms`; 8385 }); 8386 }); 8387 if (swiper.params.cubeEffect.shadow && !swiper.isHorizontal()) { 8388 const shadowEl = el.querySelector('.swiper-cube-shadow'); 8389 if (shadowEl) shadowEl.style.transitionDuration = `${duration}ms`; 8390 } 8391 }; 8392 effectInit({ 8393 effect: 'cube', 8394 swiper, 8395 on, 8396 setTranslate, 8397 setTransition, 8398 recreateShadows, 8399 getEffectParams: () => swiper.params.cubeEffect, 8400 perspective: () => true, 8401 overwriteParams: () => ({ 8402 slidesPerView: 1, 8403 slidesPerGroup: 1, 8404 watchSlidesProgress: true, 8405 resistanceRatio: 0, 8406 spaceBetween: 0, 8407 centeredSlides: false, 8408 virtualTranslate: true 8409 }) 8410 }); 8411 } 8412 8413 function createShadow(params, slideEl, side) { 8414 const shadowClass = `swiper-slide-shadow${side ? `-${side}` : ''}`; 8415 const shadowContainer = getSlideTransformEl(slideEl); 8416 let shadowEl = shadowContainer.querySelector(`.${shadowClass}`); 8417 if (!shadowEl) { 8418 shadowEl = createElement('div', `swiper-slide-shadow${side ? `-${side}` : ''}`); 8419 shadowContainer.append(shadowEl); 8420 } 8421 return shadowEl; 8422 } 8423 8424 function EffectFlip(_ref) { 8425 let { 8426 swiper, 8427 extendParams, 8428 on 8429 } = _ref; 8430 extendParams({ 8431 flipEffect: { 8432 slideShadows: true, 8433 limitRotation: true 8434 } 8435 }); 8436 const createSlideShadows = (slideEl, progress, params) => { 8437 let shadowBefore = swiper.isHorizontal() ? slideEl.querySelector('.swiper-slide-shadow-left') : slideEl.querySelector('.swiper-slide-shadow-top'); 8438 let shadowAfter = swiper.isHorizontal() ? slideEl.querySelector('.swiper-slide-shadow-right') : slideEl.querySelector('.swiper-slide-shadow-bottom'); 8439 if (!shadowBefore) { 8440 shadowBefore = createShadow(params, slideEl, swiper.isHorizontal() ? 'left' : 'top'); 8441 } 8442 if (!shadowAfter) { 8443 shadowAfter = createShadow(params, slideEl, swiper.isHorizontal() ? 'right' : 'bottom'); 8444 } 8445 if (shadowBefore) shadowBefore.style.opacity = Math.max(-progress, 0); 8446 if (shadowAfter) shadowAfter.style.opacity = Math.max(progress, 0); 8447 }; 8448 const recreateShadows = () => { 8449 // Set shadows 8450 const params = swiper.params.flipEffect; 8451 swiper.slides.forEach(slideEl => { 8452 let progress = slideEl.progress; 8453 if (swiper.params.flipEffect.limitRotation) { 8454 progress = Math.max(Math.min(slideEl.progress, 1), -1); 8455 } 8456 createSlideShadows(slideEl, progress, params); 8457 }); 8458 }; 8459 const setTranslate = () => { 8460 const { 8461 slides, 8462 rtlTranslate: rtl 8463 } = swiper; 8464 const params = swiper.params.flipEffect; 8465 for (let i = 0; i < slides.length; i += 1) { 8466 const slideEl = slides[i]; 8467 let progress = slideEl.progress; 8468 if (swiper.params.flipEffect.limitRotation) { 8469 progress = Math.max(Math.min(slideEl.progress, 1), -1); 8470 } 8471 const offset = slideEl.swiperSlideOffset; 8472 const rotate = -180 * progress; 8473 let rotateY = rotate; 8474 let rotateX = 0; 8475 let tx = swiper.params.cssMode ? -offset - swiper.translate : -offset; 8476 let ty = 0; 8477 if (!swiper.isHorizontal()) { 8478 ty = tx; 8479 tx = 0; 8480 rotateX = -rotateY; 8481 rotateY = 0; 8482 } else if (rtl) { 8483 rotateY = -rotateY; 8484 } 8485 slideEl.style.zIndex = -Math.abs(Math.round(progress)) + slides.length; 8486 if (params.slideShadows) { 8487 createSlideShadows(slideEl, progress, params); 8488 } 8489 const transform = `translate3d(${tx}px, ${ty}px, 0px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`; 8490 const targetEl = effectTarget(params, slideEl); 8491 targetEl.style.transform = transform; 8492 } 8493 }; 8494 const setTransition = duration => { 8495 const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl)); 8496 transformElements.forEach(el => { 8497 el.style.transitionDuration = `${duration}ms`; 8498 el.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(shadowEl => { 8499 shadowEl.style.transitionDuration = `${duration}ms`; 8500 }); 8501 }); 8502 effectVirtualTransitionEnd({ 8503 swiper, 8504 duration, 8505 transformElements 8506 }); 8507 }; 8508 effectInit({ 8509 effect: 'flip', 8510 swiper, 8511 on, 8512 setTranslate, 8513 setTransition, 8514 recreateShadows, 8515 getEffectParams: () => swiper.params.flipEffect, 8516 perspective: () => true, 8517 overwriteParams: () => ({ 8518 slidesPerView: 1, 8519 slidesPerGroup: 1, 8520 watchSlidesProgress: true, 8521 spaceBetween: 0, 8522 virtualTranslate: !swiper.params.cssMode 8523 }) 8524 }); 8525 } 8526 8527 function EffectCoverflow(_ref) { 8528 let { 8529 swiper, 8530 extendParams, 8531 on 8532 } = _ref; 8533 extendParams({ 8534 coverflowEffect: { 8535 rotate: 50, 8536 stretch: 0, 8537 depth: 100, 8538 scale: 1, 8539 modifier: 1, 8540 slideShadows: true 8541 } 8542 }); 8543 const setTranslate = () => { 8544 const { 8545 width: swiperWidth, 8546 height: swiperHeight, 8547 slides, 8548 slidesSizesGrid 8549 } = swiper; 8550 const params = swiper.params.coverflowEffect; 8551 const isHorizontal = swiper.isHorizontal(); 8552 const transform = swiper.translate; 8553 const center = isHorizontal ? -transform + swiperWidth / 2 : -transform + swiperHeight / 2; 8554 const rotate = isHorizontal ? params.rotate : -params.rotate; 8555 const translate = params.depth; 8556 // Each slide offset from center 8557 for (let i = 0, length = slides.length; i < length; i += 1) { 8558 const slideEl = slides[i]; 8559 const slideSize = slidesSizesGrid[i]; 8560 const slideOffset = slideEl.swiperSlideOffset; 8561 const centerOffset = (center - slideOffset - slideSize / 2) / slideSize; 8562 const offsetMultiplier = typeof params.modifier === 'function' ? params.modifier(centerOffset) : centerOffset * params.modifier; 8563 let rotateY = isHorizontal ? rotate * offsetMultiplier : 0; 8564 let rotateX = isHorizontal ? 0 : rotate * offsetMultiplier; 8565 // var rotateZ = 0 8566 let translateZ = -translate * Math.abs(offsetMultiplier); 8567 let stretch = params.stretch; 8568 // Allow percentage to make a relative stretch for responsive sliders 8569 if (typeof stretch === 'string' && stretch.indexOf('%') !== -1) { 8570 stretch = parseFloat(params.stretch) / 100 * slideSize; 8571 } 8572 let translateY = isHorizontal ? 0 : stretch * offsetMultiplier; 8573 let translateX = isHorizontal ? stretch * offsetMultiplier : 0; 8574 let scale = 1 - (1 - params.scale) * Math.abs(offsetMultiplier); 8575 8576 // Fix for ultra small values 8577 if (Math.abs(translateX) < 0.001) translateX = 0; 8578 if (Math.abs(translateY) < 0.001) translateY = 0; 8579 if (Math.abs(translateZ) < 0.001) translateZ = 0; 8580 if (Math.abs(rotateY) < 0.001) rotateY = 0; 8581 if (Math.abs(rotateX) < 0.001) rotateX = 0; 8582 if (Math.abs(scale) < 0.001) scale = 0; 8583 const slideTransform = `translate3d(${translateX}px,${translateY}px,${translateZ}px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale(${scale})`; 8584 const targetEl = effectTarget(params, slideEl); 8585 targetEl.style.transform = slideTransform; 8586 slideEl.style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1; 8587 if (params.slideShadows) { 8588 // Set shadows 8589 let shadowBeforeEl = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-left') : slideEl.querySelector('.swiper-slide-shadow-top'); 8590 let shadowAfterEl = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-right') : slideEl.querySelector('.swiper-slide-shadow-bottom'); 8591 if (!shadowBeforeEl) { 8592 shadowBeforeEl = createShadow(params, slideEl, isHorizontal ? 'left' : 'top'); 8593 } 8594 if (!shadowAfterEl) { 8595 shadowAfterEl = createShadow(params, slideEl, isHorizontal ? 'right' : 'bottom'); 8596 } 8597 if (shadowBeforeEl) shadowBeforeEl.style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0; 8598 if (shadowAfterEl) shadowAfterEl.style.opacity = -offsetMultiplier > 0 ? -offsetMultiplier : 0; 8599 } 8600 } 8601 }; 8602 const setTransition = duration => { 8603 const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl)); 8604 transformElements.forEach(el => { 8605 el.style.transitionDuration = `${duration}ms`; 8606 el.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(shadowEl => { 8607 shadowEl.style.transitionDuration = `${duration}ms`; 8608 }); 8609 }); 8610 }; 8611 effectInit({ 8612 effect: 'coverflow', 8613 swiper, 8614 on, 8615 setTranslate, 8616 setTransition, 8617 perspective: () => true, 8618 overwriteParams: () => ({ 8619 watchSlidesProgress: true 8620 }) 8621 }); 8622 } 8623 8624 function EffectCreative(_ref) { 8625 let { 8626 swiper, 8627 extendParams, 8628 on 8629 } = _ref; 8630 extendParams({ 8631 creativeEffect: { 8632 limitProgress: 1, 8633 shadowPerProgress: false, 8634 progressMultiplier: 1, 8635 perspective: true, 8636 prev: { 8637 translate: [0, 0, 0], 8638 rotate: [0, 0, 0], 8639 opacity: 1, 8640 scale: 1 8641 }, 8642 next: { 8643 translate: [0, 0, 0], 8644 rotate: [0, 0, 0], 8645 opacity: 1, 8646 scale: 1 8647 } 8648 } 8649 }); 8650 const getTranslateValue = value => { 8651 if (typeof value === 'string') return value; 8652 return `${value}px`; 8653 }; 8654 const setTranslate = () => { 8655 const { 8656 slides, 8657 wrapperEl, 8658 slidesSizesGrid 8659 } = swiper; 8660 const params = swiper.params.creativeEffect; 8661 const { 8662 progressMultiplier: multiplier 8663 } = params; 8664 const isCenteredSlides = swiper.params.centeredSlides; 8665 if (isCenteredSlides) { 8666 const margin = slidesSizesGrid[0] / 2 - swiper.params.slidesOffsetBefore || 0; 8667 wrapperEl.style.transform = `translateX(calc(50% - ${margin}px))`; 8668 } 8669 for (let i = 0; i < slides.length; i += 1) { 8670 const slideEl = slides[i]; 8671 const slideProgress = slideEl.progress; 8672 const progress = Math.min(Math.max(slideEl.progress, -params.limitProgress), params.limitProgress); 8673 let originalProgress = progress; 8674 if (!isCenteredSlides) { 8675 originalProgress = Math.min(Math.max(slideEl.originalProgress, -params.limitProgress), params.limitProgress); 8676 } 8677 const offset = slideEl.swiperSlideOffset; 8678 const t = [swiper.params.cssMode ? -offset - swiper.translate : -offset, 0, 0]; 8679 const r = [0, 0, 0]; 8680 let custom = false; 8681 if (!swiper.isHorizontal()) { 8682 t[1] = t[0]; 8683 t[0] = 0; 8684 } 8685 let data = { 8686 translate: [0, 0, 0], 8687 rotate: [0, 0, 0], 8688 scale: 1, 8689 opacity: 1 8690 }; 8691 if (progress < 0) { 8692 data = params.next; 8693 custom = true; 8694 } else if (progress > 0) { 8695 data = params.prev; 8696 custom = true; 8697 } 8698 // set translate 8699 t.forEach((value, index) => { 8700 t[index] = `calc(${value}px + (${getTranslateValue(data.translate[index])} * ${Math.abs(progress * multiplier)}))`; 8701 }); 8702 // set rotates 8703 r.forEach((value, index) => { 8704 r[index] = data.rotate[index] * Math.abs(progress * multiplier); 8705 }); 8706 slideEl.style.zIndex = -Math.abs(Math.round(slideProgress)) + slides.length; 8707 const translateString = t.join(', '); 8708 const rotateString = `rotateX(${r[0]}deg) rotateY(${r[1]}deg) rotateZ(${r[2]}deg)`; 8709 const scaleString = originalProgress < 0 ? `scale(${1 + (1 - data.scale) * originalProgress * multiplier})` : `scale(${1 - (1 - data.scale) * originalProgress * multiplier})`; 8710 const opacityString = originalProgress < 0 ? 1 + (1 - data.opacity) * originalProgress * multiplier : 1 - (1 - data.opacity) * originalProgress * multiplier; 8711 const transform = `translate3d(${translateString}) ${rotateString} ${scaleString}`; 8712 8713 // Set shadows 8714 if (custom && data.shadow || !custom) { 8715 let shadowEl = slideEl.querySelector('.swiper-slide-shadow'); 8716 if (!shadowEl && data.shadow) { 8717 shadowEl = createShadow(params, slideEl); 8718 } 8719 if (shadowEl) { 8720 const shadowOpacity = params.shadowPerProgress ? progress * (1 / params.limitProgress) : progress; 8721 shadowEl.style.opacity = Math.min(Math.max(Math.abs(shadowOpacity), 0), 1); 8722 } 8723 } 8724 const targetEl = effectTarget(params, slideEl); 8725 targetEl.style.transform = transform; 8726 targetEl.style.opacity = opacityString; 8727 if (data.origin) { 8728 targetEl.style.transformOrigin = opacityString; 8729 } 8730 } 8731 }; 8732 const setTransition = duration => { 8733 const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl)); 8734 transformElements.forEach(el => { 8735 el.style.transitionDuration = `${duration}ms`; 8736 el.querySelectorAll('.swiper-slide-shadow').forEach(shadowEl => { 8737 shadowEl.style.transitionDuration = `${duration}ms`; 8738 }); 8739 }); 8740 effectVirtualTransitionEnd({ 8741 swiper, 8742 duration, 8743 transformElements, 8744 allSlides: true 8745 }); 8746 }; 8747 effectInit({ 8748 effect: 'creative', 8749 swiper, 8750 on, 8751 setTranslate, 8752 setTransition, 8753 perspective: () => swiper.params.creativeEffect.perspective, 8754 overwriteParams: () => ({ 8755 watchSlidesProgress: true, 8756 virtualTranslate: !swiper.params.cssMode 8757 }) 8758 }); 8759 } 8760 8761 function EffectCards(_ref) { 8762 let { 8763 swiper, 8764 extendParams, 8765 on 8766 } = _ref; 8767 extendParams({ 8768 cardsEffect: { 8769 slideShadows: true, 8770 rotate: true, 8771 perSlideRotate: 2, 8772 perSlideOffset: 8 8773 } 8774 }); 8775 const setTranslate = () => { 8776 const { 8777 slides, 8778 activeIndex 8779 } = swiper; 8780 const params = swiper.params.cardsEffect; 8781 const { 8782 startTranslate, 8783 isTouched 8784 } = swiper.touchEventsData; 8785 const currentTranslate = swiper.translate; 8786 for (let i = 0; i < slides.length; i += 1) { 8787 const slideEl = slides[i]; 8788 const slideProgress = slideEl.progress; 8789 const progress = Math.min(Math.max(slideProgress, -4), 4); 8790 let offset = slideEl.swiperSlideOffset; 8791 if (swiper.params.centeredSlides && !swiper.params.cssMode) { 8792 swiper.wrapperEl.style.transform = `translateX(${swiper.minTranslate()}px)`; 8793 } 8794 if (swiper.params.centeredSlides && swiper.params.cssMode) { 8795 offset -= slides[0].swiperSlideOffset; 8796 } 8797 let tX = swiper.params.cssMode ? -offset - swiper.translate : -offset; 8798 let tY = 0; 8799 const tZ = -100 * Math.abs(progress); 8800 let scale = 1; 8801 let rotate = -params.perSlideRotate * progress; 8802 let tXAdd = params.perSlideOffset - Math.abs(progress) * 0.75; 8803 const slideIndex = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.from + i : i; 8804 const isSwipeToNext = (slideIndex === activeIndex || slideIndex === activeIndex - 1) && progress > 0 && progress < 1 && (isTouched || swiper.params.cssMode) && currentTranslate < startTranslate; 8805 const isSwipeToPrev = (slideIndex === activeIndex || slideIndex === activeIndex + 1) && progress < 0 && progress > -1 && (isTouched || swiper.params.cssMode) && currentTranslate > startTranslate; 8806 if (isSwipeToNext || isSwipeToPrev) { 8807 const subProgress = (1 - Math.abs((Math.abs(progress) - 0.5) / 0.5)) ** 0.5; 8808 rotate += -28 * progress * subProgress; 8809 scale += -0.5 * subProgress; 8810 tXAdd += 96 * subProgress; 8811 tY = `${-25 * subProgress * Math.abs(progress)}%`; 8812 } 8813 if (progress < 0) { 8814 // next 8815 tX = `calc(${tX}px + (${tXAdd * Math.abs(progress)}%))`; 8816 } else if (progress > 0) { 8817 // prev 8818 tX = `calc(${tX}px + (-${tXAdd * Math.abs(progress)}%))`; 8819 } else { 8820 tX = `${tX}px`; 8821 } 8822 if (!swiper.isHorizontal()) { 8823 const prevY = tY; 8824 tY = tX; 8825 tX = prevY; 8826 } 8827 const scaleString = progress < 0 ? `${1 + (1 - scale) * progress}` : `${1 - (1 - scale) * progress}`; 8828 const transform = ` 8829 translate3d(${tX}, ${tY}, ${tZ}px) 8830 rotateZ(${params.rotate ? rotate : 0}deg) 8831 scale(${scaleString}) 8832 `; 8833 if (params.slideShadows) { 8834 // Set shadows 8835 let shadowEl = slideEl.querySelector('.swiper-slide-shadow'); 8836 if (!shadowEl) { 8837 shadowEl = createShadow(params, slideEl); 8838 } 8839 if (shadowEl) shadowEl.style.opacity = Math.min(Math.max((Math.abs(progress) - 0.5) / 0.5, 0), 1); 8840 } 8841 slideEl.style.zIndex = -Math.abs(Math.round(slideProgress)) + slides.length; 8842 const targetEl = effectTarget(params, slideEl); 8843 targetEl.style.transform = transform; 8844 } 8845 }; 8846 const setTransition = duration => { 8847 const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl)); 8848 transformElements.forEach(el => { 8849 el.style.transitionDuration = `${duration}ms`; 8850 el.querySelectorAll('.swiper-slide-shadow').forEach(shadowEl => { 8851 shadowEl.style.transitionDuration = `${duration}ms`; 8852 }); 8853 }); 8854 effectVirtualTransitionEnd({ 8855 swiper, 8856 duration, 8857 transformElements 8858 }); 8859 }; 8860 effectInit({ 8861 effect: 'cards', 8862 swiper, 8863 on, 8864 setTranslate, 8865 setTransition, 8866 perspective: () => true, 8867 overwriteParams: () => ({ 8868 watchSlidesProgress: true, 8869 virtualTranslate: !swiper.params.cssMode 8870 }) 8871 }); 8872 } 8873 8874 // Swiper Class 8875 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]; 8876 Swiper.use(modules); 8877 8878 return Swiper; 8879 8880})); 8881//# 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.